|
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) |
|
Driver for the TSU peripheral on RZ MPUs. This module implements the ADC Interface.
Overview
Features
The TSU module supports the following features:
- Temperature code reading function
- Temperature code averaging function
- Comparison with the upper and lower limit settings
- Interrupt function
- Conversion start trigger (by software and by an ELC trigger)
- Single scan
- Continuous scan
Configuration
Build Time Configurations for r_tsu_b
The following build time configurations are defined in fsp_cfg/r_tsu_b_cfg.h:
Configuration | Options | Default | Description |
Parameter Checking |
-
Default (BSP)
-
Enabled
-
Disabled
| Default (BSP) | If selected code for parameter checking is included in the build. |
Multiplex Interrupt |
| Disabled | Enable multiplex interrupt for a single driver. |
Configurations for Analog > ADC (r_tsu_b)
This module can be added to the Stacks tab via New Stack > Analog > ADC (r_tsu_b).
Configuration | Options | Default | Description |
General > Name | Name must be a valid C symbol | g_tsu0 | Module name |
General > Unit | Unit must be a non-negative integer | 0 | Specifies the TSU_B Unit to be used. |
General > Mode | MCU Specific Options | | Select the scan mode. |
General > Average Count |
-
1(Latest read data)
-
2
-
4
-
8
| 1(Latest read data) | Average Count Setting. |
General > Trigger mode | MCU Specific Options | | Select the trigger mode. |
General > ELC Event | MCU Specific Options | | Specifies 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 Value | Value must be between -40 and 125 | 15 | Lower Limit Setting (degrees Celsius). |
Comparison Function > Upper Limit Value | Value must be between -40 and 125 | 25 | Upper Limit Setting (degrees Celsius). |
Interrupts > Callback | Name must be a valid C symbol | NULL | 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 Enable | MCU Specific Options | | Enable or disable the conversion complete interrupt. |
Interrupts > Conversion Complete Interrupt Priority | Value must be between 0 and 30 | 12 | Select the interrupt priority for Conversion complete. |
Interrupts > Comparison Result Interrupt Enable | MCU Specific Options | | Enable or disable the Comparison Result interrupt. |
Interrupts > Comparison Result Interrupt Priority | Value must be between 0 and 30 | 12 | Select the interrupt priority for Comparison Result. |
Clock Configuration
The TSU_B clock is PCLKL.
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.
{
.compare_ref_low = 0,
.compare_ref_high = 0,
.compare_ipl = 12
};
{
.p_callback = tsu_b_callback,
.p_context = NULL,
.p_extend = &g_tsu0_cfg_extend,
.scan_end_irq = VECTOR_NUMBER_TSU0_ADI,
.scan_end_ipl = 12
};
volatile bool scan_complete_flag = false;
{
scan_complete_flag = true;
}
void tsu_b_basic_example (void)
{
uint32_t calibration_data1;
uint32_t calibration_data2;
assert(FSP_SUCCESS == err);
assert(FSP_SUCCESS == err);
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);
}
assert(FSP_SUCCESS == err);
while (!scan_complete_flag)
{
}
uint16_t conversion_result;
assert(FSP_SUCCESS == err);
float 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.
{
.compare_ref_low = 20,
.compare_ref_high = 30,
.compare_irq = VECTOR_NUMBER_TSU0_ADCMPI,
.compare_ipl = 12
};
{
.p_callback = tsu_b_compare_callback,
.p_context = NULL,
.p_extend = &g_tsu0_compare_cfg_extend,
.scan_end_ipl = 12
};
{
(void) p_unused;
uint16_t conversion_result;
float temperature;
}
void tsu_b_compare_example (void)
{
uint32_t calibration_data1;
uint32_t calibration_data2;
assert(FSP_SUCCESS == err);
assert(FSP_SUCCESS == err);
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);
}
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)
{
.compare_ref_low = 0,
.compare_ref_high = 0,
.compare_ipl = 12,
};
{
.p_callback = tsu_b_get_temp_callback,
.p_context = NULL,
.p_extend = &g_tsu0_get_temp_cfg_extend,
.scan_end_irq = VECTOR_NUMBER_TSU0_ADI,
.scan_end_ipl = (12),
};
{
scan_complete_flag = true;
}
volatile bool timer_overflow_flag = false;
{
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];
assert(FSP_SUCCESS == err);
assert(FSP_SUCCESS == err);
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)
{
assert(FSP_SUCCESS == err);
assert(FSP_SUCCESS == err);
}
while (!timer_overflow_flag)
{
}
timer_overflow_flag = false;
assert(FSP_SUCCESS == err);
while (!scan_complete_flag)
{
}
scan_complete_flag = false;
assert(FSP_SUCCESS == err);
err =
&temperature[conversion_count]);
assert(FSP_SUCCESS == err);
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;
if ((TSU_B_EXAMPLE_TEMPERATURE_POSITIVE_ERROR < (Tj - temperature[0])) ||
(TSU_B_EXAMPLE_TEMPERATURE_NEGATIVE_ERROR > (Tj - temperature[0])))
{
__BKPT(0);
}
}
◆ 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_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.
|
◆ R_TSU_B_Open()
Initializes the TSU_B module and applies configurations.
- Return values
-
FSP_SUCCESS | Module is ready for use. |
FSP_ERR_ASSERTION | An input argument is invalid. |
FSP_ERR_ALREADY_OPEN | The instance control structure has already been opened. |
FSP_ERR_IRQ_BSP_DISABLED | A callback is provided, but the interrupt is not enabled. |
FSP_ERR_INVALID_HW_CONDITION | Calibration data is invalid value, so TSU_B is in invalid condition. |
◆ R_TSU_B_ScanCfg()
adc_api_t::scanCfg is not supported.
- Return values
-
FSP_ERR_UNSUPPORTED | Function not supported in this implementation. |
◆ R_TSU_B_ScanStart()
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_SUCCESS | Scan started (software trigger) or hardware triggers enabled. |
FSP_ERR_ASSERTION | An input argument is invalid. |
FSP_ERR_NOT_OPEN | TSU_B is not open. |
FSP_ERR_NOT_INITIALIZED | TSU_B is not initialized. |
FSP_ERR_IN_USE | Another scan is still in progress (software trigger). |
◆ R_TSU_B_ScanGroupStart()
◆ R_TSU_B_ScanStop()
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_SUCCESS | Hardware triggers disabled. |
FSP_ERR_ASSERTION | An input argument is invalid. |
FSP_ERR_NOT_OPEN | TSU_B is not open. |
FSP_ERR_NOT_INITIALIZED | TSU_B is not initialized. |
FSP_ERR_INVALID_MODE | Not valid for software triggers. |
◆ R_TSU_B_StatusGet()
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_SUCCESS | Module status stored in the provided pointer p_status |
FSP_ERR_ASSERTION | An input argument is invalid. |
FSP_ERR_NOT_OPEN | Unit is not open. |
◆ R_TSU_B_Read()
Reads conversion results from a sensor.
- Return values
-
FSP_SUCCESS | Data read into provided p_data. |
FSP_ERR_ASSERTION | An input argument is invalid. |
FSP_ERR_NOT_OPEN | TSU_B is not open. |
FSP_ERR_NOT_INITIALIZED | TSU_B is not initialized. |
◆ R_TSU_B_Read32()
adc_api_t::read32 is not supported.
- Return values
-
FSP_ERR_UNSUPPORTED | Function not supported in this implementation. |
◆ R_TSU_B_Close()
This function ends any scan in progress, disables interrupts, and removes power to the A/D peripheral.
- Return values
-
FSP_SUCCESS | Module closed. |
FSP_ERR_ASSERTION | An input argument is invalid. |
FSP_ERR_NOT_OPEN | Unit is not open. |
◆ R_TSU_B_InfoGet()
Get the calibration data for the sensor.
- Return values
-
FSP_SUCCESS | Information stored in p_adc_info. |
FSP_ERR_ASSERTION | An input argument is invalid. |
FSP_ERR_NOT_OPEN | TSU_B is not open. |
◆ R_TSU_B_Calibrate()
adc_api_t::calibrate is not supported.
- Return values
-
FSP_ERR_UNSUPPORTED | Function not supported in this implementation. |
◆ R_TSU_B_OffsetSet()
adc_api_t::offsetSet is not supported.
- Return values
-
FSP_ERR_UNSUPPORTED | Function not supported in this implementation. |
◆ R_TSU_B_CallbackSet()
Updates the user callback and has option of providing memory for callback structure. Implements adc_api_t::callbackSet
- Return values
-
FSP_SUCCESS | Callback updated successfully. |
FSP_ERR_ASSERTION | A required pointer is NULL. |
FSP_ERR_NOT_OPEN | The control block has not been opened. |
◆ 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_SUCCESS | Data calculate into provided p_temp. |
FSP_ERR_ASSERTION | An input argument is invalid. |
FSP_ERR_NOT_OPEN | TSU_B is not open. |
FSP_ERR_NOT_INITIALIZED | TSU_B is not initialized. |