0

I'm working on a project for automotive system where we use the MPC5748 MCU. The application uses an RTOS based on AUTOSAR OS, and this MPC target support two type of watchdogs; software and hardware (they have used soft WDT).

My mission is to fit an algorithm within this application, the development of the algorithm has been done, the problem is that in the task where the algorithm is running is a 1ms task and the algorithm needs much more time than the time dedicated to this function.

I'm a newbie to the embedded world.By the way, in the algorithm main function the program will reset itself and this seems to be a timeOut generated by the expiration of the watchdog.

My questions are:

  1. Can I disable the watchdog timer for this specified function (which must not be disabled but just for testing purpose)? It is possible to use more timeOut for the watchdog on that specified function?

  2. Must I develop another task with a big delay in other to run the algorithm? But the problem is that the algorithm need to be synchronised with the 1ms task since we are receiving CAN commands.

  3. Can i add a sleep(<1ms) on the desired function in order to wait a little bit witout affecting other tasks

  4. What are other options to try?

NB: This is a general problem on the watchdog timer and any useful informations will be much helpful for me. Sorry because I can't share the code.

The Beast
  • 1,629
  • 2
  • 29
  • 42
  • 1
    I believe [this answer](http://stackoverflow.com/questions/14758045/strategy-for-feeding-a-watchdog-in-a-multitask-environment/14780682#14780682) (and question) will be helpful to you. – kkrambo Apr 23 '16 at 21:35
  • 1
    It would be useful perhaps to know how long the "algorithm" actually takes to run - is it fixed? Is it deterministic? Does the 1ms task use the result of the algorithm directly? What is the purpose of the algorithm? What is reg responsibility of the task (other than CAN Rx mentioned)? You cannot share the code, but pseudo-code outlining the task architecture might help. – Clifford Apr 24 '16 at 08:24
  • that's the problem the decompression algorithm does have a specific timing and depends on the content of the file that have been compressed ... i have measured the elapsed time and i've found that the algorithm can pass 10us (MicroSeconds) to decode a single frame and for another frame that will be decoded to a lot of datas it goes up to 800 uS and in the worst case it goes for more than 1ms and more .... – The Beast Apr 24 '16 at 10:38
  • the results of this is read by the flash module to flash the data.the flash controller is not fast enough to flash a big amount of data (40 kb after decoding one frame of 8 bytes) sot it need to tell the decompressor to stop decoding frames until it finish the flashing operation ... the algorithm decompress data to be flashed in order to speed the transmission time (since the compressed file will be much smaller x4 from the original file) – The Beast Apr 24 '16 at 10:40

3 Answers3

3

Can I disable the watchdog timer for this specified function (which must not be disabled but just for testing purpose)? It is possible to use more timeOut for the watchdog on that specified function?

Let's forget that one - it is a really bad idea. If it is possible to defeat the watchdog, then it is possible to do it by error, and then the whole point of the watchdog is defeated. Apart from that its an XY question - a question about your proposed solution to a different problem - you should ask about the problem directly.

Must I develop another task with a big delay in other to run the algorithm? But the problem is that the algorithm need to be synchronised with the 1ms task since we are receiving CAN commands.

Yes you need another task, but you should not add a "big delay" and it is probably unnecessary and certainly a bad design. If the 1ms task needs the result of the algorithm then, the algorithm should run in a service task triggered by the 1ms task and run asynchronously to the 1ms task, the service task then makes the results available to the 1ms task when available (by shared memory or message passing perhaps). Alternatively if the result is not specifically needed by the 1ms task, the service task could take the necessary action independently of the 1ms task.

There are many options, but essentially it seems that your task partitioning is inappropriate; your CAN Rx task should be responsible for receiving CAN messages only, and any action required in response to CAN messages deferred to one or more other tasks, perhaps fed from a message queue.

What are other options to try ?

Software design should not be a matter of trial and error - get the design right, implement the design. However you might consider whether 1ms is appropriate; is it possible that the period can be extended to encompass the worst case execution time without causing a failure to meet deadlines in general? If the answer is "no" then the algorithm does not belong in this task.

Clifford
  • 88,407
  • 13
  • 85
  • 165
  • Thanks for your response , so let me explain you more the algorithm just read the incoming can frames , decompress each incoming frame and in parallel read the following one , the host keeps sending frames .... the result of the decompression will be used by the Flash module to flash those data into their corresponding adresses ... The problem does not appear when decompression a file with small compression ratio but when the compression ratio is very big : – The Beast Apr 24 '16 at 10:30
  • let's say the target will receive 200 bytes and needs to decompress that bytes to 200 KB or more (in case the whole files contains one repetitive word).In this particular case the flash module needs more time to flash the corresponding data so the decompressor should wait until the flash finish but must keep reading can frames , sorry if i was not clear but i can resume that in the following CAN frames ==> Decompressor ==> Flash module ... thanks a lot – The Beast Apr 24 '16 at 10:33
2

I don't think so you can disable/delay the WATCHDOG timer and even if you could that's not a good option to go for.

The problem what think is that the task you are calling is of 1ms, which is very less to read CAN messages and then operate on the same. The minimum task time i think should be of 5ms and the optimal time should be of 10ms.

codeDEXTER
  • 1,181
  • 7
  • 14
  • No the minimal task that read can frames is operating every 1ms but the algorithm (wich will decompress incoming can frames and perform a flash operation is taking more than that time).So you think i have to develop another task that take much more time ? thanks – The Beast Apr 24 '16 at 10:23
  • yes actually the flash operation takes a lot of time. so it would be better if you could create a sub task with a longer duration containing a queuing operating to write to the flash. where the queue would be updated by the `1ms` task. – codeDEXTER Apr 24 '16 at 16:14
2

Can I disable the watchdog timer for this specified function (which must not be disabled but just for testing purpose)? It is possible to use more timeOut for the watchdog on that specified function?

You should never disable the watchdog anywhere in your code.

It might not even be possible, on the MPC5x families you typically set up the watchdog once, and then for safety reasons all watchdog registers turn to read-only registers.

Must I develop another task with a big delay in other to run the algorithm? But the problem is that the algorithm need to be synchronised with the 1ms task since we are receiving CAN commands.

Ideally you should only service the watchdog from one single location in the program. Your CAN peripheral will be FlexCAN, which has a lot of available "mailboxes" for CAN messages. In most cases, you shouldn't need to poll it, but a flag will be set when the desired message arrive.

So it isn't obvious to me why you would need a delay to wait for them. Simply do:

void the_task (void)
{
  wdog_refresh(); 

  ... // do other things

  if(can_message_available)
  {
    // do something with the message
  }

  ... // do other things
}

rather than

// BAD:
while(!can_message_available)
  ; // do nothing

Even if you need to use the CAN as FIFO and poll it repeatedly, you would still use the same approach. You'd just have to ensure that the task runs often enough that there will never be an overflow in the FIFO buffer.

Lundin
  • 195,001
  • 40
  • 254
  • 396
  • The FIFO for can commands is already implmented , to give you an example : i need to decompress an incoming frame (8 bytes to 40 kb in worst case) the flash controller needs more time in order to write all this data into the FLASH Memory so i need to PAUSE the algorithm in parts so every 10 kb is flashed and then complete the decoding operation ... – The Beast Apr 25 '16 at 23:20
  • @Frankenstein Bootloaders are always special cases, it usually doesn't make any sense to run the application as usual while flash is getting programmed. Also, the flash erase time is usually longer than a standard watchdog timeout, so you either have to adapt the watchdog to the flash erase time, or create a special bootloader mode out of reset. – Lundin Apr 26 '16 at 06:26