Appendix A: Reference Main Function
The main function serves as the entry point for the CAN boards firmware.
Implementation
Calls the device specific initialization function (e.g. PIC18 Specific Initialization (Not Implemented) function)
mcu_init()
to initialize the chip.Calls user defined
pin_init()
function to setup PPS registers.Initialize timer for
millis()
function.Initialize CAN(controller and TX buffer)
Calls user defined
peripheral_init()
function to initialize other peripherals. (e.g. I2C, SPI)Start watchdog timer (PIC18 WDT starts by default)
Start the main loop
Main loop
The following steps are always running
Feed the watchdog timer
Check if the fail safe clock monitor has triggered, if so then set it back to use external crystal
Reset if X ms has passed since last time received a CAN message
Calls
loop()
functionif 20 ms has passed since last time, calls
periodic_20ms()
Justifications
The PPS setting function being implemented by user because it’s hard to pass a pin number as a parameter to a peripheral init function.