[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>
|
<CVariant></CVariant>
|
||||||
<CVendor>Atmel</CVendor>
|
<CVendor>Atmel</CVendor>
|
||||||
<CVersion>1.2.0</CVersion>
|
<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" />
|
<DependentComponents xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays" />
|
||||||
<Description></Description>
|
<Description></Description>
|
||||||
<Files xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
|
<Files xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
|
||||||
<d4p1:anyType i:type="FileInfo">
|
<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>
|
<Attribute></Attribute>
|
||||||
<Category>include</Category>
|
<Category>include</Category>
|
||||||
<Condition>C</Condition>
|
<Condition>C</Condition>
|
||||||
@@ -26,7 +26,7 @@
|
|||||||
<SourcePath></SourcePath>
|
<SourcePath></SourcePath>
|
||||||
</d4p1:anyType>
|
</d4p1:anyType>
|
||||||
<d4p1:anyType i:type="FileInfo">
|
<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>
|
<Attribute></Attribute>
|
||||||
<Category>header</Category>
|
<Category>header</Category>
|
||||||
<Condition>C</Condition>
|
<Condition>C</Condition>
|
||||||
@@ -37,18 +37,18 @@
|
|||||||
<SourcePath></SourcePath>
|
<SourcePath></SourcePath>
|
||||||
</d4p1:anyType>
|
</d4p1:anyType>
|
||||||
<d4p1:anyType i:type="FileInfo">
|
<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>
|
<Attribute>template</Attribute>
|
||||||
<Category>source</Category>
|
<Category>source</Category>
|
||||||
<Condition>C Exe</Condition>
|
<Condition>C Exe</Condition>
|
||||||
<FileContentHash>A/yU8r8q+GTMwpRAe+qmyw==</FileContentHash>
|
<FileContentHash>GD1k8YYhulqRs6FD1B2Hog==</FileContentHash>
|
||||||
<FileVersion></FileVersion>
|
<FileVersion></FileVersion>
|
||||||
<Name>templates/main.c</Name>
|
<Name>templates/main.c</Name>
|
||||||
<SelectString>Main file (.c)</SelectString>
|
<SelectString>Main file (.c)</SelectString>
|
||||||
<SourcePath></SourcePath>
|
<SourcePath></SourcePath>
|
||||||
</d4p1:anyType>
|
</d4p1:anyType>
|
||||||
<d4p1:anyType i:type="FileInfo">
|
<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>
|
<Attribute>template</Attribute>
|
||||||
<Category>source</Category>
|
<Category>source</Category>
|
||||||
<Condition>C Exe</Condition>
|
<Condition>C Exe</Condition>
|
||||||
@@ -59,7 +59,7 @@
|
|||||||
<SourcePath></SourcePath>
|
<SourcePath></SourcePath>
|
||||||
</d4p1:anyType>
|
</d4p1:anyType>
|
||||||
<d4p1:anyType i:type="FileInfo">
|
<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>
|
<Attribute></Attribute>
|
||||||
<Category>libraryPrefix</Category>
|
<Category>libraryPrefix</Category>
|
||||||
<Condition>GCC</Condition>
|
<Condition>GCC</Condition>
|
||||||
@@ -71,8 +71,8 @@
|
|||||||
</d4p1:anyType>
|
</d4p1:anyType>
|
||||||
</Files>
|
</Files>
|
||||||
<PackName>ATmega_DFP</PackName>
|
<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>
|
<PackPath>D:/Program Files (x86)/Atmel/Studio/7.0/Packs/atmel/ATmega_DFP/1.2.150/Atmel.ATmega_DFP.pdsc</PackPath>
|
||||||
<PackVersion>1.2.209</PackVersion>
|
<PackVersion>1.2.150</PackVersion>
|
||||||
<PresentInProject>true</PresentInProject>
|
<PresentInProject>true</PresentInProject>
|
||||||
<ReferenceConditionId>ATmega328P</ReferenceConditionId>
|
<ReferenceConditionId>ATmega328P</ReferenceConditionId>
|
||||||
<RteComponents xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
|
<RteComponents xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
|
||||||
|
|||||||
@@ -29,14 +29,14 @@
|
|||||||
<eraseonlaunchrule>1</eraseonlaunchrule>
|
<eraseonlaunchrule>1</eraseonlaunchrule>
|
||||||
<EraseKey />
|
<EraseKey />
|
||||||
<AsfFrameworkConfig>
|
<AsfFrameworkConfig>
|
||||||
<framework-data xmlns="">
|
<framework-data>
|
||||||
<options />
|
<options />
|
||||||
<configurations />
|
<configurations />
|
||||||
<files />
|
<files />
|
||||||
<documentation help="" />
|
<documentation help="" />
|
||||||
<offline-documentation help="" />
|
<offline-documentation help="" />
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.40.0" />
|
<content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.26.0" />
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</framework-data>
|
</framework-data>
|
||||||
</AsfFrameworkConfig>
|
</AsfFrameworkConfig>
|
||||||
@@ -58,7 +58,7 @@
|
|||||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||||
<ToolchainSettings>
|
<ToolchainSettings>
|
||||||
<AvrGcc>
|
<AvrGcc>
|
||||||
<avrgcc.common.Device>-mmcu=atmega328p -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\gcc\dev\atmega328p"</avrgcc.common.Device>
|
<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.hex>True</avrgcc.common.outputfiles.hex>
|
||||||
<avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
|
<avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
|
||||||
<avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
|
<avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
|
||||||
@@ -74,7 +74,7 @@
|
|||||||
</avrgcc.compiler.symbols.DefSymbols>
|
</avrgcc.compiler.symbols.DefSymbols>
|
||||||
<avrgcc.compiler.directories.IncludePaths>
|
<avrgcc.compiler.directories.IncludePaths>
|
||||||
<ListValues>
|
<ListValues>
|
||||||
<Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\include</Value>
|
<Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.2.150\include</Value>
|
||||||
</ListValues>
|
</ListValues>
|
||||||
</avrgcc.compiler.directories.IncludePaths>
|
</avrgcc.compiler.directories.IncludePaths>
|
||||||
<avrgcc.compiler.optimization.level>Optimize for size (-Os)</avrgcc.compiler.optimization.level>
|
<avrgcc.compiler.optimization.level>Optimize for size (-Os)</avrgcc.compiler.optimization.level>
|
||||||
@@ -93,7 +93,7 @@
|
|||||||
</avrgcc.linker.memorysettings.Flash>
|
</avrgcc.linker.memorysettings.Flash>
|
||||||
<avrgcc.assembler.general.IncludePaths>
|
<avrgcc.assembler.general.IncludePaths>
|
||||||
<ListValues>
|
<ListValues>
|
||||||
<Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\include</Value>
|
<Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.2.150\include</Value>
|
||||||
</ListValues>
|
</ListValues>
|
||||||
</avrgcc.assembler.general.IncludePaths>
|
</avrgcc.assembler.general.IncludePaths>
|
||||||
</AvrGcc>
|
</AvrGcc>
|
||||||
@@ -102,7 +102,7 @@
|
|||||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||||
<ToolchainSettings>
|
<ToolchainSettings>
|
||||||
<AvrGcc>
|
<AvrGcc>
|
||||||
<avrgcc.common.Device>-mmcu=atmega328p -B "%24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\gcc\dev\atmega328p"</avrgcc.common.Device>
|
<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.hex>True</avrgcc.common.outputfiles.hex>
|
||||||
<avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
|
<avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
|
||||||
<avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
|
<avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
|
||||||
@@ -118,7 +118,7 @@
|
|||||||
</avrgcc.compiler.symbols.DefSymbols>
|
</avrgcc.compiler.symbols.DefSymbols>
|
||||||
<avrgcc.compiler.directories.IncludePaths>
|
<avrgcc.compiler.directories.IncludePaths>
|
||||||
<ListValues>
|
<ListValues>
|
||||||
<Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\include</Value>
|
<Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.2.150\include</Value>
|
||||||
</ListValues>
|
</ListValues>
|
||||||
</avrgcc.compiler.directories.IncludePaths>
|
</avrgcc.compiler.directories.IncludePaths>
|
||||||
<avrgcc.compiler.optimization.level>Optimize debugging experience (-Og)</avrgcc.compiler.optimization.level>
|
<avrgcc.compiler.optimization.level>Optimize debugging experience (-Og)</avrgcc.compiler.optimization.level>
|
||||||
@@ -138,7 +138,7 @@
|
|||||||
</avrgcc.linker.memorysettings.Flash>
|
</avrgcc.linker.memorysettings.Flash>
|
||||||
<avrgcc.assembler.general.IncludePaths>
|
<avrgcc.assembler.general.IncludePaths>
|
||||||
<ListValues>
|
<ListValues>
|
||||||
<Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.2.209\include</Value>
|
<Value>%24(PackRepoDir)\atmel\ATmega_DFP\1.2.150\include</Value>
|
||||||
</ListValues>
|
</ListValues>
|
||||||
</avrgcc.assembler.general.IncludePaths>
|
</avrgcc.assembler.general.IncludePaths>
|
||||||
<avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
|
<avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ typedef void(fp_t)(void);
|
|||||||
fp_t *startApplication = (fp_t*)0x0000; /* Funktionspointer auf 0x0000 */
|
fp_t *startApplication = (fp_t*)0x0000; /* Funktionspointer auf 0x0000 */
|
||||||
fp_t *startBootloader = (fp_t*)0x7000; /* Funktionspointer auf 0x7000 */
|
fp_t *startBootloader = (fp_t*)0x7000; /* Funktionspointer auf 0x7000 */
|
||||||
|
|
||||||
#define SPM_PAGESIZE_MASK 0x7F
|
#define SPM_PAGESIZE_MASK 0x7FUL
|
||||||
|
|
||||||
inline void bootloader_enter()
|
inline void bootloader_enter()
|
||||||
{
|
{
|
||||||
@@ -46,6 +46,7 @@ typedef enum _eState
|
|||||||
StateHex,
|
StateHex,
|
||||||
} State;
|
} State;
|
||||||
|
|
||||||
|
void erase_page(uint16_t page_addr);
|
||||||
void write_page(uint16_t page_addr, uint8_t *buf);
|
void write_page(uint16_t page_addr, uint8_t *buf);
|
||||||
void program_page (uint32_t page, uint8_t *buf);
|
void program_page (uint32_t page, uint8_t *buf);
|
||||||
|
|
||||||
@@ -69,13 +70,13 @@ int main(void)
|
|||||||
|
|
||||||
uart_init(9600);
|
uart_init(9600);
|
||||||
|
|
||||||
uart_puts("Hendi-Control Bootloader\n");
|
uart_puts("Hendi-Control Bootloader v1.1\n");
|
||||||
size_t image_size = 0;
|
size_t image_size = 0;
|
||||||
uint16_t page_addr = 0xFFFF;
|
uint16_t page_addr = 0xFFFF;
|
||||||
int page_isEmpty = 1;
|
|
||||||
size_t hex_buffer_size = 0;
|
size_t hex_buffer_size = 0;
|
||||||
int leave_loop = 0;
|
int leave_loop = 0;
|
||||||
|
int page_is_dirty = 0;
|
||||||
|
int force_page_erase = 1;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
char c;
|
char c;
|
||||||
@@ -117,48 +118,50 @@ int main(void)
|
|||||||
{
|
{
|
||||||
case srec_sob:
|
case srec_sob:
|
||||||
image_size = 0;
|
image_size = 0;
|
||||||
page_isEmpty = 1;
|
init_page(page_buffer, SPM_PAGESIZE);
|
||||||
|
page_is_dirty = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case srec_data:
|
case srec_data:
|
||||||
{
|
{
|
||||||
uint16_t new_page_addr = srec.addr & ~SPM_PAGESIZE_MASK;
|
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;
|
page_addr = new_page_addr;
|
||||||
|
force_page_erase = 0;
|
||||||
|
erase_page(page_addr);
|
||||||
|
}
|
||||||
|
|
||||||
if (page_isEmpty)
|
uint16_t start = srec.addr & SPM_PAGESIZE_MASK;
|
||||||
|
uint16_t i = 0;
|
||||||
|
for (; i < srec.size; i++)
|
||||||
{
|
{
|
||||||
// Begin new page
|
if (start == SPM_PAGESIZE)
|
||||||
page_isEmpty = 0;
|
{
|
||||||
init_page(page_buffer, SPM_PAGESIZE);
|
break;
|
||||||
}
|
}
|
||||||
int start = srec.addr & SPM_PAGESIZE_MASK;
|
page_is_dirty = 1;
|
||||||
int i = 0;
|
|
||||||
int to_write = srec.size;
|
|
||||||
if ((start + to_write) > SPM_PAGESIZE)
|
|
||||||
{
|
|
||||||
to_write = SPM_PAGESIZE - start;
|
|
||||||
}
|
|
||||||
for (; i < to_write; i++)
|
|
||||||
{
|
|
||||||
page_buffer[start++] = srec.data[i];
|
page_buffer[start++] = srec.data[i];
|
||||||
}
|
}
|
||||||
// Page buffer is complete -> write to flash
|
// 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);
|
write_page(page_addr, page_buffer);
|
||||||
page_isEmpty = 1;
|
|
||||||
init_page(page_buffer, SPM_PAGESIZE);
|
init_page(page_buffer, SPM_PAGESIZE);
|
||||||
}
|
}
|
||||||
// Copy remaining data to start of page buffer
|
|
||||||
|
if (i < srec.size)
|
||||||
|
{
|
||||||
|
page_addr += SPM_PAGESIZE;
|
||||||
|
page_is_dirty = 1;
|
||||||
|
force_page_erase = 1;
|
||||||
start=0;
|
start=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy remaining data to start of page buffer
|
||||||
for (; i < srec.size; i++)
|
for (; i < srec.size; i++)
|
||||||
{
|
{
|
||||||
page_isEmpty = 0;
|
|
||||||
page_buffer[start++] = srec.data[i];
|
page_buffer[start++] = srec.data[i];
|
||||||
}
|
}
|
||||||
image_size += srec.size;
|
image_size += srec.size;
|
||||||
@@ -169,10 +172,14 @@ int main(void)
|
|||||||
break;
|
break;
|
||||||
case srec_eob:
|
case srec_eob:
|
||||||
state_next = StateIdle;
|
state_next = StateIdle;
|
||||||
if (!page_isEmpty)
|
if (page_is_dirty)
|
||||||
{
|
{
|
||||||
|
if (force_page_erase)
|
||||||
|
{
|
||||||
|
erase_page(page_addr);
|
||||||
|
}
|
||||||
write_page(page_addr, page_buffer);
|
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");
|
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 */
|
/* Reenable RWW-section again. We need this if we want to jump back */
|
||||||
@@ -202,6 +209,14 @@ int main(void)
|
|||||||
startApplication();
|
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)
|
void write_page(uint16_t page_addr, uint8_t *pPageBuffer)
|
||||||
{
|
{
|
||||||
uint16_t i;
|
uint16_t i;
|
||||||
@@ -213,10 +228,10 @@ void write_page(uint16_t page_addr, uint8_t *pPageBuffer)
|
|||||||
{
|
{
|
||||||
/* Set up little-endian word. */
|
/* Set up little-endian word. */
|
||||||
uint16_t w = *(pPageBuffer++);
|
uint16_t w = *(pPageBuffer++);
|
||||||
w += *(pPageBuffer++) << 8;
|
uint16_t v = *(pPageBuffer++);
|
||||||
|
w += v << 8;
|
||||||
|
|
||||||
boot_page_fill (page_addr + i, w);
|
boot_page_fill (page_addr + i, w);
|
||||||
}
|
}
|
||||||
|
|
||||||
boot_page_write (page_addr); /* Store buffer in flash page. */
|
boot_page_write (page_addr); /* Store buffer in flash page. */
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,8 +19,8 @@
|
|||||||
typedef struct _ssrec_t
|
typedef struct _ssrec_t
|
||||||
{
|
{
|
||||||
uint32_t addr;
|
uint32_t addr;
|
||||||
uint32_t size;
|
uint16_t size;
|
||||||
uint32_t type;
|
uint8_t type;
|
||||||
uint8_t *data;
|
uint8_t *data;
|
||||||
|
|
||||||
} srec_t;
|
} 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);
|
char uart_getc(void);
|
||||||
void uart_puts(char const *str);
|
void uart_puts(char const *str);
|
||||||
|
|
||||||
inline void print_byte(char byte)
|
void print_byte(char byte);
|
||||||
{
|
void print_word(uint16_t word);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* UART_H_ */
|
#endif /* UART_H_ */
|
||||||
Reference in New Issue
Block a user