From 7a39f5f55c2ee9fe3034d4f65c20ba392dd142be Mon Sep 17 00:00:00 2001 From: gussy Date: Wed, 2 Dec 2009 21:49:31 +0000 Subject: [PATCH] Added in ADC hooks to OpenPilot. git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@52 ebee16cc-31ac-478f-84a7-5cbb03baadba --- flight/OpenPilot/inc/openpilot.h | 2 ++ flight/OpenPilot/openpilot.c | 23 +++++------------------ flight/PiOS/STM32F10x/pios_adc.c | 2 +- flight/PiOS/pios.c | 31 +++++++++++++++++++++++++++++-- 4 files changed, 37 insertions(+), 21 deletions(-) diff --git a/flight/OpenPilot/inc/openpilot.h b/flight/OpenPilot/inc/openpilot.h index 51e484821..c7c8e34ae 100644 --- a/flight/OpenPilot/inc/openpilot.h +++ b/flight/OpenPilot/inc/openpilot.h @@ -43,5 +43,7 @@ extern void OpenPilotInit(void); extern void vApplicationIdleHook(void); +/* Hooks */ +extern void ADCNotifyChange(uint32_t pin, uint32_t pin_value); #endif /* OPENPILOT_H */ diff --git a/flight/OpenPilot/openpilot.c b/flight/OpenPilot/openpilot.c index 218da915c..02b271ece 100644 --- a/flight/OpenPilot/openpilot.c +++ b/flight/OpenPilot/openpilot.c @@ -29,8 +29,7 @@ /* Local Variables */ -static uint32_t ulIdleCycleCount = 0; -static uint32_t IdleTimePercent = 0; +static uint16_t adc_pin_values[4]; /* Local Functions */ static void ServosTask(void *pvParameters); @@ -67,23 +66,11 @@ static void ServosTask(void *pvParameters) } } - - /** -* Idle hook function +* This hook is called every time the */ -void vApplicationIdleHook(void) +void ADCNotifyChange(uint32_t pin, uint32_t pin_value) { - /* Called when the scheduler has no tasks to run */ - /* In here we could implement full stats for FreeRTOS - Although this would need us to enable stats in FreeRTOS - which is *very* costly. With the function below we can - either print it out or just watch the variable using JTAG */ - - /* This can give a basic indication of how much time the system spends in idle */ - /* IdleTimePercent is the percentage of time spent in idle since the scheduler started */ - /* For example a value of 75 would mean we are spending 75% of FreeRTOS Cycles in idle */ - ulIdleCycleCount++; - IdleTimePercent = ((ulIdleCycleCount / xTaskGetTickCount()) * 100); + /* All we really need to do here is store the values in a local array. */ + adc_pin_values[pin] = (uint16_t) pin_value; } - diff --git a/flight/PiOS/STM32F10x/pios_adc.c b/flight/PiOS/STM32F10x/pios_adc.c index 2ec2fdb05..7664d6c04 100644 --- a/flight/PiOS/STM32F10x/pios_adc.c +++ b/flight/PiOS/STM32F10x/pios_adc.c @@ -192,7 +192,7 @@ int32_t ADCHandler(void *_callback) /* Call application hook */ /* Note that due to dual conversion approach, we have to convert the pin number */ /* If an uneven number of channels selected */ - callback(pin, pin_value); + callback(pin, pin_value); } /* Start next scan */ diff --git a/flight/PiOS/pios.c b/flight/PiOS/pios.c index 60aee74e7..702062d67 100644 --- a/flight/PiOS/pios.c +++ b/flight/PiOS/pios.c @@ -34,6 +34,10 @@ /* Task Priorities */ #define PRIORITY_TASK_HOOKS ( tskIDLE_PRIORITY + 3 ) +/* Local Variables */ +static uint32_t ulIdleCycleCount = 0; +static uint32_t IdleTimePercent = 0; + /* Function Prototypes */ static void HooksTask(void *pvParameters); @@ -45,7 +49,9 @@ int main() { /* Setup Hardware */ SysInit(); - + COMInit(); + ADCInit(); + /* Initialise OpenPilot */ OpenPilotInit(); @@ -77,8 +83,29 @@ static void HooksTask(void *pvParameters) xLastExecutionTime = xCurrentTickCount; } + /* Check for ADC pin changes, call ADCNotifyChange on each pin change */ + ADCHandler(ADCNotifyChange); /* Check for incoming COM messages */ COMReceiveHandler(); } -} \ No newline at end of file +} + + +/** +* Idle hook function +*/ +void vApplicationIdleHook(void) +{ + /* Called when the scheduler has no tasks to run */ + /* In here we could implement full stats for FreeRTOS + Although this would need us to enable stats in FreeRTOS + which is *very* costly. With the function below we can + either print it out or just watch the variable using JTAG */ + + /* This can give a basic indication of how much time the system spends in idle */ + /* IdleTimePercent is the percentage of time spent in idle since the scheduler started */ + /* For example a value of 75 would mean we are spending 75% of FreeRTOS Cycles in idle */ + ulIdleCycleCount++; + IdleTimePercent = ((ulIdleCycleCount / xTaskGetTickCount()) * 100); +}