📄 board.cpp
字号:
#include "common.h"
#include "extern.h"
#define INVALID 0xffff
#define BOARDHJ 0x1f //Only used in the use low 4 bits
#define BOARDTJ 0x2f //for A13-A16 and high 4 bits for
#define BOARDZJ 0x4f //A11-A9(A9-A16 is in YK sch papers)
#define YKSTATECODE 0xfb //get the YK type of the evry object
#define YK07CODE 0xfe //get the first 8 YK state
#define YK8FCODE 0xfd //get the second 8 YK state
#define PNONE 0x00
#define PFORRD 0x02
#define PRDBACK 0x03
#define PCHECK 0x04
#define YKSNONE 0x01
#define YKSPRESET 0x02
#define YKSCHECK 0x03
#define YKSEXEC 0x04
#define YKSCANCEL 0x00
static BOOLEAN board_yx_first_sample;
static INT8U last_board_yx[BOARD_YX_LIMIT / 8]; // keep old board yx
static soe_record_t keep_soe[BOARD_YX_LIMIT]; // temporary store soe for qd
static BOOLEAN soe_start_timer_flag[BOARD_YX_LIMIT]; // use for flag qd start
static INT16U soe_timer[BOARD_YX_LIMIT];
static INT16U board_yx_map[BOARD_YX_LIMIT];
static INT16U BoardYc[BOARD_YC_LIMIT]; //for save board yc value
static INT16U ADWays;
static INT16U SwitchWays;
static INT16U board_yc_map[BOARD_YC_LIMIT];
static INT8U ym_bit[BOARD_YM_LIMIT / 8]; //Contain YM value
static INT8U ym_old_bit[BOARD_YM_LIMIT / 8]; //Contain YM value
static INT16U board_ym_map[BOARD_YM_LIMIT];
static BOOLEAN board_ym_first_sample;
static INT16U ym_timer;
yk_register_t ykreg;
static pcheck_t pcheck;
port_yk_info_t port_yk_info;
static void board_yx_update(INT16U dotno, INT16U value);
static void board_yc_update(INT16U dotno, INT16U value);
static void board_ym_update(INT16U dotno);
void board_yx_init(void);
void board_yc_init(void);
void board_ym_init(void);
void board_yx_get(void);
BOOLEAN ykselect(void);
void boardykreset(void);
void board_yx_init(void)
{
int i, j;
board_yx_first_sample = TRUE;
for (i = 0; i < _TotalBDYx; i++) {
soe_start_timer_flag[i] = FALSE;
soe_timer[i] = 0;
}
for (i = 0; i < _TotalBDYx; i++) {
board_yx_map[i] = INVALID;
for (j = 0; j < MAX_YX_LIMIT; j++) {
if (YxDefine[j].portno == BOARD_SOURCE && YxDefine[j].info == i)
board_yx_map[i] = j;
}
}
}
static const INT8U YxBoardAdd[16] =
{0x00, 0x04, 0x08, 0x0c, 0x10, 0x14, 0x18, 0x1c, //E4-E5 E3-E2
0x20, 0x24, 0x28, 0x2c, 0x30, 0x34, 0x38, 0x3c}; //E4-E3 E2-E1
static const INT8U YxChan[4] = {0, 1, 2, 3};
void board_yx_get(void)
{
int i, k;
INT16U yx_in_8bit, orderno;
// board yx total, yx total in 8 bit, board yx order
INT8U current_8yx;
// current sample 8 yx
INT8U test_bit, diff;
INT16U switch_no;
INT16U temp;
sclock sclk;
yxbw_record_t temp_yx_bw;
if (_TotalBDYx == 0) return; // have not board yx
if (_TotalBDYx % 8) {
yx_in_8bit = _TotalBDYx / 8 + 1;
}
else {
yx_in_8bit = _TotalBDYx / 8;
}
if (board_yx_first_sample == FALSE) {
outp(_dio1base + 1, YxChan[0] + YxBoardAdd[0]); // select channel
for (k = 0; k < YX_WAIT_STABLE; k++); // wait for stable
for (i = 0; i < yx_in_8bit; i++) {
current_8yx = inp(_dio1base); // read 8 yx in
outp(_dio1base + 1, YxChan[(i + 1) % 4] + YxBoardAdd[(i + 1) / 4]);
// switch to next 8 yx
diff = current_8yx ^ last_board_yx[i]; // != 0 yx changed
test_bit = 0x1;
for (k = 0; k < 8; k++, test_bit <<= 1) {
orderno = i * 8 + k; // counter
if (diff & test_bit) { // test change position
if (soe_start_timer_flag[orderno]) { // mistake
soe_start_timer_flag[orderno] = FALSE;
soe_timer[orderno] = 0; // clear timer
}
else { // new change
soe_start_timer_flag[orderno] = TRUE; // start qd timer
soe_timer[orderno] = get_mtime();
keep_soe[orderno].status_switch_no = board_yx_map[orderno] & 0xfff;
if (current_8yx & test_bit)
keep_soe[orderno].status_switch_no |= 0x8000;
else keep_soe[orderno].status_switch_no &= 0x7fff; // 0x80:0->1 0x00:1->0
GetClock(&sclk);
keep_soe[orderno].day = sclk.day;
keep_soe[orderno].hour = sclk.hour;
keep_soe[orderno].minute = sclk.minute;
keep_soe[orderno].second = sclk.second;
keep_soe[orderno].msecond = sclk.msecond;
}
} //if (diff & test_bit)
if (soe_start_timer_flag[orderno]) {
if (check_mtimeout(soe_timer[orderno], YX_QD_GAP)) { // real yx change
soe_start_timer_flag[orderno] = FALSE;
soe_timer[orderno] = 0; // clear timer
switch_no = keep_soe[orderno].status_switch_no & 0xfff;
board_yx_update(switch_no, current_8yx >> k);
insert_soe(&keep_soe[orderno]); // add to soe buffer
temp_yx_bw.func_code = (keep_soe[orderno].status_switch_no & 0xfff) / 32;
temp_yx_bw.yx_code[0] = dbdata.Yx[switch_no / 32 * 2];
temp_yx_bw.yx_code[1] = dbdata.Yx[switch_no / 32 * 2 + 1];
insert_yx_bw(&temp_yx_bw); // add to yx bw buffer
}
}
}
last_board_yx[i] = current_8yx;
}
}
if (board_yx_first_sample == TRUE) {
for (i = 0; i < yx_in_8bit; i++) {
outp(_dio1base + 1, YxChan[i % 4] + YxBoardAdd[i / 4]); // select channel
for (k = 0; k < YX_WAIT_STABLE; k++); // wait for stable
last_board_yx[i] = inp(_dio1base); // read yx data keep in old buf
for (k = 0; k < 8; k++)
board_yx_update(board_yx_map[i * 8 + k], last_board_yx[i] >> k);
}
board_yx_first_sample = FALSE;
} // first sample no soe and bw
}
void board_yx_update(INT16U dotno, INT16U value)
{
INT16U dot;
if (dotno == INVALID) return;
if (value & 0x01)
dbdata.Yx[dotno / 16] |= 1 << (dotno % 16);
else dbdata.Yx[dotno / 16] &= ~(1 << (dotno % 16));
}
void yxgetdeal(void)
{
#ifndef YX_INT_SAM
board_yx_get();
#endif
}
void board_yc_init(void)
{
int i, j;
ADWays = SwitchWays = 0;
memset(BoardYc, 0, sizeof(BoardYc));
for (i = 0; i < _TotalBDYc; i++) {
board_yc_map[i] = INVALID;
for (j = 0; j < MAX_YC_LIMIT; j++) {
if (YcDefine[j].portno == BOARD_SOURCE && YcDefine[j].info == i)
board_yc_map[i] = j;
}
}
}
static const INT8U Range = 0; // 0: +/-5V 4: 0-10V 5: 0-5V
static const INT8U StartChan = 0;
static const INT8U StopChan = 15;
void InitAD(void)
{
int i;
for (i = 0; i <= StopChan; i++) { // set a/d range
outp(_adbase + 2, i);
outp(_adbase + 1, Range);
}
outp(_adbase + 2, StopChan << 4 | StartChan); // set scan
}
static const INT8U Chan4067[16] =
{0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00,
0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08};
void selectayc(void)
{
if (_TotalBDYc == 0) return;
if (ADWays == 0)
outp(_dio1base + 0x02, Chan4067[SwitchWays]); // select 4067 way
}
void ycdeal(void)
{
INT16U Real;
INT16U ADChan;
INT8U RawL, RawH;
if (_TotalBDYc == 0) return;
if (inp(_adbase + 0x08) & 0x80) return; // convert not complete
RawL = inportb(_adbase);
RawH = inportb(_adbase + 0x01);
Real = (INT16U) RawH * 16 + (INT16U)(RawL >> 4); // get data
ADChan = RawL & 0xf; // get ad channel
/*
Real = (INT16U) inp(_adbase);
Real += (inp(_adbase + 0x01) << 8);
ADChan = Real & 0x0f;
Real = Real >> 4;*/
if (plattype == MPCMIC)
ADChan = (ADChan / 4) * 64 + SwitchWays * 4 + ADChan - (ADChan / 4) * 4;
if (plattype == MPC104)
ADChan = (ADChan / 8) * 128 + (ADChan % 2) * 64
+ SwitchWays * 4 + (ADChan % 8) / 2;
if (ADChan < _TotalBDYc) {
BoardYc[ADChan] = (BoardYc[ADChan] + Real) / 2;
if (BoardYc[ADChan] >= 0x804)
board_yc_update(ADChan, (BoardYc[ADChan] - 0x800) & 0xfff);
else if (BoardYc[ADChan] <= 0x7fc)
board_yc_update(ADChan, (BoardYc[ADChan] & 0xfff) | 0x800);
else board_yc_update(ADChan, 0);
}
outp(_adbase + 0x08, 0);
outp(_adbase, 0);
ADWays++; //to flag the A/D ways
if (ADWays > StopChan) {
ADWays = 0;
SwitchWays++; // increace the 4067 ways
if (SwitchWays > 15) SwitchWays = 0;//if >15
}
}
void board_yc_update(INT16U dotno, INT16U value)
{
INT16U dot;
dot = board_yc_map[dotno];
if (dot == INVALID) return;
dbdata.Yc[dot] = value;
}
void board_ym_init(void)
{
int i, j;
board_ym_first_sample = TRUE;
for (i = 0; i < _TotalBDYm; i++) {
board_ym_map[i] = INVALID;
for (j = 0; j < MAX_YM_LIMIT; j++) {
if (YmDefine[j].portno == BOARD_SOURCE && YmDefine[j].info == i)
board_ym_map[i] = j;
}
}
}
static const INT8U ymcode[4] = {0x00, 0x01, 0x02, 0x03};
INT8U Get8Ym(INT8U board_addr, INT8U orderno)
{
outp(_dio1base + 1, board_addr + ymcode[orderno]);
for (int i = 0; i < YX_WAIT_STABLE; i++);
return(inp(_dio1base));
}
static const INT8U YmBoardAdd[] = {0x3c, 0x38, 0x34, 0x30, 0x2c, 0x28, 0x24, 0x20}; //E4-E3 E2-E1
void boardymget(void)
{
int i, k;
INT16U ym_in_8bit;
// board yx total, yx total in 8 bit, board yx order
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -