修正InputPort拆分不完整的问题

仍然没有解决串口无法输出的问题,通过代码回滚确认是11175版本的Port拆分所致
This commit is contained in:
Stone 2016-06-15 04:59:47 +00:00
parent bcb3a68ce1
commit 1ed7d93ed9
3 changed files with 60 additions and 70 deletions

View File

@ -311,27 +311,6 @@ void AlternatePort::OnOpen(void* param)
// 输入端口 // 输入端口
#define REGION_Input 1 #define REGION_Input 1
#ifdef REGION_Input #ifdef REGION_Input
/* 中断状态结构体 */
/* 一共16条中断线意味着同一条线每一组只能有一个引脚使用中断 */
typedef struct TIntState
{
InputPort* Port;
} IntState;
// 16条中断线
static IntState States[16];
static bool hasInitState = false;
int Bits2Index(ushort value)
{
for(int i=0; i<16; i++)
{
if(value & 0x01) return i;
value >>= 1;
}
return -1;
}
InputPort::InputPort() : InputPort(P0) { } InputPort::InputPort() : InputPort(P0) { }
InputPort::InputPort(Pin pin, bool floating, PuPd pull) : Port() InputPort::InputPort(Pin pin, bool floating, PuPd pull) : Port()
@ -500,15 +479,7 @@ void InputPort::OnClose()
{ {
Port::OnClose(); Port::OnClose();
int idx = Bits2Index(Mask); ClosePin();
auto st = &States[idx];
if(st->Port == this)
{
st->Port = nullptr;
ClosePin();
}
} }
// 注册回调 及中断使能 // 注册回调 及中断使能
@ -519,34 +490,7 @@ bool InputPort::Register(IOReadHandler handler, void* param)
Handler = handler; Handler = handler;
Param = param; Param = param;
// 检查并初始化中断线数组 if(!OnRegister()) return false;
if(!hasInitState)
{
for(int i=0; i<16; i++)
{
States[i].Port = nullptr;
}
hasInitState = true;
}
int idx = Bits2Index(Mask);
auto st = &States[idx];
auto port = st->Port;
// 检查是否已经注册到别的引脚上
if(port != this && port != nullptr)
{
#if DEBUG
byte gi = _Pin >> 4;
debug_printf("中断线EXTI%d 不能注册到 P%c%d, 它已经注册到 P%c%d\r\n", gi, _PIN_NAME(_Pin), _PIN_NAME(port->_Pin));
#endif
// 将来可能修改设计,即使注册失败,也可以开启一个短时间的定时任务,来替代中断输入
return false;
}
st->Port = this;
OnRegister();
if(!_taskInput && !HardEvent) _taskInput = Sys.AddTask(InputTask, this, -1, -1, "输入中断"); if(!_taskInput && !HardEvent) _taskInput = Sys.AddTask(InputTask, this, -1, -1, "输入中断");

View File

@ -69,7 +69,7 @@ protected:
// 配置过程由Open调用最后GPIO_Init // 配置过程由Open调用最后GPIO_Init
virtual void OnOpen(void* param); virtual void OnOpen(void* param);
virtual void OnClose(); virtual void OnClose();
private: private:
static void* IndexToGroup(byte index); static void* IndexToGroup(byte index);
static void OnOpenClock(Pin pin, bool flag); static void OnOpenClock(Pin pin, bool flag);
@ -111,7 +111,7 @@ public:
protected: protected:
virtual void OnOpen(void* param); virtual void OnOpen(void* param);
private: private:
void OpenPin(void* param); void OpenPin(void* param);
}; };
@ -128,7 +128,7 @@ public:
protected: protected:
virtual void OnOpen(void* param); virtual void OnOpen(void* param);
private: private:
void OpenPin(void* param); void OpenPin(void* param);
}; };
@ -193,11 +193,11 @@ private:
IOReadHandler Handler = nullptr; IOReadHandler Handler = nullptr;
void* Param = nullptr; void* Param = nullptr;
private: private:
void OpenPin(void* param); void OpenPin(void* param);
void ClosePin(); void ClosePin();
void OnRegister(); bool OnRegister();
}; };
/******************************** AnalogInPort ********************************/ /******************************** AnalogInPort ********************************/
@ -211,7 +211,7 @@ public:
protected: protected:
virtual void OnOpen(void* param); virtual void OnOpen(void* param);
private: private:
void OpenPin(void* param); void OpenPin(void* param);
}; };

View File

@ -200,7 +200,16 @@ typedef struct TIntState
static IntState States[16]; static IntState States[16];
static bool hasInitState = false; static bool hasInitState = false;
extern int Bits2Index(ushort value); int Bits2Index(ushort value)
{
for(int i=0; i<16; i++)
{
if(value & 0x01) return i;
value >>= 1;
}
return -1;
}
#define IT 1 #define IT 1
#ifdef IT #ifdef IT
@ -281,7 +290,7 @@ bool IsOnlyExOfInt(const InputPort* pt, int idx)
int s=0, e=0; int s=0, e=0;
#if defined(STM32F1) || defined(STM32F4) #if defined(STM32F1) || defined(STM32F4)
if(idx <= 4) return true; if(idx <= 4) return true;
if(idx <= 9) if(idx <= 9)
{ {
s = 5; s = 5;
@ -332,16 +341,51 @@ InputPort::Trigger GetTrigger(InputPort::Trigger mode, bool invert)
void InputPort::ClosePin() void InputPort::ClosePin()
{ {
int idx = Bits2Index(Mask); int idx = Bits2Index(Mask);
SetEXIT(idx, false, GetTrigger(Mode, Invert));
if(!IsOnlyExOfInt(this, idx))return; auto st = &States[idx];
Interrupt.Deactivate(PORT_IRQns[idx]); if(st->Port == this)
{
st->Port = nullptr;
SetEXIT(idx, false, GetTrigger(Mode, Invert));
if(!IsOnlyExOfInt(this, idx))return;
Interrupt.Deactivate(PORT_IRQns[idx]);
}
} }
// 注册回调 及中断使能 // 注册回调 及中断使能
void InputPort::OnRegister() bool InputPort::OnRegister()
{ {
// 检查并初始化中断线数组
if(!hasInitState)
{
for(int i=0; i<16; i++)
{
States[i].Port = nullptr;
}
hasInitState = true;
}
byte gi = _Pin >> 4; byte gi = _Pin >> 4;
int idx = Bits2Index(Mask); int idx = Bits2Index(Mask);
auto st = &States[idx];
auto port = st->Port;
// 检查是否已经注册到别的引脚上
if(port != this && port != nullptr)
{
#if DEBUG
debug_printf("中断线EXTI%d 不能注册到 P%c%d, 它已经注册到 P%c%d\r\n", gi, _PIN_NAME(_Pin), _PIN_NAME(port->_Pin));
#endif
// 将来可能修改设计,即使注册失败,也可以开启一个短时间的定时任务,来替代中断输入
return false;
}
st->Port = this;
//byte gi = _Pin >> 4;
//int idx = Bits2Index(Mask);
// 打开时钟选择端口作为端口EXTI时钟线 // 打开时钟选择端口作为端口EXTI时钟线
#if defined(STM32F0) || defined(GD32F150) || defined(STM32F4) #if defined(STM32F0) || defined(GD32F150) || defined(STM32F4)
@ -358,6 +402,8 @@ void InputPort::OnRegister()
Interrupt.SetPriority(PORT_IRQns[idx], 1); Interrupt.SetPriority(PORT_IRQns[idx], 1);
Interrupt.Activate(PORT_IRQns[idx], EXTI_IRQHandler, this); Interrupt.Activate(PORT_IRQns[idx], EXTI_IRQHandler, this);
return true;
} }
#endif #endif