dec21140A ethernet driver for virtualpc, contributed by nicolas tittley.
[minix.git] / drivers / floppy / liveupdate.c
blob0d4d1421a89c3b0a853a7a466705cf12c45c5dc3
1 #include "floppy.h"
3 /* State management variables. */
4 EXTERN u16_t f_busy;
5 EXTERN int motor_status;
6 EXTERN unsigned f_drive;
7 EXTERN int last_transfer_opcode;
8 #define BSY_IO 1 /* busy doing I/O */
10 /* State management helpers. */
11 #define IS_REQUEST_PENDING(b) ((b) == BSY_IO)
12 #define IS_READ_PENDING(b, c) \
13 (IS_REQUEST_PENDING((b)) && (c) == DEV_GATHER_S)
14 #define IS_WRITE_PENDING(b, c) \
15 (IS_REQUEST_PENDING((b)) && (c) == DEV_SCATTER_S)
16 #define IS_MOTOR_RUNNING(s, d) ((s) & (1 << (d)))
18 /* Custom states definition. */
19 #define FL_STATE_MOTOR_OFF (SEF_LU_STATE_CUSTOM_BASE + 0)
20 #define FL_STATE_IS_CUSTOM(s) ((s) == FL_STATE_MOTOR_OFF)
22 /*===========================================================================*
23 * sef_cb_lu_prepare *
24 *===========================================================================*/
25 PUBLIC void sef_cb_lu_prepare(int state)
27 int is_ready;
29 /* Check if we are ready for the target state. */
30 is_ready = FALSE;
31 switch(state) {
32 /* Standard states. */
33 case SEF_LU_STATE_REQUEST_FREE:
34 case SEF_LU_STATE_PROTOCOL_FREE:
35 is_ready = (!IS_REQUEST_PENDING(f_busy));
36 break;
38 /* Custom states. */
39 case FL_STATE_MOTOR_OFF:
40 is_ready = (!IS_REQUEST_PENDING(f_busy)
41 && !IS_MOTOR_RUNNING(motor_status, f_drive));
42 break;
45 /* Tell SEF if we are ready. */
46 if(is_ready) {
47 sef_lu_ready(OK);
51 /*===========================================================================*
52 * sef_cb_lu_state_isvalid *
53 *===========================================================================*/
54 PUBLIC int sef_cb_lu_state_isvalid(int state)
56 return SEF_LU_STATE_IS_STANDARD(state) || FL_STATE_IS_CUSTOM(state);
59 /*===========================================================================*
60 * sef_cb_lu_state_dump *
61 *===========================================================================*/
62 PUBLIC void sef_cb_lu_state_dump(int state)
64 sef_lu_dprint("floppy: live update state = %d\n", state);
65 sef_lu_dprint("floppy: f_busy = %d\n", f_busy);
66 sef_lu_dprint("floppy: motor_status = 0x%02X\n", motor_status);
67 sef_lu_dprint("floppy: f_drive = %d\n", f_drive);
68 sef_lu_dprint("floppy: last_transfer_opcode = 0x%02X\n",
69 last_transfer_opcode);
71 sef_lu_dprint("floppy: SEF_LU_STATE_WORK_FREE(%d) reached = %d\n",
72 SEF_LU_STATE_WORK_FREE, TRUE);
73 sef_lu_dprint("floppy: SEF_LU_STATE_REQUEST_FREE(%d) reached = %d\n",
74 SEF_LU_STATE_REQUEST_FREE, (!IS_REQUEST_PENDING(f_busy)));
75 sef_lu_dprint("floppy: SEF_LU_STATE_PROTOCOL_FREE(%d) reached = %d\n",
76 SEF_LU_STATE_PROTOCOL_FREE, (!IS_REQUEST_PENDING(f_busy)));
77 sef_lu_dprint("floppy: FL_STATE_MOTOR_OFF(%d) reached = %d\n",
78 FL_STATE_MOTOR_OFF, (!IS_REQUEST_PENDING(f_busy)
79 && !IS_MOTOR_RUNNING(motor_status, f_drive)));