Example #1
0
/*
*********************************************************************************************************
*                                          STARTUP TASK
*
* Description : This is an example of a startup task.  As mentioned in the book's text, you MUST
*               initialize the ticker only once multitasking has started.
*
* Arguments   : p_arg   is the argument passed to 'AppTaskStart()' by 'OSTaskCreate()'.
*
* Returns     : none
*
* Notes       : 1) The first line of code is used to prevent a compiler warning because 'p_arg' is not
*                  used.  The compiler should not generate any code for this statement.
*********************************************************************************************************
*/
static  void  AppTaskStart (void *p_arg)
{
    OS_ERR  err;

   (void)p_arg;

    BSP_Init();                                                 /* Initialize BSP functions                             */
    BSP_Tick_Init();                                            /* Initialize Tick Services.                            */
    App_OS_SetAllHooks();
    
    MEM_Init();
    DR_Init();

#if OS_CFG_STAT_TASK_EN > 0u
    OSStatTaskCPUUsageInit(&err);                               /* Compute CPU capacity with no task running            */
#endif

#ifdef CPU_CFG_INT_DIS_MEAS_EN
    CPU_IntDisMeasMaxCurReset();
#endif

    DR_LED_Off(0u);                                            /* Turn Off LEDs after initialization                   */

    APP_TRACE_DBG(("Creating Application Kernel Objects\n\r"));
    AppObjCreate();                                             /* Create Applicaiton kernel objects                    */

    APP_TRACE_DBG(("Creating Application Tasks\n\r"));
    AppDataAcqCreate();                                            /* Create Application tasks                             */


    while (DEF_TRUE) {                                          /* Task body, always written as an infinite loop.       */
        DR_LED_On(1u);
        OSTimeDlyHMSM(0u, 0u, 0u, 10u,
                      OS_OPT_TIME_HMSM_STRICT,
                      &err);
        DR_LED_Off(1u);
        OSTimeDlyHMSM(0u, 0u, 1u, 0u,
                      OS_OPT_TIME_HMSM_STRICT,
                      &err);
    }
}
static  void  AppTaskStart (void *p_arg)
{
    OS_ERR  err;


   (void)p_arg;

    BSP_Init();                                                 /* Initialize BSP functions                             */
    CPU_Init();                                                 /* Initialize uC/CPU services                           */

#if OS_CFG_STAT_TASK_EN > 0u
    OSStatTaskCPUUsageInit(&err);                               /* Compute CPU capacity with no task running            */
#endif

    APP_TRACE_DBG(("uCOS-II is Running...\n\r"));

    while (DEF_ON) {                                            /* Task body, always written as an infinite loop.       */
        OSTimeDlyHMSM(0, 0, 1, 0);

        APP_TRACE_DBG(("Time: %d\n\r", OSTimeGet(&err)));
    }
}
static  void  AppTaskGreen (void *p_arg)
{
    OS_ERR    os_err;
    CPU_TS      ts;

    (void)p_arg;

    APP_TRACE_DBG(("listening on kgpiosw2, toggling green led...\n\r"));

    while (DEF_TRUE) {                                          /* Task body, always written as an infinite loop.       */

        OSSemPend(&MySem2,
                         0,
                         OS_OPT_PEND_BLOCKING,
                        &ts,
                        &os_err);

       GPIO_DRV_TogglePinOutput(BOARD_GPIO_LED_GREEN);

    }
}
static void AppTaskStart (void *p_arg)
{
  OS_ERR err;
  CPU_ERR cpu_err;
  uint32_t value;
  static uint32_t pulse_flag = 0;
  CPU_TS64 before, after;
  char tmp[80];
    
  (void)p_arg;

  CPU_Init();
  Mem_Init();
  Math_Init();

  BSP_Ser_Init(115200u);

    while (DEF_ON) {
        GPIO_DRV_TogglePinOutput( outPTB23 );
        value = GPIO_DRV_ReadPinInput( inPTB9 );
        if( value ){
            if(pulse_flag == 0)
                before = CPU_TS_Get64();    // in cpu_cfg.h must set: #define  CPU_CFG_TS_64_EN DEF_ENABLED
            pulse_flag = 1;
            GPIO_DRV_ClearPinOutput( BOARD_GPIO_LED_BLUE );
        }
        else{
            GPIO_DRV_SetPinOutput( BOARD_GPIO_LED_BLUE );
            if(pulse_flag == 1)
            {
                after = CPU_TS_Get64();     // see comment above
                sprintf( tmp, "Elapsed time in Task R = %f s\n\r", (float)((1.0*(after-before))/CPU_TS_TmrFreqGet( &cpu_err )) );
                APP_TRACE_DBG(( tmp ));
            }
            pulse_flag = 0;
        }
        OSTimeDlyHMSM(0u, 0u, 0u, 200u, OS_OPT_TIME_HMSM_STRICT, &err);
        
    }
}
Example #5
0
//Note: This routine do NOT support reentrance
//SPI simulation for FPGA control timing requirement
//31 bits control 31 mics on 4 rulers, 1- enable, 0- disable
//channels[7..0]   : ruler0_mic[7..0]
//channels[15..8]  : ruler1_mic[7..0]
//channels[23..16] : ruler2_mic[7..0]
//channels[31..24] : ruler3_mic[7..0]
void Init_FPGA( unsigned int channels )
{
   
    unsigned int i ;
    
    APP_TRACE_DBG(("\r\nInit FPGA...[0x%0X] \r\n",channels));
    
    PIO_Set(&pinsGpios[20]); //cs 
    PIO_Set(&pinsGpios[21]); //data 
    PIO_Set(&pinsGpios[22]); //clock
    
    for ( i = 0; i < 32; i++ ) {        
       PIO_Clear(&pinsGpios[20]); //cs, delay compensation
       PIO_Clear(&pinsGpios[22]); //clock       
       if( (channels<<i) & 0x80000000 ) {
           PIO_Set(&pinsGpios[21]); //data 
       } else {
           PIO_Clear(&pinsGpios[21]); //data 
       }
       PIO_Set(&pinsGpios[22]); //clock
    }    
    PIO_Set(&pinsGpios[20]); //cs 
    
}
Example #6
0
/*
*********************************************************************************************************
*                                    App_TaskNoah_Ruler()
*
* Description : Process Comminucation between Ruler module and Audio Bridge.
*               Noah protocol layer related data parsing and processing.
*               This task wait for message event from App_TaskUART_Rx(). Check if the Noah layer data is 
*               valid in the message.  
*
* Argument(s) : p_arg   Argument passed to 'App_TaskNoah_Ruler()' by 'OSTaskCreate()'.
*
* Return(s)   : none.
*
* Note(s)     : (1) The first line of code is used to prevent a compiler warning because 'p_arg' is not
*                   used.  The compiler should not generate any code for this statement.
*********************************************************************************************************
*/
void App_TaskNoah_Ruler( void *p_arg )
{ 
    (void)p_arg;
    
    NOAH_CMD   *pPcCmd ;    
    CPU_INT08U *pCmdBuf ;
    CPU_INT08U  rxID ; 
    CPU_INT08U  PcCmdRxID_Ruler[4];
    CPU_INT08U  sum ;  
    CPU_INT08U  SessionDone;
    CPU_INT08U  err ;
    CPU_INT08U *pTaskMsgIN ;  
    CPU_INT08U *pMsg ;  
    
    pTaskMsgIN  = NULL;
    pMsg        = NULL;
    SessionDone = 0 ;    
   
      
    while( DEF_TRUE ) {          
             
        pTaskMsgIN  = (INT8U *)OSQPend( EVENT_MsgQ_RulerUART2Noah, 0, &err ); 
        
        if( pTaskMsgIN != NULL && OS_ERR_NONE == err )   {
           
            pCmdBuf = pTaskMsgIN; // char point to the data buffer
            pPcCmd  = (NOAH_CMD *)pCmdBuf ; //change to NOAH_CMD type
            rxID    = GET_FRAME_ID( pPcCmd->head ) ; //get frame ID, index       
            sum     = pPcCmd->checkSum; //get check sum data  
            
            LED_Toggle(LED_DS2);           
            APP_TRACE_DBG(("\r\n<<"));
            switch( GET_FRAME_TYPE( pPcCmd->head ) ) {// GET_FRAME_TYPE(pPcCmd->head)  get frame type 
                
                case FRAM_TYPE_DATA :  
                    
                    if( (sum == 0) || ( sum == CheckSum(0,pCmdBuf, pPcCmd->DataLen + 2)) ) {   
//                        APP_TRACE_INFO(("R[%d]:[0x%2x>0x%2x][",Global_Ruler_Index,PcCmdRxID_Ruler[Global_Ruler_Index],rxID));
//                        for(unsigned int i = 0; i<pPcCmd->DataLen; i++){   
//                            APP_TRACE_INFO((" %2X", *(unsigned char*)(pPcCmd->Data+i) )); 
//                        }
//                        APP_TRACE_INFO((" ]\r\n")); 
                        pcSendDateToBuf( EVENT_MsgQ_Noah2RulerUART, SET_FRAME_HEAD(rxID,FRAM_TYPE_ACK), NULL, 0, 0, NULL, 0 ) ;  // ACK                                               
                        if( (CPU_INT08U)(PcCmdRxID_Ruler[Global_Ruler_Index]+0x40) == rxID ) { // chweck if frameID repeat  
                            PcCmdRxID_Ruler[Global_Ruler_Index] = rxID ; //save this frameID 
                         
                            err = Noah_CMD_Parse_Ruler( pPcCmd, &SessionDone); // jump to CMD parse 
                            if( (err != OS_ERR_NONE) || (SessionDone == 1) ) {
                                SessionDone = 0;
                                Ruler_CMD_Result = err ;
                                OSTimeDly(2); //wait enough time for ACK to be sent
                                APP_TRACE_DBG((" Res[0x%2x]", Ruler_CMD_Result));
                                OSSemPost( Done_Sem_RulerUART );                                     
                            }
          
                        } else {                      
                            APP_TRACE_DBG(("PcCmdRxID_Ruler[%d] Err: expect 0x%X, get 0x%X",Global_Ruler_Index,PcCmdRxID_Ruler[Global_Ruler_Index]+0x40,rxID)); 
                        }
                        
                    } else {                
                        pcSendDateToBuf( EVENT_MsgQ_Noah2RulerUART, SET_FRAME_HEAD(rxID,FRAM_TYPE_NAK), NULL, 0, 0, NULL, 0 ) ;  // NAK   
                    
                    }                 
                break ;                
          
                    
                case FRAM_TYPE_ESTA :
                  
                    PcCmdRxID_Ruler[Global_Ruler_Index] = 0xC0 ; // ? why 0x40: make sure there can be many same setup frame
                    PcCmdTxID_Ruler[Global_Ruler_Index] = 0x00 ; //  
                    
                    OSSemPost( ACK_Sem_RulerUART );                 
                    OSSemPost( Done_Sem_RulerUART ); //end the resend pending--                     
                    OSTimeDly(1); //wait for the TX buffer is empty 
                    
                    //Reset all UART CMD related buffer and release mem 
                    do{  //reset mem used by  EVENT_MsgQ_RulerUART2Noah                    
                        pMsg   = (INT8U *)OSQAccept( EVENT_MsgQ_Noah2RulerUART, &err );
                        OSMemPut( pMEM_Part_MsgUART, pMsg ); 
                    } while ( pMsg != NULL && OS_ERR_NONE == err ) ; 
                    
                    do{  //reset mem used by  EVENT_MsgQ_RulerUART2Noah                  
                        pMsg   = (INT8U *)OSQAccept( EVENT_MsgQ_RulerUART2Noah, &err );
                        OSMemPut( pMEM_Part_MsgUART, pMsg ); 
                    } while ( pMsg != NULL && OS_ERR_NONE == err ) ; 
                       
                    Queue_Flush( pUART_Send_Buf[RULER_UART] ); //clear uart send&rec data queue
                    Queue_Flush( pUART_Rece_Buf[RULER_UART] );                      
         
                    SessionDone = 0;  //init  
                    OSSemSet( ACK_Sem_RulerUART, 0, &err ); // clear the sem
                    OSSemSet( Done_Sem_RulerUART, 0, &err );
                    test_counter4++;
                    APP_TRACE_DBG(("EST/ESTA"));   
                break ;         
                        
                case FRAM_TYPE_ACK :
                  
                    if( rxID == PcCmdTxID_Ruler[Global_Ruler_Index] ) {                       
                        OSSemPost( ACK_Sem_RulerUART );                        
                        test_counter2++;
                    } else {
                        APP_TRACE_INFO_T(("\r\nACK: Got %X, Expect %X\r\n",rxID,PcCmdTxID_Ruler[Global_Ruler_Index] )); 
                    }
                    APP_TRACE_DBG(("ACK")); 
                    test_counter3++;       
                break ;
                
                case FRAM_TYPE_NAK :
                    // dismiss NAK, there will be a resend if no ACK got
                    // OSSemPost( Done_Sem_RulerUART );
                    test_counter1++;
                    APP_TRACE_DBG(("NAK")); 
                break;
                
                         
                default :    
                break ;              
            } 
            
            //release mem
            OSMemPut( pMEM_Part_MsgUART, pTaskMsgIN );  
           
        }         
        
        ////OSTimeDly(2);   //use OSQPend(), no delay needed!!! 
        
    }        
    
    
}
Example #7
0
static  void  AppTaskStart (void *p_arg)
{
    OS_ERR      err;
    CPU_INT32U  r0;
    CPU_INT32U  r1;
    CPU_INT32U  r2;
    CPU_INT32U  r3;
    CPU_INT32U  r4;
    CPU_INT32U  r5;
    CPU_INT32U  r6;
    CPU_INT32U  r7;
    CPU_INT32U  r8;
    CPU_INT32U  r9;
    CPU_INT32U  r10;
    CPU_INT32U  r11;
    CPU_INT32U  r12;


   (void)p_arg;

    r0  =  0u;                                                  /* Initialize local variables.                          */
    r1  =  1u;
    r2  =  2u;
    r3  =  3u;
    r4  =  4u;
    r5  =  5u;
    r6  =  6u;
    r7  =  7u;
    r8  =  8u;
    r9  =  9u;
    r10 = 10u;
    r11 = 11u;
    r12 = 12u;

    BSP_Init();                                                 /* Initialize BSP functions                             */
    CPU_Init();                                                 /* Initialize the uC/CPU services                       */

#if OS_CFG_STAT_TASK_EN > 0u
    OSStatTaskCPUUsageInit(&err);                               /* Compute CPU capacity with no task running            */
#endif

#ifdef CPU_CFG_INT_DIS_MEAS_EN
    CPU_IntDisMeasMaxCurReset();
#endif

#if (APP_CFG_SERIAL_EN == DEF_ENABLED)
    App_SerialInit();                                           /* Initialize Serial Communication for Application ...  */
#endif

    APP_TRACE_DBG(("Creating Application kernel objects\n\r"));
    AppObjCreate();                                             /* Create Applicaiton kernel objects                    */

    APP_TRACE_DBG(("Creating Application Tasks\n\r"));
    AppTaskCreate();                                            /* Create Application tasks                             */

    BSP_LED_Off(0u);

    while (DEF_TRUE) {                                          /* Task body, always written as an infinite loop.       */
        BSP_LED_Toggle(0u);
        OSTimeDlyHMSM(0u, 0u, 0u, 100u,
                      OS_OPT_TIME_HMSM_STRICT,
                      &err);

        if ((r0  !=  0u) ||                                     /* Check task context.                                  */
            (r1  !=  1u) ||
            (r2  !=  2u) ||
            (r3  !=  3u) ||
            (r4  !=  4u) ||
            (r5  !=  5u) ||
            (r6  !=  6u) ||
            (r7  !=  7u) ||
            (r8  !=  8u) ||
            (r9  !=  9u) ||
            (r10 != 10u) ||
            (r11 != 11u) ||
            (r12 != 12u)) {
           APP_TRACE_INFO(("Context Error\n"));
        }
    }
}