Exemple #1
0
ER GPSRec_Open(UART_BAUDRATE BaudRate)
{

    if (bGPSRecOpened)
        return E_SYS;

    #if (RECEIVE_FROM_UART2)
    if (uart2_open() == E_OK)
    #else
    if (uart_open() == E_OK)
    #endif
    {
        debug_msg("\r\nUART2: Open success\r\n");
        #if (RECEIVE_FROM_UART2)
        uart2_init(BaudRate, UART_LEN_L8_S1, UART_PARITY_NONE);
        #else
        uart_init(BaudRate, UART_LEN_L8_S1, UART_PARITY_NONE);
        #endif

    }
    else
    {
        debug_err(("UART2: open fail!\r\n"));
        return E_SYS;
    }

    debug_msg("Start GPS receive task\r\n");
    sta_tsk(GPSRECEIVE_ID,0);

    loc_cpu();
    bGPSRecOpened = TRUE;
    unl_cpu();

    return E_OK;
}
/**************************************************
* Function name		: void main(void)
*
* Created by		: Luca Lucci
* Date created		: 07/10/12
* Description		: Main program entry point
* Notes				: -
**************************************************/
void main(void)
{
  initialize_system();

    // initialize usart
  uart_init();
  uart2_open();

  // initialize interrupt
  INTCON2bits.INTEDG0 = 0;	// falling edge int0 interrupt
  INTCONbits.INT0IE = 1;	// enable int0 interrupt
  INTCONbits.INT0IF = 0;
  INTCONbits.PEIE = 1;		// enable peripheral interrupts
  INTCONbits.GIE = 1;		// enable global interrupt
  

  while(1) 
  {
    ClrWdt();
    
    // if the buffer isn't empty will send back the data
    if(uart2_buffer_read(temp))
      uart2_buffer_tx_load(temp);

    // ProcessIO
  }
}//main()
Exemple #3
0
void gps_init(struct GpsConfig *gpsconfig)
{
	gps_open_port(gpsconfig);
		
	// Wait for GPS output. On some old EB85 devices, this can take over 2sec
	if (rmc_sentence_number == -1 && nmea_buffer_RMC_counter == 0)
		microcontroller_delay_ms(10);
	if (rmc_sentence_number == -1 && nmea_buffer_RMC_counter == 0)
		microcontroller_delay_ms(50);
	if (rmc_sentence_number == -1 && nmea_buffer_RMC_counter == 0)
		microcontroller_delay_ms(100);
	if (rmc_sentence_number == -1 && nmea_buffer_RMC_counter == 0)
		microcontroller_delay_ms(200);		
	if (rmc_sentence_number == -1 && nmea_buffer_RMC_counter == 0)
		microcontroller_delay_ms(400);	 // 760ms
	if (rmc_sentence_number == -1 && nmea_buffer_RMC_counter == 0)
		microcontroller_delay_ms(800);	 // 1560ms
	if (rmc_sentence_number == -1 && nmea_buffer_RMC_counter == 0)
		microcontroller_delay_ms(1000);	 // 2560ms

	if (rmc_sentence_number == -1 && nmea_buffer_RMC_counter == 0)
	{
		uart1_puts("timeout...");
		uart2_open(115200l);
		return;	// Don't return? If module was rebooted, but GPS not, then we need to change the speed for the GPS module to become accessible
	}

	// First we configure which sentences we want. If the unit outputs all sentences at 5Hz by default, then 38400 will be too slow 
	// and the unit won't allow us to change the baudrate.
	
	gps_config_output(gpsconfig);
}
Exemple #4
0
// Configs the GPS using MTK sentences to use RMC & GGA sentences at 5Hz, and switch to 115200 baud
void gps_config_output(struct GpsConfig *gpsconfig)
{
	// Change to 115200 baud
	
	uart2_puts("$PMTK251,115200*1F\r\n");  // this can take a while if no GPS is connected
	microcontroller_delay_ms(10);
	uart2_open(115200l);
	
	// only RMC and GGA
	// RMC & GGA
	uart2_puts("$PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*28\r\n");  // this can take a while if no GPS is connected
	microcontroller_delay_ms(10);	

	// 5Hz mode
	microcontroller_delay_ms(10);
	uart2_puts("$PMTK220,200*2C\r\n");

    if (gpsconfig->enable_waas)
    {
        microcontroller_delay_ms(10);
        // DGPS data source mode
        // ?0?: No DGPS source
        // ?1?: RTCM
        // ?2?: WAAS
        microcontroller_delay_ms(10);
        uart2_puts("$PMTK301,2*2E\r\n");

        // Enable to search a SBAS satellite or not
        // ?0? = Disable
        // ?1? = Enable
        microcontroller_delay_ms(10);
        uart2_puts("$PMTK313,1*2E\r\n");
    }
}
Exemple #5
0
// Open the GPS uart port and start receiving messages
void gps_open_port(struct GpsConfig *gpsconfig)
{
	//uart2_open(4800l);    // For Locosys module
	//uart2_open(38400l);    // For Old EB-85
	//uart2_open(38400l);    // For San Jose EB-85
	
	uart2_open(gpsconfig->initial_baudrate);


	IFS1bits.U2RXIF = 0;	// Clear the Recieve Interrupt Flag
	IEC1bits.U2RXIE = 1;
}	
Exemple #6
0
ER GPSRec_Open(UART_BAUDRATE BaudRate)
{

    if (bGPSRecOpened)
        return E_SYS;

    #if (RECEIVE_FROM_UART2)
    if (uart2_open() == E_OK)
    #else
    if (uart_open() == E_OK)
    #endif
    {
        debug_msg("\r\nUART2: Open success\r\n");
        #if (RECEIVE_FROM_UART2)
        uart2_init(BaudRate, UART_LEN_L8_S1, UART_PARITY_NONE);
        #else
        uart_init(BaudRate, UART_LEN_L8_S1, UART_PARITY_NONE);
        #endif

    }
    else
    {
        debug_err(("UART2: open fail!\r\n"));
        return E_SYS;
    }

    debug_msg("Start GPS receive task\r\n");

    //#NT#2011/1/14#philex Lin-begin
    // init/toggle GPS Data buffer index,
    // GPS log buffer is double buffering mechanism.
    GPSRec_DataBufInit();
    //#NT#2011/1/14#philex Lin-end
    sta_tsk(GPSRECEIVE_ID);

    loc_cpu();
    bGPSRecOpened = TRUE;
    unl_cpu();

    return E_OK;

}