commit b0e3d721e0fae509a98a1990baf1a63f95338129 Author: Rémi Heredero Date: Tue Jul 11 12:27:35 2023 +0200 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..50cd904 --- /dev/null +++ b/.gitignore @@ -0,0 +1,30 @@ +# .gitignore file + +# MPLAB X IDE (Netbeans) specific +**/~*.* +**/build/ +**/debug/ +**/dist/ +**/disassembly/ +**/.generated_files/ +**/nbproject/private/ +**/nbproject/*.mk +**/nbproject/*.bash +**/nbproject/Makefile-genesis.properties + +# Object files +*.o +*.ko +*.obj +*.elf + +# Executables +*.exe + + +# KDE specific +.directory + +# Misc +.svn +*.bak diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..fca8e2c --- /dev/null +++ b/Makefile @@ -0,0 +1,113 @@ +# +# There exist several targets which are by default empty and which can be +# used for execution of your targets. These targets are usually executed +# before and after some main targets. They are: +# +# .build-pre: called before 'build' target +# .build-post: called after 'build' target +# .clean-pre: called before 'clean' target +# .clean-post: called after 'clean' target +# .clobber-pre: called before 'clobber' target +# .clobber-post: called after 'clobber' target +# .all-pre: called before 'all' target +# .all-post: called after 'all' target +# .help-pre: called before 'help' target +# .help-post: called after 'help' target +# +# Targets beginning with '.' are not intended to be called on their own. +# +# Main targets can be executed directly, and they are: +# +# build build a specific configuration +# clean remove built files from a configuration +# clobber remove all built files +# all build all configurations +# help print help mesage +# +# Targets .build-impl, .clean-impl, .clobber-impl, .all-impl, and +# .help-impl are implemented in nbproject/makefile-impl.mk. +# +# Available make variables: +# +# CND_BASEDIR base directory for relative paths +# CND_DISTDIR default top distribution directory (build artifacts) +# CND_BUILDDIR default top build directory (object files, ...) +# CONF name of current configuration +# CND_ARTIFACT_DIR_${CONF} directory of build artifact (current configuration) +# CND_ARTIFACT_NAME_${CONF} name of build artifact (current configuration) +# CND_ARTIFACT_PATH_${CONF} path to build artifact (current configuration) +# CND_PACKAGE_DIR_${CONF} directory of package (current configuration) +# CND_PACKAGE_NAME_${CONF} name of package (current configuration) +# CND_PACKAGE_PATH_${CONF} path to package (current configuration) +# +# NOCDDL + + +# Environment +MKDIR=mkdir +CP=cp +CCADMIN=CCadmin +RANLIB=ranlib + + +# build +build: .build-post + +.build-pre: +# Add your pre 'build' code here... + +.build-post: .build-impl +# Add your post 'build' code here... + + +# clean +clean: .clean-post + +.clean-pre: +# Add your pre 'clean' code here... +# WARNING: the IDE does not call this target since it takes a long time to +# simply run make. Instead, the IDE removes the configuration directories +# under build and dist directly without calling make. +# This target is left here so people can do a clean when running a clean +# outside the IDE. + +.clean-post: .clean-impl +# Add your post 'clean' code here... + + +# clobber +clobber: .clobber-post + +.clobber-pre: +# Add your pre 'clobber' code here... + +.clobber-post: .clobber-impl +# Add your post 'clobber' code here... + + +# all +all: .all-post + +.all-pre: +# Add your pre 'all' code here... + +.all-post: .all-impl +# Add your post 'all' code here... + + +# help +help: .help-post + +.help-pre: +# Add your pre 'help' code here... + +.help-post: .help-impl +# Add your post 'help' code here... + + + +# include project implementation makefile +include nbproject/Makefile-impl.mk + +# include project make variables +include nbproject/Makefile-variables.mk diff --git a/nbproject/configurations.xml b/nbproject/configurations.xml new file mode 100644 index 0000000..0c464b7 --- /dev/null +++ b/nbproject/configurations.xml @@ -0,0 +1,212 @@ + + + + + + src/app/factory.h + + + src/board/led.h + + + src/mcc_generated_files/tmr0.h + src/mcc_generated_files/pin_manager.h + src/mcc_generated_files/mcc.h + src/mcc_generated_files/interrupt_manager.h + src/mcc_generated_files/device_config.h + + + src/xf/ireactive.h + src/xf/event.h + src/xf/xf.h + + + + + + + src/app/factory.c + src/app/main.c + + + src/board/led.c + + + src/mcc_generated_files/mcc.c + src/mcc_generated_files/interrupt_manager.c + src/mcc_generated_files/device_config.c + src/mcc_generated_files/pin_manager.c + src/mcc_generated_files/tmr0.c + + + src/xf/xf.c + src/xf/event.c + + + + Makefile + + + + src + + Makefile + + + + localhost + PIC18F87K22 + + + PICkit3PlatformTool + XC8 + 2.41 + 2 + + + + + + + + + + + + + + + false + false + + + + + + + false + false + + false + + false + false + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/nbproject/project.xml b/nbproject/project.xml new file mode 100644 index 0000000..4e0519e --- /dev/null +++ b/nbproject/project.xml @@ -0,0 +1,25 @@ + + + com.microchip.mplab.nbide.embedded.makeproject + + + XFT + 9d10e4b8-91cc-4d86-8f12-a6fd880b26ed + 0 + UTF-8 + + + src + + + + default + 2 + + + + false + + + + diff --git a/src/app/factory.c b/src/app/factory.c new file mode 100644 index 0000000..930f122 --- /dev/null +++ b/src/app/factory.c @@ -0,0 +1,60 @@ +/*$file${.::app::factory.c} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/ +/* +* Model: XFT.qm +* File: ${.::app::factory.c} +* +* This code has been generated by QM 5.2.5 . +* DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost. +* +* SPDX-License-Identifier: GPL-3.0-or-later +* +* This generated code is open source software: you can redistribute it under +* the terms of the GNU General Public License as published by the Free +* Software Foundation. +* +* This code is distributed in the hope that it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* NOTE: +* Alternatively, this generated code may be distributed under the terms +* of Quantum Leaps commercial licenses, which expressly supersede the GNU +* General Public License and are specifically designed for licensees +* interested in retaining the proprietary status of their code. +* +* Contact information: +* +* +*/ +/*$endhead${.::app::factory.c} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/ +/* + * @author Rémi Heredero + * @date July 2023 + * @version 1.0.0 + * @see work of Medar Rieder & Pascal Sartoretti about femto XF + */ + +#include "factory.h" +Factory Factory_theFactory; + +/*${app::Factory::init} ....................................................*/ +void Factory_init(void) { + LED_init(Factory_l1(), 1); + LED_initHW(Factory_l1()); +} + +void Factory_build(){ + +} + +/*${app::Factory::start} ...................................................*/ +void Factory_start(void) { + LED_on(Factory_l1()); +} + +/*${app::Factory::l1} ......................................................*/ +LED* Factory_l1(void) { + return &Factory_theFactory.l1_; +} +/*$enddef${app::Factory} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/ diff --git a/src/app/factory.h b/src/app/factory.h new file mode 100644 index 0000000..e7748e4 --- /dev/null +++ b/src/app/factory.h @@ -0,0 +1,62 @@ +/*$file${.::app::factory.h} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/ +/* +* Model: XFT.qm +* File: ${.::app::factory.h} +* +* This code has been generated by QM 5.2.5 . +* DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost. +* +* SPDX-License-Identifier: GPL-3.0-or-later +* +* This generated code is open source software: you can redistribute it under +* the terms of the GNU General Public License as published by the Free +* Software Foundation. +* +* This code is distributed in the hope that it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* NOTE: +* Alternatively, this generated code may be distributed under the terms +* of Quantum Leaps commercial licenses, which expressly supersede the GNU +* General Public License and are specifically designed for licensees +* interested in retaining the proprietary status of their code. +* +* Contact information: +* +* +*/ +/*$endhead${.::app::factory.h} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/ +/* + * @author Rémi Heredero + * @date July 2023 + * @version 1.0.0 + * @see work of Medar Rieder & Pascal Sartoretti about femto XF + */ + +#ifndef FACTORY_H +#define FACTORY_H + +#include +#include + +#include "../board/led.h" + +/*$declare${app::Factory} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/ + +/*${app::Factory} ..........................................................*/ +typedef struct Factory { +/* public: */ + LED l1_; +} Factory; + +/* public: */ +void Factory_init(void); +void Factory_build(void); +void Factory_start(void); +LED* Factory_l1(void); +extern Factory Factory_theFactory; +/*$enddecl${app::Factory} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/ + +#endif diff --git a/src/app/main.c b/src/app/main.c new file mode 100644 index 0000000..c25864c --- /dev/null +++ b/src/app/main.c @@ -0,0 +1,57 @@ + +/* +* Model: XFT.qm +* File: ${.::app::main.c} +* +* This code has been generated by QM 5.2.5 . +* DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost. +* +* SPDX-License-Identifier: GPL-3.0-or-later +* +* This generated code is open source software: you can redistribute it under +* the terms of the GNU General Public License as published by the Free +* Software Foundation. +* +* This code is distributed in the hope that it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* NOTE: +* Alternatively, this generated code may be distributed under the terms +* of Quantum Leaps commercial licenses, which expressly supersede the GNU +* General Public License and are specifically designed for licensees +* interested in retaining the proprietary status of their code. +* +* Contact information: +* +* +*/ +#include "../mcc_generated_files/mcc.h" +#include "../app/factory.h" +#include "../xf/xf.h" + +void main(void) { + // Initialize the device + SYSTEM_Initialize(); + + // Enable the Global Interrupts + INTERRUPT_GlobalInterruptEnable(); + //INTERRUPT_GlobalInterruptDisable(); + //INTERRUPT_PeripheralInterruptEnable(); + //INTERRUPT_PeripheralInterruptDisable(); + + XF_init(); + + Factory_init(); + Factory_build(); + Factory_start(); + + TMR0_SetInterruptHandler(XF_decrementAndQueueTimers); + + + while (1) { + XF_executeOnce(); + + } +} diff --git a/src/board/button.c b/src/board/button.c new file mode 100644 index 0000000..b7f90f4 --- /dev/null +++ b/src/board/button.c @@ -0,0 +1,62 @@ +/*$file${.::board::button.c} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/ +/* +* Model: XFT.qm +* File: ${.::board::button.c} +* +* This code has been generated by QM 5.2.5 . +* DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost. +* +* SPDX-License-Identifier: GPL-3.0-or-later +* +* This generated code is open source software: you can redistribute it under +* the terms of the GNU General Public License as published by the Free +* Software Foundation. +* +* This code is distributed in the hope that it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* NOTE: +* Alternatively, this generated code may be distributed under the terms +* of Quantum Leaps commercial licenses, which expressly supersede the GNU +* General Public License and are specifically designed for licensees +* interested in retaining the proprietary status of their code. +* +* Contact information: +* +* +*/ +/*$endhead${.::board::button.c} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/ +#include "button.h" +#include "../mcc_generated_files/pin_manager.h" + +/*$skip${QP_VERSION} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/ +/* Check for the minimum required QP version */ +#if (QP_VERSION < 700U) || (QP_VERSION != ((QP_RELEASE^4294967295U) % 0x3E8U)) +#error qpc version 7.0.0 or higher required +#endif +/*$endskip${QP_VERSION} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/ + +/*$define${board::Button} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/ + +/*${board::Button} .........................................................*/ + +/*${board::Button::SM} .....................................................*/ +QState Button_initial(Button * const me, void const * const par) { + /*${board::Button::SM::initial} */ + return Q_TRAN(&Button_INIT); +} + +/*${board::Button::SM::INIT} ...............................................*/ +QState Button_INIT(Button * const me, QEvt const * const e) { + QState status_; + switch (e->sig) { + default: { + status_ = Q_SUPER(&QHsm_top); + break; + } + } + return status_; +} +/*$enddef${board::Button} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/ diff --git a/src/board/button.h b/src/board/button.h new file mode 100644 index 0000000..fe087ef --- /dev/null +++ b/src/board/button.h @@ -0,0 +1,53 @@ +/*$file${.::board::button.h} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/ +/* +* Model: XFT.qm +* File: ${.::board::button.h} +* +* This code has been generated by QM 5.2.5 . +* DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost. +* +* SPDX-License-Identifier: GPL-3.0-or-later +* +* This generated code is open source software: you can redistribute it under +* the terms of the GNU General Public License as published by the Free +* Software Foundation. +* +* This code is distributed in the hope that it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* NOTE: +* Alternatively, this generated code may be distributed under the terms +* of Quantum Leaps commercial licenses, which expressly supersede the GNU +* General Public License and are specifically designed for licensees +* interested in retaining the proprietary status of their code. +* +* Contact information: +* +* +*/ +/*$endhead${.::board::button.h} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/ +#ifndef BUTTON_H +#define BUTTON_H + +#include + +/*$declare${board::Button} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/ + +/*${board::Button} .........................................................*/ +typedef struct { +/* protected: */ + QActive super; + +/* public: */ + uint8_t id; + BUTTON_STATES state; +} Button; + +/* protected: */ +QState Button_initial(Button * const me, void const * const par); +QState Button_INIT(Button * const me, QEvt const * const e); +/*$enddecl${board::Button} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/ + +#endif diff --git a/src/board/led.c b/src/board/led.c new file mode 100644 index 0000000..e5b422c --- /dev/null +++ b/src/board/led.c @@ -0,0 +1,110 @@ + +/* +* Model: XFT.qm +* File: ${.::board::led.c} +* +* This code has been generated by QM 5.2.5 . +* DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost. +* +* SPDX-License-Identifier: GPL-3.0-or-later +* +* This generated code is open source software: you can redistribute it under +* the terms of the GNU General Public License as published by the Free +* Software Foundation. +* +* This code is distributed in the hope that it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* NOTE: +* Alternatively, this generated code may be distributed under the terms +* of Quantum Leaps commercial licenses, which expressly supersede the GNU +* General Public License and are specifically designed for licensees +* interested in retaining the proprietary status of their code. +* +* Contact information: +* +* +*/ +#include "led.h" +#include "../mcc_generated_files/pin_manager.h" + +void LED_init(LED * const me, + uint8_t id) +{ + me->id = id; +} +void LED_initHW(LED * const me) { + LED_off(me); +} +void LED_on(LED * const me) { + LED* l = (LED*) me; + switch (l->id) { + case 1: + OUTPUT1_SetHigh(); + break; + case 2: + OUTPUT2_SetHigh(); + break; + case 3: + OUTPUT3_SetHigh(); + break; + case 4: + OUTPUT4_SetHigh(); + break; + case 5: + OUTPUT5_SetHigh(); + break; + case 6: + OUTPUT6_SetHigh(); + break; + case 7: + OUTPUT7_SetHigh(); + break; + case 8: + OUTPUT8_SetHigh(); + break; + case 9: + OUTPUT9_SetHigh(); + break; + case 10: + OUTPUT10_SetHigh(); + break; + } +} +void LED_off(LED * const me) { + LED* l = (LED*) me; + switch (l->id) { + case 1: + OUTPUT1_SetLow(); + break; + case 2: + OUTPUT2_SetLow(); + break; + case 3: + OUTPUT3_SetLow(); + break; + case 4: + OUTPUT4_SetLow(); + break; + case 5: + OUTPUT5_SetLow(); + break; + case 6: + OUTPUT6_SetLow(); + break; + case 7: + OUTPUT7_SetLow(); + break; + case 8: + OUTPUT8_SetLow(); + break; + case 9: + OUTPUT9_SetLow(); + break; + case 10: + OUTPUT10_SetLow(); + break; + } +} diff --git a/src/board/led.h b/src/board/led.h new file mode 100644 index 0000000..de5eaf2 --- /dev/null +++ b/src/board/led.h @@ -0,0 +1,73 @@ + +/* +* Model: XFT.qm +* File: ${.::board::led.h} +* +* This code has been generated by QM 5.2.5 . +* DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost. +* +* SPDX-License-Identifier: GPL-3.0-or-later +* +* This generated code is open source software: you can redistribute it under +* the terms of the GNU General Public License as published by the Free +* Software Foundation. +* +* This code is distributed in the hope that it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* NOTE: +* Alternatively, this generated code may be distributed under the terms +* of Quantum Leaps commercial licenses, which expressly supersede the GNU +* General Public License and are specifically designed for licensees +* interested in retaining the proprietary status of their code. +* +* Contact information: +* +* +*/ +#ifndef LED_H +#define LED_H + +#include +/* + * @author Rémi Heredero + * @date July 2023 + * @version 1.0.0 + * @see work of Medar Rieder & Pascal Sartoretti about femto XF + */ +typedef struct { +/* public: */ + uint8_t id; +} LED; + +/* public: */ + +/** + * Initialize the led + * @param me the led itself + * @param id the id of the led + */ +void LED_init(LED * const me, + uint8_t id); + +/** + * Initializing the led + * @param me the led itself + */ +void LED_initHW(LED * const me); + +/** + * Turn On the led + * @param me the led itself + */ +void LED_on(LED * const me); + +/** + * Turn Off the led + * @param me the led itself + */ +void LED_off(LED * const me); + +#endif diff --git a/src/mcc_generated_files/device_config.c b/src/mcc_generated_files/device_config.c new file mode 100644 index 0000000..3821266 --- /dev/null +++ b/src/mcc_generated_files/device_config.c @@ -0,0 +1,117 @@ +/** + @Generated PIC10 / PIC12 / PIC16 / PIC18 MCUs Source File + + @Company: + Microchip Technology Inc. + + @File Name: + mcc.c + + @Summary: + This is the device_config.c file generated using PIC10 / PIC12 / PIC16 / PIC18 MCUs + + @Description: + This header file provides implementations for driver APIs for all modules selected in the GUI. + Generation Information : + Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8 + Device : PIC18F86K22 + Driver Version : 2.00 + The generated drivers are tested against the following: + Compiler : XC8 2.36 and above or later + MPLAB : MPLAB X 6.00 +*/ + +/* + (c) 2018 Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip software and any + derivatives exclusively with Microchip products. It is your responsibility to comply with third party + license terms applicable to your use of third party software (including open source software) that + may accompany Microchip software. + + THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER + EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY + IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS + FOR A PARTICULAR PURPOSE. + + IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND + WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP + HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO + THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL + CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT + OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS + SOFTWARE. +*/ + +// Configuration bits: selected in the GUI + +// CONFIG1L +#pragma config RETEN = ON // VREG Sleep Enable bit->Enabled +#pragma config INTOSCSEL = HIGH // LF-INTOSC Low-power Enable bit->LF-INTOSC in High-power mode during Sleep +#pragma config SOSCSEL = DIG // SOSC Power Selection and mode Configuration bits->Digital (SCLKI) mode +#pragma config XINST = OFF // Extended Instruction Set->Disabled + +// CONFIG1H +#pragma config FOSC = INTIO2 // Oscillator->Internal RC oscillator +#pragma config PLLCFG = OFF // PLL x4 Enable bit->Disabled +#pragma config FCMEN = OFF // Fail-Safe Clock Monitor->Disabled +#pragma config IESO = OFF // Internal External Oscillator Switch Over Mode->Disabled + +// CONFIG2L +#pragma config PWRTEN = OFF // Power Up Timer->Disabled +#pragma config BOREN = SBORDIS // Brown Out Detect->Enabled in hardware, SBOREN disabled +#pragma config BORV = 3 // Brown-out Reset Voltage bits->1.8V +#pragma config BORPWR = ZPBORMV // BORMV Power level->ZPBORMV instead of BORMV is selected + +// CONFIG2H +#pragma config WDTEN = OFF // Watchdog Timer->WDT disabled in hardware; SWDTEN bit disabled +#pragma config WDTPS = 1048576 // Watchdog Postscaler->1:1048576 + +// CONFIG3L +#pragma config RTCOSC = SOSCREF // RTCC Clock Select->RTCC uses SOSC +#pragma config EASHFT = ON // External Address Shift bit->Address shifting enabled +#pragma config ABW = MM // Address Bus Width Select bits->8-bit address bus +#pragma config BW = 16 // Data Bus Width->16-bit external bus mode +#pragma config WAIT = OFF // External Bus Wait->Disabled + +// CONFIG3H +#pragma config CCP2MX = PORTC // CCP2 Mux->RC1 +#pragma config ECCPMX = PORTE // ECCP Mux->Enhanced CCP1/3 [P1B/P1C/P3B/P3C] muxed with RE6/RE5/RE4/RE3 +#pragma config MSSPMSK = MSK7 // MSSP address masking->7 Bit address masking mode +#pragma config MCLRE = ON // Master Clear Enable->MCLR Enabled, RG5 Disabled + +// CONFIG4L +#pragma config STVREN = ON // Stack Overflow Reset->Enabled +#pragma config BBSIZ = BB2K // Boot Block Size->2K word Boot Block size +#pragma config DEBUG = OFF // Background Debug->Disabled + +// CONFIG5L +#pragma config CP0 = OFF // Code Protect 00800-03FFF->Disabled +#pragma config CP1 = OFF // Code Protect 04000-07FFF->Disabled +#pragma config CP2 = OFF // Code Protect 08000-0BFFF->Disabled +#pragma config CP3 = OFF // Code Protect 0C000-0FFFF->Disabled + +// CONFIG5H +#pragma config CPB = OFF // Code Protect Boot->Disabled +#pragma config CPD = OFF // Data EE Read Protect->Disabled + +// CONFIG6L +#pragma config WRT0 = OFF // Table Write Protect 00800-03FFF->Disabled +#pragma config WRT1 = OFF // Table Write Protect 04000-07FFF->Disabled +#pragma config WRT2 = OFF // Table Write Protect 08000-0BFFF->Disabled +#pragma config WRT3 = OFF // Table Write Protect 0C000-0FFFF->Disabled + +// CONFIG6H +#pragma config WRTC = OFF // Config. Write Protect->Disabled +#pragma config WRTB = OFF // Table Write Protect Boot->Disabled +#pragma config WRTD = OFF // Data EE Write Protect->Disabled + +// CONFIG7L +#pragma config EBRT0 = OFF // Table Read Protect 00800-03FFF->Disabled +#pragma config EBRT1 = OFF // Table Read Protect 04000-07FFF->Disabled +#pragma config EBRT2 = OFF // Table Read Protect 08000-0BFFF->Disabled +#pragma config EBRT3 = OFF // Table Read Protect 0C000-0FFFF->Disabled + +// CONFIG7H +#pragma config EBRTB = OFF // Table Read Protect Boot->Disabled diff --git a/src/mcc_generated_files/device_config.h b/src/mcc_generated_files/device_config.h new file mode 100644 index 0000000..8d51454 --- /dev/null +++ b/src/mcc_generated_files/device_config.h @@ -0,0 +1,55 @@ +/** + @Generated PIC10 / PIC12 / PIC16 / PIC18 MCUs Header File + + @Company: + Microchip Technology Inc. + + @File Name: + mcc.c + + @Summary: + This is the device_config.h file generated using PIC10 / PIC12 / PIC16 / PIC18 MCUs + + @Description: + This header file provides implementations for driver APIs for all modules selected in the GUI. + Generation Information : + Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8 + Device : PIC18F86K22 + Driver Version : 2.00 + The generated drivers are tested against the following: + Compiler : XC8 2.36 and above or later + MPLAB : MPLAB X 6.00 +*/ + +/* + (c) 2018 Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip software and any + derivatives exclusively with Microchip products. It is your responsibility to comply with third party + license terms applicable to your use of third party software (including open source software) that + may accompany Microchip software. + + THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER + EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY + IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS + FOR A PARTICULAR PURPOSE. + + IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND + WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP + HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO + THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL + CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT + OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS + SOFTWARE. +*/ + +#ifndef DEVICE_CONFIG_H +#define DEVICE_CONFIG_H + +#define _XTAL_FREQ 64000000 + +#endif /* DEVICE_CONFIG_H */ +/** + End of File +*/ diff --git a/src/mcc_generated_files/interrupt_manager.c b/src/mcc_generated_files/interrupt_manager.c new file mode 100644 index 0000000..b13cf76 --- /dev/null +++ b/src/mcc_generated_files/interrupt_manager.c @@ -0,0 +1,72 @@ +/** + Generated Interrupt Manager Source File + + @Company: + Microchip Technology Inc. + + @File Name: + interrupt_manager.c + + @Summary: + This is the Interrupt Manager file generated using PIC10 / PIC12 / PIC16 / PIC18 MCUs + + @Description: + This header file provides implementations for global interrupt handling. + For individual peripheral handlers please see the peripheral driver for + all modules selected in the GUI. + Generation Information : + Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8 + Device : PIC18F86K22 + Driver Version : 2.04 + The generated drivers are tested against the following: + Compiler : XC8 2.36 and above or later + MPLAB : MPLAB X 6.00 +*/ + +/* + (c) 2018 Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip software and any + derivatives exclusively with Microchip products. It is your responsibility to comply with third party + license terms applicable to your use of third party software (including open source software) that + may accompany Microchip software. + + THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER + EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY + IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS + FOR A PARTICULAR PURPOSE. + + IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND + WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP + HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO + THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL + CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT + OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS + SOFTWARE. +*/ + +#include "interrupt_manager.h" +#include "mcc.h" + +void INTERRUPT_Initialize (void) +{ + // Disable Interrupt Priority Vectors (16CXXX Compatibility Mode) + RCONbits.IPEN = 0; +} + +void __interrupt() INTERRUPT_InterruptManager (void) +{ + // interrupt handler + if(INTCONbits.TMR0IE == 1 && INTCONbits.TMR0IF == 1) + { + TMR0_ISR(); + } + else + { + //Unhandled Interrupt + } +} +/** + End of File +*/ diff --git a/src/mcc_generated_files/interrupt_manager.h b/src/mcc_generated_files/interrupt_manager.h new file mode 100644 index 0000000..7d39e2f --- /dev/null +++ b/src/mcc_generated_files/interrupt_manager.h @@ -0,0 +1,115 @@ +/** + Generated Interrupt Manager Header File + + @Company: + Microchip Technology Inc. + + @File Name: + interrupt_manager.h + + @Summary: + This is the Interrupt Manager file generated using PIC10 / PIC12 / PIC16 / PIC18 MCUs + + @Description: + This header file provides implementations for global interrupt handling. + For individual peripheral handlers please see the peripheral driver for + all modules selected in the GUI. + Generation Information : + Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8 + Device : PIC18F86K22 + Driver Version : 2.03 + The generated drivers are tested against the following: + Compiler : XC8 2.36 and above or later + MPLAB : MPLAB X 6.00 +*/ + +/* + (c) 2018 Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip software and any + derivatives exclusively with Microchip products. It is your responsibility to comply with third party + license terms applicable to your use of third party software (including open source software) that + may accompany Microchip software. + + THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER + EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY + IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS + FOR A PARTICULAR PURPOSE. + + IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND + WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP + HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO + THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL + CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT + OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS + SOFTWARE. +*/ + +#ifndef INTERRUPT_MANAGER_H +#define INTERRUPT_MANAGER_H + + +/** + * @Param + none + * @Returns + none + * @Description + This macro will enable global interrupts. + * @Example + INTERRUPT_GlobalInterruptEnable(); + */ +#define INTERRUPT_GlobalInterruptEnable() (INTCONbits.GIE = 1) + +/** + * @Param + none + * @Returns + none + * @Description + This macro will disable global interrupts. + * @Example + INTERRUPT_GlobalInterruptDisable(); + */ +#define INTERRUPT_GlobalInterruptDisable() (INTCONbits.GIE = 0) +/** + * @Param + none + * @Returns + none + * @Description + This macro will enable peripheral interrupts. + * @Example + INTERRUPT_PeripheralInterruptEnable(); + */ +#define INTERRUPT_PeripheralInterruptEnable() (INTCONbits.PEIE = 1) + +/** + * @Param + none + * @Returns + none + * @Description + This macro will disable peripheral interrupts. + * @Example + INTERRUPT_PeripheralInterruptDisable(); + */ +#define INTERRUPT_PeripheralInterruptDisable() (INTCONbits.PEIE = 0) + +/** + * @Param + none + * @Returns + none + * @Description + Initializes PIC18 peripheral interrupt priorities; enables/disables priority vectors + * @Example + INTERRUPT_Initialize(); + */ +void INTERRUPT_Initialize (void); + +#endif // INTERRUPT_MANAGER_H +/** + End of File +*/ diff --git a/src/mcc_generated_files/mcc.c b/src/mcc_generated_files/mcc.c new file mode 100644 index 0000000..01a882b --- /dev/null +++ b/src/mcc_generated_files/mcc.c @@ -0,0 +1,74 @@ +/** + @Generated PIC10 / PIC12 / PIC16 / PIC18 MCUs Source File + + @Company: + Microchip Technology Inc. + + @File Name: + mcc.c + + @Summary: + This is the mcc.c file generated using PIC10 / PIC12 / PIC16 / PIC18 MCUs + + @Description: + This header file provides implementations for driver APIs for all modules selected in the GUI. + Generation Information : + Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8 + Device : PIC18F86K22 + Driver Version : 2.00 + The generated drivers are tested against the following: + Compiler : XC8 2.36 and above or later + MPLAB : MPLAB X 6.00 +*/ + +/* + (c) 2018 Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip software and any + derivatives exclusively with Microchip products. It is your responsibility to comply with third party + license terms applicable to your use of third party software (including open source software) that + may accompany Microchip software. + + THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER + EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY + IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS + FOR A PARTICULAR PURPOSE. + + IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND + WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP + HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO + THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL + CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT + OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS + SOFTWARE. +*/ + +#include "mcc.h" + + +void SYSTEM_Initialize(void) +{ + + INTERRUPT_Initialize(); + PIN_MANAGER_Initialize(); + OSCILLATOR_Initialize(); + TMR0_Initialize(); +} + +void OSCILLATOR_Initialize(void) +{ + // SCS FOSC; IDLEN disabled; IRCF 16MHz_HF; + OSCCON = 0x70; + // SOSCGO disabled; MFIOSEL disabled; + OSCCON2 = 0x00; + // INTSRC INTRC; PLLEN enabled; TUN 0; + OSCTUNE = 0x40; + // ROSEL System Clock(FOSC); ROON disabled; ROSSLP Disabled in Sleep mode; RODIV Fosc; + REFOCON = 0x00; +} + + +/** + End of File +*/ diff --git a/src/mcc_generated_files/mcc.h b/src/mcc_generated_files/mcc.h new file mode 100644 index 0000000..21cbe47 --- /dev/null +++ b/src/mcc_generated_files/mcc.h @@ -0,0 +1,89 @@ +/** + @Generated PIC10 / PIC12 / PIC16 / PIC18 MCUs Header File + + @Company: + Microchip Technology Inc. + + @File Name: + mcc.h + + @Summary: + This is the mcc.h file generated using PIC10 / PIC12 / PIC16 / PIC18 MCUs + + @Description: + This header file provides implementations for driver APIs for all modules selected in the GUI. + Generation Information : + Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8 + Device : PIC18F86K22 + Driver Version : 2.00 + The generated drivers are tested against the following: + Compiler : XC8 2.36 and above or later + MPLAB : MPLAB X 6.00 +*/ + +/* + (c) 2018 Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip software and any + derivatives exclusively with Microchip products. It is your responsibility to comply with third party + license terms applicable to your use of third party software (including open source software) that + may accompany Microchip software. + + THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER + EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY + IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS + FOR A PARTICULAR PURPOSE. + + IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND + WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP + HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO + THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL + CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT + OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS + SOFTWARE. +*/ + +#ifndef MCC_H +#define MCC_H +#include +#include "device_config.h" +#include "pin_manager.h" +#include +#include +#include +#include "interrupt_manager.h" +#include "tmr0.h" + + + +/** + * @Param + none + * @Returns + none + * @Description + Initializes the device to the default states configured in the + * MCC GUI + * @Example + SYSTEM_Initialize(void); + */ +void SYSTEM_Initialize(void); + +/** + * @Param + none + * @Returns + none + * @Description + Initializes the oscillator to the default states configured in the + * MCC GUI + * @Example + OSCILLATOR_Initialize(void); + */ +void OSCILLATOR_Initialize(void); + +#endif /* MCC_H */ +/** + End of File +*/ \ No newline at end of file diff --git a/src/mcc_generated_files/pin_manager.c b/src/mcc_generated_files/pin_manager.c new file mode 100644 index 0000000..8c898b2 --- /dev/null +++ b/src/mcc_generated_files/pin_manager.c @@ -0,0 +1,109 @@ +/** + Generated Pin Manager File + + Company: + Microchip Technology Inc. + + File Name: + pin_manager.c + + Summary: + This is the Pin Manager file generated using PIC10 / PIC12 / PIC16 / PIC18 MCUs + + Description: + This header file provides implementations for pin APIs for all pins selected in the GUI. + Generation Information : + Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8 + Device : PIC18F86K22 + Driver Version : 2.11 + The generated drivers are tested against the following: + Compiler : XC8 2.36 and above + MPLAB : MPLAB X 6.00 + + Copyright (c) 2013 - 2015 released Microchip Technology Inc. All rights reserved. +*/ + +/* + (c) 2018 Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip software and any + derivatives exclusively with Microchip products. It is your responsibility to comply with third party + license terms applicable to your use of third party software (including open source software) that + may accompany Microchip software. + + THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER + EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY + IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS + FOR A PARTICULAR PURPOSE. + + IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND + WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP + HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO + THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL + CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT + OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS + SOFTWARE. +*/ + +#include "pin_manager.h" + + + + + +void PIN_MANAGER_Initialize(void) +{ + /** + LATx registers + */ + LATE = 0x00; + LATD = 0x00; + LATA = 0x00; + LATF = 0x00; + LATB = 0x00; + LATG = 0x00; + LATC = 0x00; + LATH = 0x00; + + /** + TRISx registers + */ + TRISE = 0xFF; + TRISF = 0xFE; + TRISA = 0xFF; + TRISG = 0x07; + TRISB = 0xFF; + TRISH = 0x00; + TRISC = 0xFF; + TRISD = 0xFF; + + /** + ANSELx registers + */ + ANCON0 = 0xFF; + ANCON1 = 0x0F; + ANCON2 = 0x0C; + + /** + WPUx registers + */ + + + + + + + + +} + +void PIN_MANAGER_IOC(void) +{ + // Clear global Interrupt-On-Change flag + INTCONbits.RBIF = 0; +} + +/** + End of File +*/ \ No newline at end of file diff --git a/src/mcc_generated_files/pin_manager.h b/src/mcc_generated_files/pin_manager.h new file mode 100644 index 0000000..de6729a --- /dev/null +++ b/src/mcc_generated_files/pin_manager.h @@ -0,0 +1,270 @@ +/** + @Generated Pin Manager Header File + + @Company: + Microchip Technology Inc. + + @File Name: + pin_manager.h + + @Summary: + This is the Pin Manager file generated using PIC10 / PIC12 / PIC16 / PIC18 MCUs + + @Description + This header file provides APIs for driver for . + Generation Information : + Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8 + Device : PIC18F86K22 + Driver Version : 2.11 + The generated drivers are tested against the following: + Compiler : XC8 2.36 and above + MPLAB : MPLAB X 6.00 +*/ + +/* + (c) 2018 Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip software and any + derivatives exclusively with Microchip products. It is your responsibility to comply with third party + license terms applicable to your use of third party software (including open source software) that + may accompany Microchip software. + + THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER + EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY + IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS + FOR A PARTICULAR PURPOSE. + + IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND + WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP + HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO + THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL + CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT + OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS + SOFTWARE. +*/ + +#ifndef PIN_MANAGER_H +#define PIN_MANAGER_H + +/** + Section: Included Files +*/ + +#include + +#define INPUT 1 +#define OUTPUT 0 + +#define HIGH 1 +#define LOW 0 + +#define ANALOG 1 +#define DIGITAL 0 + +#define PULL_UP_ENABLED 1 +#define PULL_UP_DISABLED 0 + +// get/set INPUT1 aliases +#define INPUT1_TRIS TRISBbits.TRISB0 +#define INPUT1_LAT LATBbits.LATB0 +#define INPUT1_PORT PORTBbits.RB0 +#define INPUT1_SetHigh() do { LATBbits.LATB0 = 1; } while(0) +#define INPUT1_SetLow() do { LATBbits.LATB0 = 0; } while(0) +#define INPUT1_Toggle() do { LATBbits.LATB0 = ~LATBbits.LATB0; } while(0) +#define INPUT1_GetValue() PORTBbits.RB0 +#define INPUT1_SetDigitalInput() do { TRISBbits.TRISB0 = 1; } while(0) +#define INPUT1_SetDigitalOutput() do { TRISBbits.TRISB0 = 0; } while(0) + +// get/set INPUT2 aliases +#define INPUT2_TRIS TRISBbits.TRISB1 +#define INPUT2_LAT LATBbits.LATB1 +#define INPUT2_PORT PORTBbits.RB1 +#define INPUT2_SetHigh() do { LATBbits.LATB1 = 1; } while(0) +#define INPUT2_SetLow() do { LATBbits.LATB1 = 0; } while(0) +#define INPUT2_Toggle() do { LATBbits.LATB1 = ~LATBbits.LATB1; } while(0) +#define INPUT2_GetValue() PORTBbits.RB1 +#define INPUT2_SetDigitalInput() do { TRISBbits.TRISB1 = 1; } while(0) +#define INPUT2_SetDigitalOutput() do { TRISBbits.TRISB1 = 0; } while(0) + +// get/set INPUT3 aliases +#define INPUT3_TRIS TRISBbits.TRISB4 +#define INPUT3_LAT LATBbits.LATB4 +#define INPUT3_PORT PORTBbits.RB4 +#define INPUT3_SetHigh() do { LATBbits.LATB4 = 1; } while(0) +#define INPUT3_SetLow() do { LATBbits.LATB4 = 0; } while(0) +#define INPUT3_Toggle() do { LATBbits.LATB4 = ~LATBbits.LATB4; } while(0) +#define INPUT3_GetValue() PORTBbits.RB4 +#define INPUT3_SetDigitalInput() do { TRISBbits.TRISB4 = 1; } while(0) +#define INPUT3_SetDigitalOutput() do { TRISBbits.TRISB4 = 0; } while(0) + +// get/set OUTPUT9 aliases +#define OUTPUT9_TRIS TRISGbits.TRISG3 +#define OUTPUT9_LAT LATGbits.LATG3 +#define OUTPUT9_PORT PORTGbits.RG3 +#define OUTPUT9_ANS ANCON2bits.ANSEL17 +#define OUTPUT9_SetHigh() do { LATGbits.LATG3 = 1; } while(0) +#define OUTPUT9_SetLow() do { LATGbits.LATG3 = 0; } while(0) +#define OUTPUT9_Toggle() do { LATGbits.LATG3 = ~LATGbits.LATG3; } while(0) +#define OUTPUT9_GetValue() PORTGbits.RG3 +#define OUTPUT9_SetDigitalInput() do { TRISGbits.TRISG3 = 1; } while(0) +#define OUTPUT9_SetDigitalOutput() do { TRISGbits.TRISG3 = 0; } while(0) +#define OUTPUT9_SetAnalogMode() do { ANCON2bits.ANSEL17 = 1; } while(0) +#define OUTPUT9_SetDigitalMode() do { ANCON2bits.ANSEL17 = 0; } while(0) + +// get/set OUTPUT10 aliases +#define OUTPUT10_TRIS TRISGbits.TRISG4 +#define OUTPUT10_LAT LATGbits.LATG4 +#define OUTPUT10_PORT PORTGbits.RG4 +#define OUTPUT10_ANS ANCON2bits.ANSEL16 +#define OUTPUT10_SetHigh() do { LATGbits.LATG4 = 1; } while(0) +#define OUTPUT10_SetLow() do { LATGbits.LATG4 = 0; } while(0) +#define OUTPUT10_Toggle() do { LATGbits.LATG4 = ~LATGbits.LATG4; } while(0) +#define OUTPUT10_GetValue() PORTGbits.RG4 +#define OUTPUT10_SetDigitalInput() do { TRISGbits.TRISG4 = 1; } while(0) +#define OUTPUT10_SetDigitalOutput() do { TRISGbits.TRISG4 = 0; } while(0) +#define OUTPUT10_SetAnalogMode() do { ANCON2bits.ANSEL16 = 1; } while(0) +#define OUTPUT10_SetDigitalMode() do { ANCON2bits.ANSEL16 = 0; } while(0) + +// get/set OUTPUT1 aliases +#define OUTPUT1_TRIS TRISHbits.TRISH0 +#define OUTPUT1_LAT LATHbits.LATH0 +#define OUTPUT1_PORT PORTHbits.RH0 +#define OUTPUT1_ANS ANCON2bits.ANSEL23 +#define OUTPUT1_SetHigh() do { LATHbits.LATH0 = 1; } while(0) +#define OUTPUT1_SetLow() do { LATHbits.LATH0 = 0; } while(0) +#define OUTPUT1_Toggle() do { LATHbits.LATH0 = ~LATHbits.LATH0; } while(0) +#define OUTPUT1_GetValue() PORTHbits.RH0 +#define OUTPUT1_SetDigitalInput() do { TRISHbits.TRISH0 = 1; } while(0) +#define OUTPUT1_SetDigitalOutput() do { TRISHbits.TRISH0 = 0; } while(0) +#define OUTPUT1_SetAnalogMode() do { ANCON2bits.ANSEL23 = 1; } while(0) +#define OUTPUT1_SetDigitalMode() do { ANCON2bits.ANSEL23 = 0; } while(0) + +// get/set OUTPUT2 aliases +#define OUTPUT2_TRIS TRISHbits.TRISH1 +#define OUTPUT2_LAT LATHbits.LATH1 +#define OUTPUT2_PORT PORTHbits.RH1 +#define OUTPUT2_ANS ANCON2bits.ANSEL22 +#define OUTPUT2_SetHigh() do { LATHbits.LATH1 = 1; } while(0) +#define OUTPUT2_SetLow() do { LATHbits.LATH1 = 0; } while(0) +#define OUTPUT2_Toggle() do { LATHbits.LATH1 = ~LATHbits.LATH1; } while(0) +#define OUTPUT2_GetValue() PORTHbits.RH1 +#define OUTPUT2_SetDigitalInput() do { TRISHbits.TRISH1 = 1; } while(0) +#define OUTPUT2_SetDigitalOutput() do { TRISHbits.TRISH1 = 0; } while(0) +#define OUTPUT2_SetAnalogMode() do { ANCON2bits.ANSEL22 = 1; } while(0) +#define OUTPUT2_SetDigitalMode() do { ANCON2bits.ANSEL22 = 0; } while(0) + +// get/set OUTPUT3 aliases +#define OUTPUT3_TRIS TRISHbits.TRISH2 +#define OUTPUT3_LAT LATHbits.LATH2 +#define OUTPUT3_PORT PORTHbits.RH2 +#define OUTPUT3_ANS ANCON2bits.ANSEL21 +#define OUTPUT3_SetHigh() do { LATHbits.LATH2 = 1; } while(0) +#define OUTPUT3_SetLow() do { LATHbits.LATH2 = 0; } while(0) +#define OUTPUT3_Toggle() do { LATHbits.LATH2 = ~LATHbits.LATH2; } while(0) +#define OUTPUT3_GetValue() PORTHbits.RH2 +#define OUTPUT3_SetDigitalInput() do { TRISHbits.TRISH2 = 1; } while(0) +#define OUTPUT3_SetDigitalOutput() do { TRISHbits.TRISH2 = 0; } while(0) +#define OUTPUT3_SetAnalogMode() do { ANCON2bits.ANSEL21 = 1; } while(0) +#define OUTPUT3_SetDigitalMode() do { ANCON2bits.ANSEL21 = 0; } while(0) + +// get/set OUTPUT4 aliases +#define OUTPUT4_TRIS TRISHbits.TRISH3 +#define OUTPUT4_LAT LATHbits.LATH3 +#define OUTPUT4_PORT PORTHbits.RH3 +#define OUTPUT4_ANS ANCON2bits.ANSEL20 +#define OUTPUT4_SetHigh() do { LATHbits.LATH3 = 1; } while(0) +#define OUTPUT4_SetLow() do { LATHbits.LATH3 = 0; } while(0) +#define OUTPUT4_Toggle() do { LATHbits.LATH3 = ~LATHbits.LATH3; } while(0) +#define OUTPUT4_GetValue() PORTHbits.RH3 +#define OUTPUT4_SetDigitalInput() do { TRISHbits.TRISH3 = 1; } while(0) +#define OUTPUT4_SetDigitalOutput() do { TRISHbits.TRISH3 = 0; } while(0) +#define OUTPUT4_SetAnalogMode() do { ANCON2bits.ANSEL20 = 1; } while(0) +#define OUTPUT4_SetDigitalMode() do { ANCON2bits.ANSEL20 = 0; } while(0) + +// get/set OUTPUT5 aliases +#define OUTPUT5_TRIS TRISHbits.TRISH4 +#define OUTPUT5_LAT LATHbits.LATH4 +#define OUTPUT5_PORT PORTHbits.RH4 +#define OUTPUT5_ANS ANCON1bits.ANSEL12 +#define OUTPUT5_SetHigh() do { LATHbits.LATH4 = 1; } while(0) +#define OUTPUT5_SetLow() do { LATHbits.LATH4 = 0; } while(0) +#define OUTPUT5_Toggle() do { LATHbits.LATH4 = ~LATHbits.LATH4; } while(0) +#define OUTPUT5_GetValue() PORTHbits.RH4 +#define OUTPUT5_SetDigitalInput() do { TRISHbits.TRISH4 = 1; } while(0) +#define OUTPUT5_SetDigitalOutput() do { TRISHbits.TRISH4 = 0; } while(0) +#define OUTPUT5_SetAnalogMode() do { ANCON1bits.ANSEL12 = 1; } while(0) +#define OUTPUT5_SetDigitalMode() do { ANCON1bits.ANSEL12 = 0; } while(0) + +// get/set OUTPUT6 aliases +#define OUTPUT6_TRIS TRISHbits.TRISH5 +#define OUTPUT6_LAT LATHbits.LATH5 +#define OUTPUT6_PORT PORTHbits.RH5 +#define OUTPUT6_ANS ANCON1bits.ANSEL13 +#define OUTPUT6_SetHigh() do { LATHbits.LATH5 = 1; } while(0) +#define OUTPUT6_SetLow() do { LATHbits.LATH5 = 0; } while(0) +#define OUTPUT6_Toggle() do { LATHbits.LATH5 = ~LATHbits.LATH5; } while(0) +#define OUTPUT6_GetValue() PORTHbits.RH5 +#define OUTPUT6_SetDigitalInput() do { TRISHbits.TRISH5 = 1; } while(0) +#define OUTPUT6_SetDigitalOutput() do { TRISHbits.TRISH5 = 0; } while(0) +#define OUTPUT6_SetAnalogMode() do { ANCON1bits.ANSEL13 = 1; } while(0) +#define OUTPUT6_SetDigitalMode() do { ANCON1bits.ANSEL13 = 0; } while(0) + +// get/set OUTPUT7 aliases +#define OUTPUT7_TRIS TRISHbits.TRISH6 +#define OUTPUT7_LAT LATHbits.LATH6 +#define OUTPUT7_PORT PORTHbits.RH6 +#define OUTPUT7_ANS ANCON1bits.ANSEL14 +#define OUTPUT7_SetHigh() do { LATHbits.LATH6 = 1; } while(0) +#define OUTPUT7_SetLow() do { LATHbits.LATH6 = 0; } while(0) +#define OUTPUT7_Toggle() do { LATHbits.LATH6 = ~LATHbits.LATH6; } while(0) +#define OUTPUT7_GetValue() PORTHbits.RH6 +#define OUTPUT7_SetDigitalInput() do { TRISHbits.TRISH6 = 1; } while(0) +#define OUTPUT7_SetDigitalOutput() do { TRISHbits.TRISH6 = 0; } while(0) +#define OUTPUT7_SetAnalogMode() do { ANCON1bits.ANSEL14 = 1; } while(0) +#define OUTPUT7_SetDigitalMode() do { ANCON1bits.ANSEL14 = 0; } while(0) + +// get/set OUTPUT8 aliases +#define OUTPUT8_TRIS TRISHbits.TRISH7 +#define OUTPUT8_LAT LATHbits.LATH7 +#define OUTPUT8_PORT PORTHbits.RH7 +#define OUTPUT8_ANS ANCON1bits.ANSEL15 +#define OUTPUT8_SetHigh() do { LATHbits.LATH7 = 1; } while(0) +#define OUTPUT8_SetLow() do { LATHbits.LATH7 = 0; } while(0) +#define OUTPUT8_Toggle() do { LATHbits.LATH7 = ~LATHbits.LATH7; } while(0) +#define OUTPUT8_GetValue() PORTHbits.RH7 +#define OUTPUT8_SetDigitalInput() do { TRISHbits.TRISH7 = 1; } while(0) +#define OUTPUT8_SetDigitalOutput() do { TRISHbits.TRISH7 = 0; } while(0) +#define OUTPUT8_SetAnalogMode() do { ANCON1bits.ANSEL15 = 1; } while(0) +#define OUTPUT8_SetDigitalMode() do { ANCON1bits.ANSEL15 = 0; } while(0) + +/** + @Param + none + @Returns + none + @Description + GPIO and peripheral I/O initialization + @Example + PIN_MANAGER_Initialize(); + */ +void PIN_MANAGER_Initialize (void); + +/** + * @Param + none + * @Returns + none + * @Description + Interrupt on Change Handling routine + * @Example + PIN_MANAGER_IOC(); + */ +void PIN_MANAGER_IOC(void); + + + +#endif // PIN_MANAGER_H +/** + End of File +*/ \ No newline at end of file diff --git a/src/mcc_generated_files/tmr0.c b/src/mcc_generated_files/tmr0.c new file mode 100644 index 0000000..ec5cb1a --- /dev/null +++ b/src/mcc_generated_files/tmr0.c @@ -0,0 +1,167 @@ +/** + TMR0 Generated Driver File + + @Company + Microchip Technology Inc. + + @File Name + tmr0.c + + @Summary + This is the generated driver implementation file for the TMR0 driver using PIC10 / PIC12 / PIC16 / PIC18 MCUs + + @Description + This source file provides APIs for TMR0. + Generation Information : + Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8 + Device : PIC18F86K22 + Driver Version : 2.01 + The generated drivers are tested against the following: + Compiler : XC8 2.36 and above + MPLAB : MPLAB X 6.00 +*/ + +/* + (c) 2018 Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip software and any + derivatives exclusively with Microchip products. It is your responsibility to comply with third party + license terms applicable to your use of third party software (including open source software) that + may accompany Microchip software. + + THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER + EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY + IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS + FOR A PARTICULAR PURPOSE. + + IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND + WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP + HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO + THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL + CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT + OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS + SOFTWARE. +*/ + +/** + Section: Included Files +*/ + +#include +#include "tmr0.h" + +/** + Section: Global Variables Definitions +*/ + +void (*TMR0_InterruptHandler)(void); + +volatile uint16_t timer0ReloadVal; + +/** + Section: TMR0 APIs +*/ + + +void TMR0_Initialize(void) +{ + // Set TMR0 to the options selected in the User Interface + + //Enable 16bit timer mode before assigning value to TMR0H + T0CONbits.T08BIT = 0; + + // TMR0H 99; + TMR0H = 0x63; + + // TMR0L 191; + TMR0L = 0xBF; + + + // Load TMR0 value to the 16-bit reload variable + timer0ReloadVal = (uint16_t)((TMR0H << 8) | TMR0L); + + // Clear Interrupt flag before enabling the interrupt + INTCONbits.TMR0IF = 0; + + // Enabling TMR0 interrupt. + INTCONbits.TMR0IE = 1; + + // Set Default Interrupt Handler + TMR0_SetInterruptHandler(TMR0_DefaultInterruptHandler); + + // T0PS 1:4; T08BIT 16-bit; T0SE Increment_hi_lo; T0CS FOSC/4; TMR0ON enabled; PSA assigned; + T0CON = 0x91; +} + +void TMR0_StartTimer(void) +{ + // Start the Timer by writing to TMR0ON bit + T0CONbits.TMR0ON = 1; +} + +void TMR0_StopTimer(void) +{ + // Stop the Timer by writing to TMR0ON bit + T0CONbits.TMR0ON = 0; +} + +uint16_t TMR0_ReadTimer(void) +{ + uint16_t readVal; + uint8_t readValLow; + uint8_t readValHigh; + + readValLow = TMR0L; + readValHigh = TMR0H; + readVal = ((uint16_t)readValHigh << 8) + readValLow; + + return readVal; +} + +void TMR0_WriteTimer(uint16_t timerVal) +{ + // Write to the Timer0 register + TMR0H = timerVal >> 8; + TMR0L = (uint8_t) timerVal; +} + +void TMR0_Reload(void) +{ + // Write to the Timer0 register + TMR0H = timer0ReloadVal >> 8; + TMR0L = (uint8_t) timer0ReloadVal; +} + +void TMR0_ISR(void) +{ + + // clear the TMR0 interrupt flag + INTCONbits.TMR0IF = 0; + + // reload TMR0 + // Write to the Timer0 register + TMR0H = timer0ReloadVal >> 8; + TMR0L = (uint8_t) timer0ReloadVal; + + if(TMR0_InterruptHandler) + { + TMR0_InterruptHandler(); + } + + // add your TMR0 interrupt custom code +} + + +void TMR0_SetInterruptHandler(void (* InterruptHandler)(void)){ + TMR0_InterruptHandler = InterruptHandler; +} + +void TMR0_DefaultInterruptHandler(void){ + // add your TMR0 interrupt custom code + // or set custom function using TMR0_SetInterruptHandler() +} + +/** + End of File +*/ \ No newline at end of file diff --git a/src/mcc_generated_files/tmr0.h b/src/mcc_generated_files/tmr0.h new file mode 100644 index 0000000..54e4a8d --- /dev/null +++ b/src/mcc_generated_files/tmr0.h @@ -0,0 +1,356 @@ +/** + TMR0 Generated Driver API Header File + + @Company + Microchip Technology Inc. + + @File Name + tmr0.h + + @Summary + This is the generated header file for the TMR0 driver using PIC10 / PIC12 / PIC16 / PIC18 MCUs + + @Description + This header file provides APIs for TMR0. + Generation Information : + Product Revision : PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8 + Device : PIC18F86K22 + Driver Version : 2.01 + The generated drivers are tested against the following: + Compiler : XC8 2.36 and above + MPLAB : MPLAB X 6.00 +*/ + +/* + (c) 2018 Microchip Technology Inc. and its subsidiaries. + + Subject to your compliance with these terms, you may use Microchip software and any + derivatives exclusively with Microchip products. It is your responsibility to comply with third party + license terms applicable to your use of third party software (including open source software) that + may accompany Microchip software. + + THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER + EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY + IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS + FOR A PARTICULAR PURPOSE. + + IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, + INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND + WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP + HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO + THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL + CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT + OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS + SOFTWARE. +*/ + +#ifndef TMR0_H +#define TMR0_H + +/** + Section: Included Files +*/ + +#include +#include + +#ifdef __cplusplus // Provide C++ Compatibility + + extern "C" { + +#endif + + + +/** + Section: TMR0 APIs +*/ + +/** + @Summary + Initializes the TMR0. + + @Description + This function initializes the TMR0 Registers. + This function must be called before any other TMR0 function is called. + + @Preconditions + None + + @Param + None + + @Returns + None + + @Comment + + + @Example + + main() + { + // Initialize TMR0 module + TMR0_Initialize(); + + // Do something else... + } + +*/ +void TMR0_Initialize(void); + +/** + @Summary + This function starts the TMR0. + + @Description + This function starts the TMR0 operation. + This function must be called after the initialization of TMR0. + + @Preconditions + Initialize the TMR0 before calling this function. + + @Param + None + + @Returns + None + + @Example + + // Initialize TMR0 module + + // Start TMR0 + TMR0_StartTimer(); + + // Do something else... + +*/ +void TMR0_StartTimer(void); + +/** + @Summary + This function stops the TMR0. + + @Description + This function stops the TMR0 operation. + This function must be called after the start of TMR0. + + @Preconditions + Initialize the TMR0 before calling this function. + + @Param + None + + @Returns + None + + @Example + + // Initialize TMR0 module + + // Start TMR0 + TMR0_StartTimer(); + + // Do something else... + + // Stop TMR0; + TMR0_StopTimer(); + +*/ +void TMR0_StopTimer(void); + + +/** + @Summary + Reads the 16 bits TMR0 register value. + + @Description + This function reads the 16 bits TMR0 register value and return it. + + @Preconditions + Initialize the TMR0 before calling this function. + + @Param + None + + @Returns + This function returns the 16 bits value of TMR0 register. + + @Example + + // Initialize TMR0 module + + // Start TMR0 + TMR0_StartTimer(); + + // Read the current value of TMR0 + if(0 == TMR0_ReadTimer()) + { + // Do something else... + + // Reload the TMR value + TMR0_Reload(); + } + +*/ +uint16_t TMR0_ReadTimer(void); + +/** + @Summary + Writes the 16 bits value to TMR0 register. + + @Description + This function writes the 16 bits value to TMR0 register. + This function must be called after the initialization of TMR0. + + @Preconditions + Initialize the TMR0 before calling this function. + + @Param + timerVal - Value to write into TMR0 register. + + @Returns + None + + @Example + + #define PERIOD 0x8000 + #define ZERO 0x0000 + + while(1) + { + //Read the TMR0 register + if(ZERO == TMR0_ReadTimer()) + { + // Do something else... + + // Write the TMR0 register + TMR0_WriteTimer(PERIOD); + } + + // Do something else... + } + +*/ +void TMR0_WriteTimer(uint16_t timerVal); + +/** + @Summary + Reload the 16 bits value to TMR0 register. + + @Description + This function reloads the 16 bit value to TMR0 register. + This function must be called to write initial value into TMR0 register. + + @Preconditions + Initialize the TMR0 before calling this function. + + @Param + None + + @Returns + None + + @Example + + while(1) + { + if(TMR0IF) + { + // Do something else... + + // clear the TMR0 interrupt flag + TMR0IF = 0; + + // Reload the initial value of TMR0 + TMR0_Reload(); + } + } + +*/ +void TMR0_Reload(void); + +/** + @Summary + Timer Interrupt Service Routine + + @Description + Timer Interrupt Service Routine is called by the Interrupt Manager. + + @Preconditions + Initialize the TMR0 module with interrupt before calling this isr. + + @Param + None + + @Returns + None + */ +void TMR0_ISR(void); + + +/** + @Summary + Set Timer Interrupt Handler + + @Description + This sets the function to be called during the ISR + + @Preconditions + Initialize the TMR0 module with interrupt before calling this. + + @Param + Address of function to be set + + @Returns + None +*/ + void TMR0_SetInterruptHandler(void (* InterruptHandler)(void)); + +/** + @Summary + Timer Interrupt Handler + + @Description + This is a function pointer to the function that will be called during the ISR + + @Preconditions + Initialize the TMR0 module with interrupt before calling this isr. + + @Param + None + + @Returns + None +*/ +extern void (*TMR0_InterruptHandler)(void); + +/** + @Summary + Default Timer Interrupt Handler + + @Description + This is the default Interrupt Handler function + + @Preconditions + Initialize the TMR0 module with interrupt before calling this isr. + + @Param + None + + @Returns + None +*/ +void TMR0_DefaultInterruptHandler(void); + +#ifdef __cplusplus // Provide C++ Compatibility + + } + +#endif + +#endif // TMR0_H +/** + End of File +*/ \ No newline at end of file diff --git a/src/template.c b/src/template.c new file mode 100644 index 0000000..abb8840 --- /dev/null +++ b/src/template.c @@ -0,0 +1,54 @@ +/** + * @author Rémi Heredero + * @version 1.0.0 + * @date July 2023 + * @file ${FILENAME}.c + */ + +#include "${FILENAME}.h" + +void ${FILENAME}_init(${FILENAME}* me){ + me->state = ST${FN}_INIT; +} + +void ${FILENAME}_startBehaviour(${FILENAME}* me){ + POST(me, &${FILENAME}_processEvent, ev${FN}init, 0, 0); +} + +bool ${FILENAME}_processEvent(Event* ev) { + bool processed = false; + ${FILENAME}* me = (${FILENAME}*)Event_getTarget(ev); + switch (me->state) { // onState + case ST${FN}_INIT: + if (ev->id == ev${FN}init) { + me->state = ST${FN}_{WAIT_STATE}; + } + break; + {STATES} + } + + if(oldState != me->state){ + switch (oldState) { // onExit + case ST${FN}_INIT: + break; + {STATES} + } + + switch (me->state) { // onEntry + case ST${FN}_INIT: + break; + {STATES} + } + + processed = true; + } + return processed; +} + +void ${FILENAME}_set{VAR}(${FILENAME}*me, uint16_t t) { + me->tON = t; +} + +void ${FILENAME}_emit${EVENT}(${FILENAME}*me) { + POST(me, &${FILENAME}_processEvent, ev${FN}${EVENT}, 0, 0); +} \ No newline at end of file diff --git a/src/template.h b/src/template.h new file mode 100644 index 0000000..f6bda9d --- /dev/null +++ b/src/template.h @@ -0,0 +1,54 @@ +/** + * @author Rémi Heredero + * @version 1.0.0 + * @date July 2023 + * @file ${FILENAME}.h + */ +#ifndef ${FILENAME}_H +#define ${FILENAME}_H + +#include "../xf/xf.h" + +typedef enum{ + ST${FN}_INIT, + {STATES} +} ${FILENAME}_STATES; + +typedef enum{ + ev${FN}init = 100, // TODO change this number + {EVENTS} +} ${FILENAME}_EVENTS; + +typedef struct{ + ${FILENAME}_STATES state; +} ${FILENAME}; + +/** + * Initialize the ${FILENAME} + * @param me the ${FILENAME} itself + */ +void ${FILENAME}_init(${FILENAME}* me); + +/** + * Start the ${FILENAME} state machine + * @param me the ${FILENAME} itself + */ +void ${FILENAME}_startBehaviour(${FILENAME}* me); + +/** + * Process the event + * @param ev the event to process + * @return true if the event is processed + */ +bool ${FILENAME}_processEvent(Event* ev); + +void ${FILENAME}_set{TIMEON}(${FILENAME}*me, uint16_t t); + +/** + * Emit the ${EVENT} event + * @param me the ${FILENAME} itself + */ +void ${FILENAME}_emit${EVENT}(${FILENAME}*me); + + +#endif diff --git a/src/xf/event.c b/src/xf/event.c new file mode 100644 index 0000000..a93c749 --- /dev/null +++ b/src/xf/event.c @@ -0,0 +1,91 @@ + +/* +* Model: XFT.qm +* File: ${.::xf::event.c} +* +* This code has been generated by QM 5.2.5 . +* DO NOT EDIT SECTIONS BETWEEN THE COMMENTS "$...vvv".."$end...^^^". +* All your changes in these sections will be lost. +* +* SPDX-License-Identifier: GPL-3.0-or-later +* +* This generated code is open source software: you can redistribute it under +* the terms of the GNU General Public License as published by the Free +* Software Foundation. +* +* This code is distributed in the hope that it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* NOTE: +* Alternatively, this generated code may be distributed under the terms +* of Quantum Leaps commercial licenses, which expressly supersede the GNU +* General Public License and are specifically designed for licensees +* interested in retaining the proprietary status of their code. +* +* Contact information: +* +* +*/ +#include "event.h" +#define NULL ((void*)(0)) + +void Event_init(struct Event_* me) +{ + me->id = NULLEVENT; + me->delay = 0; + me->target = NULL; + me->data = 0x0; + me->processEvent = NULL; +} + +void Event_setData(Event* me, int64_t data) +{ + me->data = data; +} + +int64_t Event_getData(Event* me) +{ + return me->data; +} + +void Event_setPE(Event* me, processEventT processEvent) +{ + me->processEvent = processEvent; +} + +void Event_setTarget(Event* me, void* target) +{ + me->target = target; +} + +processEventT Event_getPE(Event* me) +{ + return me->processEvent; +} + +void* Event_getTarget(Event* me) +{ + return me->target; +} + +void Event_setId(Event* me, evIDT eventID) +{ + me->id = eventID; +} + +evIDT Event_getId(Event* me) +{ + return me->id; +} + +void Event_setDelay(Event* me, uint16_t delay) +{ + me->delay = delay; +} + +uint16_t Event_getDelay(Event* me) +{ + return me->delay; +} diff --git a/src/xf/event.h b/src/xf/event.h new file mode 100644 index 0000000..164c384 --- /dev/null +++ b/src/xf/event.h @@ -0,0 +1,35 @@ +#include +#include +#include "ireactive.h" + +#ifndef EVENT_ONCE +#define EVENT_ONCE + +typedef uint8_t evIDT; +#define NULLEVENT 0 // no event + +struct Event_ +{ + evIDT id; + processEventT processEvent; + void* target; + uint16_t delay; + int64_t data; +}; + +typedef struct Event_ Event; + +//public methods +void Event_init(Event* me); +void Event_setTarget(Event* me, void* target); +void Event_setPE(Event* me, processEventT processEvent); +void* Event_getTarget(Event* me); +processEventT Event_getPE(Event* me); +void Event_setId(Event* me, evIDT eventID); +evIDT Event_getId(Event* me); +void Event_setDelay(Event* me, uint16_t delay); +uint16_t Event_getDelay(Event* me); +void Event_setData(Event* me, int64_t data); +int64_t Event_getData(Event* me); + +#endif diff --git a/src/xf/ireactive.h b/src/xf/ireactive.h new file mode 100644 index 0000000..8e23e99 --- /dev/null +++ b/src/xf/ireactive.h @@ -0,0 +1,8 @@ +#ifndef IREACTIVE_ONCE +#define IREACTIVE_ONCE + +struct Event_; + +typedef bool (*processEventT)(struct Event_* ev); + +#endif diff --git a/src/xf/xf.c b/src/xf/xf.c new file mode 100644 index 0000000..114c723 --- /dev/null +++ b/src/xf/xf.c @@ -0,0 +1,282 @@ +#include "xf.h" +#include "../mcc_generated_files/mcc.h" + +/* + * private methods of the XF + */ + +/******************************************************************************/ +/* FUNCTION : Push an event on the events queue */ +/* INPUT : ev - the event number (not 0) */ +/* inISR - (true if called in an ISR, else false) */ +/* OUTPUT : return false if the queue was full, else true */ +/* COMMENTS : - */ +/******************************************************************************/ +bool XF_pushEvent(Event ev, bool inISR, TimerID* tmid); +/******************************************************************************/ +/* FUNCTION : Pop an event on the events queue */ +/* INPUT : inISR - (true if called in an ISR, else false) */ +/* OUTPUT : return the next waiting event if any, else 0 */ +/* COMMENTS : - */ +/******************************************************************************/ +Event XF_popEvent(bool inISR); +/******************************************************************************/ +/* FUNCTION : Post a timer in timers queue */ +/* INPUT : tm - time before event arrives */ +/* ev - event to post */ +/* inISR - (true if called in an ISR, else false) */ +/* OUTPUT : return the timer Id used */ +/* COMMENTS : - */ +/******************************************************************************/ +TimerID XF_scheduleTimer(Time tm, Event ev, bool inISR); + +/******************************************************************************/ +/* FUNCTION : Switch of the interrupts */ +/* INPUT : inISR - (true if called in an ISR, else f */ +/* OUTPUT : none */ +/* COMMENTS : - */ +/******************************************************************************/ +static void ENTERCRITICAL(bool inISR); +/******************************************************************************/ +/* FUNCTION : Switch on the interrupts */ +/* INPUT : inISR - (true if called in an ISR, else f */ +/* OUTPUT : none */ +/* COMMENTS : - */ +/******************************************************************************/ +static void LEAVECRITICAL(bool inISR); + + +/* + * the XF instance + */ +XF theXF; // really the XF + + + +/******************************************************************************/ +/* FUNCTION : Init the XF structure */ +/* INPUT : - */ +/* OUTPUT : - */ +/* COMMENTS : Have to be called once */ +/******************************************************************************/ +void XF_init() +{ + int i; + for (i=0; i 0) + { + Event_setDelay(&ev,0); + *tmid = XF_scheduleTimer(tm, ev, inISR); + } + else + { + ENTERCRITICAL(inISR); + + temp = (theXF.in+1) % (uint8_t)(sizeof(theXF.eventQueue) / sizeof(Event)); + if(temp == theXF.out) + { + LEAVECRITICAL(inISR); + return false; + } + theXF.eventQueue[theXF.in] = ev; + theXF.in = temp; + LEAVECRITICAL(inISR); + } + return true; +} + +/******************************************************************************/ +/* FUNCTION : Pop an event on the events queue */ +/* INPUT : inISR - (true if called in an ISR, else false) */ +/* OUTPUT : return the next waiting event if any, else 0 */ +/* COMMENTS : - */ +/******************************************************************************/ +Event XF_popEvent(bool inISR) +{ + Event ev; + ev.id = NULLEVENT; + ev.target = NULL; + ev.processEvent = NULL; + + ENTERCRITICAL(inISR); + if(theXF.in == theXF.out) + { + LEAVECRITICAL(inISR); + return ev; + } + ev = theXF.eventQueue[theXF.out]; + theXF.out = (theXF.out + 1)%(uint8_t)(sizeof(theXF.eventQueue) / sizeof(Event)); + LEAVECRITICAL(inISR); + return ev; +} + +/******************************************************************************/ +/* FUNCTION : Post a timer in timers queue */ +/* INPUT : tm - time before event arrives */ +/* ev - event to post */ +/* inISR - (true if called in an ISR, else false) */ +/* OUTPUT : return the timer Id used */ +/* COMMENTS : - */ +/******************************************************************************/ +TimerID XF_scheduleTimer(Time tm, Event ev, bool inISR) +{ + uint8_t i; + + ENTERCRITICAL(inISR); + for (i=0; i. +* DO NOT EDIT SECTIONS BETWEEN THE COMMENTS "$...vvv".."$end...^^^". +* All your changes in these sections will be lost. +* +* SPDX-License-Identifier: GPL-3.0-or-later +* +* This generated code is open source software: you can redistribute it under +* the terms of the GNU General Public License as published by the Free +* Software Foundation. +* +* This code is distributed in the hope that it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* NOTE: +* Alternatively, this generated code may be distributed under the terms +* of Quantum Leaps commercial licenses, which expressly supersede the GNU +* General Public License and are specifically designed for licensees +* interested in retaining the proprietary status of their code. +* +* Contact information: +* +* +*/ +/******************************************************************************/ +/* FILENAME : xf.h */ +/*----------------------------------------------------------------------------*/ +/* GOAL : Offers the femto XF functions */ +/*----------------------------------------------------------------------------*/ +/* AUTHOR : Medard Rieder / Pascal Sartoretti */ +/*----------------------------------------------------------------------------*/ +/* DATE: : original (Medard Rieder 08.2011) */ +/* corrections & simplified (Pascal Sartoretti 06.2016) */ +/******************************************************************************/ +#ifndef XF_DEF +#define XF_DEF + +#include // usage of standard types +#include // usage of boolean types +#include "../mcc_generated_files/mcc.h" +#include "event.h" + +#define Time uint16_t // time type +#define TimerID uint8_t // identifier of timer (position in buffer) + +typedef struct Timer_ // timer structure +{ + Time tm; // time + Event ev; // event to post +} Timer; +/*----------------------------------------------------------------------------*/ +/* depending on usage, change MAXTIMER and MAXEVENT */ +/*----------------------------------------------------------------------------*/ +#define MAXTIMER 8 // number of timers in our system +#define MAXEVENT 12 // number of events in our system + +#define NULLTIMER 0 // no value for time +#define TICKINTERVAL 10 // this is the ticktimers duration + + +/*----------------------------------------------------------------------------*/ +typedef struct XF // the XF structure +{ + Timer timerList[MAXTIMER]; // the timers + Event eventQueue[MAXEVENT]; // the events + uint8_t in; // the events in pointer + uint8_t out; // the events out pointer +} XF; + +/******************************************************************************/ +/* FUNCTION : Init the XF structure */ +/* INPUT : - */ +/* OUTPUT : - */ +/* COMMENTS : Have to be called once */ +/******************************************************************************/ +void XF_init(); + +/******************************************************************************/ +/* FUNCTION : Remove a timer in timers queue */ +/* INPUT : id - the timer id to remove */ +/* inISR - (true if called in an ISR, else false) */ +/* OUTPUT : - */ +/* COMMENTS : - */ +/******************************************************************************/ +void XF_unscheduleTimer(TimerID id, bool inISR); +/******************************************************************************/ +/* FUNCTION : Decrement timers to post events if time elapsed */ +/* INPUT : - */ +/* OUTPUT : - */ +/* COMMENTS : This function has to be called from the timer ISR */ +/******************************************************************************/ +void XF_decrementAndQueueTimers(); + +/********************************************************************************/ +/* FUNCTION : POST an Event */ +/* INPUT : target - the address of the object with the state machine */ +/* processEvent - function pointer of the state machine function */ +/* id - the id of the event */ +/* delay - the delay if the event is a timeout event */ +/* data - user data */ +/* OUTPUT : TimerId - the id of the timeout if the event is a timeout */ +/* COMMENTS : */ +/********************************************************************************/ +TimerID POST(void* target, processEventT processEvent, uint8_t id, Time delay, int64_t data); + +void XF_executeOnce(); +#endif +