diff options
author | Anas Nashif <anas.nashif@intel.com> | 2016-10-21 21:44:52 -0400 |
---|---|---|
committer | Anas Nashif <nashif@linux.intel.com> | 2016-10-27 22:13:36 +0000 |
commit | 36e1e2dbaf2527101ba933262931c9a45d4d14b7 (patch) | |
tree | 143a756a0019b8308269bea6f6269d96541466eb /tests | |
parent | 5662110ec4fad341701d1edb0cbc5d84b4c07e7e (diff) |
move tests from samples to tests/
Change-Id: Ib183936134d27ff84d9af57e8e2e2d9f0cc2670f
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/drivers/adc/Makefile | 5 | ||||
-rw-r--r-- | tests/drivers/adc/prj.conf | 2 | ||||
-rw-r--r-- | tests/drivers/adc/src/Makefile | 1 | ||||
-rw-r--r-- | tests/drivers/adc/src/main.c | 93 | ||||
-rw-r--r-- | tests/drivers/adc/testcase.ini | 4 | ||||
-rw-r--r-- | tests/drivers/aon_counter/Makefile | 5 | ||||
-rw-r--r-- | tests/drivers/aon_counter/README.txt | 92 | ||||
-rw-r--r-- | tests/drivers/aon_counter/prj.conf | 2 | ||||
-rw-r--r-- | tests/drivers/aon_counter/src/Makefile | 1 | ||||
-rw-r--r-- | tests/drivers/aon_counter/src/main.c | 166 | ||||
-rw-r--r-- | tests/drivers/aon_counter/testcase.ini | 4 | ||||
-rw-r--r-- | tests/drivers/dma/Makefile | 5 | ||||
-rw-r--r-- | tests/drivers/dma/prj.conf | 2 | ||||
-rw-r--r-- | tests/drivers/dma/src/Makefile | 3 | ||||
-rw-r--r-- | tests/drivers/dma/src/dma.c | 133 | ||||
-rw-r--r-- | tests/drivers/dma/testcase.ini | 4 | ||||
-rw-r--r-- | tests/drivers/uart/Makefile | 5 | ||||
-rw-r--r-- | tests/drivers/uart/prj.conf | 2 | ||||
-rw-r--r-- | tests/drivers/uart/src/Makefile | 1 | ||||
-rw-r--r-- | tests/drivers/uart/src/main.c | 113 |
20 files changed, 643 insertions, 0 deletions
diff --git a/tests/drivers/adc/Makefile b/tests/drivers/adc/Makefile new file mode 100644 index 000000000..601d75890 --- /dev/null +++ b/tests/drivers/adc/Makefile @@ -0,0 +1,5 @@ +BOARD ?= quark_se_c1000_ss_devboard +KERNEL_TYPE = nano +CONF_FILE = prj.conf + +include ${ZEPHYR_BASE}/Makefile.inc diff --git a/tests/drivers/adc/prj.conf b/tests/drivers/adc/prj.conf new file mode 100644 index 000000000..7428c6f9f --- /dev/null +++ b/tests/drivers/adc/prj.conf @@ -0,0 +1,2 @@ +CONFIG_ADC=y +CONFIG_ADC_DEBUG=y diff --git a/tests/drivers/adc/src/Makefile b/tests/drivers/adc/src/Makefile new file mode 100644 index 000000000..00066e156 --- /dev/null +++ b/tests/drivers/adc/src/Makefile @@ -0,0 +1 @@ +obj-y = main.o diff --git a/tests/drivers/adc/src/main.c b/tests/drivers/adc/src/main.c new file mode 100644 index 000000000..29d546c92 --- /dev/null +++ b/tests/drivers/adc/src/main.c @@ -0,0 +1,93 @@ +/* adc.c - ADC test source file */ + +/* + * Copyright (c) 2015 Intel Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <zephyr.h> + +#include <device.h> +#include <misc/byteorder.h> +#include <adc.h> +#include <misc/printk.h> + +#define SLEEPTIME 2 +#define SLEEPTICKS (SLEEPTIME * sys_clock_ticks_per_sec) + +#define ADC_DEVICE_NAME "ADC_0" + +/* + * The analog input pin and channel number mapping + * for Arduino 101 board. + * A0 Channel 10 + * A1 Channel 11 + * A2 Channel 12 + * A3 Channel 13 + * A4 Channel 14 + */ +#define CHANNEL 10 +#define BUFFER_SIZE 40 + +static uint8_t seq_buffer[BUFFER_SIZE]; + +static struct adc_seq_entry sample = { + .sampling_delay = 12, + .channel_id = CHANNEL, + .buffer = seq_buffer, + .buffer_length = BUFFER_SIZE, +}; + +static struct adc_seq_table table = { + .entries = &sample, + .num_entries = 1, +}; + +static void _print_sample_in_hex(uint8_t *buf, uint32_t length) +{ + printk("Buffer content:\n"); + for (; length > 0; length -= 4, buf += 4) { + printk("0x%x ", *((uint32_t *)buf)); + } + printk("\n"); +} + +void main(void) +{ + struct device *adc; + struct nano_timer timer; + uint32_t data[2] = {0, 0}; + + printk("ADC sample started on %s\n", ADC_DEVICE_NAME); + + adc = device_get_binding(ADC_DEVICE_NAME); + if (!adc) { + printk("Cannot get adc controller\n"); + return; + } + + nano_timer_init(&timer, data); + adc_enable(adc); + while (1) { + if (adc_read(adc, &table) != 0) { + printk("Sampling could not proceed, an error occurred\n"); + } else { + printk("Sampling is done\n"); + _print_sample_in_hex(seq_buffer, BUFFER_SIZE); + } + nano_timer_start(&timer, SLEEPTICKS); + nano_timer_test(&timer, TICKS_UNLIMITED); + } + adc_disable(adc); +} diff --git a/tests/drivers/adc/testcase.ini b/tests/drivers/adc/testcase.ini new file mode 100644 index 000000000..3a54c8950 --- /dev/null +++ b/tests/drivers/adc/testcase.ini @@ -0,0 +1,4 @@ +[test] +build_only = true +tags = apps +platform_whitelist = galileo arduino_101_sss quark_d2000_crb diff --git a/tests/drivers/aon_counter/Makefile b/tests/drivers/aon_counter/Makefile new file mode 100644 index 000000000..6377eb866 --- /dev/null +++ b/tests/drivers/aon_counter/Makefile @@ -0,0 +1,5 @@ +KERNEL_TYPE = nano +BOARD ?= quark_d2000_crb +CONF_FILE = prj.conf + +include ${ZEPHYR_BASE}/Makefile.inc diff --git a/tests/drivers/aon_counter/README.txt b/tests/drivers/aon_counter/README.txt new file mode 100644 index 000000000..8cc3eef6f --- /dev/null +++ b/tests/drivers/aon_counter/README.txt @@ -0,0 +1,92 @@ +Title: Quark Always-on counter and timer test app + +Description: + +A simple test app to test the AON counter and timer for quark d2000 and Quark SE. + +-------------------------------------------------------------------------------- + +Building and Running Project: + + make BOARD=quark_d2000_crb + +-------------------------------------------------------------------------------- +Sample Output: + +Always-on counter example app +Always-on counter started +Always-on counter value: 125 +Always-on counter value: 218 +Always-on counter value: 310 +Always-on counter value: 401 +Always-on counter value: 493 +Always-on counter value: 586 +Always-on counter value: 678 +Always-on counter value: 769 +Always-on counter value: 862 +Always-on counter value: 952 +Always-on counter value: 1045 +Always-on counter value: 1139 +Always-on counter value: 1233 +Always-on counter value: 1329 +Always-on counter value: 1422 +Always-on counter value: 1518 +Always-on counter value: 1612 +Always-on counter value: 1708 +Always-on counter value: 1802 +Always-on counter value: 1898 +Always-on counter does not support alarm! +Always-on counter stopped +Periodic timer example app +Periodic timer started +Periodic timer value: ffffff92 +Periodic timer value: ffffff2f +Periodic timer value: fffffecd +Periodic timer value: fffffe6a +Periodic timer value: fffffe09 +Periodic timer value: fffffda6 +Periodic timer value: fffffd45 +Periodic timer value: fffffce4 +Periodic timer value: fffffc83 +Periodic timer value: fffffc22 +Periodic timer value: fffffbc1 +Periodic timer value: fffffb5f +Periodic timer value: fffffafc +Periodic timer value: fffffa9a +Periodic timer value: fffffa37 +Periodic timer value: fffff9d6 +Periodic timer value: fffff973 +Periodic timer value: fffff910 +Periodic timer value: fffff8ae +Periodic timer value: fffff84d +Periodic Timer alarm on +Periodic timer callback data 30 +Periodic timer callback value 9905 +Periodic timer callback data 30 +Periodic timer callback value 9905 +Periodic timer callback data 30 +Periodic timer callback value 9903 +Periodic timer callback data 30 +Periodic timer callback value 9903 +Periodic timer alarm off +Periodic timer value: 000026c4 +Periodic timer value: 00002661 +Periodic timer value: 000025fe +Periodic timer value: 0000259b +Periodic timer value: 00002538 +Periodic timer value: 000024d5 +Periodic timer value: 00002472 +Periodic timer value: 0000240f +Periodic timer value: 000023ac +Periodic timer value: 00002348 +Periodic timer value: 000022e5 +Periodic timer value: 00002282 +Periodic timer value: 0000221f +Periodic timer value: 000021bd +Periodic timer value: 0000215a +Periodic timer value: 000020f7 +Periodic timer value: 00002094 +Periodic timer value: 00002032 +Periodic timer value: 00001fcf +Periodic timer value: 00001f6c +Periodic timer stopped diff --git a/tests/drivers/aon_counter/prj.conf b/tests/drivers/aon_counter/prj.conf new file mode 100644 index 000000000..9d51e5fcd --- /dev/null +++ b/tests/drivers/aon_counter/prj.conf @@ -0,0 +1,2 @@ +CONFIG_PRINTK=y +CONFIG_COUNTER=y diff --git a/tests/drivers/aon_counter/src/Makefile b/tests/drivers/aon_counter/src/Makefile new file mode 100644 index 000000000..00066e156 --- /dev/null +++ b/tests/drivers/aon_counter/src/Makefile @@ -0,0 +1 @@ +obj-y = main.o diff --git a/tests/drivers/aon_counter/src/main.c b/tests/drivers/aon_counter/src/main.c new file mode 100644 index 000000000..8e8b623eb --- /dev/null +++ b/tests/drivers/aon_counter/src/main.c @@ -0,0 +1,166 @@ +/* + * Copyright (c) 2016 Intel Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <zephyr.h> + +#include <misc/printk.h> + +#include <device.h> +#include <counter.h> + +static void aonpt_example_callback(struct device *dev, void *user_data); + +static void free_running_counter_example(void); +static void periodic_timer_example(void); + +void main(void) +{ + /* test quark Always-on free running counter */ + free_running_counter_example(); + + /* test quark Always-on periodic timer */ + periodic_timer_example(); +} + +static void free_running_counter_example(void) +{ + volatile uint32_t delay = 0; + uint32_t c_val = 0, i = 0; + uint32_t dummy_data = 30; + uint32_t counter_initial_value = 10000; + + struct device *aon_counter_dev; + + aon_counter_dev = device_get_binding("AON_COUNTER"); + + if (!aon_counter_dev) { + printk("Counter device not found\n"); + return; + } + + printk("Always-on free running counter example app\n"); + + if (counter_start(aon_counter_dev) != 0) { + printk("Counter device enabling fail!\n"); + return; + } + + printk("Always-on counter started\n"); + + /* The AON counter runs from the RTC clock at 32KHz (rather than + * the system clock which is 32MHz) so we need to spin for a few cycles + * allow the register change to propagate. + */ + for (delay = 5000; delay--;) { + } + + for (i = 0; i < 20; i++) { + for (delay = 500; delay--;) { + } + + c_val = counter_read(aon_counter_dev); + printk("Always-on counter value: %d\n", c_val); + } + + if (counter_set_alarm(aon_counter_dev, NULL, counter_initial_value, + (void *)&dummy_data) != 0) { + printk("Always-on counter does not support alarm!\n"); + } + + counter_stop(aon_counter_dev); + + printk("Always-on counter stopped\n"); +} + +static void periodic_timer_example(void) +{ + volatile uint32_t delay = 0; + uint32_t pt_val = 0, i = 0; + uint32_t dummy_data = 30; + uint32_t timer_initial_value = 10000; + + struct device *aon_periodic_timer_dev = NULL; + + aon_periodic_timer_dev = device_get_binding("AON_TIMER"); + + if (!aon_periodic_timer_dev) { + printk("Timer device not found\n"); + return; + } + + printk("Periodic timer example app\n"); + + counter_start(aon_periodic_timer_dev); + + printk("Periodic timer started\n"); + + /* The AON timer runs from the RTC clock at 32KHz (rather than + * the system clock which is 32MHz) so we need to spin for a few cycles + * allow the register change to propagate. + */ + for (delay = 5000; delay--;) { + } + + for (i = 0; i < 20; i++) { + for (delay = 500; delay--;) { + } + + pt_val = counter_read(aon_periodic_timer_dev); + printk("Periodic timer value: %x\n", pt_val); + } + + if (counter_set_alarm(aon_periodic_timer_dev, aonpt_example_callback, + timer_initial_value, (void *)&dummy_data) + != 0) { + printk("Periodic Timer was not started yet\n"); + return; + } + + printk("Periodic Timer alarm on\n"); + + /* long delay for the alarm and callback to happen */ + for (delay = 5000000; delay--;) { + } + + /* callback is turned off */ + if (counter_set_alarm(aon_periodic_timer_dev, NULL, + timer_initial_value, (void *)&dummy_data) + != 0) { + printk("Periodic timer was not started yet\n"); + return; + } + + printk("Periodic timer alarm off\n"); + + for (i = 0; i < 20; i++) { + for (delay = 500; delay--;) { + } + + pt_val = counter_read(aon_periodic_timer_dev); + printk("Periodic timer value: %x\n", pt_val); + } + + counter_stop(aon_periodic_timer_dev); + + printk("Periodic timer stopped\n"); +} + +static void aonpt_example_callback(struct device *dev, void *user_data) +{ + printk("Periodic timer callback data %d\n", *((uint32_t *)user_data)); + + printk("Periodic timer callback value %d\n", counter_read(dev)); +} diff --git a/tests/drivers/aon_counter/testcase.ini b/tests/drivers/aon_counter/testcase.ini new file mode 100644 index 000000000..b96118640 --- /dev/null +++ b/tests/drivers/aon_counter/testcase.ini @@ -0,0 +1,4 @@ +[test] +tags = apps +build_only = true +platform_whitelist = quark_d2000_crb diff --git a/tests/drivers/dma/Makefile b/tests/drivers/dma/Makefile new file mode 100644 index 000000000..5eee94f78 --- /dev/null +++ b/tests/drivers/dma/Makefile @@ -0,0 +1,5 @@ +BOARD ?= arduino_101 +KERNEL_TYPE = nano +CONF_FILE = prj.conf + +include ${ZEPHYR_BASE}/Makefile.inc diff --git a/tests/drivers/dma/prj.conf b/tests/drivers/dma/prj.conf new file mode 100644 index 000000000..00839338b --- /dev/null +++ b/tests/drivers/dma/prj.conf @@ -0,0 +1,2 @@ +CONFIG_DMA=y +CONFIG_DMA_QMSI=y diff --git a/tests/drivers/dma/src/Makefile b/tests/drivers/dma/src/Makefile new file mode 100644 index 000000000..22016c8cd --- /dev/null +++ b/tests/drivers/dma/src/Makefile @@ -0,0 +1,3 @@ +ccflags-y += -I${ZEPHYR_BASE}/include/drivers + +obj-y = dma.o diff --git a/tests/drivers/dma/src/dma.c b/tests/drivers/dma/src/dma.c new file mode 100644 index 000000000..3d599986a --- /dev/null +++ b/tests/drivers/dma/src/dma.c @@ -0,0 +1,133 @@ +/* dma.c - DMA test source file */ + +/* + * Copyright (c) 2016 Intel Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <zephyr.h> + +#include <device.h> +#include <dma.h> +#include <misc/printk.h> +#include <string.h> + +#define SLEEPTIME 1 +#define SLEEPTICKS (SLEEPTIME * sys_clock_ticks_per_sec) + +#define TRANSFER_LOOPS (5) +#define RX_BUFF_SIZE (50) + +static const char tx_data[] = "The quick brown fox jumps over the lazy dog"; +static char rx_data[TRANSFER_LOOPS][RX_BUFF_SIZE] = {{ 0 } }; + +#define DMA_DEVICE_NAME "DMA_0" + +volatile uint8_t transfer_count; + +static void test_transfer(struct device *dev, void *data) +{ + int ret; + struct dma_transfer_config dma_trans = {0}; + uint32_t *chan_id = data; + + transfer_count++; + if (transfer_count < TRANSFER_LOOPS) { + dma_trans.block_size = strlen(tx_data); + dma_trans.source_address = (uint32_t *)tx_data; + dma_trans.destination_address = + (uint32_t *)rx_data[transfer_count]; + + ret = dma_transfer_config(dev, *chan_id, &dma_trans); + if (ret == 0) { + dma_transfer_start(dev, *chan_id); + } + } +} + +static void test_error(struct device *dev, void *data) +{ + printk("DMA could not proceed, an error occurred\n"); +} + +void main(void) +{ + struct device *dma; + struct nano_timer timer; + static uint32_t chan_id; + uint32_t data[2] = {0, 0}; + struct dma_channel_config dma_chan_cfg = {0}; + struct dma_transfer_config dma_trans = {0}; + + printk("DMA memory to memory transfer started on %s\n", DMA_DEVICE_NAME); + printk("Preparing DMA Controller\n"); + + dma = device_get_binding(DMA_DEVICE_NAME); + if (!dma) { + printk("Cannot get dma controller\n"); + return; + } + + dma_chan_cfg.channel_direction = MEMORY_TO_MEMORY; + dma_chan_cfg.source_transfer_width = TRANS_WIDTH_8; + dma_chan_cfg.destination_transfer_width = TRANS_WIDTH_8; + dma_chan_cfg.source_burst_length = BURST_TRANS_LENGTH_1; + dma_chan_cfg.destination_burst_length = BURST_TRANS_LENGTH_1; + dma_chan_cfg.dma_transfer = test_transfer; + dma_chan_cfg.dma_error = test_error; + + chan_id = 0; + dma_chan_cfg.callback_data = (void *)&chan_id; + + if (dma_channel_config(dma, chan_id, &dma_chan_cfg)) { + printk("Error: configuration\n"); + return; + } + + printk("Starting the transfer and waiting for 1 second\n"); + dma_trans.block_size = strlen(tx_data); + dma_trans.source_address = (uint32_t *)tx_data; + dma_trans.destination_address = (uint32_t *)rx_data[transfer_count]; + + if (dma_transfer_config(dma, chan_id, &dma_trans)) { + printk("ERROR: transfer config\n"); + return; + } + + if (dma_transfer_start(dma, chan_id)) { + printk("ERROR: transfer start\n"); + return; + } + + nano_timer_init(&timer, data); + nano_timer_start(&timer, SLEEPTICKS); + nano_timer_test(&timer, TICKS_UNLIMITED); + + if (transfer_count < TRANSFER_LOOPS) { + transfer_count = TRANSFER_LOOPS; + printk("ERROR: unfinished transfer\n"); + if (dma_transfer_stop(dma, chan_id)) { + printk("ERROR: transfer stop\n"); + } + } + + printk("Each RX buffer should contain the full TX buffer string.\n"); + printk("TX data: %s\n", tx_data); + + for (int i = 0; i < TRANSFER_LOOPS; i++) { + printk("RX data Loop %d: %s\n", i, rx_data[i]); + } + + printk("Finished: DMA\n"); +} diff --git a/tests/drivers/dma/testcase.ini b/tests/drivers/dma/testcase.ini new file mode 100644 index 000000000..c28ea1622 --- /dev/null +++ b/tests/drivers/dma/testcase.ini @@ -0,0 +1,4 @@ +[test] +build_only = true +tags = apps +platform_whitelist = arduino_101 quark_d2000_crb quark_se_c1000_devboard diff --git a/tests/drivers/uart/Makefile b/tests/drivers/uart/Makefile new file mode 100644 index 000000000..0e36b1c76 --- /dev/null +++ b/tests/drivers/uart/Makefile @@ -0,0 +1,5 @@ +KERNEL_TYPE = nano +BOARD ?= quark_se_c1000_devboard +CONF_FILE = prj.conf + +include ${ZEPHYR_BASE}/Makefile.inc diff --git a/tests/drivers/uart/prj.conf b/tests/drivers/uart/prj.conf new file mode 100644 index 000000000..7142f4666 --- /dev/null +++ b/tests/drivers/uart/prj.conf @@ -0,0 +1,2 @@ +CONFIG_SERIAL=y +CONFIG_UART_INTERRUPT_DRIVEN=y
\ No newline at end of file diff --git a/tests/drivers/uart/src/Makefile b/tests/drivers/uart/src/Makefile new file mode 100644 index 000000000..00066e156 --- /dev/null +++ b/tests/drivers/uart/src/Makefile @@ -0,0 +1 @@ +obj-y = main.o diff --git a/tests/drivers/uart/src/main.c b/tests/drivers/uart/src/main.c new file mode 100644 index 000000000..933ddfad4 --- /dev/null +++ b/tests/drivers/uart/src/main.c @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2016 Intel Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <string.h> + +#include <device.h> +#include <uart.h> +#include <zephyr.h> + +static const char *banner1 = "Send any character to the UART device\r\n"; +static const char *banner2 = "Character read:\r\n"; + +static volatile bool data_transmitted; +static volatile bool data_arrived; +static char new_data; + +static void write_string(struct device *dev, const char *str, int len) +{ + for (int i = 0; i < len; i++) + uart_poll_out(dev, str[i]); +} + +static void test_by_polling(struct device *dev) +{ + unsigned char data; + + write_string(dev, banner1, strlen(banner1)); + + /* Poll in the character */ + while (uart_poll_in(dev, &data) == -1) + ; + + write_string(dev, banner2, strlen(banner2)); + write_string(dev, &data, 1); + write_string(dev, "\r\n", 2); +} + +static void interrupt_handler(struct device *dev) +{ + uart_irq_update(dev); + + if (uart_irq_tx_ready(dev)) { + data_transmitted = true; + } + + if (uart_irq_rx_ready(dev)) { + uart_fifo_read(dev, &new_data, 1); + data_arrived = true; + } +} + +static void read_char_irq(struct device *dev, char *data) +{ + uart_irq_rx_enable(dev); + + data_arrived = false; + while (data_arrived == false) + ; + *data = new_data; + + uart_irq_rx_disable(dev); +} + +static void write_buf_irq(struct device *dev, const char *buf, int len) +{ + int i; + + uart_irq_tx_enable(dev); + + for (i = 0; i < len; i++) { + data_transmitted = false; + while (uart_fifo_fill(dev, &buf[i], 1) == 0) + ; + while (data_transmitted == false) + ; + } + + uart_irq_tx_disable(dev); +} + +static void test_by_irq(struct device *dev) +{ + char data; + + uart_irq_callback_set(dev, interrupt_handler); + + write_buf_irq(dev, banner1, strlen(banner1)); + read_char_irq(dev, &data); + write_buf_irq(dev, banner2, strlen(banner2)); + write_buf_irq(dev, &data, sizeof(data)); + write_buf_irq(dev, "\r\n", 2); +} + +void main(void) +{ + struct device *dev = device_get_binding(CONFIG_UART_CONSOLE_ON_DEV_NAME); + + test_by_polling(dev); + test_by_irq(dev); +} |