📄 libsi3000init.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: libSi3000Init.c
**
** System: RISC
**
** Platform: dsPIC33F
**
** Description: This file contains the API libSi3000Init().This API
** initializes the DCI on dsPIC30F device and also the SI 3000
** codec connected to it based on the settings provided by the
** user through spxSi3000 structure.
**
******************************************************************************/
#include <p33Fxxxx.h>
#include "G711Lib_common.h"
#include "G711Lib_Si3000.h"
#include "G711Lib_internal.h"
/******************************************************************************
**
** FunctionName: libSi3000Init ( )
**
** Description: This API initializes the DCI and SI 3000 codec registers
** based on settings provided by the user through structure.
** Here DCI module can be made either Slave or Master. It
** accesses members of the dci structure for initializing the
** above said registers.It has no outputs.
******************************************************************************/
void libSi3000Init ( void )
{
unsigned int temp1,temp2; //Temporary variables.
if ( g711.dcimode == 1 )
{
/*-----------------------------------------------------------------------------
Cofiguration of DCI peripheral for setting up SI 3000 codec Registers.
-----------------------------------------------------------------------------*/
DCICON1 = 0x0000; //Ensure DCI module is placed in known
DCICON2 = 0x0000; //state.
DCICON3 = 0x0000;
TSCON = 0x0000;
RSCON = 0x0000;
_TRISF6 = 0x01; //Make codec reset switch port pin as
//inputfor now.Ensure port pins are
//setcorrectly (Not really required
//since DCI takes control of it's pins)
TRISG = 0x5000; //CSDI pin configured for input
//COFS output to Si3000 in DCI Master
//mode CSCK output to Si3000
DCICON1 = 0x0040; //Set for multichannel frame sync mode
//Data tx/rx begins 1clock afterFs pulse
//Data changes on rising, sampled on
//falling Tristate output CSDO pin
//when not txing Frame sync
//generated by dsPIC DCI
//Clock is output from DCI
//Ensure module is disabled for now
DCICON2 = 0x04EF; //Data word size is 16-bits (bits 3:0)
//Data frame is 8 words (bits 8:5)
//Set buffer length control (2data words
//Will be buffered between interrupts)
DCICON3 = g711.bcg1; //Initialize DCI bit clock generator
RSCON = 0x0001; //Set receive slot 1 enable RSCON
TSCON = 0x0001; //Set transmit slot 1 enable TSCON
_DCIIF = 0x00; //Ensure DCI interrupt flag is resetIFS2
_DCIIE = 0x00; //ISR processing is disabled for nowIEC2
/*-----------------------------------------------------------------------------
Setup of SI 3000 codec through DCI peripheral on dsPIC30F device.
-----------------------------------------------------------------------------*/
TXBUF0 = PLUS_ONE_WITH_SECONDARY; //Load TXBUF0 with a value that
//requests a secondary frame
TXBUF1 = (WRITE_PLL1_DIVIDE_N1|g711.pLL1divideN1);
//Load TXBUF1 with a value that will
//initiate a WRITE to PLL Divide Control
//Register 3 in the Si3000.
_RF6 = 0x00; //Synchronize DCI with Si3000to
//ensure first frame synce is
//aligned with TXBUF0.
//This is not really required
//when the DCI is Master and
//Codec is the Slave but is
//required when the Codecis the
//Master and DCI is the Slave.
asm("nop");
_TRISF6 = 0x00; //Reset codec
asm("repeat #40"); //Transmit a minimum pulse
asm("nop"); //width of 5uS
_TRISF6 = 0x01; //Release codec
_DCIEN = 0x1; //Enable DCI module
//This ensures the first primary
//and secondary frame use data
//loaded already into TXBUF0
//and TXBUF1
while ( ! _TMPTY ); //Wait until TXBUF0 and TXBUF1
//have been movedto their shadow
//registers for transmission
TXBUF0 = PLUS_ONE_WITH_SECONDARY; //Load TXBUF0 with a value that
//requests a secondary frame
TXBUF1 = (WRITE_PLL1_MULTIPLY_M1 | g711.pLL1multiplyM1);
//Load TXBUF1 with avalue that will ini-
//tiate aWRITE to PLL Multiply Register4
while( ! _TMPTY ); //Wait until TXBUF0 and TXBUF1
//have been moved to their shadow
//registers for transmission
TXBUF0 = PLUS_ONE_WITH_SECONDARY; //Load TXBUF0 with a value that
//requests a secondary frame
TXBUF1 = (WRITE_CONTROL_1 | g711.control1);
//Load TXBUF1 with a value that
//will power up/down line driver
//and the speaker driver in Si3000
//Control Register 1
while ( ! _TMPTY ); //Wait until TXBUF0 and TXBUF1
//have been moved to their shadow
//registers for transmission
TXBUF0 = PLUS_ONE_WITH_SECONDARY; //Load TXBUF0 with a value that
//requests a secondary frame
TXBUF1 = (WRITE_CONTROL_2 | g711.control2); //Load TXBUF1 with a value that
//will initialize Control2
//Register 2.
while ( ! _TMPTY );
TXBUF0 = PLUS_ONE_WITH_SECONDARY; //Load TXBUF0 with a value that
//requests a secondary frame
TXBUF1 = (WRITE_RX_GAIN_CONTROL_1 | g711.rxgaincontroL1);//Load TXBUF1 with
//a value that will initialize
//RX Gain Control1 Register.
while ( ! _TMPTY); //Wait until TXBUF0 and TXBUF1
//have been moved to their shadow
//registers for transmission
TXBUF0 = PLUS_ONE_WITH_SECONDARY; //Load TXBUF0 with a value that
//requests a secondary frame
TXBUF1 = (WRITE_ADC_VOLUME_CONTROL | g711.adcvolumecontrol);//Load TXBUF1
//with a value that will
//initialize ADC volume contol
//Register6.
while ( ! _TMPTY ); //Wait until TXBUF0 and TXBUF1
//have been moved to their shadow
//registers for transmission
TXBUF0 = PLUS_ONE_WITH_SECONDARY; //Load TXBUF0 with a value that
//requests a secondary frame
TXBUF1 = (WRITE_DAC_VOLUME_CONTROL |g711.dacvolumecontrol);//Load TXBUF1
// with a value that that will
//initialize DAC Volume Control
// Register7
while ( ! _TMPTY ); //Wait until TXBUF0 and TXBUF1
//have been moved to their shadow
//registers for transmission
TXBUF0 = PLUS_ONE_WITH_SECONDARY; //Load TXBUF0 with a value that
//requests a secondary frame
TXBUF1 = (WRITE_ANALOG_ATTENUATION | g711.analogattenuation);//Load TXBUF1
//with a value that that
//will initialize Analog
//attenuation Control Register9.
while(!_TMPTY); //Wait until TXBUF0 and TXBUF1
//have been moved to their shadow
//registers for transmission
/*-----------------------------------------------------------------------------
Note that the TMPTY bit only gives a status of whether or not TXBUF registers
are ready to accept data. This does not tell you if the transmissions themselves
were completed.So, we need to test the SLOT<3:0> bits in the DCISTAT register.
While testing we will ensure that TXBUF0 and TXBUF1 shadow registers have been
fully transmitted on TimeSlot0 two times each. This will guarantee that
initialization of the codec is complete
-----------------------------------------------------------------------------*/
temp1 = 0x0f00; //Set up a mask for the SLOT bits
do
{ //Read the DCISTAT register
temp2 = DCISTAT; //Logical-AND to extract SLOT bits
temp2 &= temp1;
} while ( temp2 ); //Wait until SLOT bits reach 0b0000
//Did TXBUF0 get transmitted?
do
{ //Read the DCISTAT register
temp2 = DCISTAT; //Logical-AND to extract SLOT bits
temp2 &= temp1;
} while ( ! temp2 ); //Wait until SLOT bits reach non-zero
//Did TXBUF1 get transmitted?
do
{ //Read the DCISTAT register
temp2 = DCISTAT; //Logical-AND to extract SLOT bits
temp2 &= temp1;
} while ( temp2 ); //Wait until SLOT bits reach 0b0000
//Did TXBUF0 get transmitted?
do
{ //Read the DCISTAT register
temp2= DCISTAT; //Logical-AND to extract SLOT bits
temp2 &= temp1;
} while ( ! temp2 ); //Wait until SLOT bits reach 0b0000
//Did TXBUF0 get transmitted?
while ( ! _ROV ); //Testing overflow bit
temp1 = RXBUF0; //Dummy reads to clear
temp1 = RXBUF1; //overflow conditions
_DCIEN = 0x00; //Disable the DCI module
/*-----------------------------------------------------------------------------
Now re-initialize some aspects of the DCI communication for normal interrupt
driven operation based on user settings done in dci and codecsetup structures.
-----------------------------------------------------------------------------*/
DCICON1 = DCICON1VAL; //Set mode.
//Data txmit/rx setup.
//Data change setup.
//Tristate/set low output CSDO pin when
//not txing.
//Frame sync genrtd by dsPIC DCI/SI3000.
//Clock is output from DCI/SI 3000.
//Ensure module is disabled for now
DCICON2 = DCICON2VAL; //Set Data word size .(bits 3:0)
//Set data frame size.(bits 8:5)
DCICON3 = g711.bcg1; //Set DCI bit clock generator.
RSCON = RSCONVAL; //Set receive slot enable bits.
TSCON = TSCONVAL; //Set transmit slot enable bits.
codecdata.countFill = 0x0000; //Clear counter that keeps track ofdata
//filled into ping pong buffers.
codecdata.countLoad = 0x0000; //Clear counter that keeps track ofdata
//retrieved from ping pong buffers.
codecdata.fBlockdone = 0x00; //Clear flag that indicates whether or
//not one sample ping pong buffer
_DCIEN = 0x01; //has been filled.
}
else
{
/******************************************************************************
Cofiguration of DCI peripheral for setting up SI 3000 codec Registers.
******************************************************************************/
DCICON1 = 0x0000; //Ensure DCI module is placed in known
DCICON2 = 0x0000; //state.
DCICON3 = 0x0000;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -