1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 by Alan Korr & Nick Robinson
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
33 #if defined(IPOD_ACCESSORY_PROTOCOL)
34 static int autobaud
= 0;
36 static void set_bitrate(unsigned int rate
)
40 divisor
= 24000000L / rate
/ 16;
41 SER0_LCR
= 0x80; /* Divisor latch enable */
42 SER0_DLL
= (divisor
>> 0) & 0xFF;
43 SER0_LCR
= 0x03; /* Divisor latch disable, 8-N-1 */
46 void serial_setup (void)
50 #if defined(IPOD_COLOR) || defined(IPOD_4G)
51 /* Route the Tx/Rx pins. 4G Ipod??? */
52 outl(0x70000018, inl(0x70000018) & ~0xc00);
53 #elif defined(IPOD_NANO) || defined(IPOD_VIDEO)
54 /* Route the Tx/Rx pins. 5G Ipod */
55 (*(volatile unsigned long *)(0x7000008C)) &= ~0x0C;
56 GPO32_ENABLE
&= ~0x0C;
59 DEV_EN
= DEV_EN
| DEV_SER0
;
60 CPU_HI_INT_DIS
= SER0_MASK
;
66 SER0_LCR
= 0x80; /* Divisor latch enable */
68 SER0_LCR
= 0x03; /* Divisor latch disable, 8-N-1 */
71 SER0_FCR
= 0x07; /* Tx+Rx FIFO reset and FIFO enable */
73 CPU_INT_EN
|= HI_MASK
;
74 CPU_HI_INT_EN
|= SER0_MASK
;
80 void serial_bitrate(int rate
)
110 void tx_writec(unsigned char c
)
115 unsigned char rx_readc(void)
117 return (SER0_RBR
& 0xFF);
122 static int badbaud
= 0;
123 static bool newpkt
= true;
129 if (newpkt
&& autobaud
> 0)
148 if (badbaud
>= 6) /* Switch baud detection mode */
178 if (badbaud
>= 6) /* Switch baud detection */
190 bool pkt
= iap_getc(temp
);
192 autobaud
= 0; /* Found good baud */
198 void dprintf(const char * str
, ... )
200 char dprintfbuff
[256];
207 vsnprintf(ptr
,sizeof(dprintfbuff
),str
,ap
);
210 serial_tx((unsigned char *)ptr
);
213 void serial_tx(const unsigned char * buf
)