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 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++; } } }
// 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(); } }