Use uint8_t where applicable

This commit is contained in:
Kimmo Kulovesi
2014-07-07 18:08:28 +03:00
parent aac708a0fd
commit ff4d993576
2 changed files with 15 additions and 15 deletions

View File

@@ -15,7 +15,7 @@
#define ADDRESS_HIGH_MASK ((ihex_address_t) 0xFFFF0000U)
#define ADDRESS_HIGH_BYTES(addr) ((addr) >> 16)
#define HEX_DIGIT(n) ((n) + ( ((n) < 10) ? '0' : ('A' - 10)))
#define HEX_DIGIT(n) ((n) + ( ((n) < 10U) ? '0' : ('A' - 10)))
#ifndef IHEX_EXTERNAL_WRITE_BUFFER
static char ihex_write_buffer[IHEX_WRITE_BUFFER_LENGTH];
@@ -37,8 +37,8 @@ ihex_init (struct ihex_state * const ihex) {
}
static char *
ihex_buffer_byte (char * restrict w, const unsigned int byte) {
unsigned int n = (byte & 0xF0U) >> 4; // high nybble
ihex_buffer_byte (char * restrict w, const uint8_t byte) {
uint8_t n = (byte & 0xF0U) >> 4; // high nybble
*w++ = HEX_DIGIT(n);
n = byte & 0x0FU; // low nybble
*w++ = HEX_DIGIT(n);
@@ -47,13 +47,13 @@ ihex_buffer_byte (char * restrict w, const unsigned int byte) {
static char *
ihex_buffer_word (char * restrict w, const unsigned int word,
unsigned int * const restrict checksum) {
unsigned int byte = (word & 0xFF00U) >> 8; // high byte
w = ihex_buffer_byte(w, byte);
uint8_t * const restrict checksum) {
uint8_t byte = (word & 0xFF00U) >> 8; // high byte
w = ihex_buffer_byte(w, (uint8_t)byte);
*checksum += byte;
byte = word & 0x00FFU; // low byte
*checksum += byte;
return ihex_buffer_byte(w, byte);
return ihex_buffer_byte(w, (uint8_t)byte);
}
static char *
@@ -81,7 +81,7 @@ ihex_write_end_of_file (struct ihex_state * const ihex) {
w = ihex_buffer_byte(w, 0); // address msb
w = ihex_buffer_byte(w, 0); // address lsb
w = ihex_buffer_byte(w, IHEX_END_OF_FILE_RECORD); // record type
w = ihex_buffer_byte(w, ~((unsigned int)IHEX_END_OF_FILE_RECORD) + 1U); // checksum
w = ihex_buffer_byte(w, (uint8_t)~IHEX_END_OF_FILE_RECORD + 1U); // checksum
#endif
w = ihex_buffer_newline(w);
ihex_flush_buffer(ihex, ihex_write_buffer, w);
@@ -92,15 +92,15 @@ ihex_write_extended_address (struct ihex_state * const ihex,
const ihex_segment_t address,
const enum ihex_record_type type) {
char * restrict w = ihex_write_buffer;
unsigned int sum = type + 2;
uint8_t sum = type + 2U;
*w++ = IHEX_START; // :
w = ihex_buffer_byte(w, 2); // length
w = ihex_buffer_byte(w, 2U); // length
w = ihex_buffer_byte(w, 0); // 16-bit address msb
w = ihex_buffer_byte(w, 0); // 16-bit address lsb
w = ihex_buffer_byte(w, type); // record type
w = ihex_buffer_word(w, address, &sum); // high bytes of address
w = ihex_buffer_byte(w, ~sum + 1); // checksum
w = ihex_buffer_byte(w, (uint8_t)~sum + 1U); // checksum
w = ihex_buffer_newline(w);
ihex_flush_buffer(ihex, ihex_write_buffer, w);
}
@@ -110,7 +110,7 @@ ihex_write_extended_address (struct ihex_state * const ihex,
static void
ihex_write_data (struct ihex_state * const ihex) {
unsigned int len = ihex->length;
unsigned int sum = len;
uint8_t sum = len;
char * restrict w = ihex_write_buffer;
if (!len) {
@@ -149,7 +149,7 @@ ihex_write_data (struct ihex_state * const ihex) {
{
uint8_t * restrict r = ihex->data;
do {
unsigned int byte = *r++;
uint8_t byte = *r++;
sum += byte;
w = ihex_buffer_byte(w, byte);
} while (--len);
@@ -200,7 +200,7 @@ ihex_write_at_segment (struct ihex_state *ihex, ihex_segment_t segment, ihex_add
#endif
void
ihex_write_byte (struct ihex_state *ihex, unsigned int byte) {
ihex_write_byte (struct ihex_state *ihex, uint8_t byte) {
if (ihex->line_length <= ihex->length) {
ihex_write_data(ihex);
}

View File

@@ -112,7 +112,7 @@ void ihex_init(struct ihex_state * const ihex);
void ihex_write_at_address(struct ihex_state *ihex, ihex_address_t address);
// Write a single byte
void ihex_write_byte(struct ihex_state *ihex, unsigned int b);
void ihex_write_byte(struct ihex_state *ihex, uint8_t b);
// Write `count` bytes from `data`
void ihex_write_bytes(struct ihex_state *ihex, uint8_t * restrict data,