您的位置: OpenADSP社区论坛 -> Blackfin专区 -> 新手上路 -> 如何利用semphore 挂起程序等待中断?
本帖共有614个阅读者
发表帖子 发表投票 回复主题
如何利用semphore 挂起程序等待中断?
bh99(论坛新手)
bh99
头衔:社区公民
帮派:无帮无派
帖数:25
金钱:337
积分:41
注册时间:2012/4/24
楼主信息 | 留言 | Email | 主页 | 编辑 | 管理 | 离线
如何利用semphore 挂起程序等待中断?

为了寻找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 编辑过」

这家伙很懒,什么也没有留下!
等级:论坛新手 参考IP地址:*.*.*.*
2013/5/5 21:36:42
尊贵身份标志
andy(论坛版主)
andy
头衔:社区公民
帮派:无帮无派
帖数:2287
金钱:11132
积分:2263
注册时间:2011/6/8
1信息 | 留言 | Email | 主页 | 编辑 | 管理 | 离线
不看你帖子了,看你这么执着,给你一个简单的乒乓机制的代码,自己研究吧。

这家伙很懒,什么也没有留下!
等级:论坛版主 参考IP地址:*.*.*.*
2013/5/6 0:12:35
bh99(论坛新手)
bh99
头衔:社区公民
帮派:无帮无派
帖数:25
金钱:337
积分:41
注册时间:2012/4/24
2信息 | 留言 | Email | 主页 | 编辑 | 管理 | 离线

多谢andy!


这家伙很懒,什么也没有留下!
等级:论坛新手 参考IP地址:*.*.*.*
2013/5/6 15:04:13
Powered by OpenADSP Copyright © 2010 www.Openadsp.com. All rights reserved.159206 Call, 1 Queries, Processed in 0.015625 second(s),