summaryrefslogtreecommitdiff
path: root/samples/nfc
diff options
context:
space:
mode:
authorFlavio Santes <flavio.santes@intel.com>2016-11-24 13:58:25 -0600
committerAnas Nashif <nashif@linux.intel.com>2016-11-25 16:50:20 +0000
commit5f52743f094eb13b9a7726e63916ee06f7dc8105 (patch)
tree24a480f900b57639928ae5368978230bbb30d0c8 /samples/nfc
parent90fefd6dd46d73fb857f43ec5094a99586549cbf (diff)
samples/nfc: Update sample app
This commit updates the nfc_hello sample application: - Use new kernel API - Update testcase.ini platform whitelist - Coding style issues Jira: ZEP-1348 Change-Id: I2c17e40d654e33a46af02ee2f20d4a88136fcf2d Signed-off-by: Flavio Santes <flavio.santes@intel.com>
Diffstat (limited to 'samples/nfc')
-rw-r--r--samples/nfc/nfc_hello/src/main.c55
-rw-r--r--samples/nfc/nfc_hello/testcase.ini4
2 files changed, 26 insertions, 33 deletions
diff --git a/samples/nfc/nfc_hello/src/main.c b/samples/nfc/nfc_hello/src/main.c
index c462be1f9..9bc8c7216 100644
--- a/samples/nfc/nfc_hello/src/main.c
+++ b/samples/nfc/nfc_hello/src/main.c
@@ -18,39 +18,35 @@
#include <stdio.h>
#include <stdint.h>
#include <string.h>
-
#include <board.h>
#include <uart.h>
+#include <misc/byteorder.h>
-#include <misc/byteorder.h> /* for sys_cpu_to_be32 */
-
-#define BUF_MAXSIZE 256
-
-struct device *uart1_dev;
-
-#define D(fmt, args...) \
-do { \
- printf("%s() " fmt "\n", __func__, ## args); \
-} while (0)
-
+#define BUF_MAXSIZE 256
+#define SLEEP_TIME 500
-static uint8_t buf[BUF_MAXSIZE];
-static uint8_t nci_reset[] = { 0x20, 0x00, 0x01, 0x00 };
+static struct device *uart1_dev;
+static uint8_t rx_buf[BUF_MAXSIZE];
+static uint8_t tx_buf[BUF_MAXSIZE];
+static uint8_t nci_reset[] = {0x20, 0x00, 0x01, 0x00};
static void msg_dump(const char *s, uint8_t *data, unsigned len)
{
unsigned i;
+
printf("%s: ", s);
- for (i = 0; i < len; i++)
+ for (i = 0; i < len; i++) {
printf("%02x ", data[i]);
+ }
printf("(%u bytes)\n", len);
}
static void uart1_isr(struct device *x)
{
- int len = uart_fifo_read(uart1_dev, buf, BUF_MAXSIZE);
+ int len = uart_fifo_read(uart1_dev, rx_buf, BUF_MAXSIZE);
+
ARG_UNUSED(x);
- msg_dump(__func__, buf, len);
+ msg_dump(__func__, rx_buf, len);
}
static void uart1_init(void)
@@ -58,33 +54,32 @@ static void uart1_init(void)
uart1_dev = device_get_binding("UART_1");
uart_irq_callback_set(uart1_dev, uart1_isr);
-
uart_irq_rx_enable(uart1_dev);
- D("done");
+ printf("%s() done\n", __func__);
}
void main(void)
{
- struct nano_timer t;
- void *t_data;
- uint8_t *pdu = buf;
- uint32_t *len = (void *) pdu;
+ uint32_t *size = (uint32_t *)tx_buf;
printf("Sample app running on: %s\n", CONFIG_ARCH);
- nano_timer_init(&t, &t_data);
-
uart1_init();
- *len = sys_cpu_to_be32(sizeof(nci_reset));
+ /* 4 bytes for the payload's length */
+ UNALIGNED_PUT(sys_cpu_to_be32(sizeof(nci_reset)), size);
- memcpy(pdu + sizeof(*len), nci_reset, sizeof(nci_reset));
+ /* NFC Controller Interface reset cmd */
+ memcpy(tx_buf + sizeof(uint32_t), nci_reset, sizeof(nci_reset));
- uart_fifo_fill(uart1_dev, pdu, sizeof(*len) + sizeof(nci_reset));
+ /*
+ * Peer will receive: 0x00 0x00 0x00 0x04 0x20 0x00 0x01 0x00
+ * nci_reset size + nci_reset cmd
+ */
+ uart_fifo_fill(uart1_dev, tx_buf, sizeof(uint32_t) + sizeof(nci_reset));
while (1) {
- nano_task_timer_start(&t, MSEC(500));
- nano_task_timer_test(&t, TICKS_UNLIMITED);
+ k_sleep(SLEEP_TIME);
}
}
diff --git a/samples/nfc/nfc_hello/testcase.ini b/samples/nfc/nfc_hello/testcase.ini
index a378e13a9..1ec4c6201 100644
--- a/samples/nfc/nfc_hello/testcase.ini
+++ b/samples/nfc/nfc_hello/testcase.ini
@@ -1,7 +1,5 @@
[test]
build_only = true
tags = apps
-arch_whitelist = x86
-# Doesn't work for ia32_pci
-filter = CONFIG_SOC == "ia32"
+arch_whitelist = x86 arm