2014-02-18 23:11:03 -08:00
|
|
|
/************************************************************************************//**
|
|
|
|
* \file Source\ARMCM4_TM4C\cpu.c
|
|
|
|
* \brief Bootloader cpu module source file.
|
|
|
|
* \ingroup Target_ARMCM4_TM4C
|
|
|
|
* \internal
|
|
|
|
*----------------------------------------------------------------------------------------
|
|
|
|
* C O P Y R I G H T
|
|
|
|
*----------------------------------------------------------------------------------------
|
|
|
|
* Copyright (c) 2014 by Feaser http://www.feaser.com All rights reserved
|
|
|
|
*
|
|
|
|
*----------------------------------------------------------------------------------------
|
|
|
|
* L I C E N S E
|
|
|
|
*----------------------------------------------------------------------------------------
|
|
|
|
* This file is part of OpenBLT. OpenBLT 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.
|
|
|
|
*
|
|
|
|
* OpenBLT 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 OpenBLT.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
2016-03-01 06:24:23 -08:00
|
|
|
* A special exception to the GPL is included to allow you to distribute a combined work
|
|
|
|
* that includes OpenBLT without being obliged to provide the source code for any
|
2014-02-18 23:11:03 -08:00
|
|
|
* proprietary components. The exception text is included at the bottom of the license
|
|
|
|
* file <license.html>.
|
2016-03-01 06:24:23 -08:00
|
|
|
*
|
2014-02-18 23:11:03 -08:00
|
|
|
* \endinternal
|
|
|
|
****************************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************************
|
|
|
|
* Include files
|
|
|
|
****************************************************************************************/
|
|
|
|
#include "boot.h" /* bootloader generic header */
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************************
|
|
|
|
* Macro definitions
|
|
|
|
****************************************************************************************/
|
2014-07-22 07:53:07 -07:00
|
|
|
/** \brief Pointer to the user program's reset vector. */
|
2016-02-25 05:51:12 -08:00
|
|
|
#define CPU_USER_PROGRAM_STARTADDR_PTR ((blt_addr)(NvmGetUserProgBaseAddress() + 0x00000004))
|
2014-07-22 07:53:07 -07:00
|
|
|
/** \brief Pointer to the user program's vector table. */
|
2016-02-25 05:51:12 -08:00
|
|
|
#define CPU_USER_PROGRAM_VECTABLE_OFFSET ((blt_int32u)NvmGetUserProgBaseAddress())
|
2014-02-18 23:11:03 -08:00
|
|
|
|
2016-03-01 06:24:23 -08:00
|
|
|
|
2014-02-18 23:11:03 -08:00
|
|
|
/****************************************************************************************
|
|
|
|
* Register definitions
|
|
|
|
****************************************************************************************/
|
|
|
|
/** \brief Vector table offset register. */
|
|
|
|
#define SCB_VTOR (*((volatile blt_int32u *) 0xE000ED08))
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************************
|
|
|
|
* Hook functions
|
|
|
|
****************************************************************************************/
|
|
|
|
#if (BOOT_CPU_USER_PROGRAM_START_HOOK > 0)
|
|
|
|
extern blt_bool CpuUserProgramStartHook(void);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************************
|
|
|
|
* External functions
|
|
|
|
****************************************************************************************/
|
|
|
|
extern void reset_handler(void); /* implemented in cstart.s */
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************************************************//**
|
|
|
|
** \brief Starts the user program, if one is present. In this case this function
|
2016-03-01 06:24:23 -08:00
|
|
|
** does not return.
|
2014-02-18 23:11:03 -08:00
|
|
|
** \return none.
|
|
|
|
**
|
|
|
|
****************************************************************************************/
|
|
|
|
void CpuStartUserProgram(void)
|
|
|
|
{
|
|
|
|
void (*pProgResetHandler)(void);
|
|
|
|
|
|
|
|
/* check if a user program is present by verifying the checksum */
|
|
|
|
if (NvmVerifyChecksum() == BLT_FALSE)
|
|
|
|
{
|
|
|
|
/* not a valid user program so it cannot be started */
|
|
|
|
return;
|
|
|
|
}
|
2016-03-01 06:24:23 -08:00
|
|
|
#if (BOOT_CPU_USER_PROGRAM_START_HOOK > 0)
|
2014-02-18 23:11:03 -08:00
|
|
|
/* invoke callback */
|
|
|
|
if (CpuUserProgramStartHook() == BLT_FALSE)
|
|
|
|
{
|
|
|
|
/* callback requests the user program to not be started */
|
|
|
|
return;
|
|
|
|
}
|
2016-03-01 06:24:23 -08:00
|
|
|
#endif
|
|
|
|
#if (BOOT_COM_ENABLE > 0)
|
2014-02-18 23:11:03 -08:00
|
|
|
/* release the communication interface */
|
|
|
|
ComFree();
|
2016-03-01 06:24:23 -08:00
|
|
|
#endif
|
2014-02-18 23:11:03 -08:00
|
|
|
/* reset the timer */
|
|
|
|
TimerReset();
|
|
|
|
/* remap user program's vector table */
|
|
|
|
SCB_VTOR = CPU_USER_PROGRAM_VECTABLE_OFFSET & (blt_int32u)0x1FFFFF80;
|
|
|
|
/* set the address where the bootloader needs to jump to. this is the address of
|
|
|
|
* the 2nd entry in the user program's vector table. this address points to the
|
|
|
|
* user program's reset handler.
|
|
|
|
*/
|
2016-03-01 06:24:23 -08:00
|
|
|
pProgResetHandler = (void(*)(void))(*((blt_addr *)CPU_USER_PROGRAM_STARTADDR_PTR));
|
2014-02-18 23:11:03 -08:00
|
|
|
/* start the user program by activating its reset interrupt service routine */
|
|
|
|
pProgResetHandler();
|
|
|
|
} /*** end of CpuStartUserProgram ***/
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************************************************//**
|
|
|
|
** \brief Copies data from the source to the destination address.
|
|
|
|
** \param dest Destination address for the data.
|
|
|
|
** \param src Source address of the data.
|
2016-03-01 06:24:23 -08:00
|
|
|
** \param len length of the data in bytes.
|
2014-02-18 23:11:03 -08:00
|
|
|
** \return none.
|
|
|
|
**
|
|
|
|
****************************************************************************************/
|
|
|
|
void CpuMemCopy(blt_addr dest, blt_addr src, blt_int16u len)
|
|
|
|
{
|
|
|
|
blt_int8u *from, *to;
|
|
|
|
|
|
|
|
/* set casted pointers */
|
|
|
|
from = (blt_int8u *)src;
|
|
|
|
to = (blt_int8u *)dest;
|
|
|
|
|
|
|
|
/* copy all bytes from source address to destination address */
|
2016-03-01 06:24:23 -08:00
|
|
|
while (len-- > 0)
|
2014-02-18 23:11:03 -08:00
|
|
|
{
|
|
|
|
/* store byte value from source to destination */
|
|
|
|
*to++ = *from++;
|
|
|
|
/* keep the watchdog happy */
|
|
|
|
CopService();
|
|
|
|
}
|
|
|
|
} /*** end of CpuMemCopy ***/
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************************************************//**
|
|
|
|
** \brief Perform a soft reset of the microcontroller by starting from the reset ISR.
|
|
|
|
** \return none.
|
|
|
|
**
|
|
|
|
****************************************************************************************/
|
|
|
|
void CpuReset(void)
|
|
|
|
{
|
|
|
|
/* perform a software reset by calling the reset ISR routine */
|
|
|
|
reset_handler();
|
|
|
|
} /*** end of CpuReset ***/
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************** end of cpu.c **************************************/
|