kernel.h
浏览该文件的文档.
1 /*
2  * Copyright (C) 2015-2021 Alibaba Group Holding Limited
3  */
4 
5 #ifndef AOS_KERNEL_H
6 #define AOS_KERNEL_H
7 
8 #include <stdlib.h>
9 #include <stddef.h>
10 #include <sys/types.h>
11 #include <stdint.h>
12 #include <stdbool.h>
13 #include <aos/osal_debug.h>
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
33 /* Define the AliOS-Things' Version */
34 #define SYSINFO_KERNEL_VERSION "AOS-R-3.3.0"
36 /* Defined for API with delay time */
37 #define AOS_WAIT_FOREVER 0xffffffffu
38 #define AOS_NO_WAIT 0x0
40 /* Define default aos task priority*/
41 #ifndef AOS_DEFAULT_APP_PRI
42 #define AOS_DEFAULT_APP_PRI 32
43 #endif
44 
53 #define AOS_EVENT_AND 0x02u
54 #define AOS_EVENT_AND_CLEAR 0x03u
55 #define AOS_EVENT_OR 0x00u
56 #define AOS_EVENT_OR_CLEAR 0x01u
65 #define AOS_TASK_NONE 0x0u
66 #define AOS_TASK_AUTORUN 0x01u
75 #define AOS_TIMER_NONE 0x0u
76 #define AOS_TIMER_AUTORUN 0x01u
77 #define AOS_TIMER_REPEAT 0x02u
87 /* Define the handle for all aos module */
88 typedef void * aos_hdl_t;
97 /* Define the main handle for task module */
107 /* Define the main handle for mutex module */
117 /* Define the main handle for sem module */
127 /* Define the main handle for queue module */
137 /* Define the main handle for event module */
147 /* Define the main handle for timer module */
158 /* Define the main handle for workqueue module */
159 typedef struct {
161  void *stk;
163 
164 /* Define the main handle for work of workqueue module */
174 /* Define the data type for task key index */
175 typedef uint32_t aos_task_key_t;
184 /* Define the data type for function return */
185 typedef int32_t aos_status_t;
194 /* Define the main handle for spinlock module */
195 typedef struct {
196  volatile uint32_t owner; /* cpu index of owner */
198 
199 /* Define the data type for spinlock irq save value */
200 typedef long aos_irqsave_t;
238 aos_status_t aos_task_create(aos_task_t *task, const char *name, void (*fn)(void *),
239  void *arg,void *stack_buf, size_t stack_size, int32_t prio, uint32_t options);
240 
261 
279 
294 void aos_task_exit(int32_t code);
295 
315 
333 
353 aos_status_t aos_task_name_get(aos_task_t *task, char *buf, size_t buf_size);
354 
370 
379 
388 
398 
407 
432 aos_status_t aos_mutex_create(aos_mutex_t *mutex, uint32_t options);
433 
445 
467 aos_status_t aos_mutex_lock(aos_mutex_t *mutex, uint32_t timeout);
468 
487 
507 aos_status_t aos_sem_create(aos_sem_t *sem, uint32_t count, uint32_t options);
515 
525 aos_status_t aos_sem_wait(aos_sem_t *sem, uint32_t timeout);
526 
533 
540 
560 aos_status_t aos_event_create(aos_event_t *event, uint32_t value, uint32_t options);
561 
569 
570 
582 aos_status_t aos_event_get(aos_event_t *event, uint32_t value, uint32_t opt, uint32_t *actl_value, uint32_t timeout);
583 
597 aos_status_t aos_event_set(aos_event_t *event, uint32_t value, uint32_t opt);
598 
618 aos_status_t aos_queue_create(aos_queue_t *queue, size_t size, size_t max_msg, uint32_t options);
625 
635 aos_status_t aos_queue_send(aos_queue_t *queue, void *msg, size_t size);
636 
647 aos_status_t aos_queue_recv(aos_queue_t *queue, uint32_t ms, void *msg, size_t *size);
648 
657 
678 aos_status_t aos_timer_create(aos_timer_t *timer, void (*fn)(void *, void *), void *arg,
679  uint32_t ms, uint32_t options);
680 
687 
696 
705 
718 
731 
741 
762 aos_status_t aos_workqueue_create(aos_workqueue_t *workqueue, const char *name, int32_t prio, void *stack_buffer, size_t stack_size);
763 
770 
781 aos_status_t aos_work_init(aos_work_t *work, void (*fn)(void *), void *arg, int dly);
782 
791 
801 
810 
819 
836 
843 
850 
859 
868 
886 void *aos_realloc(void *mem, size_t size);
887 
895 void *aos_malloc(size_t size);
896 
905 void *aos_calloc(size_t nitems, size_t size);
906 
914 void *aos_zalloc(size_t size);
915 
922 void aos_alloc_trace(void *addr, uintptr_t allocator);
923 
931 void aos_free(void *mem);
932 
947 void aos_calendar_time_set(uint64_t now_ms);
948 
955 uint64_t aos_calendar_time_get(void);
956 
963 
969 uint64_t aos_now(void);
970 
976 uint64_t aos_now_ms(void);
977 
991 aos_status_t aos_now_time_str(char *buffer, size_t len);
992 
998 void aos_msleep(uint32_t ms);
999 
1016 void aos_srand(uint32_t seed);
1017 
1023 int32_t aos_rand(void);
1024 
1030 void aos_reboot(void);
1031 
1037 int32_t aos_get_hz(void);
1038 
1051 aos_status_t aos_version_str_get(char *buf, size_t len);
1052 
1056 void aos_init(void);
1057 
1061 void aos_start(void);
1062 
1066 /* The following APIs is marked deprecated and is not recommended */
1067 
1086 aos_status_t aos_task_new(const char *name, void (*fn)(void *), void *arg, size_t stack_size);
1087 
1101 aos_status_t aos_task_new_ext(aos_task_t *task, const char *name, void (*fn)(void *),
1102  void *arg, size_t stack_size, int32_t prio);
1103 
1123 
1133 
1153 aos_status_t aos_sem_new(aos_sem_t *sem, uint32_t count);
1154 
1164 
1184 aos_status_t aos_event_new(aos_event_t *event, uint32_t value);
1185 
1195 
1207 aos_status_t aos_queue_new(aos_queue_t *queue, void *buf, size_t size, size_t max_msg);
1208 
1218 
1228 
1250 aos_status_t aos_timer_new(aos_timer_t *timer, void (*fn)(void *, void *), void *arg,
1251  uint32_t ms, bool repeat);
1252 
1266 aos_status_t aos_timer_new_ext(aos_timer_t *timer, void (*fn)(void *, void *), void *arg,
1267  uint32_t ms, bool repeat, bool autorun);
1268 
1273 #ifdef __cplusplus
1274 }
1275 #endif
1276 
1277 #endif /* AOS_KERNEL_H */
void * aos_queue_buf_ptr(aos_queue_t *queue)
aos_status_t aos_queue_new(aos_queue_t *queue, void *buf, size_t size, size_t max_msg)
aos_status_t aos_event_new(aos_event_t *event, uint32_t value)
aos_hdl_t aos_event_t
Definition: kernel.h:128
aos_status_t aos_event_set(aos_event_t *event, uint32_t value, uint32_t opt)
aos_status_t aos_event_create(aos_event_t *event, uint32_t value, uint32_t options)
void aos_event_free(aos_event_t *event)
bool aos_event_is_valid(aos_event_t *event)
bool aos_queue_is_valid(aos_queue_t *queue)
aos_status_t aos_event_get(aos_event_t *event, uint32_t value, uint32_t opt, uint32_t *actl_value, uint32_t timeout)
void * aos_realloc(void *mem, size_t size)
void aos_alloc_trace(void *addr, uintptr_t allocator)
void aos_free(void *mem)
void * aos_zalloc(size_t size)
void * aos_calloc(size_t nitems, size_t size)
void * aos_malloc(size_t size)
aos_status_t aos_mutex_create(aos_mutex_t *mutex, uint32_t options)
aos_status_t aos_mutex_unlock(aos_mutex_t *mutex)
void aos_mutex_free(aos_mutex_t *mutex)
bool aos_mutex_is_valid(aos_mutex_t *mutex)
aos_status_t aos_mutex_lock(aos_mutex_t *mutex, uint32_t timeout)
aos_hdl_t aos_mutex_t
Definition: kernel.h:108
aos_status_t aos_mutex_new(aos_mutex_t *mutex)
aos_status_t aos_queue_send(aos_queue_t *queue, void *msg, size_t size)
aos_status_t aos_queue_get_count(aos_queue_t *queue)
void aos_queue_free(aos_queue_t *queue)
aos_status_t aos_queue_create(aos_queue_t *queue, size_t size, size_t max_msg, uint32_t options)
aos_status_t aos_queue_recv(aos_queue_t *queue, uint32_t ms, void *msg, size_t *size)
aos_hdl_t aos_queue_t
Definition: kernel.h:138
aos_hdl_t aos_sem_t
Definition: kernel.h:118
void aos_sem_signal_all(aos_sem_t *sem)
aos_status_t aos_sem_create(aos_sem_t *sem, uint32_t count, uint32_t options)
void aos_sem_free(aos_sem_t *sem)
void aos_sem_signal(aos_sem_t *sem)
aos_status_t aos_sem_wait(aos_sem_t *sem, uint32_t timeout)
aos_status_t aos_sem_new(aos_sem_t *sem, uint32_t count)
bool aos_sem_is_valid(aos_sem_t *sem)
void aos_spin_lock(aos_spinlock_t *spinlock)
void aos_spin_unlock(aos_spinlock_t *spinlock)
void aos_spin_unlock_irqrestore(aos_spinlock_t *spinlock, aos_irqsave_t flag)
void aos_spin_lock_init(aos_spinlock_t *spinlock)
aos_irqsave_t aos_spin_lock_irqsave(aos_spinlock_t *spinlock)
long aos_irqsave_t
Definition: kernel.h:200
int32_t aos_rand(void)
aos_status_t aos_version_str_get(char *buf, size_t len)
int32_t aos_get_hz(void)
void aos_init(void)
void aos_srand(uint32_t seed)
int32_t aos_status_t
Definition: kernel.h:185
void aos_reboot(void)
void * aos_hdl_t
Definition: kernel.h:88
void aos_start(void)
aos_status_t aos_task_resume(aos_task_t *task)
aos_task_t aos_task_self(void)
void aos_task_exit(int32_t code)
aos_status_t aos_task_create(aos_task_t *task, const char *name, void(*fn)(void *), void *arg, void *stack_buf, size_t stack_size, int32_t prio, uint32_t options)
void * aos_task_getspecific(aos_task_key_t key)
aos_status_t aos_task_key_create(aos_task_key_t *key)
aos_hdl_t aos_task_t
Definition: kernel.h:98
aos_status_t aos_task_suspend(aos_task_t *task)
aos_status_t aos_task_setspecific(aos_task_key_t key, void *vp)
uint32_t aos_task_key_t
Definition: kernel.h:175
aos_status_t aos_task_new(const char *name, void(*fn)(void *), void *arg, size_t stack_size)
aos_status_t aos_task_new_ext(aos_task_t *task, const char *name, void(*fn)(void *), void *arg, size_t stack_size, int32_t prio)
void aos_task_key_delete(aos_task_key_t key)
aos_status_t aos_task_name_get(aos_task_t *task, char *buf, size_t buf_size)
aos_status_t aos_task_delete(aos_task_t *task)
aos_status_t aos_task_yield(void)
void aos_msleep(uint32_t ms)
uint64_t aos_now(void)
uint64_t aos_calendar_localtime_get(void)
uint64_t aos_now_ms(void)
aos_status_t aos_now_time_str(char *buffer, size_t len)
Retrieves the timer string. Under RTOS w/o RTC, this fucntion will return the UTC time string that co...
void aos_calendar_time_set(uint64_t now_ms)
uint64_t aos_calendar_time_get(void)
aos_status_t aos_timer_new_ext(aos_timer_t *timer, void(*fn)(void *, void *), void *arg, uint32_t ms, bool repeat, bool autorun)
aos_hdl_t aos_timer_t
Definition: kernel.h:148
aos_status_t aos_timer_create(aos_timer_t *timer, void(*fn)(void *, void *), void *arg, uint32_t ms, uint32_t options)
void aos_timer_free(aos_timer_t *timer)
aos_status_t aos_timer_new(aos_timer_t *timer, void(*fn)(void *, void *), void *arg, uint32_t ms, bool repeat)
bool aos_timer_is_valid(aos_timer_t *timer)
aos_status_t aos_timer_stop(aos_timer_t *timer)
aos_status_t aos_timer_start(aos_timer_t *timer)
aos_status_t aos_timer_change_once(aos_timer_t *timer, uint32_t ms)
aos_status_t aos_timer_change(aos_timer_t *timer, uint32_t ms)
aos_hdl_t aos_work_t
Definition: kernel.h:165
aos_status_t aos_workqueue_create(aos_workqueue_t *workqueue, const char *name, int32_t prio, void *stack_buffer, size_t stack_size)
aos_status_t aos_work_sched(aos_work_t *work)
aos_status_t aos_work_init(aos_work_t *work, void(*fn)(void *), void *arg, int dly)
void aos_workqueue_del(aos_workqueue_t *workqueue)
void aos_work_destroy(aos_work_t *work)
aos_status_t aos_work_cancel(aos_work_t *work)
aos_status_t aos_work_run(aos_workqueue_t *workqueue, aos_work_t *work)
volatile uint32_t owner
Definition: kernel.h:196
aos_hdl_t hdl
Definition: kernel.h:160
void * stk
Definition: kernel.h:161