aboutsummaryrefslogtreecommitdiff
path: root/lib/chibios-contrib/testhal/STM32/STM32F4xx/FSMC_NAND/dma_storm_uart.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chibios-contrib/testhal/STM32/STM32F4xx/FSMC_NAND/dma_storm_uart.c')
-rw-r--r--lib/chibios-contrib/testhal/STM32/STM32F4xx/FSMC_NAND/dma_storm_uart.c160
1 files changed, 160 insertions, 0 deletions
diff --git a/lib/chibios-contrib/testhal/STM32/STM32F4xx/FSMC_NAND/dma_storm_uart.c b/lib/chibios-contrib/testhal/STM32/STM32F4xx/FSMC_NAND/dma_storm_uart.c
new file mode 100644
index 000000000..7b8aa0273
--- /dev/null
+++ b/lib/chibios-contrib/testhal/STM32/STM32F4xx/FSMC_NAND/dma_storm_uart.c
@@ -0,0 +1,160 @@
1/*
2 ChibiOS/RT - Copyright (C) 2014 Uladzimir Pylinsky aka barthess
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17#include "ch.h"
18#include "hal.h"
19
20/*
21 ******************************************************************************
22 * DEFINES
23 ******************************************************************************
24 */
25#define UART_STORM_BAUDRATE 3000000
26#define STORM_BUF_LEN 256
27
28/*
29 ******************************************************************************
30 * EXTERNS
31 ******************************************************************************
32 */
33
34/*
35 ******************************************************************************
36 * PROTOTYPES
37 ******************************************************************************
38 */
39static void txend1(UARTDriver *uartp);
40static void txend2(UARTDriver *uartp);
41static void rxerr(UARTDriver *uartp, uartflags_t e);
42static void rxchar(UARTDriver *uartp, uint16_t c);
43static void rxend(UARTDriver *uartp);
44
45/*
46 ******************************************************************************
47 * GLOBAL VARIABLES
48 ******************************************************************************
49 */
50static uint8_t rxbuf[STORM_BUF_LEN];
51static uint8_t txbuf[STORM_BUF_LEN];
52
53/*
54 * UART driver configuration structure.
55 */
56static const UARTConfig uart_cfg = {
57 txend1,
58 txend2,
59 rxend,
60 rxchar,
61 rxerr,
62 UART_STORM_BAUDRATE,
63 0,
64 0,
65 0
66};
67
68static uint32_t ints;
69
70/*
71 ******************************************************************************
72 ******************************************************************************
73 * LOCAL FUNCTIONS
74 ******************************************************************************
75 ******************************************************************************
76 */
77/*
78 * This callback is invoked when a transmission buffer has been completely
79 * read by the driver.
80 */
81static void txend1(UARTDriver *uartp) {
82
83 ints++;
84 chSysLockFromISR();
85 uartStartSendI(uartp, STORM_BUF_LEN, txbuf);
86 chSysUnlockFromISR();
87}
88
89/*
90 * This callback is invoked when a transmission has physically completed.
91 */
92static void txend2(UARTDriver *uartp) {
93 (void)uartp;
94
95 chSysLockFromISR();
96 chSysUnlockFromISR();
97}
98
99/*
100 * This callback is invoked on a receive error, the errors mask is passed
101 * as parameter.
102 */
103static void rxerr(UARTDriver *uartp, uartflags_t e) {
104 (void)uartp;
105 (void)e;
106 osalSysHalt("");
107}
108
109/*
110 * This callback is invoked when a character is received but the application
111 * was not ready to receive it, the character is passed as parameter.
112 */
113static void rxchar(UARTDriver *uartp, uint16_t c) {
114 (void)uartp;
115 (void)c;
116}
117
118/*
119 * This callback is invoked when a receive buffer has been completely written.
120 */
121static void rxend(UARTDriver *uartp) {
122 (void)uartp;
123
124 chSysLockFromISR();
125 uartStartReceiveI(&UARTD6, STORM_BUF_LEN, rxbuf);
126 chSysUnlockFromISR();
127}
128
129/*
130 ******************************************************************************
131 * EXPORTED FUNCTIONS
132 ******************************************************************************
133 */
134
135/**
136 *
137 */
138void dma_storm_uart_start(void){
139
140 uint32_t i;
141
142 for (i=0; i<STORM_BUF_LEN; i++){
143 txbuf[i] = 0x55;
144 rxbuf[i] = 0;
145 }
146
147 ints = 0;
148 uartStart(&UARTD6, &uart_cfg);
149 uartStartReceive(&UARTD6, STORM_BUF_LEN, rxbuf);
150 uartStartSend(&UARTD6, STORM_BUF_LEN, txbuf);
151}
152
153uint32_t dma_storm_uart_stop(void){
154
155 uartStopSend(&UARTD6);
156 uartStopReceive(&UARTD6);
157 uartStop(&UARTD6);
158
159 return ints;
160}