2023-07-24 00:01:39 -04:00
|
|
|
// a simple test program
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
uint32_t strlen(const char* str) {
|
|
|
|
if(!str)
|
|
|
|
return 0;
|
|
|
|
const char* c = str;
|
|
|
|
while(*c++)
|
|
|
|
;
|
|
|
|
return c - str;
|
|
|
|
}
|
|
|
|
|
2023-07-24 01:56:50 -04:00
|
|
|
#define SYSCON *(volatile uint32_t*)0x11100000
|
|
|
|
|
2023-07-24 00:01:39 -04:00
|
|
|
#define UART_BASE 0x10000000
|
|
|
|
#define UART_DATA *(volatile uint32_t*)UART_BASE
|
|
|
|
#define UART_STATUS UART_DATA
|
|
|
|
|
|
|
|
void putc(char c) {
|
|
|
|
UART_DATA = (uint32_t)c;
|
|
|
|
}
|
|
|
|
|
|
|
|
__attribute__((noinline)) void puts(const char* str) {
|
|
|
|
const uint32_t length = strlen(str);
|
|
|
|
for(uint32_t i = 0; i < length; ++i)
|
|
|
|
putc(str[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t value = 0;
|
|
|
|
static uint16_t shortvalue = 0;
|
|
|
|
static uint8_t bytevalue = 0;
|
|
|
|
|
2023-07-24 01:56:50 -04:00
|
|
|
#define COUNTER_TEST(var, max) \
|
|
|
|
for(int i = 0; i < max; ++i) { \
|
2023-07-24 00:01:39 -04:00
|
|
|
puts(#var " is (before modification): "); \
|
2023-07-24 01:56:50 -04:00
|
|
|
putc("0123456789"[var]); \
|
|
|
|
putc('\n'); \
|
|
|
|
\
|
|
|
|
var = i; \
|
2023-07-24 00:01:39 -04:00
|
|
|
puts(#var " is (after modification): "); \
|
2023-07-24 01:56:50 -04:00
|
|
|
putc("0123456789"[var]); \
|
|
|
|
putc('\n'); \
|
2023-07-24 00:01:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
puts("hello world I guess\n");
|
|
|
|
|
|
|
|
#if 1
|
|
|
|
COUNTER_TEST(value, 9);
|
|
|
|
COUNTER_TEST(shortvalue, 9);
|
|
|
|
COUNTER_TEST(bytevalue, 9);
|
|
|
|
#endif
|
|
|
|
|
2023-07-24 01:56:50 -04:00
|
|
|
// Shut down the test harness once we're done testing.
|
|
|
|
puts("Tests done, shutting down test harness...\n");
|
2023-07-24 06:50:18 -04:00
|
|
|
//SYSCON = 0x5555;
|
2023-07-24 01:56:50 -04:00
|
|
|
|
2023-07-24 00:01:39 -04:00
|
|
|
// loop forever
|
2023-07-24 06:50:18 -04:00
|
|
|
for(;;);
|
2023-07-24 00:01:39 -04:00
|
|
|
}
|