diff --git a/.gitignore b/.gitignore index cdfc2797f..84e70d9e3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,13 +1,61 @@ -.metadata/ -flight/.cproject -flight/.project -flight/.settings/ -ground/openpilotgcs.pro.user -ground/src/libs/uavobjgenerator/uavobjgenerator.pro.user -tools/ -build/ -downloads/ -GPATH -GRTAGS -GSYMS -GTAGS + +# /flight/ +/flight/*.pnproj +/flight/*.pnps +/flight/.cproject +/flight/.metadata +/flight/.project +/flight/.settings +/flight/Build + +# /flight/AHRS/ +/flight/AHRS/Build + +# /flight/Bootloaders/OpenPilot.old/ +/flight/Bootloaders/OpenPilot.old/Build + +# /flight/OpenPilot/ +/flight/OpenPilot/Build +/flight/OpenPilot/Build.win32 + +# /flight/PipBee/ +/flight/PipBee/Build + +# /ground/ +/ground/Build + +# /ground/share/openpilotgcs/models/Easystar/ +/ground/share/openpilotgcs/models/Easystar/Thumbs.db + +# /ground/share/openpilotgcs/sounds/ +/ground/share/openpilotgcs/sounds/normalize.exe + +# /ground/share/openpilotgcs/sounds/default/ +/ground/share/openpilotgcs/sounds/default/normalize.exe + +# /ground/share/openpilotgcs/translations/ +/ground/share/openpilotgcs/translations/extract-mimetypes.xq + +# /ground/src/experimental/OPMapWidget/core/ +/ground/src/experimental/OPMapWidget/core/header.h + +# /ground/src/experimental/tools/DocumentationHelper/ +/ground/src/experimental/tools/DocumentationHelper/ui_mainwindow.h + +# /ground/src/libs/qextserialport/ +/ground/src/libs/qextserialport/.hg +/ground/src/libs/qextserialport/.hgtags + +# /ground/src/libs/qwt/ +/ground/src/libs/qwt/qwt.prf +/ground/src/libs/qwt/designer + +# /ground/src/libs/uavobjgenerator/ +/ground/src/libs/uavobjgenerator/Makefile +/ground/src/libs/uavobjgenerator/Makefile.Debug +/ground/src/libs/uavobjgenerator/Makefile.Release +/ground/src/libs/uavobjgenerator/debug +/ground/src/libs/uavobjgenerator/release + +# /ground/src/plugins/ipconnection/ +/ground/src/plugins/ipconnection/ui_ipconnectionoptionspage.h diff --git a/flight/OpenPilot/Makefile b/flight/OpenPilot/Makefile index 0893e1796..1b50e90bd 100644 --- a/flight/OpenPilot/Makefile +++ b/flight/OpenPilot/Makefile @@ -57,7 +57,7 @@ FLASH_TOOL = OPENOCD USE_THUMB_MODE = YES # List of modules to include -MODULES = Telemetry GPS ManualControl Actuator Altitude AHRSComms Stabilization/simple/Stabilization +MODULES = Telemetry GPS ManualControl Actuator Altitude AHRSComms Stabilization/simple/Stabilization Watchdog #MODULES = Telemetry Example #MODULES = Telemetry MK/MKSerial #MODULES = Telemetry @@ -186,6 +186,7 @@ SRC += $(PIOSSTM32F10X)/pios_spektrum.c SRC += $(PIOSSTM32F10X)/pios_debug.c SRC += $(PIOSSTM32F10X)/pios_gpio.c SRC += $(PIOSSTM32F10X)/pios_exti.c +SRC += $(PIOSSTM32F10X)/pios_wdg.c # PIOS USB related files (seperated to make code maintenance more easy) SRC += $(PIOSSTM32F10X)/pios_usb_hid.c @@ -225,7 +226,7 @@ SRC += $(STMSPDSRCDIR)/stm32f10x_rtc.c SRC += $(STMSPDSRCDIR)/stm32f10x_spi.c SRC += $(STMSPDSRCDIR)/stm32f10x_tim.c SRC += $(STMSPDSRCDIR)/stm32f10x_usart.c -SRC += $(STMSPDSRCDIR)/stm32f10x_wwdg.c +SRC += $(STMSPDSRCDIR)/stm32f10x_iwdg.c SRC += $(STMSPDSRCDIR)/misc.c ## STM32 USB Library diff --git a/flight/OpenPilot/Modules/Watchdog/inc/watchdog.h b/flight/OpenPilot/Modules/Watchdog/inc/watchdog.h new file mode 100644 index 000000000..eb11548fa --- /dev/null +++ b/flight/OpenPilot/Modules/Watchdog/inc/watchdog.h @@ -0,0 +1,9 @@ +/* + * watchdog.h + * OpenPilotOSX + * + * Created by James Cotton on 8/10/10. + * Copyright 2010 OpenPilot. All rights reserved. + * + */ + diff --git a/flight/OpenPilot/Modules/Watchdog/watchdog.c b/flight/OpenPilot/Modules/Watchdog/watchdog.c new file mode 100644 index 000000000..b0cf8967e --- /dev/null +++ b/flight/OpenPilot/Modules/Watchdog/watchdog.c @@ -0,0 +1,87 @@ +/** + ****************************************************************************** + * + * @file watchdog.c + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * @brief Watchdog module which must run every 250 ms + * + * @see The GNU Public License (GPL) Version 3 + * + *****************************************************************************/ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/** + * Input object: none + * Output object: none + * + * This module initializes the PIOS Watchdog and then periodically resets the timeout + * + * The module executes in its own thread in this example. + */ + +#include "openpilot.h" +#include "watchdog.h" +#include "pios_wdg.h" + +// Private constants +// TODO: Look up maximum task priority and set this to it. Not trying to replicate CPU load. +#define TASK_PRIORITY (tskIDLE_PRIORITY+5) +#define STACK_SIZE configMINIMAL_STACK_SIZE +#define WATCHDOG_TIMEOUT 250 + +// Private types + +// Private variables +static xTaskHandle taskHandle; + +// Private functions +static void watchdogTask(void* parameters); + +/** + * Initialise the module, called on startup + * \returns 0 on success or -1 if initialisation failed + */ +int32_t WatchdogInitialize() +{ + // Start main task + xTaskCreate(watchdogTask, (signed char*)"Watchdog", STACK_SIZE, NULL, TASK_PRIORITY, &taskHandle); + + return 0; +} + +/** + * @brief Module thread, should not return. + * + * Initializes the PIOS watchdog and periodically resets it + */ +static void watchdogTask(void* parameters) +{ + uint32_t delay; + portTickType lastSysTime; + + delay = PIOS_WDG_Init( WATCHDOG_TIMEOUT ) / portTICK_RATE_MS; + + // Main task loop + lastSysTime = xTaskGetTickCount(); + while (1) + { + PIOS_WDG_Clear(); + + vTaskDelayUntil(&lastSysTime, delay ); + } +} + diff --git a/flight/OpenPilot/System/pios_board.c b/flight/OpenPilot/System/pios_board.c index 623958ed5..83f107d63 100644 --- a/flight/OpenPilot/System/pios_board.c +++ b/flight/OpenPilot/System/pios_board.c @@ -80,10 +80,6 @@ void PIOS_Board_Init(void) { #endif PIOS_I2C_Init(); - WWDG_SetPrescaler(WWDG_Prescaler_8); - WWDG_SetWindowValue(0xff); - - } /* MicroSD Interface diff --git a/flight/PiOS/STM32F10x/pios_wdg.c b/flight/PiOS/STM32F10x/pios_wdg.c new file mode 100644 index 000000000..ca8299994 --- /dev/null +++ b/flight/PiOS/STM32F10x/pios_wdg.c @@ -0,0 +1,78 @@ +/** + ****************************************************************************** + * @addtogroup PIOS PIOS Core hardware abstraction layer + * @{ + * @addtogroup PIOS_WDG Watchdog Functions + * @brief PIOS Comamnds to initialize and clear watchdog timer + * @{ + * + * @file pios_spi.c + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * Parts by Thorsten Klose (tk@midibox.org) (tk@midibox.org) + * @brief Hardware Abstraction Layer for SPI ports of STM32 + * @see The GNU Public License (GPL) Version 3 + * @notes + * + * The PIOS Watchdog provides a HAL to initialize a watchdog + * + *****************************************************************************/ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#include "pios.h" +#include "stm32f10x_iwdg.h" + +/** + * @brief Initialize the watchdog timer for a specified timeout + * + * It is important to note that this function returns the achieved timeout + * for this hardware. For hardware indendence this should be checked when + * scheduling updates. Other hardware dependent details may need to be + * considered such as a window time which sets a minimum update time, + * and this function should return a recommended delay for clearing. + * + * For the STM32 nominal clock rate is 32 khz, but for the maximum clock rate of + * 60 khz and a prescalar of 4 yields a clock rate of 15 khz. The delay that is + * set in the watchdog assumes the nominal clock rate, but the delay for FreeRTOS + * to use is 75% of the minimal delay. + * + * @param[in] delayMs The delay period in ms + * @returns Maximum recommended delay between updates + */ +uint8_t PIOS_WDG_Init( uint8_t delayMs ) +{ + uint16_t delay; + delay = 60 / 16 * delayMs; + if( delay > 0xfff ) + delay = 0xfff; + IWDG_WriteAccessCmd( IWDG_WriteAccess_Enable ); + IWDG_SetPrescaler( IWDG_Prescaler_16 ); + IWDG_SetReload( delay ); + IWDG_ReloadCounter(); + IWDG_Enable(); + return delay / (60 / 16) * .75; +} + +/** + * @brief Clear the watchdog timer + * + * This function must be called at the appropriate delay to prevent a reset event occuring + */ +void PIOS_WDG_Clear() +{ + IWDG_ReloadCounter(); +} diff --git a/flight/PiOS/STM32F10x/pios_wdg.h b/flight/PiOS/STM32F10x/pios_wdg.h new file mode 100644 index 000000000..bccaad155 --- /dev/null +++ b/flight/PiOS/STM32F10x/pios_wdg.h @@ -0,0 +1,37 @@ +/** + ****************************************************************************** + * @addtogroup PIOS PIOS Core hardware abstraction layer + * @{ + * @addtogroup PIOS_WDG Watchdog Functions + * @{ + * + * @file pios_wdg.h + * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010. + * Parts by Thorsten Klose (tk@midibox.org) + * @brief SPI functions header. + * @see The GNU Public License (GPL) Version 3 + * + *****************************************************************************/ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef PIOS_WDG +#define PIOS_WDG + +uint8_t PIOS_WDG_Init( uint8_t delayMs ); +void PIOS_WDG_Clear(); + +#endif \ No newline at end of file diff --git a/flight/PiOS/pios.h b/flight/PiOS/pios.h index b587f82f2..8ae2c20c9 100644 --- a/flight/PiOS/pios.h +++ b/flight/PiOS/pios.h @@ -81,6 +81,7 @@ #if defined(PIOS_INCLUDE_EXTI) #include #endif +#include /* PIOS Hardware Includes (Common) */ #include diff --git a/flight/Project/OpenPilotOSX/OpenPilotOSX.xcodeproj/project.pbxproj b/flight/Project/OpenPilotOSX/OpenPilotOSX.xcodeproj/project.pbxproj index 752092abe..39eaa61fa 100644 --- a/flight/Project/OpenPilotOSX/OpenPilotOSX.xcodeproj/project.pbxproj +++ b/flight/Project/OpenPilotOSX/OpenPilotOSX.xcodeproj/project.pbxproj @@ -7,6 +7,10 @@ objects = { /* Begin PBXFileReference section */ + 65003B2D1212499100C183DD /* watchdog.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = watchdog.h; sourceTree = ""; }; + 65003B2E1212499100C183DD /* watchdog.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = watchdog.c; sourceTree = ""; }; + 65003B30121249CA00C183DD /* pios_wdg.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = pios_wdg.h; path = ../STM32F10x/pios_wdg.h; sourceTree = ""; }; + 65003B31121249CA00C183DD /* pios_wdg.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = pios_wdg.c; sourceTree = ""; }; 651CF9E5120B5D8300EEFD70 /* pios_usb_hid_desc.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = pios_usb_hid_desc.c; sourceTree = ""; }; 651CF9E6120B5D8300EEFD70 /* pios_usb_hid_istr.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = pios_usb_hid_istr.c; sourceTree = ""; }; 651CF9E7120B5D8300EEFD70 /* pios_usb_hid_prop.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = pios_usb_hid_prop.c; sourceTree = ""; }; @@ -53,6 +57,16 @@ 65A2C81B11E2A33D00D0391E /* pios_sdcard.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = pios_sdcard.c; path = ../../PiOS.posix/posix/pios_sdcard.c; sourceTree = SOURCE_ROOT; }; 65A2C81C11E2A33D00D0391E /* pios_sys.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = pios_sys.c; path = ../../PiOS.posix/posix/pios_sys.c; sourceTree = SOURCE_ROOT; }; 65A2C81D11E2A33D00D0391E /* pios_udp.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = pios_udp.c; path = ../../PiOS.posix/posix/pios_udp.c; sourceTree = SOURCE_ROOT; }; + 65B7E6AD120DF1E2000C1123 /* ahrs_fsm.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = ahrs_fsm.c; path = ../../AHRS/ahrs_fsm.c; sourceTree = SOURCE_ROOT; }; + 65B7E6AE120DF1E2000C1123 /* ahrs.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = ahrs.c; path = ../../AHRS/ahrs.c; sourceTree = SOURCE_ROOT; }; + 65B7E6B0120DF1E2000C1123 /* ahrs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ahrs.h; sourceTree = ""; }; + 65B7E6B1120DF1E2000C1123 /* ahrs_fsm.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ahrs_fsm.h; sourceTree = ""; }; + 65B7E6B2120DF1E2000C1123 /* insgps.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = insgps.h; sourceTree = ""; }; + 65B7E6B3120DF1E2000C1123 /* pios_board.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = pios_board.h; sourceTree = ""; }; + 65B7E6B4120DF1E2000C1123 /* pios_config.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = pios_config.h; sourceTree = ""; }; + 65B7E6B5120DF1E2000C1123 /* insgps.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = insgps.c; path = ../../AHRS/insgps.c; sourceTree = SOURCE_ROOT; }; + 65B7E6B6120DF1E2000C1123 /* Makefile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.make; name = Makefile; path = ../../AHRS/Makefile; sourceTree = SOURCE_ROOT; }; + 65B7E6B7120DF1E2000C1123 /* pios_board.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = pios_board.c; path = ../../AHRS/pios_board.c; sourceTree = SOURCE_ROOT; }; 65E8EF1F11EEA61E00BBF654 /* Makefile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.make; name = Makefile; path = ../../OpenPilot/Makefile; sourceTree = SOURCE_ROOT; }; 65E8EF2011EEA61E00BBF654 /* Makefile.posix */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = Makefile.posix; path = ../../OpenPilot/Makefile.posix; sourceTree = SOURCE_ROOT; }; 65E8EF2311EEA61E00BBF654 /* actuator.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = actuator.c; path = ../../OpenPilot/Modules/Actuator/actuator.c; sourceTree = SOURCE_ROOT; }; @@ -334,6 +348,7 @@ 08FB7794FE84155DC02AAC07 /* OpenPilotOSX */ = { isa = PBXGroup; children = ( + 65B7E6AC120DF1CD000C1123 /* AHRS */, 65E8EF1E11EEA61E00BBF654 /* OpenPilot */, 65E8F02F11EFF25C00BBF654 /* PiOS */, 65A2C7ED11E2A33D00D0391E /* PiOS.posix */, @@ -350,6 +365,23 @@ name = Products; sourceTree = ""; }; + 65003B2B1212499100C183DD /* Watchdog */ = { + isa = PBXGroup; + children = ( + 65003B2C1212499100C183DD /* inc */, + 65003B2E1212499100C183DD /* watchdog.c */, + ); + path = Watchdog; + sourceTree = ""; + }; + 65003B2C1212499100C183DD /* inc */ = { + isa = PBXGroup; + children = ( + 65003B2D1212499100C183DD /* watchdog.h */, + ); + path = inc; + sourceTree = ""; + }; 65A2C7ED11E2A33D00D0391E /* PiOS.posix */ = { isa = PBXGroup; children = ( @@ -485,6 +517,32 @@ path = ../../PiOS.posix/posix/Libraries/FreeRTOS/Source/portable/MemMang; sourceTree = SOURCE_ROOT; }; + 65B7E6AC120DF1CD000C1123 /* AHRS */ = { + isa = PBXGroup; + children = ( + 65B7E6AD120DF1E2000C1123 /* ahrs_fsm.c */, + 65B7E6AE120DF1E2000C1123 /* ahrs.c */, + 65B7E6AF120DF1E2000C1123 /* inc */, + 65B7E6B5120DF1E2000C1123 /* insgps.c */, + 65B7E6B6120DF1E2000C1123 /* Makefile */, + 65B7E6B7120DF1E2000C1123 /* pios_board.c */, + ); + name = AHRS; + sourceTree = ""; + }; + 65B7E6AF120DF1E2000C1123 /* inc */ = { + isa = PBXGroup; + children = ( + 65B7E6B0120DF1E2000C1123 /* ahrs.h */, + 65B7E6B1120DF1E2000C1123 /* ahrs_fsm.h */, + 65B7E6B2120DF1E2000C1123 /* insgps.h */, + 65B7E6B3120DF1E2000C1123 /* pios_board.h */, + 65B7E6B4120DF1E2000C1123 /* pios_config.h */, + ); + name = inc; + path = ../../AHRS/inc; + sourceTree = SOURCE_ROOT; + }; 65E8EF1E11EEA61E00BBF654 /* OpenPilot */ = { isa = PBXGroup; children = ( @@ -516,6 +574,7 @@ 65E8EF4F11EEA61E00BBF654 /* Stabilization */, 65E8EF5311EEA61E00BBF654 /* System */, 65E8EF5711EEA61E00BBF654 /* Telemetry */, + 65003B2B1212499100C183DD /* Watchdog */, ); name = Modules; path = ../../OpenPilot/Modules; @@ -980,6 +1039,7 @@ 65E8F05211EFF25C00BBF654 /* pios_usart_priv.h */, 65E8F05311EFF25C00BBF654 /* pios_usb.h */, 65E8F05511EFF25C00BBF654 /* pios_usb_hid.h */, + 65003B30121249CA00C183DD /* pios_wdg.h */, 65E8F05611EFF25C00BBF654 /* stm32f10x_conf.h */, ); name = inc; @@ -1014,6 +1074,7 @@ 651CF9E6120B5D8300EEFD70 /* pios_usb_hid_istr.c */, 651CF9E7120B5D8300EEFD70 /* pios_usb_hid_prop.c */, 651CF9E8120B5D8300EEFD70 /* pios_usb_hid_pwr.c */, + 65003B31121249CA00C183DD /* pios_wdg.c */, 65E8F0EE11EFF25C00BBF654 /* startup_stm32f10x_HD.S */, 65E8F0EF11EFF25C00BBF654 /* startup_stm32f10x_HD_BL.S */, 65E8F0F011EFF25C00BBF654 /* startup_stm32f10x_HD_NB.S */,