summaryrefslogtreecommitdiffstats
path: root/firmware
diff options
context:
space:
mode:
authorBertrik Sikken <bertrik@sikken.nl>2011-04-23 09:12:28 +0000
committerBertrik Sikken <bertrik@sikken.nl>2011-04-23 09:12:28 +0000
commit69e1647d2dfb30adea96533eace02c658d36d66f (patch)
tree62d7a3f80ddf613e2c196a1638eeabfef424bf27 /firmware
parent55a7a31ce3a742feea2ff47f6ec35356ebb0ba06 (diff)
downloadrockbox-69e1647d2dfb30adea96533eace02c658d36d66f.tar.gz
rockbox-69e1647d2dfb30adea96533eace02c658d36d66f.tar.bz2
rockbox-69e1647d2dfb30adea96533eace02c658d36d66f.zip
iap: reduce code duplication in iap autobaud code
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29769 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
-rw-r--r--firmware/drivers/serial.c62
1 files changed, 26 insertions, 36 deletions
diff --git a/firmware/drivers/serial.c b/firmware/drivers/serial.c
index fb8851daf2..af0f3abe68 100644
--- a/firmware/drivers/serial.c
+++ b/firmware/drivers/serial.c
@@ -32,6 +32,17 @@
#if defined(IPOD_ACCESSORY_PROTOCOL)
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)
{
int tmp;
@@ -71,16 +82,13 @@ void serial_bitrate(int rate)
if(rate == 0)
{
autobaud = 2;
- SER0_LCR = 0x80; /* Divisor latch enable */
- SER0_DLL = 0x0D; /* 24000000/13/16 = 115384 baud */
- SER0_LCR = 0x03; /* Divisor latch disable, 8-N-1 */
- return;
+ set_bitrate(115200);
+ }
+ else
+ {
+ 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)
@@ -128,15 +136,11 @@ void SERIAL0(void)
case 0x55:
break;
case 0xFC:
- SER0_LCR = 0x80; /* Divisor latch enable */
- SER0_DLL = 0x4E; /* 24000000/78/16 = 19230 baud */
- SER0_LCR = 0x03; /* Divisor latch disable, 8-N-1 */
+ set_bitrate(19200);
temp = 0xFF;
break;
case 0xE0:
- SER0_LCR = 0x80; /* Divisor latch enable */
- SER0_DLL = 0x9C; /* 24000000/156/16 = 9615 baud */
- SER0_LCR = 0x03; /* Divisor latch disable, 8-N-1 */
+ set_bitrate(9600);
temp = 0xFF;
break;
default:
@@ -144,14 +148,10 @@ void SERIAL0(void)
if (badbaud >= 6) /* Switch baud detection mode */
{
autobaud = 2;
- SER0_LCR = 0x80; /* Divisor latch enable */
- SER0_DLL = 0x0D; /* 24000000/13/16 = 115384 baud */
- SER0_LCR = 0x03; /* Divisor latch disable, 8-N-1 */
+ set_bitrate(115200);
badbaud = 0;
} else {
- SER0_LCR = 0x80; /* Divisor latch enable */
- SER0_DLL = 0x1A; /* 24000000/26/16 = 57692 baud */
- SER0_LCR = 0x03; /* Divisor latch disable, 8-N-1 */
+ set_bitrate(57600);
}
continue;
}
@@ -162,21 +162,15 @@ void SERIAL0(void)
case 0x55:
break;
case 0xFE:
- SER0_LCR = 0x80; /* Divisor latch enable */
- SER0_DLL = 0x1A; /* 24000000/26/16 = 57692 baud */
- SER0_LCR = 0x03; /* Divisor latch disable, 8-N-1 */
+ set_bitrate(57600);
temp = 0xFF;
break;
case 0xFC:
- SER0_LCR = 0x80; /* Divisor latch enable */
- SER0_DLL = 0x27; /* 24000000/39/16 = 38461 baud */
- SER0_LCR = 0x03; /* Divisor latch disable, 8-N-1 */
+ set_bitrate(38400);
temp = 0xFF;
break;
case 0xE0:
- SER0_LCR = 0x80; /* Divisor latch enable */
- SER0_DLL = 0x4E; /* 24000000/78/16 = 19230 baud */
- SER0_LCR = 0x03; /* Divisor latch disable, 8-N-1 */
+ set_bitrate(19200);
temp = 0xFF;
break;
default:
@@ -184,14 +178,10 @@ void SERIAL0(void)
if (badbaud >= 6) /* Switch baud detection */
{
autobaud = 1;
- SER0_LCR = 0x80; /* Divisor latch enable */
- SER0_DLL = 0x1A; /* 24000000/26/16 = 57692 baud */
- SER0_LCR = 0x03; /* Divisor latch disable, 8-N-1 */
+ set_bitrate(57600);
badbaud = 0;
} else {
- SER0_LCR = 0x80; /* Divisor latch enable */
- SER0_DLL = 0x0D; /* 24000000/13/16 = 115384 baud */
- SER0_LCR = 0x03; /* Divisor latch disable, 8-N-1 */
+ set_bitrate(115200);
}
continue;
}