mini-jtag: code style clean up

This commit is contained in:
Xiangfu 2012-09-25 22:28:26 +08:00
parent aeddee61ff
commit ee6066e225

View File

@ -5,23 +5,20 @@
// For details see the UNLICENSE file at the root of the source tree.
//
#include <ftdi.h>
#include <usb.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include "load-bits.h"
int read_section (FILE *bit_file, char *id, uint8_t **data, uint32_t *len)
int read_section(FILE *bit_file, char *id, uint8_t **data, uint32_t *len)
{
uint8_t buf[4];
int lenbytes;
/* first read 1 bytes, the section key */
if (fread (buf, 1, 1, bit_file) != 1)
if (fread(buf, 1, 1, bit_file) != 1)
return -1;
*id = buf[0];
@ -33,7 +30,7 @@ int read_section (FILE *bit_file, char *id, uint8_t **data, uint32_t *len)
lenbytes = 2;
/* first read 1 bytes */
if (fread (buf, 1, lenbytes, bit_file) != lenbytes)
if (fread(buf, 1, lenbytes, bit_file) != lenbytes)
return -1;
/* second and third is section length */
@ -43,9 +40,9 @@ int read_section (FILE *bit_file, char *id, uint8_t **data, uint32_t *len)
*len = buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3];
/* now allocate memory for data */
*data = malloc (*len);
*data = malloc(*len);
if (fread (*data, 1, *len, bit_file) != *len)
if (fread(*data, 1, *len, bit_file) != *len)
return -1;
return 0;
@ -63,31 +60,25 @@ int load_bits(FILE *bit_file, struct load_bits *bs)
0x0f, 0xf0, 0x00, 0x00, 0x01,
};
if (fread (buf, 1, sizeof (header), bit_file) != sizeof (header))
if (fread(buf, 1, sizeof (header), bit_file) != sizeof (header))
return -1;
if (memcmp (buf, header, sizeof (header)) != 0)
if (memcmp(buf, header, sizeof (header)) != 0)
return -1;
/* printf("Valid bitfile header found.\n"); */
while (sid != 'e')
{
if (read_section (bit_file, &sid, &sdata, &slen) != 0)
while (sid != 'e') {
if (read_section(bit_file, &sid, &sdata, &slen) != 0)
return -1;
/* printf("Read section id=%c len=%d.\n", sid, slen); */
/* make sure that strings are terminated */
if (sid != 'e')
sdata[slen-1] = '\0';
switch (sid)
{
case 'a': bs->design = (char *) sdata; break;
case 'b': bs->part_name = (char *) sdata; break;
case 'c': bs->date = (char *) sdata; break;
case 'd': bs->time = (char *) sdata; break;
switch (sid) {
case 'a': bs->design = (char *)sdata; break;
case 'b': bs->part_name = (char *)sdata; break;
case 'c': bs->date = (char *)sdata; break;
case 'd': bs->time = (char *)sdata; break;
case 'e': bs->data = sdata; bs->length = slen; break;
}
}