diff options
author | Karl Kurbjun <kkurbjun@gmail.com> | 2009-12-14 06:29:15 +0000 |
---|---|---|
committer | Karl Kurbjun <kkurbjun@gmail.com> | 2009-12-14 06:29:15 +0000 |
commit | ac3fe260f1760a1438b6a1a772b01fc999eae6a6 (patch) | |
tree | 1dd56d92f3f9529e92ffae91629ba9de6d438e06 | |
parent | 91ada17c36294a1b2ef5f75ed1e231a448de3ea8 (diff) | |
download | rockbox-ac3fe260f1760a1438b6a1a772b01fc999eae6a6.tar.gz rockbox-ac3fe260f1760a1438b6a1a772b01fc999eae6a6.zip |
DM320: Add generic pin-setup function.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23985 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | firmware/target/arm/tms320dm320/system-dm320.c | 84 | ||||
-rw-r--r-- | firmware/target/arm/tms320dm320/system-target.h | 3 |
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) { | |||
336 | } | 336 | } |
337 | } | 337 | } |
338 | 338 | ||
339 | /* This function sets the spefified pin up */ | ||
340 | void dm320_set_io (char pin_num, bool input, bool invert, bool irq, bool irqany, | ||
341 | bool chat, char func_num ) | ||
342 | { | ||
343 | volatile short *pio; | ||
344 | char reg_offset; /* Holds the offset to the register */ | ||
345 | char shift_val; /* Holds the shift offset to the GPIO bit(s) */ | ||
346 | short io_val; /* Used as an intermediary to prevent glitchy | ||
347 | * assignments. */ | ||
348 | |||
349 | /* Make sure this is a valid pin number */ | ||
350 | if( (unsigned) pin_num > 40 ) | ||
351 | return; | ||
352 | |||
353 | /* Clamp the function number */ | ||
354 | func_num &= 0x03; | ||
355 | |||
356 | /* Note that these are integer calculations */ | ||
357 | reg_offset = (pin_num / 16); | ||
358 | shift_val = (pin_num - (16 * reg_offset)); | ||
359 | |||
360 | /* Handle the direction */ | ||
361 | /* Calculate the pointer to the direction register */ | ||
362 | pio = &IO_GIO_DIR0 + reg_offset; | ||
363 | |||
364 | if(input) | ||
365 | *pio |= ( 1 << shift_val ); | ||
366 | else | ||
367 | *pio &= ~( 1 << shift_val ); | ||
368 | |||
369 | /* Handle the inversion */ | ||
370 | /* Calculate the pointer to the inversion register */ | ||
371 | pio = &IO_GIO_INV0 + reg_offset; | ||
372 | |||
373 | if(invert) | ||
374 | *pio |= ( 1 << shift_val ); | ||
375 | else | ||
376 | *pio &= ~( 1 << shift_val ); | ||
377 | |||
378 | /* Handle the chat */ | ||
379 | /* Calculate the pointer to the chat register */ | ||
380 | pio = &IO_GIO_CHAT0 + reg_offset; | ||
381 | |||
382 | if(chat) | ||
383 | *pio |= ( 1 << shift_val ); | ||
384 | else | ||
385 | *pio &= ~( 1 << shift_val ); | ||
386 | |||
387 | /* Handle interrupt configuration */ | ||
388 | if(pin_num < 16) | ||
389 | { | ||
390 | /* Sets whether the pin is an irq or not */ | ||
391 | if(irq) | ||
392 | IO_GIO_IRQPORT |= (1 << pin_num ); | ||
393 | else | ||
394 | IO_GIO_IRQPORT &= ~(1 << pin_num ); | ||
395 | |||
396 | /* Set whether this is a falling or any edge sensitive irq */ | ||
397 | if(irqany) | ||
398 | IO_GIO_IRQEDGE |= (1 << pin_num ); | ||
399 | else | ||
400 | IO_GIO_IRQEDGE &= ~(1 << pin_num ); | ||
401 | } | ||
402 | |||
403 | /* Handle the function number */ | ||
404 | /* Calculate the pointer to the function register */ | ||
405 | reg_offset = ( (pin_num - 9) / 8 ); | ||
406 | shift_val = ( ((pin_num - 9) - (8 * reg_offset)) * 2 ); | ||
407 | |||
408 | if( pin_num < 9 ) | ||
409 | { | ||
410 | reg_offset = 0; | ||
411 | shift_val = 0; | ||
412 | } | ||
413 | |||
414 | /* Calculate the pointer to the function register */ | ||
415 | pio = &IO_GIO_FSEL0 + reg_offset; | ||
416 | |||
417 | io_val = *pio; | ||
418 | io_val &= ~( 3 << shift_val ); /* zero previous value */ | ||
419 | io_val |= ( func_num << shift_val ); /* Store new value */ | ||
420 | *pio = io_val; | ||
421 | } | ||
422 | |||
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 @@ | |||
31 | 31 | ||
32 | void udelay(int usec); | 32 | void udelay(int usec); |
33 | 33 | ||
34 | void dm320_set_io (char pin_num, bool input, bool invert, bool irq, bool irqany, | ||
35 | bool chat, char func_num ); | ||
36 | |||
34 | #endif /* SYSTEM_TARGET_H */ | 37 | #endif /* SYSTEM_TARGET_H */ |