📄 txhostcomm.c
字号:
/*****************************************************************************
Module : Host Communication (DSP-PC)
******************************************************************************
Function : Contains the initialization, functions and tasks to provide
the communication with the host.
Procedures : tskHostComm()
Author : $Author: Maxime $
Revision : $Revision: 10 $
Modified : $Modtime: 21/05/05 14:11 $
File : $Workfile: txhostcomm.c $
******************************************************************************
KTH, Royal Institute of Technology, S3, Stockholm
*****************************************************************************/
/*--- Include files --------------------------------------------------------*/
/* import */
#include <std.h>
#include <csl_stdinc.h>
#include <log.h>
#include <tsk.h>
#include <rtdx.h>
#include <sem.h>
#include "transmittercfg.h"
#include "../common/commondef.h"
#include "txmain.h"
#include "dsk6713_led.h"
/* export */
#include "txhostcomm.h"
/*=== End of include files =================================================*/
/*--- Global variables definition ------------------------------------------*/
typTXHST_HOSTCOMMSTATE HostCommState;
/*=== End of global variables definition ===================================*/
/*--- Global constants definition ------------------------------------------*/
/*=== End of global constants definition ===================================*/
/*--- Local defines --------------------------------------------------------*/
/*=== End of local defines =================================================*/
/*--- Local types declaration ----------------------------------------------*/
/*=== End of local types declaration =======================================*/
/*--- Local variables definition -------------------------------------------*/
static typTXHST_eHostCommState CommState;
static unsigned int arraycrtl[INITLEN];
static unsigned int arraydata[DATABURSTLEN];
/*=== End of local variables definition ====================================*/
/*--- Local constants definition -------------------------------------------*/
/*=== End of local constants definition ====================================*/
/*--- Local functions definition -------------------------------------------*/
/*=== End of local functions definition ====================================*/
/*--- Global functions definition ------------------------------------------*/
/****************************************************************************
Function : tskHostComm
****************************************************************************
Description : State machine for communication with the host
Inputs : None
Outputs : None
By : 2005-05-19 Maxime Maury
****************************************************************************/
void tskHostComm()
{
unsigned int uiNbrDataBursts; // Number of data bursts
unsigned int uiCrtl; // Value sent to the transmitter host
char* pFileBuffer = HostCommState.pDataBuff; // Relative pointer to the file data section
int iStatus; // RTDX status
int p; // Data burst index
unsigned int uiTurbo; // Turbo = 1: Download and send at the same time
char cExitLoop;
unsigned int uiLastFrameNbr;
HostCommState.cTransReady = 0; // The number of frames is not set
HostCommState.cNewFrameReady = 0; // The processed frame number has not changed
while(1)
{
switch(CommState) {
case eTXHST_IDLE:
#ifdef _RTDXDEBUGLOG
LOG_printf(&trace,"Comm: Idle state");
#endif
// Asynchronous read
iStatus = RTDX_readNB( &ichancrtl, arraycrtl, sizeof(arraycrtl) );
if ( iStatus != RTDX_OK ) {
#ifdef _RTDXDEBUGLOG
LOG_printf(&trace,"ERROR: RTDX_readNB failed!");
#endif
exit(EXIT_RTDX_READ_FAILED);
}
CommState = eTXHST_WAITING;
break;
case eTXHST_WAITING:
iStatus = RTDX_channelBusy( &ichancrtl );
#ifdef _RTDXDEBUGLOG
LOG_printf(&trace,"Comm: Waiting state %d",iStatus);
#endif
if (!iStatus) // A value has been read from the host
CommState = eTXHST_GETPARAMS;
TSK_sleep(1);
break;
case eTXHST_GETNBRFRAMES:
#ifdef _RTDXDEBUGLOG
LOG_printf(&trace,"Comm: GetNbrFrames State");
#endif
if (SEM_pend(&sem, SYS_FOREVER)== FALSE)
{
#ifdef _RTDXDEBUGLOG
LOG_printf(&trace,"SEM_pend failed");
#endif
}
if (HostCommState.cTransReady)
{
HostCommState.cTransReady = 0;
iStatus = RTDX_write( &ochancrtl, HostCommState.piuNoOfBlocks, sizeof(*(HostCommState.piuNoOfBlocks)) );
if ( iStatus == 0 ) {
#ifdef _RTDXDEBUGLOG
LOG_printf(&trace,"ERROR: RTDX_write failed!");
#endif
exit(EXIT_RTDX_WRITE_FAILED);
}
while ( RTDX_writing != NULL ) {
#if RTDX_POLLING_IMPLEMENTATION
RTDX_Poll();
#endif
TSK_sleep(1);
}
CommState = (uiTurbo) ? eTXHST_TRANSMITTFILE : eTXHST_GETSTATUS;
}
break;
case eTXHST_GETSTATUS:
#ifdef _RTDXDEBUGLOG
LOG_printf(&trace,"Comm: GetStatus State");
#endif
if (SEM_pend(&sem, SYS_FOREVER)== FALSE)
{
#ifdef _RTDXDEBUGLOG
LOG_printf(&trace,"SEM_pend failed");
#endif
}
if (HostCommState.cNewFrameReady)
{
HostCommState.cNewFrameReady = 0;
iStatus = RTDX_write( &ochancrtl, HostCommState.puiFrameNbr, sizeof(*(HostCommState.puiFrameNbr)) );
if ( iStatus == 0 ) {
#ifdef _RTDXDEBUGLOG
LOG_printf(&trace,"ERROR: RTDX_write failed!");
#endif
exit(EXIT_RTDX_WRITE_FAILED);
}
while ( RTDX_writing != NULL )
{
#if RTDX_POLLING_IMPLEMENTATION
RTDX_Poll();
#endif
TSK_sleep(1);
}
}
// End of transmission
if (*(HostCommState.pTxState) == eTX_TERMINATION)
CommState = eTXHST_IDLE;
break;
case eTXHST_GETPARAMS:
DSK6713_LED_on(1);
if (arraycrtl[0] & 1)
*(HostCommState.pTxMode) = eCOM_MIMO;
else
*(HostCommState.pTxMode) = eCOM_SISO;
*(HostCommState.piSyncRep) = arraycrtl[1];
*(HostCommState.puiFileSize) = arraycrtl[2];
uiNbrDataBursts = arraycrtl[3];
uiTurbo = arraycrtl[4];
#ifdef _RTDXDEBUGLOG
LOG_printf(&trace,"SysSelection = %d was received from the host", *(HostCommState.pTxMode));
LOG_printf(&trace,"SyncInterval = %d was received from the host", *(HostCommState.piSyncRep));
LOG_printf(&trace, "FileSize = %d was received from the host", *(HostCommState.puiFileSize) );
LOG_printf(&trace, "NbrDataBursts = %d was received from the host", uiNbrDataBursts );
LOG_printf(&trace, "Turbo = %d was received from the host", uiTurbo );
#endif
// Send back to the host
uiCrtl = uiNbrDataBursts;
iStatus = RTDX_write( &ochancrtl, &uiCrtl, sizeof(uiCrtl) );
if ( iStatus == 0 ) {
#ifdef _RTDXDEBUGLOG
LOG_printf(&trace,"ERROR: RTDX_write failed!");
#endif
exit(EXIT_RTDX_WRITE_FAILED);
}
while ( RTDX_writing != NULL )
{
#if RTDX_POLLING_IMPLEMENTATION
RTDX_Poll();
#endif
TSK_sleep(1);
}
CommState = eTXHST_TRANSMITTFILE;
break;
case eTXHST_TRANSMITTFILE:
#ifdef _RTDXDEBUGLOG
LOG_printf(&trace,"Reception of the data...!");
#endif
cExitLoop = 0;
p = 1;
//for (p=1;p<=uiNbrDataBursts;p++)
while(!cExitLoop)
{
if (p<=uiNbrDataBursts)
{
DSK6713_LED_toggle(1);
#ifdef _RTDXDEBUGLOG
LOG_printf(&trace,"RTDX Reading!");
#endif
iStatus = RTDX_readNB( &ichandata, arraydata, sizeof(arraydata) );
iStatus = 1;
while(iStatus)
{
iStatus = RTDX_channelBusy( &ichandata );
#if RTDX_POLLING_IMPLEMENTATION
RTDX_Poll();
#endif
TSK_sleep(1);
}
DSK6713_LED_toggle(1);
iStatus = RTDX_write( &ochancrtl, &p, sizeof(p) );
while ( RTDX_writing != NULL ) {
#if RTDX_POLLING_IMPLEMENTATION
RTDX_Poll();
#endif
TSK_sleep(1);
}
if ( iStatus == 0 ) {
#ifdef _RTDXDEBUGLOG
LOG_printf(&trace,"ERROR: RTDX_write failed!");
#endif
exit(EXIT_RTDX_WRITE_FAILED);
}
memcpy(pFileBuffer, arraydata, DATABURSTLEN*sizeof(int));
pFileBuffer += DATABURSTLEN*sizeof(int);
}
if (uiTurbo) // If accelerated mode
{
if (p==DELAYTURBOMODE)
{
// Starting the transmission over the air
*(HostCommState.pTxState) = eTX_STARTTX;
// Setup EDMA transfer
startEdma();
// Send the number of frames
while(!HostCommState.cTransReady)
TSK_sleep(1);
HostCommState.cTransReady = 0;
iStatus = RTDX_write( &ochancrtl, HostCommState.piuNoOfBlocks, sizeof(*(HostCommState.piuNoOfBlocks)) );
if ( iStatus == 0 ) {
#ifdef _RTDXDEBUGLOG
LOG_printf(&trace,"ERROR: RTDX_write failed!");
#endif
exit(EXIT_RTDX_WRITE_FAILED);
}
while ( RTDX_writing != NULL ) {
#if RTDX_POLLING_IMPLEMENTATION
RTDX_Poll();
#endif
TSK_sleep(1);
}
}
// Pend if nothing to download
if (p>uiNbrDataBursts)
{
if (SEM_pend(&sem, SYS_FOREVER)== FALSE)
{
#ifdef _RTDXDEBUGLOG
LOG_printf(&trace,"SEM_pend failed");
#endif
}
}
while (!HostCommState.cNewFrameReady)
TSK_sleep(1);
HostCommState.cNewFrameReady = 0;
uiLastFrameNbr = *(HostCommState.puiFrameNbr);
iStatus = RTDX_write( &ochancrtl, HostCommState.puiFrameNbr, sizeof(*(HostCommState.puiFrameNbr)) );
if ( iStatus == 0 ) {
#ifdef _RTDXDEBUGLOG
LOG_printf(&trace,"ERROR: RTDX_write failed!");
#endif
exit(EXIT_RTDX_WRITE_FAILED);
}
while ( RTDX_writing != NULL )
{
#if RTDX_POLLING_IMPLEMENTATION
RTDX_Poll();
#endif
TSK_sleep(1);
}
}
p++;
if (p>uiNbrDataBursts)
if (!uiTurbo)
cExitLoop = 1;
else
cExitLoop = (uiLastFrameNbr==*(HostCommState.piuNoOfBlocks));
}
#ifdef _RTDXDEBUGLOG
LOG_printf(&trace,"Transmission Complete!");
#endif
if (!uiTurbo)
{
// Starting the transmission over the air
*(HostCommState.pTxState) = eTX_STARTTX;
// Setup EDMA transfer
startEdma();
#ifdef _RTDXDEBUGLOG
LOG_printf(&trace,"start transmission in txhostcomm");
#endif
CommState = eTXHST_GETNBRFRAMES;
}
else
{
// End of transmission
if (*(HostCommState.pTxState) == eTX_TERMINATION)
CommState = eTXHST_IDLE;
}
DSK6713_LED_off(1);
break;
default:
#ifdef _RTDXDEBUGLOG
LOG_printf(&trace,"Comm: Defaut state");
#endif
break;
}
TSK_yield();
}
}
/****************************************************************************
Function : tskHostCommInitialize
****************************************************************************
Description : Enable the RTDX channels
Inputs : None
Outputs : None
By : 2005-05-14 Maxime Maury
****************************************************************************/
void tskHostCommInitialize()
{
/* enable the output channel */
RTDX_enableOutput( &ochancrtl );
/* enable the output channel */
RTDX_enableOutput( &ochandata );
/* enable the input channel */
RTDX_enableInput( &ichancrtl );
/* enable the intput channel */
RTDX_enableInput( &ichandata );
CommState = eTXHST_IDLE;
#ifdef _DEBUGLOG
LOG_printf(&trace,"RTDX channels enabled!");
#endif
}
/*=== End of global functions definition ===================================*/
/*--- AUTOMATICALLY GENERATED VERSION HISTORY --------------------------------
$Log: /MIMO/Transmitter/txhostcomm.c $
*
* 10 21/05/05 14:14 Maxime
* Turbo Mode implemented (simultaneous downloading & sending)
*
* 9 20/05/05 18:39 Maxime
* Bug SISO/MIMO fixed
*
* 8 20/05/05 12:27 Maxime
* Added GETPARAMS state
*
* 7 05-05-20 12:22 Adrian
* added LED function calls to indicate a file transfer with LED 1
*
* 6 05-05-20 9:15 Adrian
* included txmain.h because typTX_eTxState is now declared there
*
* 5 19/05/05 11:58 Maxime
* Added semaphores in the eTXHST_GETSTATUS and eTXHST_GETNBRFRAMES.
*
* 4 05-05-17 16:36 Adrian
* Error codes for exit() added.
*
* 3 05-05-17 10:29 Adrian
* Added basic synchronization with semaphores (needs to be refined).
*
* 2 05-05-16 19:13 Maxime
* Implementation of the communication function
*
* 1 05-05-11 14:50 Adrian
* created and added to VSS
===== END OF AUTOMATICALLY GENERATED VERSION HISTORY =======================*/
/**** End of file ***********************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -