icicle/progmem.c

38 lines
841 B
C
Raw Permalink Normal View History

2017-12-15 20:08:55 +00:00
#include <stdint.h>
#define LEDS *((volatile uint32_t *) 0x00010000)
#define UART_BAUD *((volatile uint32_t *) 0x00020000)
#define UART_STATUS *((volatile uint32_t *) 0x00020004)
#define UART_DATA *((volatile int32_t *) 0x00020008)
2017-12-26 13:46:20 +00:00
#define UART_STATUS_TX_READY 0x1
#define UART_STATUS_RX_READY 0x2
2018-01-01 14:39:05 +00:00
#define BAUD_RATE 9600
2017-12-26 13:46:20 +00:00
static void uart_puts(const char *str) {
char c;
while ((c = *str++)) {
while (!(UART_STATUS & UART_STATUS_TX_READY));
UART_DATA = c;
}
}
2017-12-29 16:09:41 +00:00
static inline uint32_t rdcycle(void) {
uint32_t cycle;
2017-12-29 17:09:53 +00:00
asm volatile ("rdcycle %0" : "=r"(cycle));
2017-12-29 16:09:41 +00:00
return cycle;
}
2017-12-15 20:08:55 +00:00
int main() {
2018-01-01 14:39:05 +00:00
UART_BAUD = FREQ / BAUD_RATE;
2017-12-26 13:46:20 +00:00
LEDS = 0xAA;
2017-12-15 20:08:55 +00:00
for (;;) {
2017-12-26 13:46:20 +00:00
uart_puts("Hello, world!\r\n");
2017-12-29 16:09:41 +00:00
uint32_t start = rdcycle();
while ((rdcycle() - start) <= FREQ);
2017-12-15 20:08:55 +00:00
}
}