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