summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
authorKarl Kurbjun <kkurbjun@gmail.com>2009-12-14 06:29:15 +0000
committerKarl Kurbjun <kkurbjun@gmail.com>2009-12-14 06:29:15 +0000
commitac3fe260f1760a1438b6a1a772b01fc999eae6a6 (patch)
tree1dd56d92f3f9529e92ffae91629ba9de6d438e06 /firmware
parent91ada17c36294a1b2ef5f75ed1e231a448de3ea8 (diff)
DM320: Add generic pin-setup function.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23985 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
-rw-r--r--firmware/target/arm/tms320dm320/system-dm320.c84
-rw-r--r--firmware/target/arm/tms320dm320/system-target.h3
2 files changed, 87 insertions, 0 deletions
diff --git a/firmware/target/arm/tms320dm320/system-dm320.c b/firmware/target/arm/tms320dm320/system-dm320.c
index 9dff1afc20..c189a873fe 100644
--- a/firmware/target/arm/tms320dm320/system-dm320.c
+++ b/firmware/target/arm/tms320dm320/system-dm320.c
@@ -336,3 +336,87 @@ void udelay(int usec) {
}
}
+/* This function sets the spefified pin up */
+void dm320_set_io (char pin_num, bool input, bool invert, bool irq, bool irqany,
+ bool chat, char func_num )
+{
+ volatile short *pio;
+ char reg_offset; /* Holds the offset to the register */
+ char shift_val; /* Holds the shift offset to the GPIO bit(s) */
+ short io_val; /* Used as an intermediary to prevent glitchy
+ * assignments. */
+
+ /* Make sure this is a valid pin number */
+ if( (unsigned) pin_num > 40 )
+ return;
+
+ /* Clamp the function number */
+ func_num &= 0x03;
+
+ /* Note that these are integer calculations */
+ reg_offset = (pin_num / 16);
+ shift_val = (pin_num - (16 * reg_offset));
+
+ /* Handle the direction */
+ /* Calculate the pointer to the direction register */
+ pio = &IO_GIO_DIR0 + reg_offset;
+
+ if(input)
+ *pio |= ( 1 << shift_val );
+ else
+ *pio &= ~( 1 << shift_val );
+
+ /* Handle the inversion */
+ /* Calculate the pointer to the inversion register */
+ pio = &IO_GIO_INV0 + reg_offset;
+
+ if(invert)
+ *pio |= ( 1 << shift_val );
+ else
+ *pio &= ~( 1 << shift_val );
+
+ /* Handle the chat */
+ /* Calculate the pointer to the chat register */
+ pio = &IO_GIO_CHAT0 + reg_offset;
+
+ if(chat)
+ *pio |= ( 1 << shift_val );
+ else
+ *pio &= ~( 1 << shift_val );
+
+ /* Handle interrupt configuration */
+ if(pin_num < 16)
+ {
+ /* Sets whether the pin is an irq or not */
+ if(irq)
+ IO_GIO_IRQPORT |= (1 << pin_num );
+ else
+ IO_GIO_IRQPORT &= ~(1 << pin_num );
+
+ /* Set whether this is a falling or any edge sensitive irq */
+ if(irqany)
+ IO_GIO_IRQEDGE |= (1 << pin_num );
+ else
+ IO_GIO_IRQEDGE &= ~(1 << pin_num );
+ }
+
+ /* Handle the function number */
+ /* Calculate the pointer to the function register */
+ reg_offset = ( (pin_num - 9) / 8 );
+ shift_val = ( ((pin_num - 9) - (8 * reg_offset)) * 2 );
+
+ if( pin_num < 9 )
+ {
+ reg_offset = 0;
+ shift_val = 0;
+ }
+
+ /* Calculate the pointer to the function register */
+ pio = &IO_GIO_FSEL0 + reg_offset;
+
+ io_val = *pio;
+ io_val &= ~( 3 << shift_val ); /* zero previous value */
+ io_val |= ( func_num << shift_val ); /* Store new value */
+ *pio = io_val;
+}
+
diff --git a/firmware/target/arm/tms320dm320/system-target.h b/firmware/target/arm/tms320dm320/system-target.h
index a9623bb54f..1c197ce72c 100644
--- a/firmware/target/arm/tms320dm320/system-target.h
+++ b/firmware/target/arm/tms320dm320/system-target.h
@@ -31,4 +31,7 @@
void udelay(int usec);
+void dm320_set_io (char pin_num, bool input, bool invert, bool irq, bool irqany,
+ bool chat, char func_num );
+
#endif /* SYSTEM_TARGET_H */