setuart.c

来自「The source code example of ARM9 developm」· C语言 代码 · 共 46 行

C
46
字号
#include <stdio.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <stdlib.h>int main(int argc, char** argv){	int type, dip_sw, i;	int fd = open("/dev/ttyS1",O_RDWR);		if(argc < 2){ /* display current UART type */		if(ioctl(fd, 0xe001, &type) == 0){			printf("Port1 Type:%d\n",type);			ioctl(fd, 0xe003, &type);			printf("Port1 Mode9:%d\n", type);		}			else	printf("Port1 Type:Unknown!\n");		close(fd);		return 0;			}	else if(argc >= 2){			type = atoi(argv[1]);			if(ioctl(fd, 0xe002, &type) == 0)				printf("Set UART Type to %d.\n", type);			if(argc > 2){				type = atoi(argv[2]);				if(type == 1)					ioctl(fd, 0xe004, &type);				else	{					type = 0;					ioctl(fd, 0xe004, &type);  				}				printf("Set UART MODE9 to %d.\n", type);			}						close(fd);			return 1;		}	printf("Usage: setuart type mode9, type:232,422 or 485 mode9:1 or 0\n");	close(fd);	return 0;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?