diff --git a/hwTestSuite/tests.c b/hwTestSuite/tests.c index 1d4ff89..99b4c62 100644 --- a/hwTestSuite/tests.c +++ b/hwTestSuite/tests.c @@ -105,8 +105,69 @@ var listDataRegisters(){ return makeVar(LENGTH_0, TYPE_NULL, 0); } +var checkSpi2EnableBitDelay(){ + static Boolean firstRun = true; + + if(firstRun){ + uint16_t y = 0; + uint16_t osSpi2Control = readArbitraryMemory16(HW_REG_ADDR(SPICONT2)) & 0xE030;/*use data rate, phase and polarity from OS*/ + + firstRun = false; + debugSafeScreenClear(C_WHITE); + + /*disable SPI2*/ + writeArbitraryMemory16(HW_REG_ADDR(SPICONT2), osSpi2Control);/*disable*/ + + /*try to enable and shift at the same time*/ + writeArbitraryMemory16(HW_REG_ADDR(SPIDATA2), 0xD4 << 8);/*write control byte, 0xD4 means read channel 5 in 12 bit reference mode*/ + writeArbitraryMemory16(HW_REG_ADDR(SPICONT2), osSpi2Control | 0x0200/*enable*/ | 0x0100/*exchange*/ | 0x000F);/*enable + exchange*/ + while(readArbitraryMemory16(HW_REG_ADDR(SPICONT2)) & 0x0100);/*wait on transfer*/ + StrPrintF(sharedDataBuffer, "Enable + Shift:"); + UG_PutString(0, y, sharedDataBuffer); + y += FONT_HEIGHT + 1; + StrPrintF(sharedDataBuffer, "SPIDATA2:0x%02X", readArbitraryMemory16(HW_REG_ADDR(SPIDATA2))); + UG_PutString(0, y, sharedDataBuffer); + y += FONT_HEIGHT + 1; + writeArbitraryMemory16(HW_REG_ADDR(SPICONT2), osSpi2Control);/*disable*/ + + /*try to disable and shift at the same time*/ + writeArbitraryMemory16(HW_REG_ADDR(SPICONT2), osSpi2Control | 0x0200/*enable*/);/*enable*/ + writeArbitraryMemory16(HW_REG_ADDR(SPIDATA2), 0xD4 << 8);/*write control byte, 0xD4 means read channel 5 in 12 bit reference mode*/ + writeArbitraryMemory16(HW_REG_ADDR(SPICONT2), osSpi2Control | 0x0100/*exchange*/ | 0x000F);/*disable + exchange*/ + while(readArbitraryMemory16(HW_REG_ADDR(SPICONT2)) & 0x0100);/*wait on transfer*/ + StrPrintF(sharedDataBuffer, "Disable + Shift:"); + UG_PutString(0, y, sharedDataBuffer); + y += FONT_HEIGHT + 1; + StrPrintF(sharedDataBuffer, "SPIDATA2:0x%02X", readArbitraryMemory16(HW_REG_ADDR(SPIDATA2))); + UG_PutString(0, y, sharedDataBuffer); + y += FONT_HEIGHT + 1; + + /*enable, shift then disable*/ + writeArbitraryMemory16(HW_REG_ADDR(SPICONT2), osSpi2Control | 0x0200/*enable*/);/*enable*/ + writeArbitraryMemory16(HW_REG_ADDR(SPIDATA2), 0xD4 << 8);/*write control byte, 0xD4 means read channel 5 in 12 bit reference mode*/ + writeArbitraryMemory16(HW_REG_ADDR(SPICONT2), osSpi2Control | 0x0200/*enable*/ | 0x0100/*exchange*/ | 0x000F);/*exchange*/ + while(readArbitraryMemory16(HW_REG_ADDR(SPICONT2)) & 0x0100);/*wait on transfer*/ + StrPrintF(sharedDataBuffer, "Enable, Shift, Disable:"); + UG_PutString(0, y, sharedDataBuffer); + y += FONT_HEIGHT + 1; + StrPrintF(sharedDataBuffer, "SPIDATA2:0x%02X", readArbitraryMemory16(HW_REG_ADDR(SPIDATA2))); + UG_PutString(0, y, sharedDataBuffer); + y += FONT_HEIGHT + 1; + writeArbitraryMemory16(HW_REG_ADDR(SPICONT2), osSpi2Control);/*disable*/ + } + + if(getButtonPressed(buttonBack)){ + firstRun = true; + exitSubprogram(); + } + + return makeVar(LENGTH_0, TYPE_NULL, 0); +} + var interrogateSpi2(){ static Boolean firstRun = true; + static uint32_t regAddresses[8] = {HW_REG_ADDR(PBDATA), HW_REG_ADDR(PCDATA), HW_REG_ADDR(PEDATA), HW_REG_ADDR(PFDATA), HW_REG_ADDR(PGDATA), HW_REG_ADDR(PJDATA), HW_REG_ADDR(PKDATA), HW_REG_ADDR(PMDATA)}; + static uint8_t registersDuringSpiRead[8];/*P(BCEFGJKM)DATA*/ uint16_t y = 0; if(firstRun){ @@ -119,48 +180,72 @@ var interrogateSpi2(){ exitSubprogram(); } - if(getButtonPressed(buttonSelect)){ - uint16_t osSpi2Control = readArbitraryMemory16(HW_REG_ADDR(SPICONT2)) & 0xE230;/*use data rate, phase and polarity from OS, also check if SPI2 is enabled*/ + if(getButton(buttonSelect)){ + uint8_t count; - writeArbitraryMemory16(HW_REG_ADDR(SPIDATA2), 0xD4 << 8); - writeArbitraryMemory16(HW_REG_ADDR(SPICONT2), osSpi2Control | 0x0200/*enable*/); - writeArbitraryMemory16(HW_REG_ADDR(SPICONT2), osSpi2Control | 0x0200/*enable*/ | 0x0100/*exchange*/ | 0x0007); + for(count = 0; count < sizeof(registersDuringSpiRead); count++){ + uint16_t osSpi2Control = readArbitraryMemory16(HW_REG_ADDR(SPICONT2)) & 0xE030;/*use data rate, phase and polarity from OS*/ + + /*enable SPI2*/ + writeArbitraryMemory16(HW_REG_ADDR(SPICONT2), osSpi2Control | 0x0200/*enable*/); + + /*flush the register*/ + writeArbitraryMemory16(HW_REG_ADDR(SPIDATA2), 0x0000); + writeArbitraryMemory16(HW_REG_ADDR(SPICONT2), osSpi2Control | 0x0200/*enable*/ | 0x0100/*exchange*/ | 0x0015); + while(readArbitraryMemory16(HW_REG_ADDR(SPICONT2)) & 0x0100); + + /*send control byte*/ + writeArbitraryMemory16(HW_REG_ADDR(SPIDATA2), 0xD4 << 8); + writeArbitraryMemory16(HW_REG_ADDR(SPICONT2), osSpi2Control | 0x0200/*enable*/ | 0x0100/*exchange*/ | 0x0007); + + /*final clock before busy, this should turn busy line on*/ + writeArbitraryMemory16(HW_REG_ADDR(SPICONT2), osSpi2Control | 0x0200/*enable*/ | 0x0100/*exchange*/ | 0x0007); + registersDuringSpiRead[count] = readArbitraryMemory8(regAddresses[count]); + } + } + else{ + uint8_t count; + + for(count = 0; count < sizeof(registersDuringSpiRead); count++) + registersDuringSpiRead[count] = readArbitraryMemory8(regAddresses[count]); } StrPrintF(sharedDataBuffer, "Select = ADS7846 Ch 5 Read"); UG_PutString(0, y, sharedDataBuffer); y += FONT_HEIGHT + 1; - StrPrintF(sharedDataBuffer, "PBDATA:0x%02X", readArbitraryMemory8(HW_REG_ADDR(PBDATA))); + StrPrintF(sharedDataBuffer, "PBDATA:0x%02X", regAddresses[0]); UG_PutString(0, y, sharedDataBuffer); y += FONT_HEIGHT + 1; - StrPrintF(sharedDataBuffer, "PCDATA:0x%02X", readArbitraryMemory8(HW_REG_ADDR(PCDATA))); + StrPrintF(sharedDataBuffer, "PCDATA:0x%02X", regAddresses[1]); UG_PutString(0, y, sharedDataBuffer); y += FONT_HEIGHT + 1; /*PDDATA is buttons, not relevent to the SPI*/ - StrPrintF(sharedDataBuffer, "PEDATA:0x%02X", readArbitraryMemory8(HW_REG_ADDR(PEDATA))); + StrPrintF(sharedDataBuffer, "PEDATA:0x%02X", regAddresses[2]); UG_PutString(0, y, sharedDataBuffer); y += FONT_HEIGHT + 1; - StrPrintF(sharedDataBuffer, "PFDATA:0x%02X", readArbitraryMemory8(HW_REG_ADDR(PFDATA))); + StrPrintF(sharedDataBuffer, "PFDATA:0x%02X", regAddresses[3]); UG_PutString(0, y, sharedDataBuffer); y += FONT_HEIGHT + 1; - StrPrintF(sharedDataBuffer, "PGDATA:0x%02X", readArbitraryMemory8(HW_REG_ADDR(PGDATA))); + StrPrintF(sharedDataBuffer, "PGDATA:0x%02X", regAddresses[4]); UG_PutString(0, y, sharedDataBuffer); y += FONT_HEIGHT + 1; - StrPrintF(sharedDataBuffer, "PJDATA:0x%02X", readArbitraryMemory8(HW_REG_ADDR(PJDATA))); + StrPrintF(sharedDataBuffer, "PJDATA:0x%02X", regAddresses[5]); UG_PutString(0, y, sharedDataBuffer); y += FONT_HEIGHT + 1; - StrPrintF(sharedDataBuffer, "PKDATA:0x%02X", readArbitraryMemory8(HW_REG_ADDR(PKDATA))); + StrPrintF(sharedDataBuffer, "PKDATA:0x%02X", regAddresses[6]); UG_PutString(0, y, sharedDataBuffer); y += FONT_HEIGHT + 1; - StrPrintF(sharedDataBuffer, "PMDATA:0x%02X", readArbitraryMemory8(HW_REG_ADDR(PMDATA))); + StrPrintF(sharedDataBuffer, "PMDATA:0x%02X", regAddresses[7]); UG_PutString(0, y, sharedDataBuffer); y += FONT_HEIGHT + 1; + /* StrPrintF(sharedDataBuffer, "PESEL:0x%02X", readArbitraryMemory8(HW_REG_ADDR(PESEL))); UG_PutString(0, y, sharedDataBuffer); y += FONT_HEIGHT + 1; StrPrintF(sharedDataBuffer, "PEDIR:0x%02X", readArbitraryMemory8(HW_REG_ADDR(PEDIR))); UG_PutString(0, y, sharedDataBuffer); y += FONT_HEIGHT + 1; + */ StrPrintF(sharedDataBuffer, "SPICONT2:0x%04X", readArbitraryMemory16(HW_REG_ADDR(SPICONT2))); UG_PutString(0, y, sharedDataBuffer); y += FONT_HEIGHT + 1; diff --git a/hwTestSuite/tests.h b/hwTestSuite/tests.h index 520f866..b0ab23b 100644 --- a/hwTestSuite/tests.h +++ b/hwTestSuite/tests.h @@ -5,6 +5,7 @@ var testButtonInput(); var listDataRegisters(); +var checkSpi2EnableBitDelay(); var interrogateSpi2(); var tstat1GetSemaphoreLockOrder(); var ads7846Read(); diff --git a/hwTestSuite/viewer.c b/hwTestSuite/viewer.c index 3db8c4e..6c452fd 100644 --- a/hwTestSuite/viewer.c +++ b/hwTestSuite/viewer.c @@ -344,6 +344,10 @@ void resetFunctionViewer(){ hwTests[totalHwTests].testFunction = ads7846Read; totalHwTests++; + StrNCopy(hwTests[totalHwTests].name, "Get SPI2 ENABLE Delay", TEST_NAME_LENGTH); + hwTests[totalHwTests].testFunction = checkSpi2EnableBitDelay; + totalHwTests++; + StrNCopy(hwTests[totalHwTests].name, "Interrogate SPI2", TEST_NAME_LENGTH); hwTests[totalHwTests].testFunction = interrogateSpi2; totalHwTests++; diff --git a/qtBuildSystem/Mu/Mu.pro.user b/qtBuildSystem/Mu/Mu.pro.user index 2b1edcc..cea58b2 100644 --- a/qtBuildSystem/Mu/Mu.pro.user +++ b/qtBuildSystem/Mu/Mu.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/src/hardwareRegistersAccessors.c.h b/src/hardwareRegistersAccessors.c.h index 59a3fd5..fb7536b 100644 --- a/src/hardwareRegistersAccessors.c.h +++ b/src/hardwareRegistersAccessors.c.h @@ -239,19 +239,20 @@ static inline void setSpiCont1(uint16_t value){ */ static inline void setSpiCont2(uint16_t value){ - //unsure if ENABLE can be set at the exact moment of write or must be set before write, currently allow both + //the ENABLE bit must be set before the transfer and in the transfer command //important bits are ENABLE, XCH, IRQ, IRQEN and BITCOUNT - //uint16_t oldSpiCont2 = registerArrayRead16(SPICONT2); - if(value & 0x0200 && value & 0x0100){ + uint16_t oldSpiCont2 = registerArrayRead16(SPICONT2); + if(value & oldSpiCont2 & 0x0200 && value & 0x0100){ //enabled and exchange set uint8_t bitCount = (value & 0x000F) + 1; uint16_t spi2Data = registerArrayRead16(SPIDATA2); - uint16_t oldSpi2Data = spi2Data; + //uint16_t oldSpi2Data = spi2Data; for(uint8_t bits = 0; bits < bitCount; bits++){ + //the Palm m515 seems to invert received bits ads7846SendBit(spi2Data & 0x8000); spi2Data <<= 1; - spi2Data |= ads7846RecieveBit(); + spi2Data |= !ads7846RecieveBit(); } registerArrayWrite16(SPIDATA2, spi2Data);