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脚本操作
SQL 脚本创建数据库.表及简单查询 --------------------------------------------------------------------------------- ...
- 错误Batch update returned unexpected row count from update [0]; actual row count: 0;
参考:http://blog.csdn.net/ssyan/article/details/7471343 也是出现类似问题,在前台页面的隐藏域中判断id是否为null,而没有去判断是否为空字符串. ...
- AD Local Domain groups, Global groups and Universal groups
http://ss64.com/nt/syntax-groups.html Rules that govern when a group can be added to another group ( ...
- php进程占用大量cpu优化
使用TOP 命令发现php进程占用大量的cpu,达到100%,需要优化. 1 ll /proc/6264/fd 查看进程正在使用的资源 2 strace -p 6264 追踪进程正在做的事情 引用 h ...
- C#.NET中数组、ArrayList和List三者的区别
数组在C#.NET中是最早出现的,在内存中是顺序连续存储的,所以它的索引速度非常快,赋值与修改元素也很简单:但是,也正因为数组是顺序连续存储的,在两个数据间插入数据是很不方便的,而且在声明数组的时候必 ...
- JAVA(IO流)文件复制
package com.am; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOEx ...
- OpenGL中实现双缓冲技术
在OpenGL中实现双缓冲技术的一种简单方法: 1.在调用glutInitDisplayMode函数时, 开启GLUT_DOUBLE,即glutInitDisplayMode(GLUT_RGB | G ...
- magento事件(event)的dispatchEvent(分发)和catchEvent(获取)
当你需要扩展Magento的核心的功能时有两个选择: (1)重写(override)Magento的core classes (2)使用Magento的event-driven 机制 由于你只能重写一 ...
- Web测试的常用测试用例与知识
1. Web测试中关于登录的测试 2. 搜索功能测试用例设计 3. 翻页功能测试用例 4. 输入框的测试 5. Web测试的常用的检查点 6. 用户及权限管理功能常规测试方法 7. Web测试之兼容性 ...
- Win2008R2+java+tomcat安装
Win2008R2+java+tomcat安装 准备软件: jdk-7u25-windows-x64.exe apache-tomcat-7.0.42-windows-x64.zip 一.安装java ...