2012-06-05 00:38:57 +02:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
* @addtogroup PIOS PIOS Core hardware abstraction layer
|
|
|
|
* @{
|
|
|
|
* @addtogroup PIOS_IAP IAP Functions
|
|
|
|
* @brief STM32F4xx Hardware dependent I2C functionality
|
|
|
|
* @{
|
2010-10-06 04:02:37 +02:00
|
|
|
*
|
2012-06-05 00:38:57 +02:00
|
|
|
* @file pios_iap.c
|
|
|
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
|
|
|
|
* @brief In application programming functions
|
|
|
|
* @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
|
2010-10-06 04:02:37 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/****************************************************************************************
|
|
|
|
* Header files
|
|
|
|
****************************************************************************************/
|
2010-11-21 23:58:14 +01:00
|
|
|
#include <pios.h>
|
2010-10-06 04:02:37 +02:00
|
|
|
|
|
|
|
/****************************************************************************************
|
|
|
|
* Private Definitions/Macros
|
|
|
|
****************************************************************************************/
|
|
|
|
|
|
|
|
/* these definitions reside here for protection and privacy. */
|
|
|
|
#define IAP_MAGIC_WORD_1 0x1122
|
|
|
|
#define IAP_MAGIC_WORD_2 0xAA55
|
|
|
|
|
|
|
|
#define UPPERWORD16(lw) (uint16_t)((uint32_t)(lw)>>16)
|
|
|
|
#define LOWERWORD16(lw) (uint16_t)((uint32_t)(lw)&0x0000ffff)
|
|
|
|
#define UPPERBYTE(w) (uint8_t)((w)>>8)
|
|
|
|
#define LOWERBYTE(w) (uint8_t)((w)&0x00ff)
|
|
|
|
|
|
|
|
/****************************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************************
|
|
|
|
* Private (static) Data
|
|
|
|
****************************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************************
|
|
|
|
* Public/Global Data
|
|
|
|
****************************************************************************************/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief PIOS_IAP_Init - performs required initializations for iap module.
|
|
|
|
* \param none.
|
|
|
|
* \return none.
|
|
|
|
* \retval none.
|
|
|
|
*
|
|
|
|
* Created: Sep 8, 2010 10:10:48 PM by joe
|
|
|
|
*/
|
|
|
|
void PIOS_IAP_Init( void )
|
|
|
|
{
|
|
|
|
/* Enable CRC clock */
|
2012-06-05 00:38:57 +02:00
|
|
|
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_CRC, ENABLE);
|
2010-10-06 04:02:37 +02:00
|
|
|
|
|
|
|
/* Enable PWR and BKP clock */
|
2012-06-05 00:38:57 +02:00
|
|
|
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_AHB1Periph_BKPSRAM, ENABLE);
|
2010-10-06 04:02:37 +02:00
|
|
|
|
|
|
|
/* Enable write access to Backup domain */
|
|
|
|
PWR_BackupAccessCmd(ENABLE);
|
|
|
|
|
|
|
|
/* Clear Tamper pin Event(TE) pending flag */
|
2012-06-05 00:38:57 +02:00
|
|
|
RTC_ClearFlag(RTC_FLAG_TAMP1F);
|
2010-10-06 04:02:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Determines if an In-Application-Programming request has been made.
|
|
|
|
* \param *comm - Which communication stream to use for the IAP (USB, Telemetry, I2C, SPI, etc)
|
|
|
|
* \return TRUE - if correct sequence found, along with 'comm' updated.
|
|
|
|
* FALSE - Note that 'comm' will have an invalid comm identifier.
|
|
|
|
* \retval
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
uint32_t PIOS_IAP_CheckRequest( void )
|
|
|
|
{
|
2012-06-05 00:38:57 +02:00
|
|
|
uint32_t retval = false;
|
2010-10-06 04:02:37 +02:00
|
|
|
uint16_t reg1;
|
|
|
|
uint16_t reg2;
|
|
|
|
|
2012-06-05 00:38:57 +02:00
|
|
|
reg1 = RTC_ReadBackupRegister( MAGIC_REG_1 );
|
|
|
|
reg2 = RTC_ReadBackupRegister( MAGIC_REG_2 );
|
2010-10-06 04:02:37 +02:00
|
|
|
|
|
|
|
if( reg1 == IAP_MAGIC_WORD_1 && reg2 == IAP_MAGIC_WORD_2 ) {
|
|
|
|
// We have a match.
|
2012-06-05 00:38:57 +02:00
|
|
|
retval = true;
|
2010-10-06 04:02:37 +02:00
|
|
|
} else {
|
2012-06-05 00:38:57 +02:00
|
|
|
retval = false;
|
2010-10-06 04:02:37 +02:00
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Sets the 1st word of the request sequence.
|
|
|
|
* \param n/a
|
|
|
|
* \return n/a
|
|
|
|
* \retval
|
|
|
|
*/
|
|
|
|
void PIOS_IAP_SetRequest1(void)
|
|
|
|
{
|
2012-06-05 00:38:57 +02:00
|
|
|
RTC_WriteBackupRegister( MAGIC_REG_1, IAP_MAGIC_WORD_1);
|
2010-10-06 04:02:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void PIOS_IAP_SetRequest2(void)
|
|
|
|
{
|
2012-06-05 00:38:57 +02:00
|
|
|
RTC_WriteBackupRegister( MAGIC_REG_2, IAP_MAGIC_WORD_2);
|
2010-10-06 04:02:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void PIOS_IAP_ClearRequest(void)
|
|
|
|
{
|
2012-06-05 00:38:57 +02:00
|
|
|
RTC_WriteBackupRegister( MAGIC_REG_1, 0);
|
|
|
|
RTC_WriteBackupRegister( MAGIC_REG_2, 0);
|
2010-10-06 04:02:37 +02:00
|
|
|
}
|
2011-12-30 19:15:39 +01:00
|
|
|
|
|
|
|
uint16_t PIOS_IAP_ReadBootCount(void)
|
|
|
|
{
|
2012-06-05 00:38:57 +02:00
|
|
|
return RTC_ReadBackupRegister ( IAP_BOOTCOUNT );
|
2011-12-30 19:15:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void PIOS_IAP_WriteBootCount (uint16_t boot_count)
|
|
|
|
{
|
2012-06-05 00:38:57 +02:00
|
|
|
RTC_WriteBackupRegister ( IAP_BOOTCOUNT, boot_count );
|
2011-12-30 19:15:39 +01:00
|
|
|
}
|