Driver for CC3000 Wi-Fi module
Dependencies: NVIC_set_all_priorities
Dependents: CC3000_Simple_Socket Wi-Go_IOT_Demo
nvmem.cpp
00001 /***************************************************************************** 00002 * 00003 * nvmem - CC3000 Host Driver Implementation. 00004 * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ 00005 * 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions 00008 * are met: 00009 * 00010 * Redistributions of source code must retain the above copyright 00011 * notice, this list of conditions and the following disclaimer. 00012 * 00013 * Redistributions in binary form must reproduce the above copyright 00014 * notice, this list of conditions and the following disclaimer in the 00015 * documentation and/or other materials provided with the 00016 * distribution. 00017 * 00018 * Neither the name of Texas Instruments Incorporated nor the names of 00019 * its contributors may be used to endorse or promote products derived 00020 * from this software without specific prior written permission. 00021 * 00022 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00023 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00024 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00025 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00026 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00027 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00028 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00029 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00030 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00031 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00032 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00033 * 00034 *****************************************************************************/ 00035 00036 00037 #include "nvmem.h" 00038 00039 signed long nvmem_read(unsigned long ulFileId, unsigned long ulLength, unsigned long ulOffset, unsigned char *buff) 00040 { 00041 unsigned char ucStatus = 0xFF; 00042 unsigned char *ptr; 00043 unsigned char *args; 00044 00045 ptr = tSLInformation.pucTxCommandBuffer; 00046 args = (ptr + HEADERS_SIZE_CMD); 00047 // Fill in HCI packet structure 00048 args = UINT32_TO_STREAM(args, ulFileId); 00049 args = UINT32_TO_STREAM(args, ulLength); 00050 args = UINT32_TO_STREAM(args, ulOffset); 00051 00052 // Initiate HCI command 00053 hci_command_send(HCI_CMND_NVMEM_READ, ptr, NVMEM_READ_PARAMS_LEN); 00054 SimpleLinkWaitEvent(HCI_CMND_NVMEM_READ, &ucStatus); 00055 00056 // If data is present, read it even when an error is returned. 00057 // Note: It is the users responsibility to ignore the data when an error is returned. 00058 // Wait for the data in a synchronous way. 00059 // We assume the buffer is large enough to also store nvmem parameters. 00060 SimpleLinkWaitData(buff, 0, 0); 00061 00062 return(ucStatus); 00063 } 00064 00065 00066 signed long nvmem_write(unsigned long ulFileId, unsigned long ulLength, unsigned long ulEntryOffset, unsigned char *buff) 00067 { 00068 long iRes; 00069 unsigned char *ptr; 00070 unsigned char *args; 00071 00072 iRes = EFAIL; 00073 00074 ptr = tSLInformation.pucTxCommandBuffer; 00075 args = (ptr + SPI_HEADER_SIZE + HCI_DATA_CMD_HEADER_SIZE); 00076 00077 // Fill in HCI packet structure 00078 args = UINT32_TO_STREAM(args, ulFileId); 00079 args = UINT32_TO_STREAM(args, 12); 00080 args = UINT32_TO_STREAM(args, ulLength); 00081 args = UINT32_TO_STREAM(args, ulEntryOffset); 00082 00083 memcpy((ptr + SPI_HEADER_SIZE + HCI_DATA_CMD_HEADER_SIZE + 00084 NVMEM_WRITE_PARAMS_LEN),buff,ulLength); 00085 00086 // Initiate a HCI command on the data channel 00087 hci_data_command_send(HCI_CMND_NVMEM_WRITE, ptr, NVMEM_WRITE_PARAMS_LEN, ulLength); 00088 00089 SimpleLinkWaitEvent(HCI_EVNT_NVMEM_WRITE, &iRes); 00090 00091 return(iRes); 00092 } 00093 00094 00095 unsigned char nvmem_set_mac_address(unsigned char *mac) 00096 { 00097 return nvmem_write(NVMEM_MAC_FILEID, MAC_ADDR_LEN, 0, mac); 00098 } 00099 00100 00101 unsigned char nvmem_get_mac_address(unsigned char *mac) 00102 { 00103 return nvmem_read(NVMEM_MAC_FILEID, MAC_ADDR_LEN, 0, mac); 00104 } 00105 00106 00107 unsigned char nvmem_write_patch(unsigned long ulFileId, unsigned long spLength, const unsigned char *spData) 00108 { 00109 unsigned char status = 0; 00110 unsigned short offset = 0; 00111 unsigned char* spDataPtr = (unsigned char*)spData; 00112 00113 while ((status == 0) && (spLength >= SP_PORTION_SIZE)) 00114 { 00115 status = nvmem_write(ulFileId, SP_PORTION_SIZE, offset, spDataPtr); 00116 offset += SP_PORTION_SIZE; 00117 spLength -= SP_PORTION_SIZE; 00118 spDataPtr += SP_PORTION_SIZE; 00119 } 00120 00121 if (status !=0) 00122 { 00123 // NVMEM error occurred 00124 return status; 00125 } 00126 00127 if (spLength != 0) 00128 { 00129 // If spLength MOD 512 is nonzero, write the remaining bytes. 00130 status = nvmem_write(ulFileId, spLength, offset, spDataPtr); 00131 } 00132 00133 return status; 00134 } 00135 00136 00137 #ifndef CC3000_TINY_DRIVER 00138 unsigned char nvmem_read_sp_version(unsigned char* patchVer) 00139 { 00140 unsigned char *ptr; 00141 // 1st byte is the status and the rest is the SP version 00142 unsigned char retBuf[5]; 00143 00144 ptr = tSLInformation.pucTxCommandBuffer; 00145 00146 // Initiate a HCI command, no args are required 00147 hci_command_send(HCI_CMND_READ_SP_VERSION, ptr, 0); 00148 SimpleLinkWaitEvent(HCI_CMND_READ_SP_VERSION, retBuf); 00149 00150 // package ID 00151 *patchVer = retBuf[3]; 00152 // package build number 00153 *(patchVer+1) = retBuf[4]; 00154 00155 return(retBuf[0]); 00156 } 00157 #endif 00158 00159 00160 signed long 00161 nvmem_create_entry(unsigned long ulFileId, unsigned long ulNewLen) 00162 { 00163 unsigned char *ptr; 00164 unsigned char *args; 00165 unsigned short retval; 00166 00167 ptr = tSLInformation.pucTxCommandBuffer; 00168 args = (ptr + HEADERS_SIZE_CMD); 00169 00170 // Fill in HCI packet structure 00171 args = UINT32_TO_STREAM(args, ulFileId); 00172 args = UINT32_TO_STREAM(args, ulNewLen); 00173 00174 // Initiate a HCI command 00175 hci_command_send(HCI_CMND_NVMEM_CREATE_ENTRY,ptr, NVMEM_CREATE_PARAMS_LEN); 00176 00177 SimpleLinkWaitEvent(HCI_CMND_NVMEM_CREATE_ENTRY, &retval); 00178 00179 return(retval); 00180 } 00181 00182
Generated on Wed Jul 13 2022 18:31:31 by 1.7.2