X-Git-Url: http://sraa.de/git/?a=blobdiff_plain;f=dol%2Fsrc%2Fdol%2Fvisitor%2Fepiphany%2Ftemplate%2Fmain.c;fp=dol%2Fsrc%2Fdol%2Fvisitor%2Fepiphany%2Ftemplate%2Fmain.c;h=e7298799c0ceb7064ddb4c3001aa0f329e50a5ec;hb=2858109405a90a4d9df149b10444678d42e41c59;hp=0000000000000000000000000000000000000000;hpb=cbc1f1265fd129d066da10e72e819d7d20f5360a;p=jump.git diff --git a/dol/src/dol/visitor/epiphany/template/main.c b/dol/src/dol/visitor/epiphany/template/main.c new file mode 100644 index 0000000..e729879 --- /dev/null +++ b/dol/src/dol/visitor/epiphany/template/main.c @@ -0,0 +1,149 @@ +/* Epiphany Host Application */ + +#include +#include +#include +#include +#include + +#include "e-hal.h" + +/* common data structures */ +#include "../shared.h" + +#define FAIL(...) { fprintf(stderr, __VA_ARGS__); exit(1); } +#define SHM_OFFSET 0x01000000 + +#define ROW(X) (X/CORES_PER_ROW) +#define COL(X) (X%CORES_PER_ROW) + +#define NUM_PROGRAMS @@SREC_NUM@@ + +#if NUM_PROGRAMS > NUM_CORES + #error "Please limit the number of processes to the number of cores." +#endif + +/* programs to run */ +char programs[NUM_PROGRAMS][64] = { +@@SREC_FILES@@ +}; + +/* local copy of shared memory */ +shm_t shm = {{ 0 }}; + +void shm_init(void) { +@@SHM_BUF_INIT@@ +} + +int main(int argc, char *argv[]) +{ + char filename[255]; /* filename to load */ + + /* core states */ + int32_t states[NUM_CORES] = { 0 }; + int32_t laststates[NUM_CORES] = { 0 }; + + e_epiphany_t dev; + e_mem_t emem; + + e_set_host_verbosity(H_D0); + e_set_loader_verbosity(L_D0); + + /* init board, reset epiphany, open workgroup */ + if(e_init(NULL) != E_OK) + FAIL("Can't init!\n"); + e_reset_system(); + if(e_open(&dev, 0, 0, 4, 4) != E_OK) + FAIL("Can't open!\n"); + + /* initialize, allocate and update shared memory buffer */ + shm_init(); + if(e_alloc(&emem, SHM_OFFSET, sizeof(shm_t)) != E_OK) + FAIL("Can't alloc!\n"); + if(e_write(&emem, 0, 0, (off_t)0, &shm, sizeof(shm_t)) == E_ERR) + FAIL("Can't clear shm!\n"); + if(e_write(&emem, 0, 0, (off_t)0, &states, sizeof(states)) == E_ERR) + FAIL("Can't clear states!\n"); + + /* load and start all programs */ + for(int i = 0; i < NUM_PROGRAMS; i++) { + snprintf(filename, 255, "%s", programs[i]); + printf("Kicking core %i = (%i, %i) with '%s'\n", + i, ROW(i), COL(i), filename); + if(e_load(filename, &dev, ROW(i), COL(i), E_TRUE) != E_OK) + FAIL("Can't load %i!\n", i); + } + + /* =============================================================== */ + printf("Started %i cores.\n", NUM_PROGRAMS); + while(1) { + int done = 1; + + /* poll shm states for changes */ + printf("Polling shared memory.\n"); + + while(1) { + /* read epiphany core states */ + if(e_read(&emem, 0, 0, (off_t)0, &states, + sizeof(states)) == E_ERR) + FAIL("Can't poll!\n"); + + /* check for state changes */ + if(memcmp(laststates, states, sizeof(states))) + break; + }; + + /* save current states */ + memcpy(laststates, states, sizeof(states)); + + /* print core states */ + for(int i = 0; i < NUM_PROGRAMS; i++) { + printf("CORE %i: ", i); + switch(states[i]) { + case -1: printf("done "); break; + default: printf("state %i ", states[i]); done=0; break; + } + printf("\n"); + } + printf("CORE14: 0x%x\n", states[14]); + printf("CORE15: 0x%x\n", states[15]); + + /* stop polling if all cores finished */ + if(done) break; + } + /* =============================================================== */ + + printf("All cores finished.\n"); + + /* read whole shm buffer */ + if(e_read(&emem, 0, 0, (off_t)0, &shm, sizeof(shm)) == E_ERR) + FAIL("Can't read full shm!\n"); + + /* print buffer 0 and buffer 1 */ + for(int i = 0; i < 16; i++) { + printf("0x%x ", shm.buf0.buf[i]); + } printf("\n"); + for(int i = 0; i < 16; i++) { + printf("0x%x ", shm.buf1.buf[i]); + } printf("\n"); + + + for(int i = 0; i < 4; i++) { + printf("%.2f\t", ((float*)shm.buf0.buf)[i]); + } printf("\n"); + + for(int i = 0; i < 8; i++) { + printf("%.2f\t", ((float*)shm.buf1.buf)[i]); + } printf("\n"); + + /* free shm buffer, close workgroup and finalize */ + if(e_free(&emem) != E_OK) + FAIL("Can't free!\n"); + if(e_close(&dev) != E_OK) + FAIL("Can't close!\n"); + if(e_finalize() != E_OK) + FAIL("Can't finalize!\n"); + + return(0); +} +