The function below reads an image a page at a time using read_page(pageIter, pageArr, PAGESIZE) and outputs the data on the DOUT AND CCLK pins.
I was told it was inefficient but I can’t seem to find a way to make it faster. It is basically a pipe ,running on a 64 pin uProcessor, between two memory spaces. One holds the image and the other receives the image.
I’ve used the register keyword, removed array indexing and replaced with pointer arithemetic, but it needs to be faster.
Thanks!
/*
Port C Pin Out
*/
#define BIT0 0x01 // CCLK
#define BIT1 0x02 // CS_B
#define BIT2 0x04 // INIT_B
#define BIT3 0x08 // PROG_B
#define BIT4 0x10 // RDRW_B
#define BIT5 0x20 // BUSY_OUT
#define BIT6 0x40 // DONE
#define BIT7 0x80 // DOUT (DIN)
/*
PAGE
*/
#define PAGESIZE 1024 // Example
void copyImage(ulong startAddress, ulong endAddress)
{
ulong pageIter;
uchar *eByte, *byteIter, pageArr[PAGESIZE];
register uchar bitIter, portCvar;
portCvar = PORTC;
/* Loops through pages in an image using ulong type*/
for(pageIter = startAddress ; pageIter <= endAddress ; pageIter += PAGESIZE)
{
read_page(pageIter, pageArr, PAGESIZE);
eByte = pageArr+PAGESIZE;
/* Loops through bytes in a page using pointer to uchar (pointer to a byte)*/
for(byteIter = pageArr; byteIter <= eByte; byteIter++)
{
/* Loops through bits in byte and writes to PORTC - DIN ANC CCLK */
for(bitIter = 0x01; bitIter != 0x00; bitIter = bitIter << 1)
{
PORTC = portCvar | BIT0;
(bitIter & *byteIter) ? (PORTC = portCvar & ~BIT7) : (PORTC = portCvar | BIT7);
PORTC = portCvar & ~BIT0;
}
}
}
}
Probably you can go faster by unrolling the transmission of each byte with something like
after precomputing once outside the image loop