33 #include "pios_bl_helper.h"
41 #define MSEC_TO_USEC(ms) ((ms) * 1000)
42 #define SEC_TO_MSEC(s) ((s) * 1000)
43 #define SEC_TO_USEC(s) ((s) * 1000 * 1000)
45 #define BL_DETECT_BREAK_TO_BL_TIMER_WITH_VSENSE MSEC_TO_USEC(2)
46 #define BL_DETECT_BREAK_TO_BL_TIMER_NO_VSENSE MSEC_TO_USEC(500)
48 #define BL_WAIT_FOR_DFU_TIMER SEC_TO_USEC(6)
49 #define BL_RECOVER_FROM_FAULT_TIMER SEC_TO_USEC(10)
331 uintptr_t initial_sp = *((__IO uint32_t*) bdinfo->
fw_base);
332 uintptr_t initial_pc = *((__IO uint32_t*) (bdinfo->
fw_base + 4));
335 if (((initial_sp & 0x2FFE0000) != 0x20000000) && ((initial_sp & 0x1FFE0000) != 0x10000000)) {
341 if ((initial_pc & 0x08000000) != 0x08000000) {
357 RCC_APB2PeriphResetCmd(0xffffffff, ENABLE);
358 RCC_APB1PeriphResetCmd(0xffffffff, ENABLE);
359 RCC_APB2PeriphResetCmd(0xffffffff, DISABLE);
360 RCC_APB1PeriphResetCmd(0xffffffff, DISABLE);
363 __set_MSP(initial_sp);
366 asm volatile(
"bx %r0" : :
"r" (initial_pc) : );
433 memset(context, 0,
sizeof(*context));
479 bool usb_connected =
false;
497 prev_ticks += elapsed_ticks;
501 if (!usb_connected) {
504 usb_connected =
true;
509 usb_connected =
false;
529 (uint8_t *)&bl_fsm_context.
msg,
530 sizeof(bl_fsm_context.
msg));
531 if (packet_available) {
539 if (device_number != 0) {
567 if (device_number == 0) {
577 }
else if (device_number == 1) {
599 memcpy (&echo, msg,
sizeof(echo));
690 if (flags & BL_MSG_FLAGS_ECHO_REQ) {
bool bl_xfer_completed_p(const struct xfer_state *xfer)
uint32_t PIOS_IAP_CheckRequest(void)
Determines if an In-Application-Programming request has been made.
enum bl_states curr_state
static void bl_fsm_inject_event(struct bl_fsm_context *context, enum bl_events event)
uint16_t PIOS_COM_MSG_Receive(uintptr_t com_id, uint8_t *buf, uint16_t buf_len)
static bool bl_fsm_timer_expired_p(struct bl_fsm_context *context)
struct bl_messages::@23::msg_enter_dfu enter_dfu
int32_t PIOS_COM_MSG_Send(uintptr_t com_id, const uint8_t *msg, uint16_t msg_len)
struct bl_messages::@23::msg_xfer_start xfer_start
uint32_t PIOS_DELAY_GetuS()
Query the Delay timer for the current uS.
struct bl_messages::@23::msg_wipe_partition wipe_partition
Main PiOS header to include all the compiled in PiOS options.
bool bl_xfer_read_start(struct xfer_state *xfer, const struct msg_xfer_start *xfer_start)
static void go_jumping_to_app(struct bl_fsm_context *context)
bool led_pwm_update_leds(struct led_pwm_state *leds)
#define BL_MSG_FLAGS_ECHO_REQ
bool bl_xfer_wipe_partition(const struct msg_wipe_partition *wipe_partition)
uint8_t dfu_device_number
struct led_pwm_state leds
APIs for PIOS_USBHOOK layer.
bool bl_xfer_send_next_read_packet(struct xfer_state *xfer)
#define BL_DETECT_BREAK_TO_BL_TIMER_WITH_VSENSE
static void go_write_in_progress(struct bl_fsm_context *context)
void PIOS_USBHOOK_Deactivate(void)
static void go_fsm_fault(struct bl_fsm_context *context)
uint32_t PIOS_DELAY_GetuSSince(uint32_t t)
Calculate time in microseconds since a previous time.
bool bl_xfer_crc_ok_p(const struct xfer_state *xfer)
#define BL_WAIT_FOR_DFU_TIMER
#define PIOS_COM_TELEM_USB
void(* entry_fn)(struct bl_fsm_context *context)
const struct pios_board_info pios_board_info_blob
static void bl_fsm_timer_start(struct bl_fsm_context *context, uint32_t timer_duration_us)
#define BL_RECOVER_FROM_FAULT_TIMER
static void process_packet_rx(struct bl_fsm_context *context, const struct bl_messages *msg)
void led_pwm_add_ticks(struct led_pwm_state *leds, uint32_t elapsed_us)
void PIOS_Board_Init(void)
static void bl_fsm_timer_cancel(struct bl_fsm_context *context)
bool bl_xfer_write_start(struct xfer_state *xfer, const struct msg_xfer_start *xfer_start)
#define BL_DETECT_BREAK_TO_BL_TIMER_NO_VSENSE
#define BL_MSG_COMMAND_MASK
static void go_dfu_idle(struct bl_fsm_context *context)
static void go_dfu_operation_ok(struct bl_fsm_context *context)
static void go_dfu_operation_failed(struct bl_fsm_context *context)
void PIOS_IAP_Init(void)
PIOS_IAP_Init - performs required initializations for iap module.
bool bl_xfer_write_cont(struct xfer_state *xfer, const struct msg_xfer_cont *xfer_cont)
void led_pwm_config(struct led_pwm_state *leds, uint32_t pwm_1_period_us, uint32_t pwm_1_sweep_steps, uint32_t pwm_2_period_us, uint32_t pwm_2_sweep_steps)
static bool bl_send_status(struct bl_fsm_context *context)
static void bl_fsm_process_auto(struct bl_fsm_context *context)
static bool bl_select_dfu_device(struct bl_fsm_context *context, uint8_t device_number)
void PIOS_ANNUNC_On(uint32_t annunc_id)
struct bl_messages::@23::msg_capabilities_req cap_req
static const uint8_t fsm_to_dfu_state_map[]
static void go_read_in_progress(struct bl_fsm_context *context)
COM MSG layer functions header.
uint32_t fsm_timer_remaining_us
int32_t PIOS_SYS_Reset(void)
#define BL_MSG_FLAGS_MASK
struct bl_messages::@23::msg_xfer_cont xfer_cont
static const struct bl_transition bl_transitions[BL_STATE_NUM_STATES]
int32_t PIOS_IRQ_Disable(void)
bool PIOS_USB_HaveVSense(uintptr_t id)
void PIOS_IAP_ClearRequest(void)
uint32_t PIOS_Boot_CheckRequest(void)
Determines if a boot request has been made.
static void bl_fsm_timer_add_ticks(struct bl_fsm_context *context, uint32_t elapsed_us)
static void go_wait_for_dfu(struct bl_fsm_context *context)
static bool bl_send_capabilities(struct bl_fsm_context *context, uint8_t device_number)
enum bl_states next_state[BL_EVENT_NUM_EVENTS]
void PIOS_IAP_WriteBootCount(uint16_t)
struct bl_messages::@23::msg_jump_fw jump_fw
bool PIOS_USB_CableConnected(uintptr_t id)
#define BL_MSG_FLAGS_ECHO_REP
static void go_detect_break_to_bl(struct bl_fsm_context *context)
static void bl_fsm_init(struct bl_fsm_context *context)
int32_t PIOS_DELAY_WaitmS(uint32_t mS)
static enum bl_states bl_fsm_get_state(struct bl_fsm_context *context)
bool bl_xfer_send_capabilities_self(void)
In application programming functions.
#define PIOS_LED_HEARTBEAT