Author Topic: trying to use fnDelayResetBoard()  (Read 11819 times)

Offline alager

  • Jr. Member
  • **
  • Posts: 92
    • View Profile
trying to use fnDelayResetBoard()
« on: October 05, 2009, 08:57:20 PM »
Mark,

I'm using the secret command "MAC" for factory configuration.  I've found that after I set the MAC, the system reboots faster than the UART can output the message "\r\nConfiguration saved\r\n". (~23ms)
So I tried removing the static qualifier on fnDelayResetBoard() and called it instead, but then the card never resets.

Code: [Select]
else {
            fnDoFlash(DO_SAVE_PARS, 0);                                  // save the new MAC address
            //fnResetBoard();                                              // reset so that it strats with the new values
   fnDelayResetBoard(); //delay to allow UART to complete, then reset with new values.
any ideas on how to make this work?

BTW, in the simulator, the message is printed fine with the regular fnResetBoard() function call.  I think this is a windows simulator buffering trick though.

Thanks,
Aaron
« Last Edit: October 05, 2009, 09:08:44 PM by alager »

Offline alager

  • Jr. Member
  • **
  • Posts: 92
    • View Profile
Re: trying to use fnDelayResetBoard()
« Reply #1 on: October 05, 2009, 10:00:10 PM »
It's been a while, since I've touched this code, so I'm sure I'm doing something wrong.
I put the other code mentioned above, back in place.  I now have added a TIMER_EVENT to fnDebug()
Code: [Select]
case TIMER_EVENT:
   fnRead( PortIDInternal, ucInputMessage, ucInputMessage[MSG_CONTENT_LENGTH]); // read the contents
            if (ucInputMessage[ 0 ] == E_TIMER_SW_DELAYED_RESET) {
fnResetBoard();
   }
   break;

and added my own function to trigger the case:
Code: [Select]
static void fnUartDelayResetBoard(void){
    uTaskerMonoTimer( TASK_DEBUG, (DELAY_LIMIT)(1*SEC), E_TIMER_SW_DELAYED_RESET );
}

and from fnDoIP() I have:
Code: [Select]
#ifdef USE_PARAMETER_BLOCK                                           // {5}
        else {
            fnDoFlash(DO_SAVE_PARS, 0);    // save the new MAC address
            //fnResetBoard();                     // reset so that it strats with the new values
   //fnDelayResetBoard(); //delay to allow UART to complete, then reset with new values.
     fnUartDelayResetBoard();
        }
    #endif
        break;

I do get to the if statement, but the ucInputMessage[0] value is 47, while E_TIMER_SW_DELAYED_RESET is defined as 131.

Why isn't the message what I have set it to?

Aaron
« Last Edit: October 05, 2009, 10:05:35 PM by alager »

Offline alager

  • Jr. Member
  • **
  • Posts: 92
    • View Profile
Re: trying to use fnDelayResetBoard()
« Reply #2 on: October 05, 2009, 10:20:41 PM »
Never mind...I'm a dork! :P

I needed
Code: [Select]
if (ucInputMessage[ MSG_TIMER_EVENT ] == MAC_SET_DELAY_RESET) {
instead of
Code: [Select]
if (ucInputMessage[ 0 ] == MAC_SET_DELAY_RESET) {


Aaron

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3238
    • View Profile
    • uTasker
Re: trying to use fnDelayResetBoard()
« Reply #3 on: October 06, 2009, 03:25:48 PM »
Hi Aaron

When using fnDelayResetBoard() you have to be careful with what else the application task is doing.
This uses a monostable timer delay at the application task but the application task may be being used for other timers too. Since the application task (in the demo code) is set up to have only a single monostable timer it is possible that a second timer use will take over the reset timer (the monostable timer operation is "single-shot retriggerable") and so the reset delay will effectively be lost.

Note that this is a bit of a problem when using the LCD demo (for example) because it uses the application timer all of the time for short delays. When the reset is commanded the LCD operation often causes the reset timer to be retriggered (taken over by an LCD timer event) and so it never actually fires. In the demo it is generally not a big deal since the reason is clear. In a real application it is advisable to either have a task dedicated to the timer or use global monostable operation (where a task can serve multiple timers) so that its function is reliable.

Regards

Mark