Contiki-NG
soc.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016, Benoît Thébaudeau <benoit.thebaudeau.dev@gmail.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-soc
33  * @{
34  *
35  * \file
36  * Implementation of the cc2538 SoC driver
37  */
38 #include "contiki.h"
39 #include "dev/rom-util.h"
40 #include "dev/sys-ctrl.h"
41 #include "dev/ioc.h"
42 #include "dev/nvic.h"
43 #include "dev/sys-ctrl.h"
44 #include "dev/gpio-hal.h"
45 #include "lpm.h"
46 #include "reg.h"
47 #include "soc.h"
48 
49 #include <stdint.h>
50 #include <stdio.h>
51 /*----------------------------------------------------------------------------*/
52 #define DIECFG0 0x400d3014
53 #define DIECFG0_SRAM_SIZE_OFS 7
54 #define DIECFG0_SRAM_SIZE_SZ 3
55 #define DIECFG0_SRAM_SIZE_MSK (((1 << DIECFG0_SRAM_SIZE_SZ) - 1) << \
56  DIECFG0_SRAM_SIZE_OFS)
57 #define DIECFG2 0x400d301c
58 #define DIECFG2_DIE_REV_OFS 8
59 #define DIECFG2_DIE_REV_SZ 8
60 #define DIECFG2_DIE_REV_MSK (((1 << DIECFG2_DIE_REV_SZ) - 1) << \
61  DIECFG2_DIE_REV_OFS)
62 #define DIECFG2_AES_EN 0x00000002
63 #define DIECFG2_PKA_EN 0x00000001
64 /*---------------------------------------------------------------------------*/
65 /* Log configuration */
66 #include "sys/log.h"
67 #define LOG_MODULE "CC2538 SoC"
68 #define LOG_LEVEL LOG_LEVEL_NONE
69 /*----------------------------------------------------------------------------*/
70 uint8_t
72 {
73  uint8_t rev = (REG(DIECFG2) & DIECFG2_DIE_REV_MSK) >> DIECFG2_DIE_REV_OFS;
74 
75  /* PG1.0 is encoded as 0x00. */
76  if(!(rev >> 4))
77  rev += 0x10;
78  return rev;
79 }
80 /*----------------------------------------------------------------------------*/
81 uint32_t
83 {
84  uint32_t size_code = (REG(DIECFG0) & DIECFG0_SRAM_SIZE_MSK) >>
85  DIECFG0_SRAM_SIZE_OFS;
86 
87  return size_code <= 1 ? (2 - size_code) << 13 : 32 << 10;
88 }
89 /*----------------------------------------------------------------------------*/
90 uint32_t
92 {
93  return REG(DIECFG2) & (DIECFG2_AES_EN | DIECFG2_PKA_EN);
94 }
95 /*----------------------------------------------------------------------------*/
96 void
98 {
99  uint8_t rev = soc_get_rev();
100  uint32_t features = soc_get_features();
101 
102  LOG_DBG("CC2538: ID: 0x%04lx, rev.: PG%d.%d, Flash: %lu KiB, "
103  "SRAM: %lu KiB, AES/SHA: %u, ECC/RSA: %u\n"
104  "System clock: %lu Hz\n"
105  "I/O clock: %lu Hz\n"
106  "Reset cause: %s\n",
107  rom_util_get_chip_id(),
108  rev >> 4, rev & 0x0f,
109  rom_util_get_flash_size() >> 10,
110  soc_get_sram_size() >> 10,
111  !!(features & SOC_FEATURE_AES_SHA),
112  !!(features & SOC_FEATURE_ECC_RSA),
116 }
117 /*----------------------------------------------------------------------------*/
118 void
120 {
121  nvic_init();
122  ioc_init();
123  sys_ctrl_init();
124  clock_init();
125  lpm_init();
126  rtimer_init();
127  gpio_hal_init();
128 }
129 /*----------------------------------------------------------------------------*/
130 /** @} */
Header file for the ARM Nested Vectored Interrupt Controller.
Header file for the cc2538 System Control driver.
const char * sys_ctrl_get_reset_cause_str(void)
Gets a string describing the cause of the last reset.
Definition: sys-ctrl.c:61
void nvic_init()
Initialises the NVIC driver.
Definition: nvic.c:44
void ioc_init()
Initialise the IOC driver.
Definition: ioc.c:47
uint32_t sys_ctrl_get_io_clock(void)
Returns the actual io clock in Hz.
Definition: sys-ctrl.c:127
Header file with declarations for the I/O Control module.
void soc_print_info(void)
Prints SoC information.
Definition: soc.c:97
uint8_t soc_get_rev(void)
Gets the SoC revision.
Definition: soc.c:71
Header file with register manipulation macro definitions.
void gpio_hal_init()
Initialise the GPIO HAL.
Definition: gpio-hal.c:95
#define SOC_FEATURE_ECC_RSA
Security HW ECC/RSA.
Definition: soc.h:54
void soc_init()
Common initialisation routine for all CC2538-based platforms.
Definition: soc.c:119
uint32_t sys_ctrl_get_sys_clock(void)
Returns the actual system clock in Hz.
Definition: sys-ctrl.c:120
uint32_t soc_get_features(void)
Gets the hardware features of the SoC that are enabled.
Definition: soc.c:91
Header file with macro and function declarations for the cc2538 SoC.
void sys_ctrl_init()
Initialises the System Control Driver.
Definition: sys-ctrl.c:74
uint32_t soc_get_sram_size(void)
Gets the SRAM size of the SoC.
Definition: soc.c:82
Header file for the cc2538 ROM utility function library driver.
void lpm_init()
Initialise the low-power mode management module.
Definition: lpm.c:557
Header file for the GPIO HAL.
Header file for the logging system
void rtimer_init(void)
Initialize the real-time scheduler.
Definition: rtimer.c:61
void clock_init(void)
Arch-specific implementation of clock_init for the cc2538.
Definition: clock.c:93
#define SOC_FEATURE_AES_SHA
Security HW AES/SHA.
Definition: soc.h:53
Header file with register, macro and function declarations for the cc2538 low power module...