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

Reformat using clang format

This commit is contained in:
Allen Hill 2023-08-18 21:27:32 -04:00
parent e8d7f5b297
commit 1da1a52c68
8 changed files with 1193 additions and 1127 deletions

6
.clang-format Normal file
View File

@ -0,0 +1,6 @@
---
BasedOnStyle: LLVM
UseCRLF: false
BreakBeforeBraces: Attach
AllowShortBlocksOnASingleLine: Empty
...

View File

@ -1,36 +1,35 @@
/* /*
Copyright (C) 2006 Marcin Slonicki <marcin@softservice.com.pl>. Copyright (C) 2006 Marcin Slonicki <marcin@softservice.com.pl>.
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2 as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation, along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
----------------------------------------------------------------------- -----------------------------------------------------------------------
this file is a part of the TOYOTA Corolla MP3 Player Project this file is a part of the TOYOTA Corolla MP3 Player Project
----------------------------------------------------------------------- -----------------------------------------------------------------------
http://www.softservice.com.pl/corolla/avc http://www.softservice.com.pl/corolla/avc
May 28 / 2009 - version 2 May 28 / 2009 - version 2
*/ */
#include "GlobalDef.h" #include "GlobalDef.h"
// max 10 events in fifo
// max 10 events in fifo byte EventCount;
byte EventCount; byte EventCmd[10];
byte EventCmd[10]; byte Event;
byte Event;
byte showLog;
byte showLog; byte showLog2;
byte showLog2;

View File

@ -12,49 +12,49 @@
#include <avr/io.h> #include <avr/io.h>
#define FALSE 0 #define FALSE 0
#define TRUE (!FALSE) #define TRUE (!FALSE)
// AVC LAN bus on AC2 (PA6/7) // AVC LAN bus on AC2 (PA6/7)
// PA6 AINP0 + // PA6 AINP0 +
// PA7 AINN1 - // PA7 AINN1 -
#define INPUT_IS_SET ( bit_is_set( AC2_STATUS, AC_STATE_bp ) ) #define INPUT_IS_SET (bit_is_set(AC2_STATUS, AC_STATE_bp))
#define INPUT_IS_CLEAR ( bit_is_clear( AC2_STATUS, AC_STATE_bp ) ) #define INPUT_IS_CLEAR (bit_is_clear(AC2_STATUS, AC_STATE_bp))
#define LED_DDR DDRB #define LED_DDR DDRB
#define LED_PORT PORTB #define LED_PORT PORTB
#define LEDOUT _BV(PORT5) #define LEDOUT _BV(PORT5)
#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; typedef unsigned char byte;
typedef unsigned int word; typedef unsigned int word;
inline void LedOff( void ); inline void LedOff(void);
inline void LedOn( void ); inline void LedOn(void);
// max 10 events in fifo // max 10 events in fifo
extern byte EventCount; extern byte EventCount;
extern byte EventCmd[10]; extern byte EventCmd[10];
extern byte Event; 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 byte showLog;
extern byte showLog2; extern byte showLog2;
#endif // _GLOBALDEF_H_ #endif // _GLOBALDEF_H_

File diff suppressed because it is too large Load Diff

View File

@ -27,66 +27,67 @@
*/ */
#ifndef __AVCLANDRV_H #ifndef __AVCLANDRV_H
#define __AVCLANDRV_H #define __AVCLANDRV_H
#include "GlobalDef.h" #include "GlobalDef.h"
#define STOPEvent cbi(RTC.PITINTCTRL, RTC_PI_bp); cbi(USART0.CTRLA, USART_RXCIE_bp); #define STOPEvent \
#define STARTEvent sbi(RTC.PITINTCTRL, RTC_PI_bp); sbi(USART0.CTRLA, USART_RXCIE_bp); cbi(RTC.PITINTCTRL, RTC_PI_bp); \
cbi(USART0.CTRLA, USART_RXCIE_bp);
#define STARTEvent \
sbi(RTC.PITINTCTRL, RTC_PI_bp); \
sbi(USART0.CTRLA, USART_RXCIE_bp);
#define CHECK_AVC_LINE \
#define CHECK_AVC_LINE if (INPUT_IS_SET) AVCLan_Read_Message(); if (INPUT_IS_SET) \
AVCLan_Read_Message();
void AVC_HoldLine(); void AVC_HoldLine();
void AVC_ReleaseLine(); void AVC_ReleaseLine();
#define MAXMSGLEN 32 #define MAXMSGLEN 32
// Head Unid ID // Head Unid ID
extern byte HU_ID_1; // 0x01 extern byte HU_ID_1; // 0x01
extern byte HU_ID_2; // 0x40 extern byte HU_ID_2; // 0x40
extern byte CD_ID_1; // 0x03
extern byte CD_ID_2; // 0x60
extern byte CD_ID_1; // 0x03
extern byte CD_ID_2; // 0x60
// DVD CHANGER // DVD CHANGER
//#define CD_ID_1 0x02 // #define CD_ID_1 0x02
//#define CD_ID_2 0x50 // #define CD_ID_2 0x50
#define cmNull 0 #define cmNull 0
#define cmStatus1 1 #define cmStatus1 1
#define cmStatus2 2 #define cmStatus2 2
#define cmStatus3 3 #define cmStatus3 3
#define cmStatus4 4 #define cmStatus4 4
#define cmRegister 100
#define cmInit 101
#define cmCheck 102
#define cmPlayIt 103
#define cmBeep 110
#define cmRegister 100 #define cmNextTrack 120
#define cmInit 101 #define cmPrevTrack 121
#define cmCheck 102 #define cmNextDisc 122
#define cmPlayIt 103 #define cmPrevDisc 123
#define cmBeep 110
#define cmNextTrack 120 #define cmScanModeOn 130
#define cmPrevTrack 121 #define cmScanModeOff 131
#define cmNextDisc 122
#define cmPrevDisc 123
#define cmScanModeOn 130 #define cmPlayReq1 5
#define cmScanModeOff 131 #define cmPlayReq2 6
#define cmPlayReq3 7
#define cmStopReq 8
#define cmStopReq2 9
#define cmPlayReq1 5 typedef enum { stStop = 0, stPlay = 1 } cd_modes;
#define cmPlayReq2 6
#define cmPlayReq3 7
#define cmStopReq 8
#define cmStopReq2 9
typedef enum { stStop=0, stPlay=1 } cd_modes;
extern cd_modes CD_Mode; extern cd_modes CD_Mode;
extern byte broadcast; extern byte broadcast;
extern byte master1; extern byte master1;
extern byte master2; extern byte master2;
@ -104,12 +105,12 @@ void AVCLan_Send_Status();
void AVCLan_Init(); void AVCLan_Init();
void AVCLan_Register(); void AVCLan_Register();
byte AVCLan_SendData(); byte AVCLan_SendData();
byte AVCLan_SendAnswer(); byte AVCLan_SendAnswer();
byte AVCLan_SendDataBroadcast(); byte AVCLan_SendDataBroadcast();
byte AVCLan_Command(byte command); byte AVCLan_Command(byte command);
byte incBCD(byte data); byte incBCD(byte data);
extern byte check_timeout; extern byte check_timeout;
@ -127,10 +128,10 @@ void ShowInMessage();
void ShowOutMessage(); void ShowOutMessage();
#ifdef SOFTWARE_DEBUG #ifdef SOFTWARE_DEBUG
void AVCLan_Measure(); void AVCLan_Measure();
#endif #endif
#ifdef HARDWARE_DEBUG #ifdef HARDWARE_DEBUG
void SetHighLow(); void SetHighLow();
#endif #endif
extern byte answerReq; extern byte answerReq;

179
com232.c
View File

@ -16,126 +16,123 @@
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
----------------------------------------------------------------------- -----------------------------------------------------------------------
this file is a part of the TOYOTA Corolla MP3 Player Project this file is a part of the TOYOTA Corolla MP3 Player Project
----------------------------------------------------------------------- -----------------------------------------------------------------------
http://www.softservice.com.pl/corolla/avc http://www.softservice.com.pl/corolla/avc
May 28 / 2009 - version 2 May 28 / 2009 - version 2
*/ */
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include "com232.h" #include "com232.h"
#include <avr/interrupt.h>
#include <avr/io.h>
#include <avr/pgmspace.h>
byte RS232_RxCharBuffer[25], RS232_RxCharBegin, RS232_RxCharEnd; byte RS232_RxCharBuffer[25], RS232_RxCharBegin, RS232_RxCharEnd;
byte readkey; byte readkey;
void RS232_Init(void) void RS232_Init(void) {
{ // // init LED
// // init LED // sbi(DDRB, 5);
// sbi(DDRB, 5); // cbi(PORTB, 5);
// cbi(PORTB, 5);
RS232_RxCharBegin = RS232_RxCharEnd = 0; RS232_RxCharBegin = RS232_RxCharEnd = 0;
USART0.CTRLA = USART_RXCIE_bm; // Enable receive interrupts USART0.CTRLA = USART_RXCIE_bm; // Enable receive interrupts
USART0.CTRLB = USART_RXEN_bm | USART_TXEN_bm | USART_RXMODE_NORMAL_gc; // Enable Rx/Tx and set receive mode normal USART0.CTRLB = USART_RXEN_bm | USART_TXEN_bm |
USART0.CTRLC = USART_CMODE_ASYNCHRONOUS_gc | USART_PMODE_DISABLED_gc | USART_CHSIZE_8BIT_gc | USART_SBMODE_1BIT_gc; // Async UART with 8N1 config USART_RXMODE_NORMAL_gc; // Enable Rx/Tx and set receive mode
USART0.BAUD = 256; // 250k baud rate (64*F_CPU/(16*250k)) for F_CPU = 16MHz // normal
USART0.CTRLC = USART_CMODE_ASYNCHRONOUS_gc | USART_PMODE_DISABLED_gc |
USART_CHSIZE_8BIT_gc |
USART_SBMODE_1BIT_gc; // Async UART with 8N1 config
USART0.BAUD = 256; // 250k baud rate (64*F_CPU/(16*250k)) for F_CPU = 16MHz
} }
ISR(USART0_RXC_vect) ISR(USART0_RXC_vect) {
{ RS232_RxCharBuffer[RS232_RxCharEnd] = USART0_RXDATAL; // Store received
RS232_RxCharBuffer[RS232_RxCharEnd] = USART0_RXDATAL; // Store received character to the End of Buffer // character to the End
RS232_RxCharEnd++; // of Buffer
RS232_RxCharEnd++;
} }
void RS232_SendByte(byte Data) void RS232_SendByte(byte 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_P(const char * str_addr) void RS232_Print_P(const char *str_addr) {
{ register byte c;
register byte c; while ((c = pgm_read_byte(str_addr++))) {
while ( (c = pgm_read_byte(str_addr++) ) ) if (c == '\n')
{ RS232_SendByte('\r');
if (c == '\n') RS232_SendByte(c);
RS232_SendByte('\r'); }
RS232_SendByte(c);
}
} }
void RS232_Print(const char *pBuf) void RS232_Print(const char *pBuf) {
{ register byte c;
register byte c; while ((c = *pBuf++)) {
while ((c = *pBuf++)) if (c == '\n')
{ RS232_SendByte('\r');
if (c == '\n') RS232_SendByte(c);
RS232_SendByte('\r'); }
RS232_SendByte(c);
}
} }
void RS232_PrintHex4(byte Data) void RS232_PrintHex4(byte Data) {
{ byte Character = Data & 0x0f;
byte 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(byte Data) {
{ RS232_PrintHex4(Data >> 4);
RS232_PrintHex4(Data >> 4); RS232_PrintHex4(Data);
RS232_PrintHex4(Data);
} }
void RS232_PrintDec(byte Data) void RS232_PrintDec(byte Data) {
{ if (Data > 99) {
if (Data>99) { RS232_SendByte('*');
RS232_SendByte('*'); return;
return; }
} if (Data < 10) {
if (Data<10) { RS232_SendByte('0' + Data);
RS232_SendByte('0'+Data); return;
return; }
} byte c;
byte c; unsigned short v, v1;
unsigned short v,v1; v = Data;
v = Data; v1 = v / 10;
v1 = v/10; c = '0' + (v - v1 * 10);
c = '0' + (v-v1*10); RS232_SendByte('0' + v1);
RS232_SendByte('0'+v1); RS232_SendByte(c);
RS232_SendByte(c);
} }
void RS232_PrintDec2(byte Data) void RS232_PrintDec2(byte Data) {
{ if (Data < 10)
if (Data<10) RS232_SendByte('0'); RS232_SendByte('0');
RS232_PrintDec(Data); RS232_PrintDec(Data);
} }
char* itoa(int i, char b[]){ char *itoa(int i, char b[]) {
char const digit[] = "0123456789"; char const digit[] = "0123456789";
char* p = b; char *p = b;
if(i<0){ if (i < 0) {
*p++ = '-'; *p++ = '-';
i *= -1; i *= -1;
} }
int shifter = i; int shifter = i;
do{ //Move to where representation ends do { // Move to where representation ends
++p; ++p;
shifter = shifter/10; shifter = shifter / 10;
}while(shifter); } while (shifter);
*p = '\0'; *p = '\0';
do{ //Move back, inserting digits as u go do { // Move back, inserting digits as u go
*--p = digit[i%10]; *--p = digit[i % 10];
i = i/10; i = i / 10;
}while(i); } while (i);
return b; return b;
} }

View File

@ -1,49 +1,45 @@
/* /*
Copyright (C) 2006 Marcin Slonicki <marcin@softservice.com.pl>. Copyright (C) 2006 Marcin Slonicki <marcin@softservice.com.pl>.
This program is free software; you can redistribute it and/or This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2 as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation, along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
----------------------------------------------------------------------- -----------------------------------------------------------------------
this file is a part of the TOYOTA Corolla MP3 Player Project this file is a part of the TOYOTA Corolla MP3 Player Project
----------------------------------------------------------------------- -----------------------------------------------------------------------
http://www.softservice.com.pl/corolla/avc http://www.softservice.com.pl/corolla/avc
May 28 / 2009 - version 2 May 28 / 2009 - version 2
*/ */
#ifndef __COM232_H #ifndef __COM232_H
#define __COM232_H #define __COM232_H
#include "GlobalDef.h" #include "GlobalDef.h"
extern byte RS232_RxCharBuffer[25], RS232_RxCharBegin, RS232_RxCharEnd; extern byte RS232_RxCharBuffer[25], RS232_RxCharBegin, RS232_RxCharEnd;
extern byte readkey; extern byte 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(byte 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(byte Data);
extern void RS232_PrintHex8(byte Data); extern void RS232_PrintHex8(byte Data);
extern void RS232_PrintDec(byte Data); extern void RS232_PrintDec(byte Data);
extern void RS232_PrintDec2(byte Data); extern void RS232_PrintDec2(byte Data);
extern char* itoa(int i, char b[]); extern char *itoa(int i, char b[]);
// LED #endif // __COM232_H
#define LED_ON() cbi(PORTB, 5)
#define LED_OFF() sbi(PORTB, 5)
#endif // __COM232_H

328
sniffer.c
View File

@ -24,13 +24,13 @@
*/ */
#include <avr/io.h>
#include <avr/interrupt.h> #include <avr/interrupt.h>
#include <avr/io.h>
#include <avr/pgmspace.h> #include <avr/pgmspace.h>
#include "GlobalDef.h" #include "GlobalDef.h"
#include "com232.h"
#include "avclandrv.h" #include "avclandrv.h"
#include "com232.h"
void Setup(); void Setup();
@ -38,198 +38,208 @@ byte rcv_command[5];
byte rcv_pos = 0; byte rcv_pos = 0;
byte rcv_time_clr = 0; byte rcv_time_clr = 0;
int main() int main() {
{ byte readSeq = 0;
byte readSeq = 0; byte s_len = 0;
byte s_len = 0; byte s_dig = 0;
byte s_dig = 0; byte s_c[2];
byte s_c[2]; byte i;
byte i; byte data_tmp[32];
byte data_tmp[32];
Setup(); Setup();
RS232_Print("AVCLan reader 1.00\nReady\n\n"); RS232_Print("AVCLan reader 1.00\nReady\n\n");
// LED_OFF(); // LED_OFF();
RS232_Print_P(PSTR("\nS - read sequence\nW - send command\nQ - send broadcast\nL/l - log on/off\nK/k - seq. echo on/off\n")); RS232_Print_P(PSTR("\nS - read sequence\nW - send command\nQ - send "
RS232_Print_P(PSTR("R/r - register device\nB - Beep\n")); "broadcast\nL/l - log on/off\nK/k - seq. echo on/off\n"));
RS232_Print_P(PSTR("R/r - register device\nB - Beep\n"));
#ifdef HARDWARE_DEBUG #ifdef HARDWARE_DEBUG
RS232_Print_P(PSTR("1 - Hold High/low\nE - Print line status\n")); RS232_Print_P(PSTR("1 - Hold High/low\nE - Print line status\n"));
#endif #endif
#ifdef SOFTWARE_DEBUG #ifdef SOFTWARE_DEBUG
RS232_Print_P(PSTR("M - Measure high and low lengths\n")); RS232_Print_P(PSTR("M - Measure high and low lengths\n"));
#endif #endif
while (1) { while (1) {
if (INPUT_IS_SET) { // if message from some device on AVCLan begin if (INPUT_IS_SET) { // if message from some device on AVCLan begin
// LED_ON(); // LED_ON();
AVCLan_Read_Message(); AVCLan_Read_Message();
// show message // show message
} else { } else {
// LED_OFF(); // LED_OFF();
// check command from HU // check command from HU
if (answerReq != 0) AVCLan_SendAnswer(); if (answerReq != 0)
AVCLan_SendAnswer();
} }
// HandleEvent // HandleEvent
switch (Event) { switch (Event) {
case EV_STATUS: Event &= ~EV_STATUS; case EV_STATUS:
AVCLan_Send_Status(); Event &= ~EV_STATUS;
break; AVCLan_Send_Status();
break;
} }
// Key handler // Key handler
if (RS232_RxCharEnd) { if (RS232_RxCharEnd) {
cbi(USART0.CTRLA, USART_RXCIE_bp); // disable RX complete interrupt cbi(USART0.CTRLA, USART_RXCIE_bp); // disable RX complete interrupt
readkey = RS232_RxCharBuffer[RS232_RxCharBegin]; // read begin of received Buffer readkey = RS232_RxCharBuffer[RS232_RxCharBegin]; // read begin of received
RS232_RxCharBegin++; // Buffer
if (RS232_RxCharBegin == RS232_RxCharEnd) // if Buffer is empty RS232_RxCharBegin++;
RS232_RxCharBegin = RS232_RxCharEnd = 0; // reset Buffer if (RS232_RxCharBegin == RS232_RxCharEnd) // if Buffer is empty
sbi(USART0.CTRLA, USART_RXCIE_bp); // enable RX complete interrupt RS232_RxCharBegin = RS232_RxCharEnd = 0; // reset Buffer
switch (readkey) { sbi(USART0.CTRLA, USART_RXCIE_bp); // enable RX complete interrupt
case 'S': showLog = 0; switch (readkey) {
RS232_Print_P(PSTR("READ SEQUENCE > \n")); case 'S':
readSeq = 1; showLog = 0;
s_len=0; RS232_Print_P(PSTR("READ SEQUENCE > \n"));
s_dig=0; readSeq = 1;
s_c[0]=s_c[1]=0; s_len = 0;
break; s_dig = 0;
case 'W' : showLog = 1; s_c[0] = s_c[1] = 0;
readSeq=0; break;
AVCLan_SendMyData(data_tmp, s_len); case 'W':
break; showLog = 1;
case 'Q' : showLog = 1; readSeq = 0;
readSeq=0; AVCLan_SendMyData(data_tmp, s_len);
AVCLan_SendMyDataBroadcast(data_tmp, s_len); break;
break; case 'Q':
case 'R': RS232_Print_P(PSTR("REGIST:\n")); showLog = 1;
AVCLan_Command( cmRegister ); readSeq = 0;
TCB1.CNT = 0; AVCLan_SendMyDataBroadcast(data_tmp, s_len);
while( TCB1.CNT < 540 ); break;
CHECK_AVC_LINE; case 'R':
break; RS232_Print_P(PSTR("REGIST:\n"));
case 'r': AVCLan_Register(); AVCLan_Command(cmRegister);
break; TCB1.CNT = 0;
case 'l': RS232_Print_P(PSTR("Log OFF\n")); while (TCB1.CNT < 540) {}
showLog = 0; CHECK_AVC_LINE;
break; break;
case 'L': RS232_Print_P(PSTR("Log ON\n")); case 'r':
showLog = 1; AVCLan_Register();
break; break;
case 'k': RS232_Print_P(PSTR("str OFF\n")); case 'l':
showLog2 = 0; RS232_Print_P(PSTR("Log OFF\n"));
break; showLog = 0;
case 'K': RS232_Print_P(PSTR("str ON\n")); break;
showLog2 = 1; case 'L':
break; RS232_Print_P(PSTR("Log ON\n"));
case 'B': showLog = 1;
data_tmp[0] = 0x00; break;
data_tmp[1] = 0x5E; case 'k':
data_tmp[2] = 0x29; RS232_Print_P(PSTR("str OFF\n"));
data_tmp[3] = 0x60; showLog2 = 0;
data_tmp[4] = 0x01; break;
s_len = 5; case 'K':
AVCLan_SendMyData(data_tmp, s_len); RS232_Print_P(PSTR("str ON\n"));
break; showLog2 = 1;
break;
case 'B':
data_tmp[0] = 0x00;
data_tmp[1] = 0x5E;
data_tmp[2] = 0x29;
data_tmp[3] = 0x60;
data_tmp[4] = 0x01;
s_len = 5;
AVCLan_SendMyData(data_tmp, s_len);
break;
#ifdef HARDWARE_DEBUG #ifdef HARDWARE_DEBUG
case '1': case '1':
SetHighLow(); SetHighLow();
break; break;
case 'E': case 'E':
if(INPUT_IS_SET) { if (INPUT_IS_SET) {
RS232_Print_P(PSTR("Set/High/1\n")); RS232_Print_P(PSTR("Set/High/1\n"));
} else if (INPUT_IS_CLEAR) { } else if (INPUT_IS_CLEAR) {
RS232_Print_P(PSTR("Unset/Low/0\n")); RS232_Print_P(PSTR("Unset/Low/0\n"));
} else { } else {
RS232_Print_P(PSTR("WTF?\n")); RS232_Print_P(PSTR("WTF?\n"));
} }
break; break;
#endif #endif
#ifdef SOFTWARE_DEBUG #ifdef SOFTWARE_DEBUG
case 'M': case 'M':
AVCLan_Measure(); AVCLan_Measure();
break; break;
#endif #endif
default : default:
if (readSeq==1) { if (readSeq == 1) {
s_c[s_dig]=readkey; s_c[s_dig] = readkey;
s_dig++; s_dig++;
if (s_dig==2) { if (s_dig == 2) {
if (s_c[0]<':') s_c[0] -= 48; if (s_c[0] < ':')
else s_c[0] -= 55; s_c[0] -= 48;
data_tmp[s_len] = 16 * s_c[0]; else
if (s_c[1]<':') s_c[1] -= 48; s_c[0] -= 55;
else s_c[1] -= 55; data_tmp[s_len] = 16 * s_c[0];
data_tmp[s_len] += s_c[1]; if (s_c[1] < ':')
s_len++; s_c[1] -= 48;
s_dig=0; else
s_c[0]=s_c[1]=0; s_c[1] -= 55;
} data_tmp[s_len] += s_c[1];
if (showLog2) { s_len++;
RS232_Print_P(PSTR("CURRENT SEQUENCE > ")); s_dig = 0;
for (i=0; i<s_len; i++) { s_c[0] = s_c[1] = 0;
RS232_PrintHex8(data_tmp[i]); }
RS232_SendByte(' '); if (showLog2) {
} RS232_Print_P(PSTR("CURRENT SEQUENCE > "));
RS232_Print_P(PSTR("\n")); for (i = 0; i < s_len; i++) {
} RS232_PrintHex8(data_tmp[i]);
} RS232_SendByte(' ');
} // switch (readkey) }
}// if (RS232_RxCharEnd) RS232_Print_P(PSTR("\n"));
} }
return 0; }
} // switch (readkey)
} // if (RS232_RxCharEnd)
}
return 0;
} }
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;
showLog = 1; showLog = 1;
showLog2 = 1; showLog2 = 1;
// Default is zero; resetting/zeroing unnecessary // Default is zero; resetting/zeroing unnecessary
// MCUCR = 0; // MCUCR = 0;
loop_until_bit_is_clear(RTC_STATUS, RTC_CTRLABUSY_bp); loop_until_bit_is_clear(RTC_STATUS, RTC_CTRLABUSY_bp);
RTC.CTRLA = RTC_PRESCALER_DIV1_gc; RTC.CTRLA = RTC_PRESCALER_DIV1_gc;
RTC.CLKSEL = RTC_CLKSEL_INT32K_gc; RTC.CLKSEL = RTC_CLKSEL_INT32K_gc;
RTC.PITINTCTRL = RTC_PI_bm; RTC.PITINTCTRL = RTC_PI_bm;
loop_until_bit_is_clear(RTC_PITSTATUS, RTC_CTRLBUSY_bp); loop_until_bit_is_clear(RTC_PITSTATUS, RTC_CTRLBUSY_bp);
RTC.PITCTRLA = RTC_PERIOD_CYC32768_gc | RTC_PITEN_bm; RTC.PITCTRLA = RTC_PERIOD_CYC32768_gc | RTC_PITEN_bm;
RS232_Init();
RS232_Init(); AVCLan_Init();
Event = EV_NOTHING;
AVCLan_Init(); sei();
Event = EV_NOTHING;
sei();
} }
// Periodic interrupt with a 1 sec period // Periodic interrupt with a 1 sec period
ISR(RTC_PIT_vect) ISR(RTC_PIT_vect) {
{ if (CD_Mode == stPlay) {
if (CD_Mode==stPlay) cd_Time_Sec = incBCD(cd_Time_Sec);
{ if (cd_Time_Sec == 0x60) {
cd_Time_Sec=incBCD(cd_Time_Sec); cd_Time_Sec = 0;
if (cd_Time_Sec==0x60) { cd_Time_Min = incBCD(cd_Time_Min);
cd_Time_Sec = 0; if (cd_Time_Min == 0xA0) {
cd_Time_Min=incBCD(cd_Time_Min); cd_Time_Min = 0x0;
if (cd_Time_Min==0xA0) { }
cd_Time_Min=0x0;
}
}
} }
Event |= EV_STATUS; }
RTC.PITINTFLAGS |= RTC_PI_bm; Event |= EV_STATUS;
RTC.PITINTFLAGS |= RTC_PI_bm;
} }