#include #include #include #include "ssam.h" ssam_cnct_t *rw; ssam_cnct_t *data; ssam_cnct_t *addr; ssam_cnct_t *ack; #define MAT_SIZE 2 enum memops { MEM_R, MEM_W }; /* MEM */ void* mem() { int tab[(MAT_SIZE*2)*3] = {0, 1, 2, 3, 4, 5, 6, 7, -1, -1, -1, -1}; unsigned int op=-1; unsigned int at; unsigned int res; for(;;ssam_wait()) { res = 0; ssam_read(rw, &op); switch( op ) { case MEM_R: /* Lire dans la mémoire */ ssam_read(addr, &at); #ifdef DEBUG printf("MEM: Read @%d (=%d)!\n", at, tab[at]); #endif ssam_write(data, &tab[at]); res = 1; break; case MEM_W: /* Ecrire dans la memoire */ ssam_read(addr, &at); ssam_read(data, &tab[at]); #ifdef DEBUG printf("MEM: Write %d@%d!\n", tab[at], at); #endif res = 1; break; default: break; } ssam_write(ack, &res); } return NULL; } /* CPU */ void* cpu() { /* Retourne la valeur à l'adresse donnée */ int get_addr(unsigned int at) { int res; unsigned int my_ack=0; unsigned int op = MEM_R; ssam_write(rw, &op); ssam_write(addr, &at); do { ssam_wait(); ssam_read(ack, &my_ack); } while ( my_ack != 1 ); ssam_read(data, &res); return res; } /* Ecrit la valeur à l'adresse donnée */ void set_addr(unsigned int at, int my_data) { unsigned int my_ack=0; unsigned int op = MEM_W; ssam_write(addr, &at); ssam_write(data, &my_data); ssam_write(rw, &op); do { ssam_wait(); ssam_read(ack, &my_ack); } while ( my_ack != 1 ); } /* Lire une ligne d'une matrice */ void read_line(int tab[MAT_SIZE], int matno, int lineno) { int i; for(i=0;i