?? darr_data_msg_easy.c
字號:
/******************************************************************************
*
* Purpose: MAX II data message transfer (Easy).
* This code is set-up for mimimum code and
* ram size, and not for maximum speed.
*
* Creator: Rob Lansbergen
*
* Version: $Revision: 21 $
*
* File Name: $Workfile: DARR_Data_Msg_Easy.c $
*
* Author: Rob Lansbergen
*
* Check in: $Author: Chong.cheeleong $
*
* The information is provided 揳s is?without any express or implied warranty
* of any kind, * including warranties of merchantability, noninfringement of
* intellectual property, or fitness for any particular purpose. In no event sha
* Wireless Sound Solutions and/or its affiliate companies, or its suppliers be
* liable for any damages whatsoever arising out of the use of or inability to
* use the information or the materials. Wireless Sound Solutions, its affiliate
* companies, and its suppliers further do not warrant the accuracy or
* completeness of information, text, graphics, or other items contained within
* materials. Wireless Sound Solutions, Inc., may make changes to materials, or
* the products described within, at any time, without notice.
* ?007 Wireless Sound Solutions. All rights reserved. Wireless Sound Solutions
* STS and STS-wireless are trademarks of Wireless Sound Solutions.
*******************************************************************************/
/*
** Include files
** -------------
*/
#include <stdio.h>
#include "defines.h"
/*
** Private data definitions
** ------------------------
*/
TXDATA_STATE TXDataState = TX_IDLE;
volatile RXDATA_STATE RXDataState;
volatile unsigned char Process_New_Frame = 0;
volatile unsigned char TX_Timeout;
unsigned char TX_Data_send_array[I2C_WBUFFER_SIZE];
unsigned char RX_Data_recv_array[I2C_RBUFFER_SIZE];
unsigned char RX_Stream_Nr;
unsigned int RX_SMUA;
unsigned char INTF_Reg;
unsigned char RDC_Reg;
extern unsigned char TbusOn_NoInt;
/******************************************************************************
*
* Function Name : DARR_Interrupt_Handler
*
* Purpose : When ever the interrupts pin goes low this function should be called.
*
* Arguments : -
*
* Return value : none
*
******************************************************************************/
void DARR_Interrupt_Handler(void)
{
INTF_Reg = I2C_Read_Byte(INTF_ADDR);
/*** New Frame ***/
if (INTF_Reg & 0x01)
{
if (Use_Own_WLAN_Detection == 0)
{
Process_New_Frame = 1;
}
Process_New_Frame_Own_WLAN_Det = 1;
}
/*** RX Complete ***/
if (INTF_Reg & 0x02)
{
RXDataState = DATA_TOBEREAD;
}
/*** TX Timout ***/
if (INTF_Reg & 0x04)
{
TXDataState = TX_TIME_OUT;
}
/*** TX Complete ***/
if (INTF_Reg & 0x08)
{
TXDataState = TX_COMPLETE;
}
/*** channel switch ***/
if (INTF_Reg & 0x40)
{
RF_Used = Read_RFC();
if (Audio_Status == AUDIO) Update_LED(RF_Used);
#ifndef NO_GUI
Show_RF_Status();
#endif /*NO_GUI*/
if (BadLink_Cnt < 50) BadLink_Cnt++;
ASTH_Reg = 55;
}
/*** insync ***/
if (INTF_Reg & 0x10)
{
if (Use_ModuleMode == CU)
{
Update_LED(Read_RFC());
}
InSync_Detected = 1;
}else
/*** No_Sync ***/
if (INTF_Reg & 0x20)
{
InSync_Detected = 0;
}
/*** Audio Snooze interupt ***/
// if (INTF_Reg & 0x80) //new s/w snooze
// {
// if (Use_Audio_Detection == 1) Handle_Wake_up_Sleep_Interrupt();
// }
}
/******************************************************************************
*
* Function Name : Send_Message
*
* Purpose : This procedure send a message to the other side unit.
*
* Arguments : TX_STReam_NR is the Audio stream on which the packet is send
* 0 = Stream A
* 1 = Stream B
* 2 = Stream C
* 3 = Stream D
* 128 = Free_slot, only for Data Up in NACK application
*
* !!!!!!!!! This is different compared to DARR78
* Bit 7 in TDC and RDC is now used to as TX_STRM_Free bit
*
* MU_Address this is only used when the CU send a message to the a MU
* For NACK application the MU addressing can be used to address the different
* MU modules.
* MU_address should never be zero except when a CU NACK application is sending a Broadcast
* TX_Data_send_array[16] hold the data that needs to be send.
*
* Return value : 1 if there was Time-out on the transmision of the data.
* 0 If message was send correcly
*
******************************************************************************/
unsigned char Send_Message (unsigned char TX_Stream_NR, unsigned int MU_Address)
{
unsigned char checksum;
unsigned char i;
if(!InSync_Detected)return (0); //Not Insync
TXDataState = TX_IDLE;
if ((I2C_Read_Byte(TDC_ADDR) & 0x08) == 0x00) /* If Not Full */
{
I2C_Write_Buf(DMUA_ADDR, (unsigned char *)&MU_Address, 2, 0);
I2C_Write_Byte(DMUA_ADDR + 2, 0x00);
I2C_Write_Byte(TDC_ADDR, TX_Stream_NR & 0x83);
checksum = 0;
for (i = 0; i < 15; i++)
{
checksum += TX_Data_send_array[i];
}
TX_Data_send_array[15] = checksum;
I2C_Write_Buf(DBUF_ADDR, TX_Data_send_array, 16, 0);
#ifdef DEBUG
putstring("TXmsg: ");
puthex(TX_Data_send_array[0]);
putchar(' ');
puthex(TX_Data_send_array[1]);
putchar(' ');
puthex(TX_Data_send_array[2]);
putchar('\r');
#endif
TX_Timeout = 0;
while (1)
{
/* check interrupt on using polling mechanism */
#ifndef NO_GUI
if (TbusOn_NoInt == 1)
{
DARR_Interrupt_Handler();
}
else
#endif /*NO_GUI*/
{
if (CHECK_INTERRUPT_PIN)
{
DARR_Interrupt_Handler();
}
}
if (TXDataState == TX_COMPLETE)
{
TXDataState = TX_IDLE;
#ifdef DEBUG
putstring("TX OKE\r");
#endif
return (0); /* message send corretly */
}
if ((TXDataState == TX_TIME_OUT) || (TX_Timeout > TIME_1_SEC))
{
#ifdef DEBUG
putstring("TO TX_Stream_NR=");
puthex(TX_Stream_NR);
putstring(" TXDataState=");
puthex(TXDataState);
putstring(" TX_Timeout=");
puthex(TX_Timeout);
putstring("\r");
#endif
TXDataState = TX_IDLE;
return (1);
}
}
}
else
{
I2C_Write_Byte(TDC_ADDR, 0x40); /* TX reset, clear TX buffers in DARR79 */
}
return (1); /* Some how there where both buffer where full(Should not be possible) */
}
/******************************************************************************
*
* Function Name : Handle_Received_Packet
* Purpose : This procedure retrieves any data from the DARR that was received
* It should only be called when the RX_Complete interrupt flag was set.
*
* Arguments : Global Variable
* RX_Stream_Nr This is the audio stream of on which the data messages was send on
* 0 = Stream A
* 1 = Stream B
* 2 = Stream C
* 3 = Stream D
* 128 = Free_slot, only for Data Up in NACK application
*
* !!!!!!!!! This is different compared to DARR78
* Bit 7 in TDC and RDC is now used to as TX_STRM_Free bit
*
* RX_SMUA This is the Address of the MU from which the message came from (used for CU only)
* MU modules.
* RX_Data_recv_array[16] This is where the message was stored in.
*
* Return value : 0xFF incorrect message (Checksum error)
* 1 Empty buffer nothing to read(Should never occur,just for safety)
* 0 If message was received correctly
*
******************************************************************************/
unsigned char Handle_Received_Packet(void)
{
unsigned char temp,i;
unsigned char return_code = 0;
if (RXDataState == DATA_TOBEREAD)
{
RDC_Reg= I2C_Read_Byte(RDC_ADDR);
if ((RDC_Reg & 0x04) != 0x04) /* check if not empty */
{
RX_SMUA= I2C_Read_Byte(SMUA_ADDR);
RX_SMUA= RX_SMUA + (I2C_Read_Byte(SMUA_ADDR + 1) << 8);
I2C_Read_Buf(DBUF_ADDR, 16); /* Read message */
/* !!!!! TDC is different compared to DARR78 !!!!! */
RX_Stream_Nr = (RDC_Reg & 0x83);
temp = 0;
for (i = 0; i < 16; i++) /* Calculate checksum */
{
if (i != 15) temp += RX_Data_recv_array[i];
}
#ifdef DEBUG
putstring("RXmsg: ");
puthex(RX_Data_recv_array[0]);
putchar(' ');
puthex(RX_Data_recv_array[1]);
putchar(' ');
puthex(RX_Data_recv_array[2]);
putchar('\r');
#endif
if (temp != RX_Data_recv_array[15]) /* Check checksum */
{
RXDataState = DATA_IDLE;
return (0xFF); /* Incorrect Checksum */
}
RXDataState = DATA_IDLE;
/* data ready to be parsed */
return_code = 1;
}
else
{
RXDataState = DATA_IDLE;
/* nothing to read */
return_code = 0;
}
RDC_Reg= I2C_Read_Byte(RDC_ADDR);
if ((RDC_Reg & 0x04) != 0x04) /* if buffer still not empty, set flag to read again */
{
RXDataState = DATA_TOBEREAD;
}
}
return(return_code);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -