Subversion Repositories NaviCtrl

Compare Revisions

Ignore whitespace Rev 246 → Rev 247

/trunk/main.c
352,7 → 352,7
SPI0_Init();
// initialize i2c bus (needs Timer 1)
I2C1_Init();
// initialize the gps position controller (needs Timer 1)
// initialize fat16 partition on sd card (needs Timer 1)
Fat16_Init();
// initialize NC params
NCParams_Init();
378,11 → 378,10
LED_RED_ON;
}
 
UART0_GetMKOSDVersion();
GPS_Init();
 
GPS_Init();
// initialize fat16 partition on sd card (needs Timer 1)
 
 
// ---------- Prepare the isr driven
// set to absolute lowest priority
VIC_Config(EXTIT3_ITLine, VIC_IRQ, PRIORITY_SW);
/trunk/settings.c
76,9 → 76,10
 
Parameter_t CFG_Parameter[] =
{
//{PID , "1234567890123456" , Group, Value, Default, Min, Max },
{PID_KML_LOGGING , "KMLLOGGING " , 1, 500, 500, 0, 60000}, // the log interval for KML logging, 0 = off
{PID_GPX_LOGGING , "GPXLOGGING " , 1, 1000, 1000, 0, 60000} // the log interval for GPX logging, 0 = off
//{PID , "1234567890123456" , Group, Value, Default, Min, Max },
{PID_KML_LOGGING , "KMLLOGGING " , 1, 500, 500, 0, 60000}, // the log interval for KML logging, 0 = off
{PID_GPX_LOGGING , "GPXLOGGING " , 1, 1000, 1000, 0, 60000}, // the log interval for GPX logging, 0 = off
{PID_GPS_AUTOCONFIG, "GPSAUTOCONFIG " , 1, 1, 1, 0, 1}
};
 
 
/trunk/settings.h
6,7 → 6,8
typedef enum
{
PID_KML_LOGGING,
PID_GPX_LOGGING
PID_GPX_LOGGING,
PID_GPS_AUTOCONFIG
} ParamId_t;
 
void Settings_Init(void);
/trunk/uart0.c
78,12 → 78,12
u16 Uart0MK3MagBaudrate = UART0_BAUD_RATE;
 
// the tx buffer
#define UART0_TX_BUFFER_LEN 200
#define UART0_TX_BUFFER_LEN 150
u8 UART0_tbuffer[UART0_TX_BUFFER_LEN];
Buffer_t UART0_tx_buffer;
 
// the rx buffer
#define UART0_RX_BUFFER_LEN 200
#define UART0_RX_BUFFER_LEN 150
u8 UART0_rbuffer[UART0_RX_BUFFER_LEN];
Buffer_t UART0_rx_buffer;
 
419,10 → 419,11
/**************************************************************/
/* Get the version of the MKOSD */
/**************************************************************/
void UART0_GetMKOSDVersion(void)
u8 UART0_GetMKOSDVersion(void)
{
u32 timeout;
u8 msg[64];
u8 retval = 0;
 
MKOSD_VersionInfo.SWMajor = 0xFF;
MKOSD_VersionInfo.SWMinor = 0xFF;
445,35 → 446,89
{
sprintf(msg, "\n\r MK-OSD V%d.%d%c", MKOSD_VersionInfo.SWMajor, MKOSD_VersionInfo.SWMinor, 'a'+MKOSD_VersionInfo.SWPatch);
UART1_PutString(msg);
retval = 1;
}
//else UART1_PutString("\n\r No version information from MK-OSD.");
//else UART1_PutString("\n\r No version information from MK-OSD.");
return(retval);
}
 
 
/**************************************************************/
/* Send a configuration message to the UBLOX device */
/* Send a message to the UBLOX device */
/**************************************************************/
u8 UART0_UBXSendCFGMsg(u8 Id, u8* pData, u16 Len)
u8 UART0_UBXSendMsg(u8* pData, u16 Len)
{
u32 timeout;
u8 retval = 0;
// check for connection to GPS
if(UART0_Muxer != UART0_MKGPS) return(retval);
// free the acknowledge buffer
UbxAck.Status = INVALID;
while(UART0_tx_buffer.Locked == TRUE) UART0_Transmit(); // output pending bytes in tx buffer;
UBX_CreateMsg(&UART0_tx_buffer, UBX_CLASS_CFG, Id, pData, Len); // build ubx message frame
UBX_CreateMsg(&UART0_tx_buffer, pData, Len); // build ubx message frame
while(UART0_tx_buffer.Locked == TRUE) UART0_Transmit(); // output pending bytes in tx buffer;
// check for acknowledge
timeout = SetDelay(500);
return(1);
}
 
/**************************************************************/
/* Send a configuration message to the UBLOX device */
/**************************************************************/
u8 UART0_UBXSendCFGMsg(u8* pData, u16 Len)
{
u32 timeout;
u8 retval = 0;
// if data are not a CFG MSG
if(pData[0]!= UBX_CLASS_CFG) return(retval);
// prepare rx msg filter
UbxMsg.Hdr.Class = UBX_CLASS_ACK;
UbxMsg.Hdr.Id = 0xFF;
UbxMsg.Hdr.Length = 0;
UbxMsg.ClassMask = 0xFF;
UbxMsg.IdMask = 0x00;
UbxMsg.Status = INVALID;
UART0_UBXSendMsg(pData, Len);
// check for acknowledge msg
timeout = SetDelay(100);
do
{
if(UbxAck.Status == NEWDATA) break;
if(UbxMsg.Status == NEWDATA) break;
}while(!CheckDelay(timeout));
if(UbxAck.Status == NEWDATA)
if(UbxMsg.Status == NEWDATA)
{ // 2 bytes payload
if((UbxMsg.Data[0] == pData[0]) && (UbxMsg.Data[1] == pData[1]) && (UbxMsg.Hdr.Length == 2)) retval = UbxMsg.Hdr.Id;
}
UbxMsg.Status = INVALID;
return(retval);
}
 
/**************************************************************/
/* Get Version Info from UBX Module */
/**************************************************************/
u8 UART0_GetUBXVersion(void)
{
u32 timeout;
u8 retval = 0xFF;
u8 ubxmsg[]={0x0A, 0x04, 0x00, 0x00}; //MON-VER
// prepare rx msg filter
UbxMsg.Hdr.Class = 0x0A;
UbxMsg.Hdr.Id = 0x04;
UbxMsg.Hdr.Length = 0;
UbxMsg.ClassMask = 0xFF;
UbxMsg.IdMask = 0xFF;
UbxMsg.Status = INVALID;
UART0_UBXSendMsg(ubxmsg, sizeof(ubxmsg));
// check for answer
timeout = SetDelay(100);
do
{
if((UbxAck.clsID == UBX_CLASS_CFG) && (UbxAck.msgID == Id)) retval = UbxAck.Ack;
if(UbxMsg.Status == NEWDATA) break;
}while(!CheckDelay(timeout));
if((UbxMsg.Hdr.Length >= 40) && (UbxMsg.Status == NEWDATA))
{
UbxMsg.Data[4] = 0; //Only the fisrt 4 chsracters
UbxMsg.Data[39] = 0;
UART1_PutString(" V");
UART1_PutString((u8*)&UbxMsg.Data);
UART1_PutString(" HW:");
UART1_PutString((u8*)&UbxMsg.Data[30]);
retval = UbxMsg.Data[0]-'0'; // major sw version
}
UbxAck.Status = INVALID;
UbxMsg.Status = INVALID;
return(retval);
}
/trunk/uart0.h
27,8 → 27,9
void UART0_Connect_to_MK3MAG(void);
void UART0_TransmitTxData(void);
void UART0_ProcessRxData(void);
void UART0_GetMKOSDVersion(void);
u8 UART0_UBXSendCFGMsg(u8 Id, u8* pData, u16 Len);
u8 UART0_GetMKOSDVersion(void);
u8 UART0_GetUBXVersion(void);
u8 UART0_UBXSendCFGMsg(u8* pData, u16 Len);
 
#endif //__UART0_H
 
/trunk/uart1.c
103,17 → 103,17
UART_TypeDef *DebugUART = UART1;
 
// the primary rx fifo
#define UART1_RX_FIFO_LEN 1024
#define UART1_RX_FIFO_LEN 512
u8 UART1_rxfifobuffer[UART1_RX_FIFO_LEN];
fifo_t UART1_rx_fifo;
 
// the rx buffer
#define UART1_RX_BUFFER_LEN 200
#define UART1_RX_BUFFER_LEN 150
u8 UART1_rbuffer[UART1_RX_BUFFER_LEN];
Buffer_t UART1_rx_buffer;
 
// the tx buffer
#define UART1_TX_BUFFER_LEN 200
#define UART1_TX_BUFFER_LEN 150
u8 UART1_tbuffer[UART1_TX_BUFFER_LEN];
Buffer_t UART1_tx_buffer;
 
/trunk/ubx.c
54,7 → 54,6
// + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// + POSSIBILITY OF SUCH DAMAGE.
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#include <string.h>
#include "91x_lib.h"
#include "uart1.h"
#include "ubx.h"
88,16 → 87,12
#define UBX_SYNC1_CHAR 0xB5
#define UBX_SYNC2_CHAR 0x62
// protocoll identifiers
#define UBX_CLASS_UNDEF 0x00
// navigation class
#define UBX_CLASS_NAV 0x01
#define UBX_ID_POSLLH 0x02
#define UBX_ID_SOL 0x06
#define UBX_ID_VELNED 0x12
// acknowledge class
#define UBX_CLASS_ACK 0x05
#define UBX_ID_ACK_NAK 0x00
#define UBX_ID_ACK_ACK 0x01
 
// ------------------------------------------------------------------------------------------------
// typedefs
 
172,7 → 167,7
volatile ubx_nav_sol_t UbxSol = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, INVALID};
volatile ubx_nav_posllh_t UbxPosLlh = {0,0,0,0,0,0,0, INVALID};
volatile ubx_nav_velned_t UbxVelNed = {0,0,0,0,0,0,0,0,0, INVALID};
volatile ubx_ack_t UbxAck = {0,0,0,INVALID};
volatile ubxmsg_t UbxMsg;
 
// shared buffer
gps_data_t GPSData = {200,{0,0,0,INVALID},0,0,0,0,0,0,0, INVALID};
272,7 → 267,7
UbxSol.Status = INVALID;
UbxPosLlh.Status = INVALID;
UbxVelNed.Status = INVALID;
UbxAck.Status = INVALID;
UbxMsg.Status = INVALID;
GPSData.Status = INVALID;
 
UBX_Timeout = SetDelay(2 * UBX_Timeout);
353,7 → 348,8
void UBX_RxParser(u8 c)
{
static ubxState_t ubxState = UBXSTATE_IDLE;
static u8 ubxclass = UBX_CLASS_UNDEF;
static u8 ubxclass;
static u8 ubxid;
static u16 msglen;
static u8 cka, ckb;
static u8 *ubxP, *ubxEp, *ubxSp; // pointers to data currently transfered
378,10 → 374,28
break;
 
case UBXSTATE_CLASS: // check message identifier
ubxid = c;
ubxState = UBXSTATE_LEN1;
cka = ubxclass + ubxid;
ckb = ubxclass + cka;
break;
 
case UBXSTATE_LEN1: // 1st message length byte
msglen = (u16)c; // lowbyte first
cka += c;
ckb += cka;
ubxState = UBXSTATE_LEN2;
break;
 
case UBXSTATE_LEN2: // 2nd message length byte
msglen += ((u16)c)<<8; // high byte last
cka += c;
ckb += cka;
 
switch(ubxclass)
{
case UBX_CLASS_NAV:
switch(c)
switch(ubxid)
{
case UBX_ID_POSLLH: // geodetic position
ubxP = (u8 *)&UbxPosLlh; // data start pointer
407,63 → 421,38
}
break;
 
case UBX_CLASS_ACK:
switch(c)
{
case UBX_ID_ACK_ACK:
UbxAck.Ack = 1;
break;
 
case UBX_ID_ACK_NAK:
UbxAck.Ack = 0;
break;
 
default:
ubxState = UBXSTATE_IDLE;
return;
default: // other classes
if(UbxMsg.Status == NEWDATA) ubxState = UBXSTATE_IDLE;
else if(((UbxMsg.Hdr.Class&UbxMsg.ClassMask) == (ubxclass&UbxMsg.ClassMask)) && ((UbxMsg.Hdr.Id&UbxMsg.IdMask) == (ubxid&UbxMsg.IdMask)))
{ // buffer is free and message matches to filter criteria
UbxMsg.Status = INVALID;
UbxMsg.Hdr.Class = ubxclass;
UbxMsg.Hdr.Id = ubxid;
UbxMsg.Hdr.Length = msglen;
ubxP = (u8 *)&(UbxMsg.Data); // data start pointer
ubxEp = (u8 *)(&UbxMsg + 1); // data end pointer
ubxSp = (u8 *)&UbxMsg.Status; // status pointer
}
ubxP = (u8 *)&(UbxAck.clsID); // data start pointer
ubxEp = (u8 *)(&UbxAck + 1); // data end pointer
ubxSp = (u8 *)&UbxAck.Status; // status pointer
else ubxState = UBXSTATE_IDLE;
break;
 
default: // unsupported class
ubxState = UBXSTATE_IDLE;
break;
}
if (ubxState != UBXSTATE_IDLE)
if(ubxState != UBXSTATE_IDLE)
{
ubxState = UBXSTATE_LEN1;
cka = UBX_CLASS_NAV + c;
ckb = UBX_CLASS_NAV + cka;
// if the old data are not processed so far then break parsing now
// to avoid writing new data in ISR during reading by another function
if ( *ubxSp == NEWDATA )
{
ubxState = UBXSTATE_IDLE;
if(ubxclass == UBX_CLASS_NAV) Update_GPSData(); //update GPS info respectively
}
else // data invalid or allready processed
{
*ubxSp = INVALID; // mark invalid during buffer filling
ubxState = UBXSTATE_DATA;
}
}
break;
 
case UBXSTATE_LEN1: // 1st message length byte
msglen = (u16)c; // lowbyte first
cka += c;
ckb += cka;
ubxState = UBXSTATE_LEN2;
break;
 
case UBXSTATE_LEN2: // 2nd message length byte
msglen += ((u16)c)<<8; // high byte last
cka += c;
ckb += cka;
// if the old data are not processed so far then break parsing now
// to avoid writing new data in ISR during reading by another function
if ( *ubxSp == NEWDATA )
{
ubxState = UBXSTATE_IDLE;
if(ubxclass == UBX_CLASS_NAV) Update_GPSData(); //update GPS info respectively
}
else // data invalid or allready processd
{
*ubxSp = INVALID; // mark invalid during buffer filling
ubxState = UBXSTATE_DATA;
}
break;
 
case UBXSTATE_DATA: // collecting data
if (ubxP < ubxEp)
{
507,7 → 496,7
}
}
 
u8 UBX_CreateMsg(Buffer_t* pBuff, u8 Class, u8 Id, u8* pData, u16 Len)
u8 UBX_CreateMsg(Buffer_t* pBuff, u8* pData, u16 Len)
{
u16 i;
u8 cka = 0, ckb = 0;
521,12 → 510,10
pBuff->Position = 0;
pBuff->pData[pBuff->Position++] = UBX_SYNC1_CHAR;
pBuff->pData[pBuff->Position++] = UBX_SYNC2_CHAR;
pBuff->pData[pBuff->Position++] = Class;
pBuff->pData[pBuff->Position++] = Id;
pBuff->pData[pBuff->Position++] = (u8)(Len);
pBuff->pData[pBuff->Position++] = (u8)(Len>>8);
memcpy(&(pBuff->pData[pBuff->Position]), pData, Len);
pBuff->Position += Len;
for(i=0;i<Len;i++)
{
pBuff->pData[pBuff->Position++] = pData[i];
}
// calculate checksum
for(i=2;i<pBuff->Position;i++)
{
/trunk/ubx.h
19,8 → 19,6
#define NEWDATA 0x01
#define PROCESSED 0x02
 
#define UBX_CLASS_CFG 0x06
 
typedef struct
{
s32 Longitude; // in 1E-7 deg
51,20 → 49,35
// To achieve new data after reading the GPSData.Status should be set to PROCESSED.
extern gps_data_t GPSData;
 
 
#define UBX_CLASS_CFG 0x06
#define UBX_CLASS_ACK 0x05
 
typedef struct
{
u8 Ack; // 1: msg acknowledged, 0: not acknowledged
u8 clsID; // the msg class
u8 msgID; // the msg id
u8 Status; // invalid/newdata/processed
} __attribute__((packed)) ubx_ack_t;
extern volatile ubx_ack_t UbxAck;
u8 Class;
u8 Id;
u16 Length;
} __attribute__((packed)) ubxmsghdr_t;
 
typedef struct
{
u8 ClassMask;
u8 IdMask;
ubxmsghdr_t Hdr;
u8 Data[100];
u8 Status;
} __attribute__((packed)) ubxmsg_t;
// msg obj to reveive
// set Class and Id and correspoinding masks of a message that should be received
extern volatile ubxmsg_t UbxMsg;
 
 
extern u32 UBX_Timeout;
 
void UBX_Init(void);
void UBX_RxParser(u8 c);
u8 UBX_CreateMsg(Buffer_t* pBuff, u8 Class, u8 Id, u8* pData, u16 Len);
u8 UBX_CreateMsg(Buffer_t* pBuff, u8* pData, u16 Len);
 
 
#endif // __UBX_H