Files
luban-lite/packages/third-party/cherryusb/osal/usb_osal_rhino.c
刘可亮 564e22b32f v0.7.5
2023-08-28 09:48:01 +08:00

160 lines
3.4 KiB
C

/**
* @file usb_osal_rtthread.c
* @brief
*
* Copyright (c) 2022 sakumisu
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
*/
#include "usb_osal.h"
#include <aos/aos.h>
#include "k_api.h"
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)
{
aos_task_t task = NULL;
int ret = 0;
ret = aos_task_create(&task, name, entry,
args, NULL, stack_size, prio, 0);
if (ret != 0) {
return NULL;
}
ret = aos_task_resume(&task);
if (ret != 0) {
return NULL;
}
return (usb_osal_thread_t)task;
}
void usb_osal_thread_suspend(usb_osal_thread_t thread)
{
aos_task_suspend(&thread);
}
void usb_osal_thread_resume(usb_osal_thread_t thread)
{
aos_task_resume(&thread);
}
usb_osal_sem_t usb_osal_sem_create(uint32_t initial_count)
{
aos_sem_t sem = NULL;
int ret = 0;
ret = aos_sem_create(&sem, initial_count, 0);
if (ret != 0) {
return NULL;
}
return (usb_osal_sem_t)sem;
}
void usb_osal_sem_delete(usb_osal_sem_t sem)
{
aos_sem_free(&sem);
}
int usb_osal_sem_take(usb_osal_sem_t sem, uint32_t timeout)
{
return aos_sem_wait(&sem, timeout);
}
int usb_osal_sem_give(usb_osal_sem_t sem)
{
aos_sem_signal(&sem);
return 0;
}
usb_osal_mutex_t usb_osal_mutex_create(void)
{
aos_mutex_t mutex = NULL;
int ret = 0;
ret = aos_mutex_new(&mutex);
if (ret != 0) {
return NULL;
}
return (usb_osal_mutex_t)mutex;
}
void usb_osal_mutex_delete(usb_osal_mutex_t mutex)
{
aos_mutex_free(&mutex);
}
int usb_osal_mutex_take(usb_osal_mutex_t mutex)
{
return aos_mutex_lock(&mutex, AOS_WAIT_FOREVER);
}
int usb_osal_mutex_give(usb_osal_mutex_t mutex)
{
return aos_mutex_unlock(&mutex);
}
usb_osal_event_t usb_osal_event_create(void)
{
aos_event_t event = NULL;
int ret = 0;
ret = aos_event_new(&event, 0);
if (ret != 0) {
return NULL;
}
return (usb_osal_event_t)event;
}
void usb_osal_event_delete(usb_osal_event_t event)
{
aos_event_free(&event);
}
int usb_osal_event_recv(usb_osal_event_t event, uint32_t set, uint32_t *recved)
{
return aos_event_get(&event, set, AOS_EVENT_OR_CLEAR, recved, AOS_WAIT_FOREVER);
}
int usb_osal_event_send(usb_osal_event_t event, uint32_t set)
{
return aos_event_set(&event, set, AOS_EVENT_OR);
}
size_t usb_osal_enter_critical_section(void)
{
CPSR_ALLOC();
RHINO_CRITICAL_ENTER();
return cpsr;
}
void usb_osal_leave_critical_section(size_t flag)
{
CPSR_ALLOC();
cpsr = flag;
RHINO_CRITICAL_EXIT();
}
void usb_osal_msleep(uint32_t delay)
{
aos_msleep(delay);
}