Linux 内核中的硬件时钟信号实现

发布于 2024-11-18 12:04:48 字数 775 浏览 4 评论 0原文

我正在寻找一些指导来了解 Linux 内核如何实现各种硬件时钟的设置。这基本上涉及设置 LCD、UART 等硬件功能将使用的各种时钟。例如,当 Linux 启动时,它如何处理 UART 或 USB 时钟的设置。也许像时钟管理器之类的东西。

我基本上试图在我正在开发的新硬件上为不同的操作系统实现类似的东西。任何帮助将不胜感激。

[编辑]
感谢您的回复和链接。这就是我到目前为止所实施的。这应该能让你知道我要去哪里。

我查找了我所针对的特定系统的硬件参考手册,并编写了一些代码来监视/修改我感兴趣的外设的信号/引脚,即从命令行打开/关闭它们。现在是这些的集合时钟/信号一起控制外设。HRM 会说,如果你想打开 UART 或其他东西,那么就打开这样那样的信号/引脚。 @BjoernD 是的,我正在使用类似 mmap() 函数的东西来与外围设备通信。

我的问题的核心是我想了解时钟/外设管理器的设计和实现,它使用我已经编写的实用程序。这个时钟/外设管理器将使我能够控制启用/禁用我想要的外设。基本上,这个管理器将使我能够对正在运行的初始化代码进行更改。此外,在运行时进程可以调用该管理器来打开/关闭设备,以便优化功耗。这可能不太合理,但我自己正在尝试解决这个问题。

现在我确信类似的东西会在 Linux 中实现,或者在任何操作系统中实现性能问题(没有人愿意在启动时打开所有外围设备来浪费电力)。我想了解它的软件架构。到目前为止,任何操作系统的参考都可以至少获得领先优势。另外,我并不是在编写自己的操作系统,而是有一个操作系统,但我更多地关注的是板级软件(即 BSP)的工作。但无论如何,感谢操作系统链接,它们真的很好。欣赏它。

谢谢!

I am looking at some pointers for understanding how the Linux kernel implements the setting up of various hardware clocks. This basically relates to working with setting up the various clocks that hardware features like the LCD, UART etc will use. For example when Linux boots how does it handle setting up the clocks for UART or USB. Maybe something like a Clock manager or something.

I am basically trying to implement something similar for a different OS on a new hardware that i am working on. Any help would be really appreciated.

[Edit]
Thanks for the replies and the links. So here is what i have implemented up until now. This should give you an idea of where I'm headed.

I looked up the Hardware Reference Manual for the particular system I'm targeting and wrote some code to monitor/modify the signals/pins of the peripherals I am interested in i.e. turning them ON/OFF from the command line.Now a collection of these clocks/signals together control a peripheral.The HRM would say that if you want to turn on the UART or something then turn on such and such signals/pins. And @BjoernD yes I am using something like a mmap() function to talk to the peripherals.

The meat of my question is that I want to understand the design and implementation of a Clock/Peripheral Manager which uses the utility that I have already written. This Clock/Peripheral Manager would give me the control of enabling/disabling the peripherals I want.Basically this Manager would enable me to make changes in the init code that is right now running. Also during run time processes can call this Manager to turn ON/OFF the devices so that power consumption is optimized. It might not have made perfect sense but I'm myself trying to wrap my head around this.

Now I'm sure something like this would have been implemented in Linux or for that matter any OS for performance issues (nobody would want to waste power by turning on all peripherals at boot time). I want to understand the Software Architecture of it. Reference from any OS would do as of now to atleast get a headstart. Also I am not writing my own OS, there is an OS in place but Im looking more at a board level software aka BSP to work on. But thanks for the OS link anyways, they are really good. Appreciate it.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

痴梦一场 2024-11-25 12:04:48

您想要实现的目标与 a) 您正在使用的平台和 b) 您想要使用的设备高度相关。例如,在 x86 上,有 3 种与设备通信的方式:

  1. 中断允许设备向 CPU 发送信号。操作系统通常提供注册中断处理程序的机制 - 发生中断时调用的函数。在 Linux 中,请参阅 request_irq() 和 linux/include/interrupt.h 中的朋友。
  2. 内存映射 I/O 是平台 BIOS 提供的设备的物理内存,与访问普通物理内存的方式相同 - 只需写入内存地址。此类存储器的具体内容(例如,网络接口配置寄存器或 LCD 帧缓冲区)取决于设备,并且通常在设备的数据表中指定。
  3. I/O 端口通过特殊地址空间和特殊指令(INB/OUTB & co.)进行访问。除此之外,它们的工作方式与 I/O 内存类似。

有多种方法可以查明设备提供哪些资源以及 BIOS 将它们映射到何处。一些平台使用 ACPI 表(自行 google 查找 1,000k 页规范),PCI 通过 PCI 配置空间以标准化方式提供设备信息,USB 具有类似的方式来发现连接到总线的设备,以及一些设备,例如 UARTS ,只是指定为在针对您的平台固定的预配置 I/O 范围内可用。

作为了解 Linux 的开始,我建议“了解 Linux 内核”。有关 Linux 如何处理设备以及如何编写驱动程序的详细信息,请查看 Linux 设备驱动程序。此外,您需要了解您的平台和您想要驱动的设备的特性。

如果您想启动自己的操作系统,那么 UART 对于打印调试输出肯定非常有帮助,因此您可能想首先使用它。

既然我写下了所有这些,看来您真正的问题是:如何开始操作系统设计。这个问题对您来说应该非常有价值:有哪些入门资源操作系统开发?

What you want to achieve is highly specific to a) the platform you are using and b) the device you want to use. For instance, on x86 there are 3 ways to communicate with a device:

  1. Interrupts allow the device to signal the CPU. The OS usually provides mechanisms to register interrupt handlers - functions that are called upon occurrence of an interrupt. In Linux see request_irq() and friends in linux/include/interrupt.h
  2. Memory-mapped I/O is physical memory of the device that the platform's BIOS makes available in the same way you also access plain physical memory - simply by writing to a memory address. What exactly is behind such memory (e.g., network interface config registers or an LCD frame buffer) depends on the device and is usually specified in the device's data sheet.
  3. I/O ports are accessed through a special address space and special instructions (INB/OUTB & co.). Other than that they work similar to I/O memory.

There's a multitude of ways to find out what resources a device provies and where the BIOS mapped them. Some platforms use ACPI tables (google yourself for the 1,000k page spec), PCI provides info on devices in a standardized way through the PCI config space, USB has similar ways of discovering devices attached to the bus, and some devices, e.g., UARTS, are simply specified to be available at a pre-configured I/O range that is fixed for your platform.

As a start for understanding Linux, I'd recommend "Understanding the Linux kernel". For specifics on how Linux handles devices and what is there to write drivers, have a look at Linux Device Drivers. Furthermore, you will need to have a look at the peculiarities of your platform and the device you want to drive.

If you want to start an own OS, a UART is certainly something that will be veeery helpful to print debug output, so you might want to go for this first.

Now that I wrote down all this, it seems that your actual question is: How to get started with Operating System design. This question should be highly valuable for you: What are some resources for getting started in operating system development?

你的心境我的脸 2024-11-25 12:04:48

大多数计算机中的两个重要用户是 CPU 和磁盘。这两者都具有 Linux 中的节能功能。当系统不忙时,CPU 时钟可以减慢,当没有 I/O 发生时,磁盘电机可以停止。对于 UART,即使您通过关闭时钟来节省其使用的所有电量,与其他 UART 相比,它仍然很小,因为 UART 中没有太多逻辑。

节省电力的最佳方法是
1)更高效的供电
2)用SSD替换旋转盘
3)减慢CPU和内存总线的速度

The two big power users in most computers are the CPU and the disks. Both of these have capabilities for power saving in Linux. The CPU clock can be slowed down when the system is not busy, and the disk motors can be stopped when no I/O is happening. For a UART, even if you save all of the power that it uses by turning off its clock, it is still tiny compared to the others because a UART doesn't have much logic in it.

Best ways to save power are
1) more efficient power supply
2) replace rotating disk with SSD
3) Slow down the CPU and memory bus

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文