int lpack(lua_State *L) { struct write_block b; wb_init(&b, NULL); _pack_from(L, &b, 0); struct block * ret = wb_close(&b); lua_pushlightuserdata(L, ret); return 1; }
static int lappend(lua_State *L) { struct write_block b; wb_init(&b, lua_touserdata(L,1)); pack_from(L,&b,1); struct block * ret = wb_close(&b); lua_pushlightuserdata(L,ret); return 1; }
int main(int argc, char** argv) { eb_status_t status; eb_socket_t socket; int devIndex=-1; // 0,1,2... - there may be more than 1 device on the WB bus const char* devName; const char* command; int cmdExecuted=0; int getEBVersion=0; int probeAfterReset=0; int waitTime=1; int exitCode=0; uint32_t nCPU; uint64_t i; int opt, error=0; char *tail; int ip; program = argv[0]; while ((opt = getopt(argc, argv, "p:eh")) != -1) { switch (opt) { case 'p' : probeAfterReset=1; waitTime = strtol(optarg, &tail, 0); if (*tail != 0) { fprintf(stderr, "Specify a proper number, not '%s'!\n", optarg); exit(1); } // if *tail break; case 'e': getEBVersion=1; break; case 'h': help(); return 0; case ':': case '?': error = 1; break; default: fprintf(stderr, "%s: bad getopt result\n", program); return 1; } // switch opt } // while opt if (error) { help(); return 1; } if (optind >= argc) { fprintf(stderr, "%s: expecting one non-optional argument: <etherbone-device>\n", program); fprintf(stderr, "\n"); help(); return 1; } devName = argv[optind]; devIndex = 0; // default: grab first device of the requested type on the wishbone bus if (optind+1 < argc) command = argv[++optind]; else command = NULL; if (getEBVersion) { if (verbose) fprintf(stdout, "EB version / EB source: "); fprintf(stdout, "%s / %s\n", eb_source_version(), eb_build_info()); } if (command) { // open Etherbone device and socket if ((status = wb_open(devName, &device, &socket)) != EB_OK) { fprintf(stderr, "can't open connection to device %s \n", devName); return (1); } // prior reset, probe device by gettings its IP if ((status = wb_wr_get_ip(device, devIndex, &ip)) != EB_OK) die("eb-reset: can't to connect to device", status); // FPGA reset if (!strcasecmp(command, "fpgareset")) { cmdExecuted = 1; // depending on the device, the etherbone cycle either completes or times out status = wb_wr_reset(device, devIndex, 0xdeadbeef); if ((status != EB_TIMEOUT) && (status != EB_OK)) die("RESET FPGA", status); if (probeAfterReset) { //close, wait and reopen socket, try to read a property (here: ip) from the device if ((status = wb_close(device, socket)) != EB_OK) die ("Probe FPGA", status); sleep(waitTime); if ((status = wb_open(devName, &device, &socket)) != EB_OK) die("Probe FPGA", status); if ((status = wb_wr_get_ip(device, devIndex, &ip)) != EB_OK) die("Probe FPGA", status); } // probe after reset } // fpga reset // halt user CPU if (!strcasecmp(command, "cpuhalt")) { cmdExecuted = 1; if (optind+2 != argc) {printf("eb-reset: expecting exactly one argument: cpuhalt <cpu>\n"); return 1;} nCPU = strtoul(argv[optind+1], &tail, 0); status = wb_cpu_halt(device, devIndex, nCPU); if (status == EB_OOM) {printf("eb-reset: illegal value for <cpu>\n"); return 1;} if (status != EB_OK) die("eb-reset: ", status); } // halt lm32 CPU // reset user CPU if (!strcasecmp(command, "cpureset")) { cmdExecuted = 1; if (optind+2 != argc) {printf("eb-reset: expecting exactly one argument: cpureset <cpu>\n"); return 1;} nCPU = strtoul(argv[optind+1], &tail, 0); status = wb_cpu_halt(device, devIndex, nCPU); if (status == EB_OOM) {printf("eb-reset: illegal value for <cpu>\n"); return 1;} if (status != EB_OK) die("eb-reset: ", status); usleep(1000); // probably not required, but its better to be on the safe side status = wb_cpu_resume(device, devIndex, nCPU); if (status == EB_OOM) {printf("eb-reset: illegal value for <cpu>\n"); return 1;} if (status != EB_OK) die("eb-reset: ", status); } // resume lm32 CPU // get user CPU halt state if (!strcasecmp(command, "cpustatus")) { cmdExecuted = 1; status = wb_cpu_status(device, devIndex, &nCPU); if (status != EB_OK) die("eb-reset: ", status); printf("eb-reset: status of user lm32 "); for (i = 1 << 16; i > 0; i = i / 2) {if (nCPU & i) printf("1"); else printf("0");} printf("\n"); } // get lm32 CPU status wb_close(device, socket); if (!cmdExecuted) printf("eb-reset: unknonwn command %s\n", command); } // if command else printf("eb-reset: no action on FPGA or lm32, use option '-h' to learn about commands\n"); return exitCode; } // main