1
0
Fork 0
forked from len0rd/rockbox

iap: reduce code duplication in iap autobaud code

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29769 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Bertrik Sikken 2011-04-23 09:12:28 +00:00
parent 55a7a31ce3
commit 69e1647d2d

View file

@ -32,6 +32,17 @@
#if defined(IPOD_ACCESSORY_PROTOCOL) #if defined(IPOD_ACCESSORY_PROTOCOL)
static int autobaud = 0; static int autobaud = 0;
static void set_bitrate(unsigned int rate)
{
unsigned int divisor;
divisor = 24000000L / rate / 16;
SER0_LCR = 0x80; /* Divisor latch enable */
SER0_DLL = (divisor >> 0) & 0xFF;
SER0_LCR = 0x03; /* Divisor latch disable, 8-N-1 */
}
void serial_setup (void) void serial_setup (void)
{ {
int tmp; int tmp;
@ -71,16 +82,13 @@ void serial_bitrate(int rate)
if(rate == 0) if(rate == 0)
{ {
autobaud = 2; autobaud = 2;
SER0_LCR = 0x80; /* Divisor latch enable */ set_bitrate(115200);
SER0_DLL = 0x0D; /* 24000000/13/16 = 115384 baud */ }
SER0_LCR = 0x03; /* Divisor latch disable, 8-N-1 */ else
return; {
autobaud = 0;
set_bitrate(rate);
} }
autobaud = 0;
SER0_LCR = 0x80; /* Divisor latch enable */
SER0_DLL = 24000000L / rate / 16;
SER0_LCR = 0x03; /* Divisor latch disable, 8-N-1 */
} }
int tx_rdy(void) int tx_rdy(void)
@ -128,15 +136,11 @@ void SERIAL0(void)
case 0x55: case 0x55:
break; break;
case 0xFC: case 0xFC:
SER0_LCR = 0x80; /* Divisor latch enable */ set_bitrate(19200);
SER0_DLL = 0x4E; /* 24000000/78/16 = 19230 baud */
SER0_LCR = 0x03; /* Divisor latch disable, 8-N-1 */
temp = 0xFF; temp = 0xFF;
break; break;
case 0xE0: case 0xE0:
SER0_LCR = 0x80; /* Divisor latch enable */ set_bitrate(9600);
SER0_DLL = 0x9C; /* 24000000/156/16 = 9615 baud */
SER0_LCR = 0x03; /* Divisor latch disable, 8-N-1 */
temp = 0xFF; temp = 0xFF;
break; break;
default: default:
@ -144,14 +148,10 @@ void SERIAL0(void)
if (badbaud >= 6) /* Switch baud detection mode */ if (badbaud >= 6) /* Switch baud detection mode */
{ {
autobaud = 2; autobaud = 2;
SER0_LCR = 0x80; /* Divisor latch enable */ set_bitrate(115200);
SER0_DLL = 0x0D; /* 24000000/13/16 = 115384 baud */
SER0_LCR = 0x03; /* Divisor latch disable, 8-N-1 */
badbaud = 0; badbaud = 0;
} else { } else {
SER0_LCR = 0x80; /* Divisor latch enable */ set_bitrate(57600);
SER0_DLL = 0x1A; /* 24000000/26/16 = 57692 baud */
SER0_LCR = 0x03; /* Divisor latch disable, 8-N-1 */
} }
continue; continue;
} }
@ -162,21 +162,15 @@ void SERIAL0(void)
case 0x55: case 0x55:
break; break;
case 0xFE: case 0xFE:
SER0_LCR = 0x80; /* Divisor latch enable */ set_bitrate(57600);
SER0_DLL = 0x1A; /* 24000000/26/16 = 57692 baud */
SER0_LCR = 0x03; /* Divisor latch disable, 8-N-1 */
temp = 0xFF; temp = 0xFF;
break; break;
case 0xFC: case 0xFC:
SER0_LCR = 0x80; /* Divisor latch enable */ set_bitrate(38400);
SER0_DLL = 0x27; /* 24000000/39/16 = 38461 baud */
SER0_LCR = 0x03; /* Divisor latch disable, 8-N-1 */
temp = 0xFF; temp = 0xFF;
break; break;
case 0xE0: case 0xE0:
SER0_LCR = 0x80; /* Divisor latch enable */ set_bitrate(19200);
SER0_DLL = 0x4E; /* 24000000/78/16 = 19230 baud */
SER0_LCR = 0x03; /* Divisor latch disable, 8-N-1 */
temp = 0xFF; temp = 0xFF;
break; break;
default: default:
@ -184,14 +178,10 @@ void SERIAL0(void)
if (badbaud >= 6) /* Switch baud detection */ if (badbaud >= 6) /* Switch baud detection */
{ {
autobaud = 1; autobaud = 1;
SER0_LCR = 0x80; /* Divisor latch enable */ set_bitrate(57600);
SER0_DLL = 0x1A; /* 24000000/26/16 = 57692 baud */
SER0_LCR = 0x03; /* Divisor latch disable, 8-N-1 */
badbaud = 0; badbaud = 0;
} else { } else {
SER0_LCR = 0x80; /* Divisor latch enable */ set_bitrate(115200);
SER0_DLL = 0x0D; /* 24000000/13/16 = 115384 baud */
SER0_LCR = 0x03; /* Divisor latch disable, 8-N-1 */
} }
continue; continue;
} }