Peripheral features and how this peripheral works
The computer operating properly (COP) module is used to help software recover from runaway code. It's a free-running down counter that, once enabled, is designed to generate a reset upon reaching zero. Software must periodically service the COP in order to reload the counter and prevent a reset.
Features
- Choice of clock sources for counter, integrated low speed oscillator
- Programmable prescaler to input clock source
- Programmable timeout period= (cop_prescaler*(TIMEOUT + 1)) clock cycles, where TIMEOUT can be from 0x0000 to 0xFFFF
- Programmable window timing to ensure that servicing doesn't occur too soon
- Programmable work enablement under WAIT and STOP mode
- COP timer is disabled while the DSC is in debug mode
- COP will assert different system reset signals according to situation, status could be read out in SIM_RSTAT:
- COP_RST_B, assert when COP counter counts down to zero
- COP_WNDW_RST_B, assert when COP counter is serviced when the count is greater than the WINDOW value
- LOR_RST_B, assert loss of reference reset 128 cycles after loss of reference clock to the PLL is detected
- COP supports interrupt generation:
- Programmable interrupt timing configuration, interrupt can occur when the counter matches interrupt timing configuration when interrupt is enabled.
- COP feature operation write protect, once write protect is enabled, all configured features cannt be changed until reset the module.
How this peripheral works
- Configure the COP features properly, enable COP
- Service periodically to prevent reset event
How this driver is designed to make this peripheral works.
The cop driver provides a structure cop_config_t which contains all the programmable features of COP. The COP_Init() function takes the argument of structure pointer to cop_config_t and configures the COP features, then enable COP. For the most simple user scenarios, only need to provide COP service function to feed the COP timer to avoid reset. But considering user may have some enhanced situation which needs to re-configure the features, such as to re-install timeout value, enable/disable interrupt functionality of COP, several function groups are designed as below:
- Initialization Interfaces The APIs in the functional group is used to initialize COP module.
- COP operation Interfaces The APIs in this functional group allows user to re-configure the COP features and service COP timer.
- Interrupt control Interfaces The APIs in this functional group can be used to enable/disable COP interrupt
How to use this driver
- Sets the COP features by invoking COP_Init()
- Defines the variable in type of cop_config_t. This variable takes 10 Bytes space.
- [Optional] Invokes COP_GetDefaultConfig() function with the pointer of variable which is type of cop_config_t to get the default options.
- Sets the member of the variable which is in type of cop_config_t.
- Invoke COP_Init to set the COP features and enable COP.
- Call to COP service API to feed COP periodically by invoking COP_Refresh()