os_except.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include "hal.h"
  2. #include "uart/uart.h"
  3. #include "osc/osc.h"
  4. #include "os_except.h"
  5. /*
  6. *********************************************************************************************************
  7. * Register Exception Handlers
  8. *
  9. * Description : This function is called to register general exception handler.
  10. * The total number of general exception is 16.
  11. *
  12. * Arguments : ipc
  13. *
  14. * Notes :
  15. *********************************************************************************************************
  16. */
  17. inline void register_exception_handler(int genneral_except_num, void (*handler)(unsigned int ipc))
  18. {
  19. if (genneral_except_num >= 16)
  20. {
  21. puts("Non-exist general exception number.\n");
  22. while (1);
  23. }
  24. General_Exception_Handler_Table[genneral_except_num] = handler;
  25. }
  26. /*
  27. *********************************************************************************************************
  28. * Exception Dispatcher
  29. *
  30. * Description : This function is called from exception handler to dispatch different
  31. * exception handler according to register itype.
  32. *
  33. * Arguments : ipc
  34. *
  35. * Notes :
  36. *********************************************************************************************************
  37. */
  38. void OS_CPU_EXCEPTION_Dispatcher(unsigned int ipc)
  39. {
  40. /* Interrupt is still disabled at this point */
  41. /* get all needed system registers' values before re-enable interrupt */
  42. unsigned int itype = __nds32__mfsr (NDS32_SR_ITYPE);
  43. unsigned int exception_num;
  44. void (*pHandler)(unsigned int ipc);
  45. exception_num = itype & 0xf;
  46. pHandler = General_Exception_Handler_Table[exception_num];
  47. pHandler(ipc);
  48. }