-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.h
142 lines (112 loc) · 5.07 KB
/
app.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/***************************************************************************//**
* @file
* @brief Application interface provided to main().
*******************************************************************************
* # License
* <b>Copyright 2020 Silicon Laboratories Inc. www.silabs.com</b>
*******************************************************************************
*
* SPDX-License-Identifier: Zlib
*
* The licensor of this software is Silicon Laboratories Inc.
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*
* Date: 08-07-2021
* Author: Dave Sluiter
* Description: This code was created by the Silicon Labs application wizard
* and started as "Bluetooth - SoC Empty".
* It is to be used only for ECEN 5823 "IoT Embedded Firmware".
* The MSLA referenced above is in effect.
*
******************************************************************************/
#ifndef APP_H
#define APP_H
#include "em_common.h"
#include "app_assert.h" // got messages that sl_app_assert() is deprecated and should switch to all_assert()
#include "sl_bluetooth.h"
#include "gatt_db.h"
#include "sl_status.h" // for sl_status_print()
#include "src/ble_device_type.h"
#include "src/gpio.h"
#include "src/lcd.h"
#include "src/oscillators.h"
#include "src/timers.h"
#include "src/irq.h"
#include "src/i2c.h"
#include "src/scheduler.h"
#include "src/ble.h"
#include "src/queue.h"
// See: https://docs.silabs.com/gecko-platform/latest/service/power_manager/overview
#if defined(SL_CATALOG_POWER_MANAGER_PRESENT)
/*Macro Definition for Energy Mode Selection*/
//#define LOWEST_ENERGY_MODE (0)
//#define LOWEST_ENERGY_MODE (1)
#define LOWEST_ENERGY_MODE (2)
//#define LOWEST_ENERGY_MODE (3)
#define EM0 (0)
#define EM1 (1)
#define EM2 (2)
#define EM3 (3)
// Macro Definition for LED ON time period
#define LETIMER_ON_TIME_MS (175)
// Macro Definition for Total LED blink period
#define LETIMER_PERIOD_MS (3000)
// -----------------------------------------------------------------------------
// defines for power manager callbacks
// -----------------------------------------------------------------------------
// Return values for app_is_ok_to_sleep():
// Return false to keep sl_power_manager_sleep() from sleeping the MCU.
// Return true to allow system to sleep when you expect/want an IRQ to wake
// up the MCU from the call to sl_power_manager_sleep() in the main while (1)
// loop.
// Students: We'll need to modify this for A2 onward.
// Set APP_IS_OK_TO_SLEEP according to energy modes
#if(LOWEST_ENERGY_MODE==0)
#define APP_IS_OK_TO_SLEEP (false)
#else
#define APP_IS_OK_TO_SLEEP (true)
#endif
// Return values for app_sleep_on_isr_exit():
// SL_POWER_MANAGER_IGNORE; // The module did not trigger an ISR and it doesn't want to contribute to the decision
// SL_POWER_MANAGER_SLEEP; // The module was the one that caused the system wakeup and the system SHOULD go back to sleep
// SL_POWER_MANAGER_WAKEUP; // The module was the one that caused the system wakeup and the system MUST NOT go back to sleep
//
// Notes:
// SL_POWER_MANAGER_IGNORE, we see calls to app_process_action() on each IRQ. This is the
// expected "normal" behavior.
//
// SL_POWER_MANAGER_SLEEP, the function app_process_action()
// in the main while(1) loop will not be called! It would seem that sl_power_manager_sleep()
// does not return in this case.
//
// SL_POWER_MANAGER_WAKEUP, doesn't seem to allow ISRs to run. Main while loop is
// running continuously, flooding the VCOM port with printf text with LETIMER0 IRQs
// disabled somehow, LED0 is not flashing.
#define APP_SLEEP_ON_ISR_EXIT (SL_POWER_MANAGER_IGNORE)
//#define APP_SLEEP_ON_ISR_EXIT (SL_POWER_MANAGER_SLEEP)
//#define APP_SLEEP_ON_ISR_EXIT (SL_POWER_MANAGER_WAKEUP)
#endif // defined(SL_CATALOG_POWER_MANAGER_PRESENT)
/**************************************************************************//**
* Application Init.
*****************************************************************************/
void app_init(void);
/**************************************************************************//**
* Application Process Action.
*****************************************************************************/
void app_process_action(void);
#endif // APP_H