Пример #1
0
void Assert(OS_BOOL Condition,CONST OS_INT8S File[],OS_INT16U Line)
{
  OS_Assert(Condition, File, "Func", Line);
}
 static void BlackfinCrash( INT errorCode )
 {
     OS_Assert( errorCode );
 }
Пример #3
0
/*---------------------------------------------------------------------------
**
** User_NullProcess()
**
** Null process which always executes as a background task and is lowest
** priority of all processes.
**
**---------------------------------------------------------------------------
**
** Inputs:
**    None
**
** Outputs:
**    None
**
** Usage:
**    User_NullProcess( );
**
**---------------------------------------------------------------------------
*/
void User_NullProcess( void )
{
   BOOL           send_lock;            /* Flag we need to do a Source Lock */
   INT            i;                    /* Loop counter */
   UDINT          adc_data[ IF8I_NUM_CH ];
   LINT           current_dsp_cycles;   /* Diagnostic timestamp */
   LINT           last_cst_update;      /* */
   static ULINT   last_dsp_cycles;
   static UINT    last_rolling;         /* Last rolling timestamp - ensure we only run Over Source on new samples */
   volatile UINT *working_addr;         /* Flash Working address for waiting on Flash burn to finish */
   extern BOOL    new_flash_pending;    /* Flag we need to do a Cal Flash in the background task */
   extern DINT    over_current_timer_expired;     /* How many RTS for timer to expire */
   extern UDINT   rts;                            /* Requested RTS in us */

   extern ADC_CHAN_CFG ADC_config[ IF8I_NUM_CH ];


   /* Init times */
   _GET_CYCLE_COUNT( last_dsp_cycles );
   last_cst_update = last_dsp_cycles;
   
#ifdef  UNIT_TEST
   UnitTestMain();       /* Run standalone unit tests */
#endif

   /* Turns on IMASK bit for all system interrupts */
   sti( OS_INTERRUPTS );

   /* Selftest should be done by the time we get here so set initial state */
   Id_SetState(ID_STATE_NO_CONNS);

   /* Kick scheduler - all tasks will execute & suspend or wait on message Q */
   /* until Null task is scheduled and we return here */
   RESCHEDULE( );
   
   /* ARM Apex/Blackfin watchdog - only enables if Release Build based on ifdef */
   Apex_WatchdogInit( &pHI_ApexIoMem->watchdog );
   Apex_WatchdogKick( );

   /* Null Task loop which runs as the background task when no other task needs to execute */
   while( TRUE )
   {

#ifdef  UNIT_TEST
      UnitTestTask();     /* Run task level unit tests */
#endif

      /* Grab copy of current dsp cycles */
      _GET_CYCLE_COUNT(current_dsp_cycles);

      send_lock = FALSE;
      
      /* Calculate max time between null loops */
      if ( ( ( current_dsp_cycles - last_dsp_cycles ) > max_null_dsp_cycles ) && null_counter )
      {
         max_null_dsp_cycles = current_dsp_cycles - last_dsp_cycles;
      }
      last_dsp_cycles = current_dsp_cycles;
      
      /* Keep track of number of times null task has run */
      null_counter++;
    
      /* Time to update CST and Time Sync data */
      if ( ( current_dsp_cycles - last_cst_update ) > US_TO_CCLK( APP_CST_POLL_RATE ) )
      {
         /* Kick Apex watchdog */
         Apex_WatchdogKick( );
        
         /* Update local copies of CST and Time Sync data */
         APP_UpdateCST( );
         APP_UpdateTimeSyncData( );
         last_cst_update = current_dsp_cycles;
      }

            
      /* Delayed Write to Flash? */
      /* Check if we need to store off the new InputRange/NotchFilter settings */
      if ( new_flash_pending )
      {
         if ( ! waiting_on_erase )
         {
            /* Now erase Cal data (configuration segment) and burn the new values. */
            if ( nvs_FlashDelayEraseSector( (UINT *)CAL_ADDRESS, 0x10000 ) != OK )
            {
               OS_Assert( OS_ASSERT_HW_ERR );
            }
            waiting_on_erase = TRUE;
         }
         /* Go back to the beginning and wait for erase to complete */
         working_addr = (volatile UINT *)( CAL_ADDRESS & FLASH_ADDR_MASK_NO_CARE );
         if ( *working_addr == 0xffff )
         {
            if ( nvs_FlashWrite( (UINT *)CAL_ADDRESS, (UINT *)&cal_flash, sizeof( cal_flash ), TRUE ) != OK )
            {
               OS_Assert( OS_ASSERT_HW_ERR );
            }
            new_flash_pending = FALSE;
         }
      }
      else
      {
         /* Check if we finished a Cal recently - wait at least 1 second before clearing bit */
         /* Only check to clear the CalSuccessful bit if data is written to Flash already */
         for ( i = 0 ; i < IF8I_NUM_CH ; i++ )
         {
            if ( if8i_i.Ch[ i ].CalSuccessful )
            {
               if ( ( if8i_i.timestamp - cal_flash.last_cal_date ) > 1000000 )
               {
                  if8i_i.Ch[ i ].CalSuccessful = FALSE;
               }
            }
         }
      }
      
      
      /* Sourcing Over Current? */
      /* Check for a Sourcing Over Current condition we need to deal with here */
      /* Rolling check ensures a new sample so we only check 1 time per sample */
      if ( last_rolling != if8i_i.rolling )
      {
         last_rolling = if8i_i.rolling;
         for ( i = 0 ; i < IF8I_NUM_CH ; i++ )
         {
            /* Check for a new Over Source condition on any channel */
            /*   Count non-zero & not already locked */
            if ( ( dbase[ i ].Alarm.SourceOverCount > over_current_timer_expired ) &&
                  !dbase[ i ].Alarm.SourceOverLocked )
            {
               /* Flag we found one & flag the channel as locked so Input remains set high */
            	send_lock = TRUE;
         	   dbase[ i ].Alarm.SourceOverLocked = TRUE;
            	/* Clear Sourcing Field Power & VBias Disable bits in AFE Ctrl2 register which should remove over current */
               ADC_config[ i ].chan_reg.afe_cntrl2 &= ~( AFE_FIELD_POWER | AFE_DVBIAS_DIS );
            }
            adc_data[ i ] = ADC_config[ i ].cfg_regs[ 3 ];
         }
         /* Check for flag we need to reconfig on a new lock */
         if ( send_lock )
         {
            /* Reconfigure ADCs to turn off sourcing on Over Current channel(s) */
            /*   Just write the 4th register AFE Ctrl2 */
            if8i_Write_ADCs( adc_data, 3 );
         }
      }
   }
}