Linduino  1.3.0
Linear Technology Arduino-Compatible Demonstration Board
LT_PMBusSpeedTest.cpp
Go to the documentation of this file.
1 /*!
2 LTC LT_PMBusSpeedTest
3 
4 @verbatim
5 
6 Check bus speed capability.
7 
8 @endverbatim
9 
10 
11 Copyright 2018(c) Analog Devices, Inc.
12 
13 All rights reserved.
14 
15 Redistribution and use in source and binary forms, with or without
16 modification, are permitted provided that the following conditions are met:
17  - Redistributions of source code must retain the above copyright
18  notice, this list of conditions and the following disclaimer.
19  - Redistributions in binary form must reproduce the above copyright
20  notice, this list of conditions and the following disclaimer in
21  the documentation and/or other materials provided with the
22  distribution.
23  - Neither the name of Analog Devices, Inc. nor the names of its
24  contributors may be used to endorse or promote products derived
25  from this software without specific prior written permission.
26  - The use of this software may or may not infringe the patent rights
27  of one or more patent holders. This license does not release you
28  from the requirement that you obtain separate licenses from these
29  patent holders to use this software.
30  - Use of the software either in source or binary form, must be run
31  on or directly connected to an Analog Devices Inc. component.
32 
33 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
34 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
35 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
36 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
37 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
38 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
39 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
40 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
41 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
42 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43 */
44 
45 /*! @file
46  @ingroup LT_PMBusDevice
47  Library Header File for LT_PMBusSpeedTest
48 */
49 
50 #include "LT_PMBusSpeedTest.h"
51 
53 {
54 }
55 
56 uint32_t LT_PMBusSpeedTest::test(uint8_t address, uint8_t tries)
57 {
58  bool nok;
59 
61  i2cbus->changeSpeed(400000);
62  nok = false;
63  for (int i = 0; i < tries; i++)
64  {
65  pmbus_->setPage(address, 0x00);
66  nok |= pmbus_->getPage(address) != 0x00;
67  if (nok) break;
68  pmbus_->setPage(address, 0xFF);
69  nok |= pmbus_->getPage(address) != 0xFF;
70  if (nok) break;
71  }
72  if (!nok) return 400000;
73 
74  i2cbus->changeSpeed(100000);
75  nok = false;
76  for (int i = 0; i < tries; i++)
77  {
78  pmbus_->setPage(address, 0x00);
79  nok |= pmbus_->getPage(address) != 0x00;
80  if (nok) break;
81  pmbus_->setPage(address, 0xFF);
82  nok |= pmbus_->getPage(address) != 0xFF;
83  if (nok) break;
84  }
85  if (!nok) return 100000;
86 
87  // Arduino Mega did not run at 10kHz.
88  i2cbus->changeSpeed(20000);
89  nok = false;
90  for (int i = 0; i < tries; i++)
91  {
92  pmbus_->setPage(address, 0x00);
93  nok |= pmbus_->getPage(address) != 0x00;
94  if (nok) break;
95  pmbus_->setPage(address, 0xFF);
96  nok |= pmbus_->getPage(address) != 0xFF;
97  if (nok) break;
98  }
99  if (!nok) return 10000;
100  return 0;
101 }
uint8_t getPage(uint8_t address)
Get the page.
Definition: LT_PMBus.cpp:3167
static LT_PMBus * pmbus
Definition: DC2875A.ino:82
static uint8_t address
Definition: DC2091A.ino:83
void changeSpeed(uint32_t speed)
Change the speed of the bus.
Definition: LT_I2CBus.cpp:73
void setPage(uint8_t address, uint8_t page)
Set the page.
Definition: LT_PMBus.cpp:3156
static LT_I2CBus * i2cbus
Definition: sandbox.ino:74
LT_SMBus * smbus()
Definition: LT_PMBus.h:401
virtual LT_I2CBus * i2cbus(void)=0
uint32_t test(uint8_t address, uint8_t tries)
LTC PSM SpeedTest.
static int i
Definition: DC2430A.ino:184
LT_PMBusSpeedTest(LT_PMBus *pmbus)
PMBus communication.
Definition: LT_PMBus.h:370