owaisfazal wrote on Monday, September 15, 2014:
Okay let me first included the necessary file into my project. I will continue from there on. One more thing, I just have the following functions related to HSMCI read and write can you please look into them and let me know if they would be sufficient for including int the F-DRIVER structure or do I need something else.
uint32_t hsmci_start_read_blocks(void *dest, uint16_t nb_block)
{
uint32_t nb_data;
nb_data = nb_block * hsmci_block_size;
// Handle unaligned memory address
if (((uint32_t)dest & 0x3) || (hsmci_block_size & 0x3))
{
HSMCI->HSMCI_MR |= HSMCI_MR_FBYTE;
}
else
{
HSMCI->HSMCI_MR &= ~HSMCI_MR_FBYTE;
}
// Configure PDC transfer
HSMCI->HSMCI_RPR = (uint32_t)dest;
HSMCI->HSMCI_RCR = (HSMCI->HSMCI_MR & HSMCI_MR_FBYTE) ? nb_data : nb_data / 4;
HSMCI->HSMCI_RNCR = 0;
// Start transfer
HSMCI->HSMCI_PTCR = HSMCI_PTCR_RXTEN;
hsmci_transfert_pos += nb_data;
return OK;
}
uint32_t hsmci_wait_end_of_read_blocks(void)
{
uint32_t sr;
// Wait end of transfer
// Note: no need of timeout, because it is include in HSMCI, see DTOE bit.
do
{
sr = HSMCI->HSMCI_SR;
if (sr & (HSMCI_SR_UNRE | HSMCI_SR_OVRE | HSMCI_SR_DTOE | HSMCI_SR_DCRCE))
{
HSMCI->HSMCI_PTCR = HSMCI_PTCR_RXTDIS | HSMCI_PTCR_TXTDIS;
hsmci_reset();
return FAIL;
}
} while (!(sr & HSMCI_SR_RXBUFF));
if (hsmci_transfert_pos < ((uint32_t)hsmci_block_size * hsmci_nb_block))
{
return OK;
}
// It is the last transfer, then wait command completed
// Note: no need of timeout, because it is include in HSMCI, see DTOE bit.
do
{
sr = HSMCI->HSMCI_SR;
if (sr & (HSMCI_SR_UNRE | HSMCI_SR_OVRE | HSMCI_SR_DTOE | HSMCI_SR_DCRCE))
{
hsmci_reset();
return FAIL;
}
} while (!(sr & HSMCI_SR_XFRDONE));
return OK;
}
uint32_t hsmci_start_write_blocks(const void *src, uint16_t nb_block)
{
uint32_t nb_data;
nb_data = nb_block * hsmci_block_size;
// Handle unaligned memory address
if (((uint32_t)src & 0x3) || (hsmci_block_size & 0x3))
{
HSMCI->HSMCI_MR |= HSMCI_MR_FBYTE;
}
else
{
HSMCI->HSMCI_MR &= ~HSMCI_MR_FBYTE;
}
// Configure PDC transfer
HSMCI->HSMCI_TPR = (uint32_t)src;
HSMCI->HSMCI_TCR = (HSMCI->HSMCI_MR & HSMCI_MR_FBYTE) ? nb_data : nb_data / 4;
HSMCI->HSMCI_TNCR = 0;
// Start transfer
HSMCI->HSMCI_PTCR = HSMCI_PTCR_TXTEN;
hsmci_transfert_pos += nb_data;
return OK;
}
uint32_t hsmci_wait_end_of_write_blocks(void)
{
uint32_t sr;
// Wait end of transfer
// Note: no need of timeout, because it is include in HSMCI, see DTOE bit.
do
{
sr = HSMCI->HSMCI_SR;
if (sr & (HSMCI_SR_UNRE | HSMCI_SR_OVRE | HSMCI_SR_DTOE | HSMCI_SR_DCRCE))
{
hsmci_reset();
HSMCI->HSMCI_PTCR = HSMCI_PTCR_RXTDIS | HSMCI_PTCR_TXTDIS;
return FAIL;
}
} while (!(sr & HSMCI_SR_TXBUFE));
if (hsmci_transfert_pos < ((uint32_t)hsmci_block_size * hsmci_nb_block))
{
return OK;
}
// It is the last transfer, then wait command completed
// Note: no need of timeout, because it is include in HSMCI, see DTOE bit.
do
{
sr = HSMCI->HSMCI_SR;
if (sr & (HSMCI_SR_UNRE | HSMCI_SR_OVRE | HSMCI_SR_DTOE | HSMCI_SR_DCRCE))
{
hsmci_reset();
return FAIL;
}
} while (!(sr & HSMCI_SR_NOTBUSY));
//Assert(HSMCI->HSMCI_SR & HSMCI_SR_FIFOEMPTY);
return OK;
}
These are from the Atmel Studio example of HSMCI interface unit test.
Thanks once again for your support.