
Test program running on MAX32625MBED. Control through USB Serial commands using a terminal emulator such as teraterm or putty.
Dependencies: MaximTinyTester CmdLine MAX541 USBDevice
Revision 57:1c9da8e90737, committed 2020-02-13
- Comitter:
- whismanoid
- Date:
- Thu Feb 13 22:52:57 2020 +0000
- Parent:
- 56:a3144eaea1a8
- Child:
- 58:2fea32db466b
- Commit message:
- readAllStatusList, CMDOP_enum_t, DecodeCommand
Changed in this revision
--- a/MAX11043/MAX11043.cpp Wed Feb 12 00:37:04 2020 +0000 +++ b/MAX11043/MAX11043.cpp Thu Feb 13 22:52:57 2020 +0000 @@ -598,7 +598,7 @@ //---------------------------------------- // Write a MAX11043 register. // -// CMD_1aaa_aaaa_REGISTER_READ bit is cleared 0 indicating a write operation. +// CMDOP_1aaa_aaaa_ReadRegister bit is cleared 0 indicating a write operation. // // MAX11043 register length can be determined by function RegSize. // @@ -632,7 +632,7 @@ //---------------------------------------- // switch based on register address szie RegSize(commandByte) - //commandByte = (MAX11043_CMD_enum_t)((commandByte &~ CMD_0aaa_aa10_RdAddr_ReadAnyRegister) & 0xFF); + //commandByte = (MAX11043_CMD_enum_t)((commandByte &~ CMDOP_0aaa_aa10_ReadRegister) & 0xFF); switch(RegSize(commandByte)) { case 8: // 8-bit register size @@ -681,7 +681,7 @@ //---------------------------------------- // Read an 8-bit MAX11043 register // -// CMD_1aaa_aaaa_REGISTER_READ bit is set 1 indicating a read operation. +// CMDOP_1aaa_aaaa_ReadRegister bit is set 1 indicating a read operation. // // MAX11043 register length can be determined by function RegSize. // @@ -716,7 +716,7 @@ //---------------------------------------- // switch based on register address szie RegSize(regAddress) - //commandByte = (MAX11043_CMD_enum_t)((commandByte &~ CMD_0aaa_aa10_RdAddr_ReadAnyRegister) & 0xFF); + //commandByte = (MAX11043_CMD_enum_t)((commandByte &~ CMDOP_0aaa_aa10_ReadRegister) & 0xFF); switch(RegSize(commandByte)) { case 8: // 8-bit register size @@ -724,7 +724,7 @@ // SPI 16-bit transfer // SPI MOSI = 1aaa_aaaa_0000_0000 // SPI MISO = xxxx_xxxx_dddd_dddd - int16_t mosiData16 = ((CMD_0aaa_aa10_RdAddr_ReadAnyRegister | (int16_t)commandByte) << 8) | ((int16_t)0); + int16_t mosiData16 = ((CMDOP_0aaa_aa10_ReadRegister | (int16_t)commandByte) << 8) | ((int16_t)0); SPIoutputCS(0); int16_t misoData16 = SPIreadWrite16bits(mosiData16); SPIoutputCS(1); @@ -739,7 +739,7 @@ // SPI MISO = xxxx_xxxx_dddd_dddd_dddd_dddd // SPI MOSI = 1aaa_aaaa_0000_0000_0000_0000_0000_0000 // SPI MISO = xxxx_xxxx_dddd_dddd_dddd_dddd_xxxx_xxxx - int32_t mosiData32 = ((CMD_0aaa_aa10_RdAddr_ReadAnyRegister | (int32_t)commandByte) << 24); + int32_t mosiData32 = ((CMDOP_0aaa_aa10_ReadRegister | (int32_t)commandByte) << 24); SPIoutputCS(0); int32_t misoData32 = SPIreadWrite32bits(mosiData32); SPIoutputCS(1); @@ -751,7 +751,7 @@ // SPI 32-bit transfer // SPI MOSI = 1aaa_aaaa_0000_0000_0000_0000_0000_0000 // SPI MISO = xxxx_xxxx_dddd_dddd_dddd_dddd_dddd_dddd - int32_t mosiData32 = ((CMD_0aaa_aa10_RdAddr_ReadAnyRegister | (int32_t)commandByte) << 24); + int32_t mosiData32 = ((CMDOP_0aaa_aa10_ReadRegister | (int32_t)commandByte) << 24); SPIoutputCS(0); int32_t misoData32 = SPIreadWrite32bits(mosiData32); SPIoutputCS(1); @@ -774,13 +774,13 @@ //---------------------------------------- // switch based on register address value regAddress - // commandByte = (MAX11043_CMD_enum_t)((commandByte &~ CMD_0aaa_aa10_RdAddr_ReadAnyRegister) & 0xFF); + // commandByte = (MAX11043_CMD_enum_t)((commandByte &~ CMDOP_0aaa_aa10_ReadRegister) & 0xFF); switch(commandByte) { default: - case CMD_0aaa_aa00_WrAddr_WriteAnyRegister: - case CMD_0aaa_aa10_RdAddr_ReadAnyRegister: - case CMD_1111_1111_NoOperationMOSIidleHigh: + // case CMDOP_0aaa_aa00_WriteRegister: + // case CMDOP_0aaa_aa10_ReadRegister: + // case CMDOP_1111_1111_NoOperationMOSIidleHigh: return 0; // undefined register size case CMD_0001_1110_d8_Rd07_Status: case CMD_0101_0100_d8_Wr15_FilterCAddress: @@ -839,6 +839,26 @@ } //---------------------------------------- +// Decode operation from commandByte +// +// @return operation such as idle, read register, write register, etc. +MAX11043::MAX11043_CMDOP_enum_t MAX11043::DecodeCommand(MAX11043_CMD_enum_t commandByte) +{ + + //---------------------------------------- + // decode operation from command byte + switch (commandByte & 0x83) + { + case CMDOP_0aaa_aa10_ReadRegister: + return CMDOP_0aaa_aa10_ReadRegister; + case CMDOP_0aaa_aa00_WriteRegister: + return CMDOP_0aaa_aa00_WriteRegister; + default: + return CMDOP_1111_1111_NoOperationMOSIidleHigh; + } +} + +//---------------------------------------- // Return the address field of a MAX11043 register // // @return register address field as given in datasheet @@ -847,7 +867,7 @@ //---------------------------------------- // extract register address value from command byte - return (uint8_t)((commandByte &~ 0x83) >> 2); // CMD_0aaa_aa10_RdAddr_ReadAnyRegister + return (uint8_t)((commandByte &~ 0x83) >> 2); // CMDOP_0aaa_aa10_ReadRegister } //---------------------------------------- @@ -859,7 +879,7 @@ //---------------------------------------- // Test whether a command byte is a register read command - return (commandByte &~ 0x02) ? 1 : 0; // CMD_0aaa_aa10_RdAddr_ReadAnyRegister + return (commandByte &~ 0x02) ? 1 : 0; // CMDOP_0aaa_aa10_ReadRegister } //---------------------------------------- @@ -871,14 +891,14 @@ //---------------------------------------- // switch based on register address value regAddress - // commandByte = (MAX11043_CMD_enum_t)((commandByte &~ CMD_0aaa_aa10_RdAddr_ReadAnyRegister) & 0xFF); + // commandByte = (MAX11043_CMD_enum_t)((commandByte &~ CMDOP_0aaa_aa10_ReadRegister) & 0xFF); switch(commandByte) { default: return ""; // undefined register - // case CMD_0aaa_aa00_WrAddr_WriteAnyRegister: return "_______"; - // case CMD_0aaa_aa10_RdAddr_ReadAnyRegister: return "_______"; - // case CMD_1111_1111_NoOperationMOSIidleHigh: return "_______"; + // case CMDOP_0aaa_aa00_WriteRegister: return "_______"; + // case CMDOP_0aaa_aa10_ReadRegister: return "_______"; + // case CMDOP_1111_1111_NoOperationMOSIidleHigh: return "_______"; case CMD_0000_0010_d24_Rd00_ADCa: return "ADCa"; case CMD_0000_0110_d24_Rd01_ADCb: return "ADCb"; case CMD_0000_1010_d24_Rd02_ADCc: return "ADCc";
--- a/MAX11043/MAX11043.h Wed Feb 12 00:37:04 2020 +0000 +++ b/MAX11043/MAX11043.h Thu Feb 13 22:52:57 2020 +0000 @@ -294,6 +294,20 @@ class MAX11043 { public: // CODE GENERATOR: TypedefEnum EnumItem declarations +// CODE GENERATOR: TypedefEnum MAX11043_CMDOP_enum_t + //---------------------------------------- + /// Command Operation Format (see function DecodeCommand) + /// + /// Naming convention is CMDOP_bitstream_OPERATION_NAME + /// - 0aaa_aax0 = 5-bit register address field + /// - 0xxx_xxr0 = read/write bit (1=read, 0=write) + /// - xxxx = don't care + typedef enum MAX11043_CMDOP_enum_t { + CMDOP_0aaa_aa00_WriteRegister = 0x00, //!< 8'b00000000 + CMDOP_0aaa_aa10_ReadRegister = 0x02, //!< 8'b00000010 + CMDOP_1111_1111_NoOperationMOSIidleHigh = 0xff, //!< 8'b11111111 + } MAX11043_CMDOP_enum_t; + // CODE GENERATOR: TypedefEnum MAX11043_CMD_enum_t //---------------------------------------- /// Register Addresses @@ -311,7 +325,6 @@ /// - d32 = 32-bit register data field /// - x = don't care typedef enum MAX11043_CMD_enum_t { - CMD_0aaa_aa00_WrAddr_WriteAnyRegister = 0x00, //!< 8'b00000000 CMD_0000_0010_d24_Rd00_ADCa = 0x02, //!< 8'b00000010 CMD_0000_0110_d24_Rd01_ADCb = 0x06, //!< 8'b00000110 CMD_0000_1010_d24_Rd02_ADCc = 0x0a, //!< 8'b00001010 @@ -359,8 +372,6 @@ CMD_0110_1000_d16_Wr1A_FlashDataIn = 0x68, //!< 8'b01101000 CMD_0110_1010_d16_Rd1A_FlashDataIn = 0x6a, //!< 8'b01101010 CMD_0110_1110_d16_Rd1B_FlashDataOut = 0x6e, //!< 8'b01101110 - CMD_0aaa_aa10_RdAddr_ReadAnyRegister = 0x80, //!< 8'b10000000 - CMD_1111_1111_NoOperationMOSIidleHigh = 0xff, //!< 8'b11111111 } MAX11043_CMD_enum_t; // CODE GENERATOR: TypedefEnum MAX11043_STATUS_enum_t @@ -718,12 +729,10 @@ // CODE GENERATOR: looks like this is a register access function because 'regAdd' // CODE GENERATOR: looks like this is a 'write' register access function -// CODE GENERATOR: looks like this is a register access function because 'regAdd' -// CODE GENERATOR: looks like this is a 'write' register access function: omit this function from test menu //---------------------------------------- /// Write a MAX11043 register. /// - /// CMD_1aaa_aaaa_REGISTER_READ bit is cleared 0 indicating a write operation. + /// CMDOP_1aaa_aaaa_ReadRegister bit is cleared 0 indicating a write operation. /// /// MAX11043 register length can be determined by function RegSize. /// @@ -756,12 +765,10 @@ // CODE GENERATOR: looks like this is a register access function because 'regAdd' // CODE GENERATOR: looks like this is a 'read' register access function -// CODE GENERATOR: looks like this is a register access function because 'regAdd' -// CODE GENERATOR: looks like this is a 'read' register access function: omit this function from test menu //---------------------------------------- /// Read an 8-bit MAX11043 register /// - /// CMD_1aaa_aaaa_REGISTER_READ bit is set 1 indicating a read operation. + /// CMDOP_1aaa_aaaa_ReadRegister bit is set 1 indicating a read operation. /// /// MAX11043 register length can be determined by function RegSize. /// @@ -803,6 +810,13 @@ // CODE GENERATOR: looks like this is a register access function because 'regAdd' //---------------------------------------- + /// Decode operation from commandByte + /// + /// @return operation such as idle, read register, write register, etc. + MAX11043::MAX11043_CMDOP_enum_t DecodeCommand(MAX11043_CMD_enum_t commandByte); + +// CODE GENERATOR: looks like this is a register access function because 'regAdd' + //---------------------------------------- /// Return the address field of a MAX11043 register /// /// @return register address field as given in datasheet
--- a/Test_Menu_MAX11043.cpp Wed Feb 12 00:37:04 2020 +0000 +++ b/Test_Menu_MAX11043.cpp Thu Feb 13 22:52:57 2020 +0000 @@ -98,14 +98,12 @@ // CODE GENERATOR: CommandReturn '@return 1 on success; 0 on failure' // CODE GENERATOR: MAX11043 Command Name = RegWrite (MAX11043_CMD_enum_t commandByte, uint32_t regData) --> uint8_t // CODE GENERATOR: no Menu item hint in description -// CODE GENERATOR: CommandDescriptionCMDWord = CMD_1aaa_aaaa_REGISTER_READ -// CODE GENERATOR: MAX11043 Command Name = RegWrite CMD_1aaa_aaaa_REGISTER_READ (MAX11043_CMD_enum_t commandByte, uint32_t regData) --> uint8_t // CODE GENERATOR: MAX11043 Command Name = RegRead (MAX11043_CMD_enum_t commandByte, uint32_t* ptrRegData) --> uint8_t // CODE GENERATOR: no Menu item hint in description -// CODE GENERATOR: CommandDescriptionCMDWord = CMD_1aaa_aaaa_REGISTER_READ -// CODE GENERATOR: MAX11043 Command Name = RegRead CMD_1aaa_aaaa_REGISTER_READ (MAX11043_CMD_enum_t commandByte, uint32_t* ptrRegData) --> uint8_t // CODE GENERATOR: MAX11043 Command Name = RegSize (MAX11043_CMD_enum_t commandByte) --> uint8_t // CODE GENERATOR: no Menu item hint in description +// CODE GENERATOR: MAX11043 Command Name = DecodeCommand (MAX11043_CMD_enum_t commandByte) --> MAX11043::MAX11043_CMDOP_enum_t +// CODE GENERATOR: no Menu item hint in description // CODE GENERATOR: MAX11043 Command Name = RegAddrOfCommand (MAX11043_CMD_enum_t commandByte) --> uint8_t // CODE GENERATOR: no Menu item hint in description // CODE GENERATOR: MAX11043 Command Name = IsRegReadCommand (MAX11043_CMD_enum_t commandByte) --> uint8_t @@ -353,17 +351,37 @@ } } // end for regAddr // not a valid register name + Callback<void(size_t, uint8_t*, uint8_t*)> saved_onSPIprint_handler = g_MAX11043_device.onSPIprint; + g_MAX11043_device.onSPIprint = NULL; // temporarily suppress SPI diagnostic messages // read "all" registers by name - const uint8_t readAllRegFirst = 0x00; // first MAX11043 register address for read-all block - const uint8_t readAllRegLast = 0x39; // last MAX11043 register address for read-all block - Callback<void(size_t, uint8_t*, uint8_t*)> saved_onSPIprint_handler = g_MAX11043_device.onSPIprint; - g_MAX11043_device.onSPIprint = NULL; - for (uint8_t regAddress = readAllRegFirst; regAddress <= readAllRegLast; regAddress++) + // TODO: KLUDGE: this constant array should live in the device driver, not the menu + const MAX11043::MAX11043_CMD_enum_t readAllStatusList[] = { + MAX11043::CMD_0000_0010_d24_Rd00_ADCa, + MAX11043::CMD_0000_0110_d24_Rd01_ADCb, + MAX11043::CMD_0000_1010_d24_Rd02_ADCc, + MAX11043::CMD_0000_1110_d24_Rd03_ADCd, + MAX11043::CMD_0001_1110_d8_Rd07_Status, + MAX11043::CMD_0010_0010_d16_Rd08_Configuration, + MAX11043::CMD_0010_0110_d16_Rd09_DAC, + MAX11043::CMD_0010_1010_d16_Rd0A_DACStep, + MAX11043::CMD_0010_1110_d16_Rd0B_DACHDACL, + MAX11043::CMD_0011_0010_d16_Rd0C_ConfigA, + MAX11043::CMD_0011_0110_d16_Rd0D_ConfigB, + MAX11043::CMD_0011_1010_d16_Rd0E_ConfigC, + MAX11043::CMD_0011_1110_d16_Rd0F_ConfigD, + MAX11043::CMD_0100_0010_d16_Rd10_Reference, + MAX11043::CMD_0100_0110_d16_Rd11_AGain, + MAX11043::CMD_0100_1010_d16_Rd12_BGain, + MAX11043::CMD_0100_1110_d16_Rd13_CGain, + MAX11043::CMD_0101_0010_d16_Rd14_DGain, + }; + for (uint8_t readAllStatusIndex = 0; readAllStatusIndex < (sizeof(readAllStatusList)/sizeof(MAX11043::MAX11043_CMD_enum_t)); readAllStatusIndex++) { + MAX11043::MAX11043_CMD_enum_t regAddress = readAllStatusList[readAllStatusIndex]; uint32_t regData = 0; - if (g_MAX11043_device.RegSize((MAX11043::MAX11043_CMD_enum_t)regAddress) == 0) continue; // skip undefined regs - if (g_MAX11043_device.RegRead((MAX11043::MAX11043_CMD_enum_t)regAddress, ®Data) == 0) continue; // skip unreadable regs - cmdLine.serial().printf("%s=0x%6.6x\r\n", g_MAX11043_device.RegName((MAX11043::MAX11043_CMD_enum_t)regAddress), regData); + if (g_MAX11043_device.RegSize(regAddress) == 0) continue; // skip undefined regs + if (g_MAX11043_device.RegRead(regAddress, ®Data) == 0) continue; // skip unreadable regs + cmdLine.serial().printf("%s=0x%6.6x\r\n", g_MAX11043_device.RegName(regAddress), regData); } // end for regAddr g_MAX11043_device.onSPIprint = saved_onSPIprint_handler; return true; // command handled by MAX11043 @@ -577,14 +595,16 @@ if (cmdLine.parse_byteCount_byteList_hex(byteCount, mosiData, MAX_SPI_BYTE_COUNT)) { - // if length is 1 byte then operation is RegRead, otherwise RegWrite + // TODO: decode operation from commandByte + // TODO: OVERSIMPLIFICATION: if length is 1 byte then operation is RegRead, otherwise RegWrite // register_read_function 'IsRegReadCommand' // register_write_function 'RegWrite' // register_name_function 'RegName' // register_size_function 'RegSize' -// CODE GENERATOR: does the chip have a defined CMD_1aaa_aaaa_REGISTER_READ bit? - // MAX11043::MAX11043_CMD_enum_t regAddress = (MAX11043::MAX11043_CMD_enum_t)((mosiData[0] &~ MAX11043::CMD_1aaa_aaaa_REGISTER_READ) & 0xFF); +// CODE GENERATOR: does the chip have a defined CMDOP_1aaa_aaaa_ReadRegister bit? + // MAX11043::MAX11043_CMD_enum_t regAddress = (MAX11043::MAX11043_CMD_enum_t)((mosiData[0] &~ MAX11043::CMDOP_1aaa_aaaa_ReadRegister) & 0xFF); MAX11043::MAX11043_CMD_enum_t commandByte = (MAX11043::MAX11043_CMD_enum_t)(mosiData[0]); + MAX11043::MAX11043_CMDOP_enum_t commandOp = g_MAX11043_device.DecodeCommand(commandByte); int regAddress = g_MAX11043_device.RegAddrOfCommand(commandByte); cmdLine.serial().printf(" regAddress=0x%2.2x\r\n", (regAddress & 0xFF)); cmdLine.serial().printf(" RegName=%s\r\n", g_MAX11043_device.RegName(commandByte)); @@ -603,8 +623,8 @@ regData = (((uint32_t)mosiData[1] & 0xFF) << 16) + (((uint32_t)mosiData[2] & 0xFF) << 8) + ((uint32_t)mosiData[3] & 0xFF); break; } -// CODE GENERATOR: does the chip have a defined CMD_1aaa_aaaa_REGISTER_READ bit? - // if ((byteCount == 1) || (regAddress & MAX11043::CMD_1aaa_aaaa_REGISTER_READ)) +// CODE GENERATOR: does the chip have a defined CMDOP_1aaa_aaaa_ReadRegister bit? + // if ((byteCount == 1) || (regAddress & MAX11043::CMDOP_1aaa_aaaa_ReadRegister)) if ((byteCount == 1) || g_MAX11043_device.IsRegReadCommand(commandByte)) { cmdLine.serial().printf(" RegRead");