/
ipod_avc.c
executable file
·136 lines (107 loc) · 3.37 KB
/
ipod_avc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
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 part of
iPod interface for TOYOTA AVC-Lan CD-Changer Emulator
v1.0
(C) 2006 SLONIU
http://www.softservice.com.pl/corolla/avc
marcin@softservice.com.pl
---------------------------------------------------------------------------
*/
//------------------------------------------------------------------------------
#include <avr/io.h>
#include <avr/signal.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>
#include "delay.h"
#include "const.h"
#include "avclandrv.h"
#include "com232.h"
#include "timer.h"
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void PIN_Setup();
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
int main()
{
PIN_Setup();
//delay_ms(100);
AVCLan_Init();
#ifndef SNIFFER
iPod_Init();
#endif
#ifdef MONITOR
RS232_Print("********************** RESET *********************\n");
#endif
while (1) {
if (INPUT_IS_SET) { // if message from some device on AVCLan begin
AVCLan_Read_Message();
// check command from HU
if (answerReq != 0) AVCLan_SendAnswer();
}
#ifndef SNIFFER
// HandleEvent
if (Event & EV_STATUS)
{
Event &= ~EV_STATUS;
if (CD_Mode!=stStop) {
AVCLan_Send_Status();
};
}
if (Event & EV_DISPLAY)
{
Event &= ~EV_DISPLAY;
AVCLan_Send_Changer_Status();
}
#endif
RS232_SendStuff();
} // end while(1)
}
//------------------------------------------------------------------------------
void PIN_Setup()
{
outb(GIMSK, 0); // disable external interupts
outb(MCUCR, 0);
outb(TIMSK, (_BV(TOIE1))); // Enable timer1 interrupt
set_sleep_mode(SLEEP_MODE_IDLE);
//cbi(DDRD, 6);
//cbi(PORTD, 6);
// Timer 1
outb(TCCR1A, 0);
outb(TCCR1B, (_BV(CS12)) | (_BV(CS10))); // Prescaler /1024
outb(TCNT1H, TI1_H); // Load counter value hi
outb(TCNT1L, TI1_L); // Load counter value lo
RS232_Init();
Event = EV_NOTHING;
cli();
AuxInput=1;
#ifndef SNIFFER
SwitchInputs();
#endif
}
//------------------------------------------------------------------------------
SIGNAL(SIG_OVERFLOW1) // Timer1 overflow every 1Sec
{
outb(TCNT1H, TI1_H); // reload timer1
outb(TCNT1L, TI1_L);
if ((CD_Mode!=stStop)) {
Event |= EV_STATUS;
}
}
SIGNAL(SIG_COMPARATOR)
{
//do nothing we're now awake!
};
//------------------------------------------------------------------------------