Ignore:
Timestamp:
Jan 14, 2011, 4:49:51 PM (9 years ago)
Author:
mulligan
Message:

Got Intel HEX format exportation working.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Deliverables/D4.1/IntelHex.ml

    r447 r448  
    3333    | '9' -> 9 | 'A' -> 10 | 'B' -> 11
    3434    | 'C' -> 12 | 'D' -> 13 | 'E' -> 14
    35     | 'F' -> 15 | _ -> assert false
     35    | 'F' -> 15 | 'a' -> 10 | 'b' -> 11
     36    | 'c' -> 12 | 'd' -> 13 | 'e' -> 14
     37    | 'f' -> 15 | _ -> assert false
    3638
    3739let intel_hex_entry_type_of_int =
     
    9496    aux (false, (vect_of_int 0 `Eight)) r
    9597
    96 let checksum_valid hex_entry =
     98let calculate_checksum hex_entry =
    9799 let ty = (flip vect_of_int $ `Eight) $ int_of_intel_hex_entry_type hex_entry.record_type in
    98100 let addr1,addr2 = from_word hex_entry.record_addr in
    99101 let _, total = add_bytes (hex_entry.record_length :: addr1 :: addr2 :: ty :: hex_entry.data_field) in
    100102 let _,total = half_add (vect_of_int 1 `Eight) $ complement total in
    101    hex_entry.data_checksum = total
    102 
     103  total
     104
     105let checksum_valid hex_entry =
     106  let total = calculate_checksum hex_entry in
     107    hex_entry.data_checksum = total
    103108
    104109let prs_intel_hex_record =
     
    136141let string_of_intel_hex_entry entry =
    137142  let length_string = hex_string_of_vect entry.record_length in
    138   let addr_string = Printf.sprintf "%04x" (int_of_vect entry.record_addr) in
    139   let checksum_string = Printf.sprintf "%02x" (int_of_vect entry.data_checksum) in
     143  let addr_string = Printf.sprintf "%04X" (int_of_vect entry.record_addr) in
     144  let checksum_string = Printf.sprintf "%02X" (int_of_vect entry.data_checksum) in
    140145  let type_string = Printf.sprintf "%02d" (int_of_intel_hex_entry_type entry.record_type) in
    141146  let data_string = String.concat "" (List.map hex_string_of_vect entry.data_field) in
     
    199204  let rec aux chunk address start_address rbuff lbuff =
    200205    if address = max_addressable then
    201       lbuff
     206      (start_address, List.rev rbuff)::lbuff
    202207    else if chunk = 0 then
    203       aux chunk_size (address + 1) address [] ((start_address, rbuff)::lbuff)
     208      aux chunk_size address address [] ((start_address, List.rev rbuff)::lbuff)
    204209    else
    205210      let code = Physical.WordMap.find (vect_of_int address `Sixteen) code_mem in
     
    216221  let addr1,addr2 = from_word record_addr in
    217222  let _, total = add_bytes (record_length :: addr1 :: addr2 :: ty :: data_field) in
    218   let _,total = half_add (vect_of_int 1 `Eight) $ complement total in
     223  let _,total = half_add (vect_of_int 0 `Eight) $ complement total in
    219224    total
    220225;;
     
    226231    let record_type = Data in
    227232    let data_field = snd x in
     233    let temp_record =
    228234      { record_length = record_length;
    229235        record_addr = record_addr;
    230236        record_type = record_type;
    231237        data_field = data_field;
    232         data_checksum = calculate_data_checksum (record_length, record_addr, record_type, data_field)
    233       })
     238        data_checksum = zero `Eight
     239      } in
     240    { temp_record with data_checksum = calculate_checksum temp_record })
    234241;;
    235242
     
    243250      record_type = End;
    244251      data_field = [];
    245       data_checksum = zero `Eight
     252      data_checksum = vect_of_int 255 `Eight
    246253    }] in
    247254    processed @ end_buffer
Note: See TracChangeset for help on using the changeset viewer.