#ifndef RBM_FUNCTIONS_H #define RBM_FUNCTIONS_H #include "rcu2_addr_map.h" //======================================================================== int rbm_direct(int verbose) { // // Initialize the bus (DIRECT MODE) // if ( verbose>5 ) printf(" RBM INIT (DIRECT MODE)\n"); if ( verbose>5 ) printf(" Writing RBM_MOD_REG: 0x%X\n", 0x0); *RBM_MOD_REG = (unsigned int) 0x0; if ( verbose>5 ) printf(" Writing RBM_CSR_REG: 0x%X\n", 0x0); *RBM_CSR_REG = (unsigned int) 0x0; return 0; } //======================================================================== int rbm_command(int verbose) { // // Initialize the bus (COMMAND MODE) // if ( verbose>5 ) printf(" RBM INIT (COMMAND MODE)\n"); if ( verbose>5 ) printf(" Writing RBM_MOD_REG: 0x%X\n", 0x1); *RBM_MOD_REG = (unsigned int) 0x1; if ( verbose>5 ) printf(" Writing RBM_CSR_REG: 0x%X\n", 0x0); *RBM_CSR_REG = (unsigned int) 0x0; return 0; } //======================================================================== int rbm_init(int verbose) { // // Initialize the bus (we use COMMAND MODE) // int retval = rbm_command(verbose); return retval; } //======================================================================== int rbm_status(int verbose) { // // Dump RCU bus status // unsigned int result = 0; result = *RBM_ADD_REG; printf(" RBM_ADD_REG: 0x%X\n", result); result = *RBM_DTX_REG; printf(" RBM_DTX_REG: 0x%X\n", result); result = *RBM_DRX_REG; printf(" RBM_DRX_REG: 0x%X\n", result); result = *RBM_CSR_REG; printf(" RBM_CSR_REG: 0x%X\n", result); result = *RBM_MOD_REG; printf(" RBM_MOD_REG: 0x%X\n", result); return 0; } //======================================================================== int rbm_write_direct(unsigned int address, unsigned int data, int verbose) { // // Write function. Return transaction status. DIRECT MODE // if ( verbose>5 ) printf(" RBM WRITE (DIRECT MODE)\n"); if ( verbose>5 ) printf(" Writing RBM_ADD_REG: 0x%X\n", address); *RBM_ADD_REG = address; delay(1000); if ( verbose>5 ) printf(" Writing RBM_DTX_REG: 0x%X\n", data); *RBM_DTX_REG = data; delay(1000); // Check transaction status refister return (*((unsigned int*)(RBM_CSR_REG)) & 0xC) >> 2; } //======================================================================== int rbm_read_direct(unsigned int address, unsigned int *data, int verbose) { // // Read function. DIRECT MODE // if ( verbose>5 ) printf(" RBM READ (DIRECT MODE)\n"); if ( verbose>5 ) printf(" Writing RBM_ADD_REG: 0x%X\n", address); *RBM_ADD_REG = address; delay(1000); unsigned int result = *RBM_DRX_REG; *data = result; if ( verbose>5 ) printf(" Result from RBM_DRX_REG: 0x%X\n", result); return 0; } //======================================================================== int rbm_write_command(unsigned int address, unsigned int data, int verbose) { // // Write function. Return transaction status. COMMAND MODE // unsigned int status = 0; unsigned int success = 0; unsigned int timeout = 0; unsigned int timer = 0; if ( verbose>5 ) printf(" RBM WRITE (COMMAND MODE)\n"); // write to the adress register if ( verbose>5 ) printf(" Writing RBM_ADD_REG: 0x%X\n", address); *RBM_ADD_REG = address; // write to the data register if ( verbose>5 ) printf(" Writing RBM_DTX_REG: 0x%X\n", data); *RBM_DTX_REG = data; // write to the command register if ( verbose>5 ) printf(" Writing write command to RBM_CSR_REG: 0x%X\n", 0x3); *RBM_CSR_REG = (unsigned int) 0x3; // write command // Poll for the transaction to be completed do { status = *RBM_CSR_REG; // printf(" CSR : 0x%X\n",status); success = status & 0x4; timeout = status & 0x8; timer++; if (timer>1000) { printf("ERROR in RBM_WRITE: TIMEOUT!\n"); return 1; } } while ( (success == 0) && (timeout == 0) ); if (verbose>5) printf(" RBM_WRITE Timer : %d\n",timer); return 0; } //======================================================================== int rbm_read_command(unsigned int address, unsigned int *data, int verbose) { // // Read function. COMMAND MODE // unsigned int status = 0; unsigned int success = 0; unsigned int timeout = 0; unsigned int timer = 0; if ( verbose>5 ) printf(" RBM READ (COMMAND MODE)\n"); // write to the adress register if ( verbose>5 ) printf(" Writing RBM_ADD_REG: 0x%X\n", address); *RBM_ADD_REG = address; // write to the command register if ( verbose>5 ) printf(" Writing read command to RBM_CSR_REG: 0x%X\n", 0x2); *RBM_CSR_REG = (unsigned int) 0x2; // read command // poll for the transaction to be completed do { timer++; status = *RBM_CSR_REG; success = status & 0x4; timeout = status & 0x8; if (timer>1000) { printf("ERROR in RBM_WRITE: TIMEOUT!\n"); return 1; } } while ( (success == 0) && (timeout == 0) ); if (verbose>5) printf(" RBM_READ Timer : %d\n", timer); // return the content of the read register unsigned int result = *RBM_DRX_REG; if ( verbose>5 ) printf(" Result from RBM_DRX_REG: 0x%X\n", result); *data = result; return 0; } //======================================================================== int rbm_write(unsigned int address, unsigned int data, int verbose) { // // Write function. Return transaction status. We use COMMAND MODE // if ( verbose>5 ) printf(" RBM WRITE function. Will use COMMAND MODE\n"); return rbm_write_command(address, data, verbose); } //======================================================================== int rbm_read(unsigned int address, unsigned int *data, int verbose) { // // Read function. Return the value. We use COMMAND MODE // if ( verbose>5 ) printf(" RBM READ function. Will use COMMAND MODE\n"); unsigned int pass_data = *data; unsigned int retval = rbm_read_command(address, &pass_data, verbose); *data = pass_data; return retval; } #endif // RBM_FUNCTIONS_H