📄 appli.c
字号:
/****************************************************************************
* Appli.c
* Implementation of a simple led blink program with Ucos on a EB01
* Task1 : Red Led blink
* Task2 : Amber Led blink
* Task3 : Green Led blink
*
* - 1.0 21/08/00 EL : Creation
***************************************************************************/
#include "includes.h"
#include "parts/m40400/lib_m40400.h"
#include "parts/m40400/reg_m40400.h"
#include "targets/eb01/eb01.h"
/* allocate memory for tasks' stacks */
#define STACKSIZE 64
/* Global Variable */
unsigned int Stack1[STACKSIZE];
unsigned int Stack2[STACKSIZE];
unsigned int Stack3[STACKSIZE];
unsigned int Stack4[STACKSIZE];
//*----------------------------------------------------------------------------
//* Function Name : Task1
//* Object : Red Led blink (50ms)
//* Input Parameters : none
//* Output Parameters : none
//*----------------------------------------------------------------------------
void Task1(void *i)
{
while(1)
{
/* set LED */
at91_pio_write (&PIO_DESC, LED1, PIO_CLEAR_OUT ) ;
/* wait a short while */
OSTimeDly(5);
/* clear LED */
at91_pio_write (&PIO_DESC, LED1, PIO_SET_OUT ) ;
/* wait a short while */
OSTimeDly(5);
}
}
//*----------------------------------------------------------------------------
//* Function Name : Task2
//* Object : Amber Led blink (80ms)
//* Input Parameters : none
//* Output Parameters : none
//*----------------------------------------------------------------------------
void Task2(void *i)
{
while(1)
{
/* set LED */
at91_pio_write (&PIO_DESC, LED2, PIO_CLEAR_OUT ) ;
/* wait a short while */
OSTimeDly(8);
/* clear LED */
at91_pio_write (&PIO_DESC, LED2, PIO_SET_OUT ) ;
/* wait a short while */
OSTimeDly(8);
}
}
//*----------------------------------------------------------------------------
//* Function Name : Task3
//* Object : Green Led blink (200ms)
//* Input Parameters : none
//* Output Parameters : none
//*----------------------------------------------------------------------------
void Task3(void *i)
{
while(1)
{
/* set LED */
at91_pio_write (&PIO_DESC, LED3, PIO_CLEAR_OUT ) ;
/* wait a short while */
OSTimeDly(20);
/* clear LED */
at91_pio_write (&PIO_DESC, LED3, PIO_SET_OUT ) ;
/* wait a short while */
OSTimeDly(20);
}
}
//*----------------------------------------------------------------------------
//* Function Name : TaskStart
//* Object : First created task with lower priority
//* : Enable timer interrupt
//* : Creation of the other tasks
//* Input Parameters : Task creation arguments
//* Output Parameters : none
//*----------------------------------------------------------------------------
void TaskStart (void *i)
{
char Id1 = '1';
char Id2 = '2';
char Id3 = '3';
TC0_IER = TC_CPCS; // enable timer counter interrupt
/*
* create the tasks in uC/OS and assign decreasing
* priority to them
*/
OSTaskCreate(Task1, &Id1, &Stack1[STACKSIZE - 1], 2);
OSTaskCreate(Task2, &Id2, &Stack2[STACKSIZE - 1], 3);
OSTaskCreate(Task3, &Id3, &Stack3[STACKSIZE - 1], 4);
// Delete current task
OSTaskDel(OS_PRIO_SELF);
}
//*----------------------------------------------------------------------------
//* Function Name : SystemInitialization
//* Object : Setup timer interrupt every 10ms
//* Input Parameters : none
//* Output Parameters : none
//*----------------------------------------------------------------------------
void SystemInitialization (void)
{
u_int timer_value[3] = {0,0,40000}; // 10ms
//* define led at PIO output
at91_pio_open ( &PIO_DESC, LED_MASK, PIO_OUTPUT );
//* define switch at PIO input
at91_pio_open ( &PIO_DESC, SW_MASK, PIO_INPUT );
//* Timer initialization
at91_tc_open(&TC0_DESC, TC_WAVE|TC_CPCTRG|TC_CLKS_MCK8,0,0);
at91_tc_write(&TC0_DESC, timer_value);
at91_tc_trig_cmd(&TC0_DESC, TC_TRIG_CHANNEL);
at91_irq_open(TC0_DESC.periph_id, 7, AIC_SRCTYPE_INT_EDGE_TRIGGERED, OSTickISR);
}
//*----------------------------------------------------------------------------
//* Function Name : main
//* Object : Main function
//* Input Parameters : none
//* Output Parameters : none
//*----------------------------------------------------------------------------
int main( void )
{
char Id4 = '4';
/* Hardware and software module related initializations */
SystemInitialization();
/* needed by uC/OS */
OSInit();
OSTimeSet(0);
/* create the start task */
OSTaskCreate(TaskStart, &Id4, &Stack4[STACKSIZE - 1], 6);
/* start the operating system */
OSStart();
return(0);
//* End
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -