1
0
Fork 0
forked from len0rd/rockbox

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

View file

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

View file

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

View file

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