-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.c
85 lines (71 loc) · 1.86 KB
/
main.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <stdio.h>
#include <stdint.h>
#include "krv_utils.h"
#include "xprintf.h"
#define USE_VL53L1X (1)
#define USE_SDRAM (1)
#ifdef USE_VL53L1X
#include "qsys_i2c.h"
#include "VL53L1X.h"
#endif //USE_VL53L1X
#ifdef USE_SDRAM
int32_t sdram_test(void) {
uint32_t
data,length;
length = SDRAM_0_END - SDRAM_0_BASE;
xprintf("SDRAM write start\r\n");
for (int k = 0 ; k < length ; k = k + 4) {
put32(SDRAM_0_BASE + k, k);
}
xprintf("SDRAM read start\r\n");
for (int k = 0 ; k < length ; k = k + 4) {
data = get32(SDRAM_0_BASE + k);
if(data != k) {
xprintf("error fount at 0x%x: expecting %d but got %d\r\n",k,k,data);
return -1;
}
}
return 0;
}
#endif // USE_SDRAM
// main function
int32_t main(int argc, char *argv[]) {
uint64_t i;
xdev_out(&uart_putc); // override xprintf
#ifdef USE_VL53L1X
xprintf("I2C init\r\n");
i2c_init(I2C_0_BASE);
i2c_disable_isr(I2C_0_BASE);
if(true == VL53L1X_init()) {
xprintf("VL5351X init OK.\r\n");
VL53L1X_setDistanceMode(VL53L1X_Long);
VL53L1X_setMeasurementTimingBudget(50000);
VL53L1X_startContinuous(50);
} else {
xprintf("VL5351X init failed.\r\n");
}
#endif //USE_VL53L1X
uint32_t data = 0;
#ifdef USE_SDRAM
if(0 == sdram_test()) {
xprintf("SDRAM r/w test OK!\r\n");
} else {
xprintf("SDRAM r/w test fail......\r\n");
}
#endif //USE_SDRAM
xprintf("KyogenRV (RV32I) Start...\r\n");
while(1){
wait_ms(500);
put32(PIO_0_BASE, 0x55);
wait_ms(500);
put32(PIO_0_BASE, 0xAA);
#ifdef USE_VL53L1X
data = VL53L1X_read(true);
xprintf("value = %d\r\n",data);
#else
i = get_time_ms() / 1000;
xprintf("machine time = %llu second\r\n",i);
#endif //USE_VL53L1X
}
return 0;
}