Changeset 448


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

Got Intel HEX format exportation working.

Location:
Deliverables/D4.1
Files:
5 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
  • Deliverables/D4.1/Parser.ml

    r138 r448  
    8484       x = '4' || x = '5' || x = '6' || x = '7' ||
    8585       x = '8' || x = '9' || x = 'A' || x = 'B' ||
    86        x = 'C' || x = 'D' || x = 'E' || x = 'F')
     86       x = 'C' || x = 'D' || x = 'E' || x = 'F' ||
     87       x = 'a' || x = 'b' || x = 'c' || x = 'd' ||
     88       x = 'e' || x = 'f')
    8789
  • Deliverables/D4.1/Physical.ml

    r442 r448  
    1111   val add : key -> byte -> map -> map
    1212   val fold : (key -> byte -> 'b -> 'b) -> map -> 'b -> 'b
     13   val equal: (byte -> byte -> bool) -> map -> map -> bool
    1314 end
    1415;;
     
    2324    with Not_found -> zero `Eight
    2425  let fold = fold
     26  let equal = equal
    2527end;;
    2628
     
    3436    with Not_found -> zero `Eight
    3537  let fold = fold
     38  let equal = equal
    3639end;;
    3740
  • Deliverables/D4.1/Physical.mli

    r442 r448  
    1111   val add : key -> byte -> map -> map
    1212   val fold : (key -> byte -> 'b -> 'b) -> map -> 'b -> 'b
     13   val equal: (byte -> byte -> bool) -> map -> map -> bool
    1314 end
    1415;;
  • Deliverables/D4.1/Test.ml

    r447 r448  
    88let mem = IntelHex.process_intel_hex hex in
    99let status = ASMInterpret.load_mem mem ASMInterpret.initialize in
    10 let _ = file_of_intel_hex "hex-output-test.hex" (pack_exported_code_memory 12 128 status.code_memory) in
     10let _ = file_of_intel_hex "hex_test_out.hex" (pack_exported_code_memory 12 114 status.code_memory) in
     11let mem' = IntelHex.process_intel_hex (IntelHex.intel_hex_of_file "hex_test_out.hex") in
     12let _ = assert (Physical.WordMap.equal (=) mem mem') in
     13let status = ASMInterpret.load_mem mem ASMInterpret.initialize in
    1114let observe status =
    1215 let pc = status.ASMInterpret.pc in
Note: See TracChangeset for help on using the changeset viewer.