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.
uart1.cpp
00001 #include "uart1.h" 00002 #include "mbed.h" 00003 00004 #define BUFFERSIZE 128 00005 extern Serial bus; 00006 DigitalOut led_2(LED2); 00007 00008 static unsigned char U1buf[BUFFERSIZE]; 00009 static unsigned int U1ptr; 00010 static unsigned int U1gptr; 00011 static unsigned int U1cnt; 00012 00013 00014 static void 00015 serial_event() 00016 { 00017 led_2 = !led_2; 00018 00019 if(bus.readable()) 00020 { 00021 U1buf[U1ptr++] = (unsigned char) USART1->RDR & 0xFF;//(unsigned char)bus.getc(); 00022 U1ptr &= BUFFERSIZE-1; 00023 if(U1ptr == U1gptr) 00024 { 00025 U1gptr++; 00026 U1gptr &= BUFFERSIZE-1; 00027 } 00028 else 00029 { 00030 U1cnt++; 00031 } 00032 } 00033 } 00034 00035 void 00036 init_uart1(void) 00037 { 00038 bus.baud(115200); 00039 bus.attach(&serial_event,Serial::RxIrq); 00040 00041 U1ptr = U1gptr = U1cnt = 0; 00042 } 00043 00044 int 00045 uart1_is_char(void) 00046 { 00047 return U1cnt; 00048 } 00049 00050 int 00051 uart1_get_char(void) 00052 { 00053 int result; 00054 result = 0; 00055 if(U1cnt) 00056 { 00057 result = U1buf[U1gptr++]; 00058 U1gptr &= BUFFERSIZE-1; 00059 U1cnt--; 00060 } 00061 00062 return result; 00063 } 00064 00065 void 00066 send_uart1_char(unsigned char c) 00067 { 00068 bus.putc(c); 00069 }
Generated on Tue Jul 12 2022 22:58:49 by
1.7.2