ld.elf_so, grep, make: use mmap()
[minix3.git] / drivers / at_wini / liveupdate.c
blob25a57b742446fac34bc68b2364ea148db274f7b8
1 #include "at_wini.h"
3 /* State management variables. */
4 EXTERN int w_command;
6 /* State management helpers. */
7 #define IS_REQUEST_PENDING(c) ((c) != CMD_IDLE)
8 #define IS_READ_PENDING(c) ((c) == CMD_READ \
9 || (c) == CMD_READ_EXT || (c) == CMD_READ_DMA || (c) == CMD_READ_DMA_EXT)
10 #define IS_WRITE_PENDING(c) ((c) == CMD_WRITE \
11 || (c) == CMD_WRITE_EXT || (c) == CMD_WRITE_DMA || (c) == CMD_WRITE_DMA_EXT)
13 /* Custom states definition. */
14 #define AT_STATE_READ_REQUEST_FREE (SEF_LU_STATE_CUSTOM_BASE + 0)
15 #define AT_STATE_WRITE_REQUEST_FREE (SEF_LU_STATE_CUSTOM_BASE + 1)
16 #define AT_STATE_IS_CUSTOM(s) \
17 ((s) >= AT_STATE_READ_REQUEST_FREE && (s) <= AT_STATE_WRITE_REQUEST_FREE)
19 /*===========================================================================*
20 * sef_cb_lu_prepare *
21 *===========================================================================*/
22 int sef_cb_lu_prepare(int state)
24 int is_ready;
26 /* Check if we are ready for the target state. */
27 is_ready = FALSE;
28 switch(state) {
29 /* Standard states. */
30 case SEF_LU_STATE_REQUEST_FREE:
31 case SEF_LU_STATE_PROTOCOL_FREE:
32 is_ready = (!IS_REQUEST_PENDING(w_command));
33 break;
35 /* Custom states. */
36 case AT_STATE_READ_REQUEST_FREE:
37 is_ready = (!IS_READ_PENDING(w_command));
38 break;
40 case AT_STATE_WRITE_REQUEST_FREE:
41 is_ready = (!IS_WRITE_PENDING(w_command));
42 break;
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) || AT_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("at_wini: live update state = %d\n", state);
63 sef_lu_dprint("at_wini: w_command = 0x%02X\n", w_command);
65 sef_lu_dprint("at_wini: SEF_LU_STATE_WORK_FREE(%d) reached = %d\n",
66 SEF_LU_STATE_WORK_FREE, TRUE);
67 sef_lu_dprint("at_wini: SEF_LU_STATE_REQUEST_FREE(%d) reached = %d\n",
68 SEF_LU_STATE_REQUEST_FREE, (!IS_REQUEST_PENDING(w_command)));
69 sef_lu_dprint("at_wini: SEF_LU_STATE_PROTOCOL_FREE(%d) reached = %d\n",
70 SEF_LU_STATE_PROTOCOL_FREE, (!IS_REQUEST_PENDING(w_command)));
71 sef_lu_dprint("at_wini: AT_STATE_READ_REQUEST_FREE(%d) reached = %d\n",
72 AT_STATE_READ_REQUEST_FREE, (!IS_READ_PENDING(w_command)));
73 sef_lu_dprint("at_wini: AT_STATE_WRITE_REQUEST_FREE(%d) reached = %d\n",
74 AT_STATE_WRITE_REQUEST_FREE, (!IS_WRITE_PENDING(w_command)));