aboutsummaryrefslogtreecommitdiffstats
path: root/demos/ATSAMA5D2
diff options
context:
space:
mode:
authorisiora <none@example.com>2018-03-15 12:24:14 +0000
committerisiora <none@example.com>2018-03-15 12:24:14 +0000
commitf9adf287c906b21a3b618483280d53d2619c4530 (patch)
treeb240f845773ab881a348ecea1a708f5ea0c626e1 /demos/ATSAMA5D2
parent19c6dfea6dab220161cc89bc7d22c322b4b2dea2 (diff)
downloadChibiOS-f9adf287c906b21a3b618483280d53d2619c4530.tar.gz
ChibiOS-f9adf287c906b21a3b618483280d53d2619c4530.tar.bz2
ChibiOS-f9adf287c906b21a3b618483280d53d2619c4530.zip
Added new services.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@11770 110e8d01-0319-4d1e-a829-52ad28d1bb01
Diffstat (limited to 'demos/ATSAMA5D2')
-rwxr-xr-xdemos/ATSAMA5D2/RT-SAMA5D2-XPLAINED-SEC/Makefile1
-rwxr-xr-xdemos/ATSAMA5D2/RT-SAMA5D2-XPLAINED-SEC/main.c56
-rw-r--r--demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED-SEC/tservices.c39
3 files changed, 80 insertions, 16 deletions
diff --git a/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED-SEC/Makefile b/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED-SEC/Makefile
index 60a233b6d..2a1c0b958 100755
--- a/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED-SEC/Makefile
+++ b/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED-SEC/Makefile
@@ -141,6 +141,7 @@ CSRC = $(STARTUPSRC) \
$(TESTSRC) \
$(CHIBIOS)/os/hal/lib/streams/chprintf.c \
tservices.c \
+ proxies/tssockstub.c \
main.c
# C++ sources that can be compiled in ARM or THUMB mode depending on the global
diff --git a/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED-SEC/main.c b/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED-SEC/main.c
index 837678368..e432e48c1 100755
--- a/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED-SEC/main.c
+++ b/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED-SEC/main.c
@@ -17,9 +17,61 @@
#include "ch.h"
#include "hal.h"
#include "chtssi.h"
+#include "proxies/tssockstub.h"
#include "rt_test_root.h"
#include "oslib_test_root.h"
#include "chprintf.h"
+#include <string.h>
+
+#define SERVER_PORT_NUM 8080
+#define SERVER_IP_ADDRESS "192.136.23.21"
+
+void tcpexample(void) {
+ int socket_fd;
+ struct sockaddr_in ra;
+
+ int recv_data; char data_buffer[80];
+
+ /*
+ * Creates an TCP socket (SOCK_STREAM) with Internet Protocol Family
+ * (PF_INET). Protocol family and Address family related. For example
+ * PF_INET Protocol Family and AF_INET family are coupled.
+ */
+ socket_fd = socket(PF_INET, SOCK_STREAM, 0);
+
+ if ( socket_fd < 0 ) {
+ chprintf((BaseSequentialStream *)&SD1, "socket call failed");
+ return;
+ }
+
+ /* Connects to server ip-address. */
+ memset(&ra, 0, sizeof(struct sockaddr_in));
+ ra.sin_family = AF_INET;
+ ra.sin_addr.s_addr = inet_addr(SERVER_IP_ADDRESS);
+ ra.sin_port = htons(SERVER_PORT_NUM);
+
+
+ if (connect(socket_fd, (struct sockaddr *)&ra,
+ sizeof (struct sockaddr_in)) < 0) {
+ chprintf((BaseSequentialStream *)&SD1, "connect failed \n");
+ close(socket_fd);
+ return;
+ }
+ if (send(socket_fd, "Baba", sizeof "Baba", 0) < 0) {
+ chprintf((BaseSequentialStream *)&SD1, "send failed \n");
+ close(socket_fd);
+ return;
+ }
+ recv_data = recv(socket_fd, data_buffer, sizeof data_buffer, 0);
+ if (recv_data < 0) {
+ chprintf((BaseSequentialStream *)&SD1, "recv failed \n");
+ close(socket_fd);
+ return;
+ }
+ data_buffer[recv_data] = '\0';
+ chprintf((BaseSequentialStream *)&SD1, "received data: %s\n",data_buffer);
+ close(socket_fd);
+}
/*
* LED blinker thread, times are in milliseconds.
@@ -43,6 +95,8 @@ static THD_FUNCTION(Thread1, arg) {
chThdSleepMilliseconds(160);
palToggleLine(LINE_LED_BLUE);
chThdSleepMilliseconds(600);
+ tcpexample();
+ chThdSleepMilliseconds(5000);
}
}
@@ -76,7 +130,7 @@ int main(void) {
/*
* Creates the blinker thread (and any other ancillary thread).
*/
- chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO+10, Thread1, NULL);
+ chThdCreateStatic(waThread1, sizeof waThread1, NORMALPRIO+10, Thread1, NULL);
/*
* System initializations.
diff --git a/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED-SEC/tservices.c b/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED-SEC/tservices.c
index ea7b6a62e..042257e2a 100644
--- a/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED-SEC/tservices.c
+++ b/demos/ATSAMA5D2/RT-SAMA5D2-XPLAINED-SEC/tservices.c
@@ -24,7 +24,8 @@
#include "ch.h"
#include "hal.h"
-#include "chtssi.h"
+#include "tservices.h"
+#include "proxies/tssockstub.h"
#include "chprintf.h"
/*===========================================================================*/
@@ -50,28 +51,35 @@
static THD_WORKING_AREA(waTsSimpleService, 1024);
static THD_FUNCTION(TsSimpleService, tsstate) {
- /* WARNING: do not put blocking call out of the cycle,
- i.e. no calls that suspend
- the current thread!.*/
-
+ BaseSequentialStream *ssp = (BaseSequentialStream*)&SD1;
ts_state_t *svcp = tsstate;
- /* Start the request/process/response cycle.*/
- while (tssiWaitRequest(tsstate) == SMC_SVC_OK) {
+ /* Start the 'wait request / process / response' cycle.*/
+ for (;/* ever */;) {
int i;
- chprintf((BaseSequentialStream*)&SD1,
- "TsSimpleService received a new request.\r\n");
+
+ /* Wait a service request.*/
+ msg_t r = tssiWaitRequest(tsstate);
+
+ /* Check if status is ko. It could not happen.*/
+ if (r != SMC_SVC_OK) {
+ chprintf(ssp, "Unexpected wait request error.\r\n");
+ continue;
+ }
+
+ /* Process the request.*/
+ chprintf(ssp, "r = %d, TsSimpleService received a new request.\r\n", r);
if (svcp->ts_datalen > 0) {
*(TS_GET_DATA(svcp) + TS_GET_DATALEN(svcp) - 1) = '\0';
- chprintf((BaseSequentialStream*)&SD1,
- "My non secure 'alter ego' has a request.\r\n");
- chprintf((BaseSequentialStream*)&SD1,
- "She tells: '");
- chprintf((BaseSequentialStream*)&SD1, TS_GET_DATA(svcp));
- chprintf((BaseSequentialStream*)&SD1, "'\r\n");
+ chprintf(ssp, "My non secure 'alter ego' has a request.\r\n");
+ chprintf(ssp, "She tells: '");
+ chprintf(ssp, TS_GET_DATA(svcp));
+ chprintf(ssp, "'\r\n");
}
for (i = 0; i < 100000; ++i)
;
+
+ /* Set the response.*/
TS_SET_STATUS(svcp, i);
}
@@ -89,6 +97,7 @@ static THD_FUNCTION(TsSimpleService, tsstate) {
TS_STATE_TABLE
TS_CONF_TABLE_BEGIN
TS_CONF_TABLE_ENTRY("TsSimpleService", waTsSimpleService, TS_BASE_PRIO, TsSimpleService, TS_STATE(0))
+ TS_CONF_TABLE_ENTRY("TsStubsService", waTsStubsService, TS_BASE_PRIO+10, TsStubsService, TS_STATE(1))
TS_CONF_TABLE_END
/** @} */