Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,6 @@ tags

# Disables the warning about the changed behavior for Kconfig defaults
hide-defaults-note
cmake_ninja_wrapper.py
.idea
cmake-build-debug
4 changes: 2 additions & 2 deletions boards/arm/nrf52840_pca10056/nrf52840_pca10056.dts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@

&uart0 {
compatible = "nordic,nrf-uart";
current-speed = <115200>;
current-speed = <57600>;
status = "ok";
tx-pin = <6>;
rx-pin = <8>;
Expand All @@ -102,7 +102,7 @@

#ifdef CONFIG_UART_1_NRF_UARTE
&uart1 {
current-speed = <115200>;
current-speed = <9600>;
status = "ok";
tx-pin = <46>;
rx-pin = <45>;
Expand Down
5 changes: 5 additions & 0 deletions cmake/flash/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,9 @@ foreach(target flash debug debugserver)
${comment}
USES_TERMINAL
)

if(target STREQUAL flash)
add_custom_command(TARGET ${target} POST_BUILD
COMMAND nrfjprog -f nrf52 -r)
endif()
endforeach()
2 changes: 2 additions & 0 deletions drivers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ add_subdirectory_if_kconfig(watchdog)
add_subdirectory_if_kconfig(wifi)
add_subdirectory_if_kconfig(can)
add_subdirectory_if_kconfig(audio)
add_subdirectory_if_kconfig(lora)
add_subdirectory_if_kconfig(uart_generic)

add_subdirectory_ifdef(CONFIG_FLASH_HAS_DRIVER_ENABLED flash)
add_subdirectory_ifdef(CONFIG_SERIAL_HAS_DRIVER serial)
Expand Down
4 changes: 4 additions & 0 deletions drivers/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@

menu "Device Drivers"

source "drivers/uart_generic/Kconfig"

source "drivers/lora/Kconfig"

source "drivers/bluetooth/Kconfig"

source "drivers/ieee802154/Kconfig"
Expand Down
122 changes: 69 additions & 53 deletions drivers/console/rtt_console.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,66 +15,22 @@
#include <init.h>
#include <rtt/SEGGER_RTT.h>

#include <console/console.h>
#include <stdio.h>
#include <zephyr/types.h>
#include <ctype.h>

extern void __printk_hook_install(int (*fn)(int));
extern void __stdout_hook_install(int (*fn)(int));

static bool host_present;

/** @brief Wait for fixed period.
*
*/
static void wait(void)
{
if (k_is_in_isr()) {
if (IS_ENABLED(CONFIG_RTT_TX_RETRY_IN_INTERRUPT)) {
k_busy_wait(1000*CONFIG_RTT_TX_RETRY_DELAY_MS);
}
} else {
k_sleep(CONFIG_RTT_TX_RETRY_DELAY_MS);
}
}

static int rtt_console_out(int character)
{
unsigned int key;
char c = (char)character;
unsigned int cnt;
int max_cnt = CONFIG_RTT_TX_RETRY_CNT;

do {
key = irq_lock();
cnt = SEGGER_RTT_WriteNoLock(0, &c, 1);
irq_unlock(key);

/* There are two possible reasons for not writing any data to
* RTT:
* - The host is not connected and not reading the data.
* - The buffer got full and will be read by the host.
* These two situations are distinguished using the following
* algorithm:
* At the beginning, the module assumes that the host is active,
* so when no data is read, it busy waits and retries.
* If, after retrying, the host reads the data, the module
* assumes that the host is active. If it fails, the module
* assumes that the host is inactive and stores that
* information. On next call, only one attempt takes place.
* The host is marked as active if the attempt is successful.
*/
if (cnt) {
/* byte processed - host is present. */
host_present = true;
} else if (host_present) {
if (max_cnt) {
wait();
max_cnt--;
continue;
} else {
host_present = false;
}
}

break;
} while (1);
key = irq_lock();
SEGGER_RTT_WriteNoLock(0, &c, 1);
irq_unlock(key);

return character;
}
Expand All @@ -91,4 +47,64 @@ static int rtt_console_init(struct device *d)
return 0;
}

SYS_INIT(rtt_console_init, PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);
#ifdef CONFIG_CONSOLE_HANDLER

static struct k_fifo *avail_queue;
static struct k_fifo *lines_queue;
static struct k_thread rtt_rx_thread;
static K_THREAD_STACK_DEFINE(rtt_rx_stack, 1024);

static void rtt_console_rx_process(void)
{
struct console_input *cmd = NULL;
unsigned int key, count;

while (true) {

if (!cmd) {
cmd = k_fifo_get(avail_queue, K_FOREVER);
}

/*
* Read and Echo back if available
*/
key = irq_lock();

/* Reserve a space for '\0' */
count = SEGGER_RTT_ReadNoLock(0, cmd->line, sizeof(cmd->line));
if (count > 0) {
SEGGER_RTT_WriteNoLock(0, cmd->line, count);
}

irq_unlock(key);

if (count > 0) {
/* Replace last '\n' to null */
cmd->line[count - 1] = '\0';
k_fifo_put(lines_queue, cmd);
cmd = NULL;
}

k_sleep(K_MSEC(10));
}
}

void rtt_register_input(struct k_fifo *avail, struct k_fifo *lines,
u8_t (*completion)(char *str, u8_t len))
{
avail_queue = avail;
lines_queue = lines;
ARG_UNUSED(completion);

k_thread_create(&rtt_rx_thread, rtt_rx_stack,
K_THREAD_STACK_SIZEOF(rtt_rx_stack),
(k_thread_entry_t)rtt_console_rx_process,
NULL, NULL, NULL, K_PRIO_COOP(8), 0, K_NO_WAIT);
}
#else
#define rtt_register_input(x) \
do { \
} while ((0))
#endif /* CONFIG_CONSOLE_HANDLER */

SYS_INIT(rtt_console_init, PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);
15 changes: 15 additions & 0 deletions drivers/lora/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#if(DEFINED CONFIG_LORA_DEVICE_USES_UART OR DEFINED CONFIG_LORA_DEVICE_USES_UARTE)
# if(NOT (DEFINED CONFIG_HW_UART0_ENABLED)
# AND NOT (DEFINED CONFIG_HW_UARTE0_ENABLED)
# AND NOT (DEFINED CONFIG_HW_UARTE1_ENABLED))
# message(WARNING "You have selected a LoRa device which requires UART, but UART is not enabled for your board")
# elseif(NOT (CONFIG_LORA_UART0 EQUAL 1) AND NOT (CONFIG_LORA_UARTE0 EQUAL 1) AND NOT (CONFIG_LORA_UARTE1 EQUAL 1))
# message(WARNING "You have selected a LoRa device which requires UART, but did not choose a UART peripheral to use")
# endif()
#endif()
#zephyr_sources_ifdef(CONFIG_LORA_DEVICE_USES_UARTE lora_device_uart.c)

zephyr_sources(lora_context.c)

zephyr_sources_ifdef(CONFIG_LORA_SHELL lora_shell.c)
zephyr_sources_ifdef(CONFIG_LORA_DEVICE_RN2483 rn2483.c)
67 changes: 67 additions & 0 deletions drivers/lora/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Kconfig - Modem configuration options

#
# Copyright (c) 2018 Foundries.io
#
# SPDX-License-Identifier: Apache-2.0
#

menuconfig LORA
bool "LoRa Drivers"
help
Enable config options for LoRa/LoRaWAN drivers.

if LORA

config LORA_DEVICE_USES_UART
bool
select UART_INTERRUPT_DRIVEN

config LORA_DEVICE_USES_UARTE
bool

config LORA_SHELL
bool "Enable LoRa shell utilities"
select CONSOLE_SHELL
help
Activate shell module that provides functions to set device keys
and useful functions for debugging.

choice
prompt "LoRa Device"

config LORA_DEVICE_DUMMY
bool "Dummy device"

config LORA_DEVICE_RN2483
bool "Microchip RN2483 LoRaWAN driver"
select LORA_DEVICE_USES_UARTE
select UART_GENERIC
help
Choose this setting to enable Microchip RN2483 via UART.
endchoice

choice
prompt "Board UART device"
depends on LORA_DEVICE_USES_UART || LORA_DEVICE_USES_UARTE

config LORA_UART0
bool "UART0"
depends on HW_UART0_ENABLED && !LORA_DEVICE_USES_UARTE

config LORA_UARTE0
bool "UARTE0"
depends on HW_UARTE0_ENABLED

config LORA_UARTE1
bool "UARTE1"
depends on HW_UARTE1_ENABLED
endchoice

comment "Please make sure that your board enables UART0, UARTE0 and/or UARTE1 peripheral"
depends on LORA_DEVICE_USES_UART && !(HW_UART0_ENABLED || HW_UARTE0_ENABLED || HW_UARTE1_ENABLED)

comment "You have selected a device which requires UARTE but no UARTE peripheral is enabled"
depends on LORA_DEVICE_USES_UARTE && !(HW_UARTE0_ENABLED || HW_UARTE1_ENABLED)
endif # LORA

23 changes: 23 additions & 0 deletions drivers/lora/lora_context.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (c) 2018 Makaio GmbH
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <drivers/lora/lora_context.h>
#define SYS_LOG_DOMAIN "lora"

static struct lora_context_cb *callback_list;

void lora_context_init(struct lora_context_cb *cb)
{
callback_list = cb;

//lora_device_init();
/*
#ifdef CONFIG_LORA_DEVICE_USES_UARTE
lora_context_uart_init();
#else
#error No LoRa device implementation found
#endif*/
}

Loading