⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gps.c

📁 gps code include 頭文件和源程序
💻 C
字号:
/**************************************************************************************
* GPS.c
*-------------------------------------------------------------------------------------------------
* Function: Test GPS module UART connection 
*---------------------------------------------------------------
* Author: 
*---------------------------------------------------------------
* revision 0.0		init code,move from Flying Pig plantform  Jason	2007/8/10    
*				Fix display bugs					    Jason 2007/8/13
*
*/
#include <string.h>
#include <stdlib.h>
#include "2442addr.h"
#include "2442lib.h"
#include "def.h"
#include "gps.h"
#include "AS3604_power.h"

#include <stdarg.h>
#include <stdio.h>
#include <ctype.h>

extern U32 Fclk, Pclk;

#define MTX_INTTYPE 1	//0:Tx interrupt type is pulse, 1:Tx interrupt type is level
#define MRX_INTTYPE 1	//0:Rx interrupt type is pulse, 1:Rx interrupt type is level

static U32 isRx1Int, isRx2Int;
static U32 rx_cnt=0;
static U32 rx_end=0;

static char Rx1_temp[512];
static int Rx1_temp_count = 0;

char Rx2_temp[512];
int Rx2_temp_count = 0;


void __irq GUart2_RxOrErr(void);
void __sub_GUart2_Rx(void);
void __sub_GUart2_RxErrInt(void);

void __irq GUart1_RxIntOrErr(void);
void __sub_GUart1_RxInt(void);
void __sub_GUart1_RxErrInt(void);

void __irq GUart2_RxOrErr(void)
{

    rINTSUBMSK|=(BIT_SUB_RXD2|BIT_SUB_TXD2|BIT_SUB_ERR2);
    if(rSUBSRCPND&BIT_SUB_RXD2) __sub_GUart2_Rx();
    else __sub_GUart2_Rx();
    ClearPending(BIT_UART2);
    rSUBSRCPND=(BIT_SUB_RXD2|BIT_SUB_ERR2);	// Clear Sub int pending    
    rINTSUBMSK&=~(BIT_SUB_RXD2|BIT_SUB_ERR2);  
    
/*    
//    Rx1_temp[0]=0;
//    Rx1_temp[1]=0;
    rINTSUBMSK|=(BIT_SUB_RXD2|BIT_SUB_TXD2|BIT_SUB_ERR2);
    if(rSUBSRCPND&BIT_SUB_RXD2) __sub_GUart2_Rx();    
//    else __sub_GUart2_RxErrInt();//cut by Jason for testing 070813

    ClearPending(BIT_UART2);
    rSUBSRCPND=(BIT_SUB_RXD2|BIT_SUB_TXD2|BIT_SUB_ERR2);
    rINTSUBMSK&=~(BIT_SUB_RXD2|BIT_SUB_TXD2|BIT_SUB_ERR2);
*/
}

void __sub_GUart2_Rx(void)
{
	U8 temp8;
	while(rUFSTAT2 & 0x7f )
	{
//		Delay(1000);//no delay is needed here

		Uart_Printf("%c",rURXH2);
		//Uart_Printf(".");
   	}
   	//isRx2Int=0;
    //	rINTMSK|=BIT_UART2;
}

void __sub_GUart2_RxErrInt(void)
{
	U32 iStatus;

	iStatus = rUERSTAT2;

	Uart_Select(2);
	Uart_Printf("Uart2 Rx error!\n");

    switch(iStatus)//to clear and check the status of register bits
    {
	case 1:
	    Uart_Printf("Overrun error!\n");
	    break;
	case 2:
	    Uart_Printf("Parity error!\n");
	    break;
	case 4:
	    Uart_Printf("Frame error!\n");
	    break;
	case 6:
	    Uart_Printf("Parity, Frame error!\n");
	    break;
	case 8:
		Uart_Printf("Breake detect\n");
		break;
	case 0xa:
		Uart_Printf("Parity error & Break detect!\n");
		break;
	case 0xc:
		Uart_Printf("Frame error & Breake detect\n");
		break;
	case 0xe:
		Uart_Printf("Parity, Frame error & Break detect!\n");
		break;
	default :
		Uart_Printf("Unknown error : 0x%x\n", iStatus);
	    break;
    }
	
   	isRx2Int=0;
}

void __irq GUart1_RxIntOrErr(void)
{
    rINTSUBMSK|=(BIT_SUB_RXD1|BIT_SUB_TXD1|BIT_SUB_ERR1);
    if(rSUBSRCPND&BIT_SUB_RXD1) __sub_GUart1_RxInt();
    else __sub_GUart1_RxErrInt();

    ClearPending(BIT_UART1);
    rSUBSRCPND=(BIT_SUB_RXD1|BIT_SUB_ERR1);	// Clear Sub int pending    
    rINTSUBMSK&=~(BIT_SUB_RXD1|BIT_SUB_ERR1);   
}

void __sub_GUart1_RxInt(void)
{
    int i;

    if(RdURXH1()!='\r') 
    {
       while(!(rUTRSTAT2 & 0x2));
       Delay(10);                 //because the slow response of hyper_terminal 
       rUTXH2 = RdURXH1();

	//for Uart1 Echo
    	//Uart_TxEmpty(1); //wait until tx buffer is empty.
       rUTXH1 = RdURXH1();
		
       Rx1_temp[Rx1_temp_count] = (char)RdURXH1();
       Rx1_temp_count++;
    }
    else
    {
    	isRx1Int=0;
       while(!(rUTRSTAT2 & 0x2));
       Delay(10);                 //because the slow response of hyper_terminal 
       rUTXH2 = '\r';

	//for Uart1 Echo
    	//Uart_TxEmpty(1); //wait until tx buffer is empty.
       rUTXH1 = '\r';
    }
}

void __sub_GUart1_RxErrInt(void)
{
    Uart_Select(1);
    Uart_Printf("Uart1 Rx error!\n");
	
    switch(rUERSTAT1)//to clear and check the status of register bits
    {
	case 1:
	    Uart_Printf("Overrun error\n");
	    break;
	case 2:
	    Uart_Printf("Parity error\n");
	    break;
	case 4:
	    Uart_Printf("Frame error\n");
	    break;
	case 8:
	    Uart_Printf("Breake detect\n");
	    break;
	default :
	    break;
    }
   	isRx1Int=0;
}



void GPS_Test(void)
{
	int i;
	long counter;

	Uart_Printf("\nThis is the test for GPS...\n");
	Uart_Printf("\nPlease type anykey then type enter.\n\n");

	rGPHCON = rGPHCON&~(0xf<<12) | (0x8a<<8);//port function set - UART2,UART1/0 set input 

	rCLKCON |= (1<<12);	//uart2 PCLK enable

	rUCON2 &= ~(3<<10);	// Select PCLK
	rUCON2 &= ~(3<<2);
	rUCON2 |= (1<<2);	
	rUBRDIV2=( (int)(66666666/16./115200+0.5) -1 );	//Baud rate divisior register
										//Glonva GPS chip Baud rate is 115200
	//--------------------------------------------------------------------------
	// Add P8 power manage GPS part
	//-------------------------------------------------------------------------
#if 1// for GPS power on test 


  ////power off first 

    LDO_17_GPS_IO_RFD_POC_OFF();//power off 2.5V
   	
	Delay(10);
	LDO_5_GPS_ANT_OFF();//power off 2.85v
	Delay(10);

	LDO_18_GPS_RFA_RFL_OFF();//power off 1.8
	Delay(10);

	LDO_15_GPS_Core_OFF();//power off 1.2 core
    	Delay(10);

////end 
    
    LDO_17_GPS_IO_RFD_POC_ON();//power on 2.5V
   	
	Delay(10);
	LDO_5_GPS_ANT_ON();//power on 2.85v
	Delay(10);

	LDO_18_GPS_RFA_RFL_ON();//power on 1.8
	Delay(10);

	LDO_15_GPS_Core_ON();//power on 1.2 core
    	Delay(10);

	Uart_Printf(" \n\n Done GPS Power supply\n\n");
	Uart_TxEmpty(1);
	Uart_Select(1);
	
	// gps reset : ows
	//Uart_Printf(" \n\n gpccon = %08x\n\n",rGPCCON);
	//rGPCCON &= ~(0x3<<0)|(0x1);
	//Uart_Printf(" \n\n gpccon = %08x\n\n",rGPCCON);
	
	rGPCDAT &= ~(0x1<<0);
	Delay(5000);
	rGPCDAT |= (0x1<<0);
		
#endif


//	pISR_UART1 = (unsigned)GUart1_RxIntOrErr;
	pISR_UART2=(unsigned)GUart2_RxOrErr;

    rULCON2=(0<<6)|(0<<3)|(0<<2)|(3);	// No(rmal,No parity,One stop bit, 8bit
    rUCON2 |= (1<<9)|(1<<8)|(1<<7)|(1<<6)|(0<<5)|(0<<4)|(1<<2)|(1);
    //Clock,Tx:Def,Rx:Def,Rx timeout:o,Rx error int:o,Loop-back:x,Send break:x,Tx:int,Rx:int
    rUFCON2=(3<<6)|(3<<4)|(1<<2)|(1<<1)|(1);
    //Tx and Rx FIFO Trigger Level:4byte,Tx and Rx FIFO Reset,FIFO on

    // Clear Int Pending and Unmask 
    ClearPending(BIT_UART2);

	rINTMSK |= (BIT_UART0|BIT_UART1);
	rINTSUBMSK|=(BIT_SUB_RXD0|BIT_SUB_TXD0|BIT_SUB_ERR0);

    rINTMSK&=~(BIT_UART2);
    rSUBSRCPND&=~(BIT_SUB_RXD2|BIT_SUB_TXD2|BIT_SUB_ERR2);
    rINTSUBMSK&=~(BIT_SUB_RXD2|BIT_SUB_ERR2);
	
	//Uart_TxEmpty(1);
	  //	Uart_TxEmpty(2);
    while(!Uart_GetKey());


}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -