Topic
No replies
rolandman
rolandman
5 Posts
ACCEPTED ANSWER

Pinned topic Mailbox communication

‏2010-08-11T07:57:20Z |
Hi,

I tried this code (from Scarpino's Book)

PPE code:

#include <stdio.h>

#include <stdlib.h>

#include <libspe2.h>

#include <ppu_intrinsics.h>

#include <pthread.h>
/* Program handle representing the SPU object */

extern spe_program_handle_t spu_mbox_interrupt;

/* The data sent to the pthread */

typedef struct ppu_pthread_data {

spe_context_ptr_t speid;

pthread_t pthread;

} ppu_pthread_data_t;
ppu_pthread_data_t data;

/* The function executed in the pthread */

void *ppu_pthread_function(void *arg) {

ppu_pthread_data_t *data = (ppu_pthread_data_t *)arg;
int retval;

unsigned int entry = SPE_DEFAULT_ENTRY;
if ((retval = spe_context_run(data->speid,

&entry, 0, NULL, NULL, NULL)) < 0) {

perror("spe_context_run");

exit (1);

}

pthread_exit(NULL);

}

int main() {

int retval;
spe_context_ptr_t spe;

unsigned int mbox_data[1];

/* Create the SPE Context */

spe = spe_context_create(SPE_MAP_PS, 0);

if (!spe) {

perror("spe_context_create");

exit(1);

}

/* Load the program into the context */

retval = spe_program_load(spe, &spu_mbox_interrupt);

if (retval) {

perror("spe_program_load");

exit(1);

}

/* Create thread */

data.speid = spe;

if ((retval = pthread_create(&data.pthread,

NULL, &ppu_pthread_function, &data)) != 0) {

perror("pthread_create");

exit (1);

}

/* Write a value to the SPE's Incoming Mailbox */

mbox_data[0] = 0x12345678;

if(spe_in_mbox_status(spe))

spe_in_mbox_write(spe, mbox_data, 1, SPE_MBOX_ALL_BLOCKING);

printf("Sent data = %x\n", mbox_data[0]);
/* Wait for the thread to finish */

if ((retval = pthread_join

(data.pthread, NULL)) != 0) {

perror("pthread_join");

exit (1);

}

/* Deallocate the context */

retval = spe_context_destroy(spe);

if (retval) {

perror("spe_context_destroy");

exit(1);

}

return 0;

}

SPE code:

#include <spu_mfcio.h>

void interrupt_service(void)

__attribute__ ((section (".interrupt")));

volatile unsigned int check_value = 0;

int main(unsigned long long speid,

unsigned long long argp,

unsigned long long envp) {

unsigned int mbox_content;

/* Write to the event mask */

spu_write_event_mask(MFC_IN_MBOX_AVAILABLE_EVENT);

/* Enable interrupt processing and wait for the interrupt */

spu_ienable();

while(!check_value);

/* Read mailbox and display result */

mbox_content = spu_read_in_mbox();

printf("Received data = %x\n", mbox_content);
return 0;

}

void interrupt_service(void) {

spu_write_event_ack(MFC_IN_MBOX_AVAILABLE_EVENT);

check_value++;

asm("iret");

}
The code works fine, but it only sent once and stop. I want to modify the code for my application. I only need a simple communication using mailbox.

PPE --> send a number, for example 20
SPE replies --> I got 20, sent me more...
PPE --> send 40
SPE replies --> I got 40, sent me more...
and so on.

How to do that? Is it necessary to use interrupt? Anybody can give an example?

Thank you for replying.