From afaf50c904f58f13d7d4fe21ca8a3010fa29ad6f Mon Sep 17 00:00:00 2001 From: Nathael Pajani Date: Thu, 10 Sep 2015 08:58:35 +0200 Subject: [PATCH] Simple test application for KNX module. Transparent bridge for electrical testing. --- transparent_bridge/Makefile | 13 +++ transparent_bridge/README | 26 ++++++ transparent_bridge/main.c | 163 ++++++++++++++++++++++++++++++++++++ 3 files changed, 202 insertions(+) create mode 100644 transparent_bridge/Makefile create mode 100644 transparent_bridge/README create mode 100644 transparent_bridge/main.c diff --git a/transparent_bridge/Makefile b/transparent_bridge/Makefile new file mode 100644 index 0000000..1df310e --- /dev/null +++ b/transparent_bridge/Makefile @@ -0,0 +1,13 @@ +# Makefile for "knx" apps +# This includes all apps for the KNX Module. + +MODULE = $(shell basename $(shell cd .. && pwd && cd -)) +NAME = $(shell basename $(CURDIR)) + +.PHONY: $(NAME).bin +$(NAME).bin: + @make -C ../../.. --no-print-directory NAME=$(NAME) MODULE=$(MODULE) apps/$(MODULE)/$(NAME)/$@ + +clean mrproper: + @make -C ../../.. --no-print-directory $@ + diff --git a/transparent_bridge/README b/transparent_bridge/README new file mode 100644 index 0000000..1c0eaa4 --- /dev/null +++ b/transparent_bridge/README @@ -0,0 +1,26 @@ +KNX module support + +Copyright 2015 Nathael Pajani + + +/* **************************************************************************** + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + *************************************************************************** */ + +First module test application. +This app does not make use of the ncn5120 driver +It only transparently transmits all bytes from one UART to the other in both directions. + + diff --git a/transparent_bridge/main.c b/transparent_bridge/main.c new file mode 100644 index 0000000..ed438ab --- /dev/null +++ b/transparent_bridge/main.c @@ -0,0 +1,163 @@ +/**************************************************************************** + * main.c + * + * KNX support example + * + * Copyright 2015 Nathael Pajani + * + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + *************************************************************************** */ + + +#include +#include "core/lpc_regs_12xx.h" +#include "core/lpc_core_cm0.h" +#include "core/pio.h" +#include "core/system.h" +#include "core/systick.h" +#include "lib/stdio.h" +#include "drivers/serial.h" +#include "drivers/gpio.h" +#include "extdrv/status_led.h" +#include "extdrv/ncn5120.h" + + +#define MODULE_VERSION 0x04 +#define MODULE_NAME "KNX Module" + +#define SELECTED_FREQ FREQ_SEL_48MHz + +/***************************************************************************** */ +/* Pins configuration */ +/* pins blocks are passed to set_pins() for pins configuration. + * Unused pin blocks can be removed safely with the corresponding set_pins() call + * All pins blocks may be safelly merged in a single block for single set_pins() call.. + */ +const struct pio_config common_pins[] = { + /* UART 0 */ + { LPC_UART0_RX_PIO_0_1, LPC_IO_DIGITAL }, + { LPC_UART0_TX_PIO_0_2, LPC_IO_DIGITAL }, + /* UART 1 (KNX) */ + { LPC_UART1_RX_PIO_0_8, LPC_IO_DIGITAL }, + { LPC_UART1_TX_PIO_0_9, LPC_IO_DIGITAL }, + /* I2C 0 */ + { LPC_I2C0_SCL_PIO_0_10, (LPC_IO_DIGITAL | LPC_IO_OPEN_DRAIN_ENABLE) }, + { LPC_I2C0_SDA_PIO_0_11, (LPC_IO_DIGITAL | LPC_IO_OPEN_DRAIN_ENABLE) }, + /* SPI */ + { LPC_SSP0_SCLK_PIO_0_14, LPC_IO_DIGITAL }, + { LPC_SSP0_MOSI_PIO_0_17, LPC_IO_DIGITAL }, + { LPC_SSP0_MISO_PIO_0_16, LPC_IO_DIGITAL }, + /* ADC */ + { LPC_ADC_AD1_PIO_0_31, LPC_IO_ANALOG }, + { LPC_ADC_AD2_PIO_1_0, LPC_IO_ANALOG }, + /* Timer 3 */ +#define LPC_TIMER_PIN_CONFIG (LPC_IO_MODE_PULL_UP | LPC_IO_DIGITAL | LPC_IO_DRIVE_HIGHCURENT) + { LPC_TIMER_32B1_M0_PIO_0_23, LPC_TIMER_PIN_CONFIG }, + { LPC_TIMER_32B1_M1_PIO_0_24, LPC_TIMER_PIN_CONFIG }, + /* User GPIO */ + { LPC_GPIO_0_0, LPC_IO_DIGITAL }, + { LPC_GPIO_0_25, LPC_IO_DIGITAL }, + { LPC_GPIO_0_26, LPC_IO_DIGITAL }, + /* KNX GPIO */ + { LPC_GPIO_0_6, LPC_IO_DIGITAL }, + { LPC_GPIO_0_7, LPC_IO_DIGITAL }, + ARRAY_LAST_PIO, +}; + +/* + * RESETB and SAVEB pin + * The RESETB signal can be used to keep the host controller in a reset state. When RESETB is low this + * indicates that the bus voltage is too low for normal operation and that the fixed DC−DC converter + * has not started up. It could also indicate a Thermal Shutdown (TSD). The RESETB signal also indicates + * if communication between host and NCN5120 is possible. + * + * The SAVEB signal indicates correct operation. When SAVEB goes low, this indicates a possible issue + * (loss of bus power or too high temperature) which could trigger the host controller to save critical + * data or go to a save state. + * + * RESETB− and SAVEB−pin are open−drain pins with an internal pull−up resistor to VDDD. + */ +const struct pio knx_reset = LPC_GPIO_0_6; +const struct pio knx_save = LPC_GPIO_0_7; + +const struct pio status_led_green = LPC_GPIO_0_28; +const struct pio status_led_red = LPC_GPIO_0_29; + +#define ADC_EXT1 LPC_ADC_NUM(1) +#define ADC_EXT2 LPC_ADC_NUM(2) + + + +/***************************************************************************** */ +void system_init() +{ + /* Stop the watchdog */ + stop_watchdog(); /* Do it right now, before it gets a chance to break in */ + + /* Note: Brown-Out detection must be powered to operate the ADC. adc_on() will power + * it back on if called after system_init() */ + system_brown_out_detection_config(0); + system_set_default_power_state(); + clock_config(SELECTED_FREQ); + set_pins(common_pins); + gpio_on(); + status_led_config(&status_led_green, &status_led_red); + /* System tick timer MUST be configured and running in order to use the sleeping + * functions */ + systick_timer_on(1); /* 1ms */ + systick_start(); +} + +/* Define our fault handler. This one is not mandatory, the dummy fault handler + * will be used when it's not overridden here. + * Note : The default one does a simple infinite loop. If the watchdog is deactivated + * the system will hang. + */ +void fault_info(const char* name, uint32_t len) +{ + serial_write(0, name, len); + /* Wait for end of Tx */ + serial_flush(0); + /* FIXME : Perform soft reset of the micro-controller ! */ + while (1); +} + +void send_for_echo(uint8_t c) +{ + struct lpc_uart* uart1 = LPC_UART_1; + uart1->func.buffer = c; + status_led(red_on); +} +void got_echo(uint8_t c) +{ + struct lpc_uart* uart0 = LPC_UART_0; + uart0->func.buffer = (c + 1); + status_led(green_on); +} + + +/***************************************************************************** */ +int main(void) { + system_init(); + uart_on(0, 115200, send_for_echo); + uart_on(1, 38400, got_echo); + + + while (1) { + } + return 0; +} + -- 2.43.0