Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RM_COMMS_I2C semaphore/mutex not initialised #350

Open
KoviRobi opened this issue Apr 22, 2024 · 1 comment
Open

RM_COMMS_I2C semaphore/mutex not initialised #350

KoviRobi opened this issue Apr 22, 2024 · 1 comment
Labels

Comments

@KoviRobi
Copy link

KoviRobi commented Apr 22, 2024

Hi,

If I add an I2C shared bus/device (rm_comms_i2c) via the e2studio, it creates the g_comms_i2c_bus<busname>_recursive_mutex_handle and g_comms_i2c_bus<busname>_blocking_semaphore_handle in ra_gen/common_data.c, but it is never initialised. I might expect it to be initialised in the RM_COMMS_I2C_Open:

fsp_err_t RM_COMMS_I2C_Open (rm_comms_ctrl_t * const p_api_ctrl, rm_comms_cfg_t const * const p_cfg)
{
rm_comms_i2c_instance_ctrl_t * p_ctrl = (rm_comms_i2c_instance_ctrl_t *) p_api_ctrl;
rm_comms_i2c_bus_extended_cfg_t * p_bus;
#if RM_COMMS_I2C_CFG_PARAM_CHECKING_ENABLE
FSP_ASSERT(NULL != p_ctrl);
FSP_ASSERT(NULL != p_cfg);
FSP_ERROR_RETURN(RM_COMMS_I2C_OPEN != p_ctrl->open, FSP_ERR_ALREADY_OPEN);
#endif
p_ctrl->p_cfg = p_cfg;
p_bus = (rm_comms_i2c_bus_extended_cfg_t *) p_cfg->p_extend;
#if RM_COMMS_I2C_CFG_PARAM_CHECKING_ENABLE
FSP_ASSERT(NULL != p_bus);
FSP_ASSERT(NULL != p_bus->p_driver_instance);
#endif
/* Set Bus configuration */
p_ctrl->p_bus = p_bus;
#if RM_COMMS_I2C_CFG_PARAM_CHECKING_ENABLE
FSP_ASSERT(NULL != p_cfg->p_lower_level_cfg);
FSP_ERROR_RETURN(FSP_SUCCESS == rm_comms_i2c_bus_status_check(p_ctrl), FSP_ERR_COMMS_BUS_NOT_OPEN);
#if BSP_CFG_RTOS
if (NULL == p_bus->p_blocking_semaphore)
{
FSP_ASSERT(NULL == p_bus->p_bus_recursive_mutex);
}
#endif
#endif
/* Set lower level driver configuration */
p_ctrl->p_lower_level_cfg = (void *) p_cfg->p_lower_level_cfg;
/* Set callback and context */
p_ctrl->p_callback = p_cfg->p_callback;
p_ctrl->p_context = p_cfg->p_context;
/* Set open flag */
p_ctrl->open = RM_COMMS_I2C_OPEN;
return FSP_SUCCESS;
}

If you contrast this with the UART CDC (rm_comms_uart), then it has a mutex in ra_gen/hal_data.c, which is initialised in RM_COMMS_UART_Open

fsp_err_t RM_COMMS_UART_Open (rm_comms_ctrl_t * const p_api_ctrl, rm_comms_cfg_t const * const p_cfg)
{
fsp_err_t err = FSP_SUCCESS;
rm_comms_uart_instance_ctrl_t * p_ctrl = (rm_comms_uart_instance_ctrl_t *) p_api_ctrl;
#if RM_COMMS_UART_CFG_PARAM_CHECKING_ENABLE
FSP_ASSERT(NULL != p_ctrl);
FSP_ASSERT(NULL != p_cfg);
FSP_ERROR_RETURN(RM_COMMS_UART_OPEN != p_ctrl->open, FSP_ERR_ALREADY_OPEN);
#endif
rm_comms_uart_extended_cfg_t * p_extend = (rm_comms_uart_extended_cfg_t *) p_cfg->p_extend;
#if RM_COMMS_UART_CFG_PARAM_CHECKING_ENABLE
FSP_ASSERT(NULL != p_extend);
FSP_ASSERT(NULL != p_extend->p_uart);
#endif
p_ctrl->p_cfg = p_cfg;
p_ctrl->p_extend = p_extend;
p_ctrl->p_callback = p_cfg->p_callback;
p_ctrl->p_context = p_cfg->p_context;
#if BSP_CFG_RTOS
if (NULL != p_extend->p_tx_mutex)
{
/* Init mutex for writing */
err = rm_comms_recursive_mutex_initialize(p_extend->p_tx_mutex);
FSP_ERROR_RETURN(FSP_SUCCESS == err, err);
}
if (NULL != p_extend->p_rx_mutex)
{
/* Init mutex for reading */
err = rm_comms_recursive_mutex_initialize(p_extend->p_rx_mutex);
FSP_ERROR_RETURN(FSP_SUCCESS == err, err);
}
if (NULL != p_extend->p_tx_semaphore)
{
/* Init semaphore for writing */
err = rm_comms_semaphore_initialize(p_extend->p_tx_semaphore);
FSP_ERROR_RETURN(FSP_SUCCESS == err, err);
}
if (NULL != p_extend->p_rx_semaphore)
{
/* Init semaphore for reading */
err = rm_comms_semaphore_initialize(p_extend->p_rx_semaphore);
FSP_ERROR_RETURN(FSP_SUCCESS == err, err);
}
#endif
/* Calls open function of UART HAL driver */
uart_api_t const * p_uart_api = p_extend->p_uart->p_api;
err = p_uart_api->open(p_extend->p_uart->p_ctrl, p_extend->p_uart->p_cfg);
FSP_ERROR_RETURN(FSP_SUCCESS == err, err);
/* Set callback function */
err = p_uart_api->callbackSet(p_extend->p_uart->p_ctrl, rm_comms_uart_callback, p_ctrl, NULL);
FSP_ERROR_RETURN(FSP_SUCCESS == err, err);
/* Set open flag */
p_ctrl->open = RM_COMMS_UART_OPEN;
return FSP_SUCCESS;
}

Possibly I didn't set some configuration setting, but I would expect the I2C mutex/semaphore to be initialised like this too. I couldn't find a different function to initialise it either. Especially since the actual mutex isn't declared in the header, so it seems like it shouldn't be user visible (which makes sense, it is internal to RM_COMMS_I2C). But without initialising the mutex/semaphore, I cannot use the I2C shared bus.

For now I've worked around this, by initialising it in src/hal_entry.c which isn't autogenerated:

        extern SemaphoreHandle_t g_comms_i2c_bus<busname>_recursive_mutex_handle;
        extern StaticSemaphore_t g_comms_i2c_bus<busname>_recursive_mutex_memory;
        extern SemaphoreHandle_t g_comms_i2c_bus<busname>_blocking_semaphore_handle;
        extern StaticSemaphore_t g_comms_i2c_bus<busname>_blocking_semaphore_memory;

        g_comms_i2c_bus<busname>_recursive_mutex_handle =
            xSemaphoreCreateRecursiveMutexStatic(&g_comms_i2c_bus<busname>_recursive_mutex_memory);

        g_comms_i2c_bus<busname>_blocking_semaphore_handle = xSemaphoreCreateCountingStatic(
            (UBaseType_t)1,
            (UBaseType_t)0,
            &g_comms_i2c_bus<busname>_blocking_semaphore_memory);

(Also as an aside, the UART uses the abstracted type rm_comms_mutex_t/rm_comms_semaphore_t from ra/fsp/src/rm_comms_lock/rm_comms_lock.h whereas the I2C just uses the TX_MUTEX/SemaphoreHandle_t)

@renesas-austin-hansen
Copy link
Collaborator

This issue is being internally tracked under FSPRA-2948.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants