mirror of
https://github.com/halleysfifthinc/Toyota-AVC-LAN
synced 2025-06-08 16:36:11 +00:00
Change split 12bit variables to single uint16_t vars
This commit is contained in:
parent
4952ecb12b
commit
8a7184a620
114
src/avclandrv.c
114
src/avclandrv.c
@ -52,11 +52,9 @@
|
|||||||
#define EVSYS_ASYNCCH0_0_bm EVSYS_ASYNCCH00_bm
|
#define EVSYS_ASYNCCH0_0_bm EVSYS_ASYNCCH00_bm
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uint8_t CD_ID_1;
|
|
||||||
uint8_t CD_ID_2;
|
|
||||||
|
|
||||||
uint8_t HU_ID_1;
|
uint16_t CD_ID;
|
||||||
uint8_t HU_ID_2;
|
uint16_t HU_ID;
|
||||||
|
|
||||||
uint8_t parity_bit;
|
uint8_t parity_bit;
|
||||||
|
|
||||||
@ -75,10 +73,8 @@ uint8_t answerReq;
|
|||||||
cd_modes CD_Mode;
|
cd_modes CD_Mode;
|
||||||
|
|
||||||
uint8_t broadcast;
|
uint8_t broadcast;
|
||||||
uint8_t master1;
|
uint16_t sender;
|
||||||
uint8_t master2;
|
uint16_t responder;
|
||||||
uint8_t slave1;
|
|
||||||
uint8_t slave2;
|
|
||||||
uint8_t message_len;
|
uint8_t message_len;
|
||||||
uint8_t message[MAXMSGLEN];
|
uint8_t message[MAXMSGLEN];
|
||||||
|
|
||||||
@ -204,21 +200,21 @@ void AVCLan_Init() {
|
|||||||
CD_Mode = stStop;
|
CD_Mode = stStop;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t AVCLan_Read_uint8_t(uint8_t length) {
|
uint8_t AVCLan_Read_Byte(uint8_t length) {
|
||||||
uint8_t bite = 0;
|
uint8_t byte = 0;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
while (INPUT_IS_CLEAR) {}
|
while (INPUT_IS_CLEAR) {}
|
||||||
TCB1.CNT = 0;
|
TCB1.CNT = 0;
|
||||||
while (INPUT_IS_SET) {} // If input was set for less than 26 us
|
while (INPUT_IS_SET) {} // If input was set for less than 26 us
|
||||||
if (TCB1.CNT < 208) { // (a generous half period), bit was a 1
|
if (TCB1.CNT < 208) { // (a generous half period), bit was a 1
|
||||||
bite++;
|
byte++;
|
||||||
parity_bit++;
|
parity_bit++;
|
||||||
}
|
}
|
||||||
length--;
|
length--;
|
||||||
if (!length)
|
if (!length)
|
||||||
return bite;
|
return byte;
|
||||||
bite = bite << 1;
|
byte = byte << 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -288,16 +284,18 @@ uint8_t AVCLan_Send_ACK() {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t AVCLan_Send_uint8_t(uint8_t bite, uint8_t len) {
|
uint8_t AVCLan_Send_Byte(uint8_t byte, uint8_t len) {
|
||||||
uint8_t b;
|
uint8_t b;
|
||||||
|
parity_bit = 0;
|
||||||
|
|
||||||
if (len == 8) {
|
if (len == 8) {
|
||||||
b = bite;
|
b = byte;
|
||||||
} else {
|
} else {
|
||||||
b = bite << (8 - len);
|
b = byte << (8 - len);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
if ((b & 128) != 0) {
|
if (b & 0x80) {
|
||||||
AVCLan_Send_Bit1();
|
AVCLan_Send_Bit1();
|
||||||
parity_bit++;
|
parity_bit++;
|
||||||
} else {
|
} else {
|
||||||
@ -366,56 +364,60 @@ uint8_t AVCLan_Read_Message() {
|
|||||||
// RS232_Print("LAN>T2\n");
|
// RS232_Print("LAN>T2\n");
|
||||||
// return 0;
|
// return 0;
|
||||||
// }
|
// }
|
||||||
AVCLan_Read_uint8_t(1);
|
AVCLan_Read_Byte(1);
|
||||||
|
|
||||||
broadcast = AVCLan_Read_uint8_t(1);
|
broadcast = AVCLan_Read_Byte(1);
|
||||||
|
|
||||||
parity_bit = 0;
|
parity_bit = 0;
|
||||||
master1 = AVCLan_Read_uint8_t(4);
|
uint8_t *sender_hi = ((uint8_t *)&sender) + 1;
|
||||||
master2 = AVCLan_Read_uint8_t(8);
|
uint8_t *sender_lo = ((uint8_t *)&sender) + 0;
|
||||||
if ((parity_bit & 1) != AVCLan_Read_uint8_t(1)) {
|
*sender_hi = AVCLan_Read_Byte(4);
|
||||||
|
*sender_lo = AVCLan_Read_Byte(8);
|
||||||
|
if ((parity_bit & 1) != AVCLan_Read_Byte(1)) {
|
||||||
STARTEvent;
|
STARTEvent;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
parity_bit = 0;
|
parity_bit = 0;
|
||||||
slave1 = AVCLan_Read_uint8_t(4);
|
uint8_t *responder_hi = ((uint8_t *)&responder) + 1;
|
||||||
slave2 = AVCLan_Read_uint8_t(8);
|
uint8_t *responder_lo = ((uint8_t *)&responder) + 0;
|
||||||
if ((parity_bit & 1) != AVCLan_Read_uint8_t(1)) {
|
*responder_hi = AVCLan_Read_Byte(4);
|
||||||
|
*responder_lo = AVCLan_Read_Byte(8);
|
||||||
|
if ((parity_bit & 1) != AVCLan_Read_Byte(1)) {
|
||||||
STARTEvent;
|
STARTEvent;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
// is this command for me ?
|
// is this command for me ?
|
||||||
if ((slave1 == CD_ID_1) && (slave2 == CD_ID_2)) {
|
if (responder == CD_ID) {
|
||||||
for_me = 1;
|
for_me = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (for_me)
|
if (for_me)
|
||||||
AVCLan_Send_ACK();
|
AVCLan_Send_ACK();
|
||||||
else
|
else
|
||||||
AVCLan_Read_uint8_t(1);
|
AVCLan_Read_Byte(1);
|
||||||
|
|
||||||
parity_bit = 0;
|
parity_bit = 0;
|
||||||
AVCLan_Read_uint8_t(4); // control - always 0xF
|
AVCLan_Read_Byte(4); // control - always 0xF
|
||||||
if ((parity_bit & 1) != AVCLan_Read_uint8_t(1)) {
|
if ((parity_bit & 1) != AVCLan_Read_Byte(1)) {
|
||||||
STARTEvent;
|
STARTEvent;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (for_me)
|
if (for_me)
|
||||||
AVCLan_Send_ACK();
|
AVCLan_Send_ACK();
|
||||||
else
|
else
|
||||||
AVCLan_Read_uint8_t(1);
|
AVCLan_Read_Byte(1);
|
||||||
|
|
||||||
parity_bit = 0;
|
parity_bit = 0;
|
||||||
message_len = AVCLan_Read_uint8_t(8);
|
message_len = AVCLan_Read_Byte(8);
|
||||||
if ((parity_bit & 1) != AVCLan_Read_uint8_t(1)) {
|
if ((parity_bit & 1) != AVCLan_Read_Byte(1)) {
|
||||||
STARTEvent;
|
STARTEvent;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (for_me)
|
if (for_me)
|
||||||
AVCLan_Send_ACK();
|
AVCLan_Send_ACK();
|
||||||
else
|
else
|
||||||
AVCLan_Read_uint8_t(1);
|
AVCLan_Read_Byte(1);
|
||||||
|
|
||||||
if (message_len > MAXMSGLEN) {
|
if (message_len > MAXMSGLEN) {
|
||||||
// RS232_Print("LAN> Command error");
|
// RS232_Print("LAN> Command error");
|
||||||
@ -425,15 +427,15 @@ uint8_t AVCLan_Read_Message() {
|
|||||||
|
|
||||||
for (i = 0; i < message_len; i++) {
|
for (i = 0; i < message_len; i++) {
|
||||||
parity_bit = 0;
|
parity_bit = 0;
|
||||||
message[i] = AVCLan_Read_uint8_t(8);
|
message[i] = AVCLan_Read_Byte(8);
|
||||||
if ((parity_bit & 1) != AVCLan_Read_uint8_t(1)) {
|
if ((parity_bit & 1) != AVCLan_Read_Byte(1)) {
|
||||||
STARTEvent;
|
STARTEvent;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (for_me) {
|
if (for_me) {
|
||||||
AVCLan_Send_ACK();
|
AVCLan_Send_ACK();
|
||||||
} else {
|
} else {
|
||||||
AVCLan_Read_uint8_t(1);
|
AVCLan_Read_Byte(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -533,15 +535,15 @@ uint8_t AVCLan_SendData() {
|
|||||||
AVC_OUT_EN();
|
AVC_OUT_EN();
|
||||||
|
|
||||||
AVCLan_Send_StartBit();
|
AVCLan_Send_StartBit();
|
||||||
AVCLan_Send_uint8_t(0x1, 1); // regular communication
|
AVCLan_Send_Byte(0x1, 1); // regular communication
|
||||||
|
|
||||||
parity_bit = 0;
|
parity_bit = 0;
|
||||||
AVCLan_Send_uint8_t(CD_ID_1, 4); // CD Changer ID as master
|
AVCLan_Send_Byte(*((uint8_t *)&CD_ID + 1), 4); // CD Changer ID as sender
|
||||||
AVCLan_Send_uint8_t(CD_ID_2, 8);
|
AVCLan_Send_Byte(*((uint8_t *)&CD_ID + 0), 8);
|
||||||
AVCLan_Send_ParityBit();
|
AVCLan_Send_ParityBit();
|
||||||
|
|
||||||
AVCLan_Send_uint8_t(HU_ID_1, 4); // HeadUnit ID as slave
|
AVCLan_Send_Byte(*((uint8_t *)&HU_ID + 1), 4); // HeadUnit ID as responder
|
||||||
AVCLan_Send_uint8_t(HU_ID_2, 8);
|
AVCLan_Send_Byte(*((uint8_t *)&HU_ID + 0), 8);
|
||||||
|
|
||||||
AVCLan_Send_ParityBit();
|
AVCLan_Send_ParityBit();
|
||||||
|
|
||||||
@ -552,7 +554,7 @@ uint8_t AVCLan_SendData() {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
AVCLan_Send_uint8_t(0xF, 4); // 0xf - control -> COMMAND WRITE
|
AVCLan_Send_Byte(0xF, 4); // 0xf - control -> COMMAND WRITE
|
||||||
AVCLan_Send_ParityBit();
|
AVCLan_Send_ParityBit();
|
||||||
if (AVCLan_Read_ACK()) {
|
if (AVCLan_Read_ACK()) {
|
||||||
AVC_OUT_DIS();
|
AVC_OUT_DIS();
|
||||||
@ -561,7 +563,7 @@ uint8_t AVCLan_SendData() {
|
|||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
AVCLan_Send_uint8_t(data_len, 8); // data length
|
AVCLan_Send_Byte(data_len, 8); // data length
|
||||||
AVCLan_Send_ParityBit();
|
AVCLan_Send_ParityBit();
|
||||||
if (AVCLan_Read_ACK()) {
|
if (AVCLan_Read_ACK()) {
|
||||||
AVC_OUT_DIS();
|
AVC_OUT_DIS();
|
||||||
@ -571,7 +573,7 @@ uint8_t AVCLan_SendData() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < data_len; i++) {
|
for (i = 0; i < data_len; i++) {
|
||||||
AVCLan_Send_uint8_t(data[i], 8); // data uint8_t
|
AVCLan_Send_Byte(data[i], 8); // data uint8_t
|
||||||
AVCLan_Send_ParityBit();
|
AVCLan_Send_ParityBit();
|
||||||
if (AVCLan_Read_ACK()) {
|
if (AVCLan_Read_ACK()) {
|
||||||
AVC_OUT_DIS();
|
AVC_OUT_DIS();
|
||||||
@ -613,28 +615,28 @@ uint8_t AVCLan_SendDataBroadcast() {
|
|||||||
AVC_OUT_EN();
|
AVC_OUT_EN();
|
||||||
|
|
||||||
AVCLan_Send_StartBit();
|
AVCLan_Send_StartBit();
|
||||||
AVCLan_Send_uint8_t(0x0, 1); // broadcast
|
AVCLan_Send_Byte(0x0, 1); // broadcast
|
||||||
|
|
||||||
parity_bit = 0;
|
parity_bit = 0;
|
||||||
AVCLan_Send_uint8_t(CD_ID_1, 4); // CD Changer ID as master
|
AVCLan_Send_Byte(*((uint8_t *)&CD_ID + 1), 4); // CD Changer ID as sender
|
||||||
AVCLan_Send_uint8_t(CD_ID_2, 8);
|
AVCLan_Send_Byte(*((uint8_t *)&CD_ID + 0), 8);
|
||||||
AVCLan_Send_ParityBit();
|
AVCLan_Send_ParityBit();
|
||||||
|
|
||||||
AVCLan_Send_uint8_t(0x1, 4); // all audio devices
|
AVCLan_Send_Byte(0x1, 4); // all audio devices
|
||||||
AVCLan_Send_uint8_t(0xFF, 8);
|
AVCLan_Send_Byte(0xFF, 8);
|
||||||
AVCLan_Send_ParityBit();
|
AVCLan_Send_ParityBit();
|
||||||
AVCLan_Send_Bit1();
|
AVCLan_Send_Bit1();
|
||||||
|
|
||||||
AVCLan_Send_uint8_t(0xF, 4); // 0xf - control -> COMMAND WRITE
|
AVCLan_Send_Byte(0xF, 4); // 0xf - control -> COMMAND WRITE
|
||||||
AVCLan_Send_ParityBit();
|
AVCLan_Send_ParityBit();
|
||||||
AVCLan_Send_Bit1();
|
AVCLan_Send_Bit1();
|
||||||
|
|
||||||
AVCLan_Send_uint8_t(data_len, 8); // data lenght
|
AVCLan_Send_Byte(data_len, 8); // data lenght
|
||||||
AVCLan_Send_ParityBit();
|
AVCLan_Send_ParityBit();
|
||||||
AVCLan_Send_Bit1();
|
AVCLan_Send_Bit1();
|
||||||
|
|
||||||
for (i = 0; i < data_len; i++) {
|
for (i = 0; i < data_len; i++) {
|
||||||
AVCLan_Send_uint8_t(data[i], 8); // data uint8_t
|
AVCLan_Send_Byte(data[i], 8); // data uint8_t
|
||||||
AVCLan_Send_ParityBit();
|
AVCLan_Send_ParityBit();
|
||||||
AVCLan_Send_Bit1();
|
AVCLan_Send_Bit1();
|
||||||
}
|
}
|
||||||
@ -875,11 +877,11 @@ void ShowInMessage() {
|
|||||||
else
|
else
|
||||||
RS232_Print("dir) ");
|
RS232_Print("dir) ");
|
||||||
|
|
||||||
RS232_PrintHex4(master1);
|
RS232_PrintHex4(*(((uint8_t *)&sender) + 1));
|
||||||
RS232_PrintHex8(master2);
|
RS232_PrintHex8(*(((uint8_t *)&sender) + 0));
|
||||||
RS232_Print("| ");
|
RS232_Print("| ");
|
||||||
RS232_PrintHex4(slave1);
|
RS232_PrintHex4(*(((uint8_t *)&responder) + 1));
|
||||||
RS232_PrintHex8(slave2);
|
RS232_PrintHex8(*(((uint8_t *)&responder) + 0));
|
||||||
RS232_Print("| ");
|
RS232_Print("| ");
|
||||||
|
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
|
@ -48,16 +48,8 @@ void AVC_ReleaseLine();
|
|||||||
|
|
||||||
#define MAXMSGLEN 32
|
#define MAXMSGLEN 32
|
||||||
|
|
||||||
// Head Unid ID
|
extern uint16_t CD_ID; // CD Changer ID
|
||||||
extern uint8_t HU_ID_1; // 0x01
|
extern uint16_t HU_ID; // Head-unit ID
|
||||||
extern uint8_t HU_ID_2; // 0x40
|
|
||||||
|
|
||||||
extern uint8_t CD_ID_1; // 0x03
|
|
||||||
extern uint8_t CD_ID_2; // 0x60
|
|
||||||
|
|
||||||
// DVD CHANGER
|
|
||||||
// #define CD_ID_1 0x02
|
|
||||||
// #define CD_ID_2 0x50
|
|
||||||
|
|
||||||
#define cmNull 0
|
#define cmNull 0
|
||||||
#define cmStatus1 1
|
#define cmStatus1 1
|
||||||
@ -89,10 +81,8 @@ typedef enum { stStop = 0, stPlay = 1 } cd_modes;
|
|||||||
extern cd_modes CD_Mode;
|
extern cd_modes CD_Mode;
|
||||||
|
|
||||||
extern uint8_t broadcast;
|
extern uint8_t broadcast;
|
||||||
extern uint8_t master1;
|
extern uint16_t sender;
|
||||||
extern uint8_t master2;
|
extern uint16_t responder;
|
||||||
extern uint8_t slave1;
|
|
||||||
extern uint8_t slave2;
|
|
||||||
extern uint8_t message_len;
|
extern uint8_t message_len;
|
||||||
extern uint8_t message[MAXMSGLEN];
|
extern uint8_t message[MAXMSGLEN];
|
||||||
|
|
||||||
|
@ -197,11 +197,13 @@ int main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Setup() {
|
void Setup() {
|
||||||
CD_ID_1 = 0x03;
|
// CD_ID_1 = 0x03;
|
||||||
CD_ID_2 = 0x60;
|
// CD_ID_2 = 0x60;
|
||||||
|
|
||||||
HU_ID_1 = 0x01;
|
// HU_ID_1 = 0x01;
|
||||||
HU_ID_2 = 0x90;
|
// HU_ID_2 = 0x90;
|
||||||
|
CD_ID = 0x360;
|
||||||
|
HU_ID = 0x190;
|
||||||
|
|
||||||
showLog = 1;
|
showLog = 1;
|
||||||
showLog2 = 1;
|
showLog2 = 1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user