1 /*
2 * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #include "cmsis_os.h"
16 #include "los_event.h"
17 #include "los_membox.h"
18 #include "los_memory.h"
19 #include "los_interrupt.h"
20 #include "los_mux.h"
21 #include "los_queue.h"
22 #include "los_sem.h"
23 #include "los_swtmr.h"
24 #include "los_task.h"
25 #include "kal.h"
26 #include "los_debug.h"
27
28 #include "string.h"
29 #include "securec.h"
30 #include "hal_trace.h"
31
32 // Thread
osThreadCreate(const osThreadDef_t * thread_def,void * argument)33 osThreadId osThreadCreate (const osThreadDef_t *thread_def, void *argument) {
34 osThreadId thread_Id;
35
36 if (thread_def == NULL) {
37 return (osThreadId)NULL;
38 }
39 thread_Id = osThreadNew((osThreadFunc_t)thread_def->pthread, argument, &thread_def->attr);
40
41 return thread_Id;
42 }
43
44
45 // Signals
46 #if 1
47 #define SignalMask ((1U<<osFeature_Signals)-1U)
48
osSignalSet(osThreadId thread_id,int32_t signals)49 int32_t osSignalSet (osThreadId thread_id, int32_t signals) {
50 uint32_t flags;
51
52 if (!thread_id) {
53 TRACE(0, "%s=>%s %d thread_Id=%p \n", __FILE__,__func__, __LINE__, thread_id);
54 return ((int32_t)0x80000000U);
55 }
56
57 flags = osEventFlagsSet(thread_id->ef_id, (uint32_t)signals);
58 if (flags == osFlagsErrorParameter) {
59 return ((int32_t)0x80000000U);
60 }
61
62 return (int32_t)flags;
63 }
64
osSignalClear(osThreadId thread_id,int32_t signals)65 int32_t osSignalClear (osThreadId thread_id, int32_t signals) {
66 uint32_t flags;
67
68 if (!thread_id) {
69 TRACE(0, "%s=>%s %d thread_Id=%p \n", __FILE__,__func__, __LINE__, thread_id);
70 return ((int32_t)0x80000000U);
71 }
72
73 if (thread_id != osThreadGetId()) {
74 return ((int32_t)0x80000000U);
75 }
76
77 flags = osEventFlagsClear(thread_id->ef_id, (uint32_t)signals);
78 if (flags == osFlagsErrorParameter) {
79 return ((int32_t)0x80000000U);
80 }
81 return ((int32_t)flags);
82 }
83
osSignalWait(int32_t signals,uint32_t millisec)84 osEvent osSignalWait (int32_t signals, uint32_t millisec) {
85 osEvent event = {0};
86 int32_t flags;
87 osThreadId thread_id = osThreadGetId();
88
89 if (!thread_id) {
90 TRACE(0, "%s=>%s %d thread_Id=%p \n", __FILE__,__func__, __LINE__, thread_id);
91 event.status = osErrorValue;
92 return event;
93 }
94
95 if (signals != 0) {
96 flags = (int32_t) osEventFlagsWait(thread_id->ef_id, (uint32_t)signals, osFlagsWaitAll, millisec);
97 } else {
98 flags = (int32_t) osEventFlagsWait(thread_id->ef_id, SignalMask, osFlagsWaitAny, millisec);
99 }
100
101 if (flags > 0) {
102 event.status = osEventSignal;
103 event.value.signals = (int32_t)flags;
104 } else {
105 switch ((int32_t)flags) {
106 case osErrorResource:
107 event.status = osOK;
108 break;
109 case osErrorTimeout:
110 event.status = osEventTimeout;
111 break;
112 case osErrorParameter:
113 event.status = osErrorValue;
114 break;
115 default:
116 event.status = (osStatus)flags;
117 break;
118 }
119 }
120 return event;
121 }
122 #endif
123
124 #if 0
125 #define SignalMask ((1U<<osFeature_Signals)-1U)
126
127 int32_t osSignalSet (osThreadId thread_id, int32_t signals) {
128 uint32_t flags;
129
130 flags = osThreadFlagsSet(thread_id, (uint32_t)signals);
131 if ((flags & 0x80000000U) != 0U) {
132 return ((int32_t)0x80000000U);
133 }
134 return ((int32_t)(flags & ~((uint32_t)signals)));
135 }
136
137 int32_t osSignalClear (osThreadId thread_id, int32_t signals) {
138 uint32_t flags;
139
140 if (thread_id != osThreadGetId()) {
141 return ((int32_t)0x80000000U);
142 }
143 flags = osThreadFlagsClear((uint32_t)signals);
144 if ((flags & 0x80000000U) != 0U) {
145 return ((int32_t)0x80000000U);
146 }
147 return ((int32_t)flags);
148 }
149
150 osEvent osSignalWait (int32_t signals, uint32_t millisec) {
151 osEvent event = {0};
152 uint32_t flags;
153
154 if (signals != 0) {
155 flags = osThreadFlagsWait((uint32_t)signals, osFlagsWaitAll, millisec);
156 } else {
157 flags = osThreadFlagsWait(SignalMask, osFlagsWaitAny, millisec);
158 }
159
160 if ((flags > 0U) && (flags < 0x80000000U)) {
161 event.status = osEventSignal;
162 event.value.signals = (int32_t)flags;
163 } else {
164 switch ((int32_t)flags) {
165 case osErrorResource:
166 event.status = osOK;
167 break;
168 case osErrorTimeout:
169 event.status = osEventTimeout;
170 break;
171 case osErrorParameter:
172 event.status = osErrorValue;
173 break;
174 default:
175 event.status = (osStatus)flags;
176 break;
177 }
178 }
179 return event;
180 }
181 #endif
182 #if 0
183 // can only use 31 bits at most
184 #if (osFeature_Signals > 0x1F)
185 #error exceed max event bit count
186 #endif
187
188 #define VALID_EVENT_MASK ((UINT32)((1U << osFeature_Signals) - 1))
189 #define INVALID_EVENT_MASK ((UINT32)(~VALID_EVENT_MASK))
190
191 int32_t osSignalSet(osThreadId thread_id, int32_t signals)
192 {
193 LosTaskCB *taskCB = (LosTaskCB *)thread_id;
194 UINT32 events = (UINT32)signals;
195 UINT32 intSave;
196 UINT32 ret;
197 EVENT_CB_S *eventCB = NULL;
198 UINT32 eventSave;
199
200 if ((taskCB == NULL) || (events & INVALID_EVENT_MASK)) {
201 return (int32_t)0x80000000;
202 }
203 if (OS_TASK_ID_CHECK_INVALID(taskCB->taskID) || (taskCB->taskStatus & OS_TASK_STATUS_UNUSED)) {
204 return (int32_t)0x80000000;
205 }
206
207 eventCB = &(taskCB->event);
208 intSave = LOS_IntLock();
209 eventSave = eventCB->uwEventID;
210 LOS_IntRestore(intSave);
211
212 ret = LOS_EventWrite(eventCB, events);
213 if (ret == LOS_OK) {
214 return (int32_t)eventSave;
215 } else {
216 return (int32_t)0x80000000;
217 }
218 }
219
220 int32_t osSignalClear(osThreadId thread_id, int32_t signals)
221 {
222 LosTaskCB *taskCB = (LosTaskCB *)thread_id;
223 UINT32 events = (UINT32)signals;
224 UINT32 intSave;
225 UINT32 ret;
226 EVENT_CB_S *eventCB = NULL;
227 UINT32 eventSave;
228
229 if ((taskCB == NULL) || (events & INVALID_EVENT_MASK) || OS_INT_ACTIVE) {
230 return (int32_t)0x80000000;
231 }
232 if (OS_TASK_ID_CHECK_INVALID(taskCB->taskID) || (taskCB->taskStatus & OS_TASK_STATUS_UNUSED)) {
233 return (int32_t)0x80000000;
234 }
235
236 eventCB = &(taskCB->event);
237 intSave = LOS_IntLock();
238 eventSave = eventCB->uwEventID;
239 LOS_IntRestore(intSave);
240
241 ret = LOS_EventClear(eventCB, ~events);
242 if (ret == LOS_OK) {
243 return (int32_t)eventSave;
244 } else {
245 return (int32_t)0x80000000;
246 }
247 }
248
249 osEvent osSignalWait(int32_t signals, uint32_t millisec)
250 {
251 UINT32 events;
252 UINT32 ret;
253 osEvent evt = {0};
254 UINT32 flags = 0;
255 LosTaskCB *runTask = NULL;
256
257 if (OS_INT_ACTIVE) {
258 evt.status = osErrorISR;
259 return evt;
260 }
261 if ((UINT32)signals & INVALID_EVENT_MASK) {
262 evt.status = osErrorValue;
263 return evt;
264 }
265
266 if (signals != 0) {
267 events = (UINT32)signals;
268 flags |= LOS_WAITMODE_AND;
269 } else {
270 events = VALID_EVENT_MASK;
271 flags |= LOS_WAITMODE_OR;
272 }
273
274
275 UINT32 tsk_id = LOS_CurTaskIDGet();
276 TSK_INFO_S tskInfo = {0};
277
278 ret = LOS_TaskInfoGet(tsk_id, &tskInfo);
279 if(ret != LOS_OK)
280 {
281 evt.status = osErrorValue;
282 TRACE(0, "%s=> %s %d ERROR==================(%s)\n", __FILE__, __func__, __LINE__, LOS_CurTaskNameGet());
283 return evt;
284 }
285 ret = LOS_EventRead(&(tskInfo.uwEvent), events, flags | LOS_WAITMODE_CLR, LOS_MS2Tick(millisec));
286 if (ret & LOS_ERRTYPE_ERROR) {
287 if (ret == LOS_ERRNO_EVENT_READ_TIMEOUT) {
288 evt.status = osEventTimeout;
289 } else {
290 evt.status = osErrorResource;
291 }
292 } else {
293 if (ret == 0) {
294 evt.status = osOK;
295 } else {
296 evt.status = osEventSignal;
297 evt.value.signals = (int32_t)ret;
298 }
299 }
300
301 return evt;
302 }
303 #endif
304
305
306 // Timer
osTimerCreate(const osTimerDef_t * timer_def,os_timer_type type,void * argument)307 osTimerId osTimerCreate (const osTimerDef_t *timer_def, os_timer_type type, void *argument) {
308
309 if (timer_def == NULL) {
310 return (osTimerId)NULL;
311 }
312 return osTimerNew((osTimerFunc_t)timer_def->ptimer, type, argument, &timer_def->attr);
313 }
314
315
316 // Mutex
osMutexCreate(const osMutexDef_t * mutex_def)317 osMutexId osMutexCreate (const osMutexDef_t *mutex_def) {
318
319 if (mutex_def == NULL) {
320 return (osMutexId)NULL;
321 }
322 return osMutexNew(mutex_def);
323 }
324
325
326 // Semaphore
327
osSemaphoreCreate(const osSemaphoreDef_t * semaphore_def,int32_t count)328 osSemaphoreId osSemaphoreCreate (const osSemaphoreDef_t *semaphore_def, int32_t count) {
329
330 if (semaphore_def == NULL) {
331 return (osSemaphoreId)NULL;
332 }
333 return osSemaphoreNew(osRtxSemaphoreTokenLimit, (uint32_t)count, semaphore_def);
334 }
335
osSemaphoreWait(osSemaphoreId semaphore_id,uint32_t millisec)336 int32_t osSemaphoreWait (osSemaphoreId semaphore_id, uint32_t millisec) {
337 osStatus_t status;
338 uint32_t count;
339
340 status = osSemaphoreAcquire(semaphore_id, millisec);
341 switch (status) {
342 case osOK:
343 count = osSemaphoreGetCount(semaphore_id);
344 return ((int32_t)count + 1);
345 case osErrorResource:
346 case osErrorTimeout:
347 return 0;
348 default:
349 break;
350 }
351 return -1;
352 }
353
354 #if 0
355 // Memory Pool
356 /**
357 * @ingroup los_membox
358 * Static memory pool information structure
359 */
360 typedef struct {
361 UINT32 uwBlkSize; /**< The memory block size of the static memory pool */
362 UINT32 uwBlkNum; /**< The total memory block number of the static memory pool */
363 UINT32 uwBlkCnt; /**< The number of allocated memory blocks in the static memory pool */
364 #ifdef LOSCFG_KERNEL_MEMBOX_STATIC
365 LOS_MEMBOX_NODE stFreeList; /**< The list of free memory block node in the static memory pool. This
366 structure member is available only LOSCFG_KERNEL_MEMBOX_STATIC is
367 defined. */
368 #endif
369 } LOS_MEMBOX_INFO;
370 #endif
371 #define LOS_MEMBOX_ALLIGNED(memAddr) (((UINTPTR)(memAddr) + sizeof(UINTPTR) - 1) & (~(sizeof(UINTPTR) - 1)))
372
373 /* internal function for osPool and osMail */
CreateAndInitMemBox(UINT32 blkNum,UINT32 blkSize)374 static void *CreateAndInitMemBox(UINT32 blkNum, UINT32 blkSize)
375 {
376 VOID *memBox = NULL;
377 UINT32 poolSize;
378 UINT32 ret;
379 UINT32 blkSizeAlign;
380
381 if ((blkNum == 0) || (blkSize == 0)) {
382 return NULL;
383 }
384
385 blkSizeAlign = LOS_MEMBOX_ALLIGNED(blkSize + OS_MEMBOX_NODE_HEAD_SIZE);
386 poolSize = blkSizeAlign * blkNum + sizeof(LOS_MEMBOX_INFO);
387 memBox = LOS_MemAlloc(m_aucSysMem0, poolSize);
388 if (memBox == NULL) {
389 return NULL;
390 }
391
392 ret = LOS_MemboxInit(memBox, poolSize, blkSize);
393 if (ret != LOS_OK) {
394 LOS_MemFree(m_aucSysMem0, memBox);
395 return NULL;
396 }
397
398 return memBox;
399 }
400
osPoolCreate(const osPoolDef_t * pool_def)401 osPoolId osPoolCreate(const osPoolDef_t *pool_def)
402 {
403 if ((pool_def == NULL) || OS_INT_ACTIVE) {
404 return NULL;
405 }
406
407 return (osPoolId)CreateAndInitMemBox(pool_def->pool_sz, pool_def->item_sz);
408 }
409
osPoolAlloc(osPoolId pool_id)410 void *osPoolAlloc(osPoolId pool_id)
411 {
412 if (pool_id == NULL) {
413 return NULL;
414 }
415
416 return LOS_MemboxAlloc(pool_id);
417 }
418
osPoolCAlloc(osPoolId pool_id)419 void *osPoolCAlloc(osPoolId pool_id)
420 {
421 void *ptr = NULL;
422
423 if (pool_id == NULL) {
424 return NULL;
425 }
426
427 ptr = LOS_MemboxAlloc(pool_id);
428 if (ptr != NULL) {
429 LOS_MemboxClr(pool_id, ptr);
430 }
431
432 return ptr;
433 }
434
osPoolFree(osPoolId pool_id,void * block)435 osStatus osPoolFree(osPoolId pool_id, void *block)
436 {
437 UINT32 ret;
438
439 if (pool_id == NULL) {
440 return osErrorParameter;
441 }
442
443 ret = LOS_MemboxFree(pool_id, block);
444 if (ret == LOS_OK) {
445 return osOK;
446 } else {
447 return osErrorValue;
448 }
449 }
450
osPoolDelete(osPoolId pool_id)451 osStatus osPoolDelete(osPoolId pool_id)
452 {
453 LOS_MEMBOX_INFO *memBox = (LOS_MEMBOX_INFO *)pool_id;
454 UINT32 ret;
455
456 if (memBox == NULL) {
457 return osErrorParameter;
458 }
459 if (OS_INT_ACTIVE) {
460 return osErrorISR;
461 }
462 if (memBox->uwBlkCnt != 0) {
463 return osErrorResource;
464 }
465
466 ret = LOS_MemFree(m_aucSysMem0, memBox);
467 if (ret == LOS_OK) {
468 return osOK;
469 } else {
470 return osErrorValue;
471 }
472 }
473
474
475 // Message Queue
476
osMessageCreate(const osMessageQDef_t * queue_def,osThreadId thread_id)477 osMessageQId osMessageCreate (const osMessageQDef_t *queue_def, osThreadId thread_id) {
478 (void)thread_id;
479
480 if (queue_def == NULL) {
481 return (osMessageQId)NULL;
482 }
483 return ((osMessageQId)(osMessageQueueNew(queue_def->queue_sz, sizeof(uint32_t), &queue_def->attr)));
484 }
485
osMessagePut(osMessageQId queue_id,uint32_t info,uint32_t millisec)486 osStatus osMessagePut (osMessageQId queue_id, uint32_t info, uint32_t millisec) {
487 return osMessageQueuePut((osMessageQueueId_t)queue_id, &info, 0U, millisec);
488 }
489
osMessageGet(osMessageQId queue_id,uint32_t millisec)490 osEvent osMessageGet (osMessageQId queue_id, uint32_t millisec) {
491 osStatus_t status;
492 osEvent event;
493 uint32_t message;
494
495 status = osMessageQueueGet((osMessageQueueId_t)queue_id, &message, NULL, millisec);
496 switch (status) {
497 case osOK:
498 event.status = osEventMessage;
499 event.value.v = message;
500 break;
501 case osErrorResource:
502 event.status = osOK;
503 break;
504 case osErrorTimeout:
505 event.status = osEventTimeout;
506 break;
507 default:
508 event.status = status;
509 break;
510 }
511 return event;
512 }
513
osMessageGetSpace(osMessageQId queue_id)514 uint32_t osMessageGetSpace (osMessageQId queue_id)
515 {
516 return osMessageQueueGetSpace(queue_id);
517 }
518
519
520
521 // Mail Queue
MappingQueueWriteRet(UINT32 ret)522 static inline osStatus MappingQueueWriteRet(UINT32 ret)
523 {
524 switch (ret) {
525 case LOS_OK:
526 return osOK;
527 case LOS_ERRNO_QUEUE_TIMEOUT:
528 case LOS_ERRNO_QUEUE_ISFULL:
529 return osErrorTimeoutResource;
530 case LOS_ERRNO_QUEUE_INVALID:
531 case LOS_ERRNO_QUEUE_NOT_CREATE:
532 case LOS_ERRNO_QUEUE_WRITE_PTR_NULL:
533 case LOS_ERRNO_QUEUE_WRITESIZE_ISZERO:
534 case LOS_ERRNO_QUEUE_WRITE_SIZE_TOO_BIG:
535 return osErrorParameter;
536 default:
537 return osErrorResource;
538 }
539 }
540
MappingQueueReadRet(UINT32 ret)541 static inline osStatus MappingQueueReadRet(UINT32 ret)
542 {
543 switch (ret) {
544 case LOS_OK:
545 return osEventMessage;
546 case LOS_ERRNO_QUEUE_TIMEOUT:
547 case LOS_ERRNO_QUEUE_ISEMPTY:
548 return osEventTimeout;
549 case LOS_ERRNO_QUEUE_INVALID:
550 case LOS_ERRNO_QUEUE_NOT_CREATE:
551 case LOS_ERRNO_QUEUE_READ_PTR_NULL:
552 case LOS_ERRNO_QUEUE_READ_SIZE_TOO_SMALL:
553 return osErrorParameter;
554 default:
555 return osErrorResource;
556 }
557 }
558
osMailCreate(const osMailQDef_t * queue_def,osThreadId thread_id)559 osMailQId osMailCreate(const osMailQDef_t *queue_def, osThreadId thread_id)
560 {
561 (VOID)thread_id;
562 UINT32 ret;
563 UINT32 queueId;
564 struct osMailQ *mailQ = NULL;
565
566 if ((queue_def == NULL) || (queue_def->pool == NULL) || OS_INT_ACTIVE) {
567 return NULL;
568 }
569
570 ret = LOS_QueueCreate(NULL, (UINT16)(queue_def->queue_sz), &queueId, 0, sizeof(UINT32));
571 if (ret != LOS_OK) {
572 return NULL;
573 }
574
575 mailQ = (struct osMailQ *)(queue_def->pool);
576 mailQ->pool = CreateAndInitMemBox(queue_def->queue_sz, queue_def->item_sz);
577 if (mailQ->pool == NULL) {
578 LOS_QueueDelete(queueId);
579 return NULL;
580 }
581
582 mailQ->queue = queueId;
583 return (osMailQId)mailQ;
584 }
585
osMailAlloc(osMailQId queue_id,uint32_t millisec)586 void *osMailAlloc(osMailQId queue_id, uint32_t millisec)
587 {
588 struct osMailQ *mailQ = (struct osMailQ *)queue_id;
589 if (mailQ == NULL) {
590 return NULL;
591 }
592
593 return OsQueueMailAlloc(mailQ->queue, mailQ->pool, LOS_MS2Tick(millisec));
594 }
595
osMailCAlloc(osMailQId queue_id,uint32_t millisec)596 void *osMailCAlloc(osMailQId queue_id, uint32_t millisec)
597 {
598 struct osMailQ *mailQ = (struct osMailQ *)queue_id;
599 void *mem = NULL;
600
601 mem = osMailAlloc(queue_id, millisec);
602 if (mem != NULL) {
603 LOS_MemboxClr(mailQ->pool, mem);
604 }
605
606 return mem;
607 }
608
osMailFree(osMailQId queue_id,void * mail)609 osStatus osMailFree(osMailQId queue_id, void *mail)
610 {
611 struct osMailQ *mailQ = (struct osMailQ *)queue_id;
612 UINT32 ret;
613
614 if (mailQ == NULL) {
615 return osErrorParameter;
616 }
617
618 ret = OsQueueMailFree(mailQ->queue, mailQ->pool, mail);
619 if (ret == LOS_OK) {
620 return osOK;
621 } else if (ret == LOS_ERRNO_QUEUE_MAIL_FREE_ERROR) {
622 return osErrorValue;
623 } else {
624 return osErrorParameter;
625 }
626 }
627
osMailPutHead(osMailQId queue_id,void * mail)628 osStatus osMailPutHead(osMailQId queue_id, void *mail)
629 {
630 struct osMailQ *mailQ = (struct osMailQ *)queue_id;
631 UINT32 ret;
632
633 if (mailQ == NULL) {
634 return osErrorParameter;
635 }
636 if (mail == NULL) {
637 return osErrorValue;
638 }
639
640 ret = LOS_QueueWriteHead(mailQ->queue, mail, sizeof(UINT32), 0);
641 return MappingQueueWriteRet(ret);
642 }
643
osMailPut(osMailQId queue_id,const void * mail)644 osStatus osMailPut(osMailQId queue_id, const void *mail)
645 {
646 struct osMailQ *mailQ = (struct osMailQ *)queue_id;
647 UINT32 ret;
648
649 if (mailQ == NULL) {
650 return osErrorParameter;
651 }
652 if (mail == NULL) {
653 return osErrorValue;
654 }
655
656 ret = LOS_QueueWrite(mailQ->queue, (void *)mail, sizeof(UINT32), 0);
657 return MappingQueueWriteRet(ret);
658 }
659
osMailGet(osMailQId queue_id,uint32_t millisec)660 osEvent osMailGet(osMailQId queue_id, uint32_t millisec)
661 {
662 struct osMailQ *mailQ = (struct osMailQ *)queue_id;
663 osEvent event = {0};
664 osStatus status;
665 UINT32 ret;
666
667 if ((mailQ == NULL) || (OS_INT_ACTIVE && (millisec != 0))) {
668 event.status = osErrorParameter;
669 return event;
670 }
671
672 ret = LOS_QueueRead(mailQ->queue, &(event.value.p), sizeof(UINT32), LOS_MS2Tick(millisec));
673 status = MappingQueueReadRet(ret);
674 event.status = (status == osEventMessage) ? osEventMail : status;
675 return event;
676 }
677
osMailClear(osMailQId queue_id)678 osStatus osMailClear(osMailQId queue_id)
679 {
680 osEvent evt;
681 UINTPTR intSave;
682 intSave = LOS_IntLock();
683 while (1) {
684 evt = osMailGet(queue_id, 0);
685 if (evt.status == osEventMail) {
686 (VOID)osMailFree(queue_id, evt.value.p);
687 } else if (evt.status == osEventTimeout) {
688 LOS_IntRestore(intSave);
689 return osOK;
690 } else {
691 LOS_IntRestore(intSave);
692 return evt.status;
693 }
694 }
695 }
696
osMailDelete(osMailQId queue_id)697 osStatus osMailDelete(osMailQId queue_id)
698 {
699 struct osMailQ *mailQ = (struct osMailQ *)queue_id;
700 osStatus ret1;
701 UINT32 ret2;
702
703 if (mailQ == NULL) {
704 return osErrorParameter;
705 }
706 if (OS_INT_ACTIVE) {
707 return osErrorISR;
708 }
709
710 ret1 = osPoolDelete(mailQ->pool);
711 ret2 = LOS_QueueDelete(mailQ->queue);
712 if ((ret1 == osOK) && (ret2 == LOS_OK)) {
713 return osOK;
714 } else {
715 return osErrorOS;
716 }
717 }
718
osMailGetCount(osMailQId queue_id)719 uint32_t osMailGetCount (osMailQId queue_id) {
720 struct osMailQ *mailQ = (struct osMailQ *)queue_id;
721 QUEUE_INFO_S queueInfo;
722
723 if (mailQ == NULL) {
724 return 0;
725 }
726
727 if (LOS_OK == LOS_QueueInfoGet(mailQ->queue, &queueInfo)) {
728 return queueInfo.readableCnt;
729 } else
730 return 0;
731 }
732
osThreadExitPub(void)733 void osThreadExitPub (void) {
734 osThreadExit();
735 }
736
osGetThreadIntId(void)737 int osGetThreadIntId (void) {
738 #if 1 // compatibility with posix thread or los thread
739 LosTaskCB *pstTaskCB = NULL;
740
741 pstTaskCB = g_losTask.runTask;
742
743 if (pstTaskCB)
744 return pstTaskCB->taskID;
745 else
746 return -1;
747 #else
748 osThreadId thread_id = osThreadGetId();
749 if (thread_id)
750 return thread_id->tid;
751 return -1;
752 #endif
753 }
754
task_idle_health_check(void)755 int task_idle_health_check(void)
756 {
757 return 0;
758 }
759