Fixed DMA option index check.

This commit is contained in:
mikeller 2019-02-28 20:27:04 +13:00
parent 31425f5171
commit e65c0f890e
3 changed files with 11 additions and 10 deletions

View File

@ -4701,7 +4701,7 @@ dmaoptEntry_t dmaoptEntryTable[] = {
static void dmaoptToString(int optval, char *buf)
{
if (optval == -1) {
if (optval == DMA_OPT_UNUSED) {
memcpy(buf, "NONE", DMA_OPT_STRING_BUFSIZE);
} else {
tfp_sprintf(buf, "%d", optval);
@ -4891,7 +4891,7 @@ static void cliDmaopt(char *cmdline)
} else {
// It's a pin
if (!pch || !(strToPin(pch, &ioTag) && IOGetByTag(ioTag))) {
cliPrintErrorLinef("INVALID PIN: %s", pch);
cliPrintErrorLinef("INVALID PIN: '%s'", pch);
return;
}
@ -4907,13 +4907,13 @@ static void cliDmaopt(char *cmdline)
pch = strtok_r(NULL, " ", &saveptr);
if (!pch) {
if (entry) {
if (orgval == -1) {
if (orgval == DMA_OPT_UNUSED) {
cliPrintLinef("%s %d NONE", entry->device, index + 1);
} else {
cliPrintLinef("%s %d %d", entry->device, index + 1, *optaddr);
}
} else {
if (orgval == -1) {
if (orgval == DMA_OPT_UNUSED) {
cliPrintLinef("pin %c%02d NONE", IO_GPIOPortIdxByTag(ioTag) + 'A', IO_GPIOPinIdxByTag(ioTag));
} else {
cliPrintLinef("pin %c%02d %d", IO_GPIOPortIdxByTag(ioTag) + 'A', IO_GPIOPinIdxByTag(ioTag), orgval);
@ -4942,8 +4942,9 @@ static void cliDmaopt(char *cmdline)
optval = DMA_OPT_UNUSED;
} else {
optval = atoi(pch);
if (optval < 0) { // XXX Check against opt max? How?
cliPrintLinef("bad optnum %s", pch);
if (optval < 0 || (entry && optval >= MAX_PERIPHERAL_DMA_OPTIONS) || (!entry && optval >= MAX_TIMER_DMA_OPTIONS)) {
cliPrintErrorLinef("BAD DMA OPTION NUMBER '%s'", pch);
return;
}
}

View File

@ -34,16 +34,12 @@
#include "dma_reqmap.h"
#define MAX_PERIPHERAL_DMA_OPTIONS 2
typedef struct dmaPeripheralMapping_s {
dmaPeripheral_e device;
uint8_t index;
dmaChannelSpec_t channelSpec[MAX_PERIPHERAL_DMA_OPTIONS];
} dmaPeripheralMapping_t;
#define MAX_TIMER_DMA_OPTIONS 3
typedef struct dmaTimerMapping_s {
TIM_TypeDef *tim;
uint8_t channel;

View File

@ -52,8 +52,12 @@ typedef enum {
} dmaPeripheral_e;
typedef int8_t dmaoptValue_t;
#define DMA_OPT_UNUSED (-1)
#define MAX_PERIPHERAL_DMA_OPTIONS 2
#define MAX_TIMER_DMA_OPTIONS 3
dmaoptValue_t dmaoptByTag(ioTag_t ioTag);
const dmaChannelSpec_t *dmaGetChannelSpecByPeripheral(dmaPeripheral_e device, uint8_t index, int8_t opt);
const dmaChannelSpec_t *dmaGetChannelSpecByTimerValue(TIM_TypeDef *tim, uint8_t channel, dmaoptValue_t dmaopt);