URL
https://opencores.org/ocsvn/simple_customized_counter/simple_customized_counter/trunk
Subversion Repositories simple_customized_counter
Compare Revisions
- This comparison shows the changes necessary to convert path
/simple_customized_counter/trunk
- from Rev 3 to Rev 4
- ↔ Reverse comparison
Rev 3 → Rev 4
/src/CCounter.psc
File deleted
\ No newline at end of file
/CounterLib.psC
0,0 → 1,146
library CounterLib |
{ |
// This is a library of counters |
// Each counter supports: |
// - resetting |
// - counting up |
// - counting down |
// - loading a value from the input iLoad |
// |
// The code is straightforward, so you can easily create your own counter |
// by changing the counter type or the operations |
// |
// The output always generates an event. |
// If you don't want the event, remove the colon ':' in the value assignment |
// -- oValue := 0 |
// |
// There are four counters in the library: |
// - CCounterEvent: executes the operation on separate input events |
// - CCounterLevel: executes the operation at each step based |
// - CCounterOprEvent: executes the operation on input Opr event |
// - CCounterOprLevel: executes the operation at each step |
// the operation is encoded on the input iOpr |
|
component CCounterEvent (in active bit iReset, |
in active bit iUp, |
in active bit iDown, |
in active bit iLoad, |
in passive ubyte iLoadVal, |
out active ubyte oValue) |
{ |
// This counter executes the operation on input events |
// There is a priority assigned to each function in parenthesis |
// 0 indicates highest priority |
// and priority decreases with increasing value |
|
DoReset(0) on iReset |
{ |
oValue := 0ub; |
} |
|
CountUp(1) on iUp |
{ |
oValue:++; |
} |
|
CountDown(2) on iDown |
{ |
oValue:--; |
} |
|
LoadValue(3) on iLoad |
{ |
oValue := iLoadVal; |
} |
}; |
|
component CCounterLevel (in passive bit iReset, |
in passive bit iUp, |
in passive bit iDown, |
in passive bit iLoad, |
in passive ubyte iLoadValue, |
out active ubyte oValue) |
{ |
// This counter executes the operation at each step or clock pulse |
// The priority is implemented with if and else instructions |
|
always() |
{ |
if(iReset) |
{ |
oValue := 0ub; |
} |
|
else if(iUp) |
{ |
oValue:++; |
} |
|
else if(iDown) |
{ |
oValue:--; |
} |
|
else if(iLoad) |
{ |
oValue := iLoadVal; |
} |
} |
}; |
|
typedef Opr_t { cOprReset, cOprUp, cOprDown, cOprLoad }; |
|
component CCounterOprEvent (in active bit iReset, |
in active bit iUp, |
in active bit iDown, |
in active bit iLoad, |
in active ubyte iLoadValue, |
out active ubyte oValue) |
{ |
// This counter executes the operation on iOpr input event |
// The input iOpr has the type Opr_t, see above |
// There is no priority on the operations |
// |
// The switch statement has no break, only one case is executed |
|
ExecuteOpr(0) on iOpr |
{ |
switch(iOpr) |
{ |
case iReset: Value := 0ub; |
case iUp: oValue:++; |
case iDown: oValue:--; |
case iLoad: oValue := iLoadValue; |
} |
} |
|
|
}; |
|
component CCounterLevel (in active bit iReset, |
in active bit iUp, |
in active bit iDown, |
in active bit iLoad, |
in active ubyte iLoadValue, |
out active ubyte oValue) |
{ |
// This counter executes the operation at each steo or clock pulse |
// The priority is implemented with if and else instructions |
always() |
{ |
// Send the event |
oValue:; |
|
// Assign the value |
// The switch instruction returns a value |
oValue = switch(iOpr) |
{ |
case iReset: 0ub; |
case iUp: oValue + 1ub; |
case iDown: oValue - 1ub; |
case iLoad: iLoadValue; |
} |
} |
}; |
|
} |