Trung tâm đào tạo thiết kế vi mạch Semicon


  • ĐĂNG KÝ TÀI KHOẢN ĐỂ TRUY CẬP NHIỀU TÀI LIỆU HƠN!
  • Đăng ký
    *
    *
    *
    *
    *
    Fields marked with an asterisk (*) are required.
semi4_volunteering.jpg

Channels In SystemC Part IV

Email In PDF.

sc_fifo

sc_fifo is a predefined primitive channel intended to model the behavior of a fifo, that is, a first-in first-out buffer. A fifo is an object of class sc_fifo. Each fifo has a number of slots for storing values. 

The number of slots is fixed when the object is constructed. Default slots size is 16.

sc_fifo has following predefined methods.

  • write() : This method write the values passed as an argument into the fifo. If fifo if full then write() function waits till fifo slot is available
  • nb_write() : This method is same as write(), only difference is, when fifo is full nb_write() does not wait till fifo slot is avaible. Rather it returns false.
  • read() : This method returns the least recent written data in fifo. If fifo is empty, then read() function waits till data is available in fifo.
  • nb_read() :This method is same as read(), only difference is, when fifo is empty, nb_read() does not wait till fifo has some data. Rather it returns false.
  • num_available() : This method returns the numbers of data values available in fifo in current delta time.
  • num_free() : This method returns the number of free slots available in fifo in current delta time.
Example : sc_fifo
  1 #include 

  2

  3 SC_MODULE(example_fifo) {

  4   void example_fifo::m_drain_packets(void);

  5   void example_fifo::t_source1(void);

  6   void example_fifo::t_source2(void);

  7   // Constructor

  8   SC_CTOR(example_fifo) {

  9     SC_METHOD(m_drain_packets);

 10     SC_THREAD(t_source1);

 11     SC_THREAD(t_source2);

 12     // Size the packet_fifo to 5 ints.

 13     sc_fifo<int> packet_fifo (5);

 14   }

 15  

 16   // Declare the FIFO

 17   sc_fifo<int> packet_fifo;

 18 };

 19

 20 void example_fifo::m_drain_packets(void) {

 21   int val;

 22   if (packet_fifo.nb_read(val)) {

 23     std::cout << sc_time_stamp() << ": m_drain_packets(): Received " << val <<

 24       std::endl;

 25   } else {

 26     std::cout << sc_time_stamp() << ": m_drain_packets(): FIFO empty." << std::endl;

 27   }

 28   // Check back in 2ns

 29   next_trigger(2, SC_NS);

 30 }

 31

 32 void example_fifo::t_source1(void) {

 33   int val = 1000;

 34   for (;;) {

 35     wait(3, SC_NS);

 36     val++;

 37     packet_fifo.write(val);

 38     std::cout << sc_time_stamp() << ": t_thread1(): Wrote " << val << std::endl;

 39   }

 40 }

 41

 42 void example_fifo::t_source2(void) {

 43   int val = 2000;

 44   for (;;) {

 45     wait(5, SC_NS);

 46     val++;

 47     packet_fifo.write(val);

 48     std::cout << sc_time_stamp() << ": t_thread2(): Wrote " << val << std::endl;

 49   }

 50 }

 51

 52 int sc_main(int argc, char* argv[]) {

 53   example_fifo ex_fifo ("ex_fifo0");

 54   sc_start(30, SC_NS);

 55   return 0;

 56 }

Simulation Output : sc_fifo

0 s: m_drain_packets(): FIFO empty.
 2 ns: m_drain_packets(): FIFO empty.
 3 ns: t_thread1(): Wrote 1001
 4 ns: m_drain_packets(): Received 1001
 5 ns: t_thread2(): Wrote 2001
 6 ns: m_drain_packets(): Received 2001
 6 ns: t_thread1(): Wrote 1002
 8 ns: m_drain_packets(): Received 1002
 9 ns: t_thread1(): Wrote 1003
 10 ns: m_drain_packets(): Received 1003
 10 ns: t_thread2(): Wrote 2002
 12 ns: m_drain_packets(): Received 2002
 12 ns: t_thread1(): Wrote 1004
 14 ns: m_drain_packets(): Received 1004
 15 ns: t_thread1(): Wrote 1005
 15 ns: t_thread2(): Wrote 2003
 16 ns: m_drain_packets(): Received 1005
 18 ns: m_drain_packets(): Received 2003
 18 ns: t_thread1(): Wrote 1006
 20 ns: m_drain_packets(): Received 1006
 20 ns: t_thread2(): Wrote 2004
 21 ns: t_thread1(): Wrote 1007
 22 ns: m_drain_packets(): Received 2004
 24 ns: m_drain_packets(): Received 1007
 24 ns: t_thread1(): Wrote 1008
 25 ns: t_thread2(): Wrote 2005
 26 ns: m_drain_packets(): Received 1008
 27 ns: t_thread1(): Wrote 1009
 28 ns: m_drain_packets(): Received 2005

   Bạn Có Đam Mê Với Vi Mạch hay Nhúng      -     Bạn Muốn Trau Dồi Thêm Kĩ Năng

Mong Muốn Có Thêm Cơ Hội Trong Công Việc

Và Trở Thành Một Người Có Giá Trị Hơn

Bạn Chưa Biết Phương Thức Nào Nhanh Chóng Để Đạt Được Chúng

Hãy Để Chúng Tôi Hỗ Trợ Cho Bạn. SEMICON  

Lần cập nhật cuối ( Thứ ba, 29 Tháng 3 2022 00:51 )