High level interface for interacting with reset and delays.
This driver provides three categories of functionality:
Critical section is a portion in the code where all active interrupts are disabled. This is usually provided in places where the code execution must not be disturbed by an interrupt. An example is a firmware controlled communication protocol where timing of each byte must be maintained and any interrupt might cause loss of data.
cyhal_system_critical_section_enter returns the current state of interrupts which denote the active interrupts in the system. This must be passed as argument to cyhal_system_critical_section_exit while exiting the critical section.
cyhal_system_get_reset_reason must be called at the beginning of the main to determine the reason for reset. The return parameters are present in cyhal_reset_reason_t.
Typedefs | |
typedef void(* | cyhal_irq_handler) (void) |
Function pointer for IRQ handlers ( cyhal_system_set_isr). More... | |
Enumerations | |
enum | cyhal_reset_reason_t { CYHAL_SYSTEM_RESET_NONE = 0, CYHAL_SYSTEM_RESET_WDT = 1 << 0, CYHAL_SYSTEM_RESET_ACTIVE_FAULT = 1 << 1, CYHAL_SYSTEM_RESET_DEEPSLEEP_FAULT = 1 << 2, CYHAL_SYSTEM_RESET_SOFT = 1 << 3, CYHAL_SYSTEM_RESET_HIB_WAKEUP = 1 << 4, CYHAL_SYSTEM_RESET_WCO_ERR = 1 << 5, CYHAL_SYSTEM_RESET_SYS_CLK_ERR = 1 << 6, CYHAL_SYSTEM_RESET_PROTECTION = 1 << 7 } |
Flags enum of possible system reset causes. More... | |
Functions | |
uint32_t | cyhal_system_critical_section_enter (void) |
Enter a critical section. More... | |
void | cyhal_system_critical_section_exit (uint32_t old_state) |
Exit a critical section. More... | |
cy_rslt_t | cyhal_system_delay_ms (uint32_t milliseconds) |
Requests that the current operation delays for at least the specified length of time. More... | |
void | cyhal_system_delay_us (uint16_t microseconds) |
Requests that the current operation delay for at least the specified number of micro-seconds. More... | |
cyhal_reset_reason_t | cyhal_system_get_reset_reason (void) |
Gets the cause of the latest reset or resets that occurred in the system. More... | |
void | cyhal_system_clear_reset_reason (void) |
Clears the reset cause registers. More... | |
cy_rslt_t | cyhal_system_set_isr (int32_t irq_num, int32_t irq_src, uint8_t priority, cyhal_irq_handler handler) |
Registers the specified handler as the callback function for the specififed irq_num with the given priority. More... | |
typedef void(* cyhal_irq_handler) (void) |
Function pointer for IRQ handlers ( cyhal_system_set_isr).
enum cyhal_reset_reason_t |
Flags enum of possible system reset causes.
uint32_t cyhal_system_critical_section_enter | ( | void | ) |
Enter a critical section.
Disables interrupts and returns a value indicating whether the interrupts were previously enabled.
See Snippet 1: Critical Section for code snippet on critical section
void cyhal_system_critical_section_exit | ( | uint32_t | old_state | ) |
Exit a critical section.
Re-enables the interrupts if they were enabled before cyhal_system_critical_section_enter() was called. The argument should be the value returned from cyhal_system_critical_section_enter().
[in] | old_state | The state of interrupts from cyhal_system_critical_section_enter() |
See Snippet 1: Critical Section for code snippet on critical section
cy_rslt_t cyhal_system_delay_ms | ( | uint32_t | milliseconds | ) |
Requests that the current operation delays for at least the specified length of time.
If this is running in an RTOS aware environment (COMPONENTS+=RTOS_AWARE) or (DEFINES+=CY_RTOS_AWARE) it will attempt to have the RTOS suspend the current task so others can continue to run. If this is not run under an RTOS it will then defer to the standard system delay which is likely to be a busy loop. If this is part of an application that is build with RTOS awareness, but the delay should not depend on the RTOS for whatever reason, use cyhal_system_delay_us() with the appropriate 1000x multiplier to the delay time.
[in] | milliseconds | The number of milliseconds to delay for |
void cyhal_system_delay_us | ( | uint16_t | microseconds | ) |
Requests that the current operation delay for at least the specified number of micro-seconds.
This will generally keep the processor active in a loop for the specified length of time. If this is running under an RTOS, it will NOT attempt to run any other RTOS tasks, however if the scheduler or a high priority interrupt comes it they can take over anyway.
[in] | microseconds | The number of micro-seconds to delay for |
cyhal_reset_reason_t cyhal_system_get_reset_reason | ( | void | ) |
Gets the cause of the latest reset or resets that occurred in the system.
Refer Snippet 2: Reset reason for code snippet on cyhal_system_get_reset_reason
void cyhal_system_clear_reset_reason | ( | void | ) |
Clears the reset cause registers.
This should be done after calling cyhal_system_get_reset_reason to make sure the reason does not persist between resets.
cy_rslt_t cyhal_system_set_isr | ( | int32_t | irq_num, |
int32_t | irq_src, | ||
uint8_t | priority, | ||
cyhal_irq_handler | handler | ||
) |
Registers the specified handler as the callback function for the specififed irq_num with the given priority.
For devices that mux interrupt sources into mcu interrupts, the irq_src defines the source of the interrupt.
[in] | irq_num | The MCU interrupt number to register the handler for. |
[in] | irq_src | The interrupt source that feeds the MCU interrupt. For devices that have a 1:1 mapping between interrupt sources and MCU interrupts this should be the same as the irq_num. |
[in] | priority | The MCU interrupt priority. |
[in] | handler | The function pointer to call when the interrupt is triggered. |