version_2.0
Dependents: cc3000_ping_demo_try_2
Fork of cc3000_hostdriver_mbedsocket by
cc3000_netapp.cpp@47:e9d12b82813e, 2014-06-25 (annotated)
- Committer:
- erezi
- Date:
- Wed Jun 25 06:08:39 2014 +0000
- Revision:
- 47:e9d12b82813e
- Parent:
- 45:50ab13d8f2dc
version_2.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Kojto | 20:30b6ed7bf8fd | 1 | /***************************************************************************** |
Kojto | 20:30b6ed7bf8fd | 2 | * |
Kojto | 20:30b6ed7bf8fd | 3 | * C++ interface/implementation created by Martin Kojtal (0xc0170). Thanks to |
Kojto | 20:30b6ed7bf8fd | 4 | * Jim Carver and Frank Vannieuwkerke for their inital cc3000 mbed port and |
Kojto | 20:30b6ed7bf8fd | 5 | * provided help. |
Kojto | 20:30b6ed7bf8fd | 6 | * |
Kojto | 20:30b6ed7bf8fd | 7 | * This version of "host driver" uses CC3000 Host Driver Implementation. Thus |
Kojto | 20:30b6ed7bf8fd | 8 | * read the following copyright: |
Kojto | 20:30b6ed7bf8fd | 9 | * |
Kojto | 20:30b6ed7bf8fd | 10 | * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ |
Kojto | 20:30b6ed7bf8fd | 11 | * |
Kojto | 20:30b6ed7bf8fd | 12 | * Redistribution and use in source and binary forms, with or without |
Kojto | 20:30b6ed7bf8fd | 13 | * modification, are permitted provided that the following conditions |
Kojto | 20:30b6ed7bf8fd | 14 | * are met: |
Kojto | 20:30b6ed7bf8fd | 15 | * |
Kojto | 20:30b6ed7bf8fd | 16 | * Redistributions of source code must retain the above copyright |
Kojto | 20:30b6ed7bf8fd | 17 | * notice, this list of conditions and the following disclaimer. |
Kojto | 20:30b6ed7bf8fd | 18 | * |
Kojto | 20:30b6ed7bf8fd | 19 | * Redistributions in binary form must reproduce the above copyright |
Kojto | 20:30b6ed7bf8fd | 20 | * notice, this list of conditions and the following disclaimer in the |
Kojto | 20:30b6ed7bf8fd | 21 | * documentation and/or other materials provided with the |
Kojto | 20:30b6ed7bf8fd | 22 | * distribution. |
Kojto | 20:30b6ed7bf8fd | 23 | * |
Kojto | 20:30b6ed7bf8fd | 24 | * Neither the name of Texas Instruments Incorporated nor the names of |
Kojto | 20:30b6ed7bf8fd | 25 | * its contributors may be used to endorse or promote products derived |
Kojto | 20:30b6ed7bf8fd | 26 | * from this software without specific prior written permission. |
Kojto | 20:30b6ed7bf8fd | 27 | * |
Kojto | 20:30b6ed7bf8fd | 28 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
Kojto | 20:30b6ed7bf8fd | 29 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
Kojto | 20:30b6ed7bf8fd | 30 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
Kojto | 20:30b6ed7bf8fd | 31 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
Kojto | 20:30b6ed7bf8fd | 32 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
Kojto | 20:30b6ed7bf8fd | 33 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
Kojto | 20:30b6ed7bf8fd | 34 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
Kojto | 20:30b6ed7bf8fd | 35 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
Kojto | 20:30b6ed7bf8fd | 36 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
Kojto | 20:30b6ed7bf8fd | 37 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
Kojto | 20:30b6ed7bf8fd | 38 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Kojto | 20:30b6ed7bf8fd | 39 | * |
Kojto | 20:30b6ed7bf8fd | 40 | *****************************************************************************/ |
Kojto | 20:30b6ed7bf8fd | 41 | #include "cc3000.h" |
Kojto | 20:30b6ed7bf8fd | 42 | #include "cc3000_netapp.h" |
Kojto | 20:30b6ed7bf8fd | 43 | |
Kojto | 20:30b6ed7bf8fd | 44 | namespace mbed_cc3000 { |
Kojto | 20:30b6ed7bf8fd | 45 | |
Kojto | 20:30b6ed7bf8fd | 46 | cc3000_netapp::cc3000_netapp(cc3000_simple_link &simple_link, cc3000_nvmem &nvmem, cc3000_hci &hci , cc3000_event &event) : |
Kojto | 20:30b6ed7bf8fd | 47 | _simple_link(simple_link), _nvmem(nvmem), _hci(hci), _event(event) { |
Kojto | 20:30b6ed7bf8fd | 48 | |
Kojto | 20:30b6ed7bf8fd | 49 | } |
Kojto | 20:30b6ed7bf8fd | 50 | |
Kojto | 20:30b6ed7bf8fd | 51 | cc3000_netapp::~cc3000_netapp() { |
Kojto | 20:30b6ed7bf8fd | 52 | |
Kojto | 20:30b6ed7bf8fd | 53 | } |
Kojto | 20:30b6ed7bf8fd | 54 | |
Kojto | 20:30b6ed7bf8fd | 55 | int32_t cc3000_netapp::config_mac_adrress(uint8_t * mac) { |
Kojto | 20:30b6ed7bf8fd | 56 | return _nvmem.set_mac_address(mac); |
Kojto | 20:30b6ed7bf8fd | 57 | } |
Kojto | 20:30b6ed7bf8fd | 58 | |
Kojto | 20:30b6ed7bf8fd | 59 | int32_t cc3000_netapp::dhcp(uint32_t *ip, uint32_t *subnet_mask,uint32_t *default_gateway, uint32_t *dns_server) { |
Kojto | 20:30b6ed7bf8fd | 60 | int8_t scRet; |
Kojto | 20:30b6ed7bf8fd | 61 | uint8_t *ptr; |
Kojto | 20:30b6ed7bf8fd | 62 | uint8_t *args; |
Kojto | 20:30b6ed7bf8fd | 63 | |
Kojto | 20:30b6ed7bf8fd | 64 | scRet = EFAIL; |
Kojto | 20:30b6ed7bf8fd | 65 | ptr = _simple_link.get_transmit_buffer(); |
Kojto | 20:30b6ed7bf8fd | 66 | args = (ptr + HEADERS_SIZE_CMD); |
Kojto | 20:30b6ed7bf8fd | 67 | |
Kojto | 20:30b6ed7bf8fd | 68 | // Fill in temporary command buffer |
Kojto | 20:30b6ed7bf8fd | 69 | ARRAY_TO_STREAM(args,ip,4); |
Kojto | 20:30b6ed7bf8fd | 70 | ARRAY_TO_STREAM(args,subnet_mask,4); |
Kojto | 20:30b6ed7bf8fd | 71 | ARRAY_TO_STREAM(args,default_gateway,4); |
Kojto | 20:30b6ed7bf8fd | 72 | args = UINT32_TO_STREAM(args, 0); |
Kojto | 20:30b6ed7bf8fd | 73 | ARRAY_TO_STREAM(args,dns_server,4); |
Kojto | 20:30b6ed7bf8fd | 74 | |
Kojto | 20:30b6ed7bf8fd | 75 | // Initiate a HCI command |
Kojto | 20:30b6ed7bf8fd | 76 | _hci.command_send(HCI_NETAPP_DHCP, ptr, NETAPP_DHCP_PARAMS_LEN); |
Kojto | 20:30b6ed7bf8fd | 77 | |
Kojto | 20:30b6ed7bf8fd | 78 | // Wait for command complete event |
Kojto | 20:30b6ed7bf8fd | 79 | _event.simplelink_wait_event(HCI_NETAPP_DHCP, &scRet); |
Kojto | 20:30b6ed7bf8fd | 80 | |
Kojto | 45:50ab13d8f2dc | 81 | return scRet; |
Kojto | 20:30b6ed7bf8fd | 82 | } |
Kojto | 20:30b6ed7bf8fd | 83 | |
Kojto | 20:30b6ed7bf8fd | 84 | #ifndef CC3000_TINY_DRIVER |
Kojto | 20:30b6ed7bf8fd | 85 | void cc3000_netapp::ipconfig( tNetappIpconfigRetArgs * ipconfig ) { |
Kojto | 20:30b6ed7bf8fd | 86 | uint8_t *ptr; |
Kojto | 20:30b6ed7bf8fd | 87 | |
Kojto | 20:30b6ed7bf8fd | 88 | ptr = _simple_link.get_transmit_buffer(); |
Kojto | 20:30b6ed7bf8fd | 89 | |
Kojto | 20:30b6ed7bf8fd | 90 | // Initiate a HCI command |
Kojto | 20:30b6ed7bf8fd | 91 | _hci.command_send(HCI_NETAPP_IPCONFIG, ptr, 0); |
Kojto | 20:30b6ed7bf8fd | 92 | |
Kojto | 20:30b6ed7bf8fd | 93 | // Wait for command complete event |
Kojto | 20:30b6ed7bf8fd | 94 | _event.simplelink_wait_event(HCI_NETAPP_IPCONFIG, ipconfig ); |
Kojto | 20:30b6ed7bf8fd | 95 | } |
Kojto | 20:30b6ed7bf8fd | 96 | |
Kojto | 20:30b6ed7bf8fd | 97 | |
Kojto | 20:30b6ed7bf8fd | 98 | int32_t cc3000_netapp::timeout_values(uint32_t *dhcp, uint32_t *arp,uint32_t *keep_alive, uint32_t *inactivity) { |
Kojto | 20:30b6ed7bf8fd | 99 | int8_t scRet; |
Kojto | 20:30b6ed7bf8fd | 100 | uint8_t *ptr; |
Kojto | 20:30b6ed7bf8fd | 101 | uint8_t *args; |
Kojto | 20:30b6ed7bf8fd | 102 | |
Kojto | 20:30b6ed7bf8fd | 103 | scRet = EFAIL; |
Kojto | 20:30b6ed7bf8fd | 104 | ptr = _simple_link.get_transmit_buffer(); |
Kojto | 20:30b6ed7bf8fd | 105 | args = (ptr + HEADERS_SIZE_CMD); |
Kojto | 20:30b6ed7bf8fd | 106 | |
Kojto | 20:30b6ed7bf8fd | 107 | // Set minimal values of timers |
Kojto | 20:30b6ed7bf8fd | 108 | MIN_TIMER_SET(*dhcp) |
Kojto | 20:30b6ed7bf8fd | 109 | MIN_TIMER_SET(*arp) |
Kojto | 20:30b6ed7bf8fd | 110 | MIN_TIMER_SET(*keep_alive) |
Kojto | 20:30b6ed7bf8fd | 111 | MIN_TIMER_SET(*inactivity) |
Kojto | 20:30b6ed7bf8fd | 112 | |
Kojto | 20:30b6ed7bf8fd | 113 | // Fill in temporary command buffer |
Kojto | 20:30b6ed7bf8fd | 114 | args = UINT32_TO_STREAM(args, *dhcp); |
Kojto | 20:30b6ed7bf8fd | 115 | args = UINT32_TO_STREAM(args, *arp); |
Kojto | 20:30b6ed7bf8fd | 116 | args = UINT32_TO_STREAM(args, *keep_alive); |
Kojto | 20:30b6ed7bf8fd | 117 | args = UINT32_TO_STREAM(args, *inactivity); |
Kojto | 20:30b6ed7bf8fd | 118 | |
Kojto | 20:30b6ed7bf8fd | 119 | // Initiate a HCI command |
Kojto | 20:30b6ed7bf8fd | 120 | _hci.command_send(HCI_NETAPP_SET_TIMERS, ptr, NETAPP_SET_TIMER_PARAMS_LEN); |
Kojto | 20:30b6ed7bf8fd | 121 | |
Kojto | 20:30b6ed7bf8fd | 122 | // Wait for command complete event |
Kojto | 20:30b6ed7bf8fd | 123 | _event.simplelink_wait_event(HCI_NETAPP_SET_TIMERS, &scRet); |
Kojto | 20:30b6ed7bf8fd | 124 | |
Kojto | 45:50ab13d8f2dc | 125 | return scRet; |
Kojto | 20:30b6ed7bf8fd | 126 | } |
Kojto | 20:30b6ed7bf8fd | 127 | |
Kojto | 20:30b6ed7bf8fd | 128 | int32_t cc3000_netapp::ping_send(uint32_t *ip, uint32_t ping_attempts, uint32_t ping_size, uint32_t ping_timeout) { |
Kojto | 20:30b6ed7bf8fd | 129 | int8_t scRet; |
Kojto | 20:30b6ed7bf8fd | 130 | uint8_t *ptr, *args; |
Kojto | 20:30b6ed7bf8fd | 131 | |
Kojto | 20:30b6ed7bf8fd | 132 | scRet = EFAIL; |
Kojto | 20:30b6ed7bf8fd | 133 | ptr = _simple_link.get_transmit_buffer(); |
Kojto | 20:30b6ed7bf8fd | 134 | args = (ptr + HEADERS_SIZE_CMD); |
Kojto | 20:30b6ed7bf8fd | 135 | |
Kojto | 20:30b6ed7bf8fd | 136 | // Fill in temporary command buffer |
Kojto | 20:30b6ed7bf8fd | 137 | args = UINT32_TO_STREAM(args, *ip); |
Kojto | 20:30b6ed7bf8fd | 138 | args = UINT32_TO_STREAM(args, ping_attempts); |
Kojto | 20:30b6ed7bf8fd | 139 | args = UINT32_TO_STREAM(args, ping_size); |
Kojto | 20:30b6ed7bf8fd | 140 | args = UINT32_TO_STREAM(args, ping_timeout); |
Kojto | 20:30b6ed7bf8fd | 141 | |
Kojto | 20:30b6ed7bf8fd | 142 | // Initiate a HCI command |
Kojto | 20:30b6ed7bf8fd | 143 | _hci.command_send(HCI_NETAPP_PING_SEND, ptr, NETAPP_PING_SEND_PARAMS_LEN); |
Kojto | 20:30b6ed7bf8fd | 144 | |
Kojto | 20:30b6ed7bf8fd | 145 | // Wait for command complete event |
Kojto | 20:30b6ed7bf8fd | 146 | _event.simplelink_wait_event(HCI_NETAPP_PING_SEND, &scRet); |
Kojto | 20:30b6ed7bf8fd | 147 | |
Kojto | 45:50ab13d8f2dc | 148 | return scRet; |
Kojto | 20:30b6ed7bf8fd | 149 | } |
Kojto | 20:30b6ed7bf8fd | 150 | |
Kojto | 20:30b6ed7bf8fd | 151 | void cc3000_netapp::ping_report() { |
Kojto | 20:30b6ed7bf8fd | 152 | uint8_t *ptr; |
Kojto | 20:30b6ed7bf8fd | 153 | int8_t scRet; |
Kojto | 20:30b6ed7bf8fd | 154 | ptr = _simple_link.get_transmit_buffer(); |
Kojto | 20:30b6ed7bf8fd | 155 | |
Kojto | 20:30b6ed7bf8fd | 156 | |
Kojto | 20:30b6ed7bf8fd | 157 | scRet = EFAIL; |
Kojto | 20:30b6ed7bf8fd | 158 | |
Kojto | 20:30b6ed7bf8fd | 159 | // Initiate a HCI command |
Kojto | 20:30b6ed7bf8fd | 160 | _hci.command_send(HCI_NETAPP_PING_REPORT, ptr, 0); |
Kojto | 20:30b6ed7bf8fd | 161 | |
Kojto | 20:30b6ed7bf8fd | 162 | // Wait for command complete event |
Kojto | 20:30b6ed7bf8fd | 163 | _event.simplelink_wait_event(HCI_NETAPP_PING_REPORT, &scRet); |
Kojto | 20:30b6ed7bf8fd | 164 | } |
Kojto | 20:30b6ed7bf8fd | 165 | |
Kojto | 20:30b6ed7bf8fd | 166 | int32_t cc3000_netapp::ping_stop() { |
Kojto | 20:30b6ed7bf8fd | 167 | int8_t scRet; |
Kojto | 20:30b6ed7bf8fd | 168 | uint8_t *ptr; |
Kojto | 20:30b6ed7bf8fd | 169 | |
Kojto | 20:30b6ed7bf8fd | 170 | scRet = EFAIL; |
Kojto | 20:30b6ed7bf8fd | 171 | ptr = _simple_link.get_transmit_buffer(); |
Kojto | 20:30b6ed7bf8fd | 172 | |
Kojto | 20:30b6ed7bf8fd | 173 | // Initiate a HCI command |
Kojto | 20:30b6ed7bf8fd | 174 | _hci.command_send(HCI_NETAPP_PING_STOP, ptr, 0); |
Kojto | 20:30b6ed7bf8fd | 175 | |
Kojto | 20:30b6ed7bf8fd | 176 | // Wait for command complete event |
Kojto | 20:30b6ed7bf8fd | 177 | _event.simplelink_wait_event(HCI_NETAPP_PING_STOP, &scRet); |
Kojto | 20:30b6ed7bf8fd | 178 | |
Kojto | 45:50ab13d8f2dc | 179 | return scRet; |
Kojto | 20:30b6ed7bf8fd | 180 | } |
Kojto | 20:30b6ed7bf8fd | 181 | |
Kojto | 20:30b6ed7bf8fd | 182 | int32_t cc3000_netapp::arp_flush() { |
Kojto | 20:30b6ed7bf8fd | 183 | int8_t scRet; |
Kojto | 20:30b6ed7bf8fd | 184 | uint8_t *ptr; |
Kojto | 20:30b6ed7bf8fd | 185 | |
Kojto | 20:30b6ed7bf8fd | 186 | scRet = EFAIL; |
Kojto | 20:30b6ed7bf8fd | 187 | ptr = _simple_link.get_transmit_buffer(); |
Kojto | 20:30b6ed7bf8fd | 188 | |
Kojto | 20:30b6ed7bf8fd | 189 | // Initiate a HCI command |
Kojto | 20:30b6ed7bf8fd | 190 | _hci.command_send(HCI_NETAPP_ARP_FLUSH, ptr, 0); |
Kojto | 20:30b6ed7bf8fd | 191 | |
Kojto | 20:30b6ed7bf8fd | 192 | // Wait for command complete event |
Kojto | 20:30b6ed7bf8fd | 193 | _event.simplelink_wait_event(HCI_NETAPP_ARP_FLUSH, &scRet); |
Kojto | 20:30b6ed7bf8fd | 194 | |
Kojto | 45:50ab13d8f2dc | 195 | return scRet; |
Kojto | 20:30b6ed7bf8fd | 196 | } |
Kojto | 20:30b6ed7bf8fd | 197 | #endif |
Kojto | 20:30b6ed7bf8fd | 198 | |
Kojto | 45:50ab13d8f2dc | 199 | } // mbed_cc3000 |