DSP

DSPLINK DEMO解析之SCALE【转】

2019-07-13 10:13发布

SCALE 示例阐明了在DSP/BIOS LINK 的数据流和信息的组合,实现了GPP端和DSP端任务间的数据传递,还从GPP端发送信息到DSP端。 -------------------------------------------GPP端------------------------------------------------ SCALE_BufferSize = DSPLINK_ALIGN (SCALE_Atoi (strBufferSize),DSPLINK_BUF_ALIGN) ;  //验证数据缓冲区大小 status = SCALE_Create (dspExecutable,strBufferSize,strNumIterations,processorId) ;     --------PROC_setup()     --------status = PROC_attach (processorId, NULL) ;     --------status = POOL_open (POOL_makePoolId(processorId, SAMPLE_POOL_ID),&poolAttrs) ;       --------status = PROC_load (processorId, dspExecutable, numArgs, args) ;     -------- status = CHNL_create (processorId, CHNL_ID_OUTPUT, &chnlAttrOutput) ;  //创建一个到DSP的channel     -------- status = CHNL_create (processorId, CHNL_ID_INPUT, &chnlAttrInput) ;    //创建一个来自DSP的channel     --------status = CHNL_allocateBuffer (processorId,CHNL_ID_OUTPUT,SCALE_Buffers,SCALE_BufferSize , 1) ;  //为发送数据到DSP端分配缓冲区     --------status = PROC_start (processorId) ;     --------status = MSGQ_transportOpen (processorId, &mqtAttrs) ;    //打开远程传输 status = SCALE_Execute (SCALE_NumIterations, processorId) ;     --------status = MSGQ_locate (SampleDspMsgqName,&SampleDspMsgq,&syncLocateAttrs) ;  //定位DSP的消息队列     --------SCALE_IOReq.buffer = SCALE_Buffers [0] ;    //填充 IO 请求结构         SCALE_IOReq.size = SCALE_BufferSize ;     --------用有效数据初始化缓冲: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 if (DSP_SUCCEEDED (status)) {            ptr8  = (Uint8 *)  (SCALE_IOReq.buffer) ;            ptr16 = (Uint16 *) (SCALE_IOReq.buffer) ;            for (   (j = 0) ;                    (DSP_SUCCEEDED (status))                 && (j < SCALE_BufferSize / DSP_MAUSIZE) ;                     j++ ) {                if (DSP_MAUSIZE == 1) {                    *ptr8 = XFER_CHAR ;                    ptr8++ ;                }                else if (DSP_MAUSIZE == 2) {                    *ptr16 = XFER_CHAR ;                    ptr16++ ;                }            }        }     --------status = CHNL_issue (processorId, CHNL_ID_OUTPUT, &SCALE_IOReq) ;    //向DSP发送数据     --------status = CHNL_reclaim (processorId,CHNL_ID_OUTPUT,WAIT_FOREVER,&SCALE_IOReq) ; //从channel回收空缓冲       --------status = CHNL_issue (processorId, CHNL_ID_INPUT, &SCALE_IOReq) ;  //从DSP端接收数据     --------status = CHNL_reclaim (processorId,CHNL_ID_INPUT,WAIT_FOREVER,&SCALE_IOReq) ; //从channel回收填充缓冲     --------status = SCALE_VerifyData (SCALE_IOReq.buffer) ;     --------SCALE_XferValue++ ;      //改变换算系数         status = MSGQ_alloc (POOL_makePoolId(processorId, SAMPLE_POOL_ID),APP_MSG_SIZE,(MSGQ_Msg *) &msg) ;     --------MSGQ_setMsgId ((MSGQ_Msg) msg, SCALE_REQUEST_MSGID) ;    //发送已经定位的消息         status = MSGQ_put (SampleDspMsgq, (MSGQ_Msg) msg) ;     --------- status = MSGQ_release (SampleDspMsgq) ;    //释放消息队列 SCALE_Delete (processorId) ;     --------status = MSGQ_transportClose (processorId) ;     --------tmpStatus = PROC_stop (processorId) ;     --------tmpStatus = CHNL_freeBuffer (processorId,CHNL_ID_OUTPUT,SCALE_Buffers,1) ;     --------tmpStatus = CHNL_delete  (processorId, CHNL_ID_INPUT) ;     --------tmpStatus = CHNL_delete  (processorId, CHNL_ID_OUTPUT) ;     --------tmpStatus = POOL_close (POOL_makePoolId(processorId, SAMPLE_POOL_ID)) ;     --------tmpStatus = PROC_detach (processorId) ;         -------- tmpStatus = PROC_destroy () ;   -------------------------------------------DSP端------------------------------------------------ SWI MODE DSPLINK_init() status = SWISCALE_create (&info) ;     --------status = POOL_open (0, &poolObj) ;     --------status = DEV_createDevice("/dsplink",&ZCPYDATA_FXNS,(Fxn) &ZCPYDATA_init,&devAttrs) ;  //动态建立IOM驱动     --------status = DEV_createDevice("/dio_dsplink",&DIO_tskDynamicFxns,NULL,&dioDevAttrs);  //动态建立DIO适配器     --------status = MSGQ_transportOpen (ID_GPP,&transport) ;     --------*infoPtr = MEM_calloc (DSPLINK_SEGID,sizeof (SWISCALE_TransferInfo),DSPLINK_BUF_ALIGN) ;  //分配结构体     --------初始化 SWICALE 传输信息结构 1 2 3 4 5 6 7 8 if (status == SYS_OK) {      info->bufferSize        = xferBufSize ;      (info->appReadCb).fxn   = readFinishCb ;      (info->appReadCb).arg   =(Ptr) info ;      (info->appWriteCb).fxn  = writeFinishCb ;      (info->appWriteCb).arg  = (Ptr) info ;      info->scalingFactor     = 1 ;    }     --------建立channel 句柄 1 2 3 4 5 6 7 8 9 10 11 GIO_Attrs gioAttrs = GIO_ATTRS ;    info->gioInputChan = "color: #006600;">GIO_create (INPUT_CHANNEL,                                 IOM_INPUT,                                 NULL,                                 NULL,                                 &gioAttrs) ;    info->gioOutputChan = "color: #006600;">GIO_create (OUTPUT_CHANNEL,                                  IOM_OUTPUT,                                  NULL,                                  NULL,                                  &gioAttrs) ;     ------为发送和接收数据新建 SWI 1 2 3 4 5 6 7 8 9 10 if (status == SYS_OK) {         swiAttrs.fxn        = dataSWI ;         swiAttrs.arg0       = (Arg) info ;         swiAttrs.mailbox    = INITIAL_DATA_MAILBOX_VAL ;         info->swiData = "color: #006600;">SWI_create (&swiAttrs) ;         if (info->swiData == NULL) {             status = SYS_EALLOC ;