From 94cdc9ec4e75fc5e55deb394eda4820ba672e3e4 Mon Sep 17 00:00:00 2001 From: Sam Anthony Date: Thu, 23 Oct 2025 19:44:16 -0400 Subject: enable CLKOUT --- fw/can.c | 7 +++++-- fw/system.c | 2 +- fw/tests/system/can_tx_systest.c | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) (limited to 'fw') 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; } -- cgit v1.2.3