?? threncode.c
字號:
/*
* Copyright 2002 by Texas Instruments Incorporated.
* All rights reserved. Property of Texas Instruments Incorporated.
* Restricted rights to use, duplicate or disclose this code are
* granted through contract.
*
*/
/*
* ======== thrProcess.c ========
* This file contains the main processing thread.
* A captured and preprocessed QCIF image is expected from the
* capture thread. Then the image will be sent to the 2 "live"
* and 2 "diff" channels for processing.
*/
// DSP/BIOS includes
#include <std.h>
#include <stdio.h>
#include <sts.h>
#include <string.h>
// DSP/BIOS includes
#include <tsk.h>
#include <csl_dat.h>
#include <csl_cache.h>
#include <csl_mcbsp.h>
#include <csl_edma.h>
// CSL modules
#include <csl_dat.h>
#include <csl_cache.h>
// RF5 module includes
#include <chan.h>
#include <icell.h>
#include <scom.h>
#include <icc_linear.h>
#include <utl.h>
// cell includes
#include "encode/cellH264encode.h"
// application includes
#include "appResources.h" // application-wide common info
// Thread include
#include "thrProcess.h"
#include "appMain.h"
#define PIOLEN 0x8000
extern int codNum;
extern uint8_t *pputdata,*pgetdata,*data_tag1,*data_tag2;
/*********Audio**********/
extern unsigned short *pAudioEncBuf;//???????
extern unsigned short *pAudioDecBuf;//???????
/*
* Thread process object which encapsulates the state information
* of the thread.
*/
#pragma DATA_SECTION(piosendbuf,".EXTPROCBUFF");
#pragma DATA_ALIGN(piosendbuf, MEMALIGN);
uint8_t piosendbuf[PIOLEN*2];
#pragma DATA_SECTION(pbuf, ".INTPROCBUFF");
uint8_t *pbuf[2];
#pragma DATA_SECTION(edma_flag, ".INTPROCBUFF");
#pragma DATA_SECTION(send_flag, ".INTPROCBUFF");
int32_t edma_flag=0;
int32_t send_flag=0;
volatile int buf_full[2]={0,0};
EDMA_Handle hEdma1;
EDMA_Config edmaconf;
EDMA_Handle hEdmadummy;
MCBSP_Handle hMcbsp;
void captureEDMA(void);
inline void setinit_edma(void);
#pragma DATA_SECTION(ybuffCap, ".EXTPROCBUFF");
#pragma DATA_SECTION(crbuffCap, ".EXTPROCBUFF");
#pragma DATA_SECTION(cbbuffCap, ".EXTPROCBUFF");
#pragma DATA_ALIGN(ybuffCap, MEMALIGN);
#pragma DATA_ALIGN(crbuffCap, MEMALIGN);
#pragma DATA_ALIGN(cbbuffCap, MEMALIGN);
/*
* Thread process object which encapsulates the state information
* of the thread.
*/
ThrProcess thrProcess;
// Buffers for SCOM
static Char ybuffCap [ PROCF_SIZE_IN_PIXELS ];
static Char crbuffCap[ PROCF_SIZE_IN_PIXELS >> 2 ];
static Char cbbuffCap[ PROCF_SIZE_IN_PIXELS >> 2 ];
static SCOM_Handle scomReceiveFromCapture;
static SCOM_Handle scomSendToCapture;
// Local function prototypes
static Void setParamsAndStartChannels( Bool doChannelOpen );
//static Void checkMsg();
Void Movedata(int i);
Void HWI_DSP_to_Host();
Void param_control();
/*
* ======== thrProcessInit ========
*
*/
Void thrProcessInit()
{
// create named SCOM queues for receiving messages from other tasks
scomReceiveFromCapture
= SCOM_create( "scomToProcessFromCapture", &SCOM_ATTRS );
UTL_assert( scomReceiveFromCapture != NULL);
//Allocate appropriate addresses for SCOM buffers
thrProcess.scombufCap.bufYCRCB[Y] = ybuffCap;
thrProcess.scombufCap.bufYCRCB[CR] = crbuffCap;
thrProcess.scombufCap.bufYCRCB[CB] = cbbuffCap;
// thrProcess.enc_buf = &bitBuf[0];
setParamsAndStartChannels( FALSE );
}
/*
* ======== thrProcessStartup ========
*
*/
Void thrProcessStartup()
{
Bool rc;
Uns chanNum;
// Open the channel
for (chanNum = 0; chanNum < NUMCOMBOCHANS; chanNum++)
{
UTL_logDebug1("Process: Combo Channel Number: %d", chanNum);
rc = CHAN_open( &thrProcess.comboChans[chanNum],
&thrProcess.comboCells[chanNum * CHCOMBONUMCELLS],
CHCOMBONUMCELLS, NULL );
}
UTL_assert( rc == TRUE );
}
/*
* ======== setParamsAndStartChannels ========
*
*/
static Void setParamsAndStartChannels( Bool doChannelOpen )
{
IENC_Params h264encParams;
ICC_Handle inputIcc;
ICC_Handle outputIcc;
Uns chanNum;
ICELL_Handle cell;
h264encParams = IENC_PARAMS;
// -------------------------------------
// Combo Channels (DIFF and then ROTATE)
// -------------------------------------
for (chanNum = 0; chanNum < NUMCOMBOCHANS; chanNum++)
{
ICELL_Obj defaultCell = ICELL_DEFAULT;
cell = &thrProcess.comboCells[ chanNum * CHCOMBONUMCELLS ];
*cell = defaultCell;
cell->name = "H264Encode";
cell->cellFxns = &H264ENC_CELLFXNS;
//x cell->algFxns = (IALG_Fxns *)&H264ENC_IH264ENC;
cell->algParams = (IALG_Params *)&h264encParams;
cell->scrBucketIndex = VIDEOPROCSCRBUCKET;
inputIcc = (ICC_Handle)ICC_linearCreate( NULL, 0);
UTL_assert( inputIcc != NULL);
outputIcc = (ICC_Handle)ICC_linearCreate( thrProcess.enc_buf,
sizeof(PROCF_SIZE_IN_PIXELS));
UTL_assert( outputIcc != NULL);
CHAN_regCell ( cell, &inputIcc, 1, &outputIcc, 1 );
}
}
/*
* ======== thrProcessRun ========
*
* Main function of Process Thread.
*/
Void thrEncodeRun()
{
CHAN_Handle chan;
int i;
int least;
int wait;
int32_t len,len_all;
int32_t poff[2]={0,0};
MCBSP_Config ConfigLoopback = {
MCBSP_SPCR_RMK(
MCBSP_SPCR_FREE_DEFAULT,
MCBSP_SPCR_SOFT_DEFAULT,
MCBSP_SPCR_FRST_DEFAULT,//YES,// /* Frame sync not reset */
MCBSP_SPCR_GRST_DEFAULT,
MCBSP_SPCR_XINTM_XRDY, /* XINT driven by XRDY */
MCBSP_SPCR_XSYNCERR_DEFAULT,
MCBSP_SPCR_XRST_DEFAULT,//YES,//
MCBSP_SPCR_DLB_OFF, /* Digital Loopback Mode enabled */
MCBSP_SPCR_RJUST_RZF, /* Right-justify and zero-fill MSBs in DRR */
MCBSP_SPCR_CLKSTP_DEFAULT,
MCBSP_SPCR_DXENA_OFF,
MCBSP_SPCR_RINTM_RRDY, /* RINT driven by RRDY */
MCBSP_SPCR_RSYNCERR_DEFAULT,
MCBSP_SPCR_RRST_DEFAULT//YES//
),
MCBSP_RCR_RMK(
MCBSP_RCR_RPHASE_SINGLE, /* Single phase frame */
MCBSP_RCR_RFRLEN2_DEFAULT,
MCBSP_RCR_RWDLEN2_DEFAULT,
MCBSP_RCR_RCOMPAND_MSB, /* No companding */
MCBSP_RCR_RFIG_YES, /* Ignore unexpected sync pulses */
MCBSP_RCR_RDATDLY_1BIT, /* 0-bit delay */
MCBSP_RCR_RFRLEN1_OF(0), /* 1 word per phase */
MCBSP_RCR_RWDLEN1_32BIT, /* 32-bit receive element length */
MCBSP_RCR_RWDREVRS_DISABLE
),
MCBSP_XCR_RMK(
MCBSP_XCR_XPHASE_SINGLE, /* Single phase frame */
MCBSP_XCR_XFRLEN2_DEFAULT,
MCBSP_XCR_XWDLEN2_DEFAULT,
MCBSP_XCR_XCOMPAND_MSB, /* No companding */
MCBSP_XCR_XFIG_YES, /* Ignore unexpected sync pulses */
MCBSP_XCR_XDATDLY_1BIT, /* 0-bit delay */
MCBSP_XCR_XFRLEN1_OF(0), /* 1 word per phase */
MCBSP_XCR_XWDLEN1_32BIT, /* 32-bit receive element length */
MCBSP_XCR_XWDREVRS_DISABLE
),
MCBSP_SRGR_RMK(
MCBSP_SRGR_GSYNC_DEFAULT,
MCBSP_SRGR_CLKSP_DEFAULT,
// MCBSP_SRGR_CLKSM_DEFAULT, /* srg clock derived internally */
MCBSP_SRGR_CLKSM_INTERNAL,
MCBSP_SRGR_FSGM_DXR2XSR,
// MCBSP_SRGR_FSGM_FSG,
// MCBSP_SRGR_FSGM_DEFAULT,
MCBSP_SRGR_FPER_DEFAULT,
MCBSP_SRGR_FWID_DEFAULT,
// MCBSP_SRGR_CLKGDV_DEFAULT
MCBSP_SRGR_CLKGDV_OF(39)
),
MCBSP_MCR_DEFAULT,
MCBSP_RCERE0_DEFAULT,
MCBSP_RCERE1_DEFAULT,
MCBSP_RCERE2_DEFAULT,
MCBSP_RCERE3_DEFAULT,
MCBSP_XCERE0_DEFAULT,
MCBSP_XCERE1_DEFAULT,
MCBSP_XCERE2_DEFAULT,
MCBSP_XCERE3_DEFAULT,
MCBSP_PCR_RMK(
MCBSP_PCR_XIOEN_DEFAULT,
MCBSP_PCR_RIOEN_DEFAULT,
MCBSP_PCR_FSXM_INTERNAL,//EXTERNAL, /* EXTERNAL frame sync signals used */
MCBSP_PCR_FSRM_EXTERNAL,//,INTERNAL /* EXTERNAL frame sync signals used */
MCBSP_PCR_CLKXM_OUTPUT,//INPUT,
MCBSP_PCR_CLKRM_INPUT,
MCBSP_PCR_CLKSSTAT_DEFAULT,
MCBSP_PCR_DXSTAT_DEFAULT,
MCBSP_PCR_FSXP_ACTIVEHIGH,
MCBSP_PCR_FSRP_ACTIVEHIGH,
MCBSP_PCR_CLKXP_RISING,
MCBSP_PCR_CLKRP_FALLING//RISING
)
};
// int first=0;
hMcbsp = MCBSP_open(MCBSP_DEV1, MCBSP_OPEN_RESET);
// MCBSP_config(hMcbsp,&ConfigLoopback);
// MCBSP_enableSrgr(hMcbsp);
// for(i=0;i<0x30;i++);
pbuf[0]=piosendbuf; pbuf[1]=piosendbuf+PIOLEN;
setinit_edma();
hEdma1 = EDMA_open(EDMA_CHA_XEVT1, EDMA_OPEN_RESET);
edmaconf.opt=
EDMA_OPT_RMK(
EDMA_OPT_PRI_HIGH,
EDMA_OPT_ESIZE_32BIT,
EDMA_OPT_2DS_NO,
EDMA_OPT_SUM_INC,
EDMA_OPT_2DD_NO,
EDMA_OPT_DUM_NONE,
EDMA_OPT_TCINT_YES, //=1
EDMA_OPT_TCC_OF(14),
EDMA_OPT_TCCM_DEFAULT,
EDMA_OPT_ATCINT_DEFAULT,
EDMA_OPT_ATCC_DEFAULT,
EDMA_OPT_PDTS_DEFAULT,
EDMA_OPT_PDTD_DEFAULT,
EDMA_OPT_LINK_NO,
EDMA_OPT_FS_NO
);
// edmaconf.src=EDMA_SRC_RMK((Uint32)(pputdata));
// edmaconf.cnt=EDMA_CNT_RMK(0,0);
edmaconf.cnt=(PIOLEN>>2);
edmaconf.dst=EDMA_DST_RMK(MCBSP_ADDRH(hMcbsp, DXR));
edmaconf.idx=EDMA_IDX_RMK(0,0);
edmaconf.rld=EDMA_RLD_RMK(0,0);
#if HAS_ENC
// UTL_logDebug1("thrEncodeRun: task = 0x%x", TSK_self());
// printf("thrEncodeRun begin\n");
// open SCOM queues for sending messages to other tasks
scomSendToCapture = SCOM_open( "scomCapture" );
UTL_assert( scomSendToCapture != NULL);
//Clear Capture and Display SCOM buffers
memset(ybuffCap, 0x00, PROCF_SIZE_IN_PIXELS);
memset(crbuffCap, 0x80, PROCF_SIZE_IN_PIXELS >> 2);
memset(cbbuffCap, 0x80, PROCF_SIZE_IN_PIXELS >> 2);
// put the Rx message on the SCOM queue for Capture thread
SCOM_putMsg( scomSendToCapture, &thrProcess.scombufCap );
_amem4(pputdata)=0xffffffff;
// Main loop
while (TRUE)
{
ScomCapToProc *scombufCap;
Int chanNum;
Bool rc;
thrProcess.enc_buf = (Char *)enc_Buf[0];
// get the message describing full input buffers from Capture
scombufCap = SCOM_getMsg(scomReceiveFromCapture, SYS_FOREVER);
//Execute all combo channels
for (chanNum = 0; chanNum < NUMCOMBOCHANS; chanNum++)
{
chan = &(thrProcess.comboChans[chanNum]);
ICC_setBuf(chan->cellSet[CHCOMBOCELLENC].inputIcc[0],
scombufCap->bufYCRCB, 0);
ICC_setBuf(chan->cellSet[CHCOMBOCELLENC].outputIcc[0],
thrProcess.enc_buf, 0);
UTL_stsStart( stsExeTimeChCombo );
rc = CHAN_execute( &thrProcess.comboChans[ chanNum ], NULL );
// HWI_DSP_to_Host();
memcpy(&len,enc_Buf[0],4);
if(len<0 || len>=(PIOLEN-0x15c)) len = 0;
len_all = len + 0x154;
len_all=(((len_all+7)>>2)<<2);
printf("len_all=%d\n",len_all);
memcpy(pputdata+4,&len_all,4); //len//
memcpy(pputdata+8,pAudioEncBuf,0x150); //audio
memcpy(pputdata+0x158,enc_Buf[0],len+4);//video
codNum = 0;
CACHE_wbL2(data_tag1,DATALEN,CACHE_WAIT);
//CACHE_clean(CACHE_L2,data_tag1,DATALEN);
//DAT_copy();
if((PIOLEN-poff[send_flag])>=(len_all+8))
{
memcpy((void*)(pbuf[send_flag]+poff[send_flag]),pputdata,len_all+8);
poff[send_flag]=poff[send_flag]+len_all+8;
if(PIOLEN==poff[send_flag])
{
/// while(0==EDMA_intTest(14));
edmaconf.src=EDMA_SRC_RMK((Uint32)(pbuf[send_flag]));
// EDMA_intClear(14);
buf_full[send_flag]=1;
// EDMA_disableChannel(hEdma1);
//MCBSP_reset(hMcbsp);
poff[send_flag]=0;
// ???;
while(1==buf_full[send_flag^1]);
EDMA_disableChannel(hEdma1);
//MCBSP_reset(hMcbsp);
MCBSP_close(hMcbsp);
hMcbsp = MCBSP_open(MCBSP_DEV1, MCBSP_OPEN_RESET);
MCBSP_config(hMcbsp,&ConfigLoopback);
MCBSP_enableSrgr(hMcbsp);
for(wait=0;wait<0x4f;wait++);
EDMA_config(hEdma1,&edmaconf);
EDMA_enableChannel(hEdma1);
/* McBSP port 0 as the transmitter */
// MCBSP_enableFsync(hMcbsp); /* Enable frame sync for the McBSP */
MCBSP_enableXmt(hMcbsp);
send_flag=(send_flag+1)&1;
}
}
else //if(0==buf_full[send_flag^1])
{
memcpy((void*)(pbuf[send_flag]+poff[send_flag]),pputdata,PIOLEN-poff[send_flag]);
edmaconf.src=EDMA_SRC_RMK((Uint32)(pbuf[send_flag]));
buf_full[send_flag]=1;
least=len_all+8-PIOLEN+poff[send_flag];
while(1==buf_full[send_flag^1]);
EDMA_disableChannel(hEdma1);
// MCBSP_reset(hMcbsp);
MCBSP_close(hMcbsp);
hMcbsp = MCBSP_open(MCBSP_DEV1, MCBSP_OPEN_RESET);
memcpy((void*)pbuf[send_flag^1],pputdata+PIOLEN-poff[send_flag],least);
poff[send_flag]=0;
// ???;
//
MCBSP_config(hMcbsp,&ConfigLoopback);
MCBSP_enableSrgr(hMcbsp);
for(wait=0;wait<0x4f;wait++);
EDMA_config(hEdma1,&edmaconf);
EDMA_enableChannel(hEdma1);
/* McBSP port 0 as the transmitter */
// MCBSP_enableFsync(hMcbsp); /* Enable frame sync for the McBSP */
MCBSP_enableXmt(hMcbsp);
send_flag=(send_flag+1)&1;
poff[send_flag]=least;
}
UTL_assert( rc == TRUE );
UTL_stsStop( stsExeTimeChCombo );
TSK_yield();
}
// send the message describing consumed input buffers to Capture
SCOM_putMsg( scomSendToCapture, scombufCap );
}
#endif
}
inline void setinit_edma(void)
{
IRQ_nmiEnable();
IRQ_globalEnable();
// IRQ_reset(IRQ_EVT_EDMAINT);
//IRQ_disable(IRQ_EVT_EDMAINT);
IRQ_map(IRQ_EVT_EDMAINT, 8);
HWI_dispatchPlug(8, (Fxn)EDMA_intDispatcher, -1, NULL);
EDMA_disableChannel(14);
EDMA_clearChannel(14);
EDMA_enableChannel(14);
EDMA_intClear(14);
EDMA_intEnable(14);
EDMA_intHook(14, captureEDMA);
IRQ_enable(IRQ_EVT_EDMAINT);
}
void captureEDMA(void)
{
EDMA_intClear(14);
buf_full[edma_flag]=0;
EVMDM642_wait(60000);
edma_flag=(edma_flag+1)&1;
//
//EDMA_disableChannel(hEdma1);
//MCBSP_reset(hMcbsp);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -