![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
SmartMesh QSL for STM32F4 version
Fork of COG-AD4050_QSL by
dn_uart.cpp@1:b909b8399252, 2018-07-12 (annotated)
- Committer:
- APS_Lab
- Date:
- Thu Jul 12 09:19:12 2018 +0000
- Revision:
- 1:b909b8399252
- Parent:
- 0:8ca1e814a851
SmartMesh for STM32F4 version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
APS_Lab | 0:8ca1e814a851 | 1 | /* |
APS_Lab | 0:8ca1e814a851 | 2 | Copyright (c) 2016, Dust Networks. All rights reserved. |
APS_Lab | 0:8ca1e814a851 | 3 | |
APS_Lab | 0:8ca1e814a851 | 4 | Port of the uart module to the NUCLEO-L053R8. |
APS_Lab | 0:8ca1e814a851 | 5 | |
APS_Lab | 0:8ca1e814a851 | 6 | \license See attached DN_LICENSE.txt. |
APS_Lab | 0:8ca1e814a851 | 7 | */ |
APS_Lab | 0:8ca1e814a851 | 8 | |
APS_Lab | 0:8ca1e814a851 | 9 | #include "dn_uart.h" |
APS_Lab | 0:8ca1e814a851 | 10 | #include "dn_ipmt.h" |
APS_Lab | 0:8ca1e814a851 | 11 | #include "dn_debug.h" |
APS_Lab | 0:8ca1e814a851 | 12 | #include "mbed.h" |
APS_Lab | 0:8ca1e814a851 | 13 | |
APS_Lab | 0:8ca1e814a851 | 14 | |
APS_Lab | 0:8ca1e814a851 | 15 | //=========================== defines ========================================= |
APS_Lab | 0:8ca1e814a851 | 16 | |
APS_Lab | 1:b909b8399252 | 17 | // Set correct pins for external UART on your board (USART1 for NUCLEO-F411) |
APS_Lab | 1:b909b8399252 | 18 | #define UART_MOTE_TX PA_9 |
APS_Lab | 1:b909b8399252 | 19 | #define UART_MOTE_RX PA_10 |
APS_Lab | 0:8ca1e814a851 | 20 | |
APS_Lab | 0:8ca1e814a851 | 21 | |
APS_Lab | 0:8ca1e814a851 | 22 | //=========================== variables ======================================= |
APS_Lab | 0:8ca1e814a851 | 23 | |
APS_Lab | 0:8ca1e814a851 | 24 | typedef struct { |
APS_Lab | 0:8ca1e814a851 | 25 | dn_uart_rxByte_cbt ipmt_uart_rxByte_cb; |
APS_Lab | 0:8ca1e814a851 | 26 | } dn_uart_vars_t; |
APS_Lab | 0:8ca1e814a851 | 27 | |
APS_Lab | 0:8ca1e814a851 | 28 | static dn_uart_vars_t dn_uart_vars; |
APS_Lab | 0:8ca1e814a851 | 29 | static Serial serialMote(UART_MOTE_TX, UART_MOTE_RX); |
APS_Lab | 0:8ca1e814a851 | 30 | |
APS_Lab | 0:8ca1e814a851 | 31 | |
APS_Lab | 0:8ca1e814a851 | 32 | //=========================== prototypes ====================================== |
APS_Lab | 0:8ca1e814a851 | 33 | |
APS_Lab | 0:8ca1e814a851 | 34 | void moteRXinterrupt(void); |
APS_Lab | 0:8ca1e814a851 | 35 | |
APS_Lab | 0:8ca1e814a851 | 36 | //=========================== public ========================================== |
APS_Lab | 0:8ca1e814a851 | 37 | |
APS_Lab | 0:8ca1e814a851 | 38 | void dn_uart_init(dn_uart_rxByte_cbt rxByte_cb) |
APS_Lab | 0:8ca1e814a851 | 39 | { |
APS_Lab | 0:8ca1e814a851 | 40 | // Store RX callback function |
APS_Lab | 0:8ca1e814a851 | 41 | dn_uart_vars.ipmt_uart_rxByte_cb = rxByte_cb; |
APS_Lab | 0:8ca1e814a851 | 42 | |
APS_Lab | 0:8ca1e814a851 | 43 | /* Default configuration for Serial: |
APS_Lab | 0:8ca1e814a851 | 44 | - 8 bit character size |
APS_Lab | 0:8ca1e814a851 | 45 | - No Parity |
APS_Lab | 0:8ca1e814a851 | 46 | - 1 bit stop bit |
APS_Lab | 0:8ca1e814a851 | 47 | - No flow control |
APS_Lab | 0:8ca1e814a851 | 48 | - 9600 baudrate |
APS_Lab | 0:8ca1e814a851 | 49 | Hence, we only need to change the baudrate */ |
APS_Lab | 0:8ca1e814a851 | 50 | serialMote.baud(115200); |
APS_Lab | 0:8ca1e814a851 | 51 | |
APS_Lab | 0:8ca1e814a851 | 52 | // Attach RX interrupt handler |
APS_Lab | 0:8ca1e814a851 | 53 | serialMote.attach(&moteRXinterrupt, Serial::RxIrq); |
APS_Lab | 0:8ca1e814a851 | 54 | |
APS_Lab | 0:8ca1e814a851 | 55 | //debug("SMIP Serial Initialized"); |
APS_Lab | 0:8ca1e814a851 | 56 | } |
APS_Lab | 0:8ca1e814a851 | 57 | |
APS_Lab | 0:8ca1e814a851 | 58 | void dn_uart_txByte(uint8_t byte) |
APS_Lab | 0:8ca1e814a851 | 59 | { |
APS_Lab | 0:8ca1e814a851 | 60 | serialMote.putc(byte); |
APS_Lab | 0:8ca1e814a851 | 61 | } |
APS_Lab | 0:8ca1e814a851 | 62 | |
APS_Lab | 0:8ca1e814a851 | 63 | void dn_uart_txFlush() |
APS_Lab | 0:8ca1e814a851 | 64 | { |
APS_Lab | 0:8ca1e814a851 | 65 | // Nothing to do since we push byte-by-byte |
APS_Lab | 0:8ca1e814a851 | 66 | } |
APS_Lab | 0:8ca1e814a851 | 67 | |
APS_Lab | 0:8ca1e814a851 | 68 | //=========================== private ========================================= |
APS_Lab | 0:8ca1e814a851 | 69 | |
APS_Lab | 0:8ca1e814a851 | 70 | //=========================== helpers ========================================= |
APS_Lab | 0:8ca1e814a851 | 71 | |
APS_Lab | 0:8ca1e814a851 | 72 | //=========================== interrupt handlers ============================== |
APS_Lab | 0:8ca1e814a851 | 73 | |
APS_Lab | 0:8ca1e814a851 | 74 | void moteRXinterrupt(void) |
APS_Lab | 0:8ca1e814a851 | 75 | { |
APS_Lab | 0:8ca1e814a851 | 76 | while (serialMote.readable()) |
APS_Lab | 0:8ca1e814a851 | 77 | { |
APS_Lab | 0:8ca1e814a851 | 78 | dn_uart_vars.ipmt_uart_rxByte_cb(serialMote.getc()); |
APS_Lab | 0:8ca1e814a851 | 79 | } |
APS_Lab | 0:8ca1e814a851 | 80 | } |
APS_Lab | 0:8ca1e814a851 | 81 |