update1
This commit is contained in:
parent
d59df82aa5
commit
0dac38e5d2
194
d72042.ino
194
d72042.ino
@ -1,18 +1,12 @@
|
||||
#include <SPI.h>
|
||||
|
||||
#define MODE 8
|
||||
#define CONTROL 9
|
||||
#define READ 0x08
|
||||
#define RESET 7
|
||||
|
||||
#define DATASIZE 20
|
||||
|
||||
char data[DATASIZE] = {0x0,};
|
||||
void iebus_init();
|
||||
byte inline bitchange(byte b)
|
||||
{
|
||||
return b << 4;
|
||||
}
|
||||
|
||||
#define iebusIRQ 2
|
||||
#define RAW 0x4
|
||||
#define isRAW (READFLG&RAW)
|
||||
#define isMARQ (READFLG&0x40)
|
||||
|
||||
|
||||
#define REG_WRITE_CTR bitchange(0x0)
|
||||
@ -37,6 +31,74 @@ byte inline bitchange(byte b)
|
||||
#define REG_READ_RBF (bitchange(0xe)|READ)
|
||||
|
||||
|
||||
#define LOW_ADDR 0x0
|
||||
#define HIGH_ADDR 0x36
|
||||
|
||||
#define MODE 8
|
||||
#define CONTROL 9
|
||||
#define READ 0x08
|
||||
#define RESET 7
|
||||
|
||||
#define DATASIZE 20
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void iebus_init();
|
||||
void flaginit();
|
||||
void iebus_transmission();
|
||||
void iebus_reception();
|
||||
void iebus_mastercomm();
|
||||
void iebus_slavetransmission();
|
||||
void iebus_command();
|
||||
int checkMARC();
|
||||
void iebus_irq();
|
||||
void iebus_loop();
|
||||
void dataWrite(char reg_addr, char *data, int datasize);
|
||||
int dataRead(char reg_addr, char *data);
|
||||
byte dataRead1byte(char addr);
|
||||
void dataWrite1byte(char addr , char data);
|
||||
|
||||
byte READFLG;
|
||||
char data[DATASIZE] = {0x0,};
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct _communicationFlag
|
||||
{
|
||||
bool RAWF;
|
||||
bool TRRQ;
|
||||
|
||||
byte I;
|
||||
bool RERQ;
|
||||
byte RECF;
|
||||
byte SIZE;
|
||||
byte PW;
|
||||
byte PR;
|
||||
byte J;
|
||||
bool MCRQ;
|
||||
bool SDRQ;
|
||||
bool CORQ;
|
||||
bool MTRQF;
|
||||
bool MRRQF;
|
||||
bool STRQF;
|
||||
bool SLREF;
|
||||
byte TRCF;
|
||||
} commFlag;
|
||||
|
||||
|
||||
byte inline bitchange(byte b)
|
||||
{
|
||||
return b << 4;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void setup (void) {
|
||||
Serial.begin(9600); //set baud rate to 115200 for usart
|
||||
|
||||
@ -58,39 +120,9 @@ void setup (void) {
|
||||
iebus_init();
|
||||
}
|
||||
|
||||
// avclan.deviceAddress = 0x360;
|
||||
// avclan.broadcast = AVC_MSG_NORMAL;
|
||||
// avclan.masterAddress = 0x0360;
|
||||
// avclan.slaveAddress = 0x0140;
|
||||
|
||||
|
||||
|
||||
#define LOW_ADDR 0x0
|
||||
#define HIGH_ADDR 0x36
|
||||
|
||||
|
||||
|
||||
struct _communicationFlag
|
||||
{
|
||||
bool RAWF;
|
||||
bool TRRQ;
|
||||
bool TRCF;
|
||||
byte I;
|
||||
bool RERQ;
|
||||
byte RECF;
|
||||
byte SIZE;
|
||||
byte PW;
|
||||
byte PR;
|
||||
byte J;
|
||||
bool MCRQ;
|
||||
bool SDRQ;
|
||||
bool CORQ;
|
||||
bool MTRQF;
|
||||
bool MRRQF;
|
||||
bool STRQF;
|
||||
bool SLREF;
|
||||
}commFlag;
|
||||
|
||||
|
||||
|
||||
|
||||
@ -106,6 +138,9 @@ void iebus_init()
|
||||
dataWrite1byte(REG_WRITE_CMR, B10000000); //CMR 100000 b1 b0
|
||||
|
||||
flaginit();
|
||||
pinMode(iebusIRQ, INPUT_PULLUP);
|
||||
|
||||
attachInterrupt(digitalPinToInterrupt(iebusIRQ), iebus_irq, RISING);
|
||||
}
|
||||
void flaginit()
|
||||
{
|
||||
@ -149,6 +184,83 @@ void iebus_command()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
int checkMARC()
|
||||
{
|
||||
byte rcrdata = 0xf0 & dataRead1byte(REG_READ_RCR);
|
||||
int isResult = 0;
|
||||
if (bitRead(rcrdata, 7) == 0 && bitRead(rcrdata, 6) == 0)
|
||||
{
|
||||
isResult = 1;
|
||||
}
|
||||
else if (bitRead(rcrdata, 7) == 0 && bitRead(rcrdata, 6) == 1 && bitRead(rcrdata, 5) == 0)
|
||||
{
|
||||
isResult = 2;
|
||||
}
|
||||
else if (bitRead(rcrdata, 7) == 0 && bitRead(rcrdata, 6) == 1 && bitRead(rcrdata, 5) == 1)
|
||||
{
|
||||
isResult = 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
isResult = 0;
|
||||
}
|
||||
|
||||
return isResult;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void iebus_irq()
|
||||
{
|
||||
byte marcValue;
|
||||
noInterrupts();
|
||||
READFLG = dataRead1byte(REG_READ_FLG);
|
||||
if (isRAW)
|
||||
{
|
||||
commFlag.RAWF = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
marcValue = checkMARC();
|
||||
if ((commFlag.MTRQF == 1 && isMARQ == 0) || (commFlag.MRRQF == 1 && isMARQ == 0) || (marcValue > 0))
|
||||
{
|
||||
Serial.println("MARC");
|
||||
if (marcValue == 1)
|
||||
{
|
||||
//00xx
|
||||
commFlag.TRCF = marcValue>>4;
|
||||
commFlag.TRRQ = 1;
|
||||
}
|
||||
else if (marcValue == 2)
|
||||
{
|
||||
//010x
|
||||
commFlag.RERQ = 1;
|
||||
commFlag.SIZE = dataRead1byte(REG_READ_RDR1);
|
||||
commFlag.RECF = marcValue>>4;
|
||||
}
|
||||
else if (isMarc == 3)
|
||||
{
|
||||
//011x
|
||||
commFlag.RERQ = 1;
|
||||
commFlag.SIZE = dataRead1byte(REG_READ_RDR1);
|
||||
commFlag.RECF = marcValue>>4;
|
||||
|
||||
//increment PW
|
||||
commFlag.RERQ = 0;
|
||||
commFlag.SIZE = 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//is Return code in slrc
|
||||
}
|
||||
}
|
||||
interrupts();
|
||||
}
|
||||
|
||||
void iebus_loop()
|
||||
{
|
||||
if (commFlag.RAWF == 1)
|
||||
|
Loading…
x
Reference in New Issue
Block a user