Skip to content

Commit

Permalink
UART lines collection and mirror, Doxygen config, unified UICR config
Browse files Browse the repository at this point in the history
  • Loading branch information
wassfila committed May 31, 2018
1 parent 640d164 commit b549eab
Show file tree
Hide file tree
Showing 18 changed files with 2,734 additions and 68 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -1 +1,3 @@
*.pyc
doc
*.tmp
2,511 changes: 2,511 additions & 0 deletions Doxyfile

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions README.md
Expand Up @@ -31,7 +31,18 @@ Once in the application directory just use ```make conf``` to call a cmsis [conf
### Automated mesh devices configuration
User data flashing is done with Pylink which reads in [uicr.py](tools\uicr.py) the registers of the attached device, look it up in the **NODES_CONFIG** file, retrives which parameters should be flashed, the mapping of parameters to CUSTOMER_X registers come from "uicr_map.json".

## simple board switch
The repo contais a directory for boards declaration "boards/" and a directory for applications "applications/". Although every application targets a particular board, it is possible to use any application for any other board. In the makefile a sinlge line has to be edited

USED_BOARD := BOARD_NRF52_SENSOR_TAG

# Doxygen Documentation
* install [Doxygen](www.doxygen.org/)
* run

gen_doc.bat

Yes this is only wrapping ```doxygen Doxyfile``` but just take it as a workspace local alias
# nRF52 Sensor Tag
This board is based on modules, it is very simple to solder and allows selection of any other I²C sensor modules.

Expand Down
15 changes: 10 additions & 5 deletions applications/nrf52_dongle/Makefile
Expand Up @@ -2,6 +2,10 @@ PROJECT_NAME := nRF52_Dongle
TARGETS := nrf52832_xxaa
OUTPUT_DIRECTORY := _build

#BOARD selection : BOARD_NRF52_DONGLE, BOARD_NRF52_SENSOR_TAG
#USED_BOARD := BOARD_NRF52_DONGLE
USED_BOARD := BOARD_NRF52_SENSOR_TAG

SDK_ROOT := ../../nRF5_SDK_15.0.0_prf
PROJ_DIR := ../..

Expand Down Expand Up @@ -53,8 +57,9 @@ SRC_FILES += \
# Include folders common to all targets
INC_FOLDERS += \
. \
$(PROJ_DIR)/drivers \
$(PROJ_DIR)/applications \
$(PROJ_DIR)/boards/ \
$(PROJ_DIR)/drivers \
$(SDK_ROOT)/components \
$(SDK_ROOT)/components/drivers_nrf/nrf_soc_nosd \
$(SDK_ROOT)/components/libraries/util \
Expand Down Expand Up @@ -96,7 +101,7 @@ OPT = -O0 -g3

# C flags common to all targets
CFLAGS += $(OPT)
CFLAGS += -DBOARD_NRF52_DONGLE
CFLAGS += -D$(USED_BOARD)
CFLAGS += -DBSP_DEFINES_ONLY
CFLAGS += -DCONFIG_GPIO_AS_PINRESET
CFLAGS += -DESB_PRESENT
Expand All @@ -120,7 +125,7 @@ ASMFLAGS += -g3
ASMFLAGS += -mcpu=cortex-m4
ASMFLAGS += -mthumb -mabi=aapcs
ASMFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
ASMFLAGS += -DBOARD_NRF52_DONGLE
ASMFLAGS += -D$(USED_BOARD)
ASMFLAGS += -DBSP_DEFINES_ONLY
ASMFLAGS += -DCONFIG_GPIO_AS_PINRESET
ASMFLAGS += -DESB_PRESENT
Expand Down Expand Up @@ -197,7 +202,7 @@ conf:
java -jar $(CMSIS_CONFIG_TOOL) $(SDK_CONFIG_FILE)

paramr:
C:\Python27\python.exe ../../tools/uicr.py uicr_map.json -r
C:\Python27\python.exe ../../tools/uicr.py ../uicr_map.json -r

paramw:
C:\Python27\python.exe ../../tools/uicr.py uicr_map.json -w
C:\Python27\python.exe ../../tools/uicr.py ../uicr_map.json -w
46 changes: 36 additions & 10 deletions applications/nrf52_dongle/main.c
Expand Up @@ -21,15 +21,17 @@

// --------------------- inputs from sdk_config ---------------------
// ---> TWI0_ENABLED ---> TWI1_ENABLED

#include "uicr_user_defines.h"
//drivers
//apps
#include "clocks.h"
#include "mesh.h"
#include "app_ser.h"

char rtc_message[100];
char uart_message[100];
char rf_message[100];
uint32_t uart_rx_size=0;

void blink()
{
Expand All @@ -47,17 +49,41 @@ void rf_mesh_handler(message_t* msg)
NRF_LOG_INFO("rf_mesh_handler()");

mesh_parse(msg,rf_message);
//ser_send(rf_message);
ser_send(rf_message);
}

/**
* @brief called only with a full line message ending with '\r', '\n' or '0'
*
* @param msg contains a pointer to the DMA buffer, so do not keep it after the call
* @param size safe managemnt with known size
*/
#define UART_MIRROR
void app_serial_handler(const char*msg,uint8_t size)
{
uart_rx_size+= size;
//the input (msg) is really the RX DMA pointer location
//and the output (uart_message) is reall the TX DMA pointer location
//so have to copy here to avoid overwriting
#ifdef UART_MIRROR
memcpy(uart_message,msg,size);
sprintf(uart_message+size,"\r\n");//Add line ending and NULL terminate it with sprintf
ser_send(uart_message);
#endif

if(UICR_is_rf_cmd())
{
mesh_handle_cmd(msg,size);
}
}
extern uint32_t ser_evt_rx_count;

void app_rtc_handler()
{
uint32_t alive_count = mesh_tx_alive();//returns an incrementing counter
NRF_LOG_INFO("id:%d:alive:%lu",mesh_node_id(),alive_count);

sprintf(uart_message,"id:%d:alive:%lu;uart_rx:%lu\r\n",mesh_node_id(),alive_count,ser_evt_rx_count);
ser_send(uart_message);
sprintf(rtc_message,"id:%d:alive:%lu;uart_rx:%lu\r\n",mesh_node_id(),alive_count,uart_rx_size);
ser_send(rtc_message);
}

int main(void)
Expand All @@ -76,13 +102,13 @@ int main(void)

clocks_start();
bsp_board_init(BSP_INIT_LEDS);
ser_init(NULL);
ser_init(app_serial_handler);

//Cannot use non-blocking with buffers from const code memory
sprintf(uart_message,"____________________________________\r\n");
ser_send(uart_message);
sprintf(uart_message,"nodeid:%d;channel:%d;event:reset\r\n",mesh_node_id(),mesh_channel());
ser_send(uart_message);
sprintf(rtc_message,"____________________________________\r\n");
ser_send(rtc_message);
sprintf(rtc_message,"nodeid:%d;channel:%d;event:reset\r\n",mesh_node_id(),mesh_channel());
ser_send(rtc_message);

blink();

Expand Down
10 changes: 0 additions & 10 deletions applications/nrf52_dongle/sdk_config.h
Expand Up @@ -55,16 +55,6 @@
#define APP_SERIAL_ENABLED 1
#endif

// <o> APP_SERIAL_TX_PIN - UART TX pin
#ifndef APP_SERIAL_TX_PIN
#define APP_SERIAL_TX_PIN 6
#endif

// <o> APP_SERIAL_RX_PIN - UART RX pin
#ifndef APP_SERIAL_RX_PIN
#define APP_SERIAL_RX_PIN 5
#endif

// <o> APP_SERIAL_BAUDRATE - Default Baudrate

// <323584=> 1200 baud
Expand Down
7 changes: 0 additions & 7 deletions applications/nrf52_dongle/uicr_map.json

This file was deleted.

7 changes: 4 additions & 3 deletions applications/nrf52_sensortag/Makefile
Expand Up @@ -54,8 +54,9 @@ SRC_FILES += \
# Include folders common to all targets
INC_FOLDERS += \
. \
$(PROJ_DIR)/drivers \
$(PROJ_DIR)/applications \
$(PROJ_DIR)/boards/ \
$(PROJ_DIR)/drivers \
$(SDK_ROOT)/components \
$(SDK_ROOT)/components/drivers_nrf/nrf_soc_nosd \
$(SDK_ROOT)/components/libraries/util \
Expand Down Expand Up @@ -196,7 +197,7 @@ conf:
java -jar $(CMSIS_CONFIG_TOOL) $(SDK_CONFIG_FILE)

paramr:
C:\Python27\python.exe ../../tools/uicr.py uicr_map.json -r
C:\Python27\python.exe ../../tools/uicr.py ../uicr_map.json -r

paramw:
C:\Python27\python.exe ../../tools/uicr.py uicr_map.json -w
C:\Python27\python.exe ../../tools/uicr.py ../uicr_map.json -w
7 changes: 0 additions & 7 deletions applications/nrf52_sensortag/uicr_map.json

This file was deleted.

8 changes: 8 additions & 0 deletions applications/uicr_map.json
@@ -0,0 +1,8 @@
{
"mesh_id" : "CUSTOMER_0",
"channel" : "CUSTOMER_1",
"sleep" : "CUSTOMER_2",
"is_listening" : "CUSTOMER_3",
"is_router" : "CUSTOMER_4",
"is_rf_cmd" : "CUSTOMER_5"
}
12 changes: 12 additions & 0 deletions applications/uicr_user_defines.h
@@ -0,0 +1,12 @@
#ifndef __USER_UICR_DEFINES__
#define __USER_UICR_DEFINES__

#define UICR_NODE_ID NRF_UICR->CUSTOMER[0]
#define UICR_RF_CHANNEL NRF_UICR->CUSTOMER[1]
#define UICR_SLEEP_SEC NRF_UICR->CUSTOMER[2]
#define UICR_is_listening() (NRF_UICR->CUSTOMER[3] == 0xBABA)
#define UICR_is_router() (NRF_UICR->CUSTOMER[4] == 0xBABA)
#define UICR_is_rf_cmd() (NRF_UICR->CUSTOMER[4] == 0xBABA)


#endif /*__USER_UICR_DEFINES__*/
1 change: 1 addition & 0 deletions doc.bat
@@ -0,0 +1 @@
doxygen Doxyfile
69 changes: 59 additions & 10 deletions drivers/app_ser.c
Expand Up @@ -21,14 +21,15 @@ static void sleep_handler(void)

/**
* @brief Construct a new nrf serial drv uart config def object
* APP_SERIAL_RX_PIN is coming from the sdk_config.h application section
* APP_SERIAL_TX_PIN is coming from the sdk_config.h application section
* NRF_UARTE_HWFC_DISABLED is beeing hardcoded here
* RX_PIN_NUMBER comes from the board definition
* TX_PIN_NUMBER comes from the board definition
* CTS,RTS : Forced to NRF_UARTE_PSEL_DISCONNECTED
* Flow : Forced to NRF_UARTE_HWFC_DISABLED
*
*/
NRF_SERIAL_DRV_UART_CONFIG_DEF(m_uart0_drv_config,
APP_SERIAL_RX_PIN, APP_SERIAL_TX_PIN,
RTS_PIN_NUMBER, CTS_PIN_NUMBER,
RX_PIN_NUMBER, TX_PIN_NUMBER,
NRF_UARTE_PSEL_DISCONNECTED, NRF_UARTE_PSEL_DISCONNECTED,
NRF_UARTE_HWFC_DISABLED, NRF_UART_PARITY_EXCLUDED,
APP_SERIAL_BAUDRATE,
UART_DEFAULT_CONFIG_IRQ_PRIORITY);
Expand All @@ -55,13 +56,34 @@ NRF_SERIAL_UART_DEF(serial_uart, APP_SERIAL_INSTANCE);

static app_serial_handler_t m_app_serial_handler;

//static char uart_cmd[128];
static char uart_cmd[128];
static uint8_t uart_cmd_count=0;

uint32_t ser_evt_tx_count = 0;
uint32_t ser_evt_rx_count = 0;
uint32_t ser_evt_drv_err_count = 0;
uint32_t ser_evt_fifo_err_count = 0;

void serial_rx_handler(const char* msg,uint8_t size)
{
for(int i=0;i<size;i++)
{
char c = msg[i];
if( (c == '\r') || (c == '\n') || (c == 0) )
{
if(uart_cmd_count > 0)
{
m_app_serial_handler(uart_cmd,uart_cmd_count);
uart_cmd_count = 0;
}
}
else
{
uart_cmd[uart_cmd_count++] = c;
}
}
}

/**
* @brief the DMA handles a batch of 4 bytes and triggers an event after every 4 bytes
*
Expand All @@ -76,7 +98,13 @@ static void ser_event_handler(nrf_serial_t const * p_serial,nrf_serial_event_t e
ser_evt_tx_count++;
break;
case NRF_SERIAL_EVENT_RX_DATA:
ser_evt_rx_count++;
{
ser_evt_rx_count++;
size_t read;
char buffer[16];//max expected per event
nrf_serial_read(&serial_uart, &buffer, sizeof(buffer), &read, 0);
serial_rx_handler(buffer,read);
}
break;
case NRF_SERIAL_EVENT_DRV_ERR:
ser_evt_drv_err_count++;
Expand All @@ -96,15 +124,16 @@ void ser_init(app_serial_handler_t handler)
ret = nrf_serial_init(&serial_uart, &m_uart0_drv_config, &serial_config);
APP_ERROR_CHECK(ret);

//ret = nrf_serial_read(&serial_uart, &uart_cmd, sizeof(uart_cmd), NULL, 0);
//ret = nrf_serial_read(&serial_uart, &uart_cmd, 4, NULL, 0);
//APP_ERROR_CHECK(ret);
}

/**
* @brief This function is non blocking, using 0 as parameter
* Internal buffers and fifos are thus beeing used
*
* @param message A null terminated string
* @param message A null terminated string, this address will directly be used by the DAM
* pointer, so do not pass any temporary local variable
*/
//Non blocking mode, using 0 as parameter
void ser_send(char* message)
Expand All @@ -119,4 +148,24 @@ void ser_init(app_serial_handler_t handler)
void ser_send(char* message)
{
}
#endif /*APP_SERIAL_ENABLED*/
#endif /*APP_SERIAL_ENABLED*/

//thse functions are now HW dependent

int sprint_buf(char*str,const char*msg,uint8_t size)
{
int total=0;
int add;
add = sprintf(str,"0x");
str+=add;
total+=add;
for(int i=0;i<size;i++)
{
add = sprintf(str,"%02X ",msg[i]);
str+=add;
total+=add;
}
add = sprintf(str,"\r\n");
total+=add;
return total;
}
5 changes: 4 additions & 1 deletion drivers/app_ser.h
Expand Up @@ -4,10 +4,13 @@

#include <stdint.h>

typedef void (*app_serial_handler_t)(uint8_t*,uint8_t);
typedef void (*app_serial_handler_t)(const char*,uint8_t);


void ser_init(app_serial_handler_t handler);
void ser_send(char* message);

//utilities
int sprint_buf(char*str,const char*msg,uint8_t size);

#endif /*__APP_SER_H__*/
2 changes: 1 addition & 1 deletion drivers/clocks.c
Expand Up @@ -19,7 +19,7 @@
#include "nrf_log.h"
NRF_LOG_MODULE_REGISTER();

#define UICR_SLEEP_SEC NRF_UICR->CUSTOMER[2]
#include "uicr_user_defines.h"


const nrf_drv_rtc_t rtc = NRF_DRV_RTC_INSTANCE(0); /**< Declaring an instance of nrf_drv_rtc for RTC0. */
Expand Down

0 comments on commit b549eab

Please sign in to comment.