Files
CherryUSB/osal/usb_osal_rtthread.c

88 lines
2.3 KiB
C
Raw Normal View History

2022-01-15 17:14:26 +08:00
/**
* @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 <rtthread.h>
2022-01-29 23:15:10 +08:00
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)
2022-01-15 17:14:26 +08:00
{
rt_thread_t htask;
htask = rt_thread_create(name, entry, args, stack_size, RT_THREAD_PRIORITY_MAX - 1 - prio, 10);
2022-01-15 17:14:26 +08:00
rt_thread_startup(htask);
return (usb_osal_thread_t)htask;
}
void usb_osal_thread_suspend(usb_osal_thread_t thread)
{
rt_thread_suspend(thread);
}
void usb_osal_thread_resume(usb_osal_thread_t thread)
{
rt_thread_resume(thread);
}
2022-01-15 17:14:26 +08:00
usb_osal_sem_t usb_osal_sem_create(uint32_t initial_count)
{
2022-01-29 23:15:10 +08:00
return (usb_osal_sem_t)rt_sem_create("usbh_sem", initial_count, RT_IPC_FLAG_FIFO);
2022-01-15 17:14:26 +08:00
}
int usb_osal_sem_take(usb_osal_sem_t sem)
{
return (int)rt_sem_take(sem, RT_WAITING_FOREVER);
}
int usb_osal_sem_give(usb_osal_sem_t sem)
{
return (int)rt_sem_release(sem);
}
usb_osal_mutex_t usb_osal_mutex_create(void)
{
2022-01-29 23:15:10 +08:00
return (usb_osal_mutex_t)rt_mutex_create("usbh_mutex", RT_IPC_FLAG_FIFO);
2022-01-15 17:14:26 +08:00
}
int usb_osal_mutex_take(usb_osal_mutex_t mutex)
{
return (int)rt_mutex_take(mutex, RT_WAITING_FOREVER);
}
int usb_osal_mutex_give(usb_osal_mutex_t mutex)
{
return (int)rt_mutex_release(mutex);
}
uint32_t usb_osal_enter_critical_section(void)
{
rt_enter_critical();
return 1;
}
void usb_osal_leave_critical_section(uint32_t flag)
{
rt_exit_critical();
}
2022-01-29 23:15:10 +08:00
void usb_osal_msleep(uint32_t delay)
2022-01-15 17:14:26 +08:00
{
rt_thread_mdelay(delay);
}