[152a2841] | 1 | /* |
---|
| 2 | * COPYRIGHT (c) 1989-2011. |
---|
| 3 | * On-Line Applications Research Corporation (OAR). |
---|
| 4 | * |
---|
| 5 | * The license and distribution terms for this file may be |
---|
| 6 | * found in the file LICENSE in this distribution or at |
---|
| 7 | * http://www.rtems.com/license/LICENSE. |
---|
| 8 | */ |
---|
| 9 | |
---|
| 10 | #ifdef HAVE_CONFIG_H |
---|
| 11 | #include "config.h" |
---|
| 12 | #endif |
---|
| 13 | |
---|
| 14 | #include <rtems.h> |
---|
| 15 | #include <rtems/system.h> |
---|
| 16 | #include <sys/types.h> |
---|
| 17 | #include <string.h> |
---|
| 18 | #include <stdarg.h> |
---|
| 19 | |
---|
| 20 | #include "tmacros.h" |
---|
| 21 | |
---|
| 22 | static rtems_id locked_print_semaphore; /* synchronisation semaphore */ |
---|
| 23 | |
---|
| 24 | void locked_print_initialize(void) |
---|
| 25 | { |
---|
| 26 | rtems_status_code sc; |
---|
| 27 | static bool initted = false; |
---|
| 28 | |
---|
| 29 | if ( initted ) |
---|
| 30 | return; |
---|
| 31 | |
---|
| 32 | initted = true; |
---|
| 33 | |
---|
| 34 | /* Create/verify synchronisation semaphore */ |
---|
| 35 | sc = rtems_semaphore_create( |
---|
| 36 | rtems_build_name ('S', 'E', 'M', '1'), |
---|
| 37 | 1, |
---|
| 38 | RTEMS_LOCAL | |
---|
[ac2bb464] | 39 | RTEMS_BINARY_SEMAPHORE | |
---|
| 40 | RTEMS_PRIORITY_CEILING | |
---|
[152a2841] | 41 | RTEMS_PRIORITY, |
---|
| 42 | 1, |
---|
| 43 | &locked_print_semaphore |
---|
| 44 | ); |
---|
| 45 | directive_failed( sc, "rtems_semaphore_create" ); |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | void locked_printf(const char *fmt, ...) { |
---|
| 49 | va_list ap; /* points to each unnamed argument in turn */ |
---|
| 50 | rtems_status_code sc; |
---|
| 51 | |
---|
| 52 | locked_print_initialize(); |
---|
| 53 | |
---|
| 54 | /* Lock semaphore without releasing the cpu */ |
---|
| 55 | do { |
---|
| 56 | sc = rtems_semaphore_obtain( locked_print_semaphore, RTEMS_NO_WAIT, 0 ); |
---|
| 57 | } while (sc != RTEMS_SUCCESSFUL ); |
---|
| 58 | |
---|
| 59 | |
---|
| 60 | va_start(ap, fmt); /* make ap point to 1st unnamed arg */ |
---|
| 61 | vprintf(fmt, ap); |
---|
| 62 | va_end(ap); /* clean up when done */ |
---|
| 63 | |
---|
| 64 | /* Release the semaphore */ |
---|
| 65 | sc = rtems_semaphore_release( locked_print_semaphore ); |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | void locked_printk(const char *fmt, ...) { |
---|
| 69 | va_list ap; /* points to each unnamed argument in turn */ |
---|
| 70 | rtems_status_code sc; |
---|
| 71 | |
---|
| 72 | |
---|
| 73 | locked_print_initialize(); |
---|
| 74 | |
---|
| 75 | /* Lock semaphore without releasing the cpu */ |
---|
| 76 | do { |
---|
| 77 | sc = rtems_semaphore_obtain( locked_print_semaphore, RTEMS_NO_WAIT, 0 ); |
---|
| 78 | } while (sc != RTEMS_SUCCESSFUL ); |
---|
| 79 | |
---|
| 80 | va_start(ap, fmt); /* make ap point to 1st unnamed arg */ |
---|
| 81 | vprintk(fmt, ap); |
---|
| 82 | va_end(ap); /* clean up when done */ |
---|
| 83 | |
---|
| 84 | /* Release the semaphore */ |
---|
| 85 | sc = rtems_semaphore_release( locked_print_semaphore ); |
---|
| 86 | } |
---|