spi_wifi_rw009.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. #define SPI_RX_POOL_SIZE 2
  53. // align check
  54. #if (MAX_DATA_LEN & 0x03) != 0
  55. #error MAX_DATA_LEN must ALIGN to 4byte!
  56. #endif
  57. typedef enum
  58. {
  59. data_type_eth_data = 0,
  60. data_type_cmd,
  61. data_type_resp,
  62. }
  63. app_data_type_typedef;
  64. struct spi_data_packet
  65. {
  66. uint32_t data_len;
  67. uint32_t data_type;
  68. char buffer[MAX_DATA_LEN];
  69. };
  70. /* tools */
  71. #define node_entry(node, type, member) \
  72. ((type *)((char *)(node) - (unsigned long)(&((type *)0)->member)))
  73. #define member_offset(type, member) \
  74. ((unsigned long)(&((type *)0)->member))
  75. #define MAX_SPI_PACKET_SIZE (member_offset(struct spi_data_packet, buffer) + MAX_DATA_LEN)
  76. /********************************* RW009 **************************************/
  77. struct spi_wifi_cmd
  78. {
  79. uint32_t cmd;
  80. char buffer[128];
  81. };
  82. struct spi_wifi_resp
  83. {
  84. uint32_t cmd;
  85. char buffer[128];
  86. };
  87. #define SPI_WIFI_CMD_INIT 128 //wait
  88. #define SPI_WIFI_CMD_SCAN 129 //no wait
  89. #define SPI_WIFI_CMD_JOIN 130 //no wait
  90. /* porting */
  91. extern void spi_wifi_hw_init(void);
  92. extern void spi_wifi_int_cmd(rt_bool_t cmd);
  93. extern rt_bool_t spi_wifi_is_busy(void);
  94. #define SSID_NAME_LENGTH_MAX (32)
  95. #define PASSWORD_LENGTH_MAX (32)
  96. struct cmd_join
  97. {
  98. char ssid[SSID_NAME_LENGTH_MAX];
  99. char passwd[PASSWORD_LENGTH_MAX];
  100. uint8_t bssid[8]; // 6byte + 2byte PAD.
  101. uint32_t channel;
  102. uint32_t security;
  103. };
  104. #endif // SPI_WIFI_H_INCLUDED