IntController.v 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*
  2. * Interrupt controller
  3. * On interrupt, CPU should save the PC and jump to ADDR 1
  4. * and restore everything on reti
  5. */
  6. module IntController(
  7. input clk, reset,
  8. input int1, int2, int3, int4, int5, int6, int7, int8, int9, int10,
  9. input intDisabled,
  10. output reg intCPU = 1'b0,
  11. output reg [7:0] intID = 8'd0
  12. );
  13. reg int1_prev = 1'b0;
  14. reg int2_prev = 1'b0;
  15. reg int3_prev = 1'b0;
  16. reg int4_prev = 1'b0;
  17. reg int5_prev = 1'b0;
  18. reg int6_prev = 1'b0;
  19. reg int7_prev = 1'b0;
  20. reg int8_prev = 1'b0;
  21. reg int9_prev = 1'b0;
  22. reg int10_prev = 1'b0;
  23. reg int1_triggered = 1'b0;
  24. reg int2_triggered = 1'b0;
  25. reg int3_triggered = 1'b0;
  26. reg int4_triggered = 1'b0;
  27. reg int5_triggered = 1'b0;
  28. reg int6_triggered = 1'b0;
  29. reg int7_triggered = 1'b0;
  30. reg int8_triggered = 1'b0;
  31. reg int9_triggered = 1'b0;
  32. reg int10_triggered = 1'b0;
  33. always @(posedge clk)
  34. begin
  35. if (reset)
  36. begin
  37. int1_prev <= 1'b0;
  38. int2_prev <= 1'b0;
  39. int3_prev <= 1'b0;
  40. int4_prev <= 1'b0;
  41. int5_prev <= 1'b0;
  42. int6_prev <= 1'b0;
  43. int7_prev <= 1'b0;
  44. int8_prev <= 1'b0;
  45. int9_prev <= 1'b0;
  46. int10_prev <= 1'b0;
  47. int1_triggered <= 1'b0;
  48. int2_triggered <= 1'b0;
  49. int3_triggered <= 1'b0;
  50. int4_triggered <= 1'b0;
  51. int5_triggered <= 1'b0;
  52. int6_triggered <= 1'b0;
  53. int7_triggered <= 1'b0;
  54. int8_triggered <= 1'b0;
  55. int9_triggered <= 1'b0;
  56. int10_triggered <= 1'b0;
  57. intCPU <= 1'b0;
  58. intID <= 8'd0;
  59. end
  60. else
  61. begin
  62. int1_prev <= int1;
  63. int2_prev <= int2;
  64. int3_prev <= int3;
  65. int4_prev <= int4;
  66. int5_prev <= int5;
  67. int6_prev <= int6;
  68. int7_prev <= int7;
  69. int8_prev <= int8;
  70. int9_prev <= int9;
  71. int10_prev <= int10;
  72. if (int1 && !int1_prev)
  73. int1_triggered <= 1'b1;
  74. if (int2 && !int2_prev)
  75. int2_triggered <= 1'b1;
  76. if (int3 && !int3_prev)
  77. int3_triggered <= 1'b1;
  78. if (int4 && !int4_prev)
  79. int4_triggered <= 1'b1;
  80. if (int5 && !int5_prev)
  81. int5_triggered <= 1'b1;
  82. if (int6 && !int6_prev)
  83. int6_triggered <= 1'b1;
  84. if (int7 && !int7_prev)
  85. int7_triggered <= 1'b1;
  86. if (int8 && !int8_prev)
  87. int8_triggered <= 1'b1;
  88. if (int9 && !int9_prev)
  89. int9_triggered <= 1'b1;
  90. if (int10 && !int10_prev)
  91. int10_triggered <= 1'b1;
  92. // trigger new interrupt if available with priority to lowest number
  93. if (!intDisabled && !intCPU)
  94. begin
  95. if (int1_triggered)
  96. begin
  97. int1_triggered <= 1'b0;
  98. intCPU <= 1'b1;
  99. intID = 8'd1;
  100. end
  101. else if (int2_triggered)
  102. begin
  103. int2_triggered <= 1'b0;
  104. intCPU <= 1'b1;
  105. intID = 8'd2;
  106. end
  107. else if (int3_triggered)
  108. begin
  109. int3_triggered <= 1'b0;
  110. intCPU <= 1'b1;
  111. intID = 8'd3;
  112. end
  113. else if (int4_triggered)
  114. begin
  115. int4_triggered <= 1'b0;
  116. intCPU <= 1'b1;
  117. intID = 8'd4;
  118. end
  119. else if (int5_triggered)
  120. begin
  121. int5_triggered <= 1'b0;
  122. intCPU <= 1'b1;
  123. intID = 8'd5;
  124. end
  125. else if (int6_triggered)
  126. begin
  127. int6_triggered <= 1'b0;
  128. intCPU <= 1'b1;
  129. intID = 8'd6;
  130. end
  131. else if (int7_triggered)
  132. begin
  133. int7_triggered <= 1'b0;
  134. intCPU <= 1'b1;
  135. intID = 8'd7;
  136. end
  137. else if (int8_triggered)
  138. begin
  139. int8_triggered <= 1'b0;
  140. intCPU <= 1'b1;
  141. intID = 8'd8;
  142. end
  143. else if (int9_triggered)
  144. begin
  145. int9_triggered <= 1'b0;
  146. intCPU <= 1'b1;
  147. intID = 8'd9;
  148. end
  149. else if (int10_triggered)
  150. begin
  151. int10_triggered <= 1'b0;
  152. intCPU <= 1'b1;
  153. intID = 8'd10;
  154. end
  155. end
  156. if (intDisabled)
  157. begin
  158. intCPU <= 1'b0;
  159. end
  160. end
  161. end
  162. endmodule