Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hello world update #13

Open
wants to merge 1 commit into
base: 2016.3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 0 additions & 44 deletions apps/hello-world/Debug/makefile

This file was deleted.

8 changes: 0 additions & 8 deletions apps/hello-world/Debug/objects.mk

This file was deleted.

17 changes: 0 additions & 17 deletions apps/hello-world/Debug/sources.mk

This file was deleted.

24 changes: 0 additions & 24 deletions apps/hello-world/Debug/src/subdir.mk

This file was deleted.

13 changes: 11 additions & 2 deletions apps/hello-world/build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

# Last update: 2016 dec 19. (JLQ).

set -e

ESDK=${EPIPHANY_HOME}
Expand All @@ -11,6 +13,9 @@ SCRIPT=$(readlink -f "$0")
EXEPATH=$(dirname "$SCRIPT")
cd $EXEPATH

# Create the binaries directory
mkdir -p bin/

if [ -z "${CROSS_COMPILE+xxx}" ]; then
case $(uname -p) in
arm*)
Expand All @@ -25,9 +30,13 @@ esac
fi

# Build HOST side application
${CROSS_COMPILE}gcc src/hello_world.c -o Debug/hello_world.elf ${EINCS} ${ELIBS} -le-hal -le-loader -lpthread
${CROSS_COMPILE}gcc src/hello_world.c -o bin/hello_world.elf ${EINCS} ${ELIBS} -le-hal -le-loader -lpthread

# Build DEVICE side program
e-gcc -T ${ELDF} src/e_hello_world.c -o Debug/e_hello_world.elf -le-lib
e-gcc -T ${ELDF} src/e_hello_world.c -o bin/e_hello_world.elf -le-lib






5 changes: 3 additions & 2 deletions apps/hello-world/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

set -e

SCRIPT=$(readlink -f "$0")
EXEPATH=$(dirname "$SCRIPT")

cd Debug

cd $EXEPATH/bin
./hello_world.elf

38 changes: 11 additions & 27 deletions apps/hello-world/src/e_hello_world.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,41 +25,25 @@
// a message identifying itself to the shared external
// memory buffer.

// Last update: 2016 dec 19. (JLQ).

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "e_lib.h"

int main(void) {
const char ShmName[] = "hello_shm";
const char Msg[] = "Hello World from core 0x%03x!";
char buf[256] = { 0 };
e_coreid_t coreid;
e_memseg_t emem;
unsigned my_row;
unsigned my_col;


// Who am I? Query the CoreID from hardware.
coreid = e_get_coreid();
e_coords_from_coreid(coreid, &my_row, &my_col);
#define buff_sz (4096)

if ( E_OK != e_shm_attach(&emem, ShmName) ) {
return EXIT_FAILURE;
}
char outbuf[buff_sz] SECTION("shared_dram");

// Attach to the shm segment
snprintf(buf, sizeof(buf), Msg, coreid);

if ( emem.size >= strlen(buf) + 1 ) {
// Write the message (including the null terminating
// character) to shared memory
e_write((void*)&emem, buf, my_row, my_col, NULL, strlen(buf) + 1);
} else {
// Shared memory region is too small for the message
return EXIT_FAILURE;
}
int main(void) {
e_coreid_t coreid;

coreid = e_get_coreid();

sprintf(outbuf, "Hello World from core 0x%03x! \n", coreid);

return EXIT_SUCCESS;
}

78 changes: 38 additions & 40 deletions apps/hello-world/src/hello_world.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
// shared external memory buffer for the core's output
// message.

// Last update: 2016 dec 19. (JLQ).

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
Expand All @@ -34,20 +36,18 @@

#include <e-hal.h>

const unsigned ShmSize = 128;
const char ShmName[] = "hello_shm";
const unsigned SeqLen = 20;
#define buff_sz (4096)
#define buff_offset (0x01000000)

int main(int argc, char *argv[])
{
unsigned row, col, coreid, i;
e_platform_t platform;
e_epiphany_t dev;
e_mem_t mbuf;
e_mem_t emem;
char emsg[buff_sz];
int rc;

srand(1);

e_set_loader_verbosity(H_D0);
e_set_host_verbosity(H_D0);

Expand All @@ -60,53 +60,51 @@ int main(int argc, char *argv[])

// Allocate a buffer in shared external memory
// for message passing from eCore to host.
rc = e_shm_alloc(&mbuf, ShmName, ShmSize);
if (rc != E_OK)
rc = e_shm_attach(&mbuf, ShmName);

if (rc != E_OK) {
fprintf(stderr, "Failed to allocate shared memory. Error is %s\n",
strerror(errno));
return EXIT_FAILURE;
}
e_alloc(&emem, buff_offset, buff_sz);

// Open a workgroup
e_open(&dev, 0, 0, platform.rows, platform.cols);

// Reset the workgroup
e_reset_group(&dev);

// Load the device program onto all the eCores
e_load_group("e_hello_world.elf", &dev, 0, 0, platform.rows, platform.cols, E_FALSE);

for (i=0; i<SeqLen; i++)

for (row=0; row<platform.rows; row++)
{
char buf[ShmSize];
for (col=0; col<platform.cols; col++)
{
// clear shared buffer.
memset(emsg, 0, buff_sz);
e_write(&emem, 0, 0, 0x0000, emsg, buff_sz);

// Draw a random core
row = rand() % platform.rows;
col = rand() % platform.cols;
// Print working core
coreid = (row + platform.row) * 64 + col + platform.col;
printf("%3d: Message from eCore 0x%03x (%2d,%2d): ", i, coreid, row, col);

// Open the single-core workgroup and reset the core, in
// case a previous process is running. Note that we used
// core coordinates relative to the workgroup.
e_open(&dev, row, col, 1, 1);
e_reset_group(&dev);

// Load the device program onto the selected eCore
// and launch after loading.
if ( E_OK != e_load("e_hello_world.elf", &dev, 0, 0, E_TRUE) ) {
fprintf(stderr, "Failed to load e_hello_world.elf\n");
return EXIT_FAILURE;
}
printf("eCore 0x%03x (%2d,%2d): \n", coreid, row, col);

// Wait for core program execution to finish, then
// read message from shared buffer.
// Start one core
e_start(&dev, row, col);

// Wait for core program execution to finish.
usleep(10000);

e_read(&mbuf, 0, 0, 0, buf, ShmSize);
// Read message from shared buffer
e_read(&emem, 0, 0, 0x0, emsg, buff_sz);

// Print the message and close the workgroup.
printf("\"%s\"\n", buf);
e_close(&dev);
printf("%s\n", emsg);

}
}

// Close the workgroup
e_close(&dev);

// Release the allocated buffer and finalize the
// e-platform connection.
e_shm_release(ShmName);
e_free(&emem);
e_finalize();

return 0;
Expand Down