Commit 9ed78882 authored by Ian McInerney's avatar Ian McInerney

Made computation rate adjustable over CRTP

parent 11111ee2
......@@ -8,6 +8,7 @@
enum comp_config_codes {
COMP_CONFIG_ENABLE = 0,
COMP_CONFIG_FUNC,
COMP_CONFIG_RATE,
};
enum Computation_channels {
......
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include "crtp.h"
#include "debug.h"
#include "config.h"
......@@ -20,6 +21,9 @@ static CRTPPacket p;
static bool computationEnabled = false;
// Rate at which the computation should run (in Hz)
static uint16_t computationRate;
/**
* Callback for the computation CRTP packet
*/
......@@ -53,6 +57,17 @@ static void Computation_crtpCB(CRTPPacket* pk) {
DEBUG_PRINT("Disabled Computation\n");
}
break;
case COMP_CONFIG_RATE:
// Configure the computation rate
p.header = CRTP_HEADER(CRTP_PORT_COMP, COMP_CHAN_CONFIG);
p.size = 1;
p.data[0] = 1;
// Copy the new computation rate into the variable
memcpy(&computationRate, &(pk->data[1]), sizeof(uint16_t));
break;
case COMP_CONFIG_FUNC:
default:
// Pass the config packet into the callback
......@@ -78,7 +93,7 @@ void Computation_Task() {
lastWakeTime = xTaskGetTickCount();
while(1) {
vTaskDelayUntil(&lastWakeTime, F2T(RATE_100_HZ));
vTaskDelayUntil(&lastWakeTime, F2T(computationRate));
if (computationEnabled) {
// Perform the computations
computation_processing();
......@@ -91,6 +106,9 @@ void Computation_Init() {
crtpInit();
crtpRegisterPortCB(CRTP_PORT_COMP, Computation_crtpCB);
// Default the computation to using a 100Hz rate
computationRate = RATE_100_HZ;
computation_algorithm_init();
// Create the computation task
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment