?login_element?

Subversion Repositories NedoOS

Rev

Rev 372 | Blame | Compare with Previous | Last modification | View Log | Download

  1. #ifndef _PLAY_H_
  2. #define _PLAY_H_
  3.  
  4.  
  5.  
  6.  
  7. // packet types
  8. #define FROMZX_HELLO     (0x00)
  9. #define FROMZX_FRAMESYNC (0x01)
  10. #define FROMZX_SYNCRPLY  (0x02)
  11. //
  12. #define TOZX_SHUTUP      (0x00)
  13. #define TOZX_DUMP        (0x01)
  14. #define TOZX_SYNCREQ     (0x02)
  15.  
  16.  
  17.  
  18. // format-related structures. WARNING: they depend both on unaligned access capability and little-endian property of the CPU
  19.  
  20. struct packet
  21. {
  22.         uint8_t type;
  23. } __attribute__((packed));
  24.  
  25.  
  26.  
  27. struct rx_packet_framesync
  28. {
  29.         struct packet base;
  30.         uint32_t value; // only valid for little-endian! TODO: upgrade code to support big endian
  31. } __attribute__((packed)); // another nasty hack to simplify code. only valid for architectures that support unaligned access
  32.  
  33. struct rx_packet_syncrply
  34. {
  35.         struct packet base;
  36.         uint32_t value;
  37. } __attribute__((packed));
  38.  
  39. struct rx_packet_hello
  40. {
  41.         struct packet base;
  42.         uint8_t len;
  43.         char text[255];
  44. } __attribute__((packed));
  45.  
  46.  
  47.  
  48. struct tx_packet_shutup
  49. {
  50.         struct packet base;
  51. } __attribute__((packed));
  52.  
  53. struct tx_packet_dump
  54. {
  55.         struct packet base;
  56.         uint8_t data[14];
  57. } __attribute__((packed));
  58.  
  59. struct tx_packet_syncreq
  60. {
  61.         struct packet base;
  62.         uint32_t value;
  63. } __attribute__((packed));
  64.  
  65.  
  66.  
  67.  
  68.  
  69. #define NET_BUF_SIZE (4096) /* must be 2^n */
  70.  
  71. struct net_context
  72. {
  73.         int sock;
  74.  
  75.         unsigned int in_ptr;   // 'input' to the local buffer
  76.         unsigned int out_ptr;  // 'output' from the buffer
  77.  
  78.         uint8_t buf[NET_BUF_SIZE];
  79. };
  80.  
  81. void init_ctx(struct net_context * ctx, int sock);
  82.  
  83. int       get_in_free_size(struct net_context * ctx);           // get total free size in context's fifo
  84. int       get_in_cont_size(struct net_context * ctx);           // get max continuous size in fifo (might be smaller that free_size)
  85. uint8_t * get_in_ptr      (struct net_context * ctx);           // get ptr where data could be 'in' to the context's fifo -- no more than cont_size
  86. void      set_write_size  (struct net_context * ctx, int len);  // set how many bytes were just written to the ptr given by get_in_ptr()
  87.  
  88. int       get_out_used_size(struct net_context * ctx);          // total used bytes in context's fifo
  89. int       get_out_cont_size(struct net_context * ctx);          // continuous bytes
  90. uint8_t * get_out_ptr      (struct net_context * ctx);          // ptr to data
  91. void      set_read_size    (struct net_context * ctx, int len); // set how many bytes were consumed
  92.  
  93.  
  94.  
  95. void play_tune(int sock, struct frame_list * frames);
  96.  
  97.  
  98.  
  99. struct packet * rcv_packet(struct net_context * ctx);
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107. #endif // _PLAY_H_
  108.  
  109.