gustavonihei commented on a change in pull request #3795:
URL: https://github.com/apache/incubator-nuttx/pull/3795#discussion_r640632208



##########
File path: arch/arm/src/s32k1xx/s32k1xx_lpspi.c
##########
@@ -1293,13 +1386,176 @@ static void s32k1xx_lpspi_exchange_nodma(FAR struct 
spi_dev_s *dev,
 #endif
 {
   FAR struct s32k1xx_lpspidev_s *priv = (FAR struct s32k1xx_lpspidev_s *)dev;
+  uint16_t framesize;
   DEBUGASSERT(priv && priv->spibase);
 
   spiinfo("txbuffer=%p rxbuffer=%p nwords=%d\n", txbuffer, rxbuffer, nwords);
 
-  /* 8- or 16-bit mode? */
+  /* bit mode? */
 
-  if (s32k1xx_lpspi_9to16bitmode(priv))
+  framesize = s32k1xx_lpspi_9to16bitmode(priv);
+  if (framesize > 16 && framesize % 32 != 0)
+    {
+      /* 17-bit or higher, byte transfer due to padding
+       * take care of big endian mode of hardware !!
+       */
+
+      const uint8_t *src = (const uint8_t *)txbuffer;
+      uint8_t *dest = (uint8_t *) rxbuffer;
+      uint32_t word = 0x0;
+#ifdef CONFIG_S32K1XX_LPSPI_DWORD
+      uint32_t word1 = 0x0;
+      uint32_t rword1;
+      bool     dwords = false;
+#endif
+
+      while (nwords-- > 0)
+        {
+          /* Get the next word to write.  Is there a source buffer? */
+
+          if (src)
+            {
+              /* read the required number of bytes */
+
+            switch (framesize)
+              {
+#ifdef CONFIG_S32K1XX_LPSPI_DWORD
+              case 40:
+                   word = (src[0] << 24) + (src[1] << 16)
+                          + (src[2] << 8) + src[3];
+                   word1 = src[4];
+                   src += 5;
+                   dwords = true;
+                   break;
+#endif
+              default:
+                      break;
+              }
+            }
+          else
+            {
+              word = 0xffffffff;
+            }
+
+#ifdef CONFIG_S32K1XX_LPSPI_DWORD
+          /* Exchange 2 words */
+
+          if (dwords)
+            {
+              word = s32k1xx_lpspi_send_dword(dev, word, word1, &rword1);
+            }
+          else
+#endif
+            {
+            word = s32k1xx_lpspi_send(dev, word);

Review comment:
       Alignment here seems wrong.
   I am surprised that NxStyle didn't catch this.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to