eBox(stm32) 之中断结构
eBox的中断结构参考了mbed,和我们平时所用的中断结构有些差异,不容易理解,最近仔细看了底层代码,终于搞清楚了,总结一下
// 绑定静态回调函数void attach(void(*fptr)(void)){pirq.attach(fptr);}FunctionPointer pirq;
typedefvoid(*exti_irq_handler)(uint32_t id);static exti_irq_handler irq_handler;staticuint32_t exti_irq_ids[16];
int exti_irq_init(uint8_t index,exti_irq_handler handler,uint32_t id){exti_irq_ids[index]= id;irq_handler = handler;return0;}
void IRQ::irq_handler(uint32_t id){IRQ *handler =(IRQ*)id;// 指向回调函数地址handler->pirq.call();// 调用回调函数}
exti_irq_init(13,(&IRQ::irq_handler),(uint32_t)this);
void EXTI4_15_IRQHandler(void){if(LL_EXTI_IsActiveFlag_0_31(LL_EXTI_LINE_13)!= RESET){LL_EXTI_ClearFlag_0_31(LL_EXTI_LINE_13);/* Manage code in main.c.*/irq_handler(exti_irq_ids[13]);}}
/** A class for storing and calling a pointer to a static or member function 用来保存静态或成员函数的指针类*/// R-返回值类型 A1-参数类型template<typename R,typename A1>classFunctionPointerArg1{public:/** Create a FunctionPointer, attaching a static function 创建函数指针** @param function The static function to attach (default is none) 附加静态函数,默认为void*/FunctionPointerArg1(R (*function)(A1)=0){attach(function);}/** Create a FunctionPointer, attaching a member function* 附加成员函数,object 成员函数的对象的指针。 成员函数* @param object The object pointer to invoke the member function on (i.e. the this pointer)* @param function The address of the member function to attach*/template<typename T>FunctionPointerArg1(T *object, R (T::*member)(A1)){attach(object, member);}/** Attach a static function* 附件静态函数* @param function The static function to attach (default is none)*/void attach(R (*function)(A1)){_p.function = function;_membercaller =0;}/** Attach a member function* 附件成员函数* @param object The object pointer to invoke the member function on (i.e. the this pointer)* @param function The address of the member function to attach*/template<typename T>void attach(T *object, R (T::*member)(A1)){_p.object =static_cast<void*>(object);// 将对象转换成void* 类型*reinterpret_cast<R (T::**)(A1)>(_member)= member;_membercaller =&FunctionPointerArg1::membercaller<T>;//注册成员函数地址}/** Call the attached static or member function*/R call(A1 a){if(_membercaller ==0&& _p.function){return _p.function(a);}elseif(_membercaller && _p.object){return _membercaller(_p.object, _member, a);}return(R)0;}/** Get registered static function*/R(*get_function(A1))(){return _membercaller ?(R(*)(A1))0:(R(*)(A1))_p.function;}#ifdef MBED_OPERATORSR operator()(A1 a){return call(a);}operatorbool(void)const{return(_membercaller != NULL ? _p.object :(void*)_p.function)!= NULL;}#endifprivate:template<typename T>//对象类型// 调用成员 对象,成员函数static R membercaller(void*object,uintptr_t*member, A1 a){T* o =static_cast<T*>(object);//类型转换R (T::**m)(A1)=reinterpret_cast<R (T::**)(A1)>(member);return(o->**m)(a);}union{R (*function)(A1);// static function pointer 静态函数指针void*object;// object this pointer 对象指针} _p;// 用联合体保存指针,静态函数或者对象,只能保存其中一种uintptr_t _member[4];// aligned raw member function pointer storage - converted back by registered _membercaller// 函数指针R (*_membercaller)(void*,uintptr_t*, A1);// registered membercaller function to convert back and call _m.member on _object};
eBox(stm32) 之中断结构的更多相关文章
- (二)stm32之中断配置
一.stm32的中断和异常 Cortex拥有强大的异常响应系统,它能够打断当前代码执行流程事件分为异常和中断,它们用一个表管理起来,编号为0~15为内核异常,16以上的为外部中断,这个表就是中断向量表 ...
- STM32外部中断具体解释
一.基本概念 ARM Coetex-M3内核共支持256个中断,当中16个内部中断,240个外部中断和可编程的256级中断优先级的设置.STM32眼下支持的中断共84个(16个内部+68个外部), ...
- stm32之中断配置
一.stm32的中断和异常 Cortex拥有强大的异常响应系统,它能够打断当前代码执行流程事件分为异常和中断,它们用一个表管理起来,编号为0~15为内核异常,16以上的为外部中断,这个表就是中断向量表 ...
- STM32的中断系统
STM32的中断系统 STM32具有十分强大的中断系统,将中断分为了两个类型:内核异常和外部中断.并将所有中断通过一个表编排起来,下面是stm32中断向量表的部分内容: 上图-3到6这个区域被标黑了, ...
- 转载:STM32之中断与事件---中断与事件的区别
这张图是一条外部中断线或外部事件线的示意图,图中信号线上划有一条斜线,旁边标志19字样的注释,表示这样的线路共有19套.图中的蓝色虚线箭头,标出了外部中断信号的传输路径,首先外部信号从编号1的芯片管脚 ...
- STM32之中断与事件---中断与事件的区别
STM32之中断与事件---中断与事件的区别 http://blog.csdn.net/flydream0/article/details/8208463 这张图是一条外部中断线或外部事件线的示意图 ...
- STM32外部中断初理解
PA0,PB0...PG0--->EXTI0 PA1,PB1...PG1--->EXTI1 ....... PA15,PB15...PG15--->EXTI15 以上为GPIO和中断 ...
- STM32之中断
在STM32(Cortex-M3)中没有显示的代码拷贝,只有启动代码进行了向量的初始化,一直以为是编译器在程序影像中自己完成了相关向量的拷贝,即,拷贝到固定的NVIC区,事实上并不是这样,cortex ...
- STM32串口中断实例二
int main(void) { uint8_t a=;//LED高低电压控制 /* System Clocks Configuration */ RCC_Configuration(); //系统时 ...
随机推荐
- SQL Server 存储过程
Transact-SQL中的存储过程,非常类似于Java语言中的方法,它可以重复调用.当存储过程执行一次后,可以将语句缓存中,这样下次执行的时候直接使用缓存中的语句.这样就可以提高存储过程的性能. Ø ...
- Web前端学习过程
推荐学习网站www.freecodecamp.cn http://www.w3school.com.cn/ 步骤: 作者:张帅 知乎链接:https://www.zhihu.com/question/ ...
- HDU5769 Substring(后缀数组)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=5769 #include <iostream> #include <stdio.h> ...
- O(n) 筛法求素数
var tot,i,j,k,m,n:longint; prime:array[0..100000] of boolean; p:array[0..100000] of longint;begin re ...
- OpenGL中实现双缓冲技术
在OpenGL中实现双缓冲技术的一种简单方法: 1.在调用glutInitDisplayMode函数时, 开启GLUT_DOUBLE,即glutInitDisplayMode(GLUT_RGB | G ...
- erlang调试之JCL
Job control mode (JCL), in which jobs can be started, stopped, detached or connected. Only the curre ...
- Spark java.lang.outofmemoryerror gc overhead limit exceeded 与 spark OOM:java heap space 解决方法
引用自:http://cache.baiducontent.com/c?m=9f65cb4a8c8507ed4fece7631046893b4c4380146d96864968d4e414c42246 ...
- Spark1.6.2 java实现读取json数据文件插入MySql数据库
public class Main implements Serializable { /** * */ private static final long serialVersionUID = -8 ...
- cloudera learning2:HDFS
存入HDFS的文件会按块(block)划分,默认每块128MB.默认1个block还有2个备份.备份增加了数据的可靠性和提高计算效率(数据本地化). HDFS部署可选择不支持HA,也可选择支持HA. ...
- busybox rootfs 启动脚本分析(二)
上次分析了busybox的启动脚本,这次分析一下init.d中一些脚本的内容. 参考链接 http://www.cnblogs.com/helloworldtoyou/p/6169678.html h ...