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

📄 68hc11.txt

📁 uCOS的移植代码,到68hc11系列单片机.
💻 TXT
📖 第 1 页 / 共 2 页
字号:

    _asm("  ldx       _OSTCBHighRdy\n");    /*  5~, Point to TCB of highest priority task ready to run */
    _asm("  stx       _OSTCBCur    \n");    /*  5~, Save in current TCB                                */
    _asm("  lds       0,x          \n");    /*  5~, Load SP into 68HC11                                */

    _asm("  rti                    \n");    /* 12~, Run task                                           */
}


/*
*********************************************************************************************************
*                                    INTERRUPT LEVEL CONTEXT SWITCH
*
* Description : This function is called by OSIntExit() to perform a context switch to a task that has
*               been made ready-to-run by an ISR.
* Arguments   : none
* Execution   : 47 bus cycles
*********************************************************************************************************
*/

void OSIntCtxSw(void)
{
    _asm("  .external _OSTCBCur    \n");
    _asm("  .external _OSTCBHighRdy\n");


    _asm("  pulx                   \n");    /*  5~, Ignore return address to OSIntCtxSw()              */
    _asm("  pulx                   \n");    /*  5~, Ignore return address from call to OSIntExit()     */

    _asm("  ldx       _OSTCBCur    \n");    /*  5~, Point to current task's TCB                        */
    _asm("  sts       0,x          \n");    /*  3~, Save stack pointer in preempted task's TCB         */

    _asm("  ldx       _OSTCBHighRdy\n");    /*  5~, Point to TCB of highest priority task ready to run */
    _asm("  stx       _OSTCBCur    \n");    /*  5~, Save in current TCB                                */
    _asm("  lds       0,x          \n");    /*  5~, Load SP into 68HC11                                */

    _asm("  rti                    \n");    /* 12~, Run task                                           */
}
/*$PAGE*/
/*
*********************************************************************************************************
*                                           SYSTEM TICK ISR
*
* Description : This function is the ISR used to notify uC/OS that a system tick has occurred.  You must
*               setup the 68HC11's interrupt vector table so that an OUTPUT COMPARE interrupt vectors
*               to this function.
* Arguments   : none
* Notes       :  1) The 'tick ISR' assumes the we are using the Output Compare specified by OS_TICK_OC
*                   (see OS_CFG.H) to generate a tick that occurs every OS_TICK_OC_CNTS (also in
*                   68HC11.H) which corresponds to the number of FRT (Free Running Timer) counts to the
*                   next interrupt.
*                2) You must specify which output compare will be used by the tick ISR as follows:
*                       Set OS_TICK_OC in OS_CFG.H to 1 to use OUTPUT COMPARE #1
*                       Set OS_TICK_OC in OS_CFG.H to 2 to use OUTPUT COMPARE #2
*                       Set OS_TICK_OC in OS_CFG.H to 3 to use OUTPUT COMPARE #3
*                       Set OS_TICK_OC in OS_CFG.H to 4 to use OUTPUT COMPARE #4
*                       Set OS_TICK_OC in OS_CFG.H to 5 to use OUTPUT COMPARE #5
*                3) TFLG1, TOC1, TOC2, TOC3, TOC4 and TOC5 are defined in the Intermetrics file IO.H
*********************************************************************************************************
*/

void OS_FAR OSTickISR(void)
{
    OSIntNesting++;                         /* Notify uC/OS about the ISR                              */

#if OS_TICK_OC == 1
    TFLG1  = 0x80;                          /* Clear OC1F interrupt flag (bit 7)                       */
    TOC1  += OS_TICK_OC_CNTS;               /* Set TOC1 to present time + desired counts to next ISR   */
#endif

#if OS_TICK_OC == 2
    TFLG1  = 0x40;                          /* Clear OC2F interrupt flag (bit 6)                       */
    TOC2  += OS_TICK_OC_CNTS;               /* Set TOC2 to present time + desired counts to next ISR   */
#endif

#if OS_TICK_OC == 3
    TFLG1  = 0x20;                          /* Clear OC3F interrupt flag (bit 5)                       */
    TOC3  += OS_TICK_OC_CNTS;               /* Set TOC3 to present time + desired counts to next ISR   */
#endif

#if OS_TICK_OC == 4
    TFLG1  = 0x10;                          /* Clear OC4F interrupt flag (bit 4)                       */
    TOC4  += OS_TICK_OC_CNTS;               /* Set TOC4 to present time + desired counts to next ISR   */
#endif

#if OS_TICK_OC == 5
    TFLG1  = 0x08;                          /* Clear OC5F interrupt flag (bit 3)                       */
    TOC5  += OS_TICK_OC_CNTS;               /* Set TOC5 to present time + desired counts to next ISR   */
#endif

    OSTimeTick();                           /* Call uC/OS's tick updating function                     */
    OSIntExit();                            /* Tell uC/OS that we are about to exit the ISR            */

    _asm("  rti \n");                       /* Return from interrupt                                   */
}



/*
*********************************************************************************************************
*                                                uC/OS
*                                         The Real-Time Kernel
*
*                         (c) Copyright 1997, Jean J. Labrosse, Plantation, FL
*                                          All Rights Reserved
*
*
*                                    68HC11F1 INTERRUPT VECTOR TABLE
*
* File : VECTORS.C
* By   : Jean J. Labrosse
*********************************************************************************************************
*/

#include "INCLUDES.H"

/*
*********************************************************************************************************
*                                              MC68HC11F1
*                                         INTERRUPT VECTOR TABLE
*
* Description: This is the interrupt vector table used by the MC68HC11F1 CPU.  Note that unused
*              interrupts are vectored to NULL.
* Notes      : You MUST define the vector that defines the address of your startup code.
*********************************************************************************************************
*/

void (* const OSVectorTbl[])(void) = {      /* This table begins at 0xFFD6                             */
    (void (*)())NULL,                       /* $FFD6 SCI Serial System                                 */

    (void (*)())NULL,                       /* $FFD8 SPI Serial Transfer Complete                      */

    (void (*)())NULL,                       /* $FFDA Pulse Accumulator Input Edge                      */

    (void (*)())NULL,                       /* $FFDC Pulse Accumulator Overflow                        */

    (void (*)())NULL,                       /* $FFDE Timer Overflow                                    */

    (void (*)())NULL,                       /* $FFE0 Timer Input Capture 4/Output Compare 5            */

    (void (*)())NULL,                       /* $FFE2 Timer Output Compare 4                            */

    (void (*)())NULL,                       /* $FFE4 Timer Output Compare 3                            */

    (void (*)())NULL,                       /* $FFE6 Timer Output Compare 2                            */

    (void (*)())OSTickISR,                  /* $FFE8 Timer Output Compare 1                            */

    (void (*)())NULL,                       /* $FFEA Timer Input Capture 3                             */

    (void (*)())NULL,                       /* $FFEC Timer Input Capture 2                             */

    (void (*)())NULL,                       /* $FFEE Timer Input Capture 1                             */

    (void (*)())NULL,                       /* $FFF0 Real Time Interrupt (RTI)                         */

    (void (*)())NULL,                       /* $FFF2 IRQ (External Pin)                                */

    (void (*)())NULL,                       /* $FFF4 XIRQ Pin (Pseudo Nonmaskable Interrupt)           */

    (void (*)())OSCtxSw,                    /* $FFF6 SWI                                               */

    (void (*)())NULL,                       /* $FFF8 Illegal Opcode Trap                               */

    (void (*)())NULL,                       /* $FFFA COP Failure (Reset)                               */

    (void (*)())NULL,                       /* $FFFC COP Clock Monitor Fail (Reset)                    */

    (void (*)())NULL                        /* $FFFE RESET                                             */
};




/*
*********************************************************************************************************
*                                                uC/OS
*                                         The Real-Time Kernel
*
*                         (c) Copyright 1997, Jean J. Labrosse, Plantation, FL
*                                          All Rights Reserved
*
*
*                                          68HC11 Sample code
*
* File : TEST.C
* By   : Jean J. Labrosse
*********************************************************************************************************
*/

#include "INCLUDES.H"

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

UBYTE AppStartTaskStk[256];

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

void OS_FAR AppStartTask(void *pdata);
void        AppTickInit(void);

/*
*********************************************************************************************************
*                                                main()
*
* Description : This is the standard entry point for C code.  It is assumed that your code will call
*               main() once you have performed all necessary 68HC11 and C initialization.
* Arguments   : none
*********************************************************************************************************
*/

void main(void)
{
    /*---- Any initialization code prior to calling OSInit() goes HERE --------------------------------*/

    OSInit();                               /* Initialize "uC/OS, The Real-Time Kernel"                */

    /*---- Any initialization code before starting multitasking ---------------------------------------*/

    OSTaskCreate(AppStartTask, (void *)0, (void *)&AppStartTaskStk[255], 0);

    /*---- Create any other task you want before we start multitasking --------------------------------*/

    OSStart();                              /* Start multitasking (i.e. give control to uC/OS)         */
}
/*$PAGE*/
/*
*********************************************************************************************************
*                                          STARTUP TASK
*
* Description : This is an example of a startup task.  As mentioned in the book's text, you MUST
*               initialize the ticker only once multitasking has started.
* Arguments   : pdata   is the argument passed to 'AppStartTask()' by 'OSTaskCreate()'.
* Notes       : 1) The first line of code is used to prevent a compiler warning because 'pdata' is not
*                  used.  The compiler should not generate any code for this statement.
*               2) Interrupts are enabled once the task start because the I-bit of the CCR register was
*                  set to 0 by 'OSTaskCreate()'.
*********************************************************************************************************
*/

void OS_FAR AppStartTask(void *pdata)
{
    pdata = pdata;
    AppTickInit();                          /* Initialize the ticker                                   */
    /*---- Task initialization code goes HERE! --------------------------------------------------------*/

    while (TRUE) {                          /* Task body, always written as an infinite loop.          */
        /*---- Task code goes HERE! -------------------------------------------------------------------*/
        OSTimeDly(1);                       /* Delay task execution for one clock tick                 */
    }
}
/*$PAGE*/
/*
*********************************************************************************************************
*                                      TICKER INITIALIZATION
*
* Description : This function is used to initialize one of the five output compares to generate an
*               interrupt at the desired tick rate.  You must decide which output compare you will be
*               using by setting the configuration variable OS_TICK_OC (see OS_CFG.H) to 1, 2, 3, 4 or 5
*               depending on which output compare to use.
*                   OS_TICK_OC set to 1 chooses output compare #1 as the ticker source
*                   OS_TICK_OC set to 2 chooses output compare #2 as the ticker source
*                   OS_TICK_OC set to 3 chooses output compare #3 as the ticker source
*                   OS_TICK_OC set to 4 chooses output compare #4 as the ticker source
*                   OS_TICK_OC set to 5 chooses output compare #5 as the ticker source
* Arguments   : none
* Notes       : 1) It is assumed that you have set the prescaler rate of the free running timer within
*                  the first 64 E clock cycles of the 68HC11.
*               2) TCNT, TOC1, TOC2, TOC3, TOC4, TOC5 and TMSK1 are define in IO.H (see Intermetrics
*                  compiler).
*********************************************************************************************************
*/

void AppTickInit(void)
{
#if OS_TICK_OC == 1
    TOC1   = TCNT + OS_TICK_OC_CNTS;        /* Set TOC1 to present time + OS_TICK_OC_CNTS              */
    TMSK1 |= 0x80;                          /* Enable OC1 interrupt.                                   */
#endif

#if OS_TICK_OC == 2
    TOC2   = TCNT + OS_TICK_OC_CNTS;        /* Set TOC2 to present time + OS_TICK_OC_CNTS              */
    TMSK1 |= 0x40;                          /* Enable OC2 interrupt.                                   */
#endif

#if OS_TICK_OC == 3
    TOC3   = TCNT + OS_TICK_OC_CNTS;        /* Set TOC3 to present time + OS_TICK_OC_CNTS              */
    TMSK1 |= 0x20;                          /* Enable OC3 interrupt.                                   */
#endif

#if OS_TICK_OC == 4
    TOC4   = TCNT + OS_TICK_OC_CNTS;        /* Set TOC4 to present time + OS_TICK_OC_CNTS              */
    TMSK1 |= 0x10;                          /* Enable OC4 interrupt.                                   */
#endif

#if OS_TICK_OC == 5
    TOC5   = TCNT + OS_TICK_OC_CNTS;        /* Set TOC5 to present time + OS_TICK_OC_CNTS              */
    TMSK1 |= 0x08;                          /* Enable OC5 interrupt.                                   */
#endif
}



/* THIS IS THE CONTENTS OF THE FILE TEST.LNK */
+map=TEST.MAP
+dead
+h
-o TEST.H11
+zpage  -b0x0000
+bss    -b0x0100
+text   -b0x8000
+bss    -b0x0800
test.o
68hc11.o
ucos.o
C:\C68HC11\LIB\LIBF.H11
C:\C68HC11\LIB\LIBI.H11
C:\C68HC11\LIB\LIBM.H11

⌨️ 快捷键说明

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