Ignore:
Timestamp:
Oct 8, 2010, 6:11:14 PM (9 years ago)
Author:
mulligan
Message:

I/O support added for serial buffer.

File:
1 edited

Legend:

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

    r163 r166  
    1212
    1313type time = int;;
    14 type line = [`P0 | `P1 ];; (* ??? *)
     14type line = [ `P0 of byte
     15            | `P1 of byte
     16            | `SerialBuff of [ `Eight of byte | `Nine of BitVectors.bit * byte ]];;
     17
     18(* In:  reception time, line of input, new continuation,
     19   Out: transmission time, output line, expected duration until reply,
     20        new continuation.
     21*)
    1522type continuation =
    16 unit (*
    17  [`In of time * line * byte * continuation] option *
    18  [`Out of (time -> line -> byte -> continuation) ]
    19 *)
     23  [`In of time * line * continuation] option *
     24  [`Out of (time -> line -> time * continuation) ]
    2025
    2126(* no differentiation between internal and external code memory *)
     
    6065   timer1: word;
    6166   timer2: word;  (* can be missing *)
     67   expected_out_time: [ `None | `Now | `At of time ];
    6268   io: continuation
    6369 }
     
    109115  | 0xA0 -> { status with p2 = v }
    110116  | 0xB0 -> { status with p3 = v }
    111   | 0x99 -> { status with sbuf = v }
     117  | 0x99 ->
     118      if status.expected_out_time = `None then
     119        { status with sbuf = v; expected_out_time = `Now }
     120      else
     121        (* a real assert false: trying to initiate a transmission whilst one is still active *)
     122        assert false
    112123  | 0x8A -> { status with tl0 = v }
    113124  | 0x8B -> { status with tl1 = v }
     
    178189  timer2 = zero `Sixteen;
    179190
    180   io = ()
     191  expected_out_time = `None;
     192
     193  io = (None, `Out (fun t l -> assert false)) (* a real assert false: unprepared for i/o *)
    181194}
    182195
     
    13381351                status) in
    13391352          (* Timer 1 follows. *)
     1353        let status =
    13401354          (match b3,b4 with
    13411355            true,true ->
     
    14011415                    { status with tl1 = res }
    14021416              else
    1403                 status)
     1417                status) in
     1418       (* Serial port code now follows *)
     1419         let in_cont, `Out out_cont = status.io in
     1420         let status =
     1421           (* Serial port input *)
     1422           (match in_cont with
     1423             Some (`In(time, line, cont)) when time >= status.clock && get_bit status.scon 4 ->
     1424               let status =
     1425                 match line with
     1426                   `P0 b -> assert false
     1427                 | `P1 b -> assert false
     1428                 | `SerialBuff (`Eight b) ->
     1429                      let b7 = get_bit (status.scon) 7 in
     1430                        (* waiting for nine bits, multiprocessor communication mode requires nine bits *)
     1431                        if b7 || get_bit status.scon 5 then
     1432                          assert false (* really: crash! *)
     1433                        else
     1434                          let status = { status with scon = set_bit status.scon 0 true } in
     1435                          let status = { status with sbuf = b } in
     1436                            status
     1437                 | `SerialBuff (`Nine (b,b')) ->
     1438                      let b7 = get_bit (status.scon) 7 in
     1439                        (* waiting for eight bits *)
     1440                        if not b7 then
     1441                          assert false (* really: crash! *)
     1442                        else
     1443                          let status = { status with scon = set_bit status.scon 2 b } in
     1444                          let status = { status with sbuf = b' } in
     1445                            if (not $ get_bit status.scon 5) || b then
     1446                              { status with scon = set_bit status.scon 0 true }
     1447                            else
     1448                              status
     1449               in
     1450                 { status with io = cont }
     1451           | _ -> status) in
     1452           (* Serial port output, part one *)
     1453           let status =
     1454             (match status.expected_out_time with
     1455               `At t when status.clock >= t ->
     1456                 { status with scon = set_bit status.scon 1 true; expected_out_time = `None }
     1457              | _ -> status) in
     1458           (* Serial port output, part two *)
     1459           if status.expected_out_time = `Now then
     1460             if get_bit status.scon 7 then
     1461               let exp_time, new_cont = out_cont status.clock (`SerialBuff (`Nine ((get_bit status.scon 3), status.sbuf))) in
     1462                 { status with expected_out_time = `At exp_time; io = new_cont }
     1463             else
     1464               let exp_time, new_cont = out_cont status.clock (`SerialBuff (`Eight status.sbuf)) in
     1465                 { status with expected_out_time = `At exp_time; io = new_cont }               
     1466           else
     1467             status
    14041468;;
    14051469
Note: See TracChangeset for help on using the changeset viewer.