Firmwares/raven/hello_raven.c

51 lines
1.1 KiB
C

#include <stdint.h>
#include <stdio.h>
#include <unistd.h>
#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 = 2;
int val_b = 3;
*(int *)target_mem_base = val_a;
*(int *)(target_mem_base+4) = val_b;
printf("HW thread ID %d: write value A=%x and value B=%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 = %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;
printf("HW thread ID %d: sum of A+B=%x \n", hartid, sum);
}
printf("End of execution");
return 0;
}