1 /* Code to manage the interface between the simulator and the kernel.
2 Copyright (C) 2005-2008, Jonathan Bachrach, Jacob Beal, and contributors
3 listed in the AUTHORS file in the MIT Proto distribution's top directory.
5 This file is part of MIT Proto, and is distributed under the terms of
6 the GNU General Public License, with a linking exception, as described
7 in the file LICENSE in the MIT Proto distribution's top directory. */
9 #ifndef __SIM_HARDWARE__
10 #define __SIM_HARDWARE__
14 // posts data without pretty nesting
15 void post_stripped_data_to (char *str
, DATA
*d
);
17 // HardwarePatch is a class that Layers should extend in order to make
18 // their dynamics available to the kernel.
21 void hardware_error(char* name
) {
22 uerror("Attempt to use unimplemented hardware function '%s'",name
);
25 virtual void mov (VEC_VAL
*val
) { hardware_error("mov"); }
26 virtual void flex (NUM_VAL val
) { hardware_error("flex"); }
27 virtual void die (NUM_VAL val
) { hardware_error("die"); }
28 virtual void clone_machine (NUM_VAL val
) { hardware_error("clone_machine"); }
30 virtual NUM_VAL
cam_get (int k
) { hardware_error("cam_get"); }
31 virtual NUM_VAL
radius_get (VOID
) { hardware_error("radius_get"); }
32 virtual NUM_VAL
radius_set (NUM_VAL val
) { hardware_error("radius_set"); }
34 virtual void set_r_led (NUM_VAL val
) { hardware_error("set_r_led"); }
35 virtual void set_g_led (NUM_VAL val
) { hardware_error("set_g_led"); }
36 virtual void set_b_led (NUM_VAL val
) { hardware_error("set_b_led"); }
37 virtual void set_probe (DATA
* d
, uint8_t p
) { hardware_error("set_probe"); }
38 virtual void set_speak (NUM_VAL period
) { hardware_error("set_speak"); }
40 virtual NUM_VAL
set_dt (NUM_VAL dt
) { hardware_error("set_dt"); }
42 virtual void set_is_folding (BOOL val
, int k
)
43 { hardware_error("set_is_folding"); }
44 virtual BOOL
read_fold_complete (int val
)
45 { hardware_error("read_fold_complete"); }
47 virtual NUM_VAL
set_channel (NUM_VAL diffusion
, int k
)
48 { hardware_error("set_channel"); }
49 virtual NUM_VAL
read_channel (int k
) { hardware_error("read_channel"); }
50 virtual NUM_VAL
drip_channel (NUM_VAL val
, int k
)
51 { hardware_error("drip_channel"); }
52 virtual VEC_VAL
*grad_channel (int k
) { hardware_error("grad_channel"); }
54 virtual NUM_VAL
read_radio_range (VOID
) {hardware_error("read_radio_range");}
55 virtual NUM_VAL
read_light_sensor(VOID
){hardware_error("read_light_sensor");}
56 virtual NUM_VAL
read_microphone (VOID
) { hardware_error("read_microphone"); }
57 virtual NUM_VAL
read_temp (VOID
) { hardware_error("read_temp"); }
58 virtual NUM_VAL
read_short (VOID
) { hardware_error("read_short"); }
59 virtual NUM_VAL
read_sensor (uint8_t n
) { hardware_error("read_sensor"); }
60 virtual VEC_VAL
*read_coord_sensor(VOID
)
61 { hardware_error("read_coord_sensor"); }
62 virtual VEC_VAL
*read_mouse_sensor(VOID
)
63 { hardware_error("read_mouse_sensor"); }
64 virtual VEC_VAL
*read_ranger (VOID
) { hardware_error("read_ranger"); }
65 virtual NUM_VAL
read_bearing (VOID
) { hardware_error("read_bearing"); }
66 virtual NUM_VAL
read_speed (VOID
) { hardware_error("read_speed"); }
67 virtual NUM_VAL
read_bump (VOID
) { hardware_error("read_bump"); }
68 virtual NUM_VAL
read_button (uint8_t n
) { hardware_error("read_button"); }
69 virtual NUM_VAL
read_slider (uint8_t ikey
, uint8_t dkey
, NUM_VAL init
,
70 NUM_VAL incr
, NUM_VAL min
, NUM_VAL max
)
71 { hardware_error("read_slider"); }
73 virtual int radio_send_export (uint8_t version
, uint8_t timeout
, uint8_t n
,
74 uint8_t len
, COM_DATA
*buf
)
75 { hardware_error("radio_send_export"); }
76 virtual int radio_send_script_pkt (uint8_t version
, uint16_t n
,
77 uint8_t pkt_num
, uint8_t *script
)
78 { hardware_error("radio_send_script_pkt"); }
79 virtual int radio_send_digest (uint8_t version
, uint16_t script_len
,
81 { hardware_error("radio_send_digest"); }
84 // A list of all the functions that can be supplied with a HardwarePatch,
85 // for use in applying the patches in a SimulatedHardware
86 enum HardwareFunction
{
87 MOV_FN
, FLEX_FN
, DIE_FN
, CLONE_MACHINE_FN
,
88 CAM_GET_FN
, RADIUS_GET_FN
, RADIUS_SET_FN
,
89 SET_R_LED_FN
, SET_G_LED_FN
, SET_B_LED_FN
, SET_PROBE_FN
, SET_SPEAK_FN
,
90 SET_DT_FN
, SET_IS_FOLDING_FN
, READ_FOLD_COMPLETE_FN
,
91 SET_CHANNEL_FN
, READ_CHANNEL_FN
, DRIP_CHANNEL_FN
, GRAD_CHANNEL_FN
,
92 READ_RADIO_RANGE_FN
, READ_LIGHT_SENSOR_FN
, READ_MICROPHONE_FN
,
93 READ_TEMP_FN
, READ_SHORT_FN
, READ_SENSOR_FN
, READ_COORD_SENSOR_FN
,
94 READ_MOUSE_SENSOR_FN
, READ_RANGER_FN
, READ_BEARING_FN
, READ_SPEED_FN
,
95 READ_BUMP_FN
, READ_BUTTON_FN
, READ_SLIDER_FN
,
96 RADIO_SEND_EXPORT_FN
, RADIO_SEND_SCRIPT_PKT_FN
, RADIO_SEND_DIGEST_FN
,
100 // This class dispatches kernel hardware calls to the appropriate patches
102 class SimulatedHardware
{
104 BOOL is_kernel_debug
, is_kernel_trace
, is_kernel_debug_script
;
106 HardwarePatch
* patch_table
[NUM_HARDWARE_FNS
];
109 void patch(HardwarePatch
* p
, HardwareFunction fn
); // instantiate a fn
110 void set_vm_context(Device
* d
); // prepare globals for kernel execution
113 // globals that carry the VM context for kernel hardware calls
114 // HardwarePatch classes can count on them being set to correct values
115 extern SimulatedHardware
* hardware
;
116 extern Device
* device
;
118 // Construction and destruction within a device object
119 extern MACHINE
* allocate_machine();
120 extern void deallocate_machine(MACHINE
** vm
);
122 #endif //__SIM_HARDWARE__