spi_wifi_rw009.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. */
  24. #ifndef SPI_WIFI_H_INCLUDED
  25. #define SPI_WIFI_H_INCLUDED
  26. #include <stdint.h>
  27. // little-endian
  28. struct cmd_request
  29. {
  30. uint32_t flag;
  31. uint32_t M2S_len; // master to slave data len.
  32. uint32_t magic1;
  33. uint32_t magic2;
  34. };
  35. #define CMD_MAGIC1 (0x67452301)
  36. #define CMD_MAGIC2 (0xEFCDAB89)
  37. #define CMD_FLAG_MRDY (0x01)
  38. // little-endian
  39. struct response
  40. {
  41. uint32_t flag;
  42. uint32_t S2M_len; // slave to master data len.
  43. uint32_t magic1;
  44. uint32_t magic2;
  45. };
  46. #define RESP_FLAG_SRDY (0x01)
  47. #define RESP_MAGIC1 (0x98BADCFE)
  48. #define RESP_MAGIC2 (0x10325476)
  49. /* spi slave configure. */
  50. #define MAX_DATA_LEN 1520
  51. #define SPI_TX_POOL_SIZE 2
  52. // align check
  53. #if (MAX_DATA_LEN & 0x03) != 0
  54. #error MAX_DATA_LEN must ALIGN to 4byte!
  55. #endif
  56. typedef enum
  57. {
  58. data_type_eth_data = 0,
  59. data_type_cmd,
  60. data_type_resp,
  61. }
  62. app_data_type_typedef;
  63. struct spi_data_packet
  64. {
  65. uint32_t data_len;
  66. uint32_t data_type;
  67. char buffer[MAX_DATA_LEN];
  68. };
  69. struct spi_wifi_cmd
  70. {
  71. uint32_t cmd;
  72. char buffer[128];
  73. };
  74. struct spi_wifi_resp
  75. {
  76. uint32_t cmd;
  77. char buffer[128];
  78. };
  79. #define SPI_WIFI_CMD_INIT 128 //wait
  80. #define SPI_WIFI_CMD_SCAN 129 //no wait
  81. #define SPI_WIFI_CMD_JOIN 130 //no wait
  82. /* porting */
  83. extern void spi_wifi_hw_init(void);
  84. extern void spi_wifi_int_cmd(rt_bool_t cmd);
  85. extern rt_bool_t spi_wifi_is_busy(void);
  86. /* tools */
  87. #define node_entry(node, type, member) \
  88. ((type *)((char *)(node) - (unsigned long)(&((type *)0)->member)))
  89. #define member_offset(type, member) \
  90. ((unsigned long)(&((type *)0)->member))
  91. #define SSID_NAME_LENGTH_MAX (32)
  92. #define PASSWORD_LENGTH_MAX (32)
  93. struct cmd_join
  94. {
  95. char ssid[SSID_NAME_LENGTH_MAX];
  96. char passwd[PASSWORD_LENGTH_MAX];
  97. uint8_t bssid[8]; // 6byte + 2byte PAD.
  98. uint32_t channel;
  99. uint32_t security;
  100. };
  101. #endif // SPI_WIFI_H_INCLUDED