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

📄 emos_test.c

📁 emos是一个新的类似于ucos的内核
💻 C
字号:
/****************************************************************************
 *
 * (c) Copyright 2001,2008, EMB system, All Rights Reserved.
 * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF EMB SYSTEM, INC.
 * The copyright notice above does not evidence any actual or intended
 * publication of such source code. 
 *
 *  Subsystem:    EMOS 
 *  File:         emos_test.c
 *  Author:       zenf zhao
 *  Description:  EMOS Test file
 *
 ****************************************************************************/
#include "emos_cfg.h"
#include "emos_core.h"

/*Set the associated value to 1 enable the test, 0 disable the test*/
#define EMOS_SEM_TEST_EN   (0)
#define EMOS_MBOX_TEST_EN  (0)
#define EMOS_MSGQ_TEST_EN  (1)

/*
 * Here is the semaphore test function prototype
 * emos_sem_test1 is used to Pend/Take a semaphore
 * emos_sem_test2 is used to Post/Give a semaphore
 */
#if EMOS_SEM_EN && EMOS_SEM_TEST_EN
EMOS_EVENT_T* gTestSem = NULL;
void emos_sem_test1()
{
  if(NULL == gTestSem)	
  {
  	gTestSem = emosSemCreate (1);
  }
  emosSemPend(gTestSem,0,&gEmosError);
  //emosSemPend(tSem,-1,&gEmosError);
}

void emos_sem_test2()
{
  if(NULL != gTestSem)
  {	
  	emosSemPost(gTestSem);
  }
}
#endif


/*
 * Here is the MsgQ test function prototype
 * emos_msg_test1 is used to Receive a message besides creating the msgQId if not created
 * emos_msg_test2 is used to Send a message
 */
#if EMOS_Q_EN && (EMOS_MAX_MSGQS >= 2) && EMOS_MSGQ_TEST_EN 
#define EMSO_MSGQ_TST_SIZE (16)

EMOS_MSGQ_ID gTstMsgQ01 = NULL;
char gTstMsgStrRcv[20] = {0};
char gTstMsgStrXmt[20] = "Hello World";
int  nret;
void emos_msg_test1()
{
  if(NULL == gTstMsgQ01) 
  {
      gTstMsgQ01 = emosMsgQCreate(16,EMSO_MSGQ_TST_SIZE);
      if(NULL == gTstMsgQ01) EMOS_Print("%s %d can not create MsgQ\r\n",__FILE__,__LINE__);
  }

  /*EMOS_Print("%s %d msg test1 MsgQRecv running\r\n",__FILE__,__LINE__);*/

  if(NULL != gTstMsgQ01)
  {
  	gTstMsgStrRcv[0] = 0;
    nret = emosMsgQRecv(gTstMsgQ01,gTstMsgStrRcv, EMSO_MSGQ_TST_SIZE, EMOS_WAIT_FOREVER);
    if(EMOS_NO_ERR != nret)
    {
      EMOS_Print("%s %d MsgQRecv Error  Code = %d\r\n",__FILE__,__LINE__,nret);
    }
    else
    {
      gTstMsgStrRcv[EMSO_MSGQ_TST_SIZE-1] = 0;	
      EMOS_Print("%s %d MsgQRecv ok = %s numMsg=%d\r\n",__FILE__,__LINE__,gTstMsgStrRcv,*((uint16*)((char*)gTstMsgQ01 + 28)));
    }
  }
}

void emos_msg_test2()
{
  char tstBuf[EMSO_MSGQ_TST_SIZE+10] = {0};
  static int cnt = 0;
  cnt++;
  if(cnt == 256) cnt = 0;
  sprintf(tstBuf,"%s=%03d ",gTstMsgStrXmt,cnt);
  
  if(NULL != gTstMsgQ01)
  {
  	
    /*nret = emosMsgQSend(gTstMsgQ01,gTstMsgStrXmt, EMSO_MSGQ_TST_SIZE);*/
    nret = emosMsgQSend(gTstMsgQ01,tstBuf, EMSO_MSGQ_TST_SIZE);        
    if(EMOS_NO_ERR != nret)
    {
      EMOS_Print("%s %d MsgQSend Error Code =%d\r\n",__FILE__,__LINE__,nret);
    }
    else
    {
      EMOS_Print("%s %d MsgQSendID numMsg=%d\r\n",__FILE__,__LINE__,*((uint16*)((char*)gTstMsgQ01 + 28)));
    } 
  }
  else
  {
     EMOS_Print("%s %d MsgQ null\r\n",__FILE__,__LINE__);
  } 
}
#endif

/*
 * Here is the MBOX test function prototype
 * emos_mbox_test1 is used to Receive a message besides creating the msgQId if not created
 * emos_mbox_test2 is used to Send a message
 */
#if EMOS_MBOX_EN && EMOS_MBOX_TEST_EN 

#endif


/* Here is the task test prototype
 * emosTaskTst1 is used to for test group1
 * emosTaskTst1 is used to for test group2
 * EMOS test modules are all best on the two tasks
 */
#define EMOS_DFT_STK_SIZE  (500)
#define EMOS_DFT_TASK_PRI  (0)
char gEmosTstStk1[EMOS_DFT_STK_SIZE];
char gEmosTstStk2[EMOS_DFT_STK_SIZE];
void emosTaskTst1 (void *pdata);
void emosTaskTst2 (void *pdata);
void emosTaskTst1 (void *pdata)
{
	pdata=pdata; 
	while(1)  
	{
	 EMOS_Print("EMOS Test Task A Running\r\n");

	 #if EMOS_SEM_EN && EMOS_SEM_TEST_EN
	 emos_sem_test1();
	 #endif

     #if EMOS_Q_EN && (EMOS_MAX_MSGQS >= 2) && EMOS_MSGQ_TEST_EN
     emos_msg_test1();
     #endif
	 
	 emosTimeDly(200);
	} 
}

void emosTaskTst2 (void *pdata) 
{
	pdata=pdata; 
    while(1)  
    {
       EMOS_Print("EMOS Test Task B Running\r\n");  
       emosDbgShow();

       #if EMOS_SEM_EN && EMOS_SEM_TEST_EN
       emos_sem_test2();
       #endif

       #if EMOS_Q_EN && (EMOS_MAX_MSGQS >= 2) && EMOS_MSGQ_TEST_EN
       emos_msg_test2();
       #endif
       
       emosTimeDly(300);
    }
}


/*
 *The EMOS System Task Gropu spawn List Functions
 */
int emos_task_group_spawn()
{
  uint8 ret = 0;
  
  ret = emosTaskCreate(emosTaskTst1, (void *)0, 
  	     (EMOS_STK *)&gEmosTstStk1[EMOS_DFT_STK_SIZE - 1], EMOS_DFT_TASK_PRI+1);
  if(ret != EMOS_NO_ERR)
  {
      EMOS_Print("EMOS Test Task A Spawn Error\r\n");
  }
  
  ret = emosTaskCreate(emosTaskTst2, (void *)0, 
  	   (EMOS_STK *)&gEmosTstStk2[EMOS_DFT_STK_SIZE - 1], EMOS_DFT_TASK_PRI);
  if(ret != EMOS_NO_ERR)
  {
      EMOS_Print("EMOS Test Task B Spawn Error\r\n");
  }

  return 0;
}

/*
 * the main entrance for MinGW win32 simulation test
 */
int main ()
{
  /*must be called as the first function of the main*/
  emosInit();
	
  /*all other tasks will be spawned in the callback*/
  emos_task_group_spawn();
  EMOS_DBGSTR_VAL(emosTaskTst1);
  EMOS_DBGSTR_VAL(emosTaskTst2);
  /*emosDbgShow();*/
  
  /*this emosStart must be called 
    as the last function of the main*/
  emosStart();
  
  #if 0
  while(!kbhit())
  {
    EMOS_Print("Main Running \r\n");
    emosDbgShow();
    Sleep(65535);
  }
  EMOS_STOP();
  #endif
  
  EMOS_Print("=========> Main Returning....\r\n");
  return 0;
}


 /*
 * Please add "$" around "Id" and "Log".
 * $Id$
 * $Log$
 *
 */

 

⌨️ 快捷键说明

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