imx233.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include <stdint.h>
  2. #include <string.h>
  3. #include "imx233.h"
  4. // /code/u-boot/arch/arm/include/asm/arch-mxs
  5. void mmio_write(uint32_t reg, uint32_t data)
  6. {
  7. *(volatile uint32_t *)reg = data;
  8. }
  9. uint32_t mmio_read(uint32_t reg)
  10. {
  11. return *(volatile uint32_t *)reg;
  12. }
  13. void uart_putc(unsigned char byte)
  14. {
  15. // Wait for UART to become ready to transmit.
  16. //while (mmio_read(UART0_FR) & (1 << 5)) { }
  17. while (*((volatile uint32_t*)0x80070018) & 32) {}; // check flag register for TXFF
  18. *((volatile uint32_t *)UART0_DR) = byte;
  19. }
  20. unsigned char uart_getc()
  21. {
  22. // Wait for UART to have received something.
  23. while (*((volatile uint32_t*)0x80070018) & 16) {};
  24. //while (mmio_read(UART0_FR) & (1 << 4)) { }
  25. return *((volatile uint32_t *)UART0_DR);
  26. //return 0;
  27. }
  28. void delay(int32_t count)
  29. {
  30. __asm("__delay_%=: subs %[count], %[count], #1; bne __delay_%=\n"
  31. : : [count]"r"(count) : "cc");
  32. }
  33. void uart_write(const unsigned char* buffer, uint32_t size)
  34. {
  35. for (uint32_t i = 0; i < size; i++) {
  36. uart_putc(buffer[i]);
  37. }
  38. }
  39. void uart_puts(const char* str)
  40. {
  41. uart_write((const unsigned char*) str, strlen(str));
  42. }
  43. void uart_init() {
  44. }