summaryrefslogtreecommitdiff
path: root/cesar/sys/sale/sale.h
blob: 09243d6a6a88a267150c1a60c83036d265ce9d9f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
#ifndef sale_h
#define sale_h
/* Cleopatre project {{{
 *
 * Copyright (C) 2010 SPiDCOM Technologies
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    sale.h
 * \brief   Interfaces for System Abstraction Layer Entity.
 * \ingroup sys
 *
 * This file contains interfaces, exported macros, variables... For the
 * System Abstraction Layer Entity.
 *
 * This is an interface documentation only file.  As many of theses will be
 * implemented as macro or inline functions, it will most of the time be
 * replaced with an implementation specific file.
 */
#include "common/defs/net_buffer.h"

#error "This is an documentation only header."

/** Number of microseconds in a jiffy. */
#define SALE_US_PER_JFF

/** Thread context structure. */
struct sale_thread_t
{
    /* Implementation specific. */
}
typedef struct sale_thread_t sale_thread_t;

/** Declare a thread stack.  This should be used right after the sale_thread_t
 * structure. */
#define SALE_THREAD_STACK(size) SALE_THREAD_STACK_ (size)

/** Flag context structure. */
struct sale_event_t
{
    /* Implementation specific. */
}
typedef struct sale_event_t sale_event_t;

/** Alarm context structure. */
struct sale_alarm_t
{
    /* Implementation specific. */
}
typedef struct sale_alarm_t sale_alarm_t;

BEGIN_DECLS

/**
 * Allocate a net_buffer.
 * \param  size  net_buffer size
 * \return  allocated buffer or NULL on error
 */
net_buffer_t *
sale_net_buffer_alloc (int size);

/**
 * Free a net_buffer.
 * \param  pointer  net_buffer pointer
 */
void
sale_net_buffer_free (net_buffer_t *pointer);

/**
 * Map a memory area.
 * \param  phys_addr  physical address to map
 * \param  size  area size to map
 * \return  mapped area address
 */
void *
sale_phys_map_area (u32 phys_addr, int size);

/**
 * Unmap a memory area.
 * \param  virt_addr  virtual address to unmap
 */
void
sale_phys_unmap_area (void *virt_addr);

/**
 * Find a virtual address corresponding to it physical one.
 * \param  phys_addr  physical address
 * \return  virtual address
 */
void *
sale_phys_to_virt (void *phys_addr);

/**
 * Find a physical address corresponding to it virtual one.
 * \param  virt_addr  virtual address
 * \return  physical address
 */
void *
sale_virt_to_phys (void *virt_addr);

/**
 * Invalidate cache for reading.
 * \param  addr  start area address to synchronise
 * \param  words  area size in words to synchronise
 *
 * This synchronise cache for reading from memory to processor.  Any word
 * loaded in cache will be discarded (and may be loaded, processor dependent).
 */
void
sale_cache_invalidate (u32 *addr, int words);

/**
 * Invalidate and load cache for reading.
 * \param  addr  start area address to synchronise
 * \param  words  area size in words to synchronise
 *
 * This synchronise cache for reading from memory to processor.  Any word
 * loaded in cache will be discarded and reloaded.
 */
void
sale_cache_load (u32 *addr, int words);

/**
 * Flush any write back buffer and write any dirty cache entry.
 * \param  addr  start area address to synchronise
 * \param  words  area size in words to synchronise
 *
 * This synchronise cache for writing from processor to memory.  Any dirty
 * word in cache will be written back to memory.
 */
void
sale_cache_write_back (u32 *addr, int words);

/**
 * Register an interrupt.
 * \param  num  interrupt number
 * \param  name interrupt name
 * \param  isr_handler  isr handler
 * \param  dsr_handler  dsr handler
 * \param  handler_data  handler argument
 */
void
sale_irq_request (int num, char *name,
                  void (*isr_handler) (void *handler_data),
                  void (*dsr_handler) (void *handler_data),
                  void *handler_data);

/**
 * Unregister an interrupt.
 * \param  num  interrupt number
 */
void
sale_irq_free (int num);

/**
 * Request a DSR run.
 * \param  num  interrupt number
 *
 * This request the DSR to run in a near future.  Calling this several times
 * before the DSR is executed will have no further effect.
 */
void
sale_dsr_schedule (int num);

/**
 * Forbid ISR execution.
 * \return  previous state
 */
uint
sale_isr_lock (void);

/**
 * Restore previous ISR lock state.
 * \param  saved_state  state returned by sale_isr_lock
 */
void
sale_isr_unlock (uint saved_state);

/**
 * Forbid DSR execution.
 * \return  previous state
 */
uint
sale_dsr_lock (void);

/**
 * Restore DSR execution.
 * \param  saved_state  state returned by sale_dsr_lock
 */
void
sale_dsr_unlock (uint saved_state);

/**
 * Initialise and start a thread.
 * \param  ctx  thread context structure
 * \param  name  thread name
 * \param  priority  thread priority
 * \param  thread_stack_size  size of thread stack in bytes
 * \param  entry  thread entry
 * \param  entry_data  thread entry argument
 *
 * Priority range can be 0 to 5.
 * 5 is the max priority.
 *
 * Thread stack will be allocated or will use space reserved with
 * SALE_THREAD_STACK right after the thread context.  Its size can be ignored
 * if the system handles it automatically.
 */
void
sale_thread_create (sale_thread_t *ctx, char *name,
                    int priority, int thread_stack_size,
                    void (*entry) (void *entry_data),
                    void *entry_data);

/**
 * Delete a thread.
 * \param  ctx  thread context structure
 */
void
sale_thread_delete (sale_thread_t *ctx);

/**
 * Switch to an other thread execution.
 *
 * Start the scheduler to check if an other task need to be executed.
 */
void
sale_thread_schedule (void);

/**
 * Suspend execution for a fixed delay.
 * \param  delay_jff  delay in jiffies
 */
void
sale_thread_delay (int delay_jff);

/**
 * Initialise an event.
 * \param  ctx  event context structure
 */
void
sale_event_init (sale_event_t *ctx);

/**
 * Uninitialise an event.
 * \param  ctx  event context structure
 */
void
sale_event_uninit (sale_event_t *ctx);

/**
 * Wait on a event.
 * \param  ctx  event context structure
 * \param  condition  C condition to be woken up
 * \return  0 or negative if interrupted
 */
#define sale_event_wait(ctx, condition)

/**
 * Wake up event queue.
 * \param  ctx  event context structure
 */
void
sale_event_wakeup (sale_event_t *ctx);

/**
 * Initialise an alarm.
 * \param  ctx  alarm context structure
 * \param  alarm_handler  alarm handler
 * \param  handler_data  handler argument
 *
 * Handler is running in DSR context.
 */
void
sale_alarm_init (sale_alarm_t *ctx,
                 void (*alarm_handler) (void *handler_data),
                 void *handler_data);

/**
 * Uninitialise an alarm.
 * \param  ctx  alarm context structure
 *
 * If the alarm is programmed, it is canceled.
 */
void
sale_alarm_uninit (sale_alarm_t *ctx);

/**
 * Program an alarm to the given date.
 * \param  ctx  alarm context structure
 * \param  expire_jffdate  expiration date
 *
 * If the alarm was programmed, its expiration date is changed.
 */
void
sale_alarm_program (sale_alarm_t *ctx, u32 expire_jffdate);

/**
 * Cancel an alarm.
 * \param  ctx  alarm context structure
 *
 * There is no arm to cancel an alarm which is not programmed.
 */
void
sale_alarm_cancel (sale_alarm_t *ctx);

/**
 * Get current date.
 * \return  current date in jiffies
 */
u32
sale_jffdate (void);

/**
 * To Check.
 */
u32
sale_phy_date (void);

END_DECLS

#endif /* sale_h */