[From 0 to 1 with embedded engineering] Implementation of reset

     Generally, there will be a reset button. After the user presses for a long time, the device performs a reset operation.

    In a certain thread, it is detected every second whether the reset button on the hardware is pressed (interface provided by the driver). setting operation. Note that the judgment time should not be too long. If there is a reset on the hardware, for example, after the hardware itself is pressed for 6 seconds, the hardware itself will reset, that is, the signal of the hardware button will also be reset. If the 7S is judged to be a long press, then the software will not be able to judge the reset signal, because the hardware has restarted before the time has come. If there is a reset on the hardware, such as 6S, 2S on the software considers that there is a reset, so the execution time of the reset operation must be completed within 4S, that is, before the hardware resets itself.

    There are two ways to reset the operation, one is to do it immediately after receiving the reset signal, and then restart; the other is to assign a flag bit after receiving the reset signal, write it in the flash, and after the restart , according to this flag bit, know that it is a reset restart, and then do the reset operation. The first one is suitable for the case where the reset operation takes a short time or the restart time can be controlled by the software, and the second one is suitable for the reset operation which takes a long time and should be done at the next startup.

    Let’s talk about an implementation first. After receiving the confirmation reset command, flush the fd of the current configuration file, then turn it off, delete the user configuration file, delete the wifi configuration file, turn on the indicator light, play the prompt tone, and create a short thread To stop some operations such as recording, unmounting the SD card, etc., wait for the completion of the short thread execution, execute reboot (RB_AUTOBOOT), and restart the device.

    Next, the configuration information in the previous article will be used, because the user configuration has been deleted before restarting. When restarting, the default configuration is loaded, and the server has reset flag is 0 by default, indicating that it has not been reset. The reset state is synchronized to the background. When the device is reconnected to the network, it will tell the reset state to the background, and then set the has reset to 1 and save it in the configuration file. In this way, other normal restarts, when loading the configuration, get the status that has been reset. After the configuration and the background reset, there is no need to send a reset request to the background.

    The other is, after confirming the reset, first write the default data to the configuration file, and after restarting, tell the system that I am start with reset. Play the prompt tone, then execute ifconfig wlan0 down, rmmod xxx and reboot -f, stop the wifi, uninstall the necessary modules, and restart.

    At startup, according to the start with reset configuration information, do what needs to be done for the first startup, and after connecting to the network, reset it with the background.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325813061&siteId=291194637