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