Driver for the DOC peripheral on RA MCUs. This module implements the DOC Interface.
Overview
Features
The DOC HAL module peripheral is used to compare, add or subtract 16-bit or 32-bit1 data and can detect the following events:
- Comparison Mode
- Data is equal to the configured reference data setting.
- Data is not equal to the configured reference data setting.
- Data is less than the configured reference data setting2.
- Data is greater than the configured reference data setting2.
- Data is inside of a configurable pair of reference data settings2.
- Data is outside of a configurable pair of reference data settings2.
- Addition Mode - Overflow of an addition operation
- Subtraction Mode - Underflow of a subtraction operation
A user-defined callback can be created to inform the CPU when any of above events occur.
- Note
- 1. Operating on 32-bit data is not supported on all MCUs.
-
2. This comparison mode is not supported on all MCUs.
Supported Devices
| Device Group | Devices |
| RA2 | RA2A1, RA2A2, RA2E1, RA2E2, RA2E3, RA2L1, RA2L2, RA2T1 |
| RA4 | RA4C1, RA4E1, RA4E2, RA4L1, RA4M1, RA4M2, RA4M3, RA4T1, RA4W1 |
| RA6 | RA6E1, RA6E2, RA6M1, RA6M2, RA6M3, RA6M4, RA6M5, RA6T1, RA6T2, RA6T3 |
| RA8 | RA8D1, RA8D2, RA8E1, RA8E2, RA8M1, RA8M2, RA8P1, RA8T1, RA8T2 |
Configuration
Build Time Configurations for r_doc
The following build time configurations are defined in fsp_cfg/r_doc_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. |
Build Time Configurations for r_doc
The following build time configurations are defined in fsp_cfg/r_doc_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. |
Configurations for Monitoring > Data Operation Circuit (r_doc)
This module can be added to the Stacks tab via New Stack > Monitoring > Data Operation Circuit (r_doc). Non-secure callable guard functions can be generated for this module by right clicking the module in the RA Configuration tool and checking the "Non-secure Callable" box.
| Configuration | Options | Default | Description |
| Name | Name must be a valid C symbol | g_doc0 | Module name. |
| Event | MCU Specific Options | | Select the event that will trigger the DOC interrupt. |
| Bit Width | MCU Specific Options | | The bit width for DOC operations. |
| Reference/Initial Data | Value must be an integer greater than or equal to 0. | 0 | Enter Initial Value for Addition/Subtraction or enter reference value for comparison. |
| Additional Reference Data | Value must be an integer greater than or equal to 0. | 0 | Additional reference data used for Window Compare modes. |
| Callback | Name must be a valid C symbol | NULL | A user callback function must be provided. This will be called from the interrupt service routine (ISR) when the configured DOC event occurs. |
| DOC Interrupt Priority | MCU Specific Options | | Select the DOC interrupt priority. |
Configurations for Monitoring > Data Operation Circuit (r_doc)
This module can be added to the Stacks tab via New Stack > Monitoring > Data Operation Circuit (r_doc). Non-secure callable guard functions can be generated for this module by right clicking the module in the RA Configuration tool and checking the "Non-secure Callable" box.
| Configuration | Options | Default | Description |
| Name | Name must be a valid C symbol | g_doc0 | Module name. |
| Event | MCU Specific Options | | Select the event that will trigger the DOC interrupt. |
| Bit Width | MCU Specific Options | | The bit width for DOC operations. |
| Reference/Initial Data | Value must be an integer greater than or equal to 0. | 0 | Enter Initial Value for Addition/Subtraction or enter reference value for comparison. |
| Additional Reference Data | Value must be an integer greater than or equal to 0. | 0 | Additional reference data used for Window Compare modes. |
| Callback | Name must be a valid C symbol | NULL | A user callback function must be provided. This will be called from the interrupt service routine (ISR) when the configured DOC event occurs. |
| DOC Interrupt Priority | MCU Specific Options | | Select the DOC interrupt priority. |
Clock Configuration
The DOC HAL module does not require a specific clock configuration.
Pin Configuration
The DOC HAL module does not require and specific pin configurations.
Usage Notes
DMAC/DTC Integration
DOC can be used with Transfer (r_dmac) or Transfer (r_dtc) to write to the input register without CPU intervention. DMAC is more useful for most DOC applications because it can be started directly from software. To write DOC input data with DTC/DMAC, set transfer_info_t::p_dest to R_DOC->DODIR.
Examples
Basic Example
This is a basic example of minimal use of the R_DOC in an application. This example shows how this driver can be used for continuous 16 bit addition operation while reading the result at every overflow event.
#define DOC_EXAMPLE_VALUE 0xF000
uint32_t g_callback_event_counter = 0;
{
g_callback_event_counter++;
}
void basic_example (void)
{
assert(FSP_SUCCESS == err);
for (int i = 0; i < 5; i++)
{
assert(FSP_SUCCESS == err);
if (g_callback_event_counter >= 1)
{
uint32_t result;
assert(FSP_SUCCESS == err);
}
}
}
◆ R_DOC_Open()
Opens and configures the Data Operation Circuit (DOC) in comparison, addition or subtraction mode and sets initial data for addition or subtraction, or reference data for comparison.
Example:
- Return values
-
| FSP_SUCCESS | DOC successfully configured. |
| FSP_ERR_ALREADY_OPEN | Module already open. |
| FSP_ERR_ASSERTION | One or more pointers point to NULL or callback is NULL or the interrupt vector is invalid. |
◆ R_DOC_Close()
Closes the module driver. Enables module stop mode.
- Return values
-
| FSP_SUCCESS | Module successfully closed. |
| FSP_ERR_NOT_OPEN | Driver not open. |
| FSP_ERR_ASSERTION | Pointer pointing to NULL. |
- Note
- This function will disable the DOC interrupt in the NVIC.
◆ R_DOC_Read()
Returns the result of addition/subtraction.
Example:
uint32_t result;
assert(FSP_SUCCESS == err);
- Return values
-
| FSP_SUCCESS | Status successfully read. |
| FSP_ERR_NOT_OPEN | Driver not open. |
| FSP_ERR_ASSERTION | One or more pointers point to NULL. |
◆ R_DOC_Write()
Writes to the DODIR - DOC Input Register.
Example:
assert(FSP_SUCCESS == err);
- Return values
-
| FSP_SUCCESS | Values successfully written to the registers. |
| FSP_ERR_NOT_OPEN | Driver not open. |
| FSP_ERR_ASSERTION | One or more pointers point to NULL. |
◆ R_DOC_CallbackSet()
Updates the user callback and has option of providing memory for callback structure. Implements doc_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. |
| FSP_ERR_NO_CALLBACK_MEMORY | p_callback is non-secure and p_callback_memory is either secure or NULL. |