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

📄 test.c

📁 ucos在所有cpu下的移植范例
💻 C
字号:
/****************************************************************************** 
 * File:        TEST.C
 *
 * Description: This is a test application for uC/OS.
 *
 * Comments:
 *
 * Revision Control:
 * $Revision: $
 * $Date: $
 * $Log: $
 *****************************************************************************/
#include <ioas.h>
#include <stdio.h>
#include "includes.h"

/* Initialize IO ports */
#define	DDRA_INIT  0x01		/* PTA0 is output */
#define	DDRB_INIT  0x08		/* PTB3 is output */
#define	DDRC_INIT  0x1F		/* PTC - All outputs */
#define	DDRD_INIT  0x00		/* PTD - All inputs */
#define	DDRE_INIT  0xFF		/* PTE - All outputs */
#define	DDRF_INIT  0x0F		/* PTF - All outputs */

/* Initialize SCI */
#define	SCC1_INIT  0x00
#define	SCC2_INIT  0x00
#define	SCC3_INIT  0x00

/* Initialize IRQ */
#define ISCR_INIT  0x06		/* Acknowledge and turn on interrupt mask */

/* Initialize CGM */
#define	PCTL_INIT  0x0F		/* PLL off */
#define	PPG_INIT   0x00		/* VCO multiplier = 1 */

/* Bit to turn on external switched power */
#define PTB_SWITCHED_POWER	0x08


/** Application Stack "variables" including the system IdleTask **/
#define TASK_STK_SIZE   32

INT8U	Task1Stk[TASK_STK_SIZE];
INT8U	Task2Stk[TASK_STK_SIZE];
INT8U	Task3Stk[TASK_STK_SIZE];

/********************************************************************/
/**  The actual multitasked code starts here                       **/

void Task1(void* pdata)
{
    for(;;)
    {
		/* Turn off the COP watchdog (set to pet when done debugging) */
		COPCTL = 0;

		/* Delay 0.5 second */
        OSTimeDly(24);
    }
}

void Task2(void* pdata)
{
    for(;;)
    {
		/* Delay 1 second */
        OSTimeDly(49);
    }
}

void Task3(void* pdata)
{
    for(;;)
    {
		/* Delay 2 seconds */
        OSTimeDly(99);
    }
}

/**  The multitasked code ends here                                **/
/********************************************************************/


int main()
	{
	/* Initialize the hardware */
	HardwareInit();

	/* Initialize the OS, create the tasks and start */
  	OSInit();
  	OSTaskCreate(Task1, (void*)0, (void*)&Task1Stk[TASK_STK_SIZE], 50);
  	OSTaskCreate(Task2, (void*)0, (void*)&Task2Stk[TASK_STK_SIZE], 51);
  	OSTaskCreate(Task3, (void*)0, (void*)&Task3Stk[TASK_STK_SIZE], 52);
  	OSStart();
    
  	return 0; //This will never happen...
	}

void HardwareInit(void)
	{
	/* Initialize CGM */
	PCTL = PCTL_INIT;	/* PLL off */
	PPG = PPG_INIT;		/* VCO multiplier = 1 */

	/* Initialize IO ports */
	PTA  = 0;
	DDRA = DDRA_INIT;
	PTB  = PTB_SWITCHED_POWER;	   
	DDRB = DDRB_INIT;
	PTC  = 0;	   
	DDRC = DDRC_INIT;
	PTD  = 0;		
	DDRD = DDRD_INIT;
	PTE  = 0;	  
	DDRE = DDRE_INIT;
	PTF  = 0;	  
	DDRF = DDRF_INIT;	  

	/* Initialize SCI */
	SCC1 = SCC1_INIT;
	SCC2 = SCC2_INIT;
	SCC3 = SCC3_INIT;

	/* Initialize IRQ input */
	ISCR = ISCR_INIT;
	}

⌨️ 快捷键说明

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