|
|
|
|
|
|
|
|
|
|
|
#ifndef _SPIFIFO_h_ |
|
|
|
|
|
#define _SPIFIFO_h_ |
|
|
|
|
|
|
|
|
#include "avr_emulation.h" |
|
|
#include "avr_emulation.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if F_BUS == 48000000 |
|
|
#if F_BUS == 48000000 |
|
|
|
|
|
|
|
|
|
|
|
#define HAS_SPIFIFO |
|
|
#define SPI_CLOCK_24MHz (SPI_CTAR_PBR(0) | SPI_CTAR_BR(0) | SPI_CTAR_DBR) //(48 / 2) * ((1+1)/2) |
|
|
#define SPI_CLOCK_24MHz (SPI_CTAR_PBR(0) | SPI_CTAR_BR(0) | SPI_CTAR_DBR) //(48 / 2) * ((1+1)/2) |
|
|
#define SPI_CLOCK_16MHz (SPI_CTAR_PBR(1) | SPI_CTAR_BR(0) | SPI_CTAR_DBR) //(48 / 3) * ((1+1)/2) 33% duty cycle |
|
|
#define SPI_CLOCK_16MHz (SPI_CTAR_PBR(1) | SPI_CTAR_BR(0) | SPI_CTAR_DBR) //(48 / 3) * ((1+1)/2) 33% duty cycle |
|
|
#define SPI_CLOCK_12MHz (SPI_CTAR_PBR(0) | SPI_CTAR_BR(0)) //(48 / 2) * ((1+0)/2) |
|
|
#define SPI_CLOCK_12MHz (SPI_CTAR_PBR(0) | SPI_CTAR_BR(0)) //(48 / 2) * ((1+0)/2) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#elif F_BUS == 24000000 |
|
|
#elif F_BUS == 24000000 |
|
|
|
|
|
|
|
|
|
|
|
#define HAS_SPIFIFO |
|
|
#define SPI_CLOCK_24MHz (SPI_CTAR_PBR(0) | SPI_CTAR_BR(0) | SPI_CTAR_DBR) //(24 / 2) * ((1+1)/2) 12 MHz |
|
|
#define SPI_CLOCK_24MHz (SPI_CTAR_PBR(0) | SPI_CTAR_BR(0) | SPI_CTAR_DBR) //(24 / 2) * ((1+1)/2) 12 MHz |
|
|
#define SPI_CLOCK_16MHz (SPI_CTAR_PBR(0) | SPI_CTAR_BR(0) | SPI_CTAR_DBR) //(24 / 2) * ((1+1)/2) 12 MHz |
|
|
#define SPI_CLOCK_16MHz (SPI_CTAR_PBR(0) | SPI_CTAR_BR(0) | SPI_CTAR_DBR) //(24 / 2) * ((1+1)/2) 12 MHz |
|
|
#define SPI_CLOCK_12MHz (SPI_CTAR_PBR(0) | SPI_CTAR_BR(0) | SPI_CTAR_DBR) //(24 / 2) * ((1+1)/2) |
|
|
#define SPI_CLOCK_12MHz (SPI_CTAR_PBR(0) | SPI_CTAR_BR(0) | SPI_CTAR_DBR) //(24 / 2) * ((1+1)/2) |
|
|
|
|
|
|
|
|
// DBR = 0, 1 -- zero preferred |
|
|
// DBR = 0, 1 -- zero preferred |
|
|
// BR = 2, 4, 6, 8, 16, 32, 64, 128, 256, 512 |
|
|
// BR = 2, 4, 6, 8, 16, 32, 64, 128, 256, 512 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAS_SPIFIFO |
|
|
|
|
|
|
|
|
#ifndef SPI_MODE0 |
|
|
#ifndef SPI_MODE0 |
|
|
#define SPI_MODE0 0x00 // CPOL = 0, CPHA = 0 |
|
|
#define SPI_MODE0 0x00 // CPOL = 0, CPHA = 0 |
|
|
#define SPI_MODE1 0x04 // CPOL = 0, CPHA = 1 |
|
|
#define SPI_MODE1 0x04 // CPOL = 0, CPHA = 1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define SPI_CONTINUE 1 |
|
|
#define SPI_CONTINUE 1 |
|
|
|
|
|
|
|
|
static uint8_t pcs = 0; |
|
|
|
|
|
static volatile uint8_t *reg = 0; |
|
|
|
|
|
|
|
|
|
|
|
class SPIFIFOclass |
|
|
class SPIFIFOclass |
|
|
{ |
|
|
{ |
|
|
public: |
|
|
public: |
|
|
|
|
|
|
|
|
inline void clear(void) __attribute__((always_inline)) { |
|
|
inline void clear(void) __attribute__((always_inline)) { |
|
|
SPI0.MCR = SPI_MCR_MSTR | SPI_MCR_PCSIS(0x1F) | SPI_MCR_CLR_TXF | SPI_MCR_CLR_RXF; |
|
|
SPI0.MCR = SPI_MCR_MSTR | SPI_MCR_PCSIS(0x1F) | SPI_MCR_CLR_TXF | SPI_MCR_CLR_RXF; |
|
|
} |
|
|
} |
|
|
|
|
|
private: |
|
|
|
|
|
static uint8_t pcs; |
|
|
|
|
|
static volatile uint8_t *reg; |
|
|
}; |
|
|
}; |
|
|
extern SPIFIFOclass SPIFIFO; |
|
|
extern SPIFIFOclass SPIFIFO; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
#endif |