看门狗芯片-SP706-调试记录

看门狗芯⽚-SP706-调试记录⼀、看门狗芯⽚
1.1 看门狗芯⽚与处理器引脚连接
  本次主控单元使⽤的看门狗芯⽚为SP706芯⽚ 。
  引脚定义:
1.2 使能外部看门狗
(1) 看门狗芯⽚SP706芯⽚⼿册中的电路图:
(2) 看门狗与主控板连接原理图如下所⽰:
    当J2接上跳线帽时,开启看门狗。反之,看门狗关闭。
    独⽴的看门狗芯⽚:这种看门狗主要有⼀个⽤于喂狗的引脚(⼀般与CPU的GPIO相连)和⼀个复位引脚(与系统的RESET引脚相连),如果没有在⼀定时间内改变喂狗脚的电平,复位引脚就会改变状态复位CPU。当J2接上跳线帽时,看门狗被使能,系统⼀上电看门狗就开始⼯作,1.6秒系统便会复位⼀次,所以必须进⾏喂狗操作,在嵌⼊式系统uboot、内核、启动脚本等阶段可能都需要喂狗。
⼆、测试程序
基于Linux下GPIO的操作:
/* Copyright (c) 2011, RidgeRun
* All rights reserved.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
rgd-208* 1. Redistributions of source code must retain the above copyright
*    notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
*    notice, this list of conditions and the following disclaimer in the
*    documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
*    must display the following acknowledgement:
*    This product includes software developed by the RidgeRun.
* 4. Neither the name of the RidgeRun nor the
*    names of its contributors may be used to endorse or promote products
*    derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY RIDGERUN ''AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL RIDGERUN BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICE
S; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<errno.h>
#include<unistd.h>
#include<fcntl.h>
#include<poll.h>
/****************************************************************
* Constants
****************************************************************/
#define SYSFS_GPIO_DIR "/sys/class/gpio"
#define POLL_TIMEOUT (3 * 1000)/* 3 seconds */
#define MAX_BUF 64
#define GPIO_GROUP_NUM  (5)
#define GPIO_NUM_PER_GROUP (32)
#define GPIO_NAME_LEN  (10)
/****************************************************************
* gpio_num_to_string
磷化液配方
****************************************************************/
int gpio_num_to_string(unsigned int gpio,char* name)
{
int i =0;
if((gpio >= GPIO_GROUP_NUM * GPIO_NUM_PER_GROUP)||(!name)){
printf("[%s : %d] wrong para\n", __FUNCTION__,__LINE__);
return-1;
}
memset(name,0, GPIO_NAME_LEN);
i = gpio / GPIO_NUM_PER_GROUP;
switch(i){
case0:
sprintf(name,"pioA%d", gpio % GPIO_NUM_PER_GROUP);
break;
case1:
sprintf(name,"pioB%d", gpio % GPIO_NUM_PER_GROUP);
break;
case2:
sprintf(name,"pioC%d", gpio % GPIO_NUM_PER_GROUP);
break;
case3:
case3:
sprintf(name,"pioD%d", gpio % GPIO_NUM_PER_GROUP);
break;
case4:
sprintf(name,"pioE%d", gpio % GPIO_NUM_PER_GROUP);
break;
default:
return-1;
}
return0;
}
/****************************************************************
* gpio_export
****************************************************************/
int gpio_export(unsigned int gpio)
{
int fd, len;
char buf[MAX_BUF];
fd =open(SYSFS_GPIO_DIR "/export", O_WRONLY);
一个圆柱形玻璃容器
if(fd <0){
printf("[%s : %d] gpio/export\n", __FUNCTION__,__LINE__);
return fd;
}
len =snprintf(buf,sizeof(buf),"%d", gpio);
write(fd, buf, len);
close(fd);
return0;
}
/****************************************************************
* gpio_unexport
****************************************************************/集装箱内衬袋
int gpio_unexport(unsigned int gpio)
{
int fd, len;
char buf[MAX_BUF];
fd =open(SYSFS_GPIO_DIR "/unexport", O_WRONLY);电机支架
if(fd <0){
printf("[%s : %d] gpio/export\n", __FUNCTION__,__LINE__);
return fd;
}
len =snprintf(buf,sizeof(buf),"%d", gpio);
write(fd, buf, len);
close(fd);
return0;
}
/
****************************************************************
* gpio_set_dir
****************************************************************/
int gpio_set_dir(unsigned int gpio,unsigned int out_flag)
UCN-11{
int fd, len;
char buf[MAX_BUF], name[GPIO_NAME_LEN];
if((fd =gpio_num_to_string(gpio, name))<0){
return fd;
}
//len = snprintf(buf, sizeof(buf), SYSFS_GPIO_DIR  "/gpio%d/direction", gpio);
len =snprintf(buf,sizeof(buf), SYSFS_GPIO_DIR  "/%s/direction", name);
fd =open(buf, O_WRONLY);
if(fd <0){
printf("[%s : %d] gpio/direction\n", __FUNCTION__,__LINE__);
return fd;
}
if(out_flag)
write(fd,"out",4);
else
write(fd,"in",3);
close(fd);
return0;
}
/****************************************************************
* gpio_set_value
****************************************************************/
int gpio_set_value(unsigned int gpio,unsigned int value)
{
int fd, len;
char buf[MAX_BUF], name[GPIO_NAME_LEN];
if((fd =gpio_num_to_string(gpio, name))<0){
return fd;
}
// len = snprintf(buf, sizeof(buf), SYSFS_GPIO_DIR "/gpio%d/value", gpio); len =snprintf(buf,sizeof(buf), SYSFS_GPIO_DIR "/%s/value", name);
fd =open(buf, O_WRONLY);
if(fd <0){
printf("[%s : %d] gpio/set-value\n", __FUNCTION__,__LINE__);
return fd;
}
if(value)
write(fd,"1",2);
else
write(fd,"0",2);
close(fd);
return0;
}
/****************************************************************
* gpio_get_value
****************************************************************/
int gpio_get_value(unsigned int gpio,unsigned int*value)
{
int fd, len;
char buf[MAX_BUF];
char ch, name[GPIO_NAME_LEN];
if((fd =gpio_num_to_string(gpio, name))<0){
return fd;
}
// len = snprintf(buf, sizeof(buf), SYSFS_GPIO_DIR "/gpio%d/value", gpio);  len =snprintf(buf,sizeof(buf), SYSFS_GPIO_DIR "/%s/value", name);
fd =open(buf, O_RDONLY);
if(fd <0){
printf("[%s : %d] gpio/get-value\n", __FUNCTION__,__LINE__);

本文发布于:2024-09-21 13:17:10,感谢您对本站的认可!

本文链接:https://www.17tex.com/tex/1/126717.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:看门狗   引脚   喂狗   系统   复位   改变   连接
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议