Contiki-NG
board.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2014, Texas Instruments Incorporated - http://www.ti.com/
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the copyright holder nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28 * OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30/*---------------------------------------------------------------------------*/
31/**
32 * \addtogroup sensortag-cc26xx-peripherals
33 * @{
34 *
35 * \file
36 * Sensortag-specific board initialisation driver
37 */
38/*---------------------------------------------------------------------------*/
39#include "contiki.h"
40#include "lib/sensors.h"
41#include "buzzer.h"
42#include "lpm.h"
43#include "ti-lib.h"
44#include "board-peripherals.h"
45#include "board-i2c.h"
46
47#include <stdint.h>
48#include <string.h>
49#include <stdbool.h>
50/*---------------------------------------------------------------------------*/
51static void
52power_domains_on(void)
53{
54 /* Turn on the PERIPH PD */
55 ti_lib_prcm_power_domain_on(PRCM_DOMAIN_PERIPH);
56
57 /* Wait for domains to power on */
58 while((ti_lib_prcm_power_domain_status(PRCM_DOMAIN_PERIPH)
59 != PRCM_DOMAIN_POWER_ON));
60}
61/*---------------------------------------------------------------------------*/
62static void
63lpm_wakeup_handler(void)
64{
65 power_domains_on();
66}
67/*---------------------------------------------------------------------------*/
68static void
69shutdown_handler(uint8_t mode)
70{
71 if(mode == LPM_MODE_SHUTDOWN) {
73 SENSORS_DEACTIVATE(bmp_280_sensor);
74 SENSORS_DEACTIVATE(opt_3001_sensor);
75 SENSORS_DEACTIVATE(tmp_007_sensor);
76 SENSORS_DEACTIVATE(hdc_1000_sensor);
77 SENSORS_DEACTIVATE(mpu_9250_sensor);
78 ti_lib_gpio_clear_dio(BOARD_IOID_MPU_POWER);
79 }
80
81 /* In all cases, stop the I2C */
83}
84/*---------------------------------------------------------------------------*/
85/*
86 * Declare a data structure to register with LPM.
87 * We don't care about what power mode we'll drop to, we don't care about
88 * getting notified before deep sleep. All we need is to be notified when we
89 * wake up so we can turn power domains back on for I2C and SSI, and to make
90 * sure everything on the board is off before CM3 shutdown.
91 */
92LPM_MODULE(sensortag_module, NULL, shutdown_handler, lpm_wakeup_handler,
93 LPM_DOMAIN_NONE);
94/*---------------------------------------------------------------------------*/
95static void
96configure_unused_pins(void)
97{
98 /* DP[0..3] */
99 ti_lib_ioc_pin_type_gpio_input(BOARD_IOID_DP0);
100 ti_lib_ioc_io_port_pull_set(BOARD_IOID_DP0, IOC_IOPULL_DOWN);
101 ti_lib_ioc_pin_type_gpio_input(BOARD_IOID_DP1);
102 ti_lib_ioc_io_port_pull_set(BOARD_IOID_DP1, IOC_IOPULL_DOWN);
103 ti_lib_ioc_pin_type_gpio_input(BOARD_IOID_DP2);
104 ti_lib_ioc_io_port_pull_set(BOARD_IOID_DP2, IOC_IOPULL_DOWN);
105 ti_lib_ioc_pin_type_gpio_input(BOARD_IOID_DP3);
106 ti_lib_ioc_io_port_pull_set(BOARD_IOID_DP3, IOC_IOPULL_DOWN);
107
108 /* Devpack ID */
109 ti_lib_ioc_pin_type_gpio_input(BOARD_IOID_DEVPK_ID);
110 ti_lib_ioc_io_port_pull_set(BOARD_IOID_DEVPK_ID, IOC_IOPULL_UP);
111
112 /* Digital Microphone */
113 ti_lib_ioc_pin_type_gpio_output(BOARD_IOID_MIC_POWER);
114 ti_lib_gpio_clear_dio(BOARD_IOID_MIC_POWER);
115 ti_lib_ioc_io_drv_strength_set(BOARD_IOID_MIC_POWER, IOC_CURRENT_2MA,
116 IOC_STRENGTH_MIN);
117
118 ti_lib_ioc_pin_type_gpio_input(BOARD_IOID_AUDIO_DI);
119 ti_lib_ioc_io_port_pull_set(BOARD_IOID_AUDIO_DI, IOC_IOPULL_DOWN);
120 ti_lib_ioc_pin_type_gpio_input(BOARD_IOID_AUDIO_CLK);
121 ti_lib_ioc_io_port_pull_set(BOARD_IOID_AUDIO_CLK, IOC_IOPULL_DOWN);
122
123 /* UART over Devpack - TX only (ToDo: Map all UART pins to Debugger) */
124 ti_lib_ioc_pin_type_gpio_input(BOARD_IOID_DP5_UARTTX);
125 ti_lib_ioc_io_port_pull_set(BOARD_IOID_DP5_UARTTX, IOC_IOPULL_DOWN);
126}
127/*---------------------------------------------------------------------------*/
128void
130{
131 /* Disable global interrupts */
132 bool int_disabled = ti_lib_int_master_disable();
133
134 power_domains_on();
135
136 /* Enable GPIO peripheral */
137 ti_lib_prcm_peripheral_run_enable(PRCM_PERIPH_GPIO);
138
139 /* Apply settings and wait for them to take effect */
140 ti_lib_prcm_load_set();
141 while(!ti_lib_prcm_load_get());
142
143 /* I2C controller */
145
146 buzzer_init();
147
148 /* Make sure the external flash is in the lower power mode */
149 ext_flash_init(NULL);
150
151 lpm_register_module(&sensortag_module);
152
153 /* For unsupported peripherals, select a default pin configuration */
154 configure_unused_pins();
155
156 /* Re-enable interrupt if initially enabled. */
157 if(!int_disabled) {
158 ti_lib_int_master_enable();
159 }
160}
161/*---------------------------------------------------------------------------*/
162/** @} */
Header file for the Sensortag I2C Driver.
#define LPM_MODULE(n, m, s, w, l)
Declare a variable to be used in order to get notifications from LPM.
Definition: lpm.h:96
void lpm_register_module(lpm_registered_module_t *module)
Register a module for LPM notifications.
Definition: lpm.c:545
bool ext_flash_init(const spi_device_t *conf)
Initialise the external flash.
Definition: ext-flash.c:527
void board_init()
Board specific iniatialisation.
Definition: board.c:80
#define BOARD_IOID_MIC_POWER
Digital Microphone.
Definition: board.h:209
const struct sensors_sensor bmp_280_sensor
Exports a global symbol to be used by the sensor API.
void buzzer_stop()
Stop the buzzer.
Definition: buzzer.c:106
void buzzer_init()
Initialise the buzzer.
Definition: buzzer.c:52
void board_i2c_wakeup()
Enables the I2C peripheral with defaults.
Definition: board-i2c.c:83
void board_i2c_shutdown()
Stops the I2C peripheral and restores pins to s/w control.
Definition: board-i2c.c:114
Header file with macros which rename TI CC26xxware functions.