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

📄 test.c

📁 Hp驱动
💻 C
字号:
/*
*********************************************************************************************************
*                                               uC/OS-II
*                                        The Real-Time Kernel
*
*                            (c) Copyright 1999, Jean J. Labrosse, Weston, FL
*                                          All Rights Reserved
*
*                                       H8/300H Test Code Skeleton
*                                            (ADVANCED mode)
*
* File : OS_CPU_C.C
* By   : Bill Knight (GNU/ADVANCED port)
*        Jean J. Labrosse
*        Dr. Odd Arild Olsen
*********************************************************************************************************
*/

#include "INCLUDES.H"

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

#define BIT(n) (1 << (n))

#define MONTRAP_SET_VECTOR_TABLE 4

#define ITU_TSTR  (*(volatile unsigned char *) (0xFFFF60)) 

#define ITU_TCR0  (*(volatile unsigned char *) (0xFFFF64))
#define ITU_TIOR0 (*(volatile unsigned char *) (0xFFFF65))
#define ITU_TIER0 (*(volatile unsigned char *) (0xFFFF66))
#define ITU_TSR0  (*(volatile unsigned char *) (0xFFFF67))
#define ITU_TCNT0 (*(volatile unsigned int  *) (0xFFFF68))
#define ITU_GRA0  (*(volatile unsigned int  *) (0xFFFF6A))

#define PCDDR     (*(volatile unsigned char *) (0xFFFFD5))
#define PCDR      (*(volatile unsigned char *) (0xFFFFD7))

#define INTC_IPRA (*(volatile unsigned char *) (0xFFFFF7))

/*
*********************************************************************************************************
*                                            GLOBAL VARIABLES
*********************************************************************************************************
*/

OS_STK    AppStartTaskStk[128];
void      AppStartTask(void *pdata);
void      AppTickInit(INT16U tickRate);
INT32U    MonH8300HFunctionTrap(INT16U funcCode, INT16U param2, INT32U param1);


INT8U     AppTmrSwDiv;
INT8U     AppTmrSwDivCnt;

extern void *vector_table;


/*$PAGE*/
/*
*********************************************************************************************************
*                                            MAIN ENTRY POINT
*********************************************************************************************************
*/
void main(void)
{
  /* --- Any initialization code prior to calling OSInit() goes HERE --- */

  // monitor call to enable user interrupt processing
  MonH8300HFunctionTrap(MONTRAP_SET_VECTOR_TABLE, 48, (INT32U)&vector_table);

  OSInit();

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

  /* Turn on the LED */
  PCDDR = 0x01;
  PCDR |= 0x01;

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

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

  OSStart();
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                            INITIAL TASK
*
* Description: This is an example of a startup task. As mentioned in the book's text, you MUST
*              initialize the ticker 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 starts because the I and UI bits of the CCR 
*                 register was set to 0 by 'OSTaskCreate'.
*********************************************************************************************************
*/
void  AppStartTask (void *pdata)
{
  pdata = pdata;                        // Prevent compiler warning

  /* --- Task initialization code goes HERE ! --- */

  AppTickInit(OS_TICKS_PER_SEC);

  for (;;)                              // Task body, always written as an infinite loop
    {
    /* --- Task code goes HERE! --- */

    PCDR ^= BIT(0);                     // Toggle the LED

    OSTimeDly(50);                      // Delay task execution 50 clock tick => 1/2 sec
    }
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                       INITIALIZE THE TICKER
*
* Description: The function calculates the number to place in the timer-counter
*              register GRA and returns the software divisor.
*
* Arguments  : The tickRate parameter in Hz.
*
* Returns    : none
*
* Notes      : Sets up timer-counter 0 as the tick timer.
*********************************************************************************************************
*/
void AppTickInit(INT16U tick_rate)
{
  INT32U  m, n;
  INT8U   sw_div;

  AppTmrSwDivCnt = 0;

  if (tick_rate == 0)
    AppTmrSwDiv = 0;

  n = SYSCLK / (INT32U)(8 * tick_rate);
  m = n;
  sw_div = 1;

  while (m > 65535)
    {
    sw_div++;
    m = n/(INT32U)sw_div;
    }

  AppTmrSwDiv = sw_div;

  // set up timer 0 as periodic counter with length given by GRA
  INTC_IPRA |= BIT(2);                  // set TMR0 IMIEA0 to high priority interrupt

  ITU_TCR0  = BIT(5) | BIT(1) | BIT(0); // internal clock/8, clear by GRA
  ITU_TIOR0 = 0;                        // no output on GRA
  ITU_TCR0 &= ~BIT(6);                  // CCLR = 01 = cleared on GRA match
  ITU_TCR0 |=  BIT(5);
  ITU_GRA0 = (INT16U)m;                 // Match count
  ITU_TSR0 = 0;                         // reset flags
  ITU_TIER0 = BIT(0);                   // enable interrupt from GRA
  ITU_TSTR |= BIT(0);                   // start timer 0
}


#pragma interrupt(tmr0)
void OSTickISR(void)
{
  OSIntEnter();

  ITU_TSR0 &= ~BIT(0);                  // Clear interrupt

  if (++AppTmrSwDivCnt >= AppTmrSwDiv)
    {
    OSTimeTick();
    AppTmrSwDivCnt = 0;
    }

  OSIntExit();
}


INT32U MonH8300HFunctionTrap(INT16U funcCode, INT16U param2, INT32U param1)
{
  asm("mov.w    r1,e0");
  asm("mov.l    er2,er1");
  asm("trapa    #1");
}

⌨️ 快捷键说明

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