mirror of https://github.com/ARMmbed/mbed-os.git
				
				
				
			Replace macros
							parent
							
								
									a32b81f7b6
								
							
						
					
					
						commit
						3664ce9b39
					
				| 
						 | 
				
			
			@ -26,23 +26,25 @@
 | 
			
		|||
 | 
			
		||||
#define mbed_tester_printf(...)
 | 
			
		||||
 | 
			
		||||
#define PHYSICAL_PINS                       128
 | 
			
		||||
#define LOGICAL_PINS                        8
 | 
			
		||||
#define FIRMWARE_SIZE                       2192012
 | 
			
		||||
#define FIRMWARE_REGION_SIZE                0x220000
 | 
			
		||||
#define FIRMWARE_HEADER_SIZE                0x10000
 | 
			
		||||
#define MBED_TESTER_FLASH_SECTOR_SIZE       0x1000
 | 
			
		||||
#define LENGTH_SIZE                         0x4
 | 
			
		||||
#define CRC_SIZE                            0x4
 | 
			
		||||
#define FLASH_SPI_FREQ_HZ                   2000000
 | 
			
		||||
#define ANALOG_COUNT                        4
 | 
			
		||||
 | 
			
		||||
#define PHYSICAL_NC    ((MbedTester::PhysicalIndex)0xFF)
 | 
			
		||||
 | 
			
		||||
static const uint8_t KEY[8] = {
 | 
			
		||||
    0x92, 0x9d, 0x9a, 0x9b,
 | 
			
		||||
    0x29, 0x35, 0xa2, 0x65
 | 
			
		||||
};
 | 
			
		||||
namespace {
 | 
			
		||||
    const auto physical_pins = 128;
 | 
			
		||||
    const auto logical_pins = 8;
 | 
			
		||||
    const auto firmware_size_const = 2192012;
 | 
			
		||||
    const auto firmware_region_size = 0x220000;
 | 
			
		||||
    const auto firmware_header_size = 0x10000;
 | 
			
		||||
    const auto flash_sector_size = 0x1000;
 | 
			
		||||
    const auto length_size = 0x4;
 | 
			
		||||
    const auto crc_size_const = 0x4;
 | 
			
		||||
    const auto flash_spi_freq_hz = 2000000;
 | 
			
		||||
    const auto analog_count = 4;
 | 
			
		||||
    
 | 
			
		||||
    const auto physical_nc = (MbedTester::PhysicalIndex)0xFF;
 | 
			
		||||
    
 | 
			
		||||
    const uint8_t key[8] = {
 | 
			
		||||
        0x92, 0x9d, 0x9a, 0x9b,
 | 
			
		||||
        0x29, 0x35, 0xa2, 0x65
 | 
			
		||||
    };
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template<size_t width>
 | 
			
		||||
class MbedTesterBitMap {
 | 
			
		||||
| 
						 | 
				
			
			@ -102,8 +104,8 @@ static uint8_t spi_transfer(mbed::DigitalInOut *clk, mbed::DigitalInOut *mosi, m
 | 
			
		|||
static void mbed_tester_command(mbed::DigitalInOut *clk, mbed::DigitalInOut *mosi, mbed::DigitalInOut *miso, uint8_t miso_index, uint32_t addr, bool write_n_read, uint8_t *data, uint8_t size)
 | 
			
		||||
{
 | 
			
		||||
    // 8 - Start Key
 | 
			
		||||
    for (uint32_t i = 0; i < sizeof(KEY); i++) {
 | 
			
		||||
        spi_transfer(clk, mosi, miso, KEY[i]);
 | 
			
		||||
    for (uint32_t i = 0; i < sizeof(key); i++) {
 | 
			
		||||
        spi_transfer(clk, mosi, miso, key[i]);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // 1 - Physical pin index for MISO
 | 
			
		||||
| 
						 | 
				
			
			@ -227,7 +229,7 @@ public:
 | 
			
		|||
            return BD_ERROR_DEVICE_ERROR;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if ((addr == 0) && (size == MBED_TESTER_FLASH_SECTOR_SIZE)) {
 | 
			
		||||
        if ((addr == 0) && (size == flash_sector_size)) {
 | 
			
		||||
            // Allow 4K erase only on the first sector. The flash on the basys3 does
 | 
			
		||||
            // not allow sector erases at the higher addresses.
 | 
			
		||||
            _write_enable();
 | 
			
		||||
| 
						 | 
				
			
			@ -482,8 +484,8 @@ static bool _firmware_header_valid(BlockDevice &flash, bool &valid)
 | 
			
		|||
    valid = false;
 | 
			
		||||
 | 
			
		||||
    // Check that first portion is erased
 | 
			
		||||
    while (pos < MBED_TESTER_FLASH_SECTOR_SIZE - sizeof(SYNC_WORD)) {
 | 
			
		||||
        read_size = MBED_TESTER_FLASH_SECTOR_SIZE - pos;
 | 
			
		||||
    while (pos < flash_sector_size - sizeof(SYNC_WORD)) {
 | 
			
		||||
        read_size = flash_sector_size - pos;
 | 
			
		||||
        if (read_size > sizeof(buf)) {
 | 
			
		||||
            read_size = sizeof(buf);
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			@ -514,8 +516,8 @@ static bool _firmware_header_valid(BlockDevice &flash, bool &valid)
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    // Check if the rest is 0xFF
 | 
			
		||||
    while (pos < FIRMWARE_HEADER_SIZE) {
 | 
			
		||||
        read_size = FIRMWARE_HEADER_SIZE - pos;
 | 
			
		||||
    while (pos < firmware_header_size) {
 | 
			
		||||
        read_size = firmware_header_size - pos;
 | 
			
		||||
        if (read_size > sizeof(buf)) {
 | 
			
		||||
            read_size = sizeof(buf);
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			@ -539,7 +541,7 @@ static bool _firmware_get_active_bank(BlockDevice &flash, bool &second_bank_acti
 | 
			
		|||
{
 | 
			
		||||
    uint8_t buf[sizeof(SYNC_WORD)];
 | 
			
		||||
 | 
			
		||||
    if (flash.read(buf, MBED_TESTER_FLASH_SECTOR_SIZE - sizeof(SYNC_WORD), sizeof(SYNC_WORD)) != BD_ERROR_OK) {
 | 
			
		||||
    if (flash.read(buf, flash_sector_size - sizeof(SYNC_WORD), sizeof(SYNC_WORD)) != BD_ERROR_OK) {
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -554,14 +556,14 @@ static bool _firmware_set_active_bank(BlockDevice &flash, bool second_bank)
 | 
			
		|||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
    if (!valid) {
 | 
			
		||||
        if (flash.erase(0, FIRMWARE_HEADER_SIZE) != BD_ERROR_OK) {
 | 
			
		||||
        if (flash.erase(0, firmware_header_size) != BD_ERROR_OK) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
        if (flash.program(BANK_B_SELECT, MBED_TESTER_FLASH_SECTOR_SIZE, sizeof(BANK_B_SELECT)) != BD_ERROR_OK) {
 | 
			
		||||
        if (flash.program(BANK_B_SELECT, flash_sector_size, sizeof(BANK_B_SELECT)) != BD_ERROR_OK) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    if (!flash.erase(0, MBED_TESTER_FLASH_SECTOR_SIZE)) {
 | 
			
		||||
    if (!flash.erase(0, flash_sector_size)) {
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -569,7 +571,7 @@ static bool _firmware_set_active_bank(BlockDevice &flash, bool second_bank)
 | 
			
		|||
    if (second_bank) {
 | 
			
		||||
        // Write the sync word. Before the sync word is written the FPGA will boot from the first bank.
 | 
			
		||||
        // After the sync word is written the FPGA will boot from the second bank.
 | 
			
		||||
        if (flash.program(SYNC_WORD, MBED_TESTER_FLASH_SECTOR_SIZE - sizeof(SYNC_WORD), sizeof(SYNC_WORD)) != BD_ERROR_OK) {
 | 
			
		||||
        if (flash.program(SYNC_WORD, flash_sector_size - sizeof(SYNC_WORD), sizeof(SYNC_WORD)) != BD_ERROR_OK) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -579,7 +581,7 @@ static bool _firmware_set_active_bank(BlockDevice &flash, bool second_bank)
 | 
			
		|||
 | 
			
		||||
MbedTester::MbedTester(const PinList *form_factor, const PinList *exclude_pins)
 | 
			
		||||
    : _form_factor(form_factor), _exclude_pins(exclude_pins), _control_auto(true), _control_valid(false),
 | 
			
		||||
      _clk_index(PHYSICAL_NC), _mosi_index(PHYSICAL_NC), _miso_index(PHYSICAL_NC), _aux_index(PHYSICAL_NC),
 | 
			
		||||
      _clk_index(physical_nc), _mosi_index(physical_nc), _miso_index(physical_nc), _aux_index(physical_nc),
 | 
			
		||||
      _clk(NULL), _mosi(NULL), _miso(NULL), _aux(NULL)
 | 
			
		||||
{
 | 
			
		||||
    _reset();
 | 
			
		||||
| 
						 | 
				
			
			@ -656,7 +658,7 @@ bool MbedTester::firmware_dump(mbed::FileHandle *dest, mbed::Callback<void(uint8
 | 
			
		|||
 | 
			
		||||
    // Mapping intentionally different from control channel to prevent
 | 
			
		||||
    // unintentional activation (clk and mosi flipped)
 | 
			
		||||
    MbedTesterBlockDevice flash(*_clk, *_miso, *_mosi, *_aux, FLASH_SPI_FREQ_HZ);
 | 
			
		||||
    MbedTesterBlockDevice flash(*_clk, *_miso, *_mosi, *_aux, flash_spi_freq_hz);
 | 
			
		||||
    sys_pin_mode_spi_serial_flash(_clk_index, _miso_index, _mosi_index, _aux_index);
 | 
			
		||||
 | 
			
		||||
    progress(0);
 | 
			
		||||
| 
						 | 
				
			
			@ -673,29 +675,29 @@ bool MbedTester::firmware_dump(mbed::FileHandle *dest, mbed::Callback<void(uint8
 | 
			
		|||
        sys_pin_mode_disabled();
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
    const uint32_t start = FIRMWARE_HEADER_SIZE + (second_bank_active ? FIRMWARE_REGION_SIZE : 0);
 | 
			
		||||
    const uint32_t start = firmware_header_size + (second_bank_active ? firmware_region_size : 0);
 | 
			
		||||
 | 
			
		||||
    // Get the firmware size
 | 
			
		||||
    uint32_t offset = 0;
 | 
			
		||||
    uint8_t buf[256];
 | 
			
		||||
    uint32_t prev_percent_done = 0;
 | 
			
		||||
    if (flash.read(buf, start + offset, LENGTH_SIZE) != BD_ERROR_OK) {
 | 
			
		||||
    if (flash.read(buf, start + offset, length_size) != BD_ERROR_OK) {
 | 
			
		||||
        sys_pin_mode_disabled();
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
    if (dest->write(buf, LENGTH_SIZE) != LENGTH_SIZE) {
 | 
			
		||||
    if (dest->write(buf, length_size) != length_size) {
 | 
			
		||||
        sys_pin_mode_disabled();
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
    offset += LENGTH_SIZE;
 | 
			
		||||
    offset += length_size;
 | 
			
		||||
    uint32_t data_size = (buf[0] << (0 * 8)) |
 | 
			
		||||
                         (buf[1] << (1 * 8)) |
 | 
			
		||||
                         (buf[2] << (2 * 8)) |
 | 
			
		||||
                         (buf[3] << (3 * 8));
 | 
			
		||||
    if (data_size > FIRMWARE_REGION_SIZE - LENGTH_SIZE - CRC_SIZE) {
 | 
			
		||||
        data_size = FIRMWARE_REGION_SIZE - LENGTH_SIZE - CRC_SIZE;
 | 
			
		||||
    if (data_size > firmware_region_size - length_size - crc_size_const) {
 | 
			
		||||
        data_size = firmware_region_size - length_size - crc_size_const;
 | 
			
		||||
    }
 | 
			
		||||
    const uint32_t firmware_size = data_size + LENGTH_SIZE + CRC_SIZE;
 | 
			
		||||
    const uint32_t firmware_size = data_size + length_size + crc_size_const;
 | 
			
		||||
 | 
			
		||||
    // Dump firmware
 | 
			
		||||
    while (offset < firmware_size) {
 | 
			
		||||
| 
						 | 
				
			
			@ -737,7 +739,7 @@ bool MbedTester::firmware_dump_all(mbed::FileHandle *dest, mbed::Callback<void(u
 | 
			
		|||
 | 
			
		||||
    // Mapping intentionally different from control channel to prevent
 | 
			
		||||
    // unintentional activation (clk and mosi flipped)
 | 
			
		||||
    MbedTesterBlockDevice flash(*_clk, *_miso, *_mosi, *_aux, FLASH_SPI_FREQ_HZ);
 | 
			
		||||
    MbedTesterBlockDevice flash(*_clk, *_miso, *_mosi, *_aux, flash_spi_freq_hz);
 | 
			
		||||
    sys_pin_mode_spi_serial_flash(_clk_index, _miso_index, _mosi_index, _aux_index);
 | 
			
		||||
 | 
			
		||||
    progress(0);
 | 
			
		||||
| 
						 | 
				
			
			@ -790,7 +792,7 @@ bool MbedTester::firmware_update(mbed::FileHandle *src, mbed::Callback<void(uint
 | 
			
		|||
 | 
			
		||||
    // Mapping intentionally different from control channel to prevent
 | 
			
		||||
    // unintentional activation (clk and mosi flipped)
 | 
			
		||||
    MbedTesterBlockDevice flash(*_clk, *_miso, *_mosi, *_aux, FLASH_SPI_FREQ_HZ);
 | 
			
		||||
    MbedTesterBlockDevice flash(*_clk, *_miso, *_mosi, *_aux, flash_spi_freq_hz);
 | 
			
		||||
    sys_pin_mode_spi_serial_flash(_clk_index, _miso_index, _mosi_index, _aux_index);
 | 
			
		||||
 | 
			
		||||
    progress(0);
 | 
			
		||||
| 
						 | 
				
			
			@ -802,12 +804,12 @@ bool MbedTester::firmware_update(mbed::FileHandle *src, mbed::Callback<void(uint
 | 
			
		|||
 | 
			
		||||
    // Validate file size
 | 
			
		||||
    const uint32_t file_size = src->size();
 | 
			
		||||
    if (file_size > FIRMWARE_REGION_SIZE) {
 | 
			
		||||
    if (file_size > firmware_region_size) {
 | 
			
		||||
        // Firmware image too big
 | 
			
		||||
        sys_pin_mode_disabled();
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
    if (file_size < LENGTH_SIZE + CRC_SIZE) {
 | 
			
		||||
    if (file_size < length_size + crc_size_const) {
 | 
			
		||||
        // Firmware image too small
 | 
			
		||||
        sys_pin_mode_disabled();
 | 
			
		||||
        return false;
 | 
			
		||||
| 
						 | 
				
			
			@ -820,7 +822,7 @@ bool MbedTester::firmware_update(mbed::FileHandle *src, mbed::Callback<void(uint
 | 
			
		|||
        sys_pin_mode_disabled();
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
    const uint32_t start = FIRMWARE_HEADER_SIZE + (second_bank_active ? 0 : FIRMWARE_REGION_SIZE);
 | 
			
		||||
    const uint32_t start = firmware_header_size + (second_bank_active ? 0 : firmware_region_size);
 | 
			
		||||
 | 
			
		||||
    // Setup CRC calculation
 | 
			
		||||
    uint32_t crc;
 | 
			
		||||
| 
						 | 
				
			
			@ -863,7 +865,7 @@ bool MbedTester::firmware_update(mbed::FileHandle *src, mbed::Callback<void(uint
 | 
			
		|||
                                     (buf[1] << (1 * 8)) |
 | 
			
		||||
                                     (buf[2] << (2 * 8)) |
 | 
			
		||||
                                     (buf[3] << (3 * 8));
 | 
			
		||||
            if (data_size != file_size - LENGTH_SIZE - CRC_SIZE) {
 | 
			
		||||
            if (data_size != file_size - length_size - crc_size_const) {
 | 
			
		||||
                // Invalid data length
 | 
			
		||||
                sys_pin_mode_disabled();
 | 
			
		||||
                return false;
 | 
			
		||||
| 
						 | 
				
			
			@ -871,13 +873,13 @@ bool MbedTester::firmware_update(mbed::FileHandle *src, mbed::Callback<void(uint
 | 
			
		|||
            size_valid = true;
 | 
			
		||||
 | 
			
		||||
            // Don't include the length in the checksum
 | 
			
		||||
            crc_offset += LENGTH_SIZE;
 | 
			
		||||
            crc_size -= LENGTH_SIZE;
 | 
			
		||||
            crc_offset += length_size;
 | 
			
		||||
            crc_size -= length_size;
 | 
			
		||||
        }
 | 
			
		||||
        if (offset + program_size > file_size - CRC_SIZE) {
 | 
			
		||||
        if (offset + program_size > file_size - crc_size_const) {
 | 
			
		||||
            // Overlap with the CRC field
 | 
			
		||||
            for (uint32_t i = 0; i < CRC_SIZE; i++) {
 | 
			
		||||
                uint32_t byte_offset = file_size - CRC_SIZE + i;
 | 
			
		||||
            for (uint32_t i = 0; i < crc_size_const; i++) {
 | 
			
		||||
                uint32_t byte_offset = file_size - crc_size_const + i;
 | 
			
		||||
                if ((byte_offset >= offset) && (byte_offset < offset + program_size)) {
 | 
			
		||||
                    uint32_t buf_pos = byte_offset - offset;
 | 
			
		||||
                    stored_crc |= buf[buf_pos] << (i * 8);
 | 
			
		||||
| 
						 | 
				
			
			@ -956,10 +958,10 @@ void MbedTester::pin_map_set(PinName physical, LogicalPin logical)
 | 
			
		|||
void MbedTester::pin_map_reset()
 | 
			
		||||
{
 | 
			
		||||
    for (uint32_t i = 0; i < sizeof(_mapping) / sizeof(_mapping[0]); i++) {
 | 
			
		||||
        _mapping[i] = PHYSICAL_NC;
 | 
			
		||||
        _mapping[i] = physical_nc;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    uint8_t pin_buf[PHYSICAL_PINS + LOGICAL_PINS];
 | 
			
		||||
    uint8_t pin_buf[physical_pins + logical_pins];
 | 
			
		||||
    memset(pin_buf, 0xFF, sizeof(pin_buf));
 | 
			
		||||
    write(TESTER_REMAP, pin_buf, sizeof(pin_buf));
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1165,7 +1167,7 @@ int MbedTester::io_expander_i2c_read(uint8_t i2c_index, uint8_t dev_addr, uint8_
 | 
			
		|||
    _update_control_pins();
 | 
			
		||||
    //sda_in = _miso_index
 | 
			
		||||
    //sda_val = _aux_index
 | 
			
		||||
    //scl_in = _mosi_index (PHYSICAL_NC)
 | 
			
		||||
    //scl_in = _mosi_index (physical_nc)
 | 
			
		||||
    //scl_val = _clk_index
 | 
			
		||||
    mbed::DigitalInOut *sda_in = _miso;
 | 
			
		||||
    mbed::DigitalInOut *sda_val = _aux;
 | 
			
		||||
| 
						 | 
				
			
			@ -1174,7 +1176,7 @@ int MbedTester::io_expander_i2c_read(uint8_t i2c_index, uint8_t dev_addr, uint8_
 | 
			
		|||
    sda_val->output();
 | 
			
		||||
    *sda_val = 1;
 | 
			
		||||
    scl_val->output();
 | 
			
		||||
    sys_pin_mode_i2c_io_expander(i2c_index, _miso_index, _aux_index, PHYSICAL_NC, _clk_index);
 | 
			
		||||
    sys_pin_mode_i2c_io_expander(i2c_index, _miso_index, _aux_index, physical_nc, _clk_index);
 | 
			
		||||
 | 
			
		||||
    //start condition
 | 
			
		||||
    *scl_val = 1;
 | 
			
		||||
| 
						 | 
				
			
			@ -1304,7 +1306,7 @@ int MbedTester::io_expander_i2c_write(uint8_t i2c_index, uint8_t dev_addr, uint8
 | 
			
		|||
    _update_control_pins();
 | 
			
		||||
    //sda_in = _miso_index
 | 
			
		||||
    //sda_val = _aux_index
 | 
			
		||||
    //scl_in = _mosi_index (PHYSICAL_NC)
 | 
			
		||||
    //scl_in = _mosi_index (physical_nc)
 | 
			
		||||
    //scl_val = _clk_index
 | 
			
		||||
    mbed::DigitalInOut *sda_in = _miso;
 | 
			
		||||
    mbed::DigitalInOut *sda_val = _aux;
 | 
			
		||||
| 
						 | 
				
			
			@ -1313,7 +1315,7 @@ int MbedTester::io_expander_i2c_write(uint8_t i2c_index, uint8_t dev_addr, uint8
 | 
			
		|||
    sda_val->output();
 | 
			
		||||
    *sda_val = 1;
 | 
			
		||||
    scl_val->output();
 | 
			
		||||
    sys_pin_mode_i2c_io_expander(i2c_index, _miso_index, _aux_index, PHYSICAL_NC, _clk_index);
 | 
			
		||||
    sys_pin_mode_i2c_io_expander(i2c_index, _miso_index, _aux_index, physical_nc, _clk_index);
 | 
			
		||||
 | 
			
		||||
    //start condition
 | 
			
		||||
    *scl_val = 1;
 | 
			
		||||
| 
						 | 
				
			
			@ -1745,7 +1747,7 @@ uint16_t MbedTester::get_analogmuxin_measurement()
 | 
			
		|||
uint16_t MbedTester::get_anin_measurement(int index)
 | 
			
		||||
{
 | 
			
		||||
    //check index is in bounds
 | 
			
		||||
    if ((index < 0) || (index >= ANALOG_COUNT)) {
 | 
			
		||||
    if ((index < 0) || (index >= analog_count)) {
 | 
			
		||||
        error("AnalogIn index is out of bounds");
 | 
			
		||||
    }
 | 
			
		||||
    //take snapshot of conversion value to make safe for reading
 | 
			
		||||
| 
						 | 
				
			
			@ -1758,7 +1760,7 @@ uint16_t MbedTester::get_anin_measurement(int index)
 | 
			
		|||
void MbedTester::get_anin_sum_samples_cycles(int index, uint64_t *sum, uint32_t *samples, uint64_t *cycles)
 | 
			
		||||
{
 | 
			
		||||
    //check index is in bounds
 | 
			
		||||
    if ((index < 0) || (index >= ANALOG_COUNT)) {
 | 
			
		||||
    if ((index < 0) || (index >= analog_count)) {
 | 
			
		||||
        error("AnalogIn index is out of bounds");
 | 
			
		||||
    }
 | 
			
		||||
    //take snapshot of the sum/samples/cycles so that all 3 values are correct in relation to each other
 | 
			
		||||
| 
						 | 
				
			
			@ -1944,10 +1946,10 @@ void MbedTester::sys_pin_mode_disabled()
 | 
			
		|||
{
 | 
			
		||||
    const uint32_t base = LogicalPinTotal;
 | 
			
		||||
 | 
			
		||||
    pin_map_index(PHYSICAL_NC, (LogicalPin)(base + 0));
 | 
			
		||||
    pin_map_index(PHYSICAL_NC, (LogicalPin)(base + 1));
 | 
			
		||||
    pin_map_index(PHYSICAL_NC, (LogicalPin)(base + 2));
 | 
			
		||||
    pin_map_index(PHYSICAL_NC, (LogicalPin)(base + 3));
 | 
			
		||||
    pin_map_index(physical_nc, (LogicalPin)(base + 0));
 | 
			
		||||
    pin_map_index(physical_nc, (LogicalPin)(base + 1));
 | 
			
		||||
    pin_map_index(physical_nc, (LogicalPin)(base + 2));
 | 
			
		||||
    pin_map_index(physical_nc, (LogicalPin)(base + 3));
 | 
			
		||||
 | 
			
		||||
    uint8_t mode = TESTER_SYS_IO_MODE_DISABLED;
 | 
			
		||||
    write(TESTER_SYS_IO_MODE, &mode, sizeof(mode));
 | 
			
		||||
| 
						 | 
				
			
			@ -1992,7 +1994,7 @@ void MbedTester::sys_pin_mode_i2c_io_expander(int index, PhysicalIndex sda_in, P
 | 
			
		|||
void MbedTester::pin_map_index(PhysicalIndex physical_index, LogicalPin logical)
 | 
			
		||||
{
 | 
			
		||||
    uint8_t remap;
 | 
			
		||||
    if ((physical_index >= PHYSICAL_PINS) && (physical_index != PHYSICAL_NC)) {
 | 
			
		||||
    if ((physical_index >= physical_pins) && (physical_index != physical_nc)) {
 | 
			
		||||
        error("Invalid physical pin index %i", physical_index);
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -2002,20 +2004,20 @@ void MbedTester::pin_map_index(PhysicalIndex physical_index, LogicalPin logical)
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    // Unmap the previous pin if it had been mapped
 | 
			
		||||
    if (_mapping[logical] < PHYSICAL_PINS) {
 | 
			
		||||
        remap = PHYSICAL_NC;
 | 
			
		||||
    if (_mapping[logical] < physical_pins) {
 | 
			
		||||
        remap = physical_nc;
 | 
			
		||||
        write(TESTER_REMAP + _mapping[logical], &remap, sizeof(remap));
 | 
			
		||||
    }
 | 
			
		||||
    _mapping[logical] = physical_index;
 | 
			
		||||
 | 
			
		||||
    // Remap physical pin if it is not PHYSICAL_NC
 | 
			
		||||
    if (physical_index < PHYSICAL_PINS) {
 | 
			
		||||
    // Remap physical pin if it is not physical_nc
 | 
			
		||||
    if (physical_index < physical_pins) {
 | 
			
		||||
        remap = logical;
 | 
			
		||||
        write(TESTER_REMAP + physical_index, &remap, sizeof(remap));
 | 
			
		||||
    }
 | 
			
		||||
    // Remap logical pin
 | 
			
		||||
    remap = physical_index;
 | 
			
		||||
    write(TESTER_REMAP + PHYSICAL_PINS + logical, &remap, sizeof(remap));
 | 
			
		||||
    write(TESTER_REMAP + physical_pins + logical, &remap, sizeof(remap));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void MbedTester::write(uint32_t addr, const uint8_t *data, uint32_t size)
 | 
			
		||||
| 
						 | 
				
			
			@ -2184,7 +2186,7 @@ bool MbedTester::self_test_control_current()
 | 
			
		|||
 | 
			
		||||
bool MbedTester::_find_control_indexes(PhysicalIndex &clk_out, PhysicalIndex &mosi_out, PhysicalIndex &miso_out, PhysicalIndex &aux_out)
 | 
			
		||||
{
 | 
			
		||||
    MbedTesterBitMap<PHYSICAL_PINS> allowed;
 | 
			
		||||
    MbedTesterBitMap<physical_pins> allowed;
 | 
			
		||||
    const size_t max_pins = _form_factor.count();
 | 
			
		||||
    const size_t max_controls = max_pins / 2;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -2200,7 +2202,7 @@ bool MbedTester::_find_control_indexes(PhysicalIndex &clk_out, PhysicalIndex &mo
 | 
			
		|||
    }
 | 
			
		||||
    for (size_t i = 0; i < LogicalPinTotal; i++) {
 | 
			
		||||
        PhysicalIndex index = _mapping[i];
 | 
			
		||||
        if (index < PHYSICAL_PINS) {
 | 
			
		||||
        if (index < physical_pins) {
 | 
			
		||||
            allowed.clear(index);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -2282,25 +2284,25 @@ void MbedTester::_free_control_pins()
 | 
			
		|||
        delete _clk;
 | 
			
		||||
    }
 | 
			
		||||
    _clk = NULL;
 | 
			
		||||
    _clk_index = PHYSICAL_NC;
 | 
			
		||||
    _clk_index = physical_nc;
 | 
			
		||||
    if (_mosi) {
 | 
			
		||||
        _mosi->input();
 | 
			
		||||
        delete _mosi;
 | 
			
		||||
    }
 | 
			
		||||
    _mosi = NULL;
 | 
			
		||||
    _mosi_index = PHYSICAL_NC;
 | 
			
		||||
    _mosi_index = physical_nc;
 | 
			
		||||
    if (_miso) {
 | 
			
		||||
        _miso->input();
 | 
			
		||||
        delete _miso;
 | 
			
		||||
    }
 | 
			
		||||
    _miso = NULL;
 | 
			
		||||
    _miso_index = PHYSICAL_NC;
 | 
			
		||||
    _miso_index = physical_nc;
 | 
			
		||||
    if (_aux) {
 | 
			
		||||
        _aux->input();
 | 
			
		||||
        delete _aux;
 | 
			
		||||
    }
 | 
			
		||||
    _aux = NULL;
 | 
			
		||||
    _aux_index = PHYSICAL_NC;
 | 
			
		||||
    _aux_index = physical_nc;
 | 
			
		||||
    _control_valid = false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -2344,7 +2346,7 @@ bool MbedTester::_update_needed()
 | 
			
		|||
void MbedTester::_reset()
 | 
			
		||||
{
 | 
			
		||||
    for (uint32_t i = 0; i < sizeof(_mapping) / sizeof(_mapping[0]); i++) {
 | 
			
		||||
        _mapping[i] = PHYSICAL_NC;
 | 
			
		||||
        _mapping[i] = physical_nc;
 | 
			
		||||
    }
 | 
			
		||||
    _free_control_pins();
 | 
			
		||||
    _control_auto = true;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue