Contiki 3.x
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-conf.h"
40 #include "lib/sensors.h"
41 #include "lpm.h"
42 #include "ti-lib.h"
43 #include "board-peripherals.h"
44 
45 #include <stdint.h>
46 #include <string.h>
47 #include <stdbool.h>
48 /*---------------------------------------------------------------------------*/
49 static void
50 wakeup_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  */
64 LPM_MODULE(launchpad_module, NULL, NULL, wakeup_handler, LPM_DOMAIN_NONE);
65 /*---------------------------------------------------------------------------*/
66 static void
67 configure_unused_pins(void)
68 {
69  uint32_t pins[] = {
70  BOARD_IOID_CS, BOARD_IOID_TDO, BOARD_IOID_TDI, BOARD_IOID_DIO12,
71  BOARD_IOID_DIO15, BOARD_IOID_DIO21, BOARD_IOID_DIO22, BOARD_IOID_DIO23,
72  BOARD_IOID_DIO24, BOARD_IOID_DIO25, BOARD_IOID_DIO26, BOARD_IOID_DIO27,
73  BOARD_IOID_DIO28, BOARD_IOID_DIO29, BOARD_IOID_DIO30,
74  IOID_UNUSED
75  };
76 
77  uint32_t *pin;
78 
79  for(pin = pins; *pin != IOID_UNUSED; pin++) {
80  ti_lib_ioc_pin_type_gpio_input(*pin);
81  ti_lib_ioc_io_port_pull_set(*pin, IOC_IOPULL_DOWN);
82  }
83 }
84 /*---------------------------------------------------------------------------*/
85 void
87 {
88  /* Disable global interrupts */
89  bool int_disabled = ti_lib_int_master_disable();
90 
91  /* Turn on relevant PDs */
92  wakeup_handler();
93 
94  /* Enable GPIO peripheral */
95  ti_lib_prcm_peripheral_run_enable(PRCM_PERIPH_GPIO);
96 
97  /* Apply settings and wait for them to take effect */
98  ti_lib_prcm_load_set();
99  while(!ti_lib_prcm_load_get());
100 
101  /* Make sure the external flash is in the lower power mode */
102  ext_flash_init();
103 
104  lpm_register_module(&launchpad_module);
105 
106  /* For unsupported peripherals, select a default pin configuration */
107  configure_unused_pins();
108 
109  /* Re-enable interrupt if initially enabled. */
110  if(!int_disabled) {
111  ti_lib_int_master_enable();
112  }
113 }
114 /*---------------------------------------------------------------------------*/
115 /** @} */
Header file with macros which rename TI CC26xxware functions.
void lpm_register_module(lpm_registered_module_t *module)
Register a module for LPM notifications.
Definition: lpm.c:498
#define BOARD_IOID_CS
Remaining pins.
Definition: board.h:159
#define LPM_MODULE(n, m, s, w, l)
Declare a variable to be used in order to get notifications from LPM.
Definition: lpm.h:92
void ext_flash_init()
Initialise the external flash.
Definition: ext-flash.c:449
void board_init()
Board specific iniatialisation.
Definition: board.c:54
#define NULL
The null pointer.