Exemple #1
0
void type_write(type_t t, type_wr_ctx_t ctx)
{
   fbuf_t *f = tree_write_file(ctx->tree_ctx);

   if (t == NULL) {
      write_u16(UINT16_C(0xffff), f);   // Null marker
      return;
   }

   if (t->generation == ctx->generation) {
      // Already visited this type
      write_u16(UINT16_C(0xfffe), f);   // Back reference marker
      write_u32(t->index, f);
      return;
   }

   t->generation = ctx->generation;
   t->index      = (ctx->n_types)++;

   write_u16(t->kind, f);

   // Call type_ident here to generate an arbitrary name if needed
   ident_write(type_ident(t), ctx->ident_ctx);

   const uint32_t has = has_map[t->kind];
   const int nitems = __builtin_popcount(has);
   uint32_t mask = 1;
   for (int n = 0; n < nitems; mask <<= 1) {
      if (has & mask) {
         if (ITEM_TYPE_ARRAY & mask) {
            type_array_t *a = &(t->items[n].type_array);
            write_u16(a->count, f);
            for (unsigned i = 0; i < a->count; i++)
               type_write(a->items[i], ctx);
         }
         else if (ITEM_TYPE & mask)
            type_write(t->items[n].type, ctx);
         else if (ITEM_TREE & mask)
            tree_write(t->items[n].tree, ctx->tree_ctx);
         else if (ITEM_TREE_ARRAY & mask) {
            tree_array_t *a = &(t->items[n].tree_array);
            write_u16(a->count, f);
            for (unsigned i = 0; i < a->count; i++)
               tree_write(a->items[i], ctx->tree_ctx);
         }
         else if (ITEM_RANGE_ARRAY & mask) {
            range_array_t *a = &(t->items[n].range_array);
            write_u16(a->count, f);
            for (unsigned i = 0; i < a->count; i++) {
               write_u8(a->items[i].kind, f);
               tree_write(a->items[i].left, ctx->tree_ctx);
               tree_write(a->items[i].right, ctx->tree_ctx);
            }
         }
         else
            item_without_type(mask);
         n++;
      }
   }
}
Exemple #2
0
void pwm_init(void)
{
  /* Configure Timer1 in PWM Fast mode */
  TCCR1B =
    (0<<WGM13)|(1<<WGM12)|         /*< Mode: Fast PWM, 8 bit */
    (0<<CS12)|(1<<CS11)|(1<<CS10)| /* Prescaler: 64 */
    (0<< ICNC1)|(0<< ICES1);       /*< No extra flags */
  TCCR1A =
    (0<<WGM11)|(1<<WGM10)|         /*< Mode: Fast PWM, 8 bit */
    (1<<COM1A1)|(0<<COM1A0)|       /*< Compare output mode OC1A: non-inverting */
    (1<<COM1B1)|(0<<COM1B0)|       /*< Compare output mode OC1B: non-inverting */
    (0<<FOC1A)|(0<<FOC1B);         /*< No forced output */
  OCR1A = UINT16_C(0);
  OCR1B = UINT16_C(0);
  TCNT1 = UINT16_C(0);
  DDRD |= ((1U << DDD4)|(1U << DDD5)|(1U << DDD7));

  /* Configure Timer2 in PWM fast mode */
  /* Reset the Timer2 counter */
  TCNT2 = UINT8_C(0);
  /* Timer2 compare register: 1001.73913Hz */
  OCR2 = UINT8_C(0);
  /* Set the control register */
  TCCR2 =
    (1<<WGM21)|(1<<WGM20)| /*< Mode: Fast PWM */
    (1<<COM21)|(0<<COM21)| /*< Compare output mode OC2: non-inverting */
    (1<<CS22)|(0<<CS21)|(0<<CS20); /* Prescaler: 64 */
}
Exemple #3
0
void mcal::gpt::init(const config_type*)
{
  if(gpt_is_initialized() == false)
  {
    // Protection off
    // SYSTEM.PRCR.WORD = 0xA503u;
    mcal::reg::access<std::uint32_t,
                      std::uint16_t,
                      mcal::reg::prcr,
                      UINT16_C(0xA503)>::reg_set();

    // Activate timer0/timer1 by clearing bit-5 in the module-stop register.
    mcal::reg::access<std::uint32_t,
                      std::uint32_t,
                      mcal::reg::mstpcra,
                      UINT8_C(5)>::bit_clr();

    // Protection on
    // SYSTEM.PRCR.WORD = 0xA500u;
    mcal::reg::access<std::uint32_t,
                      std::uint16_t,
                      mcal::reg::prcr,
                      UINT16_C(0xA500)>::reg_set();

    // Set timer0 to have an interrupt on overflow.
    mcal::reg::access<std::uint32_t,
                      std::uint8_t,
                      mcal::reg::tmr0_tcr,
                      UINT8_C(0x20)>::reg_set();

    // Enable the timer0 overflow interrupt at ier15.4.
    mcal::reg::access<std::uint32_t,
                      std::uint8_t,
                      mcal::reg::icu_ier15,
                      UINT8_C(0x04)>::bit_set();

    // Set the timer0 overflow interrupt priority to 7.
    mcal::reg::access<std::uint32_t,
                      std::uint8_t,
                      mcal::reg::icu_ipr170,
                      UINT8_C(0x07)>::reg_set();

    // Select the internal clock (not external) with the value 8.
    // Also select a prescaler of 32 with the value 3.
    mcal::reg::access<std::uint32_t,
                      std::uint8_t,
                      mcal::reg::tmr0_tccr,
                      static_cast<std::uint8_t>(UINT8_C(0x08) | UINT8_C(0x03))>::reg_set();

    // Start timer0 counting up.
    mcal::reg::access<std::uint32_t,
                      std::uint16_t,
                      mcal::reg::cmt_cmstr0,
                      UINT16_C(0x01)>::reg_set();

    gpt_is_initialized() = true;
  }
}
static void map_out(uint16_t m, uint8_t **pp)
{
  assert(pp);
  b_out((uint8_t)(m >> 8),pp);
  b_out((uint8_t)m,pp);
  w_out(UINT16_C(0),pp);
}
Exemple #5
0
static MunitResult
test_endian_swap_random(const MunitParameter params[], void* data) {
  (void) params;
  (void) data;

  munit_assert_uint16(psnip_builtin_bswap16(UINT16_C(0xefbe)), ==, UINT16_C(0xbeef));
  {
    const psnip_uint16_t input = (psnip_uint16_t) munit_rand_uint32();
    const psnip_uint16_t swapped = psnip_builtin_bswap16(input);
    const psnip_uint16_t double_swapped = psnip_builtin_bswap16(swapped);

    munit_assert_uint16(input, ==, double_swapped);
  }

  munit_assert_uint32(psnip_builtin_bswap32(UINT32_C(0xefbeadde)), ==, UINT32_C(0xdeadbeef));
  {
    const psnip_uint32_t input = munit_rand_uint32();
    const psnip_uint32_t swapped = psnip_builtin_bswap32(input);
    const psnip_uint32_t double_swapped = psnip_builtin_bswap32(swapped);

    munit_assert_uint32(input, ==, double_swapped);
  }

  munit_assert_uint64(psnip_builtin_bswap64(UINT64_C(0xdf0dde0fe0fdcba)), ==, UINT64_C(0xbadc0ffee0ddf00d));
  {
    const psnip_uint64_t input = (((psnip_uint64_t) munit_rand_uint32()) << 32) | munit_rand_uint32();
    const psnip_uint64_t swapped = psnip_builtin_bswap64(input);
    const psnip_uint64_t double_swapped = psnip_builtin_bswap64(swapped);

    munit_assert_uint64(input, ==, double_swapped);
  }

  return MUNIT_OK;
}
static void allocate_n_sectors(uint_fast8_t c_used_sectors, uint16_t *track_map)
{
	int uint16_value;

  assert(track_map);
	uint16_value = *track_map << c_used_sectors;
	*track_map = (uint16_t)(uint16_value & UINT16_C(0xFFFF));
}
Exemple #7
0
int main(void)
{
  char buf[64];
  int8_t i8;
  uint8_t u8;
  int16_t i16;
  uint16_t u16;
#if defined(__SMALLER_C_32__) || !defined(__SMALLER_C__)
  int32_t i32;
  uint32_t u32;
#endif
  intmax_t imax;
  uintmax_t umax;
  TEST_PRINT(buf, PRId8, INT8_C(-128), "-128");
  TEST_PRINT(buf, PRIi8, INT8_C(-128), "-128");
  TEST_PRINT(buf, PRIo8, UINT8_C(255), "377");
  TEST_PRINT(buf, PRIu8, UINT8_C(255), "255");
  TEST_PRINT(buf, PRIx8, UINT8_C(255), "ff");
  TEST_PRINT(buf, PRIX8, UINT8_C(255), "FF");
  TEST_PRINT(buf, PRId16, INT16_C(-32767), "-32767");
  TEST_PRINT(buf, PRIi16, INT16_C(-32767), "-32767");
  TEST_PRINT(buf, PRIo16, UINT16_C(65535), "177777");
  TEST_PRINT(buf, PRIu16, UINT16_C(65535), "65535");
  TEST_PRINT(buf, PRIx16, UINT16_C(65535), "ffff");
  TEST_PRINT(buf, PRIX16, UINT16_C(65535), "FFFF");
  TEST_PRINT(buf, PRIdMAX, INTMAX_C(-32767), "-32767");
  TEST_PRINT(buf, PRIuMAX, UINTMAX_C(65535), "65535");
#if defined(__SMALLER_C_32__) || !defined(__SMALLER_C__)
  TEST_PRINT(buf, PRId32, INT32_C(-2147483647), "-2147483647");
  TEST_PRINT(buf, PRIi32, INT32_C(-2147483647), "-2147483647");
  TEST_PRINT(buf, PRIo32, UINT32_C(4294967295), "37777777777");
  TEST_PRINT(buf, PRIu32, UINT32_C(4294967295), "4294967295");
  TEST_PRINT(buf, PRIx32, UINT32_C(4294967295), "ffffffff");
  TEST_PRINT(buf, PRIX32, UINT32_C(4294967295), "FFFFFFFF");
  TEST_PRINT(buf, PRIdMAX, INTMAX_C(-2147483647), "-2147483647");
  TEST_PRINT(buf, PRIuMAX, UINTMAX_C(4294967295), "4294967295");
#endif
  TEST_SCAN("-128", SCNd8, i8, INT8_C(-128));
  TEST_SCAN("-128", SCNi8, i8, INT8_C(-128));
  TEST_SCAN("377", SCNo8, u8, UINT8_C(255));
  TEST_SCAN("255", SCNu8, u8, UINT8_C(255));
  TEST_SCAN("Ff", SCNx8, u8, UINT8_C(255));
  TEST_SCAN("-32767", SCNd16, i16, INT16_C(-32767));
  TEST_SCAN("-32767", SCNi16, i16, INT16_C(-32767));
  TEST_SCAN("177777", SCNo16, u16, UINT16_C(65535));
  TEST_SCAN("65535", SCNu16, u16, UINT16_C(65535));
  TEST_SCAN("FffF", SCNx16, u16, UINT16_C(65535));
  TEST_SCAN("-32767", SCNdMAX, imax, INTMAX_C(-32767));
  TEST_SCAN("65535", SCNuMAX, umax, UINTMAX_C(65535));
#if defined(__SMALLER_C_32__) || !defined(__SMALLER_C__)
  TEST_SCAN("-2147483647", SCNd32, i32, INT32_C(-2147483647));
  TEST_SCAN("-2147483647", SCNi32, i32, INT32_C(-2147483647));
  TEST_SCAN("37777777777", SCNo32, u32, UINT32_C(4294967295));
  TEST_SCAN("4294967295", SCNu32, u32, UINT32_C(4294967295));
  TEST_SCAN("ffFFffFF", SCNx32, u32, UINT32_C(4294967295));
  TEST_SCAN("-2147483647", SCNdMAX, imax, INTMAX_C(-2147483647));
  TEST_SCAN("4294967295", SCNuMAX, umax, UINTMAX_C(4294967295));
#endif
  return 0;
}
Exemple #8
0
static MunitResult
test_endian_swap_known(const MunitParameter params[], void* data) {
  (void) params;
  (void) data;

  munit_assert_uint16(psnip_builtin_bswap16(UINT16_C(0xefbe)), ==, UINT16_C(0xbeef));
  munit_assert_uint32(psnip_builtin_bswap32(UINT32_C(0xefbeadde)), ==, UINT32_C(0xdeadbeef));
  munit_assert_uint64(psnip_builtin_bswap64(UINT64_C(0x0df0dde0fe0fdcba)), ==, UINT64_C(0xbadc0ffee0ddf00d));

  return MUNIT_OK;
}
static uint16_t get_free_track_map(uint_fast16_t version)
{
  uint_fast8_t cs = sectors_per_track(version);
  uint16_t mk = 0;

  while (cs--)
    {
      mk >>= 1;
      mk |= UINT16_C(0x8000);
    }
  return mk;
}
EXTERN_C
void rpTask2_Init()
{
  Pwm_SetPeriodAndDuty(ARDUINO_RGB_G, UINT16_C(500), UINT16_C(0x4000));
  Pwm_SetPeriodAndDuty(ARDUINO_RGB_B, UINT16_C(500), UINT16_C(0x4000));
  Pwm_SetPeriodAndDuty(ARDUINO_RGB_R, UINT16_C(500), UINT16_C(0x4000));
}
TEST(WireFormat, SimpleRawDataStruct) {
  AlignedData<2> data = {{
    // Struct ref, offset = 1, dataSize = 1, referenceCount = 0
    0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
    // Content for the data segment.
    0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef
  }};

  struct capn_segment seg;
  memset(&seg, 0, sizeof(seg));
  seg.data = (char*) data.bytes;
  seg.len = seg.cap = sizeof(data.bytes);

  struct capn ctx;
  memset(&ctx, 0, sizeof(ctx));
  capn_append_segment(&ctx, &seg);

  EXPECT_EQ(&seg, ctx.seglist);
  EXPECT_EQ(&seg, ctx.lastseg);
  EXPECT_EQ(&seg.hdr, ctx.segtree);
  EXPECT_EQ(1, ctx.segnum);
  EXPECT_EQ(0, seg.id);

  struct capn_ptr ptr = capn_getp(capn_root(&ctx), 0, 1);
  EXPECT_EQ(CAPN_STRUCT, ptr.type);
  EXPECT_EQ(8, ptr.datasz);
  EXPECT_EQ(0, ptr.ptrs);

  EXPECT_EQ(UINT64_C(0xefcdab8967452301), capn_read64(ptr, 0));
  EXPECT_EQ(UINT64_C(0), capn_read64(ptr, 8));
  EXPECT_EQ(UINT32_C(0x67452301), capn_read32(ptr, 0));
  EXPECT_EQ(UINT32_C(0xefcdab89), capn_read32(ptr, 4));
  EXPECT_EQ(UINT32_C(0), capn_read32(ptr, 8));
  EXPECT_EQ(UINT16_C(0x2301), capn_read16(ptr, 0));
  EXPECT_EQ(UINT16_C(0x6745), capn_read16(ptr, 2));
  EXPECT_EQ(UINT16_C(0xab89), capn_read16(ptr, 4));
  EXPECT_EQ(UINT16_C(0xefcd), capn_read16(ptr, 6));
  EXPECT_EQ(UINT16_C(0), capn_read16(ptr, 8));
}
TEST(LastBitTest, lastbit16) {
  // There are uint16_t, uint32_t and uint64_t overloads of lastbit.
  // Explicitly cast arg so we know which we are testing.
  EXPECT_EQ(0, lastbit(uint16_t(0)));
  EXPECT_EQ(0, lastbit(uint16_t(1)));
  EXPECT_EQ(1, lastbit(uint16_t(2)));
  EXPECT_EQ(0, lastbit(uint16_t(3)));
  EXPECT_EQ(2, lastbit(uint16_t(4)));
  EXPECT_EQ(0, lastbit(uint16_t(31)));
  EXPECT_EQ(5, lastbit(uint16_t(32)));
  EXPECT_EQ(2, lastbit(uint16_t(36)));

  for (int i = 1; i < 16; i++) {
    EXPECT_EQ(0, lastbit(uint16_t((UINT16_C(1) << i) - 1)));
    EXPECT_EQ(i, lastbit(uint16_t((UINT16_C(1) << i))));
    EXPECT_EQ(0, lastbit(uint16_t((UINT16_C(1) << i) + 1)));
    if (i < 14) {
      EXPECT_EQ(
          i, lastbit(uint16_t((UINT16_C(1) << i) | (UINT16_C(1) << (i + 2)))));
    }
  }
}
Exemple #13
0
/**
 * Sends a broadcast UDP packet.
 *
 * @returns VBox status code.
 * @param   pSession        The support driver session handle.
 * @param   hIf             The interface handle.
 * @param   pBuf            The interface buffer.
 * @param   SrcIPv4Addr     The source IPv4 address.
 * @param   pSrcMacAddr     The source MAC address.
 * @param   uSrcPort        The source port number.
 * @param   uDstPort        The destination port number.
 * @param   pvData          The data payload.
 * @param   cbData          The size of the data payload.
 */
int     VBoxNetUDPBroadcast(PSUPDRVSESSION pSession, INTNETIFHANDLE hIf, PINTNETBUF pBuf,
                            RTNETADDRIPV4 SrcIPv4Addr, PCRTMAC pSrcMacAddr, unsigned uSrcPort,
                            unsigned uDstPort,
                            void const *pvData, size_t cbData)
{
    RTNETADDRIPV4   IPv4AddrBrdCast;
    IPv4AddrBrdCast.u = UINT32_C(0xffffffff);
    RTMAC           MacBrdCast;
    MacBrdCast.au16[0] = MacBrdCast.au16[1] = MacBrdCast.au16[2] = UINT16_C(0xffff);

    return vboxnetudpSend(pSession, hIf, pBuf,
                          SrcIPv4Addr, pSrcMacAddr, uSrcPort,
                          IPv4AddrBrdCast, &MacBrdCast, uDstPort,
                          pvData, cbData);
}
Exemple #14
0
void __vector_timer7()
{
  // Disable the dmtimer interrupts.
  mcal::reg::access<std::uint32_t, std::uint32_t, mcal::reg::dmtimer7::irqenable_clr, UINT32_C(7)>::reg_set();

  // Clear the status of the interrupt flags.
  mcal::reg::access<std::uint32_t, std::uint32_t, mcal::reg::dmtimer7::irqstatus, UINT32_C(7)>::reg_set();

  // Increment the 64-bit system tick by 1000, representing 1000us.
  system_tick += UINT16_C(1000);

  // Signal the end of the interrupt.
  mcal::reg::access<std::uint32_t, std::uint32_t, mcal::reg::dmtimer7::irq_eoi, UINT32_C(1)>::reg_not();

  // Enable the dmtimer interrupts.
  mcal::reg::access<std::uint32_t, std::uint32_t, mcal::reg::dmtimer7::irqenable_set, UINT32_C(2)>::reg_set();
}
Exemple #15
0
/**
 * Implements VINF_IOM_MMIO_UNUSED_00.
 *
 * @returns VINF_SUCCESS.
 * @param   pvValue             Where to store the zeros.
 * @param   cbValue             How many bytes to read.
 */
static int iomMMIODoRead00s(void *pvValue, size_t cbValue)
{
    switch (cbValue)
    {
        case 1: *(uint8_t  *)pvValue = UINT8_C(0x00); break;
        case 2: *(uint16_t *)pvValue = UINT16_C(0x0000); break;
        case 4: *(uint32_t *)pvValue = UINT32_C(0x00000000); break;
        case 8: *(uint64_t *)pvValue = UINT64_C(0x0000000000000000); break;
        default:
        {
            uint8_t *pb = (uint8_t *)pvValue;
            while (cbValue--)
                *pb++ = UINT8_C(0x00);
            break;
        }
    }
    return VINF_SUCCESS;
}
static void test_w_out(ctest_ctx *ctx)
{
  const uint8_t SENTINEL = UINT8_C(0xFD);
  const uint8_t TAG_HI = UINT8_C(0xA5);
  const uint8_t TAG_LO = UINT8_C(0x5A);
  const uint16_t TAG = UINT16_C(0xA55A);
  const uint16_t w = TAG;
  uint8_t image[4];
  uint8_t *p = image+1;

  image[0] = SENTINEL;
  image[1] = SENTINEL;
  image[2] = SENTINEL;
  image[3] = SENTINEL;

  w_out(w,&p);

  CTEST(ctx,image[1]==TAG_LO);
  CTEST(ctx,image[2]==TAG_HI);
  CTEST(ctx,image[0]==SENTINEL);
  CTEST(ctx,image[3]==SENTINEL);
  CTEST(ctx,p==image+3);
}
Exemple #17
0
// Get the system type associated to a ROM country code.
static m64p_system_type rom_country_code_to_system_type(uint16_t country_code)
{
    switch (country_code & UINT16_C(0xFF))
    {
        // PAL codes
        case 0x44:
        case 0x46:
        case 0x49:
        case 0x50:
        case 0x53:
        case 0x55:
        case 0x58:
        case 0x59:
            return SYSTEM_PAL;

        // NTSC codes
        case 0x37:
        case 0x41:
        case 0x45:
        case 0x4a:
        default: // Fallback for unknown codes
            return SYSTEM_NTSC;
    }
}
EXTERN_C
void rpTask2_Func()
{
//  Cdd_MuxNXP74H_Set_Multiplex(ARDUINO_MUX_SWITCH_1);

//  Cdd_MuxNXP74H_Set_Multiplex(ARDUINO_MUX_SWITCH_2);

  Cdd_MuxNXP74H_Set_Multiplex(ARDUINO_MUX_SWITCH_3);

//  Cdd_MuxNXP74H_Set_Multiplex(ARDUINO_MUX_SWITCH_4);
  Dio_WriteChannel(ARDUINO_PORT_RX_LED, (Dio_ReadChannel(ARDUINO_MUX_SIGNAL) == STD_HIGH) ? STD_HIGH : STD_LOW);

  (upcounting_rgb_g ? duty_rgb_g += 4U : duty_rgb_g -= 4U);

  Pwm_SetDutyCycle(ARDUINO_RGB_G, duty_rgb_g);

  if((duty_rgb_g >= UINT16_C(0x7FF0)) || (duty_rgb_g <= UINT16_C(0x0010)))
  {
    upcounting_rgb_g = !upcounting_rgb_g;
  }

  (upcounting_rgb_b ? duty_rgb_b += 8U : duty_rgb_b -= 8U);

  Pwm_SetDutyCycle(ARDUINO_RGB_B, duty_rgb_b);

  if((duty_rgb_b >= UINT16_C(0x7FF0)) || (duty_rgb_b <= UINT16_C(0x0010)))
  {
    upcounting_rgb_b = !upcounting_rgb_b;
  }

  (upcounting_rgb_r ? duty_rgb_r += 16U : duty_rgb_r -= 16U);

  Pwm_SetDutyCycle(ARDUINO_RGB_R, duty_rgb_r);

  if((duty_rgb_r >= UINT16_C(0x7FF0)) || (duty_rgb_r <= UINT16_C(0x0010)))
  {
    upcounting_rgb_r = !upcounting_rgb_r;
  }
}
 std::uint16_t read_value(const unsigned) { return UINT16_C(0); }
//  Copyright 2014 Stephan Hage.
//  Copyright 2014 Christopher Kormanyos.
//  Distributed under the Boost 
//  Software License, Version 1.0. 
//  (See accompanying file LICENSE_1_0.txt 
//  or copy at http://www.boost.org/LICENSE_1_0.txt ) 
//

#include <Bsw/Common/Std_Types.h>
#include <Bsw/Mcal/Pwm/Pwm.h>

#include <Hal/Cdd/Multiplex/NXP_74HC4067/Cdd_MuxNXP74HC4067.h>
#include <Bsw/Mcal/Dio/Dio.h>

// Runnables
uint16 duty_rgb_g = UINT16_C(0x4000);
uint16 duty_rgb_b = UINT16_C(0x4000);
uint16 duty_rgb_r = UINT16_C(0x4000);

bool upcounting_rgb_g = true;
bool upcounting_rgb_b = true;
bool upcounting_rgb_r = true;

EXTERN_C
void rpTask2_Init()
{
  Pwm_SetPeriodAndDuty(ARDUINO_RGB_G, UINT16_C(500), UINT16_C(0x4000));
  Pwm_SetPeriodAndDuty(ARDUINO_RGB_B, UINT16_C(500), UINT16_C(0x4000));
  Pwm_SetPeriodAndDuty(ARDUINO_RGB_R, UINT16_C(500), UINT16_C(0x4000));
}
static void setupStruct(struct capn *ctx) {
  struct capn_ptr root = capn_root(ctx);
  ASSERT_EQ(CAPN_PTR_LIST, root.type);
  ASSERT_EQ(1, root.len);

  struct capn_ptr ptr = capn_new_struct(root.seg, 16, 6);
  ASSERT_EQ(CAPN_STRUCT, ptr.type);
  EXPECT_EQ(16, ptr.datasz);
  EXPECT_EQ(6, ptr.ptrs);
  EXPECT_EQ(0, capn_setp(root, 0, ptr));

  EXPECT_EQ(0, capn_write64(ptr, 0, UINT64_C(0x1011121314151617)));
  EXPECT_EQ(0, capn_write32(ptr, 8, UINT32_C(0x20212223)));
  EXPECT_EQ(0, capn_write16(ptr, 12, UINT16_C(0x3031)));
  EXPECT_EQ(0, capn_write8(ptr, 14, 0x40));
  EXPECT_EQ(0, capn_write8(ptr, 15, (1 << 6) | (1 << 5) | (1 << 4) | (1 << 2)));

  capn_ptr subStruct = capn_new_struct(ptr.seg, 8, 0);
  ASSERT_EQ(CAPN_STRUCT, subStruct.type);
  EXPECT_EQ(8, subStruct.datasz);
  EXPECT_EQ(0, subStruct.ptrs);
  EXPECT_EQ(0, capn_write32(subStruct, 0, 123));
  EXPECT_NE(0, capn_write32(subStruct, 8, 124));
  EXPECT_EQ(0, capn_setp(ptr, 0, subStruct));

  capn_list32 list32 = capn_new_list32(ptr.seg, 3);
  capn_list64 list64 = {list32.p};
  ASSERT_EQ(CAPN_LIST, list32.p.type);
  EXPECT_EQ(3, list32.p.len);
  EXPECT_EQ(4, list32.p.datasz);
  EXPECT_EQ(0, capn_set32(list32, 0, 200));
  EXPECT_EQ(0, capn_set32(list32, 1, 201));
  EXPECT_EQ(0, capn_set32(list32, 2, 202));
  EXPECT_NE(0, capn_set32(list32, 3, 203));
  EXPECT_NE(0, capn_set64(list64, 0, 405));
  EXPECT_EQ(0, capn_setp(ptr, 1, list32.p));

  capn_ptr list = capn_new_list(ptr.seg, 4, 4, 1);
  ASSERT_EQ(CAPN_LIST, list.type);
  ASSERT_EQ(1, list.is_composite_list);
  EXPECT_EQ(4, list.len);
  EXPECT_EQ(8, list.datasz);
  EXPECT_EQ(1, list.ptrs);
  EXPECT_EQ(0, capn_setp(ptr, 2, list));
  for (int i = 0; i < 4; i++) {
    capn_ptr element = capn_getp(list, i, 1);
    ASSERT_EQ(CAPN_STRUCT, element.type);
    EXPECT_EQ(1, element.is_list_member);
    EXPECT_EQ(8, element.datasz);
    EXPECT_EQ(1, element.ptrs);
    EXPECT_EQ(0, capn_write32(element, 0, 300+i));

    capn_ptr subelement = capn_new_struct(element.seg, 8, 0);
    ASSERT_EQ(CAPN_STRUCT, subelement.type);
    EXPECT_EQ(8, subelement.datasz);
    EXPECT_EQ(0, subelement.ptrs);
    EXPECT_EQ(0, capn_write32(subelement, 0, 400+i));
    EXPECT_EQ(0, capn_setp(element, 0, subelement));
  }

  list = capn_new_ptr_list(ptr.seg, 5);
  ASSERT_EQ(CAPN_PTR_LIST, list.type);
  EXPECT_EQ(5, list.len);
  EXPECT_EQ(0, capn_setp(ptr, 3, list));
  for (int i = 0; i < 5; i++) {
    capn_list16 element = capn_new_list16(list.seg, i+1);
    ASSERT_EQ(CAPN_LIST, element.p.type);
    EXPECT_EQ(i+1, element.p.len);
    EXPECT_EQ(2, element.p.datasz);
    EXPECT_EQ(0, element.p.ptrs);
    EXPECT_EQ(0, capn_setp(list, i, element.p));
    for (int j = 0; j <= i; j++) {
      EXPECT_EQ(0, capn_set16(element, j, 500+j));
    }
  }

  capn_ptr recurse = capn_new_struct(ptr.seg, 0, 2);
  EXPECT_EQ(CAPN_STRUCT, recurse.type);
  EXPECT_EQ(0, recurse.datasz);
  EXPECT_EQ(2, recurse.ptrs);
  EXPECT_EQ(0, capn_setp(recurse, 0, recurse));
  EXPECT_EQ(0, capn_setp(ptr, 4, recurse));

}
Exemple #22
0
RTDECL(ssize_t) RTStrFormatR80u2(char *pszBuf, size_t cbBuf, PCRTFLOAT80U2 pr80Value, signed int cchWidth,
                                 signed int cchPrecision, uint32_t fFlags)
{
    NOREF(cchWidth);
    NOREF(cchPrecision);
    NOREF(fFlags);
    char szTmp[160];

    char *pszTmp = szTmp;
    if (pr80Value->s.fSign)
        *pszTmp++ = '-';
    else
        *pszTmp++ = '+';

    if (pr80Value->s.uExponent == 0)
    {
        if (   !pr80Value->sj64.u63Fraction
                && pr80Value->sj64.fInteger)
            *pszTmp++ = '0';
        /* else: Denormal, handled way below. */
    }
    else if (pr80Value->sj64.uExponent == UINT16_C(0x7fff))
    {
        /** @todo Figure out Pseudo inf/nan... */
        if (pr80Value->sj64.fInteger)
            *pszTmp++ = 'P';
        if (pr80Value->sj64.u63Fraction == 0)
        {
            *pszTmp++ = 'I';
            *pszTmp++ = 'n';
            *pszTmp++ = 'f';
        }
        else
        {
            *pszTmp++ = 'N';
            *pszTmp++ = 'a';
            *pszTmp++ = 'N';
        }
    }
    if (pszTmp != &szTmp[1])
        *pszTmp = '\0';
    else
    {
        *pszTmp++ = pr80Value->sj64.fInteger ? '1' : '0';
        *pszTmp++ = 'm';
        pszTmp += RTStrFormatNumber(pszTmp, pr80Value->sj64.u63Fraction, 16, 2+16, 0,
                                    RTSTR_F_SPECIAL | RTSTR_F_ZEROPAD | RTSTR_F_64BIT);

        *pszTmp++ = 'e';
        pszTmp += RTStrFormatNumber(pszTmp, (int32_t)pr80Value->sj64.uExponent - 16383, 10, 0, 0,
                                    RTSTR_F_ZEROPAD | RTSTR_F_32BIT | RTSTR_F_VALSIGNED);
    }

    /*
     * Copy out the result.
     */
    ssize_t cchRet = pszTmp - &szTmp[0];
    if ((size_t)cchRet <= cbBuf)
        memcpy(pszBuf, szTmp, cchRet + 1);
    else
    {
        if (cbBuf)
        {
            memcpy(pszBuf, szTmp, cbBuf - 1);
            pszBuf[cbBuf - 1] = '\0';
        }
        cchRet = VERR_BUFFER_OVERFLOW;
    }
    return cchRet;
}
Exemple #23
0
verify_same_types (INT32_MIN, (int32_t) 0 + 0);
verify_same_types (INT32_MAX, (int32_t) 0 + 0);

#ifdef INT64_MAX
int64_t a4[3] = { INT64_C (17), INT64_MIN, INT64_MAX };
verify (TYPE_MINIMUM (int64_t) == INT64_MIN);
verify (TYPE_MAXIMUM (int64_t) == INT64_MAX);
verify_same_types (INT64_MIN, (int64_t) 0 + 0);
verify_same_types (INT64_MAX, (int64_t) 0 + 0);
#endif

uint8_t b1[2] = { UINT8_C (17), UINT8_MAX };
verify (TYPE_MAXIMUM (uint8_t) == UINT8_MAX);
verify_same_types (UINT8_MAX, (uint8_t) 0 + 0);

uint16_t b2[2] = { UINT16_C (17), UINT16_MAX };
verify (TYPE_MAXIMUM (uint16_t) == UINT16_MAX);
verify_same_types (UINT16_MAX, (uint16_t) 0 + 0);

uint32_t b3[2] = { UINT32_C (17), UINT32_MAX };
verify (TYPE_MAXIMUM (uint32_t) == UINT32_MAX);
verify_same_types (UINT32_MAX, (uint32_t) 0 + 0);

#ifdef UINT64_MAX
uint64_t b4[2] = { UINT64_C (17), UINT64_MAX };
verify (TYPE_MAXIMUM (uint64_t) == UINT64_MAX);
verify_same_types (UINT64_MAX, (uint64_t) 0 + 0);
#endif

#if INT8_MIN && INT8_MAX && INT16_MIN && INT16_MAX && INT32_MIN && INT32_MAX
/* ok */
Exemple #24
0
/**
 * @interface_method_impl{DBGCCMDHLP,pfnMemWrite}
 */
static DECLCALLBACK(int) dbgcHlpMemWrite(PDBGCCMDHLP pCmdHlp, const void *pvBuffer, size_t cbWrite, PCDBGCVAR pVarPointer, size_t *pcbWritten)
{
    PDBGC       pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
    DBGFADDRESS Address;
    int         rc;

    /*
     * Dummy check.
     */
    if (cbWrite == 0)
    {
        if (*pcbWritten)
            *pcbWritten = 0;
        return VINF_SUCCESS;
    }

    /*
     * Convert Far addresses getting size and the correct base address.
     * Getting and checking the size is what makes this messy and slow.
     */
    DBGCVAR Var = *pVarPointer;
    switch (pVarPointer->enmType)
    {
        case DBGCVAR_TYPE_GC_FAR:
        {
            /* Use DBGFR3AddrFromSelOff for the conversion. */
            Assert(pDbgc->pUVM);
            rc = DBGFR3AddrFromSelOff(pDbgc->pUVM, pDbgc->idCpu, &Address, Var.u.GCFar.sel, Var.u.GCFar.off);
            if (RT_FAILURE(rc))
                return rc;

            /* don't bother with flat selectors (for now). */
            if (!DBGFADDRESS_IS_FLAT(&Address))
            {
                DBGFSELINFO SelInfo;
                rc = DBGFR3SelQueryInfo(pDbgc->pUVM, pDbgc->idCpu, Address.Sel,
                                        DBGFSELQI_FLAGS_DT_GUEST | DBGFSELQI_FLAGS_DT_ADJ_64BIT_MODE, &SelInfo);
                if (RT_SUCCESS(rc))
                {
                    RTGCUINTPTR cb; /* -1 byte */
                    if (DBGFSelInfoIsExpandDown(&SelInfo))
                    {
                        if (    !SelInfo.u.Raw.Gen.u1Granularity
                            &&  Address.off > UINT16_C(0xffff))
                            return VERR_OUT_OF_SELECTOR_BOUNDS;
                        if (Address.off <= SelInfo.cbLimit)
                            return VERR_OUT_OF_SELECTOR_BOUNDS;
                        cb = (SelInfo.u.Raw.Gen.u1Granularity ? UINT32_C(0xffffffff) : UINT32_C(0xffff)) - Address.off;
                    }
                    else
                    {
                        if (Address.off > SelInfo.cbLimit)
                            return VERR_OUT_OF_SELECTOR_BOUNDS;
                        cb = SelInfo.cbLimit - Address.off;
                    }
                    if (cbWrite - 1 > cb)
                    {
                        if (!pcbWritten)
                            return VERR_OUT_OF_SELECTOR_BOUNDS;
                        cbWrite = cb + 1;
                    }
                }
            }
            Var.enmType = DBGCVAR_TYPE_GC_FLAT;
            Var.u.GCFlat = Address.FlatPtr;
        }
        /* fall thru */
        case DBGCVAR_TYPE_GC_FLAT:
            rc = DBGFR3MemWrite(pDbgc->pUVM, pDbgc->idCpu,
                                DBGFR3AddrFromFlat(pDbgc->pUVM, &Address, Var.u.GCFlat),
                                pvBuffer, cbWrite);
            if (pcbWritten && RT_SUCCESS(rc))
                *pcbWritten = cbWrite;
            return rc;

        case DBGCVAR_TYPE_GC_PHYS:
            rc = DBGFR3MemWrite(pDbgc->pUVM, pDbgc->idCpu,
                                DBGFR3AddrFromPhys(pDbgc->pUVM, &Address, Var.u.GCPhys),
                                pvBuffer, cbWrite);
            if (pcbWritten && RT_SUCCESS(rc))
                *pcbWritten = cbWrite;
            return rc;

        case DBGCVAR_TYPE_HC_FLAT:
        case DBGCVAR_TYPE_HC_PHYS:
        {
            /*
             * Copy HC memory page by page.
             */
            if (pcbWritten)
                *pcbWritten = 0;
            while (cbWrite > 0)
            {
                /* convert to flat address */
                DBGCVAR Var2;
                rc = dbgcOpAddrFlat(pDbgc, &Var, DBGCVAR_CAT_ANY, &Var2);
                if (RT_FAILURE(rc))
                {
                    if (pcbWritten && *pcbWritten)
                        return -VERR_INVALID_POINTER;
                    return VERR_INVALID_POINTER;
                }

                /* calc size. */
                size_t cbChunk = PAGE_SIZE;
                cbChunk -= (uintptr_t)Var.u.pvHCFlat & PAGE_OFFSET_MASK;
                if (cbChunk > cbWrite)
                    cbChunk = cbWrite;

                /** @todo protect this!!! */
                memcpy(Var2.u.pvHCFlat, pvBuffer, cbChunk);

                /* advance */
                if (Var.enmType == DBGCVAR_TYPE_HC_FLAT)
                    Var.u.pvHCFlat = (uint8_t *)Var.u.pvHCFlat + cbChunk;
                else
                    Var.u.HCPhys += cbChunk;
                pvBuffer = (uint8_t const *)pvBuffer + cbChunk;
                if (pcbWritten)
                    *pcbWritten += cbChunk;
                cbWrite -= cbChunk;
            }

            return VINF_SUCCESS;
        }

        default:
            return VERR_NOT_IMPLEMENTED;
    }
}
Exemple #25
0
/**
 * @interface_method_impl{DBGCCMDHLP,pfnMemRead}
 */
static DECLCALLBACK(int) dbgcHlpMemRead(PDBGCCMDHLP pCmdHlp, void *pvBuffer, size_t cbRead, PCDBGCVAR pVarPointer, size_t *pcbRead)
{
    PDBGC       pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
    DBGFADDRESS Address;
    int         rc;

    /*
     * Dummy check.
     */
    if (cbRead == 0)
    {
        if (*pcbRead)
            *pcbRead = 0;
        return VINF_SUCCESS;
    }

    /*
     * Convert Far addresses getting size and the correct base address.
     * Getting and checking the size is what makes this messy and slow.
     */
    DBGCVAR Var = *pVarPointer;
    switch (pVarPointer->enmType)
    {
        case DBGCVAR_TYPE_GC_FAR:
            /* Use DBGFR3AddrFromSelOff for the conversion. */
            Assert(pDbgc->pUVM);
            rc = DBGFR3AddrFromSelOff(pDbgc->pUVM, pDbgc->idCpu, &Address, Var.u.GCFar.sel, Var.u.GCFar.off);
            if (RT_FAILURE(rc))
                return rc;

            /* don't bother with flat selectors (for now). */
            if (!DBGFADDRESS_IS_FLAT(&Address))
            {
                DBGFSELINFO SelInfo;
                rc = DBGFR3SelQueryInfo(pDbgc->pUVM, pDbgc->idCpu, Address.Sel,
                                        DBGFSELQI_FLAGS_DT_GUEST | DBGFSELQI_FLAGS_DT_ADJ_64BIT_MODE, &SelInfo);
                if (RT_SUCCESS(rc))
                {
                    RTGCUINTPTR cb; /* -1 byte */
                    if (DBGFSelInfoIsExpandDown(&SelInfo))
                    {
                        if (    !SelInfo.u.Raw.Gen.u1Granularity
                            &&  Address.off > UINT16_C(0xffff))
                            return VERR_OUT_OF_SELECTOR_BOUNDS;
                        if (Address.off <= SelInfo.cbLimit)
                            return VERR_OUT_OF_SELECTOR_BOUNDS;
                        cb = (SelInfo.u.Raw.Gen.u1Granularity ? UINT32_C(0xffffffff) : UINT32_C(0xffff)) - Address.off;
                    }
                    else
                    {
                        if (Address.off > SelInfo.cbLimit)
                            return VERR_OUT_OF_SELECTOR_BOUNDS;
                        cb = SelInfo.cbLimit - Address.off;
                    }
                    if (cbRead - 1 > cb)
                    {
                        if (!pcbRead)
                            return VERR_OUT_OF_SELECTOR_BOUNDS;
                        cbRead = cb + 1;
                    }
                }
            }
            Var.enmType = DBGCVAR_TYPE_GC_FLAT;
            Var.u.GCFlat = Address.FlatPtr;
            break;

        case DBGCVAR_TYPE_GC_FLAT:
        case DBGCVAR_TYPE_GC_PHYS:
        case DBGCVAR_TYPE_HC_FLAT:
        case DBGCVAR_TYPE_HC_PHYS:
            break;

        default:
            return VERR_NOT_IMPLEMENTED;
    }



    /*
     * Copy page by page.
     */
    size_t cbLeft = cbRead;
    for (;;)
    {
        /*
         * Calc read size.
         */
        size_t cb = RT_MIN(PAGE_SIZE, cbLeft);
        switch (pVarPointer->enmType)
        {
            case DBGCVAR_TYPE_GC_FLAT: cb = RT_MIN(cb, PAGE_SIZE - (Var.u.GCFlat & PAGE_OFFSET_MASK)); break;
            case DBGCVAR_TYPE_GC_PHYS: cb = RT_MIN(cb, PAGE_SIZE - (Var.u.GCPhys & PAGE_OFFSET_MASK)); break;
            case DBGCVAR_TYPE_HC_FLAT: cb = RT_MIN(cb, PAGE_SIZE - ((uintptr_t)Var.u.pvHCFlat & PAGE_OFFSET_MASK)); break;
            case DBGCVAR_TYPE_HC_PHYS: cb = RT_MIN(cb, PAGE_SIZE - ((size_t)Var.u.HCPhys & PAGE_OFFSET_MASK)); break; /* size_t: MSC has braindead loss of data warnings! */
            default: break;
        }

        /*
         * Perform read.
         */
        switch (Var.enmType)
        {
            case DBGCVAR_TYPE_GC_FLAT:
                rc = DBGFR3MemRead(pDbgc->pUVM, pDbgc->idCpu,
                                   DBGFR3AddrFromFlat(pDbgc->pUVM, &Address, Var.u.GCFlat),
                                   pvBuffer, cb);
                break;

            case DBGCVAR_TYPE_GC_PHYS:
                rc = DBGFR3MemRead(pDbgc->pUVM, pDbgc->idCpu,
                                   DBGFR3AddrFromPhys(pDbgc->pUVM, &Address, Var.u.GCPhys),
                                   pvBuffer, cb);
                break;

            case DBGCVAR_TYPE_HC_PHYS:
            case DBGCVAR_TYPE_HC_FLAT:
            {
                DBGCVAR Var2;
                rc = dbgcOpAddrFlat(pDbgc, &Var, DBGCVAR_CAT_ANY, &Var2);
                if (RT_SUCCESS(rc))
                {
                    /** @todo protect this!!! */
                    memcpy(pvBuffer, Var2.u.pvHCFlat, cb);
                    rc = 0;
                }
                else
                    rc = VERR_INVALID_POINTER;
                break;
            }

            default:
                rc = VERR_DBGC_PARSE_INCORRECT_ARG_TYPE;
        }

        /*
         * Check for failure.
         */
        if (RT_FAILURE(rc))
        {
            if (pcbRead && (*pcbRead = cbRead - cbLeft) > 0)
                return VINF_SUCCESS;
            return rc;
        }

        /*
         * Next.
         */
        cbLeft -= cb;
        if (!cbLeft)
            break;
        pvBuffer = (char *)pvBuffer + cb;
        rc = DBGCCmdHlpEval(pCmdHlp, &Var, "%DV + %d", &Var, cb);
        if (RT_FAILURE(rc))
        {
            if (pcbRead && (*pcbRead = cbRead - cbLeft) > 0)
                return VINF_SUCCESS;
            return rc;
        }
    }

    /*
     * Done
     */
    if (pcbRead)
        *pcbRead = cbRead;
    return 0;
}
Exemple #26
0
int main()
{
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
  integral_constant_checker::check();
#endif
  //
  // verify the types of the integral constants:
  //
  integral_constant_type_check(boost::int8_t(0), INT8_C(0));
  integral_constant_type_check(boost::uint8_t(0), UINT8_C(0));
  integral_constant_type_check(boost::int16_t(0), INT16_C(0));
  integral_constant_type_check(boost::uint16_t(0), UINT16_C(0));
  integral_constant_type_check(boost::int32_t(0), INT32_C(0));
  integral_constant_type_check(boost::uint32_t(0), UINT32_C(0));
#ifndef BOOST_NO_INT64_T
  integral_constant_type_check(boost::int64_t(0), INT64_C(0));
  integral_constant_type_check(boost::uint64_t(0), UINT64_C(0));
#endif
  //
  boost::int8_t          int8          = INT8_C(-127);
  boost::int_least8_t    int_least8    = INT8_C(-127);
  boost::int_fast8_t     int_fast8     = INT8_C(-127);

  boost::uint8_t         uint8         = UINT8_C(255);
  boost::uint_least8_t   uint_least8   = UINT8_C(255);
  boost::uint_fast8_t    uint_fast8    = UINT8_C(255);

  boost::int16_t         int16         = INT16_C(-32767);
  boost::int_least16_t   int_least16   = INT16_C(-32767);
  boost::int_fast16_t    int_fast16    = INT16_C(-32767);

  boost::uint16_t        uint16         = UINT16_C(65535);
  boost::uint_least16_t  uint_least16   = UINT16_C(65535);
  boost::uint_fast16_t   uint_fast16    = UINT16_C(65535);

  boost::int32_t         int32         = INT32_C(-2147483647);
  boost::int_least32_t   int_least32   = INT32_C(-2147483647);
  boost::int_fast32_t    int_fast32    = INT32_C(-2147483647);

  boost::uint32_t        uint32        = UINT32_C(4294967295);
  boost::uint_least32_t  uint_least32  = UINT32_C(4294967295);
  boost::uint_fast32_t   uint_fast32   = UINT32_C(4294967295);

#ifndef BOOST_NO_INT64_T
  boost::int64_t         int64         = INT64_C(-9223372036854775807);
  boost::int_least64_t   int_least64   = INT64_C(-9223372036854775807);
  boost::int_fast64_t    int_fast64    = INT64_C(-9223372036854775807);

  boost::uint64_t        uint64        = UINT64_C(18446744073709551615);
  boost::uint_least64_t  uint_least64  = UINT64_C(18446744073709551615);
  boost::uint_fast64_t   uint_fast64   = UINT64_C(18446744073709551615);

  boost::intmax_t        intmax        = INTMAX_C(-9223372036854775807);
  boost::uintmax_t       uintmax       = UINTMAX_C(18446744073709551615);
#else
  boost::intmax_t        intmax        = INTMAX_C(-2147483647);
  boost::uintmax_t       uintmax       = UINTMAX_C(4294967295);
#endif

  assert( int8 == -127 );
  assert( int_least8 == -127 );
  assert( int_fast8 == -127 );
  assert( uint8 == 255u );
  assert( uint_least8 == 255u );
  assert( uint_fast8 == 255u );
  assert( int16 == -32767 );
  assert( int_least16 == -32767 );
  assert( int_fast16 == -32767 );
  assert( uint16 == 65535u );
  assert( uint_least16 == 65535u );
  assert( uint_fast16 == 65535u );
  assert( int32 == -2147483647 );
  assert( int_least32 == -2147483647 );
  assert( int_fast32 == -2147483647 );
  assert( uint32 == 4294967295u );
  assert( uint_least32 == 4294967295u );
  assert( uint_fast32 == 4294967295u );

#ifndef BOOST_NO_INT64_T
  assert( int64 == INT64_C(-9223372036854775807) );
  assert( int_least64 == INT64_C(-9223372036854775807) );
  assert( int_fast64 == INT64_C(-9223372036854775807) );
  assert( uint64 == UINT64_C(18446744073709551615) );
  assert( uint_least64 == UINT64_C(18446744073709551615) );
  assert( uint_fast64 == UINT64_C(18446744073709551615) );
  assert( intmax == INT64_C(-9223372036854775807) );
  assert( uintmax == UINT64_C(18446744073709551615) );
#else
  assert( intmax == -2147483647 );
  assert( uintmax == 4294967295u );
#endif


  std::cout << "OK\n";
  return 0;
}
int main()
{
   boost::int8_t i8 = INT8_C(0);
   (void)i8;
   boost::uint8_t ui8 = UINT8_C(0);
   (void)ui8;
   boost::int16_t i16 = INT16_C(0);
   (void)i16;
   boost::uint16_t ui16 = UINT16_C(0);
   (void)ui16;
   boost::int32_t i32 = INT32_C(0);
   (void)i32;
   boost::uint32_t ui32 = UINT32_C(0);
   (void)ui32;
#ifndef BOOST_NO_INT64_T
   boost::int64_t i64 = 0;
   (void)i64;
   boost::uint64_t ui64 = 0;
   (void)ui64;
#endif
   boost::int_least8_t i8least = INT8_C(0);
   (void)i8least;
   boost::uint_least8_t ui8least = UINT8_C(0);
   (void)ui8least;
   boost::int_least16_t i16least = INT16_C(0);
   (void)i16least;
   boost::uint_least16_t ui16least = UINT16_C(0);
   (void)ui16least;
   boost::int_least32_t i32least = INT32_C(0);
   (void)i32least;
   boost::uint_least32_t ui32least = UINT32_C(0);
   (void)ui32least;
#ifndef BOOST_NO_INT64_T
   boost::int_least64_t i64least = 0;
   (void)i64least;
   boost::uint_least64_t ui64least = 0;
   (void)ui64least;
#endif
   boost::int_fast8_t i8fast = INT8_C(0);
   (void)i8fast;
   boost::uint_fast8_t ui8fast = UINT8_C(0);
   (void)ui8fast;
   boost::int_fast16_t i16fast = INT16_C(0);
   (void)i16fast;
   boost::uint_fast16_t ui16fast = UINT16_C(0);
   (void)ui16fast;
   boost::int_fast32_t i32fast = INT32_C(0);
   (void)i32fast;
   boost::uint_fast32_t ui32fast = UINT32_C(0);
   (void)ui32fast;
#ifndef BOOST_NO_INT64_T
   boost::int_fast64_t i64fast = 0;
   (void)i64fast;
   boost::uint_fast64_t ui64fast = 0;
   (void)ui64fast;
#endif
   boost::intmax_t im = 0;
   (void)im;
   boost::uintmax_t uim = 0;
   (void)uim;
}
Exemple #28
0
C(UINTMAX_MAX)
C(PTRDIFF_MIN)
C(PTRDIFF_MAX)
C(SIG_ATOMIC_MIN)
C(SIG_ATOMIC_MAX)
C(SIZE_MAX)
C(WCHAR_MIN)
C(WCHAR_MAX)
C(WINT_MIN)
C(WINT_MAX)
C(INT8_C(0))
C(INT16_C(0))
C(INT32_C(0))
C(INT64_C(0))
C(UINT8_C(0))
C(UINT16_C(0))
C(UINT32_C(0))
C(UINT64_C(0))
C(INTMAX_C(0))
C(UINTMAX_C(0))
S(PRId8)
S(PRId16)
S(PRId32)
S(PRId64)
S(PRIdLEAST8)
S(PRIdLEAST16)
S(PRIdLEAST32)
S(PRIdLEAST64)
S(PRIdFAST8)
S(PRIdFAST16)
S(PRIdFAST32)
Exemple #29
0
void app::crc::task_func()
{
  // Calculate and verify the 8-bit, 16-bit,
  // 32-bit and 64-bit CRC.

  typedef enum app_crc_calculation_state
  {
    app_crc_calculation_state_initialize,
    app_crc_calculation_state_process_bytes,
    app_crc_calculation_state_finalize
  }
  app_crc_calculation_state_type;

  static app_crc_calculation_state_type app_crc_calculation_state =
    app_crc_calculation_state_initialize;

  static std::uint_fast8_t app_crc_process_data_byte_count;

  static std::uint_fast8_t app_crc_object_index;

  // On 8-bit target, take runtime statistics for the
  // state machine (averaged over all 8,16,32,64-bit CRCs,
  // all bytes and all states).
  //   * average 10.3us
  //   * low      3.4us
  //   * high    22  us.

  // Average load for CRC calculation only is:
  //   * 10.3us / 1ms = approx. 1%.
  //   * 36ms (total) needed to cycle through all 4 CRCs.

  // Disable all interrupts before each calculation
  // in order to provide for a clean time measurement.
  mcal::irq::disable_all();

  // Use a port pin to provide a real-time measurement.
  app_crc_measurement_port_type::set_pin_high();

  // Distribute the CRC calculations
  // over multitasking time slices.
  // Process one single byte at a time,

  switch(app_crc_calculation_state)
  {
    case app_crc_calculation_state_initialize:

      // Initialize the CRC object.
      app_crc_checksums[app_crc_object_index]->initialize();

      app_crc_calculation_state = app_crc_calculation_state_process_bytes;

      break;

      case app_crc_calculation_state_process_bytes:

      {
        // Process the next byte.
        const std::uint8_t next_byte =
          *(app_crc_test_values.data() + app_crc_process_data_byte_count);

        app_crc_checksums[app_crc_object_index]->process_bytes(&next_byte, 1U);
      }

      ++app_crc_process_data_byte_count;

      if(app_crc_process_data_byte_count >= app_crc_test_values.size())
      {
        // If all bytes for this CRC have been processed,
        // then reset the byte count to 0 and move to the
        // finalize state for this CRC calculation.
        app_crc_process_data_byte_count = 0U;

        // We are now ready to move to CRC state finalize
        // for this CRC object.
        app_crc_calculation_state = app_crc_calculation_state_finalize;
      }

      break;

    default:
    case app_crc_calculation_state_finalize:

      // Finalize this CRC object.
      app_crc_checksums[app_crc_object_index]->finalize();

      // Increment to othe next CRC object in the list.
      ++app_crc_object_index;

      if(app_crc_object_index >= app_crc_checksums.size())
      {
        // If we have reached the end of the CRC object list,
        // Then reset to the beginning of the list.
        app_crc_object_index = 0U;

        // Verify all CRC results.
        app_crc_results_are_ok =
          (    (app_crc_checksums[0U]->get_result<std::uint8_t> () == UINT8_C (0xDF))
            && (app_crc_checksums[1U]->get_result<std::uint16_t>() == UINT16_C(0x29B1))
            && (app_crc_checksums[2U]->get_result<std::uint32_t>() == UINT32_C(0x1697D06A))
            && (app_crc_checksums[3U]->get_result<std::uint64_t>() == UINT64_C(0x995DC9BBDF1939FA)));
      }

      // Return to CRC state initialization.
      app_crc_calculation_state = app_crc_calculation_state_initialize;

      break;
  }

  app_crc_measurement_port_type::set_pin_low();

  // Remember to enable all interrupts after the calculation.
  mcal::irq::enable_all();

  if(app_crc_results_are_ok == false)
  {
    // The CRC results are not OK.

    for(;;)
    {
      // Crash the system and toggle a port
      // to provide an indication of failure.

      app_crc_measurement_port_type::toggle_pin();

      mcal::cpu::nop();
    }
  }
}
Exemple #30
0
void __tmr0_ovi_irq()
{
  // Increment the software system tick.
  system_tick += UINT16_C(0x100);
}