17f832a1dSMarcus Overhagen /*
27f832a1dSMarcus Overhagen * Copyright 2006, Marcus Overhagen, <marcus@overhagen.de>
37f832a1dSMarcus Overhagen * Distributed under the terms of the MIT License.
47f832a1dSMarcus Overhagen */
57f832a1dSMarcus Overhagen
67f832a1dSMarcus Overhagen
77f832a1dSMarcus Overhagen #include <OS.h>
87f832a1dSMarcus Overhagen #include <stdio.h>
97f832a1dSMarcus Overhagen #include <string.h>
107f832a1dSMarcus Overhagen
117f832a1dSMarcus Overhagen
12*c8b86e70SMarcus Overhagen /*
137f832a1dSMarcus Overhagen *
147f832a1dSMarcus Overhagen */
157f832a1dSMarcus Overhagen
167f832a1dSMarcus Overhagen port_id id;
177f832a1dSMarcus Overhagen char data[100];
187f832a1dSMarcus Overhagen
197f832a1dSMarcus Overhagen int32
test_thread(void *)207f832a1dSMarcus Overhagen test_thread(void *)
217f832a1dSMarcus Overhagen {
227f832a1dSMarcus Overhagen ssize_t size;
237f832a1dSMarcus Overhagen
247f832a1dSMarcus Overhagen // BeBook: does block when port is empty, and unblocks when port is written to or deleted
257f832a1dSMarcus Overhagen printf("port_buffer_size...\n");
267f832a1dSMarcus Overhagen size = port_buffer_size(id);
277f832a1dSMarcus Overhagen printf("port_buffer_size size %ld (0x%08lx) (%s)\n", size, size, strerror(size));
287f832a1dSMarcus Overhagen
297f832a1dSMarcus Overhagen return 0;
307f832a1dSMarcus Overhagen }
317f832a1dSMarcus Overhagen
327f832a1dSMarcus Overhagen
337f832a1dSMarcus Overhagen int
main()347f832a1dSMarcus Overhagen main()
357f832a1dSMarcus Overhagen {
367f832a1dSMarcus Overhagen status_t s;
377f832a1dSMarcus Overhagen ssize_t size;
387f832a1dSMarcus Overhagen int32 code;
397f832a1dSMarcus Overhagen
407f832a1dSMarcus Overhagen id = create_port(1, "test port");
417f832a1dSMarcus Overhagen printf("created port %ld\n", id);
427f832a1dSMarcus Overhagen
437f832a1dSMarcus Overhagen s = write_port(id, 0x1234, data, 10);
447f832a1dSMarcus Overhagen printf("write port result 0x%08lx (%s)\n", s, strerror(s));
457f832a1dSMarcus Overhagen
467f832a1dSMarcus Overhagen size = read_port(id, &code, data, sizeof(data));
477f832a1dSMarcus Overhagen printf("read port code %lx, size %ld (0x%08lx) (%s)\n", code, size, size, strerror(size));
487f832a1dSMarcus Overhagen
497f832a1dSMarcus Overhagen printf("port_buffer_size should block for 5 seconds now, as port is empty\n");
507f832a1dSMarcus Overhagen
517f832a1dSMarcus Overhagen thread_id thread = spawn_thread(test_thread, "test thread", B_NORMAL_PRIORITY, NULL);
527f832a1dSMarcus Overhagen resume_thread(thread);
537f832a1dSMarcus Overhagen snooze(5000000);
547f832a1dSMarcus Overhagen
557f832a1dSMarcus Overhagen printf("write port...\n");
567f832a1dSMarcus Overhagen s = write_port(id, 0x5678, data, 20);
577f832a1dSMarcus Overhagen printf("write port result 0x%08lx (%s)\n", s, strerror(s));
587f832a1dSMarcus Overhagen
597f832a1dSMarcus Overhagen printf("waiting for thread to terminate\n");
607f832a1dSMarcus Overhagen wait_for_thread(thread, &s);
617f832a1dSMarcus Overhagen
627f832a1dSMarcus Overhagen return 0;
637f832a1dSMarcus Overhagen }
64