void tasks_create_tasks() { central_data = central_data_get_pointer_to_struct(); scheduler_t* scheduler = ¢ral_data->scheduler; // Main stabilisation loop scheduler_add_task(scheduler, 4000, RUN_REGULAR, PERIODIC_ABSOLUTE, PRIORITY_HIGHEST, &tasks_run_stabilisation_quaternion , 0 , 0); //scheduler_add_task(scheduler, 4000, RUN_REGULAR, PERIODIC_ABSOLUTE, PRIORITY_HIGHEST, &tasks_run_stabilisation , 0 , 0); // scheduler_add_task(scheduler, 4000, RUN_REGULAR, PERIODIC_ABSOLUTE, PRIORITY_HIGHEST, &tasks_run_stabilisation_test , 0 , 0); // LED scheduler_add_task(scheduler, 500000, RUN_REGULAR, PERIODIC_ABSOLUTE, PRIORITY_LOWEST , &tasks_led_toggle , 0 , 1); // State scheduler_add_task(scheduler, 200000, RUN_REGULAR, PERIODIC_ABSOLUTE, PRIORITY_NORMAL , (task_function_t)&state_machine_update , (task_argument_t)¢ral_data->state_machine , 2); // Communication scheduler_add_task(scheduler, 4000, RUN_REGULAR, PERIODIC_ABSOLUTE, PRIORITY_NORMAL , (task_function_t)&mavlink_communication_update , (task_argument_t)¢ral_data->mavlink_communication , 3); // Remote scheduler_add_task(scheduler, 20000, RUN_REGULAR, PERIODIC_RELATIVE, PRIORITY_HIGH , (task_function_t)&remote_update , (task_argument_t)¢ral_data->remote , 4); // Barometer scheduler_add_task(scheduler, 15000, RUN_REGULAR, PERIODIC_RELATIVE, PRIORITY_HIGH , &tasks_run_barometer_update , 0 , 5); // GPS scheduler_add_task(scheduler, 100000, RUN_REGULAR, PERIODIC_ABSOLUTE, PRIORITY_HIGH , &tasks_run_gps_update , 0 , 6); // Waypoint handler scheduler_add_task(scheduler, 10000, RUN_REGULAR, PERIODIC_ABSOLUTE, PRIORITY_LOW , (task_function_t)&waypoint_handler_control_time_out_waypoint_msg , (task_argument_t)¢ral_data->waypoint_handler , 7); // Navigation // scheduler_add_task(scheduler, 10000, RUN_REGULAR, PERIODIC_ABSOLUTE, PRIORITY_HIGH , (task_function_t)&navigation_update , (task_argument_t)¢ral_data->navigation , 8); // Analog monitor scheduler_add_task(scheduler, 100000, RUN_REGULAR, PERIODIC_ABSOLUTE, PRIORITY_LOW , (task_function_t)&analog_monitor_update , (task_argument_t)¢ral_data->analog_monitor , 9); // Data logging scheduler_add_task(scheduler, 100000, RUN_REGULAR, PERIODIC_ABSOLUTE, PRIORITY_LOW , (task_function_t)&data_logging_update , (task_argument_t)¢ral_data->data_logging , 10); // Others // scheduler_add_task(scheduler, 100000, RUN_REGULAR, PERIODIC_ABSOLUTE, PRIORITY_LOW , (task_function_t)&sonar_i2cxl_update , (task_argument_t)¢ral_data->sonar_i2cxl , 11); // Sort tasks by priority and update frequency scheduler_sort_tasks(scheduler); }
static void calibrate_task(struct task* task) { hum_temp_read(on_hum_temp_reading); if (task->times_run == CALIBRATE_SAMPLES) { struct task_config calibrate_task_config = { "htcal", TASK_ONCE, TASK_ASAP }; scheduler_add_task(&calibrate_task_config, calibrate_complete_task, NULL); } }
int main(void) { I2C_init(I2C_SPEED); //init i2c master for 100k init_time_sd(); vSemaphoreCreateBinary( event_signal ); // Create the semaphore xSemaphoreTake(event_signal, 0); // Take semaphore after creating it. scheduler_add_task(new terminalTask(PRIORITY_HIGH)); TaskHandle_t test1 = NULL; xTaskCreate((void(*)(void *))read_from_slave, "i2c_receive_task", 1024, NULL, PRIORITY_HIGH, &test1); eint3_enable_port2(0,eint_rising_edge,data_avail_isr); //register for rising edge interrupt scheduler_add_task(new send_CAN_data(PRIORITY_MEDIUM)); scheduler_add_task(new send_mailbox_config(PRIORITY_MEDIUM)); scheduler_add_task(new sendTrigTask()); //Task for getting the sensor data scheduler_start(); ///< This shouldn't return return -1; }
int main(void) { /** * A few basic tasks for this bare-bone system : * 1. Terminal task provides gateway to interact with the board through UART terminal. * 2. Remote task allows you to use remote control to interact with the board. * 3. Wireless task responsible to receive, retry, and handle mesh network. * * Disable remote task if you are not using it. Also, it needs SYS_CFG_ENABLE_TLM * such that it can save remote control codes to non-volatile memory. IR remote * control codes can be learned by typing the "learn" terminal command. */ //scheduler_add_task(new terminalTask(PRIORITY_HIGH)); /* Consumes very little CPU, but need highest priority to handle mesh network ACKs */ //scheduler_add_task(new wirelessTask(PRIORITY_CRITICAL)); /* Change "#if 0" to "#if 1" to run period tasks; @see period_callbacks.cpp */ #if 1 scheduler_add_task(new periodicSchedulerTask()); #endif /* The task for the IR receiver */ // scheduler_add_task(new remoteTask (PRIORITY_LOW)); /* Your tasks should probably used PRIORITY_MEDIUM or PRIORITY_LOW because you want the terminal * task to always be responsive so you can poke around in case something goes wrong. */ /** * This is a the board demonstration task that can be used to test the board. * This also shows you how to send a wireless packets to other boards. */ #if 0 scheduler_add_task(new example_io_demo()); #endif /** * Change "#if 0" to "#if 1" to enable examples. * Try these examples one at a time. */ #if 0 scheduler_add_task(new example_task()); scheduler_add_task(new example_alarm()); scheduler_add_task(new example_logger_qset()); scheduler_add_task(new example_nv_vars()); #endif /** * Try the rx / tx tasks together to see how they queue data to each other. */ #if 0 scheduler_add_task(new queue_tx()); scheduler_add_task(new queue_rx()); #endif /** * Another example of shared handles and producer/consumer using a queue. * In this example, producer will produce as fast as the consumer can consume. */ #if 0 scheduler_add_task(new producer()); scheduler_add_task(new consumer()); #endif /** * If you have RN-XV on your board, you can connect to Wifi using this task. * This does two things for us: * 1. The task allows us to perform HTTP web requests (@see wifiTask) * 2. Terminal task can accept commands from TCP/IP through Wifly module. * * To add terminal command channel, add this at terminal.cpp :: taskEntry() function: * @code * // Assuming Wifly is on Uart3 * addCommandChannel(Uart3::getInstance(), false); * @endcode */ #if 0 Uart3 &u3 = Uart3::getInstance(); u3.init(WIFI_BAUD_RATE, WIFI_RXQ_SIZE, WIFI_TXQ_SIZE); scheduler_add_task(new wifiTask(Uart3::getInstance(), PRIORITY_LOW)); #endif scheduler_start(); ///< This shouldn't return return 0; }
void light_setup_interrupt_schedule(uint16_t starttime) { light_set_interrupt_params(LIGHT_LEVEL_DRAWER_OPEN_MIN, 0x04); scheduler_add_task(SCHEDULER_MONITOR_LIST, LIGHT_TASK_ID, starttime, &light_wake); scheduler_add_task(SCHEDULER_MONITOR_LIST, LIGHT_TASK_ID, starttime += 105, &_light_interrupt_finish); }
void light_setup_reporting_schedule(uint16_t starttime) { scheduler_add_task(SCHEDULER_PERIODIC_SAMPLE_LIST,LIGHT_TASK_ID, starttime, &light_wake); scheduler_add_task(SCHEDULER_PERIODIC_SAMPLE_LIST,LIGHT_TASK_ID, starttime += 105, &_light_reporting_finish); // change based on integration constant }
bool onboard_parameters_init(onboard_parameters_t* onboard_parameters, const onboard_parameters_conf_t* config, scheduler_t* scheduler, mavlink_message_handler_t* message_handler, const mavlink_stream_t* mavlink_stream) { bool init_success = true; // Init dependencies onboard_parameters->mavlink_stream = mavlink_stream; // Init debug mode onboard_parameters->debug = config->debug; // Allocate memory for the onboard parameters onboard_parameters->param_set = malloc( sizeof(onboard_parameters_set_t) + sizeof(onboard_parameters_entry_t[config->max_param_count]) ); if ( onboard_parameters->param_set != NULL ) { onboard_parameters->param_set->max_param_count = config->max_param_count; onboard_parameters->param_set->param_count = 0; init_success &= true; } else { print_util_dbg_print("[ONBOARD PARAMETERS] ERROR ! Bad memory allocation\r\n"); onboard_parameters->param_set->max_param_count = 0; onboard_parameters->param_set->param_count = 0; init_success &= false; } // Add onboard parameter telemetry to the scheduler init_success &= scheduler_add_task( scheduler, 100000, RUN_REGULAR, PERIODIC_ABSOLUTE, PRIORITY_NORMAL, (task_function_t)&onboard_parameters_send_scheduled_parameters, (task_argument_t)onboard_parameters, MAVLINK_MSG_ID_PARAM_VALUE); // Add callbacks for onboard parameters requests mavlink_message_handler_msg_callback_t callback; callback.message_id = MAVLINK_MSG_ID_PARAM_REQUEST_LIST; // 21 callback.sysid_filter = MAVLINK_BASE_STATION_ID; callback.compid_filter = MAV_COMP_ID_ALL; callback.function = (mavlink_msg_callback_function_t) &onboard_parameters_send_all_parameters; callback.module_struct = (handling_module_struct_t) onboard_parameters; init_success &= mavlink_message_handler_add_msg_callback( message_handler, &callback ); callback.message_id = MAVLINK_MSG_ID_PARAM_REQUEST_READ; // 20 callback.sysid_filter = MAVLINK_BASE_STATION_ID; callback.compid_filter = MAV_COMP_ID_ALL; callback.function = (mavlink_msg_callback_function_t) &onboard_parameters_send_parameter; callback.module_struct = (handling_module_struct_t) onboard_parameters; init_success &= mavlink_message_handler_add_msg_callback( message_handler, &callback ); callback.message_id = MAVLINK_MSG_ID_PARAM_SET; // 23 callback.sysid_filter = MAVLINK_BASE_STATION_ID; callback.compid_filter = MAV_COMP_ID_ALL; callback.function = (mavlink_msg_callback_function_t) &onboard_parameters_receive_parameter; callback.module_struct = (handling_module_struct_t) onboard_parameters; init_success &= mavlink_message_handler_add_msg_callback( message_handler, &callback ); // Add callbacks for waypoint handler commands requests mavlink_message_handler_cmd_callback_t callbackcmd; callbackcmd.command_id = MAV_CMD_PREFLIGHT_STORAGE; // 245 callbackcmd.sysid_filter = MAVLINK_BASE_STATION_ID; callbackcmd.compid_filter = MAV_COMP_ID_ALL; callbackcmd.compid_target = MAV_COMP_ID_ALL; callbackcmd.function = (mavlink_cmd_callback_function_t) &onboard_parameters_preflight_storage; callbackcmd.module_struct = onboard_parameters; init_success &= mavlink_message_handler_add_cmd_callback( message_handler, &callbackcmd); print_util_dbg_print("[ONBOARD PARAMETERS] Initialised.\r\n"); return init_success; }
void hum_temp_calibrate(event_handler on_complete) { event_add_listener(EVENT_TYPE_HUM_TEMP, EVENT_DESCRIPTOR_HUM_TEMP_CALIBRATE, on_complete); struct task_config calibrate_task_config = { "htcal", CALIBRATE_SAMPLES, DHT11_POLL_INTERVAL }; scheduler_add_task(&calibrate_task_config, calibrate_task, NULL); }
void hum_temp_read(event_handler on_reading) { event_add_listener(EVENT_TYPE_HUM_TEMP, EVENT_DESCRIPTOR_HUM_TEMP_READING, on_reading); dht11_signal_start(&sensor_gpio); struct task_config read_task_config = { "dhtrd", TASK_ONCE, 18 }; scheduler_add_task(&read_task_config, hum_temp_complete_read, &sensor_gpio); }
void hum_temp_start_monitor(event_handler on_change) { struct task_config monitor_task_config = { "htmon", TASK_FOREVER, DHT11_POLL_INTERVAL * 10 }; monitor_task_id = scheduler_add_task(&monitor_task_config, monitor_task, NULL); event_add_listener(EVENT_TYPE_HUM_TEMP, EVENT_DESCRIPTOR_HUM_TEMP_CHANGE, on_change); }
void hum_temp_start_collector() { struct task_config collector_task_config = { "htcol", TASK_FOREVER, DHT11_POLL_INTERVAL }; collector_task_id = scheduler_add_task(&collector_task_config, collector_task, NULL); }