primes

table allocation module for first 1024 primes.
Author: Remco van der Most
License: BSD
Github: sss/table/primes.axo

Inlets

None

Outlets

None

Declaration
static const uint32_t LENGTHPOW = 10;
static const uint32_t LENGTH = 1024;
static const uint32_t LENGTHMASK = 1023;
static const uint32_t BITS = 16;
static const uint32_t GAIN = 12;
int16_t *array;
int i;
Init
static int16_t _array[attr_poly][LENGTH] __attribute__((section(".sdram")));
array = &_array[parent->polyIndex][0];

FIL FileObject;
FRESULT err;
UINT bytes_read;
err = f_open(&FileObject, "0:/1024primes.tab", FA_READ | FA_OPEN_EXISTING);
if (err != FR_OK) {
  report_fatfs_error(err, "0:/1024primes.tab");
  return;
}
int rem_sz = 1024;
int offset = 0;
while (rem_sz > 0) {
  if (rem_sz > sizeof(fbuff)) {
    err = f_read(&FileObject, fbuff, sizeof(fbuff), &bytes_read);
    if (bytes_read == 0)
      break;
    memcpy((char *)(_array[0]) + offset, (char *)fbuff, bytes_read);
    rem_sz -= bytes_read;
    offset += bytes_read;
  } else {
    err = f_read(&FileObject, fbuff, rem_sz, &bytes_read);
    memcpy((char *)(_array[0]) + offset, (char *)fbuff, bytes_read);
    rem_sz = 0;
  }
}
if (err != FR_OK) {
  report_fatfs_error(err, "0:/1024primes.tab");
  return;
};
err = f_close(&FileObject);
if (err != FR_OK) {
  report_fatfs_error(err, "0:/1024primes.tab");
  return;
};

Privacy

© 2024 Zrna Research