Contiki 3.x
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-conf.h"
39 #include "dev/rom-util.h"
40 #include "dev/sys-ctrl.h"
41 #include "reg.h"
42 #include "soc.h"
43 
44 #include <stdint.h>
45 #include <stdio.h>
46 /*----------------------------------------------------------------------------*/
47 #define DIECFG0 0x400d3014
48 #define DIECFG0_SRAM_SIZE_OFS 7
49 #define DIECFG0_SRAM_SIZE_SZ 3
50 #define DIECFG0_SRAM_SIZE_MSK (((1 << DIECFG0_SRAM_SIZE_SZ) - 1) << \
51  DIECFG0_SRAM_SIZE_OFS)
52 #define DIECFG2 0x400d301c
53 #define DIECFG2_DIE_REV_OFS 8
54 #define DIECFG2_DIE_REV_SZ 8
55 #define DIECFG2_DIE_REV_MSK (((1 << DIECFG2_DIE_REV_SZ) - 1) << \
56  DIECFG2_DIE_REV_OFS)
57 #define DIECFG2_AES_EN 0x00000002
58 #define DIECFG2_PKA_EN 0x00000001
59 /*----------------------------------------------------------------------------*/
60 uint8_t
62 {
63  uint8_t rev = (REG(DIECFG2) & DIECFG2_DIE_REV_MSK) >> DIECFG2_DIE_REV_OFS;
64 
65  /* PG1.0 is encoded as 0x00. */
66  if(!(rev >> 4))
67  rev += 0x10;
68  return rev;
69 }
70 /*----------------------------------------------------------------------------*/
71 uint32_t
73 {
74  uint32_t size_code = (REG(DIECFG0) & DIECFG0_SRAM_SIZE_MSK) >>
75  DIECFG0_SRAM_SIZE_OFS;
76 
77  return size_code <= 1 ? (2 - size_code) << 13 : 32 << 10;
78 }
79 /*----------------------------------------------------------------------------*/
80 uint32_t
82 {
83  return REG(DIECFG2) & (DIECFG2_AES_EN | DIECFG2_PKA_EN);
84 }
85 /*----------------------------------------------------------------------------*/
86 void
88 {
89  uint8_t rev = soc_get_rev();
90  uint32_t features = soc_get_features();
91 
92  printf("CC2538: ID: 0x%04lx, rev.: PG%d.%d, Flash: %lu KiB, SRAM: %lu KiB, "
93  "AES/SHA: %u, ECC/RSA: %u\n"
94  "System clock: %lu Hz\n"
95  "I/O clock: %lu Hz\n"
96  "Reset cause: %s\n",
97  rom_util_get_chip_id(),
98  rev >> 4, rev & 0x0f,
99  rom_util_get_flash_size() >> 10,
100  soc_get_sram_size() >> 10,
101  !!(features & SOC_FEATURE_AES_SHA),
102  !!(features & SOC_FEATURE_ECC_RSA),
106 }
107 
108 /** @} */
uint32_t soc_get_sram_size(void)
Gets the SRAM size of the SoC.
Definition: soc.c:72
Header file with register manipulation macro definitions.
#define SOC_FEATURE_AES_SHA
Security HW AES/SHA.
Definition: soc.h:53
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 soc_get_features(void)
Gets the hardware features of the SoC that are enabled.
Definition: soc.c:81
Header file for the cc2538 ROM utility function library driver.
uint32_t sys_ctrl_get_io_clock(void)
Returns the actual io clock in Hz.
Definition: sys-ctrl.c:127
Header file for the cc2538 System Control driver.
uint8_t soc_get_rev(void)
Gets the SoC revision.
Definition: soc.c:61
Header file with macro and function declarations for the cc2538 SoC.
uint32_t sys_ctrl_get_sys_clock(void)
Returns the actual system clock in Hz.
Definition: sys-ctrl.c:120
#define SOC_FEATURE_ECC_RSA
Security HW ECC/RSA.
Definition: soc.h:54
void soc_print_info(void)
Prints SoC information.
Definition: soc.c:87