Instant SoC Class Library  3.1
FC_System_Timer Class Reference

Timer. More...

Inheritance diagram for FC_System_Timer:
FC_Base

Public Member Functions

void Start (U32 t, TimeUnits unit)
 
void Start (U32 t, TimeUnits unit, U8 event_id)
 
void Stop ()
 
int Sleep (int t, TimeUnits unit=TU_us)
 
int WaitTimer ()
 

Detailed Description

Timer.

There are three ways to use the system timers. You can "Sleep", "Wait" for one timer or wait for one of many timers using the FC_System_EventManager.

// This example show how to use the Sleep functionality of the FC_System_Timer class.
// It generates a 100 us pulse every 1500 us.
#include "fc_io.h"
#include "fc_system.h"
int main()
{
//% hw_begin
FC_IO_Clk clk(100);
//% hw_end
for (;;)
{
p1 = 0x1;
timer.Sleep(100,TU_us);
p1 = 0x0;
timer.Sleep(1400,TU_us);
}
}
// This example show how to use the Start/WaitTimer functionality of the FC_System_Timer class.
// It generates a 100 us pulse every 1500 us using a FC_IO_Pulse object.
#include "fc_io.h"
#include "fc_system.h"
int main()
{
//% hw_begin
FC_IO_Clk clk(100);
//% hw_end
timer.Start(1500, TU_us);
for (;;)
{
timer.WaitTimer();
p1.Pulse(100,TU_us);
}
}

This example show how to wait for multiple timers using FC_System_EventManager:

// This example shows how to use FC_System_Timer, FC_System_EventManager and FC_IO_Pulse.
// Three timers are started.
#include "fc_io.h"
#include "fc_system.h"
int main()
{
//% hw_begin
FC_IO_Clk clk(100);
FC_IO_Pulse p3(0b1); // Inverted
//% hw_end
enum EVENTS { Event1, Event2, Event3}; // Define events id
t1.Start(2, TU_us, Event1); // Event1 @ every 2 us
t2.Start(4, TU_us, Event2); // Event2 @ every 4 us
t3.Start(6, TU_us, Event3); // Event3 @ every 6 us
for (;;)
{
switch( em.GetEvent() ) { // Wait for event
case Event1: // 50 Clk pulse
p1.Pulse(50,TU_clk);
break;
case Event2: // 150 Clk pulse
p2.Pulse(150,TU_clk);
break;
case Event3: // 150 Clk inverted pulse
p3.Pulse(150,TU_clk);
break;
}
}
}

This example will give the following result:

FC_System_EventManager
Multi Event Manager.
Definition: fc_system.h:55
FC_IO_Clk
System clock input.
Definition: fc_io.h:55
FC_IO_Pulse
Asynchronous pulse std_logic output.
Definition: fc_io.h:172
FC_IO_Out
Logic output.
Definition: fc_io.h:126
FC_System_Timer
Timer.
Definition: fc_system.h:78