#include <aversive/endian.h>
#include <aversive/pgmspace.h>
+#include <callout.h>
#include <rdline.h>
#include <xbee.h>
#include <xbee_rxtx.h>
#include "xbee_user.h"
#include "main.h"
-#define XBEE_TIMEOUT_MS 1000
+#define XBEE_TIMEOUT_MS 1000
+#define XBEE_POLL_TIMER_MS 5
static struct xbee_ctx xbee_ctx[XBEE_MAX_CHANNEL];
struct xbee_ctx ctx;
/* struct xbee_atcmd_hdr atcmd_hdr; -> no needed same than atcmd_str */
struct xbee_msg msg;
+ uint8_t prio;
+ int ret;
memset(&ctx, 0, sizeof(ctx));
ctx.atcmd_query[0] = atcmd_str[0];
msg.iov[1].buf = param;
msg.iov[1].len = param_len;
- if (xbeeapp_send(&ctx, XBEE_TYPE_ATCMD, &msg, foreground) < 0)
- return -1;
+ prio = callout_mgr_set_prio(&xbeeboard.intr_cm, XBEE_PRIO);
+ ret = xbeeapp_send(&ctx, XBEE_TYPE_ATCMD, &msg, foreground);
+ callout_mgr_set_prio(&xbeeboard.intr_cm, prio);
- return 0;
+ return ret;
}
int xbeeapp_send_msg(uint64_t addr, struct xbee_msg *msg, int foreground)
struct xbee_xmit_hdr xmit_hdr;
struct xbee_msg msg2;
unsigned i;
+ uint8_t prio;
+ int ret;
if (msg->iovlen + 2 > XBEE_MSG_MAXIOV) {
printf_P(PSTR("too many iovecs\r\n"));
return -1;
}
+
xmit_hdr.dstaddr = htonll(addr);
xmit_hdr.reserved = htons(0xFFFE);
xmit_hdr.bcast_radius = 0;
memset(&ctx, 0, sizeof(ctx));
ctx.atcmd_query[0] = '\0';
- if (xbeeapp_send(&ctx, XBEE_TYPE_XMIT, &msg2, foreground) < 0)
- return -1;
+ prio = callout_mgr_set_prio(&xbeeboard.intr_cm, XBEE_PRIO);
+ ret = xbeeapp_send(&ctx, XBEE_TYPE_XMIT, &msg2, foreground);
+ callout_mgr_set_prio(&xbeeboard.intr_cm, prio);
- return 0;
+ return ret;
}
static void evt_timeout(struct callout_mgr *cm, struct callout *clt,
callout_stop(&xbeeboard.mainloop_cm, &ctx->timeout);
}
+static void xbee_rx_poll_timer_cb(struct callout_mgr *cm, struct callout *tim,
+ void *arg)
+{
+ (void) arg;
+ xbee_rx(xbee_dev);
+ callout_reschedule(cm, tim, XBEE_POLL_TIMER_MS);
+}
+
void xbee_mainloop(void)
{
+ uint8_t prio;
+
while (1) {
callout_manage(&xbeeboard.mainloop_cm);
/* from cmdline to xbee */
c = cmdline_dev_recv(NULL);
if (c == 4) { /* CTRL-d */
+ prio = callout_mgr_set_prio(&xbeeboard.intr_cm,
+ XBEE_PRIO);
xbee_dev_send('A', NULL);
xbee_dev_send('T', NULL);
xbee_dev_send('C', NULL);
xbee_dev_send('N', NULL);
xbee_dev_send('\n', NULL);
+ callout_mgr_set_prio(&xbeeboard.intr_cm, prio);
xbee_raw = 0;
rdline_newline(&xbeeboard.rdl,
xbeeboard.prompt);
else {
if (xbee_cmdline_input_enabled)
cmdline_poll();
- xbee_rx(xbee_dev);
+ /* xbee rx polling is done in a timer, so we can block
+ * the cmdline without loosing incoming packets */
}
}
}
{
xbee_cmdline_input_enabled = 0;
}
+
+void xbeeapp_init(void)
+{
+ callout_init(&xbeeboard.xbee_rx_poll_timer, xbee_rx_poll_timer_cb,
+ NULL, XBEE_PRIO);
+ callout_schedule(&xbeeboard.intr_cm,
+ &xbeeboard.xbee_rx_poll_timer, XBEE_POLL_TIMER_MS);
+}