forked from xuos/xiuos
Replanting OSAL codes
This commit is contained in:
parent
3acfca1e34
commit
b3fdaef640
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue