Initial commit: TXW82x FPV v2.7.0.7-42229 SDK + project sources
This commit is contained in:
38
sdk/lib/misc/rtt/rt_event.c
Normal file
38
sdk/lib/misc/rtt/rt_event.c
Normal file
@@ -0,0 +1,38 @@
|
||||
#include "rtthread.h"
|
||||
|
||||
rt_err_t rt_event_init(rt_event_t event, const char *name, rt_uint8_t flag)
|
||||
{
|
||||
return os_event_init(event);
|
||||
}
|
||||
|
||||
rt_err_t rt_event_detach(rt_event_t event)
|
||||
{
|
||||
return os_event_del(event);
|
||||
}
|
||||
|
||||
rt_event_t rt_event_create(const char *name, rt_uint8_t flag)
|
||||
{
|
||||
struct rt_event *event = os_malloc(sizeof(struct rt_event));
|
||||
if (event) {
|
||||
os_event_init(event);
|
||||
}
|
||||
return event;
|
||||
}
|
||||
|
||||
rt_err_t rt_event_delete(rt_event_t event)
|
||||
{
|
||||
os_event_del(event);
|
||||
os_free(event);
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
rt_err_t rt_event_send(rt_event_t event, rt_uint32_t set)
|
||||
{
|
||||
return os_event_set(event, set, NULL);
|
||||
}
|
||||
|
||||
rt_err_t rt_event_recv(rt_event_t event, rt_uint32_t set, rt_uint8_t opt, rt_int32_t timeout, rt_uint32_t *recved)
|
||||
{
|
||||
return os_event_wait(event, set, recved, opt, timeout);
|
||||
}
|
||||
|
||||
71
sdk/lib/misc/rtt/rt_mq.c
Normal file
71
sdk/lib/misc/rtt/rt_mq.c
Normal file
@@ -0,0 +1,71 @@
|
||||
#include "rtthread.h"
|
||||
|
||||
rt_err_t rt_mq_init(rt_mq_t mq, const char *name, void *msgpool, rt_size_t msg_size, rt_size_t pool_size, rt_uint8_t flag)
|
||||
{
|
||||
return os_msgq_init(mq, pool_size);
|
||||
}
|
||||
|
||||
rt_err_t rt_mq_detach(rt_mq_t mq)
|
||||
{
|
||||
return os_msgq_del(mq);
|
||||
}
|
||||
|
||||
rt_mq_t rt_mq_create(const char *name, rt_size_t msg_size, rt_size_t max_msgs, rt_uint8_t flag)
|
||||
{
|
||||
struct rt_messagequeue *msgq = os_zalloc(sizeof(struct rt_messagequeue));
|
||||
if (msgq) {
|
||||
os_msgq_init(msgq, max_msgs);
|
||||
}
|
||||
return msgq;
|
||||
}
|
||||
|
||||
rt_err_t rt_mq_delete(rt_mq_t mq)
|
||||
{
|
||||
os_msgq_del(mq);
|
||||
os_free(mq);
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
rt_err_t rt_mq_send_wait(rt_mq_t mq, const void *buffer, rt_size_t size, rt_int32_t timeout)
|
||||
{
|
||||
void *ptr = os_malloc(size);
|
||||
if (ptr) {
|
||||
os_memcpy(ptr, buffer, size);
|
||||
if (os_msgq_put(mq, (uint32)ptr, timeout)) {
|
||||
os_free(ptr);
|
||||
return RT_ERROR;
|
||||
}
|
||||
return RT_EOK;
|
||||
}
|
||||
return RT_ENOMEM;
|
||||
}
|
||||
|
||||
rt_err_t rt_mq_send(rt_mq_t mq, const void *buffer, rt_size_t size)
|
||||
{
|
||||
return rt_mq_send_wait(mq, buffer, size, osWaitForever);
|
||||
}
|
||||
|
||||
rt_err_t rt_mq_urgent(rt_mq_t mq, const void *buffer, rt_size_t size)
|
||||
{
|
||||
void *ptr = os_malloc(size);
|
||||
if (ptr) {
|
||||
os_memcpy(ptr, buffer, size);
|
||||
if (os_msgq_put_head(mq, (uint32)ptr, osWaitForever)) {
|
||||
os_free(ptr);
|
||||
return RT_ERROR;
|
||||
}
|
||||
return RT_EOK;
|
||||
}
|
||||
return RT_ENOMEM;
|
||||
}
|
||||
|
||||
rt_err_t rt_mq_recv(rt_mq_t mq, void *buffer, rt_size_t size, rt_int32_t timeout)
|
||||
{
|
||||
void *ptr = (void *)os_msgq_get(mq, timeout);
|
||||
if (ptr) {
|
||||
os_memcpy(buffer, ptr, size);
|
||||
os_free(ptr);
|
||||
}
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
52
sdk/lib/misc/rtt/rt_rbuffer.c
Normal file
52
sdk/lib/misc/rtt/rt_rbuffer.c
Normal file
@@ -0,0 +1,52 @@
|
||||
#include "rtthread.h"
|
||||
|
||||
void rt_ringbuffer_init(struct rt_ringbuffer *rb, rt_uint8_t *pool, rt_int16_t size)
|
||||
{
|
||||
rbuffer_init(rb, size, pool);
|
||||
}
|
||||
|
||||
void rt_ringbuffer_reset(struct rt_ringbuffer *rb)
|
||||
{
|
||||
rbuffer_reset(rb);
|
||||
}
|
||||
|
||||
void rt_ringbuffer_destroy(struct rt_ringbuffer *rb)
|
||||
{
|
||||
rbuffer_destroy(rb);
|
||||
}
|
||||
|
||||
rt_size_t rt_ringbuffer_put(struct rt_ringbuffer *rb, const rt_uint8_t *ptr, rt_uint16_t length)
|
||||
{
|
||||
return rbuffer_set(rb, (void *)ptr, length);
|
||||
}
|
||||
|
||||
rt_size_t rt_ringbuffer_put_force(struct rt_ringbuffer *rb, const rt_uint8_t *ptr, rt_uint16_t length)
|
||||
{
|
||||
return rbuffer_set_force(rb, (void *)ptr, length);
|
||||
}
|
||||
|
||||
rt_size_t rt_ringbuffer_putchar(struct rt_ringbuffer *rb, const rt_uint8_t ch)
|
||||
{
|
||||
return rbuffer_set(rb, (void *)&ch, 1);
|
||||
}
|
||||
|
||||
rt_size_t rt_ringbuffer_putchar_force(struct rt_ringbuffer *rb, const rt_uint8_t ch)
|
||||
{
|
||||
return rbuffer_set_force(rb, (void *)&ch, 1);
|
||||
}
|
||||
|
||||
rt_size_t rt_ringbuffer_get(struct rt_ringbuffer *rb, rt_uint8_t *ptr, rt_uint16_t length)
|
||||
{
|
||||
return rbuffer_get(rb, ptr, length);
|
||||
}
|
||||
|
||||
rt_size_t rt_ringbuffer_getchar(struct rt_ringbuffer *rb, rt_uint8_t *ch)
|
||||
{
|
||||
return rbuffer_get(rb, ch, 1);
|
||||
}
|
||||
|
||||
rt_size_t rt_ringbuffer_data_len(struct rt_ringbuffer *rb)
|
||||
{
|
||||
return RB_COUNT(rb);
|
||||
}
|
||||
|
||||
43
sdk/lib/misc/rtt/rt_sem.c
Normal file
43
sdk/lib/misc/rtt/rt_sem.c
Normal file
@@ -0,0 +1,43 @@
|
||||
#include "rtthread.h"
|
||||
|
||||
rt_err_t rt_sem_init(rt_sem_t sem, const char *name, rt_uint32_t value, rt_uint8_t flag)
|
||||
{
|
||||
return os_sema_init(sem, value);
|
||||
}
|
||||
|
||||
rt_err_t rt_sem_detach(rt_sem_t sem)
|
||||
{
|
||||
return os_sema_del(sem);
|
||||
}
|
||||
|
||||
rt_sem_t rt_sem_create(const char *name, rt_uint32_t value, rt_uint8_t flag)
|
||||
{
|
||||
struct rt_semaphore *sem = os_malloc(sizeof(struct rt_semaphore));
|
||||
if (sem) {
|
||||
os_sema_init(sem, value);
|
||||
}
|
||||
return sem;
|
||||
}
|
||||
|
||||
rt_err_t rt_sem_delete(rt_sem_t sem)
|
||||
{
|
||||
os_sema_del(sem);
|
||||
os_free(sem);
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
rt_err_t rt_sem_take(rt_sem_t sem, rt_int32_t time)
|
||||
{
|
||||
return (os_sema_down(sem, time) == 1) ? RT_EOK : RT_ERROR;
|
||||
}
|
||||
|
||||
rt_err_t rt_sem_trytake(rt_sem_t sem)
|
||||
{
|
||||
return (os_sema_down(sem, 0) == 1) ? RT_EOK : RT_ERROR;
|
||||
}
|
||||
|
||||
rt_err_t rt_sem_release(rt_sem_t sem)
|
||||
{
|
||||
return os_sema_up(sem);
|
||||
}
|
||||
|
||||
136
sdk/lib/misc/rtt/rt_thread.c
Normal file
136
sdk/lib/misc/rtt/rt_thread.c
Normal file
@@ -0,0 +1,136 @@
|
||||
#include "rtthread.h"
|
||||
|
||||
rt_thread_t rt_thread_create(const char *name, void (*entry)(void *parameter), void *parameter,
|
||||
rt_uint32_t stack_size, rt_uint8_t priority, rt_uint32_t tick)
|
||||
{
|
||||
struct rt_thread *thd = os_malloc(sizeof(struct rt_thread));
|
||||
void *stack = os_malloc(stack_size+124); //124 = sizeof(ktask_t)
|
||||
if(stack == RT_NULL)
|
||||
{
|
||||
os_printf("[%s]:stack malloc failed!!!\n",__FUNCTION__); //usb任务栈使用sram空间,避免打到psram动态申请导致usb异常
|
||||
return NULL;
|
||||
}
|
||||
if (thd) {
|
||||
os_task_init((const uint8 *)name, thd, entry, (uint32)parameter);
|
||||
os_task_set_priority(thd, priority);
|
||||
os_task_set_stack(thd, stack, stack_size+124); //124 = sizeof(ktask_t)
|
||||
}
|
||||
return thd;
|
||||
}
|
||||
|
||||
rt_err_t rt_thread_delete(rt_thread_t thread)
|
||||
{
|
||||
rt_err_t ret;
|
||||
ret = os_task_del(thread);
|
||||
if(thread->stack)
|
||||
{
|
||||
os_free(thread->stack);
|
||||
}
|
||||
os_free(thread);
|
||||
return ret;
|
||||
}
|
||||
|
||||
rt_err_t rt_thread_init(struct rt_thread *thread, const char *name, void (*entry)(void *parameter),
|
||||
void *parameter, void *stack_start, rt_uint32_t stack_size,
|
||||
rt_uint8_t priority, rt_uint32_t tick)
|
||||
{
|
||||
void *stack = RT_NULL;
|
||||
rt_uint32_t stacksize = 0;
|
||||
|
||||
stacksize = stack_size+124; //124 = sizeof(ktask_t)
|
||||
stack = os_malloc(stacksize); //usb任务栈使用sram空间,避免打到psram动态申请导致usb异常
|
||||
if(stack == RT_NULL)
|
||||
{
|
||||
os_printf("[%s]:stack malloc failed!!!\n",__FUNCTION__);
|
||||
return RT_ERROR;
|
||||
}
|
||||
|
||||
if(stack_start)
|
||||
{
|
||||
os_printf("[%s]:This api auto malloc stack, you can free your stack space!!!\r\n");
|
||||
}
|
||||
|
||||
os_task_init((const uint8 *)name, thread, entry, (uint32)parameter);
|
||||
os_task_set_priority(thread, priority);
|
||||
os_task_set_stack(thread, stack, stacksize);
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
rt_err_t rt_thread_detach(rt_thread_t thread)
|
||||
{
|
||||
rt_err_t ret;
|
||||
ret = os_task_del(thread);
|
||||
if(thread->stack)
|
||||
{
|
||||
os_free(thread->stack);
|
||||
thread->stack = NULL;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
rt_thread_t rt_thread_self(void)
|
||||
{
|
||||
return (rt_thread_t)os_task_data(os_task_current());
|
||||
}
|
||||
|
||||
rt_thread_t rt_thread_find(char *name)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
rt_err_t rt_thread_startup(rt_thread_t thread)
|
||||
{
|
||||
return os_task_run(thread);
|
||||
}
|
||||
|
||||
rt_err_t rt_thread_yield(void)
|
||||
{
|
||||
return os_task_yield();
|
||||
}
|
||||
|
||||
rt_err_t rt_thread_delay(rt_tick_t tick)
|
||||
{
|
||||
os_sleep_ms(os_jiffies_to_msecs(tick));
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
rt_err_t rt_thread_delay_until(rt_tick_t *tick, rt_tick_t inc_tick)
|
||||
{
|
||||
return RT_ERROR;
|
||||
}
|
||||
|
||||
rt_err_t rt_thread_mdelay(rt_int32_t ms)
|
||||
{
|
||||
os_sleep_ms(ms);
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
rt_err_t rt_thread_control(rt_thread_t thread, int cmd, void *arg)
|
||||
{
|
||||
return RT_ERROR;
|
||||
}
|
||||
|
||||
rt_err_t rt_thread_suspend(rt_thread_t thread)
|
||||
{
|
||||
return os_task_suspend(thread);
|
||||
}
|
||||
|
||||
rt_err_t rt_thread_resume(rt_thread_t thread)
|
||||
{
|
||||
return os_task_resume(thread);
|
||||
}
|
||||
|
||||
void rt_thread_timeout(void *parameter)
|
||||
{
|
||||
}
|
||||
|
||||
void rt_enter_critical(void)
|
||||
{
|
||||
os_sched_disable();
|
||||
}
|
||||
|
||||
void rt_exit_critical(void)
|
||||
{
|
||||
os_sched_enbale();
|
||||
}
|
||||
|
||||
41
sdk/lib/misc/rtt/rt_timer.c
Normal file
41
sdk/lib/misc/rtt/rt_timer.c
Normal file
@@ -0,0 +1,41 @@
|
||||
#include "rtthread.h"
|
||||
|
||||
void rt_timer_init(rt_timer_t timer, const char *name, void (*timeout)(void *parameter), void *parameter, rt_tick_t time, rt_uint8_t flag)
|
||||
{
|
||||
uint8 mode = flag & RT_TIMER_FLAG_PERIODIC ? OS_TIMER_MODE_PERIODIC : OS_TIMER_MODE_ONCE;
|
||||
os_timer_init(timer, timeout, mode, parameter);
|
||||
timer->interval = time;
|
||||
}
|
||||
|
||||
rt_err_t rt_timer_detach(rt_timer_t timer)
|
||||
{
|
||||
return os_timer_del(timer);
|
||||
}
|
||||
|
||||
rt_timer_t rt_timer_create(const char *name, void (*timeout)(void *parameter), void *parameter, rt_tick_t time, rt_uint8_t flag)
|
||||
{
|
||||
uint8 mode = flag & RT_TIMER_FLAG_PERIODIC ? OS_TIMER_MODE_PERIODIC : OS_TIMER_MODE_ONCE;
|
||||
struct rt_timer *timer = os_malloc(sizeof(struct rt_timer));
|
||||
if (timer) {
|
||||
os_timer_init(timer, timeout, mode, parameter);
|
||||
timer->interval = time;
|
||||
}
|
||||
return timer;
|
||||
}
|
||||
|
||||
rt_err_t rt_timer_delete(rt_timer_t timer)
|
||||
{
|
||||
return os_timer_del(timer);
|
||||
}
|
||||
|
||||
rt_err_t rt_timer_start(rt_timer_t timer)
|
||||
{
|
||||
return os_timer_start(timer, timer->interval);
|
||||
}
|
||||
|
||||
rt_err_t rt_timer_stop(rt_timer_t timer)
|
||||
{
|
||||
return os_timer_stop(timer);
|
||||
}
|
||||
|
||||
|
||||
349
sdk/lib/misc/rtt/rtservice.h
Normal file
349
sdk/lib/misc/rtt/rtservice.h
Normal file
@@ -0,0 +1,349 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2006-03-16 Bernard the first version
|
||||
* 2006-09-07 Bernard move the kservice APIs to rtthread.h
|
||||
* 2007-06-27 Bernard fix the rt_list_remove bug
|
||||
* 2012-03-22 Bernard rename kservice.h to rtservice.h
|
||||
* 2017-11-15 JasonJia Modify rt_slist_foreach to rt_slist_for_each_entry.
|
||||
* Make code cleanup.
|
||||
*/
|
||||
|
||||
#ifndef __RT_SERVICE_H__
|
||||
#define __RT_SERVICE_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @addtogroup KernelService
|
||||
*/
|
||||
|
||||
/**@{*/
|
||||
|
||||
/**
|
||||
* rt_container_of - return the member address of ptr, if the type of ptr is the
|
||||
* struct type.
|
||||
*/
|
||||
#define rt_container_of(ptr, type, member) \
|
||||
((type *)((char *)(ptr) - (unsigned long)(&((type *)0)->member)))
|
||||
|
||||
|
||||
/**
|
||||
* @brief initialize a list object
|
||||
*/
|
||||
#define RT_LIST_OBJECT_INIT(object) { &(object), &(object) }
|
||||
|
||||
/**
|
||||
* Double List structure
|
||||
*/
|
||||
struct rt_list_node
|
||||
{
|
||||
struct rt_list_node *next; /**< point to next node. */
|
||||
struct rt_list_node *prev; /**< point to prev node. */
|
||||
};
|
||||
typedef struct rt_list_node rt_list_t; /**< Type for lists. */
|
||||
|
||||
/**
|
||||
* Single List structure
|
||||
*/
|
||||
struct rt_slist_node
|
||||
{
|
||||
struct rt_slist_node *next; /**< point to next node. */
|
||||
};
|
||||
typedef struct rt_slist_node rt_slist_t; /**< Type for single list. */
|
||||
|
||||
/**
|
||||
* @brief initialize a list
|
||||
*
|
||||
* @param l list to be initialized
|
||||
*/
|
||||
rt_inline void rt_list_init(rt_list_t *l)
|
||||
{
|
||||
l->next = l->prev = l;
|
||||
}
|
||||
|
||||
rt_inline void __rt_list_del(rt_list_t *prev, rt_list_t *next)
|
||||
{
|
||||
if(prev && next){
|
||||
next->prev = prev;
|
||||
prev->next = next;
|
||||
}
|
||||
}
|
||||
|
||||
rt_inline void rt_list_del(rt_list_t *l)
|
||||
{
|
||||
__rt_list_del(l->prev, l->next);
|
||||
l->next = 0;
|
||||
l->prev = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief insert a node after a list
|
||||
*
|
||||
* @param l list to insert it
|
||||
* @param n new node to be inserted
|
||||
*/
|
||||
rt_inline void rt_list_insert_after(rt_list_t *l, rt_list_t *n)
|
||||
{
|
||||
l->next->prev = n;
|
||||
n->next = l->next;
|
||||
|
||||
l->next = n;
|
||||
n->prev = l;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief insert a node before a list
|
||||
*
|
||||
* @param n new node to be inserted
|
||||
* @param l list to insert it
|
||||
*/
|
||||
rt_inline void rt_list_insert_before(rt_list_t *l, rt_list_t *n)
|
||||
{
|
||||
l->prev->next = n;
|
||||
n->prev = l->prev;
|
||||
|
||||
l->prev = n;
|
||||
n->next = l;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief remove node from list.
|
||||
* @param n the node to remove from the list.
|
||||
*/
|
||||
rt_inline void rt_list_remove(rt_list_t *n)
|
||||
{
|
||||
n->next->prev = n->prev;
|
||||
n->prev->next = n->next;
|
||||
|
||||
n->next = n->prev = n;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief tests whether a list is empty
|
||||
* @param l the list to test.
|
||||
*/
|
||||
rt_inline int rt_list_isempty(const rt_list_t *l)
|
||||
{
|
||||
return l->next == l;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get the list length
|
||||
* @param l the list to get.
|
||||
*/
|
||||
rt_inline unsigned int rt_list_len(const rt_list_t *l)
|
||||
{
|
||||
unsigned int len = 0;
|
||||
const rt_list_t *p = l;
|
||||
while (p->next != l)
|
||||
{
|
||||
p = p->next;
|
||||
len ++;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get the struct for this entry
|
||||
* @param node the entry point
|
||||
* @param type the type of structure
|
||||
* @param member the name of list in structure
|
||||
*/
|
||||
#define rt_list_entry(node, type, member) \
|
||||
rt_container_of(node, type, member)
|
||||
|
||||
/**
|
||||
* rt_list_for_each - iterate over a list
|
||||
* @pos: the rt_list_t * to use as a loop cursor.
|
||||
* @head: the head for your list.
|
||||
*/
|
||||
#define rt_list_for_each(pos, head) \
|
||||
for (pos = (head)->next; pos != (head); pos = pos->next)
|
||||
|
||||
/**
|
||||
* rt_list_for_each_safe - iterate over a list safe against removal of list entry
|
||||
* @pos: the rt_list_t * to use as a loop cursor.
|
||||
* @n: another rt_list_t * to use as temporary storage
|
||||
* @head: the head for your list.
|
||||
*/
|
||||
#define rt_list_for_each_safe(pos, n, head) \
|
||||
for (pos = (head)->next, n = pos->next; pos != (head); \
|
||||
pos = n, n = pos->next)
|
||||
|
||||
/**
|
||||
* rt_list_for_each_entry - iterate over list of given type
|
||||
* @pos: the type * to use as a loop cursor.
|
||||
* @head: the head for your list.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*/
|
||||
#define rt_list_for_each_entry(pos, head, member) \
|
||||
for (pos = rt_list_entry((head)->next, typeof(*pos), member); \
|
||||
&pos->member != (head); \
|
||||
pos = rt_list_entry(pos->member.next, typeof(*pos), member))
|
||||
|
||||
/**
|
||||
* rt_list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
|
||||
* @pos: the type * to use as a loop cursor.
|
||||
* @n: another type * to use as temporary storage
|
||||
* @head: the head for your list.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*/
|
||||
#define rt_list_for_each_entry_safe(pos, n, head, member) \
|
||||
for (pos = rt_list_entry((head)->next, typeof(*pos), member), \
|
||||
n = rt_list_entry(pos->member.next, typeof(*pos), member); \
|
||||
&pos->member != (head); \
|
||||
pos = n, n = rt_list_entry(n->member.next, typeof(*n), member))
|
||||
|
||||
/**
|
||||
* rt_list_first_entry - get the first element from a list
|
||||
* @ptr: the list head to take the element from.
|
||||
* @type: the type of the struct this is embedded in.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*
|
||||
* Note, that list is expected to be not empty.
|
||||
*/
|
||||
#define rt_list_first_entry(ptr, type, member) \
|
||||
rt_list_entry((ptr)->next, type, member)
|
||||
|
||||
#define RT_SLIST_OBJECT_INIT(object) { RT_NULL }
|
||||
|
||||
/**
|
||||
* @brief initialize a single list
|
||||
*
|
||||
* @param l the single list to be initialized
|
||||
*/
|
||||
rt_inline void rt_slist_init(rt_slist_t *l)
|
||||
{
|
||||
l->next = RT_NULL;
|
||||
}
|
||||
|
||||
rt_inline void rt_slist_append(rt_slist_t *l, rt_slist_t *n)
|
||||
{
|
||||
struct rt_slist_node *node;
|
||||
|
||||
node = l;
|
||||
while (node->next) node = node->next;
|
||||
|
||||
/* append the node to the tail */
|
||||
node->next = n;
|
||||
n->next = RT_NULL;
|
||||
}
|
||||
|
||||
rt_inline void rt_slist_insert(rt_slist_t *l, rt_slist_t *n)
|
||||
{
|
||||
n->next = l->next;
|
||||
l->next = n;
|
||||
}
|
||||
|
||||
rt_inline unsigned int rt_slist_len(const rt_slist_t *l)
|
||||
{
|
||||
unsigned int len = 0;
|
||||
const rt_slist_t *list = l->next;
|
||||
while (list != RT_NULL)
|
||||
{
|
||||
list = list->next;
|
||||
len ++;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
rt_inline rt_slist_t *rt_slist_remove(rt_slist_t *l, rt_slist_t *n)
|
||||
{
|
||||
/* remove slist head */
|
||||
struct rt_slist_node *node = l;
|
||||
while (node->next && node->next != n) node = node->next;
|
||||
|
||||
/* remove node */
|
||||
if (node->next != (rt_slist_t *)0) node->next = node->next->next;
|
||||
|
||||
return l;
|
||||
}
|
||||
|
||||
rt_inline rt_slist_t *rt_slist_first(rt_slist_t *l)
|
||||
{
|
||||
return l->next;
|
||||
}
|
||||
|
||||
rt_inline rt_slist_t *rt_slist_tail(rt_slist_t *l)
|
||||
{
|
||||
while (l->next) l = l->next;
|
||||
|
||||
return l;
|
||||
}
|
||||
|
||||
rt_inline rt_slist_t *rt_slist_next(rt_slist_t *n)
|
||||
{
|
||||
return n->next;
|
||||
}
|
||||
|
||||
rt_inline int rt_slist_isempty(rt_slist_t *l)
|
||||
{
|
||||
return l->next == RT_NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get the struct for this single list node
|
||||
* @param node the entry point
|
||||
* @param type the type of structure
|
||||
* @param member the name of list in structure
|
||||
*/
|
||||
#define rt_slist_entry(node, type, member) \
|
||||
rt_container_of(node, type, member)
|
||||
|
||||
/**
|
||||
* rt_slist_for_each - iterate over a single list
|
||||
* @pos: the rt_slist_t * to use as a loop cursor.
|
||||
* @head: the head for your single list.
|
||||
*/
|
||||
#define rt_slist_for_each(pos, head) \
|
||||
for (pos = (head)->next; pos != RT_NULL; pos = pos->next)
|
||||
|
||||
/**
|
||||
* rt_slist_for_each_entry - iterate over single list of given type
|
||||
* @pos: the type * to use as a loop cursor.
|
||||
* @head: the head for your single list.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*/
|
||||
#define rt_slist_for_each_entry(pos, head, member) \
|
||||
for (pos = rt_slist_entry((head)->next, typeof(*pos), member); \
|
||||
&pos->member != (RT_NULL); \
|
||||
pos = rt_slist_entry(pos->member.next, typeof(*pos), member))
|
||||
|
||||
/**
|
||||
* rt_slist_first_entry - get the first element from a slist
|
||||
* @ptr: the slist head to take the element from.
|
||||
* @type: the type of the struct this is embedded in.
|
||||
* @member: the name of the slist_struct within the struct.
|
||||
*
|
||||
* Note, that slist is expected to be not empty.
|
||||
*/
|
||||
#define rt_slist_first_entry(ptr, type, member) \
|
||||
rt_slist_entry((ptr)->next, type, member)
|
||||
|
||||
/**
|
||||
* rt_slist_tail_entry - get the tail element from a slist
|
||||
* @ptr: the slist head to take the element from.
|
||||
* @type: the type of the struct this is embedded in.
|
||||
* @member: the name of the slist_struct within the struct.
|
||||
*
|
||||
* Note, that slist is expected to be not empty.
|
||||
*/
|
||||
#define rt_slist_tail_entry(ptr, type, member) \
|
||||
rt_slist_entry(rt_slist_tail(ptr), type, member)
|
||||
|
||||
/**@}*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
196
sdk/lib/misc/rtt/rtthread.h
Normal file
196
sdk/lib/misc/rtt/rtthread.h
Normal file
@@ -0,0 +1,196 @@
|
||||
#ifndef _TXW_RTT_DEF_H_
|
||||
#define _TXW_RTT_DEF_H_
|
||||
#include "basic_include.h"
|
||||
#include "hal/netdev.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef RTT_OS
|
||||
|
||||
#define rt_device dev_obj
|
||||
|
||||
typedef struct dev_obj *rt_device_t;
|
||||
typedef uint8 rt_uint8_t;
|
||||
typedef int8 rt_int8_t;
|
||||
typedef uint32 rt_uint32_t;
|
||||
typedef int32 rt_int32_t;
|
||||
typedef uint16 rt_uint16_t;
|
||||
typedef int16 rt_int16_t;
|
||||
typedef uint32 thread_t;
|
||||
typedef size_t rt_size_t;
|
||||
typedef ssize_t rt_ssize_t;
|
||||
typedef int32 rt_err_t;
|
||||
typedef ulong rt_off_t;
|
||||
typedef int rt_bool_t;
|
||||
typedef long rt_base_t;
|
||||
typedef ulong rt_ubase_t;
|
||||
typedef ulong rt_tick_t;
|
||||
typedef uint64 rt_uint64_t;
|
||||
|
||||
typedef os_task_t *rt_thread_t;
|
||||
typedef os_msgqueue_t *rt_mq_t;
|
||||
typedef os_event_t *rt_event_t;
|
||||
typedef os_semaphore_t *rt_sem_t;
|
||||
typedef os_timer_t *rt_timer_t;
|
||||
|
||||
#define rt_event os_event
|
||||
#define rt_messagequeue os_msgqueue
|
||||
#define rt_timer os_timer
|
||||
#define rt_semaphore os_semaphore
|
||||
#define rt_thread os_task
|
||||
#define rt_ringbuffer rbuffer
|
||||
|
||||
#define rt_hw_interrupt_disable() disable_irq()
|
||||
#define rt_hw_interrupt_enable(f) enable_irq(f)
|
||||
#define rt_tick_from_millisecond(m) os_msecs_to_jiffies(m)
|
||||
|
||||
#define INIT_PREV_EXPORT(f)
|
||||
#define RT_TICK_PER_SECOND OS_SYSTICK_HZ
|
||||
#define RT_WAITING_FOREVER osWaitForever
|
||||
|
||||
#define rt_inline inline
|
||||
#define rt_align __aligned
|
||||
#define rt_weak __weak
|
||||
#define RT_ASSERT ASSERT
|
||||
#define RT_ERROR RET_ERR
|
||||
#define RT_EOK RET_OK
|
||||
#define RT_TRUE 1
|
||||
#define RT_FALSE 0
|
||||
#define RT_NULL NULL
|
||||
#define RT_ENOMEM ENOMEM
|
||||
#define RT_EIO EIO
|
||||
#define RT_ENOSYS ENOSYS
|
||||
|
||||
#define rt_memset os_memset
|
||||
#define rt_memcpy os_memcpy
|
||||
#define rt_malloc os_malloc
|
||||
#define rt_zalloc os_zalloc
|
||||
#define rt_free os_free
|
||||
#define rt_strlen os_strlen
|
||||
|
||||
#define rt_kprintf(fmt, ...) os_printf(fmt, ##__VA_ARGS__)
|
||||
#define LOG_D(fmt, ...) //os_printf(fmt"\r\n", ##__VA_ARGS__)
|
||||
#define LOG_E(fmt, ...) os_printf(fmt"\r\n", ##__VA_ARGS__)
|
||||
#define LOG_W(fmt, ...) os_printf(fmt"\r\n", ##__VA_ARGS__)
|
||||
#define LOG_I(fmt, ...) os_printf(fmt"\r\n", ##__VA_ARGS__)
|
||||
|
||||
#define rt_device_init(dev)
|
||||
#define rt_device_find()
|
||||
#define rt_device_open()
|
||||
#define rt_device_control()
|
||||
#define rt_device_write()
|
||||
#define rt_device_close()
|
||||
|
||||
#define eth_device netdev
|
||||
|
||||
#define RT_IPC_FLAG_FIFO (0)
|
||||
#define RT_EVENT_FLAG_OR OS_EVENT_WMODE_OR
|
||||
#define RT_EVENT_FLAG_CLEAR OS_EVENT_WMODE_CLEAR
|
||||
|
||||
#include "rtservice.h"
|
||||
|
||||
#define rt_set_errno(err)
|
||||
|
||||
/**
|
||||
* clock & timer macros
|
||||
*/
|
||||
#define RT_TIMER_FLAG_DEACTIVATED 0x0 /**< timer is deactive */
|
||||
#define RT_TIMER_FLAG_ACTIVATED 0x1 /**< timer is active */
|
||||
#define RT_TIMER_FLAG_ONE_SHOT 0x0 /**< one shot timer */
|
||||
#define RT_TIMER_FLAG_PERIODIC 0x2 /**< periodic timer */
|
||||
|
||||
#define RT_TIMER_FLAG_HARD_TIMER 0x0 /**< hard timer,the timer's callback function will be called in tick isr. */
|
||||
#define RT_TIMER_FLAG_SOFT_TIMER 0x4 /**< soft timer,the timer's callback function will be called in timer thread. */
|
||||
|
||||
#define RT_TIMER_CTRL_SET_TIME 0x0 /**< set timer control command */
|
||||
#define RT_TIMER_CTRL_GET_TIME 0x1 /**< get timer control command */
|
||||
#define RT_TIMER_CTRL_SET_ONESHOT 0x2 /**< change timer to one shot */
|
||||
#define RT_TIMER_CTRL_SET_PERIODIC 0x3 /**< change timer to periodic */
|
||||
|
||||
#ifndef RT_TIMER_SKIP_LIST_LEVEL
|
||||
#define RT_TIMER_SKIP_LIST_LEVEL 1
|
||||
#endif
|
||||
|
||||
/* 1 or 3 */
|
||||
#ifndef RT_TIMER_SKIP_LIST_MASK
|
||||
#define RT_TIMER_SKIP_LIST_MASK 0x3
|
||||
#endif
|
||||
|
||||
#ifndef RT_ALIGN_SIZE
|
||||
#define RT_ALIGN_SIZE 4
|
||||
#endif
|
||||
|
||||
#define INIT_BOARD_EXPORT(f)
|
||||
|
||||
#endif
|
||||
|
||||
rt_thread_t rt_thread_create(const char *name, void (*entry)(void *parameter), void *parameter,
|
||||
rt_uint32_t stack_size, rt_uint8_t priority, rt_uint32_t tick);
|
||||
rt_err_t rt_thread_delete(rt_thread_t thread);
|
||||
rt_err_t rt_thread_init(struct rt_thread *thread, const char *name, void (*entry)(void *parameter),
|
||||
void *parameter, void *stack_start, rt_uint32_t stack_size,
|
||||
rt_uint8_t priority, rt_uint32_t tick);
|
||||
rt_err_t rt_thread_detach(rt_thread_t thread);
|
||||
rt_thread_t rt_thread_self(void);
|
||||
rt_thread_t rt_thread_find(char *name);
|
||||
rt_err_t rt_thread_startup(rt_thread_t thread);
|
||||
rt_err_t rt_thread_yield(void);
|
||||
rt_err_t rt_thread_delay(rt_tick_t tick);
|
||||
rt_err_t rt_thread_delay_until(rt_tick_t *tick, rt_tick_t inc_tick);
|
||||
rt_err_t rt_thread_mdelay(rt_int32_t ms);
|
||||
rt_err_t rt_thread_control(rt_thread_t thread, int cmd, void *arg);
|
||||
rt_err_t rt_thread_suspend(rt_thread_t thread);
|
||||
rt_err_t rt_thread_resume(rt_thread_t thread);
|
||||
void rt_thread_timeout(void *parameter);
|
||||
void rt_enter_critical(void);
|
||||
void rt_exit_critical(void);
|
||||
|
||||
rt_err_t rt_event_init(rt_event_t event, const char *name, rt_uint8_t flag);
|
||||
rt_err_t rt_event_detach(rt_event_t event);
|
||||
rt_event_t rt_event_create(const char *name, rt_uint8_t flag);
|
||||
rt_err_t rt_event_delete(rt_event_t event);
|
||||
rt_err_t rt_event_send(rt_event_t event, rt_uint32_t set);
|
||||
rt_err_t rt_event_recv(rt_event_t event, rt_uint32_t set, rt_uint8_t opt, rt_int32_t timeout, rt_uint32_t *recved);
|
||||
|
||||
rt_err_t rt_mq_init(rt_mq_t mq, const char *name, void *msgpool, rt_size_t msg_size, rt_size_t pool_size, rt_uint8_t flag);
|
||||
rt_err_t rt_mq_detach(rt_mq_t mq);
|
||||
rt_mq_t rt_mq_create(const char *name, rt_size_t msg_size, rt_size_t max_msgs, rt_uint8_t flag);
|
||||
rt_err_t rt_mq_delete(rt_mq_t mq);
|
||||
rt_err_t rt_mq_send_wait(rt_mq_t mq, const void *buffer, rt_size_t size, rt_int32_t timeout);
|
||||
rt_err_t rt_mq_send(rt_mq_t mq, const void *buffer, rt_size_t size);
|
||||
rt_err_t rt_mq_urgent(rt_mq_t mq, const void *buffer, rt_size_t size);
|
||||
rt_err_t rt_mq_recv(rt_mq_t mq, void *buffer, rt_size_t size, rt_int32_t timeout);
|
||||
|
||||
rt_err_t rt_sem_init(rt_sem_t sem, const char *name, rt_uint32_t value, rt_uint8_t flag);
|
||||
rt_err_t rt_sem_detach(rt_sem_t sem);
|
||||
rt_sem_t rt_sem_create(const char *name, rt_uint32_t value, rt_uint8_t flag);
|
||||
rt_err_t rt_sem_delete(rt_sem_t sem);
|
||||
rt_err_t rt_sem_take(rt_sem_t sem, rt_int32_t time);
|
||||
rt_err_t rt_sem_trytake(rt_sem_t sem);
|
||||
rt_err_t rt_sem_release(rt_sem_t sem);
|
||||
|
||||
void rt_ringbuffer_init(struct rt_ringbuffer *rb, rt_uint8_t *pool, rt_int16_t size);
|
||||
void rt_ringbuffer_reset(struct rt_ringbuffer *rb);
|
||||
void rt_ringbuffer_destroy(struct rt_ringbuffer *rb);
|
||||
rt_size_t rt_ringbuffer_put(struct rt_ringbuffer *rb, const rt_uint8_t *ptr, rt_uint16_t length);
|
||||
rt_size_t rt_ringbuffer_put_force(struct rt_ringbuffer *rb, const rt_uint8_t *ptr, rt_uint16_t length);
|
||||
rt_size_t rt_ringbuffer_putchar(struct rt_ringbuffer *rb, const rt_uint8_t ch);
|
||||
rt_size_t rt_ringbuffer_putchar_force(struct rt_ringbuffer *rb, const rt_uint8_t ch);
|
||||
rt_size_t rt_ringbuffer_get(struct rt_ringbuffer *rb, rt_uint8_t *ptr, rt_uint16_t length);
|
||||
rt_size_t rt_ringbuffer_getchar(struct rt_ringbuffer *rb, rt_uint8_t *ch);
|
||||
rt_size_t rt_ringbuffer_data_len(struct rt_ringbuffer *rb);
|
||||
|
||||
void rt_timer_init(rt_timer_t timer, const char *name, void (*timeout)(void *parameter), void *parameter, rt_tick_t time, rt_uint8_t flag);
|
||||
rt_err_t rt_timer_detach(rt_timer_t timer);
|
||||
rt_timer_t rt_timer_create(const char *name, void (*timeout)(void *parameter), void *parameter, rt_tick_t time, rt_uint8_t flag);
|
||||
rt_err_t rt_timer_delete(rt_timer_t timer);
|
||||
rt_err_t rt_timer_start(rt_timer_t timer);
|
||||
rt_err_t rt_timer_stop(rt_timer_t timer);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user