spi_wifi_rw009.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. * File : spi_wifi_rw009.h
  3. * This file is part of RT-Thread RTOS
  4. * Copyright by Shanghai Real-Thread Electronic Technology Co.,Ltd
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2014-07-31 aozima the first version
  23. * 2014-09-18 aozima update command & response.
  24. */
  25. #ifndef SPI_WIFI_H_INCLUDED
  26. #define SPI_WIFI_H_INCLUDED
  27. #include <stdint.h>
  28. // little-endian
  29. struct spi_cmd_request
  30. {
  31. uint32_t flag;
  32. uint32_t M2S_len; // master to slave data len.
  33. uint32_t magic1;
  34. uint32_t magic2;
  35. };
  36. #define CMD_MAGIC1 (0x67452301)
  37. #define CMD_MAGIC2 (0xEFCDAB89)
  38. #define CMD_FLAG_MRDY (0x01)
  39. // little-endian
  40. struct spi_response
  41. {
  42. uint32_t flag;
  43. uint32_t S2M_len; // slave to master data len.
  44. uint32_t magic1;
  45. uint32_t magic2;
  46. };
  47. #define RESP_FLAG_SRDY (0x01)
  48. #define RESP_MAGIC1 (0x98BADCFE)
  49. #define RESP_MAGIC2 (0x10325476)
  50. /* spi slave configure. */
  51. #define SPI_MAX_DATA_LEN 1520
  52. #define SPI_TX_POOL_SIZE 2
  53. #define SPI_RX_POOL_SIZE 2
  54. typedef enum
  55. {
  56. data_type_eth_data = 0,
  57. data_type_cmd,
  58. data_type_resp,
  59. data_type_status,
  60. }
  61. app_data_type_typedef;
  62. struct spi_data_packet
  63. {
  64. uint32_t data_len;
  65. uint32_t data_type;
  66. char buffer[SPI_MAX_DATA_LEN];
  67. };
  68. /********************************* RW009 **************************************/
  69. /* option */
  70. #define RW009_CMD_TIMEOUT (RT_TICK_PER_SECOND*3)
  71. #define SSID_NAME_LENGTH_MAX (32)
  72. #define PASSWORD_LENGTH_MAX (64)
  73. typedef struct _rw009_ap_info
  74. {
  75. char ssid[SSID_NAME_LENGTH_MAX];
  76. uint8_t bssid[8]; // 6byte + 2byte PAD.
  77. int rssi; /* Receive Signal Strength Indication in dBm. */
  78. uint32_t max_data_rate; /* Maximum data rate in kilobits/s */
  79. uint32_t security; /* Security type */
  80. uint32_t channel; /* Radio channel that the AP beacon was received on */
  81. } rw009_ap_info;
  82. typedef struct _rw009_cmd_init
  83. {
  84. uint32_t mode;
  85. } rw009_cmd_init;
  86. typedef struct _rw009_resp_init
  87. {
  88. uint8_t mac[8]; // 6byte + 2byte PAD.
  89. uint8_t sn[24]; // serial.
  90. char version[16]; // firmware version.
  91. } rw009_resp_init;
  92. typedef struct _rw009_cmd_easy_join
  93. {
  94. char ssid[SSID_NAME_LENGTH_MAX];
  95. char passwd[PASSWORD_LENGTH_MAX];
  96. } rw009_cmd_easy_join;
  97. typedef struct _rw009_cmd_join
  98. {
  99. uint8_t bssid[8]; // 6byte + 2byte PAD.
  100. char passwd[PASSWORD_LENGTH_MAX];
  101. } rw009_cmd_join;
  102. typedef struct _rw009_cmd_rssi
  103. {
  104. uint8_t bssid[8]; // 6byte + 2byte PAD.
  105. } rw009_cmd_rssi;
  106. typedef struct _rw009_resp_join
  107. {
  108. rw009_ap_info ap_info;
  109. } rw009_resp_join;
  110. struct rw009_cmd
  111. {
  112. uint32_t cmd;
  113. uint32_t len;
  114. /** command body */
  115. union
  116. {
  117. rw009_cmd_init init;
  118. rw009_cmd_easy_join easy_join;
  119. rw009_cmd_join join;
  120. rw009_cmd_rssi rssi;
  121. } params;
  122. };
  123. struct rw009_resp
  124. {
  125. uint32_t cmd;
  126. uint32_t len;
  127. int32_t result; // result for CMD.
  128. /** resp Body */
  129. union
  130. {
  131. rw009_resp_init init;
  132. rw009_ap_info ap_info;
  133. } resp;
  134. };
  135. #define RW009_CMD_INIT 128
  136. #define RW009_CMD_SCAN 129
  137. #define RW009_CMD_JOIN 130
  138. #define RW009_CMD_EASY_JOIN 131
  139. #define RW009_CMD_RSSI 132
  140. /* porting */
  141. extern void spi_wifi_hw_init(void);
  142. extern void spi_wifi_int_cmd(rt_bool_t cmd);
  143. extern rt_bool_t spi_wifi_is_busy(void);
  144. /* export API. */
  145. extern int32_t rw009_rssi(void);
  146. extern rt_err_t rw009_join(const char * SSID, const char * passwd);
  147. #endif // SPI_WIFI_H_INCLUDED