物联网操作系统AliOS Things 3.3
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 */
157 /* Define the data type for task key index */
158 typedef uint32_t aos_task_key_t;
167 /* Define the data type for function return */
168 typedef int32_t aos_status_t;
177 /* Define the main handle for spinlock module */
178 typedef struct {
179  volatile uint32_t owner; /* cpu index of owner */
181 
182 /* Define the data type for spinlock irq save value */
183 typedef long aos_irqsave_t;
221 aos_status_t aos_task_create(aos_task_t *task, const char *name, void (*fn)(void *),
222  void *arg,void *stack_buf, size_t stack_size, int32_t prio, uint32_t options);
223 
244 
262 
277 void aos_task_exit(int32_t code);
278 
298 
316 
336 aos_status_t aos_task_name_get(aos_task_t *task, char *buf, size_t buf_size);
337 
353 
362 
371 
381 
390 
415 aos_status_t aos_mutex_create(aos_mutex_t *mutex, uint32_t options);
416 
428 
450 aos_status_t aos_mutex_lock(aos_mutex_t *mutex, uint32_t timeout);
451 
470 
490 aos_status_t aos_sem_create(aos_sem_t *sem, uint32_t count, uint32_t options);
498 
508 aos_status_t aos_sem_wait(aos_sem_t *sem, uint32_t timeout);
509 
516 
523 
543 aos_status_t aos_event_create(aos_event_t *event, uint32_t value, uint32_t options);
544 
552 
553 
565 aos_status_t aos_event_get(aos_event_t *event, uint32_t value, uint32_t opt, uint32_t *actl_value, uint32_t timeout);
566 
580 aos_status_t aos_event_set(aos_event_t *event, uint32_t value, uint32_t opt);
581 
601 aos_status_t aos_queue_create(aos_queue_t *queue, size_t size, size_t max_msg, uint32_t options);
608 
618 aos_status_t aos_queue_send(aos_queue_t *queue, void *msg, size_t size);
619 
630 aos_status_t aos_queue_recv(aos_queue_t *queue, uint32_t ms, void *msg, size_t *size);
631 
640 
661 aos_status_t aos_timer_create(aos_timer_t *timer, void (*fn)(void *, void *), void *arg,
662  uint32_t ms, uint32_t options);
663 
670 
679 
688 
701 
714 
731 
738 
745 
754 
763 
781 void *aos_realloc(void *mem, size_t size);
782 
790 void *aos_malloc(size_t size);
791 
800 void *aos_calloc(size_t nitems, size_t size);
801 
809 void *aos_zalloc(size_t size);
810 
817 void aos_alloc_trace(void *addr, uintptr_t allocator);
818 
826 void aos_free(void *mem);
827 
842 void aos_calendar_time_set(uint64_t now_ms);
843 
850 uint64_t aos_calendar_time_get(void);
851 
858 
864 uint64_t aos_now(void);
865 
871 uint64_t aos_now_ms(void);
872 
886 aos_status_t aos_now_time_str(char *buffer, size_t len);
887 
893 void aos_msleep(uint32_t ms);
894 
911 void aos_srand(uint32_t seed);
912 
918 int32_t aos_rand(void);
919 
925 void aos_reboot(void);
926 
932 int32_t aos_get_hz(void);
933 
946 aos_status_t aos_version_str_get(char *buf, size_t len);
947 
951 void aos_init(void);
952 
956 void aos_start(void);
957 
961 /* The following APIs is marked deprecated and is not recommended */
962 
981 aos_status_t aos_task_new(const char *name, void (*fn)(void *), void *arg, size_t stack_size);
982 
996 aos_status_t aos_task_new_ext(aos_task_t *task, const char *name, void (*fn)(void *),
997  void *arg, size_t stack_size, int32_t prio);
998 
1018 
1028 
1048 aos_status_t aos_sem_new(aos_sem_t *sem, uint32_t count);
1049 
1059 
1079 aos_status_t aos_event_new(aos_event_t *event, uint32_t value);
1080 
1090 
1102 aos_status_t aos_queue_new(aos_queue_t *queue, void *buf, size_t size, size_t max_msg);
1103 
1113 
1123 
1145 aos_status_t aos_timer_new(aos_timer_t *timer, void (*fn)(void *, void *), void *arg,
1146  uint32_t ms, bool repeat);
1147 
1161 aos_status_t aos_timer_new_ext(aos_timer_t *timer, void (*fn)(void *, void *), void *arg,
1162  uint32_t ms, bool repeat, bool autorun);
1163 
1168 #ifdef __cplusplus
1169 }
1170 #endif
1171 
1172 #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:183
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:168
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:158
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)
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)
volatile uint32_t owner
Definition: kernel.h:179