mirror of
https://github.com/halleysfifthinc/Toyota-AVC-LAN
synced 2025-08-16 21:46:52 +00:00
Initial Commit
This commit is contained in:
commit
9091a232ab
967
AVCLanDriver.c
Normal file
967
AVCLanDriver.c
Normal file
@ -0,0 +1,967 @@
|
|||||||
|
/*--------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Name : AVCLanDriver.c
|
||||||
|
|
||||||
|
Description : AVC Lan driver for Toyota devices.
|
||||||
|
|
||||||
|
Author : Louis Frigon
|
||||||
|
|
||||||
|
Copyright : (c) 2007 SigmaObjects
|
||||||
|
|
||||||
|
----------------------------------------------------------------------------------------------------
|
||||||
|
AVC LAN Theory
|
||||||
|
|
||||||
|
The AVC bus is an implementation of the IEBus which is a differential line, floating on logical
|
||||||
|
level '1' and driving on logical '0'. Floating level shall be below 20 mV whereas driving level
|
||||||
|
shall be above 120 mV.
|
||||||
|
|
||||||
|
The diagram below represents how things work from a logical perspective on the bus.
|
||||||
|
|
||||||
|
A rising edge indicates a new bit. The duration of the high state tells whether it is a start
|
||||||
|
bit (~165 us), a bit '0' (~30 us) or a bit '1' (~20 us). A normal bit length is close to 40 us.
|
||||||
|
|
||||||
|
|<---- Bit '0' ---->|<---- Bit '1' ---->|
|
||||||
|
Physical '1' ,---------------, ,---------, ,---------
|
||||||
|
^ | ^ | ^
|
||||||
|
Physical '0' -----' '---' '---------'--------- Idle low
|
||||||
|
|---- 32 us ----| 7 |- 20 us -|- 19 us -|
|
||||||
|
|
||||||
|
A bit '1' is typically 20 us high followed by 19 us low.
|
||||||
|
|
||||||
|
A bit '0' is typically 32 us high followed by 7 us low. A bit '0' is dominant i.e. it takes
|
||||||
|
precedence over a '1' by extending the pulse. This is why lower addresses win on arbitration.
|
||||||
|
|
||||||
|
A start bit is typically 165 us high followed by 30 us low.
|
||||||
|
|
||||||
|
AVC LAN Frame Format
|
||||||
|
Bits Description
|
||||||
|
|
||||||
|
1 Start bit
|
||||||
|
1 MSG_NORMAL
|
||||||
|
12 Master address
|
||||||
|
1 Parity
|
||||||
|
12 Slave address
|
||||||
|
1 Parity
|
||||||
|
1 * Acknowledge * (read below)
|
||||||
|
4 Control
|
||||||
|
1 Parity
|
||||||
|
1 * Acknowledge * (read below)
|
||||||
|
8 Payload length (n)
|
||||||
|
1 Parity
|
||||||
|
1 * Acknowledge * (read below)
|
||||||
|
8 Data
|
||||||
|
1 Parity
|
||||||
|
1 * Acknowledge * (read below)
|
||||||
|
repeat 'n' times
|
||||||
|
|
||||||
|
In point-to-point communication, sender issues an ack bit with value '1' (20 us). Receiver
|
||||||
|
upon acking will extend the bit until it looks like a '0' (32 us) on the bus. In broadcast
|
||||||
|
mode, receiver disregards the bit.
|
||||||
|
|
||||||
|
An acknowledge bit of value '0' means OK, '1' means no ack.
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------------------------*/
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include <avr/interrupt.h>
|
||||||
|
#include <avr/wdt.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "GlobalDef.h"
|
||||||
|
#include "USART.h"
|
||||||
|
#include "AVCLanDriver.h"
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------------------------
|
||||||
|
Local Functions
|
||||||
|
--------------------------------------------------------------------------------------------------*/
|
||||||
|
static void SendStartBit ( void );
|
||||||
|
static void Send12BitWord ( word data );
|
||||||
|
static void Send8BitWord ( byte data );
|
||||||
|
static void Send4BitWord ( byte data );
|
||||||
|
static void Send1BitWord ( bool data );
|
||||||
|
static bool SendMessage ( void );
|
||||||
|
|
||||||
|
static word ReadBits ( byte nbBits );
|
||||||
|
static bool ReadAcknowledge ( void );
|
||||||
|
|
||||||
|
static bool HandleAcknowledge ( void );
|
||||||
|
static bool IsAvcBusFree ( void );
|
||||||
|
|
||||||
|
static AvcActionID GetActionID ( void );
|
||||||
|
static void LoadDataInGlogalRegisters ( AvcOutMessage * msg );
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------------------------
|
||||||
|
Global Variables
|
||||||
|
--------------------------------------------------------------------------------------------------*/
|
||||||
|
// Message frame global registers
|
||||||
|
static const char * Description;
|
||||||
|
static bool Broadcast;
|
||||||
|
static word MasterAddress;
|
||||||
|
static word SlaveAddress;
|
||||||
|
static byte Control;
|
||||||
|
static byte DataSize;
|
||||||
|
static bool ParityBit;
|
||||||
|
static byte Data[ 256 ];
|
||||||
|
|
||||||
|
bool AUX_Enabled = FALSE;
|
||||||
|
AvcActionID DeviceEnabled = ACT_NONE; //casting possibly unneccesary
|
||||||
|
|
||||||
|
static AvcInMessage MessageTable [] PROGMEM =
|
||||||
|
{
|
||||||
|
/*--------------------------------------------------------------------------------------------------
|
||||||
|
Head Unit (HU) Messages
|
||||||
|
0x60 = Tuner ID
|
||||||
|
0x61 = Tape ID
|
||||||
|
0x62 = CD ID
|
||||||
|
0x63 = CD Changer ID (this is what we're emulating)
|
||||||
|
--------------------------------------------------------------------------------------------------*/
|
||||||
|
{ ACT_AUX_IN_USE, 4, {0x11, 0x01, 0x45, 0x01}, "AUX in use" },
|
||||||
|
{ ACT_TUNER_IN_USE, 4, {0x11, 0x01, 0x45, 0x60}, "Tuner in use" },
|
||||||
|
{ ACT_TAPE_IN_USE, 4, {0x11, 0x01, 0x45, 0x61}, "Tape in use" },
|
||||||
|
{ ACT_CD_IN_USE, 4, {0x11, 0x01, 0x45, 0x62}, "CD in use" },
|
||||||
|
|
||||||
|
{ ACT_NONE, 3, {0x11, 0x01, 0x46}, "No device in use" },
|
||||||
|
{ ACT_NONE, 3, {0x11, 0x01, 0x20 /* xx */}, "Ping" }, // Get this once every minute in radio off mode. xx increments
|
||||||
|
{ ACT_TUNER_INFO, 5, {0x60, 0x31, 0xF1, 0x01, 0x01 /* xx xx xx 0x00 0x00 0x00 0x00 */ /* 81 0 C9 = 107.9 or 107.7*/}, "Tuner Status"},
|
||||||
|
{ ACT_EJECT_CD, 10, {0x62, 0x31, 0xF1, 0x00, 0x30, 0x01, 0x01, 0x00, 0x00, 0x00, 0x80}, "Eject CD" },
|
||||||
|
{ ACT_NO_CD, 10, {0x62, 0x31, 0xF1, 0x00, 0xF8, 0x01, 0x01, 0x00, 0x00, 0x00, 0x80}, "No CD" },
|
||||||
|
// { ACT_CD_INFO, 6, {0x62, 0x31, 0xF1, 0x01, 0x10, 0x01 /* Track #, Min, Sec, 0x00, 0x80 */}, "CD Info: " },
|
||||||
|
{ACT_AUDIO_STATUS, 4, { 0x74, 0x31, 0xF1, 0x90 /* Volume, Balance, Fade, Bass, 0x10, Treble, 0x00, 0x0F, 0x00, 0x00 */ }, "Audio Status"},
|
||||||
|
|
||||||
|
{ ACT_STATUS, 3, {0x00, 0x01, 0x0A}, "LAN Status" },
|
||||||
|
{ ACT_REGISTER, 3, {0x11, 0x01, 0x00}, "LAN Register" },
|
||||||
|
{ ACT_INIT, 3, {0x11, 0x01, 0x01}, "LAN Restart" },
|
||||||
|
{ ACT_CHECK, 3, {0x11, 0x01, 0x20}, "LAN Check" },
|
||||||
|
|
||||||
|
{ (AvcActionID)FALSE } //possibly should be ACT_NONE
|
||||||
|
};
|
||||||
|
|
||||||
|
const byte MessageTableSize = sizeof( MessageTable ) / sizeof( AvcInMessage );
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------------------------
|
||||||
|
Our (CD) Commands
|
||||||
|
--------------------------------------------------------------------------------------------------*/
|
||||||
|
AvcOutMessage CmdReset PROGMEM = { MSG_BCAST, 5, {0x00, 0x00, 0x00, 0x00, 0x00}, "Reset" }; // This causes HU to send ACT_REGISTER
|
||||||
|
|
||||||
|
//AvcOutMessage CmdRegister PROGMEM = { MSG_NORMAL, 5, {0x00, 0x01, 0x11, 0x10, 0x63}, "Register" };
|
||||||
|
//AvcOutMessage CmdRegister PROGMEM = { MSG_NORMAL, 5, {0x00, 0x01, 0x11, 0x54, 0x63}, "Toggle HU On/Off" };
|
||||||
|
//AvcOutMessage CmdRegister PROGMEM = { MSG_NORMAL, 5, {0x00, 0x01, 0x11, 0x54, 0x63}, "Toggle HU On/Off" };
|
||||||
|
AvcOutMessage CmdEnableAux PROGMEM = { MSG_NORMAL, 5, {0x00, 0x01, 0x11, 0x50, 0x61}, "Enable AUX" };
|
||||||
|
AvcOutMessage CmdDisableAux PROGMEM = { MSG_NORMAL, 5, {0x00, 0x01, 0x11, 0x51, 0x61}, "Disable AUX" };
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Name : AvcRegisterMe
|
||||||
|
|
||||||
|
Description : Sends registration message to master controller.
|
||||||
|
|
||||||
|
Argument(s) : None.
|
||||||
|
|
||||||
|
Return value : (bool) -> TRUE if successful else FALSE.
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------------------------*/
|
||||||
|
bool AvcRegisterMe ( void )
|
||||||
|
{
|
||||||
|
Broadcast = MSG_NORMAL;
|
||||||
|
MasterAddress = MY_ADDRESS;
|
||||||
|
SlaveAddress = HU_ADDRESS;
|
||||||
|
Control = CONTROL_FLAGS;
|
||||||
|
|
||||||
|
AvcProcessActionID( ACT_REGISTER );
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Name : AvcReadMessage
|
||||||
|
|
||||||
|
Description : Read incoming messages on the AVC LAN bus.
|
||||||
|
|
||||||
|
Argument(s) : None.
|
||||||
|
|
||||||
|
Return value : (AvcActionID) -> Action ID associated with this message.
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------------------------*/
|
||||||
|
AvcActionID AvcReadMessage ( void )
|
||||||
|
{
|
||||||
|
ReadBits( 1 ); // Start bit.
|
||||||
|
|
||||||
|
LedOn();
|
||||||
|
|
||||||
|
Broadcast = ReadBits( 1 );
|
||||||
|
|
||||||
|
MasterAddress = ReadBits( 12 );
|
||||||
|
bool p = ParityBit;
|
||||||
|
if ( p != ReadBits( 1 ) )
|
||||||
|
{
|
||||||
|
UsartPutCStr( PSTR("AvcReadMessage: Parity error @ MasterAddress!\r\n") );
|
||||||
|
return (AvcActionID)FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
SlaveAddress = ReadBits( 12 );
|
||||||
|
p = ParityBit;
|
||||||
|
if ( p != ReadBits( 1 ) )
|
||||||
|
{
|
||||||
|
UsartPutCStr( PSTR("AvcReadMessage: Parity error @ SlaveAddress!\r\n") );
|
||||||
|
return (AvcActionID)FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool forMe = ( SlaveAddress == MY_ADDRESS );
|
||||||
|
|
||||||
|
// In point-to-point communication, sender issues an ack bit with value '1' (20us). Receiver
|
||||||
|
// upon acking will extend the bit until it looks like a '0' (32us) on the bus. In broadcast
|
||||||
|
// mode, receiver disregards the bit.
|
||||||
|
|
||||||
|
if ( forMe )
|
||||||
|
{
|
||||||
|
// Send ACK.
|
||||||
|
Send1BitWord( 0 );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ReadBits( 1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
Control = ReadBits( 4 );
|
||||||
|
p = ParityBit;
|
||||||
|
if ( p != ReadBits( 1 ) )
|
||||||
|
{
|
||||||
|
UsartPutCStr( PSTR("AvcReadMessage: Parity error @ Control!\r\n") );
|
||||||
|
return (AvcActionID)FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( forMe )
|
||||||
|
{
|
||||||
|
// Send ACK.
|
||||||
|
Send1BitWord( 0 );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ReadBits( 1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
DataSize = ReadBits( 8 );
|
||||||
|
p = ParityBit;
|
||||||
|
if ( p != ReadBits( 1 ) )
|
||||||
|
{
|
||||||
|
UsartPutCStr( PSTR("AvcReadMessage: Parity error @ DataSize!\r\n") );
|
||||||
|
return (AvcActionID)FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( forMe )
|
||||||
|
{
|
||||||
|
// Send ACK.
|
||||||
|
Send1BitWord( 0 );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ReadBits( 1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
byte i;
|
||||||
|
|
||||||
|
for ( i = 0; i < DataSize; i++ )
|
||||||
|
{
|
||||||
|
Data[i] = ReadBits( 8 );
|
||||||
|
p = ParityBit;
|
||||||
|
if ( p != ReadBits( 1 ) )
|
||||||
|
{
|
||||||
|
sprintf( UsartMsgBuffer, "AvcReadMessage: Parity error @ Data[%d]\r\n", i );
|
||||||
|
UsartPutStr( UsartMsgBuffer );
|
||||||
|
return (AvcActionID)FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( forMe )
|
||||||
|
{
|
||||||
|
// Send ACK.
|
||||||
|
Send1BitWord( 0 );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ReadBits( 1 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dump message on terminal.
|
||||||
|
if ( forMe ) UsartPutCStr( PSTR("AvcReadMessage: This message is for me!\r\n") );
|
||||||
|
|
||||||
|
AvcActionID actionID = GetActionID();
|
||||||
|
|
||||||
|
// switch ( actionID ) {
|
||||||
|
// case /* value */:
|
||||||
|
// }
|
||||||
|
DumpRawMessage( FALSE );
|
||||||
|
|
||||||
|
LedOff();
|
||||||
|
|
||||||
|
return actionID;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Name : AvcProcessActionID
|
||||||
|
|
||||||
|
Description : Perform processing for given action ID.
|
||||||
|
|
||||||
|
Argument(s) : actionID (AvcActionID) -> Action ID to process.
|
||||||
|
|
||||||
|
Return value : (bool) -> TRUE if action performed.
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------------------------*/
|
||||||
|
bool AvcProcessActionID ( AvcActionID actionID )
|
||||||
|
{
|
||||||
|
// This function relies on the last received message still being loaded in global registers.
|
||||||
|
|
||||||
|
switch ( actionID )
|
||||||
|
{
|
||||||
|
case ACT_AUX_IN_USE:
|
||||||
|
|
||||||
|
AUX_Enabled = TRUE;
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
case ACT_TUNER_IN_USE:
|
||||||
|
case ACT_TAPE_IN_USE:
|
||||||
|
// case ACT_AUDIO_STATUS: This is where we should print interpretted data (Volume, Balance, etc.)
|
||||||
|
// case ACT_TUNER_INFO: Same here
|
||||||
|
case ACT_CD_IN_USE:
|
||||||
|
|
||||||
|
DeviceEnabled = actionID;
|
||||||
|
AUX_Enabled = FALSE;
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
// case ACT_NO_CD:
|
||||||
|
|
||||||
|
case ACT_EJECT_CD:
|
||||||
|
|
||||||
|
// Normal CD eject command.
|
||||||
|
if ( DeviceEnabled == ACT_CD_IN_USE ) return FALSE;
|
||||||
|
|
||||||
|
if ( AUX_Enabled )
|
||||||
|
{
|
||||||
|
LoadDataInGlogalRegisters ( &CmdDisableAux );
|
||||||
|
AUX_Enabled = FALSE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LoadDataInGlogalRegisters ( &CmdEnableAux );
|
||||||
|
AUX_Enabled = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return SendMessage();
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
|
||||||
|
// No success!
|
||||||
|
UsartPutCStr( PSTR("AvcProcessActionID: Unknown action ID!\r\n") );
|
||||||
|
//POssibly dumpmsgbuffer here for sebuggimng
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Nothing to do!
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Name : LoadDataInGlogalRegisters
|
||||||
|
|
||||||
|
Description : Loads message data in global registers for given mesage ID.
|
||||||
|
|
||||||
|
Argument(s) : msg (AvcOutMessage *) -> Message to load.
|
||||||
|
|
||||||
|
Return value : None.
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------------------------*/
|
||||||
|
void LoadDataInGlogalRegisters ( AvcOutMessage * msg )
|
||||||
|
{
|
||||||
|
Description = msg->Description;
|
||||||
|
|
||||||
|
Broadcast = pgm_read_byte_near( &msg->Mode );
|
||||||
|
|
||||||
|
MasterAddress = MY_ADDRESS;
|
||||||
|
|
||||||
|
if ( Broadcast == MSG_BCAST )
|
||||||
|
SlaveAddress = BROADCAST_ADDRESS;
|
||||||
|
else
|
||||||
|
SlaveAddress = HU_ADDRESS;
|
||||||
|
|
||||||
|
DataSize = pgm_read_byte_near( &msg->DataSize );
|
||||||
|
|
||||||
|
for ( byte i = 0; i < DataSize; i++ )
|
||||||
|
{
|
||||||
|
Data[i] = pgm_read_byte_near( &msg->Data[i] );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Name : GetActionID
|
||||||
|
|
||||||
|
Description : Use the last received message to determine the corresponding action ID.
|
||||||
|
|
||||||
|
Argument(s) : None.
|
||||||
|
|
||||||
|
Return value : (AvcActionID) -> Action ID corresponding to current message.
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------------------------*/
|
||||||
|
AvcActionID GetActionID ( void )
|
||||||
|
{
|
||||||
|
Description = PSTR("Unknown message!");
|
||||||
|
|
||||||
|
// Iterate through all HU messages in table.
|
||||||
|
for ( byte msg = 0; msg < MessageTableSize; msg++ )
|
||||||
|
{
|
||||||
|
bool found = TRUE;
|
||||||
|
|
||||||
|
// Identify current message from it's payload data.
|
||||||
|
for ( byte i = 0; i < pgm_read_byte_near( &MessageTable[msg].DataSize ); i++ )
|
||||||
|
{
|
||||||
|
if ( Data[i] != pgm_read_byte_near( &MessageTable[msg].Data[i] ) )
|
||||||
|
{
|
||||||
|
found = FALSE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( found )
|
||||||
|
{
|
||||||
|
Description = MessageTable[msg].Description;
|
||||||
|
|
||||||
|
// Fetch action corresponding to the message.
|
||||||
|
AvcActionID actionID = pgm_read_byte_near( &MessageTable[msg].ActionID );
|
||||||
|
|
||||||
|
return actionID;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ACT_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Name : Send12BitWord
|
||||||
|
|
||||||
|
Description : Writes a 12 bit word on the AVC LAN bus.
|
||||||
|
|
||||||
|
Argument(s) : data (word) -> Data to write.
|
||||||
|
|
||||||
|
Return value : None.
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------------------------*/
|
||||||
|
void Send12BitWord ( word data )
|
||||||
|
{
|
||||||
|
ParityBit = 0;
|
||||||
|
|
||||||
|
// Most significant bit out first.
|
||||||
|
for ( char nbBits = 0; nbBits < 12; nbBits++ )
|
||||||
|
{
|
||||||
|
// Reset timer to measure bit length.
|
||||||
|
TCNT0 = 0;
|
||||||
|
|
||||||
|
// Drive output to signal high.
|
||||||
|
DDRD |= _BV(PD2) | _BV(PD3);
|
||||||
|
|
||||||
|
if ( data & 0x0800 )
|
||||||
|
{
|
||||||
|
// Adjust parity.
|
||||||
|
ParityBit = ! ParityBit;
|
||||||
|
|
||||||
|
while ( TCNT0 < BIT_1_HOLD_ON_LENGTH );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
while ( TCNT0 < BIT_0_HOLD_ON_LENGTH );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Release output.
|
||||||
|
DDRD &= ~( _BV(PD2) | _BV(PD3) );
|
||||||
|
|
||||||
|
// Hold output low until end of bit.
|
||||||
|
while ( TCNT0 < NORMAL_BIT_LENGTH );
|
||||||
|
|
||||||
|
// Fetch next bit.
|
||||||
|
data <<= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Name : Send8BitWord
|
||||||
|
|
||||||
|
Description : Writes an 8 bit word on the AVC LAN bus.
|
||||||
|
|
||||||
|
Argument(s) : data (byte) -> Data to write.
|
||||||
|
|
||||||
|
Return value : None.
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------------------------*/
|
||||||
|
void Send8BitWord ( byte data )
|
||||||
|
{
|
||||||
|
ParityBit = 0;
|
||||||
|
|
||||||
|
// Most significant bit out first.
|
||||||
|
for ( char nbBits = 0; nbBits < 8; nbBits++ )
|
||||||
|
{
|
||||||
|
// Reset timer to measure bit length.
|
||||||
|
TCNT0 = 0;
|
||||||
|
|
||||||
|
// Drive output to signal high.
|
||||||
|
DDRD |= _BV(PD2) | _BV(PD3);
|
||||||
|
|
||||||
|
if ( data & 0x80 )
|
||||||
|
{
|
||||||
|
// Adjust parity.
|
||||||
|
ParityBit = ! ParityBit;
|
||||||
|
|
||||||
|
while ( TCNT0 < BIT_1_HOLD_ON_LENGTH );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
while ( TCNT0 < BIT_0_HOLD_ON_LENGTH );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Release output.
|
||||||
|
DDRD &= ~( _BV(PD2) | _BV(PD3) );
|
||||||
|
|
||||||
|
// Hold output low until end of bit.
|
||||||
|
while ( TCNT0 < NORMAL_BIT_LENGTH );
|
||||||
|
|
||||||
|
// Fetch next bit.
|
||||||
|
data <<= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Name : Send4BitWord
|
||||||
|
|
||||||
|
Description : Writes a 4 bit word on the AVC LAN bus.
|
||||||
|
|
||||||
|
Argument(s) : data (byte) -> Data to write.
|
||||||
|
|
||||||
|
Return value : None.
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------------------------*/
|
||||||
|
void Send4BitWord ( byte data )
|
||||||
|
{
|
||||||
|
ParityBit = 0;
|
||||||
|
|
||||||
|
// Most significant bit out first.
|
||||||
|
for ( char nbBits = 0; nbBits < 4; nbBits++ )
|
||||||
|
{
|
||||||
|
// Reset timer to measure bit length.
|
||||||
|
TCNT0 = 0;
|
||||||
|
|
||||||
|
// Drive output to signal high.
|
||||||
|
DDRD |= _BV(PD2) | _BV(PD3);
|
||||||
|
|
||||||
|
if ( data & 0x8 )
|
||||||
|
{
|
||||||
|
// Adjust parity.
|
||||||
|
ParityBit = ! ParityBit;
|
||||||
|
|
||||||
|
while ( TCNT0 < BIT_1_HOLD_ON_LENGTH );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
while ( TCNT0 < BIT_0_HOLD_ON_LENGTH );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Release output.
|
||||||
|
DDRD &= ~( _BV(PD2) | _BV(PD3) );
|
||||||
|
|
||||||
|
// Hold output low until end of bit.
|
||||||
|
while ( TCNT0 < NORMAL_BIT_LENGTH );
|
||||||
|
|
||||||
|
// Fetch next bit.
|
||||||
|
data <<= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Name : Send1BitWord
|
||||||
|
|
||||||
|
Description : Writes a 1 bit word on the AVC LAN bus.
|
||||||
|
|
||||||
|
Argument(s) : data (bool) -> Data to write.
|
||||||
|
|
||||||
|
Return value : None.
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------------------------*/
|
||||||
|
void Send1BitWord ( bool data )
|
||||||
|
{
|
||||||
|
// Reset timer to measure bit length.
|
||||||
|
TCNT0 = 0;
|
||||||
|
|
||||||
|
// Drive output to signal high.
|
||||||
|
DDRD |= _BV(PD2) | _BV(PD3);
|
||||||
|
|
||||||
|
if ( data )
|
||||||
|
{
|
||||||
|
while ( TCNT0 < BIT_1_HOLD_ON_LENGTH );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
while ( TCNT0 < BIT_0_HOLD_ON_LENGTH );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Release output.
|
||||||
|
DDRD &= ~( _BV(PD2) | _BV(PD3) );
|
||||||
|
|
||||||
|
// Pulse level low duration until 40 us.
|
||||||
|
while ( TCNT0 < NORMAL_BIT_LENGTH );
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Name : SendStartBit
|
||||||
|
|
||||||
|
Description : Writes a start bit on the AVC LAN bus.
|
||||||
|
|
||||||
|
Argument(s) : None.
|
||||||
|
|
||||||
|
Return value : None.
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------------------------*/
|
||||||
|
void SendStartBit ( void )
|
||||||
|
{
|
||||||
|
// Reset timer to measure bit length.
|
||||||
|
TCNT0 = 0;
|
||||||
|
|
||||||
|
// Drive output to signal high.
|
||||||
|
DDRD |= _BV(PD2) | _BV(PD3);
|
||||||
|
|
||||||
|
// Pulse level high duration.
|
||||||
|
while ( TCNT0 < START_BIT_HOLD_ON_LENGTH );
|
||||||
|
|
||||||
|
// Release output.
|
||||||
|
DDRD &= ~( _BV(PD2) | _BV(PD3) );
|
||||||
|
|
||||||
|
// Pulse level low duration until ~185 us.
|
||||||
|
while ( TCNT0 < START_BIT_LENGTH );
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Name : ReadBits
|
||||||
|
|
||||||
|
Description : Reads specified number of bits from the AVC LAN bus.
|
||||||
|
|
||||||
|
Argument(s) : nbBits (byte) -> Number of bits to read.
|
||||||
|
|
||||||
|
Return value : (word) -> Data value read.
|
||||||
|
|
||||||
|
|<---- Bit '0' ---->|<---- Bit '1' ---->|
|
||||||
|
Physical '1' ,---------------, ,---------, ,---------
|
||||||
|
^ | ^ | ^
|
||||||
|
Physical '0' -----' '---' '---------'--------- Idle low
|
||||||
|
|---- 32 us ----| 7 |- 20 us -|- 19 us -|
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------------------------*/
|
||||||
|
word ReadBits ( byte nbBits )
|
||||||
|
{
|
||||||
|
word data = 0;
|
||||||
|
|
||||||
|
ParityBit = 0;
|
||||||
|
|
||||||
|
while ( nbBits-- > 0 )
|
||||||
|
{
|
||||||
|
// Insert new bit
|
||||||
|
data <<= 1;
|
||||||
|
|
||||||
|
// Wait until rising edge of new bit.
|
||||||
|
while ( INPUT_IS_CLEAR )
|
||||||
|
{
|
||||||
|
// Reset watchdog.
|
||||||
|
wdt_reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset timer to measure bit length.
|
||||||
|
TCNT0 = 0;
|
||||||
|
|
||||||
|
// Wait until falling edge.
|
||||||
|
while ( INPUT_IS_SET );
|
||||||
|
|
||||||
|
// Compare half way between a '1' (20 us) and a '0' (32 us ): 32 - (32 - 20) /2 = 26 us
|
||||||
|
if ( TCNT0 < BIT_0_HOLD_ON_LENGTH - (BIT_0_HOLD_ON_LENGTH - BIT_1_HOLD_ON_LENGTH) / 2 )
|
||||||
|
{
|
||||||
|
// Set new bit.
|
||||||
|
data |= 0x0001;
|
||||||
|
|
||||||
|
// Adjust parity.
|
||||||
|
ParityBit = ! ParityBit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Name : SendMessage
|
||||||
|
|
||||||
|
Description : Sends the message in global registers on the AVC LAN bus.
|
||||||
|
|
||||||
|
Argument(s) : None.
|
||||||
|
|
||||||
|
Return value : (bool) -> TRUE if successful else FALSE.
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------------------------*/
|
||||||
|
bool SendMessage ( void )
|
||||||
|
{
|
||||||
|
while ( ! IsAvcBusFree() );
|
||||||
|
|
||||||
|
// At this point we know the bus is available.
|
||||||
|
|
||||||
|
LedOn();
|
||||||
|
|
||||||
|
// Send start bit.
|
||||||
|
SendStartBit();
|
||||||
|
|
||||||
|
// Broadcast bit.
|
||||||
|
Send1BitWord( Broadcast );
|
||||||
|
|
||||||
|
// Master address = me.
|
||||||
|
Send12BitWord( MasterAddress );
|
||||||
|
Send1BitWord( ParityBit );
|
||||||
|
|
||||||
|
// Slave address = head unit (HU).
|
||||||
|
Send12BitWord( SlaveAddress );
|
||||||
|
Send1BitWord( ParityBit );
|
||||||
|
|
||||||
|
if ( ! HandleAcknowledge() )
|
||||||
|
{
|
||||||
|
DumpRawMessage( TRUE );
|
||||||
|
UsartPutStr( (char*)"SendMessage: No Ack @ Slave address\r\n" );
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Control flag + parity.
|
||||||
|
Send4BitWord( Control );
|
||||||
|
Send1BitWord( ParityBit );
|
||||||
|
|
||||||
|
if ( ! HandleAcknowledge() )
|
||||||
|
{
|
||||||
|
DumpRawMessage( TRUE );
|
||||||
|
UsartPutStr( (char*)"SendMessage: No Ack @ Control\r\n" );
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Data length + parity.
|
||||||
|
Send8BitWord( DataSize );
|
||||||
|
Send1BitWord( ParityBit );
|
||||||
|
|
||||||
|
if ( ! HandleAcknowledge() )
|
||||||
|
{
|
||||||
|
DumpRawMessage( TRUE );
|
||||||
|
UsartPutStr( (char*)"SendMessage: No Ack @ DataSize\r\n" );
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( byte i = 0; i < DataSize; i++ )
|
||||||
|
{
|
||||||
|
Send8BitWord( Data[i] );
|
||||||
|
Send1BitWord( ParityBit );
|
||||||
|
|
||||||
|
if ( ! HandleAcknowledge() )
|
||||||
|
{
|
||||||
|
DumpRawMessage( TRUE );
|
||||||
|
sprintf( UsartMsgBuffer, "SendMessage: No Ack @ Data[%d]\r\n", i );
|
||||||
|
UsartPutStr( UsartMsgBuffer );
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DumpRawMessage( TRUE );
|
||||||
|
|
||||||
|
LedOff();
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Name : ReadAcknowledge
|
||||||
|
|
||||||
|
Description : Reads the acknowledge bit the AVC LAN bus.
|
||||||
|
|
||||||
|
Argument(s) : None.
|
||||||
|
|
||||||
|
Return value : (bool) -> TRUE if ack detected else FALSE.
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------------------------*/
|
||||||
|
inline bool ReadAcknowledge ( void )
|
||||||
|
{
|
||||||
|
// The acknowledge pattern is very tricky: the sender shall drive the bus for the equivalent
|
||||||
|
// of a bit '1' (20 us) then release the bus and listen. At this point the target shall have
|
||||||
|
// taken over the bus maintaining the pulse until the equivalent of a bit '0' (32 us) is formed.
|
||||||
|
|
||||||
|
// Reset timer to measure bit length.
|
||||||
|
TCNT0 = 0;
|
||||||
|
|
||||||
|
// Drive output to signal high.
|
||||||
|
DDRD |= _BV(PD2) | _BV(PD3);
|
||||||
|
|
||||||
|
// Generate bit '0'.
|
||||||
|
while ( TCNT0 < BIT_1_HOLD_ON_LENGTH );
|
||||||
|
|
||||||
|
// Release output.
|
||||||
|
DDRD &= ~( _BV(PD2) | _BV(PD3) );
|
||||||
|
|
||||||
|
// Measure final resulting bit.
|
||||||
|
while ( INPUT_IS_SET );
|
||||||
|
|
||||||
|
// Sample half-way through bit '0' (26 us) to detect whether the target is acknowledging.
|
||||||
|
if ( TCNT0 > BIT_0_HOLD_ON_LENGTH - (BIT_0_HOLD_ON_LENGTH - BIT_1_HOLD_ON_LENGTH) / 2 )
|
||||||
|
{
|
||||||
|
// Slave is acknowledging (ack = 0). Wait until end of ack bit.
|
||||||
|
while ( INPUT_IS_SET );
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// No sign of life on the bus.
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Name : HandleAcknowledge
|
||||||
|
|
||||||
|
Description : Sends ack bit if I am broadcasting otherwise wait and return received ack bit.
|
||||||
|
|
||||||
|
Argument(s) : None.
|
||||||
|
|
||||||
|
Return value : (bool) -> FALSE if ack bit not detected.
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------------------------*/
|
||||||
|
bool HandleAcknowledge ( void )
|
||||||
|
{
|
||||||
|
if ( Broadcast == MSG_BCAST )
|
||||||
|
{
|
||||||
|
// Acknowledge.
|
||||||
|
Send1BitWord( 0 );
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return acknowledge bit.
|
||||||
|
return ReadAcknowledge();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Name : IsAvcBusFree
|
||||||
|
|
||||||
|
Description : Determine whether the bus is free (no tx/rx).
|
||||||
|
|
||||||
|
Argument(s) : None.
|
||||||
|
|
||||||
|
Return value : (bool) -> TRUE is bus is free.
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------------------------*/
|
||||||
|
bool IsAvcBusFree ( void )
|
||||||
|
{
|
||||||
|
// Reset timer.
|
||||||
|
TCNT0 = 0;
|
||||||
|
|
||||||
|
while ( INPUT_IS_CLEAR )
|
||||||
|
{
|
||||||
|
// We assume the bus is free if anything happens for the length of 1 bit.
|
||||||
|
if ( TCNT0 > NORMAL_BIT_LENGTH )
|
||||||
|
{
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Name : DumpRawMessage
|
||||||
|
|
||||||
|
Description : Dumps raw content of message registers on the terminal.
|
||||||
|
|
||||||
|
Argument(s) : incoming (bool) -> TRUE means incoming data, FALSE means outgoing.
|
||||||
|
|
||||||
|
Return value : None.
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------------------------*/
|
||||||
|
void DumpRawMessage ( bool incoming )
|
||||||
|
{
|
||||||
|
// Dump message on terminal.
|
||||||
|
|
||||||
|
if ( incoming )
|
||||||
|
UsartPutCStr( PSTR("\r\nAUX Enabler <<--- HU\r\n") );
|
||||||
|
else
|
||||||
|
UsartPutCStr( PSTR("\r\nAUX Enabler --->> HU\r\n") );
|
||||||
|
|
||||||
|
UsartPutCStr( PSTR(" Description: ") );
|
||||||
|
UsartPutCStr( Description );
|
||||||
|
UsartPutCStr( PSTR("\r\n") );
|
||||||
|
|
||||||
|
sprintf( UsartMsgBuffer, " Broadcast: %d \r\n", Broadcast );
|
||||||
|
UsartPutStr( UsartMsgBuffer );
|
||||||
|
|
||||||
|
sprintf( UsartMsgBuffer, " Master address: 0x%X \r\n", MasterAddress );
|
||||||
|
UsartPutStr( UsartMsgBuffer );
|
||||||
|
|
||||||
|
sprintf( UsartMsgBuffer, " Slave address: 0x%X \r\n", SlaveAddress );
|
||||||
|
UsartPutStr( UsartMsgBuffer );
|
||||||
|
|
||||||
|
sprintf( UsartMsgBuffer, " Control: 0x%X \r\n", Control );
|
||||||
|
UsartPutStr( UsartMsgBuffer );
|
||||||
|
|
||||||
|
sprintf( UsartMsgBuffer, " Data size: %d \r\n", DataSize );
|
||||||
|
UsartPutStr( UsartMsgBuffer );
|
||||||
|
|
||||||
|
sprintf( UsartMsgBuffer, " Data: " );
|
||||||
|
UsartPutStr( UsartMsgBuffer );
|
||||||
|
|
||||||
|
for ( byte i = 0; i < DataSize; i++ )
|
||||||
|
{
|
||||||
|
sprintf( UsartMsgBuffer, "%X ", Data[i] );
|
||||||
|
UsartPutStr( UsartMsgBuffer );
|
||||||
|
}
|
||||||
|
|
||||||
|
UsartPutStr( (char*)"\r\n-----\r\n" );
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Name : LedOn
|
||||||
|
|
||||||
|
Description : Turn LED on (active low signal).
|
||||||
|
|
||||||
|
Argument(s) : None.
|
||||||
|
|
||||||
|
Return value : None.
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------------------------*/
|
||||||
|
inline void LedOn ( void )
|
||||||
|
{
|
||||||
|
LED_PORT &= ~LEDOUT;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Name : LedOff
|
||||||
|
|
||||||
|
Description : Turn LED off (active low signal).
|
||||||
|
|
||||||
|
Argument(s) : None.
|
||||||
|
|
||||||
|
Return value : None.
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------------------------*/
|
||||||
|
inline void LedOff ( void )
|
||||||
|
{
|
||||||
|
LED_PORT |= LEDOUT;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------------------------
|
||||||
|
End of file.
|
||||||
|
--------------------------------------------------------------------------------------------------*/
|
109
AVCLanDriver.h
Normal file
109
AVCLanDriver.h
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
/*--------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Name : AvcLanDriver.h
|
||||||
|
|
||||||
|
Description : AVC Lan driver for Toyota devices
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------------------------*/
|
||||||
|
#ifndef _AVCLANDRV_H_
|
||||||
|
#define _AVCLANDRV_H_
|
||||||
|
|
||||||
|
#include "GlobalDef.h"
|
||||||
|
|
||||||
|
#define HU_ADDRESS 0x190 // But possibly 0x160, known to be both
|
||||||
|
|
||||||
|
#define MY_ADDRESS 0x360 // CD Changer #1
|
||||||
|
|
||||||
|
#define BROADCAST_ADDRESS 0x01FF // All audio devices
|
||||||
|
|
||||||
|
#define CONTROL_FLAGS 0xF
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|<---- Bit '0' ---->|<---- Bit '1' ---->|
|
||||||
|
Physical '1' ,---------------, ,---------, ,---------
|
||||||
|
^ | ^ | ^
|
||||||
|
Physical '0' -----' '---' '---------'--------- Idle low
|
||||||
|
|---- 33 us ----| 7 |- 20 us -|- 20 us -|
|
||||||
|
|
||||||
|
A bit '0' is typically 33 us high followed by 7 us low.
|
||||||
|
A bit '1' is typically 20 us high followed by 20 us low.
|
||||||
|
A start bit is typically 165 us high followed by 30 us low.
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
// Following multipliers result of Timer 0 prescaler having 2 counts/us
|
||||||
|
#define NORMAL_BIT_LENGTH 74 //37*2
|
||||||
|
|
||||||
|
#define BIT_1_HOLD_ON_LENGTH 40 //20*2
|
||||||
|
#define BIT_0_HOLD_ON_LENGTH 64 //33*2
|
||||||
|
|
||||||
|
#define START_BIT_LENGTH 372 //186*2
|
||||||
|
#define START_BIT_HOLD_ON_LENGTH 336 //168*2
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{ // No this is not a mistake, broadcast = 0!
|
||||||
|
MSG_NORMAL = 1,
|
||||||
|
MSG_BCAST = 0
|
||||||
|
|
||||||
|
} AvcTransmissionMode;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
ACT_NONE,
|
||||||
|
|
||||||
|
ACT_AUX_IN_USE,
|
||||||
|
ACT_TUNER_IN_USE,
|
||||||
|
ACT_TAPE_IN_USE,
|
||||||
|
ACT_CD_IN_USE,
|
||||||
|
|
||||||
|
ACT_EJECT_CD,
|
||||||
|
ACT_NO_CD,
|
||||||
|
ACT_TUNER_INFO,
|
||||||
|
ACT_AUDIO_STATUS,
|
||||||
|
// ACT_CD_INFO,
|
||||||
|
|
||||||
|
ACT_STATUS,
|
||||||
|
ACT_REGISTER,
|
||||||
|
ACT_INIT,
|
||||||
|
ACT_CHECK
|
||||||
|
|
||||||
|
} AvcActionID;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
AvcActionID ActionID; // Action to perform after receiving this message.
|
||||||
|
byte DataSize; // Payload data size (bytes).
|
||||||
|
byte Data[ 11 ]; // Payload data.
|
||||||
|
char Description[ 17 ]; // ASCII description of the command for terminal dump.
|
||||||
|
|
||||||
|
} AvcIncomingMessageStruct;
|
||||||
|
|
||||||
|
typedef const AvcIncomingMessageStruct AvcInMessage;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
AvcTransmissionMode Mode; // Transmission mode: normal (1) or broadcast (0).
|
||||||
|
byte DataSize; // Payload data size (bytes).
|
||||||
|
byte Data[ 11 ]; // Payload data.
|
||||||
|
char Description[ 17 ]; // ASCII description of the command for terminal dump.
|
||||||
|
|
||||||
|
} AvcOutgoingMessageStruct;
|
||||||
|
|
||||||
|
typedef const AvcOutgoingMessageStruct AvcOutMessage;
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------------------------
|
||||||
|
Prototypes
|
||||||
|
--------------------------------------------------------------------------------------------------*/
|
||||||
|
AvcActionID AvcReadMessage ( void );
|
||||||
|
|
||||||
|
bool AvcProcessActionID ( AvcActionID actionID );
|
||||||
|
void AvcUpdateStatus ( void );
|
||||||
|
|
||||||
|
void DumpRawMessage ( bool incoming );
|
||||||
|
|
||||||
|
#endif // _AVCLANDRV_H_
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------------------------
|
||||||
|
End of file.
|
||||||
|
--------------------------------------------------------------------------------------------------*/
|
BIN
AVCLanDriver.o
Normal file
BIN
AVCLanDriver.o
Normal file
Binary file not shown.
BIN
BigPcb.jpg
Normal file
BIN
BigPcb.jpg
Normal file
Binary file not shown.
After ![]() (image error) Size: 87 KiB |
BIN
BigSchematic.jpg
Normal file
BIN
BigSchematic.jpg
Normal file
Binary file not shown.
After ![]() (image error) Size: 128 KiB |
50
GlobalDef.h
Normal file
50
GlobalDef.h
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
/*--------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Name : GlobalDef.h
|
||||||
|
|
||||||
|
Description : Global definitions.
|
||||||
|
|
||||||
|
History : 2004/04/06 - Created by Louis Frigon.
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------------------------*/
|
||||||
|
#ifndef _GLOBALDEF_H_
|
||||||
|
#define _GLOBALDEF_H_
|
||||||
|
|
||||||
|
#include <avr/io.h>
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------------------------
|
||||||
|
Constants
|
||||||
|
--------------------------------------------------------------------------------------------------*/
|
||||||
|
#define FALSE 0
|
||||||
|
#define TRUE (!FALSE)
|
||||||
|
|
||||||
|
// AVC LAN bus directly connected to internal analog comparator (PD6/7)
|
||||||
|
// PD6 AIN0 +
|
||||||
|
// PD7 AIN1 -
|
||||||
|
#define DATAIN_PIN ACSR
|
||||||
|
#define DATAIN ACO
|
||||||
|
|
||||||
|
#define INPUT_IS_SET ( bit_is_set( DATAIN_PIN, DATAIN ) )
|
||||||
|
#define INPUT_IS_CLEAR ( bit_is_clear( DATAIN_PIN, DATAIN ) )
|
||||||
|
|
||||||
|
#define LED_DDR DDRB
|
||||||
|
#define LED_PORT PORTB
|
||||||
|
#define LEDOUT _BV(PORT5)
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------------------------
|
||||||
|
Type definitions
|
||||||
|
--------------------------------------------------------------------------------------------------*/
|
||||||
|
typedef unsigned char byte;
|
||||||
|
typedef unsigned int word;
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------------------------
|
||||||
|
Prototypes
|
||||||
|
--------------------------------------------------------------------------------------------------*/
|
||||||
|
inline void LedOff( void );
|
||||||
|
inline void LedOn( void );
|
||||||
|
|
||||||
|
#endif // _GLOBALDEF_H_
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------------------------
|
||||||
|
End of file.
|
||||||
|
--------------------------------------------------------------------------------------------------*/
|
28
Makefile
Normal file
28
Makefile
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
CC=avr-g++
|
||||||
|
CFLAGS=-c -g -Os -Wall -fno-exceptions -fpermissive -ffunction-sections -fdata-sections -fno-threadsafe-statics -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_DUEMILANOVE -DARDUINO_ARCH_AVR
|
||||||
|
LFLAGS=-g -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_DUEMILANOVE -DARDUINO_ARCH_AVR
|
||||||
|
|
||||||
|
all: ToyotaAuxEnabler.hex
|
||||||
|
|
||||||
|
ToyotaAuxEnabler.hex: ToyotaAuxEnabler.elf
|
||||||
|
avr-objcopy -j .text -j .data -O ihex ToyotaAuxEnabler.elf ToyotaAuxEnabler.hex
|
||||||
|
|
||||||
|
ToyotaAuxEnabler.elf: ToyotaAuxEnabler.o USART.o AVCLanDriver.o
|
||||||
|
$(CC) $(LFLAGS) -o ToyotaAuxEnabler.elf ToyotaAuxEnabler.o USART.o AVCLanDriver.o
|
||||||
|
|
||||||
|
ToyotaAuxEnabler.o: ToyotaAuxEnabler.c GlobalDef.h USART.h AVCLanDriver.h
|
||||||
|
$(CC) $(CFLAGS) ToyotaAuxEnabler.c
|
||||||
|
|
||||||
|
USART.o: USART.c USART.h GlobalDef.h
|
||||||
|
$(CC) $(CFLAGS) USART.c
|
||||||
|
|
||||||
|
AVCLanDriver.o: AVCLanDriver.c GlobalDef.h USART.h AVCLanDriver.h
|
||||||
|
$(CC) $(CFLAGS) AVCLanDriver.c
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm *.o *.hex *.elf
|
||||||
|
|
||||||
|
upload: ToyotaAuxEnabler.hex
|
||||||
|
avrdude -C/home/allen/Programs/arduino-1.6.5/hardware/tools/avr/etc/avrdude.conf -v -patmega328p -carduino -P/dev/arduino -b57600 -D -Uflash:w:ToyotaAuxEnabler.hex:i
|
||||||
|
|
||||||
|
.PHONY: upload
|
144
ToyotaAuxEnabler.c
Normal file
144
ToyotaAuxEnabler.c
Normal file
@ -0,0 +1,144 @@
|
|||||||
|
/*--------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Name : ToyotaAuxEnabler.c
|
||||||
|
|
||||||
|
Description : This program enables the AUX audio input on old Toyota radios with CD. Pressing
|
||||||
|
CD Eject button while no CD is loaded will toggle the AUX input.
|
||||||
|
|
||||||
|
MCU : ATmega328P @ 16 MHz.
|
||||||
|
|
||||||
|
Author : 2007-01-27 - Louis Frigon
|
||||||
|
|
||||||
|
Copyright : (c) 2007 SigmaObjects
|
||||||
|
|
||||||
|
History : 2007-01-27 - v0.1 Prototyping draft inspired from Marcin Slonicki's code.
|
||||||
|
2007-02-24 - v1.0 Production release.
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------------------------*/
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include <avr/interrupt.h>
|
||||||
|
#include <avr/wdt.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "GlobalDef.h"
|
||||||
|
#include "USART.h"
|
||||||
|
#include "AVCLanDriver.h"
|
||||||
|
|
||||||
|
#define FIRMWARE_VERSION "v1.0"
|
||||||
|
#define FIRMWARE_DATE __DATE__
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------------------------
|
||||||
|
Prototypes
|
||||||
|
--------------------------------------------------------------------------------------------------*/
|
||||||
|
void InitMCU ( void );
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------------------------
|
||||||
|
Global Variables
|
||||||
|
--------------------------------------------------------------------------------------------------*/
|
||||||
|
volatile bool SecondsTick = FALSE;
|
||||||
|
|
||||||
|
char UsartMsgBuffer[ USART_BUFFER_SIZE ];
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Name : InitMCU
|
||||||
|
|
||||||
|
Description : Performs MCU initialization.
|
||||||
|
|
||||||
|
Argument(s) : None.
|
||||||
|
|
||||||
|
Return value : None.
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------------------------*/
|
||||||
|
void InitMCU ( void )
|
||||||
|
{
|
||||||
|
// Init LED port pin
|
||||||
|
LED_DDR |= LEDOUT;
|
||||||
|
LedOff();
|
||||||
|
|
||||||
|
// OLD: TCCR0A = _BV(CS01);
|
||||||
|
// Correction: TCCR0B has the CS0n bits, not TCCR0A, prescaler should be at 8 or less to have 1 or more counts/us
|
||||||
|
// Timer 0 prescaler = 8 ( 2 count / us )
|
||||||
|
TCCR0B = _BV(CS01);
|
||||||
|
|
||||||
|
InitUSART();
|
||||||
|
|
||||||
|
// Preset AVC bus driver output pins but leave pins tri-stated until we need to use them.
|
||||||
|
PORTD |= _BV(PD3); // PD3 (+) high.
|
||||||
|
PORTD &= ~_BV(PD2); // PD2 (-) low.
|
||||||
|
|
||||||
|
// Enable watchdog @ ~2 sec.
|
||||||
|
// Likely this too, after research probably not, but maybe
|
||||||
|
wdt_enable( WDTO_2S );
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Name : LedOn
|
||||||
|
|
||||||
|
Description : Turn LED on (active low signal).
|
||||||
|
|
||||||
|
Argument(s) : None.
|
||||||
|
|
||||||
|
Return value : None.
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------------------------*/
|
||||||
|
inline void LedOn ( void )
|
||||||
|
{
|
||||||
|
LED_PORT &= ~LEDOUT;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Name : LedOff
|
||||||
|
|
||||||
|
Description : Turn LED off (active low signal).
|
||||||
|
|
||||||
|
Argument(s) : None.
|
||||||
|
|
||||||
|
Return value : None.
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------------------------*/
|
||||||
|
inline void LedOff ( void )
|
||||||
|
{
|
||||||
|
LED_PORT |= LEDOUT;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Name : main
|
||||||
|
|
||||||
|
Description : Program's main function.
|
||||||
|
|
||||||
|
Argument(s) : None.
|
||||||
|
|
||||||
|
Return value : None.
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------------------------*/
|
||||||
|
int main ( void )
|
||||||
|
{
|
||||||
|
InitMCU();
|
||||||
|
|
||||||
|
UsartPutCStr( PSTR("\r\n\t\t Toyota AVC-Lan AUX Enabler\r\n") );
|
||||||
|
UsartPutCStr( PSTR("\t\tCopyright (C) 2007, SigmaObjects Inc.\r\n") );
|
||||||
|
|
||||||
|
sprintf( UsartMsgBuffer, "\t\t Firmware %s, %s\r\n\r\n", FIRMWARE_VERSION, FIRMWARE_DATE );
|
||||||
|
UsartPutStr( UsartMsgBuffer );
|
||||||
|
|
||||||
|
while ( 1 )
|
||||||
|
{
|
||||||
|
// Reset watchdog.
|
||||||
|
wdt_reset();
|
||||||
|
|
||||||
|
AvcActionID actionID = AvcReadMessage();
|
||||||
|
|
||||||
|
if ( actionID != ACT_NONE )
|
||||||
|
{
|
||||||
|
AvcProcessActionID( actionID );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------------------------
|
||||||
|
End of file.
|
||||||
|
--------------------------------------------------------------------------------------------------*/
|
BIN
ToyotaAuxEnabler.elf
Executable file
BIN
ToyotaAuxEnabler.elf
Executable file
Binary file not shown.
273
ToyotaAuxEnabler.hex
Normal file
273
ToyotaAuxEnabler.hex
Normal file
@ -0,0 +1,273 @@
|
|||||||
|
:100000000C9414020C9431020C9431020C943102C1
|
||||||
|
:100010000C9431020C9431020C9431020C94310294
|
||||||
|
:100020000C9431020C9431020C9431020C94310284
|
||||||
|
:100030000C9431020C9431020C9431020C94310274
|
||||||
|
:100040000C9431020C9431020C9431020C94310264
|
||||||
|
:100050000C9431020C9431020C9431020C94310254
|
||||||
|
:100060000C9431020C9431020909436F7079726962
|
||||||
|
:100070006768742028432920323030372C20536998
|
||||||
|
:10008000676D614F626A6563747320496E632E0DFC
|
||||||
|
:100090000A000D0A09092020202020546F796F746E
|
||||||
|
:1000A00061204156432D4C616E2041555820456ECC
|
||||||
|
:1000B00061626C65720D0A000D0A00202020446503
|
||||||
|
:1000C000736372697074696F6E3A20202020000D8E
|
||||||
|
:1000D0000A41555820456E61626C6572202D2D2DA8
|
||||||
|
:1000E0003E3E2048550D0A000D0A41555820456EE8
|
||||||
|
:1000F00061626C6572203C3C2D2D2D2048550D0A07
|
||||||
|
:100100000041766350726F63657373416374696F06
|
||||||
|
:100110006E49443A20556E6B6E6F776E2061637442
|
||||||
|
:10012000696F6E204944210D0A00556E6B6E6F7722
|
||||||
|
:100130006E206D657373616765210041766352655A
|
||||||
|
:1001400061644D6573736167653A20546869732013
|
||||||
|
:100150006D65737361676520697320666F72206DCA
|
||||||
|
:1001600065210D0A00417663526561644D657373C4
|
||||||
|
:100170006167653A20506172697479206572726FA7
|
||||||
|
:10018000722040204461746153697A65210D0A0030
|
||||||
|
:10019000417663526561644D6573736167653A20AA
|
||||||
|
:1001A000506172697479206572726F7220402043C9
|
||||||
|
:1001B0006F6E74726F6C210D0A0041766352656137
|
||||||
|
:1001C000644D6573736167653A2050617269747933
|
||||||
|
:1001D000206572726F72204020536C6176654164B5
|
||||||
|
:1001E0006472657373210D0A004176635265616420
|
||||||
|
:1001F0004D6573736167653A205061726974792047
|
||||||
|
:100200006572726F722040204D6173746572416433
|
||||||
|
:100210006472657373210D0A00010005000111511C
|
||||||
|
:100220006100000000000044697361626C65204158
|
||||||
|
:100230005558000000000000010005000111506148
|
||||||
|
:10024000000000000000456E61626C652041555859
|
||||||
|
:100250000000000000000001000411014501000041
|
||||||
|
:10026000000000000041555820696E20757365003C
|
||||||
|
:1002700000000000000002000411014560000000C1
|
||||||
|
:100280000000000054756E657220696E20757365FC
|
||||||
|
:10029000000000000003000411014561000000009F
|
||||||
|
:1002A0000000005461706520696E20757365000060
|
||||||
|
:1002B000000000000400041101456200000000007D
|
||||||
|
:1002C0000000434420696E20757365000000000043
|
||||||
|
:1002D00000000000000311014600000000000000C3
|
||||||
|
:1002E000004E6F2064657669636520696E207573C2
|
||||||
|
:1002F0006500000003110120000000000000000064
|
||||||
|
:1003000050696E670000000000000000000000005F
|
||||||
|
:10031000000700056031F1010100000000000054F9
|
||||||
|
:10032000756E65722053746174757300000000006F
|
||||||
|
:1003300005000A6231F10030010100000080456AC9
|
||||||
|
:1003400065637420434400000000000000000006C4
|
||||||
|
:10035000000A6231F100F80101000000804E6F20B8
|
||||||
|
:1003600043440000000000000000000000000800FE
|
||||||
|
:10037000047431F1900000000000000041756469D0
|
||||||
|
:100380006F2053746174757300000000000900034E
|
||||||
|
:1003900000010A00000000000000004C414E205304
|
||||||
|
:1003A0007461747573000000000000000A000311FE
|
||||||
|
:1003B000010000000000000000004C414E2052658A
|
||||||
|
:1003C00067697374657200000000000B000311017F
|
||||||
|
:1003D0000100000000000000004C414E20526573F7
|
||||||
|
:1003E000746172740000000000000C000311012011
|
||||||
|
:1003F00000000000000000004C414E20436865638F
|
||||||
|
:100400006B00000000000000000000000000000081
|
||||||
|
:1004100000000000000000000000000000000000DC
|
||||||
|
:10042000000000000000000011241FBECFEFD8E044
|
||||||
|
:10043000DEBFCDBF11E0A0E0B1E0E0E0F0E102C03E
|
||||||
|
:1004400005900D92AC3FB107D9F723E0ACEFB1E0D6
|
||||||
|
:1004500001C01D92AA35B207E1F70E9447020C9431
|
||||||
|
:10046000FE070C940000259A2D9A82E085BD0E941B
|
||||||
|
:1004700077025B9A5A982FE088E190E00FB6F894E3
|
||||||
|
:10048000A895809360000FBE2093600008950E949D
|
||||||
|
:10049000330282E990E00E94A60288E690E00E9482
|
||||||
|
:1004A000A60280E091E09F938F938CE091E09F9370
|
||||||
|
:1004B0008F9381E191E09F938F938CEF91E09F93D5
|
||||||
|
:1004C0008F930E942D058CEF91E00E949A028DB7C8
|
||||||
|
:1004D0009EB708960FB6F8949EBF0FBE8DBFA89525
|
||||||
|
:1004E0000E9415040097D9F30E941303F8CFE1ECA2
|
||||||
|
:1004F000F0E010821092C00086E88093C20087E688
|
||||||
|
:100500008093C400589A88E1808308958091C00048
|
||||||
|
:10051000881F8827881F08958091C00087FFFCCF1F
|
||||||
|
:100520008091C60008959091C00095FFFCCF809304
|
||||||
|
:10053000C6000895CF93DF93EC018991882319F0C9
|
||||||
|
:100540000E949302FACFDF91CF910895CF93DF936A
|
||||||
|
:10055000FC018491EF012196882321F00E949302EF
|
||||||
|
:10056000FE01F7CFDF91CF9108959C01225F3F4FAD
|
||||||
|
:100570003093590320935803FC01249141E0211149
|
||||||
|
:1005800001C040E04093570320E633E03093560328
|
||||||
|
:1005900020935503411103C02FEF31E002C020E941
|
||||||
|
:1005A00031E03093540320935303FC01329644917D
|
||||||
|
:1005B00040935103319620E532E0D9015A2F521B66
|
||||||
|
:1005C000541720F454915D933196F8CF0895282F55
|
||||||
|
:1005D0001092500380E090E041E02150A8F0880F95
|
||||||
|
:1005E000991F00B605FC02C0A895FBCF16BC00B64B
|
||||||
|
:1005F00005FCFDCF36B5343380F781603091500370
|
||||||
|
:10060000342730935003E9CF089516BC8AB18C602B
|
||||||
|
:100610008AB986B58034E8F38AB1837F8AB986B512
|
||||||
|
:100620008A34E8F30895853091054CF482309105C1
|
||||||
|
:100630004CF40197A1F581E080934F0234C00597F7
|
||||||
|
:1006400041F02DC090934E0280934D0210924F02C4
|
||||||
|
:100650002AC080914D0290914E02049721F1809121
|
||||||
|
:100660004F02882339F089E192E00E94B50210928E
|
||||||
|
:100670004F0207C088E392E00E94B50281E08093B8
|
||||||
|
:100680004F0216BC00B605FCFCCF86B58B34D0F308
|
||||||
|
:100690002D9816BC8AB18C608AB986B5FECF81E0F0
|
||||||
|
:1006A00091E00E94A60280E0089581E080935703C4
|
||||||
|
:1006B00080E693E0909356038093550380E991E0A0
|
||||||
|
:1006C00090935403809353038FE0809352038AE006
|
||||||
|
:1006D00090E00E94130381E00895FF920F931F930F
|
||||||
|
:1006E000CF93DF93882319F088EE90E002C08FEC5F
|
||||||
|
:1006F00090E00E94A6028BEB90E00E94A6028091FF
|
||||||
|
:100700005803909159030E94A60288EB90E00E9442
|
||||||
|
:10071000A602809157031F928F938CE291E09F93E2
|
||||||
|
:100720008F93CCEFD1E0DF93CF930E942D05CE01C4
|
||||||
|
:100730000E949A02809156038F93809155038F9364
|
||||||
|
:1007400085E491E09F938F93DF93CF930E942D05D3
|
||||||
|
:10075000CE010E949A02809154038F93809153039B
|
||||||
|
:100760008F9380E691E09F938F93DF93CF930E94C6
|
||||||
|
:100770002D05CE010E949A02809152031F928F9301
|
||||||
|
:100780008BE791E09F938F93DF93CF930E942D058A
|
||||||
|
:10079000CE010E949A02809151031F928F9386E9A5
|
||||||
|
:1007A00091E09F938F93DF93CF930E942D05CE010D
|
||||||
|
:1007B0000E949A026FEA71E0CE010E942605CE01E6
|
||||||
|
:1007C0000E949A028DB79EB74E960FB6F8949EBFC0
|
||||||
|
:1007D0000FBE8DBFF12CC3ECD1E00CEF11E0809186
|
||||||
|
:1007E0005103F816C8F4EF2DF0E0E05BFD4F808177
|
||||||
|
:1007F0001F928F93DF93CF931F930F930E942D052A
|
||||||
|
:100800008CEF91E00E949A02F3940F900F900F905A
|
||||||
|
:100810000F900F900F90E3CF87EC91E0DF91CF9195
|
||||||
|
:100820001F910F91FF900C949A02AF92BF92CF92BA
|
||||||
|
:10083000DF92EF92FF920F931F93CF93DF9381E0AC
|
||||||
|
:100840000E94E7022D9881E00E94E70221E0892BB7
|
||||||
|
:1008500009F420E0209357038CE00E94E702909374
|
||||||
|
:10086000560380935503C0915003D0E081E00E946D
|
||||||
|
:10087000E702C817D90719F089EE91E04AC08CE069
|
||||||
|
:100880000E94E702EC01909354038093530300917C
|
||||||
|
:10089000500310E081E00E94E7020817190719F0E1
|
||||||
|
:1008A0008AEB91E036C0BB24B394C036D34029F024
|
||||||
|
:1008B000B12C81E00E94E70202C00E94050384E09F
|
||||||
|
:1008C0000E94E70280935203C0915003D0E081E080
|
||||||
|
:1008D0000E94E702C817D90719F080E991E019C012
|
||||||
|
:1008E000BB2019F00E94050303C081E00E94E702CB
|
||||||
|
:1008F00088E00E94E702A82E80935103C091500324
|
||||||
|
:10090000D0E081E00E94E702C817D90729F085E608
|
||||||
|
:1009100091E00E94A6023CC0BB2019F00E94050392
|
||||||
|
:1009200003C081E00E94E70240E5E42E42E0F42E9D
|
||||||
|
:10093000E70104C0BB2079F10E9405038C2F8E19BA
|
||||||
|
:100940008A1568F58E010055124088E00E94E70282
|
||||||
|
:100950008993C0905003D12C81E00E94E702C81611
|
||||||
|
:10096000D90641F31F930F9381ED91E09F938F93ED
|
||||||
|
:100970008CEF91E09F938F930E942D058CEF91E077
|
||||||
|
:100980000E949A020F900F900F900F900F900F906F
|
||||||
|
:10099000C0E0D0E04FC081E00E94E702CFCFBB2093
|
||||||
|
:1009A00021F08BE391E00E94A6028AE291E090930D
|
||||||
|
:1009B00059038093580329E532E080E090E0BFE1DD
|
||||||
|
:1009C000A0E0B89FB001B99F700D1124F9014491C6
|
||||||
|
:1009D000A417E8F44A2F50E0FA01E60FF71FE65A91
|
||||||
|
:1009E000FD4FE491EA01C05BDD4F48814E1302C028
|
||||||
|
:1009F000AF5FECCF0196215E3F4F8F30910501F73D
|
||||||
|
:100A0000C0E0D0E080E00E946D032D9A13C02FE17A
|
||||||
|
:100A1000289FF001299FF00D1124CF018B599D4F84
|
||||||
|
:100A20009093590380935803E95AFD4FE491CE2FD8
|
||||||
|
:100A3000D0E0E8CFCE01DF91CF911F910F91FF90D1
|
||||||
|
:100A4000EF90DF90CF90BF90AF900895FB01DC0155
|
||||||
|
:100A500001900D920020E1F70895AEE0B0E0E3E3ED
|
||||||
|
:100A6000F5E00C94D5070D891E8986E08C831A83E6
|
||||||
|
:100A700009838FEF9FE79E838D83AE01475E5F4FB3
|
||||||
|
:100A80006F89788DCE0101960E944F05EF81F88520
|
||||||
|
:100A9000E00FF11F10822E96E4E00C94F107ACE019
|
||||||
|
:100AA000B0E0E5E5F5E00C94C7077C016B018A0135
|
||||||
|
:100AB000FC0117821682838181FFBDC1CE010196A0
|
||||||
|
:100AC0004C01F7019381F60193FD859193FF81918C
|
||||||
|
:100AD0006F01882309F4ABC1853239F493FD859108
|
||||||
|
:100AE00093FF81916F01853229F4B70190E00E9454
|
||||||
|
:100AF0003707E7CF512C312C20E02032A0F48B3285
|
||||||
|
:100B000069F030F4803259F0833269F420612CC0EE
|
||||||
|
:100B10008D3239F0803339F4216026C022602460A0
|
||||||
|
:100B200023C0286021C027FD27C030ED380F3A30A0
|
||||||
|
:100B300078F426FF06C0FAE05F9E300D1124532E94
|
||||||
|
:100B400013C08AE0389E300D1124332E20620CC071
|
||||||
|
:100B50008E3221F426FD6BC1206406C08C3611F460
|
||||||
|
:100B6000206802C0883641F4F60193FD859193FF19
|
||||||
|
:100B700081916F018111C1CF982F9F7D9554933042
|
||||||
|
:100B800028F40C5F1F4FFFE3F9830DC0833631F06B
|
||||||
|
:100B9000833771F0833509F05BC022C0F801808192
|
||||||
|
:100BA00089830E5F1F4F44244394512C540115C078
|
||||||
|
:100BB0003801F2E06F0E711CF801A080B18026FFB1
|
||||||
|
:100BC00003C0652D70E002C06FEF7FEFC5012C8779
|
||||||
|
:100BD0000E942C072C0183012C852F77222E17C011
|
||||||
|
:100BE0003801F2E06F0E711CF801A080B18026FF81
|
||||||
|
:100BF00003C0652D70E002C06FEF7FEFC5012C8749
|
||||||
|
:100C00000E9421072C012C852068222E830123FCC1
|
||||||
|
:100C10001BC0832D90E048165906B0F4B70180E25E
|
||||||
|
:100C200090E00E9437073A94F4CFF50127FC8591B4
|
||||||
|
:100C300027FE81915F01B70190E00E9437073110D4
|
||||||
|
:100C40003A94F1E04F1A51084114510471F7E5C08C
|
||||||
|
:100C5000843611F0893639F5F80127FF07C0608125
|
||||||
|
:100C60007181828193810C5F1F4F08C06081718107
|
||||||
|
:100C7000882777FD8095982F0E5F1F4F2F76B22E15
|
||||||
|
:100C800097FF09C090958095709561957F4F8F4F24
|
||||||
|
:100C90009F4F2068B22E2AE030E0A4010E9469072D
|
||||||
|
:100CA000A82EA81844C0853729F42F7EB22E2AE03A
|
||||||
|
:100CB00030E025C0F22FF97FBF2E8F36C1F018F437
|
||||||
|
:100CC000883579F0B4C0803719F0883721F0AFC08B
|
||||||
|
:100CD0002F2F2061B22EB4FE0DC08B2D8460B82E54
|
||||||
|
:100CE00009C024FF0AC09F2F9660B92E06C028E0D5
|
||||||
|
:100CF00030E005C020E130E002C020E132E0F80140
|
||||||
|
:100D0000B7FE07C060817181828193810C5F1F4FA4
|
||||||
|
:100D100006C06081718180E090E00E5F1F4FA401EA
|
||||||
|
:100D20000E946907A82EA818FB2DFF77BF2EB6FEDC
|
||||||
|
:100D30000BC02B2D2E7FA51450F4B4FE0AC0B2FCBC
|
||||||
|
:100D400008C02B2D2E7E05C07A2C2B2D03C07A2CAB
|
||||||
|
:100D500001C0752C24FF0DC0FE01EA0DF11D80813C
|
||||||
|
:100D6000803311F4297E09C022FF06C07394739466
|
||||||
|
:100D700004C0822F867809F0739423FD13C020FFEE
|
||||||
|
:100D800006C05A2C731418F4530C5718732C731490
|
||||||
|
:100D900068F4B70180E290E02C870E9437077394D3
|
||||||
|
:100DA0002C85F5CF731410F4371801C0312C24FFB3
|
||||||
|
:100DB00012C0B70180E390E02C870E9437072C8592
|
||||||
|
:100DC00022FF17C021FF03C088E590E002C088E73A
|
||||||
|
:100DD00090E0B7010CC0822F867859F021FD02C047
|
||||||
|
:100DE00080E201C08BE227FD8DE2B70190E00E9416
|
||||||
|
:100DF0003707A51438F4B70180E390E00E94370765
|
||||||
|
:100E00005A94F7CFAA94F401EA0DF11D8081B7013D
|
||||||
|
:100E100090E00E943707A110F5CF332009F451CE9E
|
||||||
|
:100E2000B70180E290E00E9437073A94F6CFF701CD
|
||||||
|
:100E30008681978102C08FEF9FEF2C96E2E10C94A0
|
||||||
|
:100E4000E307FC010590615070400110D8F78095D0
|
||||||
|
:100E500090958E0F9F1F0895FC0161507040019086
|
||||||
|
:100E60000110D8F7809590958E0F9F1F08950F93CE
|
||||||
|
:100E70001F93CF93DF93182F092FEB018B8181FDF7
|
||||||
|
:100E800003C08FEF9FEF20C082FF10C04E815F81B3
|
||||||
|
:100E90002C813D81421753077CF4E881F9819F0141
|
||||||
|
:100EA0002F5F3F4F39832883108306C0E885F9857B
|
||||||
|
:100EB000812F0995892B29F72E813F812F5F3F4F85
|
||||||
|
:100EC0003F832E83812F902FDF91CF911F910F9120
|
||||||
|
:100ED0000895FA01AA27283051F1203181F1E894D0
|
||||||
|
:100EE0006F936E7F6E5F7F4F8F4F9F4FAF4FB1E01D
|
||||||
|
:100EF0003ED0B4E03CD0670F781F891F9A1FA11D18
|
||||||
|
:100F0000680F791F8A1F911DA11D6A0F711D811D18
|
||||||
|
:100F1000911DA11D20D009F468943F912AE0269FDD
|
||||||
|
:100F200011243019305D3193DEF6CF010895462F3C
|
||||||
|
:100F30004770405D4193B3E00FD0C9F7F6CF462F1D
|
||||||
|
:100F40004F70405D4A3318F0495D31FD4052419386
|
||||||
|
:100F500002D0A9F7EACFB4E0A69597958795779543
|
||||||
|
:100F60006795BA95C9F700976105710508959B01CA
|
||||||
|
:100F7000AC010A2E06945795479537952795BA9553
|
||||||
|
:100F8000C9F7620F731F841F951FA01D08952F922C
|
||||||
|
:100F90003F924F925F926F927F928F929F92AF9209
|
||||||
|
:100FA000BF92CF92DF92EF92FF920F931F93CF9356
|
||||||
|
:100FB000DF93CDB7DEB7CA1BDB0B0FB6F894DEBFED
|
||||||
|
:100FC0000FBECDBF09942A88398848885F846E8413
|
||||||
|
:100FD0007D848C849B84AA84B984C884DF80EE805D
|
||||||
|
:100FE000FD800C811B81AA81B981CE0FD11D0FB666
|
||||||
|
:100FF000F894DEBF0FBECDBFED010895F894FFCF8A
|
||||||
|
:101000004A756C20313820323031350076312E303F
|
||||||
|
:1010100000090920202020204669726D77617265E1
|
||||||
|
:101020002025732C2025730D0A0D0A002020204254
|
||||||
|
:10103000726F6164636173743A2020202020202540
|
||||||
|
:1010400064200D0A002020204D61737465722061B8
|
||||||
|
:101050006464726573733A2030782558200D0A0055
|
||||||
|
:10106000202020536C61766520616464726573731F
|
||||||
|
:101070003A202030782558200D0A00202020436F88
|
||||||
|
:101080006E74726F6C3A202020202020202030784F
|
||||||
|
:101090002558200D0A0020202044617461207369C6
|
||||||
|
:1010A0007A653A2020202020202564200D0A002087
|
||||||
|
:1010B0002020446174613A2020202020202020201C
|
||||||
|
:1010C000202000255820000D0A2D2D2D2D2D0D0A34
|
||||||
|
:1010D00000417663526561644D6573736167653A7B
|
||||||
|
:1010E00020506172697479206572726F722040209D
|
||||||
|
:0C10F000446174615B25645D0D0A000022
|
||||||
|
:00000001FF
|
BIN
ToyotaAuxEnabler.o
Normal file
BIN
ToyotaAuxEnabler.o
Normal file
Binary file not shown.
144
USART.c
Normal file
144
USART.c
Normal file
@ -0,0 +1,144 @@
|
|||||||
|
/*--------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Name : USART.c
|
||||||
|
|
||||||
|
Description : Utility functions for ATmega8 USART.
|
||||||
|
|
||||||
|
Author : 2004-10-22 - Louis Frigon
|
||||||
|
|
||||||
|
History : 2004-10-22 - First release (v0.1).
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------------------------*/
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include <avr/interrupt.h>
|
||||||
|
#include <avr/pgmspace.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "USART.h"
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Name : InitUSART
|
||||||
|
|
||||||
|
Description : Performs USART initialization: 9600,N,8,1.
|
||||||
|
|
||||||
|
Argument(s) : None.
|
||||||
|
|
||||||
|
Return value : None.
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------------------------*/
|
||||||
|
void InitUSART ( void )
|
||||||
|
{
|
||||||
|
// Disable USART while setting baud rate.
|
||||||
|
UCSR0B = 0x00;
|
||||||
|
UCSR0A = 0x00;
|
||||||
|
|
||||||
|
// 8 data bit, 1 stop, no parity.
|
||||||
|
UCSR0C = _BV(EEAR7) | _BV(UCSZ01) | _BV(UCSZ00);
|
||||||
|
|
||||||
|
// Set USART baud rate @ 9600. Divider is 103 @ 16 MHz.
|
||||||
|
UBRR0L = 103;
|
||||||
|
|
||||||
|
// Enable internal pull-up on Rx pin.
|
||||||
|
PORTD |= _BV(PD0);
|
||||||
|
|
||||||
|
// Enable Tx & Rx.
|
||||||
|
UCSR0B = _BV(RXEN0) | _BV(TXEN0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Name : UsartIsChr
|
||||||
|
|
||||||
|
Description : Return status of USART Rx buffer.
|
||||||
|
|
||||||
|
Argument(s) : None.
|
||||||
|
|
||||||
|
Return value : 0 if Rx buffer empty.
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------------------------*/
|
||||||
|
bool UsartIsChr ( void )
|
||||||
|
{
|
||||||
|
return UCSR0A & _BV(RXC0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Name : UsartGetChr
|
||||||
|
|
||||||
|
Description : Return character USART Rx buffer. Blocking until Rx buffer not empty.
|
||||||
|
|
||||||
|
Argument(s) : None.
|
||||||
|
|
||||||
|
Return value : Character in Rx buffer.
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------------------------*/
|
||||||
|
char UsartGetChr ( void )
|
||||||
|
{
|
||||||
|
while ( !UsartIsChr() );
|
||||||
|
|
||||||
|
return UDR0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Name : UsartPutChr
|
||||||
|
|
||||||
|
Description : Send a character through the USART.
|
||||||
|
|
||||||
|
Argument(s) : c -> char to send.
|
||||||
|
|
||||||
|
Return value : None.
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------------------------*/
|
||||||
|
void UsartPutChr ( char c )
|
||||||
|
{
|
||||||
|
// Wait for transmit register to be empty.
|
||||||
|
while ( !(UCSR0A & _BV(UDRE0)) );
|
||||||
|
|
||||||
|
UDR0 = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Name : UsartPutStr
|
||||||
|
|
||||||
|
Description : Transmit a string on the serial port.
|
||||||
|
|
||||||
|
Argument(s) : str -> pointer to string to send.
|
||||||
|
|
||||||
|
Return value : None.
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------------------------*/
|
||||||
|
void UsartPutStr ( char *str )
|
||||||
|
{
|
||||||
|
while ( *str )
|
||||||
|
{
|
||||||
|
UsartPutChr( *str++ );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Name : UsartPutCStr
|
||||||
|
|
||||||
|
Description : Transmit a string on the serial port.
|
||||||
|
|
||||||
|
Argument(s) : str -> pointer to constant string to send (strings in Flash).
|
||||||
|
|
||||||
|
Return value : None.
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------------------------*/
|
||||||
|
void UsartPutCStr ( const char *str )
|
||||||
|
{
|
||||||
|
char c;
|
||||||
|
|
||||||
|
while ( (c = pgm_read_byte_near( str++ )) )
|
||||||
|
{
|
||||||
|
UsartPutChr( c );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------------------------
|
||||||
|
End of file.
|
||||||
|
--------------------------------------------------------------------------------------------------*/
|
37
USART.h
Normal file
37
USART.h
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
/*--------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Name : USART.h
|
||||||
|
|
||||||
|
Description : Header file for USART functions.
|
||||||
|
|
||||||
|
History : 2004-10-22 - Created by Louis Frigon.
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------------------------*/
|
||||||
|
#ifndef _USART_H_
|
||||||
|
#define _USART_H_
|
||||||
|
|
||||||
|
#include <avr/pgmspace.h>
|
||||||
|
|
||||||
|
#include "GlobalDef.h"
|
||||||
|
|
||||||
|
#define USART_BUFFER_SIZE 80
|
||||||
|
|
||||||
|
extern char UsartMsgBuffer[ USART_BUFFER_SIZE ];
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------------------------
|
||||||
|
Function prototypes
|
||||||
|
--------------------------------------------------------------------------------------------------*/
|
||||||
|
// Function prototypes are mandatory otherwise the compiler generates unreliable code.
|
||||||
|
|
||||||
|
void InitUSART ( void );
|
||||||
|
bool UsartIsChr ( void );
|
||||||
|
char UsartGetChr ( void );
|
||||||
|
void UsartPutChr ( char c );
|
||||||
|
void UsartPutStr ( char *str );
|
||||||
|
void UsartPutCStr ( const char *str );
|
||||||
|
|
||||||
|
|
||||||
|
#endif // _USART_H_
|
||||||
|
/*--------------------------------------------------------------------------------------------------
|
||||||
|
End of file.
|
||||||
|
--------------------------------------------------------------------------------------------------*/
|
BIN
USART.o
Normal file
BIN
USART.o
Normal file
Binary file not shown.
1578
screenlog.0
Normal file
1578
screenlog.0
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user