| 359 | } |
| 360 | |
| 361 | rt_err_t rt_pic_attach_irq(int irq, rt_isr_handler_t handler, void *uid, const char *name, int flags) |
| 362 | { |
| 363 | rt_err_t err = -RT_EINVAL; |
| 364 | struct rt_pic_irq *pirq; |
| 365 | |
| 366 | if (handler && name && (pirq = irq2pirq(irq))) |
| 367 | { |
| 368 | struct rt_pic_isr *isr = RT_NULL; |
| 369 | rt_ubase_t level = rt_spin_lock_irqsave(&pirq->rw_lock); |
| 370 | |
| 371 | err = RT_EOK; |
| 372 | |
| 373 | if (!pirq->isr.action.handler) |
| 374 | { |
| 375 | /* first attach */ |
| 376 | isr = &pirq->isr; |
| 377 | rt_list_init(&isr->list); |
| 378 | } |
| 379 | else |
| 380 | { |
| 381 | rt_spin_unlock_irqrestore(&pirq->rw_lock, level); |
| 382 | |
| 383 | if ((isr = rt_malloc(sizeof(*isr)))) |
| 384 | { |
| 385 | rt_list_init(&isr->list); |
| 386 | |
| 387 | level = rt_spin_lock_irqsave(&pirq->rw_lock); |
| 388 | |
| 389 | rt_list_insert_after(&pirq->isr.list, &isr->list); |
| 390 | } |
| 391 | else |
| 392 | { |
| 393 | LOG_E("No memory to save '%s' isr", name); |
| 394 | err = -RT_ERROR; |
| 395 | } |
| 396 | } |
| 397 | |
| 398 | if (!err) |
| 399 | { |
| 400 | isr->flags = flags; |
| 401 | isr->action.handler = handler; |
| 402 | isr->action.param = uid; |
| 403 | #ifdef RT_USING_INTERRUPT_INFO |
| 404 | isr->action.counter = 0; |
| 405 | rt_strncpy(isr->action.name, name, RT_NAME_MAX - 1); |
| 406 | isr->action.name[RT_NAME_MAX - 1] = '\0'; |
| 407 | #ifdef RT_USING_SMP |
| 408 | rt_memset(isr->action.cpu_counter, 0, sizeof(isr->action.cpu_counter)); |
| 409 | #endif |
| 410 | #endif |
| 411 | |
| 412 | rt_spin_unlock_irqrestore(&pirq->rw_lock, level); |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | return err; |
| 417 | } |
| 418 |
no test coverage detected