mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-12-07 13:45:03 -05:00
Split off target-specific parts from firmware/drivers/serial.c
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29768 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
0dfce1972b
commit
55a7a31ce3
5 changed files with 304 additions and 218 deletions
|
|
@ -584,6 +584,7 @@ drivers/i2c.c
|
|||
target/sh/archos/ata-archos.c
|
||||
target/sh/archos/timer-archos.c
|
||||
target/sh/archos/ata-as-archos.S
|
||||
target/sh/archos/uart-archos.c
|
||||
target/sh/archos/player/button-player.c
|
||||
target/sh/archos/player/hwcompat-player.c
|
||||
target/sh/archos/player/lcd-as-player.S
|
||||
|
|
@ -601,6 +602,7 @@ target/sh/archos/audio-archos.c
|
|||
target/sh/archos/ata-archos.c
|
||||
target/sh/archos/timer-archos.c
|
||||
target/sh/archos/ata-as-archos.S
|
||||
target/sh/archos/uart-archos.c
|
||||
target/sh/archos/lcd-archos-bitmap.c
|
||||
target/sh/archos/lcd-as-archos-bitmap.S
|
||||
target/sh/archos/recorder/button-recorder.c
|
||||
|
|
@ -876,6 +878,7 @@ target/coldfire/iriver/udacodec-iriver.c
|
|||
#ifndef SIMULATOR
|
||||
drivers/sw_i2c.c
|
||||
target/coldfire/ata-as-coldfire.S
|
||||
target/coldfire/uart-coldfire.c
|
||||
target/coldfire/iriver/ata-iriver.c
|
||||
target/coldfire/iriver/lcd-remote-iriver.c
|
||||
target/coldfire/iriver/lcd-remote-as-iriver.S
|
||||
|
|
@ -976,6 +979,7 @@ target/arm/imx31/mmu-imx31.c
|
|||
target/arm/imx31/rolo_restart_firmware.S
|
||||
target/arm/imx31/sdma-imx31.c
|
||||
target/arm/imx31/spi-imx31.c
|
||||
target/arm/imx31/uart-imx31.c
|
||||
target/arm/imx31/gigabeat-s/adc-gigabeat-s.c
|
||||
target/arm/imx31/gigabeat-s/backlight-gigabeat-s.c
|
||||
target/arm/imx31/gigabeat-s/button-gigabeat-s.c
|
||||
|
|
|
|||
|
|
@ -30,223 +30,7 @@
|
|||
#include "serial.h"
|
||||
#include "iap.h"
|
||||
|
||||
#if CONFIG_CPU == IMX31L
|
||||
#include "serial-imx31.h"
|
||||
#endif
|
||||
|
||||
#if CONFIG_CPU == SH7034
|
||||
|
||||
/* FIX: this doesn't work on iRiver or iPod yet */
|
||||
/* iFP7xx has no remote */
|
||||
|
||||
/* Received byte identifiers */
|
||||
#define PLAY 0xC1
|
||||
#define STOP 0xC2
|
||||
#define PREV 0xC4
|
||||
#define NEXT 0xC8
|
||||
#define VOLUP 0xD0
|
||||
#define VOLDN 0xE0
|
||||
|
||||
void serial_setup (void)
|
||||
{
|
||||
/* Set PB10 function to serial Rx */
|
||||
PBCR1 = (PBCR1 & 0xffcf) | 0x0020;
|
||||
|
||||
SMR1 = 0x00;
|
||||
SCR1 = 0;
|
||||
BRR1 = (FREQ/(32*9600))-1;
|
||||
and_b(0, &SSR1); /* The status bits must be read before they are cleared,
|
||||
so we do an AND operation */
|
||||
|
||||
/* Let the hardware settle. The serial port needs to wait "at least
|
||||
the interval required to transmit or receive one bit" before it
|
||||
can be used. */
|
||||
sleep(1);
|
||||
|
||||
SCR1 = 0x10; /* Enable the receiver, no interrupt */
|
||||
}
|
||||
|
||||
int tx_rdy(void)
|
||||
{
|
||||
/* a dummy */
|
||||
return 1;
|
||||
}
|
||||
|
||||
int rx_rdy(void)
|
||||
{
|
||||
if(SSR1 & SCI_RDRF)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
void tx_writec(unsigned char c)
|
||||
{
|
||||
/* a dummy */
|
||||
(void)c;
|
||||
}
|
||||
|
||||
unsigned char rx_readc(void)
|
||||
{
|
||||
char tmp;
|
||||
/* Read byte and clear the Rx Full bit */
|
||||
tmp = RDR1;
|
||||
and_b(~SCI_RDRF, &SSR1);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
|
||||
/* This function returns the received remote control code only if it is
|
||||
received without errors before or after the reception.
|
||||
It therefore returns the received code on the second call after the
|
||||
code has been received. */
|
||||
int remote_control_rx(void)
|
||||
{
|
||||
static int last_valid_button = BUTTON_NONE;
|
||||
static int last_was_error = false;
|
||||
int btn;
|
||||
int ret = BUTTON_NONE;
|
||||
|
||||
/* Errors? Just clear'em. The receiver stops if we don't */
|
||||
if(SSR1 & (SCI_ORER | SCI_FER | SCI_PER)) {
|
||||
and_b(~(SCI_ORER | SCI_FER | SCI_PER), &SSR1);
|
||||
last_valid_button = BUTTON_NONE;
|
||||
last_was_error = true;
|
||||
return BUTTON_NONE;
|
||||
}
|
||||
|
||||
if(rx_rdy()) {
|
||||
btn = rx_readc();
|
||||
|
||||
if(last_was_error)
|
||||
{
|
||||
last_valid_button = BUTTON_NONE;
|
||||
ret = BUTTON_NONE;
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (btn)
|
||||
{
|
||||
case STOP:
|
||||
last_valid_button = BUTTON_RC_STOP;
|
||||
break;
|
||||
|
||||
case PLAY:
|
||||
last_valid_button = BUTTON_RC_PLAY;
|
||||
break;
|
||||
|
||||
case VOLUP:
|
||||
last_valid_button = BUTTON_RC_VOL_UP;
|
||||
break;
|
||||
|
||||
case VOLDN:
|
||||
last_valid_button = BUTTON_RC_VOL_DOWN;
|
||||
break;
|
||||
|
||||
case PREV:
|
||||
last_valid_button = BUTTON_RC_LEFT;
|
||||
break;
|
||||
|
||||
case NEXT:
|
||||
last_valid_button = BUTTON_RC_RIGHT;
|
||||
break;
|
||||
|
||||
default:
|
||||
last_valid_button = BUTTON_NONE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* This means that a valid remote control character was received
|
||||
the last time we were called, with no receiver errors either before
|
||||
or after. Then we can assume that there really is a remote control
|
||||
attached, and return the button code. */
|
||||
ret = last_valid_button;
|
||||
last_valid_button = BUTTON_NONE;
|
||||
}
|
||||
|
||||
last_was_error = false;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#elif defined(CPU_COLDFIRE)
|
||||
|
||||
void serial_setup (void)
|
||||
{
|
||||
UCR0 = 0x30; /* Reset transmitter */
|
||||
UCSR0 = 0xdd; /* Timer mode */
|
||||
|
||||
UCR0 = 0x10; /* Reset pointer */
|
||||
UMR0 = 0x13; /* No parity, 8 bits */
|
||||
UMR0 = 0x07; /* 1 stop bit */
|
||||
|
||||
UCR0 = 0x04; /* Tx enable */
|
||||
}
|
||||
|
||||
int tx_rdy(void)
|
||||
{
|
||||
if(USR0 & 0x04)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
int rx_rdy(void)
|
||||
{
|
||||
/* a dummy */
|
||||
return 0;
|
||||
}
|
||||
|
||||
void tx_writec(unsigned char c)
|
||||
{
|
||||
UTB0 = c;
|
||||
}
|
||||
|
||||
#elif (CONFIG_CPU == IMX31L)
|
||||
|
||||
void serial_setup(void)
|
||||
{
|
||||
#ifdef UART_INT /*enable UART Interrupts */
|
||||
UCR1_1 |= (EUARTUCR1_TRDYEN | EUARTUCR1_RRDYEN | EUARTUCR1_TXMPTYEN);
|
||||
UCR4_1 |= (EUARTUCR4_TCEN);
|
||||
#else /*disable UART Interrupts*/
|
||||
UCR1_1 &= ~(EUARTUCR1_TRDYEN | EUARTUCR1_RRDYEN | EUARTUCR1_TXMPTYEN);
|
||||
UCR4_1 &= ~(EUARTUCR4_TCEN);
|
||||
#endif
|
||||
UCR1_1 |= EUARTUCR1_UARTEN;
|
||||
UCR2_1 |= (EUARTUCR2_TXEN | EUARTUCR2_RXEN | EUARTUCR2_IRTS);
|
||||
|
||||
/* Tx,Rx Interrupt Trigger levels, Disable for now*/
|
||||
/*UFCR1 |= (UFCR1_TXTL_32 | UFCR1_RXTL_32);*/
|
||||
}
|
||||
|
||||
int tx_rdy(void)
|
||||
{
|
||||
if((UTS1 & EUARTUTS_TXEMPTY))
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*Not ready...After first Rx, UTS1 & UTS1_RXEMPTY
|
||||
keeps returning true*/
|
||||
int rx_rdy(void)
|
||||
{
|
||||
if(!(UTS1 & EUARTUTS_RXEMPTY))
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
void tx_writec(unsigned char c)
|
||||
{
|
||||
UTXD1=(int) c;
|
||||
}
|
||||
|
||||
#elif defined(IPOD_ACCESSORY_PROTOCOL)
|
||||
#if defined(IPOD_ACCESSORY_PROTOCOL)
|
||||
static int autobaud = 0;
|
||||
void serial_setup (void)
|
||||
{
|
||||
|
|
@ -419,7 +203,6 @@ void SERIAL0(void)
|
|||
newpkt = pkt;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void dprintf(const char * str, ... )
|
||||
|
|
|
|||
72
firmware/target/arm/imx31/uart-imx31.c
Normal file
72
firmware/target/arm/imx31/uart-imx31.c
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
/***************************************************************************
|
||||
* __________ __ ___.
|
||||
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||
* \/ \/ \/ \/ \/
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 2002 by Alan Korr & Nick Robinson
|
||||
*
|
||||
* 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 software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
****************************************************************************/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "button.h"
|
||||
#include "cpu.h"
|
||||
#include "system.h"
|
||||
#include "kernel.h"
|
||||
#include "serial.h"
|
||||
|
||||
#include "serial-imx31.h"
|
||||
|
||||
void serial_setup(void)
|
||||
{
|
||||
#ifdef UART_INT /*enable UART Interrupts */
|
||||
UCR1_1 |= (EUARTUCR1_TRDYEN | EUARTUCR1_RRDYEN | EUARTUCR1_TXMPTYEN);
|
||||
UCR4_1 |= (EUARTUCR4_TCEN);
|
||||
#else /*disable UART Interrupts*/
|
||||
UCR1_1 &= ~(EUARTUCR1_TRDYEN | EUARTUCR1_RRDYEN | EUARTUCR1_TXMPTYEN);
|
||||
UCR4_1 &= ~(EUARTUCR4_TCEN);
|
||||
#endif
|
||||
UCR1_1 |= EUARTUCR1_UARTEN;
|
||||
UCR2_1 |= (EUARTUCR2_TXEN | EUARTUCR2_RXEN | EUARTUCR2_IRTS);
|
||||
|
||||
/* Tx,Rx Interrupt Trigger levels, Disable for now*/
|
||||
/*UFCR1 |= (UFCR1_TXTL_32 | UFCR1_RXTL_32);*/
|
||||
}
|
||||
|
||||
int tx_rdy(void)
|
||||
{
|
||||
if((UTS1 & EUARTUTS_TXEMPTY))
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*Not ready...After first Rx, UTS1 & UTS1_RXEMPTY
|
||||
keeps returning true*/
|
||||
int rx_rdy(void)
|
||||
{
|
||||
if(!(UTS1 & EUARTUTS_RXEMPTY))
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
void tx_writec(unsigned char c)
|
||||
{
|
||||
UTXD1=(int) c;
|
||||
}
|
||||
|
||||
60
firmware/target/coldfire/uart-coldfire.c
Normal file
60
firmware/target/coldfire/uart-coldfire.c
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
/***************************************************************************
|
||||
* __________ __ ___.
|
||||
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||
* \/ \/ \/ \/ \/
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 2002 by Alan Korr & Nick Robinson
|
||||
*
|
||||
* 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 software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
****************************************************************************/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "cpu.h"
|
||||
#include "system.h"
|
||||
#include "serial.h"
|
||||
|
||||
void serial_setup (void)
|
||||
{
|
||||
UCR0 = 0x30; /* Reset transmitter */
|
||||
UCSR0 = 0xdd; /* Timer mode */
|
||||
|
||||
UCR0 = 0x10; /* Reset pointer */
|
||||
UMR0 = 0x13; /* No parity, 8 bits */
|
||||
UMR0 = 0x07; /* 1 stop bit */
|
||||
|
||||
UCR0 = 0x04; /* Tx enable */
|
||||
}
|
||||
|
||||
int tx_rdy(void)
|
||||
{
|
||||
if(USR0 & 0x04)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
int rx_rdy(void)
|
||||
{
|
||||
/* a dummy */
|
||||
return 0;
|
||||
}
|
||||
|
||||
void tx_writec(unsigned char c)
|
||||
{
|
||||
UTB0 = c;
|
||||
}
|
||||
|
||||
167
firmware/target/sh/archos/uart-archos.c
Normal file
167
firmware/target/sh/archos/uart-archos.c
Normal file
|
|
@ -0,0 +1,167 @@
|
|||
/***************************************************************************
|
||||
* __________ __ ___.
|
||||
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||
* \/ \/ \/ \/ \/
|
||||
* $Id$
|
||||
*
|
||||
* Copyright (C) 2002 by Alan Korr & Nick Robinson
|
||||
*
|
||||
* 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 software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
****************************************************************************/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "button.h"
|
||||
#include "cpu.h"
|
||||
#include "system.h"
|
||||
#include "kernel.h"
|
||||
#include "serial.h"
|
||||
|
||||
/* FIX: this doesn't work on iRiver or iPod yet */
|
||||
/* iFP7xx has no remote */
|
||||
|
||||
/* Received byte identifiers */
|
||||
#define PLAY 0xC1
|
||||
#define STOP 0xC2
|
||||
#define PREV 0xC4
|
||||
#define NEXT 0xC8
|
||||
#define VOLUP 0xD0
|
||||
#define VOLDN 0xE0
|
||||
|
||||
void serial_setup (void)
|
||||
{
|
||||
/* Set PB10 function to serial Rx */
|
||||
PBCR1 = (PBCR1 & 0xffcf) | 0x0020;
|
||||
|
||||
SMR1 = 0x00;
|
||||
SCR1 = 0;
|
||||
BRR1 = (FREQ/(32*9600))-1;
|
||||
and_b(0, &SSR1); /* The status bits must be read before they are cleared,
|
||||
so we do an AND operation */
|
||||
|
||||
/* Let the hardware settle. The serial port needs to wait "at least
|
||||
the interval required to transmit or receive one bit" before it
|
||||
can be used. */
|
||||
sleep(1);
|
||||
|
||||
SCR1 = 0x10; /* Enable the receiver, no interrupt */
|
||||
}
|
||||
|
||||
int tx_rdy(void)
|
||||
{
|
||||
/* a dummy */
|
||||
return 1;
|
||||
}
|
||||
|
||||
int rx_rdy(void)
|
||||
{
|
||||
if(SSR1 & SCI_RDRF)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
void tx_writec(unsigned char c)
|
||||
{
|
||||
/* a dummy */
|
||||
(void)c;
|
||||
}
|
||||
|
||||
unsigned char rx_readc(void)
|
||||
{
|
||||
char tmp;
|
||||
/* Read byte and clear the Rx Full bit */
|
||||
tmp = RDR1;
|
||||
and_b(~SCI_RDRF, &SSR1);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
|
||||
/* This function returns the received remote control code only if it is
|
||||
received without errors before or after the reception.
|
||||
It therefore returns the received code on the second call after the
|
||||
code has been received. */
|
||||
int remote_control_rx(void)
|
||||
{
|
||||
static int last_valid_button = BUTTON_NONE;
|
||||
static int last_was_error = false;
|
||||
int btn;
|
||||
int ret = BUTTON_NONE;
|
||||
|
||||
/* Errors? Just clear'em. The receiver stops if we don't */
|
||||
if(SSR1 & (SCI_ORER | SCI_FER | SCI_PER)) {
|
||||
and_b(~(SCI_ORER | SCI_FER | SCI_PER), &SSR1);
|
||||
last_valid_button = BUTTON_NONE;
|
||||
last_was_error = true;
|
||||
return BUTTON_NONE;
|
||||
}
|
||||
|
||||
if(rx_rdy()) {
|
||||
btn = rx_readc();
|
||||
|
||||
if(last_was_error)
|
||||
{
|
||||
last_valid_button = BUTTON_NONE;
|
||||
ret = BUTTON_NONE;
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (btn)
|
||||
{
|
||||
case STOP:
|
||||
last_valid_button = BUTTON_RC_STOP;
|
||||
break;
|
||||
|
||||
case PLAY:
|
||||
last_valid_button = BUTTON_RC_PLAY;
|
||||
break;
|
||||
|
||||
case VOLUP:
|
||||
last_valid_button = BUTTON_RC_VOL_UP;
|
||||
break;
|
||||
|
||||
case VOLDN:
|
||||
last_valid_button = BUTTON_RC_VOL_DOWN;
|
||||
break;
|
||||
|
||||
case PREV:
|
||||
last_valid_button = BUTTON_RC_LEFT;
|
||||
break;
|
||||
|
||||
case NEXT:
|
||||
last_valid_button = BUTTON_RC_RIGHT;
|
||||
break;
|
||||
|
||||
default:
|
||||
last_valid_button = BUTTON_NONE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* This means that a valid remote control character was received
|
||||
the last time we were called, with no receiver errors either before
|
||||
or after. Then we can assume that there really is a remote control
|
||||
attached, and return the button code. */
|
||||
ret = last_valid_button;
|
||||
last_valid_button = BUTTON_NONE;
|
||||
}
|
||||
|
||||
last_was_error = false;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue