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

📄 app.c

📁 Contains code for freertos port to AT91SAM7X512.Anybody can use these codes for non commercial use o
💻 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		        ( 8 )   
#define MY_TASK_PRIORITY	        ( 7 )
#define SEM_TASK1_PRIORITY              ( 6 )
#define SEM_TASK2_PRIORITY              ( 5 )
#define SEM_TASK3_PRIORITY              ( 4 )
#define USB_PRIORITY                    ( 3 )    
#define INTERRUPT_TASK_PRIORITY         ( 2 ) 

#define UIP_TASK_STACK_SIZE	          100 
#define MY_TASK_STACK_SIZE	          100
#define USB_TASK_STACK_SIZE               100
#define INTERRUPT_TASK_STACK_SIZE         100
#define SEM_TASKS_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 );
void sem_task1( void *pvParameters );
void sem_task2( void *pvParameters );
void sem_task3( void *pvParameters );


unsigned int ISR_flag = IRQ_NOTUSED ;
xSemaphoreHandle bSem1  = NULL ;
xSemaphoreHandle mutex_1 = NULL ;

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 );
        //-------------------------------------------------
        xTaskCreate( sem_task1,
                     "semtask1",
                     SEM_TASKS_STACK_SIZE,
                     NULL,
                     SEM_TASK1_PRIORITY,
                     NULL );
         xTaskCreate( sem_task2,
                     "semtask2",
                     SEM_TASKS_STACK_SIZE,
                     NULL,
                     SEM_TASK2_PRIORITY,
                     NULL );
          xTaskCreate( sem_task3,
                     "semtask3",
                     SEM_TASKS_STACK_SIZE,
                     NULL,
                     SEM_TASK3_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();
    for( ;; )
     {
             vTaskDelayUntil( &last_unblocked_time, freq );    // Wait for the next cycle.
             last_unblocked_time = xTaskGetTickCount();
         
      }
}
//--------------------------------------------------------------
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
  
}
//------------------------------------------------------------------------------
void sem_task1( void *pvParameters ){
  
  
  static unsigned long  last_unblocked_time;
  static const portTickType freq = 100;   // in ms
  
   last_unblocked_time = xTaskGetTickCount();
  // vSemaphoreCreateBinary( bSem1 );          
   bSem1 = xSemaphoreCreateMutex();  
  for( ;; ){
    
     last_unblocked_time = xTaskGetTickCount();
     vTaskDelayUntil( &last_unblocked_time, freq );    // Wait for the next cycle.
     xSemaphoreTake( bSem1, portMAX_DELAY );
     UART0_Printk("\n\rsem_task1 got bsem1");
     xSemaphoreGive( bSem1 );                   
  }
}
//------------------------------------------------------------------------------
void sem_task2( void *pvParameters ){
  static unsigned long  last_unblocked_time;
  static const portTickType freq = 200 ;   // in ms
  last_unblocked_time = xTaskGetTickCount();
  UART0_Printk("\n\rInside sem_task2");
  for( ;; ){
      vTaskDelayUntil( &last_unblocked_time, freq );    
      last_unblocked_time = xTaskGetTickCount(); 
         if( xSemaphoreTake( bSem1, portMAX_DELAY ) == pdTRUE ) {
                            UART0_Printk("\n\rsem_task2 got bsem1");
                             xSemaphoreGive( bSem1 ); 
        }
  }
}
//------------------------------------------------------------------------------
void sem_task3( void *pvParameters ){
    static unsigned long  last_unblocked_time;
    static const portTickType freq = 200 ;   // in ms
    last_unblocked_time = xTaskGetTickCount();
  //  UART0_Printk("\n\rInside sem_task2"); 
    for( ;; ){
     vTaskDelayUntil( &last_unblocked_time, freq );    
      last_unblocked_time = xTaskGetTickCount(); 
      if( xSemaphoreTake( bSem1, portMAX_DELAY ) == pdTRUE ) {
                            UART0_Printk("\n\rsem_task3 got bsem1");
                             xSemaphoreGive( bSem1 ); 
      }
  }
}
//------------------------------------------------------------------------------

⌨️ 快捷键说明

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