| 53 | #endif |
| 54 | |
| 55 | static char *alloc_device_name(struct rt_serial_device *serial) |
| 56 | { |
| 57 | char *tty_dev_name; |
| 58 | #ifdef RT_USING_DM |
| 59 | char *serial_name = serial->parent.parent.name; |
| 60 | /* |
| 61 | * if RT_USING_DM is defined, the name of the serial device |
| 62 | * must be obtained using the serial_dev_set_name function, |
| 63 | * and it should begin with "uart". |
| 64 | */ |
| 65 | RT_ASSERT((strlen(serial_name) > strlen("uart")) && (strncmp(serial_name, "uart", 4) == 0)); |
| 66 | long digits_len = (sizeof(TTY_NAME_PREFIX) - 1) /* raw prefix */ |
| 67 | + strlen(serial_name + sizeof("uart") - 1) /* suffix of serial device name*/ |
| 68 | + 1; /* tailing \0 */ |
| 69 | |
| 70 | tty_dev_name = rt_malloc(digits_len); |
| 71 | if (tty_dev_name) |
| 72 | rt_sprintf(tty_dev_name, "%s%s", TTY_NAME_PREFIX, serial_name + sizeof("uart") - 1); |
| 73 | #else |
| 74 | RT_UNUSED(serial); |
| 75 | unsigned int devid = rt_atomic_add(&_device_id_counter, 1); |
| 76 | long digits_len = (sizeof(TTY_NAME_PREFIX) - 1) /* raw prefix */ |
| 77 | + get_dec_digits(devid) + 1; /* tailing \0 */ |
| 78 | |
| 79 | tty_dev_name = rt_malloc(digits_len); |
| 80 | if (tty_dev_name) |
| 81 | rt_sprintf(tty_dev_name, "%s%u", TTY_NAME_PREFIX, devid); |
| 82 | #endif |
| 83 | return tty_dev_name; |
| 84 | } |
| 85 | |
| 86 | #ifdef LWP_DEBUG_INIT |
| 87 | static volatile int _early_input = 0; |
no test coverage detected