arm-linux アプリケーション層がドライバー関数を呼び出します

ヘッダーファイルを呼び出す必要があります

#include "stdio.h"

#include "unistd.h" 

 /*

unistd.h は、POSIX オペレーティング システム API へのアクセスを提供する C および C++ プログラミング言語のヘッダー ファイルの名前です。このヘッダー ファイルは POSIX.1 標準 (単一の UNIX 仕様の基礎) によって提案されているため、この標準に従うすべてのオペレーティング システムとコンパイラは、このヘッダー ファイルを提供する必要があります (Mac OS X を含む Unix のすべての公式バージョンなど)。 Linux など) .

Unix ライクなシステムの場合、unistd.h で定義されているインターフェイスは通常、フォーク、パイプ、さまざまな I/O プリミティブ (読み取り、書き込み、閉じるなど) などの多数のシステム コール (英語: ラッパー関数) のラッパーです。 .) .
*/

#include "sys/types.h" //データ型

#include "sys/stat.h"

/*

#include <sys/stat.h> ファイル ステータスは、UNIX/Linux システムがファイル ステータスを定義する疑似標準ヘッダー ファイルです。

*/

#include "fcntl.h"

// Linux C ヘッダー ファイルの引用#include<sys/types.h>および #include<fcntl.h>ヘッダー ファイルの概要

#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;
}

開発ボードで /ledApp /dev/gpioled を実行します。 1 gpioled は filename = argv[1]; によって取得されるドライバー名です。

                                databuf[0] 経由の 1 ビット値 = atoi(argv[2]); /* 実行するアクション: on または off */ Get

おすすめ

転載: blog.csdn.net/L1153413073/article/details/125500727