module ZephRay;

今朝有鱼今朝摸

Category

  • 摄影
  • 玩机
  • 硬件坑
  • 翻译
  • 软件坑
  • 随记

Tags

  • LCD
  • 点屏
  • 单片机
  • 计算器
  • 事
  • FPGA
  • STM32
  • 摄影
  • 古董
  • 测评
  • Verilog
  • 笔记本
  • 改造
  • 树莓派
  • 移植
  • Linux
  • ARM
  • nspire
  • 教程
  • 小动物
  • 景
  • 项目
  • GameBoy
  • EPD
  • LED
  • ThinkPad
  • 3DS
  • HP
  • 晒机
  • SDL
  • IBM
  • 82ES
  • Kindle
  • Minecraft
  • Assembly
  • 花
  • 仙剑奇侠传
  • 手办
  • Chiptune
  • 贴图
  • EL
  • 演讲
  • NDSL
  • Nikon

Recent replies

  • 朱寅翚 发表于「Kindle Paperwhite 2 强行救砖(1)」
  • 朱寅翚 发表于「Kindle Paperwhite 2 强行救砖(1)」
  • jcyfkimi 发表于「日常点屏[27]: LAEL320.256-6C」
  • hzy 发表于「IBM ThinkPad 560E (Type 2640) 简单展示」
  • 城市猎人 发表于「IBM ThinkPad 560E (Type 2640) 简单展示」
  • imbushuo 发表于「About Me」
  • 070 发表于「古董电脑选型」
  • Thermit 发表于「About Me」
  • 盛崖鱼 发表于「About Me」
  • Wenting Zhang 发表于「About Me」

My

RSS (中文优先)
RSS (English preferred)

坑 / Projects
关于我 / About
简历 / CV
破烂采购计划 / Craplist
古董电脑选型
SM83(GB CPU)指令编码
Linux PI 1M位跑分
Coremark跑分
音质参考

淘宝杂货铺
Bilibili空间
GitHub

Links

cnVintage古董电子论坛
cnCalc计算器论坛

Keshuai Xu
>Lithia's Core
ntzyz's space
丘丘塔台
tonoko.moe
kasora's blog
447f.Misaka
paizhang.info
spinmry实验室
电子考古学
Hikari Calyx Tech.
春上冰月的博客
业余无线电台 BD4SUR
FindHao
Test2g
Shell Bin
LEAFER x LAB
标签:Verilog

Pano Logic G1 (3) - UART & Hard fault

2019 年 3 月 26 日分类:硬件坑#FPGA#Verilog
Hint: this post is also available in Chinese.

It has been a while since my last update. I have been working on the USB stuff for Pano Logic G1, mainly for connecting to joysticks and flash drives. I was concerned that my LPDDR and cache would cause me some trouble when the code is being executed in RAM, but so far they are holding up well. I will talk more about them in the next log. In this log I would like to talk a little about some debugging utilites, namely, the UART and the hard fault.

UART

UART is very handy when you want to see logs from the device. At first I thought I can get away just by using VGA text terminal, but it soon turns out that 80x30 text is simply not enough. Unfortunately the Pano Logic doesn't have any serial ports. From the schematics, it seems that they originally have one, but was removed after some revisions. But anyway, I have to repurpose the IOs to create myself a serial port to use.

This is not new to Pano Logic, Skip Hansen from PanoMan project has already done this: he soldered a wire to the LED pin and get the serial output from there. For me, as mentioned in one previous log, I do not have soldering iron with me currently, so I need to find some other way.

As an alternate, I used the wire clip come with my logic analyzer. They can be attached to through-hole components easily, such as this VGA connector.

I am using VGA SCL pin for the serial port. I wrote an extremely simple UART transmitter to transfer the data: https://github.com/zephray/VerilogBoy/blob/refactor/target/panog1/fpga/simple_uart.v. Why I don't just use Skip's UART transmitter core for Pano Logic G1? Or why I don't just work on top of Tom and Skip's project? Well, the (stupid) answer is the same regarding why I picked PicoRV32 rather than VexRiscv: I have decided (long ago) to call this project VerilogBoy, so all the source code should be written in Verilog, not SpinalHDL. Yes I am also aware there are tons of better open-source UART controller written in Verilog available online. I am probably just too lazy to find one considering I don't need other fancy functions anyway.

MORE

Pano Logic G1 (2) - Cache

2019 年 3 月 2 日分类:硬件坑#FPGA#Verilog
Hint: this post is also available in Chinese.

As one of the conclusion of the last log, in order to use the LPDDR memory in 32-bit mode on the Pano Logic G1, a cache is almost a must. Sure I can just use 16-bit mode, half the capacity (16 MB) isn't really an issue for me... But I still decided to just implement a cache, it shouldn't be that hard.

So, as a result, I have got cache working on Pano Logic G1. It is a 8-KBytes 2-way set-associative cache. Replacement policy is LRU and write policy is write back. (The whole point of having a cache is because write through is almost impossible given the data mask cannot be used.) It is connected between the PicoRV32 CPU and the MIG memory controller, so all read and writes to the LPDDR is cached. I won't go into details about the cache since I feel like there is nothing special worth talking about except being slow and inefficient. I will add an bus master arbiter between the PicoRV32 and the cache in the future, so the GameBoy CPU could access the LPDDR as well. Though one need to keep in mind this is only a 2-way set-associative cache, having multiple masters would lead to very questionable performance.

So, what about the performance? Currently:

  • Read hit: 2 cycles
  • Write hit: 2 cycles
  • Read miss: 4 cycles + memory read latency
  • Write miss: 5 cycles + memory read latency
  • Read miss + flush: 12 cycles + memory write latency + memory read latency
  • Write miss + flush: 13 cycles + memory write latency + memory read latency

So you can see.. The cost of missing is high, and the cost of flush is very high.

Also, due to my bad coding and the limitation of Spartan-3E's block RAM (it does not support byte enable, which is important for a cache that allows byte enable), compared to 16-bit non-cached version, the whole design uses 1500 more LUTs. I assume mostly comes from the cache, and some from the 32-bit memory controller.

But anyway... It Works™.

MORE

Pano Logic G1 (1) - LPDDR

2019 年 2 月 25 日分类:硬件坑#Verilog#FPGA
Hint: this post is also available in Chinese.

Remember that WIP #LetsDriveLCD? I am still having some trouble with the MIPI-DSI, and that's part of the VerilogBoy project. Currently I do not have access to any soldering tools, so the plan of making a new revision of prototype need to be postponed. In the meanwhile, I thought it might be a good idea to continue working on the RTL – I started refactoring the code but haven't finished yet. But, I need a hardware platform to test. Well, I forgot to bring my FPGA development board (Xilinx ML505, I really loved that board) with me when I came back from Christmas holiday… But no problem, I got myself two Pano Logic thin clients (G1 and G2) last year. Though I have to admit, I didn't do much with these units after I got them. Now the time has come, let's take a look.

We have something to hack

In case you are not familiar with them, let me introduce them first. They were originally thin clients, used to connect to remote desktop servers. What is special about Pano boxes are, they are powered by FPGAs, rather than ARM or x86 CPUs commonly found on a thin client. They advertise it being a “Zero Client”, means there is no (zero) software running on the client. Well, unfortunate for them, they went bankruptcy in 2013. What is fortunate for us is that, these units now become useless for companies originally bought them, being sold for very low price on places like eBay. It is our turn to repurpose these devices! Of course, hackaday has already featured it for several times:

  • Ask Hackaday: We might have some FPGAs to hack
  • Racing the Beam on a Thin Client, in FPGAs
  • Pac-Man Fever Comes to the Pano Logic FPGA
  • Two Joysticks Talk To FPGA Arcade Game Over A VGA Cable

1551068560833-rear.jpg

As far as I know, there are 3 generations of Pano Logic clients, the first two looks very similar, and the third is slimmer. Unfortunately I have never seen a slim model on the eBay. If you know anything about the slim model, please tell me, I am interested. The first generation (G1) model is powered by a Xilinx Spartan-3E XC3S1600E FPGA (1600K system gates, translate to around 30K LUT4s.), with 32MB of on-board LPDDR RAM. The second generation model, depending on the revision, is either powered by a Xilinx Spartan-6 XC6SLX150 (Rev. B) or Xilinx Spartan-6 XC6SLX100 (Rev. C), both with 128MB of DDR3 memory. The one I own is a Rev. C one. Both generations has already been reversed engineered by the community, notably cyrozap, twj42, and Tom Verbeure. You may find more information about details of the Pano boxes here: https://github.com/tomverbeure/panologic, and https://github.com/tomverbeure/panologic-g2.

MORE

写给玩家的FPGA入门指南(6)——Verilog(下)

2019 年 2 月 24 日分类:硬件坑#FPGA#Verilog#教程

本期,我们将继续讲解之前没有讲完的Verilog代码。上一期的教程已经介绍了Verilog最核心的一些操作,本期则将介绍一些有用的其它操作,他们最终也可以用核心的操作代码表示出来,但是通常而言编写起来更为简便。本期同样会介绍仿真工具的使用,在开发过程中非常有用。不过在开始新的内容之前,先来讲讲上一次留的作业。

上期练习

上期留了一个作业,就是实现第五期里面讲过的状态机。这里首先复述一下第五期的状态机:假设一个贩卖机,只卖矿泉水,价格定为2元,只接受1元硬币或者5角硬币,多不找零,设计一个状态机来描述它的行为。这个机器的话,它有两个输入,投入5角或者投入1元;以及一个输出,是否已经付了足够多的钱。

如同之前一样,假设表示投入5角硬币的信号叫a,表示投入1元硬币的信号叫b,输出是否已经付够钱的信号叫c。同时定义这个系统有S0-S4一共5个状态,分别表示当时已经投入了0、0.5、1、1.5和2元。

要用Verilog来实现这个状态,第一步肯定是先写一个整体的模块框架,再往里面加入东西。于是参考上期的声明module的方法,先写下如下的代码:

module vending(
    input clk,
    input rst,
    input a,
    input b,
    output c);

endmodule

上面的代码定义了一个叫vending的模块,有四个输入,clk、rst、a和b,一个输出c,主体没有内容。clk提供时钟,rst提供复位。首先来考虑输出吧。状态机的输出是由当前状态决定的,所以需要有一个变量(触发器)来保存当前的状态,比如叫做state:

reg [2:0] state;

有了state之后就可以描述输出的逻辑了。一种方法是直接用第五期的逻辑表达式:

assign c = state[2] && !state[1] && !state[0];
MORE

写给玩家的FPGA入门指南(5)——Verilog(上)

2019 年 1 月 7 日分类:硬件坑#FPGA#Verilog#教程

首先,恭喜大家,一直跟到了这个教程的第五期。如之前所说,从本期开始,我们将正式开始使用Verilog给FPGA写代码。而要写的东西,这是第2-4期里面介绍过的组合逻辑,时序逻辑和状态机。而Verilog也将会是在这之后用于描述各种硬件的语言。

其实读Verilog代码本身并不复杂,有软件编程经验的人就不难理解代码的含义,毕竟其语法和C语言很接近;但是写Verilog代码,就是另外一回事了。Verilog里面有很多和C接近的概念和语句,比如赋值,比如if-else,比如for循环,等等。但是Verilog的目标结果,逻辑门,却又和C的目标结果,程序,太不一样了。他们确实某种程度上是接近的语言,但是语言里有接近的东西并不表示他们就能实现接近的功能。或者反过来,想要实现同样的功能,未必会使用接近的方法。所以说,学习Verilog最好的捷径就是不要走捷径,从数字电路开始学习,而并非一开始就学习代码,以至于被代码所迷惑。

Verilog程序模块

Verilog程序如同其它的编程语言程序一样,有它特定的源文件格式。Verilog的源代码后缀名为.v,每一个Verilog文件都是一个Verilog模块,各位可以类比为编程语言中的函数。基本格式如下:

module 模块名(模块输入输出信号);
    模块内容
endmodule

其中这个模块名通常需要和对应的文件名相同,同一个文件只定义一个模块,比如adder.v里就应该只定义一个叫adder的模块。这个要求和Java对类的要求很相似。

输入输出信号则是接近一个函数的返回值和参数,只不过在Verilog里并不把参数和返回值放到不同的地方定义,而是都写在一起。所有的参数或者返回值,最终都只是导线而已。而导线根据驱动信号的方向,可以有输入和输出区别。至于需要多少个输入多少个输出,那就取决于具体的程序了。

模块内容则是模块内部的逻辑,也许有代码块(always),也许只是一些简单的接线(assign)。不过别忘了,一切最后都会回归到硬件。

最后说说模块的实例化,或者说调用。如前面所说,模块类似于软件编程语言里面的函数,它也确实有对应的函数名,参数,返回值等等类似的概念。那么要使用这个“函数”,自然也就需要一种调用的方法。只不过,Verilog里的调用,并不是像编程语言一样在特定位置执行特定代码(毕竟本身就没有“执行代码”这种操作),而是新复制一份这个模块所表示的硬件,然后连接对应的导线。这一点在参数的定义时其实也就有所体现,定义的输入输出并非是变量,而是导线, 也就是说,传递的内容并不是数值,而是连接。一旦连接被确定,传输就是时时进行的(因为线被连接上了)。这个和编程语言里的调用非常不一样,所以务必进行区分。具体的例子我们之后就会提到。

MORE
  • «
  • 1
  • 2
  • 3
  • »
Copyright © 2009-2019 Wenting Zhang. All rights reserved.
Unless otherwise noted, content on this blog is licensed under CC BY-SA 4.0.