📄 main55800.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
***************************************************************************/
extern void at91_irq_handler(void);
#include "ucos-II200/includes.h"
#include "APP.h"
/* allocate memory for tasks' stacks */
#define STACKSIZE 64
//* Include files for EB55
#ifdef AT91M55800
#include "eb55.h"
#include "parts/m55800/lib_m55800.h"
#endif
/* Global Variable */
unsigned int Stack1[STACKSIZE];
unsigned int Stack2[STACKSIZE];
unsigned int Stack3[STACKSIZE];
unsigned int Stack4[STACKSIZE];
unsigned int MainStack[STACKSIZE];
//*----------------------------------------------------------------------------
//* Function Name : Task1
//* Object : Red Led blink (50ms)
//* Input Parameters : none
//* Output Parameters : none
//*----------------------------------------------------------------------------
void Task1(void *Id)
{
char buff[18];
OS_ENTER_CRITICAL();
memset(buff, 0, 18);
sprintf(buff,"\n\rTask1 is called. \n\r");
at91_usart_send_frame (&USART0_DESC,buff,18);
OS_EXIT_CRITICAL();
while(1)
{
at91_pio_write(&PIOB_DESC,
LED1|LED2|LED3,
LED_ON);
Delay(50);
at91_pio_write(&PIOB_DESC,
LED1|LED2|LED3,
LED_OFF);
/* wait a short while */
OSTimeDly(200);
}
}
//*----------------------------------------------------------------------------
//* Function Name : Task2
//* Object : Amber Led blink (80ms)
//* Input Parameters : none
//* Output Parameters : none
//*----------------------------------------------------------------------------
void Task2(void *Id)
{
char buff[18];
OS_ENTER_CRITICAL();
memset(buff, 0, 18);
sprintf(buff,"\n\rTask2 is called. \n\r");
at91_usart_send_frame (&USART0_DESC,buff,18);
OS_EXIT_CRITICAL();
while(1)
{
at91_pio_write(&PIOB_DESC,
LED4|LED5|LED6,
LED_ON);
Delay(50);
at91_pio_write(&PIOB_DESC,
LED4|LED5|LED6,
LED_OFF);
/* wait a short while */
OSTimeDly(150);
}
}
//*----------------------------------------------------------------------------
//* Function Name : Task3
//* Object :
//* Input Parameters : none
//* Output Parameters : none
//*----------------------------------------------------------------------------
void Task3(void *Id)
{
char buff[18];
OS_ENTER_CRITICAL();
memset(buff, 0, 18);
sprintf(buff,"\n\rTask3 is called. \n\r");
at91_usart_send_frame (&USART0_DESC,buff,18);
OS_EXIT_CRITICAL();
while(1)
{
at91_pio_write(&PIOB_DESC,
LED7|LED8,
LED_ON);
Delay(10);
at91_pio_write(&PIOB_DESC,
LED7|LED8,
LED_OFF);
/* wait a short while */
OSTimeDly(100);
}
}
void Task4( void *Id)
{
char i,j,max=0;int times =1;
char buff[30];
OS_ENTER_CRITICAL();
memset(buff, 0, 18);
sprintf(buff,"\n\rTask4 is called. \n\r");
at91_usart_send_frame (&USART0_DESC,buff,18);
OS_EXIT_CRITICAL();
while(1)
{
OS_ENTER_CRITICAL();
memset(buff, 0, 30);
sprintf(buff,"OS running... times=%d \r",times);
OS_EXIT_CRITICAL();
at91_usart_send_frame (&USART0_DESC,buff,30);
times +=1;
/* wait a short while */
OSTimeDly(10);
}
}
//*----------------------------------------------------------------------------
//* 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';
char Id4 = '4';
int *pTC0_IER;
pTC0_IER = (int *)0xfffd0024; /* Interrupt Enable Register */
* pTC0_IER = 0x10;//TC_CPCS; // enable timer counter interrupt
/*
* create the tasks in uC/OS and assign decreasing
* priority to them
*/
OSTaskCreate(Task1, (void *)&Id1, &Stack1[STACKSIZE - 1], 2);
OSTaskCreate(Task2, (void *)&Id2, &Stack2[STACKSIZE - 1], 3);
OSTaskCreate(Task3, (void *)&Id3, &Stack3[STACKSIZE - 1], 4);
//OSTaskCreate(Task4, (void *)&Id4, &Stack4[STACKSIZE - 1], 5);
// 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 ( &PIOB_DESC, LED_MASK, PIO_OUTPUT );
//* define switch at PIO input
at91_pio_open ( &PIOB_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 Id0 = '0';
/* Initialize an ARM Target board */
ARMTargetInit();
/* Hardware and software module related initializations */
SystemInitialization();
/* needed by uC/OS */
OSInit();
OSTimeSet(0);
/* create the start task */
OSTaskCreate(TaskStart, &Id0, &MainStack[STACKSIZE - 1], 0);
//_Link();//memory usage
/* start the operating system */
OSStart();
return(0);
//* End
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -