void stack_enumerate(const ComType com, const StackEnumerate *data) { if(com != COM_WIFI2) { StackEnumerateReturn ser = MESSAGE_EMPTY_INITIALIZER; ser.header = data->header; ser.header.length = sizeof(StackEnumerateReturn); ser.uids[0] = com_info.uid; uint8_t i = 1; for(uint8_t j = 0; j < BRICKLET_NUM; j++) { // Search for Bricklet UIDs if(bs[j].uid != 0) { ser.uids[i] = bs[j].uid; i++; } // Search for Isolators that are between the Brick and the Bricklet if(bs[j].uid_isolator != 0) { ser.uids[i] = bs[j].uid_isolator; i++; } } com_info.current = com; send_blocking_with_timeout(&ser, sizeof(StackEnumerateReturn), com); logd("Stack Enumerate: %lu %lu %lu %lu %lu\n\r", ser.uids[0], ser.uids[1], ser.uids[2], ser.uids[3], ser.uids[4]); } // Start stack enumerate timer. We will issue an enumeration if there is no // enumeration request in the next 1000ms. This is for backwards compatibility to // old Brick firmware versions. stack_enumerate_timer = system_timer_get_ms(); }
uint16_t send_blocking_with_timeout_options(const void *data, const uint16_t length, const ComType com, uint32_t *options) { uint16_t bytes_send = 0; uint32_t time_start = system_timer_get_ms(); while(length - bytes_send != 0 && !system_timer_is_time_elapsed_ms(time_start, com_blocking_timeout[com])) { bytes_send += SEND(data + bytes_send, length - bytes_send, com, options); taskYIELD(); } led_rxtx++; return bytes_send; }
void chibi_slave_init(void) { logchibii("Configuring chibi extension as Slave\n\r"); chibi_type = CHIBI_TYPE_SLAVE; chibi_low_level_init(); xTaskCreate(chibi_slave_message_loop, (signed char *)"chs_ml", MESSAGE_LOOP_SIZE, NULL, 1, (xTaskHandle *)NULL); chibi_first_message = 1; chibi_first_message_time = system_timer_get_ms(); }
void communication_callback_tick(void) { static uint32_t last_tick = 0; if(!system_timer_is_time_elapsed_ms(last_tick, COMMUNICATION_CALLBACK_TICK_WAIT_MS)) { return; } last_tick = system_timer_get_ms(); uint32_t cb_index = 0; for(uint32_t _ = 0; _ < COMMUNICATION_CALLBACK_HANDLER_NUM; _++) { if(communication_callbacks[cb_index]()) { communication_callback_handler_t current = communication_callbacks[cb_index]; for(uint32_t i = cb_index; i < COMMUNICATION_CALLBACK_HANDLER_NUM-1; i++) { communication_callbacks[i] = communication_callbacks[i+1]; } communication_callbacks[COMMUNICATION_CALLBACK_HANDLER_NUM-1] = current; } else { cb_index++; } } }
void bootloader_tick(void) { bootloader_status.system_timer_tick = system_timer_get_ms(); #ifdef BOOTLOADER_FUNCTION_SPITFP_TICK bootloader_spitfp_tick(&bootloader_status); #endif }
// This function can not be called from "main task" void coop_task_sleep_ms(const uint32_t sleep) { const uint32_t time = system_timer_get_ms(); while(!system_timer_is_time_elapsed_ms(time, sleep)) { coop_task_yield(); } }