Integrated program of 4 different kinds of application programs for processing sound signal. 4種類のサウンド信号処理を統合したプログラム.

Dependencies:   F746_GUI F746_SAI_IO FrequencyResponseDrawer SD_PlayerSkeleton UIT_FFT_Real

Committer:
MikamiUitOpen
Date:
Mon Aug 15 07:18:07 2016 +0000
Revision:
0:224dccbc4edd
1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MikamiUitOpen 0:224dccbc4edd 1 /* mbed Microcontroller Library
MikamiUitOpen 0:224dccbc4edd 2 * Copyright (c) 2006-2013 ARM Limited
MikamiUitOpen 0:224dccbc4edd 3 *
MikamiUitOpen 0:224dccbc4edd 4 * Licensed under the Apache License, Version 2.0 (the "License");
MikamiUitOpen 0:224dccbc4edd 5 * you may not use this file except in compliance with the License.
MikamiUitOpen 0:224dccbc4edd 6 * You may obtain a copy of the License at
MikamiUitOpen 0:224dccbc4edd 7 *
MikamiUitOpen 0:224dccbc4edd 8 * http://www.apache.org/licenses/LICENSE-2.0
MikamiUitOpen 0:224dccbc4edd 9 *
MikamiUitOpen 0:224dccbc4edd 10 * Unless required by applicable law or agreed to in writing, software
MikamiUitOpen 0:224dccbc4edd 11 * distributed under the License is distributed on an "AS IS" BASIS,
MikamiUitOpen 0:224dccbc4edd 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
MikamiUitOpen 0:224dccbc4edd 13 * See the License for the specific language governing permissions and
MikamiUitOpen 0:224dccbc4edd 14 * limitations under the License.
MikamiUitOpen 0:224dccbc4edd 15 */
MikamiUitOpen 0:224dccbc4edd 16 #include "SerialBase.h"
MikamiUitOpen 0:224dccbc4edd 17 #include "wait_api.h"
MikamiUitOpen 0:224dccbc4edd 18
MikamiUitOpen 0:224dccbc4edd 19 #if DEVICE_SERIAL
MikamiUitOpen 0:224dccbc4edd 20
MikamiUitOpen 0:224dccbc4edd 21 namespace mbed {
MikamiUitOpen 0:224dccbc4edd 22
MikamiUitOpen 0:224dccbc4edd 23 SerialBase::SerialBase(PinName tx, PinName rx) :
MikamiUitOpen 0:224dccbc4edd 24 #if DEVICE_SERIAL_ASYNCH
MikamiUitOpen 0:224dccbc4edd 25 _thunk_irq(this), _tx_usage(DMA_USAGE_NEVER),
MikamiUitOpen 0:224dccbc4edd 26 _rx_usage(DMA_USAGE_NEVER),
MikamiUitOpen 0:224dccbc4edd 27 #endif
MikamiUitOpen 0:224dccbc4edd 28 _serial(), _baud(9600) {
MikamiUitOpen 0:224dccbc4edd 29 serial_init(&_serial, tx, rx);
MikamiUitOpen 0:224dccbc4edd 30 serial_irq_handler(&_serial, SerialBase::_irq_handler, (uint32_t)this);
MikamiUitOpen 0:224dccbc4edd 31 }
MikamiUitOpen 0:224dccbc4edd 32
MikamiUitOpen 0:224dccbc4edd 33 void SerialBase::baud(int baudrate) {
MikamiUitOpen 0:224dccbc4edd 34 serial_baud(&_serial, baudrate);
MikamiUitOpen 0:224dccbc4edd 35 _baud = baudrate;
MikamiUitOpen 0:224dccbc4edd 36 }
MikamiUitOpen 0:224dccbc4edd 37
MikamiUitOpen 0:224dccbc4edd 38 void SerialBase::format(int bits, Parity parity, int stop_bits) {
MikamiUitOpen 0:224dccbc4edd 39 serial_format(&_serial, bits, (SerialParity)parity, stop_bits);
MikamiUitOpen 0:224dccbc4edd 40 }
MikamiUitOpen 0:224dccbc4edd 41
MikamiUitOpen 0:224dccbc4edd 42 int SerialBase::readable() {
MikamiUitOpen 0:224dccbc4edd 43 return serial_readable(&_serial);
MikamiUitOpen 0:224dccbc4edd 44 }
MikamiUitOpen 0:224dccbc4edd 45
MikamiUitOpen 0:224dccbc4edd 46
MikamiUitOpen 0:224dccbc4edd 47 int SerialBase::writeable() {
MikamiUitOpen 0:224dccbc4edd 48 return serial_writable(&_serial);
MikamiUitOpen 0:224dccbc4edd 49 }
MikamiUitOpen 0:224dccbc4edd 50
MikamiUitOpen 0:224dccbc4edd 51 void SerialBase::attach(void (*fptr)(void), IrqType type) {
MikamiUitOpen 0:224dccbc4edd 52 if (fptr) {
MikamiUitOpen 0:224dccbc4edd 53 _irq[type].attach(fptr);
MikamiUitOpen 0:224dccbc4edd 54 serial_irq_set(&_serial, (SerialIrq)type, 1);
MikamiUitOpen 0:224dccbc4edd 55 } else {
MikamiUitOpen 0:224dccbc4edd 56 serial_irq_set(&_serial, (SerialIrq)type, 0);
MikamiUitOpen 0:224dccbc4edd 57 }
MikamiUitOpen 0:224dccbc4edd 58 }
MikamiUitOpen 0:224dccbc4edd 59
MikamiUitOpen 0:224dccbc4edd 60 void SerialBase::_irq_handler(uint32_t id, SerialIrq irq_type) {
MikamiUitOpen 0:224dccbc4edd 61 SerialBase *handler = (SerialBase*)id;
MikamiUitOpen 0:224dccbc4edd 62 handler->_irq[irq_type].call();
MikamiUitOpen 0:224dccbc4edd 63 }
MikamiUitOpen 0:224dccbc4edd 64
MikamiUitOpen 0:224dccbc4edd 65 int SerialBase::_base_getc() {
MikamiUitOpen 0:224dccbc4edd 66 return serial_getc(&_serial);
MikamiUitOpen 0:224dccbc4edd 67 }
MikamiUitOpen 0:224dccbc4edd 68
MikamiUitOpen 0:224dccbc4edd 69 int SerialBase::_base_putc(int c) {
MikamiUitOpen 0:224dccbc4edd 70 serial_putc(&_serial, c);
MikamiUitOpen 0:224dccbc4edd 71 return c;
MikamiUitOpen 0:224dccbc4edd 72 }
MikamiUitOpen 0:224dccbc4edd 73
MikamiUitOpen 0:224dccbc4edd 74 void SerialBase::send_break() {
MikamiUitOpen 0:224dccbc4edd 75 // Wait for 1.5 frames before clearing the break condition
MikamiUitOpen 0:224dccbc4edd 76 // This will have different effects on our platforms, but should
MikamiUitOpen 0:224dccbc4edd 77 // ensure that we keep the break active for at least one frame.
MikamiUitOpen 0:224dccbc4edd 78 // We consider a full frame (1 start bit + 8 data bits bits +
MikamiUitOpen 0:224dccbc4edd 79 // 1 parity bit + 2 stop bits = 12 bits) for computation.
MikamiUitOpen 0:224dccbc4edd 80 // One bit time (in us) = 1000000/_baud
MikamiUitOpen 0:224dccbc4edd 81 // Twelve bits: 12000000/baud delay
MikamiUitOpen 0:224dccbc4edd 82 // 1.5 frames: 18000000/baud delay
MikamiUitOpen 0:224dccbc4edd 83 serial_break_set(&_serial);
MikamiUitOpen 0:224dccbc4edd 84 wait_us(18000000/_baud);
MikamiUitOpen 0:224dccbc4edd 85 serial_break_clear(&_serial);
MikamiUitOpen 0:224dccbc4edd 86 }
MikamiUitOpen 0:224dccbc4edd 87
MikamiUitOpen 0:224dccbc4edd 88 #if DEVICE_SERIAL_FC
MikamiUitOpen 0:224dccbc4edd 89 void SerialBase::set_flow_control(Flow type, PinName flow1, PinName flow2) {
MikamiUitOpen 0:224dccbc4edd 90 FlowControl flow_type = (FlowControl)type;
MikamiUitOpen 0:224dccbc4edd 91 switch(type) {
MikamiUitOpen 0:224dccbc4edd 92 case RTS:
MikamiUitOpen 0:224dccbc4edd 93 serial_set_flow_control(&_serial, flow_type, flow1, NC);
MikamiUitOpen 0:224dccbc4edd 94 break;
MikamiUitOpen 0:224dccbc4edd 95
MikamiUitOpen 0:224dccbc4edd 96 case CTS:
MikamiUitOpen 0:224dccbc4edd 97 serial_set_flow_control(&_serial, flow_type, NC, flow1);
MikamiUitOpen 0:224dccbc4edd 98 break;
MikamiUitOpen 0:224dccbc4edd 99
MikamiUitOpen 0:224dccbc4edd 100 case RTSCTS:
MikamiUitOpen 0:224dccbc4edd 101 case Disabled:
MikamiUitOpen 0:224dccbc4edd 102 serial_set_flow_control(&_serial, flow_type, flow1, flow2);
MikamiUitOpen 0:224dccbc4edd 103 break;
MikamiUitOpen 0:224dccbc4edd 104
MikamiUitOpen 0:224dccbc4edd 105 default:
MikamiUitOpen 0:224dccbc4edd 106 break;
MikamiUitOpen 0:224dccbc4edd 107 }
MikamiUitOpen 0:224dccbc4edd 108 }
MikamiUitOpen 0:224dccbc4edd 109 #endif
MikamiUitOpen 0:224dccbc4edd 110
MikamiUitOpen 0:224dccbc4edd 111 #if DEVICE_SERIAL_ASYNCH
MikamiUitOpen 0:224dccbc4edd 112
MikamiUitOpen 0:224dccbc4edd 113 int SerialBase::write(const uint8_t *buffer, int length, const event_callback_t& callback, int event)
MikamiUitOpen 0:224dccbc4edd 114 {
MikamiUitOpen 0:224dccbc4edd 115 if (serial_tx_active(&_serial)) {
MikamiUitOpen 0:224dccbc4edd 116 return -1; // transaction ongoing
MikamiUitOpen 0:224dccbc4edd 117 }
MikamiUitOpen 0:224dccbc4edd 118 start_write((void *)buffer, length, 8, callback, event);
MikamiUitOpen 0:224dccbc4edd 119 return 0;
MikamiUitOpen 0:224dccbc4edd 120 }
MikamiUitOpen 0:224dccbc4edd 121
MikamiUitOpen 0:224dccbc4edd 122 int SerialBase::write(const uint16_t *buffer, int length, const event_callback_t& callback, int event)
MikamiUitOpen 0:224dccbc4edd 123 {
MikamiUitOpen 0:224dccbc4edd 124 if (serial_tx_active(&_serial)) {
MikamiUitOpen 0:224dccbc4edd 125 return -1; // transaction ongoing
MikamiUitOpen 0:224dccbc4edd 126 }
MikamiUitOpen 0:224dccbc4edd 127 start_write((void *)buffer, length, 16, callback, event);
MikamiUitOpen 0:224dccbc4edd 128 return 0;
MikamiUitOpen 0:224dccbc4edd 129 }
MikamiUitOpen 0:224dccbc4edd 130
MikamiUitOpen 0:224dccbc4edd 131 void SerialBase::start_write(const void *buffer, int buffer_size, char buffer_width, const event_callback_t& callback, int event)
MikamiUitOpen 0:224dccbc4edd 132 {
MikamiUitOpen 0:224dccbc4edd 133 _tx_callback = callback;
MikamiUitOpen 0:224dccbc4edd 134
MikamiUitOpen 0:224dccbc4edd 135 _thunk_irq.callback(&SerialBase::interrupt_handler_asynch);
MikamiUitOpen 0:224dccbc4edd 136 serial_tx_asynch(&_serial, buffer, buffer_size, buffer_width, _thunk_irq.entry(), event, _tx_usage);
MikamiUitOpen 0:224dccbc4edd 137 }
MikamiUitOpen 0:224dccbc4edd 138
MikamiUitOpen 0:224dccbc4edd 139 void SerialBase::abort_write(void)
MikamiUitOpen 0:224dccbc4edd 140 {
MikamiUitOpen 0:224dccbc4edd 141 serial_tx_abort_asynch(&_serial);
MikamiUitOpen 0:224dccbc4edd 142 }
MikamiUitOpen 0:224dccbc4edd 143
MikamiUitOpen 0:224dccbc4edd 144 void SerialBase::abort_read(void)
MikamiUitOpen 0:224dccbc4edd 145 {
MikamiUitOpen 0:224dccbc4edd 146 serial_rx_abort_asynch(&_serial);
MikamiUitOpen 0:224dccbc4edd 147 }
MikamiUitOpen 0:224dccbc4edd 148
MikamiUitOpen 0:224dccbc4edd 149 int SerialBase::set_dma_usage_tx(DMAUsage usage)
MikamiUitOpen 0:224dccbc4edd 150 {
MikamiUitOpen 0:224dccbc4edd 151 if (serial_tx_active(&_serial)) {
MikamiUitOpen 0:224dccbc4edd 152 return -1;
MikamiUitOpen 0:224dccbc4edd 153 }
MikamiUitOpen 0:224dccbc4edd 154 _tx_usage = usage;
MikamiUitOpen 0:224dccbc4edd 155 return 0;
MikamiUitOpen 0:224dccbc4edd 156 }
MikamiUitOpen 0:224dccbc4edd 157
MikamiUitOpen 0:224dccbc4edd 158 int SerialBase::set_dma_usage_rx(DMAUsage usage)
MikamiUitOpen 0:224dccbc4edd 159 {
MikamiUitOpen 0:224dccbc4edd 160 if (serial_tx_active(&_serial)) {
MikamiUitOpen 0:224dccbc4edd 161 return -1;
MikamiUitOpen 0:224dccbc4edd 162 }
MikamiUitOpen 0:224dccbc4edd 163 _rx_usage = usage;
MikamiUitOpen 0:224dccbc4edd 164 return 0;
MikamiUitOpen 0:224dccbc4edd 165 }
MikamiUitOpen 0:224dccbc4edd 166
MikamiUitOpen 0:224dccbc4edd 167 int SerialBase::read(uint8_t *buffer, int length, const event_callback_t& callback, int event, unsigned char char_match)
MikamiUitOpen 0:224dccbc4edd 168 {
MikamiUitOpen 0:224dccbc4edd 169 if (serial_rx_active(&_serial)) {
MikamiUitOpen 0:224dccbc4edd 170 return -1; // transaction ongoing
MikamiUitOpen 0:224dccbc4edd 171 }
MikamiUitOpen 0:224dccbc4edd 172 start_read((void*)buffer, length, 8, callback, event, char_match);
MikamiUitOpen 0:224dccbc4edd 173 return 0;
MikamiUitOpen 0:224dccbc4edd 174 }
MikamiUitOpen 0:224dccbc4edd 175
MikamiUitOpen 0:224dccbc4edd 176
MikamiUitOpen 0:224dccbc4edd 177 int SerialBase::read(uint16_t *buffer, int length, const event_callback_t& callback, int event, unsigned char char_match)
MikamiUitOpen 0:224dccbc4edd 178 {
MikamiUitOpen 0:224dccbc4edd 179 if (serial_rx_active(&_serial)) {
MikamiUitOpen 0:224dccbc4edd 180 return -1; // transaction ongoing
MikamiUitOpen 0:224dccbc4edd 181 }
MikamiUitOpen 0:224dccbc4edd 182 start_read((void*)buffer, length, 16, callback, event, char_match);
MikamiUitOpen 0:224dccbc4edd 183 return 0;
MikamiUitOpen 0:224dccbc4edd 184 }
MikamiUitOpen 0:224dccbc4edd 185
MikamiUitOpen 0:224dccbc4edd 186
MikamiUitOpen 0:224dccbc4edd 187 void SerialBase::start_read(void *buffer, int buffer_size, char buffer_width, const event_callback_t& callback, int event, unsigned char char_match)
MikamiUitOpen 0:224dccbc4edd 188 {
MikamiUitOpen 0:224dccbc4edd 189 _rx_callback = callback;
MikamiUitOpen 0:224dccbc4edd 190 _thunk_irq.callback(&SerialBase::interrupt_handler_asynch);
MikamiUitOpen 0:224dccbc4edd 191 serial_rx_asynch(&_serial, buffer, buffer_size, buffer_width, _thunk_irq.entry(), event, char_match, _rx_usage);
MikamiUitOpen 0:224dccbc4edd 192 }
MikamiUitOpen 0:224dccbc4edd 193
MikamiUitOpen 0:224dccbc4edd 194 void SerialBase::interrupt_handler_asynch(void)
MikamiUitOpen 0:224dccbc4edd 195 {
MikamiUitOpen 0:224dccbc4edd 196 int event = serial_irq_handler_asynch(&_serial);
MikamiUitOpen 0:224dccbc4edd 197 int rx_event = event & SERIAL_EVENT_RX_MASK;
MikamiUitOpen 0:224dccbc4edd 198 if (_rx_callback && rx_event) {
MikamiUitOpen 0:224dccbc4edd 199 _rx_callback.call(rx_event);
MikamiUitOpen 0:224dccbc4edd 200 }
MikamiUitOpen 0:224dccbc4edd 201
MikamiUitOpen 0:224dccbc4edd 202 int tx_event = event & SERIAL_EVENT_TX_MASK;
MikamiUitOpen 0:224dccbc4edd 203 if (_tx_callback && tx_event) {
MikamiUitOpen 0:224dccbc4edd 204 _tx_callback.call(tx_event);
MikamiUitOpen 0:224dccbc4edd 205 }
MikamiUitOpen 0:224dccbc4edd 206 }
MikamiUitOpen 0:224dccbc4edd 207
MikamiUitOpen 0:224dccbc4edd 208 #endif
MikamiUitOpen 0:224dccbc4edd 209
MikamiUitOpen 0:224dccbc4edd 210 } // namespace mbed
MikamiUitOpen 0:224dccbc4edd 211
MikamiUitOpen 0:224dccbc4edd 212 #endif