为你袖手天下 https://passport2.21ic.com/?1214394 [收藏] [复制] [RSS]

日志

DSP的SCI的使用-FIFO

已有 1406 次阅读2015-6-18 11:04 |系统分类:兴趣爱好

以下是对TI官方例程的SCI的理解:
void main(void) {
    Uint16 SendChar;        //定义为要发送的变量

// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP2833x_SysCtrl.c file.
    InitSysCtrl();               //系统时钟初始化

// Step 2. Initialize GPIO:
// This example function is found in the DSP2833x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
    // InitGpio(); Skipped for this example

// For this example, only init the pins for the SCI-A port.
// This function is found in the DSP2833x_Sci.c file.
    InitScibGpio();                         //对SCIB的GPIO进行初始化,SCIB的GPIO口对应MUX,GPIO18和GPIO19进行配置

// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
    DINT;                                      //关闭CPU各中断

// Initialize PIE control registers to their default state.
// The default state is all PIE interrupts disabled and flags
// are cleared.
// This function is found in the DSP2833x_PieCtrl.c file.
    InitPieCtrl();                              //PIE中断级初始化                     

// Disable CPU interrupts and clear all CPU interrupt flags:
    IER = 0x0000;                                    
    IFR = 0x0000;                              //清除各种中断标志

// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
// This will populate the entire table, even if the interrupt
// is not used in this example.  This is useful for debug purposes.
// The shell ISR routines are found in DSP2833x_DefaultIsr.c.
// This function is found in DSP2833x_PieVect.c.

    InitPieVectTable();                     //中断舍量表初始化

// Step 4. Initialize all the Device Peripherals:
// This function is found in DSP2833x_InitPeripherals.c
// InitPeripherals(); // Not required for this example

// Step 5. User specific code:

    LoopCount = 0;
    ErrorCount = 0;

    Scib_fifo_init();                                                  // 初始化SCI FIFO
    Scib_echoback_init();                        

    for (;;) {

#if SCIB                                                             //如果SCIB=1则执行如下语句
        while (ScibRegs.SCIFFRX.bit.RXFFST == 0); // SCIFFRX寄存器,8~12位为RXFFST,RXFFST=00000,接收FIFO为空,00001接收FIFO有一个字,以此类
                                                                         //推; 等待有数据的时候开始往下执行

        SendChar = ScibRegs.SCIRXBUF.all;         //有数据过来,总线上接收到的数据传送到SendChar中,
        Scib_xmit(SendChar);                                //接着通过Scib_xmit函数送出接收到的数据
        while (ScibRegs.SCIFFTX.bit.TXFFST != 0) ;//判断传送是否完成,等待传送完成
#elif SCIC
        while(ScicRegs.SCIFFRX.bit.RXFFST == 0); // wait for RRDY/RXFFST =1 for 1 data available in FIFO
        SendChar = ScicRegs.SCIRXBUF.all;
        Scic_xmit(SendChar);
        while(ScicRegs.SCIFFTX.bit.TXFFST != 0);
#elif SCIA
        while(SciaRegs.SCIFFRX.bit.RXFFST == 0);  // wait for RRDY/RXFFST =1 for 1 data available in FIFO
        SendChar = SciaRegs.SCIRXBUF.all;
        Scia_xmit(SendChar);
        while(SciaRegs.SCIFFTX.bit.TXFFST != 0);

#endif
    }
}

// Test 1,Scib  DLB, 8-bit word, baud rate 0x000F, default, 1 STOP bit, no parity  //8位字,波特率9600,默认设置,1个停止位,没有奇偶校验位
void Scib_echoback_init() {
    // Note: Clocks were turned on to the Scib peripheral
    // in the InitSysCtrl() function

    ScibRegs.SCICCR.all = 0x0007;   // 1 stop bit,  No loopback
                                    // No parity,8 char bits,
                                    // async mode, idle-line protocol
    ScibRegs.SCICTL1.all = 0x0003;  // enable TX, RX, internal SCICLK,
                                    // Disable RX ERR, SLEEP, TXWAKE
    ScibRegs.SCICTL2.all = 0x0003;
    ScibRegs.SCICTL2.bit.TXINTENA = 1;
    ScibRegs.SCICTL2.bit.RXBKINTENA = 1;
#if (CPU_FRQ_150MHZ)                                                                   //选择性的,当频率为150Mhz,选择如下的方式
    ScibRegs.SCIHBAUD = 0x0001;  // 9600 baud @LSPCLK = 37.5MHz.
    ScibRegs.SCILBAUD = 0x00E7;
#endif
#if (CPU_FRQ_100MHZ)
    ScibRegs.SCIHBAUD =0x0001;  // 9600 baud @LSPCLK = 20MHz.
    ScibRegs.SCILBAUD =0x0044;
#endif
    ScibRegs.SCICTL1.all = 0x0023;  // Relinquish SCI from Reset
}

// Transmit a character from the SCI
void Scib_xmit(int a) {
    ScibRegs.SCITXBUF = a;
}

// Initialize the SCI FIFO
void Scib_fifo_init() {
    ScibRegs.SCIFFTX.all = 0xE040;
    ScibRegs.SCIFFRX.all = 0x204f;
    ScibRegs.SCIFFCT.all = 0x0;
}

所谓的FIFO就是先进先出的意思。SCI工作在FIFO模式下一般是因为所传输的信息并不是以一个帧为单位,而是以多个帧组成的一个包为信息单位的。
比如说我的一个数据包由5个帧组成,第一个为控制字节,后四个字节共同组成一个浮点数。这时你可以设置FIFO接收中断为5个字节时产生中断。
设置以后,每接收到5个字节后才会产生一次中断,而不是每接收一次产生一次中断。这样可以大幅减小CPU的开销。而先进先出的意思就是:在中断中,
你读FIFO接收寄存器读到的数据是首先接收到的数据,再读一次的话读到的是接收到的第二个数据。而16深度的话就是最多能保存最近的16个接收数据,
如果接收数据超过16个的话会产生相应的溢出,可以软件编程对溢出进行处理。

FIFO主要是可以将需要接收或者发送的数据进行打包处理,可以设置一次要接收或者发送的数据的多少,最多16个;普通模式下,一般没接收或者发送
一个字节就需要进行判断,进入中断执行中断程序,所以通过FIFO功能可以大幅的减少CPU的使用,提高效率。(个人理解)



路过

鸡蛋

鲜花

握手

雷人

评论 (0 个评论)