Wave create using fixed size CB, OOL
authorGuy McSwain <guy.mcswain@gmail.com>
Wed, 4 Mar 2020 05:13:57 +0000 (23:13 -0600)
committerGuy McSwain <guy.mcswain@gmail.com>
Wed, 4 Mar 2020 05:13:57 +0000 (23:13 -0600)
command.c
pigpio.c
pigpio.h
pigpio.py
x_pigpio.c

index 4a1da4dc7b0978e9077a1da9e36e7bc727e7b559..0687057c62b8acc163a86135ef300b3269c2725d 100644 (file)
--- 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
index fe5fc04bc26aab0eb0f4d54e7dcda1e97b62d42f..45d274f9ed2bc63db75c18c3d6c092593df14af7 100644 (file)
--- 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. */
index e3eb97d93e83b92c94e5122cf9d15e872ac93d06..8930d12807e55ebe1a1ce1821951c0ccf2a1515c 100644 (file)
--- 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
index cfaf845ed4617ef482fb9b987ae9f0cb541fed49..af63a19ee8c21e6496d2b11464d75f3ecdeb13f7 100644 (file)
--- 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):
       """
index cd15389c97262aa6a289d0e05d0fd05f86ebcf4c..61b37c2ca5b89779ce5c1a621fff596dd639c78c 100644 (file)
@@ -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");