Chinaunix首页 | 论坛 | 博客
  • 博客访问: 962052
  • 博文数量: 145
  • 博客积分: 1302
  • 博客等级: 中尉
  • 技术积分: 1778
  • 用 户 组: 普通用户
  • 注册时间: 2006-03-07 16:00
文章分类

全部博文(145)

文章存档

2018年(1)

2016年(1)

2015年(6)

2014年(4)

2013年(59)

2012年(32)

2011年(36)

2009年(1)

2007年(2)

2006年(3)

分类: LINUX

2011-05-26 09:23:50


AT91SAM9261和ATMEL其它型号的ARM处理器使用高度相似的USART外设,因而驱动程序也具有高度的相似性,而且USART硬件支持485模式,用RTS信号作为485的收发控制。在使用中,只要将其置为485模式,其余的操作和普通的232操作一模一样,RTS的翻转是自动的。
我的板子上使用USART0扩展了一个485接口,而Linux原有串口驱动只支持普通的232模式,为了在Linux下方便地使用485接口,需要对原来的驱动程序稍加改动。
有关的文件
arch/arm/mach-at91/目录下:
at91sam9261_devices.c中的相关函数(不用改):
at91_add_device_serial()
并在此文件中确认相关的引脚已被正确配置,在这里关心的是USART0的TXD,RXD和RTS引脚
static inline void configure_usart0_pins(void)
{
 at91_set_A_periph(AT91_PIN_PC8, 1);  /* TXD0 */
 at91_set_A_periph(AT91_PIN_PC9, 0);  /* RXD0 */
 at91_set_A_periph(AT91_PIN_PC10, 0);  /* RTS0 */
 at91_set_A_periph(AT91_PIN_PC11, 0);  /* CTS0 */
}
这是另一个相关的文件,也不用改
board-sam9261ek.c
include/asm-arm/arch-at91/目录下
gpio.h中有相关引脚和at91_set_A_periph的原形声明
extern int __init_or_module at91_set_GPIO_periph(unsigned pin, int use_pullup);
extern int __init_or_module at91_set_A_periph(unsigned pin, int use_pullup);
extern int __init_or_module at91_set_B_periph(unsigned pin, int use_pullup);
extern int __init_or_module at91_set_gpio_input(unsigned pin, int use_pullup);
extern int __init_or_module at91_set_gpio_output(unsigned pin, int value);
extern int __init_or_module at91_set_deglitch(unsigned pin, int is_on);
extern int __init_or_module at91_set_multi_drive(unsigned pin, int is_on);
接下来需要确定在哪里修改USART0的配置。在芯片手册中,可以找到相关的寄存器名,以此为关键字搜索源码树。
在Linux源码树下搜索:
grep -r US_MR ./
找到:drivers/serial/atmel_serial.c
其中有对串口的初始化代码,在文件中查找UART_PUT_MR,找到atmel_set_termios()函数
该函数是用户程序设置串口参数时必须调用的
在其中判断;当操作USART0时,设置为485模式:
if(AT91SAM9261_BASE_US0 == (port)->membase){  // in include/asm-arm/arch-at91/at91sam9261.h
  mode &= 0xfffffff0;
  mode |= ATMEL_US_USMODE_RS485;  // in drivers/serial/atmel_serial.h
}
将上面的代码插在UART_PUT_MR(port, mode)之前即可
下面是从外国的一个论坛上找到的:关于uart配置成rs485模式的
to change each USART in RS-485 mode, add this line in linux/drivers/serial/atmel_serial.c , in function atmel_set_termios ,
just before the instruction "UART_PUT_MR(port, mode) ;" that configures the USART mode.
mode |= ATMEL_US_USMODE_RS485; //Take effect for all USART that you configure
or if you want filter for a specific USART, i used the dedicated IRQ number :
if (port->irq == AT91SAM9260_ID_US2) // USART2 is a rs485
{
mode |= ATMEL_US_USMODE_RS485;
}
I don't know if it's the best solution but it works very well.
 
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/yangjun_0621/archive/2011/03/13/6246200.aspx
阅读(4317) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~