00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00035 #ifndef VHC_HUB_HUB_H_
00036 #define VHC_HUB_HUB_H_
00037
00038 #include <fibril_synch.h>
00039
00040 #ifndef HUB_PORT_COUNT
00041 #define HUB_PORT_COUNT 2
00042 #endif
00043 #define BITS2BYTES(bits) (bits ? ((((bits)-1)>>3)+1) : 0)
00044
00049 typedef enum {
00050 HUB_PORT_STATE_UNKNOWN,
00051 HUB_PORT_STATE_NOT_CONFIGURED,
00052 HUB_PORT_STATE_POWERED_OFF,
00053 HUB_PORT_STATE_DISCONNECTED,
00054 HUB_PORT_STATE_DISABLED,
00055 HUB_PORT_STATE_RESETTING,
00056 HUB_PORT_STATE_ENABLED,
00057 HUB_PORT_STATE_SUSPENDED,
00058 HUB_PORT_STATE_RESUMING,
00059
00060 } hub_port_state_t;
00061
00062 char hub_port_state_to_char(hub_port_state_t);
00063
00065 typedef enum {
00066 HUB_STATUS_C_PORT_CONNECTION = (1 << 0),
00067 HUB_STATUS_C_PORT_ENABLE = (1 << 1),
00068 HUB_STATUS_C_PORT_SUSPEND = (1 << 2),
00069 HUB_STATUS_C_PORT_OVER_CURRENT = (1 << 3),
00070 HUB_STATUS_C_PORT_RESET = (1 << 4),
00071
00072 } hub_status_change_t;
00073
00074 typedef struct hub hub_t;
00075
00077 typedef struct {
00079 void *connected_device;
00081 size_t index;
00083 hub_port_state_t state;
00085 uint16_t status_change;
00087 hub_t *hub;
00088 } hub_port_t;
00089
00091 struct hub {
00093 hub_port_t ports[HUB_PORT_COUNT];
00095 void *custom_data;
00097 fibril_mutex_t guard;
00099 bool signal_changes;
00100 };
00101
00102 void hub_init(hub_t *);
00103 size_t hub_connect_device(hub_t *, void *);
00104 int hub_disconnect_device(hub_t *, void *);
00105 size_t hub_find_device(hub_t *, void *);
00106 void hub_acquire(hub_t *);
00107 void hub_release(hub_t *);
00108 void hub_set_port_state(hub_t *, size_t, hub_port_state_t);
00109 void hub_set_port_state_all(hub_t *, hub_port_state_t);
00110 hub_port_state_t hub_get_port_state(hub_t *, size_t);
00111 void hub_clear_port_status_change(hub_t *, size_t, hub_status_change_t);
00112 uint16_t hub_get_port_status_change(hub_t *, size_t);
00113 uint32_t hub_get_port_status(hub_t *, size_t);
00114 uint8_t hub_get_status_change_bitmap(hub_t *);
00115
00116
00117 #endif
00118