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

📄 irq.c

📁 Philips ARM KPC2xxx series Real Time Operating System. Premptive System.
💻 C
字号:
/****************************************************************************** * * Copyright: *    (C) 2000 - 2005 Embedded Artists AB * * Description: *    Sample application that demonstrates the use of timer interrupts *    and how interrupt service routines can signal events to processes. * *****************************************************************************/#include "../pre_emptive_os/api/osapi.h"#include "../pre_emptive_os/api/general.h"#include <printf_P.h>#include <ea_init.h>#include <lpc2xxx.h>#define CONSUMER_STACK_SIZE 1024#define INIT_STACK_SIZE     1024#define MAX_BUFFER_SIZE 500static tU8 consumerStack[CONSUMER_STACK_SIZE];static tU8 initStack[INIT_STACK_SIZE];static tCntSem mySem;static void consumer(void* arg);static void initProc(void* arg);static void initTimer1Irq (void);static void timer1Isr (void);/***************************************************************************** * * Description: *    The first function to execute  * ****************************************************************************/intmain(void){  tU8 error;  tU8 pid;    osInit();  osCreateProcess(initProc, initStack, INIT_STACK_SIZE, &pid, 1, NULL, &error);  osStartProcess(pid, &error);    osStart();  return 0;}/***************************************************************************** * * Description: *    The interrupt service routine that is exectuted whenever a timer *    counter 1 interrupt occurs. This function can be an ordinary *    C-function since the RTOS saves and restores all necessary registers. * ****************************************************************************/static voidtimer1Isr (void){  static tU32 counter = 0;    //  //do some processing, for example fill a buffer with data...  //    //increment counter  counter++;  if (counter == MAX_BUFFER_SIZE)  {    tU8 error;    counter = 0;    osSemGive(&mySem, &error);    if (error != OS_OK)    {      printf("\nERROR: Serious isr error...\n");    }  }  TIMER1_IR   = 0xff;        //reset all IRQ flags
  VICVectAddr = 0x00;        //dummy write to end interrupt
}

/***************************************************************************** * * Description: *    Setup the Timer Counter 1 Interrupt to 500Hz interrupt rate * ****************************************************************************/static voidinitTimer1Irq (void){
  //set up timer
  TIMER1_TCR = 0x01;
  TIMER1_MR0 = 29491 - 1;             //14.7456 MHz % 29491 => 500 Hz
  TIMER1_IR  = 0xff;                  //reset all flags before enable IRQs
  TIMER1_MCR = 0x03;

  //setup VIC
  VICIntSelect &= ~0x20;
  VICIntEnable |=  0x20;
  VICVectAddr5  = (tU32)timer1Isr;
  VICVectCntl5  = 0x25;
}
/***************************************************************************** * * Description: *    Will consume the buffers that are sent from the timer ISR. * * Params: *    [in] arg - This parameter is not used in this application.  * ****************************************************************************/static voidconsumer(void* arg){  tU8 error;  printf("Starting consumer\n");  for(;;)  {    osSemTake(&mySem, 0, &error);    printf("Consumer: consuming imaginary buffer data...\n");  }}/***************************************************************************** * * Description: *    The entry function for the initialization process.  * * Params: *    [in] arg - This parameter is not used in this application.  * ****************************************************************************/static voidinitProc(void* arg){  tU8 error;  tU8 pid;  eaInit();  printf("\n*******************************************************\n");  printf("*                                                     *\n");  printf("* Welcome to the pre-emptive operating system from    *\n");  printf("* Embedded Artists, for the LPC2xxx microcontroller.  *\n");  printf("*                                                     *\n");  printf("* This is a sample application demonstrating how to   *\n");  printf("* create timer interrupts and signal events to        *\n");  printf("* processes.                                          *\n");  printf("*                                                     *\n");  printf("*******************************************************\n");  osSemInit(&mySem, 0);  initTimer1Irq();  osCreateProcess(consumer, consumerStack, CONSUMER_STACK_SIZE, &pid, 3, NULL, &error);  osStartProcess(pid, &error);    osDeleteProcess();}/***************************************************************************** * * Description: *    The timer tick entry function that is called once every timer tick *    interrupt in the RTOS. Observe that any processing in this *    function must be kept as short as possible since this function *    execute in interrupt context. * * Params: *    [in] elapsedTime - The number of elapsed milliseconds since last call. * ****************************************************************************/voidappTick(tU32 elapsedTime){}

⌨️ 快捷键说明

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