コード例 #1
0
ファイル: uart.c プロジェクト: heyuanjie87/rt-thread
void rt_hw_uart_init(void)
{
	struct rt_uart_lpc* uart;

#ifdef RT_USING_UART0
	/* get uart device */
	uart = &uart0_device;
	uart0_device.UART = LPC_UART0;
	uart0_device.UART_IRQn = UART0_IRQn;

	/* device initialization */
	uart->parent.type = RT_Device_Class_Char;
	rt_memset(uart->rx_buffer, 0, sizeof(uart->rx_buffer));
	uart->read_index = uart->save_index = 0;

	/* device interface */
	uart->parent.init 	    = rt_uart_init;
	uart->parent.open 	    = rt_uart_open;
	uart->parent.close      = rt_uart_close;
	uart->parent.read 	    = rt_uart_read;
	uart->parent.write      = rt_uart_write;
	uart->parent.control    = RT_NULL;
	uart->parent.user_data  = RT_NULL;

	rt_device_register(&uart->parent,
		"uart0", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_STREAM | RT_DEVICE_FLAG_INT_RX);
#endif

#ifdef RT_USING_UART1
	/* get uart device */
	uart = &uart1_device;
	uart1_device.UART = (LPC_UART_TypeDef *)LPC_UART1;
	uart1_device.UART_IRQn = UART1_IRQn;

	/* device initialization */
	uart->parent.type = RT_Device_Class_Char;
	rt_memset(uart->rx_buffer, 0, sizeof(uart->rx_buffer));
	uart->read_index = uart->save_index = 0;

	/* device interface */
	uart->parent.init 	    = rt_uart_init;
	uart->parent.open 	    = rt_uart_open;
	uart->parent.close      = rt_uart_close;
	uart->parent.read 	    = rt_uart_read;
	uart->parent.write      = rt_uart_write;
	uart->parent.control    = RT_NULL;
	uart->parent.user_data  = RT_NULL;

	rt_device_register(&uart->parent,
		"uart1", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_STREAM | RT_DEVICE_FLAG_INT_RX);
#endif
}
コード例 #2
0
ファイル: usbh_usr.c プロジェクト: mildrock/705_1
/**
 * @brief  USBH_USR_MSC_Application
 *         Demo application for mass storage
 * @param  None
 * @retval Staus
 */
int USBH_USR_MSC_Application( void )
{
//	FRESULT res;
	int		ret;

	if( diskinited )
	{
		return 0;
	}

	mscdev.type			= RT_Device_Class_Block;
	mscdev.init			= msc_init;
	mscdev.open			= msc_open;
	mscdev.close		= msc_close;
	mscdev.read			= msc_read;
	mscdev.write		= msc_write;
	mscdev.control		= msc_control;
	mscdev.user_data	= RT_NULL;
	diskinited			= 1;

	rt_device_register( &mscdev, "udisk", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_REMOVABLE );
	rt_device_init( &mscdev );
	rt_thread_delay( RT_TICK_PER_SECOND / 10 );
	//ret = dfs_mount( "udisk", "/udisk", "elm", 0, 0 );
	if(0 == f_mount(USB, &fs))
		{
		rt_kprintf("\n f_mount USB OK!");
		}
	
	//rt_kprintf( "\ndfs_mount ret=%x  now udisk start", ret );

	return 0;
}
コード例 #3
0
ファイル: usbh_usr.c プロジェクト: nathanlnw/tw705_HB_gghypt
/**
 * @brief  USBH_USR_MSC_Application
 *         Demo application for mass storage
 * @param  None
 * @retval Staus
 */
int USBH_USR_MSC_Application( void )
{
    int		ret;

    if( diskinited )
    {
        return 0;
    }

    mscdev.type			= RT_Device_Class_Block;
    mscdev.init			= msc_init;
    mscdev.open			= msc_open;
    mscdev.close		= msc_close;
    mscdev.read			= msc_read;
    mscdev.write		= msc_write;
    mscdev.control		= msc_control;
    mscdev.user_data	= RT_NULL;
    diskinited			= 1;

    rt_device_register( &mscdev, "udisk", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_REMOVABLE );
    rt_device_init( &mscdev );
    rt_thread_delay( RT_TICK_PER_SECOND / 10 );
    ret = dfs_mount( "udisk", "/udisk", "elm", 0, 0 );

    rt_kprintf( "dfs_mount ret=%x  now udisk start\r\n", ret );
    USB_find_status = USB_FIND;
    Show_Menu_5_2_ExportData();
    return 0;
}
コード例 #4
0
ファイル: drv_lcd.c プロジェクト: Alexlcb/rt-thread
int gd32_hw_lcd_init(void)
{
    _rt_framebuffer = rt_malloc_align(sizeof(rt_uint16_t) * RT_HW_LCD_WIDTH * RT_HW_LCD_HEIGHT, 32);
    if (_rt_framebuffer == RT_NULL) 
        return -1; /* no memory yet */
    
    lcd_config();
    tli_config();
    tli_layer_enable(LAYER0);  
    tli_reload_config(TLI_FRAME_BLANK_RELOAD_EN);
    tli_enable();
    
    _lcd_info.bits_per_pixel = LCD_BITS_PER_PIXEL;
    _lcd_info.pixel_format   = RTGRAPHIC_PIXEL_FORMAT_RGB565;
    _lcd_info.framebuffer    = (void *)_rt_framebuffer;
    _lcd_info.width          = RT_HW_LCD_WIDTH;
    _lcd_info.height         = RT_HW_LCD_HEIGHT;
    
    lcd.type    = RT_Device_Class_Graphic;
    lcd.init    = NULL;
    lcd.open    = NULL;
    lcd.close   = NULL;
    lcd.read    = NULL;
    lcd.write   = NULL;
    lcd.control = rt_lcd_control;
    lcd.user_data = (void *)&_lcd_info;
    
    /* register lcd device to RT-Thread */
    rt_device_register(&lcd, "lcd", RT_DEVICE_FLAG_RDWR);
    
    return 0;
}
コード例 #5
0
ファイル: lpc17xx_lcd.c プロジェクト: 304471720/rt-thread
/* LCD BL P5_4 */
void rt_hw_lcd_init(void)
{
    rt_uint16_t * _rt_framebuffer = RT_NULL;

	// _rt_framebuffer = rt_malloc_align(sizeof(rt_uint16_t)*RT_HW_LCD_HEIGHT*RT_HW_LCD_WIDTH, 8);
	// if (_rt_framebuffer == RT_NULL) return; /* no memory yet */

	_rt_framebuffer = (rt_uint16_t *)0xA0000000;

	_lcd_info.bits_per_pixel = 16;
	_lcd_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565;
	_lcd_info.framebuffer = (void*)_rt_framebuffer;
	_lcd_info.width = RT_HW_LCD_WIDTH;
	_lcd_info.height = RT_HW_LCD_HEIGHT;

	/* init device structure */
	lcd.type = RT_Device_Class_Graphic;
	lcd.init = rt_lcd_init;
	lcd.open = RT_NULL;
	lcd.close = RT_NULL;
	lcd.control = rt_lcd_control;
	lcd.user_data = (void*)&_lcd_info;

	/* register lcd device to RT-Thread */
	rt_device_register(&lcd, "lcd", RT_DEVICE_FLAG_RDWR);
}
コード例 #6
0
ファイル: console.c プロジェクト: heyuanjie87/rt-thread
/**
 * This function initializes console
 *
 */
void rt_hw_console_init(void)
{
    rt_cga_init();
	rt_serial_init();
	init_keyboard();

    /* install  keyboard isr */
    rt_hw_interrupt_install(INTKEYBOARD, rt_console_isr, RT_NULL, "kbd");
    rt_hw_interrupt_umask(INTKEYBOARD);

    rt_hw_interrupt_install(INTUART0_RX, rt_console_isr, RT_NULL, "COM1");
    rt_hw_interrupt_umask(INTUART0_RX);

    console_device.type 		= RT_Device_Class_Char;
    console_device.rx_indicate  = RT_NULL;
    console_device.tx_complete  = RT_NULL;
    console_device.init 		= rt_console_init;
    console_device.open		    = rt_console_open;
    console_device.close		= rt_console_close;
    console_device.read 		= rt_console_read;
    console_device.write 	    = rt_console_write;
    console_device.control      = rt_console_control;
    console_device.user_data    = RT_NULL;

    /* register a character device */
    rt_device_register(&console_device,
                              "console",
                              RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_STREAM);
}
コード例 #7
0
void rt_hw_dc_init(void)
{
	rt_device_t dc = rt_malloc(sizeof(struct rt_device));
	if (dc == RT_NULL) 
	{
		rt_kprintf("dc == RT_NULL\n");
		return; /* no memory yet */
	}

	_dc_info.bits_per_pixel = 16;
	_dc_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565P;
	_dc_info.framebuffer = (rt_uint8_t*)HW_FB_ADDR;
	_dc_info.width = FB_XSIZE;
	_dc_info.height = FB_YSIZE;

	/* init device structure */
	dc->type = RT_Device_Class_Graphic;
	dc->init = rt_dc_init;
	dc->open = RT_NULL;
	dc->close = RT_NULL;
	dc->control = rt_dc_control;
	dc->user_data = (void*)&_dc_info;
	
	/* register Display Controller device to RT-Thread */
	rt_device_register(dc, "dc", RT_DEVICE_FLAG_RDWR);
}
コード例 #8
0
ファイル: FM25Lx.c プロジェクト: 304471720/rt-thread
void fm25_hw_init()
{
	int i = 0xFFFFF;
	fm25_spi_cfg();

	while(i--);
	//spi_config();
	CS_LOW();
    spi_readwrite( FM25_WRDI );
    CS_HIGH();

	spi_flash_device.type    = RT_Device_Class_Block;
    spi_flash_device.init    = fm25_init;
    spi_flash_device.open    = fm25_open;
    spi_flash_device.close   = fm25_close;
    spi_flash_device.read 	 = fm25_read;
    spi_flash_device.write   = fm25_write;
    spi_flash_device.control = fm25_control;
    /* no private */
    spi_flash_device.user_data = RT_NULL;

    rt_device_register(&spi_flash_device, "fram0",
                       RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_STANDALONE);

}
コード例 #9
0
ファイル: drv_rtc.c プロジェクト: TAURUS3G/RealBoard4088
void rt_hw_rtc_init(void)
{
	rtc.type	= RT_Device_Class_RTC;
	RTC_Init(LPC_RTC);
    if (RTC_ReadGPREG(LPC_RTC,0) != FIRST_DATA)
    {
        rt_kprintf("rtc is not configured\n");
        rt_kprintf("please configure with set_date and set_time\n");
    }
    else
    {
    }
    RTC_Cmd(LPC_RTC,ENABLE);
    /* register rtc device */
    rtc.init 	= RT_NULL;
    rtc.open 	= rt_rtc_open;
    rtc.close	= RT_NULL;
    rtc.read 	= rt_rtc_read;
    rtc.write	= RT_NULL;
    rtc.control = rt_rtc_control;

    /* no private */
    rtc.user_data = RT_NULL;

    rt_device_register(&rtc, "rtc", RT_DEVICE_FLAG_RDWR);

#ifdef RT_USING_FINSH
    {
        extern void list_date(void);
        list_date();
    }
#endif

    return;
}
コード例 #10
0
ファイル: drv_lcd.c プロジェクト: yanbib/smartcar
int rt_hw_lcd_init(const char *name)
{
    
    struct lcd_device *dev;
    
    if(rt_device_find(name))
    {
        return -RT_EIO;
    }
    
    dev = rt_malloc(sizeof(struct lcd_device));
    if(!dev)
    {
        return RT_ENOMEM;
    }
    
	dev->rtdev.type         = RT_Device_Class_Graphic;
	dev->rtdev.rx_indicate  = RT_NULL;
	dev->rtdev.init         = rt_lcd_init;
	dev->rtdev.open         = RT_NULL;
	dev->rtdev.close		= RT_NULL;
	dev->rtdev.read 		= RT_NULL;
	dev->rtdev.write        = RT_NULL;
	dev->rtdev.control      = rt_lcd_control;
	dev->rtdev.user_data	= RT_NULL;

    /* initialize mutex */
    rt_mutex_init(&dev->lock, name, RT_IPC_FLAG_FIFO);
    rt_device_register(&dev->rtdev, name, RT_DEVICE_FLAG_RDWR);
    return RT_EOK;
}
コード例 #11
0
ファイル: rs485.c プロジェクト: mildrock/705_1
/*RS485设备初始化*/
void RS485_init( void )
{
	//rt_sem_init( &sem_RS485, "sem_RS485", 0, 0 );
	rt_mq_init( &mq_RS485, "mq_RS485", &RS485_rawinfo[0], 128 - sizeof( void* ), RS485_RAWINFO_SIZE, RT_IPC_FLAG_FIFO );

	dev_RS485.type		= RT_Device_Class_Char;
	dev_RS485.init		= dev_RS485_init;
	dev_RS485.open		= dev_RS485_open;
	dev_RS485.close		= dev_RS485_close;
	dev_RS485.read		= dev_RS485_read;
	dev_RS485.write		= dev_RS485_write;
	dev_RS485.control	= dev_RS485_control;

	rt_device_register( &dev_RS485, "RS485", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_STANDALONE );
	rt_device_init( &dev_RS485 );
	Cam_Device_init( );

	rt_thread_init( &thread_RS485,
	                "RS485",
	                rt_thread_entry_RS485,
	                RT_NULL,
	                &thread_RS485_stack[0],
	                sizeof( thread_RS485_stack ), 9, 5 );
	rt_thread_startup( &thread_RS485 );
}
コード例 #12
0
ファイル: sdl_fb.c プロジェクト: 634351070/rt-thread
static void sdlfb_hw_init(void)
{
    /* set video driver for VC++ debug */
    //_putenv("SDL_VIDEODRIVER=windib");

    //if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_AUDIO) < 0)
    if (SDL_Init(SDL_INIT_VIDEO) < 0)
    {
        fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
        exit(1);
    }

    _device.parent.init = sdlfb_init;
    _device.parent.open = sdlfb_open;
    _device.parent.close = sdlfb_close;
    _device.parent.read = RT_NULL;
    _device.parent.write = RT_NULL;
    _device.parent.control = sdlfb_control;

    _device.width  = SDL_SCREEN_WIDTH;
    _device.height = SDL_SCREEN_HEIGHT;
    _device.screen = SDL_SetVideoMode(_device.width, _device.height, 16, SDL_SWSURFACE | SDL_DOUBLEBUF);
    if (_device.screen == NULL)
    {
        fprintf(stderr, "Couldn't set video mode: %s\n", SDL_GetError());
        exit(1);
    }

    SDL_WM_SetCaption("RT-Thread/GUI Simulator", NULL);
    rt_device_register(RT_DEVICE(&_device), "sdl", RT_DEVICE_FLAG_RDWR);

    sdllock = rt_mutex_create("fb", RT_IPC_FLAG_FIFO);
}
コード例 #13
0
ファイル: drv_lcd.c プロジェクト: onelife/rt-thread
int stm32_hw_lcd_init(void)
{
    _rt_framebuffer = rt_malloc_align(sizeof(rt_uint16_t) * RT_HW_LCD_WIDTH * RT_HW_LCD_HEIGHT, 32);
    if (_rt_framebuffer == RT_NULL) 
        return -1; /* no memory yet */
    
    LTDC_CLK_Config();
    MX_LTDC_Init();
    lcd_backlight_init();
    MX_DMA2D_Init();
    
    _lcd_info.bits_per_pixel = LCD_BITS_PER_PIXEL;
    _lcd_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565;		// RTGRAPHIC_PIXEL_FORMAT_ARGB888
    _lcd_info.framebuffer = (void *)_rt_framebuffer;
    _lcd_info.width = RT_HW_LCD_WIDTH;
    _lcd_info.height = RT_HW_LCD_HEIGHT;
    
        /* init device structure */
    lcd.type = RT_Device_Class_Graphic;
    lcd.init = rt_lcd_init;
    lcd.open = rt_lcd_open;
    lcd.close = rt_lcd_close;
    lcd.read = NULL;
    lcd.write = NULL;
    lcd.control = rt_lcd_control;
    lcd.user_data = (void *)&_lcd_info;
    
    /* register lcd device to RT-Thread */
    rt_device_register(&lcd, "lcd", RT_DEVICE_FLAG_RDWR);
    
    return 0;
}
コード例 #14
0
ファイル: drv_ads7843.c プロジェクト: guzhaoyuan/smartCar
rt_err_t ads7843_init(const char * name, const char * spi_device_name)
{

    rt_spi_device = (struct rt_spi_device *)rt_device_find(spi_device_name);
    if(rt_spi_device == RT_NULL)
    {
        rt_kprintf("spi device %s not found!\r\n", spi_device_name);
        return -RT_ENOSYS;
    }

    /* config spi */
    {
        struct rt_spi_configuration cfg;
        cfg.data_width = 8;
        cfg.mode = RT_SPI_MODE_0 | RT_SPI_MSB; /* SPI Compatible: Mode 0 and Mode 3 */
        cfg.max_hz = 2 * 1000 * 1000;
        rt_spi_configure(rt_spi_device, &cfg);
    }

    /* register device */
    ads7843_device.type    = RT_Device_Class_Block;
    ads7843_device.init    = RT_NULL;
    ads7843_device.open    = RT_NULL;
    ads7843_device.close   = RT_NULL;
    ads7843_device.read    = ads7843_read;
    ads7843_device.write   = RT_NULL;
    ads7843_device.control = RT_NULL;
    /* no private */
    ads7843_device.user_data = RT_NULL;

    rt_device_register(&ads7843_device, name,
                       RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_STANDALONE);

    return RT_EOK;
}
コード例 #15
0
ファイル: sd_mmc.c プロジェクト: ceecer2/avr32-hifi-player
void rt_hw_sd_mmc_init()
{
	if (sd_mmc_spi_internal_init())
	{
		rt_uint8_t *sector = rt_malloc(MMC_SECTOR_SIZE);
		sd_mmc_spi_read_open(0);
		if (sd_mmc_spi_read_sector_to_ram(sector))
		{
			if (dfs_filesystem_get_partition(&sd_mmc_partition, sector, 0) != RT_EOK)
			{
				sd_mmc_partition.offset = 0;
				sd_mmc_partition.size = 0;
			}
		}
		else
		{
			sd_mmc_partition.offset = 0;
			sd_mmc_partition.size = 0;
		}
		sd_mmc_spi_read_close();
		rt_free(sector);

		rt_device_register(&sd_mmc_device, "sd0", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_REMOVABLE | RT_DEVICE_FLAG_STANDALONE);
	}
	else
	{
		rt_kprintf("Failed to initialize SD/MMC card.\n");
	}
}
コード例 #16
0
ファイル: rtc.c プロジェクト: nodeboy/nodeboyRepo
void rt_hw_rtc_init(void)
{
    rtc.type	= RT_Device_Class_RTC;
    if (BKP_ReadBackupRegister(BKP_DR1) != 0xA5A5)
    {
        rt_kprintf("rtc is not configured\n");
        rt_kprintf("please configure with set_date and set_time\n");
        if ( RTC_Configuration() != 0)
        {
            rt_kprintf("rtc configure fail...\r\n");
            return ;
        }
    }
    else
    {
        /* Wait for RTC registers synchronization */
        RTC_WaitForSynchro();
    }

    /* register rtc device */
    rtc.init 	= RT_NULL;
    rtc.open 	= rt_rtc_open;
    rtc.close	= RT_NULL;
    rtc.read 	= rt_rtc_read;
    rtc.write	= RT_NULL;
    rtc.control = rt_rtc_control;

    /* no private */
    rtc.user_data = RT_NULL;

    rt_device_register(&rtc, "rtc", RT_DEVICE_FLAG_RDWR);

    return;
}
コード例 #17
0
ファイル: serial.c プロジェクト: comrid1987/jb3500
void rt_hw_console_init(void)
{
	struct rt_lm3s_serial* serial;

	serial = &serial1;

	serial->parent.type = RT_Device_Class_Char;

	serial->hw_base = UART0_BASE;
	serial->baudrate = 115200;

	rt_memset(serial->rx_buffer, 0, sizeof(serial->rx_buffer));
	serial->read_index = serial->save_index = 0;

	/* enable UART0 clock */
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

	/* set UART0 pinmux */
    MAP_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

	/* Configure the UART for 115,200, 8-N-1 operation. */
	MAP_UARTConfigSetExpClk(UART0_BASE, MAP_SysCtlClockGet(), serial->baudrate, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));

	serial->parent.init 	= rt_serial_init;
	serial->parent.open 	= rt_serial_open;
	serial->parent.close    = rt_serial_close;
	serial->parent.read 	= rt_serial_read;
	serial->parent.write    = rt_serial_write;
	serial->parent.control  = rt_serial_control;
	serial->parent.user_data= RT_NULL;

	rt_device_register(&serial->parent, "uart1", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_STREAM);
}
コード例 #18
0
/*
 * serial register
 */
rt_err_t rt_hw_serial_register(struct rt_serial_device *serial,
                               const char              *name,
                               rt_uint32_t              flag,
                               void                    *data)
{
    struct rt_device *device;
    RT_ASSERT(serial != RT_NULL);

    device = &(serial->parent);

    device->type        = RT_Device_Class_Char;
    device->rx_indicate = RT_NULL;
    device->tx_complete = RT_NULL;

    device->init        = rt_serial_init;
    device->open        = rt_serial_open;
    device->close       = rt_serial_close;
    device->read        = rt_serial_read;
    device->write       = rt_serial_write;
    device->control     = rt_serial_control;
    device->user_data   = data;

    /* register a character device */
    return rt_device_register(device, name, flag);
}
コード例 #19
0
ファイル: drv_usart.c プロジェクト: hduffddybz/rt-thread
/***************************************************************************//**
* @brief
*   Register USART device
*
* @details
*
* @note
*
* @param[in] device
*   Pointer to device descriptor
*
* @param[in] name
*   Device name
*
* @param[in] flag
*   Configuration flags
*
* @param[in] usart
*   Pointer to USART device descriptor
*
* @return
*   Error code
******************************************************************************/
rt_err_t rt_hw_usart_register(
    rt_device_t     device,
    const char      *name,
    rt_uint32_t     flag,
    struct efm32_usart_device_t *usart)
{
    RT_ASSERT(device != RT_NULL);

    if ((flag & RT_DEVICE_FLAG_DMA_RX) ||
            (flag & RT_DEVICE_FLAG_INT_TX))
    {
        RT_ASSERT(0);
    }

    if (usart->state & USART_STATE_SYNC)
    {
        device->type    = RT_Device_Class_SPIBUS;
    }
    else
    {
        device->type    = RT_Device_Class_Char;
    }
    device->rx_indicate = RT_NULL;
    device->tx_complete = RT_NULL;
    device->init        = rt_usart_init;
    device->open        = rt_usart_open;
    device->close       = rt_usart_close;
    device->read        = rt_usart_read;
    device->write       = rt_usart_write;
    device->control     = rt_usart_control;
    device->user_data   = usart;

    /* register a character device */
    return rt_device_register(device, name, RT_DEVICE_FLAG_RDWR | flag);
}
コード例 #20
0
ファイル: drv_iic.c プロジェクト: 304471720/rt-thread
/***************************************************************************//**
 * @brief
 *  Register IIC device
 *
 * @details
 *
 * @note
 *
 * @param[in] device
 *  Pointer to device descriptor
 *
 * @param[in] name
 *  Device name
 *
 * @param[in] flag
 *  Configuration flags
 *
 * @param[in] iic
 *  Pointer to IIC device descriptor
 *
 * @return
 *  Error code
 ******************************************************************************/
rt_err_t rt_hw_iic_register(
    rt_device_t     device,
    const char      *name,
    rt_uint32_t     flag,
    struct efm32_iic_device_t *iic)
{
    RT_ASSERT(device != RT_NULL);

    if ((flag & RT_DEVICE_FLAG_DMA_TX) || (flag & RT_DEVICE_FLAG_DMA_RX) ||
        (flag & RT_DEVICE_FLAG_INT_TX))
    {
        RT_ASSERT(0);
    }

    device->type        = RT_Device_Class_Unknown;
    device->rx_indicate = RT_NULL;
    device->tx_complete = RT_NULL;
    device->init        = rt_iic_init;
    device->open        = rt_iic_open;
    device->close       = rt_iic_close;
    device->read        = rt_iic_read;
    device->write       = rt_iic_write;
    device->control     = rt_iic_control;
    device->user_data   = iic;

    /* register a character device */
    return rt_device_register(device, name, RT_DEVICE_FLAG_RDWR | flag);
}
コード例 #21
0
rt_err_t rt_hw_sdcard_init(const char * spi_device_name)
{
	int size;
    rt_uint32_t id, total_block;
    struct sdcard_device * sd;
    struct rt_device * device;

    sd = &_sdcard;
	device = &(sd->parent);

	lock = rt_mutex_create("lock", RT_IPC_FLAG_FIFO);

	/* open sd card file, if not exist, then create it  */
	sd->file = fopen(SDCARD_SIM, "rb+");
	if (sd->file == NULL)
	{
		/* create a file to simulate sd card */
		sd->file = fopen(SDCARD_SIM, "wb+");

		fseek(sd->file, 0, SEEK_END);
		size = ftell(sd->file);

		fseek(sd->file, 0, SEEK_SET );
		if (size < SDCARD_SIZE)
		{
			int i;
			unsigned char* ptr;

			ptr = (unsigned char*) malloc (1024 * 1024);
			if (ptr == NULL)
			{
				SD_TRACE("malloc error, no memory!\n");
				return RT_ERROR;
			}
			memset(ptr, 0x0, 1024 * 1024);

			fseek(sd->file, 0, SEEK_SET);

			for(i=0; i<(SDCARD_SIZE / (1024*1024)); i++)
				fwrite(ptr, 1024 * 1024, 1, sd->file);

			free(ptr);
		}
	}
	fseek(sd->file, 0, SEEK_SET);

	device->type  = RT_Device_Class_Block;								
	device->init = rt_sdcard_init;
	device->open = rt_sdcard_open;
	device->close = rt_sdcard_close;
	device->read = rt_sdcard_read;
	device->write = rt_sdcard_write;
	device->control = rt_sdcard_control;
	device->user_data = NULL;

	rt_device_register(device, "sd0",
		RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_REMOVABLE | RT_DEVICE_FLAG_STANDALONE);

    return RT_EOK;
}
コード例 #22
0
ファイル: codec.c プロジェクト: Manish-cimcon/micro
rt_err_t codec_hw_init(void)
{
    rt_device_t dev;

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC, ENABLE);
    RCC_APB1PeriphClockCmd(CODEC_I2S_RCC_APB1, ENABLE);
    RCC_AHBPeriphClockCmd(CODEC_I2S_RCC_AHB, ENABLE);

    NVIC_Configuration();
    GPIO_Configuration();
    I2S_Configuration(I2S_AudioFreq_44k);

    dev = (rt_device_t) &codec;
    dev->type = RT_Device_Class_Sound;
    dev->rx_indicate = RT_NULL;
    dev->tx_complete = RT_NULL;
    dev->init = codec_init;
    dev->open = codec_open;
    dev->close = codec_close;
    dev->read = RT_NULL;
    dev->write = codec_write;
    dev->control = codec_control;
    dev->user_data = RT_NULL;

    /* set read_index and put index to 0 */
    codec.read_index = 0;
    codec.put_index = 0;

    /* unselect */
    codec_set_csb();

    /* register the device */
    return rt_device_register(&codec.parent, "snd", RT_DEVICE_FLAG_WRONLY | RT_DEVICE_FLAG_DMA_TX);
}
コード例 #23
0
ファイル: uart.c プロジェクト: 304471720/rt-thread
void rt_hw_uart_init(void)
{
    // init uart
    set_baudrate(115200);
    IOWR_ALTERA_AVALON_UART_CONTROL(RS232_BASE, 0x80);//接收中断使能
    IOWR_ALTERA_AVALON_UART_STATUS(RS232_BASE, 0x0); // clean status
    alt_irq_register(RS232_IRQ, NULL, uart_isr);

    // register device
    uart_device.type = RT_Device_Class_Char;
    /* device interface */
    uart_device.init 	    = rt_uart_init;
    uart_device.open 	    = rt_uart_open;
    uart_device.close       = rt_uart_close;
    uart_device.read 	    = rt_uart_read;
    uart_device.write       = rt_uart_write;
    uart_device.control     = rt_uart_control;

    uart_device.user_data   = RT_NULL;
    uart_device.rx_indicate = RT_NULL;
    uart_device.tx_complete = RT_NULL;

    rt_device_register(&uart_device,
                       "uart", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_STREAM | RT_DEVICE_FLAG_INT_RX);
}
コード例 #24
0
ファイル: ethernetif.c プロジェクト: haitao52198/HD-Elastos
/* Keep old drivers compatible in RT-Thread */
Int32 eth_device_init_with_flag(struct eth_device *dev, char *name, UInt8 flags)
{
    struct netif* netif;

    netif = (struct netif*) malloc (sizeof(struct netif));
    if (netif == NULL)
    {
        printf("malloc netif failed\n");
        return -RT_ERROR;
    }
    memset(netif, 0, sizeof(struct netif));

    /* set netif */
    dev->netif = netif;
    /* device flags, which will be set to netif flags when initializing */
    dev->flags = flags;
    /* link changed status of device */
    dev->link_changed = 0x00;
    dev->parent.type = RT_Device_Class_NetIf;
    /* register to RT-Thread device manager */
    rt_device_register(&(dev->parent), name, RT_DEVICE_FLAG_RDWR);
    rt_sem_init(&(dev->tx_ack), name, 0, RT_IPC_FLAG_FIFO);

    /* set name */
    netif->name[0] = name[0];
    netif->name[1] = name[1];

    /* set hw address to 6 */
    netif->hwaddr_len 	= 6;
    /* maximum transfer unit */
    netif->mtu			= ETHERNET_MTU;

    /* get hardware MAC address */
    rt_device_control(&(dev->parent), NIOCTL_GADDR, netif->hwaddr);

    /* set output */
    netif->output		= etharp_output;
    netif->linkoutput	= ethernetif_linkoutput;

    /* if tcp thread has been started up, we add this netif to the system */
    if (rt_thread_find("tcpip") != NULL)
    {
        struct ip_addr ipaddr, netmask, gw;

#if !LWIP_DHCP
        IP4_ADDR(&ipaddr, RT_LWIP_IPADDR0, RT_LWIP_IPADDR1, RT_LWIP_IPADDR2, RT_LWIP_IPADDR3);
        IP4_ADDR(&gw, RT_LWIP_GWADDR0, RT_LWIP_GWADDR1, RT_LWIP_GWADDR2, RT_LWIP_GWADDR3);
        IP4_ADDR(&netmask, RT_LWIP_MSKADDR0, RT_LWIP_MSKADDR1, RT_LWIP_MSKADDR2, RT_LWIP_MSKADDR3);
#else
        IP4_ADDR(&ipaddr, 0, 0, 0, 0);
        IP4_ADDR(&gw, 0, 0, 0, 0);
        IP4_ADDR(&netmask, 0, 0, 0, 0);
#endif

        netifapi_netif_add(netif, &ipaddr, &netmask, &gw, dev, eth_netif_device_init, tcpip_input);
    }

    return RT_EOK;
}
コード例 #25
0
ファイル: drv_at24cxx.c プロジェクト: guzhaoyuan/smartCar
rt_err_t at24cxx_init(const char * device_name, const char * i2c_bus_name)
{
    int i;
    struct rt_i2c_bus_device* i2c_bus_device;
    
    /* initialize mutex */
    if (rt_mutex_init(&at24cxx_device.lock, device_name, RT_IPC_FLAG_FIFO) != RT_EOK)
    {
        rt_kprintf("init lock mutex failed\n");
        return -RT_ENOSYS;
    }

    /* we got i2c bus */
    i2c_bus_device = rt_i2c_bus_device_find(i2c_bus_name);
    if(i2c_bus_device == RT_NULL)
    {
        AT24CXX_TRACE("i2c device %s not found!\r\n", i2c_bus_device);
        return -RT_ENOSYS;
    }
    at24cxx_device.bus = i2c_bus_device;
    
    /* find match */
    for(i=0;i<ARRAY_SIZE(at24cxx_attr_table);i++)
    {
        if(!rt_strcmp(at24cxx_attr_table[i].name, device_name))
        {
            AT24CXX_TRACE("%s supported hardware:%s\r\n", __func__, device_name);
            at24cxx_device.attr = at24cxx_attr_table[i];
            break;
        }
    }
    
    /* devices not supported */
    if( i == ARRAY_SIZE(at24cxx_attr_table))
    {
        return RT_ERROR;
    }
    
    at24cxx_device.geometry.bytes_per_sector = at24cxx_device.attr.page_size;
    at24cxx_device.geometry.block_size = at24cxx_device.attr.page_size;
    at24cxx_device.geometry.sector_count = at24cxx_device.attr.total_size/at24cxx_device.attr.page_size;
    
    /* register device */
    at24cxx_device.parent.type    = RT_Device_Class_Block;
    at24cxx_device.parent.init    = init;
    at24cxx_device.parent.open    = open;
    at24cxx_device.parent.close   = close;
    at24cxx_device.parent.read 	  = read;
    at24cxx_device.parent.write   = write_page;
    at24cxx_device.parent.control = control;
    /* no private */
    at24cxx_device.parent.user_data = RT_NULL;

    rt_device_register(&at24cxx_device.parent, device_name,
                       RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_STANDALONE);
    
    return RT_EOK;
}
コード例 #26
0
/**
 * This function will define the susb host controller device, it will be register to the device
 * system.
 * 
 * @return the error code, RT_EOK on successfully.
 */
void rt_hw_susb_init(void)
{
    susb_hcd.parent.type = RT_Device_Class_USBHost;
    susb_hcd.parent.init = susb_init;
    
    susb_hcd.ops = &susb_ops;
    
    rt_device_register(&susb_hcd.parent, "susb", 0);    
}
コード例 #27
0
/* ethernetif APIs */
Int32 eth_device_init(struct eth_device* dev, const char* name)
{
	struct netif* netif;
        uip_ipaddr_t ipaddr;
	netif = (struct netif*) malloc (sizeof(struct netif));
	if (netif == NULL)
	{
		printf("malloc netif failed\n");
		return -RT_ERROR;
	}
	memset(netif, 0, sizeof(struct netif));

	/* set netif */
	dev->netif = netif;
	/* register to rt-thread device manager */
	rt_device_register(&(dev->parent), name, RT_DEVICE_FLAG_RDWR);
	dev->parent.type = RT_Device_Class_NetIf;
	rt_sem_init(&(dev->tx_ack), name, 0, RT_IPC_FLAG_FIFO);

	/* set name */
	netif->name[0] = name[0];
	netif->name[1] = name[1];

	/* set hw address to 6 */
	netif->hwaddr_len	= 6;
	/* maximum transfer unit */
	netif->mtu			= ETHERNET_MTU;
	/* broadcast capability */
	netif->flags		= NETIF_FLAG_BROADCAST;

#if LWIP_IGMP
	/* igmp support */
	netif->flags |= NETIF_FLAG_IGMP;
#endif

	/* get hardware address */
	rt_device_control(&(dev->parent), NIOCTL_GADDR, netif->hwaddr);

	/* set output */
	netif->output		= ethernetif_output;
	netif->linkoutput	= ethernetif_linkoutput;

	/* add netif to lwip */

	if (netif_add(netif, IP_ADDR_ANY, IP_ADDR_BROADCAST, IP_ADDR_ANY, dev,
		eth_init, eth_input) == NULL)
	{
		/* failed, unregister device and free netif */
		rt_device_unregister(&(dev->parent));
		rt_free(netif);
		return -RT_ERROR;
	}

	netif_set_default(netif);
	return RT_EOK;
}
コード例 #28
0
ファイル: drv_oled.c プロジェクト: onelife/rt-thread
/***************************************************************************//**
 * @brief
 *   Initialize OLED device
 *
 * @details
 *
 * @note
 *
 ******************************************************************************/
void bsp_hw_oled_init(void)
{
    do
    {
#if OLED_DEVICE_INTERFACE == INTERFACE_4WIRE_SPI
        /* Find SPI device */
        spi_dev = rt_device_find(OLED_USING_DEVICE_NAME);
        if (spi_dev == RT_NULL)
        {
            oled_debug("OLED: Can't find device %s!\n",
                OLED_USING_DEVICE_NAME);
            break;
        }
        oled_debug("OLED: Find device %s\n", OLED_USING_DEVICE_NAME);
#endif
        /* Register OLED device */
        oled_device.type            = RT_Device_Class_Graphic;
        oled_device.rx_indicate     = RT_NULL;
        oled_device.tx_complete     = RT_NULL;
        oled_device.init            = board_oled_init;
        oled_device.open            = miniStm32_oled_open;
        oled_device.close           = miniStm32_oled_close;
        oled_device.read            = RT_NULL;
        oled_device.write           = RT_NULL;
        oled_device.control         = miniStm32_oled_control;
#if defined(RT_USING_GUIENGINE)
        oled_device.user_data       = (void *)&oled_ops;
#else
        oled_device.user_data       = RT_NULL;
#endif
        if (rt_device_register(
            &oled_device,
            OLED_DEVICE_NAME,
            RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_STANDALONE //RT_DEVICE_FLAG_DMA_TX
            ) != RT_EOK)
        {
            break;
        }
#if defined(RT_USING_GUIENGINE)
        /* Set as rtgui graphic driver */
        if (rtgui_graphic_set_device(&oled_device) != RT_EOK)
        {
            break;
        }
#endif
        oled_debug("OLED: H/W init OK!\n");
        return;
    } while(0);

    oled_debug("OLED err: H/W init failed!\n");
}
コード例 #29
0
ファイル: drv_rtc.c プロジェクト: geniusgogo/rt-thread
int rt_hw_hp_rtc_init(void)
{
    rt_err_t ret = RT_EOK;
    
    ret = rt_device_register(&device, "rtc", RT_DEVICE_FLAG_RDWR); 
    if(ret != RT_EOK)
    {
        return ret; 
    }
    
    rt_device_open(&device, RT_DEVICE_OFLAG_RDWR); 
    
    return RT_EOK; 
}
コード例 #30
0
ファイル: mma8451.c プロジェクト: nathanlnw/tw705_HB_gghypt
/***********************************************************
* Function:
* Description:
* Input:
* Input:
* Output:
* Return:
* Others:
***********************************************************/
void mma8451_driver_init( void )
{
    dev_mma8451.type		= RT_Device_Class_Char;
    dev_mma8451.init		= mma8451_init;
    dev_mma8451.open		= mma8451_open;
    dev_mma8451.close		= mma8451_close;
    dev_mma8451.read		= mma8451_read;
    dev_mma8451.write		= mma8451_write;
    dev_mma8451.control		= mma8451_control;
    dev_mma8451.user_data	= RT_NULL;

    rt_device_register( &dev_mma8451, "sensor", RT_DEVICE_FLAG_RDWR );
    rt_device_init( &dev_mma8451 );
}