LPC1114 Cortex-M0 hacks.

first.c 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #include <stdint.h>
  2. #define pREG32 (REG32 *)
  3. typedef volatile uint32_t REG32;
  4. #define UART_BASE_ADDRESS (0x40008000)
  5. #define UART_U0LSR_THRE ((unsigned int) 0x00000020)
  6. #define UART_U0LSR (*(pREG32 (0x40008014)))
  7. /* Receive buffer */
  8. #define UART_U0RBR (*(pREG32 (0x40008000)))
  9. #define GPIO_GPIO2_BASE (0x50020000)
  10. #define GPIO_GPIO2DATA (*(pREG32 (0x50023FFC))) // Port data register
  11. #define GPIO_GPIO2DIR (*(pREG32 (0x50028000))) // Data direction register
  12. #define RAM_START 0x10000000
  13. #define RAM_SIZE 8192
  14. void pwm(int level, int top);
  15. __attribute__((naked))
  16. void start(void)
  17. {
  18. GPIO_GPIO2DIR = 0xFFFF;
  19. int top = 100;
  20. for (;;)
  21. {
  22. for (int level = 0; level <= top; level++)
  23. {
  24. pwm(level, top);
  25. }
  26. for (int level = top; level >= 0; level--)
  27. {
  28. pwm(level, top);
  29. }
  30. }
  31. }
  32. void pwm(int level, int top)
  33. {
  34. int runs = 100;
  35. for (int run = 0; run < runs; run++)
  36. {
  37. GPIO_GPIO2DATA = 0;
  38. for (volatile int j = 0; j < level; j++)
  39. ;
  40. GPIO_GPIO2DATA = 1;
  41. for (volatile int j = level; j <= top; j++)
  42. ;
  43. }
  44. }
  45. void startx(void)
  46. {
  47. GPIO_GPIO2DIR = 0xFFFF;
  48. for (;;)
  49. for (int i = 'a'; i <= 'z'; i++)
  50. {
  51. while ((UART_U0LSR & UART_U0LSR_THRE) == 0)
  52. ;
  53. UART_U0RBR = i;
  54. GPIO_GPIO2DATA = i & 1;
  55. for (volatile int j = 0; j < 100000; j++)
  56. {
  57. }
  58. }
  59. }
  60. __attribute__((section(".vectors")))
  61. const void * vectors[] = {
  62. (void *)(RAM_START + RAM_SIZE - 64),
  63. start,
  64. 0,
  65. 0,
  66. 0,
  67. 0,
  68. 0,
  69. 0,
  70. };