embedded.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #ifndef EMBEDDED_H
  2. #define EMBEDDED_H
  3. #include <ctype.h>
  4. #include <inttypes.h>
  5. /* must provide
  6. - mutex_create_p
  7. - pthread_create_name
  8. - register_xxx (see below)
  9. - stack size
  10. - s16_t, s32_t, s64_t and u64_t
  11. - PLAYER_ID / custom_player_id
  12. can overload (use #define)
  13. - exit
  14. - gettime_ms
  15. - BASE_CAP
  16. - EXT_BSS
  17. recommended to add platform specific include(s) here
  18. */
  19. typedef int16_t s16_t;
  20. typedef int32_t s32_t;
  21. typedef int64_t s64_t;
  22. typedef unsigned long long u64_t;
  23. #ifndef PTHREAD_STACK_MIN
  24. #define PTHREAD_STACK_MIN 256
  25. #endif
  26. #ifndef _CONST
  27. #define _CONST
  28. #endif
  29. #define STREAM_THREAD_STACK_SIZE 4 * 1024
  30. #define DECODE_THREAD_STACK_SIZE 14 * 1024
  31. #define OUTPUT_THREAD_STACK_SIZE 4 * 1024
  32. #define IR_THREAD_STACK_SIZE 4 * 1024
  33. // number of times the 5s search for a server will happen before slimproto exits (0 = no limit)
  34. #define MAX_SERVER_RETRIES 5
  35. // or can be as simple as #define PLAYER_ID 100
  36. #define PLAYER_ID custom_player_id
  37. extern u8_t custom_player_id;
  38. #if BYTES_PER_FRAME == 8
  39. #define BASE_CAP "Model=squeezeesp32,AccuratePlayPoints=1,HasDigitalOut=1,HasPolarityInversion=1,Balance=1,Depth=32,Firmware=" VERSION
  40. #else
  41. #define BASE_CAP "Model=squeezeesp32,AccuratePlayPoints=1,HasDigitalOut=1,HasPolarityInversion=1,Balance=1,Depth=16,Firmware=" VERSION
  42. #endif
  43. // to force some special buffer attribute
  44. #define EXT_BSS __attribute__((section(".ext_ram.bss")))
  45. // all exit() calls are made from main thread (or a function called in main thread)
  46. #define exit(code) { int ret = code; pthread_exit(&ret); }
  47. #define gettime_ms _gettime_ms_
  48. #define mutex_create_p(m) mutex_create(m)
  49. uint32_t _gettime_ms_(void);
  50. int pthread_create_name(pthread_t *thread, _CONST pthread_attr_t *attr,
  51. void *(*start_routine)( void * ), void *arg, char *name);
  52. // must provide of #define as empty macros
  53. void embedded_init(void);
  54. void register_external(void);
  55. void deregister_external(void);
  56. void decode_restore(int external);
  57. // used when other client wants to use slimproto socket to send messages
  58. extern mutex_type slimp_mutex;
  59. #define LOCK_P mutex_lock(slimp_mutex)
  60. #define UNLOCK_P mutex_unlock(slimp_mutex)
  61. // bitmap of plugs status
  62. #define PLUG_LINE_IN 0x01
  63. #define PLUG_LINE_OUT 0x02
  64. #define PLUG_HEADPHONE 0x04
  65. u16_t get_RSSI(void); // must provide or define as 0xffff
  66. u16_t get_plugged(void); // must provide or define as 0x0
  67. u16_t get_battery(void); // must provide 12 bits data or define as 0x0 (exact meaning is device-dependant)
  68. // set name
  69. void set_name(char *name); // can be defined as an empty macro
  70. // to be defined to nothing if you don't want to support these
  71. extern struct visu_export_s {
  72. pthread_mutex_t mutex;
  73. u32_t level, size, rate, gain;
  74. void *buffer;
  75. bool running;
  76. } visu_export;
  77. void output_visu_export(void *frames, frames_t out_frames, u32_t rate, bool silence, u32_t gain);
  78. void output_visu_init(log_level level);
  79. void output_visu_close(void);
  80. // optional, please chain if used
  81. bool (*slimp_handler)(u8_t *data, int len);
  82. void (*slimp_loop)(void);
  83. void (*server_notify)(in_addr_t ip, u16_t hport, u16_t cport);
  84. #endif // EMBEDDED_H