Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
SPISlaveTester.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 "SPISlaveTester.h" 00019 #include "fpga_config.h" 00020 00021 uint16_t SPISlaveTester::get_transfer_count() 00022 { 00023 return SPITester::get_transfer_count(TESTER_SPI_SLAVE_TRANSFERS, TESTER_SPI_SLAVE_TRANSFERS_SIZE); 00024 } 00025 00026 uint32_t SPISlaveTester::get_receive_checksum() 00027 { 00028 return SPITester::get_receive_checksum(TESTER_SPI_SLAVE_TO_MASTER_CHECKSUM, TESTER_SPI_SLAVE_TO_MASTER_CHECKSUM_SIZE); 00029 } 00030 00031 void SPISlaveTester::set_mode(SPITester::SpiMode mode) 00032 { 00033 SPITester::set_mode(mode, TESTER_SPI_SLAVE_CTRL, TESTER_SPI_SLAVE_CTRL_SIZE, TESTER_SPI_SLAVE_CLK_MODE_OFFSET, TESTER_SPI_SLAVE_CLK_MODE_SIZE); 00034 } 00035 00036 void SPISlaveTester::set_bit_order(SPITester::SpiBitOrder bit_order) 00037 { 00038 SPITester::set_bit_order(bit_order, TESTER_SPI_SLAVE_CTRL, TESTER_SPI_SLAVE_CTRL_SIZE, TESTER_SPI_SLAVE_BIT_ORDER_OFFSET, TESTER_SPI_SLAVE_BIT_ORDER_SIZE); 00039 } 00040 00041 void SPISlaveTester::set_sym_size(uint32_t sym_size) 00042 { 00043 SPITester::set_sym_size(sym_size, TESTER_SPI_SLAVE_CTRL, TESTER_SPI_SLAVE_CTRL_SIZE, TESTER_SPI_SLAVE_SYM_SIZE_OFFSET, TESTER_SPI_SLAVE_SYM_SIZE_SIZE); 00044 } 00045 00046 void SPISlaveTester::set_duplex_mode(SPITester::SpiDuplex duplex) 00047 { 00048 SPITester::set_duplex_mode(duplex, TESTER_SPI_SLAVE_CTRL, TESTER_SPI_SLAVE_CTRL_SIZE, TESTER_SPI_SLAVE_DUPLEX_OFFSET, TESTER_SPI_SLAVE_DUPLEX_SIZE); 00049 } 00050 00051 void SPISlaveTester::set_hd_tx_rx_cnt(uint16_t tx_cnt, uint16_t rx_cnt) 00052 { 00053 SPITester::set_hd_tx_rx_cnt(tx_cnt, rx_cnt, TESTER_SPI_SLAVE_HD_RX_CNT, TESTER_SPI_SLAVE_HD_RX_CNT_SIZE, TESTER_SPI_SLAVE_HD_TX_CNT, TESTER_SPI_SLAVE_HD_TX_CNT_SIZE); 00054 } 00055 00056 void SPISlaveTester::set_spi_master_freq(uint16_t clk_div) 00057 { 00058 write(TESTER_SPI_SLAVE_CLK_DIV, (uint8_t *)&clk_div, TESTER_SPI_SLAVE_CLK_DIV_SIZE); 00059 } 00060 00061 void SPISlaveTester::set_num_of_symbols(uint16_t num_of_sym) 00062 { 00063 write(TESTER_SPI_SLAVE_NUM_OF_SYMBOLS, (uint8_t *)&num_of_sym, TESTER_SPI_SLAVE_NUM_OF_SYMBOLS_SIZE); 00064 } 00065 00066 void SPISlaveTester::set_start_delay_us(uint8_t start_delay_us) 00067 { 00068 write(TESTER_SPI_SLAVE_START_DELAY_US, (uint8_t *)&start_delay_us, TESTER_SPI_SLAVE_START_DELAY_US_SIZE); 00069 } 00070 00071 void SPISlaveTester::set_sym_delay_ns(uint16_t sym_delay_ns) 00072 { 00073 const uint16_t sym_delay_ticks = (sym_delay_ns + 9) / 10; // round up 00074 write(TESTER_SPI_SLAVE_SYM_DELAY_TICKS, (uint8_t *)&sym_delay_ticks, TESTER_SPI_SLAVE_SYM_DELAY_TICKS_SIZE); 00075 } 00076 00077 void SPISlaveTester::start_transfer() 00078 { 00079 uint32_t spi_ctrl = 0; 00080 read(TESTER_SPI_SLAVE_CTRL, (uint8_t *)&spi_ctrl, TESTER_SPI_SLAVE_CTRL_SIZE); 00081 spi_ctrl &= ~(((1 << TESTER_SPI_SLAVE_START_REQUEST_SIZE) - 1) << TESTER_SPI_SLAVE_START_REQUEST_OFFSET); 00082 spi_ctrl |= (1 << TESTER_SPI_SLAVE_START_REQUEST_OFFSET); 00083 write(TESTER_SPI_SLAVE_CTRL, (uint8_t *)&spi_ctrl, TESTER_SPI_SLAVE_CTRL_SIZE); 00084 }
Generated on Tue Jul 12 2022 13:54:51 by
