1 /*
2 * Copyright (C) 2015-2019 Alibaba Group Holding Limited
3 */
4
5 #include <stdint.h>
6 #include <stdlib.h>
7 #include "aos_system.h"
8 #include "at_opts.h"
9
atpsr_malloc(uint32_t size)10 void *atpsr_malloc(uint32_t size)
11 {
12 return aos_malloc(size);
13 }
14
atpsr_free(void * ptr)15 void atpsr_free(void *ptr)
16 {
17 aos_free(ptr);
18 }
19
20 #if ATPSR_SINGLE_TASK
atpsr_mutex_new(void)21 void *atpsr_mutex_new(void)
22 {
23 return (void*)1;
24 }
25
atpsr_mutex_free(void * mutex)26 void atpsr_mutex_free(void *mutex)
27 {
28 return;
29 }
30
atpsr_mutex_lock(void * mutex)31 void atpsr_mutex_lock(void *mutex)
32 {
33 return;
34 }
35
atpsr_mutex_unlock(void * mutex)36 void atpsr_mutex_unlock(void *mutex)
37 {
38 return;
39 }
40
atpsr_sem_new(void)41 void *atpsr_sem_new(void)
42 {
43 return (void*)1;
44 }
45
atpsr_sem_free(void * sem)46 void atpsr_sem_free(void *sem)
47 {
48 return;
49 }
50
atpsr_sem_signal(void * sem)51 void atpsr_sem_signal(void *sem)
52 {
53 return;
54 }
55
atpsr_sem_wait(void * sem,uint32_t timeout_ms)56 int atpsr_sem_wait(void *sem, uint32_t timeout_ms)
57 {
58 return 0;
59 }
60 #else
atpsr_mutex_new(void)61 void *atpsr_mutex_new(void)
62 {
63 aos_mutex_t mutex;
64 if (0 != aos_mutex_new(&mutex)) {
65 return NULL;
66 }
67 return mutex;
68 }
69
atpsr_mutex_free(void * mutex)70 void atpsr_mutex_free(void *mutex)
71 {
72 if (NULL != mutex) {
73 aos_mutex_free((aos_mutex_t *)&mutex);
74 }
75 }
76
atpsr_mutex_lock(void * mutex)77 void atpsr_mutex_lock(void *mutex)
78 {
79 if (NULL != mutex) {
80 aos_mutex_lock((aos_mutex_t *)&mutex, AOS_WAIT_FOREVER);
81 }
82 }
83
atpsr_mutex_unlock(void * mutex)84 void atpsr_mutex_unlock(void *mutex)
85 {
86 if (NULL != mutex) {
87 aos_mutex_unlock((aos_mutex_t *)&mutex);
88 }
89 }
90
atpsr_sem_new(void)91 void *atpsr_sem_new(void)
92 {
93 aos_sem_t sem;
94 if (0 != aos_sem_new(&sem, 0)) {
95 return NULL;
96 }
97 return sem;
98 }
99
atpsr_sem_free(void * sem)100 void atpsr_sem_free(void *sem)
101 {
102 aos_sem_free((aos_sem_t *)&sem);
103 }
104
atpsr_sem_signal(void * sem)105 void atpsr_sem_signal(void *sem)
106 {
107 aos_sem_signal((aos_sem_t *)&sem);
108 }
109
atpsr_sem_wait(void * sem,uint32_t timeout_ms)110 int atpsr_sem_wait(void *sem, uint32_t timeout_ms)
111 {
112 return aos_sem_wait((aos_sem_t *)&sem, timeout_ms);
113 }
114
atpsr_task_new_ext(void * task,char * name,void (* fn)(void *),void * arg,int stack_size,int prio)115 int atpsr_task_new_ext(void *task, char *name, void (*fn)(void *),
116 void *arg, int stack_size, int prio)
117 {
118 if (task == NULL)
119 return -1;
120
121 return aos_task_new_ext(&task, name, fn, arg, stack_size, AOS_DEFAULT_APP_PRI);
122 }
123
atpsr_sleep_ms(const unsigned int millisec)124 void atpsr_sleep_ms(const unsigned int millisec)
125 {
126 aos_msleep(millisec);
127 }
128 #endif
129