Logo Search packages:      
Sourcecode: s51dude version File versions

int Write_IHexRecord ( const IHexRecord  ihexRecord,
FILE *  out 
)

Writes an Intel HEX record to an opened file.

Parameters:
ihexRecord The Intel HEX record structure that will be written.
in A file pointer to an opened file that can be written to.
Returns:
IHEX_OK on success, otherwise one of the IHEX_ERROR_ error codes.
Return values:
IHEX_OK on success.
IHEX_ERROR_INVALID_ARGUMENTS if the file pointer "out" is invalid.
IHEX_ERROR_INVALID_RECORD if the record's data length is out of range (greater than the maximum data length allowed by record specifications, see IHexRecord.data).
IHEX_ERROR_FILE if a file writing error has occured.

Definition at line 100 of file ihex.c.

References _IHexRecord::address, _IHexRecord::data, _IHexRecord::dataLen, IHEX_ERROR_FILE, IHEX_ERROR_INVALID_ARGUMENTS, IHEX_ERROR_INVALID_RECORD, IHEX_OK, and _IHexRecord::type.

                                                             {
      int i;
      
      /* Check our file pointer */
      if (out == NULL)
            return IHEX_ERROR_INVALID_ARGUMENTS;
            
      /* Check that the data length is in range */
      if (ihexRecord.dataLen > IHEX_MAX_DATA_LEN/2)
            return IHEX_ERROR_INVALID_RECORD;
      
      /* Write the start code, data count, address, and type fields */
      if (fprintf(out, "%c%2.2X%2.4X%2.2X", IHEX_START_CODE, ihexRecord.dataLen, ihexRecord.address, ihexRecord.type) < 0)
            return IHEX_ERROR_FILE;
            
      /* Write the data bytes */
      for (i = 0; i < ihexRecord.dataLen; i++) {
            if (fprintf(out, "%2.2X", ihexRecord.data[i]) < 0)
                  return IHEX_ERROR_FILE;
      }
      
      /* Calculate and write the checksum field */
      if (fprintf(out, "%2.2X\r\n", Checksum_IHexRecord(ihexRecord)) < 0)
            return IHEX_ERROR_FILE;
            
      return IHEX_OK;
}


Generated by  Doxygen 1.6.0   Back to index