MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / rt_pic_attach_irq

Function rt_pic_attach_irq

components/drivers/pic/pic.c:361–417  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

359}
360
361rt_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

Callers 4

rt_hw_interrupt_installFunction · 0.85
serial8250_setupFunction · 0.85
rk_serial_debug_initFunction · 0.85
rk_timer_probeFunction · 0.85

Calls 8

irq2pirqFunction · 0.85
rt_list_initFunction · 0.85
rt_mallocFunction · 0.85
rt_list_insert_afterFunction · 0.85
rt_strncpyFunction · 0.85
rt_memsetFunction · 0.85
rt_spin_lock_irqsaveFunction · 0.50

Tested by

no test coverage detected