?? psconfig.cpp
字號:
//
// Copyright (c) Cambridge Silicon Radio. All rights reserved.
//
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Module Name: PSConfig.cpp
//
//
// Abstract: This module is a lightweight WinCE port of PS update code
//
/* Int'l Corp. 2005
$Modifier sign Description
==========================================================================================
*/
#include <windows.h>
#include <types.h>
#include <stdio.h>
#include <stdlib.h>
#include "ubcsp.h"
#include "PSConfig.h"
#include "SerialCSR.h"
#include "PSKey.h"
#define LINKTIMEOUT 4000
#define BT_DBGMSG NKDbgPrintfW
#define PS_DBG FALSE
int ReadPSKey(DWORD Count);
// Declarations
//char* gchFileName = "\\Windows\\PSConfig.txt"; // Persistent store keys
int giPDUCount = 0; // Count of pdu entries
int giPDUIndex = 0; // Index of pdu entries
BCCMDPDU *gPDU; // Array of pdu entries to update persistent store with
int giResetSent = 0;
HANDLE ghPort = NULL;
static struct uBCSPQueue uBCSP_TXQueue;
static struct uBCSPQueue uBCSP_RXQueue;
uint16 stores_;
int giStartTime = 0;
bool gbLinkTimeOut = FALSE;
bool gbLinked = FALSE;
extern BOOL gbBTPower;
//evan_note
typedef struct
{
uint16 pskey;
//uint16 data[8]; //RAD_R03_060213a
uint16 data[100]; //RAD_R03_060213a
uint16 len;
}PSDATA;
static PSDATA psdata[] =
{
{PSKEY_BADADDR, {0x0010, 0x05fd, 0x006e, 0x0006} , 4},
{PSKEY_ANA_FREQ, {0x6590}, 1},
{PSKEY_UART_BAUDRATE, {0x01d8}, 1},
{PSKEY_PCM_CONFIG32, {0x0080, 0x0000}, 2},
{PSKEY_ANA_FTRIM, {0x0000}, 1},
{PSKEY_LC_MAX_TX_POWER, {0x0004}, 1},
{PSKEY_TX_PRE_LVL, {0x000e}, 1},
{PSKEY_UNKNOWN, {0x0008}, 1},
{PSKEY_LOOP_FILTER_TRIM,{0x06bb}, 1},
{PSKEY_TX_GAIN_RAMP, {0x30a0}, 1},
{PSKEY_RF_RESONANCE_TRIM,{0x130f}, 1}
};
// Monitor states
extern struct ubcsp_configuration ubcsp_config; // NB uBCSP decl changed from static
//HANDLE com_handle;
//Jonathan_test start
// HCI Command Queues
struct HCIQueue
{
uint8 NoOfOpcodes;
uint8 commandnumber;
uint8 HCIOpcode[2];
uint8 NoOfRetries;
};
static struct HCIQueue HCI_TXQueue;
static struct HCIQueue HCI_RXQueue;
static uint8 Enable_Device_Under_Test_Mode[] =
{
0x03, 0x18, 0x00
};
static uint8 HCICommand_Write_Scan_Enable[] =
{
0x1A, 0x0C, 0x01, 0x03
};
static uint8 Set_Event_Filter[] =
{
0x05, 0x0C, 0x03, 0x02, 0x00, 0x02
};
//Jonathan_test end
/////////////////////////////////////////////////////////////////////////
BOOL PSConfig(HANDLE hPort)
{
int iDelay;
BOOL bLastSentPacket;
unsigned char chActivity;
unsigned char chSendBuffer[512], chReceiveBuffer[512];
struct ubcsp_packet SendPacket, ReceivePacket;
RETAILMSG(PS_DBG,(TEXT("PSConfig start\r\n")));
// Construct pdus
ghPort = hPort;
giResetSent = 0;
chActivity = 0;
giPDUIndex=0;
gbLinked=FALSE;
ubcsp_initialize ();
/*//evan_note
FILE *stream;
stream = fopen(gchFileName, "r"); //Read PSConfig.psr
if(stream)
{
// Count entries
giPDUCount = 0;
giPDUCount = ReadPSRFile(stream, false); // Count only
if(giPDUCount == 0)
{
BT_DBGMSG(TEXT("!!!! read file fail !!!!\r\n"));
return FALSE; // No data
}
else
//BT_DBGMSG(TEXT("!!!! read file ok !!!!\r\n"));
gPDU = new BCCMDPDU[giPDUCount + 1]; // Last pdu is warm reset
fseek(stream, 0, SEEK_SET); // Seek start of stream
giPDUCount = 0; // Reset to zero and load pdu array
ReadPSRFile(stream, true); // Adds .psr file pdu's
giPDUCount++; // Extra reset pdu
ConfigResetPDU(); // Construct Reset PDU
// Close file
fclose(stream);
}else
{
BT_DBGMSG(TEXT("!!!! load file fail !!!!\r\n"));
RETAILMSG(1,(TEXT("PSConfig read file fail !!!!!!\r\n")));
return FALSE; // File access problem
}
*///evan_note
//RETAILMSG(1,(TEXT("PSConfig start1\r\n")));
/*
// Initialise com port
if(!Initialise(chComPort)) // Setup port for communication
return FALSE;
*/
giPDUCount = 0;
giPDUCount = (sizeof(psdata) / sizeof(PSDATA));
if(giPDUCount == 0)
return FALSE; // No data
gPDU = new BCCMDPDU[giPDUCount + 1]; // Last pdu is warm reset
giPDUCount = 0; // Reset to zero and load pdu array
ReadPSKey(sizeof(psdata) / sizeof(PSDATA));
giPDUCount++; // Extra reset pdu
ConfigResetPDU();
// Setup packets payload
SendPacket.payload = chSendBuffer;
ReceivePacket.payload = chReceiveBuffer;
ReceivePacket.length = 512;
// Ask ubcsp to receive a packet
ubcsp_receive_packet (&ReceivePacket);
uBCSP_TXQueue.CommandNumber = RECEIVED_STATE;
uBCSP_TXQueue.NoOfOpcodes = 0;
uBCSP_TXQueue.NoOfRetries = 0;
// Start Link establishment timer
giStartTime = GetTickCount();
// Reset packet counter
bLastSentPacket = FALSE;
// Enter loop to 'listen' to uBCSP commands
while(gbBTPower)
{
switch(uBCSP_TXQueue.CommandNumber)
{
case POLL_STATE:
{
// Poll uBCSP for activity
iDelay = ubcsp_poll (&chActivity);
uBCSP_TXQueue.CommandNumber = RECEIVED_STATE;
RETAILMSG(PS_DBG,(TEXT("POLL_STATE\r\n")));
// Link Init check
if((GetTickCount() - giStartTime > LINKTIMEOUT) && !gbLinked)
{
RETAILMSG(PS_DBG,(TEXT("!!!! Link time out !!!!\r\n")));
uBCSP_TXQueue.CommandNumber = EXIT_STATE;
}
if(ubcsp_config.link_establishment_state > 0)
gbLinked = TRUE;
}
break;
case RECEIVED_STATE:
{
RETAILMSG(PS_DBG,(TEXT("RECEIVED_STATE ac=%x\r\n"),chActivity));
uBCSP_TXQueue.CommandNumber = PEER_RESET_STATE;
if(chActivity & UBCSP_PACKET_RECEIVED)
GetReceiveState(&ReceivePacket, chReceiveBuffer);
if(chActivity & UBCSP_PACKET_SENT)
{
// Acknowledge sent package
if(!bLastSentPacket)
{
// Link is established
RETAILMSG(PS_DBG,(TEXT("Link is now Established\r\n")));
uBCSP_TXQueue.CommandNumber = SENT_STATE;
}
bLastSentPacket = TRUE;
}
}
break;
case SENT_STATE:
{
// Returns the appropriate next state
RETAILMSG(PS_DBG,(TEXT("SENT_STATE\r\n")));
GetSentState(&SendPacket);
}
break;
case PEER_RESET_STATE:
{
RETAILMSG(PS_DBG,(TEXT("PSConfig peer reset state\r\n")));
//Jonathan1223a
if((chActivity & UBCSP_PEER_RESET) && giResetSent > 0)
{
// This function is wait uBCSP Peer Reset Activity
// and Send PSKey PDU finish command, Then will leave
// the CSR PSKey Update Function.--Jonathan1223a
// Peer reset detected
RETAILMSG(PS_DBG,(TEXT("uBCSP Peer Reset Received\r\n")));
uBCSP_TXQueue.CommandNumber = EXIT_STATE;
break;
}
uBCSP_TXQueue.CommandNumber = SLEEP_STATE;
RETAILMSG(PS_DBG,(TEXT("PEER_RESET_STATE : SLEEP_STATE\r\n")));
}
break;
case SLEEP_STATE:
{
RETAILMSG(PS_DBG,(TEXT("PSConfig sleep\r\n")));//jack debug
//BT_DBGMSG(TEXT("CSR sleep \r\n"));
if(iDelay)
{
// If we need to delay, sleep for minimum period
Sleep(1);
}
uBCSP_TXQueue.CommandNumber = POLL_STATE;
}
break;
case EXIT_STATE:
{
// Exit module
//BT_DBGMSG(TEXT("@exit\r\n"));
ExitMod();
return 0;
}
break;
}
}
RETAILMSG(PS_DBG,(TEXT("PSConfig end\r\n")));
return 0;
}
/*//evan_note
int ReadPSRFile(FILE* ist, bool bBuild)
{
char linebuf[LineDatabufSize];
uint16 data[LineDatabufSize];
uint16 *pdata;
char *p, *end;
int key;
bool query_mode = false;
while (fgets(linebuf, LineDatabufSize, ist))
{
// Does it start with an &?
p = linebuf;
linebuf[LineDatabufSize - 1] = '\0';
end = &linebuf[strlen(linebuf)];
while ((p < end) && isspace(*p))
p++;
if (p == end)
continue;
if (*p == '?')
query_mode = true;
else if (*p != '&')
continue; // Not a valid line.
p++;
// Are there digits next?
key = 0;
while ((p < end) && isxdigit(*p))
{
key = (key * 16) + Hex2Int(*p);
p++;
}
if (key == 0)
continue;
while ((p < end) && isspace(*p))
p++;
if (p == end)
{ // No operation?
continue; // Next line please.
}
// Read the operation
if (*p != '=')
continue; // Next line please.
if (p < end)
p++;
// Key counter
giPDUCount++;
if(bBuild) // If building pdu array read data and set key
{
// Read the data
pdata = data;
for (;;)
{
while ((p < end) && isspace(*p))
p++;
if (p == end)
break;
if (*p == '\"')
{
p++;
while (p < end)
{
*pdata++ = *p++;
}
break;
}
else
{
if (p >= end || (!isxdigit(*p)))
break;
*pdata = 0;
while ((p < end) && isxdigit(*p))
{
*pdata = (*pdata * 16) + Hex2Int(*p);
p++;
}
pdata++;
}
}
// Create pdu
ConfigPSRPDU(key, data, pdata-data);
//BT_DBGMSG(TEXT("Read file key=%x\r\n"),key);
}
}
return giPDUCount;
}
*///evan_note
int ReadPSKey(DWORD Count)
//int ReadPSKey(bool bBuild)
{
PSDATA *pskeydata;
DWORD i;
//RETAILMSG(PS_DBG,(TEXT("ReadPSKey=%d\r\n"),Count));
pskeydata = psdata;
for(i =0 ; i < Count; i++)
{
giPDUCount++;
ConfigPSRPDU(pskeydata->pskey, pskeydata->data, pskeydata->len);
pskeydata++;
}
return giPDUCount;
}
// BCCMD Protocol : "Message Structure"
// ----------------------------------------------------------------------------------
// | Type | Pdulen | seqno | varid | status | Pay .... load |
// ----------------------------------------------------------------------------------
// uint16s | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
// bytes | 1 ..... 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
// |<--------------- Header --------------->|<------------- payload --------------->|
// |<---------------------------------- Message ----------------------------------->|
void ConfigPSRPDU(const pskey key, const uint16 *data, uint16 len )
{
// Construct data unit
//RETAILMSG(PS_DBG,(TEXT("ConfigPSRPDU+++\n")));
BCCMDPDU *p = (BCCMDPDU *)malloc(BCCMDPDU_MAXBUFSIZ_PC);
memset(p, 0, BCCMDPDU_MAXBUFSIZ_PC);
p->type = BCCMDPDU_SETREQ;
if (len > MAX_PS_VALUE_LEN_XAP)
len = (uint16)MAX_PS_VALUE_LEN_XAP;
p->pdulen = BCCMDPDUMIN + len; // XAP_PDU_LEN(len);
p->seqno = giPDUCount;
p->varid = BCCMDVARID_PS; // Persistent store
p->status = BCCMDPDU_STAT_OK;
p->d.ps.id = key;
p->d.ps.len = len;
p->d.ps.stores = stores_;
// Assign pdu to global array
gPDU[giPDUCount-1] = *p; // *** Confirm doing this doesn't clobber anything
memcpy(gPDU[giPDUCount-1].d.ps.psmem, data, PC_SIZE(len)); // *** ie. pointer to something already malloc'd ?
free(p );
//RETAILMSG(PS_DBG,(TEXT("ConfigPSRPDU---\n")));
}
void ConfigResetPDU()
{
// Write reset pdu
//RETAILMSG(1,(TEXT("ConfigResetPDU+++\n")));
BCCMDPDU *p = (BCCMDPDU *)malloc(BCCMDPDU_MAXBUFSIZ_PC);
memset(p, 0, BCCMDPDU_MAXBUFSIZ_PC);
p->type = BCCMDPDU_SETREQ;
p->pdulen = BCCMDPDUMIN + 1;
p->varid = BCCMDVARID_WARM_RESET;
p->status = BCCMDPDU_STAT_OK;
gPDU[giPDUCount-1] = *p;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -