mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Tue Jun 30 09:45:08 2015 +0100
Revision:
576:99a3d3d9c43f
Parent:
558:0880f51c4036
Child:
601:248b0d2dd755
Synchronized with git revision 1c13bc80fedd0fdfaedfab5c33183dc2b6f9b1bb

Full URL: https://github.com/mbedmicro/mbed/commit/1c13bc80fedd0fdfaedfab5c33183dc2b6f9b1bb/

Wiznet - Update and bug fix.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 576:99a3d3d9c43f 1 /* mbed Microcontroller Library
mbed_official 576:99a3d3d9c43f 2 *******************************************************************************
mbed_official 576:99a3d3d9c43f 3 * Copyright (c) 2015 WIZnet Co.,Ltd. All rights reserved.
mbed_official 576:99a3d3d9c43f 4 * All rights reserved.
mbed_official 576:99a3d3d9c43f 5 *
mbed_official 576:99a3d3d9c43f 6 * Redistribution and use in source and binary forms, with or without
mbed_official 576:99a3d3d9c43f 7 * modification, are permitted provided that the following conditions are met:
mbed_official 576:99a3d3d9c43f 8 *
mbed_official 576:99a3d3d9c43f 9 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 576:99a3d3d9c43f 10 * this list of conditions and the following disclaimer.
mbed_official 576:99a3d3d9c43f 11 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 576:99a3d3d9c43f 12 * this list of conditions and the following disclaimer in the documentation
mbed_official 576:99a3d3d9c43f 13 * and/or other materials provided with the distribution.
mbed_official 576:99a3d3d9c43f 14 * 3. Neither the name of ARM Limited nor the names of its contributors
mbed_official 576:99a3d3d9c43f 15 * may be used to endorse or promote products derived from this software
mbed_official 576:99a3d3d9c43f 16 * without specific prior written permission.
mbed_official 576:99a3d3d9c43f 17 *
mbed_official 576:99a3d3d9c43f 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 576:99a3d3d9c43f 19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 576:99a3d3d9c43f 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 576:99a3d3d9c43f 21 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 576:99a3d3d9c43f 22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 576:99a3d3d9c43f 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 576:99a3d3d9c43f 24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 576:99a3d3d9c43f 25 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 576:99a3d3d9c43f 26 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 576:99a3d3d9c43f 27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 576:99a3d3d9c43f 28 *******************************************************************************
mbed_official 576:99a3d3d9c43f 29 */
mbed_official 576:99a3d3d9c43f 30
mbed_official 558:0880f51c4036 31 #include "W7500x.h"
mbed_official 558:0880f51c4036 32
mbed_official 558:0880f51c4036 33 typedef enum
mbed_official 558:0880f51c4036 34 {
mbed_official 558:0880f51c4036 35 I2C_WRITE_SA7=0,
mbed_official 558:0880f51c4036 36 I2C_READ_SA7,
mbed_official 558:0880f51c4036 37 I2C_CTRWRITE_SA7,
mbed_official 558:0880f51c4036 38 I2C_CTRREAD_SA7,
mbed_official 558:0880f51c4036 39 } I2C_CTR;
mbed_official 558:0880f51c4036 40
mbed_official 558:0880f51c4036 41 typedef enum
mbed_official 558:0880f51c4036 42 {
mbed_official 558:0880f51c4036 43 I2C_ACKR=0,
mbed_official 558:0880f51c4036 44 I2C_ACKT,
mbed_official 558:0880f51c4036 45 I2C_OACKR,
mbed_official 558:0880f51c4036 46 I2C_SACKR,
mbed_official 558:0880f51c4036 47 I2C_BT,
mbed_official 558:0880f51c4036 48 } I2C_SR;
mbed_official 558:0880f51c4036 49
mbed_official 558:0880f51c4036 50
mbed_official 558:0880f51c4036 51 typedef enum
mbed_official 558:0880f51c4036 52 {
mbed_official 558:0880f51c4036 53 INT_ACKR=-1,
mbed_official 558:0880f51c4036 54 INT_ACKT=-2,
mbed_official 558:0880f51c4036 55 INT_NACKR=-3,
mbed_official 558:0880f51c4036 56 INT_NACKT=-4,
mbed_official 558:0880f51c4036 57 INT_BT=-5,
mbed_official 558:0880f51c4036 58 } I2C_ERROR;
mbed_official 558:0880f51c4036 59
mbed_official 558:0880f51c4036 60
mbed_official 558:0880f51c4036 61 /**
mbed_official 558:0880f51c4036 62 *@
mbed_official 558:0880f51c4036 63 */
mbed_official 558:0880f51c4036 64 /** @defgroup I2C_registers
mbed_official 558:0880f51c4036 65 * @{
mbed_official 558:0880f51c4036 66 */
mbed_official 558:0880f51c4036 67
mbed_official 558:0880f51c4036 68 #define I2C_Register_PRER ((uint8_t)0x00)
mbed_official 558:0880f51c4036 69 #define I2C_Register_CTR ((uint8_t)0x04)
mbed_official 558:0880f51c4036 70 #define I2C_Register_CMDR ((uint8_t)0x08)
mbed_official 558:0880f51c4036 71 #define I2C_Register_SR ((uint8_t)0x0C)
mbed_official 558:0880f51c4036 72 #define I2C_Register_TSR ((uint8_t)0x10)
mbed_official 558:0880f51c4036 73 #define I2C_Register_SADDR ((uint8_t)0x14)
mbed_official 558:0880f51c4036 74 #define I2C_Register_TXR ((uint8_t)0x18)
mbed_official 558:0880f51c4036 75 #define I2C_Register_RXR ((uint8_t)0x1C)
mbed_official 558:0880f51c4036 76 #define I2C_Register_ISR ((uint8_t)0x20)
mbed_official 558:0880f51c4036 77 #define I2C_Register_ISCR ((uint8_t)0x24)
mbed_official 558:0880f51c4036 78 #define I2C_Register_ISMR ((uint8_t)0x28)
mbed_official 558:0880f51c4036 79 #define IS_I2C_REGISTER(REGISTER) (((REGISTER) == I2C_Register_PRER) || \
mbed_official 558:0880f51c4036 80 ((REGISTER) == I2C_Register_CTR) || \
mbed_official 558:0880f51c4036 81 ((REGISTER) == I2C_Register_CMDR) || \
mbed_official 558:0880f51c4036 82 ((REGISTER) == I2C_Register_SR) || \
mbed_official 558:0880f51c4036 83 ((REGISTER) == I2C_Register_TSR) || \
mbed_official 558:0880f51c4036 84 ((REGISTER) == I2C_Register_SADDR) || \
mbed_official 558:0880f51c4036 85 ((REGISTER) == I2C_Register_TXR) || \
mbed_official 558:0880f51c4036 86 ((REGISTER) == I2C_Register_RXR) || \
mbed_official 558:0880f51c4036 87 ((REGISTER) == I2C_Register_ISR)|| \
mbed_official 558:0880f51c4036 88 ((REGISTER) == I2C_Register_ISCR)| \
mbed_official 558:0880f51c4036 89 ((REGISTER) == I2C_Register_ISMR))
mbed_official 558:0880f51c4036 90
mbed_official 558:0880f51c4036 91 /** @defgroup I2C_Private_Defines
mbed_official 558:0880f51c4036 92 * @{
mbed_official 558:0880f51c4036 93 */
mbed_official 558:0880f51c4036 94 /* I2C COREEN mask */
mbed_official 558:0880f51c4036 95 #define I2C_CTR_COREEN_DIS ((uint16_t)0xFF7F)
mbed_official 558:0880f51c4036 96
mbed_official 558:0880f51c4036 97 /* I2C INTEREN mask */
mbed_official 558:0880f51c4036 98 #define I2C_CTR_INTEREN_DIS ((uint16_t)0xFFBF)
mbed_official 558:0880f51c4036 99
mbed_official 558:0880f51c4036 100 /* I2C MODE(M/SN) mask */
mbed_official 558:0880f51c4036 101 #define I2C_CTR_MODE_SLAVE ((uint16_t)0xFFDF)
mbed_official 558:0880f51c4036 102
mbed_official 558:0880f51c4036 103 /* I2C ADDR10(10/7N) mask */
mbed_official 558:0880f51c4036 104 #define I2C_CTR_ADDR10_7BIT ((uint16_t)0xFFEF)
mbed_official 558:0880f51c4036 105
mbed_official 558:0880f51c4036 106 /* I2C CTRRWN(R/WN) mask */
mbed_official 558:0880f51c4036 107 #define I2C_CTR_CTRRWN_DIS ((uint16_t)0xFFF7)
mbed_official 558:0880f51c4036 108
mbed_official 558:0880f51c4036 109 /* I2C CTREN mask */
mbed_official 558:0880f51c4036 110 #define I2C_CTR_CTEN_DIS ((uint16_t)0xFFFB)
mbed_official 558:0880f51c4036 111
mbed_official 558:0880f51c4036 112
mbed_official 558:0880f51c4036 113 /* I2C START mask */
mbed_official 558:0880f51c4036 114 #define I2C_CMDR_START_DIS ((uint16_t)0xFF7F)
mbed_official 558:0880f51c4036 115
mbed_official 558:0880f51c4036 116 /* I2C STOP mask */
mbed_official 558:0880f51c4036 117 #define I2C_CMDR_STOP_DIS ((uint16_t)0xFFBF)
mbed_official 558:0880f51c4036 118
mbed_official 558:0880f51c4036 119 /* I2C ACK mask */
mbed_official 558:0880f51c4036 120 #define I2C_CMDR_ACK_NAK ((uint16_t)0xFFDF)
mbed_official 558:0880f51c4036 121
mbed_official 558:0880f51c4036 122 /* I2C RESTART mask */
mbed_official 558:0880f51c4036 123 #define I2C_CMDR_RESTA_DIS ((uint16_t)0xFFEF)
mbed_official 558:0880f51c4036 124
mbed_official 558:0880f51c4036 125 /* I2C INTERRUPT RESET mask */
mbed_official 558:0880f51c4036 126 #define I2C_ISCR_RST_DIS ((uint16_t)0xFFFE)
mbed_official 558:0880f51c4036 127 /**
mbed_official 558:0880f51c4036 128 * @}
mbed_official 558:0880f51c4036 129 */
mbed_official 558:0880f51c4036 130
mbed_official 558:0880f51c4036 131
mbed_official 558:0880f51c4036 132
mbed_official 558:0880f51c4036 133 #define I2C_WRITE 0
mbed_official 558:0880f51c4036 134 #define I2C_READ 1
mbed_official 558:0880f51c4036 135 #define I2C_RWSEL(NewState) (((NewState) == I2C_WRITE)|| \
mbed_official 558:0880f51c4036 136 ((NewState) == I2C_READ))
mbed_official 558:0880f51c4036 137
mbed_official 558:0880f51c4036 138
mbed_official 558:0880f51c4036 139 #define I2C_Ack_Enable (0x01ul << 5)
mbed_official 558:0880f51c4036 140 #define I2C_Ack_Disable (0x00ul << 5)
mbed_official 558:0880f51c4036 141 #define IS_I2C_ACK_NewState(NewState) (((NewState) == I2C_Ack_Enable) || \
mbed_official 558:0880f51c4036 142 ((NewState) == I2C_Ack_Disable))
mbed_official 558:0880f51c4036 143
mbed_official 558:0880f51c4036 144 #define I2C_MASTER_MODE (0x01ul << 5 ) // 0x20
mbed_official 558:0880f51c4036 145 #define I2C_SLAVE_MODE (0x00ul << 5 ) // 0x20
mbed_official 558:0880f51c4036 146 #define IS_I2C_MODE(MODE) ((MODE) == I2C_MASTER_MODE)|| \
mbed_official 558:0880f51c4036 147 (MODE) == I2C_SLAVE_MODE))
mbed_official 558:0880f51c4036 148
mbed_official 558:0880f51c4036 149 #define I2C_CTR_MODE (0x01ul << 5 ) // 0x20
mbed_official 558:0880f51c4036 150
mbed_official 558:0880f51c4036 151 #define SLAVE_ADDR10 0x208
mbed_official 558:0880f51c4036 152
mbed_official 558:0880f51c4036 153
mbed_official 558:0880f51c4036 154 typedef enum
mbed_official 558:0880f51c4036 155 {
mbed_official 558:0880f51c4036 156 I2C_Master = I2C_MASTER_MODE,
mbed_official 558:0880f51c4036 157 I2C_Slave = I2C_SLAVE_MODE
mbed_official 558:0880f51c4036 158 }I2C_MODE;
mbed_official 558:0880f51c4036 159
mbed_official 558:0880f51c4036 160
mbed_official 558:0880f51c4036 161 typedef struct
mbed_official 558:0880f51c4036 162 {
mbed_official 558:0880f51c4036 163 uint8_t prescale;
mbed_official 558:0880f51c4036 164 uint16_t timeout;
mbed_official 558:0880f51c4036 165 I2C_CTR control;
mbed_official 558:0880f51c4036 166 }I2C_MasterConfStruct;
mbed_official 558:0880f51c4036 167
mbed_official 558:0880f51c4036 168
mbed_official 558:0880f51c4036 169 typedef struct
mbed_official 558:0880f51c4036 170 {
mbed_official 558:0880f51c4036 171 uint32_t mode;
mbed_official 558:0880f51c4036 172 uint16_t slave_address; // only on slave mode
mbed_official 558:0880f51c4036 173 I2C_MasterConfStruct master;
mbed_official 558:0880f51c4036 174 }I2C_ConfigStruct;
mbed_official 558:0880f51c4036 175
mbed_official 558:0880f51c4036 176
mbed_official 558:0880f51c4036 177 /** @defgroup I2C_Exported_Functions
mbed_official 558:0880f51c4036 178 * @{
mbed_official 558:0880f51c4036 179 */
mbed_official 558:0880f51c4036 180
mbed_official 558:0880f51c4036 181 uint32_t I2C_Init (I2C_TypeDef* I2Cx, I2C_ConfigStruct conf);
mbed_official 558:0880f51c4036 182 void setFrequency (I2C_TypeDef* I2Cx, uint8_t prescale);
mbed_official 558:0880f51c4036 183 void I2C_DeInit (I2C_TypeDef* I2Cx);
mbed_official 558:0880f51c4036 184
mbed_official 558:0880f51c4036 185 ErrorStatus I2C_Start (I2C_TypeDef* I2Cx, uint16_t slave_address, I2C_CTR ctr);
mbed_official 558:0880f51c4036 186 void I2C_Stop (I2C_TypeDef* I2Cx);
mbed_official 558:0880f51c4036 187 void I2C_Reset (I2C_TypeDef* I2Cx);
mbed_official 558:0880f51c4036 188
mbed_official 558:0880f51c4036 189 void I2C_SendData (I2C_TypeDef* I2Cx,uint16_t Data);
mbed_official 558:0880f51c4036 190 int8_t I2C_SendDataAck (I2C_TypeDef* I2Cx,uint16_t Data);
mbed_official 558:0880f51c4036 191 int I2C_ReceiveData (I2C_TypeDef* I2Cx, int last);
mbed_official 558:0880f51c4036 192
mbed_official 558:0880f51c4036 193 int I2C_Burst_Read (I2C_TypeDef* I2Cx, uint16_t address, uint8_t *data, int length, int stop);
mbed_official 558:0880f51c4036 194 int I2C_Burst_Write (I2C_TypeDef* I2Cx, uint16_t address, uint8_t *data, int length, int stop);
mbed_official 558:0880f51c4036 195
mbed_official 558:0880f51c4036 196 void I2C_GenerateSTART (I2C_TypeDef* I2Cx, FunctionalState NewState);
mbed_official 558:0880f51c4036 197 void I2C_GenerateSTOP (I2C_TypeDef* I2Cx, FunctionalState NewState);
mbed_official 558:0880f51c4036 198
mbed_official 558:0880f51c4036 199 void I2C_AcknowledgeConfig (I2C_TypeDef* I2Cx, FunctionalState NewState);
mbed_official 558:0880f51c4036 200 void I2C_RESTART (I2C_TypeDef * I2Cx, FunctionalState NewState);
mbed_official 558:0880f51c4036 201
mbed_official 558:0880f51c4036 202 void I2C_CoreEn (I2C_TypeDef* I2Cx,FunctionalState NewState);
mbed_official 558:0880f51c4036 203 void I2C_InterEn (I2C_TypeDef* I2Cx,FunctionalState NewState);
mbed_official 558:0880f51c4036 204 void I2C_MasterSlave(I2C_TypeDef* I2Cx,FunctionalState NewState);
mbed_official 558:0880f51c4036 205 void I2C_ControlRW (I2C_TypeDef* I2Cx,FunctionalState NewState);
mbed_official 558:0880f51c4036 206 void I2C_ControlEn (I2C_TypeDef* I2Cx,FunctionalState NewState);
mbed_official 558:0880f51c4036 207
mbed_official 558:0880f51c4036 208 void I2C_InterRst (I2C_TypeDef* I2Cx,FunctionalState NewState);
mbed_official 558:0880f51c4036 209 void I2C_Prescale (I2C_TypeDef* I2Cx,uint16_t Data);
mbed_official 558:0880f51c4036 210 void I2C_TimeoutSet (I2C_TypeDef* I2Cx,uint16_t Data);
mbed_official 558:0880f51c4036 211 void I2C_SetSlavAddress (I2C_TypeDef* I2Cx,uint16_t Data);
mbed_official 558:0880f51c4036 212 uint8_t I2C_StatusRead (I2C_TypeDef* I2Cx);
mbed_official 558:0880f51c4036 213
mbed_official 558:0880f51c4036 214 ErrorStatus I2C_CheckEvent(I2C_TypeDef* I2Cx,I2C_SR sr);
mbed_official 558:0880f51c4036 215
mbed_official 558:0880f51c4036 216 void I2C_MasterInit (I2C_TypeDef * I2Cx,uint8_t Prescale,uint16_t Timeout,I2C_CTR Ctr);
mbed_official 558:0880f51c4036 217 void I2C_SlaveInit (I2C_TypeDef * I2Cx,FunctionalState NewState, uint16_t data);
mbed_official 558:0880f51c4036 218 void I2C_SendSlaveAddress (I2C_TypeDef* I2Cx, uint8_t SlaveAddress,I2C_CTR Ctr);
mbed_official 558:0880f51c4036 219
mbed_official 558:0880f51c4036 220 int8_t I2C_Restart_Structure(I2C_TypeDef * I2Cx,uint32_t SlaveAddress,I2C_CTR Ctr);
mbed_official 558:0880f51c4036 221 uint16_t I2C_ReadRegister (I2C_TypeDef* I2Cx, uint8_t I2C_Register);
mbed_official 558:0880f51c4036 222
mbed_official 576:99a3d3d9c43f 223 void I2C_GPIO(void);
mbed_official 576:99a3d3d9c43f 224 void GPIO_I2C(void );
mbed_official 576:99a3d3d9c43f 225
mbed_official 576:99a3d3d9c43f 226 void WriteByte(uint8_t val);
mbed_official 576:99a3d3d9c43f 227
mbed_official 576:99a3d3d9c43f 228 void digitalWrite(GPIO_TypeDef* GPIOx,uint16_t pin, uint16_t val);
mbed_official 576:99a3d3d9c43f 229 uint16_t digitalRead(GPIO_TypeDef* GPIOx,uint16_t pin);
mbed_official 576:99a3d3d9c43f 230 void i2c_loop_us(int us);
mbed_official 576:99a3d3d9c43f 231 void i2c_loop_ms(int count) ;
mbed_official 576:99a3d3d9c43f 232
mbed_official 558:0880f51c4036 233 /**
mbed_official 558:0880f51c4036 234 * @}
mbed_official 558:0880f51c4036 235 */
mbed_official 558:0880f51c4036 236