I came across with a library for FAT file system. It is a library for embedded systems. In the example code I found some interesting lines which I do not understand.
Here is the problematic line::
sd_protocol.spiHwInit=(void *)atmega_spi_init;
where sd_protocol
is a struct SdSpiProtocol sd_protocol;
Here is the type definition:
struct _SdSpiProtocol
{
void *spiHwInterface;
euint8 (*spiHwInit)(void* spiHwInterface);
euint8 (*spiSendByte)(void* spiHwInterface,euint8 data);
};
typedef struct _SdSpiProtocol SdSpiProtocol;
and atmega_spi_init
is the following function:
euint8 atmega_spi_init(atmegaSpiInterface *iface)
{
euint8 i;
/* Unselect card */
PORTB |= iface->pinSelect;
/* Set as master, clock and chip select output */
DDR_SPI = (1<<DD_MOSI) | (1<<DD_SCK) | 1;
/* Enable SPI, master, set clock rate to fck/2 */
SPCR = (1<<SPE) | (1<<MSTR); /* fsck / 4 */
SPSR = 1; /* fsck / 2 */
/* Send 10 spi commands with card not selected */
for(i=0;i<10;i++)
atmega_spi_send(iface,0xff);
/* Select card */
PORTB &= ~(iface->pinSelect);
return(0);
}
sd_protocol.spiHwInit=(void *)atmega_spi_init;
this is not a function call, then what it is?
and I do not understand what this line supposed to do either, in the type definition:
euint8 (*spiHwInit)(void* spiHwInterface);
Thanks in advance!