typedef void (*event_func_t)( void *arg ); typedef struct { void *pargs; uint32_t debug; event_func_t pfunc; } event_data_handle_t; #define MAX_DELAY_EVENT 64 typedef struct { uint32_t event[MAX_DELAY_EVENT]; uint32_t args[MAX_DELAY_EVENT]; uint32_t delay[MAX_DELAY_EVENT]; uint32_t debug[MAX_DELAY_EVENT]; } event_delay_treat_t; #define APP_EVENT_MESQ_NUM 12 static struct rt_messagequeue app_event_mesq; static uint8_t event_mq_buffer[APP_EVENT_MESQ_NUM*sizeof(event_data_handle_t)]; static struct rt_mutex app_event_mutex; static struct rt_timer app_event_timer; static struct rt_semaphore timeout_event_sem; #define EVENT_TASK_SIZE 1024 #define EVENT_THREAD_PRIORITY 3 static void app_event_process_thread(void *args); static struct rt_thread app_event_thread; static uint8_t event_task_stack_buffer[EVENT_TASK_SIZE]; #define TIMEOUT_TASK_SIZE 1024 #define TIMEOUT_THREAD_PRIORITY 4 static void event_delay_timeout_handler(void *parameter); static void app_timeout_process_thread(void *args); static struct rt_thread app_timeout_thread; static uint8_t timer_task_stack_buffer[TIMEOUT_TASK_SIZE]; static volatile uint32_t s_event_start_ticks = 0; static volatile event_delay_treat_t event_delay_treat; static volatile uint32_t event_current_debug; static volatile uint32_t event_current_event; |
void app_event_init(void *args) { rt_err_t ret; event_printf("app_event_mesq..\r\n"); ret = rt_mq_init(&app_event_mesq, "evtmqt", &event_mq_buffer[0], sizeof(event_data_handle_t), sizeof(event_mq_buffer), RT_IPC_FLAG_FIFO); APP_ERROR_CHECK(ret); if (ret) { event_printf("app_event_mesq create failure\n"); } rt_timer_init(&app_event_timer, "evttimer", event_delay_timeout_handler, NULL, RT_WAITING_FOREVER, RT_TIMER_FLAG_ONE_SHOT); if(rt_thread_find("evttask")) { rt_thread_detach(&app_event_thread); } if(rt_thread_find("evttask") == NULL) { ret = rt_thread_init(&app_event_thread, "evttask", app_event_process_thread, RT_NULL, &event_task_stack_buffer[0], EVENT_TASK_SIZE, EVENT_THREAD_PRIORITY, 20); APP_ERROR_CHECK(ret); if (ret == RT_EOK) { rt_thread_startup(&app_event_thread); } } event_printf("app_event_thread creat ok!!\r\n"); if(rt_thread_find("evttimer")) { rt_thread_detach(&app_event_thread); } if(rt_thread_find("evttimer") == NULL) { ret = rt_thread_init(&app_timeout_thread, "evttimer", app_timeout_process_thread, RT_NULL, &timer_task_stack_buffer[0], TIMEOUT_TASK_SIZE, TIMEOUT_THREAD_PRIORITY, 20); APP_ERROR_CHECK(ret); if (ret == RT_EOK) { rt_thread_startup(&app_timeout_thread); } } event_printf("app_timeout_thread creat ok!!\r\n"); ret = rt_sem_init(&timeout_event_sem,"evtsem", 0, RT_IPC_FLAG_FIFO); APP_ERROR_CHECK(ret); if (ret) { event_printf("timeout_event_sem create failure = %d\n",ret); } event_printf("app_event_mutex.owner = %x\r\n",app_event_mutex.owner); if(app_event_mutex.owner == NULL) { event_printf("wait app event init\r\n"); while(1) { if(&app_event_timer) { break; } } ret = rt_mutex_init(&app_event_mutex,"mutex", RT_IPC_FLAG_FIFO); APP_ERROR_CHECK(ret); } event_printf("app event init complite\r\n"); } |
欢迎光临 嵌入式开发交流网论坛 (http://www.dianzixuexi.com/bbs/) | Powered by Discuz! X3.2 |