mirror of https://github.com/ARMmbed/mbed-os.git
Remove sigio implementation from FileHandle
Make FileHandle more of an interface class, by requiring implementers to provide the sigio() functionality themselves. sigio() and poll() remain parallel independent mechanisms, so FileHandle implementations must trigger both on state changes.pull/4119/head
parent
1afc7bfbef
commit
c65f81bf46
|
@ -40,7 +40,7 @@ BufferedSerial::~BufferedSerial()
|
|||
|
||||
void BufferedSerial::DCD_IRQ()
|
||||
{
|
||||
_poll_change(this);
|
||||
wake();
|
||||
}
|
||||
|
||||
void BufferedSerial::set_data_carrier_detect(PinName DCD_pin, bool active_high)
|
||||
|
@ -94,6 +94,18 @@ int BufferedSerial::sync()
|
|||
return 0;
|
||||
}
|
||||
|
||||
void BufferedSerial::sigio(Callback<void()> func) {
|
||||
core_util_critical_section_enter();
|
||||
_sigio_cb = func;
|
||||
if (_sigio_cb) {
|
||||
short current_events = poll(0x7FFF);
|
||||
if (current_events) {
|
||||
_sigio_cb();
|
||||
}
|
||||
}
|
||||
core_util_critical_section_exit();
|
||||
}
|
||||
|
||||
ssize_t BufferedSerial::write(const void* buffer, size_t length)
|
||||
{
|
||||
size_t data_written = 0;
|
||||
|
@ -164,6 +176,14 @@ bool BufferedSerial::hup() const
|
|||
return _dcd && _dcd->read() != 0;
|
||||
}
|
||||
|
||||
void BufferedSerial::wake()
|
||||
{
|
||||
_poll_change(this);
|
||||
if (_sigio_cb) {
|
||||
_sigio_cb();
|
||||
}
|
||||
}
|
||||
|
||||
short BufferedSerial::poll(short events) const {
|
||||
|
||||
short revents = 0;
|
||||
|
@ -213,7 +233,7 @@ void BufferedSerial::rx_irq(void)
|
|||
|
||||
/* Report the File handler that data is ready to be read from the buffer. */
|
||||
if (was_empty && !_rxbuf.empty()) {
|
||||
_poll_change(this);
|
||||
wake();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -237,7 +257,7 @@ void BufferedSerial::tx_irq(void)
|
|||
|
||||
/* Report the File handler that data can be written to peripheral. */
|
||||
if (was_full && !_txbuf.full() && !hup()) {
|
||||
_poll_change(this);
|
||||
wake();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -64,8 +64,11 @@ public:
|
|||
|
||||
virtual int set_blocking(bool blocking) { _blocking = blocking; return 0; }
|
||||
|
||||
virtual void sigio(Callback<void()> func);
|
||||
|
||||
void set_data_carrier_detect(PinName DCD_pin, bool active_high=false);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
/** Software serial buffers
|
||||
|
@ -76,6 +79,8 @@ private:
|
|||
|
||||
PlatformMutex _mutex;
|
||||
|
||||
Callback<void()> _sigio_cb;
|
||||
|
||||
bool _blocking;
|
||||
bool _tx_irq_enabled;
|
||||
InterruptIn *_dcd;
|
||||
|
@ -95,6 +100,8 @@ private:
|
|||
void tx_irq(void);
|
||||
void rx_irq(void);
|
||||
|
||||
void wake(void);
|
||||
|
||||
void DCD_IRQ(void);
|
||||
};
|
||||
} //namespace mbed
|
||||
|
|
|
@ -32,19 +32,6 @@ off_t FileHandle::size()
|
|||
seek(off, SEEK_SET);
|
||||
return size;
|
||||
}
|
||||
|
||||
void FileHandle::sigio(Callback<void()> func) {
|
||||
core_util_critical_section_enter();
|
||||
_callback = func;
|
||||
if (_callback) {
|
||||
short current_events = poll(0x7FFF);
|
||||
if (current_events) {
|
||||
_callback();
|
||||
}
|
||||
}
|
||||
core_util_critical_section_exit();
|
||||
}
|
||||
|
||||
std::FILE *fdopen(FileHandle *fh, const char *mode)
|
||||
{
|
||||
return mbed_fdopen(fh, mode);
|
||||
|
|
|
@ -181,7 +181,9 @@ public:
|
|||
* The input parameter can be used or ignored - the could always return all events,
|
||||
* or could check just the events listed in events.
|
||||
* Call is non-blocking - returns instantaneous state of events.
|
||||
* Whenever an event occurs, the derived class must call _poll_change().
|
||||
* Whenever an event occurs, the derived class must call _poll_change() (as well as
|
||||
* the sigio() callback).
|
||||
*
|
||||
* @param events bitmask of poll events we're interested in - POLLIN/POLLOUT etc.
|
||||
*
|
||||
* @returns
|
||||
|
@ -230,18 +232,10 @@ public:
|
|||
*
|
||||
* @param func Function to call on state change
|
||||
*/
|
||||
void sigio(Callback<void()> func);
|
||||
|
||||
/** Issue sigio to user - used by mbed::_poll_change */
|
||||
void _send_sigio()
|
||||
virtual void sigio(Callback<void()> func)
|
||||
{
|
||||
if (_callback) {
|
||||
_callback();
|
||||
//Default for real files. Do nothing for real files.
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
Callback<void()> _callback;
|
||||
};
|
||||
|
||||
/** Not a member function
|
||||
|
|
|
@ -75,9 +75,6 @@ int poll(pollfh fhs[], unsigned nfhs, int timeout)
|
|||
void _poll_change(FileHandle *fh)
|
||||
{
|
||||
// TODO, will depend on how we implement poll
|
||||
|
||||
// Also, do the user callback
|
||||
fh->_send_sigio();
|
||||
}
|
||||
|
||||
} // namespace mbed
|
||||
|
|
|
@ -49,7 +49,9 @@ struct pollfh {
|
|||
*/
|
||||
int poll(pollfh fhs[], unsigned nfhs, int timeout);
|
||||
|
||||
/** To be called by device when poll state changes - must be called for poll() and sigio() to work
|
||||
/** To be called by device when poll state changes - must be called for poll() to work
|
||||
* This must be called in addition to the user-provided callback.
|
||||
*
|
||||
* @param fh A pointer to the file handle*/
|
||||
void _poll_change(FileHandle *fh);
|
||||
|
||||
|
|
Loading…
Reference in New Issue