-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.c
More file actions
75 lines (57 loc) · 1.42 KB
/
main.c
File metadata and controls
75 lines (57 loc) · 1.42 KB
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
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <fcntl.h>
#include "mailbox.h"
#define BUS_TO_PHYS(x) ((x)&~0xC0000000)
#define CODESIZE 1024
int mbox;
unsigned handle;
unsigned ptr;
uint8_t *program;
void setup() {
mbox = mbox_open();
handle = mem_alloc(mbox, CODESIZE, 8, 4);
ptr = mem_lock(mbox, handle);
program = mapmem(BUS_TO_PHYS(ptr), CODESIZE);
int fd = 0;
fd = open("code.bin", O_RDONLY);
if (fd < 1) {
printf("Failed loading code.bin\n");
exit(0);
} else {
int size = (int)lseek(fd, 0, SEEK_END);
if (size > CODESIZE){
printf("VPU binary exceeds maximum codesize\n");
exit(0);
}
lseek(fd, 0, SEEK_SET);
read(fd, program, size);
printf("Loaded code.bin with size %d byte\n", size);
}
}
void cleanup() {
unmapmem(program, 64);
mem_unlock(mbox, handle);
mem_free(mbox, handle);
mbox_close(mbox);
}
unsigned readmem(unsigned phys) {
return execute_code(mbox, ptr, phys, 0, 0, 0, 0, 0);
}
void writemem(unsigned phys, unsigned value) {
execute_code(mbox, ptr+4, phys, value, 0, 0, 0, 0);
}
int main(int argc, char *argv[]) {
setup();
printf("Start VPU code\n");
printf("Returnvalue R0 = 0x%08x\n", execute_code(mbox, ptr, 0, 0, 0, 0, 0, 0));
cleanup();
return 0;
}