common.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // SPDX-License-Identifier: Apache-2.0
  2. // Copyright 2015-2021 Espressif Systems (Shanghai) PTE LTD
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. /** prevent recursive inclusion **/
  15. #ifndef __COMMON_H
  16. #define __COMMON_H
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. /** Includes **/
  21. #include "stdint.h"
  22. #include "stdio.h"
  23. #include "os_wrapper.h"
  24. #include "esp_err.h"
  25. /** Constants/Macros **/
  26. #define MAX_NETWORK_INTERFACES 2
  27. #define STA_INTERFACE "ESP_STATION"
  28. #define SOFTAP_INTERFACE "ESP_SOFTAP"
  29. #define UNUSED_VAR(x) (void)(x);
  30. #define MAX_SPI_BUFFER_SIZE 1600
  31. /* TODO: SDIO buffers to be set same at both, ESP and host side */
  32. #define MAX_SDIO_BUFFER_SIZE 1536
  33. #define MAX_SPI_HD_BUFFER_SIZE 1600
  34. #define MAX_UART_BUFFER_SIZE 1600
  35. #define MAX_SUPPORTED_SDIO_CLOCK_MHZ 40
  36. #define IP_ADDR_LEN 4
  37. #define MAC_LEN 6
  38. #define MIN_MAC_STRING_LEN 17
  39. #ifndef BIT
  40. #define BIT(x) (1UL << (x))
  41. #endif
  42. #define FREQ_IN_MHZ(x) ((x)*1000000)
  43. #define MHZ_TO_HZ(x) (1000000*(x))
  44. #define SUCCESS 0
  45. #define FAILURE -1
  46. typedef enum stm_ret_s {
  47. STM_OK = 0,
  48. STM_FAIL = -1,
  49. STM_FAIL_TIMEOUT = -2,
  50. STM_FAIL_INVALID_ARG = -3,
  51. STM_FAIL_NO_MEMORY = -4,
  52. STM_FAIL_NOT_FOUND = -5,
  53. STM_FAIL_NOT_FINISHED = -6,
  54. STM_FAIL_ALIGNMENT = -7
  55. }stm_ret_t;
  56. typedef enum {
  57. TRANSPORT_INACTIVE,
  58. TRANSPORT_RX_ACTIVE,
  59. TRANSPORT_TX_ACTIVE,
  60. } transport_drv_events_e;
  61. /** Exported Structures **/
  62. /* interface header */
  63. typedef struct {
  64. union {
  65. void *priv_buffer_handle;
  66. };
  67. uint8_t if_type;
  68. uint8_t if_num;
  69. uint8_t *payload;
  70. uint8_t flag;
  71. uint16_t payload_len;
  72. uint16_t seq_num;
  73. /* no need of memcpy at different layers */
  74. uint8_t payload_zcopy;
  75. void (*free_buf_handle)(void *buf_handle);
  76. } interface_buffer_handle_t;
  77. /** Exported variables **/
  78. /** Exported Functions **/
  79. uint16_t hton_short (uint16_t x);
  80. uint32_t hton_long (uint32_t x);
  81. #define ntoh_long hton_long
  82. #define ntoh_short hton_short
  83. typedef unsigned char u_char;
  84. typedef unsigned long u_long;
  85. #ifndef min
  86. int min(int x, int y);
  87. #endif
  88. #if 0
  89. void hard_delay(int x);
  90. int get_num_from_string(int *val, char *arg);
  91. #endif
  92. #define H_FREE_PTR_WITH_FUNC(FreeFunc, FreePtr) do { \
  93. if (FreeFunc && FreePtr) { \
  94. FreeFunc(FreePtr); \
  95. FreePtr = NULL; \
  96. } \
  97. } while (0);
  98. #ifdef __cplusplus
  99. }
  100. #endif
  101. #endif