Subversion Repositories NaviCtrl

Compare Revisions

Ignore whitespace Rev 153 → Rev 154

/trunk/analog.c
66,6 → 66,7
{
if(ADC_GetFlagStatus(ADC_FLAG_ECV) == SET)
{
ADC_ClearFlag(ADC_FLAG_ECV);
AnalogData.Ch1 = ADC_GetConversionValue(ADC_Channel_1);
AnalogData.Ch2 = ADC_GetConversionValue(ADC_Channel_2);
AnalogData.Ch3 = ADC_GetConversionValue(ADC_Channel_3);
74,7 → 75,6
AnalogData.Ch6 = ADC_GetConversionValue(ADC_Channel_6);
AnalogData.Ch7 = ADC_GetConversionValue(ADC_Channel_7);
DebugOut.Analog[4] = AnalogData.Ch1;
ADC_ClearFlag(ADC_FLAG_ECV);
}
VIC0->VAR = 0xFF;
}
/trunk/config.h
13,7 → 13,7
//<i> IRQ with the same priority are NOT allowed
 
//<o> VIC0.5: system time <0-15>
#define PRIORITY_TIMER1 8 // VIC0.5: system time
#define PRIORITY_TIMER1 0 // VIC0.5: system time
 
//<o> VIC0.6: servo pwm <0-15>
#define PRIORITY_TIMER2 7 // VIC0.6: servo pwm, must be disabled on UART redirection
22,7 → 22,7
#define PRIORITY_USB 9 // VIC0.8 VIC 0.9: usb port
 
//<o> VIC0.15: adc conversion <0-15>
#define PRIORITY_ADC 15 // VIC0.15: adc conversion
#define PRIORITY_ADC 14 // VIC0.15: adc conversion
//=============================================================================
//</h>
//<h>Vector 1 (lower priority than vector 0)
43,8 → 43,10
#define PRIORITY_SPI0 3 // VIC1.5: timing forced by FC, must be lower than UARTS for flashing FC thrue the NC
 
//<o> VIC0.5: VIC1.10 switch SD card <0-15>
#define PRIORITY_SDSWITCH 15 // VIC1.10 switch at sd port
#define PRIORITY_SDSWITCH 14 // VIC1.10 switch at sd port
 
#define PRIORITY_SW 15 //VIC1.11: Software Interrupt at absolute lowest priority
 
//</h>
//=============================================================================
//<h>Baudrates
/trunk/i2c.c
67,7 → 67,7
 
 
volatile I2C_State_t I2C_State = I2C_OFF;
u8 I2C_StopPolling = 1;
volatile u8 I2C_StopPolling = 1;
 
// rxbuffer
volatile u8 I2C_RxBufferSize;
190,6 → 190,8
I2C_GenerateSTOP(I2C1, ENABLE);
I2C_State = I2C_IDLE;
 
I2C_StopPolling = 0; // start polling
 
UART1_PutString("ok");
}
 
198,11 → 200,12
void I2C1_Deinit(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
I2C_State = I2C_OFF;
I2C_StopPolling = 1;// stop polling
UART1_PutString("\r\n I2C deinit...");
I2C_GenerateStart(I2C1, DISABLE);
I2C_GenerateSTOP(I2C1, ENABLE);
VIC_ITCmd(I2C1_ITLine, DISABLE);
I2C_State = I2C_OFF;
I2C_ITConfig(I2C1, DISABLE);
I2C_Cmd(I2C1, DISABLE);
I2C_DeInit(I2C1);
465,9 → 468,11
void I2C1_GetMK3MagVersion(void)
{
u8 msg[64];
u8 repeat = 20;
u8 repeat;
u32 timeout;
UART1_PutString("\r\n Getting Version from MK3MAG");
// stop polling of other commands
I2C_StopPolling = 1;
 
MK3MAG_Version.Major = 0xFF;
475,24 → 480,29
MK3MAG_Version.Patch = 0xFF;
MK3MAG_Version.Compatible = 0xFF;
// polling of version info
while ((MK3MAG_Version.Major == 0xFF) && (repeat != 0))
repeat = 0;
do
{
I2C1_SendCommand(I2C_CMD_VERSION);
timeout = SetDelay(500);
while (!CheckDelay(timeout)) if (MK3MAG_Version.Major != 0xFF) break;
repeat--;
}
 
timeout = SetDelay(250);
do
{
if (MK3MAG_Version.Major != 0xFF) break; // break loop on success
}while (!CheckDelay(timeout));
UART1_PutString(".");
repeat++;
}while ((MK3MAG_Version.Major == 0xFF) && (repeat < 12)); // 12*250ms=3s
// if we got it
if (MK3MAG_Version.Major != 0xFF)
{
sprintf(msg, "\n\r MK3Mag V%d.%d%c", MK3MAG_Version.Major, MK3MAG_Version.Minor, 'a' + MK3MAG_Version.Patch);
sprintf(msg, "\r\n MK3MAG V%d.%d%c", MK3MAG_Version.Major, MK3MAG_Version.Minor, 'a' + MK3MAG_Version.Patch);
UART1_PutString(msg);
sprintf(msg, " Compatible: %d", MK3MAG_Version.Compatible);
UART1_PutString(msg);
}
else UART1_PutString("\n\rNo version information from MK3Mag.");
else UART1_PutString("\n\r No version information from MK3Mag.");
 
I2C_StopPolling = 0; // enable polling of heading
I2C_StopPolling = 0; // enable polling of heading command
}
 
 
501,7 → 511,7
{
static u32 TimerCompassUpdate = 0;
 
if((I2C_State == I2C_OFF) || (I2C_StopPolling)) return;
if( (I2C_State == I2C_OFF) || I2C_StopPolling ) return;
if(CheckDelay(TimerCompassUpdate))
{
/trunk/interrupt.c
164,10 → 164,8
*******************************************************************************/
void SW_IRQHandler(void)
{
/*write your handler here*/
/* ... */
/* write your handler here */
/*write any value to VIC0 VAR*/
VIC0->VAR = 0xFF;
}
446,9 → 444,11
* Function Name : EXTIT3_IRQHandler
* Description : This function handles the EXTIT3 interrupt request
*******************************************************************************/
/*
void EXTIT3_IRQHandler(void)
{
}
*/
/*******************************************************************************
* Function Name : USBWU_IRQHandler
* Description : This function handles the USBWU interrupt request
/trunk/main.c
74,6 → 74,7
#include "sdc.h"
#include "logging.h"
#include "settings.h"
#include "config.h"
#include "main.h"
 
u32 TimerCheckError;
184,8 → 185,25
}
}
 
// the handler will be cyclic called by the timer 1 ISR
// used is for critical timing parts that normaly would handled
// within the main loop that could block longer at logging activities
void EXTIT3_IRQHandler(void)
{
VIC_ITCmd(EXTIT3_ITLine,DISABLE); // disable irq
 
I2C1_UpdateCompass(); // update compass communication
UART0_ProcessRxData(); // process request
UART1_ProcessRxData(); // process request
USB_ProcessRxData(); // process request
 
SPI0_UpdateBuffer(); // handle new SPI Data
Analog_Update(); // get new ADC values
 
VIC_SWITCmd(EXTIT3_ITLine,DISABLE); // clear pending bit
VIC_ITCmd(EXTIT3_ITLine, ENABLE); // enable irq
}
 
//----------------------------------------------------------------------------------------------------
int main(void)
{
250,22 → 268,19
UART0_GetMKOSDVersion();
 
UART1_PutString("\r\n---------------------------------------------\r\n\r\n");
// ---------- Prepare the isr driven
// set to absolute lowest priority
VIC_Config(EXTIT3_ITLine, VIC_IRQ, PRIORITY_SW);
// enanble interrupts
VIC_ITCmd(EXTIT3_ITLine, ENABLE);
 
for (;;)
for (;;) // the endless main loop
{
UART1_ProcessRxData(); // process request
UART0_TransmitTxData(); // send answer
UART1_TransmitTxData(); // send answer
 
UART0_ProcessRxData(); // process request
UART0_TransmitTxData(); // send answer
 
USB_ProcessRxData(); // process request
USB_TransmitTxData(); // send answer
 
SPI0_UpdateBuffer(); // handle new SPI Data
 
//I2C1_UpdateCompass(); moved to Timer1 ISR to avoid timing problems
 
// ---------------- Error Check Timing ----------------------------
if(CheckDelay(TimerCheckError))
{
282,7 → 297,6
// ---------------- Logging ---------------------------------------
Logging_Update(); // could be block some time for at max. 2 seconds, therefore move time critical part of the mainloop into the ISR of timer 1
// ---------------- ADC readings -----------------------------------
Analog_Update();
}
}
 
/trunk/spi_slave.c
430,21 → 430,29
//------------------------------------------------------
void SPI0_GetFlightCtrlVersion(void)
{
u16 timeout;
u32 timeout;
u8 repeat;
u8 msg[64];
 
UART1_PutString("\r\n Getting Version from FC");
FC_Version.Major = 0xFF;
FC_Version.Minor = 0xFF;
FC_Version.Patch = 0xFF;
FC_Version.Compatible = 0xFF;
 
// polling FC version info for 3 second
timeout = SetDelay(3000);
// polling FC versioni info
repeat = 0;
do
{
SPI0_UpdateBuffer();
if (FC_Version.Major != 0xFF) break;
}while (!CheckDelay(timeout));
timeout = SetDelay(250);
do
{
SPI0_UpdateBuffer();
if (FC_Version.Major != 0xFF) break;
}while (!CheckDelay(timeout));
UART1_PutString(".");
repeat++;
}while((FC_Version.Major == 0xFF) && (repeat < 12)); // 12*250ms = 3s
// if we got it
if (FC_Version.Major != 0xFF)
{
/trunk/ssc.c
179,9 → 179,9
// configure the EXT11 interrupt line (P5.3) as an IRQ with the lowest priority
SCU_APBPeriphClockConfig(__WIU, ENABLE);
WIU_Cmd(ENABLE );
WIU_Cmd(ENABLE);
WIU_ClearITPendingBit(WIU_Line11);
WIU_DeInit();
//WIU_DeInit();
WIU_InitStructure.WIU_TriggerEdge = WIU_FallingEdge;
WIU_InitStructure.WIU_Line = WIU_Line11;
WIU_Init(&WIU_InitStructure);
/trunk/timer1.c
57,7 → 57,6
#include "91x_lib.h"
#include "timer1.h"
#include "uart1.h"
#include "i2c.h"
#include "config.h"
 
u32 CountMilliseconds;
68,12 → 67,13
{
if(TIM_GetFlagStatus(TIM1, TIM_FLAG_OC1) == SET)
{
TIM_ClearFlag(TIM1, TIM_FLAG_OC1); // clear irq pending bit
TIM1->OC1R += 200; // Timerfreq is 200kHz, generate an interrupt every 1ms
CountMilliseconds++;
I2C1_UpdateCompass(); // update compass communication
 
TIM_ClearFlag(TIM1, TIM_FLAG_OC1); // clear irq pending bit
// generate SW Interrupt to make a regular timing
// indeoendent from the mainloop at the lowest IRQ priority
VIC_SWITCmd(EXTIT3_ITLine, ENABLE);
}
// write any value to VIC0 Vector address register
VIC0->VAR = 0xFF;
/trunk/timer2.c
95,6 → 95,7
 
if(TIM_GetFlagStatus(TIM2, TIM_FLAG_OC1) == SET)
{
TIM_ClearFlag(TIM2, TIM_FLAG_OC1); // clear irq pending bit
if (TIM2->CR1 & CR1_OLVL1_MASK) // start of high pulse
{
pulselen = MINSERVOPULSE + SERVORANGE/2;
130,11 → 131,11
TIM2->CR1 |= CR1_OLVL1_MASK; // make next a high pulse
}
TIM2->OC1R += pulselen;
TIM_ClearFlag(TIM2, TIM_FLAG_OC1); // clear irq pending bit
}
 
if(TIM_GetFlagStatus(TIM2, TIM_FLAG_OC2) == SET)
{
TIM_ClearFlag(TIM2, TIM_FLAG_OC2); // clear irq pending bit
if (TIM2->CR1 & CR1_OLVL2_MASK) // was high pulse
{
pulselen = MINSERVOPULSE + SERVORANGE/2;
170,7 → 171,6
TIM2->CR1 |= CR1_OLVL2_MASK; // make next a high pulse
}
TIM2->OC2R += pulselen;
TIM_ClearFlag(TIM2, TIM_FLAG_OC2); // clear irq pending bit
}
 
// write any value to VIC0 Vector address register
/trunk/uart1.c
98,7 → 98,7
UART_TypeDef *DebugUART = UART1;
 
// the primary rx fifo
#define UART1_RX_FIFO_LEN 512
#define UART1_RX_FIFO_LEN 1024
u8 UART1_rxfifobuffer[UART1_RX_FIFO_LEN];
fifo_t UART1_rx_fifo;
 
320,7 → 320,7
else // DebugUART == UART1 (normal operation)
{
while(UART_GetFlagStatus(UART1, UART_FLAG_RxFIFOEmpty) != SET)
{ // some byes in the fifo and rxd buffer not locked
{ // some byes in the hardware fifo
// get byte from hardware fifo
c = UART_ReceiveData(UART1);
// put into the software fifo
328,7 → 328,15
{ // fifo overflow
fifo_purge(&UART1_rx_fifo); // flush the whole buffer
}
} // some byes in the fifo and rxd buffer not locked
} // EOF while some byes in the hardware fifo
// if rx buffer is not locked
if(UART1_rx_buffer.Locked == FALSE)
{ //collect data from primary rx fifo
while(fifo_get(&UART1_rx_fifo, &c))
{ // break if complete frame is collected
if(MKProtocol_CollectSerialFrame(&UART1_rx_buffer, c)) break;
}
}
} // eof DebugUart = UART1
}
}
338,19 → 346,9
/**************************************************************/
void UART1_ProcessRxData(void)
{
u8 c;
 
// return on forwarding uart
if(DebugUART != UART1) return;
// return on forwarding uart or unlocked rx buffer
if((DebugUART != UART1) || (UART1_rx_buffer.Locked == FALSE)) return;
// collect data from primary rx fifo
while(fifo_get(&UART1_rx_fifo, &c))
{ // break if complete frame is collected
if(MKProtocol_CollectSerialFrame(&UART1_rx_buffer, c)) break;
}
// if data in the rxd buffer are not locked immediately return
if(UART1_rx_buffer.Locked == FALSE) return;
Waypoint_t * pWaypoint = NULL;
SerialMsg_t SerialMsg;
 
560,6 → 558,30
Echo = 0; // reset echo value
UART1_Request_Echo = FALSE;
}
else if(UART1_Request_NewWaypoint && (UART1_tx_buffer.Locked == FALSE))
{
u8 WPNumber = WPList_GetCount();
MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'W', NC_ADDRESS, 1, &WPNumber, sizeof(WPNumber));
UART1_Request_NewWaypoint = FALSE;
}
else if((UART1_Request_ReadWaypoint != 0xFF) && (UART1_tx_buffer.Locked == FALSE))
{
u8 WPNumber = WPList_GetCount();
if (UART1_Request_ReadWaypoint < WPNumber)
{
MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'X', NC_ADDRESS, 3, &WPNumber, 1, &UART1_Request_ReadWaypoint, 1, WPList_GetAt(UART1_Request_ReadWaypoint), sizeof(Waypoint_t));
}
else
{
MKProtocol_CreateSerialFrame(&UART1_tx_buffer,'X', NC_ADDRESS, 1, &WPNumber, sizeof(WPNumber));
}
UART1_Request_ReadWaypoint = 0xFF;
}
else if((UART1_Request_DebugLabel != 0xFF) && (UART1_tx_buffer.Locked == FALSE))
{
MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'A', NC_ADDRESS, 2, &UART1_Request_DebugLabel, sizeof(UART1_Request_DebugLabel), (u8 *) ANALOG_LABEL[UART1_Request_DebugLabel], 16);
UART1_Request_DebugLabel = 0xFF;
}
else if(( ((UART1_NaviData_Interval > 0) && CheckDelay(UART1_NaviData_Timer) ) || UART1_Request_NaviData) && (UART1_tx_buffer.Locked == FALSE))
{
NaviData.Errorcode = ErrorCode;
579,11 → 601,6
UART1_Data3D_Timer = SetDelay(UART1_Data3D_Interval);
UART1_Request_Data3D = FALSE;
}
else if((UART1_Request_DebugLabel != 0xFF) && (UART1_tx_buffer.Locked == FALSE))
{
MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'A', NC_ADDRESS, 2, &UART1_Request_DebugLabel, sizeof(UART1_Request_DebugLabel), (u8 *) ANALOG_LABEL[UART1_Request_DebugLabel], 16);
UART1_Request_DebugLabel = 0xFF;
}
else if(UART1_ConfirmFrame && (UART1_tx_buffer.Locked == FALSE))
{
MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'B', NC_ADDRESS, 1, &UART1_ConfirmFrame, sizeof(UART1_ConfirmFrame));
633,25 → 650,6
MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 's', NC_ADDRESS, 1, (u8 *)&FollowMe, sizeof(FollowMe));
UART1_Request_SendFollowMe = FALSE;
}
else if(UART1_Request_NewWaypoint && (UART1_tx_buffer.Locked == FALSE))
{
u8 WPNumber = WPList_GetCount();
MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'W', NC_ADDRESS, 1, &WPNumber, sizeof(WPNumber));
UART1_Request_NewWaypoint = FALSE;
}
else if((UART1_Request_ReadWaypoint != 0xFF) && (UART1_tx_buffer.Locked == FALSE))
{
u8 WPNumber = WPList_GetCount();
if (UART1_Request_ReadWaypoint < WPNumber)
{
MKProtocol_CreateSerialFrame(&UART1_tx_buffer, 'X', NC_ADDRESS, 3, &WPNumber, 1, &UART1_Request_ReadWaypoint, 1, WPList_GetAt(UART1_Request_ReadWaypoint), sizeof(Waypoint_t));
}
else
{
MKProtocol_CreateSerialFrame(&UART1_tx_buffer,'X', NC_ADDRESS, 1, &WPNumber, sizeof(WPNumber));
}
UART1_Request_ReadWaypoint = 0xFF;
}
UART1_Transmit(); // output pending bytes in tx buffer
}