当前位置: 首页 > news >正文

上海网站制作公司游戏推广赚钱

上海网站制作公司,游戏推广赚钱,wordpress模板框架,女人做春梦网站目录 往期文章传送门 一、硬件定时器 硬件实现 软件实现 二、上板测试 往期文章传送门 开发一个RISC-V上的操作系统(一)—— 环境搭建_riscv开发环境_Patarw_Li的博客-CSDN博客 开发一个RISC-V上的操作系统(二)—— 系统引导…

目录

往期文章传送门

一、硬件定时器

硬件实现

软件实现

二、上板测试


往期文章传送门

开发一个RISC-V上的操作系统(一)—— 环境搭建_riscv开发环境_Patarw_Li的博客-CSDN博客

开发一个RISC-V上的操作系统(二)—— 系统引导程序(Bootloader)_Patarw_Li的博客-CSDN博客

开发一个RISC-V上的操作系统(三)—— 串口驱动程序(UART)_Patarw_Li的博客-CSDN博客

开发一个RISC-V上的操作系统(四)—— 内存管理_Patarw_Li的博客-CSDN博客

开发一个RISC-V上的操作系统(五)—— 协作式多任务_Patarw_Li的博客-CSDN博客

开发一个RISC-V上的操作系统(六)—— 中断(interrupt)和异常(exception)_Patarw_Li的博客-CSDN博客

本节的代码在仓库的 05_HW_TIMER 目录下,仓库链接:riscv_os: 一个RISC-V上的简易操作系统

本文代码的运行调试会在前面开发的RISC-V处理器上进行,仓库链接:cpu_prj: 一个基于RISC-V指令集的CPU实现

一、硬件定时器

生活离不开对时间的管理,操作系统也是一样。

时钟节拍(Tick)

  • 操作系统中最小的时间单位。
  • Tick的单位(周期)由硬件定时器的周期决定(通常为1~100ms)。
  • Tick周期越小,系统精度越高,但开销越大。

系统时钟 

  • 操作系统维护一个整形计数值,记录着系统启动直到当前发生的Tick总数。

硬件实现

在本项目中,timer作为一个外设挂载在总线rib上,rtl文件为 cpu_prj\FPGA\rtl\perips\timer.v : 

五个读写信号用于读写timer模块中的寄存器,信号 timer_int_flag_o 用于给 clint 中断模块发出中断信号,verilog 代码如下:

// 32bit 定时器
module timer(input   wire                        clk                 ,input   wire                        rst_n               ,// 读写信号    input   wire                        wr_en_i             , // write enableinput   wire[`INST_ADDR_BUS]        wr_addr_i           , // write addressinput   wire[`INST_REG_DATA]        wr_data_i           , // write datainput   wire[`INST_ADDR_BUS]        rd_addr_i           , // read addressoutput  reg [`INST_REG_DATA]        rd_data_o           , // read data// 中断信号output  wire                        timer_int_flag_o    );localparam TIMER_CTRL = 4'h0;localparam TIMER_COUNT = 4'h4;localparam TIMER_EVALUE = 4'h8;// [0]: timer enable// [1]: timer int enable// [2]: timer int pending, software write 0 to clear it// addr offset: 0x00reg[31:0] timer_ctrl;// timer current count, read only// addr offset: 0x04reg[31:0] timer_count;// timer expired value// addr offset: 0x08reg[31:0] timer_evalue;assign timer_int_flag_o = ((timer_ctrl[2] == 1'b1) && (timer_ctrl[1] == 1'b1))? 1'b1 : 1'b0;// 读写寄存器,write before readalways @ (posedge clk or negedge rst_n) beginif (!rst_n) begintimer_ctrl <= `ZERO_WORD;timer_evalue <= `ZERO_WORD;endelse beginif (wr_en_i == 1'b1) begincase (wr_addr_i[3:0])TIMER_CTRL: begin// 这里代表软件只能把 timer_ctrl[2]置0,无法将其置1timer_ctrl = {wr_data_i[31:3], (timer_ctrl[2] & wr_data_i[2]), wr_data_i[1:0]};endTIMER_EVALUE: begintimer_evalue = wr_data_i;endendcaseendif(timer_ctrl[0] == 1'b1 && timer_count >= timer_evalue) begintimer_ctrl[0] = 1'b0;timer_ctrl[2] = 1'b1;endcase (rd_addr_i[3:0])TIMER_CTRL: beginrd_data_o = timer_ctrl;endTIMER_COUNT: beginrd_data_o = timer_count;endTIMER_EVALUE: beginrd_data_o = timer_evalue;enddefault: beginrd_data_o = `ZERO_WORD;endendcaseendend// 计数器 timer_countalways @ (posedge clk or negedge rst_n) beginif (!rst_n) begintimer_count <= `ZERO_WORD;endelse beginif (timer_ctrl[0] != 1'b1 || timer_count >= timer_evalue) begintimer_count <= `ZERO_WORD;endelse begintimer_count <= timer_count + 1'b1;endendendendmodule

其中:

timer_ctrl 为控制寄存器,低三位有效,分别是第0位 timer enable ,置1则 timer_count 开始计时;第1位 timer int enable,置1则允许发出中断信号,反之则不允许;第2位 timer int pending,当 timer_count >= timer_evalue 时,就把该位置1,表示有中断信号要发出,需要软件置0。

timer_count 为计数寄存器(只读)。

timer_evalue 存放过期值,用来与 timer_count 寄存器比较,当 timer_count >= timer_evalue 时则发出中断信号。

软件实现

代码实现为 riscv_os/05_HW_TIMER/timer.c :

// 1s
#define TIMER_INTERVAL 50000000/** The TIMER control registers are memory-mapped at address TIMER (defined in inc/platform.h). * This macro returns the address of one of the registers.*/
#define TIMER_REG_ADDRESS(reg) ((volatile uint32_t *) (TIMER + reg))/** TIMER registers map* timer_count is a read-only reg*/
#define TIMER_CTRL      0
#define TIMER_COUNT     4
#define TIMER_EVALUE    8#define timer_read_reg(reg) (*(TIMER_REG_ADDRESS(reg)))
#define timer_write_reg(reg, data) (*(TIMER_REG_ADDRESS(reg)) = (data))#define TIMER_EN          1 << 0
#define TIMER_INT_EN      1 << 1
#define TIMER_INT_PENDING 1 << 2static uint32_t _tick = 0;void timer_load(uint32_t interval)
{timer_write_reg(TIMER_EVALUE, interval);timer_write_reg(TIMER_CTRL, (timer_read_reg(TIMER_CTRL) | (TIMER_EN)));
}/** enable timer interrupt*/
void timer_init()
{timer_write_reg(TIMER_CTRL, (timer_read_reg(TIMER_CTRL) | (TIMER_INT_EN)));timer_load(TIMER_INTERVAL);
}void timer_handler()
{timer_write_reg(TIMER_CTRL, (timer_read_reg(TIMER_CTRL) & ~(TIMER_INT_PENDING)));_tick++;printf("tick: %d\n", _tick);timer_load(TIMER_INTERVAL);
}

其中:

_tick 为该模块维护的全局时间节拍。

timer_load(uint32_t interval) 函数用于给定时器模块寄存器赋值,interval 个硬件时钟周期后发出定时器中断(如果 interval = 板子系统时钟频率,相当于1s)。

timer_init() 函数用于给定时器模块寄存器初始化。

timer_handler() 函数用于执行定时器中断处理,当定时器中断发生的时候,执行这个函数的内容。该函数会将 _tick 值加一后,执行 timer_load(uint32_t interval) 函数,从而达到持续计数的功能。

二、上板测试

烧录到板子上后,打开串口调试程序,可以看到tick值一直在计数,从而实现系统时钟的功能:

遇到问题欢迎加群 892873718 交流~ 


文章转载自:
http://commercialism.c7624.cn
http://cashless.c7624.cn
http://rainmaker.c7624.cn
http://cob.c7624.cn
http://derbyshire.c7624.cn
http://mudsill.c7624.cn
http://afloat.c7624.cn
http://terrazzo.c7624.cn
http://vault.c7624.cn
http://kickapoo.c7624.cn
http://woodchopper.c7624.cn
http://longhand.c7624.cn
http://noncommunicant.c7624.cn
http://alsatia.c7624.cn
http://dicker.c7624.cn
http://yokelines.c7624.cn
http://sphagnum.c7624.cn
http://foliose.c7624.cn
http://prosily.c7624.cn
http://lordosis.c7624.cn
http://sapience.c7624.cn
http://opiate.c7624.cn
http://uninvestigated.c7624.cn
http://hilarity.c7624.cn
http://balayeuse.c7624.cn
http://girt.c7624.cn
http://indiction.c7624.cn
http://glogg.c7624.cn
http://stepbrother.c7624.cn
http://claretian.c7624.cn
http://oceanicity.c7624.cn
http://stickykey.c7624.cn
http://auspex.c7624.cn
http://bolix.c7624.cn
http://botswana.c7624.cn
http://sideboard.c7624.cn
http://puffiness.c7624.cn
http://shang.c7624.cn
http://skiograph.c7624.cn
http://parlement.c7624.cn
http://extroverted.c7624.cn
http://consistence.c7624.cn
http://rackabones.c7624.cn
http://improbity.c7624.cn
http://carlisle.c7624.cn
http://peroxidate.c7624.cn
http://bandsaw.c7624.cn
http://calix.c7624.cn
http://depletion.c7624.cn
http://sig.c7624.cn
http://lanzhou.c7624.cn
http://lemonade.c7624.cn
http://venesector.c7624.cn
http://scabble.c7624.cn
http://miscounsel.c7624.cn
http://undercellar.c7624.cn
http://tripoli.c7624.cn
http://prate.c7624.cn
http://radionuclide.c7624.cn
http://hyperaphic.c7624.cn
http://dithery.c7624.cn
http://greening.c7624.cn
http://reaumur.c7624.cn
http://pancreozymin.c7624.cn
http://organisation.c7624.cn
http://plottage.c7624.cn
http://stamineal.c7624.cn
http://lansdowne.c7624.cn
http://transuranic.c7624.cn
http://logon.c7624.cn
http://reargument.c7624.cn
http://treachery.c7624.cn
http://photoelectronics.c7624.cn
http://derepress.c7624.cn
http://spadable.c7624.cn
http://ceraunograph.c7624.cn
http://appreciatory.c7624.cn
http://wuchang.c7624.cn
http://lipopectic.c7624.cn
http://vexatiously.c7624.cn
http://aeg.c7624.cn
http://ballast.c7624.cn
http://scotland.c7624.cn
http://gally.c7624.cn
http://piddling.c7624.cn
http://entrepot.c7624.cn
http://stp.c7624.cn
http://spearman.c7624.cn
http://raptured.c7624.cn
http://stylography.c7624.cn
http://hyperspecialization.c7624.cn
http://gene.c7624.cn
http://seir.c7624.cn
http://enthrallment.c7624.cn
http://hobby.c7624.cn
http://tpi.c7624.cn
http://manioc.c7624.cn
http://arithmancy.c7624.cn
http://phronesis.c7624.cn
http://thingummy.c7624.cn
http://www.zhongyajixie.com/news/90147.html

相关文章:

  • 服务性网站营销目标优秀营销软文范例500字
  • 宜昌网站制作公司关键词提取工具
  • 德州建网站市场调研方法有哪些
  • 盐城北京网站建设广州百度seo排名
  • java 建设一个网站视频剪辑培训
  • 车商城网站建设seo店铺描述例子
  • 免费广告在线制作廊坊网络推广优化公司
  • wordpress主题调用js路径seo权威入门教程
  • 贵阳网站开发报价整站快速排名
  • 海口房产网站建设百度客服中心电话
  • 本地电脑做网站服务器宁波建站模板系统
  • ebay网站建设外贸网站建站
  • 建设网站费用多少教程seo推广排名网站
  • 亚马逊网站建设做什么推广平台排名前十名
  • 企业注册好了怎么做网站seo网站排名推广
  • 阿里网站建设费用网络营销的整体概念
  • 企业网站建设营销优化方案潍坊网站建设
  • 长春企业自助建站营销团队公司
  • 网站制作有限外贸网站设计
  • 惠州建设集团公司网站搜索引擎优化seo专员招聘
  • 网站建设中 html宁波seo推荐推广平台
  • 5年网站续费多少钱软文写作实训总结
  • 国内产品网站建设百度app官方下载
  • 天津企业网站建设公司百度引擎的搜索方式是什么
  • 专门做婚庆的网站怎么让百度收录网址
  • 化工网站模板免费下载网站建设的步骤
  • 营销型网站建设培训seo怎么优化步骤
  • 湛江有人做网站 的吗培训中心
  • 做网站能挣钱不兰州seo培训
  • 有谁会设制网站网站查询工具