SmartMesh QSL for STM32F4 version

Fork of COG-AD4050_QSL by APS Lab

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers dn_uart.cpp Source File

dn_uart.cpp

00001 /*
00002 Copyright (c) 2016, Dust Networks. All rights reserved.
00003 
00004 Port of the uart module to the NUCLEO-L053R8.
00005 
00006 \license See attached DN_LICENSE.txt.
00007 */
00008 
00009 #include "dn_uart.h"
00010 #include "dn_ipmt.h"
00011 #include "dn_debug.h"
00012 #include "mbed.h"
00013 
00014 
00015 //=========================== defines =========================================
00016 
00017 // Set correct pins for external UART on your board (USART1 for NUCLEO-F411)
00018 #define UART_MOTE_TX    PA_9
00019 #define UART_MOTE_RX    PA_10
00020 
00021 
00022 //=========================== variables =======================================
00023 
00024 typedef struct {
00025     dn_uart_rxByte_cbt  ipmt_uart_rxByte_cb;
00026 } dn_uart_vars_t;
00027 
00028 static dn_uart_vars_t dn_uart_vars;
00029 static Serial serialMote(UART_MOTE_TX, UART_MOTE_RX);
00030 
00031 
00032 //=========================== prototypes ======================================
00033 
00034 void moteRXinterrupt(void);
00035 
00036 //=========================== public ==========================================
00037 
00038 void dn_uart_init(dn_uart_rxByte_cbt rxByte_cb)
00039 {
00040     // Store RX callback function
00041     dn_uart_vars.ipmt_uart_rxByte_cb = rxByte_cb;
00042     
00043     /* Default configuration for Serial:
00044         - 8 bit character size
00045         - No Parity
00046         - 1 bit stop bit
00047         - No flow control
00048         - 9600 baudrate
00049     Hence, we only need to change the baudrate */
00050     serialMote.baud(115200);
00051     
00052     // Attach RX interrupt handler
00053     serialMote.attach(&moteRXinterrupt, Serial::RxIrq);
00054 
00055     //debug("SMIP Serial Initialized");
00056 }
00057 
00058 void dn_uart_txByte(uint8_t byte)
00059 {
00060     serialMote.putc(byte);
00061 }
00062 
00063 void dn_uart_txFlush()
00064 {
00065     // Nothing to do since we push byte-by-byte
00066 }
00067 
00068 //=========================== private =========================================
00069 
00070 //=========================== helpers =========================================
00071 
00072 //=========================== interrupt handlers ==============================
00073 
00074 void moteRXinterrupt(void)
00075 {
00076     while (serialMote.readable())
00077     {
00078         dn_uart_vars.ipmt_uart_rxByte_cb(serialMote.getc());
00079     }
00080 }
00081