Guest User

Copper/CircuitOS IPC Design

a guest
Oct 16th, 2015
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.13 KB | None | 0 0
  1. == main.cu, /os/main ==
  2.  
  3. OBJ keyboard : "/io/keyboard";
  4. OBJ console  : "/io/console";
  5.  
  6. PUB main() | c : TEXT
  7. BEGIN
  8.     keyboard.waitForDriver();
  9.    
  10.     # selects the current thread for reading keyboard input
  11.     keyboard.setFocus();
  12.     WHILE TRUE DO
  13.         keyboard.getChar() → c;
  14.         console.put(c);
  15.     END
  16. END
  17.  
  18. == keyboard.cu, /io/keyboard ==
  19.  
  20. TYPE KeyData IS
  21.     …
  22. END
  23.  
  24. SHARED VAR buffer : KeyData;
  25.  
  26. SHARED PRI init()
  27. BEGIN
  28.     # Initialize shared data with necessary non-nil pointer
  29.     [KeyData] → buffer;
  30. NED
  31.  
  32. PUB sendKeyHit(keycode : INT)
  33. BEGIN
  34.     …
  35. END
  36.  
  37. PUB sendKeyRelease(keycode : INT)
  38. BEGIN
  39.     …
  40. END
  41.  
  42. PUB getChar() → c : TEXT
  43. BEGIN
  44.     # We just always send a nice little k instead of reading actual key pressed... :P
  45.     "k" → c;
  46. END
  47.  
  48. == keyboard.driver.cu, /drv/keyboard ==
  49. OBJ interrupts : "/sys/interrupts";
  50. OBJ keyboard   : "/io/keyboard";
  51.  
  52. PRI irq(id : INT, cpu : CPUSTATE) | breakcode : BOOL, key : INT
  53. BEGIN
  54.     IF id =/= 0x21 THEN
  55.         RETURN;
  56.     END
  57.     # Code that reads scancodes and translates them to keycodes.
  58.     …
  59.     IF breakcode THEN
  60.         keyboard.sendKeyRelease(key);
  61.     ELSE
  62.         keyboard.sendKeyHit(key);
  63.     END
  64. END
Advertisement
Add Comment
Please, Sign In to add comment