drivers/comedi/drivers/ni_routing/tools/convert_csv_to_c.py
Source file repositories/reference/linux-study-clean/drivers/comedi/drivers/ni_routing/tools/convert_csv_to_c.py
File Facts
- System
- Linux kernel
- Corpus path
drivers/comedi/drivers/ni_routing/tools/convert_csv_to_c.py- Extension
.py- Size
- 16094 bytes
- Lines
- 497
- Domain
- Driver Families
- Bucket
- drivers/comedi
- Inferred role
- Driver Families: drivers/comedi
- Status
- atlas-only
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
ni_device_routes.h{extern_h}../ni_device_routes.hni_route_values.h../ni_route_values.h
Detected Declarations
struct ni_device_routesfunction c_to_o
Annotated Snippet
struct ni_device_routes {table_name} = {{\
"""
def __init__(self, pattern='csv/device_routes/*.csv'):
super(DeviceRoutes,self).__init__(pattern)
def to_listinit(self):
chunks = [ self.output_file_top,
'',
'struct ni_device_routes *const ni_device_routes_list[] = {'
]
# put the sheets in lexical order of device numbers then bus
sheets = sorted(self.items(), key=lambda i : tuple(i[0].split('-')[::-1]) )
externs = []
objs = [c_to_o(self.SET_C)]
for sheet,D in sheets:
S = sheet.lower()
dev_table_name = 'ni_{}_device_routes'.format(S.replace('-','_'))
sheet_filename = os.path.join(self.ITEMS_DIR,'{}.c'.format(S))
externs.append('extern struct ni_device_routes {};'.format(dev_table_name))
chunks.append('\t&{},'.format(dev_table_name))
s_chunks = [
self.single_output_file_top.format(
filename = sheet_filename,
table_name = dev_table_name,
extern_h = self.EXTERN_H,
),
routedict_to_routelist_single(S, D),
'};',
]
objs.append(c_to_o(sheet_filename))
with open(os.path.join(self.OUTPUT_DIR, sheet_filename), 'w') as f:
f.write('\n'.join(s_chunks))
f.write('\n')
with open(os.path.join(self.OUTPUT_DIR, self.MKFILE_SEGMENTS), 'w') as f:
f.write('# This is the segment that should be included in comedi/drivers/Makefile\n')
f.write('ni_routing-objs\t\t\t\t+= \\\n')
f.write('\n'.join(objs))
f.write('\n')
EXTERN_H = os.path.join(self.ITEMS_DIR, self.EXTERN_H)
with open(os.path.join(self.OUTPUT_DIR, EXTERN_H), 'w') as f:
f.write(self.extern_header.format(
filename=EXTERN_H, externs='\n'.join(externs)))
chunks.append('\tNULL,') # terminate list
chunks.append('};')
return '\n'.join(chunks)
def save(self):
filename=os.path.join(self.OUTPUT_DIR, self.SET_C)
try:
os.makedirs(os.path.join(self.OUTPUT_DIR, self.ITEMS_DIR))
except:
pass
with open(filename,'w') as f:
f.write( self.to_listinit() )
f.write( '\n' )
class RouteValues(CSVCollection):
MKFILE_SEGMENTS = 'route-values.mk'
Annotation
- Immediate include surface: `ni_device_routes.h`, `{extern_h}`, `../ni_device_routes.h`, `ni_route_values.h`, `../ni_route_values.h`.
- Detected declarations: `struct ni_device_routes`, `function c_to_o`.
- Atlas domain: Driver Families / drivers/comedi.
- Implementation status: atlas-only.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.