summaryrefslogtreecommitdiff
path: root/cleopatre/devkit/plcdrv/arm/inc/hal.h
blob: db99ef1479c39966b69ca8e3e42dee77345648bc (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
#ifndef hal_h
#define hal_h
/* Cleopatre project {{{
 *
 * Copyright (C) 2008 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    hal.h
 * \brief   interfaces for mailbox layer
 * \ingroup Cleopatre - PlcDrv
 *
 * this file content interfaces and exported macros, variables... For the
 * Hardware Abstraction Layer
 */

#ifdef __UTESTS__
# include "common.h"
# include <linux/spinlock.h>
#else
# include <linux/spinlock.h>
#endif

#define A2L_RING_MASK            (A2L_RING_SIZE-1)
#define L2A_RING_MASK            (L2A_RING_SIZE-1)

#define MAX_MSG_SIZE             (2 * 4) //2 words : one for header and one for data

/** hal layer context structure */
struct halctx {
    volatile uint32_t *A2L_ptr;
    volatile uint32_t *L2A_ptr;
    volatile uint32_t *L2A_head;
#ifdef __UTESTS__
    volatile uint32_t *A2L_head;
    volatile uint32_t *L2A_tail;
#else
    const volatile uint32_t *A2L_head;
    const volatile uint32_t *L2A_tail;
#endif
    volatile uint32_t *A2L_tail;
    volatile uint32_t *A2L_it;
    volatile uint32_t *L2A_it;
    volatile uint32_t *L2A_it_mask;
    uint32_t L2A_max_length; // current L2A queue length for stats
    uint32_t A2L_max_length; // current A2L queue length for stats
    //Spin lock to protect concurrent access to the HAL mailbox.
    spinlock_t lock;
};

/**
 * Initialize the hal layer.
 *
 * \param  init  user information.
 * \return  hal context.
 */
struct halctx* halmbx_init(struct init_info *info);

/**
 * UnInitialize the hal layer.
 *
 * \param  ctx  hal context.
 * \return  error code.
 */
int halmbx_uninit(struct halctx *ctx);

/**
 * Check if Leon to Arm mailbox queue is empty.
 *
 * \param  ctx  hal context.
 * \return  0 if the queue is empty.
 */
int halmbx_L2Amail_not_empty_queue(struct halctx *ctx);

/**
 * Check Arm to Leon mailbox queue status.
 *
 * \param  ctx  hal context.
 * \return  queue state.
 */
int halmbx_A2Lmail_status_queue(struct halctx *ctx);

/**
 * Check Leon to Arm mailbox queue status.
 *
 * \param  ctx  hal context.
 * \return  queue state.
 */
int halmbx_L2Amail_status_queue(struct halctx *ctx);

/**
 * Copy message to the ring buffer.
 *
 * \param  ctx  hal context.
 * \param  message  pointer to the message align on 32bits.
 * \param  size  message size in bytes and align on 32bits.
 * \return  error code.
 */
int halmbx_copy_to_ring(struct halctx *ctx, uint32_t *message, int size);

/**
 * Copy message from the ring buffer.
 *
 * \param  ctx  hal context.
 * \param  message  pointer to the message align on 32bits.
 * \param  size  max message size in bytes and align on 32bits.
 * \return  error code.
 */
int halmbx_copy_from_ring(struct halctx *ctx, uint32_t *message, int size);

/**
 * Update the ring management for Leon to Arm mailbox (TX).
 *
 * \param  ctx  hal context.
 * \param  size  real size of the last proceed message.
 * \return  error code.
 */
int halmbx_A2Lmail_update(struct halctx *ctx, int size);

/**
 * Update the ring management for Arm to Leon mailbox (RX).
 *
 * \param  ctx  hal context.
 * \param  size  real size of the last proceed message.
 * \return  error code.
 */
int halmbx_L2Amail_update(struct halctx *ctx, int size);

/**
 * Enable the Arm to Leon Acknowledge Interrupt.
 *
 * \param  ctx  hal context.
 */
void A2La_it_enable(struct halctx *ctx);

/**
 * Enable the Leon to Arm Trigger Interrupt.
 *
 * \param  ctx  hal context.
 */
void L2At_it_enable(struct halctx *ctx);

/**
 * Enable the Leon to Arm Watchdog Interrupt.
 *
 * \param  ctx  hal context.
 */
void L2Awd_it_enable(struct halctx *ctx);

/**
 * Disable the Arm to Leon Acknowledge Interrupt.
 *
 * \param  ctx  hal context.
 */
void A2La_it_disable(struct halctx *ctx);

/**
 * Disable the Leon to Arm Trigger Interrupt.
 *
 * \param  ctx  hal context.
 */
void L2At_it_disable(struct halctx *ctx);

/**
 * Set the Arm to Leon Interrupt.
 *
 * \param  ctx  hal context.
 */
void set_A2Lt_interrupt(struct halctx *ctx);

/**
 * Disable the Leon to Arm Watchdog Interrupt.
 *
 * \param  ctx  hal context.
 */
void L2Awd_it_disable(struct halctx *ctx);

/**
 * Set the Arm to Leon acknowledge Interrupt.
 *
 * \param  ctx  hal context.
 */
void set_L2Aa_interrupt(struct halctx *ctx);

/**
 * Clear the Leon to Arm Interrupt.
 *
 * \param  ctx  hal context.
 */
void clr_L2At_interrupt(struct halctx *ctx);

/**
 * Clear the Leon to Arm acknowledge Interrupt.
 *
 * \param  ctx  hal context.
 */
void clr_A2La_interrupt(struct halctx *ctx);

/**
 * Clear the Leon to Arm watchdog Interrupt.
 *
 * \param  ctx  hal context.
 */
void clr_L2Awd_interrupt(struct halctx *ctx);
#endif /* hal_h */