⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 copy.c

📁 DSP内核代码
💻 C
字号:
/*
*********************************************************************
copy的文件程序文档说明
* 程序名: copy.c
* 目的:从数据输入管道中读取数据,并将数据写入输出管道
* 主要使用了HST,PIP模块以及SWI模块
*********************************************************************
*/

#include <std.h>

#include <hst.h>
#include <pip.h>
#include <swi.h>
#include <log.h>

#include "copycfg.h"

Void inputReady(Void);      /*输入通道input的通知函数,查看具体函数定义*/
Void outputReady(Void);     /*输出通道output的通知函数,查看具体函数定义*/

static Void error(Void);      /* error函数,发生错误时调用,查看具体函数定义*/

/*
*= = = = = = = = = =main= = = = = = = = = = = =
*/

Void main(Int argc, String argv[])
{

LOG_printf(&trace, "Copy example started.");
                    /*进入了idle循环,此时CPU有能力(或时间)执行IDL线程,主机通道才能够使用*/
    return;                 
}

/*
*= = = = = = = = = =copy= = = = = = = = = = = =
*/

Void copy(HST_Obj *input, HST_Obj *output) /*软件中断copySwi调用的函数*/
{
    PIP_Obj     *in, *out;
    Uns        *src, *dst;
    Uns         size;
    
    in = HST_getpipe(input);            /*获得数据输入管道的句柄*/
out = HST_getpipe(output);          /*获得数据输出管道的句柄*/
                                          /*得到了数据管道句柄之后,应用程
序才可以调用PIP模块的API函数
来完成数据的读出和写入*/

if (PIP_getReaderNumFrames(in) == 0 || PIP_getWriterNumFrames(out) == 0) {
error();    /*PIP_getReaderNumFrames(in)指数据输入管道中包含多
少数据帧(装满数据的帧),PIP_getWriterNumFrames(out)
指数据管道中可以写入数据的空帧的数量,如果两者其中
任一个为0,那么调用error函数*/
    }

    PIP_get(in);          /*从输入管道中取得一个数据帧*/
    PIP_alloc(out);        /*从输出管道中分配一个空帧*/

   
    src = PIP_getReaderAddr(in);/*返回从输入管道中得到的数据帧的首地址*/
    dst = PIP_getWriterAddr(out);  /*返回数据帧写入的起始地址指针,此函数一般在PIP_alloc()分配了一个空帧之后调用*/

    size = PIP_getReaderSize(in);    /*返回数据帧中可读数据的数量*/
    PIP_setWriterSize(out, size);   /*返回可以写入的数据的数量;对数据输出管道写入数据时,调用此函数来确定最多能有多少字写进数据帧*/

    for (; size > 0; size--) {       
        *dst++ = *src++;         /*复制输入数据到输出管道中*/
    }


    PIP_put(out);                     /*将写满的数据帧放到输出数据管道中*/
    PIP_free(in);                     /*输入管道中的数据读取完成,释放数据帧*/
}
/*
*= = = = = = = = = =error= = = = = = = = = = = =
*/

static Void error(Void)
{
    LOG_printf(&trace, "Error: copy signal falsely triggered!");
    
    for (;;) {
        ;                   /*错误发生后,不停的进行循环*/
    }
}

/*
*= = = = = = = = = =inputReady= = = = = = = = = = = =
*/

Void inputReady(Void)             /*输入管道数据传送完毕时,此函数自动执行*/
{

     SWI_andn(&copySwi, 1);        /*清除了邮箱最后一位的值*/

}

/*
*= = = = = = = = = =outputReady= = = = = = = = = = = =
*/
Void outputReady(Void)             /*输出管道数据传送完毕时,此函数自动执行*/
{

     SWI_andn(&copySwi, 2);        /*清除了邮箱第二位的值,并启动
软件中断copySwi,转到函数copy线程,同时恢复邮箱初始值3*/

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -