Atomic GPIO access

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7114 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Linus Nielsen Feltzing 2005-07-12 07:25:01 +00:00
parent d2ca7fc5de
commit 192a604cd4
4 changed files with 43 additions and 42 deletions

View file

@ -18,6 +18,7 @@
****************************************************************************/
#include "config.h"
#include "cpu.h"
#include "system.h"
#include "kernel.h"
#include "thread.h"
#include "adc.h"
@ -111,11 +112,11 @@ static unsigned char adcdata[NUM_ADC_CHANNELS];
#define CS_LO GPIO_OUT &= ~0x80
#define CS_HI GPIO_OUT |= 0x80
#define CLK_LO GPIO_OUT &= ~0x00400000
#define CLK_HI GPIO_OUT |= 0x00400000
#define CLK_LO and_l(~0x00400000, &GPIO_OUT)
#define CLK_HI or_l(0x00400000, &GPIO_OUT)
#define DO (GPIO_READ & 0x80000000)
#define DI_LO GPIO_OUT &= ~0x00200000
#define DI_HI GPIO_OUT |= 0x00200000
#define DI_LO and_l(~0x00200000, &GPIO_OUT)
#define DI_HI or_l(0x00200000, &GPIO_OUT)
/* delay loop */
#define DELAY do { int _x; for(_x=0;_x<10;_x++);} while (0)
@ -194,13 +195,13 @@ static void adc_tick(void)
void adc_init(void)
{
GPIO_FUNCTION |= 0x80600080; /* GPIO7: CS
GPIO21: Data In (to the ADC)
GPIO22: CLK
GPIO31: Data Out (from the ADC) */
GPIO_ENABLE |= 0x00600080;
GPIO_OUT |= 0x80; /* CS high */
GPIO_OUT &= ~0x00400000; /* CLK low */
or_l(0x80600080, &GPIO_FUNCTION); /* GPIO7: CS
GPIO21: Data In (to the ADC)
GPIO22: CLK
GPIO31: Data Out (from the ADC) */
or_l(0x00600080, &GPIO_ENABLE);
or_l(0x80, &GPIO_OUT); /* CS high */
and_l(~0x00400000, &GPIO_OUT); /* CLK low */
adc_scan(ADC_BATTERY);

View file

@ -1092,10 +1092,10 @@ int ata_hard_reset(void)
or_b(0x02, &PADRH); /* negate _RESET */
sleep(1); /* > 2ms */
#elif CONFIG_CPU == MCF5249
GPIO_OUT &= ~0x00080000;
and_l(~0x00080000, &GPIO_OUT);
sleep(1); /* > 25us */
GPIO_OUT |= 0x00080000;
or_l(0x00080000, &GPIO_OUT);
sleep(1); /* > 25us */
#elif CONFIG_CPU == TCC730
@ -1234,12 +1234,12 @@ void ata_enable(bool on)
or_b(0x80, &PAIORL);
#elif CONFIG_CPU == MCF5249
if(on)
GPIO_OUT &= ~0x0040000;
and_l(~0x0040000, &GPIO_OUT);
else
GPIO_OUT |= 0x0040000;
or_l(0x0040000, &GPIO_OUT);
GPIO_ENABLE |= 0x00040000;
GPIO_FUNCTION |= 0x00040000;
or_l(0x00040000, &GPIO_ENABLE);
or_l(0x00040000, &GPIO_FUNCTION);
#elif CONFIG_CPU == TCC730
#endif
@ -1408,14 +1408,14 @@ int ata_init(void)
PACR2 &= 0xBFFF; /* GPIO function for PA7 (IDE enable) */
#elif CONFIG_CPU == MCF5249
/* Enable disk LED & ISD chip power control */
GPIO_OUT &= ~0x0000240;
GPIO_ENABLE |= 0x00000240;
GPIO_FUNCTION |= 0x00000200;
and_l(~0x0000240, &GPIO_OUT);
or_l(0x00000240, &GPIO_ENABLE);
or_l(0x00000200, &GPIO_FUNCTION);
/* ATA reset */
GPIO_OUT |= 0x00080000;
GPIO_ENABLE |= 0x00080000;
GPIO_FUNCTION |= 0x00080000;
or_l(0x00080000, &GPIO_OUT);
or_l(0x00080000, &GPIO_ENABLE);
or_l(0x00080000, &GPIO_FUNCTION);
/* FYI: The IDECONFIGx registers are set by set_cpu_frequency() */
#endif

View file

@ -60,16 +60,16 @@ int radio_get_status(void)
void power_init(void)
{
#if CONFIG_CPU == MCF5249
GPIO1_OUT |= 0x00080000;
GPIO1_ENABLE |= 0x00080000;
GPIO1_FUNCTION |= 0x00080000;
or_l(0x00080000, &GPIO1_OUT);
or_l(0x00080000, &GPIO1_ENABLE);
or_l(0x00080000, &GPIO1_FUNCTION);
#ifdef BOOTLOADER
/* Hard drive power default = off in bootloader*/
GPIO_OUT |= 0x80000000;
or_l(0x80000000, &GPIO_OUT);
#endif
GPIO_ENABLE |= 0x80000000;
GPIO_FUNCTION |= 0x80000000;
or_l(0x80000000, &GPIO_ENABLE);
or_l(0x80000000, &GPIO_FUNCTION);
#ifdef HAVE_SPDIF_POWER
spdif_power_enable(false);
#endif
@ -139,17 +139,17 @@ void charger_enable(bool on)
#ifdef HAVE_SPDIF_POWER
void spdif_power_enable(bool on)
{
GPIO1_FUNCTION |= 0x01000000;
GPIO1_ENABLE |= 0x01000000;
or_l(0x01000000, &GPIO1_FUNCTION);
or_l(0x01000000, &GPIO1_ENABLE);
#ifdef SPDIF_POWER_INVERTED
if(!on)
#else
if(on)
#endif
GPIO1_OUT &= ~0x01000000;
and_l(~0x01000000, &GPIO1_OUT);
else
GPIO1_OUT |= 0x01000000;
or_l(0x01000000, &GPIO1_OUT);
}
#endif
@ -160,9 +160,9 @@ void ide_power_enable(bool on)
#if CONFIG_CPU == MCF5249
if(on)
GPIO_OUT &= ~0x80000000;
and_l(~0x80000000, &GPIO_OUT);
else
GPIO_OUT |= 0x80000000;
or_l(0x80000000, &GPIO_OUT);
#elif defined(GMINI_ARCH)
if(on)
P1 |= 0x08;
@ -243,7 +243,7 @@ void power_off(void)
{
set_irq_level(HIGHEST_IRQ_LEVEL);
#if CONFIG_CPU == MCF5249
GPIO1_OUT &= ~0x00080000;
and_l(~0x00080000, &GPIO1_OUT);
#elif defined(GMINI_ARCH)
P1 &= ~1;
P1CON &= ~1;

View file

@ -134,13 +134,13 @@ static void usb_enable(bool on)
if(on)
{
/* Power on the Cypress chip */
GPIO_OUT |= 0x01000000;
or_l(0x01000000, &GPIO_OUT);
sleep(2);
}
else
{
/* Power off the Cypress chip */
GPIO_OUT &= ~0x01000000;
and_l(~0x01000000, &GPIO_OUT);
}
#else
@ -429,11 +429,11 @@ void usb_init(void)
countdown = -1;
#ifdef USB_IRIVERSTYLE
GPIO_OUT &= ~0x01000000; /* GPIO24 is the Cypress chip power */
GPIO_ENABLE |= 0x01000000;
GPIO_FUNCTION |= 0x01000000;
and_l(~0x01000000, &GPIO_OUT); /* GPIO24 is the Cypress chip power */
or_l(0x01000000, &GPIO_ENABLE);
or_l(0x01000000, &GPIO_FUNCTION);
GPIO1_FUNCTION |= 0x00000080; /* GPIO39 is the USB detect input */
or_l(0x00000080, &GPIO1_FUNCTION); /* GPIO39 is the USB detect input */
#endif
usb_enable(false);