Skip to content

Commit f750aa6

Browse files
committed
Heartbeat: Implements Chibi thread for Heartbeat system.
This commit implements the Chibi thread for the heartbeat system, blinking the light on the Teensy Bottom Shell periodically while it receives power. It also fixes some errors with documentation comments in the light system.
1 parent 11b607f commit f750aa6

File tree

5 files changed

+45
-4
lines changed

5 files changed

+45
-4
lines changed

platformio.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ build_flags =
2222
;-Isrc/battery
2323
-Isrc/common
2424
;-Isrc/gps
25-
;-Isrc/heartbeat
25+
-Isrc/heartbeat
2626
;-Isrc/inputs
2727
;-Isrc/logging
2828
;-Isrc/misc

src/heartbeat/heartbeat.cpp

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
#include "heartbeat.h"
3+
#include "common.h"
4+
5+
// TODO: this was defined in params.h; should we move this there?
6+
#define THREAD_STACK_SIZE_HEARTBEAT 512
7+
#define THREAD_PRIORITY_HEARTBEAT LOWPRIO
8+
9+
static THD_WORKING_AREA(wa_heartbeat, THREAD_STACK_SIZE_HEARTBEAT);
10+
/**
11+
* @brief Construct a new thd function object to handle sending telemetry data back to pit/base station
12+
*
13+
*/
14+
static THD_FUNCTION(heartbeat, arg) {
15+
(void) arg;
16+
while (true){
17+
digitalWrite(LED_BUILTIN, HIGH);
18+
chThdSleepMilliseconds(1000);
19+
digitalWrite(LED_BUILTIN, LOW);
20+
chThdSleepMilliseconds(1000);
21+
}
22+
}
23+
/**
24+
* @brief One-time call function to set up the heartbeat thread
25+
*
26+
*/
27+
void heartbeatSetup() {
28+
chThdCreateStatic(wa_heartbeat, sizeof(wa_heartbeat),THREAD_PRIORITY_HEARTBEAT, heartbeat, NULL);
29+
}

src/heartbeat/heartbeat.h

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#ifndef HEARTBEAT_H
2+
#define HEARTBEAT_H
3+
4+
/**
5+
* @brief Function that sets up basic heartbeat thread. This thread blinks a
6+
* light on and off with a period of two seconds. Mainly a debug to ensure the
7+
* car isn't dead yet.
8+
*/
9+
void heartbeatSetup();
10+
11+
#endif

src/light/light.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ extern struct {
3030
/**
3131
* @brief Function called in the "setup" phase. Initializes light threads and establishes light state.
3232
* Combination of `lightSetup` and `routerSetup` from TBS.
33-
* @param msg Input CAN message. Assumes correct ID and layout.
3433
*/
3534
void lightSetup();
3635

@@ -52,7 +51,7 @@ void updateRightLight(CAN_message_t msg);
5251
void updateHeadlights(CAN_message_t msg);
5352
/**
5453
* @brief Function to update brake lights based on an already parsed can message. Called in response to a change in the brakes.
55-
* @param msg Input CAN message. Assumes correct ID and layout.
54+
* @param msg Input bool.
5655
*/
5756
void updateBrakeLights(bool msg);
5857

@@ -63,7 +62,7 @@ void updateBrakeLights(bool msg);
6362
void updateBPSLight(CAN_message_t msg);
6463

6564
/**
66-
* @brief
65+
* @brief TODO
6766
*/
6867
void updateYButtonLong(CAN_message_t msg);
6968

src/main.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "common.h"
22
#include "light.h"
3+
#include "heartbeat.h"
34

45
// Initalize CAN ports. See can_setup.h for more info.
56
typedef FlexCAN_T4<CAN1, RX_SIZE_256, TX_SIZE_16> can0;
@@ -9,6 +10,7 @@ can1 MotorCan;
910

1011
void main_setup(){
1112
lightSetup();
13+
heartbeatSetup();
1214
}
1315

1416
void setup(){

0 commit comments

Comments
 (0)