summaryrefslogtreecommitdiff
path: root/cesar/bufmgr/inc/context.h
blob: 1f2d59e75c03dcd600a1fe0367ac38f9c89bd8df (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
#ifndef bufmgr_inc_context_h
#define bufmgr_inc_context_h

/* Cesar project {{{
 *
 * Copyright (C) 2012 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    bufmgr/inc/context.h
 * \brief   Buffer manager context structure definition.
 * \ingroup bufmgr
 */
#include "common/ipmbox/protocol.h"
#include "hal/ipmbox/ipmbox.h"
#include "hal/arch/sem.h"

#include "bufmgr/inc/trace.h"

/* Size of the local buffer list. */
#define BUFMGR_BUFFER_LIST_SIZE \
   (IPMBOX_PROTOCOL_QUEUE_SIZE_A2L_EMPTY_BUF / 2)

/* Number of required local buffers in local list.
 * The list is bigger to store empty buffers received from the PLC to the CP.
 * Those buffers are empty buffers given by linux and must be kept in the
 * buffer manager. */
#define BUFMGR_BUFFER_LIST_NB (BUFMGR_BUFFER_LIST_SIZE / 2)

/* Number of buffer reserved for blocking clients. */
#define BUFMGR_RESERVED_BUFFER_NB 4

/* Number of registered clients. */
#define BUFMGR_CLIENT_NB 5

/* Client callback. */
struct bufmgr_client_t
{
    /** Callback. */
    bufmgr_callback_t cb;
    /** User data. */
    void *user_data;
};
typedef struct bufmgr_client_t bufmgr_client_t;

/* Context structure. */
struct bufmgr_t
{
    /* IPMbox context. */
    ipmbox_t *ipmbox;
    /** Table of client callback. */
    bufmgr_client_t client[BUFMGR_CLIENT_NB];
    /** Number of clients registered. */
    uint client_nb;
    /** List of buffers. */
    u32 buffers [BUFMGR_BUFFER_LIST_SIZE];
    /** Number of available buffers. */
    uint buffers_nb;
    /** Semaphore for reserved buffers. */
    hal_arch_sem_t sem;
#if CONFIG_TRACE
    /** Buffer Manager Trace */
    trace_buffer_t trace;
#endif
};

#endif /*bufmgr_inc_context_h*/