[bootloader]
- reduce memory footprint - bugfix writing last page git-svn-id: http://moon:8086/svn/projects/HendiControl@56 fda53097-d464-4ada-af97-ba876c37ca34
This commit is contained in:
@@ -10,12 +10,12 @@
|
||||
<CVariant></CVariant>
|
||||
<CVendor>Atmel</CVendor>
|
||||
<CVersion>1.2.0</CVersion>
|
||||
<DefaultRepoPath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs</DefaultRepoPath>
|
||||
<DefaultRepoPath>D:/Program Files (x86)\Atmel\Studio\7.0\Packs</DefaultRepoPath>
|
||||
<DependentComponents xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays" />
|
||||
<Description></Description>
|
||||
<Files xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
|
||||
<d4p1:anyType i:type="FileInfo">
|
||||
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\include</AbsolutePath>
|
||||
<AbsolutePath>D:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.150\include</AbsolutePath>
|
||||
<Attribute></Attribute>
|
||||
<Category>include</Category>
|
||||
<Condition>C</Condition>
|
||||
@@ -26,7 +26,7 @@
|
||||
<SourcePath></SourcePath>
|
||||
</d4p1:anyType>
|
||||
<d4p1:anyType i:type="FileInfo">
|
||||
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\include\avr\iom328p.h</AbsolutePath>
|
||||
<AbsolutePath>D:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.150\include\avr\iom328p.h</AbsolutePath>
|
||||
<Attribute></Attribute>
|
||||
<Category>header</Category>
|
||||
<Condition>C</Condition>
|
||||
@@ -37,18 +37,18 @@
|
||||
<SourcePath></SourcePath>
|
||||
</d4p1:anyType>
|
||||
<d4p1:anyType i:type="FileInfo">
|
||||
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\templates\main.c</AbsolutePath>
|
||||
<AbsolutePath>D:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.150\templates\main.c</AbsolutePath>
|
||||
<Attribute>template</Attribute>
|
||||
<Category>source</Category>
|
||||
<Condition>C Exe</Condition>
|
||||
<FileContentHash>A/yU8r8q+GTMwpRAe+qmyw==</FileContentHash>
|
||||
<FileContentHash>GD1k8YYhulqRs6FD1B2Hog==</FileContentHash>
|
||||
<FileVersion></FileVersion>
|
||||
<Name>templates/main.c</Name>
|
||||
<SelectString>Main file (.c)</SelectString>
|
||||
<SourcePath></SourcePath>
|
||||
</d4p1:anyType>
|
||||
<d4p1:anyType i:type="FileInfo">
|
||||
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\templates\main.cpp</AbsolutePath>
|
||||
<AbsolutePath>D:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.150\templates\main.cpp</AbsolutePath>
|
||||
<Attribute>template</Attribute>
|
||||
<Category>source</Category>
|
||||
<Condition>C Exe</Condition>
|
||||
@@ -59,7 +59,7 @@
|
||||
<SourcePath></SourcePath>
|
||||
</d4p1:anyType>
|
||||
<d4p1:anyType i:type="FileInfo">
|
||||
<AbsolutePath>C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\gcc\dev\atmega328p</AbsolutePath>
|
||||
<AbsolutePath>D:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.150\gcc\dev\atmega328p</AbsolutePath>
|
||||
<Attribute></Attribute>
|
||||
<Category>libraryPrefix</Category>
|
||||
<Condition>GCC</Condition>
|
||||
@@ -71,8 +71,8 @@
|
||||
</d4p1:anyType>
|
||||
</Files>
|
||||
<PackName>ATmega_DFP</PackName>
|
||||
<PackPath>C:/Program Files (x86)/Atmel/Studio/7.0/Packs/atmel/ATmega_DFP/1.2.209/Atmel.ATmega_DFP.pdsc</PackPath>
|
||||
<PackVersion>1.2.209</PackVersion>
|
||||
<PackPath>D:/Program Files (x86)/Atmel/Studio/7.0/Packs/atmel/ATmega_DFP/1.2.150/Atmel.ATmega_DFP.pdsc</PackPath>
|
||||
<PackVersion>1.2.150</PackVersion>
|
||||
<PresentInProject>true</PresentInProject>
|
||||
<ReferenceConditionId>ATmega328P</ReferenceConditionId>
|
||||
<RteComponents xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
|
||||
|
||||
@@ -29,16 +29,16 @@
|
||||
<eraseonlaunchrule>1</eraseonlaunchrule>
|
||||
<EraseKey />
|
||||
<AsfFrameworkConfig>
|
||||
<framework-data xmlns="">
|
||||
<options />
|
||||
<configurations />
|
||||
<files />
|
||||
<documentation help="" />
|
||||
<offline-documentation help="" />
|
||||
<dependencies>
|
||||
<content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.40.0" />
|
||||
</dependencies>
|
||||
</framework-data>
|
||||
<framework-data>
|
||||
<options />
|
||||
<configurations />
|
||||
<files />
|
||||
<documentation help="" />
|
||||
<offline-documentation help="" />
|
||||
<dependencies>
|
||||
<content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.26.0" />
|
||||
</dependencies>
|
||||
</framework-data>
|
||||
</AsfFrameworkConfig>
|
||||
<avrtool>com.atmel.avrdbg.tool.atmelice</avrtool>
|
||||
<avrtoolserialnumber>J41800089261</avrtoolserialnumber>
|
||||
@@ -58,91 +58,91 @@
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||
<ToolchainSettings>
|
||||
<AvrGcc>
|
||||
<avrgcc.common.Device>-mmcu=atmega328p -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\gcc\dev\atmega328p"</avrgcc.common.Device>
|
||||
<avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
|
||||
<avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
|
||||
<avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
|
||||
<avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
|
||||
<avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
|
||||
<avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
|
||||
<avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
|
||||
<avrgcc.compiler.symbols.DefSymbols>
|
||||
<ListValues>
|
||||
<Value>NDEBUG</Value>
|
||||
<Value>ARDUINO_NANO=1</Value>
|
||||
</ListValues>
|
||||
</avrgcc.compiler.symbols.DefSymbols>
|
||||
<avrgcc.compiler.directories.IncludePaths>
|
||||
<ListValues>
|
||||
<Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\include</Value>
|
||||
</ListValues>
|
||||
</avrgcc.compiler.directories.IncludePaths>
|
||||
<avrgcc.compiler.optimization.level>Optimize for size (-Os)</avrgcc.compiler.optimization.level>
|
||||
<avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
|
||||
<avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
|
||||
<avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
|
||||
<avrgcc.linker.libraries.Libraries>
|
||||
<ListValues>
|
||||
<Value>libm</Value>
|
||||
</ListValues>
|
||||
</avrgcc.linker.libraries.Libraries>
|
||||
<avrgcc.linker.memorysettings.Flash>
|
||||
<ListValues>
|
||||
<Value>.text=0x3800</Value>
|
||||
</ListValues>
|
||||
</avrgcc.linker.memorysettings.Flash>
|
||||
<avrgcc.assembler.general.IncludePaths>
|
||||
<ListValues>
|
||||
<Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\include</Value>
|
||||
</ListValues>
|
||||
</avrgcc.assembler.general.IncludePaths>
|
||||
</AvrGcc>
|
||||
<avrgcc.common.Device>-mmcu=atmega328p -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.2.150\gcc\dev\atmega328p"</avrgcc.common.Device>
|
||||
<avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
|
||||
<avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
|
||||
<avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
|
||||
<avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
|
||||
<avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
|
||||
<avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
|
||||
<avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
|
||||
<avrgcc.compiler.symbols.DefSymbols>
|
||||
<ListValues>
|
||||
<Value>NDEBUG</Value>
|
||||
<Value>ARDUINO_NANO=1</Value>
|
||||
</ListValues>
|
||||
</avrgcc.compiler.symbols.DefSymbols>
|
||||
<avrgcc.compiler.directories.IncludePaths>
|
||||
<ListValues>
|
||||
<Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.2.150\include</Value>
|
||||
</ListValues>
|
||||
</avrgcc.compiler.directories.IncludePaths>
|
||||
<avrgcc.compiler.optimization.level>Optimize for size (-Os)</avrgcc.compiler.optimization.level>
|
||||
<avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
|
||||
<avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
|
||||
<avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
|
||||
<avrgcc.linker.libraries.Libraries>
|
||||
<ListValues>
|
||||
<Value>libm</Value>
|
||||
</ListValues>
|
||||
</avrgcc.linker.libraries.Libraries>
|
||||
<avrgcc.linker.memorysettings.Flash>
|
||||
<ListValues>
|
||||
<Value>.text=0x3800</Value>
|
||||
</ListValues>
|
||||
</avrgcc.linker.memorysettings.Flash>
|
||||
<avrgcc.assembler.general.IncludePaths>
|
||||
<ListValues>
|
||||
<Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.2.150\include</Value>
|
||||
</ListValues>
|
||||
</avrgcc.assembler.general.IncludePaths>
|
||||
</AvrGcc>
|
||||
</ToolchainSettings>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||
<ToolchainSettings>
|
||||
<AvrGcc>
|
||||
<avrgcc.common.Device>-mmcu=atmega328p -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\gcc\dev\atmega328p"</avrgcc.common.Device>
|
||||
<avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
|
||||
<avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
|
||||
<avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
|
||||
<avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
|
||||
<avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
|
||||
<avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
|
||||
<avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
|
||||
<avrgcc.compiler.symbols.DefSymbols>
|
||||
<ListValues>
|
||||
<Value>DEBUG</Value>
|
||||
<Value>ARDUINO_NANO=1</Value>
|
||||
</ListValues>
|
||||
</avrgcc.compiler.symbols.DefSymbols>
|
||||
<avrgcc.compiler.directories.IncludePaths>
|
||||
<ListValues>
|
||||
<Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\include</Value>
|
||||
</ListValues>
|
||||
</avrgcc.compiler.directories.IncludePaths>
|
||||
<avrgcc.compiler.optimization.level>Optimize debugging experience (-Og)</avrgcc.compiler.optimization.level>
|
||||
<avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
|
||||
<avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
|
||||
<avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
|
||||
<avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
|
||||
<avrgcc.linker.libraries.Libraries>
|
||||
<ListValues>
|
||||
<Value>libm</Value>
|
||||
</ListValues>
|
||||
</avrgcc.linker.libraries.Libraries>
|
||||
<avrgcc.linker.memorysettings.Flash>
|
||||
<ListValues>
|
||||
<Value>.text=0x3800</Value>
|
||||
</ListValues>
|
||||
</avrgcc.linker.memorysettings.Flash>
|
||||
<avrgcc.assembler.general.IncludePaths>
|
||||
<ListValues>
|
||||
<Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\include</Value>
|
||||
</ListValues>
|
||||
</avrgcc.assembler.general.IncludePaths>
|
||||
<avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
|
||||
</AvrGcc>
|
||||
<avrgcc.common.Device>-mmcu=atmega328p -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.2.150\gcc\dev\atmega328p"</avrgcc.common.Device>
|
||||
<avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
|
||||
<avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
|
||||
<avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
|
||||
<avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
|
||||
<avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
|
||||
<avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
|
||||
<avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
|
||||
<avrgcc.compiler.symbols.DefSymbols>
|
||||
<ListValues>
|
||||
<Value>DEBUG</Value>
|
||||
<Value>ARDUINO_NANO=1</Value>
|
||||
</ListValues>
|
||||
</avrgcc.compiler.symbols.DefSymbols>
|
||||
<avrgcc.compiler.directories.IncludePaths>
|
||||
<ListValues>
|
||||
<Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.2.150\include</Value>
|
||||
</ListValues>
|
||||
</avrgcc.compiler.directories.IncludePaths>
|
||||
<avrgcc.compiler.optimization.level>Optimize debugging experience (-Og)</avrgcc.compiler.optimization.level>
|
||||
<avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
|
||||
<avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
|
||||
<avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
|
||||
<avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
|
||||
<avrgcc.linker.libraries.Libraries>
|
||||
<ListValues>
|
||||
<Value>libm</Value>
|
||||
</ListValues>
|
||||
</avrgcc.linker.libraries.Libraries>
|
||||
<avrgcc.linker.memorysettings.Flash>
|
||||
<ListValues>
|
||||
<Value>.text=0x3800</Value>
|
||||
</ListValues>
|
||||
</avrgcc.linker.memorysettings.Flash>
|
||||
<avrgcc.assembler.general.IncludePaths>
|
||||
<ListValues>
|
||||
<Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.2.150\include</Value>
|
||||
</ListValues>
|
||||
</avrgcc.assembler.general.IncludePaths>
|
||||
<avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
|
||||
</AvrGcc>
|
||||
</ToolchainSettings>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -19,7 +19,7 @@ typedef void(fp_t)(void);
|
||||
fp_t *startApplication = (fp_t*)0x0000; /* Funktionspointer auf 0x0000 */
|
||||
fp_t *startBootloader = (fp_t*)0x7000; /* Funktionspointer auf 0x7000 */
|
||||
|
||||
#define SPM_PAGESIZE_MASK 0x7F
|
||||
#define SPM_PAGESIZE_MASK 0x7FUL
|
||||
|
||||
inline void bootloader_enter()
|
||||
{
|
||||
@@ -46,6 +46,7 @@ typedef enum _eState
|
||||
StateHex,
|
||||
} State;
|
||||
|
||||
void erase_page(uint16_t page_addr);
|
||||
void write_page(uint16_t page_addr, uint8_t *buf);
|
||||
void program_page (uint32_t page, uint8_t *buf);
|
||||
|
||||
@@ -69,13 +70,13 @@ int main(void)
|
||||
|
||||
uart_init(9600);
|
||||
|
||||
uart_puts("Hendi-Control Bootloader\n");
|
||||
uart_puts("Hendi-Control Bootloader v1.1\n");
|
||||
size_t image_size = 0;
|
||||
uint16_t page_addr = 0xFFFF;
|
||||
int page_isEmpty = 1;
|
||||
size_t hex_buffer_size = 0;
|
||||
int leave_loop = 0;
|
||||
|
||||
int page_is_dirty = 0;
|
||||
int force_page_erase = 1;
|
||||
do
|
||||
{
|
||||
char c;
|
||||
@@ -117,48 +118,50 @@ int main(void)
|
||||
{
|
||||
case srec_sob:
|
||||
image_size = 0;
|
||||
page_isEmpty = 1;
|
||||
init_page(page_buffer, SPM_PAGESIZE);
|
||||
page_is_dirty = 0;
|
||||
break;
|
||||
|
||||
case srec_data:
|
||||
{
|
||||
uint16_t new_page_addr = srec.addr & ~SPM_PAGESIZE_MASK;
|
||||
if (new_page_addr != page_addr)
|
||||
if ((new_page_addr != page_addr) || force_page_erase)
|
||||
{
|
||||
eeprom_busy_wait ();
|
||||
boot_spm_busy_wait ();
|
||||
boot_page_erase (new_page_addr);
|
||||
page_addr = new_page_addr;
|
||||
force_page_erase = 0;
|
||||
erase_page(page_addr);
|
||||
}
|
||||
page_addr = new_page_addr;
|
||||
|
||||
if (page_isEmpty)
|
||||
{
|
||||
// Begin new page
|
||||
page_isEmpty = 0;
|
||||
init_page(page_buffer, SPM_PAGESIZE);
|
||||
}
|
||||
int start = srec.addr & SPM_PAGESIZE_MASK;
|
||||
int i = 0;
|
||||
int to_write = srec.size;
|
||||
if ((start + to_write) > SPM_PAGESIZE)
|
||||
{
|
||||
to_write = SPM_PAGESIZE - start;
|
||||
}
|
||||
for (; i < to_write; i++)
|
||||
uint16_t start = srec.addr & SPM_PAGESIZE_MASK;
|
||||
uint16_t i = 0;
|
||||
for (; i < srec.size; i++)
|
||||
{
|
||||
if (start == SPM_PAGESIZE)
|
||||
{
|
||||
break;
|
||||
}
|
||||
page_is_dirty = 1;
|
||||
page_buffer[start++] = srec.data[i];
|
||||
}
|
||||
// Page buffer is complete -> write to flash
|
||||
if ((start + i) >= SPM_PAGESIZE)
|
||||
if (start == SPM_PAGESIZE)
|
||||
{
|
||||
page_is_dirty = 0;
|
||||
write_page(page_addr, page_buffer);
|
||||
page_isEmpty = 1;
|
||||
init_page(page_buffer, SPM_PAGESIZE);
|
||||
}
|
||||
|
||||
if (i < srec.size)
|
||||
{
|
||||
page_addr += SPM_PAGESIZE;
|
||||
page_is_dirty = 1;
|
||||
force_page_erase = 1;
|
||||
start=0;
|
||||
}
|
||||
|
||||
// Copy remaining data to start of page buffer
|
||||
start=0;
|
||||
for (; i < srec.size; i++)
|
||||
{
|
||||
page_isEmpty = 0;
|
||||
page_buffer[start++] = srec.data[i];
|
||||
}
|
||||
image_size += srec.size;
|
||||
@@ -169,10 +172,14 @@ int main(void)
|
||||
break;
|
||||
case srec_eob:
|
||||
state_next = StateIdle;
|
||||
if (!page_isEmpty)
|
||||
if (page_is_dirty)
|
||||
{
|
||||
if (force_page_erase)
|
||||
{
|
||||
erase_page(page_addr);
|
||||
}
|
||||
write_page(page_addr, page_buffer);
|
||||
page_isEmpty = 1;
|
||||
page_is_dirty = 0;
|
||||
}
|
||||
uart_puts("\nImage size: 0x"); print_word(image_size); uart_puts("\n");
|
||||
/* Reenable RWW-section again. We need this if we want to jump back */
|
||||
@@ -202,6 +209,14 @@ int main(void)
|
||||
startApplication();
|
||||
}
|
||||
|
||||
void erase_page(uint16_t page_addr)
|
||||
{
|
||||
// uart_puts("ErasePage: "); print_word(page_addr); uart_puts("\n");
|
||||
eeprom_busy_wait ();
|
||||
boot_spm_busy_wait ();
|
||||
boot_page_erase (page_addr);
|
||||
|
||||
}
|
||||
void write_page(uint16_t page_addr, uint8_t *pPageBuffer)
|
||||
{
|
||||
uint16_t i;
|
||||
@@ -213,10 +228,10 @@ void write_page(uint16_t page_addr, uint8_t *pPageBuffer)
|
||||
{
|
||||
/* Set up little-endian word. */
|
||||
uint16_t w = *(pPageBuffer++);
|
||||
w += *(pPageBuffer++) << 8;
|
||||
uint16_t v = *(pPageBuffer++);
|
||||
w += v << 8;
|
||||
|
||||
boot_page_fill (page_addr + i, w);
|
||||
}
|
||||
|
||||
boot_page_write (page_addr); /* Store buffer in flash page. */
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
typedef struct _ssrec_t
|
||||
{
|
||||
uint32_t addr;
|
||||
uint32_t size;
|
||||
uint32_t type;
|
||||
uint16_t size;
|
||||
uint8_t type;
|
||||
uint8_t *data;
|
||||
|
||||
} srec_t;
|
||||
|
||||
@@ -67,3 +67,34 @@ void uart_puts(char const *str)
|
||||
}
|
||||
}
|
||||
|
||||
void print_byte(char byte)
|
||||
{
|
||||
int i;
|
||||
unsigned char c, nibble;
|
||||
|
||||
for (i=0; i < 2; i++)
|
||||
{
|
||||
nibble = (char)((byte >> 4) & 0xF);
|
||||
byte <<= 4;
|
||||
|
||||
if (nibble < 10)
|
||||
c = nibble + '0';
|
||||
else
|
||||
c = nibble + 'A' - 10;
|
||||
|
||||
uart_putc(c);
|
||||
}
|
||||
}
|
||||
|
||||
void print_word(uint16_t word)
|
||||
{
|
||||
int i;
|
||||
unsigned char c;
|
||||
|
||||
for (i=0; i < 2; i++)
|
||||
{
|
||||
c = (char) (word >> 8);
|
||||
print_byte(c);
|
||||
word <<= 8;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,36 +20,7 @@ void uart_putc(char c);
|
||||
char uart_getc(void);
|
||||
void uart_puts(char const *str);
|
||||
|
||||
inline void print_byte(char byte)
|
||||
{
|
||||
int i;
|
||||
unsigned char c, nibble;
|
||||
|
||||
for (i=0; i < 2; i++)
|
||||
{
|
||||
nibble = (char)((byte >> 4) & 0xF);
|
||||
byte <<= 4;
|
||||
|
||||
if (nibble < 10)
|
||||
c = nibble + '0';
|
||||
else
|
||||
c = nibble + 'A' - 10;
|
||||
|
||||
uart_putc(c);
|
||||
}
|
||||
}
|
||||
|
||||
inline void print_word(uint16_t word)
|
||||
{
|
||||
int i;
|
||||
unsigned char c;
|
||||
|
||||
for (i=0; i < 2; i++)
|
||||
{
|
||||
c = (char) (word >> 8);
|
||||
print_byte(c);
|
||||
word <<= 8;
|
||||
}
|
||||
}
|
||||
void print_byte(char byte);
|
||||
void print_word(uint16_t word);
|
||||
|
||||
#endif /* UART_H_ */
|
||||
Reference in New Issue
Block a user