EM-ODP  3.7.0
Event Machine on ODP
em_timer.h
1 /*
2  * Copyright (c) 2017, Nokia Solutions and Networks
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  * * Neither the name of the copyright holder nor the names of its
15  * contributors may be used to endorse or promote products derived
16  * from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 #ifndef EM_TIMER_H_
31 #define EM_TIMER_H_
32 
33 #include "em_timer_types.h"
34 
35 #define TMR_DBG_PRINT(fmt, ...) \
36  EM_DBG("TMRDBG: %s(): " fmt, __func__, ## __VA_ARGS__)
37 
38 em_status_t timer_init(timer_storage_t *const tmrs);
39 em_status_t timer_init_local(void);
40 em_status_t timer_term_local(void);
41 em_status_t timer_term(timer_storage_t *const tmrs);
42 
43 static inline int
44 timer_clksrc_em2odp(em_timer_clksrc_t clksrc_em,
45  odp_timer_clk_src_t *clksrc_odp /* out */)
46 {
47  switch (clksrc_em) {
48  case EM_TIMER_CLKSRC_0:
49  *clksrc_odp = ODP_CLOCK_SRC_0;
50  break;
51  case EM_TIMER_CLKSRC_1:
52  *clksrc_odp = ODP_CLOCK_SRC_1;
53  break;
54  case EM_TIMER_CLKSRC_2:
55  *clksrc_odp = ODP_CLOCK_SRC_2;
56  break;
57  case EM_TIMER_CLKSRC_3:
58  *clksrc_odp = ODP_CLOCK_SRC_3;
59  break;
60  case EM_TIMER_CLKSRC_4:
61  *clksrc_odp = ODP_CLOCK_SRC_4;
62  break;
63  case EM_TIMER_CLKSRC_5:
64  *clksrc_odp = ODP_CLOCK_SRC_5;
65  break;
66  default:
67  return -1;
68  }
69  return 0;
70 }
71 
72 static inline int
73 timer_clksrc_odp2em(odp_timer_clk_src_t clksrc_odp,
74  em_timer_clksrc_t *clksrc_em /* out */)
75 {
76  switch (clksrc_odp) {
77  case ODP_CLOCK_SRC_0:
78  *clksrc_em = EM_TIMER_CLKSRC_0;
79  break;
80  case ODP_CLOCK_SRC_1:
81  *clksrc_em = EM_TIMER_CLKSRC_1;
82  break;
83  case ODP_CLOCK_SRC_2:
84  *clksrc_em = EM_TIMER_CLKSRC_2;
85  break;
86  case ODP_CLOCK_SRC_3:
87  *clksrc_em = EM_TIMER_CLKSRC_3;
88  break;
89  case ODP_CLOCK_SRC_4:
90  *clksrc_em = EM_TIMER_CLKSRC_4;
91  break;
92  case ODP_CLOCK_SRC_5:
93  *clksrc_em = EM_TIMER_CLKSRC_5;
94  break;
95  default:
96  return -1;
97  }
98  return 0;
99 }
100 
101 #endif /* EM_TIMER_H_ */
timer_storage_t
Definition: em_timer_types.h:50
em_timer_clksrc_t
em_timer_clksrc_t
Definition: event_machine_timer_hw_specific.h:95
em_status_t
uint32_t em_status_t
Definition: event_machine_types.h:321