Advertisement
Guest User

main.cpp

a guest
May 28th, 2012
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.59 KB | None | 0 0
  1. /*
  2.  * std lib headers
  3.  */
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <stdint.h>
  8.  
  9. /*
  10.  * libmaple headers
  11.  */
  12. #include <wirish.h>
  13. #include <dma.h> // direct memory access
  14.  
  15. /*
  16.  * nano Open Sound Control lib
  17.  * continuous music controller lib
  18.  */
  19. extern "C" {
  20. #include <nosc.h>
  21. #include <cmc.h>
  22. #include <fix16.h>
  23. #include <dma_udp.h>
  24. }
  25.  
  26. uint8_t mac [] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
  27. uint8_t ip [] = {192, 168, 1, 177};
  28. uint8_t gateway [] = {192, 168, 1, 1};
  29. uint8_t subnet [] = {255, 255, 255, 0};
  30. uint8_t sock = 0;
  31. uint16_t port = 3333;
  32.  
  33. uint8_t remote_ip [] = {192, 168, 1, 255};
  34. uint16_t remote_port = 3333;
  35.  
  36. static uint8_t buf [1024];
  37.  
  38. HardwareSPI spi(2);
  39.  
  40. extern "C"{
  41. void initSS ()
  42. {
  43.     pinMode (BOARD_SPI2_NSS_PIN, OUTPUT);
  44. }
  45.  
  46. void setSS ()
  47. {
  48.     digitalWrite (BOARD_SPI2_NSS_PIN, 0); // enable wiz820io
  49. }
  50.  
  51. void resetSS ()
  52. {
  53.     digitalWrite (BOARD_SPI2_NSS_PIN, 1); // dsable wiz820io
  54. }
  55. }
  56.  
  57. void
  58. loop ()
  59. {
  60.     dma_udp_send (sock, buf, 1024);
  61. }
  62.  
  63. void
  64. setup ()
  65. {
  66.   pinMode (BOARD_BUTTON_PIN, INPUT);
  67.   pinMode (BOARD_LED_PIN, OUTPUT);
  68.  
  69.   delay(300);
  70.  
  71.   spi.begin (SPI_18MHZ, MSBFIRST, 0);
  72.     initSS ();
  73.  
  74.     dma_init (DMA1);
  75.     spi_rx_dma_enable (SPI2); // Enables TX DMA on SPI2
  76.     spi_tx_dma_enable (SPI2); // Enables TX DMA on SPI2
  77.  
  78.     // set up dma_udp
  79.     dma_udp_init (mac, ip, gateway, subnet);
  80.     dma_udp_begin (sock, port);
  81.     dma_udp_set_remote (sock, remote_ip, remote_port);
  82. }
  83.  
  84. __attribute__ ((constructor)) void
  85. premain ()
  86. {
  87.   init ();
  88. }
  89.  
  90. int
  91. main (void)
  92. {
  93.   setup ();
  94.  
  95.   while (true)
  96.     loop ();
  97.  
  98.   return 0;
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement