📄 dataio.c
字号:
#include "wea_dos.h"
void Ini_FPGA()
{
BYTE d;
unsigned short p;
d=0;
p=PC_ENABLE_L_O;
outb(p,d);
outb(p,d);
p=PC_DISABLE_H_O;
outb(p,d);
outb(p,d);
p=PC_INI_O;
d=0xaa;
d=0xaa;
outb(p,d);
p=SELF_TEST_SEL_O;
d=0;
outb(p,d);
outb(p,d);
}
void Ini_Map()
{
unsigned short p=MAP_O;
MAPO map;
map._bit.sdata=1;
map._bit.sclk=1;
map._bit.latch=1;
outb(p,map._byte);
outb(p,map._byte);
}
void Ini_Wea()
{
g_wea_o._bit.ready=0;
g_wea_o._bit.rpt_end=1;
g_wea_o._bit.job_end=0;
outb(WEAVER_O,g_wea_o._byte);
}
void Kill_FPGA()
{
unsigned short p=PC_INI_O;
BYTE d=0;
outb(p,d);
}
/*
void SendEnable(int TimeWidth)
{
int t=TimeWidth;
int p=MAP_O;
g_map_o._bit.enable=1;
outb(p,g_map_o._byte);
for(int i=0;i<t;i++)
DelayMs(1);
g_map_o._bit.enable=0;
outb(p,g_map_o._byte);
}
*/
void SendByte(BYTE data)
{
int bit,i;
int m=0x80;
for(i=0;i<8;i++)
{
bit=data&m;
SendBit(bit);
m=m/2;
}
}
void SendBit(int bit)
{ unsigned short p;
if(bit!=0)
bit=1;
p=MAP_O;
g_map_o._bit.sclk=0;
g_map_o._bit.latch=1;
outb(p,g_map_o._byte); /*sclk=0*/
g_map_o._bit.sdata=bit;
outb(p,g_map_o._byte); /*sdata=bit*/
/*Delay1u();*/
g_map_o._bit.sclk=1;
outb(p,g_map_o._byte); /*sclk=1*/
/*DelayUs(1);
DelayUs(1);*/
#ifndef CPU300M
DelayUs(1);
#endif
}
void SendLatchLevel(int level)
{
unsigned short p=MAP_O;
g_map_o._bit.latch=level;
outb(p,g_map_o._byte);
}
void SendSclkLevel(int level)
{
unsigned short p=MAP_O;
g_map_o._bit.sclk=level;
outb(p,g_map_o._byte);
}
/*
void SendEnableLevel(int level)
{
int p=OUTPORT;
if(level==0)
g_map_o._bit.enable=0;
else
g_map_o._bit.enable=1;
outb(p,g_map_o._byte);
}
*/
void SendLatch()
{
unsigned short p=MAP_O;
g_map_o._bit.latch=1;
outb(p,g_map_o._byte); /*latch=1*/
g_map_o._bit.latch=0;
outb(p,g_map_o._byte); /*latch=0*/
DelayMs(1); /* delay 1mS*/
g_map_o._bit.latch=1;
outb(p,g_map_o._byte); /*latch=1*/
}
void SendZero(int nMap)
{
int i;
BYTE data;
data=0;
for(i=0;i<nMap*4;i++)
SendByte(data);
SendLatch();
}
/*
BYTE GetByte(BOOL bInvert)
{
int p=INPORT;
int i;
BYTE data=0;
for(i=0;i<8;i++)
{
data=data*2;
SendSclks(1);
g_map_i._byte=inb(p);
if(bInvert!=0)
g_map_i._bit.sdata_i=1-g_map_i._bit.sdata_i;
data=data+g_map_i._bit.sdata_i;
}
return data;
}
*/
void ByteToBit(BYTE data,int* bit)
{
int b,k;
BYTE mask=0x80;
for(k=0;k<8;k++)
{
b=data&mask;
if(b!=0)
bit[k]=1;
else
bit[k]=0;
mask=mask/2;
}
}
void Delay1u() /*0.5uS*/
{
int i;
#ifdef CPU300M
for(i=0;i<20;i++)
#else
for(i=0;i<100;i++)
#endif
{
}
}
void Delay1m() /*0.5mS*/
{
int i,j;
#ifdef CPU300M
for(i=0;i<200;i++)
#else
for(i=0;i<1000;i++)
#endif
for(j=0;j<100;j++)
{
}
}
void DelayMs(int nMs)
{ int i;
for(i=0;i<2*nMs;i++)
Delay1m();
}
void DelayUs(int nUs)
{
int i;
for(i=0;i<2*nUs;i++)
Delay1u();
}
int GetMapNum(int MaxMapNumber)
{
int i,j;
unsigned short p=MAP_I;
DelayMs(10);
#ifdef SOFT_RUN
return g_job.nWarp/32;
#endif
for(j=0;j<25;j++)
{
SendBit(0);
}
SendBit(1);
SendBit(0);
SendBit(0);
SendBit(0);
SendBit(0);
SendBit(0);
DelayMs(10);
g_map_i._byte=inb(p);
if(g_map_i._bit.test==0) /* inverted*/
{
return 0; /* error at D7*/
}
SendBit(0);
DelayMs(10);
g_map_i._byte=inb(p);
if(g_map_i._bit.test==1) /* inverted*/
{
return 0; /* error at D7*/
}
for(i=1;i<MaxMapNumber;i++)
{
for(j=0;j<31;j++) /* data OK, test next MAP*/
{
SendBit(1);
}
DelayMs(10);
g_map_i._byte=inb(p);
if(g_map_i._bit.test==0) /* inverted*/
{
return i; /* error at D7*/
}
SendBit(1);
DelayMs(10);
g_map_i._byte=inb(p);
if(g_map_i._bit.test==1) /* inverted*/
{
return i; /* error at D7*/
}
}
return 0;
}
BOOL CheckDataConnect(char* info)
{
unsigned short p=MAP_I;
int nMap;
SendSclkLevel(0);
DelayMs(10);
g_map_i._byte=inb(p);
if(g_map_i._bit.sclk_i==1)
{
nMap=GetMapNum(100);
sprintf(info,"Data line on MAP %d-%d not connected\n\r",nMap,nMap+1);
return FALSE;
}
SendSclkLevel(1);
DelayMs(10);
g_map_i._byte=inb(p);
if(g_map_i._bit.sclk_i==0)
{
nMap=GetMapNum(100);
sprintf(info,"Data line on MAP %d-%d not connected\n\r",nMap,nMap+1);
return FALSE;
}
return TRUE;
}
int GetBit(BOOL bInvert)
{
unsigned short p=MAP_I;
int bit;
g_map_i._byte=inb(p);
bit=g_map_i._bit.sdata_i;
if(bInvert!=0)
bit=1-bit;
return bit;
}
void ReadFRAM()
{ /*format: 0,1:WeaIndex(not uesed);2,3:g_iLine;
4,5:g_iWeaRepeat; 6,7:g_iJobRepeat(not used)*/
unsigned short p,d;
int i;
p=PC_MEM_START_O;
g_point.iWea._byte.l=inb(p);
p++;
g_point.iWea._byte.h=inb(p);
p++;
g_point.iLine._byte.l=inb(p);
p++;
g_point.iLine._byte.h=inb(p);
p++;
g_point.iWeaRepeat._byte.l=inb(p);
p++;
g_point.iWeaRepeat._byte.h=inb(p);
p++;
g_point.iJobRepeat._byte.l=inb(p);
p++;
g_point.iJobRepeat._byte.h=inb(p);
p++;
i=g_point.iWea._int;
if(i<0 || i>=g_job.nWea)
{
ResetPoint();
return;
}
if(g_point.iLine._int<g_job.start[i] ||g_point.iLine._int>g_job.end[i])
ResetPoint();
}
void WriteFRAM()
{ /*format: 0,1:WeaIndex(not uesed);2,3:g_iLine;
4,5:g_iWeaRepeat; 6,7:g_iJobRepeat(not used)*/
unsigned short p;
p=PC_MEM_START_O+2;
outb(p,g_point.iLine._byte.l);
p++;
outb(p,g_point.iLine._byte.h);
p++;
outb(p,g_point.iWeaRepeat._byte.l);
p++;
outb(p,g_point.iWeaRepeat._byte.h);
}
BOOL CheckIO(char* info)
{
/* OK,NODATA,NOPOWER,WEFTBRK,WARPBRK */
int p=MAP_I;
#ifdef SOFT_RUN
return 1;
#endif
/*return 1;*/
g_map_i._byte=inb(p);
/* if(g_map_i._bit.no_data==1)
{
// *err=NODATA;
strcpy(info,"No data");
Forward1();
Forward1();
return FALSE;
}
*/ if(g_map_i._bit.ps==0)
{
strcpy(info,"Power error");
return FALSE;
/* g_power_count++;
if(g_power_count>=2)
{
g_power_count=0;
strcpy(info,"Power error");
return FALSE;
} */
// *err=NOPOWER;
}
p=WEAVER_I;
g_wea_i._byte=inb(p);
if(g_wea_i._byte!=0)
{
DelayMs(4);
g_wea_i._byte=inb(p);
}
if(g_bWoofFinish==1)
{
g_bWoofFinish=0;
if(g_bWeftLock==1)
{
// *err=WEFTBRK;
strcpy(info,"Weft break, clear error when ready");
return FALSE;
}
else
{
strcpy(info,"Weft break, run when ready");
// *err=WEFTBRK;
}
}
if((g_wea_i._bit.wa_brk==0) && (g_Warp_break==1))
{
g_Warp_break=0;
strcpy(info,"Warp break, run when ready");
// *err=WARPBRK;
}
g_Warp_break=g_wea_i._bit.wa_brk;
return TRUE;
}
BOOL ClearError(char *info)
{
BOOL bOK;
int n;
outb(PC_CLEAR_FPGALOCK_O,1);
n=GetMapNum(100);
if(n!=g_job.nWarp/32)
{
sprintf(info,"Map number (%d) does not match job (%d)",n,g_job.nWarp/32);
StopRun();
return FALSE;
}
bOK=CheckIO(info);
if(!bOK)
{
StopRun();
return FALSE;
}
sprintf(info,"Ready to run");
StartRun();
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -