vbus_drv.c 3.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
/*
 * VMM Bus Driver
 *
 * COPYRIGHT (C) 2015, Shanghai Real-Thread Technology Co., Ltd
 *      http://www.rt-thread.com
 *
 *  This file is part of RT-Thread (http://www.rt-thread.org)
 *
 *  All rights reserved.
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Change Logs:
 * Date           Author       Notes
 * 2015-01-07     Grissiom     add comment
 */

#include <rtthread.h>

#ifdef RT_USING_VBUS
#include <rtdevice.h>
#include <rthw.h>
#include <interrupt.h>
#include <vbus.h>
#include <board.h>

int rt_vbus_do_init(void)
{
    return rt_vbus_init((void*)_RT_VBUS_RING_BASE,
                        (void*)(_RT_VBUS_RING_BASE + _RT_VBUS_RING_SZ));
}
INIT_COMPONENT_EXPORT(rt_vbus_do_init);

static void _bus_resume_in_thread(int irqnr, void *param)
{
    rt_vbus_isr(irqnr, RT_NULL);
}

int rt_vbus_hw_init(void)
{
    rt_kprintf("install irq: %d\n", RT_VBUS_HOST_VIRQ);
    rt_hw_interrupt_install(RT_VBUS_HOST_VIRQ,
                            _bus_resume_in_thread, RT_NULL,
                            "vbusin");
    rt_hw_interrupt_umask(RT_VBUS_HOST_VIRQ);

    return 0;
}

int rt_vbus_hw_eoi(int irqnr, void *param)
{
    rt_hw_interrupt_clear(irqnr);

    return 0;
}

#define RT_VBUS_SER_PRIO  20
#define RT_VBUS_RFS_PRIO  19
#define RT_VBUS_TASK2_PRIO 6
#define RT_VBUS_INT_PRIO   4

struct rt_vbus_dev rt_vbus_chn_devx[] = {
    {
        .req =
        {
            .prio = RT_VBUS_SER_PRIO,
            .name = RT_VBUS_SHELL_DEV_NAME,
            .is_server = 1,
            .recv_wm.low = RT_VMM_RB_BLK_NR / 3,
            .recv_wm.high = RT_VMM_RB_BLK_NR * 2 / 3,
            .post_wm.low = RT_VMM_RB_BLK_NR / 3,
            .post_wm.high = RT_VMM_RB_BLK_NR * 2 / 3,
        }
    },
    {
        .req =
        {
            .prio = 23,
            .name = RT_VBUS_RFS_DEV_NAME,
            .is_server = 0,
            .recv_wm.low = RT_VMM_RB_BLK_NR / 3,
            .recv_wm.high = RT_VMM_RB_BLK_NR * 2 / 3,
            .post_wm.low = RT_VMM_RB_BLK_NR / 3,
            .post_wm.high = RT_VMM_RB_BLK_NR * 2 / 3,
        }
    },
    {
        .req =
        {
            .prio = 30,
            .name = "vecho",
            .is_server = 1,
            .recv_wm.low = RT_VMM_RB_BLK_NR / 3,
            .recv_wm.high = RT_VMM_RB_BLK_NR * 2 / 3,
            .post_wm.low = RT_VMM_RB_BLK_NR / 3,
            .post_wm.high = RT_VMM_RB_BLK_NR * 2 / 3,
        }
    },
    {
        .req =
        {
            .name = RT_NULL,
        }
    },
};

#endif /* RT_USING_VBUS */