forked from AleksandarKostovic/Riscy-SoC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
progmem.c
41 lines (32 loc) · 978 Bytes
/
progmem.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#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)
#define MTIME *((volatile uint64_t *) 0x00030000)
#define MTIMECMP *((volatile uint64_t *) 0x00030008)
#define UART_STATUS_TX_READY 0x1
#define UART_STATUS_RX_READY 0x2
#define FREQ 10000000
#define BAUD_RATE 9600
static void uart_puts(const char *str) {
char c;
while ((c = *str++)) {
while (!(UART_STATUS & UART_STATUS_TX_READY));
UART_DATA = c;
}
}
static inline uint32_t rdcycle(void) {
uint32_t cycle;
asm volatile ("rdcycle %0" : "=r"(cycle));
return cycle;
}
int main() {
UART_BAUD = FREQ / BAUD_RATE;
LEDS = 0xAA;
for (;;) {
uart_puts("Hello everyone!\r\n");
uint32_t start = rdcycle();
while ((rdcycle() - start) <= FREQ);
}
}