modwlan.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * This file is part of the MicroPython project, http://micropython.org/
  3. *
  4. * The MIT License (MIT)
  5. *
  6. * Copyright (c) 2015 Daniel Campora
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. */
  26. #ifndef MICROPY_INCLUDED_CC3200_MODS_MODWLAN_H
  27. #define MICROPY_INCLUDED_CC3200_MODS_MODWLAN_H
  28. /******************************************************************************
  29. DEFINE CONSTANTS
  30. ******************************************************************************/
  31. #define SIMPLELINK_SPAWN_TASK_PRIORITY 3
  32. #define SIMPLELINK_TASK_STACK_SIZE 2048
  33. #define SL_STOP_TIMEOUT 35
  34. #define SL_STOP_TIMEOUT_LONG 575
  35. #define MODWLAN_WIFI_EVENT_ANY 0x01
  36. #define MODWLAN_SSID_LEN_MAX 32
  37. /******************************************************************************
  38. DEFINE TYPES
  39. ******************************************************************************/
  40. typedef enum {
  41. MODWLAN_OK = 0,
  42. MODWLAN_ERROR_INVALID_PARAMS = -1,
  43. MODWLAN_ERROR_TIMEOUT = -2,
  44. MODWLAN_ERROR_UNKNOWN = -3,
  45. } modwlan_Status_t;
  46. typedef struct _wlan_obj_t {
  47. mp_obj_base_t base;
  48. mp_obj_t irq_obj;
  49. uint32_t status;
  50. uint32_t ip;
  51. int8_t mode;
  52. uint8_t auth;
  53. uint8_t channel;
  54. uint8_t antenna;
  55. // my own ssid, key and mac
  56. uint8_t ssid[(MODWLAN_SSID_LEN_MAX + 1)];
  57. uint8_t key[65];
  58. uint8_t mac[SL_MAC_ADDR_LEN];
  59. // the sssid (or name) and mac of the other device
  60. uint8_t ssid_o[33];
  61. uint8_t bssid[6];
  62. uint8_t irq_flags;
  63. bool irq_enabled;
  64. #if (MICROPY_PORT_HAS_TELNET || MICROPY_PORT_HAS_FTP)
  65. bool servers_enabled;
  66. #endif
  67. } wlan_obj_t;
  68. /******************************************************************************
  69. DECLARE PUBLIC DATA
  70. ******************************************************************************/
  71. extern _SlLockObj_t wlan_LockObj;
  72. /******************************************************************************
  73. DECLARE PUBLIC FUNCTIONS
  74. ******************************************************************************/
  75. extern void wlan_pre_init (void);
  76. extern void wlan_sl_init (int8_t mode, const char *ssid, uint8_t ssid_len, uint8_t auth, const char *key, uint8_t key_len,
  77. uint8_t channel, uint8_t antenna, bool add_mac);
  78. extern void wlan_first_start (void);
  79. extern void wlan_update(void);
  80. extern void wlan_stop (uint32_t timeout);
  81. extern void wlan_get_mac (uint8_t *macAddress);
  82. extern void wlan_get_ip (uint32_t *ip);
  83. extern bool wlan_is_connected (void);
  84. extern void wlan_set_current_time (uint32_t seconds_since_2000);
  85. extern void wlan_off_on (void);
  86. #endif // MICROPY_INCLUDED_CC3200_MODS_MODWLAN_H