Skip to content

Commit 4040091

Browse files
committed
Current tests
1 parent fc812b1 commit 4040091

8 files changed

Lines changed: 467 additions & 0 deletions

File tree

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Set the prefix for `riscvXX-unknown-elf-*`
2+
# On installations using `multilib`, this will be `riscv64` even for compiling to 32-bit targets
3+
TOOLCHAIN_PREFIX=riscv32-none-elf
4+
#TOOLCHAIN_PREFIX=riscv32
5+
# ARCH=rv32i
6+
ARCH=rv32i_zicsr
7+
8+
# ---- Project Configuration ----
9+
SRCDIR = src
10+
INCDIR = include
11+
SOURCES = $(wildcard $(SRCDIR)/*.c)
12+
PROJECT = current
13+
14+
# ---- Test patterns for project raven ----
15+
16+
.SUFFIXES:
17+
18+
hex: $(PROJECT).hex
19+
20+
$(PROJECT).elf: $(SOURCES) ../sections.lds ../crt0_vex.S
21+
#$(TOOLCHAIN_PREFIX)-gcc -O0 -march=rv32i -Wl,-Bstatic,-T,../sections.lds,--strip-debug -ffreestanding -nostdlib -o $@ ../start.s ../print_io.c $<
22+
$(TOOLCHAIN_PREFIX)-gcc -I../ -I../generated/ -I$(INCDIR) -O0 -mabi=ilp32 -march=$(ARCH) -D__vexriscv__ -Wl,-Bstatic,-T,../sections.lds,--strip-debug -ffreestanding -nostdlib -o $@ ../crt0_vex.S ../isr.c ../stub.c $(SOURCES)
23+
$(TOOLCHAIN_PREFIX)-objdump -D $(PROJECT).elf > $(PROJECT).lst
24+
25+
%.hex: %.elf
26+
$(TOOLCHAIN_PREFIX)-objcopy -O verilog $< $@
27+
sed -ie 's/@1000/@0000/g' $@
28+
29+
%.bin: %.elf
30+
$(TOOLCHAIN_PREFIX)-objcopy -O binary $< $@
31+
32+
client: client.c
33+
gcc client.c -o client
34+
35+
flash: $(PROJECT).hex
36+
python3 ../util/caravel_hkflash.py $(PROJECT).hex
37+
38+
flash2: $(PROJECT).hex
39+
python3 ../util/caravel_flash.py $(PROJECT).hex
40+
41+
show_projectid:
42+
python3 ../util/caravel_projectid.py
43+
44+
# ---- Clean ----
45+
46+
clean:
47+
rm -f $(PROJECT).elf $(PROJECT).hex $(PROJECT).bin $(PROJECT).lst *.vvp *.vcd
48+
49+
.PHONY: clean hex all flash
50+

firmware/chipignite/current/README.md

Whitespace-only changes.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Constants
2+
#define BAUD_RATE 9600
3+
4+
// Variables
5+
String receivedData = "";
6+
unsigned long lastReceiveTime = 0;
7+
const unsigned long DISPLAY_TIMEOUT = 500; // ms
8+
9+
void setup() {
10+
Serial.begin(BAUD_RATE); // Initialize serial communication with computer
11+
Serial1.begin(BAUD_RATE); // Initialize serial communication with chip
12+
13+
Serial.println("Chip Serial Monitor Started");
14+
Serial.println("Waiting for data...");
15+
}
16+
17+
void loop() {
18+
// Read data from the chip
19+
while (Serial1.available() > 0) {
20+
char inByte = Serial1.read();
21+
receivedData += inByte;
22+
lastReceiveTime = millis();
23+
}
24+
25+
// Print complete messages after timeout
26+
if (receivedData.length() > 0 && (millis() - lastReceiveTime > DISPLAY_TIMEOUT)) {
27+
Serial.print("Received: ");
28+
29+
// Print as ASCII
30+
Serial.print("ASCII: \"");
31+
Serial.print(receivedData);
32+
Serial.print("\" | HEX: ");
33+
34+
// Print as HEX
35+
for (int i = 0; i < receivedData.length(); i++) {
36+
char c = receivedData.charAt(i);
37+
if (c < 0x10) Serial.print("0");
38+
Serial.print(c, HEX);
39+
Serial.print(" ");
40+
}
41+
42+
Serial.println();
43+
receivedData = "";
44+
}
45+
46+
// Send data to chip if entered in Serial Monitor
47+
if (Serial.available() > 0) {
48+
String input = Serial.readStringUntil('\n');
49+
Serial1.println(input);
50+
Serial.println("Sent: " + input);
51+
}
52+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* @file slip.h
3+
* @brief GPIO implementation header
4+
*
5+
* Provides functions to interface with the GPIO pins.
6+
*/
7+
8+
#pragma once
9+
10+
#include <stdint.h>
11+
#include <stdbool.h>
12+
13+
/* Begin typedef declarations */
14+
15+
/* Begin function prototype declarations */
16+
17+
bool valid_pin(uint32_t pin);
18+
void gpio_set(uint32_t pin, bool value);
19+
void gpio_clear(uint32_t pin);
20+
void gpio_toggle(uint32_t pin);
21+
bool gpio_get(uint32_t pin);
22+
23+
/* Begin inline function declarations */
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* @file uart.h
3+
* @brief Universal Asynchronous Receiver/Transmitter (UART) implementation header
4+
*
5+
* Provides functions to configure and use the UART for serial communication.
6+
*/
7+
8+
#pragma once
9+
10+
#include <stdint.h>
11+
12+
#define UART_BAUD_RATE 9600
13+
#define CRYSTAL_CLK 10000000
14+
#define UART_CLKDIV ((CRYSTAL_CLK / UART_BAUD_RATE))
15+
16+
/* Begin typedef declarations */
17+
18+
/* Begin function prototype declarations */
19+
#ifdef __cplusplus
20+
extern "C" {
21+
#endif
22+
23+
#define UART_EV_TX 0x1
24+
#define UART_EV_RX 0x2
25+
26+
void uart_init(void);
27+
void uart_sync(void);
28+
29+
void uart_write(uint8_t ch);
30+
uint8_t uart_read(void);
31+
int uart_read_available(void);
32+
int uart_write_available(void);
33+
34+
#ifdef __cplusplus
35+
}
36+
#endif
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
#include <defs.h>
2+
#include <stub.h>
3+
#include <csr.h>
4+
#include "../include/slip.h"
5+
#include "../include/uart.h"
6+
#include "../include/gpio.h"
7+
8+
#define ARRAY_SIZE 100
9+
10+
// --------------------------------------------------------
11+
// Firmware routines
12+
// --------------------------------------------------------
13+
14+
/** @brief Configure the IO pins
15+
*/
16+
void configure_io() {
17+
// ======= Useful GPIO mode values =============
18+
19+
// GPIO_MODE_MGMT_STD_INPUT_NOPULL
20+
// GPIO_MODE_MGMT_STD_INPUT_PULLDOWN
21+
// GPIO_MODE_MGMT_STD_INPUT_PULLUP
22+
// GPIO_MODE_MGMT_STD_OUTPUT
23+
// GPIO_MODE_MGMT_STD_BIDIRECTIONAL
24+
// GPIO_MODE_MGMT_STD_ANALOG
25+
26+
// GPIO_MODE_USER_STD_INPUT_NOPULL
27+
// GPIO_MODE_USER_STD_INPUT_PULLDOWN
28+
// GPIO_MODE_USER_STD_INPUT_PULLUP
29+
// GPIO_MODE_USER_STD_OUTPUT
30+
// GPIO_MODE_USER_STD_BIDIRECTIONAL
31+
// GPIO_MODE_USER_STD_ANALOG
32+
33+
// ======= set each IO to the desired configuration =============
34+
35+
// GPIO 0 is turned off to prevent toggling the debug pin; For debug, make this an output and
36+
// drive it externally to ground.
37+
38+
reg_mprj_io_0 = GPIO_MODE_MGMT_STD_ANALOG;
39+
40+
// Changing configuration for IO[1-4] will interfere with programming flash. if you change them,
41+
// You may need to hold reset while powering up the board and initiating flash to keep the process
42+
// configuring these IO from their default values.
43+
44+
// SPI
45+
reg_mprj_io_1 = GPIO_MODE_MGMT_STD_OUTPUT;
46+
reg_mprj_io_2 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
47+
reg_mprj_io_3 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
48+
reg_mprj_io_4 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
49+
50+
// -------------------------------------------
51+
52+
reg_mprj_io_5 = GPIO_MODE_MGMT_STD_INPUT_NOPULL; // UART Rx
53+
reg_mprj_io_6 = GPIO_MODE_MGMT_STD_OUTPUT; // UART Tx
54+
reg_mprj_io_7 = GPIO_MODE_MGMT_STD_INPUT_NOPULL; // Used for reset
55+
reg_mprj_io_8 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
56+
reg_mprj_io_9 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
57+
reg_mprj_io_10 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
58+
reg_mprj_io_11 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
59+
reg_mprj_io_12 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
60+
reg_mprj_io_13 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
61+
reg_mprj_io_14 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
62+
reg_mprj_io_15 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
63+
reg_mprj_io_16 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
64+
reg_mprj_io_17 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
65+
reg_mprj_io_18 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
66+
67+
reg_mprj_io_19 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
68+
reg_mprj_io_20 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
69+
reg_mprj_io_21 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
70+
reg_mprj_io_22 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
71+
reg_mprj_io_23 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
72+
reg_mprj_io_24 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
73+
reg_mprj_io_25 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
74+
reg_mprj_io_26 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
75+
reg_mprj_io_27 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
76+
reg_mprj_io_28 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
77+
reg_mprj_io_29 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
78+
reg_mprj_io_30 = GPIO_MODE_MGMT_STD_INPUT_PULLUP; // High
79+
reg_mprj_io_31 = GPIO_MODE_MGMT_STD_INPUT_PULLDOWN; // Low
80+
reg_mprj_io_32 = GPIO_MODE_MGMT_STD_INPUT_PULLUP; // High
81+
reg_mprj_io_33 = GPIO_MODE_MGMT_STD_OUTPUT; // Controlled by the code
82+
reg_mprj_io_34 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
83+
reg_mprj_io_35 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
84+
reg_mprj_io_36 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
85+
reg_mprj_io_37 = GPIO_MODE_MGMT_STD_INPUT_NOPULL;
86+
87+
// Initialize UART
88+
uart_init();
89+
90+
// Initiate the serial transfer to configure IO
91+
reg_mprj_xfer = 1;
92+
while (reg_mprj_xfer == 1);
93+
}
94+
95+
/** @brief Delay in microseconds
96+
*
97+
* @param d Delay in microseconds.
98+
*/
99+
void delay(const int d) {
100+
/* Configure timer for a single-shot countdown */
101+
reg_timer0_config = 0;
102+
reg_timer0_data = d;
103+
reg_timer0_config = 1;
104+
105+
// Loop, waiting for value to reach zero
106+
reg_timer0_update = 1; // latch current value
107+
while (reg_timer0_value > 0) { reg_timer0_update = 1; }
108+
}
109+
110+
/** @brief Turn off the LED
111+
*/
112+
void led_off() { reg_gpio_out = 1; }
113+
114+
/** @brief Turn on the LED
115+
*/
116+
void led_on() { reg_gpio_out = 0; }
117+
118+
/** @brief Entry point
119+
*/
120+
void main() {
121+
// Initialize GPIO
122+
reg_gpio_mode1 = 1;
123+
reg_gpio_mode0 = 0;
124+
reg_gpio_ien = 1;
125+
reg_gpio_oe = 1;
126+
127+
// Configure IO pins including UART pins
128+
configure_io();
129+
130+
// Configure All LA probes as inputs to the cpu
131+
reg_la0_oenb = reg_la0_iena = 0x00000000; // [31:0]
132+
reg_la1_oenb = reg_la1_iena = 0x00000000; // [63:32]
133+
reg_la2_oenb = reg_la2_iena = 0x00000000; // [95:64]
134+
reg_la3_oenb = reg_la3_iena = 0x00000000; // [127:96]
135+
136+
// write data to la output
137+
// reg_la0_data = 0x00;
138+
// reg_la1_data = 0x00;
139+
// reg_la2_data = 0x00;
140+
// reg_la3_data = 0x00;
141+
142+
// read data from la input
143+
// data0 = reg_la0_data;
144+
// data1 = reg_la1_data;
145+
// data2 = reg_la2_data;
146+
// data3 = reg_la3_data;
147+
148+
bool pulse = false;
149+
150+
// Turn off all GPIO outputs
151+
reg_mprj_datah = 0x00000000; // Set all high pins (32-37) low
152+
reg_mprj_datal = 0x00000000; // Set all low pins (0-31) low
153+
154+
// Define a static array of items initialized to zero
155+
static uint8_t zero_array[ARRAY_SIZE] = {0};
156+
157+
// Main loop - echo received characters and blink LED and
158+
while (true) {
159+
if (!pulse) {
160+
led_off();
161+
// Set GPIO 33 low (bit 1)
162+
gpio_clear(33);
163+
} else {
164+
led_on();
165+
// Set GPIO 33 high (bit 1)
166+
gpio_set(33, true);
167+
}
168+
pulse = !pulse;
169+
170+
// For every non-zero element in the array, set back to zero and send a packet to the host
171+
for (uint32_t i = 0; i < (uint32_t)(sizeof(zero_array) / sizeof(*zero_array)); i++) {
172+
if (zero_array[i] != 0) {
173+
// When a non-zero element is found (due to radiation), send a packet to the host
174+
struct {
175+
uint8_t* base_address; // base address of the array
176+
uint8_t index; // index of the non-zero element
177+
uint8_t value; // value of the non-zero element
178+
} carp_data = {zero_array, i, zero_array[i]};
179+
180+
slip_send_packet((uint8_t*)&carp_data, sizeof(carp_data), SLIP_CMD_DATA, uart_write);
181+
zero_array[i] = 0;
182+
}
183+
}
184+
185+
// Wait for 1 second
186+
delay(10000000);
187+
}
188+
}

0 commit comments

Comments
 (0)