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

📄 main.c

📁 ucos在摩托罗拉16位微控制器68hc16上的移植
💻 C
字号:
/*	 
 *	MAIN.C - Test uCOS kernal on M68HC16Z1 BDM using INTROL16 compiler
 *          The kernal services tested are:
 *	                            OSInit()
 *                             OSIntEnter()
 *                             OSIntExit()
 *                             OSTimeTick()
 *	                            OSTaskCreate()
 *	                            OSStart()
 *	                            OSTimeDly()
 *	                            OSSemCreate()
 *	                            OSSemPend()
 *                             OSSemPost()
 *                             OSTimeSet()
 *                             OSTimeGet()
 *
 *	 
*/

#ifdef __CC16__
#include "c:\introl\incl16\proto.h"
#include "c:\introl\incl16\h16reg.h"
#endif
	 
#include <math.h>
#include "defs.h"
#include "UCOS.H"

/****************************** DEFINES **********************************/
#define  TASK_STK_SIZE	 1024
#define  NUM_TASKS       3

/****************************** GLOBALS **********************************/
UBYTE num_task_stk[TASK_STK_SIZE];
UBYTE test_func_stk[TASK_STK_SIZE];
UBYTE test_ucos_stk[TASK_STK_SIZE];
UBYTE test_array[50];
OS_EVENT *TestSem;

/********************** FUNCTION PROTOTYPES ******************************/
void main( void );
void num_task( void );
void enable_tick_int( void );
void test_func( void );
void test_ucos( void );
/*************************************************************************/

void main()
{
	int i_rc;

	OSInit();			 /* initialize uCOS kernal */

	                   /* allocate storage for tasks and create the tasks */  
	i_rc = OSTaskCreate( num_task, (void *)&num_task_stk[TASK_STK_SIZE], 2);
   if( i_rc != OS_NO_ERR )
		return;
	i_rc = OSTaskCreate( test_ucos, (void *)&test_ucos_stk[TASK_STK_SIZE], 4);
   if( i_rc != OS_NO_ERR )
		return;
	i_rc = OSTaskCreate( test_func, (void *)&test_func_stk[TASK_STK_SIZE], 6);
   if( i_rc != OS_NO_ERR )
		return;

	TestSem = OSSemCreate(0); /* Tasks will wait for each other to initialize */

   OSTimeSet(0L);          /* Reset System Clock */
	OSStart();					/* start multitasking - won't return to main() */
}


/* PRIORITY = 2 */
void num_task(void)
{
	int i=0;
	UBYTE sem_err;

	  /* start (OC2) timer for system tick - enable OC2 interrupt  */
	  /* prescaler - system CLK (16.777216 MHz) / 256              */
   enable_tick_int();                 /* OC2 will toggle every time tick */
	for(i=0;i<50;i++)
	  test_array[i] = 2;
	OSSemPend(TestSem, 0, &sem_err);   /* Wait for all tasks to init */
	if( sem_err != OS_NO_ERR )
	  return;

	while(1)
		{
	    i=i+2;
	    i=i-2;
		 OSTimeDly(400);		 /* Delay for 20 seconds */
		}
}

/* PRIORITY = 4 */
void test_ucos(void)
{
	int i=0;
	UBYTE sem_err;

	i=i+4;
	i=i-4;
	OSSemPend(TestSem, 0, &sem_err);   /* Wait for all tasks to init */
	if( sem_err != OS_NO_ERR )
	  return;

	while(1)
	 {
	    i=i+4;
	    i=i-4;
       CPU16_GPTPDR |= 0x20;    /* set a general purpose I/O pin (OC3)    */
                           /* this takes 18 clocks = 1 uSec at 16.777 MHz */
       OSTimeDly(100);          /* Delay for 5 sec  */
       CPU16_GPTPDR &= 0x0DF;   /* clear a general purpose I/O pin (OC3) */
    }
}

/* PRIORITY = 6 */
void test_func(void)
{
	int i=0;
   unsigned long ul_clk;

	i=i+6;
	i=i-6;
   for(i=0; i<NUM_TASKS-1;i++)
	   OSSemPost(TestSem);             /*  All tasks may continue */

	while(1)
	 {
      ul_clk = OSTimeGet();
	   i=i+6;
	   i=i-6;
		 for(i=0;i<50;i++)
		   test_array[i] = 4;
    }
}

⌨️ 快捷键说明

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