为了寻找ping-pong操作样例,搜VisualDSP自带的代码例子,在 Blackfin\Examples\ADSP-BF533 EZ-KIT Lite\AD9244 ADC (C)\main.c中有如下一段代码,从注释看好像是说信号量能够使得程序等待,例子程序中也没有判断dma数据已经操作过的代码,但我测试下来并不能等待。
请问,如何利用semphore 挂起程序等待中断?
Software: VisualDSP++4.5
Hardware: BF533 EZ-KIT Board Rev 1.1
Extender Card Rev. 1.3
AD9244 Evaluation Board
#include "system.h"
#include "sysreg.h"
#include "ccblkfn.h"
// semaphore to indicate that a half has been transmitted
short DMA_completed_Receive = 0;
// store IMAKS register when interrupts are disabled
int interruptLatch;
Ping_Pong = 0;
DMA_completed_Receive = 0;
// configure the programmable flags (for debug)
//initFlags();
// initialise Hardware
//InitPPI(); // enable PPI (will start only after an impulse on PF2)
//InitInterrupts();
int x=0;
// MAIN loop
// waits indefinetely for interrupts from DMA 这句话是说会在信号量上持续等待吧?
// When an interrupt has occured, the flag indicates which half of the received data the main loop can process
while(1) {
// sync to interrupt through semaphore
asm("cli %0;" : "=d" (interruptLatch)); asm("ssync;");
// Check for the semaphore, and process if semaphore indicates completion
if (DMA_completed_Receive == 1) {
DMA_completed_Receive = 0; // reset the semaphore
} // if
asm("sti %0;" : : "d" (interruptLatch)); asm("ssync;");
// insert interruptible code here
// variable Ping_Pong indicates which half is "free"
// for instance: copy to buffer for display 这里面没有判断已经处理过,不需要再次处理的代码
*pFIO_FLAG_S = 0x0001; // PF0 shows execution time of this loop
for (i=(Ping_Pong * Number_of_ADC_channels * Number_of_Samples); i<(((Ping_Pong+1) * Number_of_ADC_channels * Number_of_Samples)); i++)
ADC_data[i] = sPPI_RxBuffer[i];
printf("%d ",x++); //我增加这段代码,注释掉中断函数中的DMA_completed_Receive = 1;注释掉main()中的//initFlags();//InitPPI();//InitInterrupts();调用,仍然会持续不断的吐数据,证明程序没有挂起等待 (最上面注释中说的 waits indefinetely for interrupts from DMA)
*pFIO_FLAG_C = 0x0001; // PF0 shows execution time of this loop
}
}
输出:
Load complete.
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66.....
「该帖子被 bh99 在 2013-05-05 22:09:36 编辑过」