aboutsummaryrefslogtreecommitdiffstats
path: root/fw
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2025-10-23 19:44:16 -0400
committerSam Anthony <sam@samanthony.xyz>2025-10-23 19:44:16 -0400
commit94cdc9ec4e75fc5e55deb394eda4820ba672e3e4 (patch)
treecf0762794d78324cd508cf5e80b5a13351965d63 /fw
parent04fbfdb4fd6bf4118b88867d852e3b29d139c800 (diff)
downloadcan-gauge-interface-94cdc9ec4e75fc5e55deb394eda4820ba672e3e4.zip
enable CLKOUT
Diffstat (limited to 'fw')
-rw-r--r--fw/can.c7
-rw-r--r--fw/system.c2
-rw-r--r--fw/tests/system/can_tx_systest.c2
3 files changed, 7 insertions, 4 deletions
diff --git a/fw/can.c b/fw/can.c
index 2998631..6518f91 100644
--- a/fw/can.c
+++ b/fw/can.c
@@ -12,6 +12,8 @@
// Oscillator startup timeout
#define STARTUP_TIME 128u
+#define TX_RETRIES 10u
+
// Register addresses
typedef enum {
// Config and status
@@ -288,6 +290,7 @@ canTx(const CanFrame *frame) {
// Send
bitModify(REG_TXB0CTRL, TXREQ, TXREQ);
+ k = 0u;
do {
ctrl = read(REG_TXB0CTRL);
if (ctrl & TXERR) {
@@ -295,9 +298,9 @@ canTx(const CanFrame *frame) {
bitModify(REG_TXB0CTRL, TXREQ, 0); // cancel transmission
return FAIL;
}
- } while (ctrl & TXREQ); // transmission in progress
+ } while ((ctrl & TXREQ) && (++k <= TX_RETRIES)); // transmission in progress
- return OK;
+ return (k <= TX_RETRIES) ? OK : FAIL;
}
void
diff --git a/fw/system.c b/fw/system.c
index 720f456..5f7bbb4 100644
--- a/fw/system.c
+++ b/fw/system.c
@@ -9,7 +9,7 @@
#pragma config MCLRE = ON // MCLR Pin Function Select (MCLR pin is MCLR)
#pragma config CP = OFF // Flash Program Memory Code Protection (Program memory code protection is disabled)
#pragma config BOREN = ON // Brown-out Reset Enable (Brown-out Reset enabled)
-#pragma config CLKOUTEN = OFF // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin)
+#pragma config CLKOUTEN = ON // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin)
#pragma config IESO = OFF // Internal/External Switchover Mode (Internal/External Switchover Mode is disabled)
#pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is disabled)
diff --git a/fw/tests/system/can_tx_systest.c b/fw/tests/system/can_tx_systest.c
index a770d06..b1dec17 100644
--- a/fw/tests/system/can_tx_systest.c
+++ b/fw/tests/system/can_tx_systest.c
@@ -49,7 +49,7 @@ main(void) {
void
__interrupt() isr(void) {
if (PIR1bits.TMR1IF) {
- if (++ctr == 23u) { // 1s period
+ if (++ctr == 114u) { // 5s period
(void)canTx(&frame);
ctr = 0u;
}