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

📄 app.c

📁 ucos-II在MSP430上的移植代码
💻 C
字号:
/*
*********************************************************************************************************
*                                                uC/OS-II
*                                          The Real-Time Kernel
*
*                              (c) Copyright 2002, Micrium, Inc., Weston, FL
*                                           All Rights Reserved
*
*                                                TI MSP430
*********************************************************************************************************
*/

#include <includes.h>

/*
*********************************************************************************************************
*                                               CONSTANTS
*********************************************************************************************************
*/

#define  TASK_STK_SIZE                  64       /* Size of each task's stacks (# of OS_STK entries)   */

/*
*********************************************************************************************************
*                                               VARIABLES
*********************************************************************************************************
*/

OS_STK   TaskStartStk[TASK_STK_SIZE];

/*
*********************************************************************************************************
*                                           FUNCTION PROTOTYPES
*********************************************************************************************************
*/

void   TaskStart(void *data);           /* Function prototypes of Startup task                */
void   Enable_XT2(void);                /* Enable XT2 and use it as the clock source          */        

/*$PAGE*/
/*
*********************************************************************************************************
*                                                MAIN
*********************************************************************************************************
*/

int  main (void)
{
    WDTCTL = WDTPW + WDTHOLD;           /* Disable the watchdog timer   */

    P1SEL = 0x00;                       /* Port1 is set to GPIO         */
    P1DIR = 0x01;                       /* P1.0 is the only output.     */
    P1OUT = 0x00;                       /* P1.0 initially low.          */

    // TIMERA Configuration             /* Configure TIMERA for the system Tick source. */
    //
    TACTL    = TASSEL1 + TACLR;         /* Clear the Timer and set SMCLK as the source. */
    TACTL   |= 0x00C0;                  /* Input divider is /8.  */
    TACCTL0  = CCIE;                    /* Enable the TACCR0 interrupt. */
    TACCR0   = 2304;                   /* Load the TACCR0 register.    */  

    OSInit();                                              /* Initialize uC/OS-II                      */
    OSTaskCreate(TaskStart, (void *)0, &TaskStartStk[TASK_STK_SIZE - 1], 0);
    OSStart();                                             /* Start multitasking                       */

	return(0);
}

/*
*********************************************************************************************************
*                                            STARTUP TASK
*********************************************************************************************************
*/

void  TaskStart (void *pdata)
{
    pdata  = pdata;         /* Prevent compiler warning                 */

    TACTL |= MC1;           /* Start the Timer in Continuous mode. */

    while (1) 
    {
        /* Task specific code */

        P1OUT ^= 0x01;      /* Toggle the port pin to show signs of life.   */
        OSTimeDly(OS_TICKS_PER_SEC);      /* Delay for a bit.                             */
    }
}


void Enable_XT2(void)
{
    int i;
    volatile int j;

    i=1;
    while(i)
    {
        _BIS_SR(OSCOFF);
        BCSCTL1 = 0;            /* XT2 is On */
        IFG1 &= ~OFIFG;         /* Clear the Oscillator Fault interrupt flag. */

        for(j=0;j<1000;j++);    /* Wait for a little bit.  */

        if(!(IFG1 & OFIFG))     /* If OFIFG remained cleared we are ready to go. */
        {                       /* Otherwise repeat the process until it stays cleared. */
            i = 0;
        }
    }

    BCSCTL2 = 0x88;             /* Select XT2CLK for MCLK and SMCLK */
}

⌨️ 快捷键说明

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