Created
December 21, 2013 13:08
-
-
Save Arachnid/8069083 to your computer and use it in GitHub Desktop.
Everything you need to bootload with an SCB UART in PSoC 4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void CyBtldrCommStart(void) { | |
UART_Start(); | |
} | |
void CyBtldrCommStop (void) { | |
UART_Stop(); | |
} | |
void CyBtldrCommReset(void) { | |
UART_SpiUartClearRxBuffer(); | |
UART_SpiUartClearTxBuffer(); | |
} | |
cystatus CyBtldrCommWrite(uint8* buffer, uint16 size, uint16* count, uint8 timeOut) { | |
for(*count = 0; *count < size; (*count)++) { | |
UART_UartPutChar(buffer[*count]); | |
} | |
return CYRET_SUCCESS; | |
} | |
cystatus CyBtldrCommRead (uint8* buffer, uint16 size, uint16* count, uint8 timeOut) { | |
int timeoutUs = timeOut * 10000; | |
cystatus status = CYRET_TIMEOUT; | |
*count = 0; | |
while(*count < size && timeoutUs >= 0) { | |
if(UART_SpiUartGetRxBufferSize() > 0) { | |
buffer[(*count)++] = UART_UartGetByte(); | |
// Switch to byte-to-byte timeout and mark as success | |
timeoutUs = 10000; //10mS | |
status = CYRET_SUCCESS; | |
} else { | |
CyDelayUs(10); | |
timeoutUs -= 10; | |
} | |
} | |
return status; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment