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.
Fork of ST_I2S by
drivers/I2S.cpp@16:04e1abb4cca3, 2017-01-25 (annotated)
- Committer:
- Wolfgang Betz
- Date:
- Wed Jan 25 13:56:15 2017 +0100
- Revision:
- 16:04e1abb4cca3
- Parent:
- 11:50562a5f8a93
- Child:
- 17:7a4a4631672c
Make locking function become protected
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Wolfgang Betz |
0:752e74bf5ef1 | 1 | #include "drivers/I2S.h" |
Wolfgang Betz |
0:752e74bf5ef1 | 2 | #include "platform/critical.h" |
Wolfgang Betz |
0:752e74bf5ef1 | 3 | #include "platform/mbed_assert.h" |
Wolfgang Betz |
0:752e74bf5ef1 | 4 | |
Wolfgang Betz |
0:752e74bf5ef1 | 5 | #if DEVICE_I2S |
Wolfgang Betz |
0:752e74bf5ef1 | 6 | |
Wolfgang Betz |
0:752e74bf5ef1 | 7 | namespace mbed { |
Wolfgang Betz |
0:752e74bf5ef1 | 8 | |
Wolfgang Betz |
10:1a612c2e4a85 | 9 | I2S* I2S::_owner = NULL; |
Wolfgang Betz |
10:1a612c2e4a85 | 10 | SingletonPtr<PlatformMutex> I2S::_mutex; // intentional class level lock! |
Wolfgang Betz |
0:752e74bf5ef1 | 11 | |
Wolfgang Betz |
10:1a612c2e4a85 | 12 | events::EventQueue I2S::i2s_bh_queue; |
Wolfgang Betz |
0:752e74bf5ef1 | 13 | |
Wolfgang Betz |
10:1a612c2e4a85 | 14 | void I2S::lock() { |
Wolfgang Betz |
10:1a612c2e4a85 | 15 | #if defined(NDEBUG) || !defined(MBED_CONF_RTOS_PRESENT) |
Wolfgang Betz |
10:1a612c2e4a85 | 16 | _mutex->lock(); // intentional class level lock! |
Wolfgang Betz |
0:752e74bf5ef1 | 17 | #else |
Wolfgang Betz |
10:1a612c2e4a85 | 18 | osStatus ret = _mutex->lock(); // intentional class level lock! |
Wolfgang Betz |
10:1a612c2e4a85 | 19 | MBED_ASSERT(ret == osOK); |
Wolfgang Betz |
0:752e74bf5ef1 | 20 | #endif |
Wolfgang Betz |
10:1a612c2e4a85 | 21 | } |
Wolfgang Betz |
10:1a612c2e4a85 | 22 | |
Wolfgang Betz |
10:1a612c2e4a85 | 23 | void I2S::unlock() { |
Wolfgang Betz |
10:1a612c2e4a85 | 24 | #if defined(NDEBUG) || !defined(MBED_CONF_RTOS_PRESENT) |
Wolfgang Betz |
10:1a612c2e4a85 | 25 | _mutex->unlock(); // intentional class level lock! |
Wolfgang Betz |
10:1a612c2e4a85 | 26 | #else |
Wolfgang Betz |
10:1a612c2e4a85 | 27 | osStatus ret = _mutex->unlock(); // intentional class level lock! |
Wolfgang Betz |
10:1a612c2e4a85 | 28 | MBED_ASSERT(ret == osOK); |
Wolfgang Betz |
10:1a612c2e4a85 | 29 | #endif |
Wolfgang Betz |
10:1a612c2e4a85 | 30 | } |
Wolfgang Betz |
0:752e74bf5ef1 | 31 | |
Wolfgang Betz |
10:1a612c2e4a85 | 32 | I2S::I2S(PinName dpin, PinName clk, PinName wsel, PinName fdpin, PinName mck) : |
Wolfgang Betz |
16:04e1abb4cca3 | 33 | _i2s(), |
Wolfgang Betz |
10:1a612c2e4a85 | 34 | _irq_tx(this), _irq_rx(this), |
Wolfgang Betz |
10:1a612c2e4a85 | 35 | _priority(MEDIUM), |
Wolfgang Betz |
10:1a612c2e4a85 | 36 | _dbits(16), |
Wolfgang Betz |
10:1a612c2e4a85 | 37 | _fbits(16), |
Wolfgang Betz |
10:1a612c2e4a85 | 38 | _polarity(0), |
Wolfgang Betz |
10:1a612c2e4a85 | 39 | _protocol(PHILIPS), |
Wolfgang Betz |
10:1a612c2e4a85 | 40 | _mode(MASTER_TX), |
Wolfgang Betz |
10:1a612c2e4a85 | 41 | _circular(false), |
Wolfgang Betz |
10:1a612c2e4a85 | 42 | _hz(44100) { |
Wolfgang Betz |
10:1a612c2e4a85 | 43 | lock(); |
Wolfgang Betz |
10:1a612c2e4a85 | 44 | /* Init instance */ |
Wolfgang Betz |
10:1a612c2e4a85 | 45 | i2s_init(&_i2s, dpin, clk, wsel, fdpin, mck, _mode); |
Wolfgang Betz |
10:1a612c2e4a85 | 46 | acquire(); |
Wolfgang Betz |
10:1a612c2e4a85 | 47 | unlock(); |
Wolfgang Betz |
10:1a612c2e4a85 | 48 | } |
Wolfgang Betz |
0:752e74bf5ef1 | 49 | |
Wolfgang Betz |
10:1a612c2e4a85 | 50 | int I2S::format(int dbits, int fbits, int polarity) { |
Wolfgang Betz |
10:1a612c2e4a85 | 51 | lock(); |
Wolfgang Betz |
10:1a612c2e4a85 | 52 | if (i2s_active(&_i2s)) { |
Wolfgang Betz |
9:c4c2240e06d6 | 53 | unlock(); |
Wolfgang Betz |
10:1a612c2e4a85 | 54 | return -1; |
Wolfgang Betz |
0:752e74bf5ef1 | 55 | } |
Wolfgang Betz |
10:1a612c2e4a85 | 56 | _dbits = dbits; |
Wolfgang Betz |
10:1a612c2e4a85 | 57 | _fbits = fbits; |
Wolfgang Betz |
10:1a612c2e4a85 | 58 | _polarity = polarity; |
Wolfgang Betz |
10:1a612c2e4a85 | 59 | I2S::_owner = NULL; // Not that elegant, but works. rmeyer |
Wolfgang Betz |
10:1a612c2e4a85 | 60 | acquire(); |
Wolfgang Betz |
10:1a612c2e4a85 | 61 | unlock(); |
Wolfgang Betz |
10:1a612c2e4a85 | 62 | return 0; |
Wolfgang Betz |
10:1a612c2e4a85 | 63 | } |
Wolfgang Betz |
0:752e74bf5ef1 | 64 | |
Wolfgang Betz |
10:1a612c2e4a85 | 65 | int I2S::audio_frequency(unsigned int hz) { |
Wolfgang Betz |
10:1a612c2e4a85 | 66 | lock(); |
Wolfgang Betz |
10:1a612c2e4a85 | 67 | if (i2s_active(&_i2s)) { |
Wolfgang Betz |
9:c4c2240e06d6 | 68 | unlock(); |
Wolfgang Betz |
10:1a612c2e4a85 | 69 | return -1; |
Wolfgang Betz |
0:752e74bf5ef1 | 70 | } |
Wolfgang Betz |
10:1a612c2e4a85 | 71 | _hz = hz; |
Wolfgang Betz |
10:1a612c2e4a85 | 72 | I2S::_owner = NULL; // Not that elegant, but works. rmeyer |
Wolfgang Betz |
10:1a612c2e4a85 | 73 | acquire(); |
Wolfgang Betz |
10:1a612c2e4a85 | 74 | unlock(); |
Wolfgang Betz |
10:1a612c2e4a85 | 75 | return 0; |
Wolfgang Betz |
10:1a612c2e4a85 | 76 | } |
Wolfgang Betz |
0:752e74bf5ef1 | 77 | |
Wolfgang Betz |
10:1a612c2e4a85 | 78 | int I2S::set_protocol(i2s_bitorder_t protocol) { |
Wolfgang Betz |
10:1a612c2e4a85 | 79 | lock(); |
Wolfgang Betz |
10:1a612c2e4a85 | 80 | if (i2s_active(&_i2s)) { |
Wolfgang Betz |
9:c4c2240e06d6 | 81 | unlock(); |
Wolfgang Betz |
10:1a612c2e4a85 | 82 | return -1; |
Wolfgang Betz |
0:752e74bf5ef1 | 83 | } |
Wolfgang Betz |
10:1a612c2e4a85 | 84 | _protocol = protocol; |
Wolfgang Betz |
10:1a612c2e4a85 | 85 | I2S::_owner = NULL; // Not that elegant, but works. rmeyer |
Wolfgang Betz |
10:1a612c2e4a85 | 86 | acquire(); |
Wolfgang Betz |
10:1a612c2e4a85 | 87 | unlock(); |
Wolfgang Betz |
10:1a612c2e4a85 | 88 | return 0; |
Wolfgang Betz |
10:1a612c2e4a85 | 89 | } |
Wolfgang Betz |
0:752e74bf5ef1 | 90 | |
Wolfgang Betz |
10:1a612c2e4a85 | 91 | int I2S::set_mode(i2s_mode_t mode, bool circular) { |
Wolfgang Betz |
10:1a612c2e4a85 | 92 | lock(); |
Wolfgang Betz |
10:1a612c2e4a85 | 93 | if (i2s_active(&_i2s)) { |
Wolfgang Betz |
9:c4c2240e06d6 | 94 | unlock(); |
Wolfgang Betz |
10:1a612c2e4a85 | 95 | return -1; |
Wolfgang Betz |
10:1a612c2e4a85 | 96 | } |
Wolfgang Betz |
10:1a612c2e4a85 | 97 | _mode = mode; |
Wolfgang Betz |
10:1a612c2e4a85 | 98 | _circular = circular; |
Wolfgang Betz |
10:1a612c2e4a85 | 99 | I2S::_owner = NULL; // Not that elegant, but works. rmeyer |
Wolfgang Betz |
10:1a612c2e4a85 | 100 | acquire(); |
Wolfgang Betz |
10:1a612c2e4a85 | 101 | unlock(); |
Wolfgang Betz |
10:1a612c2e4a85 | 102 | return 0; |
Wolfgang Betz |
10:1a612c2e4a85 | 103 | } |
Wolfgang Betz |
10:1a612c2e4a85 | 104 | |
Wolfgang Betz |
10:1a612c2e4a85 | 105 | int I2S::harmonize(I2S &dev_i2s_1, I2S &dev_i2s_2) { |
Wolfgang Betz |
10:1a612c2e4a85 | 106 | dev_i2s_1.lock(); |
Wolfgang Betz |
10:1a612c2e4a85 | 107 | if (i2s_active(&dev_i2s_1._i2s)) { |
Wolfgang Betz |
10:1a612c2e4a85 | 108 | dev_i2s_1.unlock(); |
Wolfgang Betz |
10:1a612c2e4a85 | 109 | return -1; |
Wolfgang Betz |
0:752e74bf5ef1 | 110 | } |
Wolfgang Betz |
9:c4c2240e06d6 | 111 | |
Wolfgang Betz |
10:1a612c2e4a85 | 112 | dev_i2s_2.lock(); |
Wolfgang Betz |
10:1a612c2e4a85 | 113 | if (i2s_active(&dev_i2s_2._i2s)) { |
Wolfgang Betz |
11:50562a5f8a93 | 114 | dev_i2s_2.unlock(); |
Wolfgang Betz |
9:c4c2240e06d6 | 115 | dev_i2s_1.unlock(); |
Wolfgang Betz |
10:1a612c2e4a85 | 116 | return -1; |
Wolfgang Betz |
9:c4c2240e06d6 | 117 | } |
Wolfgang Betz |
9:c4c2240e06d6 | 118 | |
Wolfgang Betz |
10:1a612c2e4a85 | 119 | uint32_t hz1 = dev_i2s_1._hz; |
Wolfgang Betz |
10:1a612c2e4a85 | 120 | uint32_t hz2 = dev_i2s_2._hz; |
Wolfgang Betz |
10:1a612c2e4a85 | 121 | int8_t ret = i2s_harmonize(&dev_i2s_1._i2s, &hz1, &dev_i2s_2._i2s, &hz2); |
Wolfgang Betz |
0:752e74bf5ef1 | 122 | |
Wolfgang Betz |
10:1a612c2e4a85 | 123 | if(ret == 0) { |
Wolfgang Betz |
10:1a612c2e4a85 | 124 | dev_i2s_1.audio_frequency(hz1); |
Wolfgang Betz |
10:1a612c2e4a85 | 125 | dev_i2s_2.audio_frequency(hz2); |
Wolfgang Betz |
9:c4c2240e06d6 | 126 | } |
Wolfgang Betz |
0:752e74bf5ef1 | 127 | |
Wolfgang Betz |
10:1a612c2e4a85 | 128 | dev_i2s_2.unlock(); |
Wolfgang Betz |
10:1a612c2e4a85 | 129 | dev_i2s_1.unlock(); |
Wolfgang Betz |
10:1a612c2e4a85 | 130 | |
Wolfgang Betz |
10:1a612c2e4a85 | 131 | return ret; |
Wolfgang Betz |
10:1a612c2e4a85 | 132 | } |
Wolfgang Betz |
10:1a612c2e4a85 | 133 | |
Wolfgang Betz |
10:1a612c2e4a85 | 134 | void I2S::abort_transfer() |
Wolfgang Betz |
10:1a612c2e4a85 | 135 | { |
Wolfgang Betz |
10:1a612c2e4a85 | 136 | lock(); |
Wolfgang Betz |
10:1a612c2e4a85 | 137 | i2s_abort_asynch(&_i2s); |
Wolfgang Betz |
10:1a612c2e4a85 | 138 | #if TRANSACTION_QUEUE_SIZE_I2S |
Wolfgang Betz |
10:1a612c2e4a85 | 139 | dequeue_transaction(); |
Wolfgang Betz |
10:1a612c2e4a85 | 140 | #endif |
Wolfgang Betz |
10:1a612c2e4a85 | 141 | unlock(); |
Wolfgang Betz |
10:1a612c2e4a85 | 142 | } |
Wolfgang Betz |
10:1a612c2e4a85 | 143 | |
Wolfgang Betz |
0:752e74bf5ef1 | 144 | |
Wolfgang Betz |
10:1a612c2e4a85 | 145 | void I2S::clear_transfer_buffer() |
Wolfgang Betz |
10:1a612c2e4a85 | 146 | { |
Wolfgang Betz |
10:1a612c2e4a85 | 147 | #if TRANSACTION_QUEUE_SIZE_I2S |
Wolfgang Betz |
10:1a612c2e4a85 | 148 | lock(); |
Wolfgang Betz |
10:1a612c2e4a85 | 149 | _transaction_buffer.reset(); |
Wolfgang Betz |
10:1a612c2e4a85 | 150 | unlock(); |
Wolfgang Betz |
10:1a612c2e4a85 | 151 | #endif |
Wolfgang Betz |
10:1a612c2e4a85 | 152 | } |
Wolfgang Betz |
0:752e74bf5ef1 | 153 | |
Wolfgang Betz |
10:1a612c2e4a85 | 154 | void I2S::abort_all_transfers() |
Wolfgang Betz |
10:1a612c2e4a85 | 155 | { |
Wolfgang Betz |
10:1a612c2e4a85 | 156 | lock(); |
Wolfgang Betz |
10:1a612c2e4a85 | 157 | clear_transfer_buffer(); |
Wolfgang Betz |
10:1a612c2e4a85 | 158 | abort_transfer(); |
Wolfgang Betz |
10:1a612c2e4a85 | 159 | unlock(); |
Wolfgang Betz |
10:1a612c2e4a85 | 160 | } |
Wolfgang Betz |
10:1a612c2e4a85 | 161 | |
Wolfgang Betz |
10:1a612c2e4a85 | 162 | int I2S::get_transfer_status() |
Wolfgang Betz |
10:1a612c2e4a85 | 163 | { |
Wolfgang Betz |
10:1a612c2e4a85 | 164 | lock(); |
Wolfgang Betz |
10:1a612c2e4a85 | 165 | if (i2s_active(&_i2s)) { |
Wolfgang Betz |
9:c4c2240e06d6 | 166 | unlock(); |
Wolfgang Betz |
10:1a612c2e4a85 | 167 | return -1; |
Wolfgang Betz |
0:752e74bf5ef1 | 168 | } |
Wolfgang Betz |
10:1a612c2e4a85 | 169 | unlock(); |
Wolfgang Betz |
10:1a612c2e4a85 | 170 | return 0; |
Wolfgang Betz |
10:1a612c2e4a85 | 171 | } |
Wolfgang Betz |
0:752e74bf5ef1 | 172 | |
Wolfgang Betz |
10:1a612c2e4a85 | 173 | unsigned int I2S::get_module() |
Wolfgang Betz |
10:1a612c2e4a85 | 174 | { |
Wolfgang Betz |
10:1a612c2e4a85 | 175 | return i2s_get_module(&_i2s); |
Wolfgang Betz |
10:1a612c2e4a85 | 176 | } |
Wolfgang Betz |
0:752e74bf5ef1 | 177 | |
Wolfgang Betz |
10:1a612c2e4a85 | 178 | int I2S::set_dma_priority(i2s_dma_prio_t prio) |
Wolfgang Betz |
10:1a612c2e4a85 | 179 | { |
Wolfgang Betz |
10:1a612c2e4a85 | 180 | lock(); |
Wolfgang Betz |
10:1a612c2e4a85 | 181 | if (i2s_active(&_i2s)) { |
Wolfgang Betz |
10:1a612c2e4a85 | 182 | unlock(); |
Wolfgang Betz |
10:1a612c2e4a85 | 183 | return -1; |
Wolfgang Betz |
10:1a612c2e4a85 | 184 | } |
Wolfgang Betz |
10:1a612c2e4a85 | 185 | _priority = prio; |
Wolfgang Betz |
10:1a612c2e4a85 | 186 | unlock(); |
Wolfgang Betz |
10:1a612c2e4a85 | 187 | return 0; |
Wolfgang Betz |
10:1a612c2e4a85 | 188 | } |
Wolfgang Betz |
10:1a612c2e4a85 | 189 | |
Wolfgang Betz |
10:1a612c2e4a85 | 190 | int I2S::queue_transfer(const void *tx_buffer, int tx_length, void *rx_buffer, int rx_length, const event_callback_t& callback, int event) |
Wolfgang Betz |
10:1a612c2e4a85 | 191 | { // betzw: MUST be called with lock held! |
Wolfgang Betz |
10:1a612c2e4a85 | 192 | #if TRANSACTION_QUEUE_SIZE_I2S |
Wolfgang Betz |
10:1a612c2e4a85 | 193 | transaction_t t; |
Wolfgang Betz |
10:1a612c2e4a85 | 194 | |
Wolfgang Betz |
10:1a612c2e4a85 | 195 | t.tx_buffer = const_cast<void *>(tx_buffer); |
Wolfgang Betz |
10:1a612c2e4a85 | 196 | t.tx_length = tx_length; |
Wolfgang Betz |
10:1a612c2e4a85 | 197 | t.rx_buffer = rx_buffer; |
Wolfgang Betz |
10:1a612c2e4a85 | 198 | t.rx_length = rx_length; |
Wolfgang Betz |
10:1a612c2e4a85 | 199 | t.event = event; |
Wolfgang Betz |
10:1a612c2e4a85 | 200 | t.callback = callback; |
Wolfgang Betz |
10:1a612c2e4a85 | 201 | t.width = 16; |
Wolfgang Betz |
10:1a612c2e4a85 | 202 | Transaction<I2S> transaction(this, t); |
Wolfgang Betz |
10:1a612c2e4a85 | 203 | core_util_critical_section_enter(); |
Wolfgang Betz |
10:1a612c2e4a85 | 204 | if (_transaction_buffer.full()) { |
Wolfgang Betz |
9:c4c2240e06d6 | 205 | core_util_critical_section_enter(); |
Wolfgang Betz |
10:1a612c2e4a85 | 206 | return -1; // the buffer is full |
Wolfgang Betz |
10:1a612c2e4a85 | 207 | } else { |
Wolfgang Betz |
10:1a612c2e4a85 | 208 | _transaction_buffer.push(transaction); |
Wolfgang Betz |
10:1a612c2e4a85 | 209 | core_util_critical_section_exit(); |
Wolfgang Betz |
10:1a612c2e4a85 | 210 | return 0; |
Wolfgang Betz |
10:1a612c2e4a85 | 211 | } |
Wolfgang Betz |
9:c4c2240e06d6 | 212 | #else |
Wolfgang Betz |
10:1a612c2e4a85 | 213 | return -1; |
Wolfgang Betz |
9:c4c2240e06d6 | 214 | #endif |
Wolfgang Betz |
10:1a612c2e4a85 | 215 | } |
Wolfgang Betz |
0:752e74bf5ef1 | 216 | |
Wolfgang Betz |
0:752e74bf5ef1 | 217 | |
Wolfgang Betz |
9:c4c2240e06d6 | 218 | // ignore the fact that there are multiple physical i2s's, and always update if it wasn't us last |
Wolfgang Betz |
10:1a612c2e4a85 | 219 | void I2S::acquire() { // betzw: MUST be called with lock held! |
Wolfgang Betz |
10:1a612c2e4a85 | 220 | if (_owner != this) { |
Wolfgang Betz |
10:1a612c2e4a85 | 221 | i2s_format(&_i2s, _dbits, _fbits, _polarity); |
Wolfgang Betz |
10:1a612c2e4a85 | 222 | i2s_audio_frequency(&_i2s, _hz); |
Wolfgang Betz |
10:1a612c2e4a85 | 223 | i2s_set_protocol(&_i2s, _protocol); |
Wolfgang Betz |
10:1a612c2e4a85 | 224 | i2s_set_mode(&_i2s, _mode); |
Wolfgang Betz |
10:1a612c2e4a85 | 225 | _owner = this; |
Wolfgang Betz |
0:752e74bf5ef1 | 226 | } |
Wolfgang Betz |
10:1a612c2e4a85 | 227 | } |
Wolfgang Betz |
0:752e74bf5ef1 | 228 | |
Wolfgang Betz |
10:1a612c2e4a85 | 229 | void I2S::start_transfer(const void *tx_buffer, int tx_length, void *rx_buffer, int rx_length, |
Wolfgang Betz |
10:1a612c2e4a85 | 230 | const event_callback_t& callback, int event) |
Wolfgang Betz |
10:1a612c2e4a85 | 231 | { // betzw: MUST be called with lock held! |
Wolfgang Betz |
10:1a612c2e4a85 | 232 | acquire(); |
Wolfgang Betz |
10:1a612c2e4a85 | 233 | _callback = callback; |
Wolfgang Betz |
10:1a612c2e4a85 | 234 | _irq_tx.callback(&I2S::irq_handler_asynch_tx); |
Wolfgang Betz |
10:1a612c2e4a85 | 235 | _irq_rx.callback(&I2S::irq_handler_asynch_rx); |
Wolfgang Betz |
10:1a612c2e4a85 | 236 | i2s_transfer(&_i2s, |
Wolfgang Betz |
10:1a612c2e4a85 | 237 | const_cast<void *>(tx_buffer), tx_length, rx_buffer, rx_length, |
Wolfgang Betz |
10:1a612c2e4a85 | 238 | _circular, _priority, |
Wolfgang Betz |
10:1a612c2e4a85 | 239 | _irq_tx.entry(), _irq_rx.entry(), |
Wolfgang Betz |
10:1a612c2e4a85 | 240 | event); |
Wolfgang Betz |
10:1a612c2e4a85 | 241 | } |
Wolfgang Betz |
0:752e74bf5ef1 | 242 | |
Wolfgang Betz |
0:752e74bf5ef1 | 243 | #if TRANSACTION_QUEUE_SIZE_I2S |
Wolfgang Betz |
0:752e74bf5ef1 | 244 | |
Wolfgang Betz |
10:1a612c2e4a85 | 245 | void I2S::start_transaction(transaction_t *data) |
Wolfgang Betz |
10:1a612c2e4a85 | 246 | { // betzw: MUST be called with lock held! |
Wolfgang Betz |
10:1a612c2e4a85 | 247 | start_transfer(data->tx_buffer, data->tx_length, data->rx_buffer, data->rx_length, data->callback, data->event); |
Wolfgang Betz |
10:1a612c2e4a85 | 248 | } |
Wolfgang Betz |
0:752e74bf5ef1 | 249 | |
Wolfgang Betz |
10:1a612c2e4a85 | 250 | void I2S::dequeue_transaction() |
Wolfgang Betz |
10:1a612c2e4a85 | 251 | { |
Wolfgang Betz |
10:1a612c2e4a85 | 252 | lock(); |
Wolfgang Betz |
10:1a612c2e4a85 | 253 | if (!i2s_active(&_i2s)) { |
Wolfgang Betz |
10:1a612c2e4a85 | 254 | Transaction<I2S> t; |
Wolfgang Betz |
10:1a612c2e4a85 | 255 | if (_transaction_buffer.pop(t)) { |
Wolfgang Betz |
10:1a612c2e4a85 | 256 | I2S* obj = t.get_object(); |
Wolfgang Betz |
10:1a612c2e4a85 | 257 | transaction_t* data = t.get_transaction(); |
Wolfgang Betz |
16:04e1abb4cca3 | 258 | MBED_ASSERT(obj == this); |
Wolfgang Betz |
10:1a612c2e4a85 | 259 | obj->start_transaction(data); |
Wolfgang Betz |
9:c4c2240e06d6 | 260 | } |
Wolfgang Betz |
0:752e74bf5ef1 | 261 | } |
Wolfgang Betz |
10:1a612c2e4a85 | 262 | unlock(); |
Wolfgang Betz |
10:1a612c2e4a85 | 263 | } |
Wolfgang Betz |
0:752e74bf5ef1 | 264 | |
Wolfgang Betz |
0:752e74bf5ef1 | 265 | #endif |
Wolfgang Betz |
0:752e74bf5ef1 | 266 | |
Wolfgang Betz |
10:1a612c2e4a85 | 267 | void I2S::irq_handler_asynch_rx(void) |
Wolfgang Betz |
10:1a612c2e4a85 | 268 | { |
Wolfgang Betz |
10:1a612c2e4a85 | 269 | int event = i2s_irq_handler_asynch(&_i2s, I2S_RX_EVENT); |
Wolfgang Betz |
10:1a612c2e4a85 | 270 | if (_callback && (event & I2S_EVENT_ALL)) { |
Wolfgang Betz |
10:1a612c2e4a85 | 271 | I2sBhHandler::i2s_defer_function(_callback, event & I2S_EVENT_ALL); |
Wolfgang Betz |
10:1a612c2e4a85 | 272 | } |
Wolfgang Betz |
0:752e74bf5ef1 | 273 | #if TRANSACTION_QUEUE_SIZE_I2S |
Wolfgang Betz |
10:1a612c2e4a85 | 274 | if (event & I2S_EVENT_INTERNAL_TRANSFER_COMPLETE) { |
Wolfgang Betz |
10:1a612c2e4a85 | 275 | I2sBhHandler::i2s_defer_function(Callback<void()>(this, &I2S::dequeue_transaction)); |
Wolfgang Betz |
10:1a612c2e4a85 | 276 | } |
Wolfgang Betz |
0:752e74bf5ef1 | 277 | #endif |
Wolfgang Betz |
10:1a612c2e4a85 | 278 | } |
Davide Aliprandi |
4:21603d68bcf7 | 279 | |
Wolfgang Betz |
10:1a612c2e4a85 | 280 | void I2S::irq_handler_asynch_tx(void) |
Wolfgang Betz |
10:1a612c2e4a85 | 281 | { |
Wolfgang Betz |
10:1a612c2e4a85 | 282 | int event = i2s_irq_handler_asynch(&_i2s, I2S_TX_EVENT); |
Wolfgang Betz |
10:1a612c2e4a85 | 283 | if (_callback && (event & I2S_EVENT_ALL)) { |
Wolfgang Betz |
10:1a612c2e4a85 | 284 | I2sBhHandler::i2s_defer_function(_callback, event & I2S_EVENT_ALL); |
Wolfgang Betz |
10:1a612c2e4a85 | 285 | } |
Wolfgang Betz |
9:c4c2240e06d6 | 286 | #if TRANSACTION_QUEUE_SIZE_I2S |
Wolfgang Betz |
10:1a612c2e4a85 | 287 | if (event & I2S_EVENT_INTERNAL_TRANSFER_COMPLETE) { |
Wolfgang Betz |
10:1a612c2e4a85 | 288 | I2sBhHandler::i2s_defer_function(Callback<void()>(this, &I2S::dequeue_transaction)); |
Wolfgang Betz |
10:1a612c2e4a85 | 289 | } |
Wolfgang Betz |
9:c4c2240e06d6 | 290 | #endif |
Wolfgang Betz |
10:1a612c2e4a85 | 291 | } |
Davide Aliprandi |
4:21603d68bcf7 | 292 | |
Wolfgang Betz |
0:752e74bf5ef1 | 293 | } // namespace mbed |
Wolfgang Betz |
0:752e74bf5ef1 | 294 | |
Wolfgang Betz |
0:752e74bf5ef1 | 295 | #endif |