This library allows any user to use their Mbed project with a transient energy source( e.g. windturbine, solar power).

Dependencies:   mbed

Fork of Hibernus by Bogdan Lazarescu

This library allows any user to use their Mbed project with a transient energy source( e.g. windturbine, solar power). You can do this by simply import the "hibernus.h" header file, and call the "Hibernus()" method at the beginning of you main program. In case of a power loss the state of your programm will be saved to the nonvolatile memory and it will be resumed from the same point as soon as there is enough power for the board to run properly. If the power drops down, the internal capacitance of the system is used to save a snapshot of your program into the flash memory, and the board goes in a low power mode (sleep or deepsleep). In order to detect a power loss, the library uses an analog comparator which can be internal (eg Freescale KL 05Z has an internal comparator which can be used ), or external (on LPC11U24 there is no internal comparator) via a GPIO interrupt. For more details see the code comments and the attached example main.cpp file.

This library use "IAP" library, in order to write the required data to the flash nonvolatile memory.

The library can be easily adapted to work with other boards, from different manufactures, which have support for Mbed. In order to adapt this library and use it on your board, the write to flash methods have to be changed. Some changes listed below are required because of the platform dependent parameters of each board. All required changes have to be applied to the "config.h" and "config.cpp" files.

  • The "erase_flags_memory()", "copyRamToFlash()", "restore_flags()", "setFlag()" and " isFlagSet()" methods have to be modified in order to use the right Flash IAP of your board.
  • The wake up and hibernate interrupts have to be modified in order to be trigghered when the voltage drops down or rise. If you use an internal comparator, it should trigger and interrupt whenever the power drops(e.g see CMP0_IRQHandler() method writtend for KL05Z at https://developer.mbed.org/users/BogdanL/code/Hibernus-KL05Z/ ) . At that time a snapshot have to be saved and the board sent to sleep. Another interrupt have to be triggered when the power comes back(see "LLW_IRQHandler()" at https://developer.mbed.org/users/BogdanL/code/Hibernus-KL05Z ) . This have to wake up the board and resume de computation. In you use an external comparator two GPIO interrupts are used. One of them (for LPC11U24 see "FLEX_INT1_IRQHandler()" ) is used to save the snapshot when the power drops down, and the other one (for LPC11U24 see "FLEX_INT0_IRQHandler()" ) is used to wake up the board.
  • For each board, the right Sleep mode have to be chosen. Also the interrups and the comparator have to be properly set, in order to be triggered as desired. For a good example see "configure_VR_gpio_interrupt()" and "configure_VH_gpio_interrupt()" that are used to set up the Restore and Hibernate interrupts on LPC11U24 board, that uses an external comparator.
  • In the "config.h" file, the two arrays, "REG_Addresses_4B[]" and "REG_Addresses_4B[]" have to be populated with the addresses of the 1 Byte and 4Bytes peripheral registers that are used by your project. Different boards have different modules that use different peripheral registers. The addresses of the registers can be found in the Reference Manual of each board, and will be used in order to save and later restore the content of the registers. Also the number of used registers, "No_Of_4B_Peripheral_Reg", No_Of_1B_Peripheral_Reg, have to be updated with the correct number of used registers.
  • At the top of "config.h" header file, specific board parameters have to be fixed: RAM start address(RAM_1_Address), Flash start address(FLASH_Start), RAM size(RAM_Size), Flash size(flash_Size) and the flash sector size(sector_Size).
Committer:
BogdanL
Date:
Fri Sep 08 18:01:22 2017 +0000
Revision:
0:f9a13d4b41f3
First Version of Hibernus Library;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
BogdanL 0:f9a13d4b41f3 1 /** Hibernus Library
BogdanL 0:f9a13d4b41f3 2 * University of Southampton 2017
BogdanL 0:f9a13d4b41f3 3 *
BogdanL 0:f9a13d4b41f3 4 * Open-source liberary that enable any of your Mbed project work with transient enegy sources.
BogdanL 0:f9a13d4b41f3 5 * In order to use this library include the "hibernus.h" header file, and use the "Hibernus()" method at the beginning of you main funtion.
BogdanL 0:f9a13d4b41f3 6 * For more details and example see the "main.cpp" exampe file, and the attached documnetation
BogdanL 0:f9a13d4b41f3 7 *
BogdanL 0:f9a13d4b41f3 8 *
BogdanL 0:f9a13d4b41f3 9 * Released under the MIT License: http://mbed.org/license/mit
BogdanL 0:f9a13d4b41f3 10 */
BogdanL 0:f9a13d4b41f3 11 #ifndef CONFIG_H_
BogdanL 0:f9a13d4b41f3 12 #define CONFIG_H_
BogdanL 0:f9a13d4b41f3 13 #ifdef LPC11U24
BogdanL 0:f9a13d4b41f3 14 #include "mbed.h"
BogdanL 0:f9a13d4b41f3 15 #include "IAP.h"
BogdanL 0:f9a13d4b41f3 16
BogdanL 0:f9a13d4b41f3 17 /////for LPC11U24
BogdanL 0:f9a13d4b41f3 18 #define RAM_Start 0x10000000
BogdanL 0:f9a13d4b41f3 19 #define FLASH_Start 0x00000000
BogdanL 0:f9a13d4b41f3 20 #define RAM_Size 8192
BogdanL 0:f9a13d4b41f3 21 #define flash_Size 32768 //32K flash
BogdanL 0:f9a13d4b41f3 22 #define sector_Size FLASH_SECTOR_SIZE //4K sector size
BogdanL 0:f9a13d4b41f3 23
BogdanL 0:f9a13d4b41f3 24 #define No_Of_4B_Peripheral_Reg 10
BogdanL 0:f9a13d4b41f3 25 #define No_Of_1B_Peripheral_Reg 0
BogdanL 0:f9a13d4b41f3 26
BogdanL 0:f9a13d4b41f3 27 const unsigned int REG_Addresses_4B[83] = {
BogdanL 0:f9a13d4b41f3 28 (unsigned int)&LPC_GPIO_PIN_INT->ISEL, /*!< (@ 0x4004C000) Pin Interrupt Mode register */
BogdanL 0:f9a13d4b41f3 29 (unsigned int)&LPC_GPIO_PIN_INT->IENR, /*!< (@ 0x4004C004) Pin Interrupt Enable (Rising) register */
BogdanL 0:f9a13d4b41f3 30 (unsigned int)&LPC_GPIO_PIN_INT->SIENR, /*!< (@ 0x4004C008) Set Pin Interrupt Enable (Rising) register */
BogdanL 0:f9a13d4b41f3 31 (unsigned int)&LPC_GPIO_PIN_INT->CIENR, /*!< (@ 0x4004C00C) Clear Pin Interrupt Enable (Rising) register */
BogdanL 0:f9a13d4b41f3 32 (unsigned int)&LPC_GPIO_PIN_INT->IENF, /*!< (@ 0x4004C010) Pin Interrupt Enable Falling Edge / Active Level register */
BogdanL 0:f9a13d4b41f3 33 (unsigned int)&LPC_GPIO_PIN_INT->SIENF, /*!< (@ 0x4004C014) Set Pin Interrupt Enable Falling Edge / Active Level register */
BogdanL 0:f9a13d4b41f3 34 (unsigned int)&LPC_GPIO_PIN_INT->CIENF, /*!< (@ 0x4004C018) Clear Pin Interrupt Enable Falling Edge / Active Level address */
BogdanL 0:f9a13d4b41f3 35 (unsigned int)&LPC_GPIO_PIN_INT->RISE, /*!< (@ 0x4004C01C) Pin Interrupt Rising Edge register */
BogdanL 0:f9a13d4b41f3 36 (unsigned int)&LPC_GPIO_PIN_INT->FALL, /*!< (@ 0x4004C020) Pin Interrupt Falling Edge register */
BogdanL 0:f9a13d4b41f3 37 (unsigned int)&LPC_GPIO_PIN_INT->IST,
BogdanL 0:f9a13d4b41f3 38 };
BogdanL 0:f9a13d4b41f3 39
BogdanL 0:f9a13d4b41f3 40 const unsigned int REG_Addresses_1B[30] = {};
BogdanL 0:f9a13d4b41f3 41
BogdanL 0:f9a13d4b41f3 42 #if HasInternalComparator == 1
BogdanL 0:f9a13d4b41f3 43 void configure_VR_comparator_interrupt(void);
BogdanL 0:f9a13d4b41f3 44 void configure_VH_comparator_interrupt(void);
BogdanL 0:f9a13d4b41f3 45 void Comparator_Setup(void);
BogdanL 0:f9a13d4b41f3 46 #else
BogdanL 0:f9a13d4b41f3 47 extern "C" void FLEX_INT0_IRQHandler(void);
BogdanL 0:f9a13d4b41f3 48 extern "C" void FLEX_INT1_IRQHandler(void);
BogdanL 0:f9a13d4b41f3 49 void configure_VH_gpio_interrupt(void);
BogdanL 0:f9a13d4b41f3 50 void configure_VR_gpio_interrupt(void);
BogdanL 0:f9a13d4b41f3 51 #endif
BogdanL 0:f9a13d4b41f3 52
BogdanL 0:f9a13d4b41f3 53 void erase_flags_memory(void);
BogdanL 0:f9a13d4b41f3 54 void restore_flags(void);
BogdanL 0:f9a13d4b41f3 55 void Enter_LLS(void);
BogdanL 0:f9a13d4b41f3 56 void setFlag(volatile unsigned int*);
BogdanL 0:f9a13d4b41f3 57 bool isFlagSet(volatile unsigned int*);
BogdanL 0:f9a13d4b41f3 58 void copyRamToFlash(void);
BogdanL 0:f9a13d4b41f3 59
BogdanL 0:f9a13d4b41f3 60 #endif
BogdanL 0:f9a13d4b41f3 61 #endif
BogdanL 0:f9a13d4b41f3 62