-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
arch/arm/src/nrf52: 1. added RNG device driver 2. added errdata to co…
…rrect temp which will be used by RNG module 3. use general task_trigger / event_clear inline api for all driver.
- Loading branch information
1 parent
04fe412
commit 1389d90
Showing
8 changed files
with
688 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/************************************************************************************ | ||
* arch/arm/src/nrf52/chip/nrf52_rng.h | ||
* | ||
* Copyright (C) 2019 Gregory Nutt. All rights reserved. | ||
* Author: Zhiqiang Li <levin.li@outlook.com> | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in | ||
* the documentation and/or other materials provided with the | ||
* distribution. | ||
* 3. Neither the name NuttX nor the names of its contributors may be | ||
* used to endorse or promote products derived from this software | ||
* without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS | ||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | ||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
************************************************************************************/ | ||
|
||
#ifndef __ARCH_ARM_SRC_NRF52_CHIP_NRF52_RNG_H | ||
#define __ARCH_ARM_SRC_NRF52_CHIP_NRF52_RNG_H | ||
|
||
/************************************************************************************ | ||
* Included Files | ||
************************************************************************************/ | ||
|
||
#include <nuttx/config.h> | ||
#include "chip/nrf52_memorymap.h" | ||
#include "chip.h" | ||
|
||
/************************************************************************************ | ||
* Pre-processor Definitions | ||
************************************************************************************/ | ||
|
||
/* Register Offsets *****************************************************************/ | ||
|
||
#define NRF52_RNG_T_START_OFFSET 0x000 /* RNG Task Start */ | ||
#define NRF52_RNG_T_STOP_OFFSET 0x004 /* RNG Task Stop */ | ||
#define NRF52_RNG_EVENT_RDY_OFFSET 0x100 /* RNG Eevent ValRDY */ | ||
#define NRF52_RNG_SHORT_OFFSET 0x200 /* RNG Short Register */ | ||
#define NRF52_RNG_INT_SET_OFFSET 0x304 /* RNG INT SET Register */ | ||
#define NRF52_RNG_INT_CLR_OFFSET 0x308 /* RNG INT CLR Register */ | ||
#define NRF52_RNG_CONFIG_OFFSET 0x504 /* RNG CONFIG Register */ | ||
#define NRF52_RNG_VALUE_OFFSET 0x508 /* RNG Value Register */ | ||
|
||
/* Register Addresses ***************************************************************/ | ||
|
||
#define NRF52_RNG_T_START (NRF52_RNG_BASE + NRF52_RNG_T_START_OFFSET) | ||
#define NRF52_RNG_T_STOP (NRF52_RNG_BASE + NRF52_RNG_T_STOP_OFFSET) | ||
#define NRF52_RNG_EVENT_RDY (NRF52_RNG_BASE + NRF52_RNG_EVENT_RDY_OFFSET) | ||
|
||
#define NRF52_RNG_SHORT (NRF52_RNG_BASE + NRF52_RNG_SHORT_OFFSET) | ||
#define NRF52_RNG_INT_SET (NRF52_RNG_BASE + NRF52_RNG_INT_SET_OFFSET) | ||
#define NRF52_RNG_INT_CLR (NRF52_RNG_BASE + NRF52_RNG_INT_CLR_OFFSET) | ||
|
||
#define NRF52_RNG_CONFIG (NRF52_RNG_BASE + NRF52_RNG_CONFIG_OFFSET) | ||
#define NRF52_RNG_VALUE (NRF52_RNG_BASE + NRF52_RNG_VALUE_OFFSET) | ||
|
||
/* Register Bitfield Definitions ****************************************************/ | ||
|
||
/* IntEnSet / IntEnClr Register Bit */ | ||
|
||
#define NRF52_RNG_INT_EVENT_RDY (1<<0) | ||
|
||
#endif /* __ARCH_ARM_SRC_NRF52_CHIP_STM32_RNG_H */ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/**************************************************************************** | ||
* arch/arm/src/nrf52/nrf52_utils.h | ||
* | ||
* Copyright (C) 2017 Gregory Nutt. All rights reserved. | ||
* Author: Zhiqiang Li <levin.li@outlook.com> | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in | ||
* the documentation and/or other materials provided with the | ||
* distribution. | ||
* 3. Neither the name NuttX nor the names of its contributors may be | ||
* used to endorse or promote products derived from this software | ||
* without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS | ||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | ||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
****************************************************************************/ | ||
|
||
#ifndef __ARCH_ARM_SRC_NRF52_CHIP_NRF52_UTILS_H | ||
#define __ARCH_ARM_SRC_NRF52_CHIP_NRF52_UTILS_H | ||
|
||
/**************************************************************************** | ||
* Included Files | ||
****************************************************************************/ | ||
|
||
#include <nuttx/config.h> | ||
|
||
/**************************************************************************** | ||
* Public Function Prototypes / Inline Functions | ||
****************************************************************************/ | ||
|
||
/**************************************************************************** | ||
* Name: nrf52_clrpend | ||
* | ||
* Description: | ||
* Clear a pending interrupt at the NVIC. This does not seem to be | ||
* required for most interrupts. | ||
* | ||
****************************************************************************/ | ||
|
||
void nrf52_clrpend(int irq); | ||
|
||
/**************************************************************************** | ||
* Name: nrf52832_errdata_init | ||
* | ||
* Description: | ||
* ErrData correction for 52832 | ||
* required for most interrupts. | ||
* | ||
****************************************************************************/ | ||
|
||
void nrf52832_errdata_init(void); | ||
|
||
/**************************************************************************** | ||
* Name: nrf52_task_trigger | ||
* | ||
* Description: | ||
* trigger the special task which is passed from task parameter | ||
* | ||
****************************************************************************/ | ||
|
||
static inline void nrf52_task_trigger(uint32_t task) | ||
{ | ||
putreg32(1, task); | ||
} | ||
|
||
/**************************************************************************** | ||
* Name: nrf52_event_clear | ||
* | ||
* Description: | ||
* clear the Event | ||
* | ||
****************************************************************************/ | ||
|
||
static inline void nrf52_event_clear(uint32_t event) | ||
{ | ||
putreg32(0, event); | ||
} | ||
|
||
/**************************************************************************** | ||
* Name: nrf52_interrupt_enable | ||
* | ||
* Description: | ||
* Enable the bitfield interrupt | ||
* | ||
****************************************************************************/ | ||
|
||
static inline void nrf52_interrupt_enable(uint32_t reg_intenset, | ||
uint32_t bitfield) | ||
{ | ||
putreg32(bitfield, reg_intenset); | ||
} | ||
|
||
/**************************************************************************** | ||
* Name: nrf52_interrupt_disable | ||
* | ||
* Description: | ||
* Disable the bitfield interrupt | ||
* | ||
****************************************************************************/ | ||
|
||
static inline void nrf52_interrupt_disable(uint32_t reg_intenclr, | ||
uint32_t bitfield) | ||
{ | ||
putreg32(bitfield, reg_intenclr); | ||
} | ||
|
||
#endif /* __ARCH_ARM_SRC_NRF52_CHIP_NRF52_UTILS_H */ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
/**************************************************************************** | ||
* arch/arm/src/nrf52/nrf52832_errdata.c | ||
* | ||
* Copyright (C) 2019 Gregory Nutt. All rights reserved. | ||
* Author: Levin Li <levin.li@outlook.com> | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in | ||
* the documentation and/or other materials provided with the | ||
* distribution. | ||
* 3. Neither the name NuttX nor the names of its contributors may be | ||
* used to endorse or promote products derived from this software | ||
* without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS | ||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | ||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
****************************************************************************/ | ||
|
||
/**************************************************************************** | ||
* Included Files | ||
****************************************************************************/ | ||
|
||
#include <stdint.h> | ||
#include <stdbool.h> | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include <debug.h> | ||
#include <errno.h> | ||
#include <fcntl.h> | ||
#include <nuttx/fs/fs.h> | ||
#include <nuttx/irq.h> | ||
#include <nuttx/arch.h> | ||
#include <nuttx/semaphore.h> | ||
#include <nuttx/fs/ioctl.h> | ||
#include <nuttx/drivers/drivers.h> | ||
|
||
#include "up_arch.h" | ||
#include "chip.h" | ||
#include "chip/nrf52_utils.h" | ||
#include "chip/nrf52_rng.h" | ||
#include "up_internal.h" | ||
|
||
/**************************************************************************** | ||
* Private Functions | ||
****************************************************************************/ | ||
|
||
static bool errata_16(void) | ||
{ | ||
if (((getreg32(0xf0000fe0) & 0xff) == 0x6) && | ||
((getreg32(0xf0000fe4) & 0x0f) == 0x0)) | ||
{ | ||
if ((getreg32(0xf0000fe8) & 0xf0) == 0x30) | ||
{ | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
static bool errata_66(void) | ||
{ | ||
/* This piece of code is modifed from Nordic SDK , there is no document to | ||
* describe how to get the errdata information | ||
*/ | ||
|
||
if (((getreg32(0xf0000fe0) & 0xff) == 0x6) && | ||
((getreg32(0xf0000fe4) & 0x0f) == 0x0)) | ||
{ | ||
if ((getreg32(0xf0000fe8) & 0xf0) == 0x50) | ||
{ | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
static void nrf52832_errdata_16(void) | ||
{ | ||
if (errata_16()) | ||
{ | ||
*(volatile uint32_t *)0x4007c074 = 3131961357ul; | ||
} | ||
} | ||
|
||
static void nrf52832_errdata_66_temp(void) | ||
{ | ||
/* Workaround for Errata 66 "TEMP: Linearity specification not met with | ||
* default settings found at the Errata document for your device located | ||
* at https://infocenter.nordicsemi.com/ | ||
*/ | ||
|
||
if (errata_66()) | ||
{ | ||
uint32_t temp_offset = 0x520; | ||
uint32_t temp_ficr_offset = 0x404; | ||
|
||
/* slot A : 6 totals */ | ||
|
||
for (int i = 0; i < 6; i++) | ||
{ | ||
putreg32(getreg32(NRF52_FICR_BASE + temp_ficr_offset + i * 4), | ||
NRF52_TEMP_BASE + temp_offset + i * 4); | ||
} | ||
|
||
/* Slot B : 6 totals */ | ||
|
||
temp_offset = 0x540; | ||
temp_ficr_offset = 0x41c; | ||
for (int i = 0 ; i < 6; i++) | ||
{ | ||
putreg32(getreg32(NRF52_FICR_BASE + temp_ficr_offset + i * 4), | ||
NRF52_TEMP_BASE + temp_offset + i * 4); | ||
} | ||
|
||
/* slot C : 5 totals */ | ||
|
||
temp_offset = 0x560; | ||
temp_ficr_offset = 0x434; | ||
for (int i = 0; i < 5; i++) | ||
{ | ||
putreg32(getreg32(NRF52_FICR_BASE + temp_ficr_offset + i * 4), | ||
NRF52_TEMP_BASE + temp_offset + i * 4); | ||
} | ||
} | ||
} | ||
|
||
/**************************************************************************** | ||
* Public Functions | ||
****************************************************************************/ | ||
|
||
void nrf52832_errdata_init(void) | ||
{ | ||
nrf52832_errdata_16(); | ||
|
||
nrf52832_errdata_66_temp(); | ||
} |
Oops, something went wrong.