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