summaryrefslogtreecommitdiffstats
path: root/firmware/target/arm/s5l8702/ipod6g/serial-ipod6g.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/s5l8702/ipod6g/serial-ipod6g.c')
-rw-r--r--firmware/target/arm/s5l8702/ipod6g/serial-ipod6g.c71
1 files changed, 42 insertions, 29 deletions
diff --git a/firmware/target/arm/s5l8702/ipod6g/serial-ipod6g.c b/firmware/target/arm/s5l8702/ipod6g/serial-ipod6g.c
index b022fef675..c77b5d0c95 100644
--- a/firmware/target/arm/s5l8702/ipod6g/serial-ipod6g.c
+++ b/firmware/target/arm/s5l8702/ipod6g/serial-ipod6g.c
@@ -18,19 +18,16 @@
* KIND, either express or implied.
*
****************************************************************************/
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
+#include <stdint.h>
+#include <stdbool.h>
#include "config.h"
#include "cpu.h"
#include "system.h"
-#include "kernel.h"
-
#include "serial.h"
+
#include "s5l8702.h"
-#include "uc8702.h"
-#include "uart-s5l8702.h"
+#include "uc870x.h"
/* Define LOGF_ENABLE to enable logf output in this file */
#define LOGF_ENABLE
@@ -38,16 +35,26 @@
/* shall include serial HW configuracion for specific target */
-#define IPOD6G_UART_CLK_HZ 12000000 /* external OSC0 ??? */
+#define IPOD6G_UART_CLK_HZ 12000000 /* external OSC0 ??? */
+
+/* This values below are valid with a UCLK of 12MHz */
+#define BRDATA_9600 (77) /* 9615 */
+#define BRDATA_19200 (38) /* 19231 */
+#define BRDATA_28800 (25) /* 28846 */
+#define BRDATA_38400 (19 | (0xc330c << 8)) /* 38305 */
+#define BRDATA_57600 (12) /* 57692 */
+#define BRDATA_115200 (6 | (0xffffff << 8)) /* 114286 */
-extern struct uartc s5l8702_uart;
+
+extern const struct uartc s5l8702_uartc;
#ifdef IPOD_ACCESSORY_PROTOCOL
void iap_rx_isr(int, char*, char*, uint32_t);
#endif
-struct uartc_port ser_port IDATA_ATTR = {
+struct uartc_port ser_port IDATA_ATTR =
+{
/* location */
- .uartc = &s5l8702_uart,
+ .uartc = &s5l8702_uartc,
.id = 0,
/* configuration */
@@ -70,17 +77,18 @@ struct uartc_port ser_port IDATA_ATTR = {
*/
void serial_setup(void)
{
- uart_port_init(&ser_port);
+ uartc_port_open(&ser_port);
/* set a default configuration, Tx and Rx modes are
disabled when the port is initialized */
- uartc_port_config(&ser_port, 115200, ULCON_DATA_BITS_8,
+ uartc_port_config(&ser_port, ULCON_DATA_BITS_8,
ULCON_PARITY_NONE, ULCON_STOP_BITS_1);
+ uartc_port_set_bitrate_raw(&ser_port, BRDATA_115200);
/* enable Tx interrupt request or POLLING mode */
uartc_port_set_tx_mode(&ser_port, UCON_MODE_INTREQ);
- logf("[%lu] serial_setup(): port %d ready!", USEC_TIMER, ser_port.id);
+ logf("[%lu] "MODEL_NAME" port %d ready!", USEC_TIMER, ser_port.id);
}
int tx_rdy(void)
@@ -93,16 +101,15 @@ void tx_writec(unsigned char c)
uartc_port_tx_byte(&ser_port, c);
}
+
#ifdef IPOD_ACCESSORY_PROTOCOL
#include "iap.h"
-enum {
+static enum {
ABR_STATUS_LAUNCHED, /* ST_SYNC */
ABR_STATUS_SYNCING, /* ST_SOF */
ABR_STATUS_DONE
-};
-
-int abr_status;
+} abr_status;
void serial_bitrate(int rate)
{
@@ -131,8 +138,13 @@ void serial_bitrate(int rate)
abr_status = ABR_STATUS_LAUNCHED;
}
else {
+ uint32_t brdata;
+ if (rate == 57600) brdata = BRDATA_57600;
+ else if (rate == 38400) brdata = BRDATA_38400;
+ else if (rate == 19200) brdata = BRDATA_19200;
+ else brdata = BRDATA_9600;
uartc_port_abr_stop(&ser_port); /* abort ABR if already launched */
- uartc_port_set_bitrate(&ser_port, rate);
+ uartc_port_set_bitrate_raw(&ser_port, brdata);
uartc_port_set_rx_mode(&ser_port, UCON_MODE_INTREQ);
abr_status = ABR_STATUS_DONE;
}
@@ -149,22 +161,21 @@ void iap_rx_isr(int len, char *data, char *err, uint32_t abr_cnt)
/* autobauding */
if (abr_cnt) {
#define BR2CNT(s) (IPOD6G_UART_CLK_HZ / (unsigned)(s))
- unsigned speed;
-
if (abr_cnt < BR2CNT(57600*1.1) || abr_cnt > BR2CNT(9600*0.9)) {
/* detected speed out of range, relaunch ABR */
uartc_port_abr_start(&ser_port);
return;
}
/* valid speed detected, select it */
- else if (abr_cnt < BR2CNT(48000)) speed = 57600;
- else if (abr_cnt < BR2CNT(33600)) speed = 38400;
- else if (abr_cnt < BR2CNT(24000)) speed = 28800;
- else if (abr_cnt < BR2CNT(14400)) speed = 19200;
- else speed = 9600;
+ uint32_t brdata;
+ if (abr_cnt < BR2CNT(48000)) brdata = BRDATA_57600;
+ else if (abr_cnt < BR2CNT(33600)) brdata = BRDATA_38400;
+ else if (abr_cnt < BR2CNT(24000)) brdata = BRDATA_28800;
+ else if (abr_cnt < BR2CNT(14400)) brdata = BRDATA_19200;
+ else brdata = BRDATA_9600;
/* set detected speed */
- uartc_port_set_bitrate(&ser_port, speed);
+ uartc_port_set_bitrate_raw(&ser_port, brdata);
uartc_port_set_rx_mode(&ser_port, UCON_MODE_INTREQ);
/* enter SOF state */
@@ -176,10 +187,12 @@ void iap_rx_isr(int len, char *data, char *err, uint32_t abr_cnt)
}
/* process received data */
- while (len--) {
+ while (len--)
+ {
bool sync_done = !iap_getc(*data++);
- if (abr_status == ABR_STATUS_SYNCING) {
+ if (abr_status == ABR_STATUS_SYNCING)
+ {
if (sync_done) {
abr_status = ABR_STATUS_DONE;
}