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

View File

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

View File

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