Changeset 131


Ignore:
Timestamp:
Sep 27, 2010, 1:25:06 PM (9 years ago)
Author:
mulligan
Message:

Changes from this morning: checking checksum is correct for a
intel_hex_entry. Also some new useful functions in Util and elsewhere.

Location:
Deliverables/D4.1
Files:
3 edited

Legend:

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

    r130 r131  
    7878  | 4 -> ExtendedLinear
    7979  | _ -> assert false
     80;;
     81
     82let int_of_intel_hex_type =
     83  function
     84    Data -> 0
     85  | End -> 1
     86  | ExtendedSeg -> 2
     87  | ExtendedLinear -> 4
    8088;;
    8189
     
    183191  in
    184192    aux strs
     193
     194let add_bytes v  =
     195  let r = List.rev v in
     196  let rec aux (cry, bs) =
     197    function
     198      [] -> (cry, bs)
     199    | hd::tl ->
     200        aux (full_add hd bs cry) tl
     201  in
     202    aux (false, (vect_of_int 0 `Eight)) r
     203
     204let checksum_valid hex_entry =
     205  if List.length hex_entry.data_field mod 2 <> 0 then
     206    false
     207  else
     208    let chk_1, chk_2 = hex_entry.data_checksum in
     209    let _, cs_total = half_add chk_1 chk_2 in
     210    let len_1, len_2 = hex_entry.record_length in
     211    let _, ln_total = half_add len_1 len_2 in
     212    let adr_1, adr_2, adr_3, adr_4 = hex_entry.record_addr in
     213    let _, ad_total1 = half_add adr_1 adr_2 in
     214    let _, ad_total2 = half_add adr_3 adr_4 in
     215    let _, dt_total = add_bytes hex_entry.data_field in
     216    let _, total = add_bytes [cs_total; ln_total; ad_total1; ad_total2; dt_total] in
     217      cs_total = total
  • Deliverables/D4.1/IntelHex.mli

    r130 r131  
    2626val vect_of_hex_string: string -> sizes -> sizes vect;;
    2727val hex_string_of_vect: 'a vect -> string;;
     28
     29val checksum_valid: intel_hex_entry -> bool;;
  • Deliverables/D4.1/Util.ml

    r130 r131  
    33
    44let (<*>) f g x = f (g x)
     5;;
     6
     7let flip f a b = f b a
    58;;
    69
Note: See TracChangeset for help on using the changeset viewer.