?? packetdisassembler.c
字號:
/*****************************************************************************
* *
* ********** *
* ************ *
* *** *** *
* *** +++ *** *
* *** + + *** *
* *** + CHIPCON CC1010 Wireless audio project *
* *** + + *** *
* *** +++ *** PacketDisassembler for the master unit *
* *** *** *
* *********** *
* ********* *
* *
*****************************************************************************
* This source file is part of a software project for Full Duplex, *
* single-chip, wireless intercom, written for the CC1010 chip *
* (RF-transceiver chip with integrated 8051 micro-controller). *
*****************************************************************************
* Author: OAE *
*****************************************************************************
* Revision history: *
* *
* $Log: PacketDisassembler.c,v $
* Revision 1.1 2003/08/04 12:35:08 tos
* Initial version in CVS.
*
* *
* *
****************************************************************************/
#include <chipcon/reg1010.h>
#include <chipcon/cc1010eb.h>
#include <chipcon/hal.h>
// Define buffer constants
#define BUFFER_SIZE 256
#define BUFFER0 0
#define BUFFER1 1
// Set up RAM buffers for halDES() at absolute addresses
byte xdata receivebuffer0[BUFFER_SIZE] _at_ 0x0200;
byte xdata receivebuffer1[BUFFER_SIZE] _at_ 0x0300;
// Define constants
#define MSB 1
#define LSB 0
// Define buffer pointers
const byte xdata *receive_buffer_start_ptr0 = &receivebuffer0[0];
const byte xdata *receive_buffer_start_ptr1 = &receivebuffer1[0];
byte xdata *receive_buffer_read_ptr;
// Variables for receive buffer
byte buffercode;// Temporary variable to store bytes read from buffer
byte receivereadcounter = 0;
bit readytoreadbuffer = 0;
bit currentreceivebuffer = 0;
// Extern variables
extern byte decoderpredsample;
// Function prototypes
byte DpcmDecoder (byte dpcmcodein, bit msbits);
/**************************************************************************
* PacketDisassembler() - Routine for packet disassembling *
***************************************************************************
* Description: *
* Used to read and decode (done by DpcmCodec()) received speech codes, *
* read from receive buffer, and return decoded PCM speech samples, *
***************************************************************************
* Input arguments: *
* None. *
* Return value: *
* byte: A decoded (predicted) unsigned PCM speech sample (0-255). *
**************************************************************************/
byte PacketDisassembler()
{
/* The first byte of a valid packet will contain an uncoded
predicted sample that must be saved rather than decoded*/
if (receivereadcounter == 0)
{
if (currentreceivebuffer == BUFFER0)
{
// Point to the second buffer element
receive_buffer_read_ptr = receive_buffer_start_ptr0 + 1;
// Increment read counter
receivereadcounter++;
// Initialize readytoreadbuffer
readytoreadbuffer = 0;
// Save and return the received predicted sample
return (decoderpredsample = *receive_buffer_start_ptr0);
}// End if
else// (currentreceivebuffer == BUFFER1)
{
// Point to the second buffer element
receive_buffer_read_ptr = receive_buffer_start_ptr1 + 1;
// Increment read counter
receivereadcounter++;
// Initialize readytoreadbuffer
readytoreadbuffer = 0;
// Save and return the received predicted sample
return (decoderpredsample = *receive_buffer_start_ptr1);
}// End else
}// End if
else// (receivereadcounter != 0)
{
// Toggle readytoreadbuffer
readytoreadbuffer =! readytoreadbuffer;
if (readytoreadbuffer)
{
// Read encoded byte from current buffer position
buffercode = *receive_buffer_read_ptr;
// Decode the four MSB of the buffercode, return decoded sample
return (DpcmDecoder(buffercode,MSB));
}// End if
else // (!readytoreadbuffer)
{
// Increment read counter
receivereadcounter++;
// Increment pointer
receive_buffer_read_ptr++;
// Decode the four LSB of the buffercode, return decoded sample
return (DpcmDecoder(buffercode,LSB));
}// End else
}// End else
}// End function
/**************************************************************************
* InitializeDisassembler() - Initialization of the PacketDisassembler() *
***************************************************************************
* Description: *
* Used to reset and initialize the function PacketDisassembler(). This *
* is done by forcing the receivereadcounter to zero and switching *
* between the two receivebuffers *
***************************************************************************
* Input arguments: *
* None. *
* Return value: *
* None *
**************************************************************************/
void InitializeDisassembler()
{
receivereadcounter = 0;
// Switch buffer
currentreceivebuffer = !currentreceivebuffer;
}// End function
/**************************************************************************
* ResetReceiveBuffers() - Routine for resetting both receive buffers *
***************************************************************************
* Description: *
* Used to fill both receive buffers with NULL-samples *
***************************************************************************
* Input arguments: *
* None. *
* Return value: *
* None. *
**************************************************************************/
void ResetReceiveBuffers()
{
// Define the total buffersize
word totalbuffersize = 2*BUFFER_SIZE;
// Copy buffer pointer to local pointer variable
byte xdata *buffer_start_ptr = receive_buffer_start_ptr0;
// Fill receive buffers with NULL-samples
while(totalbuffersize--)
*buffer_start_ptr++ = 0x00;
}// End function
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -