329 lines
5.8 KiB
C
329 lines
5.8 KiB
C
|
|
|
|||
|
|
|
|||
|
|
#include "exio.h"
|
|||
|
|
|
|||
|
|
#if (SHIFT_REG_NUM > 0)
|
|||
|
|
|
|||
|
|
#include "shell.h"
|
|||
|
|
#include "delay.h"
|
|||
|
|
#include "inout.h"
|
|||
|
|
#include "trigger.h"
|
|||
|
|
|
|||
|
|
#define OUT_TM_INFO 0
|
|||
|
|
|
|||
|
|
//------------------------------------------
|
|||
|
|
#ifndef ExDelay
|
|||
|
|
#define ExDelay() DelayUs(1)
|
|||
|
|
#endif
|
|||
|
|
|
|||
|
|
//------------------------------------------
|
|||
|
|
|
|||
|
|
void ReadExInputs(u8 * inputList);
|
|||
|
|
void WriteExOutputs(u8* outputList);
|
|||
|
|
void ExioSwapData(void);
|
|||
|
|
|
|||
|
|
void TestExInout(char * para1, char * para2);
|
|||
|
|
|
|||
|
|
//------------------------------------------
|
|||
|
|
|
|||
|
|
#define MAX_EX_INPUTS_NUM (SHIFT_REG_NUM*IN_NUM_PER_REG)
|
|||
|
|
#define MAX_EX_OUTPUTS_NUM (SHIFT_REG_NUM*OUT_NUM_PER_REG)
|
|||
|
|
|
|||
|
|
u8 g_exInputStaList[MAX_EX_INPUTS_NUM];
|
|||
|
|
u8 g_exOutputStaList[MAX_EX_OUTPUTS_NUM];
|
|||
|
|
|
|||
|
|
//------------------------------------------
|
|||
|
|
|
|||
|
|
#ifndef SetOutputEnHigh
|
|||
|
|
#define SetOutputEnHigh SetOutputNull
|
|||
|
|
#endif
|
|||
|
|
|
|||
|
|
#ifndef SetOutputEnLow
|
|||
|
|
#define SetOutputEnLow SetOutputNull
|
|||
|
|
#endif
|
|||
|
|
|
|||
|
|
void InitExInOuts(void)
|
|||
|
|
{
|
|||
|
|
memset(g_exInputStaList, 0, sizeof(u8)*MAX_EX_INPUTS_NUM);
|
|||
|
|
memset(g_exOutputStaList, 0, sizeof(u8)*MAX_EX_INPUTS_NUM);
|
|||
|
|
|
|||
|
|
SetOutputEnHigh();
|
|||
|
|
GetExInputSta(-1); // <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD>״̬
|
|||
|
|
SetExOutputOff(0); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD>Ϊoff
|
|||
|
|
SetOutputEnLow();
|
|||
|
|
|
|||
|
|
// AddShellCmd("TESTEX", "test Ex inout", TestExInout);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD>״̬
|
|||
|
|
void ReadExInputs(u8 * inputList)
|
|||
|
|
{
|
|||
|
|
int i;
|
|||
|
|
if (inputList == NULL)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
SetClkHigh(); // <20><><EFBFBD><EFBFBD>Ϊ<EFBFBD>ߵ<EFBFBD>ƽ
|
|||
|
|
SetInputLatchLow(); // <20><><EFBFBD>浽<EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>
|
|||
|
|
ExDelay();
|
|||
|
|
SetInputLatchHigh(); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
ExDelay(); // <20>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȶ<EFBFBD>
|
|||
|
|
|
|||
|
|
// <20><>ȡ<EFBFBD><C8A1><EFBFBD>ݣ<EFBFBD><DDA3>ӵ<EFBFBD>λ<EFBFBD><CEBB>ʼ
|
|||
|
|
for(i = 0; i < MAX_EX_INPUTS_NUM; i++)
|
|||
|
|
{
|
|||
|
|
ExDelay(); // <20>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȶ<EFBFBD>
|
|||
|
|
SetClkLow(); // <20><>ƽ<EFBFBD><C6BD>ת
|
|||
|
|
*inputList++ = GetDinStatus(); // <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
|||
|
|
ExDelay();
|
|||
|
|
SetClkHigh(); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>ʼ<EFBFBD><CABC>λ
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
void WriteExOutputs(u8* outputList)
|
|||
|
|
{
|
|||
|
|
int i;
|
|||
|
|
|
|||
|
|
if (outputList == NULL)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
SetClkLow();
|
|||
|
|
SetOutputLatchLow();
|
|||
|
|
ExDelay();
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><DDA3>Ӹ<EFBFBD>λ<EFBFBD><CEBB>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
|
|||
|
|
for(i = MAX_EX_OUTPUTS_NUM; i > 0; i--)
|
|||
|
|
{
|
|||
|
|
if ((outputList[i-1]) != 0)
|
|||
|
|
{
|
|||
|
|
SetDOutLow();
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
SetDOutHigh();
|
|||
|
|
}
|
|||
|
|
ExDelay(); // <20>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȶ<EFBFBD>
|
|||
|
|
SetClkHigh(); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD>
|
|||
|
|
ExDelay(); // <20>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȶ<EFBFBD>
|
|||
|
|
SetClkLow(); // <20><>תΪ<D7AA>͵<EFBFBD>ƽ
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
SetOutputLatchHigh(); // <20><><EFBFBD><EFBFBD><EFBFBD>أ<EFBFBD><D8A3><EFBFBD>λ<EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>
|
|||
|
|
ExDelay();
|
|||
|
|
SetOutputLatchLow(); // <20><>תΪ<D7AA>͵<EFBFBD>ƽ
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
void ExioSwapData(void)
|
|||
|
|
{
|
|||
|
|
int i, j;
|
|||
|
|
SetClkLow(); // <20><><EFBFBD><EFBFBD>Ϊ<EFBFBD>͵<EFBFBD>ƽ
|
|||
|
|
SetOutputLatchLow(); // <20><><EFBFBD><EFBFBD>Ϊ<EFBFBD>͵<EFBFBD>ƽ
|
|||
|
|
SetInputLatchLow(); // <20><><EFBFBD>浽<EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>
|
|||
|
|
ExDelay();
|
|||
|
|
SetInputLatchHigh(); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
ExDelay(); // <20>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȶ<EFBFBD>
|
|||
|
|
|
|||
|
|
for(i = MAX_EX_OUTPUTS_NUM, j = 0; i > 0; i--, j++)
|
|||
|
|
{
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
if ((g_exInputStaList[i-1]) != 0)
|
|||
|
|
{
|
|||
|
|
SetDOutLow();
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
SetDOutHigh();
|
|||
|
|
}
|
|||
|
|
ExDelay(); // <20>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȶ<EFBFBD>
|
|||
|
|
SetClkHigh(); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>ʼ<EFBFBD><CABC>λ
|
|||
|
|
ExDelay();
|
|||
|
|
g_exInputStaList[j] = GetDinStatus(); // <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
SetClkLow(); // <20><>תΪ<D7AA>͵<EFBFBD>ƽ
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
SetOutputLatchHigh(); // <20><><EFBFBD><EFBFBD><EFBFBD>أ<EFBFBD><D8A3><EFBFBD>λ<EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>
|
|||
|
|
ExDelay();
|
|||
|
|
SetOutputLatchLow(); // <20><>תΪ<D7AA>͵<EFBFBD>ƽ
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#ifndef RD_EXIN_GAP
|
|||
|
|
#define RD_EXIN_GAP 0 // <20><>λms
|
|||
|
|
#endif
|
|||
|
|
|
|||
|
|
u8 GetExInputSta(int id)
|
|||
|
|
{
|
|||
|
|
#if (OUT_TM_INFO == 1)
|
|||
|
|
u32 temp, timer;
|
|||
|
|
timer = GetUsSoftTimer();
|
|||
|
|
#endif
|
|||
|
|
#if (RD_EXIN_GAP > 0)
|
|||
|
|
static u32 oldtimer = 0;
|
|||
|
|
u32 newtimer = GetMsSoftTimer();
|
|||
|
|
if (newtimer - oldtimer > RD_EXIN_GAP)
|
|||
|
|
{
|
|||
|
|
oldtimer = newtimer;
|
|||
|
|
ReadExInputs(g_exInputStaList);
|
|||
|
|
}
|
|||
|
|
#else
|
|||
|
|
ReadExInputs(g_exInputStaList);
|
|||
|
|
#endif
|
|||
|
|
#if (OUT_TM_INFO == 1)
|
|||
|
|
temp = GetUsSoftTimer();
|
|||
|
|
printf("GetExInputSta time=%d\r\n", temp-timer);
|
|||
|
|
#endif
|
|||
|
|
if (id > 0 && id <= MAX_EX_INPUTS_NUM)
|
|||
|
|
{
|
|||
|
|
return g_exInputStaList[id-1];
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return 0xff;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
u8 GetExOutputSta(int id)
|
|||
|
|
{
|
|||
|
|
if (id > 0 && id <= MAX_EX_OUTPUTS_NUM)
|
|||
|
|
{
|
|||
|
|
return g_exOutputStaList[id-1];
|
|||
|
|
}
|
|||
|
|
return 0xff;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void SetExOutputOn(int id)
|
|||
|
|
{
|
|||
|
|
#if (OUT_TM_INFO == 1)
|
|||
|
|
u32 temp, timer;
|
|||
|
|
timer = GetUsSoftTimer();
|
|||
|
|
#endif
|
|||
|
|
if (id > 0 && id <= MAX_EX_OUTPUTS_NUM)
|
|||
|
|
{
|
|||
|
|
g_exOutputStaList[id-1] = 1;
|
|||
|
|
}
|
|||
|
|
else if (id == 0)
|
|||
|
|
{
|
|||
|
|
memset(g_exOutputStaList, 1, sizeof(u8)*MAX_EX_INPUTS_NUM); // ȫ<><C8AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
WriteExOutputs(g_exOutputStaList);
|
|||
|
|
#if (OUT_TM_INFO == 1)
|
|||
|
|
temp = GetUsSoftTimer();
|
|||
|
|
printf("GetExInputSta time=%d\r\n", temp-timer);
|
|||
|
|
#endif
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void SetExOutputOff(int id)
|
|||
|
|
{
|
|||
|
|
#if (OUT_TM_INFO == 1)
|
|||
|
|
u32 temp, timer;
|
|||
|
|
timer = GetUsSoftTimer();
|
|||
|
|
#endif
|
|||
|
|
if (id > 0 && id <= MAX_EX_OUTPUTS_NUM)
|
|||
|
|
{
|
|||
|
|
g_exOutputStaList[id-1] = 0;
|
|||
|
|
}
|
|||
|
|
else if (id == 0)
|
|||
|
|
{
|
|||
|
|
memset(g_exOutputStaList, 0, sizeof(u8)*MAX_EX_INPUTS_NUM); // ȫ<><C8AB><EFBFBD>ر<EFBFBD>
|
|||
|
|
}
|
|||
|
|
WriteExOutputs(g_exOutputStaList);
|
|||
|
|
#if (OUT_TM_INFO == 1)
|
|||
|
|
temp = GetUsSoftTimer();
|
|||
|
|
printf("GetExInputSta time=%d\r\n", temp-timer);
|
|||
|
|
#endif
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void TestExInout(char * para1, char * para2)
|
|||
|
|
{
|
|||
|
|
int p1, p2;
|
|||
|
|
|
|||
|
|
p1 = p2 = 0;
|
|||
|
|
if (para1 != NULL && strcmp(para1, "") != 0)
|
|||
|
|
{
|
|||
|
|
p1 = atoi(para1);
|
|||
|
|
}
|
|||
|
|
if (para2 != NULL && strcmp(para2, "") != 0)
|
|||
|
|
{
|
|||
|
|
p2 = atoi(para2);
|
|||
|
|
}
|
|||
|
|
if (p1 == p2)
|
|||
|
|
{
|
|||
|
|
}
|
|||
|
|
//--------------------------------
|
|||
|
|
|
|||
|
|
if (p1 < 100)
|
|||
|
|
{// <20><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>״̬
|
|||
|
|
s8 oldinput[MAX_EX_INPUTS_NUM] = {-1};
|
|||
|
|
do
|
|||
|
|
{
|
|||
|
|
GetExInputSta(-1);
|
|||
|
|
|
|||
|
|
for (int i = 0; i < MAX_EX_INPUTS_NUM; i++)
|
|||
|
|
{
|
|||
|
|
if (oldinput[i] != g_exInputStaList[i])
|
|||
|
|
{
|
|||
|
|
oldinput[i] = g_exInputStaList[i];
|
|||
|
|
if (oldinput[i] == 0)
|
|||
|
|
{
|
|||
|
|
printf("%d.input is on\r\n", i+1);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
printf("%d.input is off\r\n", i+1);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (IsConsoleCancel() != 0 || p1 == 0) // <20>ն<EFBFBD><D5B6><EFBFBD><EFBFBD><EFBFBD>ֹͣ
|
|||
|
|
{
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
DelayMs(50);
|
|||
|
|
|
|||
|
|
}while(1);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{// <20><><EFBFBD><EFBFBD>
|
|||
|
|
p1 -= 100;
|
|||
|
|
if (p1 == 0)
|
|||
|
|
{// <20><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>״̬
|
|||
|
|
for (int i = 0; i < MAX_EX_OUTPUTS_NUM; i++)
|
|||
|
|
{
|
|||
|
|
if (g_exOutputStaList[i] == 1)
|
|||
|
|
{
|
|||
|
|
printf("%d.output is on\r\n", i+1);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
printf("%d.output is off\r\n", i+1);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
|
|||
|
|
if (p2 == 0)
|
|||
|
|
{// off
|
|||
|
|
if (p1 > 0 && p1 <= MAX_EX_OUTPUTS_NUM)
|
|||
|
|
{
|
|||
|
|
g_exOutputStaList[p1-1] = 0;
|
|||
|
|
WriteExOutputs(g_exOutputStaList);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{// on
|
|||
|
|
if (p1 > 0 && p1 <= MAX_EX_OUTPUTS_NUM)
|
|||
|
|
{
|
|||
|
|
g_exOutputStaList[p1-1] = 1;
|
|||
|
|
WriteExOutputs(g_exOutputStaList);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#endif
|