Background technology
Voice are acoustics performances of language, are that human exchange of information is the most natural, the most effective, the means of most convenient, also are a kind of supports that the mankind carry out thinking.The transmission of speech business is one of Core Feature most important, the most basic in the communication system all the time, even if in the third generation of advocating multimedia service even the 4th algebraically word mobile communication system, speech business also remains its dominant traffic.
PCM is the english abbreviation of pulse code modulation (Pulse Code Modulation), namely voice signal is carried out the process of impulse sampling, digital quantization, coding.The frequency band limits of telephone speech signal is at 300Hz-3400Hz, for the digitization of speech signals with simulation, at first to carry out impulse sampling (time quantization) to analog signal, according to sampling thheorem, the frequency of voice signal sampling pulse is at least the twice of voice signal frequency, and ccitt standard is defined as 8kHz.And then the PAM pulse that sampling obtains carried out amplitude quantizing, each pulse amplitude represents that with 8bit the pcm encoder speed of each road telephone signal is 8k * 8bit=64kb/s like this.The PCM signal extensively is used in telephone exchange, network telephone, optical transceiver, integrated access equipment, the synthetic multiplexing device.
In the normal telephone net, telephone set collects analog voice just need to carry out pcm encoder through telephone line transmission behind office exchange, does not therefore relate to digital coding and the transmission of PCM as the telephone set of communication terminal.Along with communicating by letter to intelligent, networked future development, increasing digital terminal has appearred, such as ISDN terminal, mobile phone, network telephone etc.The digitlization of voice can directly be finished in terminal, and the integrated circuit (IC) chip of numerous special PCM encoding and decoding is also arisen at the historic moment, and is exactly a chip that carries out voice PCM encoding and decoding for terminal equipment specially such as the W681512 of magnificent nation.Meanwhile, microcontroller generally lacks special PCM communication interface, and this just needs microcontroller can use common communication interface to finish information interaction with the PCM codec chip.
SPI is the abbreviation of English Serial Peripheral Interface, as the term suggests be exactly Serial Peripheral Interface.SPI is a kind of high speed, full duplex, and synchronous communication bus can be processed a plurality of main frame and slaves of specifying on the bus that are connected to.Only take four lines on the pin of chip, saved the pipe of chip
Pin.4 lines of this interface normal operation, serial time clock line (SCK), main frame input/slave output line (MISO), main frame output/slave input line (MOSI), slave is selected line (SSEL).In transfer of data, main frame always can send to slave the data of 8 to 16 positions of a frame, and slave also always sends a frame byte data to main frame.In point-to-point communication, the SPI interface does not need to carry out addressing operation, and is full-duplex communication, seems simple efficient.
In the SPI communication system, main frame must be arranged.Spi bus can be configured to single main single from, single main many from.Generally can be undertaken by special PCM communication interface between the microcontroller of voice terminal device and the PCM encoder, in the development process of speech communication equipment, seriously limit the selection to microcontroller.For the microprocessor that does not have the PCM communication interface, can use SPI host interface simulation PCM communication interface, but this method will take microcontrolled operand in a large number, and not be suitable for a large amount of low cost microcontrollers.In the SPI communication system, main frame must be arranged.Peripheral PCM codec chip provides SPI slave interface, needs microcontroller to provide the SPI host interface to be connected with the PCM encoding and decoding.When using the G.711 coded voice information of SPI interface transmission 64Kbits/s speed, per second needs the 8K secondary data mutual, and each microcontroller that all needs alternately participates in control and the data transfer of sequential, obviously will take greatly the resource of microcontroller, the microcontroller of a lot of low sides then can't be finished such operation at all.
Summary of the invention
The present invention seeks to: a kind of operand that can greatly reduce microcontroller is provided, and reduction is to the voice terminal device of method and employing the method for the use SPI Interface realization PCM information interaction of the requirement of microcontroller.
Technical scheme of the present invention is: a kind of method of the SPI of use Interface realization PCM information interaction, the SPI interface of microcontroller is connected with the SPI interface of PCM codec chip, it is characterized in that, the SPI interface of described microcontroller and the SPI interface of PCM codec chip all are made as the slave interface, provide SPI host interface clock by external clock reference.The process of mutual PCM information does not have actual SPI host interface to participate in, and only by two independent finishing of SPI slave interface, at utmost reduces the operand of microcontroller in PCM information transmit-receive process.
A kind of voice terminal device, comprise microcontroller and PCM codec, it is characterized in that, also comprise the external clock reference that SPI host interface clock can be provided, the SPI interface of described external clock reference and PCM codec and the SPI interface that is set as the microcontroller of slave interface link to each other.
Further, described external clock reference is the built-in timer of described microcontroller.
Further, described microcontroller is that use direct memory access mode is finished the microcontroller to the data transmit-receive of SPI Peripheral Interface.Described microcontroller use direct memory access mode is finished the data transmit-receive to the SPI Peripheral Interface, thereby further reduces the exchanges data amount.
Operation principle: the SPI interface of microcontroller also is configured to the slave interface, then provides the SPI interface clock by external clock reference.Like this, originally point-to-point main frame is connected between microcontroller SPI host interface and the PCM encoder, become that virtual SPI host interface (do not participate in data interaction, clock only is provided), micro-control machine SPI slave interface, PCM encoder form one main two from the three parts connect.From traditional one main many from method of attachment different be, traditional method of attachment slave all only with the main frame interaction data, and in the method, two slaves not with the main frame interaction data, and only under the SPI sequential that main frame provides with another one slave interaction data.So just realized that virtual SPI main frame only provides sequential, and two SPI slaves are followed the each other independent interaction data of realization of SPI sequential.From the another one angle, micro-control machine and PCM encoder, any one SPI slave all is considered as the other side the SPI main frame, thinks that all the SPI sequential is provided by the other side, and only need under the SPI sequential, finish simple SPI and get final product from machine operation.
Advantage of the present invention is: microcontrolled SPI interface configuration is become the slave interface, then need not the sequential that microcontroller provides the SPI interactive operation.The SPI controller of adding microcontroller has the transmitting-receiving buffering of some bytes, only after the SPI controller receiving data arrives certain FIFO degree of depth, just need microcontroller to participate in the transmitting-receiving of data, therefore under slave mode, the CPU operand that the SPI transmitting-receiving needs is less than 1/10th of host mode, to discharge greatly the operand of microcontroller, also allow and use lower microcontroller to become possibility.Be applicable to 8 of a large amount of low sides, 16,32-bit microprocessor, allow more flexible, the cheap voice terminal device of development become possibility.Voice terminal device according to this scheme development has been realized flexible, cheap requirement.
Further, microcontroller does not need to provide the SPI sequential when using SPI slave interface to carry out data transmit-receive, and the data transmit-receive that then uses dma controller to participate in the SPI interface for microcontroller provides possibility.When using dma controller, microcontroller only needs every 20MS to participate in a PCM data transmit-receive, every 0.125MS participates in once transmitting-receiving when using host interface, and it is original 1/160 that the frequency that SPI slave interface is carried out transmitting-receiving only has, and will at utmost discharge the operand of microcontroller.
Embodiment
As shown in Figure 1, the SPI interface of microcontroller also is configured to the slave interface, then provides SPI host interface clock by external clock reference (Clock dividers).Like this, originally point-to-point main frame is connected between microcontroller SPI host interface and the PCM encoder, become that virtual SPI host interface (do not participate in data interaction, clock only is provided), micro-control machine SPI slave interface, PCM encoder form one main two from the three parts connect.From traditional one main many from method of attachment different be, traditional method of attachment slave all only with the main frame interaction data, and in the method, two slaves not with the main frame interaction data only with another one slave interaction data.So just realized that virtual SPI main frame only provides sequential, and realized autonomous interaction data between two SPI slaves.From the another one angle, micro-control machine and PCM encoder, any one SPI slave all is considered as the other side the SPI main frame, is that the other side provides to recognizing the SPI sequential all, and only need under the SPI sequential, finishes simple SPI and get final product from machine operation.
For advancing the validity of the two slave mode SPI method for interface communication of explanation, we do a step and set forth as an example of USB phone scheme example.Microcontroller chip uses NXP company market price to be lower than the MCU chip LPC11U14 of 1 dollar, and the PCM codec chip uses the W681512 of magnificent nation.The LPC11U114 kernel uses the COMTEX-M0 technology, and the speed of service can reach 50M, has the 32K in-chip FLASH, the 8K on-chip SRAM, and the USB2.0 interface of PHY is finished the demand that satisfies the USB phone on the integration slice.W681512 is the single channel CODEC that is applied to voice, analog-to-digital, digital revolving die plan, with noise minimization, meets G.711 industrial standard of ITU-T with full differential output function.For further saving cost, the external clock reference that the SPI interface needs is provided by LPC11U14 oneself, and the CLK clock of 2M is provided by timer 1 respectively, and the frame synchronization clock of 8K is provided by timer 0, timer is the autonomous generation clock of meeting after setting is finished, and does not need microcontroller itself to participate in.The CLK clock of 2M is received respectively the SCK1 of LPC11U14, the BCLKR of W681512 and BCLKT.The frame synchronization clock of 8K is received respectively the SSEL1 of LPC11U14, the FSR of W681512 and FST.The MOSI1 of LPC11U14 is connected with the PCMT of W681512, the MISO1 of LPC11U14 is connected with the PCMR of W681512.The SPI interface that has so just consisted of complete two slave modes connects.Physical circuit figure such as Fig. 2, shown in Figure 3.On software, the SPI1 interface of LPC11U14 is set to slave mode, interrupts processing function for SPI1 sets, and interrupting processing in the function, respectively the SPI1 interface is carried out the reading and writing operation, finishes the data interaction with PCM encoder.For further raising the efficiency, during actual design, the SPI1 interface configuration is become dma mode, like this, and the data of 160 bytes of every transmitting-receiving, being equivalent to per 20 milliseconds just needs microcontroller to participate in to carry out once-through operation, at utmost reduced the operand of microcontroller.After tested, use two slave modes, during with the G.711 formatted data of the mutual 64kbits/s of PCM encoder, only take 5% of whole CPU usage, sending and receiving data zero defect meets design requirement fully.
To SPI1 to initialized code instance:
void ssp1Init(void)
{
/* Set DSS data to 8-bit, Frame format TI, CPOL = 0, CPHA = 0*/
SSP1CR0 = 0x0017;
/* SSPCPSR clock prescale register, master mode, minimum divisor is 0x02 */
SSP1CPSR = 18;
SSP1IMSC=0x04; // startup sending and receiving
SSP1CR1 = 0x06
SSP1DMACR = 0x03;
}
The initialization example of the DMA that SPI1 is used
void gpdmaInit(void)
{
start2MClock();
start8KFrame();
ssp1Init();
PCONP |= (1 << 29);
GPDMA_INT_TCCLR = 0x03;
GPDMA_INT_ERR_CLR = 0x03;
GPDMA_CONFIG = 0x01; /* Enable DMA channels, little endian */
while (!(GPDMA_CONFIG & 0x01));
g_gpdmaSndHead = 0;
g_gpdmaSndTail = 0;
g_gpdmaRcvHead = 0;
g_gpdmaRcvTail = 0;
// startup receives DMA
GPDMA_CH1_SRC = DMA_SSP1DR;
GPDMA_CH1_DEST = GPDMA_RECV_BUF_ADDR;
GPDMA_CH1_LLI = 0;
GPDMA_CH1_CTRL = GPDMA_BLOCK_SIZE | (0x01 << 12) | (0x01 << 15)| (1 << 27) | 0x80000000;
GPDMA_CH1_CFG = (0x0C001 | 0x03 << 1 | 0x00 << 6 | 0x02 << 11);
}
Example is interrupted in the sending and receiving of DMA under the SPI1 interface
void gpdmaIsr(void) __irq
{
ULONG intStatus, intTcStatus, intErrorStatus, next;
intStatus = GPDMA_INT_STAT;
intTcStatus = GPDMA_INT_TCSTAT;
intErrorStatus = GPDMA_INT_ERR_STAT;
if (intStatus & 0x01)
{
// DMA passage 0 has interruption
if (intErrorStatus & 0x01)
{
GPDMA_INT_ERR_CLR = 0x01;
}
if (intTcStatus & 0x01)
{
GPDMA_INT_TCCLR = 0x01;
}
}
if (intStatus & 0x02)
{
// DMA passage 1 has interruption
if (intErrorStatus & 0x02)
{
GPDMA_INT_ERR_CLR = 0x02;
}
if (intTcStatus & 0x02)
{
//g_gpdmaRcvKeep++;
next = g_gpdmaRcvTail + 1;
if (next >= GPDMA_RCV_BLOCK_NUM)
{
next = 0;
}
if (next != g_gpdmaRcvHead)
{
// receive BUFFER also to have time
g_gpdmaRcvTail = next;
}
else
{
g_gpdmaRcvHead = 0;
g_gpdmaRcvTail = 0;
}
GPDMA_CH1_SRC = DMA_SSP1DR;
GPDMA_CH1_DEST = GPDMA_RECV_BUF_ADDR+g_gpdmaRcvTail*GPDMA_BLOCK_SIZE;
GPDMA_CH1_LLI = 0;
GPDMA_CH1_CTRL = GPDMA_BLOCK_SIZE | (0x01 << 12) | (0x01 << 15)| (1 << 27) | 0x80000000;
// when receiving data, send data.
if (g_gpdmaSndHead == g_gpdmaSndTail)
{
memset((UCHAR *)(GPDMA_ECHO_BUF_ADDR+g_gpdmaRcvTail*GPDMA_BLOCK_SIZE),
0xD5, GPDMA_BLOCK_SIZE);
}
else
{
// sound that sends is kept as echo
memcpy((UCHAR *)(GPDMA_ECHO_BUF_ADDR+g_gpdmaRcvTail*GPDMA_BLOCK_SIZE),
(UCHAR *)(GPDMA_SEND_BUF_ADDR+g_gpdmaSndHead*GPDMA_BLOCK_SIZE),
GPDMA_BLOCK_SIZE);
g_gpdmaSndHead++;
if (g_gpdmaSndHead >= GPDMA_SND_BLOCK_NUM)
{
g_gpdmaSndHead = 0;
}
}
// startup sends DMA
GPDMA_CH0_SRC = GPDMA_ECHO_BUF_ADDR+g_gpdmaRcvTail*GPDMA_BLOCK_SIZE;
GPDMA_CH0_DEST = DMA_SSP1DR;
GPDMA_CH0_LLI = 0;
GPDMA_CH0_CTRL = GPDMA_BLOCK_SIZE | (0x01 << 12) | (0x01 << 15)| (1 << 26) | 0x80000000;
GPDMA_CH0_CFG = (0x04001 | 0x00 << 1 | 0x02 << 6 | 0x01 << 11);
GPDMA_CH1_CFG = (0x0C001 | 0x03 << 1 | 0x00 << 6 | 0x02 << 11);
OSEventSnd (2); // notice application layer task receive data
GPDMA_INT_TCCLR = 0x02;
}
}
VICVectAddr = 0; /* Acknowledge Interrupt */
OSIntExit();
}
Advantage of the present invention is that microcontrolled SPI interface configuration is become the slave interface, then need not to provide the sequential of SPI interactive operation.The SPI controller of adding microcontroller has the transmitting-receiving buffering of some bytes, only after the SPI controller receiving data arrives certain FIFO degree of depth, just need microcontroller to participate in the transmitting-receiving of data, therefore under slave mode, the CPU operand that the SPI transmitting-receiving needs is less than 1/10th of host mode, further again, if use dma controller to participate in the transmitting-receiving of PCM information, microcontroller only needs every 20MS to participate in a PCM data transmit-receive, every 0.125MS participates in once transmitting-receiving during than the use host interface, the frequency that SPI slave interface is carried out transmitting-receiving only has original 1/160, to discharge greatly the operand of microcontroller, also allow and use lower microcontroller to become possibility.Be applicable to 8 of a large amount of low sides, 16,32-bit microprocessor, allow more flexible, the cheap voice terminal device of development become possibility.Voice terminal device according to this scheme development has been realized flexible, cheap requirement.