Ejemplo n.º 1
0
/*
 * net_buffer_init
 * This function will initialize the buffer file system for out networking
 * stack.
 */
void net_buffer_init()
{
    /* Clear the global structure. */
    memset(&net_buffers_fs, 0, sizeof(NET_BUFFER_FS));

    /* Initialize the buffer data. */
    net_buffers_fs.fs.name = "\\net\\buffers";
    net_buffers_fs.fs.get_lock = &net_buffer_lock;
    net_buffers_fs.fs.release_lock = &net_buffer_unlock;

    /* Read and write functions. */
    net_buffers_fs.fs.write = &net_buffer_write;
    net_buffers_fs.fs.read = &net_buffer_read;

    /* Initial file system configurations. */
    net_buffers_fs.fs.flags = (FS_SPACE_AVAILABLE);
    net_buffers_fs.fs.timeout = MAX_WAIT;

    /* Initialize file system condition. */
    fs_condition_init(&net_buffers_fs.fs);

#ifdef CONFIG_SEMAPHORE
    /* Create a semaphore to protect net buffer file descriptor. */
    semaphore_create(&net_buffers_fs.lock, 1, 1, SEMAPHORE_PRIORITY);
#endif

    /* Register net buffer file system. */
    fs_register((FS *)&net_buffers_fs);

    /* Set the global networking stack buffer descriptor. */
    net_buff_fd = (FD)&net_buffers_fs;

} /* net_buffer_init */
Ejemplo n.º 2
0
/*
 * console_register
 * @console: Console data.
 * This function will register a console.
 */
void console_register(CONSOLE *console)
{
#ifndef CONFIG_SEMAPHORE
    /* Lock the scheduler. */
    scheduler_lock();
#else
    /* Obtain the global data lock. */
    OS_ASSERT(semaphore_obtain(&console_data.lock, MAX_WAIT) != SUCCESS);

    /* Create a semaphore to protect this console device. */
    memset(&console->lock, 0, sizeof(SEMAPHORE));
    semaphore_create(&console->lock, 1, 1, SEMAPHORE_PRIORITY);
#endif

    /* This utility is called by drivers for registering consoles for the
     * applicable devices, so no need to check for name conflicts. */
    /* Just push this file system in the list. */
    sll_push(&console_data.list, console, OFFSETOF(CONSOLE, fs.next));

    /* Initialize console FS data. */
    console->fs.get_lock = console_lock;
    console->fs.release_lock = console_unlock;
    console->fs.timeout = MAX_WAIT;

    /* Initialize file system condition. */
    fs_condition_init(&console->fs);

#ifdef CONFIG_SEMAPHORE
    /* Release the global data lock. */
    semaphore_release(&console_data.lock);
#else
    /* Enable scheduling. */
    scheduler_unlock();
#endif

} /* console_register */