4.openwrt helloworld 应用程序,ipk,gpio驱动ipk,gpio应用ipk

1.mips编译hellowold到开发板中运行

1.1 vi hello_world.c 输入如下:

#include <stdio.h>
int main(char argc, char *argv[])
{
int i = 1;
while(1){
//1~10 循环
printf("Hello world!!!%d\n",i); //打印内容
if (i < 10){
i++;
}else{
i = 1;
}
sleep(1);// 一秒钟打印一次
}
return 0;

1.2mips编译(在第三节有介绍mips编译器的安装方法):

mipsel-openwrt-linux-gcc hello_world.c -o hello_world

1.3运行:

将文件传输到开发板的“/tmp”目录下,在开发板的串口终端下,执行如下命令。
/tmp/hello_world

2.0编译helloworld ipk

切换到 openwrt 源码根目录,然后执行下列命令,在utile中建立文件夹 helloworld,helloworld.c makefile放到下层目录src中

cd ./package/utils //进入 package/utils 目录
mkdir hello_world //创建一个名为“hello_world”的文件夹,用于放置安装包源码。
cd hello_world  //进入“hello_world”目录
mkdir src //新建一个名为“src”的目录用于放置源码
vi src/hello_world.c //在 src 目录下新建一个名为 hello_world.c 文件

vi src/Makefile //在 src 目录下新建一个Makefile

all: hello_world
hello_world: hello_world.o
	$(CC) $(LDFLAGS) hello_world.o -o hello_world
helloworld.o: hello_world.c
	$(CC) $(CFLAGS) -c hello_world.c
clean:
	rm *.o hello_world

helloworld中也建立Makefie

include $(TOPDIR)/rules.mk

PKG_NAME:=hello_world
PKG_VERSION:=1.0
PKG_BUILD_DIR:= $(BUILD_DIR)/$(PKG_NAME)


include $(INCLUDE_DIR)/package.mk

define Package/hello_world
	SECTION:=base
	CATEGORY:=Utilities
	TITLE:=Hello world -prints a hello world message
endef

define Package/hello_world/description
	If you can't figure out what this program does, you're probably  
	brain-dead and need immediate medical attention.
endef

define Build/Prepare
	mkdir -p $(PKG_BUILD_DIR)
	$(CP) ./src/* $(PKG_BUILD_DIR)/
endef

define Package/hello_world/install
	$(INSTALL_DIR) $(1)/bin
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/hello_world $(1)/bin/
endef

$(eval $(call BuildPackage,hello_world))

编译:
保存退出,接下来回到openwrt 根目录,执行命令
make menuconfig
并选择我们已经加进去的安装包。
Utilities —>
hello_world… Hello world -prints a hello world message
保存退出。
make V=s
等待编译完成后,我们就可以在以下路径找到生成的安装包
“openwrt/ bin/ramips/packages/base/hello_world_1.0_ramips_24kec.ipk”
安装此安装包后,直接在串口终端输入:
hello_world
结果和之前一样

gpio驱动:
复制“JS7628 开发板配套资料\开发板源码\gpio_control_driver”文件夹到“openwrt 源
码根目录/package/kernel/”目录下,然后执行
make menuconfig
进入配置页面,选上如下配置
Kernel modules —>
Other modules —>
kmod-gpio_control_driver… Driver for JS9331/JS7628 gpios control
保存退出,执行
make V=s
重新编译源码,如果编译没有问题的话, 找到编译生成的IPK
“kmod-gpio_control_driver_3.18.29-1_ramips_24kec.ipk”,将此 IPK 传输到开发板并安装。安
装完成后,执行 lsmod,如下图所示
可以看到“gpio_control_driver”内核模块已经正确的插入内核中运行,并且出现了
“/dev/gpio_control”这个设备

gpio应用:
复制“JS7628 开发板配套资料\开发板源码\gpio_control_app”到“openwrt 源码根目录
/package/utils/”目录下,并执行
make menuconfig
进入配置页面,选上如下配置
Utilities —>
gpio_control_app… Control gpios
保存退出,执行
make V=s
重新编译源码,如果编译没有问题的话,找到编译生成的IPK
“gpio_control_app_1.0_ramips_24kec.ipk”,将此IPK 传输到开发板并安装。安装完成后,执

gpio_control_app -h
结果如下图所示
JS7628 开发板 openwrt 入门教程 杭州卓钛科技有限公司 www.zhuotk.com
出现上图,说明已经正常安装。这里我们还是采用之前“GPIO 简单控制”一节中用到的GPIO18、
GPIO19 这两个 GPIO 进行测试,并且也需要烧录IOT device 固件。测试GPIO18命令如下
gpio_control_app demo1 18

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值