仿真器XDS100V2,环境CCS5.5
在使用串口中断过程中有一个很奇怪的问题就是明明很简单单的代码就能实现串口中断,一度以为自己的代码出现了问题
结果,不停测试才发现,只有断电-仿真下载-第一次串口中断可以正常运行
第二次第三次就无法中断了.......
不明觉厉,先这么用吧
最后找到问题所在了
https://e2echina.ti.com/question_answer/dsp_arm/c6000_dsp/f/32/t/29536
妈呀
附上串口代码
/****************************************************************************/
/* */
/* 通用异步串口2测试(中断方式) */
/* */
/* 2014年04月20日 */
/* */
/****************************************************************************/
// 注意:DSP ports, Shared RAM, UART0, EDMA, SPI0, MMC/SDs,
// VPIF, LCDC, SATA, uPP, DDR2/mDDR (bus ports), USB2.0, HPI, PRU
// 这些外设使用的时钟来源为 PLL0_SYSCLK2 默认频率为 CPU 频率的二分之一
// 但是,ECAPs, UART1/2, Timer64P2/3, eHRPWMs,McBSPs, McASP0, SPI1
// 这些外设的时钟来源可以在 PLL0_SYSCLK2 和 PLL1_SYSCLK2 中选择
// 通过修改 System Configuration (SYSCFG) Module
// 寄存器 Chip Configuration 3 Register (CFGCHIP3) 第四位 ASYNC3_CLKSRC
// 配置时钟来源
// (默认值) 0 来源于 PLL0_SYSCLK2
// 1 来源于 PLL1_SYSCLK2
// 如果不是为了降低功耗,不建议修改这个值,它会影响所有相关外设的时钟频率
#include "TL6748.h" // 创龙 DSP6748 开发板相关声明
#include "hw_types.h" // 宏命令
#include "hw_syscfg0_C6748.h" // 系统配置模块寄存器
#include "soc_C6748.h" // DSP C6748 外设寄存器
#include "psc.h" // 电源与睡眠控制宏及设备抽象层函数声明
#include "gpio.h" // 通用输入输出口宏及设备抽象层函数声明
#include "uart.h" // 通用异步串口宏及设备抽象层函数声明
#include "interrupt.h" // DSP C6748 中断相关应用程序接口函数声明及系统事件号定义
#include "uart2.h"
/****************************************************************************/
/* */
/* 宏定义 */
/* */
/****************************************************************************/
// 软件断点
#define SW_BREAKPOINT asm(" SWBP 0 ");
// 时钟
#define SYSCLK_1_FREQ (456000000)
#define SYSCLK_2_FREQ (SYSCLK_1_FREQ/2)
#define UART_2_FREQ (SYSCLK_2_FREQ)
/****************************************************************************/
/* */
/* 全局变量 */
/* */
/****************************************************************************/
char txArray[] = "Tronlong UART2 Application......\n\r";
/****************************************************************************/
/* */
/* 函数声明 */
/* */
/****************************************************************************/
/****************************************************************************/
/* */
/* UART 初始化 */
/* */
/****************************************************************************/
void UART2Init(void)
{
// 外设使能配置
PSCModuleControl(SOC_PSC_1_REGS, HW_PSC_UART2, PSC_POWERDOMAIN_ALWAYS_ON, PSC_MDCTL_NEXT_ENABLE);
// UART2 禁用流控
UARTPinMuxSetup(2, FALSE);
// 初始化 DSP 中断控制器
IntDSPINTCInit();
// 使能 DSP 全局中断
IntGlobalEnable();
// 配置 UART2 参数
// 波特率 115200 数据位 8 停止位 1 无校验位
UARTConfigSetExpClk(SOC_UART_2_REGS, UART_2_FREQ, BAUD_115200,
UART_WORDL_8BITS, UART_OVER_SAMP_RATE_16);
// 使能 UART2
UARTEnable(SOC_UART_2_REGS);
// 使能接收 / 发送 FIFO
UARTFIFOEnable(SOC_UART_2_REGS);
// 设置 FIFO 级别
UARTFIFOLevelSet(SOC_UART_2_REGS, UART_RX_TRIG_LEVEL_1);
}
/****************************************************************************/
/* */
/* UART 中断初始化 */
/* */
/****************************************************************************/
void UART2InterruptInit(void)
{
IntRegister(C674X_MASK_INT6, UARTIsr);
IntEventMap(C674X_MASK_INT6, SYS_INT_UART2_INT);
IntEnable(C674X_MASK_INT6);
// 使能中断
unsigned int intFlags = 0;
intFlags |= (UART_INT_LINE_STAT | \
UART_INT_TX_EMPTY | \
UART_INT_RXDATA_CTI);
UARTIntEnable(SOC_UART_2_REGS, intFlags);
}
/****************************************************************************/
/* */
/* UART 中断服务函数 */
/* */
/****************************************************************************/
void UARTIsr()
{
// static unsigned int length = sizeof(txArray);
// static unsigned int count = 0;
unsigned char rxData = 0;
unsigned int int_id = 0;
// 确定中断源
int_id = UARTIntStatus(SOC_UART_2_REGS);
// 清除 UART2 系统中断
IntEventClear(SYS_INT_UART2_INT);
// 发送中断
// if(UART_INTID_TX_EMPTY == int_id)
// {
// if(0 < length)
// {
// // 写一个字节到 THR
// UARTCharPutNonBlocking(SOC_UART_2_REGS, txArray[count]);
// length--;
// count++;
// }
// if(0 == length)
// {
// // 禁用发送中断
// UARTIntDisable(SOC_UART_2_REGS, UART_INT_TX_EMPTY);
// }
// }
// 接收中断
if(UART_INTID_RX_DATA == int_id)
{
rxData = UARTCharGetNonBlocking(SOC_UART_2_REGS);
UARTCharPutNonBlocking(SOC_UART_2_REGS, rxData);
}
// 接收错误
if(UART_INTID_RX_LINE_STAT == int_id)
{
while(UARTRxErrorGet(SOC_UART_2_REGS))
{
// 从 RBR 读一个字节
UARTCharGetNonBlocking(SOC_UART_2_REGS);
}
}
return;
}