Skip to content

Commit

Permalink
Update implementation of WP_ReceiveBytes
Browse files Browse the repository at this point in the history
- Following nanoframework#2012.
  • Loading branch information
josesimoes committed Aug 25, 2021
1 parent 349d99c commit 9d68666
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
13 changes: 5 additions & 8 deletions targets/AzureRTOS/Maxim/_common/WireProtocol_HAL_Interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void UART_TxCallback(mxc_uart_req_t *req, int error)
}
}

uint8_t WP_ReceiveBytes(uint8_t *ptr, uint32_t *size)
void WP_ReceiveBytes(uint8_t **ptr, uint32_t *size)
{
// save for later comparison
uint32_t requestedSize = *size;
Expand All @@ -58,7 +58,7 @@ uint8_t WP_ReceiveBytes(uint8_t *ptr, uint32_t *size)
NanoUART_InitRequest(&rxRequest);

rxRequest.uart = MXC_UART_GET_UART(WIRE_PROTOCOL_UART);
rxRequest.rxData = ptr;
rxRequest.rxData = *ptr;
rxRequest.rxLen = requestedSize;
rxRequest.callback = UART_RxCallback;

Expand All @@ -80,23 +80,20 @@ uint8_t WP_ReceiveBytes(uint8_t *ptr, uint32_t *size)
goto abort_rx;
}

ptr += receivedBytes;
*ptr += receivedBytes;
*size -= receivedBytes;

TRACE(TRACE_STATE, "RXMSG: Expecting %d bytes, received %d.\n", requestedSize, receivedBytes);

// check if any bytes where read
return receivedBytes > 0;
}

return true;
return;

abort_rx:
// abort any ongoing UART operation
NanoUART_AbortAsync(MXC_UART_GET_UART(WIRE_PROTOCOL_UART));

// done here
return false;
return;
}

uint8_t WP_TransmitMessage(WP_Message *message)
Expand Down
8 changes: 3 additions & 5 deletions targets/AzureRTOS/ST/_common/WireProtocol_HAL_Interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#include <serialcfg.h>

uint8_t WP_ReceiveBytes(uint8_t *ptr, uint32_t *size)
void WP_ReceiveBytes(uint8_t **ptr, uint32_t *size)
{
volatile uint32_t read;

Expand All @@ -23,7 +23,7 @@ uint8_t WP_ReceiveBytes(uint8_t *ptr, uint32_t *size)
if (*size)
{
// non blocking read from serial port with 20ms timeout
read = chnReadTimeout(&SERIAL_DRIVER, ptr, requestedSize, OSAL_MS2I(20));
read = chnReadTimeout(&SERIAL_DRIVER, *ptr, requestedSize, OSAL_MS2I(20));

TRACE(TRACE_STATE, "RXMSG: Expecting %d bytes, received %d.\n", requestedSize, read);

Expand All @@ -33,11 +33,9 @@ uint8_t WP_ReceiveBytes(uint8_t *ptr, uint32_t *size)
return false;
}

ptr += read;
*ptr += read;
*size -= read;
}

return true;
}

uint8_t WP_TransmitMessage(WP_Message *message)
Expand Down

0 comments on commit 9d68666

Please sign in to comment.