2016-10-20 22:19:53 +00:00
|
|
|
#include <alt_types.h>
|
|
|
|
#include <altera_avalon_pio_regs.h>
|
|
|
|
#include <sys/alt_timestamp.h>
|
|
|
|
#include <system.h>
|
|
|
|
#include <io.h>
|
|
|
|
#include "i2c_opencores.h"
|
2016-10-16 09:53:54 +00:00
|
|
|
#include "spi_io.h"
|
2016-10-20 22:19:53 +00:00
|
|
|
#include "av_controller.h"
|
2016-10-16 09:53:54 +00:00
|
|
|
|
2017-10-28 09:10:54 +00:00
|
|
|
extern alt_u16 sys_ctrl;
|
2016-10-20 22:19:53 +00:00
|
|
|
|
|
|
|
alt_u32 sd_timer_ts;
|
2016-10-16 09:53:54 +00:00
|
|
|
|
|
|
|
void SPI_Init (void) {
|
2016-10-20 22:19:53 +00:00
|
|
|
I2C_init(SD_SPI_BASE,ALT_CPU_FREQ,400000);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SPI_W(BYTE *wd, int len) {
|
|
|
|
SPI_write(SD_SPI_BASE, wd, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SPI_R(BYTE *rd, int len) {
|
|
|
|
SPI_read(SD_SPI_BASE, rd, len);
|
2016-10-16 09:53:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BYTE SPI_RW (BYTE d) {
|
2016-10-20 22:19:53 +00:00
|
|
|
BYTE w;
|
|
|
|
SPI_R(&w, 1);
|
2016-10-16 09:53:54 +00:00
|
|
|
|
2016-10-20 22:19:53 +00:00
|
|
|
return w;
|
2016-10-16 09:53:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SPI_Release (void) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void SPI_CS_Low (void) {
|
2016-10-20 22:19:53 +00:00
|
|
|
sys_ctrl &= ~SD_SPI_SS_N;
|
|
|
|
IOWR_ALTERA_AVALON_PIO_DATA(PIO_0_BASE, sys_ctrl);
|
2016-10-16 09:53:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void SPI_CS_High (void){
|
2016-10-20 22:19:53 +00:00
|
|
|
sys_ctrl |= SD_SPI_SS_N;
|
|
|
|
IOWR_ALTERA_AVALON_PIO_DATA(PIO_0_BASE, sys_ctrl);
|
2016-10-16 09:53:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void SPI_Freq_High (void) {
|
2016-10-20 22:19:53 +00:00
|
|
|
I2C_init(SD_SPI_BASE,ALT_CPU_FREQ,ALT_CPU_FREQ/SCL_MIN_CLKDIV);
|
2016-10-16 09:53:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void SPI_Freq_Low (void) {
|
2016-10-20 22:19:53 +00:00
|
|
|
I2C_init(SD_SPI_BASE,ALT_CPU_FREQ,400000);
|
2016-10-16 09:53:54 +00:00
|
|
|
}
|
|
|
|
|
2016-10-26 22:08:23 +00:00
|
|
|
int SPI_Timer_On (WORD ms) {
|
|
|
|
if (!sd_timer_ts) {
|
|
|
|
sd_timer_ts = ms*(ALT_CPU_FREQ/1000);
|
|
|
|
alt_timestamp_start();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
2016-10-16 09:53:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline BOOL SPI_Timer_Status (void) {
|
2016-10-20 22:19:53 +00:00
|
|
|
return alt_timestamp() < sd_timer_ts;
|
2016-10-16 09:53:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void SPI_Timer_Off (void) {
|
2016-10-26 22:08:23 +00:00
|
|
|
sd_timer_ts = 0;
|
2016-10-20 22:19:53 +00:00
|
|
|
return;
|
2016-10-16 09:53:54 +00:00
|
|
|
}
|