49 #define STACK_CHECK 0xDEADBEEF
71 extern
char * __dateRev __attribute__((weak));
73 #if !defined(GOLDEN) && defined(DEBUG)
77 static bool allFF(uint8_t * ptr, uint32_t len)
89 static void coreDumpInit()
91 _flAddr = CRASH_OFFSET;
93 sfRead( _flAddr, mem,
sizeof(mem));
95 while (!allFF(mem,
sizeof(mem)))
98 _flAddr += CRASH_IMG_SIZE;
101 if (_flAddr >= CRASH_OFFSET + CRASH_SIZE)
103 logWarn(
"Core dump memory full, can't store any more core dumps");
108 sfRead( _flAddr, mem,
sizeof(mem));
110 logInfo(
"Core dump memory contains %d of %d images", c, CRASH_SIZE / CRASH_IMG_SIZE);
113 static volatile bool _coreDumpInProgress =
false;
117 _coreDumpInProgress =
true;
118 _flAddr = CRASH_OFFSET;
119 for (_flAddr = CRASH_OFFSET + CRASH_SIZE - BLOCK_BYTES; _flAddr >= CRASH_OFFSET; _flAddr -= BLOCK_BYTES)
124 logInfo(
"Erasing address %08x", _flAddr);
127 _flAddr = CRASH_OFFSET;
128 _coreDumpInProgress =
false;
131 static void coreDump()
133 if (_flAddr == 0)
return;
134 if (_coreDumpInProgress)
return;
135 _coreDumpInProgress =
true;
138 _flAddr += CRASH_IMG_SIZE;
139 if (_flAddr >= CRASH_OFFSET + CRASH_SIZE )
141 logWarn(
"Core dump memory full, can't store any more crash information");
144 _coreDumpInProgress =
false;
148 static void coreDump()
151 static void coreDumpInit()
168 }
else if (c !=
'\r')
187 if (!
suartRx(CONSOLE_UART,&c)) {
203 uint32_t uptime = (uint32_t) ( 0xFFFFFFFF &
wrxUtcTime() );
220 #define _AN_SWITCH_COUNT 60
221 static int _anCount = _AN_SWITCH_COUNT;
223 static void sysAutoNegSwitch() {
225 if (!
wrxUp())
return;
227 uint32_t status =
wrxInfo()->status;
229 if (status & WRX_STATUS_LINK_UP) {
230 _anCount = _AN_SWITCH_COUNT;
235 if (status & WRX_STATUS_AUTONEG_ON) {
241 _anCount = _AN_SWITCH_COUNT;
249 puts(
"--- register dump ---");
251 for (i = 0; i < 10; ++i)
253 printf(
" r%-2d: %08x\n", i + 1,
pState[i]);
269 static volatile uint32_t _ppsCount = 0;
276 logError(
"Program stalled, rebooting...");
277 logError(
" r1: %08x r2: %08x r3: %08x r4: %08x r5: %08x ",
279 logError(
" r6: %08x r7: %08x r8: %08x r9: %08x r10: %08x ",
281 logError(
" ra: %08x ba: %08x ea: %08x",
297 logError(
" r1: %08x r2: %08x r3: %08x r4: %08x r5: %08x ",
299 logError(
" r6: %08x r7: %08x r8: %08x r9: %08x r10: %08x ",
301 logError(
" ra: %08x ba: %08x ea: %08x",
309 uint32_t sysPPSCount()
312 uint32_t ppsC = _ppsCount;
332 static void sysHeartBeat()
339 if (_end != STACK_CHECK)
375 values[0] = ( 100 * t[
TIMER_SECT_IDLE] + (TIMER_MAX_COUNT >> 1) ) / TIMER_MAX_COUNT;
376 values[1] = ( 100 * t[
TIMER_SECT_TASK] + (TIMER_MAX_COUNT >> 1) ) / TIMER_MAX_COUNT;
377 values[2] = ( 100 * t[
TIMER_SECT_IRQ] + (TIMER_MAX_COUNT >> 1) ) / TIMER_MAX_COUNT;
383 *brdTempFrq =
wrxInfo()->brdTempFrac;
393 return (uint32_t) (&__dateRev);
399 extern const char _appName[];
401 static void dInit(
bool result,
char * name) {
404 printf(
"%-20s [OK]\n", name);
411 #define _SWDATE(DR) ( ( ( DR ) & DATEREV_DATE_MASK ) >> DATEREV_DATE_SHIFT )
412 #define _SWREV(DR) ( ( ( DR ) & DATEREV_REV_MASK ) >> DATEREV_REV_SHIFT )
417 #define CRC_BLOCK_SIZE 32
420 static const uint8_t * _crc32_pos = 0;
421 extern const uint32_t _crc32_;
423 static void doRomScan()
426 if ((_crc32_pos + CRC_BLOCK_SIZE) < &_rom_size)
428 _crc32 =
crc32(_crc32, _crc32_pos, CRC_BLOCK_SIZE,
false);
429 _crc32_pos += CRC_BLOCK_SIZE;
433 if (_crc32_pos != &_rom_size)
435 _crc32 =
crc32(_crc32, _crc32_pos, (
unsigned int)(&_rom_size-_crc32_pos)-4,
false);
439 if (_crc32 != _crc32_) {
446 _crc32_pos = &_rom_offset;
450 static void initRomTest()
452 _crc32_pos = &_rom_offset;
457 static void sysInitHw()
462 logInfo(
"%s starting...", _appName);
471 xadcSetAveraging(XADC_CMD_AVERAGE_MODE_NO);
481 dInit(
sfInit(),
"Serial Flash");
483 logWarn(
"Failed to initialize Flash logger");
491 dInit(
sdbInit(),
"Self Describing Bus");
501 dInit(
updInit(),
"Update System");
520 uint32_t sysClockTicks() {
525 #define RESET_MAGIC 0x100FF5E7
526 static volatile uint32_t _reset_detect __attribute__ ((section (
".noinit")));
528 int main(
int argc,
char **argv)
531 if (_reset_detect == 0x100FF5E7)
537 _reset_detect = 0x100FF5E7;
#define TIMER_SECT_IRQ
time spend in IRQs
SPI initialization structure.
Implements search functionality for the self-describing bus.
bool errHas()
Returns whether there is an error pending.
#define PSTATE_RA
return address (from IRQ = PC at the moment or interrupt)
#define IRQ_1HZ
1Hz IRQ for watchdog-like feature
#define MBOOT_GOLDEN
The golden image index position.
This module provides access to the peripherals on the power board.
Defines the configuration of the LM32 SOC for the CLBv2.
#define I2C_SPEED
Unfortunately 90K is set because AHRS messes up otherwise.
bool sfInit()
Initializes the Serial Flash.
void _appInit()
Prototype to be implemented by higher-level function to start the application.
void coreDumpClear()
Clears core dump information.
void schdRunPeriodic(int taskId, int interval)
Schedule a task to run periodically.
void mbootLoad(int imgNo)
Boots a specific image.
uint32_t sysHwDateRev()
Returns the Hardware date revision.
static void __irqEnable()
Enabled IRQ's on a global level.
void schdRunForever()
Invoked in the main, starts the scheduler.
bool lhFlashInit()
Initializes the flash storage (may take a while).
Low level routines for LM32, including interrupt handling.
#define PSTATE_BA
break pointer address
White Rabbit simple timer 'Ticks' driver.
bool schdRegister(SchdTaskF task, bool priority, int *taskId)
Register a task with the scheduler.
System start up and management.
uint32_t _logTime()
Stub function, which should return the current time in seconds, since whatever.
void sysReboot()
Reboot the system.
#define DATEREV
Date/Revision Device.
#define TIMER_SECT_IDLE
time spend being idle
int _shellChar()
Stub function.
static void wdogSetTopCount(uint16_t counterValue)
Set the watchdog top-counter in seconds.
#define TICKS_PER_SEC
Timer is in milliseconds.
static void __irqDisable()
Disables IRQ's on a global level.
#define SPI
SPI memory mapped structure.
bool updInit()
Initializes the update module.
White Rabbit Simple UART Driver.
void lhStore(LogLevel level, char *msg)
Stores a line in the buffer, and in flash if activated.
const char * errGetDescr()
Returns the last error description, if any, else null.
Simple task scheduler for tasks.
#define MBOOT
Multiboot base pointer.
This driver wraps the functions of the OpenCores SPI master.
uint64_t wrxUtcTime()
Returns the UTC time, or 0 if not available.
bool sdbInit()
Initializes the self-describing bus.
#define SUART_BAUDRATE_DEFAULT
Default Baudrate.
void sysLogClearError(const char *doingWhat)
Logs an error in the context of what the application is doing.
Multiboot Driver, exposes one function, mbootLoad.
static uint32_t ticks()
Nr of ticks since device start up.
#define GPIO_BLINK_LED
Led which blink to say I'm alive.
#define I2C
Real OpenCores I2C.
#define IRQ_HANDLER(IRQ)
Defines an IRQ handler.
#define PSTATE_EA
exception address
void suartInit(SUART_Descriptor *desc, unsigned int baudrate)
Initializes the simple UART.
#define logWarn(MSG,...)
Format a log message with warning level.
void gpioPinSet(int pin, bool high)
Sets the pin state.
#define MBOOT_CMD_IPROG
Trigger reconfiguration.
void irqMaskSet(int irq, bool set)
Set/clear the interrupt mask for the specified IRQ.
uint32_t * timerValues()
Returns.
uint32_t bitrate
Bit-rate.
bool sfErase(uint32_t address)
Erase a sector in flash.
uint32_t * pState
Program state before IRQ.
MAX123x multichannel ADC driver.
bool i2cInit(I2C_Device *dev, uint32_t bitrate)
Initializes the I2C device with the specified bitrate.
void errPrint(bool clear)
Prints the last error.
bool spiInit(SPI_Device *dev, SpiInit *init)
Initializes the specified SPI device with the specified parameters.
bool schdAddIdleTask(SchdTaskF idleTask)
Adds an idle task, the task which is executed when there is nothing else to do.
#define CRC32_INIT_VAL
Value to which the CRC32 checksum should be initialized.
void sysBoardTemp(uint16_t *brdTemp, uint16_t *brdTempFrq)
Returns the board temperature with a fractional part.
#define IRQ_ROMXS
Triggered when there is ROM access.
bool wrxUp()
Returns whether or not the WhiteRabbit interface is up and running.
void gpioInit()
Initializes the GPIO.
void errClear()
Clears the current error.
bool sfProgXPage(uint32_t address, uint8_t *data, uint32_t count)
Program cross pages.
volatile WrxInfo * wrxInfo()
Returns the whiteRabbit information structure if available, else NULL.
void sysClearCrashDetect()
Clear crash detect.
#define IRQ_DEBUG
Debug button pressed.
uint32_t errGet()
Returns the last error code, or null.
bool suartRx(SUART_Descriptor *desc, char *c)
Receives a character.
void reboot()
Soft reboot the LM32.
uint32_t crc32(uint32_t crc, const uint8_t *ptr, int cnt, bool dbg)
Lightweight CRC32 algorithm, using Ethernet polynomial.
#define SYS_CRASH_COUNT
After 10 seconds of no main-loop activity, reboot CLB.
#define SPI_DEFAULT_INIT
Default initialization structure.
#define logError(MSG,...)
Format a log message with fatal level.
#define LOG_DEF(NAME,...)
Define a logger for a module.
bool sfRead(uint32_t address, uint8_t *data, uint32_t count)
Read from a specific address in flash.
bool wrxSetAutoNeg(bool on)
Returns autonegotation on or off.
uint32_t sysSwDateRev()
Returns the Software date revision.
This module provides checksum functions.
static bool suartRxReady(SUART_Descriptor *desc)
Returns whether or not the RX buffer has data.
This file assigns all device structures to memory mapped structures.
This driver implements access to the Serial Flash.
bool suartTx(SUART_Descriptor *desc, char c)
Transmits a character.
#define TIMER_SECT_TASK
time spend executing a task
static void wdogFeed()
Feed the watchdog.
void _logOut(LogLevel level, char *logLine)
External dependency function.
Implements a generic logger facility.
void sysLoad(uint8_t *values)
Gives the system load in percentage.
WhiteRabbit exchange exchanges information between the 2nd LM32 and WhiteRabbit though a small client...
#define logInfo(MSG,...)
Write a log message with formatting on info level.
#define SPI_SPEED
Maximum SPI speed = half WB speed.
Configures the board-specific peripherals, like I2C, SPI etc...
Facilitates the update process.
OpenCores I2C device driver.