1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-17 02:52:12 +01:00

OP-21/Flight Bootloader

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1641 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
zedamota 2010-09-15 17:07:43 +00:00 committed by zedamota
parent cf864225fe
commit f972b78bfb
2 changed files with 135 additions and 22 deletions

View File

@ -0,0 +1,90 @@
/**
******************************************************************************
* @addtogroup PIOS PIOS Core hardware abstraction layer
* @{
* @addtogroup PIOS_BOOTLOADER Functions
* @brief HAL code to interface to the OpenPilot AHRS module
* @{
*
* @file pios_bl_helper.c
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief Bootloader Helper 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
*/
/* Project Includes */
#include "pios.h"
#if defined(PIOS_INCLUDE_BL_HELPER)
#include "stm32f10x_flash.h"
uint8_t *FLASH_If_Read(uint32_t SectorAddress) {
return (uint8_t*) (SectorAddress);
}
uint8_t FLASH_Ini() {
FLASH_Unlock();
return 1;
}
uint8_t FLASH_Start() {
uint32_t pageAdress;
pageAdress = START_OF_USER_CODE;
uint8_t fail = FALSE;
while ((pageAdress < START_OF_USER_CODE + SIZE_OF_CODE + SIZE_OF_DESCRIPTION)
|| (fail == TRUE)) {
for (int retry = 0; retry < MAX_DEL_RETRYS; ++retry) {
if (FLASH_ErasePage(pageAdress) == FLASH_COMPLETE) {
fail = FALSE;
break;
} else {
fail = TRUE;
}
}
#ifdef STM32F10X_HD
pageAdress += 2048;
#elif STM32F10X_MD
pageAdress += 1024;
#endif
}
return (fail == TRUE) ? 0 : 1;
}
uint32_t crc_memory_calc()
{
CRC_ResetDR();
CRC_CalcBlockCRC((uint32_t *) START_OF_USER_CODE, (SIZE_OF_CODE) >> 2);
return CRC_GetCRC();
}
void read_description(uint8_t * array)
{
for(uint32_t i=START_OF_USER_CODE+SIZE_OF_CODE;i<START_OF_USER_CODE+SIZE_OF_CODE+SIZE_OF_DESCRIPTION;++i)
{
*array=*FLASH_If_Read(i);
array++;
}
}
void CRC_Ini()
{
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_CRC, ENABLE);
}
#endif

View File

@ -56,7 +56,6 @@ static int32_t opahrs_msg_txrx (const uint8_t * tx, uint8_t * rx, uint32_t len)
return (rc);
}
static enum opahrs_result opahrs_msg_v0_send_req (const struct opahrs_msg_v0 * req)
{
int32_t rc;
@ -76,10 +75,10 @@ static enum opahrs_result opahrs_msg_v0_send_req (const struct opahrs_msg_v0 * r
}
switch (rsp->head.type) {
case OPAHRS_MSG_TYPE_LINK:
case OPAHRS_MSG_TYPE_LINK:
switch (rsp->payload.link.state) {
case OPAHRS_MSG_LINK_STATE_BUSY:
case OPAHRS_MSG_LINK_STATE_INACTIVE:
case OPAHRS_MSG_LINK_STATE_BUSY:
case OPAHRS_MSG_LINK_STATE_INACTIVE:
/* Wait for a small delay and retry */
#ifdef PIOS_INCLUDE_FREERTOS
vTaskDelay(20 / portTICK_RATE_MS);
@ -87,13 +86,13 @@ static enum opahrs_result opahrs_msg_v0_send_req (const struct opahrs_msg_v0 * r
PIOS_DELAY_WaitmS(20);
#endif
continue;
case OPAHRS_MSG_LINK_STATE_READY:
case OPAHRS_MSG_LINK_STATE_READY:
/* Peer was ready when we Tx'd so they have now Rx'd our message */
return OPAHRS_RESULT_OK;
}
break;
case OPAHRS_MSG_TYPE_USER_V0:
case OPAHRS_MSG_TYPE_USER_V1:
case OPAHRS_MSG_TYPE_USER_V0:
case OPAHRS_MSG_TYPE_USER_V1:
/* Wait for a small delay and retry */
#ifdef PIOS_INCLUDE_FREERTOS
vTaskDelay(50 / portTICK_RATE_MS);
@ -125,9 +124,9 @@ static enum opahrs_result opahrs_msg_v0_recv_rsp (enum opahrs_msg_v0_tag tag, st
}
switch (rsp->head.type) {
case OPAHRS_MSG_TYPE_LINK:
case OPAHRS_MSG_TYPE_LINK:
switch (rsp->payload.link.state) {
case OPAHRS_MSG_LINK_STATE_BUSY:
case OPAHRS_MSG_LINK_STATE_BUSY:
/* Wait for a small delay and retry */
#ifdef PIOS_INCLUDE_FREERTOS
vTaskDelay(20 / portTICK_RATE_MS);
@ -135,20 +134,20 @@ static enum opahrs_result opahrs_msg_v0_recv_rsp (enum opahrs_msg_v0_tag tag, st
PIOS_DELAY_WaitmS(20);
#endif
continue;
case OPAHRS_MSG_LINK_STATE_INACTIVE:
case OPAHRS_MSG_LINK_STATE_READY:
case OPAHRS_MSG_LINK_STATE_INACTIVE:
case OPAHRS_MSG_LINK_STATE_READY:
/* somehow, we've missed our response */
return OPAHRS_RESULT_FAILED;
}
break;
case OPAHRS_MSG_TYPE_USER_V0:
case OPAHRS_MSG_TYPE_USER_V0:
if (rsp->payload.user.t == tag) {
return OPAHRS_RESULT_OK;
} else {
return OPAHRS_RESULT_FAILED;
}
break;
case OPAHRS_MSG_TYPE_USER_V1:
case OPAHRS_MSG_TYPE_USER_V1:
/* This isn't the type we expected */
return OPAHRS_RESULT_FAILED;
break;
@ -169,8 +168,8 @@ static enum opahrs_result PIOS_OPAHRS_v0_simple_req (enum opahrs_msg_v0_tag req_
/* Send the message until it is received */
rc = opahrs_msg_v0_send_req (&req);
if ((rc == OPAHRS_RESULT_OK) && rsp) {
/* We need a specific kind of reply, go get it */
return opahrs_msg_v0_recv_rsp (rsp_type, rsp);
/* We need a specific kind of reply, go get it */
return opahrs_msg_v0_recv_rsp (rsp_type, rsp);
}
return rc;
@ -181,8 +180,17 @@ enum opahrs_result PIOS_OPAHRS_bl_GetVersions(struct opahrs_msg_v0 * rsp)
if (!rsp) return OPAHRS_RESULT_FAILED;
return (PIOS_OPAHRS_v0_simple_req (OPAHRS_MSG_V0_REQ_VERSIONS,
rsp,
OPAHRS_MSG_V0_RSP_VERSIONS));
rsp,
OPAHRS_MSG_V0_RSP_VERSIONS));
}
enum opahrs_result PIOS_OPAHRS_bl_GetMemMap(struct opahrs_msg_v0 * rsp)
{
if (!rsp) return OPAHRS_RESULT_FAILED;
return (PIOS_OPAHRS_v0_simple_req (OPAHRS_MSG_V0_REQ_MEM_MAP,
rsp,
OPAHRS_MSG_V0_RSP_MEM_MAP));
}
enum opahrs_result PIOS_OPAHRS_bl_GetSerial(struct opahrs_msg_v0 * rsp)
@ -190,8 +198,8 @@ enum opahrs_result PIOS_OPAHRS_bl_GetSerial(struct opahrs_msg_v0 * rsp)
if (!rsp) return OPAHRS_RESULT_FAILED;
return (PIOS_OPAHRS_v0_simple_req (OPAHRS_MSG_V0_REQ_SERIAL,
rsp,
OPAHRS_MSG_V0_RSP_SERIAL));
rsp,
OPAHRS_MSG_V0_RSP_SERIAL));
}
enum opahrs_result PIOS_OPAHRS_bl_FwupStart(struct opahrs_msg_v0 * req, struct opahrs_msg_v0 * rsp)
@ -233,11 +241,10 @@ enum opahrs_result PIOS_OPAHRS_bl_FwupVerify(struct opahrs_msg_v0 * rsp)
if (!rsp) return OPAHRS_RESULT_FAILED;
return (PIOS_OPAHRS_v0_simple_req (OPAHRS_MSG_V0_REQ_FWUP_VERIFY,
rsp,
OPAHRS_MSG_V0_RSP_FWUP_STATUS));
rsp,
OPAHRS_MSG_V0_RSP_FWUP_STATUS));
}
enum opahrs_result PIOS_OPAHRS_bl_resync(void)
{
struct opahrs_msg_v0 req;
@ -280,5 +287,21 @@ enum opahrs_result PIOS_OPAHRS_bl_resync(void)
return rc;
}
enum opahrs_result PIOS_OPAHRS_bl_reset()
{
struct opahrs_msg_v0 rsp;
return (PIOS_OPAHRS_v0_simple_req (OPAHRS_MSG_V0_REQ_RESET,
&rsp,
OPAHRS_MSG_V0_RSP_FWUP_STATUS));
}
enum opahrs_result PIOS_OPAHRS_bl_boot()
{
struct opahrs_msg_v0 rsp;
return (PIOS_OPAHRS_v0_simple_req (OPAHRS_MSG_V0_REQ_BOOT,
&rsp,
OPAHRS_MSG_V0_RSP_FWUP_STATUS));
}
#endif /* PIOS_INCLUDE_OPAHRS */