The arm-linux application layer calls the driver function

Need to call the header file

#include "stdio.h"

#include "unistd.h" 

 /*

unistd.h is the name of the header file in the C and C++ programming languages ​​that provides access to the POSIX operating system API. This header file is proposed by the POSIX.1 standard (the basis of a single UNIX specification), so all operating systems and compilers that follow this standard should provide this header file (such as all official versions of Unix, including Mac OS X, Linux, etc.) .

For Unix-like systems, the interfaces defined in unistd.h are usually wrappers for a large number of system calls (English: wrapper functions), such as fork, pipe, and various I/O primitives (read, write, close, etc.) .
*/

#include "sys/types.h" //data type

#include "sys/stat.h"

/*

#include <sys/stat.h> The file status is a pseudo-standard header file where the unix/linux system defines the file status.

*/

#include "fcntl.h"

//Quoting the linux c header file#include<sys/types.h>and #include<fcntl.h>Header file summary

#include "stdlib.h"

#include "string.h"

#include "stdio.h"
#include "unistd.h"
#include "sys/types.h"
#include "sys/stat.h"
#include "fcntl.h"
#include "stdlib.h"
#include "string.h"


#define LEDOFF 	0
#define LEDON 	1

/*
 * @description		: main主程序
 * @param - argc 	: argv数组元素个数
 * @param - argv 	: 具体参数
 * @return 			: 0 成功;其他 失败
 */
int main(int argc, char *argv[])
{
	int fd, retvalue;
	char *filename;
	unsigned char databuf[1];
	
	if(argc != 3){
		printf("Error Usage!\r\n");
		return -1;
	}

	filename = argv[1];

	/* 打开led驱动 */
	fd = open(filename, O_RDWR);
	if(fd < 0){
		printf("file %s open failed!\r\n", argv[1]);
		return -1;
	}

	databuf[0] = atoi(argv[2]);	/* 要执行的操作:打开或关闭 */

	/* 向/dev/led文件写入数据 */
	retvalue = write(fd, databuf, sizeof(databuf));
	if(retvalue < 0){
		printf("LED Control Failed!\r\n");
		close(fd);
		return -1;
	}

	retvalue = close(fd); /* 关闭文件 */
	if(retvalue < 0){
		printf("file %s close failed!\r\n", argv[1]);
		return -1;
	}
	return 0;
}

Run /ledApp /dev/gpioled on the development board 1 gpioled is the driver name obtained by filename = argv[1];

                                1-bit value via databuf[0] = atoi(argv[2]); /* action to perform: on or off */ Get

Guess you like

Origin blog.csdn.net/L1153413073/article/details/125500727