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

@ -26,7 +26,6 @@
#include "GlobalDef.h"
// max 10 events in fifo
byte EventCount;
byte EventCmd[10];

View File

@ -18,8 +18,8 @@
// AVC LAN bus on AC2 (PA6/7)
// PA6 AINP0 +
// PA7 AINN1 -
#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_SET (bit_is_set(AC2_STATUS, AC_STATE_bp))
#define INPUT_IS_CLEAR (bit_is_clear(AC2_STATUS, AC_STATE_bp))
#define LED_DDR DDRB
#define LED_PORT PORTB
@ -31,8 +31,8 @@
typedef unsigned char byte;
typedef unsigned int word;
inline void LedOff( void );
inline void LedOn( void );
inline void LedOff(void);
inline void LedOn(void);
// max 10 events in fifo
extern byte EventCount;
@ -51,8 +51,8 @@ extern byte Event;
#define smMin 5
#define smWDay 6
//#define STOPEvent cbi(TIMSK, TOIE1); cbi(UCSRB, RXCIE);
//#define STARTEvent sbi(TIMSK, TOIE1); sbi(UCSRB, RXCIE);
// #define STOPEvent cbi(TIMSK, TOIE1); cbi(UCSRB, RXCIE);
// #define STARTEvent sbi(TIMSK, TOIE1); sbi(UCSRB, RXCIE);
extern byte showLog;
extern byte showLog2;

File diff suppressed because it is too large Load Diff

View File

@ -27,17 +27,21 @@
*/
#ifndef __AVCLANDRV_H
#define __AVCLANDRV_H
#include "GlobalDef.h"
#define STOPEvent 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 STOPEvent \
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 if (INPUT_IS_SET) AVCLan_Read_Message();
#define CHECK_AVC_LINE \
if (INPUT_IS_SET) \
AVCLan_Read_Message();
void AVC_HoldLine();
void AVC_ReleaseLine();
@ -51,10 +55,9 @@ extern byte HU_ID_2; // 0x40
extern byte CD_ID_1; // 0x03
extern byte CD_ID_2; // 0x60
// DVD CHANGER
//#define CD_ID_1 0x02
//#define CD_ID_2 0x50
// #define CD_ID_1 0x02
// #define CD_ID_2 0x50
#define cmNull 0
#define cmStatus1 1
@ -62,7 +65,6 @@ extern byte CD_ID_2; // 0x60
#define cmStatus3 3
#define cmStatus4 4
#define cmRegister 100
#define cmInit 101
#define cmCheck 102
@ -83,10 +85,9 @@ extern byte CD_ID_2; // 0x60
#define cmStopReq 8
#define cmStopReq2 9
typedef enum { stStop=0, stPlay=1 } cd_modes;
typedef enum { stStop = 0, stPlay = 1 } cd_modes;
extern cd_modes CD_Mode;
extern byte broadcast;
extern byte master1;
extern byte master2;
@ -127,10 +128,10 @@ void ShowInMessage();
void ShowOutMessage();
#ifdef SOFTWARE_DEBUG
void AVCLan_Measure();
void AVCLan_Measure();
#endif
#ifdef HARDWARE_DEBUG
void SetHighLow();
void SetHighLow();
#endif
extern byte answerReq;

View File

@ -24,64 +24,63 @@
*/
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.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 readkey;
void RS232_Init(void)
{
// // init LED
// sbi(DDRB, 5);
// cbi(PORTB, 5);
void RS232_Init(void) {
// // init LED
// sbi(DDRB, 5);
// cbi(PORTB, 5);
RS232_RxCharBegin = RS232_RxCharEnd = 0;
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.CTRLC = USART_CMODE_ASYNCHRONOUS_gc | USART_PMODE_DISABLED_gc | USART_CHSIZE_8BIT_gc | USART_SBMODE_1BIT_gc; // Async UART with 8N1 config
USART0.CTRLB = USART_RXEN_bm | USART_TXEN_bm |
USART_RXMODE_NORMAL_gc; // Enable Rx/Tx and set receive mode
// 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)
{
RS232_RxCharBuffer[RS232_RxCharEnd] = USART0_RXDATAL; // Store received character to the End of Buffer
ISR(USART0_RXC_vect) {
RS232_RxCharBuffer[RS232_RxCharEnd] = USART0_RXDATAL; // Store received
// character to the End
// of Buffer
RS232_RxCharEnd++;
}
void RS232_SendByte(byte Data)
{
loop_until_bit_is_set(USART0_STATUS, USART_DREIF_bp); // wait for UART to become available
void RS232_SendByte(byte Data) {
loop_until_bit_is_set(USART0_STATUS,
USART_DREIF_bp); // wait for UART to become available
USART0_TXDATAL = Data; // send character
}
void RS232_Print_P(const char * str_addr)
{
void RS232_Print_P(const char *str_addr) {
register byte c;
while ( (c = pgm_read_byte(str_addr++) ) )
{
while ((c = pgm_read_byte(str_addr++))) {
if (c == '\n')
RS232_SendByte('\r');
RS232_SendByte(c);
}
}
void RS232_Print(const char *pBuf)
{
void RS232_Print(const char *pBuf) {
register byte c;
while ((c = *pBuf++))
{
while ((c = *pBuf++)) {
if (c == '\n')
RS232_SendByte('\r');
RS232_SendByte(c);
}
}
void RS232_PrintHex4(byte Data)
{
void RS232_PrintHex4(byte Data) {
byte Character = Data & 0x0f;
Character += '0';
if (Character > '9')
@ -89,53 +88,51 @@ void RS232_PrintHex4(byte Data)
RS232_SendByte(Character);
}
void RS232_PrintHex8(byte Data)
{
void RS232_PrintHex8(byte Data) {
RS232_PrintHex4(Data >> 4);
RS232_PrintHex4(Data);
}
void RS232_PrintDec(byte Data)
{
if (Data>99) {
void RS232_PrintDec(byte Data) {
if (Data > 99) {
RS232_SendByte('*');
return;
}
if (Data<10) {
RS232_SendByte('0'+Data);
if (Data < 10) {
RS232_SendByte('0' + Data);
return;
}
byte c;
unsigned short v,v1;
unsigned short v, v1;
v = Data;
v1 = v/10;
c = '0' + (v-v1*10);
RS232_SendByte('0'+v1);
v1 = v / 10;
c = '0' + (v - v1 * 10);
RS232_SendByte('0' + v1);
RS232_SendByte(c);
}
void RS232_PrintDec2(byte Data)
{
if (Data<10) RS232_SendByte('0');
void RS232_PrintDec2(byte Data) {
if (Data < 10)
RS232_SendByte('0');
RS232_PrintDec(Data);
}
char* itoa(int i, char b[]){
char *itoa(int i, char b[]) {
char const digit[] = "0123456789";
char* p = b;
if(i<0){
char *p = b;
if (i < 0) {
*p++ = '-';
i *= -1;
}
int shifter = i;
do{ //Move to where representation ends
do { // Move to where representation ends
++p;
shifter = shifter/10;
}while(shifter);
shifter = shifter / 10;
} while (shifter);
*p = '\0';
do{ //Move back, inserting digits as u go
*--p = digit[i%10];
i = i/10;
}while(i);
do { // Move back, inserting digits as u go
*--p = digit[i % 10];
i = i / 10;
} while (i);
return b;
}

View File

@ -33,17 +33,13 @@ extern byte RS232_RxCharBuffer[25], RS232_RxCharBegin, RS232_RxCharEnd;
extern byte readkey;
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_Print(const char *pBuf);
extern void RS232_PrintHex4(byte Data);
extern void RS232_PrintHex8(byte Data);
extern void RS232_PrintDec(byte Data);
extern void RS232_PrintDec2(byte Data);
extern char* itoa(int i, char b[]);
// LED
#define LED_ON() cbi(PORTB, 5)
#define LED_OFF() sbi(PORTB, 5)
extern char *itoa(int i, char b[]);
#endif // __COM232_H

120
sniffer.c
View File

@ -24,13 +24,13 @@
*/
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/io.h>
#include <avr/pgmspace.h>
#include "GlobalDef.h"
#include "com232.h"
#include "avclandrv.h"
#include "com232.h"
void Setup();
@ -38,8 +38,7 @@ byte rcv_command[5];
byte rcv_pos = 0;
byte rcv_time_clr = 0;
int main()
{
int main() {
byte readSeq = 0;
byte s_len = 0;
byte s_dig = 0;
@ -50,8 +49,9 @@ int main()
Setup();
RS232_Print("AVCLan reader 1.00\nReady\n\n");
// 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"));
// 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("R/r - register device\nB - Beep\n"));
#ifdef HARDWARE_DEBUG
RS232_Print_P(PSTR("1 - Hold High/low\nE - Print line status\n"));
@ -69,59 +69,70 @@ int main()
} else {
// LED_OFF();
// check command from HU
if (answerReq != 0) AVCLan_SendAnswer();
if (answerReq != 0)
AVCLan_SendAnswer();
}
// HandleEvent
switch (Event) {
case EV_STATUS: Event &= ~EV_STATUS;
case EV_STATUS:
Event &= ~EV_STATUS;
AVCLan_Send_Status();
break;
}
// Key handler
if (RS232_RxCharEnd) {
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++;
if (RS232_RxCharBegin == RS232_RxCharEnd) // if Buffer is empty
RS232_RxCharBegin = RS232_RxCharEnd = 0; // reset Buffer
sbi(USART0.CTRLA, USART_RXCIE_bp); // enable RX complete interrupt
switch (readkey) {
case 'S': showLog = 0;
case 'S':
showLog = 0;
RS232_Print_P(PSTR("READ SEQUENCE > \n"));
readSeq = 1;
s_len=0;
s_dig=0;
s_c[0]=s_c[1]=0;
s_len = 0;
s_dig = 0;
s_c[0] = s_c[1] = 0;
break;
case 'W' : showLog = 1;
readSeq=0;
case 'W':
showLog = 1;
readSeq = 0;
AVCLan_SendMyData(data_tmp, s_len);
break;
case 'Q' : showLog = 1;
readSeq=0;
case 'Q':
showLog = 1;
readSeq = 0;
AVCLan_SendMyDataBroadcast(data_tmp, s_len);
break;
case 'R': RS232_Print_P(PSTR("REGIST:\n"));
AVCLan_Command( cmRegister );
case 'R':
RS232_Print_P(PSTR("REGIST:\n"));
AVCLan_Command(cmRegister);
TCB1.CNT = 0;
while( TCB1.CNT < 540 );
while (TCB1.CNT < 540) {}
CHECK_AVC_LINE;
break;
case 'r': AVCLan_Register();
case 'r':
AVCLan_Register();
break;
case 'l': RS232_Print_P(PSTR("Log OFF\n"));
case 'l':
RS232_Print_P(PSTR("Log OFF\n"));
showLog = 0;
break;
case 'L': RS232_Print_P(PSTR("Log ON\n"));
case 'L':
RS232_Print_P(PSTR("Log ON\n"));
showLog = 1;
break;
case 'k': RS232_Print_P(PSTR("str OFF\n"));
case 'k':
RS232_Print_P(PSTR("str OFF\n"));
showLog2 = 0;
break;
case 'K': RS232_Print_P(PSTR("str ON\n"));
case 'K':
RS232_Print_P(PSTR("str ON\n"));
showLog2 = 1;
break;
case 'B':
@ -139,7 +150,7 @@ int main()
SetHighLow();
break;
case 'E':
if(INPUT_IS_SET) {
if (INPUT_IS_SET) {
RS232_Print_P(PSTR("Set/High/1\n"));
} else if (INPUT_IS_CLEAR) {
RS232_Print_P(PSTR("Unset/Low/0\n"));
@ -154,25 +165,29 @@ int main()
break;
#endif
default :
if (readSeq==1) {
s_c[s_dig]=readkey;
default:
if (readSeq == 1) {
s_c[s_dig] = readkey;
s_dig++;
if (s_dig==2) {
if (s_c[0]<':') s_c[0] -= 48;
else s_c[0] -= 55;
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;
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;
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++) {
for (i = 0; i < s_len; i++) {
RS232_PrintHex8(data_tmp[i]);
RS232_SendByte(' ');
}
@ -180,13 +195,12 @@ int main()
}
}
} // switch (readkey)
}// if (RS232_RxCharEnd)
}
} // if (RS232_RxCharEnd)
}
return 0;
}
void Setup()
{
void Setup() {
CD_ID_1 = 0x03;
CD_ID_2 = 0x60;
@ -196,8 +210,8 @@ void Setup()
showLog = 1;
showLog2 = 1;
// Default is zero; resetting/zeroing unnecessary
// MCUCR = 0;
// Default is zero; resetting/zeroing unnecessary
// MCUCR = 0;
loop_until_bit_is_clear(RTC_STATUS, RTC_CTRLABUSY_bp);
RTC.CTRLA = RTC_PRESCALER_DIV1_gc;
@ -206,10 +220,8 @@ void Setup()
loop_until_bit_is_clear(RTC_PITSTATUS, RTC_CTRLBUSY_bp);
RTC.PITCTRLA = RTC_PERIOD_CYC32768_gc | RTC_PITEN_bm;
RS232_Init();
AVCLan_Init();
Event = EV_NOTHING;
@ -217,16 +229,14 @@ void Setup()
}
// Periodic interrupt with a 1 sec period
ISR(RTC_PIT_vect)
{
if (CD_Mode==stPlay)
{
cd_Time_Sec=incBCD(cd_Time_Sec);
if (cd_Time_Sec==0x60) {
ISR(RTC_PIT_vect) {
if (CD_Mode == stPlay) {
cd_Time_Sec = incBCD(cd_Time_Sec);
if (cd_Time_Sec == 0x60) {
cd_Time_Sec = 0;
cd_Time_Min=incBCD(cd_Time_Min);
if (cd_Time_Min==0xA0) {
cd_Time_Min=0x0;
cd_Time_Min = incBCD(cd_Time_Min);
if (cd_Time_Min == 0xA0) {
cd_Time_Min = 0x0;
}
}
}