RA Flexible Software Package Documentation  Release v5.2.0

 
FS3000 Flow Sensor (rm_fs3000)

Functions

fsp_err_t RM_FS3000_Open (rm_fsxxxx_ctrl_t *const p_api_ctrl, rm_fsxxxx_cfg_t const *const p_cfg)
 Opens and configures the FS3000 Middle module. Implements rm_fsxxxx_api_t::open. More...
 
fsp_err_t RM_FS3000_Close (rm_fsxxxx_ctrl_t *const p_api_ctrl)
 Disables specified FS3000 control block. Implements rm_fsxxxx_api_t::close. More...
 
fsp_err_t RM_FS3000_Read (rm_fsxxxx_ctrl_t *const p_api_ctrl, rm_fsxxxx_raw_data_t *const p_raw_data)
 Reads ADC data from FS3000. Implements rm_fsxxxx_api_t::read. More...
 
fsp_err_t RM_FS3000_DataCalculate (rm_fsxxxx_ctrl_t *const p_api_ctrl, rm_fsxxxx_raw_data_t *const p_raw_data, rm_fsxxxx_data_t *const p_fs3000_data)
 Calculates flow [m/sec] from ADC data. Implements rm_fsxxxx_api_t::dataCalculate. More...
 

Detailed Description

Middleware to implement the FS3000 sensor interface. This module implements the FSXXXX Middleware Interface.

Overview

Features

The FS3000 sensor interface implementation has the following key features:

Configuration

Build Time Configurations for rm_fs3000

The following build time configurations are defined in fsp_cfg/rm_fs3000_cfg.h:

ConfigurationOptionsDefaultDescription
Parameter Checking
  • Default (BSP)
  • Enabled
  • Disabled
Default (BSP) If selected code for parameter checking is included in the build.
Device TypeFS3000-1005FS3000-1005 Select FS3000 device used.

Configurations for Sensor > FS3000 Flow Sensor (rm_fs3000)

This module can be added to the Stacks tab via New Stack > Sensor > FS3000 Flow Sensor (rm_fs3000).

ConfigurationOptionsDefaultDescription
NameName must be a valid C symbolg_fs3000_sensor0 Module name.
CallbackName must be a valid C symbolfs3000_callback A user callback function can be provided.

Pin Configuration

This module use SDA and SCL pins of I2C Master and SCI I2C.

Usage Notes

FS3000 datasheet is here.
If ADC data is invalid, it is needed to read ADC data from FS3000 again. The module only supports FS3000-1005.

If an RTOS is used, blocking and bus lock is available.

Bus Initialization

The FS3000 interface expects a bus instance to be opened before opening any FS3000 device. The interface will handle switching between devices on the bus but will not open or close the bus instance. The user should open the bus with the appropriate I2C Master Interface open call.

Examples

Basic Example

This is a basic example of minimal use of FS3000 sensor implementation in an application.

void rm_fs3000_basic_example (void)
{
fsp_err_t err = FSP_SUCCESS;
rm_fsxxxx_raw_data_t fs3000_raw_data;
rm_fsxxxx_data_t fs3000_data;
uint8_t calculated_flag = 0;
/* Open the I2C bus if it is not already open. */
rm_comms_i2c_bus_extended_cfg_t * p_extend =
(rm_comms_i2c_bus_extended_cfg_t *) g_fs3000_cfg.p_instance->p_cfg->p_extend;
i2c_master_instance_t * p_driver_instance = (i2c_master_instance_t *) p_extend->p_driver_instance;
p_driver_instance->p_api->open(p_driver_instance->p_ctrl, p_driver_instance->p_cfg);
#if BSP_CFG_RTOS
/* Create a semaphore for blocking if a semaphore is not NULL */
if (NULL != p_extend->p_blocking_semaphore)
{
#if BSP_CFG_RTOS == 1 // AzureOS
tx_semaphore_create(p_extend->p_blocking_semaphore->p_semaphore_handle,
p_extend->p_blocking_semaphore->p_semaphore_name,
(ULONG) 0);
#elif BSP_CFG_RTOS == 2 // FreeRTOS
*(p_extend->p_blocking_semaphore->p_semaphore_handle) =
xSemaphoreCreateCountingStatic((UBaseType_t) 1,
(UBaseType_t) 0,
p_extend->p_blocking_semaphore->p_semaphore_memory);
#endif
}
/* Create a recursive mutex for bus lock if a recursive mutex is not NULL */
if (NULL != p_extend->p_bus_recursive_mutex)
{
#if BSP_CFG_RTOS == 1 // AzureOS
tx_mutex_create(p_extend->p_bus_recursive_mutex->p_mutex_handle,
p_extend->p_bus_recursive_mutex->p_mutex_name,
TX_INHERIT);
#elif BSP_CFG_RTOS == 2 // FreeRTOS
*(p_extend->p_bus_recursive_mutex->p_mutex_handle) =
xSemaphoreCreateRecursiveMutexStatic(p_extend->p_bus_recursive_mutex->p_mutex_memory);
#endif
}
#endif
err = RM_FS3000_Open(&g_fs3000_ctrl, &g_fs3000_cfg);
/* Handle any errors. This function should be defined by the user. */
handle_error(err);
while (true)
{
do
{
g_flag = 0;
/* Read ADC Data from FS3000 */
RM_FS3000_Read(&g_fs3000_ctrl, &fs3000_raw_data);
while (0 == g_flag)
{
/* Wait callback */
}
/* Calculate Flow value from ADC data */
err = RM_FS3000_DataCalculate(&g_fs3000_ctrl, &fs3000_raw_data, &fs3000_data);
if (FSP_SUCCESS == err)
{
calculated_flag = 1;
}
else if (FSP_ERR_SENSOR_INVALID_DATA == err) /* Checksum error */
{
calculated_flag = 0;
}
else
{
handle_error(err);
}
} while (0 == calculated_flag);
/* Wait 125 milliseconds. See table 4 on the page 7 of the datasheet. */
}
}

Data Structures

struct  rm_fs3000_instance_ctrl_t
 

Data Structure Documentation

◆ rm_fs3000_instance_ctrl_t

struct rm_fs3000_instance_ctrl_t

FS3000 Control Block

Data Fields

uint32_t open
 Open flag.
 
rm_fsxxxx_cfg_t const * p_cfg
 Pointer to FS3000 Configuration.
 
rm_comms_instance_t const * p_comms_i2c_instance
 Pointer of I2C Communications Middleware instance structure.
 
void const * p_context
 Pointer to the user-provided context.
 

Function Documentation

◆ RM_FS3000_Open()

fsp_err_t RM_FS3000_Open ( rm_fsxxxx_ctrl_t *const  p_api_ctrl,
rm_fsxxxx_cfg_t const *const  p_cfg 
)

Opens and configures the FS3000 Middle module. Implements rm_fsxxxx_api_t::open.

Example:

err = RM_FS3000_Open(&g_fs3000_ctrl, &g_fs3000_cfg);
Return values
FSP_SUCCESSFS3000 successfully configured.
FSP_ERR_ASSERTIONNull pointer, or one or more configuration options is invalid.
FSP_ERR_ALREADY_OPENModule is already open. This module can only be opened once.

◆ RM_FS3000_Close()

fsp_err_t RM_FS3000_Close ( rm_fsxxxx_ctrl_t *const  p_api_ctrl)

Disables specified FS3000 control block. Implements rm_fsxxxx_api_t::close.

Return values
FSP_SUCCESSSuccessfully closed.
FSP_ERR_ASSERTIONNull pointer passed as a parameter.
FSP_ERR_NOT_OPENModule is not open.

◆ RM_FS3000_Read()

fsp_err_t RM_FS3000_Read ( rm_fsxxxx_ctrl_t *const  p_api_ctrl,
rm_fsxxxx_raw_data_t *const  p_raw_data 
)

Reads ADC data from FS3000. Implements rm_fsxxxx_api_t::read.

Return values
FSP_SUCCESSSuccessfully data decoded.
FSP_ERR_ASSERTIONNull pointer, or one or more configuration options is invalid.
FSP_ERR_NOT_OPENModule is not open.

◆ RM_FS3000_DataCalculate()

fsp_err_t RM_FS3000_DataCalculate ( rm_fsxxxx_ctrl_t *const  p_api_ctrl,
rm_fsxxxx_raw_data_t *const  p_raw_data,
rm_fsxxxx_data_t *const  p_fs3000_data 
)

Calculates flow [m/sec] from ADC data. Implements rm_fsxxxx_api_t::dataCalculate.

Return values
FSP_SUCCESSSuccessfully data decoded.
FSP_ERR_ASSERTIONNull pointer, or one or more configuration options is invalid.
FSP_ERR_NOT_OPENModule is not open.
FSP_ERR_SENSOR_INVALID_DATAData is invalid.