am335x 配置pps,异步通知fasync
linux pps驱动实现gps授时_gps授时pps怎么用-CSDN博客
1.gps数据-NEMA协议
RMC: $GPRMC,083559.00,A,3723.2475,N,12158.3416,W,000.0,360.0,191204,,,A*43
RMC (Recommended Minimum Navigation Information)提供了有关位置、速度和时间的信息,是最常用的NMEA协议之一。以下是该数据的解析:
Sentence Identifier (语句标识符):$GPRMC
UTC时间:083559.00
定位状态:A(有效定位)/V(无效定位)
纬度:3723.2475
纬度方向:N(北)/S(南)
经度:12158.3416
经度方向:W(西)/E(东)
地面速率(单位:节):000.0
地面航向:360.0
日期:191204
磁偏角:空白(该字段已被弃用)
磁偏角方向:空白(该字段已被弃用)
模式指示:A(自主定位)/D(差分定位)/E(估算定位)/N(数据无效)
2.pps内核配置 (make menuconfig)

3.配置设备树:
pps {
compatible = "pps-gpio";
pinctrl-names = "default";
pinctrl-0 = <&pps_pins_default>;
gpios = <&gpio3 21 GPIO_ACTIVE_HIGH>;
status = "okay";
};
pps_pins_default: pps_pins_default {
pinctrl-single,pins = <
0x1ac ( PIN_INPUT | MUX_MODE7 ) /* (A14) mcasp0_ahclkx.gpio3[21] */
>;
};

应用|:
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/select.h>
#include <unistd.h>
#include <signal.h>
#include <app_test.h>
#define BUFFER_SIZE 1024
#define GPS_DEV "/dev/COM5"
int fd;
void sign_handler(int sig)
{
printf("<app> %s\n", __FUNCTION__);
}
int main(void)
{
char buf[20];
int f_flags;
fd = open("/dev/pps0", O_RDWR);
if(fd < 0)
{
perror("open");
return -1;
}
signal(SIGIO, sign_handler);
fcntl(fd, F_SETOWN, getpid());
f_flags = fcntl(fd, F_GETFL);
fcntl(fd, F_SETFL, FASYNC | f_flags);
while(1)
{
printf("waiting\n"); //在还没收到信号前,程序还在不停的打印
sleep(4);
}
read(fd, buf, f, 10);
printf("finish: read[%s]\n", buf);
close(fd);
return 0;
}
浙公网安备 33010602011771号