📄 app.c
字号:
/*
Creates all the application tasks, then starts the scheduler.
A task is also created called "uIP". This executes the uIP stack and small
WEB server sample. All the other tasks are from the set of standard
demo tasks. The WEB documentation provides more details of the standard
demo application tasks.
*/
/* Standard includes. */
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <stdio.h>
/* Scheduler includes. */
#include "FreeRTOS.h"
#include "task.h"
#include "semphr.h"
//#include "queue.h"
/* application includes. */
#include "uip_task.h"
#include "Board.h"
#include "App.h"
/* Priorities/stacks for the application tasks. */
#define UIP_PRIORITY ( 4 )
#define MY_TASK_PRIORITY ( 3 )
#define USB_PRIORITY ( 2 )
#define INTERRUPT_TASK_PRIORITY ( 1 )
#define UIP_TASK_STACK_SIZE 200
#define MY_TASK_STACK_SIZE 100
#define USB_TASK_STACK_SIZE 100
#define INTERRUPT_TASK_STACK_SIZE 100
#define LONG_TIME 0xffff
static void SetupHardware( void );
void my_task( void *pvParameters );
void interrupt_task( void *pvParameters );
void USBDemoTask( void *pvParameters );
unsigned int ISR_flag = IRQ_NOTUSED ;
xQueueHandle Queue1;
unsigned portLONG ulVar = 10;
int main( void )
{
SetupHardware();
UART0_Printk("%c%c%c%c%c%c" ,0x1B,0x5B,0x32,0x4A,0x1B,0x63 ); //clear screen.
UART0_Printk("\n\n\r\t\t AT91SAM7X512 FREE RTOS V 5.1.0 Testing . . . \n\n");
//------------------------------------------------------------------------
xTaskCreate( vuIP_TASK, // Start the task that handles the TCP/IP and WEB server functionality.
"uIP",
UIP_TASK_STACK_SIZE,
NULL,
UIP_PRIORITY,
NULL );
//-------------------------------------------------
xTaskCreate( my_task,
"MY TASK",
MY_TASK_STACK_SIZE,
NULL,
MY_TASK_PRIORITY,
NULL );
//-------------------------------------------------
xTaskCreate( USBDemoTask,
"USBtsk",
USB_TASK_STACK_SIZE,
NULL,
USB_PRIORITY,
NULL );
//-------------------------------------------------
xTaskCreate( interrupt_task,
"ISR_tsk",
INTERRUPT_TASK_STACK_SIZE,
NULL,
INTERRUPT_TASK_PRIORITY,
NULL );
//-------------------------------------------------
vTaskStartScheduler(); // Now all the tasks have been started - start the scheduler.
return 0;
}
/*-----------------------------------------------------------*/
static void SetupHardware( void )
{
/* Enable the peripheral clock. */
AT91F_PMC_EnablePeriphClock( AT91C_BASE_PMC, 1 << AT91C_ID_PIOA );
AT91F_PMC_EnablePeriphClock( AT91C_BASE_PMC, 1 << AT91C_ID_EMAC ) ;
AT91F_PMC_EnablePeriphClock( AT91C_BASE_PMC, 1 << AT91C_ID_PIOB ) ;
AT91C_BASE_AIC->AIC_EOICR = 0;
UART0_init();
}
//--------------------------------------------------------------
void my_task( void *pvParameters ){
static unsigned long last_unblocked_time;
static const portTickType freq = 200 ; // in ms
last_unblocked_time = xTaskGetTickCount();
Queue1 = xQueueCreate( 1 , sizeof( unsigned portLONG ) );
if( Queue1 == 0 )
{
UART0_Printk( "\n\r queue not created ... killed process ");
for(;;); //trapped here.
}
for( ;; )
{
vTaskDelayUntil( &last_unblocked_time, freq ); // Wait for the next cycle.
last_unblocked_time = xTaskGetTickCount();
if( xQueueSend( Queue1 , ( void * ) &ulVar, ( portTickType ) 10 ) != pdPASS ){
//Failed to post the message, even after 10 ticks.
}
}
}
//--------------------------------------------------------------
void interrupt_task( void *pvParameters ){
unsigned long last_unblocked_time;
static unsigned char temp0;
const portTickType freq = 100 ; //in ms
last_unblocked_time = xTaskGetTickCount();
for(;;)
{ //---------------delay needed ---------------
vTaskDelayUntil( &last_unblocked_time, freq );
last_unblocked_time = xTaskGetTickCount();
//-------------------------------------------
switch(ISR_flag) {
case US0_int :
temp0 = (char)AT91C_BASE_US0->US_RHR;
UART0_Printk( "\r\tUART0 RECEIVED --> [%c]", temp0 );
if( temp0 == '0'){
UART0_Printk("%c%c%c%c%c%c" ,0x1B,0x5B,0x32,0x4A,0x1B,0x63 ); //clear screen.
UART0_Printk("\n\n\r\t\t AT91SAM7X512 FREE RTOS V 5.1.0 Testing . . . \n\n");
}
ISR_flag = IRQ_NOTUSED ;
break;
case US1_int :
temp0 = (char)AT91C_BASE_US1->US_RHR;
// UART1_Printk( "\r\tUART1 RECEIVED --> [%c]", temp0 );
ISR_flag = IRQ_NOTUSED ;
break;
default:
break;
}
}//end of while
}
//------------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -