Contiki 3.x
sys-ctrl.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012, 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  *
14  * 3. Neither the name of the copyright holder nor the names of its
15  * contributors may be used to endorse or promote products derived
16  * from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
29  * OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 /**
32  * \addtogroup cc2538-sys-ctrl
33  * @{
34  *
35  * \file
36  * Implementation of the cc2538 System Control driver
37  */
38 #include "contiki.h"
39 #include "reg.h"
40 #include "cpu.h"
41 #include "dev/sys-ctrl.h"
42 #include "dev/gpio.h"
43 #include "dev/ioc.h"
44 
45 #include <stdint.h>
46 
47 #if SYS_CTRL_OSC32K_USE_XTAL
48 #define SYS_CTRL_OSCS 0
49 #else
50 #define SYS_CTRL_OSCS SYS_CTRL_CLOCK_CTRL_OSC32K
51 #endif
52 /*---------------------------------------------------------------------------*/
53 void
55 {
56  uint32_t val;
57 
58 #if SYS_CTRL_OSC32K_USE_XTAL
59  /* Set the XOSC32K_Q pads to analog for crystal */
66 #endif
67 
68  /*
69  * Desired Clock Ctrl configuration:
70  * 32KHz source: RC or crystal, according to SYS_CTRL_OSC32K_USE_XTAL
71  * System Clock: 32 MHz
72  * Power Down Unused
73  * I/O Div: 16MHz
74  * Sys Div: 16MHz
75  * Rest: Don't care
76  */
77 
78  val = SYS_CTRL_OSCS | SYS_CTRL_CLOCK_CTRL_OSC_PD
79  | SYS_CTRL_CLOCK_CTRL_IO_DIV_16MHZ | SYS_CTRL_CLOCK_CTRL_SYS_DIV_16MHZ;
80  REG(SYS_CTRL_CLOCK_CTRL) = val;
81 
82  while((REG(SYS_CTRL_CLOCK_STA) & (SYS_CTRL_CLOCK_STA_OSC32K |
83  SYS_CTRL_CLOCK_STA_OSC)) != SYS_CTRL_OSCS);
84 
85 #if SYS_CTRL_OSC32K_USE_XTAL
86  /* Wait for the 32-kHz crystal oscillator to stabilize */
87  while(REG(SYS_CTRL_CLOCK_STA) & SYS_CTRL_CLOCK_STA_SYNC_32K);
88  while(!(REG(SYS_CTRL_CLOCK_STA) & SYS_CTRL_CLOCK_STA_SYNC_32K));
89 #endif
90 }
91 /*---------------------------------------------------------------------------*/
92 void
94 {
95  REG(SYS_CTRL_PWRDBG) = SYS_CTRL_PWRDBG_FORCE_WARM_RESET;
96 }
97 
98 /**
99  * @}
100  * @}
101  */
#define GPIO_PORT_TO_BASE(PORT)
Converts a port number to the port base address.
Definition: gpio.h:276
void sys_ctrl_reset()
Generates a warm reset through the SYS_CTRL_PWRDBG register.
Definition: sys-ctrl.c:93
#define IOC_OVERRIDE_ANA
Analog Enable.
Definition: ioc.h:225
#define GPIO_D_NUM
GPIO_D: 3.
Definition: gpio.h:82
#define SYS_CTRL_CLOCK_STA
Clock status register.
Definition: sys-ctrl.h:64
Header file with register and macro declarations for the cc2538 GPIO module.
void ioc_set_over(uint8_t port, uint8_t pin, uint8_t over)
Set Port:Pin override function.
Definition: ioc.c:54
#define GPIO_SET_INPUT(PORT_BASE, PIN_MASK)
Set pins with PIN_MASK of port with PORT_BASE to input.
Definition: gpio.h:93
Header file with declarations for the I/O Control module.
Header file with prototypes for interrupt control on the cc2538 Cortex-M3 micro.
#define SYS_CTRL_PWRDBG
Power debug register.
Definition: sys-ctrl.h:87
Header file with register manipulation macro definitions.
#define SYS_CTRL_CLOCK_CTRL
Clock control register.
Definition: sys-ctrl.h:63
Header file for the cc2538 System Control driver.
#define GPIO_SOFTWARE_CONTROL(PORT_BASE, PIN_MASK)
Configure the pin to be software controlled with PIN_MASK of port with PORT_BASE. ...
Definition: gpio.h:214
void sys_ctrl_init()
Initialises the System Control Driver.
Definition: sys-ctrl.c:54
#define GPIO_PIN_MASK(PIN)
Converts a pin number to a pin mask.
Definition: gpio.h:268