Commit 9147bc13 authored by root's avatar root

IO objects and methods for GPIO

parent 09ddd39b
include $(pwre_dir_symbols)
ifndef variables_mk
-include $(pwre_croot)/src/tools/bld/src/$(os_name)/$(hw_name)/variables.mk
endif
ifndef variables_mk
include $(pwre_croot)/src/tools/bld/src/$(os_name)/variables.mk
endif
ifndef rules_mk
-include $(pwre_croot)/src/tools/bld/src/$(os_name)/$(hw_name)/rules.mk
endif
ifndef rules_mk
include $(pwre_croot)/src/tools/bld/src/$(os_name)/rules.mk
endif
.PHONY : all init copy lib exe clean realclean\
$(clean_c)
all : init copy lib
init :
copy : $(inc_dir)/libusbio.h
lib :
exe :
clean :
realclean : clean $(clean_obj)
.SUFFIXES:
#$(lib_dir)/libusbio.a : ../libusbio.a
# @ echo "Copying libusbio.a"
# @ $(cp) $(cpflags) $(source) $(target)
$(inc_dir)/libusbio.h : ../libusbio.h
@ echo "Copying libusbio.h"
@ $(cp) $(cpflags) $(source) $(target)
include $(pwre_dir_symbols)
-include $(pwre_kroot)/tools/bld/src/$(os_name)/$(hw_name)/$(type_name)_generic.mk
ifeq ($($(type_name)_generic_mk),)
-include $(pwre_kroot)/tools/bld/src/$(os_name)/$(type_name)_generic.mk
endif
ifeq ($($(type_name)_generic_mk),)
include $(pwre_kroot)/tools/bld/src/$(type_name)_generic.mk
endif
-include ../../special.mk
-include ../special.mk
-include special.mk
/*
* Proview $Id$
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* rt_io_m_gpio.c -- I/O methods for class GPIO. */
#include <stdio.h>
#include <stdlib.h>
#include "pwr.h"
#include "pwr_basecomponentclasses.h"
#include "pwr_otherioclasses.h"
#include "rt_io_base.h"
#include "rt_io_rack_init.h"
#include "rt_io_rack_close.h"
#include "rt_io_msg.h"
#include "rt_io_m_gpio.h"
static pwr_tStatus IoRackInit( io_tCtx ctx,
io_sAgent *ap,
io_sRack *rp)
{
io_sCard *cp;
pwr_sClass_GPIO *op = (pwr_sClass_GPIO *)rp->op;
FILE *fp;
pwr_tStatus sts;
int i;
fp = fopen( "/sys/class/gpio/export", "w");
if (!fp) {
errh_Error( "GPIO unable to open \"/sys/class/gpio/export\", %s", rp->Name);
sts = IO__INITFAIL;
op->Status = sts;
return sts;
}
for ( cp = rp->cardlist; cp; cp = cp->next) {
for ( i = 0; i < GPIO_MAX_CHANNELS; i++) {
if ( cp->chanlist[i].cop) {
switch ( cp->chanlist[i].ChanClass) {
case pwr_cClass_ChanDi:
fprintf( fp, "%u", ((pwr_sClass_ChanDi *)cp->chanlist[i].cop)->Number);
fflush( fp);
break;
case pwr_cClass_ChanDo:
fprintf( fp, "%u", ((pwr_sClass_ChanDo *)cp->chanlist[i].cop)->Number);
fflush( fp);
break;
default: ;
}
}
}
}
fclose( fp);
errh_Info( "Init of GPIO '%s'", rp->Name);
op->Status = IO__SUCCESS;
return IO__SUCCESS;
}
static pwr_tStatus IoRackClose( io_tCtx ctx,
io_sAgent *ap,
io_sRack *rp)
{
pwr_sClass_GPIO *op = (pwr_sClass_GPIO *)rp->op;
op->Status = 0;
return IO__SUCCESS;
}
/* Every method should be registred here. */
pwr_dExport pwr_BindIoMethods(GPIO) = {
pwr_BindIoMethod(IoRackInit),
pwr_BindIoMethod(IoRackClose),
pwr_NullMethod
};
/* ra_io_m_motioncontrol_usb.h -- I/O methods for class MotionControl_USBIO. */
#ifndef ra_io_m_gpio_h
#define ra_io_m_gpio_h
#define GPIO_MAX_CHANNELS 32
typedef struct {
FILE *value_fp[GPIO_MAX_CHANNELS];
unsigned int number[GPIO_MAX_CHANNELS];
int scancount;
} io_sLocalGPIO_Module;
#endif
/*
* Proview $Id: rt_io_m_motioncontrol_usbio.c,v 1.1 2007-11-22 13:28:59 claes Exp $
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* rt_io_m_motioncontrol_usbio.c -- I/O methods for class MotionControl_USBIO. */
#include "pwr.h"
#include "pwr_basecomponentclasses.h"
#include "pwr_otherioclasses.h"
#include "co_time.h"
#include "rt_io_base.h"
#include "rt_io_card_init.h"
#include "rt_io_card_close.h"
#include "rt_io_card_read.h"
#include "rt_io_card_write.h"
#include "rt_io_msg.h"
#include "rt_io_m_gpio.h"
static pwr_tStatus IoCardInit( io_tCtx ctx,
io_sAgent *ap,
io_sRack *rp,
io_sCard *cp)
{
int i;
pwr_sClass_GPIO_Module *op = (pwr_sClass_GPIO_Module *)cp->op;
FILE *fp;
char str[80];
io_sLocalGPIO_Module *local;
char direction[20];
char access[20];
pwr_tStatus sts;
local = (io_sLocalGPIO_Module *) calloc( 1, sizeof(io_sLocalGPIO_Module));
cp->Local = local;
for ( i = 0; i < GPIO_MAX_CHANNELS; i++) {
if ( cp->chanlist[i].cop) {
switch( cp->chanlist[i].ChanClass) {
case pwr_cClass_ChanDi:
local->number[i] = ((pwr_sClass_ChanDi *)cp->chanlist[i].cop)->Number;
strcpy( direction, "in");
strcpy( access, "r+");
break;
case pwr_cClass_ChanDo:
local->number[i] = ((pwr_sClass_ChanDo *)cp->chanlist[i].cop)->Number;
strcpy( direction, "out");
strcpy( access, "w");
break;
default: ;
}
switch( cp->chanlist[i].ChanClass) {
case pwr_cClass_ChanDi:
case pwr_cClass_ChanDo:
sprintf( str, "/sys/class/gpio/gpio%u/direction", local->number[i]);
fp = fopen( str, "w");
if (!fp) {
errh_Error( "GPIO uable to open %s, %s, Id: %d", str, cp->Name,
local->number[i]);
sts = IO__INITFAIL;
op->Status = sts;
return sts;
}
fprintf( fp, "%s", direction);
fclose( fp);
sprintf( str, "/sys/class/gpio/gpio%u/value", local->number[i]);
local->value_fp[i] = fopen( str, access);
if (!local->value_fp[i]) {
errh_Error( "GPIO Unable op open %s, '%s' Id: %d", str, cp->Name,
local->number[i]);
sts = IO__INITFAIL;
op->Status = sts;
return sts;
}
break;
default: ;
}
}
}
errh_Info( "Init of GPIO Module '%s'", cp->Name);
return IO__SUCCESS;
}
static pwr_tStatus IoCardClose( io_tCtx ctx,
io_sAgent *ap,
io_sRack *rp,
io_sCard *cp)
{
int i;
io_sLocalGPIO_Module *local = (io_sLocalGPIO_Module *)cp->Local;
for ( i = 0; i < GPIO_MAX_CHANNELS; i++) {
if ( cp->chanlist[i].cop) {
switch( cp->chanlist[i].ChanClass){
case pwr_cClass_ChanDi:
case pwr_cClass_ChanDo:
if ( local->value_fp[i])
fclose( local->value_fp[i]);
break;
default: ;
}
}
}
free( cp->Local);
return IO__SUCCESS;
}
static pwr_tStatus IoCardRead( io_tCtx ctx,
io_sAgent *ap,
io_sRack *rp,
io_sCard *cp)
{
io_sLocalGPIO_Module *local = (io_sLocalGPIO_Module *)cp->Local;
int i;
char str[20];
for ( i = 0; i < GPIO_MAX_CHANNELS; i++) {
if ( cp->chanlist[i].cop) {
switch( cp->chanlist[i].ChanClass) {
case pwr_cClass_ChanDi:
fflush( local->value_fp[i]);
fgets( str, sizeof(str), local->value_fp[i]);
rewind( local->value_fp[i]);
if ( str[0] == '0')
*(pwr_tBoolean *)cp->chanlist[i].vbp = 0;
else
*(pwr_tBoolean *)cp->chanlist[i].vbp = 1;
break;
default: ;
}
}
}
return IO__SUCCESS;
}
static pwr_tStatus IoCardWrite( io_tCtx ctx,
io_sAgent *ap,
io_sRack *rp,
io_sCard *cp)
{
io_sLocalGPIO_Module *local = (io_sLocalGPIO_Module *)cp->Local;
int i;
for ( i = 0; i < GPIO_MAX_CHANNELS; i++) {
if ( cp->chanlist[i].cop) {
switch( cp->chanlist[i].ChanClass) {
case pwr_cClass_ChanDo:
if ( *(pwr_tBoolean *)cp->chanlist[i].vbp)
fprintf( local->value_fp[i], "1");
else
fprintf( local->value_fp[i], "0");
fflush( local->value_fp[i]);
// printf( "Write %d %d\n", local->number[i], *(pwr_tBoolean *)cp->chanlist[i].vbp);
break;
default: ;
}
}
}
return IO__SUCCESS;
}
/* Every method should be registred here. */
pwr_dExport pwr_BindIoMethods(GPIO_Module) = {
pwr_BindIoMethod(IoCardInit),
pwr_BindIoMethod(IoCardClose),
pwr_BindIoMethod(IoCardRead),
pwr_BindIoMethod(IoCardWrite),
pwr_NullMethod
};
......@@ -5,3 +5,5 @@ Modbus_Module
Modbus_Master
Modbus_TCP_Server
Modbus_TCP_ServerModule
GPIO
GPIO_Module
Volume OtherIO $ClassVolume 0.0.250.10
Body SysBody 01-JAN-1970 01:00:00.00
Attr NextOix = "_X77"
Attr NextCix = "_X8"
Attr NextOix = "_X91"
Attr NextCix = "_X10"
Attr NextTix[0] = "_X5"
EndBody
Object Type $TypeHier 1 15-NOV-2007 14:35:37.90
......@@ -1452,5 +1452,146 @@ Volume OtherIO $ClassVolume 0.0.250.10
EndBody
EndObject
EndObject
Object GPIO $ClassDef 8 15-APR-2010 21:46:30.11
Body SysBody 15-APR-2010 21:46:16.74
Attr Editor = 0
Attr Method = 0
Attr Flags = 10320
EndBody
Object RtBody $ObjBodyDef 1 15-APR-2010 21:46:16.74
Body SysBody 15-APR-2010 21:46:39.64
Attr StructName = "GPIO"
Attr NextAix = "_X17"
EndBody
Object Description $Attribute 13 15-APR-2010 21:46:16.74
Body SysBody 15-APR-2010 21:46:16.74
Attr PgmName = "Description"
Attr TypeRef = "pwrs:Type-$String80"
EndBody
EndObject
Object Process $Attribute 14 15-APR-2010 21:46:16.74
Body SysBody 15-APR-2010 21:54:44.41
Attr PgmName = "Process"
Attr TypeRef = "pwrb:Type-IoProcessMask"
EndBody
EndObject
Object ThreadObject $Attribute 15 15-APR-2010 21:46:16.74
Body SysBody 15-APR-2010 21:46:16.74
Attr PgmName = "ThreadObject"
Attr TypeRef = "pwrs:Type-$Objid"
EndBody
EndObject
Object Status $Attribute 16 15-APR-2010 21:46:16.74
Body SysBody 15-APR-2010 21:55:29.27
Attr PgmName = "Status"
Attr Flags = 1040
Attr TypeRef = "pwrs:Type-$Status"
EndBody
EndObject
EndObject
Object ConfiguratorPoson $Menu 78 15-APR-2010 21:46:16.74
Object Pointed $Menu 79 15-APR-2010 21:46:16.74
Object Connect $MenuButton 80 15-APR-2010 21:46:16.74
Body SysBody 15-APR-2010 21:46:16.74
Attr ButtonName = "Connect PlcThread"
Attr MethodName = "$Objid-Connect"
Attr MethodArguments[0] = "ThreadObject"
Attr MethodArguments[1] = "PlcThread"
Attr FilterName = "$Objid-IsOkConnect"
Attr FilterArguments[0] = "ThreadObject"
Attr FilterArguments[1] = "PlcThread"
EndBody
EndObject
EndObject
EndObject
Object IoMethods $RtMethod 89 15-APR-2010 21:52:17.62
Object IoRackInit $Method 90 15-APR-2010 21:52:17.62
Body SysBody 15-APR-2010 21:52:28.10
Attr MethodName = "GPIO-IoRackInit"
EndBody
EndObject
Object IoRackClose $Method 91 15-APR-2010 21:52:17.62
Body SysBody 15-APR-2010 21:52:39.12
Attr MethodName = "GPIO-IoRackClose"
EndBody
EndObject
EndObject
Object Template GPIO 2149810176 01-JAN-1970 01:00:00.00
Body RtBody 15-APR-2010 21:57:21.82
Attr Process = 1
EndBody
EndObject
EndObject
Object GPIO_Module $ClassDef 9 15-APR-2010 21:49:47.13
Body SysBody 15-APR-2010 21:46:16.74
Attr Editor = 0
Attr Method = 0
Attr Flags = 18512
EndBody
Object RtBody $ObjBodyDef 1 15-APR-2010 21:46:16.74
Body SysBody 15-APR-2010 21:52:59.99
Attr StructName = "GPIO_Module"
Attr NextAix = "_X15"
EndBody
Object Description $Attribute 10 15-APR-2010 21:53:54.03
Body SysBody 15-APR-2010 21:54:16.96
Attr PgmName = "Description"
Attr TypeRef = "pwrs:Type-$String80"
EndBody
EndObject
Object Process $Attribute 11 15-APR-2010 21:54:37.62
Body SysBody 15-APR-2010 21:54:53.56
Attr PgmName = "Process"
Attr TypeRef = "pwrb:Type-IoProcessMask"
EndBody
EndObject
Object ThreadObject $Attribute 13 15-APR-2010 21:55:05.81
Body SysBody 15-APR-2010 21:55:05.81
Attr PgmName = "ThreadObject"
Attr TypeRef = "pwrs:Type-$Objid"
EndBody
EndObject
Object Status $Attribute 12 15-APR-2010 21:55:37.33
Body SysBody 15-APR-2010 21:55:45.30
Attr PgmName = "Status"
Attr TypeRef = "pwrs:Type-$Status"
EndBody
EndObject
Object ScanInterval $Attribute 14 16-APR-2010 16:09:01.24
Body SysBody 16-APR-2010 16:09:02.20
Attr PgmName = "ScanInterval"
Attr TypeRef = "pwrs:Type-$UInt32"
EndBody
EndObject
EndObject
Object IoMethods $RtMethod 84 15-APR-2010 21:46:16.74
Object IoCardInit $Method 85 15-APR-2010 21:46:16.74
Body SysBody 15-APR-2010 21:55:58.78
Attr MethodName = "GPIO_Module-IoCardInit"
EndBody
EndObject
Object IoCardClose $Method 86 15-APR-2010 21:46:16.74
Body SysBody 15-APR-2010 21:56:07.31
Attr MethodName = "GPIO_Module-IoCardClose"
EndBody
EndObject
Object IoCardRead $Method 87 15-APR-2010 21:46:16.74
Body SysBody 15-APR-2010 21:56:12.67
Attr MethodName = "GPIO_Module-IoCardRead"
EndBody
EndObject
Object IoCardWrite $Method 88 15-APR-2010 21:46:16.74
Body SysBody 15-APR-2010 21:56:18.19
Attr MethodName = "GPIO_Module-IoCardWrite"
EndBody
EndObject
EndObject
Object Template GPIO_Module 2150072320 01-JAN-1970 01:00:00.00
Body RtBody 15-APR-2010 21:57:34.91
Attr Process = 1
Attr Status = 286
EndBody
EndObject
EndObject
EndObject
EndVolume
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment