Defines | Functions

projects/nrfgo_sdk/bootloader_32k/host_applications/bootlu1p_linux/hexfile.h File Reference

Go to the source code of this file.

Defines

#define ERR_CRC   1
#define ERR_ADDR   2
#define ERR_FMT   3
#define NO_ERR   0

Functions

int read_hex_file (FILE *fp, int crc, unsigned char *buf, unsigned buf_size, unsigned *low_addr, unsigned *high_addr)

Define Documentation

#define ERR_CRC   1

Definition at line 17 of file hexfile.h.

#define ERR_ADDR   2

Definition at line 18 of file hexfile.h.

#define ERR_FMT   3

Definition at line 19 of file hexfile.h.

#define NO_ERR   0

Definition at line 20 of file hexfile.h.


Function Documentation

int read_hex_file ( FILE *  fp,
int  crc,
unsigned char *  buf,
unsigned  buf_size,
unsigned *  low_addr,
unsigned *  high_addr 
)

Definition at line 74 of file hexfile.c.

{
    int res, lcount, err;
    char line[1000];
    lcount = 0;
    err = 0;
    while (!feof(fp) && !ferror(fp))
    {
        fgets(line, 1000, fp);
        lcount++;
        if ((res = read_hex_line(line, buf, buf_size, low_addr, high_addr)) != NO_ERR)
        {
            switch(res)
            {
                case ERR_CRC:
                    if (crc == 1)
                    {
                        fprintf(stderr, "ERROR: Checksum error on line %d\n", lcount);
                        err = res;;
                    }
                    break;

                case ERR_ADDR:
                    fprintf(stderr, "ERROR: Hex file contents does not fit into flash\n");
                    return res;

                case ERR_FMT:
                    fprintf(stderr, "ERROR: Invalid Intel hex format on line %d\n", lcount);
                    return res;
            }
        }
    }
    return err;
}