mirror of
https://github.com/Ai-Thinker-Open/Ai-Thinker-Open_RTL8710BX_ALIOS_SDK.git
synced 2026-07-11 12:45:39 +00:00
rel_1.6.0 init
This commit is contained in:
commit
27b3e2883d
19359 changed files with 8093121 additions and 0 deletions
26
Living_SDK/kernel/vcall/espos/include/arch/espos_arch.h
Normal file
26
Living_SDK/kernel/vcall/espos/include/arch/espos_arch.h
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed 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.
|
||||
|
||||
#ifndef _ESPOS_ARCH_H_
|
||||
#define _ESPOS_ARCH_H_
|
||||
|
||||
#if defined(ESPOS_FOR_ESP32)
|
||||
#include "espos_esp32.h"
|
||||
#elif defined(ESPOS_FOR_ESP8266)
|
||||
#include "espos_esp8266.h"
|
||||
#else
|
||||
#error "no espressif platform"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
110
Living_SDK/kernel/vcall/espos/include/arch/espos_esp32.h
Normal file
110
Living_SDK/kernel/vcall/espos/include/arch/espos_esp32.h
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed 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.
|
||||
|
||||
#ifndef _ESPOS_ESP32_H_
|
||||
#define _ESPOS_ESP32_H_
|
||||
|
||||
#include "sdkconfig.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_FREERTOS_UNICORE
|
||||
#define ESPOS_PROCESSORS_NUM 2u
|
||||
#define CONFIG_ESPOS_SMP
|
||||
#else
|
||||
#define ESPOS_PROCESSORS_NUM 1u
|
||||
#endif
|
||||
|
||||
typedef struct espos_spinlock_arch {
|
||||
int lock;
|
||||
} espos_spinlock_arch_t;
|
||||
|
||||
#define ESPOS_SPINLOCK_ARCH_UNLOCK_INITIALIZER \
|
||||
{ \
|
||||
0, \
|
||||
}
|
||||
|
||||
static inline int espos_get_core_id(void)
|
||||
{
|
||||
int id;
|
||||
|
||||
__asm__ __volatile__ (
|
||||
" rsr.prid %0\n"
|
||||
" extui %0, %0, 13, 1\n"
|
||||
:"=r"(id));
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
static inline void espos_spinlock_arch_init(espos_spinlock_arch_t *lock)
|
||||
{
|
||||
lock->lock = 0;
|
||||
}
|
||||
|
||||
static inline void espos_spinlock_arch_deinit(espos_spinlock_arch_t *lock)
|
||||
{
|
||||
lock->lock = 0;
|
||||
}
|
||||
|
||||
static inline void espos_spinlock_arch_lock(espos_spinlock_arch_t *lock)
|
||||
{
|
||||
unsigned long tmp;
|
||||
|
||||
__asm__ __volatile__(
|
||||
" movi %0, 0\n"
|
||||
" wsr %0, scompare1\n"
|
||||
"1: movi %0, 1\n"
|
||||
" s32c1i %0, %1, 0\n"
|
||||
" bnez %0, 1b\n"
|
||||
: "=&a" (tmp)
|
||||
: "a" (&lock->lock)
|
||||
: "memory");
|
||||
}
|
||||
|
||||
static inline int espos_spinlock_arch_trylock(espos_spinlock_arch_t *lock)
|
||||
{
|
||||
unsigned long tmp;
|
||||
|
||||
__asm__ __volatile__(
|
||||
" movi %0, 0\n"
|
||||
" wsr %0, scompare1\n"
|
||||
" movi %0, 1\n"
|
||||
" s32c1i %0, %1, 0\n"
|
||||
: "=&a" (tmp)
|
||||
: "a" (&lock->lock)
|
||||
: "memory");
|
||||
|
||||
return tmp == 0 ? 0 : 1;
|
||||
}
|
||||
|
||||
static inline void espos_spinlock_arch_unlock(espos_spinlock_arch_t *lock)
|
||||
{
|
||||
unsigned long tmp;
|
||||
|
||||
__asm__ __volatile__(
|
||||
" movi %0, 0\n"
|
||||
" s32ri %0, %1, 0\n"
|
||||
: "=&a" (tmp)
|
||||
: "a" (&lock->lock)
|
||||
: "memory");
|
||||
}
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _ESPOS_ESP32_H_ */
|
||||
57
Living_SDK/kernel/vcall/espos/include/arch/espos_esp8266.h
Normal file
57
Living_SDK/kernel/vcall/espos/include/arch/espos_esp8266.h
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed 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.
|
||||
|
||||
#ifndef _ESPOS_ESP8266_H_
|
||||
#define _ESPOS_ESP8266_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define ESPOS_PROCESSORS_NUM 1u
|
||||
|
||||
#define ESPOS_SPINLOCK_ARCH_UNLOCK_INITIALIZER \
|
||||
{ \
|
||||
0, \
|
||||
}
|
||||
|
||||
typedef int32_t esp_err_t;
|
||||
|
||||
typedef struct espos_spinlock_arch {
|
||||
int lock;
|
||||
} espos_spinlock_arch_t;
|
||||
|
||||
static inline uintptr_t espos_suspend_interrupt(void)
|
||||
{
|
||||
uintptr_t state;
|
||||
|
||||
__asm__ volatile ("RSIL %0, 5" : "=a" (state) :: "memory");
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
static inline void espos_resume_interrupt(uintptr_t state)
|
||||
{
|
||||
__asm__ volatile ("WSR %0, ps" :: "a" (state) : "memory");
|
||||
}
|
||||
|
||||
#define espos_get_core_id() 0
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _ESPOS_ESP8266_H_ */
|
||||
17
Living_SDK/kernel/vcall/espos/include/espos_errno.h
Normal file
17
Living_SDK/kernel/vcall/espos/include/espos_errno.h
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef _ESPOS_ERRNO_H_
|
||||
#define _ESPOS_ERRNO_H_
|
||||
|
||||
#include <sys/errno.h>
|
||||
#if defined(ESPOS_FOR_ESP32)
|
||||
#include "esp_err.h"
|
||||
#elif defined(ESPOS_FOR_ESP8266)
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
20
Living_SDK/kernel/vcall/espos/include/espos_include.h
Normal file
20
Living_SDK/kernel/vcall/espos/include/espos_include.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef ESPOS_INCLUDE_H
|
||||
#define ESPOS_INCLUDE_H
|
||||
|
||||
#include "espos_errno.h"
|
||||
#include "espos_mutex.h"
|
||||
#include "espos_queue.h"
|
||||
#include "espos_scheduler.h"
|
||||
#include "espos_semaphore.h"
|
||||
#include "espos_spinlock.h"
|
||||
#include "espos_task.h"
|
||||
#include "espos_time.h"
|
||||
#include "espos_timer.h"
|
||||
#include "espos_types.h"
|
||||
|
||||
#endif /* ESPOS_INCLUDE_H */
|
||||
|
||||
142
Living_SDK/kernel/vcall/espos/include/espos_mutex.h
Normal file
142
Living_SDK/kernel/vcall/espos/include/espos_mutex.h
Normal file
|
|
@ -0,0 +1,142 @@
|
|||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed 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.
|
||||
|
||||
#ifndef _ESPOS_MUTEX_H_
|
||||
#define _ESPOS_MUTEX_H_
|
||||
|
||||
#include "espos_types.h"
|
||||
#include "espos_errno.h"
|
||||
#include "espos_time.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* use default option to create mutex */
|
||||
typedef enum espos_mutex_opt {
|
||||
|
||||
/* AT this mode, deadlock detection shall not be provided. Attempting to relock the mutex causes deadlock.
|
||||
*
|
||||
* If a thread attempts to unlock a mutex that it has not locked or a mutex which is unlocked,
|
||||
* undefined behavior results.
|
||||
*/
|
||||
ESPOS_MUTEX_NORMAL = 0,
|
||||
|
||||
ESPOS_MUTEX_RECURSIVE,
|
||||
|
||||
ESPOS_MUTEX_TYPE_MAX
|
||||
} espos_mutex_type_t;
|
||||
|
||||
#define ESPOS_MUTEX_TYPE(type) (type & 0xFF)
|
||||
|
||||
/**
|
||||
* @brief create a mutex
|
||||
*
|
||||
* @param mutex mutex handle point
|
||||
* @param opt mutex option, if you don't know how to do, just use "ESPOS_MUTEX_NORMAL" here
|
||||
*
|
||||
* @return the result
|
||||
* 0 : successful
|
||||
* -ENOMEM : no enough memory
|
||||
* -EINTR : you do this at interrupt state, and it is not supported
|
||||
* -EINVAL : input parameter error
|
||||
*/
|
||||
esp_err_t espos_mutex_create(espos_mutex_t *mutex, espos_opt_t opt);
|
||||
|
||||
/**
|
||||
* @brief set a mutex name
|
||||
*
|
||||
* @param mutex mutex handle
|
||||
* @param name mutex's name
|
||||
*
|
||||
* @return the result
|
||||
* 0 : successful
|
||||
* -EINVAL : input parameter error
|
||||
*/
|
||||
esp_err_t espos_mutex_set_name(espos_mutex_t mutex, const char *name);
|
||||
|
||||
/**
|
||||
* @brief lock a mutex
|
||||
*
|
||||
* @param mutex mutex handle
|
||||
* @param wait_ticks sleep for system ticks if the locked mutex is not unlocked. Otherwise if someone
|
||||
* else unlock the locked mutex, you will wake up.
|
||||
* maximum time is "ESPOS_MAX_DELAY", no time is "ESPOS_NO_DELAY"
|
||||
*
|
||||
* @return the result
|
||||
* 0 : successful
|
||||
* -EINVAL : input parameter error
|
||||
* -EINTR : you do this at interrupt state, and it is not supported
|
||||
* -ETIMEDOUT : timeout and you have not locked it
|
||||
*
|
||||
* @note you can transform the millisecond to ticks by "espos_ms_to_ticks"
|
||||
*/
|
||||
esp_err_t espos_mutex_lock(espos_mutex_t mutex, espos_tick_t wait_ticks);
|
||||
|
||||
/**
|
||||
* @bref try to lock a mutex and it will return immediately without being blocked
|
||||
*
|
||||
* @param m mutex handle
|
||||
*
|
||||
* @return the result
|
||||
* 0 : successful
|
||||
* -EINVAL : input parameter error
|
||||
* -EINTR : you do this at interrupt state, and it is not supported
|
||||
*/
|
||||
#define espos_mutex_trylock(m) espos_mutex_lock(m, ESPOS_NO_DELAY)
|
||||
|
||||
/**
|
||||
* @brief unlock a mutex
|
||||
*
|
||||
* @param mutex mutex handle
|
||||
*
|
||||
* @return the result
|
||||
* 0 : successful
|
||||
* -EINVAL : input parameter error
|
||||
* -EINTR : you do this at interrupt state, and it is not supported
|
||||
* -EPERM : current task don't lock the mutex
|
||||
*/
|
||||
esp_err_t espos_mutex_unlock(espos_mutex_t mutex);
|
||||
|
||||
/**
|
||||
* @brief get task handle which lock the mutex
|
||||
*
|
||||
* @param mutex mutex handle
|
||||
*
|
||||
* @return the result
|
||||
* 0 : successful
|
||||
* -EINVAL : input parameter error
|
||||
*/
|
||||
espos_task_t espos_mutex_get_holder(espos_mutex_t mutex);
|
||||
|
||||
/**
|
||||
* @brief delete the mutex
|
||||
*
|
||||
* @param mutex mutex handle
|
||||
*
|
||||
* @return the result
|
||||
* 0 : successful
|
||||
* -EINTR : you do this at interrupt state, and it is not supported
|
||||
* -EINVAL : input parameter error
|
||||
*
|
||||
* @note if low-level module is YunOS, this function will awake all task blocked at the mutex
|
||||
*/
|
||||
esp_err_t espos_mutex_del(espos_mutex_t mutex);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
212
Living_SDK/kernel/vcall/espos/include/espos_queue.h
Normal file
212
Living_SDK/kernel/vcall/espos/include/espos_queue.h
Normal file
|
|
@ -0,0 +1,212 @@
|
|||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed 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.
|
||||
|
||||
#ifndef _ESPOS_QUEUE_H_
|
||||
#define _ESPOS_QUEUE_H_
|
||||
|
||||
#include "espos_types.h"
|
||||
#include "espos_errno.h"
|
||||
#include "espos_time.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum espos_queue_pos {
|
||||
/* send message to the front of the queue */
|
||||
ESPOS_QUEUE_SEND_FRONT = 0,
|
||||
|
||||
/* send message to the back of the queue */
|
||||
ESPOS_QUEUE_SEND_BACK,
|
||||
|
||||
ESPOS_QUEUE_POS_MAX
|
||||
} espos_queue_pos_t;
|
||||
|
||||
typedef enum espos_queue_send_opt {
|
||||
/* send message with normal option */
|
||||
ESPOS_QUEUE_SEND_OPT_NORMAL = 0,
|
||||
|
||||
ESPOS_QUEUE_SEND_OPT_MAX
|
||||
} espos_queue_send_opt_t;
|
||||
|
||||
typedef enum espos_queue_recv_opt {
|
||||
/* receive message with normal option */
|
||||
ESPOS_QUEUE_RECV_OPT_NORMAL = 0,
|
||||
|
||||
ESPOS_QUEUE_RECV_OPT_MAX
|
||||
} espos_queue_recv_opt_t;
|
||||
|
||||
/**
|
||||
* @brief create a queue
|
||||
*
|
||||
* @param queue queue handle point
|
||||
* @param msg_len queue internal message length (bytes)
|
||||
* @param queue_len queue internal message maximum number
|
||||
*
|
||||
* @return the result
|
||||
* 0 : successful
|
||||
* -ENOMEM : no enough memory
|
||||
* -EINTR : you do this at interrupt state, and it is not supported
|
||||
* -EINVAL : input parameter error
|
||||
*
|
||||
* @note all input and out message length is fixedly "msg_len"
|
||||
*/
|
||||
esp_err_t espos_queue_create(espos_queue_t *queue, espos_size_t msg_len, espos_size_t queue_len);
|
||||
|
||||
/**
|
||||
* @brief set a queue name
|
||||
*
|
||||
* @param queue queue handle
|
||||
* @param name queue's name
|
||||
*
|
||||
* @return the result
|
||||
* 0 : successful
|
||||
* -EINVAL : input parameter error
|
||||
*/
|
||||
esp_err_t espos_queue_set_name(espos_queue_t queue, const char *name);
|
||||
|
||||
/**
|
||||
* @brief send a message to the queue, it is suggested that you had better not use "espos_queue_send" directly,
|
||||
* please use "espos_queue_send_front" or "espos_queue_send_back"
|
||||
*
|
||||
* @param queue queue handle
|
||||
* @param msg message point
|
||||
* @param wait_ticks sleep for system ticks if the queue is full. Otherwise if queue is not full, you will wake up.
|
||||
* maximum time is "ESPOS_MAX_DELAY", no time is "ESPOS_NO_DELAY"
|
||||
* @param pos position where sending the message
|
||||
* ESPOS_QUEUE_SEND_FRONT : send message to the front of the queue
|
||||
* ESPOS_QUEUE_SEND_BACK : send message to the back of the queue
|
||||
* @param opt sending option
|
||||
* ESPOS_QUEUE_SEND_OPT_NORMAL : wake up blocked task
|
||||
*
|
||||
* @return the result
|
||||
* 0 : successful
|
||||
* -EINVAL : input parameter error
|
||||
* -ETIMEDOUT : timeout and the queue is full
|
||||
*
|
||||
* @note you can transform the millisecond to ticks by "espos_ms_to_ticks"
|
||||
*/
|
||||
esp_err_t espos_queue_send_generic(espos_queue_t queue, void *msg, espos_tick_t wait_ticks, espos_pos_t pos, espos_opt_t opt);
|
||||
|
||||
/**
|
||||
* @brief send a message to the front of the queue
|
||||
*
|
||||
* @param q queue handle
|
||||
* @param m message point
|
||||
* @param t sleep for system ticks if the queue is full. Otherwise if queue is not full, you will wake up.
|
||||
* maximum time is "ESPOS_MAX_DELAY", no time is "ESPOS_NO_DELAY"
|
||||
*
|
||||
* @return the result
|
||||
* 0 : successful
|
||||
* -EINVAL : input parameter error
|
||||
* -ETIMEDOUT : timeout and the queue is full
|
||||
*
|
||||
* @note you can transform the millisecond to ticks by "espos_ms_to_ticks"
|
||||
*/
|
||||
#define espos_queue_send_front(q, m, t) espos_queue_send_generic(q, m, t, ESPOS_QUEUE_SEND_FRONT, ESPOS_QUEUE_SEND_OPT_NORMAL)
|
||||
|
||||
/**
|
||||
* @brief send a message to the back of the queue
|
||||
*
|
||||
* @param q queue handle
|
||||
* @param m message point
|
||||
* @param t sleep for system ticks if the queue is full. Otherwise if queue is not full, you will wake up.
|
||||
* maximum time is "ESPOS_MAX_DELAY", no time is "ESPOS_NO_DELAY"
|
||||
*
|
||||
* @return the result
|
||||
* 0 : successful
|
||||
* -EINVAL : input parameter error
|
||||
* -ETIMEDOUT : timeout and the queue is full
|
||||
*
|
||||
* @note you can transform the millisecond to ticks by "espos_ms_to_ticks"
|
||||
*/
|
||||
#define espos_queue_send(q, m, t) espos_queue_send_generic(q, m, t, ESPOS_QUEUE_SEND_BACK, ESPOS_QUEUE_SEND_OPT_NORMAL)
|
||||
|
||||
/**
|
||||
* @brief receive a message of the queue
|
||||
*
|
||||
* @param queue queue handle
|
||||
* @param msg message point
|
||||
* @param wait_ticks sleep for system ticks if the queue is empty. Otherwise if queue is not empty, you will wake up.
|
||||
* maximum time is "ESPOS_MAX_DELAY", no time is "ESPOS_NO_DELAY", at CPU ISR mode, it is forced to be 0
|
||||
* @param opt queue sending option
|
||||
* ESPOS_QUEUE_RECV_OPT_NORMAL : use wait_ticks to check if it is need be blocked
|
||||
*
|
||||
* @return the result
|
||||
* 0 : successful
|
||||
* -EINVAL : input parameter error
|
||||
* -ETIMEDOUT : timeout and the queue is empty
|
||||
*
|
||||
* @note you can transform the millisecond to ticks by "espos_ms_to_ticks"
|
||||
*/
|
||||
esp_err_t espos_queue_recv_generic(espos_queue_t queue, void *msg, espos_tick_t wait_ticks, espos_opt_t opt);
|
||||
|
||||
/**
|
||||
* @brief receive a message of the queue with normal option
|
||||
*
|
||||
* @param queue queue handle
|
||||
* @param msg message point
|
||||
* @param wait_ticks sleep for system ticks if the queue is empty. Otherwise if queue is not empty, you will wake up.
|
||||
* maximum time is "ESPOS_MAX_DELAY", no time is "ESPOS_NO_DELAY", at CPU ISR mode, it is forced to be 0
|
||||
*
|
||||
* @return the result
|
||||
* 0 : successful
|
||||
* -EINVAL : input parameter error
|
||||
* -ETIMEDOUT : timeout and the queue is empty
|
||||
*
|
||||
* @note you can transform the millisecond to ticks by "espos_ms_to_ticks"
|
||||
*/
|
||||
#define espos_queue_recv(q, m, t) espos_queue_recv_generic(q, m, t, ESPOS_QUEUE_RECV_OPT_NORMAL)
|
||||
|
||||
/**
|
||||
* @brief get current message number of the queue
|
||||
*
|
||||
* @param queue queue handle
|
||||
*
|
||||
* @return current message number of the queue
|
||||
*/
|
||||
espos_size_t espos_queue_msg_waiting(espos_queue_t queue);
|
||||
|
||||
/**
|
||||
* @brief reset the queue
|
||||
*
|
||||
* @param queue queue handle
|
||||
*
|
||||
* @return the result
|
||||
* 0 : successful
|
||||
* -EINVAL : input parameter error
|
||||
*
|
||||
* @note if low-level module is YunOS, the function will not awake the tasks which is blocked at the queue
|
||||
*/
|
||||
esp_err_t espos_queue_flush(espos_queue_t queue);
|
||||
|
||||
/**
|
||||
* @brief delete the queue
|
||||
*
|
||||
* @param queue queue handle
|
||||
*
|
||||
* @return the result
|
||||
* 0 : successful
|
||||
* -EINTR : you do this at interrupt state, and it is not supported
|
||||
* -EINVAL : input parameter error
|
||||
*
|
||||
* @note if low-level module is YunOS, this function will awake all task blocked at the mutex
|
||||
*/
|
||||
esp_err_t espos_queue_del(espos_queue_t queue);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
245
Living_SDK/kernel/vcall/espos/include/espos_scheduler.h
Normal file
245
Living_SDK/kernel/vcall/espos/include/espos_scheduler.h
Normal file
|
|
@ -0,0 +1,245 @@
|
|||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed 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.
|
||||
|
||||
#ifndef _ESPOS_SCHEDULER_H_
|
||||
#define _ESPOS_SCHEDULER_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "espos_types.h"
|
||||
#include "espos_errno.h"
|
||||
#include "espos_spinlock.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* ESPOS state
|
||||
*/
|
||||
typedef enum espos_stat {
|
||||
ESPOS_IS_NOT_STARTED = 0,
|
||||
ESPOS_IS_RUNNING,
|
||||
ESPOS_IS_SUSPENDED
|
||||
} espos_stat_t;
|
||||
|
||||
/************************************ internal function ************************************/
|
||||
/**
|
||||
* @brief enter ESPOS system critical state
|
||||
*
|
||||
* @param spinlock spinlock handle point
|
||||
*
|
||||
* @return critical state temple variable(used by "espos_exit_critical")
|
||||
*/
|
||||
espos_critical_t _espos_enter_critical(espos_spinlock_t *spinlock);
|
||||
|
||||
/**
|
||||
* @brief exit ESPOS system critical state
|
||||
*
|
||||
* @param spinlock spinlock handle point
|
||||
* @param tmp critical state temple variable(created by "espos_enter_critical")
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void _espos_exit_critical(espos_spinlock_t *spinlock, espos_critical_t tmp);
|
||||
|
||||
/*******************************************************************************************/
|
||||
|
||||
/**
|
||||
* @brief initialize ESPOS system
|
||||
*
|
||||
* @return the result
|
||||
* 0 : successful
|
||||
* -ENOMEM : no enough memory
|
||||
*/
|
||||
esp_err_t espos_init(void);
|
||||
|
||||
/**
|
||||
* @brief start ESPOS system
|
||||
*
|
||||
* @return the result
|
||||
* 0 : successful
|
||||
* -EPERM : failed (it will never happen in a general way)
|
||||
*/
|
||||
esp_err_t espos_start(void);
|
||||
|
||||
/**
|
||||
* @brief start ESPOS system CPU port
|
||||
*
|
||||
* @param port CPU port ID
|
||||
*
|
||||
* @return the result
|
||||
* 0 : successful
|
||||
* -EPERM : failed (it will never happen in a general way)
|
||||
*/
|
||||
esp_err_t espos_start_port(int port);
|
||||
|
||||
/**
|
||||
* @brief get espos system state
|
||||
*
|
||||
* @return the state
|
||||
* ESPOS_IS_NOT_STARTED : ESPOS is not started
|
||||
* ESPOS_IS_RUNNING : ESPOS is running
|
||||
* ESPOS_IS_SUSPENDED : ESPOS is suspended
|
||||
*/
|
||||
espos_stat_t espos_sched_state_get(void);
|
||||
|
||||
/**
|
||||
* @brief declare espos critical temp data
|
||||
*/
|
||||
#define espos_declare_critical(t) espos_critical_t t
|
||||
|
||||
/**
|
||||
* @brief enter ESPOS system critical state
|
||||
*
|
||||
* @param sl spinlock handle
|
||||
* @param t critical state
|
||||
*
|
||||
* @return critical state temple variable(used by "espos_exit_critical")
|
||||
*/
|
||||
#define espos_enter_critical(t, sl) (t) = _espos_enter_critical(&(sl))
|
||||
|
||||
/**
|
||||
* @brief exit ESPOS system critical state
|
||||
*
|
||||
* @param t critical state temple variable(created by "espos_enter_critical")
|
||||
* @param sl spinlock handle point
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
#define espos_exit_critical(t, sl) _espos_exit_critical(&(sl), t)
|
||||
|
||||
/**
|
||||
* @brief OS internal function enter ESPOS system critical state
|
||||
*
|
||||
* @param sl spinlock handle
|
||||
* @param t critical state
|
||||
*
|
||||
* @return critical state temple variable(used by "espos_exit_critical")
|
||||
*
|
||||
* @note: ESPOS is application level OS API, so it means all APIs call internal
|
||||
* real OS's function, so if OS's or its core hardware's functions want
|
||||
* to call ESPOS, loop nesting will occur, so we should tell ESPOS it's
|
||||
* at OS internal state now.
|
||||
*/
|
||||
#define espos_os_enter_critical(t, sl) \
|
||||
espos_os_enter(); \
|
||||
(t) = _espos_enter_critical(&(sl))
|
||||
|
||||
/**
|
||||
* @brief OS internal function exit ESPOS system critical state
|
||||
*
|
||||
* @param t critical state temple variable(created by "espos_enter_critical")
|
||||
* @param sl spinlock handle point
|
||||
*
|
||||
* @return none
|
||||
*
|
||||
* @note: ESPOS is application level OS API, so it means all APIs call internal
|
||||
* real OS's function, so if OS's or its core hardware's functions want
|
||||
* to call ESPOS, loop nesting will occur, so we should tell ESPOS it's
|
||||
* at OS internal state now.
|
||||
*/
|
||||
#define espos_os_exit_critical(t, sl) \
|
||||
_espos_exit_critical(&(sl), t); \
|
||||
espos_os_exit()
|
||||
|
||||
/**
|
||||
* @brief suspend the local CPU core preempt and the current task
|
||||
* owned by local CPU core will not be preempted
|
||||
*
|
||||
* @return the result
|
||||
* 0 : successful
|
||||
* -EAGAIN : preempt suspending maximum number is reached, and fail to do it
|
||||
* -EINTR : you do this at interrupt state, and it is not supported
|
||||
*
|
||||
* @note the function can be used nested
|
||||
*/
|
||||
esp_err_t espos_preempt_suspend_local(void);
|
||||
|
||||
/**
|
||||
* @brief resume the local CPU core preempt
|
||||
*
|
||||
* @return the result
|
||||
* 0 : successful
|
||||
* -EAGAIN : preempt resuming maximum number is reached, and fail to do it
|
||||
* -EINTR : you do this at interrupt state, and it is not supported
|
||||
*
|
||||
* @note the function can be used nested
|
||||
*/
|
||||
esp_err_t espos_preempt_resume_local(void);
|
||||
|
||||
/**
|
||||
* @brief enter system interrupt server, the function must be used after entering hardware interrupt
|
||||
*
|
||||
* @return the result
|
||||
* 0 : successful
|
||||
* -EAGAIN : nested count is reached
|
||||
*
|
||||
* @note the function can be used nested
|
||||
*/
|
||||
esp_err_t espos_isr_enter (void);
|
||||
|
||||
/**
|
||||
* @brief exit system interrupt server, the function must be used before exiting hardware interrupt
|
||||
*
|
||||
* @return none
|
||||
*
|
||||
* @note the function can be used nested
|
||||
*/
|
||||
void espos_isr_exit(void);
|
||||
|
||||
/**
|
||||
* @brief check if the CPU is at ISR state
|
||||
*
|
||||
* @param none
|
||||
*
|
||||
* @return true if the CPU is at ISR state or false
|
||||
*/
|
||||
bool espos_in_isr(void);
|
||||
|
||||
/**
|
||||
* @brief mark it enters real OS interal function
|
||||
*
|
||||
* @return the result
|
||||
* 0 : successful
|
||||
* -EAGAIN : nested count is reached
|
||||
*
|
||||
* @note the function can be used nested
|
||||
*/
|
||||
esp_err_t espos_os_enter(void);
|
||||
|
||||
/**
|
||||
* @brief remove mark it enters real OS interal function
|
||||
*
|
||||
* @param none
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void espos_os_exit(void);
|
||||
|
||||
/**
|
||||
* @brief check if the function is at real OS internal fucntion
|
||||
*
|
||||
* @param none
|
||||
*
|
||||
* @return true if the CPU is at real OS internal fucntion or false
|
||||
*/
|
||||
bool espos_os_isr(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
119
Living_SDK/kernel/vcall/espos/include/espos_semaphore.h
Normal file
119
Living_SDK/kernel/vcall/espos/include/espos_semaphore.h
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed 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.
|
||||
|
||||
#ifndef _ESPOS_SEMAPHORE_H_
|
||||
#define _ESPOS_SEMAPHORE_H_
|
||||
|
||||
#include "espos_types.h"
|
||||
#include "espos_errno.h"
|
||||
#include "espos_time.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief create a semaphore
|
||||
*
|
||||
* @param sem semaphore handle point
|
||||
* @param max_count semaphore maximum count
|
||||
* @param init_count semaphore initialized count
|
||||
*
|
||||
* @return the result
|
||||
* 0 : successful
|
||||
* ENOMEM : no enough memory
|
||||
* EINVAL : input parameter error
|
||||
*
|
||||
* @note if low-level module is YunOS, "max_count" does not work, and the reachable count is "0xFFFFFFFF"
|
||||
*/
|
||||
esp_err_t espos_sem_create(espos_sem_t *sem, espos_sem_count_t max_count, espos_sem_count_t init_count);
|
||||
|
||||
/**
|
||||
* @brief set a semaphore name
|
||||
*
|
||||
* @param semaphore semaphore handle
|
||||
* @param name semaphore's name
|
||||
*
|
||||
* @return the result
|
||||
* 0 : successful
|
||||
* -EINVAL : input parameter error
|
||||
*/
|
||||
esp_err_t espos_sem_set_name(espos_sem_t sem, const char *name);
|
||||
|
||||
/**
|
||||
* @brief take semaphore
|
||||
*
|
||||
* @param sem semaphore handle
|
||||
* @param wait_ticks sleep for system ticks if the semaphore is empty. Otherwise if semaphore is given,
|
||||
* oldest blocked task will wake up.
|
||||
* maximum time is "ESPOS_MAX_DELAY", no time is "ESPOS_NO_DELAY"
|
||||
*
|
||||
* @return the result
|
||||
* 0 : successful
|
||||
* -EINVAL : input parameter error
|
||||
* -ETIMEDOUT : timeout and not take semaphore
|
||||
*
|
||||
* @note you can transform the millisecond to ticks by "espos_ms_to_ticks"
|
||||
*/
|
||||
esp_err_t espos_sem_take(espos_sem_t sem, espos_tick_t wait_ticks);
|
||||
|
||||
/**
|
||||
* @brief try to take semaphore
|
||||
*
|
||||
* @param s semaphore handle
|
||||
*
|
||||
* @return the result
|
||||
* 0 : successful
|
||||
* -EINVAL : input parameter error
|
||||
* -ETIMEDOUT : not take semaphore
|
||||
*
|
||||
* @note you can transform the millisecond to ticks by "espos_ms_to_ticks"
|
||||
*/
|
||||
#define espos_sem_trytake(s) espos_sem_take(s, ESPOS_NO_DELAY)
|
||||
|
||||
/**
|
||||
* @brief give up semaphore
|
||||
*
|
||||
* @param sem semaphore handle
|
||||
* @param wait_ticks no meaning
|
||||
*
|
||||
* @return the result
|
||||
* 0 : successful
|
||||
* -EINVAL : input parameter error
|
||||
* -EAGAIN : the maximum count is reached
|
||||
*
|
||||
* @note you can transform the millisecond to ticks by "espos_ms_to_ticks"
|
||||
*/
|
||||
esp_err_t espos_sem_give(espos_sem_t sem);
|
||||
|
||||
/**
|
||||
* @brief delete the semaphore
|
||||
*
|
||||
* @param sem semaphore handle
|
||||
*
|
||||
* @return the result
|
||||
* 0 : successful
|
||||
* -EINTR : you do this at interrupt state, and it is not supported
|
||||
* -EINVAL : input parameter error
|
||||
*
|
||||
* @note if low-level module is YunOS, this function will awake all task blocked here
|
||||
*/
|
||||
esp_err_t espos_sem_del(espos_sem_t sem);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
128
Living_SDK/kernel/vcall/espos/include/espos_spinlock.h
Normal file
128
Living_SDK/kernel/vcall/espos/include/espos_spinlock.h
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed 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.
|
||||
|
||||
#ifndef _ESPOS_SPINLOCK_H_
|
||||
#define _ESPOS_SPINLOCK_H_
|
||||
|
||||
#include "espos_types.h"
|
||||
#include "espos_errno.h"
|
||||
#include "espos_task.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct espos_spinlock {
|
||||
espos_spinlock_arch_t lock;
|
||||
espos_task_t holder;
|
||||
} espos_spinlock_t;
|
||||
|
||||
#define ESPOS_SPINLOCK_UNLOCK_INITIALIZER \
|
||||
{ \
|
||||
ESPOS_SPINLOCK_ARCH_UNLOCK_INITIALIZER, \
|
||||
ESPOS_OBJ_NONE, \
|
||||
}
|
||||
|
||||
#define ESPOS_DEFINE_SPINLOCK(l) \
|
||||
espos_spinlock_t l = ESPOS_SPINLOCK_UNLOCK_INITIALIZER
|
||||
|
||||
#define ESPOS_DEFINE_STATIC_SPINLOCK(l) \
|
||||
static espos_spinlock_t l = ESPOS_SPINLOCK_UNLOCK_INITIALIZER
|
||||
|
||||
/**
|
||||
* @brief create a spinlock
|
||||
*
|
||||
* @param spinlock spinlock handle point
|
||||
*
|
||||
* @return the result
|
||||
* 0 : successful
|
||||
* -ENOMEM : no enough memory
|
||||
* -EINVAL : input parameter error
|
||||
*/
|
||||
esp_err_t espos_spinlock_create (espos_spinlock_t *spinlock);
|
||||
|
||||
/**
|
||||
* @brief set a spinlock name
|
||||
*
|
||||
* @param spinlock spinlock handle
|
||||
* @param name spinlock's name
|
||||
*
|
||||
* @return the result
|
||||
* 0 : successful
|
||||
* -EINVAL : input parameter error
|
||||
*/
|
||||
esp_err_t espos_spinlock_set_name(espos_spinlock_t *spinlock, const char *name);
|
||||
|
||||
/**
|
||||
* @brief spin to lock a spinlock until successfully
|
||||
*
|
||||
* @param spinlock spinlock handle
|
||||
*
|
||||
* @return the result
|
||||
* 0 : successful
|
||||
* -EINVAL : input parameter error
|
||||
*/
|
||||
esp_err_t espos_spinlock_lock(espos_spinlock_t *spinlock);
|
||||
|
||||
/**
|
||||
* @brief try to lock a spinlock
|
||||
*
|
||||
* @param spinlock spinlock handle
|
||||
*
|
||||
* @return the result
|
||||
* 0 : successful
|
||||
* -EAGAIN : no spinlock is valid
|
||||
* -EINVAL : input parameter error
|
||||
*/
|
||||
esp_err_t espos_spinlock_trylock(espos_spinlock_t *spinlock);
|
||||
|
||||
/**
|
||||
* @brief get spinlock holder task handle
|
||||
*
|
||||
* @param spinlock spinlock handle
|
||||
*
|
||||
* @return holder task handle
|
||||
*/
|
||||
espos_task_t espos_spinlock_get_holder(espos_spinlock_t *spinlock);
|
||||
|
||||
/**
|
||||
* @brief unlock a spinlock
|
||||
*
|
||||
* @param spinlock spinlock handle
|
||||
*
|
||||
* @return the result
|
||||
* 0 : successful
|
||||
* -EAGAIN : no spinlock is locked
|
||||
* -EINVAL : input parameter error
|
||||
*/
|
||||
esp_err_t espos_spinlock_unlock(espos_spinlock_t *spinlock);
|
||||
|
||||
/**
|
||||
* @brief delete a spinlock
|
||||
*
|
||||
* @param spinlock spinlock handle
|
||||
*
|
||||
* @return the result
|
||||
* 0 : successful
|
||||
* -EACCES : failed to do it with some special reason
|
||||
* -EINVAL : input parameter error
|
||||
*/
|
||||
esp_err_t espos_spinlock_del(espos_spinlock_t *spinlock);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
209
Living_SDK/kernel/vcall/espos/include/espos_task.h
Normal file
209
Living_SDK/kernel/vcall/espos/include/espos_task.h
Normal file
|
|
@ -0,0 +1,209 @@
|
|||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed 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.
|
||||
|
||||
#ifndef _ESPOS_TASK_H_
|
||||
#define _ESPOS_TASK_H_
|
||||
|
||||
#include "espos_types.h"
|
||||
#include "espos_errno.h"
|
||||
#include "espos_time.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* task will run at any CPU */
|
||||
#define ESPOS_TASK_NO_AFFINITY -1
|
||||
|
||||
/* create task and start it automatically */
|
||||
#define ESPOS_TASK_CREATE_NORMAL 0
|
||||
/* just create task and don't start it */
|
||||
#define ESPOS_TASK_CREATE_SILENCE 1
|
||||
|
||||
/* task delete itself */
|
||||
#define ESPOS_TASK_DELETE_SELF 0
|
||||
|
||||
/*
|
||||
* task priority numbers, we use 26 here because FreeRTOS uses 26 but YunOS uses 62,
|
||||
* we should use minimum one of them to be compatible with the current application
|
||||
*/
|
||||
#ifndef ESPOS_TASK_PRIO_NUM
|
||||
#define ESPOS_TASK_PRIO_NUM espos_task_prio_num()
|
||||
#endif
|
||||
|
||||
/* task maximum priority number */
|
||||
#define ESPOS_TASK_PRIO_MAX (ESPOS_TASK_PRIO_NUM - 1)
|
||||
|
||||
/**
|
||||
* @brief create a task
|
||||
*
|
||||
* @param task task handle point
|
||||
* @param name task name, if name is NULL, we will use "default_task" default
|
||||
* @param arg task entry function inputting parameter
|
||||
* @param prio task priority
|
||||
* @param ticks task time slice
|
||||
* @param stack_size task stack size, its unit is "byte"
|
||||
* @param entry task entry function
|
||||
* @param opt task option
|
||||
* ESPOS_TASK_CREATE_NORMAL : the created task will be started automatically
|
||||
* ESPOS_TASK_CREATE_SILENCE : the created task will not be started automatically
|
||||
* @param cpu_id task CPU id
|
||||
* natural number : the task only runs at the CPU of the number
|
||||
* ESPOS_TASK_NO_AFFINITY : the task runs at any CPU
|
||||
*
|
||||
* @return the result
|
||||
* 0 : successful
|
||||
* -ENOMEM : no enough memory
|
||||
* -EINVAL : input parameter error
|
||||
* -EINTR : you do this at interrupt state, and it is not supported
|
||||
*/
|
||||
esp_err_t espos_task_create_on_cpu(espos_task_t *task, const char *name, void *arg, espos_prio_t prio,
|
||||
espos_tick_t ticks, espos_size_t stack_size, espos_task_entry_t entry, espos_opt_t opt, espos_cpu_t cpu_id);
|
||||
|
||||
|
||||
/**
|
||||
* @brief create a task and set its CPU id to be "ESPOS_TASK_NO_AFFINITY"
|
||||
*
|
||||
* @param task task handle point
|
||||
* @param name task name, if name is NULL, we will use "default_task" default
|
||||
* @param arg task entry function inputting parameter
|
||||
* @param prio task priority
|
||||
* @param ticks task time slice
|
||||
* @param stack_size task stack size, its unit is "byte"
|
||||
* @param entry task entry function
|
||||
* @param opt task option
|
||||
* ESPOS_TASK_CREATE_NORMAL : the created task will be started automatically
|
||||
* ESPOS_TASK_CREATE_SILENCE : the created task will not be started automatically
|
||||
*
|
||||
* @return the result
|
||||
* 0 : successful
|
||||
* -ENOMEM : no enough memory
|
||||
* -EINVAL : input parameter error
|
||||
* -EINTR : you do this at interrupt state, and it is not supported
|
||||
*/
|
||||
#define espos_task_create(task, name, arg, prio, ticks, stack_size, entry, opt) \
|
||||
espos_task_create_on_cpu(task, name, arg, prio, ticks, stack_size, entry, opt, ESPOS_TASK_NO_AFFINITY)
|
||||
|
||||
/**
|
||||
* @brief delete a task
|
||||
*
|
||||
* @param task task handle
|
||||
* ESPOS_TASK_DELETE_SELF : task will delete itself
|
||||
*
|
||||
* @return the result
|
||||
* 0 : successful
|
||||
* EACCES : failed to do it with some special reason
|
||||
*/
|
||||
esp_err_t espos_task_del(espos_task_t task);
|
||||
|
||||
/**
|
||||
* @brief let current task sleep for some ticks
|
||||
*
|
||||
* @param delay_ticks system ticks
|
||||
*
|
||||
* @return the result
|
||||
* 0 : successful
|
||||
* EINVAL : input parameter error
|
||||
*/
|
||||
esp_err_t espos_task_delay(const espos_tick_t delay_ticks);
|
||||
|
||||
/**
|
||||
* @brief suspend target task
|
||||
*
|
||||
* @param task task handle
|
||||
*
|
||||
* @return the result
|
||||
* 0 : successful
|
||||
* EINVAL : input parameter error
|
||||
*/
|
||||
esp_err_t espos_task_suspend(espos_task_t task);
|
||||
|
||||
/**
|
||||
* @brief resume target task
|
||||
*
|
||||
* @param task task handle
|
||||
*
|
||||
* @return the result
|
||||
* 0 : successful
|
||||
* EINVAL : input parameter error
|
||||
*/
|
||||
esp_err_t espos_task_resume(espos_task_t task);
|
||||
|
||||
/**
|
||||
* @brief yield the cpu once
|
||||
*
|
||||
* @return the result
|
||||
* 0 : successful
|
||||
* EACCES : failed to do it with some special reason
|
||||
*/
|
||||
esp_err_t espos_task_yield(void);
|
||||
|
||||
/**
|
||||
* @brief get current task handle
|
||||
*
|
||||
* @return current task handle
|
||||
*/
|
||||
espos_task_t espos_task_get_current(void);
|
||||
|
||||
/**
|
||||
* @brief get current task name point
|
||||
*
|
||||
* @param task task handle
|
||||
* @param pname pointing at name's point
|
||||
*
|
||||
* @return current task handle
|
||||
*/
|
||||
esp_err_t espos_task_get_name (espos_task_t task, char **pname);
|
||||
|
||||
/**
|
||||
* @brief set task private data
|
||||
*
|
||||
* @param task task handle
|
||||
* @param idx task data index
|
||||
* @param info task private data
|
||||
*
|
||||
* @return the result
|
||||
* 0 : successful
|
||||
* EINVAL : input parameter error
|
||||
*/
|
||||
esp_err_t espos_task_set_private_data(espos_task_t task, int idx, void *info);
|
||||
|
||||
/**
|
||||
* @brief get task private data
|
||||
*
|
||||
* @param task task handle
|
||||
* @param idx task data index
|
||||
* @param info task private data point
|
||||
*
|
||||
* @return the result
|
||||
* 0 : successful
|
||||
* EINVAL : input parameter error
|
||||
*/
|
||||
esp_err_t espos_task_get_private_data(espos_task_t task, int idx, void **info);
|
||||
|
||||
/**
|
||||
* @brief get CPU affinity of task
|
||||
*
|
||||
* @return CPU affinity of task
|
||||
*/
|
||||
espos_cpu_t espos_task_get_affinity(espos_task_t task);
|
||||
|
||||
size_t espos_task_prio_num(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
69
Living_SDK/kernel/vcall/espos/include/espos_time.h
Normal file
69
Living_SDK/kernel/vcall/espos/include/espos_time.h
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed 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.
|
||||
|
||||
#ifndef _ESPOS_TIME_H_
|
||||
#define _ESPOS_TIME_H_
|
||||
|
||||
#include "espos_types.h"
|
||||
#include "espos_errno.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* delay or wait for ticks, it is used by mutex, queue,
|
||||
* semaphore, timer and so on
|
||||
*/
|
||||
/* no delay for ticks, function will return immediately */
|
||||
#define ESPOS_NO_DELAY 0u
|
||||
/* delay forever, function will never return until event triggers */
|
||||
#define ESPOS_MAX_DELAY 0xffffffffu
|
||||
|
||||
espos_time_t espos_get_tick_per_ms(void);
|
||||
|
||||
/**
|
||||
* @brief get current system ticks
|
||||
*
|
||||
* @return current ticks
|
||||
*/
|
||||
espos_tick_t espos_get_tick_count(void);
|
||||
|
||||
/**
|
||||
* @brief transform milliseconds to system ticks
|
||||
*
|
||||
* @param ms milliseconds
|
||||
*
|
||||
* @return system ticks
|
||||
*
|
||||
* @note the function discards the shortage of digits, for example:
|
||||
* 20ms -> 2 ticks ; 21ms -> 2 ticks; 29 -> 2 ticks
|
||||
*/
|
||||
espos_tick_t espos_ms_to_ticks(espos_time_t ms);
|
||||
|
||||
/**
|
||||
* @brief transform system ticks to milliseconds
|
||||
*
|
||||
* @param ticks system ticks
|
||||
*
|
||||
* @return milliseconds
|
||||
*/
|
||||
espos_time_t espos_ticks_to_ms(espos_tick_t ticks);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
174
Living_SDK/kernel/vcall/espos/include/espos_timer.h
Normal file
174
Living_SDK/kernel/vcall/espos/include/espos_timer.h
Normal file
|
|
@ -0,0 +1,174 @@
|
|||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed 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.
|
||||
|
||||
#ifndef _ESPOS_TIMER_H_
|
||||
#define _ESPOS_TIMER_H_
|
||||
|
||||
#include "espos_types.h"
|
||||
#include "espos_errno.h"
|
||||
#include "espos_time.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* timer just run once after starting it */
|
||||
#define ESPOS_TIMER_NO_AUTO_RUN 0
|
||||
/* timer run cycle after starting it */
|
||||
#define ESPOS_TIMER_AUTO_RUN (1 << 0)
|
||||
|
||||
/* timer configuration command */
|
||||
typedef enum espos_timer_cmd {
|
||||
/* configure time's period */
|
||||
ESPOS_TIMER_CHANGE_PERIOD = 0,
|
||||
/* configure time to be "once" */
|
||||
ESPOS_TIMER_CHANGE_ONCE,
|
||||
/* configure time to be "auto" */
|
||||
ESPOS_TIMER_CHANGE_AUTO,
|
||||
|
||||
ESPOS_TIMER_CMD_MAX
|
||||
} espos_timer_cmd_t;
|
||||
|
||||
/**
|
||||
* @brief create a timer
|
||||
*
|
||||
* @param timer timer handle point
|
||||
* @param name timer name, if name is NULL, we will use "default_timer" default
|
||||
* @param cb timer callback function
|
||||
* @param arg timer entry function inputting parameter
|
||||
* @param period_ticks timer period ticks
|
||||
* @param opt timer option
|
||||
* ESPOS_TIMER_NO_AUTO_RUN : created timer will run once, even if it is started,
|
||||
* ESPOS_TIMER_AUTO_RUN : created timer will run automatically
|
||||
*
|
||||
* @return the result
|
||||
* 0 : successful
|
||||
* -ENOMEM : no enough memory
|
||||
* -EINVAL : input parameter error
|
||||
* -EINTR : you do this at interrupt state, and it is not supported
|
||||
*
|
||||
* @note after starting the created timer by "espos_timer_start", it will only run.
|
||||
*/
|
||||
esp_err_t espos_timer_create(espos_timer_t *timer, const char *name, espos_timer_cb_t cb, void *arg,
|
||||
espos_tick_t period_ticks, espos_opt_t opt);
|
||||
|
||||
/**
|
||||
* @brief start a timer
|
||||
*
|
||||
* @param timer timer handle
|
||||
*
|
||||
* @return the result
|
||||
* 0 : successful
|
||||
* -EINVAL : input parameter error
|
||||
* -ECANCELED : failed for some reason depend on low-level OS
|
||||
*
|
||||
* @note after starting the created timer by "espos_timer_start", it will only run
|
||||
*/
|
||||
esp_err_t espos_timer_start(espos_timer_t timer);
|
||||
|
||||
/**
|
||||
* @brief stop a timer
|
||||
*
|
||||
* @param timer timer handle
|
||||
*
|
||||
* @return the result
|
||||
* 0 : successful
|
||||
* -EINVAL : input parameter error
|
||||
* -ECANCELED : failed for some reason depend on low-level OS
|
||||
*
|
||||
* @note the timer should be started again, if it is stopped
|
||||
*/
|
||||
esp_err_t espos_timer_stop(espos_timer_t timer);
|
||||
|
||||
/**
|
||||
* @brief configure a timer
|
||||
*
|
||||
* @param timer timer handle
|
||||
* @param opt timer option command
|
||||
* @param arg timer parameter
|
||||
*
|
||||
* @return the result
|
||||
* 0 : successful
|
||||
* -EINVAL : input parameter error
|
||||
* -ECANCELED : failed for some reason depend on low-level OS
|
||||
*/
|
||||
esp_err_t espos_timer_change(espos_timer_t timer, espos_opt_t opt, void *arg);
|
||||
|
||||
/**
|
||||
* @brief configure period of timer
|
||||
*
|
||||
* @param t timer handle
|
||||
* @param a timer period
|
||||
*
|
||||
* @return the result
|
||||
* 0 : successful
|
||||
* -EINVAL : input parameter error
|
||||
* -ECANCELED : failed for some reason depend on low-level OS
|
||||
*/
|
||||
#define espos_timer_set_period(t, a) espos_timer_change(t, ESPOS_TIMER_CHANGE_PERIOD, (void *)a)
|
||||
|
||||
/**
|
||||
* @brief configure timer to be "once"
|
||||
*
|
||||
* @param t timer handle
|
||||
*
|
||||
* @return the result
|
||||
* 0 : successful
|
||||
* -EINVAL : input parameter error
|
||||
* -ECANCELED : failed for some reason depend on low-level OS
|
||||
*/
|
||||
#define espos_timer_set_once(t) espos_timer_change(t, ESPOS_TIMER_CHANGE_ONCE, NULL)
|
||||
|
||||
/**
|
||||
* @brief configure timer to be "auto"
|
||||
*
|
||||
* @param t timer handle
|
||||
*
|
||||
* @return the result
|
||||
* 0 : successful
|
||||
* -EINVAL : input parameter error
|
||||
* -ECANCELED : failed for some reason depend on low-level OS
|
||||
*/
|
||||
#define espos_timer_set_auto(t) espos_timer_change(t, ESPOS_TIMER_CHANGE_AUTO, NULL)
|
||||
|
||||
/**
|
||||
* @brief delete a timer
|
||||
*
|
||||
* @param t timer handle
|
||||
*
|
||||
* @return the result
|
||||
* 0 : successful
|
||||
* -EACCES : failed to do it with some special reason
|
||||
* -EINTR : you do this at interrupt state, and it is not supported
|
||||
*/
|
||||
esp_err_t espos_timer_del(espos_timer_t timer);
|
||||
|
||||
/**
|
||||
* @brief get current timer name point
|
||||
*
|
||||
* @param timer timer handle
|
||||
* @param pname pointing at name's point
|
||||
*
|
||||
* @return the result
|
||||
* 0 : successful
|
||||
* -EINVAL : input parameter error
|
||||
*/
|
||||
esp_err_t espos_get_timer_name (espos_timer_t timer, char **pname);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
42
Living_SDK/kernel/vcall/espos/include/espos_types.h
Normal file
42
Living_SDK/kernel/vcall/espos/include/espos_types.h
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef _ESPOS_TYPES_H_
|
||||
#define _ESPOS_TYPES_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "arch/espos_arch.h"
|
||||
|
||||
#define ESPOS_OBJ_NONE 0
|
||||
|
||||
#ifdef ARCH64
|
||||
typedef uint64_t espos_obj_t;
|
||||
#else
|
||||
typedef uint32_t espos_obj_t;
|
||||
#endif
|
||||
|
||||
typedef espos_obj_t espos_task_t;
|
||||
typedef espos_obj_t espos_queue_t;
|
||||
typedef espos_obj_t espos_mutex_t;
|
||||
typedef espos_obj_t espos_sem_t;
|
||||
typedef espos_obj_t espos_timer_t;
|
||||
typedef espos_obj_t espos_critical_t;
|
||||
|
||||
typedef size_t espos_size_t;
|
||||
typedef size_t espos_pos_t;
|
||||
typedef uint8_t espos_prio_t;
|
||||
typedef uint32_t espos_opt_t;
|
||||
typedef int32_t espos_cpu_t;
|
||||
|
||||
typedef espos_size_t espos_tick_t;
|
||||
typedef espos_size_t espos_time_t;
|
||||
typedef espos_size_t espos_sem_count_t;
|
||||
|
||||
typedef void (*espos_task_entry_t)(void *p);
|
||||
typedef void (*espos_timer_cb_t)(espos_timer_t timer, void *arg);
|
||||
|
||||
#endif
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue