Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*! ----------------------------------------------------------------------------
- * @file deca_spi.c
- * @brief SPI access functions
- *
- * @attention
- *
- * Copyright 2013 (c) DecaWave Ltd, Dublin, Ireland.
- *
- * All rights reserved.
- *
- * @author DecaWave
- */
- #include "deca_spi.h"
- #include "deca_device_api.h"
- /*! ------------------------------------------------------------------------------------------------------------------
- * Function: openspi()
- *
- * Low level abstract function to open and initialise access to the SPI device.
- * returns 0 for success, or -1 for error
- */
- int openspi(/*SPI_TypeDef* SPIx*/)
- {
- return 0;
- } // end openspi()
- /*! ------------------------------------------------------------------------------------------------------------------
- * Function: closespi()
- *
- * Low level abstract function to close the the SPI device.
- * returns 0 for success, or -1 for error
- */
- int closespi(void)
- {
- return 0;
- } // end closespi()
- /*! ------------------------------------------------------------------------------------------------------------------
- * Function: writetospi()
- *
- * Low level abstract function to write to the SPI
- * Takes two separate byte buffers for write header and write data
- * returns 0 for success, or -1 for error
- */
- uint8_t spi_recieve_byte(uint8_t b)
- {
- SPDR = b;
- while(!(SPSR & (1<<SPIF)));
- return SPDR;
- }
- int writetospi(uint16 headerLength, const uint8 *headerBuffer, uint32 bodylength, const uint8 *bodyBuffer)
- {
- decaIrqStatus_t stat ;
- //stat = decamutexon() ;
- digitalWrite(10, LOW);
- for (uint8_t i = 0; i < headerLength; i++)
- spi_recieve_byte(headerBuffer[i]);
- for (uint8_t i = 0; i < bodylength; i++)
- spi_recieve_byte(bodyBuffer[i]);
- digitalWrite(10, HIGH);
- //decamutexoff(stat) ;
- return 0;
- } // end writetospi()
- /*! ------------------------------------------------------------------------------------------------------------------
- * Function: readfromspi()
- *
- * Low level abstract function to read from the SPI
- * Takes two separate byte buffers for write header and read data
- * returns the offset into read buffer where first byte of read data may be found,
- * or returns -1 if there was an error
- */
- int readfromspi(uint16 headerLength, const uint8 *headerBuffer, uint32 readlength, uint8 *readBuffer)
- {
- decaIrqStatus_t stat ;
- //stat = decamutexon() ;
- digitalWrite(10, LOW);
- for (uint8_t i = 0; i < headerLength; i++)
- spi_recieve_byte(headerBuffer[i]);
- for (uint8_t i = 0; i < readlength; i++)
- readBuffer[i] = spi_recieve_byte(0);
- digitalWrite(10, HIGH);
- //decamutexoff(stat) ;
- return 0;
- } // end readfromspi()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement