1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-21 11:54:15 +01:00

OP-302 Remove threads from modules that do not need them - Battery Module

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2812 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
FredericG 2011-02-19 18:56:52 +00:00 committed by FredericG
parent 374e822f79
commit c9060393e5

View File

@ -53,15 +53,13 @@
//
// Configuration
//
#define STACK_SIZE 1024
#define TASK_PRIORITY (tskIDLE_PRIORITY + 1)
#define SAMPLE_PERIOD_MS 500
#define POWER_SENSOR_VERSION 1
//#define ENABLE_DEBUG_MSG
#ifdef ENABLE_DEBUG_MSG
#define DEBUG_PORT PIOS_COM_TELEM_RF
#define DEBUG_PORT PIOS_COM_GPS
#define DEBUG_MSG(format, ...) PIOS_COM_SendFormattedString(DEBUG_PORT, format, ## __VA_ARGS__)
#else
#define DEBUG_MSG(format, ...)
@ -70,10 +68,9 @@
// Private types
// Private variables
static xTaskHandle taskHandle;
// Private functions
static void task(void *parameters);
static void onTimer(UAVObjEvent* ev);
/**
* Initialise the module, called on startup
@ -81,31 +78,33 @@ static void task(void *parameters);
*/
int32_t BatteryInitialize(void)
{
// Start main task
xTaskCreate(task, (signed char *)"Battery", STACK_SIZE, NULL, TASK_PRIORITY, &taskHandle);
static UAVObjEvent ev;
memset(&ev,0,sizeof(UAVObjEvent));
EventPeriodicCallbackCreate(&ev, onTimer, SAMPLE_PERIOD_MS / portTICK_RATE_MS);
return 0;
}
/**
* Module thread, should not return.
*/
static void task(void *parameters)
static void onTimer(UAVObjEvent* ev)
{
portTickType lastSysTime;
static portTickType lastSysTime;
static bool firstRun = true;
FlightBatteryStateData flightBatteryData;
#ifdef ENABLE_DEBUG_MSG
if (firstRun) {
#ifdef ENABLE_DEBUG_MSG
PIOS_COM_ChangeBaud(DEBUG_PORT, 57600);
#endif
lastSysTime = xTaskGetTickCount();
firstRun = false;
}
DEBUG_MSG("Battery Started\n");
#endif
AlarmsSet(SYSTEMALARMS_ALARM_BATTERY, SYSTEMALARMS_ALARM_ERROR);
lastSysTime = xTaskGetTickCount();
while (1) {
#if (POWER_SENSOR_VERSION == 1)
// TODO: Compare with floating point calculations
uint cnt = 0;
@ -144,7 +143,7 @@ static void task(void *parameters)
//calculate the battery parameters
flightBatteryData.Voltage = ((float)PIOS_ADC_PinGet(2)) * 0.008065 * batterySettings.Calibrations[BATTERYSETTINGS_CALIBRATIONS_VOLTAGE]; //in Volts
flightBatteryData.Current = ((float)PIOS_ADC_PinGet(1)) * 0.016113 * batterySettings.Calibrations[BATTERYSETTINGS_CALIBRATIONS_CURRENT]; //in Amps
Bob =dT; // FIXME: something funky happens if I don't do this... Andrew
Bob =dT; // FIXME: something funky happens if I don't do this... Andrew
flightBatteryData.ConsumedEnergy += (flightBatteryData.Current * 1000.0 * dT / 3600.0) ;//in mAh
if (flightBatteryData.Current > flightBatteryData.PeakCurrent)flightBatteryData.PeakCurrent = flightBatteryData.Current; //in Amps
@ -178,8 +177,6 @@ static void task(void *parameters)
FlightBatteryStateSet(&flightBatteryData);
#endif
vTaskDelayUntil(&lastSysTime, SAMPLE_PERIOD_MS / portTICK_RATE_MS);
}
}
/**