@ -1,16 +1,16 @@
/*************************************************************************
/*************************************************************************
* This demo uses the BALibrary to provide enhanced control of
* This demo uses the BALibrary to provide enhanced control of
* the TGA Pro board .
* the TGA Pro board .
*
*
* The latest copy of the BALibrary can be obtained from
* The latest copy of the BALibrary can be obtained from
* https : //github.com/Blackaddr/BALibrary
* https : //github.com/Blackaddr/BALibrary
*
*
* This demo will perform a DMA memory test on MEM1 attached
* This demo will perform a DMA memory test on MEM1 attached
* to SPI1 .
* to SPI1 .
*
*
* NOTE : SPI MEM1 can be used by a Teensy 3.5 / 3.6 .
* NOTE : SPI MEM1 can be used by a Teensy 3.5 / 3.6 .
* pins .
* pins .
*
*
*/
*/
# include <Wire.h>
# include <Wire.h>
# include "BALibrary.h"
# include "BALibrary.h"
@ -30,7 +30,6 @@ using namespace BALibrary;
SPISettings memSettings ( 20000000 , MSBFIRST , SPI_MODE0 ) ;
SPISettings memSettings ( 20000000 , MSBFIRST , SPI_MODE0 ) ;
const int cs0pin = SPI1_CS_PIN ;
const int cs0pin = SPI1_CS_PIN ;
BAGpio gpio ; // access to User LED
BASpiMemoryDMA spiMem1 ( SpiDeviceId : : SPI_DEVICE1 ) ;
BASpiMemoryDMA spiMem1 ( SpiDeviceId : : SPI_DEVICE1 ) ;
bool compareBuffers ( uint8_t * a , uint8_t * b , size_t numBytes )
bool compareBuffers ( uint8_t * a , uint8_t * b , size_t numBytes )
@ -61,37 +60,35 @@ void setup() {
TGA_PRO_MKII_REV1 ( ) ; // Declare the version of the TGA Pro you are using.
TGA_PRO_MKII_REV1 ( ) ; // Declare the version of the TGA Pro you are using.
//TGA_PRO_REVB(x);
//TGA_PRO_REVB(x);
//TGA_PRO_REVA(x);
//TGA_PRO_REVA(x);
gpio . begin ( ) ;
Serial . begin ( 57600 ) ;
Serial . begin ( 57600 ) ;
while ( ! Serial ) { yield ( ) ; }
while ( ! Serial ) { yield ( ) ; }
delay ( 5 ) ;
delay ( 5 ) ;
SPI_MEM1_1 M ( ) ;
SPI_MEM1_64 M ( ) ;
SPI_MAX_ADDR = BAHardwareConfig . getSpiMemMaxAddr ( MemSelect : : MEM1 ) ;
SPI_MAX_ADDR = BAHardwareConfig . getSpiMemMaxAddr ( MemSelect : : MEM1 ) ;
Serial . println ( " Enabling SPI, testing MEM1 " ) ;
Serial . printf ( " Enabling SPI, testing MEM1, max address %08X \n \r " , SPI_MAX_ADDR ) ; Serial . flush ( ) ;
spiMem1 . begin ( ) ;
spiMem1 . begin ( ) ;
}
}
bool spi8BitTest ( void ) {
bool spi8BitTest ( void ) {
size_t spiAddress = 0 ;
size_t spiAddress = 0 ;
int spiPhase = 0 ;
int spiPhase = 0 ;
constexpr uint8_t MASK80 = 0xaa ;
constexpr uint8_t MASK80 = 0xaa ;
constexpr uint8_t MASK81 = 0x55 ;
constexpr uint8_t MASK81 = 0x55 ;
uint8_t src8 [ DMA_SIZE ] ;
uint8_t src8 [ DMA_SIZE ] ;
uint8_t dest8 [ DMA_SIZE ] ;
uint8_t dest8 [ DMA_SIZE ] ;
// Write to the memory using 8-bit transfers
// Write to the memory using 8-bit transfers
Serial . println ( " \n Starting 8-bit test Write/Read " ) ;
Serial . println ( " \n Starting 8-bit test Write/Read " ) ; Serial . flush ( ) ;
while ( spiPhase < 4 ) {
while ( spiPhase < 4 ) {
spiAddress = 0 ;
spiAddress = 0 ;
while ( spiAddress < = SPI_MAX_ADDR ) {
while ( spiAddress < = SPI_MAX_ADDR ) {
// fill the write data buffer
// fill the write data buffer
switch ( spiPhase ) {
switch ( spiPhase ) {
case 0 :
case 0 :
@ -114,15 +111,15 @@ bool spi8BitTest(void) {
src8 [ i ] = ( ( spiAddress + i ) & 0xff ) ^ ( ! MASK81 ) ;
src8 [ i ] = ( ( spiAddress + i ) & 0xff ) ^ ( ! MASK81 ) ;
}
}
break ;
break ;
}
}
// Send the DMA transfer
// Send the DMA transfer
spiMem1 . write ( spiAddress , src8 , DMA_SIZE ) ;
spiMem1 . write ( spiAddress , src8 , DMA_SIZE ) ;
// wait until write is done
// wait until write is done
while ( spiMem1 . isWriteBusy ( ) ) { }
while ( spiMem1 . isWriteBusy ( ) ) { }
spiAddress + = DMA_SIZE ;
spiAddress + = DMA_SIZE ;
}
}
// Read back the data using 8-bit transfers
// Read back the data using 8-bit transfers
spiAddress = 0 ;
spiAddress = 0 ;
while ( spiAddress < = SPI_MAX_ADDR ) {
while ( spiAddress < = SPI_MAX_ADDR ) {
@ -149,15 +146,15 @@ bool spi8BitTest(void) {
}
}
break ;
break ;
}
}
// Read back the DMA data
// Read back the DMA data
spiMem1 . read ( spiAddress , dest8 , DMA_SIZE ) ;
spiMem1 . read ( spiAddress , dest8 , DMA_SIZE ) ;
// wait until read is done
// wait until read is done
while ( spiMem1 . isReadBusy ( ) ) { }
while ( spiMem1 . isReadBusy ( ) ) { }
if ( ! compareBuffers ( src8 , dest8 , DMA_SIZE ) ) {
if ( ! compareBuffers ( src8 , dest8 , DMA_SIZE ) ) {
Serial . println ( String ( " ERROR @ " ) + spiAddress ) ;
Serial . println ( String ( " ERROR @ " ) + spiAddress ) ;
return false ; } // stop the test
return false ; } // stop the test
spiAddress + = DMA_SIZE ;
spiAddress + = DMA_SIZE ;
}
}
Serial . println ( String ( " Phase " ) + spiPhase + String ( " : 8-bit Write/Read test passed! " ) ) ;
Serial . println ( String ( " Phase " ) + spiPhase + String ( " : 8-bit Write/Read test passed! " ) ) ;
spiPhase + + ;
spiPhase + + ;
@ -169,7 +166,7 @@ bool spi8BitTest(void) {
}
}
# endif
# endif
Serial . println ( " \n Starting 8-bit test Zero/Read " ) ;
Serial . println ( " \n Starting 8-bit test Zero/Read " ) ; Serial . flush ( ) ;
// Clear the memory
// Clear the memory
spiAddress = 0 ;
spiAddress = 0 ;
memset ( src8 , 0 , DMA_SIZE ) ;
memset ( src8 , 0 , DMA_SIZE ) ;
@ -178,7 +175,7 @@ bool spi8BitTest(void) {
spiMem1 . zero ( spiAddress , DMA_SIZE ) ;
spiMem1 . zero ( spiAddress , DMA_SIZE ) ;
// wait until write is done
// wait until write is done
while ( spiMem1 . isWriteBusy ( ) ) { }
while ( spiMem1 . isWriteBusy ( ) ) { }
spiAddress + = DMA_SIZE ;
spiAddress + = DMA_SIZE ;
}
}
// Check the memory is clear
// Check the memory is clear
@ -188,8 +185,8 @@ bool spi8BitTest(void) {
spiMem1 . read ( spiAddress , dest8 , DMA_SIZE ) ;
spiMem1 . read ( spiAddress , dest8 , DMA_SIZE ) ;
// wait until read is done
// wait until read is done
while ( spiMem1 . isReadBusy ( ) ) { }
while ( spiMem1 . isReadBusy ( ) ) { }
if ( ! compareBuffers ( src8 , dest8 , DMA_SIZE ) ) { return false ; } // stop the test
if ( ! compareBuffers ( src8 , dest8 , DMA_SIZE ) ) { return false ; } // stop the test
spiAddress + = DMA_SIZE ;
spiAddress + = DMA_SIZE ;
}
}
Serial . println ( String ( " : 8-bit Zero/Read test passed! " ) ) ;
Serial . println ( String ( " : 8-bit Zero/Read test passed! " ) ) ;
return true ;
return true ;
@ -201,16 +198,16 @@ bool spi16BitTest(void) {
constexpr uint16_t MASK160 = 0xaaaa ;
constexpr uint16_t MASK160 = 0xaaaa ;
constexpr uint16_t MASK161 = 0x5555 ;
constexpr uint16_t MASK161 = 0x5555 ;
constexpr int NUM_DATA = DMA_SIZE / sizeof ( uint16_t ) ;
constexpr int NUM_DATA = DMA_SIZE / sizeof ( uint16_t ) ;
uint16_t src16 [ NUM_DATA ] ;
uint16_t src16 [ NUM_DATA ] ;
uint16_t dest16 [ NUM_DATA ] ;
uint16_t dest16 [ NUM_DATA ] ;
// Write to the memory using 16-bit transfers
// Write to the memory using 16-bit transfers
Serial . println ( " \n Starting 16-bit test " ) ;
Serial . println ( " \n Starting 16-bit test " ) ; Serial . flush ( ) ;
while ( spiPhase < 4 ) {
while ( spiPhase < 4 ) {
spiAddress = 0 ;
spiAddress = 0 ;
while ( spiAddress < = SPI_MAX_ADDR ) {
while ( spiAddress < = SPI_MAX_ADDR ) {
// fill the write data buffer
// fill the write data buffer
switch ( spiPhase ) {
switch ( spiPhase ) {
case 0 :
case 0 :
@ -234,14 +231,14 @@ bool spi16BitTest(void) {
}
}
break ;
break ;
}
}
// Send the DMA transfer
// Send the DMA transfer
spiMem1 . write16 ( spiAddress , src16 , NUM_DATA ) ;
spiMem1 . write16 ( spiAddress , src16 , NUM_DATA ) ;
// wait until write is done
// wait until write is done
while ( spiMem1 . isWriteBusy ( ) ) { }
while ( spiMem1 . isWriteBusy ( ) ) { }
spiAddress + = DMA_SIZE ;
spiAddress + = DMA_SIZE ;
}
}
// Read back the data using 8-bit transfers
// Read back the data using 8-bit transfers
spiAddress = 0 ;
spiAddress = 0 ;
while ( spiAddress < = SPI_MAX_ADDR ) {
while ( spiAddress < = SPI_MAX_ADDR ) {
@ -268,15 +265,15 @@ bool spi16BitTest(void) {
}
}
break ;
break ;
}
}
// Read back the DMA data
// Read back the DMA data
spiMem1 . read16 ( spiAddress , dest16 , NUM_DATA ) ;
spiMem1 . read16 ( spiAddress , dest16 , NUM_DATA ) ;
// wait until read is done
// wait until read is done
while ( spiMem1 . isReadBusy ( ) ) { }
while ( spiMem1 . isReadBusy ( ) ) { }
if ( ! compareBuffers16 ( src16 , dest16 , NUM_DATA ) ) {
if ( ! compareBuffers16 ( src16 , dest16 , NUM_DATA ) ) {
Serial . print ( " ERROR @ " ) ; Serial . println ( spiAddress , HEX ) ;
Serial . print ( " ERROR @ " ) ; Serial . println ( spiAddress , HEX ) ;
return false ; } // stop the test
return false ; } // stop the test
spiAddress + = DMA_SIZE ;
spiAddress + = DMA_SIZE ;
}
}
Serial . println ( String ( " Phase " ) + spiPhase + String ( " : 16-bit test passed! " ) ) ;
Serial . println ( String ( " Phase " ) + spiPhase + String ( " : 16-bit test passed! " ) ) ;
spiPhase + + ;
spiPhase + + ;
@ -287,7 +284,7 @@ bool spi16BitTest(void) {
}
}
# endif
# endif
Serial . println ( " \n Starting 16-bit test Zero/Read " ) ;
Serial . println ( " \n Starting 16-bit test Zero/Read " ) ; Serial . flush ( ) ;
// Clear the memory
// Clear the memory
spiAddress = 0 ;
spiAddress = 0 ;
memset ( src16 , 0 , DMA_SIZE ) ;
memset ( src16 , 0 , DMA_SIZE ) ;
@ -296,7 +293,7 @@ bool spi16BitTest(void) {
spiMem1 . zero16 ( spiAddress , NUM_DATA ) ;
spiMem1 . zero16 ( spiAddress , NUM_DATA ) ;
// wait until write is done
// wait until write is done
while ( spiMem1 . isWriteBusy ( ) ) { }
while ( spiMem1 . isWriteBusy ( ) ) { }
spiAddress + = DMA_SIZE ;
spiAddress + = DMA_SIZE ;
}
}
// Check the memory is clear
// Check the memory is clear
@ -306,8 +303,8 @@ bool spi16BitTest(void) {
spiMem1 . read16 ( spiAddress , dest16 , NUM_DATA ) ;
spiMem1 . read16 ( spiAddress , dest16 , NUM_DATA ) ;
// wait until read is done
// wait until read is done
while ( spiMem1 . isReadBusy ( ) ) { }
while ( spiMem1 . isReadBusy ( ) ) { }
if ( ! compareBuffers16 ( src16 , dest16 , NUM_DATA ) ) { return false ; } // stop the test
if ( ! compareBuffers16 ( src16 , dest16 , NUM_DATA ) ) { return false ; } // stop the test
spiAddress + = DMA_SIZE ;
spiAddress + = DMA_SIZE ;
}
}
Serial . println ( String ( " : 16-bit Zero/Read test passed! " ) ) ;
Serial . println ( String ( " : 16-bit Zero/Read test passed! " ) ) ;
return true ;
return true ;