Hi3531A添加串口uart1、uart2、uart3


海思3531A芯片有四个串口uart单元,uart0是调试串口,默认打开。现添加uart1、uart2、uart3,测试验证成功。
资源截图
代码片段和文件信息
/************************************************************************************************
*****Describe: This program is writen to operate HI35xx serial devices.
*************************************************************************************************/

#include       
#include     
#include    
#include   
#include     
#include     
#include    
#include      
#include 
#include   

#include 
#include 
#include 
#include 

//宏定义  
#define HI_FALSE  -1  
#define HI_TRUE     0   

#ifdef debugprintf
#define debugpri(mesg args...) fprintf(stderr “[HI Serial print:%s:%d:] “ mesg “
“ __FILE__ __LINE__ ##args) 
#else
#define debugpri(mesg args...)
#endif

int HiSerfd; 
void HI_Serial_Close(int fd);
  
void Hi_sigsegv(int dummy)
{
if(HiSerfd > 0)
HI_Serial_Close(HiSerfd);
fprintf(stderr “Hi Serial Caught SIGSEGV Abort!
“);
fclose(stderr);
abort();
}

void Hi_sigterm(int dummy)
{
if(HiSerfd > 0)
HI_Serial_Close(HiSerfd);
fprintf(stderr “Hi Serial Caught SIGTERM Abort!
“);
fclose(stderr);
exit(0);
}

void Hi_init_signals(void)
{
struct sigaction sa;
sa.sa_flags = 0;

sigemptyset(&sa.sa_mask);
sigaddset(&sa.sa_mask SIGSEGV);
sigaddset(&sa.sa_mask SIGTERM);
sigaddset(&sa.sa_mask SIGPIPE);

sa.sa_handler = Hi_sigsegv;
sigaction(SIGSEGV &sa NULL);

sa.sa_handler = Hi_sigterm;
sigaction(SIGTERM &sa NULL);

sa.sa_handler = SIG_IGN;
sigaction(SIGPIPE &sa NULL);
}

int HI_Serial_Usage(void)
{
    printf(“Usage:
“);
    printf(“ myhicom [-d]  [-s] get netdeviece info [-rw] read or wite select
“);
    printf(“ myhicom [-h] for more usage
“);
    printf(“ myhicom [-v] the verson of the sofware
“);
printf(“ Example:
myhicom -d /dev/ttyAMA1 -s 115200 -w HelloWorld!!!
“);
}

/*
*Function: HI_Serial_Open(int fdchar* ComDevice)  
*Param: fd:file descirbe handle  Serial Device: /dev/ttyAMA1 /dev/ttyAMA2
*Output: Ok or Fail
*/

int HI_Serial_Open(char* HiSerDevice)  
{  
    int fd;

fd = open(HiSerDevice O_RDWR|O_NOCTTY|O_NDELAY);  
if (HI_FALSE == fd)  
{  
perror(“HiSerial Can‘t Open Serial HiSerDevice“);  
return(HI_FALSE);  
}  
//恢复串口为阻塞状态                                 
if(fcntl(fd F_SETFL 0) < 0)  
{  
debugpri(“fcntl failed!
“);  
return(HI_FALSE);  
}       
else  
{  
debugpri(“fcntl=%d
“fcntl(fd F_SETFL0));  
}  
//测试是否为终端设备      
if(0 == isatty(STDIN_FILENO))  
{  
debugpri(“standard input is not a terminal device
“);  
return(HI_FALSE);  
}  
else  
{  
debugpri(“isatty success!
“);  
}                
printf(“fd->open=%d
“fd);  
return fd;  
}  

/*
*Function: HI_Serial_Close(int fd) 
*Param: fd:file descirbe handle  
*Output: Null
*/

void 

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      21185  2018-12-04 11:26  Hi3531A添加串口uart1-33.管脚复用寄存器.xlsx

     文件     515219  2018-12-04 16:52  Hi3531A添加串口uart1-33531A设备添加测试UART1-3.docx

     文件      11152  2018-12-04 16:25  Hi3531A添加串口uart1-3com_testhiserial.c

     文件        144  2018-12-04 16:14  Hi3531A添加串口uart1-3com_testMakefile

     文件     516648  2018-11-28 11:44  Hi3531A添加串口uart1-3com_testmyhicom

     文件        137  2018-12-04 16:23  Hi3531A添加串口uart1-3com_test
eadme.txt

     文件     137334  2018-12-03 16:16  Hi3531A添加串口uart1-3sp3232中文.docx

     文件     451072  2017-05-26 23:38  Hi3531A添加串口uart1-3sscom32sscom5.13.1.exe

     文件       5087  2018-12-04 14:31  Hi3531A添加串口uart1-3sscom32sscom51.ini

     文件       1028  2018-11-30 16:29  Hi3531A添加串口uart1-3uart-regconfig.sh

     目录          0  2018-12-04 16:21  Hi3531A添加串口uart1-3com_test

     目录          0  2018-12-04 16:12  Hi3531A添加串口uart1-3sscom32

     目录          0  2018-12-04 16:55  Hi3531A添加串口uart1-3

----------- ---------  ---------- -----  ----

              1659006                    13


版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

发表评论

评论列表(条)