summaryrefslogtreecommitdiff
path: root/cleopatre/plcdrv/arm/inc/hal.h
blob: d9096e2ea3a79f117fb3e72a18831c1cd924cdc6 (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
#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 "hal_utests.h"
#endif

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

/** hal layer context structure */
struct halctx {
    uint32_t *A2L_ptr;
    uint32_t *L2A_ptr;
    const uint32_t *A2L_head;
    uint32_t *A2L_tail;
    uint32_t *L2A_head;
    const uint32_t *L2A_tail;
    uint32_t *A2L_it;
    uint32_t *L2A_it;
    uint32_t *L2A_it_mask;
};

/** 
 * 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 Leon to Arm Trigger Interrupt.
 * 
 * \param  ctx  hal context.
 */
void L2At_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);

/** 
 * 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);

#endif /* hal_h */