uart: add ledctrl app
This commit is contained in:
parent
b8ee42bfc2
commit
2f210dd561
3
uart/led.h
Normal file
3
uart/led.h
Normal file
@ -0,0 +1,3 @@
|
||||
#define LED_ADDR ((volatile char*)0xC000)
|
||||
|
||||
#define led_write(x) (*LED_ADDR = (x))
|
24
uart/ledctrl.c
Normal file
24
uart/ledctrl.c
Normal file
@ -0,0 +1,24 @@
|
||||
#include "led.h"
|
||||
#include "uart.h"
|
||||
|
||||
int main() {
|
||||
int c;
|
||||
int led = 0;
|
||||
|
||||
while (1) {
|
||||
led_write(1 << led);
|
||||
c = uart_read();
|
||||
|
||||
if (c == 'a') {
|
||||
led++;
|
||||
} else if (c == 'd') {
|
||||
led--;
|
||||
}
|
||||
|
||||
if (led == 8) {
|
||||
led = 0;
|
||||
} else if (led < 0) {
|
||||
led = 7;
|
||||
}
|
||||
}
|
||||
}
|
15
uart/makefile
Normal file
15
uart/makefile
Normal file
@ -0,0 +1,15 @@
|
||||
CC = ../bin/cc
|
||||
LD = ../bin/ld
|
||||
|
||||
all: echo.vhdl.inc ledctrl.vhdl.inc
|
||||
|
||||
echo.vhdl.inc: echo.o uart.o
|
||||
ledctrl.vhdl.inc: ledctrl.o uart.o
|
||||
|
||||
%.vhdl.inc:
|
||||
$(LD) -o $@ --vhdl $^
|
||||
|
||||
PHONY: clean
|
||||
|
||||
clean:
|
||||
rm -rf *.o *.vhdl.inc
|
11
uart/util.c
Normal file
11
uart/util.c
Normal file
@ -0,0 +1,11 @@
|
||||
#define CYCLES_PER_MS 6666 // ish
|
||||
|
||||
/** waits a general amount of time */
|
||||
void busy_sleep(int ms) {
|
||||
for (int i = 0; i < ms; ++i) {
|
||||
// wait for 1 ms
|
||||
for (int i = 0; i < CYCLES_PER_MS; ++i) {
|
||||
// nothing
|
||||
}
|
||||
}
|
||||
}
|
2
uart/util.h
Normal file
2
uart/util.h
Normal file
@ -0,0 +1,2 @@
|
||||
/** waits a general amount of time */
|
||||
void busy_sleep(int ms);
|
Loading…
Reference in New Issue
Block a user