Welcome to the Board Support Package (BSP) for the Efinix Sapphire SoC. This BSP allows software running on the RISC-V processor to interact with on-chip peripherals such as SPI, I2C, GPIO, and Timers.
The drivers are designed to be bare-metal compliant, lightweight, and capable of running with or without an operating system (RTOS).
The BSP follows an Instance-Based driver model. Each peripheral driver consists of two main data structures:
- Hardware Register Map (*_hwreg_t): A structure that maps directly to the physical memory address of the peripheral. This is typically used internally by the driver to read/write hardware registers.
- Software Instance (*_instance_t): A high-level structure that holds the Configuration State (Shadow Registers) and a pointer to the hardware base address. @ Unlike traditional drivers that write to hardware immediately, this BSP uses a "Configure-then-Apply" pattern to ensure atomic updates:
- Modify: Update the settings in the instance structure (e.g., spi.cpol = HIGH).
- Apply: Call the applyConfig() function to flush these settings to the hardware.
To use a specific driver, the application must follow this initialization flow:
- Instantiate: Declare the driver instance structure.
- Link: Assign the hardware base address (defined in soc.h).
- Configure: Set the desired parameters (Prescalers, Modes, Interrupts).
- Apply: Call *_applyConfig() to initialize the hardware.
- Enable: (Optional) Register the interrupt handler via the PLIC.
Note: This is an example showing how to instantiate I2C with i2c_instance_t and i2c_hwreg_t.
#include i2c/i2c.h
#define I2C_FREQ 100000
#define I2C_ADDR 0x67<<1
#define I2C_CTRL_HZ SYSTEM_CLINT_HZ
#define I2C_CTRL (i2c_hwreg_t *)SYSTEM_I2C_1_IO_CTRL
.hwreg = I2C_CTRL,
.slaveAddress = I2C_ADDR,
.samplingClockDivider = 3,
.timeout = I2C_CTRL_HZ/1000,
.tsuDat = I2C_CTRL_HZ/(I2C_FREQ*5),
.tLow = I2C_CTRL_HZ/(I2C_FREQ*2),
.tHigh = I2C_CTRL_HZ/(I2C_FREQ*2),
.tBuf = I2C_CTRL_HZ/(I2C_FREQ),
};
I2C instance. Holds the software registers and hardware pointer.
View License and Legal Information