Skip to content

File conv_core.h

File List > conv > conv_core.h

Go to the documentation of this file

#ifndef CONV_CORE_H
#define CONV_CORE_H

#include "clib_common.h"
#include "dp_state.h"

#include <stddef.h>
#include <stdint.h>

#ifdef __cplusplus
extern "C"
{
#endif

#define CONV_K_MAX 9

#define CONV_N_MAX 6

  typedef struct
  {
    unsigned k;                  
    unsigned n;                  
    uint32_t poly[CONV_N_MAX];   
    uint32_t invert;             
  } conv_code_t;

  int conv_code_valid (const conv_code_t *c);

  JM_FORCEINLINE uint32_t
  conv_states (const conv_code_t *c)
  {
    return 1u << (c->k - 1u);
  }

  unsigned conv_outputs (const conv_code_t *c, uint32_t state, unsigned bit);

  JM_FORCEINLINE uint32_t
  conv_next_state (const conv_code_t *c, uint32_t state, unsigned bit)
  {
    return (((bit & 1u) << (c->k - 1u)) | state) >> 1;
  }

  /* ── the encoder ─────────────────────────────────────────────────────── */

  typedef struct
  {
    uint32_t reg; 
  } conv_enc_t;

  void conv_enc_init (conv_enc_t *s);

  size_t conv_encode (conv_enc_t *s, const conv_code_t *c, const uint8_t *in,
                      size_t n_in, uint8_t *out, size_t max_out);

#ifdef __cplusplus
}
#endif

#endif /* CONV_CORE_H */