?? init8416viaspi.c
字號:
///////////////////////////////////////////////////////////////////////////////////////
//NAME: init8416viaSPI.c (Block-based Talkthrough)
//DATE: 9/18/03
//PURPOSE: Talkthrough framework for receiving SPDIF samples and sending to the AD1835.
//
//USAGE: This file contains the subroutines for accessing the AD1835 control
// registers via SPI.
//
////////////////////////////////////////////////////////////////////////////////////////
#include "tt.h"
#include "CS8416.h"
#include <SRU.h>
void SetupSPICS8416(void);
void DisableSPICS8416(void);
void SetupSPICS8416(void);
void DisableSPICS8416(void);
// Set up the SPI port to access the CS8416
void SetupSPICS8416 ()
{
// Flush the SPI transceive FIFOs
*(volatile int *)SPICTL = (TXFLSH | RXFLSH);
// Setup the baud rate to 1MHz
*(volatile int *)SPIBAUD = 100;
// Flag pins are not being used as the device select
*(volatile int *)SPIFLG = 0;
// Now configure the SPI control register
*(volatile int *)SPICTL = (SPIEN | SPIMS | MSBF | TIMOD1);
}
// Disable the SPI Port and flush the transceive FIFOs
void DisableSPICS8416 ()
{
*(volatile int *)SPICTL = (TXFLSH | RXFLSH);
}
// Read a register from the CS8416
unsigned int ReadCS8416Register (int addr)
{
SetupSPICS8416 ();
SRU(LOW,DAI_PB15_I);
TxCS8416SPI(SPDIF_WRITE_REG);
TxCS8416SPI(addr);
SRU(HIGH,DAI_PB15_I);
Delay (100) ;
SRU(LOW,DAI_PB15_I);
// Write a dummy value to clock the output
TxCS8416SPI(SPDIF_READ_REG);
TxCS8416SPI(0x00);
SRU(HIGH,DAI_PB15_I);
DisableSPICS8416 ();
return *(volatile int *)RXSPI ;
}
unsigned int TxCS8416SPI(int val)
{
*(volatile int *)TXSPI = val;
Delay (100) ;
while (1) // Wait for the SPI port to finish
{
if ( SPIF & *(volatile int *)SPISTAT)
break;
}
Delay (100) ;
return *(volatile int *)RXSPI;
}
// Send a word to the CS8416 via SPI
void WriteCS8416Register (int add, int val)
{
SRU(LOW,DAI_PB15_I);
TxCS8416SPI(SPDIF_WRITE_REG);
TxCS8416SPI(add);
TxCS8416SPI(val);
SRU(HIGH,DAI_PB15_I);
}
//Set up all CS8416 registers via SPI
void InitCS8416viaSPI()
{
outputMuted = 0;
SetupSPICS8416 () ;
WriteCS8416Register(SPDIF_CTRL1, (0x00));
WriteCS8416Register(SPDIF_CTRL2, GPO_NON_AUDIO);
WriteCS8416Register(SPDIF_CTRL3, (0xC0));
WriteCS8416Register(SPDIF_CTRL4, (0x81));
WriteCS8416Register(SPDIF_DATA_FORMAT, FRMT_I2S);
WriteCS8416Register(SPDIF_RX_ERR_MASK, (0x00));
WriteCS8416Register(SPDIF_INT_MASK, (0x00));
WriteCS8416Register(SPDIF_INT_MODE_MSB, (0x00));
WriteCS8416Register(SPDIF_INT_MODE_LSB, (0x00));
DisableSPICS8416 () ;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -