IgH EtherCAT Master  1.7.0
sii_page.c
Go to the documentation of this file.
1/*****************************************************************************
2 *
3 * Copyright (C) 2026 Florian Pose, Ingenieurgemeinschaft IgH
4 *
5 * This file is part of the IgH EtherCAT Master.
6 *
7 * The IgH EtherCAT Master is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License version 2, as
9 * published by the Free Software Foundation.
10 *
11 * The IgH EtherCAT Master is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
14 * Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with the IgH EtherCAT Master; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 *
20 ****************************************************************************/
21
26
27/****************************************************************************/
28
29#include "sii_page.h"
30
31#include <linux/slab.h>
32
33/****************************************************************************/
34
38
40 ec_sii_page_t *page
41 )
42{
43 page->vendor_id = 0x00000000;
44 page->product_code = 0x00000000;
45 page->revision_number = 0x00000000;
46 page->serial_number = 0x00000000;
47 page->alias = 0x0000;
48
50
51 page->words = NULL;
52 page->word_count = 0;
53}
54
55/****************************************************************************/
56
61
63 ec_sii_page_t *page
64 )
65{
66 if (page->words) {
67 kfree(page->words);
68 }
69}
70
71/****************************************************************************/
72
77 ec_sii_page_t *page,
78 size_t word_count
79 )
80{
81 if (page->words) {
82 kfree(page->words);
83 }
84
85 page->word_count = 0;
86
87 if (!(page->words = (uint16_t *) kmalloc(word_count * 2, GFP_KERNEL))) {
88 return -ENOMEM;
89 }
90
91 page->word_count = word_count;
92 return 0;
93}
94
95/****************************************************************************/
96
101 ec_sii_page_t *page,
102 const ec_sii_page_t *from
103 )
104{
105 int ret;
106
107 page->vendor_id = from->vendor_id;
108 page->product_code = from->product_code;
109 page->revision_number = from->revision_number;
110 page->serial_number = from->serial_number;
111 page->alias = from->alias;
112
113 page->origin = from->origin;
114
115 ret = ec_sii_page_alloc(page, from->word_count);
116 if (ret) {
117 return ret;
118 }
119
120 memcpy(page->words, from->words, page->word_count * 2);
121 return 0;
122}
123
124/****************************************************************************/
void ec_sii_page_init(ec_sii_page_t *page)
SII page constructor.
Definition sii_page.c:39
int ec_sii_page_alloc(ec_sii_page_t *page, size_t word_count)
Free page memory.
Definition sii_page.c:76
int ec_sii_page_copy(ec_sii_page_t *page, const ec_sii_page_t *from)
Copy contents from other page.
Definition sii_page.c:100
void ec_sii_page_clear(ec_sii_page_t *page)
Slave destructor.
Definition sii_page.c:62
EtherCAT SII/Eeprom memory contents.
@ EC_SII_PAGE_UNKNOWN
Information not available.
Definition sii_page.h:38
struct ec_sii_page ec_sii_page_t
Slave information interface memory page.
uint16_t * words
Complete SII image.
Definition sii_page.h:60
uint32_t revision_number
Revision number.
Definition sii_page.h:54
ec_sii_page_origin_t origin
Page origin.
Definition sii_page.h:58
size_t word_count
Size of the SII contents in words.
Definition sii_page.h:61
uint32_t serial_number
Serial number.
Definition sii_page.h:55
uint32_t vendor_id
Vendor ID.
Definition sii_page.h:52
uint16_t alias
Configured station alias.
Definition sii_page.h:56
uint32_t product_code
Vendor-specific product code.
Definition sii_page.h:53