Skip to content

Commit 01ded9a

Browse files
committed
CurieMailbox/examples/String.ino: receive on all channels
Also, add public 'numChannels' constant to CurieMailbox class, so all channels can be easily iterated over
1 parent dc4c873 commit 01ded9a

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

libraries/CurieMailbox/examples/String/String.ino

+6-6
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,23 @@
1515

1616
#include "CurieMailbox.h"
1717

18-
int receiveChannel = 0; /* Receiving messages on this channel */
19-
2018
void setup (void) {
2119
Serial.begin(9600);
2220

2321
/* Enable the mailbox */
2422
CurieMailbox.begin();
2523

26-
/* Enable channel for receiving messages */
27-
CurieMailbox.enableReceive(receiveChannel);
24+
/* Enable all channels for receiving messages */
25+
for (int i = 0; i < CurieMailbox.numChannels; ++i) {
26+
CurieMailbox.enableReceive(i);
27+
}
2828
}
2929

3030
void printMessageAsString (CurieMailboxMsg msg)
3131
{
3232
char *p = (char *)msg.data;
33-
Serial.print("Received message '" + String(p) + "' from channel ");
34-
Serial.println(msg.channel);
33+
Serial.print("Received message from channel " + String(msg.channel) + ": ");
34+
Serial.println(String(p));
3535
}
3636

3737
void loop (void) {

libraries/CurieMailbox/src/CurieMailbox.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
#include "CurieMailbox.h"
55

66
#define BUFSIZE 33
7-
#define NUM_CHANNELS 8
87
#define CHANNEL_STS_MASK 0x1
98
#define CHANNEL_INT_MASK 0x2
109
#define CTRL_WORD_MASK 0x7FFFFFFF
1110
#define CHALL_STATUS_MASK 0xFFFF
1211
#define CHANNEL_STS_BITS (CHANNEL_STS_MASK | CHANNEL_INT_MASK)
1312

14-
#define CAP_CHAN(chan) chan = (chan >= NUM_CHANNELS) ? \
15-
NUM_CHANNELS - 1 : ((chan < 0) ? 0 : chan)
13+
#define CAP_CHAN(chan) chan = (chan >= CurieMailbox.numChannels) ?\
14+
CurieMailbox.numChannels - 1 : ((chan < 0) \
15+
? 0 : chan)
1616

1717
/* Mailbox channel status register */
1818
#define IO_REG_MAILBOX_CHALL_STS (SCSS_REGISTER_BASE + 0xAC0)
@@ -122,7 +122,7 @@ static void mbox_isr (void)
122122

123123
sts = get_chall_sts();
124124
/* Get channel number */
125-
for (i = 0; i < NUM_CHANNELS; ++i) {
125+
for (i = 0; i < CurieMailbox.numChannels; ++i) {
126126
if (sts & (1 << (i * 2 + 1))) {
127127
break;
128128
}
@@ -135,7 +135,7 @@ static void mbox_hardware_init (void)
135135
{
136136
int i;
137137

138-
for (i = 0; i < NUM_CHANNELS; ++i) {
138+
for (i = 0; i < CurieMailbox.numChannels; ++i) {
139139
mbox[i].sts &= ~(CHANNEL_STS_BITS);
140140
}
141141
}

libraries/CurieMailbox/src/CurieMailbox.h

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
class CurieMailboxClass {
77
public:
8+
const int numChannels = 8;
9+
810
CurieMailboxClass (void);
911
void begin (void);
1012
void begin (bool master);

0 commit comments

Comments
 (0)