华清远见fs4412开发板学习笔记(六)

fs4412开发板学习笔记(六)

嵌入式产品
高端嵌入式产品(运行OS)
低端嵌入式产品(不需要OS)
1.Linux 系统编程
“Everything in Unix is a file” 一切皆文件
【1】文件I/O
open
ioctl (i/o control)
close
【2】文件描述符
是一个非负的整数。用于标识一个进程打开的文件。
分配原则 : 顺序分配、最小可用

【3】open 打开文件
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

int open(const char *pathname, int flags);
函数参数:
[1] pathname : 文件路径
[2] flags : 打开方式
O_RDONLY 只读
O_WRONLY 只写
O_RDWR 读写
O_NONBLCK 非阻塞
返回值:
成败 返回文件描述符(>=0 整数)
失败 -1

【4】close 关闭文件
#include <unistd.h>

int close(int fd);
函数参数:
fd : 需要关闭的文件的文件描述符

【5】ioctl 控制文件/向驱动程序发送请求
#include <sys/ioctl.h>

int ioctl(int d, int request, …);
函数参数:
[1]d : 控制的文件的文件描述符
[2]request : 向驱动程序发送请求(却决于驱动程序)
LED_ON
LED_OFF
[3] … : 可变参数 (取决于命令)
返回值:
成功 返回 0
失败 返回 -1

【6】遇到 “No such file or directory” 问题该如何解决
分析:
缺少对应的驱动程序
安装驱动程序
1)准备工作(Ubuntu)
将 led.ko pwm.ko 驱动程序模块
拷贝到/source/rootfs

修改权限: sudo chmod 777 /source/rootfs -R

2)在开发板上操作
insmod XXXX.ko //每次启动开发板时都需要执行
开机自动加载驱动
fs@ubuntu:/source/rootfs$ vim etc/init.d/rcS
在最后两行添加
#!/bin/sh
#This is the first script called by init process
/bin/mount -a
mkdir /dev/pts
mount -t devpts devpts /dev/pts
echo /sbin/mdev>/proc/sys/kernel/hotplug
/sbin/mdev -s
insmod led.ko
insmod pwm.ko

查看Linux支持驱动
cat /proc/devices

使用交叉编译器
arm-none-linux-gnueabi-gcc hello.c -o hello

./hello

代码对齐(命令模式)
gg = G

#include <unistd.h>
unsigned int sleep(unsigned int seconds); //秒

#include <unistd.h>
int usleep(useconds_t usec); //微秒
1s = 1000 ms = 1000000 us

作业:
1)完成LED代码
2)完成音乐代码(搜乐谱 自己写歌 2-3首)

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ManGo CHEN

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值