aboutsummaryrefslogtreecommitdiffstats
path: root/fw
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2025-10-23 15:53:20 -0400
committerSam Anthony <sam@samanthony.xyz>2025-10-23 15:53:20 -0400
commit24bce89e4663baaa28332887d5b531fa03ebb252 (patch)
tree35f8b06903724bdaf3cd0ef5b9a3342c06e2fae9 /fw
parent7fab1a08e546953f9f601cc108b1bb981316b344 (diff)
downloadcan-gauge-interface-24bce89e4663baaa28332887d5b531fa03ebb252.zip
can tx systest
Diffstat (limited to 'fw')
-rw-r--r--fw/tests/system/can_tx_systest.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/fw/tests/system/can_tx_systest.c b/fw/tests/system/can_tx_systest.c
new file mode 100644
index 0000000..a770d06
--- /dev/null
+++ b/fw/tests/system/can_tx_systest.c
@@ -0,0 +1,58 @@
+#include <xc.h>
+
+#include <stdbool.h>
+#include <stdint.h>
+
+#include "system.h"
+#include "types.h"
+#include "spi.h"
+#include "can.h"
+
+// Frame to transmit periodically
+static const CanFrame frame = {
+ .id = {
+ .type = CAN_ID_STD,
+ .sid = {0x01, 0x23},
+ },
+ .dlc = 8u,
+ .data = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77},
+ .rtr = false,
+};
+
+static U8 ctr = 0u; // timer
+
+void
+main(void) {
+ sysInit();
+ spiInit();
+ canInit();
+
+ // Setup MCP2515 CAN controller
+ canSetBitTiming(CAN_TIMING_10K);
+ canSetMode(CAN_MODE_NORMAL);
+
+ // Setup TMR1
+ T1CON = 0x31; // Fosc/4, 1:8 prescaler
+ PIE1bits.TMR1IE = 1; // enable interrupts
+ PIR1bits.TMR1IF = 0; // clear flag
+
+ // Enable interrupts
+ INTCON = 0x00; // clear flags
+ INTCONbits.PEIE = 1; // enable peripheral interrupts
+ INTCONbits.GIE = 1; // enable global interrupts
+
+ for (;;) {
+
+ }
+}
+
+void
+__interrupt() isr(void) {
+ if (PIR1bits.TMR1IF) {
+ if (++ctr == 23u) { // 1s period
+ (void)canTx(&frame);
+ ctr = 0u;
+ }
+ PIR1bits.TMR1IF = 0;
+ }
+}