diff options
author | Clifford Wolf <clifford@clifford.at> | 2015-07-19 16:09:19 +0200 |
---|---|---|
committer | Clifford Wolf <clifford@clifford.at> | 2015-07-19 16:09:19 +0200 |
commit | 6c7125b380c3d8f5428bae9306e91b5d327f1a61 (patch) | |
tree | 2266334795864972fe5f04af8f5e27637840df92 /scripts/icestorm/firmware.c | |
parent | 812d4d0793baf8f9a77991caaf68c622e10e0f5a (diff) | |
download | picorv32-6c7125b380c3d8f5428bae9306e91b5d327f1a61.tar.gz picorv32-6c7125b380c3d8f5428bae9306e91b5d327f1a61.zip |
Improved icestorm example
Diffstat (limited to 'scripts/icestorm/firmware.c')
-rw-r--r-- | scripts/icestorm/firmware.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/scripts/icestorm/firmware.c b/scripts/icestorm/firmware.c new file mode 100644 index 0000000..b400ba0 --- /dev/null +++ b/scripts/icestorm/firmware.c @@ -0,0 +1,28 @@ +#include <stdint.h> + +#define SHIFT_COUNTER_BITS 16 + +void output(uint8_t c) +{ + *(volatile char*)0x10000000 = c; +} + +void output_gray(uint8_t c) +{ + unsigned int in_buf = c, out_buf = 0; + for (int i = 0; i < 8; i++) { + unsigned int bit = (in_buf & 1) ^ ((in_buf >> 1) & 1); + in_buf = in_buf >> 1; + out_buf = (out_buf << 1) | bit; + } + output(out_buf); +} + +void main() +{ + for (uint32_t counter = (2+4+32+64) << SHIFT_COUNTER_BITS;; counter++) { + asm volatile ("" : : "r"(counter)); + if ((counter & ~(~0 << SHIFT_COUNTER_BITS)) == 0) + output_gray(counter >> SHIFT_COUNTER_BITS); + } +} |