Implementation of 1-Wire with added Alarm Search Functionality

Dependents:   Max32630_One_Wire_Interface

Committer:
mfruge
Date:
Tue Aug 13 14:42:37 2019 +0000
Revision:
142:85b71cfd617e
Parent:
140:6f32bf635c9d
Added functions to ROMCommands to add Alarm Search functionality

Who changed what in which revision?

UserRevisionLine numberNew contents of line
j3 140:6f32bf635c9d 1 /******************************************************************//**
j3 140:6f32bf635c9d 2 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
j3 140:6f32bf635c9d 3 *
j3 140:6f32bf635c9d 4 * Permission is hereby granted, free of charge, to any person obtaining a
j3 140:6f32bf635c9d 5 * copy of this software and associated documentation files (the "Software"),
j3 140:6f32bf635c9d 6 * to deal in the Software without restriction, including without limitation
j3 140:6f32bf635c9d 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
j3 140:6f32bf635c9d 8 * and/or sell copies of the Software, and to permit persons to whom the
j3 140:6f32bf635c9d 9 * Software is furnished to do so, subject to the following conditions:
j3 140:6f32bf635c9d 10 *
j3 140:6f32bf635c9d 11 * The above copyright notice and this permission notice shall be included
j3 140:6f32bf635c9d 12 * in all copies or substantial portions of the Software.
j3 140:6f32bf635c9d 13 *
j3 140:6f32bf635c9d 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
j3 140:6f32bf635c9d 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
j3 140:6f32bf635c9d 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
j3 140:6f32bf635c9d 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
j3 140:6f32bf635c9d 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
j3 140:6f32bf635c9d 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
j3 140:6f32bf635c9d 20 * OTHER DEALINGS IN THE SOFTWARE.
j3 140:6f32bf635c9d 21 *
j3 140:6f32bf635c9d 22 * Except as contained in this notice, the name of Maxim Integrated
j3 140:6f32bf635c9d 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
j3 140:6f32bf635c9d 24 * Products, Inc. Branding Policy.
j3 140:6f32bf635c9d 25 *
j3 140:6f32bf635c9d 26 * The mere transfer of this software does not imply any licenses
j3 140:6f32bf635c9d 27 * of trade secrets, proprietary technology, copyrights, patents,
j3 140:6f32bf635c9d 28 * trademarks, maskwork rights, or any other form of intellectual
j3 140:6f32bf635c9d 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
j3 140:6f32bf635c9d 30 * ownership rights.
j3 140:6f32bf635c9d 31 **********************************************************************/
j3 140:6f32bf635c9d 32
j3 140:6f32bf635c9d 33 #if defined(TARGET_MAX32620) || defined(TARGET_MAX32625) || defined(TARGET_MAX32630)
j3 140:6f32bf635c9d 34
j3 140:6f32bf635c9d 35 #include "MCU_OWM.h"
j3 140:6f32bf635c9d 36
j3 140:6f32bf635c9d 37 using namespace OneWire;
j3 140:6f32bf635c9d 38
j3 140:6f32bf635c9d 39 MCU_OWM::MCU_OWM(bool extWeakPup, bool extStrongPup)
j3 140:6f32bf635c9d 40 {
j3 140:6f32bf635c9d 41 m_sysCfgOwm.clk_scale = CLKMAN_SCALE_AUTO;
j3 140:6f32bf635c9d 42
j3 140:6f32bf635c9d 43 if(extStrongPup)
j3 140:6f32bf635c9d 44 {
j3 140:6f32bf635c9d 45 m_owmCfg.ext_pu_mode = OWM_EXT_PU_ACT_LOW;
j3 140:6f32bf635c9d 46 ioman_cfg_t cfg = IOMAN_OWM(1, 1);
j3 140:6f32bf635c9d 47 m_sysCfgOwm.io_cfg = cfg;
j3 140:6f32bf635c9d 48 }
j3 140:6f32bf635c9d 49 else
j3 140:6f32bf635c9d 50 {
j3 140:6f32bf635c9d 51 m_owmCfg.ext_pu_mode = OWM_EXT_PU_UNUSED;
j3 140:6f32bf635c9d 52 ioman_cfg_t cfg = IOMAN_OWM(1, 0);
j3 140:6f32bf635c9d 53 m_sysCfgOwm.io_cfg = cfg;
j3 140:6f32bf635c9d 54 }
j3 140:6f32bf635c9d 55
j3 140:6f32bf635c9d 56 if(extWeakPup)
j3 140:6f32bf635c9d 57 {
j3 140:6f32bf635c9d 58 m_owmCfg.int_pu_en = 0;
j3 140:6f32bf635c9d 59 }
j3 140:6f32bf635c9d 60 else
j3 140:6f32bf635c9d 61 {
j3 140:6f32bf635c9d 62 m_owmCfg.int_pu_en = 1;
j3 140:6f32bf635c9d 63 }
j3 140:6f32bf635c9d 64
j3 140:6f32bf635c9d 65 m_owmCfg.long_line_mode = 0;
j3 140:6f32bf635c9d 66 m_owmCfg.overdrive_spec = OWM_OVERDRIVE_UNUSED;
j3 140:6f32bf635c9d 67 }
j3 140:6f32bf635c9d 68
j3 140:6f32bf635c9d 69 //**********************************************************************
j3 140:6f32bf635c9d 70 bool MCU_OWM::extStrongPup() const
j3 140:6f32bf635c9d 71 {
j3 140:6f32bf635c9d 72 return m_owmCfg.ext_pu_mode == OWM_EXT_PU_ACT_LOW;
j3 140:6f32bf635c9d 73 }
j3 140:6f32bf635c9d 74
j3 140:6f32bf635c9d 75 //**********************************************************************
j3 140:6f32bf635c9d 76 OneWireMaster::CmdResult MCU_OWM::OWInitMaster()
j3 140:6f32bf635c9d 77 {
j3 140:6f32bf635c9d 78 OneWireMaster::CmdResult result = OneWireMaster::OperationFailure;
j3 140:6f32bf635c9d 79
j3 140:6f32bf635c9d 80 if(OWM_Init(MXC_OWM, &m_owmCfg, &m_sysCfgOwm) == E_NO_ERROR)
j3 140:6f32bf635c9d 81 {
j3 140:6f32bf635c9d 82 result = OneWireMaster::Success;
j3 140:6f32bf635c9d 83 }
j3 140:6f32bf635c9d 84
j3 140:6f32bf635c9d 85 return result;
j3 140:6f32bf635c9d 86 }
j3 140:6f32bf635c9d 87
j3 140:6f32bf635c9d 88 //**********************************************************************
j3 140:6f32bf635c9d 89 OneWireMaster::CmdResult MCU_OWM::OWReset()
j3 140:6f32bf635c9d 90 {
j3 140:6f32bf635c9d 91 OneWireMaster::CmdResult result = OneWireMaster::OperationFailure;
j3 140:6f32bf635c9d 92
j3 140:6f32bf635c9d 93 if(OWM_Reset(MXC_OWM))
j3 140:6f32bf635c9d 94 {
j3 140:6f32bf635c9d 95 result = OneWireMaster::Success;
j3 140:6f32bf635c9d 96 }
j3 140:6f32bf635c9d 97 return result;
j3 140:6f32bf635c9d 98 }
j3 140:6f32bf635c9d 99
j3 140:6f32bf635c9d 100 //**********************************************************************
j3 140:6f32bf635c9d 101 OneWireMaster::CmdResult MCU_OWM::OWTouchBitSetLevel(uint8_t & sendRecvBit, OWLevel afterLevel)
j3 140:6f32bf635c9d 102 {
j3 140:6f32bf635c9d 103 OneWireMaster::CmdResult result = OneWireMaster::OperationFailure;
j3 140:6f32bf635c9d 104
j3 140:6f32bf635c9d 105 sendRecvBit = OWM_TouchBit(MXC_OWM, sendRecvBit);
j3 140:6f32bf635c9d 106
j3 140:6f32bf635c9d 107 if(extStrongPup())
j3 140:6f32bf635c9d 108 {
j3 140:6f32bf635c9d 109 result = OWSetLevel(afterLevel);
j3 140:6f32bf635c9d 110 }
j3 140:6f32bf635c9d 111 else
j3 140:6f32bf635c9d 112 {
j3 140:6f32bf635c9d 113 result = OneWireMaster::Success;
j3 140:6f32bf635c9d 114 }
j3 140:6f32bf635c9d 115
j3 140:6f32bf635c9d 116 return result;
j3 140:6f32bf635c9d 117 }
j3 140:6f32bf635c9d 118
j3 140:6f32bf635c9d 119 //**********************************************************************
j3 140:6f32bf635c9d 120 OneWireMaster::CmdResult MCU_OWM::OWWriteByteSetLevel(uint8_t sendByte, OWLevel afterLevel)
j3 140:6f32bf635c9d 121 {
j3 140:6f32bf635c9d 122 OneWireMaster::CmdResult result = OneWireMaster::OperationFailure;
j3 140:6f32bf635c9d 123
j3 140:6f32bf635c9d 124 if(OWM_WriteByte(MXC_OWM, sendByte) == E_NO_ERROR)
j3 140:6f32bf635c9d 125 {
j3 140:6f32bf635c9d 126 if(extStrongPup())
j3 140:6f32bf635c9d 127 {
j3 140:6f32bf635c9d 128 result = OWSetLevel(afterLevel);
j3 140:6f32bf635c9d 129 }
j3 140:6f32bf635c9d 130 else
j3 140:6f32bf635c9d 131 {
j3 140:6f32bf635c9d 132 result = OneWireMaster::Success;
j3 140:6f32bf635c9d 133 }
j3 140:6f32bf635c9d 134 }
j3 140:6f32bf635c9d 135
j3 140:6f32bf635c9d 136 return result;
j3 140:6f32bf635c9d 137 }
j3 140:6f32bf635c9d 138
j3 140:6f32bf635c9d 139 //**********************************************************************
j3 140:6f32bf635c9d 140 OneWireMaster::CmdResult MCU_OWM::OWReadByteSetLevel(uint8_t & recvByte, OWLevel afterLevel)
j3 140:6f32bf635c9d 141 {
j3 140:6f32bf635c9d 142 OneWireMaster::CmdResult result = OneWireMaster::OperationFailure;
j3 140:6f32bf635c9d 143
j3 140:6f32bf635c9d 144 recvByte = OWM_ReadByte(MXC_OWM);
j3 140:6f32bf635c9d 145
j3 140:6f32bf635c9d 146 if(extStrongPup())
j3 140:6f32bf635c9d 147 {
j3 140:6f32bf635c9d 148 result = OWSetLevel(afterLevel);
j3 140:6f32bf635c9d 149 }
j3 140:6f32bf635c9d 150 else
j3 140:6f32bf635c9d 151 {
j3 140:6f32bf635c9d 152 result = OneWireMaster::Success;
j3 140:6f32bf635c9d 153 }
j3 140:6f32bf635c9d 154
j3 140:6f32bf635c9d 155 return result;
j3 140:6f32bf635c9d 156 }
j3 140:6f32bf635c9d 157
j3 140:6f32bf635c9d 158 //**********************************************************************
j3 140:6f32bf635c9d 159 OneWireMaster::CmdResult MCU_OWM::OWSetSpeed(OWSpeed newSpeed)
j3 140:6f32bf635c9d 160 {
j3 140:6f32bf635c9d 161 OneWireMaster::CmdResult result = OneWireMaster::Success;
j3 140:6f32bf635c9d 162
j3 140:6f32bf635c9d 163 if(newSpeed == OneWireMaster::OverdriveSpeed)
j3 140:6f32bf635c9d 164 {
j3 140:6f32bf635c9d 165 OWM_SetOverdrive(MXC_OWM, 1);
j3 140:6f32bf635c9d 166 }
j3 140:6f32bf635c9d 167 else if(newSpeed == OneWireMaster::StandardSpeed)
j3 140:6f32bf635c9d 168 {
j3 140:6f32bf635c9d 169 OWM_SetOverdrive(MXC_OWM, 0);
j3 140:6f32bf635c9d 170 }
j3 140:6f32bf635c9d 171 else
j3 140:6f32bf635c9d 172 {
j3 140:6f32bf635c9d 173 result = OneWireMaster::OperationFailure;
j3 140:6f32bf635c9d 174 }
j3 140:6f32bf635c9d 175
j3 140:6f32bf635c9d 176 return result;
j3 140:6f32bf635c9d 177 }
j3 140:6f32bf635c9d 178
j3 140:6f32bf635c9d 179 //**********************************************************************
j3 140:6f32bf635c9d 180 OneWireMaster::CmdResult MCU_OWM::OWSetLevel(OWLevel newLevel)
j3 140:6f32bf635c9d 181 {
j3 140:6f32bf635c9d 182 OneWireMaster::CmdResult result = OneWireMaster::OperationFailure;
j3 140:6f32bf635c9d 183
j3 140:6f32bf635c9d 184 if(extStrongPup())
j3 140:6f32bf635c9d 185 {
j3 140:6f32bf635c9d 186 if(newLevel == OneWireMaster::StrongLevel)
j3 140:6f32bf635c9d 187 {
j3 140:6f32bf635c9d 188 OWM_SetExtPullup(MXC_OWM, 1);
j3 140:6f32bf635c9d 189 }
j3 140:6f32bf635c9d 190 else
j3 140:6f32bf635c9d 191 {
j3 140:6f32bf635c9d 192 OWM_SetExtPullup(MXC_OWM, 0);
j3 140:6f32bf635c9d 193 }
j3 140:6f32bf635c9d 194
j3 140:6f32bf635c9d 195 result = OneWireMaster::Success;
j3 140:6f32bf635c9d 196 }
j3 140:6f32bf635c9d 197
j3 140:6f32bf635c9d 198 return result;
j3 140:6f32bf635c9d 199 }
j3 140:6f32bf635c9d 200
j3 140:6f32bf635c9d 201 #endif /* TARGET_MAX326xx */
j3 140:6f32bf635c9d 202