drv_irq.c 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright (c) 2006-2022, RT-Thread Development Team
  3. * Copyright (c) 2022, Xiaohua Semiconductor Co., Ltd.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0
  6. *
  7. * Change Logs:
  8. * Date Author Notes
  9. * 2022-04-28 CDT first version
  10. */
  11. /*******************************************************************************
  12. * Include files
  13. ******************************************************************************/
  14. #include <rtthread.h>
  15. #include "drv_irq.h"
  16. /*******************************************************************************
  17. * Local type definitions ('typedef')
  18. ******************************************************************************/
  19. /*******************************************************************************
  20. * Local pre-processor symbols/macros ('#define')
  21. ******************************************************************************/
  22. /*******************************************************************************
  23. * Global variable definitions (declared in header file with 'extern')
  24. ******************************************************************************/
  25. /*******************************************************************************
  26. * Local function prototypes ('static')
  27. ******************************************************************************/
  28. /*******************************************************************************
  29. * Local variable definitions ('static')
  30. ******************************************************************************/
  31. /*******************************************************************************
  32. * Function implementation - global ('extern') and local ('static')
  33. ******************************************************************************/
  34. rt_err_t hc32_install_irq_handler(struct hc32_irq_config *irq_config,
  35. void (*irq_hdr)(void),
  36. rt_bool_t irq_enable)
  37. {
  38. rt_err_t result = -RT_ERROR;
  39. stc_irq_signin_config_t stcIrqSignConfig;
  40. RT_ASSERT(RT_NULL != irq_config);
  41. RT_ASSERT(RT_NULL != irq_hdr);
  42. stcIrqSignConfig.enIRQn = irq_config->irq_num;
  43. stcIrqSignConfig.enIntSrc = irq_config->int_src;
  44. stcIrqSignConfig.pfnCallback = irq_hdr;
  45. if (LL_OK == INTC_IrqSignIn(&stcIrqSignConfig))
  46. {
  47. NVIC_ClearPendingIRQ(stcIrqSignConfig.enIRQn);
  48. NVIC_SetPriority(stcIrqSignConfig.enIRQn, irq_config->irq_prio);
  49. if (RT_TRUE == irq_enable)
  50. {
  51. NVIC_EnableIRQ(stcIrqSignConfig.enIRQn);
  52. }
  53. else
  54. {
  55. NVIC_DisableIRQ(stcIrqSignConfig.enIRQn);
  56. }
  57. result = RT_EOK;
  58. }
  59. return result;
  60. }
  61. /*******************************************************************************
  62. * EOF (not truncated)
  63. ******************************************************************************/