new-sonar/firmware/hello_world_c/main.c
David Lenfesty 1cfa5a47de firmware: made some rust firmware to test
Had some issues due to lack of startup code (stack pointer was unset,
leading to underflow in address space), so decided to just get the rust
FW started instead of finding some startup code to use.
2023-01-22 15:20:27 -07:00

77 lines
1.3 KiB
C

#include "uart.h"
#include <stdint.h>
#include <stdbool.h>
void write_cstring(const char* string);
void write_char(char c);
void toggle_led();
#define LED *((uint32_t*) 0x01002000)
int main() {
uint32_t i = 0;
bool toggle = false;
for (;;) {
if (i >= 100) {
i = 0;
if (toggle) {
LED = 1;
} else {
LED = 0;
}
}
write_char('H');
write_char('e');
write_char('l');
write_char('l');
write_char('o');
write_char(' ');
write_char('W');
write_char('o');
write_char('r');
write_char('l');
write_char('d');
write_char('!');
write_char('\n');
write_char('\r');
i += 1;
}
}
void write_char(char c) {
//while (!UART0->TXEMPTY);
//// Wait for room to clear up
//if (!UART0->TXFULL) {
// UART0->RXTX = c;
//}
}
void write_cstring(const char* string) {
int i = 0;
for (;;) {
// Return at end of string
if (string[i] == 0) {
return;
}
// Wait for room to clear up
if (!UART0->TXFULL) {
UART0->RXTX = string[i];
}
i += 1;
}
}
void toggle_led() {
LED = !LED;
write_char('0' + LED);
}