Changeset cfe7716 in mainline
- Timestamp:
- 2010-04-29T14:13:28Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7f8b581
- Parents:
- 953bc1ef
- Location:
- uspace
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/libc/generic/ddi.c
r953bc1ef rcfe7716 105 105 } 106 106 107 /** Enable /disableinterrupt.107 /** Enable an interrupt. 108 108 * 109 109 * @param irq the interrupt. 110 * @param enable 1 - enable interrupt, 0 - disable interrupt.111 110 * 112 111 * @return Zero on success, negative error code otherwise. 113 112 */ 114 int interrupt_enable(int irq , int enable)113 int interrupt_enable(int irq) 115 114 { 116 return __SYSCALL2(SYS_INTERRUPT_ENABLE, (sysarg_t) irq, (sysarg_t) enable); 115 return __SYSCALL2(SYS_INTERRUPT_ENABLE, (sysarg_t) irq, 1); 116 } 117 118 /** Disable an interrupt. 119 * 120 * @param irq the interrupt. 121 * 122 * @return Zero on success, negative error code otherwise. 123 */ 124 int interrupt_disable(int irq) 125 { 126 return __SYSCALL2(SYS_INTERRUPT_ENABLE, (sysarg_t) irq, 0); 117 127 } 118 128 -
uspace/lib/libc/include/ddi.h
r953bc1ef rcfe7716 43 43 extern int preemption_control(int); 44 44 extern int pio_enable(void *, size_t, void **); 45 extern int interrupt_enable(int, int); 45 extern int interrupt_enable(int); 46 extern int interrupt_disable(int); 46 47 47 48 #endif -
uspace/lib/libdrv/include/driver.h
r953bc1ef rcfe7716 41 41 #include <device/hw_res.h> 42 42 #include <assert.h> 43 #include <ddi.h> 44 #include <libarch/ddi.h> 45 #include <fibril_synch.h> 46 #include <malloc.h> 43 47 44 48 struct device; … … 159 163 int child_device_register(device_t *child, device_t *parent); 160 164 165 // interrupts 166 167 static irq_cmd_t default_cmds[] = { 168 { 169 .cmd = CMD_ACCEPT 170 } 171 }; 172 173 static irq_code_t default_pseudocode = { 174 sizeof(default_cmds) / sizeof(irq_cmd_t), 175 default_cmds 176 }; 177 178 typedef void interrupt_handler_t(device_t *dev, ipc_callid_t iid, ipc_call_t *icall); 179 180 typedef struct interrupt_context { 181 int id; 182 device_t *dev; 183 int irq; 184 interrupt_handler_t *handler; 185 link_t link; 186 } interrupt_context_t; 187 188 typedef struct interrupt_context_list { 189 int curr_id; 190 link_t contexts; 191 fibril_mutex_t mutex; 192 } interrupt_context_list_t; 193 194 static inline interrupt_context_t * create_interrupt_context() 195 { 196 interrupt_context_t *ctx = (interrupt_context_t *)malloc(sizeof(interrupt_context_t)); 197 if (NULL != ctx) { 198 memset(ctx, 0, sizeof(interrupt_context_t)); 199 } 200 return ctx; 201 } 202 203 static inline void delete_interrupt_context(interrupt_context_t *ctx) 204 { 205 if (NULL != ctx) { 206 free(ctx); 207 } 208 } 209 210 static inline void init_interrupt_context_list(interrupt_context_list_t *list) 211 { 212 memset(list, 0, sizeof(interrupt_context_list_t)); 213 fibril_mutex_initialize(&list->mutex); 214 list_initialize(&list->contexts); 215 } 216 217 static inline void add_interrupt_context(interrupt_context_list_t *list, interrupt_context_t *ctx) 218 { 219 fibril_mutex_lock(&list->mutex); 220 221 ctx->id = list->curr_id++; 222 list_append(&ctx->link, &list->contexts); 223 224 fibril_mutex_unlock(&list->mutex); 225 } 226 227 static inline void remove_interrupt_context(interrupt_context_list_t *list, interrupt_context_t *ctx) 228 { 229 fibril_mutex_lock(&list->mutex); 230 231 list_remove(&ctx->link); 232 233 fibril_mutex_unlock(&list->mutex); 234 } 235 236 static inline interrupt_context_t *find_interrupt_context_by_id(interrupt_context_list_t *list, int id) 237 { 238 fibril_mutex_lock(&list->mutex); 239 link_t *link = list->contexts.next; 240 interrupt_context_t *ctx; 241 242 while (link != &list->contexts) { 243 ctx = list_get_instance(link, interrupt_context_t, link); 244 if (id == ctx->id) { 245 fibril_mutex_unlock(&list->mutex); 246 return ctx; 247 } 248 link = link->next; 249 } 250 fibril_mutex_unlock(&list->mutex); 251 return NULL; 252 } 253 254 static inline interrupt_context_t *find_interrupt_context(interrupt_context_list_t *list, device_t *dev, int irq) 255 { 256 fibril_mutex_lock(&list->mutex); 257 link_t *link = list->contexts.next; 258 interrupt_context_t *ctx; 259 260 while (link != &list->contexts) { 261 ctx = list_get_instance(link, interrupt_context_t, link); 262 if (irq == ctx->irq && dev == ctx->dev) { 263 fibril_mutex_unlock(&list->mutex); 264 return ctx; 265 } 266 link = link->next; 267 } 268 fibril_mutex_unlock(&list->mutex); 269 return NULL; 270 } 161 271 162 272 #endif -
uspace/srv/drivers/serial/serial.c
r953bc1ef rcfe7716 238 238 } 239 239 240 static int serial_interrupt_enable(device_t *dev) 241 { 242 serial_dev_data_t *data = (serial_dev_data_t *)dev->driver_data; 243 244 // enable interrupt globally 245 enable_interrupt(data->irq); 246 247 // enable interrupt on the serial port 248 pio_write_8(data->port + 1 , 0x01); // Interrupt when data received 249 pio_write_8(data->port + 4, 0x0B); 250 251 return EOK; 252 } 253 254 static void serial_initialize_port(device_t *dev) 255 { 256 serial_dev_data_t *data = (serial_dev_data_t *)dev->driver_data; 257 ioport8_t *port = data->port; 258 259 pio_write_8(port + 1, 0x00); // Disable all interrupts 260 pio_write_8(port + 3, 0x80); // Enable DLAB (set baud rate divisor) 261 pio_write_8(port + 0, 0x60); // Set divisor to 96 (lo byte) 1200 baud 262 pio_write_8(port + 1, 0x00); // (hi byte) 263 pio_write_8(port + 3, 0x07); // 8 bits, no parity, two stop bits 264 pio_write_8(port + 2, 0xC7); // Enable FIFO, clear them, with 14-byte threshold 265 pio_write_8(port + 4, 0x0B); // RTS/DSR set (Request to Send and Data Terminal Ready lines enabled), 266 // Aux Output2 set - needed for interrupts 267 } 268 240 269 static int serial_add_device(device_t *dev) 241 270 { … … 250 279 serial_dev_cleanup(dev); 251 280 return EADDRNOTAVAIL; 252 } 253 254 281 } 282 283 // find out whether the device is present 255 284 if (!serial_dev_probe(dev)) { 256 285 serial_dev_cleanup(dev); … … 258 287 } 259 288 260 // TODO interrupt and serial port initialization (baud rate etc.) 289 // serial port initialization (baud rate etc.) 290 serial_initialize_port(dev); 291 292 // TODO register interrupt handler 293 294 // enable interrupt 295 if (0 != (res = serial_interrupt_enable(dev))) { 296 serial_dev_cleanup(dev); 297 return res; 298 } 261 299 262 300 return EOK;
Note:
See TracChangeset
for help on using the changeset viewer.