class::hal::Device

class hal::Device
  : public fs::File

This is a device class used for accessing MCU peripherals and other devices.

  • MCU peripheral hardware (most devices have a class that inherits this class)
  • Devices with built-in drivers (see “/dev” folder on the device)

    #include <sapi/hal.hpp>
    
    int main(int argc, char * argv[]){
    char buffer[16];
    Device device;
    device.open("/dev/fifo", Device::RDWR); //open the system fifo (if it exists)
    device.read(0, buffer, 16);             //read 16 bytes from channel (location) 0
    device.close();                         //close the SPI (power it off)
    return 0;
    }
    

Summary

Device()

int cancel(

int channel,
int o_events
)

int cancel_read(

int channel
)

int cancel_write(

int channel
)

virtual const Device & operator<<(

const chrono::MicroTime & t
) const

virtual int read(

fs::Aio & aio
) const

int set_interrupt_priority(

int priority,
int request
)

int set_signal_action(

const DeviceSignal & signal,
const arg::Events o_events,
const arg::Channel channel
)

virtual int write(

fs::Aio & aio
) const

Members

Device()

Constructs a Device.

Unlike fs::File, upon creation the is_close_on_destruct() flag is cleared for all devices (and hal::Periph). In order to close a device, close() must be called explicitly.

This is the desired behavior because it is common to create more than one hal::Device object to access the same hardware in different contexts.


int cancel(

int channel,
int o_events
)


int cancel_read(

int channel
)


int cancel_write(

int channel
)


virtual const Device & operator<<(

const chrono::MicroTime & t
) const


virtual int read(

fs::Aio & aio
) const

Reads the device asynchronously.

Parameters

  • aio A reference to the fs::Aio object to use for reading

See also: fs::Aio


int set_interrupt_priority(

int priority,
int request
)


int set_signal_action(

const DeviceSignal & signal,
const arg::Events o_events,
const arg::Channel channel
)

Configures the device to send a signal when an event happens.

Parameters

  • signal The signal to send

  • o_events A bitmask of events which will cause the signal to be sent

  • channel The hardware channel to listen for events on


virtual int write(

fs::Aio & aio
) const

Writes the device asynchronously.

Parameters

  • aio A reference to the fs::Aio object to use for writing

See also: fs::Aio


X

Thanks for Coming!

Subscribe to news and updates