22
22
23
23
namespace mbed {
24
24
25
- static void donothing () {};
26
- static void donothing2 (int arg) {};
27
-
28
-
29
25
SerialBase::SerialBase (PinName tx, PinName rx, int baud) :
30
26
#if DEVICE_SERIAL_ASYNCH
31
27
_thunk_irq (this ), _tx_usage(DMA_USAGE_NEVER),
32
- _rx_usage(DMA_USAGE_NEVER), _tx_callback(donothing2 ),
33
- _rx_callback(donothing2 ),
28
+ _rx_usage(DMA_USAGE_NEVER), _tx_callback(NULL ),
29
+ _rx_callback(NULL ),
34
30
#endif
35
31
_serial (), _baud(baud) {
36
32
// No lock needed in the constructor
37
33
38
34
for (size_t i = 0 ; i < sizeof _irq / sizeof _irq[0 ]; i++) {
39
- _irq[i] = donothing ;
35
+ _irq[i] = NULL ;
40
36
}
41
37
42
38
serial_init (&_serial, tx, rx);
@@ -78,17 +74,17 @@ void SerialBase::attach(Callback<void()> func, IrqType type) {
78
74
core_util_critical_section_enter ();
79
75
if (func) {
80
76
// lock deep sleep only the first time
81
- if (_irq[type] == donothing ) {
77
+ if (! _irq[type]) {
82
78
sleep_manager_lock_deep_sleep ();
83
79
}
84
80
_irq[type] = func;
85
81
serial_irq_set (&_serial, (SerialIrq)type, 1 );
86
82
} else {
87
83
// unlock deep sleep only the first time
88
- if (_irq[type] != donothing ) {
84
+ if (_irq[type]) {
89
85
sleep_manager_unlock_deep_sleep ();
90
86
}
91
- _irq[type] = donothing ;
87
+ _irq[type] = NULL ;
92
88
serial_irq_set (&_serial, (SerialIrq)type, 0 );
93
89
}
94
90
core_util_critical_section_exit ();
@@ -97,7 +93,9 @@ void SerialBase::attach(Callback<void()> func, IrqType type) {
97
93
98
94
void SerialBase::_irq_handler (uint32_t id, SerialIrq irq_type) {
99
95
SerialBase *handler = (SerialBase*)id;
100
- handler->_irq [irq_type]();
96
+ if (handler->_irq [irq_type]) {
97
+ handler->_irq [irq_type]();
98
+ }
101
99
}
102
100
103
101
int SerialBase::_base_getc () {
@@ -192,20 +190,20 @@ void SerialBase::start_write(const void *buffer, int buffer_size, char buffer_wi
192
190
void SerialBase::abort_write (void )
193
191
{
194
192
// rx might still be active
195
- if (_rx_callback == &donothing2 ) {
193
+ if (_rx_callback) {
196
194
sleep_manager_unlock_deep_sleep ();
197
195
}
198
- _tx_callback = donothing2 ;
196
+ _tx_callback = NULL ;
199
197
serial_tx_abort_asynch (&_serial);
200
198
}
201
199
202
200
void SerialBase::abort_read (void )
203
201
{
204
202
// tx might still be active
205
- if (_tx_callback == &donothing2 ) {
203
+ if (_tx_callback) {
206
204
sleep_manager_unlock_deep_sleep ();
207
205
}
208
- _rx_callback = donothing2 ;
206
+ _rx_callback = NULL ;
209
207
serial_rx_abort_asynch (&_serial);
210
208
}
211
209
0 commit comments