Skip to content

Commit

Permalink
made variables changed in interrupts volatile
Browse files Browse the repository at this point in the history
  • Loading branch information
W3AXL committed Aug 22, 2024
1 parent 4d96d4a commit 8f3e56f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion fw/v24/inc/sync.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ extern "C" {
extern unsigned long rxValidFrames;
extern unsigned long rxTotalFrames;
extern unsigned long txTotalFrames;
extern enum RxState SyncRxState;
extern volatile enum RxState SyncRxState;

// State machine stuff
enum RxState {
Expand Down
24 changes: 12 additions & 12 deletions fw/v24/src/sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ FIFO_t syncTxFifo = {
};
// Current byte to transmit
uint8_t syncTxByte = 0;
uint8_t syncTxBytePos = 0;
uint8_t syncLastTxByte = 0;
bool syncTxFlag = false;
volatile uint8_t syncTxBytePos = 0;
volatile uint8_t syncLastTxByte = 0;
volatile bool syncTxFlag = false;

// RX fifo buffer
uint8_t syncRxBuf[SYNC_RX_BUF_LEN];
Expand All @@ -49,20 +49,20 @@ FIFO_t syncRxFifo = {
.maxlen = SYNC_RX_BUF_LEN
};
// Current byte being received
uint8_t rxCurrentByte = 0;
uint8_t rxBitCounter = 0;
uint8_t byteStuffed = 255;
volatile uint8_t rxCurrentByte = 0;
volatile uint8_t rxBitCounter = 0;
volatile uint8_t byteStuffed = 255;

// Status variables
enum RxState SyncRxState = SEARCH;
volatile enum RxState SyncRxState = SEARCH;
unsigned int SyncBytesReceived = 0;

// For detecting RX bit stuffing
uint8_t rxOnesCounter = 0;
volatile uint8_t rxOnesCounter = 0;

// For TX bit stuffing
uint8_t txOnesCounter = 0;
uint8_t txLastBit = 0;
volatile uint8_t txOnesCounter = 0;
volatile uint8_t txLastBit = 0;

volatile bool rxMsgInProgress = false;

Expand All @@ -71,7 +71,7 @@ uint16_t rxCurPos = 0;
bool rxMsgStarted = false;
bool rxMsgComplete = false;

unsigned long syncRxTimer = 50; // timer for delay after sync reset/drop/startup
volatile unsigned long syncRxTimer = 50; // timer for delay after sync reset/drop/startup

/**
* @brief Starts the timer interrupt handler
Expand Down Expand Up @@ -442,7 +442,7 @@ void RxBits()
}

/**
* @brief Callback for the 9600 baud timer (actually runs at X2 speed), clocks data in & out
* @brief Callback for the 9600 baud timer interrupt (actually runs at X2 speed), clocks data in & out
*/
void SyncTimerCallback(void)
{
Expand Down

0 comments on commit 8f3e56f

Please sign in to comment.