code cleanup, fixed testhal
This commit is contained in:
parent
c7f7b70596
commit
022cad0452
|
@ -15,7 +15,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file NRF51/RNGv1/rng_lld.c
|
* @file NRF51/NRF518221/rng_lld.c
|
||||||
* @brief NRF51 RNG subsystem low level driver source.
|
* @brief NRF51 RNG subsystem low level driver source.
|
||||||
*
|
*
|
||||||
* @addtogroup RNG
|
* @addtogroup RNG
|
||||||
|
@ -70,6 +70,7 @@ RNGDriver RNGD1;
|
||||||
void rng_lld_init(void) {
|
void rng_lld_init(void) {
|
||||||
rngObjectInit(&RNGD1);
|
rngObjectInit(&RNGD1);
|
||||||
RNGD1.rng = NRF_RNG;
|
RNGD1.rng = NRF_RNG;
|
||||||
|
RNGD1.irq = RNG_IRQn;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -80,19 +81,29 @@ void rng_lld_init(void) {
|
||||||
* @notapi
|
* @notapi
|
||||||
*/
|
*/
|
||||||
void rng_lld_start(RNGDriver *rngp) {
|
void rng_lld_start(RNGDriver *rngp) {
|
||||||
|
NRF_RNG_Type *rng = rngp->rng;
|
||||||
|
|
||||||
|
/* If not specified, set default configuration */
|
||||||
if (rngp->config == NULL)
|
if (rngp->config == NULL)
|
||||||
rngp->config = &default_config;
|
rngp->config = &default_config;
|
||||||
|
|
||||||
rngp->rng->POWER = 1;
|
/* Power on peripheric */
|
||||||
|
rng->POWER = 1;
|
||||||
|
|
||||||
|
/* Configure digital error correction */
|
||||||
if (rngp->config->digital_error_correction)
|
if (rngp->config->digital_error_correction)
|
||||||
rngp->rng->CONFIG |= RNG_CONFIG_DERCEN_Msk;
|
rng->CONFIG |= RNG_CONFIG_DERCEN_Msk;
|
||||||
else
|
else
|
||||||
rngp->rng->CONFIG &= ~RNG_CONFIG_DERCEN_Msk;
|
rng->CONFIG &= ~RNG_CONFIG_DERCEN_Msk;
|
||||||
|
|
||||||
rngp->rng->EVENTS_VALRDY = 0;
|
/* Clear pending events */
|
||||||
rngp->rng->INTENSET = RNG_INTENSET_VALRDY_Msk;
|
rng->EVENTS_VALRDY = 0;
|
||||||
rngp->rng->TASKS_START = 1;
|
|
||||||
|
/* Set interrupt mask */
|
||||||
|
rng->INTENSET = RNG_INTENSET_VALRDY_Msk;
|
||||||
|
|
||||||
|
/* Start */
|
||||||
|
rng->TASKS_START = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -104,8 +115,11 @@ void rng_lld_start(RNGDriver *rngp) {
|
||||||
* @notapi
|
* @notapi
|
||||||
*/
|
*/
|
||||||
void rng_lld_stop(RNGDriver *rngp) {
|
void rng_lld_stop(RNGDriver *rngp) {
|
||||||
rngp->rng->TASKS_STOP = 1;
|
NRF_RNG_Type *rng = rngp->rng;
|
||||||
rngp->rng->POWER = 0;
|
|
||||||
|
/* Stop and power off peripheric */
|
||||||
|
rng->TASKS_STOP = 1;
|
||||||
|
rng->POWER = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -120,6 +134,7 @@ void rng_lld_stop(RNGDriver *rngp) {
|
||||||
*/
|
*/
|
||||||
msg_t rng_lld_write(RNGDriver *rngp, uint8_t *buf, size_t n,
|
msg_t rng_lld_write(RNGDriver *rngp, uint8_t *buf, size_t n,
|
||||||
systime_t timeout) {
|
systime_t timeout) {
|
||||||
|
NRF_RNG_Type *rng = rngp->rng;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
for (i = 0 ; i < n ; i++) {
|
for (i = 0 ; i < n ; i++) {
|
||||||
|
@ -127,7 +142,7 @@ msg_t rng_lld_write(RNGDriver *rngp, uint8_t *buf, size_t n,
|
||||||
* It take about 677µs to generate a new byte, not sure if
|
* It take about 677µs to generate a new byte, not sure if
|
||||||
* forcing a context switch will be a benefit
|
* forcing a context switch will be a benefit
|
||||||
*/
|
*/
|
||||||
while (NRF_RNG->EVENTS_VALRDY == 0) {
|
while (rng->EVENTS_VALRDY == 0) {
|
||||||
/* Sleep and wakeup on ARM event (interrupt) */
|
/* Sleep and wakeup on ARM event (interrupt) */
|
||||||
SCB->SCR |= SCB_SCR_SEVONPEND_Msk;
|
SCB->SCR |= SCB_SCR_SEVONPEND_Msk;
|
||||||
__SEV();
|
__SEV();
|
||||||
|
@ -136,13 +151,13 @@ msg_t rng_lld_write(RNGDriver *rngp, uint8_t *buf, size_t n,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Read byte */
|
/* Read byte */
|
||||||
buf[i] = (char)NRF_RNG->VALUE;
|
buf[i] = (char)rng->VALUE;
|
||||||
|
|
||||||
/* Mark as read */
|
/* Mark as read */
|
||||||
NRF_RNG->EVENTS_VALRDY = 0;
|
rng->EVENTS_VALRDY = 0;
|
||||||
|
|
||||||
/* Clear interrupt so we can wake up again */
|
/* Clear interrupt so we can wake up again */
|
||||||
nvicClearPending(RNG_IRQn);
|
nvicClearPending(rngp->irq);
|
||||||
}
|
}
|
||||||
return MSG_OK;
|
return MSG_OK;
|
||||||
}
|
}
|
||||||
|
|
|
@ -134,6 +134,10 @@ struct RNGDriver {
|
||||||
* @brief Pointer to the RNGx registers block.
|
* @brief Pointer to the RNGx registers block.
|
||||||
*/
|
*/
|
||||||
NRF_RNG_Type *rng;
|
NRF_RNG_Type *rng;
|
||||||
|
/**
|
||||||
|
* @brief IRQ number
|
||||||
|
*/
|
||||||
|
uint32_t irq;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
|
|
@ -81,13 +81,13 @@ endif
|
||||||
PROJECT = ch
|
PROJECT = ch
|
||||||
|
|
||||||
# Imported source files and paths
|
# Imported source files and paths
|
||||||
|
CHIBIOS = /home/sdalu/ChibiOS/ChibiOS
|
||||||
|
CHIBIOS_CONTRIB = /home/sdalu/ChibiOS/ChibiOS-Contrib
|
||||||
#CHIBIOS = ../../../../../ChibiOS-RT
|
#CHIBIOS = ../../../../../ChibiOS-RT
|
||||||
#CHIBIOS_CONTRIB = $(CHIBIOS)/../ChibiOS-Contrib
|
#CHIBIOS_CONTRIB = $(CHIBIOS)/../ChibiOS-Contrib
|
||||||
CHIBIOS = /home/sdalu/ChibiOS/ChibiOS_16.1.2
|
|
||||||
CHIBIOS_CONTRIB = /home/sdalu/ChibiOS/Z/ChibiOS-Contrib
|
|
||||||
|
|
||||||
# Startup files.
|
# Startup files.
|
||||||
include $(CHIBIOS_CONTRIB)/os/common/ports/ARMCMx/compilers/GCC/mk/startup_nrf51.mk
|
include $(CHIBIOS_CONTRIB)/os/common/startup/ARMCMx/compilers/GCC/mk/startup_nrf51.mk
|
||||||
# HAL-OSAL files (optional).
|
# HAL-OSAL files (optional).
|
||||||
include $(CHIBIOS)/os/hal/hal.mk
|
include $(CHIBIOS)/os/hal/hal.mk
|
||||||
include $(CHIBIOS_CONTRIB)/os/hal/hal.mk
|
include $(CHIBIOS_CONTRIB)/os/hal/hal.mk
|
||||||
|
@ -96,7 +96,10 @@ include $(CHIBIOS_CONTRIB)/os/hal/boards/NRF51-DK/board.mk
|
||||||
include $(CHIBIOS)/os/hal/osal/rt/osal.mk
|
include $(CHIBIOS)/os/hal/osal/rt/osal.mk
|
||||||
# RTOS files (optional).
|
# RTOS files (optional).
|
||||||
include $(CHIBIOS)/os/rt/rt.mk
|
include $(CHIBIOS)/os/rt/rt.mk
|
||||||
include $(CHIBIOS)/os/rt/ports/ARMCMx/compilers/GCC/mk/port_v6m.mk
|
include $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC/mk/port_v6m.mk
|
||||||
|
# Other files (optional).
|
||||||
|
include $(CHIBIOS)/test/rt/test.mk
|
||||||
|
include $(CHIBIOS)/os/various/shell/shell.mk
|
||||||
|
|
||||||
|
|
||||||
# Define linker script file here
|
# Define linker script file here
|
||||||
|
@ -112,7 +115,7 @@ CSRC = $(STARTUPSRC) \
|
||||||
$(PLATFORMSRC) \
|
$(PLATFORMSRC) \
|
||||||
$(BOARDSRC) \
|
$(BOARDSRC) \
|
||||||
$(TESTSRC) \
|
$(TESTSRC) \
|
||||||
$(CHIBIOS)/os/various/shell.c \
|
$(SHELLSRC) \
|
||||||
$(CHIBIOS)/os/hal/lib/streams/memstreams.c \
|
$(CHIBIOS)/os/hal/lib/streams/memstreams.c \
|
||||||
$(CHIBIOS)/os/hal/lib/streams/chprintf.c \
|
$(CHIBIOS)/os/hal/lib/streams/chprintf.c \
|
||||||
main.c
|
main.c
|
||||||
|
@ -142,10 +145,13 @@ TCSRC =
|
||||||
TCPPSRC =
|
TCPPSRC =
|
||||||
|
|
||||||
# List ASM source files here
|
# List ASM source files here
|
||||||
ASMSRC = $(STARTUPASM) $(PORTASM) $(OSALASM)
|
ASMSRC =
|
||||||
|
ASMXSRC = $(STARTUPASM) $(PORTASM) $(OSALASM)
|
||||||
|
|
||||||
INCDIR = $(STARTUPINC) $(KERNINC) $(PORTINC) $(OSALINC) \
|
INCDIR = $(CHIBIOS)/os/license \
|
||||||
|
$(STARTUPINC) $(KERNINC) $(PORTINC) $(OSALINC) \
|
||||||
$(HALINC) $(PLATFORMINC) $(BOARDINC) $(TESTINC) \
|
$(HALINC) $(PLATFORMINC) $(BOARDINC) $(TESTINC) \
|
||||||
|
$(SHELLINC) \
|
||||||
$(CHIBIOS)/os/hal/lib/streams $(CHIBIOS)/os/various
|
$(CHIBIOS)/os/hal/lib/streams $(CHIBIOS)/os/various
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -213,7 +219,7 @@ ULIBS =
|
||||||
# End of user defines
|
# End of user defines
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
RULESPATH = $(CHIBIOS)/os/common/ports/ARMCMx/compilers/GCC
|
RULESPATH = $(CHIBIOS)/os/common/startup/ARMCMx/compilers/GCC/
|
||||||
include $(RULESPATH)/rules.mk
|
include $(RULESPATH)/rules.mk
|
||||||
|
|
||||||
|
|
||||||
|
@ -223,8 +229,8 @@ JLINK_PRE_FLASH = w4 4001e504 1
|
||||||
JLINK_ERASE_ALL = w4 4001e504 2\nw4 4001e50c 1\nsleep 100
|
JLINK_ERASE_ALL = w4 4001e504 2\nw4 4001e50c 1\nsleep 100
|
||||||
|
|
||||||
|
|
||||||
include /home/sdalu/ChibiOS/W/ChibiOS-Contrib/os/various/jlink.mk
|
include $(CHIBIOS_CONTRIB)/os/various/jlink.mk
|
||||||
include /home/sdalu/ChibiOS/W/ChibiOS-Contrib/os/various/gdb.mk
|
include $(CHIBIOS_CONTRIB)/os/various/gdb.mk
|
||||||
|
|
||||||
flash: all jlink-flash
|
flash: all jlink-flash
|
||||||
debug: gdb-debug
|
debug: gdb-debug
|
||||||
|
|
|
@ -25,8 +25,10 @@
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _CHCONF_H_
|
#ifndef CHCONF_H
|
||||||
#define _CHCONF_H_
|
#define CHCONF_H
|
||||||
|
|
||||||
|
#define _CHIBIOS_RT_CONF_
|
||||||
|
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
/**
|
/**
|
||||||
|
@ -262,14 +264,6 @@
|
||||||
*/
|
*/
|
||||||
#define CH_CFG_USE_MAILBOXES TRUE
|
#define CH_CFG_USE_MAILBOXES TRUE
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief I/O Queues APIs.
|
|
||||||
* @details If enabled then the I/O queues APIs are included in the kernel.
|
|
||||||
*
|
|
||||||
* @note The default is @p TRUE.
|
|
||||||
*/
|
|
||||||
#define CH_CFG_USE_QUEUES TRUE
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Core Memory Manager APIs.
|
* @brief Core Memory Manager APIs.
|
||||||
* @details If enabled then the core memory manager APIs are included
|
* @details If enabled then the core memory manager APIs are included
|
||||||
|
@ -357,12 +351,18 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Debug option, trace buffer.
|
* @brief Debug option, trace buffer.
|
||||||
* @details If enabled then the context switch circular trace buffer is
|
* @details If enabled then the trace buffer is activated.
|
||||||
* activated.
|
|
||||||
*
|
*
|
||||||
* @note The default is @p FALSE.
|
* @note The default is @p CH_DBG_TRACE_MASK_DISABLED.
|
||||||
*/
|
*/
|
||||||
#define CH_DBG_ENABLE_TRACE TRUE
|
#define CH_DBG_TRACE_MASK CH_DBG_TRACE_MASK_ALL
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Trace buffer entries.
|
||||||
|
* @note The trace buffer is only allocated if @p CH_DBG_TRACE_MASK is
|
||||||
|
* different from @p CH_DBG_TRACE_MASK_DISABLED.
|
||||||
|
*/
|
||||||
|
#define CH_DBG_TRACE_BUFFER_SIZE 128
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Debug option, stack checks.
|
* @brief Debug option, stack checks.
|
||||||
|
@ -427,10 +427,6 @@
|
||||||
/**
|
/**
|
||||||
* @brief Threads finalization hook.
|
* @brief Threads finalization hook.
|
||||||
* @details User finalization code added to the @p chThdExit() API.
|
* @details User finalization code added to the @p chThdExit() API.
|
||||||
*
|
|
||||||
* @note It is inserted into lock zone.
|
|
||||||
* @note It is also invoked when the threads simply return in order to
|
|
||||||
* terminate.
|
|
||||||
*/
|
*/
|
||||||
#define CH_CFG_THREAD_EXIT_HOOK(tp) { \
|
#define CH_CFG_THREAD_EXIT_HOOK(tp) { \
|
||||||
/* Add threads finalization code here.*/ \
|
/* Add threads finalization code here.*/ \
|
||||||
|
@ -444,6 +440,20 @@
|
||||||
/* Context switch code here.*/ \
|
/* Context switch code here.*/ \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief ISR enter hook.
|
||||||
|
*/
|
||||||
|
#define CH_CFG_IRQ_PROLOGUE_HOOK() { \
|
||||||
|
/* IRQ prologue code here.*/ \
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief ISR exit hook.
|
||||||
|
*/
|
||||||
|
#define CH_CFG_IRQ_EPILOGUE_HOOK() { \
|
||||||
|
/* IRQ epilogue code here.*/ \
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Idle thread enter hook.
|
* @brief Idle thread enter hook.
|
||||||
* @note This hook is invoked within a critical zone, no OS functions
|
* @note This hook is invoked within a critical zone, no OS functions
|
||||||
|
@ -451,6 +461,7 @@
|
||||||
* @note This macro can be used to activate a power saving mode.
|
* @note This macro can be used to activate a power saving mode.
|
||||||
*/
|
*/
|
||||||
#define CH_CFG_IDLE_ENTER_HOOK() { \
|
#define CH_CFG_IDLE_ENTER_HOOK() { \
|
||||||
|
/* Idle-enter code here.*/ \
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -460,6 +471,7 @@
|
||||||
* @note This macro can be used to deactivate a power saving mode.
|
* @note This macro can be used to deactivate a power saving mode.
|
||||||
*/
|
*/
|
||||||
#define CH_CFG_IDLE_LEAVE_HOOK() { \
|
#define CH_CFG_IDLE_LEAVE_HOOK() { \
|
||||||
|
/* Idle-leave code here.*/ \
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -488,12 +500,21 @@
|
||||||
/* System halt code here.*/ \
|
/* System halt code here.*/ \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Trace hook.
|
||||||
|
* @details This hook is invoked each time a new record is written in the
|
||||||
|
* trace buffer.
|
||||||
|
*/
|
||||||
|
#define CH_CFG_TRACE_HOOK(tep) { \
|
||||||
|
/* Trace code here.*/ \
|
||||||
|
}
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
/* Port-specific settings (override port settings defaulted in chcore.h). */
|
/* Port-specific settings (override port settings defaulted in chcore.h). */
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
|
||||||
#endif /* _CHCONF_H_ */
|
#endif /* CHCONF_H */
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
|
@ -48,7 +48,7 @@ static void cmd_random(BaseSequentialStream *chp, int argc, char *argv[]) {
|
||||||
|
|
||||||
for (i = 0 ; i < size ; i++) {
|
for (i = 0 ; i < size ; i++) {
|
||||||
chprintf(chp, "%02x ", random_buffer[i]);
|
chprintf(chp, "%02x ", random_buffer[i]);
|
||||||
if (nl = (((i+1) % 20) == 0))
|
if ((nl = (((i+1) % 20)) == 0))
|
||||||
chprintf(chp, "\r\n");
|
chprintf(chp, "\r\n");
|
||||||
}
|
}
|
||||||
if (!nl)
|
if (!nl)
|
||||||
|
@ -60,7 +60,7 @@ static void cmd_random(BaseSequentialStream *chp, int argc, char *argv[]) {
|
||||||
/*
|
/*
|
||||||
* Shell
|
* Shell
|
||||||
*/
|
*/
|
||||||
#define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(2048)
|
static THD_WORKING_AREA(shell_wa, 1024);
|
||||||
|
|
||||||
static const ShellCommand commands[] = {
|
static const ShellCommand commands[] = {
|
||||||
{"random", cmd_random},
|
{"random", cmd_random},
|
||||||
|
@ -105,7 +105,8 @@ int main(void) {
|
||||||
* Shell manager initialization.
|
* Shell manager initialization.
|
||||||
*/
|
*/
|
||||||
shellInit();
|
shellInit();
|
||||||
shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO);
|
chThdCreateStatic(shell_wa, sizeof(shell_wa), NORMALPRIO,
|
||||||
|
shellThread, (void *)&shell_cfg1);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in New Issue