UINT32 Example_StaticMem(VOID) { UINT32 *p_num = NULL; UINT32 uwBlkSize = 3, uwBoxSize = 48; UINT32 uwRet; uwRet = LOS_MemboxInit(&pBoxMem[0], uwBoxSize, uwBlkSize); if (uwRet != LOS_OK) { dprintf("Mem box init failed\n"); return LOS_NOK; } else { dprintf("Mem box init ok!\n"); } /* membox alloc */ p_num = (UINT32*)LOS_MemboxAlloc(pBoxMem); if (NULL == p_num) { dprintf("Mem box alloc failed!\n"); return LOS_NOK; } dprintf("Mem box alloc ok\n"); /* assignment */ *p_num = 828; dprintf("*p_num = %d\n", *p_num); /* clear mem context */ LOS_MemboxClr(pBoxMem, p_num); dprintf("clear data ok\n *p_num = %d\n", *p_num); /* membox free */ uwRet = LOS_MemboxFree(pBoxMem, p_num); if (LOS_OK == uwRet) { dprintf("Mem box free ok!\n"); uwRet = LOS_InspectStatusSetByID(LOS_INSPECT_SMEM, LOS_INSPECT_STU_SUCCESS); if (LOS_OK != uwRet) { dprintf("Set Inspect Status Err\n"); } } else { dprintf("Mem box free failed!\n"); uwRet = LOS_InspectStatusSetByID(LOS_INSPECT_SMEM, LOS_INSPECT_STU_ERROR); if (LOS_OK != uwRet) { dprintf("Set Inspect Status Err\n"); } } return LOS_OK; }
/*任务2接收数据*/ static void *recv_Entry(UINT32 uwParam1, UINT32 uwParam2, UINT32 uwParam3, UINT32 uwParam4) { UINT32 uwReadbuf; UINT32 uwRet = LOS_OK; UINT32 uwMsgCount = 0; while (1) { /*读取队列里的数据存入uwReadbuf里*/ uwRet = LOS_QueueRead(g_uwQueue, &uwReadbuf, 24, 0); if(uwRet != LOS_OK) { dprintf("recv message failure,error:%x\n",uwRet); break; } else { dprintf("recv message:%s\n", (char *)uwReadbuf); uwMsgCount++; } (void)LOS_TaskDelay(5); } /*删除队列*/ while (LOS_OK != LOS_QueueDelete(g_uwQueue)) { (void)LOS_TaskDelay(1); } dprintf("delete the queue success!\n"); if(API_MSG_NUM == uwMsgCount) { uwRet = LOS_InspectStatusSetByID(LOS_INSPECT_MSG,LOS_INSPECT_STU_SUCCESS); if (LOS_OK != uwRet) { dprintf("Set Inspect Status Err\n"); } } else { uwRet = LOS_InspectStatusSetByID(LOS_INSPECT_MSG,LOS_INSPECT_STU_ERROR); if (LOS_OK != uwRet) { dprintf("Set Inspect Status Err\n"); } } return NULL; }
static VOID Example_SemTask1(VOID) { UINT32 uwRet; dprintf("Example_SemTask1 try get sem g_usSemID ,timeout 10 ticks.\n"); /* get sem, timeout is 10 ticks */ uwRet = LOS_SemPend(g_usSemID, 10); /* get sem ok */ if (LOS_OK == uwRet) { LOS_SemPost(g_usSemID); return; } /* timeout, get sem fail */ if (LOS_ERRNO_SEM_TIMEOUT == uwRet) { dprintf("Example_SemTask1 timeout and try get sem g_usSemID wait forever.\n"); /* get sem wait forever, LOS_SemPend return until has been get mux */ uwRet = LOS_SemPend(g_usSemID, LOS_WAIT_FOREVER); if (LOS_OK == uwRet) { dprintf("Example_SemTask1 wait_forever and got sem g_usSemID success.\n"); LOS_SemPost(g_usSemID); uwRet = LOS_InspectStatusSetByID(LOS_INSPECT_SEM, LOS_INSPECT_STU_SUCCESS); if (LOS_OK != uwRet) { dprintf("Set Inspect Status Err\n"); } return; } } return; }