Main Page   Packages   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Search  

C:/temp/src/j2k/QNX4/Board.cpp

Go to the documentation of this file.
00001 #ifndef __J2K__QNX__Board_CPP__
00002 #define __J2K__QNX__Board_CPP__
00003 
00004 #include <j2k/Fred/QNX/Board.hpp>
00005 
00006 // In16 and Out16 Stuff
00007 static const int Board::input_base_addr  =  INPUT_BASE_ADDR;
00008 static const int Board::output_base_addr = OUTPUT_BASE_ADDR;
00009 static const int Board::enable_addr      = OUTPUT_BASE_ADDR + ENABLE_OFFSET;
00010 
00011 // Switch 1->4, Inside/Outside
00012 static const int Board::SwitchTable[8] = {
00013   SWITCH_1_INSIDE,
00014   SWITCH_1_OUTSIDE,
00015   SWITCH_2_INSIDE,
00016   SWITCH_2_OUTSIDE,
00017   SWITCH_3_INSIDE,
00018   SWITCH_3_OUTSIDE,
00019   SWITCH_4_INSIDE,
00020   SWITCH_4_OUTSIDE 
00021 };
00022 
00023 
00024 Board::Board() {
00025   outp( output_base_addr, 255);
00026   outp( enable_addr, 3 );   // Enable Output Port 0 & 1 (%0000 0011)
00027 }
00028     
00029 virtual Board::~Board() {
00030   outp( output_base_addr,     255 ); // Send 0xFF to Port 0 & 1
00031   outp( output_base_addr + 1, 255 );
00032   outp( enable_addr, 0 );            // Disable All Output Port 
00033 }
00034 
00035 void Board::Write( int port, int val) {
00036   port = ( port >= 1 ) ? ( 1 ) : ( 0 );
00037   val  = ( val > VAL_MAX ) ? ( 0 ) : ( val );
00038   outp( output_base_addr + port, val);
00039 }
00040 
00041 void Board::Write( int val ) {
00042   int val1 = (val & 0x00FF);
00043   int val2 = (val & 0xFF00) >> 8;
00044 
00045 //   int port = ( val > VAL_MAX ) ? ( 1 ) : ( 0 );
00046 //       val  = ( val > VAL_MAX ) ? ( 0 ) : ( val );
00047 
00048   outp( output_base_addr,     val1 );
00049   outp( output_base_addr + 1, val2 );
00050 }
00051 
00052 void Board::Switch( int switch_id, int direction ) {
00053   // If the switch_id doesn't make sense then return
00054   if ( switch_id < 0 || switch_id > 3 ) return;
00055 
00056   // If the direction doesn't make sense then return
00057   if ( direction < 0 || direction > 1 ) return;
00058 
00059   // Optimized version
00060   int index = (switch_id << 1) + direction;
00061   int val   = SwitchTable[index];
00062 
00063   printf( "Send %d", val );
00064   outp( output_base_addr, val );
00065 }
00066 
00067 void Board::SwitchNormal() {
00068   outp( output_base_addr, 255 );
00069 }
00070 
00071 int Board::Read( int port ) {
00072   port = ( port >= 1 ) ? ( 1 ) : ( 0 );
00073   return ( inp( input_base_addr + port ) );
00074 }
00075 
00076 int Board::Read() {
00077   int r1 = inp( input_base_addr     );
00078   int r2 = inp( input_base_addr + 1 );
00079   return ( ( r2 << 8 ) + r1 );    // Shift Left 8 bits and Add.
00080 }
00081 
00082 #endif

Generated on Sun Oct 14 18:46:40 2001 for Standard J2K Library by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001