📄 ssp_que.c
字号:
#ifdef __cplusplusextern "C"{#endif #include "syscfg.h"#include "sys/sys_pub.h"#include "aos.h"#include "ssp_que.h"MSG_QUE_S *g_pstMque;U32 m_mque_init(){ U32 idx; g_pstMque = (MSG_QUE_S*)aos_smem_alloc( MPE_SYS, SID_MQ, sizeof( MSG_QUE_S)*CONFIG_QUE_NUM ); if( NULL == g_pstMque ) { return QUE_MOD_INIT_FAIL; } for( idx=0; idx < CONFIG_QUE_NUM; idx++ ) { g_pstMque[idx].status = QUE_CB_FREE; g_pstMque[idx].name[0]= '\0'; g_pstMque[idx].sys_mq = (SYS_MQD_T)-1; } return AOS_SUCC;}U32 aos_mq_create( S8 name[AOS_NAME_LEN+1], U32 flags, U32 ulMaxMsg, U32 ulMsgSize, U32*pulMqId ){ U32 idx,lockKey; MSG_QUE_S *pMque; if( NULL == pulMqId ) { return QUE_INVALID_POINTER_PARA; } lockKey = aos_int_lock(); for( idx=0; idx < CONFIG_QUE_NUM; idx++ ) { if( QUE_CB_FREE == g_pstMque[idx].status ) { break; } } if( idx >= CONFIG_QUE_NUM ) { aos_int_unlock(lockKey); *pulMqId = U32_BUTT; return QUE_CREATE_NOMEM; } pMque = &g_pstMque[idx]; pMque->status = QUE_CB_USED; aos_int_unlock(lockKey); if( AOS_SUCC != sys_mq_create( name, flags, ulMaxMsg, ulMsgSize, &pMque->sys_mq ) ) { lockKey = aos_int_lock(); pMque->status = QUE_CB_FREE; aos_int_unlock(lockKey); *pulMqId = U32_BUTT; return QUE_SYS_CREATE_FAIL; } lockKey = aos_int_lock(); aos_strncpy( pMque->name, name, AOS_NAME_LEN ); aos_int_unlock(lockKey); *pulMqId = idx; return AOS_SUCC; }U32 aos_mq_cancel( U32 ulMqId ){ U32 lockKey, result; MSG_QUE_S *pMque; lockKey = aos_int_lock(); if( (ulMqId >= CONFIG_QUE_NUM) || (QUE_CB_USED != g_pstMque[ulMqId].status) ) { aos_int_unlock(lockKey); return QUE_INVALID_QUE_ID; } pMque = &g_pstMque[ulMqId]; aos_int_unlock(lockKey); result = sys_mq_cancel( pMque->sys_mq ); QUE_CONVERT_ERRNO(result); if( AOS_SUCC != result ) { return result; } lockKey = aos_int_lock(); pMque->status = QUE_CB_FREE; pMque->name[0]= '\0'; pMque->sys_mq = (SYS_MQD_T)-1; aos_int_unlock(lockKey); return AOS_SUCC;}U32 aos_mq_send( U32 ulMqId, U8 *pMsgPtr, U32 ulMsgLen, U32 ulTimeOut ){ U32 lockKey, result; MSG_QUE_S *pMque; lockKey = aos_int_lock(); if( (ulMqId >= CONFIG_QUE_NUM) || (QUE_CB_USED != g_pstMque[ulMqId].status) ) { aos_int_unlock(lockKey); return QUE_INVALID_QUE_ID; } pMque = &g_pstMque[ulMqId]; aos_int_unlock(lockKey); result = sys_mq_send( pMque->sys_mq, pMsgPtr, ulMsgLen, ulTimeOut ); QUE_CONVERT_ERRNO(result); return result;}U32 aos_mq_receive( U32 ulMqId, U8 *pMsgPtr, U32 ulMsgLen, U32 ulTimeOut ){ U32 lockKey, ret; MSG_QUE_S *pMque; lockKey = aos_int_lock(); if( (ulMqId >= CONFIG_QUE_NUM) || (QUE_CB_USED != g_pstMque[ulMqId].status) ) { aos_int_unlock(lockKey); return U32_BUTT; } pMque = &g_pstMque[ulMqId]; aos_int_unlock(lockKey); ret = sys_mq_receive( pMque->sys_mq, pMsgPtr, ulMsgLen, ulTimeOut ); return ret;}U32 aos_mq_trysend( U32 ulMqId, U8 *pMsgPtr, U32 ulMsgLen ){ U32 lockKey, result; MSG_QUE_S *pMque; lockKey = aos_int_lock(); if( (ulMqId >= CONFIG_QUE_NUM) || (QUE_CB_USED != g_pstMque[ulMqId].status) ) { aos_int_unlock(lockKey); return QUE_INVALID_QUE_ID; } pMque = &g_pstMque[ulMqId]; aos_int_unlock(lockKey); result = sys_mq_trysend( pMque->sys_mq, pMsgPtr, ulMsgLen ); QUE_CONVERT_ERRNO(result); return result;}U32 aos_mq_tryreceive( U32 ulMqId , U8 *pMsgPtr, U32 ulMsgLen ){ U32 lockKey, ret; MSG_QUE_S *pMque; lockKey = aos_int_lock(); if( (ulMqId >= CONFIG_QUE_NUM) || (QUE_CB_USED != g_pstMque[ulMqId].status) ) { aos_int_unlock(lockKey); return U32_BUTT; } pMque = &g_pstMque[ulMqId]; aos_int_unlock(lockKey); ret = sys_mq_tryreceive( pMque->sys_mq, pMsgPtr, ulMsgLen ); return ret;}U32 aos_mq_curmsgs( U32 ulMqId ){ U32 lockKey; MSG_QUE_S *pMque; lockKey = aos_int_lock(); if( (ulMqId >= CONFIG_QUE_NUM) || (QUE_CB_USED != g_pstMque[ulMqId].status) ) { aos_int_unlock(lockKey); return U32_BUTT; } pMque = &g_pstMque[ulMqId]; aos_int_unlock(lockKey); return sys_mq_curmsgs( pMque->sys_mq );}U32 aos_mq_info( U32 ulMqId, U32 *pFlags, U32 *pulMaxMsg, U32 *pulMsgSize){ U32 lockKey; MSG_QUE_S *pMque; lockKey = aos_int_lock(); if( (ulMqId >= CONFIG_QUE_NUM) || (QUE_CB_USED != g_pstMque[ulMqId].status) ) { aos_int_unlock(lockKey); return QUE_INVALID_QUE_ID; } if((pFlags == (U32 *)NULL) || (pulMaxMsg == (U32 *)NULL) || (pulMsgSize == (U32 *)NULL)) { aos_int_unlock(lockKey); return QUE_INVALID_POINTER_PARA; } pMque = &g_pstMque[ulMqId]; aos_int_unlock(lockKey); return sys_mq_info( pMque->sys_mq, pFlags, pulMaxMsg, pulMsgSize);}#ifdef __cplusplus}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -