Skip to content

Commit

Permalink
Making task build
Browse files Browse the repository at this point in the history
  • Loading branch information
nwdepatie committed Sep 29, 2023
1 parent 75a878b commit 2837d60
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 49 deletions.
6 changes: 3 additions & 3 deletions Core/Inc/monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ void vTempMonitor(void *pv_params);

osThreadId_t temp_monitor_handle;
const osThreadAttr_t temp_monitor_attributes = {
.name = "TempMonitor",
.stack_size = 128 * 4,
.priority = (osPriority_t) osPriorityBelowNormal3,
.name = "TempMonitor",
.stack_size = 128 * 4,
.priority = (osPriority_t) osPriorityBelowNormal3,
};

#endif // MONITOR_H
90 changes: 47 additions & 43 deletions Core/Src/monitor.c
Original file line number Diff line number Diff line change
@@ -1,52 +1,56 @@
#include <sht30.h>
#include <FreeRTOS.h>
#include <string.h>
#include "cerberus_conf.h"
#include "task.h"
#include "can.h"

void vTempMonitor(void *pv_params)
{
static const uint8_t num_samples = 10;

sht30_t temp_sensor;
I2C_HandleTypeDef *hi2c1;
can_msg_t temp_msg = {
.id = CANID_TEMP_SENSOR,
.len = 4, /* bytes */
.line = CAN_LINE_1
};
struct {
uint16_t temperature;
uint16_t humidity;
} sensor_data;


hi2c1 = (I2C_HandleTypeDef *)pv_params;

if (sht30_init(&temp_sensor, &hi2c1)) {
//TODO: Handle error
}

for(;;) {

/* Take measurement */
if (sht30_get_temp_humid(&temp_sensor)) {
//TODO: Handler error
}

/* Run values through LPF of sample size */
sensor_data.temperature = (sensor_data.temperature + temp_sensor.temp)
/ num_samples;
sensor_data.humidity = (sensor_data.humidity + temp_sensor.humidity)
/ num_samples;

/* Send CAN message */
temp_msg.data = (uint8_t *) sensor_data;
if (can_send_message(temp_msg)) {
//TODO: Handle error
}

/* Yield to other tasks */
taskYIELD();
}
static const uint8_t num_samples = 10;
static const uint8_t temp_sensor_sample_delay = 500; /* ms */
static const uint8_t can_msg_len = 4; /* bytes */

sht30_t temp_sensor;
I2C_HandleTypeDef *hi2c1;
can_msg_t temp_msg = {
.id = CANID_TEMP_SENSOR,
.len = can_msg_len,
.line = CAN_LINE_1,
.data = {0}
};

struct {
uint16_t temperature;
uint16_t humidity;
} sensor_data;

hi2c1 = (I2C_HandleTypeDef *)pv_params;

if (sht30_init(&temp_sensor, &hi2c1)) {
//TODO: Handle error
}

for(;;) {

/* Take measurement */
if (sht30_get_temp_humid(&temp_sensor)) {
//TODO: Handler error
}

/* Run values through LPF of sample size */
sensor_data.temperature = (sensor_data.temperature + temp_sensor.temp)
/ num_samples;
sensor_data.humidity = (sensor_data.humidity + temp_sensor.humidity)
/ num_samples;

/* Send CAN message */
memcpy(temp_msg.data, &sensor_data, can_msg_len);
if (can_send_message(temp_msg)) {
//TODO: Handle error
}

/* Yield to other tasks */
osDelayUntil();
}
}
6 changes: 3 additions & 3 deletions Drivers/NER/include/can.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ typedef struct
} can_msg_t;

/* These are the queues for each CAN line */
struct msg_queue* can1_incoming;
struct msg_queue* can2_incoming;
// msg_queue* can3_incoming;
extern struct msg_queue* can1_incoming;
extern struct msg_queue* can2_incoming;
// extern struct msg_queue* can3_incoming;


/* Use this when referencing CAN lines when sending a message */
Expand Down
5 changes: 5 additions & 0 deletions Drivers/NER/src/can.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ CAN_HandleTypeDef* can1;
CAN_HandleTypeDef* can2;
// CAN_HandleTypeDef* can3;

/* These are the queues for each CAN line */
struct msg_queue* can1_incoming;
struct msg_queue* can2_incoming;
// msg_queue* can3_incoming;

/* Used in the Queue implementation - you probably dont need to worry about it */
struct node
{
Expand Down

0 comments on commit 2837d60

Please sign in to comment.