📄 root.c
字号:
/*
* COPYRIGHT (c) 1995,2000 TriMedia Technologies Inc.
*
* +-----------------------------------------------------------------+
* | THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY ONLY BE USED |
* | AND COPIED IN ACCORDANCE WITH THE TERMS AND CONDITIONS OF SUCH |
* | A LICENSE AND WITH THE INCLUSION OF THE THIS COPY RIGHT NOTICE. |
* | THIS SOFTWARE OR ANY OTHER COPIES OF THIS SOFTWARE MAY NOT BE |
* | PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY OTHER PERSON. THE |
* | OWNERSHIP AND TITLE OF THIS SOFTWARE IS NOT TRANSFERRED. |
* +-----------------------------------------------------------------+
*
* Module name : root.c 1.5
*
* Module type : IMPLEMENTATION
*
* Title : Interprocessor data streaming
*
* Author : Juul van der Spek
*
* Last update : 13:45:56 - 00/06/19
*
* Description :
*
* This program demonstrates how to use pSOS+m
* and DMA to stream data from one TM-1000 processor
* to another in a multiprocessor system.
*
* Based on the TM-1000 node identifier,
* this program behaves as a producer of data buffers
* on node 0, or a consumer on all other nodes.
*
* Node 0 allocates a collection of packet buffers
* in its own SDRAM, and puts the addresses of filled
* packets into a global queue. All other nodes
* read (the address of) whichever packet they can get
* from this queue, and 'use' it in some way (just a
* data check here). Although the other nodes can
* very well directly read the contents of their received
* packets, such reading would be uncached, via the PCI bus.
*
* Therefore, the receiving nodes use DMA to copy the data
* into a local buffer before 'use'. After this, the packets
* are 'returned' to node 0 via a second global return queue.
*/
/* ------------------------------------------------------ */
#include "psos.h"
#include "sys_conf.h"
#include "stdio.h"
#include "tmlib/tmtypes.h"
#define NROF_PACKETS 100
#define PACKET_SIZE 1000
extern Int _node_number;
static ULONG full_packets;
static ULONG empty_packets;
extern void transfer( Char *local, Char *remote, Int size );
/* ------------------------------------------------------ */
static void create_empty_packets()
{
Int i;
for (i=1; i<=NROF_PACKETS; i++) {
ULONG message[4];
message[0]= (ULONG)_cache_malloc(PACKET_SIZE,-1);
q_send(empty_packets, message);
}
}
/* ------------------------------------------------------ */
static void use( Char * buffer )
{
Char c= *buffer;
Int i;
for (i=1; i<PACKET_SIZE; i++) {
if (buffer[i] != c) {
printf("NODE %d: error, mismatch at %d\n",
_node_number, i );
_psos_exit(-1);
}
}
printf("NODE %d: all `%c` received\n",
_node_number, c );
}
static void consume()
{
Char *local_buffer;
local_buffer= (Char*)_cache_malloc(PACKET_SIZE,-1);
_cache_invalidate(local_buffer,PACKET_SIZE);
while (True) {
ULONG message[4];
Char *packet_ptr;
q_receive (full_packets, Q_WAIT, 0, message);
packet_ptr= (Char*)message[0];
transfer(local_buffer, packet_ptr, PACKET_SIZE);
use (local_buffer);
q_send (empty_packets, message);
}
}
/* ------------------------------------------------------ */
static void fill( Char * buffer )
{
static Char c= '0';
Int i;
for (i=0; i<PACKET_SIZE; i++) {
buffer[i]= c;
}
c++;
}
static void produce()
{
while (True) {
ULONG message[4];
Char *packet_ptr;
q_receive (empty_packets, Q_WAIT, 0, message);
packet_ptr= (Char*)message[0];
fill ( packet_ptr );
_cache_copyback ( packet_ptr, PACKET_SIZE );
q_send (full_packets, message);
}
}
/* ------------------------------------------------------ */
void root()
{
if (_node_number == 0) {
/*
* Create queues named "EMPT" and "FULL" on node #0:
*/
q_create("EMPT", 0, Q_GLOBAL | Q_NOLIMIT | Q_FIFO, &empty_packets);
q_create("FULL", 0, Q_GLOBAL | Q_NOLIMIT | Q_FIFO, &full_packets);
create_empty_packets();
produce();
} else {
/*
* On all other nodes: wait until the send/receive
* queues have been received:
*/
while ( q_ident("EMPT", 0, &empty_packets)
|| q_ident("FULL", 0, &full_packets)
);
consume();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -