multi-app based on nrf52sdk

This commit is contained in:
Thomas Klaehn
2020-03-12 15:30:53 +01:00
parent df2d84dee1
commit 3a31e2bcb9
18 changed files with 3567 additions and 595 deletions

View File

@@ -1,26 +1,77 @@
#include <stdbool.h>
#include <limits.h>
#include "nrf_delay.h"
#include "boards.h"
#include "platform/narf52/narf52_dk.h"
#include "driver.h"
int main(void)
{
drv_open(&led_1);
drv_open(&led_2);
drv_open(&led_3);
drv_open(&led_4);
while(true) {
for(unsigned int i = 0; i < UINT_MAX; i++) {
char x = 0x30 | (char)(1 & i);
drv_write(&led_1, &x, 1);
drv_write(&led_2, &x, 1);
drv_write(&led_3, &x, 1);
drv_write(&led_4, &x, 1);
nrf_delay_ms(500);
}
}
}
/**
* Copyright (c) 2014 - 2019, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/** @file
*
* @defgroup blinky_example_main main.c
* @{
* @ingroup blinky_example
* @brief Blinky Example Application main file.
*
* This file contains the source code for a sample application to blink LEDs.
*
*/
#include <stdbool.h>
#include <stdint.h>
#include "nrf_delay.h"
#include "boards.h"
/**
* @brief Function for application main entry.
*/
int main(void)
{
/* Configure board. */
bsp_board_init(BSP_INIT_LEDS);
/* Toggle LEDs. */
while (true)
{
for (int i = 0; i < LEDS_NUMBER; i++)
{
bsp_board_led_invert(i);
nrf_delay_ms(500);
}
}
}
/**
*@}
**/

View File

@@ -1,34 +1,113 @@
#include <stdbool.h>
#include <stdint.h>
#include "board.h"
#include "driver.h"
int main(void)
{
// bsp_board_init(BSP_INIT_LEDS);
drv_open(&led_1);
drv_open(&led_2);
drv_open(&led_3);
drv_open(&led_4);
drv_open(&button_1);
drv_open(&button_2);
drv_open(&button_3);
drv_open(&button_4);
while(true) {
char x;
drv_read(&button_1, &x, 1);
drv_write(&led_1, &x, 1);
drv_read(&button_2, &x, 1);
drv_write(&led_2, &x, 1);
drv_read(&button_3, &x, 1);
drv_write(&led_3, &x, 1);
drv_read(&button_4, &x, 1);
drv_write(&led_4, &x, 1);
}
}
/**
* Copyright (c) 2014 - 2019, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/** @file
* @defgroup pin_change_int_example_main main.c
* @{
* @ingroup pin_change_int_example
* @brief Pin Change Interrupt Example Application main file.
*
* This file contains the source code for a sample application using interrupts triggered by GPIO pins.
*
*/
#include <stdbool.h>
#include "nrf.h"
#include "nrf_drv_gpiote.h"
#include "app_error.h"
#include "boards.h"
#ifdef BSP_BUTTON_0
#define PIN_IN BSP_BUTTON_0
#endif
#ifndef PIN_IN
#error "Please indicate input pin"
#endif
#ifdef BSP_LED_0
#define PIN_OUT BSP_LED_0
#endif
#ifndef PIN_OUT
#error "Please indicate output pin"
#endif
void in_pin_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
nrf_drv_gpiote_out_toggle(PIN_OUT);
}
/**
* @brief Function for configuring: PIN_IN pin for input, PIN_OUT pin for output,
* and configures GPIOTE to give an interrupt on pin change.
*/
static void gpio_init(void)
{
ret_code_t err_code;
err_code = nrf_drv_gpiote_init();
APP_ERROR_CHECK(err_code);
nrf_drv_gpiote_out_config_t out_config = GPIOTE_CONFIG_OUT_SIMPLE(false);
err_code = nrf_drv_gpiote_out_init(PIN_OUT, &out_config);
APP_ERROR_CHECK(err_code);
nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_TOGGLE(true);
in_config.pull = NRF_GPIO_PIN_PULLUP;
err_code = nrf_drv_gpiote_in_init(PIN_IN, &in_config, in_pin_handler);
APP_ERROR_CHECK(err_code);
nrf_drv_gpiote_in_event_enable(PIN_IN, true);
}
/**
* @brief Function for application main entry.
*/
int main(void)
{
gpio_init();
while (true)
{
// Do nothing.
}
}
/** @} */

View File

@@ -1,67 +0,0 @@
#include <stdlib.h>
#include <assert.h>
#include "driver.h"
int drv_open(const struct driver *drv)
{
int res = -1;
assert(drv != NULL);
if(drv->fp->open) {
res = drv->fp->open(drv);
}
return res;
}
int drv_close(const struct driver *drv)
{
int res = -1;
assert(drv != NULL);
if(drv->fp->close) {
res = drv->fp->close(drv);
}
return res;
}
int drv_read(const struct driver *drv, char *buffer, unsigned int length)
{
int res = -1;
assert(drv != NULL);
if(drv->fp->read) {
res = drv->fp->read(drv, buffer, length);
}
return res;
}
int drv_write(const struct driver *drv, const char *buffer, unsigned int length)
{
int res = -1;
assert(drv != NULL);
if(drv->fp->write) {
res = drv->fp->write(drv, buffer, length);
}
return res;
}
int drv_ioctl(const struct driver *drv, unsigned int cmd, unsigned int argc, ...)
{
int res = -1;
assert(drv != NULL);
if(drv->fp->ioctl) {
va_list args;
va_start(args, argc);
res = drv->fp->ioctl(drv, cmd, argc, args);
va_end(args);
}
return res;
}

View File

@@ -1,82 +0,0 @@
#include <assert.h>
#include <fcntl.h>
#include <stddef.h>
#include <stdio.h>
#include <unistd.h>
#include "platform/narf52/narf52.h"
#include "platform/narf52/narf52_gpio.h"
#include "gpio.h"
int gpio_open(const struct driver *drv)
{
assert(NULL != drv);
int res = -1;
struct narf52_gpio *this = (struct narf52_gpio *)(drv->dev);
struct narf52_gpio_type *reg = (struct narf52_gpio_type *)NARF_P0_BASE;
reg->PIN_CNF[this->pin_number] = ((uint32_t)(this->dir) << 0)
| ((uint32_t)(this->input) << 1)
| ((uint32_t)(this->pull) << 2)
| ((uint32_t)(this->drive) << 8)
| ((uint32_t)(this->sense) << 16);
return res;
}
int gpio_close(const struct driver *drv)
{
assert(NULL != drv);
int res = -1;
struct gpio *this = (struct gpio *)(drv->dev);
this = this;
return res;
}
int gpio_read(const struct driver *drv, char *buffer, unsigned int len)
{
assert((NULL != drv) && (buffer != NULL));
if(len == 0) {
return 0;
}
struct narf52_gpio *this = (struct narf52_gpio *)(drv->dev);
struct narf52_gpio_type *reg = (struct narf52_gpio_type *)NARF_P0_BASE;
uint32_t state = ((reg->IN) >> (this->pin_number) & 1UL);
if(state) {
buffer[0] = 0x31;
} else {
buffer[0] = 0x30;
}
return 1;
}
int gpio_write(const struct driver *drv, const char *buffer, unsigned int len)
{
assert((NULL != drv) && (buffer != NULL));
if(len == 0) {
return 0;
}
struct narf52_gpio *this = (struct narf52_gpio *)(drv->dev);
struct narf52_gpio_type *reg = (struct narf52_gpio_type *)NARF_P0_BASE;
if(buffer[0] != 0x30) {
reg->OUTSET = 1 << (this->pin_number);
} else {
reg->OUTCLR = 1 << (this->pin_number);
}
return 1;
}
int gpio_ioctl(const struct driver *drv, unsigned int cmd, unsigned int argc, va_list args)
{
assert(drv != 0);
int res = -1;
struct gpio *this = (struct gpio *)(drv->dev);
this = this;
return res;
}