Subversion Repositories NaviCtrl

Compare Revisions

Ignore whitespace Rev 33 → Rev 34

/branches/V0.1 killagreg/interrupt.c
362,9 → 362,9
* Function Name : UART2_IRQHandler
* Description : This function handles the UART2 interrupt request
*******************************************************************************/
void UART2_IRQHandler(void)
/*void UART2_IRQHandler(void)
{
}
} */
/*******************************************************************************
* Function Name : I2C0_IRQHandler
* Description : This function handles the I2C0 interrupt request
/branches/V0.1 killagreg/kml.c
144,7 → 144,7
// Description: This function closes the document specified by doc.
//
//
// Returnvalue: none
// Returnvalue: '1' if the KML- file could be closed.
//________________________________________________________________________________________________________________________________________
 
u8 KML_DocumentClose(KML_Document_t *doc)
193,7 → 193,7
// Description: This function adds a placemark to the document.
//
//
// Returnvalue: none
// Returnvalue: '1' if the PlaceMark could be opened
//________________________________________________________________________________________________________________________________________
 
u8 KML_PlaceMarkOpen(s8 *name, KML_Document_t *doc)
217,7 → 217,7
// Description: This function ends the placemark opened before.
//
//
// Returnvalue: none
// Returnvalue: 1' if the PlaceMark could be closed
//________________________________________________________________________________________________________________________________________
 
u8 KML_PlaceMarkClose(KML_Document_t *doc)
244,7 → 244,7
// Description: This function ends the placemark opened before.
//
//
// Returnvalue: none
// Returnvalue: '1' if the LineString could be started
//________________________________________________________________________________________________________________________________________
 
u8 KML_LineStringBegin(KML_Document_t *doc)
268,7 → 268,7
// Description: This function ends the placemark opened before.
//
//
// Returnvalue: none
// Returnvalue: '1' if the LineString could be terminated
//________________________________________________________________________________________________________________________________________
 
u8 KML_LineStringEnd(KML_Document_t *doc)
293,7 → 293,7
// Description: This function adds a point to the specified document.
//
//
// Returnvalue: none
// Returnvalue: '1' if a ppoint was added could be started
//________________________________________________________________________________________________________________________________________
 
u8 KML_LineStringAddPoint(gps_data_t * pgpsdata ,KML_Document_t *doc)
337,11 → 337,12
// Description: This function opens adds gpscoordinates to an KML-Document. The document will be opened, if not already done
//
//
// Returnvalue: none
// Returnvalue: '1' if an gps coordinate was logged
//________________________________________________________________________________________________________________________________________
 
void KML_LoggGPSCoordinates(gps_data_t * pgpsdata, KML_Document_t *doc)
u8 KML_LoggGPSCoordinates(gps_data_t * pgpsdata, KML_Document_t *doc)
{
u8 retval = 0;
while(doc->state != DOC_LINESTRING_OPENED) // automatic create document with default filename on the card.
{
switch(doc->state)
348,7 → 349,8
{
case DOC_CLOSED: // document hasn't been opened yet therefore it will be initialized automatically
KML_DocumentInit(doc); // initialize the document to default values
if(KML_DocumentOpen("default.kml",doc)) // open the kml-document with a standardname.
retval = KML_DocumentOpen("default.kml",doc); // open the kml-document with a standardname.
if(retval)
{
doc->state = DOC_OPENED;
}
355,7 → 357,8
break;
 
case DOC_OPENED: // if a document has been opened before but no placemark exists:
if(KML_PlaceMarkOpen("MIKROKOPTER",doc))
retval = KML_PlaceMarkOpen("MIKROKOPTER",doc);
if(retval)
{
doc->state = DOC_PLACEMARK_OPENED; // add a placemark to the document.
}
362,7 → 365,8
break;
 
case DOC_PLACEMARK_OPENED: // add linestring to the placemark
if(KML_LineStringBegin(doc))
retval = KML_LineStringBegin(doc);
if(retval)
{
doc->state = DOC_LINESTRING_OPENED;
}
369,14 → 373,17
break;
 
default:
retval = 1;
break;
 
}
};
if(retval != 1) return(retval); // stop on error
}
 
if(doc->state == DOC_LINESTRING_OPENED) // if the document was opened add coordinates to the document.
{
KML_LineStringAddPoint(pgpsdata , doc);
retval = KML_LineStringAddPoint(pgpsdata , doc);
}
return(retval);
}
 
/branches/V0.1 killagreg/kml.h
37,7 → 37,7
 
 
 
void KML_LoggGPSCoordinates(gps_data_t* pGPSData , KML_Document_t *); // intializes the kml-document with standard filename and adds points to the file
u8 KML_LoggGPSCoordinates(gps_data_t* pGPSData , KML_Document_t *); // intializes the kml-document with standard filename and adds points to the file
u8 KML_DocumentInit(KML_Document_t *); // Init the new kml-document
u8 KML_DocumentOpen(s8 *, KML_Document_t *); // opens a new kml-document. a new file is created on the sd-memorycard
u8 KML_DocumentClose(KML_Document_t *doc); // closes the specified document saving remaining data to the file.
/branches/V0.1 killagreg/main.c
62,7 → 62,7
#include "led.h"
#include "uart0.h"
#include "uart1.h"
//#include "uart2.h"
#include "uart2.h"
#include "GPS.h"
#include "i2c.h"
#include "timer.h"
73,6 → 73,15
#include "kml.h"
#include "main.h"
 
 
typedef enum
{
LOGFILE_IDLE,
LOGFILE_CLOSED,
LOGFILE_OPENED,
LOGFILE_ERROR,
} logfilestate_t;
 
u32 TimerCompassUpdate;
u32 TimerDebugDataDelay;
u32 TimerKmlAddPointDelay;
120,13 → 129,16
//----------------------------------------------------------------------------------------------------
int main(void)
{
u8 kml_state = 0;
u8 kml_count = 0;
KML_Document_t mydocument;
logfilestate_t logfilestate = LOGFILE_IDLE;
KML_Document_t gpslogfile;
u16 gpslogfilenum = 0;
s8 gpslogfilename[13];
/* Configure the system clocks */
SCU_Config();
KML_DocumentInit(&gpslogfile); // Initialize the new kml-document for further use.
sprintf(gpslogfilename, "gps%05i.klm", gpslogfilenum); // initialize gps logfile name
 
KML_DocumentInit(&mydocument); // Initialize the new kml-document for further use.
 
/* Fill Version Info Structure */
VersionInfo.Major = VERSION_MAJOR;
144,10 → 156,10
// initialize the LEDs (needs Timer 1)
Led_Init();
// initialize the debug UART1
UART1_Init();
//UART1_Init();
OutputStartupData();
// initialize UART2 to FLIGHTCTRL
//UART2_Init();
UART2_Init();
// initialize UART0 (to MKGPS or MK3MAG)
UART0_Init();
// initialize usb
218,45 → 230,82
TimerDebugDataDelay = SetDelay(500);
}
// ---------------- KML Timing ------------------------------------
if(CheckDelay(TimerKmlAddPointDelay))
if(CheckDelay(TimerKmlAddPointDelay))
{
TimerKmlAddPointDelay = SetDelay(500);
switch(kml_state)
 
if(FC.MKFlags & MKFLAG_FLY) // model is flying
{
case 0:
if((GPSData.Status != INVALID) && (GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.SatFix == SATFIX_3D))
switch(logfilestate)
{
case LOGFILE_IDLE:
case LOGFILE_CLOSED:
// find unused logfile name
while(fexist_(gpslogfilename))
{ // generate new logfile name
gpslogfilenum++;
sprintf(gpslogfilename, "gps%05i.klm", gpslogfilenum);
}
// try to create the log file
if(KML_DocumentOpen(gpslogfilename,&gpslogfile))
{
SerialPutString("\r\nopening kml-file\r\nadding data");
logfilestate = LOGFILE_OPENED; // goto next step
}
else
{
logfilestate = LOGFILE_ERROR;
SerialPutString("\r\nError opening kml-file");
TimerKmlAddPointDelay = SetDelay(10);
}
break;
 
 
case LOGFILE_OPENED:
// append new gps log data
if((GPSData.Status != INVALID) && (GPSData.Flags & FLAG_GPSFIXOK) && (GPSData.SatFix == SATFIX_3D))
{
if(KML_DocumentOpen("Flight01.kml",&mydocument)) // create a new kml-document on the memorycard.
{
SerialPutString("\r\nopening kml-file\r\nadding data");
kml_state = 1; // goto next step
if(!KML_LoggGPSCoordinates(&GPSData, &gpslogfile))
{ // error logging data
KML_DocumentClose(&gpslogfile);
logfilestate = LOGFILE_ERROR;
}
else
{
SerialPutString("\r\nError opening kml-file");
// try to reinitialize the FAT16
if(0 != Fat16_Init()) TimerKmlAddPointDelay = SetDelay(5000); // try again in 5 sec
}
}
break; // document.state will be changed to DOC_OPENED automatic.
case 1: // linestring opened, so datapoint (gps_coordinates) can be added to the document.
if(kml_count++ < 20) // add 10 datapoints to the document.
case LOGFILE_ERROR:
// try to reinitialize the fat16 filesystem
if(0 == Fat16_Init())
{
KML_LoggGPSCoordinates(&GPSData, &mydocument);
logfilestate = LOGFILE_IDLE;
TimerKmlAddPointDelay = SetDelay(10); // try again in 5 sec
}
else // after the datapoints have been written to the document close the document.
else
{
KML_DocumentClose(&mydocument);
SerialPutString("\r\nfile closed");
kml_state = 2;
}
logfilestate = LOGFILE_ERROR;
TimerKmlAddPointDelay = SetDelay(5000); // try again in 5 sec
}
break;
 
default:
break; // all data has been written to card. open new document to add new data.
}
 
default:
break;
 
}
} // EOF model is flying
else // model is not flying
{ // close log file if opened
if(logfilestate == LOGFILE_OPENED)
{
if(KML_DocumentClose(&gpslogfile))
{
logfilestate = LOGFILE_CLOSED;
}
else
{
logfilestate = LOGFILE_ERROR;
}
}
} //EOF model is nit flying
}
}
}
/branches/V0.1 killagreg/uart1.c
61,7 → 61,7
#include "GPS.h"
#include "uart0.h"
#include "uart1.h"
//#include "uart2.h"
#include "uart2.h"
#include "timer.h"
#include "usb.h"
#include "main.h"
451,8 → 451,8
switch(tmp_char_arr2[0])
{
case UART_FLIGHTCTRL:
//UART2_Init(); // initialize UART2 to FC pins
//DebugUART = UART2;
UART2_Init(); // initialize UART2 to FC pins
DebugUART = UART2;
break;
case UART_MK3MAG:
UART0_Connect_to_MK3MAG(); // mux UART0 to MK3MAG pins
/branches/V0.1 killagreg/uart2.c
111,11 → 111,11
UART_InitStructure.UART_RxFIFOLevel = UART_FIFOLevel_1_2;
 
UART_DeInit(UART2); // reset uart 0 to default
UART_Init(UART2, &UART_InitStructure); // initialize uart 0
UART_Init(UART2, &UART_InitStructure); // initialize uart 2
 
// enable uart 2 interrupts selective
UART_ITConfig(UART2, UART_IT_Receive | UART_IT_ReceiveTimeOut, ENABLE);
UART_Cmd(UART2, ENABLE); // enable uart 0
UART_Cmd(UART2, ENABLE); // enable uart 2
// configure the uart 2 interupt line as an IRQ with priority 9 (0 is highest)
VIC_Config(UART2_ITLine, VIC_IRQ, 9);
// enable the uart 2 IRQ
124,6 → 124,42
SerialPutString("ok");
}
 
 
void UART2_Deinit(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
 
SerialPutString("\r\n UART2 deinit...");
VIC_ITCmd(UART2_ITLine, DISABLE); // disable the uart 2 IRQ
UART_Cmd(UART2, DISABLE); // disable uart 2
UART_DeInit(UART2); // reset uart 0 to default
SCU_APBPeriphClockConfig(__UART2, DISABLE); // disable the UART2 Clock
 
SCU_APBPeriphClockConfig(__GPIO5, ENABLE);
// unmap UART2 from FC
// set port pin 5.2 (serial data from FC) to input and disconnect from IP
GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull;
GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Disable;
GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1;
GPIO_Init(GPIO5, &GPIO_InitStructure);
 
SCU_APBPeriphClockConfig(__GPIO3, ENABLE);
// set port pin 3.0 (serial data to FC) to input and disconnect from IP
GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull;
GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Disable;
GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1;
GPIO_Init(GPIO3, &GPIO_InitStructure);
 
SerialPutString("ok");
}
 
/********************************************************/
/* UART2 Interrupt Handler */
/********************************************************/
142,7 → 178,7
{
// wait for space in the tx buffer of the UART1
while(UART_GetFlagStatus(UART1, UART_FLAG_TxFIFOFull) == SET) {};
// move the byte from the rx buffer of UART0 to the tx buffer of UART1
// move the byte from the rx buffer of UART2 to the tx buffer of UART1
UART_SendData(UART1, UART_ReceiveData(UART2));
}
}
/branches/V0.1 killagreg/uart2.h
2,5 → 2,6
#define __UART2_H
 
void UART2_Init (void);
void UART2_Deinit (void);
 
#endif //__UART2_H