000
29.10.2008, 07:59 Uhr
~Guiekalle
Gast
|
Habe ein Programm, in das ich meinen Makro (Lese-Befehl)
Code: |
[b]#define rdlmode(adr) (outword (MOD1ADR+0x10,(adr)),inword (MOD1ADR+0x108)) [/b]
|
einbauen möchte.
Diese Adresse des Makro´s entspricht ABCC_PARALLEL_BASE_ADDRESS + 0x3D00
So muss ich nun meinen Makro (besser dessen Adresse anstelle von der BASE_ADDRESS+0x3D00) irgendwie dort einbauen.
Müsste doch so richtig sein? Oder habt ihr andere Ideen.Wie kann ich vorgehen ?
Würde mich freuen...
Hier nun zum Programm:
C++: |
/******************************************************************************* ** ** Public Globals ** ******************************************************************************** */
/* ** bSw1 and bSw2 represent two DIP-switches (or similar) which are used to set ** the fieldbus node adress and baudrate. */
#ifdef USE_DIPSWITCHES UINT8 bSw1; UINT8 bSw2; #endif
/* ** Working copies of the status and control registers */
UINT8 bControlReg = ABP_CTRL_R_BIT; UINT8 bStatusReg = 0x80;
/* ** State variable that keeps track of which initialization command to send next */
#ifdef USE_DIPSWITCHES CmdStateType eCmdState = MSG_NODE_ADR; #else CmdStateType eCmdState = MSG_MAP_IO_1; #endif
/* ** This variable keeps track of if there are any commands which we have not yet ** received a response to. */
UINT8 bOutstandingCmds = 0;
/* ** The application data instances (ADIs for short) ** This is the data which will be exchanged on the fieldbus ** In this simple example we only have eight UINT16 parameters */
UINT16 aiApplicationData[ NUMBER_OF_ADIS ] = { 0, 1, 2, 3, 4, 5, 6, 7 };
/* ** The names of each application data instance (ADI for short) ** These strings should be changed to reflect the proper names of the ADIs. */
const char* const apbADINames[ NUMBER_OF_ADIS ] = { "1st ADI", "2nd ADI", "3rd ADI", "4th ADI", "5th ADI", "6th ADI", "7th ADI", "8th ADI" };
/* ** This variable is used to indicate the network data format. ** Little endian or big endian. */
NetFormatType eNetFormat = NET_UNKNOWN;
/******************************************************************************* ** ** Private Globals ** ******************************************************************************** */
/* ** Pointers to process data, messages and registers in the Anybus-CC. */
#ifdef ABCC_PARALLEL_DIRECT_ACCESS_THROUGH_PTR UINT16* const piWritePD = (UINT16*)( ABCC_PARALLEL_BASE_ADDRESS + 0x3800 ); UINT16* const piReadPD = (UINT16*)( ABCC_PARALLEL_BASE_ADDRESS + 0x3900 ); ABP_MsgType* const psWriteMsg = (ABP_MsgType*)( ABCC_PARALLEL_BASE_ADDRESS + 0x3B00 ); [b] ABP_MsgType* const psReadMsg = (ABP_MsgType*)( ABCC_PARALLEL_BASE_ADDRESS + 0x3D00 );[/b] volatile UINT8* const pbControlReg = (UINT8*)( ABCC_PARALLEL_BASE_ADDRESS + 0x3FFE ); volatile UINT8* const pbStatusReg = (UINT8*)( ABCC_PARALLEL_BASE_ADDRESS + 0x3FFF ); #else UINT16 aiWritePDBuffer[ 2 ]; UINT16 aiReadPDBuffer[ 2 ]; UINT16* const piWritePD = aiWritePDBuffer; UINT16* const piReadPD = aiReadPDBuffer; ABP_MsgType sMsgBuffer; ABP_MsgType* const psWriteMsg = &sMsgBuffer; ABP_MsgType* const psReadMsg = &sMsgBuffer; #endif
/******************************************************************************* ** ** Public Functions ** ******************************************************************************** */
/*------------------------------------------------------------------------------ ** Main() **------------------------------------------------------------------------------ */
void Main( void ) { UINT8 bNewStatusReg1, bNewStatusReg2; #ifdef USE_DIPSWITCHES static UINT8 bLastSw1, bLastSw2; #endif
/* ** Read the status register. ** The status register must doublechecked since we are not using the ** interrupt feature. */
do { #ifdef ABCC_PARALLEL_DIRECT_ACCESS_THROUGH_PTR bNewStatusReg1 = *pbStatusReg; bNewStatusReg2 = *pbStatusReg; #else ReadParallel( &bNewStatusReg1, 0x3FFF, 1 ); ReadParallel( &bNewStatusReg2, 0x3FFF, 1 ); #endif } while( bNewStatusReg1 != bNewStatusReg2 );
/* ** Check if the toggle bit in the status register has toggled. */
if( ( bNewStatusReg1 & ABP_STAT_T_BIT ) == ( bStatusReg & ABP_STAT_T_BIT ) ) { /* ** Toggle bit has not toggled: Modul is still busy */
return; }
bStatusReg = bNewStatusReg1;
bControlReg &= ~ABP_CTRL_M_BIT; bControlReg ^= ABP_CTRL_T_BIT;
if( bStatusReg & ABP_STAT_M_BIT ) { /* ** There is a message available. */
#ifndef ABCC_PARALLEL_DIRECT_ACCESS_THROUGH_PTR ReadParallel( psReadMsg, 0x3D00, sizeof( ABP_MsgHeaderType ) ); ReadParallel( psReadMsg->abData, 0x3D00 + sizeof( ABP_MsgHeaderType ), psReadMsg->sHeader.bDataSize ); #endif
if( psReadMsg->sHeader.bCmd & ABP_MSG_HEADER_C_BIT ) { /* ** The message is a command ** First we copy the header to prepare the response. */
psWriteMsg->sHeader = psReadMsg->sHeader; psWriteMsg->sHeader.bCmd = psReadMsg->sHeader.bCmd & ~ABP_MSG_HEADER_C_BIT;
switch( psReadMsg->sHeader.bDestObj ) { case ABP_OBJ_NUM_APPD:
/* ** Command to the application data object */
ApplicationDataObject(); bControlReg |= ABP_CTRL_M_BIT;
break;
default:
/* ** Command to a unsupported object. */
SetMsgError( psWriteMsg, 1, ABP_ERR_UNSUP_OBJ ); bControlReg |= ABP_CTRL_M_BIT;
break; } } else {
|
.......usw........ Dieser Post wurde am 29.10.2008 um 08:22 Uhr von FloSoft editiert. |