From f4a4b9772f6d039d5026fa7348f09e557abe898c Mon Sep 17 00:00:00 2001 From: Guy McSwain Date: Tue, 3 Mar 2020 23:13:57 -0600 Subject: [PATCH] Wave create using fixed size CB, OOL --- command.c | 2 +- pigpio.c | 39 ++++++++++++++++++++++++++++++++++----- pigpio.h | 2 +- pigpio.py | 4 ++-- x_pigpio.c | 4 ++-- 5 files changed, 40 insertions(+), 11 deletions(-) diff --git a/command.c b/command.c index 4a1da4d..0687057 100644 --- a/command.c +++ b/command.c @@ -201,7 +201,7 @@ cmdInfo_t cmdInfo[]= {PI_CMD_WVBSY, "WVBSY", 101, 2, 1}, // gpioWaveTxBusy {PI_CMD_WVCHA, "WVCHA", 197, 0, 0}, // gpioWaveChain {PI_CMD_WVCLR, "WVCLR", 101, 0, 1}, // gpioWaveClear - {PI_CMD_WVCRE, "WVCRE", 101, 2, 1}, // gpioWaveCreate + {PI_CMD_WVCRE, "WVCRE", 112, 2, 1}, // gpioWaveCreate {PI_CMD_WVDEL, "WVDEL", 112, 0, 1}, // gpioWaveDelete {PI_CMD_WVGO, "WVGO" , 101, 2, 0}, // gpioWaveTxStart {PI_CMD_WVGOR, "WVGOR", 101, 2, 0}, // gpioWaveTxStart diff --git a/pigpio.c b/pigpio.c index fe5fc04..45d274f 100644 --- a/pigpio.c +++ b/pigpio.c @@ -2432,7 +2432,7 @@ static int myDoCommand(uintptr_t *p, unsigned bufSize, char *buf) case PI_CMD_WVCLR: res = gpioWaveClear(); break; - case PI_CMD_WVCRE: res = gpioWaveCreate(); break; + case PI_CMD_WVCRE: res = gpioWaveCreate(p[1]); break; case PI_CMD_WVDEL: res = gpioWaveDelete(p[1]); break; @@ -2992,7 +2992,7 @@ static void waveCBsOOLs(int *numCBs, int *numBOOLs, int *numTOOLs) /* ----------------------------------------------------------------------- */ -static int wave2Cbs(unsigned wave_mode, int *CB, int *BOOL, int *TOOL) +static int wave2Cbs(unsigned wave_mode, int *CB, int *BOOL, int *TOOL, int size) { int botCB=*CB, botOOL=*BOOL, topOOL=*TOOL; @@ -3130,6 +3130,25 @@ static int wave2Cbs(unsigned wave_mode, int *CB, int *BOOL, int *TOOL) } } + /* pad the wave */ + botCB = *CB + NUM_WAVE_CBS / size - 1; + botOOL = *BOOL + NUM_WAVE_OOL / size - 1; + //topOOL = *TOOL - (NUM_WAVE_OOL / size / 8); + + /* link the last CB to end of wave */ + + p->next = waveCbPOadr(botCB); + + /* add dummy cb at end of DMA */ + + p = rawWaveCBAdr(botCB++); + p->info = NORMAL_DMA | DMA_DEST_IGNORE; + p->src = waveOOLPOadr(botOOL++); + p->dst = ((GPIO_BASE + (GPSET0*4)) & 0x00ffffff) | PI_PERI_BUS; + p->length = 4; + p->next = 0; + + if (p != NULL) { if (wave_mode == PI_WAVE_MODE_ONE_SHOT) @@ -9552,7 +9571,7 @@ int rawWaveAddSPI( /* ----------------------------------------------------------------------- */ -int gpioWaveCreate(void) +int gpioWaveCreate(int size) // Fix: Make variadic. { int i, wid; int numCB, numBOOL, numTOOL; @@ -9566,7 +9585,14 @@ int gpioWaveCreate(void) /* What resources are needed? */ - waveCBsOOLs(&numCB, &numBOOL, &numTOOL); + if (size == 0) + waveCBsOOLs(&numCB, &numBOOL, &numTOOL); + + else { + numCB = NUM_WAVE_CBS / size; + numBOOL = NUM_WAVE_OOL / size; + numTOOL = 0; // ignore TOOL, ie, no flags support + } wid = -1; @@ -9619,7 +9645,7 @@ int gpioWaveCreate(void) BOOL = waveInfo[wid].botOOL; TOOL = waveInfo[wid].topOOL; - wave2Cbs(PI_WAVE_MODE_ONE_SHOT, &CB, &BOOL, &TOOL); + wave2Cbs(PI_WAVE_MODE_ONE_SHOT, &CB, &BOOL, &TOOL, size); /* Sanity check. */ @@ -9633,6 +9659,9 @@ int gpioWaveCreate(void) numTOOL, waveInfo[wid].topOOL-TOOL); } + DBG(DBG_USER, "Wave Stats: wid=%d CBs %d BOOL %d TOOL %d", wid, + numCB, numBOOL, numTOOL); + waveInfo[wid].deleted = 0; /* Consume waves. */ diff --git a/pigpio.h b/pigpio.h index e3eb97d..8930d12 100644 --- a/pigpio.h +++ b/pigpio.h @@ -1933,7 +1933,7 @@ D*/ /*F*/ -int gpioWaveCreate(void); +int gpioWaveCreate(int); /*D This function creates a waveform from the data provided by the prior calls to the [*gpioWaveAdd**] functions. Upon success a wave id diff --git a/pigpio.py b/pigpio.py index cfaf845..af63a19 100644 --- a/pigpio.py +++ b/pigpio.py @@ -2257,7 +2257,7 @@ class pi(): else: return 0 - def wave_create(self): + def wave_create(self, size): """ Creates a waveform from the data provided by the prior calls to the [*wave_add_**] functions. @@ -2302,7 +2302,7 @@ class pi(): wid = pi.wave_create() ... """ - return _u2i(_pigpio_command(self.sl, _PI_CMD_WVCRE, 0, 0)) + return _u2i(_pigpio_command(self.sl, _PI_CMD_WVCRE, size, 0)) def wave_delete(self, wave_id): """ diff --git a/x_pigpio.c b/x_pigpio.c index cd15389..61b37c2 100644 --- a/x_pigpio.c +++ b/x_pigpio.c @@ -391,7 +391,7 @@ To the lascivious pleasing of a lute.\n\ e = gpioWaveAddGeneric(4, wf); CHECK(5, 2, e, 4, 0, "pulse, wave add generic"); - wid = gpioWaveCreate(); + wid = gpioWaveCreate(0); e = gpioWaveTxSend(wid, PI_WAVE_MODE_REPEAT); if (e < 14) CHECK(5, 3, e, 9, 0, "wave tx repeat"); else CHECK(5, 3, e, 19, 0, "wave tx repeat"); @@ -413,7 +413,7 @@ To the lascivious pleasing of a lute.\n\ e = gpioWaveAddSerial(GPIO, BAUD, 8, 2, 5000000, strlen(TEXT), TEXT); CHECK(5, 7, e, 3405, 0, "wave clear, wave add serial"); - wid = gpioWaveCreate(); + wid = gpioWaveCreate(0); e = gpioWaveTxSend(wid, PI_WAVE_MODE_ONE_SHOT); if (e < 6964) CHECK(5, 8, e, 6811, 0, "wave tx start"); else CHECK(5, 8, e, 7116, 0, "wave tx start");