David Fletcher / simplelink_V2

Fork of simplelink_V2 by David Fletcher

Committer:
dflet
Date:
Sat Jun 06 13:31:01 2015 +0000
Revision:
0:1a07906111ec
Changes made to use external spawn Freertos

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dflet 0:1a07906111ec 1 /*
dflet 0:1a07906111ec 2 * netcfg.c - CC31xx/CC32xx Host Driver Implementation
dflet 0:1a07906111ec 3 *
dflet 0:1a07906111ec 4 * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
dflet 0:1a07906111ec 5 *
dflet 0:1a07906111ec 6 *
dflet 0:1a07906111ec 7 * Redistribution and use in source and binary forms, with or without
dflet 0:1a07906111ec 8 * modification, are permitted provided that the following conditions
dflet 0:1a07906111ec 9 * are met:
dflet 0:1a07906111ec 10 *
dflet 0:1a07906111ec 11 * Redistributions of source code must retain the above copyright
dflet 0:1a07906111ec 12 * notice, this list of conditions and the following disclaimer.
dflet 0:1a07906111ec 13 *
dflet 0:1a07906111ec 14 * Redistributions in binary form must reproduce the above copyright
dflet 0:1a07906111ec 15 * notice, this list of conditions and the following disclaimer in the
dflet 0:1a07906111ec 16 * documentation and/or other materials provided with the
dflet 0:1a07906111ec 17 * distribution.
dflet 0:1a07906111ec 18 *
dflet 0:1a07906111ec 19 * Neither the name of Texas Instruments Incorporated nor the names of
dflet 0:1a07906111ec 20 * its contributors may be used to endorse or promote products derived
dflet 0:1a07906111ec 21 * from this software without specific prior written permission.
dflet 0:1a07906111ec 22 *
dflet 0:1a07906111ec 23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
dflet 0:1a07906111ec 24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
dflet 0:1a07906111ec 25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
dflet 0:1a07906111ec 26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
dflet 0:1a07906111ec 27 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
dflet 0:1a07906111ec 28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
dflet 0:1a07906111ec 29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
dflet 0:1a07906111ec 30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
dflet 0:1a07906111ec 31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
dflet 0:1a07906111ec 32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
dflet 0:1a07906111ec 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
dflet 0:1a07906111ec 34 *
dflet 0:1a07906111ec 35 */
dflet 0:1a07906111ec 36
dflet 0:1a07906111ec 37
dflet 0:1a07906111ec 38
dflet 0:1a07906111ec 39 /*****************************************************************************/
dflet 0:1a07906111ec 40 /* Include files */
dflet 0:1a07906111ec 41 /*****************************************************************************/
dflet 0:1a07906111ec 42 #include "cc3100_simplelink.h"
dflet 0:1a07906111ec 43 #include "cc3100_protocol.h"
dflet 0:1a07906111ec 44 #include "cc3100_driver.h"
dflet 0:1a07906111ec 45
dflet 0:1a07906111ec 46 #include "cc3100_netcfg.h"
dflet 0:1a07906111ec 47
dflet 0:1a07906111ec 48 namespace mbed_cc3100 {
dflet 0:1a07906111ec 49
dflet 0:1a07906111ec 50 cc3100_netcfg::cc3100_netcfg(cc3100_driver &driver)
dflet 0:1a07906111ec 51 : _driver(driver)
dflet 0:1a07906111ec 52 {
dflet 0:1a07906111ec 53
dflet 0:1a07906111ec 54 }
dflet 0:1a07906111ec 55
dflet 0:1a07906111ec 56 cc3100_netcfg::~cc3100_netcfg()
dflet 0:1a07906111ec 57 {
dflet 0:1a07906111ec 58
dflet 0:1a07906111ec 59 }
dflet 0:1a07906111ec 60
dflet 0:1a07906111ec 61 /*****************************************************************************/
dflet 0:1a07906111ec 62 /* sl_NetCfgSet */
dflet 0:1a07906111ec 63 /*****************************************************************************/
dflet 0:1a07906111ec 64 typedef union {
dflet 0:1a07906111ec 65 _NetCfgSetGet_t Cmd;
dflet 0:1a07906111ec 66 _BasicResponse_t Rsp;
dflet 0:1a07906111ec 67 } _SlNetCfgMsgSet_u;
dflet 0:1a07906111ec 68
dflet 0:1a07906111ec 69 #if _SL_INCLUDE_FUNC(sl_NetCfgSet)
dflet 0:1a07906111ec 70 const _SlCmdCtrl_t _SlNetCfgSetCmdCtrl = {
dflet 0:1a07906111ec 71 SL_OPCODE_DEVICE_NETCFG_SET_COMMAND,
dflet 0:1a07906111ec 72 sizeof(_NetCfgSetGet_t),
dflet 0:1a07906111ec 73 sizeof(_BasicResponse_t)
dflet 0:1a07906111ec 74 };
dflet 0:1a07906111ec 75
dflet 0:1a07906111ec 76 int32_t cc3100_netcfg::sl_NetCfgSet(const uint8_t ConfigId, const uint8_t ConfigOpt, const uint8_t ConfigLen, const uint8_t *pValues)
dflet 0:1a07906111ec 77 {
dflet 0:1a07906111ec 78 _SlNetCfgMsgSet_u Msg;
dflet 0:1a07906111ec 79 _SlCmdExt_t CmdExt;
dflet 0:1a07906111ec 80
dflet 0:1a07906111ec 81 _driver._SlDrvResetCmdExt(&CmdExt);
dflet 0:1a07906111ec 82 CmdExt.TxPayloadLen = (ConfigLen+3) & (~3);
dflet 0:1a07906111ec 83 CmdExt.pTxPayload = (uint8_t *)pValues;
dflet 0:1a07906111ec 84
dflet 0:1a07906111ec 85 Msg.Cmd.ConfigId = ConfigId;
dflet 0:1a07906111ec 86 Msg.Cmd.ConfigLen = ConfigLen;
dflet 0:1a07906111ec 87 Msg.Cmd.ConfigOpt = ConfigOpt;
dflet 0:1a07906111ec 88
dflet 0:1a07906111ec 89 VERIFY_RET_OK(_driver._SlDrvCmdOp((_SlCmdCtrl_t *)&_SlNetCfgSetCmdCtrl, &Msg, &CmdExt));
dflet 0:1a07906111ec 90
dflet 0:1a07906111ec 91 return (int16_t)Msg.Rsp.status;
dflet 0:1a07906111ec 92 }
dflet 0:1a07906111ec 93 #endif
dflet 0:1a07906111ec 94
dflet 0:1a07906111ec 95 uint32_t cc3100_netcfg::SL_IPV4_VAL(uint8_t add_3,uint8_t add_2,uint8_t add_1,uint8_t add_0){
dflet 0:1a07906111ec 96
dflet 0:1a07906111ec 97 return((((uint32_t)add_3 << 24) & 0xFF000000) | (((uint32_t)add_2 << 16) & 0xFF0000) | (((uint32_t)add_1 << 8) & 0xFF00) | ((uint32_t)add_0 & 0xFF) );
dflet 0:1a07906111ec 98 }
dflet 0:1a07906111ec 99
dflet 0:1a07906111ec 100 uint8_t cc3100_netcfg::SL_IPV4_BYTE(uint32_t val,uint8_t index){
dflet 0:1a07906111ec 101
dflet 0:1a07906111ec 102 return( (val >>= (index*8)) & 0xFF );
dflet 0:1a07906111ec 103 }
dflet 0:1a07906111ec 104
dflet 0:1a07906111ec 105 /*****************************************************************************/
dflet 0:1a07906111ec 106 /* sl_NetCfgGet */
dflet 0:1a07906111ec 107 /*****************************************************************************/
dflet 0:1a07906111ec 108 typedef union {
dflet 0:1a07906111ec 109 _NetCfgSetGet_t Cmd;
dflet 0:1a07906111ec 110 _NetCfgSetGet_t Rsp;
dflet 0:1a07906111ec 111 } _SlNetCfgMsgGet_u;
dflet 0:1a07906111ec 112
dflet 0:1a07906111ec 113 #if _SL_INCLUDE_FUNC(sl_NetCfgGet)
dflet 0:1a07906111ec 114 const _SlCmdCtrl_t _SlNetCfgGetCmdCtrl = {
dflet 0:1a07906111ec 115 SL_OPCODE_DEVICE_NETCFG_GET_COMMAND,
dflet 0:1a07906111ec 116 sizeof(_NetCfgSetGet_t),
dflet 0:1a07906111ec 117 sizeof(_NetCfgSetGet_t)
dflet 0:1a07906111ec 118 };
dflet 0:1a07906111ec 119
dflet 0:1a07906111ec 120 int32_t cc3100_netcfg::sl_NetCfgGet(const uint8_t ConfigId, uint8_t *pConfigOpt,uint8_t *pConfigLen, uint8_t *pValues)
dflet 0:1a07906111ec 121 {
dflet 0:1a07906111ec 122 _SlNetCfgMsgGet_u Msg;
dflet 0:1a07906111ec 123 _SlCmdExt_t CmdExt;
dflet 0:1a07906111ec 124
dflet 0:1a07906111ec 125 if (*pConfigLen == 0) {
dflet 0:1a07906111ec 126 return SL_EZEROLEN;
dflet 0:1a07906111ec 127 }
dflet 0:1a07906111ec 128
dflet 0:1a07906111ec 129 _driver._SlDrvResetCmdExt(&CmdExt);
dflet 0:1a07906111ec 130 CmdExt.RxPayloadLen = *pConfigLen;
dflet 0:1a07906111ec 131 CmdExt.pRxPayload = (uint8_t *)pValues;
dflet 0:1a07906111ec 132
dflet 0:1a07906111ec 133 Msg.Cmd.ConfigLen = *pConfigLen;
dflet 0:1a07906111ec 134 Msg.Cmd.ConfigId = ConfigId;
dflet 0:1a07906111ec 135
dflet 0:1a07906111ec 136 if( pConfigOpt ) {
dflet 0:1a07906111ec 137 Msg.Cmd.ConfigOpt = (uint16_t)*pConfigOpt;
dflet 0:1a07906111ec 138 }
dflet 0:1a07906111ec 139 VERIFY_RET_OK(_driver._SlDrvCmdOp((_SlCmdCtrl_t *)&_SlNetCfgGetCmdCtrl, &Msg, &CmdExt));
dflet 0:1a07906111ec 140
dflet 0:1a07906111ec 141 if( pConfigOpt ) {
dflet 0:1a07906111ec 142 *pConfigOpt = (uint8_t)Msg.Rsp.ConfigOpt;
dflet 0:1a07906111ec 143 }
dflet 0:1a07906111ec 144 if (CmdExt.RxPayloadLen < CmdExt.ActualRxPayloadLen) {
dflet 0:1a07906111ec 145 *pConfigLen = (uint8_t)CmdExt.RxPayloadLen;
dflet 0:1a07906111ec 146 if( SL_MAC_ADDRESS_GET == ConfigId )
dflet 0:1a07906111ec 147 {
dflet 0:1a07906111ec 148 return SL_RET_CODE_OK; /* sp fix */
dflet 0:1a07906111ec 149 }
dflet 0:1a07906111ec 150 else
dflet 0:1a07906111ec 151 {
dflet 0:1a07906111ec 152 return SL_ESMALLBUF;
dflet 0:1a07906111ec 153 }
dflet 0:1a07906111ec 154 }
dflet 0:1a07906111ec 155 else
dflet 0:1a07906111ec 156 {
dflet 0:1a07906111ec 157 *pConfigLen = (uint8_t)CmdExt.ActualRxPayloadLen;
dflet 0:1a07906111ec 158 }
dflet 0:1a07906111ec 159
dflet 0:1a07906111ec 160 return (int16_t)Msg.Rsp.Status;
dflet 0:1a07906111ec 161 }
dflet 0:1a07906111ec 162 #endif
dflet 0:1a07906111ec 163
dflet 0:1a07906111ec 164 }//namespace mbed_cc3100