ARM7 based quadrocopter
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
2.9KB

  1. /***************************************************************************
  2. * sam7fc - Debug Unit RS232 Port *
  3. * *
  4. * Copyright (C) 01/2008 by Olaf Rempel *
  5. * razzor@kopf-tisch.de *
  6. * *
  7. * This program is free software; you can redistribute it and/or modify *
  8. * it under the terms of the GNU General Public License as published by *
  9. * the Free Software Foundation; version 2 of the License *
  10. * *
  11. * This program is distributed in the hope that it will be useful, *
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  14. * GNU General Public License for more details. *
  15. * *
  16. * You should have received a copy of the GNU General Public License *
  17. * along with this program; if not, write to the *
  18. * Free Software Foundation, Inc., *
  19. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  20. ***************************************************************************/
  21. #include <stdint.h>
  22. #include <string.h>
  23. #include "AT91SAM7S256.h"
  24. #include "board.h"
  25. #include "at91_dbgu.h"
  26. #include "at91_sysc.h"
  27. #include "fifo.h"
  28. #define DBGU_BAUDRATE 115200
  29. #define DBGU_FIFO_SIZE 1024
  30. #define DBGU_TX_CHUNKS 16
  31. static struct fifo *txfifo;
  32. static void dbgu_isr(uint32_t status)
  33. {
  34. /* only enabled interrupts */
  35. status &= *AT91C_DBGU_IMR;
  36. if (status & AT91C_US_TXBUFE)
  37. if (fifo_txpdc(txfifo, AT91C_BASE_PDC_DBGU, DBGU_TX_CHUNKS) == 0)
  38. *AT91C_DBGU_IDR = AT91C_US_TXBUFE;
  39. }
  40. void at91_dbgu_init(void)
  41. {
  42. /* switch pins to UART */
  43. *AT91C_PIOA_PDR = AT91C_PA9_DRXD | AT91C_PA10_DTXD;
  44. /* enable Debug Port with 115200 Baud (+0.16%) */
  45. AT91S_DBGU *dbgu = AT91C_BASE_DBGU;
  46. dbgu->DBGU_BRGR = BAUD_TO_DIV(DBGU_BAUDRATE);
  47. dbgu->DBGU_MR = AT91C_US_PAR_NONE | AT91C_US_CHMODE_NORMAL;
  48. dbgu->DBGU_CR = AT91C_US_RXEN | AT91C_US_TXEN | AT91C_US_RSTSTA;
  49. txfifo = fifo_alloc(DBGU_FIFO_SIZE);
  50. /* enable TX PDC */
  51. dbgu->DBGU_PTCR = AT91C_PDC_TXTEN;
  52. sysc_register_isr(AT91_SYSIRQ_DBGU, dbgu_isr);
  53. }
  54. void at91_dbgu_putc(char c)
  55. {
  56. fifo_putbyte(txfifo, c);
  57. *AT91C_DBGU_IER = AT91C_US_TXBUFE;
  58. }
  59. void at91_dbgu_puts(const char *p)
  60. {
  61. fifo_put(txfifo, (char *)p, strlen(p));
  62. *AT91C_DBGU_IER = AT91C_US_TXBUFE;
  63. }
  64. int at91_dbgu_write(void *base, const char *buf, size_t len)
  65. {
  66. int retval = fifo_put(txfifo, (char *)buf, len);
  67. *AT91C_DBGU_IER = AT91C_US_TXBUFE;
  68. return retval;
  69. }