• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *   Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
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  * Description: msgqueue
15  *
16  * Create: 2021-12-16
17  */
18 
19 #include <los_queue.h>
20 #include "soc_osal.h"
21 #include "osal_errno.h"
22 #include "osal_inner.h"
23 
24 #define OSAL_INVALID_MSG_NUM 0xFFFFFFFF
25 
26 #ifndef TINY_KERNEL
osal_msg_queue_create(const char * name,unsigned short queue_len,unsigned long * queue_id,unsigned int flags,unsigned short max_msgsize)27 int osal_msg_queue_create(const char *name, unsigned short queue_len, unsigned long *queue_id,
28     unsigned int flags, unsigned short max_msgsize)
29 {
30     unsigned int ret = LOS_QueueCreate(name, queue_len, (unsigned int *)queue_id, flags, max_msgsize);
31     if (ret != LOS_OK) {
32         osal_log("LOS_QueueCreate failed! ret = %#x.\n", ret);
33         return OSAL_FAILURE;
34     }
35     if (name != NULL && queue_id != NULL) {
36         osal_log("qName:%s qID=0x%x \r\n", name, *queue_id);
37     }
38     return (int)ret;
39 }
40 #endif
41 
osal_msg_queue_write_copy(unsigned long queue_id,void * buffer_addr,unsigned int buffer_size,unsigned int timeout)42 int osal_msg_queue_write_copy(unsigned long queue_id, void *buffer_addr, unsigned int buffer_size, unsigned int timeout)
43 {
44     unsigned int ret = LOS_QueueWriteCopy(queue_id, buffer_addr, buffer_size, timeout);
45     if (ret != LOS_OK) {
46         osal_log("LOS_QueueWriteCopy failed! ret = %#x.qID=0x%x\n", ret, queue_id);
47         return OSAL_FAILURE;
48     }
49     return (int)ret;
50 }
51 
osal_msg_queue_write_head_copy(unsigned long queue_id,void * buffer_addr,unsigned int buffer_size,unsigned int timeout)52 int osal_msg_queue_write_head_copy(unsigned long queue_id, void *buffer_addr, unsigned int buffer_size,
53     unsigned int timeout)
54 {
55     unsigned int ret = LOS_QueueWriteHeadCopy(queue_id, buffer_addr, buffer_size, timeout);
56     if (ret != LOS_OK) {
57         osal_log("LOS_QueueWriteHeadCopy failed! ret = %#x.qID=0x%x\n", ret, queue_id);
58         return OSAL_FAILURE;
59     }
60     return (int)ret;
61 }
62 
osal_msg_queue_read_copy(unsigned long queue_id,void * buffer_addr,unsigned int * buffer_size,unsigned int timeout)63 int osal_msg_queue_read_copy(unsigned long queue_id, void *buffer_addr, unsigned int *buffer_size, unsigned int timeout)
64 {
65     unsigned int ret = LOS_QueueReadCopy(queue_id, buffer_addr, buffer_size, timeout);
66     if (ret != LOS_OK) {
67         return OSAL_FAILURE;
68     }
69     return OSAL_SUCCESS;
70 }
71 
osal_msg_queue_delete(unsigned long queue_id)72 void osal_msg_queue_delete(unsigned long queue_id)
73 {
74     unsigned int ret = LOS_QueueDelete(queue_id);
75     if (ret != LOS_OK) {
76         osal_log("LOS_QueueDelete failed! ret = %#x.\n", ret);
77     }
78 }
79 
osal_msg_queue_is_full(unsigned long queue_id)80 int osal_msg_queue_is_full(unsigned long queue_id)
81 {
82     QUEUE_INFO_S q_inf = { 0 };
83     unsigned int ret;
84 
85     ret = LOS_QueueInfoGet(queue_id, &q_inf);
86     if (ret != OSAL_SUCCESS) {
87         return TRUE;
88     }
89 
90 #ifndef CONFIG_SEC_CORE
91     return q_inf.usReadableCnt == q_inf.usQueueLen;
92 #else
93     return q_inf.info.readWriteableCnt[0] == q_inf.info.queueLen;
94 #endif
95 }
96 
osal_msg_queue_get_msg_num(unsigned long queue_id)97 unsigned int osal_msg_queue_get_msg_num(unsigned long queue_id)
98 {
99     QUEUE_INFO_S q_inf = { 0 };
100     unsigned int ret;
101 
102     ret = LOS_QueueInfoGet(queue_id, &q_inf);
103     if (ret != OSAL_SUCCESS) {
104         return OSAL_INVALID_MSG_NUM;
105     }
106 
107 #ifndef CONFIG_SEC_CORE
108     return q_inf.usReadableCnt;
109 #else
110     return q_inf.info.readWriteableCnt[0];
111 #endif
112 }
113