Reset vector from BASIC

Questions about the BASICtools and MakeItC
Post Reply
basicchip
Posts: 1028
Joined: Fri Oct 19, 2012 2:39 am
Location: Lake Tahoe, CA
Contact:

Reset vector from BASIC

Post by basicchip »

> from help line
>Is there a reset vector in the SuperPro that can be executed through BASIC in order to approximate a hardware reset?

>I have an instance where it would be beneficial to completely re-start the SuperPro under program control without having to toggle an external line. I suppose I could route one i/o to DTR with a jumper (but it seems like a kludge).

>I suppose, if there's not a BASIC construct to do it (like the old SYS() command), that it might be possible to push a false return on the stack, or to do a GOTO or GOSUB to a hex address.
>If I had the address of the reset vector, I could simply gosub to it via pointer to effect the reset.

Actually I think the closest is the watchdog timer, spelled out in the forum here. It does do a reset, and it is a good way to protect from a code run-away.

The other way is to do some educated guessing on the Boot ROM (no I don't have the code for it)

From the user manual for the LPC175x, the memory map puts the Boot ROM at &H1FFF0000

From BASIC you can just poke around at it. Cortex ARMs boot by loading the value at location 0 into the SP, and location 4 into the PC. I assume that on powerup the Boot ROM is mapped to location 0. So here is my guess at how to do it

Code: Select all

@1fff0000

1fff0000:  10001FFC 1FFF0081 00000000 00000000 00000000 00000000 00000000 00000000 
wait(100)
call (&H1fff0081)
run
Programming Flash 1756...
ARMbasic[9.27h] on the PC  Copyright 2013, Coridium Corp.
*+
... ( 0.03K code + 0.00K const)/96K   0.00/9K data programmed
Executing...

Welcome to ARMbasic Kernel[8.25] with Floating Point            Copyright 2013, Coridium Corp.
  for the SuperPro  
OK, well good try but it didn't really work. While it did actually restart from the reset vector, when the BASIC firmware comes up, if the power on reset was true, or the reset pin was pulled low, or the watchdog timer was tripped, then the user BASIC program starts up. Anything else is treated like an unhandled exception and the user program is not started.

So, I learned something here to, or at least reminded myself of how things startup (at least today).

SO the conclusion is either connect an IO line to the reset (which I have done before), or use the Watchdog.



AMDlloydsp
Posts: 99
Joined: Mon Apr 15, 2013 3:51 pm
Location: NE Central FL

Re: Reset vector from BASIC

Post by AMDlloydsp »

Thank you.

It'll probably be the watchdog, being the cleaner solution.

Is BASIC or the LPC1756 kernel code using the watchdog currently, or can I take it over completely without penalty (for my own watchdog purposes)?
Nevermind! That was answered in the Watchdog threads!


Thanks,
Lloyd
Last edited by AMDlloydsp on Tue Oct 22, 2013 1:53 am, edited 1 time in total.

basicchip
Posts: 1028
Joined: Fri Oct 19, 2012 2:39 am
Location: Lake Tahoe, CA
Contact:

Re: Reset vector from BASIC

Post by basicchip »

None of the BASICs use the Watchdog, so it is free for user code.

We have used it ourselves in code both BASIC and on trial versions of firmware. When we were debugging remote versions of ARMweb we enabled the watchdog to kick us out of TCPIP code problems.

AMDlloydsp
Posts: 99
Joined: Mon Apr 15, 2013 3:51 pm
Location: NE Central FL

Re: Reset vector from BASIC

Post by AMDlloydsp »

I finally got into a project that made me implement a software reboot of the SuperPro. This works nicely.


#define WDMOD *&H40000000 ' watchdog mode register
#define WDFEED *&H40000008 ' watchdog timer feed register, must get an "AA" followed by a "55" to work
#define WDTC *&H40000004 ' watchdog timer timeout constant register
.
.
.
interrupt(0) ' turn off interrupts, so my local IRQs cannot interrupt our settings of the Watchdog timer
WDTC = &H000000FF ' set the time constant to the minimum
WDMOD = &H00000003 ' set the WDMOD register to enable interrupts and start the watchdog with WDEN and WDRESET true
WDFEED = &H000000AA ' poke the Watchdog timer feed register with the start of a feed command
WDFEED = &H00000055 ' finish the feed command. At LEAST ONE successful feed must occur to assert WDRESET
WDFEED = &H000000AA ' now start another feed, but this time,
WDTC = &H00000000 ' cause a fault interrupt by not completing it properly with a 0x55
interrupt(1) ' just on GPs to keep things balanced, not that it will have any effect, since a reset is occurring

Lloyd

AMDlloydsp
Posts: 99
Joined: Mon Apr 15, 2013 3:51 pm
Location: NE Central FL

Re: Reset vector from BASIC

Post by AMDlloydsp »

BTW... it turns out that Bruce already defined all those registers for us.

Here are the defs from LPC17xx.bas (from BASICLIB)

#define WDG_BASE_ADDR &H40000000
#define WD_WDMOD *(WDG_BASE_ADDR + &H00)
#define WD_WDTC *(WDG_BASE_ADDR + &H04)
#define WD_WDFEED *(WDG_BASE_ADDR + &H08)
#define WD_WDTV *(WDG_BASE_ADDR + &H0C)
#define WD_WDCLKSEL *(WDG_BASE_ADDR + &H10)

Lloyd

Post Reply