at v2.6.30 328 lines 12 kB view raw
1/**************************************************************************** 2 3 (c) SYSTEC electronic GmbH, D-07973 Greiz, August-Bebel-Str. 29 4 www.systec-electronic.com 5 6 Project: openPOWERLINK 7 8 Description: source file for EPL API module (process image) 9 10 License: 11 12 Redistribution and use in source and binary forms, with or without 13 modification, are permitted provided that the following conditions 14 are met: 15 16 1. Redistributions of source code must retain the above copyright 17 notice, this list of conditions and the following disclaimer. 18 19 2. Redistributions in binary form must reproduce the above copyright 20 notice, this list of conditions and the following disclaimer in the 21 documentation and/or other materials provided with the distribution. 22 23 3. Neither the name of SYSTEC electronic GmbH nor the names of its 24 contributors may be used to endorse or promote products derived 25 from this software without prior written permission. For written 26 permission, please contact info@systec-electronic.com. 27 28 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 29 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 30 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 31 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 32 COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 33 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 34 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 35 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 36 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 37 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 38 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 39 POSSIBILITY OF SUCH DAMAGE. 40 41 Severability Clause: 42 43 If a provision of this License is or becomes illegal, invalid or 44 unenforceable in any jurisdiction, that shall not affect: 45 1. the validity or enforceability in that jurisdiction of any other 46 provision of this License; or 47 2. the validity or enforceability in other jurisdictions of that or 48 any other provision of this License. 49 50 ------------------------------------------------------------------------- 51 52 $RCSfile: EplApiProcessImage.c,v $ 53 54 $Author: D.Krueger $ 55 56 $Revision: 1.7 $ $Date: 2008/11/13 17:13:09 $ 57 58 $State: Exp $ 59 60 Build Environment: 61 GCC V3.4 62 63 ------------------------------------------------------------------------- 64 65 Revision History: 66 67 2006/10/10 d.k.: start of the implementation, version 1.00 68 69****************************************************************************/ 70 71#include "Epl.h" 72 73#include <linux/uaccess.h> 74 75/***************************************************************************/ 76/* */ 77/* */ 78/* G L O B A L D E F I N I T I O N S */ 79/* */ 80/* */ 81/***************************************************************************/ 82 83//--------------------------------------------------------------------------- 84// const defines 85//--------------------------------------------------------------------------- 86 87//--------------------------------------------------------------------------- 88// local types 89//--------------------------------------------------------------------------- 90 91//--------------------------------------------------------------------------- 92// modul globale vars 93//--------------------------------------------------------------------------- 94 95//--------------------------------------------------------------------------- 96// local function prototypes 97//--------------------------------------------------------------------------- 98 99/***************************************************************************/ 100/* */ 101/* */ 102/* C L A S S EplApi */ 103/* */ 104/* */ 105/***************************************************************************/ 106// 107// Description: 108// 109// 110/***************************************************************************/ 111 112//=========================================================================// 113// // 114// P R I V A T E D E F I N I T I O N S // 115// // 116//=========================================================================// 117 118//--------------------------------------------------------------------------- 119// const defines 120//--------------------------------------------------------------------------- 121 122//--------------------------------------------------------------------------- 123// local types 124//--------------------------------------------------------------------------- 125 126#if ((EPL_API_PROCESS_IMAGE_SIZE_IN > 0) || (EPL_API_PROCESS_IMAGE_SIZE_OUT > 0)) 127typedef struct { 128#if EPL_API_PROCESS_IMAGE_SIZE_IN > 0 129 u8 m_abProcessImageInput[EPL_API_PROCESS_IMAGE_SIZE_IN]; 130#endif 131#if EPL_API_PROCESS_IMAGE_SIZE_OUT > 0 132 u8 m_abProcessImageOutput[EPL_API_PROCESS_IMAGE_SIZE_OUT]; 133#endif 134 135} tEplApiProcessImageInstance; 136 137//--------------------------------------------------------------------------- 138// local vars 139//--------------------------------------------------------------------------- 140 141static tEplApiProcessImageInstance EplApiProcessImageInstance_g; 142#endif 143 144//--------------------------------------------------------------------------- 145// local function prototypes 146//--------------------------------------------------------------------------- 147 148//=========================================================================// 149// // 150// P U B L I C F U N C T I O N S // 151// // 152//=========================================================================// 153 154//--------------------------------------------------------------------------- 155// 156// Function: EplApiProcessImageSetup() 157// 158// Description: sets up static process image 159// 160// Parameters: (none) 161// 162// Returns: tEplKernel = error code 163// 164// 165// State: 166// 167//--------------------------------------------------------------------------- 168 169tEplKernel EplApiProcessImageSetup(void) 170{ 171 tEplKernel Ret = kEplSuccessful; 172#if ((EPL_API_PROCESS_IMAGE_SIZE_IN > 0) || (EPL_API_PROCESS_IMAGE_SIZE_OUT > 0)) 173 unsigned int uiVarEntries; 174 tEplObdSize ObdSize; 175#endif 176 177#if EPL_API_PROCESS_IMAGE_SIZE_IN > 0 178 uiVarEntries = EPL_API_PROCESS_IMAGE_SIZE_IN; 179 ObdSize = 1; 180 Ret = EplApiLinkObject(0x2000, 181 EplApiProcessImageInstance_g. 182 m_abProcessImageInput, &uiVarEntries, &ObdSize, 183 1); 184 185 uiVarEntries = EPL_API_PROCESS_IMAGE_SIZE_IN; 186 ObdSize = 1; 187 Ret = EplApiLinkObject(0x2001, 188 EplApiProcessImageInstance_g. 189 m_abProcessImageInput, &uiVarEntries, &ObdSize, 190 1); 191 192 ObdSize = 2; 193 uiVarEntries = EPL_API_PROCESS_IMAGE_SIZE_IN / ObdSize; 194 Ret = EplApiLinkObject(0x2010, 195 EplApiProcessImageInstance_g. 196 m_abProcessImageInput, &uiVarEntries, &ObdSize, 197 1); 198 199 ObdSize = 2; 200 uiVarEntries = EPL_API_PROCESS_IMAGE_SIZE_IN / ObdSize; 201 Ret = EplApiLinkObject(0x2011, 202 EplApiProcessImageInstance_g. 203 m_abProcessImageInput, &uiVarEntries, &ObdSize, 204 1); 205 206 ObdSize = 4; 207 uiVarEntries = EPL_API_PROCESS_IMAGE_SIZE_IN / ObdSize; 208 Ret = EplApiLinkObject(0x2020, 209 EplApiProcessImageInstance_g. 210 m_abProcessImageInput, &uiVarEntries, &ObdSize, 211 1); 212 213 ObdSize = 4; 214 uiVarEntries = EPL_API_PROCESS_IMAGE_SIZE_IN / ObdSize; 215 Ret = EplApiLinkObject(0x2021, 216 EplApiProcessImageInstance_g. 217 m_abProcessImageInput, &uiVarEntries, &ObdSize, 218 1); 219#endif 220 221#if EPL_API_PROCESS_IMAGE_SIZE_OUT > 0 222 uiVarEntries = EPL_API_PROCESS_IMAGE_SIZE_OUT; 223 ObdSize = 1; 224 Ret = EplApiLinkObject(0x2030, 225 EplApiProcessImageInstance_g. 226 m_abProcessImageOutput, &uiVarEntries, &ObdSize, 227 1); 228 229 uiVarEntries = EPL_API_PROCESS_IMAGE_SIZE_OUT; 230 ObdSize = 1; 231 Ret = EplApiLinkObject(0x2031, 232 EplApiProcessImageInstance_g. 233 m_abProcessImageOutput, &uiVarEntries, &ObdSize, 234 1); 235 236 ObdSize = 2; 237 uiVarEntries = EPL_API_PROCESS_IMAGE_SIZE_OUT / ObdSize; 238 Ret = EplApiLinkObject(0x2040, 239 EplApiProcessImageInstance_g. 240 m_abProcessImageOutput, &uiVarEntries, &ObdSize, 241 1); 242 243 ObdSize = 2; 244 uiVarEntries = EPL_API_PROCESS_IMAGE_SIZE_OUT / ObdSize; 245 Ret = EplApiLinkObject(0x2041, 246 EplApiProcessImageInstance_g. 247 m_abProcessImageOutput, &uiVarEntries, &ObdSize, 248 1); 249 250 ObdSize = 4; 251 uiVarEntries = EPL_API_PROCESS_IMAGE_SIZE_OUT / ObdSize; 252 Ret = EplApiLinkObject(0x2050, 253 EplApiProcessImageInstance_g. 254 m_abProcessImageOutput, &uiVarEntries, &ObdSize, 255 1); 256 257 ObdSize = 4; 258 uiVarEntries = EPL_API_PROCESS_IMAGE_SIZE_OUT / ObdSize; 259 Ret = EplApiLinkObject(0x2051, 260 EplApiProcessImageInstance_g. 261 m_abProcessImageOutput, &uiVarEntries, &ObdSize, 262 1); 263#endif 264 265 return Ret; 266} 267 268//---------------------------------------------------------------------------- 269// Function: EplApiProcessImageExchangeIn() 270// 271// Description: replaces passed input process image with the one of EPL stack 272// 273// Parameters: pPI_p = input process image 274// 275// Returns: tEplKernel = error code 276// 277// State: 278//---------------------------------------------------------------------------- 279 280tEplKernel EplApiProcessImageExchangeIn(tEplApiProcessImage *pPI_p) 281{ 282 tEplKernel Ret = kEplSuccessful; 283 284#if EPL_API_PROCESS_IMAGE_SIZE_IN > 0 285 copy_to_user(pPI_p->m_pImage, 286 EplApiProcessImageInstance_g.m_abProcessImageInput, 287 min(pPI_p->m_uiSize, 288 sizeof(EplApiProcessImageInstance_g. 289 m_abProcessImageInput))); 290#endif 291 292 return Ret; 293} 294 295//---------------------------------------------------------------------------- 296// Function: EplApiProcessImageExchangeOut() 297// 298// Description: copies passed output process image to EPL stack. 299// 300// Parameters: pPI_p = output process image 301// 302// Returns: tEplKernel = error code 303// 304// State: 305//---------------------------------------------------------------------------- 306 307tEplKernel EplApiProcessImageExchangeOut(tEplApiProcessImage *pPI_p) 308{ 309 tEplKernel Ret = kEplSuccessful; 310 311#if EPL_API_PROCESS_IMAGE_SIZE_OUT > 0 312 copy_from_user(EplApiProcessImageInstance_g.m_abProcessImageOutput, 313 pPI_p->m_pImage, 314 min(pPI_p->m_uiSize, 315 sizeof(EplApiProcessImageInstance_g. 316 m_abProcessImageOutput))); 317#endif 318 319 return Ret; 320} 321 322//=========================================================================// 323// // 324// P R I V A T E F U N C T I O N S // 325// // 326//=========================================================================// 327 328// EOF