Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers I2CTester.cpp Source File

I2CTester.cpp

00001 /*
00002  * Copyright (c) 2019, Arm Limited and affiliates.
00003  * SPDX-License-Identifier: Apache-2.0
00004  *
00005  * Licensed under the Apache License, Version 2.0 (the "License");
00006  * you may not use this file except in compliance with the License.
00007  * You may obtain a copy of the License at
00008  *
00009  * http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 
00018 #include "I2CTester.h"
00019 #include "fpga_config.h"
00020 
00021 uint8_t I2CTester::num_starts()
00022 {
00023     uint8_t num_starts = 0;
00024     read(TESTER_I2C_STARTS, &num_starts, sizeof(num_starts));
00025     return num_starts;
00026 }
00027 
00028 uint8_t I2CTester::num_stops()
00029 {
00030     uint8_t num_stops = 0;
00031     read(TESTER_I2C_STOPS, &num_stops, sizeof(num_stops));
00032     return num_stops;
00033 }
00034 
00035 uint16_t I2CTester::num_acks()
00036 {
00037     uint16_t num_acks = 0;
00038     read(TESTER_I2C_ACKS, (uint8_t *)&num_acks, sizeof(num_acks));
00039     return num_acks;
00040 }
00041 
00042 uint16_t I2CTester::num_nacks()
00043 {
00044     uint16_t num_nacks = 0;
00045     read(TESTER_I2C_NACKS, (uint8_t *)&num_nacks, sizeof(num_nacks));
00046     return num_nacks;
00047 }
00048 
00049 uint16_t I2CTester::transfer_count()
00050 {
00051     uint16_t transfers = 0;
00052     MBED_ASSERT(sizeof(transfers) == TESTER_I2C_TRANSFERS_SIZE);
00053     read(TESTER_I2C_TRANSFERS, (uint8_t *)&transfers, sizeof(transfers));
00054     return transfers;
00055 }
00056 
00057 uint32_t I2CTester::get_receive_checksum()
00058 {
00059     uint32_t to_slave_checksum = 0;
00060     MBED_ASSERT(sizeof(to_slave_checksum) == TESTER_I2C_TO_SLAVE_CHECKSUM_SIZE);
00061     read(TESTER_I2C_TO_SLAVE_CHECKSUM, (uint8_t *)&to_slave_checksum, sizeof(to_slave_checksum));
00062     return to_slave_checksum;
00063 }
00064 
00065 uint32_t I2CTester::get_send_checksum()
00066 {
00067     uint32_t from_slave_checksum = 0;
00068     MBED_ASSERT(sizeof(from_slave_checksum) == TESTER_I2C_FROM_SLAVE_CHECKSUM_SIZE);
00069     read(TESTER_I2C_FROM_SLAVE_CHECKSUM, (uint8_t *)&from_slave_checksum, sizeof(from_slave_checksum));
00070     return from_slave_checksum;
00071 }
00072 
00073 uint8_t I2CTester::state_num()
00074 {
00075     uint8_t state_num = 0;
00076     read(TESTER_I2C_STATE_NUM, &state_num, sizeof(state_num));
00077     return state_num;
00078 }
00079 
00080 uint8_t I2CTester::num_dev_addr_matches()
00081 {
00082     uint8_t num_dev_addr_matches = 0;
00083     read(TESTER_I2C_NUMBER_DEV_ADDR_MATCHES, &num_dev_addr_matches, sizeof(num_dev_addr_matches));
00084     return num_dev_addr_matches;
00085 }
00086 
00087 uint8_t I2CTester::num_dev_addr_mismatches()
00088 {
00089     uint8_t num_dev_addr_mismatches = 0;
00090     read(TESTER_I2C_NUMBER_DEV_ADDR_MISMATCHES, &num_dev_addr_mismatches, sizeof(num_dev_addr_mismatches));
00091     return num_dev_addr_mismatches;
00092 }
00093 
00094 void I2CTester::set_device_address(uint16_t addr)
00095 {
00096     uint16_t data = addr;
00097     write(TESTER_I2C_DEVICE_ADDRESS, (uint8_t *)&data, sizeof(data));
00098 }
00099 
00100 uint16_t I2CTester::get_device_address()
00101 {
00102     uint16_t addr = 0;
00103     read(TESTER_I2C_DEVICE_ADDRESS, (uint8_t *)&addr, sizeof(addr));
00104     return addr;
00105 }
00106 
00107 void I2CTester::set_sda(uint8_t value)
00108 {
00109     uint8_t val = value;
00110     write(TESTER_I2C_SET_SDA, &val, sizeof(val));
00111 }
00112 
00113 uint8_t I2CTester::get_prev_to_slave_4()
00114 {
00115     uint8_t prev_to_slave_4 = 0;
00116     read(TESTER_I2C_PREV_TO_SLAVE_4, &prev_to_slave_4, sizeof(prev_to_slave_4));
00117     return prev_to_slave_4;
00118 }
00119 uint8_t I2CTester::get_prev_to_slave_3()
00120 {
00121     uint8_t prev_to_slave_3 = 0;
00122     read(TESTER_I2C_PREV_TO_SLAVE_3, &prev_to_slave_3, sizeof(prev_to_slave_3));
00123     return prev_to_slave_3;
00124 }
00125 uint8_t I2CTester::get_prev_to_slave_2()
00126 {
00127     uint8_t prev_to_slave_2 = 0;
00128     read(TESTER_I2C_PREV_TO_SLAVE_2, &prev_to_slave_2, sizeof(prev_to_slave_2));
00129     return prev_to_slave_2;
00130 }
00131 uint8_t I2CTester::get_prev_to_slave_1()
00132 {
00133     uint8_t prev_to_slave_1 = 0;
00134     read(TESTER_I2C_PREV_TO_SLAVE_1, &prev_to_slave_1, sizeof(prev_to_slave_1));
00135     return prev_to_slave_1;
00136 }
00137 void I2CTester::set_next_from_slave(uint8_t value)
00138 {
00139     uint8_t val = value;
00140     write(TESTER_I2C_NEXT_FROM_SLAVE, &val, sizeof(val));
00141 }
00142 uint8_t I2CTester::get_next_from_slave()
00143 {
00144     uint8_t next_from_slave = 0;
00145     read(TESTER_I2C_NEXT_FROM_SLAVE, &next_from_slave, sizeof(next_from_slave));
00146     return next_from_slave;
00147 }
00148 uint16_t I2CTester::num_writes()
00149 {
00150     uint16_t num_writes = 0;
00151     read(TESTER_I2C_NUM_WRITES, (uint8_t *)&num_writes, sizeof(num_writes));
00152     return num_writes;
00153 }
00154 uint16_t I2CTester::num_reads()
00155 {
00156     uint16_t num_reads = 0;
00157     read(TESTER_I2C_NUM_READS, (uint8_t *)&num_reads, sizeof(num_reads));
00158     return num_reads;
00159 }