OpenCores
URL https://opencores.org/ocsvn/c0or1k/c0or1k/trunk

Subversion Repositories c0or1k

[/] [c0or1k/] [trunk/] [conts/] [baremetal/] [timer_service/] [include/] [timer.h] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 drasko
/*
2
 * Timer details.
3
 */
4
#ifndef __TIMER_H__
5
#define __TIMER_H__
6
 
7
#include <l4lib/mutex.h>
8
#include <l4/lib/list.h>
9
#include <l4lib/types.h>
10
 
11
/* Structure representing the sleeping tasks */
12
struct sleeper_task {
13
        struct link list;
14
        l4id_t tid;     /* tid of sleeping task */
15
        int retval;     /* return value on wakeup */
16
};
17
 
18
/* list of tasks to be woken up */
19
struct wake_task_list {
20
        struct link head;
21
        struct link *end; /* optimization */
22
        struct l4_mutex wake_list_lock; /* lock for sanity of head */
23
};
24
 
25
#define BUCKET_BASE_LEVEL_BITS          8
26
#define BUCKET_HIGHER_LEVEL_BITS        6
27
 
28
#define BUCKET_BASE_LEVEL_SIZE          (1 << BUCKET_BASE_LEVEL_BITS)
29
#define BUCKET_HIGHER_LEVEL_SIZE        (1 << BUCKET_HIGHER_LEVEL_BITS)
30
 
31
#define BUCKET_BASE_LEVEL_MASK          0xFF
32
#define BUCKET_HIGHER_LEVEL_MASK        0x3F
33
 
34
/*
35
 * Web of sleeping tasks
36
 * based on timer wheel base algorithm
37
 */
38
struct sleeper_task_bucket {
39
        struct link bucket_level0[BUCKET_BASE_LEVEL_SIZE];
40
        struct link bucket_level1[BUCKET_HIGHER_LEVEL_SIZE];
41
        struct link bucket_level2[BUCKET_HIGHER_LEVEL_SIZE];
42
        struct link bucket_level3[BUCKET_HIGHER_LEVEL_SIZE];
43
        struct link bucket_level4[BUCKET_HIGHER_LEVEL_SIZE];
44
};
45
 
46
/* Macros to extract bucket levels */
47
#define GET_BUCKET_LEVEL4(x)    \
48
        ((x >> (BUCKET_BASE_LEVEL_BITS + (3 * BUCKET_HIGHER_LEVEL_BITS))) & \
49
          BUCKET_HIGHER_LEVEL_MASK)
50
#define GET_BUCKET_LEVEL3(x)    \
51
        ((x >> (BUCKET_BASE_LEVEL_BITS + (2 * BUCKET_HIGHER_LEVEL_BITS))) & \
52
          BUCKET_HIGHER_LEVEL_MASK)
53
#define GET_BUCKET_LEVEL2(x)    \
54
        ((x >> (BUCKET_BASE_LEVEL_BITS + (1 * BUCKET_HIGHER_LEVEL_BITS))) & \
55
         BUCKET_HIGHER_LEVEL_MASK)
56
#define GET_BUCKET_LEVEL1(x)    \
57
        ((x >> BUCKET_BASE_LEVEL_BITS) &  BUCKET_HIGHER_LEVEL_MASK)
58
#define GET_BUCKET_LEVEL0(x)    (x & BUCKET_BASE_LEVEL_MASK)
59
 
60
/* Macros to find bucket level */
61
#define IS_IN_LEVEL0_BUCKET(x)          \
62
        (x < (1 << BUCKET_BASE_LEVEL_BITS))
63
#define IS_IN_LEVEL1_BUCKET(x)          \
64
        (x < (1 << (BUCKET_BASE_LEVEL_BITS + BUCKET_HIGHER_LEVEL_BITS)))
65
#define IS_IN_LEVEL2_BUCKET(x)          \
66
        (x < (1 << (BUCKET_BASE_LEVEL_BITS + (2 * BUCKET_HIGHER_LEVEL_BITS))))
67
#define IS_IN_LEVEL3_BUCKET(x)          \
68
        (x < (1 << (BUCKET_BASE_LEVEL_BITS + (3 * BUCKET_HIGHER_LEVEL_BITS))))
69
 
70
/*
71
 * Timer structure
72
 * TODO: Keep timer 32 bit for time being,
73
 * we will make it 64 in future
74
 */
75
struct timer {
76
        int slot;               /* Notify slot on utcb */
77
        unsigned long base;     /* Virtual base address */
78
        unsigned int count;             /* Counter/jiffies */
79
        struct sleeper_task_bucket task_list;   /* List of sleeping tasks */
80
        struct l4_mutex task_list_lock; /* Lock for sleeper_task_bucket */
81
        struct capability cap;  /* Capability describing timer */
82
};
83
 
84
#endif /* __TIMER_H__ */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.