📄 voipradio.c
字号:
//-----------------------------------------------------------------------------
//
// Filename: voipRadio.c
//
// DESCRIPTION: General radio configuration, non-voice operations
//
//--------------------------------------------------------------------------
// $Archive:
// $Modtime:
// $Revision:
//--------------------------------------------------------------------------
//
// Copyright 2005-2006, Cypress Semiconductor Corporation.
//
// This software is owned by Cypress Semiconductor Corporation (Cypress)
// and is protected by and subject to worldwide patent protection (United
// States and foreign), United States copyright laws and international
// treaty provisions. Cypress hereby grants to licensee a personal,
// non-exclusive, non-transferable license to copy, use, modify, create
// derivative works of, and compile the Cypress Source Code and derivative
// works for the sole purpose of creating custom software in support of
// licensee product to be used only in conjunction with a Cypress integrated
// circuit as specified in the applicable agreement. Any reproduction,
// modification, translation, compilation, or representation of this
// software except as specified above is prohibited without the express
// written permission of Cypress.
//
// Disclaimer: CYPRESS MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// WITH REGARD TO THIS MATERIAL, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
// Cypress reserves the right to make changes without further notice to the
// materials described herein. Cypress does not assume any liability arising
// out of the application or use of any product or circuit described herein.
// Cypress does not authorize its products for use as critical components in
// life-support systems where a malfunction or failure may reasonably be
// expected to result in significant injury to the user. The inclusion of
// Cypress' product in a life-support systems application implies that the
// manufacturer assumes all risk of such use and in doing so indemnifies
// Cypress against all charges.
//
// Use may be limited by and subject to the applicable Cypress software
// license agreement.
//
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
// INDENTATION NOTES:
// ASM files indent with HARD-TABs and assume standard 8-char/tab
// 'C' files indent with 4 SPACE characters
//--------------------------------------------------------------------------
#include "lpradio.h"
#include "Defines.h"
#include "voip8kIsr.h"
//--------------------------------------
// Local Definitions and Types
//--------------------------------------
#define CHANNEL 90 // 0-98
//#define CHANNEL 84 // 0-98 Demo units
#define PN_CODE 2 // 0-12
#define PA_LEVEL 4 // 4, 0, -20, -30
// ---------------------------------------------------------------------------
static enum
{
RS_IDLE,
RS_RECEIVING,
RS_TRANSMITTING
} state;
// Global radio transmit/receive buffers
BYTE radioTxBuffer[WIRELESS_PACKET_LENGTH];
BYTE radioRxBuffer[WIRELESS_PACKET_LENGTH];
// ---------------------------------------------------------------------------
//
// Initialize ONE radio
//
// Return:
// TRUE if we were able to talk to the radio OK.
// ---------------------------------------------------------------------------
static BOOL WirelessInitialiseWorker(void)
{
RadioInit(END_STATE_RXSYNTH, TX_CFG_RST);
RadioSetFrequency(CHANNEL); // Set Tx chan (2400MHz + CHANNEL)
voiceCh = CHANNEL - 1; // isr DRIVER DOESN'T DECR 1 LIKE API
if(RadioGetFrequency() != CHANNEL) {
return FALSE;
}
RadioWrite(XTAL_CTRL_ADR, XOUT_FREQ_3MHZ); // PWM16_1
RadioSetSopPnCode(PN_CODE);
#if PA_LEVEL == 4
RadioSetTxConfig(DATCODE_LEN_32 | DATMODE_8DR | PA_4_DBM);
#elif PA_LEVEL == 0
RadioSetTxConfig(DATCODE_LEN_32 | DATMODE_8DR | PA_0_DBM);
#elif PA_LEVEL == -20
RadioSetTxConfig(DATCODE_LEN_32 | DATMODE_8DR | PA_N20_DBM);
#else
RadioSetTxConfig(DATCODE_LEN_32 | DATMODE_8DR | PA_N30_DBM);
#endif
RadioSetXactConfig( 0
// | ACK_EN
// | FRC_END_STATE
| END_STATE_TXSYNTH
// | END_STATE_RXSYNTH
// | END_STATE_RX // 30uS faster, but 10mA more 0x10
// | ACK_TO_4X // don't use transaction mode
);
RadioSetPreambleCount(0x01);
RadioSetFrameConfig(0xA4); // KBM uses SOP Threshold 4
RadioSetThreshold32(0x04);
return TRUE;
}
// ---------------------------------------------------------------------------
//
// Initialize the radio "system"
//
// ---------------------------------------------------------------------------
void WirelessInitialise(void)
{
volatile BYTE ivar;
LP_nSS_Data_ADDR |= LP_nSS_MASK; // Make sure BOTH radios are
LP_nSS2_Data_ADDR |= LP_nSS2_MASK; // DESELECTED before write to one
// Reset the Radio - Delay for 3.7us (waiting for characterization)
// Listener has hard connect to radio Reset input, although it really
// should rely on a cap to Vcc and the radio's internal pull-down
// because of a radio silicon bug whereby Reset has some timing
// relationship with the radio's Vcc.
// ------------------------------------------------------------------------
LP_RST_Data_ADDR |= LP_RST_MASK;
for (ivar=0; ivar < 255; ++ivar);
LP_RST_Data_ADDR &= ~LP_RST_MASK;
for (ivar=0; ivar < 255; ++ivar);
while(!WirelessInitialiseWorker())
{
;
}
}
// ---------------------------------------------------------------------------
//
// Maintain RSSI Map while IDLE
//
// ---------------------------------------------------------------------------
#define P_RSSI ((WORD*)0x300)
#define MAX_CH 94
#define RISE_TIME_SHIFT 8
BYTE chNum;
BYTE bestRssi;
BYTE bestCh;
void WirelessRssiGather(void)
{
volatile WORD cheapDelay;
BYTE rssiSample;
WORD rssiAve;
RadioSetFrequency(chNum);
for (cheapDelay=0; cheapDelay < 200; ++cheapDelay);
RadioGetRssi();
for (cheapDelay=0; cheapDelay < 10; ++cheapDelay);
rssiSample = RadioGetRssi() & 0x1F;
// if (bestRssi > rssiSample)
// {
// bestRssi = rssiSample;
// bestCh = chNum;
// }
//
// rssiAve = P_RSSI[chNum/2];
// rssiAve = rssiAve - (rssiAve>>RISE_TIME_SHIFT) + 0;
// P_RSSI[chNum/2] = rssiAve;
//
// chNum += 2;
// if (chNum > MAX_CH) {
// P_RSSI[bestCh/2] += 255;
// chNum = 0;
// bestRssi = 255;
// }
//
rssiAve = P_RSSI[chNum/2];
if (rssiAve < ((WORD)rssiSample<<RISE_TIME_SHIFT) ) {
rssiAve = (WORD)rssiSample<<RISE_TIME_SHIFT;
}
else {
// Shift RiseTimeSamples
// 8 561
// ::::::::
// 3 16
rssiAve = rssiAve - (rssiAve>>RISE_TIME_SHIFT) + rssiSample;
}
P_RSSI[chNum/2] = rssiAve;
chNum += 2;
if (chNum > MAX_CH) {
chNum = 0;
}
}
////--------------------------------------
//// External API to be implemented by customer
////--------------------------------------
//unsigned char handle_mouse_report(void) {
//}
//unsigned char handle_keyboard_report(void) {
//}
//void RetrieveSystemParameters(void) {
//}
//void StoreSystemParameters(void) {
//}
//
//#define DELAY_50US 100
//void TimerDelay50usec(void) {
// WORD volatile delay;
// for (delay=0; delay != DELAY_50US; ++delay)
// ;
//}
//
//void TxRetryDelay(void) {
//}
//void TimerSetTimer(unsigned char timeout_ms) {
//}
//unsigned char TimerTimeOut(void) {
//}
//void TimerDelayMsec(unsigned short num_milliseconds) {
//}
//void DecryptData(void) {
//}
//void AES_Decrypt(void) {
//}
//void GenerateEncryptKey(void) {
//}
//void EncryptKey(void) {
//}
//unsigned char EncryptRequestKey(void) {
//}
//void EncryptData(unsigned char data_length) {
//}
//
//void NotifyDownloadBackChannelData(void) {
//}
//
//
//void NotifyStartBind() {}
//void NotifyContinueBind() {}
//void NotifyStopBind() {}
//void NotifyStartPing() {}
//void NotifyStopPing() {}
// ###########################################################################
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -