Skip to content

CurieMailbox/examples/String.ino: receive on all channels #356

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions libraries/CurieMailbox/examples/String/String.ino
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@

#include "CurieMailbox.h"

int receiveChannel = 0; /* Receiving messages on this channel */

void setup (void) {
Serial.begin(9600);

/* Enable the mailbox */
CurieMailbox.begin();

/* Enable channel for receiving messages */
CurieMailbox.enableReceive(receiveChannel);
/* Enable all channels for receiving messages */
for (int i = 0; i < CurieMailbox.numChannels; ++i) {
CurieMailbox.enableReceive(i);
}
}

void printMessageAsString (CurieMailboxMsg msg)
{
char *p = (char *)msg.data;
Serial.print("Received message '" + String(p) + "' from channel ");
Serial.println(msg.channel);
Serial.print("Received message from channel " + String(msg.channel) + ": ");
Serial.println(String(p));
}

void loop (void) {
Expand Down
10 changes: 5 additions & 5 deletions libraries/CurieMailbox/src/CurieMailbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
#include "CurieMailbox.h"

#define BUFSIZE 33
#define NUM_CHANNELS 8
#define CHANNEL_STS_MASK 0x1
#define CHANNEL_INT_MASK 0x2
#define CTRL_WORD_MASK 0x7FFFFFFF
#define CHALL_STATUS_MASK 0xFFFF
#define CHANNEL_STS_BITS (CHANNEL_STS_MASK | CHANNEL_INT_MASK)

#define CAP_CHAN(chan) chan = (chan >= NUM_CHANNELS) ? \
NUM_CHANNELS - 1 : ((chan < 0) ? 0 : chan)
#define CAP_CHAN(chan) chan = (chan >= CurieMailbox.numChannels) ?\
CurieMailbox.numChannels - 1 : ((chan < 0) \
? 0 : chan)

/* Mailbox channel status register */
#define IO_REG_MAILBOX_CHALL_STS (SCSS_REGISTER_BASE + 0xAC0)
Expand Down Expand Up @@ -122,7 +122,7 @@ static void mbox_isr (void)

sts = get_chall_sts();
/* Get channel number */
for (i = 0; i < NUM_CHANNELS; ++i) {
for (i = 0; i < CurieMailbox.numChannels; ++i) {
if (sts & (1 << (i * 2 + 1))) {
break;
}
Expand All @@ -135,7 +135,7 @@ static void mbox_hardware_init (void)
{
int i;

for (i = 0; i < NUM_CHANNELS; ++i) {
for (i = 0; i < CurieMailbox.numChannels; ++i) {
mbox[i].sts &= ~(CHANNEL_STS_BITS);
}
}
Expand Down
2 changes: 2 additions & 0 deletions libraries/CurieMailbox/src/CurieMailbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

class CurieMailboxClass {
public:
const int numChannels = 8;

CurieMailboxClass (void);
void begin (void);
void begin (bool master);
Expand Down