void testStaticAssert (void) { /* sdcc always supports _Static_assert, even though the earliest standard requiring it is C11. */ #if defined (__SDCC) || __STDC_VERSION__ >= 201112L _Static_assert (1, "First assertion"); _Static_assert (sizeof(int), "Second assertion"); #endif }
static int get_address_family (int fd) { struct sockaddr_storage sa; socklen_t sa_len = sizeof (sa); if (__getsockname (fd, (struct sockaddr *) &sa, &sa_len) < 0) return -1; /* Check that the socket family number is preserved despite in-band signaling. */ _Static_assert (sizeof (sa.ss_family) < sizeof (int), "address family size"); _Static_assert (0 < (__typeof__ (sa.ss_family)) -1, "address family unsigned"); return sa.ss_family; }
main() { char x = *(char *)(long)"hi"; printf("endian: %d\n", (*(unsigned short *)"\xff\x00" < 0x100)); _Static_assert( __builtin_constant_p(*(char *)(long)"hi"), "word casts should be constant"); _Static_assert( !__builtin_constant_p(*(unsigned short *)"\xff\x00"), "endian dependent cast/deref result"); }
static FORCE_INLINE int64_t voids_to_int64_t(const struct worker_params *x) { union dummy_union y; _Static_assert(sizeof(struct worker_params) >= sizeof(int64_t),"wrong sizes"); y.p = *x; return y.i64; }
void constructor(void) { _Static_assert(sizeof(BrickContext) <= BRICKLET_CONTEXT_MAX_SIZE, "BrickContext too big"); PIN_OVER_CURRENT.type = PIO_INPUT; PIN_OVER_CURRENT.attribute = PIO_PULLUP; BA->PIO_Configure(&PIN_OVER_CURRENT, 1); BC->over_current = false; BC->current_avg = 0; adc_channel_enable(BS->adc_channel); uint16_t data; BA->bricklet_select(BS->port - 'a'); BA->i2c_eeprom_master_read(BA->twid->pTwi, EEPROM_POSITION, (char *)&data, 2); BA->bricklet_deselect(BS->port - 'a'); if(data == 0xFFFF) { BC->offset = 0; } else { BC->offset = data; } simple_constructor(); }
void bootblock_mainboard_early_init(void) { /* Let gpio2ab io domains works at 1.8V. * * If io_vsel[0] == 0(default value), gpio2ab io domains is 3.0V * powerd by APIO2_VDD, otherwise, 1.8V supplied by APIO2_VDDPST. * But from the schematic of kevin rev0, the APIO2_VDD and * APIO2_VDDPST both are 1.8V(intentionally?). * * So, by default, CPU1_SDIO_PWREN(GPIO2_A2) can't output 3.0V * because the supply is 1.8V. * Let ask GPIO2_A2 output 1.8V to make GPIO interal logic happy. */ write32(&rk3399_grf->io_vsel, RK_SETBITS(1 << 0)); /* * Let's enable these power rails here, we are already running the SPI * Flash based code. */ gpio_output(GPIO(0, B, 2), 1); /* PP1500_EN */ gpio_output(GPIO(0, B, 4), 1); /* PP3000_EN */ if (IS_ENABLED(CONFIG_DRIVERS_UART)) { _Static_assert(CONFIG_CONSOLE_SERIAL_UART_ADDRESS == UART2_BASE, "CONSOLE_SERIAL_UART should be UART2"); /* iomux: select gpio4c[4:3] as uart2 dbg port */ write32(&rk3399_grf->iomux_uart2c, IOMUX_UART2C); /* grf soc_con7[11:10] use for uart2 select */ write32(&rk3399_grf->soc_con7, UART2C_SEL); } }
void constructor(void) { _Static_assert(sizeof(BrickContext) <= BRICKLET_CONTEXT_MAX_SIZE, "BrickContext too big"); simple_constructor(); BC->pin_alert = &BS->pin2_da; BC->pin_alert->type = PIO_INPUT; BC->pin_alert->attribute = PIO_PULLUP; BA->PIO_Configure(BC->pin_alert, 1); BC->averaging = INA226_DEFAULT_AVERAGING; BC->voltage_conversion_time = INA226_DEFAULT_CONVERSION_BV; BC->current_conversion_time = INA226_DEFAULT_CONVERSION_SV; ina226_configure(); eeprom_read_calibration(); ina226_write_mask(); // 2 Milliohm // (((0.002/(2.5/1000/1000))*2097.152)/2048)*40.0 = 2^15 // 4 Milliohm // (((0.004/(2.5/1000/1000))*2097.152)/2048)*20.0 = 2^15 ina226_write_register(INA226_REG_CALIBRATION, 2048); }
static void SendControlData(void) { struct DebugData { int16_t accelerometer_sum[3]; int16_t gyro_sum[3]; int16_t stick_16[2]; uint8_t stick_8[2]; } __attribute__((packed)) debug_data; _Static_assert(((sizeof(struct DebugData) + 2) / 3) * 4 + 6 < UART_TX_BUFFER_LENGTH, "DebugData is too large for the UART TX buffer"); union S16Bytes temp; debug_data.accelerometer_sum[0] = AccelerometerSum(X_BODY_AXIS); debug_data.accelerometer_sum[1] = AccelerometerSum(Y_BODY_AXIS); debug_data.accelerometer_sum[2] = AccelerometerSum(Z_BODY_AXIS); debug_data.gyro_sum[0] = GyroSum(X_BODY_AXIS); debug_data.gyro_sum[1] = GyroSum(Y_BODY_AXIS); debug_data.gyro_sum[2] = GyroSum(Z_BODY_AXIS); temp.s16 = SBusYaw(); debug_data.stick_16[0] = (SBusPitch() << 4) | (temp.bytes[1] & 0x07); debug_data.stick_8[0] = temp.bytes[0]; temp.s16 = SBusThrust(); debug_data.stick_16[1] = (SBusRoll() << 4) | MotorsRunning() | (temp.bytes[1] & 0x07); debug_data.stick_8[1] = temp.bytes[0]; MKSerialTx(1, 'I', (uint8_t *)&debug_data, sizeof(debug_data)); }
static off_t seek_offset(IO *io) { off_t n; size_t sz; n = io->offset; sz = io->dbsz; _Static_assert(sizeof(io->offset) == sizeof(int64_t), "64-bit off_t"); /* * If the lseek offset will be negative, verify that this is a special * device file. Some such files (e.g. /dev/kmem) permit "negative" * offsets. * * Bail out if the calculation of a file offset would overflow. */ if ((io->flags & ISCHR) == 0 && n > OFF_MAX / (ssize_t)sz) errx(1, "seek offsets cannot be larger than %jd", (intmax_t)OFF_MAX); else if ((io->flags & ISCHR) != 0 && (uint64_t)n > UINT64_MAX / sz) errx(1, "seek offsets cannot be larger than %ju", (uintmax_t)UINT64_MAX); return ((off_t)( (uint64_t)n * sz )); }
// ----------------------------------------------------------------------------- static void SendSensorData(void) { struct SensorData { int16_t accelerometer_sum[3]; int16_t gyro_sum[3]; uint16_t biased_pressure; uint16_t battery_voltage; uint16_t timestamp; } __attribute__((packed)) sensor_data; _Static_assert(((sizeof(struct SensorData) + 2) / 3) * 4 + 6 < UART_TX_BUFFER_LENGTH, "SensorData is too large for the UART TX buffer"); sensor_data.accelerometer_sum[0] = AccelerometerSum(X_BODY_AXIS); sensor_data.accelerometer_sum[1] = AccelerometerSum(Y_BODY_AXIS); sensor_data.accelerometer_sum[2] = AccelerometerSum(Z_BODY_AXIS); sensor_data.gyro_sum[0] = GyroSum(X_BODY_AXIS); sensor_data.gyro_sum[1] = GyroSum(Y_BODY_AXIS); sensor_data.gyro_sum[2] = GyroSum(Z_BODY_AXIS); sensor_data.biased_pressure = BiasedPressureSum(); sensor_data.battery_voltage = BatteryVoltage(); sensor_data.timestamp = GetTimestamp(); MKSerialTx(1, 'I', (uint8_t *)&sensor_data, sizeof(sensor_data)); }
// ----------------------------------------------------------------------------- static void SendKalmanData(void) { struct KalmanData { int16_t gyro_sum[2]; int16_t command[2]; int16_t kalman_rate[2]; int16_t kalman_acceleration[2]; uint16_t timestamp; } __attribute__((packed)) kalman_data; _Static_assert(((sizeof(struct KalmanData) + 2) / 3) * 4 + 6 < UART_TX_BUFFER_LENGTH, "KalmanData is too large for the UART TX buffer"); kalman_data.gyro_sum[0] = GyroSum(X_BODY_AXIS); kalman_data.gyro_sum[1] = GyroSum(Y_BODY_AXIS); kalman_data.command[0] = (int16_t)(AngularCommand(X_BODY_AXIS) * 100.0); kalman_data.command[1] = (int16_t)(AngularCommand(Y_BODY_AXIS) * 100.0); kalman_data.kalman_rate[0] = (int16_t)(KalmanP() * GYRO_SCALE * ADC_N_SAMPLES); kalman_data.kalman_rate[1] = (int16_t)(KalmanQ() * GYRO_SCALE * ADC_N_SAMPLES); kalman_data.kalman_acceleration[0] = (int16_t)(KalmanPDot() * GYRO_SCALE * ADC_N_SAMPLES * DT); kalman_data.kalman_acceleration[1] = (int16_t)(KalmanQDot() * GYRO_SCALE * ADC_N_SAMPLES * DT); kalman_data.timestamp = GetTimestamp(); MKSerialTx(1, 'I', (uint8_t *)&kalman_data, sizeof(kalman_data)); }
void constructor(void) { _Static_assert(sizeof(BrickContext) <= BRICKLET_CONTEXT_MAX_SIZE, "BrickContext too big"); PIN_PWR.type = PIO_OUTPUT_0; PIN_PWR.attribute = PIO_DEFAULT; BA->PIO_Configure(&PIN_PWR, 1); PIN_SCL.type = PIO_INPUT; PIN_SCL.attribute = PIO_PULLUP; BA->PIO_Configure(&PIN_SCL, 1); PIN_SDA.type = PIO_INPUT; PIN_SDA.attribute = PIO_PULLUP; BA->PIO_Configure(&PIN_SCL, 1); PIN_PWM.type = PIO_INPUT; PIN_PWM.attribute = PIO_PULLUP; BA->PIO_Configure(&PIN_PWM, 1); SLEEP_MS(100); PIN_PWR.type = PIO_OUTPUT_1; BA->PIO_Configure(&PIN_PWR, 1); simple_constructor(); BC->laser_enabled = false; BC->new_mode = 0; BC->moving_average_upto[SIMPLE_UNIT_DISTANCE] = DEFAULT_MOVING_AVERAGE_DISTANCE; BC->moving_average_upto[SIMPLE_UNIT_VELOCITY] = DEFAULT_MOVING_AVERAGE_VELOCITY; reinitialize_moving_average_distance(); reinitialize_moving_average_velocity(); BC->measurement_state = MS_START_ACQUISITION; BC->next_measurement_state_counter = 100; }
/** * @brief Check size and offsets of context_switch_frame * * This does nothing at runtime. It is optimized out since it's only * doing compile-time checks. */ static void check_context_switch_frame_alignment(void) { _Static_assert(sizeof(struct context_switch_frame) % 16 == 0, "Stack pointer should be 16 byte aligned"); _Static_assert(sizeof(struct context_switch_frame) == CONTEXT_FRAME_SIZE, "context_switch_frame size mismatch"); CHECK_OFFSET(pad); CHECK_OFFSET(pc); CHECK_OFFSET(s0); CHECK_OFFSET(s1); CHECK_OFFSET(s2); CHECK_OFFSET(s3); CHECK_OFFSET(s4); CHECK_OFFSET(s5); CHECK_OFFSET(s6); CHECK_OFFSET(s7); CHECK_OFFSET(s8); CHECK_OFFSET(s9); CHECK_OFFSET(s10); CHECK_OFFSET(s11); CHECK_OFFSET(ra); CHECK_OFFSET(tp); CHECK_OFFSET(t0); CHECK_OFFSET(t1); CHECK_OFFSET(t2); CHECK_OFFSET(t3); CHECK_OFFSET(t4); CHECK_OFFSET(t5); CHECK_OFFSET(t6); CHECK_OFFSET(a0); CHECK_OFFSET(a1); CHECK_OFFSET(a2); CHECK_OFFSET(a3); CHECK_OFFSET(a4); CHECK_OFFSET(a5); CHECK_OFFSET(a6); CHECK_OFFSET(a7); /* * also check the SP offset in the _frame structure */ _Static_assert( offsetof(struct _thread, sp) == SP_OFFSET_IN_THREAD, "Offset of SP in _thread mismatch"); }
v_line *create_empty_line() { v_line *to_create = NULL; to_create = malloc(sizeof(v_line)); to_create->text[0] = 0; _Static_assert(sizeof(((v_line *) (0))->text) > 100, "..."); memset(to_create->text, 0, sizeof(((v_line *) (0))->text)); return to_create; }
/** ************************************************************************** * \brief * Compile time structure sanity * * \details * Sanitize the abstract data type interface. Enforced in header file so * as to catch improper usage/include by unauthorized callers. * ************************************************************************** */ static void utest_list_bytes( void ) { CDISPLAY("[%u]", sizeof(list_t)); CDISPLAY("[%u]", sizeof(adts_list_t)); _Static_assert(sizeof(list_t) <= sizeof(adts_list_t), "Mismatch structs detected"); CDISPLAY("[%u]", sizeof(list_node_t)); CDISPLAY("[%u]", sizeof(adts_list_node_t)); _Static_assert(sizeof(list_node_t) <= sizeof(adts_list_node_t), "Mismatch structs detected"); return; } /* utest_list_bytes() */
void constructor(void) { _Static_assert(sizeof(BrickContext) <= BRICKLET_CONTEXT_MAX_SIZE, "BrickContext too big"); BC->value[SIMPLE_UNIT_HEART_RATE] = 0; BC->beat_intervals_filled = false; BC->debounce_high_filled = false; BC->previous_signal_state = false; BC->beat_state = 0; BC->beat_state_changed = 0; BC->beat_state_changed_callback_enabled = 0; BC->beat_intervals_iterator = 0; BC->debounce_high_iterator = 0; BC->tick_counter = 0; BC->last_high_at = 0; BC->last_low_at = 0; BC->beat_intervals[0] = 0; BC->beat_intervals[1] = 0; BC->beat_intervals[2] = 0; BC->beat_intervals[3] = 0; BC->beat_intervals[4] = 0; BC->beat_intervals[5] = 0; BC->beat_intervals[6] = 0; BC->beat_intervals[7] = 0; BC->debounce_high_times[0] = 0; BC->debounce_high_times[1] = 0; BC->debounce_high_times[2] = 0; BC->debounce_high_times[3] = 0; BC->debounce_high_times[4] = 0; BC->debounce_high_times[5] = 0; BC->debounce_high_times[6] = 0; BC->debounce_high_times[7] = 0; BC->debounce_low_times[0] = 0; BC->debounce_low_times[1] = 0; BC->debounce_low_times[2] = 0; BC->debounce_low_times[3] = 0; BC->debounce_low_times[4] = 0; BC->debounce_low_times[5] = 0; BC->debounce_low_times[6] = 0; BC->debounce_low_times[7] = 0; //default debounce values BC->debounce_high = MIN_DEBOUNCE; BC->debounce_low = MIN_DEBOUNCE; // Setting the signal pin as input PIN_SIGNAL.pio->PIO_ODR = PIN_SIGNAL.mask; PIN_SIGNAL.pio->PIO_PER = PIN_SIGNAL.mask; simple_constructor(); }
void constructor(void) { _Static_assert(sizeof(BrickContext) <= BRICKLET_CONTEXT_MAX_SIZE, "BrickContext too big"); // Disable Reset PIN_RESET.type = PIO_OUTPUT_1; BA->PIO_Configure(&PIN_RESET, 1); PIN_INT_A.type = PIO_INPUT; PIN_INT_A.attribute = PIO_PULLUP; BA->PIO_Configure(&PIN_INT_A, 1); PIN_INT_B.type = PIO_INPUT; PIN_INT_B.attribute = PIO_PULLUP; BA->PIO_Configure(&PIN_INT_B, 1); BC->debounce_period = 100; // Enable interrupt for edge count io_write(I2C_INTERNAL_ADDRESS_GPINTEN_A, MASK_EDGE_COUNT); BC->interrupt_edge = false; for(uint8_t i = 0; i < NUM_PORTS; i++) { BC->counter[i] = 0; io_write(I2C_INTERNAL_ADDRESS_IOCON_A + i, IOCON_ODR); // Default is input pull up io_write(I2C_INTERNAL_ADDRESS_GPPU_A+i, 0xFF); io_write(I2C_INTERNAL_ADDRESS_IODIR_A+i, 0xFF); BC->current_gpinten[i] = 0; BC->current_olat[i] = 0; BC->current_gpio[i] = 0xFF; BC->current_gppu[i] = 0xFF; BC->current_iodir[i] = 0xFF; for(uint8_t j = 0; j < NUM_PINS_PER_PORT; j++) { BC->time[j][i] = 0; BC->time_remaining[j][i] = 0; } BC->monoflop_callback_mask[i] = 0; BC->edge_count[i] = 0; BC->edge_type[i] = EDGE_TYPE_RISING; BC->edge_debounce[i] = 100; BC->edge_debounce_counter[i] = 0; BC->edge_last_state[i] = 1; BC->interrupt_callback_mask[i] = 0; BC->interrupt_callback_value[i] = 0; } }
static uid_t id(const char *name, const char *type) { unsigned long val; char *ep; errno = 0; val = strtoul(name, &ep, 10); _Static_assert(UID_MAX >= GID_MAX, "UID MAX less than GID MAX"); if (errno || *ep != '\0' || val > UID_MAX) errx(1, "%s: illegal %s name", name, type); return (val); }
static unsigned int log2_help(unsigned int v) { const unsigned int b[] = {0x2, 0xC, 0xF0, 0xFF00, 0xFFFF0000}; const unsigned int S[] = {1, 2, 4, 8, 16}; _Static_assert(sizeof(unsigned int) == 4 ,"unsupported size of unsigned int"); int i; unsigned int r = 0; for ( i = 4; i >= 0; i-- ){ if ( v & b[i] ){ v >>= S[i]; r |= S[i]; } }
void test_nonconst_static_assert (int param) { int local = 0; _Static_assert (param > 0, "message"); /* { dg-error "expression in static assertion is not constant" } */ /* { dg-begin-multiline-output "" } _Static_assert (param > 0, "message"); ~~~~~~^~~ { dg-end-multiline-output "" } */ _Static_assert (param, "message"); /* { dg-error "expression in static assertion is not constant" } */ /* { dg-begin-multiline-output "" } _Static_assert (param, "message"); ^~~~~ { dg-end-multiline-output "" } */ _Static_assert (local, "message"); /* { dg-error "expression in static assertion is not constant" } */ /* { dg-begin-multiline-output "" } _Static_assert (local, "message"); ^~~~~ { dg-end-multiline-output "" } */ }
/** * Return the raw data type used to represent values of @p type, or return * @p type is @p type is not a complex type. * * @param type The type to query. */ bhnd_nvram_type bhnd_nvram_raw_type(bhnd_nvram_type type) { switch (type) { case BHND_NVRAM_TYPE_CHAR: return (BHND_NVRAM_TYPE_UINT8); case BHND_NVRAM_TYPE_CHAR_ARRAY: return (BHND_NVRAM_TYPE_UINT8_ARRAY); case BHND_NVRAM_TYPE_BOOL: { _Static_assert(sizeof(bhnd_nvram_bool_t) == sizeof(uint8_t), "bhnd_nvram_bool_t must be uint8-representable"); return (BHND_NVRAM_TYPE_UINT8); } case BHND_NVRAM_TYPE_BOOL_ARRAY: return (BHND_NVRAM_TYPE_UINT8_ARRAY); case BHND_NVRAM_TYPE_DATA: return (BHND_NVRAM_TYPE_UINT8_ARRAY); case BHND_NVRAM_TYPE_STRING: case BHND_NVRAM_TYPE_STRING_ARRAY: return (BHND_NVRAM_TYPE_UINT8_ARRAY); case BHND_NVRAM_TYPE_UINT8: case BHND_NVRAM_TYPE_UINT16: case BHND_NVRAM_TYPE_UINT32: case BHND_NVRAM_TYPE_UINT64: case BHND_NVRAM_TYPE_INT8: case BHND_NVRAM_TYPE_INT16: case BHND_NVRAM_TYPE_INT32: case BHND_NVRAM_TYPE_INT64: case BHND_NVRAM_TYPE_NULL: case BHND_NVRAM_TYPE_UINT8_ARRAY: case BHND_NVRAM_TYPE_UINT16_ARRAY: case BHND_NVRAM_TYPE_UINT32_ARRAY: case BHND_NVRAM_TYPE_UINT64_ARRAY: case BHND_NVRAM_TYPE_INT8_ARRAY: case BHND_NVRAM_TYPE_INT16_ARRAY: case BHND_NVRAM_TYPE_INT32_ARRAY: case BHND_NVRAM_TYPE_INT64_ARRAY: return (type); } /* Quiesce gcc4.2 */ BHND_NV_PANIC("bhnd nvram type %u unknown", type); }
/// Clear the marker that allows the firmware to boot. /// \returns true iff successful bool storage_protect_on(void) { _Static_assert(sizeof(STORAGE_PROTECT_ON_MAGIC) == sizeof(STORAGE_PROTECT_OFF_MAGIC), "Storage protection markers must be the same length"); Allocation active; if (!find_active_storage(&active)) return false; Allocation marker_sector = next_storage(active); flash_erase_word(marker_sector); bool ret = flash_write(marker_sector, 0, sizeof(STORAGE_PROTECT_ON_MAGIC), (const uint8_t*)STORAGE_PROTECT_ON_MAGIC); return ret; }
// ----------------------------------------------------------------------------- static void SendMotorSetpoints(void) { struct Setpoints { int16_t motor_setpoints[MAX_MOTORS]; uint16_t timestamp; } __attribute__((packed)) setpoints; _Static_assert(((sizeof(struct Setpoints) + 2) / 3) * 4 + 6 < UART_TX_BUFFER_LENGTH, "Setpoints is too large for the UART TX buffer"); for (uint16_t i = MAX_MOTORS; i--; ) setpoints.motor_setpoints[i] = MotorSetpoint(i); setpoints.timestamp = GetTimestamp(); MKSerialTx(1, 'I', (uint8_t *)&setpoints, sizeof(setpoints)); }
void constructor(void) { _Static_assert(sizeof(BrickContext) <= BRICKLET_CONTEXT_MAX_SIZE, "BrickContext too big"); BC->magic_number1 = MAGIC_NUMBER_INDUSTRIAL_DIGITAL_OUT_4_1; BC->magic_number2 = MAGIC_NUMBER_INDUSTRIAL_DIGITAL_OUT_4_2; BC->group[0] = 'n'; BC->group[1] = 'n'; BC->group[2] = 'n'; BC->group[3] = 'n'; reconfigure_group(); reconfigure_pins(); BC->monoflop_callback_mask = 0; BC->counter = 0; }
clock_t clock (void) { struct timespec ts; _Static_assert (CLOCKS_PER_SEC == 1000000, "CLOCKS_PER_SEC should be 1000000"); /* clock_gettime shouldn't fail here since CLOCK_PROCESS_CPUTIME_ID is supported since 2.6.12. Check the return value anyway in case the kernel barfs on us for some reason. */ if (__glibc_unlikely (__clock_gettime (CLOCK_PROCESS_CPUTIME_ID, &ts) != 0)) return (clock_t) -1; return (ts.tv_sec * CLOCKS_PER_SEC + ts.tv_nsec / (1000000000 / CLOCKS_PER_SEC)); }
static void _func_detour(func_t *func) { struct { uint8_t padding[3]; uint8_t opcode; ptrdiff_t offset; } jmp; _Static_assert(sizeof(jmp) == 8, "sizeof(jmp) != 8"); jmp.opcode = 0xE9; jmp.offset = (func->copy_addr - (func->real_addr + 5)); mem_unprotect((void *)func->real_addr, func->real_size); memcpy((void *)func->real_addr, &jmp.opcode, 5); mem_protect((void *)func->real_addr, func->real_size); }
void constructor(void) { _Static_assert(sizeof(BrickContext) <= BRICKLET_CONTEXT_MAX_SIZE, "BrickContext too big"); BC->motion = MOTION_NOT_DETECTED; BC->motion_detected = false; BC->detection_cycle_ended = false; BC->debounce = 0; BC->status_led_config = STATUS_LED_CONFIG_STATUS; PIN_DETECT.type = PIO_INPUT; PIN_DETECT.attribute = PIO_DEFAULT; BA->PIO_Configure(&PIN_DETECT, 1); PIN_LED.type = PIO_OUTPUT_1; PIN_LED.attribute = PIO_DEFAULT; BA->PIO_Configure(&PIN_LED, 1); }
void constructor(void) { _Static_assert(sizeof(BrickContext) <= BRICKLET_CONTEXT_MAX_SIZE, "BrickContext too big"); PIN_ENABLE.type = PIO_OUTPUT_0; PIN_ENABLE.attribute = PIO_DEFAULT; BA->PIO_Configure(&PIN_ENABLE, 1); PIN_FEEDBACK.type = PIO_INPUT; PIN_FEEDBACK.attribute = PIO_DEFAULT; BA->PIO_Configure(&PIN_FEEDBACK, 1); BC->morse_pos = 60; BC->morse_duration = 0; BC->morse_buzz = false; BC->beep_duration = BEEP_DURATION_OFF; BC->morse_length = 0; load_calibration(); }
//-------------------------------------------------------------------------------------------------- static WatchdogObj_t* CreateNewWatchdog ( pid_t clientPid, ///< The process id of the client uid_t appId ///< the user id of the client ) { char timerName[LIMIT_MAX_TIMER_NAME_BYTES]; LE_DEBUG("Making a new dog"); WatchdogObj_t* newDogPtr = le_mem_ForceAlloc(WatchdogPool); newDogPtr->procId = clientPid; newDogPtr->appId = appId; newDogPtr->kickTimeoutInterval = GetConfigKickTimeoutInterval(clientPid, appId); LE_ASSERT(0 <= snprintf(timerName, sizeof(timerName), "wdog_u%d:p%d", clientPid, appId)); newDogPtr->timer = le_timer_Create(timerName); _Static_assert (sizeof(pid_t) <= sizeof(intptr_t), "pid_t is truncated by cast to void*"); LE_ASSERT(LE_OK == le_timer_SetContextPtr(newDogPtr->timer, (void*)((intptr_t)clientPid))); LE_ASSERT(LE_OK == le_timer_SetHandler(newDogPtr->timer, WatchdogHandleExpiry)); return newDogPtr; }
static int _parse_kcmdline (void) { int ret = CMDLINE_UNSET; char value[KENV_MVALLEN]; /* a compile time check to avoid unexpected stack overflow */ _Static_assert(KENV_MVALLEN < 1024 * 1024, "KENV_MVALLEN is too large"); if (kenv (KENV_GET, "gnome.fallback", value, KENV_MVALLEN) == -1) return ret; if (*value != '0' && *value != '1') fprintf (stderr, "gnome-session-is-accelerated: Invalid value '%s' for gnome.fallback passed in kernel environment.\n", value); else ret = atoi (value); g_debug ("Kernel environment parsed to %d", ret); return ret; }