#include #define pREG32 (REG32 *) typedef volatile uint32_t REG32; #define UART_BASE_ADDRESS (0x40008000) #define UART_U0LSR_THRE ((unsigned int) 0x00000020) #define UART_U0LSR (*(pREG32 (0x40008014))) /* Receive buffer */ #define UART_U0RBR (*(pREG32 (0x40008000))) #define GPIO_GPIO2_BASE (0x50020000) #define GPIO_GPIO2DATA (*(pREG32 (0x50023FFC))) // Port data register #define GPIO_GPIO2DIR (*(pREG32 (0x50028000))) // Data direction register #define RAM_START 0x10000000 #define RAM_SIZE 8192 void pwm(int level, int top); __attribute__((naked)) void start(void) { GPIO_GPIO2DIR = 0xFFFF; int top = 100; for (;;) { for (int level = 0; level <= top; level++) { pwm(level, top); } for (int level = top; level >= 0; level--) { pwm(level, top); } } } void pwm(int level, int top) { int runs = 100; for (int run = 0; run < runs; run++) { GPIO_GPIO2DATA = 0; for (volatile int j = 0; j < level; j++) ; GPIO_GPIO2DATA = 1; for (volatile int j = level; j <= top; j++) ; } } void startx(void) { GPIO_GPIO2DIR = 0xFFFF; for (;;) for (int i = 'a'; i <= 'z'; i++) { while ((UART_U0LSR & UART_U0LSR_THRE) == 0) ; UART_U0RBR = i; GPIO_GPIO2DATA = i & 1; for (volatile int j = 0; j < 100000; j++) { } } } __attribute__((section(".vectors"))) const void * vectors[] = { (void *)(RAM_START + RAM_SIZE - 64), start, 0, 0, 0, 0, 0, 0, };