Browse Source

Further improvements in serial const correctness

master
Martin Budden 8 years ago
parent
commit
ed99c264c7
  1. 2
      lib/main/STM32_USB-FS-Device_Driver/inc/usb_mem.h
  2. 2
      lib/main/STM32_USB-FS-Device_Driver/src/usb_mem.c
  3. 2
      lib/main/STM32_USB_Device_Library/Class/cdc/inc/usbd_cdc_core.h
  4. 6
      src/main/drivers/serial.c
  5. 6
      src/main/drivers/serial.h
  6. 8
      src/main/drivers/serial_usb_vcp.c
  7. 2
      src/main/vcp/hw_config.c
  8. 2
      src/main/vcp/hw_config.h
  9. 6
      src/main/vcpf4/usbd_cdc_vcp.c
  10. 2
      src/main/vcpf4/usbd_cdc_vcp.h

2
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 --------------------------------------------------------*/

2
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;

2
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;

6
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);
}

6
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);

8
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);

2
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) {

2
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

6
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;

2
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

Loading…
Cancel
Save