1 /**
2 ****************************************************************************************
3 * @file app_systick.c
4 * @author BLE Driver Team
5 * @brief HAL APP module driver.
6 ****************************************************************************************
7 * @attention
8 #####Copyright (c) 2019 GOODIX
9 All rights reserved.
10
11 Redistribution and use in source and binary forms, with or without
12 modification, are permitted provided that the following conditions are met:
13 * Redistributions of source code must retain the above copyright
14 notice, this list of conditions and the following disclaimer.
15 * Redistributions in binary form must reproduce the above copyright
16 notice, this list of conditions and the following disclaimer in the
17 documentation and/or other materials provided with the distribution.
18 * Neither the name of GOODIX nor the names of its contributors may be used
19 to endorse or promote products derived from this software without
20 specific prior written permission.
21
22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
26 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 POSSIBILITY OF SUCH DAMAGE.
33 ****************************************************************************************
34 */
35
36 /*
37 * INCLUDE FILES
38 *****************************************************************************************
39 */
40 #include <stdbool.h>
41 #include "gr55xx_hal.h"
42 #include "app_pwr_mgmt.h"
43 #include "app_systick.h"
44
45 /*
46 * DEFINES
47 *****************************************************************************************
48 */
49 #define SYSTICK_USE_PATTERN 0x47
50
51 /*
52 * LOCAL FUNCTION DECLARATION
53 *****************************************************************************************
54 */
55 static bool systick_prepare_for_sleep(void);
56 static void systick_sleep_canceled(void);
57 static void systick_wake_up_ind(void);
58
59 /*
60 * LOCAL VARIABLE DEFINITIONS
61 *****************************************************************************************
62 */
63 static uint8_t s_systick_use_flag = 0;
64 static bool s_sleep_cb_registered_flag = false;
65
66 static const app_sleep_callbacks_t systick_sleep_cb = {
67 .app_prepare_for_sleep = systick_prepare_for_sleep,
68 .app_sleep_canceled = systick_sleep_canceled,
69 .app_wake_up_ind = systick_wake_up_ind
70 };
71
systick_prepare_for_sleep(void)72 static bool systick_prepare_for_sleep(void)
73 {
74 return true;
75 }
76
systick_sleep_canceled(void)77 static void systick_sleep_canceled(void)
78 {
79 }
80
81 /*
82 * LOCAL FUNCTION DEFINITIONS
83 *****************************************************************************************
84 */
systick_wake_up_ind(void)85 SECTION_RAM_CODE static void systick_wake_up_ind(void)
86 {
87 if (s_systick_use_flag != SYSTICK_USE_PATTERN) {
88 return;
89 }
90
91 hal_init();
92 }
93
94 /*
95 * GLOBAL FUNCTION DEFINITIONS
96 ****************************************************************************************
97 */
app_systick_init(void)98 void app_systick_init(void)
99 {
100 s_systick_use_flag = SYSTICK_USE_PATTERN;
101
102 if (s_sleep_cb_registered_flag == false) { // register sleep callback
103 if (!(SysTick->CTRL & SysTick_CTRL_ENABLE_Msk)) {
104 hal_init();
105 }
106 s_sleep_cb_registered_flag = true;
107 pwr_register_sleep_cb(&systick_sleep_cb, APP_DRIVER_SYSTICK_WAPEUP_PRIORITY);
108 }
109 }
110
app_systick_deinit(void)111 void app_systick_deinit(void)
112 {
113 }
114
115