野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8026|回复: 3

SDK中的函数InstallIRQHandler怎么使用?

[复制链接]
发表于 2018-6-2 15:49:00 | 显示全部楼层 |阅读模式
在官方SDK中的fsl_common.c文件中发现如下函数,这个跟我们需要把中断向量表拷贝到内部RAM是差不多原理,有人知道怎么使用吗?

  1. #ifndef __GIC_PRIO_BITS
  2. #if defined(ENABLE_RAM_VECTOR_TABLE)
  3. uint32_t InstallIRQHandler(IRQn_Type irq, uint32_t irqHandler)
  4. {
  5. /* Addresses for VECTOR_TABLE and VECTOR_RAM come from the linker file */
  6. #if defined(__CC_ARM)
  7. extern uint32_t Image$VECTOR_ROM$Base[];
  8. extern uint32_t Image$VECTOR_RAM$Base[];
  9. extern uint32_t Image$RW_m_data$Base[];

  10. #define __VECTOR_TABLE Image$VECTOR_ROM$Base
  11. #define __VECTOR_RAM Image$VECTOR_RAM$Base
  12. #define __RAM_VECTOR_TABLE_SIZE (((uint32_t)Image$RW_m_data$Base - (uint32_t)Image$VECTOR_RAM$Base))
  13. #elif defined(__ICCARM__)
  14. extern uint32_t __RAM_VECTOR_TABLE_SIZE[];
  15. extern uint32_t __VECTOR_TABLE[];
  16. extern uint32_t __VECTOR_RAM[];
  17. #elif defined(__GNUC__)
  18. extern uint32_t __VECTOR_TABLE[];
  19. extern uint32_t __VECTOR_RAM[];
  20. extern uint32_t __RAM_VECTOR_TABLE_SIZE_BYTES[];
  21. uint32_t __RAM_VECTOR_TABLE_SIZE = (uint32_t)(__RAM_VECTOR_TABLE_SIZE_BYTES);
  22. #endif /* defined(__CC_ARM) */
  23. uint32_t n;
  24. uint32_t ret;
  25. uint32_t irqMaskValue;

  26. irqMaskValue = DisableGlobalIRQ();
  27. if (SCB->VTOR != (uint32_t)__VECTOR_RAM)
  28. {
  29. /* Copy the vector table from ROM to RAM */
  30. for (n = 0; n < ((uint32_t)__RAM_VECTOR_TABLE_SIZE) / sizeof(uint32_t); n++)
  31. {
  32. __VECTOR_RAM[n] = __VECTOR_TABLE[n];
  33. }
  34. /* Point the VTOR to the position of vector table */
  35. SCB->VTOR = (uint32_t)__VECTOR_RAM;
  36. }

  37. ret = __VECTOR_RAM[irq + 16];
  38. /* make sure the __VECTOR_RAM is noncachable */
  39. __VECTOR_RAM[irq + 16] = irqHandler;

  40. EnableGlobalIRQ(irqMaskValue);

  41. /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
  42. exception return operation might vector to incorrect interrupt */
  43. #if defined __CORTEX_M && (__CORTEX_M == 4U)
  44. __DSB();
  45. #endif

  46. return ret;
  47. }
  48. #endif /* ENABLE_RAM_VECTOR_TABLE. */
  49. #endif /* __GIC_PRIO_BITS. */
复制代码


回复

使用道具 举报

发表于 2018-6-4 08:54:40 | 显示全部楼层
好高深,帮顶
回复 支持 反对

使用道具 举报

发表于 2018-6-4 08:54:55 | 显示全部楼层
wow,好长的代码。。。。。。钻也帮顶
回复 支持 反对

使用道具 举报

发表于 2018-6-4 16:54:38 | 显示全部楼层

就是直接用这个涵数更新新的中断涵数,它会先把中断项量表复制到ram
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

联系站长|手机版|野火电子官网|野火淘宝店铺|野火电子论坛 ( 粤ICP备14069197号 ) 大学生ARM嵌入式2群

GMT+8, 2024-5-5 00:54 , Processed in 0.029169 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表