Arm Virtual Hardware  Version 2.1.0
AVH FVP Models
 
Loading...
Searching...
No Matches

Using Virtual Socket Interface (VSocket)

Using Virtual Socket Interface (VSocket)

VSocket API provides a general purpose implementation for socket peripheral. This chapter shows how VSocket can be applied in specific use case.

./interface/vsocket/iot_socket.c: implements the IoT Socket variant for Arm Virtual Hardware based on the ARM_VSocket_Type structure and its mapping defined in arm_vsocket.h.

Setup

Instructions below cover specifically setup for using IoT Socket API in a project using Arm Fixed Virtual Platform (FVP) as a target.

Note that VSocket does not require Semihosting I/O to be enabled on the FVP model.

Usage example

After VSocket is added to the project the interface can be fully used as described in IoT Socket documentation. For example:

#include "iot_socket.h" // ::IoT Utility:Socket (API)
static const char message[] = { "The quick brown fox jumps over the lazy dog." };
void Echo_Client_Thread (void *arg) {
uint8_t ip[4] = { 192U, 168U, 0U, 100U };
int32_t sock, res;
char dbuf[120];
while (1) {
sock = iotSocketCreate (IOT_SOCKET_AF_INET, IOT_SOCKET_SOCK_STREAM, IOT_SOCKET_IPPROTO_TCP);
res = iotSocketConnect (sock, (uint8_t *)ip, sizeof(ip), 7U);
if (res == 0) {
while (1) {
iotSocketSend (sock, message, sizeof(message));
res = iotSocketRecv (sock, dbuf, sizeof(dbuf));
if (res < 0) {
break; // Receive error
}
if (res > 0) {
if (memcmp (dbuf, message, res) != 0) {
break; // Message error, echoed message is not the same
}
}
osDelay (1000U);
}
}
iotSocketClose (sock);
}
}