RZV Flexible Software Package Documentation  Release v3.0.0

 
Temperature Sensor Unit (r_tsu_b)

Functions

fsp_err_t R_TSU_B_Open (adc_ctrl_t *p_ctrl, adc_cfg_t const *const p_cfg)
 
fsp_err_t R_TSU_B_ScanCfg (adc_ctrl_t *p_ctrl, void const *const p_channel_cfg)
 
fsp_err_t R_TSU_B_ScanStart (adc_ctrl_t *p_ctrl)
 
fsp_err_t R_TSU_B_ScanGroupStart (adc_ctrl_t *p_ctrl, adc_group_mask_t group_id)
 
fsp_err_t R_TSU_B_ScanStop (adc_ctrl_t *p_ctrl)
 
fsp_err_t R_TSU_B_StatusGet (adc_ctrl_t *p_ctrl, adc_status_t *p_status)
 
fsp_err_t R_TSU_B_Read (adc_ctrl_t *p_ctrl, adc_channel_t const reg_id, uint16_t *const p_data)
 
fsp_err_t R_TSU_B_Read32 (adc_ctrl_t *p_ctrl, adc_channel_t const reg_id, uint32_t *const p_data)
 
fsp_err_t R_TSU_B_Close (adc_ctrl_t *p_ctrl)
 
fsp_err_t R_TSU_B_InfoGet (adc_ctrl_t *p_ctrl, adc_info_t *p_adc_info)
 
fsp_err_t R_TSU_B_Calibrate (adc_ctrl_t *const p_ctrl, void const *p_extend)
 
fsp_err_t R_TSU_B_OffsetSet (adc_ctrl_t *const p_ctrl, adc_channel_t const reg_id, int32_t offset)
 
fsp_err_t R_TSU_B_CallbackSet (adc_ctrl_t *const p_api_ctrl, void(*p_callback)(adc_callback_args_t *), void const *const p_context, adc_callback_args_t *const p_callback_memory)
 
fsp_err_t R_TSU_B_CalculateTemperature (adc_ctrl_t *p_ctrl, uint16_t temperature_code, float *const p_temperature)
 

Detailed Description

Driver for the TSU peripheral on RZ MPUs. This module implements the ADC Interface.

Overview

Features

The TSU module supports the following features: *1

*1 This driver only supports Cortex-M33.

Configuration

Build Time Configurations for r_tsu_b

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

ConfigurationOptionsDefaultDescription
Parameter Checking
  • Default (BSP)
  • Enabled
  • Disabled
Default (BSP) If selected code for parameter checking is included in the build.

Configurations for Sensor > Temperature Sensor Unit (r_tsu_b)

This module can be added to the Stacks tab via New Stack > Sensor > Temperature Sensor Unit (r_tsu_b).

ConfigurationOptionsDefaultDescription
General > NameName must be a valid C symbolg_tsu0 Module name
General > UnitUnit must be a non-negative integer0 Specifies the TSU_B Unit to be used.
General > ModeMCU Specific OptionsSelect the scan mode.
General > Average Count
  • 1(Latest read data)
  • 2
  • 4
  • 8
1(Latest read data) Average Count Setting.
General > Trigger modeMCU Specific OptionsSelect the trigger mode.
General > ELC EventMCU Specific OptionsSpecifies the ELC trigger to be used for this unit.
Comparison Function > Compare Mode
  • Disabled
  • Outside the range of the setting values
  • Within the range of the setting values
Disabled Select the compare mode.
Comparison Function > Lower Limit ValueValue must be between -40 and 12515 Lower Limit Setting (degrees Celsius).
Comparison Function > Upper Limit ValueValue must be between -40 and 12525 Upper Limit Setting (degrees Celsius).
Interrupts > CallbackName must be a valid C symbolNULL A user callback function can be provided here. If this callback function is provided, it is called from the interrupt service routine (ISR)
Interrupts > Conversion Complete Interrupt EnableMCU Specific OptionsEnable or disable the conversion complete interrupt.
Interrupts > Conversion Complete Interrupt PriorityValue must be between 0 and 25512 Select the interrupt priority for Conversion complete.
Interrupts > Comparison Result Interrupt EnableMCU Specific OptionsEnable or disable the Comparison Result interrupt.
Interrupts > Comparison Result Interrupt PriorityValue must be between 0 and 25512 Select the interrupt priority for Comparison Result.

Clock Configuration

The TSU_B clock is OSC. Fix the clock frequency of this unit to 24 MHz.

Pin Configuration

This module does not use I/O pins.

Usage Notes

Using the Temperature Sensor with the TSU

The TSU_B HAL module supports reading the data from the on-chip temperature sensor. The value returned by the sensor can be converted to degrees Celsius by calling R_TSU_B_CalculateTemperature.

Comparison function

This function compares the averaged temperature code and the values set by the LLIM[11:0] bits of the lower limit setting register and the ULIM[11:0] bits of the upper limit setting register. When a value meets the configured condition an interrupt can be produced.

Examples

Basic Example

This is a basic example of minimal use of the TSU_B in an application.

const tsu_b_extended_cfg_t g_tsu0_cfg_extend =
{
.comparison_mode = TSU_B_COMPARE_CFG_DISABLE,
.compare_ref_low = 0,
.compare_ref_high = 0,
.compare_irq = FSP_INVALID_VECTOR,
.compare_ipl = 12
};
const adc_cfg_t g_tsu0_cfg =
{
.unit = 0,
.resolution = ADC_RESOLUTION_12_BIT,
.p_callback = tsu_b_callback,
.p_context = NULL,
.p_extend = &g_tsu0_cfg_extend,
.scan_end_irq = TSU_B0_S12TSUADI_IRQn,
.scan_end_ipl = 12
};
volatile bool scan_complete_flag = false;
void tsu_b_callback (adc_callback_args_t * p_args)
{
scan_complete_flag = true;
}
void tsu_b_basic_example (void)
{
uint32_t calibration_data1;
uint32_t calibration_data2;
fsp_err_t err = FSP_SUCCESS;
/* Initializes the module. */
err = R_TSU_B_Open(&g_tsu0_ctrl, &g_tsu0_cfg);
/* Handle any errors. This function should be defined by the user. */
assert(FSP_SUCCESS == err);
/* Get Calibration data from the MCU if available. */
adc_info_t tsu_info;
err = R_TSU_B_InfoGet(&g_tsu0_ctrl, &tsu_info);
assert(FSP_SUCCESS == err);
calibration_data1 = tsu_info.calibration_data1;
calibration_data2 = tsu_info.calibration_data2;
/* Check the calibration data because of if the calibration data is an incorrect value, the temperature cannot be calculated correctly. */
if ((calibration_data1 < TSU_B_EXAMPLE_CALIBRATION_DATA_LOWER_LIMIT) ||
(calibration_data1 > TSU_B_EXAMPLE_CALIBRATION_DATA_UPPER_LIMIT) ||
(calibration_data2 < TSU_B_EXAMPLE_CALIBRATION_DATA_LOWER_LIMIT) ||
(calibration_data2 > TSU_B_EXAMPLE_CALIBRATION_DATA_UPPER_LIMIT))
{
__BKPT(0);
}
/* In software trigger mode, start a scan by calling R_TSU_B_ScanStart(). In other modes, enable external
* triggers by calling R_TSU_B_ScanStart(). */
err = R_TSU_B_ScanStart(&g_tsu0_ctrl);
assert(FSP_SUCCESS == err);
/* Wait for conversion to complete. */
while (!scan_complete_flag)
{
/* Wait for callback to set flag. */
}
/* Read converted data. */
uint16_t conversion_result;
err = R_TSU_B_Read(&g_tsu0_ctrl, ADC_CHANNEL_0, &conversion_result);
assert(FSP_SUCCESS == err);
/* Calculate temperature. */
float temperature;
err = R_TSU_B_CalculateTemperature(&g_tsu0_ctrl, conversion_result, &temperature);
assert(FSP_SUCCESS == err);
}

Compare Example

This example shows how to configure the compare function at runtime as well as how to handle events and obtain comparison results through a callback.

const tsu_b_extended_cfg_t g_tsu0_compare_cfg_extend =
{
.comparison_mode = TSU_B_COMPARE_CFG_INSIDE,
.compare_ref_low = 20,
.compare_ref_high = 30,
.compare_irq = TSU_B0_S12TSUADCMPI_IRQn,
.compare_ipl = 12
};
const adc_cfg_t g_tsu0_compare_cfg =
{
.unit = 0,
.resolution = ADC_RESOLUTION_12_BIT,
.p_callback = tsu_b_compare_callback,
.p_context = NULL,
.p_extend = &g_tsu0_compare_cfg_extend,
.scan_end_irq = FSP_INVALID_VECTOR,
.scan_end_ipl = 12
};
void tsu_b_compare_callback (adc_callback_args_t * const p_unused)
{
(void) p_unused;
/* Read converted data. */
uint16_t conversion_result;
float temperature;
/* Read converted data. */
(void) R_TSU_B_Read(&g_tsu0_ctrl, ADC_CHANNEL_0, &conversion_result);
/* Calculate temperature. */
(void) R_TSU_B_CalculateTemperature(&g_tsu0_ctrl, conversion_result, &temperature);
}
void tsu_b_compare_example (void)
{
uint32_t calibration_data1;
uint32_t calibration_data2;
fsp_err_t err = FSP_SUCCESS;
/* Initializes the module. */
err = R_TSU_B_Open(&g_tsu0_ctrl, &g_tsu0_compare_cfg);
/* Handle any errors. This function should be defined by the user. */
assert(FSP_SUCCESS == err);
/* Get Calibration data from the MCU if available. */
adc_info_t tsu_info;
err = R_TSU_B_InfoGet(&g_tsu0_ctrl, &tsu_info);
assert(FSP_SUCCESS == err);
calibration_data1 = tsu_info.calibration_data1;
calibration_data2 = tsu_info.calibration_data2;
/* Check the calibration data because of if the calibration data is an incorrect value, the temperature cannot be calculated correctly. */
if ((calibration_data1 < TSU_B_EXAMPLE_CALIBRATION_DATA_LOWER_LIMIT) ||
(calibration_data1 > TSU_B_EXAMPLE_CALIBRATION_DATA_UPPER_LIMIT) ||
(calibration_data2 < TSU_B_EXAMPLE_CALIBRATION_DATA_LOWER_LIMIT) ||
(calibration_data2 > TSU_B_EXAMPLE_CALIBRATION_DATA_UPPER_LIMIT))
{
__BKPT(0);
}
/* In software trigger mode, start a scan by calling R_TSU_B_ScanStart(). In other modes, enable external
* triggers by calling R_TSU_B_ScanStart(). */
err = R_TSU_B_ScanStart(&g_tsu0_ctrl);
assert(FSP_SUCCESS == err);
}

Get temperature Example

This example shows how to get the temperature multiple times and average it to calculate the temperature.

#define TSU_B_EXAMPLE_CONVERSION_COUNT (4)
#define TSU_B_EXAMPLE_TEMPERATURE_LOWER_LIMIT (-41)
#define TSU_B_EXAMPLE_TEMPERATURE_UPPER_LIMIT (125)
#define TSU_B_EXAMPLE_TEMPERATURE_POSITIVE_ERROR (5)
#define TSU_B_EXAMPLE_TEMPERATURE_NEGATIVE_ERROR (-5)
const tsu_b_extended_cfg_t g_tsu0_get_temp_cfg_extend =
{
.comparison_mode = TSU_B_COMPARE_CFG_DISABLE,
.compare_ref_low = 0,
.compare_ref_high = 0,
.compare_irq = FSP_INVALID_VECTOR,
.compare_ipl = 12,
};
const adc_cfg_t g_tsu0_get_temp_cfg =
{
.unit = 0,
.resolution = ADC_RESOLUTION_12_BIT,
.p_callback = tsu_b_get_temp_callback,
.p_context = NULL,
.p_extend = &g_tsu0_get_temp_cfg_extend,
.scan_end_irq = TSU_B0_S12TSUADI_IRQn,
.scan_end_ipl = (12),
};
void tsu_b_get_temp_callback (adc_callback_args_t * p_args)
{
scan_complete_flag = true;
}
volatile bool timer_overflow_flag = false;
void gpt_callback (timer_callback_args_t * p_args)
{
timer_overflow_flag = true;
}
void tsu_b_get_temperature_example (void)
{
uint32_t calibration_data1;
uint32_t calibration_data2;
uint8_t conversion_count = 0;
float temperature_sum = 0.0;
float Tj;
uint16_t conversion_result[TSU_B_EXAMPLE_CONVERSION_COUNT];
float temperature[TSU_B_EXAMPLE_CONVERSION_COUNT];
fsp_err_t err = FSP_SUCCESS;
/* Initializes the module. */
err = R_TSU_B_Open(&g_tsu0_ctrl, &g_tsu0_get_temp_cfg);
/* Handle any errors. This function should be defined by the user. */
assert(FSP_SUCCESS == err);
/* Get Calibration data from the MCU if available. */
adc_info_t tsu_info;
err = R_TSU_B_InfoGet(&g_tsu0_ctrl, &tsu_info);
assert(FSP_SUCCESS == err);
calibration_data1 = tsu_info.calibration_data1;
calibration_data2 = tsu_info.calibration_data2;
/* Check the calibration data because of if the calibration data is an incorrect value, the temperature cannot be calculated correctly. */
if ((calibration_data1 < TSU_B_EXAMPLE_CALIBRATION_DATA_LOWER_LIMIT) ||
(calibration_data1 > TSU_B_EXAMPLE_CALIBRATION_DATA_UPPER_LIMIT) ||
(calibration_data2 < TSU_B_EXAMPLE_CALIBRATION_DATA_LOWER_LIMIT) ||
(calibration_data2 > TSU_B_EXAMPLE_CALIBRATION_DATA_UPPER_LIMIT))
{
__BKPT(0);
}
while(conversion_count < TSU_B_EXAMPLE_CONVERSION_COUNT)
{
if(conversion_count == 0)
{
/* Initializes the GPT module. Set the period to 500ms. (This value becomes the temperature acquisition interval and can be changed by the user.) */
err = R_GPT_Open(&g_timer0_ctrl, &g_timer0_cfg);
assert(FSP_SUCCESS == err);
/* Start the timer. */
err = R_GPT_Start(&g_timer0_ctrl);
assert(FSP_SUCCESS == err);
}
while (!timer_overflow_flag)
{
/* Wait for callback to set flag. */
}
timer_overflow_flag = false;
/* In software trigger mode, start a scan by calling R_TSU_B_ScanStart(). */
err = R_TSU_B_ScanStart(&g_tsu0_ctrl);
assert(FSP_SUCCESS == err);
/* Wait for conversion to complete. */
while (!scan_complete_flag)
{
/* Wait for callback to set flag. */
}
scan_complete_flag = false;
/* Read converted data. */
err = R_TSU_B_Read(&g_tsu0_ctrl, ADC_CHANNEL_0, &conversion_result[conversion_count]);
assert(FSP_SUCCESS == err);
/* Calculate temperature. */
err =
R_TSU_B_CalculateTemperature(&g_tsu0_ctrl, conversion_result[conversion_count],
&temperature[conversion_count]);
assert(FSP_SUCCESS == err);
/* Confirm that it is within the range of +125 degrees Celsius to -41 degrees Celsius and calculate the average value. */
if ((temperature[conversion_count] > TSU_B_EXAMPLE_TEMPERATURE_LOWER_LIMIT) &&
(temperature[conversion_count] < TSU_B_EXAMPLE_TEMPERATURE_UPPER_LIMIT))
{
temperature_sum += temperature[conversion_count];
conversion_count++;
}
else
{
break;
}
}
Tj = temperature_sum / TSU_B_EXAMPLE_CONVERSION_COUNT;
/* Check that the initial value and Tj are within the error range. */
if ((TSU_B_EXAMPLE_TEMPERATURE_POSITIVE_ERROR < (Tj - temperature[0])) ||
(TSU_B_EXAMPLE_TEMPERATURE_NEGATIVE_ERROR > (Tj - temperature[0])))
{
__BKPT(0);
}
}

Data Structures

struct  tsu_b_extended_cfg_t
 
struct  tsu_b_instance_ctrl_t
 

Enumerations

enum  tsu_b_average_t
 
enum  tsu_b_compare_cfg_t
 

Data Structure Documentation

◆ tsu_b_extended_cfg_t

struct tsu_b_extended_cfg_t

Extended configuration structure for ADC.

Data Fields
tsu_b_average_t average_count Average counts.
tsu_b_compare_cfg_t comparison_mode TSU_B compare function configuration.
int16_t compare_ref_low Lower reference value.
int16_t compare_ref_high Upper reference value.
IRQn_Type compare_irq IRQ number for Comparison Result Interrupts.
uint8_t compare_ipl Priority for Comparison Result Interrupts.

◆ tsu_b_instance_ctrl_t

struct tsu_b_instance_ctrl_t

TSU_B instance control block. DO NOT INITIALIZE. Initialized in adc_api_t::open().

Enumeration Type Documentation

◆ tsu_b_average_t

TSU_B data sample addition and averaging options

Enumerator
TSU_B_AVERAGE_OFF 

Latest read data.

TSU_B_AVERAGE_TWO 

Average two samples.

TSU_B_AVERAGE_FOUR 

Average four samples.

TSU_B_AVERAGE_EIGHT 

Average eight samples.

◆ tsu_b_compare_cfg_t

TSU_B comparison settings

Enumerator
TSU_B_COMPARE_CFG_DISABLE 

Compare function is disabled.

TSU_B_COMPARE_CFG_OUTSIDE 

Comparison Mode: Outside.

TSU_B_COMPARE_CFG_INSIDE 

Comparison Mode: Inside.

Function Documentation

◆ R_TSU_B_Open()

fsp_err_t R_TSU_B_Open ( adc_ctrl_t p_ctrl,
adc_cfg_t const *const  p_cfg 
)

Initializes the TSU_B module and applies configurations.

Return values
FSP_SUCCESSModule is ready for use.
FSP_ERR_ASSERTIONAn input argument is invalid.
FSP_ERR_ALREADY_OPENThe instance control structure has already been opened.
FSP_ERR_IRQ_BSP_DISABLEDA callback is provided, but the interrupt is not enabled.
FSP_ERR_INVALID_HW_CONDITIONCalibration data is invalid value, so TSU_B is in invalid condition.

◆ R_TSU_B_ScanCfg()

fsp_err_t R_TSU_B_ScanCfg ( adc_ctrl_t p_ctrl,
void const *const  p_channel_cfg 
)

adc_api_t::scanCfg is not supported.

Return values
FSP_ERR_UNSUPPORTEDFunction not supported in this implementation.

◆ R_TSU_B_ScanStart()

fsp_err_t R_TSU_B_ScanStart ( adc_ctrl_t p_ctrl)

Starts a software scan or enables the hardware trigger for a scan depending on how the triggers were configured in the R_TSU_B_Open call. If the unit was configured for ELC or external hardware triggering, then this function allows the trigger signal to get to the TSU_B unit. The function is not able to control the generation of the trigger itself. If the unit was configured for software triggering, then this function starts the software triggered scan.

Return values
FSP_SUCCESSScan started (software trigger) or hardware triggers enabled.
FSP_ERR_ASSERTIONAn input argument is invalid.
FSP_ERR_NOT_OPENTSU_B is not open.
FSP_ERR_NOT_INITIALIZEDTSU_B is not initialized.
FSP_ERR_IN_USEAnother scan is still in progress (software trigger).

◆ R_TSU_B_ScanGroupStart()

fsp_err_t R_TSU_B_ScanGroupStart ( adc_ctrl_t p_ctrl,
adc_group_mask_t  group_id 
)

adc_api_t::scanGroupStart is not supported.

Return values
FSP_ERR_UNSUPPORTEDFunction not supported in this implementation.

◆ R_TSU_B_ScanStop()

fsp_err_t R_TSU_B_ScanStop ( adc_ctrl_t p_ctrl)

Disables the unit from being triggered by the hardware trigger (ELC or external) based on what type of trigger the unit was configured for in the R_TSU_B_Open function. Stopping a hardware triggered scan via this function does not abort an ongoing scan, but prevents the next scan from occurring.

Return values
FSP_SUCCESSHardware triggers disabled.
FSP_ERR_ASSERTIONAn input argument is invalid.
FSP_ERR_NOT_OPENTSU_B is not open.
FSP_ERR_NOT_INITIALIZEDTSU_B is not initialized.
FSP_ERR_INVALID_MODENot valid for software triggers.

◆ R_TSU_B_StatusGet()

fsp_err_t R_TSU_B_StatusGet ( adc_ctrl_t p_ctrl,
adc_status_t p_status 
)

Get current TSU_B status and store it in provided pointer p_status. Provides the status of any scan process that was started, including scans started by ELC or external triggers.

Return values
FSP_SUCCESSModule status stored in the provided pointer p_status
FSP_ERR_ASSERTIONAn input argument is invalid.
FSP_ERR_NOT_OPENUnit is not open.

◆ R_TSU_B_Read()

fsp_err_t R_TSU_B_Read ( adc_ctrl_t p_ctrl,
adc_channel_t const  reg_id,
uint16_t *const  p_data 
)

Reads conversion results from a sensor.

Return values
FSP_SUCCESSData read into provided p_data.
FSP_ERR_ASSERTIONAn input argument is invalid.
FSP_ERR_NOT_OPENTSU_B is not open.
FSP_ERR_NOT_INITIALIZEDTSU_B is not initialized.

◆ R_TSU_B_Read32()

fsp_err_t R_TSU_B_Read32 ( adc_ctrl_t p_ctrl,
adc_channel_t const  reg_id,
uint32_t *const  p_data 
)

adc_api_t::read32 is not supported.

Return values
FSP_ERR_UNSUPPORTEDFunction not supported in this implementation.

◆ R_TSU_B_Close()

fsp_err_t R_TSU_B_Close ( adc_ctrl_t p_ctrl)

This function ends any scan in progress, disables interrupts, and removes power to the A/D peripheral.

Return values
FSP_SUCCESSModule closed.
FSP_ERR_ASSERTIONAn input argument is invalid.
FSP_ERR_NOT_OPENUnit is not open.

◆ R_TSU_B_InfoGet()

fsp_err_t R_TSU_B_InfoGet ( adc_ctrl_t p_ctrl,
adc_info_t p_adc_info 
)

Get the calibration data for the sensor.

Return values
FSP_SUCCESSInformation stored in p_adc_info.
FSP_ERR_ASSERTIONAn input argument is invalid.
FSP_ERR_NOT_OPENTSU_B is not open.

◆ R_TSU_B_Calibrate()

fsp_err_t R_TSU_B_Calibrate ( adc_ctrl_t *const  p_ctrl,
void const *  p_extend 
)

adc_api_t::calibrate is not supported.

Return values
FSP_ERR_UNSUPPORTEDFunction not supported in this implementation.

◆ R_TSU_B_OffsetSet()

fsp_err_t R_TSU_B_OffsetSet ( adc_ctrl_t *const  p_ctrl,
adc_channel_t const  reg_id,
int32_t  offset 
)

adc_api_t::offsetSet is not supported.

Return values
FSP_ERR_UNSUPPORTEDFunction not supported in this implementation.

◆ R_TSU_B_CallbackSet()

fsp_err_t R_TSU_B_CallbackSet ( adc_ctrl_t *const  p_api_ctrl,
void(*)(adc_callback_args_t *)  p_callback,
void const *const  p_context,
adc_callback_args_t *const  p_callback_memory 
)

Updates the user callback and has option of providing memory for callback structure. Implements adc_api_t::callbackSet

Return values
FSP_SUCCESSCallback updated successfully.
FSP_ERR_ASSERTIONA required pointer is NULL.
FSP_ERR_NOT_OPENThe control block has not been opened.
FSP_ERR_NO_CALLBACK_MEMORYp_callback is non-secure and p_callback_memory is either secure or NULL.

◆ R_TSU_B_CalculateTemperature()

fsp_err_t R_TSU_B_CalculateTemperature ( adc_ctrl_t p_ctrl,
uint16_t  temperature_code,
float *const  p_temperature 
)

The value returned from the sensor can be converted into degrees Celsius.

Return values
FSP_SUCCESSData calculate into provided p_temp.
FSP_ERR_ASSERTIONAn input argument is invalid.
FSP_ERR_NOT_OPENTSU_B is not open.
FSP_ERR_NOT_INITIALIZEDTSU_B is not initialized.