UART2 <--> UART6 data rate: print stats on uart1

- byte/sec (IN/OUT)
- total bytes (IN/OUT)
master
gnssuser 3 weeks ago
parent 172ed5e2be
commit 5778a37513

@ -22,6 +22,7 @@
/* Private includes ----------------------------------------------------------*/ /* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */ /* USER CODE BEGIN Includes */
#include "printf.h" #include "printf.h"
#include <stm32f4xx_it.h>
#include <usart2_it.h> #include <usart2_it.h>
#include <usart6_it.h> #include <usart6_it.h>
#include "usart1_it.h" #include "usart1_it.h"
@ -135,24 +136,67 @@ int main(void) {
/* USER CODE BEGIN WHILE */ /* USER CODE BEGIN WHILE */
while (1) { while (1) {
static uint32_t Tick10msRef = 0; static uint32_t Tick10msRef = 0;
/* per-second and total byte counters */
static uint32_t bytes_2to6 = 0;
static uint32_t bytes_6to2 = 0;
static uint32_t total_2to6 = 0;
static uint32_t total_6to2 = 0;
if (TickChk(&Tick10msRef, 10)) { if (TickChk(&Tick10msRef, 10)) {
} }
static uint32_t Tick1secRef = 0; static uint32_t Tick1secRef = 0;
if (TickChk(&Tick1secRef, 1000)) { if (TickChk(&Tick1secRef, 1000)) {
LED2_Toggle(); LED2_Toggle();
/* print per-second data rates and cumulative totals */
printf("OUT:%5u IN:%5u B/s (Total:%u/%u)\n", (unsigned) bytes_2to6, (unsigned) bytes_6to2, (unsigned) total_2to6, (unsigned) total_6to2);
/* reset per-second counters */
bytes_2to6 = 0;
bytes_6to2 = 0;
} }
int c; int c;
c = Usart1_GetByte();
if (c != -1) { // new incoming data
/*
switch (c) {
case '1':
printf("Send 800 bytes to UART1\n");
for (int i = 0; i < 800; i++) {
Usart1_PutByte((i % 10) + '0');
}
break;
case '2':
printf("Send 800 bytes to UART2\n");
for (int i = 0; i < 800; i++) {
Usart2_PutByte((i % 20) + 'A');
}
break;
case '6':
printf("Send 800 bytes to UART6\n");
for (int i = 0; i < 800; i++) {
Usart6_PutByte((i % 20) + 'a');
}
break;
default: // echo back
Usart1_PutByte(c);
break;
}
*/
}
c = Usart2_GetByte(); c = Usart2_GetByte();
if (c != -1) {// new incoming data if (c != -1) { // new incoming data
Usart6_PutByte(c);// UART2rx --> UART6tx Usart6_PutByte(c); // UART2rx --> UART6tx
bytes_2to6++;
total_2to6++;
} }
c = Usart6_GetByte(); c = Usart6_GetByte();
if (c != -1) {// new incoming data if (c != -1) { // new incoming data
Usart2_PutByte(c);// UART6rx --> UART2tx Usart2_PutByte(c); // UART6rx --> UART2tx
bytes_6to2++;
total_6to2++;
} }
/* USER CODE END WHILE */ /* USER CODE END WHILE */

Loading…
Cancel
Save