aboutsummaryrefslogtreecommitdiffstats
path: root/demos/NRF52/Classic/main.c
diff options
context:
space:
mode:
authorStephane D'Alu <sdalu@sdalu.com>2016-07-10 12:04:39 +0200
committerStephane D'Alu <sdalu@sdalu.com>2016-07-10 12:04:39 +0200
commit6423c3dabeba4e4ed9217d71873653bc8af9ae4e (patch)
treeb7b22ab995afbeda36cb7471f5e347c9097f5b17 /demos/NRF52/Classic/main.c
parent3db81f7f03844057a6d4150e2c66a81a772df16d (diff)
downloadChibiOS-Contrib-6423c3dabeba4e4ed9217d71873653bc8af9ae4e.tar.gz
ChibiOS-Contrib-6423c3dabeba4e4ed9217d71873653bc8af9ae4e.tar.bz2
ChibiOS-Contrib-6423c3dabeba4e4ed9217d71873653bc8af9ae4e.zip
moved rng to LLD directory.
removed rng power control (doesn't exist in nrf52, wasn't documented in nrf51) renamed peripheral to start at 0
Diffstat (limited to 'demos/NRF52/Classic/main.c')
-rw-r--r--demos/NRF52/Classic/main.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/demos/NRF52/Classic/main.c b/demos/NRF52/Classic/main.c
index c0a63b9..efa6591 100644
--- a/demos/NRF52/Classic/main.c
+++ b/demos/NRF52/Classic/main.c
@@ -9,9 +9,50 @@
#define LED_EXT 14
+
+
+/*
+ * Command Random
+ */
+#define RANDOM_BUFFER_SIZE 1024
+static uint8_t random_buffer[RANDOM_BUFFER_SIZE];
+
+static void cmd_random(BaseSequentialStream *chp, int argc, char *argv[]) {
+ uint16_t size = 16;
+ uint16_t i = 0;
+ uint8_t nl = 0;
+
+ if (argc > 0) {
+ size = atoi(argv[0]);
+ }
+
+ if (size > RANDOM_BUFFER_SIZE) {
+ chprintf(chp, "random: maximum size is %d.\r\n", RANDOM_BUFFER_SIZE);
+ return;
+ }
+
+ chprintf(chp, "Fetching %d random byte(s):\r\n", size);
+
+ rngStart(&RNGD1, NULL);
+ rngWrite(&RNGD1, random_buffer, size, TIME_INFINITE);
+ rngStop(&RNGD1);
+
+ for (i = 0 ; i < size ; i++) {
+ chprintf(chp, "%02x ", random_buffer[i]);
+ if ((nl = (((i+1) % 20)) == 0))
+ chprintf(chp, "\r\n");
+ }
+ if (!nl)
+ chprintf(chp, "\r\n");
+
+}
+
+
+
static THD_WORKING_AREA(shell_wa, 1024);
static const ShellCommand commands[] = {
+ {"random", cmd_random},
{NULL, NULL}
};