Update revision to use TI's mqtt and Freertos.

Dependencies:   mbed client server

Fork of cc3100_Test_mqtt_CM3 by David Fletcher

Committer:
dflet
Date:
Thu Sep 03 14:02:37 2015 +0000
Revision:
3:a8c249046181
SPI Mode change 1 to 0

Who changed what in which revision?

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