1 /** mbed Microcontroller Library
2   ******************************************************************************
3   * @file    sleep_ex_api.h
4   * @author
5   * @version V1.0.0
6   * @brief   This file provides mbed API for SLEEP.
7   ******************************************************************************
8   * @attention
9   *
10   * Copyright (c) 2015, Realtek Semiconductor Corp.
11   * All rights reserved.
12   *
13   * This module is a confidential and proprietary property of RealTek and
14   * possession or use of this module requires written permission of RealTek.
15   ******************************************************************************
16   */
17 #ifndef MBED_SLEEP_EX_API_H
18 #define MBED_SLEEP_EX_API_H
19 
20 #include "device.h"
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 /** @addtogroup sleep_ex SLEEP_EX
27  *  @ingroup    hal
28  *  @brief      sleep extended functions
29  *  @{
30  */
31 
32 #if defined(CONFIG_PLATFORM_8195A) && (CONFIG_PLATFORM_8195A == 1)
33 ///@name Ameba1 Only
34 ///@{
35 /* Sleep Eake Up event, the User application also
36    need to config the peripheral to trigger wake up event */
37 #define SLEEP_WAKEUP_BY_STIMER            (SLP_STIMER)    // wake up by system timer
38 #define SLEEP_WAKEUP_BY_GTIMER            (SLP_GTIMER)    // wake up by General purpose timer timeout
39 #define SLEEP_WAKEUP_BY_GPIO_INT          (SLP_GPIO)      // wake up by GPIO Port A[7:0] Interrupt
40 #define SLEEP_WAKEUP_BY_WLAN              (SLP_WL)        // wake up by WLan event
41 #define SLEEP_WAKEUP_BY_NFC               (SLP_NFC)       // wake up by NFC event
42 #define SLEEP_WAKEUP_BY_SDIO              (SLP_SDIO)      // wake up by SDIO event
43 #define SLEEP_WAKEUP_BY_USB               (SLP_USB)       // wake up by USB event
44 
45 // Deep Standby Wakeup event
46 #define STANDBY_WAKEUP_BY_STIMER      (BIT0)     // wake up by system timer
47 #define STANDBY_WAKEUP_BY_NFC         (BIT1)     // wake up by NFC event
48 //#define SLEEP_WAKEUP_BY_DS_TIMER    (BIT2)     // The timer to wakeup from Deep Sleep timer
49 // Do not modify these definition, or need to modify the code also.
50 #define STANDBY_WAKEUP_BY_PA5         (BIT4)     // GPIO Port A[5]
51 #define STANDBY_WAKEUP_BY_PC7         (BIT5)     // GPIO Port C[7]
52 #define STANDBY_WAKEUP_BY_PD5         (BIT6)     // GPIO Port D[5]
53 #define STANDBY_WAKEUP_BY_PE3         (BIT7)     // GPIO Port E[3]
54 
55 // Deep Sleep Wakeup event
56 #define DSLEEP_WAKEUP_BY_TIMER     (DS_TIMER33)
57 #define DSLEEP_WAKEUP_BY_GPIO      (DS_GPIO)    // GPIO Port B[1]
58 
59 typedef struct _SLEEP_WKUP_EVENT_ {
60     u8 wakeup_event;    // Wake up event: Timer, NFC, GPIO
61     u8 gpio_option;     // GPIO Wakeup setting: [3:0]: Pin 3~0 enable, [7:4]: pin3~0 active high/low
62     u32 timer_duration; // the sleep duration and then wakeup
63 } SLEEP_WAKEUP_EVENT, *PSLEEP_WAKEUP_EVENT;
64 ///@}
65 #endif //CONFIG_PLATFORM_8195A
66 
67 #if defined(CONFIG_PLATFORM_8711B) && (CONFIG_PLATFORM_8711B == 1)
68 ///@name AmebaZ Only
69 ///@{
70 /* Sleep Eake Up event, the User application also
71    need to config the peripheral to trigger wake up event */
72 #define SLEEP_WAKEUP_BY_STIMER			(BIT_SYSON_WEVT_SYSTIM_MSK)    // wake up by system timer
73 #define SLEEP_WAKEUP_BY_GPIO_INT		(BIT_SYSON_WEVT_GPIO_MSK)      // wake up by GPIO Port A[31:0] Interrupt
74 #define SLEEP_WAKEUP_BY_WLAN			(BIT_SYSON_WEVT_WLAN_MSK)        // wake up by WLan event
75 #define SLEEP_WAKEUP_BY_SDIO			(BIT_SYSON_WEVT_SDIO_MSK)      // wake up by SDIO event
76 #define SLEEP_WAKEUP_BY_USB				(BIT_SYSON_WEVT_USB_MSK)       // wake up by USB event
77 #define SLEEP_WAKEUP_BY_GPIO			(BIT_SYSON_WEVT_GPIO_DSTBY_MSK)       // GPIO Port(PA_18, PA_5, PA_22, PA_23)
78 #define SLEEP_WAKEUP_BY_UART			(BIT_SYSON_WEVT_UART0_MSK | BIT_SYSON_WEVT_UART1_MSK)       // wake up by UART event
79 #define SLEEP_WAKEUP_BY_I2C				(BIT_SYSON_WEVT_I2C0_MSK | BIT_SYSON_WEVT_I2C1_MSK)		 // wake up by I2C event
80 #define SLEEP_WAKEUP_BY_RTC				(BIT_SYSON_WEVT_RTC_MSK)       // wake up by RTC event
81 
82 // Deep Standby Wakeup event
83 #define STANDBY_WAKEUP_BY_STIMER		(BIT_SYSON_WEVT_A33_AND_A33GPIO_MSK)     // wake up by 1K timer
84 #define STANDBY_WAKEUP_BY_GPIO			(BIT_SYSON_WEVT_GPIO_DSTBY_MSK)     // GPIO Port(PA_18, PA_5, PA_22, PA_23)
85 #define STANDBY_WAKEUP_BY_RTC			(BIT_SYSON_WEVT_RTC_MSK)       // wake up by RTC event
86 
87 // Deep Sleep Wakeup event
88 #define DSLEEP_WAKEUP_BY_TIMER		BIT(0)
89 #define DSLEEP_WAKEUP_BY_GPIO			BIT(2)    // GPIO Port(PA_18, PA_5, PA_22, PA_23)
90 
91 typedef struct _SLEEP_WKUP_EVENT_ {
92     u32 wakeup_event;    // Wake up event: Timer, NFC, GPIO
93     u32 gpio_option;     // GPIO Wakeup setting: [3:0]: Pin 3~0 enable, [11:8]: pin3~0 active high/low
94     u32 timer_duration; // the sleep duration and then wakeup
95 } SLEEP_WAKEUP_EVENT, *PSLEEP_WAKEUP_EVENT;
96 ///@}
97 #endif //CONFIG_PLATFORM_8711B
98 
99 ///@name Ameba Common
100 ///@{
101 
102 /**
103   * @brief  To make the system entering the Clock Gated power saving.
104   *         This function just make the system to enter the clock gated
105   *         power saving mode and pending on wake up event waitting.
106   *         The user application need to configure the peripheral to
107   *         generate system wake up event, like GPIO interrupt,
108   *         G-Timer timeout, etc. befor entering power saving mode.
109   * @param  wakeup_event: A bit map of wake up event.
110   *   This parameter can be any combination of the following values:
111   *		 @arg SLEEP_WAKEUP_BY_STIMER
112   *		 @arg SLEEP_WAKEUP_BY_GTIMER
113   *		 @arg SLEEP_WAKEUP_BY_GPIO_INT
114   *		 @arg SLEEP_WAKEUP_BY_WLAN
115   *		 @arg SLEEP_WAKEUP_BY_SDIO
116   *		 @arg SLEEP_WAKEUP_BY_USB
117   *		 @arg SLEEP_WAKEUP_BY_GPIO
118   *		 @arg SLEEP_WAKEUP_BY_UART
119   *		 @arg SLEEP_WAKEUP_BY_I2C
120   *		 @arg SLEEP_WAKEUP_BY_RTC
121   *		 @arg SLEEP_WAKEUP_BY_RESETPIN
122   * @param  sleep_duration: the system sleep duration in ms, only valid
123   *         for SLEEP_WAKEUP_BY_STIMER wake up event.
124   * @retval None
125   */
126 void sleep_ex(uint32_t wakeup_event,  uint32_t sleep_duration);
127 
128 /**
129   * @brief  To make the system entering the Clock Gated power saving.
130   *         This function just make the system to enter the clock gated
131   *         power saving mode and pending on wake up event waitting.
132   *         The user application need to configure the peripheral to
133   *         generate system wake up event, like GPIO interrupt
134   *         , G-Timer timeout, etc. befor entering power saving mode.
135   * @param  wakeup_event: A bit map of wake up event.
136   *   This parameter can be any combination of the following values:
137   *		 @arg SLEEP_WAKEUP_BY_STIMER
138   *		 @arg SLEEP_WAKEUP_BY_GTIMER
139   *		 @arg SLEEP_WAKEUP_BY_GPIO_INT
140   *		 @arg SLEEP_WAKEUP_BY_WLAN
141   *		 @arg SLEEP_WAKEUP_BY_SDIO
142   *		 @arg SLEEP_WAKEUP_BY_USB
143   *		 @arg SLEEP_WAKEUP_BY_GPIO
144   *		 @arg SLEEP_WAKEUP_BY_UART
145   *		 @arg SLEEP_WAKEUP_BY_I2C
146   *		 @arg SLEEP_WAKEUP_BY_RTC
147   *		 @arg SLEEP_WAKEUP_BY_RESETPIN
148   * @param  sleep_duration: the system sleep duration in ms, only valid
149   *         for SLEEP_WAKEUP_BY_STIMER wake up event.
150   * @param  clk_sourec_enable: the option for SCLK on(1)/off(0)
151   * @param  sdr_enable: the option for turn off the SDR controller (1:off, 0:on)
152   * @retval None
153   */
154 void sleep_ex_selective(uint32_t wakeup_event,  uint32_t sleep_duration, uint32_t clk_sourec_enable, uint32_t sdr_enable);
155 
156 #if defined(CONFIG_PLATFORM_8195A) && (CONFIG_PLATFORM_8195A == 1)
157 ///@name Ameba1 Only
158 ///@{
159 /**
160   * @brief  To make the system entering the Deep Standby power saving.
161   *         The CPU, memory and part fo peripheral power is off when
162   *         entering deep standby power saving mode. The program needs
163   *         to be reload from the flash at system resume.
164   * @retval None
165   */
166 void deepstandby_ex(void);
167 ///@}
168 #endif //CONFIG_PLATFORM_8195A
169 
170 #if defined(CONFIG_PLATFORM_8711B) && (CONFIG_PLATFORM_8711B == 1)
171 ///@name AmebaZ Only
172 ///@{
173 /**
174   * @brief  To make the system entering the Deep Standby power saving.
175   *         The CPU, memory and part fo peripheral power is off when
176   *         entering deep standby power saving mode. The program needs
177   *         to be reload from the flash at system resume.
178   * @param  sleep_duration_ms: the system sleep duration in ms, only valid
179   *             for STANDBY_WAKEUP_BY_STIMER wake up event.
180   * @retval None
181   */
182 void deepstandby_ex(uint32_t sleep_duration_ms);
183 ///@}
184 #endif //CONFIG_PLATFORM_8711B
185 
186 /**
187   * @brief  To make the system entering the Deep Sleep power saving mode.
188   *         The CPU, memory and peripheral power is off when entering
189   *         deep sleep power saving mode. The program needs to be reload
190   *         and all peripheral needs be re-configure when system resume.
191   * @param  wakeup_event: A bit map of wake up event.
192   *   This parameter can be any combination of the following values:
193   *		 @arg DSLEEP_WAKEUP_BY_TIMER
194   *		 @arg DSLEEP_WAKEUP_BY_GPIO
195   * @param  sleep_duration: the system sleep duration in ms, only valid
196   *         for DSLEEP_WAKEUP_BY_TIMER wake up event.
197   * @retval None
198   */
199 void deepsleep_ex(uint32_t wakeup_event, uint32_t sleep_duration);
200 
201 #if defined(CONFIG_PLATFORM_8195A) && (CONFIG_PLATFORM_8195A == 1)
202 ///@name Ameba1 Only
203 ///@{
204 /**
205   * @brief  To add a wake up event to wake up the system from the
206   *         deep standby power saving mode.
207   * @param  wakeup_event: A bit map of wake up event.
208   *   This parameter can be any combination of the following values:
209   *		 @arg STANDBY_WAKEUP_BY_STIMER
210   *		 @arg STANDBY_WAKEUP_BY_GPIO
211   *		 @arg STANDBY_WAKEUP_BY_RTC
212   *		 @arg STANDBY_WAKEUP_BY_RESETPIN
213   * @param  sleep_duration_ms: the system sleep duration in ms, only valid
214   *             for STANDBY_WAKEUP_BY_STIMER wake up event.
215   * @param  gpio_option: for a GPIO pin to wake up the system by goes high or low
216   *   This parameter can be any combination of the following values:
217   *		 @arg WAKEUP_BY_GPIO_NONE
218   *		 @arg WAKEUP_BY_GPIO_WAKEUP0_LOW
219   *		 @arg WAKEUP_BY_GPIO_WAKEUP0_HIG
220   *		 @arg WAKEUP_BY_GPIO_WAKEUP1_LOW
221   *		 @arg WAKEUP_BY_GPIO_WAKEUP1_HIG
222   *		 @arg WAKEUP_BY_GPIO_WAKEUP2_LOW
223   *		 @arg WAKEUP_BY_GPIO_WAKEUP2_HIG
224   *		 @arg WAKEUP_BY_GPIO_WAKEUP3_LOW
225   *		 @arg WAKEUP_BY_GPIO_WAKEUP3_HIG
226   * @retval None
227   */
228 void standby_wakeup_event_add(uint32_t wakeup_event, uint32_t sleep_duration_ms, uint32_t gpio_active);
229 ///@}
230 #endif //CONFIG_PLATFORM_8195A
231 
232 #if defined(CONFIG_PLATFORM_8711B) && (CONFIG_PLATFORM_8711B == 1)
233 ///@name AmebaZ Only
234 ///@{
235 /**
236   * @brief  To add a wake up event to wake up the system from the
237   *         deep standby power saving mode.
238   * @param  wakeup_event: A bit map of wake up event.
239   *   This parameter can be any combination of the following values:
240   *		 @arg STANDBY_WAKEUP_BY_STIMER
241   *		 @arg STANDBY_WAKEUP_BY_GPIO
242   *		 @arg STANDBY_WAKEUP_BY_RTC
243   *		 @arg STANDBY_WAKEUP_BY_RESETPIN
244   * @param  gpio_option: for a GPIO pin to wake up the system by goes high or low
245   *   This parameter can be any combination of the following values:
246   *		 @arg WAKEUP_BY_GPIO_NONE
247   *		 @arg WAKEUP_BY_GPIO_WAKEUP0_LOW
248   *		 @arg WAKEUP_BY_GPIO_WAKEUP0_HIG
249   *		 @arg WAKEUP_BY_GPIO_WAKEUP1_LOW
250   *		 @arg WAKEUP_BY_GPIO_WAKEUP1_HIG
251   *		 @arg WAKEUP_BY_GPIO_WAKEUP2_LOW
252   *		 @arg WAKEUP_BY_GPIO_WAKEUP2_HIG
253   *		 @arg WAKEUP_BY_GPIO_WAKEUP3_LOW
254   *		 @arg WAKEUP_BY_GPIO_WAKEUP3_HIG
255   * @retval None
256   */
257 void standby_wakeup_event_add(uint32_t wakeup_event, uint32_t gpio_active);
258 ///@}
259 #endif //CONFIG_PLATFORM_8711B
260 
261 /**
262   * @brief  To delete a wake up event for wakeing up the system from the
263   *         deep standby power saving mode.
264   * @param  wakeup_event: A bit map of wake up event.
265   *   This parameter can be any combination of the following values:
266   *		 @arg STANDBY_WAKEUP_BY_STIMER
267   *		 @arg STANDBY_WAKEUP_BY_GPIO
268   *		 @arg STANDBY_WAKEUP_BY_RTC
269   *		 @arg STANDBY_WAKEUP_BY_RESETPIN
270   * @retval None
271   */
272 void standby_wakeup_event_del(uint32_t wakeup_event);
273 
274 ///@}
275 
276 
277 #ifdef __cplusplus
278 }
279 #endif
280 
281 //#endif
282 /*\@}*/
283 #endif
284