[abb18dc] | 1 | /* |
---|
| 2 | * Task Create Shell Command Implmentation |
---|
| 3 | * |
---|
[a2aad55] | 4 | * COPYRIGHT (c) 1989-2013. |
---|
[abb18dc] | 5 | * On-Line Applications Research Corporation (OAR). |
---|
| 6 | * |
---|
| 7 | * The license and distribution terms for this file may be |
---|
| 8 | * found in the file LICENSE in this distribution or at |
---|
| 9 | * http://www.rtems.com/license/LICENSE. |
---|
| 10 | */ |
---|
| 11 | |
---|
| 12 | #ifdef HAVE_CONFIG_H |
---|
| 13 | #include "config.h" |
---|
| 14 | #endif |
---|
| 15 | |
---|
| 16 | #define __need_getopt_newlib |
---|
| 17 | #include <newlib/getopt.h> |
---|
| 18 | |
---|
| 19 | #include <stdio.h> |
---|
| 20 | |
---|
| 21 | #include <rtems.h> |
---|
| 22 | #include "shell.h" |
---|
| 23 | #include <rtems/stringto.h> |
---|
| 24 | #include <schedsim_shell.h> |
---|
| 25 | #include <rtems/error.h> |
---|
| 26 | |
---|
| 27 | int rtems_shell_main_semaphore_create( |
---|
| 28 | int argc, |
---|
| 29 | char *argv[] |
---|
| 30 | ) |
---|
| 31 | { |
---|
| 32 | char name[5]; |
---|
| 33 | rtems_id id; |
---|
| 34 | rtems_status_code status; |
---|
| 35 | long tmp; |
---|
| 36 | rtems_task_priority ceiling; |
---|
| 37 | rtems_attribute attr; |
---|
| 38 | struct getopt_data getopt_reent; |
---|
| 39 | char option; |
---|
| 40 | int value; |
---|
| 41 | |
---|
| 42 | CHECK_RTEMS_IS_UP(); |
---|
| 43 | |
---|
| 44 | ceiling = 0; |
---|
| 45 | attr = RTEMS_DEFAULT_ATTRIBUTES; |
---|
| 46 | value = 0; |
---|
| 47 | |
---|
| 48 | memset(&getopt_reent, 0, sizeof(getopt_data)); |
---|
| 49 | while ( (option = getopt_r( argc, argv, "bcsfpiC:V:", &getopt_reent)) != -1 ) { |
---|
| 50 | switch (option) { |
---|
| 51 | case 'b': attr |= RTEMS_BINARY_SEMAPHORE; break; |
---|
| 52 | case 'c': attr |= RTEMS_COUNTING_SEMAPHORE; break; |
---|
| 53 | case 's': attr |= RTEMS_SIMPLE_BINARY_SEMAPHORE; break; |
---|
| 54 | |
---|
| 55 | case 'f': attr |= RTEMS_FIFO; break; |
---|
| 56 | case 'p': attr |= RTEMS_PRIORITY; break; |
---|
| 57 | |
---|
| 58 | case 'i': attr |= RTEMS_INHERIT_PRIORITY; break; |
---|
| 59 | case 'C': |
---|
| 60 | attr |= RTEMS_PRIORITY_CEILING; |
---|
| 61 | if ( rtems_string_to_long(getopt_reent.optarg, &tmp, NULL, 0) ) { |
---|
| 62 | printf( "Ceiling argument (%s) is not a number\n", argv[1] ); |
---|
| 63 | return -1; |
---|
| 64 | } |
---|
| 65 | ceiling = tmp; |
---|
| 66 | break; |
---|
| 67 | |
---|
| 68 | case 'V': |
---|
| 69 | if ( rtems_string_to_long(getopt_reent.optarg, &tmp, NULL, 0) ) { |
---|
| 70 | printf( "Ceiling argument (%s) is not a number\n", argv[1] ); |
---|
| 71 | return -1; |
---|
| 72 | } |
---|
| 73 | value = tmp; |
---|
| 74 | break; |
---|
| 75 | |
---|
| 76 | default: |
---|
| 77 | fprintf( stderr, "%s: Usage [-bcsfpiC:V:] name\n", argv[0] ); |
---|
| 78 | return -1; |
---|
| 79 | } |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | if ( getopt_reent.optind >= argc ) { |
---|
| 83 | fprintf( stderr, "No name specified\n" ); |
---|
| 84 | return -1; |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | /* |
---|
| 88 | * Now create the semaphore |
---|
| 89 | */ |
---|
| 90 | memset( name, '\0', sizeof(name) ); |
---|
| 91 | strncpy( name, argv[getopt_reent.optind], 4 ); |
---|
| 92 | |
---|
| 93 | status = rtems_semaphore_create( |
---|
| 94 | rtems_build_name( name[0], name[1], name[2], name[3] ), |
---|
| 95 | value, |
---|
| 96 | attr, |
---|
| 97 | ceiling, |
---|
| 98 | &id |
---|
| 99 | ); |
---|
| 100 | if ( status ) { |
---|
| 101 | fprintf( |
---|
| 102 | stderr, |
---|
| 103 | "Semaphore create(%s) returned %s\n", |
---|
| 104 | argv[1], |
---|
| 105 | rtems_status_text( status ) |
---|
[b38dbcc] | 106 | ); |
---|
[abb18dc] | 107 | return -1; |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | printf( "Semaphore (%s) created: id=0x%08x\n", argv[1], id ); |
---|
[b38dbcc] | 111 | |
---|
[abb18dc] | 112 | return 0; |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | rtems_shell_cmd_t rtems_shell_SEMAPHORE_CREATE_Command = { |
---|
| 116 | "semaphore_create", /* name */ |
---|
| 117 | "semaphore_create name priority", /* usage */ |
---|
| 118 | "rtems", /* topic */ |
---|
| 119 | rtems_shell_main_semaphore_create, /* command */ |
---|
| 120 | NULL, /* alias */ |
---|
| 121 | NULL /* next */ |
---|
| 122 | }; |
---|