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(); //系统时 ...
随机推荐
- ZeroMQ接口函数之 :zmq - 0MQ 轻量级消息传输内核
官方网址:http://api.zeromq.org/4-0:zmq zmq(7) 0MQ Manual - 0MQ/3.2.5 Name zmq – ØMQ 轻量级消息传输内核 Synopsis # ...
- 使用BigDecimal进行精确运算以及格式化输出数字
一.引言 借用<Effactive Java>这本书中的话,float和double类型的主要设计目标是为了科学计算和工程计算.他们执行二进制浮点运算,这是为了在广域数值范围上提供 ...
- php 跨服务器ftp移动文件
$ftp_server = "120.25.1.1";$ftp_user_name = "p1111";$ftp_user_pass = "psa12 ...
- js--敏感词屏蔽
<!doctype html><html><head><meta charset="utf-8"><meta name=&qu ...
- 《Linux内核设计与实现》读书笔记 第一、二章
第一章 Linux内核简介 1.1Unix历史 Unix特点:1.很简洁 2.所有东西都被当成文件对待 3.Unix内核和相关的系统工具软件都是用C语言编写而成 4.进程创建非常迅速 所以Uni ...
- 【emWin】例程八:绘制位图
实验指导书及代码包下载: 链接:http://pan.baidu.com/s/1bpeMYpp 密码:wgtp 实验现象:
- JS学习总结(新手)
1. JS面向对象 http://www.cnblogs.com/JavascriptDream/p/5064976.html a. Prototype 属性的理解 b. 遗传继承函数 functio ...
- PCB上过孔via钻孔的直径如何设置 是任意的吗 谈谈PCB钻孔工艺及规格
PCB上过孔via钻孔的直径如何设置,是不是可以随便填入一个直径尺寸就行了?比如我的走线宽度是6mil,那我的via过孔直径也设置为6mil,节约布线空间岂不是更好?这样的设计板厂是否都能按照设计规格 ...
- js 相关知识整理(一)
真正声明变量,是用逗号隔开的 EcM5:严格模式“use strict” java与js 语言的区别: 1.弱类型语言 1.声明变量时不需要提前指定数据类型 2.同一个变量可先后保存不同类型的数据 3 ...
- Ueditor百度网页编辑器开发者版java utf-8的使用
index.jsp主要代码: <html> <head> <title>网页编辑器</title> <script type="text ...