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.
Fork of cc3000_hostdriver_mbedsocket by
cc3000_hci.cpp
00001 /***************************************************************************** 00002 * 00003 * C++ interface/implementation created by Martin Kojtal (0xc0170). Thanks to 00004 * Jim Carver and Frank Vannieuwkerke for their inital cc3000 mbed port and 00005 * provided help. 00006 * 00007 * This version of "host driver" uses CC3000 Host Driver Implementation. Thus 00008 * read the following copyright: 00009 * 00010 * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ 00011 * 00012 * Redistribution and use in source and binary forms, with or without 00013 * modification, are permitted provided that the following conditions 00014 * are met: 00015 * 00016 * Redistributions of source code must retain the above copyright 00017 * notice, this list of conditions and the following disclaimer. 00018 * 00019 * Redistributions in binary form must reproduce the above copyright 00020 * notice, this list of conditions and the following disclaimer in the 00021 * documentation and/or other materials provided with the 00022 * distribution. 00023 * 00024 * Neither the name of Texas Instruments Incorporated nor the names of 00025 * its contributors may be used to endorse or promote products derived 00026 * from this software without specific prior written permission. 00027 * 00028 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00029 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00030 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00031 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00032 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00033 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00034 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00035 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00036 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00037 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00038 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00039 * 00040 *****************************************************************************/ 00041 #include "cc3000.h" 00042 00043 namespace mbed_cc3000 { 00044 00045 cc3000_hci::cc3000_hci(cc3000_spi &spi) : _spi(spi) { 00046 00047 } 00048 00049 cc3000_hci::~cc3000_hci() { 00050 00051 } 00052 00053 uint16_t cc3000_hci::command_send(uint16_t op_code, uint8_t *buffer, uint8_t length) { 00054 uint8_t *stream; 00055 00056 DBG_HCI_CMD("Command Sent : 0x%04X", op_code); 00057 00058 stream = (buffer + SPI_HEADER_SIZE); 00059 00060 UINT8_TO_STREAM(stream, HCI_TYPE_CMND); 00061 stream = UINT16_TO_STREAM(stream, op_code); 00062 UINT8_TO_STREAM(stream, length); 00063 //Update the opcode of the event we will be waiting for 00064 _spi.write(buffer, length + SIMPLE_LINK_HCI_CMND_HEADER_SIZE); 00065 return(0); 00066 } 00067 00068 uint32_t cc3000_hci::data_send(uint8_t op_code, uint8_t *args, uint16_t arg_length, 00069 uint16_t data_length, const uint8_t *tail, uint16_t tail_length) { 00070 uint8_t *stream; 00071 00072 stream = ((args) + SPI_HEADER_SIZE); 00073 00074 UINT8_TO_STREAM(stream, HCI_TYPE_DATA); 00075 UINT8_TO_STREAM(stream, op_code); 00076 UINT8_TO_STREAM(stream, arg_length); 00077 stream = UINT16_TO_STREAM(stream, arg_length + data_length + tail_length); 00078 00079 // Send the packet 00080 _spi.write(args, SIMPLE_LINK_HCI_DATA_HEADER_SIZE + arg_length + data_length + tail_length); 00081 00082 return 0; 00083 } 00084 00085 void cc3000_hci::data_command_send(uint16_t op_code, uint8_t *buffer, uint8_t arg_length, uint16_t data_length) { 00086 uint8_t *stream = (buffer + SPI_HEADER_SIZE); 00087 00088 UINT8_TO_STREAM(stream, HCI_TYPE_DATA); 00089 UINT8_TO_STREAM(stream, op_code); 00090 UINT8_TO_STREAM(stream, arg_length); 00091 stream = UINT16_TO_STREAM(stream, arg_length + data_length); 00092 00093 // Send the command 00094 _spi.write(buffer, arg_length + data_length + SIMPLE_LINK_HCI_DATA_CMND_HEADER_SIZE); 00095 00096 return; 00097 } 00098 00099 void cc3000_hci::patch_send(uint8_t op_code, uint8_t *buffer, uint8_t *patch, uint16_t data_length) { 00100 uint16_t usTransLength; 00101 uint8_t *stream = (buffer + SPI_HEADER_SIZE); 00102 UINT8_TO_STREAM(stream, HCI_TYPE_PATCH); 00103 UINT8_TO_STREAM(stream, op_code); 00104 stream = UINT16_TO_STREAM(stream, data_length + SIMPLE_LINK_HCI_PATCH_HEADER_SIZE); 00105 if (data_length <= SL_PATCH_PORTION_SIZE) { 00106 UINT16_TO_STREAM(stream, data_length); 00107 stream = UINT16_TO_STREAM(stream, data_length); 00108 memcpy((buffer + SPI_HEADER_SIZE) + HCI_PATCH_HEADER_SIZE, patch, data_length); 00109 // Update the opcode of the event we will be waiting for 00110 _spi.write(buffer, data_length + HCI_PATCH_HEADER_SIZE); 00111 } else { 00112 00113 usTransLength = (data_length/SL_PATCH_PORTION_SIZE); 00114 UINT16_TO_STREAM(stream, data_length + SIMPLE_LINK_HCI_PATCH_HEADER_SIZE + usTransLength*SIMPLE_LINK_HCI_PATCH_HEADER_SIZE); 00115 stream = UINT16_TO_STREAM(stream, SL_PATCH_PORTION_SIZE); 00116 memcpy(buffer + SPI_HEADER_SIZE + HCI_PATCH_HEADER_SIZE, patch, SL_PATCH_PORTION_SIZE); 00117 data_length -= SL_PATCH_PORTION_SIZE; 00118 patch += SL_PATCH_PORTION_SIZE; 00119 00120 // Update the opcode of the event we will be waiting for 00121 _spi.write(buffer, SL_PATCH_PORTION_SIZE + HCI_PATCH_HEADER_SIZE); 00122 00123 stream = (buffer + SPI_HEADER_SIZE); 00124 while (data_length) { 00125 if (data_length <= SL_PATCH_PORTION_SIZE) { 00126 usTransLength = data_length; 00127 data_length = 0; 00128 } else { 00129 usTransLength = SL_PATCH_PORTION_SIZE; 00130 data_length -= usTransLength; 00131 } 00132 00133 *(uint16_t *)stream = usTransLength; 00134 memcpy(stream + SIMPLE_LINK_HCI_PATCH_HEADER_SIZE, patch, usTransLength); 00135 patch += usTransLength; 00136 00137 // Update the opcode of the event we will be waiting for 00138 _spi.write((unsigned char *)stream, usTransLength + sizeof(usTransLength)); 00139 } 00140 } 00141 } 00142 00143 } // mbed_cc3000 namespace
Generated on Fri Jul 15 2022 17:19:25 by
1.7.2
