
#ifndef _SD_ROUTINES_H
#define _SD_ROUTINES_H

	#include "stm32l1xx.h"
	#include "ff.h"
	#include "crc.h"
	#include "routines.h"
	#include "speaker.h"
	#include "debug.h"
	#include "crc.h"
	#include "global.h"

	#define _500kHz 	64
	#define _16MHz		2

	BYTE SD_init(void);
	BYTE SD_sendCommand(BYTE, DWORD);
	BYTE SD_readSingleBlock(DWORD, BYTE *);
	BYTE SD_writeSingleBlock(DWORD, BYTE *);
	BYTE SD_readMultipleBlock (DWORD, DWORD, BYTE *);
	BYTE SD_writeMultipleBlock(DWORD, DWORD, BYTE *);
	BYTE SD_erase (DWORD, DWORD);
	DWORD GetSystemTime (void);
	BYTE SPI_transmit(BYTE);
	BYTE check_SD_write_permission(void);
	BYTE check_SD_insertion(void);
	BYTE crc7_calc (BYTE *, BYTE);
	BYTE crc7 (BYTE *);
	WORD crc16(BYTE *, WORD);
	void gen_crc7_syndrome_table (void);
	void SD_SpiInit (WORD);
	void SetSdTimer (DWORD);
	void SetInitSdTimer (DWORD);
	void SetSPITimer (DWORD);
	DWORD GetSystemTime(void);
	BYTE check_SD_insertion(void);
	BYTE SD_erase (DWORD, DWORD);


#endif



