Index: Accel.c =================================================================== diff -u -rf7c61d2d14b40cfbbd2fa8e0968a1f972a39e4e0 -r0f1d0c443daee3e30ae823711e85f3410bbf49fe --- Accel.c (.../Accel.c) (revision f7c61d2d14b40cfbbd2fa8e0968a1f972a39e4e0) +++ Accel.c (.../Accel.c) (revision 0f1d0c443daee3e30ae823711e85f3410bbf49fe) @@ -1,19 +1,19 @@ -/************************************************************************** -* -* Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. -* -* THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN -* WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. -* -* @file Accel.c -* -* @author (last) Sean Nash -* @date (last) 19-Aug-2020 -* -* @author (original) Sean Nash -* @date (original) 29-Jul-2020 -* -***************************************************************************/ +/************************************************************************** +* +* Copyright (c) 2019-2021 Diality Inc. - All Rights Reserved. +* +* THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN +* WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. +* +* @file Accel.c +* +* @author (last) Sean Nash +* @date (last) 16-Nov-2020 +* +* @author (original) Sean Nash +* @date (original) 29-Jul-2020 +* +***************************************************************************/ #include @@ -39,7 +39,7 @@ #define MAX_TILT_ANGLE ( 7.0 ) ///< Maximum tilt of system before alarm #define MIN_TILT_ANGLE_TO_CLEAR_ALARM ( 5.0 ) ///< Minimum tilt of system before alarm is cleared #define MAX_TILT_PERSISTENCE ( 1 * MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< Maximum time (in task intervals) that a tilt in excess of limit can persist before alarm -#define MAX_SHOCK_ACCELERATION ( 2.0 ) ///< Maximum shock (acceleration) measured on any axis before alarm +#define MAX_SHOCK_ACCELERATION ( 4.0 ) ///< Maximum shock (acceleration) measured on any axis before alarm #define MAX_TILT_G ( 1.0 ) ///< Maximum tilt (in g) #define MAX_TILT_ANGLE_DEG ( 90.0 ) ///< Maximum tilt angle (in degrees) @@ -96,9 +96,8 @@ /*********************************************************************//** * @brief * The initAccel function initializes the Accel module. - * @details - * Inputs: none - * Outputs: Accel module initialized + * @details Inputs: none + * @details Outputs: Accel module initialized * @return none *************************************************************************/ void initAccel( void ) @@ -125,9 +124,8 @@ /*********************************************************************//** * @brief * The execAccel function executes the accelerometer monitor state machine. - * @details - * Inputs: accelState - * Outputs: accelState, alarm if software fault happened + * @details Inputs: accelState + * @details Outputs: accelState, alarm if software fault happened * @return none *************************************************************************/ void execAccel( void ) @@ -159,10 +157,9 @@ * @brief * The handleAccelMonitorState function handles the accelerometer monitor * state of the accelerometer monitor state machine. - * @details - * Inputs: accelNoNewSampleTimerCounter, accelFPGASampleCtr, accelAxes, + * @details Inputs: accelNoNewSampleTimerCounter, accelFPGASampleCtr, accelAxes, * accelFPGAFaultReg, accelCalOffsets - * Outputs: accelNoNewSampleTimerCounter, accelFPGASampleCtr, accelAxes + * @details Outputs: accelNoNewSampleTimerCounter, accelFPGASampleCtr, accelAxes * alarm if accelerometer failed * @return next state *************************************************************************/ @@ -211,9 +208,9 @@ accelAxes[ ACCEL_AXIS_X ].data = (F32)x * G_PER_LSB + accelCalOffsets[ ACCEL_AXIS_X ]; accelAxes[ ACCEL_AXIS_Y ].data = (F32)y * G_PER_LSB + accelCalOffsets[ ACCEL_AXIS_Y ]; accelAxes[ ACCEL_AXIS_Z ].data = (F32)z * G_PER_LSB + accelCalOffsets[ ACCEL_AXIS_Z ]; - xMax = (F32)xm * G_PER_LSB; - yMax = (F32)ym * G_PER_LSB; - zMax = (F32)zm * G_PER_LSB; + xMax = fabs( (F32)xm * G_PER_LSB ); + yMax = fabs( (F32)ym * G_PER_LSB ); + zMax = fabs( (F32)zm * G_PER_LSB ); if ( xMax > accelMaxs[ ACCEL_AXIS_X ].data ) { accelMaxs[ ACCEL_AXIS_X ].data = xMax; @@ -241,9 +238,8 @@ * @brief * The getPublishAccelDataInterval function gets the accelerometer vector * data publication interval. - * @details - * Inputs: accelDataPublishInterval - * Outputs: none + * @details Inputs: accelDataPublishInterval + * @details Outputs: none * @return the current accelerometer vector data publication interval * (in priority task periods). *************************************************************************/ @@ -263,9 +259,8 @@ * @brief * The getMeasuredAccelAxis function gets the current magnitude for * the given accelerometer axis. - * @details - * Inputs: accelAxes - * Outputs: alarm if software fault happened + * @details Inputs: accelAxes + * @details Outputs: alarm if software fault happened * @param axis the axis to measure the acceleration from * @return the current magnitude for the given accelerometer axis (in g). *************************************************************************/ @@ -300,9 +295,8 @@ * @brief * The getMaxAccelAxis function gets the current max magnitude for the given * accelerometer axis. - * @details - * Inputs: accelMaxs - * Outputs: alarm software fault if happened + * @details Inputs: accelMaxs + * @details Outputs: alarm software fault if happened * @param axis the axis to get the max acceleration * @return the current maximum magnitude for the given accelerometer axis (in g). *************************************************************************/ @@ -337,9 +331,8 @@ * @brief * The publishAccelData function publishes accelerometer data at the set * interval. - * @details - * Inputs: accelAvgVector, accelTilt, accelAxes, accelDataPublicationTimerCounter - * Outputs: accelAxes, accelDataPublicationTimerCounter + * @details Inputs: accelAvgVector, accelTilt, accelAxes, accelDataPublicationTimerCounter + * @details Outputs: accelAxes, accelDataPublicationTimerCounter * @return none *************************************************************************/ static void publishAccelData( void ) @@ -371,10 +364,9 @@ * @brief * The resetAccelMovingAverage function re-initializes the accelerometer * moving average sample buffer. - * @details - * Inputs: accelReadingsTotal, accelAvgVector, accelReadings, accelReadingsIdx, + * @details Inputs: accelReadingsTotal, accelAvgVector, accelReadings, accelReadingsIdx, * accelReadingsCount - * Outputs: accelReadingsTotal, accelAvgVector, accelReadings, accelReadingsIdx, + * @details Outputs: accelReadingsTotal, accelAvgVector, accelReadings, accelReadingsIdx, * accelReadingsCount * @return none *************************************************************************/ @@ -399,10 +391,9 @@ /*********************************************************************//** * @brief * The filterAccelReadings function adds a new axis samples to the filter. - * @details - * Inputs: accelReadingsCount, accelReadingsTotal, accelReadings, + * @details Inputs: accelReadingsCount, accelReadingsTotal, accelReadings, * accelReadings, accelReadingsCount - * Outputs: accelReadingsCount, accelReadingsTotal, accelReadings, + * @details Outputs: accelReadingsCount, accelReadingsTotal, accelReadings, * accelReadings, accelReadingsCount * @return none *************************************************************************/ @@ -449,9 +440,8 @@ * @brief * The calcVectorLength function calculates the length of a vector with * given vector axis magnitudes. - * @details - * Inputs: none - * Outputs: none + * @details Inputs: none + * @details Outputs: none * @param x X axis magnitude of vector * @param y Y axis magnitude of vector * @param z Z axis magnitude of vector @@ -467,9 +457,8 @@ /*********************************************************************//** * @brief * The checkForTiltError function checks for a tilt error. - * @details - * Inputs: accelTilt, accelTiltErrorTimerCounter - * Outputs: accelTiltErrorTimerCounter, alarm if persistent excessive + * @details Inputs: accelTilt, accelTiltErrorTimerCounter + * @details Outputs: accelTiltErrorTimerCounter, alarm if persistent excessive * tilt detected * @return none *************************************************************************/ @@ -509,9 +498,8 @@ /*********************************************************************//** * @brief * The checkForShockError function checks for a shock error. - * @details - * Inputs: none - * Outputs: alarm if excessive shock detected + * @details Inputs: none + * @details Outputs: alarm if excessive shock detected * @return none *************************************************************************/ static void checkForShockError( void ) @@ -541,9 +529,9 @@ if ( maxAll > MAX_SHOCK_ACCELERATION ) { #ifdef _DG_ - SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DG_SHOCK, (F32)maxAxis, maxAll ) + SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DG_SHOCK, (F32)maxAxis, getMaxAccelAxis( maxAxis ) ) #else - SET_ALARM_WITH_2_F32_DATA( ALARM_ID_HD_SHOCK, (F32)maxAxis, maxAll ) + SET_ALARM_WITH_2_F32_DATA( ALARM_ID_HD_SHOCK, (F32)maxAxis, getMaxAccelAxis( maxAxis ) ) #endif } } @@ -552,9 +540,8 @@ * @brief * The execAccelTest function executes the state machine for the * accelerometer self-test. - * @details - * Inputs: accelSelfTestState, accelCalOffsets - * Outputs: accelSelfTestState, accelCalOffsets, Alarm is self-test failed + * @details Inputs: accelSelfTestState, accelCalOffsets + * @details Outputs: accelSelfTestState, accelCalOffsets, Alarm is self-test failed * @return the current state of the accelerometer self-test. *************************************************************************/ SELF_TEST_STATUS_T execAccelTest( void ) @@ -633,9 +620,8 @@ * @brief * The setAccelCalibration function sets the accelerometer calibration * factors and has them stored in non-volatile memory. - * @details - * Inputs: accelCalOffsets - * Outputs: accelCalOffsets + * @details Inputs: accelCalOffsets + * @details Outputs: accelCalOffsets * @param offsetX offset calibration factor for X axis * @param offsetY offset calibration factor for Y axis * @param offsetZ offset calibration factor for Z axis @@ -669,9 +655,8 @@ * @brief * The getAccelCalibration function retrieves the current accelerometer * calibration factors. - * @details - * Inputs: accelCalOffsets - * Outputs: none + * @details Inputs: accelCalOffsets + * @details Outputs: none * @param offsetX value to populate with X axis offset calibration factor * @param offsetY value to populate with Y axis offset calibration factor * @param offsetZ value to populate with Z axis offset calibration factor @@ -688,9 +673,8 @@ * @brief * The testSetAccelDataPublishIntervalOverride function overrides the * accelerometer data publish interval. - * @details - * Inputs: accelDataPublishInterval - * Outputs: accelDataPublishInterval + * @details Inputs: accelDataPublishInterval + * @details Outputs: accelDataPublishInterval * @param value override accelerometer data publish interval with (in ms) * @return TRUE if override successful, FALSE if not *************************************************************************/ @@ -714,9 +698,8 @@ * @brief * The testResetAccelDataPublishIntervalOverride function resets the * override of the accelerometer data publish interval. - * @details - * Inputs: accelDataPublishInterval - * Outputs: accelDataPublishInterval + * @details Inputs: accelDataPublishInterval + * @details Outputs: accelDataPublishInterval * @return TRUE if override reset successful, FALSE if not *************************************************************************/ BOOL testResetAccelDataPublishIntervalOverride( void ) @@ -737,8 +720,8 @@ * @brief * The testSetAccelAxisOverride function overrides the value of the * specified accelerometer axis with a given value. - * Inputs: accelAxes - * Outputs: accelAxes + * @details Inputs: accelAxes + * @details Outputs: accelAxes * @param axis ID of sensor axis to override for * @param value override value for the given axis * @return TRUE if override successful, FALSE if not @@ -764,9 +747,8 @@ * @brief * The testResetAccelAxisOverride function resets the override of the * specified accelerometer axis. - * @details - * Inputs: accelAxes - * Outputs: accelAxes + * @details Inputs: accelAxes + * @details Outputs: accelAxes * @param axis ID of accelerometer axis to reset override for * @return TRUE if override successful, FALSE if not *************************************************************************/ @@ -791,8 +773,8 @@ * @brief * The testSetAccelMaxOverride function overrides the max. value of the * specified accelerometer axis with a given value. - * Inputs: accelMaxs - * Outputs: accelMaxs + * @details Inputs: accelMaxs + * @details Outputs: accelMaxs * @param axis ID of sensor axis to override for * @param value override value for the given axis maximum * @return TRUE if override successful, FALSE if not @@ -818,9 +800,8 @@ * @brief * The testResetAccelMaxOverride function resets the override of the * specified accelerometer axis maximum. - * @details - * Inputs: accelMaxs - * Outputs: accelMaxs + * @details Inputs: accelMaxs + * @details Outputs: accelMaxs * @param axis ID of accelerometer axis to reset override for * @return TRUE if override successful, FALSE if not *************************************************************************/