This repository was archived by the owner on Mar 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathSFE_CC3000_Callbacks.cpp
169 lines (152 loc) · 3.61 KB
/
SFE_CC3000_Callbacks.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/**
* @file SFE_CC3000_Callbacks.cpp
* @brief Callback functions for the CC3000 library
* @author Shawn Hymel (SparkFun Electronics)
*
* @copyright This code is public domain but you buy me a beer if you use
* this and we meet someday (Beerware license).
*
* These functions implement the required callbacks for the provided TI CC3000
* library. The Arduino library provides the functions' addresses so the TI
* library can call them.
*/
#include <Arduino.h>
#include "common.h"
#include "SFE_CC3000_Callbacks.h"
#include "SFE_CC3000_SPI.h"
#include "utility/evnt_handler.h"
#include "utility/hci.h"
/**
* @brief Asynchronous callback from CC3000 library - handles events
*
* @param lEventType Event type
* @param data Pointer to the data
* @param length length of data
*/
void cc3000AsyncCallback(long lEventType, char * data, unsigned char length)
{
if (lEventType == HCI_EVNT_WLAN_ASYNC_SIMPLE_CONFIG_DONE)
{
ulSmartConfigFinished = 1;
ucStopSmartConfig = 1;
}
if (lEventType == HCI_EVNT_WLAN_UNSOL_CONNECT)
{
ulCC3000Connected = 1;
}
if (lEventType == HCI_EVNT_WLAN_UNSOL_DISCONNECT)
{
ulCC3000Connected = 0;
ulCC3000DHCP = 0;
ulCC3000DHCP_configured = 0;
}
if (lEventType == HCI_EVNT_WLAN_UNSOL_DHCP)
{
// Notes:
// 1) IP config parameters are received swapped
// 2) IP config parameters are valid only if status is OK, i.e. ulCC3000DHCP becomes 1
// only if status is OK, the flag is set to 1 and the addresses are valid
if ( *(data + NETAPP_IPCONFIG_MAC_OFFSET) == 0)
{
ulCC3000DHCP = 1;
}
else
{
ulCC3000DHCP = 0;
}
}
if (lEventType == HCI_EVENT_CC3000_CAN_SHUT_DOWN)
{
OkToDoShutDown = 1;
}
if (lEventType == HCI_EVNT_WLAN_ASYNC_PING_REPORT)
{
memcpy(&g_ping_report, data, length);
}
if(lEventType == HCI_EVNT_CONNECT)
{
g_socket_connected = true;
}
if (lEventType == HCI_EVNT_BSD_TCP_CLOSE_WAIT)
{
g_socket_connected = false;
}
}
/**
* @brief This function provides a pointer to the firmware patch
*
* Since there is no patch in the host, it returns NULL.
*
* @param Length pointer to the length
*
* @return a pointer to the firmware patch
*/
char *sendFirmwarePatch(unsigned long *Length)
{
*Length = 0;
return NULL;
}
/**
* @brief This function provides a pointer to the driver patch
*
* Since there is no patch in the host, it returns NULL.
*
* @param Length pointer to the length
*
* @return a pointer to the driver patch
*/
char *sendDriverPatch(unsigned long *Length)
{
*Length = 0;
return NULL;
}
/**
* @brief This function provides a pointer to the bootloader patch
*
* Since there is no patch in the host, it returns NULL.
*
* @param Length pointer to the length
*
* @return a pointer to the bootloader patch
*/
char *sendBootLoaderPatch(unsigned long *Length)
{
*Length = 0;
return NULL;
}
/**
* @brief Reads the state of the CC3000 interrupt pin
*
* @return the state of the CC3000 interrupt pin
*/
long readWlanInterruptPin()
{
return digitalRead(g_int_pin);
}
/**
* @brief Enables CC3000 interrupt pin interrupts
*/
void enableWlanInterrupt()
{
attachInterrupt(g_int_num, cc3000_ISR, FALLING);
}
/**
* @brief Disables CC3000 interrupt pin interrupts
*/
void disableWlanInterrupt()
{
detachInterrupt(g_int_num);
}
/**
* @brief The TI library calls this to enable or disable the CC3000 EN pin
*
* @param val The value to write to the EN pin (high or low)
*/
void writeWlanPin(unsigned char val)
{
if (val) {
digitalWrite(g_en_pin, HIGH);
} else {
digitalWrite(g_en_pin, LOW);
}
}