Subversion Repositories NaviCtrl

Compare Revisions

Ignore whitespace Rev 37 → Rev 38

/branches/V0.1 killagreg/i2c.c
65,7 → 65,7
#include "spi_slave.h"
 
 
volatile I2C_State_t I2C_State;
volatile I2C_State_t I2C_State = I2C_OFF;
 
// rxbuffer
volatile u8 I2C_RxBufferSize;
193,6 → 193,8
//--------------------------------------------------------------
void I2C1_Deinit(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
 
SerialPutString("\r\n I2C deinit...");
I2C_GenerateStart(I2C1, DISABLE);
I2C_GenerateSTOP(I2C1, ENABLE);
201,6 → 203,16
I2C_Cmd(I2C1, DISABLE);
I2C_DeInit(I2C1);
SCU_APBPeriphClockConfig(__I2C1, DISABLE);
// set ports to input
SCU_APBPeriphClockConfig(__GPIO2, ENABLE);
GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3;
GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull;
GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Disable;
GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1;
GPIO_Init(GPIO2, &GPIO_InitStructure);
 
I2C_TxBuffer = NULL;
Tx_Idx = 0;
210,7 → 222,7
Rx_Idx = 0;
I2C_RxBufferSize = 0;
 
I2C_State = I2C_UNDEF;
I2C_State = I2C_OFF;
 
I2C1_Timeout = 0;
I2C_Heading.Heading = -1;
/branches/V0.1 killagreg/i2c.h
52,6 → 52,7
I2C_TX_PROGRESS,
I2C_RX_PENDING,
I2C_RX_PROGRESS,
I2C_OFF
} I2C_State_t;
 
extern volatile I2C_State_t I2C_State;
/branches/V0.1 killagreg/main.c
200,29 → 200,32
UART1_Transmit(); // empty txd buffer
// ------------------------- I2C Timing --------------------------------
if (CheckDelay(TimerCompassUpdate))
if(I2C_State != I2C_OFF)
{
// check for hanging I2C bus
if(CheckDelay(I2C1_Timeout))
{ // reset I2C
I2C1_Deinit();
I2C1_Init();
}
else
{ // check for incomming compass calibration request
if(CompassCalcStateFiFo.count)
{
I2C1_SendCommand(I2C_CMD_WRITE_CAL);
if (CheckDelay(TimerCompassUpdate))
{
// check for hanging I2C bus
if(CheckDelay(I2C1_Timeout))
{ // reset I2C
I2C1_Deinit();
I2C1_Init();
}
else // request current heading
{
I2C1_SendCommand(I2C_CMD_READ_HEADING);
}
TimerCompassUpdate = SetDelay(25); // every 25 ms
}
else
{ // check for incomming compass calibration request
if(CompassCalcStateFiFo.count)
{
I2C1_SendCommand(I2C_CMD_WRITE_CAL);
}
else // request current heading
{
I2C1_SendCommand(I2C_CMD_READ_HEADING);
}
TimerCompassUpdate = SetDelay(25); // every 25 ms
}
}
}
}
// ---------------- Debug Timing ----------------------------------
if (CheckDelay(TimerDebugDataDelay))
{
/branches/V0.1 killagreg/uart1.c
59,6 → 59,7
#include "menu.h"
#include "printf_P.h"
#include "GPS.h"
#include "i2c.h"
#include "uart0.h"
#include "uart1.h"
#include "uart2.h"
455,6 → 456,7
DebugUART = UART2;
break;
case UART_MK3MAG:
I2C1_Deinit();
UART0_Connect_to_MK3MAG(); // mux UART0 to MK3MAG pins
DebugUART = UART0;
break;
/branches/V0.1 killagreg/ubx.c
175,7 → 175,6
DateTime_t GPSDateTime = {0,0,0,0,0,0,0, INVALID};
 
 
 
//------------------------------------------------------------------------------------
// functions
 
276,32 → 275,50
/********************************************************/
void Update_GPSData (void)
{
if ((UbxSol.Status == NEWDATA) && (UbxPosLlh.Status == NEWDATA) && (UbxVelNed.Status == NEWDATA))
{
LED_RED_TOGGLE;
// update GPS data only if the status is INVALID or PROCESSED
if(GPSData.Status != NEWDATA) // if last data were processed
{ // wait for new data at all neccesary ubx messages
GPSData.Status = INVALID;
// NAV SOL
GPSData.Flags = UbxSol.Flags;
GPSData.NumOfSats = UbxSol.numSV;
GPSData.SatFix = UbxSol.GPSfix;
GPSData.Position_Accuracy = UbxSol.PAcc;
GPSData.Speed_Accuracy = UbxSol.SAcc;
SetGPSTime(&SystemTime); // update system time
// NAV POSLLH
GPSData.Longitude = UbxPosLlh.LON;
GPSData.Latitude = UbxPosLlh.LAT;
GPSData.Altitude = UbxPosLlh.HMSL;
// NAV VELNED
GPSData.Speed_East = UbxVelNed.VEL_E;
GPSData.Speed_North = UbxVelNed.VEL_N;
GPSData.Speed_Top = -UbxVelNed.VEL_D;
GPSData.Speed_Ground = UbxVelNed.GSpeed;
GPSData.Status = NEWDATA; // new data available
}
static u32 Ubx_Timeout = 0;
static u8 Msg_Count = 0;
 
// the timeout is used to detect the delay between two message sets
// and is used for synchronisation so that always a set is collected
// that belongs together
// _______NAVSOL|POSLLH|VELNED|___________________NAVSOL|POSLLH|VELNED|_____________
// | 8ms | 8ms | 184 ms | | |
// msg_count: 0 1 2 0 1 2
if(CheckDelay(Ubx_Timeout)) Msg_Count = 0;
else Msg_Count++;
Ubx_Timeout = SetDelay(100); // reset ubx msg timeout
// if a new set of ubx messages was collected
if((Msg_Count >= 2))
{ // if set is complete
if((UbxSol.Status == NEWDATA) && (UbxPosLlh.Status == NEWDATA) && (UbxVelNed.Status == NEWDATA))
{
LED_RED_TOGGLE;
// update GPS data only if the status is INVALID or PROCESSED and the last ubx message was received within less than 100 ms
if((GPSData.Status != NEWDATA)) // if last data were processed
{ // wait for new data at all neccesary ubx messages
GPSData.Status = INVALID;
// NAV SOL
GPSData.Flags = UbxSol.Flags;
GPSData.NumOfSats = UbxSol.numSV;
GPSData.SatFix = UbxSol.GPSfix;
GPSData.Position_Accuracy = UbxSol.PAcc;
GPSData.Speed_Accuracy = UbxSol.SAcc;
SetGPSTime(&SystemTime); // update system time
// NAV POSLLH
GPSData.Longitude = UbxPosLlh.LON;
GPSData.Latitude = UbxPosLlh.LAT;
GPSData.Altitude = UbxPosLlh.HMSL;
// NAV VELNED
GPSData.Speed_East = UbxVelNed.VEL_E;
GPSData.Speed_North = UbxVelNed.VEL_N;
GPSData.Speed_Top = -UbxVelNed.VEL_D;
GPSData.Speed_Ground = UbxVelNed.GSpeed;
GPSData.Status = NEWDATA; // new data available
} // EOF if(GPSData.Status != NEWDATA)
} // EOF all ubx messages received
// set state to collect new data
UbxSol.Status = PROCESSED; // ready for new data
UbxPosLlh.Status = PROCESSED; // ready for new data