Commit 5d8a5bb2 authored by Bernd-Christian Renner's avatar Bernd-Christian Renner
Browse files

new feature: pktpin

parent 6daedefc
=== PKTPIN ===
- if we change modes, the pin behavior may be corrupted until the next trigger!
(e.g., what if queue non-empty and we switch to queue mode?)
=== RANGING ===
- sending another ping (or packet?) when waiting for a pong will create invalid ranging results
(when receiving a pong for the former/first ping!)
=== ACI ===
- processCmd should return bool? (valid or invalid command? or a return type?)
......
/**
* Copyright 2016-2020
* Copyright 2016-2021
*
* Bernd-Christian Renner,
* Jan Heitmann, and
......@@ -46,6 +46,7 @@
#include "csrc/aci_batvoltage.c"
#include "csrc/aci_bootloader.c"
#include "csrc/aci_reset.c"
#include "csrc/aci_pktpin.c"
#include "csrc/aci_rxthresh.c"
#include "csrc/aci_bitspread.c"
#include "csrc/aci_filterraw.c"
......@@ -92,6 +93,7 @@ cmdTbl[ACI_TYPE_ID-PACKET_TYPE_CMD_OFFSET] = aci_id_processCmd;
cmdTbl[ACI_TYPE_BATVOLTAGE-PACKET_TYPE_CMD_OFFSET] = aci_batvoltage_processCmd;
cmdTbl[ACI_TYPE_BOOTLOADER-PACKET_TYPE_CMD_OFFSET] = aci_bootloader_processCmd;
cmdTbl[ACI_TYPE_RESET-PACKET_TYPE_CMD_OFFSET] = aci_reset_processCmd;
cmdTbl[ACI_TYPE_PKTPIN-PACKET_TYPE_CMD_OFFSET] = aci_pktpin_processCmd;
cmdTbl[ACI_TYPE_RXTHRESH-PACKET_TYPE_CMD_OFFSET] = aci_rxthresh_processCmd;
cmdTbl[ACI_TYPE_BITSPREAD-PACKET_TYPE_CMD_OFFSET] = aci_bitspread_processCmd;
cmdTbl[ACI_TYPE_FILTERRAW-PACKET_TYPE_CMD_OFFSET] = aci_filterraw_processCmd;
......@@ -126,6 +128,7 @@ rspTbl[ACI_TYPE_ID-PACKET_TYPE_CMD_OFFSET] = aci_id_fillReply;
rspTbl[ACI_TYPE_BATVOLTAGE-PACKET_TYPE_CMD_OFFSET] = aci_batvoltage_fillReply;
rspTbl[ACI_TYPE_BOOTLOADER-PACKET_TYPE_CMD_OFFSET] = aci_bootloader_fillReply;
rspTbl[ACI_TYPE_RESET-PACKET_TYPE_CMD_OFFSET] = aci_reset_fillReply;
rspTbl[ACI_TYPE_PKTPIN-PACKET_TYPE_CMD_OFFSET] = aci_pktpin_fillReply;
rspTbl[ACI_TYPE_RXTHRESH-PACKET_TYPE_CMD_OFFSET] = aci_rxthresh_fillReply;
rspTbl[ACI_TYPE_BITSPREAD-PACKET_TYPE_CMD_OFFSET] = aci_bitspread_fillReply;
rspTbl[ACI_TYPE_FILTERRAW-PACKET_TYPE_CMD_OFFSET] = aci_filterraw_fillReply;
......
/**
* Copyright 2016-2019
* Copyright 2016-2021
*
* Bernd-Christian Renner,
* Jan Heitmann, and
......@@ -46,6 +46,7 @@ ACI_TYPE_ID = 0x84,
ACI_TYPE_BATVOLTAGE = 0x85,
ACI_TYPE_BOOTLOADER = 0x86,
ACI_TYPE_RESET = 0x87,
ACI_TYPE_PKTPIN = 0x89,
ACI_TYPE_RXTHRESH = 0x94,
ACI_TYPE_BITSPREAD = 0x95,
ACI_TYPE_FILTERRAW = 0x96,
......
......@@ -5,6 +5,7 @@ ID = 0x84 // setup modem id
BATVOLTAGE = 0x85 // get voltage
BOOTLOADER = 0x86 // jump to bootloader
RESET = 0x87 // reset modem
PKTPIN = 0x89 // configure packet pin behavior
// setup
// FREQSETUP_NUMBANDS = 0x90 // setup frequency bands
......
/**
* Copyright 2021
*
* Bernd-Christian Renner, and
* Hamburg University of Technology (TUHH).
* 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 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 the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER 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.
*/
#include "aci.h"
#include "aci/types/pktpin_cmd.h"
#include "aci_pktpin.h"
#include "pktpin.h"
/**************************************************************************
* private prototypes
*/
/**************************************************************************
* private functions
*/
uint8_t
aci_pktpin_fillReply(uint8_t * payload)
{
aci_pktpin_cmd_t * p = (aci_pktpin_cmd_t *)payload;
p->mode = pktpin_getMode();
return sizeof(aci_pktpin_cmd_t);
}
/**************************************************************************
* public functions
*/
void
aci_pktpin_processCmd(const mm_packet_t * pkt)
{
if (pkt->header.len == sizeof(aci_pktpin_cmd_t)) {
aci_pktpin_cmd_t * p = (aci_pktpin_cmd_t *)(pkt->payload);
pktpin_setMode(p->mode);
}
}
/**
* Copyright 2021
*
* Bernd-Christian Renner, and
* Hamburg University of Technology (TUHH).
* 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 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 the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER 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.
*/
#ifndef ACI_PKTPIN_H
#define ACI_PKTPIN_H
#include "types.h"
/**
* configure packet pin mode
*/
extern void
aci_pktpin_processCmd(const mm_packet_t * pkt);
extern uint8_t
aci_pktpin_fillReply(uint8_t * payload);
#endif /* ACI_PKTPIN_H */
typedef struct __attribute__ ((__packed__)) {
uint8_t mode; // pktpin mode, @see PKTPIN_MODE_*
} aci_pktpin_cmd_t;
......@@ -18,6 +18,7 @@ receive.c \
id.c \
send.c \
packetqueue.c \
pktpin.c \
serializer.c \
spreader.c \
fixpoint.c \
......
......@@ -116,6 +116,14 @@
/** @} */
/**
* \defgroup ext_pins STM32F4 External GPIO Pins
* @{
*/
#define EXT_PKT_PIN GPIO_NA
/** @} */
/**
* \defgroup leds STM32F4 Led to GPIO mapping
* @{
......
......@@ -116,6 +116,14 @@
/** @} */
/**
* \defgroup ext_pins STM32F4 External GPIO Pins
* @{
*/
#define EXT_PKT_PIN (gpio_t){GPIOC, GPIO_PIN_11}
/** @} */
/**
* \defgroup leds STM32F4 Led to GPIO mapping
* @{
......
/**
* Copyright 2016-2019
* Copyright 2016-2021
*
* Timo Kortbrae,
* Jan Heitmann,
......@@ -90,6 +90,17 @@ gpio_init(void)
HAL_GPIO_Init(TXRX_SW_PIN.port, &GPIO_InitStruct);
gpio_clear(TXRX_SW_PIN);
//
// external packet pin
//
GPIO_InitStruct.Pin = EXT_PKT_PIN.pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
//GPIO_InitStruct.Alternate = 0;
HAL_GPIO_Init(EXT_PKT_PIN.port, &GPIO_InitStruct);
gpio_clear(EXT_PKT_PIN);
//
// LEDs, all same setup
//
......
/**
* Copyright 2016-2020
* Copyright 2016-2021
*
* Bernd-Christian Renner
* Jan Heitmann, and
......@@ -101,6 +101,7 @@
#include "sync.h"
#include "receive.h"
#include "packet.h"
#include "pktpin.h"
#include "send.h"
#include "ranging.h"
......@@ -184,6 +185,16 @@ processRxPacket(void)
while (! host_sendPacket((uint8_t*)pkt, MM_HEADER_LEN + pkt->header.len + MM_FOOTER_LEN)) { ; }
packetpool_put(pkt);
// TODO where /exactly/ should we do this (before or after packet transmission?
// doing this after sending may cause timing issues (should not?), meaning
// that the host has to wait a short while after reception before checking the
// the pin again; however, pulling the pin low before sending will require it
// to be pulled high, if there is an error while sending
// reset signal (GPIO), if no more packet
if (packetqueue_empty(&RXQ)) {
pktpin_trigger(PKTPIN_TRIG_QEMPTY);
}
}
......@@ -354,6 +365,7 @@ cbModemReceive(mm_packet_t * pkt)
// insert new rx packet in queue and signal (GPIO)
packetqueue_insert(&RXQ, pkt);
pktpin_trigger(PKTPIN_TRIG_QINSERT);
return packetpool_get();
}
......
/**
* Copyright 2021
*
* Bernd-Christian Renner, and
* Hamburg University of Technology (TUHH).
* 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 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 the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER 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.
*/
#include "pktpin.h"
#include <hal_gpio.h>
/******************************************************************************
* Variables & Declarations *
******************************************************************************/
static uint8_t pktpinMode = PKTPIN_MODE_NONE;
static bool pktpinQFilled = false;
/******************************************************************************
* Public Functions *
******************************************************************************/
bool
pktpin_setMode(uint8_t mode)
{
// change mode
if (mode >= PKTPIN_MODE_NUM) {
return false;
}
pktpinMode = mode;
// restore pin state
switch (pktpinMode) {
case PKTPIN_MODE_QUEUE:
if (pktpinQFilled) {
gpio_set(EXT_PKT_PIN);
} else {
gpio_clear(EXT_PKT_PIN);
}
break;
case PKTPIN_MODE_RANGE:
// nothing
break;
}
return true;
}
uint8_t
pktpin_getMode(void)
{
return pktpinMode;
}
void
pktpin_trigger(uint8_t trigger)
{
switch (pktpinMode) {
case PKTPIN_MODE_QUEUE:
if (trigger == PKTPIN_TRIG_QINSERT) {
pktpinQFilled = true;
gpio_set(EXT_PKT_PIN);
} else if (trigger == PKTPIN_TRIG_QEMPTY) {
pktpinQFilled = false;
gpio_clear(EXT_PKT_PIN);
}
break;
case PKTPIN_MODE_RANGE:
if (trigger == PKTPIN_TRIG_RANGE) {
gpio_toggle(EXT_PKT_PIN);
}
break;
}
}
/**
* Copyright 2021
*
* Bernd-Christian Renner, and
* Hamburg University of Technology (TUHH).
* 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 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 the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER 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.
*/
#ifndef PKTPIN_H
#define PKTPIN_H
#include <stdbool.h>
#include <stdint.h>
/******************************************************************************
* Defines *
******************************************************************************/
enum {
PKTPIN_MODE_NONE, // disabled
PKTPIN_MODE_QUEUE, // at least one pkt available in queue
// pin will stay high as long as there is a packet in the queue
PKTPIN_MODE_RANGE, // toggle upon SFD detection
PKTPIN_MODE_NUM
};
enum {
PKTPIN_TRIG_QINSERT, // inserted packet into queue
PKTPIN_TRIG_QEMPTY, // queue is emptied (last packet removed)
PKTPIN_TRIG_RANGE, // at calculation of ranging info
PKTPIN_TRIG_NUM
};
/*******************************************************************************
* Public Prototypes *
******************************************************************************/
bool
pktpin_setMode(uint8_t mode);
uint8_t
pktpin_getMode(void);
void
pktpin_trigger(uint8_t trigger);
#endif /* PKTPIN_H */
......@@ -39,38 +39,51 @@
#include "freqsetup.h"
#include "packetpool.h"
#include "packetqueue.h"
#include "pktpin.h"
#include <hal_adda.h>
#include <hal_host.h>
static sample_time_t rangingDelay = 0; // ticks
static sample_time_t rangingTx = 0; // set after sending a ranging ping
// empirical value, subject to change and potential source of error upon algorithm / parameter change
// why do these occur anyway?, where is the untracked time "going"?
// FIXME this is HW dependent, move ... where?
#define RANGING_PROCESSING_DELAY 34 // measured with modems #2/#3 (mean 33.9us, stddev 6.2us for each direction!)
/**************************************************************************
* private type definitions
*/
typedef struct {
uint32_t delay; // micro seconds
uint32_t delay; // processing delay (time delta between ping reception
// and pong transmission) (micro seconds)
} pong_t;
typedef struct {
uint32_t tof; // micro seconds
sample_time_t pingTxTime;
sample_time_t pongSyncTime;
uint32_t remoteDelay; // micro seconds
uint32_t tof; // pure 2-way time-of-flight (micro seconds)
uint32_t pingTxDt; // time delta of ping transmission since pong processing (micro seconds)
uint32_t pongRxDt; // time delta of pong start and processing (micro seconds)
uint32_t remoteDelay; // remote processing delay (micro seconds)
} serial_pong_t;
// FIXME if there are modems with different times (ticks, i.e., sampling frequency),
// this will fail ...
// so convert to a common time (us?)
/**************************************************************************
* local global variables
*/
static sample_time_t rangingDelay = 0; // ticks
static sample_time_t rangingTx = 0; // set after sending a ranging ping
/**************************************************************************
* public functions
*/
void
ranging_createPong(mm_packet_t * pong, const mm_packet_t * const ping)
{
......@@ -129,11 +142,17 @@ ranging_processPong(mm_packet_t * const pong)
if (dt < 0) {
dt = 0;
}
// pull pktpin trigger right now to make it most accurate!
pktpin_trigger(PKTPIN_TRIG_RANGE);
sample_time_t now = adda_getTimerTicks();
uint32_t txDt = TICKS_TO_US(now - rangingTx);
uint32_t rxDt = TICKS_TO_US(now - pong->meta.startTime);
// fill ranging data fields
spp.tof = HTONL((uint32_t)dt);
spp.pingTxTime = HTONL(rangingTx);
spp.pongSyncTime = HTONL(pong->meta.syncTime);
spp.pingTxDt = HTONL(txDt);
spp.pongRxDt = HTONL(rxDt);
spp.remoteDelay = HTONL(rdt);
// append ranging result to actual payload
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment