[tuxdroid-svn] r383 - firmware/tuxup/trunk
Status: Beta
Brought to you by:
ks156
From: neimad <c2m...@c2...> - 2007-06-17 10:07:53
|
Author: neimad Date: 2007-06-17 12:07:50 +0200 (Sun, 17 Jun 2007) New Revision: 383 Modified: firmware/tuxup/trunk/bootloader.c Log: * Fixed lots of comments going far beyond the 80 columns limit (see coding style guidelines). Modified: firmware/tuxup/trunk/bootloader.c =================================================================== --- firmware/tuxup/trunk/bootloader.c 2007-06-17 09:50:17 UTC (rev 382) +++ firmware/tuxup/trunk/bootloader.c 2007-06-17 10:07:50 UTC (rev 383) @@ -79,11 +79,11 @@ FILE_ParsedData_t parsedData; /* Last hunk of data parsed */ FILE_Addr_t segAddr; /* Address of the segment in memory */ FILE_SegmentLen_t segLen; /* Length of the segment in memory */ - int inSeg; /* We've started a segment which hasn't been finished yet */ - FILE_Addr_t currAddr; /* The current address in memory being processed */ + int inSeg; /* Inside a segment */ + FILE_Addr_t currAddr; /* Current address in memory being processed */ uint8_t *segmentData; /* Complete segment data */ - int segmentDataIdx; /* index used for filling in the segment data */ - usb_dev_handle *dev_handle; /* usb device handle for sending parsed data */ + int segmentDataIdx; /* Index used for filling in the segment data */ + usb_dev_handle *dev_handle; /* USB device handle for sending parsed data */ } Parser_t; /** @@ -231,16 +231,19 @@ static int startSegment(Parser_t * parser) { parser->segmentDataIdx = 0; + /* set segment address */ parser->segmentData[parser->segmentDataIdx++] = (uint8_t) (parser->segAddr >> 8); parser->segmentData[parser->segmentDataIdx++] = (uint8_t) parser->segAddr; + /* fill with '0xFF' if necessary */ while (parser->currAddr < parser->parsedData.addr) { parser->segmentData[parser->segmentDataIdx++] = 0xFF; parser->currAddr++; } + return TRUE; } @@ -265,9 +268,12 @@ uint8_t data_buffer[36]; int ret; - parser->inSeg = FALSE; /* inidicates that we completed a segment */ + /* Indicate that we completed a segment */ + parser->inSeg = FALSE; + #if (PRINT_DATA) - printf("segment data: \n"); /* XXX debug */ + /* XXX debug */ + printf("segment data: \n"); for (i = 0; i < parser->segLen + 2; i++) printf("%02x", parser->segmentData[i]); printf("\n"); @@ -275,13 +281,19 @@ data_buffer[0] = LIBUSB_I2C_HEADER; data_buffer[1] = BOOT_FILLPAGE; + + /* + * Send first packet + */ for (i = 2; i < 36; i++) - data_buffer[i] = parser->segmentData[idx++]; /* send first packet */ + data_buffer[i] = parser->segmentData[idx++]; /* EEPROM handling */ if (mem_type == EEPROM) { - usleep(200000); /* try to solve the programming problem with some boards */ - data_buffer[2] |= 0x80; /* set the last bit to 1 to indicate eeprom type to the bootloader */ + /* try to solve the programming problem with some boards */ + usleep(200000); + /* set the last bit to 1 to indicate eeprom type to the bootloader */ + data_buffer[2] |= 0x80; } ret = usb_send_commands(parser->dev_handle, data_buffer, 36); #if (PRINT_DATA) @@ -289,8 +301,12 @@ #endif if (ret != 36) return FALSE; + + /* + * Send second packet + */ for (i = 2; i < 34; i++) - data_buffer[i] = parser->segmentData[idx++]; /* send second packet */ + data_buffer[i] = parser->segmentData[idx++]; keybreak(); ret = usb_send_commands(parser->dev_handle, data_buffer, 34); #if (PRINT_DATA) @@ -300,11 +316,15 @@ return FALSE; keybreak(); + + /* + * Bootlader status command and result + */ ret = usb_get_commands(parser->dev_handle, data_buffer, 5); #if (PRINT_DATA) printf("Status of feedback from bootloader: %x\n", ret); #endif - if ((ret == 5) && (data_buffer[0] == 0xF0) && (data_buffer[1] == 0)) /* Bootlader status command and result */ + if ((ret == 5) && (data_buffer[0] == 0xF0) && (data_buffer[1] == 0)) { printf("."); return TRUE; @@ -324,7 +344,6 @@ * * @return TRUE if parsing should continue, FALSE if it should stop. */ - static int ParsedData(Parser_t * parser, int lastSeg) { FILE_ParsedData_t *parsedData = &parser->parsedData; @@ -335,7 +354,8 @@ #if (PRINT_DATA) printf("--last segment --\n"); #endif - while (parser->currAddr < (parser->segAddr + parser->segLen)) /* fill with '0' until the end of segment */ + /* fill with '0' until the end of segment */ + while (parser->currAddr < (parser->segAddr + parser->segLen)) { fillSegment(parser, 0xFF); } @@ -351,11 +371,14 @@ #endif if (!parser->inSeg) { - parser->currAddr = parsedData->addr & ~(parser->segLen - 1); /* set current address at the segment start by zeroing lower bits */ + /* set current address at the segment start by zeroing lower bits */ + parser->currAddr = parsedData->addr & ~(parser->segLen - 1); break; } fillSegment(parser, 0xFF); - if (parser->currAddr == (parser->segAddr + parser->segLen)) /* end of segment */ + + /* end of segment ? */ + if (parser->currAddr == (parser->segAddr + parser->segLen)) { finishSegment(parser); } @@ -370,19 +393,24 @@ #if (PRINT_DATA) printf("--loop--"); #endif - if (!parser->inSeg) /* start a new segment if needed */ + /* start a new segment if needed */ + if (!parser->inSeg) { #if (PRINT_DATA) printf("--new segment--\n"); #endif parser->inSeg = TRUE; - parser->segAddr = parser->currAddr; /* set address of the segment start */ + /* set address of the segment start */ + parser->segAddr = parser->currAddr; startSegment(parser); } + /* store data in segmentData */ fillSegment(parser, parsedData->data[dataIdx]); dataIdx++; - if (parser->currAddr == (parser->segAddr + parser->segLen)) /* end of segment */ + + /* end of segment ? */ + if (parser->currAddr == (parser->segAddr + parser->segLen)) { #if (PRINT_DATA) printf("--end segment--"); @@ -425,9 +453,8 @@ if (line[0] != ':') { - // In Intel Hex format, lines which don't start with ':' are - // supposed to be ignored. - + /* In Intel Hex format, lines which don't start with ':' are + supposed to be ignored */ return TRUE; } @@ -523,8 +550,13 @@ memset(&parser, 0, sizeof(parser)); /* clear all parser elements */ - parser.segLen = 0x40; /* TODO get this value from either the file or the main program. What if we get an ATM168? */ - parser.dev_handle = dev_h; /* XXX this is not a good way to pass the handle up to finsihSegment, any better idea? */ + /* TODO get this value from either the file or the main program. + What if we get an ATM168? */ + parser.segLen = 0x40; + /* XXX this is not a good way to pass the handle up to + finishSegment, any better idea? */ + parser.dev_handle = dev_h; + if ((parser.segmentData = malloc(parser.segLen + 2)) == NULL) { fprintf(stderr, "Unable to allocate segmentData space"); @@ -570,8 +602,8 @@ { int rc = FALSE; uint8_t data_buffer[5]; - uint8_t page_size = 64; /* XXX should be adapted depending on the CPU type, how to do this? */ - uint8_t packet_total = 2; /* XXX should be adapted depending on the CPU type, how to do this? */ + uint8_t page_size = 64; /* XXX Should depend on CPU type */ + uint8_t packet_total = 2; /* XXX should depend on CPU type */ int ret; /* Set global variable mem_type to the memory type */ |