From ed99c264c7d42327291ebd51a75843625c9655d3 Mon Sep 17 00:00:00 2001 From: Martin Budden Date: Tue, 4 Oct 2016 08:37:09 +0100 Subject: [PATCH] Further improvements in serial const correctness --- lib/main/STM32_USB-FS-Device_Driver/inc/usb_mem.h | 2 +- lib/main/STM32_USB-FS-Device_Driver/src/usb_mem.c | 2 +- .../Class/cdc/inc/usbd_cdc_core.h | 2 +- src/main/drivers/serial.c | 6 +++--- src/main/drivers/serial.h | 6 +++--- src/main/drivers/serial_usb_vcp.c | 8 ++++---- src/main/vcp/hw_config.c | 2 +- src/main/vcp/hw_config.h | 2 +- src/main/vcpf4/usbd_cdc_vcp.c | 6 +++--- src/main/vcpf4/usbd_cdc_vcp.h | 2 +- 10 files changed, 19 insertions(+), 19 deletions(-) diff --git a/lib/main/STM32_USB-FS-Device_Driver/inc/usb_mem.h b/lib/main/STM32_USB-FS-Device_Driver/inc/usb_mem.h index 0b2910060..a182432d7 100644 --- a/lib/main/STM32_USB-FS-Device_Driver/inc/usb_mem.h +++ b/lib/main/STM32_USB-FS-Device_Driver/inc/usb_mem.h @@ -35,7 +35,7 @@ /* Exported constants --------------------------------------------------------*/ /* Exported macro ------------------------------------------------------------*/ /* 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); /* External variables --------------------------------------------------------*/ diff --git a/lib/main/STM32_USB-FS-Device_Driver/src/usb_mem.c b/lib/main/STM32_USB-FS-Device_Driver/src/usb_mem.c index 4e0748ac3..46074cc6c 100644 --- a/lib/main/STM32_USB-FS-Device_Driver/src/usb_mem.c +++ b/lib/main/STM32_USB-FS-Device_Driver/src/usb_mem.c @@ -45,7 +45,7 @@ * Output : 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 i, temp1, temp2; diff --git a/lib/main/STM32_USB_Device_Library/Class/cdc/inc/usbd_cdc_core.h b/lib/main/STM32_USB_Device_Library/Class/cdc/inc/usbd_cdc_core.h index b9afa7423..d05ecf5f8 100644 --- a/lib/main/STM32_USB_Device_Library/Class/cdc/inc/usbd_cdc_core.h +++ b/lib/main/STM32_USB_Device_Library/Class/cdc/inc/usbd_cdc_core.h @@ -95,7 +95,7 @@ typedef struct _CDC_IF_PROP uint16_t (*pIf_Init) (void); uint16_t (*pIf_DeInit) (void); 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); } CDC_IF_Prop_TypeDef; diff --git a/src/main/drivers/serial.c b/src/main/drivers/serial.c index f3f855f6b..24c80c3df 100644 --- a/src/main/drivers/serial.c +++ b/src/main/drivers/serial.c @@ -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) { instance->vTable->writeBuf(instance, data, count); } else { - for (uint8_t *p = data; count > 0; count--, p++) { + for (const uint8_t *p = data; count > 0; count--, p++) { while (!serialTxBytesFree(instance)) { }; @@ -86,7 +86,7 @@ void serialSetMode(serialPort_t *instance, portMode_t 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); } diff --git a/src/main/drivers/serial.h b/src/main/drivers/serial.h index 50e0ac7d4..6bbef15ec 100644 --- a/src/main/drivers/serial.h +++ b/src/main/drivers/serial.h @@ -74,7 +74,7 @@ struct serialPortVTable { 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. void (*beginWrite)(serialPort_t *instance); void (*endWrite)(serialPort_t *instance); @@ -83,7 +83,7 @@ struct serialPortVTable { void serialWrite(serialPort_t *instance, uint8_t ch); uint32_t serialRxBytesWaiting(const serialPort_t *instance); uint8_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); void serialSetBaudRate(serialPort_t *instance, uint32_t baudRate); 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); // 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 serialEndWrite(serialPort_t *instance); diff --git a/src/main/drivers/serial_usb_vcp.c b/src/main/drivers/serial_usb_vcp.c index 81d71a7ed..79e6db8c7 100644 --- a/src/main/drivers/serial_usb_vcp.c +++ b/src/main/drivers/serial_usb_vcp.c @@ -59,13 +59,13 @@ static void usbVcpSetMode(serialPort_t *instance, portMode_t mode) // TODO implement } -static bool isUsbVcpTransmitBufferEmpty(serialPort_t *instance) +static bool isUsbVcpTransmitBufferEmpty(const serialPort_t *instance) { UNUSED(instance); return true; } -static uint32_t usbVcpAvailable(serialPort_t *instance) +static uint32_t usbVcpAvailable(const serialPort_t *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); @@ -93,7 +93,7 @@ static void usbVcpWriteBuf(serialPort_t *instance, void *data, int count) } uint32_t start = millis(); - uint8_t *p = data; + const uint8_t *p = data; uint32_t txed = 0; while (count > 0) { txed = CDC_Send_DATA(p, count); diff --git a/src/main/vcp/hw_config.c b/src/main/vcp/hw_config.c index 3270d1bf7..e39c7147b 100644 --- a/src/main/vcp/hw_config.c +++ b/src/main/vcp/hw_config.c @@ -283,7 +283,7 @@ static void IntToUnicode(uint32_t value, uint8_t *pbuf, uint8_t len) * Output : 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 */ if (packetSent) { diff --git a/src/main/vcp/hw_config.h b/src/main/vcp/hw_config.h index de454859f..d7f9a3fca 100644 --- a/src/main/vcp/hw_config.h +++ b/src/main/vcp/hw_config.h @@ -55,7 +55,7 @@ void Leave_LowPowerMode(void); void USB_Interrupts_Config(void); void USB_Cable_Config(FunctionalState NewState); 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_Receive_DATA(uint8_t* recvBuf, uint32_t len); // HJI uint8_t usbIsConfigured(void); // HJI uint8_t usbIsConnected(void); // HJI diff --git a/src/main/vcpf4/usbd_cdc_vcp.c b/src/main/vcpf4/usbd_cdc_vcp.c index 2af4456ac..244420445 100644 --- a/src/main/vcpf4/usbd_cdc_vcp.c +++ b/src/main/vcpf4/usbd_cdc_vcp.c @@ -51,7 +51,7 @@ usbStruct_t usbData; static uint16_t VCP_Init(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_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); CDC_IF_Prop_TypeDef VCP_fops = {VCP_Init, VCP_DeInit, VCP_Ctrl, VCP_DataTx, VCP_DataRx }; @@ -151,7 +151,7 @@ static uint16_t VCP_Ctrl(uint32_t Cmd, uint8_t* Buf, uint32_t Len) * Output : 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) { uint32_t i = 0; if(USB_Tx_State!=1) @@ -169,7 +169,7 @@ uint32_t CDC_Send_DATA(uint8_t *ptrBuffer, uint8_t sendLength) * @param Len: Number of data to be sent (in bytes) * @retval Result of the opeartion: 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) { uint16_t ptr_head = APP_Rx_ptr_in; uint16_t ptr_tail = APP_Rx_ptr_out; diff --git a/src/main/vcpf4/usbd_cdc_vcp.h b/src/main/vcpf4/usbd_cdc_vcp.h index 7810f657d..31e50096d 100644 --- a/src/main/vcpf4/usbd_cdc_vcp.h +++ b/src/main/vcpf4/usbd_cdc_vcp.h @@ -38,7 +38,7 @@ __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_Receive_DATA(uint8_t* recvBuf, uint32_t len); // HJI uint8_t usbIsConfigured(void); // HJI uint8_t usbIsConnected(void); // HJI