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

📄 68hc11.txt

📁 uCOS的移植代码,到68hc11系列单片机.
💻 TXT
📖 第 1 页 / 共 2 页
字号:
/*
*********************************************************************************************************
*                                                uC/OS
*                                         The Real-Time Kernel
*
*                         (c) Copyright 1997, Jean J. Labrosse, Plantation, FL
*                                          All Rights Reserved
*
*                                     COMMANDS TO COMPILE AND LINK
*                                                68HC11
*
* Assumes COSMIC C compiler:
*
* COSMIC Software
* 617-932-2556
* 100 Tower Office Park, Suite C
* Woburn, MA 01801
*
* c-tools@cosmic-us.com
*
* Assumes that the COSMIC compiler is installed in:
*
*  C:\C68HC11
*
* Assumes 68HC11 source files are in:
*
*  \SOFTWARE\UCOS\68HC11\SOURCE
*
* Assumes 68HC11 objects are compiled in:
*
*  \SOFTWARE\UCOS\68HC11\TEST
*
*
*  COPY \SOFTWARE\UCOS\SOURCE\UCOS.C /y
*  COPY ..\SOURCE\TEST.C   /y
*  COPY ..\SOURCE\68HC11.C /y
*  COPY ..\SOURCE\*.H      /y
*  C:\C68HC11\C -v -dxdebug -dsprec -dfast -dlistcs -dmap -dnowiden -dverbose +o UCOS.C
*  C:\C68HC11\C -v -dxdebug -dsprec -dfast -dlistcs -dmap -dnowiden -dverbose +o 68HC11.C
*  C:\C68HC11\C -v -dxdebug -dsprec -dfast -dlistcs -dmap -dnowiden -dverbose +o TEST.C
*  C:\C68HC11\LNKH11 <..\SOURCE\TEST.LNK
*********************************************************************************************************
*/


/*
*********************************************************************************************************
*                                                uC/OS
*                                         The Real-Time Kernel
*
*                         (c) Copyright 1997, Jean J. Labrosse, Plantation, FL
*                                          All Rights Reserved
*
*                                          MASTER INCLUDE FILE
*                                                68HC11
*
* File : INCLUDES.H
* By   : Jean J. Labrosse
*********************************************************************************************************
*/

#include <IOF1.H>
#include "OS_CFG.H"
#include "68HC11.H"
#include "TEST.H"
#include "\SOFTWARE\UCOS\SOURCE\UCOS.H"


/*
*********************************************************************************************************
*                                                uC/OS
*                                         The Real-Time Kernel
*
*                         (c) Copyright 1997, Jean J. Labrosse, Plantation, FL
*                                          All Rights Reserved
*
*                                        uC/OS Configuration File
*
* File : OS_CFG.H
* By   : Jean J. Labrosse
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*                                          uC/OS CONFIGURATION
*********************************************************************************************************
*/

#define  OS_MAX_TASKS            63    /* Maximum number of tasks in your application                  */
#define  OS_MAX_EVENTS           20    /* Maximum number of event control blocks in your application   */
#define  OS_MAX_QS                5    /* Maximum number of queue control blocks in your application   */

#define  OS_IDLE_TASK_STK_SIZE  256    /* Idle task stack size (BYTEs)                                 */
#define  OS_IDLE_TASK_STK_TOP   255    /* Index into idle task top of stack                            */

#define  OS_TASK_CHANGE_PRIO_EN   1    /* Include code for OSTaskChangePrio()                          */
#define  OS_TASK_DEL_EN           1    /* Include code for OSTaskDel()                                 */
#define  OS_SEM_EN                1    /* Include code for SEMAPHORES                                  */
#define  OS_MBOX_EN               1    /* Include code for MAILBOXES                                   */
#define  OS_Q_EN                  1    /* Include code for QUEUES                                      */
#define  OS_TASK_SUSPEND_EN       1    /* Include code for OSTaskSuspend() and OSTaskResume()          */

#define  OS_TICK_RATE           100    /* System Tick rate (Hz)                                        */

#define  OS_TICKS_10mS     (OS_TICK_RATE / 100)
#define  OS_TICKS_20mS     (OS_TICK_RATE /  50)
#define  OS_TICKS_50mS     (OS_TICK_RATE /  20)
#define  OS_TICKS_100mS    (OS_TICK_RATE /  10)
#define  OS_TICKS_200mS    (OS_TICK_RATE /   5)
#define  OS_TICKS_500mS    (OS_TICK_RATE /   2)
#define  OS_TICKS_1S       (OS_TICK_RATE)
#define  OS_TICKS_2S       (OS_TICK_RATE *   2)
#define  OS_TICKS_3S       (OS_TICK_RATE *   3)
#define  OS_TICKS_4S       (OS_TICK_RATE *   4)
#define  OS_TICKS_5S       (OS_TICK_RATE *   5)
#define  OS_TICKS_6S       (OS_TICK_RATE *   6)
#define  OS_TICKS_7S       (OS_TICK_RATE *   7)
#define  OS_TICKS_8S       (OS_TICK_RATE *   8)
#define  OS_TICKS_9S       (OS_TICK_RATE *   9)
#define  OS_TICKS_10S      (OS_TICK_RATE *  10)
#define  OS_TICKS_20S      (OS_TICK_RATE *  20)
#define  OS_TICKS_30S      (OS_TICK_RATE *  30)
#define  OS_TICKS_40S      (OS_TICK_RATE *  40)
#define  OS_TICKS_50S      (OS_TICK_RATE *  50)
#define  OS_TICKS_1M       (OS_TICK_RATE *  60)
#define  OS_TICKS_2M       (OS_TICK_RATE * 120)
#define  OS_TICKS_3M       (OS_TICK_RATE * 180)
#define  OS_TICKS_4M       (OS_TICK_RATE * 240)
#define  OS_TICKS_5M       (OS_TICK_RATE * 300)


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

/*
*********************************************************************************************************
*                                              DATA TYPES
*********************************************************************************************************
*/

typedef  unsigned char  BOOLEAN;       /* TRUE or FALSE                                                */
typedef  unsigned char  UBYTE;         /* Unsigned  8 bit quantity (             0 to           255)   */
typedef  signed   char  BYTE;          /* Signed    8 bit quantity (          -128 to           127)   */
typedef  unsigned int   UWORD;         /* Unsigned 16 bit quantity (             0 to        65,535)   */
typedef  signed   int   WORD;          /* Signed   16 bit quantity (       -32,768 to        32,767)   */
typedef  unsigned long  ULONG;         /* Unsigned 32 bit quantity (             0 to 4,294,967,295)   */
typedef  signed   long  LONG;          /* Signed   32 bit quantity (-2,147,483,648 to 2,147,483,647)   */

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

#ifndef  FALSE                         /* Define TRUE and FALSE if not already done                    */
#define  FALSE    0
#endif

#ifndef  TRUE
#define  TRUE     1
#endif

/*
*********************************************************************************************************
*                                           68HC11 SPECIFICS
*********************************************************************************************************
*/

#define  OS_FAR                               /* Define OS_FAR to nothing (68HC11 does not use 'far')  */

#define  OS_STK_TYPE          UBYTE           /* Data type used for stacks                             */

#define  OS_ENTER_CRITICAL()  _asm(" sei\n");
#define  OS_EXIT_CRITICAL()   _asm(" cli\n");
#define  OS_TASK_SW()         _asm(" swi\n");


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

/*
*********************************************************************************************************
*                                         PROCESSOR SPECIFICS
*********************************************************************************************************
*/

#define  CPU_FRT_FREQ         250000L               /* Free Running Timer rate (Hz)                    */

#define  OS_TICK_OC                 1               /* Output compare # used to generate a tick int.   */
                                                    /* Number of FRT counts to produce an interrupt ...*/
#define  OS_TICK_OC_CNTS  (CPU_FRT_FREQ / OS_TICK_RATE)    /* ... at the desired tick rate.            */


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

#include "INCLUDES.H"

/*
*********************************************************************************************************
*                                           CREATE A TASK
*
* Description : This function is used to create a task under uC/OS.  To manage the task, uC/OS needs to
*               know the starting address of the task, the address of any data that you would like to
*               pass to that task when it starts executing, the address of the top-of-stack for the
*               task's stack and finally, the priority of the task.
* Arguments   : task    is the address of your task
*               pdata   is a pointer to data that you wish to pass to the task when the task starts
*               pstk    is a pointer to the task's top-of-stack
*               prio    is the task's priority
*********************************************************************************************************
*/

UBYTE OSTaskCreate(void (OS_FAR *task)(void *pd), void *pdata, void *pstk, UBYTE p)
{
    UWORD *wstk;
    UBYTE *bstk;
    UBYTE  err;


    OS_ENTER_CRITICAL();
    if (OSTCBPrioTbl[p] == (OS_TCB *)0) {   /* Make sure task doesn't already exist at this priority   */
        OS_EXIT_CRITICAL();
        wstk    = (UWORD *)pstk;            /* Load stack pointer                                      */
        *--wstk = (UWORD)pdata;             /* Simulate call to function with argument                 */
        *--wstk = (UWORD)task;
        *--wstk = (UWORD)task;              /* Put pointer to task   on top of stack                   */
        *--wstk = (UWORD)0x0000;            /* Y Register = 0                                          */
        *--wstk = (UWORD)0x0000;            /* X Register = 0                                          */
        *--wstk = (UWORD)0x0000;            /* D Register = 0  (i.e. A = 0 and B = 0)                  */
        bstk    = (UBYTE *)wstk;            /* Convert WORD ptr to BYTE ptr to set CCR                 */
        *--bstk = 0xC0;                     /* CCR Register (disable XIRQ and STOP instruction)        */
        bstk--;
        err = OSTCBInit(p, (void *)bstk);   /* Get and initialize a TCB                                */
        if (err == OS_NO_ERR) {
            if (OSRunning) {                /* Find highest priority task if multitasking has started  */
                OSSched();
            }
        }
        return (err);
    } else {
        OS_EXIT_CRITICAL();
        return (OS_PRIO_EXIST);
    }
}
/*$PAGE*/
/*
*********************************************************************************************************
*                               START HIGHEST PRIORITY TASK READY-TO-RUN
*
* Description : This function is called by OSStart() to start the highest priority task that was created
*               by your application before calling OSStart().
* Arguments   : none
* Execution   : 27 bus cycles
*********************************************************************************************************
*/

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


    _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*/
/*
*********************************************************************************************************
*                                       TASK LEVEL CONTEXT SWITCH
*
* Description : This function is called when a task makes a higher priority task ready-to-run.
* Arguments   : none
* Execution   : 35 bus cycles
*********************************************************************************************************
*/

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


    _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         */

⌨️ 快捷键说明

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