⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 autosira_msm7731.c

📁 蓝牙HANDFREE软件源代码
💻 C
字号:
/****************************************************************************
FILE
    autosira_msm7731.c
 
DESCRIPTION
    This module contains a device abstraction for an OKI Semiconductor MSM7731
    dual echo canceler and noise canceller with dual codec for hands free
    applications.  The library is built on top of the SPI library.

    The MSM 7731 is an IC device developed for portable, handfree
    communication with built-in echo canceler, acoustic echo canceler,
    and transmission signal noise canceler.  Built-in to the voice
    signal interface is a linear CODEC for the analog interface on the
    acoustic-side and a linear CODEC for the analog interface on the
    line-side.  On the line-side, in addition to the analog interface,
    there is also a U-law PCM/16-bit linear digital interface.
    Equipped with gain and mute controls for data transmission and
    reception, a u-law PCM/16-bit linear digital interface for memo
    recording and message output, and transfer clock and sync clock
    generators for digital communication, the device is ideally suited
    for handsfree systems.
 
MODIFICATION HISTORY
    1.1     11:Nov:02   jm01    Created.
    1.2     26:Nov:02   am01    Modified.
*/

#include "spi.h"
#include "autosira_msm7731.h"

#include <ccltypes.h>
#include <pio.h>
#include <ps.h>
#include <stdlib.h>

/****************************************************************************
NAME
    Msm7731Init
 
FUNCTION
    This function is called by the client at Reset to configure the
    device for operation.  The underlying SPI transport is initialised
    and any device specific initialisation

RETURNS
    void
*/

void Msm7731Init(void)
{
    /* Initialise the SPI transport Library */  
    SpiInit();

    /* Update the PS keys on BlueCore */
    PsUpdate();

    /* Toggtle the PDN/RST low and then high again */
    MsmPdnRst();

    /* Update all registers of the MSM */
    MsmUpdate();
//      MSMGainInit();

    /* Once updated set CR0 B0 & B1 to 1 */
    MsmAudio();
}


/****************************************************************************
NAME
    Msm7731Write
 
FUNCTION
    This function is called by the client to write to one of the
    devices internal registers.  See pages 26 to 39 of the datasheet
    for a full description

        CR0 -   Basic operating mode setting
        CR1 -   
        CR2 -   Receive side level control
        CR3 -   Transmit gain adjustment
        CR4 -   Line echo canceler strings
        CR5     -       Acoustic echo canceler setting
        CR6 -   Internal data memory write register
        CR7 -   Internal data memory write register
        CR8 -   Internal data memory write register
        CR9 -   Internal data memory write register
        CR10-   Echo canceler I/O level setting
        CR11-   SYNC power-down control register
        CR12-   Reserved register

    The control regsiter to write to is defined by reg and the data to
    be written supplied by data.  This function performs a write
    followed by read to verify the write cycle.  In the event that a
    write operation fails then FALSE is returned to indicate to the
    Client that the operation was unsuccessful
        
RETURNS
    TRUE or FALSE
*/

uint16 Msm7731Write(MSM7731_REG reg, uint8 data)
{
    uint8       cr[2];

    /* Assume successful write operation */
    uint16      success = TRUE;

    /* Ensure that control register address is valid (Within range) */
    cr[0] = reg & MSM7731_REG_MASK;
        
    /* Write data to control register */
    cr[1] = data;
    SpiWrite(cr,2);

    return success;
}


/****************************************************************************
NAME
    Msm7731Read
 
FUNCTION
    This function is called by the client to read one of the devices
    internal registers.  See pages 26 to 39 of the datasheet for a
    full description

        CR0 -   Basic operating mode setting
        CR1 -   
        CR2 -   Receive side level control
        CR3 -   Transmit gain adjustment
        CR4 -   Line echo canceler strings
        CR5     -       Acoustic echo canceler setting
        CR6 -   Internal data memory write register
        CR7 -   Internal data memory write register
        CR8 -   Internal data memory write register
        CR9 -   Internal data memory write register
        CR10-   Echo canceler I/O level setting
        CR11-   SYNC power-down control register
        CR12-   Reserved register

    The control regsiter to read is defined by reg 
        
RETURNS
    The contents of the control register
*/

uint8 Msm7731Read(MSM7731_REG reg)
{
    uint8       cr;
    uint8       data;

    /* Ensure that control register address is valid (Within range) */
    cr = reg & MSM7731_REG_MASK;
        
    /* Set the MS bit of the control register address to indicate a write operation */
    cr |= MSM7731_READ;

    /* Read data from control register */
    SpiCommandRead(cr,&data,1);

    return data;
}

/****************************************************************************
NAME
    PsUpdate
 
FUNCTION
    This function is called to update the PS values on BlueCore with default values is empty.

RETURNS
    void
*/

void PsUpdate(void)
{
    uint16 i;
    uint16 zeroBuf;

    /* Check if PS is blank, if so load default value */
    for (i=0; i<13; i++)
    {   
        if (PsRetrieve(PS_CR0+i,&zeroBuf,1)==0)
        {
            zeroBuf = msmDefaultValues[i];
            PsStore(PS_CR0+i,&zeroBuf,1);
        }
                
        PioSetDir(PWNRST, ~0);
        PioSet(PWNRST, 0);
    }
}


/****************************************************************************
NAME
    Msm7731ReadReady
 
FUNCTION
    This function is called to read the ready bit from the MSM.

RETURNS
    void
*/

uint8 Msm7731ReadReady(void)
{
    /* Check if MSM is ready or not */
    uint16 state;

    if ((Msm7731Read(CR11) & (MSM7731_READY))==MSM7731_READY)
        state = 1;
    else
        state = 0;

    return state;
}


/****************************************************************************
NAME
    MsmUpdate
 
FUNCTION
    This function is called to write PS values on BlueCore to the MSM device.

RETURNS
    void
*/

void MsmUpdate(void)
{
        
    uint16 i;
    uint16      zeroBuf;

    /* Load default values into MSM */
    for (i=0; i<13; i++) 
    {
        PsRetrieve(PS_CR0+i,&zeroBuf,1);
        while(Msm7731ReadReady()== 0);
        Msm7731Write(CR0+i, zeroBuf);
    }
}


void MsmAudio(void)
{
    uint16      zeroBuf;
    PsRetrieve(PS_CR0,&zeroBuf,1);

    /* set CR0 B0 & B1 to 1 */
    Msm7731Write(CR0, zeroBuf|0x03);
}


/* Initialise the Power Down Reset pin to high, then toggle low and then high again*/
void MsmPdnRst (void)
{
    PioSet(PWNRST, 0);
    PioSet(PWNRST, ~0);
}


/*Write a delay time of 32ms into MSM memory register*/
void MsmWriteDelay (void)
{
    uint16 data;
        
    while (Msm7731ReadReady()==0);
    Msm7731Write(CR6, 0x00);
    Msm7731Write(CR7, 0x9b);
    PsRetrieve(PS_CR8,&data,1);
    Msm7731Write(CR8, data);
    PsRetrieve(PS_CR9,&data,1);
    Msm7731Write(CR9, data);
    data=Msm7731Read(CR1);
    Msm7731Write(CR1, (MSM7731_INTWRITE | data));
    data=Msm7731Read(CR1);
    while (Msm7731Read((CR1)&(0x80))==1);
}


void setMSMGain(uint16 gain)
{
    Msm7731Write(CR2,msmGain[gain]);
}

void MSMGainInit(void)
{
    uint16 gainBuf;
    PsRetrieve(PS_CR13,&gainBuf,1);
    Msm7731Write(CR2,msmGain[gainBuf]);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -