Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Last revision Both sides next revision | ||
intro_example:chp_fifo [2022/05/15 13:05] rajit [A ten-place buffer] |
intro_example:chp_fifo [2022/06/08 06:52] rajit [Simulating the buffer] |
||
---|---|---|---|
Line 2: | Line 2: | ||
- | //(It is a bit unfortunate that the computer science community uses the term buffer to refer to a fifo, while the circuits community uses the term buffer to refer to an electrical circuit that introduces gain to improve signal drive.)// | + | //(It is a bit unfortunate that the computer science community uses the term buffer to refer to a fifo, while the circuits community uses the term buffer to refer to an electrical circuit that introduces gain to improve signal drive strength.)// |
===== A one-place buffer ===== | ===== A one-place buffer ===== | ||
- | ACT supports behavioral descriptions using the [[language: | + | ACT supports behavioral descriptions using the [[language: |
A one-place buffer is a component that repeatedly does the following: it receives a new input; once the input is received, it sends the new value on its output. Suppose we want to describe a CHP component that has an input channel '' | A one-place buffer is a component that repeatedly does the following: it receives a new input; once the input is received, it sends the new value on its output. Suppose we want to describe a CHP component that has an input channel '' | ||
Line 12: | Line 12: | ||
L?x | L?x | ||
</ | </ | ||
- | receives a value from channel '' | + | receives a value from channel '' |
+ | |||
+ | Once we have successfully received the input, we can follow this operation by sending the value '' | ||
<code act> | <code act> | ||
R!x | R!x | ||
</ | </ | ||
- | The send operation is also blocking; | + | The send operation is also blocking; the send will block until the receiver |
<code act> | <code act> | ||
L?x; R!x | L?x; R!x | ||
Line 38: | Line 40: | ||
</ | </ | ||
- | This defines a //process// called '' | + | This defines a //process// called '' |
+ | |||
+ | We have specified two ports: '' | ||
+ | |||
+ | Finally, the definition of the process includes the declaration of the variable '' | ||
The same process that manipulates 8-bit integers would be written as follows: | The same process that manipulates 8-bit integers would be written as follows: | ||
Line 73: | Line 79: | ||
one_place_buffer b[10]; | one_place_buffer b[10]; | ||
</ | </ | ||
- | This creates ten concurrent buffers, named '' | + | This creates ten concurrent buffers, named '' |
+ | <code act> | ||
+ | b[0].R = b[1].L; | ||
+ | b[1].R = b[2].L; | ||
+ | ... | ||
+ | b[8].R = b[9].L; | ||
+ | </ | ||
+ | Since typing all of these connections gets tedious, ACT provides syntax for [[language: | ||
+ | <code act> | ||
+ | (i : 9 : b[i].R = b[i+1].L; | ||
+ | </ | ||
+ | Here, '' | ||
+ | <code act> | ||
+ | (sym id : range : body(id) ) | ||
+ | </ | ||
+ | The '' | ||
+ | <code act> | ||
+ | | ||
+ | </ | ||
+ | where '' | ||
+ | The complete ten-place buffer with its primary input and output channels is given by: | ||
+ | <code act> | ||
+ | defproc tenplace_buffer (chan?(int) L; chan!(int) R) | ||
+ | { | ||
+ | | ||
+ | (i : 9 : b[i].R = b[i+1].L;) | ||
+ | | ||
+ | | ||
+ | } | ||
+ | </ | ||
+ | Note that we connected the '' | ||
+ | ===== An N-place buffer ===== | ||
+ | |||
+ | Now that we have defined a ten-place buffer, how about a twenty-place one? Or some other capacity buffer? ACT provides parameters that can be used to guide circuit construction. An integer parameter in ACT has type '' | ||
+ | <code act> | ||
+ | | ||
+ | (i : N-1 : b[i].R = b[i+1].L;) | ||
+ | | ||
+ | | ||
+ | </ | ||
+ | Finally, we need to define a process that is parameterized by '' | ||
+ | |||
+ | <code act> | ||
+ | template< | ||
+ | defproc buffer (chan?(int) L; chan!(int) R) | ||
+ | { | ||
+ | | ||
+ | (i : N-1 : b[i].R = b[i+1].L;) | ||
+ | | ||
+ | | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | If we want to create a ten-place buffer, we would instantiate it as follows: | ||
+ | <code act> | ||
+ | buffer< | ||
+ | </ | ||
+ | Note once again the use of angle brackets to specify template parameters. | ||
+ | |||
+ | ===== Simulating the buffer ===== | ||
+ | |||
+ | Assuming all the process definitions above are in a file '' | ||
+ | |||
+ | <file act test.act> | ||
+ | import " | ||
+ | |||
+ | defproc test_source (chan!(int) X) | ||
+ | { | ||
+ | int i; | ||
+ | chp { | ||
+ | i := 0; | ||
+ | *[ i < 10 -> X!i; i := i + 1 ] | ||
+ | } | ||
+ | } | ||
+ | |||
+ | defproc test_sink (chan?(int) X) | ||
+ | { | ||
+ | int x; | ||
+ | chp { | ||
+ | *[ X?x; log (" | ||
+ | } | ||
+ | } | ||
+ | |||
+ | defproc test() | ||
+ | { | ||
+ | one_place_buffer b; | ||
+ | test_source tsrc; | ||
+ | test_sink tsink; | ||
+ | b.L = tsrc.X; | ||
+ | b.R = tsink.X; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | This can be simulated using '' | ||
+ | |||
+ | < | ||
+ | % actsim test.act test | ||
+ | |||
+ | actsim> cycle | ||
+ | WARNING: test_sink<>: | ||
+ | WARNING: test_source<>: | ||
+ | WARNING: one_place_buffer<>: | ||
+ | actsim> cycle | ||
+ | [ 30] < | ||
+ | [ 50] < | ||
+ | [ 70] < | ||
+ | [ 90] < | ||
+ | [ 110] < | ||
+ | [ 130] < | ||
+ | [ 150] < | ||
+ | [ 170] < | ||
+ | [ 190] < | ||
+ | [ 210] < | ||
+ | actsim> | ||
+ | </ | ||
+ | The first set of numbers is the time (default delays are 10 time units for each step in the CHP program). Next, the instance name is specified in angle brackets. Finally the log message is displayed. |