openMSP430_IO interrupt

Verilog file: omsp_gpio.v

 //============================================================================
// 4) INTERRUPT GENERATION
//============================================================================ // Port 2 interrupt
//------------------ // Delay input // The p2in_dly stores former value of p2in, it will be used for edge detection
reg [:] p2in_dly;
always @ (posedge mclk or posedge puc_rst)
if (puc_rst) p2in_dly <= 'h00;
else p2in_dly <= p2in & P2_EN_MSK; // Edge detection // Now we can detect rising and falling edge easily by combining p2in and p2in_dly
wire [:] p2in_re = p2in & ~p2in_dly;
wire [:] p2in_fe = ~p2in & p2in_dly; // Set interrupt flag // p2ies register decide which edge is interrup signal; p2ifg_set is sent to p2ifg for interrupt flag
assign p2ifg_set = {p2ies[] ? p2in_fe[] : p2in_re[],
p2ies[] ? p2in_fe[] : p2in_re[],
p2ies[] ? p2in_fe[] : p2in_re[],
p2ies[] ? p2in_fe[] : p2in_re[],
p2ies[] ? p2in_fe[] : p2in_re[],
p2ies[] ? p2in_fe[] : p2in_re[],
p2ies[1] ? p2in_fe[] : p2in_re[],
p2ies[] ? p2in_fe[] : p2in_re[]} & P2_EN_MSK; // Generate CPU interrupt // Interrupt is generated when interrupt is enabled and p2ifg (interrupt flag) is available
assign irq_port2 = |(p2ie & p2ifg) & P2_EN[];

  

  Assume  P2_EN is 1'b1, interrupt is enabled(P2IE=1), interrupt edge is rising(P2IES=0), so the code is as following:

 // Delay input
reg [:] p2in_dly;
always @ (posedge mclk or posedge puc_rst)
if (puc_rst) p2in_dly <= 'h00;
else p2in_dly <= p2in; // Edge detection
wire [:] p2in_re = p2in & ~p2in_dly; // Set interrupt flag
assign p2ifg_set = { p2in_re[],
p2in_re[],
p2in_re[],
p2in_re[],
p2in_re[],
p2in_re[],
p2in_re[],
p2in_re[]  }; // Generate CPU interrupt
assign irq_port2 = | p2ifg;

  

  P2IFG register is as following:

 // P2IFG Register
//----------------
reg [:] p2ifg; wire p2ifg_wr = P2IFG[] ? reg_hi_wr[P2IFG] : reg_lo_wr[P2IFG];
wire [:] p2ifg_nxt = P2IFG[] ? per_din[:] : per_din[:];
wire [:] p2ifg_set; always @ (posedge mclk or posedge puc_rst)
if (puc_rst) p2ifg <= 'h00;
else if (p2ifg_wr) p2ifg <= (p2ifg_nxt | p2ifg_set) & P2_EN_MSK;
else p2ifg <= (p2ifg | p2ifg_set) & P2_EN_MSK;

  Assume P2_EN is 1'b1; P2IFG='h2B, so P2IFG[0]=1;  p2ifg_set = 8{1'b1}

   // P2IFG Register
//----------------
reg [:] p2ifg; wire p2ifg_wr = reg_hi_wr[]; // If decoded address is P2IFG, then write it into data
wire [:] p2ifg_nxt = per_din[:]; // receive high byte data from openMSP
wire [:] p2ifg_set; always @ (posedge mclk or posedge puc_rst)
if (puc_rst) p2ifg <= 'h00;
else if (p2ifg_wr) p2ifg <= p2ifg_nxt | p2ifg_set; // write into
else p2ifg <= p2ifg | p2ifg_set; // read out

最新文章

  1. 解决:error: .repo/manifests/: contains uncommitted changes
  2. 从 IClassFactory 为 CLSID 为 {00024500-0000-0000-C000-000000000046} 的 COM 组件创建实例失败,原因是出现以下错误: 8001010a解决办法
  3. Java开发环境的配置与Hello World
  4. python 列表排序
  5. 关于cnas培训
  6. 19.Android之文件存储方法学习
  7. tcp粘包问题(封包)
  8. ASP.NET MVC中的拦截器
  9. Spring IOC 方式结合TESTGN测试用例,测试简单java的命令模式
  10. 【Stage3D学习笔记续】山寨Starling(一):从事件说起
  11. AS问题解决系列1—Unable to execute DX错误
  12. 笔记本PS/2键盘无法使用,试下这个方法
  13. 删除IE缓存中指定的文件
  14. 在 Windows Azure 上部署预配置 Oracle VM
  15. Windows Phone 选择器
  16. sql server int 列 NULLIF,isnull 判断是0还是1 ,如果是0就变成1
  17. docker-maven-plugin插件设置Docker的buildArgs
  18. fork/join概述
  19. vue 兼容性——ie家族不支持promise
  20. leecode第十四题(最长公共前缀)

热门文章

  1. tree:以树形结构显示目录下的内容
  2. CSS定位相关
  3. Bootstrap 表单控件状态(禁用状态)
  4. 阿里云对象存储服务,OSS使用经验总结,图片存储,分页查询
  5. RabbitMQ学习总结(1)——基础概念详细介绍
  6. HDU 5186
  7. POJ 1106
  8. uva 704
  9. POJ 2167 Irrelevant Elements 质因数分解
  10. 10317 Fans of Footbal Teams