summaryrefslogtreecommitdiff
path: root/bsp/allwinner/libraries/sunxi-hal/hal/source/msgbox/msgbox_sx/msgbox_sx.h
blob: 3044bd41988902d36fb9bcfe767bc300cfda5afa (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
#ifndef __MSGBOX_SX_H
#define __MSGBOX_SX_H

#include "hal_msgbox.h"
#include "errno.h"
#include <stdint.h>

enum msgbox_direction {
    MSGBOX_DIRECTION_DSP,
    MSGBOX_DIRECTION_CPU,
};

enum msgbox_channel_direction {
    MSGBOX_CHANNEL_RECEIVE,
    MSGBOX_CHANNEL_SEND,
};


struct messagebox;

struct msg_channel {
    struct messagebox *mb;
    enum msgbox_channel_direction dir;
    void *data;
    unsigned char *send;
    int len;
    int idx;
    int (*cb_of_msg_queue)(int queue, void *data);
    int (*cb_tx_done)(unsigned long d, void *data);
    int (*cb_rx)(unsigned long d, void *data);
    int channel;
};

/**
 * @base: messagebox base address
 * @this_user: the messagebox user
 */
struct messagebox {
    unsigned long base;
    int this_user;

    int (*channel_set_direction)(struct messagebox *, int channel,
                      enum msgbox_channel_direction dir);

    int (*channel_irq_set)(struct messagebox *, int channel, int enable);

    int (*channel_read)(struct messagebox *, int channel,
                unsigned long *read);
    int (*channel_write)(struct messagebox *, int channel,
                 unsigned long write);
    int (*channel_fifo_len)(struct messagebox *, int channel);

    struct msg_channel msg_handler[0];
};

extern struct messagebox *msgbox_dsp;
extern struct messagebox *msgbox_cpu;

int messagebox_init_sx(void);

struct msg_channel *msgbox_alloc_channel_sx(struct messagebox *mb, int channel,
                     enum msgbox_channel_direction dir,
                     int (*func)(unsigned long, void *),
                     void *data);

void msgbox_free_channel_sx(struct messagebox *mb, struct msg_channel *ch);

int msgbox_channel_send_data_sx(struct msg_channel *ch, unsigned char *d,
                 size_t len);


#define MSGBOX_CHANNEL_DEPTH    8
#define MSGBOX_MAX_QUEUE    8
#define MSGBOX_MAX_USER     2

int msg_ops_init_sx(struct messagebox *mb);
int msg_irq_handler_sx(int i, void *mb);

#endif /* __MSGBOX_SX_H */