aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sw/.gitignore12
-rw-r--r--sw/Makefile22
-rw-r--r--sw/config.h21
-rw-r--r--sw/init.c17
-rw-r--r--sw/init.h11
-rw-r--r--sw/main.c38
-rw-r--r--sw/tests/system/eeprom_systest.c21
7 files changed, 102 insertions, 40 deletions
diff --git a/sw/.gitignore b/sw/.gitignore
new file mode 100644
index 0000000..b228a86
--- /dev/null
+++ b/sw/.gitignore
@@ -0,0 +1,12 @@
+*.cmf
+*.d
+*.elf
+*.hex
+*.hxl
+*.lst
+*.o
+*.p1
+*.rlf
+*.s
+*.sdb
+*.sym
diff --git a/sw/Makefile b/sw/Makefile
index 36538cb..b4b0ae9 100644
--- a/sw/Makefile
+++ b/sw/Makefile
@@ -3,22 +3,36 @@ INCLUDES = -I./ -I/home/sam/prog/mla/v2018_11_26/framework/usb/inc
CFLAGS = -mcpu=pic16f1459 -std=c99 $(INCLUDES) -Wall
LDFLAGS =
+SYSTEST_DIR = tests/system
+
OUT = can_gauge
-SRC = $(wildcard *.c)
+SRC = $(shell find . -name "*.c" ! -name "main.c" -maxdepth 1)
HDR = $(wildcard *.h)
-HEX = $(OUT).hex
OBJ = $(SRC:.c=.p1)
+HEX = $(OUT).hex
-$(HEX): $(OBJ)
+SYSTEST_SRC = $(wildcard $(SYSTEST_DIR)/*.c)
+SYSTEST_OBJ = $(notdir $(SYSTEST_SRC:.c=.p1))
+SYSTEST_HEX = $(SYSTEST_OBJ:.p1=.hex)
+
+$(HEX): $(OBJ) main.p1
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
%.p1: %.c
$(CC) $(CFLAGS) -c $<
+$(SYSTEST_HEX): %.hex: %.p1 $(OBJ)
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
+
+$(SYSTEST_OBJ): %.p1: $(SYSTEST_DIR)/%.c
+ $(CC) $(CFLAGS) -c $<
+
clean:
rm -f $(OBJ) $(HEX) *.d *.p1 *.lst *.rlf *.o *.s *.sdb *.sym *.hxl *.elf *.cmf
+systest: $(SYSTEST_HEX)
+
$(OBJ): $(HDR)
-.PHONY: clean
+.PHONY: clean systest
diff --git a/sw/config.h b/sw/config.h
new file mode 100644
index 0000000..f369673
--- /dev/null
+++ b/sw/config.h
@@ -0,0 +1,21 @@
+// CONFIG1
+#pragma config FOSC = INTOSC // Oscillator Selection Bits (INTOSC oscillator: I/O function on CLKIN pin)
+#pragma config WDTE = OFF // Watchdog Timer Enable (WDT disabled)
+#pragma config PWRTE = OFF // Power-up Timer Enable (PWRT disabled)
+#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 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)
+
+// CONFIG2
+#pragma config WRT = OFF // Flash Memory Self-Write Protection (Write protection off)
+#pragma config CPUDIV = NOCLKDIV// CPU System Clock Selection Bit (NO CPU system divide)
+#pragma config USBLSCLK = 48MHz // USB Low SPeed Clock Selection bit (System clock expects 48 MHz, FS/LS USB CLKENs divide-by is set to 8.)
+#pragma config PLLMULT = 3x // PLL Multipler Selection Bit (3x Output Frequency Selected)
+#pragma config PLLEN = ENABLED // PLL Enable Bit (3x or 4x PLL Enabled)
+#pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset)
+#pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.)
+#pragma config LPBOR = OFF // Low-Power Brown Out Reset (Low-Power BOR is disabled)
+#pragma config LVP = ON // Low-Voltage Programming Enable
diff --git a/sw/init.c b/sw/init.c
new file mode 100644
index 0000000..9c89bee
--- /dev/null
+++ b/sw/init.c
@@ -0,0 +1,17 @@
+#include <xc.h>
+
+#include "init.h"
+
+void
+clockInit(void) {
+ OSCCON = 0xFC; // HFINTOSC @ 16MHz, 3x PLL, PLL enabled
+ ACTCON = 0x90; // active clock tuning enabled for USB
+}
+
+void
+pinsInit(void) {
+ // Disable all analog pin functions
+ ANSELA = 0;
+ ANSELB = 0;
+ ANSELC = 0;
+}
diff --git a/sw/init.h b/sw/init.h
new file mode 100644
index 0000000..0dc8dc3
--- /dev/null
+++ b/sw/init.h
@@ -0,0 +1,11 @@
+/* Device: PIC16F1459
+ * Compiler: XC8 v3.00
+ *
+ * Usage:
+ *
+ * #include <xc8.h>
+ * #include "init.h"
+ */
+
+void clockInit(void);
+void pinsInit(void);
diff --git a/sw/main.c b/sw/main.c
index 4d9b2be..cdc3fc2 100644
--- a/sw/main.c
+++ b/sw/main.c
@@ -3,44 +3,10 @@
#include <stdint.h>
#include "types.h"
+#include "init.h"
#include "spi.h"
#include "eeprom.h"
-
-// CONFIG1
-#pragma config FOSC = INTOSC // Oscillator Selection Bits (INTOSC oscillator: I/O function on CLKIN pin)
-#pragma config WDTE = OFF // Watchdog Timer Enable (WDT disabled)
-#pragma config PWRTE = OFF // Power-up Timer Enable (PWRT disabled)
-#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 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)
-
-// CONFIG2
-#pragma config WRT = OFF // Flash Memory Self-Write Protection (Write protection off)
-#pragma config CPUDIV = NOCLKDIV// CPU System Clock Selection Bit (NO CPU system divide)
-#pragma config USBLSCLK = 48MHz // USB Low SPeed Clock Selection bit (System clock expects 48 MHz, FS/LS USB CLKENs divide-by is set to 8.)
-#pragma config PLLMULT = 3x // PLL Multipler Selection Bit (3x Output Frequency Selected)
-#pragma config PLLEN = ENABLED // PLL Enable Bit (3x or 4x PLL Enabled)
-#pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset)
-#pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.)
-#pragma config LPBOR = OFF // Low-Power Brown Out Reset (Low-Power BOR is disabled)
-#pragma config LVP = ON // Low-Voltage Programming Enable
-
-static void
-clockInit(void) {
- OSCCON = 0xFC; // HFINTOSC @ 16MHz, 3x PLL, PLL enabled
- ACTCON = 0x90; // active clock tuning enabled for USB
-}
-
-static void
-pinsInit(void) {
- // Disable all analog pin functions
- ANSELA = 0;
- ANSELB = 0;
- ANSELC = 0;
-}
+#include "config.h"
void
main(void) {
diff --git a/sw/tests/system/eeprom_systest.c b/sw/tests/system/eeprom_systest.c
new file mode 100644
index 0000000..9099345
--- /dev/null
+++ b/sw/tests/system/eeprom_systest.c
@@ -0,0 +1,21 @@
+#include <xc.h>
+
+#include <stdint.h>
+
+#include "types.h"
+#include "init.h"
+#include "spi.h"
+#include "eeprom.h"
+#include "config.h"
+
+void
+main(void) {
+ clockInit();
+ pinsInit();
+ spiInit();
+ eepromInit();
+
+ for (;;) {
+
+ }
+}