All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Functions
cpu_api.c File Reference
#include <sw_types.h>
#include <sw_board.h>
#include <sw_debug.h>
#include <global.h>
#include <cpu.h>
#include <gic.h>
#include <secure_timer.h>

Go to the source code of this file.

Functions

void timer_init (void)
 Init secure kernel timer.
 
void enable_timer (void)
 Enable secure kernel timer.
 
void disable_timer (void)
 Disable secure kernel timer.
 
void trigger_tick (u64 usecs)
 This function writes the number of clockcycles to be expired before the next tick to the tick timer and enables the tick timer.
 
u64 clockcycles_to_timeval (u32 clockcycles)
 This function converts the clockcycles to time in seconds and nanoseconds This function definition depends on clock used.
 
u64 timeval_to_clockcycles (timeval_t *time)
 It converts the time (seconds and nanoseconds) to the number of clockcycles.
 
void emulate_timer_irq (void)
 Emulate timer IRQ functionality.
 
void schedule (void)
 Invoke scheduler.
 

Function Documentation

u64 clockcycles_to_timeval ( u32  clockcycles)

This function converts the clockcycles to time in seconds and nanoseconds This function definition depends on clock used.

Parameters
clockcycles
Returns

Definition at line 113 of file cpu_api.c.

{
timeval_t time;
u64 tmp_nsecs;
u64 tmp_secs;
u64 tmp_usecs;
u64 tmp_calc;
u64 usecs;
/* Divide by 1000
* x/1000 = x>>10 + 3*x>>17 +9*x>>24;
* or
* y = x>>10;
* ==> x/1000 = y + (3*y)>>7 + (9*y)>>14
*/
usecs = clockcycles * get_clock_period_us();
/* Find number of seconds */
tmp_secs = usecs;
tmp_secs = (tmp_secs >> 10);
tmp_secs = tmp_secs + ((3 * tmp_secs)>>7) + ((9 * tmp_secs)>>14);
tmp_secs = (tmp_secs >> 10);
tmp_secs = tmp_secs + ((3 * tmp_secs)>>7) + ((9 * tmp_secs)>>14);
/* Multiply number of seconds with 10^6 to convert it to number of
* clockcycles and then subtract it from the total number of
* clockcycles to obtain the number of microseconds
*/
/* Multiply by thousand
* 1000 = 1024 + 8 - 32
* = 2^10 + 2^3 - 2^5
*/
tmp_calc = (tmp_secs << 10) + (tmp_secs << 3) - (tmp_secs << 5);
tmp_calc = (tmp_calc << 10) + (tmp_calc << 3) - (tmp_calc << 5);
tmp_usecs = usecs - tmp_calc;
tmp_nsecs = (tmp_usecs<<10) + (tmp_usecs <<3) - (tmp_usecs<<5);
time.tval.nsec = tmp_nsecs;
time.tval.sec = tmp_secs;
return time.tval64;
}
void disable_timer ( void  )

Disable secure kernel timer.

This function disables the secure kernel timer

Definition at line 65 of file cpu_api.c.

void emulate_timer_irq ( void  )

Emulate timer IRQ functionality.

Definition at line 209 of file cpu_api.c.

{
#ifdef CONFIG_EMULATE_FIQ
/* asm volatile("swi #0xaaaa"); */
#endif
}
void enable_timer ( void  )

Enable secure kernel timer.

This function enables the secure kernel timer

Definition at line 52 of file cpu_api.c.

void schedule ( void  )

Invoke scheduler.

This function invokes the scheduler to schedule the next ready task

Definition at line 222 of file cpu_api.c.

{
#ifdef CONFIG_EMULATE_FIQ
#else
asm volatile("swi #0xbbbb");
#endif
}
void timer_init ( void  )

Init secure kernel timer.

This function initialize the secure kernel timer

Definition at line 40 of file cpu_api.c.

{
/* sp804_sleep_timer_init(SECURE_TIMER_BASE); */
}
u64 timeval_to_clockcycles ( timeval_t time)

It converts the time (seconds and nanoseconds) to the number of clockcycles.

Parameters
time
Returns

Definition at line 167 of file cpu_api.c.

{
u64 useconds = 0;
u64 clockcycles;
u64 tmp_sec , tmp_nsec;
if((time->tval.sec < 0) || (time->tval.nsec < 0))
return 0;
tmp_sec = time->tval.sec;
if(tmp_sec > 0) {
/* multiply by 1000 * 1000 */
tmp_sec = (tmp_sec<<10) + (tmp_sec <<3) - (tmp_sec<<5);
tmp_sec = (tmp_sec<<10) + (tmp_sec <<3) - (tmp_sec<<5);
}
/* Divide by 1000
* x/1000 = x>>10 + 3*x>>17 +9*x>>24;
* or
* y = x>>10;
* ==> x/1000 = y + (3*y)>>7 + (9*y)>>14
*/
tmp_nsec = time->tval.nsec;
tmp_nsec = tmp_nsec >> 10;
tmp_nsec = tmp_nsec + ((3 * tmp_nsec)>>7) + ((9*tmp_nsec)>>14);
useconds = tmp_nsec;
useconds += tmp_sec;
clockcycles = (u32)useconds / (u32)get_clock_period_us();
/* Minimum clock cycles to be 1 clock period */
if(clockcycles == 0)
clockcycles = get_clock_period_us();
return clockcycles;
}
void trigger_tick ( u64  usecs)

This function writes the number of clockcycles to be expired before the next tick to the tick timer and enables the tick timer.

Parameters
usecs

Definition at line 89 of file cpu_api.c.

{
if(usecs > TIMER_COUNT_MAX)
usecs = TIMER_COUNT_MAX;
#ifdef CPU_API_DBG
sw_printf("SW: new oneshot tick value 0x%x\n", (u32)usecs);
#endif
if(usecs == 0) {
sw_printf("SW: one shot time minimum value should be 1 us\n");
usecs = 1;
}
}