Changeset 446


Ignore:
Timestamp:
Jan 14, 2011, 2:14:17 PM (9 years ago)
Author:
mulligan
Message:

Checksum calculation added. Seems to still be buggy.

File:
1 edited

Legend:

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

    r445 r446  
    136136let string_of_intel_hex_entry entry =
    137137  let length_string = hex_string_of_vect entry.record_length in
    138   let addr_string = hex_string_of_vect entry.record_addr in
    139   let checksum_string = hex_string_of_vect entry.data_checksum 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
    140140  let type_string = Printf.sprintf "%02d" (int_of_intel_hex_entry_type entry.record_type) in
    141141  let data_string = String.concat "" (List.map hex_string_of_vect entry.data_field) in
     
    212212;;
    213213
     214let calculate_data_checksum (record_length, record_addr, record_type, data_field) =
     215 let ty = (flip vect_of_int $ `Eight) $ int_of_intel_hex_entry_type record_type in
     216 let addr1,addr2 = from_word record_addr in
     217 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
     219   total
     220;;
     221
    214222let process_exported_code_memory =
    215223  List.map (fun x ->
    216     { record_length = vect_of_int (List.length (snd x)) `Eight;
    217       record_addr = vect_of_int (fst x) `Sixteen;
    218       record_type = Data;
    219       data_field = snd x;
    220       data_checksum = zero `Eight (* for the time being *)
    221     })
     224    let record_length = vect_of_int (List.length (snd x)) `Eight in
     225    let record_addr = vect_of_int (fst x) `Sixteen in
     226    let record_type = Data in
     227    let data_field = snd x in
     228      { record_length = record_length;
     229        record_addr = record_addr;
     230        record_type = record_type;
     231        data_field = data_field;
     232        data_checksum = calculate_data_checksum (record_length, record_addr, record_type, data_field)
     233      })
    222234;;
    223235
Note: See TracChangeset for help on using the changeset viewer.