2
0

embedded.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. // otherwise just leave it empty
  46. void em_logprint(const char *fmt, ...);
  47. #define LOG_ERROR(fmt, ...) em_logprint("%s %s:%d " fmt "\n", logtime(), __FUNCTION__, __LINE__, ##__VA_ARGS__);
  48. // all exit() calls are made from main thread (or a function called in main thread)
  49. void embedded_exit(int code);
  50. #define exit(code) do { embedded_exit(code); } while (0)
  51. #define gettime_ms _gettime_ms_
  52. #define mutex_create_p(m) mutex_create(m)
  53. uint32_t _gettime_ms_(void);
  54. int pthread_create_name(pthread_t *thread, _CONST pthread_attr_t *attr,
  55. void *(*start_routine)( void * ), void *arg, char *name);
  56. // must provide of #define as empty macros
  57. int embedded_init(void);
  58. void register_external(void);
  59. void deregister_external(void);
  60. void decode_restore(int external);
  61. void powering(bool on);
  62. // used when other client wants to use slimproto socket to send messages
  63. extern mutex_type slimp_mutex;
  64. #define LOCK_P mutex_lock(slimp_mutex)
  65. #define UNLOCK_P mutex_unlock(slimp_mutex)
  66. // bitmap of plugs status
  67. #define PLUG_LINE_IN 0x01
  68. #define PLUG_LINE_OUT 0x02
  69. #define PLUG_HEADPHONE 0x04
  70. u16_t get_RSSI(void); // must provide or define as 0xffff
  71. u16_t get_plugged(void); // must provide or define as 0x0
  72. u16_t get_battery(void); // must provide 12 bits data or define as 0x0 (exact meaning is device-dependant)
  73. // set name
  74. void set_name(char *name); // can be defined as an empty macro
  75. // to be defined to nothing if you don't want to support these
  76. extern struct visu_export_s {
  77. pthread_mutex_t mutex;
  78. u32_t level, size, rate, gain;
  79. void *buffer;
  80. bool running;
  81. } visu_export;
  82. void output_visu_export(void *frames, frames_t out_frames, u32_t rate, bool silence, u32_t gain);
  83. void output_visu_init(log_level level);
  84. void output_visu_close(void);
  85. // optional, please chain if used
  86. bool (*slimp_handler)(u8_t *data, int len);
  87. void (*slimp_loop)(void);
  88. void (*server_notify)(in_addr_t ip, u16_t hport, u16_t cport);
  89. #endif // EMBEDDED_H