Class Peripheral

Inheritance Relationships

Base Type

Derived Types

Class Documentation

class Peripheral : public IO_RegHandler

Abstract class defining a framework for MCU peripherals.

Subclassed by ArchAVR_ACP, ArchAVR_ADC, ArchAVR_ExtInt, ArchAVR_Fuses, ArchAVR_MiscRegCtrl, ArchAVR_NVM, ArchAVR_ResetCtrl, ArchAVR_SPI, ArchAVR_TWI, ArchAVR_Timer, ArchAVR_USART, ArchAVR_USI, ArchAVR_WDT, ArchXT_ACP, ArchXT_ADC, ArchXT_Fuses, ArchXT_MiscRegCtrl, ArchXT_NVM, ArchXT_PortMuxCtrl, ArchXT_RTC, ArchXT_ResetCtrl, ArchXT_SPI, ArchXT_TWI, ArchXT_TimerA, ArchXT_TimerB, ArchXT_USART, ArchXT_USERROW, DummyController, InterruptController, Port, SleepController, VREF, WatchdogTimer

Public Functions

explicit Peripheral(ctl_id_t id)

Build a default peripheral.

virtual ~Peripheral()
inline ctl_id_t id() const

Unique identifier of the peripheral.

std::string name() const
Returns:

the name of the peripheral (the id converted to 4 ASCII characters)

virtual bool init(Device &device)

Virtual method called when the device is initialised. This is where the peripheral can allocate its I/O registers, interrupts or connect signals.

Returns:

boolean indicates the success of all allocations.

virtual void reset()

Virtual method called when the device is reset. Note that resetting I/O registers is only necessary here if their reset value is not zero.

virtual bool ctlreq(ctlreq_id_t req, ctlreq_data_t *data)

Virtual method called for a CTL request. The method must return true if the request has been processed.

virtual uint8_t ioreg_read_handler(reg_addr_t addr, uint8_t value) override

Virtual method called when the CPU is reading a I/O register allocated by this peripheral. The value has not been read yet so the module can modify it before the CPU gets it.

Parameters:
  • addr – the register address in I/O space

  • value – current cached value of the register

Returns:

actual value of the register

virtual uint8_t ioreg_peek_handler(reg_addr_t addr, uint8_t value) override

Virtual method called when a debug probe is peeking the value of a register. The value has not been read yet so the module can modify it before the CPU gets it. The difference between a peek and a read is that a peek should not modify the state of the peripheral. By default, ioreg_read_handler is called to obtain the value.

Parameters:
  • addr – the register address in I/O space

  • value – current cached value of the register

Returns:

actual value of the register

virtual void ioreg_write_handler(reg_addr_t addr, const ioreg_write_t &data) override

Virtual method called when the CPU is writing a I/O register allocated by this peripheral. The value has already been written.

Parameters:
  • addr – the register address in I/O space

  • value – the new register content

virtual void sleep(bool on, SleepMode mode)

Virtual method called when the device enters or exits a sleep mode.

Parameters:
  • on – true when entering a sleep mode, false when exiting it.

  • mode – one of the enum SleepMode values

Peripheral(const Peripheral&) = delete
Peripheral &operator=(const Peripheral&) = delete

Protected Functions

inline Device *device() const

Access to the device. It is null before init() is called.

inline Logger &logger()
void add_ioreg(const regbit_t &rb, bool readonly = false)
void add_ioreg(const regbit_compound_t &rbc, bool readonly = false)
void add_ioreg(reg_addr_t addr, uint8_t mask = 0xFF, bool readonly = false)
uint8_t read_ioreg(reg_addr_t reg) const
void write_ioreg(const regbit_t &rb, uint8_t value)
inline uint8_t read_ioreg(const regbit_t &rb) const
uint64_t read_ioreg(const regbit_compound_t &rbc) const
inline uint8_t read_ioreg(reg_addr_t reg, const bitmask_t &bm) const
inline bool test_ioreg(reg_addr_t reg, uint8_t bit) const
inline bool test_ioreg(reg_addr_t reg, const bitmask_t &bm) const
inline bool test_ioreg(const regbit_t &rb, uint8_t bit = 0) const
void write_ioreg(const regbit_compound_t &rbc, uint64_t value)
inline void write_ioreg(reg_addr_t reg, uint8_t value)
inline void write_ioreg(reg_addr_t reg, uint8_t bit, uint8_t value)
inline void write_ioreg(reg_addr_t reg, const bitmask_t &bm, uint8_t value)
inline void set_ioreg(const regbit_t &rb)
void set_ioreg(const regbit_compound_t &rbc)
inline void set_ioreg(reg_addr_t reg, uint8_t bit)
inline void set_ioreg(reg_addr_t reg, const bitmask_t &bm)
inline void set_ioreg(const regbit_t &rb, uint8_t bit)
inline void clear_ioreg(const regbit_t &rb)
void clear_ioreg(const regbit_compound_t &rbc)
inline void clear_ioreg(reg_addr_t reg)
inline void clear_ioreg(reg_addr_t reg, uint8_t bit)
inline void clear_ioreg(reg_addr_t reg, const bitmask_t &bm)
inline void clear_ioreg(const regbit_t &rb, uint8_t bit)
bool register_interrupt(int_vect_t vector, InterruptHandler &handler) const

Helper function to register an interrupt vector.

Signal *get_signal(ctl_id_t ctl_id) const

Helper function to obtain a pointer to a signal from another peripheral.

inline Signal *get_signal(const char *name) const