#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#include <sys/mman.h>
#include <sys/neutrino.h>
#include <hw/inout.h>
#include "BoardDef.hpp"
Go to the source code of this file.
Functions | |
uintptr_t | setHardware (uint64_t addr) |
void | SetupIO () |
void | CleanUp () |
int | server () |
int | main (int argc, char **argv) |
Variables | |
uintptr_t | ib_state = NULL |
uintptr_t | ob_state = NULL |
uintptr_t | ib_ctrl = NULL |
uintptr_t | ob_ctrl = NULL |
name_attach_t * | attach = (name_attach_t*)(~0) |
USHORT | ob_val = 0xFFFF |
USHORT | ib_val = 0xFFFF |
int | done = 0 |
|
Definition at line 41 of file BoardServer.cpp. 00042 { 00043 /* Remove the name from the space */ 00044 printf( "Removing the attach name from the local name space.\n" ); 00045 name_detach(attach, 0); 00046 } |
|
Definition at line 29 of file BoardServer.cpp. 00030 { 00031 ob_state = setHardware( BOARD_OUT16_ADDR ); 00032 ib_state = setHardware( BOARD_IN16_ADDR ); 00033 ob_ctrl = setHardware( BOARD_OUT16_ADDR + BOARD_CONTROL_OFFSET ); 00034 ib_ctrl = setHardware( BOARD_IN16_ADDR + BOARD_CONTROL_OFFSET ); 00035 00036 out16( ob_state, ob_val ); // Set to default 00037 out8( ob_ctrl, BOARD_OUT16_ENABLE ); // Set Array 0 & 1 ON (Controllable) 00038 ib_val = in16( ib_state ); 00039 } |
|
Definition at line 172 of file BoardServer.cpp. 00172 { 00173 return server(); 00174 } |
|
Definition at line 49 of file BoardServer.cpp. 00050 { 00051 board_data_t msg, rmsg; 00052 int rcvid; 00053 00054 /* Create a local name (/dev/name/local/...) */ 00055 attach = name_attach( NULL, ATTACH_POINT, NAME_FLAG_ATTACH_GLOBAL ); 00056 if ( attach == NULL ) 00057 { 00058 printf( "Could not attach a name to the local name space.\n" ); 00059 return EXIT_FAILURE; 00060 } 00061 00062 SetupIO(); 00063 00064 /* Do your MsgReceive's here now with the chid */ 00065 while( !done ) 00066 { 00067 memset( msg.string, 0, 80 ); 00068 memset( rmsg.string, 0, 80 ); 00069 rcvid = MsgReceive(attach->chid, &msg, sizeof(msg), NULL); 00070 00071 // printf( "Received [%d]\n", rcvid ); 00072 00073 if (rcvid == -1) /* Error condition, exit */ 00074 { 00075 break; 00076 } 00077 00078 if (rcvid == 0) /* Pulse received */ 00079 { 00080 printf( "Pulse received.\n" ); 00081 switch (msg.hdr.code) { 00082 case _PULSE_CODE_DISCONNECT: 00083 /* 00084 * A client disconnected all its connections (called 00085 * name_close() for each name_open() of our name) or 00086 * terminated 00087 */ 00088 printf( "Client disconnected.\n" ); 00089 fflush( stdout ); 00090 ConnectDetach(msg.hdr.scoid); 00091 break; 00092 00093 case _PULSE_CODE_UNBLOCK: 00094 /* 00095 * REPLY blocked client wants to unblock (was hit by 00096 * a signal or timed out). It's up to you if you 00097 * reply now or later. 00098 */ 00099 printf( "Client wants to unblock.\n"); 00100 break; 00101 default: 00102 /* A pulse sent by one of your processes? */ 00103 printf( "Unknown pulse.\n" ); 00104 fflush( stdout ); 00105 break; 00106 } 00107 continue; 00108 } 00109 00110 /* A QNX IO message received, reject */ 00111 if (msg.hdr.type >= _IO_BASE && msg.hdr.type <= _IO_MAX) { 00112 MsgError( rcvid, ENOSYS ); 00113 printf( "Rejected.\n" ); 00114 continue; 00115 } 00116 00117 if ( msg.serialMsgID != BOARD_SerialMsgID ) { 00118 printf( "Wrong Serial ID...\n" ); 00119 continue; 00120 } 00121 00122 /* A message (presumable ours) received, handle */ 00123 // printf( "Server receive %d \n", msg.data ); 00124 00125 memcpy( &rmsg, &msg, sizeof( msg ) ); 00126 00127 register UCHAR cmd = msg.command; 00128 00129 if ( (cmd & BOARD_CONTROL_IN) == BOARD_CONTROL_IN ) 00130 out8( ib_ctrl, msg.control_in ); 00131 00132 if ( (cmd & BOARD_CONTROL_OUT) == BOARD_CONTROL_OUT ) 00133 out8( ob_ctrl, msg.control_out ); 00134 00135 if ( (cmd & BOARD_IN16_READ ) == BOARD_IN16_READ ) { 00136 ib_val = in16( ib_state ); 00137 rmsg.input = ~ib_val; 00138 } 00139 00140 if ( (cmd & BOARD_OUT16_WRITE ) == BOARD_OUT16_WRITE ) { 00141 ob_val = ~( msg.output ); 00142 out16( ob_state, ob_val ); 00143 } 00144 00145 if ( (cmd & BOARD_GET_STATE) == BOARD_GET_STATE ) { 00146 rmsg.control_in = in8( ib_ctrl ); 00147 rmsg.control_out = in8( ib_ctrl ); 00148 rmsg.output = ~ob_val; 00149 // input processed already. 00150 } 00151 00152 if ( (cmd & BOARD_TEST_SERVER) == BOARD_TEST_SERVER ) { 00153 memcpy( &rmsg, &msg, sizeof( board_data_t ) ); 00154 } 00155 00156 if ( (cmd & BOARD_KILL_SERVER) == BOARD_KILL_SERVER ) { 00157 done++; 00158 } 00159 00160 rmsg.command = BOARD_REPLY_DONE; 00161 00162 rmsg.data++; 00163 strcpy( rmsg.string, "ACK" ); 00164 MsgReply(rcvid, EOK, &rmsg, sizeof( rmsg ) ); 00165 } 00166 00167 CleanUp(); 00168 00169 return EXIT_SUCCESS; 00170 } |
|
Definition at line 13 of file BoardServer.cpp. Referenced by SetupIO().
00014 { 00015 ThreadCtl( _NTO_TCTL_IO, 0 ); 00016 uintptr_t ptr = mmap_device_io( 2, addr ); 00017 } |
|
Definition at line 23 of file BoardServer.cpp. |
|
Definition at line 27 of file BoardServer.cpp. |
|
Definition at line 21 of file BoardServer.cpp. |
|
Definition at line 19 of file BoardServer.cpp. |
|
Definition at line 26 of file BoardServer.cpp. |
|
Definition at line 22 of file BoardServer.cpp. |
|
Definition at line 20 of file BoardServer.cpp. |
|
Definition at line 25 of file BoardServer.cpp. |