Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
WifiRobot/cc3000/cc3000_hci.cpp@0:2deb247ab4bd, 2014-12-09 (annotated)
- Committer:
- wueric
- Date:
- Tue Dec 09 05:06:37 2014 +0000
- Revision:
- 0:2deb247ab4bd
sharing stuff;
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| wueric | 0:2deb247ab4bd | 1 | /***************************************************************************** |
| wueric | 0:2deb247ab4bd | 2 | * |
| wueric | 0:2deb247ab4bd | 3 | * C++ interface/implementation created by Martin Kojtal (0xc0170). Thanks to |
| wueric | 0:2deb247ab4bd | 4 | * Jim Carver and Frank Vannieuwkerke for their inital cc3000 mbed port and |
| wueric | 0:2deb247ab4bd | 5 | * provided help. |
| wueric | 0:2deb247ab4bd | 6 | * |
| wueric | 0:2deb247ab4bd | 7 | * This version of "host driver" uses CC3000 Host Driver Implementation. Thus |
| wueric | 0:2deb247ab4bd | 8 | * read the following copyright: |
| wueric | 0:2deb247ab4bd | 9 | * |
| wueric | 0:2deb247ab4bd | 10 | * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ |
| wueric | 0:2deb247ab4bd | 11 | * |
| wueric | 0:2deb247ab4bd | 12 | * Redistribution and use in source and binary forms, with or without |
| wueric | 0:2deb247ab4bd | 13 | * modification, are permitted provided that the following conditions |
| wueric | 0:2deb247ab4bd | 14 | * are met: |
| wueric | 0:2deb247ab4bd | 15 | * |
| wueric | 0:2deb247ab4bd | 16 | * Redistributions of source code must retain the above copyright |
| wueric | 0:2deb247ab4bd | 17 | * notice, this list of conditions and the following disclaimer. |
| wueric | 0:2deb247ab4bd | 18 | * |
| wueric | 0:2deb247ab4bd | 19 | * Redistributions in binary form must reproduce the above copyright |
| wueric | 0:2deb247ab4bd | 20 | * notice, this list of conditions and the following disclaimer in the |
| wueric | 0:2deb247ab4bd | 21 | * documentation and/or other materials provided with the |
| wueric | 0:2deb247ab4bd | 22 | * distribution. |
| wueric | 0:2deb247ab4bd | 23 | * |
| wueric | 0:2deb247ab4bd | 24 | * Neither the name of Texas Instruments Incorporated nor the names of |
| wueric | 0:2deb247ab4bd | 25 | * its contributors may be used to endorse or promote products derived |
| wueric | 0:2deb247ab4bd | 26 | * from this software without specific prior written permission. |
| wueric | 0:2deb247ab4bd | 27 | * |
| wueric | 0:2deb247ab4bd | 28 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| wueric | 0:2deb247ab4bd | 29 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| wueric | 0:2deb247ab4bd | 30 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| wueric | 0:2deb247ab4bd | 31 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| wueric | 0:2deb247ab4bd | 32 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| wueric | 0:2deb247ab4bd | 33 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| wueric | 0:2deb247ab4bd | 34 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| wueric | 0:2deb247ab4bd | 35 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| wueric | 0:2deb247ab4bd | 36 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| wueric | 0:2deb247ab4bd | 37 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| wueric | 0:2deb247ab4bd | 38 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| wueric | 0:2deb247ab4bd | 39 | * |
| wueric | 0:2deb247ab4bd | 40 | *****************************************************************************/ |
| wueric | 0:2deb247ab4bd | 41 | #include "cc3000.h" |
| wueric | 0:2deb247ab4bd | 42 | |
| wueric | 0:2deb247ab4bd | 43 | namespace mbed_cc3000 { |
| wueric | 0:2deb247ab4bd | 44 | |
| wueric | 0:2deb247ab4bd | 45 | cc3000_hci::cc3000_hci(cc3000_spi &spi) : _spi(spi) { |
| wueric | 0:2deb247ab4bd | 46 | |
| wueric | 0:2deb247ab4bd | 47 | } |
| wueric | 0:2deb247ab4bd | 48 | |
| wueric | 0:2deb247ab4bd | 49 | cc3000_hci::~cc3000_hci() { |
| wueric | 0:2deb247ab4bd | 50 | |
| wueric | 0:2deb247ab4bd | 51 | } |
| wueric | 0:2deb247ab4bd | 52 | |
| wueric | 0:2deb247ab4bd | 53 | uint16_t cc3000_hci::command_send(uint16_t op_code, uint8_t *buffer, uint8_t length) { |
| wueric | 0:2deb247ab4bd | 54 | uint8_t *stream; |
| wueric | 0:2deb247ab4bd | 55 | |
| wueric | 0:2deb247ab4bd | 56 | DBG_HCI_CMD("Command Sent : 0x%04X", op_code); |
| wueric | 0:2deb247ab4bd | 57 | |
| wueric | 0:2deb247ab4bd | 58 | stream = (buffer + SPI_HEADER_SIZE); |
| wueric | 0:2deb247ab4bd | 59 | |
| wueric | 0:2deb247ab4bd | 60 | UINT8_TO_STREAM(stream, HCI_TYPE_CMND); |
| wueric | 0:2deb247ab4bd | 61 | stream = UINT16_TO_STREAM(stream, op_code); |
| wueric | 0:2deb247ab4bd | 62 | UINT8_TO_STREAM(stream, length); |
| wueric | 0:2deb247ab4bd | 63 | //Update the opcode of the event we will be waiting for |
| wueric | 0:2deb247ab4bd | 64 | _spi.write(buffer, length + SIMPLE_LINK_HCI_CMND_HEADER_SIZE); |
| wueric | 0:2deb247ab4bd | 65 | return(0); |
| wueric | 0:2deb247ab4bd | 66 | } |
| wueric | 0:2deb247ab4bd | 67 | |
| wueric | 0:2deb247ab4bd | 68 | uint32_t cc3000_hci::data_send(uint8_t op_code, uint8_t *args, uint16_t arg_length, |
| wueric | 0:2deb247ab4bd | 69 | uint16_t data_length, const uint8_t *tail, uint16_t tail_length) { |
| wueric | 0:2deb247ab4bd | 70 | uint8_t *stream; |
| wueric | 0:2deb247ab4bd | 71 | |
| wueric | 0:2deb247ab4bd | 72 | stream = ((args) + SPI_HEADER_SIZE); |
| wueric | 0:2deb247ab4bd | 73 | |
| wueric | 0:2deb247ab4bd | 74 | UINT8_TO_STREAM(stream, HCI_TYPE_DATA); |
| wueric | 0:2deb247ab4bd | 75 | UINT8_TO_STREAM(stream, op_code); |
| wueric | 0:2deb247ab4bd | 76 | UINT8_TO_STREAM(stream, arg_length); |
| wueric | 0:2deb247ab4bd | 77 | stream = UINT16_TO_STREAM(stream, arg_length + data_length + tail_length); |
| wueric | 0:2deb247ab4bd | 78 | |
| wueric | 0:2deb247ab4bd | 79 | // Send the packet |
| wueric | 0:2deb247ab4bd | 80 | _spi.write(args, SIMPLE_LINK_HCI_DATA_HEADER_SIZE + arg_length + data_length + tail_length); |
| wueric | 0:2deb247ab4bd | 81 | |
| wueric | 0:2deb247ab4bd | 82 | return 0; |
| wueric | 0:2deb247ab4bd | 83 | } |
| wueric | 0:2deb247ab4bd | 84 | |
| wueric | 0:2deb247ab4bd | 85 | void cc3000_hci::data_command_send(uint16_t op_code, uint8_t *buffer, uint8_t arg_length, uint16_t data_length) { |
| wueric | 0:2deb247ab4bd | 86 | uint8_t *stream = (buffer + SPI_HEADER_SIZE); |
| wueric | 0:2deb247ab4bd | 87 | |
| wueric | 0:2deb247ab4bd | 88 | UINT8_TO_STREAM(stream, HCI_TYPE_DATA); |
| wueric | 0:2deb247ab4bd | 89 | UINT8_TO_STREAM(stream, op_code); |
| wueric | 0:2deb247ab4bd | 90 | UINT8_TO_STREAM(stream, arg_length); |
| wueric | 0:2deb247ab4bd | 91 | stream = UINT16_TO_STREAM(stream, arg_length + data_length); |
| wueric | 0:2deb247ab4bd | 92 | |
| wueric | 0:2deb247ab4bd | 93 | // Send the command |
| wueric | 0:2deb247ab4bd | 94 | _spi.write(buffer, arg_length + data_length + SIMPLE_LINK_HCI_DATA_CMND_HEADER_SIZE); |
| wueric | 0:2deb247ab4bd | 95 | |
| wueric | 0:2deb247ab4bd | 96 | return; |
| wueric | 0:2deb247ab4bd | 97 | } |
| wueric | 0:2deb247ab4bd | 98 | |
| wueric | 0:2deb247ab4bd | 99 | void cc3000_hci::patch_send(uint8_t op_code, uint8_t *buffer, uint8_t *patch, uint16_t data_length) { |
| wueric | 0:2deb247ab4bd | 100 | uint16_t usTransLength; |
| wueric | 0:2deb247ab4bd | 101 | uint8_t *stream = (buffer + SPI_HEADER_SIZE); |
| wueric | 0:2deb247ab4bd | 102 | UINT8_TO_STREAM(stream, HCI_TYPE_PATCH); |
| wueric | 0:2deb247ab4bd | 103 | UINT8_TO_STREAM(stream, op_code); |
| wueric | 0:2deb247ab4bd | 104 | stream = UINT16_TO_STREAM(stream, data_length + SIMPLE_LINK_HCI_PATCH_HEADER_SIZE); |
| wueric | 0:2deb247ab4bd | 105 | if (data_length <= SL_PATCH_PORTION_SIZE) { |
| wueric | 0:2deb247ab4bd | 106 | UINT16_TO_STREAM(stream, data_length); |
| wueric | 0:2deb247ab4bd | 107 | stream = UINT16_TO_STREAM(stream, data_length); |
| wueric | 0:2deb247ab4bd | 108 | memcpy((buffer + SPI_HEADER_SIZE) + HCI_PATCH_HEADER_SIZE, patch, data_length); |
| wueric | 0:2deb247ab4bd | 109 | // Update the opcode of the event we will be waiting for |
| wueric | 0:2deb247ab4bd | 110 | _spi.write(buffer, data_length + HCI_PATCH_HEADER_SIZE); |
| wueric | 0:2deb247ab4bd | 111 | } else { |
| wueric | 0:2deb247ab4bd | 112 | |
| wueric | 0:2deb247ab4bd | 113 | usTransLength = (data_length/SL_PATCH_PORTION_SIZE); |
| wueric | 0:2deb247ab4bd | 114 | UINT16_TO_STREAM(stream, data_length + SIMPLE_LINK_HCI_PATCH_HEADER_SIZE + usTransLength*SIMPLE_LINK_HCI_PATCH_HEADER_SIZE); |
| wueric | 0:2deb247ab4bd | 115 | stream = UINT16_TO_STREAM(stream, SL_PATCH_PORTION_SIZE); |
| wueric | 0:2deb247ab4bd | 116 | memcpy(buffer + SPI_HEADER_SIZE + HCI_PATCH_HEADER_SIZE, patch, SL_PATCH_PORTION_SIZE); |
| wueric | 0:2deb247ab4bd | 117 | data_length -= SL_PATCH_PORTION_SIZE; |
| wueric | 0:2deb247ab4bd | 118 | patch += SL_PATCH_PORTION_SIZE; |
| wueric | 0:2deb247ab4bd | 119 | |
| wueric | 0:2deb247ab4bd | 120 | // Update the opcode of the event we will be waiting for |
| wueric | 0:2deb247ab4bd | 121 | _spi.write(buffer, SL_PATCH_PORTION_SIZE + HCI_PATCH_HEADER_SIZE); |
| wueric | 0:2deb247ab4bd | 122 | |
| wueric | 0:2deb247ab4bd | 123 | stream = (buffer + SPI_HEADER_SIZE); |
| wueric | 0:2deb247ab4bd | 124 | while (data_length) { |
| wueric | 0:2deb247ab4bd | 125 | if (data_length <= SL_PATCH_PORTION_SIZE) { |
| wueric | 0:2deb247ab4bd | 126 | usTransLength = data_length; |
| wueric | 0:2deb247ab4bd | 127 | data_length = 0; |
| wueric | 0:2deb247ab4bd | 128 | } else { |
| wueric | 0:2deb247ab4bd | 129 | usTransLength = SL_PATCH_PORTION_SIZE; |
| wueric | 0:2deb247ab4bd | 130 | data_length -= usTransLength; |
| wueric | 0:2deb247ab4bd | 131 | } |
| wueric | 0:2deb247ab4bd | 132 | |
| wueric | 0:2deb247ab4bd | 133 | *(uint16_t *)stream = usTransLength; |
| wueric | 0:2deb247ab4bd | 134 | memcpy(stream + SIMPLE_LINK_HCI_PATCH_HEADER_SIZE, patch, usTransLength); |
| wueric | 0:2deb247ab4bd | 135 | patch += usTransLength; |
| wueric | 0:2deb247ab4bd | 136 | |
| wueric | 0:2deb247ab4bd | 137 | // Update the opcode of the event we will be waiting for |
| wueric | 0:2deb247ab4bd | 138 | _spi.write((unsigned char *)stream, usTransLength + sizeof(usTransLength)); |
| wueric | 0:2deb247ab4bd | 139 | } |
| wueric | 0:2deb247ab4bd | 140 | } |
| wueric | 0:2deb247ab4bd | 141 | } |
| wueric | 0:2deb247ab4bd | 142 | |
| wueric | 0:2deb247ab4bd | 143 | } // mbed_cc3000 namespace |
