Subversion Repositories Code-Repo

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
113 Kevin 1
#ifndef __msg_queues_h
2
#define __msg_queues_h
3
 
4
// The maximum length (in bytes) of a message
5
#define MSGLEN 255
6
 
7
// The maximum number of messages in a single queue
8
#define MSGQUEUELEN 2   // DO NOT CHANGE THIS!
9
 
10
typedef struct __msg {
11
    unsigned char full; // Indicates that data resides in this msg
12
    unsigned char length; // Length of message data to store
13
    unsigned char msgtype; // Indicates type of message (see maindefs.h)
14
 
15
    unsigned char *data; // The actual message data
16
} msg;  // 5 bytes overhead per msg
17
 
18
typedef struct __msg_queue {
19
    msg queue[MSGQUEUELEN];
20
    unsigned char cur_write_index; // Location to write to next
21
    unsigned char cur_read_index; // Location to read from next
22
} msg_queue;    // 12 bytes overhead per queue
23
 
24
// Error Codes
25
#define MSG_SEND_OKAY 1         // Message sent okay
26
#define MSG_QUEUE_FULL -1       // Too many messages in the queue
27
#define MSG_BAD_LEN -2          // The length of the message is either too large or negative
28
#define MSG_BUFFER_TOOSMALL -3  // The message buffer is too small to receive the message in the queue
29
#define MSG_QUEUE_EMPTY -4      // The message queue is empty
30
#define MSG_NOT_IN_LOW -5       // This call must be made from a low-priority interrupt handler
31
#define MSG_NOT_IN_HIGH -6      // This call must be made from a high-priority interrupt handler
32
#define MSG_NOT_IN_MAIN -7      // This call must be made from the "main()" thread
33
 
34
// This MUST be called before anything else in messages and should
35
// be called before interrupts are enabled
36
void MQ_init(void);
37
 
38
// This is called from a high priority interrupt to decide if the
39
// processor may sleep. It is currently called in interrupts.c
40
void MQ_sleep_high_interrupt_if_okay(void);
41
 
42
// This is called in the "main()" thread (if desired) to block
43
// until a message is received on one of the two incoming queues
44
void MQ_wait_on_incoming_msg_queues(void);
45
 
46
// Queue:
47
// The "MQ_ToMainToLow" queue is a message queue from low priority
48
//  interrupt handlers to the "main()" thread.  The send is called
49
//  in the interrupt handlers and the receive from "main()"
50
signed char	MQ_sendmsg_ToMainFromLow(unsigned char,unsigned char,void *);
51
signed char	MQ_recvmsg_ToMainFromLow(unsigned char,unsigned char *,void *);
52
unsigned char   MQ_peek_ToMainFromLow(void);
53
 
54
// Queue:
55
// The "MQ_ToMainFromHigh" queue is a message queue from high priority
56
//  interrupt handlers to the "main()" thread.  The send is called
57
//  in the interrupt handlers and the receive from "main()"
58
signed char	MQ_sendmsg_ToMainFromHigh(unsigned char,unsigned char,void *);
59
signed char	MQ_recvmsg_ToMainFromHigh(unsigned char,unsigned char *,void *);
60
unsigned char   MQ_peek_ToMainFromHigh(void);
61
 
62
// Queue:
63
// The "MQ_FromMainToLow" queue is a message queue from the "main()"
64
//  thread to the low priority interrupt handlers.  The send is called
65
//  in the "main()" thread and the receive from the interrupt handlers.
66
signed char	MQ_sendmsg_FromMainToLow(unsigned char,unsigned char,void *);
67
signed char	MQ_recvmsg_FromMainToLow(unsigned char,unsigned char *,void *);
68
unsigned char   MQ_peek_FromMainToLow(void);
69
 
70
// Queue:
71
// The "MQ_FromMainToHigh" queue is a message queue from the "main()"
72
//  thread to the high priority interrupt handlers.  The send is called
73
//  in the "main()" thread and the receive from the interrupt handlers.
74
signed char	MQ_sendmsg_FromMainToHigh(unsigned char,unsigned char,void *);
75
signed char	MQ_recvmsg_FromMainToHigh(unsigned char,unsigned char *,void *);
76
unsigned char   MQ_peek_FromMainToHigh(void);
77
 
78
#endif