小弟最近想做个多核系统(3cpu),只是在sopc builder中用mutex方式搭好了系统,但是
不知该如何在ide中配置和编写代码,应该和单核的有区别吧?
哪位达人有多核下写的代码的例子啊?
能不能给我学习一下?
谢谢了!
单核的操作你应该是知道的,多核就是在配置的时候选择不同的cpu就可以了,相当于两个nios的操作,你要注意不要冲突资源就可以了。
可以参考:creating multiprocessor niosII system tutorial.pdf
恩,各自编写自己的代码就好了,选择cpu不同。
原来的用户名一直登陆不了,无奈注册了一个新名。。。
我按照creating multiprocessor niosII system tutorial.pdf文档中的指导建立了一个多核系统
运行文档中提供的代码时出现下面的提示:
nios2-terminal: connected to hardware target using JTAG UART on cable
nios2-terminal: "Nios II Evaluation Board [USB-0]", device 1, instance 0
nios2-terminal: (Use the IDE stop button or Ctrl-C to terminate)
一般出现这样的提示后应该出结果了才对啊!?
可是我运行时出现这段提示后没有任何反映了,本应该在console栏中打印出一些信息的啊?
请问这是怎么回事啊?
谢谢了!
是很为难啊,呵呵..
可是我只是奇怪:既然编译是没有错误,程序又是肯定能跑通的,运行后应该有点反映啊?
象这样既无错误提示,又不出结果,一般大概是哪一部分的问题呢?帮忙给各大概的范围就行,呵呵..
谢谢啊!
你的应用程序有没有打印提示输出的内容呢,如果有的话,是不是两个核的打印输出都有问题吗?你查一下。
我的程序中有打印提示输出的内容啊
就是下面这个程序...
#include <stdio.h>
#include <string.h>
#include "sys/alt_alarm.h"
#include "system.h"
#include "nios2.h"
#include "altera_avalon_mutex.h"
#define MESSAGE_WAITING 1
#define NO_MESSAGE 0
#define LOCK_SUCCESS 0
#define LOCK_FAIL 1
#define MESSAGE_BUFFER_BASE MESSAGE_BUFFER_RAM_BASE
#define FIRST_LOCK 1 /* for testing only */
#define ERROR_OPENED_INVALID_MUTEX 1 /* for testing only */
#define ERROR_ALLOWED_ACCESS_WITHOUT_OWNING_MUTEX 2 /* for testing only */
#define ERROR_COULDNT_OPEN_MUTEX 3 /* for testing only */
#define MS_DELAY 1000
// Message buffer structure
typedef struct {
char flag;
char buf[100];
} message_buffer_struct;
int main()
{
// Pointer to our mutex device
alt_mutex_dev* mutex = NULL;
// Local variables
unsigned int id;
unsigned int value;
unsigned int count = 0;
unsigned int ticks_at_last_message;
char got_first_lock = 0; /* for testing only */
unsigned int error_code = 0; /* for testing only */
message_buffer_struct *message;
// Get our processor ID (add 1 so it matches the cpu name in SOPC Builder)
NIOS2_READ_CPUID(id);
id += 1;
// Value can be any non-zero value
value = 1;
// Initialize the message buffer location
message = (message_buffer_struct*)MESSAGE_BUFFER_BASE;
// We'll try to open the wrong mutex here and hope it's not successful.
mutex = altera_avalon_mutex_open("/dev/wrong_device_name"); /* for testing only */
if (mutex != NULL) /* for testing only */
{
// Whoops, opening the invalid mutex was successful.
error_code = ERROR_OPENED_INVALID_MUTEX; /* for testing only */
goto error; /* for testing only */
}
// Okay, now we'll open the real mutex
// It's not actually a mutex to share the jtag_uart, but to share a message
// buffer which CPU1 is responsible for reading and printing to the jtag_uart.
mutex = altera_avalon_mutex_open(MESSAGE_BUFFER_MUTEX_NAME);
// We'll use the system clock to keep track of our delay time.
// Here we initialize delay tracking variable.
ticks_at_last_message = alt_nticks();
if (mutex)
{
// If the mutex has never been locked, clear the message flag.
// We are safe to use the non-blocking "trylock" function here
// because if we dont get the mutex on the first shot, it means
// someone else already has it and we clearly arent going to be
// the first to release it anyway.
if(altera_avalon_mutex_trylock(mutex, value) == LOCK_SUCCESS) /* for testing only */
{
if (altera_avalon_mutex_first_lock(mutex) == FIRST_LOCK) /* for testing only */
{
message->flag = NO_MESSAGE; /* for testing only */
got_first_lock = 1; /* for testing only */
}
altera_avalon_mutex_unlock(mutex); /* for testing only */
}
while(1)
{
// See if it's time to send a message yet
if (alt_nticks() >= (ticks_at_last_message + ((alt_ticks_per_second() * (MS_DELAY)) / 1000)))
{
ticks_at_last_message = alt_nticks();
// Try and aquire the mutex (non-blocking).
if(altera_avalon_mutex_trylock(mutex, value) == LOCK_SUCCESS)
{
// Just make sure we own the mutex
if(altera_avalon_mutex_is_mine(mutex)) /* for testing only */
{
// Check if the message buffer is empty
if(message->flag == NO_MESSAGE)
{
count++;
// If we were the first to lock the mutex, say so in our first message.
if (got_first_lock) /* for testing only */
{
sprintf(message->buf, "FIRST LOCK - Message from CPU %d. Number sent: %d\n", id, count); /* for testing only */
got_first_lock = 0; /* for testing only */
}
else
{
sprintf(message->buf, "Message from CPU %d. Number sent: %d\n", id, count);
}
// Set the flag that a message has been put in the buffer.
message->flag = MESSAGE_WAITING;
}
}
else /* for testing only */
{
error_code = ERROR_ALLOWED_ACCESS_WITHOUT_OWNING_MUTEX; /* for testing only */
goto error; /* for testing only */
}
// Release the mutex
altera_avalon_mutex_unlock(mutex);
}
}
// If we are CPU1, check the message buffer
// and if there's a message, print it to stdout.
if(id == 1)
{
if(message->flag == MESSAGE_WAITING)
{
// We dont really need to lock the mutex here since the if(id == 1) statement
// assures we are the only CPU grabbing messages out of the buffer, but
// we'll do it anyway to test the blocking lock routine.
altera_avalon_mutex_lock(mutex, value); /* for testing only */
// Just make sure we own the mutex
if(altera_avalon_mutex_is_mine(mutex)) /* for testing only */
{
printf("%s", message->buf);
message->flag = NO_MESSAGE;
}
else /* for testing only */
{
error_code = ERROR_ALLOWED_ACCESS_WITHOUT_OWNING_MUTEX; /* for testing only */
goto error; /* for testing only */
}
// Release the Mutex
altera_avalon_mutex_unlock(mutex); /* for testing only */
}
}
}
}
else /* for testing only */
{
error_code = ERROR_COULDNT_OPEN_MUTEX; /* for testing only */
goto error; /* for testing only */
}
error: /* for testing only */
return(error_code); /* for testing only */
// return(0);
run之后应该有信息printf出来,可是console栏里出现下列提示后就没有反映了,
nios2-terminal: connected to hardware target using JTAG UART on cable
nios2-terminal: "Nios II Evaluation Board [USB-0]", device 1, instance 0
nios2-terminal: (Use the IDE stop button or Ctrl-C to terminate)
我感到很奇怪啊
建议lz写一个稍微简单的代码,就是进行双核的数据通信,并且答应数据,这个看起来代码有点长。
这个是altera网站上提供的一个程序...
我本来想的是这样:
这个程序应该是没问题的,可以运行出结果的,结果应该是在console栏中输出一些信息.
这样如果run出现问题我就能认为是我的硬件系统有错误...
可是我对照例程看了许多遍都感觉我的硬件系统应该没问题啊..是按照creating multiprocessor niosII system tutorial.pdf中一步一步做的...而且run后的提示:
nios2-terminal: connected to hardware target using JTAG UART on cable
nios2-terminal: "Nios II Evaluation Board [USB-0]", device 1, instance 0
nios2-terminal: (Use the IDE stop button or Ctrl-C to terminate)
也应该是证明硬件没有问题,程序开始运行了..
我用的是nios6.0
真是感到很费解啊
[em06][em06]欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |