1 /* 2 * Copyright 2006, Marcus Overhagen, <marcus@overhagen.de> 3 * Distributed under the terms of the MIT License. 4 */ 5 6 7 #include <OS.h> 8 #include <stdio.h> 9 #include <string.h> 10 11 12 /* A full port can't be written to. Thus the write from thread should block, until main thread reads. 13 * 14 */ 15 16 port_id id; 17 char data[100]; 18 19 int32 20 test_thread(void *) 21 { 22 ssize_t size; 23 24 // BeBook: does block when port is empty, and unblocks when port is written to or deleted 25 printf("port_buffer_size...\n"); 26 size = port_buffer_size(id); 27 printf("port_buffer_size size %ld (0x%08lx) (%s)\n", size, size, strerror(size)); 28 29 return 0; 30 } 31 32 33 int 34 main() 35 { 36 status_t s; 37 ssize_t size; 38 int32 code; 39 40 id = create_port(1, "test port"); 41 printf("created port %ld\n", id); 42 43 s = write_port(id, 0x1234, data, 10); 44 printf("write port result 0x%08lx (%s)\n", s, strerror(s)); 45 46 size = read_port(id, &code, data, sizeof(data)); 47 printf("read port code %lx, size %ld (0x%08lx) (%s)\n", code, size, size, strerror(size)); 48 49 printf("port_buffer_size should block for 5 seconds now, as port is empty\n"); 50 51 thread_id thread = spawn_thread(test_thread, "test thread", B_NORMAL_PRIORITY, NULL); 52 resume_thread(thread); 53 snooze(5000000); 54 55 printf("write port...\n"); 56 s = write_port(id, 0x5678, data, 20); 57 printf("write port result 0x%08lx (%s)\n", s, strerror(s)); 58 59 printf("waiting for thread to terminate\n"); 60 wait_for_thread(thread, &s); 61 62 return 0; 63 } 64