#pragma once

#include <stdint.h>
#include <semaphore.h>

#ifdef __cplusplus
extern "C" {
#endif 


// thread
/********************************************************************/


typedef void (*timer_func_cb)(void *arg);


void task_sleep_ms(uint32_t ms);


// event
/********************************************************************/

// 等待方式
#define TASK_EVENT_WAIT_FOREVER 0xFFFFFFFF

// 事件标志
#define TASK_EVENT_FLAG_AND 0x01
#define TASK_EVENT_FLAG_OR  0x02
#define TASK_EVENT_FLAG_CLEAR 0x04


typedef void *stru_task_event_t;


stru_task_event_t task_event_create(const char *name);
int task_event_destroy(stru_task_event_t p_event);
int task_event_send(stru_task_event_t p_event, uint32_t event);
int task_event_recv(stru_task_event_t p_event, uint32_t set, uint32_t opt, uint32_t timeout_ms, uint32_t *recved);
int task_event_clear(stru_task_event_t p_event, uint32_t event);

// msg_queue
/********************************************************************/


typedef void *stru_task_msg_queue_t;

stru_task_msg_queue_t task_msg_queue_create(const char *name, uint32_t msg_size, uint32_t msg_num);
int task_msg_queue_destroy(stru_task_msg_queue_t p_queue);
int task_msg_queue_send(stru_task_msg_queue_t p_queue, const void *msg, uint32_t len);
int task_msg_queue_recv(stru_task_msg_queue_t p_queue, void *msg, uint32_t len, uint32_t timeout_ms);
int task_msg_queue_try_recv(stru_task_msg_queue_t p_queue, void *msg, uint32_t size);
uint32_t task_msg_queue_get_count(stru_task_msg_queue_t p_queue);
uint32_t task_msg_queue_space(stru_task_msg_queue_t p_queue);

// timer
/********************************************************************/

#define TASK_TIMER_FLAG_ONCE 0x01
#define TASK_TIMER_FLAG_PERIODIC 0x02


typedef void *stru_task_timer_t;


stru_task_timer_t task_timer_create(const char *name, timer_func_cb fun_cb, void *arg, uint32_t timeout_ms, int flags);
int task_timer_start(stru_task_timer_t p_timer);
int task_timer_stop(stru_task_timer_t p_timer);
int task_timer_restart(stru_task_timer_t p_timer, uint32_t timeout_ms);
int task_timer_destroy(stru_task_timer_t p_timer);
int task_timer_is_active(stru_task_timer_t p_timer);

#ifdef __cplusplus
}
#endif



