Navigation Menu

Skip to content

Commit

Permalink
K64F: Minor refactoring for low power driver
Browse files Browse the repository at this point in the history
Signed-off-by: J. German Rivera <jgrivera67@gmail.com>
  • Loading branch information
jgrivera67 committed Aug 31, 2017
1 parent 35f33ca commit 02188c0
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 22 deletions.
41 changes: 26 additions & 15 deletions drivers/mcu_specific/nxp_kinetis_k64f/low_power_driver.adb
Expand Up @@ -97,6 +97,32 @@ is
Restore_Private_Data_Region (Old_Region);
end Initialize;

----------------------------------
-- Schedule_Low_Power_Stop_Mode --
----------------------------------

procedure Schedule_Low_Power_Stop_Mode
is
SCR_Value : SCR_Type;
Old_Region : MPU_Region_Descriptor_Type;
begin
Set_Private_Data_Region (SCB'Address,
SCB'Size,
Read_Write,
Old_Region);

--
-- Enable deep sleep mode (stop mode) in the ARM Cortex-M core, so
-- that the MCU goes to "stop" mode, instead of "wait" mode the next time
-- that it executes a WFI instruction:
--
SCR_Value := SCB.SCR;
SCR_Value.SLEEPDEEP := 1;
SCB.SCR := SCR_Value;

Restore_Private_Data_Region (Old_Region);
end Schedule_Low_Power_Stop_Mode;

-------------------------------
-- Set_Low_Leakage_Stop_Mode --
-------------------------------
Expand All @@ -106,7 +132,6 @@ is
is
PMCTRL_Value : SMC_PMCTRL_Register;
Dummy_PMCTRL_Value : SMC_PMCTRL_Register with Unreferenced;
SCR_Value : SCR_Type;
Old_Region : MPU_Region_Descriptor_Type;
begin
Set_Private_Data_Region (Low_Power_Var'Address,
Expand Down Expand Up @@ -140,20 +165,6 @@ is
--
Dummy_PMCTRL_Value := SMC_Periph.PMCTRL;

--
-- Enable deep sleep mode (stop mode) in the ARM Cortex-M core, so
-- that the MCU goes to "stop" mode, instead of "wait" mode when
-- executing a WFI instruction:
--

Set_Private_Data_Region (SCB'Address,
SCB'Size,
Read_Write);

SCR_Value := SCB.SCR;
SCR_Value.SLEEPDEEP := 1;
SCB.SCR := SCR_Value;

Restore_Private_Data_Region (Old_Region);
end Set_Low_Leakage_Stop_Mode;

Expand Down
3 changes: 3 additions & 0 deletions drivers/portable/low_power_driver.ads
Expand Up @@ -46,6 +46,9 @@ package Low_Power_Driver is
-- Initialize the low power hardware module
--

procedure Schedule_Low_Power_Stop_Mode
with Pre => Initialized;

procedure Set_Low_Power_Run_Mode
with Pre => Initialized;

Expand Down
11 changes: 4 additions & 7 deletions hexiwear_watch/watch.adb
Expand Up @@ -127,6 +127,9 @@ package body Watch is
begin
Low_Power_Driver.Initialize;
Low_Power_Driver.Set_Low_Power_Run_Mode;
Low_Power_Driver.Set_Low_Power_Stop_Mode (
Low_Power_Wakeup_Callback'Access);

RTC_Driver.Initialize;
Accelerometer.Initialize (Go_to_Sleep_Callback => null);

Expand Down Expand Up @@ -464,13 +467,7 @@ package body Watch is
Watch_Var.Display_On := False;
RTC_Driver.Disable_RTC_Periodic_One_Second_Interrupt;
Set_False (Watch_Var.Watch_Task_Suspension_Obj);

--
-- Prepare for deep sleep:
--
Low_Power_Driver.Set_Low_Power_Stop_Mode (
Low_Power_Wakeup_Callback'Access);

Low_Power_Driver.Schedule_Low_Power_Stop_Mode;
elsif Watch_Var.Event_Low_Power_Wakeup then
Watch_Var.Event_Low_Power_Wakeup := False;
LCD_Display.Turn_On_Display;
Expand Down

0 comments on commit 02188c0

Please sign in to comment.