Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
bootloader_hal.h
Go to the documentation of this file.
1
35#ifndef _INCLUDE_FREERTOS_BOOTLOADER_HAL_H_
36#define _INCLUDE_FREERTOS_BOOTLOADER_HAL_H_
37
38#include <stdint.h>
39#include "can_frame.h"
40
41
42#ifdef __cplusplus
43extern "C" {
44#else
46typedef unsigned bool;
47#endif
48
50#define CHECKSUM_COUNT 4
51
72
76 /* 1 when there is an incoming packet pending, an outgoing packet pending or
77 datagram being transmitted or deceived. */
78 LED_ACTIVE = 1,
79 /* 1 for the duration of erase and write operations. */
80 LED_WRITING = 2,
81 /* Not used currently. */
82 LED_IDENT = 4,
83 /* 1 if the applicaiton checksum failed. */
84 LED_CSUM_ERROR = 8,
85 /* 1 if the end-user requested entry to the bootloader. */
86 LED_REQUEST = 16,
87 /* 1 if a buffer overrun occurred. */
88 LED_FRAME_LOST = 32,
89};
90
93static const uint32_t REQUEST_BOOTLOADER = 0x76b89b1eU;
96extern uint32_t __bootloader_magic_ptr;
97
105
108extern void bootloader_hw_init(void);
109
113extern bool request_bootloader(void);
114
116extern void application_entry(void);
117
119extern void bootloader_reboot(void);
120
125extern void bootloader_led(enum BootloaderLed led, bool value);
126
133extern bool read_can_frame(struct can_frame *frame);
134
135#ifdef __cplusplus
136
143extern bool try_send_can_frame(const struct can_frame &frame);
144
145#endif
146
154extern void get_flash_boundaries(const void **flash_min, const void **flash_max,
155 const struct app_header **app_header);
156
165extern void get_flash_page_info(
166 const void *address, const void **page_start, uint32_t *page_length_bytes);
167
176extern void erase_flash_page(const void *address);
177
186extern void raw_erase_flash_page(const void *address);
187
195extern void write_flash(
196 const void *address, const void *data, uint32_t size_bytes);
197
207extern void raw_write_flash(
208 const void *address, const void *data, uint32_t size_bytes);
209
213extern uint16_t flash_complete(void);
214
221extern void checksum_data(const void* data, uint32_t size, uint32_t* checksum);
222
226extern uint16_t nmranet_alias(void);
227
230extern uint64_t nmranet_nodeid(void);
231
232#ifdef __cplusplus
233}
234#endif
235
236#endif // _INCLUDE_FREERTOS_BOOTLOADER_HAL_H_
bool try_send_can_frame(const struct can_frame &frame)
Callback from the bootloader to transmit a single CAN frame.
void get_flash_boundaries(const void **flash_min, const void **flash_max, const struct app_header **app_header)
Returns the boundaries of the user flash.
void raw_write_flash(const void *address, const void *data, uint32_t size_bytes)
Writes data to the flash.
void bootloader_reboot(void)
Resets the microcontroller.
void application_entry(void)
Enters the application.
uint32_t __bootloader_magic_ptr
This is the place where REQUEST_BOOTLOADER has to be written before rebooting the MCU to force enteri...
static const uint32_t REQUEST_BOOTLOADER
Write this value to __bootloader_magic_ptr and jump to the bootloader entry point in order to explici...
unsigned bool
Hack to allow compiling this code in C context too.
BootloaderLed
Parametrizes the bootloader_led function with logical functions that can be assigned to physical LEDs...
void erase_flash_page(const void *address)
Erases the flash page at a specific address.
void get_flash_page_info(const void *address, const void **page_start, uint32_t *page_length_bytes)
Rounds a flash address into a flash page.
void raw_erase_flash_page(const void *address)
Erases the flash page at a specific address.
void bootloader_led(enum BootloaderLed led, bool value)
Sets status LEDs.
void bootloader_hw_set_to_safe(void)
Initializes the hardware to a safe state of the outputs.
#define CHECKSUM_COUNT
Number of 32-bit words in one checksum data.
uint16_t flash_complete(void)
Signals that the bootloading operation is complete.
void checksum_data(const void *data, uint32_t size, uint32_t *checksum)
Computes checksum over a block of data.
bool request_bootloader(void)
void bootloader_hw_init(void)
Called after hw_set_to_safe and after the bss and data segments are initialized.
bool read_can_frame(struct can_frame *frame)
Checks if there is an incoming CAN frame from the hardware.
uint16_t nmranet_alias(void)
Suggests an NMRAnet CAN alias for use.
uint64_t nmranet_nodeid(void)
Callback from the bootloader to obtain the node-id to use.
void write_flash(const void *address, const void *data, uint32_t size_bytes)
Writes data to the flash.
Static definitions of the application.
uint32_t app_size
The total length of the application binary.
uint32_t checksum_pre[CHECKSUM_COUNT]
Checksum data for the application info.
uint32_t checksum_post[CHECKSUM_COUNT]
checksum_post: is the checksum of the bytes between the app_header and the application end.