📄 initiator.c
字号:
/*********************************************************************
* *
* Software License Agreement *
* *
* The software supplied herewith by Microchip Technology *
* Incorporated (the "Company") for its dsPIC controller *
* is intended and supplied to you, the Company's customer, *
* for use solely and exclusively on Microchip dsPIC *
* products. The software is owned by the Company and/or its *
* supplier, and is protected under applicable copyright laws. All *
* rights are reserved. Any use in violation of the foregoing *
* restrictions may subject the user to criminal sanctions under *
* applicable laws, as well as to civil liability for the breach of *
* the terms and conditions of this license. *
* *
* THIS SOFTWARE IS PROVIDED IN AN "AS IS" CONDITION. NO *
* WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, *
* BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND *
* FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE *
* COMPANY SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, *
* INCIDENTAL OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. *
* *
*********************************************************************/
/******************************************************************************
**
** Filename: Initiator.c
**
** System: RISC
**
** Platform: dsPIC33F
**
** Description: This file contains only Initiator.This is used to synchronise
** the data Tx and Rx between the two boards.
**
******************************************************************************/
#include <p33Fxxxx.h>
#include "G711Lib_common.h"
#include "G711Lib_si3000.h"
#include "G711Lib_internal.h"
//************************External Variables*********************************//
//User defined ping pong buffers.
extern short buffer1[NUMOFSAMPLESPERBLOCK]; //sampleIpBuffer.
extern short buffer2[NUMOFSAMPLESPERBLOCK]; //sampleOpBuffer.
extern short expandbuffer1[NUMOFSAMPLESPERBLOCK]; //sampleExpandIpBuffer
extern short expandbuffer2[NUMOFSAMPLESPERBLOCK]; //sampleExpandOpBuffer
extern short buffer11[NUMOFSAMPLESPERBLOCK]; //sampleComprsIpBuffer.
extern short buffer12[NUMOFSAMPLESPERBLOCK]; //sampleComprsOpBuffer.
extern volatile unsigned int Txcount, RXcount;
extern volatile unsigned int fRxCpl,fRxstart,fRxstop;
void Initiator ( void )
{
/*---------------------------------------------------------------------------
Local Variables
----------------------------------------------------------------------------*/
volatile char fVal =0x00;
if ( fRxstop == 1)
{
IFS0bits.U1RXIF = 0x00; //Clear Rx interrupt flag
IEC0bits.U1RXIE = 0x00; //Disable Rx ISR processing
_U2RXIF = 0x00; //Clear Rx interrupt flag
IEC1bits.U2RXIE = 0x00; //Disable Rx ISR processing
/* stop sampling speech data from SI 3000 codec. */
libSi3000StopSampling ( );
/* Reset to Initial Conditions */
codecdata.sampleExpandIpBuffer = 0x0000;
codecdata.sampleExpandOpBuffer = 0x0000;
codecdata.sampleIpBuffer = 0x0000;
codecdata.sampleOpBuffer = 0x0000;
codecdata.sampleComprsIpBuffer = 0x0000;
codecdata.sampleComprsOpBuffer = 0x0000;
codecdata.fBlockdone = 0x00;
codecdata.fStartPlay = 0x00;
codecdata.blockCount = 0x0000;
codecdata.loadblockCount = 0x0000;
codecdata.countFill = 0x0000;
codecdata.countLoad = 0x0000;
codecdata.fBlockplayed = 0x01;
codecdata.fCompressdone = 0x00;
/* Reset Flags to Initial conditions */
fRxCpl = 0;
Txcount = 0;
RXcount = 0;
fRxstart = 0;
fRxstop = 0;
}
if ( codecdata.initiator == 1 )
{
//-------------------------------------------------------------------------
// Master
//-------------------------------------------------------------------------
while ( 1 )
{
while ( !U2STAbits.TRMT );
U2TXREG = 0x05; //Transmit 5.
asm ( "repeat #2100" );
asm ( "nop" );
U2STAbits.OERR = 0x00;
if ( U2STAbits.URXDA ) //Read received data.
fVal = U2RXREG;
if ( fVal == 0x10 ) //Check if the Rx data is 10.
{
while ( !U2STAbits.TRMT );
U2TXREG = 0x08; //Transmit 8.
asm ( "repeat #1000" ); //Wait till 8 reaches other end.
asm ( "nop" );
fVal = 0x00;
break;
}
}
}
//---------------------------------------------------------------------------
// Slave
//---------------------------------------------------------------------------
else
{
while ( 1 )
{
U2STAbits.OERR = 0x00;
if ( U2STAbits.URXDA ) //Read the data.
fVal = U2RXREG;
if ( fVal == 0x05 ) //Check for 5.
{
while ( U2STAbits.UTXBF );
U2TXREG = 0x10; //Transmit 10.
there: fVal = 0x00;
U2STAbits.OERR = 0x00;
while ( !U2STAbits.URXDA );
fVal = U2RXREG;
if ( fVal == 0x08 ) //Check for 8.
{
fVal = 0;
break;
}
goto there; //If 8 not Received loop.
}
}
}
IFS1bits.U2RXIF = 0x00; //Clear Rx interrupt flag.
IEC1bits.U2RXIE = 0x01; //Enable Rx interrupt.
/* Start SI3000 Sampling */
libSi3000StartSampling ( buffer1, buffer2,expandbuffer1,expandbuffer2,\
buffer11, buffer12 );
libStartPlay ( );
}
/*-----------------------------------------------------------------------------
END OF FILE: Initiator .c
-----------------------------------------------------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -