19c6d7c21Sopenharmony_ci/* 29c6d7c21Sopenharmony_ci * Copyright (c) 2020 Huawei Device Co., Ltd. 39c6d7c21Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 49c6d7c21Sopenharmony_ci * you may not use this file except in compliance with the License. 59c6d7c21Sopenharmony_ci * You may obtain a copy of the License at 69c6d7c21Sopenharmony_ci * 79c6d7c21Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 89c6d7c21Sopenharmony_ci * 99c6d7c21Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 109c6d7c21Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 119c6d7c21Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 129c6d7c21Sopenharmony_ci * See the License for the specific language governing permissions and 139c6d7c21Sopenharmony_ci * limitations under the License. 149c6d7c21Sopenharmony_ci */ 159c6d7c21Sopenharmony_ci#include "queue_adapter.h" 169c6d7c21Sopenharmony_ci#include <cmsis_os.h> 179c6d7c21Sopenharmony_ci#include <ohos_types.h> 189c6d7c21Sopenharmony_ci#include <ohos_errno.h> 199c6d7c21Sopenharmony_ci 209c6d7c21Sopenharmony_ciMQueueId QUEUE_Create(const char *name, int size, int count) 219c6d7c21Sopenharmony_ci{ 229c6d7c21Sopenharmony_ci osMessageQueueAttr_t queueAttr = {name, 0, NULL, 0, NULL, 0}; 239c6d7c21Sopenharmony_ci return (MQueueId)osMessageQueueNew(count, size, &queueAttr); 249c6d7c21Sopenharmony_ci} 259c6d7c21Sopenharmony_ci 269c6d7c21Sopenharmony_ciint QUEUE_Put(MQueueId queueId, const void *element, uint8 pri, int timeout) 279c6d7c21Sopenharmony_ci{ 289c6d7c21Sopenharmony_ci uint32_t waitTime = (timeout <= 0) ? 0 : (uint32_t)timeout; 299c6d7c21Sopenharmony_ci osStatus_t ret = osMessageQueuePut(queueId, element, pri, waitTime); 309c6d7c21Sopenharmony_ci if (ret != osOK) { 319c6d7c21Sopenharmony_ci return EC_BUSBUSY; 329c6d7c21Sopenharmony_ci } 339c6d7c21Sopenharmony_ci return EC_SUCCESS; 349c6d7c21Sopenharmony_ci} 359c6d7c21Sopenharmony_ci 369c6d7c21Sopenharmony_ciint QUEUE_Pop(MQueueId queueId, void *element, uint8 *pri, int timeout) 379c6d7c21Sopenharmony_ci{ 389c6d7c21Sopenharmony_ci uint32_t waitTime = (timeout <= 0) ? osWaitForever : (uint32_t)timeout; 399c6d7c21Sopenharmony_ci osStatus_t evt = osMessageQueueGet(queueId, element, pri, waitTime); 409c6d7c21Sopenharmony_ci if (evt != osOK) { 419c6d7c21Sopenharmony_ci return EC_BUSBUSY; 429c6d7c21Sopenharmony_ci } 439c6d7c21Sopenharmony_ci return EC_SUCCESS; 449c6d7c21Sopenharmony_ci} 459c6d7c21Sopenharmony_ci 469c6d7c21Sopenharmony_ciint QUEUE_Destroy(MQueueId queueId) 479c6d7c21Sopenharmony_ci{ 489c6d7c21Sopenharmony_ci osStatus_t evt = osMessageQueueDelete(queueId); 499c6d7c21Sopenharmony_ci if (evt != osOK) { 509c6d7c21Sopenharmony_ci return EC_FAILURE; 519c6d7c21Sopenharmony_ci } 529c6d7c21Sopenharmony_ci return EC_SUCCESS; 539c6d7c21Sopenharmony_ci}