Acknowledgements and following TRD.
@@ -19,11 +19,13 @@ const int COM_CHAN = 3;
const int COM_POWER = 4;
const int COM_TX = 5;
const int COM_READY = 6;
+const int COM_COMMIT = 7;
const int EVT_TX = 0;
const int EVT_RX = 1;
+const int EVT_CFG = 2;
-int radio_init(void) {
+int radio_init() {
while (!radio_ready()) {}
return 0;
} // Do nothing for now
@@ -42,16 +44,18 @@ static void cb_rx( __attribute__ ((unused)) int unused0,
*((bool*)ud) = true;
}
+static void cb_config( __attribute__ ((unused)) int unused0,
+ __attribute__ ((unused)) int unused1,
+ __attribute__ ((unused)) int unused2,
+ void* ud) {
+ *((bool*)ud) = true;
+}
+
// packet contains the payload of the 802.15.4 packet; this will
// be copied into a packet buffer with header space within the kernel.
int radio_send(unsigned short addr, const char* packet, unsigned char len) {
bool cond = false;
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wcast-qual"
- // in lieu of RO allow
- void* buf = (void*) packet;
-#pragma GCC diagnostic pop
- int err = allow(SYS_RADIO, BUF_TX, buf, len);
+ int err = allow(SYS_RADIO, BUF_TX, (void*)packet, len);
if (err < 0) {
return err;
}
@@ -83,6 +87,25 @@ int radio_set_addr(unsigned short addr) {
int radio_set_pan(unsigned short pan) {
return command(SYS_RADIO, COM_PAN, (unsigned int)pan);
}
+
+int radio_set_power(char power) {
+ return command(SYS_RADIO, COM_POWER, (unsigned int) (power + 128));
+}
+
+int radio_commit() {
+ bool cond = false;
+ int err = subscribe(SYS_RADIO, EVT_CFG, cb_config, &cond);
+ if (err != SUCCESS) {
+ return err;
+ }
+ err = command(SYS_RADIO, COM_COMMIT, 0);
+ if (err != SUCCESS) {
+ return err;
+ }
+ yield_for(&cond);
+ return SUCCESS;
+}
+
// Valid channels are 10-26
int radio_set_channel(unsigned char channel) {
return command(SYS_RADIO, COM_CHAN, (unsigned int)channel);
@@ -90,12 +113,7 @@ int radio_set_channel(unsigned char channel) {
int radio_receive(const char* packet, unsigned char len) {
bool cond = false;
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wcast-qual"
- // in lieu of RO allow
- void* buf = (void*) packet;
-#pragma GCC diagnostic pop
- int err = allow(SYS_RADIO, BUF_RX, buf, len);
+ int err = allow(SYS_RADIO, BUF_RX, (void*)packet, len);
if (err < 0) {
return err;
}
@@ -107,6 +125,6 @@ int radio_receive(const char* packet, unsigned char len) {
return (int)packet[1];
}
-int radio_ready(void) {
+int radio_ready() {
return command(SYS_RADIO, COM_READY, 0) == SUCCESS;
}
