51 const char cmd_gpio_help[] =
"GPIO test: gpio set|clear <led no>";
53 bool cmd_gpio_exec(
int argc,
const char *args[])
55 if (argc < 2)
return false;
56 int v = (args[1][0]) -
'0';
61 const char cmd_bus_help[] =
"Various bus operations (read/write) 'bus help' for help";
63 bool cmd_bus_exec(
int argc,
const char *args[])
72 if (
cnvParseU(args[1], &addr, cnvHex) <= 0)
return false;
74 volatile uint32_t * ptr = ((
volatile uint32_t *)addr);
75 printf(
"&%08x: %08x\n", addr, *ptr);
76 if (argc == 2 && strcmp(args[0],
"peek") == 0) {
78 }
else if (argc == 3 && strcmp(args[0],
"poke") == 0) {
79 if (
cnvParseU(args[2], &val, cnvHex) <= 0)
return false;
80 printf(
"-> Setting value %08lx (%lu)\n", val, val);
82 }
else if (argc == 3 && strcmp(args[0],
"set") == 0) {
83 int bit = atoi(args[2]);
84 printf(
"-> Setting bit %d\n", bit);
85 *ptr = *ptr | (1 << bit);
86 }
else if (argc == 3 && strcmp(args[0],
"clr") == 0) {
87 int bit = atoi(args[2]);
88 printf(
"-> Clearing bit %d\n", bit);
89 *ptr = *ptr & ~(1 << bit);
93 printf(
"&%08x: %08x (after)\n", addr, *ptr);
95 }
else if (argc == 1 && strcmp(args[0],
"help") == 0) {
96 puts(
"bus [option] [arguments]");
97 puts(
"where 'option' may be:");
98 puts(
" help - This text");
99 puts(
" peek [addr] - Read memory location");
100 puts(
" poke [addr] [val] - Write value to address");
101 puts(
" set [addr] [bit] - Set a bit");
102 puts(
" clr [addr] [bit] - Clears a bit");
104 puts(
" [addr] and [val] are in hex, [bit] is an integer value ranging from 0 to 31");
105 puts(
" all values are 32 bits, addresses must be 32 bit aligned");
117 const char cmd_reset_help[] =
"Resets the LM32 CPU";
119 bool cmd_reset_exec(
int argc,
const char *args[])
126 const char cmd_load_help[] =
"Shows the system load";
128 bool cmd_load_exec(
int argc,
const char *args[])
135 uint32_t idle = ( 100 * ( t[
TIMER_SECT_IDLE] >> 8 )) / (TIMER_MAX_COUNT >> 8);
136 uint32_t task = ( 100 * ( t[
TIMER_SECT_TASK] >> 8 )) / (TIMER_MAX_COUNT >> 8);
137 uint32_t irq = ( 100 * ( t[
TIMER_SECT_IRQ] >> 8 )) / (TIMER_MAX_COUNT >> 8);
140 printf(
"Tasks: %u%%, Interrupts: %u%%, Idle: %u%%\n", task, irq, idle);
142 #ifdef SCHD_TRACE_LOAD
143 if (argc == 1 && strcmp(args[0],
"reset") == 0) {
154 const char cmd_sdb_help[] =
"Iterate self-describing bus";
156 bool cmd_sdb_exec(
int argc,
const char *args[])
163 const char cmd_delay_help[] =
"Delay test: delay <ms>";
165 bool cmd_delay_exec(
int argc,
const char *args[])
167 if (argc != 1)
return false;
168 uint32_t v = atoi(args[0]);
174 const char cmd_wdog_help[] =
"Watchdog functions";
176 bool cmd_wdog_exec(
int argc,
const char *args[])
178 if (argc == 1 && strcmp(args[0],
"reboot") == 0) {
181 puts(
"wdog [cmd] - currently the onyl cmd is just 'reboot'");
190 const char cmd_crash_help[] =
"Crash the node";
192 bool cmd_crash_exec(
int argc,
const char *args[])
198 const char cmd_mboot_help[] =
"Multiboot commands";
201 bool cmd_mboot_exec(
int argc,
const char *args[])
203 if (argc == 0 || (argc == 1 && strcmp(args[0],
"help") == 0))
205 puts(
"mboot # - execute image 0-3");
206 puts(
"mboot info - Read icap information");
207 puts(
"mboot wdog start [to] - Start dog, timeout in approx seconds");
208 puts(
"mboot wdog feed - Feed the watchdog");
209 puts(
"mboot wdog stop - Stop the watchdog");
211 }
else if (argc == 1) {
213 if (strcmp(args[0],
"info") == 0)
216 printf(
"Boot status: current=%02x, previous=%02x\n",
218 printf(
"TIMER : %08lx\n",
MBOOT->WTIMER);
221 uint32_t v = atoi(args[0]);
222 printf(
"Booting new image at %08x, bye!", v * FLASH_SPACING);
224 puts(
"err... you should never see this message");
226 }
else if (argc >= 2 && strcmp(args[0],
"wdog") == 0) {
227 if (strcmp(args[1],
"feed") == 0) {
230 }
else if (strcmp(args[1],
"stop") == 0) {
233 }
else if (strcmp(args[1],
"start") == 0 && argc == 3) {
243 const char cmd_flash_help[] =
"Execute flash commands";
245 bool cmd_flash_exec(
int argc,
const char *args[])
249 if (argc == 0 || (argc == 1 && strcmp(args[0],
"help") == 0))
251 puts(
"flash [option] [params...]");
253 puts(
" info Displays information");
254 puts(
" reset Resets the flash");
255 puts(
" erase #<sector> Erases a sector in flash");
256 puts(
" read #<page> Reads bytes from a page");
257 puts(
" prog #<page> <text> Writes bytes of text to flash page");
258 puts(
" quad [on/off] Turn quad data mode on or off");
263 puts(
" diag Prints diagnostic information");
265 }
else if (argc == 1 &&
streq(args[0],
"reset")) {
266 puts(
"resetting flash");
268 }
else if (argc == 1 &&
streq(args[0],
"diag")) {
270 }
else if (argc == 1 &&
streq(args[0],
"unlock")) {
271 puts(
"unlocking golden image");
273 }
else if (argc == 1 &&
streq(args[0],
"lock")) {
276 }
else if (argc == 1 &&
streq(args[0],
"unprotect")) {
277 puts(
"Unprotecting");
279 }
else if (argc == 1 &&
streq(args[0],
"protect")) {
285 }
else if (argc == 1 && strcmp(args[0],
"info") == 0)
287 puts(
"Serial Flash info:");
292 puts(
"Unsupported device, no further information.");
295 printf(
"Sector Size : %d KB (%d sectors on device)\n",
sfInfo.
sectorSize / 1024,
297 printf(
"Page Size : %d bytes (%d pages / sector, %d pages total)\n",
300 printf(
"Flash status: %02x (device specific)\n",
sfInfo.
_status);
302 }
else if (argc == 2 && strcmp(args[0],
"erase") == 0)
305 uint32_t a = atoi(args[1]);
307 }
else if (argc == 2 && strcmp(args[0],
"read") == 0)
310 uint32_t a = atoi(args[1]);
312 showHex8(
"HEX: ", buf,
sizeof(buf));
314 printf(
"ASCII: %s\n", buf);
316 }
else if (argc == 2 && strcmp(args[0],
"quad") == 0)
319 }
else if (argc == 3 && strcmp(args[0],
"prog") == 0)
322 uint32_t a = atoi(args[1]);
330 const char cmd_img_help[] =
"Execute image commands";
332 bool cmd_img_exec(
int argc,
const char *args[])
334 if (argc == 0 || (argc == 1 && strcmp(args[0],
"help") == 0))
336 puts(
"flash [option] [params...]");
338 puts(
" list Lists all flash images");
339 }
else if (argc == 1 &&
streq(args[0],
"list")) {
342 const char* imgTypes[] = {
343 "Golden",
"Runtime",
"Base",
"Calibration"
346 for (
int i = 0; i < FLASH_MAX_IMAGES; i++) {
347 printf(
"Pos %d: ", i);
352 puts(
"Unknown / old");
354 printf(
"%s Fw=%08x Sw=%08x\n", imgTypes[info.
imgType - 1], info.
fwRev, info.
swRev);
356 printf(
"Error! Type=%d\n", info.
imgType);
368 const char cmd_pwr_help[] =
"Execute power board commands";
370 bool cmd_pwr_exec(
int argc,
const char *args[])
372 if (argc == 0 || (argc == 1 && strcmp(args[0],
"help") == 0))
374 puts(
"pwr [option] [params...]");
376 puts(
" help Displays this help");
377 puts(
" led <mV> Sets the LED DAC for the Nano beacon");
378 puts(
" meas Measure all the values, and display");
380 }
else if (argc == 1 &&
streq(args[0],
"meas")) {
381 uint16_t vals[POWER_COUNT];
386 puts(
"Powerboard read-out");
387 printf(
" 1.0V : %5d mV %5d mA\n", vals[POWER_1V_LVL], vals[POWER_1V_CUR]);
388 printf(
" 1.8V : %5d mV %5d mA\n", vals[POWER_1V8_LVL], vals[POWER_1V8_CUR]);
389 printf(
" 2.5V : %5d mV %5d mA\n", vals[POWER_2V5_LVL], vals[POWER_2V5_CUR]);
390 printf(
" 3.3V : %5d mV %5d mA\n", vals[POWER_3V3_LVL], vals[POWER_3V3_CUR]);
391 printf(
" 3.3V PMT: %5d mV %5d mA\n", vals[POWER_3V3PMT_LVL], vals[POWER_3V3PMT_CUR]);
392 printf(
" 5.0V : %5d mV %5d mA\n", vals[POWER_5V_LVL], vals[POWER_5V_CUR]);
393 printf(
"12.0V : %5d mV %5d mA\n", vals[POWER_12V_LVL], vals[POWER_12V_CUR]);
394 printf(
"VLED : %5d mV %5d mA\n", vals[POWER_VLED_LVL], vals[POWER_VLED_CUR]);
395 printf(
"Temp. : %5d mC\n"
396 "DAC CTRL : %5d mV\n", vals[POWER_TEMP_LVL], vals[POWER_DACCTL_LVL]);
399 }
else if (argc == 2 &&
streq(args[0],
"led")) {
400 int v = atoi(args[1]);
408 const char cmd_i2c_help[] =
"I2C debugging commands";
410 bool cmd_i2c_exec(
int argc,
const char *args[])
413 puts(
"i2c <dev> <command> [<options>]");
414 puts(
"device must be 1 to 3");
415 puts(
"where command may be");
416 puts(
" scan - do a complete scan of the I2C bus, listing all addresses");
418 int devIdx = atoi(args[0]);
420 bool canRead, canWrite;
424 case 1: dev =
I2C1;
break;
425 case 2: dev =
I2C2;
break;
426 case 3: dev =
I2C3;
break;
428 puts(
"Incorrect I2C device number, must be 1-3");
432 if (
streq(args[1],
"scan"))
434 puts(
"I2C Bus scan");
435 puts(
"===============================");
437 for (
i2cAddr addr = 0; addr < 0x7F; addr++) {
438 if (!
i2cExists(dev, addr, &canRead, &canWrite)) {
439 printf(
"Error at %02x:\n", addr);
441 }
else if (canRead || canWrite) {
442 printf(
"Device at %02x:%s%s\n", addr,
443 canRead ?
" Readable" :
"",
444 canWrite ?
" Writable" :
"");
448 printf(
"%d device(s) found\n", found);
458 const char cmd_wrx_help[] =
"Dump WhiteRabbit eXchange data";
460 bool cmd_wrx_exec(
int argc,
const char *args[])
467 if (argc == 2 && strcmp(args[0],
"test") == 0) {
469 int c = atoi(args[1]);
471 volatile WrxInfo * info =
wrxInfo();
475 memcpy(mac_cpy, (
const void *)&info->macAddr[0], 6);
477 for (
int i = 0; i < c; ++i) {
478 mac_tst[0] =
wrxInfo()->macAddr[0];
479 mac_tst[1] =
wrxInfo()->macAddr[1];
480 mac_tst[2] =
wrxInfo()->macAddr[2];
481 mac_tst[3] =
wrxInfo()->macAddr[3];
482 mac_tst[4] =
wrxInfo()->macAddr[4];
483 mac_tst[5] =
wrxInfo()->macAddr[5];
485 if (memcmp(mac_tst, mac_cpy, 6) != 0) {
487 memcpy(mac_cpy, mac_tst, 6);
491 printf(
"Run: %d, Errors: %d, rate: %d%%\n", c, err, ( err * 100 ) / c);
495 volatile WrxInfo * info =
wrxInfo();
496 printf(
"Status: %08x\n", info->status);
497 printf(
"MAC : %02x:%02x:%02x:%02x:%02x:%02x\n", info->macAddr[0], info->macAddr[1],
498 info->macAddr[2], info->macAddr[3], info->macAddr[4], info->macAddr[5]);
499 printf(
"Temp : %d.%d\n", info->brdTemp, info->brdTempFrac);
500 printf(
"Time : %llu\n",info->utcTime);
506 const char cmd_log_help[] =
"log [#] - Read the last # log-lines from flash. When ommited read all";
508 bool cmd_log_exec(
int argc,
const char *args[])
511 if (argc == 1) count = atoi(args[0]);
526 const char cmd_rt_help[] =
"set/get the runtime configuration";
528 bool cmd_rt_exec(
int argc,
const char *args[])
532 printf(
"runtime image to load no: %d\n",
rtImage());
534 }
else if (argc == 1 && strcmp(
"help", args[0]) == 0) {
535 puts(
"rt help - show this help");
536 puts(
"rt - list current runtime settings");
537 puts(
"rt image <#> - sets the runtime image number. This image is");
538 puts(
" loaded after the golden image.");
539 }
else if (argc == 2) {
540 if (strcmp(args[0],
"image") == 0)
556 const char cmd_cdc_help[] =
"Core dump clear";
558 bool cmd_cdc_exec(
int argc,
const char *args[])
561 puts(
"Core-dump cleared");
#define TIMER_SECT_IRQ
time spend in IRQs
bool sfQuadEnable(bool enable)
Quad enable,.
Implements search functionality for the self-describing bus.
static void mbootWDogFeed()
Feed the watchdog.
This module provides access to the peripherals on the power board.
This driver is to read and configure the AHRS I2C sensor.
void coreDumpClear()
Clears core dump information.
int rtImage()
Returns the image loaded for runtime.
bool i2cExists(I2C_Device *dev, i2cAddr addr, bool *canRead, bool *canWrite)
Checks whether or not an I2C address is present on the bus.
uint32_t flashSize
flash size in bytes
static int mbootBootStatus(bool previous)
Returns the boot status.
void mbootLoad(int imgNo)
Boots a specific image.
static bool streq(const char *one, char *other)
Simple compares two strings for equality.
bool updUnlock()
Unlocks the golden image for writing.
Provides access to the runtime image booting.
int cnvParseU(const char *input, uint32_t *output, CnvParams params)
Parse an unsigned integer.
Low level routines for LM32, including interrupt handling.
bool updImgInfo(uint32_t imgNo, UpdImgInfo *imgInfo)
Retrieve image information for the specified location.
#define UPD_IMGTYPE_NONE
There is no image at the specified location.
uint8_t mfId
Manufacturer ID.
bool lhFlashItNext(char *bufPtr, int bufSize)
Get the next element.
uint8_t _status
Hardware status register value.
Structure defines OpenCores I2C Device.
#define TIMER_SECT_IDLE
time spend being idle
int8_t imgType
Image type.
Simple task scheduler for tasks.
static void mbootWDogStop()
Stop the watchdog.
#define MBOOT
Multiboot base pointer.
SfInfo sfInfo
Flash info, only valid after successful initialization.
uint16_t pageSize
Page size in bytes.
void timeDelay(uint32_t msec)
Simple busy-wait delay.
#define I2C3
Virtual OpenCores I2C.
uint32_t sectorSize
Sector size in bytes.
Multiboot Driver, exposes one function, mbootLoad.
static void wdogReboot()
Reboot the FPGA (hard)
#define I2C2
Virtual OpenCores I2C.
uint8_t i2cAddr
I2C address type.
bool updLock()
Locks the golden image for writing.
void gpioPinSet(int pin, bool high)
Sets the pin state.
bool pwrMeasureAll(uint16_t *results)
Initiates a conversion for the given channel.
void mbootWDogStart(uint32_t timer, bool config)
Configures and starts the ICAPE2 watchdog.
uint32_t * timerValues()
Returns.
#define MBOOT_WATCHDOG_FREQ
Worse case watchdog speed.
bool sfReset()
Resets the flash.
Manages the global system error.
bool sfErase(uint32_t address)
Erase a sector in flash.
void errPrint(bool clear)
Prints the last error.
This structure provides information about formatting and parsing.
uint32_t swRev
Software revision.
#define UPD_IMGTYPE_UNKNOWN
There is an image, but it has no meta-data.
uint32_t fwRev
Firmware revision.
bool sfProtect(uint32_t address)
Protects a specific sector from being erased or programmed.
bool wrxUp()
Returns whether or not the WhiteRabbit interface is up and running.
volatile WrxInfo * wrxInfo()
Returns the whiteRabbit information structure if available, else NULL.
#define UPD_IMGTYPE_CALIB
Calibration image.
Various useful functions.
void reboot()
Soft reboot the LM32.
void sdbDisplay()
Dumps the contents of the SDB records to standard out.
uint8_t devCap
Device capacity ID.
This driver is to read the SHT21 I2C temperature and humidity sensor.
#define I2C1
Virtual OpenCores I2C.
bool lhFlashItStart(int count)
Start the iteration through the flash entries.
static uint32_t mbootIDCode()
Returns the ID-code.
bool sfRead(uint32_t address, uint8_t *data, uint32_t count)
Read from a specific address in flash.
This file assigns all device structures to memory mapped structures.
bool errSet(uint32_t code, const char *error, const char *name)
Sets an error.
#define ERROR(CODE,...)
Expands an error code to an error code with a description (if ERROR_W_DESCR is declared).
This driver implements access to the Serial Flash.
bool rtSetImage(int imgNo)
Sets the runtime boot image number.
#define TIMER_SECT_TASK
time spend executing a task
bool pwrSetLED(uint32_t mv)
Set the LED output in millivolts.
#define UPD_IMGTYPE_GOLDEN
Golden image.
WhiteRabbit exchange exchanges information between the 2nd LM32 and WhiteRabbit though a small client...
This module implements parsing and formating of strings and integers.
bool sfProg(uint32_t address, uint8_t *data, uint32_t count)
Program an page in flash.
void sfSpDiag()
Shows diagnostic state of Spansion Flash.
#define E_NOTSUPPORTED
Generic error: not supported.
bool sfUnProtect()
Unprotects the entire flash array.
Facilitates the update process.
OpenCores I2C device driver.