修正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
#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(Pin pin, bool floating, PuPd pull) : Port()
@ -500,15 +479,7 @@ void InputPort::OnClose()
{
Port::OnClose();
int idx = Bits2Index(Mask);
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;
Param = param;
// 检查并初始化中断线数组
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(!OnRegister()) return false;
if(!_taskInput && !HardEvent) _taskInput = Sys.AddTask(InputTask, this, -1, -1, "输入中断");

View File

@ -197,7 +197,7 @@ private:
private:
void OpenPin(void* param);
void ClosePin();
void OnRegister();
bool OnRegister();
};
/******************************** AnalogInPort ********************************/

View File

@ -200,7 +200,16 @@ typedef struct TIntState
static IntState States[16];
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
#ifdef IT
@ -332,16 +341,51 @@ InputPort::Trigger GetTrigger(InputPort::Trigger mode, bool invert)
void InputPort::ClosePin()
{
int idx = Bits2Index(Mask);
auto st = &States[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;
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时钟线
#if defined(STM32F0) || defined(GD32F150) || defined(STM32F4)
@ -358,6 +402,8 @@ void InputPort::OnRegister()
Interrupt.SetPriority(PORT_IRQns[idx], 1);
Interrupt.Activate(PORT_IRQns[idx], EXTI_IRQHandler, this);
return true;
}
#endif