Fork of RTOS_SPI that removes SimpleDMA from direct include to correct linker issues when using SimpleDMA twice Note that this library is still required!

Dependents:   FlashM25PSpi

Fork of RTOS_SPI by Erik -

Committer:
Tomo2k
Date:
Tue Aug 19 16:47:40 2014 +0000
Revision:
5:f6a414f1f342
Parent:
2:d052724e2ad6
Removed SimpleDMA due to linker trouble; This library is still required but not directly included

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Sissors 0:004e5e86de4e 1 #ifndef RTOS_SPI_H
Sissors 0:004e5e86de4e 2 #define RTOS_SPI_H
Sissors 0:004e5e86de4e 3
Sissors 0:004e5e86de4e 4 #include "mbed.h"
Sissors 0:004e5e86de4e 5 #include "rtos.h"
Sissors 0:004e5e86de4e 6 #include "SimpleDMA.h"
Sissors 0:004e5e86de4e 7
Sissors 0:004e5e86de4e 8 /**
Sissors 0:004e5e86de4e 9 * RTOS_SPI uses SimpleDMA to control SPI using DMA.
Sissors 0:004e5e86de4e 10 *
Sissors 0:004e5e86de4e 11 * As the name says it is intended to be used with RTOS.
Sissors 0:004e5e86de4e 12 * The current Thread is paused until it is done, meanwhile
Sissors 0:004e5e86de4e 13 * other Threads will continue to run. Once finished the
Sissors 0:004e5e86de4e 14 * Thread will continue.
Sissors 0:004e5e86de4e 15 *
Sissors 0:004e5e86de4e 16 * This is a child class of SPI, so all regular SPI functions
Sissors 0:004e5e86de4e 17 * are available + two for DMA control.
Tomo2k 2:d052724e2ad6 18 *
Tomo2k 2:d052724e2ad6 19 * @note Only supports 8-bit SPI. The 16-bit SPI mode of the KL46Z is not supported.
Sissors 0:004e5e86de4e 20 */
Sissors 0:004e5e86de4e 21 class RTOS_SPI: public SPI {
Sissors 0:004e5e86de4e 22 public:
Sissors 0:004e5e86de4e 23 /** Create a SPI master connected to the specified pins
Sissors 0:004e5e86de4e 24 *
Sissors 0:004e5e86de4e 25 * mosi or miso can be specfied as NC if not used
Sissors 0:004e5e86de4e 26 *
Sissors 0:004e5e86de4e 27 * @param mosi - SPI Master Out, Slave In pin
Sissors 0:004e5e86de4e 28 * @param miso - SPI Master In, Slave Out pin
Sissors 0:004e5e86de4e 29 * @param sclk - SPI Clock pin
Sissors 0:004e5e86de4e 30 */
Sissors 0:004e5e86de4e 31 RTOS_SPI(PinName mosi, PinName miso, PinName sclk, PinName _unused=NC);
Sissors 0:004e5e86de4e 32
Sissors 0:004e5e86de4e 33 /**
Sissors 0:004e5e86de4e 34 * Write a block of data via SPI
Sissors 0:004e5e86de4e 35 *
Sissors 0:004e5e86de4e 36 * This throws away all read data
Sissors 0:004e5e86de4e 37 *
Sissors 0:004e5e86de4e 38 * @param *write_data - uint8_t pointer to data to write
Sissors 0:004e5e86de4e 39 * @param length - number of bytes to write
Sissors 0:004e5e86de4e 40 * @param array - true if write_data is an array, false if it is a single constant value
Sissors 0:004e5e86de4e 41 */
Tomo2k 2:d052724e2ad6 42 void bulkWrite(const uint8_t *write_data, int length, bool array = true) {
Sissors 0:004e5e86de4e 43 uint8_t dummy;
Sissors 0:004e5e86de4e 44 bulkInternal(&dummy, write_data, length, false, array);
Sissors 0:004e5e86de4e 45 }
Sissors 0:004e5e86de4e 46
Sissors 0:004e5e86de4e 47 /**
Sissors 0:004e5e86de4e 48 * Write a block of data via SPI, read returning value
Sissors 0:004e5e86de4e 49 *
Sissors 0:004e5e86de4e 50 * @param *read_data - uint8_t pointer to array where received data should be stored
Sissors 0:004e5e86de4e 51 * @param *write_data - uint8_t pointer to data to write
Sissors 0:004e5e86de4e 52 * @param length - number of bytes to write
Sissors 0:004e5e86de4e 53 * @param array - true if write_data is an array, false if it is a single constant value
Sissors 0:004e5e86de4e 54 */
Tomo2k 2:d052724e2ad6 55 void bulkReadWrite(uint8_t *read_data, const uint8_t *write_data, int length, bool array = true) {
Sissors 0:004e5e86de4e 56 bulkInternal(read_data, write_data, length, true, array);
Sissors 0:004e5e86de4e 57 }
Sissors 0:004e5e86de4e 58
Sissors 0:004e5e86de4e 59 private:
Tomo2k 2:d052724e2ad6 60 void bulkInternal(uint8_t *read_data, const uint8_t *write_data, int length, bool read_inc, bool write_inc);
Sissors 0:004e5e86de4e 61
Sissors 0:004e5e86de4e 62 SimpleDMA read_dma;
Sissors 0:004e5e86de4e 63 SimpleDMA write_dma;
Sissors 0:004e5e86de4e 64
Sissors 0:004e5e86de4e 65 };
Sissors 0:004e5e86de4e 66
Sissors 0:004e5e86de4e 67
Sissors 0:004e5e86de4e 68 #endif