Logo
UNICENS V2.3.0-4567
User Manual and API Reference
Peripheral Bus Interface Examples

Example for Ucs_Gpio_CreatePort

// Main function
void main()
{
Ucs_Return_t result = Ucs_Gpio_CreatePort(running_inst_ptr,
0x00U,
0x0003U,
&App_GpioCreatePortResCb);
if (result != UCS_RET_SUCCESS)
{
// Error handling here
}
}
// The GPIO CreatePort event handler function
// Handle GpioCreatePort event
static void App_GpioCreatePortResCb(uint16_t device_id,
uint16_t port_handle,
void * user_ptr)
{
if (result.code == UCS_GPIO_RES_SUCCESS)
{
// Store received port handle
}
else
{
// Error handling here
}
}

Example for Ucs_Gpio_SetPinMode

// Main function
void main()
{
// Set configuration of GPIO pin no. 3
Ucs_Return_t result = Ucs_Gpio_SetPinMode(running_inst_ptr,
0x221U,
0x1D00,
0x03U,
&App_GpioConfigPinModeResCb);
if (result != UCS_RET_SUCCESS)
{
// Error handling here
}
}
// The event handler function
// Handle GpioConfigPinMode event
static void App_GpioConfigPinModeResCb(uint16_t device_id,
uint16_t port_handle,
uint8_t list_sz,
void * user_ptr)
{
if (result.code == UCS_GPIO_RES_SUCCESS)
{
uint8_t i;
for (i = 0U; i < list_sz; i++)
{
// Configuration list of all GPIO pins
// Check configuration of GPIO pin no. 3 here
if (pin_cfg_list[i].pin == 3 && pin_cfg_list[i].mode != UCS_GPIO_OUT_DEFAULT_LOW)
{
// Error handling
}
}
}
else
{
// Error handling here
}
}

Example for Ucs_Gpio_GetPinMode

// Main function
void main()
{
// Read configuration of GPIO pins
Ucs_Return_t result = Ucs_Gpio_GetPinMode(running_inst_ptr,
0x222U,
0x1D00,
&App_GpioConfigPinModeResCb);
if (result != UCS_RET_SUCCESS)
{
// Error handling here
}
}
// The event handler function
// Handle GpioConfigPinMode event
static void App_GpioConfigPinModeResCb(uint16_t device_id,
uint16_t port_handle,
Ucs_Gpio_PinConfiguration_tpin_cfg_list[],
uint8_t list_sz,
void * user_ptr)
{
if (result.code == UCS_GPIO_RES_SUCCESS)
{
uint8_t i;
for (i = 0U; i < list_sz; i++)
{
// Configuration list of all GPIO pins
// Do what needs to be..
}
}
else
{
// Error handling here
}
}

Example for Ucs_Gpio_WritePort

// Main function
void main()
{
Ucs_Return_t result = Ucs_Gpio_WritePort(running_inst_ptr,
0x555U,
0x1D00,
0x0039U,
0x0038U,
&App_GpioWritePortResCb);
if (result != UCS_RET_SUCCESS)
{
// Error handling here
}
}
// The event handler function
// Handle GpioWritePort event
static void App_GpioWritePortResCb(uint16_t device_id,
uint16_t port_handle,
uint16_t current_state,
uint16_t sticky_state,
void * user_ptr)
{
if (result.code == UCS_GPIO_RES_SUCCESS)
{
// Do what needs to be..
}
else
{
// Error handling here
switch (result.details.result_type)
{
// Handle the target results
break;
// Handle transmission error
break;
}
}
}

Example for Ucs_Gpio_ReadPort

// Main function
void main()
{
Ucs_Return_t result = Ucs_Gpio_ReadPort(running_inst_ptr,
0x1D00,
&App_GpioReadPortResCb);
if (result != UCS_RET_SUCCESS)
{
// Error handling here
}
}
// The event handler function
// Handle GpioReadPort event
static void App_GpioReadPortResCb(uint16_t device_id,
uint16_t port_handle,
uint16_t current_state,
uint16_t sticky_state,
{
if (result.code == UCS_GPIO_RES_SUCCESS)
{
// Do what needs to be..
}
else
{
// Error handling here
}
}

Example for App_GpioTriggerEventStatusCb

Ucs_InitData_t ucs_init_data;
(void)Ucs_SetDefaultConfig(&ucs_init_data)
// Resources Management init section.
ucs_init_data.gpio.trigger_event_status_fptr = &App_GpioTriggerEventStatusCb;
// Handle the GPIO trigger events here
void App_GpioTriggerEventStatusCb(uint16_t node_address,
uint16_t gpio_port_handle,
uint16_t rising_edges,
uint16_t falling_edges,
uint16_t levels,
void * user_ptr)
{
// Do what needs to be..
}

Example for Ucs_I2c_CreatePort

#define I2C_INT_PIN_MASK ((uint8_t)0x01)
// Main function
void main()
{
Ucs_Return_t result = Ucs_I2c_CreatePort(running_inst_ptr,
0x556U,
0x00U,
I2C_INT_PIN_MASK,
&App_I2cCreatePortResCb);
if (result != UCS_RET_SUCCESS)
{
// Error handling here
}
}
// Handle I2cCreatePort event
static void App_I2cCreatePortResCb( uint16_t device_id,
uint16_t port_handle,
void * user_ptr )
{
if (result.code == UCS_I2C_RES_SUCCESS)
{
// Store received port handle
}
else
{
// Error handling here
}
}

Example for Ucs_I2c_WritePort

uint8_t myData[] = {0x4U, 0x3U, 0x2U, 0x1U, 0x0U, 0x4U, 0x3U, 0x2U, 0x1U, 0x0U, 0x05U, 0x05U};
// Main function
void main()
{
Ucs_Return_t result = Ucs_I2c_WritePort(running_inst_ptr,
0x15U,
0x0F00U,
4U,
0x20U,
0x0FU,
12U,
myData,
&App_I2cWritePortResCb);
if (result != UCS_RET_SUCCESS)
{
// Error handling here
}
}
// The event handler function
// Handle I2cWritePort event
static void App_I2cWritePortResCb(uint16_t device_id,
uint16_t port_handle,
uint8_t i2c_slave_address,
uint8_t data_len,
void * user_ptr)
{
if (result.code == UCS_I2C_RES_SUCCESS)
{
// Do what needs to be..
}
else
{
// Error handling here
switch (result.details.result_type)
{
// Handle the target results
break;
default:
// Handle transmission error
break;
}
}
}

Example for Ucs_I2c_ReadPort

// Main function
void main()
{
Ucs_Return_t result = Ucs_I2c_ReadPort(running_inst_ptr,
0x14U,
0x0F00U,
0x20U,
5U,
0x0FU,
&App_I2cReadPortResCb);
if (result != UCS_RET_SUCCESS)
{
// Error handling here
}
}
// The event handler function
// Handle I2cReadPort event
static void App_I2cReadPortResCb(uint16_t device_id,
uint16_t port_handle,
uint8_t slave_address,
uint8_t data_len,
uint8_t data_ptr[],
void * user_ptr)
{
if (result.code == UCS_I2C_RES_SUCCESS)
{
// Do what needs to be..
}
else
{
// Error handling here
}
}

Example for Ucs_I2c_InitData_

Ucs_InitData_t ucs_init_data;
(void)Ucs_SetDefaultConfig(&ucs_init_data)
// Resources Management init section.
ucs_init_data.i2c.interrupt_status_fptr = &App_I2cIntStatusCb;
// Handle the I2C interrupt event here
void App_I2cIntStatusCb(uint16_t node_address, void * user_ptr)
{
// Do what needs to be..
}