cc3000 hostdriver with the mbed socket interface

Fork of cc3000_hostdriver_mbedsocket by Martin Kojtal

Committer:
Kojto
Date:
Wed Nov 06 17:56:25 2013 +0100
Revision:
45:50ab13d8f2dc
Parent:
33:9e23b24fb4f3
Child:
51:897cfc2c7e8c
complete Ethernet interface

- code clean-up
- IRQ - faster enable/disable, a flag to process an IRQ
- EthernetInterface
- TINY_DRIVER compilation errors correction

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Kojto 20:30b6ed7bf8fd 1 /*****************************************************************************
Kojto 20:30b6ed7bf8fd 2 *
Kojto 20:30b6ed7bf8fd 3 * C++ interface/implementation created by Martin Kojtal (0xc0170). Thanks to
Kojto 20:30b6ed7bf8fd 4 * Jim Carver and Frank Vannieuwkerke for their inital cc3000 mbed port and
Kojto 20:30b6ed7bf8fd 5 * provided help.
Kojto 20:30b6ed7bf8fd 6 *
Kojto 20:30b6ed7bf8fd 7 * This version of "host driver" uses CC3000 Host Driver Implementation. Thus
Kojto 20:30b6ed7bf8fd 8 * read the following copyright:
Kojto 20:30b6ed7bf8fd 9 *
Kojto 20:30b6ed7bf8fd 10 * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
Kojto 20:30b6ed7bf8fd 11 *
Kojto 20:30b6ed7bf8fd 12 * Redistribution and use in source and binary forms, with or without
Kojto 20:30b6ed7bf8fd 13 * modification, are permitted provided that the following conditions
Kojto 20:30b6ed7bf8fd 14 * are met:
Kojto 20:30b6ed7bf8fd 15 *
Kojto 20:30b6ed7bf8fd 16 * Redistributions of source code must retain the above copyright
Kojto 20:30b6ed7bf8fd 17 * notice, this list of conditions and the following disclaimer.
Kojto 20:30b6ed7bf8fd 18 *
Kojto 20:30b6ed7bf8fd 19 * Redistributions in binary form must reproduce the above copyright
Kojto 20:30b6ed7bf8fd 20 * notice, this list of conditions and the following disclaimer in the
Kojto 20:30b6ed7bf8fd 21 * documentation and/or other materials provided with the
Kojto 20:30b6ed7bf8fd 22 * distribution.
Kojto 20:30b6ed7bf8fd 23 *
Kojto 20:30b6ed7bf8fd 24 * Neither the name of Texas Instruments Incorporated nor the names of
Kojto 20:30b6ed7bf8fd 25 * its contributors may be used to endorse or promote products derived
Kojto 20:30b6ed7bf8fd 26 * from this software without specific prior written permission.
Kojto 20:30b6ed7bf8fd 27 *
Kojto 20:30b6ed7bf8fd 28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
Kojto 20:30b6ed7bf8fd 29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
Kojto 20:30b6ed7bf8fd 30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
Kojto 20:30b6ed7bf8fd 31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
Kojto 20:30b6ed7bf8fd 32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
Kojto 20:30b6ed7bf8fd 33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
Kojto 20:30b6ed7bf8fd 34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
Kojto 20:30b6ed7bf8fd 35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
Kojto 20:30b6ed7bf8fd 36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Kojto 20:30b6ed7bf8fd 37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Kojto 20:30b6ed7bf8fd 38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Kojto 20:30b6ed7bf8fd 39 *
Kojto 20:30b6ed7bf8fd 40 *****************************************************************************/
Kojto 20:30b6ed7bf8fd 41 #include "cc3000.h"
Kojto 20:30b6ed7bf8fd 42 #include "cc3000_common.h"
Kojto 20:30b6ed7bf8fd 43
Kojto 20:30b6ed7bf8fd 44 namespace mbed_cc3000 {
Kojto 20:30b6ed7bf8fd 45
Kojto 20:30b6ed7bf8fd 46 cc3000_simple_link::cc3000_simple_link() {
Kojto 20:30b6ed7bf8fd 47 _rx_buffer[CC3000_RX_BUFFER_SIZE - 1] = CC3000_BUFFER_MAGIC_NUMBER;
Kojto 20:30b6ed7bf8fd 48 _tx_buffer[CC3000_TX_BUFFER_SIZE - 1] = CC3000_BUFFER_MAGIC_NUMBER;
Kojto 20:30b6ed7bf8fd 49 }
Kojto 20:30b6ed7bf8fd 50
Kojto 20:30b6ed7bf8fd 51 cc3000_simple_link::~cc3000_simple_link() {
Kojto 20:30b6ed7bf8fd 52 }
Kojto 20:30b6ed7bf8fd 53
Kojto 20:30b6ed7bf8fd 54 uint8_t cc3000_simple_link::get_data_received_flag() {
Kojto 20:30b6ed7bf8fd 55 return _data_received_flag;
Kojto 20:30b6ed7bf8fd 56 }
Kojto 20:30b6ed7bf8fd 57
Kojto 20:30b6ed7bf8fd 58 void *cc3000_simple_link::get_func_pointer(FunctionNumber function){
Kojto 20:30b6ed7bf8fd 59 void *result;
Kojto 20:30b6ed7bf8fd 60 /* casting to void *, will be casted back once used */
Kojto 20:30b6ed7bf8fd 61 switch(function) {
Kojto 20:30b6ed7bf8fd 62 case FW_PATCHES:
Kojto 20:30b6ed7bf8fd 63 result = (void *)_fFWPatches;
Kojto 20:30b6ed7bf8fd 64 break;
Kojto 20:30b6ed7bf8fd 65 case DRIVER_PATCHES:
Kojto 20:30b6ed7bf8fd 66 result = (void *)_fDriverPatches;
Kojto 20:30b6ed7bf8fd 67 break;
Kojto 20:30b6ed7bf8fd 68 case BOOTLOADER_PATCHES:
Kojto 20:30b6ed7bf8fd 69 result = (void *)_fBootLoaderPatches;
Kojto 20:30b6ed7bf8fd 70 break;
Kojto 20:30b6ed7bf8fd 71 default:
Kojto 20:30b6ed7bf8fd 72 result = 0;
Kojto 20:30b6ed7bf8fd 73 }
Kojto 20:30b6ed7bf8fd 74 return result;
Kojto 20:30b6ed7bf8fd 75 }
Kojto 20:30b6ed7bf8fd 76
Kojto 45:50ab13d8f2dc 77 uint8_t* cc3000_simple_link::get_transmit_buffer() {
Kojto 20:30b6ed7bf8fd 78 return _tx_buffer;
Kojto 20:30b6ed7bf8fd 79 }
Kojto 20:30b6ed7bf8fd 80
Kojto 45:50ab13d8f2dc 81 uint8_t* cc3000_simple_link::get_received_buffer() {
Kojto 20:30b6ed7bf8fd 82 return _rx_buffer;
Kojto 20:30b6ed7bf8fd 83 }
Kojto 20:30b6ed7bf8fd 84
Kojto 20:30b6ed7bf8fd 85 void cc3000_simple_link::set_op_code(uint16_t code) {
Kojto 20:30b6ed7bf8fd 86 _rx_event_opcode = code;
Kojto 20:30b6ed7bf8fd 87 }
Kojto 20:30b6ed7bf8fd 88
Kojto 20:30b6ed7bf8fd 89 void cc3000_simple_link::set_pending_data(uint16_t value) {
Kojto 20:30b6ed7bf8fd 90 _rx_data_pending = value;
Kojto 20:30b6ed7bf8fd 91 }
Kojto 20:30b6ed7bf8fd 92
Kojto 20:30b6ed7bf8fd 93 uint16_t cc3000_simple_link::get_pending_data() {
Kojto 20:30b6ed7bf8fd 94 return _rx_data_pending;
Kojto 20:30b6ed7bf8fd 95 }
Kojto 20:30b6ed7bf8fd 96
Kojto 20:30b6ed7bf8fd 97 void cc3000_simple_link::set_number_free_buffers(uint16_t value) {
Kojto 20:30b6ed7bf8fd 98 _free_buffers = value;
Kojto 20:30b6ed7bf8fd 99 }
Kojto 20:30b6ed7bf8fd 100
Kojto 20:30b6ed7bf8fd 101 void cc3000_simple_link::set_number_of_released_packets(uint16_t value) {
Kojto 20:30b6ed7bf8fd 102 _released_packets = value;
Kojto 20:30b6ed7bf8fd 103 }
Kojto 20:30b6ed7bf8fd 104
Kojto 20:30b6ed7bf8fd 105
Kojto 20:30b6ed7bf8fd 106 void cc3000_simple_link::set_tx_complete_signal(bool value) {
Kojto 20:30b6ed7bf8fd 107 _tx_complete_signal = value;
Kojto 20:30b6ed7bf8fd 108 }
Kojto 20:30b6ed7bf8fd 109
Kojto 20:30b6ed7bf8fd 110 bool cc3000_simple_link::get_tx_complete_signal() {
Kojto 20:30b6ed7bf8fd 111 return _tx_complete_signal;
Kojto 20:30b6ed7bf8fd 112 }
Kojto 20:30b6ed7bf8fd 113
Kojto 20:30b6ed7bf8fd 114 void cc3000_simple_link::set_data_received_flag(uint8_t value) {
Kojto 20:30b6ed7bf8fd 115 _data_received_flag = value;
Kojto 20:30b6ed7bf8fd 116 }
Kojto 20:30b6ed7bf8fd 117
Kojto 20:30b6ed7bf8fd 118 uint16_t cc3000_simple_link::get_number_free_buffers() {
Kojto 20:30b6ed7bf8fd 119 return _free_buffers;
Kojto 20:30b6ed7bf8fd 120 }
Kojto 20:30b6ed7bf8fd 121
Kojto 20:30b6ed7bf8fd 122 uint16_t cc3000_simple_link::get_buffer_length() {
Kojto 20:30b6ed7bf8fd 123 return _buffer_length;
Kojto 20:30b6ed7bf8fd 124 }
Kojto 20:30b6ed7bf8fd 125
Kojto 20:30b6ed7bf8fd 126 void cc3000_simple_link::set_buffer_length(uint16_t value) {
Kojto 20:30b6ed7bf8fd 127 _buffer_length = value;
Kojto 20:30b6ed7bf8fd 128 }
Kojto 20:30b6ed7bf8fd 129
Kojto 20:30b6ed7bf8fd 130 uint16_t cc3000_simple_link::get_op_code() {
Kojto 20:30b6ed7bf8fd 131 return _rx_event_opcode;
Kojto 20:30b6ed7bf8fd 132 }
Kojto 20:30b6ed7bf8fd 133
Kojto 20:30b6ed7bf8fd 134 uint16_t cc3000_simple_link::get_released_packets() {
Kojto 20:30b6ed7bf8fd 135 return _released_packets;
Kojto 20:30b6ed7bf8fd 136 }
Kojto 20:30b6ed7bf8fd 137
Kojto 20:30b6ed7bf8fd 138 uint16_t cc3000_simple_link::get_sent_packets() {
Kojto 20:30b6ed7bf8fd 139 return _sent_packets;
Kojto 20:30b6ed7bf8fd 140 }
Kojto 20:30b6ed7bf8fd 141
Kojto 20:30b6ed7bf8fd 142 void cc3000_simple_link::set_sent_packets(uint16_t value) {
Kojto 20:30b6ed7bf8fd 143 _sent_packets = value;
Kojto 20:30b6ed7bf8fd 144 }
Kojto 20:30b6ed7bf8fd 145
Kojto 20:30b6ed7bf8fd 146 void cc3000_simple_link::set_transmit_error(int32_t value){
Kojto 20:30b6ed7bf8fd 147 _transmit_data_error = value;
Kojto 20:30b6ed7bf8fd 148 }
Kojto 20:30b6ed7bf8fd 149
Kojto 20:30b6ed7bf8fd 150 int32_t cc3000_simple_link::get_transmit_error(){
Kojto 20:30b6ed7bf8fd 151 return _transmit_data_error;
Kojto 20:30b6ed7bf8fd 152 }
Kojto 20:30b6ed7bf8fd 153
Kojto 20:30b6ed7bf8fd 154 void cc3000_simple_link::set_buffer_size(uint16_t value) {
Kojto 20:30b6ed7bf8fd 155 _buffer_size = value;
Kojto 20:30b6ed7bf8fd 156 }
Kojto 20:30b6ed7bf8fd 157
Kojto 20:30b6ed7bf8fd 158 uint16_t cc3000_simple_link::get_buffer_size(void) {
Kojto 20:30b6ed7bf8fd 159 return _buffer_size;
Kojto 20:30b6ed7bf8fd 160 }
Kojto 20:30b6ed7bf8fd 161
Kojto 20:30b6ed7bf8fd 162 uint8_t *cc3000_simple_link::get_received_data(void) {
Kojto 20:30b6ed7bf8fd 163 return _received_data;
Kojto 20:30b6ed7bf8fd 164 }
Kojto 20:30b6ed7bf8fd 165
Kojto 20:30b6ed7bf8fd 166 void cc3000_simple_link::set_received_data(uint8_t *pointer) {
Kojto 20:30b6ed7bf8fd 167 _received_data = pointer;
Kojto 20:30b6ed7bf8fd 168 }
Kojto 20:30b6ed7bf8fd 169
Kojto 45:50ab13d8f2dc 170 } // mbed_cc3000 namespace