Subversion Repositories Code-Repo

Rev

Rev 107 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 107 Rev 111
Line 9... Line 9...
9
// ToMainQueueFromLow: Writer is a low priority interrupt, Reader is main()
9
// ToMainQueueFromLow: Writer is a low priority interrupt, Reader is main()
10
// ToMainQueueFromHigh: Writer is a high priority interrupt, Reader is main()
10
// ToMainQueueFromHigh: Writer is a high priority interrupt, Reader is main()
11
// FromMainQueueToLow: Writer is main(), Reader is a low priority interrupt
11
// FromMainQueueToLow: Writer is main(), Reader is a low priority interrupt
12
// FromMainQueueToHigh: Writer is main(), Reader is a high priority interrupt
12
// FromMainQueueToHigh: Writer is main(), Reader is a high priority interrupt
13
 
13
 
14
//#pragma udata msgqueue1_1
14
#pragma udata msgqueue1_1
15
//static msg MQ_ToMainFromLow_1;
15
static msg MQ_ToMainFromLow_1;
16
//#pragma udata msgqueue1_2
16
#pragma udata msgqueue1_2
17
//static msg MQ_ToMainFromLow_2;
17
static msg MQ_ToMainFromLow_2;
18
 
18
 
19
#pragma udata msgqueue2_1
19
#pragma udata msgqueue2_1
20
static msg MQ_ToMainFromHigh_1;
20
static msg MQ_ToMainFromHigh_1;
21
#pragma udata msgqueue2_2
21
#pragma udata msgqueue2_2
22
static msg MQ_ToMainFromHigh_2;
22
static msg MQ_ToMainFromHigh_2;
23
#pragma udata msgqueue2_3
23
//#pragma udata msgqueue2_3
24
static msg MQ_ToMainFromHigh_3;
24
//static msg MQ_ToMainFromHigh_3;
25
 
25
 
26
//#pragma udata msgqueue3_1
26
#pragma udata msgqueue3_1
27
//static msg MQ_FromMainToLow_1;
27
static msg MQ_FromMainToLow_1;
28
//#pragma udata msgqueue3_2
28
#pragma udata msgqueue3_2
29
//static msg MQ_FromMainToLow_2;
29
static msg MQ_FromMainToLow_2;
30
 
30
 
31
#pragma udata msgqueue4_1
31
#pragma udata msgqueue4_1
32
static msg MQ_FromMainToHigh_1;
32
static msg MQ_FromMainToHigh_1;
33
#pragma udata msgqueue4_2
33
#pragma udata msgqueue4_2
34
static msg MQ_FromMainToHigh_2;
34
static msg MQ_FromMainToHigh_2;
35
#pragma udata msgqueue4_3
35
//#pragma udata msgqueue4_3
36
static msg MQ_FromMainToHigh_3;
36
//static msg MQ_FromMainToHigh_3;
37
 
37
 
38
#pragma udata 
38
#pragma udata 
39
//static msg_queue MQ_ToMainFromLow;
39
static msg_queue MQ_ToMainFromLow;
40
static msg_queue MQ_ToMainFromHigh;
40
static msg_queue MQ_ToMainFromHigh;
41
//static msg_queue MQ_FromMainToLow;
41
static msg_queue MQ_FromMainToLow;
42
static msg_queue MQ_FromMainToHigh;
42
static msg_queue MQ_FromMainToHigh;
43
 
43
 
44
static unsigned char MQ_Main_Willing_To_Block;
44
static unsigned char MQ_Main_Willing_To_Block;
45
 
45
 
46
void MQ_init_queue(msg_queue *qptr) {
46
void MQ_init_queue(msg_queue *qptr) {
Line 54... Line 54...
54
}
54
}
55
 
55
 
56
void MQ_init() {
56
void MQ_init() {
57
    MQ_Main_Willing_To_Block = 0;
57
    MQ_Main_Willing_To_Block = 0;
58
 
58
 
59
//    MQ_ToMainFromLow.queue[0] = &MQ_ToMainFromLow_1;
59
    MQ_ToMainFromLow.queue[0] = &MQ_ToMainFromLow_1;
60
//    MQ_ToMainFromLow.queue[1] = &MQ_ToMainFromLow_2;
60
    MQ_ToMainFromLow.queue[1] = &MQ_ToMainFromLow_2;
61
 
61
 
62
    MQ_ToMainFromHigh.queue[0] = &MQ_ToMainFromHigh_1;
62
    MQ_ToMainFromHigh.queue[0] = &MQ_ToMainFromHigh_1;
63
    MQ_ToMainFromHigh.queue[1] = &MQ_ToMainFromHigh_2;
63
    MQ_ToMainFromHigh.queue[1] = &MQ_ToMainFromHigh_2;
64
    MQ_ToMainFromHigh.queue[2] = &MQ_ToMainFromHigh_3;
64
//    MQ_ToMainFromHigh.queue[2] = &MQ_ToMainFromHigh_3;
65
 
65
 
66
//    MQ_FromMainToLow.queue[0] = &MQ_FromMainToLow_1;
66
    MQ_FromMainToLow.queue[0] = &MQ_FromMainToLow_1;
67
//    MQ_FromMainToLow.queue[1] = &MQ_FromMainToLow_2;
67
    MQ_FromMainToLow.queue[1] = &MQ_FromMainToLow_2;
68
 
68
 
69
    MQ_FromMainToHigh.queue[0] = &MQ_FromMainToHigh_1;
69
    MQ_FromMainToHigh.queue[0] = &MQ_FromMainToHigh_1;
70
    MQ_FromMainToHigh.queue[1] = &MQ_FromMainToHigh_2;
70
    MQ_FromMainToHigh.queue[1] = &MQ_FromMainToHigh_2;
71
    MQ_FromMainToHigh.queue[2] = &MQ_FromMainToHigh_3;
71
//    MQ_FromMainToHigh.queue[2] = &MQ_FromMainToHigh_3;
72
 
72
 
73
//    MQ_init_queue(&MQ_ToMainFromLow);
73
    MQ_init_queue(&MQ_ToMainFromLow);
74
    MQ_init_queue(&MQ_ToMainFromHigh);
74
    MQ_init_queue(&MQ_ToMainFromHigh);
75
//    MQ_init_queue(&MQ_FromMainToLow);
75
    MQ_init_queue(&MQ_FromMainToLow);
76
    MQ_init_queue(&MQ_FromMainToHigh);
76
    MQ_init_queue(&MQ_FromMainToHigh);
77
}
77
}
78
 
78
 
79
signed char MQ_send_msg(msg_queue *qptr,unsigned char length,unsigned char msgtype, void *data) {
79
signed char MQ_send_msg(msg_queue *qptr,unsigned char length,unsigned char msgtype, void *data) {
80
    unsigned char slot;
80
    unsigned char slot;
Line 189... Line 189...
189
    _asm
189
    _asm
190
    sleep
190
    sleep
191
    _endasm
191
    _endasm
192
}
192
}
193
 
193
 
194
///* Message Queue 1 - Low Interrupt -> Main */
194
/* Message Queue 1 - Low Interrupt -> Main */
195
//signed char MQ_sendmsg_ToMainFromLow(unsigned char length, unsigned char msgtype, void *data) {
195
signed char MQ_sendmsg_ToMainFromLow(unsigned char length, unsigned char msgtype, void *data) {
196
//#ifdef DEBUG
196
#ifdef DEBUG
197
//    if (!interrupt_in_low_interrupt_routine()) {
197
    if (!interrupt_in_low_interrupt_routine()) {
198
//        return (MSG_NOT_IN_LOW);
198
        return (MSG_NOT_IN_LOW);
199
//    }
199
    }
200
//#endif
200
#endif
201
//    return (MQ_send_msg(&MQ_ToMainFromLow, length, msgtype, data));
201
    return (MQ_send_msg(&MQ_ToMainFromLow, length, msgtype, data));
202
//}
202
}
203
//
203
 
204
//signed char MQ_recvmsg_ToMainFromLow(unsigned char maxlength, unsigned char *msgtype, void *data) {
204
signed char MQ_recvmsg_ToMainFromLow(unsigned char maxlength, unsigned char *msgtype, void *data) {
205
//#ifdef DEBUG
205
#ifdef DEBUG
206
//    if (!interrupt_in_main_routine()) {
206
    if (!interrupt_in_main_routine()) {
207
//        return (MSG_NOT_IN_MAIN);
207
        return (MSG_NOT_IN_MAIN);
208
//    }
208
    }
209
//#endif
209
#endif
210
//    return (MQ_recv_msg(&MQ_ToMainFromLow, maxlength, msgtype, data));
210
    return (MQ_recv_msg(&MQ_ToMainFromLow, maxlength, msgtype, data));
211
//}
211
}
212
//
212
 
213
//unsigned char MQ_peek_ToMainFromLow() {
213
unsigned char MQ_peek_ToMainFromLow() {
214
//    return (MQ_peek_msg(&MQ_ToMainFromLow));
214
    return (MQ_peek_msg(&MQ_ToMainFromLow));
215
//}
215
}
216
 
216
 
217
/* Message Queue 2 - High Interrupt -> Main */
217
/* Message Queue 2 - High Interrupt -> Main */
218
signed char MQ_sendmsg_ToMainFromHigh(unsigned char length, unsigned char msgtype, void *data) {
218
signed char MQ_sendmsg_ToMainFromHigh(unsigned char length, unsigned char msgtype, void *data) {
219
#ifdef DEBUG
219
#ifdef DEBUG
220
    if (!interrupt_in_high_interrupt_routine()) {
220
    if (!interrupt_in_high_interrupt_routine()) {
Line 235... Line 235...
235
 
235
 
236
unsigned char MQ_peek_ToMainFromHigh() {
236
unsigned char MQ_peek_ToMainFromHigh() {
237
    return (MQ_peek_msg(&MQ_ToMainFromHigh));
237
    return (MQ_peek_msg(&MQ_ToMainFromHigh));
238
}
238
}
239
 
239
 
240
///* Message Queue 3 - Main -> Low Interrupt */
240
/* Message Queue 3 - Main -> Low Interrupt */
241
//signed char MQ_sendmsg_FromMainToLow(unsigned char length, unsigned char msgtype, void *data) {
241
signed char MQ_sendmsg_FromMainToLow(unsigned char length, unsigned char msgtype, void *data) {
242
//#ifdef DEBUG
242
#ifdef DEBUG
243
//    if (!interrupt_in_main_routine()) {
243
    if (!interrupt_in_main_routine()) {
244
//        return (MSG_NOT_IN_MAIN);
244
        return (MSG_NOT_IN_MAIN);
245
//    }
245
    }
246
//#endif
246
#endif
247
//    return (MQ_send_msg(&MQ_FromMainToLow, length, msgtype, data));
247
    return (MQ_send_msg(&MQ_FromMainToLow, length, msgtype, data));
248
//}
248
}
249
//
249
 
250
//signed char MQ_recvmsg_FromMainToLow(unsigned char maxlength, unsigned char *msgtype, void *data) {
250
signed char MQ_recvmsg_FromMainToLow(unsigned char maxlength, unsigned char *msgtype, void *data) {
251
//#ifdef DEBUG
251
#ifdef DEBUG
252
//    if (!interrupt_in_low_interrupt_routine()) {
252
    if (!interrupt_in_low_interrupt_routine()) {
253
//        return (MSG_NOT_IN_LOW);
253
        return (MSG_NOT_IN_LOW);
254
//    }
254
    }
255
//#endif
255
#endif
256
//    return (MQ_recv_msg(&MQ_FromMainToLow, maxlength, msgtype, data));
256
    return (MQ_recv_msg(&MQ_FromMainToLow, maxlength, msgtype, data));
257
//}
257
}
258
//
258
 
259
//unsigned char MQ_peek_FromMainToLow() {
259
unsigned char MQ_peek_FromMainToLow() {
260
//    return (MQ_peek_msg(&MQ_FromMainToLow));
260
    return (MQ_peek_msg(&MQ_FromMainToLow));
261
//}
261
}
262
 
262
 
263
/* Message Queue 4 - Main -> High Interrupt */
263
/* Message Queue 4 - Main -> High Interrupt */
264
signed char MQ_sendmsg_FromMainToHigh(unsigned char length, unsigned char msgtype, void *data) {
264
signed char MQ_sendmsg_FromMainToHigh(unsigned char length, unsigned char msgtype, void *data) {
265
#ifdef DEBUG
265
#ifdef DEBUG
266
    if (!interrupt_in_main_routine()) {
266
    if (!interrupt_in_main_routine()) {
Line 305... Line 305...
305
 
305
 
306
    // Check the message queues to make sure that they're empty
306
    // Check the message queues to make sure that they're empty
307
    if (MQ_check_msg_queue_unread(&MQ_ToMainFromHigh)) {
307
    if (MQ_check_msg_queue_unread(&MQ_ToMainFromHigh)) {
308
        return;
308
        return;
309
    }
309
    }
310
//    if (MQ_check_msg_queue_unread(&MQ_ToMainFromLow)) {
310
    if (MQ_check_msg_queue_unread(&MQ_ToMainFromLow)) {
311
//        return;
311
        return;
312
//    }
312
    }
313
 
313
 
314
    // If everything checks out, go to sleep
314
    // If everything checks out, go to sleep
315
    MQ_enter_sleep_mode();
315
    MQ_enter_sleep_mode();
316
}
316
}
317
 
317
 
Line 327... Line 327...
327
        // If any incoming message queues are not empty, break out of wait
327
        // If any incoming message queues are not empty, break out of wait
328
        if (MQ_check_msg_queue_unread(&MQ_ToMainFromHigh)) {
328
        if (MQ_check_msg_queue_unread(&MQ_ToMainFromHigh)) {
329
            MQ_Main_Willing_To_Block = 0;
329
            MQ_Main_Willing_To_Block = 0;
330
            return;
330
            return;
331
        }
331
        }
332
//        if (MQ_check_msg_queue_unread(&MQ_ToMainFromLow)) {
332
        if (MQ_check_msg_queue_unread(&MQ_ToMainFromLow)) {
333
//            MQ_Main_Willing_To_Block = 0;
333
            MQ_Main_Willing_To_Block = 0;
334
//            return;
334
            return;
335
//        }
335
        }
336
        // Sleep for a period of time before checking again
336
        // Sleep for a period of time before checking again
337
        Delay1KTCYx(10);
337
        Delay1KTCYx(10);
338
    }
338
    }
339
}
339
}
340
340