📄 gpsid.cpp
字号:
/******************************************************************************* * * G p s I D * ******************************************************************************/#include "stdafx.h"#include <winioctl.h>#include <windows.h>#include <pkfuncs.h>#include "gpioHardware.h"#include "spiDriver.h"#include "gpsDeviceDriver.h"#include "cust_debug.h"#include "cust_hw_spi.h"#include "xllp_ssp.h"#include "xllp_ost.h"#include "bulverde_clkmgr.h"#include "bulverde_gpio.h"#include "wit_gpiomap.h"#include "gpsSerialControl.h"UINT8SPI_Exchange_Bytes(UINT8 cmd, const UINT8* pIn, UINT8* pOut, DWORD& sizeIn);extern volatile XLLP_GPIO_T* v_pGPIORegs;extern volatile XLLP_SSP_REGS* v_pSPIRegs;extern volatile XLLP_CLKMGR_T* v_pClockRegs;//------------------------------------------------------------------------------//// GPS Disable.//// 1) remove standby// 2) apply reset// 3) remove power////------------------------------------------------------------------------------static void GpioDisable(void){ #ifdef GPS_GPIO_STANDBY_EXISTS // { 6 v_pGPIORegs->GPCR_STANDBY = GPS_GPIO_STANDBY_EXISTS; v_pGPIORegs->GPDR_STANDBY |= GPS_GPIO_STANDBY_EXISTS; #endif // } GPS_GPIO_STANDBY_EXISTS#if 0 // { Dangerous to do this all the time. #ifdef GPS_GPIO_POWER_EXISTS // { 5 v_pGPIORegs->GPCR_POWER = GPS_GPIO_POWER_EXISTS; v_pGPIORegs->GPDR_POWER |= GPS_GPIO_POWER_EXISTS; #endif // } GPS_GPIO_POWER_EXISTS #ifdef GPS_GPIO_RESET_EXISTS // { 4 v_pGPIORegs->GPCR_RESET = GPS_GPIO_RESET_EXISTS; v_pGPIORegs->GPDR_RESET |= GPS_GPIO_RESET_EXISTS; #endif // } GPS_GPIO_RESET_EXISTS#endif // }}//------------------------------------------------------------------------------//// GPS Enable.//// 1) disable device// 2) apply power// 3) remove reset// 4) remove standby////------------------------------------------------------------------------------static void GpioEnable(void){ GpioDisable();#ifdef GPS_GPIO_RESET_EXISTS // { 4 v_pGPIORegs->GPSR_RESET = GPS_GPIO_RESET_EXISTS; v_pGPIORegs->GPDR_RESET |= GPS_GPIO_RESET_EXISTS; Sleep(1);#endif // } GPS_GPIO_RESET_EXISTS#ifdef GPS_GPIO_POWER_EXISTS // { 5 v_pGPIORegs->GPSR_POWER = GPS_GPIO_POWER_EXISTS; v_pGPIORegs->GPDR_POWER |= GPS_GPIO_POWER_EXISTS; Sleep(1);#endif // } GPS_GPIO_POWER_EXISTS#ifdef GPS_GPIO_STANDBY_EXISTS // { 6 v_pGPIORegs->GPSR_STANDBY = GPS_GPIO_STANDBY_EXISTS; v_pGPIORegs->GPDR_STANDBY |= GPS_GPIO_STANDBY_EXISTS;#endif // } GPS_GPIO_STANDBY_EXISTS}//------------------------------------------------------------------------------//// getGpsDeviceID()//// Simple means to get device ID of GPS chip.//// Note: this is enabled only for debug & test because we normally// should not be touching device I/O inside the device driver// without being told to do so by the HABI.////------------------------------------------------------------------------------const unsigned char SmallReply_GL20000 [] = {0xfe,0x00,0xfd,0xc0,0x00,0x71, 0x45,0x03,0x10,0xfc};const unsigned char SmallReply_Mantaray [] = {0xfe,0x00,0xfd,0xc0,0x00,0xF1, 0x71,0x07,0x10,0xfc};const unsigned char SmallReply_Hammerhead [] = {0xfe,0x00,0xfd,0xc0,0x00,0xF2, 0x71,0x09,0x10,0xfc};bool GetGpsDeviceID(void){ bool result = false; UINT8 sr; ///////////////////////////////////////////// // Turn on device ///////////////////////////////////////////// ///////////////////////////////////////////// // Send command ///////////////////////////////////////////// const unsigned char SmallCmd[] = {0xff,0x00,0xfd,0xc0,0x00,0xfc}; enum { CMD_SIZE = sizeof(SmallCmd) }; unsigned char dummyRead[CMD_SIZE] = {0}; DWORD txCount = CMD_SIZE; sr = SPI_Exchange_Bytes(GL_SPI_WRITE_DATA, SmallCmd, dummyRead, txCount); if (txCount != CMD_SIZE) { GL_ERROR((TEXT("GetGpsType()/%d command write failed %d 0x%x\n\r"), __LINE__, txCount, sr)); } ///////////////////////////////////////////// // Get Reply ///////////////////////////////////////////// enum { REPLY_SIZE = sizeof(SmallReply_Mantaray) }; const unsigned char dummyWrite[REPLY_SIZE] = {0}; unsigned char SmallReply[REPLY_SIZE] = {0}; DWORD rxCount = REPLY_SIZE; sr = SPI_Exchange_Bytes(GL_SPI_READ_DATA, dummyWrite, SmallReply, rxCount); if (rxCount != REPLY_SIZE) { GL_ERROR((TEXT("GetGpsType()/%d command read failed %d 0x%x\n\r"), __LINE__, txCount, sr)); } else { ///////////////////////////////////////////// // Compare GPS Device ID ///////////////////////////////////////////// GL_DEBUG_PACKET(MSG("GetGpsDeviceID"), SmallReply, rxCount); const TCHAR* gpsType = TEXT("unknown"); if (memcmp(SmallReply, SmallReply_GL20000, rxCount) == 0) { gpsType = TEXT("GL-20000"); result = true; } else if (memcmp(SmallReply, SmallReply_Mantaray, rxCount) == 0) { gpsType = TEXT("Mantaray"); result = true; } else if (memcmp(SmallReply, SmallReply_Hammerhead, rxCount) == 0) { gpsType = TEXT("Hammerhead"); result = true; } GL_ERROR((TEXT("GPS device \"%s\" found\n\r"), gpsType)); } ///////////////////////////////////////////// // Turn off device ///////////////////////////////////////////// return result;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -