0,0 → 1,166 |
#include <avr/io.h> |
#include "fat16.h" |
#include "ssc.h" |
|
//________________________________________________________________________________________________________________________________________ |
// Module name: fat16.c |
// Compiler used: avr-gcc 3.4.5 |
// Last Modifikation: 24.07.2007 |
// Version: 1.03 |
// Authors: Stephan Busker |
// Description: Source files for access to the synchrnous serial channel. |
// Copyright (C) 2007 Stephan Busker |
//........................................................................................................................................ |
// Functions: extern void SSC_Init(void); |
// extern u8 SSC_GetChar (void); |
// extern void SSC_PutChar (u8 Byte); |
// extern void SSC_Disable(void); |
// extern void SSC_Enable(void); |
//........................................................................................................................................ |
// ext. functions: extern u8 SDC_GetSector (u32,u8*); |
// extern u8 SDC_PutSector (u32,u8*); |
//........................................................................................................................................ |
// |
// URL: www.Mikro-Control.de |
// mailto: stephan.busker@mikro-control.de |
//________________________________________________________________________________________________________________________________________ |
|
|
|
|
//________________________________________________________________________________________________________________________________________ |
// Funtion: SSC_Init(void); |
// |
// Description: This function initialises the synchronus serial channel to the sdcard. |
// |
// |
// Returnvalue: none |
//________________________________________________________________________________________________________________________________________ |
|
void SSC_Init(void) |
{ |
MMC_Direction_REG &=~(1<<SPI_DI); // Set the direction of the ssc-port |
MMC_Direction_REG |= (1<<SPI_Clock); // _______ _______ |
MMC_Direction_REG |= (1<<SPI_DO); // CS \________________________/ |
MMC_Direction_REG |= (1<<MMC_Chip_Select); // |
MMC_Direction_REG |= (1<<SPI_SS); // ___ ___ ___ |
// clk __________/ \___/ \___/ \_________ |
// |
SSC_Disable(); // ___ ___ |
// data_________/ \___________/ \___________ |
|
// initialise ssc, clock = Idel low |
// devide clock by 32 |
SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR1)|(1<<CPOL); // Enable SSC in mastermode, invert clockpolarity (idle high) |
SPSR = SPSR|(1<<SPI2X); |
} |
|
|
|
|
//________________________________________________________________________________________________________________________________________ |
// Funtion: void SSC_ClearRxFifo(void); |
// |
// Description: Clears the fifo of the ssc if the controller used has a builtin fifo. |
// |
// |
// Returnvalue: none |
//________________________________________________________________________________________________________________________________________ |
|
|
void SSC_ClearRxFifo(void) |
{ |
// enter your code here to clear the rx-fifo of the ssc. |
} |
|
|
|
//________________________________________________________________________________________________________________________________________ |
// Funtion: SSC_GetChar(void); |
// |
// Description: This function reads one byte from the SSC |
// |
// |
// Returnvalue: the byte received. |
//________________________________________________________________________________________________________________________________________ |
|
u8 SSC_GetChar (void) |
{ |
u8 Byte = 0; |
|
SPDR = 0x00; // read one byte of data from the SSC |
while(!(SPSR & (1<<SPIF))){}; // wait until the data has been read. |
Byte = SPDR; |
|
#ifdef __MMC_INTERFACE_INVERTED |
return (~Byte); |
#else |
return (Byte); // the byte received |
#endif |
|
|
} |
|
|
//________________________________________________________________________________________________________________________________________ |
// Funtion: SSC_PutChar(u8 Byte); |
// |
// Description: This function writes one byte to the SSC |
// |
// |
// Returnvalue: none |
//________________________________________________________________________________________________________________________________________ |
|
void SSC_PutChar (u8 Byte) |
{ |
#ifdef __MMC_INTERFACE_INVERTED |
SPDR = ~Byte; // send one byte of data to the SSC |
#else |
SPDR = Byte; // send one byte of data to the SSC |
#endif |
SPDR = ~Byte; // send one byte of data to the SSC |
while(!(SPSR & (1<<SPIF))) // wait until data was send. |
{ |
} |
} |
|
|
//________________________________________________________________________________________________________________________________________ |
// Funtion: SSC_Disable(void); |
// |
// Description: This function enables chipselect of the sdcard (active low) |
// |
// |
// Returnvalue: none |
//________________________________________________________________________________________________________________________________________ |
|
void SSC_Disable(void) |
{ |
#ifdef __MMC_INTERFACE_INVERTED |
MMC_Write &= ~(1<<MMC_Chip_Select); // disable chipselect of the sdcard (active low). |
#else |
MMC_Write |= (1<<MMC_Chip_Select); // enable chipselect of the sdcard (active low). |
#endif |
} |
|
|
|
|
//________________________________________________________________________________________________________________________________________ |
// Funtion: SSC_Enable(void); |
// |
// Description: This function disables chipselect of the sdcard (active low) |
// |
// |
// Returnvalue: none |
//________________________________________________________________________________________________________________________________________ |
|
void SSC_Enable(void) |
{ |
#ifdef __MMC_INTERFACE_INVERTED |
MMC_Write |= (1<<MMC_Chip_Select); // enable chipselect of the sdcard (active low). |
#else |
MMC_Write &= ~(1<<MMC_Chip_Select); // disable chipselect of the sdcard (active low). |
#endif |
} |
|