uint32_t OS_Task_create(task_start_t pstart, void* param, uint32_t pri, uint32_t stack_size, char* task_name, void* opt) { osa_status_t status; /* * For uC/OS, we should allocate memory for task stack. */ #if ((defined (FSL_RTOS_UCOSII)) || (defined (FSL_RTOS_UCOSIII))) usb_adapter_task_struct* task_struct = OSA_MemAllocZero(sizeof(usb_adapter_task_struct)); if (!task_struct) { return (uint32_t)OS_TASK_ERROR; } task_struct->stack_mem = OSA_MemAlloc(stack_size); if(!task_struct->stack_mem) { OSA_MemFree(task_struct); return (uint32_t)OS_TASK_ERROR; } #if defined (FSL_RTOS_UCOSIII) task_struct->handler = OSA_MemAllocZero(sizeof(OS_TCB)); if(!task_struct->handler) { OSA_MemFree(task_struct->stack_mem); OSA_MemFree(task_struct); return (uint32_t)OS_TASK_ERROR; } #endif status = OSA_TaskCreate((task_t)pstart, (uint8_t*)task_name, stack_size, task_struct->stack_mem, pri, (task_param_t)param, false, &task_struct->handler); if (kStatus_OSA_Success == status) { return (uint32_t)task_struct; } else { return (uint32_t)OS_TASK_ERROR; } #else //((defined (FSL_RTOS_UCOSII)) || (defined (FSL_RTOS_UCOSIII))) task_handler_t task_handler; status = OSA_TaskCreate((task_t) pstart, (uint8_t*) task_name, stack_size, NULL, pri, (task_param_t) param, false, &task_handler); if (kStatus_OSA_Success == status) { return (uint32_t) task_handler; } else { return (uint32_t) OS_TASK_ERROR; } #endif //((defined (FSL_RTOS_UCOSII)) || (defined (FSL_RTOS_UCOSIII))) }
/* * NOTE: The msg_size here is counted by words, not bytes! */ os_msgq_handle OS_MsgQ_create(uint32_t max_msg_number, uint32_t msg_size) { os_msgq_handle ret; #if defined (FSL_RTOS_UCOSII) uint8_t *p_tmp; uint32_t size = sizeof(msg_queue_t) + (msg_size*sizeof(int32_t)+sizeof(void*))*max_msg_number; #elif defined (FSL_RTOS_UCOSIII) uint8_t *p_tmp; uint32_t size = sizeof(msg_queue_t) + (msg_size*sizeof(int32_t))*max_msg_number; #elif defined (FSL_RTOS_MQX) uint32_t size = (SIZE_IN_MMT_UNITS(sizeof(LWMSGQ_STRUCT)) + SIZE_IN_MMT_UNITS((msg_size*sizeof(int32_t))*(max_msg_number))) * sizeof(_mqx_max_type); #elif defined (FSL_RTOS_FREE_RTOS) #else /* Bare metal by default. */ uint8_t *p_tmp; uint32_t size = sizeof(msg_queue_t) + sizeof(uint32_t) * max_msg_number * msg_size; #endif #if defined (FSL_RTOS_FREE_RTOS) msg_queue_t* msgq = NULL; #else msg_queue_t* msgq = (msg_queue_t*) OSA_MemAllocZero(size); if (!msgq) { return (msg_queue_handler_t) 0; } #endif /* initialize the msg_queue_t */ #if defined (FSL_RTOS_UCOSII) p_tmp = (uint8_t*)msgq; p_tmp += sizeof(msg_queue_t); msgq->msgTbl = (void**)p_tmp; p_tmp += max_msg_number*sizeof(void*); msgq->msgs = (uint32_t*)p_tmp; #elif defined (FSL_RTOS_UCOSIII) p_tmp = (uint8_t*)msgq; p_tmp += sizeof(msg_queue_t); msgq->msgs = (void*)p_tmp; #elif defined (FSL_RTOS_MQX) #elif defined (FSL_RTOS_FREE_RTOS) #else /* Bare metal by default. */ p_tmp = (uint8_t*) msgq; p_tmp += sizeof(msg_queue_t); msgq->queueMem = (uint32_t*) p_tmp; #endif ret = OSA_MsgQCreate(msgq, max_msg_number, msg_size); #if !defined (FSL_RTOS_FREE_RTOS) if (!ret) { OSA_MemFree(msgq); } #endif return ret; }
uint32_t OS_Task_delete(uint32_t task_id) { #if ((defined (FSL_RTOS_UCOSII)) || (defined (FSL_RTOS_UCOSIII))) usb_adapter_task_struct* task_struct = (usb_adapter_task_struct*)task_id; if (kStatus_OSA_Success != OSA_TaskDestroy(task_struct->handler)) { return (uint32_t)OS_TASK_ERROR; } #if defined (FSL_RTOS_UCOSIII) OSA_MemFree(task_struct->handler); // Free TCB #endif OSA_MemFree(task_struct->stack_mem); // Free stack memory OSA_MemFree(task_struct); return (uint32_t)OS_TASK_OK; #else return (kStatus_OSA_Success == OSA_TaskDestroy((task_handler_t) task_id)) ? (uint32_t) OS_TASK_OK : (uint32_t) OS_TASK_ERROR; #endif }
uint32_t OS_Sem_destroy(os_sem_handle handle) { if (kStatus_OSA_Success == OSA_SemaDestroy((semaphore_t*) handle)) { OSA_MemFree(handle); return (uint32_t) OS_SEM_OK; } else { return (uint32_t) OS_SEM_ERROR; } }
uint32_t OS_Mutex_destroy(os_mutex_handle handle) { if (kStatus_OSA_Success == OSA_MutexDestroy((mutex_t*) handle)) { OSA_MemFree(handle); return (uint32_t) OS_MUTEX_OK; } else { return (uint32_t) OS_MUTEX_ERROR; } }
uint32_t OS_MsgQ_destroy(os_msgq_handle msgq) { if (kStatus_OSA_Success == OSA_MsgQDestroy((msg_queue_handler_t) msgq)) { #if !defined (FSL_RTOS_FREE_RTOS) OSA_MemFree(msgq); #endif return (uint32_t) OS_MSGQ_OK; } else { return (uint32_t) OS_MSGQ_ERROR; } }
uint32_t OS_Event_destroy(os_event_handle handle) { event_t* obj = (event_t*) handle; if (kStatus_OSA_Success == OSA_EventDestroy(obj)) { OSA_MemFree(handle); return (uint32_t) OS_EVENT_OK; } else { return (uint32_t) OS_EVENT_ERROR; } }
/* Mutex create and destroy */ os_mutex_handle OS_Mutex_create(void) { mutex_t *p_mutex = (mutex_t *) OSA_MemAllocZero(sizeof(mutex_t)); if (!p_mutex) { return (os_mutex_handle) 0; } if (kStatus_OSA_Success != OSA_MutexCreate(p_mutex)) { OSA_MemFree(p_mutex); return (os_mutex_handle) 0; } return (os_mutex_handle) p_mutex; }
/* Event create and destroy */ os_event_handle OS_Event_create(uint32_t flag) { event_t *p_event = (event_t *) OSA_MemAllocZero(sizeof(event_t)); if (!p_event) { return (os_event_handle) 0; } if (kStatus_OSA_Success != OSA_EventCreate(p_event, flag ? kEventAutoClear : kEventManualClear)) { OSA_MemFree(p_event); return (os_event_handle) 0; } return (os_event_handle) p_event; }
/* Semaphore create and destroy */ os_sem_handle OS_Sem_create(uint32_t initial_number) { semaphore_t *p_sem = (semaphore_t *) OSA_MemAllocZero(sizeof(semaphore_t)); if (!p_sem) { return (os_sem_handle) 0; } if (kStatus_OSA_Success != OSA_SemaCreate(p_sem, initial_number)) { OSA_MemFree(p_sem); return (os_sem_handle) 0; } return (os_sem_handle) p_sem; }
/*FUNCTION********************************************************************* * * Function Name : SND_RxDeinit * Description : Deinit the rx soundcard. * The soundcard includes a controller and a codec. *END**************************************************************************/ snd_status_t SND_RxDeinit(sound_card_t *card) { audio_controller_t *ctrl = &card->controller; audio_codec_t *codec = &card->codec; audio_buffer_t *buffer = &card->buffer; /* Call the deinit function of the ctrl and codec. */ ctrl->ops->Ctrl_RxDeinit(ctrl->instance); codec->ops->Codec_Deinit((void *)codec->handler); #if USEDMA /* Deinit the dma resource */ EDMA_DRV_StopChannel(&ctrl->dma_channel); EDMA_DRV_ReleaseChannel(&ctrl->dma_channel); #endif OSA_SemaDestroy(&buffer->sem); #if !SOUNDCARD_USE_STATIC_MEM /* Free the tx and rx buffer. */ OSA_MemFree(buffer->buff); #endif return kStatus_SND_Success; }
void free_align(void *ptr) { char pad; char count; if(ptr != NULL) { char *temp = ptr; temp--; /* Decrement pointer to find the padding size. */ pad = *temp; temp++; count = 0; while(count < pad) /* Decrement pointer to start of previously allocated memory. */ { temp--; count++; } OSA_MemFree(temp); temp = NULL; } }
static int nio_serial_init(void *init_data, void **dev_context) { osa_status_t status; NIO_SERIAL_DEV_CONTEXT_STRUCT *serial_dev_context = (NIO_SERIAL_DEV_CONTEXT_STRUCT *)dev_context; NIO_SERIAL_INIT_DATA_STRUCT *init = (NIO_SERIAL_INIT_DATA_STRUCT*)init_data; #if PLATFORM_LPUART_ENABLED assert(init->UART_INSTANCE < HW_LPUART_INSTANCE_COUNT); lpuart_user_config_t uartConfig = #else assert(init->UART_INSTANCE < HW_UART_INSTANCE_COUNT); uart_user_config_t uartConfig = #endif { .baudRate = init->BAUDRATE, .parityMode = init->PARITY_MODE, .stopBitCount = init->STOPBIT_COUNT, .bitCountPerChar = init->BITCOUNT_PERCHAR, }; serial_dev_context = (NIO_SERIAL_DEV_CONTEXT_STRUCT*) OSA_MemAlloc(sizeof(NIO_SERIAL_DEV_CONTEXT_STRUCT)); /* SDK HAL init */ #if PLATFORM_LPUART_ENABLED if ( kStatus_UART_Success != LPUART_DRV_Init(init->UART_INSTANCE, &serial_dev_context->uart_state, &uartConfig)) { errno = ENXIO; } /* LPUART handler interrupt installation */ status = OSA_InstallIntHandler(g_lpuartRxTxIrqId[init->UART_INSTANCE], init->handler); if (kStatus_OSA_Success != status) { errno = ENXIO; } NVIC_SetPriority(g_lpuartRxTxIrqId[init->UART_INSTANCE], init->RXTX_PRIOR); NVIC_EnableIRQ(g_lpuartRxTxIrqId[init->UART_INSTANCE]); #else if ( kStatus_UART_Success != UART_DRV_Init(init->UART_INSTANCE, &serial_dev_context->uart_state, &uartConfig)) { errno = ENXIO; } /* UART handler interrupt installation */ status = OSA_InstallIntHandler(g_uartRxTxIrqId[init->UART_INSTANCE], init->handler); if (kStatus_OSA_Success != status) { errno = ENXIO; } NVIC_SetPriority(g_uartRxTxIrqId[init->UART_INSTANCE], init->RXTX_PRIOR); NVIC_EnableIRQ(g_uartRxTxIrqId[init->UART_INSTANCE]); #endif serial_dev_context->instance = init->UART_INSTANCE; *dev_context = (void*)serial_dev_context; return 0; } static int nio_serial_deinit(void *dev_context) { NIO_SERIAL_DEV_CONTEXT_STRUCT *serial_dev_context = (NIO_SERIAL_DEV_CONTEXT_STRUCT *)dev_context; #if PLATFORM_LPUART_ENABLED LPUART_DRV_Deinit(serial_dev_context->instance); #else UART_DRV_Deinit(serial_dev_context->instance); #endif OSA_MemFree(dev_context); return 0; }
static int nio_dummy_deinit(void *dev_context, int *error) { OSA_SemaDestroy(&((NIO_DUMMY_DEV_CONTEXT_STRUCT*)dev_context)->lock); OSA_MemFree(dev_context); return 0; }
static int nio_dummy_close(void *dev_context, void *fp_context, int *error) { OSA_MemFree(fp_context); return 0; }