1
0
mirror of https://github.com/halleysfifthinc/Toyota-AVC-LAN synced 2025-06-07 16:06:12 +00:00

Replace byte/word typedefs with uintN_t

This commit is contained in:
Allen Hill 2023-08-20 20:45:22 -04:00
parent c4f67378ae
commit 4fcdf4af36
7 changed files with 277 additions and 281 deletions

View File

@ -27,9 +27,9 @@
#include "GlobalDef.h" #include "GlobalDef.h"
// max 10 events in fifo // max 10 events in fifo
byte EventCount; // uint8_t EventCount;
byte EventCmd[10]; // uint8_t EventCmd[10];
byte Event; uint8_t Event;
byte showLog; uint8_t showLog;
byte showLog2; uint8_t showLog2;

View File

@ -24,30 +24,27 @@
#define sbi(port, bit) (port) |= (1 << (bit)) // Set bit (i.e. to 1) #define sbi(port, bit) (port) |= (1 << (bit)) // Set bit (i.e. to 1)
#define cbi(port, bit) (port) &= ~(1 << (bit)) // Clear bit (i.e. set bit to 0) #define cbi(port, bit) (port) &= ~(1 << (bit)) // Clear bit (i.e. set bit to 0)
typedef unsigned char byte; // // max 10 events in fifo
typedef unsigned int word; // extern uint8_t EventCount;
// extern uint8_t EventCmd[10];
// max 10 events in fifo extern uint8_t Event;
extern byte EventCount;
extern byte EventCmd[10];
extern byte Event;
#define EV_NOTHING 0 #define EV_NOTHING 0
#define EV_DISPLAY 1 #define EV_DISPLAY 1
#define EV_STATUS 4 #define EV_STATUS 4
// const // // const
#define smYear 1 // #define smYear 1
#define smMonth 2 // #define smMonth 2
#define smDay 3 // #define smDay 3
#define smHour 4 // #define smHour 4
#define smMin 5 // #define smMin 5
#define smWDay 6 // #define smWDay 6
// #define STOPEvent cbi(TIMSK, TOIE1); cbi(UCSRB, RXCIE); // #define STOPEvent cbi(TIMSK, TOIE1); cbi(UCSRB, RXCIE);
// #define STARTEvent sbi(TIMSK, TOIE1); sbi(UCSRB, RXCIE); // #define STARTEvent sbi(TIMSK, TOIE1); sbi(UCSRB, RXCIE);
extern byte showLog; extern uint8_t showLog;
extern byte showLog2; extern uint8_t showLog2;
#endif // _GLOBALDEF_H_ #endif // _GLOBALDEF_H_

View File

@ -47,102 +47,102 @@
__asm__ __volatile__( \ __asm__ __volatile__( \
"cbi %[vporta_out], 6;" ::[vporta_out] "I"(_SFR_IO_ADDR(VPORTA_OUT))); "cbi %[vporta_out], 6;" ::[vporta_out] "I"(_SFR_IO_ADDR(VPORTA_OUT)));
byte CD_ID_1; uint8_t CD_ID_1;
byte CD_ID_2; uint8_t CD_ID_2;
byte HU_ID_1; uint8_t HU_ID_1;
byte HU_ID_2; uint8_t HU_ID_2;
byte parity_bit; uint8_t parity_bit;
byte repeatMode; uint8_t repeatMode;
byte randomMode; uint8_t randomMode;
byte playMode; uint8_t playMode;
byte cd_Disc; uint8_t cd_Disc;
byte cd_Track; uint8_t cd_Track;
byte cd_Time_Min; uint8_t cd_Time_Min;
byte cd_Time_Sec; uint8_t cd_Time_Sec;
byte answerReq; uint8_t answerReq;
cd_modes CD_Mode; cd_modes CD_Mode;
byte broadcast; uint8_t broadcast;
byte master1; uint8_t master1;
byte master2; uint8_t master2;
byte slave1; uint8_t slave1;
byte slave2; uint8_t slave2;
byte message_len; uint8_t message_len;
byte message[MAXMSGLEN]; uint8_t message[MAXMSGLEN];
byte data_control; uint8_t data_control;
byte data_len; uint8_t data_len;
byte data[MAXMSGLEN]; uint8_t data[MAXMSGLEN];
// we need check answer (to avclan check) timeout // we need check answer (to avclan check) timeout
// when is more then 1 min, FORCE answer. // when is more then 1 min, FORCE answer.
byte check_timeout; uint8_t check_timeout;
#define SW_ID 0x11 // 11 For my stereo #define SW_ID 0x11 // 11 For my stereo
// commands // commands
const byte stat1[] = {0x4, 0x00, 0x00, 0x01, 0x0A}; const uint8_t stat1[] = {0x4, 0x00, 0x00, 0x01, 0x0A};
const byte stat2[] = {0x4, 0x00, 0x00, 0x01, 0x08}; const uint8_t stat2[] = {0x4, 0x00, 0x00, 0x01, 0x08};
const byte stat3[] = {0x4, 0x00, 0x00, 0x01, 0x0D}; const uint8_t stat3[] = {0x4, 0x00, 0x00, 0x01, 0x0D};
const byte stat4[] = {0x4, 0x00, 0x00, 0x01, 0x0C}; const uint8_t stat4[] = {0x4, 0x00, 0x00, 0x01, 0x0C};
// broadcast // broadcast
const byte lan_stat1[] = {0x3, 0x00, 0x01, 0x0A}; const uint8_t lan_stat1[] = {0x3, 0x00, 0x01, 0x0A};
const byte lan_reg[] = {0x3, SW_ID, 0x01, 0x00}; const uint8_t lan_reg[] = {0x3, SW_ID, 0x01, 0x00};
const byte lan_init[] = {0x3, SW_ID, 0x01, 0x01}; const uint8_t lan_init[] = {0x3, SW_ID, 0x01, 0x01};
const byte lan_check[] = {0x3, SW_ID, 0x01, 0x20}; const uint8_t lan_check[] = {0x3, SW_ID, 0x01, 0x20};
const byte lan_playit[] = {0x4, SW_ID, 0x01, 0x45, 0x63}; const uint8_t lan_playit[] = {0x4, SW_ID, 0x01, 0x45, 0x63};
const byte play_req1[] = {0x4, 0x00, 0x25, 0x63, 0x80}; const uint8_t play_req1[] = {0x4, 0x00, 0x25, 0x63, 0x80};
#ifdef __AVENSIS__ #ifdef __AVENSIS__
const byte play_req2[] = {0x6, 0x00, SW_ID, 0x63, 0x42}; const uint8_t play_req2[] = {0x6, 0x00, SW_ID, 0x63, 0x42};
#else #else
const byte play_req2[] = {0x6, 0x00, SW_ID, 0x63, 0x42, 0x01, 0x00}; const uint8_t play_req2[] = {0x6, 0x00, SW_ID, 0x63, 0x42, 0x01, 0x00};
#endif #endif
const byte play_req3[] = {0x5, 0x00, SW_ID, 0x63, 0x42, 0x41}; const uint8_t play_req3[] = {0x5, 0x00, SW_ID, 0x63, 0x42, 0x41};
const byte stop_req[] = {0x5, 0x00, SW_ID, 0x63, 0x43, 0x01}; const uint8_t stop_req[] = {0x5, 0x00, SW_ID, 0x63, 0x43, 0x01};
const byte stop_req2[] = {0x5, 0x00, SW_ID, 0x63, 0x43, 0x41}; const uint8_t stop_req2[] = {0x5, 0x00, SW_ID, 0x63, 0x43, 0x41};
// answers // answers
const byte CMD_REGISTER[] = {0x1, 0x05, 0x00, 0x01, SW_ID, 0x10, 0x63}; const uint8_t CMD_REGISTER[] = {0x1, 0x05, 0x00, 0x01, SW_ID, 0x10, 0x63};
const byte CMD_STATUS1[] = {0x1, 0x04, 0x00, 0x01, 0x00, 0x1A}; const uint8_t CMD_STATUS1[] = {0x1, 0x04, 0x00, 0x01, 0x00, 0x1A};
const byte CMD_STATUS2[] = {0x1, 0x04, 0x00, 0x01, 0x00, 0x18}; const uint8_t CMD_STATUS2[] = {0x1, 0x04, 0x00, 0x01, 0x00, 0x18};
const byte CMD_STATUS3[] = {0x1, 0x04, 0x00, 0x01, 0x00, 0x1D}; const uint8_t CMD_STATUS3[] = {0x1, 0x04, 0x00, 0x01, 0x00, 0x1D};
const byte CMD_STATUS4[] = {0x1, 0x05, 0x00, 0x01, 0x00, 0x1C, 0x00}; const uint8_t CMD_STATUS4[] = {0x1, 0x05, 0x00, 0x01, 0x00, 0x1C, 0x00};
byte CMD_CHECK[] = {0x1, 0x06, 0x00, 0x01, SW_ID, 0x30, 0x00, 0x00}; uint8_t CMD_CHECK[] = {0x1, 0x06, 0x00, 0x01, SW_ID, 0x30, 0x00, 0x00};
const byte CMD_STATUS5[] = {0x1, 0x05, 0x00, 0x5C, 0x12, 0x53, 0x02}; const uint8_t CMD_STATUS5[] = {0x1, 0x05, 0x00, 0x5C, 0x12, 0x53, 0x02};
const byte CMD_STATUS5A[] = {0x0, 0x05, 0x5C, 0x31, 0xF1, 0x00, 0x00}; const uint8_t CMD_STATUS5A[] = {0x0, 0x05, 0x5C, 0x31, 0xF1, 0x00, 0x00};
const byte CMD_STATUS6[] = {0x1, 0x06, 0x00, 0x5C, 0x32, 0xF0, 0x02, 0x00}; const uint8_t CMD_STATUS6[] = {0x1, 0x06, 0x00, 0x5C, 0x32, 0xF0, 0x02, 0x00};
const byte CMD_PLAY_OK1[] = {0x1, 0x05, 0x00, 0x63, SW_ID, 0x50, 0x01}; const uint8_t CMD_PLAY_OK1[] = {0x1, 0x05, 0x00, 0x63, SW_ID, 0x50, 0x01};
const byte CMD_PLAY_OK2[] = {0x1, 0x05, 0x00, 0x63, SW_ID, 0x52, 0x01}; const uint8_t CMD_PLAY_OK2[] = {0x1, 0x05, 0x00, 0x63, SW_ID, 0x52, 0x01};
const byte CMD_PLAY_OK3[] = {0x0, 0x0B, 0x63, 0x31, 0xF1, 0x01, 0x00, const uint8_t CMD_PLAY_OK3[] = {0x0, 0x0B, 0x63, 0x31, 0xF1, 0x01, 0x00,
0x01, 0xFF, 0xFF, 0xFF, 0x00, 0x80}; 0x01, 0xFF, 0xFF, 0xFF, 0x00, 0x80};
byte CMD_PLAY_OK4[] = {0x0, 0x0B, 0x63, 0x31, 0xF1, 0x01, 0x28, uint8_t CMD_PLAY_OK4[] = {0x0, 0x0B, 0x63, 0x31, 0xF1, 0x01, 0x28,
0x00, 0x00, 0x00, 0x00, 0x00, 0x80}; 0x00, 0x00, 0x00, 0x00, 0x00, 0x80};
const byte CMD_STOP1[] = {0x1, 0x05, 0x00, 0x63, SW_ID, 0x53, 0x01}; const uint8_t CMD_STOP1[] = {0x1, 0x05, 0x00, 0x63, SW_ID, 0x53, 0x01};
byte CMD_STOP2[] = {0x0, 0x0B, 0x63, 0x31, 0xF1, 0x00, 0x30, uint8_t CMD_STOP2[] = {0x0, 0x0B, 0x63, 0x31, 0xF1, 0x00, 0x30,
0x00, 0x00, 0x00, 0x00, 0x00, 0x80}; 0x00, 0x00, 0x00, 0x00, 0x00, 0x80};
const byte CMD_BEEP[] = {0x1, 0x05, 0x00, 0x63, 0x29, 0x60, 0x02}; const uint8_t CMD_BEEP[] = {0x1, 0x05, 0x00, 0x63, 0x29, 0x60, 0x02};
void AVC_HoldLine() { void AVC_HoldLine() {
STOPEvent; STOPEvent;
// wait for free line // wait for free line
byte line_busy = 1; uint8_t line_busy = 1;
TCB1.CNT = 0; TCB1.CNT = 0;
do { do {
@ -171,8 +171,7 @@ void AVC_ReleaseLine() {
void AVCLan_Init() { void AVCLan_Init() {
PORTA.PIN6CTRL = PORT_ISC_INPUT_DISABLE_gc; // Disable input buffer; PORTA.PIN6CTRL = PORT_ISC_INPUT_DISABLE_gc; // Disable input buffer;
// recommended when using AC PORTA.PIN7CTRL = PORT_ISC_INPUT_DISABLE_gc; // recommended when using AC
PORTA.PIN7CTRL = PORT_ISC_INPUT_DISABLE_gc;
// Pull-ups are disabled by default // Pull-ups are disabled by default
VPORTA.DIR &= ~(PIN6_bm | PIN7_bm); // Zero pin 6 and 7 to set as input VPORTA.DIR &= ~(PIN6_bm | PIN7_bm); // Zero pin 6 and 7 to set as input
@ -200,8 +199,8 @@ void AVCLan_Init() {
CD_Mode = stStop; CD_Mode = stStop;
} }
byte AVCLan_Read_Byte(byte length) { uint8_t AVCLan_Read_uint8_t(uint8_t length) {
byte bite = 0; uint8_t bite = 0;
while (1) { while (1) {
while (INPUT_IS_CLEAR) {} while (INPUT_IS_CLEAR) {}
@ -230,7 +229,7 @@ void set_AVC_logic_for(uint8_t val, uint16_t period) {
TCB1_INTFLAGS = 1; TCB1_INTFLAGS = 1;
} }
byte AVCLan_Send_StartBit() { uint8_t AVCLan_Send_StartBit() {
set_AVC_logic_for(1, 1328); // 166 us @ 125 ns tick (for F_CPU = 16MHz) set_AVC_logic_for(1, 1328); // 166 us @ 125 ns tick (for F_CPU = 16MHz)
set_AVC_logic_for(0, 152); // 19 us @ 125 ns tick (for F_CPU = 16MHz) set_AVC_logic_for(0, 152); // 19 us @ 125 ns tick (for F_CPU = 16MHz)
@ -247,7 +246,7 @@ void AVCLan_Send_Bit0() {
set_AVC_logic_for(0, 44); // 5.5 us @ 125 ns tick (for F_CPU = 16MHz) set_AVC_logic_for(0, 44); // 5.5 us @ 125 ns tick (for F_CPU = 16MHz)
} }
byte AVCLan_Read_ACK() { uint8_t AVCLan_Read_ACK() {
set_AVC_logic_for(1, 152); // 34 us @ 125 ns tick (for F_CPU = 16MHz) set_AVC_logic_for(1, 152); // 34 us @ 125 ns tick (for F_CPU = 16MHz)
AVC_SET_LOGICAL_0(); // Replace with AVC_ReleaseLine? AVC_SET_LOGICAL_0(); // Replace with AVC_ReleaseLine?
AVC_OUT_DIS(); // switch to read mode AVC_OUT_DIS(); // switch to read mode
@ -267,7 +266,7 @@ byte AVCLan_Read_ACK() {
return 0; return 0;
} }
byte AVCLan_Send_ACK() { uint8_t AVCLan_Send_ACK() {
TCB1.CNT = 0; TCB1.CNT = 0;
while (INPUT_IS_CLEAR) { while (INPUT_IS_CLEAR) {
if (TCB1.CNT >= 900) if (TCB1.CNT >= 900)
@ -284,8 +283,8 @@ byte AVCLan_Send_ACK() {
return 1; return 1;
} }
byte AVCLan_Send_Byte(byte bite, byte len) { uint8_t AVCLan_Send_uint8_t(uint8_t bite, uint8_t len) {
byte b; uint8_t b;
if (len == 8) { if (len == 8) {
b = bite; b = bite;
} else { } else {
@ -308,7 +307,7 @@ byte AVCLan_Send_Byte(byte bite, byte len) {
} }
} }
byte AVCLan_Send_ParityBit() { uint8_t AVCLan_Send_ParityBit() {
if ((parity_bit & 1) != 0) { if ((parity_bit & 1) != 0) {
AVCLan_Send_Bit1(); AVCLan_Send_Bit1();
// parity_bit++; // parity_bit++;
@ -319,10 +318,10 @@ byte AVCLan_Send_ParityBit() {
return 1; return 1;
} }
byte CheckCmd(byte *cmd) { uint8_t CheckCmd(uint8_t *cmd) {
byte i; uint8_t i;
byte *c; uint8_t *c;
byte l; uint8_t l;
c = cmd; c = cmd;
l = *c++; l = *c++;
@ -335,11 +334,11 @@ byte CheckCmd(byte *cmd) {
return 1; return 1;
} }
byte AVCLan_Read_Message() { uint8_t AVCLan_Read_Message() {
STOPEvent; // disable timer1 interrupt STOPEvent; // disable timer1 interrupt
byte i; uint8_t i;
byte for_me = 0; uint8_t for_me = 0;
// RS232_Print("$ "); // RS232_Print("$ ");
// TCCR1B |= (1 << CS11)|(1 << CS10); // Timer1 prescaler at 64 // TCCR1B |= (1 << CS11)|(1 << CS10); // Timer1 prescaler at 64
@ -362,22 +361,22 @@ byte AVCLan_Read_Message() {
// RS232_Print("LAN>T2\n"); // RS232_Print("LAN>T2\n");
// return 0; // return 0;
// } // }
AVCLan_Read_Byte(1); AVCLan_Read_uint8_t(1);
broadcast = AVCLan_Read_Byte(1); broadcast = AVCLan_Read_uint8_t(1);
parity_bit = 0; parity_bit = 0;
master1 = AVCLan_Read_Byte(4); master1 = AVCLan_Read_uint8_t(4);
master2 = AVCLan_Read_Byte(8); master2 = AVCLan_Read_uint8_t(8);
if ((parity_bit & 1) != AVCLan_Read_Byte(1)) { if ((parity_bit & 1) != AVCLan_Read_uint8_t(1)) {
STARTEvent; STARTEvent;
return 0; return 0;
} }
parity_bit = 0; parity_bit = 0;
slave1 = AVCLan_Read_Byte(4); slave1 = AVCLan_Read_uint8_t(4);
slave2 = AVCLan_Read_Byte(8); slave2 = AVCLan_Read_uint8_t(8);
if ((parity_bit & 1) != AVCLan_Read_Byte(1)) { if ((parity_bit & 1) != AVCLan_Read_uint8_t(1)) {
STARTEvent; STARTEvent;
return 0; return 0;
} }
@ -389,29 +388,29 @@ byte AVCLan_Read_Message() {
if (for_me) if (for_me)
AVCLan_Send_ACK(); AVCLan_Send_ACK();
else else
AVCLan_Read_Byte(1); AVCLan_Read_uint8_t(1);
parity_bit = 0; parity_bit = 0;
AVCLan_Read_Byte(4); // control - always 0xF AVCLan_Read_uint8_t(4); // control - always 0xF
if ((parity_bit & 1) != AVCLan_Read_Byte(1)) { if ((parity_bit & 1) != AVCLan_Read_uint8_t(1)) {
STARTEvent; STARTEvent;
return 0; return 0;
} }
if (for_me) if (for_me)
AVCLan_Send_ACK(); AVCLan_Send_ACK();
else else
AVCLan_Read_Byte(1); AVCLan_Read_uint8_t(1);
parity_bit = 0; parity_bit = 0;
message_len = AVCLan_Read_Byte(8); message_len = AVCLan_Read_uint8_t(8);
if ((parity_bit & 1) != AVCLan_Read_Byte(1)) { if ((parity_bit & 1) != AVCLan_Read_uint8_t(1)) {
STARTEvent; STARTEvent;
return 0; return 0;
} }
if (for_me) if (for_me)
AVCLan_Send_ACK(); AVCLan_Send_ACK();
else else
AVCLan_Read_Byte(1); AVCLan_Read_uint8_t(1);
if (message_len > MAXMSGLEN) { if (message_len > MAXMSGLEN) {
// RS232_Print("LAN> Command error"); // RS232_Print("LAN> Command error");
@ -421,15 +420,15 @@ byte 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_Byte(8); message[i] = AVCLan_Read_uint8_t(8);
if ((parity_bit & 1) != AVCLan_Read_Byte(1)) { if ((parity_bit & 1) != AVCLan_Read_uint8_t(1)) {
STARTEvent; STARTEvent;
return 0; return 0;
} }
if (for_me) { if (for_me) {
AVCLan_Send_ACK(); AVCLan_Send_ACK();
} else { } else {
AVCLan_Read_Byte(1); AVCLan_Read_uint8_t(1);
} }
} }
@ -440,65 +439,65 @@ byte AVCLan_Read_Message() {
if (for_me) { if (for_me) {
if (CheckCmd((byte *)stat1)) { if (CheckCmd((uint8_t *)stat1)) {
answerReq = cmStatus1; answerReq = cmStatus1;
return 1; return 1;
} }
if (CheckCmd((byte *)stat2)) { if (CheckCmd((uint8_t *)stat2)) {
answerReq = cmStatus2; answerReq = cmStatus2;
return 1; return 1;
} }
if (CheckCmd((byte *)stat3)) { if (CheckCmd((uint8_t *)stat3)) {
answerReq = cmStatus3; answerReq = cmStatus3;
return 1; return 1;
} }
if (CheckCmd((byte *)stat4)) { if (CheckCmd((uint8_t *)stat4)) {
answerReq = cmStatus4; answerReq = cmStatus4;
return 1; return 1;
} }
// if (CheckCmd((byte*)stat5)) { answerReq = cmStatus5; return 1; } // if (CheckCmd((uint8_t*)stat5)) { answerReq = cmStatus5; return 1; }
if (CheckCmd((byte *)play_req1)) { if (CheckCmd((uint8_t *)play_req1)) {
answerReq = cmPlayReq1; answerReq = cmPlayReq1;
return 1; return 1;
} }
if (CheckCmd((byte *)play_req2)) { if (CheckCmd((uint8_t *)play_req2)) {
answerReq = cmPlayReq2; answerReq = cmPlayReq2;
return 1; return 1;
} }
if (CheckCmd((byte *)play_req3)) { if (CheckCmd((uint8_t *)play_req3)) {
answerReq = cmPlayReq3; answerReq = cmPlayReq3;
return 1; return 1;
} }
if (CheckCmd((byte *)stop_req)) { if (CheckCmd((uint8_t *)stop_req)) {
answerReq = cmStopReq; answerReq = cmStopReq;
return 1; return 1;
} }
if (CheckCmd((byte *)stop_req2)) { if (CheckCmd((uint8_t *)stop_req2)) {
answerReq = cmStopReq2; answerReq = cmStopReq2;
return 1; return 1;
} }
} else { // broadcast check } else { // broadcast check
if (CheckCmd((byte *)lan_playit)) { if (CheckCmd((uint8_t *)lan_playit)) {
answerReq = cmPlayIt; answerReq = cmPlayIt;
return 1; return 1;
} }
if (CheckCmd((byte *)lan_check)) { if (CheckCmd((uint8_t *)lan_check)) {
answerReq = cmCheck; answerReq = cmCheck;
CMD_CHECK[6] = message[3]; CMD_CHECK[6] = message[3];
return 1; return 1;
} }
if (CheckCmd((byte *)lan_reg)) { if (CheckCmd((uint8_t *)lan_reg)) {
answerReq = cmRegister; answerReq = cmRegister;
return 1; return 1;
} }
if (CheckCmd((byte *)lan_init)) { if (CheckCmd((uint8_t *)lan_init)) {
answerReq = cmInit; answerReq = cmInit;
return 1; return 1;
} }
if (CheckCmd((byte *)lan_stat1)) { if (CheckCmd((uint8_t *)lan_stat1)) {
answerReq = cmStatus1; answerReq = cmStatus1;
return 1; return 1;
} }
@ -507,13 +506,13 @@ byte AVCLan_Read_Message() {
return 1; return 1;
} }
byte AVCLan_SendData() { uint8_t AVCLan_SendData() {
byte i; uint8_t i;
STOPEvent; STOPEvent;
// wait for free line // wait for free line
byte line_busy = 1; uint8_t line_busy = 1;
TCB1.CNT = 0; TCB1.CNT = 0;
do { do {
@ -529,15 +528,15 @@ byte AVCLan_SendData() {
AVC_OUT_EN(); AVC_OUT_EN();
AVCLan_Send_StartBit(); AVCLan_Send_StartBit();
AVCLan_Send_Byte(0x1, 1); // regular communication AVCLan_Send_uint8_t(0x1, 1); // regular communication
parity_bit = 0; parity_bit = 0;
AVCLan_Send_Byte(CD_ID_1, 4); // CD Changer ID as master AVCLan_Send_uint8_t(CD_ID_1, 4); // CD Changer ID as master
AVCLan_Send_Byte(CD_ID_2, 8); AVCLan_Send_uint8_t(CD_ID_2, 8);
AVCLan_Send_ParityBit(); AVCLan_Send_ParityBit();
AVCLan_Send_Byte(HU_ID_1, 4); // HeadUnit ID as slave AVCLan_Send_uint8_t(HU_ID_1, 4); // HeadUnit ID as slave
AVCLan_Send_Byte(HU_ID_2, 8); AVCLan_Send_uint8_t(HU_ID_2, 8);
AVCLan_Send_ParityBit(); AVCLan_Send_ParityBit();
@ -548,7 +547,7 @@ byte AVCLan_SendData() {
return 1; return 1;
} }
AVCLan_Send_Byte(0xF, 4); // 0xf - control -> COMMAND WRITE AVCLan_Send_uint8_t(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();
@ -557,7 +556,7 @@ byte AVCLan_SendData() {
return 2; return 2;
} }
AVCLan_Send_Byte(data_len, 8); // data length AVCLan_Send_uint8_t(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();
@ -567,12 +566,12 @@ byte AVCLan_SendData() {
} }
for (i = 0; i < data_len; i++) { for (i = 0; i < data_len; i++) {
AVCLan_Send_Byte(data[i], 8); // data byte AVCLan_Send_uint8_t(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();
STARTEvent; STARTEvent;
RS232_Print("Error ACK 4 (Data Byte: "); RS232_Print("Error ACK 4 (Data uint8_t: ");
RS232_PrintDec(i); RS232_PrintDec(i);
RS232_Print(")\n"); RS232_Print(")\n");
return 4; return 4;
@ -588,13 +587,13 @@ byte AVCLan_SendData() {
return 0; return 0;
} }
byte AVCLan_SendDataBroadcast() { uint8_t AVCLan_SendDataBroadcast() {
byte i; uint8_t i;
STOPEvent; STOPEvent;
// wait for free line // wait for free line
byte line_busy = 1; uint8_t line_busy = 1;
TCB1.CNT = 0; TCB1.CNT = 0;
do { do {
@ -609,28 +608,28 @@ byte AVCLan_SendDataBroadcast() {
AVC_OUT_EN(); AVC_OUT_EN();
AVCLan_Send_StartBit(); AVCLan_Send_StartBit();
AVCLan_Send_Byte(0x0, 1); // broadcast AVCLan_Send_uint8_t(0x0, 1); // broadcast
parity_bit = 0; parity_bit = 0;
AVCLan_Send_Byte(CD_ID_1, 4); // CD Changer ID as master AVCLan_Send_uint8_t(CD_ID_1, 4); // CD Changer ID as master
AVCLan_Send_Byte(CD_ID_2, 8); AVCLan_Send_uint8_t(CD_ID_2, 8);
AVCLan_Send_ParityBit(); AVCLan_Send_ParityBit();
AVCLan_Send_Byte(0x1, 4); // all audio devices AVCLan_Send_uint8_t(0x1, 4); // all audio devices
AVCLan_Send_Byte(0xFF, 8); AVCLan_Send_uint8_t(0xFF, 8);
AVCLan_Send_ParityBit(); AVCLan_Send_ParityBit();
AVCLan_Send_Bit1(); AVCLan_Send_Bit1();
AVCLan_Send_Byte(0xF, 4); // 0xf - control -> COMMAND WRITE AVCLan_Send_uint8_t(0xF, 4); // 0xf - control -> COMMAND WRITE
AVCLan_Send_ParityBit(); AVCLan_Send_ParityBit();
AVCLan_Send_Bit1(); AVCLan_Send_Bit1();
AVCLan_Send_Byte(data_len, 8); // data lenght AVCLan_Send_uint8_t(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_Byte(data[i], 8); // data byte AVCLan_Send_uint8_t(data[i], 8); // data uint8_t
AVCLan_Send_ParityBit(); AVCLan_Send_ParityBit();
AVCLan_Send_Bit1(); AVCLan_Send_Bit1();
} }
@ -642,10 +641,10 @@ byte AVCLan_SendDataBroadcast() {
return 0; return 0;
} }
byte AVCLan_SendAnswerFrame(byte *cmd) { uint8_t AVCLan_SendAnswerFrame(uint8_t *cmd) {
byte i; uint8_t i;
byte *c; uint8_t *c;
byte b; uint8_t b;
c = cmd; c = cmd;
@ -661,9 +660,9 @@ byte AVCLan_SendAnswerFrame(byte *cmd) {
return AVCLan_SendDataBroadcast(); return AVCLan_SendDataBroadcast();
} }
byte AVCLan_SendMyData(byte *data_tmp, byte s_len) { uint8_t AVCLan_SendMyData(uint8_t *data_tmp, uint8_t s_len) {
byte i; uint8_t i;
byte *c; uint8_t *c;
c = data_tmp; c = data_tmp;
@ -675,9 +674,9 @@ byte AVCLan_SendMyData(byte *data_tmp, byte s_len) {
return AVCLan_SendData(); return AVCLan_SendData();
} }
byte AVCLan_SendMyDataBroadcast(byte *data_tmp, byte s_len) { uint8_t AVCLan_SendMyDataBroadcast(uint8_t *data_tmp, uint8_t s_len) {
byte i; uint8_t i;
byte *c; uint8_t *c;
c = data_tmp; c = data_tmp;
@ -689,60 +688,60 @@ byte AVCLan_SendMyDataBroadcast(byte *data_tmp, byte s_len) {
return AVCLan_SendDataBroadcast(); return AVCLan_SendDataBroadcast();
} }
byte AVCLan_SendInitCommands() { uint8_t AVCLan_SendInitCommands() {
byte r; uint8_t r;
const byte c1[] = {0x0, 0x0B, 0x63, 0x31, 0xF1, 0x00, 0x80, const uint8_t c1[] = {0x0, 0x0B, 0x63, 0x31, 0xF1, 0x00, 0x80,
0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x80}; 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x80};
const byte c2[] = {0x0, 0x0A, 0x63, 0x31, 0xF3, 0x00, const uint8_t c2[] = {0x0, 0x0A, 0x63, 0x31, 0xF3, 0x00,
0x3F, 0x00, 0x00, 0x00, 0x00, 0x02}; 0x3F, 0x00, 0x00, 0x00, 0x00, 0x02};
const byte c3[] = {0x0, 0x0A, 0x63, 0x31, 0xF3, 0x00, const uint8_t c3[] = {0x0, 0x0A, 0x63, 0x31, 0xF3, 0x00,
0x3F, 0x00, 0x01, 0x00, 0x01, 0x02}; 0x3F, 0x00, 0x01, 0x00, 0x01, 0x02};
const byte c4[] = {0x0, 0x0A, 0x63, 0x31, 0xF3, 0x00, const uint8_t c4[] = {0x0, 0x0A, 0x63, 0x31, 0xF3, 0x00,
0x3D, 0x00, 0x01, 0x00, 0x01, 0x02}; 0x3D, 0x00, 0x01, 0x00, 0x01, 0x02};
const byte c5[] = {0x0, 0x0A, 0x63, 0x31, 0xF3, 0x00, const uint8_t c5[] = {0x0, 0x0A, 0x63, 0x31, 0xF3, 0x00,
0x39, 0x00, 0x01, 0x00, 0x01, 0x02}; 0x39, 0x00, 0x01, 0x00, 0x01, 0x02};
const byte c6[] = {0x0, 0x0A, 0x63, 0x31, 0xF3, 0x00, const uint8_t c6[] = {0x0, 0x0A, 0x63, 0x31, 0xF3, 0x00,
0x31, 0x00, 0x01, 0x00, 0x01, 0x02}; 0x31, 0x00, 0x01, 0x00, 0x01, 0x02};
const byte c7[] = {0x0, 0x0A, 0x63, 0x31, 0xF3, 0x00, const uint8_t c7[] = {0x0, 0x0A, 0x63, 0x31, 0xF3, 0x00,
0x21, 0x00, 0x01, 0x00, 0x01, 0x02}; 0x21, 0x00, 0x01, 0x00, 0x01, 0x02};
const byte c8[] = {0x0, 0x0B, 0x63, 0x31, 0xF1, 0x00, 0x90, const uint8_t c8[] = {0x0, 0x0B, 0x63, 0x31, 0xF1, 0x00, 0x90,
0x01, 0xFF, 0xFF, 0xFF, 0x00, 0x80}; 0x01, 0xFF, 0xFF, 0xFF, 0x00, 0x80};
const byte c9[] = {0x0, 0x0A, 0x63, 0x31, 0xF3, 0x00, const uint8_t c9[] = {0x0, 0x0A, 0x63, 0x31, 0xF3, 0x00,
0x01, 0x00, 0x01, 0x00, 0x01, 0x02}; 0x01, 0x00, 0x01, 0x00, 0x01, 0x02};
const byte cA[] = {0x0, 0x0B, 0x63, 0x31, 0xF1, 0x00, 0x30, const uint8_t cA[] = {0x0, 0x0B, 0x63, 0x31, 0xF1, 0x00, 0x30,
0x01, 0xFF, 0xFF, 0xFF, 0x00, 0x80}; 0x01, 0xFF, 0xFF, 0xFF, 0x00, 0x80};
r = AVCLan_SendAnswerFrame((byte *)c1); r = AVCLan_SendAnswerFrame((uint8_t *)c1);
if (!r) if (!r)
r = AVCLan_SendAnswerFrame((byte *)c2); r = AVCLan_SendAnswerFrame((uint8_t *)c2);
if (!r) if (!r)
r = AVCLan_SendAnswerFrame((byte *)c3); r = AVCLan_SendAnswerFrame((uint8_t *)c3);
if (!r) if (!r)
r = AVCLan_SendAnswerFrame((byte *)c4); r = AVCLan_SendAnswerFrame((uint8_t *)c4);
if (!r) if (!r)
r = AVCLan_SendAnswerFrame((byte *)c5); r = AVCLan_SendAnswerFrame((uint8_t *)c5);
if (!r) if (!r)
r = AVCLan_SendAnswerFrame((byte *)c6); r = AVCLan_SendAnswerFrame((uint8_t *)c6);
if (!r) if (!r)
r = AVCLan_SendAnswerFrame((byte *)c7); r = AVCLan_SendAnswerFrame((uint8_t *)c7);
if (!r) if (!r)
r = AVCLan_SendAnswerFrame((byte *)c8); r = AVCLan_SendAnswerFrame((uint8_t *)c8);
if (!r) if (!r)
r = AVCLan_SendAnswerFrame((byte *)c9); r = AVCLan_SendAnswerFrame((uint8_t *)c9);
if (!r) if (!r)
r = AVCLan_SendAnswerFrame((byte *)cA); r = AVCLan_SendAnswerFrame((uint8_t *)cA);
// const byte c1[] = { 0x0, 0x0B, 0x63, 0x31, 0xF1, 0x00, 0x80, // const uint8_t c1[] = { 0x0, 0x0B, 0x63, 0x31, 0xF1, 0x00, 0x80,
// 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x80 }; r = // 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x80 }; r =
// AVCLan_SendAnswerFrame((byte*)c1); // AVCLan_SendAnswerFrame((uint8_t*)c1);
return r; return r;
} }
void AVCLan_Send_Status() { void AVCLan_Send_Status() {
// disc track t_min // disc track t_min
// t_sec // t_sec
byte STATUS[] = {0x0, 0x0B, 0x63, 0x31, 0xF1, 0x01, 0x10, uint8_t STATUS[] = {0x0, 0x0B, 0x63, 0x31, 0xF1, 0x01, 0x10,
0x01, 0x01, 0x00, 0x00, 0x00, 0x80}; 0x01, 0x01, 0x00, 0x00, 0x00, 0x80};
STATUS[7] = cd_Disc; STATUS[7] = cd_Disc;
@ -752,47 +751,47 @@ void AVCLan_Send_Status() {
STATUS[11] = 0; STATUS[11] = 0;
AVCLan_SendAnswerFrame((byte *)STATUS); AVCLan_SendAnswerFrame((uint8_t *)STATUS);
} }
byte AVCLan_SendAnswer() { uint8_t AVCLan_SendAnswer() {
byte r = 0; uint8_t r = 0;
switch (answerReq) { switch (answerReq) {
case cmStatus1: case cmStatus1:
r = AVCLan_SendAnswerFrame((byte *)CMD_STATUS1); r = AVCLan_SendAnswerFrame((uint8_t *)CMD_STATUS1);
break; break;
case cmStatus2: case cmStatus2:
r = AVCLan_SendAnswerFrame((byte *)CMD_STATUS2); r = AVCLan_SendAnswerFrame((uint8_t *)CMD_STATUS2);
break; break;
case cmStatus3: case cmStatus3:
r = AVCLan_SendAnswerFrame((byte *)CMD_STATUS3); r = AVCLan_SendAnswerFrame((uint8_t *)CMD_STATUS3);
break; break;
case cmStatus4: case cmStatus4:
r = AVCLan_SendAnswerFrame((byte *)CMD_STATUS4); r = AVCLan_SendAnswerFrame((uint8_t *)CMD_STATUS4);
break; break;
case cmRegister: case cmRegister:
r = AVCLan_SendAnswerFrame((byte *)CMD_REGISTER); r = AVCLan_SendAnswerFrame((uint8_t *)CMD_REGISTER);
break; break;
case cmInit: // RS232_Print("INIT\n"); case cmInit: // RS232_Print("INIT\n");
r = AVCLan_SendInitCommands(); r = AVCLan_SendInitCommands();
break; break;
case cmCheck: case cmCheck:
r = AVCLan_SendAnswerFrame((byte *)CMD_CHECK); r = AVCLan_SendAnswerFrame((uint8_t *)CMD_CHECK);
check_timeout = 0; check_timeout = 0;
CMD_CHECK[6]++; CMD_CHECK[6]++;
RS232_Print("AVCCHK\n"); RS232_Print("AVCCHK\n");
break; break;
case cmPlayReq1: case cmPlayReq1:
playMode = 0; playMode = 0;
r = AVCLan_SendAnswerFrame((byte *)CMD_PLAY_OK1); r = AVCLan_SendAnswerFrame((uint8_t *)CMD_PLAY_OK1);
break; break;
case cmPlayReq2: case cmPlayReq2:
case cmPlayReq3: case cmPlayReq3:
playMode = 0; playMode = 0;
r = AVCLan_SendAnswerFrame((byte *)CMD_PLAY_OK2); r = AVCLan_SendAnswerFrame((uint8_t *)CMD_PLAY_OK2);
if (!r) if (!r)
r = AVCLan_SendAnswerFrame((byte *)CMD_PLAY_OK3); r = AVCLan_SendAnswerFrame((uint8_t *)CMD_PLAY_OK3);
CD_Mode = stPlay; CD_Mode = stPlay;
break; break;
case cmPlayIt: case cmPlayIt:
@ -802,7 +801,7 @@ byte AVCLan_SendAnswer() {
CMD_PLAY_OK4[8] = cd_Track; CMD_PLAY_OK4[8] = cd_Track;
CMD_PLAY_OK4[9] = cd_Time_Min; CMD_PLAY_OK4[9] = cd_Time_Min;
CMD_PLAY_OK4[10] = cd_Time_Sec; CMD_PLAY_OK4[10] = cd_Time_Sec;
r = AVCLan_SendAnswerFrame((byte *)CMD_PLAY_OK4); r = AVCLan_SendAnswerFrame((uint8_t *)CMD_PLAY_OK4);
if (!r) if (!r)
AVCLan_Send_Status(); AVCLan_Send_Status();
CD_Mode = stPlay; CD_Mode = stPlay;
@ -812,15 +811,15 @@ byte AVCLan_SendAnswer() {
CD_Mode = stStop; CD_Mode = stStop;
playMode = 0; playMode = 0;
r = AVCLan_SendAnswerFrame((byte *)CMD_STOP1); r = AVCLan_SendAnswerFrame((uint8_t *)CMD_STOP1);
CMD_STOP2[7] = cd_Disc; CMD_STOP2[7] = cd_Disc;
CMD_STOP2[8] = cd_Track; CMD_STOP2[8] = cd_Track;
CMD_STOP2[9] = cd_Time_Min; CMD_STOP2[9] = cd_Time_Min;
CMD_STOP2[10] = cd_Time_Sec; CMD_STOP2[10] = cd_Time_Sec;
r = AVCLan_SendAnswerFrame((byte *)CMD_STOP2); r = AVCLan_SendAnswerFrame((uint8_t *)CMD_STOP2);
break; break;
case cmBeep: case cmBeep:
AVCLan_SendAnswerFrame((byte *)CMD_BEEP); AVCLan_SendAnswerFrame((uint8_t *)CMD_BEEP);
break; break;
} }
@ -830,14 +829,14 @@ byte AVCLan_SendAnswer() {
void AVCLan_Register() { void AVCLan_Register() {
RS232_Print("REG_ST\n"); RS232_Print("REG_ST\n");
AVCLan_SendAnswerFrame((byte *)CMD_REGISTER); AVCLan_SendAnswerFrame((uint8_t *)CMD_REGISTER);
RS232_Print("REG_END\n"); RS232_Print("REG_END\n");
// AVCLan_Command( cmRegister ); // AVCLan_Command( cmRegister );
AVCLan_Command(cmInit); AVCLan_Command(cmInit);
} }
byte AVCLan_Command(byte command) { uint8_t AVCLan_Command(uint8_t command) {
byte r; uint8_t r;
answerReq = command; answerReq = command;
r = AVCLan_SendAnswer(); r = AVCLan_SendAnswer();
@ -851,7 +850,7 @@ byte AVCLan_Command(byte command) {
/* Increment packed 2-digit BCD number. /* Increment packed 2-digit BCD number.
WARNING: Overflow behavior is incorrect (e.g. `incBCD(0x99) != 0x00`) */ WARNING: Overflow behavior is incorrect (e.g. `incBCD(0x99) != 0x00`) */
byte incBCD(byte data) { uint8_t incBCD(uint8_t data) {
if ((data & 0x9) == 0x9) if ((data & 0x9) == 0x9)
return (data + 7); return (data + 7);
@ -878,7 +877,7 @@ void ShowInMessage() {
RS232_PrintHex8(slave2); RS232_PrintHex8(slave2);
RS232_Print("| "); RS232_Print("| ");
byte i; uint8_t i;
for (i = 0; i < message_len; i++) { for (i = 0; i < message_len; i++) {
RS232_PrintHex8(message[i]); RS232_PrintHex8(message[i]);
RS232_Print(" "); RS232_Print(" ");
@ -889,7 +888,7 @@ void ShowInMessage() {
} }
void ShowOutMessage() { void ShowOutMessage() {
byte i; uint8_t i;
AVC_HoldLine(); AVC_HoldLine();
@ -904,13 +903,13 @@ void ShowOutMessage() {
} }
#ifdef SOFTWARE_DEBUG #ifdef SOFTWARE_DEBUG
word temp_b[100]; uint16_t temp_b[100];
void AVCLan_Measure() { void AVCLan_Measure() {
STOPEvent; STOPEvent;
// word tmp, tmp1, tmp2, bit0, bit1; // uint16_t tmp, tmp1, tmp2, bit0, bit1;
byte n = 0; uint8_t n = 0;
cbi(TCCR1B, CS12); cbi(TCCR1B, CS12);
TCCR1B = _BV(CS10); TCCR1B = _BV(CS10);
@ -961,7 +960,7 @@ void AVCLan_Measure() {
n += 10; n += 10;
} }
for (byte i = 0; i < 100; i++) { for (uint8_t i = 0; i < 100; i++) {
itoa(temp_b[i], str); itoa(temp_b[i], str);
if (i & 1) { if (i & 1) {
RS232_Print("High,"); RS232_Print("High,");
@ -984,7 +983,7 @@ void AVCLan_Measure() {
void SetHighLow() { void SetHighLow() {
AVC_OUT_EN(); AVC_OUT_EN();
sbi(TCCR1B, CS10); sbi(TCCR1B, CS10);
word n = 60000; uint16_t n = 60000;
TCNT1 = 0; TCNT1 = 0;
AVC_SET_LOGICAL_1(); AVC_SET_LOGICAL_1();
while (TCNT1 < n) {} while (TCNT1 < n) {}

View File

@ -49,11 +49,11 @@ void AVC_ReleaseLine();
#define MAXMSGLEN 32 #define MAXMSGLEN 32
// Head Unid ID // Head Unid ID
extern byte HU_ID_1; // 0x01 extern uint8_t HU_ID_1; // 0x01
extern byte HU_ID_2; // 0x40 extern uint8_t HU_ID_2; // 0x40
extern byte CD_ID_1; // 0x03 extern uint8_t CD_ID_1; // 0x03
extern byte CD_ID_2; // 0x60 extern uint8_t CD_ID_2; // 0x60
// DVD CHANGER // DVD CHANGER
// #define CD_ID_1 0x02 // #define CD_ID_1 0x02
@ -88,41 +88,41 @@ extern byte CD_ID_2; // 0x60
typedef enum { stStop = 0, stPlay = 1 } cd_modes; typedef enum { stStop = 0, stPlay = 1 } cd_modes;
extern cd_modes CD_Mode; extern cd_modes CD_Mode;
extern byte broadcast; extern uint8_t broadcast;
extern byte master1; extern uint8_t master1;
extern byte master2; extern uint8_t master2;
extern byte slave1; extern uint8_t slave1;
extern byte slave2; extern uint8_t slave2;
extern byte message_len; extern uint8_t message_len;
extern byte message[MAXMSGLEN]; extern uint8_t message[MAXMSGLEN];
extern byte data_control; extern uint8_t data_control;
extern byte data_len; extern uint8_t data_len;
extern byte data[MAXMSGLEN]; extern uint8_t data[MAXMSGLEN];
byte AVCLan_Read_Message(); uint8_t AVCLan_Read_Message();
void AVCLan_Send_Status(); void AVCLan_Send_Status();
void AVCLan_Init(); void AVCLan_Init();
void AVCLan_Register(); void AVCLan_Register();
byte AVCLan_SendData(); uint8_t AVCLan_SendData();
byte AVCLan_SendAnswer(); uint8_t AVCLan_SendAnswer();
byte AVCLan_SendDataBroadcast(); uint8_t AVCLan_SendDataBroadcast();
byte AVCLan_Command(byte command); uint8_t AVCLan_Command(uint8_t command);
byte incBCD(byte data); uint8_t incBCD(uint8_t data);
extern byte check_timeout; extern uint8_t check_timeout;
extern byte cd_Disc; extern uint8_t cd_Disc;
extern byte cd_Track; extern uint8_t cd_Track;
extern byte cd_Time_Min; extern uint8_t cd_Time_Min;
extern byte cd_Time_Sec; extern uint8_t cd_Time_Sec;
extern byte playMode; extern uint8_t playMode;
byte AVCLan_SendMyData(byte *data_tmp, byte s_len); uint8_t AVCLan_SendMyData(uint8_t *data_tmp, uint8_t s_len);
byte AVCLan_SendMyDataBroadcast(byte *data_tmp, byte s_len); uint8_t AVCLan_SendMyDataBroadcast(uint8_t *data_tmp, uint8_t s_len);
void ShowInMessage(); void ShowInMessage();
void ShowOutMessage(); void ShowOutMessage();
@ -134,6 +134,6 @@ void AVCLan_Measure();
void SetHighLow(); void SetHighLow();
#endif #endif
extern byte answerReq; extern uint8_t answerReq;
#endif // __AVCLANDRV_H #endif // __AVCLANDRV_H

View File

@ -28,8 +28,8 @@
#include <avr/interrupt.h> #include <avr/interrupt.h>
#include <avr/io.h> #include <avr/io.h>
byte RS232_RxCharBuffer[25], RS232_RxCharBegin, RS232_RxCharEnd; uint8_t RS232_RxCharBuffer[25], RS232_RxCharBegin, RS232_RxCharEnd;
byte readkey; uint8_t readkey;
void RS232_Init(void) { void RS232_Init(void) {
RS232_RxCharBegin = RS232_RxCharEnd = 0; RS232_RxCharBegin = RS232_RxCharEnd = 0;
@ -53,14 +53,14 @@ ISR(USART0_RXC_vect) {
RS232_RxCharEnd++; RS232_RxCharEnd++;
} }
void RS232_SendByte(byte Data) { void RS232_SendByte(uint8_t Data) {
loop_until_bit_is_set(USART0_STATUS, loop_until_bit_is_set(USART0_STATUS,
USART_DREIF_bp); // wait for UART to become available USART_DREIF_bp); // wait for UART to become available
USART0_TXDATAL = Data; // send character USART0_TXDATAL = Data; // send character
} }
void RS232_Print(const char *pBuf) { void RS232_Print(const char *pBuf) {
register byte c; register uint8_t c;
while ((c = *pBuf++)) { while ((c = *pBuf++)) {
if (c == '\n') if (c == '\n')
RS232_SendByte('\r'); RS232_SendByte('\r');
@ -68,20 +68,20 @@ void RS232_Print(const char *pBuf) {
} }
} }
void RS232_PrintHex4(byte Data) { void RS232_PrintHex4(uint8_t Data) {
byte Character = Data & 0x0f; uint8_t Character = Data & 0x0f;
Character += '0'; Character += '0';
if (Character > '9') if (Character > '9')
Character += 'A' - '0' - 10; Character += 'A' - '0' - 10;
RS232_SendByte(Character); RS232_SendByte(Character);
} }
void RS232_PrintHex8(byte Data) { void RS232_PrintHex8(uint8_t Data) {
RS232_PrintHex4(Data >> 4); RS232_PrintHex4(Data >> 4);
RS232_PrintHex4(Data); RS232_PrintHex4(Data);
} }
void RS232_PrintDec(byte Data) { void RS232_PrintDec(uint8_t Data) {
if (Data > 99) { if (Data > 99) {
RS232_SendByte('*'); RS232_SendByte('*');
return; return;
@ -90,7 +90,7 @@ void RS232_PrintDec(byte Data) {
RS232_SendByte('0' + Data); RS232_SendByte('0' + Data);
return; return;
} }
byte c; uint8_t c;
unsigned short v, v1; unsigned short v, v1;
v = Data; v = Data;
v1 = v / 10; v1 = v / 10;
@ -99,7 +99,7 @@ void RS232_PrintDec(byte Data) {
RS232_SendByte(c); RS232_SendByte(c);
} }
void RS232_PrintDec2(byte Data) { void RS232_PrintDec2(uint8_t Data) {
if (Data < 10) if (Data < 10)
RS232_SendByte('0'); RS232_SendByte('0');
RS232_PrintDec(Data); RS232_PrintDec(Data);

View File

@ -29,17 +29,17 @@
#include "GlobalDef.h" #include "GlobalDef.h"
extern byte RS232_RxCharBuffer[25], RS232_RxCharBegin, RS232_RxCharEnd; extern uint8_t RS232_RxCharBuffer[25], RS232_RxCharBegin, RS232_RxCharEnd;
extern byte readkey; extern uint8_t readkey;
void RS232_Init(void); void RS232_Init(void);
extern void RS232_Print_P(const char *str_addr); extern void RS232_Print_P(const char *str_addr);
extern void RS232_SendByte(byte Data); extern void RS232_SendByte(uint8_t Data);
extern void RS232_Print(const char *pBuf); extern void RS232_Print(const char *pBuf);
extern void RS232_PrintHex4(byte Data); extern void RS232_PrintHex4(uint8_t Data);
extern void RS232_PrintHex8(byte Data); extern void RS232_PrintHex8(uint8_t Data);
extern void RS232_PrintDec(byte Data); extern void RS232_PrintDec(uint8_t Data);
extern void RS232_PrintDec2(byte Data); extern void RS232_PrintDec2(uint8_t Data);
extern char *itoa(int i, char b[]); extern char *itoa(int i, char b[]);
#endif // __COM232_H #endif // __COM232_H

View File

@ -33,17 +33,17 @@
void Setup(); void Setup();
byte rcv_command[5]; uint8_t rcv_command[5];
byte rcv_pos = 0; uint8_t rcv_pos = 0;
byte rcv_time_clr = 0; uint8_t rcv_time_clr = 0;
int main() { int main() {
byte readSeq = 0; uint8_t readSeq = 0;
byte s_len = 0; uint8_t s_len = 0;
byte s_dig = 0; uint8_t s_dig = 0;
byte s_c[2]; uint8_t s_c[2];
byte i; uint8_t i;
byte data_tmp[32]; uint8_t data_tmp[32];
Setup(); Setup();