diff --git a/mutekh/boards/Makefile b/mutekh/boards/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..54d17b49a29fda98aada412d1d47708026329a00 --- /dev/null +++ b/mutekh/boards/Makefile @@ -0,0 +1,3 @@ +ifneq ($(CONFIG_BMAAA_BOARD),) +objs += $(CONFIG_BMAAA_BOARD).o +endif diff --git a/mutekh/boards/bmaaa.build b/mutekh/boards/bmaaa.build new file mode 100644 index 0000000000000000000000000000000000000000..9231eb49d2db7f5fa21b74108c1df7e3273065b3 --- /dev/null +++ b/mutekh/boards/bmaaa.build @@ -0,0 +1,12 @@ +%section bmaaa-pinky + %inherit nrf51-xxac + + CONFIG_BMAAA + CONFIG_BMAAA_BOARD pinky + + CONFIG_DRIVER_NRF5X_SPI + CONFIG_DRIVER_NRF5X_CLOCK + CONFIG_DRIVER_NRF5X_CLOCK_LFRC_CAL + CONFIG_DRIVER_NRF5X_TIMER + CONFIG_DRIVER_NRF5X_PRINTK_PIN 19 +%common diff --git a/mutekh/boards/bmaaa.config b/mutekh/boards/bmaaa.config new file mode 100644 index 0000000000000000000000000000000000000000..1d9a8f91d64fcb64930c68c5277caa085bb16fb6 --- /dev/null +++ b/mutekh/boards/bmaaa.config @@ -0,0 +1,10 @@ +%config CONFIG_BMAAA + desc BMAAA module + module bmaaa +%config end + +%config CONFIG_BMAAA_BOARD + desc Board definition filename + flags value + parent CONFIG_BMAAA +%config end diff --git a/mutekh/boards/pinky.c b/mutekh/boards/pinky.c new file mode 100644 index 0000000000000000000000000000000000000000..3c9a5d4ed7930cbe2ac5dc1c4d94ebdfa6621c79 --- /dev/null +++ b/mutekh/boards/pinky.c @@ -0,0 +1,75 @@ +/* + This file is part of MutekH. + + MutekH is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; version 2.1 of the + License. + + MutekH 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this program. If not, see + . + + Copyright Nicolas Pouillon (c) 2016 +*/ + +#include +#include +#include +#include +#include +#include +#include + +DEV_DECLARE_STATIC(clock_dev, "clock", 0, nrf5x_clock_drv, + // Muxes + DEV_STATIC_RES_CMU_MUX(NRF_CLOCK_OSC_HFXO, NRF_CLOCK_SRC_HFCLK, 0b100, 1, 1), + DEV_STATIC_RES_CMU_MUX(NRF_CLOCK_OSC_HFRC, NRF_CLOCK_SRC_HFCLK, 0b011, 1, 1), + DEV_STATIC_RES_CMU_MUX(NRF_CLOCK_OSC_LFRC, NRF_CLOCK_SRC_LFCLK, 0b111, 1, 1), + + // Oscillators + DEV_STATIC_RES_CMU_OSC_ACC(NRF_CLOCK_OSC_LFRC, 0b110, 32768, 1, 7, 18), // 246ppm + DEV_STATIC_RES_CMU_OSC_ACC(NRF_CLOCK_OSC_LFRC, 0b001, 32768, 1, 2, 25), // 2% + DEV_STATIC_RES_CMU_OSC_ACC(NRF_CLOCK_OSC_HFXO, 0b111, 32000000, 1, 7, 15), // 31ppm + DEV_STATIC_RES_CMU_OSC_ACC(NRF_CLOCK_OSC_HFRC, 0b111, 16000000, 1, 2, 25), // 2% + + NRF_STATIC_RES_PERIPHERAL_MEM(NRF5X_CLOCK), + DEV_STATIC_RES_DEV_ICU("/cpu"), + DEV_STATIC_RES_IRQ(0, NRF5X_CLOCK, DEV_IRQ_SENSE_HIGH_LEVEL, 0, 1), + + NRF_STATIC_RES_PERIPHERAL_MEM(NRF5X_TEMP), + DEV_STATIC_RES_IRQ(1, NRF5X_TEMP, DEV_IRQ_SENSE_HIGH_LEVEL, 0, 1), + ); + +#if defined(CONFIG_DRIVER_NRF5X_UART) + +DEV_DECLARE_STATIC(uart_dev, "uart0", 0, nrf5x_uart_drv, + NRF_STATIC_RES_PERIPHERAL_MEM(NRF5X_UART0), + DEV_STATIC_RES_DEV_ICU("/cpu"),, + DEV_STATIC_RES_IRQ(0, NRF5X_UART0, DEV_IRQ_SENSE_HIGH_LEVEL, 0, 1) + DEV_STATIC_RES_DEV_IOMUX("/gpio"), + DEV_STATIC_RES_UART(1000000, 8, DEV_UART_PARITY_NONE, 1, 0, 0), + DEV_STATIC_RES_IOMUX("tx", 0, 19, 0, 0), + DEV_STATIC_RES_IOMUX("rx", 0, 20, 0, 0) + ); + +#endif + +#if defined(CONFIG_DRIVER_NRF5X_SPI) + +DEV_DECLARE_STATIC(spi_dev, "spi0", 0, nrf5x_spi_drv, + NRF_STATIC_RES_PERIPHERAL_MEM(NRF5X_SPI1), + DEV_STATIC_RES_DEV_ICU("/cpu"), + DEV_STATIC_RES_IRQ(0, NRF5X_SPI1, DEV_IRQ_SENSE_HIGH_LEVEL, 0, 1), + DEV_STATIC_RES_DEV_IOMUX("/gpio"), + DEV_STATIC_RES_IOMUX("clk", 0, 29, 0, 0), + DEV_STATIC_RES_IOMUX("mosi", 0, 28, 0, 0), + DEV_STATIC_RES_IOMUX("miso", 0, 27, 0, 0) + ); + +#endif diff --git a/mutekh/common.build b/mutekh/common.build new file mode 100644 index 0000000000000000000000000000000000000000..e9ef5130b64423276e353c74f1441e73ebdd3314 --- /dev/null +++ b/mutekh/common.build @@ -0,0 +1,81 @@ +CONFIG_HEXO_CPU_STACK_SIZE 0x600 + +CONFIG_COMPILE_PIC undefined +CONFIG_COMPILE_FRAMEPTR undefined +CONFIG_COMPILE_MERGE +CONFIG_COMPILE_OPTIMIZE s + +%include boards/bmaaa.build + +%section nrf5?-* + CONFIG_DRIVER_NRF5X_CLOCK + CONFIG_DRIVER_NRF5X_RTC + CONFIG_DRIVER_NRF5X_PERSIST + CONFIG_DRIVER_NRF5X_AES + CONFIG_DRIVER_NRF5X_AES_RANDOM + CONFIG_DRIVER_NRF5X_RNG + CONFIG_DRIVER_NRF5X_NVMC + CONFIG_DRIVER_NRF5X_GPIO + CONFIG_MUTEK_PRINTK_ADDR 0x40002000 + + %subsection ble-* + CONFIG_DRIVER_NRF5X_AES_CCM + CONFIG_DRIVER_NRF5X_BLE +# CONFIG_DRIVER_BLE_RADIO + CONFIG_MUTEK_KROUTINE_IDLE + CONFIG_MUTEK_KROUTINE_SCHED + %end + +%section nrf5x-ble-radio + CONFIG_DRIVER_NRF5X_BLE_RADIO + +%section ble-peripheral + CONFIG_NET + CONFIG_BLE + CONFIG_BLE_PERIPHERAL + CONFIG_BLE_GATTDB_INCLUDE + +%section ble-central + CONFIG_NET + CONFIG_BLE + CONFIG_BLE_CENTRAL + +%section ble-security + CONFIG_BLE_SECURITY_DB + %inherit ble-crypto + +%section ble-crypto + CONFIG_BLE_CRYPTO + CONFIG_DRIVER_NRF5X_PERSIST + CONFIG_DRIVER_NRF5X_AES + CONFIG_DRIVER_NRF5X_AES_RANDOM + CONFIG_DRIVER_NRF5X_AES_CCM + CONFIG_DRIVER_NRF5X_RNG + CONFIG_DRIVER_NRF5X_NVMC + +%section ble-debug + CONFIG_DRIVER_NRF5X_BLE_DEBUG + +%section printk + CONFIG_DRIVER_NRF5X_PRINTK + CONFIG_MUTEK_PRINTK_HEXDUMP + +%section rtt + CONFIG_DRIVER_RTT + CONFIG_DRIVER_RTT_PRINTK + CONFIG_MUTEK_PRINTK_HEXDUMP + +%section uart-shell + CONFIG_DRIVER_NRF5X_UART + CONFIG_DEVICE_UART + %inherit shell + +%section rtt-shell + CONFIG_DRIVER_CHAR_RTT + CONFIG_DRIVER_CHAR_RTT_RX_BUFFER_SIZE 128 + %inherit shell + +%common + +%include arch/arch.build +%include scripts/options.build diff --git a/mutekh/hello/Makefile b/mutekh/hello/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..ee7694b3a3dc63465e13f32023f2425ddc58b9f7 --- /dev/null +++ b/mutekh/hello/Makefile @@ -0,0 +1 @@ +objs = hello.o diff --git a/mutekh/hello/config b/mutekh/hello/config new file mode 100644 index 0000000000000000000000000000000000000000..e38e719667290e48bd9e716ea9b501934c10da15 --- /dev/null +++ b/mutekh/hello/config @@ -0,0 +1,8 @@ +%set OUTPUT_NAME hello +%append MODULES $(OUTPUT_NAME):$(CONFIGPATH) + +%include common.build + +CONFIG_LICENSE_APP_BSD +CONFIG_APP_START + diff --git a/mutekh/hello/hello.c b/mutekh/hello/hello.c new file mode 100644 index 0000000000000000000000000000000000000000..5d2f39c13fd9d5b9b162ac4326506ba8c2f6e006 --- /dev/null +++ b/mutekh/hello/hello.c @@ -0,0 +1,88 @@ +#include +#include +#include +#include +#include + +#define RS 18 +#define D7 13 +#define BACK 12 +#define E 17 + +#define FIRST 12 +#define LAST 18 + +static const uint64_t nibble_rev = 0xf7b3d591e6a2c480; + +struct device_gpio_s gpio; +struct device_timer_s timer; +dev_timer_delay_t msec; + +static void lcd_put(bool_t rs, uint8_t byte) +{ + uint8_t val; + + DEVICE_OP(&gpio, set_output, RS, RS, + rs ? dev_gpio_mask1 : dev_gpio_mask0, + rs ? dev_gpio_mask1 : dev_gpio_mask0); + + val = nibble_rev >> ((byte >> 4) * 4); + DEVICE_OP(&gpio, set_output, D7, D7 + 3, &val, &val); + + DEVICE_OP(&gpio, set_output, E, E, dev_gpio_mask0, dev_gpio_mask0); + dev_timer_wait_delay(&timer, msec, 0); + DEVICE_OP(&gpio, set_output, E, E, dev_gpio_mask1, dev_gpio_mask1); + dev_timer_wait_delay(&timer, msec, 0); + + val = nibble_rev >> ((byte & 0xf) * 4); + DEVICE_OP(&gpio, set_output, D7, D7 + 3, &val, &val); + + DEVICE_OP(&gpio, set_output, E, E, dev_gpio_mask0, dev_gpio_mask0); + dev_timer_wait_delay(&timer, msec, 0); + DEVICE_OP(&gpio, set_output, E, E, dev_gpio_mask1, dev_gpio_mask1); + dev_timer_wait_delay(&timer, msec, 0); +} + +static void lcd_put_string(char *str) +{ + while (*str) + lcd_put(1, *str++); +} + +static CONTEXT_ENTRY(lcd_hello) +{ + lcd_put(0, 0x33); + dev_timer_wait_delay(&timer, msec * 4, 0); + lcd_put(0, 0x33); + dev_timer_wait_delay(&timer, msec * 4, 0); + lcd_put(0, 0x32); + lcd_put(0, 0x28); + lcd_put(0, 0x08); + lcd_put(0, 0x01); + lcd_put(0, 0x06); + lcd_put(0, 0x0c); + + lcd_put_string("Hello,"); + lcd_put(0, 0xc0); + lcd_put_string("world !"); +} + +void app_start() +{ + error_t err; + printk("Hello World!\n"); + + err = device_get_accessor_by_path(&gpio.base, NULL, "/gpio*", DRIVER_CLASS_GPIO); + assert(!err); + + err = device_get_accessor_by_path(&timer.base, NULL, "/rtc*", DRIVER_CLASS_TIMER); + assert(!err); + + DEVICE_OP(&gpio, set_output, FIRST, LAST, dev_gpio_mask1, dev_gpio_mask1); + DEVICE_OP(&gpio, set_output, BACK, BACK, dev_gpio_mask0, dev_gpio_mask0); + DEVICE_OP(&gpio, set_mode, FIRST, LAST, dev_gpio_mask1, DEV_PIN_PUSHPULL); + + dev_timer_init_sec(&timer, &msec, 0, 1, 1000); + + thread_create(lcd_hello, 0, NULL); +}