所有关于电路

了解arm cortex 4处理器的中断双使能寄存器逻辑

Y

线程启动

yef史密斯

2020年8月2日加入
191
您好,在示例代码中我们有nvic_clearpendingirq(usart0_tx_irqn);
从手册第220页开始启用USART_TX中断。
但在之后的代码中

代码:
//启用发送缓冲区级别中断usart_intable (USART_IEN_TXBL);
这意味着启用启用TXBL标志。
看来我们两次都能做同样的事,
两个启用之间的区别是什么,为什么我们需要启用两次?
1603472145260. png
https://www.silabs.com/content/user...earmcortexm4manualih-jz8g/cortex m4 guide.pdf.


代码:
#include“em_device.h”#include“em_chip.h”#include“em_mu.h”#include“em_cpio.h”#include“em_usart.h”#include“bsp.h”//接收数据的缓冲区的大小#define buflen 80 //接收数据缓冲区UINT8_T缓冲器[BUFLEN];//当前位置INS BUFFER UINT32_T INPOS = 0;UINT32_T OUTPOS = 0;//在接收数据时(等待Cr或Buflen字符)BOOL接收= TRUE;/ ************************************************************************** // ** * @brief * gpio初始化******************************************************************************* / void initgpio(void){cmu_clockenable(cmuclock_gpio,true);//将VCOM发送引脚配置为板控制器作为输出GPIO_PINMODEET(BSP_BCC_TXPORT,BSP_BCC_TXPIN,GPIOMODEPUSHPULL,1);//从电路板控制器配置VCOM再次引脚作为输入GPIO_PINMODEET(BSP_BCC_RXPORT,BSP_BCC_RXPIN,GPIOMODEINPUT,0);//启用VCOM连接到板控制器GPIO_PINMODEET(BSP_BCC_ENABLE_PORT,BSP_BCC_ENABLE_PIN,GPIOMODEPUSHPULL,1); } /**************************************************************************//** * @brief * USART0 initialization (VCOM on xG1/xG12/xG13 boards) *****************************************************************************/ void initUsart0(void) { CMU_ClockEnable(cmuClock_USART0, true); // Default asynchronous initializer (115.2 Kbps, 8N1, no flow control) USART_InitAsync_TypeDef init = USART_INITASYNC_DEFAULT; // Configure and enable USART0 USART_InitAsync(USART0, &init); // Enable NVIC USART sources NVIC_ClearPendingIRQ(USART0_RX_IRQn); NVIC_EnableIRQ(USART0_RX_IRQn); NVIC_ClearPendingIRQ(USART0_TX_IRQn); NVIC_EnableIRQ(USART0_TX_IRQn); USART0->ROUTEPEN |= USART_ROUTEPEN_RXPEN | USART_ROUTEPEN_TXPEN; } void USART0_RX_IRQHandler(void) { // Get the character just received buffer[inpos] = USART0->RXDATA; // Exit loop on new line or buffer full if ((buffer[inpos] != '\r') && (inpos < BUFLEN)) inpos++; else receive = false; // Stop receiving on CR // Clear the requesting interrupt before exiting the handler USART_IntClear(USART0, USART_IF_RXDATAV); } /**************************************************************************//** * @brief * The USART0 transmit interrupt outputs characters. *****************************************************************************/ void USART0_TX_IRQHandler(void) { // Send a previously received character if (outpos < inpos) USART0->TXDATA = buffer[outpos++]; else /* * Need to disable the transmit buffer level interrupt in this IRQ * handler when done or it will immediately trigger again upon exit * even though there is no data left to send. */ { receive = true; // Go back into receive when all is sent USART_IntDisable(USART0, USART_IEN_TXBL); } // Clear the requesting interrupt before exiting the handler USART_IntClear(USART0, USART_IF_TXBL); } /**************************************************************************//** * @brief * Main function *****************************************************************************/ int main(void) { uint32_t i; // Chip errata CHIP_Init(); // Initialize GPIO and USART0 initGpio(); initUsart0(); while (1) { // Zero out buffer for (i = 0; i < BUFLEN; i++) buffer[i] = 0; // Enable receive data valid interrupt USART_IntEnable(USART0, USART_IEN_RXDATAV); // Wait in EM1 while receiving to reduce current draw while (receive) EMU_EnterEM1(); // Disable receive data valid interrupt USART_IntDisable(USART0, USART_IEN_RXDATAV); // Enable transmit buffer level interrupt USART_IntEnable(USART0, USART_IEN_TXBL); // Wait in EM1 while transmitting to reduce current draw while (!receive) EMU_EnterEM1(); // Reset buffer indices inpos = outpos = 0; } }
最后的编辑:

McKenney.

2018年11月10日加入
115
一个外设通常有许多中断源,这些中断源被组合在一起以触发对NVIC的单个请求。在这种情况下,能够在外设中启用一些而不是其他,然后分别配置(union) NVIC请求是有意义的。这不是必需的,但是它避免了大量的向量项。

在这种情况下,他们似乎配置设计了他们的USART外设来将每个中断源直接传递给NVIC,这也是很好的。你同样可以问是否NVIC_EnableIRQ是冗余的,但NVIC是Cortex-M4的一部分,所以(据我所知)他们不能摆脱它。

[编辑:小的措辞变化]
len_galasso

len_galasso

2020年7月13日加入
1
这是一个良好实践的例子,它将防止以后出现虚假的中断。前者片段清除NVIC中的任何锁存中断从源(在这种情况下USART发射器fifo空),这可能已经从电源上活跃,或自最后初始化序列。后者的代码在其源上启用中断。最后一步(没有显示)是在NVIC中启用中断。

如果没有执行这个额外的步骤,那么一旦NVIC中启用了中断,就可能导致一个立即中断(上面的锁存中断)。这似乎是多余的,但并非如此。
线程启动 类似的线程 论坛 回复 日期
无线射频设计 6
Zazas321. 编程语言 9
J 通用电子聊天 8
Zazas321. 微控制器 5
upand_at_them. 电力电子 7