1 /**
2 * @file lv_mqx.c
3 *
4 */
5
6 /*********************
7 * INCLUDES
8 *********************/
9 #include "lv_os.h"
10
11 #if LV_USE_OS == LV_OS_MQX
12
13 #include "../misc/lv_log.h"
14 #include "../stdlib/lv_string.h"
15
16 /*********************
17 * DEFINES
18 *********************/
19
20 /**********************
21 * TYPEDEFS
22 **********************/
23
24 /**********************
25 * STATIC PROTOTYPES
26 **********************/
27
28 /**********************
29 * STATIC VARIABLES
30 **********************/
31
32 /**********************
33 * MACROS
34 **********************/
35
36 /**********************
37 * GLOBAL FUNCTIONS
38 **********************/
39
lv_thread_init(lv_thread_t * thread,const char * const name,lv_thread_prio_t prio,void (* callback)(void *),size_t stack_size,void * user_data)40 lv_result_t lv_thread_init(lv_thread_t * thread, const char * const name, lv_thread_prio_t prio,
41 void (*callback)(void *), size_t stack_size,
42 void * user_data)
43 {
44 TASK_TEMPLATE_STRUCT task_template;
45
46 lv_memzero(&task_template, sizeof(task_template));
47
48 task_template.TASK_ADDRESS = (TASK_FPTR)callback;
49 task_template.TASK_STACKSIZE = stack_size;
50 task_template.TASK_PRIORITY = _sched_get_min_priority(0) - prio;
51 task_template.TASK_NAME = name;
52 task_template.CREATION_PARAMETER = (uint32_t)user_data;
53
54 *thread = _task_create(0, 0, (uint32_t)&task_template);
55 if(*thread == MQX_NULL_TASK_ID) {
56 LV_LOG_WARN("_task_create failed!");
57 return LV_RESULT_INVALID;
58 }
59 return LV_RESULT_OK;
60 }
61
lv_thread_delete(lv_thread_t * thread)62 lv_result_t lv_thread_delete(lv_thread_t * thread)
63 {
64 _mqx_uint ret = _task_destroy(*thread);
65 if(ret != MQX_OK) {
66 LV_LOG_WARN("_task_destroy failed!");
67 return LV_RESULT_INVALID;
68 }
69 return LV_RESULT_OK;
70 }
71
lv_mutex_init(lv_mutex_t * mutex)72 lv_result_t lv_mutex_init(lv_mutex_t * mutex)
73 {
74 if(MQX_OK != _mutex_init(mutex, NULL)) {
75 LV_LOG_WARN("create mutex failed");
76 return LV_RESULT_INVALID;
77 }
78 return LV_RESULT_OK;
79 }
80
lv_mutex_lock(lv_mutex_t * mutex)81 lv_result_t lv_mutex_lock(lv_mutex_t * mutex)
82 {
83 _mqx_uint ret = _mutex_lock(mutex);
84 if(ret != MQX_OK) {
85 LV_LOG_WARN("Error: %x", ret);
86 return LV_RESULT_INVALID;
87 }
88 return LV_RESULT_OK;
89 }
90
lv_mutex_lock_isr(lv_mutex_t * mutex)91 lv_result_t lv_mutex_lock_isr(lv_mutex_t * mutex)
92 {
93 _mqx_uint ret = _mutex_lock(mutex);
94 if(ret != MQX_OK) {
95 LV_LOG_WARN("Error: %x", ret);
96 return LV_RESULT_INVALID;
97 }
98 return LV_RESULT_OK;
99 }
100
lv_mutex_unlock(lv_mutex_t * mutex)101 lv_result_t lv_mutex_unlock(lv_mutex_t * mutex)
102 {
103 _mqx_uint ret = _mutex_unlock(mutex);
104 if(ret != MQX_OK) {
105 LV_LOG_WARN("Error: %x", ret);
106 return LV_RESULT_INVALID;
107 }
108 return LV_RESULT_OK;
109 }
110
lv_mutex_delete(lv_mutex_t * mutex)111 lv_result_t lv_mutex_delete(lv_mutex_t * mutex)
112 {
113 _mqx_uint ret = _mutex_destroy(mutex);
114 if(ret != MQX_OK) {
115 LV_LOG_WARN("Error: %x", ret);
116 return LV_RESULT_INVALID;
117 }
118 return LV_RESULT_OK;
119 }
120
lv_thread_sync_init(lv_thread_sync_t * sync)121 lv_result_t lv_thread_sync_init(lv_thread_sync_t * sync)
122 {
123 if(MQX_OK != _lwsem_create(sync, 0)) {
124 LV_LOG_WARN("create semaphore failed");
125 return LV_RESULT_INVALID;
126 }
127 return LV_RESULT_OK;
128 }
129
lv_thread_sync_wait(lv_thread_sync_t * sync)130 lv_result_t lv_thread_sync_wait(lv_thread_sync_t * sync)
131 {
132 _mqx_uint ret = _lwsem_wait(sync);
133 if(ret != MQX_OK) {
134 LV_LOG_WARN("Error: %x", ret);
135 return LV_RESULT_INVALID;
136 }
137 return LV_RESULT_OK;
138 }
139
lv_thread_sync_signal(lv_thread_sync_t * sync)140 lv_result_t lv_thread_sync_signal(lv_thread_sync_t * sync)
141 {
142 _mqx_uint ret = _lwsem_post(sync);
143 if(ret != MQX_OK) {
144 LV_LOG_WARN("Error: %x", ret);
145 return LV_RESULT_INVALID;
146 }
147 return LV_RESULT_OK;
148 }
149
lv_thread_sync_delete(lv_thread_sync_t * sync)150 lv_result_t lv_thread_sync_delete(lv_thread_sync_t * sync)
151 {
152 _mqx_uint ret = _lwsem_destroy(sync);
153 if(ret != MQX_OK) {
154 LV_LOG_WARN("Error: %x", ret);
155 return LV_RESULT_INVALID;
156 }
157 return LV_RESULT_OK;
158 }
159
lv_thread_sync_signal_isr(lv_thread_sync_t * sync)160 lv_result_t lv_thread_sync_signal_isr(lv_thread_sync_t * sync)
161 {
162 LV_UNUSED(sync);
163 return LV_RESULT_INVALID;
164 }
165
166 /**********************
167 * STATIC FUNCTIONS
168 **********************/
169
170 #endif /*LV_USE_OS == LV_OS_MQX*/
171