| 1732 | ****************************************************************************/ |
| 1733 | |
| 1734 | int audio_register(FAR const char *name, FAR struct audio_lowerhalf_s *dev) |
| 1735 | { |
| 1736 | FAR struct audio_upperhalf_s *upper; |
| 1737 | char path[AUDIO_MAX_DEVICE_PATH]; |
| 1738 | static bool dev_audio_created = false; |
| 1739 | #ifndef CONFIG_AUDIO_CUSTOM_DEV_PATH |
| 1740 | FAR const char *devname = "/dev/audio"; |
| 1741 | #elif !defined(CONFIG_AUDIO_DEV_ROOT) |
| 1742 | FAR const char *devname = CONFIG_AUDIO_DEV_PATH; |
| 1743 | FAR const char *ptr; |
| 1744 | FAR char *pathptr; |
| 1745 | #endif |
| 1746 | |
| 1747 | /* Allocate the upper-half data structure */ |
| 1748 | |
| 1749 | upper = kmm_zalloc(sizeof(struct audio_upperhalf_s)); |
| 1750 | if (!upper) |
| 1751 | { |
| 1752 | auderr("ERROR: Allocation failed\n"); |
| 1753 | return -ENOMEM; |
| 1754 | } |
| 1755 | |
| 1756 | /* Initialize the Audio device structure |
| 1757 | * (it was already zeroed by kmm_zalloc()) |
| 1758 | */ |
| 1759 | |
| 1760 | nxmutex_init(&upper->lock); |
| 1761 | spin_lock_init(&upper->spinlock); |
| 1762 | upper->dev = dev; |
| 1763 | |
| 1764 | #ifdef CONFIG_AUDIO_CUSTOM_DEV_PATH |
| 1765 | |
| 1766 | #ifdef CONFIG_AUDIO_DEV_ROOT |
| 1767 | |
| 1768 | /* This is the simple case ... No need to make a directory */ |
| 1769 | |
| 1770 | strlcpy(path, "/dev/", sizeof(path)); |
| 1771 | strlcat(path, name, sizeof(path)); |
| 1772 | |
| 1773 | #else |
| 1774 | /* Ensure the path begins with "/dev" as we don't support placing device |
| 1775 | * anywhere but in the /dev directory |
| 1776 | */ |
| 1777 | |
| 1778 | DEBUGASSERT(strncmp(devname, "/dev", 4) == 0); |
| 1779 | |
| 1780 | /* Create a /dev/audio directory. */ |
| 1781 | |
| 1782 | if (!dev_audio_created) |
| 1783 | { |
| 1784 | /* Get path name after "/dev" */ |
| 1785 | |
| 1786 | ptr = &devname[4]; |
| 1787 | if (*ptr == '/') |
| 1788 | { |
| 1789 | ptr++; |
| 1790 | } |
| 1791 |
no test coverage detected