![]() |
PIC16F15214 Bootloader
|
#include <xc.h>#include <stdint.h>#include <stdbool.h>Macros | |
| #define | WRITE_FLASH_BLOCKSIZE 32 |
| Write Size of a line of flash in words. More... | |
| #define | ERASE_FLASH_BLOCKSIZE 32 |
| ERASE Size of a line of flash in words. More... | |
| #define | END_FLASH 0x1000 |
| End address of flash programming area (exclusive) More... | |
| #define | NEW_RESET_VECTOR 0x140 |
| The address (in words) in flash where the Application's reset vector will be placed. More... | |
| #define | NEW_INTERRUPT_VECTOR (NEW_RESET_VECTOR + 4) |
| The address (in words) in flash where the Application's interrupt handler or interrupt handler goto statement will be placed. More... | |
| #define | _str(x) #x |
| #define | str(x) _str(x) |
Functions | |
| asm ("psect intentry,global,class=CODE,delta=2") | |
| asm ("pagesel " str(NEW_INTERRUPT_VECTOR)) | |
| asm ("GOTO " str(NEW_INTERRUPT_VECTOR)) | |
| void | StartWrite () |
| Unlock and start the write or erase sequence. See the PIC16F15214 datasheet. More... | |
| uint8_t | EUSART1_Read (void) |
| Wait until a byte is avaialble from the UART and return it. More... | |
| void | EUSART1_Write (uint8_t txData) |
| Wait until buffer space is avaialble in the UART and transmit a byte. More... | |
| uint8_t | Bootload_Required () |
| Determine whether we should stay in the bootloader or jump to app Jump to app will happen unless one of the following criteria is present: More... | |
| void | Run_Bootloader () |
| The bootloader programming executable. This function is called if the Bootload_Required function indicates a bootload is required. More... | |
| void | main (void) |
| Main Program The main program contains a flattening of a number of functions created for initialization inside SYSTEM_Initialize by the Microchip code configurator (MCC) tool. The function calls were removed to save flash space since most functions simply assign values to registers. The original function name is commented out but left in to help line comparison software in the case that a comparison is done between this main and a new MCC generation. The Bootloader runs at 16MHz so that it can run down to 1.8V. More... | |
Variables | |
| uint8_t | bootloadReason = 0 |
| Global variable storing reason that the bootloader stayed in boot rather than jumping to the application. More... | |
| uint8_t | startBytes [4] |
| An array of bytes that is treated like a FIFO by the code. This array stores the last 4 bytes received and compares them to a magic value to enter the bootloader. More... | |
| #define _str | ( | x | ) | #x |
| #define END_FLASH 0x1000 |
End address of flash programming area (exclusive)
| #define ERASE_FLASH_BLOCKSIZE 32 |
ERASE Size of a line of flash in words.
| #define NEW_INTERRUPT_VECTOR (NEW_RESET_VECTOR + 4) |
The address (in words) in flash where the Application's interrupt handler or interrupt handler goto statement will be placed.
| #define NEW_RESET_VECTOR 0x140 |
The address (in words) in flash where the Application's reset vector will be placed.
| #define str | ( | x | ) | _str(x) |
| #define WRITE_FLASH_BLOCKSIZE 32 |
Write Size of a line of flash in words.
| asm | ( | "GOTO " | strNEW_INTERRUPT_VECTOR | ) |
| asm | ( | "pagesel " | strNEW_INTERRUPT_VECTOR | ) |
| asm | ( | "psect | intentry, |
| global | , | ||
| class | = CODE |
||
| ) |
| uint8_t Bootload_Required | ( | ) |
Determine whether we should stay in the bootloader or jump to app Jump to app will happen unless one of the following criteria is present:
| uint8_t EUSART1_Read | ( | void | ) |
Wait until a byte is avaialble from the UART and return it.
| void EUSART1_Write | ( | uint8_t | txData | ) |
Wait until buffer space is avaialble in the UART and transmit a byte.
| void main | ( | void | ) |
Main Program The main program contains a flattening of a number of functions created for initialization inside SYSTEM_Initialize by the Microchip code configurator (MCC) tool. The function calls were removed to save flash space since most functions simply assign values to registers. The original function name is commented out but left in to help line comparison software in the case that a comparison is done between this main and a new MCC generation. The Bootloader runs at 16MHz so that it can run down to 1.8V.
LATx registers
TRISx registers
ANSELx registers
WPUx registers
ODx registers
SLRCONx registers
INLVLx registers
| void Run_Bootloader | ( | void | ) |
The bootloader programming executable. This function is called if the Bootload_Required function indicates a bootload is required.
| void StartWrite | ( | void | ) |
Unlock and start the write or erase sequence. See the PIC16F15214 datasheet.
| uint8_t bootloadReason = 0 |
Global variable storing reason that the bootloader stayed in boot rather than jumping to the application.
Valid values are:
| uint8_t startBytes[4] |
An array of bytes that is treated like a FIFO by the code. This array stores the last 4 bytes received and compares them to a magic value to enter the bootloader.
1.8.17