class::hal::Periph

class hal::Periph
  : public hal::PeriphObject

This is an abstract class for a microcontroller peripheral.

All peripherals have a common interface based on the following function:

The classes that inherit Periph implement a method for each ioctl() call available on the peripheral. For example, the UART has an ioctl request called I_UART_SETATTR so the method Uart::set_attr() implements the ioctl request.

Summary

[Periph](#classhal_1_1_periph_1a853a3e80705b3f43ceab939e50fce58c)(  

core_periph_t periph,
port_t port
)

int get_info(

info_t & info
) const

int get_version() const

int initialize()

int initialize(

const AttributesClass & attributes
)

Periph & operator<<(

const AttributesClass & attributes
) const

Periph & operator<<(

const mcu_action_t & action
)

port_t port() const

int set_action(

const mcu_action_t & action
) const

int set_action(

const arg::Channel & channel,
const arg::Events & o_events,
const arg::InterruptPriority & priority,
const arg::McuCallback & callback,
const arg::Context & context
) const

int set_attributes() const

int set_attributes(

const AttributesClass & attributes
) const

int set_attributes(

const attr_t & attr
) const

int set_priority(

const arg::InterruptPriority & priority,
const arg::Events & o_events,
const arg::Channel & channel
)

protected u32 get_channel(

u32 loc,
const arg::IoRequest request
) const

protected int set_channel(

const mcu_channel_t & channel,
int request
) const

protected int set_channel(

u32 loc,
u32 value,
const arg::IoRequest request
) const

Members

Periph(

core_periph_t periph,
port_t port
)

Constructs an MCU peripheral object

Parameters

  • periph Core peripheral value

  • port Port number

If the peripheral has been opened by another object, the file descriptor from that object will be used with this object as well.


int get_info(

info_t & info
) const

Gets the peripheral info.

Parameters

  • info A reference to the info object that will be written.

Returns

Zero on success, less than one for an error


int get_version() const

Gets the version of the peripheral driver.

Returns

The BCD version of the driver

The version is a 24-bit BCD value. For example, 0x010203 is version 1.2.3 where:

  • 1 is the major version
  • 2 is the minor version
  • 3 is the patch version

If the major version of the driver is not the same as the major version of the driver interface header in the SDK, there will be problems using the hardware.

Here is a code sample using a Pwm object (which inherits this object)

#include <sapi.hal.hpp>

Pwm pwm(1); //pwm inherits this object
pwm.open();
if( (pwm.get_version()) >> 16 != (PWM_VERSION >>16) ){
 printf("Major versions are not the same\n");
} else {
 printf("Major versions match\n");
}

int initialize()

Initializes the hardware using the default attributes.

Returns

Less than zero on an error.

The system should set the error number to ENOSYS if no default attributes are provided.


int initialize(

const AttributesClass & attributes
)

Initializes the peripheral using the provided attributes


Periph & operator<<(

const AttributesClass & attributes
) const

Applies the given attributes to the peripheral.

Use error_number() to see if the operation was successful.


Periph & operator<<(

const mcu_action_t & action
)


port_t port() const

int set_action(

const mcu_action_t & action
) const


int set_action(

const arg::Channel & channel,
const arg::Events & o_events,
const arg::InterruptPriority & priority,
const arg::McuCallback & callback,
const arg::Context & context
) const

Sets the action callback for the event.

Parameters

  • channel

  • o_events

  • prio

  • callback

  • context

Returns


int set_attributes() const

Sets the default attributes on the hardware.

Returns

Zero on success

For this method to work correctly, the board support package must include the configuration information for the device. If the information is not provided, this method will return an error.

The system should set the error number to ENOSYS if no default attributes are provided.


int set_attributes(

const AttributesClass & attributes
) const

Sets the peripheral attributes based on the attributes passed.

Parameters

  • attributes A const reference to the attributes used to apply to the peripheral.

Returns

Zero on success or less than zero for an error

UartAttributes uart_attributes; //default attributes
uart_attributes.set_frequency(9600);

Uart uart(0);
uart.open();
uart.set_attributes(uart_attributes);

int set_attributes(

const attr_t & attr
) const


int set_priority(

const arg::InterruptPriority & priority,
const arg::Events & o_events,
const arg::Channel & channel
)

Adjusts the priority of the hardware interrupt for the MCU peripheral.

Returns

Zero on success


protected u32 get_channel(

u32 loc,
const arg::IoRequest request
) const


protected int set_channel(

const mcu_channel_t & channel,
int request
) const


protected int set_channel(

u32 loc,
u32 value,
const arg::IoRequest request
) const


X

Thanks for Coming!

Subscribe to news and updates