summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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) {
336 } 336 }
337} 337}
338 338
339/* This function sets the spefified pin up */
340void 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
32void udelay(int usec); 32void udelay(int usec);
33 33
34void 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 */