osal_none remove tu_malloc in queue API

This commit is contained in:
hathach 2018-05-17 19:13:07 +07:00
parent ca4d64caf6
commit d6794074e1
1 changed files with 15 additions and 25 deletions

View File

@ -128,24 +128,17 @@ static inline osal_task_t osal_task_create(osal_func_t code, const char* name, u
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// QUEUE API // QUEUE API
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
#define OSAL_QUEUE_DEF(_name, _depth, _type) FIFO_DEF(_name, _depth, _type, false)
typedef fifo_t osal_queue_def_t;
typedef fifo_t* osal_queue_t; typedef fifo_t* osal_queue_t;
static inline osal_queue_t osal_queue_create(uint32_t depth, uint32_t item_size) static inline osal_queue_t osal_queue_create(osal_queue_def_t* qdef)
{ {
fifo_t* ff = (fifo_t* ) tu_malloc( sizeof(fifo_t) ); fifo_clear(qdef);
uint8_t* buf = (uint8_t*) tu_malloc( depth*item_size ); return (osal_queue_t) qdef;
VERIFY( ff && buf, NULL);
*ff = (fifo_t) {
.buffer = buf, .depth = depth, .item_size = item_size,
.count = 0, .wr_idx =0, .rd_idx = 0, .overwritable = false
};
return (osal_queue_t) ff;
} }
static inline bool osal_queue_send_isr(osal_queue_t const queue_hdl, void const * data) static inline bool osal_queue_send_isr(osal_queue_t const queue_hdl, void const * data)
{ {
return fifo_write( (fifo_t*) queue_hdl, data); return fifo_write( (fifo_t*) queue_hdl, data);
@ -181,20 +174,16 @@ typedef struct
{ {
volatile uint16_t count; volatile uint16_t count;
uint16_t max_count; uint16_t max_count;
}osal_semaphore_data_t; }osal_semaphore_def_t;
typedef osal_semaphore_data_t* osal_semaphore_t; typedef osal_semaphore_def_t* osal_semaphore_t;
static inline osal_semaphore_t osal_semaphore_create(uint32_t max_count, uint32_t init) static inline osal_semaphore_t osal_semaphore_create(osal_semaphore_def_t* semdef)
{ {
osal_semaphore_data_t* sem_data = (osal_semaphore_data_t*) tu_malloc( sizeof(osal_semaphore_data_t)); semdef->count = 0;
VERIFY(sem_data, NULL); semdef->max_count = 1;
return semdef;
sem_data->count = init;
sem_data->max_count = max_count;
return sem_data;
} }
#define osal_semaphore_post_isr osal_semaphore_post #define osal_semaphore_post_isr osal_semaphore_post
@ -205,7 +194,7 @@ static inline bool osal_semaphore_post(osal_semaphore_t sem_hdl)
return true; return true;
} }
static inline void osal_semaphore_reset(osal_semaphore_t sem_hdl) static inline void osal_semaphore_reset_isr(osal_semaphore_t sem_hdl)
{ {
sem_hdl->count = 0; sem_hdl->count = 0;
} }
@ -230,6 +219,7 @@ static inline void osal_semaphore_reset(osal_semaphore_t sem_hdl)
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// MUTEX API (priority inheritance) // MUTEX API (priority inheritance)
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
#if 0
typedef osal_semaphore_t osal_mutex_t; typedef osal_semaphore_t osal_mutex_t;
static inline osal_mutex_t osal_mutex_create(void) static inline osal_mutex_t osal_mutex_create(void)
@ -243,7 +233,7 @@ static inline bool osal_mutex_release(osal_mutex_t mutex_hdl)
} }
#define osal_mutex_wait osal_semaphore_wait #define osal_mutex_wait osal_semaphore_wait
#endif
#ifdef __cplusplus #ifdef __cplusplus