bosko lekovic
/
IO_board_K22
K22 processor
Diff: SPIprotokol/SlaveSpi.h
- Revision:
- 18:6196688e2a94
- Parent:
- 12:ea2256d6c725
diff -r f99cdfd01d4e -r 6196688e2a94 SPIprotokol/SlaveSpi.h --- a/SPIprotokol/SlaveSpi.h Sat May 15 13:59:57 2021 +0200 +++ b/SPIprotokol/SlaveSpi.h Sun May 16 22:01:47 2021 +0200 @@ -32,46 +32,46 @@ public: -static int spiReadRegister( int ar ){ return *(int*)( _SPI_BASE + ar);} -static void spiWriteRegister( int ar, int d ){ *(int*)( _SPI_BASE + ar) = d;} + static int spiReadRegister( int ar ){ return *(int*)( _SPI_BASE + ar);} + static void spiWriteRegister( int ar, int d ){ *(int*)( _SPI_BASE + ar) = d;} -static void inic_slaveSpi( void ) -{ - NVIC_DisableIRQ( _SPI_IRQn ); - _CS = 1; - wait_us(10); - _CS = 0; - spiWriteRegister(0, spiReadRegister(0) | 0x3c00); /* 0x00000C00 = ciscenje rx i tx buffer-a*/ - spiWriteRegister(0x2c, spiReadRegister(0x2c) | 0x80000000); /* TCF clear */ - spiWriteRegister(0x30, spiReadRegister(0x30) | 0x80000000); /* transfer interrupt enable */ + static void inic_slaveSpi( void ) + { + NVIC_DisableIRQ( _SPI_IRQn ); + _CS = 1; + wait_us(10); + _CS = 0; + spiWriteRegister(0, spiReadRegister(0) | 0x3c00); /* 0x00000C00 = ciscenje rx i tx buffer-a*/ + //! spiWriteRegister(0x2c, spiReadRegister(0x2c) | 0x80000000); /* TCF clear */ + //! spiWriteRegister(0x30, spiReadRegister(0x30) | 0x80000000); /* transfer interrupt enable */ + + spiWriteRegister(0x34, writeData); /* data for transmit */ + } - spiWriteRegister(0x34, writeData); /* data for transmit */ -} - -static void ff(void ) -{ - if( ( spiReadRegister(0x2c)) & 0x80000000 ) + static void ff(void ) { - spiWriteRegister(0x2c, spiReadRegister(0x2c) | 0x80000000); - readData = spiReadRegister(0x38); /* data register read */ - spiWriteRegister(0x34, writeData); /* data for transmit */ - + if( ( spiReadRegister(0x2c)) & 0x80000000 ) + { + spiWriteRegister(0x2c, spiReadRegister(0x2c) | 0x80000000); + readData = spiReadRegister(0x38); /* data register read */ + spiWriteRegister(0x34, writeData); /* data for transmit */ - _transferFlag = 1; - ef.set(1); + + _transferFlag = 1; + ef.set(1); + } + + // else { ledG =! ledG; inic_slaveSpi( ); set_slaveSpiInterrupt(ff);} + // ledC =! ledC; + // spiByteTransfer( &writeData, readData ); } - // else { ledG =! ledG; inic_slaveSpi( ); set_slaveSpiInterrupt(ff);} - // ledC =! ledC; -// spiByteTransfer( &writeData, readData ); -} + static void set_slaveSpiInterrupt( pfv p_fun ) + { + NVIC_SetVector( _SPI_IRQn, (int)p_fun ); // varijanta sa static ff() + NVIC_EnableIRQ( _SPI_IRQn ); -static void set_slaveSpiInterrupt( pfv p_fun ) -{ - NVIC_SetVector( _SPI_IRQn, (int)p_fun ); // varijanta sa static ff() - NVIC_EnableIRQ( _SPI_IRQn ); - -} + } // class C_slaveSpi: SPISlave, C_thread // { @@ -123,7 +123,11 @@ char get_bitCount( void ) { return bitCount;} - void clear_bitCount( void ) { /*ledG =! ledG;*/ bitCount = 0; inic_slaveSpi( ); set_slaveSpiInterrupt(ff);} + void clear_bitCount( void ) { /*ledG =! ledG;*/ + bitCount = 0; + inic_slaveSpi( ); + set_slaveSpiInterrupt(ff); + } void spi_monitor( void ){};