minor fixes for safecopy & safemap tests
[minix.git] / lib / libaudiodriver / liveupdate.c
blob96b8a35fe1ef27416ab31acc5e7acccfaf25a6b1
1 #include <minix/audio_fw.h>
3 /* State management variables. */
4 EXTERN int is_status_msg_expected;
5 /*
6 * - From audio_fw.h:
7 * EXTERN drv_t drv;
8 * EXTERN sub_dev_t sub_dev[];
9 */
11 /* State management helpers */
12 static int is_read_pending;
13 static int is_write_pending;
14 static void load_state_info(void)
16 int i, dma_mode, found_pending;
18 /* Check if reads or writes are pending. */
19 is_read_pending = FALSE;
20 is_write_pending = FALSE;
21 found_pending = FALSE;
22 for (i = 0; i < drv.NrOfSubDevices && !found_pending; i++) {
23 if(sub_dev[i].RevivePending) {
24 dma_mode = sub_dev[i].DmaMode;
26 if(dma_mode == DEV_READ_S) {
27 is_read_pending = TRUE;
29 else if (dma_mode == DEV_WRITE_S){
30 is_write_pending = TRUE;
34 found_pending = (is_read_pending && is_write_pending);
38 /* Custom states definition. */
39 #define AUDIO_STATE_READ_REQUEST_FREE (SEF_LU_STATE_CUSTOM_BASE + 0)
40 #define AUDIO_STATE_WRITE_REQUEST_FREE (SEF_LU_STATE_CUSTOM_BASE + 1)
41 #define AUDIO_STATE_IS_CUSTOM(s) \
42 ((s) >= AUDIO_STATE_READ_REQUEST_FREE && (s) <=AUDIO_STATE_WRITE_REQUEST_FREE)
44 /*===========================================================================*
45 * sef_cb_lu_prepare *
46 *===========================================================================*/
47 int sef_cb_lu_prepare(int state)
49 int is_ready;
51 /* Load state information. */
52 load_state_info();
54 /* Check if we are ready for the target state. */
55 is_ready = FALSE;
56 switch(state) {
57 /* Standard states. */
58 case SEF_LU_STATE_REQUEST_FREE:
59 is_ready = (!is_read_pending && !is_write_pending);
60 break;
62 case SEF_LU_STATE_PROTOCOL_FREE:
63 is_ready = (!is_read_pending && !is_write_pending
64 && !is_status_msg_expected);
65 break;
67 /* Custom states. */
68 case AUDIO_STATE_READ_REQUEST_FREE:
69 is_ready = (!is_read_pending);
70 break;
72 case AUDIO_STATE_WRITE_REQUEST_FREE:
73 is_ready = (!is_write_pending);
74 break;
77 /* Tell SEF if we are ready. */
78 return is_ready ? OK : ENOTREADY;
81 /*===========================================================================*
82 * sef_cb_lu_state_isvalid *
83 *===========================================================================*/
84 int sef_cb_lu_state_isvalid(int state)
86 return SEF_LU_STATE_IS_STANDARD(state) || AUDIO_STATE_IS_CUSTOM(state);
89 /*===========================================================================*
90 * sef_cb_lu_state_dump *
91 *===========================================================================*/
92 void sef_cb_lu_state_dump(int state)
94 /* Load state information. */
95 load_state_info();
97 sef_lu_dprint("audio: live update state = %d\n", state);
98 sef_lu_dprint("audio: is_status_msg_expected = %d\n",
99 is_status_msg_expected);
100 sef_lu_dprint("audio: is_read_pending = %d\n", is_read_pending);
101 sef_lu_dprint("audio: is_write_pending = %d\n", is_write_pending);
103 sef_lu_dprint("audio: SEF_LU_STATE_WORK_FREE(%d) reached = %d\n",
104 SEF_LU_STATE_WORK_FREE, TRUE);
105 sef_lu_dprint("audio: SEF_LU_STATE_REQUEST_FREE(%d) reached = %d\n",
106 SEF_LU_STATE_REQUEST_FREE, (!is_read_pending && !is_write_pending));
107 sef_lu_dprint("audio: SEF_LU_STATE_PROTOCOL_FREE(%d) reached = %d\n",
108 SEF_LU_STATE_PROTOCOL_FREE, (!is_read_pending && !is_write_pending
109 && !is_status_msg_expected));
110 sef_lu_dprint("audio: AUDIO_STATE_READ_REQUEST_FREE(%d) reached = %d\n",
111 AUDIO_STATE_READ_REQUEST_FREE, (!is_read_pending));
112 sef_lu_dprint("audio: AUDIO_STATE_WRITE_REQUEST_FREE(%d) reached = %d\n",
113 AUDIO_STATE_WRITE_REQUEST_FREE, (!is_write_pending));