forked from nrfconnect/sdk-nrf
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.c
72 lines (55 loc) · 2.02 KB
/
main.c
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
/*
* Copyright (c) 2018 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
*/
#include <zephyr.h>
#include <stdio.h>
#include <uart.h>
#include <string.h>
#include <gpio.h>
#include <hal/nrf_regulators.h>
#include <hal/nrf_gpio.h>
#include <hal/nrf_power.h>
#include <lte_lc.h>
#include <bsd.h>
#define WAKEUP_PIN NRF_GPIO_PIN_MAP(0,31)
/**@brief Recoverable BSD library error. */
void bsd_recoverable_error_handler(uint32_t err)
{
printk("bsdlib recoverable error: %u\n", err);
}
/**@brief Irrecoverable BSD library error. */
void bsd_irrecoverable_error_handler(uint32_t err)
{
printk("bsdlib irrecoverable error: %u\n", err);
__ASSERT_NO_MSG(false);
}
void main(void)
{
printk("The AT host sample started\n");
u32_t rr = nrf_power_resetreas_get(NRF_POWER_NS)
printk("RR: 0x%08x", rr);
if(rr & POWER_RESETREAS_OFF_Msk)
{
//Clear all RESETREAS when waking up from System OFF sleep by GPIO.
nrf_power_resetreas_clear(NRF_POWER_NS, 0x70017);
}
printk("Configuring pin %d as sense input\n",WAKEUP_PIN);
// Due to errata 4, Always configure PIN_CNF[n].INPUT before PIN_CNF[n].SENSE.
nrf_gpio_cfg_input(WAKEUP_PIN,NRF_GPIO_PIN_PULLUP);
nrf_gpio_cfg_sense_set(WAKEUP_PIN,NRF_GPIO_PIN_SENSE_LOW);
// We readback the pin config, and print it.
uint32_t cnf = NRF_P0_NS->PIN_CNF[WAKEUP_PIN];
NRF_P0_NS->PIN_CNF[WAKEUP_PIN] = cnf | (GPIO_PIN_CNF_SENSE_Low << GPIO_PIN_CNF_SENSE_Pos);
printk("PIN_CNF register for pin %d is %d \n",WAKEUP_PIN,NRF_P0_NS->PIN_CNF[WAKEUP_PIN]);
printk("Going to System OFF\n");
// The LTE modem also needs to be stopped,
// by issuing a command through the modem API, before entering System OFF mode.
// Once the command is issued, one should wait for the modem to respond that it actually has stopped
// as there may be a delay until modem is disconnected from the network.
lte_lc_power_off();
bsd_shutdown(); // Method to gracefully shutdown the BSD library.
nrf_regulators_system_off(NRF_REGULATORS_NS);
printk("This should not be printed \n");
}