Fix the issue about RTEMS-libbsd interrupt install failed

RTEMS-libbsd use RTEMS as kernel, and libbsd as a library.

But when i use the interrupt in RTEMS-libbsd, For some bsp, there will be an situation about interrupt can not used.

For example, When I transplant USB driver for the beaglebone black , we need to install usb interrupt(interrupt vector 0x18, 0x19). But the program stuck at the interrupt install function, That is _Terminate.

What's more, my GSOC mentor Christian Mauderer meet the same problem when he used the ATSAM v71 bsp.

Through gdb for debug, gdb output information:

  1. (gdb) c  
  2. Continuing.  
  3. Breakpoint 3, _Terminate (the_source=the_source@entry=RTEMS_FATAL_SOURCE_BSP, the_error=the_error@entry=0) at /home/christian/rtems/rtems-sichenzhao/build/..//rtems/c/src/../../cpukit/score/src/interr.c:34  
  4. 34      {  
  5. (gdb) bt  
  6. #0  _Terminate (the_source=the_source@entry=RTEMS_FATAL_SOURCE_BSP, the_error=the_error@entry=0) at /home/christian/rtems/rtems-sichenzhao/build/..//rtems/c/src/../../cpukit/score/src/interr.c:34  
  7. #1  0x800a71c4 in rtems_fatal (error_code=0, fatal_source=RTEMS_FATAL_SOURCE_BSP) at ../../../../../.././beagleboneblack/lib/include/rtems/fatal.h:88  
  8. #2  bsp_fatal (code=BSP_FATAL_INTERRUPT_INITIALIZATION) at ../../../../../.././beagleboneblack/lib/include/bsp/fatal.h:142  
  9. #3  omap_get_mir_reg (vector=<optimized out>, mask=<optimized out>) at /home/christian/rtems/rtems-sichenzhao/build/..//rtems/c/src/lib/libbsp/arm/beagle/irq.c:92  
  10. #4  0x800a7270 in bsp_interrupt_vector_disable (vector=<optimized out>) at /home/christian/rtems/rtems-sichenzhao/build/..//rtems/c/src/lib/libbsp/arm/beagle/irq.c:113  
  11. #5  0x800a7344 in bsp_interrupt_server_trigger (arg=0x8032b488, arg@entry=0x8032b480) at /home/christian/rtems/rtems-sichenzhao/build/..//rtems/c/src/lib/libbsp/arm/beagle/../../shared/src/irq-server.c:59  
  12. #6  0x800a7584 in bsp_interrupt_server_call_helper (vector=vector@entry=18, options=options@entry=0, handler=<optimized out>, arg=arg@entry=0x800369b8 <nexus_setup_intr+148>, helper=0x800a73b0 <bsp_interrupt_server_install_helper>)  
  13.     at /home/christian/rtems/rtems-sichenzhao/build/..//rtems/c/src/lib/libbsp/arm/beagle/../../shared/src/irq-server.c:276  
  14. #7  0x800a7678 in rtems_interrupt_server_handler_install (server=server@entry=0, vector=vector@entry=18, info=<optimized out>, options=options@entry=0, handler=0x800a73b0 <bsp_interrupt_server_install_helper>,   
  15.     handler@entry=0x80000898 <musbotg_wrapper_interrupt>, arg=arg@entry=0x80396a90) at /home/christian/rtems/rtems-sichenzhao/build/..//rtems/c/src/lib/libbsp/arm/beagle/../../shared/src/irq-server.c:352  
  16. #8  0x800369b8 in nexus_setup_intr (dev=dev@entry=0x803951a8, child=child@entry=0x803954f8, res=res@entry=0x803982b0, flags=flags@entry=514, filt=filt@entry=0x0, intr=intr@entry=0x80000898 <musbotg_wrapper_interrupt>, arg=0x80396a90,   
  17.     arg@entry=0x80000bac <musbotg_attach+444>, cookiep=0x8039709c, cookiep@entry=0x80000898 <musbotg_wrapper_interrupt>) at ../../rtemsbsd/rtems/rtems-kernel-nexus.c:307  
  18. #9  0x800208dc in BUS_SETUP_INTR (_cookiep=0x80000898 <musbotg_wrapper_interrupt>, _arg=0x80000bac <musbotg_attach+444>, _intr=0x80000898 <musbotg_wrapper_interrupt>, _filter=0x0, _flags=514, _irq=0x803982b0, _child=0x803954f8,   
  19.     _dev=0x803951a8) at ../../rtemsbsd/include/rtems/bsd/local/bus_if.h:529  
  20. #10 _bsd_bus_setup_intr (dev=dev@entry=0x803954f8, r=0x803982b0, flags=flags@entry=514, filter=filter@entry=0x0, handler=handler@entry=0x80000898 <musbotg_wrapper_interrupt>, arg=arg@entry=0x80396a90, cookiep=cookiep@entry=0x8039709c)  
  21.     at ../../freebsd/sys/kern/subr_bus.c:4584  
  22. #11 0x80000bac in musbotg_attach (dev=0x803954f8) at ../../freebsd/sys/arm/ti/am335x/am335x_musb.c:304  
  23. #12 0x8001f07c in DEVICE_ATTACH (dev=0x803954f8) at ../../rtemsbsd/include/rtems/bsd/local/device_if.h:180  
  24. #13 _bsd_device_attach (dev=dev@entry=0x803954f8) at ../../freebsd/sys/kern/subr_bus.c:2947  
  25. #14 0x8001ff44 in _bsd_device_probe_and_attach (dev=dev@entry=0x803954f8) at ../../freebsd/sys/kern/subr_bus.c:2903  
  26. #15 0x8001fff0 in _bsd_bus_generic_attach (dev=<optimized out>) at ../../freebsd/sys/kern/subr_bus.c:3714  
  27. #16 0x8001f07c in DEVICE_ATTACH (dev=0x803951a8) at ../../rtemsbsd/include/rtems/bsd/local/device_if.h:180  
  28. #17 _bsd_device_attach (dev=dev@entry=0x803951a8) at ../../freebsd/sys/kern/subr_bus.c:2947  
  29. #18 0x8001ff44 in _bsd_device_probe_and_attach (dev=dev@entry=0x803951a8) at ../../freebsd/sys/kern/subr_bus.c:2903  
  30. #19 0x800203e8 in _bsd_bus_generic_new_pass (dev=0x80392950) at ../../freebsd/sys/kern/subr_bus.c:4000  
  31. #20 0x8001eca8 in BUS_NEW_PASS (_dev=0x80392950) at ../../rtemsbsd/include/rtems/bsd/local/bus_if.h:939  
  32. #21 _bsd_bus_set_pass (pass=2147483647) at ../../freebsd/sys/kern/subr_bus.c:987  
  33. #22 0x8003e2fc in _bsd_mi_startup () at ../../freebsd/sys/kern/init_main.c:306  
  34. #23 0x80036228 in rtems_bsd_initialize () at ../../rtemsbsd/rtems/rtems-kernel-init.c:158  
  35. #24 0x800005e4 in Init (arg=<optimized out>) at ../../testsuite/usb01/init.c:110  
  36. #25 0x800ccfcc in _Thread_Handler () at /home/christian/rtems/rtems-sichenzhao/build/..//rtems/c/src/../../cpukit/score/src/threadhandler.c:88  
  37. #26 0x800b9cb0 in _Thread_Life_action_handler (executing=0x0, action=<optimized out>, lock_context=0x0) at /home/christian/rtems/rtems-sichenzhao/build/..//rtems/c/src/../../cpukit/score/src/threadrestart.c:379  
  38. #27 0x00000000 in ?? ()  
  39. Backtrace stopped: previous frame identical to this frame (corrupt stack?)  
  40. (gdb)   


  1. (gdb) up  
  2. #3  omap_get_mir_reg (vector=<optimized out>, mask=<optimized out>) at /home/christian/rtems/rtems-sichenzhao/build/..//rtems/c/src/lib/libbsp/arm/beagle/irq.c:92  
  3. 92          bsp_fatal(0);  
  4. (gdb) list  
  5. 87          mir_reg = OMAP3_INTCPS_MIR2;  
  6. 88        } else if (vector < 128u) {  
  7. 89          mir_reg = OMAP3_INTCPS_MIR3;  
  8. 90        } else {  
  9. 91          /* Invalid IRQ number. This should never happen. */  
  10. 92          bsp_fatal(0);  
  11. 93        }  
  12. 94  
  13. 95        return mir_reg;  
  14. 96      }  
  15. (gdb)   



We can see that the code is terminated in bsp_fatal (), which is in the rtems source beagle's irq.c file

So , it seems that the reason for the problem is obvious:

128 is a pseudo vector that is used for the interrupt server on this target. But during install of the vector, the `bsp_interrupt_vector_disable` is called. this function doesn't know about the pseudo-IRQ number that is used for the interrupt server. Therefore it would try to disable it in the hardware. 
And the hardware doesn't have that much interrupts.

And Christian Mauderer has create a patch to solve the ATSAM v71 irq:


I use this as a reference: 
In the rtems source beagle bsp folder, the irq.c file, bsp_interrupt_vector_disable and bsp_interrupt_vector_enable function, i add a judge, if the interrupt vector is valid, then the processing

The patch i create for Beaglebone Black is:


The patch reads as follows:


  1. Enable/disable vector routines now check for a valid vector.  
  2. Without these guards, the enable/disable vector routines  
  3. will not work with the interrupt server.  
  4. ---  
  5.  c/src/lib/libbsp/arm/beagle/irq.c | 22 ++++++++++++++--------  
  6.  1 file changed, 14 insertions(+), 8 deletions(-)  
  7.   
  8. diff --git a/c/src/lib/libbsp/arm/beagle/irq.c b/c/src/lib/libbsp/arm/beagle/irq.c  
  9. index d080a5e..35750ba 100644  
  10. --- a/c/src/lib/libbsp/arm/beagle/irq.c  
  11. +++ b/c/src/lib/libbsp/arm/beagle/irq.c  
  12. @@ -98,11 +98,14 @@ static uint32_t omap_get_mir_reg(rtems_vector_number vector, uint32_t *const mas  
  13.  rtems_status_code bsp_interrupt_vector_enable(rtems_vector_number vector)  
  14.  {  
  15.    uint32_t mask, cur;  
  16. -  uint32_t mir_reg = omap_get_mir_reg(vector, &mask);  
  17.    
  18. -  cur = mmio_read(omap_intr.base + mir_reg);  
  19. -  mmio_write(omap_intr.base + mir_reg, cur & ~mask);  
  20. -  flush_data_cache();  
  21. +  if (bsp_interrupt_is_valid_vector(vector)) {  
  22. +    uint32_t mir_reg = omap_get_mir_reg(vector, &mask);  
  23. +  
  24. +    cur = mmio_read(omap_intr.base + mir_reg);  
  25. +    mmio_write(omap_intr.base + mir_reg, cur & ~mask);  
  26. +    flush_data_cache();  
  27. +  }  
  28.    
  29.    return RTEMS_SUCCESSFUL;  
  30.  }  
  31. @@ -110,11 +113,14 @@ rtems_status_code bsp_interrupt_vector_enable(rtems_vector_number vector)  
  32.  rtems_status_code bsp_interrupt_vector_disable(rtems_vector_number vector)  
  33.  {  
  34.    uint32_t mask, cur;  
  35. -  uint32_t mir_reg = omap_get_mir_reg(vector, &mask);  
  36.    
  37. -  cur = mmio_read(omap_intr.base + mir_reg);  
  38. -  mmio_write(omap_intr.base + mir_reg, cur | mask);  
  39. -  flush_data_cache();  
  40. +  if (bsp_interrupt_is_valid_vector(vector)) {  
  41. +    uint32_t mir_reg = omap_get_mir_reg(vector, &mask);  
  42. +  
  43. +    cur = mmio_read(omap_intr.base + mir_reg);  
  44. +    mmio_write(omap_intr.base + mir_reg, cur | mask);  
  45. +    flush_data_cache();  
  46. +  }  
  47.    
  48.    return RTEMS_SUCCESSFUL;  
  49.  }  
  50. --   
  51. 2.7.4  

评论

此博客中的热门博文

How to generate image file and dd to SD card

Developed the I2C driver for Beaglebone Black BSP

Compiling RTEMS for Beaglebone Black BSP