Driver for hardware IO port

More
13 Jan 2014 13:54 #42679 by mariusl
Hi All,
I have to write a driver that will access a hardware port on a industrial motherboard. I think the chipset is a winbond device of sorts. I have the input and output address of the port.
I looked at the opto_ac5 hal driver as an example. It would seem to be the only simple driver that does a similar job.
I noticed that the following functions are available for the component but I dont see them in the code. What am I missing?

This is from the document
opto_ac5.0.digital-read - Add this to a thread to read all the input points.
opto_ac5.0.digital-write - Add this to a thread to write all the output points and LEDs.

And this in the code
// These methods are exported to the HAL.
static void Device_DigitalInRead(void *this, long period);
static void Device_DigitalOutWrite(void *this, long period);

Am i looking in the right place or is there another way to get a base thread component going?

Regards
Marius


www.bluearccnc.com

Please Log in or Create an account to join the conversation.

More
13 Jan 2014 15:02 #42680 by cmorley
Replied by cmorley on topic Driver for hardware IO port
They are in the code:
// here we read inputs from board
// we read the current data (variable 'pins') of the first port. Then for each of the 24 points
// we compare to the mask of the first port to see which of the 24 io points are inputs (the bits that are false)
// if it is an input then check 'pins' against the mask to see if input bit is true
// update the HAL pin and not-pin accoringly. shift the mask then do the next point (of 24 io points)
// after all pins done-increase 'portnum' to 1 set offset to the offset for port1
// then do it all again on the second port

static void
Device_DigitalInRead(void *arg, long period)
{
    board_data_t			*pboard = (board_data_t *)arg;
    DigitalPinsParams			*pDigital;
    int					i, portnum=0;
    unsigned long			pins, offset=DATA_READ_OFFSET_0, mask;

    // For each port.
	while (portnum<2)
		{
			mask=1;
			pDigital = &pboard->port[portnum].io[0];

			// Read digital I/O register.
			pins=	readl (pboard->base + (offset));
   			for(i = 0; i < 24; i++,pDigital++)
			{
				if ((pboard->port[portnum].mask & mask) ==0) // is it an input bit ?
				{
				    if ((pins & mask) !=0){	*(pDigital->pValue) =0;
					}else{	*(pDigital->pValue) = 1;	}
					// Update not pin.
				    *(pDigital->pValueNot) = !*(pDigital->pValue);
				}
	  		 	 mask <<=1;// shift mask
			}
			portnum++;
			offset=DATA_READ_OFFSET_1;// change to offset for port1
 		}
}

Chris M

Please Log in or Create an account to join the conversation.

More
13 Jan 2014 15:07 - 13 Jan 2014 15:09 #42681 by cmorley
Replied by cmorley on topic Driver for hardware IO port
Or maybe you are wondering where the pins are made:
// we check each ports mask (port[portnum].mask) against a mask bit to see which of the 24 points of i/o are inputs (a false bit is an input)
// then export HAL pins mapped to the proper io structure
// HAL pin numbers represent position in an opto22 relay rack (eg. pin 00 is position 0)
// this way you can configure the i/o in any way for all the 24 points of each port

static int Device_ExportDigitalInPinsParametersFunctions(board_data_t *this, int comp_id, int boardId)
{
    int					halError=0, channel,mask,portnum=0;
    char				name[HAL_NAME_LEN + 1];

    // Export pins and parameters.
	while (portnum<2)
		{
		mask=1;
   		 for(channel = 0; channel < 24; channel++)
		   {
			if ((this->port[portnum].mask & mask)==0)//physical input?
			{
			// Pins.
			if((halError = hal_pin_bit_newf(HAL_OUT, &(this->port[portnum].io[channel].pValue),
			  comp_id, "opto-ac5.%d.port%d.in-%02d", boardId, portnum, channel)) != 0)
			    break;

			if((halError = hal_pin_bit_newf(HAL_OUT, &(this->port[portnum].io[channel].pValueNot),
			  comp_id, "opto-ac5.%d.port%d.in-%02d-not", boardId, portnum, channel)) != 0)
			    break;

			// Init pin.
			*(this->port[portnum].io[channel].pValue) = 0;
			*(this->port[portnum].io[channel].pValueNot) = 1;
			}
			mask <<=1;
		   }

		   portnum ++;	
	 	}

    // Export functions.
    if(!halError){
	rtapi_snprintf(name, sizeof(name), "opto-ac5.%d.digital-read", boardId);
	halError = hal_export_funct(name, Device_DigitalInRead, this, 0, 0, comp_id);
    }

    if(halError){
	rtapi_print_msg(RTAPI_MSG_ERR, "ERROR OPTO22_AC5---exporting digital inputs to HAL failed\n");
	return(-1);
    }

    return(0);
}
Last edit: 13 Jan 2014 15:09 by cmorley.

Please Log in or Create an account to join the conversation.

More
13 Jan 2014 15:11 #42682 by mariusl
Replied by mariusl on topic Driver for hardware IO port
Hi Chris
Thanks for answering quick. I did see the code but what I dont understand is the difference in syntax between the declaration and the exported function.

Regards
Marius


www.bluearccnc.com

Please Log in or Create an account to join the conversation.

More
13 Jan 2014 15:22 #42684 by cmorley
Replied by cmorley on topic Driver for hardware IO port
I'm sorry I'm not a good C programmer and I made that program 8 years ago using the skeleton example mostly.
// Export functions.
    if(!halError){
	rtapi_snprintf(name, sizeof(name), "opto-ac5.%d.digital-read", boardId);
	halError = hal_export_funct(name, Device_DigitalInRead, this, 0, 0, comp_id);
    }

This part of the code ties the pin name to the function call to service it.

Chris M

Please Log in or Create an account to join the conversation.

More
13 Jan 2014 15:28 #42685 by mariusl
Replied by mariusl on topic Driver for hardware IO port
Chris
I see it now. It is my complete lack of understanding in this area of LCNC.
Where do I find the skeleton for this kind of work?

Regards
Marius


www.bluearccnc.com

Please Log in or Create an account to join the conversation.

More
13 Jan 2014 15:39 #42686 by cmorley
Replied by cmorley on topic Driver for hardware IO port
It takes a bit to get your head around it.
Some driver building docs would be a good addition to the manual....

hal_skeleton.c is in src/hal/drivers

If you are comfortable with building components with comp, look at pcl720.comp (for an ISA card)
Andy made that one so he will probably comment if you have questions about it.
Comp hides some of the RTAI details.


Chris M

Please Log in or Create an account to join the conversation.

More
13 Jan 2014 16:12 #42688 by mariusl
Replied by mariusl on topic Driver for hardware IO port
I have done several components using Comp so I will go that way. Thanks for the help so far.

For interest sake, how do you do the compile with your C type of component? I mean the make process outside of the source tree while you are writing and testing it.

Regards
Marius


www.bluearccnc.com

Please Log in or Create an account to join the conversation.

More
13 Jan 2014 17:16 #42691 by cmorley
Replied by cmorley on topic Driver for hardware IO port
comp can compile C source.
www.linuxcnc.org/docs/2.5/html/hal/comp....-realtime-components

I did it by adding to the make file. I haven't made a realtime driver in a long time.

Chris M

Please Log in or Create an account to join the conversation.

More
13 Jan 2014 17:47 #42692 by mariusl
Replied by mariusl on topic Driver for hardware IO port
Thanks Chris.
I just received a shared library for my DIO port from the supplier. Can I use shared libraries in components?

Regards
Marius


www.bluearccnc.com

Please Log in or Create an account to join the conversation.

Time to create page: 0.088 seconds
Powered by Kunena Forum