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.
Serial.cpp
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2006-2013 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 #include "Serial.h" 00017 00018 #if DEVICE_SERIAL 00019 00020 namespace mbed { 00021 00022 Serial::Serial(PinName tx, PinName rx, const char *name) : Stream(name) { 00023 serial_init(&_serial, tx, rx); 00024 serial_irq_handler(&_serial, Serial::_irq_handler, (uint32_t)this); 00025 } 00026 00027 void Serial::baud(int baudrate) { 00028 serial_baud(&_serial, baudrate); 00029 } 00030 00031 void Serial::format(int bits, Parity parity, int stop_bits) { 00032 serial_format(&_serial, bits, (SerialParity)parity, stop_bits); 00033 } 00034 00035 int Serial::readable() { 00036 return serial_readable(&_serial); 00037 } 00038 00039 00040 int Serial::writeable() { 00041 return serial_writable(&_serial); 00042 } 00043 00044 void Serial::attach(void (*fptr)(void), IrqType type) { 00045 if (fptr) { 00046 _irq[type].attach(fptr); 00047 serial_irq_set(&_serial, (SerialIrq)type, 1); 00048 } else { 00049 serial_irq_set(&_serial, (SerialIrq)type, 0); 00050 } 00051 } 00052 00053 00054 void Serial::_irq_handler(uint32_t id, SerialIrq irq_type) { 00055 Serial *handler = (Serial*)id; 00056 handler->_irq[irq_type].call(); 00057 } 00058 00059 int Serial::_getc() { 00060 return serial_getc(&_serial); 00061 } 00062 00063 int Serial::_putc(int c) { 00064 serial_putc(&_serial, c); 00065 return c; 00066 } 00067 00068 } // namespace mbed 00069 00070 #endif
Generated on Thu Jul 14 2022 07:43:04 by
1.7.2