diff --git a/src/CLR/Include/WireProtocol_HAL_Interface.h b/src/CLR/Include/WireProtocol_HAL_Interface.h index f5d98f37ff..b06ecd037a 100644 --- a/src/CLR/Include/WireProtocol_HAL_Interface.h +++ b/src/CLR/Include/WireProtocol_HAL_Interface.h @@ -9,7 +9,7 @@ #include "WireProtocol_v2.h" ////////////////////////////////////////// -bool WP_ReceiveBytes(uint8_t* ptr, uint16_t* size); +bool WP_ReceiveBytes(unsigned char* ptr, unsigned short* size); bool WP_TransmitMessage(WP_Message* message); void WP_CheckAvailableIncomingData(); diff --git a/src/CLR/Include/WireProtocol_Message.h b/src/CLR/Include/WireProtocol_Message.h index e9796da0a7..399d9164e7 100644 --- a/src/CLR/Include/WireProtocol_Message.h +++ b/src/CLR/Include/WireProtocol_Message.h @@ -14,19 +14,38 @@ //////////////////////////////////////////////////// // function declarations (related with WP_Message) +#ifdef __cplusplus +extern "C" { +#endif + void WP_Message_Initialize(WP_Message* message); void WP_Message_PrepareReception(WP_Message* message); -void WP_Message_PrepareRequest(WP_Message* message, uint32_t cmd, uint32_t flags, uint32_t payloadSize, uint8_t* payload); -void WP_Message_PrepareReply(WP_Message* message, const WP_Packet* req, uint32_t flags, uint32_t payloadSize, uint8_t* payload); -void WP_Message_SetPayload(WP_Message* message, uint8_t* payload); +void WP_Message_PrepareRequest(WP_Message* message, unsigned int cmd, unsigned int flags, unsigned int payloadSize, unsigned char* payload); +void WP_Message_PrepareReply(WP_Message* message, const WP_Packet* req, unsigned int flags, unsigned int payloadSize, unsigned char* payload); +void WP_Message_SetPayload(WP_Message* message, unsigned char* payload); void WP_Message_Release(WP_Message* message); bool WP_Message_VerifyHeader(WP_Message* message); bool WP_Message_VerifyPayload(WP_Message* message); -void WP_Message_ReplyBadPacket(uint32_t flags); +void WP_Message_ReplyBadPacket(unsigned int flags); bool WP_Message_Process(WP_Message* message); +#ifdef __cplusplus +} +#endif + ////////////////////////////////////////// // helper functions + +#ifdef __cplusplus +extern "C" { +#endif + void WP_ReplyToCommand(WP_Message* message, bool fSuccess, bool fCritical, void* ptr, int size); +void WP_SendProtocolMessage(WP_Message *message); +void WP_PrepareAndSendProtocolMessage(unsigned int cmd, unsigned int payloadSize, unsigned char* payload, unsigned int flags); + +#ifdef __cplusplus +} +#endif #endif // _WIREPROTOCOL_MESSAGE_H_ diff --git a/src/CLR/Include/WireProtocol_MonitorCommands.h b/src/CLR/Include/WireProtocol_MonitorCommands.h index bd88e3030c..d90d193726 100644 --- a/src/CLR/Include/WireProtocol_MonitorCommands.h +++ b/src/CLR/Include/WireProtocol_MonitorCommands.h @@ -57,11 +57,21 @@ typedef enum MemoryMap_Options // backwards compatible with .NETMF typedef struct Monitor_Ping_Reply { - uint32_t m_source; - uint32_t m_dbg_flags; + unsigned int m_source; + unsigned int m_dbg_flags; }Monitor_Ping_Reply; +// structure for command Monitor Ping +// backwards compatible with .NETMF +typedef struct Monitor_Ping_Command +{ + unsigned int m_source; + unsigned int m_dbg_flags; + +}Monitor_Ping_Command; + + // structure with reply for OEM information command typedef struct Monitor_OemInfo_Reply { @@ -71,43 +81,43 @@ typedef struct Monitor_OemInfo_Reply typedef struct CLR_DBG_Commands_Monitor_WriteMemory { - uint32_t address; - uint32_t length; - uint8_t data[1]; + unsigned int address; + unsigned int length; + unsigned char data[1]; }CLR_DBG_Commands_Monitor_WriteMemory; typedef struct Monitor_Reboot_Command { - uint32_t m_flags; + unsigned int m_flags; }Monitor_Reboot_Command; typedef struct CLR_DBG_Commands_Monitor_EraseMemory { - uint32_t address; - uint32_t length; + unsigned int address; + unsigned int length; }CLR_DBG_Commands_Monitor_EraseMemory; typedef struct CLR_DBG_Commands_Monitor_CheckMemory { - uint32_t address; - uint32_t length; + unsigned int address; + unsigned int length; }CLR_DBG_Commands_Monitor_CheckMemory; typedef struct CLR_DBG_Commands_Monitor_CheckMemory_Reply { - uint32_t crc; + unsigned int crc; }CLR_DBG_Commands_Monitor_CheckMemory_Reply; typedef struct MemoryMap_Range { - uint32_t m_address; - uint32_t m_length; - uint32_t m_flags; + unsigned int m_address; + unsigned int m_length; + unsigned int m_flags; }MemoryMap_Range; @@ -140,4 +150,3 @@ bool Monitor_FlashSectorMap(WP_Message* message); #endif #endif //_WIREPROTOCOL_COMMANDS_H_ - diff --git a/src/CLR/WireProtocol/WireProtocol_HAL_Interface.c b/src/CLR/WireProtocol/WireProtocol_HAL_Interface.c index 3213f5de1e..7df061db45 100644 --- a/src/CLR/WireProtocol/WireProtocol_HAL_Interface.c +++ b/src/CLR/WireProtocol/WireProtocol_HAL_Interface.c @@ -16,7 +16,7 @@ ///////////////////////////////////////////////////////////////////////////////////////////////// // provided as weak to be replaced by actual implementation by HAL interface -__nfweak bool WP_ReceiveBytes(uint8_t* ptr, uint16_t* size) +__nfweak bool WP_ReceiveBytes(unsigned char* ptr, unsigned short* size) { // default to false return false; diff --git a/src/CLR/WireProtocol/WireProtocol_Message.c b/src/CLR/WireProtocol/WireProtocol_Message.c index 5df91e5156..6b33ec32ac 100644 --- a/src/CLR/WireProtocol/WireProtocol_Message.c +++ b/src/CLR/WireProtocol/WireProtocol_Message.c @@ -4,14 +4,13 @@ // See LICENSE file in the project root for full license information. // -#include #include #include "WireProtocol_Message.h" -uint8_t receptionBuffer[2048]; +unsigned char receptionBuffer[2048]; static uint16_t lastOutboundMessage; -uint32_t m_payloadTicks; -static uint8_t* marker; +// FIXME #146 unsigned int m_payloadTicks; +static unsigned char* marker; ////////////////////////////////////////// // helper functions @@ -19,7 +18,7 @@ static uint8_t* marker; void WP_ReplyToCommand(WP_Message* message, bool fSuccess, bool fCritical, void* ptr, int size) { WP_Message msgReply; - uint32_t flags = 0; + unsigned int flags = 0; // // Make sure we reply only once! @@ -44,7 +43,7 @@ void WP_ReplyToCommand(WP_Message* message, bool fSuccess, bool fCritical, void* WP_Message_Initialize(&msgReply); - WP_Message_PrepareReply(&msgReply, &message->m_header, flags, size, (uint8_t*)ptr ); + WP_Message_PrepareReply(&msgReply, &message->m_header, flags, size, (unsigned char*)ptr ); WP_TransmitMessage(&msgReply); } @@ -63,9 +62,9 @@ void WP_Message_PrepareReception(WP_Message* message) message->m_rxState = ReceiveState_Initialize; } -void WP_Message_PrepareRequest(WP_Message* message, uint32_t cmd, uint32_t flags, uint32_t payloadSize, uint8_t* payload) +void WP_Message_PrepareRequest(WP_Message* message, unsigned int cmd, unsigned int flags, unsigned int payloadSize, unsigned char* payload) { - memcpy(&message->m_header.m_signature, marker ? marker : (uint8_t*)MARKER_PACKET_V1, sizeof(message->m_header.m_signature)); + memcpy(&message->m_header.m_signature, marker ? marker : (unsigned char*)MARKER_PACKET_V1, sizeof(message->m_header.m_signature)); message->m_header.m_crcData = SUPPORT_ComputeCRC(payload, payloadSize, 0); message->m_header.m_cmd = cmd; @@ -79,13 +78,13 @@ void WP_Message_PrepareRequest(WP_Message* message, uint32_t cmd, uint32_t flags // The CRC for the header is computed setting the CRC field to zero and then running the CRC algorithm. // message->m_header.m_crcHeader = 0; - message->m_header.m_crcHeader = SUPPORT_ComputeCRC((uint8_t*)&message->m_header, sizeof(message->m_header), 0); + message->m_header.m_crcHeader = SUPPORT_ComputeCRC((unsigned char*)&message->m_header, sizeof(message->m_header), 0); } -void WP_Message_PrepareReply(WP_Message* message, const WP_Packet* req, uint32_t flags, uint32_t payloadSize, uint8_t* payload) +void WP_Message_PrepareReply(WP_Message* message, const WP_Packet* req, unsigned int flags, unsigned int payloadSize, unsigned char* payload) { - memcpy(&message->m_header.m_signature, marker ? marker : (uint8_t*)MARKER_PACKET_V1, sizeof(message->m_header.m_signature)); + memcpy(&message->m_header.m_signature, marker ? marker : (unsigned char*)MARKER_PACKET_V1, sizeof(message->m_header.m_signature)); message->m_header.m_crcData = SUPPORT_ComputeCRC(payload, payloadSize, 0); message->m_header.m_cmd = req->m_cmd; @@ -99,10 +98,10 @@ void WP_Message_PrepareReply(WP_Message* message, const WP_Packet* req, uint32_t // The CRC for the header is computed setting the CRC field to zero and then running the CRC algorithm. // message->m_header.m_crcHeader = 0; - message->m_header.m_crcHeader = SUPPORT_ComputeCRC((uint8_t*)&message->m_header, sizeof(message->m_header), 0); + message->m_header.m_crcHeader = SUPPORT_ComputeCRC((unsigned char*)&message->m_header, sizeof(message->m_header), 0); } -void WP_Message_SetPayload(WP_Message* message, uint8_t* payload) +void WP_Message_SetPayload(WP_Message* message, unsigned char* payload) { message->m_payload = payload; } @@ -117,9 +116,9 @@ void WP_Message_Release(WP_Message* message) bool WP_Message_VerifyHeader(WP_Message* message) { - uint32_t crc = message->m_header.m_crcHeader; + unsigned int crc = message->m_header.m_crcHeader; message->m_header.m_crcHeader = 0; - uint32_t computedCrc = SUPPORT_ComputeCRC((uint8_t*)&message->m_header, sizeof(message->m_header), 0); + unsigned int computedCrc = SUPPORT_ComputeCRC((unsigned char*)&message->m_header, sizeof(message->m_header), 0); message->m_header.m_crcHeader = crc; if(computedCrc != crc) @@ -136,7 +135,7 @@ bool WP_Message_VerifyPayload(WP_Message* message) return false; } - uint32_t computedCrc = SUPPORT_ComputeCRC(message->m_payload, message->m_header.m_size, 0); + unsigned int computedCrc = SUPPORT_ComputeCRC(message->m_payload, message->m_header.m_size, 0); if(computedCrc != message->m_header.m_crcData) { return false; @@ -144,7 +143,7 @@ bool WP_Message_VerifyPayload(WP_Message* message) return true; } -void WP_Message_ReplyBadPacket(uint32_t flags) +void WP_Message_ReplyBadPacket(unsigned int flags) { WP_Message message; WP_Message_Initialize(&message); @@ -155,7 +154,7 @@ void WP_Message_ReplyBadPacket(uint32_t flags) bool WP_Message_Process(WP_Message* message) { - uint8_t* buf = (uint8_t*)&message->m_header; + unsigned char* buf = (unsigned char*)&message->m_header; int len; while(true) @@ -169,7 +168,7 @@ bool WP_Message_Process(WP_Message* message) WP_Message_Release(message); message->m_rxState = ReceiveState_WaitingForHeader; - message->m_pos = (uint8_t*)&message->m_header; + message->m_pos = (unsigned char*)&message->m_header; message->m_size = sizeof(message->m_header); break; @@ -244,7 +243,7 @@ bool WP_Message_Process(WP_Message* message) } else { - m_payloadTicks = HAL_Time_CurrentSysTicks(); + // FIXME #146 m_payloadTicks = HAL_Time_CurrentSysTicks(); message->m_rxState = ReceiveState_ReadingPayload; message->m_pos = message->m_payload; message->m_size = message->m_header.m_size; @@ -303,3 +302,17 @@ bool WP_Message_Process(WP_Message* message) } } } + +void WP_SendProtocolMessage(WP_Message *message) +{ + WP_TransmitMessage(&message); +} + +void WP_PrepareAndSendProtocolMessage(unsigned int cmd, unsigned int payloadSize, unsigned char* payload, unsigned int flags) +{ + WP_Message message; + WP_Message_Initialize(&message); + WP_Message_PrepareRequest(&message, cmd, flags, payloadSize, payload); + + WP_TransmitMessage(&message); +}