Verwendeter Programmcode in Studienarbeit für ESY1B zum Thema "Verifikation mit SystemVerilog und Python"
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

i2cSlave_define.v 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // ----------------------- i2cSlave_define.v --------------------
  2. // stream states
  3. `define STREAM_IDLE 2'b00
  4. `define STREAM_READ 2'b01
  5. `define STREAM_WRITE_ADDR 2'b10
  6. `define STREAM_WRITE_DATA 2'b11
  7. // start stop detection states
  8. `define NULL_DET 2'b00
  9. `define START_DET 2'b01
  10. `define STOP_DET 2'b10
  11. // i2c ack and nak
  12. `define I2C_NAK 1'b1
  13. `define I2C_ACK 1'b0
  14. // ----------------------------------------------------------------
  15. // ------------- modify constants below this line -----------------
  16. // ----------------------------------------------------------------
  17. // i2c device address
  18. `define I2C_ADDRESS 7'h3c
  19. // System clock frequency in MHz
  20. // If you are using a clock frequency below 24MHz, then the macro
  21. // for SDA_DEL_LEN will result in compile errors for i2cSlave.v
  22. // you will need to hand tweak the SDA_DEL_LEN constant definition
  23. `define CLK_FREQ 48
  24. // Debounce SCL and SDA over this many clock ticks
  25. // The rise time of SCL and SDA can be up to 1000nS (in standard mode)
  26. // so it is essential to debounce the inputs.
  27. // The spec requires 0.05V of hysteresis, but in practise
  28. // simply debouncing the inputs is sufficient
  29. // I2C spec requires suppresion of spikes of
  30. // maximum duration 50nS, so this debounce time should be greater than 50nS
  31. // Also increases data hold time and decreases data setup time
  32. // during an I2C read operation
  33. // 10 ticks = 208nS @ 48MHz
  34. `define DEB_I2C_LEN (10*`CLK_FREQ)/48
  35. // Delay SCL for use as internal sampling clock
  36. // Using delayed version of SCL to ensure that
  37. // SDA is stable when it is sampled.
  38. // Not entirely citical, as according to I2C spec
  39. // SDA should have a minimum of 100nS of set up time
  40. // with respect to SCL rising edge. But with the very slow edge
  41. // speeds used in I2C it is better to err on the side of caution.
  42. // This delay also has the effect of adding extra hold time to the data
  43. // with respect to SCL falling edge. I2C spec requires 0nS of data hold time.
  44. // 10 ticks = 208nS @ 48MHz
  45. `define SCL_DEL_LEN (10*`CLK_FREQ)/48
  46. // Delay SDA for use in start/stop detection
  47. // Use delayed SDA during start/stop detection to avoid
  48. // incorrect detection at SCL falling edge.
  49. // From I2C spec start/stop setup is 600nS with respect to SCL rising edge
  50. // and start/stop hold is 600nS wrt SCL falling edge.
  51. // So it is relatively easy to discriminate start/stop,
  52. // but data setup time is a minimum of 100nS with respect to SCL rising edge
  53. // and 0nS hold wrt to SCL falling edge.
  54. // So the tricky part is providing robust start/stop detection
  55. // in the presence of regular data transitions.
  56. // This delay time should be less than 100nS
  57. // 4 ticks = 83nS @ 48MHz
  58. `define SDA_DEL_LEN (4*`CLK_FREQ)/48