Further improvements to serial const correctness

This commit is contained in:
Martin Budden 2016-10-04 09:01:28 +01:00
parent 63ae7a26b6
commit 4cd61f08b5
10 changed files with 19 additions and 19 deletions

View File

@ -35,7 +35,7 @@
/* Exported constants --------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------*/ /* Exported macro ------------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */ /* Exported functions ------------------------------------------------------- */
void UserToPMABufferCopy(uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes); void UserToPMABufferCopy(const uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes);
void PMAToUserBufferCopy(uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes); void PMAToUserBufferCopy(uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes);
/* External variables --------------------------------------------------------*/ /* External variables --------------------------------------------------------*/

View File

@ -45,7 +45,7 @@
* Output : None. * Output : None.
* Return : None . * Return : None .
*******************************************************************************/ *******************************************************************************/
void UserToPMABufferCopy(uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes) void UserToPMABufferCopy(const uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes)
{ {
uint32_t n = (wNBytes + 1) >> 1; /* n = (wNBytes + 1) / 2 */ uint32_t n = (wNBytes + 1) >> 1; /* n = (wNBytes + 1) / 2 */
uint32_t i, temp1, temp2; uint32_t i, temp1, temp2;

View File

@ -95,7 +95,7 @@ typedef struct _CDC_IF_PROP
uint16_t (*pIf_Init) (void); uint16_t (*pIf_Init) (void);
uint16_t (*pIf_DeInit) (void); uint16_t (*pIf_DeInit) (void);
uint16_t (*pIf_Ctrl) (uint32_t Cmd, uint8_t* Buf, uint32_t Len); uint16_t (*pIf_Ctrl) (uint32_t Cmd, uint8_t* Buf, uint32_t Len);
uint16_t (*pIf_DataTx) (uint8_t* Buf, uint32_t Len); uint16_t (*pIf_DataTx) (const uint8_t* Buf, uint32_t Len);
uint16_t (*pIf_DataRx) (uint8_t* Buf, uint32_t Len); uint16_t (*pIf_DataRx) (uint8_t* Buf, uint32_t Len);
} }
CDC_IF_Prop_TypeDef; CDC_IF_Prop_TypeDef;

View File

@ -41,12 +41,12 @@ void serialWrite(serialPort_t *instance, uint8_t ch)
} }
void serialWriteBuf(serialPort_t *instance, uint8_t *data, int count) void serialWriteBuf(serialPort_t *instance, const uint8_t *data, int count)
{ {
if (instance->vTable->writeBuf) { if (instance->vTable->writeBuf) {
instance->vTable->writeBuf(instance, data, count); instance->vTable->writeBuf(instance, data, count);
} else { } else {
for (uint8_t *p = data; count > 0; count--, p++) { for (const uint8_t *p = data; count > 0; count--, p++) {
while (!serialTxBytesFree(instance)) { while (!serialTxBytesFree(instance)) {
}; };
@ -86,7 +86,7 @@ void serialSetMode(serialPort_t *instance, portMode_t mode)
instance->vTable->setMode(instance, mode); instance->vTable->setMode(instance, mode);
} }
void serialWriteBufShim(void *instance, uint8_t *data, int count) void serialWriteBufShim(void *instance, const uint8_t *data, int count)
{ {
serialWriteBuf((serialPort_t *)instance, data, count); serialWriteBuf((serialPort_t *)instance, data, count);
} }

View File

@ -74,7 +74,7 @@ struct serialPortVTable {
void (*setMode)(serialPort_t *instance, portMode_t mode); void (*setMode)(serialPort_t *instance, portMode_t mode);
void (*writeBuf)(serialPort_t *instance, void *data, int count); void (*writeBuf)(serialPort_t *instance, const void *data, int count);
// Optional functions used to buffer large writes. // Optional functions used to buffer large writes.
void (*beginWrite)(serialPort_t *instance); void (*beginWrite)(serialPort_t *instance);
void (*endWrite)(serialPort_t *instance); void (*endWrite)(serialPort_t *instance);
@ -83,7 +83,7 @@ struct serialPortVTable {
void serialWrite(serialPort_t *instance, uint8_t ch); void serialWrite(serialPort_t *instance, uint8_t ch);
uint32_t serialRxBytesWaiting(const serialPort_t *instance); uint32_t serialRxBytesWaiting(const serialPort_t *instance);
uint32_t serialTxBytesFree(const serialPort_t *instance); uint32_t serialTxBytesFree(const serialPort_t *instance);
void serialWriteBuf(serialPort_t *instance, uint8_t *data, int count); void serialWriteBuf(serialPort_t *instance, const uint8_t *data, int count);
uint8_t serialRead(serialPort_t *instance); uint8_t serialRead(serialPort_t *instance);
void serialSetBaudRate(serialPort_t *instance, uint32_t baudRate); void serialSetBaudRate(serialPort_t *instance, uint32_t baudRate);
void serialSetMode(serialPort_t *instance, portMode_t mode); void serialSetMode(serialPort_t *instance, portMode_t mode);
@ -92,6 +92,6 @@ void serialPrint(serialPort_t *instance, const char *str);
uint32_t serialGetBaudRate(serialPort_t *instance); uint32_t serialGetBaudRate(serialPort_t *instance);
// A shim that adapts the bufWriter API to the serialWriteBuf() API. // A shim that adapts the bufWriter API to the serialWriteBuf() API.
void serialWriteBufShim(void *instance, uint8_t *data, int count); void serialWriteBufShim(void *instance, const uint8_t *data, int count);
void serialBeginWrite(serialPort_t *instance); void serialBeginWrite(serialPort_t *instance);
void serialEndWrite(serialPort_t *instance); void serialEndWrite(serialPort_t *instance);

View File

@ -59,13 +59,13 @@ static void usbVcpSetMode(serialPort_t *instance, portMode_t mode)
// TODO implement // TODO implement
} }
static bool isUsbVcpTransmitBufferEmpty(serialPort_t *instance) static bool isUsbVcpTransmitBufferEmpty(const serialPort_t *instance)
{ {
UNUSED(instance); UNUSED(instance);
return true; return true;
} }
static uint32_t usbVcpAvailable(serialPort_t *instance) static uint32_t usbVcpAvailable(const serialPort_t *instance)
{ {
UNUSED(instance); UNUSED(instance);
@ -84,7 +84,7 @@ static uint8_t usbVcpRead(serialPort_t *instance)
} }
} }
static void usbVcpWriteBuf(serialPort_t *instance, void *data, int count) static void usbVcpWriteBuf(serialPort_t *instance, const void *data, int count)
{ {
UNUSED(instance); UNUSED(instance);
@ -93,7 +93,7 @@ static void usbVcpWriteBuf(serialPort_t *instance, void *data, int count)
} }
uint32_t start = millis(); uint32_t start = millis();
uint8_t *p = data; const uint8_t *p = data;
uint32_t txed = 0; uint32_t txed = 0;
while (count > 0) { while (count > 0) {
txed = CDC_Send_DATA(p, count); txed = CDC_Send_DATA(p, count);

View File

@ -282,7 +282,7 @@ static void IntToUnicode(uint32_t value, uint8_t *pbuf, uint8_t len)
* Output : None. * Output : None.
* Return : None. * Return : None.
*******************************************************************************/ *******************************************************************************/
uint32_t CDC_Send_DATA(uint8_t *ptrBuffer, uint8_t sendLength) uint32_t CDC_Send_DATA(const uint8_t *ptrBuffer, uint8_t sendLength)
{ {
/* Last transmission hasn't finished, abort */ /* Last transmission hasn't finished, abort */
if (packetSent) { if (packetSent) {

View File

@ -55,7 +55,7 @@ void Leave_LowPowerMode(void);
void USB_Interrupts_Config(void); void USB_Interrupts_Config(void);
void USB_Cable_Config(FunctionalState NewState); void USB_Cable_Config(FunctionalState NewState);
void Get_SerialNum(void); void Get_SerialNum(void);
uint32_t CDC_Send_DATA(uint8_t *ptrBuffer, uint8_t sendLength); // HJI uint32_t CDC_Send_DATA(const uint8_t *ptrBuffer, uint8_t sendLength); // HJI
uint32_t CDC_Send_FreeBytes(void); uint32_t CDC_Send_FreeBytes(void);
uint32_t CDC_Receive_DATA(uint8_t* recvBuf, uint32_t len); // HJI uint32_t CDC_Receive_DATA(uint8_t* recvBuf, uint32_t len); // HJI
uint32_t CDC_Receive_BytesAvailable(void); uint32_t CDC_Receive_BytesAvailable(void);

View File

@ -57,7 +57,7 @@ static uint32_t APP_Tx_ptr_in = 0;
static uint16_t VCP_Init(void); static uint16_t VCP_Init(void);
static uint16_t VCP_DeInit(void); static uint16_t VCP_DeInit(void);
static uint16_t VCP_Ctrl(uint32_t Cmd, uint8_t* Buf, uint32_t Len); static uint16_t VCP_Ctrl(uint32_t Cmd, uint8_t* Buf, uint32_t Len);
static uint16_t VCP_DataTx(uint8_t* Buf, uint32_t Len); static uint16_t VCP_DataTx(const uint8_t* Buf, uint32_t Len);
static uint16_t VCP_DataRx(uint8_t* Buf, uint32_t Len); static uint16_t VCP_DataRx(uint8_t* Buf, uint32_t Len);
CDC_IF_Prop_TypeDef VCP_fops = {VCP_Init, VCP_DeInit, VCP_Ctrl, VCP_DataTx, VCP_DataRx }; CDC_IF_Prop_TypeDef VCP_fops = {VCP_Init, VCP_DeInit, VCP_Ctrl, VCP_DataTx, VCP_DataRx };
@ -157,7 +157,7 @@ static uint16_t VCP_Ctrl(uint32_t Cmd, uint8_t* Buf, uint32_t Len)
* Output : None. * Output : None.
* Return : None. * Return : None.
*******************************************************************************/ *******************************************************************************/
uint32_t CDC_Send_DATA(uint8_t *ptrBuffer, uint8_t sendLength) uint32_t CDC_Send_DATA(const uint8_t *ptrBuffer, uint8_t sendLength)
{ {
VCP_DataTx(ptrBuffer, sendLength); VCP_DataTx(ptrBuffer, sendLength);
return sendLength; return sendLength;
@ -182,7 +182,7 @@ uint32_t CDC_Send_FreeBytes(void)
* @param Len: Number of data to be sent (in bytes) * @param Len: Number of data to be sent (in bytes)
* @retval Result of the operation: USBD_OK if all operations are OK else VCP_FAIL * @retval Result of the operation: USBD_OK if all operations are OK else VCP_FAIL
*/ */
static uint16_t VCP_DataTx(uint8_t* Buf, uint32_t Len) static uint16_t VCP_DataTx(const uint8_t* Buf, uint32_t Len)
{ {
/* /*
make sure that any paragraph end frame is not in play make sure that any paragraph end frame is not in play

View File

@ -36,7 +36,7 @@
__ALIGN_BEGIN USB_OTG_CORE_HANDLE USB_OTG_dev __ALIGN_END; __ALIGN_BEGIN USB_OTG_CORE_HANDLE USB_OTG_dev __ALIGN_END;
uint32_t CDC_Send_DATA(uint8_t *ptrBuffer, uint8_t sendLength); // HJI uint32_t CDC_Send_DATA(const uint8_t *ptrBuffer, uint8_t sendLength); // HJI
uint32_t CDC_Send_FreeBytes(void); uint32_t CDC_Send_FreeBytes(void);
uint32_t CDC_Receive_DATA(uint8_t* recvBuf, uint32_t len); // HJI uint32_t CDC_Receive_DATA(uint8_t* recvBuf, uint32_t len); // HJI
uint32_t CDC_Receive_BytesAvailable(void); uint32_t CDC_Receive_BytesAvailable(void);