content
stringlengths
19
48.2k
/** * mono_cominterop_get_native_wrapper: * \param method managed method * \returns the generated method to call */ MonoMethod * mono_cominterop_get_native_wrapper (MonoMethod *method) { MonoMethod *res; GHashTable *cache; MonoMethodBuilder *mb; MonoMethodSignature *sig, *csig; g_assert (method); cache = mono_marshal_get_cache (&mono_method_get_wrapper_cache (method)->cominterop_wrapper_cache, mono_aligned_addr_hash, NULL); if ((res = mono_marshal_find_in_cache (cache, method))) return res; if (!m_class_get_vtable (method->klass)) mono_class_setup_vtable (method->klass); if (!m_class_get_methods (method->klass)) mono_class_setup_methods (method->klass); g_assert (!mono_class_has_failure (method->klass)); sig = mono_method_signature_internal (method); mb = mono_mb_new (method->klass, method->name, MONO_WRAPPER_COMINTEROP); #ifndef DISABLE_JIT if (MONO_CLASS_IS_IMPORT(method->klass)) { if (!strcmp(method->name, ".ctor")) { MONO_STATIC_POINTER_INIT (MonoMethod, ctor) ERROR_DECL (error); ctor = mono_class_get_method_from_name_checked (mono_class_get_com_object_class (), ".ctor", 0, 0, error); mono_error_assert_ok (error); MONO_STATIC_POINTER_INIT_END (MonoMethod, ctor) mono_mb_emit_ldarg (mb, 0); mono_mb_emit_managed_call (mb, ctor, NULL); mono_mb_emit_byte (mb, CEE_RET); } else if (method->flags & METHOD_ATTRIBUTE_STATIC) { ERROR_DECL (error); mono_cominterop_get_interface_missing_error (error, method); mono_mb_emit_exception_for_error (mb, error); mono_error_cleanup (error); } else { MonoMethod *adjusted_method; int retval = 0; int ptr_this; int i; gboolean const preserve_sig = (method->iflags & METHOD_IMPL_ATTRIBUTE_PRESERVE_SIG) != 0; ptr_this = mono_mb_add_local (mb, mono_get_int_type ()); if (!MONO_TYPE_IS_VOID (sig->ret)) retval = mono_mb_add_local (mb, sig->ret); mono_mb_emit_ldarg (mb, 0); mono_mb_emit_ptr (mb, method); mono_mb_emit_icall (mb, cominterop_get_method_interface); mono_mb_emit_icall (mb, cominterop_get_interface); mono_mb_emit_stloc (mb, ptr_this); mono_mb_emit_ldloc (mb, ptr_this); for (i = 1; i <= sig->param_count; i++) mono_mb_emit_ldarg (mb, i); if (!MONO_TYPE_IS_VOID (sig->ret) && !preserve_sig) mono_mb_emit_ldloc_addr (mb, retval); adjusted_method = cominterop_get_native_wrapper_adjusted (method); mono_mb_emit_managed_call (mb, adjusted_method, NULL); if (!preserve_sig) { MONO_STATIC_POINTER_INIT (MonoMethod, ThrowExceptionForHR) ERROR_DECL (error); ThrowExceptionForHR = mono_class_get_method_from_name_checked (mono_defaults.marshal_class, "ThrowExceptionForHR", 1, 0, error); mono_error_assert_ok (error); MONO_STATIC_POINTER_INIT_END (MonoMethod, ThrowExceptionForHR) mono_mb_emit_managed_call (mb, ThrowExceptionForHR, NULL); if (!MONO_TYPE_IS_VOID (sig->ret)) mono_mb_emit_ldloc (mb, retval); } mono_mb_emit_byte (mb, CEE_RET); } } else { char *msg = g_strdup ("non imported interfaces on \ imported classes is not yet implemented."); mono_mb_emit_exception (mb, "NotSupportedException", msg); } #endif csig = mono_metadata_signature_dup_full (m_class_get_image (method->klass), sig); csig->pinvoke = 0; res = mono_mb_create_and_cache (cache, method, mb, csig, csig->param_count + 16); mono_mb_free (mb); return res; }
/* * Generic routines and proc interface for ELD(EDID Like Data) information * * Copyright(c) 2008 Intel Corporation. * * Authors: * Wu Fengguang <wfg@linux.intel.com> * * This driver is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This driver is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include <linux/init.h> #include <linux/slab.h> #include <sound/core.h> #include <asm/unaligned.h> #include "hda_codec.h" #include "hda_local.h" enum eld_versions { ELD_VER_CEA_861D = 2, ELD_VER_PARTIAL = 31, }; enum cea_edid_versions { CEA_EDID_VER_NONE = 0, CEA_EDID_VER_CEA861 = 1, CEA_EDID_VER_CEA861A = 2, CEA_EDID_VER_CEA861BCD = 3, CEA_EDID_VER_RESERVED = 4, }; static char *cea_speaker_allocation_names[] = { /* 0 */ "FL/FR", /* 1 */ "LFE", /* 2 */ "FC", /* 3 */ "RL/RR", /* 4 */ "RC", /* 5 */ "FLC/FRC", /* 6 */ "RLC/RRC", /* 7 */ "FLW/FRW", /* 8 */ "FLH/FRH", /* 9 */ "TC", /* 10 */ "FCH", }; static char *eld_connection_type_names[4] = { "HDMI", "DisplayPort", "2-reserved", "3-reserved" }; enum cea_audio_coding_types { AUDIO_CODING_TYPE_REF_STREAM_HEADER = 0, AUDIO_CODING_TYPE_LPCM = 1, AUDIO_CODING_TYPE_AC3 = 2, AUDIO_CODING_TYPE_MPEG1 = 3, AUDIO_CODING_TYPE_MP3 = 4, AUDIO_CODING_TYPE_MPEG2 = 5, AUDIO_CODING_TYPE_AACLC = 6, AUDIO_CODING_TYPE_DTS = 7, AUDIO_CODING_TYPE_ATRAC = 8, AUDIO_CODING_TYPE_SACD = 9, AUDIO_CODING_TYPE_EAC3 = 10, AUDIO_CODING_TYPE_DTS_HD = 11, AUDIO_CODING_TYPE_MLP = 12, AUDIO_CODING_TYPE_DST = 13, AUDIO_CODING_TYPE_WMAPRO = 14, AUDIO_CODING_TYPE_REF_CXT = 15, /* also include valid xtypes below */ AUDIO_CODING_TYPE_HE_AAC = 15, AUDIO_CODING_TYPE_HE_AAC2 = 16, AUDIO_CODING_TYPE_MPEG_SURROUND = 17, }; enum cea_audio_coding_xtypes { AUDIO_CODING_XTYPE_HE_REF_CT = 0, AUDIO_CODING_XTYPE_HE_AAC = 1, AUDIO_CODING_XTYPE_HE_AAC2 = 2, AUDIO_CODING_XTYPE_MPEG_SURROUND = 3, AUDIO_CODING_XTYPE_FIRST_RESERVED = 4, }; static char *cea_audio_coding_type_names[] = { /* 0 */ "undefined", /* 1 */ "LPCM", /* 2 */ "AC-3", /* 3 */ "MPEG1", /* 4 */ "MP3", /* 5 */ "MPEG2", /* 6 */ "AAC-LC", /* 7 */ "DTS", /* 8 */ "ATRAC", /* 9 */ "DSD (One Bit Audio)", /* 10 */ "E-AC-3/DD+ (Dolby Digital Plus)", /* 11 */ "DTS-HD", /* 12 */ "MLP (Dolby TrueHD)", /* 13 */ "DST", /* 14 */ "WMAPro", /* 15 */ "HE-AAC", /* 16 */ "HE-AACv2", /* 17 */ "MPEG Surround", }; /* * The following two lists are shared between * - HDMI audio InfoFrame (source to sink) * - CEA E-EDID Extension (sink to source) */ /* * SS1:SS0 index => sample size */ static int cea_sample_sizes[4] = { 0, /* 0: Refer to Stream Header */ AC_SUPPCM_BITS_16, /* 1: 16 bits */ AC_SUPPCM_BITS_20, /* 2: 20 bits */ AC_SUPPCM_BITS_24, /* 3: 24 bits */ }; /* * SF2:SF1:SF0 index => sampling frequency */ static int cea_sampling_frequencies[8] = { 0, /* 0: Refer to Stream Header */ SNDRV_PCM_RATE_32000, /* 1: 32000Hz */ SNDRV_PCM_RATE_44100, /* 2: 44100Hz */ SNDRV_PCM_RATE_48000, /* 3: 48000Hz */ SNDRV_PCM_RATE_88200, /* 4: 88200Hz */ SNDRV_PCM_RATE_96000, /* 5: 96000Hz */ SNDRV_PCM_RATE_176400, /* 6: 176400Hz */ SNDRV_PCM_RATE_192000, /* 7: 192000Hz */ }; static unsigned char hdmi_get_eld_byte(struct hda_codec *codec, hda_nid_t nid, int byte_index) { unsigned int val; val = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_HDMI_ELDD, byte_index); #ifdef BE_PARANOID printk(KERN_INFO "HDMI: ELD data byte %d: 0x%x\n", byte_index, val); #endif if ((val & AC_ELDD_ELD_VALID) == 0) { snd_printd(KERN_INFO "HDMI: invalid ELD data byte %d\n", byte_index); val = 0; } return val & AC_ELDD_ELD_DATA; } #define GRAB_BITS(buf, byte, lowbit, bits) \ ({ \ BUILD_BUG_ON(lowbit > 7); \ BUILD_BUG_ON(bits > 8); \ BUILD_BUG_ON(bits <= 0); \ \ (buf[byte] >> (lowbit)) & ((1 << (bits)) - 1); \ }) static void hdmi_update_short_audio_desc(struct cea_sad *a, const unsigned char *buf) { int i; int val; val = GRAB_BITS(buf, 1, 0, 7); a->rates = 0; for (i = 0; i < 7; i++) if (val & (1 << i)) a->rates |= cea_sampling_frequencies[i + 1]; a->channels = GRAB_BITS(buf, 0, 0, 3); a->channels++; a->sample_bits = 0; a->max_bitrate = 0; a->format = GRAB_BITS(buf, 0, 3, 4); switch (a->format) { case AUDIO_CODING_TYPE_REF_STREAM_HEADER: snd_printd(KERN_INFO "HDMI: audio coding type 0 not expected\n"); break; case AUDIO_CODING_TYPE_LPCM: val = GRAB_BITS(buf, 2, 0, 3); for (i = 0; i < 3; i++) if (val & (1 << i)) a->sample_bits |= cea_sample_sizes[i + 1]; break; case AUDIO_CODING_TYPE_AC3: case AUDIO_CODING_TYPE_MPEG1: case AUDIO_CODING_TYPE_MP3: case AUDIO_CODING_TYPE_MPEG2: case AUDIO_CODING_TYPE_AACLC: case AUDIO_CODING_TYPE_DTS: case AUDIO_CODING_TYPE_ATRAC: a->max_bitrate = GRAB_BITS(buf, 2, 0, 8); a->max_bitrate *= 8000; break; case AUDIO_CODING_TYPE_SACD: break; case AUDIO_CODING_TYPE_EAC3: break; case AUDIO_CODING_TYPE_DTS_HD: break; case AUDIO_CODING_TYPE_MLP: break; case AUDIO_CODING_TYPE_DST: break; case AUDIO_CODING_TYPE_WMAPRO: a->profile = GRAB_BITS(buf, 2, 0, 3); break; case AUDIO_CODING_TYPE_REF_CXT: a->format = GRAB_BITS(buf, 2, 3, 5); if (a->format == AUDIO_CODING_XTYPE_HE_REF_CT || a->format >= AUDIO_CODING_XTYPE_FIRST_RESERVED) { snd_printd(KERN_INFO "HDMI: audio coding xtype %d not expected\n", a->format); a->format = 0; } else a->format += AUDIO_CODING_TYPE_HE_AAC - AUDIO_CODING_XTYPE_HE_AAC; break; } } /* * Be careful, ELD buf could be totally rubbish! */ static int hdmi_update_eld(struct hdmi_eld *e, const unsigned char *buf, int size) { int mnl; int i; e->eld_ver = GRAB_BITS(buf, 0, 3, 5); if (e->eld_ver != ELD_VER_CEA_861D && e->eld_ver != ELD_VER_PARTIAL) { snd_printd(KERN_INFO "HDMI: Unknown ELD version %d\n", e->eld_ver); goto out_fail; } e->eld_size = size; e->baseline_len = GRAB_BITS(buf, 2, 0, 8); mnl = GRAB_BITS(buf, 4, 0, 5); e->cea_edid_ver = GRAB_BITS(buf, 4, 5, 3); e->support_hdcp = GRAB_BITS(buf, 5, 0, 1); e->support_ai = GRAB_BITS(buf, 5, 1, 1); e->conn_type = GRAB_BITS(buf, 5, 2, 2); e->sad_count = GRAB_BITS(buf, 5, 4, 4); e->aud_synch_delay = GRAB_BITS(buf, 6, 0, 8) * 2; e->spk_alloc = GRAB_BITS(buf, 7, 0, 7); e->port_id = get_unaligned_le64(buf + 8); /* not specified, but the spec's tendency is little endian */ e->manufacture_id = get_unaligned_le16(buf + 16); e->product_id = get_unaligned_le16(buf + 18); if (mnl > ELD_MAX_MNL) { snd_printd(KERN_INFO "HDMI: MNL is reserved value %d\n", mnl); goto out_fail; } else if (ELD_FIXED_BYTES + mnl > size) { snd_printd(KERN_INFO "HDMI: out of range MNL %d\n", mnl); goto out_fail; } else strlcpy(e->monitor_name, buf + ELD_FIXED_BYTES, mnl + 1); for (i = 0; i < e->sad_count; i++) { if (ELD_FIXED_BYTES + mnl + 3 * (i + 1) > size) { snd_printd(KERN_INFO "HDMI: out of range SAD %d\n", i); goto out_fail; } hdmi_update_short_audio_desc(e->sad + i, buf + ELD_FIXED_BYTES + mnl + 3 * i); } return 0; out_fail: e->eld_ver = 0; return -EINVAL; } int snd_hdmi_get_eld_size(struct hda_codec *codec, hda_nid_t nid) { return snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_HDMI_DIP_SIZE, AC_DIPSIZE_ELD_BUF); } int snd_hdmi_get_eld(struct hdmi_eld *eld, struct hda_codec *codec, hda_nid_t nid) { int i; int ret; int size; unsigned char *buf; if (!eld->eld_valid) return -ENOENT; size = snd_hdmi_get_eld_size(codec, nid); if (size == 0) { /* wfg: workaround for ASUS P5E-VM HDMI board */ snd_printd(KERN_INFO "HDMI: ELD buf size is 0, force 128\n"); size = 128; } if (size < ELD_FIXED_BYTES || size > PAGE_SIZE) { snd_printd(KERN_INFO "HDMI: invalid ELD buf size %d\n", size); return -ERANGE; } buf = kmalloc(size, GFP_KERNEL); if (!buf) return -ENOMEM; for (i = 0; i < size; i++) buf[i] = hdmi_get_eld_byte(codec, nid, i); ret = hdmi_update_eld(eld, buf, size); kfree(buf); return ret; } static void hdmi_show_short_audio_desc(struct cea_sad *a) { char buf[SND_PRINT_RATES_ADVISED_BUFSIZE]; char buf2[8 + SND_PRINT_BITS_ADVISED_BUFSIZE] = ", bits ="; if (!a->format) return; snd_print_pcm_rates(a->rates, buf, sizeof(buf)); if (a->format == AUDIO_CODING_TYPE_LPCM) snd_print_pcm_bits(a->sample_bits, buf2 + 8, sizeof(buf2) - 8); else if (a->max_bitrate) snprintf(buf2, sizeof(buf2), ", max bitrate = %d", a->max_bitrate); else buf2[0] = '\0'; printk(KERN_INFO "HDMI: supports coding type %s:" " channels = %d, rates =%s%s\n", cea_audio_coding_type_names[a->format], a->channels, buf, buf2); } void snd_print_channel_allocation(int spk_alloc, char *buf, int buflen) { int i, j; for (i = 0, j = 0; i < ARRAY_SIZE(cea_speaker_allocation_names); i++) { if (spk_alloc & (1 << i)) j += snprintf(buf + j, buflen - j, " %s", cea_speaker_allocation_names[i]); } buf[j] = '\0'; /* necessary when j == 0 */ } void snd_hdmi_show_eld(struct hdmi_eld *e) { int i; printk(KERN_INFO "HDMI: detected monitor %s at connection type %s\n", e->monitor_name, eld_connection_type_names[e->conn_type]); if (e->spk_alloc) { char buf[SND_PRINT_CHANNEL_ALLOCATION_ADVISED_BUFSIZE]; snd_print_channel_allocation(e->spk_alloc, buf, sizeof(buf)); printk(KERN_INFO "HDMI: available speakers:%s\n", buf); } for (i = 0; i < e->sad_count; i++) hdmi_show_short_audio_desc(e->sad + i); } #ifdef CONFIG_PROC_FS static void hdmi_print_sad_info(int i, struct cea_sad *a, struct snd_info_buffer *buffer) { char buf[SND_PRINT_RATES_ADVISED_BUFSIZE]; snd_iprintf(buffer, "sad%d_coding_type\t[0x%x] %s\n", i, a->format, cea_audio_coding_type_names[a->format]); snd_iprintf(buffer, "sad%d_channels\t\t%d\n", i, a->channels); snd_print_pcm_rates(a->rates, buf, sizeof(buf)); snd_iprintf(buffer, "sad%d_rates\t\t[0x%x]%s\n", i, a->rates, buf); if (a->format == AUDIO_CODING_TYPE_LPCM) { snd_print_pcm_bits(a->sample_bits, buf, sizeof(buf)); snd_iprintf(buffer, "sad%d_bits\t\t[0x%x]%s\n", i, a->sample_bits, buf); } if (a->max_bitrate) snd_iprintf(buffer, "sad%d_max_bitrate\t%d\n", i, a->max_bitrate); if (a->profile) snd_iprintf(buffer, "sad%d_profile\t\t%d\n", i, a->profile); } static void hdmi_print_eld_info(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { struct hdmi_eld *e = entry->private_data; char buf[SND_PRINT_CHANNEL_ALLOCATION_ADVISED_BUFSIZE]; int i; static char *eld_versoin_names[32] = { "reserved", "reserved", "CEA-861D or below", [3 ... 30] = "reserved", [31] = "partial" }; static char *cea_edid_version_names[8] = { "no CEA EDID Timing Extension block present", "CEA-861", "CEA-861-A", "CEA-861-B, C or D", [4 ... 7] = "reserved" }; snd_iprintf(buffer, "monitor_present\t\t%d\n", e->monitor_present); snd_iprintf(buffer, "eld_valid\t\t%d\n", e->eld_valid); if (!e->eld_valid) return; snd_iprintf(buffer, "monitor_name\t\t%s\n", e->monitor_name); snd_iprintf(buffer, "connection_type\t\t%s\n", eld_connection_type_names[e->conn_type]); snd_iprintf(buffer, "eld_version\t\t[0x%x] %s\n", e->eld_ver, eld_versoin_names[e->eld_ver]); snd_iprintf(buffer, "edid_version\t\t[0x%x] %s\n", e->cea_edid_ver, cea_edid_version_names[e->cea_edid_ver]); snd_iprintf(buffer, "manufacture_id\t\t0x%x\n", e->manufacture_id); snd_iprintf(buffer, "product_id\t\t0x%x\n", e->product_id); snd_iprintf(buffer, "port_id\t\t\t0x%llx\n", (long long)e->port_id); snd_iprintf(buffer, "support_hdcp\t\t%d\n", e->support_hdcp); snd_iprintf(buffer, "support_ai\t\t%d\n", e->support_ai); snd_iprintf(buffer, "audio_sync_delay\t%d\n", e->aud_synch_delay); snd_print_channel_allocation(e->spk_alloc, buf, sizeof(buf)); snd_iprintf(buffer, "speakers\t\t[0x%x]%s\n", e->spk_alloc, buf); snd_iprintf(buffer, "sad_count\t\t%d\n", e->sad_count); for (i = 0; i < e->sad_count; i++) hdmi_print_sad_info(i, e->sad + i, buffer); } static void hdmi_write_eld_info(struct snd_info_entry *entry, struct snd_info_buffer *buffer) { struct hdmi_eld *e = entry->private_data; char line[64]; char name[64]; char *sname; long long val; unsigned int n; while (!snd_info_get_line(buffer, line, sizeof(line))) { if (sscanf(line, "%s %llx", name, &val) != 2) continue; /* * We don't allow modification to these fields: * monitor_name manufacture_id product_id * eld_version edid_version */ if (!strcmp(name, "monitor_present")) e->monitor_present = val; else if (!strcmp(name, "eld_valid")) e->eld_valid = val; else if (!strcmp(name, "connection_type")) e->conn_type = val; else if (!strcmp(name, "port_id")) e->port_id = val; else if (!strcmp(name, "support_hdcp")) e->support_hdcp = val; else if (!strcmp(name, "support_ai")) e->support_ai = val; else if (!strcmp(name, "audio_sync_delay")) e->aud_synch_delay = val; else if (!strcmp(name, "speakers")) e->spk_alloc = val; else if (!strcmp(name, "sad_count")) e->sad_count = val; else if (!strncmp(name, "sad", 3)) { sname = name + 4; n = name[3] - '0'; if (name[4] >= '0' && name[4] <= '9') { sname++; n = 10 * n + name[4] - '0'; } if (n >= ELD_MAX_SAD) continue; if (!strcmp(sname, "_coding_type")) e->sad[n].format = val; else if (!strcmp(sname, "_channels")) e->sad[n].channels = val; else if (!strcmp(sname, "_rates")) e->sad[n].rates = val; else if (!strcmp(sname, "_bits")) e->sad[n].sample_bits = val; else if (!strcmp(sname, "_max_bitrate")) e->sad[n].max_bitrate = val; else if (!strcmp(sname, "_profile")) e->sad[n].profile = val; if (n >= e->sad_count) e->sad_count = n + 1; } } } int snd_hda_eld_proc_new(struct hda_codec *codec, struct hdmi_eld *eld, int index) { char name[32]; struct snd_info_entry *entry; int err; snprintf(name, sizeof(name), "eld#%d.%d", codec->addr, index); err = snd_card_proc_new(codec->bus->card, name, &entry); if (err < 0) return err; snd_info_set_text_ops(entry, eld, hdmi_print_eld_info); entry->c.text.write = hdmi_write_eld_info; entry->mode |= S_IWUSR; eld->proc_entry = entry; return 0; } void snd_hda_eld_proc_free(struct hda_codec *codec, struct hdmi_eld *eld) { if (!codec->bus->shutdown && eld->proc_entry) { snd_device_free(codec->bus->card, eld->proc_entry); eld->proc_entry = NULL; } } #endif /* CONFIG_PROC_FS */ /* update PCM info based on ELD */ void hdmi_eld_update_pcm_info(struct hdmi_eld *eld, struct hda_pcm_stream *pcm, struct hda_pcm_stream *codec_pars) { int i; /* assume basic audio support (the basic audio flag is not in ELD; * however, all audio capable sinks are required to support basic * audio) */ pcm->rates = SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000; pcm->formats = SNDRV_PCM_FMTBIT_S16_LE; pcm->maxbps = 16; pcm->channels_max = 2; for (i = 0; i < eld->sad_count; i++) { struct cea_sad *a = &eld->sad[i]; pcm->rates |= a->rates; if (a->channels > pcm->channels_max) pcm->channels_max = a->channels; if (a->format == AUDIO_CODING_TYPE_LPCM) { if (a->sample_bits & AC_SUPPCM_BITS_20) { pcm->formats |= SNDRV_PCM_FMTBIT_S32_LE; if (pcm->maxbps < 20) pcm->maxbps = 20; } if (a->sample_bits & AC_SUPPCM_BITS_24) { pcm->formats |= SNDRV_PCM_FMTBIT_S32_LE; if (pcm->maxbps < 24) pcm->maxbps = 24; } } } if (!codec_pars) return; /* restrict the parameters by the values the codec provides */ pcm->rates &= codec_pars->rates; pcm->formats &= codec_pars->formats; pcm->channels_max = min(pcm->channels_max, codec_pars->channels_max); pcm->maxbps = min(pcm->maxbps, codec_pars->maxbps); }
/* SPDX-License-Identifier: GPL-2.0 */ /* * Public Include File for DRV6000 users * (ie. NxtWave Communications - NXT6000 demodulator driver) * * Copyright (C) 2001 NxtWave Communications, Inc. * */ /* Nxt6000 Register Addresses and Bit Masks */ /* Maximum Register Number */ #define MAXNXT6000REG (0x9A) /* 0x1B A_VIT_BER_0 aka 0x3A */ #define A_VIT_BER_0 (0x1B) /* 0x1D A_VIT_BER_TIMER_0 aka 0x38 */ #define A_VIT_BER_TIMER_0 (0x1D) /* 0x21 RS_COR_STAT */ #define RS_COR_STAT (0x21) #define RSCORESTATUS (0x03) /* 0x22 RS_COR_INTEN */ #define RS_COR_INTEN (0x22) /* 0x23 RS_COR_INSTAT */ #define RS_COR_INSTAT (0x23) #define INSTAT_ERROR (0x04) #define LOCK_LOSS_BITS (0x03) /* 0x24 RS_COR_SYNC_PARAM */ #define RS_COR_SYNC_PARAM (0x24) #define SYNC_PARAM (0x03) /* 0x25 BER_CTRL */ #define BER_CTRL (0x25) #define BER_ENABLE (0x02) #define BER_RESET (0x01) /* 0x26 BER_PAY */ #define BER_PAY (0x26) /* 0x27 BER_PKT_L */ #define BER_PKT_L (0x27) #define BER_PKTOVERFLOW (0x80) /* 0x30 VIT_COR_CTL */ #define VIT_COR_CTL (0x30) #define BER_CONTROL (0x02) #define VIT_COR_MASK (0x82) #define VIT_COR_RESYNC (0x80) /* 0x32 VIT_SYNC_STATUS */ #define VIT_SYNC_STATUS (0x32) #define VITINSYNC (0x80) /* 0x33 VIT_COR_INTEN */ #define VIT_COR_INTEN (0x33) #define GLOBAL_ENABLE (0x80) /* 0x34 VIT_COR_INTSTAT */ #define VIT_COR_INTSTAT (0x34) #define BER_DONE (0x08) #define BER_OVERFLOW (0x10) /* 0x38 VIT_BERTIME_2 */ #define VIT_BERTIME_2 (0x38) /* 0x39 VIT_BERTIME_1 */ #define VIT_BERTIME_1 (0x39) /* 0x3A VIT_BERTIME_0 */ #define VIT_BERTIME_0 (0x3a) /* 0x38 OFDM_BERTimer *//* Use the alias registers */ #define A_VIT_BER_TIMER_0 (0x1D) /* 0x3A VIT_BER_TIMER_0 *//* Use the alias registers */ #define A_VIT_BER_0 (0x1B) /* 0x3B VIT_BER_1 */ #define VIT_BER_1 (0x3b) /* 0x3C VIT_BER_0 */ #define VIT_BER_0 (0x3c) /* 0x40 OFDM_COR_CTL */ #define OFDM_COR_CTL (0x40) #define COREACT (0x20) #define HOLDSM (0x10) #define WAIT_AGC (0x02) #define WAIT_SYR (0x03) /* 0x41 OFDM_COR_STAT */ #define OFDM_COR_STAT (0x41) #define COR_STATUS (0x0F) #define MONITOR_TPS (0x06) #define TPSLOCKED (0x40) #define AGCLOCKED (0x10) /* 0x42 OFDM_COR_INTEN */ #define OFDM_COR_INTEN (0x42) #define TPSRCVBAD (0x04) #define TPSRCVCHANGED (0x02) #define TPSRCVUPDATE (0x01) /* 0x43 OFDM_COR_INSTAT */ #define OFDM_COR_INSTAT (0x43) /* 0x44 OFDM_COR_MODEGUARD */ #define OFDM_COR_MODEGUARD (0x44) #define FORCEMODE (0x08) #define FORCEMODE8K (0x04) /* 0x45 OFDM_AGC_CTL */ #define OFDM_AGC_CTL (0x45) #define INITIAL_AGC_BW (0x08) #define AGCNEG (0x02) #define AGCLAST (0x10) /* 0x48 OFDM_AGC_TARGET */ #define OFDM_AGC_TARGET (0x48) #define OFDM_AGC_TARGET_DEFAULT (0x28) #define OFDM_AGC_TARGET_IMPULSE (0x38) /* 0x49 OFDM_AGC_GAIN_1 */ #define OFDM_AGC_GAIN_1 (0x49) /* 0x4B OFDM_ITB_CTL */ #define OFDM_ITB_CTL (0x4B) #define ITBINV (0x01) /* 0x49 AGC_GAIN_1 */ #define AGC_GAIN_1 (0x49) /* 0x4A AGC_GAIN_2 */ #define AGC_GAIN_2 (0x4A) /* 0x4C OFDM_ITB_FREQ_1 */ #define OFDM_ITB_FREQ_1 (0x4C) /* 0x4D OFDM_ITB_FREQ_2 */ #define OFDM_ITB_FREQ_2 (0x4D) /* 0x4E OFDM_CAS_CTL */ #define OFDM_CAS_CTL (0x4E) #define ACSDIS (0x40) #define CCSEN (0x80) /* 0x4F CAS_FREQ */ #define CAS_FREQ (0x4F) /* 0x51 OFDM_SYR_CTL */ #define OFDM_SYR_CTL (0x51) #define SIXTH_ENABLE (0x80) #define SYR_TRACKING_DISABLE (0x01) /* 0x52 OFDM_SYR_STAT */ #define OFDM_SYR_STAT (0x52) #define GI14_2K_SYR_LOCK (0x13) #define GI14_8K_SYR_LOCK (0x17) #define GI14_SYR_LOCK (0x10) /* 0x55 OFDM_SYR_OFFSET_1 */ #define OFDM_SYR_OFFSET_1 (0x55) /* 0x56 OFDM_SYR_OFFSET_2 */ #define OFDM_SYR_OFFSET_2 (0x56) /* 0x58 OFDM_SCR_CTL */ #define OFDM_SCR_CTL (0x58) #define SYR_ADJ_DECAY_MASK (0x70) #define SYR_ADJ_DECAY (0x30) /* 0x59 OFDM_PPM_CTL_1 */ #define OFDM_PPM_CTL_1 (0x59) #define PPMMAX_MASK (0x30) #define PPM256 (0x30) /* 0x5B OFDM_TRL_NOMINALRATE_1 */ #define OFDM_TRL_NOMINALRATE_1 (0x5B) /* 0x5C OFDM_TRL_NOMINALRATE_2 */ #define OFDM_TRL_NOMINALRATE_2 (0x5C) /* 0x5D OFDM_TRL_TIME_1 */ #define OFDM_TRL_TIME_1 (0x5D) /* 0x60 OFDM_CRL_FREQ_1 */ #define OFDM_CRL_FREQ_1 (0x60) /* 0x63 OFDM_CHC_CTL_1 */ #define OFDM_CHC_CTL_1 (0x63) #define MANMEAN1 (0xF0); #define CHCFIR (0x01) /* 0x64 OFDM_CHC_SNR */ #define OFDM_CHC_SNR (0x64) /* 0x65 OFDM_BDI_CTL */ #define OFDM_BDI_CTL (0x65) #define LP_SELECT (0x02) /* 0x67 OFDM_TPS_RCVD_1 */ #define OFDM_TPS_RCVD_1 (0x67) #define TPSFRAME (0x03) /* 0x68 OFDM_TPS_RCVD_2 */ #define OFDM_TPS_RCVD_2 (0x68) /* 0x69 OFDM_TPS_RCVD_3 */ #define OFDM_TPS_RCVD_3 (0x69) /* 0x6A OFDM_TPS_RCVD_4 */ #define OFDM_TPS_RCVD_4 (0x6A) /* 0x6B OFDM_TPS_RESERVED_1 */ #define OFDM_TPS_RESERVED_1 (0x6B) /* 0x6C OFDM_TPS_RESERVED_2 */ #define OFDM_TPS_RESERVED_2 (0x6C) /* 0x73 OFDM_MSC_REV */ #define OFDM_MSC_REV (0x73) /* 0x76 OFDM_SNR_CARRIER_2 */ #define OFDM_SNR_CARRIER_2 (0x76) #define MEAN_MASK (0x80) #define MEANBIT (0x80) /* 0x80 ANALOG_CONTROL_0 */ #define ANALOG_CONTROL_0 (0x80) #define POWER_DOWN_ADC (0x40) /* 0x81 ENABLE_TUNER_IIC */ #define ENABLE_TUNER_IIC (0x81) #define ENABLE_TUNER_BIT (0x01) /* 0x82 EN_DMD_RACQ */ #define EN_DMD_RACQ (0x82) #define EN_DMD_RACQ_REG_VAL (0x81) #define EN_DMD_RACQ_REG_VAL_14 (0x01) /* 0x84 SNR_COMMAND */ #define SNR_COMMAND (0x84) #define SNRStat (0x80) /* 0x85 SNRCARRIERNUMBER_LSB */ #define SNRCARRIERNUMBER_LSB (0x85) /* 0x87 SNRMINTHRESHOLD_LSB */ #define SNRMINTHRESHOLD_LSB (0x87) /* 0x89 SNR_PER_CARRIER_LSB */ #define SNR_PER_CARRIER_LSB (0x89) /* 0x8B SNRBELOWTHRESHOLD_LSB */ #define SNRBELOWTHRESHOLD_LSB (0x8B) /* 0x91 RF_AGC_VAL_1 */ #define RF_AGC_VAL_1 (0x91) /* 0x92 RF_AGC_STATUS */ #define RF_AGC_STATUS (0x92) /* 0x98 DIAG_CONFIG */ #define DIAG_CONFIG (0x98) #define DIAG_MASK (0x70) #define TB_SET (0x10) #define TRAN_SELECT (0x07) #define SERIAL_SELECT (0x01) /* 0x99 SUB_DIAG_MODE_SEL */ #define SUB_DIAG_MODE_SEL (0x99) #define CLKINVERSION (0x01) /* 0x9A TS_FORMAT */ #define TS_FORMAT (0x9A) #define ERROR_SENSE (0x08) #define VALID_SENSE (0x04) #define SYNC_SENSE (0x02) #define GATED_CLOCK (0x01) #define NXT6000ASICDEVICE (0x0b)
//=== tools/dsymutil/DebugMap.h - Generic debug map representation -*- C++ -*-// // // The LLVM Linker // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// /// /// \file /// /// This file contains the class declaration of the DebugMap /// entity. A DebugMap lists all the object files linked together to /// produce an executable along with the linked address of all the /// atoms used in these object files. /// The DebugMap is an input to the DwarfLinker class that will /// extract the Dwarf debug information from the referenced object /// files and link their usefull debug info together. /// //===----------------------------------------------------------------------===// #ifndef LLVM_TOOLS_DSYMUTIL_DEBUGMAP_H #define LLVM_TOOLS_DSYMUTIL_DEBUGMAP_H #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/Triple.h" #include "llvm/ADT/iterator_range.h" #include "llvm/Object/ObjectFile.h" #include "llvm/Support/Chrono.h" #include "llvm/Support/ErrorOr.h" #include "llvm/Support/Format.h" #include "llvm/Support/Path.h" #include "llvm/Support/YAMLTraits.h" #include <vector> namespace llvm { class raw_ostream; namespace dsymutil { class DebugMapObject; /// \brief The DebugMap object stores the list of object files to /// query for debug information along with the mapping between the /// symbols' addresses in the object file to their linked address in /// the linked binary. /// /// A DebugMap producer could look like this: /// DebugMap *DM = new DebugMap(); /// for (const auto &Obj: LinkedObjects) { /// DebugMapObject &DMO = DM->addDebugMapObject(Obj.getPath()); /// for (const auto &Sym: Obj.getLinkedSymbols()) /// DMO.addSymbol(Sym.getName(), Sym.getObjectFileAddress(), /// Sym.getBinaryAddress()); /// } /// /// A DebugMap consumer can then use the map to link the debug /// information. For example something along the lines of: /// for (const auto &DMO: DM->objects()) { /// auto Obj = createBinary(DMO.getObjectFilename()); /// for (auto &DIE: Obj.getDwarfDIEs()) { /// if (SymbolMapping *Sym = DMO.lookup(DIE.getName())) /// DIE.relocate(Sym->ObjectAddress, Sym->BinaryAddress); /// else /// DIE.discardSubtree(); /// } /// } class DebugMap { Triple BinaryTriple; std::string BinaryPath; typedef std::vector<std::unique_ptr<DebugMapObject>> ObjectContainer; ObjectContainer Objects; /// For YAML IO support. ///@{ friend yaml::MappingTraits<std::unique_ptr<DebugMap>>; friend yaml::MappingTraits<DebugMap>; DebugMap() = default; ///@} public: DebugMap(const Triple &BinaryTriple, StringRef BinaryPath) : BinaryTriple(BinaryTriple), BinaryPath(BinaryPath) {} typedef ObjectContainer::const_iterator const_iterator; iterator_range<const_iterator> objects() const { return make_range(begin(), end()); } const_iterator begin() const { return Objects.begin(); } const_iterator end() const { return Objects.end(); } /// This function adds an DebugMapObject to the list owned by this /// debug map. DebugMapObject & addDebugMapObject(StringRef ObjectFilePath, sys::TimePoint<std::chrono::seconds> Timestamp); const Triple &getTriple() const { return BinaryTriple; } StringRef getBinaryPath() const { return BinaryPath; } void print(raw_ostream &OS) const; #ifndef NDEBUG void dump() const; #endif /// Read a debug map for \a InputFile. static ErrorOr<std::vector<std::unique_ptr<DebugMap>>> parseYAMLDebugMap(StringRef InputFile, StringRef PrependPath, bool Verbose); }; /// \brief The DebugMapObject represents one object file described by /// the DebugMap. It contains a list of mappings between addresses in /// the object file and in the linked binary for all the linked atoms /// in this object file. class DebugMapObject { public: struct SymbolMapping { Optional<yaml::Hex64> ObjectAddress; yaml::Hex64 BinaryAddress; yaml::Hex32 Size; SymbolMapping(Optional<uint64_t> ObjectAddr, uint64_t BinaryAddress, uint32_t Size) : BinaryAddress(BinaryAddress), Size(Size) { if (ObjectAddr) ObjectAddress = *ObjectAddr; } /// For YAML IO support SymbolMapping() = default; }; typedef std::pair<std::string, SymbolMapping> YAMLSymbolMapping; typedef StringMapEntry<SymbolMapping> DebugMapEntry; /// \brief Adds a symbol mapping to this DebugMapObject. /// \returns false if the symbol was already registered. The request /// is discarded in this case. bool addSymbol(llvm::StringRef SymName, Optional<uint64_t> ObjectAddress, uint64_t LinkedAddress, uint32_t Size); /// \brief Lookup a symbol mapping. /// \returns null if the symbol isn't found. const DebugMapEntry *lookupSymbol(StringRef SymbolName) const; /// \brief Lookup an objectfile address. /// \returns null if the address isn't found. const DebugMapEntry *lookupObjectAddress(uint64_t Address) const; llvm::StringRef getObjectFilename() const { return Filename; } sys::TimePoint<std::chrono::seconds> getTimestamp() const { return Timestamp; } iterator_range<StringMap<SymbolMapping>::const_iterator> symbols() const { return make_range(Symbols.begin(), Symbols.end()); } void print(raw_ostream &OS) const; #ifndef NDEBUG void dump() const; #endif private: friend class DebugMap; /// DebugMapObjects can only be constructed by the owning DebugMap. DebugMapObject(StringRef ObjectFilename, sys::TimePoint<std::chrono::seconds> Timestamp); std::string Filename; sys::TimePoint<std::chrono::seconds> Timestamp; StringMap<SymbolMapping> Symbols; DenseMap<uint64_t, DebugMapEntry *> AddressToMapping; /// For YAMLIO support. ///@{ friend yaml::MappingTraits<dsymutil::DebugMapObject>; friend yaml::SequenceTraits<std::vector<std::unique_ptr<DebugMapObject>>>; DebugMapObject() = default; public: DebugMapObject(DebugMapObject &&) = default; DebugMapObject &operator=(DebugMapObject &&) = default; ///@} }; } } LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::dsymutil::DebugMapObject::YAMLSymbolMapping) namespace llvm { namespace yaml { using namespace llvm::dsymutil; template <> struct MappingTraits<std::pair<std::string, DebugMapObject::SymbolMapping>> { static void mapping(IO &io, std::pair<std::string, DebugMapObject::SymbolMapping> &s); static const bool flow = true; }; template <> struct MappingTraits<dsymutil::DebugMapObject> { struct YamlDMO; static void mapping(IO &io, dsymutil::DebugMapObject &DMO); }; template <> struct ScalarTraits<Triple> { static void output(const Triple &val, void *, llvm::raw_ostream &out); static StringRef input(StringRef scalar, void *, Triple &value); static bool mustQuote(StringRef) { return true; } }; template <> struct SequenceTraits<std::vector<std::unique_ptr<dsymutil::DebugMapObject>>> { static size_t size(IO &io, std::vector<std::unique_ptr<dsymutil::DebugMapObject>> &seq); static dsymutil::DebugMapObject & element(IO &, std::vector<std::unique_ptr<dsymutil::DebugMapObject>> &seq, size_t index); }; template <> struct MappingTraits<dsymutil::DebugMap> { static void mapping(IO &io, dsymutil::DebugMap &DM); }; template <> struct MappingTraits<std::unique_ptr<dsymutil::DebugMap>> { static void mapping(IO &io, std::unique_ptr<dsymutil::DebugMap> &DM); }; } } #endif // LLVM_TOOLS_DSYMUTIL_DEBUGMAP_H
/* Reading function for int Schemas. */ static PyObject* read_int_schema(Schema* schema, uint8_t* buf, uint8_t** pos, uint8_t* max) { long value; CHECK(handle_read_error(read_int(pos, max, &value)), error) #if PY_MAJOR_VERSION >= 3 return PyLong_FromLong((long)value); #else return PyInt_FromLong((long)value); #endif error: return NULL; }
/* addsym * * Adds a symbol to the symbol table (either global or local variables, * or global and local constants). */ symbol * addsym(char *name, cell addr, int ident, int vclass, int tag, int usage) { symbol entry, **refer; assert(!(ident == iFUNCTN || ident == iCONSTEXPR) || vclass != sGLOBAL || findglb(name) == NULL); assert(ident != iLABEL || findloc(name) == NULL); if (!(refer = (symbol **)malloc(sizeof(symbol *)))) { error(103); return NULL; } *refer = NULL; strcpy(entry.name, name); entry.hash = namehash(name); entry.addr = addr; entry.vclass = (char)vclass; entry.ident = (char)ident; entry.tag = tag; entry.usage = (char)usage; entry.compound = 0; entry.fnumber = -1; entry.numrefers = 1; entry.refer = refer; entry.parent = NULL; if (vclass == sGLOBAL) return add_symbol(&glbtab, &entry, TRUE); else return add_symbol(&loctab, &entry, FALSE); }
/** * Add elements into FIFO buffer. * * :param buff: Pointer to the buffer :c:type:`fifo_buffer`. * :param elements: Array of pointer that should be added to the buffer. * :param N: Size of the array. * :return: Error code according to :c:type:`fifo_errors`. */ enum fifo_errors fifo_add_elements(struct fifo_buffer *buff, stored_data_t elements[], buff_int_t N) { if (buff->is_full) return FIFO_FULL; if (buff->max_size < N) return FIFO_TOO_SMALL; buff_int_t el_left = buff->max_size - fifo_size(buff); if (el_left < N) return FIFO_TOO_SMALL; for (buff_int_t i = 0; i < N; i++) { buff_int_t buff_i = (buff->last_el + i) % buff->max_size; buff->start_addr[buff_i] = elements[i]; } buff->last_el = (buff->last_el + N) % buff->max_size; if (buff->first_el == buff->last_el) buff->is_full = true; return FIFO_OK; }
/* try to delete object, fail if it is still in use. */ static int nfnl_acct_try_del(struct nf_acct *cur) { int ret = 0; if (refcount_dec_if_one(&cur->refcnt)) { list_del_rcu(&cur->head); kfree_rcu(cur, rcu_head); } else { ret = -EBUSY; } return ret; }
/* A special case: we have no dbg, no alloc header etc. So create something out of thin air that we can recognize in dwarf_dealloc. Something with the prefix (prefix space hidden from caller). Only applies to DW_DLA_ERROR, making up an error record. */ struct Dwarf_Error_s * _dwarf_special_no_dbg_error_malloc(void) { union u { Dwarf_Alloc_Area ptr_not_used; struct Dwarf_Error_s base_not_used; char data_space[sizeof(struct Dwarf_Error_s) + (_DW_RESERVE * 2)]; }; char *mem; mem = malloc(sizeof(union u)); if (mem == 0) { return 0; } memset(mem,0, sizeof(union u)); mem += _DW_RESERVE; return (struct Dwarf_Error_s *) mem; }
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 8 -*- */ /* * This file is part of The Croco Library * * Copyright (C) 2002-2003 Dodji Seketeli <dodji@seketeli.org> * * This program is free software; you can redistribute it and/or * modify it under the terms of version 3 of the GNU General Public * License as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ /* *$Id: cr-enc-handler.h,v 1.6 2005/05/10 19:48:56 dodji Exp $ */ /** *@file: *The declaration of the #CREncHandler class. * */ #ifndef __CR_ENC_HANDLER_H__ #define __CR_ENC_HANDLER_H__ #include "cr-utils.h" G_BEGIN_DECLS typedef struct _CREncHandler CREncHandler ; typedef enum CRStatus (*CREncInputFunc) (const guchar * a_in, gulong *a_in_len, guchar *a_out, gulong *a_out_len) ; typedef enum CRStatus (*CREncOutputFunc) (const guchar * a_in, gulong *a_in_len, guchar *a_out, gulong *a_out_len) ; typedef enum CRStatus (*CREncInputStrLenAsUtf8Func) (const guchar *a_in_start, const guchar *a_in_end, gulong *a_in_size); typedef enum CRStatus (*CREncUtf8StrLenAsOutputFunc) (const guchar *a_in_start, const guchar *a_in_end, gulong *a_in_size) ; /** *This class is responsible of the *the encoding conversions stuffs in *libcroco. */ struct _CREncHandler { enum CREncoding encoding ; CREncInputFunc decode_input ; CREncInputFunc encode_output ; CREncInputStrLenAsUtf8Func enc_str_len_as_utf8 ; CREncUtf8StrLenAsOutputFunc utf8_str_len_as_enc ; } ; CREncHandler * cr_enc_handler_get_instance (enum CREncoding a_enc) ; enum CRStatus cr_enc_handler_resolve_enc_alias (const guchar *a_alias_name, enum CREncoding *a_enc) ; enum CRStatus cr_enc_handler_convert_input (CREncHandler *a_this, const guchar *a_in, gulong *a_in_len, guchar **a_out, gulong *a_out_len) ; G_END_DECLS #endif /*__CR_ENC_HANDLER_H__*/
/* ensure buffer pointed to by `*buf` can stomach at least `minsz` bytes */ void growbuf(char **buf, size_t *bufsz, size_t minsz) { if (minsz < *bufsz) return; size_t nsz = *bufsz; while (nsz < minsz) nsz *= 2; *buf = xrealloc(*buf, nsz); *bufsz = nsz; return; }
/* build "status change" packet (one or two bytes) from HC registers */ static int ehci_hub_status_data (struct usb_hcd *hcd, char *buf) { struct ehci_hcd *ehci = hcd_to_ehci (hcd); u32 temp, status = 0; int ports, i, retval = 1; unsigned long flags; buf [0] = 0; ports = HCS_N_PORTS (ehci->hcs_params); if (ports > 7) { buf [1] = 0; retval++; } spin_lock_irqsave (&ehci->lock, flags); for (i = 0; i < ports; i++) { temp = readl (&ehci->regs->port_status [i]); if (temp & PORT_OWNER) { if (temp & PORT_CSC) { temp &= ~PORT_CSC; writel (temp, &ehci->regs->port_status [i]); } continue; } if (!(temp & PORT_CONNECT)) ehci->reset_done [i] = 0; if ((temp & (PORT_CSC | PORT_PEC | PORT_OCC)) != 0) { if (i < 7) buf [0] |= 1 << (i + 1); else buf [1] |= 1 << (i - 7); status = STS_PCD; } } spin_unlock_irqrestore (&ehci->lock, flags); return status ? retval : 0; }
/** * @brief Connect a port to another port. * Connect a target port to a source port so that the target port will * receive messages sent from the source port. * @public @memberof MIDIPort * @param port The source port. * @param target The target port. */ int MIDIPortConnect( struct MIDIPort * port, struct MIDIPort * target ) { MIDIPrecond( port != NULL, EFAULT ); MIDIPrecond( target != NULL , EINVAL ); return MIDIListAdd( port->ports, target ); }
/** * Go to the next logo and return its pointer. */ static logo_t *LogoListNext( logo_list_t *p_list, mtime_t i_date ) { p_list->i_counter = ( p_list->i_counter + 1 ) % p_list->i_count; logo_t *p_logo = LogoListCurrent( p_list ); p_list->i_next_pic = i_date + ( p_logo->i_delay != -1 ? p_logo->i_delay : p_list->i_delay ) * 1000; return p_logo; }
#include <stdio.h> #include <stdlib.h> int main() { int n; scanf("%i",&n); int arr[n]; int i; for(i=0;i<n;i++) scanf("%i",&arr[i]); int min = arr[0], max = arr[0]; int minp =0, maxp =0; for(i=0;i<n;i++) { if(arr[i] > max) { max = arr[i]; maxp = i; } if(arr[i] <= min) { min = arr[i]; minp = i; } } int total = 0; total += (n-1)-minp; total += maxp; if(maxp > minp) total -= 1; printf("%i",total); }
/* * spacc_symc_addbuf - add a flags to the last valid nodes. */ int spacc_symc_addctrl(unsigned int chn_num, spacc_buf_type_en type, unsigned int ctrl) { struct spacc_symc_context *info = &g_symc_context[chn_num]; unsigned int id; spacc_value_return_if_max(chn_num, SPACC_LOGIC_MAX_CHN); switch (type) { case SPACC_BUF_TYPE_SYMC_IN: id = (info->symc_cur_in_nodes == 0) ? SPACC_MAX_DEPTH - 1 : info->symc_cur_in_nodes - 1; info->entry_symc_in[id].sym_ctrl |= ctrl; break; case SPACC_BUF_TYPE_SYMC_OUT: id = (info->symc_cur_out_nodes == 0) ? SPACC_MAX_DEPTH - 1 : info->symc_cur_out_nodes - 1; info->entry_symc_out[id].aes_ctrl |= ctrl; break; default: return SPACC_ERR_INVALID_PARAM; } return SPACC_OK; }
// GENERATED FILE - DO NOT EDIT. // Generated by gen_extensions.py using data from registry_xml.py and gl.xml // // Copyright 2021 The ANGLE Project Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // // gles_extensions_autogen.h: GLES extension information. #ifndef LIBANGLE_GLES_EXTENSIONS_AUTOGEN_H_ #define LIBANGLE_GLES_EXTENSIONS_AUTOGEN_H_ namespace gl { class TextureCapsMap; struct Extensions { Extensions(); Extensions(const Extensions &other); Extensions &operator=(const Extensions &other); // Generate a vector of supported extension strings std::vector<std::string> getStrings() const; // Set all texture related extension support based on the supported textures. // Determines support for: // GL_OES_packed_depth_stencil // GL_OES_rgb8_rgba8 // GL_EXT_texture_format_BGRA8888 // GL_EXT_color_buffer_half_float, // GL_OES_texture_half_float, GL_OES_texture_half_float_linear // GL_OES_texture_float, GL_OES_texture_float_linear // GL_EXT_texture_rg // GL_EXT_texture_type_2_10_10_10_REV // GL_EXT_texture_compression_dxt1, GL_ANGLE_texture_compression_dxt3, // GL_ANGLE_texture_compression_dxt5 // GL_KHR_texture_compression_astc_ldr, GL_OES_texture_compression_astc. // NOTE: GL_KHR_texture_compression_astc_hdr must be enabled separately. Support for the // HDR profile cannot be determined from the format enums alone. // GL_OES_compressed_ETC1_RGB8_texture // GL_EXT_sRGB // GL_ANGLE_depth_texture, GL_OES_depth32 // GL_EXT_color_buffer_float // GL_EXT_texture_norm16 // GL_EXT_texture_compression_bptc // GL_EXT_texture_compression_rgtc void setTextureExtensionSupport(const TextureCapsMap &textureCaps); // Helper functions bool clipCullDistanceAny() const { return (clipCullDistanceANGLE || clipCullDistanceEXT); } bool copyImageAny() const { return (copyImageEXT || copyImageOES); } bool depthTextureAny() const { return (depthTextureANGLE || depthTextureOES); } bool drawBuffersIndexedAny() const { return (drawBuffersIndexedEXT || drawBuffersIndexedOES); } bool drawElementsBaseVertexAny() const { return (drawElementsBaseVertexEXT || drawElementsBaseVertexOES); } bool framebufferBlitAny() const { return (framebufferBlitANGLE || framebufferBlitNV); } bool geometryShaderAny() const { return (geometryShaderEXT || geometryShaderOES); } bool instancedArraysAny() const { return (instancedArraysANGLE || instancedArraysEXT); } bool polygonModeAny() const { return (polygonModeANGLE || polygonModeNV); } bool primitiveBoundingBoxAny() const { return (primitiveBoundingBoxEXT || primitiveBoundingBoxOES); } bool shaderFramebufferFetchAny() const { return (shaderFramebufferFetchARM || shaderFramebufferFetchEXT); } bool shaderIoBlocksAny() const { return (shaderIoBlocksEXT || shaderIoBlocksOES); } bool textureBorderClampAny() const { return (textureBorderClampEXT || textureBorderClampOES); } bool textureBufferAny() const { return (textureBufferEXT || textureBufferOES); } bool textureCubeMapArrayAny() const { return (textureCubeMapArrayEXT || textureCubeMapArrayOES); } // GLES 2.0+ extensions // -------------------- // GL_EXT_base_instance bool baseInstanceEXT = false; // GL_KHR_blend_equation_advanced bool blendEquationAdvancedKHR = false; // GL_EXT_blend_func_extended bool blendFuncExtendedEXT = false; // GL_EXT_blend_minmax bool blendMinmaxEXT = false; // GL_EXT_buffer_storage bool bufferStorageEXT = false; // GL_EXT_clip_control bool clipControlEXT = false; // GL_EXT_clip_cull_distance bool clipCullDistanceEXT = false; // GL_APPLE_clip_distance bool clipDistanceAPPLE = false; // GL_EXT_color_buffer_float bool colorBufferFloatEXT = false; // GL_EXT_color_buffer_half_float bool colorBufferHalfFloatEXT = false; // GL_OES_compressed_EAC_R11_signed_texture bool compressedEACR11SignedTextureOES = false; // GL_OES_compressed_EAC_R11_unsigned_texture bool compressedEACR11UnsignedTextureOES = false; // GL_OES_compressed_EAC_RG11_signed_texture bool compressedEACRG11SignedTextureOES = false; // GL_OES_compressed_EAC_RG11_unsigned_texture bool compressedEACRG11UnsignedTextureOES = false; // GL_EXT_compressed_ETC1_RGB8_sub_texture bool compressedETC1RGB8SubTextureEXT = false; // GL_OES_compressed_ETC1_RGB8_texture bool compressedETC1RGB8TextureOES = false; // GL_OES_compressed_ETC2_punchthroughA_RGBA8_texture bool compressedETC2PunchthroughARGBA8TextureOES = false; // GL_OES_compressed_ETC2_punchthroughA_sRGB8_alpha_texture bool compressedETC2PunchthroughASRGB8AlphaTextureOES = false; // GL_OES_compressed_ETC2_RGB8_texture bool compressedETC2RGB8TextureOES = false; // GL_OES_compressed_ETC2_RGBA8_texture bool compressedETC2RGBA8TextureOES = false; // GL_OES_compressed_ETC2_sRGB8_alpha8_texture bool compressedETC2SRGB8Alpha8TextureOES = false; // GL_OES_compressed_ETC2_sRGB8_texture bool compressedETC2SRGB8TextureOES = false; // GL_OES_compressed_paletted_texture bool compressedPalettedTextureOES = false; // GL_EXT_conservative_depth bool conservativeDepthEXT = false; // GL_EXT_copy_image bool copyImageEXT = false; // GL_OES_copy_image bool copyImageOES = false; // GL_KHR_debug bool debugKHR = false; // GL_EXT_debug_label bool debugLabelEXT = false; // GL_EXT_debug_marker bool debugMarkerEXT = false; // GL_OES_depth24 bool depth24OES = false; // GL_OES_depth32 bool depth32OES = false; // GL_NV_depth_buffer_float2 bool depthBufferFloat2NV = false; // GL_EXT_depth_clamp bool depthClampEXT = false; // GL_ANGLE_depth_texture bool depthTextureANGLE = false; // GL_OES_depth_texture bool depthTextureOES = false; // GL_OES_depth_texture_cube_map bool depthTextureCubeMapOES = false; // GL_EXT_discard_framebuffer bool discardFramebufferEXT = false; // GL_EXT_disjoint_timer_query bool disjointTimerQueryEXT = false; // GL_EXT_draw_buffers bool drawBuffersEXT = false; // GL_EXT_draw_buffers_indexed bool drawBuffersIndexedEXT = false; // GL_OES_draw_buffers_indexed bool drawBuffersIndexedOES = false; // GL_EXT_draw_elements_base_vertex bool drawElementsBaseVertexEXT = false; // GL_OES_draw_elements_base_vertex bool drawElementsBaseVertexOES = false; // GL_OES_EGL_image bool EGLImageOES = false; // GL_EXT_EGL_image_array bool EGLImageArrayEXT = false; // GL_OES_EGL_image_external bool EGLImageExternalOES = false; // GL_OES_EGL_image_external_essl3 bool EGLImageExternalEssl3OES = false; // GL_EXT_EGL_image_external_wrap_modes bool EGLImageExternalWrapModesEXT = false; // GL_EXT_EGL_image_storage bool EGLImageStorageEXT = false; // GL_NV_EGL_stream_consumer_external bool EGLStreamConsumerExternalNV = false; // GL_OES_EGL_sync bool EGLSyncOES = false; // GL_OES_element_index_uint bool elementIndexUintOES = false; // GL_ANDROID_extension_pack_es31a bool extensionPackEs31aANDROID = false; // GL_EXT_external_buffer bool externalBufferEXT = false; // GL_OES_fbo_render_mipmap bool fboRenderMipmapOES = false; // GL_NV_fence bool fenceNV = false; // GL_EXT_float_blend bool floatBlendEXT = false; // GL_EXT_frag_depth bool fragDepthEXT = false; // GL_ANGLE_framebuffer_blit bool framebufferBlitANGLE = false; // GL_NV_framebuffer_blit bool framebufferBlitNV = false; // GL_MESA_framebuffer_flip_y bool framebufferFlipYMESA = false; // GL_EXT_geometry_shader bool geometryShaderEXT = false; // GL_OES_geometry_shader bool geometryShaderOES = false; // GL_OES_get_program_binary bool getProgramBinaryOES = false; // GL_EXT_gpu_shader5 bool gpuShader5EXT = false; // GL_ANGLE_instanced_arrays bool instancedArraysANGLE = false; // GL_EXT_instanced_arrays bool instancedArraysEXT = false; // GL_OES_mapbuffer bool mapbufferOES = false; // GL_EXT_map_buffer_range bool mapBufferRangeEXT = false; // GL_EXT_memory_object bool memoryObjectEXT = false; // GL_EXT_memory_object_fd bool memoryObjectFdEXT = false; // GL_EXT_multi_draw_indirect bool multiDrawIndirectEXT = false; // GL_EXT_multisample_compatibility bool multisampleCompatibilityEXT = false; // GL_EXT_multisampled_render_to_texture bool multisampledRenderToTextureEXT = false; // GL_EXT_multisampled_render_to_texture2 bool multisampledRenderToTexture2EXT = false; // GL_OVR_multiview bool multiviewOVR = false; // GL_OVR_multiview2 bool multiview2OVR = false; // GL_KHR_no_error bool noErrorKHR = false; // GL_EXT_occlusion_query_boolean bool occlusionQueryBooleanEXT = false; // GL_OES_packed_depth_stencil bool packedDepthStencilOES = false; // GL_ANGLE_pack_reverse_row_order bool packReverseRowOrderANGLE = false; // GL_NV_pack_subimage bool packSubimageNV = false; // GL_KHR_parallel_shader_compile bool parallelShaderCompileKHR = false; // GL_AMD_performance_monitor bool performanceMonitorAMD = false; // GL_NV_pixel_buffer_object bool pixelBufferObjectNV = false; // GL_NV_polygon_mode bool polygonModeNV = false; // GL_EXT_polygon_offset_clamp bool polygonOffsetClampEXT = false; // GL_EXT_primitive_bounding_box bool primitiveBoundingBoxEXT = false; // GL_OES_primitive_bounding_box bool primitiveBoundingBoxOES = false; // GL_EXT_protected_textures bool protectedTexturesEXT = false; // GL_EXT_pvrtc_sRGB bool pvrtcSRGBEXT = false; // GL_NV_read_depth bool readDepthNV = false; // GL_NV_read_depth_stencil bool readDepthStencilNV = false; // GL_EXT_read_format_bgra bool readFormatBgraEXT = false; // GL_NV_read_stencil bool readStencilNV = false; // GL_QCOM_render_shared_exponent bool renderSharedExponentQCOM = false; // GL_EXT_render_snorm bool renderSnormEXT = false; // GL_OES_rgb8_rgba8 bool rgb8Rgba8OES = false; // GL_KHR_robust_buffer_access_behavior bool robustBufferAccessBehaviorKHR = false; // GL_EXT_robustness bool robustnessEXT = false; // GL_NV_robustness_video_memory_purge bool robustnessVideoMemoryPurgeNV = false; // GL_OES_sample_shading bool sampleShadingOES = false; // GL_OES_sample_variables bool sampleVariablesOES = false; // GL_EXT_semaphore bool semaphoreEXT = false; // GL_EXT_semaphore_fd bool semaphoreFdEXT = false; // GL_EXT_separate_shader_objects bool separateShaderObjectsEXT = false; // GL_ARM_shader_framebuffer_fetch bool shaderFramebufferFetchARM = false; // GL_EXT_shader_framebuffer_fetch bool shaderFramebufferFetchEXT = false; // GL_EXT_shader_framebuffer_fetch_non_coherent bool shaderFramebufferFetchNonCoherentEXT = false; // GL_OES_shader_image_atomic bool shaderImageAtomicOES = false; // GL_EXT_shader_io_blocks bool shaderIoBlocksEXT = false; // GL_OES_shader_io_blocks bool shaderIoBlocksOES = false; // GL_OES_shader_multisample_interpolation bool shaderMultisampleInterpolationOES = false; // GL_EXT_shader_non_constant_global_initializers bool shaderNonConstantGlobalInitializersEXT = false; // GL_NV_shader_noperspective_interpolation bool shaderNoperspectiveInterpolationNV = false; // GL_EXT_shader_texture_lod bool shaderTextureLodEXT = false; // GL_QCOM_shading_rate bool shadingRateQCOM = false; // GL_EXT_shadow_samplers bool shadowSamplersEXT = false; // GL_EXT_sRGB bool sRGBEXT = false; // GL_EXT_sRGB_write_control bool sRGBWriteControlEXT = false; // GL_OES_standard_derivatives bool standardDerivativesOES = false; // GL_OES_surfaceless_context bool surfacelessContextOES = false; // GL_ARB_sync bool syncARB = false; // GL_EXT_tessellation_shader bool tessellationShaderEXT = false; // GL_OES_texture_3D bool texture3DOES = false; // GL_EXT_texture_border_clamp bool textureBorderClampEXT = false; // GL_OES_texture_border_clamp bool textureBorderClampOES = false; // GL_EXT_texture_buffer bool textureBufferEXT = false; // GL_OES_texture_buffer bool textureBufferOES = false; // GL_OES_texture_compression_astc bool textureCompressionAstcOES = false; // GL_KHR_texture_compression_astc_hdr bool textureCompressionAstcHdrKHR = false; // GL_KHR_texture_compression_astc_ldr bool textureCompressionAstcLdrKHR = false; // GL_KHR_texture_compression_astc_sliced_3d bool textureCompressionAstcSliced3dKHR = false; // GL_EXT_texture_compression_bptc bool textureCompressionBptcEXT = false; // GL_EXT_texture_compression_dxt1 bool textureCompressionDxt1EXT = false; // GL_IMG_texture_compression_pvrtc bool textureCompressionPvrtcIMG = false; // GL_IMG_texture_compression_pvrtc2 bool textureCompressionPvrtc2IMG = false; // GL_EXT_texture_compression_rgtc bool textureCompressionRgtcEXT = false; // GL_EXT_texture_compression_s3tc bool textureCompressionS3tcEXT = false; // GL_EXT_texture_compression_s3tc_srgb bool textureCompressionS3tcSrgbEXT = false; // GL_EXT_texture_cube_map_array bool textureCubeMapArrayEXT = false; // GL_OES_texture_cube_map_array bool textureCubeMapArrayOES = false; // GL_EXT_texture_filter_anisotropic bool textureFilterAnisotropicEXT = false; // GL_EXT_texture_filter_minmax bool textureFilterMinmaxEXT = false; // GL_OES_texture_float bool textureFloatOES = false; // GL_OES_texture_float_linear bool textureFloatLinearOES = false; // GL_EXT_texture_format_BGRA8888 bool textureFormatBGRA8888EXT = false; // GL_EXT_texture_format_sRGB_override bool textureFormatSRGBOverrideEXT = false; // GL_OES_texture_half_float bool textureHalfFloatOES = false; // GL_OES_texture_half_float_linear bool textureHalfFloatLinearOES = false; // GL_EXT_texture_mirror_clamp_to_edge bool textureMirrorClampToEdgeEXT = false; // GL_EXT_texture_norm16 bool textureNorm16EXT = false; // GL_OES_texture_npot bool textureNpotOES = false; // GL_EXT_texture_rg bool textureRgEXT = false; // GL_EXT_texture_sRGB_decode bool textureSRGBDecodeEXT = false; // GL_EXT_texture_sRGB_R8 bool textureSRGBR8EXT = false; // GL_EXT_texture_sRGB_RG8 bool textureSRGBRG8EXT = false; // GL_OES_texture_stencil8 bool textureStencil8OES = false; // GL_EXT_texture_storage bool textureStorageEXT = false; // GL_OES_texture_storage_multisample_2d_array bool textureStorageMultisample2dArrayOES = false; // GL_EXT_texture_type_2_10_10_10_REV bool textureType2101010REVEXT = false; // GL_ANGLE_texture_usage bool textureUsageANGLE = false; // GL_ANGLE_translated_shader_source bool translatedShaderSourceANGLE = false; // GL_EXT_unpack_subimage bool unpackSubimageEXT = false; // GL_OES_vertex_array_object bool vertexArrayObjectOES = false; // GL_OES_vertex_half_float bool vertexHalfFloatOES = false; // GL_OES_vertex_type_10_10_10_2 bool vertexType1010102OES = false; // GL_WEBGL_video_texture bool videoTextureWEBGL = false; // GL_EXT_YUV_target bool YUVTargetEXT = false; // ANGLE unofficial extensions // --------------------------- // GL_ANGLE_base_vertex_base_instance bool baseVertexBaseInstanceANGLE = false; // GL_ANGLE_base_vertex_base_instance_shader_builtin bool baseVertexBaseInstanceShaderBuiltinANGLE = false; // GL_CHROMIUM_bind_generates_resource bool bindGeneratesResourceCHROMIUM = false; // GL_CHROMIUM_bind_uniform_location bool bindUniformLocationCHROMIUM = false; // GL_ANGLE_client_arrays bool clientArraysANGLE = false; // GL_ANGLE_clip_cull_distance bool clipCullDistanceANGLE = false; // GL_CHROMIUM_color_buffer_float_rgb bool colorBufferFloatRgbCHROMIUM = false; // GL_CHROMIUM_color_buffer_float_rgba bool colorBufferFloatRgbaCHROMIUM = false; // GL_ANGLE_compressed_texture_etc bool compressedTextureEtcANGLE = false; // GL_CHROMIUM_copy_compressed_texture bool copyCompressedTextureCHROMIUM = false; // GL_CHROMIUM_copy_texture bool copyTextureCHROMIUM = false; // GL_ANGLE_copy_texture_3d bool copyTexture3dANGLE = false; // GL_CHROMIUM_framebuffer_mixed_samples bool framebufferMixedSamplesCHROMIUM = false; // GL_ANGLE_framebuffer_multisample bool framebufferMultisampleANGLE = false; // GL_ANGLE_get_image bool getImageANGLE = false; // GL_ANGLE_get_serialized_context_string bool getSerializedContextStringANGLE = false; // GL_ANGLE_get_tex_level_parameter bool getTexLevelParameterANGLE = false; // GL_ANGLE_logic_op bool logicOpANGLE = false; // GL_CHROMIUM_lose_context bool loseContextCHROMIUM = false; // GL_ANGLE_lossy_etc_decode bool lossyEtcDecodeANGLE = false; // GL_ANGLE_memory_object_flags bool memoryObjectFlagsANGLE = false; // GL_ANGLE_memory_object_fuchsia bool memoryObjectFuchsiaANGLE = false; // GL_ANGLE_memory_size bool memorySizeANGLE = false; // GL_ANGLE_multi_draw bool multiDrawANGLE = false; // GL_ANGLE_multiview_multisample bool multiviewMultisampleANGLE = false; // GL_ANGLE_polygon_mode bool polygonModeANGLE = false; // GL_ANGLE_program_binary bool programBinaryANGLE = false; // GL_ANGLE_program_cache_control bool programCacheControlANGLE = false; // GL_ANGLE_provoking_vertex bool provokingVertexANGLE = false; // GL_ANGLE_read_only_depth_stencil_feedback_loops bool readOnlyDepthStencilFeedbackLoopsANGLE = false; // GL_ANGLE_relaxed_vertex_attribute_type bool relaxedVertexAttributeTypeANGLE = false; // GL_ANGLE_renderability_validation bool renderabilityValidationANGLE = false; // GL_ANGLE_request_extension bool requestExtensionANGLE = false; // GL_ANGLE_rgbx_internal_format bool rgbxInternalFormatANGLE = false; // GL_ANGLE_robust_client_memory bool robustClientMemoryANGLE = false; // GL_ANGLE_robust_fragment_shader_output bool robustFragmentShaderOutputANGLE = false; // GL_ANGLE_robust_resource_initialization bool robustResourceInitializationANGLE = false; // GL_ANGLE_semaphore_fuchsia bool semaphoreFuchsiaANGLE = false; // GL_ANGLE_shader_binary bool shaderBinaryANGLE = false; // GL_ANGLE_shader_pixel_local_storage bool shaderPixelLocalStorageANGLE = false; // GL_ANGLE_shader_pixel_local_storage_coherent bool shaderPixelLocalStorageCoherentANGLE = false; // GL_ANGLE_stencil_texturing bool stencilTexturingANGLE = false; // GL_CHROMIUM_sync_query bool syncQueryCHROMIUM = false; // GL_ANGLE_texture_compression_dxt3 bool textureCompressionDxt3ANGLE = false; // GL_ANGLE_texture_compression_dxt5 bool textureCompressionDxt5ANGLE = false; // GL_ANGLE_texture_external_update bool textureExternalUpdateANGLE = false; // GL_CHROMIUM_texture_filtering_hint bool textureFilteringHintCHROMIUM = false; // GL_ANGLE_texture_multisample bool textureMultisampleANGLE = false; // GL_ANGLE_texture_rectangle bool textureRectangleANGLE = false; // GL_ANGLE_vulkan_image bool vulkanImageANGLE = false; // GL_ANGLE_webgl_compatibility bool webglCompatibilityANGLE = false; // GL_ANGLE_yuv_internal_format bool yuvInternalFormatANGLE = false; // GLES 1.0 and 1.1 extensions // --------------------------- // GL_OES_draw_texture bool drawTextureOES = false; // GL_OES_framebuffer_object bool framebufferObjectOES = false; // GL_OES_matrix_palette bool matrixPaletteOES = false; // GL_OES_point_size_array bool pointSizeArrayOES = false; // GL_OES_point_sprite bool pointSpriteOES = false; // GL_OES_query_matrix bool queryMatrixOES = false; // GL_OES_texture_cube_map bool textureCubeMapOES = false; }; } // namespace gl #endif // LIBANGLE_GLES_EXTENSIONS_AUTOGEN_H_
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #ifndef nsXULPrototypeCache_h__ #define nsXULPrototypeCache_h__ #include "nsBaseHashtable.h" #include "nsCOMPtr.h" #include "nsIObserver.h" #include "nsInterfaceHashtable.h" #include "nsRefPtrHashtable.h" #include "nsURIHashKey.h" #include "nsXULPrototypeDocument.h" #include "nsIStorageStream.h" #include "mozilla/scache/StartupCache.h" #include "js/experimental/JSStencil.h" #include "mozilla/RefPtr.h" class nsIHandleReportCallback; namespace mozilla { class StyleSheet; } // namespace mozilla /** * The XUL prototype cache can be used to store and retrieve shared data for * XUL documents, style sheets, XBL, and scripts. * * The cache has two levels: * 1. In-memory hashtables * 2. The on-disk cache file. */ class nsXULPrototypeCache : public nsIObserver { public: enum class CacheType { Prototype, Script }; // nsISupports NS_DECL_THREADSAFE_ISUPPORTS NS_DECL_NSIOBSERVER bool IsCached(nsIURI* aURI) { return GetPrototype(aURI) != nullptr; } void AbortCaching(); /** * Whether the prototype cache is enabled. */ bool IsEnabled(); /** * Flush the cache; remove all XUL prototype documents, style * sheets, and scripts. */ void Flush(); // The following methods are used to put and retrive various items into and // from the cache. nsXULPrototypeDocument* GetPrototype(nsIURI* aURI); nsresult PutPrototype(nsXULPrototypeDocument* aDocument); JS::Stencil* GetStencil(nsIURI* aURI); nsresult PutStencil(nsIURI* aURI, JS::Stencil* aStencil); /** * Write the XUL prototype document to a cache file. The proto must be * fully loaded. */ nsresult WritePrototype(nsXULPrototypeDocument* aPrototypeDocument); /** * This interface allows partial reads and writes from the buffers in the * startupCache. */ inline nsresult GetPrototypeInputStream(nsIURI* aURI, nsIObjectInputStream** objectInput) { return GetInputStream(CacheType::Prototype, aURI, objectInput); } inline nsresult GetScriptInputStream(nsIURI* aURI, nsIObjectInputStream** objectInput) { return GetInputStream(CacheType::Script, aURI, objectInput); } inline nsresult FinishScriptInputStream(nsIURI* aURI) { return FinishInputStream(aURI); } inline nsresult GetPrototypeOutputStream( nsIURI* aURI, nsIObjectOutputStream** objectOutput) { return GetOutputStream(aURI, objectOutput); } inline nsresult GetScriptOutputStream(nsIURI* aURI, nsIObjectOutputStream** objectOutput) { return GetOutputStream(aURI, objectOutput); } inline nsresult FinishPrototypeOutputStream(nsIURI* aURI) { return FinishOutputStream(CacheType::Prototype, aURI); } inline nsresult FinishScriptOutputStream(nsIURI* aURI) { return FinishOutputStream(CacheType::Script, aURI); } inline nsresult HasPrototype(nsIURI* aURI, bool* exists) { return HasData(CacheType::Prototype, aURI, exists); } inline nsresult HasScript(nsIURI* aURI, bool* exists) { return HasData(CacheType::Script, aURI, exists); } private: nsresult GetInputStream(CacheType cacheType, nsIURI* uri, nsIObjectInputStream** stream); nsresult FinishInputStream(nsIURI* aURI); nsresult GetOutputStream(nsIURI* aURI, nsIObjectOutputStream** objectOutput); nsresult FinishOutputStream(CacheType cacheType, nsIURI* aURI); nsresult HasData(CacheType cacheType, nsIURI* aURI, bool* exists); public: static nsXULPrototypeCache* GetInstance(); static nsXULPrototypeCache* MaybeGetInstance() { return sInstance; } static void ReleaseGlobals() { NS_IF_RELEASE(sInstance); } void MarkInCCGeneration(uint32_t aGeneration); static void CollectMemoryReports(nsIHandleReportCallback* aHandleReport, nsISupports* aData); protected: friend nsresult NS_NewXULPrototypeCache(REFNSIID aIID, void** aResult); nsXULPrototypeCache(); virtual ~nsXULPrototypeCache() = default; static nsXULPrototypeCache* sInstance; nsRefPtrHashtable<nsURIHashKey, nsXULPrototypeDocument> mPrototypeTable; // owns the prototypes class StencilHashKey : public nsURIHashKey { public: explicit StencilHashKey(const nsIURI* aKey) : nsURIHashKey(aKey) {} StencilHashKey(StencilHashKey&&) = default; RefPtr<JS::Stencil> mStencil; }; nsTHashtable<StencilHashKey> mStencilTable; // URIs already written to the startup cache, to prevent double-caching. nsTHashtable<nsURIHashKey> mStartupCacheURITable; nsInterfaceHashtable<nsURIHashKey, nsIStorageStream> mOutputStreamTable; nsInterfaceHashtable<nsURIHashKey, nsIObjectInputStream> mInputStreamTable; // Bootstrap caching service nsresult BeginCaching(nsIURI* aDocumentURI); }; #endif // nsXULPrototypeCache_h__
/* In the following three functions, the caller must hold hdev's lock */ int usb_hub_claim_port(struct usb_device *hdev, unsigned port1, struct dev_state *owner) { int rc; struct dev_state **powner; rc = find_port_owner(hdev, port1, &powner); if (rc) return rc; if (*powner) return -EBUSY; *powner = owner; return rc; }
/** * @brief Increment the counter for the given query type. * * @param query_type indicate the type of record being resolved (A, AAAA, or other). */ void incrementQueryTypeCount(const uint16_t query_type) { switch (query_type) { case DNS_RECORD_TYPE_A: config_->stats().a_record_queries_.inc(); break; case DNS_RECORD_TYPE_AAAA: config_->stats().aaaa_record_queries_.inc(); break; case DNS_RECORD_TYPE_SRV: config_->stats().srv_record_queries_.inc(); break; default: config_->stats().unsupported_queries_.inc(); break; } }
/************************************************************************** * Convert a given matrix to or from logs. **************************************************************************/ void convert_to_from_log_matrix (bool to_log, MATRIX_T* source_matrix, MATRIX_T* target_matrix) { int num_rows; int i_row; num_rows = get_num_rows(source_matrix); for (i_row = 0; i_row < num_rows; i_row++) { convert_to_from_log_array(to_log, get_matrix_row(i_row, source_matrix), get_matrix_row(i_row, target_matrix)); } }
/** * Copyright 2013-2023 Software Radio Systems Limited * * This file is part of srsRAN. * * srsRAN is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of * the License, or (at your option) any later version. * * srsRAN is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * A copy of the GNU Affero General Public License can be found in * the LICENSE file in the top-level directory of this distribution * and at http://www.gnu.org/licenses/. * */ #ifndef SRSENB_RRC_MOBILITY_H #define SRSENB_RRC_MOBILITY_H #include "rrc.h" #include "rrc_ue.h" #include "srsran/adt/fsm.h" #include <map> namespace srsenb { enum class ho_interface_t { S1, X2, intra_enb }; class rrc::ue::rrc_mobility : public srsran::fsm_t<rrc::ue::rrc_mobility> { public: // public events struct user_crnti_upd_ev { uint16_t crnti; uint16_t temp_crnti; }; struct ho_cancel_ev { asn1::s1ap::cause_c cause; ho_cancel_ev(const asn1::s1ap::cause_c& cause_) : cause(cause_) {} }; rrc_mobility(srsenb::rrc::ue* outer_ue); bool fill_conn_recfg_no_ho_cmd(asn1::rrc::rrc_conn_recfg_r8_ies_s* conn_recfg); void handle_ue_meas_report(const asn1::rrc::meas_report_s& msg, srsran::unique_byte_buffer_t pdu); void handle_ho_preparation_complete(rrc::ho_prep_result result, const asn1::s1ap::ho_cmd_s& msg, srsran::unique_byte_buffer_t container); bool is_ho_running() const { return not is_in_state<idle_st>(); } // S1-Handover bool start_s1_tenb_ho(const asn1::s1ap::ho_request_s& msg, const asn1::s1ap::sourceenb_to_targetenb_transparent_container_s& container, asn1::s1ap::cause_c& cause); std::pair<uint16_t, uint32_t> get_source_ue_rnti_and_pci(); private: // helper methods bool update_ue_var_meas_cfg(uint32_t src_earfcn, const enb_cell_common& target_pcell, asn1::rrc::meas_cfg_s* diff_meas_cfg); // Handover from source cell bool start_ho_preparation(uint32_t target_eci, uint16_t target_tac, uint8_t measobj_id, bool fwd_direct_path_available); // Handover to target cell void fill_mobility_reconf_common(asn1::rrc::dl_dcch_msg_s& msg, const enb_cell_common& target_cell, uint32_t src_dl_earfcn, uint32_t src_pci); bool apply_ho_prep_cfg(const asn1::rrc::ho_prep_info_r8_ies_s& ho_prep, const asn1::s1ap::ho_request_s& ho_req_msg, std::vector<asn1::s1ap::erab_item_s>& erabs_failed_to_setup, asn1::s1ap::cause_c& cause); rrc::ue* rrc_ue = nullptr; rrc* rrc_enb = nullptr; srslog::basic_logger& logger; // vars asn1::rrc::meas_cfg_s current_meas_cfg; asn1::rrc::rrc_conn_recfg_complete_s pending_recfg_complete; asn1::s1ap::cause_c failure_cause; // events struct ho_meas_report_ev { uint32_t target_eci = 0; uint16_t target_tac = 0; const asn1::rrc::meas_obj_to_add_mod_s* meas_obj = nullptr; bool direct_fwd_path = false; }; struct ho_req_rx_ev { const asn1::s1ap::ho_request_s* ho_req_msg; const asn1::s1ap::sourceenb_to_targetenb_transparent_container_s* transparent_container; }; struct ho_failure_ev { asn1::s1ap::cause_c cause; ho_failure_ev(const asn1::s1ap::cause_c& cause_) : cause(cause_) {} }; using recfg_complete_ev = asn1::rrc::rrc_conn_recfg_complete_s; using status_transfer_ev = asn1::s1ap::bearers_subject_to_status_transfer_list_l; // states struct idle_st {}; struct intraenb_ho_st { const enb_cell_common* target_cell = nullptr; const enb_cell_common* source_cell = nullptr; uint16_t last_temp_crnti = SRSRAN_INVALID_RNTI; void enter(rrc_mobility* f, const ho_meas_report_ev& meas_report); }; struct s1_target_ho_st { asn1::s1ap::cause_c failure_cause; std::vector<uint32_t> pending_tunnels; uint16_t src_rnti; uint32_t src_pci; }; struct wait_recfg_comp {}; struct s1_source_ho_st : public subfsm_t<s1_source_ho_st> { struct ho_cmd_msg { const asn1::s1ap::ho_cmd_s* s1ap_ho_cmd; const asn1::rrc::ho_cmd_r8_ies_s* ho_cmd; }; ho_meas_report_ev report; void enter(rrc_mobility* f, const ho_meas_report_ev& ev); struct wait_ho_cmd {}; struct status_transfer_st {}; explicit s1_source_ho_st(rrc_mobility* parent_); private: void handle_ho_cmd(wait_ho_cmd& s, const ho_cmd_msg& ho_cmd); void handle_ho_cancel(const ho_cancel_ev& ev); asn1::s1ap::cause_c start_enb_status_transfer(const asn1::s1ap::ho_cmd_s& s1ap_ho_cmd); rrc* rrc_enb; rrc::ue* rrc_ue; srslog::basic_logger& logger; protected: using fsm = s1_source_ho_st; state_list<wait_ho_cmd, status_transfer_st> states{this}; // clang-format off using transitions = transition_table< // Start Target Event Action Guard // +-------------------+------------------+---------------------+-----------------------+---------------------+ to_state< idle_st, srsran::failure_ev >, to_state< idle_st, ho_cancel_ev, &fsm::handle_ho_cancel >, row< wait_ho_cmd, status_transfer_st, ho_cmd_msg, &fsm::handle_ho_cmd > // +-------------------+------------------+---------------------+-----------------------+---------------------+ >; // clang-format on }; // FSM guards bool needs_s1_ho(idle_st& s, const ho_meas_report_ev& meas_report); bool needs_intraenb_ho(idle_st& s, const ho_meas_report_ev& meas_report); // FSM transition handlers void handle_crnti_ce(intraenb_ho_st& s, const user_crnti_upd_ev& ev); void handle_recfg_complete(intraenb_ho_st& s, const recfg_complete_ev& ev); void handle_ho_requested(idle_st& s, const ho_req_rx_ev& ho_req); void handle_ho_failure(const ho_failure_ev& ev); void handle_status_transfer(s1_target_ho_st& s, const status_transfer_ev& ev); void defer_recfg_complete(s1_target_ho_st& s, const recfg_complete_ev& ev); void handle_recfg_complete(wait_recfg_comp& s, const recfg_complete_ev& ev); protected: // states state_list<idle_st, intraenb_ho_st, s1_target_ho_st, wait_recfg_comp, s1_source_ho_st> states{this, idle_st{}, intraenb_ho_st{}, s1_target_ho_st{}, wait_recfg_comp{}, s1_source_ho_st{this}}; // transitions using fsm = rrc_mobility; // clang-format off using transitions = transition_table< // Start Target Event Action Guard // +----------------+-------------------+---------------------+----------------------------+-------------------------+ row< idle_st, s1_source_ho_st, ho_meas_report_ev, nullptr, &fsm::needs_s1_ho >, row< idle_st, intraenb_ho_st, ho_meas_report_ev, nullptr, &fsm::needs_intraenb_ho >, row< idle_st, s1_target_ho_st, ho_req_rx_ev, &fsm::handle_ho_requested >, // +----------------+-------------------+---------------------+----------------------------+-------------------------+ upd< intraenb_ho_st, user_crnti_upd_ev, &fsm::handle_crnti_ce >, row< intraenb_ho_st, idle_st, recfg_complete_ev, &fsm::handle_recfg_complete >, // +----------------+-------------------+---------------------+----------------------------+-------------------------+ row< s1_target_ho_st, wait_recfg_comp, status_transfer_ev, &fsm::handle_status_transfer >, to_state< idle_st, ho_failure_ev, &fsm::handle_ho_failure >, upd< s1_target_ho_st, recfg_complete_ev, &fsm::defer_recfg_complete >, row< wait_recfg_comp, idle_st, recfg_complete_ev, &fsm::handle_recfg_complete > // +----------------+-------------------+---------------------+----------------------------+-------------------------+ >; // clang-format on }; } // namespace srsenb #endif // SRSENB_RRC_MOBILITY_H
// Returns position of a word in the vocabulary; if the word is not found, returns -1 int SearchVocab(char *word, EXPSETTING *expsetting) { unsigned long long hash = GetWordHash(word, expsetting -> vocab_hash_size); while (1) { if ((expsetting -> vocab_hash)[hash] == -1) return -1; if (!strcmp(word, (expsetting -> vocab)[(expsetting -> vocab_hash)[hash]].word)) return (expsetting -> vocab_hash)[hash]; hash = (hash + 1) % (expsetting -> vocab_hash_size); } return -1; }
/*! * @brief This API is used to parse and store the sensor time from the * FIFO data in the structure instance dev. */ static void unpack_sensortime_frame(uint16_t *data_index, const struct bmi088_dev *dev) { uint32_t sensor_time_byte3 = 0; uint16_t sensor_time_byte2 = 0; uint8_t sensor_time_byte1 = 0; if ((*data_index + BMI088_SENSOR_TIME_LENGTH) > dev->accel_fifo->length) { *data_index = dev->accel_fifo->length; } else { sensor_time_byte3 = dev->accel_fifo->data[(*data_index) + BMI088_SENSOR_TIME_MSB_BYTE] << BMI088_SIXTEEN; sensor_time_byte2 = dev->accel_fifo->data[(*data_index) + BMI088_SENSOR_TIME_XLSB_BYTE] << BMI088_EIGHT; sensor_time_byte1 = dev->accel_fifo->data[(*data_index) + BMI088_SENSOR_TIME_LSB_BYTE]; dev->accel_fifo->sensor_time = (uint32_t)(sensor_time_byte3 | sensor_time_byte2 | sensor_time_byte1); *data_index = (*data_index) + BMI088_SENSOR_TIME_LENGTH; } }
/* * Print out a null-padded filename (or other ascii string). * If ep is NULL, assume no truncation check is needed. * Return true if truncated. */ int fn_printzp(register const u_char *s, register u_int n, register const u_char *ep) { register int ret; register u_char c; ret = 1; while (n > 0 && (ep == NULL || s < ep)) { n--; c = *s++; if (c == '\0') { ret = 0; break; } if (!isascii(c)) { c = toascii(c); putchar('M'); putchar('-'); } if (!isprint(c)) { c ^= 0x40; putchar('^'); } putchar(c); } return (n == 0) ? 0 : ret; }
/* * Copyright (c) 2015 Kaprica Security, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * */ #include "cgc_stdio_private.h" static unsigned int cgc_hash_seed(const char *seed) { unsigned int i; unsigned int H = 0x314abc86; for (i = 0; seed[i] != 0; i++) { H *= 37; H ^= seed[i]; H = (H << 13) ^ (H >> 19); } return H; } void cgc_fxlat(FILE *stream, const char *seed) { unsigned int state, i; unsigned char *map, *map_inv; if (seed == NULL) { cgc_free(stream->xlat_map); stream->xlat_map = NULL; stream->xlat_map_inv = NULL; return; } map = stream->xlat_map = cgc_realloc(stream->xlat_map, 256); map_inv = stream->xlat_map_inv = cgc_realloc(stream->xlat_map_inv, 256); state = cgc_hash_seed(seed); /* initialize map with identity */ for (i = 0; i < 256; i++) map[i] = i; /* shuffle using Fisher-Yates */ for (i = 255; i >= 1; i--) { unsigned int j = state % i, tmp; /* iterate state */ state *= 3; state = (state << 13) ^ (state >> 19) ^ (state >> 21); /* exchange elements */ tmp = map[i]; map[i] = map[j]; map[j] = tmp; } /* initialize inverse mapping */ for (i = 0; i < 256; i++) { map_inv[map[i]] = i; } }
/* * Copyright (c) 2018-2019, Texas Instruments Incorporated - http://www.ti.com/ * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ /*---------------------------------------------------------------------------*/ /* * Parameter summary * Adv. Address: 010203040506 * Adv. Data: 255 * BLE Channel: 17 * Frequency: 2440 MHz * PDU Payload length: 30 * TX Power: 9 dBm (requires define CCFG_FORCE_VDDR_HH = 1 in ccfg.c, * see CC13xx/CC26xx Technical Reference Manual) * Whitening: true */ /*---------------------------------------------------------------------------*/ #include "sys/cc.h" /*---------------------------------------------------------------------------*/ #include <ti/devices/DeviceFamily.h> #include DeviceFamily_constructPath(driverlib/rf_mailbox.h) #include DeviceFamily_constructPath(driverlib/rf_common_cmd.h) #include DeviceFamily_constructPath(driverlib/rf_ble_cmd.h) #include DeviceFamily_constructPath(rf_patches/rf_patch_cpe_ble.h) #include DeviceFamily_constructPath(rf_patches/rf_patch_rfe_ble.h) #include <ti/drivers/rf/RF.h> /*---------------------------------------------------------------------------*/ #include "ble-settings.h" /*---------------------------------------------------------------------------*/ /* TI-RTOS RF Mode Object */ RF_Mode rf_ble_mode = { .rfMode = RF_MODE_MULTIPLE, .cpePatchFxn = &rf_patch_cpe_ble, .mcePatchFxn = 0, .rfePatchFxn = &rf_patch_rfe_ble, }; /*---------------------------------------------------------------------------*/ /* Overrides for CMD_RADIO_SETUP */ uint32_t rf_ble_overrides[] CC_ALIGN(4) = { // override_use_patch_ble_1mbps.xml // PHY: Use MCE ROM, RFE RAM patch MCE_RFE_OVERRIDE(0,0,0,1,0,0), // override_synth_ble_1mbps.xml // Synth: Set recommended RTRIM to 4 HW_REG_OVERRIDE(0x4038,0x0034), // Synth: Set Fref to 3.43 MHz (uint32_t)0x000784A3, // Synth: Configure fine calibration setting HW_REG_OVERRIDE(0x4020,0x7F00), // Synth: Configure fine calibration setting HW_REG_OVERRIDE(0x4064,0x0040), // Synth: Configure fine calibration setting (uint32_t)0xB1070503, // Synth: Configure fine calibration setting (uint32_t)0x05330523, // Synth: Set loop bandwidth after lock to 80 kHz (uint32_t)0xA47E0583, // Synth: Set loop bandwidth after lock to 80 kHz (uint32_t)0xEAE00603, // Synth: Set loop bandwidth after lock to 80 kHz (uint32_t)0x00010623, // Synth: Configure PLL bias HW32_ARRAY_OVERRIDE(0x405C,1), // Synth: Configure PLL bias (uint32_t)0x18000000, // Synth: Configure VCO LDO (in ADI1, set VCOLDOCFG=0x9F to use voltage input reference) ADI_REG_OVERRIDE(1,4,0x9F), // Synth: Configure synth LDO (in ADI1, set SLDOCTL0.COMP_CAP=1) ADI_HALFREG_OVERRIDE(1,7,0x4,0x4), // override_phy_ble_1mbps.xml // Tx: Configure symbol shape for BLE frequency deviation requirements (uint32_t)0x013800C3, // Rx: Configure AGC reference level HW_REG_OVERRIDE(0x6088, 0x0045), // Rx: Configure AGC gain level HW_REG_OVERRIDE(0x6084, 0x05FD), // Rx: Configure LNA bias current trim offset (uint32_t)0x00038883, // override_frontend_xd.xml // Rx: Set RSSI offset to adjust reported RSSI by +13 dB (uint32_t)0x00F388A3, #if RF_TXPOWER_BOOST_MODE // TX power override // Tx: Set PA trim to max (in ADI0, set PACTL0=0xF8) ADI_REG_OVERRIDE(0,12,0xF8), #endif (uint32_t)0xFFFFFFFF }; /*---------------------------------------------------------------------------*/ /* CMD_RADIO_SETUP: Radio Setup Command for Pre-Defined Schemes */ rfc_CMD_RADIO_SETUP_t rf_ble_cmd_radio_setup = { .commandNo = CMD_RADIO_SETUP, .status = IDLE, .pNextOp = 0, .startTime = 0x00000000, .startTrigger.triggerType = TRIG_NOW, .startTrigger.bEnaCmd = 0x0, .startTrigger.triggerNo = 0x0, .startTrigger.pastTrig = 0x0, .condition.rule = COND_NEVER, .condition.nSkip = 0x0, .mode = 0x00, .loDivider = 0x00, .config.frontEndMode = 0x0, /* set by driver */ .config.biasMode = 0x0, /* set by driver */ .config.analogCfgMode = 0x0, .config.bNoFsPowerUp = 0x0, .txPower = 0x5F3C, /* set by driver */ .pRegOverride = rf_ble_overrides, }; /*---------------------------------------------------------------------------*/ /* CMD_BLE_ADV_NC: BLE Non-Connectable Advertiser Command */ rfc_CMD_BLE_ADV_NC_t rf_ble_cmd_ble_adv_nc = { .commandNo = CMD_BLE_ADV_NC, .status = IDLE, .pNextOp = 0, .startTime = 0x00000000, .startTrigger.triggerType = TRIG_NOW, .startTrigger.bEnaCmd = 0x0, .startTrigger.triggerNo = 0x0, .startTrigger.pastTrig = 0x1, .condition.rule = 0x0, /* set by driver */ .condition.nSkip = 0x0, .channel = 0x00, /* set by driver */ .whitening.init = 0x00, /* set by driver */ .whitening.bOverride = 0x1, .pParams = 0x00000000, /* set by driver */ .pOutput = 0x00000000, /* set by driver */ }; /*---------------------------------------------------------------------------*/
/* * Substitutes one substring for all occurrences another in a string. * * Arguments: * inString Pointer to the input string. * str Pointer to the substring to be replaced. * outString Pointer to the output string buffer. * repl Pointer to the replacement substring. * size Size of the output string buffer, including the * terminating NUL. * Returns: * 0 Failure. The output string buffer is too small. * else Success. */ static int substitute( const char* const inString, const char* str, char* const outString, const char* repl, const size_t size) { const char* in = inString; char* out = outString; char* beyond = outString + size; size_t strLen = strlen(str); size_t replLen = strlen(repl); while (*in) { size_t nbytes; char* cp = strstr(in, str); if (cp == NULL) { nbytes = strlen(in); if (out + nbytes >= beyond) { ut_set_status(UT_SYNTAX); ut_handle_error_message("String \"%s\" is too long", inString); return 0; } (void)strncpy(out, in, nbytes); out += nbytes; break; } else { nbytes = (size_t)(cp - in); if (out + nbytes + replLen >= beyond) { ut_set_status(UT_SYNTAX); ut_handle_error_message("String \"%s\" is too long", inString); return 0; } (void)strncpy(out, in, nbytes); out += nbytes; (void)strncpy(out, repl, replLen); out += replLen; in += nbytes + strLen; } } *out = 0; return 1; }
/** * @brief Get IPv4 time-to-live value specified for a given interface * * @param iface Network interface * * @return Time-to-live */ static inline u8_t net_if_ipv4_get_ttl(struct net_if *iface) { if (!iface->config.ip.ipv4) { return 0; } return iface->config.ip.ipv4->ttl; }
/* MTX mail fetch message header * Accepts: MAIL stream * message # to fetch * pointer to returned header text length * option flags * Returns: message header in RFC822 format */ char *mtx_header (MAILSTREAM *stream,unsigned long msgno,unsigned long *length, long flags) { *length = 0; if (flags & FT_UID) return ""; lseek (LOCAL->fd,mtx_hdrpos (stream,msgno,length),L_SET); if (*length > LOCAL->buflen) { fs_give ((void **) &LOCAL->buf); LOCAL->buf = (char *) fs_get ((LOCAL->buflen = *length) + 1); } LOCAL->buf[*length] = '\0'; read (LOCAL->fd,LOCAL->buf,*length); return (char *) LOCAL->buf; }
#include<stdio.h> #include<stdlib.h> #define SIZE 100001 enum TYPE{root, node, leaf, null}; char* strtype[] = {"root", "internal node", "leaf"}; typedef struct Vec{ int lenght; int size; int maxsize; int* buff; }VEC; typedef struct VecIt{ int i; VEC* vp; }VECIT; struct TREE{ int parent; int depth; int type; VEC* vp; }; struct TREE tree[SIZE]; int treeroot; VEC* newVec(void) { VEC* vp = (VEC*)malloc(sizeof(VEC)); vp->lenght = 0; vp->size = 10; vp->maxsize = SIZE; vp->buff = (int*)calloc(vp->size, sizeof(int)); return(vp); } void delVec(VEC* vp) { free(vp->buff); free(vp); return; } void resizeVec(VEC* vp) { vp->size += vp->size; vp->buff = (int*)realloc(vp->buff, vp->size*sizeof(int)); return; } void addVec(VEC* vp, int n) { if(vp->size <= vp->lenght){ resizeVec(vp); } vp->buff[vp->lenght] = n; vp->lenght++; return; } int getVec(VEC* vp, int n) { if(n < vp->lenght){ return(vp->buff[n]); } return(-1); } int lenghtVec(VEC* vp) { return(vp->lenght); } VECIT* newVecIt(VEC* vp) { VECIT* vpit = (VECIT*)malloc(sizeof(VECIT)); vpit->vp = vp; vpit->i = 0; return(vpit); } void delVecIt(VECIT* vp) { free(vp); return; } int nextVecIt(VECIT* vp) { return(getVec(vp->vp, vp->i++)); } void init(void) { int i; for(i = 0; i < SIZE; i++){ tree[i].parent = -1; tree[i].depth = 0; tree[i].type = null; tree[i].vp = newVec(); } return; } void end(void) { int i; for(i = 0; i < SIZE; i++){ delVec(tree[i].vp); } return; } void tr(int node, int lv) { int n; VECIT* it = newVecIt(tree[node].vp); while((n = nextVecIt(it)) != -1){ tr(n, lv + 1); } tree[node].depth = lv; return; } int main(int argc, char* argv[]) { int i, j, k, n, c, id, itn; VECIT* it; init(); scanf("%d", &n); for(i = 0; i < n; i++){ scanf("%d", &id); scanf("%d", &k); for(j = 0; j < k; j++){ scanf("%d", &c); if(tree[c].type == null){ tree[c].type = leaf; } tree[c].parent = id; addVec(tree[id].vp, c); } if(0 < lenghtVec(tree[id].vp)){ tree[id].type = node; }else{ tree[id].type = leaf; } } for(i = 0; i < n; i++){ if(tree[i].parent == -1){ treeroot = i; break; } } tree[treeroot].type = root; tr(treeroot, 0); for(i = 0; i < n; i++){ printf("node %d: parent = %d, depth = %d, ", i, tree[i].parent, tree[i].depth); printf("%s, [", strtype[tree[i].type]); it = newVecIt(tree[i].vp); itn = lenghtVec(tree[i].vp); for(j = 0; j < itn-1; j++){ printf("%d, ", nextVecIt(it)); } if(itn == 0){ printf("]\n"); }else{ printf("%d]\n", nextVecIt(it)); } delVecIt(it); } end(); return(0); }
#include <stdio.h> #include <stdlib.h> int main() { long int a,b,c,x,y,z; scanf("%ld%ld%ld%ld%ld%ld",&a,&b,&c,&x,&y,&z); if(a+b+c < x+y+z) { printf("No\n"); return 0; } else { if(a-x >= 0) a = (a-x)/2; else a = a-x; if(b-y >= 0) b = (b-y)/2; else b = b-y; if(c-z >= 0) c = (c-z)/2; else c = c-z; if(a+b+c >= 0) printf("Yes\n"); else printf("No\n"); } return 0; }
/** * CANCEL a pending INVITE * * To match the INVITE, the following parameter must not be changed: * * CSeq * * From tag value */ void send_sip_cancel() { TxBufferT& tx_buffer = m_socket.get_new_tx_buf(); send_sip_header("CANCEL", m_uri, m_to_uri, tx_buffer); if (!m_response.empty()) { tx_buffer << "Contact: \"" << m_user << "\" <sip:" << m_user << "@" << m_my_ip << ":" << LOCAL_PORT << ";transport=" << TRANSPORT_LOWER << ">\r\n"; tx_buffer << "Content-Type: application/sdp\r\n"; tx_buffer << "Authorization: Digest username=\"" << m_user << "\", realm=\"" << m_realm << "\", nonce=\"" << m_nonce << "\", uri=\"" << m_uri << "\", response=\"" << m_response << "\"\r\n"; } tx_buffer << "Content-Length: 0\r\n"; tx_buffer << "\r\n"; m_socket.send_buffered_data(); }
#ifndef __HD64570_H #define __HD64570_H /* SCA HD64570 register definitions - all addresses for mode 0 (8086 MPU) and 1 (64180 MPU). For modes 2 and 3, XOR the address with 0x01. Source: HD64570 SCA User's Manual */ /* SCA Control Registers */ #define LPR 0x00 /* Low Power */ /* Wait controller registers */ #define PABR0 0x02 /* Physical Address Boundary 0 */ #define PABR1 0x03 /* Physical Address Boundary 1 */ #define WCRL 0x04 /* Wait Control L */ #define WCRM 0x05 /* Wait Control M */ #define WCRH 0x06 /* Wait Control H */ #define PCR 0x08 /* DMA Priority Control */ #define DMER 0x09 /* DMA Master Enable */ /* Interrupt registers */ #define ISR0 0x10 /* Interrupt Status 0 */ #define ISR1 0x11 /* Interrupt Status 1 */ #define ISR2 0x12 /* Interrupt Status 2 */ #define IER0 0x14 /* Interrupt Enable 0 */ #define IER1 0x15 /* Interrupt Enable 1 */ #define IER2 0x16 /* Interrupt Enable 2 */ #define ITCR 0x18 /* Interrupt Control */ #define IVR 0x1A /* Interrupt Vector */ #define IMVR 0x1C /* Interrupt Modified Vector */ /* MSCI channel (port) 0 registers - offset 0x20 MSCI channel (port) 1 registers - offset 0x40 */ #define MSCI0_OFFSET 0x20 #define MSCI1_OFFSET 0x40 #define TRBL 0x00 /* TX/RX buffer L */ #define TRBH 0x01 /* TX/RX buffer H */ #define ST0 0x02 /* Status 0 */ #define ST1 0x03 /* Status 1 */ #define ST2 0x04 /* Status 2 */ #define ST3 0x05 /* Status 3 */ #define FST 0x06 /* Frame Status */ #define IE0 0x08 /* Interrupt Enable 0 */ #define IE1 0x09 /* Interrupt Enable 1 */ #define IE2 0x0A /* Interrupt Enable 2 */ #define FIE 0x0B /* Frame Interrupt Enable */ #define CMD 0x0C /* Command */ #define MD0 0x0E /* Mode 0 */ #define MD1 0x0F /* Mode 1 */ #define MD2 0x10 /* Mode 2 */ #define CTL 0x11 /* Control */ #define SA0 0x12 /* Sync/Address 0 */ #define SA1 0x13 /* Sync/Address 1 */ #define IDL 0x14 /* Idle Pattern */ #define TMC 0x15 /* Time Constant */ #define RXS 0x16 /* RX Clock Source */ #define TXS 0x17 /* TX Clock Source */ #define TRC0 0x18 /* TX Ready Control 0 */ #define TRC1 0x19 /* TX Ready Control 1 */ #define RRC 0x1A /* RX Ready Control */ #define CST0 0x1C /* Current Status 0 */ #define CST1 0x1D /* Current Status 1 */ /* Timer channel 0 (port 0 RX) registers - offset 0x60 Timer channel 1 (port 0 TX) registers - offset 0x68 Timer channel 2 (port 1 RX) registers - offset 0x70 Timer channel 3 (port 1 TX) registers - offset 0x78 */ #define TIMER0RX_OFFSET 0x60 #define TIMER0TX_OFFSET 0x68 #define TIMER1RX_OFFSET 0x70 #define TIMER1TX_OFFSET 0x78 #define TCNTL 0x00 /* Up-counter L */ #define TCNTH 0x01 /* Up-counter H */ #define TCONRL 0x02 /* Constant L */ #define TCONRH 0x03 /* Constant H */ #define TCSR 0x04 /* Control/Status */ #define TEPR 0x05 /* Expand Prescale */ /* DMA channel 0 (port 0 RX) registers - offset 0x80 DMA channel 1 (port 0 TX) registers - offset 0xA0 DMA channel 2 (port 1 RX) registers - offset 0xC0 DMA channel 3 (port 1 TX) registers - offset 0xE0 */ #define DMAC0RX_OFFSET 0x80 #define DMAC0TX_OFFSET 0xA0 #define DMAC1RX_OFFSET 0xC0 #define DMAC1TX_OFFSET 0xE0 #define BARL 0x00 /* Buffer Address L (chained block) */ #define BARH 0x01 /* Buffer Address H (chained block) */ #define BARB 0x02 /* Buffer Address B (chained block) */ #define DARL 0x00 /* RX Destination Addr L (single block) */ #define DARH 0x01 /* RX Destination Addr H (single block) */ #define DARB 0x02 /* RX Destination Addr B (single block) */ #define SARL 0x04 /* TX Source Address L (single block) */ #define SARH 0x05 /* TX Source Address H (single block) */ #define SARB 0x06 /* TX Source Address B (single block) */ #define CPB 0x06 /* Chain Pointer Base (chained block) */ #define CDAL 0x08 /* Current Descriptor Addr L (chained block) */ #define CDAH 0x09 /* Current Descriptor Addr H (chained block) */ #define EDAL 0x0A /* Error Descriptor Addr L (chained block) */ #define EDAH 0x0B /* Error Descriptor Addr H (chained block) */ #define BFLL 0x0C /* RX Receive Buffer Length L (chained block)*/ #define BFLH 0x0D /* RX Receive Buffer Length H (chained block)*/ #define BCRL 0x0E /* Byte Count L */ #define BCRH 0x0F /* Byte Count H */ #define DSR 0x10 /* DMA Status */ #define DSR_RX(node) (DSR + (node ? DMAC1RX_OFFSET : DMAC0RX_OFFSET)) #define DSR_TX(node) (DSR + (node ? DMAC1TX_OFFSET : DMAC0TX_OFFSET)) #define DMR 0x11 /* DMA Mode */ #define DMR_RX(node) (DMR + (node ? DMAC1RX_OFFSET : DMAC0RX_OFFSET)) #define DMR_TX(node) (DMR + (node ? DMAC1TX_OFFSET : DMAC0TX_OFFSET)) #define FCT 0x13 /* Frame End Interrupt Counter */ #define FCT_RX(node) (FCT + (node ? DMAC1RX_OFFSET : DMAC0RX_OFFSET)) #define FCT_TX(node) (FCT + (node ? DMAC1TX_OFFSET : DMAC0TX_OFFSET)) #define DIR 0x14 /* DMA Interrupt Enable */ #define DIR_RX(node) (DIR + (node ? DMAC1RX_OFFSET : DMAC0RX_OFFSET)) #define DIR_TX(node) (DIR + (node ? DMAC1TX_OFFSET : DMAC0TX_OFFSET)) #define DCR 0x15 /* DMA Command */ #define DCR_RX(node) (DCR + (node ? DMAC1RX_OFFSET : DMAC0RX_OFFSET)) #define DCR_TX(node) (DCR + (node ? DMAC1TX_OFFSET : DMAC0TX_OFFSET)) /* Descriptor Structure */ typedef struct { u16 cp; /* Chain Pointer */ u32 bp; /* Buffer Pointer (24 bits) */ u16 len; /* Data Length */ u8 stat; /* Status */ u8 unused; /* pads to 2-byte boundary */ }__packed pkt_desc; /* Packet Descriptor Status bits */ #define ST_TX_EOM 0x80 /* End of frame */ #define ST_TX_EOT 0x01 /* End of transmition */ #define ST_RX_EOM 0x80 /* End of frame */ #define ST_RX_SHORT 0x40 /* Short frame */ #define ST_RX_ABORT 0x20 /* Abort */ #define ST_RX_RESBIT 0x10 /* Residual bit */ #define ST_RX_OVERRUN 0x08 /* Overrun */ #define ST_RX_CRC 0x04 /* CRC */ #define ST_ERROR_MASK 0x7C #define DIR_EOTE 0x80 /* Transfer completed */ #define DIR_EOME 0x40 /* Frame Transfer Completed (chained-block) */ #define DIR_BOFE 0x20 /* Buffer Overflow/Underflow (chained-block)*/ #define DIR_COFE 0x10 /* Counter Overflow (chained-block) */ #define DSR_EOT 0x80 /* Transfer completed */ #define DSR_EOM 0x40 /* Frame Transfer Completed (chained-block) */ #define DSR_BOF 0x20 /* Buffer Overflow/Underflow (chained-block)*/ #define DSR_COF 0x10 /* Counter Overflow (chained-block) */ #define DSR_DE 0x02 /* DMA Enable */ #define DSR_DWE 0x01 /* DMA Write Disable */ /* DMA Master Enable Register (DMER) bits */ #define DMER_DME 0x80 /* DMA Master Enable */ #define CMD_RESET 0x21 /* Reset Channel */ #define CMD_TX_ENABLE 0x02 /* Start transmitter */ #define CMD_RX_ENABLE 0x12 /* Start receiver */ #define MD0_HDLC 0x80 /* Bit-sync HDLC mode */ #define MD0_CRC_ENA 0x04 /* Enable CRC code calculation */ #define MD0_CRC_CCITT 0x02 /* CCITT CRC instead of CRC-16 */ #define MD0_CRC_PR1 0x01 /* Initial all-ones instead of all-zeros */ #define MD0_CRC_NONE 0x00 #define MD0_CRC_16_0 0x04 #define MD0_CRC_16 0x05 #define MD0_CRC_ITU_0 0x06 #define MD0_CRC_ITU 0x07 #define MD2_NRZ 0x00 #define MD2_NRZI 0x20 #define MD2_MANCHESTER 0x80 #define MD2_FM_MARK 0xA0 #define MD2_FM_SPACE 0xC0 #define MD2_LOOPBACK 0x03 /* Local data Loopback */ #define CTL_NORTS 0x01 #define CTL_IDLE 0x10 /* Transmit an idle pattern */ #define CTL_UDRNC 0x20 /* Idle after CRC or FCS+flag transmition */ #define ST0_TXRDY 0x02 /* TX ready */ #define ST0_RXRDY 0x01 /* RX ready */ #define ST1_UDRN 0x80 /* MSCI TX underrun */ #define ST1_CDCD 0x04 /* DCD level changed */ #define ST3_CTS 0x08 /* modem input - /CTS */ #define ST3_DCD 0x04 /* modem input - /DCD */ #define IE0_TXINT 0x80 /* TX INT MSCI interrupt enable */ #define IE0_RXINTA 0x40 /* RX INT A MSCI interrupt enable */ #define IE1_UDRN 0x80 /* TX underrun MSCI interrupt enable */ #define IE1_CDCD 0x04 /* DCD level changed */ #define DCR_ABORT 0x01 /* Software abort command */ #define DCR_CLEAR_EOF 0x02 /* Clear EOF interrupt */ /* TX and RX Clock Source - RXS and TXS */ #define CLK_BRG_MASK 0x0F #define CLK_LINE_RX 0x00 /* TX/RX clock line input */ #define CLK_LINE_TX 0x00 /* TX/RX line input */ #define CLK_BRG_RX 0x40 /* internal baud rate generator */ #define CLK_BRG_TX 0x40 /* internal baud rate generator */ #define CLK_RXCLK_TX 0x60 /* TX clock from RX clock */ #endif
/* * Checks if write buffer has overflowed, if so, a log will be issued and buffer will reset. */ inline XnBool CheckWriteBufferForOverflow(XnUInt32 nWriteSize) { if (GetWriteBuffer()->GetFreeSpaceInBuffer() < nWriteSize) { WriteBufferOverflowed(); return FALSE; } return TRUE; }
#include "stdio.h" #include <stdint.h> #include <stdlib.h> #include <string.h> #include "math.h" #define max(a,b) ((a)>(b)?(a):(b)) #define min(a,b) ((a)<(b)?(a):(b)) #define ll long long int main(int argc, char *argv[]) { ll t,n,k; scanf("%lld", &t); while (t--) { scanf("%lld", &n); int ans = 0; while (n>=2) { ll k = sqrt(2 * n / 3 + 1); while (k * k * 3 + k > n * 2) { k--; } ll z = (k * k * 3 + k) / 2; ans += n/z; n %= z; } printf("%d\n", ans); } }
/* Return both allocated and actual size, since there's a race between allocation and list compilation */ static int memorystatus_get_priority_list(memorystatus_priority_entry_t **list_ptr, size_t *buffer_size, size_t *list_size, boolean_t size_only) { uint32_t list_count, i = 0; memorystatus_priority_entry_t *list_entry; proc_t p; list_count = memorystatus_list_count; *list_size = sizeof(memorystatus_priority_entry_t) * list_count; if (size_only) { return 0; } if (*buffer_size < *list_size) { return EINVAL; } *list_ptr = (memorystatus_priority_entry_t*)kalloc(*list_size); if (!list_ptr) { return ENOMEM; } memset(*list_ptr, 0, *list_size); *buffer_size = *list_size; *list_size = 0; list_entry = *list_ptr; proc_list_lock(); p = memorystatus_get_first_proc_locked(&i, TRUE); while (p && (*list_size < *buffer_size)) { list_entry->pid = p->p_pid; list_entry->priority = p->p_memstat_effectivepriority; list_entry->user_data = p->p_memstat_userdata; if (p->p_memstat_memlimit <= 0) { task_get_phys_footprint_limit(p->task, &list_entry->limit); } else { list_entry->limit = p->p_memstat_memlimit; } list_entry->state = memorystatus_build_state(p); list_entry++; *list_size += sizeof(memorystatus_priority_entry_t); p = memorystatus_get_next_proc_locked(&i, p, TRUE); } proc_list_unlock(); MEMORYSTATUS_DEBUG(1, "memorystatus_get_priority_list: returning %lu for size\n", (unsigned long)*list_size); return 0; }
/* * at91_cf.c -- AT91 CompactFlash controller driver * * Copyright (C) 2005 David Brownell * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. */ #include <linux/module.h> #include <linux/kernel.h> #include <linux/platform_device.h> #include <linux/errno.h> #include <linux/init.h> #include <linux/interrupt.h> #include <pcmcia/ss.h> #include <asm/hardware.h> #include <asm/io.h> #include <asm/sizes.h> #include <asm/arch/board.h> #include <asm/arch/gpio.h> #include <asm/arch/at91rm9200_mc.h> /* * A0..A10 work in each range; A23 indicates I/O space; A25 is CFRNW; * some other bit in {A24,A22..A11} is nREG to flag memory access * (vs attributes). So more than 2KB/region would just be waste. * Note: These are offsets from the physical base address. */ #define CF_ATTR_PHYS (0) #define CF_IO_PHYS (1 << 23) #define CF_MEM_PHYS (0x017ff800) /*--------------------------------------------------------------------------*/ static const char driver_name[] = "at91_cf"; struct at91_cf_socket { struct pcmcia_socket socket; unsigned present:1; struct platform_device *pdev; struct at91_cf_data *board; unsigned long phys_baseaddr; }; #define SZ_2K (2 * SZ_1K) static inline int at91_cf_present(struct at91_cf_socket *cf) { return !at91_get_gpio_value(cf->board->det_pin); } /*--------------------------------------------------------------------------*/ static int at91_cf_ss_init(struct pcmcia_socket *s) { return 0; } static irqreturn_t at91_cf_irq(int irq, void *_cf) { struct at91_cf_socket *cf = _cf; if (irq == cf->board->det_pin) { unsigned present = at91_cf_present(cf); /* kick pccard as needed */ if (present != cf->present) { cf->present = present; pr_debug("%s: card %s\n", driver_name, present ? "present" : "gone"); pcmcia_parse_events(&cf->socket, SS_DETECT); } } return IRQ_HANDLED; } static int at91_cf_get_status(struct pcmcia_socket *s, u_int *sp) { struct at91_cf_socket *cf; if (!sp) return -EINVAL; cf = container_of(s, struct at91_cf_socket, socket); /* NOTE: CF is always 3VCARD */ if (at91_cf_present(cf)) { int rdy = cf->board->irq_pin; /* RDY/nIRQ */ int vcc = cf->board->vcc_pin; *sp = SS_DETECT | SS_3VCARD; if (!rdy || at91_get_gpio_value(rdy)) *sp |= SS_READY; if (!vcc || at91_get_gpio_value(vcc)) *sp |= SS_POWERON; } else *sp = 0; return 0; } static int at91_cf_set_socket(struct pcmcia_socket *sock, struct socket_state_t *s) { struct at91_cf_socket *cf; cf = container_of(sock, struct at91_cf_socket, socket); /* switch Vcc if needed and possible */ if (cf->board->vcc_pin) { switch (s->Vcc) { case 0: at91_set_gpio_value(cf->board->vcc_pin, 0); break; case 33: at91_set_gpio_value(cf->board->vcc_pin, 1); break; default: return -EINVAL; } } /* toggle reset if needed */ at91_set_gpio_value(cf->board->rst_pin, s->flags & SS_RESET); pr_debug("%s: Vcc %d, io_irq %d, flags %04x csc %04x\n", driver_name, s->Vcc, s->io_irq, s->flags, s->csc_mask); return 0; } static int at91_cf_ss_suspend(struct pcmcia_socket *s) { return at91_cf_set_socket(s, &dead_socket); } /* we already mapped the I/O region */ static int at91_cf_set_io_map(struct pcmcia_socket *s, struct pccard_io_map *io) { struct at91_cf_socket *cf; u32 csr; cf = container_of(s, struct at91_cf_socket, socket); io->flags &= (MAP_ACTIVE | MAP_16BIT | MAP_AUTOSZ); /* * Use 16 bit accesses unless/until we need 8-bit i/o space. */ csr = at91_sys_read(AT91_SMC_CSR(cf->board->chipselect)) & ~AT91_SMC_DBW; /* * NOTE: this CF controller ignores IOIS16, so we can't really do * MAP_AUTOSZ. The 16bit mode allows single byte access on either * D0-D7 (even addr) or D8-D15 (odd), so it's close enough for many * purposes (and handles ide-cs). * * The 8bit mode is needed for odd byte access on D0-D7. It seems * some cards only like that way to get at the odd byte, despite * CF 3.0 spec table 35 also giving the D8-D15 option. */ if (!(io->flags & (MAP_16BIT | MAP_AUTOSZ))) { csr |= AT91_SMC_DBW_8; pr_debug("%s: 8bit i/o bus\n", driver_name); } else { csr |= AT91_SMC_DBW_16; pr_debug("%s: 16bit i/o bus\n", driver_name); } at91_sys_write(AT91_SMC_CSR(cf->board->chipselect), csr); io->start = cf->socket.io_offset; io->stop = io->start + SZ_2K - 1; return 0; } /* pcmcia layer maps/unmaps mem regions */ static int at91_cf_set_mem_map(struct pcmcia_socket *s, struct pccard_mem_map *map) { struct at91_cf_socket *cf; if (map->card_start) return -EINVAL; cf = container_of(s, struct at91_cf_socket, socket); map->flags &= (MAP_ACTIVE | MAP_ATTRIB | MAP_16BIT); if (map->flags & MAP_ATTRIB) map->static_start = cf->phys_baseaddr + CF_ATTR_PHYS; else map->static_start = cf->phys_baseaddr + CF_MEM_PHYS; return 0; } static struct pccard_operations at91_cf_ops = { .init = at91_cf_ss_init, .suspend = at91_cf_ss_suspend, .get_status = at91_cf_get_status, .set_socket = at91_cf_set_socket, .set_io_map = at91_cf_set_io_map, .set_mem_map = at91_cf_set_mem_map, }; /*--------------------------------------------------------------------------*/ static int __init at91_cf_probe(struct platform_device *pdev) { struct at91_cf_socket *cf; struct at91_cf_data *board = pdev->dev.platform_data; struct resource *io; int status; if (!board || !board->det_pin || !board->rst_pin) return -ENODEV; io = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!io) return -ENODEV; cf = kzalloc(sizeof *cf, GFP_KERNEL); if (!cf) return -ENOMEM; cf->board = board; cf->pdev = pdev; cf->phys_baseaddr = io->start; platform_set_drvdata(pdev, cf); /* must be a GPIO; ergo must trigger on both edges */ status = request_irq(board->det_pin, at91_cf_irq, 0, driver_name, cf); if (status < 0) goto fail0; device_init_wakeup(&pdev->dev, 1); /* * The card driver will request this irq later as needed. * but it causes lots of "irqNN: nobody cared" messages * unless we report that we handle everything (sigh). * (Note: DK board doesn't wire the IRQ pin...) */ if (board->irq_pin) { status = request_irq(board->irq_pin, at91_cf_irq, IRQF_SHARED, driver_name, cf); if (status < 0) goto fail0a; cf->socket.pci_irq = board->irq_pin; } else cf->socket.pci_irq = NR_IRQS + 1; /* pcmcia layer only remaps "real" memory not iospace */ cf->socket.io_offset = (unsigned long) ioremap(cf->phys_baseaddr + CF_IO_PHYS, SZ_2K); if (!cf->socket.io_offset) { status = -ENXIO; goto fail1; } /* reserve chip-select regions */ if (!request_mem_region(io->start, io->end + 1 - io->start, driver_name)) { status = -ENXIO; goto fail1; } pr_info("%s: irqs det #%d, io #%d\n", driver_name, board->det_pin, board->irq_pin); cf->socket.owner = THIS_MODULE; cf->socket.dev.parent = &pdev->dev; cf->socket.ops = &at91_cf_ops; cf->socket.resource_ops = &pccard_static_ops; cf->socket.features = SS_CAP_PCCARD | SS_CAP_STATIC_MAP | SS_CAP_MEM_ALIGN; cf->socket.map_size = SZ_2K; cf->socket.io[0].res = io; status = pcmcia_register_socket(&cf->socket); if (status < 0) goto fail2; return 0; fail2: release_mem_region(io->start, io->end + 1 - io->start); fail1: if (cf->socket.io_offset) iounmap((void __iomem *) cf->socket.io_offset); if (board->irq_pin) free_irq(board->irq_pin, cf); fail0a: device_init_wakeup(&pdev->dev, 0); free_irq(board->det_pin, cf); fail0: kfree(cf); return status; } static int __exit at91_cf_remove(struct platform_device *pdev) { struct at91_cf_socket *cf = platform_get_drvdata(pdev); struct at91_cf_data *board = cf->board; struct resource *io = cf->socket.io[0].res; pcmcia_unregister_socket(&cf->socket); if (board->irq_pin) free_irq(board->irq_pin, cf); device_init_wakeup(&pdev->dev, 0); free_irq(board->det_pin, cf); iounmap((void __iomem *) cf->socket.io_offset); release_mem_region(io->start, io->end + 1 - io->start); kfree(cf); return 0; } #ifdef CONFIG_PM static int at91_cf_suspend(struct platform_device *pdev, pm_message_t mesg) { struct at91_cf_socket *cf = platform_get_drvdata(pdev); struct at91_cf_data *board = cf->board; pcmcia_socket_dev_suspend(&pdev->dev, mesg); if (device_may_wakeup(&pdev->dev)) { enable_irq_wake(board->det_pin); if (board->irq_pin) enable_irq_wake(board->irq_pin); } return 0; } static int at91_cf_resume(struct platform_device *pdev) { struct at91_cf_socket *cf = platform_get_drvdata(pdev); struct at91_cf_data *board = cf->board; if (device_may_wakeup(&pdev->dev)) { disable_irq_wake(board->det_pin); if (board->irq_pin) disable_irq_wake(board->irq_pin); } pcmcia_socket_dev_resume(&pdev->dev); return 0; } #else #define at91_cf_suspend NULL #define at91_cf_resume NULL #endif static struct platform_driver at91_cf_driver = { .driver = { .name = (char *) driver_name, .owner = THIS_MODULE, }, .remove = __exit_p(at91_cf_remove), .suspend = at91_cf_suspend, .resume = at91_cf_resume, }; /*--------------------------------------------------------------------------*/ static int __init at91_cf_init(void) { return platform_driver_probe(&at91_cf_driver, at91_cf_probe); } module_init(at91_cf_init); static void __exit at91_cf_exit(void) { platform_driver_unregister(&at91_cf_driver); } module_exit(at91_cf_exit); MODULE_DESCRIPTION("AT91 Compact Flash Driver"); MODULE_AUTHOR("David Brownell"); MODULE_LICENSE("GPL");
/*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef IGTL3DIMAGEDEVICESOURCE_H_HEADER_INCLUDED_ #define IGTL3DIMAGEDEVICESOURCE_H_HEADER_INCLUDED_ #include "mitkIGTLDeviceSource.h" namespace mitk { /** * \brief Connects a mitk::IGTLDevice to a * MITK-OpenIGTLink-Message-Filter-Pipeline * * This class is the source of most OpenIGTLink pipelines. It encapsulates a * mitk::IGTLDevice and provides the information/messages of the connected * OpenIGTLink devices as igtl::MessageBase objects. Note, that there is just * one single output. * */ class MITKOPENIGTLINK_EXPORT IGTL3DImageDeviceSource : public IGTLDeviceSource { public: mitkClassMacro(IGTL3DImageDeviceSource, IGTLDeviceSource); itkFactorylessNewMacro(Self) itkCloneMacro(Self) protected: IGTL3DImageDeviceSource(); virtual ~IGTL3DImageDeviceSource(); /** * \brief filter execute method * * queries the OpenIGTLink device for new messages and updates its output * igtl::MessageBase objects with it. * \warning Will raise a std::out_of_range exception, if tools were added to * the OpenIGTLink device after it was set as input for this filter */ virtual void GenerateData() override; }; } // namespace mitk #endif /* MITKIGTLDeviceSource_H_HEADER_INCLUDED_ */
#include<stdio.h> #define N 25 typedef struct { int parent; int left; int right; }Tree; void PreOrder(int); void InOrder(int); void PostOrder(int); Tree data[N]; int n; int main(){ int i,id,root; scanf("%d",&n); for(i=0;i<n;i++){ data[i].parent=-1; data[i].left=-1; data[i].right=-1; } for(i=0;i<n;i++){ scanf("%d",&id); scanf("%d %d",&data[id].left,&data[id].right); if(data[id].left!=-1) data[data[id].left].parent=id; if(data[id].right!=-1)data[data[id].right].parent=id; } for(i=0;i<n;i++){ if(data[i].parent==-1) root=i; } printf("Preorder\n"); PreOrder(root); printf("\n"); printf("Inorder\n"); InOrder(root); printf("\n"); printf("Postorder\n"); PostOrder(root); printf("\n"); return 0; } void PreOrder(int node){ if(node==-1) return; printf(" %d",node); PreOrder(data[node].left); PreOrder(data[node].right); } void InOrder(int node){ if(node==-1) return; InOrder(data[node].left); printf(" %d",node); InOrder(data[node].right); } void PostOrder(int node){ if(node==-1) return; PostOrder(data[node].left); PostOrder(data[node].right); printf(" %d",node); }
/* * mport_add_mport() - Add rio_mport from LDM device struct * @dev: Linux device model struct * @class_intf: Linux class_interface */ static int mport_add_mport(struct device *dev, struct class_interface *class_intf) { struct rio_mport *mport = NULL; struct mport_dev *chdev = NULL; mport = to_rio_mport(dev); if (!mport) return -ENODEV; chdev = mport_cdev_add(mport); if (!chdev) return -ENODEV; return 0; }
/* * arch/arm/plat-orion/include/plat/addr-map.h * * Marvell Orion SoC address map handling. * * This file is licensed under the terms of the GNU General Public * License version 2. This program is licensed "as is" without any * warranty of any kind, whether express or implied. */ #ifndef __PLAT_ADDR_MAP_H #define __PLAT_ADDR_MAP_H extern struct mbus_dram_target_info orion_mbus_dram_info; struct orion_addr_map_cfg { const int num_wins; /* Total number of windows */ const int remappable_wins; void __iomem *bridge_virt_base; int hw_io_coherency; /* If NULL, the default cpu_win_can_remap will be used, using the value in remappable_wins */ int (*cpu_win_can_remap) (const struct orion_addr_map_cfg *cfg, const int win); /* If NULL, the default win_cfg_base will be used, using the value in bridge_virt_base */ void __iomem *(*win_cfg_base) (const struct orion_addr_map_cfg *cfg, const int win); }; /* * Information needed to setup one address mapping. */ struct orion_addr_map_info { const int win; const u32 base; const u32 size; const u8 target; const u8 attr; const int remap; }; void __init orion_config_wins(struct orion_addr_map_cfg *cfg, const struct orion_addr_map_info *info); void __init orion_setup_cpu_win(const struct orion_addr_map_cfg *cfg, const int win, const u32 base, const u32 size, const u8 target, const u8 attr, const int remap); void __init orion_setup_cpu_mbus_target(const struct orion_addr_map_cfg *cfg, const void __iomem *ddr_window_cpu_base); #endif
// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. #pragma once namespace AttrName { static constexpr const char* AcrossChannels = "across_channels"; static constexpr const char* ActivationAlpha = "activation_alpha"; static constexpr const char* ActivationBeta = "activation_beta"; static constexpr const char* Activations = "activations"; static constexpr const char* AllowZero = "allowzero"; static constexpr const char* Alpha = "alpha"; static constexpr const char* AlignCorners = "align_corners"; static constexpr const char* AutoPad = "auto_pad"; static constexpr const char* Axes = "axes"; static constexpr const char* Axis = "axis"; static constexpr const char* AxisW = "axis_w"; static constexpr const char* BatchAxis = "batch_axis"; static constexpr const char* BatchDimensions = "batch_dims"; static constexpr const char* Beta = "beta"; static constexpr const char* Bias = "bias"; static constexpr const char* BlockSize = "blocksize"; static constexpr const char* Border = "border"; static constexpr const char* Broadcast = "broadcast"; static constexpr const char* CeilMode = "ceil_mode"; static constexpr const char* Clip = "clip"; static constexpr const char* CoordinateTransformationMode = "coordinate_transformation_mode"; static constexpr const char* CountIncludePad = "count_include_pad"; static constexpr const char* CubicCoefficientA = "cubic_coeff_a"; static constexpr const char* DetectPositive = "detect_positive"; static constexpr const char* DetectNegative = "detect_negative"; static constexpr const char* Dilations = "dilations"; static constexpr const char* Direction = "direction"; static constexpr const char* Dtype = "dtype"; static constexpr const char* End = "end"; static constexpr const char* Ends = "ends"; static constexpr const char* Epsilon = "epsilon"; static constexpr const char* Equation = "equation"; static constexpr const char* ExcludeOutside = "exclude_outside"; static constexpr const char* Exclusive = "exclusive"; static constexpr const char* Exponent = "exponent"; static constexpr const char* ExtrapolationValue = "extrapolation_value"; static constexpr const char* Fmod = "fmod"; static constexpr const char* Gamma = "gamma"; static constexpr const char* Group = "group"; static constexpr const char* HeightScale = "height_scale"; static constexpr const char* HiddenSize = "hidden_size"; static constexpr const char* High = "high"; static constexpr const char* InputForget = "input_forget"; static constexpr const char* K = "k"; static constexpr const char* KeepDims = "keepdims"; static constexpr const char* KernelShape = "kernel_shape"; static constexpr const char* LinearBeforeReset = "linear_before_reset"; static constexpr const char* Lambda = "lambd"; // Deliberate typo to match ONNX spec. static constexpr const char* Largest = "largest"; static constexpr const char* Layout = "layout"; static constexpr const char* Low = "low"; static constexpr const char* Max = "max"; static constexpr const char* Mean = "mean"; static constexpr const char* Min = "min"; static constexpr const char* Mode = "mode"; static constexpr const char* NearestMode = "nearest_mode"; static constexpr const char* NewAxis = "new_axis"; static constexpr const char* NoopWithEmptyAxes = "noop_with_empty_axes"; static constexpr const char* NormalizeVariance = "normalize_variance"; static constexpr const char* NumOutputs = "num_outputs"; static constexpr const char* P = "p"; static constexpr const char* PaddingMode = "padding_mode"; static constexpr const char* OutputHeight = "output_height"; static constexpr const char* OutputShape = "output_shape"; static constexpr const char* OutputPadding = "output_padding"; static constexpr const char* OutputWidth = "output_width"; static constexpr const char* Pads = "pads"; static constexpr const char* PooledShape = "pooled_shape"; static constexpr const char* Reduction = "reduction"; static constexpr const char* Reverse = "reverse"; static constexpr const char* SampleSize = "sample_size"; static constexpr const char* SamplingRatio = "sampling_ratio"; static constexpr const char* Scale = "scale"; static constexpr const char* Scales = "scales"; static constexpr const char* Seed = "seed"; static constexpr const char* SelectLastIndex = "select_last_index"; static constexpr const char* Shape = "shape"; static constexpr const char* Size = "size"; static constexpr const char* Sorted = "sorted"; static constexpr const char* Spatial = "spatial"; static constexpr const char* SpatialScale = "spatial_scale"; static constexpr const char* Split = "split"; static constexpr const char* Start = "start"; static constexpr const char* Starts = "starts"; static constexpr const char* Steepness = "steepness"; static constexpr const char* StorageOrder = "storage_order"; static constexpr const char* Strides = "strides"; static constexpr const char* Tiles = "tiles"; static constexpr const char* TimeAxis = "time_axis"; static constexpr const char* To = "to"; static constexpr const char* TrainingMode = "training_mode"; static constexpr const char* TransA = "transA"; static constexpr const char* TransBatchA = "transBatchA"; static constexpr const char* TransB = "transB"; static constexpr const char* TransBatchB = "transBatchB"; static constexpr const char* Upper = "upper"; static constexpr const char* Value = "value"; static constexpr const char* WidthScale = "width_scale"; static constexpr const char* QkvHiddenSizes = "qkv_hidden_sizes"; static constexpr const char* Unidirectional = "unidirectional"; static constexpr const char* NumHeads = "num_heads"; static constexpr const char* FusedActivation = "fused_activation"; static constexpr const char* FusedActivationDomain = "fused_activation_domain"; static constexpr const char* FusedActivationSinceVersion = "fused_activation_since_version"; static constexpr const char* FusedAlpha = "fused_alpha"; static constexpr const char* FusedBeta = "fused_beta"; static constexpr const char* FusedGamma = "fused_gamma"; static constexpr const char* FusedRatio = "fused_ratio"; static constexpr const char* MaskFilterValue = "mask_filter_value"; static constexpr const char* DoRotary = "do_rotary"; static constexpr const char* Activation = "activation"; static constexpr const char* Groups = "groups"; static constexpr const char* GraphFusedActivation = "activation"; static constexpr const char* GraphFusedAxis = "activation_axis"; } // namespace AttrName namespace AttrValue { static constexpr const char* ActivationRelu = "Relu"; static constexpr const char* ActivationLeakyRelu = "LeakyRelu"; static constexpr const char* ActivationThresholdedRelu = "ThresholdedRelu"; static constexpr const char* ActivationTanh = "Tanh"; static constexpr const char* ActivationScaledTanh = "ScaledTanh"; static constexpr const char* ActivationSigmoid = "Sigmoid"; static constexpr const char* ActivationSigmoidHard = "HardSigmoid"; static constexpr const char* ActivationElu = "Elu"; static constexpr const char* ActivationSoftsign = "Softsign"; static constexpr const char* ActivationSoftplus = "Softplus"; static constexpr const char* Bilinear = "BILINEAR"; static constexpr const char* Constant = "constant"; static constexpr const char* DirectionBidirectional = "bidirectional"; static constexpr const char* DirectionForward = "forward"; static constexpr const char* DirectionReverse = "reverse"; static constexpr const char* Edge = "edge"; static constexpr const char* NCHW = "NCHW"; static constexpr const char* NearestNeighbor = "NN"; static constexpr const char* NotSet = "NOTSET"; static constexpr const char* Reflect = "reflect"; } // namespace AttrValue
/* * Similar to TIFFWriteDirectory(), writes the directory out * but leaves all data structures in memory so that it can be * written again. This will make a partially written TIFF file * readable before it is successfully completed/closed. */ int TIFFCheckpointDirectory(TIFF* tif) { int rc; if (tif->tif_dir.td_stripoffset_p == NULL) (void) TIFFSetupStrips(tif); rc = TIFFWriteDirectorySec(tif,TRUE,FALSE,NULL); (void) TIFFSetWriteOffset(tif, TIFFSeekFile(tif, 0, SEEK_END)); return rc; }
/** * Lookup specified X.509 certificate in X509 store * @param store X.509 store * @param cert X.509 certificate * @return True if certificate is found */ static inline bool lookupInStore(X509_STORE *store, X509 *cert) { X509_STORE_CTX *ctx = X509_STORE_CTX_new(); if (!ctx) { return false; } if (!X509_STORE_CTX_init(ctx, store, NULL, NULL)) { return false; } if (!X509_STORE_CTX_set_purpose(ctx, X509_PURPOSE_SSL_CLIENT)) { X509_STORE_CTX_free(ctx); return false; } bool ret = lookupInCtx(ctx, cert); X509_STORE_CTX_free(ctx); return ret; }
/* Synchronize updating contents with the file and the device. */ int vlsync(VILLA *villa){ int err; err = FALSE; if(!vlmemsync(villa)) err = TRUE; if(!dpsync(villa->depot)) err = TRUE; return err ? FALSE : TRUE; }
/* Allocate a floating-point condition-code register of mode MODE. These condition code registers are used for certain kinds of compound operation, such as compare and branches, vconds, and built-in functions. At expand time, their use is entirely controlled by MIPS-specific code and is entirely internal to these compound operations. We could (and did in the past) expose condition-code values as pseudo registers and leave the register allocator to pick appropriate registers. The problem is that it is not practically possible for the rtl optimizers to guarantee that no spills will be needed, even when AVOID_CCMODE_COPIES is defined. We would therefore need spill and reload sequences to handle the worst case. Although such sequences do exist, they are very expensive and are not something we'd want to use. This is especially true of CCV2 and CCV4, where all the shuffling would greatly outweigh whatever benefit the vectorization itself provides. The main benefit of having more than one condition-code register is to allow the pipelining of operations, especially those involving comparisons and conditional moves. We don't really expect the registers to be live for long periods, and certainly never want them to be live across calls. Also, there should be no penalty attached to using all the available registers. They are simply bits in the same underlying FPU control register. We therefore expose the hardware registers from the outset and use a simple round-robin allocation scheme. */ static rtx mips_allocate_fcc (machine_mode mode) { unsigned int regno, count; gcc_assert (TARGET_HARD_FLOAT && ISA_HAS_8CC); if (mode == CCmode) count = 1; else if (mode == CCV2mode) count = 2; else if (mode == CCV4mode) count = 4; else gcc_unreachable (); cfun->machine->next_fcc += -cfun->machine->next_fcc & (count - 1); if (cfun->machine->next_fcc > ST_REG_LAST - ST_REG_FIRST) cfun->machine->next_fcc = 0; regno = ST_REG_FIRST + cfun->machine->next_fcc; cfun->machine->next_fcc += count; return gen_rtx_REG (mode, regno); }
/* * mono_aot_method_hash: * * Return a hash code for methods which only depends on metadata. */ guint32 mono_aot_method_hash (MonoMethod *method) { MonoMethodSignature *sig; MonoClass *klass; int i, hindex; int hashes_count; guint32 *hashes_start, *hashes; guint32 a, b, c; MonoGenericInst *class_ginst = NULL; MonoGenericInst *ginst = NULL; sig = mono_method_signature (method); if (mono_class_is_ginst (method->klass)) class_ginst = mono_class_get_generic_class (method->klass)->context.class_inst; if (method->is_inflated) ginst = ((MonoMethodInflated*)method)->context.method_inst; hashes_count = sig->param_count + 5 + (class_ginst ? class_ginst->type_argc : 0) + (ginst ? ginst->type_argc : 0); hashes_start = (guint32 *)g_malloc0 (hashes_count * sizeof (guint32)); hashes = hashes_start; if (!method->wrapper_type || method->wrapper_type == MONO_WRAPPER_REMOTING_INVOKE_WITH_CHECK) klass = method->klass; else klass = mono_defaults.object_class; if (!method->wrapper_type) { char *full_name; if (mono_class_is_ginst (klass)) full_name = mono_type_full_name (m_class_get_byval_arg (mono_class_get_generic_class (klass)->container_class)); else full_name = mono_type_full_name (m_class_get_byval_arg (klass)); hashes [0] = mono_metadata_str_hash (full_name); hashes [1] = 0; g_free (full_name); } else { hashes [0] = mono_metadata_str_hash (m_class_get_name (klass)); hashes [1] = mono_metadata_str_hash (m_class_get_name_space (klass)); } if (method->wrapper_type == MONO_WRAPPER_STFLD || method->wrapper_type == MONO_WRAPPER_LDFLD || method->wrapper_type == MONO_WRAPPER_LDFLDA) hashes [2] = 0; else hashes [2] = mono_metadata_str_hash (method->name); hashes [3] = method->wrapper_type; hashes [4] = mono_aot_type_hash (sig->ret); hindex = 5; for (i = 0; i < sig->param_count; i++) { hashes [hindex ++] = mono_aot_type_hash (sig->params [i]); } if (class_ginst) { for (i = 0; i < class_ginst->type_argc; ++i) hashes [hindex ++] = mono_aot_type_hash (class_ginst->type_argv [i]); } if (ginst) { for (i = 0; i < ginst->type_argc; ++i) hashes [hindex ++] = mono_aot_type_hash (ginst->type_argv [i]); } g_assert (hindex == hashes_count); a = b = c = 0xdeadbeef + (((guint32)hashes_count)<<2); while (hashes_count > 3) { a += hashes [0]; b += hashes [1]; c += hashes [2]; mix (a,b,c); hashes_count -= 3; hashes += 3; } switch (hashes_count) { case 3 : c += hashes [2]; case 2 : b += hashes [1]; case 1 : a += hashes [0]; final (a,b,c); case 0: break; } g_free (hashes_start); return c; }
/** * Check if the control point is activated. * * @param ctrlPoint The control point to stop * * @return TRUE if running; otherwise FALSE * */ BOOL cg_upnp_controlpoint_isrunning(CgUpnpControlPoint *ctrlPoint) { CgHttpServerList *httpServerList; httpServerList = cg_upnp_controlpoint_gethttpserverlist(ctrlPoint); if (cg_http_serverlist_size(httpServerList) == 0) return FALSE; return TRUE; }
#include <stdio.h> int main(){ long m,s,a[200],i,ss; scanf("%ld %ld",&m,&s); ss=s; if ((s==0)&&(m==1)){ printf("0 0\n"); return(0); } if (s==0){ printf("-1 -1\n"); return(0); } if (s>m*9){ printf("-1 -1\n"); return(0); } else{ i=m; if (s-1<=i*9-9){ a[i]=1; i--; s--; } else{ a[i]=s-(i*9-9); s-=a[i]; i--; } while (i>0){ if (s<=i*9-9){ a[i]=0; i--; } else{ a[i]=s-i*9+9; s-=a[i]; i--; } } for (i=m;i>=1;i--) printf("%ld",a[i]); printf(" "); i=m; while (i>0){ if (ss>=9){ a[i]=9; i--; ss-=9; } else{ a[i]=ss; ss-=a[i]; i--; } } for (i=m;i>=1;i--) printf("%ld",a[i]); printf("\n"); } }
/* Free vars used for code hoisting analysis. */ static void free_code_hoist_mem (void) { sbitmap_vector_free (antloc); sbitmap_vector_free (transp); sbitmap_vector_free (comp); sbitmap_vector_free (hoist_vbein); sbitmap_vector_free (hoist_vbeout); sbitmap_vector_free (hoist_exprs); sbitmap_vector_free (transpout); free_dominance_info (CDI_DOMINATORS); }
/* this will disable all gates passed in mask, will not change rate & src */ static int s3x_clkd_disable_gate(S3x_ClkD *clkd, UINT16_t mask) { s3x_clkd_set_gate_mask(clkd, mask, 0); if(!(clkd->gate_val) && (!(clkd->flags & HW_GATED))) s3x_disable_src_div(clkd); return STATUS_OK; }
/* Writes arbitrary data into the buffer out. */ void write_unconstrained_data(unsigned char *out, size_t len) { assert(AWS_MEM_IS_WRITABLE(out, len)); char start; __CPROVER_array_copy( out, &start); }
/*interface*/ #include<stdio.h> #define N 256 /*interface implementation*/ /*client*/ int main() { int n,k; scanf("%d%d",&n,&k); int i; getchar(); int times[N]; for(i=0; i<N; i++) { times[i]=0; } for(i=0; i<n; i++) { char card=getchar(); times[(int)card]++; } long long coins=0; while(1) { int max_i='A'; int max=times['A']; for(i='B'; i<='Z'; i++) { if(times[i]>max) { max_i=i; max=times[i]; } } if(max>=k) { long long k2=(long long)k; //两个10^5相乘就出界了! long long kk=k2*k2; coins=coins+kk; break; } else { times[max_i]=0; long long max2=(long long)max; long long mmax=max2*max2; coins=coins+mmax; k=k-max; } } printf("%lld\n",coins); return 0; }
/* * ALSA sequencer Ports * Copyright (c) 1998 by Frank van de Pol <fvdpol@coil.demon.nl> * Jaroslav Kysela <perex@perex.cz> * * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include <sound/core.h> #include <linux/slab.h> #include <linux/module.h> #include "seq_system.h" #include "seq_ports.h" #include "seq_clientmgr.h" /* registration of client ports */ /* NOTE: the current implementation of the port structure as a linked list is not optimal for clients that have many ports. For sending messages to all subscribers of a port we first need to find the address of the port structure, which means we have to traverse the list. A direct access table (array) would be better, but big preallocated arrays waste memory. Possible actions: 1) leave it this way, a client does normaly does not have more than a few ports 2) replace the linked list of ports by a array of pointers which is dynamicly kmalloced. When a port is added or deleted we can simply allocate a new array, copy the corresponding pointers, and delete the old one. We then only need a pointer to this array, and an integer that tells us how much elements are in array. */ /* return pointer to port structure - port is locked if found */ struct snd_seq_client_port *snd_seq_port_use_ptr(struct snd_seq_client *client, int num) { struct snd_seq_client_port *port; if (client == NULL) return NULL; read_lock(&client->ports_lock); list_for_each_entry(port, &client->ports_list_head, list) { if (port->addr.port == num) { if (port->closing) break; /* deleting now */ snd_use_lock_use(&port->use_lock); read_unlock(&client->ports_lock); return port; } } read_unlock(&client->ports_lock); return NULL; /* not found */ } /* search for the next port - port is locked if found */ struct snd_seq_client_port *snd_seq_port_query_nearest(struct snd_seq_client *client, struct snd_seq_port_info *pinfo) { int num; struct snd_seq_client_port *port, *found; num = pinfo->addr.port; found = NULL; read_lock(&client->ports_lock); list_for_each_entry(port, &client->ports_list_head, list) { if (port->addr.port < num) continue; if (port->addr.port == num) { found = port; break; } if (found == NULL || port->addr.port < found->addr.port) found = port; } if (found) { if (found->closing) found = NULL; else snd_use_lock_use(&found->use_lock); } read_unlock(&client->ports_lock); return found; } /* initialize snd_seq_port_subs_info */ static void port_subs_info_init(struct snd_seq_port_subs_info *grp) { INIT_LIST_HEAD(&grp->list_head); grp->count = 0; grp->exclusive = 0; rwlock_init(&grp->list_lock); init_rwsem(&grp->list_mutex); grp->open = NULL; grp->close = NULL; } /* create a port, port number is returned (-1 on failure) */ struct snd_seq_client_port *snd_seq_create_port(struct snd_seq_client *client, int port) { unsigned long flags; struct snd_seq_client_port *new_port, *p; int num = -1; /* sanity check */ if (snd_BUG_ON(!client)) return NULL; if (client->num_ports >= SNDRV_SEQ_MAX_PORTS) { pr_warn("ALSA: seq: too many ports for client %d\n", client->number); return NULL; } /* create a new port */ new_port = kzalloc(sizeof(*new_port), GFP_KERNEL); if (!new_port) return NULL; /* failure, out of memory */ /* init port data */ new_port->addr.client = client->number; new_port->addr.port = -1; new_port->owner = THIS_MODULE; sprintf(new_port->name, "port-%d", num); snd_use_lock_init(&new_port->use_lock); port_subs_info_init(&new_port->c_src); port_subs_info_init(&new_port->c_dest); num = port >= 0 ? port : 0; mutex_lock(&client->ports_mutex); write_lock_irqsave(&client->ports_lock, flags); list_for_each_entry(p, &client->ports_list_head, list) { if (p->addr.port > num) break; if (port < 0) /* auto-probe mode */ num = p->addr.port + 1; } /* insert the new port */ list_add_tail(&new_port->list, &p->list); client->num_ports++; new_port->addr.port = num; /* store the port number in the port */ write_unlock_irqrestore(&client->ports_lock, flags); mutex_unlock(&client->ports_mutex); sprintf(new_port->name, "port-%d", num); return new_port; } /* */ static int subscribe_port(struct snd_seq_client *client, struct snd_seq_client_port *port, struct snd_seq_port_subs_info *grp, struct snd_seq_port_subscribe *info, int send_ack); static int unsubscribe_port(struct snd_seq_client *client, struct snd_seq_client_port *port, struct snd_seq_port_subs_info *grp, struct snd_seq_port_subscribe *info, int send_ack); static struct snd_seq_client_port *get_client_port(struct snd_seq_addr *addr, struct snd_seq_client **cp) { struct snd_seq_client_port *p; *cp = snd_seq_client_use_ptr(addr->client); if (*cp) { p = snd_seq_port_use_ptr(*cp, addr->port); if (! p) { snd_seq_client_unlock(*cp); *cp = NULL; } return p; } return NULL; } static void delete_and_unsubscribe_port(struct snd_seq_client *client, struct snd_seq_client_port *port, struct snd_seq_subscribers *subs, bool is_src, bool ack); static inline struct snd_seq_subscribers * get_subscriber(struct list_head *p, bool is_src) { if (is_src) return list_entry(p, struct snd_seq_subscribers, src_list); else return list_entry(p, struct snd_seq_subscribers, dest_list); } /* * remove all subscribers on the list * this is called from port_delete, for each src and dest list. */ static void clear_subscriber_list(struct snd_seq_client *client, struct snd_seq_client_port *port, struct snd_seq_port_subs_info *grp, int is_src) { struct list_head *p, *n; list_for_each_safe(p, n, &grp->list_head) { struct snd_seq_subscribers *subs; struct snd_seq_client *c; struct snd_seq_client_port *aport; subs = get_subscriber(p, is_src); if (is_src) aport = get_client_port(&subs->info.dest, &c); else aport = get_client_port(&subs->info.sender, &c); delete_and_unsubscribe_port(client, port, subs, is_src, false); if (!aport) { /* looks like the connected port is being deleted. * we decrease the counter, and when both ports are deleted * remove the subscriber info */ if (atomic_dec_and_test(&subs->ref_count)) kfree(subs); continue; } /* ok we got the connected port */ delete_and_unsubscribe_port(c, aport, subs, !is_src, true); kfree(subs); snd_seq_port_unlock(aport); snd_seq_client_unlock(c); } } /* delete port data */ static int port_delete(struct snd_seq_client *client, struct snd_seq_client_port *port) { /* set closing flag and wait for all port access are gone */ port->closing = 1; snd_use_lock_sync(&port->use_lock); /* clear subscribers info */ clear_subscriber_list(client, port, &port->c_src, true); clear_subscriber_list(client, port, &port->c_dest, false); if (port->private_free) port->private_free(port->private_data); snd_BUG_ON(port->c_src.count != 0); snd_BUG_ON(port->c_dest.count != 0); kfree(port); return 0; } /* delete a port with the given port id */ int snd_seq_delete_port(struct snd_seq_client *client, int port) { unsigned long flags; struct snd_seq_client_port *found = NULL, *p; mutex_lock(&client->ports_mutex); write_lock_irqsave(&client->ports_lock, flags); list_for_each_entry(p, &client->ports_list_head, list) { if (p->addr.port == port) { /* ok found. delete from the list at first */ list_del(&p->list); client->num_ports--; found = p; break; } } write_unlock_irqrestore(&client->ports_lock, flags); mutex_unlock(&client->ports_mutex); if (found) return port_delete(client, found); else return -ENOENT; } /* delete the all ports belonging to the given client */ int snd_seq_delete_all_ports(struct snd_seq_client *client) { unsigned long flags; struct list_head deleted_list; struct snd_seq_client_port *port, *tmp; /* move the port list to deleted_list, and * clear the port list in the client data. */ mutex_lock(&client->ports_mutex); write_lock_irqsave(&client->ports_lock, flags); if (! list_empty(&client->ports_list_head)) { list_add(&deleted_list, &client->ports_list_head); list_del_init(&client->ports_list_head); } else { INIT_LIST_HEAD(&deleted_list); } client->num_ports = 0; write_unlock_irqrestore(&client->ports_lock, flags); /* remove each port in deleted_list */ list_for_each_entry_safe(port, tmp, &deleted_list, list) { list_del(&port->list); snd_seq_system_client_ev_port_exit(port->addr.client, port->addr.port); port_delete(client, port); } mutex_unlock(&client->ports_mutex); return 0; } /* set port info fields */ int snd_seq_set_port_info(struct snd_seq_client_port * port, struct snd_seq_port_info * info) { if (snd_BUG_ON(!port || !info)) return -EINVAL; /* set port name */ if (info->name[0]) strlcpy(port->name, info->name, sizeof(port->name)); /* set capabilities */ port->capability = info->capability; /* get port type */ port->type = info->type; /* information about supported channels/voices */ port->midi_channels = info->midi_channels; port->midi_voices = info->midi_voices; port->synth_voices = info->synth_voices; /* timestamping */ port->timestamping = (info->flags & SNDRV_SEQ_PORT_FLG_TIMESTAMP) ? 1 : 0; port->time_real = (info->flags & SNDRV_SEQ_PORT_FLG_TIME_REAL) ? 1 : 0; port->time_queue = info->time_queue; return 0; } /* get port info fields */ int snd_seq_get_port_info(struct snd_seq_client_port * port, struct snd_seq_port_info * info) { if (snd_BUG_ON(!port || !info)) return -EINVAL; /* get port name */ strlcpy(info->name, port->name, sizeof(info->name)); /* get capabilities */ info->capability = port->capability; /* get port type */ info->type = port->type; /* information about supported channels/voices */ info->midi_channels = port->midi_channels; info->midi_voices = port->midi_voices; info->synth_voices = port->synth_voices; /* get subscriber counts */ info->read_use = port->c_src.count; info->write_use = port->c_dest.count; /* timestamping */ info->flags = 0; if (port->timestamping) { info->flags |= SNDRV_SEQ_PORT_FLG_TIMESTAMP; if (port->time_real) info->flags |= SNDRV_SEQ_PORT_FLG_TIME_REAL; info->time_queue = port->time_queue; } return 0; } /* * call callback functions (if any): * the callbacks are invoked only when the first (for connection) or * the last subscription (for disconnection) is done. Second or later * subscription results in increment of counter, but no callback is * invoked. * This feature is useful if these callbacks are associated with * initialization or termination of devices (see seq_midi.c). */ static int subscribe_port(struct snd_seq_client *client, struct snd_seq_client_port *port, struct snd_seq_port_subs_info *grp, struct snd_seq_port_subscribe *info, int send_ack) { int err = 0; if (!try_module_get(port->owner)) return -EFAULT; grp->count++; if (grp->open && grp->count == 1) { err = grp->open(port->private_data, info); if (err < 0) { module_put(port->owner); grp->count--; } } if (err >= 0 && send_ack && client->type == USER_CLIENT) snd_seq_client_notify_subscription(port->addr.client, port->addr.port, info, SNDRV_SEQ_EVENT_PORT_SUBSCRIBED); return err; } static int unsubscribe_port(struct snd_seq_client *client, struct snd_seq_client_port *port, struct snd_seq_port_subs_info *grp, struct snd_seq_port_subscribe *info, int send_ack) { int err = 0; if (! grp->count) return -EINVAL; grp->count--; if (grp->close && grp->count == 0) err = grp->close(port->private_data, info); if (send_ack && client->type == USER_CLIENT) snd_seq_client_notify_subscription(port->addr.client, port->addr.port, info, SNDRV_SEQ_EVENT_PORT_UNSUBSCRIBED); module_put(port->owner); return err; } /* check if both addresses are identical */ static inline int addr_match(struct snd_seq_addr *r, struct snd_seq_addr *s) { return (r->client == s->client) && (r->port == s->port); } /* check the two subscribe info match */ /* if flags is zero, checks only sender and destination addresses */ static int match_subs_info(struct snd_seq_port_subscribe *r, struct snd_seq_port_subscribe *s) { if (addr_match(&r->sender, &s->sender) && addr_match(&r->dest, &s->dest)) { if (r->flags && r->flags == s->flags) return r->queue == s->queue; else if (! r->flags) return 1; } return 0; } static int check_and_subscribe_port(struct snd_seq_client *client, struct snd_seq_client_port *port, struct snd_seq_subscribers *subs, bool is_src, bool exclusive, bool ack) { struct snd_seq_port_subs_info *grp; struct list_head *p; struct snd_seq_subscribers *s; int err; grp = is_src ? &port->c_src : &port->c_dest; err = -EBUSY; down_write(&grp->list_mutex); if (exclusive) { if (!list_empty(&grp->list_head)) goto __error; } else { if (grp->exclusive) goto __error; /* check whether already exists */ list_for_each(p, &grp->list_head) { s = get_subscriber(p, is_src); if (match_subs_info(&subs->info, &s->info)) goto __error; } } err = subscribe_port(client, port, grp, &subs->info, ack); if (err < 0) { grp->exclusive = 0; goto __error; } /* add to list */ write_lock_irq(&grp->list_lock); if (is_src) list_add_tail(&subs->src_list, &grp->list_head); else list_add_tail(&subs->dest_list, &grp->list_head); grp->exclusive = exclusive; atomic_inc(&subs->ref_count); write_unlock_irq(&grp->list_lock); err = 0; __error: up_write(&grp->list_mutex); return err; } static void delete_and_unsubscribe_port(struct snd_seq_client *client, struct snd_seq_client_port *port, struct snd_seq_subscribers *subs, bool is_src, bool ack) { struct snd_seq_port_subs_info *grp; struct list_head *list; bool empty; grp = is_src ? &port->c_src : &port->c_dest; list = is_src ? &subs->src_list : &subs->dest_list; down_write(&grp->list_mutex); write_lock_irq(&grp->list_lock); empty = list_empty(list); if (!empty) list_del_init(list); grp->exclusive = 0; write_unlock_irq(&grp->list_lock); up_write(&grp->list_mutex); if (!empty) unsubscribe_port(client, port, grp, &subs->info, ack); } /* connect two ports */ int snd_seq_port_connect(struct snd_seq_client *connector, struct snd_seq_client *src_client, struct snd_seq_client_port *src_port, struct snd_seq_client *dest_client, struct snd_seq_client_port *dest_port, struct snd_seq_port_subscribe *info) { struct snd_seq_subscribers *subs; bool exclusive; int err; subs = kzalloc(sizeof(*subs), GFP_KERNEL); if (!subs) return -ENOMEM; subs->info = *info; atomic_set(&subs->ref_count, 0); INIT_LIST_HEAD(&subs->src_list); INIT_LIST_HEAD(&subs->dest_list); exclusive = !!(info->flags & SNDRV_SEQ_PORT_SUBS_EXCLUSIVE); err = check_and_subscribe_port(src_client, src_port, subs, true, exclusive, connector->number != src_client->number); if (err < 0) goto error; err = check_and_subscribe_port(dest_client, dest_port, subs, false, exclusive, connector->number != dest_client->number); if (err < 0) goto error_dest; return 0; error_dest: delete_and_unsubscribe_port(src_client, src_port, subs, true, connector->number != src_client->number); error: kfree(subs); return err; } /* remove the connection */ int snd_seq_port_disconnect(struct snd_seq_client *connector, struct snd_seq_client *src_client, struct snd_seq_client_port *src_port, struct snd_seq_client *dest_client, struct snd_seq_client_port *dest_port, struct snd_seq_port_subscribe *info) { struct snd_seq_port_subs_info *src = &src_port->c_src; struct snd_seq_subscribers *subs; int err = -ENOENT; down_write(&src->list_mutex); /* look for the connection */ list_for_each_entry(subs, &src->list_head, src_list) { if (match_subs_info(info, &subs->info)) { atomic_dec(&subs->ref_count); /* mark as not ready */ err = 0; break; } } up_write(&src->list_mutex); if (err < 0) return err; delete_and_unsubscribe_port(src_client, src_port, subs, true, connector->number != src_client->number); delete_and_unsubscribe_port(dest_client, dest_port, subs, false, connector->number != dest_client->number); kfree(subs); return 0; } /* get matched subscriber */ struct snd_seq_subscribers *snd_seq_port_get_subscription(struct snd_seq_port_subs_info *src_grp, struct snd_seq_addr *dest_addr) { struct snd_seq_subscribers *s, *found = NULL; down_read(&src_grp->list_mutex); list_for_each_entry(s, &src_grp->list_head, src_list) { if (addr_match(dest_addr, &s->info.dest)) { found = s; break; } } up_read(&src_grp->list_mutex); return found; } /* * Attach a device driver that wants to receive events from the * sequencer. Returns the new port number on success. * A driver that wants to receive the events converted to midi, will * use snd_seq_midisynth_register_port(). */ /* exported */ int snd_seq_event_port_attach(int client, struct snd_seq_port_callback *pcbp, int cap, int type, int midi_channels, int midi_voices, char *portname) { struct snd_seq_port_info portinfo; int ret; /* Set up the port */ memset(&portinfo, 0, sizeof(portinfo)); portinfo.addr.client = client; strlcpy(portinfo.name, portname ? portname : "Unamed port", sizeof(portinfo.name)); portinfo.capability = cap; portinfo.type = type; portinfo.kernel = pcbp; portinfo.midi_channels = midi_channels; portinfo.midi_voices = midi_voices; /* Create it */ ret = snd_seq_kernel_client_ctl(client, SNDRV_SEQ_IOCTL_CREATE_PORT, &portinfo); if (ret >= 0) ret = portinfo.addr.port; return ret; } EXPORT_SYMBOL(snd_seq_event_port_attach); /* * Detach the driver from a port. */ /* exported */ int snd_seq_event_port_detach(int client, int port) { struct snd_seq_port_info portinfo; int err; memset(&portinfo, 0, sizeof(portinfo)); portinfo.addr.client = client; portinfo.addr.port = port; err = snd_seq_kernel_client_ctl(client, SNDRV_SEQ_IOCTL_DELETE_PORT, &portinfo); return err; } EXPORT_SYMBOL(snd_seq_event_port_detach);
/* * mtx is a slightly simplified version of malloc_mutex. This code duplication * is unfortunate, but there are allocator bootstrapping considerations that * would leak into the test infrastructure if malloc_mutex were used directly * in tests. */ typedef struct { #ifdef _WIN32 CRITICAL_SECTION lock; #elif (defined(JEMALLOC_OSSPIN)) OSSpinLock lock; #else pthread_mutex_t lock; #endif } mtx_t; bool mtx_init(mtx_t *mtx); void mtx_fini(mtx_t *mtx); void mtx_lock(mtx_t *mtx); void mtx_unlock(mtx_t *mtx);
#include<stdio.h> main() { int i, ans=0, a, b; scanf("%d", &a); for(i=2; i<a; i++) { ans+=a%i; b=a; while(b/i!=0) { b/=i; ans+=b%i; } } b=i-2; for(a=2; a<=b; a++) { if(ans%a==0 && b%a==0) { ans/=a; b/=a; a=1; } } printf("%d/%d", ans, b); }
/** * alloc a buffer item from somewhere. * * In the future there might be a fixed stack pool of buffers (very likely) * such that stack buffers are used first until there are none free to use * after which malloc'd buffers are allocated and freed as necessary. * * Keeping a set of stack buffers may substantially speed up buffering * as no malloc/free calls would be needed. * * That is the reasoning for the api. * * notably the requested size may be different than the returned size. */ static inline octo_buffer_chunk * octo_buffer_chunk_alloc(size_t len) { octo_buffer_chunk *item; item = malloc(sizeof(octo_buffer_chunk) + len); if(item == NULL) { perror("malloc"); return NULL; } item->start = 0; item->size = 0; item->capacity = len; return item; }
#include<stdio.h> int main (){ int w, h , k; int sum = 0; scanf("%d%d%d",&w,&h,&k); while(k--) { sum+=(w+h)*2-4; w-=4;h-=4; } printf("%d",sum); }
/** Codel initModule of activity DedicatedSocket. * * Triggered by bass_start. * Yields to bass_ether, bass_recv. */ genom_event initModule(const bass_Audio *Audio, genom_context self) { uint32_t i; server_sockfd = socket(AF_INET, SOCK_STREAM, 0); if(server_sockfd < 0) { printf("ERROR: Socket not opened.\n"); return bass_ether; } printf("Socket opened.\n"); bzero((char *)&serv_addr, sizeof(serv_addr)); portno = 8081; serv_addr.sin_family = AF_INET; serv_addr.sin_addr.s_addr = INADDR_ANY; serv_addr.sin_port = htons(portno); if (setsockopt(server_sockfd,SOL_SOCKET,SO_REUSEADDR,&yes,sizeof(int)) == -1) { printf("ERROR: setsockopt.\n"); return bass_ether; } if(bind(server_sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) { printf("Error binding.\n"); close(server_sockfd); return bass_ether; } printf("Bind correctly\n"); listen(server_sockfd, 5); fd_set writefds, read_fds; struct timeval timeout; timeout.tv_usec = 5000; FD_ZERO(&writefds); FD_SET(client_sockfd, &writefds); numfds = 0; memset(poll_set, '\0', sizeof(poll_set)); poll_set[numfds].fd = server_sockfd; poll_set[numfds].events = POLLIN; numfds++; max_fd = server_sockfd; end = 0; sizeofMessage = 2*(Audio->data(self)->nChunksOnPort*Audio->data(self)->nFramesPerChunk)*sizeof(int32_t); message = malloc(sizeofMessage); messageInfo = malloc(infoSize*sizeof(int32_t)); return bass_recv; }
#include<stdio.h> int main() { int n,i,b,d; scanf("%d",&n); char s[10][10]={ "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", }; char a[10][15]={ "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen", }; char c[8][10]={ "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety", }; if(n<10) printf("%s\n",s[n]); else if(n<20) { printf("%s\n",a[n-10]); } else if(n%10==0) { printf("%s\n",c[(n/10)-2]); } else { b=n%10; d=n/10; printf("%s-%s\n",c[d-2],s[b]); } return 0; }
// This file is part of libigl, a simple c++ geometry processing library. // // Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com> // // This Source Code Form is subject to the terms of the Mozilla Public License // v. 2.0. If a copy of the MPL was not distributed with this file, You can // obtain one at http://mozilla.org/MPL/2.0/. #ifndef IGL_ARAP_H #define IGL_ARAP_H #include "igl_inline.h" #include "min_quad_with_fixed.h" #include "ARAPEnergyType.h" #include <Eigen/Core> #include <Eigen/Sparse> namespace igl { struct ARAPData { // n #V // G #V list of group indices (1 to k) for each vertex, such that vertex i // is assigned to group G(i) // energy type of energy to use // with_dynamics whether using dynamics (need to call arap_precomputation // after changing) // f_ext #V by dim list of external forces // vel #V by dim list of velocities // h dynamics time step // ym ~Young's modulus smaller is softer, larger is more rigid/stiff // max_iter maximum inner iterations // K rhs pre-multiplier // M mass matrix // solver_data quadratic solver data // b list of boundary indices into V // dim dimension being used for solving int n; Eigen::VectorXi G; ARAPEnergyType energy; bool with_dynamics; Eigen::MatrixXd f_ext,vel; double h; double ym; int max_iter; Eigen::SparseMatrix<double> K,M; Eigen::SparseMatrix<double> CSM; min_quad_with_fixed_data<double> solver_data; Eigen::VectorXi b; int dim; ARAPData(): n(0), G(), energy(ARAP_ENERGY_TYPE_DEFAULT), with_dynamics(false), f_ext(), h(1), ym(1), max_iter(10), K(), CSM(), solver_data(), b(), dim(-1) // force this to be set by _precomputation { }; }; // Compute necessary information to start using an ARAP deformation // // Inputs: // V #V by dim list of mesh positions // F #F by simplex-size list of triangle|tet indices into V // dim dimension being used at solve time. For deformation usually dim = // V.cols(), for surface parameterization V.cols() = 3 and dim = 2 // b #b list of "boundary" fixed vertex indices into V // Outputs: // data struct containing necessary precomputation template < typename DerivedV, typename DerivedF, typename Derivedb> IGL_INLINE bool arap_precomputation( const Eigen::PlainObjectBase<DerivedV> & V, const Eigen::PlainObjectBase<DerivedF> & F, const int dim, const Eigen::PlainObjectBase<Derivedb> & b, ARAPData & data); // Inputs: // bc #b by dim list of boundary conditions // data struct containing necessary precomputation and parameters // U #V by dim initial guess template < typename Derivedbc, typename DerivedU> IGL_INLINE bool arap_solve( const Eigen::PlainObjectBase<Derivedbc> & bc, ARAPData & data, Eigen::PlainObjectBase<DerivedU> & U); }; #ifndef IGL_STATIC_LIBRARY #include "arap.cpp" #endif #endif
#ifndef SATPROVINGENGINE_H #define SATPROVINGENGINE_H #include "common.h" #include "CLTheory/Theory.h" #include "CLProof/CLProof.h" #include "ProvingEngine/ProvingEngine.h" using namespace std; class URSA_ProvingEngine : public ProvingEngine { public: URSA_ProvingEngine(Theory *pT, proverParams& params); void AddPremise(const Fact& f); bool ProveFromPremises(const DNFFormula& formula, CLProof& proof); virtual void SetTimeLimit(unsigned timeLimit); virtual PROVING_ENGINE GetKind() { return eURSA_ProvingEngine; } private: void EncodeAxiom(size_t no, CLFormula& axiom, string name); void EncodeHint(const tHint& hint); void EncodeProof(const DNFFormula& formula); string mURSAstringAxioms; string mURSAstringPremises; string mURSAstringHints; }; #endif // SATPROVINGENGINE_H
/** * Parse a series of data segments for page fault handling. * * @qp the QP on which the fault occurred. * @pfault contains page fault information. * @wqe points at the first data segment in the WQE. * @wqe_end points after the end of the WQE. * @bytes_mapped receives the number of bytes that the function was able to * map. This allows the caller to decide intelligently whether * enough memory was mapped to resolve the page fault * successfully (e.g. enough for the next MTU, or the entire * WQE). * @total_wqe_bytes receives the total data size of this WQE in bytes (minus * the committed bytes). * * Returns the number of pages loaded if positive, zero for an empty WQE, or a * negative error code. */ static int pagefault_data_segments(struct mlx5_ib_qp *qp, struct mlx5_ib_pfault *pfault, void *wqe, void *wqe_end, u32 *bytes_mapped, u32 *total_wqe_bytes, int receive_queue) { int ret = 0, npages = 0; u64 io_virt; u32 key; u32 byte_count; size_t bcnt; int inline_segment; if (receive_queue && qp->ibqp.srq) wqe += sizeof(struct mlx5_wqe_srq_next_seg); if (bytes_mapped) *bytes_mapped = 0; if (total_wqe_bytes) *total_wqe_bytes = 0; while (wqe < wqe_end) { struct mlx5_wqe_data_seg *dseg = wqe; io_virt = be64_to_cpu(dseg->addr); key = be32_to_cpu(dseg->lkey); byte_count = be32_to_cpu(dseg->byte_count); inline_segment = !!(byte_count & MLX5_INLINE_SEG); bcnt = byte_count & ~MLX5_INLINE_SEG; if (inline_segment) { bcnt = bcnt & MLX5_WQE_INLINE_SEG_BYTE_COUNT_MASK; wqe += ALIGN(sizeof(struct mlx5_wqe_inline_seg) + bcnt, 16); } else { wqe += sizeof(*dseg); } if (receive_queue && bcnt == 0 && key == MLX5_INVALID_LKEY && io_virt == 0) break; if (!inline_segment && total_wqe_bytes) { *total_wqe_bytes += bcnt - min_t(size_t, bcnt, pfault->mpfault.bytes_committed); } if (bcnt == 0) bcnt = 1U << 31; if (inline_segment || bcnt <= pfault->mpfault.bytes_committed) { pfault->mpfault.bytes_committed -= min_t(size_t, bcnt, pfault->mpfault.bytes_committed); continue; } ret = pagefault_single_data_segment(qp, pfault, key, io_virt, bcnt, bytes_mapped); if (ret < 0) break; npages += ret; } return ret < 0 ? ret : npages; }
// // Locate the primary temp input on the coretemp sysfs // static int cpuid_findcpusensorpath(const char * path) { #define MAX_SENSOR_PATHS 16 DIR * dirp; struct dirent * dp; char tbuf[MAX_SENSOR_PATHS][32] = {{0}}; int cnt = 0, i = 0, sensorx = 0; char sensor[8] = {0}; dirp = opendir(path); if (dirp == NULL) return -1; snprintf(sensor, sizeof(sensor), "temp%d", sensorx); while (cnt < (MAX_SENSOR_PATHS - 1) && (dp = readdir(dirp)) != NULL) { if (!strncmp(dp->d_name, sensor, 5)) { (void) closedir(dirp); if (asprintf(&cpuinfo.cputemppath, "%stemp%d_input", CORETEMP_PATH, sensorx) == -1) { perror("asprintf"); } return sensorx; } else if (!strncmp(dp->d_name, "temp", 4)) { strncpy(tbuf[cnt], dp->d_name, 31); tbuf[cnt][31] = '\0'; if (cnt < (MAX_SENSOR_PATHS - 1)) ++cnt; } } (void) closedir(dirp); for (sensorx = 1; sensorx < 8; sensorx++) for (i = 0; i < cnt; i++) { snprintf(sensor, sizeof(sensor), "temp%d", sensorx); if (!strncasecmp(tbuf[i], sensor, strlen(sensor))) { if (asprintf(&cpuinfo.cputemppath, "%stemp%d_input", CORETEMP_PATH, sensorx) == -1) { perror("asprintf"); } return sensorx; } } return -1; }
/* * Copyright (c) 2023 bytes at work AG * Copyright (c) 2020 Teslabs Engineering S.L. * * SPDX-License-Identifier: Apache-2.0 */ #define DT_DRV_COMPAT orisetech_otm8009a #include <zephyr/kernel.h> #include <zephyr/drivers/display.h> #include <zephyr/drivers/mipi_dsi.h> #include <zephyr/drivers/gpio.h> #include <zephyr/sys/byteorder.h> #include <zephyr/logging/log.h> LOG_MODULE_REGISTER(otm8009a, CONFIG_DISPLAY_LOG_LEVEL); #include "display_otm8009a.h" struct otm8009a_config { const struct device *mipi_dsi; const struct gpio_dt_spec reset; const struct gpio_dt_spec backlight; uint8_t data_lanes; uint16_t width; uint16_t height; uint8_t channel; uint16_t rotation; }; struct otm8009a_data { uint16_t xres; uint16_t yres; uint8_t dsi_pixel_format; enum display_pixel_format pixel_format; enum display_orientation orientation; }; static inline int otm8009a_dcs_write(const struct device *dev, uint8_t cmd, const void *buf, size_t len) { const struct otm8009a_config *cfg = dev->config; int ret; ret = mipi_dsi_dcs_write(cfg->mipi_dsi, cfg->channel, cmd, buf, len); if (ret < 0) { LOG_ERR("DCS 0x%x write failed! (%d)", cmd, ret); return ret; } return 0; } static int otm8009a_mcs_write(const struct device *dev, uint16_t cmd, const void *buf, size_t len) { const struct otm8009a_config *cfg = dev->config; uint8_t scmd; int ret; scmd = cmd & 0xFF; ret = mipi_dsi_dcs_write(cfg->mipi_dsi, cfg->channel, OTM8009A_MCS_ADRSFT, &scmd, 1); if (ret < 0) { return ret; } ret = mipi_dsi_dcs_write(cfg->mipi_dsi, cfg->channel, cmd >> 8, buf, len); if (ret < 0) { return ret; } return 0; } static int otm8009a_check_id(const struct device *dev) { const struct otm8009a_config *cfg = dev->config; uint32_t id = 0; int ret; ret = mipi_dsi_dcs_read(cfg->mipi_dsi, cfg->channel, OTM8009A_CMD_ID1, &id, sizeof(id)); if (ret != sizeof(id)) { LOG_ERR("Read panel ID failed! (%d)", ret); return -EIO; } if (id != OTM8009A_ID1) { LOG_ERR("ID 0x%x (should 0x%x)", id, OTM8009A_ID1); return -EINVAL; } return 0; } static int otm8009a_configure(const struct device *dev) { struct otm8009a_data *data = dev->data; uint8_t buf[4]; int ret; static const uint8_t pwr_ctrl2[] = {0x96, 0x34, 0x01, 0x33, 0x33, 0x34, 0x33}; static const uint8_t sd_ctrl[] = {0x0D, 0x1B, 0x02, 0x01, 0x3C, 0x08}; static const uint8_t goavst[] = { 0x85, 0x01, 0x00, 0x84, 0x01, 0x00, 0x81, 0x01, 0x28, 0x82, 0x01, 0x28 }; static const uint8_t goaclka1[] = {0x18, 0x04, 0x03, 0x39, 0x00, 0x00, 0x00}; static const uint8_t goaclka2[] = {0x18, 0x03, 0x03, 0x3A, 0x00, 0x00, 0x00}; static const uint8_t goaclka3[] = {0x18, 0x02, 0x03, 0x3B, 0x00, 0x00, 0x00}; static const uint8_t goaclka4[] = {0x18, 0x01, 0x03, 0x3C, 0x00, 0x00, 0x00}; static const uint8_t goaeclk[] = {0x01, 0x01, 0x20, 0x20, 0x00, 0x00}; static const uint8_t panctrlset1[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; static const uint8_t panctrlset2[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; static const uint8_t panctrlset3[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; static const uint8_t panctrlset4[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; static const uint8_t panctrlset5[] = { 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; static const uint8_t panctrlset6[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00 }; static const uint8_t panctrlset7[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; static const uint8_t panctrlset8[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; static const uint8_t panu2d1[] = { 0x00, 0x26, 0x09, 0x0B, 0x01, 0x25, 0x00, 0x00, 0x00, 0x00 }; static const uint8_t panu2d2[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x26, 0x0A, 0x0C, 0x02 }; static const uint8_t panu2d3[] = { 0x25, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; static const uint8_t pand2u1[] = { 0x00, 0x25, 0x0C, 0x0A, 0x02, 0x26, 0x00, 0x00, 0x00, 0x00 }; static const uint8_t pand2u2[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x25, 0x0B, 0x09, 0x01 }; static const uint8_t pand2u3[] = { 0x26, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; static const uint8_t pgamma[] = { 0x00, 0x09, 0x0F, 0x0E, 0x07, 0x10, 0x0B, 0x0A, 0x04, 0x07, 0x0B, 0x08, 0x0F, 0x10, 0x0A, 0x01 }; static const uint8_t ngamma[] = { 0x00, 0x09, 0x0F, 0x0E, 0x07, 0x10, 0x0B, 0x0A, 0x04, 0x07, 0x0B, 0x08, 0x0F, 0x10, 0x0A, 0x01 }; /* enter command 2 mode to access manufacturer registers (ref. 5.3) */ buf[0] = 0x80; buf[1] = 0x09; buf[2] = 0x01; ret = otm8009a_mcs_write(dev, OTM8009A_MCS_CMD2_ENA1, buf, 3); if (ret < 0) { return ret; } /* enter Orise command 2 mode */ buf[0] = 0x80; buf[1] = 0x09; ret = otm8009a_mcs_write(dev, OTM8009A_MCS_CMD2_ENA2, buf, 2); if (ret < 0) { return ret; } /* source driver precharge control */ buf[0] = 0x30; buf[1] = 0x8A; ret = otm8009a_mcs_write(dev, OTM8009A_MCS_SD_PCH_CTRL, buf, 2); if (ret < 0) { return ret; } /* not documented */ buf[0] = 0x40; ret = otm8009a_mcs_write(dev, OTM8009A_MCS_NO_DOC1, buf, 1); if (ret < 0) { return ret; } /* power control settings 4 for DC voltage settings */ /* enable GVDD test mode */ buf[0] = 0x04; buf[1] = 0xA9; ret = otm8009a_mcs_write(dev, OTM8009A_MCS_PWR_CTRL4, buf, 2); if (ret < 0) { return ret; } /* power control settings 2 for normal mode */ /* set pump 4 vgh voltage from 15.0v down to 13.0v */ /* set pump 5 vgh voltage from -12.0v downto -9.0v */ /* set pump 4&5 x6 (ONLY VALID when PUMP4_EN_ASDM_HV = "0") */ /* change pump4 clock ratio from 1 line to 1/2 line */ ret = otm8009a_mcs_write(dev, OTM8009A_MCS_PWR_CTRL2, pwr_ctrl2, sizeof(pwr_ctrl2)); if (ret < 0) { return ret; } /* panel driving mode */ /* set column inversion */ buf[0] = 0x50; ret = otm8009a_mcs_write(dev, OTM8009A_MCS_P_DRV_M, buf, 1); if (ret < 0) { return ret; } /* VCOM voltage setting */ /* VCOM Voltage settings from -1.0000v downto -1.2625v */ buf[0] = 0x4E; ret = otm8009a_mcs_write(dev, OTM8009A_MCS_VCOMDC, buf, 1); if (ret < 0) { return ret; } /* oscillator adjustment for idle/normal mode */ /* set 65Hz */ buf[0] = 0x66; ret = otm8009a_mcs_write(dev, OTM8009A_MCS_OSC_ADJ, buf, 1); if (ret < 0) { return ret; } /* RGB video mode setting */ buf[0] = 0x08; ret = otm8009a_mcs_write(dev, OTM8009A_MCS_RGB_VID_SET, buf, 1); if (ret < 0) { return ret; } /* GVDD/NGVDD */ buf[0] = 0x79; buf[1] = 0x79; ret = otm8009a_mcs_write(dev, OTM8009A_MCS_GVDDSET, buf, 2); if (ret < 0) { return ret; } /* source driver timing setting */ ret = otm8009a_mcs_write(dev, OTM8009A_MCS_SD_CTRL, sd_ctrl, sizeof(sd_ctrl)); if (ret < 0) { return ret; } /* panel type setting */ buf[0] = 0x00; buf[1] = 0x01; ret = otm8009a_mcs_write(dev, OTM8009A_MCS_PANSET, buf, 2); if (ret < 0) { return ret; } /* GOA VST setting */ ret = otm8009a_mcs_write(dev, OTM8009A_MCS_GOAVST, goavst, sizeof(goavst)); if (ret < 0) { return ret; } /* GOA CLKA1 setting */ ret = otm8009a_mcs_write(dev, OTM8009A_MCS_GOACLKA1, goaclka1, sizeof(goaclka1)); if (ret < 0) { return ret; } /* GOA CLKA2 setting */ ret = otm8009a_mcs_write(dev, OTM8009A_MCS_GOACLKA2, goaclka2, sizeof(goaclka2)); if (ret < 0) { return ret; } /* GOA CLKA3 setting */ ret = otm8009a_mcs_write(dev, OTM8009A_MCS_GOACLKA3, goaclka3, sizeof(goaclka3)); if (ret < 0) { return ret; } /* GOA CLKA4 setting */ ret = otm8009a_mcs_write(dev, OTM8009A_MCS_GOACLKA4, goaclka4, sizeof(goaclka4)); if (ret < 0) { return ret; } /* GOA ECLK */ ret = otm8009a_mcs_write(dev, OTM8009A_MCS_GOAECLK, goaeclk, sizeof(goaeclk)); if (ret < 0) { return ret; } /** GOA Other Options 1 */ buf[0] = 0x01; ret = otm8009a_mcs_write(dev, OTM8009A_MCS_GOAPT1, buf, 1); if (ret < 0) { return ret; } /* GOA Signal Toggle Option Setting */ buf[0] = 0x02; buf[1] = 0x00; buf[2] = 0x00; ret = otm8009a_mcs_write(dev, OTM8009A_MCS_GOATGOPT, buf, 3); if (ret < 0) { return ret; } /* not documented */ buf[0] = 0x00; ret = otm8009a_mcs_write(dev, OTM8009A_MCS_NO_DOC2, buf, 3); if (ret < 0) { return ret; } /* Panel Control Setting 1 */ ret = otm8009a_mcs_write(dev, OTM8009A_MCS_PANCTRLSET1, panctrlset1, sizeof(panctrlset1)); if (ret < 0) { return ret; } ret = otm8009a_mcs_write(dev, OTM8009A_MCS_PANCTRLSET2, panctrlset2, sizeof(panctrlset2)); if (ret < 0) { return ret; } ret = otm8009a_mcs_write(dev, OTM8009A_MCS_PANCTRLSET3, panctrlset3, sizeof(panctrlset3)); if (ret < 0) { return ret; } ret = otm8009a_mcs_write(dev, OTM8009A_MCS_PANCTRLSET4, panctrlset4, sizeof(panctrlset4)); if (ret < 0) { return ret; } ret = otm8009a_mcs_write(dev, OTM8009A_MCS_PANCTRLSET5, panctrlset5, sizeof(panctrlset5)); if (ret < 0) { return ret; } ret = otm8009a_mcs_write(dev, OTM8009A_MCS_PANCTRLSET6, panctrlset6, sizeof(panctrlset6)); if (ret < 0) { return ret; } ret = otm8009a_mcs_write(dev, OTM8009A_MCS_PANCTRLSET7, panctrlset7, sizeof(panctrlset7)); if (ret < 0) { return ret; } ret = otm8009a_mcs_write(dev, OTM8009A_MCS_PANCTRLSET8, panctrlset8, sizeof(panctrlset8)); if (ret < 0) { return ret; } ret = otm8009a_mcs_write(dev, OTM8009A_MCS_PANU2D1, panu2d1, sizeof(panu2d1)); if (ret < 0) { return ret; } ret = otm8009a_mcs_write(dev, OTM8009A_MCS_PANU2D2, panu2d2, sizeof(panu2d2)); if (ret < 0) { return ret; } ret = otm8009a_mcs_write(dev, OTM8009A_MCS_PANU2D3, panu2d3, sizeof(panu2d3)); if (ret < 0) { return ret; } ret = otm8009a_mcs_write(dev, OTM8009A_MCS_PAND2U1, pand2u1, sizeof(pand2u1)); if (ret < 0) { return ret; } ret = otm8009a_mcs_write(dev, OTM8009A_MCS_PAND2U2, pand2u2, sizeof(pand2u2)); if (ret < 0) { return ret; } ret = otm8009a_mcs_write(dev, OTM8009A_MCS_PAND2U3, pand2u3, sizeof(pand2u3)); if (ret < 0) { return ret; } /* power control setting 1 */ /* Pump 1 min and max DM */ buf[0] = 0x08; buf[1] = 0x66; buf[2] = 0x83; buf[3] = 0x00; ret = otm8009a_mcs_write(dev, OTM8009A_MCS_PWR_CTRL1, buf, 4); if (ret < 0) { return ret; } /* not documented */ buf[0] = 0x06; ret = otm8009a_mcs_write(dev, OTM8009A_MCS_NO_DOC3, buf, 1); if (ret < 0) { return ret; } /* PWM parameter 3 */ /* Freq: 19.5 KHz */ buf[0] = 0x06; ret = otm8009a_mcs_write(dev, OTM8009A_MCS_PWM_PARA3, buf, 1); if (ret < 0) { return ret; } /* gamma correction 2.2+ */ ret = otm8009a_mcs_write(dev, OTM8009A_MCS_GMCT2_2P, pgamma, sizeof(pgamma)); if (ret < 0) { return ret; } /* gamma correction 2.2- */ ret = otm8009a_mcs_write(dev, OTM8009A_MCS_GMCT2_2N, ngamma, sizeof(ngamma)); if (ret < 0) { return ret; } /* exit command 2 mode */ buf[0] = 0xFF; buf[1] = 0xFF; buf[2] = 0xFF; ret = otm8009a_mcs_write(dev, OTM8009A_MCS_CMD2_ENA1, buf, 3); if (ret < 0) { return ret; } /* exit sleep mode */ ret = otm8009a_dcs_write(dev, MIPI_DCS_EXIT_SLEEP_MODE, NULL, 0); if (ret < 0) { return ret; } k_msleep(OTM8009A_EXIT_SLEEP_MODE_WAIT_TIME); /* set pixel color format */ switch (data->dsi_pixel_format) { case MIPI_DSI_PIXFMT_RGB565: buf[0] = MIPI_DCS_PIXEL_FORMAT_16BIT; break; case MIPI_DSI_PIXFMT_RGB888: buf[0] = MIPI_DCS_PIXEL_FORMAT_24BIT; break; default: LOG_ERR("Unsupported pixel format 0x%x!", data->dsi_pixel_format); return -ENOTSUP; } ret = otm8009a_dcs_write(dev, MIPI_DCS_SET_PIXEL_FORMAT, buf, 1); if (ret < 0) { return ret; } /* configure address mode */ if (data->orientation == DISPLAY_ORIENTATION_NORMAL) { buf[0] = 0x00; } else if (data->orientation == DISPLAY_ORIENTATION_ROTATED_90) { buf[0] = MIPI_DCS_ADDRESS_MODE_MIRROR_X | MIPI_DCS_ADDRESS_MODE_SWAP_XY; } else if (data->orientation == DISPLAY_ORIENTATION_ROTATED_180) { buf[0] = MIPI_DCS_ADDRESS_MODE_MIRROR_X | MIPI_DCS_ADDRESS_MODE_MIRROR_Y; } else if (data->orientation == DISPLAY_ORIENTATION_ROTATED_270) { buf[0] = MIPI_DCS_ADDRESS_MODE_MIRROR_Y | MIPI_DCS_ADDRESS_MODE_SWAP_XY; } ret = otm8009a_dcs_write(dev, MIPI_DCS_SET_ADDRESS_MODE, buf, 1); if (ret < 0) { return ret; } buf[0] = 0x00; buf[1] = 0x00; sys_put_be16(data->xres, (uint8_t *)&buf[2]); ret = otm8009a_dcs_write(dev, MIPI_DCS_SET_COLUMN_ADDRESS, buf, 4); if (ret < 0) { return ret; } buf[0] = 0x00; buf[1] = 0x00; sys_put_be16(data->yres, (uint8_t *)&buf[2]); ret = otm8009a_dcs_write(dev, MIPI_DCS_SET_PAGE_ADDRESS, buf, 4); if (ret < 0) { return ret; } /* backlight control */ buf[0] = OTM8009A_WRCTRLD_BCTRL | OTM8009A_WRCTRLD_DD | OTM8009A_WRCTRLD_BL; ret = otm8009a_dcs_write(dev, MIPI_DCS_WRITE_CONTROL_DISPLAY, buf, 1); if (ret < 0) { return ret; } /* adaptive brightness control */ buf[0] = OTM8009A_WRCABC_UI; ret = otm8009a_dcs_write(dev, MIPI_DCS_WRITE_POWER_SAVE, buf, 1); if (ret < 0) { return ret; } /* adaptive brightness control minimum brightness */ buf[0] = 0xFF; ret = otm8009a_dcs_write(dev, MIPI_DCS_SET_CABC_MIN_BRIGHTNESS, buf, 1); if (ret < 0) { return ret; } /* brightness */ buf[0] = 0xFF; ret = otm8009a_dcs_write(dev, MIPI_DCS_SET_DISPLAY_BRIGHTNESS, buf, 1); if (ret < 0) { return ret; } /* Display On */ ret = otm8009a_dcs_write(dev, MIPI_DCS_SET_DISPLAY_ON, NULL, 0); if (ret < 0) { return ret; } /* trigger display write (from data coming by DSI bus) */ ret = otm8009a_dcs_write(dev, MIPI_DCS_WRITE_MEMORY_START, NULL, 0); if (ret < 0) { return ret; } return 0; } static int otm8009a_blanking_on(const struct device *dev) { const struct otm8009a_config *cfg = dev->config; int ret; if (cfg->backlight.port != NULL) { ret = gpio_pin_set_dt(&cfg->backlight, 0); if (ret) { LOG_ERR("Disable backlight failed! (%d)", ret); return ret; } } return otm8009a_dcs_write(dev, MIPI_DCS_SET_DISPLAY_OFF, NULL, 0); } static int otm8009a_blanking_off(const struct device *dev) { const struct otm8009a_config *cfg = dev->config; int ret; if (cfg->backlight.port != NULL) { ret = gpio_pin_set_dt(&cfg->backlight, 1); if (ret) { LOG_ERR("Enable backlight failed! (%d)", ret); return ret; } } return otm8009a_dcs_write(dev, MIPI_DCS_SET_DISPLAY_ON, NULL, 0); } static int otm8009a_write(const struct device *dev, uint16_t x, uint16_t y, const struct display_buffer_descriptor *desc, const void *buf) { return -ENOTSUP; } static int otm8009a_read(const struct device *dev, uint16_t x, uint16_t y, const struct display_buffer_descriptor *desc, void *buf) { return -ENOTSUP; } static void *otm8009a_get_framebuffer(const struct device *dev) { return NULL; } static int otm8009a_set_brightness(const struct device *dev, uint8_t brightness) { return otm8009a_dcs_write(dev, MIPI_DCS_SET_DISPLAY_BRIGHTNESS, &brightness, 1); } static int otm8009a_set_contrast(const struct device *dev, uint8_t contrast) { return -ENOTSUP; } static void otm8009a_get_capabilities(const struct device *dev, struct display_capabilities *capabilities) { const struct otm8009a_config *cfg = dev->config; struct otm8009a_data *data = dev->data; memset(capabilities, 0, sizeof(struct display_capabilities)); capabilities->x_resolution = cfg->width; capabilities->y_resolution = cfg->height; capabilities->supported_pixel_formats = data->pixel_format; capabilities->current_pixel_format = data->pixel_format; capabilities->current_orientation = data->orientation; } static int otm8009a_set_pixel_format(const struct device *dev, enum display_pixel_format pixel_format) { return -ENOTSUP; } static int otm8009a_set_orientation(const struct device *dev, enum display_orientation orientation) { return -ENOTSUP; } static const struct display_driver_api otm8009a_api = { .blanking_on = otm8009a_blanking_on, .blanking_off = otm8009a_blanking_off, .write = otm8009a_write, .read = otm8009a_read, .get_framebuffer = otm8009a_get_framebuffer, .set_brightness = otm8009a_set_brightness, .set_contrast = otm8009a_set_contrast, .get_capabilities = otm8009a_get_capabilities, .set_pixel_format = otm8009a_set_pixel_format, .set_orientation = otm8009a_set_orientation, }; static int otm8009a_init(const struct device *dev) { const struct otm8009a_config *cfg = dev->config; struct otm8009a_data *data = dev->data; struct mipi_dsi_device mdev; int ret; if (cfg->reset.port) { if (!gpio_is_ready_dt(&cfg->reset)) { LOG_ERR("Reset GPIO device is not ready!"); return -ENODEV; } ret = gpio_pin_configure_dt(&cfg->reset, GPIO_OUTPUT_INACTIVE); if (ret < 0) { LOG_ERR("Reset display failed! (%d)", ret); return ret; } k_msleep(OTM8009A_RESET_TIME); ret = gpio_pin_set_dt(&cfg->reset, 1); if (ret < 0) { LOG_ERR("Enable display failed! (%d)", ret); return ret; } k_msleep(OTM8009A_WAKE_TIME); } /* store x/y resolution & rotation */ if (cfg->rotation == 0) { data->xres = cfg->width; data->yres = cfg->height; data->orientation = DISPLAY_ORIENTATION_NORMAL; } else if (cfg->rotation == 90) { data->xres = cfg->height; data->yres = cfg->width; data->orientation = DISPLAY_ORIENTATION_ROTATED_90; } else if (cfg->rotation == 180) { data->xres = cfg->width; data->yres = cfg->height; data->orientation = DISPLAY_ORIENTATION_ROTATED_180; } else if (cfg->rotation == 270) { data->xres = cfg->height; data->yres = cfg->width; data->orientation = DISPLAY_ORIENTATION_ROTATED_270; } /* attach to MIPI-DSI host */ mdev.data_lanes = cfg->data_lanes; mdev.pixfmt = data->dsi_pixel_format; mdev.mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_BURST | MIPI_DSI_MODE_LPM; mdev.timings.hactive = data->xres; mdev.timings.hbp = OTM8009A_HBP; mdev.timings.hfp = OTM8009A_HFP; mdev.timings.hsync = OTM8009A_HSYNC; mdev.timings.vactive = data->yres; mdev.timings.vbp = OTM8009A_VBP; mdev.timings.vfp = OTM8009A_VFP; mdev.timings.vsync = OTM8009A_VSYNC; ret = mipi_dsi_attach(cfg->mipi_dsi, cfg->channel, &mdev); if (ret < 0) { LOG_ERR("MIPI-DSI attach failed! (%d)", ret); return ret; } ret = otm8009a_check_id(dev); if (ret) { LOG_ERR("Panel ID check failed! (%d)", ret); return ret; } ret = otm8009a_configure(dev); if (ret) { LOG_ERR("DSI init sequence failed! (%d)", ret); return ret; } ret = otm8009a_blanking_off(dev); if (ret) { LOG_ERR("Display blanking off failed! (%d)", ret); return ret; } return 0; } #define OTM8009A_DEVICE(inst) \ static const struct otm8009a_config otm8009a_config_##inst = { \ .mipi_dsi = DEVICE_DT_GET(DT_INST_BUS(inst)), \ .reset = GPIO_DT_SPEC_INST_GET_OR(inst, reset_gpios, {0}), \ .backlight = GPIO_DT_SPEC_INST_GET_OR(inst, bl_gpios, {0}), \ .data_lanes = DT_INST_PROP_BY_IDX(inst, data_lanes, 0), \ .width = DT_INST_PROP(inst, width), \ .height = DT_INST_PROP(inst, height), \ .channel = DT_INST_REG_ADDR(inst), \ .rotation = DT_INST_PROP(inst, rotation), \ }; \ static struct otm8009a_data otm8009a_data_##inst = { \ .dsi_pixel_format = DT_INST_PROP(inst, pixel_format), \ }; \ DEVICE_DT_INST_DEFINE(inst, &otm8009a_init, NULL, &otm8009a_data_##inst, \ &otm8009a_config_##inst, POST_KERNEL, \ CONFIG_DISPLAY_OTM8009A_INIT_PRIORITY, &otm8009a_api); \ DT_INST_FOREACH_STATUS_OKAY(OTM8009A_DEVICE)
/* * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source * tree. An additional intellectual property rights grant can be found * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree. */ #ifndef MODULES_DESKTOP_CAPTURE_DESKTOP_AND_CURSOR_COMPOSER_H_ #define MODULES_DESKTOP_CAPTURE_DESKTOP_AND_CURSOR_COMPOSER_H_ #include <memory> #if defined(WEBRTC_USE_GIO) #include "modules/desktop_capture/desktop_capture_metadata.h" #endif // defined(WEBRTC_USE_GIO) #include "modules/desktop_capture/desktop_capture_options.h" #include "modules/desktop_capture/desktop_capture_types.h" #include "modules/desktop_capture/desktop_capturer.h" #include "modules/desktop_capture/desktop_frame.h" #include "modules/desktop_capture/desktop_geometry.h" #include "modules/desktop_capture/mouse_cursor.h" #include "modules/desktop_capture/mouse_cursor_monitor.h" #include "modules/desktop_capture/shared_memory.h" #include "rtc_base/system/rtc_export.h" namespace webrtc { // A wrapper for DesktopCapturer that also captures mouse using specified // MouseCursorMonitor and renders it on the generated streams. class RTC_EXPORT DesktopAndCursorComposer : public DesktopCapturer, public DesktopCapturer::Callback, public MouseCursorMonitor::Callback { public: // Creates a new composer that captures mouse cursor using // MouseCursorMonitor::Create(options) and renders it into the frames // generated by `desktop_capturer`. DesktopAndCursorComposer(std::unique_ptr<DesktopCapturer> desktop_capturer, const DesktopCaptureOptions& options); ~DesktopAndCursorComposer() override; DesktopAndCursorComposer(const DesktopAndCursorComposer&) = delete; DesktopAndCursorComposer& operator=(const DesktopAndCursorComposer&) = delete; // Creates a new composer that relies on an external source for cursor shape // and position information via the MouseCursorMonitor::Callback interface. static std::unique_ptr<DesktopAndCursorComposer> CreateWithoutMouseCursorMonitor( std::unique_ptr<DesktopCapturer> desktop_capturer); // DesktopCapturer interface. void Start(DesktopCapturer::Callback* callback) override; void SetSharedMemoryFactory( std::unique_ptr<SharedMemoryFactory> shared_memory_factory) override; void CaptureFrame() override; void SetExcludedWindow(WindowId window) override; bool GetSourceList(SourceList* sources) override; bool SelectSource(SourceId id) override; bool FocusOnSelectedSource() override; bool IsOccluded(const DesktopVector& pos) override; void SetMaxFrameRate(uint32_t max_frame_rate) override; #if defined(WEBRTC_USE_GIO) DesktopCaptureMetadata GetMetadata() override; #endif // defined(WEBRTC_USE_GIO) // MouseCursorMonitor::Callback interface. void OnMouseCursor(MouseCursor* cursor) override; void OnMouseCursorPosition(const DesktopVector& position) override; private: // Allows test cases to use a fake MouseCursorMonitor implementation. friend class DesktopAndCursorComposerTest; // Constructor to delegate both deprecated and new constructors and allows // test cases to use a fake MouseCursorMonitor implementation. DesktopAndCursorComposer(DesktopCapturer* desktop_capturer, MouseCursorMonitor* mouse_monitor); // DesktopCapturer::Callback interface. void OnFrameCaptureStart() override; void OnCaptureResult(DesktopCapturer::Result result, std::unique_ptr<DesktopFrame> frame) override; const std::unique_ptr<DesktopCapturer> desktop_capturer_; const std::unique_ptr<MouseCursorMonitor> mouse_monitor_; DesktopCapturer::Callback* callback_; std::unique_ptr<MouseCursor> cursor_; DesktopVector cursor_position_; DesktopRect previous_cursor_rect_; bool cursor_changed_ = false; }; } // namespace webrtc #endif // MODULES_DESKTOP_CAPTURE_DESKTOP_AND_CURSOR_COMPOSER_H_
/* * check the http status code for problems */ int ebxml_status (char *reply) { char *ch, *nl; if ((nl = strchr (reply, '\n')) == NULL) nl = reply + strlen (reply); if (((ch = strchr (reply, ' ')) != NULL) && (ch < nl)) { while (isspace (*ch)) ch++; if (atoi (ch) == 200) return (0); } else ch = reply; error ("EbXML reply failed: %.*s\n", nl - ch, ch); return (-1); }
/* * Returns policy descriptor for the specified device. */ kcf_policy_desc_t * kcf_policy_lookup_by_dev(char *name, uint_t instance) { kcf_policy_desc_t *policy_desc; uint_t i; mutex_enter(&policy_tab_mutex); for (i = 0; i < KCF_MAX_POLICY; i++) { if ((policy_desc = policy_tab[i]) != NULL && policy_desc->pd_prov_type == CRYPTO_HW_PROVIDER && strncmp(policy_desc->pd_name, name, MAXNAMELEN) == 0 && policy_desc->pd_instance == instance) { KCF_POLICY_REFHOLD(policy_desc); mutex_exit(&policy_tab_mutex); return (policy_desc); } } mutex_exit(&policy_tab_mutex); return (NULL); }
// in the name of GOD #include<stdio.h> #include<string.h> char *suffix(char s[]) { static char *p; if(strcmp(s+(strlen(s)-2),"po")==0) p="FILIPINO"; else if (strcmp(s+(strlen(s)-4),"desu")==0 || strcmp(s+(strlen(s)-4),"masu")==0) p="JAPANESE"; else if (strcmp(s+(strlen(s)-5),"mnida")==0) p="KOREAN"; return p; } int main() { int n; char s[1001]; scanf("%d",&n); for (int i=0;i<n;i++) { scanf("%s",s); printf("%s\n",suffix(s)); } }
/* * End the transmission phase of a call. * * This occurs when we get an ACKALL packet, the first DATA packet of a reply, * or a final ACK packet. */ static bool rxrpc_end_tx_phase(struct rxrpc_call *call, bool reply_begun, const char *abort_why) { ASSERT(test_bit(RXRPC_CALL_TX_LAST, &call->flags)); write_lock(&call->state_lock); switch (call->state) { case RXRPC_CALL_CLIENT_SEND_REQUEST: case RXRPC_CALL_CLIENT_AWAIT_REPLY: if (reply_begun) call->state = RXRPC_CALL_CLIENT_RECV_REPLY; else call->state = RXRPC_CALL_CLIENT_AWAIT_REPLY; break; case RXRPC_CALL_SERVER_AWAIT_ACK: __rxrpc_call_completed(call); rxrpc_notify_socket(call); break; default: goto bad_state; } write_unlock(&call->state_lock); if (call->state == RXRPC_CALL_CLIENT_AWAIT_REPLY) { rxrpc_propose_ACK(call, RXRPC_ACK_IDLE, 0, 0, false, true, rxrpc_propose_ack_client_tx_end); trace_rxrpc_transmit(call, rxrpc_transmit_await_reply); } else { trace_rxrpc_transmit(call, rxrpc_transmit_end); } _leave(" = ok"); return true; bad_state: write_unlock(&call->state_lock); kdebug("end_tx %s", rxrpc_call_states[call->state]); rxrpc_proto_abort(abort_why, call, call->tx_top); return false; }
/** * Assign a default set of parameters to the state passed in * * @param state Pointer to state structure to assign defaults to */ static void default_status(RASPIVIDYUV_STATE *state) { if (!state) { vcos_assert(0); return; } memset(state, 0, sizeof(RASPIVIDYUV_STATE)); state->timeout = 5000; state->width = 1920; state->height = 1080; state->framerate = VIDEO_FRAME_RATE_NUM; state->demoMode = 0; state->demoInterval = 250; state->waitMethod = WAIT_METHOD_NONE; state->onTime = 5000; state->offTime = 5000; state->bCapturing = 0; state->cameraNum = 0; state->settings = 0; state->sensor_mode = 0; raspipreview_set_defaults(&state->preview_parameters); raspicamcontrol_set_defaults(&state->camera_parameters); }
#include<stdio.h> #define MAX 100 #define N 100 #define WHITE 0 #define GRAY 1 #define BLACK 2 int isEmpty(); int isFull(); void enqueue(int); int dequeue(); void bfs(int,int); int head = 0, tail = 0; int que[MAX]; int G[N][N]; char color[N]; int d[N]; int f[N]; int main() { int n,i,k,u,v,j; scanf("%d", &n); for(i=0;i<n;i++) { scanf("%d%d", &u, &k); for(j=0;j<k;j++) { scanf("%d", &v); G[u-1][v-1]=1; } } bfs(0,n); for(i=0;i<n;i++) { printf("%d %d\n", i+1, d[i]); } return 0; } int isEmpty() { return head == tail; } int isFull() { return head == (tail+1)%MAX; } void enqueue(int x) { if(isFull()) { printf("OVF\n"); } que[tail] = x; if(tail+1 == MAX) { tail = 0; } else { tail++; } } int dequeue() { if(isEmpty()) { printf("UNF\n"); } int x = que[head]; if(head+1 == MAX) { head = 0; } else { head++; } return x; } void bfs(int s, int n) { int i,u; for(i=0;i<n;i++) { color[i]=WHITE; d[i]=-1; } color[s]=GRAY; d[s]=0; enqueue(s); while(!isEmpty()) { u=dequeue(); for(i=0;i<n;i++) { if(G[u][i]) { if(color[i]==WHITE) { color[i]=GRAY; d[i]=d[u]+1; enqueue(i); } } } color[u]=BLACK; } }
/** * gtk_flow_box_get_min_children_per_line: (attributes org.gtk.Method.get_property=min-children-per-line) * @box: a `GtkFlowBox` * * Gets the minimum number of children per line. * * Returns: the minimum number of children per line */ guint gtk_flow_box_get_min_children_per_line (GtkFlowBox *box) { g_return_val_if_fail (GTK_IS_FLOW_BOX (box), FALSE); return BOX_PRIV (box)->min_children_per_line; }
/* * Copyright 2017-2021 Uber Technologies, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <stdlib.h> #include "algos.h" #include "constants.h" #include "h3Index.h" #include "latLng.h" #include "test.h" #include "utility.h" // Tests for specific polygonToCells examples SUITE(polygonToCells_reported) { // https://github.com/uber/h3-js/issues/76#issuecomment-561204505 TEST(entireWorld) { // TODO: Fails for a single worldwide polygon LatLng worldVerts[] = { {-M_PI_2, -M_PI}, {M_PI_2, -M_PI}, {M_PI_2, 0}, {-M_PI_2, 0}}; GeoLoop worldGeoLoop = {.numVerts = 4, .verts = worldVerts}; GeoPolygon worldGeoPolygon = {.geoloop = worldGeoLoop, .numHoles = 0}; LatLng worldVerts2[] = { {-M_PI_2, 0}, {M_PI_2, 0}, {M_PI_2, M_PI}, {-M_PI_2, M_PI}}; GeoLoop worldGeoLoop2 = {.numVerts = 4, .verts = worldVerts2}; GeoPolygon worldGeoPolygon2 = {.geoloop = worldGeoLoop2, .numHoles = 0}; for (int res = 0; res < 3; res++) { int64_t polygonToCellsSize; t_assertSuccess(H3_EXPORT(maxPolygonToCellsSize)( &worldGeoPolygon, res, 0, &polygonToCellsSize)); H3Index *polygonToCellsOut = calloc(polygonToCellsSize, sizeof(H3Index)); t_assertSuccess(H3_EXPORT(polygonToCells)(&worldGeoPolygon, res, 0, polygonToCellsOut)); int64_t actualNumIndexes = countNonNullIndexes(polygonToCellsOut, polygonToCellsSize); int64_t polygonToCellsSize2; t_assertSuccess(H3_EXPORT(maxPolygonToCellsSize)( &worldGeoPolygon2, res, 0, &polygonToCellsSize2)); H3Index *polygonToCellsOut2 = calloc(polygonToCellsSize2, sizeof(H3Index)); t_assertSuccess(H3_EXPORT(polygonToCells)(&worldGeoPolygon2, res, 0, polygonToCellsOut2)); int64_t actualNumIndexes2 = countNonNullIndexes(polygonToCellsOut2, polygonToCellsSize2); int64_t expectedTotalWorld; t_assertSuccess(H3_EXPORT(getNumCells)(res, &expectedTotalWorld)); t_assert(actualNumIndexes + actualNumIndexes2 == expectedTotalWorld, "got expected polygonToCells size (entire world)"); // Sets should be disjoint for (int i = 0; i < polygonToCellsSize; i++) { if (polygonToCellsOut[i] == 0) continue; bool found = false; for (int j = 0; j < polygonToCellsSize2; j++) { if (polygonToCellsOut[i] == polygonToCellsOut2[j]) { found = true; break; } } t_assert( !found, "Index found more than once when polygonToCellsing the " "entire world"); } free(polygonToCellsOut); free(polygonToCellsOut2); } } // https://github.com/uber/h3-js/issues/67 TEST(h3js_67) { double east = H3_EXPORT(degsToRads)(-56.25); double north = H3_EXPORT(degsToRads)(-33.13755119234615); double south = H3_EXPORT(degsToRads)(-34.30714385628804); double west = H3_EXPORT(degsToRads)(-57.65625); LatLng testVerts[] = { {north, east}, {south, east}, {south, west}, {north, west}}; GeoLoop testGeoLoop = {.numVerts = 4, .verts = testVerts}; GeoPolygon testPolygon; testPolygon.geoloop = testGeoLoop; testPolygon.numHoles = 0; int res = 7; int64_t numHexagons; t_assertSuccess(H3_EXPORT(maxPolygonToCellsSize)(&testPolygon, res, 0, &numHexagons)); H3Index *hexagons = calloc(numHexagons, sizeof(H3Index)); t_assertSuccess( H3_EXPORT(polygonToCells)(&testPolygon, res, 0, hexagons)); int64_t actualNumIndexes = countNonNullIndexes(hexagons, numHexagons); t_assert(actualNumIndexes == 4499, "got expected polygonToCells size (h3-js#67)"); free(hexagons); } // 2nd test case from h3-js#67 TEST(h3js_67_2nd) { double east = H3_EXPORT(degsToRads)(-57.65625); double north = H3_EXPORT(degsToRads)(-34.30714385628804); double south = H3_EXPORT(degsToRads)(-35.4606699514953); double west = H3_EXPORT(degsToRads)(-59.0625); LatLng testVerts[] = { {north, east}, {south, east}, {south, west}, {north, west}}; GeoLoop testGeoLoop = {.numVerts = 4, .verts = testVerts}; GeoPolygon testPolygon; testPolygon.geoloop = testGeoLoop; testPolygon.numHoles = 0; int res = 7; int64_t numHexagons; t_assertSuccess(H3_EXPORT(maxPolygonToCellsSize)(&testPolygon, res, 0, &numHexagons)); H3Index *hexagons = calloc(numHexagons, sizeof(H3Index)); t_assertSuccess( H3_EXPORT(polygonToCells)(&testPolygon, res, 0, hexagons)); int64_t actualNumIndexes = countNonNullIndexes(hexagons, numHexagons); t_assert(actualNumIndexes == 4609, "got expected polygonToCells size (h3-js#67, 2nd case)"); free(hexagons); } // https://github.com/uber/h3/issues/136 TEST(h3_136) { LatLng testVerts[] = {{0.10068990369902957, 0.8920772174196191}, {0.10032914690616246, 0.8915914753447348}, {0.10033349237998787, 0.8915860128746426}, {0.10069496685903621, 0.8920742194546231}}; GeoLoop testGeoLoop = {.numVerts = 4, .verts = testVerts}; GeoPolygon testPolygon; testPolygon.geoloop = testGeoLoop; testPolygon.numHoles = 0; int res = 13; int64_t numHexagons; t_assertSuccess(H3_EXPORT(maxPolygonToCellsSize)(&testPolygon, res, 0, &numHexagons)); H3Index *hexagons = calloc(numHexagons, sizeof(H3Index)); t_assertSuccess( H3_EXPORT(polygonToCells)(&testPolygon, res, 0, hexagons)); int64_t actualNumIndexes = countNonNullIndexes(hexagons, numHexagons); t_assert(actualNumIndexes == 4353, "got expected polygonToCells size"); free(hexagons); } // https://github.com/uber/h3/issues/595 TEST(h3_136) { H3Index center = 0x85283473fffffff; LatLng centerLatLng; H3_EXPORT(cellToLatLng)(center, &centerLatLng); // This polygon should include the center cell. The issue here arises // when one of the polygon vertexes is to the east of the index center, // with exactly the same latitude LatLng testVerts[] = {{.lat = centerLatLng.lat, -2.121207808248113}, {0.6565301558937859, -2.1281107217935986}, {0.6515463604919347, -2.1345342663428695}, {0.6466583305904194, -2.1276313527973842}}; GeoLoop testGeoLoop = {.numVerts = 4, .verts = testVerts}; GeoPolygon testPolygon; testPolygon.geoloop = testGeoLoop; testPolygon.numHoles = 0; int res = 5; int64_t numHexagons; t_assertSuccess(H3_EXPORT(maxPolygonToCellsSize)(&testPolygon, res, 0, &numHexagons)); H3Index *hexagons = calloc(numHexagons, sizeof(H3Index)); t_assertSuccess( H3_EXPORT(polygonToCells)(&testPolygon, res, 0, hexagons)); int64_t actualNumIndexes = countNonNullIndexes(hexagons, numHexagons); t_assert(actualNumIndexes == 8, "got expected polygonToCells size"); free(hexagons); } }
/** * Parse TCP option list. For each parsed option the corresponding pointer in * opts will be set. * * @param p Pointer to packet * @param len Packet length * @param [out] opts Pointers to parsed options * * @return 0 if parsed successful, -1 otherwise. */ static inline int tcp_parse_options(const struct pkt_tcp *p, uint16_t len, struct tcp_opts *opts) { uint8_t *opt = (uint8_t *) (p + 1); uint16_t opts_len = TCPH_HDRLEN(&p->tcp) * 4 - 20; uint16_t off = 0; uint8_t opt_kind, opt_len, opt_avail; opts->ts = NULL; if (TCPH_HDRLEN(&p->tcp) < 5 || opts_len > (len - sizeof(*p))) { fprintf(stderr, "hlen=%u opts_len=%u len=%u so=%zu\n", TCPH_HDRLEN(&p->tcp), opts_len, len, sizeof(*p)); return -1; } while (off < opts_len) { opt_kind = opt[off]; opt_avail = opts_len - off; if (opt_kind == TCP_OPT_END_OF_OPTIONS) { break; } else if (opt_kind == TCP_OPT_NO_OP) { opt_len = 1; } else { if (opt_avail < 2) { fprintf(stderr, "parse_options: opt_avail=%u kind=%u off=%u\n", opt_avail, opt_kind, off); return -1; } opt_len = opt[off + 1]; if (opt_kind == TCP_OPT_TIMESTAMP) { if (opt_len != sizeof(struct tcp_timestamp_opt)) { fprintf(stderr, "parse_options: opt_len=%u so=%zu\n", opt_len, sizeof(struct tcp_timestamp_opt)); return -1; } opts->ts = (struct tcp_timestamp_opt *) (opt + off); } } off += opt_len; } return 0; }
/* Copyright (C) CFEngine AS This file is part of CFEngine 3 - written and maintained by CFEngine AS. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 3. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA To the extent this program is licensed as part of the Enterprise versions of CFEngine, the applicable Commercial Open Source License (COSL) may apply to this file if you as a licensee so wish it. See included file COSL.txt. */ #ifndef CFENGINE_HASH_H #define CFENGINE_HASH_H /** @brief Hash implementations */ #include <openssl/rsa.h> #include <hash_method.h> /* HashMethod, HashSize */ typedef struct Hash Hash; /** @brief Creates a new structure of type Hash. @param data String to hash. @param length Length of the string to hash. @param method Hash method. @return A structure of type Hash or NULL in case of error. */ Hash *HashNew(const char *data, const unsigned int length, HashMethod method); /** @brief Creates a new structure of type Hash. @param descriptor Either file descriptor or socket descriptor. @param method Hash method. @return A structure of type Hash or NULL in case of error. */ Hash *HashNewFromDescriptor(const int descriptor, HashMethod method); /** @brief Creates a new structure of type Hash. @param rsa RSA key to be hashed. @param method Hash method. @return A structure of type Hash or NULL in case of error. */ Hash *HashNewFromKey(const RSA *rsa, HashMethod method); /** @brief Destroys a structure of type Hash. @param hash The structure to be destroyed. */ void HashDestroy(Hash **hash); /** @brief Copy a hash @param origin Hash to be copied. @param destination Hash to be copied to. @return 0 if successful, -1 in any other case. */ int HashCopy(Hash *origin, Hash **destination); /** @brief Checks if two hashes are equal. @param a 1st hash to be compared. @param b 2nd hash to be compared. @return True if both hashes are equal and false in any other case. */ int HashEqual(const Hash *a, const Hash *b); /** @brief Pointer to the raw digest data. @note Notice that this is a binary representation and not '\0' terminated. @param hash Hash structure. @param length Pointer to an unsigned int to hold the length of the data. @return A pointer to the raw digest data. */ const unsigned char *HashData(const Hash *hash, unsigned int *length); /** @brief Printable hash representation. @param hash Hash structure. @return A pointer to the printable digest representation. */ const char *HashPrintable(const Hash *hash); /** @brief Hash type. @param hash Hash structure @return The hash method used by this hash structure. */ HashMethod HashType(const Hash *hash); /** @brief Hash length in bytes. @param hash Hash structure @return The hash length in bytes. */ HashSize HashLength(const Hash *hash); /** @brief Returns the ID of the hash based on the name @param hash_name Name of the hash. @return Returns the ID of the hash from the name. */ HashMethod HashIdFromName(const char *hash_name); /** @brief Returns the name of the hash based on the ID. @param hash_id Id of the hash. @return Returns the name of the hash. */ const char *HashNameFromId(HashMethod hash_id); /** @brief Size of the hash @param method Hash method @return Returns the size of the hash or 0 in case of error. */ HashSize HashSizeFromId(HashMethod hash_id); #endif // CFENGINE_HASH_H
/* * Copyright (c) 2009 Wind River Systems, Inc. * Tom Rix <Tom.Rix at windriver.com> * * SPDX-License-Identifier: GPL-2.0+ * * twl4030_led_init is from cpu/omap3/common.c, power_init_r * * (C) Copyright 2004-2008 * Texas Instruments, <www.ti.com> * * Author : * Sunil Kumar <sunilsaini05 at gmail.com> * Shashi Ranjan <shashiranjanmca05 at gmail.com> * * Derived from Beagle Board and 3430 SDP code by * Richard Woodruff <r-woodruff2 at ti.com> * Syed Mohammed Khasim <khasim at ti.com> */ #include <twl4030.h> void twl4030_led_init(unsigned char ledon_mask) { /* LEDs need to have corresponding PWMs enabled */ if (ledon_mask & TWL4030_LED_LEDEN_LEDAON) ledon_mask |= TWL4030_LED_LEDEN_LEDAPWM; if (ledon_mask & TWL4030_LED_LEDEN_LEDBON) ledon_mask |= TWL4030_LED_LEDEN_LEDBPWM; twl4030_i2c_write_u8(TWL4030_CHIP_LED, TWL4030_LED_LEDEN, ledon_mask); }
/* * Texas Instrument's NFC Driver For Shared Transport. * * NFC Driver acts as interface between NCI core and * TI Shared Transport Layer. * * Copyright (C) 2011 Texas Instruments, Inc. * * Written by Ilan Elias <ilane@ti.com> * * Acknowledgements: * This file is based on btwilink.c, which was written * by Raja Mani and Pavan Savoy. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include <linux/platform_device.h> #include <linux/module.h> #include <linux/types.h> #include <linux/firmware.h> #include <linux/nfc.h> #include <net/nfc/nci.h> #include <net/nfc/nci_core.h> #include <linux/ti_wilink_st.h> #define NFCWILINK_CHNL 12 #define NFCWILINK_OPCODE 7 #define NFCWILINK_MAX_FRAME_SIZE 300 #define NFCWILINK_HDR_LEN 4 #define NFCWILINK_OFFSET_LEN_IN_HDR 1 #define NFCWILINK_LEN_SIZE 2 #define NFCWILINK_REGISTER_TIMEOUT 8000 /* 8 sec */ #define NFCWILINK_CMD_TIMEOUT 5000 /* 5 sec */ #define BTS_FILE_NAME_MAX_SIZE 40 #define BTS_FILE_HDR_MAGIC 0x42535442 #define BTS_FILE_CMD_MAX_LEN 0xff #define BTS_FILE_ACTION_TYPE_SEND_CMD 1 #define NCI_VS_NFCC_INFO_CMD_GID 0x2f #define NCI_VS_NFCC_INFO_CMD_OID 0x12 #define NCI_VS_NFCC_INFO_RSP_GID 0x4f #define NCI_VS_NFCC_INFO_RSP_OID 0x12 struct nfcwilink_hdr { __u8 chnl; __u8 opcode; __le16 len; } __packed; struct nci_vs_nfcc_info_cmd { __u8 gid; __u8 oid; __u8 plen; } __packed; struct nci_vs_nfcc_info_rsp { __u8 gid; __u8 oid; __u8 plen; __u8 status; __u8 hw_id; __u8 sw_ver_x; __u8 sw_ver_z; __u8 patch_id; } __packed; struct bts_file_hdr { __le32 magic; __le32 ver; __u8 rfu[24]; __u8 actions[0]; } __packed; struct bts_file_action { __le16 type; __le16 len; __u8 data[0]; } __packed; struct nfcwilink { struct platform_device *pdev; struct nci_dev *ndev; unsigned long flags; char st_register_cb_status; long (*st_write) (struct sk_buff *); struct completion completed; struct nci_vs_nfcc_info_rsp nfcc_info; }; /* NFCWILINK driver flags */ enum { NFCWILINK_RUNNING, NFCWILINK_FW_DOWNLOAD, }; static int nfcwilink_send(struct sk_buff *skb); static inline struct sk_buff *nfcwilink_skb_alloc(unsigned int len, gfp_t how) { struct sk_buff *skb; skb = alloc_skb(len + NFCWILINK_HDR_LEN, how); if (skb) skb_reserve(skb, NFCWILINK_HDR_LEN); return skb; } static void nfcwilink_fw_download_receive(struct nfcwilink *drv, struct sk_buff *skb) { struct nci_vs_nfcc_info_rsp *rsp = (void *)skb->data; /* Detect NCI_VS_NFCC_INFO_RSP and store the result */ if ((skb->len > 3) && (rsp->gid == NCI_VS_NFCC_INFO_RSP_GID) && (rsp->oid == NCI_VS_NFCC_INFO_RSP_OID)) { memcpy(&drv->nfcc_info, rsp, sizeof(struct nci_vs_nfcc_info_rsp)); } kfree_skb(skb); complete(&drv->completed); } static int nfcwilink_get_bts_file_name(struct nfcwilink *drv, char *file_name) { struct nci_vs_nfcc_info_cmd *cmd; struct sk_buff *skb; unsigned long comp_ret; int rc; nfc_dev_dbg(&drv->pdev->dev, "get_bts_file_name entry"); skb = nfcwilink_skb_alloc(sizeof(struct nci_vs_nfcc_info_cmd), GFP_KERNEL); if (!skb) { nfc_dev_err(&drv->pdev->dev, "no memory for nci_vs_nfcc_info_cmd"); return -ENOMEM; } skb->dev = (void *)drv->ndev; cmd = (struct nci_vs_nfcc_info_cmd *) skb_put(skb, sizeof(struct nci_vs_nfcc_info_cmd)); cmd->gid = NCI_VS_NFCC_INFO_CMD_GID; cmd->oid = NCI_VS_NFCC_INFO_CMD_OID; cmd->plen = 0; drv->nfcc_info.plen = 0; rc = nfcwilink_send(skb); if (rc) return rc; comp_ret = wait_for_completion_timeout(&drv->completed, msecs_to_jiffies(NFCWILINK_CMD_TIMEOUT)); nfc_dev_dbg(&drv->pdev->dev, "wait_for_completion_timeout returned %ld", comp_ret); if (comp_ret == 0) { nfc_dev_err(&drv->pdev->dev, "timeout on wait_for_completion_timeout"); return -ETIMEDOUT; } nfc_dev_dbg(&drv->pdev->dev, "nci_vs_nfcc_info_rsp: plen %d, status %d", drv->nfcc_info.plen, drv->nfcc_info.status); if ((drv->nfcc_info.plen != 5) || (drv->nfcc_info.status != 0)) { nfc_dev_err(&drv->pdev->dev, "invalid nci_vs_nfcc_info_rsp"); return -EINVAL; } snprintf(file_name, BTS_FILE_NAME_MAX_SIZE, "TINfcInit_%d.%d.%d.%d.bts", drv->nfcc_info.hw_id, drv->nfcc_info.sw_ver_x, drv->nfcc_info.sw_ver_z, drv->nfcc_info.patch_id); nfc_dev_info(&drv->pdev->dev, "nfcwilink FW file name: %s", file_name); return 0; } static int nfcwilink_send_bts_cmd(struct nfcwilink *drv, __u8 *data, int len) { struct nfcwilink_hdr *hdr = (struct nfcwilink_hdr *)data; struct sk_buff *skb; unsigned long comp_ret; int rc; nfc_dev_dbg(&drv->pdev->dev, "send_bts_cmd entry"); /* verify valid cmd for the NFC channel */ if ((len <= sizeof(struct nfcwilink_hdr)) || (len > BTS_FILE_CMD_MAX_LEN) || (hdr->chnl != NFCWILINK_CHNL) || (hdr->opcode != NFCWILINK_OPCODE)) { nfc_dev_err(&drv->pdev->dev, "ignoring invalid bts cmd, len %d, chnl %d, opcode %d", len, hdr->chnl, hdr->opcode); return 0; } /* remove the ST header */ len -= sizeof(struct nfcwilink_hdr); data += sizeof(struct nfcwilink_hdr); skb = nfcwilink_skb_alloc(len, GFP_KERNEL); if (!skb) { nfc_dev_err(&drv->pdev->dev, "no memory for bts cmd"); return -ENOMEM; } skb->dev = (void *)drv->ndev; memcpy(skb_put(skb, len), data, len); rc = nfcwilink_send(skb); if (rc) return rc; comp_ret = wait_for_completion_timeout(&drv->completed, msecs_to_jiffies(NFCWILINK_CMD_TIMEOUT)); nfc_dev_dbg(&drv->pdev->dev, "wait_for_completion_timeout returned %ld", comp_ret); if (comp_ret == 0) { nfc_dev_err(&drv->pdev->dev, "timeout on wait_for_completion_timeout"); return -ETIMEDOUT; } return 0; } static int nfcwilink_download_fw(struct nfcwilink *drv) { unsigned char file_name[BTS_FILE_NAME_MAX_SIZE]; const struct firmware *fw; __u16 action_type, action_len; __u8 *ptr; int len, rc; nfc_dev_dbg(&drv->pdev->dev, "download_fw entry"); set_bit(NFCWILINK_FW_DOWNLOAD, &drv->flags); rc = nfcwilink_get_bts_file_name(drv, file_name); if (rc) goto exit; rc = request_firmware(&fw, file_name, &drv->pdev->dev); if (rc) { nfc_dev_err(&drv->pdev->dev, "request_firmware failed %d", rc); /* if the file is not found, don't exit with failure */ if (rc == -ENOENT) rc = 0; goto exit; } len = fw->size; ptr = (__u8 *)fw->data; if ((len == 0) || (ptr == NULL)) { nfc_dev_dbg(&drv->pdev->dev, "request_firmware returned size %d", len); goto release_fw; } if (__le32_to_cpu(((struct bts_file_hdr *)ptr)->magic) != BTS_FILE_HDR_MAGIC) { nfc_dev_err(&drv->pdev->dev, "wrong bts magic number"); rc = -EINVAL; goto release_fw; } /* remove the BTS header */ len -= sizeof(struct bts_file_hdr); ptr += sizeof(struct bts_file_hdr); while (len > 0) { action_type = __le16_to_cpu(((struct bts_file_action *)ptr)->type); action_len = __le16_to_cpu(((struct bts_file_action *)ptr)->len); nfc_dev_dbg(&drv->pdev->dev, "bts_file_action type %d, len %d", action_type, action_len); switch (action_type) { case BTS_FILE_ACTION_TYPE_SEND_CMD: rc = nfcwilink_send_bts_cmd(drv, ((struct bts_file_action *)ptr)->data, action_len); if (rc) goto release_fw; break; } /* advance to the next action */ len -= (sizeof(struct bts_file_action) + action_len); ptr += (sizeof(struct bts_file_action) + action_len); } release_fw: release_firmware(fw); exit: clear_bit(NFCWILINK_FW_DOWNLOAD, &drv->flags); return rc; } /* Called by ST when registration is complete */ static void nfcwilink_register_complete(void *priv_data, char data) { struct nfcwilink *drv = priv_data; nfc_dev_dbg(&drv->pdev->dev, "register_complete entry"); /* store ST registration status */ drv->st_register_cb_status = data; /* complete the wait in nfc_st_open() */ complete(&drv->completed); } /* Called by ST when receive data is available */ static long nfcwilink_receive(void *priv_data, struct sk_buff *skb) { struct nfcwilink *drv = priv_data; int rc; if (!skb) return -EFAULT; if (!drv) { kfree_skb(skb); return -EFAULT; } nfc_dev_dbg(&drv->pdev->dev, "receive entry, len %d", skb->len); /* strip the ST header (apart for the chnl byte, which is not received in the hdr) */ skb_pull(skb, (NFCWILINK_HDR_LEN-1)); if (test_bit(NFCWILINK_FW_DOWNLOAD, &drv->flags)) { nfcwilink_fw_download_receive(drv, skb); return 0; } skb->dev = (void *) drv->ndev; /* Forward skb to NCI core layer */ rc = nci_recv_frame(skb); if (rc < 0) { nfc_dev_err(&drv->pdev->dev, "nci_recv_frame failed %d", rc); return rc; } return 0; } /* protocol structure registered with ST */ static struct st_proto_s nfcwilink_proto = { .chnl_id = NFCWILINK_CHNL, .max_frame_size = NFCWILINK_MAX_FRAME_SIZE, .hdr_len = (NFCWILINK_HDR_LEN-1), /* not including chnl byte */ .offset_len_in_hdr = NFCWILINK_OFFSET_LEN_IN_HDR, .len_size = NFCWILINK_LEN_SIZE, .reserve = 0, .recv = nfcwilink_receive, .reg_complete_cb = nfcwilink_register_complete, .write = NULL, }; static int nfcwilink_open(struct nci_dev *ndev) { struct nfcwilink *drv = nci_get_drvdata(ndev); unsigned long comp_ret; int rc; nfc_dev_dbg(&drv->pdev->dev, "open entry"); if (test_and_set_bit(NFCWILINK_RUNNING, &drv->flags)) { rc = -EBUSY; goto exit; } nfcwilink_proto.priv_data = drv; init_completion(&drv->completed); drv->st_register_cb_status = -EINPROGRESS; rc = st_register(&nfcwilink_proto); if (rc < 0) { if (rc == -EINPROGRESS) { comp_ret = wait_for_completion_timeout( &drv->completed, msecs_to_jiffies(NFCWILINK_REGISTER_TIMEOUT)); nfc_dev_dbg(&drv->pdev->dev, "wait_for_completion_timeout returned %ld", comp_ret); if (comp_ret == 0) { /* timeout */ rc = -ETIMEDOUT; goto clear_exit; } else if (drv->st_register_cb_status != 0) { rc = drv->st_register_cb_status; nfc_dev_err(&drv->pdev->dev, "st_register_cb failed %d", rc); goto clear_exit; } } else { nfc_dev_err(&drv->pdev->dev, "st_register failed %d", rc); goto clear_exit; } } /* st_register MUST fill the write callback */ BUG_ON(nfcwilink_proto.write == NULL); drv->st_write = nfcwilink_proto.write; if (nfcwilink_download_fw(drv)) { nfc_dev_err(&drv->pdev->dev, "nfcwilink_download_fw failed %d", rc); /* open should succeed, even if the FW download failed */ } goto exit; clear_exit: clear_bit(NFCWILINK_RUNNING, &drv->flags); exit: return rc; } static int nfcwilink_close(struct nci_dev *ndev) { struct nfcwilink *drv = nci_get_drvdata(ndev); int rc; nfc_dev_dbg(&drv->pdev->dev, "close entry"); if (!test_and_clear_bit(NFCWILINK_RUNNING, &drv->flags)) return 0; rc = st_unregister(&nfcwilink_proto); if (rc) nfc_dev_err(&drv->pdev->dev, "st_unregister failed %d", rc); drv->st_write = NULL; return rc; } static int nfcwilink_send(struct sk_buff *skb) { struct nci_dev *ndev = (struct nci_dev *)skb->dev; struct nfcwilink *drv = nci_get_drvdata(ndev); struct nfcwilink_hdr hdr = {NFCWILINK_CHNL, NFCWILINK_OPCODE, 0x0000}; long len; nfc_dev_dbg(&drv->pdev->dev, "send entry, len %d", skb->len); if (!test_bit(NFCWILINK_RUNNING, &drv->flags)) { kfree_skb(skb); return -EINVAL; } /* add the ST hdr to the start of the buffer */ hdr.len = cpu_to_le16(skb->len); memcpy(skb_push(skb, NFCWILINK_HDR_LEN), &hdr, NFCWILINK_HDR_LEN); /* Insert skb to shared transport layer's transmit queue. * Freeing skb memory is taken care in shared transport layer, * so don't free skb memory here. */ len = drv->st_write(skb); if (len < 0) { kfree_skb(skb); nfc_dev_err(&drv->pdev->dev, "st_write failed %ld", len); return -EFAULT; } return 0; } static struct nci_ops nfcwilink_ops = { .open = nfcwilink_open, .close = nfcwilink_close, .send = nfcwilink_send, }; static int nfcwilink_probe(struct platform_device *pdev) { static struct nfcwilink *drv; int rc; __u32 protocols; nfc_dev_dbg(&pdev->dev, "probe entry"); drv = devm_kzalloc(&pdev->dev, sizeof(struct nfcwilink), GFP_KERNEL); if (!drv) { rc = -ENOMEM; goto exit; } drv->pdev = pdev; protocols = NFC_PROTO_JEWEL_MASK | NFC_PROTO_MIFARE_MASK | NFC_PROTO_FELICA_MASK | NFC_PROTO_ISO14443_MASK | NFC_PROTO_ISO14443_B_MASK | NFC_PROTO_NFC_DEP_MASK; drv->ndev = nci_allocate_device(&nfcwilink_ops, protocols, NFC_SE_NONE, NFCWILINK_HDR_LEN, 0); if (!drv->ndev) { nfc_dev_err(&pdev->dev, "nci_allocate_device failed"); rc = -ENOMEM; goto exit; } nci_set_parent_dev(drv->ndev, &pdev->dev); nci_set_drvdata(drv->ndev, drv); rc = nci_register_device(drv->ndev); if (rc < 0) { nfc_dev_err(&pdev->dev, "nci_register_device failed %d", rc); goto free_dev_exit; } dev_set_drvdata(&pdev->dev, drv); goto exit; free_dev_exit: nci_free_device(drv->ndev); exit: return rc; } static int nfcwilink_remove(struct platform_device *pdev) { struct nfcwilink *drv = dev_get_drvdata(&pdev->dev); struct nci_dev *ndev; nfc_dev_dbg(&pdev->dev, "remove entry"); if (!drv) return -EFAULT; ndev = drv->ndev; nci_unregister_device(ndev); nci_free_device(ndev); dev_set_drvdata(&pdev->dev, NULL); return 0; } static struct platform_driver nfcwilink_driver = { .probe = nfcwilink_probe, .remove = nfcwilink_remove, .driver = { .name = "nfcwilink", .owner = THIS_MODULE, }, }; module_platform_driver(nfcwilink_driver); /* ------ Module Info ------ */ MODULE_AUTHOR("Ilan Elias <ilane@ti.com>"); MODULE_DESCRIPTION("NFC Driver for TI Shared Transport"); MODULE_LICENSE("GPL");
/** * \brief Performs a smooth(er) interpolation between 0 and 1 with 1st and 2nd order derivatives of zero at endpoints. * \remarks See https://en.wikipedia.org/wiki/Smoothstep * \param amount Value between 0 and 1 indicating interpolation amount. */ inline float smootherstep(float amount) { if (amount <= 0) { return 0; } return amount >= 1 ? 1 : amount * amount * amount * (amount * (amount * 6 - 15) + 10); }
/** * Initialize the resolver: set up the UDP pcb and configure the default server * (DNS_SERVER_ADDRESS). */ void dns_init() { struct ip_addr dnsserver; dnsserver.addr = DNS_SERVER_ADDRESS; LWIP_DEBUGF(DNS_DEBUG, ("dns_init: initializing\n")); if (dns_pcb == NULL) { dns_pcb = udp_new(); if (dns_pcb != NULL) { LWIP_ASSERT("For implicit initialization to work, DNS_STATE_UNUSED needs to be 0", DNS_STATE_UNUSED == 0); udp_bind(dns_pcb, IP_ADDR_ANY, 0); udp_recv(dns_pcb, dns_recv, NULL); dns_setserver(0, &dnsserver); } } }
/* Release the free page cache to the system. */ static void release_pages () { #ifdef USING_MMAP page_entry *p, *next; char *start; size_t len; p = G.free_pages; while (p) { start = p->page; next = p->next; len = p->bytes; free (p); p = next; while (p && p->page == start + len) { next = p->next; len += p->bytes; free (p); p = next; } munmap (start, len); G.bytes_mapped -= len; } G.free_pages = NULL; #endif #ifdef USING_MALLOC_PAGE_GROUPS page_entry **pp, *p; page_group **gp, *g; pp = &G.free_pages; while ((p = *pp) != NULL) if (p->group->in_use == 0) { *pp = p->next; free (p); } else pp = &p->next; gp = &G.page_groups; while ((g = *gp) != NULL) if (g->in_use == 0) { *gp = g->next; G.bytes_mapped -= g->alloc_size; free (g->allocation); } else gp = &g->next; #endif }
// // Copy fields from JSON event to the event struct, for events of the // type "Change Connection". Return value is 0 upon error, 1 upon success. // static int spindump_event_parser_json_parse_aux_change_connection(const struct spindump_json_value* json, struct spindump_event* event) { This always succeeds return(1); }
// pBuffer is a pointer to the beginning of where the X.224 data header // will be. Required encoding size for the whole PDU is given in // macro DUinPDUSize(). void CreateDetachUserInd( MCSReason Reason, int NUserIDs, UserID *UserIDs, BYTE *pBuffer) { int i, EncodedLength, NBytesConsumed; BOOLEAN bLarge; pBuffer[X224_DataHeaderSize] = MCS_DETACH_USER_INDICATION_ENUM << 2; pBuffer[X224_DataHeaderSize + 1] = 0; Put3BitFieldAtBit1(pBuffer + X224_DataHeaderSize, Reason); EncodeLengthDeterminantPER( pBuffer + X224_DataHeaderSize + 2, NUserIDs, &EncodedLength, &bLarge, &NBytesConsumed); ASSERT(!bLarge); for (i = 0; i < NUserIDs; i++) PutUserID(pBuffer + X224_DataHeaderSize + 2 + NBytesConsumed + sizeof(short) * i, UserIDs[i]); CreateX224DataHeader(pBuffer, DUinBaseSize(NUserIDs), TRUE); }
#include<stdio.h> int main() { int t; scanf("%d",&t); while(t--) { int n; int count=0; scanf("%d",&n); int wan,qian,bai,shi,ge; ge = n % 10; shi = (n - ge)%100; bai = (n - ge - shi)%1000; qian = (n - ge - shi - bai)%10000; wan = (n - ge - shi - bai - qian)%100000; if(ge != 0) { count++; } if(shi != 0) { count++; } if(bai != 0) { count++; } if(qian != 0) { count++; } if(wan != 0) { count++; } printf("%d\n",count); if(ge != 0) { printf("%d ",ge); } if(shi != 0) { printf("%d ",shi); } if(bai != 0) { printf("%d ",bai); } if(qian != 0) { printf("%d ",qian); } if(wan != 0) { printf("%d ",wan); } printf("\n"); } return 0; }
#include <stdio.h> int main(void) { int j,n,i; int x[5] = { 0, 0, 0, 0, 0 }; scanf("%d", &n); for(i=0;i<n;i++) { scanf("%d", &j); x[j]++; } if(x[3] >= x[1] ) { x[4] = x[4] + x[1]; x[3] = x[3] - x[1]; x[1] = 0; } else if (x[3] < x[1]) { x[4] = x[4] + x[3]; x[1] = x[1] - x[3]; x[3] = 0; } if(x[2]%2 == 0) { x[4] = x[4] + (x[2] / 2); x[2] = 0; } else if(x[2] > 2) { x[4] = x[4] + (x[2] / 2); x[2] = 1; if(x[1] >= 2) { x[4] = x[4] + 1; x[2] = 0; x[1] = x[1] - 2; } } if(x[1] %4 == 0) { x[4] = x[4] + (x[1]/4); x[1] = 0; } else { x[4] = x[4] + (x[1]/4); x[1] = x[1] % 4; if(x[1] == 3) { x[3] = x[3] + 1; x[1] = 0; } else if (x[1] == 2) { x[2] = x[2] + 1; x[1] = 0; } } if(x[1] >= x[2] ) { x[3] = x[3] + x[2]; x[1] = x[1] - x[2]; x[2] = 0; } else if (x[1] < x[2]) { x[3] = x[3] + x[1]; x[2] = x[2] - x[1]; x[1] = 0; } if(x[3] >= x[1] ) { x[4] = x[4] + x[1]; x[3] = x[3] - x[1]; x[1] = 0; } else if (x[3] < x[1]) { x[4] = x[4] + x[3]; x[1] = x[1] - x[3]; x[3] = 0; } if(x[1] >= 3) { x[3] = x[3] + (x[1] / 3); x[1] = x[1] % 3; } else if(x[1] >= 2) { x[2] = x[2] + (x[1] / 2); x[1] = x[1] % 2; } if(x[2]%2 == 0) { x[4] = x[4] + (x[2] / 2); x[2] = 0; } else if(x[2] >= 2) { x[4] = x[4] + (x[2] / 2); x[2] = 1; } printf("%d", x[1]+x[2]+x[3]+x[4]) ; }
/** * lpfc_nlp_logo_unreg - Unreg mailbox completion handler before LOGO * @phba: Pointer to HBA context object. * @pmb: Pointer to mailbox object. * * This function will issue an ELS LOGO command after completing * the UNREG_RPI. **/ void lpfc_nlp_logo_unreg(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) { struct lpfc_vport *vport = pmb->vport; struct lpfc_nodelist *ndlp; ndlp = (struct lpfc_nodelist *)(pmb->context1); if (!ndlp) return; lpfc_issue_els_logo(vport, ndlp, 0); mempool_free(pmb, phba->mbox_mem_pool); }
/************************************************************************* ************************************************************************** #cat: free_shape - Deallocates a shape structure and all its allocated #cat: attributes. Input: shape - pointer to the shape structure to be deallocated **************************************************************************/ void free_shape(SHAPE *shape) { int i; for(i = 0; i < shape->alloc; i++){ free(shape->rows[i]->xs); free(shape->rows[i]); } free(shape->rows); free(shape); }
/**************************************************/ /* */ /* Read the output header template file. */ /* Specifically extract the image size info. */ /* */ /**************************************************/ int mDiff_readTemplate(char *filename) { int i; FILE *fp; char line[MAXSTR]; fp = fopen(filename, "r"); if(fp == (FILE *)NULL) { mDiff_printError("Template file not found."); return 1; } while(1) { if(fgets(line, MAXSTR, fp) == (char *)NULL) break; if(line[strlen(line)-1] == '\n') line[strlen(line)-1] = '\0'; if(line[strlen(line)-1] == '\r') line[strlen(line)-1] = '\0'; if(mDiff_debug >= 3) { printf("Template line: [%s]\n", line); fflush(stdout); } for(i=strlen(line); i<80; ++i) line[i] = ' '; line[80] = '\0'; mDiff_parseLine(line); } fclose(fp); return 0; }
/* * Establish a link-map mode, initializing it if it has just been loaded, or * potentially updating it if it already exists. */ int update_mode(Rt_map *lmp, int omode, int nmode) { Lm_list *lml = LIST(lmp); int pmode = 0; if ((FLAGS(lmp) & FLG_RT_MODESET) == 0) { MODE(lmp) |= nmode & ~(RTLD_PARENT | RTLD_NOLOAD | RTLD_FIRST); FLAGS(lmp) |= FLG_RT_MODESET; return (1); } if ((omode & RTLD_LAZY) && (nmode & RTLD_NOW)) { MODE(lmp) &= ~RTLD_LAZY; pmode |= RTLD_NOW; } pmode |= ((~omode & nmode) & (RTLD_GLOBAL | RTLD_WORLD | RTLD_NODELETE)); if (pmode) { DBG_CALL(Dbg_file_mode_promote(lmp, pmode)); MODE(lmp) |= pmode; } if ((pmode & RTLD_NOW) && (FLAGS(lmp) & (FLG_RT_RELOCED | FLG_RT_RELOCING))) { Lm_cntl *lmc; lmc = (Lm_cntl *)alist_item_by_offset(LIST(lmp)->lm_lists, CNTL(lmp)); (void) aplist_append(&lmc->lc_now, lmp, AL_CNT_LMNOW); } if (((FLAGS(lmp) & (FLG_RT_INITCLCT | FLG_RT_INITCALL)) == FLG_RT_INITCLCT) && ((lml->lm_flags & LML_FLG_OBJADDED) || ((pmode & RTLD_NOW) && (FLAGS(lmp) & (FLG_RT_RELOCED | FLG_RT_RELOCING))))) { FLAGS(lmp) &= ~FLG_RT_INITCLCT; LIST(lmp)->lm_init++; LIST(lmp)->lm_flags |= LML_FLG_OBJREEVAL; } return (pmode); }
// Returns 0 on success, non-zero on failure. int entropy_getrandom(unsigned char* buf, size_t len) { while (len) { ssize_t bytes_read = getrandom(buf, len, 0); if (bytes_read == -1) { if (errno != EINTR) return -1; else continue; } len -= bytes_read; buf += bytes_read; } return 0; }
/* BLIS An object-based framework for developing high-performance BLAS-like libraries. Copyright (C) 2014, The University of Texas at Austin Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name(s) of the copyright holder(s) nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "vector_int_macros.h" #define D_ASSEMBLE_VEC_PAIR \ __builtin_mma_assemble_pair (&colA_1, ca[1], ca[0]); \ __builtin_mma_assemble_pair (&colA_2, ca[3], ca[2]); #define D_ACCUMULATE \ __builtin_mma_xvf64gerpp (&acc0, colA_1, rb[0]); \ __builtin_mma_xvf64gerpp (&acc1, colA_1, rb[1]); \ __builtin_mma_xvf64gerpp (&acc2, colA_1, rb[2]); \ __builtin_mma_xvf64gerpp (&acc3, colA_1, rb[3]); \ __builtin_mma_xvf64gerpp (&acc4, colA_2, rb[0]); \ __builtin_mma_xvf64gerpp (&acc5, colA_2, rb[1]); \ __builtin_mma_xvf64gerpp (&acc6, colA_2, rb[2]); \ __builtin_mma_xvf64gerpp (&acc7, colA_2, rb[3]); #define D_INCREMENT \ A0+=8; \ B0+=8; #define D_AB_PRODUCT \ LOAD_VECTORS \ D_ASSEMBLE_VEC_PAIR \ D_INCREMENT \ D_ACCUMULATE void bli_dgemm_power10_mma_8x8 ( dim_t m, dim_t n, dim_t k, const void* alpha, const void* a, const void* b, const void* beta, void* c, inc_t rs_c0, inc_t cs_c0, auxinfo_t* data, const cntx_t* cntx ) { // Typecast local copies of integers in case dim_t and inc_t are a // different size than is expected by load instructions. uint64_t k_iter = k / 4; uint64_t k_left = k % 4; uint64_t rs_c = rs_c0; uint64_t cs_c = cs_c0; GEMM_UKR_SETUP_CT( d, 8, 8, true ); const double* restrict A0 = a; const double* restrict B0 = b; double* restrict C0 = c; double alpha_ = *((double*)alpha), beta_ = *((double*)beta); dv4sf_t result[4]; dv4sf_t *rowC; /* 8 accumulator registers that will be used to store the result. Each accumulator register is mapped to 4 vector registers. Illustration: acc0 = [ vs0 vs1 vs3 vs4 ] These registers are used to store the result of an outer product instruction (general outer product instruction syntax: xv???ger??). */ __vector_quad acc0, acc1, acc2, acc3, acc4, acc5, acc6, acc7; // initialize the accumulators to zeros __builtin_mma_xxsetaccz(&acc0); __builtin_mma_xxsetaccz(&acc1); __builtin_mma_xxsetaccz(&acc2); __builtin_mma_xxsetaccz(&acc3); __builtin_mma_xxsetaccz(&acc4); __builtin_mma_xxsetaccz(&acc5); __builtin_mma_xxsetaccz(&acc6); __builtin_mma_xxsetaccz(&acc7); /* 2 vector pairs are necessary for a double precision outer product instruction. */ __vector_pair colA_1, colA_2; /* Prefetch C so that it stays in cache */ PREFETCH1 (C0, 0); PREFETCH1 (C0 + rs_c, 0); PREFETCH1 (C0 + rs_c + rs_c, 0); PREFETCH1 (C0 + rs_c + rs_c + rs_c, 0); PREFETCH1 (C0, 128); PREFETCH1 (C0 + rs_c, 128); PREFETCH1 (C0 + rs_c + rs_c, 128); PREFETCH1 (C0 + rs_c + rs_c + rs_c, 128); /* Load elements into vector registers */ vec_t *ca = (vec_t *) A0; vec_t *rb = (vec_t *) B0; /* Each accumulator represents a matrix of size 4 x ( 16 / (datatype size in bytes) ) (vector register size = 16B) Thus in the case of double, the accumulate registers represent a 4x2 matrix. However, a vector register can hold at most 2 doubles. Thus, if we performed an outer product using 2 vector register, we can only get a 2x2 matrix. Therefore, we must create a vector register pair in order to get the desired 4x2 matrix. */ D_ASSEMBLE_VEC_PAIR // k loop (unrolled by 4) for (int k = 0; k<k_iter; k++) { D_AB_PRODUCT D_AB_PRODUCT D_AB_PRODUCT D_AB_PRODUCT } // edge loop for (int k = 0; k<k_left; k++) { D_AB_PRODUCT } // handle beta cases if (beta_ != 0.0) { SAVE_ACC(dv4sf_t, &acc0, rs_c, 0 ); SAVE_ACC(dv4sf_t, &acc1, rs_c, 2 ); SAVE_ACC(dv4sf_t, &acc2, rs_c, 4 ); SAVE_ACC(dv4sf_t, &acc3, rs_c, 6 ); SAVE_ACC(dv4sf_t, &acc4, rs_c, 4*rs_c); SAVE_ACC(dv4sf_t, &acc5, rs_c, 2+4*rs_c); SAVE_ACC(dv4sf_t, &acc6, rs_c, 4+4*rs_c); SAVE_ACC(dv4sf_t, &acc7, rs_c, 6+4*rs_c); } else { SAVE_ACC_bz(dv4sf_t, &acc0, rs_c, 0 ); SAVE_ACC_bz(dv4sf_t, &acc1, rs_c, 2 ); SAVE_ACC_bz(dv4sf_t, &acc2, rs_c, 4 ); SAVE_ACC_bz(dv4sf_t, &acc3, rs_c, 6 ); SAVE_ACC_bz(dv4sf_t, &acc4, rs_c, 4*rs_c); SAVE_ACC_bz(dv4sf_t, &acc5, rs_c, 2+4*rs_c); SAVE_ACC_bz(dv4sf_t, &acc6, rs_c, 4+4*rs_c); SAVE_ACC_bz(dv4sf_t, &acc7, rs_c, 6+4*rs_c); } GEMM_UKR_FLUSH_CT( d ); }
// Copyright (c) the JPEG XL Project Authors. All rights reserved. // // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. #ifndef LIB_JPEGLI_ENTROPY_CODING_H_ #define LIB_JPEGLI_ENTROPY_CODING_H_ /* clang-format off */ #include <stdio.h> #include <jpeglib.h> /* clang-format on */ namespace jpegli { size_t MaxNumTokensPerMCURow(j_compress_ptr cinfo); size_t EstimateNumTokens(j_compress_ptr cinfo, size_t mcu_y, size_t ysize_mcus, size_t num_tokens, size_t max_per_row); void TokenizeJpeg(j_compress_ptr cinfo); void CopyHuffmanTables(j_compress_ptr cinfo); void OptimizeHuffmanCodes(j_compress_ptr cinfo); void InitEntropyCoder(j_compress_ptr cinfo); } // namespace jpegli #endif // LIB_JPEGLI_ENTROPY_CODING_H_
/** * @brief Initializes the CRYP peripheral in AES CTR decryption mode * then decrypted pCypherData. The cypher data are available in pPlainData * @param hcryp pointer to a CRYP_HandleTypeDef structure that contains * the configuration information for CRYP module * @param pCypherData Pointer to the cyphertext buffer * @param Size Length of the plaintext buffer, must be a multiple of 16. * @param pPlainData Pointer to the plaintext buffer * @param Timeout Specify Timeout value * @retval HAL status */ HAL_StatusTypeDef HAL_CRYP_AESCTR_Decrypt(CRYP_HandleTypeDef *hcryp, uint8_t *pCypherData, uint16_t Size, uint8_t *pPlainData, uint32_t Timeout) { __HAL_LOCK(hcryp); if(hcryp->Phase == HAL_CRYP_PHASE_READY) { hcryp->State = HAL_CRYP_STATE_BUSY; CRYP_SetKey(hcryp, hcryp->Init.pKey, hcryp->Init.KeySize); __HAL_CRYP_SET_MODE(hcryp, CRYP_CR_ALGOMODE_AES_CTR | CRYP_CR_ALGODIR); CRYP_SetInitVector(hcryp, hcryp->Init.pInitVect, CRYP_KEYSIZE_128B); __HAL_CRYP_FIFO_FLUSH(hcryp); __HAL_CRYP_ENABLE(hcryp); hcryp->Phase = HAL_CRYP_PHASE_PROCESS; } if(CRYP_ProcessData(hcryp, pCypherData, Size, pPlainData, Timeout) != HAL_OK) { return HAL_TIMEOUT; } hcryp->State = HAL_CRYP_STATE_READY; __HAL_UNLOCK(hcryp); return HAL_OK; }
/* * Adjust quota limits, and start/stop timers accordingly. */ int xfs_qm_scall_setqlim( struct xfs_mount *mp, xfs_dqid_t id, uint type, struct qc_dqblk *newlim) { struct xfs_quotainfo *q = mp->m_quotainfo; struct xfs_disk_dquot *ddq; struct xfs_dquot *dqp; struct xfs_trans *tp; struct xfs_def_quota *defq; int error; xfs_qcnt_t hard, soft; if (newlim->d_fieldmask & ~XFS_QC_MASK) return -EINVAL; if ((newlim->d_fieldmask & XFS_QC_MASK) == 0) return 0; mutex_lock(&q->qi_quotaofflock); error = xfs_qm_dqget(mp, NULL, id, type, XFS_QMOPT_DQALLOC, &dqp); if (error) { ASSERT(error != -ENOENT); goto out_unlock; } defq = xfs_get_defquota(dqp, q); xfs_dqunlock(dqp); error = xfs_trans_alloc(mp, &M_RES(mp)->tr_qm_setqlim, 0, 0, 0, &tp); if (error) goto out_rele; xfs_dqlock(dqp); xfs_trans_dqjoin(tp, dqp); ddq = &dqp->q_core; hard = (newlim->d_fieldmask & QC_SPC_HARD) ? (xfs_qcnt_t) XFS_B_TO_FSB(mp, newlim->d_spc_hardlimit) : be64_to_cpu(ddq->d_blk_hardlimit); soft = (newlim->d_fieldmask & QC_SPC_SOFT) ? (xfs_qcnt_t) XFS_B_TO_FSB(mp, newlim->d_spc_softlimit) : be64_to_cpu(ddq->d_blk_softlimit); if (hard == 0 || hard >= soft) { ddq->d_blk_hardlimit = cpu_to_be64(hard); ddq->d_blk_softlimit = cpu_to_be64(soft); xfs_dquot_set_prealloc_limits(dqp); if (id == 0) { defq->bhardlimit = hard; defq->bsoftlimit = soft; } } else { xfs_debug(mp, "blkhard %Ld < blksoft %Ld", hard, soft); } hard = (newlim->d_fieldmask & QC_RT_SPC_HARD) ? (xfs_qcnt_t) XFS_B_TO_FSB(mp, newlim->d_rt_spc_hardlimit) : be64_to_cpu(ddq->d_rtb_hardlimit); soft = (newlim->d_fieldmask & QC_RT_SPC_SOFT) ? (xfs_qcnt_t) XFS_B_TO_FSB(mp, newlim->d_rt_spc_softlimit) : be64_to_cpu(ddq->d_rtb_softlimit); if (hard == 0 || hard >= soft) { ddq->d_rtb_hardlimit = cpu_to_be64(hard); ddq->d_rtb_softlimit = cpu_to_be64(soft); if (id == 0) { defq->rtbhardlimit = hard; defq->rtbsoftlimit = soft; } } else { xfs_debug(mp, "rtbhard %Ld < rtbsoft %Ld", hard, soft); } hard = (newlim->d_fieldmask & QC_INO_HARD) ? (xfs_qcnt_t) newlim->d_ino_hardlimit : be64_to_cpu(ddq->d_ino_hardlimit); soft = (newlim->d_fieldmask & QC_INO_SOFT) ? (xfs_qcnt_t) newlim->d_ino_softlimit : be64_to_cpu(ddq->d_ino_softlimit); if (hard == 0 || hard >= soft) { ddq->d_ino_hardlimit = cpu_to_be64(hard); ddq->d_ino_softlimit = cpu_to_be64(soft); if (id == 0) { defq->ihardlimit = hard; defq->isoftlimit = soft; } } else { xfs_debug(mp, "ihard %Ld < isoft %Ld", hard, soft); } if (newlim->d_fieldmask & QC_SPC_WARNS) ddq->d_bwarns = cpu_to_be16(newlim->d_spc_warns); if (newlim->d_fieldmask & QC_INO_WARNS) ddq->d_iwarns = cpu_to_be16(newlim->d_ino_warns); if (newlim->d_fieldmask & QC_RT_SPC_WARNS) ddq->d_rtbwarns = cpu_to_be16(newlim->d_rt_spc_warns); if (id == 0) { if (newlim->d_fieldmask & QC_SPC_TIMER) { q->qi_btimelimit = newlim->d_spc_timer; ddq->d_btimer = cpu_to_be32(newlim->d_spc_timer); } if (newlim->d_fieldmask & QC_INO_TIMER) { q->qi_itimelimit = newlim->d_ino_timer; ddq->d_itimer = cpu_to_be32(newlim->d_ino_timer); } if (newlim->d_fieldmask & QC_RT_SPC_TIMER) { q->qi_rtbtimelimit = newlim->d_rt_spc_timer; ddq->d_rtbtimer = cpu_to_be32(newlim->d_rt_spc_timer); } if (newlim->d_fieldmask & QC_SPC_WARNS) q->qi_bwarnlimit = newlim->d_spc_warns; if (newlim->d_fieldmask & QC_INO_WARNS) q->qi_iwarnlimit = newlim->d_ino_warns; if (newlim->d_fieldmask & QC_RT_SPC_WARNS) q->qi_rtbwarnlimit = newlim->d_rt_spc_warns; } else { xfs_qm_adjust_dqtimers(mp, ddq); } dqp->dq_flags |= XFS_DQ_DIRTY; xfs_trans_log_dquot(tp, dqp); error = xfs_trans_commit(tp); out_rele: xfs_qm_dqrele(dqp); out_unlock: mutex_unlock(&q->qi_quotaofflock); return error; }
/* Delete_edge but try not to mess up outer face. * Also faces have symedges now, so make sure not * to mess those up either. */ static void dissolve_symedge(CDT_state *cdt, SymEdge *se) { SymEdge *symse = sym(se); if (symse->face == cdt->outer_face) { se = sym(se); symse = sym(se); } if (cdt->outer_face->symedge == se || cdt->outer_face->symedge == symse) { if (se->next->next == se) { cdt->outer_face->symedge = NULL; } else { cdt->outer_face->symedge = se->next->next; } } else { if (se->face->symedge == se) { se->face->symedge = se->next; } if (symse->face->symedge == symse) { symse->face->symedge = symse->next; } } delete_edge(cdt, se); }
/* * linux/arch/arm/mach-at91/board-csb637.c * * Copyright (C) 2005 SAN People * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include <linux/types.h> #include <linux/init.h> #include <linux/mm.h> #include <linux/module.h> #include <linux/platform_device.h> #include <linux/mtd/physmap.h> #include <asm/setup.h> #include <asm/mach-types.h> #include <asm/irq.h> #include <asm/mach/arch.h> #include <asm/mach/map.h> #include <asm/mach/irq.h> #include <mach/hardware.h> #include <mach/board.h> #include <mach/gpio.h> #include "generic.h" static void __init csb637_init_early(void) { /* Initialize processor: 3.6864 MHz crystal */ at91rm9200_initialize(3686400); /* DBGU on ttyS0. (Rx & Tx only) */ at91_register_uart(0, 0, 0); /* make console=ttyS0 (ie, DBGU) the default */ at91_set_serial_console(0); } static void __init csb637_init_irq(void) { at91rm9200_init_interrupts(NULL); } static struct at91_eth_data __initdata csb637_eth_data = { .phy_irq_pin = AT91_PIN_PC0, .is_rmii = 0, }; static struct at91_usbh_data __initdata csb637_usbh_data = { .ports = 2, }; static struct at91_udc_data __initdata csb637_udc_data = { .vbus_pin = AT91_PIN_PB28, .pullup_pin = AT91_PIN_PB1, }; #define CSB_FLASH_BASE AT91_CHIPSELECT_0 #define CSB_FLASH_SIZE SZ_16M static struct mtd_partition csb_flash_partitions[] = { { .name = "uMON flash", .offset = 0, .size = MTDPART_SIZ_FULL, .mask_flags = MTD_WRITEABLE, /* read only */ } }; static struct physmap_flash_data csb_flash_data = { .width = 2, .parts = csb_flash_partitions, .nr_parts = ARRAY_SIZE(csb_flash_partitions), }; static struct resource csb_flash_resources[] = { { .start = CSB_FLASH_BASE, .end = CSB_FLASH_BASE + CSB_FLASH_SIZE - 1, .flags = IORESOURCE_MEM, } }; static struct platform_device csb_flash = { .name = "physmap-flash", .id = 0, .dev = { .platform_data = &csb_flash_data, }, .resource = csb_flash_resources, .num_resources = ARRAY_SIZE(csb_flash_resources), }; static struct gpio_led csb_leds[] = { { /* "d1", red */ .name = "d1", .gpio = AT91_PIN_PB2, .active_low = 1, .default_trigger = "heartbeat", }, }; static void __init csb637_board_init(void) { /* LED(s) */ at91_gpio_leds(csb_leds, ARRAY_SIZE(csb_leds)); /* Serial */ at91_add_device_serial(); /* Ethernet */ at91_add_device_eth(&csb637_eth_data); /* USB Host */ at91_add_device_usbh(&csb637_usbh_data); /* USB Device */ at91_add_device_udc(&csb637_udc_data); /* I2C */ at91_add_device_i2c(NULL, 0); /* SPI */ at91_add_device_spi(NULL, 0); /* NOR flash */ platform_device_register(&csb_flash); } MACHINE_START(CSB637, "Cogent CSB637") /* Maintainer: Bill Gatliff */ .timer = &at91rm9200_timer, .map_io = at91rm9200_map_io, .init_early = csb637_init_early, .init_irq = csb637_init_irq, .init_machine = csb637_board_init, MACHINE_END
/** * @brief Update Terminal characteristic value * @param uint8_t *data string to write * @param uint32_t length Length of string to write * @retval tBleStatus Status */ tBleStatus Term_Update(uint8_t *data, uint8_t length) { uint32_t Offset; uint8_t DataToSend; msgData_t msg; msg.type = TERM_STDOUT; for(Offset =0; Offset<length; Offset +=W2ST_MAX_CHAR_LEN){ DataToSend = (length-Offset); DataToSend = (DataToSend>W2ST_MAX_CHAR_LEN) ? W2ST_MAX_CHAR_LEN : DataToSend; memcpy(LastTermBuffer,data+Offset,DataToSend); LastTermLen = DataToSend; msg.term.length = DataToSend; memcpy(msg.term.data,data+Offset,DataToSend); SendMsgToHost(&msg); } return BLE_STATUS_SUCCESS; }
/* * Copyright 2019 The WebRTC Project Authors. All rights reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source * tree. An additional intellectual property rights grant can be found * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree. */ #ifndef VIDEO_QUALITY_LIMITATION_REASON_TRACKER_H_ #define VIDEO_QUALITY_LIMITATION_REASON_TRACKER_H_ #include <map> #include "common_video/include/quality_limitation_reason.h" #include "system_wrappers/include/clock.h" namespace webrtc { // A tracker of quality limitation reasons. The quality limitation reason is the // primary reason for limiting resolution and/or framerate (such as CPU or // bandwidth limitations). The tracker keeps track of the current reason and the // duration of time spent in each reason. See qualityLimitationReason[1], // qualityLimitationDurations[2], and qualityLimitationResolutionChanges[3] in // the webrtc-stats spec. // Note that the specification defines the durations in seconds while the // internal data structures defines it in milliseconds. // [1] // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-qualitylimitationreason // [2] // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-qualitylimitationdurations // [3] // https://w3c.github.io/webrtc-stats/#dom-rtcoutboundrtpstreamstats-qualitylimitationresolutionchanges class QualityLimitationReasonTracker { public: // The caller is responsible for making sure `clock` outlives the tracker. explicit QualityLimitationReasonTracker(Clock* clock); // The current reason defaults to QualityLimitationReason::kNone. QualityLimitationReason current_reason() const; void SetReason(QualityLimitationReason reason); std::map<QualityLimitationReason, int64_t> DurationsMs() const; private: Clock* const clock_; QualityLimitationReason current_reason_; int64_t current_reason_updated_timestamp_ms_; // The total amount of time spent in each reason at time // `current_reason_updated_timestamp_ms_`. To get the total amount duration // so-far, including the time spent in `current_reason_` elapsed since the // last time `current_reason_` was updated, see DurationsMs(). std::map<QualityLimitationReason, int64_t> durations_ms_; }; } // namespace webrtc #endif // VIDEO_QUALITY_LIMITATION_REASON_TRACKER_H_
#include<stdio.h> int main() { int a[3], b[3], n, i = 0, s = 4, c = 9; for(i = 0; i<3; i++) { scanf("%d", &a[i]); s = s+a[i]; } for(i = 0; i<3; i++) { scanf("%d", &b[i]); c = c+b[i]; } scanf("%d", &n); int k = s/5; int j = c/10; if(k+j <= n) { printf("YES\n"); } else { printf("NO\n"); } }