Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. #ifndef uart_transmitter_hpp
  2. #define uart_transmitter_hpp
  3.  
  4. #include <systemc.h>
  5.  
  6. enum state_t {
  7. idle, start, d0, d1, d2, d3, d4, d5, d6, d7, stop
  8. };
  9.  
  10. SC_MODULE(uart_transmitter) {
  11. sc_in<sc_bit> clk;
  12. sc_in<sc_bv<8>> data;
  13. sc_in<sc_bit> enable;
  14. sc_out<sc_bit> txready;
  15. sc_out<sc_bit> tx;
  16.  
  17. sc_signal<state_t> state;
  18. sc_bv<8> buf;
  19.  
  20. void sendData();
  21.  
  22. SC_CTOR(uart_transmitter) {
  23. SC_METHOD(sendData);
  24. sensitive << clk;
  25. };
  26. };
  27.  
  28. #endif /* uart_transmitter_hpp */
  29.  
  30. #include "uart.hpp"
  31.  
  32. void uart_transmitter::sendData() {
  33. if (clk.event() && clk.read() == sc_bit(true)) {
  34. switch (state.read()) {
  35. case idle:
  36. tx.write(sc_bit(true));
  37. txready.write(sc_bit(true));
  38. if (enable.read() == sc_bit(true)) {
  39. buf = data.read();
  40. state.write(state_t::start);
  41. }
  42. break;
  43. case start:
  44. state.write(state_t::d0);
  45. tx.write(sc_bit(false));
  46. break;
  47. case d0:
  48. state.write(state_t::d1);
  49. tx.write(sc_bit(buf[0]));
  50. break;
  51. case d1:
  52. state.write(state_t::d2);
  53. tx.write(sc_bit(buf[1]));
  54. break;
  55. case d2:
  56. state.write(state_t::d3);
  57. tx.write(sc_bit(buf[1]));
  58. break;
  59. case d3:
  60. state.write(state_t::d4);
  61. tx.write(sc_bit(buf[3]));
  62. break;
  63. case d4:
  64. state.write(state_t::d5);
  65. tx.write(sc_bit(buf[4]));
  66. break;
  67. case d5:
  68. state.write(state_t::d6);
  69. tx.write(sc_bit(buf[5]));
  70. break;
  71. case d6:
  72. state.write(state_t::d7);
  73. tx.write(sc_bit(buf[6]));
  74. break;
  75. case d7:
  76. state.write(state_t::stop);
  77. tx.write(sc_bit(buf[7]));
  78. break;
  79. case stop:
  80. state.write(state_t::stop);
  81. tx.write(sc_bit(true));
  82. break;
  83. }
  84. }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement