drv_irq.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright (C) 2022-2024, Xiaohua Semiconductor Co., Ltd.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2022-04-28 CDT first version
  9. * 2024-06-07 CDT Modify the IRQ install implementation for F448/F472
  10. * 2025-07-16 CDT Support HC32F334
  11. */
  12. /*******************************************************************************
  13. * Include files
  14. ******************************************************************************/
  15. #include <rtthread.h>
  16. #include "drv_irq.h"
  17. /*******************************************************************************
  18. * Local type definitions ('typedef')
  19. ******************************************************************************/
  20. /*******************************************************************************
  21. * Local pre-processor symbols/macros ('#define')
  22. ******************************************************************************/
  23. #if defined (HC32F448) || defined (HC32F472) || defined (HC32F334)
  24. /* Interrupt registration max number */
  25. #define HC32_INT_REG_MAX_NUM (16U)
  26. #endif
  27. /*******************************************************************************
  28. * Global variable definitions (declared in header file with 'extern')
  29. ******************************************************************************/
  30. /*******************************************************************************
  31. * Local function prototypes ('static')
  32. ******************************************************************************/
  33. /*******************************************************************************
  34. * Local variable definitions ('static')
  35. ******************************************************************************/
  36. /*******************************************************************************
  37. * Function implementation - global ('extern') and local ('static')
  38. ******************************************************************************/
  39. rt_err_t hc32_install_irq_handler(struct hc32_irq_config *irq_config,
  40. void (*irq_hdr)(void),
  41. rt_bool_t irq_enable)
  42. {
  43. rt_err_t result = -RT_ERROR;
  44. stc_irq_signin_config_t stcIrqSignConfig;
  45. RT_ASSERT(RT_NULL != irq_config);
  46. #if defined (HC32F448) || defined (HC32F472) || defined (HC32F334)
  47. if (irq_config->irq_num < HC32_INT_REG_MAX_NUM)
  48. {
  49. RT_ASSERT(RT_NULL != irq_hdr);
  50. INTC_IntSrcCmd(irq_config->int_src, DISABLE);
  51. }
  52. else
  53. {
  54. INTC_IntSrcCmd(irq_config->int_src, ENABLE);
  55. goto nvic_config;
  56. }
  57. stcIrqSignConfig.enIRQn = irq_config->irq_num;
  58. stcIrqSignConfig.enIntSrc = irq_config->int_src;
  59. stcIrqSignConfig.pfnCallback = irq_hdr;
  60. if (LL_OK == INTC_IrqSignIn(&stcIrqSignConfig))
  61. #elif defined (HC32F460) || defined (HC32F4A0) || defined (HC32F4A8)
  62. stcIrqSignConfig.enIRQn = irq_config->irq_num;
  63. stcIrqSignConfig.enIntSrc = irq_config->int_src;
  64. stcIrqSignConfig.pfnCallback = irq_hdr;
  65. if (LL_OK == INTC_IrqSignIn(&stcIrqSignConfig))
  66. #endif
  67. nvic_config:
  68. {
  69. NVIC_ClearPendingIRQ(irq_config->irq_num);
  70. NVIC_SetPriority(irq_config->irq_num, irq_config->irq_prio);
  71. if (RT_TRUE == irq_enable)
  72. {
  73. NVIC_EnableIRQ(irq_config->irq_num);
  74. }
  75. else
  76. {
  77. NVIC_DisableIRQ(irq_config->irq_num);
  78. }
  79. result = RT_EOK;
  80. }
  81. return result;
  82. }
  83. /*******************************************************************************
  84. * EOF (not truncated)
  85. ******************************************************************************/