Initial commit
This commit is contained in:
		
							
								
								
									
										29
									
								
								306-controller_interface.X/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								306-controller_interface.X/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,29 @@ | |||||||
|  | # .gitignore file | ||||||
|  |  | ||||||
|  | # MPLAB X IDE (Netbeans) specific | ||||||
|  | ~*.* | ||||||
|  | build/ | ||||||
|  | debug/ | ||||||
|  | dist/ | ||||||
|  | disassembly/ | ||||||
|  | nbproject/private/ | ||||||
|  | nbproject/*.mk | ||||||
|  | nbproject/*.bash | ||||||
|  | nbproject/Makefile-genesis.properties | ||||||
|  |  | ||||||
|  | # Object files | ||||||
|  | *.o | ||||||
|  | *.ko | ||||||
|  | *.obj | ||||||
|  | *.elf | ||||||
|  |  | ||||||
|  | # Executables | ||||||
|  | *.exe | ||||||
|  |  | ||||||
|  |  | ||||||
|  | # KDE specific | ||||||
|  | .directory | ||||||
|  |  | ||||||
|  | # Misc | ||||||
|  | .svn | ||||||
|  | *.bak | ||||||
							
								
								
									
										113
									
								
								306-controller_interface.X/Makefile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										113
									
								
								306-controller_interface.X/Makefile
									
									
									
									
									
										Normal file
									
								
							| @@ -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 | ||||||
							
								
								
									
										25
									
								
								306-controller_interface.X/app/blcontrol.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								306-controller_interface.X/app/blcontrol.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,25 @@ | |||||||
|  | #include "blcontrol.h" | ||||||
|  | #include "../mcc_generated_files/mcc.h" | ||||||
|  | #include "../factory/factory.h" | ||||||
|  | //private methods | ||||||
|  |  | ||||||
|  | void BLControl_init(BLControl* me) | ||||||
|  | { | ||||||
|  |     //nothing to do yet | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void BLControl_onButton(void * me, uint8_t buttonId, bool pressed) | ||||||
|  | { | ||||||
|  |     BLControl* realMe = (BLControl*)me; | ||||||
|  |     if (buttonId == BID) | ||||||
|  |     { | ||||||
|  |         if (pressed)     | ||||||
|  |         { | ||||||
|  |             LED_on(l()); | ||||||
|  |         } | ||||||
|  |         else | ||||||
|  |         { | ||||||
|  |             LED_off(l()); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										19
									
								
								306-controller_interface.X/app/blcontrol.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								306-controller_interface.X/app/blcontrol.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,19 @@ | |||||||
|  | #ifndef BLCONTROL_DEF | ||||||
|  | #define BLCONTROL_DEF | ||||||
|  |  | ||||||
|  | #include <stdint.h> | ||||||
|  | #include <stdbool.h> | ||||||
|  | #include "../xf/xf.h" | ||||||
|  | #include "../board/button/buttonsm.h" | ||||||
|  |  | ||||||
|  | struct BLControl_ | ||||||
|  | { | ||||||
|  |      | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | typedef struct BLControl_ BLControl; | ||||||
|  |  | ||||||
|  | void BLControl_init(BLControl* me); | ||||||
|  | void BLControl_onButton(void* me, uint8_t buttonId, bool pressed); | ||||||
|  |  | ||||||
|  | #endif | ||||||
							
								
								
									
										66
									
								
								306-controller_interface.X/board/button/button.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										66
									
								
								306-controller_interface.X/board/button/button.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,66 @@ | |||||||
|  |  | ||||||
|  | #include "button.h" | ||||||
|  | #include "../../mcc_generated_files/pin_manager.h" | ||||||
|  |  | ||||||
|  | void Button_init(Button* me, uint8_t id, bool isPullUp) | ||||||
|  | { | ||||||
|  |     me->id = id; | ||||||
|  |     me->isPullUp = isPullUp; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * @brief Initialize the Driver | ||||||
|  |  *  | ||||||
|  |  */ | ||||||
|  | void Button_initHW(Button* me) | ||||||
|  | { | ||||||
|  | } | ||||||
|  |  | ||||||
|  | //read the state of the button | ||||||
|  | //maybe you have to adjust the  | ||||||
|  | //low level calls | ||||||
|  | uint8_t Button_read(Button* me) | ||||||
|  | { | ||||||
|  |     uint8_t value = LOW; | ||||||
|  |     switch (me->id) | ||||||
|  |     { | ||||||
|  |         case 1: | ||||||
|  |             value = IO_RA7_GetValue(); | ||||||
|  |         break; | ||||||
|  |         case 2: | ||||||
|  |         break; | ||||||
|  |         case 3: | ||||||
|  |         break; | ||||||
|  |         case 4: | ||||||
|  |         break; | ||||||
|  |         case 5: | ||||||
|  |         break; | ||||||
|  |         case 6: | ||||||
|  |         break; | ||||||
|  |         case 7: | ||||||
|  |         break; | ||||||
|  |         case 8: | ||||||
|  |         break; | ||||||
|  |         case 9: | ||||||
|  |         break; | ||||||
|  |         case 10: | ||||||
|  |         break;     | ||||||
|  |     } | ||||||
|  |     if (me->isPullUp == true) | ||||||
|  |     { | ||||||
|  |         value=value==LOW?HIGH:LOW; | ||||||
|  |     } | ||||||
|  |     return value; | ||||||
|  |   } | ||||||
|  |  | ||||||
|  | //id getter | ||||||
|  | uint8_t Button_getId(Button* me) | ||||||
|  | { | ||||||
|  |     return me->id; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | //id setter | ||||||
|  | void Button_setId(Button* me, uint8_t id) | ||||||
|  | { | ||||||
|  |     me->id = id; | ||||||
|  | } | ||||||
							
								
								
									
										25
									
								
								306-controller_interface.X/board/button/button.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								306-controller_interface.X/board/button/button.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,25 @@ | |||||||
|  | #ifndef Button_ONCE | ||||||
|  | #define Button_ONCE | ||||||
|  |  | ||||||
|  | #include <stdint.h> | ||||||
|  | #include <stdbool.h> | ||||||
|  |  | ||||||
|  | /* | ||||||
|  |  * this is the declaration of the Button class | ||||||
|  |  */ | ||||||
|  |  | ||||||
|  | struct Button_ | ||||||
|  | { | ||||||
|  |   uint8_t id; | ||||||
|  |   bool isPullUp; | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | typedef struct Button_ Button; | ||||||
|  |  | ||||||
|  | void Button_init(Button* me, uint8_t id, bool isPullUp); | ||||||
|  | void Button_initHW(Button* me); | ||||||
|  | uint8_t Button_read(Button* me); | ||||||
|  | void Button_setId(Button* me, uint8_t id); | ||||||
|  | uint8_t Button_getId(Button* me); | ||||||
|  |  | ||||||
|  | #endif | ||||||
							
								
								
									
										129
									
								
								306-controller_interface.X/board/button/buttonsm.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										129
									
								
								306-controller_interface.X/board/button/buttonsm.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,129 @@ | |||||||
|  | #include "buttonsm.h" | ||||||
|  |  | ||||||
|  | /* | ||||||
|  |  * this is the init method of the ButtonSM class | ||||||
|  |  */ | ||||||
|  | void ButtonSM_init(ButtonSM* me, Button* button) | ||||||
|  | { | ||||||
|  |     me->state = ST_BSMINIT; | ||||||
|  |     me->button = button; | ||||||
|  |  | ||||||
|  |     me->actualState = ST_BSMINIT; | ||||||
|  |     me->observer = NULL; | ||||||
|  |     me->observerCB = NULL; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | /* | ||||||
|  |  * this is the state machine method of the ButtonSM class | ||||||
|  |  */ | ||||||
|  | bool ButtonSM_processEvent(Event* ev) | ||||||
|  | { | ||||||
|  |     ButtonSM* me = (ButtonSM*)ev->target; | ||||||
|  |     bool processed = false; | ||||||
|  |     BSMState oldState = me->state; | ||||||
|  |        | ||||||
|  |     switch (me->state) | ||||||
|  |     { | ||||||
|  |         case ST_BSMINIT: | ||||||
|  |             if (Event_getId(ev) == evBSMInit) | ||||||
|  |             { | ||||||
|  |                 me->state = ST_BSMWAIT; | ||||||
|  |             }  | ||||||
|  |         break; | ||||||
|  |         case ST_BSMWAIT: | ||||||
|  |                 if (Event_getId(ev) == evBSMPollTM) | ||||||
|  |             { | ||||||
|  |                 me->state = ST_BSMPOLL; | ||||||
|  |             }            | ||||||
|  |         break; | ||||||
|  |         case ST_BSMPOLL: | ||||||
|  |             if (Event_getId(ev) == evBSMDefault) | ||||||
|  |             { | ||||||
|  |                 if (Button_read(me->button)==HIGH) | ||||||
|  |                 { | ||||||
|  |                     me->state = ST_BSMPRESSED; | ||||||
|  |                 } | ||||||
|  |                 else | ||||||
|  |                 { | ||||||
|  |                     me->state = ST_BSMRELEASED; | ||||||
|  |                 } | ||||||
|  |             }            | ||||||
|  |         break; | ||||||
|  |         case ST_BSMPRESSED: | ||||||
|  |             if (Event_getId(ev) == evBSMDefault) | ||||||
|  |             { | ||||||
|  |                 me->state = ST_BSMWAIT; | ||||||
|  |             }   | ||||||
|  |         break;   | ||||||
|  |         case ST_BSMRELEASED: | ||||||
|  |             if (Event_getId(ev) == evBSMDefault) | ||||||
|  |             { | ||||||
|  |                 me->state = ST_BSMWAIT; | ||||||
|  |             }            | ||||||
|  |         break; | ||||||
|  |     } | ||||||
|  |     if (oldState != me->state) | ||||||
|  |     { | ||||||
|  |         processed = true; | ||||||
|  |         switch (me->state) | ||||||
|  |         { | ||||||
|  |             case ST_BSMINIT: | ||||||
|  |             break; | ||||||
|  |             case ST_BSMWAIT: | ||||||
|  |                 POST(me, &ButtonSM_processEvent, evBSMPollTM,POLLTM,0); | ||||||
|  |             break; | ||||||
|  |             case ST_BSMPOLL: | ||||||
|  |                 POST(me, &ButtonSM_processEvent, evBSMDefault,0,0);   | ||||||
|  |             break; | ||||||
|  |             case ST_BSMPRESSED: | ||||||
|  |                 POST(me, &ButtonSM_processEvent, evBSMDefault,0,0); | ||||||
|  |                 if (me->actualState != ST_BSMPRESSED) | ||||||
|  |                 { | ||||||
|  |                     if (me->observerCB != NULL) | ||||||
|  |                     { | ||||||
|  |                         me->observerCB(me->observer,Button_getId(me->button),true); | ||||||
|  |                         me->actualState = ST_BSMPRESSED; | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |             break; | ||||||
|  |             case ST_BSMRELEASED: | ||||||
|  |                 POST(me, &ButtonSM_processEvent, evBSMDefault,0,0); | ||||||
|  |                 if (me->actualState != ST_BSMRELEASED) | ||||||
|  |                 { | ||||||
|  |                     if (me->observerCB != NULL) | ||||||
|  |                     { | ||||||
|  |                         me->observerCB(me->observer,Button_getId(me->button),false); | ||||||
|  |                         me->actualState = ST_BSMRELEASED; | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |             break; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |     return processed; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | /* | ||||||
|  |  * this is the start method for the  | ||||||
|  |  * state machine of the ButtonSM class | ||||||
|  |  */ | ||||||
|  | void ButtonSM_startBehaviour(ButtonSM* me) | ||||||
|  | { | ||||||
|  |     POST(me, &ButtonSM_processEvent, evBSMInit,0,0); | ||||||
|  |     me->actualState = Button_read(me->button)==HIGH?ST_BSMPRESSED:ST_BSMRELEASED; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | /* | ||||||
|  |  * this is the method to set the object and the  | ||||||
|  |  * call back method of the ButtonSM class | ||||||
|  |  * this method will be called whenever the  | ||||||
|  |  * button changes its state | ||||||
|  |  * as parameters to the callback method will be passed | ||||||
|  |  * the object address, the button id and its state | ||||||
|  |  * if the call back method does not belong to a class, | ||||||
|  |  * then the object address must be set to NULL | ||||||
|  |  */ | ||||||
|  | void ButtonSM_setObserver(ButtonSM* me, void* observer, buttonObserverCBT observerCB) | ||||||
|  | { | ||||||
|  |     me->observer = observer; | ||||||
|  |     me->observerCB = observerCB; | ||||||
|  | } | ||||||
							
								
								
									
										69
									
								
								306-controller_interface.X/board/button/buttonsm.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										69
									
								
								306-controller_interface.X/board/button/buttonsm.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,69 @@ | |||||||
|  | #ifndef BUTTONSM_DEF | ||||||
|  | #define BUTTONSM_DEF | ||||||
|  |  | ||||||
|  | #include <stdint.h> | ||||||
|  | #include <stdbool.h> | ||||||
|  | #include "../../xf/xf.h" | ||||||
|  | #include "button.h" | ||||||
|  |  | ||||||
|  | /* | ||||||
|  |  * these are the events of the | ||||||
|  |  * button state machine | ||||||
|  |  * be sure to make the first event  | ||||||
|  |  * in the enumeration different from 0 | ||||||
|  |  */ | ||||||
|  | typedef enum BSMEvent  | ||||||
|  | {  | ||||||
|  |     evBSMInit = 10, | ||||||
|  |     evBSMDefault,      | ||||||
|  |     evBSMPollTM | ||||||
|  | } BSMEvent; | ||||||
|  |  | ||||||
|  | /* | ||||||
|  |  * these are the states of the | ||||||
|  |  * button state machine  | ||||||
|  |  */ | ||||||
|  | typedef enum BSMSTate_ | ||||||
|  | { | ||||||
|  |     ST_BSMINIT,  | ||||||
|  |     ST_BSMWAIT, | ||||||
|  |     ST_BSMPOLL, | ||||||
|  |     ST_BSMPRESSED, | ||||||
|  |     ST_BSMRELEASED | ||||||
|  | } BSMState; | ||||||
|  |  | ||||||
|  | /* | ||||||
|  |  * the associated button will be polled | ||||||
|  |  * each 50 ms. do not make this time  | ||||||
|  |  * shorter than TICKINTERVAL | ||||||
|  |  */ | ||||||
|  | #define POLLTM 50 | ||||||
|  |  | ||||||
|  | /* | ||||||
|  |  * this is the prototype type of the callback function | ||||||
|  |  * that will be called when the associated button  | ||||||
|  |  * changes from released to pressed or inverse. | ||||||
|  |  */ | ||||||
|  | typedef void (*buttonObserverCBT)(void*, uint8_t, bool); | ||||||
|  |  | ||||||
|  | /* | ||||||
|  |  * this is the declaration of the ButtonSM class | ||||||
|  |  */ | ||||||
|  | struct ButtonSM_ | ||||||
|  | { | ||||||
|  |     BSMState state; | ||||||
|  |     Button* button; | ||||||
|  |     BSMState actualState; | ||||||
|  |  | ||||||
|  |     buttonObserverCBT observerCB; | ||||||
|  |     void* observer; | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | typedef struct ButtonSM_ ButtonSM; | ||||||
|  |  | ||||||
|  |  | ||||||
|  | void ButtonSM_init(ButtonSM* me, Button* button); | ||||||
|  | void ButtonSM_startBehaviour(ButtonSM* me); | ||||||
|  | bool ButtonSM_processEvent(Event* ev); | ||||||
|  | void ButtonSM_setObserver(ButtonSM* me, void* observer, buttonObserverCBT observerCB); | ||||||
|  | #endif | ||||||
							
								
								
									
										103
									
								
								306-controller_interface.X/board/led/led.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										103
									
								
								306-controller_interface.X/board/led/led.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,103 @@ | |||||||
|  | #include "led.h" | ||||||
|  | #include "../../mcc_generated_files/pin_manager.h" | ||||||
|  |  | ||||||
|  | void LED_init(LED* me, uint8_t id) | ||||||
|  | { | ||||||
|  |     me->id = id; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * @brief Initialize the Driver | ||||||
|  |  *  | ||||||
|  |  */ | ||||||
|  | void LED_initHW(LED* me) | ||||||
|  | { | ||||||
|  |     LED_off(me); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | /* | ||||||
|  |  * for the on and the off methods:  | ||||||
|  |  * if the output is push pull, it depends if the  | ||||||
|  |  * load is connect to ground or vcc.  | ||||||
|  |  * in this case, the load is connected to vcc,  | ||||||
|  |  * so on and off are inverted. Change the code as it  | ||||||
|  |  * is convenient for your hardware | ||||||
|  |  */ | ||||||
|  |  | ||||||
|  |  | ||||||
|  | //switch on the led | ||||||
|  | //maybe you have to adjust your | ||||||
|  | //low level calls | ||||||
|  | void LED_on(LED* me) | ||||||
|  | { | ||||||
|  |     switch (me->id) | ||||||
|  |     { | ||||||
|  |         case 1: | ||||||
|  |             IO_RB0_SetLow(); | ||||||
|  |         break; | ||||||
|  |         case 2: | ||||||
|  |         break; | ||||||
|  |         case 3: | ||||||
|  |         break; | ||||||
|  |         case 4: | ||||||
|  |         break; | ||||||
|  |         case 5: | ||||||
|  |         break; | ||||||
|  |         case 6: | ||||||
|  |         break; | ||||||
|  |         case 7: | ||||||
|  |         break; | ||||||
|  |         case 8: | ||||||
|  |         break; | ||||||
|  |         case 9: | ||||||
|  |         break; | ||||||
|  |         case 10: | ||||||
|  |         break;     | ||||||
|  |     } | ||||||
|  |        | ||||||
|  | } | ||||||
|  |  | ||||||
|  | //switch off the led | ||||||
|  | //maybe you have to adjust your | ||||||
|  | //low level calls | ||||||
|  | void LED_off(LED* me) | ||||||
|  | { | ||||||
|  |     switch (me->id) | ||||||
|  |     { | ||||||
|  |         case 1: | ||||||
|  |             IO_RB0_SetHigh(); | ||||||
|  |         break; | ||||||
|  |         case 2: | ||||||
|  |         break; | ||||||
|  |         case 3: | ||||||
|  |         break; | ||||||
|  |         case 4: | ||||||
|  |         break; | ||||||
|  |         case 5: | ||||||
|  |         break; | ||||||
|  |         case 6: | ||||||
|  |         break; | ||||||
|  |         case 7: | ||||||
|  |         break; | ||||||
|  |         case 8: | ||||||
|  |         break; | ||||||
|  |         case 9: | ||||||
|  |         break; | ||||||
|  |         case 10: | ||||||
|  |         break;     | ||||||
|  |     } | ||||||
|  |              | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void LED_setState(LED* me, uint8_t state) | ||||||
|  | { | ||||||
|  |     if (state == HIGH) | ||||||
|  |     { | ||||||
|  |         LED_on(me); | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |     if (state == LOW) | ||||||
|  |     { | ||||||
|  |         LED_off(me); | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										23
									
								
								306-controller_interface.X/board/led/led.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								306-controller_interface.X/board/led/led.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,23 @@ | |||||||
|  | #ifndef LED_ONCE | ||||||
|  | #define LED_ONCE | ||||||
|  |  | ||||||
|  | #include <stdint.h> | ||||||
|  |  | ||||||
|  | /* | ||||||
|  |  * this is the declaration of the Led class  | ||||||
|  |  */ | ||||||
|  | struct LED_ | ||||||
|  | { | ||||||
|  |   //has a gpo  | ||||||
|  |     uint8_t id; | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | typedef struct LED_ LED; | ||||||
|  |  | ||||||
|  | void LED_init(LED* me, uint8_t id); | ||||||
|  | void LED_initHW(LED* me); | ||||||
|  | void LED_on(LED* me); | ||||||
|  | void LED_off(LED* me); | ||||||
|  | void LED_setState(LED* me,uint8_t state); | ||||||
|  |  | ||||||
|  | #endif | ||||||
							
								
								
									
										53
									
								
								306-controller_interface.X/factory/factory.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										53
									
								
								306-controller_interface.X/factory/factory.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,53 @@ | |||||||
|  | #include "factory.h" | ||||||
|  |  | ||||||
|  |  | ||||||
|  | //the factory object containing all objects of our system | ||||||
|  | static Factory theFactory; | ||||||
|  |  | ||||||
|  |  | ||||||
|  | //all the getters | ||||||
|  | LED* l() | ||||||
|  | { | ||||||
|  |     return &theFactory.l_; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | Button* b() | ||||||
|  | { | ||||||
|  |     return &theFactory.b_; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | ButtonSM* bsm() | ||||||
|  | { | ||||||
|  |     return &theFactory.bsm_; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | BLControl* blc() | ||||||
|  | { | ||||||
|  |     return &theFactory.blc_; | ||||||
|  | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  | //initialize all objects | ||||||
|  | void Factory_init() | ||||||
|  | { | ||||||
|  |     LED_init(l(),LID); | ||||||
|  |     LED_initHW(l()); | ||||||
|  |     Button_init(b(),BID, true); | ||||||
|  |     Button_initHW(b());   | ||||||
|  |     ButtonSM_init(bsm(),b());     | ||||||
|  |     BLControl_init(blc()); | ||||||
|  | ; | ||||||
|  |      | ||||||
|  | } | ||||||
|  |  | ||||||
|  | //connect objects if required | ||||||
|  | void Factory_build() | ||||||
|  | { | ||||||
|  |     ButtonSM_setObserver(bsm(), blc(), &BLControl_onButton);  | ||||||
|  | } | ||||||
|  |  | ||||||
|  | //start all state machines | ||||||
|  | void Factory_start() | ||||||
|  | { | ||||||
|  |     ButtonSM_startBehaviour(bsm()); | ||||||
|  | } | ||||||
							
								
								
									
										41
									
								
								306-controller_interface.X/factory/factory.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								306-controller_interface.X/factory/factory.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,41 @@ | |||||||
|  | /* this is the Factory class */ | ||||||
|  |  | ||||||
|  |  | ||||||
|  | #ifndef FACTORY_ONCE | ||||||
|  | #define FACTORY_ONCE | ||||||
|  |  | ||||||
|  | #include <stdint.h> | ||||||
|  | #include <stdbool.h> | ||||||
|  |  | ||||||
|  | #include "../board/led/led.h" | ||||||
|  | #include "../board/button/button.h" | ||||||
|  | #include "../board/button/buttonsm.h" | ||||||
|  | #include "../app/blcontrol.h" | ||||||
|  |  | ||||||
|  |  | ||||||
|  | #define BID 1 | ||||||
|  | #define LID 1 | ||||||
|  |  | ||||||
|  | void bObs(void*, uint8_t,bool); | ||||||
|  |  | ||||||
|  | struct Factory_ | ||||||
|  | { | ||||||
|  |     LED l_; | ||||||
|  |     Button b_; | ||||||
|  |     ButtonSM bsm_; | ||||||
|  |     BLControl blc_; | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | typedef struct Factory_ Factory; | ||||||
|  |  | ||||||
|  | void Factory_init(); | ||||||
|  | void Factory_build(); | ||||||
|  | void Factory_start(); | ||||||
|  |  | ||||||
|  | //these are global getters for our objects | ||||||
|  | LED* l(); | ||||||
|  | Button* b(); | ||||||
|  | ButtonSM* bsm(); | ||||||
|  | BLControl* blc(); | ||||||
|  |  | ||||||
|  | #endif | ||||||
							
								
								
									
										39
									
								
								306-controller_interface.X/main.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								306-controller_interface.X/main.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,39 @@ | |||||||
|  | #include "mcc_generated_files/mcc.h" | ||||||
|  | #include "xf/xf.h" | ||||||
|  | #include "factory/factory.h" | ||||||
|  |  | ||||||
|  | /* | ||||||
|  |  * the main function | ||||||
|  |  */ | ||||||
|  | void main(void) | ||||||
|  | { | ||||||
|  |     // Initialize the device | ||||||
|  |     SYSTEM_Initialize(); | ||||||
|  |      | ||||||
|  |     // Enable the Global Interrupts | ||||||
|  |     INTERRUPT_GlobalInterruptEnable(); | ||||||
|  |  | ||||||
|  |     // Disable the Global Interrupts | ||||||
|  |     // INTERRUPT_GlobalInterruptDisable(); | ||||||
|  |      | ||||||
|  |     // initialize the XF | ||||||
|  |     XF_init(); | ||||||
|  |      | ||||||
|  |     // produce the system | ||||||
|  |     Factory_init(); | ||||||
|  |     Factory_build(); | ||||||
|  |     Factory_start(); | ||||||
|  |  | ||||||
|  |     // let the XF timers handling become the TMR0 interrupt handler | ||||||
|  |     // this means that the XF timers are always decremented when the  | ||||||
|  |     // TMR0 is interrupting. Important: Set the TICKINTERVAL define in  | ||||||
|  |     //the xf.h file to the same value as the TMR0 value.  | ||||||
|  |     TMR0_SetInterruptHandler(XF_decrementAndQueueTimers); | ||||||
|  |  | ||||||
|  |     while (1) | ||||||
|  |     { | ||||||
|  |         //handle the next event if there is any in the queue | ||||||
|  |         XF_executeOnce(); | ||||||
|  |         //maybe sleep a short while to save energy | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -0,0 +1,97 @@ | |||||||
|  | /** | ||||||
|  |   @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            :  PIC18F26K83 | ||||||
|  |         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 FEXTOSC = OFF    // External Oscillator Selection->Oscillator not enabled | ||||||
|  | #pragma config RSTOSC = HFINTOSC_64MHZ    // Reset Oscillator Selection->HFINTOSC with HFFRQ = 64 MHz and CDIV = 1:1 | ||||||
|  |  | ||||||
|  | // CONFIG1H | ||||||
|  | #pragma config CLKOUTEN = OFF    // Clock out Enable bit->CLKOUT function is disabled | ||||||
|  | #pragma config PR1WAY = ON    // PRLOCKED One-Way Set Enable bit->PRLOCK bit can be cleared and set only once | ||||||
|  | #pragma config CSWEN = ON    // Clock Switch Enable bit->Writing to NOSC and NDIV is allowed | ||||||
|  | #pragma config FCMEN = ON    // Fail-Safe Clock Monitor Enable bit->Fail-Safe Clock Monitor enabled | ||||||
|  |  | ||||||
|  | // CONFIG2L | ||||||
|  | #pragma config MCLRE = EXTMCLR    // MCLR Enable bit->If LVP = 0, MCLR pin is MCLR; If LVP = 1, RE3 pin function is MCLR  | ||||||
|  | #pragma config PWRTS = PWRT_OFF    // Power-up timer selection bits->PWRT is disabled | ||||||
|  | #pragma config MVECEN = OFF    // Multi-vector enable bit->Interrupt contoller does not use vector table to prioritze interrupts | ||||||
|  | #pragma config IVT1WAY = ON    // IVTLOCK bit One-way set enable bit->IVTLOCK bit can be cleared and set only once | ||||||
|  | #pragma config LPBOREN = OFF    // Low Power BOR Enable bit->ULPBOR disabled | ||||||
|  | #pragma config BOREN = SBORDIS    // Brown-out Reset Enable bits->Brown-out Reset enabled , SBOREN bit is ignored | ||||||
|  |  | ||||||
|  | // CONFIG2H | ||||||
|  | #pragma config BORV = VBOR_2P45    // Brown-out Reset Voltage Selection bits->Brown-out Reset Voltage (VBOR) set to 2.45V | ||||||
|  | #pragma config ZCD = OFF    // ZCD Disable bit->ZCD disabled. ZCD can be enabled by setting the ZCDSEN bit of ZCDCON | ||||||
|  | #pragma config PPS1WAY = ON    // PPSLOCK bit One-Way Set Enable bit->PPSLOCK bit can be cleared and set only once; PPS registers remain locked after one clear/set cycle | ||||||
|  | #pragma config STVREN = ON    // Stack Full/Underflow Reset Enable bit->Stack full/underflow will cause Reset | ||||||
|  | #pragma config DEBUG = OFF    // Debugger Enable bit->Background debugger disabled | ||||||
|  | #pragma config XINST = OFF    // Extended Instruction Set Enable bit->Extended Instruction Set and Indexed Addressing Mode disabled | ||||||
|  |  | ||||||
|  | // CONFIG3L | ||||||
|  | #pragma config WDTCPS = WDTCPS_31    // WDT Period selection bits->Divider ratio 1:65536; software control of WDTPS | ||||||
|  | #pragma config WDTE = OFF    // WDT operating mode->WDT Disabled; SWDTEN is ignored | ||||||
|  |  | ||||||
|  | // CONFIG3H | ||||||
|  | #pragma config WDTCWS = WDTCWS_7    // WDT Window Select bits->window always open (100%); software control; keyed access not required | ||||||
|  | #pragma config WDTCCS = SC    // WDT input clock selector->Software Control | ||||||
|  |  | ||||||
|  | // CONFIG4L | ||||||
|  | #pragma config BBSIZE = BBSIZE_512    // Boot Block Size selection bits->Boot Block size is 512 words | ||||||
|  | #pragma config BBEN = OFF    // Boot Block enable bit->Boot block disabled | ||||||
|  | #pragma config SAFEN = OFF    // Storage Area Flash enable bit->SAF disabled | ||||||
|  | #pragma config WRTAPP = OFF    // Application Block write protection bit->Application Block not write protected | ||||||
|  |  | ||||||
|  | // CONFIG4H | ||||||
|  | #pragma config WRTB = OFF    // Boot Block Write Protection bit->Boot Block not write-protected | ||||||
|  | #pragma config WRTC = OFF    // Configuration Register Write Protection bit->Configuration registers (300000-30000Bh) not write-protected | ||||||
|  | #pragma config WRTD = OFF    // Data EEPROM Write Protection bit->Data EEPROM not write-protected | ||||||
|  | #pragma config WRTSAF = OFF    // SAF Write protection bit->SAF not Write Protected | ||||||
|  | #pragma config LVP = ON    // Low Voltage Programming Enable bit->Low voltage programming enabled. MCLR/VPP pin function is MCLR. MCLRE configuration bit is ignored | ||||||
|  |  | ||||||
|  | // CONFIG5L | ||||||
|  | #pragma config CP = OFF    // PFM and Data EEPROM Code Protection bit->PFM and Data EEPROM code protection disabled | ||||||
| @@ -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            :  PIC18F26K83 | ||||||
|  |         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 | ||||||
|  | */ | ||||||
							
								
								
									
										754
									
								
								306-controller_interface.X/mcc_generated_files/ecan.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										754
									
								
								306-controller_interface.X/mcc_generated_files/ecan.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,754 @@ | |||||||
|  | /** | ||||||
|  |   ECAN Generated Driver  File | ||||||
|  |  | ||||||
|  |   @Company | ||||||
|  |     Microchip Technology Inc. | ||||||
|  |  | ||||||
|  |   @File Name | ||||||
|  |     ecan.c | ||||||
|  |  | ||||||
|  |   @Summary | ||||||
|  |     This is the generated driver implementation for the CAN driver using PIC10 / PIC12 / PIC16 / PIC18 MCUs | ||||||
|  |  | ||||||
|  |   @Description | ||||||
|  |     This source file provides APIs for CAN. | ||||||
|  |     Generation Information : | ||||||
|  |         Product Revision  :  PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.7 | ||||||
|  |         Device            :  PIC18F26K83 | ||||||
|  |         Driver Version    :  3.0.0 | ||||||
|  |     The generated drivers are tested against the following: | ||||||
|  |         Compiler          :  XC8 2.31 and above | ||||||
|  |         MPLAB 	          :  MPLAB X 5.45 | ||||||
|  | */ | ||||||
|  |  | ||||||
|  | /* | ||||||
|  |     (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 <xc.h> | ||||||
|  | #include "ecan.h" | ||||||
|  |  | ||||||
|  | static void (*RXBnInterruptHandler)(void); | ||||||
|  | static void (*RXBnOverflowHandler)(void); | ||||||
|  | static void (*BusOffHandler)(void); | ||||||
|  | static void (*TXPassiveHandler)(void); | ||||||
|  | static void (*RXPassiveHandler)(void); | ||||||
|  | static void (*TXWarningHandler)(void); | ||||||
|  | static void (*RXWarningHandler)(void); | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |     Local Functions | ||||||
|  | */ | ||||||
|  | static uint32_t convertReg2ExtendedCANid(uint8_t tempRXBn_EIDH, uint8_t tempRXBn_EIDL, uint8_t tempRXBn_SIDH, uint8_t tempRXBn_SIDL); | ||||||
|  | static uint32_t convertReg2StandardCANid(uint8_t tempRXBn_SIDH, uint8_t tempRXBn_SIDL); | ||||||
|  | static void convertCANid2Reg(uint32_t tempPassedInID, uint8_t canIdType, uint8_t *passedInEIDH, uint8_t *passedInEIDL, uint8_t *passedInSIDH, uint8_t *passedInSIDL); | ||||||
|  |  | ||||||
|  | static void RXBnDefaultInterruptHandler(void) {} | ||||||
|  | static void RXBnOverflowDefaultHandler(void) {} | ||||||
|  | static void BusOffDefaultHandler(void) {} | ||||||
|  | static void TXPassiveDefaultHandler(void) {} | ||||||
|  | static void RXPassiveDefaultHandler(void) {} | ||||||
|  | static void TXWarningDefaultHandler(void) {} | ||||||
|  | static void RXWarningDefaultHandler(void) {} | ||||||
|  |  | ||||||
|  | void ECAN_Initialize(void) | ||||||
|  | { | ||||||
|  |     CANCON = 0x80; | ||||||
|  |     while (0x80 != (CANSTAT & 0xE0)); // wait until ECAN is in config mode | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |     Mode 2 | ||||||
|  |     */ | ||||||
|  |     ECANCON = 0x90; | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |     Initialize CAN I/O | ||||||
|  |     */ | ||||||
|  |     CIOCON = 0x00; | ||||||
|  |      | ||||||
|  |     /** | ||||||
|  |     Mask and Filter definitions | ||||||
|  |     ........................................................     | ||||||
|  |     CAN ID		ID Type		Mask				Filter		Buffer     | ||||||
|  |     ........................................................     | ||||||
|  |     0x123		SID		Acceptance Mask 0		Filter 0	FIFO | ||||||
|  |     ........................................................ | ||||||
|  |     */ | ||||||
|  |      | ||||||
|  |     /** | ||||||
|  |     Configure Generic Buffers to be Transmit or Receive | ||||||
|  |     */ | ||||||
|  |     BSEL0 = 0x00; | ||||||
|  |   /** | ||||||
|  |     Mask and Filter definitions | ||||||
|  |     ........................................................     | ||||||
|  |     CAN ID		ID Type		Mask				Filter		Buffer     | ||||||
|  |     ........................................................     | ||||||
|  |     ........................................................ | ||||||
|  |     */ | ||||||
|  |     // mask 0 is 11 bits for filter 0 and 1 | ||||||
|  |     convertCANid2Reg(0x070, dSTANDARD_CAN_MSG_ID_2_0B, &RXM0EIDH, &RXM0EIDL, &RXM0SIDH, &RXM0SIDL); | ||||||
|  |     // filter 0 and 1 is broadcast message | ||||||
|  |     convertCANid2Reg(0x000, dSTANDARD_CAN_MSG_ID_2_0B, &RXF0EIDH, &RXF0EIDL, &RXF0SIDH, &RXF0SIDL);   | ||||||
|  |     convertCANid2Reg(0x010, dSTANDARD_CAN_MSG_ID_2_0B, &RXF1EIDH, &RXF1EIDL, &RXF1SIDH, &RXF1SIDL);   | ||||||
|  |     convertCANid2Reg(0x070, dSTANDARD_CAN_MSG_ID_2_0B, &RXF2EIDH, &RXF2EIDL, &RXF2SIDH, &RXF2SIDL);   | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |     Enable Filters | ||||||
|  |     */ | ||||||
|  |     RXFCON0 = 0x01;     // Filter 0 is activated | ||||||
|  |     RXFCON1 = 0x00; | ||||||
|  |      | ||||||
|  |     /** | ||||||
|  |     Assign Filters to Masks | ||||||
|  |     */ | ||||||
|  |     MSEL0 = 0x00;       // filter 0 is assigned to mask 0 | ||||||
|  |     MSEL1 = 0x00; | ||||||
|  |     MSEL2 = 0x00; | ||||||
|  |     MSEL3 = 0x00; | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |     Initialize CAN Timings | ||||||
|  |     */ | ||||||
|  |      | ||||||
|  |    /** | ||||||
|  | 	Baud rate: 250kbps | ||||||
|  | 	System frequency: 64000000 | ||||||
|  |     ECAN clock frequency: 64000000 | ||||||
|  | 	Time quanta: 8 | ||||||
|  | 	Sample point: 1-1-4-2 | ||||||
|  | 	Sample point: 75% | ||||||
|  | 	*/ | ||||||
|  |      | ||||||
|  |     BRGCON1 = 0x0F; | ||||||
|  |     BRGCON2 = 0x98; | ||||||
|  |     BRGCON3 = 0x81; | ||||||
|  |  | ||||||
|  |      | ||||||
|  |     ECAN_SetRXBnInterruptHandler(RXBnDefaultInterruptHandler); | ||||||
|  |     PIR5bits.RXBnIF = 0; | ||||||
|  |     PIE5bits.RXBnIE = 1; | ||||||
|  |      | ||||||
|  |     ECAN_SetRXBnOverflowHandler(RXBnOverflowDefaultHandler); | ||||||
|  |     ECAN_SetBusOffHandler(BusOffDefaultHandler); | ||||||
|  |     ECAN_SetTXPassiveHandler(TXPassiveDefaultHandler); | ||||||
|  |     ECAN_SetRXPassiveHandler(RXPassiveDefaultHandler); | ||||||
|  |     ECAN_SetTXWarningHandler(TXWarningDefaultHandler); | ||||||
|  |     ECAN_SetRXWarningHandler(RXWarningDefaultHandler); | ||||||
|  |     PIR5bits.ERRIF = 0; | ||||||
|  |     PIE5bits.ERRIE = 1; | ||||||
|  |      | ||||||
|  |     CANCON = 0x00; | ||||||
|  |     while (0x00 != (CANSTAT & 0xE0)); // wait until ECAN is in Normal mode | ||||||
|  |  | ||||||
|  | } | ||||||
|  |  /** | ||||||
|  |   Section: ECAN APIs | ||||||
|  | */ | ||||||
|  | void CAN_sleep(void)  | ||||||
|  | { | ||||||
|  |     CANCON = 0x20; // request disable mode | ||||||
|  |     while ((CANSTAT & 0xE0) != 0x20); // wait until ECAN is in disable mode    | ||||||
|  |     //Wake up from sleep should set the CAN module straight into Normal mode | ||||||
|  | } | ||||||
|  |  | ||||||
|  | uint8_t CAN_transmit(uCAN_MSG *tempCanMsg)  | ||||||
|  | { | ||||||
|  |     uint8_t tempEIDH = 0; | ||||||
|  |     uint8_t tempEIDL = 0; | ||||||
|  |     uint8_t tempSIDH = 0; | ||||||
|  |     uint8_t tempSIDL = 0; | ||||||
|  |     uint8_t returnValue = 0; | ||||||
|  |  | ||||||
|  |     if (TXB0CONbits.TXREQ != 1)  | ||||||
|  |     { | ||||||
|  |         convertCANid2Reg(tempCanMsg->frame.id, tempCanMsg->frame.idType, &tempEIDH, &tempEIDL, &tempSIDH, &tempSIDL); | ||||||
|  |  | ||||||
|  |         TXB0EIDH = tempEIDH; | ||||||
|  |         TXB0EIDL = tempEIDL; | ||||||
|  |         TXB0SIDH = tempSIDH; | ||||||
|  |         TXB0SIDL = tempSIDL; | ||||||
|  |         TXB0DLC  = tempCanMsg->frame.dlc | ((tempCanMsg->frame.rtr)<<6); | ||||||
|  |         TXB0D0   = tempCanMsg->frame.data0; | ||||||
|  |         TXB0D1   = tempCanMsg->frame.data1; | ||||||
|  |         TXB0D2   = tempCanMsg->frame.data2; | ||||||
|  |         TXB0D3   = tempCanMsg->frame.data3; | ||||||
|  |         TXB0D4   = tempCanMsg->frame.data4; | ||||||
|  |         TXB0D5   = tempCanMsg->frame.data5; | ||||||
|  |         TXB0D6   = tempCanMsg->frame.data6; | ||||||
|  |         TXB0D7   = tempCanMsg->frame.data7; | ||||||
|  |  | ||||||
|  |         TXB0CONbits.TXREQ = 1; //Set the buffer to transmit		 | ||||||
|  |         returnValue = 1; | ||||||
|  |          | ||||||
|  |     }  | ||||||
|  |     else if (TXB1CONbits.TXREQ != 1)  | ||||||
|  |     { | ||||||
|  |  | ||||||
|  |         convertCANid2Reg(tempCanMsg->frame.id, tempCanMsg->frame.idType, &tempEIDH, &tempEIDL, &tempSIDH, &tempSIDL); | ||||||
|  |  | ||||||
|  |         TXB1EIDH = tempEIDH; | ||||||
|  |         TXB1EIDL = tempEIDL; | ||||||
|  |         TXB1SIDH = tempSIDH; | ||||||
|  |         TXB1SIDL = tempSIDL; | ||||||
|  |         TXB1DLC  = tempCanMsg->frame.dlc | ((tempCanMsg->frame.rtr)<<6); | ||||||
|  |         TXB1D0   = tempCanMsg->frame.data0; | ||||||
|  |         TXB1D1   = tempCanMsg->frame.data1; | ||||||
|  |         TXB1D2   = tempCanMsg->frame.data2; | ||||||
|  |         TXB1D3   = tempCanMsg->frame.data3; | ||||||
|  |         TXB1D4   = tempCanMsg->frame.data4; | ||||||
|  |         TXB1D5   = tempCanMsg->frame.data5; | ||||||
|  |         TXB1D6   = tempCanMsg->frame.data6; | ||||||
|  |         TXB1D7   = tempCanMsg->frame.data7; | ||||||
|  |  | ||||||
|  |         TXB1CONbits.TXREQ = 1; //Set the buffer to transmit		 | ||||||
|  |         returnValue = 1; | ||||||
|  |     }  | ||||||
|  |     else if (TXB2CONbits.TXREQ != 1)  | ||||||
|  |     { | ||||||
|  |  | ||||||
|  |         convertCANid2Reg(tempCanMsg->frame.id, tempCanMsg->frame.idType, &tempEIDH, &tempEIDL, &tempSIDH, &tempSIDL); | ||||||
|  |  | ||||||
|  |         TXB2EIDH = tempEIDH; | ||||||
|  |         TXB2EIDL = tempEIDL; | ||||||
|  |         TXB2SIDH = tempSIDH; | ||||||
|  |         TXB2SIDL = tempSIDL; | ||||||
|  |         TXB2DLC  = tempCanMsg->frame.dlc | ((tempCanMsg->frame.rtr)<<6); | ||||||
|  |         TXB2D0   = tempCanMsg->frame.data0; | ||||||
|  |         TXB2D1   = tempCanMsg->frame.data1; | ||||||
|  |         TXB2D2   = tempCanMsg->frame.data2; | ||||||
|  |         TXB2D3   = tempCanMsg->frame.data3; | ||||||
|  |         TXB2D4   = tempCanMsg->frame.data4; | ||||||
|  |         TXB2D5   = tempCanMsg->frame.data5; | ||||||
|  |         TXB2D6   = tempCanMsg->frame.data6; | ||||||
|  |         TXB2D7   = tempCanMsg->frame.data7; | ||||||
|  |  | ||||||
|  |         TXB2CONbits.TXREQ = 1; //Set the buffer to transmit		 | ||||||
|  |         returnValue = 1; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     return (returnValue); | ||||||
|  | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  | /** | ||||||
|  | Version A2 has a silicon errata | ||||||
|  | This code works for all revisions | ||||||
|  | */ | ||||||
|  | //Fix for Errata | ||||||
|  | #define dRXB0CON_FIFO_POINTER_VALUE 0 | ||||||
|  | #define dRXB1CON_FIFO_POINTER_VALUE 1 | ||||||
|  | #define dB0CON_FIFO_POINTER_VALUE 2 | ||||||
|  | #define dB1CON_FIFO_POINTER_VALUE 3 | ||||||
|  | #define dB2CON_FIFO_POINTER_VALUE 4 | ||||||
|  | #define dB3CON_FIFO_POINTER_VALUE 5 | ||||||
|  | #define dB4CON_FIFO_POINTER_VALUE 6 | ||||||
|  | #define dB5CON_FIFO_POINTER_VALUE 7 | ||||||
|  |  | ||||||
|  | uint8_t CAN_receive(uCAN_MSG *tempCanMsg) { | ||||||
|  |     uint8_t returnValue = 0; | ||||||
|  |     uint8_t tempECANCON; | ||||||
|  |     uint8_t tempReg; | ||||||
|  |  | ||||||
|  |     tempReg = (CANCON & 0x0F); //get the next RX buffer to read | ||||||
|  |     tempECANCON = ECANCON; //Backup | ||||||
|  |     ECANCON |= (tempReg + 0x10); | ||||||
|  |  | ||||||
|  |     //Per Errata need to use this method to read out BxCON register | ||||||
|  |     switch (tempReg) | ||||||
|  |     { | ||||||
|  |         case dRXB0CON_FIFO_POINTER_VALUE: | ||||||
|  |             if (RXB0CONbits.RXFUL != 0) // Check RXB0 | ||||||
|  |             { | ||||||
|  |                 if ((RXB0SIDL & 0x08) == 0x08) //If Extended Message | ||||||
|  |                 { | ||||||
|  |                     //message is extended | ||||||
|  |                     tempCanMsg->frame.idType = (uint8_t) dEXTENDED_CAN_MSG_ID_2_0B; | ||||||
|  |                     tempCanMsg->frame.id = convertReg2ExtendedCANid(RXB0EIDH, RXB0EIDL, RXB0SIDH, RXB0SIDL); | ||||||
|  |                 } | ||||||
|  |                 else | ||||||
|  |                 { | ||||||
|  |                     //message is standard | ||||||
|  |                     tempCanMsg->frame.idType = (uint8_t) dSTANDARD_CAN_MSG_ID_2_0B; | ||||||
|  |                     tempCanMsg->frame.id = convertReg2StandardCANid(RXB0SIDH, RXB0SIDL); | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 tempCanMsg->frame.dlc   = RXB0DLC & 0x0F; | ||||||
|  |                 tempCanMsg->frame.rtr   = RXB0DLC >> 6; | ||||||
|  |                 tempCanMsg->frame.data0 = RXB0D0; | ||||||
|  |                 tempCanMsg->frame.data1 = RXB0D1; | ||||||
|  |                 tempCanMsg->frame.data2 = RXB0D2; | ||||||
|  |                 tempCanMsg->frame.data3 = RXB0D3; | ||||||
|  |                 tempCanMsg->frame.data4 = RXB0D4; | ||||||
|  |                 tempCanMsg->frame.data5 = RXB0D5; | ||||||
|  |                 tempCanMsg->frame.data6 = RXB0D6; | ||||||
|  |                 tempCanMsg->frame.data7 = RXB0D7; | ||||||
|  |                 RXB0CONbits.RXFUL = 0; | ||||||
|  |                 returnValue = 1; | ||||||
|  |             } | ||||||
|  |             break; | ||||||
|  |         case dRXB1CON_FIFO_POINTER_VALUE: | ||||||
|  |             if (RXB1CONbits.RXFUL != 0) // Check RXB1 | ||||||
|  |             { | ||||||
|  |                 if ((RXB0SIDL & 0x08) == 0x08) //If Extended Message | ||||||
|  |                 { | ||||||
|  |                     //message is extended | ||||||
|  |                     tempCanMsg->frame.idType = (uint8_t) dEXTENDED_CAN_MSG_ID_2_0B; | ||||||
|  |                     tempCanMsg->frame.id = convertReg2ExtendedCANid(RXB0EIDH, RXB0EIDL, RXB0SIDH, RXB0SIDL); | ||||||
|  |                 } else { | ||||||
|  |                     //message is standard | ||||||
|  |                     tempCanMsg->frame.idType = (uint8_t) dSTANDARD_CAN_MSG_ID_2_0B; | ||||||
|  |                     tempCanMsg->frame.id = convertReg2StandardCANid(RXB0SIDH, RXB0SIDL); | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 tempCanMsg->frame.dlc = RXB0DLC & 0x0F; | ||||||
|  |                 tempCanMsg->frame.rtr   = RXB0DLC >> 6; | ||||||
|  |                 tempCanMsg->frame.data0 = RXB0D0; | ||||||
|  |                 tempCanMsg->frame.data1 = RXB0D1; | ||||||
|  |                 tempCanMsg->frame.data2 = RXB0D2; | ||||||
|  |                 tempCanMsg->frame.data3 = RXB0D3; | ||||||
|  |                 tempCanMsg->frame.data4 = RXB0D4; | ||||||
|  |                 tempCanMsg->frame.data5 = RXB0D5; | ||||||
|  |                 tempCanMsg->frame.data6 = RXB0D6; | ||||||
|  |                 tempCanMsg->frame.data7 = RXB0D7; | ||||||
|  |                 RXB1CONbits.RXFUL = 0; | ||||||
|  |                 returnValue = 1; | ||||||
|  |             } | ||||||
|  |             break; | ||||||
|  |         case dB0CON_FIFO_POINTER_VALUE: | ||||||
|  |             if (B0CONbits.RXFUL != 0) //Check B0 | ||||||
|  |             { | ||||||
|  |                 if ((RXB0SIDL & 0x08) == 0x08) //If Extended Message | ||||||
|  |                 { | ||||||
|  |                     //message is extended | ||||||
|  |                     tempCanMsg->frame.idType = (uint8_t) dEXTENDED_CAN_MSG_ID_2_0B; | ||||||
|  |                     tempCanMsg->frame.id = convertReg2ExtendedCANid(RXB0EIDH, RXB0EIDL, RXB0SIDH, RXB0SIDL); | ||||||
|  |                 } else { | ||||||
|  |                     //message is standard | ||||||
|  |                     tempCanMsg->frame.idType = (uint8_t) dSTANDARD_CAN_MSG_ID_2_0B; | ||||||
|  |                     tempCanMsg->frame.id = convertReg2StandardCANid(RXB0SIDH, RXB0SIDL); | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 tempCanMsg->frame.dlc   = RXB0DLC & 0x0F; | ||||||
|  |                 tempCanMsg->frame.rtr   = RXB0DLC >> 6; | ||||||
|  |                 tempCanMsg->frame.data0 = RXB0D0; | ||||||
|  |                 tempCanMsg->frame.data1 = RXB0D1; | ||||||
|  |                 tempCanMsg->frame.data2 = RXB0D2; | ||||||
|  |                 tempCanMsg->frame.data3 = RXB0D3; | ||||||
|  |                 tempCanMsg->frame.data4 = RXB0D4; | ||||||
|  |                 tempCanMsg->frame.data5 = RXB0D5; | ||||||
|  |                 tempCanMsg->frame.data6 = RXB0D6; | ||||||
|  |                 tempCanMsg->frame.data7 = RXB0D7; | ||||||
|  |                 B0CONbits.RXFUL = 0; | ||||||
|  |                 returnValue = 1; | ||||||
|  |             } | ||||||
|  |             break; | ||||||
|  |         case dB1CON_FIFO_POINTER_VALUE: | ||||||
|  |             if (B1CONbits.RXFUL != 0) //CheckB1 | ||||||
|  |             { | ||||||
|  |                 if ((RXB0SIDL & 0x08) == 0x08) //If Extended Message | ||||||
|  |                 { | ||||||
|  |                     //message is extended | ||||||
|  |                     tempCanMsg->frame.idType = (uint8_t) dEXTENDED_CAN_MSG_ID_2_0B; | ||||||
|  |                     tempCanMsg->frame.id = convertReg2ExtendedCANid(RXB0EIDH, RXB0EIDL, RXB0SIDH, RXB0SIDL); | ||||||
|  |                 } | ||||||
|  |                 else | ||||||
|  |                 { | ||||||
|  |                     //message is standard | ||||||
|  |                     tempCanMsg->frame.idType = (uint8_t) dSTANDARD_CAN_MSG_ID_2_0B; | ||||||
|  |                     tempCanMsg->frame.id = convertReg2StandardCANid(RXB0SIDH, RXB0SIDL); | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 tempCanMsg->frame.dlc   = RXB0DLC & 0x0F; | ||||||
|  |                 tempCanMsg->frame.rtr   = RXB0DLC >> 6; | ||||||
|  |                 tempCanMsg->frame.data0 = RXB0D0; | ||||||
|  |                 tempCanMsg->frame.data1 = RXB0D1; | ||||||
|  |                 tempCanMsg->frame.data2 = RXB0D2; | ||||||
|  |                 tempCanMsg->frame.data3 = RXB0D3; | ||||||
|  |                 tempCanMsg->frame.data4 = RXB0D4; | ||||||
|  |                 tempCanMsg->frame.data5 = RXB0D5; | ||||||
|  |                 tempCanMsg->frame.data6 = RXB0D6; | ||||||
|  |                 tempCanMsg->frame.data7 = RXB0D7; | ||||||
|  |                 B1CONbits.RXFUL = 0; | ||||||
|  |                 returnValue = 1; | ||||||
|  |             } | ||||||
|  |             break; | ||||||
|  |         case dB2CON_FIFO_POINTER_VALUE: | ||||||
|  |             if (B2CONbits.RXFUL != 0) //CheckB2 | ||||||
|  |             { | ||||||
|  |                 if ((RXB0SIDL & 0x08) == 0x08) //If Extended Message | ||||||
|  |                 { | ||||||
|  |                     //message is extended | ||||||
|  |                     tempCanMsg->frame.idType = (uint8_t) dEXTENDED_CAN_MSG_ID_2_0B; | ||||||
|  |                     tempCanMsg->frame.id = convertReg2ExtendedCANid(RXB0EIDH, RXB0EIDL, RXB0SIDH, RXB0SIDL); | ||||||
|  |                 } | ||||||
|  |                 else | ||||||
|  |                 { | ||||||
|  |                     //message is standard | ||||||
|  |                     tempCanMsg->frame.idType = (uint8_t) dSTANDARD_CAN_MSG_ID_2_0B; | ||||||
|  |                     tempCanMsg->frame.id = convertReg2StandardCANid(RXB0SIDH, RXB0SIDL); | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 tempCanMsg->frame.dlc   = RXB0DLC & 0x0F; | ||||||
|  |                 tempCanMsg->frame.rtr   = RXB0DLC >> 6; | ||||||
|  |                 tempCanMsg->frame.data0 = RXB0D0; | ||||||
|  |                 tempCanMsg->frame.data1 = RXB0D1; | ||||||
|  |                 tempCanMsg->frame.data2 = RXB0D2; | ||||||
|  |                 tempCanMsg->frame.data3 = RXB0D3; | ||||||
|  |                 tempCanMsg->frame.data4 = RXB0D4; | ||||||
|  |                 tempCanMsg->frame.data5 = RXB0D5; | ||||||
|  |                 tempCanMsg->frame.data6 = RXB0D6; | ||||||
|  |                 tempCanMsg->frame.data7 = RXB0D7; | ||||||
|  |                 B2CONbits.RXFUL = 0; | ||||||
|  |                 returnValue = 1; | ||||||
|  |             } | ||||||
|  |             break; | ||||||
|  |         case dB3CON_FIFO_POINTER_VALUE: | ||||||
|  |             if (B3CONbits.RXFUL != 0) //CheckB3 | ||||||
|  |             { | ||||||
|  |                 if ((RXB0SIDL & 0x08) == 0x08) //If Extended Message | ||||||
|  |                 { | ||||||
|  |                     //message is extended | ||||||
|  |                     tempCanMsg->frame.idType = (uint8_t) dEXTENDED_CAN_MSG_ID_2_0B; | ||||||
|  |                     tempCanMsg->frame.id = convertReg2ExtendedCANid(RXB0EIDH, RXB0EIDL, RXB0SIDH, RXB0SIDL); | ||||||
|  |                 } | ||||||
|  |                 else | ||||||
|  |                 { | ||||||
|  |                     //message is standard | ||||||
|  |                     tempCanMsg->frame.idType = (uint8_t) dSTANDARD_CAN_MSG_ID_2_0B; | ||||||
|  |                     tempCanMsg->frame.id = convertReg2StandardCANid(RXB0SIDH, RXB0SIDL); | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 tempCanMsg->frame.dlc   = RXB0DLC & 0x0F; | ||||||
|  |                 tempCanMsg->frame.rtr   = RXB0DLC >> 6; | ||||||
|  |                 tempCanMsg->frame.data0 = RXB0D0; | ||||||
|  |                 tempCanMsg->frame.data1 = RXB0D1; | ||||||
|  |                 tempCanMsg->frame.data2 = RXB0D2; | ||||||
|  |                 tempCanMsg->frame.data3 = RXB0D3; | ||||||
|  |                 tempCanMsg->frame.data4 = RXB0D4; | ||||||
|  |                 tempCanMsg->frame.data5 = RXB0D5; | ||||||
|  |                 tempCanMsg->frame.data6 = RXB0D6; | ||||||
|  |                 tempCanMsg->frame.data7 = RXB0D7; | ||||||
|  |                 B3CONbits.RXFUL = 0; | ||||||
|  |                 returnValue = 1; | ||||||
|  |             } | ||||||
|  |             break; | ||||||
|  |         case dB4CON_FIFO_POINTER_VALUE: | ||||||
|  |             if (B4CONbits.RXFUL != 0) //CheckB4 | ||||||
|  |             { | ||||||
|  |                 if ((RXB0SIDL & 0x08) == 0x08) //If Extended Message | ||||||
|  |                 { | ||||||
|  |                     //message is extended | ||||||
|  |                     tempCanMsg->frame.idType = (uint8_t) dEXTENDED_CAN_MSG_ID_2_0B; | ||||||
|  |                     tempCanMsg->frame.id = convertReg2ExtendedCANid(RXB0EIDH, RXB0EIDL, RXB0SIDH, RXB0SIDL); | ||||||
|  |                 } | ||||||
|  |                 else | ||||||
|  |                 { | ||||||
|  |                     //message is standard | ||||||
|  |                     tempCanMsg->frame.idType = (uint8_t) dSTANDARD_CAN_MSG_ID_2_0B; | ||||||
|  |                     tempCanMsg->frame.id = convertReg2StandardCANid(RXB0SIDH, RXB0SIDL); | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 tempCanMsg->frame.dlc   = RXB0DLC & 0x0F; | ||||||
|  |                 tempCanMsg->frame.rtr   = RXB0DLC >> 6; | ||||||
|  |                 tempCanMsg->frame.data0 = RXB0D0; | ||||||
|  |                 tempCanMsg->frame.data1 = RXB0D1; | ||||||
|  |                 tempCanMsg->frame.data2 = RXB0D2; | ||||||
|  |                 tempCanMsg->frame.data3 = RXB0D3; | ||||||
|  |                 tempCanMsg->frame.data4 = RXB0D4; | ||||||
|  |                 tempCanMsg->frame.data5 = RXB0D5; | ||||||
|  |                 tempCanMsg->frame.data6 = RXB0D6; | ||||||
|  |                 tempCanMsg->frame.data7 = RXB0D7; | ||||||
|  |                 B4CONbits.RXFUL = 0; | ||||||
|  |                 returnValue = 1; | ||||||
|  |             } | ||||||
|  |             break; | ||||||
|  |         case dB5CON_FIFO_POINTER_VALUE: | ||||||
|  |             if (B5CONbits.RXFUL != 0) //CheckB5 | ||||||
|  |             { | ||||||
|  |                 if ((RXB0SIDL & 0x08) == 0x08) //If Extended Message | ||||||
|  |                 { | ||||||
|  |                     //message is extended | ||||||
|  |                     tempCanMsg->frame.idType = (uint8_t) dEXTENDED_CAN_MSG_ID_2_0B; | ||||||
|  |                     tempCanMsg->frame.id = convertReg2ExtendedCANid(RXB0EIDH, RXB0EIDL, RXB0SIDH, RXB0SIDL); | ||||||
|  |                 } | ||||||
|  |                 else | ||||||
|  |                 { | ||||||
|  |                     //message is standard | ||||||
|  |                     tempCanMsg->frame.idType = (uint8_t) dSTANDARD_CAN_MSG_ID_2_0B; | ||||||
|  |                     tempCanMsg->frame.id = convertReg2StandardCANid(RXB0SIDH, RXB0SIDL); | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 tempCanMsg->frame.dlc   = RXB0DLC & 0x0F; | ||||||
|  |                 tempCanMsg->frame.rtr   = RXB0DLC >> 6; | ||||||
|  |                 tempCanMsg->frame.data0 = RXB0D0; | ||||||
|  |                 tempCanMsg->frame.data1 = RXB0D1; | ||||||
|  |                 tempCanMsg->frame.data2 = RXB0D2; | ||||||
|  |                 tempCanMsg->frame.data3 = RXB0D3; | ||||||
|  |                 tempCanMsg->frame.data4 = RXB0D4; | ||||||
|  |                 tempCanMsg->frame.data5 = RXB0D5; | ||||||
|  |                 tempCanMsg->frame.data6 = RXB0D6; | ||||||
|  |                 tempCanMsg->frame.data7 = RXB0D7; | ||||||
|  |                 B5CONbits.RXFUL = 0; | ||||||
|  |                 returnValue = 1; | ||||||
|  |             } | ||||||
|  |             break; | ||||||
|  |     } | ||||||
|  | 		 | ||||||
|  |     ECANCON = tempECANCON; | ||||||
|  |     return (returnValue); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | uint8_t CAN_messagesInBuffer(void) { | ||||||
|  |     uint8_t messageCount = 0; | ||||||
|  |     if (RXB0CONbits.RXFUL != 0) //CheckRXB0 | ||||||
|  |     { | ||||||
|  |         messageCount++; | ||||||
|  |     } | ||||||
|  |     if (RXB1CONbits.RXFUL != 0) //CheckRXB1 | ||||||
|  |     { | ||||||
|  |         messageCount++; | ||||||
|  |     } | ||||||
|  |     if (B0CONbits.RXFUL_TXBIF != 0) //CheckB0 | ||||||
|  |     { | ||||||
|  |         messageCount++; | ||||||
|  |     } | ||||||
|  |     if (B1CONbits.RXFUL_TXBIF != 0) //CheckB1 | ||||||
|  |     { | ||||||
|  |         messageCount++; | ||||||
|  |     } | ||||||
|  |     if (B2CONbits.RXFUL_TXBIF != 0) //CheckB2 | ||||||
|  |     { | ||||||
|  |         messageCount++; | ||||||
|  |     } | ||||||
|  |     if (B3CONbits.RXFUL_TXBIF != 0) //CheckB3 | ||||||
|  |     { | ||||||
|  |         messageCount++; | ||||||
|  |     } | ||||||
|  |     if (B4CONbits.RXFUL_TXBIF != 0) //CheckB4 | ||||||
|  |     { | ||||||
|  |         messageCount++; | ||||||
|  |     } | ||||||
|  |     if (B5CONbits.RXFUL_TXBIF != 0) //CheckB5 | ||||||
|  |     { | ||||||
|  |         messageCount++; | ||||||
|  |     } | ||||||
|  |     return (messageCount); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | uint8_t CAN_isBusOff(void) | ||||||
|  | { | ||||||
|  |     uint8_t returnValue = 0; | ||||||
|  |  | ||||||
|  |     //COMSTAT bit 5 TXBO: Transmitter Bus-Off bit | ||||||
|  |     //1 = Transmit error counter > 255 | ||||||
|  |     //0 = Transmit error counter less then or equal to 255 | ||||||
|  |  | ||||||
|  |     if (COMSTATbits.TXBO == 1) { | ||||||
|  |         returnValue = 1; | ||||||
|  |     } | ||||||
|  |     return (returnValue); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | uint8_t CAN_isRXErrorPassive(void) | ||||||
|  | { | ||||||
|  |     uint8_t returnValue = 0; | ||||||
|  |  | ||||||
|  |     //COMSTAT bit 3 RXBP: Receiver Bus Passive bit | ||||||
|  |     //1 = Receive error counter > 127 | ||||||
|  |     //0 = Receive error counter less then or equal to 127 | ||||||
|  |  | ||||||
|  |     if (COMSTATbits.RXBP == 1) { | ||||||
|  |         returnValue = 1; | ||||||
|  |     } | ||||||
|  |     return (returnValue); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | uint8_t CAN_isTXErrorPassive(void) | ||||||
|  | { | ||||||
|  |     uint8_t returnValue = 0; | ||||||
|  |  | ||||||
|  |     //COMSTAT bit 4 TXBP: Transmitter Bus Passive bit | ||||||
|  |     //1 = Transmit error counter > 127 | ||||||
|  |     //0 = Transmit error counter less then or equal to 127 | ||||||
|  |  | ||||||
|  |     if (COMSTATbits.TXBP == 1) | ||||||
|  |     { | ||||||
|  |         returnValue = 1; | ||||||
|  |     } | ||||||
|  |     return (returnValue); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | /** | ||||||
|  | Internal functions | ||||||
|  | */ | ||||||
|  |  | ||||||
|  | static uint32_t convertReg2ExtendedCANid(uint8_t tempRXBn_EIDH, uint8_t tempRXBn_EIDL, uint8_t tempRXBn_SIDH, uint8_t tempRXBn_SIDL) { | ||||||
|  |     uint32_t returnValue = 0; | ||||||
|  |     uint32_t ConvertedID = 0; | ||||||
|  |     uint8_t CAN_standardLo_ID_lo2bits; | ||||||
|  |     uint8_t CAN_standardLo_ID_hi3bits; | ||||||
|  |  | ||||||
|  |     CAN_standardLo_ID_lo2bits = (uint8_t)(tempRXBn_SIDL & 0x03); | ||||||
|  |     CAN_standardLo_ID_hi3bits = (uint8_t)(tempRXBn_SIDL >> 5); | ||||||
|  |     ConvertedID = (uint32_t)(tempRXBn_SIDH << 3); | ||||||
|  |     ConvertedID = ConvertedID + CAN_standardLo_ID_hi3bits; | ||||||
|  |     ConvertedID = (ConvertedID << 2); | ||||||
|  |     ConvertedID = ConvertedID + CAN_standardLo_ID_lo2bits; | ||||||
|  |     ConvertedID = (ConvertedID << 8); | ||||||
|  |     ConvertedID = ConvertedID + tempRXBn_EIDH; | ||||||
|  |     ConvertedID = (ConvertedID << 8); | ||||||
|  |     ConvertedID = ConvertedID + tempRXBn_EIDL; | ||||||
|  |     returnValue = ConvertedID; | ||||||
|  |     return (returnValue); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | static uint32_t convertReg2StandardCANid(uint8_t tempRXBn_SIDH, uint8_t tempRXBn_SIDL) { | ||||||
|  |     uint32_t returnValue = 0; | ||||||
|  |     uint32_t ConvertedID; | ||||||
|  |     //if standard message (11 bits) | ||||||
|  |     //EIDH = 0 + EIDL = 0 + SIDH + upper three bits SIDL (3rd bit needs to be clear) | ||||||
|  |     //1111 1111 111 | ||||||
|  |     ConvertedID = (uint32_t)(tempRXBn_SIDH << 3); | ||||||
|  |     ConvertedID = ConvertedID + (uint32_t)(tempRXBn_SIDL >> 5); | ||||||
|  |     returnValue = ConvertedID; | ||||||
|  |     return (returnValue); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | static void convertCANid2Reg(uint32_t tempPassedInID, uint8_t canIdType, uint8_t *passedInEIDH, uint8_t *passedInEIDL, uint8_t *passedInSIDH, uint8_t *passedInSIDL) { | ||||||
|  |     uint8_t wipSIDL = 0; | ||||||
|  |  | ||||||
|  |     if (canIdType == dEXTENDED_CAN_MSG_ID_2_0B) | ||||||
|  |     { | ||||||
|  |         //EIDL | ||||||
|  |         *passedInEIDL = 0xFF & tempPassedInID; //CAN_extendedLo_ID_TX1 = &HFF And CAN_UserEnter_ID_TX1 | ||||||
|  |         tempPassedInID = tempPassedInID >> 8; //CAN_UserEnter_ID_TX1 = CAN_UserEnter_ID_TX1 >> 8 | ||||||
|  |  | ||||||
|  |         //EIDH | ||||||
|  |         *passedInEIDH = 0xFF & tempPassedInID; //CAN_extendedHi_ID_TX1 = &HFF And CAN_UserEnter_ID_TX1 | ||||||
|  |         tempPassedInID = tempPassedInID >> 8; //CAN_UserEnter_ID_TX1 = CAN_UserEnter_ID_TX1 >> 8 | ||||||
|  |  | ||||||
|  |         //SIDL | ||||||
|  |         //push back 5 and or it | ||||||
|  |         wipSIDL = 0x03 & tempPassedInID; | ||||||
|  |         tempPassedInID = tempPassedInID << 3; //CAN_UserEnter_ID_TX1 = CAN_UserEnter_ID_TX1 << 3 | ||||||
|  |         wipSIDL = (0xE0 & tempPassedInID) + wipSIDL; | ||||||
|  |         wipSIDL = (uint8_t)(wipSIDL + 0x08); // TEMP_CAN_standardLo_ID_TX1 = TEMP_CAN_standardLo_ID_TX1 + &H8 | ||||||
|  |         *passedInSIDL = (uint8_t)(0xEB & wipSIDL); //CAN_standardLo_ID_TX1 = &HEB And TEMP_CAN_standardLo_ID_TX1 | ||||||
|  |  | ||||||
|  |         //SIDH | ||||||
|  |         tempPassedInID = tempPassedInID >> 8; | ||||||
|  |         *passedInSIDH = 0xFF & tempPassedInID; | ||||||
|  |     } | ||||||
|  |     else //(canIdType == dSTANDARD_CAN_MSG_ID_2_0B) | ||||||
|  |     { | ||||||
|  |         *passedInEIDH = 0; | ||||||
|  |         *passedInEIDL = 0; | ||||||
|  |         tempPassedInID = tempPassedInID << 5; | ||||||
|  |         *passedInSIDL = 0xFF & tempPassedInID; | ||||||
|  |         tempPassedInID = tempPassedInID >> 8; | ||||||
|  |         *passedInSIDH = 0xFF & tempPassedInID; | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void ECAN_SetRXBnInterruptHandler(void (*handler)(void)) | ||||||
|  | { | ||||||
|  |     RXBnInterruptHandler = handler; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void ECAN_RXBnI_ISR(void) | ||||||
|  | { | ||||||
|  |     RXBnInterruptHandler(); | ||||||
|  |     PIR5bits.RXBnIF = 0;  // The ECAN hardware overrides the setting of this bit (to '1') when any receive buffer is not empty. | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void ECAN_SetRXBnOverflowHandler(void (*handler)(void)) | ||||||
|  | { | ||||||
|  |     RXBnOverflowHandler = handler; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void ECAN_SetBusOffHandler(void (*handler)(void)) | ||||||
|  | { | ||||||
|  |     BusOffHandler = handler; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void ECAN_SetTXPassiveHandler(void (*handler)(void)) | ||||||
|  | { | ||||||
|  |     TXPassiveHandler = handler; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void ECAN_SetRXPassiveHandler(void (*handler)(void)) | ||||||
|  | { | ||||||
|  |     RXPassiveHandler = handler; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void ECAN_SetTXWarningHandler(void (*handler)(void)) | ||||||
|  | { | ||||||
|  |     TXWarningHandler = handler; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void ECAN_SetRXWarningHandler(void (*handler)(void)) | ||||||
|  | { | ||||||
|  |     RXWarningHandler = handler; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void ECAN_ERRI_ISR(void) | ||||||
|  | { | ||||||
|  |     if (COMSTATbits.RXB1OVFL) | ||||||
|  |     { | ||||||
|  |         RXBnOverflowHandler(); | ||||||
|  |         COMSTATbits.RXB1OVFL = 0;  // In mode 2, this clears RXBnOVFL | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |     if (COMSTATbits.TXBO) | ||||||
|  |     { | ||||||
|  |         BusOffHandler(); | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |     if (COMSTATbits.TXBP) | ||||||
|  |     { | ||||||
|  |         TXPassiveHandler(); | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |     if (COMSTATbits.RXBP) | ||||||
|  |     { | ||||||
|  |         RXPassiveHandler(); | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |     if (COMSTATbits.TXWARN) | ||||||
|  |     { | ||||||
|  |         TXWarningHandler(); | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |     if (COMSTATbits.RXWARN) | ||||||
|  |     { | ||||||
|  |         RXWarningHandler(); | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |     PIR5bits.ERRIF = 0; | ||||||
|  | } | ||||||
|  |  | ||||||
|  |  | ||||||
							
								
								
									
										589
									
								
								306-controller_interface.X/mcc_generated_files/ecan.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										589
									
								
								306-controller_interface.X/mcc_generated_files/ecan.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,589 @@ | |||||||
|  | /** | ||||||
|  |   ECAN Generated Driver API Header File | ||||||
|  |  | ||||||
|  |   @Company | ||||||
|  |     Microchip Technology Inc. | ||||||
|  |  | ||||||
|  |   @File Name | ||||||
|  |     ecan.h | ||||||
|  |  | ||||||
|  |   @Summary | ||||||
|  |     This is the generated header file for the ECAN driver using PIC10 / PIC12 / PIC16 / PIC18 MCUs | ||||||
|  |  | ||||||
|  |   @Description | ||||||
|  |     This header file provides APIs driver for ECAN. | ||||||
|  |     Generation Information : | ||||||
|  |         Product Revision  :  PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.7 | ||||||
|  |         Device            :  PIC18F26K83 | ||||||
|  |         Driver Version    :  3.0.0 | ||||||
|  |     The generated drivers are tested against the following: | ||||||
|  |         Compiler          :  XC8 2.31 and above | ||||||
|  |         MPLAB 	          :  MPLAB X 5.45 | ||||||
|  | */ | ||||||
|  |  | ||||||
|  | /* | ||||||
|  |     (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 ECAN_H | ||||||
|  | #define ECAN_H | ||||||
|  |  | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |   Section: Included Files | ||||||
|  | */ | ||||||
|  |  | ||||||
|  | #include <stdbool.h> | ||||||
|  | #include <stdint.h> | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  | ||||||
|  | Global Defines   | ||||||
|  |  | ||||||
|  | */ | ||||||
|  | typedef union { | ||||||
|  |  | ||||||
|  |     struct { | ||||||
|  |         uint8_t idType; | ||||||
|  |         uint32_t id; | ||||||
|  |         uint8_t dlc; | ||||||
|  |         uint8_t data0; | ||||||
|  |         uint8_t data1; | ||||||
|  |         uint8_t data2; | ||||||
|  |         uint8_t data3; | ||||||
|  |         uint8_t data4; | ||||||
|  |         uint8_t data5; | ||||||
|  |         uint8_t data6; | ||||||
|  |         uint8_t data7; | ||||||
|  |         uint8_t rtr; | ||||||
|  |     } frame; | ||||||
|  |     uint8_t array[15]; | ||||||
|  | } uCAN_MSG; | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  Defines | ||||||
|  | */ | ||||||
|  |  | ||||||
|  | #define dSTANDARD_CAN_MSG_ID_2_0B 1 | ||||||
|  | #define dEXTENDED_CAN_MSG_ID_2_0B 2 | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |   Section: ECAN APIs | ||||||
|  | */ | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |     @Summary | ||||||
|  |         Initializes the ECAN module.  | ||||||
|  |  | ||||||
|  |     @Description | ||||||
|  |         This routine sets all the set parameters to the ECAN module. | ||||||
|  |  | ||||||
|  |     @Preconditions  | ||||||
|  |         None | ||||||
|  |  | ||||||
|  |     @Param | ||||||
|  |         None | ||||||
|  |    | ||||||
|  |     @Returns | ||||||
|  |         None | ||||||
|  |   | ||||||
|  |     @Example | ||||||
|  |         <code> | ||||||
|  |         ECAN_Initialize();    | ||||||
|  |         </code>                                                                       | ||||||
|  | */ | ||||||
|  | void ECAN_Initialize(void); | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |                                                                             | ||||||
|  |     @Summary | ||||||
|  |         CAN_sleep | ||||||
|  |  | ||||||
|  |     @Description | ||||||
|  |         Puts the CAN module to sleep | ||||||
|  |  | ||||||
|  |     @Param | ||||||
|  |         None  | ||||||
|  |  | ||||||
|  |     @Returns | ||||||
|  |         None    | ||||||
|  |  | ||||||
|  |     @Example | ||||||
|  |         <code> | ||||||
|  |         CAN_init();   | ||||||
|  |         </code>  | ||||||
|  |                                                                             | ||||||
|  | */ | ||||||
|  |  | ||||||
|  | void CAN_sleep(void); | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |     @Summary | ||||||
|  |         CAN_transmit | ||||||
|  |  | ||||||
|  |     @Description | ||||||
|  |         Transmits out sCAN_MSG | ||||||
|  |  | ||||||
|  |     @Param | ||||||
|  |         Pointer to a sCAN_MSG | ||||||
|  |  | ||||||
|  |     @Returns | ||||||
|  |         True or False if message was loaded to transmit buffer  | ||||||
|  |  | ||||||
|  |     @Example | ||||||
|  |         <code> | ||||||
|  |         uCAN_MSG txMessage; | ||||||
|  |         CAN_transmit(&txMessage);   | ||||||
|  |         </code>                                                                              | ||||||
|  | */ | ||||||
|  | uint8_t CAN_transmit(uCAN_MSG *tempCanMsg); | ||||||
|  |  | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  | ||||||
|  | 	@Summary | ||||||
|  | 		CAN_receive | ||||||
|  |  | ||||||
|  | 	@Description | ||||||
|  | 		Receives CAN messages | ||||||
|  |  | ||||||
|  | 	@Param | ||||||
|  | 		Pointer to a sCAN_MSG | ||||||
|  |  | ||||||
|  | 	@Returns | ||||||
|  | 		True or False for a new message  | ||||||
|  |    | ||||||
|  | 	@Example | ||||||
|  | 		<code> | ||||||
|  | 		uCAN_MSG rxMessage; | ||||||
|  | 		CAN_receive(&rxMessage);   | ||||||
|  | 		</code>  | ||||||
|  |                                                                               | ||||||
|  | */ | ||||||
|  | uint8_t CAN_receive(uCAN_MSG *tempCanMsg); | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |   | ||||||
|  | 	@Summary | ||||||
|  | 		CAN_messagesInBuffer | ||||||
|  |   | ||||||
|  | 	@Description | ||||||
|  | 		Checks to see how many messages are in the buffer | ||||||
|  | 	 | ||||||
|  | 	@Param | ||||||
|  | 		None | ||||||
|  |  | ||||||
|  | 	@Returns | ||||||
|  | 		Returns total number of messages in the buffers | ||||||
|  |  | ||||||
|  | 	@Example | ||||||
|  | 		<code> | ||||||
|  | 		uint8_t nrMsg; | ||||||
|  | 		nrMsg = CAN_messagesInBuffer();   | ||||||
|  | 		</code>                                                                             | ||||||
|  | */ | ||||||
|  | uint8_t CAN_messagesInBuffer(void); | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  | ||||||
|  | 	@Summary | ||||||
|  | 		CAN_isBusOff | ||||||
|  |  | ||||||
|  | 	@Description | ||||||
|  | 		Checks to see if module is busoff | ||||||
|  |  | ||||||
|  | 	@Param | ||||||
|  | 		None | ||||||
|  |  | ||||||
|  | 	@Returns | ||||||
|  | 		True if module is in Busoff, False is if it is not | ||||||
|  |  | ||||||
|  | 	@Example | ||||||
|  | 		<code> | ||||||
|  | 		uint8_t busOff; | ||||||
|  | 		busOff = CAN_isBusOff();   | ||||||
|  | 		</code>  | ||||||
|  |                                                    | ||||||
|  | */ | ||||||
|  |  | ||||||
|  | uint8_t CAN_isBusOff(void); | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  | ||||||
|  | 	@Summary | ||||||
|  | 		CAN_isRXErrorPassive | ||||||
|  |  | ||||||
|  | 	@Description | ||||||
|  | 		Checks to see if module is RX Error Passive | ||||||
|  |          | ||||||
|  | 	@Param | ||||||
|  | 		None | ||||||
|  |   | ||||||
|  | 	@Returns | ||||||
|  |  		True if module is in RX Error Passive, False is if it is not                                                     | ||||||
|  |  | ||||||
|  |  	@Example | ||||||
|  | 		<code> | ||||||
|  | 		uint8_t errRxPasive; | ||||||
|  | 		errRxPasive = CAN_isRXErrorPassive(); | ||||||
|  | 		</code>      | ||||||
|  |                                                      | ||||||
|  |  */ | ||||||
|  |   | ||||||
|  | uint8_t CAN_isRXErrorPassive(void); | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  | ||||||
|  | 	@Summary | ||||||
|  | 		CAN_isTXErrorPassive | ||||||
|  |  | ||||||
|  | 	@Description | ||||||
|  | 		Checks to see if module is TX Error Passive | ||||||
|  |  | ||||||
|  | 	@Param | ||||||
|  | 		None | ||||||
|  |  | ||||||
|  | 	@Returns | ||||||
|  | 		True if module is in TX Error Passive, False is if it is not | ||||||
|  |  | ||||||
|  | 	@Example | ||||||
|  | 		<code> | ||||||
|  | 		uint8_t errTxPasive; | ||||||
|  | 		errTxPasive = CAN_isTXErrorPassive();   | ||||||
|  | 		</code>        | ||||||
|  |  | ||||||
|  | */ | ||||||
|  |  | ||||||
|  | uint8_t CAN_isTXErrorPassive(void); | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |     @Summary | ||||||
|  |         ECAN_SetRXBnInterruptHandler | ||||||
|  |  | ||||||
|  |     @Description | ||||||
|  |         Sets the ECAN Receive buffer n interrupt handler | ||||||
|  |  | ||||||
|  |     @Param | ||||||
|  |         Address of the callback routine | ||||||
|  |  | ||||||
|  |     @Returns | ||||||
|  |         None | ||||||
|  |  | ||||||
|  |     @Example | ||||||
|  |         <code> | ||||||
|  |         volatile bool customRXBnFlag = false; | ||||||
|  |  | ||||||
|  |         void CustomRXBnInterruptHandler(void) | ||||||
|  |         { | ||||||
|  |             customRXBnFlag = true; | ||||||
|  |             // ... | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         void main(void) | ||||||
|  |         { | ||||||
|  |             // ... | ||||||
|  |             ECAN_SetRXBnInterruptHandler(CustomRXBnInterruptHandler); | ||||||
|  |  | ||||||
|  |             while (1) | ||||||
|  |             { | ||||||
|  |                 if (customRXBnFlag) { | ||||||
|  |                     customRXBnFlag = false; | ||||||
|  |                     // ... | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         </code>        | ||||||
|  | */ | ||||||
|  | void ECAN_SetRXBnInterruptHandler(void (*handler)(void)); | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |     @Summary | ||||||
|  |         ECAN_RXBnI_ISR | ||||||
|  |  | ||||||
|  |     @Description | ||||||
|  |         Implements the ECAN Receive buffer n interrupt service routine | ||||||
|  |  | ||||||
|  |     @Param | ||||||
|  |         None | ||||||
|  |  | ||||||
|  |     @Returns | ||||||
|  |         None | ||||||
|  | */ | ||||||
|  | void ECAN_RXBnI_ISR(void); | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |     @Summary | ||||||
|  |         ECAN_SetRXBnOverflowHandler | ||||||
|  |  | ||||||
|  |     @Description | ||||||
|  |         Sets the ECAN Receive buffer n overflow interrupt handler | ||||||
|  |  | ||||||
|  |     @Param | ||||||
|  |         Address of the callback routine | ||||||
|  |  | ||||||
|  |     @Returns | ||||||
|  |         None | ||||||
|  |  | ||||||
|  |     @Example | ||||||
|  |         <code> | ||||||
|  |         volatile bool customRXBnOverflowFlag = false; | ||||||
|  |  | ||||||
|  |         void CustomRXBnOverflowHandler(void) | ||||||
|  |         { | ||||||
|  |             customRXBnOverflowFlag = true; | ||||||
|  |             // ... | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         void main(void) | ||||||
|  |         { | ||||||
|  |             // ... | ||||||
|  |             ECAN_SetRXBnOverflowHandler(CustomRXBnOverflowHandler); | ||||||
|  |  | ||||||
|  |             while (1) | ||||||
|  |             { | ||||||
|  |                 if (customRXBnOverflowFlag) { | ||||||
|  |                     customRXBnOverflowFlag = false; | ||||||
|  |                     // ... | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         </code>        | ||||||
|  | */ | ||||||
|  | void ECAN_SetRXBnOverflowHandler(void (*handler)(void)); | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |     @Summary | ||||||
|  |         ECAN_SetBusOffHandler | ||||||
|  |  | ||||||
|  |     @Description | ||||||
|  |         Sets the ECAN Bus off interrupt handler | ||||||
|  |  | ||||||
|  |     @Param | ||||||
|  |         Address of the callback routine | ||||||
|  |  | ||||||
|  |     @Returns | ||||||
|  |         None | ||||||
|  |  | ||||||
|  |     @Example | ||||||
|  |         <code> | ||||||
|  |         volatile bool customBusOffFlag = false; | ||||||
|  |  | ||||||
|  |         void CustomBusOffHandler(void) | ||||||
|  |         { | ||||||
|  |             customBusOffFlag = true; | ||||||
|  |             // ... | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         void main(void) | ||||||
|  |         { | ||||||
|  |             // ... | ||||||
|  |             ECAN_SetBusOffHandler(CustomBusOffHandler); | ||||||
|  |  | ||||||
|  |             while (1) | ||||||
|  |             { | ||||||
|  |                 if (customBusOffFlag) { | ||||||
|  |                     customBusOffFlag = false; | ||||||
|  |                     // ... | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         </code>        | ||||||
|  | */ | ||||||
|  | void ECAN_SetBusOffHandler(void (*handler)(void)); | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |     @Summary | ||||||
|  |         ECAN_SetTXPassiveHandler | ||||||
|  |  | ||||||
|  |     @Description | ||||||
|  |         Sets the ECAN TX passive interrupt handler | ||||||
|  |  | ||||||
|  |     @Param | ||||||
|  |         Address of the callback routine | ||||||
|  |  | ||||||
|  |     @Returns | ||||||
|  |         None | ||||||
|  |  | ||||||
|  |     @Example | ||||||
|  |         <code> | ||||||
|  |         volatile bool customTXPassiveFlag = false; | ||||||
|  |  | ||||||
|  |         void CustomTXPassiveHandler(void) | ||||||
|  |         { | ||||||
|  |             customTXPassiveFlag = true; | ||||||
|  |             // ... | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         void main(void) | ||||||
|  |         { | ||||||
|  |             // ... | ||||||
|  |             ECAN_SetTXPassiveHandler(CustomTXPassiveHandler); | ||||||
|  |  | ||||||
|  |             while (1) | ||||||
|  |             { | ||||||
|  |                 if (customTXPassiveFlag) { | ||||||
|  |                     customTXPassiveFlag = false; | ||||||
|  |                     // ... | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         </code>        | ||||||
|  | */ | ||||||
|  | void ECAN_SetTXPassiveHandler(void (*handler)(void)); | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |     @Summary | ||||||
|  |         ECAN_SetRXPassiveHandler | ||||||
|  |  | ||||||
|  |     @Description | ||||||
|  |         Sets the ECAN RX passive interrupt handler | ||||||
|  |  | ||||||
|  |     @Param | ||||||
|  |         Address of the callback routine | ||||||
|  |  | ||||||
|  |     @Returns | ||||||
|  |         None | ||||||
|  |  | ||||||
|  |     @Example | ||||||
|  |         <code> | ||||||
|  |         volatile bool customRXPassiveFlag = false; | ||||||
|  |  | ||||||
|  |         void CustomRXPassiveHandler(void) | ||||||
|  |         { | ||||||
|  |             customRXPassiveFlag = true; | ||||||
|  |             // ... | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         void main(void) | ||||||
|  |         { | ||||||
|  |             // ... | ||||||
|  |             ECAN_SetRXPassiveHandler(CustomRXPassiveHandler); | ||||||
|  |  | ||||||
|  |             while (1) | ||||||
|  |             { | ||||||
|  |                 if (customRXPassiveFlag) { | ||||||
|  |                     customRXPassiveFlag = false; | ||||||
|  |                     // ... | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         </code>        | ||||||
|  | */ | ||||||
|  | void ECAN_SetRXPassiveHandler(void (*handler)(void)); | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |     @Summary | ||||||
|  |         ECAN_SetTXWarningHandler | ||||||
|  |  | ||||||
|  |     @Description | ||||||
|  |         Sets the ECAN TX warning interrupt handler | ||||||
|  |  | ||||||
|  |     @Param | ||||||
|  |         Address of the callback routine | ||||||
|  |  | ||||||
|  |     @Returns | ||||||
|  |         None | ||||||
|  |  | ||||||
|  |     @Example | ||||||
|  |         <code> | ||||||
|  |         volatile bool customTXWarningFlag = false; | ||||||
|  |  | ||||||
|  |         void CustomTXWarningHandler(void) | ||||||
|  |         { | ||||||
|  |             customTXWarningFlag = true; | ||||||
|  |             // ... | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         void main(void) | ||||||
|  |         { | ||||||
|  |             // ... | ||||||
|  |             ECAN_SetTXWarningHandler(CustomTXWarningHandler); | ||||||
|  |  | ||||||
|  |             while (1) | ||||||
|  |             { | ||||||
|  |                 if (customTXWarningFlag) { | ||||||
|  |                     customTXWarningFlag = false; | ||||||
|  |                     // ... | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         </code>        | ||||||
|  | */ | ||||||
|  | void ECAN_SetTXWarningHandler(void (*handler)(void)); | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |     @Summary | ||||||
|  |         ECAN_SetRXWarningHandler | ||||||
|  |  | ||||||
|  |     @Description | ||||||
|  |         Sets the ECAN RX warning interrupt handler | ||||||
|  |  | ||||||
|  |     @Param | ||||||
|  |         Address of the callback routine | ||||||
|  |  | ||||||
|  |     @Returns | ||||||
|  |         None | ||||||
|  |  | ||||||
|  |     @Example | ||||||
|  |         <code> | ||||||
|  |         volatile bool customRXWarningFlag = false; | ||||||
|  |  | ||||||
|  |         void CustomRXWarningHandler(void) | ||||||
|  |         { | ||||||
|  |             customRXWarningFlag = true; | ||||||
|  |             // ... | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         void main(void) | ||||||
|  |         { | ||||||
|  |             // ... | ||||||
|  |             ECAN_SetRXWarningHandler(CustomRXWarningHandler); | ||||||
|  |  | ||||||
|  |             while (1) | ||||||
|  |             { | ||||||
|  |                 if (customRXWarningFlag) { | ||||||
|  |                     customRXWarningFlag = false; | ||||||
|  |                     // ... | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         </code>        | ||||||
|  | */ | ||||||
|  | void ECAN_SetRXWarningHandler(void (*handler)(void)); | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |     @Summary | ||||||
|  |         ECAN_ERRI_ISR | ||||||
|  |  | ||||||
|  |     @Description | ||||||
|  |         Implements the ECAN Module error interrupt service routine | ||||||
|  |  | ||||||
|  |     @Param | ||||||
|  |         None | ||||||
|  |  | ||||||
|  |     @Returns | ||||||
|  |         None | ||||||
|  | */ | ||||||
|  | void ECAN_ERRI_ISR(void); | ||||||
|  |  | ||||||
|  |  | ||||||
|  | #endif // ECAN_H | ||||||
| @@ -0,0 +1,80 @@ | |||||||
|  | /** | ||||||
|  |   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            :  PIC18F26K83 | ||||||
|  |         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) | ||||||
|  |     INTCON0bits.IPEN = 0; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void __interrupt() INTERRUPT_InterruptManager (void) | ||||||
|  | { | ||||||
|  |     // interrupt handler | ||||||
|  |     if(PIE3bits.TMR0IE == 1 && PIR3bits.TMR0IF == 1) | ||||||
|  |     { | ||||||
|  |         TMR0_ISR(); | ||||||
|  |     } | ||||||
|  |     else if(PIE5bits.ERRIE == 1 && PIR5bits.ERRIF == 1) | ||||||
|  |     { | ||||||
|  |         ECAN_ERRI_ISR(); | ||||||
|  |     } | ||||||
|  |     else if(PIE5bits.RXBnIE == 1 && PIR5bits.RXBnIF == 1) | ||||||
|  |     { | ||||||
|  |         ECAN_RXBnI_ISR(); | ||||||
|  |     } | ||||||
|  |     else | ||||||
|  |     { | ||||||
|  |         //Unhandled Interrupt | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | /** | ||||||
|  |  End of File | ||||||
|  | */ | ||||||
| @@ -0,0 +1,92 @@ | |||||||
|  | /** | ||||||
|  |   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            :  PIC18F26K83 | ||||||
|  |         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() (INTCON0bits.GIE = 1) | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * @Param | ||||||
|  |     none | ||||||
|  |  * @Returns | ||||||
|  |     none | ||||||
|  |  * @Description | ||||||
|  |     This macro will disable global interrupts. | ||||||
|  |  * @Example | ||||||
|  |     INTERRUPT_GlobalInterruptDisable(); | ||||||
|  |  */ | ||||||
|  | #define INTERRUPT_GlobalInterruptDisable() (INTCON0bits.GIE = 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 | ||||||
|  | */ | ||||||
							
								
								
									
										97
									
								
								306-controller_interface.X/mcc_generated_files/mcc.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										97
									
								
								306-controller_interface.X/mcc_generated_files/mcc.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,97 @@ | |||||||
|  | /** | ||||||
|  |   @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            :  PIC18F26K83 | ||||||
|  |         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(); | ||||||
|  |     PMD_Initialize(); | ||||||
|  |     PIN_MANAGER_Initialize(); | ||||||
|  |     OSCILLATOR_Initialize(); | ||||||
|  |     TMR0_Initialize(); | ||||||
|  |     ECAN_Initialize(); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void OSCILLATOR_Initialize(void) | ||||||
|  | { | ||||||
|  |     // NOSC HFINTOSC; NDIV 1;  | ||||||
|  |     OSCCON1 = 0x60; | ||||||
|  |     // CSWHOLD may proceed; SOSCPWR Low power;  | ||||||
|  |     OSCCON3 = 0x00; | ||||||
|  |     // MFOEN disabled; LFOEN disabled; ADOEN disabled; SOSCEN disabled; EXTOEN disabled; HFOEN disabled;  | ||||||
|  |     OSCEN = 0x00; | ||||||
|  |     // HFFRQ 64_MHz;  | ||||||
|  |     OSCFRQ = 0x08; | ||||||
|  |     // TUN 0;  | ||||||
|  |     OSCTUNE = 0x00; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void PMD_Initialize(void) | ||||||
|  | { | ||||||
|  |     // CLKRMD CLKR enabled; SYSCMD SYSCLK enabled; SCANMD SCANNER enabled; FVRMD FVR enabled; IOCMD IOC enabled; CRCMD CRC enabled; HLVDMD HLVD enabled; NVMMD NVM enabled;  | ||||||
|  |     PMD0 = 0x00; | ||||||
|  |     // NCO1MD DDS(NCO1) enabled; TMR0MD TMR0 enabled; TMR1MD TMR1 enabled; TMR4MD TMR4 enabled; TMR5MD TMR5 enabled; TMR2MD TMR2 enabled; TMR3MD TMR3 enabled; TMR6MD TMR6 enabled;  | ||||||
|  |     PMD1 = 0x00; | ||||||
|  |     // ZCDMD ZCD enabled; DACMD DAC enabled; CMP1MD CMP1 enabled; ADCMD ADC enabled; CMP2MD CMP2 enabled;  | ||||||
|  |     PMD2 = 0x00; | ||||||
|  |     // CCP2MD CCP2 enabled; CCP1MD CCP1 enabled; CCP4MD CCP4 enabled; CCP3MD CCP3 enabled; PWM6MD PWM6 enabled; PWM5MD PWM5 enabled; PWM8MD PWM8 enabled; PWM7MD PWM7 enabled;  | ||||||
|  |     PMD3 = 0x00; | ||||||
|  |     // CWG3MD CWG3 enabled; CWG2MD CWG2 enabled; CWG1MD CWG1 enabled;  | ||||||
|  |     PMD4 = 0x00; | ||||||
|  |     // U2MD UART2 enabled; U1MD UART1 enabled; SPI1MD SPI1 enabled; I2C2MD I2C2 enabled; I2C1MD I2C1 enabled;  | ||||||
|  |     PMD5 = 0x00; | ||||||
|  |     // DSMMD DSM1 enabled; CLC3MD CLC3 enabled; CLC4MD CLC4 enabled; SMT1MD SMT1 enabled; SMT2MD SMT2 enabled; CLC1MD CLC1 enabled; CLC2MD CLC2 enabled;  | ||||||
|  |     PMD6 = 0x00; | ||||||
|  |     // DMA1MD DMA1 enabled; DMA2MD DMA2 enabled;  | ||||||
|  |     PMD7 = 0x00; | ||||||
|  | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  End of File | ||||||
|  | */ | ||||||
							
								
								
									
										105
									
								
								306-controller_interface.X/mcc_generated_files/mcc.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										105
									
								
								306-controller_interface.X/mcc_generated_files/mcc.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,105 @@ | |||||||
|  | /** | ||||||
|  |   @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            :  PIC18F26K83 | ||||||
|  |         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 <xc.h> | ||||||
|  | #include "device_config.h" | ||||||
|  | #include "pin_manager.h" | ||||||
|  | #include <stdint.h> | ||||||
|  | #include <stdbool.h> | ||||||
|  | #include <conio.h> | ||||||
|  | #include "interrupt_manager.h" | ||||||
|  | #include "memory.h" | ||||||
|  | #include "tmr0.h" | ||||||
|  | #include "ecan.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); | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * @Param | ||||||
|  |     none | ||||||
|  |  * @Returns | ||||||
|  |     none | ||||||
|  |  * @Description | ||||||
|  |     Initializes the PMD module to the default states configured in the | ||||||
|  |  *                  MCC GUI | ||||||
|  |  * @Example | ||||||
|  |     PMD_Initialize(void); | ||||||
|  |  */ | ||||||
|  | void PMD_Initialize(void); | ||||||
|  |  | ||||||
|  |  | ||||||
|  | #endif	/* MCC_H */ | ||||||
|  | /** | ||||||
|  |  End of File | ||||||
|  | */ | ||||||
							
								
								
									
										206
									
								
								306-controller_interface.X/mcc_generated_files/memory.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										206
									
								
								306-controller_interface.X/mcc_generated_files/memory.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,206 @@ | |||||||
|  | /** | ||||||
|  |   MEMORY Generated Driver File | ||||||
|  |  | ||||||
|  |   @Company | ||||||
|  |     Microchip Technology Inc. | ||||||
|  |  | ||||||
|  |   @File Name | ||||||
|  |     memory.c | ||||||
|  |  | ||||||
|  |   @Summary | ||||||
|  |     This is the generated driver implementation file for the MEMORY driver using PIC10 / PIC12 / PIC16 / PIC18 MCUs | ||||||
|  |  | ||||||
|  |   @Description | ||||||
|  |     This file provides implementations of driver APIs for MEMORY. | ||||||
|  |     Generation Information : | ||||||
|  |         Product Revision  :  PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8 | ||||||
|  |         Device            :  PIC18F26K83 | ||||||
|  |         Driver Version    :  2.1.3 | ||||||
|  |     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 <xc.h> | ||||||
|  | #include "memory.h" | ||||||
|  |  | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |   Section: Flash Module APIs | ||||||
|  | */ | ||||||
|  |  | ||||||
|  | uint8_t FLASH_ReadByte(uint32_t flashAddr) | ||||||
|  | { | ||||||
|  | 	NVMCON1bits.NVMREG = 2; | ||||||
|  |     TBLPTRU = (uint8_t)((flashAddr & 0x00FF0000) >> 16); | ||||||
|  |     TBLPTRH = (uint8_t)((flashAddr & 0x0000FF00)>> 8); | ||||||
|  |     TBLPTRL = (uint8_t)(flashAddr & 0x000000FF); | ||||||
|  |  | ||||||
|  |     asm("TBLRD"); | ||||||
|  |  | ||||||
|  |     return (TABLAT); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | uint16_t FLASH_ReadWord(uint32_t flashAddr) | ||||||
|  | { | ||||||
|  |     return ((((uint16_t)FLASH_ReadByte(flashAddr+1))<<8)|(FLASH_ReadByte(flashAddr))); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void FLASH_WriteByte(uint32_t flashAddr, uint8_t *flashRdBufPtr, uint8_t byte) | ||||||
|  | { | ||||||
|  |     uint32_t blockStartAddr = (uint32_t)(flashAddr & ((END_FLASH-1) ^ (ERASE_FLASH_BLOCKSIZE-1))); | ||||||
|  |     uint8_t offset = (uint8_t)(flashAddr & (ERASE_FLASH_BLOCKSIZE-1)); | ||||||
|  |     uint8_t i; | ||||||
|  |  | ||||||
|  |     // Entire row will be erased, read and save the existing data | ||||||
|  |     for (i=0; i<ERASE_FLASH_BLOCKSIZE; i++) | ||||||
|  |     { | ||||||
|  |         flashRdBufPtr[i] = FLASH_ReadByte((blockStartAddr+i)); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     // Load byte at offset | ||||||
|  |     flashRdBufPtr[offset] = byte; | ||||||
|  |  | ||||||
|  |     // Writes buffer contents to current block | ||||||
|  |     FLASH_WriteBlock(blockStartAddr, flashRdBufPtr); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | int8_t FLASH_WriteBlock(uint32_t writeAddr, uint8_t *flashWrBufPtr) | ||||||
|  | { | ||||||
|  |     uint32_t blockStartAddr  = (uint32_t )(writeAddr & ((END_FLASH-1) ^ (ERASE_FLASH_BLOCKSIZE-1))); | ||||||
|  |     uint8_t GIEBitValue = INTCON0bits.GIE;     // Save interrupt enable | ||||||
|  |     uint8_t i; | ||||||
|  |  | ||||||
|  |     // Flash write must start at the beginning of a row | ||||||
|  |     if( writeAddr != blockStartAddr ) | ||||||
|  |     { | ||||||
|  |         return -1; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     // Block erase sequence | ||||||
|  |     FLASH_EraseBlock(writeAddr); | ||||||
|  |  | ||||||
|  |     // Block write sequence | ||||||
|  |     TBLPTRU = (uint8_t)((writeAddr & 0x00FF0000) >> 16);    // Load Table point register | ||||||
|  |     TBLPTRH = (uint8_t)((writeAddr & 0x0000FF00)>> 8); | ||||||
|  |     TBLPTRL = (uint8_t)(writeAddr & 0x000000FF); | ||||||
|  |  | ||||||
|  |     // Write block of data | ||||||
|  |     for (i=0; i<WRITE_FLASH_BLOCKSIZE; i++) | ||||||
|  |     { | ||||||
|  |         TABLAT = flashWrBufPtr[i];  // Load data byte | ||||||
|  |  | ||||||
|  |         if (i == (WRITE_FLASH_BLOCKSIZE-1)) | ||||||
|  |         { | ||||||
|  |             asm("TBLWT"); | ||||||
|  |         } | ||||||
|  |         else | ||||||
|  |         { | ||||||
|  |             asm("TBLWTPOSTINC"); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     NVMCON1bits.NVMREG = 2; | ||||||
|  |     NVMCON1bits.WREN = 1;	 | ||||||
|  |     INTCON0bits.GIE = 0; // Disable interrupts	 | ||||||
|  |     NVMCON2 = 0x55; | ||||||
|  |     NVMCON2 = 0xAA; | ||||||
|  |     NVMCON1bits.WR = 1; // Start program | ||||||
|  | 	INTCON0bits.GIE = GIEBitValue; // Restore interrupt enable | ||||||
|  |     NVMCON1bits.WREN = 0; // Disable writes to memory | ||||||
|  |  | ||||||
|  |     return 0; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void FLASH_EraseBlock(uint32_t baseAddr) | ||||||
|  | { | ||||||
|  |     uint8_t GIEBitValue = INTCON0bits.GIE;   // Save interrupt enable | ||||||
|  |  | ||||||
|  |     TBLPTRU = (uint8_t)((baseAddr & 0x00FF0000) >> 16); | ||||||
|  |     TBLPTRH = (uint8_t)((baseAddr & 0x0000FF00)>> 8); | ||||||
|  |     TBLPTRL = (uint8_t)(baseAddr & 0x000000FF); | ||||||
|  |  | ||||||
|  |     NVMCON1bits.NVMREG = 2; | ||||||
|  |     NVMCON1bits.WREN = 1; | ||||||
|  |     NVMCON1bits.FREE = 1;	 | ||||||
|  |     INTCON0bits.GIE = 0; // Disable interrupts	 | ||||||
|  |     NVMCON2 = 0x55; | ||||||
|  |     NVMCON2 = 0xAA; | ||||||
|  |     NVMCON1bits.WR = 1; // Start program | ||||||
|  | 	INTCON0bits.GIE = GIEBitValue; // Restore interrupt enable | ||||||
|  |     NVMCON1bits.WREN = 0; // Disable writes to memory | ||||||
|  | } | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |   Section: Data EEPROM Module APIs | ||||||
|  | */ | ||||||
|  |  | ||||||
|  | void DATAEE_WriteByte(uint16_t bAdd, uint8_t bData) | ||||||
|  | { | ||||||
|  |     uint8_t GIEBitValue = INTCON0bits.GIE; | ||||||
|  |  | ||||||
|  |     NVMADRH = (uint8_t)((bAdd >> 8) & 0x03); | ||||||
|  |     NVMADRL = (uint8_t)(bAdd & 0xFF); | ||||||
|  |     NVMDAT = bData; | ||||||
|  |     NVMCON1bits.NVMREG = 0; | ||||||
|  |     NVMCON1bits.WREN = 1; | ||||||
|  |     INTCON0bits.GIE = 0;     // Disable interrupts | ||||||
|  |     NVMCON2 = 0x55; | ||||||
|  |     NVMCON2 = 0xAA; | ||||||
|  |     NVMCON1bits.WR = 1; | ||||||
|  |     // Wait for write to complete | ||||||
|  |     while (NVMCON1bits.WR) | ||||||
|  |     { | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     NVMCON1bits.WREN = 0; | ||||||
|  |     INTCON0bits.GIE = GIEBitValue;   // restore interrupt enable | ||||||
|  | } | ||||||
|  |  | ||||||
|  | uint8_t DATAEE_ReadByte(uint16_t bAdd) | ||||||
|  | { | ||||||
|  |     NVMADRH = (uint8_t)((bAdd >> 8) & 0x03); | ||||||
|  |     NVMADRL = (uint8_t)(bAdd & 0xFF); | ||||||
|  |     NVMCON1bits.NVMREG = 0; | ||||||
|  |     NVMCON1bits.RD = 1; | ||||||
|  |     NOP();  // NOPs may be required for latency at high frequencies | ||||||
|  |     NOP(); | ||||||
|  |  | ||||||
|  |     return (NVMDAT); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void MEMORY_Tasks( void ) | ||||||
|  | { | ||||||
|  |     /* TODO : Add interrupt handling code */ | ||||||
|  |     PIR0bits.NVMIF = 0; | ||||||
|  | } | ||||||
|  | /** | ||||||
|  |  End of File | ||||||
|  | */ | ||||||
							
								
								
									
										289
									
								
								306-controller_interface.X/mcc_generated_files/memory.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										289
									
								
								306-controller_interface.X/mcc_generated_files/memory.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,289 @@ | |||||||
|  | /** | ||||||
|  |   MEMORY Generated Driver API Header File | ||||||
|  |  | ||||||
|  |   @Company | ||||||
|  |     Microchip Technology Inc. | ||||||
|  |  | ||||||
|  |   @File Name | ||||||
|  |     memory.h | ||||||
|  |  | ||||||
|  |   @Summary | ||||||
|  |     This is the generated header file for the MEMORY driver using PIC10 / PIC12 / PIC16 / PIC18 MCUs | ||||||
|  |  | ||||||
|  |   @Description | ||||||
|  |     This header file provides APIs for driver for MEMORY. | ||||||
|  |     Generation Information : | ||||||
|  |         Product Revision  :  PIC10 / PIC12 / PIC16 / PIC18 MCUs - 1.81.8 | ||||||
|  |         Device            :  PIC18F26K83 | ||||||
|  |         Driver Version    :  2.1.3 | ||||||
|  |     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 MEMORY_H | ||||||
|  | #define MEMORY_H | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |   Section: Included Files | ||||||
|  | */ | ||||||
|  |  | ||||||
|  | #include <stdbool.h> | ||||||
|  | #include <stdint.h> | ||||||
|  |  | ||||||
|  | #ifdef __cplusplus  // Provide C++ Compatibility | ||||||
|  |  | ||||||
|  |     extern "C" { | ||||||
|  |  | ||||||
|  | #endif | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |   Section: Macro Declarations | ||||||
|  | */ | ||||||
|  |  | ||||||
|  | #define WRITE_FLASH_BLOCKSIZE    128 | ||||||
|  | #define ERASE_FLASH_BLOCKSIZE    128 | ||||||
|  | #define END_FLASH                0x010000 | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |   Section: Flash Module APIs | ||||||
|  | */ | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |   @Summary | ||||||
|  |     Reads a data byte from Flash | ||||||
|  |  | ||||||
|  |   @Description | ||||||
|  |     This routine reads a data byte from given Flash address | ||||||
|  |  | ||||||
|  |   @Preconditions | ||||||
|  |     None | ||||||
|  |  | ||||||
|  |   @Param | ||||||
|  |     flashAddr - Flash program memory location from which data has to be read | ||||||
|  |  | ||||||
|  |   @Returns | ||||||
|  |     Data byte read from given Flash address | ||||||
|  |  | ||||||
|  |   @Example | ||||||
|  |     <code> | ||||||
|  |     uint8_t    readByte; | ||||||
|  |     uint32_t    flashAddr = 0x7D00; | ||||||
|  |  | ||||||
|  |     readByte = FLASH_ReadByte(flashAddr); | ||||||
|  |     </code> | ||||||
|  | */ | ||||||
|  | uint8_t FLASH_ReadByte(uint32_t flashAddr); | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |   @Summary | ||||||
|  |     Reads a data word from Flash | ||||||
|  |  | ||||||
|  |   @Description | ||||||
|  |     This routine reads a data word from given Flash address | ||||||
|  |  | ||||||
|  |   @Preconditions | ||||||
|  |     None | ||||||
|  |  | ||||||
|  |   @Param | ||||||
|  |     flashAddr - Flash program memory location from which data has to be read | ||||||
|  |  | ||||||
|  |   @Returns | ||||||
|  |     Data word read from given Flash address | ||||||
|  |  | ||||||
|  |   @Example | ||||||
|  |     <code> | ||||||
|  |     uint16_t    readWord; | ||||||
|  |     uint32_t    flashAddr = 0x7D00; | ||||||
|  |  | ||||||
|  |     readWord = FLASH_ReadWord(flashAddr); | ||||||
|  |     </code> | ||||||
|  | */ | ||||||
|  | uint16_t FLASH_ReadWord(uint32_t flashAddr); | ||||||
|  |  | ||||||
|  |  /** | ||||||
|  |   @Summary | ||||||
|  |     Writes a data byte into Flash | ||||||
|  |  | ||||||
|  |   @Description | ||||||
|  |     This routine writes the given data byte into mentioned Flash address. | ||||||
|  |  | ||||||
|  |     This routine intially reads block of data (from Flash) into RAM, updates | ||||||
|  |     data values in RAM, and writes back updated values to Flash. | ||||||
|  |  | ||||||
|  |   @Preconditions | ||||||
|  |     None | ||||||
|  |  | ||||||
|  |   @Param | ||||||
|  |     flashAddr      - Flash program memory location to which data has to be written | ||||||
|  |     *flashRdBufPtr - Pointer to RAM buffer of size 'ERASE_FLASH_BLOCKSIZE' at least | ||||||
|  |     byte           - Data byte to be written in Flash | ||||||
|  |  | ||||||
|  |   @Returns | ||||||
|  |     None | ||||||
|  |  | ||||||
|  |   @Example | ||||||
|  |     <code> | ||||||
|  |     uint8_t    writeData = 0xAA; | ||||||
|  |     uint32_t    flashAddr = 0x7D00; | ||||||
|  |     uint8_t    Buf[ERASE_FLASH_BLOCKSIZE]; | ||||||
|  |  | ||||||
|  |     FLASH_WriteWord(flashAddr, Buf, writeData); | ||||||
|  |     </code> | ||||||
|  | */ | ||||||
|  | void FLASH_WriteByte(uint32_t flashAddr, uint8_t *flashRdBufPtr, uint8_t byte); | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |   @Summary | ||||||
|  |     Writes data to complete block of Flash | ||||||
|  |  | ||||||
|  |   @Description | ||||||
|  |     This routine writes data bytes to complete block in Flash program memory | ||||||
|  |  | ||||||
|  |   @Preconditions | ||||||
|  |     None | ||||||
|  |  | ||||||
|  |   @Param | ||||||
|  |     writeAddr      - A valid block starting address in Flash | ||||||
|  |     *flashWrBufPtr - Pointer to an array of size 'WRITE_FLASH_BLOCKSIZE' at least | ||||||
|  |  | ||||||
|  |   @Returns | ||||||
|  |     -1, if the given address is not a valid block starting address of Flash | ||||||
|  |     0, in case of valid block starting address | ||||||
|  |  | ||||||
|  |   @Example | ||||||
|  |     <code> | ||||||
|  |     #define FLASH_ROW_ADDRESS     0x7D00 | ||||||
|  |  | ||||||
|  |     uint8_t wrBlockData[] = | ||||||
|  |     { | ||||||
|  |         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, | ||||||
|  |         0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, | ||||||
|  |         0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, | ||||||
|  |         0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F | ||||||
|  |     }; | ||||||
|  |  | ||||||
|  |     // write to Flash memory block | ||||||
|  |     FLASH_WriteBlock((uint32_t)FLASH_ROW_ADDRESS, (uint8_t *)wrBlockData); | ||||||
|  |     </code> | ||||||
|  | */ | ||||||
|  | int8_t FLASH_WriteBlock(uint32_t writeAddr, uint8_t *flashWrBufPtr); | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |   @Summary | ||||||
|  |     Erases complete Flash program memory block | ||||||
|  |  | ||||||
|  |   @Description | ||||||
|  |     This routine erases complete Flash program memory block | ||||||
|  |  | ||||||
|  |   @Preconditions | ||||||
|  |     None | ||||||
|  |  | ||||||
|  |   @Param | ||||||
|  |     baseAddr - A valid block starting address in Flash program memory | ||||||
|  |  | ||||||
|  |   @Returns | ||||||
|  |     None | ||||||
|  |  | ||||||
|  |   @Example | ||||||
|  |     <code> | ||||||
|  |     uint32_t    flashBlockStartAddr = 0x7D00; | ||||||
|  |  | ||||||
|  |     FLASH_EraseBlock(flashBlockStartAddr); | ||||||
|  |     </code> | ||||||
|  | */ | ||||||
|  | void FLASH_EraseBlock(uint32_t baseAddr); | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |   Section: Data EEPROM Module APIs | ||||||
|  | */ | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |   @Summary | ||||||
|  |     Writes a data byte to Data EEPROM | ||||||
|  |  | ||||||
|  |   @Description | ||||||
|  |     This routine writes a data byte to given Data EEPROM location | ||||||
|  |  | ||||||
|  |   @Preconditions | ||||||
|  |     None | ||||||
|  |  | ||||||
|  |   @Param | ||||||
|  |     bAdd  - Data EEPROM location to which data to be written | ||||||
|  |     bData - Data to be written to Data EEPROM location | ||||||
|  |  | ||||||
|  |   @Returns | ||||||
|  |     None | ||||||
|  |  | ||||||
|  |   @Example | ||||||
|  |     <code> | ||||||
|  |     uint16_t dataeeAddr = 0x10; | ||||||
|  |     uint8_t dataeeData = 0x55; | ||||||
|  |  | ||||||
|  |     DATAEE_WriteByte(dataeeAddr, dataeeData); | ||||||
|  |     </code> | ||||||
|  | */ | ||||||
|  | void DATAEE_WriteByte(uint16_t bAdd, uint8_t bData); | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |   @Summary | ||||||
|  |     Reads a data byte from Data EEPROM | ||||||
|  |  | ||||||
|  |   @Description | ||||||
|  |     This routine reads a data byte from given Data EEPROM location | ||||||
|  |  | ||||||
|  |   @Preconditions | ||||||
|  |     None | ||||||
|  |  | ||||||
|  |   @Param | ||||||
|  |     bAdd  - Data EEPROM location from which data has to be read | ||||||
|  |  | ||||||
|  |   @Returns | ||||||
|  |     Data byte read from given Data EEPROM location | ||||||
|  |  | ||||||
|  |   @Example | ||||||
|  |     <code> | ||||||
|  |     uint16_t dataeeAddr = 0x10; | ||||||
|  |     uint8_t readData; | ||||||
|  |  | ||||||
|  |     readData = DATAEE_ReadByte(dataeeAddr); | ||||||
|  |     </code> | ||||||
|  | */ | ||||||
|  | uint8_t DATAEE_ReadByte(uint16_t bAdd); | ||||||
|  |  | ||||||
|  | void MEMORY_Tasks(void); | ||||||
|  |  | ||||||
|  | #ifdef __cplusplus  // Provide C++ Compatibility | ||||||
|  |  | ||||||
|  |     } | ||||||
|  |  | ||||||
|  | #endif | ||||||
|  |  | ||||||
|  | #endif // MEMORY_H | ||||||
|  | /** | ||||||
|  |  End of File | ||||||
|  | */ | ||||||
|  |  | ||||||
							
								
								
									
										124
									
								
								306-controller_interface.X/mcc_generated_files/pin_manager.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										124
									
								
								306-controller_interface.X/mcc_generated_files/pin_manager.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,124 @@ | |||||||
|  | /** | ||||||
|  |   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            :  PIC18F26K83 | ||||||
|  |         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 | ||||||
|  |     */ | ||||||
|  |     LATA = 0x00; | ||||||
|  |     LATB = 0x00; | ||||||
|  |     LATC = 0x00; | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |     TRISx registers | ||||||
|  |     */ | ||||||
|  |     TRISA = 0xFF; | ||||||
|  |     TRISB = 0xFE; | ||||||
|  |     TRISC = 0xFF; | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |     ANSELx registers | ||||||
|  |     */ | ||||||
|  |     ANSELC = 0xFF; | ||||||
|  |     ANSELB = 0xF6; | ||||||
|  |     ANSELA = 0x7F; | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |     WPUx registers | ||||||
|  |     */ | ||||||
|  |     WPUE = 0x00; | ||||||
|  |     WPUB = 0x00; | ||||||
|  |     WPUA = 0x80; | ||||||
|  |     WPUC = 0x00; | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |     ODx registers | ||||||
|  |     */ | ||||||
|  |     ODCONA = 0x00; | ||||||
|  |     ODCONB = 0x00; | ||||||
|  |     ODCONC = 0x00; | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |     SLRCONx registers | ||||||
|  |     */ | ||||||
|  |     SLRCONA = 0xFF; | ||||||
|  |     SLRCONB = 0xFF; | ||||||
|  |     SLRCONC = 0xFF; | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |     INLVLx registers | ||||||
|  |     */ | ||||||
|  |     INLVLA = 0xFF; | ||||||
|  |     INLVLB = 0xFF; | ||||||
|  |     INLVLC = 0xFF; | ||||||
|  |     INLVLE = 0x08; | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |     | ||||||
|  |      | ||||||
|  | 	 | ||||||
|  |     CANRXPPS = 0x0B;   //RB3->ECAN:CANRX;     | ||||||
|  | } | ||||||
|  |    | ||||||
|  | void PIN_MANAGER_IOC(void) | ||||||
|  | {    | ||||||
|  | } | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  End of File | ||||||
|  | */ | ||||||
							
								
								
									
										149
									
								
								306-controller_interface.X/mcc_generated_files/pin_manager.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										149
									
								
								306-controller_interface.X/mcc_generated_files/pin_manager.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,149 @@ | |||||||
|  | /** | ||||||
|  |   @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            :  PIC18F26K83 | ||||||
|  |         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 <xc.h> | ||||||
|  |  | ||||||
|  | #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 IO_RA7 aliases | ||||||
|  | #define IO_RA7_TRIS                 TRISAbits.TRISA7 | ||||||
|  | #define IO_RA7_LAT                  LATAbits.LATA7 | ||||||
|  | #define IO_RA7_PORT                 PORTAbits.RA7 | ||||||
|  | #define IO_RA7_WPU                  WPUAbits.WPUA7 | ||||||
|  | #define IO_RA7_OD                   ODCONAbits.ODCA7 | ||||||
|  | #define IO_RA7_ANS                  ANSELAbits.ANSELA7 | ||||||
|  | #define IO_RA7_SetHigh()            do { LATAbits.LATA7 = 1; } while(0) | ||||||
|  | #define IO_RA7_SetLow()             do { LATAbits.LATA7 = 0; } while(0) | ||||||
|  | #define IO_RA7_Toggle()             do { LATAbits.LATA7 = ~LATAbits.LATA7; } while(0) | ||||||
|  | #define IO_RA7_GetValue()           PORTAbits.RA7 | ||||||
|  | #define IO_RA7_SetDigitalInput()    do { TRISAbits.TRISA7 = 1; } while(0) | ||||||
|  | #define IO_RA7_SetDigitalOutput()   do { TRISAbits.TRISA7 = 0; } while(0) | ||||||
|  | #define IO_RA7_SetPullup()          do { WPUAbits.WPUA7 = 1; } while(0) | ||||||
|  | #define IO_RA7_ResetPullup()        do { WPUAbits.WPUA7 = 0; } while(0) | ||||||
|  | #define IO_RA7_SetPushPull()        do { ODCONAbits.ODCA7 = 0; } while(0) | ||||||
|  | #define IO_RA7_SetOpenDrain()       do { ODCONAbits.ODCA7 = 1; } while(0) | ||||||
|  | #define IO_RA7_SetAnalogMode()      do { ANSELAbits.ANSELA7 = 1; } while(0) | ||||||
|  | #define IO_RA7_SetDigitalMode()     do { ANSELAbits.ANSELA7 = 0; } while(0) | ||||||
|  |  | ||||||
|  | // get/set IO_RB0 aliases | ||||||
|  | #define IO_RB0_TRIS                 TRISBbits.TRISB0 | ||||||
|  | #define IO_RB0_LAT                  LATBbits.LATB0 | ||||||
|  | #define IO_RB0_PORT                 PORTBbits.RB0 | ||||||
|  | #define IO_RB0_WPU                  WPUBbits.WPUB0 | ||||||
|  | #define IO_RB0_OD                   ODCONBbits.ODCB0 | ||||||
|  | #define IO_RB0_ANS                  ANSELBbits.ANSELB0 | ||||||
|  | #define IO_RB0_SetHigh()            do { LATBbits.LATB0 = 1; } while(0) | ||||||
|  | #define IO_RB0_SetLow()             do { LATBbits.LATB0 = 0; } while(0) | ||||||
|  | #define IO_RB0_Toggle()             do { LATBbits.LATB0 = ~LATBbits.LATB0; } while(0) | ||||||
|  | #define IO_RB0_GetValue()           PORTBbits.RB0 | ||||||
|  | #define IO_RB0_SetDigitalInput()    do { TRISBbits.TRISB0 = 1; } while(0) | ||||||
|  | #define IO_RB0_SetDigitalOutput()   do { TRISBbits.TRISB0 = 0; } while(0) | ||||||
|  | #define IO_RB0_SetPullup()          do { WPUBbits.WPUB0 = 1; } while(0) | ||||||
|  | #define IO_RB0_ResetPullup()        do { WPUBbits.WPUB0 = 0; } while(0) | ||||||
|  | #define IO_RB0_SetPushPull()        do { ODCONBbits.ODCB0 = 0; } while(0) | ||||||
|  | #define IO_RB0_SetOpenDrain()       do { ODCONBbits.ODCB0 = 1; } while(0) | ||||||
|  | #define IO_RB0_SetAnalogMode()      do { ANSELBbits.ANSELB0 = 1; } while(0) | ||||||
|  | #define IO_RB0_SetDigitalMode()     do { ANSELBbits.ANSELB0 = 0; } while(0) | ||||||
|  |  | ||||||
|  | // get/set RB3 procedures | ||||||
|  | #define RB3_SetHigh()            do { LATBbits.LATB3 = 1; } while(0) | ||||||
|  | #define RB3_SetLow()             do { LATBbits.LATB3 = 0; } while(0) | ||||||
|  | #define RB3_Toggle()             do { LATBbits.LATB3 = ~LATBbits.LATB3; } while(0) | ||||||
|  | #define RB3_GetValue()              PORTBbits.RB3 | ||||||
|  | #define RB3_SetDigitalInput()    do { TRISBbits.TRISB3 = 1; } while(0) | ||||||
|  | #define RB3_SetDigitalOutput()   do { TRISBbits.TRISB3 = 0; } while(0) | ||||||
|  | #define RB3_SetPullup()             do { WPUBbits.WPUB3 = 1; } while(0) | ||||||
|  | #define RB3_ResetPullup()           do { WPUBbits.WPUB3 = 0; } while(0) | ||||||
|  | #define RB3_SetAnalogMode()         do { ANSELBbits.ANSELB3 = 1; } while(0) | ||||||
|  | #define RB3_SetDigitalMode()        do { ANSELBbits.ANSELB3 = 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 | ||||||
|  | */ | ||||||
							
								
								
									
										145
									
								
								306-controller_interface.X/mcc_generated_files/tmr0.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										145
									
								
								306-controller_interface.X/mcc_generated_files/tmr0.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,145 @@ | |||||||
|  | /** | ||||||
|  |   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            :  PIC18F26K83 | ||||||
|  |         Driver Version    :  3.10 | ||||||
|  |     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 <xc.h> | ||||||
|  | #include "tmr0.h" | ||||||
|  |  | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |   Section: TMR0 APIs | ||||||
|  | */ | ||||||
|  |  | ||||||
|  | void (*TMR0_InterruptHandler)(void); | ||||||
|  |  | ||||||
|  | void TMR0_Initialize(void) | ||||||
|  | { | ||||||
|  |     // Set TMR0 to the options selected in the User Interface | ||||||
|  |  | ||||||
|  |     // T0CS FOSC/4; T0CKPS 1:64; T0ASYNC synchronised;  | ||||||
|  |     T0CON1 = 0x46; | ||||||
|  |  | ||||||
|  |     // TMR0H 249;  | ||||||
|  |     TMR0H = 0xF9; | ||||||
|  |  | ||||||
|  |     // TMR0L 0;  | ||||||
|  |     TMR0L = 0x00; | ||||||
|  |  | ||||||
|  |     // Clear Interrupt flag before enabling the interrupt | ||||||
|  |     PIR3bits.TMR0IF = 0; | ||||||
|  |  | ||||||
|  |     // Enabling TMR0 interrupt. | ||||||
|  |     PIE3bits.TMR0IE = 1; | ||||||
|  |  | ||||||
|  |     // Set Default Interrupt Handler | ||||||
|  |     TMR0_SetInterruptHandler(TMR0_DefaultInterruptHandler); | ||||||
|  |  | ||||||
|  |     // T0OUTPS 1:10; T0EN enabled; T016BIT 8-bit;  | ||||||
|  |     T0CON0 = 0x89; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void TMR0_StartTimer(void) | ||||||
|  | { | ||||||
|  |     // Start the Timer by writing to TMR0ON bit | ||||||
|  |     T0CON0bits.T0EN = 1; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void TMR0_StopTimer(void) | ||||||
|  | { | ||||||
|  |     // Stop the Timer by writing to TMR0ON bit | ||||||
|  |     T0CON0bits.T0EN = 0; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | uint8_t TMR0_ReadTimer(void) | ||||||
|  | { | ||||||
|  |     uint8_t readVal; | ||||||
|  |  | ||||||
|  |     // read Timer0, low register only | ||||||
|  |     readVal = TMR0L; | ||||||
|  |  | ||||||
|  |     return readVal; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void TMR0_WriteTimer(uint8_t timerVal) | ||||||
|  | { | ||||||
|  |     // Write to Timer0 registers, low register only | ||||||
|  |     TMR0L = timerVal; | ||||||
|  |  } | ||||||
|  |  | ||||||
|  | void TMR0_Reload(uint8_t periodVal) | ||||||
|  | { | ||||||
|  |    // Write to Timer0 registers, high register only | ||||||
|  |    TMR0H = periodVal; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void TMR0_ISR(void) | ||||||
|  | { | ||||||
|  |     // clear the TMR0 interrupt flag | ||||||
|  |     PIR3bits.TMR0IF = 0; | ||||||
|  |     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 | ||||||
|  | */ | ||||||
							
								
								
									
										357
									
								
								306-controller_interface.X/mcc_generated_files/tmr0.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										357
									
								
								306-controller_interface.X/mcc_generated_files/tmr0.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,357 @@ | |||||||
|  | /** | ||||||
|  |   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            :  PIC18F26K83 | ||||||
|  |         Driver Version    :  3.10 | ||||||
|  |     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 <stdint.h> | ||||||
|  | #include <stdbool.h> | ||||||
|  |  | ||||||
|  | #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 | ||||||
|  |     <code> | ||||||
|  |     main() | ||||||
|  |     { | ||||||
|  |         // Initialize TMR0 module | ||||||
|  |         TMR0_Initialize(); | ||||||
|  |  | ||||||
|  |         // Do something else... | ||||||
|  |     } | ||||||
|  |     </code> | ||||||
|  | */ | ||||||
|  | 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 | ||||||
|  |     <code> | ||||||
|  |     // Initialize TMR0 module | ||||||
|  |  | ||||||
|  |     // Start TMR0 | ||||||
|  |     TMR0_StartTimer(); | ||||||
|  |  | ||||||
|  |     // Do something else... | ||||||
|  |     </code> | ||||||
|  | */ | ||||||
|  | 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 | ||||||
|  |     <code> | ||||||
|  |     // Initialize TMR0 module | ||||||
|  |  | ||||||
|  |     // Start TMR0 | ||||||
|  |     TMR0_StartTimer(); | ||||||
|  |  | ||||||
|  |     // Do something else... | ||||||
|  |  | ||||||
|  |     // Stop TMR0; | ||||||
|  |     TMR0_StopTimer(); | ||||||
|  |     </code> | ||||||
|  | */ | ||||||
|  | void TMR0_StopTimer(void); | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |   @Summary | ||||||
|  |     Reads the 8 bits TMR0 register value. | ||||||
|  |  | ||||||
|  |   @Description | ||||||
|  |     This function reads the 8 bits TMR0 register value and return it. | ||||||
|  |  | ||||||
|  |   @Preconditions | ||||||
|  |     Initialize  the TMR0 before calling this function. | ||||||
|  |  | ||||||
|  |   @Param | ||||||
|  |     None | ||||||
|  |  | ||||||
|  |   @Returns | ||||||
|  |     This function returns the 8 bits value of TMR0 register. | ||||||
|  |  | ||||||
|  |   @Example | ||||||
|  |     <code> | ||||||
|  |     // Initialize TMR0 module | ||||||
|  |  | ||||||
|  |     // Start TMR0 | ||||||
|  |     TMR0_StartTimer(); | ||||||
|  |  | ||||||
|  |     // Read the current value of TMR0 | ||||||
|  |     if(0 == TMR0_ReadTimer()) | ||||||
|  |     { | ||||||
|  |         // Do something else... | ||||||
|  |  | ||||||
|  |         // Stop TMR0; | ||||||
|  |         TMR0_StopTimer(); | ||||||
|  |     } | ||||||
|  |     </code> | ||||||
|  | */ | ||||||
|  | uint8_t TMR0_ReadTimer(void); | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |   @Summary | ||||||
|  |     Writes the 8 bits value to TMR0 register. | ||||||
|  |  | ||||||
|  |   @Description | ||||||
|  |     This function writes the 8 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 | ||||||
|  |     <code> | ||||||
|  |     #define PERIOD 0x80 | ||||||
|  |     #define ZERO   0x00 | ||||||
|  |  | ||||||
|  |     while(1) | ||||||
|  |     { | ||||||
|  |         // Read the TMR0 register | ||||||
|  |         if(ZERO == TMR0_ReadTimer()) | ||||||
|  |         { | ||||||
|  |             // Do something else... | ||||||
|  |  | ||||||
|  |             // Write the TMR0 register | ||||||
|  |             TMR0_WriteTimer(PERIOD); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         // Do something else... | ||||||
|  |     } | ||||||
|  |     </code> | ||||||
|  | */ | ||||||
|  | void TMR0_WriteTimer(uint8_t timerVal); | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |   @Summary | ||||||
|  |     Load value to Period Register. | ||||||
|  |  | ||||||
|  |   @Description | ||||||
|  |     This function writes the value to TMR0H register. | ||||||
|  |     This function must be called after the initialization of TMR0. | ||||||
|  |  | ||||||
|  |   @Preconditions | ||||||
|  |     Initialize  the TMR0 before calling this function. | ||||||
|  |  | ||||||
|  |   @Param | ||||||
|  |     periodVal - Value to load into TMR0 register. | ||||||
|  |  | ||||||
|  |   @Returns | ||||||
|  |     None | ||||||
|  |  | ||||||
|  |  | ||||||
|  |   @Example | ||||||
|  |     <code> | ||||||
|  |     while(1) | ||||||
|  |     { | ||||||
|  |         if(TMR0IF) | ||||||
|  |         { | ||||||
|  |             // Do something else... | ||||||
|  |  | ||||||
|  |             // clear the TMR0 interrupt flag | ||||||
|  |             TMR0IF = 0; | ||||||
|  |  | ||||||
|  |             // Change the period value of TMR0 | ||||||
|  |             TMR0_Reload(0x80); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |     </code> | ||||||
|  | */ | ||||||
|  | void TMR0_Reload(uint8_t periodVal); | ||||||
|  |  | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |   @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 | ||||||
|  | */ | ||||||
							
								
								
									
										248
									
								
								306-controller_interface.X/nbproject/configurations.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										248
									
								
								306-controller_interface.X/nbproject/configurations.xml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,248 @@ | |||||||
|  | <?xml version="1.0" encoding="UTF-8"?> | ||||||
|  | <configurationDescriptor version="65"> | ||||||
|  |   <logicalFolder name="root" displayName="root" projectFiles="true"> | ||||||
|  |     <logicalFolder name="HeaderFiles" | ||||||
|  |                    displayName="Header Files" | ||||||
|  |                    projectFiles="true"> | ||||||
|  |       <logicalFolder name="app" displayName="app" projectFiles="true"> | ||||||
|  |         <itemPath>app/blcontrol.h</itemPath> | ||||||
|  |       </logicalFolder> | ||||||
|  |       <logicalFolder name="board" displayName="board" projectFiles="true"> | ||||||
|  |         <logicalFolder name="button" displayName="button" projectFiles="true"> | ||||||
|  |           <itemPath>board/button/buttonsm.h</itemPath> | ||||||
|  |           <itemPath>board/button/button.h</itemPath> | ||||||
|  |         </logicalFolder> | ||||||
|  |         <logicalFolder name="led" displayName="led" projectFiles="true"> | ||||||
|  |           <itemPath>board/led/led.h</itemPath> | ||||||
|  |         </logicalFolder> | ||||||
|  |       </logicalFolder> | ||||||
|  |       <logicalFolder name="factory" displayName="factory" projectFiles="true"> | ||||||
|  |         <itemPath>factory/factory.h</itemPath> | ||||||
|  |       </logicalFolder> | ||||||
|  |       <logicalFolder name="MCC Generated Files" | ||||||
|  |                      displayName="MCC Generated Files" | ||||||
|  |                      projectFiles="true"> | ||||||
|  |         <itemPath>mcc_generated_files/pin_manager.h</itemPath> | ||||||
|  |         <itemPath>mcc_generated_files/device_config.h</itemPath> | ||||||
|  |         <itemPath>mcc_generated_files/mcc.h</itemPath> | ||||||
|  |         <itemPath>mcc_generated_files/interrupt_manager.h</itemPath> | ||||||
|  |         <itemPath>mcc_generated_files/tmr0.h</itemPath> | ||||||
|  |         <itemPath>mcc_generated_files/ecan.h</itemPath> | ||||||
|  |         <itemPath>mcc_generated_files/memory.h</itemPath> | ||||||
|  |       </logicalFolder> | ||||||
|  |       <logicalFolder name="middleware" displayName="middleware" projectFiles="true"> | ||||||
|  |       </logicalFolder> | ||||||
|  |       <logicalFolder name="xf" displayName="xf" projectFiles="true"> | ||||||
|  |         <itemPath>xf/event.h</itemPath> | ||||||
|  |         <itemPath>xf/xf.h</itemPath> | ||||||
|  |         <itemPath>xf/ireactive.h</itemPath> | ||||||
|  |       </logicalFolder> | ||||||
|  |     </logicalFolder> | ||||||
|  |     <logicalFolder name="LinkerScript" | ||||||
|  |                    displayName="Linker Files" | ||||||
|  |                    projectFiles="true"> | ||||||
|  |     </logicalFolder> | ||||||
|  |     <logicalFolder name="SourceFiles" | ||||||
|  |                    displayName="Source Files" | ||||||
|  |                    projectFiles="true"> | ||||||
|  |       <logicalFolder name="app" displayName="app" projectFiles="true"> | ||||||
|  |         <itemPath>app/blcontrol.c</itemPath> | ||||||
|  |       </logicalFolder> | ||||||
|  |       <logicalFolder name="board" displayName="board" projectFiles="true"> | ||||||
|  |         <logicalFolder name="button" displayName="button" projectFiles="true"> | ||||||
|  |           <itemPath>board/button/button.c</itemPath> | ||||||
|  |           <itemPath>board/button/buttonsm.c</itemPath> | ||||||
|  |         </logicalFolder> | ||||||
|  |         <logicalFolder name="led" displayName="led" projectFiles="true"> | ||||||
|  |           <itemPath>board/led/led.c</itemPath> | ||||||
|  |         </logicalFolder> | ||||||
|  |       </logicalFolder> | ||||||
|  |       <logicalFolder name="factory" displayName="factory" projectFiles="true"> | ||||||
|  |         <itemPath>factory/factory.c</itemPath> | ||||||
|  |       </logicalFolder> | ||||||
|  |       <logicalFolder name="MCC Generated Files" | ||||||
|  |                      displayName="MCC Generated Files" | ||||||
|  |                      projectFiles="true"> | ||||||
|  |         <itemPath>mcc_generated_files/interrupt_manager.c</itemPath> | ||||||
|  |         <itemPath>mcc_generated_files/tmr0.c</itemPath> | ||||||
|  |         <itemPath>mcc_generated_files/pin_manager.c</itemPath> | ||||||
|  |         <itemPath>mcc_generated_files/device_config.c</itemPath> | ||||||
|  |         <itemPath>mcc_generated_files/mcc.c</itemPath> | ||||||
|  |         <itemPath>mcc_generated_files/ecan.c</itemPath> | ||||||
|  |         <itemPath>mcc_generated_files/memory.c</itemPath> | ||||||
|  |       </logicalFolder> | ||||||
|  |       <logicalFolder name="middleware" displayName="middleware" projectFiles="true"> | ||||||
|  |       </logicalFolder> | ||||||
|  |       <logicalFolder name="xf" displayName="xf" projectFiles="true"> | ||||||
|  |         <itemPath>xf/event.c</itemPath> | ||||||
|  |         <itemPath>xf/xf.c</itemPath> | ||||||
|  |       </logicalFolder> | ||||||
|  |       <itemPath>main.c</itemPath> | ||||||
|  |     </logicalFolder> | ||||||
|  |     <logicalFolder name="ExternalFiles" | ||||||
|  |                    displayName="Important Files" | ||||||
|  |                    projectFiles="false"> | ||||||
|  |       <itemPath>Makefile</itemPath> | ||||||
|  |       <itemPath>ss22x0.mc3</itemPath> | ||||||
|  |       <itemPath>ss22ep.mc3</itemPath> | ||||||
|  |     </logicalFolder> | ||||||
|  |   </logicalFolder> | ||||||
|  |   <sourceRootList> | ||||||
|  |     <Elem>board</Elem> | ||||||
|  |     <Elem>led</Elem> | ||||||
|  |     <Elem>factory</Elem> | ||||||
|  |     <Elem>middleware</Elem> | ||||||
|  |     <Elem>app</Elem> | ||||||
|  |     <Elem>xf</Elem> | ||||||
|  |   </sourceRootList> | ||||||
|  |   <projectmakefile>Makefile</projectmakefile> | ||||||
|  |   <confs> | ||||||
|  |     <conf name="default" type="2"> | ||||||
|  |       <toolsSet> | ||||||
|  |         <developmentServer>localhost</developmentServer> | ||||||
|  |         <targetDevice>PIC18F26K83</targetDevice> | ||||||
|  |         <targetHeader></targetHeader> | ||||||
|  |         <targetPluginBoard></targetPluginBoard> | ||||||
|  |         <platformTool>PICkit3PlatformTool</platformTool> | ||||||
|  |         <languageToolchain>XC8</languageToolchain> | ||||||
|  |         <languageToolchainVersion>2.41</languageToolchainVersion> | ||||||
|  |         <platform>3</platform> | ||||||
|  |       </toolsSet> | ||||||
|  |       <packs> | ||||||
|  |         <pack name="PIC18F-K_DFP" vendor="Microchip" version="1.5.114"/> | ||||||
|  |       </packs> | ||||||
|  |       <ScriptingSettings> | ||||||
|  |       </ScriptingSettings> | ||||||
|  |       <compileType> | ||||||
|  |         <linkerTool> | ||||||
|  |           <linkerLibItems> | ||||||
|  |           </linkerLibItems> | ||||||
|  |         </linkerTool> | ||||||
|  |         <archiverTool> | ||||||
|  |         </archiverTool> | ||||||
|  |         <loading> | ||||||
|  |           <useAlternateLoadableFile>false</useAlternateLoadableFile> | ||||||
|  |           <parseOnProdLoad>false</parseOnProdLoad> | ||||||
|  |           <alternateLoadableFile></alternateLoadableFile> | ||||||
|  |         </loading> | ||||||
|  |         <subordinates> | ||||||
|  |         </subordinates> | ||||||
|  |       </compileType> | ||||||
|  |       <makeCustomizationType> | ||||||
|  |         <makeCustomizationPreStepEnabled>false</makeCustomizationPreStepEnabled> | ||||||
|  |         <makeUseCleanTarget>false</makeUseCleanTarget> | ||||||
|  |         <makeCustomizationPreStep></makeCustomizationPreStep> | ||||||
|  |         <makeCustomizationPostStepEnabled>false</makeCustomizationPostStepEnabled> | ||||||
|  |         <makeCustomizationPostStep></makeCustomizationPostStep> | ||||||
|  |         <makeCustomizationPutChecksumInUserID>false</makeCustomizationPutChecksumInUserID> | ||||||
|  |         <makeCustomizationEnableLongLines>false</makeCustomizationEnableLongLines> | ||||||
|  |         <makeCustomizationNormalizeHexFile>false</makeCustomizationNormalizeHexFile> | ||||||
|  |       </makeCustomizationType> | ||||||
|  |       <HI-TECH-COMP> | ||||||
|  |         <property key="additional-warnings" value="true"/> | ||||||
|  |         <property key="asmlist" value="true"/> | ||||||
|  |         <property key="call-prologues" value="false"/> | ||||||
|  |         <property key="default-bitfield-type" value="true"/> | ||||||
|  |         <property key="default-char-type" value="true"/> | ||||||
|  |         <property key="define-macros" value=""/> | ||||||
|  |         <property key="disable-optimizations" value="true"/> | ||||||
|  |         <property key="extra-include-directories" value=""/> | ||||||
|  |         <property key="favor-optimization-for" value="-speed,+space"/> | ||||||
|  |         <property key="garbage-collect-data" value="true"/> | ||||||
|  |         <property key="garbage-collect-functions" value="true"/> | ||||||
|  |         <property key="identifier-length" value="255"/> | ||||||
|  |         <property key="local-generation" value="false"/> | ||||||
|  |         <property key="operation-mode" value="free"/> | ||||||
|  |         <property key="opt-xc8-compiler-strict_ansi" value="false"/> | ||||||
|  |         <property key="optimization-assembler" value="true"/> | ||||||
|  |         <property key="optimization-assembler-files" value="true"/> | ||||||
|  |         <property key="optimization-debug" value="false"/> | ||||||
|  |         <property key="optimization-invariant-enable" value="false"/> | ||||||
|  |         <property key="optimization-invariant-value" value="16"/> | ||||||
|  |         <property key="optimization-level" value="-O0"/> | ||||||
|  |         <property key="optimization-speed" value="false"/> | ||||||
|  |         <property key="optimization-stable-enable" value="false"/> | ||||||
|  |         <property key="preprocess-assembler" value="true"/> | ||||||
|  |         <property key="short-enums" value="true"/> | ||||||
|  |         <property key="tentative-definitions" value="-fno-common"/> | ||||||
|  |         <property key="undefine-macros" value=""/> | ||||||
|  |         <property key="use-cci" value="false"/> | ||||||
|  |         <property key="use-iar" value="false"/> | ||||||
|  |         <property key="verbose" value="false"/> | ||||||
|  |         <property key="warning-level" value="-3"/> | ||||||
|  |         <property key="what-to-do" value="ignore"/> | ||||||
|  |       </HI-TECH-COMP> | ||||||
|  |       <HI-TECH-LINK> | ||||||
|  |         <property key="additional-options-checksum" value=""/> | ||||||
|  |         <property key="additional-options-code-offset" value=""/> | ||||||
|  |         <property key="additional-options-command-line" value=""/> | ||||||
|  |         <property key="additional-options-errata" value=""/> | ||||||
|  |         <property key="additional-options-extend-address" value="false"/> | ||||||
|  |         <property key="additional-options-trace-type" value=""/> | ||||||
|  |         <property key="additional-options-use-response-files" value="false"/> | ||||||
|  |         <property key="backup-reset-condition-flags" value="false"/> | ||||||
|  |         <property key="calibrate-oscillator" value="false"/> | ||||||
|  |         <property key="calibrate-oscillator-value" value="0x3400"/> | ||||||
|  |         <property key="clear-bss" value="true"/> | ||||||
|  |         <property key="code-model-external" value="wordwrite"/> | ||||||
|  |         <property key="code-model-rom" value=""/> | ||||||
|  |         <property key="create-html-files" value="false"/> | ||||||
|  |         <property key="data-model-ram" value=""/> | ||||||
|  |         <property key="data-model-size-of-double" value="32"/> | ||||||
|  |         <property key="data-model-size-of-double-gcc" value="no-short-double"/> | ||||||
|  |         <property key="data-model-size-of-float" value="32"/> | ||||||
|  |         <property key="data-model-size-of-float-gcc" value="no-short-float"/> | ||||||
|  |         <property key="display-class-usage" value="false"/> | ||||||
|  |         <property key="display-hex-usage" value="false"/> | ||||||
|  |         <property key="display-overall-usage" value="true"/> | ||||||
|  |         <property key="display-psect-usage" value="false"/> | ||||||
|  |         <property key="extra-lib-directories" value=""/> | ||||||
|  |         <property key="fill-flash-options-addr" value=""/> | ||||||
|  |         <property key="fill-flash-options-const" value=""/> | ||||||
|  |         <property key="fill-flash-options-how" value="0"/> | ||||||
|  |         <property key="fill-flash-options-inc-const" value="1"/> | ||||||
|  |         <property key="fill-flash-options-increment" value=""/> | ||||||
|  |         <property key="fill-flash-options-seq" value=""/> | ||||||
|  |         <property key="fill-flash-options-what" value="0"/> | ||||||
|  |         <property key="format-hex-file-for-download" value="false"/> | ||||||
|  |         <property key="initialize-data" value="true"/> | ||||||
|  |         <property key="input-libraries" value="libm"/> | ||||||
|  |         <property key="keep-generated-startup.as" value="false"/> | ||||||
|  |         <property key="link-in-c-library" value="true"/> | ||||||
|  |         <property key="link-in-c-library-gcc" value=""/> | ||||||
|  |         <property key="link-in-peripheral-library" value="false"/> | ||||||
|  |         <property key="managed-stack" value="false"/> | ||||||
|  |         <property key="opt-xc8-linker-file" value="false"/> | ||||||
|  |         <property key="opt-xc8-linker-link_startup" value="false"/> | ||||||
|  |         <property key="opt-xc8-linker-serial" value=""/> | ||||||
|  |         <property key="program-the-device-with-default-config-words" value="true"/> | ||||||
|  |         <property key="remove-unused-sections" value="true"/> | ||||||
|  |       </HI-TECH-LINK> | ||||||
|  |       <PICkit3PlatformTool> | ||||||
|  |         <property key="firmware.download.all" value="false"/> | ||||||
|  |       </PICkit3PlatformTool> | ||||||
|  |       <Tool> | ||||||
|  |         <property key="firmware.download.all" value="false"/> | ||||||
|  |       </Tool> | ||||||
|  |       <XC8-CO> | ||||||
|  |         <property key="coverage-enable" value=""/> | ||||||
|  |         <property key="stack-guidance" value="false"/> | ||||||
|  |       </XC8-CO> | ||||||
|  |       <XC8-config-global> | ||||||
|  |         <property key="advanced-elf" value="true"/> | ||||||
|  |         <property key="gcc-opt-driver-new" value="true"/> | ||||||
|  |         <property key="gcc-opt-std" value="-std=c99"/> | ||||||
|  |         <property key="gcc-output-file-format" value="dwarf-3"/> | ||||||
|  |         <property key="omit-pack-options" value="false"/> | ||||||
|  |         <property key="omit-pack-options-new" value="1"/> | ||||||
|  |         <property key="output-file-format" value="-mcof,+elf"/> | ||||||
|  |         <property key="stack-size-high" value="auto"/> | ||||||
|  |         <property key="stack-size-low" value="auto"/> | ||||||
|  |         <property key="stack-size-main" value="auto"/> | ||||||
|  |         <property key="stack-type" value="compiled"/> | ||||||
|  |         <property key="user-pack-device-support" value=""/> | ||||||
|  |         <property key="wpo-lto" value="false"/> | ||||||
|  |       </XC8-config-global> | ||||||
|  |     </conf> | ||||||
|  |   </confs> | ||||||
|  | </configurationDescriptor> | ||||||
							
								
								
									
										34
									
								
								306-controller_interface.X/nbproject/project.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								306-controller_interface.X/nbproject/project.xml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,34 @@ | |||||||
|  | <?xml version="1.0" encoding="UTF-8"?> | ||||||
|  | <project xmlns="http://www.netbeans.org/ns/project/1"> | ||||||
|  |     <type>com.microchip.mplab.nbide.embedded.makeproject</type> | ||||||
|  |     <configuration> | ||||||
|  |         <data xmlns="http://www.netbeans.org/ns/make-project/1"> | ||||||
|  |             <name>306-controller_interface</name> | ||||||
|  |             <creation-uuid>89baf189-5cb3-4a17-9f0a-47659c07dc79</creation-uuid> | ||||||
|  |             <make-project-type>0</make-project-type> | ||||||
|  |             <c-extensions>c</c-extensions> | ||||||
|  |             <cpp-extensions/> | ||||||
|  |             <header-extensions>h</header-extensions> | ||||||
|  |             <asminc-extensions/> | ||||||
|  |             <sourceEncoding>ISO-8859-1</sourceEncoding> | ||||||
|  |             <make-dep-projects/> | ||||||
|  |             <sourceRootList> | ||||||
|  |                 <sourceRootElem>board</sourceRootElem> | ||||||
|  |                 <sourceRootElem>led</sourceRootElem> | ||||||
|  |                 <sourceRootElem>factory</sourceRootElem> | ||||||
|  |                 <sourceRootElem>middleware</sourceRootElem> | ||||||
|  |                 <sourceRootElem>app</sourceRootElem> | ||||||
|  |                 <sourceRootElem>xf</sourceRootElem> | ||||||
|  |             </sourceRootList> | ||||||
|  |             <confList> | ||||||
|  |                 <confElem> | ||||||
|  |                     <name>default</name> | ||||||
|  |                     <type>2</type> | ||||||
|  |                 </confElem> | ||||||
|  |             </confList> | ||||||
|  |             <formatting> | ||||||
|  |                 <project-formatting-style>false</project-formatting-style> | ||||||
|  |             </formatting> | ||||||
|  |         </data> | ||||||
|  |     </configuration> | ||||||
|  | </project> | ||||||
							
								
								
									
										17228
									
								
								306-controller_interface.X/ss22ep.mc3
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17228
									
								
								306-controller_interface.X/ss22ep.mc3
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
							
								
								
									
										61
									
								
								306-controller_interface.X/xf/event.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										61
									
								
								306-controller_interface.X/xf/event.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,61 @@ | |||||||
|  | #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; | ||||||
|  | } | ||||||
							
								
								
									
										35
									
								
								306-controller_interface.X/xf/event.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								306-controller_interface.X/xf/event.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,35 @@ | |||||||
|  | #include <stdint.h> | ||||||
|  | #include <stdbool.h> | ||||||
|  | #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 | ||||||
							
								
								
									
										8
									
								
								306-controller_interface.X/xf/ireactive.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								306-controller_interface.X/xf/ireactive.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,8 @@ | |||||||
|  | #ifndef IREACTIVE_ONCE | ||||||
|  | #define IREACTIVE_ONCE | ||||||
|  |  | ||||||
|  | struct Event_; | ||||||
|  |  | ||||||
|  | typedef bool (*processEventT)(struct Event_* ev); | ||||||
|  |  | ||||||
|  | #endif | ||||||
							
								
								
									
										292
									
								
								306-controller_interface.X/xf/xf.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										292
									
								
								306-controller_interface.X/xf/xf.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,292 @@ | |||||||
|  | /******************************************************************************/ | ||||||
|  | /* FILENAME	: xf.h                                                            */ | ||||||
|  | /*----------------------------------------------------------------------------*/ | ||||||
|  | /* GOAL		  : Offers the femto XF functions (for PIC CPU)                     */ | ||||||
|  | /*----------------------------------------------------------------------------*/ | ||||||
|  | /* AUTHOR   : Medard Rieder / Pascal Sartoretti                               */ | ||||||
|  | /*----------------------------------------------------------------------------*/ | ||||||
|  | /* DATE:    : original (Medard Rieder 08.2011)                                */ | ||||||
|  | /*            corrections & simplified (Pascal Sartoretti 06.2016)            */ | ||||||
|  | /******************************************************************************/ | ||||||
|  | #include <stdbool.h>              // boolean types | ||||||
|  | #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<MAXEVENT; i++) | ||||||
|  |     { | ||||||
|  |         Event_init(&(theXF.eventQueue[i])); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     for (i=0; i<MAXTIMER; i++) | ||||||
|  |     { | ||||||
|  |         theXF.timerList[i].tm = NULLTIMER; | ||||||
|  |         Event_init(&(theXF.timerList[i].ev)); | ||||||
|  |     } | ||||||
|  |     theXF.in = 0; | ||||||
|  |     theXF.out = 0; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | /******************************************************************************/ | ||||||
|  | /* 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) | ||||||
|  | { | ||||||
|  |     uint8_t temp; | ||||||
|  |     Time tm; | ||||||
|  |     tm = Event_getDelay(&ev);  | ||||||
|  |     if ( tm > 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<MAXTIMER; i++) | ||||||
|  |     { | ||||||
|  |         if (theXF.timerList[i].ev.id == NULLEVENT) | ||||||
|  |         { | ||||||
|  |             theXF.timerList[i].tm = tm; | ||||||
|  |             theXF.timerList[i].ev = ev; | ||||||
|  |             break; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     //here you could react | ||||||
|  |     //if timerlist is full | ||||||
|  |  | ||||||
|  |     LEAVECRITICAL(inISR); | ||||||
|  |     return i; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | /******************************************************************************/ | ||||||
|  | /* 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) | ||||||
|  | { | ||||||
|  |     ENTERCRITICAL(inISR); | ||||||
|  |     theXF.timerList[id].tm = NULLTIMER; | ||||||
|  |     Event_init(&(theXF.timerList[id].ev));  | ||||||
|  |     LEAVECRITICAL(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() | ||||||
|  | { | ||||||
|  |     uint8_t i; | ||||||
|  |     for (i=0; i<MAXTIMER; i++) | ||||||
|  |     { | ||||||
|  |         if (theXF.timerList[i].ev.id != NULLEVENT) | ||||||
|  |         { | ||||||
|  |             theXF.timerList[i].tm-=TICKINTERVAL; | ||||||
|  |             if (theXF.timerList[i].tm ==0) | ||||||
|  |             { | ||||||
|  |                 TimerID dummy; | ||||||
|  |                 if (XF_pushEvent(theXF.timerList[i].ev, true, &dummy) == true) | ||||||
|  |                 {   | ||||||
|  |                   XF_unscheduleTimer(i, true); | ||||||
|  |                 } | ||||||
|  |                 else | ||||||
|  |                 { | ||||||
|  |                   theXF.timerList[i].tm=1; | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     //here you could use done to react | ||||||
|  |     //if timerID was not found (done == 0) | ||||||
|  | } | ||||||
|  |  | ||||||
|  | /******************************************************************************/ | ||||||
|  | /* FUNCTION     : Lock interrupts if not in ISR                               */ | ||||||
|  | /* INPUT        : -                                                           */ | ||||||
|  | /* OUTPUT       : -                                                           */ | ||||||
|  | /* COMMENTS     : -                                                           */ | ||||||
|  | /******************************************************************************/ | ||||||
|  | static void ENTERCRITICAL(bool inISR) | ||||||
|  | { | ||||||
|  |     if (inISR == false) | ||||||
|  |     { | ||||||
|  |       //GIE = 0; | ||||||
|  |       INTERRUPT_GlobalInterruptDisable(); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | /******************************************************************************/ | ||||||
|  | /* FUNCTION     : Unlock interrupts if not in ISR                             */ | ||||||
|  | /* INPUT        : -                                                           */ | ||||||
|  | /* OUTPUT       : -                                                           */ | ||||||
|  | /* COMMENTS     : -                                                           */ | ||||||
|  | /******************************************************************************/ | ||||||
|  | static void LEAVECRITICAL(bool inISR) | ||||||
|  | { | ||||||
|  |     if (inISR == false) | ||||||
|  |     { | ||||||
|  |       //GIE = 1; | ||||||
|  |      INTERRUPT_GlobalInterruptEnable();    | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | TimerID POST(void* target, processEventT processEvent, uint8_t id, Time delay , int64_t data) | ||||||
|  | { | ||||||
|  |     TimerID tmid = MAXTIMER;  //this is to say that no timer has been scheduled | ||||||
|  |                               //is a timer has been scheduled, the ID will be  | ||||||
|  |                               //from 0 to MAXTIMER-1 | ||||||
|  |     Event ev; | ||||||
|  |     Event_init(&ev); | ||||||
|  |     Event_setTarget(&ev,target); | ||||||
|  |     Event_setPE(&ev,processEvent); | ||||||
|  |     Event_setId(&ev,id); | ||||||
|  |     Event_setDelay(&ev,delay); | ||||||
|  |     Event_setData(&ev,data); | ||||||
|  |     XF_pushEvent(ev,false,&tmid); | ||||||
|  |     return tmid; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | void XF_executeOnce() | ||||||
|  | { | ||||||
|  |     Event ev = XF_popEvent(false); | ||||||
|  |     //if this event is valid | ||||||
|  |     if (ev.id != NULLEVENT) | ||||||
|  |     { | ||||||
|  |         //if this event has a valid target | ||||||
|  |         if (ev.target != NULL) | ||||||
|  |         { | ||||||
|  |             //if this event has a valid state machine | ||||||
|  |             //function pointer | ||||||
|  |             if (ev.processEvent != NULL) | ||||||
|  |             { | ||||||
|  |                 //call the state machine method function  | ||||||
|  |                 //and pass the event as parameter | ||||||
|  |                 ev.processEvent(&ev); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										84
									
								
								306-controller_interface.X/xf/xf.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										84
									
								
								306-controller_interface.X/xf/xf.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,84 @@ | |||||||
|  | /******************************************************************************/ | ||||||
|  | /* 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 <stdint.h>         // usage of standard types | ||||||
|  | #include <stdbool.h>        // 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 | ||||||
|  |  | ||||||
		Reference in New Issue
	
	Block a user