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(); //系统时 ...
随机推荐
- TranslateAnimation参数
看TranslateAnimation动画参数,一直忘记四个参数意思: public TranslateAnimation(float fromXDelta, float toXDelta, f ...
- 第6章 DOM节点操作
一.创建节点 为了使页面更加智能化,有时我们想动态的在 html 结构页面添加一个元素标签,那么 在插入之前首先要做的动作就是:创建节点. varbox=$('<div id="box ...
- 不断优化,重构我的代码-----拖拽jquery插件
最近学东西学的有点太散了,歇一阵子,重新完善之前的JQ插件,今天先上拖拽吧 // JavaScript Document (function($){ var defaults = { actionEl ...
- gdb
● 要用gdb调试,在ggc编译时,需要家参数-g: gcc -g test.c - test ● 设置断点: gdb test b 63 if i==10 63是断点坐在的行号,用list命令列举出 ...
- Myeclipse java程序中运行图片无法加载并且乱码
Windows---prefrence--workspace--text file encoding亲测有效
- javascript入门:prototype和面向对象的实现
由于工作需要,需要大量使用javascript,于是对其进行了一下学习. 学习任何一个语言,最重要的是掌握其和其他语言不同的关键特性.对javascript来说,我总结就是prototype.就像me ...
- Android NDK常见配置问题的解决方案
添加NDK包时出现"Not a valid NDK directory" 在解压的android-ndk-rxxx文件夹中新建一个txt文件,将名字包括后缀更改为ndk-build ...
- Linux从零单排(一):Google Chrome的安装
刚刚安装了Linux ubuntu16.10系统,先装上我一直习惯用的Google Chrome 安装步骤如下: 1.终端输入 sudo wget https://repo.fdzh.org/chro ...
- LeetCode Intersection of Two Arrays II
原题链接在这里:https://leetcode.com/problems/intersection-of-two-arrays-ii/ 题目: Given two arrays, write a f ...
- vim - buffer
1. buffer switching http://vim.wikia.com/wiki/Easier_buffer_switching :buffer:ls:files 2. vim defaul ...