1
0
mirror of https://github.com/halleysfifthinc/sniffer2 synced 2025-06-06 23:46:25 +00:00

Initial commit.

This commit is contained in:
Allen Hill 2015-07-18 21:11:49 -07:00
parent b0e606722f
commit 8040e43d3a
25 changed files with 2408 additions and 0 deletions

886
avclandrv.c Normal file
View File

@ -0,0 +1,886 @@
/*
Copyright (C) 2006 Marcin Slonicki <marcin@softservice.com.pl>.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-----------------------------------------------------------------------
this file is a part of the TOYOTA Corolla MP3 Player Project
-----------------------------------------------------------------------
http://www.softservice.com.pl/corolla/avc
May 28 / 2009 - version 2
*/
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include "timer.h"
#include "delay2.h"
#include "avclandrv.h"
#include "com232.h"
#include "const.h"
//------------------------------------------------------------------------------
#define AVC_OUT_EN() sbi(PORTD, 6); sbi(DDRD, 6); sbi(DDRD, 7); sbi(ACSR, ACD);
#define AVC_OUT_DIS() cbi(PORTD, 6); cbi(DDRD, 6); cbi(DDRD, 7); cbi(ACSR, ACD);
#define AVC_SET_1() sbi(PORTD, 6);
#define AVC_SET_0() cbi(PORTD, 6);
u08 CD_ID_1;
u08 CD_ID_2;
u08 HU_ID_1;
u08 HU_ID_2;
u08 parity_bit;
u08 repeatMode;
u08 randomMode;
u08 playMode;
u08 cd_Disc;
u08 cd_Track;
u08 cd_Time_Min;
u08 cd_Time_Sec;
u08 answerReq;
// we need check answer (to avclan check) timeout
// when is more then 1 min, FORCE answer.
u08 check_timeout;
#define SW_ID 0x12
// commands
const u08 stat1[] = { 0x4, 0x00, 0x00, 0x01, 0x0A };
const u08 stat2[] = { 0x4, 0x00, 0x00, 0x01, 0x08 };
const u08 stat3[] = { 0x4, 0x00, 0x00, 0x01, 0x0D };
const u08 stat4[] = { 0x4, 0x00, 0x00, 0x01, 0x0C };
// broadcast
const u08 lan_stat1[] = { 0x3, 0x00, 0x01, 0x0A };
const u08 lan_reg[] = { 0x3, SW_ID, 0x01, 0x00 };
const u08 lan_init[] = { 0x3, SW_ID, 0x01, 0x01 };
const u08 lan_check[] = { 0x3, SW_ID, 0x01, 0x20 };
const u08 lan_playit[] = { 0x4, SW_ID, 0x01, 0x45, 0x63 };
const u08 play_req1[] = { 0x4, 0x00, 0x25, 0x63, 0x80 };
#ifdef __AVENSIS__
const u08 play_req2[] = { 0x6, 0x00, SW_ID, 0x63, 0x42 };
#else
const u08 play_req2[] = { 0x6, 0x00, SW_ID, 0x63, 0x42, 0x01, 0x00 };
#endif
const u08 play_req3[] = { 0x6, 0x00, SW_ID, 0x63, 0x42, 0x41, 0x00 };
const u08 stop_req[] = { 0x5, 0x00, SW_ID, 0x63, 0x43, 0x01 };
const u08 stop_req2[] = { 0x5, 0x00, SW_ID, 0x63, 0x43, 0x41 };
// answers
const u08 CMD_REGISTER[] = {0x1, 0x05, 0x00, 0x01, SW_ID, 0x10, 0x63 };
const u08 CMD_STATUS1[] = {0x1, 0x04, 0x00, 0x01, 0x00, 0x1A };
const u08 CMD_STATUS2[] = {0x1, 0x04, 0x00, 0x01, 0x00, 0x18 };
const u08 CMD_STATUS3[] = {0x1, 0x04, 0x00, 0x01, 0x00, 0x1D };
const u08 CMD_STATUS4[] = {0x1, 0x05, 0x00, 0x01, 0x00, 0x1C, 0x00 };
u08 CMD_CHECK[] = {0x1, 0x06, 0x00, 0x01, SW_ID, 0x30, 0x00, 0x00 };
const u08 CMD_STATUS5[] = {0x1, 0x05, 0x00, 0x5C, 0x12, 0x53, 0x02 };
const u08 CMD_STATUS5A[] = {0x0, 0x05, 0x5C, 0x31, 0xF1, 0x00, 0x00 };
const u08 CMD_STATUS6[] = {0x1, 0x06, 0x00, 0x5C, 0x32, 0xF0, 0x02, 0x00 };
const u08 CMD_PLAY_OK1[] = {0x1, 0x05, 0x00, 0x63, SW_ID, 0x50, 0x01 };
const u08 CMD_PLAY_OK2[] = {0x1, 0x05, 0x00, 0x63, SW_ID, 0x52, 0x01 };
const u08 CMD_PLAY_OK3[] = {0x0, 0x0B, 0x63, 0x31, 0xF1, 0x01, 0x00, 0x01, 0xFF, 0xFF, 0xFF, 0x00, 0x80 };
u08 CMD_PLAY_OK4[] = {0x0, 0x0B, 0x63, 0x31, 0xF1, 0x01, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80 };
const u08 CMD_STOP1[] = {0x1, 0x05, 0x00, 0x63, SW_ID, 0x53, 0x01 };
u08 CMD_STOP2[] = {0x0, 0x0B, 0x63, 0x31, 0xF1, 0x00, 0x30, 0x00, 0x00,0x00, 0x00, 0x00, 0x80 };
const u08 CMD_BEEP[] = {0x1, 0x05, 0x00, 0x63, 0x29, 0x60, 0x02 };
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void AVC_HoldLine()
{
STOPEvent;
// wait for free line
u08 T=0;
u08 line_busy = 1;
timer0_source(CK64);
timer0_start();
do {
while (INPUT_IS_CLEAR) {
T = TCNT0;
if (T >= 25) break;
}
if (T > 24) line_busy=0;
} while (line_busy);
// switch to out mode
AVC_OUT_EN();
AVC_SET_1();
STARTEvent;
}
//------------------------------------------------------------------------------
void AVC_ReleaseLine()
{
AVC_SET_0();
AVC_OUT_DIS();
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void AVCLan_Init()
{
// AVCLan TX+/TX- : internal comparator PINB2, PINB3
// OUTPUT ( set as input for comparator )
cbi(PORTD, 6);
cbi(DDRD, 6);
// INPUT
cbi(PORTD, 7);
cbi(DDRD, 7);
// Analog comparator
cbi(ADCSRB, ACME); // Analog Comparator Multiplexer Enable - NO
/*
cbi(ACSR, ACBG); // Analog Comparator Bandgap Select
// ACI: Analog Comparator Interrupt Flag
cbi(ACSR, ACIE); // Analog Comparator Interrupt Enable - NO
cbi(ACSR, ACIC); // Analog Comparator Input Capture Enable - NO
*/
cbi(ACSR, ACIS1); // Analog Comparator Interrupt Mode Select
cbi(ACSR, ACIS0); // Comparator Interrupt on Output Toggle
cbi(ACSR, ACD); // Analog Comparator Disbale - NO
message_len = 0;
answerReq = cmNull;
check_timeout = 0;
cd_Disc = 1;
cd_Track = 1;
cd_Time_Min = 0;
cd_Time_Sec = 0;
repeatMode = 0;
randomMode = 0;
playMode = 0;
CD_Mode = stStop;
}
//------------------------------------------------------------------------------
u08 AVCLan_Read_Byte(u08 length)
{
u08 byte = 0;
u08 wT;
while (1) {
while (INPUT_IS_CLEAR);
timer0_start();
while (INPUT_IS_SET);
wT = TCNT0;
if (wT<8) {
byte++;
parity_bit++;
}
length--;
if (!length) return byte;
byte = byte << 1;
}
}
//------------------------------------------------------------------------------
u08 AVCLan_Send_StartBit()
{
AVC_SET_1();
delay1(166);
AVC_SET_0();
delay1(30);
return 1;
}
//------------------------------------------------------------------------------
void AVCLan_Send_Bit1()
{
AVC_SET_1();
delay1(20);
AVC_SET_0();
delay1(16); // 12-21
}
//------------------------------------------------------------------------------
void AVCLan_Send_Bit0()
{
AVC_SET_1();
delay1(32); // 28-37
AVC_SET_0();
delay1(4); // 00-09
}
//------------------------------------------------------------------------------
u08 AVCLan_Read_ACK()
{
u08 time = 0;
AVC_SET_1();
delay1(19);
AVC_SET_0();
delay1(1);
AVC_OUT_DIS(); // switch to read mode
timer0_source(CK64);
timer0_start();
while(1) {
time = TCNT0;
if (INPUT_IS_SET && (time > 1)) break;
if (time > 20) return 1;
}
while(INPUT_IS_SET);
AVC_OUT_EN();// back to write mode
return 0;
}
//------------------------------------------------------------------------------
u08 AVCLan_Send_ACK()
{
timer0_source(CK64); //update every 1us
timer0_start();
while (INPUT_IS_CLEAR) {
if (TCNT0 >= 25) return 0; // max wait time
}
AVC_OUT_EN();
AVC_SET_1();
delay1(32); //28-37
AVC_SET_0();
delay1(4); //00-09
AVC_OUT_DIS();
return 1;
}
//------------------------------------------------------------------------------
u08 AVCLan_Send_Byte(u08 byte, u08 len)
{
u08 b;
if (len==8) {
b = byte;
} else {
b = byte << (8-len);
}
while (1) {
if ( (b & 128)!=0 ) {
AVCLan_Send_Bit1();
parity_bit++;
} else {
AVCLan_Send_Bit0();
}
len--;
if (!len) {
//if (INPUT_IS_SET) RS232_Print("SBER\n"); // Send Bit ERror
return 1;
}
b = b << 1;
}
}
//------------------------------------------------------------------------------
u08 AVCLan_Send_ParityBit()
{
if ( (parity_bit & 1)!=0 ) {
AVCLan_Send_Bit1();
//parity_bit++;
} else {
AVCLan_Send_Bit0();
}
parity_bit=0;
return 1;
}
//------------------------------------------------------------------------------
u08 CheckCmd(u08 *cmd)
{
u08 i;
u08 *c;
u08 l;
c = cmd;
l = *c++;
for (i=0; i<l; i++) {
if (message[i] != *c) return 0;
c++;
}
return 1;
}
//------------------------------------------------------------------------------
u08 AVCLan_Read_Message()
{
STOPEvent; // disable timer1 interrupt
u08 T = 0;
u08 i;
u08 for_me = 0;
//RS232_Print("$ ");
timer0_source(CK64);
// check start bit
timer0_start();
while (INPUT_IS_SET) {
T=TCNT0;
if (T>254) {
STARTEvent;
RS232_Print("LAN>T1\n");
return 0;
}
}
if (T<10) { // !!!!!!! 20 !!!!!!!!!!!
STARTEvent;
RS232_Print("LAN>T2\n");
return 0;
}
broadcast = AVCLan_Read_Byte(1);
parity_bit = 0;
master1 = AVCLan_Read_Byte(4);
master2 = AVCLan_Read_Byte(8);
if ((parity_bit&1)!=AVCLan_Read_Byte(1)) {
STARTEvent;
return 0;
}
parity_bit = 0;
slave1 = AVCLan_Read_Byte(4);
slave2 = AVCLan_Read_Byte(8);
if ((parity_bit&1)!=AVCLan_Read_Byte(1)) {
STARTEvent;
return 0;
}
// is this command for me ?
if ((slave1==CD_ID_1)&&(slave2==CD_ID_2)) {
for_me=1;
}
if (for_me) AVCLan_Send_ACK();
else AVCLan_Read_Byte(1);
parity_bit = 0;
AVCLan_Read_Byte(4); // control - always 0xF
if ((parity_bit&1)!=AVCLan_Read_Byte(1)) {
STARTEvent;
return 0;
}
if (for_me) AVCLan_Send_ACK();
else AVCLan_Read_Byte(1);
parity_bit = 0;
message_len = AVCLan_Read_Byte(8);
if ((parity_bit&1)!=AVCLan_Read_Byte(1)) {
STARTEvent;
return 0;
}
if (for_me) AVCLan_Send_ACK();
else AVCLan_Read_Byte(1);
if (message_len > MAXMSGLEN) {
// RS232_Print("LAN> Command error");
STARTEvent;
return 0;
}
for (i=0; i<message_len; i++) {
parity_bit = 0;
message[i] = AVCLan_Read_Byte(8);
if ((parity_bit&1)!=AVCLan_Read_Byte(1)) {
STARTEvent;
return 0;
}
if (for_me) {
AVCLan_Send_ACK();
} else {
AVCLan_Read_Byte(1);
}
}
STARTEvent;
if (showLog) ShowInMessage();
if (for_me) {
if (CheckCmd((u08*)stat1)) { answerReq = cmStatus1; return 1; }
if (CheckCmd((u08*)stat2)) { answerReq = cmStatus2; return 1; }
if (CheckCmd((u08*)stat3)) { answerReq = cmStatus3; return 1; }
if (CheckCmd((u08*)stat4)) { answerReq = cmStatus4; return 1; }
// if (CheckCmd((u08*)stat5)) { answerReq = cmStatus5; return 1; }
if (CheckCmd((u08*)play_req1)) { answerReq = cmPlayReq1; return 1; }
if (CheckCmd((u08*)play_req2)) { answerReq = cmPlayReq2; return 1; }
if (CheckCmd((u08*)play_req3)) { answerReq = cmPlayReq3; return 1; }
if (CheckCmd((u08*)stop_req)) { answerReq = cmStopReq; return 1; }
if (CheckCmd((u08*)stop_req2)) { answerReq = cmStopReq2; return 1; }
} else { // broadcast check
if (CheckCmd((u08*)lan_playit)) { answerReq = cmPlayIt; return 1; }
if (CheckCmd((u08*)lan_check)) {
answerReq = cmCheck;
CMD_CHECK[6]=message[3];
return 1;
}
if (CheckCmd((u08*)lan_reg)) { answerReq = cmRegister; return 1; }
if (CheckCmd((u08*)lan_init)) { answerReq = cmInit; return 1; }
if (CheckCmd((u08*)lan_stat1)) { answerReq = cmStatus1; return 1; }
}
answerReq = cmNull;
return 1;
}
//------------------------------------------------------------------------------
u08 AVCLan_SendData()
{
u08 i;
STOPEvent;
// wait for free line
u08 T=0;
u08 line_busy = 1;
timer0_source(CK64);
timer0_start();
do {
while (INPUT_IS_CLEAR) {
T = TCNT0;
if (T >= 25) break;
}
if (T > 24) line_busy=0;
} while (line_busy);
// switch to output mode
AVC_OUT_EN();
AVCLan_Send_StartBit();
AVCLan_Send_Byte(0x1, 1); // regular communication
parity_bit = 0;
AVCLan_Send_Byte(CD_ID_1, 4); // CD Changer ID as master
AVCLan_Send_Byte(CD_ID_2, 8);
AVCLan_Send_ParityBit();
AVCLan_Send_Byte(HU_ID_1, 4); // HeadUnit ID as slave
AVCLan_Send_Byte(HU_ID_2, 8);
AVCLan_Send_ParityBit();
if (AVCLan_Read_ACK()) {
AVC_OUT_DIS();
STARTEvent;
RS232_Print("E1\n");
return 1;
}
AVCLan_Send_Byte(0xF, 4); // 0xf - control -> COMMAND WRITE
AVCLan_Send_ParityBit();
if (AVCLan_Read_ACK()) {
AVC_OUT_DIS();
STARTEvent;
RS232_Print("E2\n");
return 2;
}
AVCLan_Send_Byte(data_len, 8);// data lenght
AVCLan_Send_ParityBit();
if (AVCLan_Read_ACK()) {
AVC_OUT_DIS();
STARTEvent;
RS232_Print("E3\n");
return 3;
}
for (i=0;i<data_len;i++) {
AVCLan_Send_Byte(data[i], 8);// data byte
AVCLan_Send_ParityBit();
if (AVCLan_Read_ACK()) {
AVC_OUT_DIS();
STARTEvent;
RS232_Print("E4(");
RS232_PrintDec(i);
RS232_Print(")\n");
return 4;
}
}
// back to read mode
AVC_OUT_DIS();
STARTEvent;
if (showLog) ShowOutMessage();
return 0;
}
//------------------------------------------------------------------------------
u08 AVCLan_SendDataBroadcast()
{
u08 i;
STOPEvent;
// wait for free line
u08 T=0;
u08 line_busy = 1;
timer0_source(CK64);
timer0_start();
do {
while (INPUT_IS_CLEAR) {
T = TCNT0;
if (T >= 25) break;
}
if (T > 24) line_busy=0;
} while (line_busy);
AVC_OUT_EN();
AVCLan_Send_StartBit();
AVCLan_Send_Byte(0x0, 1); // broadcast
parity_bit = 0;
AVCLan_Send_Byte(CD_ID_1, 4); // CD Changer ID as master
AVCLan_Send_Byte(CD_ID_2, 8);
AVCLan_Send_ParityBit();
AVCLan_Send_Byte(0x1, 4); // all audio devices
AVCLan_Send_Byte(0xFF, 8);
AVCLan_Send_ParityBit();
AVCLan_Send_Bit1();
AVCLan_Send_Byte(0xF, 4); // 0xf - control -> COMMAND WRITE
AVCLan_Send_ParityBit();
AVCLan_Send_Bit1();
AVCLan_Send_Byte(data_len, 8); // data lenght
AVCLan_Send_ParityBit();
AVCLan_Send_Bit1();
for (i=0;i<data_len;i++) {
AVCLan_Send_Byte(data[i], 8); // data byte
AVCLan_Send_ParityBit();
AVCLan_Send_Bit1();
}
AVC_OUT_DIS();
STARTEvent;
if (showLog) ShowOutMessage();
return 0;
}
//------------------------------------------------------------------------------
u08 AVCLan_SendAnswerFrame(u08 *cmd)
{
u08 i;
u08 *c;
u08 b;
c = cmd;
b = *c++;
data_control = 0xF;
data_len = *c++;
for (i=0; i<data_len; i++) {
data[i]= *c++;
}
if (b)
return AVCLan_SendData();
else
return AVCLan_SendDataBroadcast();
}
//------------------------------------------------------------------------------
u08 AVCLan_SendMyData(u08 *data_tmp, u08 s_len)
{
u08 i;
u08 *c;
c = data_tmp;
data_control = 0xF;
data_len = s_len;
for (i=0; i<data_len; i++) {
data[i]= *c++;
}
return AVCLan_SendData();
}
//------------------------------------------------------------------------------
u08 AVCLan_SendMyDataBroadcast(u08 *data_tmp, u08 s_len)
{
u08 i;
u08 *c;
c = data_tmp;
data_control = 0xF;
data_len = s_len;
for (i=0; i<data_len; i++) {
data[i]= *c++;
}
return AVCLan_SendDataBroadcast();
}
//------------------------------------------------------------------------------
u08 AVCLan_SendInitCommands()
{
u08 r;
const u08 c1[] = { 0x0, 0x0B, 0x63, 0x31, 0xF1, 0x00, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x80 };
const u08 c2[] = { 0x0, 0x0A, 0x63, 0x31, 0xF3, 0x00, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x02 };
const u08 c3[] = { 0x0, 0x0A, 0x63, 0x31, 0xF3, 0x00, 0x3F, 0x00, 0x01, 0x00, 0x01, 0x02 };
const u08 c4[] = { 0x0, 0x0A, 0x63, 0x31, 0xF3, 0x00, 0x3D, 0x00, 0x01, 0x00, 0x01, 0x02 };
const u08 c5[] = { 0x0, 0x0A, 0x63, 0x31, 0xF3, 0x00, 0x39, 0x00, 0x01, 0x00, 0x01, 0x02 };
const u08 c6[] = { 0x0, 0x0A, 0x63, 0x31, 0xF3, 0x00, 0x31, 0x00, 0x01, 0x00, 0x01, 0x02 };
const u08 c7[] = { 0x0, 0x0A, 0x63, 0x31, 0xF3, 0x00, 0x21, 0x00, 0x01, 0x00, 0x01, 0x02 };
const u08 c8[] = { 0x0, 0x0B, 0x63, 0x31, 0xF1, 0x00, 0x90, 0x01, 0xFF, 0xFF, 0xFF, 0x00, 0x80 };
const u08 c9[] = { 0x0, 0x0A, 0x63, 0x31, 0xF3, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x02 };
const u08 cA[] = { 0x0, 0x0B, 0x63, 0x31, 0xF1, 0x00, 0x30, 0x01, 0xFF, 0xFF, 0xFF, 0x00, 0x80 };
r = AVCLan_SendAnswerFrame((u08*)c1);
if (!r) r = AVCLan_SendAnswerFrame((u08*)c2);
if (!r) r = AVCLan_SendAnswerFrame((u08*)c3);
if (!r) r = AVCLan_SendAnswerFrame((u08*)c4);
if (!r) r = AVCLan_SendAnswerFrame((u08*)c5);
if (!r) r = AVCLan_SendAnswerFrame((u08*)c6);
if (!r) r = AVCLan_SendAnswerFrame((u08*)c7);
if (!r) r = AVCLan_SendAnswerFrame((u08*)c8);
if (!r) r = AVCLan_SendAnswerFrame((u08*)c9);
if (!r) r = AVCLan_SendAnswerFrame((u08*)cA);
//const u08 c1[] = { 0x0, 0x0B, 0x63, 0x31, 0xF1, 0x00, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x80 };
//r = AVCLan_SendAnswerFrame((u08*)c1);
return r;
}
//------------------------------------------------------------------------------
void AVCLan_Send_Status()
{
// disc track t_min t_sec
u08 STATUS[] = {0x0, 0x0B, 0x63, 0x31, 0xF1, 0x01, 0x10, 0x01, 0x01, 0x00, 0x00, 0x00, 0x80 };
STATUS[7] = cd_Disc;
STATUS[8] = cd_Track;
STATUS[9] = cd_Time_Min;
STATUS[10] = cd_Time_Sec;
STATUS[11] = 0;
AVCLan_SendAnswerFrame((u08*)STATUS);
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
u08 AVCLan_SendAnswer()
{
u08 r = 0 ;
switch (answerReq) {
case cmStatus1: r = AVCLan_SendAnswerFrame((u08*)CMD_STATUS1);
break;
case cmStatus2: r = AVCLan_SendAnswerFrame((u08*)CMD_STATUS2);
break;
case cmStatus3: r = AVCLan_SendAnswerFrame((u08*)CMD_STATUS3);
break;
case cmStatus4: r = AVCLan_SendAnswerFrame((u08*)CMD_STATUS4);
break;
case cmRegister: r = AVCLan_SendAnswerFrame((u08*)CMD_REGISTER);
break;
case cmInit: //RS232_Print("INIT\n");
r = AVCLan_SendInitCommands();
break;
case cmCheck: r = AVCLan_SendAnswerFrame((u08*)CMD_CHECK);
check_timeout = 0;
CMD_CHECK[6]++;
RS232_Print("AVCCHK\n");
break;
case cmPlayReq1: playMode = 0;
r = AVCLan_SendAnswerFrame((u08*)CMD_PLAY_OK1);
break;
case cmPlayReq2:
case cmPlayReq3: playMode = 0;
r = AVCLan_SendAnswerFrame((u08*)CMD_PLAY_OK2);
if (!r) r = AVCLan_SendAnswerFrame((u08*)CMD_PLAY_OK3);
CD_Mode = stPlay;
break;
case cmPlayIt: playMode = 1;
RS232_Print("PLAY\n");
CMD_PLAY_OK4[7]=cd_Disc;
CMD_PLAY_OK4[8]=cd_Track;
CMD_PLAY_OK4[9]=cd_Time_Min;
CMD_PLAY_OK4[10]=cd_Time_Sec;
r = AVCLan_SendAnswerFrame((u08*)CMD_PLAY_OK4);
if (!r) AVCLan_Send_Status();
CD_Mode = stPlay;
break;
case cmStopReq:
case cmStopReq2: CD_Mode = stStop;
playMode = 0;
r = AVCLan_SendAnswerFrame((u08*)CMD_STOP1);
CMD_STOP2[7]=cd_Disc;
CMD_STOP2[8]=cd_Track;
CMD_STOP2[9]=cd_Time_Min;
CMD_STOP2[10]=cd_Time_Sec;
r = AVCLan_SendAnswerFrame((u08*)CMD_STOP2);
break;
case cmBeep: AVCLan_SendAnswerFrame((u08*)CMD_BEEP);
break;
}
answerReq = cmNull;
return r;
}
//------------------------------------------------------------------------------
void AVCLan_Register()
{
RS232_Print("REG_ST\n");
AVCLan_SendAnswerFrame((u08*)CMD_REGISTER);
RS232_Print("REG_END\n");
//AVCLan_Command( cmRegister );
AVCLan_Command( cmInit );
}
//------------------------------------------------------------------------------
u08 AVCLan_Command(u08 command)
{
u08 r;
answerReq = command;
r = AVCLan_SendAnswer();
/*
RS232_Print("ret=");
RS232_PrintHex8(r);
RS232_Print("\n");
*/
return r;
}
//------------------------------------------------------------------------------
u08 HexInc(u08 data)
{
if ((data & 0x9)==0x9)
return (data + 7);
return (data+1);
}
//------------------------------------------------------------------------------
u08 HexDec(u08 data)
{
if ((data & 0xF)==0)
return (data - 7);
return (data-1);
}
//------------------------------------------------------------------------------
// encode decimal valute to 'toyota' format :-)
// ex. 42 (dec) = 0x42 (toy)
u08 Dec2Toy(u08 data)
{
u08 d,d1;
d = (u32)data/(u32)10;
d1 = d * 16;
d = d1 + (data - 10*d);
return d;
}
//------------------------------------------------------------------------------
void ShowInMessage()
{
if (message_len==0) return;
AVC_HoldLine();
RS232_S((u16)PSTR("HU < ("));
if (broadcast==0) RS232_S((u16)PSTR("bro) "));
else RS232_Print("dir) ");
RS232_PrintHex4(master1);
RS232_PrintHex8(master2);
RS232_Print("| ");
RS232_PrintHex4(slave1);
RS232_PrintHex8(slave2);
RS232_Print("| ");
u08 i;
for (i=0;i<message_len;i++) {
RS232_PrintHex8(message[i]);
RS232_Print(" ");
}
RS232_Print("\n");
AVC_ReleaseLine();
}
//------------------------------------------------------------------------------
void ShowOutMessage()
{
u08 i;
AVC_HoldLine();
RS232_S((u16)PSTR("out > "));
for (i=0; i<data_len; i++) {
RS232_PrintHex8(data[i]);
RS232_SendByte(' ');
}
RS232_Print("\n");
AVC_ReleaseLine();
}
//------------------------------------------------------------------------------

137
avclandrv.h Normal file
View File

@ -0,0 +1,137 @@
/*
Copyright (C) 2006 Marcin Slonicki <marcin@softservice.com.pl>.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-----------------------------------------------------------------------
this file is a part of the TOYOTA Corolla MP3 Player Project
-----------------------------------------------------------------------
http://www.softservice.com.pl/corolla/avc
May 28 / 2009 - version 2
*/
#ifndef __AVCLANDRV_H
#define __AVCLANDRV_H
//------------------------------------------------------------------------------
#include "const.h"
#define INPUT_IS_SET (ACSR & _BV(ACO))
#define INPUT_IS_CLEAR (!(ACSR & _BV(ACO)))
#define STOPEvent cbi(TIMSK1, TOIE1); cbi(UCSR0B, RXCIE0);
#define STARTEvent sbi(TIMSK1, TOIE1); sbi(UCSR0B, RXCIE0);
#define CHECK_AVC_LINE if (INPUT_IS_SET) AVCLan_Read_Message();
void AVC_HoldLine();
void AVC_ReleaseLine();
#define MAXMSGLEN 32
// Head Unid ID
extern u08 HU_ID_1; // 0x01
extern u08 HU_ID_2; // 0x40
extern u08 CD_ID_1; // 0x03
extern u08 CD_ID_2; // 0x60
// DVD CHANGER
//#define CD_ID_1 0x02
//#define CD_ID_2 0x50
#define cmNull 0
#define cmStatus1 1
#define cmStatus2 2
#define cmStatus3 3
#define cmStatus4 4
#define cmRegister 100
#define cmInit 101
#define cmCheck 102
#define cmPlayIt 103
#define cmBeep 110
#define cmNextTrack 120
#define cmPrevTrack 121
#define cmNextDisc 122
#define cmPrevDisc 123
#define cmScanModeOn 130
#define cmScanModeOff 131
#define cmPlayReq1 5
#define cmPlayReq2 6
#define cmPlayReq3 7
#define cmStopReq 8
#define cmStopReq2 9
typedef enum { stStop=0, stPlay=1 } cd_modes;
cd_modes CD_Mode;
u08 broadcast;
u08 master1;
u08 master2;
u08 slave1;
u08 slave2;
u08 message_len;
u08 message[MAXMSGLEN];
u08 data_control;
u08 data_len;
u08 data[MAXMSGLEN];
u08 AVCLan_Read_Message();
void AVCLan_Send_Status();
void AVCLan_Init();
void AVCLan_Register();
u08 AVCLan_SendData();
u08 AVCLan_SendAnswer();
u08 AVCLan_SendDataBroadcast();
u08 AVCLan_Command(u08 command);
u08 HexInc(u08 data);
u08 HexDec(u08 data);
u08 Dec2Toy(u08 data);
extern u08 check_timeout;
extern u08 cd_Disc;
extern u08 cd_Track;
extern u08 cd_Time_Min;
extern u08 cd_Time_Sec;
extern u08 playMode;
u08 AVCLan_SendMyData(u08 *data_tmp, u08 s_len);
u08 AVCLan_SendMyDataBroadcast(u08 *data_tmp, u08 s_len);
void ShowInMessage();
void ShowOutMessage();
//------------------------------------------------------------------------------
extern u08 answerReq;
//------------------------------------------------------------------------------
#endif

135
com232.c Normal file
View File

@ -0,0 +1,135 @@
/*
Copyright (C) 2006 Marcin Slonicki <marcin@softservice.com.pl>.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-----------------------------------------------------------------------
this file is a part of the TOYOTA Corolla MP3 Player Project
-----------------------------------------------------------------------
http://www.softservice.com.pl/corolla/avc
May 28 / 2009 - version 2
*/
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include "com232.h"
#ifndef F_CPU
#error F_CPU not defined!
#endif
#if F_CPU!=14745000
#error we need 14.745000 MHz crystal
#endif
//------------------------------------------------------------------------------
void RS232_Init(void)
{
// init LED
sbi(DDRB, 0);
cbi(PORTB, 0);
RS232_RxCharBegin = RS232_RxCharEnd = 0;
// enable RxD/TxD and interrupts
UCSR0A = 0;
UCSR0B = ((1<<RXCIE0) | (1<<RXEN0) | (1<<TXEN0)); // enable RxD/TxD and interrupts
UCSR0C = ((1<<UCSZ01)|(1<<UCSZ00)); // 8N1
UBRR0 = 7;
}
//------------------------------------------------------------------------------
SIGNAL(SIG_USART_RECV)
{
RS232_RxCharBuffer[RS232_RxCharEnd] = UDR0; // Store received character to the End of Buffer
RS232_RxCharEnd++;
}
//------------------------------------------------------------------------------
void RS232_SendByte(u08 Data)
{
while ((UCSR0A & _BV(UDRE0)) != _BV(UDRE0)); // wait for UART to become available
UDR0 = Data; // send character
}
//------------------------------------------------------------------------------
void RS232_S(u16 str_addr)
{
register u08 c;
while ( (c = pgm_read_byte(str_addr++) ) )
{
if (c == '\n')
RS232_SendByte('\r');
RS232_SendByte(c);
}
}
//------------------------------------------------------------------------------
void RS232_Print(char* pBuf)
{
register u08 c;
while ((c = *pBuf++))
{
if (c == '\n')
RS232_SendByte('\r');
RS232_SendByte(c);
}
}
//------------------------------------------------------------------------------
void RS232_PrintHex4(u08 Data)
{
u08 Character = Data & 0x0f;
Character += '0';
if (Character > '9')
Character += 'A' - '0' - 10;
RS232_SendByte(Character);
}
//------------------------------------------------------------------------------
void RS232_PrintHex8(u08 Data)
{
RS232_PrintHex4(Data >> 4);
RS232_PrintHex4(Data);
}
//------------------------------------------------------------------------------
void RS232_PrintDec(u08 Data)
{
if (Data>99) {
RS232_SendByte('*');
return;
}
if (Data<10) {
RS232_SendByte('0'+Data);
return;
}
u08 c;
u16 v,v1;
v = Data;
v1 = v/10;
c = '0' + (v-v1*10);
RS232_SendByte('0'+v1);
RS232_SendByte(c);
}
//------------------------------------------------------------------------------
void RS232_PrintDec2(u08 Data)
{
if (Data<10) RS232_SendByte('0');
RS232_PrintDec(Data);
}
//------------------------------------------------------------------------------

54
com232.h Normal file
View File

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

37
const.c Normal file
View File

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

78
const.h Normal file
View File

@ -0,0 +1,78 @@
/*
Copyright (C) 2006 Marcin Slonicki <marcin@softservice.com.pl>.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-----------------------------------------------------------------------
this file is a part of the TOYOTA Corolla MP3 Player Project
-----------------------------------------------------------------------
http://www.softservice.com.pl/corolla/avc
May 28 / 2009 - version 2
*/
#ifndef __CONST_H
#define __CONST_H
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// variable type
#define u08 unsigned char
#define u16 unsigned short
#define u32 unsigned int
#define u64 unsigned long
// port set/unset
#define sbi(port, bit) (port) |= (1 << (bit))
#define cbi(port, bit) (port) &= ~(1 << (bit))
//------------------------------------------------------------------------------
// max 10 events in fifo
extern u08 EventCount;
extern u08 EventCmd[10];
extern u08 Event;
#define EV_NOTHING 0
#define EV_DISPLAY 1
#define EV_STATUS 4
//------------------------------------------------------------------------------
// const
#define smYear 1
#define smMonth 2
#define smDay 3
#define smHour 4
#define smMin 5
#define smWDay 6
//#define STOPEvent cbi(TIMSK, TOIE1); cbi(UCSRB, RXCIE);
//#define STARTEvent sbi(TIMSK, TOIE1); sbi(UCSRB, RXCIE);
extern u08 showLog;
extern u08 showLog2;
//------------------------------------------------------------------------------
#endif

86
default/Makefile Normal file
View File

@ -0,0 +1,86 @@
###############################################################################
# Makefile for the project sniffer
###############################################################################
## General Flags
PROJECT = sniffer
MCU = atmega88
TARGET = sniffer.elf
CC = avr-gcc.exe
## Options common to compile, link and assembly rules
COMMON = -mmcu=$(MCU)
## Compile options common for all C compilation units.
CFLAGS = $(COMMON)
CFLAGS += -Wall -gdwarf-2 -DF_CPU=14745000UL -Os -fsigned-char
CFLAGS += -MD -MP -MT $(*F).o -MF dep/$(@F).d
## Assembly specific flags
ASMFLAGS = $(COMMON)
ASMFLAGS += $(CFLAGS)
ASMFLAGS += -x assembler-with-cpp -Wa,-gdwarf2
## Linker flags
LDFLAGS = $(COMMON)
LDFLAGS +=
## Intel Hex file production flags
HEX_FLASH_FLAGS = -R .eeprom
HEX_EEPROM_FLAGS = -j .eeprom
HEX_EEPROM_FLAGS += --set-section-flags=.eeprom="alloc,load"
HEX_EEPROM_FLAGS += --change-section-lma .eeprom=0 --no-change-warnings
## Objects that must be built in order to link
OBJECTS = sniffer.o avclandrv.o com232.o const.o delay2.o
## Objects explicitly added by the user
LINKONLYOBJECTS =
## Build
all: $(TARGET) sniffer.hex sniffer.eep size
## Compile
sniffer.o: ../sniffer.c
$(CC) $(INCLUDES) $(CFLAGS) -c $<
avclandrv.o: ../avclandrv.c
$(CC) $(INCLUDES) $(CFLAGS) -c $<
com232.o: ../com232.c
$(CC) $(INCLUDES) $(CFLAGS) -c $<
const.o: ../const.c
$(CC) $(INCLUDES) $(CFLAGS) -c $<
delay2.o: ../delay2.c
$(CC) $(INCLUDES) $(CFLAGS) -c $<
##Link
$(TARGET): $(OBJECTS)
$(CC) $(LDFLAGS) $(OBJECTS) $(LINKONLYOBJECTS) $(LIBDIRS) $(LIBS) -o $(TARGET)
%.hex: $(TARGET)
avr-objcopy -O ihex $(HEX_FLASH_FLAGS) $< $@
%.eep: $(TARGET)
-avr-objcopy $(HEX_EEPROM_FLAGS) -O ihex $< $@ || exit 0
%.lss: $(TARGET)
avr-objdump -h -S $< > $@
size: ${TARGET}
@echo
@avr-size -C --mcu=${MCU} ${TARGET}
## Clean target
.PHONY: clean
clean:
-rm -rf $(OBJECTS) sniffer.elf dep/* sniffer.hex sniffer.eep
## Other dependencies
-include $(shell mkdir dep 2>/dev/null) $(wildcard dep/*)

BIN
default/avclandrv.o Normal file

Binary file not shown.

BIN
default/com232.o Normal file

Binary file not shown.

BIN
default/const.o Normal file

Binary file not shown.

BIN
default/delay2.o Normal file

Binary file not shown.

44
default/dep/avclandrv.o.d Normal file
View File

@ -0,0 +1,44 @@
avclandrv.o: ../avclandrv.c c:/winavr/bin/../avr/include/avr/io.h \
c:/winavr/bin/../avr/include/avr/sfr_defs.h \
c:/winavr/bin/../avr/include/inttypes.h \
c:/winavr/bin/../avr/include/stdint.h \
c:/winavr/bin/../avr/include/avr/iom88.h \
c:/winavr/bin/../avr/include/avr/iomx8.h \
c:/winavr/bin/../avr/include/avr/portpins.h \
c:/winavr/bin/../avr/include/avr/version.h \
c:/winavr/bin/../avr/include/avr/interrupt.h \
c:/winavr/bin/../avr/include/avr/pgmspace.h \
c:\winavr\bin\../lib/gcc/avr/4.1.2/include/stddef.h ../timer.h \
../delay2.h ../const.h ../avclandrv.h ../com232.h
c:/winavr/bin/../avr/include/avr/io.h:
c:/winavr/bin/../avr/include/avr/sfr_defs.h:
c:/winavr/bin/../avr/include/inttypes.h:
c:/winavr/bin/../avr/include/stdint.h:
c:/winavr/bin/../avr/include/avr/iom88.h:
c:/winavr/bin/../avr/include/avr/iomx8.h:
c:/winavr/bin/../avr/include/avr/portpins.h:
c:/winavr/bin/../avr/include/avr/version.h:
c:/winavr/bin/../avr/include/avr/interrupt.h:
c:/winavr/bin/../avr/include/avr/pgmspace.h:
c:\winavr\bin\../lib/gcc/avr/4.1.2/include/stddef.h:
../timer.h:
../delay2.h:
../const.h:
../avclandrv.h:
../com232.h:

38
default/dep/com232.o.d Normal file
View File

@ -0,0 +1,38 @@
com232.o: ../com232.c c:/winavr/bin/../avr/include/avr/io.h \
c:/winavr/bin/../avr/include/avr/sfr_defs.h \
c:/winavr/bin/../avr/include/inttypes.h \
c:/winavr/bin/../avr/include/stdint.h \
c:/winavr/bin/../avr/include/avr/iom88.h \
c:/winavr/bin/../avr/include/avr/iomx8.h \
c:/winavr/bin/../avr/include/avr/portpins.h \
c:/winavr/bin/../avr/include/avr/version.h \
c:/winavr/bin/../avr/include/avr/interrupt.h \
c:/winavr/bin/../avr/include/avr/pgmspace.h \
c:\winavr\bin\../lib/gcc/avr/4.1.2/include/stddef.h ../com232.h \
../const.h
c:/winavr/bin/../avr/include/avr/io.h:
c:/winavr/bin/../avr/include/avr/sfr_defs.h:
c:/winavr/bin/../avr/include/inttypes.h:
c:/winavr/bin/../avr/include/stdint.h:
c:/winavr/bin/../avr/include/avr/iom88.h:
c:/winavr/bin/../avr/include/avr/iomx8.h:
c:/winavr/bin/../avr/include/avr/portpins.h:
c:/winavr/bin/../avr/include/avr/version.h:
c:/winavr/bin/../avr/include/avr/interrupt.h:
c:/winavr/bin/../avr/include/avr/pgmspace.h:
c:\winavr\bin\../lib/gcc/avr/4.1.2/include/stddef.h:
../com232.h:
../const.h:

3
default/dep/const.o.d Normal file
View File

@ -0,0 +1,3 @@
const.o: ../const.c ../const.h
../const.h:

31
default/dep/delay2.o.d Normal file
View File

@ -0,0 +1,31 @@
delay2.o: ../delay2.c c:/winavr/bin/../avr/include/avr/io.h \
c:/winavr/bin/../avr/include/avr/sfr_defs.h \
c:/winavr/bin/../avr/include/inttypes.h \
c:/winavr/bin/../avr/include/stdint.h \
c:/winavr/bin/../avr/include/avr/iom88.h \
c:/winavr/bin/../avr/include/avr/iomx8.h \
c:/winavr/bin/../avr/include/avr/portpins.h \
c:/winavr/bin/../avr/include/avr/version.h ../delay2.h ../const.h \
../timer.h
c:/winavr/bin/../avr/include/avr/io.h:
c:/winavr/bin/../avr/include/avr/sfr_defs.h:
c:/winavr/bin/../avr/include/inttypes.h:
c:/winavr/bin/../avr/include/stdint.h:
c:/winavr/bin/../avr/include/avr/iom88.h:
c:/winavr/bin/../avr/include/avr/iomx8.h:
c:/winavr/bin/../avr/include/avr/portpins.h:
c:/winavr/bin/../avr/include/avr/version.h:
../delay2.h:
../const.h:
../timer.h:

42
default/dep/sniffer.o.d Normal file
View File

@ -0,0 +1,42 @@
sniffer.o: ../sniffer.c c:/winavr/bin/../avr/include/avr/io.h \
c:/winavr/bin/../avr/include/avr/sfr_defs.h \
c:/winavr/bin/../avr/include/inttypes.h \
c:/winavr/bin/../avr/include/stdint.h \
c:/winavr/bin/../avr/include/avr/iom88.h \
c:/winavr/bin/../avr/include/avr/iomx8.h \
c:/winavr/bin/../avr/include/avr/portpins.h \
c:/winavr/bin/../avr/include/avr/version.h \
c:/winavr/bin/../avr/include/avr/interrupt.h \
c:/winavr/bin/../avr/include/avr/pgmspace.h \
c:\winavr\bin\../lib/gcc/avr/4.1.2/include/stddef.h ../const.h \
../com232.h ../delay2.h ../avclandrv.h
c:/winavr/bin/../avr/include/avr/io.h:
c:/winavr/bin/../avr/include/avr/sfr_defs.h:
c:/winavr/bin/../avr/include/inttypes.h:
c:/winavr/bin/../avr/include/stdint.h:
c:/winavr/bin/../avr/include/avr/iom88.h:
c:/winavr/bin/../avr/include/avr/iomx8.h:
c:/winavr/bin/../avr/include/avr/portpins.h:
c:/winavr/bin/../avr/include/avr/version.h:
c:/winavr/bin/../avr/include/avr/interrupt.h:
c:/winavr/bin/../avr/include/avr/pgmspace.h:
c:\winavr\bin\../lib/gcc/avr/4.1.2/include/stddef.h:
../const.h:
../com232.h:
../delay2.h:
../avclandrv.h:

BIN
default/sniffer.elf Normal file

Binary file not shown.

330
default/sniffer.hex Normal file
View File

@ -0,0 +1,330 @@
:100000007BC095C094C093C092C091C090C08FC077
:100010008EC08DC08CC08BC08AC08AC088C087C08B
:1000200086C085C012C883C082C081C080C07FC026
:100030007EC07DC0522F72202D2072656769737457
:100040006572206465766963650A004B2F6B202D0D
:10005000207365712E206563686F206F6E2F6F6649
:10006000660A004C2F6C202D206C6F67206F6E2F5E
:100070006F66660A0051202D2073656E64206272DF
:100080006F6164636173740A0057202D2073656E7D
:100090006420636F6D6D616E640A0053202D2072C1
:1000A0006561642073657175656E63650A0048203B
:1000B0002D2048552069640A0054202D206465765F
:1000C0006963652069640A004156434C616E207281
:1000D000656164657220312E30300A526561647941
:1000E0000A0A006F7574203E200062726F2920009A
:1000F0004855203C2028000011241FBECFEFD4E03B
:10010000DEBFCDBF13E0A0E0B1E0ECE5F2E102C05C
:1001100005900D92A632B107D9F713E0A6E2B3E03D
:1001200001C01D92A03BB107E1F778D096C868CF17
:100130001F920F920FB60F9211242F933F934F935C
:100140005F936F937F938F939F93AF93BF93EF933F
:10015000FF938FE79FE890938500809384008091C0
:1001600028038F5F809328038230F9F410922803CC
:1001700080912C0390912D030197B9F48091A003F5
:100180001AD28093A003803659F41092A003809174
:10019000A10311D28093A103803A11F41092A1031C
:1001A0008091AF0384608093AF03FF91EF91BF9183
:1001B000AF919F918F917F916F915F914F913F91FF
:1001C0002F910F900FBE0F901F90189582E0809393
:1001D0009B0380E880939F0391E09093940380E4D5
:1001E00080939E039093AE039093AD0315BEEFE60C
:1001F000F0E010828081816080831092800084E032
:10020000809381008FE79FE890938500809384001E
:1002100007D773D11092AF0378940895EF92FF92AD
:100220000F931F93CF93DF93CDB7DEB7A2970FB68F
:10023000F894DEBF0FBECDBFC9DF88EC90E096D743
:10024000289A89EB90E092D78EEA90E08FD78BE9DD
:1002500090E08CD789E890E089D785E790E086D751
:1002600083E690E083D78BE490E080D784E390E04E
:100270007DD700E0EE24FF2400B605FE03C02898D9
:100280004DD205C0289A80919D0381110FD680918F
:10029000AF03843019F41092AF03AAD520918D03D7
:1002A000222351F38091C1008F778093C100809108
:1002B0005103E82FFF27EE5AFC4F908190938C0357
:1002C0008F5F80935103821721F410928D03109257
:1002D00051038091C10080688093C100933509F477
:1002E0005EC0943590F49C3409F483C09D3430F49E
:1002F000983499F19B3409F090C088C0913509F485
:100300005BC0923509F089C05FC09B3609F478C0A4
:100310009C3630F4943559F0973509F07EC044C0CE
:100320009C3609F460C0923709F077C05AC00023A8
:1003300079F08B8180939B038C8180939F0380E075
:1003400091E0FFD680919B03B3D680919F0315C0A7
:100350001092AE0381E191E01DC00023B9F08B81C2
:10036000809394038C8180939E038CE191E0E9D685
:10037000809194039DD680919E039AD68FE091E060
:10038000E0D681E08093AE0300E076CF1092AE031A
:100390008AE291E0D6D61A82198201E06BCF1092E0
:1003A000AE0384E391E0F6CF81E08093AE036E2D3F
:1003B000CE010396E8D4E8CF81E08093AE036E2DA2
:1003C000CE010396F4D3E0CF86E491E0BAD684E67A
:1003D00016D68FE090E0F0D600B605FE4DCF9ED148
:1003E0004BCF12D649CF8FE491E0ABD61092AE033B
:1003F00043CF88E591E0A5D681E08093AE033CCF62
:1004000080E691E09ED61092AD0336CF89E691E06A
:1004100098D681E08093AD032FCF013009F02CCF27
:10042000FE01EF0DF11D9183F39482E0F816E1F4E3
:1004300089818A3310F4805301C087538983EE2D5C
:10044000FF2799819295907F8A818A3310F4805397
:1004500001C087538A838A81980FEC0FFD1F938315
:10046000E3941A821982FF248091AD03882309F452
:1004700003CF81E791E065D610E008C0FE01E10FEF
:10048000F11D838115D680E2FED51F5F1E15B1F7E1
:100490008FE091E056D6F0CE80916F008E7F8093F2
:1004A0006F008091C1008F778093C10083E085BD8C
:1004B00081E086BD80E003C086B5893120F400B6B6
:1004C00005FEFACFFACF5E9A569A579A80B780689F
:1004D00080BF5E9A80916F00816080936F008091F1
:1004E000C10080688093C10008955E985E98569818
:1004F000579880B78F7780BF08955E9856985F9819
:100500005798EBE7F0E080818F7B808380B78D7F09
:1005100080BF80B78E7F80BF80B78F7780BF1092FB
:100520002B0310929D0310929C0381E0809398030B
:10053000809396031092A1031092A0031092990346
:10054000109297031092950310922D0310922C0392
:100550000895382F20919A0390E041E000B605FEFF
:10056000FDCF46BD00B605FCFDCF86B5883010F442
:100570009F5F2F5F315011F0990FF0CF20939A03B6
:10058000892F99270895FC013081DC0120E00EC0FD
:10059000FD0181811196E22FFF27E25DFC4F9081E2
:1005A000981719F080E090E008952F5F231781F7E6
:1005B00081E090E00895982F8970893021F4995F47
:1005C000892F992708959F5F892F99270895282FAC
:1005D00099278F709070892B21F42750822F9927AB
:1005E00008952150822F99270895282F6AE015D663
:1005F0009927AC0173E0440F551F7A95E1F7880FF6
:10060000991F480F591F241B33E0880F991F3A95F3
:10061000E1F7280F822F99270895CF93DF933CDFCE
:1006200083EE90E0A3D5C0E0D0E007C0FF27E559F6
:10063000FC4F80813DD580E226D5EC2F219680911C
:100640004F03E81798F386E891E07BD54EDFDF9102
:10065000CF910895CF93DF9380912B038823B1F13D
:100660001BDF80EF90E082D580919303882321F4F3
:100670008AEE90E07BD503C088E891E062D5809156
:100680008B0309D580914E0313D58EE891E059D59F
:100690008091500300D5809129030AD58EE891E01E
:1006A00050D5C0E0D0E008C0FF27E25DFC4F80815C
:1006B000FFD481E991E045D5EC2F219680912B0361
:1006C000E81790F386E891E03CD50FDFDF91CF91FA
:1006D000089583E085BD81E086BD06C086B5893179
:1006E00018F080E090E0089500B605FEF7CF5E9A1E
:1006F000569A579A80B7806880BF5E9A80E290E0F1
:100700005BD55E9884E090E057D55E9856985798F0
:1007100080B78F7780BF81E090E00895FF920F93BC
:100720001F93CF93DF9380916F008E7F80936F0034
:100730008091C1008F778093C10083E085BD81E007
:1007400086BD80E004C086B58F3F09F436C100B68F
:1007500005FCF9CF8A3068F480916F008160809346
:100760006F008091C10080688093C1008BE991E0A7
:1007700030C181E0EEDE8093930310929A0384E00F
:10078000E8DE80938B0388E0E4DE80934E030091E3
:100790009A0311270170107081E0DBDE992708179A
:1007A000190709F0FFC010929A0384E0D2DE80930B
:1007B000500388E0CEDE8093290300919A0311272D
:1007C0000170107081E0C5DE99270817190709F03C
:1007D000E9C09091500380919B03981739F4909150
:1007E000290380919F03981709F4D8C081E0B1DEF6
:1007F000FF2410929A0384E0ACDE00919A03112743
:100800000170107081E0A5DE99270817190709F01B
:10081000C9C0FF2011F05DDF02C081E09ADE1092B6
:100820009A0388E096DE80932B0300919A031127A8
:100830000170107081E08DDE99270817190709F003
:10084000B1C0FF2011F045DF02C081E082DE80915F
:100850002B03813208F0A6C0C0E0D0E01CC010928B
:100860009A0388E076DEE02FFF27E25DFC4F80836D
:1008700000919A0311270170107081E06ADE9927B8
:100880000817190709F08EC0FF2011F022DF02C0FF
:1008900081E05FDE21960C2F80912B03C817F8F2C0
:1008A00080916F00816080936F008091C1008068AB
:1008B0008093C1008091AE038111CCDEFF20F1F165
:1008C00085ED91E060DE882309F05FC08AED91E05C
:1008D0005ADE882311F082E059C08FED91E053DE9B
:1008E000882311F083E052C084EE91E04CDE88232F
:1008F00011F084E04BC08EEF91E045DE882311F0CB
:1009000085E044C083E092E03EDE882311F086E07B
:100910003DC08AE092E037DE882311F087E036C0E0
:1009200081E192E030DE882311F088E02FC087E17A
:1009300092E029DE882369F189E028C089EF91E0FF
:1009400022DE882311F087E621C085EF91E01BDECF
:10095000882341F086E680939D0380913103809344
:10096000430219C08DEE91E00EDE882311F084E67B
:100970000DC081EF91E007DE882311F085E606C007
:1009800089EE91E000DE882321F081E080939D03D1
:1009900002C010929D0381E090E01EC09ADEE1E06B
:1009A000FE2E27CF80916F00816080936F00809131
:1009B000C10080688093C1000DC080916F0081608C
:1009C00080936F008091C10080688093C10083E9AB
:1009D00091E0B7D380E090E0DF91CF911F910F912C
:1009E000FF9008955E9A83E190E0E6D35E9881E0FF
:1009F00090E0E2D35E985698579880B78F7780BF83
:100A000083E085BD81E086BD86B500B605FE02C0E7
:100A1000823028F48531C0F381E090E0089500B67B
:100A200005FCFDCF5E9A569A579A80B7806880BFC2
:100A300080E090E008955E9A80E290E0BDD35E98F9
:100A400084E090E0B9D308955E9A84E190E0B4D355
:100A50005E9880E190E0B0D3089580919A0380FF82
:100A600002C0F2DF01C0E7DF10929A0381E090E05C
:100A700008950F931F93062F683011F4182F0CC0A0
:100A8000282F332788E090E0861B910902C0220FAF
:100A9000331F8A95E2F7122F17FF07C0D5DF809129
:100AA0009A038F5F80939A0301C0C5DF015011F054
:100AB000110FF2CF81E090E01F910F9108955E9A9F
:100AC00086EA90E079D35E988EE190E075D381E07C
:100AD00090E00895CF93DF9380916F008E7F809395
:100AE0006F008091C1008F778093C10083E085BD46
:100AF00081E086BD80E003C086B5893140F500B64F
:100B000005FEFACFFACFFF27E559FC4F68E0808158
:100B1000B0DFA3DF99DFEC2F219680914F03E81718
:100B200090F35E985698579880B78F7780BF8091E2
:100B30006F00816080936F008091C1008068809316
:100B4000C1008091AE03882369F167DD2BC05E9AF6
:100B5000569A579A80B7806880BFB1DF61E080E025
:100B600088DF10929A0364E080919B0382DF68E043
:100B700080919F037EDF71DF64E081E07ADF68E0CF
:100B80008FEF77DF6ADF60DF64E08FE072DF65DFC1
:100B90005BDF68E080914F036CDF5FDF55DFC0E013
:100BA000D0E0B9CF80E090E0DF91CF9108952FE0C1
:100BB00020932A0360934F03DC0190E007C0E92FE4
:100BC000FF27E559FC4F8D9180839F5F9617B9F7FA
:100BD00081DF992708951F93CF93DF9380916F0052
:100BE0008E7F80936F008091C1008F778093C100CA
:100BF00083E085BD81E086BD80E004C086B5893193
:100C000008F09AC000B605FEF9CFF9CF5E98569865
:100C1000579880B78F7780BF80916F0081608093F5
:100C20006F008091C10080688093C10083EA91E0E9
:100C300088D281E090E0A3C064E08FE01ADF0DDF8E
:100C4000D1DE8823B1F05E985698579880B78F7799
:100C500080BF80916F00816080936F008091C100A0
:100C600080688093C10087EA91E06BD282E090E0D7
:100C700086C068E080914F03FCDEEFDEB3DE8823A0
:100C8000E9F15E985698579880B78F7780BF80912A
:100C90006F00816080936F008091C10080688093B5
:100CA000C1008BEA91E04DD283E090E068C0E12F73
:100CB000FF27E559FC4F68E08081DBDECEDE92DE67
:100CC00021968823E9F05E985698579880B78F77D9
:100CD00080BF80916F00816080936F008091C10020
:100CE00080688093C1008FEA91E02BD2812FE9D1F7
:100CF00083EB91E026D284E090E041C0C0E0D0E0F8
:100D00001C2F80914F03C81790F25E985698579801
:100D100080B78F7780BF80916F00816080936F0074
:100D20008091C10080688093C1008091AE038111E1
:100D300074DC80E090E023C05E9A569A579A80B7A0
:100D4000806880BFBCDE61E081E093DE10929A0390
:100D500064E080919B038DDE68E080919F0389DED3
:100D60007CDE64E08091940384DE68E080919E03E1
:100D700080DE73DE37DE882309F048CF5DCFDF9158
:100D8000CF911F9108952FE020932A0360934F0382
:100D9000DC0190E007C0E92FFF27E559FC4F8D915A
:100DA00080839F5F9617B9F716DF99270895CF9331
:100DB000DF93FC0130818FE080932A03218120930F
:100DC0004F03DF0190E008C0E92FFF27E559FC4FF2
:100DD000ED01898180839F5F11969217A9F73323D4
:100DE00011F0F9DE01C076DE9927DF91CF910895E9
:100DF000CF93DF93CDB7DEB72D970FB6F894DEBF54
:100E00000FBECDBFDE011196EEE9F2E08DE001905C
:100E10000D928150E1F78091980388878091960325
:100E200089878091A1038A878091A0038B871C8684
:100E3000CE010196BCDF2D960FB6F894DEBF0FBE33
:100E4000CDBFDF91CF91089589E193E0B0DF882392
:100E500059F58DE093E0ABDF882331F581E093E035
:100E6000A6DF882309F585EF92E0A1DF8823E1F46E
:100E700089EE92E09CDF8823B9F48DED92E097DF54
:100E8000882391F481ED92E092DF882369F484EC69
:100E900092E08DDF882341F488EB92E088DF88239D
:100EA00019F48BEA92E083DF992708951F938091CC
:100EB0009D03883098F4863008F048C0833039F1BB
:100EC000843030F48130E9F0823009F091C01CC0E8
:100ED000843001F1853009F08BC033C0853601F1D3
:100EE000863638F48A3008F462C0843609F080C04F
:100EF00014C08736C1F18736A8F08E3609F475C064
:100F000077C084E292E06EC08AE292E06BC080E338
:100F100092E068C086E392E065C08DE192E062C035
:100F200093DF61C08DE392E042DF182F10929C03A3
:100F3000809143028F5F8093430286EB91E001D161
:100F400058C0109295038BE592E04CC01092950327
:100F500082E692E02CDF182F882311F589E692E0D3
:100F600026DF182F1DC081E0809395038EEB91E062
:100F7000E8D08091980380937D02809196038093BE
:100F80007E028091A10380937F028091A0038093D1
:100F9000800286E792E00BDF182F882309F428DF10
:100FA00081E090E090932D0380932C0322C0109257
:100FB0002D0310922C031092950383E892E0F7DE44
:100FC000809198038093910280919603809392027E
:100FD0008091A103809393028091A0038093940257
:100FE0008AE892E0E4DE182F04C087E992E0DFDEB1
:100FF00010E010929D03812F99271F9108958093EF
:101000009D0354DF9927089584EC91E09AD08DE1F7
:1010100092E0CDDE8CEC91E094D085E6F0DF08958F
:10102000209A289810928D03109251031092C000BC
:1010300088E98093C10086E08093C20087E090E059
:101040009093C5008093C40008951F920F920FB62D
:101050000F9211248F939F93EF93FF9380918D03B1
:101060009091C600E2E5F3E0E80FF11D90838F5FF9
:1010700080938D03FF91EF919F918F910F900FBE01
:101080000F901F901895982F8091C00085FFFCCF7E
:101090009093C60008958F70982F905D9A3308F052
:1010A000995F8091C00085FFFCCF9093C6000895A2
:1010B0001F93182F82958F70EEDF812FECDF1F9129
:1010C0000895E82F843640F08091C00085FFFCCF62
:1010D0008AE28093C60008958A3030F48091C0007F
:1010E00085FFFCCFE05D1DC0FF27CF016AE070E007
:1010F000A0D0CB01880F991F9B0143E0220F331F23
:101100004A95E1F7820F931FE81BE05D8091C000D4
:1011100085FFFCCF605D6093C6008091C00085FFB5
:10112000FCCFE093C6000895982F8A3038F4809160
:10113000C00085FFFCCF80E38093C600892FC1DF0C
:101140000895FC012DE00EC09A3031F48091C0006A
:1011500085FFFCCF2093C6008091C00085FFFCCFA7
:101160009093C6009191992379F70895FC014DE081
:101170000FC09A3031F48091C00085FFFCCF4093BE
:10118000C6008091C00085FFFCCF9093C600F90196
:101190009F012F5F3F4F9491992359F70895DC01E8
:1011A000CB0181159105A105B10529F08150904031
:1011B000A040B040D9F70895AC0120E030E006C06F
:1011C000000000000000000000000000822F9927AE
:1011D0002F5F3F4F8417950798F30895CF93DF93C0
:1011E000CDB7DEB721970FB6F894DEBF0FBECDBFE7
:1011F000898381E085BD21E005C026BD96B5898142
:101200009817E0F36150C8F721960FB6F894DEBF47
:101210000FBECDBFDF91CF910895991B79E004C037
:10122000991F961708F0961B881F7A95C9F7809525
:101230000895AA1BBB1B51E107C0AA1FBB1FA6171D
:10124000B70710F0A61BB70B881F991F5A95A9F76F
:0C12500080959095BC01CD010895FFCF62
:10125C00444556204944205345543A203078000ADE
:10126C0000444556204944203E200A004855204958
:10127C0044205345543A20307800485520494420A6
:10128C003E200A00524541442053455155454E439A
:10129C0045203E200A005245474953543A0A004C17
:1012AC006F67204F46460A004C6F67204F4E0A006E
:1012BC00737472204F46460A00737472204F4E0AA4
:1012CC00004355525245454E542053455155454EB9
:1012DC004345203E20000A006469722920007C20CE
:1012EC000020004C414E3E54310A004C414E3E54BD
:1012FC00320A0045310A0045320A0045330A0045DE
:10130C00342800290A0041564343484B0A00504CEC
:10131C0041590A005245475F53540A005245475FF2
:10132C00454E440A00040000010A040000010804B0
:10133C000000010D040000010C0300010A0312015E
:10134C000003120101031201200412014563040081
:10135C0025638006001263420100060012634241BD
:10136C0000050012634301050012634341010500AF
:10137C000112106301040001001A0104000100189D
:10138C0001040001001D01050001001C0001060004
:10139C0001123000000105005C12530200055C31A3
:1013AC00F100000106005C32F0020001050063123E
:1013BC00500101050063125201000B6331F1010071
:1013CC0001FFFFFF0080000B6331F10128000000DA
:1013DC0000008001050063125301000B6331F10022
:1013EC003000000000008001050063296002000B42
:1013FC006331F10110010100000080000B6331F139
:10140C00003001FFFFFF0080000A6331F300010090
:10141C0001000102000B6331F1009001FFFFFF009E
:10142C0080000A6331F300210001000102000A630D
:10143C0031F300310001000102000A6331F300397D
:10144C000001000102000A6331F3003D00010001BC
:10145C0002000A6331F3003F0001000102000A633D
:10146C0031F3003F0000000002000B6331F10080FB
:06147C00FFFFFFFF0080EE
:00000001FF

BIN
default/sniffer.o Normal file

Binary file not shown.

72
delay2.c Normal file
View File

@ -0,0 +1,72 @@
/*
Precise Delay Functions
V 0.5, Martin Thomas, 9/2004
In the original Code from Peter Dannegger a timer-interrupt
driven "timebase" has been used for precise One-Wire-Delays.
My loop-approach is less elegant but may be more usable
as library-function. Since it's not "timer-dependent"
See also delay.h.
Inspired by the avr-libc's loop-code
*/
#include <avr/io.h>
#include <avr/io.h>
#include <inttypes.h>
#include "delay2.h"
#include "timer.h"
void delayloop32(uint32_t loops)
{
__asm__ volatile ( "cp %A0,__zero_reg__ \n\t" \
"cpc %B0,__zero_reg__ \n\t" \
"cpc %C0,__zero_reg__ \n\t" \
"cpc %D0,__zero_reg__ \n\t" \
"breq L_Exit_%= \n\t" \
"L_LOOP_%=: \n\t" \
"subi %A0,1 \n\t" \
"sbci %B0,0 \n\t" \
"sbci %C0,0 \n\t" \
"sbci %D0,0 \n\t" \
"brne L_LOOP_%= \n\t" \
"L_Exit_%=: \n\t" \
: "=w" (loops) \
: "0" (loops) \
); \
return;
}
//------------------------------------------------------------------------------
// delay ~ 1us * count for F_CPU = 14745600;
void delay1(u16 count)
{
u08 j;
for (j=0;j<count;j++) {
__asm__ volatile ( \
"nop\n\t" \
"nop\n\t" \
"nop\n\t" \
"nop\n\t" \
"nop\n\t" \
"nop\n\t" \
);
}
}
//------------------------------------------------------------------------------
void delay1us(volatile u08 delay, u08 count)
{
timer0_source(CK);
while (count-- !=0)
{
timer0_start();
while (TCNT0 < delay);
}
}
//------------------------------------------------------------------------------

66
delay2.h Normal file
View File

@ -0,0 +1,66 @@
/*
Copyright (C) 2006 Marcin Slonicki <marcin@softservice.com.pl>.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-----------------------------------------------------------------------
this file is a part of the TOYOTA Corolla MP3 Player Project
-----------------------------------------------------------------------
http://www.softservice.com.pl/corolla/avc
May 28 / 2009 - version 2
*/
#ifndef _delay_h_
#define _delay_h_
#include <inttypes.h>
#include <avr/io.h>
#include "const.h"
/* delay function for microsec
4 cpu cycles per loop + 1 cycles(?) overhead
when a constant is passed. */
static inline void delayloop16(uint16_t count)
{
asm volatile ( "cp %A0,__zero_reg__ \n\t" \
"cpc %B0,__zero_reg__ \n\t" \
"breq L_Exit_%= \n\t" \
"L_LOOP_%=: \n\t" \
"sbiw %0,1 \n\t" \
"brne L_LOOP_%= \n\t" \
"L_Exit_%=: \n\t" \
: "=w" (count)
: "0" (count)
);
}
// delayloop16(x) eats 4 cycles per x
#define DELAY_US_CONV(us) ((uint16_t)(((((us)*1000L)/(1000000000/F_CPU))-1)/4))
#define delay_us(us) delayloop16(DELAY_US_CONV(us))
/* delay function for millisec
(6 cycles per x + 20(?) overhead) */
void delayloop32( uint32_t l); // not inline
#define DELAY_MS_CONV(ms) ( (uint32_t) (ms*(F_CPU/6000L)) )
#define delay_ms(ms) delayloop32(DELAY_MS_CONV(ms))
void delay1us(volatile u08 delay, u08 count);
void delay1(u16 count);
#endif

1
sniffer.aps Normal file
View File

@ -0,0 +1 @@
<AVRStudio><MANAGEMENT><ProjectName>sniffer</ProjectName><Created>25-May-2009 21:45:09</Created><LastEdit>25-May-2009 23:55:14</LastEdit><ICON>241</ICON><ProjectType>0</ProjectType><Created>25-May-2009 21:45:09</Created><Version>4</Version><Build>4, 13, 0, 528</Build><ProjectTypeName>AVR GCC</ProjectTypeName></MANAGEMENT><CODE_CREATION><ObjectFile>default\sniffer.elf</ObjectFile><EntryFile></EntryFile><SaveFolder>C:\Users\ms1\Documents\Corolla_DVR\_uptodate\sniffer\</SaveFolder></CODE_CREATION><DEBUG_TARGET><CURRENT_TARGET>AVR Simulator</CURRENT_TARGET><CURRENT_PART>ATmega88.xml</CURRENT_PART><BREAKPOINTS></BREAKPOINTS><IO_EXPAND><HIDE>false</HIDE></IO_EXPAND><REGISTERNAMES><Register>R00</Register><Register>R01</Register><Register>R02</Register><Register>R03</Register><Register>R04</Register><Register>R05</Register><Register>R06</Register><Register>R07</Register><Register>R08</Register><Register>R09</Register><Register>R10</Register><Register>R11</Register><Register>R12</Register><Register>R13</Register><Register>R14</Register><Register>R15</Register><Register>R16</Register><Register>R17</Register><Register>R18</Register><Register>R19</Register><Register>R20</Register><Register>R21</Register><Register>R22</Register><Register>R23</Register><Register>R24</Register><Register>R25</Register><Register>R26</Register><Register>R27</Register><Register>R28</Register><Register>R29</Register><Register>R30</Register><Register>R31</Register></REGISTERNAMES><COM>Auto</COM><COMType>0</COMType><WATCHNUM>0</WATCHNUM><WATCHNAMES><Pane0></Pane0><Pane1></Pane1><Pane2></Pane2><Pane3></Pane3></WATCHNAMES><BreakOnTrcaeFull>0</BreakOnTrcaeFull></DEBUG_TARGET><Debugger><Triggers></Triggers></Debugger><AVRGCCPLUGIN><FILES><SOURCEFILE>sniffer.c</SOURCEFILE><SOURCEFILE>avclandrv.c</SOURCEFILE><SOURCEFILE>com232.c</SOURCEFILE><SOURCEFILE>const.c</SOURCEFILE><SOURCEFILE>delay2.c</SOURCEFILE><HEADERFILE>avclandrv.h</HEADERFILE><HEADERFILE>com232.h</HEADERFILE><HEADERFILE>timer.h</HEADERFILE><HEADERFILE>const.h</HEADERFILE><HEADERFILE>delay2.h</HEADERFILE></FILES><CONFIGS><CONFIG><NAME>default</NAME><USESEXTERNALMAKEFILE>NO</USESEXTERNALMAKEFILE><EXTERNALMAKEFILE></EXTERNALMAKEFILE><PART>atmega88</PART><HEX>1</HEX><LIST>0</LIST><MAP>0</MAP><OUTPUTFILENAME>sniffer.elf</OUTPUTFILENAME><OUTPUTDIR>default\</OUTPUTDIR><ISDIRTY>0</ISDIRTY><OPTIONS/><INCDIRS/><LIBDIRS/><LIBS/><LINKOBJECTS/><OPTIONSFORALL>-Wall -gdwarf-2 -DF_CPU=14745000UL -Os -fsigned-char</OPTIONSFORALL><LINKEROPTIONS></LINKEROPTIONS><SEGMENTS/></CONFIG></CONFIGS><LASTCONFIG>default</LASTCONFIG><USES_WINAVR>1</USES_WINAVR><GCC_LOC>C:\WinAVR\bin\avr-gcc.exe</GCC_LOC><MAKE_LOC>C:\WinAVR\utils\bin\make.exe</MAKE_LOC></AVRGCCPLUGIN><IOView><usergroups/></IOView><Files><File00000><FileId>00000</FileId><FileName>sniffer.c</FileName><Status>1</Status></File00000><File00001><FileId>00001</FileId><FileName>com232.h</FileName><Status>1</Status></File00001><File00002><FileId>00002</FileId><FileName>com232.c</FileName><Status>1</Status></File00002><File00003><FileId>00003</FileId><FileName>avclandrv.c</FileName><Status>1</Status></File00003><File00004><FileId>00004</FileId><FileName>avclandrv.h</FileName><Status>1</Status></File00004><File00005><FileId>00005</FileId><FileName>const.h</FileName><Status>1</Status></File00005><File00006><FileId>00006</FileId><FileName>timer.h</FileName><Status>1</Status></File00006><File00007><FileId>00007</FileId><FileName>delay2.h</FileName><Status>1</Status></File00007><File00008><FileId>00008</FileId><FileName>delay2.c</FileName><Status>1</Status></File00008><File00009><FileId>00009</FileId><FileName>const.c</FileName><Status>1</Status></File00009></Files><Workspace><File00000><Position>242 97 1128 572</Position><LineCol>254 4</LineCol></File00000><File00001><Position>265 120 1168 590</Position><LineCol>8 0</LineCol></File00001><File00002><Position>288 143 1191 613</Position><LineCol>23 0</LineCol></File00002><File00003><Position>234 69 1360 782</Position><LineCol>117 14</LineCol><State>Maximized</State></File00003><File00004><Position>334 189 1237 659</Position><LineCol>46 28</LineCol></File00004><File00005><Position>357 212 1260 682</Position><LineCol>44 3</LineCol></File00005><File00006><Position>380 235 1283 705</Position><LineCol>53 10</LineCol></File00006><File00007><Position>403 258 1306 728</Position><LineCol>0 0</LineCol></File00007><File00008><Position>426 281 1329 751</Position><LineCol>17 16</LineCol></File00008><File00009><Position>449 304 1352 774</Position><LineCol>0 0</LineCol></File00009></Workspace><Events><Bookmarks></Bookmarks></Events><Trace><Filters></Filters></Trace></AVRStudio>

1
sniffer.aws Normal file
View File

@ -0,0 +1 @@
<AVRWorkspace><IOSettings><CurrentRegisters/></IOSettings><part name="ATMEGA88"/><Files><File00000 Name="C:\Users\ms1\Documents\Corolla_DVR\_uptodate\sniffer\sniffer.c" Position="234 71 1360 784" LineCol="246 0" State="Maximized"/><File00001 Name="C:\Users\ms1\Documents\Corolla_DVR\_uptodate\sniffer\com232.h" Position="256 114 1159 584" LineCol="33 0" State="Maximized"/><File00002 Name="C:\Users\ms1\Documents\Corolla_DVR\_uptodate\sniffer\com232.c" Position="279 137 1182 607" LineCol="69 46" State="Maximized"/><File00003 Name="C:\Users\ms1\Documents\Corolla_DVR\_uptodate\sniffer\avclandrv.c" Position="225 63 1351 776" LineCol="742 0" State="Maximized"/><File00004 Name="C:\Users\ms1\Documents\Corolla_DVR\_uptodate\sniffer\avclandrv.h" Position="325 183 1228 653" LineCol="137 0" State="Maximized"/><File00005 Name="C:\Users\ms1\Documents\Corolla_DVR\_uptodate\sniffer\const.h" Position="348 206 1251 676" LineCol="25 0" State="Maximized"/><File00006 Name="C:\Users\ms1\Documents\Corolla_DVR\_uptodate\sniffer\timer.h" Position="234 69 1360 782" LineCol="1 0" State="Maximized"/><File00007 Name="C:\Users\ms1\Documents\Corolla_DVR\_uptodate\sniffer\delay2.h" Position="394 252 1297 722" LineCol="25 0" State="Maximized"/><File00008 Name="C:\Users\ms1\Documents\Corolla_DVR\_uptodate\sniffer\delay2.c" Position="417 275 1320 745" LineCol="0 0" State="Maximized"/><File00009 Name="C:\Users\ms1\Documents\Corolla_DVR\_uptodate\sniffer\const.c" Position="231 67 1357 780" LineCol="26 0" State="Maximized"/></Files></AVRWorkspace>

293
sniffer.c Normal file
View File

@ -0,0 +1,293 @@
/*
Copyright (C) 2006 Marcin Slonicki <marcin@softservice.com.pl>.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-----------------------------------------------------------------------
this file is a part of the TOYOTA Corolla MP3 Player Project
-----------------------------------------------------------------------
http://www.softservice.com.pl/corolla/avc
May 28 / 2009 - version 2
*/
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include "const.h"
#include "com232.h"
#include "delay2.h"
#include "avclandrv.h"
// -------------------------------------------------------------------------------------
void Setup();
u08 rcv_command[5];
u08 rcv_pos = 0;
u08 rcv_time_clr = 0;
// -------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
// MAIN PROGRAM
//
int main()
{
// u08 h;
u08 readSeq = 0;
u08 s_len = 0;
u08 s_dig = 0;
u08 s_c[2];
u08 i;
u08 data_tmp[32];
Setup();
RS232_S((u16)PSTR("AVCLan reader 1.00\nReady\n\n"));
LED_OFF();
RS232_S((u16)PSTR("T - device id\n"));
RS232_S((u16)PSTR("H - HU id\n"));
RS232_S((u16)PSTR("S - read sequence\n"));
RS232_S((u16)PSTR("W - send command\n"));
RS232_S((u16)PSTR("Q - send broadcast\n"));
RS232_S((u16)PSTR("L/l - log on/off\n"));
RS232_S((u16)PSTR("K/k - seq. echo on/off\n"));
RS232_S((u16)PSTR("R/r - register device\n"));
while (1) {
if (INPUT_IS_SET) { // if message from some device on AVCLan begin
LED_ON();
AVCLan_Read_Message();
// show message
} else {
LED_OFF();
// check command from HU
if (answerReq != 0) AVCLan_SendAnswer();
}
// HandleEvent
switch (Event) {
case EV_STATUS: Event &= ~EV_STATUS;
AVCLan_Send_Status();
break;
}
// Key handler
if (RS232_RxCharEnd) {
cbi(UCSR0B, RXCIE0); // disable RX complete interrupt
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; // do reset Buffer
sbi(UCSR0B, RXCIE0); // enable RX complete interrupt
switch (readkey) {
case 'T': if (readSeq) {
CD_ID_1 = data_tmp[0];
CD_ID_2 = data_tmp[1];
RS232_Print("DEV ID SET: 0x");
RS232_PrintHex8(CD_ID_1);
RS232_PrintHex8(CD_ID_2);
RS232_Print("\n");
showLog = 1;
readSeq=0;
} else {
showLog = 0;
RS232_Print("DEV ID > \n");
readSeq = 1;
s_len=0;
s_dig=0;
s_c[0]=s_c[1]=0;
}
break;
case 'H': if (readSeq) {
HU_ID_1 = data_tmp[0];
HU_ID_2 = data_tmp[1];
RS232_Print("HU ID SET: 0x");
RS232_PrintHex8(HU_ID_1);
RS232_PrintHex8(HU_ID_2);
RS232_Print("\n");
showLog = 1;
readSeq=0;
} else {
showLog = 0;
RS232_Print("HU ID > \n");
readSeq = 1;
s_len=0;
s_dig=0;
s_c[0]=s_c[1]=0;
}
break;
case 'S': showLog = 0;
RS232_Print("READ SEQUENCE > \n");
readSeq = 1;
s_len=0;
s_dig=0;
s_c[0]=s_c[1]=0;
break;
case 'W' : showLog = 1;
readSeq=0;
AVCLan_SendMyData(data_tmp, s_len);
break;
case 'Q' : showLog = 1;
readSeq=0;
AVCLan_SendMyDataBroadcast(data_tmp, s_len);
break;
case 'R': RS232_Print("REGIST:\n");
AVCLan_Command( cmRegister );
delay1(15);
CHECK_AVC_LINE;
break;
case 'r': AVCLan_Register();
break;
case 'l': RS232_Print("Log OFF\n");
showLog = 0;
break;
case 'L': RS232_Print("Log ON\n");
showLog = 1;
break;
case 'k': RS232_Print("str OFF\n");
showLog2 = 0;
break;
case 'K': RS232_Print("str ON\n");
showLog2 = 1;
break;
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;
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("CURREENT SEQUENCE > ");
for (i=0; i<s_len; i++) {
RS232_PrintHex8(data_tmp[i]);
RS232_SendByte(' ');
}
RS232_Print("\n");
}
}
} // switch (readkey)
}// if (RS232_RxCharEnd)
}
return 0;
}
// -------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
// Setup - uP: ATMega16
//
void Setup()
{
// GIMSK = 0; // (GICR ?) disable external interupts
CD_ID_1 = 0x02;
CD_ID_2 = 0x80;
HU_ID_1 = 0x01;
HU_ID_2 = 0x40;
showLog = 1;
showLog2 = 1;
MCUCR = 0;
TIMSK1 = 0;
sbi(TIMSK1, TOIE1); // Enable timer1 interrupt
// Timer 1
TCCR1A = 0;
TCCR1B = _BV(CS12);
TCNT1 = 0xFFFF - 0x7080;
RS232_Init();
AVCLan_Init();
Event = EV_NOTHING;
sei();
}
// -------------------------------------------------------------------------------------
u08 s1=0;
//------------------------------------------------------------------------------
SIGNAL(SIG_OVERFLOW1) // Timer1 overflow every 1Sec
{
TCNT1 = 0xFFFF - 0x7080;
s1++;
if (s1==2) {
s1=0;
if (CD_Mode==stPlay) {
cd_Time_Sec=HexInc(cd_Time_Sec);
if (cd_Time_Sec==0x60) {
cd_Time_Sec = 0;
cd_Time_Min=HexInc(cd_Time_Min);
if (cd_Time_Min==0xA0) {
cd_Time_Min=0x0;
}
}
Event |= EV_STATUS;
}
}
}
//------------------------------------------------------------------------------

74
timer.h Normal file
View File

@ -0,0 +1,74 @@
/* Copyright (c) 2002, Marek Michalkiewicz
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE. */
/* $Id: timer.h,v 1.4.2.2 2004/02/15 20:28:09 joerg_wunsch Exp $ */
#ifndef _AVR_TIMER_H_
#define _AVR_TIMER_H_
#include <avr/io.h>
#if defined(__AVR_ATmega128__) || defined(__AVR_ATmega64__)
# warning "This file is known to be incorrect for your MCU type"
#endif
#ifdef __cplusplus
extern "C" {
#endif
enum {
STOP = 0,
CK = 1,
CK8 = 2,
CK64 = 3,
CK256 = 4,
CK1024 = 5,
T0_FALLING_EDGE = 6,
T0_RISING_EDGE = 7
};
static __inline__ void timer0_source (unsigned int src)
{
TCCR0B = src;
}
/*
* NB: this is completely bogus.
*/
static __inline__ void timer0_stop (void)
{
TCNT0 = 0;
}
static __inline__ void timer0_start (void)
{
TCNT0 = 1;
}
#ifdef __cplusplus
}
#endif
#endif /* _AVR_TIMER_H_ */