-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathfirmware.c
61 lines (51 loc) · 1.21 KB
/
firmware.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <stdint.h>
#define reg_uart_clkdiv (*(volatile uint32_t*)0x60000000)
#define reg_uart_data (*(volatile uint32_t*)0x60000004)
#define reg_led (*(volatile uint8_t*)0x60000008)
//#define SIMULATION
void putchar(char c)
{
if (c == '\n')
putchar('\r');
reg_uart_data = c;
#ifndef SIMULATION
// FIXME [gls]: minimum value we get away here should inform the
// size of the buffer we need to use in the mmio behav_sram module!
for (volatile int i = 0; i < 2000; i++);
#endif
}
void print(const char *p)
{
while (*p)
putchar(*(p++));
}
void print_uint_bin(unsigned int num)
{
for (int i = 0; i < 32; i++, num <<= 1)
putchar((num & 0x80000000) ? '1' : '0');
putchar('\n');
}
// Simulation is much slower, so we want a much shorter delay.
// Uncomment the following line to see LED activity during simulation:
#ifdef SIMULATION
#define DELAY 0x05
#else // FPGA synthesis
#define DELAY 0x200000
#endif
void delay(void)
{
for (volatile int i = 0; i < DELAY; i++);
}
int main(int argc, char *argv[])
{
// 115200 baud at 55MHz
reg_uart_clkdiv = 477;
for (unsigned int i = 0;; i++) {
print("Hello world!!!\n");
reg_led = (i & 0xFF);
print_uint_bin(i);
delay();
reg_led = 0x00;
delay();
}
}