Ignore:
Timestamp:
Nov 4, 2010, 12:27:37 PM (9 years ago)
Author:
mulligan
Message:

Interrupts are harder than they look.

File:
1 edited

Legend:

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

    r215 r216  
    1515            | `P3 of byte
    1616            | `SerialBuff of [ `Eight of byte | `Nine of BitVectors.bit * byte ]];;
    17 
    18 type interrupt =
    19   Timer0
    20 | Timer1
    21 | External0
    22 | External1
    2317
    2418let string_of_line =
     
    135129  e0i_running: bool;
    136130  e1i_running: bool;
    137 
    138   interrupt_queue: interrupt list;
     131  es_running: bool;
    139132}
    140133
     
    278271  io = debug_continuation; (* a real assert false: unprepared for i/o *)
    279272
     273  (* Initially no interrupts are executing *)
    280274  esi_running = false;
    281275  t0i_running = false;
     
    283277  e0i_running = false;
    284278  e1i_running = false;
    285 
    286   interrupt_queue = [];
     279  es_running = false;
    287280}
    288281
     
    14701463
    14711464let external_serial_interrupt status esi =
     1465  (* Interrupt enabled *)
    14721466  if esi then
    1473     assert false
     1467    (* If we're already running, then fine (todo: check for *another* interrupt
     1468       and add to a queue, or something? *)
     1469    if status.t1i_running then
     1470      status
     1471    else
     1472      (* If we should be running, but aren't... *)
     1473      if false then
     1474        assert false
     1475      else
     1476        status
    14741477  else
    14751478    status
     
    14771480
    14781481let external0_interrupt status e0i =
     1482  (* Interrupt enabled *)
    14791483  if e0i then
    1480     assert false
     1484    (* If we're already running, then fine (todo: check for *another* interrupt
     1485       and add to a queue, or something? *)
     1486    if status.t1i_running then
     1487      status
     1488    else
     1489      (* If we should be running, but aren't... *)
     1490      if false then
     1491        assert false
     1492      else
     1493        status
    14811494  else
    14821495    status
     
    14841497
    14851498let external1_interrupt status e1i =
     1499  (* Interrupt enabled *)
    14861500  if e1i then
    1487     assert false
     1501    (* If we're already running, then fine (todo: check for *another* interrupt
     1502       and add to a queue, or something? *)
     1503    if status.t1i_running then
     1504      status
     1505    else
     1506      (* If we should be running, but aren't... *)
     1507      if false then
     1508        assert false
     1509      else
     1510        status
    14881511  else
    14891512    status
     
    14911514
    14921515let timer0_interrupt status t0i =
     1516  (* Interrupt enabled *)
    14931517  if t0i then
    1494     assert false
     1518    (* If we're already running, then fine (todo: check for *another* interrupt
     1519       and add to a queue, or something? *)
     1520    if status.t1i_running then
     1521      status
     1522    else
     1523      (* If we should be running, but aren't... *)
     1524      if false then
     1525        assert false
     1526      else
     1527        status
    14951528  else
    14961529    status
     
    14981531
    14991532let timer1_interrupt status t1i =
     1533  (* Interrupt enabled *)
    15001534  if t1i then
    1501     assert false
     1535    (* If we're already running, then fine (todo: check for *another* interrupt
     1536       and add to a queue, or something? *)
     1537    if status.t1i_running then
     1538      status
     1539    else
     1540      (* If we should be running, but aren't... *)
     1541      if false then
     1542        assert false
     1543      else
     1544        status
    15021545  else
    15031546    status
     
    15091552    (* DPM: are interrupts enabled? *)
    15101553    if ea then
    1511       match (pt1,px1,pt0,px0) with
     1554      match (ps,pt1,px1,pt0,px0) with
    15121555        (* Check priorities of interrupts *)
    1513         (false,false,false,false) ->
     1556        (false,false,false,false,false) ->
    15141557          (* Standard priority, so just do regular polling sequence *)
    15151558          let status = external0_interrupt status ex0 in
     
    15191562          let status = external_serial_interrupt status es in
    15201563            status
    1521       | (true,false,false,false) ->
     1564      | (true,false,false,false,false) ->
     1565          if status.es_running then
     1566            (* External interrupt is currently running, and cannot be interrupted *)
     1567            status
     1568          else
     1569            (* Standard priority, so just do regular polling sequence *)
     1570            let status = external0_interrupt status ex0 in
     1571            let status = timer0_interrupt status et0 in
     1572            let status = external1_interrupt status ex1 in
     1573            let status = timer1_interrupt status et1 in
     1574            let status = external_serial_interrupt status es in
     1575              status
     1576      | (false,true,false,false,false) ->
    15221577          if status.t1i_running then
    15231578            (* Timer1 interrupt is currently running, and cannot be interrupted *)
     
    15311586            let status = external_serial_interrupt status es in
    15321587              status
    1533       | (false,true,false,false) ->
     1588      | (false,false,true,false,false) ->
    15341589          if status.e1i_running then
    15351590            (* External1 interrupt is currently running, and cannot be interrupted *)
     
    15431598            let status = external_serial_interrupt status es in
    15441599              status
    1545       | (false,false,true,false) ->
     1600      | (false,false,false,true,false) ->
    15461601          if status.t0i_running then
    15471602            (* Timer0 interrupt is currently running, and cannot be interrupted *)
     
    15551610            let status = external_serial_interrupt status es in
    15561611              status
    1557       | (false,false,false,true) ->
     1612      | (false,false,false,false,true) ->
    15581613          if status.e0i_running then
    15591614            (* External0 interrupt is currently running, and cannot be interrupted *)
     
    15671622            let status = external_serial_interrupt status es in
    15681623              status
    1569       | (true,true,false,false) ->
     1624      | (false,true,true,false,false) ->
    15701625          if status.t1i_running && status.e1i_running then
    15711626            (* Cannot have two interrupts with same priority running together *)
Note: See TracChangeset for help on using the changeset viewer.