#include #include #include #include "platform.h" #include "encoding.h" #define IOF_ENABLE_TERMINAL (0x30000) int factorial(int i){ volatile int result = 1; for (int ii = 1; ii <= i; ii++) { result = result * ii; } return result; } int main() { GPIO_REG(GPIO_IOF_EN) |= IOF_ENABLE_TERMINAL; // enable GPIO connection to the terminal int hartid = read_csr(0xf14); // CSR_MHARTID int target_mem_base = 0x90000000; int local_mem_base = 0x80000000; if (hartid == 0) { int val_a = 5; int val_b = 0xA; *(int *)target_mem_base = val_a; *(int *)(target_mem_base+4) = val_b; printf("HW thread ID %d: write value A=0x%x and value B=0x%x to thread 1\n", hartid, val_a, val_b); } int result = factorial (10); printf("HW thread ID %d: spend some time calculating factorial of 10=0x%x\n", hartid, result); if (hartid == 1) { int val_a = *(int *)local_mem_base; int val_b = *(int *)(local_mem_base+4); int sum = val_a + val_b; if (sum == 0xF) printf("HW thread ID %d: sum of A+B=0x%x\n", hartid, sum); else { printf("HW thread ID %d: sum of A+B is not 0x%x. Test FAILED!!!\n", hartid, sum); return 1; } } printf("End of execution"); return 0; }