libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
|
Configuring interrupts from the UART More...
Functions | |
void | uart_enable_interrupts (uint32_t uart, enum uart_interrupt_flag ints) |
Enable Specific UART Interrupts. More... | |
void | uart_disable_interrupts (uint32_t uart, enum uart_interrupt_flag ints) |
Enable Specific UART Interrupts. More... | |
void | uart_enable_rx_interrupt (uint32_t uart) |
Enable the UART Receive Interrupt. More... | |
void | uart_disable_rx_interrupt (uint32_t uart) |
Disable the UART Receive Interrupt. More... | |
void | uart_enable_tx_interrupt (uint32_t uart) |
Enable the UART Transmit Interrupt. More... | |
void | uart_disable_tx_interrupt (uint32_t uart) |
Disable the UART Transmit Interrupt. More... | |
void | uart_clear_interrupt_flag (uint32_t uart, enum uart_interrupt_flag ints) |
Mark interrupt as serviced. More... | |
static bool | uart_is_interrupt_source (uint32_t uart, enum uart_interrupt_flag source) |
Determine if interrupt is generated by the given source. More... | |
Configuring interrupts from the UART
To have an event generate an interrupt, its interrupt source must be unmasked. This can be achieved with uart_enable_interrupts(). Interrupts which are no longer needed can be disabled through uart_disable_interrupts().
In order for the interrupt to generate an IRQ and a call to the interrupt service routine, the interrupt for the target UART must be routed through the NVIC with nvic_enable_irq(). For this last step, the nvic.h header is needed:
Enabling an interrupt is as simple as unmasking the desired interrupt, and routing the desired UART's interrupt through the NVIC.
If a more than one interrupt is to be enabled at one time, the interrupts can be enabled by a single call to uart_enable_interrupts(). For example:
After interrupts are properly enabled and routed through the NVIC, when an event occurs, the appropriate IRQ flag is set by hardware, and execution jumps to the UART ISR. The ISR should query the IRQ flags to determine which event caused the interrupt. For this, use uart_is_interrupt_source(), with the desired UART_INT flag. After one or more interrupt sources are serviced, the IRQ flags must be cleared by the ISR. This can be done with uart_clear_interrupt_flag().
A typical UART ISR may look like the following:
void uart_clear_interrupt_flag | ( | uint32_t | uart, |
enum uart_interrupt_flag | ints | ||
) |
Mark interrupt as serviced.
After an interrupt is services, its flag must be cleared. If the flag is not cleared, then execution will jump back to the start of the ISR after the ISR returns.
[in] | uart | UART block register address base UART register base addresses |
[in] | ints | Interrupts which to clear. Any combination of interrupts may be specified by OR'ing then together |
Definition at line 508 of file uart.c.
References UART_ICR.
void uart_disable_interrupts | ( | uint32_t | uart, |
enum uart_interrupt_flag | ints | ||
) |
Enable Specific UART Interrupts.
Disabe any combination of interrupts. Interrupts may be OR'ed together to disable them with one call. For example, to disable both the RX and CTS interrupts, pass (UART_INT_RX | UART_INT_CTS)
[in] | uart | UART block register address base UART register base addresses |
[in] | ints | Interrupts which to disable. Any combination of interrupts may be specified by OR'ing then together |
Definition at line 446 of file uart.c.
References UART_IM.
Referenced by uart_disable_rx_interrupt(), and uart_disable_tx_interrupt().
void uart_disable_rx_interrupt | ( | uint32_t | uart | ) |
Disable the UART Receive Interrupt.
[in] | uart | UART block register address base UART register base addresses |
Definition at line 469 of file uart.c.
References uart_disable_interrupts(), and UART_INT_RX.
void uart_disable_tx_interrupt | ( | uint32_t | uart | ) |
Disable the UART Transmit Interrupt.
[in] | uart | UART block register address base UART register base addresses |
Definition at line 492 of file uart.c.
References uart_disable_interrupts(), and UART_INT_TX.
void uart_enable_interrupts | ( | uint32_t | uart, |
enum uart_interrupt_flag | ints | ||
) |
Enable Specific UART Interrupts.
Enable any combination of interrupts. Interrupts may be OR'ed together to enable them with one call. For example, to enable both the RX and CTS interrupts, pass (UART_INT_RX | UART_INT_CTS)
Note that the NVIC must be enabled and properly configured for the interrupt to be routed to the CPU.
[in] | uart | UART block register address base UART register base addresses |
[in] | ints | Interrupts which to enable. Any combination of interrupts may be specified by OR'ing then together |
Definition at line 430 of file uart.c.
References UART_IM.
Referenced by uart_enable_rx_interrupt(), and uart_enable_tx_interrupt().
void uart_enable_rx_interrupt | ( | uint32_t | uart | ) |
Enable the UART Receive Interrupt.
Note that the NVIC must be enabled and properly configured for the interrupt to be routed to the CPU.
[in] | uart | UART block register address base UART register base addresses |
Definition at line 459 of file uart.c.
References uart_enable_interrupts(), and UART_INT_RX.
void uart_enable_tx_interrupt | ( | uint32_t | uart | ) |
Enable the UART Transmit Interrupt.
Note that the NVIC must be enabled and properly configured for the interrupt to be routed to the CPU.
[in] | uart | UART block register address base UART register base addresses |
Definition at line 482 of file uart.c.
References uart_enable_interrupts(), and UART_INT_TX.
|
inlinestatic |
Determine if interrupt is generated by the given source.
[in] | uart | UART block register address base UART register base addresses |
[in] | source | source to check. |
Definition at line 540 of file uart.h.
References UART_MIS.