1-Wire and ENS210 driver stack
DS2485_port_maxim.c
Go to the documentation of this file.
1 /**
2  * @file DS2485_port_maxim.c
3  * @brief Platform-specific interface used to drive the DS2485 over I2C in the original Maxim environment.
4  *
5  * @par Update history
6  * 18-May-2023 Dave Nadler Isolated platform-dependent code in this source file.
7  *
8  * @note This implementation is not used in the SensorBox/Vario application.
9  */
10 
11 /*******************************************************************************
12 * Copyright (C) Maxim Integrated Products, Inc., All rights Reserved.
13 *
14 * This software is protected by copyright laws of the United States and
15 * of foreign countries. This material may also be protected by patent laws
16 * and technology transfer regulations of the United States and of foreign
17 * countries. This software is furnished under a license agreement and/or a
18 * nondisclosure agreement and may only be used or reproduced in accordance
19 * with the terms of those agreements. Dissemination of this information to
20 * any party or parties not specified in the license agreement and/or
21 * nondisclosure agreement is expressly prohibited.
22 *
23 * The above copyright notice and this permission notice shall be included
24 * in all copies or substantial portions of the Software.
25 *
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
27 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
29 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
30 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
31 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
32 * OTHER DEALINGS IN THE SOFTWARE.
33 *
34 * Except as contained in this notice, the name of Maxim Integrated
35 * Products, Inc. shall not be used except as stated in the Maxim Integrated
36 * Products, Inc. Branding Policy.
37 *
38 * The mere transfer of this software does not imply any licenses
39 * of trade secrets, proprietary technology, copyrights, patents,
40 * trademarks, maskwork rights, or any other form of intellectual
41 * property whatsoever. Maxim Integrated Products, Inc. retains all
42 * ownership rights.
43 *******************************************************************************
44 */
45 
46 /* **** Includes **** */
47 #include <stdint.h>
48 #include <string.h> // memcpy...
49 
50 #if 1 // Maxim-specific
51  #include "i2c.h"
52  #include "mxc_delay.h"
53  #include "mxc_sys.h"
54  #include "tmr.h"
55  #include "mxc_config.h"
56 #endif
57 
58 #include "DS2485.h"
59 
60 /* **** Definitions **** */
61 #define I2C_MASTER MXC_I2C0
62 #define I2C_MASTER_IDX 0
63 #define I2C_SLAVE_ADDR (DS2485_I2C_7BIT_ADDRESS << 1)
64 
65 /* **** Globals **** */
66 
67 /* **** Functions **** */
68 int DS2485_ExecuteCommand(const uint8_t *packet, int packetSize, int delay_uSec, uint8_t *response, int responseSize)
69 {
70  int error = 0;
71  const sys_cfg_i2c_t sys_i2c_cfg = NULL;
72 
73  //Setup the I2C Master
74  I2C_Shutdown(I2C_MASTER);
75  if((error = I2C_Init(I2C_MASTER, I2C_STD_MODE, &sys_i2c_cfg)) != E_NO_ERROR) {
76  return error;
77  }
78 
79  if((error = I2C_MasterWrite(MXC_I2C0, I2C_SLAVE_ADDR, packet, packetSize, 0)) != packetSize) {
80  return error;
81  }
82 
83  mxc_delay(MXC_DELAY_MSEC(delay_uSec));
84 
85  //Read out Length Byte
86  if((error = I2C_MasterRead(MXC_I2C0, I2C_SLAVE_ADDR, response, responseSize, 0)) != responseSize) {
87  return error;
88  }
89 
90  return 0;
91 }
int DS2485_ExecuteCommand(const uint8_t *packet, int packetSize, int delay_uSec, uint8_t *response, int responseSize)
Platform-specific I2C command interface implemented in DS2485_port_xxxx.c Returns &#39;error&#39; (0 if compl...
General library for the DS2485, supporting the higher-level one_wire.c/.h API.