⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ssp_msg.c

📁 abstract rtos
💻 C
📖 第 1 页 / 共 2 页
字号:
#include "syscfg.h"#ifdef __cplusplusextern "C"{#endif #include "sys/sys_pub.h"#include "aos.h"#include "ssp_event.h"#include "ssp_task.h"#include "ssp_msg.h"#include "ssp_cputick.h"#include "ssp_spy.h"MPS_S *g_pstMpset       = NULL;MPE_S *g_pstMpe         = NULL;U32    g_MsgLock        = U32_BUTT;U32    m_ulMsgEnable    = FALSE;U32    g_LastHandleTaskId     = U32_BUTT;#if (CONFIG_BOARD_EIA == TRUE) U32 load_clear_rollback_flag(VOID);#endifextern int printf(char *fmt,...);U32 m_msg_init(  ){    MPS mps;    MPE mpe;    U32 result;        g_pstMpset = (MPS_S*)aos_smem_alloc(MPE_SYS, SID_MPS, sizeof(MPS_S)*MPS_BUTT );    if( NULL == g_pstMpset )    {        return MSG_INIT_NO_MEM;    }    g_pstMpe = (MPE_S*)aos_smem_alloc(MPE_SYS, SID_MPE, sizeof(MPE_S)*MPE_BUTT );    if( NULL == g_pstMpset )    {        return MSG_INIT_NO_MEM;    }    result = aos_sem_create("_msglck", AOS_FIFO, 1, &g_MsgLock);    if( AOS_SUCC != result )    {        return result;    }    for( mps=0; mps < MPS_BUTT; mps++ )    {        U32 que_idx;                g_pstMpset[mps].status       = FALSE;        g_pstMpset[mps].name[0]      = '\0';        g_pstMpset[mps].task_prio    = TASK_PRIO_BUTT;                g_pstMpset[mps].task_id      = U32_BUTT;        for( que_idx=0; que_idx<MSG_PRIO_BUTT; que_idx++ )        {            if( MPS_SS7 == mps && MSG_PRIO_NORMAL == que_idx )            {                msg_lock_que_init( &g_pstMpset[mps].msg_que[que_idx] );            }            else            {                msg_que_init( &g_pstMpset[mps].msg_que[que_idx] );            }        }    }    for( mpe=0; mpe < MPE_BUTT; mpe++ )    {        g_pstMpe[mpe].status      = FALSE;        g_pstMpe[mpe].print_flag  = FALSE;        g_pstMpe[mpe].name[0]     = '\0';        g_pstMpe[mpe].mps         = U32_BUTT;                g_pstMpe[mpe].init        = (MPE_INIT_ROUTINE)NULL;        g_pstMpe[mpe].run         = (MPE_RUN_ROUTINE)NULL;        g_pstMpe[mpe].msg_handling= 0;        g_pstMpe[mpe].message_cnt = 0;            }        return AOS_SUCC;}VOID* aos_msg_alloc_x( MPE mpe, U32 ulSize, S8 *pszFile, U32 ulLine ){    MSG_HEAD_S *pNewMsgBuf;        if( (0 == ulSize) || (mpe >= MPE_BUTT) )    {        return NULL;    }    if(pszFile == NULL)    {        return NULL;    }        pNewMsgBuf = (MSG_HEAD_S*)aos_dmem_alloc_x(mpe, SID_MSG,                                                ulSize + sizeof( MSG_HEAD_S),                                               pszFile, ulLine);    if( NULL == pNewMsgBuf )    {        return NULL;    }    pNewMsgBuf->srcProcessorId = LOCAL_PROCESSOR_ID;    pNewMsgBuf->srcMpe         = mpe;    pNewMsgBuf->ulSize         = ulSize;    pNewMsgBuf->status         = MSG_ALLOCATED;        return pNewMsgBuf->msg;    }U32 aos_msg_free( VOID *pvMsgBuf ){    MSG_HEAD_S *pFreeMsgBuf;        if( NULL == pvMsgBuf )    {        return MSG_INVALID;    }    pFreeMsgBuf = (MSG_HEAD_S*)((U32)pvMsgBuf - ELEMENT_OFFSET(MSG_HEAD_S,msg));    if( NULL == pFreeMsgBuf )    {        return MSG_INVALID;    }    if( MSG_ALLOCATED != pFreeMsgBuf->status )    {        if (MSG_SENDED == pFreeMsgBuf->status )        {            aos_printf( MPE_SYS, "free a message after send, msg_ptr=0x%x\r\n", pvMsgBuf );        }        else if ( MSG_RECEIVED == pFreeMsgBuf->status )        {            aos_printf( MPE_SYS, "free a message being processed, msg_ptr=0x%x\r\n", pvMsgBuf );        }        else if ( MSG_STATUS_NULL == pFreeMsgBuf->status )        {            aos_printf( MPE_SYS, "refree a message, msg_ptr=0x%x\r\n", pvMsgBuf );        }        else        {            aos_printf( MPE_SYS, "free a non-allocated message, msg_ptr=0x%x\r\n", pvMsgBuf );                    }                return MSG_FREE_NOT_ALLOCATED;    }    pFreeMsgBuf->status = MSG_STATUS_NULL;    return aos_dmem_free((VOID*)pFreeMsgBuf);}U32 aos_msg_send( MSG_S *msg ){    return ssp_msg_send( msg, DL_DATA_REQUEST );}U32 aos_msg_trysend( MSG_S *msg ){    return ssp_msg_send( msg, DL_UNIT_DATA_REQUEST );}U32 aos_mps_reg( S8 name[AOS_NAME_LEN+1], MPS mps, TASK_PRIO msgTskPrio ){    MPS_S *pMpset;        if( mps >= MPS_BUTT )    {        return MSG_MPS_INVALID;    }    if( msgTskPrio >= TASK_PRIO_BUTT )    {         return MSG_MPS_PRIO_INVALID;    }    pMpset = &g_pstMpset[mps];    if( TRUE == pMpset->status )    {        return MSG_MPS_EXIST;    }    pMpset->status       = TRUE;    pMpset->task_prio    = msgTskPrio;    aos_strncpy( pMpset->name, name, AOS_NAME_LEN );        return AOS_SUCC;}U32 aos_mpe_reg( S8 name[AOS_NAME_LEN+1],                 MPE mpe,                 MPS mps,                 MPE_INIT_ROUTINE initRtn,                 MPE_RUN_ROUTINE runRtn ){    MPE_S *pMpe;    MPS_S *pMpset;        if( mpe >= MPE_BUTT )    {        return MSG_MPE_INVALID;    }    if( mps >= MPS_BUTT )    {        return MSG_MPS_INVALID;    }    pMpset = &g_pstMpset[mps];    if( FALSE == pMpset->status )    {        return MSG_MPS_INVALID;    }    pMpe = &g_pstMpe[mpe];    if( TRUE == pMpe->status )    {        return MSG_MPE_EXIST;    }    pMpe->status = TRUE;#if( CONFIG_VERSION_DEBUG == TRUE )    pMpe->print_flag = FALSE;#else    pMpe->print_flag = FALSE;#endif    if(MPE_SYS == mpe || MPE_DEBUG == mpe || MPE_MM == mpe)    {        pMpe->print_flag = TRUE;    }    pMpe->mps    = mps;    pMpe->init   = initRtn;    pMpe->run    = runRtn;    aos_strncpy( pMpe->name, name, AOS_NAME_LEN );        return AOS_SUCC;}U32 aos_mps_name(MPS mps, S8 * szName){    U32 i;    if(szName == NULL)    {        return AOS_FAIL;    }    if((mps > MPS_BUTT) || (g_pstMpset[mps].status != TRUE))    {        aos_sprintf(szName,"unknown");        return AOS_SUCC;    }    for(i = 0; i < AOS_NAME_LEN;i++)    {        szName[i] = (S8)(g_pstMpset[mps].name[i]);    }    szName[i] = '\0';    return AOS_SUCC;}U32 aos_mpe_name(MPE mpe, S8 * szName){    U32 i;    if(szName == NULL)    {        return AOS_FAIL;    }    if((mpe > MPE_BUTT) || (g_pstMpe[mpe].status != TRUE))    {        aos_sprintf(szName,"unknown");        return AOS_FAIL;    }    for(i = 0; i < AOS_NAME_LEN;i++)    {        szName[i] = (S8)(g_pstMpe[mpe].name[i]);    }    szName[i] = '\0';    return AOS_SUCC;}VOID aos_msg_send2( VOID *pvMsg ){    struct msg_blk *mb;    L3_MSG_HEAD_S *pMsg = (L3_MSG_HEAD_S*)pvMsg;        if( NULL == pMsg )    {        return;    }    if( (pMsg->dstMpe >= MPE_BUTT)   ||        (FALSE == g_pstMpe[pMsg->dstMpe].status) )    {        aos_msg_free( pMsg->msg );        return;    }    mb = msg_alloc();    if(NULL == mb )    {        aos_msg_free( pMsg->msg );        return;    }    mb->head    = mem_obj_head(pMsg);    mb->truelen = mem_obj_size(pMsg);    mb->end     = mb->head + mb->truelen;    mb->data    = (U8*)pMsg;    mb->len     = pMsg->ulSize + ELEMENT_OFFSET(L3_MSG_HEAD_S, msg);    mb->tail    = mb->data + mb->len;            MSG_QUE_SEND( pMsg->dstMpe, mb, MSG_PRIO_NORMAL );}VOID aos_msg_send3( struct msg_blk *mb, MPE srcMpe, MPE dstMpe ){    L3_MSG_HEAD_S *pL3Msg;        if( NULL == mb )    {        AOS_ASSERT(0);        return;    }    if( (dstMpe >= MPE_BUTT)   ||        (FALSE == g_pstMpe[dstMpe].status) )    {        aos_dmem_free( mb->head );        msg_free( mb );        return;    }        pL3Msg = (L3_MSG_HEAD_S*)msg_push( mb, L3_MSG_HEAD_LEN );    pL3Msg->srcProcessorId = LOCAL_PROCESSOR_ID;    pL3Msg->srcMpe         = srcMpe;    pL3Msg->dstProcessorId = LOCAL_PROCESSOR_ID;    pL3Msg->dstMpe         = dstMpe;        pL3Msg->ulSize         = mb->len - L3_MSG_HEAD_LEN;            MSG_QUE_SEND( dstMpe, mb, MSG_PRIO_NORMAL );}VOID ssp_show_mpe(){    MPS mps;    MPE mpe;    aos_printf( MPE_DEBUG, "Show mps information" );    for( mps=0; mps < MPS_BUTT; mps++ )    {        if( TRUE == g_pstMpset[mps].status )        {            aos_printf( MPE_DEBUG, "mps=%3d,tsk_prio=%2d,tsk_id=%2d,high_msg=%4d,normal_msg=%4d,name=%s,",                        mps, g_pstMpset[mps].task_prio,g_pstMpset[mps].task_id,                        g_pstMpset[mps].msg_que[0].qlen,                        g_pstMpset[mps].msg_que[1].qlen,                        g_pstMpset[mps].name );        }    }    aos_printf( MPE_DEBUG, "Show mpe information" );    for( mpe=0; mpe < MPE_BUTT; mpe++ )    {        if( TRUE == g_pstMpe[mpe].status )        {            aos_printf( MPE_DEBUG, "mpe=%3d,parent mps=%2d,name=%s",                        mpe,g_pstMpe[mpe].mps,g_pstMpe[mpe].name );        }    }}U32 ssp_mpe_verify( MPE mpe ){    if( mpe >= MPE_BUTT )    {        return MSG_MPE_INVALID;    }    if( FALSE == g_pstMpe[mpe].status )    {        return MSG_MPE_INVALID;    }    return AOS_SUCC;}U32 ssp_mpe_msg_verify( MPE mpe ){    MPS mps;        if( mpe >= MPE_BUTT )    {        return MSG_MPE_INVALID;    }    if( FALSE == g_pstMpe[mpe].status )    {        return MSG_MPE_INVALID;    }    mps = g_pstMpe[mpe].mps;    if( mps >= MPS_BUTT )    {        return MSG_MPS_INVALID;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -