- Corrected whitespace formatting with Astyle tool.

git-svn-id: https://svn.code.sf.net/p/openblt/code/trunk@132 5dc33758-31d5-4daf-9ae8-b24bf3d40d73
This commit is contained in:
Frank Voorburg 2016-03-01 14:24:23 +00:00
parent efbab9c73d
commit 90b766c778
173 changed files with 41206 additions and 38694 deletions

20
Doc/astyle.bat Normal file
View File

@ -0,0 +1,20 @@
@echo off
rem Configuration file for Astyle. Can be downloaded from: https://sourceforge.net/projects/astyle/?source=typ_redirect
rem Example usage: C:\Work\software\OpenBLT\Target\Source>..\..\Doc\astyle.bat *.c *.h
set ASTYLE_BIN="C:\AStyle\bin"
set ASTYLE_CODESTYLE_PARAMS=--mode=c --style=allman --indent=spaces=2 --indent-switches --pad-header --unpad-paren --lineend=windows --add-brackets --align-pointer=name
set ASTYLE_EXECUTION_PARAMS=--suffix=none --formatted --ignore-exclude-errors-x --recursive
echo.
echo ------------------ prepare astyle ---------------------------------------------
echo.
%ASTYLE_BIN%\AStyle.exe --version
echo style params: %ASTYLE_CODESTYLE_PARAMS%
echo exec params : %ASTYLE_EXECUTION_PARAMS%
echo user params : %*
echo target dir : %CD%
echo.
echo ------------------ astyle execution -------------------------------------------
echo.
%ASTYLE_BIN%\AStyle.exe %ASTYLE_CODESTYLE_PARAMS% %ASTYLE_EXECUTION_PARAMS% %*
echo.
echo ------------------ astyle done ------------------------------------------------

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -67,13 +67,13 @@
/****************************************************************************************
* Type definitions
****************************************************************************************/
/** \brief Function pointer type that is needed to call IAP functions of the
/** \brief Function pointer type that is needed to call IAP functions of the
* NXP LPC2xxx.
*/
typedef void (*pIapHandler)(blt_int32u command[], blt_int32u result[]);
/** \brief Flash sector descriptor type. */
typedef struct
typedef struct
{
blt_addr sector_start; /**< sector start address */
blt_int32u sector_size; /**< sector size in bytes */
@ -82,17 +82,17 @@ typedef struct
/** \brief Structure type for grouping flash block information.
* \details Programming is done per block of max FLASH_WRITE_BLOCK_SIZE. for this a
* \details Programming is done per block of max FLASH_WRITE_BLOCK_SIZE. for this a
* flash block manager is implemented in this driver. this flash block manager
* depends on this flash block info structure. It holds the base address of
* the flash block and the data that should be programmed into the flash
* depends on this flash block info structure. It holds the base address of
* the flash block and the data that should be programmed into the flash
* block. Note that the .data member must be 32-bit aligned by the linker.
* the .base_addr must be a multiple of FLASH_WRITE_BLOCK_SIZE.
*/
typedef struct
{
blt_addr base_addr; /**< Base address for the flash operation.*/
blt_int8u data[FLASH_WRITE_BLOCK_SIZE] __attribute__ ((aligned (4))); /**< Data array. */
blt_int8u data[FLASH_WRITE_BLOCK_SIZE] __attribute__((aligned(4))); /**< Data array. */
} tFlashBlockInfo;
@ -101,7 +101,7 @@ typedef struct
****************************************************************************************/
static blt_bool FlashInitBlock(tFlashBlockInfo *block, blt_addr address);
static tFlashBlockInfo *FlashSwitchBlock(tFlashBlockInfo *block, blt_addr base_addr);
static blt_bool FlashAddToBlock(tFlashBlockInfo *block, blt_addr address,
static blt_bool FlashAddToBlock(tFlashBlockInfo *block, blt_addr address,
blt_int8u *data, blt_int32u len);
static blt_bool FlashWriteBlock(tFlashBlockInfo *block);
static blt_bool FlashEraseSectors(blt_int8u first_sector, blt_int8u last_sector);
@ -112,11 +112,11 @@ static blt_int8u FlashGetSector(blt_addr address);
* Local constant declarations
****************************************************************************************/
/** \brief Array wit the layout of the flash memory.
* \details Also controls what part of the flash memory is reserved for the bootloader.
* If the bootloader size changes, the reserved sectors for the bootloader
* \details Also controls what part of the flash memory is reserved for the bootloader.
* If the bootloader size changes, the reserved sectors for the bootloader
* might need adjustment to make sure the bootloader doesn't get overwritten.
* The current flash layout supports the NXP LPC21xx and LPC22xx targets.
* LPC23xx has a slightly different layout. To support the LPC23xx, simply
* The current flash layout supports the NXP LPC21xx and LPC22xx targets.
* LPC23xx has a slightly different layout. To support the LPC23xx, simply
* update this flash layout.
*/
static const tFlashSector flashLayout[] =
@ -177,27 +177,27 @@ static const tFlashSector flashLayout[] =
****************************************************************************************/
/** \brief Local variable with information about the flash block that is currently
* being operated on.
* \details The smallest amount of flash that can be programmed is
* \details The smallest amount of flash that can be programmed is
* FLASH_WRITE_BLOCK_SIZE. A flash block manager is implemented in this driver
* and stores info in this variable. Whenever new data should be flashed, it
* is first added to a RAM buffer, which is part of this variable. Whenever
* the RAM buffer, which has the size of a flash block, is full or data needs
* to be written to a different block, the contents of the RAM buffer are
* programmed to flash. The flash block manager requires some software
* overhead, yet results is faster flash programming because data is first
* harvested, ideally until there is enough to program an entire flash block,
* to be written to a different block, the contents of the RAM buffer are
* programmed to flash. The flash block manager requires some software
* overhead, yet results is faster flash programming because data is first
* harvested, ideally until there is enough to program an entire flash block,
* before the flash device is actually operated on.
*/
static tFlashBlockInfo blockInfo;
static tFlashBlockInfo blockInfo;
/** \brief Local variable with information about the flash boot block.
* \details The first block of the user program holds the vector table, which on the
* LPC2000 is also the where the checksum is written to. Is it likely that the
* vector table is first flashed and then, at the end of the programming
* vector table is first flashed and then, at the end of the programming
* sequence, the checksum. This means that this flash block need to be written
* to twice. Normally this is not a problem with flash memory, as long as you
* write the same values to those bytes that are not supposed to be changed and
* the locations where you do write to are still in the erased 0xFF state.
* the locations where you do write to are still in the erased 0xFF state.
* Unfortunately, writing twice to flash this way, does not work reliably on
* the LPC2000. This is why we need to have an extra block, the bootblock,
* placed under the management of the block manager. This way is it possible
@ -208,7 +208,7 @@ static tFlashBlockInfo bootBlockInfo;
/************************************************************************************//**
** \brief Initializes the flash driver.
** \brief Initializes the flash driver.
** \return none.
**
****************************************************************************************/
@ -228,23 +228,23 @@ void FlashInit(void)
/************************************************************************************//**
** \brief Writes the data to flash through a flash block manager. Note that this
** function also checks that no data is programmed outside the flash
** function also checks that no data is programmed outside the flash
** memory region, so the bootloader can never be overwritten.
** \param addr Start address.
** \param len Length in bytes.
** \param data Pointer to the data buffer.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
blt_bool FlashWrite(blt_addr addr, blt_int32u len, blt_int8u *data)
{
blt_addr base_addr;
/* make sure the addresses are within the flash device */
if ( (FlashGetSector(addr) == FLASH_INVALID_SECTOR) || \
(FlashGetSector(addr+len-1) == FLASH_INVALID_SECTOR) )
if ((FlashGetSector(addr) == FLASH_INVALID_SECTOR) || \
(FlashGetSector(addr+len-1) == FLASH_INVALID_SECTOR))
{
return BLT_FALSE;
return BLT_FALSE;
}
/* if this is the bootblock, then let the boot block manager handle it */
@ -260,24 +260,24 @@ blt_bool FlashWrite(blt_addr addr, blt_int32u len, blt_int8u *data)
/************************************************************************************//**
** \brief Erases the flash memory. Note that this function also checks that no
** data is erased outside the flash memory region, so the bootloader can
** \brief Erases the flash memory. Note that this function also checks that no
** data is erased outside the flash memory region, so the bootloader can
** never be erased.
** \param addr Start address.
** \param len Length in bytes.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
blt_bool FlashErase(blt_addr addr, blt_int32u len)
{
blt_int8u first_sector;
blt_int8u last_sector;
/* obtain the first and last sector number */
first_sector = FlashGetSector(addr);
last_sector = FlashGetSector(addr+len-1);
/* check them */
if ( (first_sector == FLASH_INVALID_SECTOR) || (last_sector == FLASH_INVALID_SECTOR) )
if ((first_sector == FLASH_INVALID_SECTOR) || (last_sector == FLASH_INVALID_SECTOR))
{
return BLT_FALSE;
}
@ -292,16 +292,16 @@ blt_bool FlashErase(blt_addr addr, blt_int32u len)
** the checksum, the bootloader can check if the programming session
** was completed, which indicates that a valid user programming is
** present and can be started.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
blt_bool FlashWriteChecksum(void)
{
blt_int32u signature_checksum = 0;
/* The ARM7 core already has a spot reserved for a checksum that the bootloader can
* store at the end of a programming session.
*
* store at the end of a programming session.
*
* Layout of the vector table (* = don't care)
* 0x******00 Reset Exception
* 0x******04 Undefined Instruction Exception
@ -311,7 +311,7 @@ blt_bool FlashWriteChecksum(void)
* 0x******14 [reserved for signature checksum]
* 0x******18 IRQ Exception
* 0x******1C FIQ Exception
*
*
* signature_checksum = Two's complement of (SUM(exception address values))
*/
@ -319,50 +319,50 @@ blt_bool FlashWriteChecksum(void)
* bootblock is not part of the reprogramming this time and therefore no
* new checksum needs to be written
*/
if (bootBlockInfo.base_addr == FLASH_INVALID_ADDRESS)
{
if (bootBlockInfo.base_addr == FLASH_INVALID_ADDRESS)
{
return BLT_TRUE;
}
}
/* compute the checksum. note that the user program's vectors are not yet written
* to flash but are present in the bootblock data structure at this point.
*/
signature_checksum += *((blt_int32u*)(&bootBlockInfo.data[0+0x00]));
signature_checksum += *((blt_int32u*)(&bootBlockInfo.data[0+0x04]));
signature_checksum += *((blt_int32u*)(&bootBlockInfo.data[0+0x08]));
signature_checksum += *((blt_int32u*)(&bootBlockInfo.data[0+0x0C]));
signature_checksum += *((blt_int32u*)(&bootBlockInfo.data[0+0x10]));
signature_checksum += *((blt_int32u*)(&bootBlockInfo.data[0+0x18]));
signature_checksum += *((blt_int32u*)(&bootBlockInfo.data[0+0x1C]));
signature_checksum += *((blt_int32u *)(&bootBlockInfo.data[0+0x00]));
signature_checksum += *((blt_int32u *)(&bootBlockInfo.data[0+0x04]));
signature_checksum += *((blt_int32u *)(&bootBlockInfo.data[0+0x08]));
signature_checksum += *((blt_int32u *)(&bootBlockInfo.data[0+0x0C]));
signature_checksum += *((blt_int32u *)(&bootBlockInfo.data[0+0x10]));
signature_checksum += *((blt_int32u *)(&bootBlockInfo.data[0+0x18]));
signature_checksum += *((blt_int32u *)(&bootBlockInfo.data[0+0x1C]));
signature_checksum = ~signature_checksum; /* one's complement */
signature_checksum += 1; /* two's complement */
/* write the checksum */
return FlashWrite(flashLayout[0].sector_start+0x14, sizeof(blt_addr),
(blt_int8u*)&signature_checksum);
return FlashWrite(flashLayout[0].sector_start+0x14, sizeof(blt_addr),
(blt_int8u *)&signature_checksum);
} /*** end of FlashWriteChecksum ***/
/************************************************************************************//**
** \brief Verifies the checksum, which indicates that a valid user program is
** present and can be started.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
blt_bool FlashVerifyChecksum(void)
{
blt_int32u signature_checksum = 0;
/* verify the checksum based on how it was written by CpuWriteChecksum() */
signature_checksum += *((blt_int32u*)(flashLayout[0].sector_start));
signature_checksum += *((blt_int32u*)(flashLayout[0].sector_start+0x04));
signature_checksum += *((blt_int32u*)(flashLayout[0].sector_start+0x08));
signature_checksum += *((blt_int32u*)(flashLayout[0].sector_start+0x0C));
signature_checksum += *((blt_int32u*)(flashLayout[0].sector_start+0x10));
signature_checksum += *((blt_int32u*)(flashLayout[0].sector_start+0x14));
signature_checksum += *((blt_int32u*)(flashLayout[0].sector_start+0x18));
signature_checksum += *((blt_int32u*)(flashLayout[0].sector_start+0x1C));
signature_checksum += *((blt_int32u *)(flashLayout[0].sector_start));
signature_checksum += *((blt_int32u *)(flashLayout[0].sector_start+0x04));
signature_checksum += *((blt_int32u *)(flashLayout[0].sector_start+0x08));
signature_checksum += *((blt_int32u *)(flashLayout[0].sector_start+0x0C));
signature_checksum += *((blt_int32u *)(flashLayout[0].sector_start+0x10));
signature_checksum += *((blt_int32u *)(flashLayout[0].sector_start+0x14));
signature_checksum += *((blt_int32u *)(flashLayout[0].sector_start+0x18));
signature_checksum += *((blt_int32u *)(flashLayout[0].sector_start+0x1C));
/* sum should add up to an unsigned 32-bit value of 0 */
if (signature_checksum == 0)
{
@ -377,7 +377,7 @@ blt_bool FlashVerifyChecksum(void)
/************************************************************************************//**
** \brief Finalizes the flash driver operations. There could still be data in
** the currently active block that needs to be flashed.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
blt_bool FlashDone(void)
@ -390,7 +390,7 @@ blt_bool FlashDone(void)
return BLT_FALSE;
}
}
/* check if there is still data waiting to be programmed */
if (blockInfo.base_addr != FLASH_INVALID_ADDRESS)
{
@ -399,7 +399,7 @@ blt_bool FlashDone(void)
return BLT_FALSE;
}
}
/* still here so all is okay */
/* still here so all is okay */
return BLT_TRUE;
} /*** end of FlashDone ***/
@ -417,16 +417,16 @@ blt_addr FlashGetUserProgBaseAddress(void)
/************************************************************************************//**
** \brief Copies data currently in flash to the block->data and sets the
** \brief Copies data currently in flash to the block->data and sets the
** base address.
** \param block Pointer to flash block info structure to operate on.
** \param address Base address of the block data.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
static blt_bool FlashInitBlock(tFlashBlockInfo *block, blt_addr address)
{
/* check address alignment */
/* check address alignment */
if ((address % FLASH_WRITE_BLOCK_SIZE) != 0)
{
return BLT_FALSE;
@ -437,8 +437,8 @@ static blt_bool FlashInitBlock(tFlashBlockInfo *block, blt_addr address)
/* block already initialized, so nothing to do */
return BLT_TRUE;
}
/* set the base address and copies the current data from flash */
block->base_addr = address;
/* set the base address and copies the current data from flash */
block->base_addr = address;
CpuMemCopy((blt_addr)block->data, address, FLASH_WRITE_BLOCK_SIZE);
return BLT_TRUE;
} /*** end of FlashInitBlock ***/
@ -457,14 +457,14 @@ static tFlashBlockInfo *FlashSwitchBlock(tFlashBlockInfo *block, blt_addr base_a
{
/* check if a switch needs to be made away from the boot block. in this case the boot
* block shouldn't be written yet, because this is done at the end of the programming
* session by FlashDone(), this is right after the checksum was written.
* session by FlashDone(), this is right after the checksum was written.
*/
if (block == &bootBlockInfo)
{
/* switch from the boot block to the generic block info structure */
block = &blockInfo;
}
/* check if a switch back into the bootblock is needed. in this case the generic block
/* check if a switch back into the bootblock is needed. in this case the generic block
* doesn't need to be written here yet.
*/
else if (base_addr == flashLayout[0].sector_start)
@ -483,7 +483,7 @@ static tFlashBlockInfo *FlashSwitchBlock(tFlashBlockInfo *block, blt_addr base_a
}
/* initialize tne new block when necessary */
if (FlashInitBlock(block, base_addr) == BLT_FALSE)
if (FlashInitBlock(block, base_addr) == BLT_FALSE)
{
return BLT_NULL;
}
@ -505,13 +505,13 @@ static tFlashBlockInfo *FlashSwitchBlock(tFlashBlockInfo *block, blt_addr base_a
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
static blt_bool FlashAddToBlock(tFlashBlockInfo *block, blt_addr address,
static blt_bool FlashAddToBlock(tFlashBlockInfo *block, blt_addr address,
blt_int8u *data, blt_int32u len)
{
blt_addr current_base_addr;
blt_int8u *dst;
blt_int8u *src;
/* determine the current base address */
current_base_addr = (address/FLASH_WRITE_BLOCK_SIZE)*FLASH_WRITE_BLOCK_SIZE;
@ -535,7 +535,7 @@ static blt_bool FlashAddToBlock(tFlashBlockInfo *block, blt_addr address,
return BLT_FALSE;
}
}
/* add the data to the current block, but check for block overflow */
dst = &(block->data[address - block->base_addr]);
src = data;
@ -590,7 +590,7 @@ static blt_bool FlashWriteBlock(tFlashBlockInfo *block)
return BLT_FALSE;
}
/* send the prepare sector command for just this one sector */
iap_command[0] = IAP_CMD_PREPARE_SECTORS;
iap_command[0] = IAP_CMD_PREPARE_SECTORS;
iap_command[1] = sector_num;
iap_command[2] = sector_num;
iap_result[0] = !IAP_CMD_SUCCESS;
@ -602,7 +602,7 @@ static blt_bool FlashWriteBlock(tFlashBlockInfo *block)
return BLT_FALSE;
}
/* send the erase sector command */
iap_command[0] = IAP_CMD_COPY_RAM_TO_FLASH;
iap_command[0] = IAP_CMD_COPY_RAM_TO_FLASH;
iap_command[1] = (blt_int32u)block->base_addr;
iap_command[2] = (blt_int32u)block->data;
iap_command[3] = FLASH_WRITE_BLOCK_SIZE;
@ -616,7 +616,7 @@ static blt_bool FlashWriteBlock(tFlashBlockInfo *block)
return BLT_FALSE;
}
/* perform a comparison for verification purposes */
iap_command[0] = IAP_CMD_COMPARE;
iap_command[0] = IAP_CMD_COMPARE;
iap_command[1] = (blt_int32u)block->base_addr;
iap_command[2] = (blt_int32u)block->data;
iap_command[3] = FLASH_WRITE_BLOCK_SIZE;
@ -630,7 +630,7 @@ static blt_bool FlashWriteBlock(tFlashBlockInfo *block)
}
/* still here so all is okay */
return BLT_TRUE;
} /*** end of FlashWriteBlock ***/
@ -646,20 +646,20 @@ static blt_bool FlashEraseSectors(blt_int8u first_sector, blt_int8u last_sector)
blt_int32u iap_command[5];
blt_int32u iap_result[3];
pIapHandler iapHandler = (void *)IAP_ENTRY_ADDRESS;
/* validate the sector numbers */
if (first_sector > last_sector)
{
return BLT_FALSE;
}
if ( (first_sector < flashLayout[0].sector_num) || \
(last_sector > flashLayout[FLASH_TOTAL_SECTORS-1].sector_num) )
if ((first_sector < flashLayout[0].sector_num) || \
(last_sector > flashLayout[FLASH_TOTAL_SECTORS-1].sector_num))
{
return BLT_FALSE;
}
/* send the prepare sector command for just this one sector */
iap_command[0] = IAP_CMD_PREPARE_SECTORS;
iap_command[0] = IAP_CMD_PREPARE_SECTORS;
iap_command[1] = first_sector;
iap_command[2] = last_sector;
iap_result[0] = !IAP_CMD_SUCCESS;
@ -671,7 +671,7 @@ static blt_bool FlashEraseSectors(blt_int8u first_sector, blt_int8u last_sector)
return BLT_FALSE;
}
/* send the erase sector command */
iap_command[0] = IAP_CMD_ERASE_SECTORS;
iap_command[0] = IAP_CMD_ERASE_SECTORS;
iap_command[1] = first_sector;
iap_command[2] = last_sector;
iap_command[3] = BOOT_CPU_SYSTEM_SPEED_KHZ;
@ -684,7 +684,7 @@ static blt_bool FlashEraseSectors(blt_int8u first_sector, blt_int8u last_sector)
return BLT_FALSE;
}
/* perform a blank check for verification purposes */
iap_command[0] = IAP_CMD_BLANK_CHECK_SECTORS ;
iap_command[0] = IAP_CMD_BLANK_CHECK_SECTORS ;
iap_command[1] = first_sector;
iap_command[2] = last_sector;
iap_result[0] = !IAP_CMD_SUCCESS;
@ -709,16 +709,16 @@ static blt_bool FlashEraseSectors(blt_int8u first_sector, blt_int8u last_sector)
static blt_int8u FlashGetSector(blt_addr address)
{
blt_int8u sectorIdx;
/* search through the sectors to find the right one */
for (sectorIdx = 0; sectorIdx < FLASH_TOTAL_SECTORS; sectorIdx++)
{
/* keep the watchdog happy */
CopService();
/* is the address in this sector? */
if ( (address >= flashLayout[sectorIdx].sector_start) && \
(address < (flashLayout[sectorIdx].sector_start + \
flashLayout[sectorIdx].sector_size)) )
if ((address >= flashLayout[sectorIdx].sector_start) && \
(address < (flashLayout[sectorIdx].sector_start + \
flashLayout[sectorIdx].sector_size)))
{
/* return the sector number */
return flashLayout[sectorIdx].sector_num;

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
#ifndef FLASH_H

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -67,13 +67,13 @@
/****************************************************************************************
* Type definitions
****************************************************************************************/
/** \brief Function pointer type that is needed to call IAP functions of the
/** \brief Function pointer type that is needed to call IAP functions of the
* NXP LPC2xxx.
*/
typedef void (*pIapHandler)(blt_int32u command[], blt_int32u result[]);
/** \brief Flash sector descriptor type. */
typedef struct
typedef struct
{
blt_addr sector_start; /**< sector start address */
blt_int32u sector_size; /**< sector size in bytes */
@ -82,17 +82,17 @@ typedef struct
/** \brief Structure type for grouping flash block information.
* \details Programming is done per block of max FLASH_WRITE_BLOCK_SIZE. for this a
* \details Programming is done per block of max FLASH_WRITE_BLOCK_SIZE. for this a
* flash block manager is implemented in this driver. this flash block manager
* depends on this flash block info structure. It holds the base address of
* the flash block and the data that should be programmed into the flash
* depends on this flash block info structure. It holds the base address of
* the flash block and the data that should be programmed into the flash
* block. Note that the .data member must be 32-bit aligned by the linker.
* the .base_addr must be a multiple of FLASH_WRITE_BLOCK_SIZE.
*/
typedef struct
{
blt_addr base_addr; /**< Base address for the flash operation.*/
blt_int8u data[FLASH_WRITE_BLOCK_SIZE] __attribute__ ((aligned (4))); /**< Data array. */
blt_int8u data[FLASH_WRITE_BLOCK_SIZE] __attribute__((aligned(4))); /**< Data array. */
} tFlashBlockInfo;
@ -101,7 +101,7 @@ typedef struct
****************************************************************************************/
static blt_bool FlashInitBlock(tFlashBlockInfo *block, blt_addr address);
static tFlashBlockInfo *FlashSwitchBlock(tFlashBlockInfo *block, blt_addr base_addr);
static blt_bool FlashAddToBlock(tFlashBlockInfo *block, blt_addr address,
static blt_bool FlashAddToBlock(tFlashBlockInfo *block, blt_addr address,
blt_int8u *data, blt_int32u len);
static blt_bool FlashWriteBlock(tFlashBlockInfo *block);
static blt_bool FlashEraseSectors(blt_int8u first_sector, blt_int8u last_sector);
@ -112,11 +112,11 @@ static blt_int8u FlashGetSector(blt_addr address);
* Local constant declarations
****************************************************************************************/
/** \brief Array wit the layout of the flash memory.
* \details Also controls what part of the flash memory is reserved for the bootloader.
* If the bootloader size changes, the reserved sectors for the bootloader
* \details Also controls what part of the flash memory is reserved for the bootloader.
* If the bootloader size changes, the reserved sectors for the bootloader
* might need adjustment to make sure the bootloader doesn't get overwritten.
* The current flash layout supports the NXP LPC21xx and LPC22xx targets.
* LPC23xx has a slightly different layout. To support the LPC23xx, simply
* The current flash layout supports the NXP LPC21xx and LPC22xx targets.
* LPC23xx has a slightly different layout. To support the LPC23xx, simply
* update this flash layout.
*/
static const tFlashSector flashLayout[] =
@ -177,27 +177,27 @@ static const tFlashSector flashLayout[] =
****************************************************************************************/
/** \brief Local variable with information about the flash block that is currently
* being operated on.
* \details The smallest amount of flash that can be programmed is
* \details The smallest amount of flash that can be programmed is
* FLASH_WRITE_BLOCK_SIZE. A flash block manager is implemented in this driver
* and stores info in this variable. Whenever new data should be flashed, it
* is first added to a RAM buffer, which is part of this variable. Whenever
* the RAM buffer, which has the size of a flash block, is full or data needs
* to be written to a different block, the contents of the RAM buffer are
* programmed to flash. The flash block manager requires some software
* overhead, yet results is faster flash programming because data is first
* harvested, ideally until there is enough to program an entire flash block,
* to be written to a different block, the contents of the RAM buffer are
* programmed to flash. The flash block manager requires some software
* overhead, yet results is faster flash programming because data is first
* harvested, ideally until there is enough to program an entire flash block,
* before the flash device is actually operated on.
*/
static tFlashBlockInfo blockInfo;
static tFlashBlockInfo blockInfo;
/** \brief Local variable with information about the flash boot block.
* \details The first block of the user program holds the vector table, which on the
* LPC2000 is also the where the checksum is written to. Is it likely that the
* vector table is first flashed and then, at the end of the programming
* vector table is first flashed and then, at the end of the programming
* sequence, the checksum. This means that this flash block need to be written
* to twice. Normally this is not a problem with flash memory, as long as you
* write the same values to those bytes that are not supposed to be changed and
* the locations where you do write to are still in the erased 0xFF state.
* the locations where you do write to are still in the erased 0xFF state.
* Unfortunately, writing twice to flash this way, does not work reliably on
* the LPC2000. This is why we need to have an extra block, the bootblock,
* placed under the management of the block manager. This way is it possible
@ -208,7 +208,7 @@ static tFlashBlockInfo bootBlockInfo;
/************************************************************************************//**
** \brief Initializes the flash driver.
** \brief Initializes the flash driver.
** \return none.
**
****************************************************************************************/
@ -228,23 +228,23 @@ void FlashInit(void)
/************************************************************************************//**
** \brief Writes the data to flash through a flash block manager. Note that this
** function also checks that no data is programmed outside the flash
** function also checks that no data is programmed outside the flash
** memory region, so the bootloader can never be overwritten.
** \param addr Start address.
** \param len Length in bytes.
** \param data Pointer to the data buffer.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
blt_bool FlashWrite(blt_addr addr, blt_int32u len, blt_int8u *data)
{
blt_addr base_addr;
/* make sure the addresses are within the flash device */
if ( (FlashGetSector(addr) == FLASH_INVALID_SECTOR) || \
(FlashGetSector(addr+len-1) == FLASH_INVALID_SECTOR) )
if ((FlashGetSector(addr) == FLASH_INVALID_SECTOR) || \
(FlashGetSector(addr+len-1) == FLASH_INVALID_SECTOR))
{
return BLT_FALSE;
return BLT_FALSE;
}
/* if this is the bootblock, then let the boot block manager handle it */
@ -260,24 +260,24 @@ blt_bool FlashWrite(blt_addr addr, blt_int32u len, blt_int8u *data)
/************************************************************************************//**
** \brief Erases the flash memory. Note that this function also checks that no
** data is erased outside the flash memory region, so the bootloader can
** \brief Erases the flash memory. Note that this function also checks that no
** data is erased outside the flash memory region, so the bootloader can
** never be erased.
** \param addr Start address.
** \param len Length in bytes.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
blt_bool FlashErase(blt_addr addr, blt_int32u len)
{
blt_int8u first_sector;
blt_int8u last_sector;
/* obtain the first and last sector number */
first_sector = FlashGetSector(addr);
last_sector = FlashGetSector(addr+len-1);
/* check them */
if ( (first_sector == FLASH_INVALID_SECTOR) || (last_sector == FLASH_INVALID_SECTOR) )
if ((first_sector == FLASH_INVALID_SECTOR) || (last_sector == FLASH_INVALID_SECTOR))
{
return BLT_FALSE;
}
@ -292,16 +292,16 @@ blt_bool FlashErase(blt_addr addr, blt_int32u len)
** the checksum, the bootloader can check if the programming session
** was completed, which indicates that a valid user programming is
** present and can be started.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
blt_bool FlashWriteChecksum(void)
{
blt_int32u signature_checksum = 0;
/* The ARM7 core already has a spot reserved for a checksum that the bootloader can
* store at the end of a programming session.
*
* store at the end of a programming session.
*
* Layout of the vector table (* = don't care)
* 0x******00 Reset Exception
* 0x******04 Undefined Instruction Exception
@ -311,7 +311,7 @@ blt_bool FlashWriteChecksum(void)
* 0x******14 [reserved for signature checksum]
* 0x******18 IRQ Exception
* 0x******1C FIQ Exception
*
*
* signature_checksum = Two's complement of (SUM(exception address values))
*/
@ -319,50 +319,50 @@ blt_bool FlashWriteChecksum(void)
* bootblock is not part of the reprogramming this time and therefore no
* new checksum needs to be written
*/
if (bootBlockInfo.base_addr == FLASH_INVALID_ADDRESS)
{
if (bootBlockInfo.base_addr == FLASH_INVALID_ADDRESS)
{
return BLT_TRUE;
}
}
/* compute the checksum. note that the user program's vectors are not yet written
* to flash but are present in the bootblock data structure at this point.
*/
signature_checksum += *((blt_int32u*)(&bootBlockInfo.data[0+0x00]));
signature_checksum += *((blt_int32u*)(&bootBlockInfo.data[0+0x04]));
signature_checksum += *((blt_int32u*)(&bootBlockInfo.data[0+0x08]));
signature_checksum += *((blt_int32u*)(&bootBlockInfo.data[0+0x0C]));
signature_checksum += *((blt_int32u*)(&bootBlockInfo.data[0+0x10]));
signature_checksum += *((blt_int32u*)(&bootBlockInfo.data[0+0x18]));
signature_checksum += *((blt_int32u*)(&bootBlockInfo.data[0+0x1C]));
signature_checksum += *((blt_int32u *)(&bootBlockInfo.data[0+0x00]));
signature_checksum += *((blt_int32u *)(&bootBlockInfo.data[0+0x04]));
signature_checksum += *((blt_int32u *)(&bootBlockInfo.data[0+0x08]));
signature_checksum += *((blt_int32u *)(&bootBlockInfo.data[0+0x0C]));
signature_checksum += *((blt_int32u *)(&bootBlockInfo.data[0+0x10]));
signature_checksum += *((blt_int32u *)(&bootBlockInfo.data[0+0x18]));
signature_checksum += *((blt_int32u *)(&bootBlockInfo.data[0+0x1C]));
signature_checksum = ~signature_checksum; /* one's complement */
signature_checksum += 1; /* two's complement */
/* write the checksum */
return FlashWrite(flashLayout[0].sector_start+0x14, sizeof(blt_addr),
(blt_int8u*)&signature_checksum);
return FlashWrite(flashLayout[0].sector_start+0x14, sizeof(blt_addr),
(blt_int8u *)&signature_checksum);
} /*** end of FlashWriteChecksum ***/
/************************************************************************************//**
** \brief Verifies the checksum, which indicates that a valid user program is
** present and can be started.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
blt_bool FlashVerifyChecksum(void)
{
blt_int32u signature_checksum = 0;
/* verify the checksum based on how it was written by CpuWriteChecksum() */
signature_checksum += *((blt_int32u*)(flashLayout[0].sector_start));
signature_checksum += *((blt_int32u*)(flashLayout[0].sector_start+0x04));
signature_checksum += *((blt_int32u*)(flashLayout[0].sector_start+0x08));
signature_checksum += *((blt_int32u*)(flashLayout[0].sector_start+0x0C));
signature_checksum += *((blt_int32u*)(flashLayout[0].sector_start+0x10));
signature_checksum += *((blt_int32u*)(flashLayout[0].sector_start+0x14));
signature_checksum += *((blt_int32u*)(flashLayout[0].sector_start+0x18));
signature_checksum += *((blt_int32u*)(flashLayout[0].sector_start+0x1C));
signature_checksum += *((blt_int32u *)(flashLayout[0].sector_start));
signature_checksum += *((blt_int32u *)(flashLayout[0].sector_start+0x04));
signature_checksum += *((blt_int32u *)(flashLayout[0].sector_start+0x08));
signature_checksum += *((blt_int32u *)(flashLayout[0].sector_start+0x0C));
signature_checksum += *((blt_int32u *)(flashLayout[0].sector_start+0x10));
signature_checksum += *((blt_int32u *)(flashLayout[0].sector_start+0x14));
signature_checksum += *((blt_int32u *)(flashLayout[0].sector_start+0x18));
signature_checksum += *((blt_int32u *)(flashLayout[0].sector_start+0x1C));
/* sum should add up to an unsigned 32-bit value of 0 */
if (signature_checksum == 0)
{
@ -377,7 +377,7 @@ blt_bool FlashVerifyChecksum(void)
/************************************************************************************//**
** \brief Finalizes the flash driver operations. There could still be data in
** the currently active block that needs to be flashed.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
blt_bool FlashDone(void)
@ -390,7 +390,7 @@ blt_bool FlashDone(void)
return BLT_FALSE;
}
}
/* check if there is still data waiting to be programmed */
if (blockInfo.base_addr != FLASH_INVALID_ADDRESS)
{
@ -399,7 +399,7 @@ blt_bool FlashDone(void)
return BLT_FALSE;
}
}
/* still here so all is okay */
/* still here so all is okay */
return BLT_TRUE;
} /*** end of FlashDone ***/
@ -417,16 +417,16 @@ blt_addr FlashGetUserProgBaseAddress(void)
/************************************************************************************//**
** \brief Copies data currently in flash to the block->data and sets the
** \brief Copies data currently in flash to the block->data and sets the
** base address.
** \param block Pointer to flash block info structure to operate on.
** \param address Base address of the block data.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
static blt_bool FlashInitBlock(tFlashBlockInfo *block, blt_addr address)
{
/* check address alignment */
/* check address alignment */
if ((address % FLASH_WRITE_BLOCK_SIZE) != 0)
{
return BLT_FALSE;
@ -437,8 +437,8 @@ static blt_bool FlashInitBlock(tFlashBlockInfo *block, blt_addr address)
/* block already initialized, so nothing to do */
return BLT_TRUE;
}
/* set the base address and copies the current data from flash */
block->base_addr = address;
/* set the base address and copies the current data from flash */
block->base_addr = address;
CpuMemCopy((blt_addr)block->data, address, FLASH_WRITE_BLOCK_SIZE);
return BLT_TRUE;
} /*** end of FlashInitBlock ***/
@ -457,14 +457,14 @@ static tFlashBlockInfo *FlashSwitchBlock(tFlashBlockInfo *block, blt_addr base_a
{
/* check if a switch needs to be made away from the boot block. in this case the boot
* block shouldn't be written yet, because this is done at the end of the programming
* session by FlashDone(), this is right after the checksum was written.
* session by FlashDone(), this is right after the checksum was written.
*/
if (block == &bootBlockInfo)
{
/* switch from the boot block to the generic block info structure */
block = &blockInfo;
}
/* check if a switch back into the bootblock is needed. in this case the generic block
/* check if a switch back into the bootblock is needed. in this case the generic block
* doesn't need to be written here yet.
*/
else if (base_addr == flashLayout[0].sector_start)
@ -483,7 +483,7 @@ static tFlashBlockInfo *FlashSwitchBlock(tFlashBlockInfo *block, blt_addr base_a
}
/* initialize tne new block when necessary */
if (FlashInitBlock(block, base_addr) == BLT_FALSE)
if (FlashInitBlock(block, base_addr) == BLT_FALSE)
{
return BLT_NULL;
}
@ -505,13 +505,13 @@ static tFlashBlockInfo *FlashSwitchBlock(tFlashBlockInfo *block, blt_addr base_a
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
static blt_bool FlashAddToBlock(tFlashBlockInfo *block, blt_addr address,
static blt_bool FlashAddToBlock(tFlashBlockInfo *block, blt_addr address,
blt_int8u *data, blt_int32u len)
{
blt_addr current_base_addr;
blt_int8u *dst;
blt_int8u *src;
/* determine the current base address */
current_base_addr = (address/FLASH_WRITE_BLOCK_SIZE)*FLASH_WRITE_BLOCK_SIZE;
@ -535,7 +535,7 @@ static blt_bool FlashAddToBlock(tFlashBlockInfo *block, blt_addr address,
return BLT_FALSE;
}
}
/* add the data to the current block, but check for block overflow */
dst = &(block->data[address - block->base_addr]);
src = data;
@ -590,7 +590,7 @@ static blt_bool FlashWriteBlock(tFlashBlockInfo *block)
return BLT_FALSE;
}
/* send the prepare sector command for just this one sector */
iap_command[0] = IAP_CMD_PREPARE_SECTORS;
iap_command[0] = IAP_CMD_PREPARE_SECTORS;
iap_command[1] = sector_num;
iap_command[2] = sector_num;
iap_result[0] = !IAP_CMD_SUCCESS;
@ -602,7 +602,7 @@ static blt_bool FlashWriteBlock(tFlashBlockInfo *block)
return BLT_FALSE;
}
/* send the erase sector command */
iap_command[0] = IAP_CMD_COPY_RAM_TO_FLASH;
iap_command[0] = IAP_CMD_COPY_RAM_TO_FLASH;
iap_command[1] = (blt_int32u)block->base_addr;
iap_command[2] = (blt_int32u)block->data;
iap_command[3] = FLASH_WRITE_BLOCK_SIZE;
@ -616,7 +616,7 @@ static blt_bool FlashWriteBlock(tFlashBlockInfo *block)
return BLT_FALSE;
}
/* perform a comparison for verification purposes */
iap_command[0] = IAP_CMD_COMPARE;
iap_command[0] = IAP_CMD_COMPARE;
iap_command[1] = (blt_int32u)block->base_addr;
iap_command[2] = (blt_int32u)block->data;
iap_command[3] = FLASH_WRITE_BLOCK_SIZE;
@ -630,7 +630,7 @@ static blt_bool FlashWriteBlock(tFlashBlockInfo *block)
}
/* still here so all is okay */
return BLT_TRUE;
} /*** end of FlashWriteBlock ***/
@ -646,20 +646,20 @@ static blt_bool FlashEraseSectors(blt_int8u first_sector, blt_int8u last_sector)
blt_int32u iap_command[5];
blt_int32u iap_result[3];
pIapHandler iapHandler = (void *)IAP_ENTRY_ADDRESS;
/* validate the sector numbers */
if (first_sector > last_sector)
{
return BLT_FALSE;
}
if ( (first_sector < flashLayout[0].sector_num) || \
(last_sector > flashLayout[FLASH_TOTAL_SECTORS-1].sector_num) )
if ((first_sector < flashLayout[0].sector_num) || \
(last_sector > flashLayout[FLASH_TOTAL_SECTORS-1].sector_num))
{
return BLT_FALSE;
}
/* send the prepare sector command for just this one sector */
iap_command[0] = IAP_CMD_PREPARE_SECTORS;
iap_command[0] = IAP_CMD_PREPARE_SECTORS;
iap_command[1] = first_sector;
iap_command[2] = last_sector;
iap_result[0] = !IAP_CMD_SUCCESS;
@ -671,7 +671,7 @@ static blt_bool FlashEraseSectors(blt_int8u first_sector, blt_int8u last_sector)
return BLT_FALSE;
}
/* send the erase sector command */
iap_command[0] = IAP_CMD_ERASE_SECTORS;
iap_command[0] = IAP_CMD_ERASE_SECTORS;
iap_command[1] = first_sector;
iap_command[2] = last_sector;
iap_command[3] = BOOT_CPU_SYSTEM_SPEED_KHZ;
@ -684,7 +684,7 @@ static blt_bool FlashEraseSectors(blt_int8u first_sector, blt_int8u last_sector)
return BLT_FALSE;
}
/* perform a blank check for verification purposes */
iap_command[0] = IAP_CMD_BLANK_CHECK_SECTORS ;
iap_command[0] = IAP_CMD_BLANK_CHECK_SECTORS ;
iap_command[1] = first_sector;
iap_command[2] = last_sector;
iap_result[0] = !IAP_CMD_SUCCESS;
@ -709,16 +709,16 @@ static blt_bool FlashEraseSectors(blt_int8u first_sector, blt_int8u last_sector)
static blt_int8u FlashGetSector(blt_addr address)
{
blt_int8u sectorIdx;
/* search through the sectors to find the right one */
for (sectorIdx = 0; sectorIdx < FLASH_TOTAL_SECTORS; sectorIdx++)
{
/* keep the watchdog happy */
CopService();
/* is the address in this sector? */
if ( (address >= flashLayout[sectorIdx].sector_start) && \
(address < (flashLayout[sectorIdx].sector_start + \
flashLayout[sectorIdx].sector_size)) )
if ((address >= flashLayout[sectorIdx].sector_start) && \
(address < (flashLayout[sectorIdx].sector_start + \
flashLayout[sectorIdx].sector_size)))
{
/* return the sector number */
return flashLayout[sectorIdx].sector_num;

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
#ifndef FLASH_H

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -41,9 +41,9 @@
/****************************************************************************************
* Function prototypes
****************************************************************************************/
void __attribute__ ((interrupt("FIQ"))) FIQ_ISR(void);
void __attribute__ ((interrupt("IRQ"))) IRQ_ISR(void);
void __attribute__ ((interrupt("UNDEF"))) UNDEF_ISR(void);
void __attribute__((interrupt("FIQ"))) FIQ_ISR(void);
void __attribute__((interrupt("IRQ"))) IRQ_ISR(void);
void __attribute__((interrupt("UNDEF"))) UNDEF_ISR(void);
/************************************************************************************//**

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -43,7 +43,7 @@
* Macro definitions
****************************************************************************************/
/** \brief Transmit buffer 1 idle bit. */
#define CAN_TBS1 (0x00000004)
#define CAN_TBS1 (0x00000004)
/** \brief Transmit buffer 1 complete bit. */
#define CAN_TCS1 (0x00000008)
/** \brief Receive buffer release bit. */
@ -104,42 +104,43 @@ typedef struct t_can_bus_timing
* Local constant declarations
****************************************************************************************/
/** \brief CAN bittiming table for dynamically calculating the bittiming settings.
* \details According to the CAN protocol 1 bit-time can be made up of between 8..25
* time quanta (TQ). The total TQ in a bit is SYNC + TSEG1 + TSEG2 with SYNC
* always being 1. The sample point is (SYNC + TSEG1) / (SYNC + TSEG1 + SEG2) *
* \details According to the CAN protocol 1 bit-time can be made up of between 8..25
* time quanta (TQ). The total TQ in a bit is SYNC + TSEG1 + TSEG2 with SYNC
* always being 1. The sample point is (SYNC + TSEG1) / (SYNC + TSEG1 + SEG2) *
* 100%. This array contains possible and valid time quanta configurations with
* a sample point between 68..78%.
*/
static const tCanBusTiming canTiming[] =
{ /* TQ | TSEG1 | TSEG2 | SP */
/* ------------------------- */
{ 5, 2 }, /* 8 | 5 | 2 | 75% */
{ 6, 2 }, /* 9 | 6 | 2 | 78% */
{ 6, 3 }, /* 10 | 6 | 3 | 70% */
{ 7, 3 }, /* 11 | 7 | 3 | 73% */
{ 8, 3 }, /* 12 | 8 | 3 | 75% */
{ 9, 3 }, /* 13 | 9 | 3 | 77% */
{ 9, 4 }, /* 14 | 9 | 4 | 71% */
{ 10, 4 }, /* 15 | 10 | 4 | 73% */
{ 11, 4 }, /* 16 | 11 | 4 | 75% */
{ 12, 4 }, /* 17 | 12 | 4 | 76% */
{ 12, 5 }, /* 18 | 12 | 5 | 72% */
{ 13, 5 }, /* 19 | 13 | 5 | 74% */
{ 14, 5 }, /* 20 | 14 | 5 | 75% */
{ 15, 5 }, /* 21 | 15 | 5 | 76% */
{ 15, 6 }, /* 22 | 15 | 6 | 73% */
{ 16, 6 }, /* 23 | 16 | 6 | 74% */
{ 16, 7 }, /* 24 | 16 | 7 | 71% */
{ 16, 8 } /* 25 | 16 | 8 | 68% */
{
/* TQ | TSEG1 | TSEG2 | SP */
/* ------------------------- */
{ 5, 2 }, /* 8 | 5 | 2 | 75% */
{ 6, 2 }, /* 9 | 6 | 2 | 78% */
{ 6, 3 }, /* 10 | 6 | 3 | 70% */
{ 7, 3 }, /* 11 | 7 | 3 | 73% */
{ 8, 3 }, /* 12 | 8 | 3 | 75% */
{ 9, 3 }, /* 13 | 9 | 3 | 77% */
{ 9, 4 }, /* 14 | 9 | 4 | 71% */
{ 10, 4 }, /* 15 | 10 | 4 | 73% */
{ 11, 4 }, /* 16 | 11 | 4 | 75% */
{ 12, 4 }, /* 17 | 12 | 4 | 76% */
{ 12, 5 }, /* 18 | 12 | 5 | 72% */
{ 13, 5 }, /* 19 | 13 | 5 | 74% */
{ 14, 5 }, /* 20 | 14 | 5 | 75% */
{ 15, 5 }, /* 21 | 15 | 5 | 76% */
{ 15, 6 }, /* 22 | 15 | 6 | 73% */
{ 16, 6 }, /* 23 | 16 | 6 | 74% */
{ 16, 7 }, /* 24 | 16 | 7 | 71% */
{ 16, 8 } /* 25 | 16 | 8 | 68% */
};
/************************************************************************************//**
** \brief Search algorithm to match the desired baudrate to a possible bus
** \brief Search algorithm to match the desired baudrate to a possible bus
** timing configuration.
** \param baud The desired baudrate in kbps. Valid values are 10..1000.
** \param btr Pointer to where the value for register CANxBTR will be stored.
** \return BLT_TRUE if the CAN bustiming register values were found, BLT_FALSE
** \return BLT_TRUE if the CAN bustiming register values were found, BLT_FALSE
** otherwise.
**
****************************************************************************************/
@ -157,7 +158,7 @@ static blt_bool CanGetSpeedConfig(blt_int16u baud, blt_int32u *btr)
prescaler = BOOT_CPU_SYSTEM_SPEED_KHZ/(baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1));
/* make sure the prescaler is valid */
if ( (prescaler > 0) && (prescaler <= 1024) )
if ((prescaler > 0) && (prescaler <= 1024))
{
/* store the prescaler and bustiming register value */
*btr = prescaler - 1;
@ -181,25 +182,25 @@ void CanInit(void)
{
blt_bool result;
blt_int32u btr_reg_value=0;
/* the current implementation supports CAN1, which has channel index 0. throw an
* assertion error in case a different CAN channel is configured.
/* the current implementation supports CAN1, which has channel index 0. throw an
* assertion error in case a different CAN channel is configured.
*/
ASSERT_CT(BOOT_COM_CAN_CHANNEL_INDEX == 0);
ASSERT_CT(BOOT_COM_CAN_CHANNEL_INDEX == 0);
/* configure acceptance filter for bypass mode so it receives all messages */
CANAFMR = 0x00000002L;
/* take CAN controller offline and go into reset mode */
CAN1MOD = 1;
CAN1MOD = 1;
/* disable all interrupts. driver only needs to work in polling mode */
CAN1IER = 0;
/* reset CAN controller status */
CAN1GSR = 0;
CAN1GSR = 0;
/* configure the bittiming */
result = CanGetSpeedConfig(BOOT_COM_CAN_BAUDRATE/1000, &btr_reg_value);
/* check that a valid baudrate configuration was found */
ASSERT_RT(result == BLT_TRUE);
/* write the bittiming configuration to the register */
CAN1BTR = btr_reg_value;
CAN1BTR = btr_reg_value;
/* enter normal operating mode and synchronize to the CAN bus */
CAN1MOD = 0;
} /*** end of CanInit ***/
@ -217,7 +218,7 @@ void CanTransmitPacket(blt_int8u *data, blt_int8u len)
/* check that transmit buffer 1 is ready to accept a new message */
ASSERT_RT((CAN1SR & CAN_TBS1) != 0);
/* write dlc and configure message as a standard message with 11-bit identifier */
CAN1TFI1 = (len << 16);
CAN1TFI1 = (len << 16);
/* write the message identifier */
CAN1TID1 = BOOT_COM_CAN_TX_MSG_ID;
/* write the first set of 4 data bytes */
@ -227,7 +228,7 @@ void CanTransmitPacket(blt_int8u *data, blt_int8u len)
/* write transmission request for transmit buffer 1 */
CAN1CMR = CAN_TR | CAN_STB1;
/* wait for transmit completion */
while ((CAN1SR & CAN_TCS1) == 0)
while ((CAN1SR & CAN_TCS1) == 0)
{
/* keep the watchdog happy */
CopService();
@ -254,14 +255,14 @@ blt_bool CanReceivePacket(blt_int8u *data)
return BLT_FALSE;
}
/* store the message data */
data[0] = (blt_int8u)CAN1RDA;
data[1] = (blt_int8u)(CAN1RDA >> 8);
data[2] = (blt_int8u)(CAN1RDA >> 16);
data[3] = (blt_int8u)(CAN1RDA >> 24);
data[4] = (blt_int8u)CAN1RDB;
data[5] = (blt_int8u)(CAN1RDB >> 8);
data[6] = (blt_int8u)(CAN1RDB >> 16);
data[7] = (blt_int8u)(CAN1RDB >> 24);
data[0] = (blt_int8u)CAN1RDA;
data[1] = (blt_int8u)(CAN1RDA >> 8);
data[2] = (blt_int8u)(CAN1RDA >> 16);
data[3] = (blt_int8u)(CAN1RDA >> 24);
data[4] = (blt_int8u)CAN1RDB;
data[5] = (blt_int8u)(CAN1RDB >> 8);
data[6] = (blt_int8u)(CAN1RDB >> 16);
data[7] = (blt_int8u)(CAN1RDB >> 24);
/* release the receive buffer */
CAN1CMR = CAN_RRB;
/* inform called that a new data was received */

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -71,43 +71,43 @@ extern void Reset_Handler(void); /* reset service routine in cst
/************************************************************************************//**
** \brief Starts the user program, if one is present. In this case this function
** does not return.
** does not return.
** \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;
}
#if (BOOT_CPU_USER_PROGRAM_START_HOOK > 0)
#if (BOOT_CPU_USER_PROGRAM_START_HOOK > 0)
/* invoke callback */
if (CpuUserProgramStartHook() == BLT_FALSE)
{
/* callback requests the user program to not be started */
return;
}
#endif
#if (BOOT_COM_ENABLE > 0)
#endif
#if (BOOT_COM_ENABLE > 0)
/* release the communication interface */
ComFree();
#endif
#endif
/* reset the timer */
TimerReset();
/* copy the user program's interrupt vector table to RAM */
CpuMemCopy(CPU_RAM_VECTORS_START_ADDR, CPU_USER_PROG_VECTORS_START_ADDR, \
CPU_VECTORS_TABLE_SIZE);
/* select RAM vector table */
MEMMAP = 0x02;
/* set the address where the bootloader needs to jump to */
pProgResetHandler = (void*)CPU_RAM_VECTORS_START_ADDR;
pProgResetHandler = (void *)CPU_RAM_VECTORS_START_ADDR;
/* start the user program by activating its reset interrupt service routine */
pProgResetHandler();
@ -118,7 +118,7 @@ void CpuStartUserProgram(void)
** \brief Copies data from the source to the destination address.
** \param dest Destination address for the data.
** \param src Source address of the data.
** \param len length of the data in bytes.
** \param len length of the data in bytes.
** \return none.
**
****************************************************************************************/
@ -131,7 +131,7 @@ void CpuMemCopy(blt_addr dest, blt_addr src, blt_int16u len)
to = (blt_int8u *)dest;
/* copy all bytes from source address to destination address */
while(len-- > 0)
while (len-- > 0)
{
/* store byte value from source to destination */
*to++ = *from++;
@ -151,7 +151,7 @@ void CpuReset(void)
/* perform a software reset by calling the reset ISR routine. note that this requires
* access to the processor status registers (PSRs), which works because the entire
* bootloader runs in supervisor mode.
*/
*/
Reset_Handler();
} /*** end of CpuReset ***/

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -93,12 +93,12 @@ blt_bool NvmWrite(blt_addr addr, blt_int32u len, blt_int8u *data)
* by this driver.
*/
result = NvmWriteHook(addr, len, data);
/* process the return code */
if (result == BLT_NVM_OKAY)
{
/* data was within range of the additionally supported memory and succesfully
* programmed, so we are all done.
* programmed, so we are all done.
*/
return BLT_TRUE;
}
@ -134,12 +134,12 @@ blt_bool NvmErase(blt_addr addr, blt_int32u len)
* by this driver.
*/
result = NvmEraseHook(addr, len);
/* process the return code */
if (result == BLT_NVM_OKAY)
{
/* address was within range of the additionally supported memory and succesfully
* erased, so we are all done.
* erased, so we are all done.
*/
return BLT_TRUE;
}
@ -176,7 +176,7 @@ blt_bool NvmVerifyChecksum(void)
/************************************************************************************//**
** \brief Obtains the base address of the non-volatile memory available to the user
** \brief Obtains the base address of the non-volatile memory available to the user
** program. This is typically that start of the vector table.
** \return Base address.
**
@ -188,11 +188,11 @@ blt_addr NvmGetUserProgBaseAddress(void)
/************************************************************************************//**
** \brief Once all erase and programming operations are completed, this
** function is called, so at the end of the programming session and
** \brief Once all erase and programming operations are completed, this
** function is called, so at the end of the programming session and
** right before a software reset is performed. It is used to calculate
** a checksum and program this into flash. This checksum is later used
** to determine if a valid user program is present in flash.
** to determine if a valid user program is present in flash.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -133,7 +133,7 @@ blt_int32u TimerGet(void)
* detection.
*/
TimerUpdate();
/* read and return the amount of milliseconds that passed since initialization */
return millisecond_counter;
} /*** end of TimerGet ***/

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
#ifndef TYPES_H

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -100,11 +100,11 @@ static blt_bool UartTransmitByte(blt_int8u data);
void UartInit(void)
{
blt_int32u baud_reg_value; /* baudrate register value */
/* the current implementation supports UART0. throw an assertion error in case
* a different UART channel is configured.
/* the current implementation supports UART0. throw an assertion error in case
* a different UART channel is configured.
*/
ASSERT_CT(BOOT_COM_UART_CHANNEL_INDEX == 0);
ASSERT_CT(BOOT_COM_UART_CHANNEL_INDEX == 0);
/* disable UART related interrupt generation. this driver works in polling mode */
U0IER = 0;
/* clear interrupt id register */
@ -113,19 +113,19 @@ void UartInit(void)
U0LSR = 0;
/* set divisor latch DLAB = 1 so buadrate can be configured */
U0LCR = UART_DLAB;
/* Baudrate calculation:
* y = BOOT_CPU_SYSTEM_SPEED_KHZ * 1000 / 16 / BOOT_COM_UART_BAUDRATE and add
/* Baudrate calculation:
* y = BOOT_CPU_SYSTEM_SPEED_KHZ * 1000 / 16 / BOOT_COM_UART_BAUDRATE and add
* smartness to automatically round the value up/down using the following trick:
* y = x/n can round with y = (x + (n + 1)/2 ) / n
*/
/* check that baudrate register value is not 0 */
ASSERT_CT((((BOOT_CPU_SYSTEM_SPEED_KHZ*1000/16)+((BOOT_COM_UART_BAUDRATE+1)/2))/ \
BOOT_COM_UART_BAUDRATE) > 0);
BOOT_COM_UART_BAUDRATE) > 0);
/* check that baudrate register value is not greater than max 16-bit unsigned value */
ASSERT_CT((((BOOT_CPU_SYSTEM_SPEED_KHZ*1000/16)+((BOOT_COM_UART_BAUDRATE+1)/2))/ \
BOOT_COM_UART_BAUDRATE) <= 65535);
BOOT_COM_UART_BAUDRATE) <= 65535);
baud_reg_value = (((BOOT_CPU_SYSTEM_SPEED_KHZ*1000/16)+ \
((BOOT_COM_UART_BAUDRATE+1)/2))/BOOT_COM_UART_BAUDRATE);
((BOOT_COM_UART_BAUDRATE+1)/2))/BOOT_COM_UART_BAUDRATE);
/* write the calculated baudrate selector value to the registers */
U0DLL = (blt_int8u)baud_reg_value;
U0DLM = (blt_int8u)(baud_reg_value >> 8);
@ -149,12 +149,12 @@ void UartTransmitPacket(blt_int8u *data, blt_int8u len)
blt_bool result;
/* verify validity of the len-paramenter */
ASSERT_RT(len <= BOOT_COM_UART_TX_MAX_DATA);
ASSERT_RT(len <= BOOT_COM_UART_TX_MAX_DATA);
/* first transmit the length of the packet */
/* first transmit the length of the packet */
result = UartTransmitByte(len);
ASSERT_RT(result == BLT_TRUE);
ASSERT_RT(result == BLT_TRUE);
/* transmit all the packet bytes one-by-one */
for (data_index = 0; data_index < len; data_index++)
{
@ -162,7 +162,7 @@ void UartTransmitPacket(blt_int8u *data, blt_int8u len)
CopService();
/* write byte */
result = UartTransmitByte(data[data_index]);
ASSERT_RT(result == BLT_TRUE);
ASSERT_RT(result == BLT_TRUE);
}
} /*** end of UartTransmitPacket ***/
@ -209,7 +209,7 @@ blt_bool UartReceivePacket(blt_int8u *data)
if (xcpCtoRxLength == xcpCtoReqPacket[0])
{
/* copy the packet data */
CpuMemCopy((blt_int32u)data, (blt_int32u)&xcpCtoReqPacket[1], xcpCtoRxLength);
CpuMemCopy((blt_int32u)data, (blt_int32u)&xcpCtoReqPacket[1], xcpCtoRxLength);
/* done with cto packet reception */
xcpCtoRxInProgress = BLT_FALSE;
/* packet reception complete */
@ -242,7 +242,7 @@ blt_bool UartReceivePacket(blt_int8u *data)
static blt_bool UartReceiveByte(blt_int8u *data)
{
/* check if a new byte was received by means of the RDR-bit */
if((U0LSR & UART_RDR) != 0)
if ((U0LSR & UART_RDR) != 0)
{
/* store the received byte */
data[0] = U0RBR;
@ -271,8 +271,8 @@ static blt_bool UartTransmitByte(blt_int8u data)
/* write byte to transmit holding register */
U0THR = data;
/* wait for tx holding register to be empty */
while((U0LSR & UART_THRE) == 0)
{
while ((U0LSR & UART_THRE) == 0)
{
/* keep the watchdog happy */
CopService();
}

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -47,7 +47,7 @@ extern void reset_handler(void); /* implemented in cstart.s
* External data declarations
****************************************************************************************/
/** \brief Stack end address (memory.x) */
extern blt_int32u __stack_end__;
extern blt_int32u __stack_end__;
/************************************************************************************//**
@ -70,13 +70,13 @@ typedef union
{
void (*func)(void); /**< for ISR function pointers */
blt_int32u ptr; /**< for stack pointer entry */
}tIsrFunc;
} tIsrFunc;
/** \brief Interrupt vector table. */
__attribute__ ((section(".vectors")))
__attribute__((section(".vectors")))
const tIsrFunc _vectors[] =
{
{ .ptr = (blt_int32u)&__stack_end__ }, /* the initial stack pointer */
{ .ptr = (blt_int32u) &__stack_end__ }, /* the initial stack pointer */
reset_handler, /* the reset handler */
UnusedISR, /* NMI Handler */
UnusedISR, /* Hard Fault Handler */

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -57,7 +57,7 @@ extern blt_int32u _estack;
/************************************************************************************//**
** \brief Reset interrupt service routine. Configures the stack, initializes
** \brief Reset interrupt service routine. Configures the stack, initializes
** RAM and jumps to function main.
** \return none.
**
@ -70,11 +70,11 @@ void reset_handler(void)
__asm(" cpsid i");
/* copy the data segment initializers from flash to SRAM */
pSrc = &_etext;
for(pDest = &_data; pDest < &_edata; )
for (pDest = &_data; pDest < &_edata;)
{
*pDest++ = *pSrc++;
}
/* zero fill the bss segment. this is done with inline assembly since this will
/* zero fill the bss segment. this is done with inline assembly since this will
* clear the value of pDest if it is not kept in a register.
*/
__asm(" ldr r0, =_bss\n"

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -64,13 +64,13 @@ typedef union
{
void (*func)(void); /**< for ISR function pointers */
blt_int32u ptr; /**< for stack pointer entry */
}tIsrFunc;
} tIsrFunc;
/** \brief Interrupt vector table. */
__attribute__ ((section(".isr_vector")))
__attribute__((section(".isr_vector")))
const tIsrFunc _vectab[] =
{
{ .ptr = (blt_int32u)&_estack }, /* the initial stack pointer */
{ .ptr = (blt_int32u) &_estack }, /* the initial stack pointer */
{ reset_handler }, /* the reset handler */
{ UnusedISR }, /* NMI Handler */
{ UnusedISR }, /* Hard Fault Handler */

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -40,7 +40,7 @@
/****************************************************************************************
* External functions
****************************************************************************************/
extern void reset_handler( void );
extern void reset_handler(void);
/****************************************************************************************
@ -51,7 +51,7 @@ typedef union
{
void (*func)(void); /**< for ISR function pointers */
void *ptr; /**< for stack pointer entry */
}tIsrFunc;
} tIsrFunc;
/************************************************************************************//**
@ -75,7 +75,7 @@ void UnusedISR(void)
/** \brief Interrupt vector table. */
__root const tIsrFunc __vector_table[] @ ".intvec" =
{
{ .ptr = __sfe( "CSTACK" ) }, /* the initial stack pointer */
{ .ptr = __sfe("CSTACK") }, /* the initial stack pointer */
{ &reset_handler }, /* the reset handler */
{ UnusedISR }, /* NMI Handler */
{ UnusedISR }, /* Hard Fault Handler */

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -69,7 +69,7 @@ extern void reset_handler(void); /* implemented in cstart.s
/************************************************************************************//**
** \brief Starts the user program, if one is present. In this case this function
** does not return.
** does not return.
** \return none.
**
****************************************************************************************/
@ -83,18 +83,18 @@ void CpuStartUserProgram(void)
/* not a valid user program so it cannot be started */
return;
}
#if (BOOT_CPU_USER_PROGRAM_START_HOOK > 0)
#if (BOOT_CPU_USER_PROGRAM_START_HOOK > 0)
/* invoke callback */
if (CpuUserProgramStartHook() == BLT_FALSE)
{
/* callback requests the user program to not be started */
return;
}
#endif
#if (BOOT_COM_ENABLE > 0)
#endif
#if (BOOT_COM_ENABLE > 0)
/* release the communication interface */
ComFree();
#endif
#endif
/* reset the timer */
TimerReset();
/* remap user program's vector table */
@ -103,7 +103,7 @@ void CpuStartUserProgram(void)
* the 2nd entry in the user program's vector table. this address points to the
* user program's reset handler.
*/
pProgResetHandler = (void(*)(void))(*((blt_addr*)CPU_USER_PROGRAM_STARTADDR_PTR));
pProgResetHandler = (void(*)(void))(*((blt_addr *)CPU_USER_PROGRAM_STARTADDR_PTR));
/* start the user program by activating its reset interrupt service routine */
pProgResetHandler();
} /*** end of CpuStartUserProgram ***/
@ -113,7 +113,7 @@ void CpuStartUserProgram(void)
** \brief Copies data from the source to the destination address.
** \param dest Destination address for the data.
** \param src Source address of the data.
** \param len length of the data in bytes.
** \param len length of the data in bytes.
** \return none.
**
****************************************************************************************/
@ -126,7 +126,7 @@ void CpuMemCopy(blt_addr dest, blt_addr src, blt_int16u len)
to = (blt_int8u *)dest;
/* copy all bytes from source address to destination address */
while(len-- > 0)
while (len-- > 0)
{
/* store byte value from source to destination */
*to++ = *from++;

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -57,7 +57,7 @@
* Type definitions
****************************************************************************************/
/** \brief Flash sector descriptor type. */
typedef struct
typedef struct
{
blt_addr sector_start; /**< sector start address */
blt_int32u sector_size; /**< sector size in bytes */
@ -65,10 +65,10 @@ typedef struct
} tFlashSector;
/** \brief Structure type for grouping flash block information.
* \details Programming is done per block of max FLASH_WRITE_BLOCK_SIZE. for this a
* \details Programming is done per block of max FLASH_WRITE_BLOCK_SIZE. for this a
* flash block manager is implemented in this driver. this flash block manager
* depends on this flash block info structure. It holds the base address of
* the flash block and the data that should be programmed into the flash
* depends on this flash block info structure. It holds the base address of
* the flash block and the data that should be programmed into the flash
* block. The .base_addr must be a multiple of FLASH_WRITE_BLOCK_SIZE.
*/
typedef struct
@ -83,7 +83,7 @@ typedef struct
****************************************************************************************/
static blt_bool FlashInitBlock(tFlashBlockInfo *block, blt_addr address);
static tFlashBlockInfo *FlashSwitchBlock(tFlashBlockInfo *block, blt_addr base_addr);
static blt_bool FlashAddToBlock(tFlashBlockInfo *block, blt_addr address,
static blt_bool FlashAddToBlock(tFlashBlockInfo *block, blt_addr address,
blt_int8u *data, blt_int32u len);
static blt_bool FlashWriteBlock(tFlashBlockInfo *block);
static blt_bool FlashEraseSectors(blt_int8u first_sector, blt_int8u last_sector);
@ -97,13 +97,13 @@ static blt_int32u FlashCalcPageSize(void);
* Local constant declarations
****************************************************************************************/
/** \brief Array wit the layout of the flash memory.
* \details Also controls what part of the flash memory is reserved for the bootloader.
* If the bootloader size changes, the reserved sectors for the bootloader
* \details Also controls what part of the flash memory is reserved for the bootloader.
* If the bootloader size changes, the reserved sectors for the bootloader
* might need adjustment to make sure the bootloader doesn't get overwritten.
* The current flash layout does not reflect the minimum sector size of the
* physical flash (1 - 2kb), because this would make the table quit long and
* a waste of ROM. The minimum sector size is only really needed when erasing
* the flash. This can still be done in combination with macro
* the flash. This can still be done in combination with macro
* FLASH_ERASE_BLOCK_SIZE.
*/
static const tFlashSector flashLayout[] =
@ -159,30 +159,30 @@ static const tFlashSector flashLayout[] =
****************************************************************************************/
/** \brief Local variable with information about the flash block that is currently
* being operated on.
* \details The smallest amount of flash that can be programmed is
* \details The smallest amount of flash that can be programmed is
* FLASH_WRITE_BLOCK_SIZE. A flash block manager is implemented in this driver
* and stores info in this variable. Whenever new data should be flashed, it
* is first added to a RAM buffer, which is part of this variable. Whenever
* the RAM buffer, which has the size of a flash block, is full or data needs
* to be written to a different block, the contents of the RAM buffer are
* programmed to flash. The flash block manager requires some software
* overhead, yet results is faster flash programming because data is first
* harvested, ideally until there is enough to program an entire flash block,
* to be written to a different block, the contents of the RAM buffer are
* programmed to flash. The flash block manager requires some software
* overhead, yet results is faster flash programming because data is first
* harvested, ideally until there is enough to program an entire flash block,
* before the flash device is actually operated on.
*/
static tFlashBlockInfo blockInfo;
/** \brief Local variable with information about the flash boot block.
* \details The first block of the user program holds the vector table, which on the
* STM32 is also the where the checksum is written to. Is it likely that
* \details The first block of the user program holds the vector table, which on the
* STM32 is also the where the checksum is written to. Is it likely that
* the vector table is first flashed and then, at the end of the programming
* sequence, the checksum. This means that this flash block need to be written
* to twice. Normally this is not a problem with flash memory, as long as you
* write the same values to those bytes that are not supposed to be changed
* write the same values to those bytes that are not supposed to be changed
* and the locations where you do write to are still in the erased 0xFF state.
* Unfortunately, writing twice to flash this way, does not work reliably on
* Unfortunately, writing twice to flash this way, does not work reliably on
* all micros. This is why we need to have an extra block, the bootblock,
* placed under the management of the block manager. This way is it possible
* placed under the management of the block manager. This way is it possible
* to implement functionality so that the bootblock is only written to once
* at the end of the programming sequence.
*/
@ -190,7 +190,7 @@ static tFlashBlockInfo bootBlockInfo;
/************************************************************************************//**
** \brief Initializes the flash driver.
** \brief Initializes the flash driver.
** \return none.
**
****************************************************************************************/
@ -206,12 +206,12 @@ void FlashInit(void)
/************************************************************************************//**
** \brief Writes the data to flash through a flash block manager. Note that this
** function also checks that no data is programmed outside the flash
** function also checks that no data is programmed outside the flash
** memory region, so the bootloader can never be overwritten.
** \param addr Start address.
** \param len Length in bytes.
** \param data Pointer to the data buffer.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
blt_bool FlashWrite(blt_addr addr, blt_int32u len, blt_int8u *data)
@ -219,10 +219,10 @@ blt_bool FlashWrite(blt_addr addr, blt_int32u len, blt_int8u *data)
blt_addr base_addr;
/* make sure the addresses are within the flash device */
if ( (FlashGetSector(addr) == FLASH_INVALID_SECTOR) || \
(FlashGetSector(addr+len-1) == FLASH_INVALID_SECTOR) )
if ((FlashGetSector(addr) == FLASH_INVALID_SECTOR) || \
(FlashGetSector(addr+len-1) == FLASH_INVALID_SECTOR))
{
return BLT_FALSE;
return BLT_FALSE;
}
/* if this is the bootblock, then let the boot block manager handle it */
@ -238,24 +238,24 @@ blt_bool FlashWrite(blt_addr addr, blt_int32u len, blt_int8u *data)
/************************************************************************************//**
** \brief Erases the flash memory. Note that this function also checks that no
** data is erased outside the flash memory region, so the bootloader can
** \brief Erases the flash memory. Note that this function also checks that no
** data is erased outside the flash memory region, so the bootloader can
** never be erased.
** \param addr Start address.
** \param len Length in bytes.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
blt_bool FlashErase(blt_addr addr, blt_int32u len)
{
blt_int8u first_sector;
blt_int8u last_sector;
/* obtain the first and last sector number */
first_sector = FlashGetSector(addr);
last_sector = FlashGetSector(addr+len-1);
/* check them */
if ( (first_sector == FLASH_INVALID_SECTOR) || (last_sector == FLASH_INVALID_SECTOR) )
if ((first_sector == FLASH_INVALID_SECTOR) || (last_sector == FLASH_INVALID_SECTOR))
{
return BLT_FALSE;
}
@ -270,27 +270,27 @@ blt_bool FlashErase(blt_addr addr, blt_int32u len)
** the checksum, the bootloader can check if the programming session
** was completed, which indicates that a valid user programming is
** present and can be started.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
blt_bool FlashWriteChecksum(void)
{
blt_int32u signature_checksum = 0;
/* for the EFM32 target we defined the checksum as the Two's complement value of the
* sum of the first 7 exception addresses.
*
* Layout of the vector table:
* 0x00000000 Initial stack pointer
* 0x00000000 Initial stack pointer
* 0x00000004 Reset Handler
* 0x00000008 NMI Handler
* 0x0000000C Hard Fault Handler
* 0x00000010 MPU Fault Handler
* 0x00000010 MPU Fault Handler
* 0x00000014 Bus Fault Handler
* 0x00000018 Usage Fault Handler
*
* signature_checksum = Two's complement of (SUM(exception address values))
*
*
* the bootloader writes this 32-bit checksum value right after the vector table
* of the user program. note that this means one extra dummy entry must be added
* at the end of the user program's vector table to reserve storage space for the
@ -301,49 +301,49 @@ blt_bool FlashWriteChecksum(void)
* bootblock is not part of the reprogramming this time and therefore no
* new checksum needs to be written
*/
if (bootBlockInfo.base_addr == FLASH_INVALID_ADDRESS)
{
if (bootBlockInfo.base_addr == FLASH_INVALID_ADDRESS)
{
return BLT_TRUE;
}
}
/* compute the checksum. note that the user program's vectors are not yet written
* to flash but are present in the bootblock data structure at this point.
*/
signature_checksum += *((blt_int32u*)(&bootBlockInfo.data[0+0x00]));
signature_checksum += *((blt_int32u*)(&bootBlockInfo.data[0+0x04]));
signature_checksum += *((blt_int32u*)(&bootBlockInfo.data[0+0x08]));
signature_checksum += *((blt_int32u*)(&bootBlockInfo.data[0+0x0C]));
signature_checksum += *((blt_int32u*)(&bootBlockInfo.data[0+0x10]));
signature_checksum += *((blt_int32u*)(&bootBlockInfo.data[0+0x14]));
signature_checksum += *((blt_int32u*)(&bootBlockInfo.data[0+0x18]));
signature_checksum += *((blt_int32u *)(&bootBlockInfo.data[0+0x00]));
signature_checksum += *((blt_int32u *)(&bootBlockInfo.data[0+0x04]));
signature_checksum += *((blt_int32u *)(&bootBlockInfo.data[0+0x08]));
signature_checksum += *((blt_int32u *)(&bootBlockInfo.data[0+0x0C]));
signature_checksum += *((blt_int32u *)(&bootBlockInfo.data[0+0x10]));
signature_checksum += *((blt_int32u *)(&bootBlockInfo.data[0+0x14]));
signature_checksum += *((blt_int32u *)(&bootBlockInfo.data[0+0x18]));
signature_checksum = ~signature_checksum; /* one's complement */
signature_checksum += 1; /* two's complement */
/* write the checksum */
return FlashWrite(flashLayout[0].sector_start+FLASH_VECTOR_TABLE_CS_OFFSET,
sizeof(blt_addr), (blt_int8u*)&signature_checksum);
return FlashWrite(flashLayout[0].sector_start+FLASH_VECTOR_TABLE_CS_OFFSET,
sizeof(blt_addr), (blt_int8u *)&signature_checksum);
} /*** end of FlashWriteChecksum ***/
/************************************************************************************//**
** \brief Verifies the checksum, which indicates that a valid user program is
** present and can be started.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
blt_bool FlashVerifyChecksum(void)
{
blt_int32u signature_checksum = 0;
/* verify the checksum based on how it was written by CpuWriteChecksum() */
signature_checksum += *((blt_int32u*)(flashLayout[0].sector_start));
signature_checksum += *((blt_int32u*)(flashLayout[0].sector_start+0x04));
signature_checksum += *((blt_int32u*)(flashLayout[0].sector_start+0x08));
signature_checksum += *((blt_int32u*)(flashLayout[0].sector_start+0x0C));
signature_checksum += *((blt_int32u*)(flashLayout[0].sector_start+0x10));
signature_checksum += *((blt_int32u*)(flashLayout[0].sector_start+0x14));
signature_checksum += *((blt_int32u*)(flashLayout[0].sector_start+0x18));
signature_checksum += *((blt_int32u*)(flashLayout[0].sector_start+FLASH_VECTOR_TABLE_CS_OFFSET));
signature_checksum += *((blt_int32u *)(flashLayout[0].sector_start));
signature_checksum += *((blt_int32u *)(flashLayout[0].sector_start+0x04));
signature_checksum += *((blt_int32u *)(flashLayout[0].sector_start+0x08));
signature_checksum += *((blt_int32u *)(flashLayout[0].sector_start+0x0C));
signature_checksum += *((blt_int32u *)(flashLayout[0].sector_start+0x10));
signature_checksum += *((blt_int32u *)(flashLayout[0].sector_start+0x14));
signature_checksum += *((blt_int32u *)(flashLayout[0].sector_start+0x18));
signature_checksum += *((blt_int32u *)(flashLayout[0].sector_start+FLASH_VECTOR_TABLE_CS_OFFSET));
/* sum should add up to an unsigned 32-bit value of 0 */
if (signature_checksum == 0)
{
@ -358,7 +358,7 @@ blt_bool FlashVerifyChecksum(void)
/************************************************************************************//**
** \brief Finalizes the flash driver operations. There could still be data in
** the currently active block that needs to be flashed.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
blt_bool FlashDone(void)
@ -371,7 +371,7 @@ blt_bool FlashDone(void)
return BLT_FALSE;
}
}
/* check if there is still data waiting to be programmed */
if (blockInfo.base_addr != FLASH_INVALID_ADDRESS)
{
@ -382,7 +382,7 @@ blt_bool FlashDone(void)
}
/* disable the flash controller for writing */
MSC_Deinit();
/* still here so all is okay */
/* still here so all is okay */
return BLT_TRUE;
} /*** end of FlashDone ***/
@ -400,16 +400,16 @@ blt_addr FlashGetUserProgBaseAddress(void)
/************************************************************************************//**
** \brief Copies data currently in flash to the block->data and sets the
** \brief Copies data currently in flash to the block->data and sets the
** base address.
** \param block Pointer to flash block info structure to operate on.
** \param address Base address of the block data.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
static blt_bool FlashInitBlock(tFlashBlockInfo *block, blt_addr address)
{
/* check address alignment */
/* check address alignment */
if ((address % FLASH_WRITE_BLOCK_SIZE) != 0)
{
return BLT_FALSE;
@ -420,8 +420,8 @@ static blt_bool FlashInitBlock(tFlashBlockInfo *block, blt_addr address)
/* block already initialized, so nothing to do */
return BLT_TRUE;
}
/* set the base address and copies the current data from flash */
block->base_addr = address;
/* set the base address and copies the current data from flash */
block->base_addr = address;
CpuMemCopy((blt_addr)block->data, address, FLASH_WRITE_BLOCK_SIZE);
return BLT_TRUE;
} /*** end of FlashInitBlock ***/
@ -440,14 +440,14 @@ static tFlashBlockInfo *FlashSwitchBlock(tFlashBlockInfo *block, blt_addr base_a
{
/* check if a switch needs to be made away from the boot block. in this case the boot
* block shouldn't be written yet, because this is done at the end of the programming
* session by FlashDone(), this is right after the checksum was written.
* session by FlashDone(), this is right after the checksum was written.
*/
if (block == &bootBlockInfo)
{
/* switch from the boot block to the generic block info structure */
block = &blockInfo;
}
/* check if a switch back into the bootblock is needed. in this case the generic block
/* check if a switch back into the bootblock is needed. in this case the generic block
* doesn't need to be written here yet.
*/
else if (base_addr == flashLayout[0].sector_start)
@ -466,7 +466,7 @@ static tFlashBlockInfo *FlashSwitchBlock(tFlashBlockInfo *block, blt_addr base_a
}
/* initialize tne new block when necessary */
if (FlashInitBlock(block, base_addr) == BLT_FALSE)
if (FlashInitBlock(block, base_addr) == BLT_FALSE)
{
return BLT_NULL;
}
@ -488,13 +488,13 @@ static tFlashBlockInfo *FlashSwitchBlock(tFlashBlockInfo *block, blt_addr base_a
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
static blt_bool FlashAddToBlock(tFlashBlockInfo *block, blt_addr address,
static blt_bool FlashAddToBlock(tFlashBlockInfo *block, blt_addr address,
blt_int8u *data, blt_int32u len)
{
blt_addr current_base_addr;
blt_int8u *dst;
blt_int8u *src;
/* determine the current base address */
current_base_addr = (address/FLASH_WRITE_BLOCK_SIZE)*FLASH_WRITE_BLOCK_SIZE;
@ -518,7 +518,7 @@ static blt_bool FlashAddToBlock(tFlashBlockInfo *block, blt_addr address,
return BLT_FALSE;
}
}
/* add the data to the current block, but check for block overflow */
dst = &(block->data[address - block->base_addr]);
src = data;
@ -579,7 +579,7 @@ static blt_bool FlashWriteBlock(tFlashBlockInfo *block)
for (word_cnt=0; word_cnt<(FLASH_WRITE_BLOCK_SIZE/sizeof(blt_int32u)); word_cnt++)
{
prog_addr = block->base_addr + (word_cnt * sizeof(blt_int32u));
prog_data = *(volatile blt_int32u*)(&block->data[word_cnt * sizeof(blt_int32u)]);
prog_data = *(volatile blt_int32u *)(&block->data[word_cnt * sizeof(blt_int32u)]);
/* keep the watchdog happy */
CopService();
/* program a word */
@ -589,7 +589,7 @@ static blt_bool FlashWriteBlock(tFlashBlockInfo *block)
break;
}
/* verify that the written data is actually there */
if (*(volatile blt_int32u*)prog_addr != prog_data)
if (*(volatile blt_int32u *)prog_addr != prog_data)
{
result = BLT_FALSE;
break;
@ -608,14 +608,14 @@ static blt_bool FlashWriteBlock(tFlashBlockInfo *block)
****************************************************************************************/
static blt_int32u FlashCalcPageSize(void)
{
blt_int8u family = *(blt_int8u*)0x0FE081FE;
blt_int8u family = *(blt_int8u *)0x0FE081FE;
if ( ( family == 71 ) || ( family == 73 ) )
if ((family == 71) || (family == 73))
{
/* Gecko and Tiny, 'G' or 'I' */
return 512;
return 512;
}
else if ( family == 72 )
else if (family == 72)
{
/* Giant, 'H' */
return 4096;
@ -648,8 +648,8 @@ static blt_bool FlashEraseSectors(blt_int8u first_sector, blt_int8u last_sector)
{
return BLT_FALSE;
}
if ( (first_sector < flashLayout[0].sector_num) || \
(last_sector > flashLayout[FLASH_TOTAL_SECTORS-1].sector_num) )
if ((first_sector < flashLayout[0].sector_num) || \
(last_sector > flashLayout[FLASH_TOTAL_SECTORS-1].sector_num))
{
return BLT_FALSE;
}
@ -659,7 +659,7 @@ static blt_bool FlashEraseSectors(blt_int8u first_sector, blt_int8u last_sector)
start_addr = FlashGetSectorBaseAddr(first_sector);
end_addr = FlashGetSectorBaseAddr(last_sector) + FlashGetSectorSize(last_sector) - 1;
nr_of_blocks = (end_addr - start_addr + 1) / erase_block_size;
/* erase all blocks one by one */
for (block_cnt=0; block_cnt<nr_of_blocks; block_cnt++)
{
@ -686,16 +686,16 @@ static blt_bool FlashEraseSectors(blt_int8u first_sector, blt_int8u last_sector)
static blt_int8u FlashGetSector(blt_addr address)
{
blt_int8u sectorIdx;
/* search through the sectors to find the right one */
for (sectorIdx = 0; sectorIdx < FLASH_TOTAL_SECTORS; sectorIdx++)
{
/* keep the watchdog happy */
CopService();
/* is the address in this sector? */
if ( (address >= flashLayout[sectorIdx].sector_start) && \
(address < (flashLayout[sectorIdx].sector_start + \
flashLayout[sectorIdx].sector_size)) )
if ((address >= flashLayout[sectorIdx].sector_start) && \
(address < (flashLayout[sectorIdx].sector_start + \
flashLayout[sectorIdx].sector_size)))
{
/* return the sector number */
return flashLayout[sectorIdx].sector_num;
@ -715,7 +715,7 @@ static blt_int8u FlashGetSector(blt_addr address)
static blt_addr FlashGetSectorBaseAddr(blt_int8u sector)
{
blt_int8u sectorIdx;
/* search through the sectors to find the right one */
for (sectorIdx = 0; sectorIdx < FLASH_TOTAL_SECTORS; sectorIdx++)
{
@ -740,7 +740,7 @@ static blt_addr FlashGetSectorBaseAddr(blt_int8u sector)
static blt_addr FlashGetSectorSize(blt_int8u sector)
{
blt_int8u sectorIdx;
/* search through the sectors to find the right one */
for (sectorIdx = 0; sectorIdx < FLASH_TOTAL_SECTORS; sectorIdx++)
{

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
#ifndef FLASH_H

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -93,12 +93,12 @@ blt_bool NvmWrite(blt_addr addr, blt_int32u len, blt_int8u *data)
* by this driver.
*/
result = NvmWriteHook(addr, len, data);
/* process the return code */
if (result == BLT_NVM_OKAY)
{
/* data was within range of the additionally supported memory and succesfully
* programmed, so we are all done.
* programmed, so we are all done.
*/
return BLT_TRUE;
}
@ -134,12 +134,12 @@ blt_bool NvmErase(blt_addr addr, blt_int32u len)
* by this driver.
*/
result = NvmEraseHook(addr, len);
/* process the return code */
if (result == BLT_NVM_OKAY)
{
/* address was within range of the additionally supported memory and succesfully
* erased, so we are all done.
* erased, so we are all done.
*/
return BLT_TRUE;
}
@ -176,7 +176,7 @@ blt_bool NvmVerifyChecksum(void)
/************************************************************************************//**
** \brief Obtains the base address of the non-volatile memory available to the user
** \brief Obtains the base address of the non-volatile memory available to the user
** program. This is typically that start of the vector table.
** \return Base address.
**
@ -188,11 +188,11 @@ blt_addr NvmGetUserProgBaseAddress(void)
/************************************************************************************//**
** \brief Once all erase and programming operations are completed, this
** function is called, so at the end of the programming session and
** \brief Once all erase and programming operations are completed, this
** function is called, so at the end of the programming session and
** right before a software reset is performed. It is used to calculate
** a checksum and program this into flash. This checksum is later used
** to determine if a valid user program is present in flash.
** to determine if a valid user program is present in flash.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
#ifndef TYPES_H

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -110,12 +110,12 @@ void UartTransmitPacket(blt_int8u *data, blt_int8u len)
blt_bool result;
/* verify validity of the len-paramenter */
ASSERT_RT(len <= BOOT_COM_UART_TX_MAX_DATA);
ASSERT_RT(len <= BOOT_COM_UART_TX_MAX_DATA);
/* first transmit the length of the packet */
/* first transmit the length of the packet */
result = UartTransmitByte(len);
ASSERT_RT(result == BLT_TRUE);
ASSERT_RT(result == BLT_TRUE);
/* transmit all the packet bytes one-by-one */
for (data_index = 0; data_index < len; data_index++)
{
@ -123,7 +123,7 @@ void UartTransmitPacket(blt_int8u *data, blt_int8u len)
CopService();
/* write byte */
result = UartTransmitByte(data[data_index]);
ASSERT_RT(result == BLT_TRUE);
ASSERT_RT(result == BLT_TRUE);
}
} /*** end of UartTransmitPacket ***/
@ -170,7 +170,7 @@ blt_bool UartReceivePacket(blt_int8u *data)
if (xcpCtoRxLength == xcpCtoReqPacket[0])
{
/* copy the packet data */
CpuMemCopy((blt_int32u)data, (blt_int32u)&xcpCtoReqPacket[1], xcpCtoRxLength);
CpuMemCopy((blt_int32u)data, (blt_int32u)&xcpCtoReqPacket[1], xcpCtoRxLength);
/* done with cto packet reception */
xcpCtoRxInProgress = BLT_FALSE;
/* packet reception complete */
@ -233,8 +233,8 @@ static blt_bool UartTransmitByte(blt_int8u data)
/* write byte to transmit holding register */
LEUART_Tx(LEUART1, data);
/* wait for tx holding register to be empty */
while((LEUART1->STATUS & LEUART_STATUS_TXBL) == 0)
{
while ((LEUART1->STATUS & LEUART_STATUS_TXBL) == 0)
{
/* keep the watchdog happy */
CopService();
}

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -47,7 +47,7 @@ extern void reset_handler(void); /* implemented in cstart.s
* External data declarations
****************************************************************************************/
/** \brief Stack end address (memory.x) */
extern blt_int32u __stack_end__;
extern blt_int32u __stack_end__;
/************************************************************************************//**
@ -70,13 +70,13 @@ typedef union
{
void (*func)(void); /**< for ISR function pointers */
blt_int32u ptr; /**< for stack pointer entry */
}tIsrFunc;
} tIsrFunc;
/** \brief Interrupt vector table. */
__attribute__ ((section(".vectors")))
__attribute__((section(".vectors")))
const tIsrFunc _vectors[] =
{
{ .ptr = (blt_int32u)&__stack_end__ }, /* the initial stack pointer */
{ .ptr = (blt_int32u) &__stack_end__ }, /* the initial stack pointer */
reset_handler, /* the reset handler */
UnusedISR, /* NMI Handler */
UnusedISR, /* Hard Fault Handler */

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -56,7 +56,7 @@ extern blt_int32u _estack;
/************************************************************************************//**
** \brief Reset interrupt service routine. Configures the stack, initializes
** \brief Reset interrupt service routine. Configures the stack, initializes
** RAM and jumps to function main.
** \return none.
**
@ -69,11 +69,11 @@ void reset_handler(void)
__asm(" cpsid i");
/* copy the data segment initializers from flash to SRAM */
pSrc = &_etext;
for(pDest = &_data; pDest < &_edata; )
for (pDest = &_data; pDest < &_edata;)
{
*pDest++ = *pSrc++;
}
/* zero fill the bss segment. this is done with inline assembly since this will
/* zero fill the bss segment. this is done with inline assembly since this will
* clear the value of pDest if it is not kept in a register.
*/
__asm(" ldr r0, =_bss\n"

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -64,13 +64,13 @@ typedef union
{
void (*func)(void); /**< for ISR function pointers */
blt_int32u ptr; /**< for stack pointer entry */
}tIsrFunc;
} tIsrFunc;
/** \brief Interrupt vector table. */
__attribute__ ((section(".isr_vector")))
__attribute__((section(".isr_vector")))
const tIsrFunc _vectab[] =
{
{ .ptr = (blt_int32u)&_estack }, /* the initial stack pointer */
{ .ptr = (blt_int32u) &_estack }, /* the initial stack pointer */
{ reset_handler }, /* the reset handler */
{ UnusedISR }, /* NMI Handler */
{ UnusedISR }, /* Hard Fault Handler */

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -40,7 +40,7 @@
/****************************************************************************************
* External functions
****************************************************************************************/
extern void reset_handler( void );
extern void reset_handler(void);
/****************************************************************************************
@ -51,7 +51,7 @@ typedef union
{
void (*func)(void); /**< for ISR function pointers */
void *ptr; /**< for stack pointer entry */
}tIsrFunc;
} tIsrFunc;
/************************************************************************************//**
@ -75,7 +75,7 @@ void UnusedISR(void)
/** \brief Interrupt vector table. */
__root const tIsrFunc __vector_table[] @ ".intvec" =
{
{ .ptr = __sfe( "CSTACK" ) }, /* the initial stack pointer */
{ .ptr = __sfe("CSTACK") }, /* the initial stack pointer */
{ &reset_handler }, /* the reset handler */
{ UnusedISR }, /* NMI Handler */
{ UnusedISR }, /* Hard Fault Handler */

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -66,8 +66,8 @@ static const blt_int16u canBitNum2Mask[] =
/************************************************************************************//**
** \brief Attempts to match the bittiming parameters to the requested baudrate
** for a sample point between 65 and 75%, through a linear search
** \brief Attempts to match the bittiming parameters to the requested baudrate
** for a sample point between 65 and 75%, through a linear search
** algorithm. It is based on the equation:
** baudrate = CAN Clock Freq/((1+PropSeg+Phase1Seg+Phase2Seg)*Prescaler)
** \return BLT_TRUE if a valid bittiming configuration was found and set. BLT_FALSE
@ -91,7 +91,7 @@ static blt_int8u CanSetBittiming(void)
{
samplepoint = ((1+bitClkParms.uSyncPropPhase1Seg) * 100) / (1+bitClkParms.uSyncPropPhase1Seg+bitClkParms.uPhase2Seg);
/* check that sample points is within the preferred range */
if ( (samplepoint >= 65) && (samplepoint <= 75) )
if ((samplepoint >= 65) && (samplepoint <= 75))
{
/* does a prescaler exist to get the exact baudrate with these bittiming
* settings?
@ -104,7 +104,7 @@ static blt_int8u CanSetBittiming(void)
*/
if (bitClkParms.uPhase2Seg < 4)
{
bitClkParms.uSJW = bitClkParms.uPhase2Seg;
bitClkParms.uSJW = bitClkParms.uPhase2Seg;
}
/* calculate the actual prescaler value */
bitClkParms.uQuantumPrescaler = ((BOOT_CPU_XTAL_SPEED_KHZ*1000)/BOOT_COM_CAN_BAUDRATE)/(1+bitClkParms.uSyncPropPhase1Seg+bitClkParms.uPhase2Seg);
@ -131,10 +131,10 @@ void CanInit(void)
blt_bool result;
tCANMsgObject rxMsgObject;
/* the current implementation supports CAN0. throw an assertion error in case a
* different CAN channel is configured.
/* the current implementation supports CAN0. throw an assertion error in case a
* different CAN channel is configured.
*/
ASSERT_CT(BOOT_COM_CAN_CHANNEL_INDEX == 0);
ASSERT_CT(BOOT_COM_CAN_CHANNEL_INDEX == 0);
/* enable the CAN controller */
SysCtlPeripheralEnable(SYSCTL_PERIPH_CAN0);
/* reset the state of the CAN controller, including the message objects */

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -45,7 +45,7 @@
/** \brief Pointer to the user program's vector table. */
#define CPU_USER_PROGRAM_VECTABLE_OFFSET ((blt_int32u)NvmGetUserProgBaseAddress())
/****************************************************************************************
* Register definitions
****************************************************************************************/
@ -69,7 +69,7 @@ extern void reset_handler(void); /* implemented in cstart.s
/************************************************************************************//**
** \brief Starts the user program, if one is present. In this case this function
** does not return.
** does not return.
** \return none.
**
****************************************************************************************/
@ -83,18 +83,18 @@ void CpuStartUserProgram(void)
/* not a valid user program so it cannot be started */
return;
}
#if (BOOT_CPU_USER_PROGRAM_START_HOOK > 0)
#if (BOOT_CPU_USER_PROGRAM_START_HOOK > 0)
/* invoke callback */
if (CpuUserProgramStartHook() == BLT_FALSE)
{
/* callback requests the user program to not be started */
return;
}
#endif
#if (BOOT_COM_ENABLE > 0)
#endif
#if (BOOT_COM_ENABLE > 0)
/* release the communication interface */
ComFree();
#endif
#endif
/* reset the timer */
TimerReset();
/* remap user program's vector table */
@ -103,7 +103,7 @@ void CpuStartUserProgram(void)
* the 2nd entry in the user program's vector table. this address points to the
* user program's reset handler.
*/
pProgResetHandler = (void(*)(void))(*((blt_addr*)CPU_USER_PROGRAM_STARTADDR_PTR));
pProgResetHandler = (void(*)(void))(*((blt_addr *)CPU_USER_PROGRAM_STARTADDR_PTR));
/* start the user program by activating its reset interrupt service routine */
pProgResetHandler();
} /*** end of CpuStartUserProgram ***/
@ -113,7 +113,7 @@ void CpuStartUserProgram(void)
** \brief Copies data from the source to the destination address.
** \param dest Destination address for the data.
** \param src Source address of the data.
** \param len length of the data in bytes.
** \param len length of the data in bytes.
** \return none.
**
****************************************************************************************/
@ -126,7 +126,7 @@ void CpuMemCopy(blt_addr dest, blt_addr src, blt_int16u len)
to = (blt_int8u *)dest;
/* copy all bytes from source address to destination address */
while(len-- > 0)
while (len-- > 0)
{
/* store byte value from source to destination */
*to++ = *from++;

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -61,7 +61,7 @@
* Type definitions
****************************************************************************************/
/** \brief Flash sector descriptor type. */
typedef struct
typedef struct
{
blt_addr sector_start; /**< sector start address */
blt_int32u sector_size; /**< sector size in bytes */
@ -69,10 +69,10 @@ typedef struct
} tFlashSector;
/** \brief Structure type for grouping flash block information.
* \details Programming is done per block of max FLASH_WRITE_BLOCK_SIZE. for this a
* \details Programming is done per block of max FLASH_WRITE_BLOCK_SIZE. for this a
* flash block manager is implemented in this driver. this flash block manager
* depends on this flash block info structure. It holds the base address of
* the flash block and the data that should be programmed into the flash
* depends on this flash block info structure. It holds the base address of
* the flash block and the data that should be programmed into the flash
* block. The .base_addr must be a multiple of FLASH_WRITE_BLOCK_SIZE.
*/
typedef struct
@ -87,7 +87,7 @@ typedef struct
****************************************************************************************/
static blt_bool FlashInitBlock(tFlashBlockInfo *block, blt_addr address);
static tFlashBlockInfo *FlashSwitchBlock(tFlashBlockInfo *block, blt_addr base_addr);
static blt_bool FlashAddToBlock(tFlashBlockInfo *block, blt_addr address,
static blt_bool FlashAddToBlock(tFlashBlockInfo *block, blt_addr address,
blt_int8u *data, blt_int32u len);
static blt_bool FlashWriteBlock(tFlashBlockInfo *block);
static blt_bool FlashEraseSectors(blt_int8u first_sector, blt_int8u last_sector);
@ -100,13 +100,13 @@ static blt_addr FlashGetSectorSize(blt_int8u sector);
* Local constant declarations
****************************************************************************************/
/** \brief Array wit the layout of the flash memory.
* \details Also controls what part of the flash memory is reserved for the bootloader.
* If the bootloader size changes, the reserved sectors for the bootloader
* \details Also controls what part of the flash memory is reserved for the bootloader.
* If the bootloader size changes, the reserved sectors for the bootloader
* might need adjustment to make sure the bootloader doesn't get overwritten.
* The current flash layout does not reflect the minimum sector size of the
* physical flash (1 - 2kb), because this would make the table quit long and
* a waste of ROM. The minimum sector size is only really needed when erasing
* the flash. This can still be done in combination with macro
* the flash. This can still be done in combination with macro
* FLASH_ERASE_BLOCK_SIZE.
*/
static const tFlashSector flashLayout[] =
@ -162,30 +162,30 @@ static const tFlashSector flashLayout[] =
****************************************************************************************/
/** \brief Local variable with information about the flash block that is currently
* being operated on.
* \details The smallest amount of flash that can be programmed is
* \details The smallest amount of flash that can be programmed is
* FLASH_WRITE_BLOCK_SIZE. A flash block manager is implemented in this driver
* and stores info in this variable. Whenever new data should be flashed, it
* is first added to a RAM buffer, which is part of this variable. Whenever
* the RAM buffer, which has the size of a flash block, is full or data needs
* to be written to a different block, the contents of the RAM buffer are
* programmed to flash. The flash block manager requires some software
* overhead, yet results is faster flash programming because data is first
* harvested, ideally until there is enough to program an entire flash block,
* to be written to a different block, the contents of the RAM buffer are
* programmed to flash. The flash block manager requires some software
* overhead, yet results is faster flash programming because data is first
* harvested, ideally until there is enough to program an entire flash block,
* before the flash device is actually operated on.
*/
static tFlashBlockInfo blockInfo;
/** \brief Local variable with information about the flash boot block.
* \details The first block of the user program holds the vector table, which on the
* STM32 is also the where the checksum is written to. Is it likely that
* \details The first block of the user program holds the vector table, which on the
* STM32 is also the where the checksum is written to. Is it likely that
* the vector table is first flashed and then, at the end of the programming
* sequence, the checksum. This means that this flash block need to be written
* to twice. Normally this is not a problem with flash memory, as long as you
* write the same values to those bytes that are not supposed to be changed
* write the same values to those bytes that are not supposed to be changed
* and the locations where you do write to are still in the erased 0xFF state.
* Unfortunately, writing twice to flash this way, does not work reliably on
* Unfortunately, writing twice to flash this way, does not work reliably on
* all micros. This is why we need to have an extra block, the bootblock,
* placed under the management of the block manager. This way is it possible
* placed under the management of the block manager. This way is it possible
* to implement functionality so that the bootblock is only written to once
* at the end of the programming sequence.
*/
@ -193,7 +193,7 @@ static tFlashBlockInfo bootBlockInfo;
/************************************************************************************//**
** \brief Initializes the flash driver.
** \brief Initializes the flash driver.
** \return none.
**
****************************************************************************************/
@ -207,12 +207,12 @@ void FlashInit(void)
/************************************************************************************//**
** \brief Writes the data to flash through a flash block manager. Note that this
** function also checks that no data is programmed outside the flash
** function also checks that no data is programmed outside the flash
** memory region, so the bootloader can never be overwritten.
** \param addr Start address.
** \param len Length in bytes.
** \param data Pointer to the data buffer.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
blt_bool FlashWrite(blt_addr addr, blt_int32u len, blt_int8u *data)
@ -220,10 +220,10 @@ blt_bool FlashWrite(blt_addr addr, blt_int32u len, blt_int8u *data)
blt_addr base_addr;
/* make sure the addresses are within the flash device */
if ( (FlashGetSector(addr) == FLASH_INVALID_SECTOR) || \
(FlashGetSector(addr+len-1) == FLASH_INVALID_SECTOR) )
if ((FlashGetSector(addr) == FLASH_INVALID_SECTOR) || \
(FlashGetSector(addr+len-1) == FLASH_INVALID_SECTOR))
{
return BLT_FALSE;
return BLT_FALSE;
}
/* if this is the bootblock, then let the boot block manager handle it */
@ -239,24 +239,24 @@ blt_bool FlashWrite(blt_addr addr, blt_int32u len, blt_int8u *data)
/************************************************************************************//**
** \brief Erases the flash memory. Note that this function also checks that no
** data is erased outside the flash memory region, so the bootloader can
** \brief Erases the flash memory. Note that this function also checks that no
** data is erased outside the flash memory region, so the bootloader can
** never be erased.
** \param addr Start address.
** \param len Length in bytes.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
blt_bool FlashErase(blt_addr addr, blt_int32u len)
{
blt_int8u first_sector;
blt_int8u last_sector;
/* obtain the first and last sector number */
first_sector = FlashGetSector(addr);
last_sector = FlashGetSector(addr+len-1);
/* check them */
if ( (first_sector == FLASH_INVALID_SECTOR) || (last_sector == FLASH_INVALID_SECTOR) )
if ((first_sector == FLASH_INVALID_SECTOR) || (last_sector == FLASH_INVALID_SECTOR))
{
return BLT_FALSE;
}
@ -271,27 +271,27 @@ blt_bool FlashErase(blt_addr addr, blt_int32u len)
** the checksum, the bootloader can check if the programming session
** was completed, which indicates that a valid user programming is
** present and can be started.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
blt_bool FlashWriteChecksum(void)
{
blt_int32u signature_checksum = 0;
/* for the LM3S target we defined the checksum as the Two's complement value of the
* sum of the first 7 exception addresses.
*
* Layout of the vector table:
* 0x00000000 Initial stack pointer
* 0x00000000 Initial stack pointer
* 0x00000004 Reset Handler
* 0x00000008 NMI Handler
* 0x0000000C Hard Fault Handler
* 0x00000010 MPU Fault Handler
* 0x00000010 MPU Fault Handler
* 0x00000014 Bus Fault Handler
* 0x00000018 Usage Fault Handler
*
* signature_checksum = Two's complement of (SUM(exception address values))
*
*
* the bootloader writes this 32-bit checksum value right after the vector table
* of the user program. note that this means one extra dummy entry must be added
* at the end of the user program's vector table to reserve storage space for the
@ -302,49 +302,49 @@ blt_bool FlashWriteChecksum(void)
* bootblock is not part of the reprogramming this time and therefore no
* new checksum needs to be written
*/
if (bootBlockInfo.base_addr == FLASH_INVALID_ADDRESS)
{
if (bootBlockInfo.base_addr == FLASH_INVALID_ADDRESS)
{
return BLT_TRUE;
}
}
/* compute the checksum. note that the user program's vectors are not yet written
* to flash but are present in the bootblock data structure at this point.
*/
signature_checksum += *((blt_int32u*)(&bootBlockInfo.data[0+0x00]));
signature_checksum += *((blt_int32u*)(&bootBlockInfo.data[0+0x04]));
signature_checksum += *((blt_int32u*)(&bootBlockInfo.data[0+0x08]));
signature_checksum += *((blt_int32u*)(&bootBlockInfo.data[0+0x0C]));
signature_checksum += *((blt_int32u*)(&bootBlockInfo.data[0+0x10]));
signature_checksum += *((blt_int32u*)(&bootBlockInfo.data[0+0x14]));
signature_checksum += *((blt_int32u*)(&bootBlockInfo.data[0+0x18]));
signature_checksum += *((blt_int32u *)(&bootBlockInfo.data[0+0x00]));
signature_checksum += *((blt_int32u *)(&bootBlockInfo.data[0+0x04]));
signature_checksum += *((blt_int32u *)(&bootBlockInfo.data[0+0x08]));
signature_checksum += *((blt_int32u *)(&bootBlockInfo.data[0+0x0C]));
signature_checksum += *((blt_int32u *)(&bootBlockInfo.data[0+0x10]));
signature_checksum += *((blt_int32u *)(&bootBlockInfo.data[0+0x14]));
signature_checksum += *((blt_int32u *)(&bootBlockInfo.data[0+0x18]));
signature_checksum = ~signature_checksum; /* one's complement */
signature_checksum += 1; /* two's complement */
/* write the checksum */
return FlashWrite(flashLayout[0].sector_start+FLASH_VECTOR_TABLE_CS_OFFSET,
sizeof(blt_addr), (blt_int8u*)&signature_checksum);
return FlashWrite(flashLayout[0].sector_start+FLASH_VECTOR_TABLE_CS_OFFSET,
sizeof(blt_addr), (blt_int8u *)&signature_checksum);
} /*** end of FlashWriteChecksum ***/
/************************************************************************************//**
** \brief Verifies the checksum, which indicates that a valid user program is
** present and can be started.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
blt_bool FlashVerifyChecksum(void)
{
blt_int32u signature_checksum = 0;
/* verify the checksum based on how it was written by CpuWriteChecksum() */
signature_checksum += *((blt_int32u*)(flashLayout[0].sector_start));
signature_checksum += *((blt_int32u*)(flashLayout[0].sector_start+0x04));
signature_checksum += *((blt_int32u*)(flashLayout[0].sector_start+0x08));
signature_checksum += *((blt_int32u*)(flashLayout[0].sector_start+0x0C));
signature_checksum += *((blt_int32u*)(flashLayout[0].sector_start+0x10));
signature_checksum += *((blt_int32u*)(flashLayout[0].sector_start+0x14));
signature_checksum += *((blt_int32u*)(flashLayout[0].sector_start+0x18));
signature_checksum += *((blt_int32u*)(flashLayout[0].sector_start+FLASH_VECTOR_TABLE_CS_OFFSET));
signature_checksum += *((blt_int32u *)(flashLayout[0].sector_start));
signature_checksum += *((blt_int32u *)(flashLayout[0].sector_start+0x04));
signature_checksum += *((blt_int32u *)(flashLayout[0].sector_start+0x08));
signature_checksum += *((blt_int32u *)(flashLayout[0].sector_start+0x0C));
signature_checksum += *((blt_int32u *)(flashLayout[0].sector_start+0x10));
signature_checksum += *((blt_int32u *)(flashLayout[0].sector_start+0x14));
signature_checksum += *((blt_int32u *)(flashLayout[0].sector_start+0x18));
signature_checksum += *((blt_int32u *)(flashLayout[0].sector_start+FLASH_VECTOR_TABLE_CS_OFFSET));
/* sum should add up to an unsigned 32-bit value of 0 */
if (signature_checksum == 0)
{
@ -359,7 +359,7 @@ blt_bool FlashVerifyChecksum(void)
/************************************************************************************//**
** \brief Finalizes the flash driver operations. There could still be data in
** the currently active block that needs to be flashed.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
blt_bool FlashDone(void)
@ -372,7 +372,7 @@ blt_bool FlashDone(void)
return BLT_FALSE;
}
}
/* check if there is still data waiting to be programmed */
if (blockInfo.base_addr != FLASH_INVALID_ADDRESS)
{
@ -381,7 +381,7 @@ blt_bool FlashDone(void)
return BLT_FALSE;
}
}
/* still here so all is okay */
/* still here so all is okay */
return BLT_TRUE;
} /*** end of FlashDone ***/
@ -399,16 +399,16 @@ blt_addr FlashGetUserProgBaseAddress(void)
/************************************************************************************//**
** \brief Copies data currently in flash to the block->data and sets the
** \brief Copies data currently in flash to the block->data and sets the
** base address.
** \param block Pointer to flash block info structure to operate on.
** \param address Base address of the block data.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
static blt_bool FlashInitBlock(tFlashBlockInfo *block, blt_addr address)
{
/* check address alignment */
/* check address alignment */
if ((address % FLASH_WRITE_BLOCK_SIZE) != 0)
{
return BLT_FALSE;
@ -419,8 +419,8 @@ static blt_bool FlashInitBlock(tFlashBlockInfo *block, blt_addr address)
/* block already initialized, so nothing to do */
return BLT_TRUE;
}
/* set the base address and copies the current data from flash */
block->base_addr = address;
/* set the base address and copies the current data from flash */
block->base_addr = address;
CpuMemCopy((blt_addr)block->data, address, FLASH_WRITE_BLOCK_SIZE);
return BLT_TRUE;
} /*** end of FlashInitBlock ***/
@ -439,14 +439,14 @@ static tFlashBlockInfo *FlashSwitchBlock(tFlashBlockInfo *block, blt_addr base_a
{
/* check if a switch needs to be made away from the boot block. in this case the boot
* block shouldn't be written yet, because this is done at the end of the programming
* session by FlashDone(), this is right after the checksum was written.
* session by FlashDone(), this is right after the checksum was written.
*/
if (block == &bootBlockInfo)
{
/* switch from the boot block to the generic block info structure */
block = &blockInfo;
}
/* check if a switch back into the bootblock is needed. in this case the generic block
/* check if a switch back into the bootblock is needed. in this case the generic block
* doesn't need to be written here yet.
*/
else if (base_addr == flashLayout[0].sector_start)
@ -465,7 +465,7 @@ static tFlashBlockInfo *FlashSwitchBlock(tFlashBlockInfo *block, blt_addr base_a
}
/* initialize tne new block when necessary */
if (FlashInitBlock(block, base_addr) == BLT_FALSE)
if (FlashInitBlock(block, base_addr) == BLT_FALSE)
{
return BLT_NULL;
}
@ -487,13 +487,13 @@ static tFlashBlockInfo *FlashSwitchBlock(tFlashBlockInfo *block, blt_addr base_a
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
static blt_bool FlashAddToBlock(tFlashBlockInfo *block, blt_addr address,
static blt_bool FlashAddToBlock(tFlashBlockInfo *block, blt_addr address,
blt_int8u *data, blt_int32u len)
{
blt_addr current_base_addr;
blt_int8u *dst;
blt_int8u *src;
/* determine the current base address */
current_base_addr = (address/FLASH_WRITE_BLOCK_SIZE)*FLASH_WRITE_BLOCK_SIZE;
@ -517,7 +517,7 @@ static blt_bool FlashAddToBlock(tFlashBlockInfo *block, blt_addr address,
return BLT_FALSE;
}
}
/* add the data to the current block, but check for block overflow */
dst = &(block->data[address - block->base_addr]);
src = data;
@ -576,7 +576,7 @@ static blt_bool FlashWriteBlock(tFlashBlockInfo *block)
for (word_cnt=0; word_cnt<(FLASH_WRITE_BLOCK_SIZE/sizeof(blt_int32u)); word_cnt++)
{
prog_addr = block->base_addr + (word_cnt * sizeof(blt_int32u));
prog_data = *(volatile blt_int32u*)(&block->data[word_cnt * sizeof(blt_int32u)]);
prog_data = *(volatile blt_int32u *)(&block->data[word_cnt * sizeof(blt_int32u)]);
/* keep the watchdog happy */
CopService();
/* program the word to flash */
@ -586,7 +586,7 @@ static blt_bool FlashWriteBlock(tFlashBlockInfo *block)
break;
}
/* verify that the written data is actually there */
if (*(volatile blt_int32u*)prog_addr != prog_data)
if (*(volatile blt_int32u *)prog_addr != prog_data)
{
result = BLT_FALSE;
break;
@ -616,8 +616,8 @@ static blt_bool FlashEraseSectors(blt_int8u first_sector, blt_int8u last_sector)
{
return BLT_FALSE;
}
if ( (first_sector < flashLayout[0].sector_num) || \
(last_sector > flashLayout[FLASH_TOTAL_SECTORS-1].sector_num) )
if ((first_sector < flashLayout[0].sector_num) || \
(last_sector > flashLayout[FLASH_TOTAL_SECTORS-1].sector_num))
{
return BLT_FALSE;
}
@ -625,7 +625,7 @@ static blt_bool FlashEraseSectors(blt_int8u first_sector, blt_int8u last_sector)
start_addr = FlashGetSectorBaseAddr(first_sector);
end_addr = FlashGetSectorBaseAddr(last_sector) + FlashGetSectorSize(last_sector) - 1;
nr_of_blocks = (end_addr - start_addr + 1) / FLASH_ERASE_BLOCK_SIZE;
/* erase all blocks one by one */
for (block_cnt=0; block_cnt<nr_of_blocks; block_cnt++)
{
@ -651,16 +651,16 @@ static blt_bool FlashEraseSectors(blt_int8u first_sector, blt_int8u last_sector)
static blt_int8u FlashGetSector(blt_addr address)
{
blt_int8u sectorIdx;
/* search through the sectors to find the right one */
for (sectorIdx = 0; sectorIdx < FLASH_TOTAL_SECTORS; sectorIdx++)
{
/* keep the watchdog happy */
CopService();
/* is the address in this sector? */
if ( (address >= flashLayout[sectorIdx].sector_start) && \
(address < (flashLayout[sectorIdx].sector_start + \
flashLayout[sectorIdx].sector_size)) )
if ((address >= flashLayout[sectorIdx].sector_start) && \
(address < (flashLayout[sectorIdx].sector_start + \
flashLayout[sectorIdx].sector_size)))
{
/* return the sector number */
return flashLayout[sectorIdx].sector_num;
@ -680,7 +680,7 @@ static blt_int8u FlashGetSector(blt_addr address)
static blt_addr FlashGetSectorBaseAddr(blt_int8u sector)
{
blt_int8u sectorIdx;
/* search through the sectors to find the right one */
for (sectorIdx = 0; sectorIdx < FLASH_TOTAL_SECTORS; sectorIdx++)
{
@ -705,7 +705,7 @@ static blt_addr FlashGetSectorBaseAddr(blt_int8u sector)
static blt_addr FlashGetSectorSize(blt_int8u sector)
{
blt_int8u sectorIdx;
/* search through the sectors to find the right one */
for (sectorIdx = 0; sectorIdx < FLASH_TOTAL_SECTORS; sectorIdx++)
{

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
#ifndef FLASH_H

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -93,12 +93,12 @@ blt_bool NvmWrite(blt_addr addr, blt_int32u len, blt_int8u *data)
* by this driver.
*/
result = NvmWriteHook(addr, len, data);
/* process the return code */
if (result == BLT_NVM_OKAY)
{
/* data was within range of the additionally supported memory and succesfully
* programmed, so we are all done.
* programmed, so we are all done.
*/
return BLT_TRUE;
}
@ -134,12 +134,12 @@ blt_bool NvmErase(blt_addr addr, blt_int32u len)
* by this driver.
*/
result = NvmEraseHook(addr, len);
/* process the return code */
if (result == BLT_NVM_OKAY)
{
/* address was within range of the additionally supported memory and succesfully
* erased, so we are all done.
* erased, so we are all done.
*/
return BLT_TRUE;
}
@ -176,7 +176,7 @@ blt_bool NvmVerifyChecksum(void)
/************************************************************************************//**
** \brief Obtains the base address of the non-volatile memory available to the user
** \brief Obtains the base address of the non-volatile memory available to the user
** program. This is typically that start of the vector table.
** \return Base address.
**
@ -188,11 +188,11 @@ blt_addr NvmGetUserProgBaseAddress(void)
/************************************************************************************//**
** \brief Once all erase and programming operations are completed, this
** function is called, so at the end of the programming session and
** \brief Once all erase and programming operations are completed, this
** function is called, so at the end of the programming session and
** right before a software reset is performed. It is used to calculate
** a checksum and program this into flash. This checksum is later used
** to determine if a valid user program is present in flash.
** to determine if a valid user program is present in flash.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
#ifndef TYPES_H

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -67,16 +67,16 @@ static blt_bool UartTransmitByte(blt_int8u data);
****************************************************************************************/
void UartInit(void)
{
/* the current implementation supports UART0. throw an assertion error in case a
* different UART channel is configured.
/* the current implementation supports UART0. throw an assertion error in case a
* different UART channel is configured.
*/
ASSERT_CT(BOOT_COM_UART_CHANNEL_INDEX == 0);
ASSERT_CT(BOOT_COM_UART_CHANNEL_INDEX == 0);
/* enable the UART0 peripheral */
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
/* configure the UART0 baudrate and communication parameters */
UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), BOOT_COM_UART_BAUDRATE,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE));
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE));
} /*** end of UartInit ***/
@ -93,12 +93,12 @@ void UartTransmitPacket(blt_int8u *data, blt_int8u len)
blt_bool result;
/* verify validity of the len-paramenter */
ASSERT_RT(len <= BOOT_COM_UART_TX_MAX_DATA);
ASSERT_RT(len <= BOOT_COM_UART_TX_MAX_DATA);
/* first transmit the length of the packet */
/* first transmit the length of the packet */
result = UartTransmitByte(len);
ASSERT_RT(result == BLT_TRUE);
ASSERT_RT(result == BLT_TRUE);
/* transmit all the packet bytes one-by-one */
for (data_index = 0; data_index < len; data_index++)
{
@ -106,7 +106,7 @@ void UartTransmitPacket(blt_int8u *data, blt_int8u len)
CopService();
/* write byte */
result = UartTransmitByte(data[data_index]);
ASSERT_RT(result == BLT_TRUE);
ASSERT_RT(result == BLT_TRUE);
}
} /*** end of UartTransmitPacket ***/
@ -153,7 +153,7 @@ blt_bool UartReceivePacket(blt_int8u *data)
if (xcpCtoRxLength == xcpCtoReqPacket[0])
{
/* copy the packet data */
CpuMemCopy((blt_int32u)data, (blt_int32u)&xcpCtoReqPacket[1], xcpCtoRxLength);
CpuMemCopy((blt_int32u)data, (blt_int32u)&xcpCtoReqPacket[1], xcpCtoRxLength);
/* done with cto packet reception */
xcpCtoRxInProgress = BLT_FALSE;
/* packet reception complete */
@ -190,7 +190,7 @@ static blt_bool UartReceiveByte(blt_int8u *data)
/* try to read a newly received byte */
result = UARTCharGetNonBlocking(UART0_BASE);
/* check if a new byte was received */
if(result != -1)
if (result != -1)
{
/* store the received byte */
data[0] = (blt_int8u)result;
@ -217,8 +217,8 @@ static blt_bool UartTransmitByte(blt_int8u data)
return BLT_FALSE;
}
/* wait for tx holding register to be empty */
while(UARTSpaceAvail(UART0_BASE) == false)
{
while (UARTSpaceAvail(UART0_BASE) == false)
{
/* keep the watchdog happy */
CopService();
}

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -47,7 +47,7 @@ extern void reset_handler(void); /* implemented in cstart.s
* External data declarations
****************************************************************************************/
/** \brief Stack end address (memory.x) */
extern blt_int32u __stack_end__;
extern blt_int32u __stack_end__;
/************************************************************************************//**
@ -70,13 +70,13 @@ typedef union
{
void (*func)(void); /**< for ISR function pointers */
blt_int32u ptr; /**< for stack pointer entry */
}tIsrFunc;
} tIsrFunc;
/** \brief Interrupt vector table. */
__attribute__ ((section(".vectors")))
__attribute__((section(".vectors")))
const tIsrFunc _vectors[] =
{
{ .ptr = (blt_int32u)&__stack_end__ }, /* the initial stack pointer */
{ .ptr = (blt_int32u) &__stack_end__ }, /* the initial stack pointer */
reset_handler, /* the reset handler */
UnusedISR, /* NMI Handler */
UnusedISR, /* Hard Fault Handler */

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -56,7 +56,7 @@ extern blt_int32u _estack;
/************************************************************************************//**
** \brief Reset interrupt service routine. Configures the stack, initializes
** \brief Reset interrupt service routine. Configures the stack, initializes
** RAM and jumps to function main.
** \return none.
**
@ -69,11 +69,11 @@ void reset_handler(void)
__asm(" cpsid i");
/* copy the data segment initializers from flash to SRAM */
pSrc = &_etext;
for(pDest = &_data; pDest < &_edata; )
for (pDest = &_data; pDest < &_edata;)
{
*pDest++ = *pSrc++;
}
/* zero fill the bss segment. this is done with inline assembly since this will
/* zero fill the bss segment. this is done with inline assembly since this will
* clear the value of pDest if it is not kept in a register.
*/
__asm(" ldr r0, =_bss\n"

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -64,13 +64,13 @@ typedef union
{
void (*func)(void); /**< for ISR function pointers */
blt_int32u ptr; /**< for stack pointer entry */
}tIsrFunc;
} tIsrFunc;
/** \brief Interrupt vector table. */
__attribute__ ((section(".isr_vector")))
__attribute__((section(".isr_vector")))
const tIsrFunc _vectab[] =
{
{ .ptr = (blt_int32u)&_estack }, /* the initial stack pointer */
{ .ptr = (blt_int32u) &_estack }, /* the initial stack pointer */
{ reset_handler }, /* the reset handler */
{ UnusedISR }, /* NMI Handler */
{ UnusedISR }, /* Hard Fault Handler */

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -40,7 +40,7 @@
/****************************************************************************************
* External functions
****************************************************************************************/
extern void reset_handler( void );
extern void reset_handler(void);
/****************************************************************************************
@ -51,7 +51,7 @@ typedef union
{
void (*func)(void); /**< for ISR function pointers */
void *ptr; /**< for stack pointer entry */
}tIsrFunc;
} tIsrFunc;
/************************************************************************************//**
@ -75,7 +75,7 @@ void UnusedISR(void)
/** \brief Interrupt vector table. */
__root const tIsrFunc __vector_table[] @ ".intvec" =
{
{ .ptr = __sfe( "CSTACK" ) }, /* the initial stack pointer */
{ .ptr = __sfe("CSTACK") }, /* the initial stack pointer */
{ &reset_handler }, /* the reset handler */
{ UnusedISR }, /* NMI Handler */
{ UnusedISR }, /* Hard Fault Handler */

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -58,7 +58,7 @@ typedef struct
volatile blt_int32u RDTR;
volatile blt_int32u RDLR;
volatile blt_int32u RDHR;
} tCanRxFIFOMailBox;
} tCanRxFIFOMailBox;
/** \brief CAN filter register layout. */
typedef struct
@ -92,7 +92,7 @@ typedef struct
volatile blt_int32u FA1R;
blt_int32u RESERVED5[8];
tCanFilter sFilterRegister[14];
} tCanRegs;
} tCanRegs;
/****************************************************************************************
@ -140,48 +140,49 @@ typedef struct t_can_bus_timing
* Local constant declarations
****************************************************************************************/
/** \brief CAN bittiming table for dynamically calculating the bittiming settings.
* \details According to the CAN protocol 1 bit-time can be made up of between 8..25
* time quanta (TQ). The total TQ in a bit is SYNC + TSEG1 + TSEG2 with SYNC
* always being 1. The sample point is (SYNC + TSEG1) / (SYNC + TSEG1 + SEG2) *
* \details According to the CAN protocol 1 bit-time can be made up of between 8..25
* time quanta (TQ). The total TQ in a bit is SYNC + TSEG1 + TSEG2 with SYNC
* always being 1. The sample point is (SYNC + TSEG1) / (SYNC + TSEG1 + SEG2) *
* 100%. This array contains possible and valid time quanta configurations with
* a sample point between 68..78%.
*/
static const tCanBusTiming canTiming[] =
{ /* TQ | TSEG1 | TSEG2 | SP */
/* ------------------------- */
{ 5, 2 }, /* 8 | 5 | 2 | 75% */
{ 6, 2 }, /* 9 | 6 | 2 | 78% */
{ 6, 3 }, /* 10 | 6 | 3 | 70% */
{ 7, 3 }, /* 11 | 7 | 3 | 73% */
{ 8, 3 }, /* 12 | 8 | 3 | 75% */
{ 9, 3 }, /* 13 | 9 | 3 | 77% */
{ 9, 4 }, /* 14 | 9 | 4 | 71% */
{ 10, 4 }, /* 15 | 10 | 4 | 73% */
{ 11, 4 }, /* 16 | 11 | 4 | 75% */
{ 12, 4 }, /* 17 | 12 | 4 | 76% */
{ 12, 5 }, /* 18 | 12 | 5 | 72% */
{ 13, 5 }, /* 19 | 13 | 5 | 74% */
{ 14, 5 }, /* 20 | 14 | 5 | 75% */
{ 15, 5 }, /* 21 | 15 | 5 | 76% */
{ 15, 6 }, /* 22 | 15 | 6 | 73% */
{ 16, 6 }, /* 23 | 16 | 6 | 74% */
{ 16, 7 }, /* 24 | 16 | 7 | 71% */
{ 16, 8 } /* 25 | 16 | 8 | 68% */
{
/* TQ | TSEG1 | TSEG2 | SP */
/* ------------------------- */
{ 5, 2 }, /* 8 | 5 | 2 | 75% */
{ 6, 2 }, /* 9 | 6 | 2 | 78% */
{ 6, 3 }, /* 10 | 6 | 3 | 70% */
{ 7, 3 }, /* 11 | 7 | 3 | 73% */
{ 8, 3 }, /* 12 | 8 | 3 | 75% */
{ 9, 3 }, /* 13 | 9 | 3 | 77% */
{ 9, 4 }, /* 14 | 9 | 4 | 71% */
{ 10, 4 }, /* 15 | 10 | 4 | 73% */
{ 11, 4 }, /* 16 | 11 | 4 | 75% */
{ 12, 4 }, /* 17 | 12 | 4 | 76% */
{ 12, 5 }, /* 18 | 12 | 5 | 72% */
{ 13, 5 }, /* 19 | 13 | 5 | 74% */
{ 14, 5 }, /* 20 | 14 | 5 | 75% */
{ 15, 5 }, /* 21 | 15 | 5 | 76% */
{ 15, 6 }, /* 22 | 15 | 6 | 73% */
{ 16, 6 }, /* 23 | 16 | 6 | 74% */
{ 16, 7 }, /* 24 | 16 | 7 | 71% */
{ 16, 8 } /* 25 | 16 | 8 | 68% */
};
/************************************************************************************//**
** \brief Search algorithm to match the desired baudrate to a possible bus
** \brief Search algorithm to match the desired baudrate to a possible bus
** timing configuration.
** \param baud The desired baudrate in kbps. Valid values are 10..1000.
** \param prescaler Pointer to where the value for the prescaler will be stored.
** \param tseg1 Pointer to where the value for TSEG2 will be stored.
** \param tseg2 Pointer to where the value for TSEG2 will be stored.
** \return BLT_TRUE if the CAN bustiming register values were found, BLT_FALSE
** \return BLT_TRUE if the CAN bustiming register values were found, BLT_FALSE
** otherwise.
**
****************************************************************************************/
static blt_bool CanGetSpeedConfig(blt_int16u baud, blt_int16u *prescaler,
static blt_bool CanGetSpeedConfig(blt_int16u baud, blt_int16u *prescaler,
blt_int8u *tseg1, blt_int8u *tseg2)
{
blt_int8u cnt;
@ -195,7 +196,7 @@ static blt_bool CanGetSpeedConfig(blt_int16u baud, blt_int16u *prescaler,
*prescaler = (BOOT_CPU_SYSTEM_SPEED_KHZ/2)/(baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1));
/* make sure the prescaler is valid */
if ( (*prescaler > 0) && (*prescaler <= 1024) )
if ((*prescaler > 0) && (*prescaler <= 1024))
{
/* store the bustiming configuration */
*tseg1 = canTiming[cnt].tseg1;
@ -221,10 +222,10 @@ void CanInit(void)
blt_int8u tseg1, tseg2;
blt_bool result;
/* the current implementation supports CAN1. throw an assertion error in case a
* different CAN channel is configured.
/* the current implementation supports CAN1. throw an assertion error in case a
* different CAN channel is configured.
*/
ASSERT_CT(BOOT_COM_CAN_CHANNEL_INDEX == 0);
ASSERT_CT(BOOT_COM_CAN_CHANNEL_INDEX == 0);
/* obtain bittiming configuration information */
result = CanGetSpeedConfig(BOOT_COM_CAN_BAUDRATE/1000, &prescaler, &tseg1, &tseg2);
ASSERT_RT(result == BLT_TRUE);
@ -267,8 +268,8 @@ void CanInit(void)
/* 32-bit scale for the filter */
CANx->FS1R |= CAN_BIT_FILTER0;
/* open up the acceptance filter to receive all messages */
CANx->sFilterRegister[0].FR1 = 0;
CANx->sFilterRegister[0].FR2 = 0;
CANx->sFilterRegister[0].FR1 = 0;
CANx->sFilterRegister[0].FR2 = 0;
/* select id/mask mode for the filter */
CANx->FM1R &= ~CAN_BIT_FILTER0;
/* FIFO 0 assignation for the filter */

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -69,7 +69,7 @@ extern void reset_handler(void); /* implemented in cstart.s
/************************************************************************************//**
** \brief Starts the user program, if one is present. In this case this function
** does not return.
** does not return.
** \return none.
**
****************************************************************************************/
@ -83,18 +83,18 @@ void CpuStartUserProgram(void)
/* not a valid user program so it cannot be started */
return;
}
#if (BOOT_CPU_USER_PROGRAM_START_HOOK > 0)
#if (BOOT_CPU_USER_PROGRAM_START_HOOK > 0)
/* invoke callback */
if (CpuUserProgramStartHook() == BLT_FALSE)
{
/* callback requests the user program to not be started */
return;
}
#endif
#if (BOOT_COM_ENABLE > 0)
#endif
#if (BOOT_COM_ENABLE > 0)
/* release the communication interface */
ComFree();
#endif
#endif
/* reset the timer */
TimerReset();
/* remap user program's vector table */
@ -103,7 +103,7 @@ void CpuStartUserProgram(void)
* the 2nd entry in the user program's vector table. this address points to the
* user program's reset handler.
*/
pProgResetHandler = (void(*)(void))(*((blt_addr*)CPU_USER_PROGRAM_STARTADDR_PTR));
pProgResetHandler = (void(*)(void))(*((blt_addr *)CPU_USER_PROGRAM_STARTADDR_PTR));
/* start the user program by activating its reset interrupt service routine */
pProgResetHandler();
} /*** end of CpuStartUserProgram ***/
@ -113,7 +113,7 @@ void CpuStartUserProgram(void)
** \brief Copies data from the source to the destination address.
** \param dest Destination address for the data.
** \param src Source address of the data.
** \param len length of the data in bytes.
** \param len length of the data in bytes.
** \return none.
**
****************************************************************************************/
@ -126,7 +126,7 @@ void CpuMemCopy(blt_addr dest, blt_addr src, blt_int16u len)
to = (blt_int8u *)dest;
/* copy all bytes from source address to destination address */
while(len-- > 0)
while (len-- > 0)
{
/* store byte value from source to destination */
*to++ = *from++;

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -75,7 +75,7 @@
* Type definitions
****************************************************************************************/
/** \brief Flash sector descriptor type. */
typedef struct
typedef struct
{
blt_addr sector_start; /**< sector start address */
blt_int32u sector_size; /**< sector size in bytes */
@ -83,10 +83,10 @@ typedef struct
} tFlashSector;
/** \brief Structure type for grouping flash block information.
* \details Programming is done per block of max FLASH_WRITE_BLOCK_SIZE. for this a
* \details Programming is done per block of max FLASH_WRITE_BLOCK_SIZE. for this a
* flash block manager is implemented in this driver. this flash block manager
* depends on this flash block info structure. It holds the base address of
* the flash block and the data that should be programmed into the flash
* depends on this flash block info structure. It holds the base address of
* the flash block and the data that should be programmed into the flash
* block. The .base_addr must be a multiple of FLASH_WRITE_BLOCK_SIZE.
*/
typedef struct
@ -98,7 +98,7 @@ typedef struct
/** \brief Flash controller register layout type. */
typedef struct
{
volatile blt_int32u ACR; /**< flash access control register */
volatile blt_int32u ACR; /**< flash access control register */
volatile blt_int32u KEYR; /**< FPEC key register */
volatile blt_int32u OPTKEYR; /**< flash OPTKEY register */
volatile blt_int32u SR; /**< flash status register */
@ -107,7 +107,7 @@ typedef struct
volatile blt_int32u RESERVED;
volatile blt_int32u OBR; /**< option byte register */
volatile blt_int32u WRPR; /**< write protection register */
} tFlashRegs;
} tFlashRegs;
/****************************************************************************************
@ -115,7 +115,7 @@ typedef struct
****************************************************************************************/
static blt_bool FlashInitBlock(tFlashBlockInfo *block, blt_addr address);
static tFlashBlockInfo *FlashSwitchBlock(tFlashBlockInfo *block, blt_addr base_addr);
static blt_bool FlashAddToBlock(tFlashBlockInfo *block, blt_addr address,
static blt_bool FlashAddToBlock(tFlashBlockInfo *block, blt_addr address,
blt_int8u *data, blt_int32u len);
static blt_bool FlashWriteBlock(tFlashBlockInfo *block);
static blt_bool FlashEraseSectors(blt_int8u first_sector, blt_int8u last_sector);
@ -130,13 +130,13 @@ static blt_addr FlashGetSectorSize(blt_int8u sector);
* Local constant declarations
****************************************************************************************/
/** \brief Array wit the layout of the flash memory.
* \details Also controls what part of the flash memory is reserved for the bootloader.
* If the bootloader size changes, the reserved sectors for the bootloader
* \details Also controls what part of the flash memory is reserved for the bootloader.
* If the bootloader size changes, the reserved sectors for the bootloader
* might need adjustment to make sure the bootloader doesn't get overwritten.
* The current flash layout does not reflect the minimum sector size of the
* physical flash (1 - 2kb), because this would make the table quit long and
* a waste of ROM. The minimum sector size is only really needed when erasing
* the flash. This can still be done in combination with macro
* the flash. This can still be done in combination with macro
* FLASH_ERASE_BLOCK_SIZE.
*/
static const tFlashSector flashLayout[] =
@ -192,30 +192,30 @@ static const tFlashSector flashLayout[] =
****************************************************************************************/
/** \brief Local variable with information about the flash block that is currently
* being operated on.
* \details The smallest amount of flash that can be programmed is
* \details The smallest amount of flash that can be programmed is
* FLASH_WRITE_BLOCK_SIZE. A flash block manager is implemented in this driver
* and stores info in this variable. Whenever new data should be flashed, it
* is first added to a RAM buffer, which is part of this variable. Whenever
* the RAM buffer, which has the size of a flash block, is full or data needs
* to be written to a different block, the contents of the RAM buffer are
* programmed to flash. The flash block manager requires some software
* overhead, yet results is faster flash programming because data is first
* harvested, ideally until there is enough to program an entire flash block,
* to be written to a different block, the contents of the RAM buffer are
* programmed to flash. The flash block manager requires some software
* overhead, yet results is faster flash programming because data is first
* harvested, ideally until there is enough to program an entire flash block,
* before the flash device is actually operated on.
*/
static tFlashBlockInfo blockInfo;
/** \brief Local variable with information about the flash boot block.
* \details The first block of the user program holds the vector table, which on the
* STM32 is also the where the checksum is written to. Is it likely that
* \details The first block of the user program holds the vector table, which on the
* STM32 is also the where the checksum is written to. Is it likely that
* the vector table is first flashed and then, at the end of the programming
* sequence, the checksum. This means that this flash block need to be written
* to twice. Normally this is not a problem with flash memory, as long as you
* write the same values to those bytes that are not supposed to be changed
* write the same values to those bytes that are not supposed to be changed
* and the locations where you do write to are still in the erased 0xFF state.
* Unfortunately, writing twice to flash this way, does not work reliably on
* Unfortunately, writing twice to flash this way, does not work reliably on
* all micros. This is why we need to have an extra block, the bootblock,
* placed under the management of the block manager. This way is it possible
* placed under the management of the block manager. This way is it possible
* to implement functionality so that the bootblock is only written to once
* at the end of the programming sequence.
*/
@ -223,7 +223,7 @@ static tFlashBlockInfo bootBlockInfo;
/************************************************************************************//**
** \brief Initializes the flash driver.
** \brief Initializes the flash driver.
** \return none.
**
****************************************************************************************/
@ -237,12 +237,12 @@ void FlashInit(void)
/************************************************************************************//**
** \brief Writes the data to flash through a flash block manager. Note that this
** function also checks that no data is programmed outside the flash
** function also checks that no data is programmed outside the flash
** memory region, so the bootloader can never be overwritten.
** \param addr Start address.
** \param len Length in bytes.
** \param data Pointer to the data buffer.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
blt_bool FlashWrite(blt_addr addr, blt_int32u len, blt_int8u *data)
@ -250,10 +250,10 @@ blt_bool FlashWrite(blt_addr addr, blt_int32u len, blt_int8u *data)
blt_addr base_addr;
/* make sure the addresses are within the flash device */
if ( (FlashGetSector(addr) == FLASH_INVALID_SECTOR) || \
(FlashGetSector(addr+len-1) == FLASH_INVALID_SECTOR) )
if ((FlashGetSector(addr) == FLASH_INVALID_SECTOR) || \
(FlashGetSector(addr+len-1) == FLASH_INVALID_SECTOR))
{
return BLT_FALSE;
return BLT_FALSE;
}
/* if this is the bootblock, then let the boot block manager handle it */
@ -269,24 +269,24 @@ blt_bool FlashWrite(blt_addr addr, blt_int32u len, blt_int8u *data)
/************************************************************************************//**
** \brief Erases the flash memory. Note that this function also checks that no
** data is erased outside the flash memory region, so the bootloader can
** \brief Erases the flash memory. Note that this function also checks that no
** data is erased outside the flash memory region, so the bootloader can
** never be erased.
** \param addr Start address.
** \param len Length in bytes.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
blt_bool FlashErase(blt_addr addr, blt_int32u len)
{
blt_int8u first_sector;
blt_int8u last_sector;
/* obtain the first and last sector number */
first_sector = FlashGetSector(addr);
last_sector = FlashGetSector(addr+len-1);
/* check them */
if ( (first_sector == FLASH_INVALID_SECTOR) || (last_sector == FLASH_INVALID_SECTOR) )
if ((first_sector == FLASH_INVALID_SECTOR) || (last_sector == FLASH_INVALID_SECTOR))
{
return BLT_FALSE;
}
@ -301,27 +301,27 @@ blt_bool FlashErase(blt_addr addr, blt_int32u len)
** the checksum, the bootloader can check if the programming session
** was completed, which indicates that a valid user programming is
** present and can be started.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
blt_bool FlashWriteChecksum(void)
{
blt_int32u signature_checksum = 0;
/* for the STM32 target we defined the checksum as the Two's complement value of the
* sum of the first 7 exception addresses.
*
* Layout of the vector table:
* 0x08000000 Initial stack pointer
* 0x08000000 Initial stack pointer
* 0x08000004 Reset Handler
* 0x08000008 NMI Handler
* 0x0800000C Hard Fault Handler
* 0x08000010 MPU Fault Handler
* 0x08000010 MPU Fault Handler
* 0x08000014 Bus Fault Handler
* 0x08000018 Usage Fault Handler
*
* signature_checksum = Two's complement of (SUM(exception address values))
*
*
* the bootloader writes this 32-bit checksum value right after the vector table
* of the user program. note that this means one extra dummy entry must be added
* at the end of the user program's vector table to reserve storage space for the
@ -332,49 +332,49 @@ blt_bool FlashWriteChecksum(void)
* bootblock is not part of the reprogramming this time and therefore no
* new checksum needs to be written
*/
if (bootBlockInfo.base_addr == FLASH_INVALID_ADDRESS)
{
if (bootBlockInfo.base_addr == FLASH_INVALID_ADDRESS)
{
return BLT_TRUE;
}
}
/* compute the checksum. note that the user program's vectors are not yet written
* to flash but are present in the bootblock data structure at this point.
*/
signature_checksum += *((blt_int32u*)(&bootBlockInfo.data[0+0x00]));
signature_checksum += *((blt_int32u*)(&bootBlockInfo.data[0+0x04]));
signature_checksum += *((blt_int32u*)(&bootBlockInfo.data[0+0x08]));
signature_checksum += *((blt_int32u*)(&bootBlockInfo.data[0+0x0C]));
signature_checksum += *((blt_int32u*)(&bootBlockInfo.data[0+0x10]));
signature_checksum += *((blt_int32u*)(&bootBlockInfo.data[0+0x14]));
signature_checksum += *((blt_int32u*)(&bootBlockInfo.data[0+0x18]));
signature_checksum += *((blt_int32u *)(&bootBlockInfo.data[0+0x00]));
signature_checksum += *((blt_int32u *)(&bootBlockInfo.data[0+0x04]));
signature_checksum += *((blt_int32u *)(&bootBlockInfo.data[0+0x08]));
signature_checksum += *((blt_int32u *)(&bootBlockInfo.data[0+0x0C]));
signature_checksum += *((blt_int32u *)(&bootBlockInfo.data[0+0x10]));
signature_checksum += *((blt_int32u *)(&bootBlockInfo.data[0+0x14]));
signature_checksum += *((blt_int32u *)(&bootBlockInfo.data[0+0x18]));
signature_checksum = ~signature_checksum; /* one's complement */
signature_checksum += 1; /* two's complement */
/* write the checksum */
return FlashWrite(flashLayout[0].sector_start+FLASH_VECTOR_TABLE_CS_OFFSET,
sizeof(blt_addr), (blt_int8u*)&signature_checksum);
return FlashWrite(flashLayout[0].sector_start+FLASH_VECTOR_TABLE_CS_OFFSET,
sizeof(blt_addr), (blt_int8u *)&signature_checksum);
} /*** end of FlashWriteChecksum ***/
/************************************************************************************//**
** \brief Verifies the checksum, which indicates that a valid user program is
** present and can be started.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
blt_bool FlashVerifyChecksum(void)
{
blt_int32u signature_checksum = 0;
/* verify the checksum based on how it was written by CpuWriteChecksum() */
signature_checksum += *((blt_int32u*)(flashLayout[0].sector_start));
signature_checksum += *((blt_int32u*)(flashLayout[0].sector_start+0x04));
signature_checksum += *((blt_int32u*)(flashLayout[0].sector_start+0x08));
signature_checksum += *((blt_int32u*)(flashLayout[0].sector_start+0x0C));
signature_checksum += *((blt_int32u*)(flashLayout[0].sector_start+0x10));
signature_checksum += *((blt_int32u*)(flashLayout[0].sector_start+0x14));
signature_checksum += *((blt_int32u*)(flashLayout[0].sector_start+0x18));
signature_checksum += *((blt_int32u*)(flashLayout[0].sector_start+FLASH_VECTOR_TABLE_CS_OFFSET));
signature_checksum += *((blt_int32u *)(flashLayout[0].sector_start));
signature_checksum += *((blt_int32u *)(flashLayout[0].sector_start+0x04));
signature_checksum += *((blt_int32u *)(flashLayout[0].sector_start+0x08));
signature_checksum += *((blt_int32u *)(flashLayout[0].sector_start+0x0C));
signature_checksum += *((blt_int32u *)(flashLayout[0].sector_start+0x10));
signature_checksum += *((blt_int32u *)(flashLayout[0].sector_start+0x14));
signature_checksum += *((blt_int32u *)(flashLayout[0].sector_start+0x18));
signature_checksum += *((blt_int32u *)(flashLayout[0].sector_start+FLASH_VECTOR_TABLE_CS_OFFSET));
/* sum should add up to an unsigned 32-bit value of 0 */
if (signature_checksum == 0)
{
@ -389,7 +389,7 @@ blt_bool FlashVerifyChecksum(void)
/************************************************************************************//**
** \brief Finalizes the flash driver operations. There could still be data in
** the currently active block that needs to be flashed.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
blt_bool FlashDone(void)
@ -402,7 +402,7 @@ blt_bool FlashDone(void)
return BLT_FALSE;
}
}
/* check if there is still data waiting to be programmed */
if (blockInfo.base_addr != FLASH_INVALID_ADDRESS)
{
@ -411,7 +411,7 @@ blt_bool FlashDone(void)
return BLT_FALSE;
}
}
/* still here so all is okay */
/* still here so all is okay */
return BLT_TRUE;
} /*** end of FlashDone ***/
@ -429,16 +429,16 @@ blt_addr FlashGetUserProgBaseAddress(void)
/************************************************************************************//**
** \brief Copies data currently in flash to the block->data and sets the
** \brief Copies data currently in flash to the block->data and sets the
** base address.
** \param block Pointer to flash block info structure to operate on.
** \param address Base address of the block data.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
static blt_bool FlashInitBlock(tFlashBlockInfo *block, blt_addr address)
{
/* check address alignment */
/* check address alignment */
if ((address % FLASH_WRITE_BLOCK_SIZE) != 0)
{
return BLT_FALSE;
@ -449,8 +449,8 @@ static blt_bool FlashInitBlock(tFlashBlockInfo *block, blt_addr address)
/* block already initialized, so nothing to do */
return BLT_TRUE;
}
/* set the base address and copies the current data from flash */
block->base_addr = address;
/* set the base address and copies the current data from flash */
block->base_addr = address;
CpuMemCopy((blt_addr)block->data, address, FLASH_WRITE_BLOCK_SIZE);
return BLT_TRUE;
} /*** end of FlashInitBlock ***/
@ -469,14 +469,14 @@ static tFlashBlockInfo *FlashSwitchBlock(tFlashBlockInfo *block, blt_addr base_a
{
/* check if a switch needs to be made away from the boot block. in this case the boot
* block shouldn't be written yet, because this is done at the end of the programming
* session by FlashDone(), this is right after the checksum was written.
* session by FlashDone(), this is right after the checksum was written.
*/
if (block == &bootBlockInfo)
{
/* switch from the boot block to the generic block info structure */
block = &blockInfo;
}
/* check if a switch back into the bootblock is needed. in this case the generic block
/* check if a switch back into the bootblock is needed. in this case the generic block
* doesn't need to be written here yet.
*/
else if (base_addr == flashLayout[0].sector_start)
@ -495,7 +495,7 @@ static tFlashBlockInfo *FlashSwitchBlock(tFlashBlockInfo *block, blt_addr base_a
}
/* initialize tne new block when necessary */
if (FlashInitBlock(block, base_addr) == BLT_FALSE)
if (FlashInitBlock(block, base_addr) == BLT_FALSE)
{
return BLT_NULL;
}
@ -517,13 +517,13 @@ static tFlashBlockInfo *FlashSwitchBlock(tFlashBlockInfo *block, blt_addr base_a
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
static blt_bool FlashAddToBlock(tFlashBlockInfo *block, blt_addr address,
static blt_bool FlashAddToBlock(tFlashBlockInfo *block, blt_addr address,
blt_int8u *data, blt_int32u len)
{
blt_addr current_base_addr;
blt_int8u *dst;
blt_int8u *src;
/* determine the current base address */
current_base_addr = (address/FLASH_WRITE_BLOCK_SIZE)*FLASH_WRITE_BLOCK_SIZE;
@ -547,7 +547,7 @@ static blt_bool FlashAddToBlock(tFlashBlockInfo *block, blt_addr address,
return BLT_FALSE;
}
}
/* add the data to the current block, but check for block overflow */
dst = &(block->data[address - block->base_addr]);
src = data;
@ -618,9 +618,9 @@ static blt_bool FlashWriteBlock(tFlashBlockInfo *block)
for (word_cnt=0; word_cnt<(FLASH_WRITE_BLOCK_SIZE/sizeof(blt_int32u)); word_cnt++)
{
prog_addr = block->base_addr + (word_cnt * sizeof(blt_int32u));
prog_data = *(volatile blt_int32u*)(&block->data[word_cnt * sizeof(blt_int32u)]);
prog_data = *(volatile blt_int32u *)(&block->data[word_cnt * sizeof(blt_int32u)]);
/* program the first half word */
*(volatile blt_int16u*)prog_addr = (blt_int16u)prog_data;
*(volatile blt_int16u *)prog_addr = (blt_int16u)prog_data;
/* wait for the program operation to complete */
while ((FLASH->SR & FLASH_BSY_BIT) == FLASH_BSY_BIT)
{
@ -628,7 +628,7 @@ static blt_bool FlashWriteBlock(tFlashBlockInfo *block)
CopService();
}
/* program the second half word */
*(volatile blt_int16u*)(prog_addr+2) = (blt_int16u)(prog_data >> 16);
*(volatile blt_int16u *)(prog_addr+2) = (blt_int16u)(prog_data >> 16);
/* wait for the program operation to complete */
while ((FLASH->SR & FLASH_BSY_BIT) == FLASH_BSY_BIT)
{
@ -636,7 +636,7 @@ static blt_bool FlashWriteBlock(tFlashBlockInfo *block)
CopService();
}
/* verify that the written data is actually there */
if (*(volatile blt_int32u*)prog_addr != prog_data)
if (*(volatile blt_int32u *)prog_addr != prog_data)
{
result = BLT_FALSE;
break;
@ -670,8 +670,8 @@ static blt_bool FlashEraseSectors(blt_int8u first_sector, blt_int8u last_sector)
{
return BLT_FALSE;
}
if ( (first_sector < flashLayout[0].sector_num) || \
(last_sector > flashLayout[FLASH_TOTAL_SECTORS-1].sector_num) )
if ((first_sector < flashLayout[0].sector_num) || \
(last_sector > flashLayout[FLASH_TOTAL_SECTORS-1].sector_num))
{
return BLT_FALSE;
}
@ -692,7 +692,7 @@ static blt_bool FlashEraseSectors(blt_int8u first_sector, blt_int8u last_sector)
start_addr = FlashGetSectorBaseAddr(first_sector);
end_addr = FlashGetSectorBaseAddr(last_sector) + FlashGetSectorSize(last_sector) - 1;
nr_of_blocks = (end_addr - start_addr + 1) / FLASH_ERASE_BLOCK_SIZE;
/* erase all blocks one by one */
for (block_cnt=0; block_cnt<nr_of_blocks; block_cnt++)
{
@ -754,16 +754,16 @@ static void FlashLock(void)
static blt_int8u FlashGetSector(blt_addr address)
{
blt_int8u sectorIdx;
/* search through the sectors to find the right one */
for (sectorIdx = 0; sectorIdx < FLASH_TOTAL_SECTORS; sectorIdx++)
{
/* keep the watchdog happy */
CopService();
/* is the address in this sector? */
if ( (address >= flashLayout[sectorIdx].sector_start) && \
(address < (flashLayout[sectorIdx].sector_start + \
flashLayout[sectorIdx].sector_size)) )
if ((address >= flashLayout[sectorIdx].sector_start) && \
(address < (flashLayout[sectorIdx].sector_start + \
flashLayout[sectorIdx].sector_size)))
{
/* return the sector number */
return flashLayout[sectorIdx].sector_num;
@ -783,7 +783,7 @@ static blt_int8u FlashGetSector(blt_addr address)
static blt_addr FlashGetSectorBaseAddr(blt_int8u sector)
{
blt_int8u sectorIdx;
/* search through the sectors to find the right one */
for (sectorIdx = 0; sectorIdx < FLASH_TOTAL_SECTORS; sectorIdx++)
{
@ -808,7 +808,7 @@ static blt_addr FlashGetSectorBaseAddr(blt_int8u sector)
static blt_addr FlashGetSectorSize(blt_int8u sector)
{
blt_int8u sectorIdx;
/* search through the sectors to find the right one */
for (sectorIdx = 0; sectorIdx < FLASH_TOTAL_SECTORS; sectorIdx++)
{

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
#ifndef FLASH_H

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -93,12 +93,12 @@ blt_bool NvmWrite(blt_addr addr, blt_int32u len, blt_int8u *data)
* by this driver.
*/
result = NvmWriteHook(addr, len, data);
/* process the return code */
if (result == BLT_NVM_OKAY)
{
/* data was within range of the additionally supported memory and succesfully
* programmed, so we are all done.
* programmed, so we are all done.
*/
return BLT_TRUE;
}
@ -134,12 +134,12 @@ blt_bool NvmErase(blt_addr addr, blt_int32u len)
* by this driver.
*/
result = NvmEraseHook(addr, len);
/* process the return code */
if (result == BLT_NVM_OKAY)
{
/* address was within range of the additionally supported memory and succesfully
* erased, so we are all done.
* erased, so we are all done.
*/
return BLT_TRUE;
}
@ -176,7 +176,7 @@ blt_bool NvmVerifyChecksum(void)
/************************************************************************************//**
** \brief Obtains the base address of the non-volatile memory available to the user
** \brief Obtains the base address of the non-volatile memory available to the user
** program. This is typically that start of the vector table.
** \return Base address.
**
@ -188,11 +188,11 @@ blt_addr NvmGetUserProgBaseAddress(void)
/************************************************************************************//**
** \brief Once all erase and programming operations are completed, this
** function is called, so at the end of the programming session and
** \brief Once all erase and programming operations are completed, this
** function is called, so at the end of the programming session and
** right before a software reset is performed. It is used to calculate
** a checksum and program this into flash. This checksum is later used
** to determine if a valid user program is present in flash.
** to determine if a valid user program is present in flash.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
#ifndef TYPES_H

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -109,10 +109,10 @@ static blt_bool UartTransmitByte(blt_int8u data);
****************************************************************************************/
void UartInit(void)
{
/* the current implementation supports USART1 and USART2. throw an assertion error in
* case a different UART channel is configured.
/* the current implementation supports USART1 and USART2. throw an assertion error in
* case a different UART channel is configured.
*/
ASSERT_CT((BOOT_COM_UART_CHANNEL_INDEX == 0) || (BOOT_COM_UART_CHANNEL_INDEX == 1));
ASSERT_CT((BOOT_COM_UART_CHANNEL_INDEX == 0) || (BOOT_COM_UART_CHANNEL_INDEX == 1));
/* first reset the UART configuration. note that this already configures the UART
* for 1 stopbit, 8 databits and no parity.
*/
@ -145,10 +145,10 @@ void UartTransmitPacket(blt_int8u *data, blt_int8u len)
/* verify validity of the len-paramenter */
ASSERT_RT(len <= BOOT_COM_UART_TX_MAX_DATA);
/* first transmit the length of the packet */
/* first transmit the length of the packet */
result = UartTransmitByte(len);
ASSERT_RT(result == BLT_TRUE);
ASSERT_RT(result == BLT_TRUE);
/* transmit all the packet bytes one-by-one */
for (data_index = 0; data_index < len; data_index++)
{
@ -156,7 +156,7 @@ void UartTransmitPacket(blt_int8u *data, blt_int8u len)
CopService();
/* write byte */
result = UartTransmitByte(data[data_index]);
ASSERT_RT(result == BLT_TRUE);
ASSERT_RT(result == BLT_TRUE);
}
} /*** end of UartTransmitPacket ***/
@ -203,7 +203,7 @@ blt_bool UartReceivePacket(blt_int8u *data)
if (xcpCtoRxLength == xcpCtoReqPacket[0])
{
/* copy the packet data */
CpuMemCopy((blt_int32u)data, (blt_int32u)&xcpCtoReqPacket[1], xcpCtoRxLength);
CpuMemCopy((blt_int32u)data, (blt_int32u)&xcpCtoReqPacket[1], xcpCtoRxLength);
/* done with cto packet reception */
xcpCtoRxInProgress = BLT_FALSE;
/* packet reception complete */
@ -236,7 +236,7 @@ blt_bool UartReceivePacket(blt_int8u *data)
static blt_bool UartReceiveByte(blt_int8u *data)
{
/* check if a new byte was received by means of the RDR-bit */
if((UARTx->SR & UART_BIT_RXNE) != 0)
if ((UARTx->SR & UART_BIT_RXNE) != 0)
{
/* store the received byte */
data[0] = UARTx->DR;
@ -265,8 +265,8 @@ static blt_bool UartTransmitByte(blt_int8u data)
/* write byte to transmit holding register */
UARTx->DR = data;
/* wait for tx holding register to be empty */
while((UARTx->SR & UART_BIT_TXE) == 0)
{
while ((UARTx->SR & UART_BIT_TXE) == 0)
{
/* keep the watchdog happy */
CopService();
}

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -65,7 +65,7 @@ typedef struct t_fifo_ctrl
blt_int8u *writeptr; /**< pointer to next free location */
blt_int8u length; /**< number of buffer elements */
blt_int8u entries; /**< # of full buffer elements */
blt_int8u handle; /**< handle of the buffer */
blt_int8u handle; /**< handle of the buffer */
struct t_fifo_ctrl *fifoctrlptr; /**< pointer to free buffer control */
} tFifoCtrl;
@ -123,15 +123,15 @@ void UsbInit(void)
fifoPipeBulkIN.handle = UsbFifoMgrCreate(fifoPipeBulkIN.data, FIFO_PIPE_SIZE);
fifoPipeBulkOUT.handle = UsbFifoMgrCreate(fifoPipeBulkOUT.data, FIFO_PIPE_SIZE);
/* validate fifo handles */
ASSERT_RT( (fifoPipeBulkIN.handle != FIFO_ERR_INVALID_HANDLE) && \
(fifoPipeBulkOUT.handle != FIFO_ERR_INVALID_HANDLE) );
ASSERT_RT((fifoPipeBulkIN.handle != FIFO_ERR_INVALID_HANDLE) && \
(fifoPipeBulkOUT.handle != FIFO_ERR_INVALID_HANDLE));
/* initialize the low level USB driver */
USB_Init();
} /*** end of UsbInit ***/
/************************************************************************************//**
** \brief Releases the USB communication interface.
** \brief Releases the USB communication interface.
** \return none.
**
****************************************************************************************/
@ -155,12 +155,12 @@ void UsbTransmitPacket(blt_int8u *data, blt_int8u len)
blt_bool result;
/* verify validity of the len-paramenter */
ASSERT_RT(len <= BOOT_COM_USB_TX_MAX_DATA);
ASSERT_RT(len <= BOOT_COM_USB_TX_MAX_DATA);
/* first transmit the length of the packet */
/* first transmit the length of the packet */
result = UsbTransmitByte(len);
ASSERT_RT(result == BLT_TRUE);
ASSERT_RT(result == BLT_TRUE);
/* transmit all the packet bytes one-by-one */
for (data_index = 0; data_index < len; data_index++)
{
@ -168,7 +168,7 @@ void UsbTransmitPacket(blt_int8u *data, blt_int8u len)
CopService();
/* write byte */
result = UsbTransmitByte(data[data_index]);
ASSERT_RT(result == BLT_TRUE);
ASSERT_RT(result == BLT_TRUE);
}
} /*** end of UsbTransmitPacket ***/
@ -215,7 +215,7 @@ blt_bool UsbReceivePacket(blt_int8u *data)
if (xcpCtoRxLength == xcpCtoReqPacket[0])
{
/* copy the packet data */
CpuMemCopy((blt_int32u)data, (blt_int32u)&xcpCtoReqPacket[1], xcpCtoRxLength);
CpuMemCopy((blt_int32u)data, (blt_int32u)&xcpCtoReqPacket[1], xcpCtoRxLength);
/* done with cto packet reception */
xcpCtoRxInProgress = BLT_FALSE;
@ -238,7 +238,7 @@ blt_bool UsbReceivePacket(blt_int8u *data)
static blt_bool UsbReceiveByte(blt_int8u *data)
{
blt_bool result;
/* obtain data from the fifo */
result = UsbFifoMgrRead(fifoPipeBulkOUT.handle, data);
return result;
@ -254,7 +254,7 @@ static blt_bool UsbReceiveByte(blt_int8u *data)
static blt_bool UsbTransmitByte(blt_int8u data)
{
blt_bool result;
/* write data from to fifo */
result = UsbFifoMgrWrite(fifoPipeBulkIN.handle, data);
return result;
@ -333,14 +333,14 @@ void UsbTransmitPipeBulkIN(void)
result = UsbFifoMgrRead(fifoPipeBulkIN.handle, &byte_value);
ASSERT_RT(result == BLT_TRUE);
/* store it in the endpoint's RAM */
USB_Tx_Buffer[byte_counter] = byte_value;
USB_Tx_Buffer[byte_counter] = byte_value;
}
/* store it in the endpoint's RAM */
UserToPMABufferCopy(&USB_Tx_Buffer[0], ENDP1_TXADDR, nr_of_bytes_for_tx_endpoint);
/* set the number of bytes that need to be transmitted from this endpoint */
SetEPTxCount(ENDP1, nr_of_bytes_for_tx_endpoint);
/* inform the endpoint that it can start its transmission because the data is valid */
SetEPTxValid(ENDP1);
SetEPTxValid(ENDP1);
} /*** end of UsbTransmitPipeBulkIN ***/
@ -356,12 +356,12 @@ void UsbReceivePipeBulkOUT(void)
uint16_t USB_Rx_Cnt;
uint16_t byte_counter;
blt_bool result;
/* Get the received data buffer and update the counter */
USB_Rx_Cnt = USB_SIL_Read(EP1_OUT, USB_Rx_Buffer);
/* USB data will be immediately processed, this allow next USB traffic being
* NAKed till the end of the USART Xfer
/* USB data will be immediately processed, this allow next USB traffic being
* NAKed till the end of the USART Xfer
*/
for (byte_counter=0; byte_counter<USB_Rx_Cnt; byte_counter++)
{
@ -383,23 +383,23 @@ void UsbReceivePipeBulkOUT(void)
** \return none.
**
****************************************************************************************/
static void IntToUnicode (blt_int32u value , blt_int8u *pbuf , blt_int8u len)
static void IntToUnicode(blt_int32u value , blt_int8u *pbuf , blt_int8u len)
{
blt_int8u idx = 0;
for( idx = 0 ; idx < len ; idx ++)
for (idx = 0 ; idx < len ; idx ++)
{
if( ((value >> 28)) < 0xA )
if (((value >> 28)) < 0xA)
{
pbuf[ 2* idx] = (value >> 28) + '0';
}
else
{
pbuf[2* idx] = (value >> 28) + 'A' - 10;
pbuf[2* idx] = (value >> 28) + 'A' - 10;
}
value = value << 4;
pbuf[ 2* idx + 1] = 0;
}
} /*** end of IntToUnicode ***/
@ -414,9 +414,9 @@ void UsbGetSerialNum(void)
{
blt_int32u Device_Serial0, Device_Serial1, Device_Serial2;
Device_Serial0 = *(volatile blt_int32u*)(0x1FFFF7E8);
Device_Serial1 = *(volatile blt_int32u*)(0x1FFFF7EC);
Device_Serial2 = *(volatile blt_int32u*)(0x1FFFF7F0);
Device_Serial0 = *(volatile blt_int32u *)(0x1FFFF7E8);
Device_Serial1 = *(volatile blt_int32u *)(0x1FFFF7EC);
Device_Serial2 = *(volatile blt_int32u *)(0x1FFFF7F0);
Device_Serial0 += Device_Serial2;
@ -488,7 +488,7 @@ static blt_int8u UsbFifoMgrCreate(blt_int8u *buffer, blt_int8u length)
pbc->writeptr = buffer;
pbc->entries = 0;
pbc->startptr = buffer;
pbc->endptr = (blt_int8u*)(buffer + length - 1);
pbc->endptr = (blt_int8u *)(buffer + length - 1);
/* return the handle to the successfully created fifo control */
return pbc->handle;
@ -524,7 +524,7 @@ static blt_bool UsbFifoMgrWrite(blt_int8u handle, blt_int8u data)
/* set write pointer to start of the cyclic fifo */
fifoCtrl[handle].writeptr = fifoCtrl[handle].startptr;
}
/* still here so all is okay */
/* still here so all is okay */
return BLT_TRUE;
} /*** end of UsbFifoMgrWrite ***/

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -47,7 +47,7 @@ extern void reset_handler(void); /* implemented in cstart.s
* External data declarations
****************************************************************************************/
/** \brief Stack end address (memory.x) */
extern blt_int32u __stack_end__;
extern blt_int32u __stack_end__;
/************************************************************************************//**
@ -70,13 +70,13 @@ typedef union
{
void (*func)(void); /**< for ISR function pointers */
blt_int32u ptr; /**< for stack pointer entry */
}tIsrFunc;
} tIsrFunc;
/** \brief Interrupt vector table. */
__attribute__ ((section(".vectors")))
__attribute__((section(".vectors")))
const tIsrFunc _vectors[] =
{
{ .ptr = (blt_int32u)&__stack_end__ }, /* the initial stack pointer */
{ .ptr = (blt_int32u) &__stack_end__ }, /* the initial stack pointer */
reset_handler, /* the reset handler */
UnusedISR, /* NMI Handler */
UnusedISR, /* Hard Fault Handler */

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -56,7 +56,7 @@ extern blt_int32u _estack;
/************************************************************************************//**
** \brief Reset interrupt service routine. Configures the stack, initializes
** \brief Reset interrupt service routine. Configures the stack, initializes
** RAM and jumps to function main.
** \return none.
**
@ -69,11 +69,11 @@ void reset_handler(void)
__asm(" cpsid i");
/* copy the data segment initializers from flash to SRAM */
pSrc = &_etext;
for(pDest = &_data; pDest < &_edata; )
for (pDest = &_data; pDest < &_edata;)
{
*pDest++ = *pSrc++;
}
/* zero fill the bss segment. this is done with inline assembly since this will
/* zero fill the bss segment. this is done with inline assembly since this will
* clear the value of pDest if it is not kept in a register.
*/
__asm(" ldr r0, =_bss\n"

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -64,13 +64,13 @@ typedef union
{
void (*func)(void); /**< for ISR function pointers */
blt_int32u ptr; /**< for stack pointer entry */
}tIsrFunc;
} tIsrFunc;
/** \brief Interrupt vector table. */
__attribute__ ((section(".isr_vector")))
__attribute__((section(".isr_vector")))
const tIsrFunc _vectab[] =
{
{ .ptr = (blt_int32u)&_estack }, /* the initial stack pointer */
{ .ptr = (blt_int32u) &_estack }, /* the initial stack pointer */
{ reset_handler }, /* the reset handler */
{ UnusedISR }, /* NMI Handler */
{ UnusedISR }, /* Hard Fault Handler */

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -40,7 +40,7 @@
/****************************************************************************************
* External functions
****************************************************************************************/
extern void reset_handler( void );
extern void reset_handler(void);
/****************************************************************************************
@ -51,7 +51,7 @@ typedef union
{
void (*func)(void); /**< for ISR function pointers */
void *ptr; /**< for stack pointer entry */
}tIsrFunc;
} tIsrFunc;
/************************************************************************************//**
@ -75,7 +75,7 @@ void UnusedISR(void)
/** \brief Interrupt vector table. */
__root const tIsrFunc __vector_table[] @ ".intvec" =
{
{ .ptr = __sfe( "CSTACK" ) }, /* the initial stack pointer */
{ .ptr = __sfe("CSTACK") }, /* the initial stack pointer */
{ &reset_handler }, /* the reset handler */
{ UnusedISR }, /* NMI Handler */
{ UnusedISR }, /* Hard Fault Handler */

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -58,7 +58,7 @@ typedef struct
volatile blt_int32u RDTR;
volatile blt_int32u RDLR;
volatile blt_int32u RDHR;
} tCanRxFIFOMailBox;
} tCanRxFIFOMailBox;
/** \brief CAN filter register layout. */
typedef struct
@ -92,7 +92,7 @@ typedef struct
volatile blt_int32u FA1R;
blt_int32u RESERVED5[8];
tCanFilter sFilterRegister[28];
} tCanRegs;
} tCanRegs;
/****************************************************************************************
@ -149,48 +149,49 @@ typedef struct t_can_bus_timing
* Local constant declarations
****************************************************************************************/
/** \brief CAN bittiming table for dynamically calculating the bittiming settings.
* \details According to the CAN protocol 1 bit-time can be made up of between 8..25
* time quanta (TQ). The total TQ in a bit is SYNC + TSEG1 + TSEG2 with SYNC
* always being 1. The sample point is (SYNC + TSEG1) / (SYNC + TSEG1 + SEG2) *
* \details According to the CAN protocol 1 bit-time can be made up of between 8..25
* time quanta (TQ). The total TQ in a bit is SYNC + TSEG1 + TSEG2 with SYNC
* always being 1. The sample point is (SYNC + TSEG1) / (SYNC + TSEG1 + SEG2) *
* 100%. This array contains possible and valid time quanta configurations with
* a sample point between 68..78%.
*/
static const tCanBusTiming canTiming[] =
{ /* TQ | TSEG1 | TSEG2 | SP */
/* ------------------------- */
{ 5, 2 }, /* 8 | 5 | 2 | 75% */
{ 6, 2 }, /* 9 | 6 | 2 | 78% */
{ 6, 3 }, /* 10 | 6 | 3 | 70% */
{ 7, 3 }, /* 11 | 7 | 3 | 73% */
{ 8, 3 }, /* 12 | 8 | 3 | 75% */
{ 9, 3 }, /* 13 | 9 | 3 | 77% */
{ 9, 4 }, /* 14 | 9 | 4 | 71% */
{ 10, 4 }, /* 15 | 10 | 4 | 73% */
{ 11, 4 }, /* 16 | 11 | 4 | 75% */
{ 12, 4 }, /* 17 | 12 | 4 | 76% */
{ 12, 5 }, /* 18 | 12 | 5 | 72% */
{ 13, 5 }, /* 19 | 13 | 5 | 74% */
{ 14, 5 }, /* 20 | 14 | 5 | 75% */
{ 15, 5 }, /* 21 | 15 | 5 | 76% */
{ 15, 6 }, /* 22 | 15 | 6 | 73% */
{ 16, 6 }, /* 23 | 16 | 6 | 74% */
{ 16, 7 }, /* 24 | 16 | 7 | 71% */
{ 16, 8 } /* 25 | 16 | 8 | 68% */
{
/* TQ | TSEG1 | TSEG2 | SP */
/* ------------------------- */
{ 5, 2 }, /* 8 | 5 | 2 | 75% */
{ 6, 2 }, /* 9 | 6 | 2 | 78% */
{ 6, 3 }, /* 10 | 6 | 3 | 70% */
{ 7, 3 }, /* 11 | 7 | 3 | 73% */
{ 8, 3 }, /* 12 | 8 | 3 | 75% */
{ 9, 3 }, /* 13 | 9 | 3 | 77% */
{ 9, 4 }, /* 14 | 9 | 4 | 71% */
{ 10, 4 }, /* 15 | 10 | 4 | 73% */
{ 11, 4 }, /* 16 | 11 | 4 | 75% */
{ 12, 4 }, /* 17 | 12 | 4 | 76% */
{ 12, 5 }, /* 18 | 12 | 5 | 72% */
{ 13, 5 }, /* 19 | 13 | 5 | 74% */
{ 14, 5 }, /* 20 | 14 | 5 | 75% */
{ 15, 5 }, /* 21 | 15 | 5 | 76% */
{ 15, 6 }, /* 22 | 15 | 6 | 73% */
{ 16, 6 }, /* 23 | 16 | 6 | 74% */
{ 16, 7 }, /* 24 | 16 | 7 | 71% */
{ 16, 8 } /* 25 | 16 | 8 | 68% */
};
/************************************************************************************//**
** \brief Search algorithm to match the desired baudrate to a possible bus
** \brief Search algorithm to match the desired baudrate to a possible bus
** timing configuration.
** \param baud The desired baudrate in kbps. Valid values are 10..1000.
** \param prescaler Pointer to where the value for the prescaler will be stored.
** \param tseg1 Pointer to where the value for TSEG2 will be stored.
** \param tseg2 Pointer to where the value for TSEG2 will be stored.
** \return BLT_TRUE if the CAN bustiming register values were found, BLT_FALSE
** \return BLT_TRUE if the CAN bustiming register values were found, BLT_FALSE
** otherwise.
**
****************************************************************************************/
static blt_bool CanGetSpeedConfig(blt_int16u baud, blt_int16u *prescaler,
static blt_bool CanGetSpeedConfig(blt_int16u baud, blt_int16u *prescaler,
blt_int8u *tseg1, blt_int8u *tseg2)
{
blt_int8u cnt;
@ -204,7 +205,7 @@ static blt_bool CanGetSpeedConfig(blt_int16u baud, blt_int16u *prescaler,
*prescaler = (BOOT_CPU_SYSTEM_SPEED_KHZ/4)/(baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1));
/* make sure the prescaler is valid */
if ( (*prescaler > 0) && (*prescaler <= 1024) )
if ((*prescaler > 0) && (*prescaler <= 1024))
{
/* store the bustiming configuration */
*tseg1 = canTiming[cnt].tseg1;
@ -230,10 +231,10 @@ void CanInit(void)
blt_int8u tseg1, tseg2;
blt_bool result;
/* the current implementation supports CAN1 and 2. throw an assertion error in case a
* different CAN channel is configured.
/* the current implementation supports CAN1 and 2. throw an assertion error in case a
* different CAN channel is configured.
*/
ASSERT_CT((BOOT_COM_CAN_CHANNEL_INDEX == 0 || BOOT_COM_CAN_CHANNEL_INDEX == 1));
ASSERT_CT((BOOT_COM_CAN_CHANNEL_INDEX == 0 || BOOT_COM_CAN_CHANNEL_INDEX == 1));
/* obtain bittiming configuration information */
result = CanGetSpeedConfig(BOOT_COM_CAN_BAUDRATE/1000, &prescaler, &tseg1, &tseg2);
@ -279,8 +280,8 @@ void CanInit(void)
/* 32-bit scale for the filter */
CAN1->FS1R |= CAN_BIT_FILTER0;
/* open up the acceptance filter to receive all messages */
CAN1->sFilterRegister[0].FR1 = 0;
CAN1->sFilterRegister[0].FR2 = 0;
CAN1->sFilterRegister[0].FR1 = 0;
CAN1->sFilterRegister[0].FR2 = 0;
/* select id/mask mode for the filter */
CAN1->FM1R &= ~CAN_BIT_FILTER0;
/* FIFO 0 assignation for the filter */
@ -297,8 +298,8 @@ void CanInit(void)
/* 32-bit scale for the filter */
CAN1->FS1R |= CAN_BIT_FILTER14;
/* open up the acceptance filter to receive all messages */
CAN1->sFilterRegister[14].FR1 = 0;
CAN1->sFilterRegister[14].FR2 = 0;
CAN1->sFilterRegister[14].FR1 = 0;
CAN1->sFilterRegister[14].FR2 = 0;
/* select id/mask mode for the filter */
CAN1->FM1R &= ~CAN_BIT_FILTER14;
/* FIFO 0 assignation for the filter */
@ -307,7 +308,7 @@ void CanInit(void)
CAN1->FA1R |= CAN_BIT_FILTER14;
/* leave initialisation mode for the acceptance filter */
CAN1->FMR &= ~CAN_BIT_FINIT;
#endif
#endif
} /*** end of CanInit ***/

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -69,7 +69,7 @@ extern void reset_handler(void); /* implemented in cstart.s
/************************************************************************************//**
** \brief Starts the user program, if one is present. In this case this function
** does not return.
** does not return.
** \return none.
**
****************************************************************************************/
@ -83,18 +83,18 @@ void CpuStartUserProgram(void)
/* not a valid user program so it cannot be started */
return;
}
#if (BOOT_CPU_USER_PROGRAM_START_HOOK > 0)
#if (BOOT_CPU_USER_PROGRAM_START_HOOK > 0)
/* invoke callback */
if (CpuUserProgramStartHook() == BLT_FALSE)
{
/* callback requests the user program to not be started */
return;
}
#endif
#if (BOOT_COM_ENABLE > 0)
#endif
#if (BOOT_COM_ENABLE > 0)
/* release the communication interface */
ComFree();
#endif
#endif
/* reset the timer */
TimerReset();
/* remap user program's vector table */
@ -103,7 +103,7 @@ void CpuStartUserProgram(void)
* the 2nd entry in the user program's vector table. this address points to the
* user program's reset handler.
*/
pProgResetHandler = (void(*)(void))(*((blt_addr*)CPU_USER_PROGRAM_STARTADDR_PTR));
pProgResetHandler = (void(*)(void))(*((blt_addr *)CPU_USER_PROGRAM_STARTADDR_PTR));
/* start the user program by activating its reset interrupt service routine */
pProgResetHandler();
} /*** end of CpuStartUserProgram ***/
@ -113,7 +113,7 @@ void CpuStartUserProgram(void)
** \brief Copies data from the source to the destination address.
** \param dest Destination address for the data.
** \param src Source address of the data.
** \param len length of the data in bytes.
** \param len length of the data in bytes.
** \return none.
**
****************************************************************************************/
@ -126,7 +126,7 @@ void CpuMemCopy(blt_addr dest, blt_addr src, blt_int16u len)
to = (blt_int8u *)dest;
/* copy all bytes from source address to destination address */
while(len-- > 0)
while (len-- > 0)
{
/* store byte value from source to destination */
*to++ = *from++;

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -58,7 +58,7 @@
* Type definitions
****************************************************************************************/
/** \brief Flash sector descriptor type. */
typedef struct
typedef struct
{
blt_addr sector_start; /**< sector start address */
blt_int32u sector_size; /**< sector size in bytes */
@ -66,10 +66,10 @@ typedef struct
} tFlashSector;
/** \brief Structure type for grouping flash block information.
* \details Programming is done per block of max FLASH_WRITE_BLOCK_SIZE. for this a
* \details Programming is done per block of max FLASH_WRITE_BLOCK_SIZE. for this a
* flash block manager is implemented in this driver. this flash block manager
* depends on this flash block info structure. It holds the base address of
* the flash block and the data that should be programmed into the flash
* depends on this flash block info structure. It holds the base address of
* the flash block and the data that should be programmed into the flash
* block. The .base_addr must be a multiple of FLASH_WRITE_BLOCK_SIZE.
*/
typedef struct
@ -84,7 +84,7 @@ typedef struct
****************************************************************************************/
static blt_bool FlashInitBlock(tFlashBlockInfo *block, blt_addr address);
static tFlashBlockInfo *FlashSwitchBlock(tFlashBlockInfo *block, blt_addr base_addr);
static blt_bool FlashAddToBlock(tFlashBlockInfo *block, blt_addr address,
static blt_bool FlashAddToBlock(tFlashBlockInfo *block, blt_addr address,
blt_int8u *data, blt_int32u len);
static blt_bool FlashWriteBlock(tFlashBlockInfo *block);
static blt_bool FlashEraseSectors(blt_int8u first_sector, blt_int8u last_sector);
@ -95,8 +95,8 @@ static blt_int8u FlashGetSector(blt_addr address);
* Local constant declarations
****************************************************************************************/
/** \brief Array wit the layout of the flash memory.
* \details Also controls what part of the flash memory is reserved for the bootloader.
* If the bootloader size changes, the reserved sectors for the bootloader
* \details Also controls what part of the flash memory is reserved for the bootloader.
* If the bootloader size changes, the reserved sectors for the bootloader
* might need adjustment to make sure the bootloader doesn't get overwritten.
*/
static const tFlashSector flashLayout[] =
@ -177,30 +177,30 @@ static const blt_int16u flashSectorNumToMask[] =
****************************************************************************************/
/** \brief Local variable with information about the flash block that is currently
* being operated on.
* \details The smallest amount of flash that can be programmed is
* \details The smallest amount of flash that can be programmed is
* FLASH_WRITE_BLOCK_SIZE. A flash block manager is implemented in this driver
* and stores info in this variable. Whenever new data should be flashed, it
* is first added to a RAM buffer, which is part of this variable. Whenever
* the RAM buffer, which has the size of a flash block, is full or data needs
* to be written to a different block, the contents of the RAM buffer are
* programmed to flash. The flash block manager requires some software
* overhead, yet results is faster flash programming because data is first
* harvested, ideally until there is enough to program an entire flash block,
* to be written to a different block, the contents of the RAM buffer are
* programmed to flash. The flash block manager requires some software
* overhead, yet results is faster flash programming because data is first
* harvested, ideally until there is enough to program an entire flash block,
* before the flash device is actually operated on.
*/
static tFlashBlockInfo blockInfo;
/** \brief Local variable with information about the flash boot block.
* \details The first block of the user program holds the vector table, which on the
* STM32 is also the where the checksum is written to. Is it likely that
* \details The first block of the user program holds the vector table, which on the
* STM32 is also the where the checksum is written to. Is it likely that
* the vector table is first flashed and then, at the end of the programming
* sequence, the checksum. This means that this flash block need to be written
* to twice. Normally this is not a problem with flash memory, as long as you
* write the same values to those bytes that are not supposed to be changed
* write the same values to those bytes that are not supposed to be changed
* and the locations where you do write to are still in the erased 0xFF state.
* Unfortunately, writing twice to flash this way, does not work reliably on
* Unfortunately, writing twice to flash this way, does not work reliably on
* all micros. This is why we need to have an extra block, the bootblock,
* placed under the management of the block manager. This way is it possible
* placed under the management of the block manager. This way is it possible
* to implement functionality so that the bootblock is only written to once
* at the end of the programming sequence.
*/
@ -208,7 +208,7 @@ static tFlashBlockInfo bootBlockInfo;
/************************************************************************************//**
** \brief Initializes the flash driver.
** \brief Initializes the flash driver.
** \return none.
**
****************************************************************************************/
@ -222,12 +222,12 @@ void FlashInit(void)
/************************************************************************************//**
** \brief Writes the data to flash through a flash block manager. Note that this
** function also checks that no data is programmed outside the flash
** function also checks that no data is programmed outside the flash
** memory region, so the bootloader can never be overwritten.
** \param addr Start address.
** \param len Length in bytes.
** \param data Pointer to the data buffer.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
blt_bool FlashWrite(blt_addr addr, blt_int32u len, blt_int8u *data)
@ -235,10 +235,10 @@ blt_bool FlashWrite(blt_addr addr, blt_int32u len, blt_int8u *data)
blt_addr base_addr;
/* make sure the addresses are within the flash device */
if ( (FlashGetSector(addr) == FLASH_INVALID_SECTOR) || \
(FlashGetSector(addr+len-1) == FLASH_INVALID_SECTOR) )
if ((FlashGetSector(addr) == FLASH_INVALID_SECTOR) || \
(FlashGetSector(addr+len-1) == FLASH_INVALID_SECTOR))
{
return BLT_FALSE;
return BLT_FALSE;
}
/* if this is the bootblock, then let the boot block manager handle it */
@ -254,24 +254,24 @@ blt_bool FlashWrite(blt_addr addr, blt_int32u len, blt_int8u *data)
/************************************************************************************//**
** \brief Erases the flash memory. Note that this function also checks that no
** data is erased outside the flash memory region, so the bootloader can
** \brief Erases the flash memory. Note that this function also checks that no
** data is erased outside the flash memory region, so the bootloader can
** never be erased.
** \param addr Start address.
** \param len Length in bytes.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
blt_bool FlashErase(blt_addr addr, blt_int32u len)
{
blt_int8u first_sector;
blt_int8u last_sector;
/* obtain the first and last sector number */
first_sector = FlashGetSector(addr);
last_sector = FlashGetSector(addr+len-1);
/* check them */
if ( (first_sector == FLASH_INVALID_SECTOR) || (last_sector == FLASH_INVALID_SECTOR) )
if ((first_sector == FLASH_INVALID_SECTOR) || (last_sector == FLASH_INVALID_SECTOR))
{
return BLT_FALSE;
}
@ -286,27 +286,27 @@ blt_bool FlashErase(blt_addr addr, blt_int32u len)
** the checksum, the bootloader can check if the programming session
** was completed, which indicates that a valid user programming is
** present and can be started.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
blt_bool FlashWriteChecksum(void)
{
blt_int32u signature_checksum = 0;
/* for the STM32 target we defined the checksum as the Two's complement value of the
* sum of the first 7 exception addresses.
*
* Layout of the vector table:
* 0x08000000 Initial stack pointer
* 0x08000000 Initial stack pointer
* 0x08000004 Reset Handler
* 0x08000008 NMI Handler
* 0x0800000C Hard Fault Handler
* 0x08000010 MPU Fault Handler
* 0x08000010 MPU Fault Handler
* 0x08000014 Bus Fault Handler
* 0x08000018 Usage Fault Handler
*
* signature_checksum = Two's complement of (SUM(exception address values))
*
*
* the bootloader writes this 32-bit checksum value right after the vector table
* of the user program. note that this means one extra dummy entry must be added
* at the end of the user program's vector table to reserve storage space for the
@ -317,49 +317,49 @@ blt_bool FlashWriteChecksum(void)
* bootblock is not part of the reprogramming this time and therefore no
* new checksum needs to be written
*/
if (bootBlockInfo.base_addr == FLASH_INVALID_ADDRESS)
{
if (bootBlockInfo.base_addr == FLASH_INVALID_ADDRESS)
{
return BLT_TRUE;
}
}
/* compute the checksum. note that the user program's vectors are not yet written
* to flash but are present in the bootblock data structure at this point.
*/
signature_checksum += *((blt_int32u*)(&bootBlockInfo.data[0+0x00]));
signature_checksum += *((blt_int32u*)(&bootBlockInfo.data[0+0x04]));
signature_checksum += *((blt_int32u*)(&bootBlockInfo.data[0+0x08]));
signature_checksum += *((blt_int32u*)(&bootBlockInfo.data[0+0x0C]));
signature_checksum += *((blt_int32u*)(&bootBlockInfo.data[0+0x10]));
signature_checksum += *((blt_int32u*)(&bootBlockInfo.data[0+0x14]));
signature_checksum += *((blt_int32u*)(&bootBlockInfo.data[0+0x18]));
signature_checksum += *((blt_int32u *)(&bootBlockInfo.data[0+0x00]));
signature_checksum += *((blt_int32u *)(&bootBlockInfo.data[0+0x04]));
signature_checksum += *((blt_int32u *)(&bootBlockInfo.data[0+0x08]));
signature_checksum += *((blt_int32u *)(&bootBlockInfo.data[0+0x0C]));
signature_checksum += *((blt_int32u *)(&bootBlockInfo.data[0+0x10]));
signature_checksum += *((blt_int32u *)(&bootBlockInfo.data[0+0x14]));
signature_checksum += *((blt_int32u *)(&bootBlockInfo.data[0+0x18]));
signature_checksum = ~signature_checksum; /* one's complement */
signature_checksum += 1; /* two's complement */
/* write the checksum */
return FlashWrite(flashLayout[0].sector_start+FLASH_VECTOR_TABLE_CS_OFFSET,
sizeof(blt_addr), (blt_int8u*)&signature_checksum);
return FlashWrite(flashLayout[0].sector_start+FLASH_VECTOR_TABLE_CS_OFFSET,
sizeof(blt_addr), (blt_int8u *)&signature_checksum);
} /*** end of FlashWriteChecksum ***/
/************************************************************************************//**
** \brief Verifies the checksum, which indicates that a valid user program is
** present and can be started.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
blt_bool FlashVerifyChecksum(void)
{
blt_int32u signature_checksum = 0;
/* verify the checksum based on how it was written by CpuWriteChecksum() */
signature_checksum += *((blt_int32u*)(flashLayout[0].sector_start));
signature_checksum += *((blt_int32u*)(flashLayout[0].sector_start+0x04));
signature_checksum += *((blt_int32u*)(flashLayout[0].sector_start+0x08));
signature_checksum += *((blt_int32u*)(flashLayout[0].sector_start+0x0C));
signature_checksum += *((blt_int32u*)(flashLayout[0].sector_start+0x10));
signature_checksum += *((blt_int32u*)(flashLayout[0].sector_start+0x14));
signature_checksum += *((blt_int32u*)(flashLayout[0].sector_start+0x18));
signature_checksum += *((blt_int32u*)(flashLayout[0].sector_start+FLASH_VECTOR_TABLE_CS_OFFSET));
signature_checksum += *((blt_int32u *)(flashLayout[0].sector_start));
signature_checksum += *((blt_int32u *)(flashLayout[0].sector_start+0x04));
signature_checksum += *((blt_int32u *)(flashLayout[0].sector_start+0x08));
signature_checksum += *((blt_int32u *)(flashLayout[0].sector_start+0x0C));
signature_checksum += *((blt_int32u *)(flashLayout[0].sector_start+0x10));
signature_checksum += *((blt_int32u *)(flashLayout[0].sector_start+0x14));
signature_checksum += *((blt_int32u *)(flashLayout[0].sector_start+0x18));
signature_checksum += *((blt_int32u *)(flashLayout[0].sector_start+FLASH_VECTOR_TABLE_CS_OFFSET));
/* sum should add up to an unsigned 32-bit value of 0 */
if (signature_checksum == 0)
{
@ -374,7 +374,7 @@ blt_bool FlashVerifyChecksum(void)
/************************************************************************************//**
** \brief Finalizes the flash driver operations. There could still be data in
** the currently active block that needs to be flashed.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
blt_bool FlashDone(void)
@ -387,7 +387,7 @@ blt_bool FlashDone(void)
return BLT_FALSE;
}
}
/* check if there is still data waiting to be programmed */
if (blockInfo.base_addr != FLASH_INVALID_ADDRESS)
{
@ -396,7 +396,7 @@ blt_bool FlashDone(void)
return BLT_FALSE;
}
}
/* still here so all is okay */
/* still here so all is okay */
return BLT_TRUE;
} /*** end of FlashDone ***/
@ -414,16 +414,16 @@ blt_addr FlashGetUserProgBaseAddress(void)
/************************************************************************************//**
** \brief Copies data currently in flash to the block->data and sets the
** \brief Copies data currently in flash to the block->data and sets the
** base address.
** \param block Pointer to flash block info structure to operate on.
** \param address Base address of the block data.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
static blt_bool FlashInitBlock(tFlashBlockInfo *block, blt_addr address)
{
/* check address alignment */
/* check address alignment */
if ((address % FLASH_WRITE_BLOCK_SIZE) != 0)
{
return BLT_FALSE;
@ -434,8 +434,8 @@ static blt_bool FlashInitBlock(tFlashBlockInfo *block, blt_addr address)
/* block already initialized, so nothing to do */
return BLT_TRUE;
}
/* set the base address and copies the current data from flash */
block->base_addr = address;
/* set the base address and copies the current data from flash */
block->base_addr = address;
CpuMemCopy((blt_addr)block->data, address, FLASH_WRITE_BLOCK_SIZE);
return BLT_TRUE;
} /*** end of FlashInitBlock ***/
@ -454,14 +454,14 @@ static tFlashBlockInfo *FlashSwitchBlock(tFlashBlockInfo *block, blt_addr base_a
{
/* check if a switch needs to be made away from the boot block. in this case the boot
* block shouldn't be written yet, because this is done at the end of the programming
* session by FlashDone(), this is right after the checksum was written.
* session by FlashDone(), this is right after the checksum was written.
*/
if (block == &bootBlockInfo)
{
/* switch from the boot block to the generic block info structure */
block = &blockInfo;
}
/* check if a switch back into the bootblock is needed. in this case the generic block
/* check if a switch back into the bootblock is needed. in this case the generic block
* doesn't need to be written here yet.
*/
else if (base_addr == flashLayout[0].sector_start)
@ -480,7 +480,7 @@ static tFlashBlockInfo *FlashSwitchBlock(tFlashBlockInfo *block, blt_addr base_a
}
/* initialize tne new block when necessary */
if (FlashInitBlock(block, base_addr) == BLT_FALSE)
if (FlashInitBlock(block, base_addr) == BLT_FALSE)
{
return BLT_NULL;
}
@ -502,13 +502,13 @@ static tFlashBlockInfo *FlashSwitchBlock(tFlashBlockInfo *block, blt_addr base_a
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
static blt_bool FlashAddToBlock(tFlashBlockInfo *block, blt_addr address,
static blt_bool FlashAddToBlock(tFlashBlockInfo *block, blt_addr address,
blt_int8u *data, blt_int32u len)
{
blt_addr current_base_addr;
blt_int8u *dst;
blt_int8u *src;
/* determine the current base address */
current_base_addr = (address/FLASH_WRITE_BLOCK_SIZE)*FLASH_WRITE_BLOCK_SIZE;
@ -532,7 +532,7 @@ static blt_bool FlashAddToBlock(tFlashBlockInfo *block, blt_addr address,
return BLT_FALSE;
}
}
/* add the data to the current block, but check for block overflow */
dst = &(block->data[address - block->base_addr]);
src = data;
@ -589,14 +589,14 @@ static blt_bool FlashWriteBlock(tFlashBlockInfo *block)
}
/* unlock the flash array */
FLASH_Unlock();
/* clear pending flags (if any) */
FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR |
FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR|FLASH_FLAG_PGSERR);
/* clear pending flags (if any) */
FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR |
FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR|FLASH_FLAG_PGSERR);
/* check that the flash peripheral is not busy */
if (FLASH_GetStatus() == FLASH_BUSY)
{
/* lock the flash array again */
FLASH_Lock();
FLASH_Lock();
/* could not perform erase operation */
return BLT_FALSE;
}
@ -604,7 +604,7 @@ static blt_bool FlashWriteBlock(tFlashBlockInfo *block)
for (word_cnt=0; word_cnt<(FLASH_WRITE_BLOCK_SIZE/sizeof(blt_int32u)); word_cnt++)
{
prog_addr = block->base_addr + (word_cnt * sizeof(blt_int32u));
prog_data = *(volatile blt_int32u*)(&block->data[word_cnt * sizeof(blt_int32u)]);
prog_data = *(volatile blt_int32u *)(&block->data[word_cnt * sizeof(blt_int32u)]);
/* keep the watchdog happy */
CopService();
/* program the word */
@ -614,14 +614,14 @@ static blt_bool FlashWriteBlock(tFlashBlockInfo *block)
break;
}
/* verify that the written data is actually there */
if (*(volatile blt_int32u*)prog_addr != prog_data)
if (*(volatile blt_int32u *)prog_addr != prog_data)
{
result = BLT_FALSE;
break;
}
}
/* lock the flash array again */
FLASH_Lock();
FLASH_Lock();
/* still here so all is okay */
return result;
} /*** end of FlashWriteBlock ***/
@ -643,21 +643,21 @@ static blt_bool FlashEraseSectors(blt_int8u first_sector, blt_int8u last_sector)
{
return BLT_FALSE;
}
if ( (first_sector < flashLayout[0].sector_num) || \
(last_sector > flashLayout[FLASH_TOTAL_SECTORS-1].sector_num) )
if ((first_sector < flashLayout[0].sector_num) || \
(last_sector > flashLayout[FLASH_TOTAL_SECTORS-1].sector_num))
{
return BLT_FALSE;
}
/* unlock the flash array */
FLASH_Unlock();
/* clear pending flags (if any) */
FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR |
FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR|FLASH_FLAG_PGSERR);
/* clear pending flags (if any) */
FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR |
FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR|FLASH_FLAG_PGSERR);
/* check that the flash peripheral is not busy */
if (FLASH_GetStatus() == FLASH_BUSY)
{
/* lock the flash array again */
FLASH_Lock();
FLASH_Lock();
/* could not perform erase operation */
return BLT_FALSE;
}
@ -670,13 +670,13 @@ static blt_bool FlashEraseSectors(blt_int8u first_sector, blt_int8u last_sector)
if (FLASH_EraseSector(flashSectorNumToMask[sector_cnt], VoltageRange_3) != FLASH_COMPLETE)
{
/* lock the flash array again */
FLASH_Lock();
FLASH_Lock();
/* could not perform erase operation */
return BLT_FALSE;
}
}
/* lock the flash array again */
FLASH_Lock();
FLASH_Lock();
/* still here so all went okay */
return BLT_TRUE;
} /*** end of FlashEraseSectors ***/
@ -691,16 +691,16 @@ static blt_bool FlashEraseSectors(blt_int8u first_sector, blt_int8u last_sector)
static blt_int8u FlashGetSector(blt_addr address)
{
blt_int8u sectorIdx;
/* search through the sectors to find the right one */
for (sectorIdx = 0; sectorIdx < FLASH_TOTAL_SECTORS; sectorIdx++)
{
/* keep the watchdog happy */
CopService();
/* is the address in this sector? */
if ( (address >= flashLayout[sectorIdx].sector_start) && \
(address < (flashLayout[sectorIdx].sector_start + \
flashLayout[sectorIdx].sector_size)) )
if ((address >= flashLayout[sectorIdx].sector_start) && \
(address < (flashLayout[sectorIdx].sector_start + \
flashLayout[sectorIdx].sector_size)))
{
/* return the sector number */
return flashLayout[sectorIdx].sector_num;

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
#ifndef FLASH_H

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -93,12 +93,12 @@ blt_bool NvmWrite(blt_addr addr, blt_int32u len, blt_int8u *data)
* by this driver.
*/
result = NvmWriteHook(addr, len, data);
/* process the return code */
if (result == BLT_NVM_OKAY)
{
/* data was within range of the additionally supported memory and succesfully
* programmed, so we are all done.
* programmed, so we are all done.
*/
return BLT_TRUE;
}
@ -134,12 +134,12 @@ blt_bool NvmErase(blt_addr addr, blt_int32u len)
* by this driver.
*/
result = NvmEraseHook(addr, len);
/* process the return code */
if (result == BLT_NVM_OKAY)
{
/* address was within range of the additionally supported memory and succesfully
* erased, so we are all done.
* erased, so we are all done.
*/
return BLT_TRUE;
}
@ -176,7 +176,7 @@ blt_bool NvmVerifyChecksum(void)
/************************************************************************************//**
** \brief Obtains the base address of the non-volatile memory available to the user
** \brief Obtains the base address of the non-volatile memory available to the user
** program. This is typically that start of the vector table.
** \return Base address.
**
@ -188,11 +188,11 @@ blt_addr NvmGetUserProgBaseAddress(void)
/************************************************************************************//**
** \brief Once all erase and programming operations are completed, this
** function is called, so at the end of the programming session and
** \brief Once all erase and programming operations are completed, this
** function is called, so at the end of the programming session and
** right before a software reset is performed. It is used to calculate
** a checksum and program this into flash. This checksum is later used
** to determine if a valid user program is present in flash.
** to determine if a valid user program is present in flash.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
#ifndef TYPES_H

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -85,15 +85,15 @@ void UartInit(void)
{
USART_InitTypeDef USART_InitStructure;
/* the current implementation supports USART1 - USART6. throw an assertion error in
* case a different UART channel is configured.
/* the current implementation supports USART1 - USART6. throw an assertion error in
* case a different UART channel is configured.
*/
ASSERT_CT((BOOT_COM_UART_CHANNEL_INDEX == 0) ||
(BOOT_COM_UART_CHANNEL_INDEX == 1) ||
(BOOT_COM_UART_CHANNEL_INDEX == 2) ||
(BOOT_COM_UART_CHANNEL_INDEX == 3) ||
(BOOT_COM_UART_CHANNEL_INDEX == 4) ||
(BOOT_COM_UART_CHANNEL_INDEX == 5));
(BOOT_COM_UART_CHANNEL_INDEX == 5));
/* initialize the uart for the specified communication speed */
USART_InitStructure.USART_BaudRate = BOOT_COM_UART_BAUDRATE;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
@ -117,15 +117,15 @@ void UartInit(void)
void UartTransmitPacket(blt_int8u *data, blt_int8u len)
{
blt_int16u data_index;
blt_bool result;
blt_bool result;
/* verify validity of the len-paramenter */
ASSERT_RT(len <= BOOT_COM_UART_TX_MAX_DATA);
ASSERT_RT(len <= BOOT_COM_UART_TX_MAX_DATA);
/* first transmit the length of the packet */
/* first transmit the length of the packet */
result = UartTransmitByte(len);
ASSERT_RT(result == BLT_TRUE);
ASSERT_RT(result == BLT_TRUE);
/* transmit all the packet bytes one-by-one */
for (data_index = 0; data_index < len; data_index++)
{
@ -133,7 +133,7 @@ void UartTransmitPacket(blt_int8u *data, blt_int8u len)
CopService();
/* write byte */
result = UartTransmitByte(data[data_index]);
ASSERT_RT(result == BLT_TRUE);
ASSERT_RT(result == BLT_TRUE);
}
} /*** end of UartTransmitPacket ***/
@ -180,7 +180,7 @@ blt_bool UartReceivePacket(blt_int8u *data)
if (xcpCtoRxLength == xcpCtoReqPacket[0])
{
/* copy the packet data */
CpuMemCopy((blt_int32u)data, (blt_int32u)&xcpCtoReqPacket[1], xcpCtoRxLength);
CpuMemCopy((blt_int32u)data, (blt_int32u)&xcpCtoReqPacket[1], xcpCtoRxLength);
/* done with cto packet reception */
xcpCtoRxInProgress = BLT_FALSE;
/* packet reception complete */
@ -242,8 +242,8 @@ static blt_bool UartTransmitByte(blt_int8u data)
/* write byte to transmit holding register */
USART_SendData(USART_CHANNEL, data);
/* wait for tx holding register to be empty */
while (USART_GetFlagStatus(USART_CHANNEL, USART_FLAG_TXE) == RESET)
{
while (USART_GetFlagStatus(USART_CHANNEL, USART_FLAG_TXE) == RESET)
{
;
}
/* byte transmitted */

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -69,7 +69,7 @@ typedef struct t_fifo_ctrl
blt_int8u *writeptr; /**< pointer to next free location */
blt_int8u length; /**< number of buffer elements */
blt_int8u entries; /**< # of full buffer elements */
blt_int8u handle; /**< handle of the buffer */
blt_int8u handle; /**< handle of the buffer */
struct t_fifo_ctrl *fifoctrlptr; /**< pointer to free buffer control */
} tFifoCtrl;
@ -122,15 +122,15 @@ void UsbInit(void)
fifoPipeBulkIN.handle = UsbFifoMgrCreate(fifoPipeBulkIN.data, FIFO_PIPE_SIZE);
fifoPipeBulkOUT.handle = UsbFifoMgrCreate(fifoPipeBulkOUT.data, FIFO_PIPE_SIZE);
/* validate fifo handles */
ASSERT_RT( (fifoPipeBulkIN.handle != FIFO_ERR_INVALID_HANDLE) && \
(fifoPipeBulkOUT.handle != FIFO_ERR_INVALID_HANDLE) );
ASSERT_RT((fifoPipeBulkIN.handle != FIFO_ERR_INVALID_HANDLE) && \
(fifoPipeBulkOUT.handle != FIFO_ERR_INVALID_HANDLE));
/* initialize the low level USB driver */
USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_bulk_cb, &USR_cb);
} /*** end of UsbInit ***/
/************************************************************************************//**
** \brief Releases the USB communication interface.
** \brief Releases the USB communication interface.
** \return none.
**
****************************************************************************************/
@ -156,12 +156,12 @@ void UsbTransmitPacket(blt_int8u *data, blt_int8u len)
blt_bool result;
/* verify validity of the len-paramenter */
ASSERT_RT(len <= BOOT_COM_USB_TX_MAX_DATA);
ASSERT_RT(len <= BOOT_COM_USB_TX_MAX_DATA);
/* first transmit the length of the packet */
/* first transmit the length of the packet */
result = UsbTransmitByte(len);
ASSERT_RT(result == BLT_TRUE);
ASSERT_RT(result == BLT_TRUE);
/* transmit all the packet bytes one-by-one */
for (data_index = 0; data_index < len; data_index++)
{
@ -169,7 +169,7 @@ void UsbTransmitPacket(blt_int8u *data, blt_int8u len)
CopService();
/* write byte */
result = UsbTransmitByte(data[data_index]);
ASSERT_RT(result == BLT_TRUE);
ASSERT_RT(result == BLT_TRUE);
}
} /*** end of UsbTransmitPacket ***/
@ -187,7 +187,7 @@ blt_bool UsbReceivePacket(blt_int8u *data)
static blt_bool xcpCtoRxInProgress = BLT_FALSE;
/* poll USB interrupt flags to process USB related events */
USBD_OTG_ISR_Handler (&USB_OTG_dev);
USBD_OTG_ISR_Handler(&USB_OTG_dev);
/* start of cto packet received? */
if (xcpCtoRxInProgress == BLT_FALSE)
@ -216,7 +216,7 @@ blt_bool UsbReceivePacket(blt_int8u *data)
if (xcpCtoRxLength == xcpCtoReqPacket[0])
{
/* copy the packet data */
CpuMemCopy((blt_int32u)data, (blt_int32u)&xcpCtoReqPacket[1], xcpCtoRxLength);
CpuMemCopy((blt_int32u)data, (blt_int32u)&xcpCtoReqPacket[1], xcpCtoRxLength);
/* done with cto packet reception */
xcpCtoRxInProgress = BLT_FALSE;
@ -239,7 +239,7 @@ blt_bool UsbReceivePacket(blt_int8u *data)
static blt_bool UsbReceiveByte(blt_int8u *data)
{
blt_bool result;
/* obtain data from the fifo */
result = UsbFifoMgrRead(fifoPipeBulkOUT.handle, data);
return result;
@ -255,7 +255,7 @@ static blt_bool UsbReceiveByte(blt_int8u *data)
static blt_bool UsbTransmitByte(blt_int8u data)
{
blt_bool result;
/* write data from to fifo */
result = UsbFifoMgrWrite(fifoPipeBulkIN.handle, data);
return result;
@ -296,7 +296,7 @@ void UsbTransmitPipeBulkIN(void)
result = UsbFifoMgrRead(fifoPipeBulkIN.handle, &byte_value);
ASSERT_RT(result == BLT_TRUE);
/* store it in the endpoint's RAM */
USB_Tx_Buffer[byte_counter] = byte_value;
USB_Tx_Buffer[byte_counter] = byte_value;
}
/* copy data to endpoint's RAM and start the transmission */
DCD_EP_Tx(&USB_OTG_dev, BULK_IN_EP, &USB_Tx_Buffer[0], nr_of_bytes_for_tx_endpoint);
@ -313,12 +313,12 @@ void UsbReceivePipeBulkOUT(uint8_t epnum)
uint16_t USB_Rx_Cnt=0;
uint16_t byte_counter;
blt_bool result;
/* Get the received data buffer and update the counter */
USB_Rx_Cnt = USB_OTG_dev.dev.out_ep[epnum].xfer_count;
/* USB data will be immediately processed, this allow next USB traffic being
* NAKed till the end of the USART Xfer
/* USB data will be immediately processed, this allow next USB traffic being
* NAKed till the end of the USART Xfer
*/
for (byte_counter=0; byte_counter<USB_Rx_Cnt; byte_counter++)
{
@ -394,7 +394,7 @@ static blt_int8u UsbFifoMgrCreate(blt_int8u *buffer, blt_int8u length)
pbc->writeptr = buffer;
pbc->entries = 0;
pbc->startptr = buffer;
pbc->endptr = (blt_int8u*)(buffer + length - 1);
pbc->endptr = (blt_int8u *)(buffer + length - 1);
/* return the handle to the successfully created fifo control */
return pbc->handle;
@ -430,7 +430,7 @@ static blt_bool UsbFifoMgrWrite(blt_int8u handle, blt_int8u data)
/* set write pointer to start of the cyclic fifo */
fifoCtrl[handle].writeptr = fifoCtrl[handle].startptr;
}
/* still here so all is okay */
/* still here so all is okay */
return BLT_TRUE;
} /*** end of UsbFifoMgrWrite ***/

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -40,7 +40,7 @@
/****************************************************************************************
* External functions
****************************************************************************************/
extern void reset_handler( void );
extern void reset_handler(void);
/****************************************************************************************
@ -51,7 +51,7 @@ typedef union
{
void (*func)(void); /**< for ISR function pointers */
void *ptr; /**< for stack pointer entry */
}tIsrFunc;
} tIsrFunc;
/************************************************************************************//**
@ -75,7 +75,7 @@ void UnusedISR(void)
/** \brief Interrupt vector table. */
__root const tIsrFunc __vector_table[] @ ".intvec" =
{
{ .ptr = __sfe( "CSTACK" ) }, /* the initial stack pointer */
{ .ptr = __sfe("CSTACK") }, /* the initial stack pointer */
{ &reset_handler }, /* the reset handler */
{ UnusedISR }, /* NMI Handler */
{ UnusedISR }, /* Hard Fault Handler */

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -45,7 +45,7 @@
/** \brief Pointer to the user program's vector table. */
#define CPU_USER_PROGRAM_VECTABLE_OFFSET ((blt_int32u)NvmGetUserProgBaseAddress())
/****************************************************************************************
* Register definitions
****************************************************************************************/
@ -69,7 +69,7 @@ extern void reset_handler(void); /* implemented in cstart.s
/************************************************************************************//**
** \brief Starts the user program, if one is present. In this case this function
** does not return.
** does not return.
** \return none.
**
****************************************************************************************/
@ -83,18 +83,18 @@ void CpuStartUserProgram(void)
/* not a valid user program so it cannot be started */
return;
}
#if (BOOT_CPU_USER_PROGRAM_START_HOOK > 0)
#if (BOOT_CPU_USER_PROGRAM_START_HOOK > 0)
/* invoke callback */
if (CpuUserProgramStartHook() == BLT_FALSE)
{
/* callback requests the user program to not be started */
return;
}
#endif
#if (BOOT_COM_ENABLE > 0)
#endif
#if (BOOT_COM_ENABLE > 0)
/* release the communication interface */
ComFree();
#endif
#endif
/* reset the timer */
TimerReset();
/* remap user program's vector table */
@ -103,7 +103,7 @@ void CpuStartUserProgram(void)
* the 2nd entry in the user program's vector table. this address points to the
* user program's reset handler.
*/
pProgResetHandler = (void(*)(void))(*((blt_addr*)CPU_USER_PROGRAM_STARTADDR_PTR));
pProgResetHandler = (void(*)(void))(*((blt_addr *)CPU_USER_PROGRAM_STARTADDR_PTR));
/* start the user program by activating its reset interrupt service routine */
pProgResetHandler();
} /*** end of CpuStartUserProgram ***/
@ -113,7 +113,7 @@ void CpuStartUserProgram(void)
** \brief Copies data from the source to the destination address.
** \param dest Destination address for the data.
** \param src Source address of the data.
** \param len length of the data in bytes.
** \param len length of the data in bytes.
** \return none.
**
****************************************************************************************/
@ -126,7 +126,7 @@ void CpuMemCopy(blt_addr dest, blt_addr src, blt_int16u len)
to = (blt_int8u *)dest;
/* copy all bytes from source address to destination address */
while(len-- > 0)
while (len-- > 0)
{
/* store byte value from source to destination */
*to++ = *from++;

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -63,7 +63,7 @@
* Type definitions
****************************************************************************************/
/** \brief Flash sector descriptor type. */
typedef struct
typedef struct
{
blt_addr sector_start; /**< sector start address */
blt_int32u sector_size; /**< sector size in bytes */
@ -71,10 +71,10 @@ typedef struct
} tFlashSector;
/** \brief Structure type for grouping flash block information.
* \details Programming is done per block of max FLASH_WRITE_BLOCK_SIZE. for this a
* \details Programming is done per block of max FLASH_WRITE_BLOCK_SIZE. for this a
* flash block manager is implemented in this driver. this flash block manager
* depends on this flash block info structure. It holds the base address of
* the flash block and the data that should be programmed into the flash
* depends on this flash block info structure. It holds the base address of
* the flash block and the data that should be programmed into the flash
* block. The .base_addr must be a multiple of FLASH_WRITE_BLOCK_SIZE.
*/
typedef struct
@ -89,7 +89,7 @@ typedef struct
****************************************************************************************/
static blt_bool FlashInitBlock(tFlashBlockInfo *block, blt_addr address);
static tFlashBlockInfo *FlashSwitchBlock(tFlashBlockInfo *block, blt_addr base_addr);
static blt_bool FlashAddToBlock(tFlashBlockInfo *block, blt_addr address,
static blt_bool FlashAddToBlock(tFlashBlockInfo *block, blt_addr address,
blt_int8u *data, blt_int32u len);
static blt_bool FlashWriteBlock(tFlashBlockInfo *block);
static blt_bool FlashEraseSectors(blt_int8u first_sector, blt_int8u last_sector);
@ -102,13 +102,13 @@ static blt_addr FlashGetSectorSize(blt_int8u sector);
* Local constant declarations
****************************************************************************************/
/** \brief Array wit the layout of the flash memory.
* \details Also controls what part of the flash memory is reserved for the bootloader.
* If the bootloader size changes, the reserved sectors for the bootloader
* \details Also controls what part of the flash memory is reserved for the bootloader.
* If the bootloader size changes, the reserved sectors for the bootloader
* might need adjustment to make sure the bootloader doesn't get overwritten.
* The current flash layout does not reflect the minimum sector size of the
* physical flash (1 - 2kb), because this would make the table quit long and
* a waste of ROM. The minimum sector size is only really needed when erasing
* the flash. This can still be done in combination with macro
* the flash. This can still be done in combination with macro
* FLASH_ERASE_BLOCK_SIZE.
*/
static const tFlashSector flashLayout[] =
@ -164,30 +164,30 @@ static const tFlashSector flashLayout[] =
****************************************************************************************/
/** \brief Local variable with information about the flash block that is currently
* being operated on.
* \details The smallest amount of flash that can be programmed is
* \details The smallest amount of flash that can be programmed is
* FLASH_WRITE_BLOCK_SIZE. A flash block manager is implemented in this driver
* and stores info in this variable. Whenever new data should be flashed, it
* is first added to a RAM buffer, which is part of this variable. Whenever
* the RAM buffer, which has the size of a flash block, is full or data needs
* to be written to a different block, the contents of the RAM buffer are
* programmed to flash. The flash block manager requires some software
* overhead, yet results is faster flash programming because data is first
* harvested, ideally until there is enough to program an entire flash block,
* to be written to a different block, the contents of the RAM buffer are
* programmed to flash. The flash block manager requires some software
* overhead, yet results is faster flash programming because data is first
* harvested, ideally until there is enough to program an entire flash block,
* before the flash device is actually operated on.
*/
static tFlashBlockInfo blockInfo;
/** \brief Local variable with information about the flash boot block.
* \details The first block of the user program holds the vector table, which on the
* STM32 is also the where the checksum is written to. Is it likely that
* \details The first block of the user program holds the vector table, which on the
* STM32 is also the where the checksum is written to. Is it likely that
* the vector table is first flashed and then, at the end of the programming
* sequence, the checksum. This means that this flash block need to be written
* to twice. Normally this is not a problem with flash memory, as long as you
* write the same values to those bytes that are not supposed to be changed
* write the same values to those bytes that are not supposed to be changed
* and the locations where you do write to are still in the erased 0xFF state.
* Unfortunately, writing twice to flash this way, does not work reliably on
* Unfortunately, writing twice to flash this way, does not work reliably on
* all micros. This is why we need to have an extra block, the bootblock,
* placed under the management of the block manager. This way is it possible
* placed under the management of the block manager. This way is it possible
* to implement functionality so that the bootblock is only written to once
* at the end of the programming sequence.
*/
@ -195,7 +195,7 @@ static tFlashBlockInfo bootBlockInfo;
/************************************************************************************//**
** \brief Initializes the flash driver.
** \brief Initializes the flash driver.
** \return none.
**
****************************************************************************************/
@ -209,12 +209,12 @@ void FlashInit(void)
/************************************************************************************//**
** \brief Writes the data to flash through a flash block manager. Note that this
** function also checks that no data is programmed outside the flash
** function also checks that no data is programmed outside the flash
** memory region, so the bootloader can never be overwritten.
** \param addr Start address.
** \param len Length in bytes.
** \param data Pointer to the data buffer.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
blt_bool FlashWrite(blt_addr addr, blt_int32u len, blt_int8u *data)
@ -222,10 +222,10 @@ blt_bool FlashWrite(blt_addr addr, blt_int32u len, blt_int8u *data)
blt_addr base_addr;
/* make sure the addresses are within the flash device */
if ( (FlashGetSector(addr) == FLASH_INVALID_SECTOR) || \
(FlashGetSector(addr+len-1) == FLASH_INVALID_SECTOR) )
if ((FlashGetSector(addr) == FLASH_INVALID_SECTOR) || \
(FlashGetSector(addr+len-1) == FLASH_INVALID_SECTOR))
{
return BLT_FALSE;
return BLT_FALSE;
}
/* if this is the bootblock, then let the boot block manager handle it */
@ -241,24 +241,24 @@ blt_bool FlashWrite(blt_addr addr, blt_int32u len, blt_int8u *data)
/************************************************************************************//**
** \brief Erases the flash memory. Note that this function also checks that no
** data is erased outside the flash memory region, so the bootloader can
** \brief Erases the flash memory. Note that this function also checks that no
** data is erased outside the flash memory region, so the bootloader can
** never be erased.
** \param addr Start address.
** \param len Length in bytes.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
blt_bool FlashErase(blt_addr addr, blt_int32u len)
{
blt_int8u first_sector;
blt_int8u last_sector;
/* obtain the first and last sector number */
first_sector = FlashGetSector(addr);
last_sector = FlashGetSector(addr+len-1);
/* check them */
if ( (first_sector == FLASH_INVALID_SECTOR) || (last_sector == FLASH_INVALID_SECTOR) )
if ((first_sector == FLASH_INVALID_SECTOR) || (last_sector == FLASH_INVALID_SECTOR))
{
return BLT_FALSE;
}
@ -273,27 +273,27 @@ blt_bool FlashErase(blt_addr addr, blt_int32u len)
** the checksum, the bootloader can check if the programming session
** was completed, which indicates that a valid user programming is
** present and can be started.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
blt_bool FlashWriteChecksum(void)
{
blt_int32u signature_checksum = 0;
/* for the TM4C target we defined the checksum as the Two's complement value of the
* sum of the first 7 exception addresses.
*
* Layout of the vector table:
* 0x00000000 Initial stack pointer
* 0x00000000 Initial stack pointer
* 0x00000004 Reset Handler
* 0x00000008 NMI Handler
* 0x0000000C Hard Fault Handler
* 0x00000010 MPU Fault Handler
* 0x00000010 MPU Fault Handler
* 0x00000014 Bus Fault Handler
* 0x00000018 Usage Fault Handler
*
* signature_checksum = Two's complement of (SUM(exception address values))
*
*
* the bootloader writes this 32-bit checksum value right after the vector table
* of the user program. note that this means one extra dummy entry must be added
* at the end of the user program's vector table to reserve storage space for the
@ -304,49 +304,49 @@ blt_bool FlashWriteChecksum(void)
* bootblock is not part of the reprogramming this time and therefore no
* new checksum needs to be written
*/
if (bootBlockInfo.base_addr == FLASH_INVALID_ADDRESS)
{
if (bootBlockInfo.base_addr == FLASH_INVALID_ADDRESS)
{
return BLT_TRUE;
}
}
/* compute the checksum. note that the user program's vectors are not yet written
* to flash but are present in the bootblock data structure at this point.
*/
signature_checksum += *((blt_int32u*)(&bootBlockInfo.data[0+0x00]));
signature_checksum += *((blt_int32u*)(&bootBlockInfo.data[0+0x04]));
signature_checksum += *((blt_int32u*)(&bootBlockInfo.data[0+0x08]));
signature_checksum += *((blt_int32u*)(&bootBlockInfo.data[0+0x0C]));
signature_checksum += *((blt_int32u*)(&bootBlockInfo.data[0+0x10]));
signature_checksum += *((blt_int32u*)(&bootBlockInfo.data[0+0x14]));
signature_checksum += *((blt_int32u*)(&bootBlockInfo.data[0+0x18]));
signature_checksum += *((blt_int32u *)(&bootBlockInfo.data[0+0x00]));
signature_checksum += *((blt_int32u *)(&bootBlockInfo.data[0+0x04]));
signature_checksum += *((blt_int32u *)(&bootBlockInfo.data[0+0x08]));
signature_checksum += *((blt_int32u *)(&bootBlockInfo.data[0+0x0C]));
signature_checksum += *((blt_int32u *)(&bootBlockInfo.data[0+0x10]));
signature_checksum += *((blt_int32u *)(&bootBlockInfo.data[0+0x14]));
signature_checksum += *((blt_int32u *)(&bootBlockInfo.data[0+0x18]));
signature_checksum = ~signature_checksum; /* one's complement */
signature_checksum += 1; /* two's complement */
/* write the checksum */
return FlashWrite(flashLayout[0].sector_start+FLASH_VECTOR_TABLE_CS_OFFSET,
sizeof(blt_addr), (blt_int8u*)&signature_checksum);
return FlashWrite(flashLayout[0].sector_start+FLASH_VECTOR_TABLE_CS_OFFSET,
sizeof(blt_addr), (blt_int8u *)&signature_checksum);
} /*** end of FlashWriteChecksum ***/
/************************************************************************************//**
** \brief Verifies the checksum, which indicates that a valid user program is
** present and can be started.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
blt_bool FlashVerifyChecksum(void)
{
blt_int32u signature_checksum = 0;
/* verify the checksum based on how it was written by CpuWriteChecksum() */
signature_checksum += *((blt_int32u*)(flashLayout[0].sector_start));
signature_checksum += *((blt_int32u*)(flashLayout[0].sector_start+0x04));
signature_checksum += *((blt_int32u*)(flashLayout[0].sector_start+0x08));
signature_checksum += *((blt_int32u*)(flashLayout[0].sector_start+0x0C));
signature_checksum += *((blt_int32u*)(flashLayout[0].sector_start+0x10));
signature_checksum += *((blt_int32u*)(flashLayout[0].sector_start+0x14));
signature_checksum += *((blt_int32u*)(flashLayout[0].sector_start+0x18));
signature_checksum += *((blt_int32u*)(flashLayout[0].sector_start+FLASH_VECTOR_TABLE_CS_OFFSET));
signature_checksum += *((blt_int32u *)(flashLayout[0].sector_start));
signature_checksum += *((blt_int32u *)(flashLayout[0].sector_start+0x04));
signature_checksum += *((blt_int32u *)(flashLayout[0].sector_start+0x08));
signature_checksum += *((blt_int32u *)(flashLayout[0].sector_start+0x0C));
signature_checksum += *((blt_int32u *)(flashLayout[0].sector_start+0x10));
signature_checksum += *((blt_int32u *)(flashLayout[0].sector_start+0x14));
signature_checksum += *((blt_int32u *)(flashLayout[0].sector_start+0x18));
signature_checksum += *((blt_int32u *)(flashLayout[0].sector_start+FLASH_VECTOR_TABLE_CS_OFFSET));
/* sum should add up to an unsigned 32-bit value of 0 */
if (signature_checksum == 0)
{
@ -361,7 +361,7 @@ blt_bool FlashVerifyChecksum(void)
/************************************************************************************//**
** \brief Finalizes the flash driver operations. There could still be data in
** the currently active block that needs to be flashed.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
blt_bool FlashDone(void)
@ -374,7 +374,7 @@ blt_bool FlashDone(void)
return BLT_FALSE;
}
}
/* check if there is still data waiting to be programmed */
if (blockInfo.base_addr != FLASH_INVALID_ADDRESS)
{
@ -383,7 +383,7 @@ blt_bool FlashDone(void)
return BLT_FALSE;
}
}
/* still here so all is okay */
/* still here so all is okay */
return BLT_TRUE;
} /*** end of FlashDone ***/
@ -401,16 +401,16 @@ blt_addr FlashGetUserProgBaseAddress(void)
/************************************************************************************//**
** \brief Copies data currently in flash to the block->data and sets the
** \brief Copies data currently in flash to the block->data and sets the
** base address.
** \param block Pointer to flash block info structure to operate on.
** \param address Base address of the block data.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
static blt_bool FlashInitBlock(tFlashBlockInfo *block, blt_addr address)
{
/* check address alignment */
/* check address alignment */
if ((address % FLASH_WRITE_BLOCK_SIZE) != 0)
{
return BLT_FALSE;
@ -421,8 +421,8 @@ static blt_bool FlashInitBlock(tFlashBlockInfo *block, blt_addr address)
/* block already initialized, so nothing to do */
return BLT_TRUE;
}
/* set the base address and copies the current data from flash */
block->base_addr = address;
/* set the base address and copies the current data from flash */
block->base_addr = address;
CpuMemCopy((blt_addr)block->data, address, FLASH_WRITE_BLOCK_SIZE);
return BLT_TRUE;
} /*** end of FlashInitBlock ***/
@ -441,14 +441,14 @@ static tFlashBlockInfo *FlashSwitchBlock(tFlashBlockInfo *block, blt_addr base_a
{
/* check if a switch needs to be made away from the boot block. in this case the boot
* block shouldn't be written yet, because this is done at the end of the programming
* session by FlashDone(), this is right after the checksum was written.
* session by FlashDone(), this is right after the checksum was written.
*/
if (block == &bootBlockInfo)
{
/* switch from the boot block to the generic block info structure */
block = &blockInfo;
}
/* check if a switch back into the bootblock is needed. in this case the generic block
/* check if a switch back into the bootblock is needed. in this case the generic block
* doesn't need to be written here yet.
*/
else if (base_addr == flashLayout[0].sector_start)
@ -467,7 +467,7 @@ static tFlashBlockInfo *FlashSwitchBlock(tFlashBlockInfo *block, blt_addr base_a
}
/* initialize tne new block when necessary */
if (FlashInitBlock(block, base_addr) == BLT_FALSE)
if (FlashInitBlock(block, base_addr) == BLT_FALSE)
{
return BLT_NULL;
}
@ -489,13 +489,13 @@ static tFlashBlockInfo *FlashSwitchBlock(tFlashBlockInfo *block, blt_addr base_a
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
static blt_bool FlashAddToBlock(tFlashBlockInfo *block, blt_addr address,
static blt_bool FlashAddToBlock(tFlashBlockInfo *block, blt_addr address,
blt_int8u *data, blt_int32u len)
{
blt_addr current_base_addr;
blt_int8u *dst;
blt_int8u *src;
/* determine the current base address */
current_base_addr = (address/FLASH_WRITE_BLOCK_SIZE)*FLASH_WRITE_BLOCK_SIZE;
@ -519,7 +519,7 @@ static blt_bool FlashAddToBlock(tFlashBlockInfo *block, blt_addr address,
return BLT_FALSE;
}
}
/* add the data to the current block, but check for block overflow */
dst = &(block->data[address - block->base_addr]);
src = data;
@ -574,12 +574,12 @@ static blt_bool FlashWriteBlock(tFlashBlockInfo *block)
{
return BLT_FALSE;
}
/* program all words in the block one by one */
for (word_cnt=0; word_cnt<(FLASH_WRITE_BLOCK_SIZE/sizeof(blt_int32u)); word_cnt++)
{
prog_addr = block->base_addr + (word_cnt * sizeof(blt_int32u));
prog_data = *(volatile blt_int32u*)(&block->data[word_cnt * sizeof(blt_int32u)]);
prog_data = *(volatile blt_int32u *)(&block->data[word_cnt * sizeof(blt_int32u)]);
/* keep the watchdog happy */
CopService();
/* program the word to flash */
@ -589,7 +589,7 @@ static blt_bool FlashWriteBlock(tFlashBlockInfo *block)
break;
}
/* verify that the written data is actually there */
if (*(volatile blt_int32u*)prog_addr != prog_data)
if (*(volatile blt_int32u *)prog_addr != prog_data)
{
result = BLT_FALSE;
break;
@ -619,12 +619,12 @@ static blt_bool FlashEraseSectors(blt_int8u first_sector, blt_int8u last_sector)
{
return BLT_FALSE;
}
if ( (first_sector < flashLayout[0].sector_num) || \
(last_sector > flashLayout[FLASH_TOTAL_SECTORS-1].sector_num) )
if ((first_sector < flashLayout[0].sector_num) || \
(last_sector > flashLayout[FLASH_TOTAL_SECTORS-1].sector_num))
{
return BLT_FALSE;
}
/* determine how many blocks need to be erased */
start_addr = FlashGetSectorBaseAddr(first_sector);
end_addr = FlashGetSectorBaseAddr(last_sector) + FlashGetSectorSize(last_sector) - 1;
@ -655,16 +655,16 @@ static blt_bool FlashEraseSectors(blt_int8u first_sector, blt_int8u last_sector)
static blt_int8u FlashGetSector(blt_addr address)
{
blt_int8u sectorIdx;
/* search through the sectors to find the right one */
for (sectorIdx = 0; sectorIdx < FLASH_TOTAL_SECTORS; sectorIdx++)
{
/* keep the watchdog happy */
CopService();
/* is the address in this sector? */
if ( (address >= flashLayout[sectorIdx].sector_start) && \
(address < (flashLayout[sectorIdx].sector_start + \
flashLayout[sectorIdx].sector_size)) )
if ((address >= flashLayout[sectorIdx].sector_start) && \
(address < (flashLayout[sectorIdx].sector_start + \
flashLayout[sectorIdx].sector_size)))
{
/* return the sector number */
return flashLayout[sectorIdx].sector_num;
@ -684,7 +684,7 @@ static blt_int8u FlashGetSector(blt_addr address)
static blt_addr FlashGetSectorBaseAddr(blt_int8u sector)
{
blt_int8u sectorIdx;
/* search through the sectors to find the right one */
for (sectorIdx = 0; sectorIdx < FLASH_TOTAL_SECTORS; sectorIdx++)
{
@ -709,7 +709,7 @@ static blt_addr FlashGetSectorBaseAddr(blt_int8u sector)
static blt_addr FlashGetSectorSize(blt_int8u sector)
{
blt_int8u sectorIdx;
/* search through the sectors to find the right one */
for (sectorIdx = 0; sectorIdx < FLASH_TOTAL_SECTORS; sectorIdx++)
{

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
#ifndef FLASH_H

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -93,12 +93,12 @@ blt_bool NvmWrite(blt_addr addr, blt_int32u len, blt_int8u *data)
* by this driver.
*/
result = NvmWriteHook(addr, len, data);
/* process the return code */
if (result == BLT_NVM_OKAY)
{
/* data was within range of the additionally supported memory and succesfully
* programmed, so we are all done.
* programmed, so we are all done.
*/
return BLT_TRUE;
}
@ -134,12 +134,12 @@ blt_bool NvmErase(blt_addr addr, blt_int32u len)
* by this driver.
*/
result = NvmEraseHook(addr, len);
/* process the return code */
if (result == BLT_NVM_OKAY)
{
/* address was within range of the additionally supported memory and succesfully
* erased, so we are all done.
* erased, so we are all done.
*/
return BLT_TRUE;
}
@ -176,7 +176,7 @@ blt_bool NvmVerifyChecksum(void)
/************************************************************************************//**
** \brief Obtains the base address of the non-volatile memory available to the user
** \brief Obtains the base address of the non-volatile memory available to the user
** program. This is typically that start of the vector table.
** \return Base address.
**
@ -188,11 +188,11 @@ blt_addr NvmGetUserProgBaseAddress(void)
/************************************************************************************//**
** \brief Once all erase and programming operations are completed, this
** function is called, so at the end of the programming session and
** \brief Once all erase and programming operations are completed, this
** function is called, so at the end of the programming session and
** right before a software reset is performed. It is used to calculate
** a checksum and program this into flash. This checksum is later used
** to determine if a valid user program is present in flash.
** to determine if a valid user program is present in flash.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
#ifndef TYPES_H

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -69,16 +69,16 @@ static blt_bool UartTransmitByte(blt_int8u data);
****************************************************************************************/
void UartInit(void)
{
/* the current implementation supports UART0. throw an assertion error in case a
* different UART channel is configured.
/* the current implementation supports UART0. throw an assertion error in case a
* different UART channel is configured.
*/
ASSERT_CT(BOOT_COM_UART_CHANNEL_INDEX == 0);
ASSERT_CT(BOOT_COM_UART_CHANNEL_INDEX == 0);
/* enable the UART0 peripheral */
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
/* configure the UART0 baudrate and communication parameters */
UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), BOOT_COM_UART_BAUDRATE,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE));
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE));
} /*** end of UartInit ***/
@ -95,12 +95,12 @@ void UartTransmitPacket(blt_int8u *data, blt_int8u len)
blt_bool result;
/* verify validity of the len-paramenter */
ASSERT_RT(len <= BOOT_COM_UART_TX_MAX_DATA);
ASSERT_RT(len <= BOOT_COM_UART_TX_MAX_DATA);
/* first transmit the length of the packet */
/* first transmit the length of the packet */
result = UartTransmitByte(len);
ASSERT_RT(result == BLT_TRUE);
ASSERT_RT(result == BLT_TRUE);
/* transmit all the packet bytes one-by-one */
for (data_index = 0; data_index < len; data_index++)
{
@ -108,7 +108,7 @@ void UartTransmitPacket(blt_int8u *data, blt_int8u len)
CopService();
/* write byte */
result = UartTransmitByte(data[data_index]);
ASSERT_RT(result == BLT_TRUE);
ASSERT_RT(result == BLT_TRUE);
}
} /*** end of UartTransmitPacket ***/
@ -155,7 +155,7 @@ blt_bool UartReceivePacket(blt_int8u *data)
if (xcpCtoRxLength == xcpCtoReqPacket[0])
{
/* copy the packet data */
CpuMemCopy((blt_int32u)data, (blt_int32u)&xcpCtoReqPacket[1], xcpCtoRxLength);
CpuMemCopy((blt_int32u)data, (blt_int32u)&xcpCtoReqPacket[1], xcpCtoRxLength);
/* done with cto packet reception */
xcpCtoRxInProgress = BLT_FALSE;
/* packet reception complete */
@ -192,7 +192,7 @@ static blt_bool UartReceiveByte(blt_int8u *data)
/* try to read a newly received byte */
result = UARTCharGetNonBlocking(UART0_BASE);
/* check if a new byte was received */
if(result != -1)
if (result != -1)
{
/* store the received byte */
data[0] = (blt_int8u)result;
@ -219,8 +219,8 @@ static blt_bool UartTransmitByte(blt_int8u data)
return BLT_FALSE;
}
/* wait for tx holding register to be empty */
while(UARTSpaceAvail(UART0_BASE) == false)
{
while (UARTSpaceAvail(UART0_BASE) == false)
{
/* keep the watchdog happy */
CopService();
}

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -67,7 +67,7 @@ typedef struct t_fifo_ctrl
blt_int8u *writeptr; /**< pointer to next free location */
blt_int8u length; /**< number of buffer elements */
blt_int8u entries; /**< # of full buffer elements */
blt_int8u handle; /**< handle of the buffer */
blt_int8u handle; /**< handle of the buffer */
struct t_fifo_ctrl *fifoctrlptr; /**< pointer to free buffer control */
} tFifoCtrl;
@ -129,8 +129,8 @@ void UsbInit(void)
fifoPipeBulkIN.handle = UsbFifoMgrCreate(fifoPipeBulkIN.data, FIFO_PIPE_SIZE);
fifoPipeBulkOUT.handle = UsbFifoMgrCreate(fifoPipeBulkOUT.data, FIFO_PIPE_SIZE);
/* validate fifo handles */
ASSERT_RT( (fifoPipeBulkIN.handle != FIFO_ERR_INVALID_HANDLE) && \
(fifoPipeBulkOUT.handle != FIFO_ERR_INVALID_HANDLE) );
ASSERT_RT((fifoPipeBulkIN.handle != FIFO_ERR_INVALID_HANDLE) && \
(fifoPipeBulkOUT.handle != FIFO_ERR_INVALID_HANDLE));
/* initialize the transmit and receive buffers */
USBBufferInit(&g_sTxBuffer);
USBBufferInit(&g_sRxBuffer);
@ -141,7 +141,7 @@ void UsbInit(void)
/************************************************************************************//**
** \brief Releases the USB communication interface.
** \brief Releases the USB communication interface.
** \return none.
**
****************************************************************************************/
@ -167,12 +167,12 @@ void UsbTransmitPacket(blt_int8u *data, blt_int8u len)
blt_bool result;
/* verify validity of the len-parameter */
ASSERT_RT(len <= BOOT_COM_USB_TX_MAX_DATA);
ASSERT_RT(len <= BOOT_COM_USB_TX_MAX_DATA);
/* first transmit the length of the packet */
/* first transmit the length of the packet */
result = UsbTransmitByte(len);
ASSERT_RT(result == BLT_TRUE);
ASSERT_RT(result == BLT_TRUE);
/* transmit all the packet bytes one-by-one */
for (data_index = 0; data_index < len; data_index++)
{
@ -180,9 +180,9 @@ void UsbTransmitPacket(blt_int8u *data, blt_int8u len)
CopService();
/* write byte */
result = UsbTransmitByte(data[data_index]);
ASSERT_RT(result == BLT_TRUE);
ASSERT_RT(result == BLT_TRUE);
}
/* start the transmission */
UsbTransmitPipeBulkIN();
} /*** end of UsbTransmitPacket ***/
@ -202,7 +202,7 @@ blt_bool UsbReceivePacket(blt_int8u *data)
/* poll for USB events */
USB0DeviceIntHandler();
/* start of cto packet received? */
if (xcpCtoRxInProgress == BLT_FALSE)
{
@ -230,7 +230,7 @@ blt_bool UsbReceivePacket(blt_int8u *data)
if (xcpCtoRxLength == xcpCtoReqPacket[0])
{
/* copy the packet data */
CpuMemCopy((blt_int32u)data, (blt_int32u)&xcpCtoReqPacket[1], xcpCtoRxLength);
CpuMemCopy((blt_int32u)data, (blt_int32u)&xcpCtoReqPacket[1], xcpCtoRxLength);
/* done with cto packet reception */
xcpCtoRxInProgress = BLT_FALSE;
@ -253,7 +253,7 @@ blt_bool UsbReceivePacket(blt_int8u *data)
static blt_bool UsbReceiveByte(blt_int8u *data)
{
blt_bool result;
/* obtain data from the fifo */
result = UsbFifoMgrRead(fifoPipeBulkOUT.handle, data);
return result;
@ -269,7 +269,7 @@ static blt_bool UsbReceiveByte(blt_int8u *data)
static blt_bool UsbTransmitByte(blt_int8u data)
{
blt_bool result;
/* write data from to fifo */
result = UsbFifoMgrWrite(fifoPipeBulkIN.handle, data);
return result;
@ -291,7 +291,7 @@ static void UsbTransmitPipeBulkIN(void)
blt_int8u byte_counter;
blt_int8u byte_value;
blt_bool result;
/* read how many bytes should be transmitted */
nr_of_bytes_for_tx_endpoint = UsbFifoMgrScan(fifoPipeBulkIN.handle);
/* only continue if there is actually data left to transmit */
@ -343,11 +343,11 @@ static void UsbReceivePipeBulkOUT(blt_int8u *data, blt_int32u len)
blt_int32u byte_counter;
blt_bool result;
blt_int32u rxReadIdx;
/* determine read index for the rx buffer */
rxReadIdx = (uint32_t)(data - g_pui8USBRxBuffer);
/* store the received data in the reception fifo */
for (byte_counter=0; byte_counter<len; byte_counter++)
{
@ -377,7 +377,7 @@ static void UsbReceivePipeBulkOUT(blt_int8u *data, blt_int32u len)
****************************************************************************************/
uint32_t UsbBulkTxHandler(void *pvCBData, uint32_t ui32Event, uint32_t ui32MsgValue, void *pvMsgData)
{
if(ui32Event == USB_EVENT_TX_COMPLETE)
if (ui32Event == USB_EVENT_TX_COMPLETE)
{
/* check if more data is waiting to be transmitted */
UsbTransmitPipeBulkIN();
@ -399,7 +399,7 @@ uint32_t UsbBulkTxHandler(void *pvCBData, uint32_t ui32Event, uint32_t ui32MsgVa
uint32_t UsbBulkRxHandler(void *pvCBData, uint32_t ui32Event, uint32_t ui32MsgValue, void *pvMsgData)
{
/* which event are we being sent? */
switch(ui32Event)
switch (ui32Event)
{
/* we are connected to a host and communication is now possible */
case USB_EVENT_CONNECTED:
@ -504,7 +504,7 @@ static blt_int8u UsbFifoMgrCreate(blt_int8u *buffer, blt_int8u length)
pbc->writeptr = buffer;
pbc->entries = 0;
pbc->startptr = buffer;
pbc->endptr = (blt_int8u*)(buffer + length - 1);
pbc->endptr = (blt_int8u *)(buffer + length - 1);
/* return the handle to the successfully created fifo control */
return pbc->handle;
@ -540,7 +540,7 @@ static blt_bool UsbFifoMgrWrite(blt_int8u handle, blt_int8u data)
/* set write pointer to start of the cyclic fifo */
fifoCtrl[handle].writeptr = fifoCtrl[handle].startptr;
}
/* still here so all is okay */
/* still here so all is okay */
return BLT_TRUE;
} /*** end of UsbFifoMgrWrite ***/

View File

@ -17,7 +17,7 @@ Note: C++ destructors of global objects are NOT yet supported in the HIWARE Obje
/*#define __BANKED_COPY_DOWN : allow to allocate .copy in flash area */
#if defined(__BANKED_COPY_DOWN) && (!defined(__HCS12X__) || !defined(__ELF_OBJECT_FILE_FORMAT__))
#error /* the __BANKED_COPY_DOWN switch is only supported for the HCS12X with ELF */
/* (and not for the HC12, HCS12 or for the HIWARE object file format) */
/* (and not for the HC12, HCS12 or for the HIWARE object file format) */
#endif
#include "hidef.h"
@ -49,7 +49,7 @@ Note: C++ destructors of global objects are NOT yet supported in the HIWARE Obje
/* by default, the startup code assumes that the startup data structure */
/* _startupData, the zero out areas and the .copy section are all */
/* allocated in NON_BANKED memory. Especially the .copy section can be */
/* huge if there are many or huge RAM areas to initialize. */
/* huge if there are many or huge RAM areas to initialize. */
/* For the HCS12X, which also copies the XGATE RAM located code via .copy */
/* section, the startup code supports to allocate .copy in a banked flash */
/* The placement of .copy in the prm file has to be adapted when adding or */
@ -71,8 +71,8 @@ __EXTERN_C void main(void); /* prototype of main function */
#pragma DATA_SEG __NEAR_SEG STARTUP_DATA /* _startupData can be accessed using 16 bit accesses. */
/* This is needed because it contains the stack top, and without stack, far data cannot be accessed */
struct _tagStartup _startupData; /* read-only: */
/* _startupData is allocated in ROM and */
/* initialized by the linker */
/* _startupData is allocated in ROM and */
/* initialized by the linker */
#pragma DATA_SEG DEFAULT
#endif /* __ONLY_INIT_SP */
@ -86,8 +86,8 @@ struct _tagStartup _startupData; /* read-only: */
/*lint -esym(752,_SET_PAGE) , symbol '_SET_PAGE' is referenced in HLI */
__EXTERN_C void _SET_PAGE(void); /* the inline assembler needs a prototype */
/* this is a runtime routine with a special */
/* calling convention, do not use it in c code! */
/* this is a runtime routine with a special */
/* calling convention, do not use it in c code! */
#else
/*lint -e451 default.sgm contains a conditionally compiled CODE_SEG pragma */
#include "default.sgm"
@ -127,198 +127,300 @@ static void __far Init(void)
#else
static void Init(void)
#endif
{
/* purpose: 1) zero out RAM-areas where data is allocated */
/* 2) copy initialization data from ROM to RAM */
/* 3) call global constructors in C++ */
/* called from: _Startup, LibInits */
asm {
ZeroOut:
{
/* purpose: 1) zero out RAM-areas where data is allocated */
/* 2) copy initialization data from ROM to RAM */
/* 3) call global constructors in C++ */
/* called from: _Startup, LibInits */
asm
{
ZeroOut:
#if defined(__HIWARE_OBJECT_FILE_FORMAT__) && defined(__LARGE__)
LDX _startupData.pZeroOut:1 ; in the large memory model in the HIWARE format, pZeroOut is a 24 bit pointer
LDX _startupData.pZeroOut:1 ;
in the large memory model in the HIWARE format, pZeroOut is a 24 bit pointer
#else
LDX _startupData.pZeroOut ; *pZeroOut
LDX _startupData.pZeroOut ;
*pZeroOut
#endif
LDY _startupData.nofZeroOuts ; nofZeroOuts
BEQ CopyDown ; if nothing to zero out
LDY _startupData.nofZeroOuts ;
nofZeroOuts
BEQ CopyDown ;
if nothing to zero out
NextZeroOut: PSHY ; save nofZeroOuts
NextZeroOut: PSHY ;
save nofZeroOuts
#if defined(FAR_DATA)
LDAB 1,X+ ; load page of destination address
LDY 2,X+ ; load offset of destination address
LDAB 1,X+ ;
load page of destination address
LDY 2,X+ ;
load offset of destination address
#if defined(__HCS12X__)
STAB __GPAGE_ADR__
STAB __GPAGE_ADR__
#else /* defined(__HCS12X__) */
__PIC_JSR(_SET_PAGE) ; sets the page in the correct page register
__PIC_JSR(_SET_PAGE) ;
sets the page in the correct page register
#endif /* defined(__HCS12X__) */
#else /* FAR_DATA */
LDY 2,X+ ; start address and advance *pZeroOut (X = X+4)
LDY 2,X+ ;
start address and advance *pZeroOut(X = X+4)
#endif /* FAR_DATA */
#if defined(__HCS12X__) && defined(FAR_DATA)
PSHX
LDX 0,X ; byte count
PSHX
LDX 0,X ;
byte count
#if defined(__OPTIMIZE_FOR_SIZE__)
CLRA
NextWord: GSTAA 1,Y+ ; clear memory byte
__FEED_COP_IN_HLI() ; feed the COP if necessary /*lint !e505 !e522 asm code */
DBNE X, NextWord ; dec byte count
CLRA
NextWord:
GSTAA 1,Y+ ;
clear memory byte
__FEED_COP_IN_HLI() ;
feed the COP if necessary /*lint !e505 !e522 asm code */
DBNE X, NextWord ;
dec byte count
#else
LDD #0
LSRX
BEQ LoopClrW1 ; do we copy more than 1 byte?
NextWord: GSTD 2,Y+ ; clear memory word
__FEED_COP_IN_HLI() ; feed the COP if necessary /*lint !e505 !e522 asm code */
DBNE X, NextWord ; dec word count
LDD #0
LSRX
BEQ LoopClrW1 ;
do we copy more than 1 byte?
NextWord: GSTD 2,Y+ ;
clear memory word
__FEED_COP_IN_HLI() ;
feed the COP if necessary /*lint !e505 !e522 asm code */
DBNE X, NextWord ;
dec word count
LoopClrW1:
BCC LastClr ; handle last byte
GSTAA 1,Y+ ; handle last byte
BCC LastClr ;
handle last byte
GSTAA 1,Y+ ;
handle last byte
LastClr:
#endif
PULX
LEAX 2,X
PULX
LEAX 2,X
#elif defined(__OPTIMIZE_FOR_SIZE__) /* -os, default */
LDD 2,X+ ; byte count
NextWord: CLR 1,Y+ ; clear memory byte
__FEED_COP_IN_HLI() ; feed the COP if necessary /*lint !e505 !e522 asm code */
DBNE D, NextWord ; dec byte count
LDD 2,X+ ;
byte count
NextWord:
CLR 1,Y+ ;
clear memory byte
__FEED_COP_IN_HLI() ;
feed the COP if necessary /*lint !e505 !e522 asm code */
DBNE D, NextWord ;
dec byte count
#else /* __OPTIMIZE_FOR_TIME__ */
LDD 2,X+ ; byte count
LSRD ; /2 and save bit 0 in the carry
BEQ LoopClrW1 ; do we copy more than 1 byte?
PSHX
LDX #0
LoopClrW: STX 2,Y+ ; Word-Clear
__FEED_COP_IN_HLI() ; feed the COP if necessary /*lint !e505 !e522 asm code */
DBNE D, LoopClrW
PULX
LDD 2,X+ ;
byte count
LSRD ;
/2 and save bit 0 in the carry
BEQ LoopClrW1 ;
do we copy more than 1 byte?
PSHX
LDX #0
LoopClrW: STX 2,Y+ ;
Word-Clear
__FEED_COP_IN_HLI() ;
feed the COP if necessary /*lint !e505 !e522 asm code */
DBNE D, LoopClrW
PULX
LoopClrW1:
BCC LastClr ; handle last byte
CLR 1,Y+
BCC LastClr ;
handle last byte
CLR 1,Y+
LastClr:
#endif /* __OPTIMIZE_FOR_SIZE__/__OPTIMIZE_FOR_TIME__ */
PULY ; restore nofZeroOuts
DEY ; dec nofZeroOuts
BNE NextZeroOut
PULY ;
restore nofZeroOuts
DEY ;
dec nofZeroOuts
BNE NextZeroOut
CopyDown:
#if defined(__BANKED_COPY_DOWN)
LDAA _startupData.toCopyDownBeg:0 ; get PAGE address of .copy section
STAA __PPAGE_ADR__ ; set PPAGE address
LDX _startupData.toCopyDownBeg:1 ; load address of copy down desc.
LDAA _startupData.toCopyDownBeg:0 ;
get PAGE address of .copy section
STAA __PPAGE_ADR__ ;
set PPAGE address
LDX _startupData.toCopyDownBeg:1 ;
load address of copy down desc.
#elif defined(__ELF_OBJECT_FILE_FORMAT__)
LDX _startupData.toCopyDownBeg ; load address of copy down desc.
LDX _startupData.toCopyDownBeg ;
load address of copy down desc.
#else
LDX _startupData.toCopyDownBeg:2 ; load address of copy down desc.
LDX _startupData.toCopyDownBeg:2 ;
load address of copy down desc.
#endif
NextBlock:
LDD 2,X+ ; size of init-data -> D
BEQ funcInits ; end of copy down desc.
LDD 2,X+ ;
size of init-data -> D
BEQ funcInits ;
end of copy down desc.
#ifdef FAR_DATA
PSHD ; save counter
LDAB 1,X+ ; load destination page
LDY 2,X+ ; destination address
PSHD ;
save counter
LDAB 1,X+ ;
load destination page
LDY 2,X+ ;
destination address
#if defined(__HCS12X__)
STAB __GPAGE_ADR__
STAB __GPAGE_ADR__
#else /* __HCS12X__ */
__PIC_JSR(_SET_PAGE) ; sets the destinations page register
__PIC_JSR(_SET_PAGE) ;
sets the destinations page register
#endif /* __HCS12X__ */
PULD ; restore counter
PULD ;
restore counter
#else /* FAR_DATA */
LDY 2,X+ ; load destination address
LDY 2,X+ ;
load destination address
#endif /* FAR_DATA */
#if defined(__HCS12X__) && defined(FAR_DATA)
#if defined(__OPTIMIZE_FOR_SIZE__) /* -os, default */
Copy: PSHA
LDAA 1,X+
GSTAA 1,Y+ ; move a byte from ROM to the data area
PULA
__FEED_COP_IN_HLI() ; feed the COP if necessary /*lint !e505 !e522 asm code */
DBNE D,Copy ; copy-byte loop
Copy:
PSHA
LDAA 1,X+
GSTAA 1,Y+ ;
move a byte from ROM to the data area
PULA
__FEED_COP_IN_HLI() ;
feed the COP if necessary /*lint !e505 !e522 asm code */
DBNE D,Copy ;
copy-byte loop
#else
LSRD ; /2 and save bit 0 in the carry
BEQ Copy1 ; do we copy more than 1 byte?
LSRD ;
/2 and save bit 0 in the carry
BEQ Copy1 ;
do we copy more than 1 byte?
Copy: PSHD
LDD 2,X+
GSTD 2,Y+ ; move a word from ROM to the data area
PULD
__FEED_COP_IN_HLI() ; feed the COP if necessary /*lint !e505 !e522 asm code */
DBNE D,Copy ; copy-word loop
Copy: PSHD
LDD 2,X+
GSTD 2,Y+ ;
move a word from ROM to the data area
PULD
__FEED_COP_IN_HLI() ;
feed the COP if necessary /*lint !e505 !e522 asm code */
DBNE D,Copy ;
copy-word loop
Copy1:
BCC NextBlock ; handle last byte?
LDAA 1,X+
GSTAA 1,Y+ ; move a byte from ROM to the data area
BCC NextBlock ;
handle last byte?
LDAA 1,X+
GSTAA 1,Y+ ;
move a byte from ROM to the data area
#endif
#elif defined(__OPTIMIZE_FOR_SIZE__) /* -os, default */
Copy: MOVB 1,X+,1,Y+ ; move a byte from ROM to the data area
__FEED_COP_IN_HLI() ; feed the COP if necessary /*lint !e505 !e522 asm code */
DBNE D,Copy ; copy-byte loop
Copy:
MOVB 1,X+,1,Y+ ;
move a byte from ROM to the data area
__FEED_COP_IN_HLI() ;
feed the COP if necessary /*lint !e505 !e522 asm code */
DBNE D,Copy ;
copy-byte loop
#else /* __OPTIMIZE_FOR_TIME__ */
LSRD ; /2 and save bit 0 in the carry
BEQ Copy1 ; do we copy more than 1 byte?
Copy: MOVW 2,X+,2,Y+ ; move a word from ROM to the data area
__FEED_COP_IN_HLI() ; feed the COP if necessary /*lint !e505 !e522 asm code */
DBNE D,Copy ; copy-word loop
LSRD ;
/2 and save bit 0 in the carry
BEQ Copy1 ;
do we copy more than 1 byte?
Copy: MOVW 2,X+,2,Y+ ;
move a word from ROM to the data area
__FEED_COP_IN_HLI() ;
feed the COP if necessary /*lint !e505 !e522 asm code */
DBNE D,Copy ;
copy-word loop
Copy1:
BCC NextBlock ; handle last byte?
MOVB 1,X+,1,Y+ ; copy the last byte
BCC NextBlock ;
handle last byte?
MOVB 1,X+,1,Y+ ;
copy the last byte
#endif /* __OPTIMIZE_FOR_SIZE__/__OPTIMIZE_FOR_TIME__ */
BRA NextBlock
funcInits: ; call of global construtors is only in c++ necessary
BRA NextBlock
funcInits:
;
call of global construtors is only in c++ necessary
#if defined(__cplusplus)
#if defined(__ELF_OBJECT_FILE_FORMAT__)
#if defined( __BANKED__) || defined(__LARGE__)
LDY _startupData.nofInitBodies; load number of cpp.
BEQ done ; if cppcount == 0, goto done
LDX _startupData.initBodies ; load address of first module to initialize
LDY _startupData.nofInitBodies;
load number of cpp.
BEQ done ;
if cppcount == 0, goto done
LDX _startupData.initBodies ;
load address of first module to initialize
nextInit:
LEAX 3,X ; increment to next init
PSHX ; save address of next function to initialize
PSHY ; save cpp counter
CALL [-3,X] ; use double indirect call to load the page register also
PULY ; restore cpp counter
PULX ; restore actual address
DEY ; decrement cpp counter
BNE nextInit
LEAX 3,X ;
increment to next init
PSHX ;
save address of next function to initialize
PSHY ;
save cpp counter
CALL [-3,X] ;
use double indirect call to load the page register also
PULY ;
restore cpp counter
PULX ;
restore actual address
DEY ;
decrement cpp counter
BNE nextInit
#else /* defined( __BANKED__) || defined(__LARGE__) */
LDD _startupData.nofInitBodies; load number of cpp.
BEQ done ; if cppcount == 0, goto done
LDX _startupData.initBodies ; load address of first module to initialize
LDD _startupData.nofInitBodies;
load number of cpp.
BEQ done ;
if cppcount == 0, goto done
LDX _startupData.initBodies ;
load address of first module to initialize
nextInit:
LDY 2,X+ ; load address of first module to initialize
PSHD
PSHX ; save actual address
JSR 0,Y ; call initialization function
PULX ; restore actual address
PULD ; restore cpp counter
DBNE D, nextInit
LDY 2,X+ ;
load address of first module to initialize
PSHD
PSHX ;
save actual address
JSR 0,Y ;
call initialization function
PULX ;
restore actual address
PULD ;
restore cpp counter
DBNE D, nextInit
#endif /* defined( __BANKED__) || defined(__LARGE__) */
#else /* __ELF_OBJECT_FILE_FORMAT__ */
LDX _startupData.mInits ; load address of first module to initialize
LDX _startupData.mInits ;
load address of first module to initialize
#if defined( __BANKED__) || defined(__LARGE__)
nextInit: LDY 3,X+ ; load address of initialization function
BEQ done ; stop when address == 0
; in common environments the offset of a function is never 0, so this test could be avoided
nextInit:
LDY 3,X+ ;
load address of initialization function
BEQ done ;
stop when address == 0
;
in common environments the offset of a function is never 0, so this test could be avoided
#ifdef __InitFunctionsMayHaveOffset0__
BRCLR -1,X, done, 0xff ; stop when address == 0
BRCLR -1,X, done, 0xff ;
stop when address == 0
#endif /* __InitFunctionsMayHaveOffset0__ */
PSHX ; save address of next function to initialize
CALL [-3,X] ; use double indirect call to load the page register also
PSHX ;
save address of next function to initialize
CALL [-3,X] ;
use double indirect call to load the page register also
#else /* defined( __BANKED__) || defined(__LARGE__) */
nextInit:
LDY 2,X+ ; load address of first module to initialize
BEQ done ; stop when address of function == 0
PSHX ; save actual address
JSR 0,Y ; call initialization function
LDY 2,X+ ;
load address of first module to initialize
BEQ done ;
stop when address of function == 0
PSHX ;
save actual address
JSR 0,Y ;
call initialization function
#endif /* defined( __BANKED__) || defined(__LARGE__) */
PULX ; restore actual address
BRA nextInit
PULX ;
restore actual address
BRA nextInit
#endif /* __ELF_OBJECT_FILE_FORMAT__ */
done:
#endif /* __cplusplus */
}
}
}
#endif /* __ONLY_INIT_SP */
@ -330,38 +432,57 @@ static void __far Fini(void)
static void Fini(void)
#endif
{
/* purpose: 1) call global destructors in C++ */
asm {
/* purpose: 1) call global destructors in C++ */
asm
{
#if defined( __BANKED__) || defined(__LARGE__)
LDY _startupData.nofFiniBodies; load number of cpp.
BEQ done ; if cppcount == 0, goto done
LDX _startupData.finiBodies ; load address of first module to finalize
nextInit2:
LEAX 3,X ; increment to next init
PSHX ; save address of next function to finalize
PSHY ; save cpp counter
CALL [-3,X] ; use double indirect call to load the page register also
PULY ; restore cpp counter
PULX ; restore actual address
DEY ; decrement cpp counter
BNE nextInit2
LDY _startupData.nofFiniBodies;
load number of cpp.
BEQ done ;
if cppcount == 0, goto done
LDX _startupData.finiBodies ;
load address of first module to finalize
nextInit2:
LEAX 3,X ;
increment to next init
PSHX ;
save address of next function to finalize
PSHY ;
save cpp counter
CALL [-3,X] ;
use double indirect call to load the page register also
PULY ;
restore cpp counter
PULX ;
restore actual address
DEY ;
decrement cpp counter
BNE nextInit2
#else /* defined( __BANKED__) || defined(__LARGE__) */
LDD _startupData.nofFiniBodies; load number of cpp.
BEQ done ; if cppcount == 0, goto done
LDX _startupData.finiBodies ; load address of first module to finalize
nextInit2:
LDY 2,X+ ; load address of first module to finalize
PSHD
PSHX ; save actual address
JSR 0,Y ; call finalize function
PULX ; restore actual address
PULD ; restore cpp counter
DBNE D, nextInit2
LDD _startupData.nofFiniBodies;
load number of cpp.
BEQ done ;
if cppcount == 0, goto done
LDX _startupData.finiBodies ;
load address of first module to finalize
nextInit2:
LDY 2,X+ ;
load address of first module to finalize
PSHD
PSHX ;
save actual address
JSR 0,Y ;
call finalize function
PULX ;
restore actual address
PULD ;
restore cpp counter
DBNE D, nextInit2
#endif /* defined(__BANKED__) || defined(__LARGE__) */
done:;
}
}
}
#endif
@ -390,35 +511,37 @@ done:;
/* the reset vector must be set so that the application has a defined entry point */
#if defined(__SET_RESET_VECTOR__)
__EXTERN_C void __interrupt 0 _Startup(void) {
__EXTERN_C void __interrupt 0 _Startup(void)
{
#else
__EXTERN_C void _Startup(void) {
__EXTERN_C void _Startup(void)
{
#endif
/* purpose: 1) initialize the stack
2) initialize the RAM, copy down init data etc (Init)
3) call main;
parameters: NONE
called from: _PRESTART-code generated by the Linker
or directly referenced by the reset vector */
/* purpose: 1) initialize the stack
2) initialize the RAM, copy down init data etc (Init)
3) call main;
parameters: NONE
called from: _PRESTART-code generated by the Linker
or directly referenced by the reset vector */
/* initialize the stack pointer */
/*lint -e{960} , MISRA 14.3 REQ, macro INIT_SP_FROM_STARTUP_DESC() expands to HLI code */
/*lint -e{522} , MISRA 14.2 REQ, macro INIT_SP_FROM_STARTUP_DESC() expands to HLI code */
/* With OpenBLT this function is not directly called at reset, but called by a custom
* reset handler. For this to work, the stackpointer must be initialized before this
* function is called, otherwise the RTS instruction won't know where to go.
*/
/*INIT_SP_FROM_STARTUP_DESC();*/ /* HLI macro definition in hidef.h */
/* initialize the stack pointer */
/*lint -e{960} , MISRA 14.3 REQ, macro INIT_SP_FROM_STARTUP_DESC() expands to HLI code */
/*lint -e{522} , MISRA 14.2 REQ, macro INIT_SP_FROM_STARTUP_DESC() expands to HLI code */
/* With OpenBLT this function is not directly called at reset, but called by a custom
* reset handler. For this to work, the stackpointer must be initialized before this
* function is called, otherwise the RTS instruction won't know where to go.
*/
/*INIT_SP_FROM_STARTUP_DESC();*/ /* HLI macro definition in hidef.h */
/* Here user defined code could be inserted, the stack could be used */
/* Here user defined code could be inserted, the stack could be used */
#if defined(_DO_DISABLE_COP_)
_DISABLE_COP();
_DISABLE_COP();
#endif
/* Example : Set up WinDef Register to allow Paging */
/* Example : Set up WinDef Register to allow Paging */
#ifdef HC812A4 /* HC12 A4 derivative needs WINDEF to configure which pages are available */
#if (__ENABLE_EPAGE__ != 0 || __ENABLE_DPAGE__ != 0 || __ENABLE_PPAGE__ != 0)
WINDEF= __ENABLE_EPAGE__ | __ENABLE_DPAGE__ | __ENABLE_PPAGE__;
WINDEF= __ENABLE_EPAGE__ | __ENABLE_DPAGE__ | __ENABLE_PPAGE__;
#endif
#endif
@ -449,23 +572,23 @@ __EXTERN_C void _Startup(void) {
_MMCTL1_SET(_MMCTL1_BIT_ROMON | _MMCTL1_BIT_EROMON | _MMCTL1_BIT_ROMHM);
#else /* RAM */
_MMCTL1_SET(_MMCTL1_BIT_ROMON | _MMCTL1_BIT_EROMON | _MMCTL1_BIT_RAMHM | _MMCTL1_BIT_ROMHM);
#endif
#endif
#endif
#ifndef __ONLY_INIT_SP
/*lint -e{522} , MISRA 14.2 REQ, function Init() contains HLI only */
Init(); /* zero out, copy down, call constructors */
/*lint -e{522} , MISRA 14.2 REQ, function Init() contains HLI only */
Init(); /* zero out, copy down, call constructors */
#endif
/* Here user defined code could be inserted, all global variables are initilized */
/* Here user defined code could be inserted, all global variables are initilized */
#if defined(_DO_ENABLE_COP_)
_ENABLE_COP(1);
_ENABLE_COP(1);
#endif
/* OpenBLT modifcation: do not call main. instead do this in the reset handler found in
* vectors.c
*/
/* main(); */
/* OpenBLT modifcation: do not call main. instead do this in the reset handler found in
* vectors.c
*/
/* main(); */
}

File diff suppressed because it is too large Load Diff

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -44,7 +44,7 @@
****************************************************************************************/
/** \brief Structure type with the layout of a CAN reception message slot. */
typedef volatile struct
{
{
volatile blt_int8u idr[4]; /**< identifier register 0..3 */
volatile blt_int8u dsr[8]; /**< data segment register 0..7 */
volatile blt_int8u dlr; /**< data length register */
@ -54,7 +54,7 @@ typedef volatile struct
/** \brief Structure type with the layout of a CAN transmit message slot. */
typedef volatile struct
{
{
volatile blt_int8u idr[4]; /**< identifier register 0..3 */
volatile blt_int8u dsr[8]; /**< data segment register 0..7 */
volatile blt_int8u dlr; /**< data length register */
@ -64,7 +64,7 @@ typedef volatile struct
/** \brief Structure type with the layout of the CAN related control registers. */
typedef volatile struct
{
{
volatile blt_int8u cctl0; /**< control register 0 */
volatile blt_int8u cctl1; /**< control register 1 */
volatile blt_int8u cbtr0; /**< bus timing register 0 */
@ -187,26 +187,27 @@ static blt_bool CanGetSpeedConfig(blt_int16u baud, blt_int8u *btr0, blt_int8u *b
* with a sample point between 68..78%.
*/
static const tCanBusTiming canTiming[] =
{ /* TQ | TSEG1 | TSEG2 | SP */
/* ------------------------- */
{ 5, 2 }, /* 8 | 5 | 2 | 75% */
{ 6, 2 }, /* 9 | 6 | 2 | 78% */
{ 6, 3 }, /* 10 | 6 | 3 | 70% */
{ 7, 3 }, /* 11 | 7 | 3 | 73% */
{ 8, 3 }, /* 12 | 8 | 3 | 75% */
{ 9, 3 }, /* 13 | 9 | 3 | 77% */
{ 9, 4 }, /* 14 | 9 | 4 | 71% */
{ 10, 4 }, /* 15 | 10 | 4 | 73% */
{ 11, 4 }, /* 16 | 11 | 4 | 75% */
{ 12, 4 }, /* 17 | 12 | 4 | 76% */
{ 12, 5 }, /* 18 | 12 | 5 | 72% */
{ 13, 5 }, /* 19 | 13 | 5 | 74% */
{ 14, 5 }, /* 20 | 14 | 5 | 75% */
{ 15, 5 }, /* 21 | 15 | 5 | 76% */
{ 15, 6 }, /* 22 | 15 | 6 | 73% */
{ 16, 6 }, /* 23 | 16 | 6 | 74% */
{ 16, 7 }, /* 24 | 16 | 7 | 71% */
{ 16, 8 } /* 25 | 16 | 8 | 68% */
{
/* TQ | TSEG1 | TSEG2 | SP */
/* ------------------------- */
{ 5, 2 }, /* 8 | 5 | 2 | 75% */
{ 6, 2 }, /* 9 | 6 | 2 | 78% */
{ 6, 3 }, /* 10 | 6 | 3 | 70% */
{ 7, 3 }, /* 11 | 7 | 3 | 73% */
{ 8, 3 }, /* 12 | 8 | 3 | 75% */
{ 9, 3 }, /* 13 | 9 | 3 | 77% */
{ 9, 4 }, /* 14 | 9 | 4 | 71% */
{ 10, 4 }, /* 15 | 10 | 4 | 73% */
{ 11, 4 }, /* 16 | 11 | 4 | 75% */
{ 12, 4 }, /* 17 | 12 | 4 | 76% */
{ 12, 5 }, /* 18 | 12 | 5 | 72% */
{ 13, 5 }, /* 19 | 13 | 5 | 74% */
{ 14, 5 }, /* 20 | 14 | 5 | 75% */
{ 15, 5 }, /* 21 | 15 | 5 | 76% */
{ 15, 6 }, /* 22 | 15 | 6 | 73% */
{ 16, 6 }, /* 23 | 16 | 6 | 74% */
{ 16, 7 }, /* 24 | 16 | 7 | 71% */
{ 16, 8 } /* 25 | 16 | 8 | 68% */
};
@ -221,11 +222,11 @@ void CanInit(void)
blt_bool result;
blt_int32u accept_code;
blt_int32u accept_mask;
/* the current implementation supports CAN0..4. throw an assertion error in case a
* different CAN channel is configured.
/* the current implementation supports CAN0..4. throw an assertion error in case a
* different CAN channel is configured.
*/
ASSERT_CT((BOOT_COM_CAN_CHANNEL_INDEX >= 0) && (BOOT_COM_CAN_CHANNEL_INDEX <= 4));
ASSERT_CT((BOOT_COM_CAN_CHANNEL_INDEX >= 0) && (BOOT_COM_CAN_CHANNEL_INDEX <= 4));
/* enter initialization mode. note that this automatically disables CAN interrupts */
CAN->cctl0 = INITRQ_BIT;
@ -243,7 +244,7 @@ void CanInit(void)
/* configure baudrate */
result = CanGetSpeedConfig(BOOT_COM_CAN_BAUDRATE/1000, &btrRegValues[0], &btrRegValues[1]);
ASSERT_RT(result == BLT_TRUE);
/* configure the baudrate */
CAN->cbtr0 = btrRegValues[0];
CAN->cbtr1 = btrRegValues[1];
@ -253,7 +254,7 @@ void CanInit(void)
* identifiers and filter 0 to receive standard 11-bit identifiers.
*/
CAN->cidac &= ~(IDAM1_BIT | IDAM0_BIT);
/* set the acceptance filter code and mask to a value that only BOOT_COM_CAN_RX_MSG_ID
* is received.
*/
@ -305,7 +306,7 @@ void CanInit(void)
void CanTransmitPacket(blt_int8u *data, blt_int8u len)
{
blt_int8u byte_idx;
/* double check that the transmit slot is really available */
ASSERT_RT((CAN->ctflg & TXE0_BIT) != 0);
@ -367,25 +368,25 @@ blt_bool CanReceivePacket(blt_int8u *data)
if ((CAN->crflg & RXF_BIT) == RXF_BIT)
{
/* check IDE-bit to determine if it is a 11-bit or 29-bit identifier */
if ((CAN->rxSlot.idr[1] & IDE_BIT) == 0)
if ((CAN->rxSlot.idr[1] & IDE_BIT) == 0)
{
/* 11-bit id */
rxMsgId = (*(blt_int16u*)(&CAN->rxSlot.idr[0])) >> 5;
rxMsgId = (*(blt_int16u *)(&CAN->rxSlot.idr[0])) >> 5;
}
else
{
/* 29-bit id */
rxMsgId = (blt_int32u)(((*(blt_int32u*)(&CAN->rxSlot.idr[0])) & 0x0007ffff) >> 1) |
(blt_int32u)(((*(blt_int32u*)(&CAN->rxSlot.idr[0])) & 0xffe00000) >> 3);
rxMsgId = (blt_int32u)(((*(blt_int32u *)(&CAN->rxSlot.idr[0])) & 0x0007ffff) >> 1) |
(blt_int32u)(((*(blt_int32u *)(&CAN->rxSlot.idr[0])) & 0xffe00000) >> 3);
}
/* is this the packet identifier? */
/* is this the packet identifier? */
if (rxMsgId == BOOT_COM_CAN_RX_MSG_ID)
{
result = BLT_TRUE;
/* store the dlc */
rxMsgLen = CAN->rxSlot.dlr & 0xf;
/* copy message data */
for (byte_idx=0; byte_idx<rxMsgLen; byte_idx++)
for (byte_idx=0; byte_idx<rxMsgLen; byte_idx++)
{
data[byte_idx] = CAN->rxSlot.dsr[byte_idx];
}
@ -403,7 +404,7 @@ blt_bool CanReceivePacket(blt_int8u *data)
** \param baud The desired baudrate in kbps. Valid values are 10..1000.
** \param btr0 Pointer to where the value for register CANxBTR0 will be stored.
** \param btr1 Pointer to where the value for register CANxBTR1 will be stored.
** \return BLT_TRUE if the CAN bustiming register values were found, BLT_FALSE
** \return BLT_TRUE if the CAN bustiming register values were found, BLT_FALSE
** otherwise.
**
****************************************************************************************/
@ -421,7 +422,7 @@ static blt_bool CanGetSpeedConfig(blt_int16u baud, blt_int8u *btr0, blt_int8u *b
prescaler = (blt_int8u)(BOOT_CPU_XTAL_SPEED_KHZ/(baud*(canTiming[cnt].tseg1+canTiming[cnt].tseg2+1)));
/* make sure the prescaler is valid */
if ( (prescaler > 0) && (prescaler <= 64) )
if ((prescaler > 0) && (prescaler <= 64))
{
/* store the MSCAN bustiming register values */
*btr0 = prescaler - 1;

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -41,7 +41,7 @@
* Macro definitions
****************************************************************************************/
/** \brief Start address of the user program. This is the address of the reset vector
* in the user program's vector table.
* in the user program's vector table.
* \attention This value must be updated if the memory reserved for the bootloader
* changes.
*/
@ -64,7 +64,7 @@ extern void reset_handler(void); /* implemented in C startu
/************************************************************************************//**
** \brief Starts the user program, if one is present. In this case this function
** does not return.
** does not return.
** \return none.
**
****************************************************************************************/
@ -78,25 +78,25 @@ void CpuStartUserProgram(void)
/* not a valid user program so it cannot be started */
return;
}
#if (BOOT_CPU_USER_PROGRAM_START_HOOK > 0)
#if (BOOT_CPU_USER_PROGRAM_START_HOOK > 0)
/* invoke callback */
if (CpuUserProgramStartHook() == BLT_FALSE)
{
/* callback requests the user program to not be started */
return;
}
#endif
#if (BOOT_COM_ENABLE > 0)
#endif
#if (BOOT_COM_ENABLE > 0)
/* release the communication interface */
ComFree();
#endif
#endif
/* reset the timer */
TimerReset();
/* set the address where the bootloader needs to jump to. this is the address of
* the last entry in the user program's vector table. this address points to the
* user program's reset handler.
*/
pProgResetHandler = (void(*)(void))(*((blt_int16u*)CPU_USER_PROGRAM_STARTADDR_PTR));
pProgResetHandler = (void(*)(void))(*((blt_int16u *)CPU_USER_PROGRAM_STARTADDR_PTR));
/* start the user program by activating its reset interrupt service routine */
pProgResetHandler();
} /*** end of CpuStartUserProgram ***/
@ -106,7 +106,7 @@ void CpuStartUserProgram(void)
** \brief Copies data from the source to the destination address.
** \param dest Destination address for the data.
** \param src Source address of the data.
** \param len length of the data in bytes.
** \param len length of the data in bytes.
** \return none.
**
****************************************************************************************/
@ -119,7 +119,7 @@ void CpuMemCopy(blt_addr dest, blt_addr src, blt_int16u len)
to = (blt_int8u *)dest;
/* copy all bytes from source address to destination address */
while(len-- > 0)
while (len-- > 0)
{
/* store byte value from source to destination */
*to++ = *from++;

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -59,7 +59,7 @@
/** \brief End address of the bootloader programmable flash. */
#define FLASH_END_ADDRESS (flashLayout[FLASH_LAST_SECTOR_IDX].sector_start + \
flashLayout[FLASH_LAST_SECTOR_IDX].sector_size - 1)
/** \brief Size of a flash page on the HCS12. */
/** \brief Size of a flash page on the HCS12. */
#define FLASH_PAGE_SIZE (0x4000) /* flash page size in bytes */
/** \brief Physical start address of the HCS12 page window. */
#define FLASH_PAGE_OFFSET (0x8000) /* physical start addr. of pages */
@ -82,7 +82,7 @@
#endif
/** \brief Bitmask for selecting a block with flash pages. */
#define FLASH_BLOCK_SEL_MASK (0x03)
/****************************************************************************************
* Register definitions
@ -107,17 +107,17 @@
* Type definitions
****************************************************************************************/
/** \brief Structure type for the flash sectors in the flash layout table. */
typedef struct
typedef struct
{
blt_addr sector_start; /**< sector start address */
blt_int32u sector_size; /**< sector size in bytes */
} tFlashSector;
/** \brief Structure type for grouping flash block information.
* \details Programming is done per block of max FLASH_WRITE_BLOCK_SIZE. for this a
* \details Programming is done per block of max FLASH_WRITE_BLOCK_SIZE. for this a
* flash block manager is implemented in this driver. this flash block manager
* depends on this flash block info structure. It holds the base address of
* the flash block and the data that should be programmed into the flash
* depends on this flash block info structure. It holds the base address of
* the flash block and the data that should be programmed into the flash
* block. The .base_addr must be a multiple of FLASH_WRITE_BLOCK_SIZE.
*/
typedef struct
@ -128,7 +128,7 @@ typedef struct
/** \brief Structure type for the flash control registers. */
typedef volatile struct
{
{
volatile blt_int8u fclkdiv; /**< flash clock devider register */
volatile blt_int8u fsec; /**< flash security register */
volatile blt_int8u ftstmod; /**< flash test mode register */
@ -136,10 +136,10 @@ typedef volatile struct
volatile blt_int8u fprot; /**< flash protection register */
volatile blt_int8u fstat; /**< flash status register */
volatile blt_int8u fcmd; /**< flash command register */
} tFlashRegs;
} tFlashRegs;
/** \brief Pointer type to flash command execution function. */
typedef void (*pFlashExeCmdFct) (void);
typedef void (*pFlashExeCmdFct)(void);
/****************************************************************************************
@ -147,7 +147,7 @@ typedef void (*pFlashExeCmdFct) (void);
****************************************************************************************/
static blt_bool FlashInitBlock(tFlashBlockInfo *block, blt_addr address);
static tFlashBlockInfo *FlashSwitchBlock(tFlashBlockInfo *block, blt_addr base_addr);
static blt_bool FlashAddToBlock(tFlashBlockInfo *block, blt_addr address,
static blt_bool FlashAddToBlock(tFlashBlockInfo *block, blt_addr address,
blt_int8u *data, blt_int32u len);
static blt_bool FlashWriteBlock(tFlashBlockInfo *block);
static blt_int8u FlashGetLinearAddrByte(blt_addr addr);
@ -161,12 +161,12 @@ static blt_bool FlashOperate(blt_int8u cmd, blt_addr addr, blt_int16u data);
* Local constant declarations
****************************************************************************************/
/** \brief Array wit the layout of the flash memory.
* \details Also controls what part of the flash memory is reserved for the bootloader.
* If the bootloader size changes, the reserved sectors for the bootloader
* \details Also controls what part of the flash memory is reserved for the bootloader.
* If the bootloader size changes, the reserved sectors for the bootloader
* might need adjustment to make sure the bootloader doesn't get overwritten.
* This layout uses linear addresses only. For example, the first address on
* page 0x3F is: 0x3F * 0x4000 (page size) = 0xFC000. Note that page 0x3F is
* where the bootloader also resides and it has been entered as 8 chunks of 2kb.
* where the bootloader also resides and it has been entered as 8 chunks of 2kb.
* This allows flexibility for reserving more/less space for the bootloader in
* case its size changes in the future.
*/
@ -232,7 +232,7 @@ static const tFlashSector flashLayout[] =
* independent. This allows us to copy it to a ram buffer and execute the code
* from ram. This way the flash driver can be located in flash memory without
* running into problems when erasing/programming the same flash block that
* contains the flash driver. the source code for the machine code is as
* contains the flash driver. the source code for the machine code is as
* follows:
* // launch the command
* FLASH->fstat = CBEIF_BIT;
@ -276,46 +276,46 @@ static const blt_int8u flashExecCmd[] =
****************************************************************************************/
/** \brief Local variable with information about the flash block that is currently
* being operated on.
* \details The smallest amount of flash that can be programmed is
* \details The smallest amount of flash that can be programmed is
* FLASH_WRITE_BLOCK_SIZE. A flash block manager is implemented in this driver
* and stores info in this variable. Whenever new data should be flashed, it
* is first added to a RAM buffer, which is part of this variable. Whenever
* the RAM buffer, which has the size of a flash block, is full or data needs
* to be written to a different block, the contents of the RAM buffer are
* programmed to flash. The flash block manager requires some software
* overhead, yet results is faster flash programming because data is first
* harvested, ideally until there is enough to program an entire flash block,
* to be written to a different block, the contents of the RAM buffer are
* programmed to flash. The flash block manager requires some software
* overhead, yet results is faster flash programming because data is first
* harvested, ideally until there is enough to program an entire flash block,
* before the flash device is actually operated on.
*/
static tFlashBlockInfo blockInfo;
/** \brief Local variable with information about the flash boot block.
* \details The first block of the user program holds the vector table, which on the
* STM32 is also the where the checksum is written to. Is it likely that
* \details The first block of the user program holds the vector table, which on the
* STM32 is also the where the checksum is written to. Is it likely that
* the vector table is first flashed and then, at the end of the programming
* sequence, the checksum. This means that this flash block need to be written
* to twice. Normally this is not a problem with flash memory, as long as you
* write the same values to those bytes that are not supposed to be changed
* write the same values to those bytes that are not supposed to be changed
* and the locations where you do write to are still in the erased 0xFF state.
* Unfortunately, writing twice to flash this way, does not work reliably on
* Unfortunately, writing twice to flash this way, does not work reliably on
* all micros. This is why we need to have an extra block, the bootblock,
* placed under the management of the block manager. This way is it possible
* placed under the management of the block manager. This way is it possible
* to implement functionality so that the bootblock is only written to once
* at the end of the programming sequence.
*/
static tFlashBlockInfo bootBlockInfo;
/** \brief RAM buffer where the executable flash operation code is copied to. */
static blt_int8u flashExecCmdRam[(sizeof(flashExecCmd)/sizeof(flashExecCmd[0]))];
static blt_int8u flashExecCmdRam[(sizeof(flashExecCmd)/sizeof(flashExecCmd[0]))];
/** \brief Maximum number of supported blocks, which is determined dynamically to have
* code that is independent of the used HCS12 derivative.
*/
static blt_int8u flashMaxNrBlocks;
static blt_int8u flashMaxNrBlocks;
/************************************************************************************//**
** \brief Initializes the flash driver.
** \brief Initializes the flash driver.
** \return none.
**
****************************************************************************************/
@ -332,7 +332,7 @@ void FlashInit(void)
/* init the flash block info structs by setting the address to an invalid address */
blockInfo.base_addr = FLASH_INVALID_ADDRESS;
bootBlockInfo.base_addr = FLASH_INVALID_ADDRESS;
/* determine how many flash blocks this device supports by first trying to set all
* all block selection bits. on devices where a specific block is not supported,
* the bit is reserved and will read back 0 afterwards
@ -340,7 +340,7 @@ void FlashInit(void)
FLASH->fcnfg |= FLASH_BLOCK_SEL_MASK;
/* read back which ones got set */
flashMaxNrBlocks = (FLASH->fcnfg & FLASH_BLOCK_SEL_MASK) + 1;
/* set back to default reset value */
/* set back to default reset value */
FLASH->fcnfg &= ~(CBEIE_BIT | CCIE_BIT | KEYACC_BIT | FLASH_BLOCK_SEL_MASK);
/* enable extra prescale factor of 8 when the external crystal is > 12.8 MHz */
@ -358,7 +358,7 @@ void FlashInit(void)
clockFreq = BOOT_CPU_XTAL_SPEED_KHZ / (prescaler * (1 + cnt));
/* is this a valid setting? */
if ( (clockFreq > 150) && (clockFreq < 200) )
if ((clockFreq > 150) && (clockFreq < 200))
{
/* configure the setting while taking into account the prescaler */
if (prescaler == 8)
@ -375,7 +375,7 @@ void FlashInit(void)
break;
}
}
/* make sure that a valid clock divider was found */
ASSERT_RT(result == BLT_TRUE);
} /*** end of FlashInit ***/
@ -383,30 +383,30 @@ void FlashInit(void)
/************************************************************************************//**
** \brief Writes the data to flash through a flash block manager. Note that this
** function also checks that no data is programmed outside the flash
** function also checks that no data is programmed outside the flash
** memory region, so the bootloader can never be overwritten.
** \param addr Start address.
** \param len Length in bytes.
** \param data Pointer to the data buffer.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
blt_bool FlashWrite(blt_addr addr, blt_int32u len, blt_int8u *data)
{
blt_addr base_addr;
blt_addr last_block_base_addr;
/* make sure the addresses are within the flash device */
if ( (addr < FLASH_START_ADDRESS) || ((addr+len-1) > FLASH_END_ADDRESS) )
if ((addr < FLASH_START_ADDRESS) || ((addr+len-1) > FLASH_END_ADDRESS))
{
return BLT_FALSE;
return BLT_FALSE;
}
/* determine the start address of the last block in flash */
last_block_base_addr = flashLayout[FLASH_LAST_SECTOR_IDX].sector_start + \
flashLayout[FLASH_LAST_SECTOR_IDX].sector_size - \
FLASH_WRITE_BLOCK_SIZE;
/* if this is the bootblock, then let the boot block manager handle it */
base_addr = (addr/FLASH_WRITE_BLOCK_SIZE)*FLASH_WRITE_BLOCK_SIZE;
if (base_addr == last_block_base_addr)
@ -420,12 +420,12 @@ blt_bool FlashWrite(blt_addr addr, blt_int32u len, blt_int8u *data)
/************************************************************************************//**
** \brief Erases the flash memory. Note that this function also checks that no
** data is erased outside the flash memory region, so the bootloader can
** \brief Erases the flash memory. Note that this function also checks that no
** data is erased outside the flash memory region, so the bootloader can
** never be erased.
** \param addr Start address.
** \param len Length in bytes.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
blt_bool FlashErase(blt_addr addr, blt_int32u len)
@ -435,25 +435,25 @@ blt_bool FlashErase(blt_addr addr, blt_int32u len)
blt_int32u total_erase_len;
blt_int16u block_cnt;
/* determine the base address for the erase operation, by aligning to
/* determine the base address for the erase operation, by aligning to
* FLASH_ERASE_BLOCK_SIZE.
*/
erase_base_addr = (addr/FLASH_ERASE_BLOCK_SIZE)*FLASH_ERASE_BLOCK_SIZE;
/* make sure the addresses are within the flash device */
if ( (erase_base_addr < FLASH_START_ADDRESS) || ((addr+len-1) > FLASH_END_ADDRESS) )
if ((erase_base_addr < FLASH_START_ADDRESS) || ((addr+len-1) > FLASH_END_ADDRESS))
{
return BLT_FALSE;
return BLT_FALSE;
}
/* determine number of bytes to erase from base address */
total_erase_len = len + (addr - erase_base_addr);
/* determine the number of blocks to erase */
nr_of_erase_blocks = (blt_int16u) (total_erase_len / FLASH_ERASE_BLOCK_SIZE);
nr_of_erase_blocks = (blt_int16u)(total_erase_len / FLASH_ERASE_BLOCK_SIZE);
if ((total_erase_len % FLASH_ERASE_BLOCK_SIZE) > 0)
{
nr_of_erase_blocks++;
nr_of_erase_blocks++;
}
/* erase all blocks one by one */
@ -461,17 +461,17 @@ blt_bool FlashErase(blt_addr addr, blt_int32u len)
{
/* keep the watchdog happy */
CopService();
/* erase the block */
if (FlashOperate(FLASH_ERASE_SECTOR_CMD, erase_base_addr, 0x55aa) == BLT_FALSE)
{
/* error occurred */
return BLT_FALSE;
return BLT_FALSE;
}
/* point to the next block's base address */
erase_base_addr += FLASH_ERASE_BLOCK_SIZE;
}
/* erase successful */
return BLT_TRUE;
} /*** end of FlashErase ***/
@ -483,7 +483,7 @@ blt_bool FlashErase(blt_addr addr, blt_int32u len)
** the checksum, the bootloader can check if the programming session
** was completed, which indicates that a valid user programming is
** present and can be started.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
blt_bool FlashWriteChecksum(void)
@ -492,8 +492,8 @@ blt_bool FlashWriteChecksum(void)
blt_int8u byte_counter;
blt_int16u vectab_offset;
blt_addr checksum_address;
/* for the HCS12 target we defined the checksum as the 16-bit Two's complement value
/* for the HCS12 target we defined the checksum as the 16-bit Two's complement value
* of the sum of all the 64 interrupt vector addresses, so basically a checksum over
* the contents of the entire user program interrupt vector table.
*
@ -524,8 +524,8 @@ blt_bool FlashWriteChecksum(void)
*/
for (byte_counter=0; byte_counter<FLASH_VECTOR_TABLE_SIZE; byte_counter++)
{
signature_checksum += bootBlockInfo.data[vectab_offset + byte_counter];
signature_checksum += bootBlockInfo.data[vectab_offset + byte_counter];
}
signature_checksum = ~signature_checksum; /* one's complement */
signature_checksum += 1; /* two's complement */
@ -534,15 +534,15 @@ blt_bool FlashWriteChecksum(void)
checksum_address = flashLayout[FLASH_LAST_SECTOR_IDX].sector_start + \
flashLayout[FLASH_LAST_SECTOR_IDX].sector_size - \
FLASH_VECTOR_TABLE_CS_OFFSET;
return FlashWrite(checksum_address, sizeof(signature_checksum),
(blt_int8u*)&signature_checksum);
return FlashWrite(checksum_address, sizeof(signature_checksum),
(blt_int8u *)&signature_checksum);
} /*** end of FlashWriteChecksum ***/
/************************************************************************************//**
** \brief Verifies the checksum, which indicates that a valid user program is
** present and can be started.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
blt_bool FlashVerifyChecksum(void)
@ -563,11 +563,11 @@ blt_bool FlashVerifyChecksum(void)
/* compute the checksum based on how it was written by FlashWriteChecksum() */
for (byte_counter=0; byte_counter<FLASH_VECTOR_TABLE_SIZE; byte_counter++)
{
signature_checksum += FlashGetLinearAddrByte(vector_table_addr_lin + byte_counter);
signature_checksum += FlashGetLinearAddrByte(vector_table_addr_lin + byte_counter);
}
/* add the 16-bit checksum value */
signature_checksum += (((blt_int16u)FlashGetLinearAddrByte(checksum_addr_lin) << 8) +
FlashGetLinearAddrByte(checksum_addr_lin + 1));
FlashGetLinearAddrByte(checksum_addr_lin + 1));
/* sum should add up to an unsigned 16-bit value of 0 */
if (signature_checksum == 0)
{
@ -582,7 +582,7 @@ blt_bool FlashVerifyChecksum(void)
/************************************************************************************//**
** \brief Finalizes the flash driver operations. There could still be data in
** the currently active block that needs to be flashed.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
blt_bool FlashDone(void)
@ -597,7 +597,7 @@ blt_bool FlashDone(void)
return BLT_FALSE;
}
}
/* check if there is still data waiting to be programmed */
if (blockInfo.base_addr != FLASH_INVALID_ADDRESS)
{
@ -606,21 +606,21 @@ blt_bool FlashDone(void)
return BLT_FALSE;
}
}
/* flash operations complete, so clear the RAM buffer with operation execution code */
for (cnt=0; cnt<(sizeof(flashExecCmd)/sizeof(flashExecCmd[0])); cnt++)
{
flashExecCmdRam[cnt] = 0;
}
/* still here so all is okay */
/* still here so all is okay */
return BLT_TRUE;
} /*** end of FlashDone ***/
/************************************************************************************//**
** \brief Obtains the base address of the flash memory available to the user program.
** This is basically the last address in the flashLayout table converted to
** This is basically the last address in the flashLayout table converted to
** the physical address on the last page (0x3f), because this is where the
** address will be in.
** \return Base address.
@ -631,7 +631,7 @@ blt_addr FlashGetUserProgBaseAddress(void)
blt_addr end_address_linear;
blt_addr end_address_physical_page_window;
blt_addr end_address_physical_page_3f;
end_address_linear = FLASH_END_ADDRESS + 1;
end_address_physical_page_window = FlashGetPhysAddr(end_address_linear);
end_address_physical_page_3f = end_address_physical_page_window + FLASH_PAGE_SIZE;
@ -640,18 +640,18 @@ blt_addr FlashGetUserProgBaseAddress(void)
/************************************************************************************//**
** \brief Copies data currently in flash to the block->data and sets the
** \brief Copies data currently in flash to the block->data and sets the
** base address.
** \param block Pointer to flash block info structure to operate on.
** \param address Base address of the block data.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
static blt_bool FlashInitBlock(tFlashBlockInfo *block, blt_addr address)
{
blt_int8u oldPage;
/* check address alignment */
/* check address alignment */
if ((address % FLASH_WRITE_BLOCK_SIZE) != 0)
{
return BLT_FALSE;
@ -662,7 +662,7 @@ static blt_bool FlashInitBlock(tFlashBlockInfo *block, blt_addr address)
/* block already initialized, so nothing to do */
return BLT_TRUE;
}
/* set the base address */
/* set the base address */
block->base_addr = address;
/* backup originally selected page */
oldPage = FLASH_PPAGE_REG;
@ -690,14 +690,14 @@ static tFlashBlockInfo *FlashSwitchBlock(tFlashBlockInfo *block, blt_addr base_a
{
/* check if a switch needs to be made away from the boot block. in this case the boot
* block shouldn't be written yet, because this is done at the end of the programming
* session by FlashDone(), this is right after the checksum was written.
* session by FlashDone(), this is right after the checksum was written.
*/
if (block == &bootBlockInfo)
{
/* switch from the boot block to the generic block info structure */
block = &blockInfo;
}
/* check if a switch back into the bootblock is needed. in this case the generic block
/* check if a switch back into the bootblock is needed. in this case the generic block
* doesn't need to be written here yet.
*/
else if (base_addr == flashLayout[FLASH_LAST_SECTOR_IDX].sector_start)
@ -716,7 +716,7 @@ static tFlashBlockInfo *FlashSwitchBlock(tFlashBlockInfo *block, blt_addr base_a
}
/* initialize tne new block when necessary */
if (FlashInitBlock(block, base_addr) == BLT_FALSE)
if (FlashInitBlock(block, base_addr) == BLT_FALSE)
{
return BLT_NULL;
}
@ -738,13 +738,13 @@ static tFlashBlockInfo *FlashSwitchBlock(tFlashBlockInfo *block, blt_addr base_a
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
static blt_bool FlashAddToBlock(tFlashBlockInfo *block, blt_addr address,
static blt_bool FlashAddToBlock(tFlashBlockInfo *block, blt_addr address,
blt_int8u *data, blt_int32u len)
{
blt_addr current_base_addr;
blt_int8u *dst;
blt_int8u *src;
/* determine the current base address */
current_base_addr = (address/FLASH_WRITE_BLOCK_SIZE)*FLASH_WRITE_BLOCK_SIZE;
@ -768,7 +768,7 @@ static blt_bool FlashAddToBlock(tFlashBlockInfo *block, blt_addr address,
return BLT_FALSE;
}
}
/* add the data to the current block, but check for block overflow */
dst = &(block->data[address - block->base_addr]);
src = data;
@ -810,7 +810,7 @@ static blt_bool FlashAddToBlock(tFlashBlockInfo *block, blt_addr address,
**
****************************************************************************************/
static blt_bool FlashWriteBlock(tFlashBlockInfo *block)
{
{
blt_bool result = BLT_TRUE;
blt_addr prog_addr;
blt_int16u prog_data;
@ -826,27 +826,27 @@ static blt_bool FlashWriteBlock(tFlashBlockInfo *block)
for (word_cnt=0; word_cnt<(FLASH_WRITE_BLOCK_SIZE/sizeof(blt_int16u)); word_cnt++)
{
prog_addr = block->base_addr + (word_cnt * sizeof(blt_int16u));
prog_data = *(volatile blt_int16u*)(&block->data[word_cnt * sizeof(blt_int16u)]);
prog_data = *(volatile blt_int16u *)(&block->data[word_cnt * sizeof(blt_int16u)]);
/* keep the watchdog happy */
CopService();
/* program the word to flash */
if (FlashOperate(FLASH_PROGRAM_WORD_CMD, prog_addr, prog_data) == BLT_FALSE)
{
/* error occurred */
result = BLT_FALSE;
result = BLT_FALSE;
break;
}
/* verify that the written data is actually there */
if (FlashGetLinearAddrByte(prog_addr) != (blt_int8u)(prog_data >> 8))
{
/* msb not correctly written */
result = BLT_FALSE;
result = BLT_FALSE;
break;
}
if (FlashGetLinearAddrByte(prog_addr+1) != (blt_int8u)(prog_data))
{
/* lsb not correctly written */
result = BLT_FALSE;
result = BLT_FALSE;
break;
}
}
@ -856,7 +856,7 @@ static blt_bool FlashWriteBlock(tFlashBlockInfo *block)
/************************************************************************************//**
** \brief Reads the byte value from the linear address.
** \brief Reads the byte value from the linear address.
** \param addr Linear address.
** \return The byte value located at the linear address.
**
@ -873,7 +873,7 @@ static blt_int8u FlashGetLinearAddrByte(blt_addr addr)
FLASH_PPAGE_REG = FlashGetPhysPage(addr);
/* read the byte value from the page address */
result = *((blt_int8u*)FlashGetPhysAddr(addr));
result = *((blt_int8u *)FlashGetPhysAddr(addr));
/* restore originally selected page */
FLASH_PPAGE_REG = oldPage;
@ -884,7 +884,7 @@ static blt_int8u FlashGetLinearAddrByte(blt_addr addr)
/************************************************************************************//**
** \brief Extracts the physical flash page number from a linear address.
** \brief Extracts the physical flash page number from a linear address.
** \param addr Linear address.
** \return The page number.
**
@ -896,8 +896,8 @@ static blt_int8u FlashGetPhysPage(blt_addr addr)
/************************************************************************************//**
** \brief Extracts the physical address on the flash page number from a
** linear address.
** \brief Extracts the physical address on the flash page number from a
** linear address.
** \param addr Linear address.
** \return The physical address.
**
@ -913,14 +913,14 @@ static blt_int16u FlashGetPhysAddr(blt_addr addr)
** stored as location independant machine code in array flashExecCmd[].
** The contents of this array are temporarily copied to RAM. This way the
** function can be executed from RAM avoiding problem when try to perform
** a flash operation on the same flash block that this driver is located.
** a flash operation on the same flash block that this driver is located.
** \return none.
**
****************************************************************************************/
static void FlashExecuteCommand(void)
{
/* pointer to command execution function */
pFlashExeCmdFct pExecCommandFct;
pFlashExeCmdFct pExecCommandFct;
blt_int8u cnt;
/* copy code for command execution to ram buffer */
@ -930,9 +930,9 @@ static void FlashExecuteCommand(void)
}
/* init the function pointer */
pExecCommandFct = (pFlashExeCmdFct) ((void *)flashExecCmdRam);
pExecCommandFct = (pFlashExeCmdFct)((void *)flashExecCmdRam);
/* call the command execution function */
pExecCommandFct();
pExecCommandFct();
} /*** end of FlashExecuteCommand ***/
@ -949,16 +949,16 @@ static blt_bool FlashOperate(blt_int8u cmd, blt_addr addr, blt_int16u data)
blt_bool result;
blt_int8u oldPage;
blt_int8u selPage;
/* set default result to error */
result = BLT_FALSE;
/* backup originally selected page */
oldPage = FLASH_PPAGE_REG;
/* calculate page number */
selPage = FlashGetPhysPage(addr);
selPage = FlashGetPhysPage(addr);
/* select correct page */
FLASH_PPAGE_REG = selPage;
/* there are always a fixed number of pages per block. to get the block index number
* we simply divide by this number of pages per block. to one tricky thing is that
* the block number goes from high to low with increasing page numbers so we need to
@ -968,21 +968,21 @@ static blt_bool FlashOperate(blt_int8u cmd, blt_addr addr, blt_int16u data)
FLASH->fcnfg |= (~(selPage / FLASH_PAGES_PER_BLOCK)) & FLASH_BLOCK_SEL_MASK;
/* clear error flags */
FLASH->fstat = (ACCERR_BIT | PVIOL_BIT);
FLASH->fstat = (ACCERR_BIT | PVIOL_BIT);
/* command buffer empty? */
if ((FLASH->fstat & CBEIF_BIT) == CBEIF_BIT)
if ((FLASH->fstat & CBEIF_BIT) == CBEIF_BIT)
{
/* write data value to the physical address to operate on */
*((blt_int16u*)FlashGetPhysAddr(addr)) = data;
*((blt_int16u *)FlashGetPhysAddr(addr)) = data;
/* write the command */
FLASH->fcmd = cmd;
FLASH->fcmd = cmd;
/* launch the actual command */
FlashExecuteCommand();
FlashExecuteCommand();
/* check error flags */
if ((FLASH->fstat & (ACCERR_BIT | PVIOL_BIT)) == 0)
if ((FLASH->fstat & (ACCERR_BIT | PVIOL_BIT)) == 0)
{
/* operation was successful */
result = BLT_TRUE;
result = BLT_TRUE;
}
}

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
#ifndef FLASH_H

View File

@ -25,11 +25,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -61,7 +61,7 @@
/** \brief End address of the bootloader programmable flash. */
#define FLASH_END_ADDRESS (flashLayout[FLASH_LAST_SECTOR_IDX].sector_start + \
flashLayout[FLASH_LAST_SECTOR_IDX].sector_size - 1)
/** \brief Size of a flash page on the HCS12. */
/** \brief Size of a flash page on the HCS12. */
#define FLASH_PAGE_SIZE (0x4000) /* flash page size in bytes */
/** \brief Physical start address of the HCS12 page window. */
#define FLASH_PAGE_OFFSET (0x8000) /* physical start addr. of pages */
@ -83,7 +83,7 @@
#define FLASH_ERASE_SECTOR_CMD (0x0A)
/** \brief Program phrase flash command. */
#define FLASH_PROGRAM_PHRASE_CMD (0x06)
/****************************************************************************************
* Register definitions
@ -102,17 +102,17 @@
* Type definitions
****************************************************************************************/
/** \brief Structure type for the flash sectors in the flash layout table. */
typedef struct
typedef struct
{
blt_addr sector_start; /**< sector start address */
blt_int32u sector_size; /**< sector size in bytes */
} tFlashSector;
/** \brief Structure type for grouping flash block information.
* \details Programming is done per block of max FLASH_WRITE_BLOCK_SIZE. for this a
* \details Programming is done per block of max FLASH_WRITE_BLOCK_SIZE. for this a
* flash block manager is implemented in this driver. this flash block manager
* depends on this flash block info structure. It holds the base address of
* the flash block and the data that should be programmed into the flash
* depends on this flash block info structure. It holds the base address of
* the flash block and the data that should be programmed into the flash
* block. The .base_addr must be a multiple of FLASH_WRITE_BLOCK_SIZE.
*/
typedef struct
@ -123,7 +123,7 @@ typedef struct
/** \brief Structure type for the flash control registers. */
typedef volatile struct
{
{
volatile blt_int8u fclkdiv; /**< flash clock devider register */
volatile blt_int8u fsec; /**< flash security register */
volatile blt_int8u fccobix; /**< flash CCOB index register */
@ -143,15 +143,15 @@ typedef volatile struct
volatile blt_int8u frsv5; /**< flash reserver register */
volatile blt_int8u frsv6; /**< flash reserver register */
volatile blt_int8u frsv7; /**< flash reserver register */
} tFlashRegs;
} tFlashRegs;
/** \brief Pointer type to flash command execution function. */
typedef void (*pFlashExeCmdFct) (void);
typedef void (*pFlashExeCmdFct)(void);
/** \brief Mapping table for finding the corect flash clock divider prescaler. */
typedef struct
{
blt_int16u sysclock_min; /**< min busclock for this prescaler */
blt_int16u sysclock_min; /**< min busclock for this prescaler */
blt_int16u sysclock_max; /**< max busclock for this prescaler */
blt_int8u prescaler; /**< prescaler for this busclock range*/
} tFlashPrescalerSysclockMapping;
@ -162,14 +162,14 @@ typedef struct
****************************************************************************************/
static blt_bool FlashInitBlock(tFlashBlockInfo *block, blt_addr address);
static tFlashBlockInfo *FlashSwitchBlock(tFlashBlockInfo *block, blt_addr base_addr);
static blt_bool FlashAddToBlock(tFlashBlockInfo *block, blt_addr address,
static blt_bool FlashAddToBlock(tFlashBlockInfo *block, blt_addr address,
blt_int8u *data, blt_int32u len);
static blt_bool FlashWriteBlock(tFlashBlockInfo *block);
static blt_int8u FlashGetGlobalAddrByte(blt_addr addr);
static blt_int8u FlashGetPhysPage(blt_addr addr);
static blt_int16u FlashGetPhysAddr(blt_addr addr);
static void FlashExecuteCommand(void);
static blt_bool FlashOperate(blt_int8u cmd, blt_addr addr, blt_int16u params[],
static blt_bool FlashOperate(blt_int8u cmd, blt_addr addr, blt_int16u params[],
blt_int8u param_count);
@ -177,11 +177,11 @@ static blt_bool FlashOperate(blt_int8u cmd, blt_addr addr, blt_int16u params[]
* Local constant declarations
****************************************************************************************/
/** \brief Array wit the layout of the flash memory.
* \details Also controls what part of the flash memory is reserved for the bootloader.
* If the bootloader size changes, the reserved sectors for the bootloader
* \details Also controls what part of the flash memory is reserved for the bootloader.
* If the bootloader size changes, the reserved sectors for the bootloader
* might need adjustment to make sure the bootloader doesn't get overwritten.
* This layout uses global addresses only. Note that the last part is where the
* bootloader also resides and it has been entered as 8 chunks of 2kb.
* bootloader also resides and it has been entered as 8 chunks of 2kb.
* This allows flexibility for reserving more/less space for the bootloader in
* case its size changes in the future.
*/
@ -238,7 +238,7 @@ static const tFlashSector flashLayout[] =
/** \brief Lookup table for determining the flash clock divider setting based on the
* system clock speed. The flash clock must be around 1MHz and is scaled down
* from the system clock using a prescaler value. Note that clock speeds in
* from the system clock using a prescaler value. Note that clock speeds in
* the table are in kHz.
*/
static const tFlashPrescalerSysclockMapping flashFDIVlookup[] =
@ -284,7 +284,7 @@ static const tFlashPrescalerSysclockMapping flashFDIVlookup[] =
* independent. This allows us to copy it to a ram buffer and execute the code
* from ram. This way the flash driver can be located in flash memory without
* running into problems when erasing/programming the same flash block that
* contains the flash driver. the source code for the machine code is as
* contains the flash driver. the source code for the machine code is as
* follows:
* // launch the command
* FLASH->fstat = CCIF_BIT;
@ -328,41 +328,41 @@ static const blt_int8u flashExecCmd[] =
****************************************************************************************/
/** \brief Local variable with information about the flash block that is currently
* being operated on.
* \details The smallest amount of flash that can be programmed is
* \details The smallest amount of flash that can be programmed is
* FLASH_WRITE_BLOCK_SIZE. A flash block manager is implemented in this driver
* and stores info in this variable. Whenever new data should be flashed, it
* is first added to a RAM buffer, which is part of this variable. Whenever
* the RAM buffer, which has the size of a flash block, is full or data needs
* to be written to a different block, the contents of the RAM buffer are
* programmed to flash. The flash block manager requires some software
* overhead, yet results is faster flash programming because data is first
* harvested, ideally until there is enough to program an entire flash block,
* to be written to a different block, the contents of the RAM buffer are
* programmed to flash. The flash block manager requires some software
* overhead, yet results is faster flash programming because data is first
* harvested, ideally until there is enough to program an entire flash block,
* before the flash device is actually operated on.
*/
static tFlashBlockInfo blockInfo;
/** \brief Local variable with information about the flash boot block.
* \details The first block of the user program holds the vector table, which on the
* STM32 is also the where the checksum is written to. Is it likely that
* \details The first block of the user program holds the vector table, which on the
* STM32 is also the where the checksum is written to. Is it likely that
* the vector table is first flashed and then, at the end of the programming
* sequence, the checksum. This means that this flash block need to be written
* to twice. Normally this is not a problem with flash memory, as long as you
* write the same values to those bytes that are not supposed to be changed
* write the same values to those bytes that are not supposed to be changed
* and the locations where you do write to are still in the erased 0xFF state.
* Unfortunately, writing twice to flash this way, does not work reliably on
* Unfortunately, writing twice to flash this way, does not work reliably on
* all micros. This is why we need to have an extra block, the bootblock,
* placed under the management of the block manager. This way is it possible
* placed under the management of the block manager. This way is it possible
* to implement functionality so that the bootblock is only written to once
* at the end of the programming sequence.
*/
static tFlashBlockInfo bootBlockInfo;
/** \brief RAM buffer where the executable flash operation code is copied to. */
static blt_int8u flashExecCmdRam[(sizeof(flashExecCmd)/sizeof(flashExecCmd[0]))];
static blt_int8u flashExecCmdRam[(sizeof(flashExecCmd)/sizeof(flashExecCmd[0]))];
/************************************************************************************//**
** \brief Initializes the flash driver.
** \brief Initializes the flash driver.
** \return none.
**
****************************************************************************************/
@ -370,16 +370,16 @@ void FlashInit(void)
{
blt_int8u fdiv_bits = FLASH_FDIV_INVALID;
blt_int8u cnt;
/* init the flash block info structs by setting the address to an invalid address */
blockInfo.base_addr = FLASH_INVALID_ADDRESS;
bootBlockInfo.base_addr = FLASH_INVALID_ADDRESS;
/* try to find correct flash clock divider setting using the lookup table */
for (cnt=0; cnt<(sizeof(flashFDIVlookup)/sizeof(flashFDIVlookup[0])); cnt++)
{
if ( (BOOT_CPU_SYSTEM_SPEED_KHZ > flashFDIVlookup[cnt].sysclock_min) &&
(BOOT_CPU_SYSTEM_SPEED_KHZ <= flashFDIVlookup[cnt].sysclock_max) )
if ((BOOT_CPU_SYSTEM_SPEED_KHZ > flashFDIVlookup[cnt].sysclock_min) &&
(BOOT_CPU_SYSTEM_SPEED_KHZ <= flashFDIVlookup[cnt].sysclock_max))
{
/* matching configuration found in the lookup table so store it */
fdiv_bits = flashFDIVlookup[cnt].prescaler;
@ -387,12 +387,12 @@ void FlashInit(void)
break;
}
}
/* make sure that a valid configuration was found */
ASSERT_RT(fdiv_bits != FLASH_FDIV_INVALID);
/* wait until all flash commands are finished */
while((FLASH->fstat & CCIF_BIT) == 0)
while ((FLASH->fstat & CCIF_BIT) == 0)
{
;
}
@ -403,7 +403,7 @@ void FlashInit(void)
/* double check that the configuration was correctly stored because access to these
* clock divider bits can be locked.
*/
*/
ASSERT_RT((FLASH->fclkdiv & FLASH_FDIV_MASK) == fdiv_bits);
/* double check that the flash module registered the clock configuration otherwise
@ -415,30 +415,30 @@ void FlashInit(void)
/************************************************************************************//**
** \brief Writes the data to flash through a flash block manager. Note that this
** function also checks that no data is programmed outside the flash
** function also checks that no data is programmed outside the flash
** memory region, so the bootloader can never be overwritten.
** \param addr Start address.
** \param len Length in bytes.
** \param data Pointer to the data buffer.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
blt_bool FlashWrite(blt_addr addr, blt_int32u len, blt_int8u *data)
{
blt_addr base_addr;
blt_addr last_block_base_addr;
/* make sure the addresses are within the flash device */
if ( (addr < FLASH_START_ADDRESS) || ((addr+len-1) > FLASH_END_ADDRESS) )
if ((addr < FLASH_START_ADDRESS) || ((addr+len-1) > FLASH_END_ADDRESS))
{
return BLT_FALSE;
return BLT_FALSE;
}
/* determine the start address of the last block in flash */
last_block_base_addr = flashLayout[FLASH_LAST_SECTOR_IDX].sector_start + \
flashLayout[FLASH_LAST_SECTOR_IDX].sector_size - \
FLASH_WRITE_BLOCK_SIZE;
/* if this is the bootblock, then let the boot block manager handle it */
base_addr = (addr/FLASH_WRITE_BLOCK_SIZE)*FLASH_WRITE_BLOCK_SIZE;
if (base_addr == last_block_base_addr)
@ -452,12 +452,12 @@ blt_bool FlashWrite(blt_addr addr, blt_int32u len, blt_int8u *data)
/************************************************************************************//**
** \brief Erases the flash memory. Note that this function also checks that no
** data is erased outside the flash memory region, so the bootloader can
** \brief Erases the flash memory. Note that this function also checks that no
** data is erased outside the flash memory region, so the bootloader can
** never be erased.
** \param addr Start address.
** \param len Length in bytes.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
blt_bool FlashErase(blt_addr addr, blt_int32u len)
@ -467,25 +467,25 @@ blt_bool FlashErase(blt_addr addr, blt_int32u len)
blt_int32u total_erase_len;
blt_int16u block_cnt;
/* determine the base address for the erase operation, by aligning to
/* determine the base address for the erase operation, by aligning to
* FLASH_ERASE_BLOCK_SIZE.
*/
erase_base_addr = (addr/FLASH_ERASE_BLOCK_SIZE)*FLASH_ERASE_BLOCK_SIZE;
/* make sure the addresses are within the flash device */
if ( (erase_base_addr < FLASH_START_ADDRESS) || ((addr+len-1) > FLASH_END_ADDRESS) )
if ((erase_base_addr < FLASH_START_ADDRESS) || ((addr+len-1) > FLASH_END_ADDRESS))
{
return BLT_FALSE;
return BLT_FALSE;
}
/* determine number of bytes to erase from base address */
total_erase_len = len + (addr - erase_base_addr);
/* determine the number of blocks to erase */
nr_of_erase_blocks = (blt_int16u) (total_erase_len / FLASH_ERASE_BLOCK_SIZE);
nr_of_erase_blocks = (blt_int16u)(total_erase_len / FLASH_ERASE_BLOCK_SIZE);
if ((total_erase_len % FLASH_ERASE_BLOCK_SIZE) > 0)
{
nr_of_erase_blocks++;
nr_of_erase_blocks++;
}
/* erase all blocks one by one */
@ -493,18 +493,18 @@ blt_bool FlashErase(blt_addr addr, blt_int32u len)
{
/* keep the watchdog happy */
CopService();
/* erase the block */
if (FlashOperate(FLASH_ERASE_SECTOR_CMD, erase_base_addr, BLT_NULL, 0) == BLT_FALSE)
{
/* error occurred */
return BLT_FALSE;
return BLT_FALSE;
}
/* point to the next block's base address */
erase_base_addr += FLASH_ERASE_BLOCK_SIZE;
}
/* erase successful */
return BLT_TRUE;
} /*** end of FlashErase ***/
@ -516,7 +516,7 @@ blt_bool FlashErase(blt_addr addr, blt_int32u len)
** the checksum, the bootloader can check if the programming session
** was completed, which indicates that a valid user programming is
** present and can be started.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
blt_bool FlashWriteChecksum(void)
@ -525,8 +525,8 @@ blt_bool FlashWriteChecksum(void)
blt_int8u byte_counter;
blt_int16u vectab_offset;
blt_addr checksum_address;
/* for the HCS12 target we defined the checksum as the 16-bit Two's complement value
/* for the HCS12 target we defined the checksum as the 16-bit Two's complement value
* of the sum of all the 64 interrupt vector addresses, so basically a checksum over
* the contents of the entire user program interrupt vector table.
*
@ -557,8 +557,8 @@ blt_bool FlashWriteChecksum(void)
*/
for (byte_counter=0; byte_counter<FLASH_VECTOR_TABLE_SIZE; byte_counter++)
{
signature_checksum += bootBlockInfo.data[vectab_offset + byte_counter];
signature_checksum += bootBlockInfo.data[vectab_offset + byte_counter];
}
signature_checksum = ~signature_checksum; /* one's complement */
signature_checksum += 1; /* two's complement */
@ -567,15 +567,15 @@ blt_bool FlashWriteChecksum(void)
checksum_address = flashLayout[FLASH_LAST_SECTOR_IDX].sector_start + \
flashLayout[FLASH_LAST_SECTOR_IDX].sector_size - \
FLASH_VECTOR_TABLE_CS_OFFSET;
return FlashWrite(checksum_address, sizeof(signature_checksum),
(blt_int8u*)&signature_checksum);
return FlashWrite(checksum_address, sizeof(signature_checksum),
(blt_int8u *)&signature_checksum);
} /*** end of FlashWriteChecksum ***/
/************************************************************************************//**
** \brief Verifies the checksum, which indicates that a valid user program is
** present and can be started.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
blt_bool FlashVerifyChecksum(void)
@ -596,11 +596,11 @@ blt_bool FlashVerifyChecksum(void)
/* compute the checksum based on how it was written by FlashWriteChecksum() */
for (byte_counter=0; byte_counter<FLASH_VECTOR_TABLE_SIZE; byte_counter++)
{
signature_checksum += FlashGetGlobalAddrByte(vector_table_addr_glob + byte_counter);
signature_checksum += FlashGetGlobalAddrByte(vector_table_addr_glob + byte_counter);
}
/* add the 16-bit checksum value */
signature_checksum += (((blt_int16u)FlashGetGlobalAddrByte(checksum_addr_glob) << 8) +
FlashGetGlobalAddrByte(checksum_addr_glob + 1));
FlashGetGlobalAddrByte(checksum_addr_glob + 1));
/* sum should add up to an unsigned 16-bit value of 0 */
if (signature_checksum == 0)
{
@ -615,7 +615,7 @@ blt_bool FlashVerifyChecksum(void)
/************************************************************************************//**
** \brief Finalizes the flash driver operations. There could still be data in
** the currently active block that needs to be flashed.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
blt_bool FlashDone(void)
@ -630,7 +630,7 @@ blt_bool FlashDone(void)
return BLT_FALSE;
}
}
/* check if there is still data waiting to be programmed */
if (blockInfo.base_addr != FLASH_INVALID_ADDRESS)
{
@ -639,31 +639,31 @@ blt_bool FlashDone(void)
return BLT_FALSE;
}
}
/* flash operations complete, so clear the RAM buffer with operation execution code */
for (cnt=0; cnt<(sizeof(flashExecCmd)/sizeof(flashExecCmd[0])); cnt++)
{
flashExecCmdRam[cnt] = 0;
}
/* still here so all is okay */
/* still here so all is okay */
return BLT_TRUE;
} /*** end of FlashDone ***/
/************************************************************************************//**
** \brief Copies data currently in flash to the block->data and sets the
** \brief Copies data currently in flash to the block->data and sets the
** base address.
** \param block Pointer to flash block info structure to operate on.
** \param address Base address of the block data.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
static blt_bool FlashInitBlock(tFlashBlockInfo *block, blt_addr address)
{
blt_int8u oldPage;
/* check address alignment */
/* check address alignment */
if ((address % FLASH_WRITE_BLOCK_SIZE) != 0)
{
return BLT_FALSE;
@ -674,9 +674,9 @@ static blt_bool FlashInitBlock(tFlashBlockInfo *block, blt_addr address)
/* block already initialized, so nothing to do */
return BLT_TRUE;
}
/* set the base address */
/* set the base address */
block->base_addr = address;
/* backup originally selected page */
oldPage = FLASH_PPAGE_REG;
/* select correct page */
@ -703,14 +703,14 @@ static tFlashBlockInfo *FlashSwitchBlock(tFlashBlockInfo *block, blt_addr base_a
{
/* check if a switch needs to be made away from the boot block. in this case the boot
* block shouldn't be written yet, because this is done at the end of the programming
* session by FlashDone(), this is right after the checksum was written.
* session by FlashDone(), this is right after the checksum was written.
*/
if (block == &bootBlockInfo)
{
/* switch from the boot block to the generic block info structure */
block = &blockInfo;
}
/* check if a switch back into the bootblock is needed. in this case the generic block
/* check if a switch back into the bootblock is needed. in this case the generic block
* doesn't need to be written here yet.
*/
else if (base_addr == flashLayout[FLASH_LAST_SECTOR_IDX].sector_start)
@ -729,7 +729,7 @@ static tFlashBlockInfo *FlashSwitchBlock(tFlashBlockInfo *block, blt_addr base_a
}
/* initialize tne new block when necessary */
if (FlashInitBlock(block, base_addr) == BLT_FALSE)
if (FlashInitBlock(block, base_addr) == BLT_FALSE)
{
return BLT_NULL;
}
@ -751,13 +751,13 @@ static tFlashBlockInfo *FlashSwitchBlock(tFlashBlockInfo *block, blt_addr base_a
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
static blt_bool FlashAddToBlock(tFlashBlockInfo *block, blt_addr address,
static blt_bool FlashAddToBlock(tFlashBlockInfo *block, blt_addr address,
blt_int8u *data, blt_int32u len)
{
blt_addr current_base_addr;
blt_int8u *dst;
blt_int8u *src;
/* determine the current base address */
current_base_addr = (address/FLASH_WRITE_BLOCK_SIZE)*FLASH_WRITE_BLOCK_SIZE;
@ -781,7 +781,7 @@ static blt_bool FlashAddToBlock(tFlashBlockInfo *block, blt_addr address,
return BLT_FALSE;
}
}
/* add the data to the current block, but check for block overflow */
dst = &(block->data[address - block->base_addr]);
src = data;
@ -823,7 +823,7 @@ static blt_bool FlashAddToBlock(tFlashBlockInfo *block, blt_addr address,
**
****************************************************************************************/
static blt_bool FlashWriteBlock(tFlashBlockInfo *block)
{
{
blt_bool result = BLT_TRUE;
blt_bool cmd_result;
blt_int16u phrase_cnt;
@ -847,17 +847,17 @@ static blt_bool FlashWriteBlock(tFlashBlockInfo *block)
{
phrase_data[byte_cnt] = block->data[(phrase_cnt * FLASH_PHRASE_SIZE) + byte_cnt];
}
/* keep the watchdog happy */
CopService();
/* program the phrase to flash */
cmd_result = FlashOperate(FLASH_PROGRAM_PHRASE_CMD, phrase_addr,
cmd_result = FlashOperate(FLASH_PROGRAM_PHRASE_CMD, phrase_addr,
(unsigned short *)phrase_data, 4);
if (cmd_result == BLT_FALSE)
{
/* error occurred */
result = BLT_FALSE;
result = BLT_FALSE;
break;
}
@ -867,7 +867,7 @@ static blt_bool FlashWriteBlock(tFlashBlockInfo *block)
if (FlashGetGlobalAddrByte(phrase_addr+byte_cnt) != phrase_data[byte_cnt])
{
/* write verification occurred */
result = BLT_FALSE;
result = BLT_FALSE;
break;
}
}
@ -879,7 +879,7 @@ static blt_bool FlashWriteBlock(tFlashBlockInfo *block)
/************************************************************************************//**
** \brief Reads the byte value from the linear address.
** \brief Reads the byte value from the linear address.
** \param addr Linear address.
** \return The byte value located at the linear address.
**
@ -896,7 +896,7 @@ static blt_int8u FlashGetGlobalAddrByte(blt_addr addr)
FLASH_PPAGE_REG = FlashGetPhysPage(addr);
/* read the byte value from the page address */
result = *((blt_int8u*)FlashGetPhysAddr(addr));
result = *((blt_int8u *)FlashGetPhysAddr(addr));
/* restore originally selected page */
FLASH_PPAGE_REG = oldPage;
@ -907,7 +907,7 @@ static blt_int8u FlashGetGlobalAddrByte(blt_addr addr)
/************************************************************************************//**
** \brief Extracts the physical flash page number from a linear address.
** \brief Extracts the physical flash page number from a linear address.
** \param addr Linear address.
** \return The page number.
**
@ -919,8 +919,8 @@ static blt_int8u FlashGetPhysPage(blt_addr addr)
/************************************************************************************//**
** \brief Extracts the physical address on the flash page number from a
** linear address.
** \brief Extracts the physical address on the flash page number from a
** linear address.
** \param addr Linear address.
** \return The physical address.
**
@ -936,14 +936,14 @@ static blt_int16u FlashGetPhysAddr(blt_addr addr)
** stored as location independant machine code in array flashExecCmd[].
** The contents of this array are temporarily copied to RAM. This way the
** function can be executed from RAM avoiding problem when try to perform
** a flash operation on the same flash block that this driver is located on.
** a flash operation on the same flash block that this driver is located on.
** \return none.
**
****************************************************************************************/
static void FlashExecuteCommand(void)
{
/* pointer to command execution function */
pFlashExeCmdFct pExecCommandFct;
pFlashExeCmdFct pExecCommandFct;
blt_int8u cnt;
/* copy code for command execution to ram buffer */
@ -953,9 +953,9 @@ static void FlashExecuteCommand(void)
}
/* init the function pointer */
pExecCommandFct = (pFlashExeCmdFct) ((void *)flashExecCmdRam);
pExecCommandFct = (pFlashExeCmdFct)((void *)flashExecCmdRam);
/* call the command execution function */
pExecCommandFct();
pExecCommandFct();
} /*** end of FlashExecuteCommand ***/
@ -972,23 +972,23 @@ static blt_bool FlashOperate(blt_int8u cmd, blt_addr addr, blt_int16u params[],
{
blt_bool result;
blt_int8u idx;
/* set default result to error */
result = BLT_FALSE;
/* make sure the number of flash parameters is within bounds */
ASSERT_RT(param_count <= FLASH_CMD_MAX_PARAMS);
/* it is not expected that flash commands are being executed now, just make sure this
* is really the case.
*/
if ((FLASH->fstat & CCIF_BIT) == 0)
if ((FLASH->fstat & CCIF_BIT) == 0)
{
return result;
return result;
}
/* clear possibly pending error flags from the previous command */
FLASH->fstat = (FPVIOL_BIT | ACCERR_BIT);
/* clear possibly pending error flags from the previous command */
FLASH->fstat = (FPVIOL_BIT | ACCERR_BIT);
/* write the command and the address to operate on */
FLASH->fccobix = 0;
@ -996,25 +996,25 @@ static blt_bool FlashOperate(blt_int8u cmd, blt_addr addr, blt_int16u params[],
FLASH->fccobix = 1;
FLASH->fccob = (blt_int16u)addr;
/* write command paramaters one by one */
/* write command paramaters one by one */
for (idx=0; idx<param_count; idx++)
{
/* select the correct command parameter index */
FLASH->fccobix = idx + 2;
FLASH->fccobix = idx + 2;
/* write the command parameter for this index */
FLASH->fccob = params[idx];
}
/* execute the command */
FlashExecuteCommand();
/* check the results */
if ((FLASH->fstat & (ACCERR_BIT | FPVIOL_BIT)) == 0)
if ((FLASH->fstat & (ACCERR_BIT | FPVIOL_BIT)) == 0)
{
/* operation was successful */
result = BLT_TRUE;
result = BLT_TRUE;
}
return result;
} /*** end of FlashOperate ***/

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -92,12 +92,12 @@ blt_bool NvmWrite(blt_addr addr, blt_int32u len, blt_int8u *data)
* by this driver.
*/
result = NvmWriteHook(addr, len, data);
/* process the return code */
if (result == BLT_NVM_OKAY)
{
/* data was within range of the additionally supported memory and succesfully
* programmed, so we are all done.
* programmed, so we are all done.
*/
return BLT_TRUE;
}
@ -133,12 +133,12 @@ blt_bool NvmErase(blt_addr addr, blt_int32u len)
* by this driver.
*/
result = NvmEraseHook(addr, len);
/* process the return code */
if (result == BLT_NVM_OKAY)
{
/* address was within range of the additionally supported memory and succesfully
* erased, so we are all done.
* erased, so we are all done.
*/
return BLT_TRUE;
}
@ -175,7 +175,7 @@ blt_bool NvmVerifyChecksum(void)
/************************************************************************************//**
** \brief Obtains the base address of the non-volatile memory available to the user
** \brief Obtains the base address of the non-volatile memory available to the user
** program. This is typically that start of the vector table.
** \return Base address.
**
@ -187,11 +187,11 @@ blt_addr NvmGetUserProgBaseAddress(void)
/************************************************************************************//**
** \brief Once all erase and programming operations are completed, this
** function is called, so at the end of the programming session and
** \brief Once all erase and programming operations are completed, this
** function is called, so at the end of the programming session and
** right before a software reset is performed. It is used to calculate
** a checksum and program this into flash. This checksum is later used
** to determine if a valid user program is present in flash.
** to determine if a valid user program is present in flash.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
#ifndef TYPES_H

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -43,7 +43,7 @@
****************************************************************************************/
/** \brief Structure type with the layout of the UART related control registers. */
typedef volatile struct
{
{
volatile blt_int8u scibdh; /**< baudrate control register [SBR 12..8] */
volatile blt_int8u scibdl; /**< baudrate control register [SBR 8..0] */
volatile blt_int8u scicr1; /**< control register 1 */
@ -102,10 +102,10 @@ void UartInit(void)
{
blt_int16u baudrate_sbr0_12;
/* the current implementation supports SCI0 and SCI1. throw an assertion error in
* case a different UART channel is configured.
/* the current implementation supports SCI0 and SCI1. throw an assertion error in
* case a different UART channel is configured.
*/
ASSERT_CT((BOOT_COM_UART_CHANNEL_INDEX == 0) || (BOOT_COM_UART_CHANNEL_INDEX == 1));
ASSERT_CT((BOOT_COM_UART_CHANNEL_INDEX == 0) || (BOOT_COM_UART_CHANNEL_INDEX == 1));
/* reset the SCI subsystem's configuration, which automatically configures it for
* 8,n,1 communication mode.
*/
@ -114,7 +114,7 @@ void UartInit(void)
UART->scibdh = 0;
UART->scibdl = 0;
/* configure the baudrate from BOOT_COM_UART_BAUDRATE */
baudrate_sbr0_12 = (BOOT_CPU_SYSTEM_SPEED_KHZ * 1000ul) / 16 / BOOT_COM_UART_BAUDRATE;
baudrate_sbr0_12 = (BOOT_CPU_SYSTEM_SPEED_KHZ * 1000ul) / 16 / BOOT_COM_UART_BAUDRATE;
/* baudrate register value cannot be more than 13 bits */
ASSERT_RT((baudrate_sbr0_12 & 0xe000) == 0);
/* write first MSB then LSB for the baudrate to latch */
@ -138,12 +138,12 @@ void UartTransmitPacket(blt_int8u *data, blt_int8u len)
blt_bool result;
/* verify validity of the len-paramenter */
ASSERT_RT(len <= BOOT_COM_UART_TX_MAX_DATA);
ASSERT_RT(len <= BOOT_COM_UART_TX_MAX_DATA);
/* first transmit the length of the packet */
/* first transmit the length of the packet */
result = UartTransmitByte(len);
ASSERT_RT(result == BLT_TRUE);
ASSERT_RT(result == BLT_TRUE);
/* transmit all the packet bytes one-by-one */
for (data_index = 0; data_index < len; data_index++)
{
@ -151,7 +151,7 @@ void UartTransmitPacket(blt_int8u *data, blt_int8u len)
CopService();
/* write byte */
result = UartTransmitByte(data[data_index]);
ASSERT_RT(result == BLT_TRUE);
ASSERT_RT(result == BLT_TRUE);
}
} /*** end of UartTransmitPacket ***/
@ -198,7 +198,7 @@ blt_bool UartReceivePacket(blt_int8u *data)
if (xcpCtoRxLength == xcpCtoReqPacket[0])
{
/* copy the packet data */
CpuMemCopy((blt_int32u)data, (blt_int32u)&xcpCtoReqPacket[1], xcpCtoRxLength);
CpuMemCopy((blt_int32u)data, (blt_int32u)&xcpCtoReqPacket[1], xcpCtoRxLength);
/* done with cto packet reception */
xcpCtoRxInProgress = BLT_FALSE;
/* packet reception complete */
@ -231,7 +231,7 @@ blt_bool UartReceivePacket(blt_int8u *data)
static blt_bool UartReceiveByte(blt_int8u *data)
{
/* check if a new byte was received by means of the RDRF-bit */
if((UART->scisr1 & RDRF_BIT) != 0)
if ((UART->scisr1 & RDRF_BIT) != 0)
{
/* store the received byte */
data[0] = UART->scidrl;
@ -260,8 +260,8 @@ static blt_bool UartTransmitByte(blt_int8u data)
/* write byte to transmit holding register */
UART->scidrl = data;
/* wait for tx holding register to be empty */
while((UART->scisr1 & TDRE_BIT) == 0)
{
while ((UART->scisr1 & TDRE_BIT) == 0)
{
/* keep the watchdog happy */
CopService();
}

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -45,10 +45,10 @@ static void CpuWriteWDTCON0(blt_int32u uwValue);
/************************************************************************************//**
** \brief This macro clears the EndInit bit, which controls access to system critical
** registers. Clearing the EndInit bit unlocks all EndInit protectedd
** registers. Clearing the EndInit bit unlocks all EndInit protectedd
** registers. Modifications of the EndInit bit are monitored by the watchdog
** timer such that after clearing the EndInit, the watchdog timer enters a
** defined time-out mode; EndInit must be set again before the time-out
** defined time-out mode; EndInit must be set again before the time-out
** expires.
** \return none.
**
@ -58,7 +58,7 @@ void CpuEnterInitMode(void)
/* request clearing of the EndInit bit */
CpuWriteWDTCON0(WDT_CON0.reg & ~0x00000001);
/* wait for hardware handshake */
while (WDT_CON0.bits.ENDINIT != 0)
while (WDT_CON0.bits.ENDINIT != 0)
{
/* keep the watchdog happy */
CopService();
@ -94,16 +94,16 @@ static void CpuWriteWDTCON0(blt_int32u value)
/* set HWPW1 = 1111b */
dummy |= 0x000000F0;
/* set HWPW0 = WDTDR */
if(WDT_CON1.bits.DR)
if (WDT_CON1.bits.DR)
{
dummy |= 0x00000008;
dummy |= 0x00000008;
}
else
{
dummy &= ~0x00000008;
}
/* set HWPW0 = WDTIR */
if(WDT_CON1.bits.IR)
if (WDT_CON1.bits.IR)
{
dummy |= 0x00000004;
}

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
#ifndef CPU_COMP_H
@ -36,10 +36,10 @@
/****************************************************************************************
* Include files
****************************************************************************************/
#include <TC1798.h>
#include <TC1798.h>
#include <machine/intrinsics.h>
#include <machine/cint.h>
#include <sys/types.h>
#include <machine/cint.h>
#include <sys/types.h>
/****************************************************************************************
@ -48,7 +48,7 @@
/** \brief Macro for performing a processor specific desync. This part is located in the
* compiler specific part because it uses an inline assembly call.
*/
#define CpuSetDSYNC() asm("DSYNC")
#define CpuSetDSYNC() asm("DSYNC")
/****************************************************************************************

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -60,39 +60,39 @@ extern void _start(void); /* implemented in crt0-tc1
/************************************************************************************//**
** \brief Starts the user program, if one is present. In this case this function
** does not return.
** does not return.
** \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;
}
#if (BOOT_CPU_USER_PROGRAM_START_HOOK > 0)
#if (BOOT_CPU_USER_PROGRAM_START_HOOK > 0)
/* invoke callback */
if (CpuUserProgramStartHook() == BLT_FALSE)
{
/* callback requests the user program to not be started */
return;
}
#endif
#if (BOOT_COM_ENABLE > 0)
#endif
#if (BOOT_COM_ENABLE > 0)
/* release the communication interface */
ComFree();
#endif
#endif
/* reset the timer */
TimerReset();
/* set the address where the bootloader needs to jump to. the user program entry,
* typically called _start, is expected to be located at the start of the user program
* flash.
* flash.
*/
pProgResetHandler = (void(*)(void))((blt_addr*)CPU_USER_PROGRAM_STARTADDR_PTR);
pProgResetHandler = (void(*)(void))((blt_addr *)CPU_USER_PROGRAM_STARTADDR_PTR);
/* start the user program by activating its reset interrupt service routine */
pProgResetHandler();
} /*** end of CpuStartUserProgram ***/
@ -102,7 +102,7 @@ void CpuStartUserProgram(void)
** \brief Copies data from the source to the destination address.
** \param dest Destination address for the data.
** \param src Source address of the data.
** \param len length of the data in bytes.
** \param len length of the data in bytes.
** \return none.
**
****************************************************************************************/
@ -115,7 +115,7 @@ void CpuMemCopy(blt_addr dest, blt_addr src, blt_int16u len)
to = (blt_int8u *)dest;
/* copy all bytes from source address to destination address */
while(len-- > 0)
while (len-- > 0)
{
/* store byte value from source to destination */
*to++ = *from++;

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -55,7 +55,7 @@
/** \brief The flash driver is setup to operate on the cached PFLASH addresses, whereas
* the actual PFLASH commands should operate on non-cached addresses. This
* macro defines the offset between cached (80xxxxxxh) and non-cached
* macro defines the offset between cached (80xxxxxxh) and non-cached
* (A0xxxxxxh) addresses.
*/
#define FLASH_NON_CACHED_OFFSET (0x20000000u)
@ -72,7 +72,7 @@
/** \brief Base address of the PFLASH0 flash status register. */
#define FLASH_PFLASH1_FSR_ADDR (0xF8004010u)
/** \brief Macro that returns the PFLASHx modules base address, giving any address
/** \brief Macro that returns the PFLASHx modules base address, giving any address
* in PFLASH.
*/
#define FLASH_GET_PFLASH_BASE(addr) ((addr < FLASH_PFLASH1_BASE) ? \
@ -89,7 +89,7 @@
*/
#define FLASH_GET_FSR_REG_ADDR(addr) ((addr < FLASH_PFLASH1_BASE) ? \
FLASH_PFLASH0_FSR_ADDR : FLASH_PFLASH1_FSR_ADDR)
/** \brief Offset in bytes from the bootblock's base address where the checksum is
* located.
*/
@ -109,7 +109,7 @@
* Type definitions
****************************************************************************************/
/** \brief Flash sector descriptor type. */
typedef struct
typedef struct
{
blt_addr sector_start; /**< sector start address */
blt_int32u sector_size; /**< sector size in bytes */
@ -117,10 +117,10 @@ typedef struct
} tFlashSector;
/** \brief Structure type for grouping flash block information.
* \details Programming is done per block of max FLASH_WRITE_BLOCK_SIZE. for this a
* \details Programming is done per block of max FLASH_WRITE_BLOCK_SIZE. for this a
* flash block manager is implemented in this driver. this flash block manager
* depends on this flash block info structure. It holds the base address of
* the flash block and the data that should be programmed into the flash
* depends on this flash block info structure. It holds the base address of
* the flash block and the data that should be programmed into the flash
* block. The .base_addr must be a multiple of FLASH_WRITE_BLOCK_SIZE.
*/
typedef struct
@ -135,7 +135,7 @@ typedef struct
****************************************************************************************/
static blt_bool FlashInitBlock(tFlashBlockInfo *block, blt_addr address);
static tFlashBlockInfo *FlashSwitchBlock(tFlashBlockInfo *block, blt_addr base_addr);
static blt_bool FlashAddToBlock(tFlashBlockInfo *block, blt_addr address,
static blt_bool FlashAddToBlock(tFlashBlockInfo *block, blt_addr address,
blt_int8u *data, blt_int32u len);
static blt_bool FlashWriteBlock(tFlashBlockInfo *block);
static blt_bool FlashEraseSectors(blt_int8u first_sector, blt_int8u last_sector);
@ -150,10 +150,10 @@ static blt_bool FlashTricoreEraseSector(blt_addr start_addr);
* Local constant declarations
****************************************************************************************/
/** \brief Array wit the layout of the flash memory.
* \details The current implementation assumes that the bootloader is in the 2Mbyte
* \details The current implementation assumes that the bootloader is in the 2Mbyte
* PFLASH0 and supports flash operations only on the 2Mbyte PFLASH1. The reason
* for this is that a flash module cannot be in read mode and command mode at
* the same time. A future improvement is one where the actual flash command
* the same time. A future improvement is one where the actual flash command
* code is copied and run from RAM, to bypass this restriction.
*/
static const tFlashSector flashLayout[] =
@ -185,30 +185,30 @@ static const tFlashSector flashLayout[] =
****************************************************************************************/
/** \brief Local variable with information about the flash block that is currently
* being operated on.
* \details The smallest amount of flash that can be programmed is
* \details The smallest amount of flash that can be programmed is
* FLASH_WRITE_BLOCK_SIZE. A flash block manager is implemented in this driver
* and stores info in this variable. Whenever new data should be flashed, it
* is first added to a RAM buffer, which is part of this variable. Whenever
* the RAM buffer, which has the size of a flash block, is full or data needs
* to be written to a different block, the contents of the RAM buffer are
* programmed to flash. The flash block manager requires some software
* overhead, yet results is faster flash programming because data is first
* harvested, ideally until there is enough to program an entire flash block,
* to be written to a different block, the contents of the RAM buffer are
* programmed to flash. The flash block manager requires some software
* overhead, yet results is faster flash programming because data is first
* harvested, ideally until there is enough to program an entire flash block,
* before the flash device is actually operated on.
*/
static tFlashBlockInfo blockInfo;
/** \brief Local variable with information about the flash boot block.
* \details The first block of the user program holds the vector table, which on the
* STM32 is also the where the checksum is written to. Is it likely that
* \details The first block of the user program holds the vector table, which on the
* STM32 is also the where the checksum is written to. Is it likely that
* the vector table is first flashed and then, at the end of the programming
* sequence, the checksum. This means that this flash block need to be written
* to twice. Normally this is not a problem with flash memory, as long as you
* write the same values to those bytes that are not supposed to be changed
* write the same values to those bytes that are not supposed to be changed
* and the locations where you do write to are still in the erased 0xFF state.
* Unfortunately, writing twice to flash this way, does not work reliably on
* Unfortunately, writing twice to flash this way, does not work reliably on
* all micros. This is why we need to have an extra block, the bootblock,
* placed under the management of the block manager. This way is it possible
* placed under the management of the block manager. This way is it possible
* to implement functionality so that the bootblock is only written to once
* at the end of the programming sequence.
*/
@ -216,7 +216,7 @@ static tFlashBlockInfo bootBlockInfo;
/************************************************************************************//**
** \brief Initializes the flash driver.
** \brief Initializes the flash driver.
** \return none.
**
****************************************************************************************/
@ -230,12 +230,12 @@ void FlashInit(void)
/************************************************************************************//**
** \brief Writes the data to flash through a flash block manager. Note that this
** function also checks that no data is programmed outside the flash
** function also checks that no data is programmed outside the flash
** memory region, so the bootloader can never be overwritten.
** \param addr Start address.
** \param len Length in bytes.
** \param data Pointer to the data buffer.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
blt_bool FlashWrite(blt_addr addr, blt_int32u len, blt_int8u *data)
@ -243,10 +243,10 @@ blt_bool FlashWrite(blt_addr addr, blt_int32u len, blt_int8u *data)
blt_addr base_addr;
/* make sure the addresses are within the flash device */
if ( (FlashGetSector(addr) == FLASH_INVALID_SECTOR) || \
(FlashGetSector(addr+len-1) == FLASH_INVALID_SECTOR) )
if ((FlashGetSector(addr) == FLASH_INVALID_SECTOR) || \
(FlashGetSector(addr+len-1) == FLASH_INVALID_SECTOR))
{
return BLT_FALSE;
return BLT_FALSE;
}
/* if this is the bootblock, then let the boot block manager handle it */
@ -262,24 +262,24 @@ blt_bool FlashWrite(blt_addr addr, blt_int32u len, blt_int8u *data)
/************************************************************************************//**
** \brief Erases the flash memory. Note that this function also checks that no
** data is erased outside the flash memory region, so the bootloader can
** \brief Erases the flash memory. Note that this function also checks that no
** data is erased outside the flash memory region, so the bootloader can
** never be erased.
** \param addr Start address.
** \param len Length in bytes.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
blt_bool FlashErase(blt_addr addr, blt_int32u len)
{
blt_int8u first_sector;
blt_int8u last_sector;
/* obtain the first and last sector number */
first_sector = FlashGetSector(addr);
last_sector = FlashGetSector(addr+len-1);
/* check them */
if ( (first_sector == FLASH_INVALID_SECTOR) || (last_sector == FLASH_INVALID_SECTOR) )
if ((first_sector == FLASH_INVALID_SECTOR) || (last_sector == FLASH_INVALID_SECTOR))
{
return BLT_FALSE;
}
@ -294,7 +294,7 @@ blt_bool FlashErase(blt_addr addr, blt_int32u len)
** the checksum, the bootloader can check if the programming session
** was completed, which indicates that a valid user programming is
** present and can be started.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
blt_bool FlashWriteChecksum(void)
@ -304,16 +304,16 @@ blt_bool FlashWriteChecksum(void)
/* for the Tricore TC1798 target, the bootlblock is FLASH_WRITE_BLOCK_SIZE in size.
* the actual 32-bit checksum value in this bootblock is located at:
* <bootblock_base_addr> + 4.
* <bootblock_base_addr> + 4.
* for this reason the checksum is defined as the one's complement value of the sum
* of everything else in the bootblock, so starting at:
* <bootblock_base_addr> + 8 and ending at:
* <bootblock_base_addr> + FLASH_WRITE_BLOCK_SIZE - 1;
*
* note that the user program need to be modified to reserve 32-bit at
*
* note that the user program need to be modified to reserve 32-bit at
* <bootblock_base_addr> + 4, because the bootload will write the checksum value
* here. refer to the port specific documentation for additional details.
*
*
* keep in mind that this checksum is just used as a user program signature, i.e. as
* a flag to figure out if a user program is present or not. the checksum is not
* calculated over the full user program size. such a checksum routine is typically
@ -323,35 +323,35 @@ blt_bool FlashWriteChecksum(void)
* You can then implement your own checksum write/verify routines in the hook
* functions NvmWriteChecksumHook() and NvmVerifyChecksumHook().
*/
/* first check that the bootblock contains valid data. if not, this means the
* bootblock is not part of the reprogramming this time and therefore no
* new checksum needs to be written
*/
if (bootBlockInfo.base_addr == FLASH_INVALID_ADDRESS)
{
if (bootBlockInfo.base_addr == FLASH_INVALID_ADDRESS)
{
return BLT_TRUE;
}
}
/* compute the checksum. note that the data in the checksum range is not yet written
* to flash but is present in the bootblock data structure at this point.
*/
for (wordIdx = 0; wordIdx < FLASH_CS_RANGE_TOTAL_WORDS; wordIdx++)
{
signature_checksum += *((blt_int32u*)(&bootBlockInfo.data[(wordIdx*4)+FLASH_CS_RANGE_START_OFFSET]));
}
signature_checksum += *((blt_int32u *)(&bootBlockInfo.data[(wordIdx*4)+FLASH_CS_RANGE_START_OFFSET]));
}
signature_checksum = ~signature_checksum; /* one's complement */
/* write the checksum */
return FlashWrite(flashLayout[0].sector_start+FLASH_CS_OFFSET,
sizeof(blt_addr), (blt_int8u*)&signature_checksum);
return FlashWrite(flashLayout[0].sector_start+FLASH_CS_OFFSET,
sizeof(blt_addr), (blt_int8u *)&signature_checksum);
} /*** end of FlashWriteChecksum ***/
/************************************************************************************//**
** \brief Verifies the checksum, which indicates that a valid user program is
** present and can be started.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
blt_bool FlashVerifyChecksum(void)
@ -363,14 +363,14 @@ blt_bool FlashVerifyChecksum(void)
/* compute the checksum by reading it from flash */
for (wordIdx = 0; wordIdx < FLASH_CS_RANGE_TOTAL_WORDS; wordIdx++)
{
signature_checksum += *((blt_int32u*)(flashLayout[0].sector_start + (wordIdx*4) + FLASH_CS_RANGE_START_OFFSET));
}
signature_checksum += *((blt_int32u *)(flashLayout[0].sector_start + (wordIdx*4) + FLASH_CS_RANGE_START_OFFSET));
}
signature_checksum = ~signature_checksum; /* one's complement */
/* read the checksum value from flash that was writtin by the bootloader at the end
* of the last firmware update
*/
signature_checksum_rom = *((blt_int32u*)(flashLayout[0].sector_start + FLASH_CS_OFFSET));
signature_checksum_rom = *((blt_int32u *)(flashLayout[0].sector_start + FLASH_CS_OFFSET));
/* verify that they are both the same */
if (signature_checksum == signature_checksum_rom)
{
@ -385,7 +385,7 @@ blt_bool FlashVerifyChecksum(void)
/************************************************************************************//**
** \brief Finalizes the flash driver operations. There could still be data in
** the currently active block that needs to be flashed.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
blt_bool FlashDone(void)
@ -398,7 +398,7 @@ blt_bool FlashDone(void)
return BLT_FALSE;
}
}
/* check if there is still data waiting to be programmed */
if (blockInfo.base_addr != FLASH_INVALID_ADDRESS)
{
@ -407,7 +407,7 @@ blt_bool FlashDone(void)
return BLT_FALSE;
}
}
/* still here so all is okay */
/* still here so all is okay */
return BLT_TRUE;
} /*** end of FlashDone ***/
@ -425,16 +425,16 @@ blt_addr FlashGetUserProgBaseAddress(void)
/************************************************************************************//**
** \brief Copies data currently in flash to the block->data and sets the
** \brief Copies data currently in flash to the block->data and sets the
** base address.
** \param block Pointer to flash block info structure to operate on.
** \param address Base address of the block data.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
static blt_bool FlashInitBlock(tFlashBlockInfo *block, blt_addr address)
{
/* check address alignment */
/* check address alignment */
if ((address % FLASH_WRITE_BLOCK_SIZE) != 0)
{
return BLT_FALSE;
@ -445,8 +445,8 @@ static blt_bool FlashInitBlock(tFlashBlockInfo *block, blt_addr address)
/* block already initialized, so nothing to do */
return BLT_TRUE;
}
/* set the base address and copies the current data from flash */
block->base_addr = address;
/* set the base address and copies the current data from flash */
block->base_addr = address;
CpuMemCopy((blt_addr)block->data, address, FLASH_WRITE_BLOCK_SIZE);
return BLT_TRUE;
} /*** end of FlashInitBlock ***/
@ -465,14 +465,14 @@ static tFlashBlockInfo *FlashSwitchBlock(tFlashBlockInfo *block, blt_addr base_a
{
/* check if a switch needs to be made away from the boot block. in this case the boot
* block shouldn't be written yet, because this is done at the end of the programming
* session by FlashDone(), this is right after the checksum was written.
* session by FlashDone(), this is right after the checksum was written.
*/
if (block == &bootBlockInfo)
{
/* switch from the boot block to the generic block info structure */
block = &blockInfo;
}
/* check if a switch back into the bootblock is needed. in this case the generic block
/* check if a switch back into the bootblock is needed. in this case the generic block
* doesn't need to be written here yet.
*/
else if (base_addr == flashLayout[0].sector_start)
@ -491,7 +491,7 @@ static tFlashBlockInfo *FlashSwitchBlock(tFlashBlockInfo *block, blt_addr base_a
}
/* initialize tne new block when necessary */
if (FlashInitBlock(block, base_addr) == BLT_FALSE)
if (FlashInitBlock(block, base_addr) == BLT_FALSE)
{
return BLT_NULL;
}
@ -513,13 +513,13 @@ static tFlashBlockInfo *FlashSwitchBlock(tFlashBlockInfo *block, blt_addr base_a
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/
static blt_bool FlashAddToBlock(tFlashBlockInfo *block, blt_addr address,
static blt_bool FlashAddToBlock(tFlashBlockInfo *block, blt_addr address,
blt_int8u *data, blt_int32u len)
{
blt_addr current_base_addr;
blt_int8u *dst;
blt_int8u *src;
/* determine the current base address */
current_base_addr = (address/FLASH_WRITE_BLOCK_SIZE)*FLASH_WRITE_BLOCK_SIZE;
@ -543,7 +543,7 @@ static blt_bool FlashAddToBlock(tFlashBlockInfo *block, blt_addr address,
return BLT_FALSE;
}
}
/* add the data to the current block, but check for block overflow */
dst = &(block->data[address - block->base_addr]);
src = data;
@ -597,7 +597,7 @@ static blt_bool FlashWriteBlock(tFlashBlockInfo *block)
/* the FLASH_WRITE_BLOCK_SIZE is configured to exactly match the size of a page in
* PFLASH. so here simply need to program one page in PFLASH.
*/
return FlashTricoreProgramPage(block->base_addr, block->data);
return FlashTricoreProgramPage(block->base_addr, block->data);
} /*** end of FlashWriteBlock ***/
@ -618,8 +618,8 @@ static blt_bool FlashEraseSectors(blt_int8u first_sector, blt_int8u last_sector)
{
return BLT_FALSE;
}
if ( (first_sector < flashLayout[0].sector_num) || \
(last_sector > flashLayout[FLASH_TOTAL_SECTORS-1].sector_num) )
if ((first_sector < flashLayout[0].sector_num) || \
(last_sector > flashLayout[FLASH_TOTAL_SECTORS-1].sector_num))
{
return BLT_FALSE;
}
@ -652,16 +652,16 @@ static blt_bool FlashEraseSectors(blt_int8u first_sector, blt_int8u last_sector)
static blt_int8u FlashGetSector(blt_addr address)
{
blt_int8u sectorIdx;
/* search through the sectors to find the right one */
for (sectorIdx = 0; sectorIdx < FLASH_TOTAL_SECTORS; sectorIdx++)
{
/* keep the watchdog happy */
CopService();
/* is the address in this sector? */
if ( (address >= flashLayout[sectorIdx].sector_start) && \
(address < (flashLayout[sectorIdx].sector_start + \
flashLayout[sectorIdx].sector_size)) )
if ((address >= flashLayout[sectorIdx].sector_start) && \
(address < (flashLayout[sectorIdx].sector_start + \
flashLayout[sectorIdx].sector_size)))
{
/* return the sector number */
return flashLayout[sectorIdx].sector_num;
@ -681,7 +681,7 @@ static blt_int8u FlashGetSector(blt_addr address)
static blt_addr FlashGetSectorBaseAddr(blt_int8u sector)
{
blt_int8u sectorIdx;
/* search through the sectors to find the right one */
for (sectorIdx = 0; sectorIdx < FLASH_TOTAL_SECTORS; sectorIdx++)
{
@ -706,7 +706,7 @@ static blt_addr FlashGetSectorBaseAddr(blt_int8u sector)
static blt_int32u FlashGetSectorSize(blt_int8u sector)
{
blt_int8u sectorIdx;
/* search through the sectors to find the right one */
for (sectorIdx = 0; sectorIdx < FLASH_TOTAL_SECTORS; sectorIdx++)
{
@ -739,7 +739,7 @@ static blt_bool FlashTricoreProgramPage(blt_addr start_addr, blt_int8u *data)
blt_int8u *readPtr;
blt_int32u idx;
FLASHn_FSR_t *pflashFSR;
/* check address alignment to a page in PFLASH */
if ((start_addr % FLASH_WRITE_BLOCK_SIZE) != 0)
{
@ -756,23 +756,23 @@ static blt_bool FlashTricoreProgramPage(blt_addr start_addr, blt_int8u *data)
/* perform DSYNC */
CpuSetDSYNC();
/* wait until FSR.xFPAGE = '1' */
while(pflashFSR->bits.PFPAGE != 1)
{
while (pflashFSR->bits.PFPAGE != 1)
{
/* fail if FSR.SQER = '1' */
if (pflashFSR->bits.SQER == 1)
{
return BLT_FALSE;
}
if (pflashFSR->bits.SQER == 1)
{
return BLT_FALSE;
}
/* fail if FSR.PROER = '1' */
if (pflashFSR->bits.PROER == 1)
{
return BLT_FALSE;
}
if (pflashFSR->bits.PROER == 1)
{
return BLT_FALSE;
}
/* keep the watchdog happy */
CopService();
}
}
/* load FLASH_WRITE_BLOCK_SIZE bytes of program data into the assembly buffer */
dataPtr = (blt_int32u *)data;
dataPtr = (blt_int32u *)data;
for (idx = 0; idx <(FLASH_WRITE_BLOCK_SIZE/8u); idx++)
{
/* write first 32-bit value */
@ -790,55 +790,55 @@ static blt_bool FlashTricoreProgramPage(blt_addr start_addr, blt_int8u *data)
/* perform DSYNC */
CpuSetDSYNC();
/* wait until FSR.PROG = '1' */
while(pflashFSR->bits.PROG != 1)
{
while (pflashFSR->bits.PROG != 1)
{
/* fail if FSR.SQER = '1' */
if (pflashFSR->bits.SQER == 1)
{
return BLT_FALSE;
}
if (pflashFSR->bits.SQER == 1)
{
return BLT_FALSE;
}
/* fail if FSR.PROER = '1' */
if (pflashFSR->bits.PROER == 1)
{
return BLT_FALSE;
}
if (pflashFSR->bits.PROER == 1)
{
return BLT_FALSE;
}
/* keep the watchdog happy */
CopService();
}
}
/* wait until FSR.xBUSY = '0' */
while(pflashFSR->bits.PBUSY == 1)
{
while (pflashFSR->bits.PBUSY == 1)
{
/* check flag FSR.xFOPER for 1 as abort criterion to protect against hardware
* failures causing BUSY to stay '1'
*/
if (pflashFSR->bits.PFOPER == 1)
{
return BLT_FALSE;
}
if (pflashFSR->bits.PFOPER == 1)
{
return BLT_FALSE;
}
/* keep the watchdog happy */
CopService();
}
}
/* check FSR.VER flag */
if (pflashFSR->bits.VER != 0)
{
return BLT_FALSE;
}
if (pflashFSR->bits.VER != 0)
{
return BLT_FALSE;
}
/* fail if FSR.xFOPER = '1' */
if (pflashFSR->bits.PFOPER != 0)
{
return BLT_FALSE;
}
if (pflashFSR->bits.PFOPER != 0)
{
return BLT_FALSE;
}
/* evaluate FSR.xDBER */
if(pflashFSR->bits.PFDBER != 0)
{
return BLT_FALSE;
}
if (pflashFSR->bits.PFDBER != 0)
{
return BLT_FALSE;
}
/* use "clear status" command to clear flags */
FLASH_WRITE_TO_U32_PTR_BY_ADDR(baseAddr + 0x5554u, 0x000000F5u);
/* perform verification by checking the written values. do this on a byte-per-byte
* basis to also check the code for byte swapping mistakes.
/* perform verification by checking the written values. do this on a byte-per-byte
* basis to also check the code for byte swapping mistakes.
*/
readPtr = (blt_int8u *)start_addr;
readPtr = (blt_int8u *)start_addr;
for (idx = 0; idx <FLASH_WRITE_BLOCK_SIZE; idx++)
{
/* verify 32-bits at a time */
@ -869,7 +869,7 @@ static blt_bool FlashTricoreEraseSector(blt_addr start_addr)
blt_int8u sectorNum;
blt_int32u *readPtr;
blt_int32u idx;
/* determine base address of the PFLASH module */
baseAddr = FLASH_GET_PFLASH_BASE(start_addr);
/* set pointer for the PFLASH module's FSR register */
@ -885,49 +885,49 @@ static blt_bool FlashTricoreEraseSector(blt_addr start_addr)
FLASH_WRITE_TO_U32_PTR_BY_ADDR(start_addr, 0x00000030u);
/* perform DSYNC */
CpuSetDSYNC();
/* wait until FSR.ERASE = '1' */
while(pflashFSR->bits.ERASE != 1)
{
/* wait until FSR.ERASE = '1' */
while (pflashFSR->bits.ERASE != 1)
{
/* fail if FSR.SQER = '1' */
if (pflashFSR->bits.SQER == 1)
{
return BLT_FALSE;
}
if (pflashFSR->bits.SQER == 1)
{
return BLT_FALSE;
}
/* fail if FSR.PROER = '1' */
if (pflashFSR->bits.PROER == 1)
{
return BLT_FALSE;
}
if (pflashFSR->bits.PROER == 1)
{
return BLT_FALSE;
}
/* keep the watchdog happy */
CopService();
}
}
/* wait until FSR.xBUSY = '0' */
while(pflashFSR->bits.PBUSY == 1)
{
while (pflashFSR->bits.PBUSY == 1)
{
/* check flag FSR.xFOPER for 1 as abort criterion to protect against hardware
* failures causing BUSY to stay '1'
*/
if (pflashFSR->bits.PFOPER == 1)
{
return BLT_FALSE;
}
if (pflashFSR->bits.PFOPER == 1)
{
return BLT_FALSE;
}
/* keep the watchdog happy */
CopService();
}
}
/* check FSR.VER flag */
if (pflashFSR->bits.VER != 0)
{
return BLT_FALSE;
}
if (pflashFSR->bits.VER != 0)
{
return BLT_FALSE;
}
/* fail if FSR.xFOPER = '1' */
if (pflashFSR->bits.PFOPER != 0)
{
return BLT_FALSE;
}
if (pflashFSR->bits.PFOPER != 0)
{
return BLT_FALSE;
}
/* use "clear status" command to clear flags */
FLASH_WRITE_TO_U32_PTR_BY_ADDR(baseAddr + 0x5554u, 0x000000F5u);
/* perform erase verification */
/* perform erase verification */
sectorNum = FlashGetSector(start_addr);
if (sectorNum == FLASH_INVALID_SECTOR)
{

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
#ifndef FLASH_H

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -93,12 +93,12 @@ blt_bool NvmWrite(blt_addr addr, blt_int32u len, blt_int8u *data)
* by this driver.
*/
result = NvmWriteHook(addr, len, data);
/* process the return code */
if (result == BLT_NVM_OKAY)
{
/* data was within range of the additionally supported memory and succesfully
* programmed, so we are all done.
* programmed, so we are all done.
*/
return BLT_TRUE;
}
@ -134,12 +134,12 @@ blt_bool NvmErase(blt_addr addr, blt_int32u len)
* by this driver.
*/
result = NvmEraseHook(addr, len);
/* process the return code */
if (result == BLT_NVM_OKAY)
{
/* address was within range of the additionally supported memory and succesfully
* erased, so we are all done.
* erased, so we are all done.
*/
return BLT_TRUE;
}
@ -176,7 +176,7 @@ blt_bool NvmVerifyChecksum(void)
/************************************************************************************//**
** \brief Obtains the base address of the non-volatile memory available to the user
** \brief Obtains the base address of the non-volatile memory available to the user
** program. This is typically that start of the vector table.
** \return Base address.
**
@ -188,11 +188,11 @@ blt_addr NvmGetUserProgBaseAddress(void)
/************************************************************************************//**
** \brief Once all erase and programming operations are completed, this
** function is called, so at the end of the programming session and
** \brief Once all erase and programming operations are completed, this
** function is called, so at the end of the programming session and
** right before a software reset is performed. It is used to calculate
** a checksum and program this into flash. This checksum is later used
** to determine if a valid user program is present in flash.
** to determine if a valid user program is present in flash.
** \return BLT_TRUE if successful, BLT_FALSE otherwise.
**
****************************************************************************************/

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -46,7 +46,7 @@
*/
static blt_int32u millisecond_counter;
/** \brief Holds the timer tick count for 1 millisecond. */
/** \brief Holds the timer tick count for 1 millisecond. */
static blt_int16u millisecond_ticks;
@ -58,13 +58,13 @@ static blt_int16u millisecond_ticks;
void TimerInit(void)
{
blt_int32u dummy;
/* reset the timer configuration */
TimerReset();
/* obtain "E" access rights */
CpuEnterInitMode();
/* enable the GPT12 timer module */
GPT120_CLC.reg = 0x00000000;
GPT120_CLC.reg = 0x00000000;
/* dummy read to avoid pipeline effects */
dummy = GPT120_CLC.reg;
/* release "E" access rights */
@ -80,7 +80,7 @@ void TimerInit(void)
*/
GPT120_T3CON.reg = 0x00000845;
/* reset the timer 3 register so that counter starts at 0 */
GPT120_T3.reg = 0x00000000;
GPT120_T3.reg = 0x00000000;
/* calculate the number of timer ticks in 1 millisecond */
millisecond_ticks = ((blt_int32u)BOOT_CPU_SYSTEM_SPEED_KHZ / 128);
/* reset the millisecond counter value */
@ -100,11 +100,11 @@ void TimerReset(void)
/* revert back to timer 3 configuration reset value */
GPT120_T3CON.reg = 0x00000000;
/* revert back to timer 3 reset value */
GPT120_T3.reg = 0x00000000;
GPT120_T3.reg = 0x00000000;
/* obtain "E" access rights */
CpuEnterInitMode();
/* disable the GPT12 timer module */
GPT120_CLC.reg = 0x00000003;
GPT120_CLC.reg = 0x00000003;
/* dummy read to avoid pipeline effects */
dummy = GPT120_CLC.reg;
/* release "E" access rights */

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
#ifndef TYPES_H

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -44,23 +44,23 @@
****************************************************************************************/
typedef struct
{
blt_int32u reserved0[0x1]; /* 0x0 */
ASCn_PISEL_t PISEL; /* 0x4 */
ASCn_ID_t ID; /* 0x8 */
blt_int32u reserved3[0x1]; /* 0xc */
ASCn_CON_t CON; /* 0x10 */
ASCn_BG_t BG; /* 0x14 */
ASCn_FDV_t FDV; /* 0x18 */
blt_int32u reserved7[0x1]; /* 0x1c */
ASCn_TBUF_t TBUF; /* 0x20 */
ASCn_RBUF_t RBUF; /* 0x24 */
blt_int32u reserved10[0xa]; /* 0x28 */
ASCn_WHBCON_t WHBCON; /* 0x50 */
blt_int32u reserved12[0x27]; /* 0x54 */
ASCn_TSRC_t TSRC; /* 0xf0 */
ASCn_RSRC_t RSRC; /* 0xf4 */
ASCn_ESRC_t ESRC; /* 0xf8 */
ASCn_TBSRC_t TBSRC; /* 0xfc */
blt_int32u reserved0[0x1]; /* 0x0 */
ASCn_PISEL_t PISEL; /* 0x4 */
ASCn_ID_t ID; /* 0x8 */
blt_int32u reserved3[0x1]; /* 0xc */
ASCn_CON_t CON; /* 0x10 */
ASCn_BG_t BG; /* 0x14 */
ASCn_FDV_t FDV; /* 0x18 */
blt_int32u reserved7[0x1]; /* 0x1c */
ASCn_TBUF_t TBUF; /* 0x20 */
ASCn_RBUF_t RBUF; /* 0x24 */
blt_int32u reserved10[0xa]; /* 0x28 */
ASCn_WHBCON_t WHBCON; /* 0x50 */
blt_int32u reserved12[0x27]; /* 0x54 */
ASCn_TSRC_t TSRC; /* 0xf0 */
ASCn_RSRC_t RSRC; /* 0xf4 */
ASCn_ESRC_t ESRC; /* 0xf8 */
ASCn_TBSRC_t TBSRC; /* 0xfc */
} tUartRegs;
@ -104,33 +104,33 @@ void UartInit(void)
{
blt_int32u frequency, reload_value, fdv, dfreq;
/* Compute system frequency and reload value for ASC */
frequency = BOOT_CPU_SYSTEM_SPEED_KHZ * 1000;
/* Compute system frequency and reload value for ASC */
frequency = BOOT_CPU_SYSTEM_SPEED_KHZ * 1000;
/* reload_value = fdv/512 * freq/16/baudrate -1 ==>
/* reload_value = fdv/512 * freq/16/baudrate -1 ==>
* reload_value = (512*freq)/(baudrate * 512*16) - 1
* fdv = (reload_value + 1) * (baudrate*512*16/freq)
* reload_value = (frequency / 32) / baudrate - 1;
*/
reload_value = (frequency / ((blt_int32u)BOOT_COM_UART_BAUDRATE * 16)) - 1;
dfreq = frequency / (16*512);
fdv = (reload_value + 1) * (blt_int32u)BOOT_COM_UART_BAUDRATE / dfreq;
*/
reload_value = (frequency / ((blt_int32u)BOOT_COM_UART_BAUDRATE * 16)) - 1;
dfreq = frequency / (16*512);
fdv = (reload_value + 1) * (blt_int32u)BOOT_COM_UART_BAUDRATE / dfreq;
/* enable ASC module */
CpuEnterInitMode();
ASC0_CLC.bits.RMC = 1;
ASC0_CLC.bits.DISR = 0;
CpuLeaveInitMode();
/* enable ASC module */
CpuEnterInitMode();
ASC0_CLC.bits.RMC = 1;
ASC0_CLC.bits.DISR = 0;
CpuLeaveInitMode();
/* configure the ASC module for 8,n,1 */
UARTx->CON.reg = 0;
UARTx->BG.reg = reload_value;
UARTx->FDV.reg = fdv;
UARTx->BG.reg = reload_value;
UARTx->FDV.reg = fdv;
UARTx->CON.bits.M = 0x01;
UARTx->CON.bits.R = 1;
UARTx->CON.bits.REN = 1;
UARTx->CON.bits.FDE = 1;
UARTx->CON.bits.M = 0x01;
UARTx->CON.bits.R = 1;
UARTx->CON.bits.REN = 1;
UARTx->CON.bits.FDE = 1;
} /*** end of UartInit ***/
@ -147,12 +147,12 @@ void UartTransmitPacket(blt_int8u *data, blt_int8u len)
blt_bool result;
/* verify validity of the len-paramenter */
ASSERT_RT(len <= BOOT_COM_UART_TX_MAX_DATA);
ASSERT_RT(len <= BOOT_COM_UART_TX_MAX_DATA);
/* first transmit the length of the packet */
/* first transmit the length of the packet */
result = UartTransmitByte(len);
ASSERT_RT(result == BLT_TRUE);
ASSERT_RT(result == BLT_TRUE);
/* transmit all the packet bytes one-by-one */
for (data_index = 0; data_index < len; data_index++)
{
@ -160,7 +160,7 @@ void UartTransmitPacket(blt_int8u *data, blt_int8u len)
CopService();
/* write byte */
result = UartTransmitByte(data[data_index]);
ASSERT_RT(result == BLT_TRUE);
ASSERT_RT(result == BLT_TRUE);
}
} /*** end of UartTransmitPacket ***/
@ -207,7 +207,7 @@ blt_bool UartReceivePacket(blt_int8u *data)
if (xcpCtoRxLength == xcpCtoReqPacket[0])
{
/* copy the packet data */
CpuMemCopy((blt_int32u)data, (blt_int32u)&xcpCtoReqPacket[1], xcpCtoRxLength);
CpuMemCopy((blt_int32u)data, (blt_int32u)&xcpCtoReqPacket[1], xcpCtoRxLength);
/* done with cto packet reception */
xcpCtoRxInProgress = BLT_FALSE;
/* packet reception complete */
@ -249,7 +249,7 @@ static blt_bool UartReceiveByte(blt_int8u *data)
/* reset the reception event flag */
UARTx->RSRC.bits.CLRR = 1;
/* set result to indicate that a new byte was received */
result = BLT_TRUE;
result = BLT_TRUE;
}
/* inform caller about the result */
@ -270,10 +270,10 @@ static blt_bool UartTransmitByte(blt_int8u data)
/* write byte to transmit buffer register */
UARTx->TBUF.reg = data;
/* wait for transmit buffer register to be empty */
while(UARTx->TBSRC.bits.SRR == 0)
while (UARTx->TBSRC.bits.SRR == 0)
{
CopService();
}
}
/* byte transmitted */
return BLT_TRUE;
} /*** end of UartTransmitByte ***/

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -48,7 +48,7 @@ static volatile blt_int32u assert_failure_line;
/************************************************************************************//**
** \brief Called when a runtime assertion failed. It stores information about where
** \brief Called when a runtime assertion failed. It stores information about where
** the assertion occurred and halts the software program.
** \param file Name of the source file where the assertion occurred.
** \param line Linenumber in the source file where the assertion occurred.
@ -61,10 +61,10 @@ void AssertFailure(blt_char *file, blt_int32u line)
assert_failure_file = file;
assert_failure_line = line;
/* hang the software so that it requires a hard reset */
for(;;)
{
for (;;)
{
/* keep servicing the watchdog so that this one does not cause a reset */
CopService();
CopService();
}
} /*** end of AssertFailure ***/
#endif /* !NDEBUG */

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
#ifndef ASSERT_H
@ -40,15 +40,15 @@
* for runtime assertions.
*/
#ifdef NDEBUG
#define ASSERT_CT(cond) ((void)0)
#define ASSERT_RT(cond) ((void)0)
#else
#define ASSERT_CONCAT_(a, b) a##b
#define ASSERT_CONCAT(a, b) ASSERT_CONCAT_(a, b)
/** \brief Macro for assertions that can be performed at compile time. */
#define ASSERT_CT(cond) enum { ASSERT_CONCAT(assert_error_on_line_, __LINE__) = 1/(!!(cond)) }
/** \brief Macro for assertions that can only be performed at run time. */
#define ASSERT_RT(cond) \
#define ASSERT_CT(cond) ((void)0)
#define ASSERT_RT(cond) ((void)0)
#else
#define ASSERT_CONCAT_(a, b) a##b
#define ASSERT_CONCAT(a, b) ASSERT_CONCAT_(a, b)
/** \brief Macro for assertions that can be performed at compile time. */
#define ASSERT_CT(cond) enum { ASSERT_CONCAT(assert_error_on_line_, __LINE__) = 1/(!!(cond)) }
/** \brief Macro for assertions that can only be performed at run time. */
#define ASSERT_RT(cond) \
if (cond) \
{ ; } \
else \

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -41,25 +41,25 @@
* Macro definitions
****************************************************************************************/
#if (BOOT_BACKDOOR_HOOKS_ENABLE == 0)
#ifndef BACKDOOR_ENTRY_TIMEOUT_MS
/** \brief Sets the time in milliseconds that the backdoor is open, but allow an
* override for this time. note that this time should be at least 2.5 times
* as long as the time that is configured in Microboot's XCP settings for the
* connect command response. This is the last entry on XCP Timeouts tab. By
* default the connect command response is configured as 20ms by Microboot,
* except for TCP/IP where it is 300ms due to accomodate for worldwide
* network latency. The default value was chosen safely for compatibility
* reasons with all supported communication interfaces. It could be made
* shorter your bootloader. To change this value, simply add the macro
* BACKDOOR_ENTRY_TIMEOUT_MS to blt_conf.h with your desired backdoor open time
* in milliseconds.
*/
#if (BOOT_COM_NET_ENABLE == 1)
#define BACKDOOR_ENTRY_TIMEOUT_MS (750)
#else
#define BACKDOOR_ENTRY_TIMEOUT_MS (500)
#endif
#endif
#ifndef BACKDOOR_ENTRY_TIMEOUT_MS
/** \brief Sets the time in milliseconds that the backdoor is open, but allow an
* override for this time. note that this time should be at least 2.5 times
* as long as the time that is configured in Microboot's XCP settings for the
* connect command response. This is the last entry on XCP Timeouts tab. By
* default the connect command response is configured as 20ms by Microboot,
* except for TCP/IP where it is 300ms due to accomodate for worldwide
* network latency. The default value was chosen safely for compatibility
* reasons with all supported communication interfaces. It could be made
* shorter your bootloader. To change this value, simply add the macro
* BACKDOOR_ENTRY_TIMEOUT_MS to blt_conf.h with your desired backdoor open time
* in milliseconds.
*/
#if (BOOT_COM_NET_ENABLE == 1)
#define BACKDOOR_ENTRY_TIMEOUT_MS (750)
#else
#define BACKDOOR_ENTRY_TIMEOUT_MS (500)
#endif
#endif
#endif
/****************************************************************************************
@ -92,22 +92,22 @@ void BackDoorInit(void)
#if (BOOT_BACKDOOR_HOOKS_ENABLE > 0)
/* initialize application's backdoor functionality */
BackDoorInitHook();
/* attempt to start the user program when no backdoor entry is requested */
if (BackDoorEntryHook() == BLT_FALSE)
{
/* this function does not return if a valid user program is present */
CpuStartUserProgram();
}
#if (BOOT_FILE_SYS_ENABLE > 0)
#if (BOOT_FILE_SYS_ENABLE > 0)
else
{
/* the backdoor is open so we should check if a update from locally attached storage
/* the backdoor is open so we should check if a update from locally attached storage
* is requested and, if so, start it.
*/
FileHandleFirmwareUpdateRequest();
}
#endif
#endif
#else
/* open the backdoor after a reset */
backdoorOpen = BLT_TRUE;
@ -129,26 +129,26 @@ void BackDoorInit(void)
void BackDoorCheck(void)
{
#if (BOOT_BACKDOOR_HOOKS_ENABLE == 0)
#if (BOOT_COM_ENABLE > 0)
#if (BOOT_COM_ENABLE > 0)
/* check if a connection with the host was already established. in this case the
* backdoor stays open anyway, so no need to check if it needs to be closed.
* backdoor stays open anyway, so no need to check if it needs to be closed.
*/
if (ComIsConnected() == BLT_TRUE)
{
return;
}
#endif
#if (BOOT_FILE_SYS_ENABLE > 0)
#endif
#if (BOOT_FILE_SYS_ENABLE > 0)
/* check if the file module is busy, indicating that a firmware update through the
* locally attached storage is in progress. in this case the backdoor stays open
* anyway, so no need to check if it needs to be closed.
* locally attached storage is in progress. in this case the backdoor stays open
* anyway, so no need to check if it needs to be closed.
*/
if (FileIsIdle() == BLT_FALSE)
{
return;
}
#endif
#endif
/* when the backdoor is still open, check if it's time to close it */
if (backdoorOpen == BLT_TRUE)
{
@ -157,13 +157,13 @@ void BackDoorCheck(void)
{
/* close the backdoor */
backdoorOpen = BLT_FALSE;
#if (BOOT_FILE_SYS_ENABLE > 0)
#if (BOOT_FILE_SYS_ENABLE > 0)
/* during the timed backdoor no remote update request was detected. now do one
* last check to see if a firmware update from locally attached storage is
* pending.
*/
if (FileHandleFirmwareUpdateRequest() == BLT_FALSE)
#endif
#endif
{
/* no firmware update requests detected, so attempt to start the user program.
* this function does not return if a valid user program is present.

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
#ifndef BACKDOOR_H

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -38,7 +38,7 @@
/************************************************************************************//**
** \brief Initializes the bootloader core.
** \brief Initializes the bootloader core.
** \return none
**
****************************************************************************************/
@ -50,21 +50,21 @@ void BootInit(void)
TimerInit();
/* initialize the non-volatile memory driver */
NvmInit();
#if (BOOT_FILE_SYS_ENABLE > 0)
#if (BOOT_FILE_SYS_ENABLE > 0)
/* initialize the file system module */
FileInit();
#endif
#if (BOOT_COM_ENABLE > 0)
#endif
#if (BOOT_COM_ENABLE > 0)
/* initialize the communication module */
ComInit();
#endif
#endif
/* initialize the backdoor entry */
BackDoorInit();
} /*** end of BootInit ***/
/************************************************************************************//**
** \brief Task function of the bootloader core that drives the program.
** \brief Task function of the bootloader core that drives the program.
** \return none
**
****************************************************************************************/
@ -74,14 +74,14 @@ void BootTask(void)
CopService();
/* update the millisecond timer */
TimerUpdate();
#if (BOOT_FILE_SYS_ENABLE > 0)
#if (BOOT_FILE_SYS_ENABLE > 0)
/* call worker task for updating firmware from locally attached file storage */
FileTask();
#endif /* BOOT_FILE_SYS_ENABLE > 0 */
#if (BOOT_COM_ENABLE > 0)
#endif /* BOOT_FILE_SYS_ENABLE > 0 */
#if (BOOT_COM_ENABLE > 0)
/* process possibly pending communication data */
ComTask();
#endif
#endif
/* control the backdoor */
BackDoorCheck();
} /*** end of BootTask ***/

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
#ifndef BOOT_H
@ -48,7 +48,7 @@
* Include files
****************************************************************************************/
/* Note that it is possible to override the standard blt_conf.h configuration header
* file with a project specific one that is defined in the IDE/makefile. For example,
* file with a project specific one that is defined in the IDE/makefile. For example,
* the following define could be configured: PROJ_BLT_CONF_H="my_boot_config.h". This can
* be handy if you use the bootloader in several projects with a different configuration,
* and enables you to have just one bootloader source base.

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
#ifndef CAN_H

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
@ -36,16 +36,16 @@
****************************************************************************************/
#include "boot.h" /* bootloader generic header */
#if (BOOT_COM_CAN_ENABLE > 0)
#include "can.h" /* can driver module */
#include "can.h" /* can driver module */
#endif
#if (BOOT_COM_UART_ENABLE > 0)
#include "uart.h" /* uart driver module */
#include "uart.h" /* uart driver module */
#endif
#if (BOOT_COM_USB_ENABLE > 0)
#include "usb.h" /* usb driver module */
#include "usb.h" /* usb driver module */
#endif
#if (BOOT_COM_NET_ENABLE > 0)
#include "net.h" /* tcp/ip driver module */
#include "net.h" /* tcp/ip driver module */
#endif
@ -58,7 +58,7 @@ static tComInterfaceId comActiveInterface = COM_IF_OTHER;
/************************************************************************************//**
** \brief Initializes the communication module including the hardware needed for
** \brief Initializes the communication module including the hardware needed for
** the communication.
** \return none
**
@ -95,7 +95,7 @@ void ComInit(void)
/************************************************************************************//**
** \brief Updates the communication module by checking if new data was received
** \brief Updates the communication module by checking if new data was received
** and submitting the request to process newly received data.
** \return none
**
@ -104,7 +104,7 @@ void ComTask(void)
{
/* make xcpCtoReqPacket static for runtime efficiency */
static blt_int8u xcpCtoReqPacket[BOOT_COM_RX_MAX_DATA];
#if (BOOT_COM_CAN_ENABLE > 0)
if (CanReceivePacket(&xcpCtoReqPacket[0]) == BLT_TRUE)
{
@ -214,7 +214,7 @@ void ComTransmitPacket(blt_int8u *data, blt_int16u len)
blt_int16u ComGetActiveInterfaceMaxRxLen(void)
{
blt_int16u result;
/* filter on communication interface identifier */
switch (comActiveInterface)
{
@ -233,18 +233,18 @@ blt_int16u ComGetActiveInterfaceMaxRxLen(void)
case COM_IF_NET:
result = BOOT_COM_NET_RX_MAX_DATA;
break;
default:
result = BOOT_COM_RX_MAX_DATA;
break;
}
return result;
} /*** end of ComGetActiveInterfaceMaxRxLen ***/
/************************************************************************************//**
** \brief Obtains the maximum number of bytes that can be transmitted on the
** \brief Obtains the maximum number of bytes that can be transmitted on the
** specified communication interface.
** \return Maximum number of bytes that can be received.
**
@ -252,7 +252,7 @@ blt_int16u ComGetActiveInterfaceMaxRxLen(void)
blt_int16u ComGetActiveInterfaceMaxTxLen(void)
{
blt_int16u result;
/* filter on communication interface identifier */
switch (comActiveInterface)
{
@ -271,12 +271,12 @@ blt_int16u ComGetActiveInterfaceMaxTxLen(void)
case COM_IF_NET:
result = BOOT_COM_NET_TX_MAX_DATA;
break;
default:
result = BOOT_COM_TX_MAX_DATA;
break;
}
return result;
} /*** end of ComGetActiveInterfaceMaxTxLen ***/

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/
#ifndef COM_H

View File

@ -23,11 +23,11 @@
* You should have received a copy of the GNU General Public License along with OpenBLT.
* If not, see <http://www.gnu.org/licenses/>.
*
* 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
* 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
* proprietary components. The exception text is included at the bottom of the license
* file <license.html>.
*
*
* \endinternal
****************************************************************************************/

Some files were not shown because too many files have changed in this diff Show More