Contiki-NG
Loading...
Searching...
No Matches
board.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015, 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 launchpad-peripherals
33 * @{
34 *
35 * \file
36 * LaunchPad-specific board initialisation driver
37 */
38/*---------------------------------------------------------------------------*/
39#include "contiki.h"
40#include "lpm.h"
41#include "ti-lib.h"
42#include "board-peripherals.h"
43#include "rf-core/rf-switch.h"
44
45#include <stdint.h>
46#include <string.h>
47#include <stdbool.h>
48/*---------------------------------------------------------------------------*/
49static void
50wakeup_handler(void)
51{
52 /* Turn on the PERIPH PD */
53 ti_lib_prcm_power_domain_on(PRCM_DOMAIN_PERIPH);
54 while(ti_lib_prcm_power_domain_status(PRCM_DOMAIN_PERIPH)
55 != PRCM_DOMAIN_POWER_ON);
56}
57/*---------------------------------------------------------------------------*/
58/*
59 * Declare a data structure to register with LPM.
60 * We don't care about what power mode we'll drop to, we don't care about
61 * getting notified before deep sleep. All we need is to be notified when we
62 * wake up so we can turn power domains back on
63 */
64LPM_MODULE(launchpad_module, NULL, NULL, wakeup_handler, LPM_DOMAIN_NONE);
65/*---------------------------------------------------------------------------*/
66static void
67configure_unused_pins(void)
68{
69 uint32_t pins[] = BOARD_UNUSED_PINS;
70
71 uint32_t *pin;
72
73 for(pin = pins; *pin != IOID_UNUSED; pin++) {
74 ti_lib_ioc_pin_type_gpio_input(*pin);
75 ti_lib_ioc_io_port_pull_set(*pin, IOC_IOPULL_DOWN);
76 }
77}
78/*---------------------------------------------------------------------------*/
79void
81{
82 /* Disable global interrupts */
83 bool int_disabled = ti_lib_int_master_disable();
84
85 /* Turn on relevant PDs */
86 wakeup_handler();
87
88 /* Enable GPIO peripheral */
89 ti_lib_prcm_peripheral_run_enable(PRCM_PERIPH_GPIO);
90
91 /* Apply settings and wait for them to take effect */
92 ti_lib_prcm_load_set();
93 while(!ti_lib_prcm_load_get());
94
95 /* Make sure the external flash is in the lower power mode */
96 ext_flash_init(NULL);
97
98 lpm_register_module(&launchpad_module);
99
100 /* For unsupported peripherals, select a default pin configuration */
101 configure_unused_pins();
102
103 /* Initialise the RF switch if present */
104 rf_switch_init();
105
106 /* Re-enable interrupt if initially enabled. */
107 if(!int_disabled) {
108 ti_lib_int_master_enable();
109 }
110}
111/*---------------------------------------------------------------------------*/
112/** @} */
Header file with definitions related to LaunchPad peripherals.
#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
Header file with definitions related to RF switch support.
Header file with macros which rename TI CC26xxware functions.