From b3fdaef64087eaa63063fe52894c071b49aec0e4 Mon Sep 17 00:00:00 2001 From: xj Date: Thu, 13 Jun 2024 03:00:24 -0700 Subject: [PATCH] Replanting OSAL codes --- .../drivers/usb/components/osal/usb_osal.c | 84 +++++++++++++++++-- .../drivers/usb/components/osal/usb_osal.h | 32 +++++++ 2 files changed, 110 insertions(+), 6 deletions(-) diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/usb/components/osal/usb_osal.c b/Ubiquitous/XiZi_AIoT/services/drivers/usb/components/osal/usb_osal.c index caa94e5ef..521e041e6 100644 --- a/Ubiquitous/XiZi_AIoT/services/drivers/usb/components/osal/usb_osal.c +++ b/Ubiquitous/XiZi_AIoT/services/drivers/usb/components/osal/usb_osal.c @@ -1,9 +1,20 @@ -/* - * Edited by Kameblue on June 12, 2024. +/* + * Copyright (c) 2022, sakumisu * - * For adapting CherryUSB to XiZi AIoT. + * SPDX-License-Identifier: Apache-2.0 */ +/************************************************* +File name: usb_osal.c +Description: adopt cherry USB to XiZi AIOT. +Others: CherryUSB v0.1.2/CherryUSB/osal/usb_osal_freertos.c for references + https://github.com/cherry-embedded/CherryUSB/blob/v0.10.2/osal/usb_osal_freertos.c +History: +1. Date: 2024-06-13 +Author: AIIT XUOS Lab +Modification: rename the file name, and re-develop all OS abstract layer function. +*************************************************/ + #include "usb_osal.h" #include "libserial.h" #include "syscall.h" @@ -27,23 +38,84 @@ void usb_osal_thread_delete(usb_osal_thread_t thread){ usb_osal_sem_t usb_osal_sem_create(uint32_t initial_count){ + int sem_id; + sem_id = semaphore_new(initial_count); - return NULL; + return (usb_osal_sem_t)sem_id; } void usb_osal_sem_delete(usb_osal_sem_t sem){ - + int sem_id; + sem_id = (int)sem; + semaphore_free(sem_id); } int usb_osal_sem_take(usb_osal_sem_t sem, uint32_t timeout){ + int sem_id; + sem_id = (int)sem; + + if(sem_id < 0) + return -1; + + semaphore_wait(sem_id); + return 0; } int usb_osal_sem_give(usb_osal_sem_t sem){ + int sem_id; + sem_id = (int)sem; + + if(sem_id < 0) + return -1; + + semaphore_signal(sem_id); + return 0; -} \ No newline at end of file +} + +usb_osal_mutex_t usb_osal_mutex_create(void){ + int mutex_id; + + mutex_id = semaphore_new(1); + + return (usb_osal_mutex_t)mutex_id; +} + +void usb_osal_mutex_delete(usb_osal_mutex_t mutex){ + int mutex_id; + mutex_id = (int)mutex; + semaphore_free(mutex_id); +} + +int usb_osal_mutex_take(usb_osal_mutex_t mutex){ + int mutex_id; + mutex_id = (int)mutex; + + if(mutex_id < 0) + return -1; + + semaphore_wait(mutex_id); + + return 0; +} + + +int usb_osal_mutex_give(usb_osal_mutex_t mutex){ + int mutex_id; + mutex_id = (int)mutex; + + if(mutex_id < 0) + return -1; + + semaphore_signal(mutex_id); + + return 0; +} + + diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/usb/components/osal/usb_osal.h b/Ubiquitous/XiZi_AIoT/services/drivers/usb/components/osal/usb_osal.h index 303df88c5..5317bd35a 100644 --- a/Ubiquitous/XiZi_AIoT/services/drivers/usb/components/osal/usb_osal.h +++ b/Ubiquitous/XiZi_AIoT/services/drivers/usb/components/osal/usb_osal.h @@ -1,3 +1,20 @@ +/* + * Copyright (c) 2022, sakumisu + * + * SPDX-License-Identifier: Apache-2.0 + */ + + + /************************************************* +File name: usb_osal.h +Description: support OS abstract layer +Others: take CherryUSB v0.1.2/CherryUSB/osal/usb_osal.h for references + https://github.com/cherry-embedded/CherryUSB/blob/v0.10.2/osal/usb_osal.h +History: +1. Date: 2024-06-13 +Author: AIIT XUOS Lab +Modification: introduce message queue mechanism. +*************************************************/ #ifndef USB_OSAL_H_ #define USB_OSAL_H_ @@ -13,6 +30,7 @@ typedef void *usb_osal_mq_t; typedef void (*usb_thread_entry_t)(void *argument); usb_osal_thread_t usb_osal_thread_create(const char *name, uint32_t stack_size, uint32_t prio, usb_thread_entry_t entry, void *args); +void usb_osal_thread_delete(usb_osal_thread_t thread); usb_osal_sem_t usb_osal_sem_create(uint32_t initial_count); void usb_osal_sem_delete(usb_osal_sem_t sem); @@ -34,4 +52,18 @@ void usb_osal_leave_critical_section(size_t flag); void usb_osal_msleep(uint32_t delay); +/* + * Defination of the Message queue. + */ + + #if 1 +struct osal_msg_queue{ + uint16_t msg_size; + uint16_t max_msgs; + uint16_t cur; + uint16_t header; + uint16_t tail; +}; +#endif + #endif