silice-learning/syntax-example.si

59 lines
1.2 KiB
Plaintext
Raw Permalink Normal View History

2023-06-24 15:01:18 +02:00
$$Period = 1 / Frequency;
$$NSPerClock = 1000000000 * Period;
$$ClocksPerMS = math.floor( 1000000 / NSPerClock );
algorithm Debounce( input uint1 Source, output uint1 Dest ) <autorun> {
uint24 Clocks = 0;
uint8 Bitmap = 0;
while ( 1 ) {
Clocks = Clocks + 1;
if ( Clocks == $ClocksPerMS$ ) {
Bitmap = ( Bitmap << 1 ) | Source;
Clocks = 0;
}
// If all the bits are set then the button should have finished bouncing
// and the output should be reliable.
Dest = ( Bitmap == 8hff ) ? 1 : 0;
}
}
subroutine WaitForRisingEdge( input uint1 Signal, output uint1 Debug ) {
uint1 Last = 0;
Debug = 1;
while ( 1 ) {
if ( Last == 0 && Signal == 1 ) {
break;
}
Last = Signal;
}
Debug = 0;
}
algorithm main( output uint$NUM_LEDS$ leds, output uint$NUM_GPIO_OUT$ gp, input uint$NUM_GPIO_IN$ gn ) {
uint1 FilteredButton = 0;
uint1 Button = 0;
uint1 State = 0;
Debounce Btn(
Source <: Button,
Dest :> FilteredButton
);
Button := gn[ 10,1 ];
leds[ 0,1 ] := State;
while ( 1 ) {
// Error
// ^^^^^^^^^^^^^^^^^^^ incorrect input parameters in call to algorithm 'WaitForRisingEdge', last correct match was parameter 'Signal'
( ) <- WaitForRisingEdge <- ( FilteredButton, LED );
State = ~State;
}
}