简体   繁体   English

在Linux内核和用户空间/ MCU之间共享代码

[英]Sharing code between Linux kernel and userspace/MCU

I have a Linux driver for an external MCU application. 我有一个用于外部MCU应用程序的Linux驱动程序。 The driver and the MCU communicate over a bus using our own protocol. 驱动程序和MCU使用我们自己的协议通过总线进行通信。

I would like to share the program code for the protocol features between the kernel module and the MCU but since it's not possible to build a lib for the kernel my only idea so far is to write the code "as kernel as possible" and then just copy the entire .c file between the platforms. 我想在内核模块和MCU之间共享协议功能的程序代码,但是由于无法为内核构建库,到目前为止,我唯一的想法是“尽可能多地编写代码”,然后在平台之间复制整个.c文件。

Are there any other ways? 还有其他方法吗? Surly I can't be the first to want to do this. 当然,我不能成为第一个这样做的人。

I'm talking about code reuse, not IPC mechanisms. 我说的是代码重用,而不是IPC机制。

Thanks! 谢谢!

It requires some hardware abstraction so the code implementing the protocol needs to be generic as possible not requiring any hardware specific details. 它需要一些硬件抽象,因此实现该协议的代码需要尽可能通用,而不需要任何硬件特定的细节。 The file implementing the protocol could have functions like init, exit, read, write and interrupt. 实现该协议的文件可以具有诸如init,exit,read,write和interrupt之类的功能。 The hardware implementation itself (gpio, memory, bus) can be accessed through function pointers which are registered at time when calling the init function. 硬件实现本身(gpio,内存,总线)可以通过调用init函数时注册的函数指针进行访问。 The directory structure can be set up like @smbear suggested 可以像建议@smbear一样设置目录结构

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM