From f4c812bef76a2cd95f675cb27ea89059561ceec7 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 13 Feb 2015 23:51:10 -0800 Subject: altos: Replace ao_alarm/ao_clear_alarm with ao_sleep_for Having arbitrary alarms firing in the middle of complicated device logic makes no sense at all. Therefore only correct use of ao_alarm and ao_clear_alarm was around a specific ao_sleep call, with correct recovery in case the alarm fires. This patch replaces all uses of ao_alarm/ao_sleep/ao_clear_alarm with ao_sleep_for, a new function which takes the alarm timeout directly. A few cases which weren't simply calling ao_sleep have been reworked to pass the timeout value down to the place where sleep *is* being called, and having that code deal with the return correctly. Signed-off-by: Keith Packard --- src/kernel/ao_packet.h | 2 +- src/kernel/ao_pyro.c | 4 +--- src/kernel/ao_serial.h | 8 ++++---- src/kernel/ao_task.c | 20 +++++++++++++++----- src/kernel/ao_task.h | 10 ++++++++++ src/kernel/ao_telemetry.c | 4 +--- 6 files changed, 32 insertions(+), 16 deletions(-) (limited to 'src/kernel') diff --git a/src/kernel/ao_packet.h b/src/kernel/ao_packet.h index b8426cf9..136609c3 100644 --- a/src/kernel/ao_packet.h +++ b/src/kernel/ao_packet.h @@ -54,7 +54,7 @@ void ao_packet_send(void); uint8_t -ao_packet_recv(void); +ao_packet_recv(uint16_t timeout); void ao_packet_flush(void); diff --git a/src/kernel/ao_pyro.c b/src/kernel/ao_pyro.c index 3044d565..43e73de4 100644 --- a/src/kernel/ao_pyro.c +++ b/src/kernel/ao_pyro.c @@ -375,9 +375,7 @@ ao_pyro(void) ao_sleep(&ao_flight_state); for (;;) { - ao_alarm(AO_MS_TO_TICKS(100)); - ao_sleep(&ao_pyro_wakeup); - ao_clear_alarm(); + ao_sleep_for(&ao_pyro_wakeup, AO_MS_TO_TICKS(100)); if (ao_flight_state >= ao_flight_landed) break; any_waiting = ao_pyro_check(); diff --git a/src/kernel/ao_serial.h b/src/kernel/ao_serial.h index dbc9f8e4..e21643ac 100644 --- a/src/kernel/ao_serial.h +++ b/src/kernel/ao_serial.h @@ -35,7 +35,7 @@ int _ao_serial0_pollchar(void); uint8_t -_ao_serial0_sleep(void); +_ao_serial0_sleep_for(uint16_t timeout); void ao_serial0_putchar(char c); @@ -58,7 +58,7 @@ int _ao_serial1_pollchar(void); uint8_t -_ao_serial1_sleep(void); +_ao_serial1_sleep_for(uint16_t timeout); void ao_serial1_putchar(char c); @@ -81,7 +81,7 @@ int _ao_serial2_pollchar(void); uint8_t -_ao_serial2_sleep(void); +_ao_serial2_sleep_for(uint16_t timeout); void ao_serial2_putchar(char c); @@ -104,7 +104,7 @@ int _ao_serial3_pollchar(void); uint8_t -_ao_serial3_sleep(void); +_ao_serial3_sleep_for(uint16_t timeout); void ao_serial3_putchar(char c); diff --git a/src/kernel/ao_task.c b/src/kernel/ao_task.c index bafb4943..1ecdd7dd 100644 --- a/src/kernel/ao_task.c +++ b/src/kernel/ao_task.c @@ -450,7 +450,7 @@ ao_wakeup(__xdata void *wchan) __reentrant ao_check_stack(); } -void +static void ao_alarm(uint16_t delay) { #if HAS_TASK_QUEUE @@ -468,7 +468,7 @@ ao_alarm(uint16_t delay) #endif } -void +static void ao_clear_alarm(void) { #if HAS_TASK_QUEUE @@ -483,14 +483,24 @@ ao_clear_alarm(void) #endif } +uint8_t +ao_sleep_for(__xdata void *wchan, uint16_t timeout) +{ + uint8_t ret; + if (timeout) + ao_alarm(timeout); + ret = ao_sleep(wchan); + if (timeout) + ao_clear_alarm(); + return ret; +} + static __xdata uint8_t ao_forever; void ao_delay(uint16_t ticks) { - ao_alarm(ticks); - ao_sleep(&ao_forever); - ao_clear_alarm(); + ao_sleep_for(&ao_forever, ticks); } void diff --git a/src/kernel/ao_task.h b/src/kernel/ao_task.h index 9c56b480..c6bec0e3 100644 --- a/src/kernel/ao_task.h +++ b/src/kernel/ao_task.h @@ -68,10 +68,19 @@ extern __data uint8_t ao_task_minimize_latency; /* Reduce IRQ latency */ uint8_t ao_sleep(__xdata void *wchan); +/* Suspend the current task until wchan is awoken or the timeout + * expires. returns: + * 0 on normal wake + * 1 on alarm + */ +uint8_t +ao_sleep_for(__xdata void *wchan, uint16_t timeout); + /* Wake all tasks sleeping on wchan */ void ao_wakeup(__xdata void *wchan) __reentrant; +#if 0 /* set an alarm to go off in 'delay' ticks */ void ao_alarm(uint16_t delay); @@ -79,6 +88,7 @@ ao_alarm(uint16_t delay); /* Clear any pending alarm */ void ao_clear_alarm(void); +#endif /* Yield the processor to another task */ void diff --git a/src/kernel/ao_telemetry.c b/src/kernel/ao_telemetry.c index e2197f7a..854ac898 100644 --- a/src/kernel/ao_telemetry.c +++ b/src/kernel/ao_telemetry.c @@ -486,9 +486,7 @@ ao_telemetry(void) #endif /* HAS_APRS */ delay = time - ao_time(); if (delay > 0) { - ao_alarm(delay); - ao_sleep(&telemetry); - ao_clear_alarm(); + ao_sleep_for(&telemetry, delay); } } } -- cgit v1.2.3 From 9c75faf1ec51eb2f9a8dc9402653490143a784d9 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 14 Feb 2015 08:35:47 -0800 Subject: altos: embed ao_alarm and ao_clear_alarm in ao_sleep_for sdcc won't embed these itself, and thus consumes too much flash for telemetrum-v1.0 Signed-off-by: Keith Packard --- src/kernel/ao_task.c | 54 +++++++++++++++++++++------------------------------- 1 file changed, 22 insertions(+), 32 deletions(-) (limited to 'src/kernel') diff --git a/src/kernel/ao_task.c b/src/kernel/ao_task.c index 1ecdd7dd..55e423bb 100644 --- a/src/kernel/ao_task.c +++ b/src/kernel/ao_task.c @@ -450,48 +450,38 @@ ao_wakeup(__xdata void *wchan) __reentrant ao_check_stack(); } -static void -ao_alarm(uint16_t delay) +uint8_t +ao_sleep_for(__xdata void *wchan, uint16_t timeout) { + uint8_t ret; + if (timeout) { #if HAS_TASK_QUEUE - uint32_t flags; - /* Make sure we sleep *at least* delay ticks, which means adding - * one to account for the fact that we may be close to the next tick - */ - flags = ao_arch_irqsave(); + uint32_t flags; + /* Make sure we sleep *at least* delay ticks, which means adding + * one to account for the fact that we may be close to the next tick + */ + flags = ao_arch_irqsave(); #endif - if (!(ao_cur_task->alarm = ao_time() + delay + 1)) - ao_cur_task->alarm = 1; + if (!(ao_cur_task->alarm = ao_time() + timeout + 1)) + ao_cur_task->alarm = 1; #if HAS_TASK_QUEUE - ao_task_to_alarm_queue(ao_cur_task); - ao_arch_irqrestore(flags); + ao_task_to_alarm_queue(ao_cur_task); + ao_arch_irqrestore(flags); #endif -} - -static void -ao_clear_alarm(void) -{ + } + ret = ao_sleep(wchan); + if (timeout) { #if HAS_TASK_QUEUE - uint32_t flags; + uint32_t flags; - flags = ao_arch_irqsave(); + flags = ao_arch_irqsave(); #endif - ao_cur_task->alarm = 0; + ao_cur_task->alarm = 0; #if HAS_TASK_QUEUE - ao_task_from_alarm_queue(ao_cur_task); - ao_arch_irqrestore(flags); + ao_task_from_alarm_queue(ao_cur_task); + ao_arch_irqrestore(flags); #endif -} - -uint8_t -ao_sleep_for(__xdata void *wchan, uint16_t timeout) -{ - uint8_t ret; - if (timeout) - ao_alarm(timeout); - ret = ao_sleep(wchan); - if (timeout) - ao_clear_alarm(); + } return ret; } -- cgit v1.2.3 From ec2d758844202108b446e6b12ec1da8812ceb265 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 28 Feb 2015 15:07:16 -0800 Subject: altos: Allow software to offer other USB interface classes than CDC This lets some boards offer non-CDC class USB interfaces so that the modem driver doesn't pick them up. Signed-off-by: Keith Packard --- src/kernel/ao_product.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/kernel') diff --git a/src/kernel/ao_product.c b/src/kernel/ao_product.c index b9327bac..baee8dd6 100644 --- a/src/kernel/ao_product.c +++ b/src/kernel/ao_product.c @@ -33,6 +33,10 @@ const char ao_product[] = AO_iProduct_STRING; #define AO_USB_MAX_POWER 100 #endif +#ifndef AO_USB_INTERFACE_CLASS +#define AO_USB_INTERFACE_CLASS 0x02 +#endif + #include "ao_usb.h" /* USB descriptors in one giant block of bytes */ AO_ROMCONFIG_SYMBOL(0x00aa) uint8_t ao_usb_descriptors [] = @@ -69,7 +73,7 @@ AO_ROMCONFIG_SYMBOL(0x00aa) uint8_t ao_usb_descriptors [] = 0x00, /* bInterfaceNumber */ 0x00, /* bAlternateSetting */ 0x01, /* bNumEndPoints */ - 0x02, /* bInterfaceClass */ + AO_USB_INTERFACE_CLASS, /* bInterfaceClass */ 0x02, /* bInterfaceSubClass */ 0x01, /* bInterfaceProtocol, linux requires value of 1 for the cdc_acm module */ 0x00, /* iInterface */ -- cgit v1.2.3 From 2614d20b324ab215ef22f178e3635d48e757fa9b Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 2 Mar 2015 21:02:31 -0800 Subject: altos: Make APRS format (compressed/uncompressed) configurable This provides a choice of compressed vs uncompressed when sending APRS packets to deal with receivers that still do not have support for the more useful compressed format. Signed-off-by: Keith Packard --- src/drivers/ao_aprs.c | 98 +++++++++++++++++++++++++++++++++++++++++--------- src/kernel/ao_config.c | 23 ++++++++++++ src/kernel/ao_config.h | 9 ++++- 3 files changed, 112 insertions(+), 18 deletions(-) (limited to 'src/kernel') diff --git a/src/drivers/ao_aprs.c b/src/drivers/ao_aprs.c index 19beb78f..2e977612 100644 --- a/src/drivers/ao_aprs.c +++ b/src/drivers/ao_aprs.c @@ -707,8 +707,7 @@ static int tncPositionPacket(void) static int32_t latitude; static int32_t longitude; static int32_t altitude; - int32_t lat, lon, alt; - uint8_t *buf; + uint8_t *buf; if (ao_gps_data.flags & AO_GPS_VALID) { latitude = ao_gps_data.latitude; @@ -719,28 +718,93 @@ static int tncPositionPacket(void) } buf = tncBuffer; - *buf++ = '!'; - /* Symbol table ID */ - *buf++ = '/'; + switch (ao_config.aprs_format) { + case AO_APRS_FORMAT_COMPRESSED: + default: + { + int32_t lat, lon, alt; + + *buf++ = '!'; + + /* Symbol table ID */ + *buf++ = '/'; + + lat = ((uint64_t) 380926 * (900000000 - latitude)) / 10000000; + lon = ((uint64_t) 190463 * (1800000000 + longitude)) / 10000000; + + alt = ao_aprs_encode_altitude(altitude); + + tncCompressInt(buf, lat, 4); + buf += 4; + tncCompressInt(buf, lon, 4); + buf += 4; - lat = ((uint64_t) 380926 * (900000000 - latitude)) / 10000000; - lon = ((uint64_t) 190463 * (1800000000 + longitude)) / 10000000; + /* Symbol code */ + *buf++ = '\''; - alt = ao_aprs_encode_altitude(altitude); + tncCompressInt(buf, alt, 2); + buf += 2; - tncCompressInt(buf, lat, 4); - buf += 4; - tncCompressInt(buf, lon, 4); - buf += 4; + *buf++ = 33 + ((1 << 5) | (2 << 3)); - /* Symbol code */ - *buf++ = '\''; + break; + } + case AO_APRS_FORMAT_UNCOMPRESSED: + { + char lat_sign = 'N', lon_sign = 'E'; + int32_t lat = latitude; + int32_t lon = longitude; + int32_t alt = altitude; + uint16_t lat_deg; + uint16_t lon_deg; + uint16_t lat_min; + uint16_t lat_frac; + uint16_t lon_min; + uint16_t lon_frac; + + if (lat < 0) { + lat_sign = 'S'; + lat = -lat; + } - tncCompressInt(buf, alt, 2); - buf += 2; + if (lon < 0) { + lon_sign = 'W'; + lon = -lon; + } - *buf++ = 33 + ((1 << 5) | (2 << 3)); + /* Round latitude and longitude by 0.005 minutes */ + lat = lat + 833; + if (lat > 900000000) + lat = 900000000; + lon = lon + 833; + if (lon > 1800000000) + lon = 1800000000; + + lat_deg = lat / 10000000; + lat -= lat_deg * 10000000; + lat *= 60; + lat_min = lat / 10000000; + lat -= lat_min * 10000000; + lat_frac = lat / 100000; + + lon_deg = lon / 10000000; + lon -= lon_deg * 10000000; + lon *= 60; + lon_min = lon / 10000000; + lon -= lon_min * 10000000; + lon_frac = lon / 100000; + + /* Convert from meters to feet */ + alt = (alt * 328 + 50) / 100; + + buf += sprintf((char *) tncBuffer, "!%02u%02u.%02u%c/%03u%02u.%02u%c'/A=%06u ", + lat_deg, lat_min, lat_frac, lat_sign, + lon_deg, lon_min, lon_frac, lon_sign, + alt); + break; + } + } buf += tncComment(buf); diff --git a/src/kernel/ao_config.c b/src/kernel/ao_config.c index 8dab7c42..b0d3e541 100644 --- a/src/kernel/ao_config.c +++ b/src/kernel/ao_config.c @@ -219,6 +219,10 @@ _ao_config_get(void) #if HAS_RADIO_FORWARD if (minor < 21) ao_config.send_frequency = 434550; +#endif +#if HAS_APRS + if (minor < 22) + ao_config.aprs_format = AO_CONFIG_DEFAULT_APRS_FORMAT; #endif ao_config.minor = AO_CONFIG_MINOR; ao_config_dirty = 1; @@ -876,6 +880,23 @@ ao_config_aprs_ssid_set(void) ao_config.aprs_ssid = ao_cmd_lex_i; _ao_config_edit_finish(); } + +void +ao_config_aprs_format_set(void) +{ + ao_cmd_decimal(); + if (ao_cmd_status != ao_cmd_success) + return; + _ao_config_edit_start(); + ao_config.aprs_format = ao_cmd_lex_i != 0; + _ao_config_edit_finish(); +} + +void +ao_config_aprs_format_show(void) +{ + printf ("APRS format: %d\n", ao_config.aprs_format); +} #endif /* HAS_APRS */ struct ao_config_var { @@ -969,6 +990,8 @@ __code struct ao_config_var ao_config_vars[] = { #if HAS_APRS { "S \0Set APRS SSID (0-15)", ao_config_aprs_ssid_set, ao_config_aprs_ssid_show }, + { "C <0 compressed, 1 uncompressed>\0APRS format", + ao_config_aprs_format_set, ao_config_aprs_format_show }, #endif { "s\0Show", ao_config_show, 0 }, diff --git a/src/kernel/ao_config.h b/src/kernel/ao_config.h index 164584a5..cfe8555c 100644 --- a/src/kernel/ao_config.h +++ b/src/kernel/ao_config.h @@ -57,7 +57,7 @@ #endif #define AO_CONFIG_MAJOR 1 -#define AO_CONFIG_MINOR 21 +#define AO_CONFIG_MINOR 22 #define AO_AES_LEN 16 @@ -115,8 +115,15 @@ struct ao_config { #if HAS_RADIO_FORWARD uint32_t send_frequency; /* minor version 21 */ #endif +#if HAS_APRS + uint8_t aprs_format; /* minor version 22 */ +#endif }; +#define AO_APRS_FORMAT_COMPRESSED 0 +#define AO_APRS_FORMAT_UNCOMPRESSED 1 +#define AO_CONFIG_DEFAULT_APRS_FORMAT AO_APRS_FORMAT_COMPRESSED + #if HAS_RADIO_FORWARD extern __xdata uint32_t ao_send_radio_setting; #endif -- cgit v1.2.3 From bef7c89dac68956a94ae386fa6b87165ab6cb484 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 2 Mar 2015 21:16:06 -0800 Subject: altos: Missing pad field in TMv2 data packet The normal ARM padding would have filled this in correctly, but it's best to be explicit about the structure. This also adds a test to make sure the resulting telemetry declaration is exactly 32 bytes, Signed-off-by: Keith Packard --- src/kernel/ao_telemetry.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/kernel') diff --git a/src/kernel/ao_telemetry.h b/src/kernel/ao_telemetry.h index 711e0d36..672d2317 100644 --- a/src/kernel/ao_telemetry.h +++ b/src/kernel/ao_telemetry.h @@ -258,13 +258,14 @@ struct ao_telemetry_metrum_data { uint16_t serial; /* 0 */ uint16_t tick; /* 2 */ uint8_t type; /* 4 */ + uint8_t pad5[3]; /* 5 */ - int32_t ground_pres; /* 8 average pres on pad */ + int32_t ground_pres; /* 8 average pres on pad */ int16_t ground_accel; /* 12 average accel on pad */ int16_t accel_plus_g; /* 14 accel calibration at +1g */ int16_t accel_minus_g; /* 16 accel calibration at -1g */ - uint8_t pad[14]; /* 18 */ + uint8_t pad18[14]; /* 18 */ /* 32 */ }; @@ -332,6 +333,8 @@ union ao_telemetry_all { struct ao_telemetry_baro baro; }; +typedef char ao_check_telemetry_size[sizeof(union ao_telemetry_all) == 32 ? 1 : -1]; + struct ao_telemetry_all_recv { union ao_telemetry_all telemetry; int8_t rssi; -- cgit v1.2.3 From c3321bd9f73c89686fe983a8d99f4e54fa91550e Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 19 Mar 2015 01:11:33 -0700 Subject: altos: Add the ability to configure a different USB vendor ID ChaosKey will use an OpenMoko vid/pid, so we need the ability to configure a different USB vendor ID for each product. Signed-off-by: Keith Packard --- src/kernel/ao_product.c | 2 +- src/util/ao-make-product.5c | 49 +++++++++++++++++++++++++++++++-------------- 2 files changed, 35 insertions(+), 16 deletions(-) (limited to 'src/kernel') diff --git a/src/kernel/ao_product.c b/src/kernel/ao_product.c index baee8dd6..c711a4d2 100644 --- a/src/kernel/ao_product.c +++ b/src/kernel/ao_product.c @@ -49,7 +49,7 @@ AO_ROMCONFIG_SYMBOL(0x00aa) uint8_t ao_usb_descriptors [] = 0x00, /* bDeviceSubClass */ 0x00, /* bDeviceProtocol */ AO_USB_CONTROL_SIZE, /* bMaxPacketSize */ - LE_WORD(0xFFFE), /* idVendor */ + LE_WORD(AO_idVendor_NUMBER), /* idVendor */ LE_WORD(AO_idProduct_NUMBER), /* idProduct */ LE_WORD(0x0100), /* bcdDevice */ 0x01, /* iManufacturer */ diff --git a/src/util/ao-make-product.5c b/src/util/ao-make-product.5c index 5f2eb8e8..3ab8d16e 100644 --- a/src/util/ao-make-product.5c +++ b/src/util/ao-make-product.5c @@ -1,54 +1,58 @@ -#!/bin/sh +#!/usr/bin/nickle autoimport ParseArgs; +file out = stdout; + void write_ucs2(string a, string description) { int len = String::length(a); - printf("/* %s */\n", description); - printf("#define AO_%s_LEN 0x%02x\n", description, len * 2 + 2); - printf("#define AO_%s_STRING \"%s\"\n", description, a); - printf("#define AO_%s_UCS2", description); + File::fprintf(out, "/* %s */\n", description); + File::fprintf(out, "#define AO_%s_LEN 0x%02x\n", description, len * 2 + 2); + File::fprintf(out, "#define AO_%s_STRING \"%s\"\n", description, a); + File::fprintf(out, "#define AO_%s_UCS2", description); for (int i = 0; i < len; i++) { int c = a[i]; if (i > 0) - printf(","); + File::fprintf(out, ","); if (0x20 <= c && c < 128) - printf(" '%c', 0", c); + File::fprintf(out, " '%c', 0", c); else - printf(" LE_WORD(0x%04x),", c); + File::fprintf(out, " LE_WORD(0x%04x),", c); } - printf("\n\n"); + File::fprintf(out, "\n\n"); } void write_string(string a, string description) { - printf ("/* %s */\n", description); - printf ("#define AO_%s_STRING \"%s\"\n", description, a); + File::fprintf(out, "/* %s */\n", description); + File::fprintf(out, "#define AO_%s_STRING \"%s\"\n", description, a); } void write_int(int a, string description) { - printf ("/* %s */\n", description); - printf ("#define AO_%s_NUMBER %d\n\n", description, a); + File::fprintf(out, "/* %s */\n", description); + File::fprintf(out, "#define AO_%s_NUMBER %d\n\n", description, a); } void write_hex(int a, string description) { - printf ("/* %s */\n", description); - printf ("#define AO_%s_NUMBER 0x%04x\n\n", description, a); + File::fprintf(out, "/* %s */\n", description); + File::fprintf(out, "#define AO_%s_NUMBER 0x%04x\n\n", description, a); } string manufacturer = "altusmetrum.org"; string product = "TeleMetrum"; string version = "0.0"; +string output = ""; int serial = 1; int user_argind = 0; +int id_vendor = 0xfffe; int id_product = 0x000a; argdesc argd = { @@ -65,6 +69,12 @@ argdesc argd = { .name = "product", .expr_name = "prod", .desc = "Product name." }, + { + .var = { .arg_int = &id_vendor }, + .abbr = 'V', + .name = "id_vendor", + .expr_name = "id_v", + .desc = "Vendor ID." }, { .var = { .arg_int = &id_product }, .abbr = 'i', @@ -83,6 +93,12 @@ argdesc argd = { .name = "version", .expr_name = "string", .desc = "Program version." }, + { + .var = { .arg_string = &output }, + .abbr = 'o', + .name = "output", + .expr_name = "out", + .desc = "Output file." }, }, .prog_name = "usb descriptors", }; @@ -92,11 +108,14 @@ main() { string[dim(argv)-1] nargv = {[n] = argv[n+1]}; parseargs(&argd, &nargv); + if (output != "") + out = File::open(output, "w"); write_ucs2(manufacturer, "iManufacturer"); write_ucs2(product, "iProduct"); write_ucs2(sprintf("%06d", serial), "iSerial"); write_int(serial, "iSerial"); write_hex(id_product, "idProduct"); + write_hex(id_vendor, "idVendor"); write_string(version, "iVersion"); } -- cgit v1.2.3 From 0e76cb2a7d5db24b6cecdccb6fb8d5bf5527fadf Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 24 May 2015 17:28:07 -0700 Subject: altos: Only set CMAC RSSI value on valid packet received This ignores spurious packets for the purpose of showing the RSSI value in telelco/telefire, avoiding warning about 'low RSSI' when the radio receives noise. Signed-off-by: Keith Packard --- src/kernel/ao_radio_cmac.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/kernel') diff --git a/src/kernel/ao_radio_cmac.c b/src/kernel/ao_radio_cmac.c index bff848f6..b6835346 100644 --- a/src/kernel/ao_radio_cmac.c +++ b/src/kernel/ao_radio_cmac.c @@ -91,7 +91,6 @@ radio_cmac_recv(uint8_t len, uint16_t timeout) __reentrant return AO_RADIO_CMAC_TIMEOUT; } - ao_radio_cmac_rssi = ao_radio_rssi; if (!(cmac_data[len + AO_CMAC_KEY_LEN +1] & AO_RADIO_STATUS_CRC_OK)) return AO_RADIO_CMAC_CRC_ERROR; @@ -114,13 +113,15 @@ radio_cmac_recv(uint8_t len, uint16_t timeout) __reentrant /* Check the packet signature against the signature provided * over the link */ - + if (memcmp(&cmac_data[len], &cmac_data[len + AO_CMAC_KEY_LEN + 2], AO_CMAC_KEY_LEN) != 0) { return AO_RADIO_CMAC_MAC_ERROR; } + ao_radio_cmac_rssi = ao_radio_rssi; + return AO_RADIO_CMAC_OK; } @@ -161,4 +162,3 @@ ao_radio_cmac_recv(__xdata void *packet, uint8_t len, uint16_t timeout) __reentr ao_mutex_put(&ao_radio_cmac_mutex); return i; } - -- cgit v1.2.3