main.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #include <arm/NXP/LPC17xx/LPC17xx.h>
  2. #include "clock.h"
  3. #include "uart.h"
  4. #include "bits.h"
  5. #include "power.h"
  6. #include "timer.h"
  7. #include "ff.h"
  8. #include "diskio.h"
  9. #include "spi.h"
  10. #include "sdcard.h"
  11. #include "fileops.h"
  12. #define EMC0TOGGLE (3<<4)
  13. #define MR0R (1<<1)
  14. int i;
  15. /* FIXME HACK */
  16. volatile enum diskstates disk_state;
  17. int main(void) {
  18. LPC_GPIO2->FIODIR = BV(0) | BV(1) | BV(2);
  19. LPC_GPIO1->FIODIR = 0;
  20. uint32_t p1;
  21. /* connect UART3 on P0[25:26] + SSP1 on P0[6:9] */
  22. LPC_PINCON->PINSEL1=(0xf<<18);
  23. LPC_PINCON->PINSEL0=BV(13) | BV(15) | BV(17) | BV(19);
  24. clock_disconnect();
  25. power_init();
  26. timer_init();
  27. uart_init();
  28. delay_ms(10);
  29. spi_init(SPI_SPEED_SLOW);
  30. sd_init();
  31. /* do this last because the peripheral init()s change PCLK dividers */
  32. clock_init();
  33. file_init();
  34. printf("fileres: %d diskstate: %d\n", file_res, disk_state);
  35. file_open((uint8_t*)"/mon.smc", FA_READ);
  36. spi_set_speed(SPI_SPEED_FAST);
  37. printf("fileres: %d diskstate: %d\n", file_res, disk_state);
  38. uart_putc('S');
  39. for(p1=0; p1<2048; p1++) {
  40. file_read();
  41. }
  42. uart_putc('E');
  43. uart_putcrlf();
  44. printf("sizeof(struct FIL): %d\n", sizeof(file_handle));
  45. uart_trace(file_buf, 0, 512);
  46. /* setup timer (fpga clk) */
  47. LPC_TIM3->CTCR=0;
  48. LPC_TIM3->EMR=EMC0TOGGLE;
  49. LPC_PINCON->PINSEL0=(0x3<<20);
  50. LPC_TIM3->MCR=MR0R;
  51. LPC_TIM3->MR0=1;
  52. LPC_TIM3->TCR=1;
  53. uart_puts("hurr durr derpderpderp\n");
  54. while (1) {
  55. p1 = LPC_GPIO1->FIOPIN;
  56. BITBAND(LPC_GPIO2->FIOPIN, 1) = (p1 & BV(29))>>29;
  57. }
  58. }