aboutsummaryrefslogtreecommitdiffstats
path: root/testhal/STM32/STM32F4xx/DMA_STORM/main.c
diff options
context:
space:
mode:
authorGiovanni Di Sirio <gdisirio@gmail.com>2015-04-13 12:01:48 +0000
committerGiovanni Di Sirio <gdisirio@gmail.com>2015-04-13 12:01:48 +0000
commit5e74f17084778dc526471d4839ebf564c3b18b5d (patch)
tree847994bf441e80da312a2e1267d5cec1e4bc5150 /testhal/STM32/STM32F4xx/DMA_STORM/main.c
parentaf35dcf4d9c6729900b52d6afc46ed647d96fe16 (diff)
downloadChibiOS-5e74f17084778dc526471d4839ebf564c3b18b5d.tar.gz
ChibiOS-5e74f17084778dc526471d4839ebf564c3b18b5d.tar.bz2
ChibiOS-5e74f17084778dc526471d4839ebf564c3b18b5d.zip
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@7887 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'testhal/STM32/STM32F4xx/DMA_STORM/main.c')
-rw-r--r--testhal/STM32/STM32F4xx/DMA_STORM/main.c43
1 files changed, 33 insertions, 10 deletions
diff --git a/testhal/STM32/STM32F4xx/DMA_STORM/main.c b/testhal/STM32/STM32F4xx/DMA_STORM/main.c
index d119613f9..7bfc7b2c0 100644
--- a/testhal/STM32/STM32F4xx/DMA_STORM/main.c
+++ b/testhal/STM32/STM32F4xx/DMA_STORM/main.c
@@ -19,9 +19,23 @@
#include "ch.h"
#include "hal.h"
+/**
+ * DMA operation timeout failure handler.
+ */
+static void tmo(void *p) {
+
+ chSysHalt((const char *)p);
+}
+
+/*--------------------------------------------------------------------------*/
+/* ADC related code. */
+/*--------------------------------------------------------------------------*/
+
#define ADC_GRP2_NUM_CHANNELS 8
#define ADC_GRP2_BUF_DEPTH 16
+static virtual_timer_t adcvt;
+
static adcsample_t samples2[ADC_GRP2_NUM_CHANNELS * ADC_GRP2_BUF_DEPTH];
static void adccallback(ADCDriver *adcp, adcsample_t *buffer, size_t n) {
@@ -29,6 +43,10 @@ static void adccallback(ADCDriver *adcp, adcsample_t *buffer, size_t n) {
(void)adcp;
(void)buffer;
(void)n;
+
+ chSysLockFromISR();
+ chVTSetI(&adcvt, MS2ST(10), tmo, (void *)"ADC timeout");
+ chSysUnlockFromISR();
}
static void adcerrorcallback(ADCDriver *adcp, adcerror_t err) {
@@ -60,6 +78,10 @@ static const ADCConversionGroup adcgrpcfg2 = {
ADC_SQR3_SQ2_N(ADC_CHANNEL_IN12) | ADC_SQR3_SQ1_N(ADC_CHANNEL_IN11)
};
+/*--------------------------------------------------------------------------*/
+/* SPI related code. */
+/*--------------------------------------------------------------------------*/
+
/*
* Maximum speed SPI configuration (21MHz, CPHA=0, CPOL=0, MSb first).
*/
@@ -70,12 +92,6 @@ static const SPIConfig hs_spicfg = {
0
};
-static void tmo(void *p) {
-
- (void)p;
- chSysHalt("timeout");
-}
-
/*
* SPI thread.
*/
@@ -89,6 +105,8 @@ static THD_FUNCTION(spi_thread, p) {
uint8_t txbuf[256];
uint8_t rxbuf[256];
+ chRegSetThreadName("SPI overlord");
+
chVTObjectInit(&vt);
/* Prepare transmit pattern.*/
@@ -99,7 +117,7 @@ static THD_FUNCTION(spi_thread, p) {
while (true) {
/* Starts a VT working as watchdog to catch a malfunction in the SPI
driver.*/
- chVTSet(&vt, MS2ST(10), tmo, NULL);
+ chVTSet(&vt, MS2ST(10), tmo, (void *)"SPI timeout");
spiExchange(spip, sizeof(txbuf), txbuf, rxbuf);
@@ -108,9 +126,13 @@ static THD_FUNCTION(spi_thread, p) {
}
}
+/*--------------------------------------------------------------------------*/
+/* Application code. */
+/*--------------------------------------------------------------------------*/
+
/*
* This is a periodic thread that does absolutely nothing except flashing
- * a LED.
+ * a LED. If the application fails then the LED stops flashing.
*/
static THD_WORKING_AREA(waThread1, 128);
static THD_FUNCTION(Thread1, arg) {
@@ -148,7 +170,8 @@ int main(void) {
adcStart(&ADCD1, NULL);
adcSTM32EnableTSVREFE();
- /* Starts an ADC continuous conversion.*/
+ /* Starts an ADC continuous conversion and its watchdog virtual timer.*/
+ chVTSet(&adcvt, MS2ST(10), tmo, (void *)"ADC timeout");
adcStartConversion(&ADCD1, &adcgrpcfg2, samples2, ADC_GRP2_BUF_DEPTH);
/* Activating SPI drivers.*/
@@ -180,7 +203,7 @@ int main(void) {
/* Starts a VT working as watchdog to catch a malfunction in the DMA
driver.*/
- chVTSet(&vt, MS2ST(10), tmo, NULL);
+ chVTSet(&vt, MS2ST(10), tmo, (void *)"copy timeout");
/* Copy pattern 1.*/
dmaStartMemCopy(STM32_DMA2_STREAM6,