industrialNETworXnetx

simon

simon

| 07.08.2008 | 14:22 | 3 replies

PROFIBUS warmstart via DPM memory

Hi,

I'm trying to get a PROFIBUS connection on my NXHX-500 which is connected to another uP via Host-Interface (DPM mode).

Unfortunately the DPM manual (netX_DPM_Interface_Rev04.pdf) is not very clear about what flags have to be set in order to get the DPM really working. It would be helpful to know what the xChannel functions listed below actually do.

On the netSTICK, I activate a PROFIBUS connection as follows:

      /* Toggle Application Ready State Flag */
      lRet = xChannelHostState(hChannel, CIFX_HOST_STATE_READY, &ulState, ulTimeout);
      if(lRet == CIFX_DEV_NOT_RUNNING)
      {
        /* reset the communication channel before send Warmstart Paramenters */
        lRet = xChannelReset(hChannel, CIFX_CHANNELINIT, ulTimeout);

/* Set Fieldbus Warmstart Parameters Packet */
DeviceControlCommProto_SetFBWarmstartParamsPkt(ptRsc, (void*)&tSendPkt);

/* send Fieldbus Warmstart Request Packet */
lRet = xChannelPutPacket(hChannel, &tSendPkt, 3000);

/* Get Fieldbus Warmstart Response Packet */
lRet = xChannelGetPacket(hChannel, sizeof(tRecvPkt), (void*)&tRecvPkt, 3000);

/* Toggle Application Ready State Flag */
lRet = xChannelHostState(hChannel, CIFX_HOST_STATE_READY, &ulState, ulTimeout);
}

My attempt to build a set of functions to replace the xChannel functions in the code:

for xChannelHostState:

#define APP_COS 0x0308
#define HOST_FLAGS 0x020A

void set_host_state(unsigned long cmd, unsigned long *state) {
switch(cmd) {
case HOST_STATE_NOT_READY:
DPM_ENABLE;
// set APP_COS_APP_READY flag to zero
*(unsigned long *)DPM_ADR(APP_COS) &= 0x7F;
DPM_DISABLE;
break;
case HOST_STATE_READY:
DPM_ENABLE;
// set APP_COS_APP_READY flag to one
*(unsigned long *)DPM_ADR(APP_COS) |= 0x1;
DPM_DISABLE;
break;
default:
DPM_ENABLE;
*state = (*(unsigned long *)DPM_ADR(APP_COS) & 0x1);
DPM_DISABLE;
}
DPM_ENABLE;
*(unsigned short*)DPM_ADR(HOST_FLAGS) |= 0x4;
DPM_DISABLE;
return;
}

DPM_ENABLE and DPM_DISABLE are for the chip-select signal...
DPM_ADR maps the DPM addresses to the corresponding address range of my uP.

Then the cifX Device Driver Manual says that xChannelHostState returns either CIFX_NO_ERROR or CIFX_NO_COM_FLAG. But in the code fragment from the netSTICK app it is checked against CIFX_DEV_NOT_RUNNING. Why?

For xChannelReset:

void comm_channel_reset() {
  DPM_ENABLE;
  *(unsigned long*)DPM_ADR(APP_COS) |= 0x18;
  *(unsigned short*)DPM_ADR(HOST_FLAGS) |= 0x4;
  DPM_DISABLE;
  return;
}

For xChannelPutPacket

void send_packet(int len, char *data) {
  DPM_ENABLE;
  memcpy((void*)SEND_MBX, data, len);
  DPM_DISABLE;
  return;
}

Do I have to work with the CMD and ACK flags for this function to work? The DPM manual wasn't very clear about that.

For xChannelGetPacket

void recv_packet(int len, char *dest) {
  DPM_ENABLE;
  memcpy(dest, (void const *)RECV_MBX, len);
  DPM_DISABLE;
  return;
}

I hope someone can help me on this...

Thanks,

simon

Andreas Jacob

Andreas Jacob

Hilscher Gesellschaft fuer Systemautomation mbH

| 07.08.2008 | 14:32

Hi,

to figure out, what the xChannel functions are doing, please hzave a look into the C-Toolkit and the manual.

I think this will clarify all your questions ;-)

simon

simon

| 07.08.2008 | 14:56

Well, I've been sitting over the "cifX Device Driver Manual.pdf" (cifX Manual) and "netX DPM Interface.pdf" (DPM manual) files for the last two days and I'm sorry to say but the documentation is not very clear on some points.

For example, it's nice to know that the xChannelHostState function does

cifX Manual wrote:
Toggle the 'Application Ready State Flag' in the communication channel host handshake flags. This
function is used to signal a communication stack the presents of a user application.
but it's not very easy to write a function which does the same by toggling flags in the DPM memory. Setting the 'Application Ready State Flag' in the communication channel host handshake flags (there actually isn't a 'Application Ready State Flag' in these flags according to the DPM manual) doesn't work. I tried setting the 'Application Ready State Flag' (APP_COS_APP_READY) in the Application Change Of State register (DPM offset 0x0308) in the Control Block (see section 3.2.4 of the DPM manual) but this didn't work. Then for good measure I also toggle the HSF_HOST_COS_CMD flag in the Host System Flags register but this also doesn't help much, apparently...

I hope you can clarify what I forgot to do.

Thanks,

simon

Andreas Jacob

Andreas Jacob

Hilscher Gesellschaft fuer Systemautomation mbH

| 07.08.2008 | 15:15

Why you will write all the functions by your self?

Have you looked into the C-Toolkit?
It is provided in source code and should help you by your implementation.
It is a collection of all the needed functions.

Login