LCOV - code coverage report
Current view: top level - packet - interleave.c (source / functions) Hit Total Coverage
Test: test-37de7e7-dirty-coverage.info Lines: 18 18 100.0 %
Date: 2019-04-16 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /* @file interleave.c
       2             :  *
       3             :  * Packet Interleaving Functions
       4             :  *
       5             :  * @author Phil Crump
       6             :  *
       7             :  * @ingroup packet
       8             :  * @{
       9             :  */
      10             : 
      11             : #include "../firmware.h"
      12             : 
      13             : /**
      14             :  * @brief Interleave (transpose) a 32x32 bit buffer.
      15             :  *
      16             :  * @description Length of input must be 1024 bits (128 bytes).
      17             :  *
      18             :  * @param buffer Pointer to the buffer to be interleaved.
      19             :  */
      20           4 : void Packet_interleave_32x32(uint8_t *buffer)
      21             : {
      22             :    uint32_t i, j;
      23           4 :    uint8_t output[128] = { 0 };
      24             : 
      25        4100 :    for(i=0;i<1024;i++)
      26             :    {
      27        4096 :       j = (((i & 0x1f) << 5) + (i >> 5));
      28             :       
      29        4096 :       if((i & 0x07) >= (j & 0x07))
      30             :       {
      31        2304 :          output[j>>3] = (uint8_t)(output[j>>3] | ((buffer[i>>3] & (0x80 >> (i & 0x07))) << ((i & 0x07) - (j & 0x07))));
      32             :       }
      33             :       else
      34             :       {
      35        1792 :          output[j>>3] = (uint8_t)(output[j>>3] | ((buffer[i>>3] & (0x80 >> (i & 0x07))) >> ((j & 0x07) - (i & 0x07))));
      36             :       }
      37             :    }
      38             : 
      39           4 :    memcpy(buffer, output, 128);
      40           4 : }
      41             : 
      42             : /**
      43             :  * @brief Interleave (transpose) a 64x64 bit buffer.
      44             :  *
      45             :  * @description Length of input must be 4096 bits (512 bytes).
      46             :  *
      47             :  * @param buffer Pointer to the buffer to be interleaved.
      48             :  */
      49           2 : void Packet_interleave_64x64(uint8_t *buffer)
      50             : {
      51             :    uint32_t i, j;
      52           2 :    uint8_t output[512] = { 0 };
      53             : 
      54        8194 :    for(i=0;i<4096;i++)
      55             :    {
      56        8192 :       j = (((i & 0x3f) << 6) + (i >> 6));
      57             :       
      58        8192 :       if((i & 0x07) >= (j & 0x07))
      59             :       {
      60        4608 :          output[j>>3] = (uint8_t)(output[j>>3] | ((buffer[i>>3] & (0x80 >> (i & 0x07))) << ((i & 0x07) - (j & 0x07))));
      61             :       }
      62             :       else
      63             :       {
      64        3584 :          output[j>>3] = (uint8_t)(output[j>>3] | ((buffer[i>>3] & (0x80 >> (i & 0x07))) >> ((j & 0x07) - (i & 0x07))));
      65             :       }
      66             :    }
      67             : 
      68           2 :    memcpy(buffer, output, 512);
      69           2 : }
      70             : 
      71             : /**
      72             :  * @}
      73             :  */

Generated by: LCOV version 1.10