Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BufferedSerial mbed-rtos mbed
Fork of NucleoF401_ESP8622 by
Diff: modem.cpp
- Revision:
- 0:515a38e245a4
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/modem.cpp Tue Jan 13 15:48:44 2015 +0000
@@ -0,0 +1,54 @@
+
+#include "modem.h"
+
+
+Modem::Modem(PinName tx, PinName rx) : Serial(tx,rx)
+{
+ tx_in=0;
+ tx_out=0;
+ rx_in=0;
+ rx_out=0;
+
+ device_irqn = USART1_IRQn;
+
+ // attach the interrupts
+ Serial::attach(this, &Modem::Rx_interrupt, Serial::RxIrq);
+
+}
+
+
+// Read a line from the large rx buffer from rx interrupt routine
+void Modem::read_buf(char *c,int ln)
+{
+int i=0;
+// Start Critical Section - don't interrupt while changing global buffer variables
+ NVIC_DisableIRQ(USART1_IRQn);
+
+ for (i=0;i<ln;i++){
+ *c=rx_buffer[i];
+ c++;
+ }
+ rx_out=0;
+ rx_in=0;
+ memset(rx_buffer,0,BUFFER_SIZE);
+ NVIC_EnableIRQ(USART1_IRQn);
+ return;
+
+
+}
+
+// Interupt Routine to read in data from serial port
+void Modem::Rx_interrupt()
+{
+ // Loop just in case more than one character is in UART's receive FIFO buffer
+ // Stop if buffer full
+ while ((readable()) && (((rx_in + 1) % BUFFER_SIZE) != rx_out)) {
+ rx_buffer[rx_in] = getc();
+ // pc.putc(rx_buffer[rx_in]);
+ // Uncomment to Echo to USB serial to watch data flow
+ // monitor_device.putc(rx_buffer[rx_in]);
+ rx_in = (rx_in + 1) % BUFFER_SIZE;
+ }
+ return;
+}
+
