number007cool 发表于 2010-7-16 10:52:58

请教avic一个问题!

这是我建的sopc.h文件
#ifndef SOPC_H_
#define SOPC_H_
#include "system.h"
#define _LED
typedef struct
{
    unsigned long int DATA;
    unsigned long int DIRECTION;
    unsigned long int INTERRUPT_MASK;
    unsigned long int EDGE_CAPTURE;
} PIO_STR;

#ifdef _LED
#define LED ((PIO_STR *)LED_GREEN_BASE)
#endif

#endif /*SOPC_H_*/

这是我建的main.c文件
#include "unistd.h"
#include "stdio.h"
#include "../inc/sopc.h"
int main()
{
    while(1)
    {
      LED->DATA=0xf0;
    }
}
程序编译没任何问题,下载到目标板灯始终不亮!请问是什么原因?
(注:如果直接使用系统API的话可以正常点亮,即ptf文件的配置没任何问题;另外我的是8个灯,不是四个)

number007cool 发表于 2010-7-16 10:58:03

这完全是按照NIOS II的那些事上面写的!

rayz82 发表于 2010-7-16 11:28:44

你去他博客看看 有篇文章解释过了

tear086 发表于 2010-7-16 11:37:59

回复【楼主位】number007cool
-----------------------------------------------------------------------

看这里。
[笔记].浅析在Nios II中的两种寄存器映射方法的异同.
http://www.cnblogs.com/yuphone/archive/2010/04/22/1717779.html

281229961 发表于 2010-7-16 13:36:10

http://cache.amobbs.com/bbs_upload782111/files_30/ourdev_568176ESBBDF.jpg
(原文件名:122.jpg)

你IO口基地址是这样定义的吗?

wcabcd 发表于 2010-7-16 14:00:48

楼主看看avic的这篇博客就明白了!我也遇到过同样的问题!
http://www.cnblogs.com/kingst/archive/2010/05/15/1735886.html

number007cool 发表于 2010-7-16 14:36:02

回复 【4楼】 281229961 小朱
你IO口基地址是这样定义的吗?
---------------------------------------------------------
我是这样定义的!

number007cool 发表于 2010-7-16 15:25:18

回复 【5楼】 wcabcd
楼主看看avic的这篇博客就明白了!我也遇到过同样的问题!
http://www.cnblogs.com/kingst/archive/2010/05/15/1735886.html
-----------------------------------------------------------------------------------

我把高速缓存改成none以后,重新generate.
然后在NIOS II 上跑那个程序,依然不亮

tear086 发表于 2010-7-16 15:41:34

回复【7楼】number007cool
-----------------------------------------------------------------------

按照我的方法做就行了。详情见我引用的手册内容。

number007cool 发表于 2010-7-16 16:24:47

#include "system.h"
#define _LED
typedef struct
{
    unsigned long int DATA;
    unsigned long int DIRECTION;
    unsigned long int INTERRUPT_MASK;
    unsigned long int EDGE_CAPTURE;
} PIO_STR;
回复【8楼】 tear086 .COM 缺氧
按照我的方法做就行了。详情见我引用的手册内容。
------------------------------------------------------------------------
我的程序是这样写的:
#ifdef _LED
#define LED ((PIO_STR *)LED_GREEN_BASE|(1<<31))
#endif

#include "unistd.h"
#include "stdio.h"
//#include "../inc/sopc.h"
int main()
{
    while(1)
    {
      LED->DATA=1<<3;
    }
}
编译时提示出错信息如下:
**** Build of configuration Debug for project abc ****

make -s all includes
Compiling hello_world.c...
../hello_world.c: In function `main':
../hello_world.c:22: error: invalid operands to binary |
../hello_world.c:24:2: warning: no newline at end of file
make: *** Error 1
Build completed in 1.687 seconds
不知问题在哪,请指教!
谢谢!

tear086 发表于 2010-7-16 16:36:51

回复【9楼】number007cool
-----------------------------------------------------------------------

//#include "../inc/sopc.h" ?????????????????

为什么把结构体的定义丢下呢?

number007cool 发表于 2010-7-16 17:05:25

回复【10楼】 tear086 .COM 缺氧
----------------------------------------------------------
我没有丢下结构体的定义啊,请仔细看:
----------------------------------------------------------
#include "system.h"
#define _LED
typedef struct
{
    unsigned long int DATA;
    unsigned long int DIRECTION;
    unsigned long int INTERRUPT_MASK;
    unsigned long int EDGE_CAPTURE;
} PIO_STR;
#ifdef _LED
#define LED ((PIO_STR *)LED_GREEN_BASE|(1<<31))
#endif

#include "unistd.h"
#include "stdio.h"
//#include "../inc/sopc.h"
int main()
{
    while(1)
    {
      LED->DATA=1<<3;
    }
}

avic 发表于 2010-7-16 21:08:11

还没研究明白呢啊

number007cool 发表于 2010-7-16 21:46:55

恩,行不通!
./emotion/em004.gif

wcabcd 发表于 2010-7-17 13:43:23

#define LED          ((PIO_STR *) (PIO_LED_BASE| 1 <<31))这样定义看看!
高速缓存部分不改

number007cool 发表于 2010-7-17 14:42:02

回复【5楼】 wcabcd
------------------------------------------------------------
已经成功了!!!!!!!!!!!!!!

多谢大家的发言,非常感谢!终于搞哪个不用API的程序了!
./emotion/em012.gif

number007cool 发表于 2010-7-17 15:54:55

新问题出现了:
这是我的按键的程序,也是没有使用API,按照”那些事“的套路写的:
#include "system.h"
#include <unistd.h>
#include <stdio.h>
#include "sys/alt_irq.h"
#include "altera_avalon_pio_regs.h"
#define uintunsigned int
#define uchar unsigned char
/*结构体的定义*/
typedef struct
{
    unsigned long int DATA;
    unsigned long int DIRECTION;
    unsigned long int INTERRUPT_MASK;
    unsigned long int EDGE_CAPTURE;
} PIO_STR;
/*绿灯的定义*/
#define LED_GREEN ((PIO_STR *)LED_GREEN_BASE)
/*红灯的定义*/
#define LED_RED   ((PIO_STR *)LED_RED_BASE)
/*按键的定义*/
#define KEY       ((PIO_STR *)BUTTON_PIO_BASE)

int key_flag=0;
void isr_key(void *context,unsigned long int id)
{
    key_flag=~key_flag;
   
}
int init_interrupt()
{
    KEY->INTERRUPT_MASK=1;
    //EDGE_CAPTUREKEY->EDGE_CAPTURE=FALLING;
    return alt_irq_register(BUTTON_PIO_IRQ,NULL,isr_key);
   
}
int main()
{
    if(!init_interrupt())
    {
      printf("successful!");
    }
    else
    {
      printf("error!");
    }
    while(1)
    {
       if(key_flag)
       {
      LED_GREEN->DATA=1<<0;
       }
       else
       {
         LED_GREEN->DATA=1<<7;
       }
    }
}
中断注册成功了,但是不管按不按键都是执行LED_GREEN->DATA=1<<7,即最高位的那个灯亮。
需要说明的是,我配置的按键管脚的时候用的是下降沿中断,在这里是不是要多加几句话?
页: [1]
查看完整版本: 请教avic一个问题!