3 /* State management variables. */
5 EXTERN
int motor_status
;
6 EXTERN
unsigned f_drive
;
7 EXTERN
int last_was_write
;
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 /*===========================================================================*
24 *===========================================================================*/
25 int sef_cb_lu_prepare(int state
)
29 /* Check if we are ready for the target 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
));
39 case FL_STATE_MOTOR_OFF
:
40 is_ready
= (!IS_REQUEST_PENDING(f_busy
)
41 && !IS_MOTOR_RUNNING(motor_status
, f_drive
));
45 /* Tell SEF if we are ready. */
46 return is_ready
? OK
: ENOTREADY
;
49 /*===========================================================================*
50 * sef_cb_lu_state_isvalid *
51 *===========================================================================*/
52 int sef_cb_lu_state_isvalid(int state
)
54 return SEF_LU_STATE_IS_STANDARD(state
) || FL_STATE_IS_CUSTOM(state
);
57 /*===========================================================================*
58 * sef_cb_lu_state_dump *
59 *===========================================================================*/
60 void sef_cb_lu_state_dump(int state
)
62 sef_lu_dprint("floppy: live update state = %d\n", state
);
63 sef_lu_dprint("floppy: f_busy = %d\n", f_busy
);
64 sef_lu_dprint("floppy: motor_status = 0x%02X\n", motor_status
);
65 sef_lu_dprint("floppy: f_drive = %d\n", f_drive
);
66 sef_lu_dprint("floppy: last_was_write = %d\n", last_was_write
);
68 sef_lu_dprint("floppy: SEF_LU_STATE_WORK_FREE(%d) reached = %d\n",
69 SEF_LU_STATE_WORK_FREE
, TRUE
);
70 sef_lu_dprint("floppy: SEF_LU_STATE_REQUEST_FREE(%d) reached = %d\n",
71 SEF_LU_STATE_REQUEST_FREE
, (!IS_REQUEST_PENDING(f_busy
)));
72 sef_lu_dprint("floppy: SEF_LU_STATE_PROTOCOL_FREE(%d) reached = %d\n",
73 SEF_LU_STATE_PROTOCOL_FREE
, (!IS_REQUEST_PENDING(f_busy
)));
74 sef_lu_dprint("floppy: FL_STATE_MOTOR_OFF(%d) reached = %d\n",
75 FL_STATE_MOTOR_OFF
, (!IS_REQUEST_PENDING(f_busy
)
76 && !IS_MOTOR_RUNNING(motor_status
, f_drive
)));