Skip to content

Commit

Permalink
fport: Receive fport data (don't parse yet)
Browse files Browse the repository at this point in the history
  • Loading branch information
pengi committed May 17, 2020
1 parent 3fb136b commit 8ee4024
Show file tree
Hide file tree
Showing 13 changed files with 293 additions and 48 deletions.
4 changes: 3 additions & 1 deletion make/config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ TARGET_nodeflight_DEPENDS = freertos tinyprintf core lib
TARGET_nodeflight_SOURCES = \
core/main.c \
lib/strops.c \
module/rc_rx/fport.c \
module/io/stdout.c

TARGET_nodeflight_INCLUDES = .
Expand Down Expand Up @@ -125,7 +126,8 @@ TARGET_stm32_SOURCES = \
platform/stm32/hwacc/gpio.c \
platform/stm32/hwacc/uart.c \
platform/stm32/hwacc/usb_vcp.c \
platform/stm32/hwmap/resource_stm32.c
platform/stm32/hwmap/resource_stm32.c \
platform/stm32/fault_irq.c

TARGET_stm32_CFLAGS = \
-DUSE_FULL_LL_DRIVER \
Expand Down
7 changes: 7 additions & 0 deletions src/core/interface_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ struct interface_serial_config_s {
uint16_t tx_buf_size;
uint16_t rx_buf_size;
uint32_t flags;

void (*rx_done)(
const uint8_t *buf,
uint16_t len,
void *storage);

void *storage;
};

struct interface_serial_s {
Expand Down
13 changes: 7 additions & 6 deletions src/core/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,13 @@ int main(

config_init();

xTaskCreate(main_task,
"main",
1024,
NULL,
tskIDLE_PRIORITY,
NULL);
// xTaskCreate(main_task,
// "main",
// 1024,
// NULL,
// tskIDLE_PRIORITY,
// NULL);
(void) main_task;

vTaskStartScheduler();
asm ("bkpt 255");
Expand Down
127 changes: 127 additions & 0 deletions src/module/rc_rx/fport.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/*
* NodeFlight - platform for embedded control systems
* Copyright (C) 2020 Max Sikström
*
* 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 3 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 <https://www.gnu.org/licenses/>.
*/

#include "core/module.h"
#include "core/interface.h"
#include "core/interface_types.h"
#include "core/config.h"
#include "FreeRTOS.h"
#include "task.h"

#include "vendor/tinyprintf/tinyprintf.h"

#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include <string.h>

typedef struct fport_s fport_t;

struct fport_s {
interface_header_t *if_ser;

uint8_t data[64];
uint16_t len;

TaskHandle_t task;
};

static int fport_init(
const char *tag);

static void fport_task(
void *storage);

MODULE_DECL(fport, fport_init);

static void fport_rx_done(
const uint8_t *buf,
uint16_t len,
void *storage)
{
fport_t *fport_if = storage;

memcpy(fport_if->data, buf, len);
fport_if->len = len;

BaseType_t should_switch = pdFALSE;
xTaskNotifyFromISR(fport_if->task, 0x00000001, eSetBits, &should_switch);
portYIELD_FROM_ISR(should_switch);
}

int fport_init(
const char *tag)
{
const char *peripheral_config;
fport_t *fport_if;

peripheral_config = config_get_peripheral_config(tag);
if (peripheral_config == NULL) {
return -1;
}

fport_if = pvPortMalloc(sizeof(fport_t));
if (fport_if == NULL) {
return -1;
}

xTaskCreate(fport_task,
"fport_proc",
1024,
fport_if,
15,
&fport_if->task);

fport_if->if_ser = interface_create(peripheral_config);
if (fport_if->if_ser == NULL) {
return -1;
}
interface_serial_configure(fport_if->if_ser, &(const interface_serial_config_t) {
.baudrate = 115200,
.tx_buf_size = 16,
.rx_buf_size = 128,
.flags = (
INTERFACE_SERIAL_HALF_DUPLEX
| INTERFACE_SERIAL_INVERTED_RX
| INTERFACE_SERIAL_INVERTED_TX
),
.rx_done = fport_rx_done,
.storage = fport_if
});

return 0;
}

void fport_task(
void *storage)
{
fport_t *fport_if = storage;
int i;
uint32_t notify_value;

tfp_printf("fport loaded\n");

for (;;) {
xTaskNotifyWait(0x00, UINT32_MAX, &notify_value, 500 * portTICK_PERIOD_MS);
tfp_printf("fport:");
for (i = 0; i < fport_if->len; i++) {
tfp_printf(" %02x", fport_if->data[i]);
}
tfp_printf("\n");
}
}
6 changes: 3 additions & 3 deletions src/platform/stm32/FreeRTOSConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@
#define configTIMER_TASK_STACK_DEPTH configMINIMAL_STACK_SIZE

/* Interrupt nesting behaviour configuration. */
#define configKERNEL_INTERRUPT_PRIORITY 4
#define configMAX_SYSCALL_INTERRUPT_PRIORITY 3
#define configMAX_API_CALL_INTERRUPT_PRIORITY 3
#define configKERNEL_INTERRUPT_PRIORITY (0xFFUL)
#define configMAX_SYSCALL_INTERRUPT_PRIORITY 8
#define configMAX_API_CALL_INTERRUPT_PRIORITY 8

/* Define to trap errors during development. */
#define configASSERT(x) if ( (x) == 0) asm ("bkpt 255")
Expand Down
28 changes: 28 additions & 0 deletions src/platform/stm32/fault_irq.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* NodeFlight - platform for embedded control systems
* Copyright (C) 2020 Max Sikström
*
* 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 3 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 <https://www.gnu.org/licenses/>.
*/

/*
* Don't do anything special, but keeping it separate from Default_Handler will make it easier to identify hardfaults
* from other unimplemented interrupts in GDB backtrace
*/
void HardFault_Handler(
void)
{
for (;;) {
}
}
10 changes: 2 additions & 8 deletions src/platform/stm32/hwacc/dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,8 @@ static void dma_irq_handler(
/* Get flags, aligned to first bits */
uint32_t flags = def->flags[0] >> def->flag_bit;

/* Clear all flags, always */
def->flags[2] = (
DMA_LIFCR_CFEIF0
| DMA_LIFCR_CDMEIF0
| DMA_LIFCR_CTEIF0
| DMA_LIFCR_CHTIF0
| DMA_LIFCR_CTCIF0
) << def->flag_bit;
/* Clear the flags identified. Any missed flags will be taken next IRQ */
def->flags[2] = flags << def->flag_bit;

if ((flags & DMA_LISR_FEIF0) && state->cb_fifo_error != NULL) {
state->cb_fifo_error(def, state->storage);
Expand Down
Loading

0 comments on commit 8ee4024

Please sign in to comment.