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

File cleaning

This commit is contained in:
Allen Hill 2023-08-17 18:06:02 -04:00
parent 241b7cf50a
commit e8d7f5b297
7 changed files with 146 additions and 279 deletions

View File

@ -25,7 +25,6 @@
*/ */
#include "GlobalDef.h" #include "GlobalDef.h"
//------------------------------------------------------------------------------
// max 10 events in fifo // max 10 events in fifo

View File

@ -12,9 +12,6 @@
#include <avr/io.h> #include <avr/io.h>
/*--------------------------------------------------------------------------------------------------
Constants
--------------------------------------------------------------------------------------------------*/
#define FALSE 0 #define FALSE 0
#define TRUE (!FALSE) #define TRUE (!FALSE)
@ -31,22 +28,12 @@
#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)
/*--------------------------------------------------------------------------------------------------
Type definitions
--------------------------------------------------------------------------------------------------*/
typedef unsigned char byte; typedef unsigned char byte;
typedef unsigned int word; typedef unsigned int word;
/*--------------------------------------------------------------------------------------------------
Prototypes
--------------------------------------------------------------------------------------------------*/
inline void LedOff( void ); inline void LedOff( void );
inline void LedOn( void ); inline void LedOn( void );
/*--------------------------------------------------------------------------------------------------
From Marcin's "const.h"
--------------------------------------------------------------------------------------------------*/
// max 10 events in fifo // max 10 events in fifo
extern byte EventCount; extern byte EventCount;
extern byte EventCmd[10]; extern byte EventCmd[10];
@ -56,8 +43,6 @@ extern byte Event;
#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
@ -66,17 +51,10 @@ extern byte Event;
#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_
/*--------------------------------------------------------------------------------------------------
End of file.
--------------------------------------------------------------------------------------------------*/

View File

@ -36,8 +36,6 @@
#include "GlobalDef.h" #include "GlobalDef.h"
//------------------------------------------------------------------------------
#define AVC_OUT_EN() cbi(AC2_CTRLA, AC_ENABLE_bp); sbi(VPORTA_DIR, 6); // Write mode #define AVC_OUT_EN() cbi(AC2_CTRLA, AC_ENABLE_bp); sbi(VPORTA_DIR, 6); // Write mode
#define AVC_OUT_DIS() cbi(VPORTA_DIR, 6); sbi(AC2_CTRLA, AC_ENABLE_bp); // Read mode #define AVC_OUT_DIS() cbi(VPORTA_DIR, 6); sbi(AC2_CTRLA, AC_ENABLE_bp); // Read mode
#define AVC_SET_LOGICAL_1() \ #define AVC_SET_LOGICAL_1() \
@ -137,11 +135,7 @@ byte CMD_STOP2[] = {0x0, 0x0B, 0x63, 0x31, 0xF1, 0x00, 0x30, 0x00, 0x00,0x00,
const byte CMD_BEEP[] = {0x1, 0x05, 0x00, 0x63, 0x29, 0x60, 0x02 }; const byte CMD_BEEP[] = {0x1, 0x05, 0x00, 0x63, 0x29, 0x60, 0x02 };
//------------------------------------------------------------------------------
// DONE: Timing adjusted, however refactoring may make code more clear/efficient
//------------------------------------------------------------------------------
void AVC_HoldLine() void AVC_HoldLine()
{ {
STOPEvent; STOPEvent;
@ -167,18 +161,12 @@ void AVC_HoldLine()
STARTEvent; STARTEvent;
} }
// DONE: No changes necessary
//------------------------------------------------------------------------------
void AVC_ReleaseLine() void AVC_ReleaseLine()
{ {
AVC_SET_LOGICAL_0(); AVC_SET_LOGICAL_0();
AVC_OUT_DIS(); AVC_OUT_DIS();
} }
//------------------------------------------------------------------------------
// DONE: No changes necessary
//------------------------------------------------------------------------------
void AVCLan_Init() void AVCLan_Init()
{ {
PORTA.PIN6CTRL = PORT_ISC_INPUT_DISABLE_gc; // Disable input buffer; recommended when using AC PORTA.PIN6CTRL = PORT_ISC_INPUT_DISABLE_gc; // Disable input buffer; recommended when using AC
@ -212,8 +200,6 @@ void AVCLan_Init()
} }
// DONE: Timing adjusted, however refactoring may make code more clear/efficient
//------------------------------------------------------------------------------
byte AVCLan_Read_Byte(byte length) byte AVCLan_Read_Byte(byte length)
{ {
byte bite = 0; byte bite = 0;
@ -244,8 +230,6 @@ void set_AVC_logic_for(uint8_t val, uint16_t period) {
TCB1_INTFLAGS = 1; TCB1_INTFLAGS = 1;
} }
// DONE: Timing adjusted
//------------------------------------------------------------------------------
byte AVCLan_Send_StartBit() byte 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)
@ -254,8 +238,6 @@ byte AVCLan_Send_StartBit()
return 1; return 1;
} }
// DONE: Timing adjusted. Comparison values are timer ticks, not us.
//------------------------------------------------------------------------------
void AVCLan_Send_Bit1() void AVCLan_Send_Bit1()
{ {
set_AVC_logic_for(1, 164); // 20.5 us @ 125 ns tick (for F_CPU = 16MHz) set_AVC_logic_for(1, 164); // 20.5 us @ 125 ns tick (for F_CPU = 16MHz)
@ -268,8 +250,6 @@ 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)
} }
// DONE: Timing adjusted.
//------------------------------------------------------------------------------
byte AVCLan_Read_ACK() byte 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)
@ -305,8 +285,6 @@ byte AVCLan_Send_ACK()
return 1; return 1;
} }
// DONE: var 'byte' adjusted to 'bite' to avoid reserved word conflict
//------------------------------------------------------------------------------
byte AVCLan_Send_Byte(byte bite, byte len) byte AVCLan_Send_Byte(byte bite, byte len)
{ {
byte b; byte b;
@ -333,8 +311,6 @@ byte AVCLan_Send_Byte(byte bite, byte len)
} }
// DONE: Nothing needed.
//------------------------------------------------------------------------------
byte AVCLan_Send_ParityBit() byte AVCLan_Send_ParityBit()
{ {
if ( (parity_bit & 1)!=0 ) { if ( (parity_bit & 1)!=0 ) {
@ -347,8 +323,6 @@ byte AVCLan_Send_ParityBit()
return 1; return 1;
} }
// DONE: Nothing needed.
//------------------------------------------------------------------------------
byte CheckCmd(byte *cmd) byte CheckCmd(byte *cmd)
{ {
byte i; byte i;
@ -365,8 +339,6 @@ byte CheckCmd(byte *cmd)
return 1; return 1;
} }
// DONE: Timing adjusted.
//------------------------------------------------------------------------------
byte AVCLan_Read_Message() byte AVCLan_Read_Message()
{ {
STOPEvent; // disable timer1 interrupt STOPEvent; // disable timer1 interrupt
@ -497,8 +469,6 @@ byte AVCLan_Read_Message()
return 1; return 1;
} }
// DONE: Timing adjusted.
//------------------------------------------------------------------------------
byte AVCLan_SendData() byte AVCLan_SendData()
{ {
byte i; byte i;
@ -581,8 +551,6 @@ byte AVCLan_SendData()
return 0; return 0;
} }
// DONE: Timing adjusted.
//------------------------------------------------------------------------------
byte AVCLan_SendDataBroadcast() byte AVCLan_SendDataBroadcast()
{ {
byte i; byte i;
@ -636,8 +604,6 @@ byte AVCLan_SendDataBroadcast()
return 0; return 0;
} }
// DONE: Nothing needed.
//------------------------------------------------------------------------------
byte AVCLan_SendAnswerFrame(byte *cmd) byte AVCLan_SendAnswerFrame(byte *cmd)
{ {
byte i; byte i;
@ -658,8 +624,6 @@ byte AVCLan_SendAnswerFrame(byte *cmd)
return AVCLan_SendDataBroadcast(); return AVCLan_SendDataBroadcast();
} }
// DONE: Nothing needed.
//------------------------------------------------------------------------------
byte AVCLan_SendMyData(byte *data_tmp, byte s_len) byte AVCLan_SendMyData(byte *data_tmp, byte s_len)
{ {
byte i; byte i;
@ -675,8 +639,6 @@ byte AVCLan_SendMyData(byte *data_tmp, byte s_len)
return AVCLan_SendData(); return AVCLan_SendData();
} }
// DONE: Nothing needed.
//------------------------------------------------------------------------------
byte AVCLan_SendMyDataBroadcast(byte *data_tmp, byte s_len) byte AVCLan_SendMyDataBroadcast(byte *data_tmp, byte s_len)
{ {
byte i; byte i;
@ -693,8 +655,6 @@ byte AVCLan_SendMyDataBroadcast(byte *data_tmp, byte s_len)
return AVCLan_SendDataBroadcast(); return AVCLan_SendDataBroadcast();
} }
// DONE: Nothing needed.
//------------------------------------------------------------------------------
byte AVCLan_SendInitCommands() byte AVCLan_SendInitCommands()
{ {
byte r; byte r;
@ -726,8 +686,6 @@ byte AVCLan_SendInitCommands()
return r; return r;
} }
// DONE: Nothing needed.
//------------------------------------------------------------------------------
void AVCLan_Send_Status() void AVCLan_Send_Status()
{ {
// disc track t_min t_sec // disc track t_min t_sec
@ -743,8 +701,6 @@ void AVCLan_Send_Status()
AVCLan_SendAnswerFrame((byte*)STATUS); AVCLan_SendAnswerFrame((byte*)STATUS);
} }
// DONE: Nothing needed.
//------------------------------------------------------------------------------
byte AVCLan_SendAnswer() byte AVCLan_SendAnswer()
{ {
byte r = 0 ; byte r = 0 ;
@ -806,8 +762,6 @@ byte AVCLan_SendAnswer()
return r; return r;
} }
// DONE: Nothing needed.
//------------------------------------------------------------------------------
void AVCLan_Register() void AVCLan_Register()
{ {
RS232_Print_P(PSTR("REG_ST\n")); RS232_Print_P(PSTR("REG_ST\n"));
@ -817,8 +771,6 @@ void AVCLan_Register()
AVCLan_Command( cmInit ); AVCLan_Command( cmInit );
} }
// DONE: Nothing needed.
//------------------------------------------------------------------------------
byte AVCLan_Command(byte command) byte AVCLan_Command(byte command)
{ {
byte r; byte r;
@ -843,27 +795,6 @@ byte incBCD(byte data)
return (data+1); return (data+1);
} }
// /* Decrement packed 2-digit BCD number */
// byte decBCD(byte data)
// {
// if ((data & 0xF)==0)
// return (data - 7);
// return (data-1);
// }
// /* convert 8-bit binary to packed 2-digit BCD */
// byte bin2BCD8(byte data)
// {
// byte d,d1;
// d = (unsigned int)data/(unsigned int)10;
// d1 = d * 16;
// d = d1 + (data - 10*d);
// return d;
// }
// DONE: No timing adjustment needed.
//------------------------------------------------------------------------------
void ShowInMessage() void ShowInMessage()
{ {
if (message_len==0) return; if (message_len==0) return;
@ -893,7 +824,6 @@ void ShowInMessage()
AVC_ReleaseLine(); AVC_ReleaseLine();
} }
//------------------------------------------------------------------------------
void ShowOutMessage() void ShowOutMessage()
{ {
byte i; byte i;
@ -1005,5 +935,3 @@ void ShowOutMessage()
AVC_OUT_DIS(); AVC_OUT_DIS();
} }
#endif #endif
//------------------------------------------------------------------------------

View File

@ -30,7 +30,7 @@
#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 cbi(RTC.PITINTCTRL, RTC_PI_bp); cbi(USART0.CTRLA, USART_RXCIE_bp);
@ -110,8 +110,6 @@ byte AVCLan_SendDataBroadcast();
byte AVCLan_Command(byte command); byte AVCLan_Command(byte command);
byte incBCD(byte data); byte incBCD(byte data);
// byte decBCD(byte data); // unused
// byte bin2BCD8(byte data);
extern byte check_timeout; extern byte check_timeout;
@ -135,7 +133,6 @@ void ShowOutMessage();
void SetHighLow(); void SetHighLow();
#endif #endif
//------------------------------------------------------------------------------
extern byte answerReq; extern byte answerReq;
//------------------------------------------------------------------------------
#endif #endif // __AVCLANDRV_H

View File

@ -32,7 +32,6 @@
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
@ -46,19 +45,19 @@ void RS232_Init(void)
USART0.CTRLC = USART_CMODE_ASYNCHRONOUS_gc | USART_PMODE_DISABLED_gc | USART_CHSIZE_8BIT_gc | USART_SBMODE_1BIT_gc; // Async UART with 8N1 config 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 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 character to the End of Buffer RS232_RxCharBuffer[RS232_RxCharEnd] = USART0_RXDATAL; // Store received character to the End of Buffer
RS232_RxCharEnd++; RS232_RxCharEnd++;
} }
//------------------------------------------------------------------------------
void RS232_SendByte(byte Data) void RS232_SendByte(byte Data)
{ {
loop_until_bit_is_set(USART0_STATUS, USART_DREIF_bp); // wait for UART to become available loop_until_bit_is_set(USART0_STATUS, 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;
@ -69,7 +68,7 @@ void RS232_Print_P(const char * str_addr)
RS232_SendByte(c); RS232_SendByte(c);
} }
} }
//------------------------------------------------------------------------------
void RS232_Print(const char *pBuf) void RS232_Print(const char *pBuf)
{ {
register byte c; register byte c;
@ -80,7 +79,7 @@ void RS232_Print(const char *pBuf)
RS232_SendByte(c); RS232_SendByte(c);
} }
} }
//------------------------------------------------------------------------------
void RS232_PrintHex4(byte Data) void RS232_PrintHex4(byte Data)
{ {
byte Character = Data & 0x0f; byte Character = Data & 0x0f;
@ -89,13 +88,13 @@ void RS232_PrintHex4(byte Data)
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) {
@ -114,7 +113,7 @@ void RS232_PrintDec(byte Data)
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) RS232_SendByte('0'); if (Data<10) RS232_SendByte('0');
@ -140,4 +139,3 @@ char* itoa(int i, char b[]){
}while(i); }while(i);
return b; return b;
} }
//------------------------------------------------------------------------------

View File

@ -26,15 +26,11 @@
#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);
@ -46,10 +42,8 @@ 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 // LED
#define LED_ON() cbi(PORTB, 5) #define LED_ON() cbi(PORTB, 5)
#define LED_OFF() sbi(PORTB, 5) #define LED_OFF() sbi(PORTB, 5)
//------------------------------------------------------------------------------ #endif // __COM232_H
#endif

295
sniffer.c
View File

@ -16,16 +16,14 @@
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/io.h>
#include <avr/interrupt.h> #include <avr/interrupt.h>
#include <avr/pgmspace.h> #include <avr/pgmspace.h>
@ -34,38 +32,27 @@
#include "com232.h" #include "com232.h"
#include "avclandrv.h" #include "avclandrv.h"
// -------------------------------------------------------------------------------------
void Setup(); void Setup();
byte rcv_command[5]; byte rcv_command[5];
byte rcv_pos = 0; byte rcv_pos = 0;
byte rcv_time_clr = 0; byte rcv_time_clr = 0;
// -------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
// MAIN PROGRAM
//
int main() int main()
{ {
byte readSeq = 0;
byte s_len = 0;
byte s_dig = 0;
byte s_c[2];
byte i;
byte data_tmp[32];
byte readSeq = 0; Setup();
byte s_len = 0;
byte s_dig = 0;
byte s_c[2];
byte i;
byte data_tmp[32];
Setup(); RS232_Print("AVCLan reader 1.00\nReady\n\n");
// LED_OFF();
RS232_Print("AVCLan reader 1.00\nReady\n\n"); 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"));
LED_OFF(); RS232_Print_P(PSTR("R/r - register device\nB - Beep\n"));
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("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
@ -75,153 +62,142 @@ int main()
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: Event &= ~EV_STATUS;
AVCLan_Send_Status(); AVCLan_Send_Status();
break; 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 Buffer
RS232_RxCharBegin++; RS232_RxCharBegin++;
if (RS232_RxCharBegin == RS232_RxCharEnd) // if Buffer is empty if (RS232_RxCharBegin == RS232_RxCharEnd) // if Buffer is empty
RS232_RxCharBegin = RS232_RxCharEnd = 0; // do reset Buffer RS232_RxCharBegin = RS232_RxCharEnd = 0; // reset Buffer
sbi(USART0.CTRLA, USART_RXCIE_bp); // enable RX complete interrupt sbi(USART0.CTRLA, USART_RXCIE_bp); // enable RX complete interrupt
switch (readkey) { switch (readkey) {
case 'S': showLog = 0; case 'S': showLog = 0;
RS232_Print_P(PSTR("READ SEQUENCE > \n")); RS232_Print_P(PSTR("READ SEQUENCE > \n"));
readSeq = 1; readSeq = 1;
s_len=0; s_len=0;
s_dig=0; s_dig=0;
s_c[0]=s_c[1]=0; s_c[0]=s_c[1]=0;
break; break;
case 'W' : showLog = 1; case 'W' : showLog = 1;
readSeq=0; readSeq=0;
AVCLan_SendMyData(data_tmp, s_len); AVCLan_SendMyData(data_tmp, s_len);
break; break;
case 'Q' : showLog = 1; case 'Q' : showLog = 1;
readSeq=0; readSeq=0;
AVCLan_SendMyDataBroadcast(data_tmp, s_len); AVCLan_SendMyDataBroadcast(data_tmp, s_len);
break; break;
case 'R': RS232_Print_P(PSTR("REGIST:\n")); case 'R': RS232_Print_P(PSTR("REGIST:\n"));
AVCLan_Command( cmRegister ); AVCLan_Command( cmRegister );
TCB1.CNT = 0; TCB1.CNT = 0;
while( TCB1.CNT < 540 ); while( TCB1.CNT < 540 );
CHECK_AVC_LINE; CHECK_AVC_LINE;
break; break;
case 'r': AVCLan_Register(); case 'r': AVCLan_Register();
break; break;
case 'l': RS232_Print_P(PSTR("Log OFF\n")); case 'l': RS232_Print_P(PSTR("Log OFF\n"));
showLog = 0; showLog = 0;
break; break;
case 'L': RS232_Print_P(PSTR("Log ON\n")); case 'L': RS232_Print_P(PSTR("Log ON\n"));
showLog = 1; showLog = 1;
break; break;
case 'k': RS232_Print_P(PSTR("str OFF\n")); case 'k': RS232_Print_P(PSTR("str OFF\n"));
showLog2 = 0; showLog2 = 0;
break; break;
case 'K': RS232_Print_P(PSTR("str ON\n")); case 'K': RS232_Print_P(PSTR("str ON\n"));
showLog2 = 1; showLog2 = 1;
break; break;
case 'B': case 'B':
data_tmp[0] = 0x00; data_tmp[0] = 0x00;
data_tmp[1] = 0x5E; data_tmp[1] = 0x5E;
data_tmp[2] = 0x29; data_tmp[2] = 0x29;
data_tmp[3] = 0x60; data_tmp[3] = 0x60;
data_tmp[4] = 0x01; data_tmp[4] = 0x01;
s_len = 5; s_len = 5;
AVCLan_SendMyData(data_tmp, s_len); AVCLan_SendMyData(data_tmp, s_len);
break; 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++;
if (s_dig==2) {
if (s_c[0]<':') s_c[0] -= 48;
else s_c[0] -= 55;
data_tmp[s_len] = 16 * s_c[0];
if (s_c[1]<':') s_c[1] -= 48;
else s_c[1] -= 55;
data_tmp[s_len] += s_c[1];
s_len++;
s_dig=0;
s_c[0]=s_c[1]=0;
}
if (showLog2) {
RS232_Print_P(PSTR("CURRENT SEQUENCE > "));
for (i=0; i<s_len; i++) {
RS232_PrintHex8(data_tmp[i]);
RS232_SendByte(' ');
}
RS232_Print_P(PSTR("\n"));
}
}
} // switch (readkey)
}// if (RS232_RxCharEnd)
s_dig++;
if (s_dig==2) {
if (s_c[0]<':') s_c[0] -= 48;
else s_c[0] -= 55;
data_tmp[s_len] = 16 * s_c[0];
if (s_c[1]<':') s_c[1] -= 48;
else s_c[1] -= 55;
data_tmp[s_len] += s_c[1];
s_len++;
s_dig=0;
s_c[0]=s_c[1]=0;
}
if (showLog2) {
RS232_Print_P(PSTR("CURRENT SEQUENCE > "));
for (i=0; i<s_len; i++) {
RS232_PrintHex8(data_tmp[i]);
RS232_SendByte(' ');
}
RS232_Print_P(PSTR("\n"));
}
}
} // switch (readkey)
}// if (RS232_RxCharEnd)
} }
return 0; return 0;
} }
// -------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
// Setup - uP: ATMega328p
//
void Setup() void Setup()
{ {
// GIMSK = 0; // (GICR ?) disable external interupts CD_ID_1 = 0x03;
CD_ID_2 = 0x60;
CD_ID_1 = 0x03; HU_ID_1 = 0x01;
CD_ID_2 = 0x60; HU_ID_2 = 0x90;
HU_ID_1 = 0x01; showLog = 1;
HU_ID_2 = 0x90; showLog2 = 1;
showLog = 1; // Default is zero; resetting/zeroing unnecessary
showLog2 = 1; // 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;
@ -231,20 +207,17 @@ void Setup()
RTC.PITCTRLA = RTC_PERIOD_CYC32768_gc | RTC_PITEN_bm; RTC.PITCTRLA = RTC_PERIOD_CYC32768_gc | RTC_PITEN_bm;
RS232_Init(); RS232_Init();
AVCLan_Init(); AVCLan_Init();
Event = EV_NOTHING;
sei();
Event = EV_NOTHING;
sei();
} }
// -------------------------------------------------------------------------------------
// Periodic interrupt with a 1 sec period
ISR(RTC_PIT_vect) // Periodic interrupt with a 1 sec period ISR(RTC_PIT_vect)
{ {
if (CD_Mode==stPlay) if (CD_Mode==stPlay)
{ {