embedded/projects/osp-steval-mki109v2/sources/app/sensoracq_t.c
static void SensorDataHandler(InputSensor_t sensorId, uint32_t timeStamp)
{
    MsgAccelData accelData;
    MsgMagData magData;
    MsgGyroData gyroData;
    static uint32_t sMagDecimateCount = 0;
    static uint32_t gyroSampleCount = 0;
    static uint32_t accSampleCount = 0;

#if defined ALGORITHM_TASK || defined ANDROID_COMM_TASK
    MessageBuffer *pMagSample = NULLP;
    MessageBuffer *pAccSample = NULLP;
    MessageBuffer *pGyroSample = NULLP;
#endif

    switch (sensorId)
    {
    case MAG_INPUT_SENSOR:
        if ((sMagDecimateCount++ % MAG_DECIMATE_FACTOR) == 0 )
        {
            /* Read mag Data - reading would clear interrupt also */
            Mag_ReadData( &magData );
            /* Replace time stamp with that captured by interrupt handler */
            magData.timeStamp = timeStamp;
#ifdef ALGORITHM_TASK
            ASF_assert( ASFCreateMessage( MSG_MAG_DATA, sizeof(MsgMagData), &pMagSample ) == ASF_OK );
            pMagSample->msg.msgMagData = magData;
            ASF_assert( ASFSendMessage( ALGORITHM_TASK_ID, pMagSample ) == ASF_OK );
#endif
#ifdef ANDROID_COMM_TASK
            pMagSample = NULLP;
            /* Send sample to Host interface also */
            ASF_assert( ASFCreateMessage( MSG_MAG_DATA, sizeof(MsgMagData), &pMagSample ) == ASF_OK );
            pMagSample->msg.msgMagData = magData;
            ASFSendMessage( ANDROID_COMM_TASK, pMagSample ); // No error check. We are OK to drop messages
#endif
        }
        else
        {
            Mag_ClearDataInt();
        }
        break;

    case GYRO_INPUT_SENSOR:
        if ((gyroSampleCount++ % GYRO_SAMPLE_DECIMATE) == 0)
        {
            /* Read Gyro Data - reading typically clears interrupt as well */
            Gyro_ReadData( &gyroData ); //Reads also clears DRDY interrupt
            /* Replace time stamp with that captured by interrupt handler */
            gyroData.timeStamp = timeStamp;
#ifdef ALGORITHM_TASK
            ASF_assert( ASFCreateMessage( MSG_GYRO_DATA, sizeof(MsgGyroData), &pGyroSample ) == ASF_OK );
            pGyroSample->msg.msgGyroData = gyroData;
            ASF_assert( ASFSendMessage( ALGORITHM_TASK_ID, pGyroSample ) == ASF_OK );
#endif
#ifdef ANDROID_COMM_TASK
            pGyroSample = NULLP;
            /* Send sample to Host interface also */
            ASF_assert( ASFCreateMessage( MSG_GYRO_DATA, sizeof(MsgGyroData), &pGyroSample ) == ASF_OK );
            pGyroSample->msg.msgGyroData = gyroData;
            ASFSendMessage( ANDROID_COMM_TASK, pGyroSample ); // No error check. We are OK to drop messages
#endif
        }
        else
        {
            Gyro_ClearDataInt();
        }
        break;

    case ACCEL_INPUT_SENSOR:
#if defined TRIGGERED_MAG_SAMPLING
        if (accSampleCount % MAG_TRIGGER_RATE_DECIMATE == 0)
        {
            Mag_TriggerDataAcq(); //Mag is triggered relative to Accel to avoid running separate timer
        }
#endif
        if (accSampleCount++ % ACCEL_SAMPLE_DECIMATE == 0)
        {
            /* Read Accel Data - reading typically clears interrupt as well */
            Accel_ReadData( &accelData );
            /* Replace time stamp with that captured by interrupt handler */
            accelData.timeStamp = timeStamp;
#ifdef ALGORITHM_TASK
            ASF_assert( ASFCreateMessage( MSG_ACC_DATA, sizeof(MsgAccelData), &pAccSample ) == ASF_OK );
            pAccSample->msg.msgAccelData = accelData;
            ASF_assert( ASFSendMessage( ALGORITHM_TASK_ID, pAccSample ) == ASF_OK );
#endif
#ifdef ANDROID_COMM_TASK
            pAccSample = NULLP;
            /* Send sample to Host interface also */
            ASF_assert( ASFCreateMessage( MSG_ACC_DATA, sizeof(MsgAccelData), &pAccSample ) == ASF_OK );
            pAccSample->msg.msgAccelData = accelData;
            ASFSendMessage( ANDROID_COMM_TASK, pAccSample ); // No error check. We are OK to drop messages
#endif

        }
        else
        {
            Accel_ClearDataInt();
        }
        break;

    default:
        break;

    }
}
/****************************************************************************************************
 * @fn      SensorDataHandler
 *          Handle data ready indications from ISR for various sensors
 *
 ***************************************************************************************************/
@fn      SensorDataHandler
Handle data ready indications from ISR for various sensors
@fn SensorDataHandler Handle data ready indications from ISR for various sensors
static void SensorDataHandler(InputSensor_t sensorId, uint32_t timeStamp)
{
    MsgAccelData accelData;
    MsgMagData magData;
    MsgGyroData gyroData;
    static uint32_t sMagDecimateCount = 0;
    static uint32_t gyroSampleCount = 0;
    static uint32_t accSampleCount = 0;
#if defined ALGORITHM_TASK || defined ANDROID_COMM_TASK
    MessageBuffer *pMagSample = NULLP;
    MessageBuffer *pAccSample = NULLP;
    MessageBuffer *pGyroSample = NULLP;
#endif
    switch (sensorId)
    {
    case MAG_INPUT_SENSOR:
        if ((sMagDecimateCount++ % MAG_DECIMATE_FACTOR) == 0 )
        {
            Mag_ReadData( &magData );
            magData.timeStamp = timeStamp;
#ifdef ALGORITHM_TASK
            ASF_assert( ASFCreateMessage( MSG_MAG_DATA, sizeof(MsgMagData), &pMagSample ) == ASF_OK );
            pMagSample->msg.msgMagData = magData;
            ASF_assert( ASFSendMessage( ALGORITHM_TASK_ID, pMagSample ) == ASF_OK );
#endif
#ifdef ANDROID_COMM_TASK
            pMagSample = NULLP;
            ASF_assert( ASFCreateMessage( MSG_MAG_DATA, sizeof(MsgMagData), &pMagSample ) == ASF_OK );
            pMagSample->msg.msgMagData = magData;
            ASFSendMessage( ANDROID_COMM_TASK, pMagSample ); 
#endif
        }
        else
        {
            Mag_ClearDataInt();
        }
        break;
    case GYRO_INPUT_SENSOR:
        if ((gyroSampleCount++ % GYRO_SAMPLE_DECIMATE) == 0)
        {
            Gyro_ReadData( &gyroData ); 
            gyroData.timeStamp = timeStamp;
#ifdef ALGORITHM_TASK
            ASF_assert( ASFCreateMessage( MSG_GYRO_DATA, sizeof(MsgGyroData), &pGyroSample ) == ASF_OK );
            pGyroSample->msg.msgGyroData = gyroData;
            ASF_assert( ASFSendMessage( ALGORITHM_TASK_ID, pGyroSample ) == ASF_OK );
#endif
#ifdef ANDROID_COMM_TASK
            pGyroSample = NULLP;
            ASF_assert( ASFCreateMessage( MSG_GYRO_DATA, sizeof(MsgGyroData), &pGyroSample ) == ASF_OK );
            pGyroSample->msg.msgGyroData = gyroData;
            ASFSendMessage( ANDROID_COMM_TASK, pGyroSample ); 
#endif
        }
        else
        {
            Gyro_ClearDataInt();
        }
        break;
    case ACCEL_INPUT_SENSOR:
#if defined TRIGGERED_MAG_SAMPLING
        if (accSampleCount % MAG_TRIGGER_RATE_DECIMATE == 0)
        {
            Mag_TriggerDataAcq(); 
        }
#endif
        if (accSampleCount++ % ACCEL_SAMPLE_DECIMATE == 0)
        {
            Accel_ReadData( &accelData );
            accelData.timeStamp = timeStamp;
#ifdef ALGORITHM_TASK
            ASF_assert( ASFCreateMessage( MSG_ACC_DATA, sizeof(MsgAccelData), &pAccSample ) == ASF_OK );
            pAccSample->msg.msgAccelData = accelData;
            ASF_assert( ASFSendMessage( ALGORITHM_TASK_ID, pAccSample ) == ASF_OK );
#endif
#ifdef ANDROID_COMM_TASK
            pAccSample = NULLP;
            ASF_assert( ASFCreateMessage( MSG_ACC_DATA, sizeof(MsgAccelData), &pAccSample ) == ASF_OK );
            pAccSample->msg.msgAccelData = accelData;
            ASFSendMessage( ANDROID_COMM_TASK, pAccSample ); 
#endif
        }
        else
        {
            Accel_ClearDataInt();
        }
        break;
    default:
        break;
    }
}
static void SensorDataHandler ( InputSensor_t sensorId , uint32_t timeStamp ) { MsgAccelData accelData ; MsgMagData magData ; MsgGyroData gyroData ; static uint32_t sMagDecimateCount = 0 ; static uint32_t gyroSampleCount = 0 ; static uint32_t accSampleCount = 0 ; #if defined ALGORITHM_TASK || defined ANDROID_COMM_TASK MessageBuffer * pMagSample = NULLP ; MessageBuffer * pAccSample = NULLP ; MessageBuffer * pGyroSample = NULLP ; #endif switch ( sensorId ) { case MAG_INPUT_SENSOR : if ( ( sMagDecimateCount ++ % MAG_DECIMATE_FACTOR ) == 0 ) { Mag_ReadData ( & magData ) ; magData . timeStamp = timeStamp ; #ifdef ALGORITHM_TASK ASF_assert ( ASFCreateMessage ( MSG_MAG_DATA , sizeof ( MsgMagData ) , & pMagSample ) == ASF_OK ) ; pMagSample -> msg . msgMagData = magData ; ASF_assert ( ASFSendMessage ( ALGORITHM_TASK_ID , pMagSample ) == ASF_OK ) ; #endif #ifdef ANDROID_COMM_TASK pMagSample = NULLP ; ASF_assert ( ASFCreateMessage ( MSG_MAG_DATA , sizeof ( MsgMagData ) , & pMagSample ) == ASF_OK ) ; pMagSample -> msg . msgMagData = magData ; ASFSendMessage ( ANDROID_COMM_TASK , pMagSample ) ; #endif } else { Mag_ClearDataInt ( ) ; } break ; case GYRO_INPUT_SENSOR : if ( ( gyroSampleCount ++ % GYRO_SAMPLE_DECIMATE ) == 0 ) { Gyro_ReadData ( & gyroData ) ; gyroData . timeStamp = timeStamp ; #ifdef ALGORITHM_TASK ASF_assert ( ASFCreateMessage ( MSG_GYRO_DATA , sizeof ( MsgGyroData ) , & pGyroSample ) == ASF_OK ) ; pGyroSample -> msg . msgGyroData = gyroData ; ASF_assert ( ASFSendMessage ( ALGORITHM_TASK_ID , pGyroSample ) == ASF_OK ) ; #endif #ifdef ANDROID_COMM_TASK pGyroSample = NULLP ; ASF_assert ( ASFCreateMessage ( MSG_GYRO_DATA , sizeof ( MsgGyroData ) , & pGyroSample ) == ASF_OK ) ; pGyroSample -> msg . msgGyroData = gyroData ; ASFSendMessage ( ANDROID_COMM_TASK , pGyroSample ) ; #endif } else { Gyro_ClearDataInt ( ) ; } break ; case ACCEL_INPUT_SENSOR : #if defined TRIGGERED_MAG_SAMPLING if ( accSampleCount % MAG_TRIGGER_RATE_DECIMATE == 0 ) { Mag_TriggerDataAcq ( ) ; } #endif if ( accSampleCount ++ % ACCEL_SAMPLE_DECIMATE == 0 ) { Accel_ReadData ( & accelData ) ; accelData . timeStamp = timeStamp ; #ifdef ALGORITHM_TASK ASF_assert ( ASFCreateMessage ( MSG_ACC_DATA , sizeof ( MsgAccelData ) , & pAccSample ) == ASF_OK ) ; pAccSample -> msg . msgAccelData = accelData ; ASF_assert ( ASFSendMessage ( ALGORITHM_TASK_ID , pAccSample ) == ASF_OK ) ; #endif #ifdef ANDROID_COMM_TASK pAccSample = NULLP ; ASF_assert ( ASFCreateMessage ( MSG_ACC_DATA , sizeof ( MsgAccelData ) , & pAccSample ) == ASF_OK ) ; pAccSample -> msg . msgAccelData = accelData ; ASFSendMessage ( ANDROID_COMM_TASK , pAccSample ) ; #endif } else { Accel_ClearDataInt ( ) ; } break ; default : break ; } }
@fn      SensorDataHandler
          Handle data ready indications from ISR for various sensors
@fn SensorDataHandler Handle data ready indications from ISR for various sensors
/* Read mag Data - reading would clear interrupt also */ /* Replace time stamp with that captured by interrupt handler */ /* Send sample to Host interface also */ // No error check. We are OK to drop messages /* Read Gyro Data - reading typically clears interrupt as well */ //Reads also clears DRDY interrupt /* Replace time stamp with that captured by interrupt handler */ /* Send sample to Host interface also */ // No error check. We are OK to drop messages //Mag is triggered relative to Accel to avoid running separate timer /* Read Accel Data - reading typically clears interrupt as well */ /* Replace time stamp with that captured by interrupt handler */ /* Send sample to Host interface also */ // No error check. We are OK to drop messages