|
Forum Index : Microcontroller and PC projects : MM.RESTART like MM.WATCHDOG?
| Author | Message | ||||
sagt3k![]() Guru Joined: 01/02/2015 Location: ItalyPosts: 313 |
Hi Geoff Is it possible to have a variable like MM.WATCHDOG but increased +1 after the instruction CPU RESTART? Thanks Antonio |
||||
| Turbo46 Guru Joined: 24/12/2017 Location: AustraliaPosts: 1646 |
Antonio, Would something like this suit your purpose? ' DIM CPU_Starts% = 0 VAR RESTORE CPU_Starts% = CPU_Starts + 1 IF CPU_Starts% <= 10 THEN VAR SAVE END IF ' If this is put near the start of your program CPU_Starts% will record the number of times the program has restarted. I've chosen a limit of 10 to save the flash from over-use. It might be a problem if you are using VAR SAVE and VAR RESTORE elsewhere in your program. Bill Keep safe. Live long and prosper. |
||||
sagt3k![]() Guru Joined: 01/02/2015 Location: ItalyPosts: 313 |
Hi Bill Thanks, I already use this method, I just wanted to know if it was useful and implementable MM.RESTART in RAM. Is CPU RESTART a HW reset or SW reset? Antonio |
||||
| Turbo46 Guru Joined: 24/12/2017 Location: AustraliaPosts: 1646 |
OK Antonio, But your query did make me realise that it would be good to have a way of knowing if a watchdog (internal or external) was operated and how many times it has. In a slave device, this could be reported to the master. Bill Keep safe. Live long and prosper. |
||||
sagt3k![]() Guru Joined: 01/02/2015 Location: ItalyPosts: 313 |
Hi Bill Exact , it would be convenient to have a variable RAM (integer) that is not affected by a sw reset.Take for example simple IOT remote device. You put it in inaccessible places, maybe you've never had power problems, but for reasons of logic code you had watchdog and cpu restart, then after you connect a uart and you would like to know how many times the micro has restarted. Ok, you could use the RAM/EPROM of other devices/i2c, but it would increase the costs and complexity of the circuit. Antonio |
||||
| matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 10572 |
This should certainly be possible and sounds like a useful idea. I'll have a play on the MMX as part of the 5.05.01 update and report back. |
||||
| Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3308 |
It is possible (and easy to do). The syntax would be challenging. Perhaps something like: MM.KEEPVALUE = nn CPU RESET ... PRINT MM.KEEPVALUE Geoff Geoff Graham - http://geoffg.net |
||||
| matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 10572 |
Just implemented in the latest MMX firmware long long int saved_variable __attribute__ ((persistent)); void fun_persist(void){ iret = saved_variable; targ = T_INT; } void cmd_persist(void) { while(*cmdline && tokenfunction(*cmdline) != op_equal) cmdline++; if(!*cmdline) error("Syntax"); saved_variable = getinteger(++cmdline); } |
||||
sagt3k![]() Guru Joined: 01/02/2015 Location: ItalyPosts: 313 |
Hi Geoff & matherph Thanks , but will it be available on all MMbasic family PIC32,MMX,STM32 ?Thanks Antonio |
||||
| The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |