hexsha
stringlengths
40
40
size
int64
5
1.05M
ext
stringclasses
588 values
lang
stringclasses
305 values
max_stars_repo_path
stringlengths
3
363
max_stars_repo_name
stringlengths
5
118
max_stars_repo_head_hexsha
stringlengths
40
40
max_stars_repo_licenses
listlengths
1
10
max_stars_count
float64
1
191k
max_stars_repo_stars_event_min_datetime
stringdate
2015-01-01 00:00:35
2022-03-31 23:43:49
max_stars_repo_stars_event_max_datetime
stringdate
2015-01-01 12:37:38
2022-03-31 23:59:52
max_issues_repo_path
stringlengths
3
363
max_issues_repo_name
stringlengths
5
118
max_issues_repo_head_hexsha
stringlengths
40
40
max_issues_repo_licenses
listlengths
1
10
max_issues_count
float64
1
134k
max_issues_repo_issues_event_min_datetime
stringlengths
24
24
max_issues_repo_issues_event_max_datetime
stringlengths
24
24
max_forks_repo_path
stringlengths
3
363
max_forks_repo_name
stringlengths
5
135
max_forks_repo_head_hexsha
stringlengths
40
40
max_forks_repo_licenses
listlengths
1
10
max_forks_count
float64
1
105k
max_forks_repo_forks_event_min_datetime
stringdate
2015-01-01 00:01:02
2022-03-31 23:27:27
max_forks_repo_forks_event_max_datetime
stringdate
2015-01-03 08:55:07
2022-03-31 23:59:24
content
stringlengths
5
1.05M
avg_line_length
float64
1.13
1.04M
max_line_length
int64
1
1.05M
alphanum_fraction
float64
0
1
0f37b782ced064b477e2b3ae9c985ca3fbd51e32
3,410
h
C
src/ywindow_lib/card.h
Niakr1s/yWindow
f0e4ee8b5b88ea01fe6587861f917adb9e311f92
[ "MIT" ]
1
2022-02-06T14:00:06.000Z
2022-02-06T14:00:06.000Z
src/ywindow_lib/card.h
Niakr1s/yWindow
f0e4ee8b5b88ea01fe6587861f917adb9e311f92
[ "MIT" ]
1
2022-02-06T13:59:52.000Z
2022-02-06T13:59:52.000Z
src/ywindow_lib/card.h
Niakr1s/yWindow
f0e4ee8b5b88ea01fe6587861f917adb9e311f92
[ "MIT" ]
null
null
null
#ifndef CARD_H #define CARD_H #include <map> #include <memory> #include <string> #include <vector> namespace dict { class Dictionary; struct Tag { Tag(); std::string tag; std::string keyword; int rating = 0; std::string description; }; using TagMap = std::map<std::string, Tag>; class Card { public: virtual ~Card(); std::string reading(); // please, separate separate readings by ";" virtual std::string originWord() const; virtual std::string word() const = 0; virtual std::vector<std::string> readings() const = 0; virtual std::string meaning() const = 0; virtual std::string dictionaryInfo() const = 0; virtual void setDictionaryInfo(std::shared_ptr<std::string> info) = 0; virtual std::string etc() const; virtual bool isProxy() const; virtual bool isKanji() const; virtual bool isTerm() const; }; class DefaultCard : public Card { public: DefaultCard(Dictionary* dict); void setWord(const std::string& word); Dictionary* dict() const; std::string dictionaryInfo() const override; void setDictionaryInfo(std::shared_ptr<std::string> info) override; std::string word() const override; protected: std::shared_ptr<std::string> dict_info_; std::string word_; }; class YomiDictionary; class YomiCard : public DefaultCard { public: YomiCard(Dictionary* dict); void addTag(const std::string& tag); void setTags(std::vector<std::string>&& tags); void addMeaning(const std::string& meaning); std::vector<std::string> readings() const override; std::string meaning() const override; void setReading(const std::vector<std::string>& readings); protected: std::vector<std::string> meanings_; std::vector<std::string> tags_; std::vector<std::string> readings_; }; class YomiTermCard : public YomiCard { public: using YomiCard::YomiCard; virtual bool isTerm() const override; }; class YomiKanjiCard : public YomiCard { public: using YomiCard::YomiCard; virtual bool isKanji() const override; }; class DeinflectDictionary; class DeinflectCard : public DefaultCard { public: DeinflectCard(Dictionary* dict); void setReading(const std::string& reading); std::vector<std::string> readings() const override; std::string meaning() const override; private: std::string reading_; }; class UserCard : public DefaultCard { public: UserCard(Dictionary* dict); void setReading(const std::string& reading); void setMeaning(const std::string& meaning); std::vector<std::string> readings() const override; std::string meaning() const override; private: std::string reading_, meaning_; }; class ProxyCard : public Card { public: ProxyCard(std::shared_ptr<Card> card, const std::string& word); std::string originWord() const override; std::string word() const override; std::vector<std::string> readings() const override; std::string meaning() const override; std::string dictionaryInfo() const override; std::string etc() const override; void setDictionaryInfo(std::shared_ptr<std::string> info) override; virtual bool isProxy() const override; virtual bool isTerm() const override; virtual bool isKanji() const override; private: std::shared_ptr<Card> card_; std::string word_; }; using CardPtr = std::shared_ptr<Card>; using CardPtrMap = std::multimap<std::string, CardPtr>; using CardPtrs = std::vector<CardPtr>; } // namespace dict #endif // CARD_H
22.434211
72
0.713783
2419e2a05010449c48feb6b592ee6dc5ad8eb653
1,357
h
C
src/application/worldState/component/SurfaceImplementation.h
MoritzWillig/Ape
dccca2ba03f25e9d70c31ef98e336ec90277831a
[ "MIT" ]
null
null
null
src/application/worldState/component/SurfaceImplementation.h
MoritzWillig/Ape
dccca2ba03f25e9d70c31ef98e336ec90277831a
[ "MIT" ]
null
null
null
src/application/worldState/component/SurfaceImplementation.h
MoritzWillig/Ape
dccca2ba03f25e9d70c31ef98e336ec90277831a
[ "MIT" ]
null
null
null
#pragma once #include <string> #include <common/signals/Signal.h> #include "worldState.h" namespace ape { namespace worldState { class SurfaceImplementation: public ISurface { private: ValueSignal<std::string> path; ValueSignal<bool> isExisting; protected: ValueSignal<ISurface::SurfacePersistentHandle> handle; std::string name; cv::Mat texture; void probeSurfaceExisting(); public: //Default SurfaceImplementation(); SurfaceImplementation( std::string path, ISurface::SurfacePersistentHandle handle, std::string name); // Copy constructor SurfaceImplementation(const SurfaceImplementation&) = default; // Move constructor SurfaceImplementation(SurfaceImplementation&&) = default; // Copy assignment operator SurfaceImplementation& operator=(const SurfaceImplementation&)& = default; // Move assignment operator SurfaceImplementation& operator=(SurfaceImplementation&&)& = default; // Destructor virtual ~SurfaceImplementation() = default; virtual std::string getName() override; virtual ValueSignal<ISurface::SurfacePersistentHandle> getPersistentHandle() override; virtual cv::Mat getTexture() override; void setTexture(cv::Mat texture); }; } }
23
80
0.680177
0f937648dc63bdf81aa64fa78989d3d723ecf28e
59
h
C
extlibs/freetype-2.5.2/src/pcf/PaxHeaders.20920/pcfdrivr.h
halak/bibim
ad01efa8aac4f074f64bf033ac0f1ed382060334
[ "curl" ]
3
2016-08-28T06:48:11.000Z
2019-12-04T13:04:34.000Z
extlibs/freetype-2.5.2/src/pcf/PaxHeaders.20920/pcfdrivr.h
Darkttd/Bibim
9dec24529ef89536f7686abc1245ea5fc7fa9474
[ "curl" ]
8
2016-04-24T13:07:28.000Z
2016-06-01T10:04:42.000Z
extlibs/freetype-2.5.2/src/pcf/PaxHeaders.20920/pcfdrivr.h
Darkttd/Bibim
9dec24529ef89536f7686abc1245ea5fc7fa9474
[ "curl" ]
1
2016-08-28T06:47:43.000Z
2016-08-28T06:47:43.000Z
30 atime=1386526222.340499735 29 ctime=1374498496.57830894
19.666667
29
0.864407
be5ad1865e0f2479d7e84c6365c7ff3175f375d4
9,141
c
C
parameters.c
hrjung/smtr_v1
9d2e0b2d060fd190d416fb2ecf5b3aa00c987d25
[ "MIT" ]
1
2021-09-03T12:23:44.000Z
2021-09-03T12:23:44.000Z
parameters.c
hrjung/smtr_v1
9d2e0b2d060fd190d416fb2ecf5b3aa00c987d25
[ "MIT" ]
null
null
null
parameters.c
hrjung/smtr_v1
9d2e0b2d060fd190d416fb2ecf5b3aa00c987d25
[ "MIT" ]
1
2021-02-16T21:21:07.000Z
2021-02-16T21:21:07.000Z
//########################################################################### // // FILE: common_tools.c // // TITLE: // //########################################################################### #include <stdarg.h> #include <stdint.h> #include <stdbool.h> #include <Assert.h> #include "main.h" #include "inv_param.h" #include "parameters.h" #include "common_tools.h" #include "uartstdio.h" //***************************************************************************** // //! \addtogroup //! @{ // //***************************************************************************** inv_parameter_st iparam[INV_PARAM_INDEX_MAX]; inv_parameter_st err_info[ERR_CODE_MAX]; inv_parameter_st inv_status[INV_STATUS_MAX]; //***************************************************************************** // // Function implementation // //***************************************************************************** void PARAM_init(void) { iparam[FREQ_VALUE_INDEX].type = PARAMETER_TYPE_FLOAT; iparam[FREQ_VALUE_INDEX].value.f = 10.0; iparam[ACCEL_TIME_INDEX].type = PARAMETER_TYPE_FLOAT; iparam[ACCEL_TIME_INDEX].value.f = 10.0; iparam[DECEL_TIME_INDEX].type = PARAMETER_TYPE_FLOAT; iparam[DECEL_TIME_INDEX].value.f = 10.0; iparam[VF_FOC_SEL_INDEX].type = PARAMETER_TYPE_LONG; iparam[VF_FOC_SEL_INDEX].value.l = VF_CONTROL; iparam[ENERGY_SAVE_INDEX].type = PARAMETER_TYPE_LONG; iparam[ENERGY_SAVE_INDEX].value.l = ESAVE_UNUSED; iparam[PWM_FREQ_INDEX].type = PARAMETER_TYPE_LONG; iparam[PWM_FREQ_INDEX].value.l = PWM_4KHz; iparam[JUMP_ENABLE0_INDEX].type = PARAMETER_TYPE_LONG; iparam[JUMP_ENABLE0_INDEX].value.l = NOT_USED; iparam[JUMP_LOW0_INDEX].type = PARAMETER_TYPE_FLOAT; iparam[JUMP_LOW0_INDEX].value.f = 0.0; iparam[JUMP_HIGH0_INDEX].type = PARAMETER_TYPE_FLOAT; iparam[JUMP_HIGH0_INDEX].value.f = 0.0; iparam[JUMP_ENABLE1_INDEX].type = PARAMETER_TYPE_LONG; iparam[JUMP_ENABLE1_INDEX].value.l = NOT_USED; iparam[JUMP_LOW1_INDEX].type = PARAMETER_TYPE_FLOAT; iparam[JUMP_LOW1_INDEX].value.f = 0.0; iparam[JUMP_HIGH1_INDEX].type = PARAMETER_TYPE_FLOAT; iparam[JUMP_HIGH1_INDEX].value.f = 0.0; iparam[JUMP_ENABLE2_INDEX].type = PARAMETER_TYPE_LONG; iparam[JUMP_ENABLE2_INDEX].value.l = NOT_USED; iparam[JUMP_LOW2_INDEX].type = PARAMETER_TYPE_FLOAT; iparam[JUMP_LOW2_INDEX].value.f = 0.0; iparam[JUMP_HIGH2_INDEX].type = PARAMETER_TYPE_FLOAT; iparam[JUMP_HIGH2_INDEX].value.f = 0.0; iparam[V_BOOST_INDEX].type = PARAMETER_TYPE_FLOAT; iparam[V_BOOST_INDEX].value.f = 0.0; iparam[FOC_TORQUE_LIMIT_INDEX].type = PARAMETER_TYPE_FLOAT; iparam[FOC_TORQUE_LIMIT_INDEX].value.f = 180.0; iparam[BRK_TYPE_INDEX].type = PARAMETER_TYPE_LONG; iparam[BRK_TYPE_INDEX].value.l = REDUCE_SPEED_BRAKE; iparam[BRK_FREQ_INDEX].type = PARAMETER_TYPE_FLOAT; iparam[BRK_FREQ_INDEX].value.f = 3.0; iparam[BRK_DCI_START_FREQ_INDEX].type = PARAMETER_TYPE_FLOAT; iparam[BRK_DCI_START_FREQ_INDEX].value.f = REDUCE_SPEED_BRAKE; iparam[BRK_DCI_BLOCK_TIME_INDEX].type = PARAMETER_TYPE_FLOAT; iparam[BRK_DCI_BLOCK_TIME_INDEX].value.f = 1.0; iparam[BRK_DCI_BRAKING_TIME_INDEX].type = PARAMETER_TYPE_FLOAT; iparam[BRK_DCI_BRAKING_TIME_INDEX].value.f = 5.0; iparam[BRK_DCI_BRAKING_RATE_INDEX].type = PARAMETER_TYPE_FLOAT; iparam[BRK_DCI_BRAKING_RATE_INDEX].value.f = 50.0; iparam[OVL_WARN_LIMIT_INDEX].type = PARAMETER_TYPE_LONG; iparam[OVL_WARN_LIMIT_INDEX].value.l = 150; iparam[OVL_WR_DURATION_INDEX].type = PARAMETER_TYPE_LONG; iparam[OVL_WR_DURATION_INDEX].value.l = 10; iparam[OVL_ENABLE_INDEX].type = PARAMETER_TYPE_LONG; iparam[OVL_ENABLE_INDEX].value.l = 1; //use iparam[OVL_TR_LIMIT_INDEX].type = PARAMETER_TYPE_LONG; iparam[OVL_TR_LIMIT_INDEX].value.l = 180; iparam[OVL_TR_DURATION_INDEX].type = PARAMETER_TYPE_LONG; iparam[OVL_TR_DURATION_INDEX].value.l = 30; iparam[REGEN_RESISTANCE_INDEX].type = PARAMETER_TYPE_FLOAT; iparam[REGEN_RESISTANCE_INDEX].value.f = 200.0; iparam[REGEN_THERMAL_INDEX].type = PARAMETER_TYPE_FLOAT; iparam[REGEN_THERMAL_INDEX].value.f = 5.0; iparam[REGEN_POWER_INDEX].type = PARAMETER_TYPE_LONG; iparam[REGEN_POWER_INDEX].value.l = 200; iparam[REGEN_BAND_INDEX].type = PARAMETER_TYPE_LONG; iparam[REGEN_BAND_INDEX].value.l = 0; iparam[STATOR_RESISTANCE_INDEX].type = PARAMETER_TYPE_FLOAT; iparam[STATOR_RESISTANCE_INDEX].value.f = 2.5; iparam[ROTATOR_RESISTANCE_INDEX].type = PARAMETER_TYPE_FLOAT; iparam[ROTATOR_RESISTANCE_INDEX].value.f = 2.14568; iparam[INDUCTANCE_INDEX].type = PARAMETER_TYPE_FLOAT; iparam[INDUCTANCE_INDEX].value.f = 0.013955; iparam[NOLOAD_CURRENT_INDEX].type = PARAMETER_TYPE_FLOAT; iparam[NOLOAD_CURRENT_INDEX].value.f = 2.0; iparam[RATED_CURRENT_INDEX].type = PARAMETER_TYPE_FLOAT; iparam[RATED_CURRENT_INDEX].value.f = 3.4; iparam[POLES_INDEX].type = PARAMETER_TYPE_LONG; iparam[POLES_INDEX].value.l = 2; iparam[INPUT_VOLTAGE_INDEX].type = PARAMETER_TYPE_LONG; iparam[INPUT_VOLTAGE_INDEX].value.l = 380; iparam[RATED_FREQ_INDEX].type = PARAMETER_TYPE_LONG; iparam[RATED_FREQ_INDEX].value.l = 60; // error parameter PARAM_initErrInfo(); // inverter status PARAM_initInvStatus(); } void PARAM_update(uint16_t index, uint16_t *buf) { iparam[index].value.arr[0] = buf[0]; iparam[index].value.arr[1] = buf[1]; } uint16_t PARAM_getValue(uint16_t index, uint16_t *buf) { #if 1 // test only iparam[index].value.f = 3.14; #endif buf[0] = iparam[index].value.arr[0]; buf[1] = iparam[index].value.arr[1]; return 2; // size } void PARAM_initErrInfo(void) { err_info[ERR_CODE_INDEX].type = PARAMETER_TYPE_LONG; err_info[ERR_CODE_INDEX].value.l = 0; err_info[ERR_CURRENT_INDEX].type = PARAMETER_TYPE_FLOAT; err_info[ERR_CURRENT_INDEX].value.f = 0.0; err_info[ERR_FREQ_INDEX].type = PARAMETER_TYPE_FLOAT; err_info[ERR_FREQ_INDEX].value.f = 0.0; } void PARAM_setErrInfo(uint16_t err_code, uint16_t err_status, float_t current, float_t freq) { err_info[ERR_CODE_INDEX].value.arr[0] = err_code; err_info[ERR_CODE_INDEX].value.arr[1] = err_status; err_info[ERR_CURRENT_INDEX].value.f = current; err_info[ERR_FREQ_INDEX].value.f = freq; } uint16_t PARAM_getErrorInfo(uint16_t *buf) { #if 1 // test only err_info[ERR_CODE_INDEX].value.arr[0] = 0; err_info[ERR_CODE_INDEX].value.arr[1] = 1; err_info[ERR_CURRENT_INDEX].value.f = 10.5; err_info[ERR_FREQ_INDEX].value.f = 120.0; #endif buf[0] = err_info[ERR_CODE_INDEX].value.arr[0]; buf[1] = err_info[ERR_CODE_INDEX].value.arr[1]; buf[2] = err_info[ERR_CURRENT_INDEX].value.arr[0]; buf[3] = err_info[ERR_CURRENT_INDEX].value.arr[1]; buf[4] = err_info[ERR_FREQ_INDEX].value.arr[0]; buf[5] = err_info[ERR_FREQ_INDEX].value.arr[1]; return (ERR_CODE_MAX*2); } void PARAM_initInvStatus(void) { inv_status[INV_STATUS_INDEX].type = PARAMETER_TYPE_LONG; inv_status[INV_STATUS_INDEX].value.l = 0; inv_status[INV_I_RMS_INDEX].type = PARAMETER_TYPE_FLOAT; inv_status[INV_I_RMS_INDEX].value.f = 0.0; inv_status[INV_RUN_FREQ_INDEX].type = PARAMETER_TYPE_FLOAT; inv_status[INV_RUN_FREQ_INDEX].value.f = 0.0; inv_status[INV_DC_VOLTAGE_INDEX].type = PARAMETER_TYPE_FLOAT; inv_status[INV_DC_VOLTAGE_INDEX].value.f = 0.0; inv_status[INV_IPM_TEMP_INDEX].type = PARAMETER_TYPE_FLOAT; inv_status[INV_IPM_TEMP_INDEX].value.f = 0.0; inv_status[INV_MOTOR_TEMP_INDEX].type = PARAMETER_TYPE_FLOAT; inv_status[INV_MOTOR_TEMP_INDEX].value.f = 0.0; } void PARAM_setInvStatus(uint16_t run, uint16_t dir, float_t icurr, float_t freq, float_t vdc, float_t ipm_t, float_t mtr_t) { inv_status[INV_STATUS_INDEX].value.arr[0] = run; inv_status[INV_STATUS_INDEX].value.arr[1] = dir; inv_status[INV_I_RMS_INDEX].value.f = icurr; inv_status[INV_RUN_FREQ_INDEX].value.f = freq; inv_status[INV_DC_VOLTAGE_INDEX].value.f = vdc; inv_status[INV_IPM_TEMP_INDEX].value.f = ipm_t; inv_status[INV_MOTOR_TEMP_INDEX].value.f = mtr_t; } uint16_t PARAM_getInvStatus(uint16_t *buf) { #if 1 // test only inv_status[INV_STATUS_INDEX].value.arr[0] = 0; inv_status[INV_STATUS_INDEX].value.arr[1] = 1; inv_status[INV_I_RMS_INDEX].value.f = 2.1; inv_status[INV_RUN_FREQ_INDEX].value.f = 30.2; inv_status[INV_DC_VOLTAGE_INDEX].value.f = 531.3; inv_status[INV_IPM_TEMP_INDEX].value.f = 63.4; inv_status[INV_MOTOR_TEMP_INDEX].value.f = 54.1; #endif buf[0] = inv_status[INV_STATUS_INDEX].value.arr[0]; buf[1] = inv_status[INV_STATUS_INDEX].value.arr[1]; buf[2] = inv_status[INV_I_RMS_INDEX].value.arr[0]; buf[3] = inv_status[INV_I_RMS_INDEX].value.arr[1]; buf[4] = inv_status[INV_RUN_FREQ_INDEX].value.arr[0]; buf[5] = inv_status[INV_RUN_FREQ_INDEX].value.arr[1]; buf[6] = inv_status[INV_DC_VOLTAGE_INDEX].value.arr[0]; buf[7] = inv_status[INV_DC_VOLTAGE_INDEX].value.arr[1]; buf[8] = inv_status[INV_IPM_TEMP_INDEX].value.arr[0]; buf[9] = inv_status[INV_IPM_TEMP_INDEX].value.arr[1]; buf[10] = inv_status[INV_MOTOR_TEMP_INDEX].value.arr[0]; buf[11] = inv_status[INV_MOTOR_TEMP_INDEX].value.arr[1]; return (INV_STATUS_MAX*2); } //***************************************************************************** // // Close the Doxygen group. //! @} // //*****************************************************************************
31.304795
123
0.719396
d50afb48addba9961f9f3af4bede31ea8b0ca8b0
2,031
c
C
src/pkg/util/eprintf.c
uggedal/bare
f112dde89b03ab618aa6719a73943af3cc278b77
[ "0BSD" ]
27
2019-05-17T16:18:16.000Z
2022-02-03T00:29:31.000Z
src/pkg/util/eprintf.c
uggedal/bare
f112dde89b03ab618aa6719a73943af3cc278b77
[ "0BSD" ]
null
null
null
src/pkg/util/eprintf.c
uggedal/bare
f112dde89b03ab618aa6719a73943af3cc278b77
[ "0BSD" ]
4
2019-05-26T16:46:17.000Z
2022-01-27T19:13:55.000Z
/* * MIT/X Consortium License * * © 2011 Connor Lane Smith <cls@lubutu.com> * © 2011-2016 Dimitris Papastamos <sin@2f30.org> * © 2014-2016 Laslo Hunhold <dev@frign.de> * * 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 <stdarg.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include "../util.h" char *argv0; static void xvprintf(const char *, va_list); void eprintf(const char *fmt, ...) { va_list ap; va_start(ap, fmt); xvprintf(fmt, ap); va_end(ap); exit(1); } void enprintf(int status, const char *fmt, ...) { va_list ap; va_start(ap, fmt); xvprintf(fmt, ap); va_end(ap); exit(status); } void weprintf(const char *fmt, ...) { va_list ap; va_start(ap, fmt); xvprintf(fmt, ap); va_end(ap); } void xvprintf(const char *fmt, va_list ap) { if (argv0 && strncmp(fmt, "usage", strlen("usage"))) fprintf(stderr, "%s: ", argv0); vfprintf(stderr, fmt, ap); if (fmt[0] && fmt[strlen(fmt)-1] == ':') { fputc(' ', stderr); perror(NULL); } }
24.178571
77
0.700148
b93d52f52ba9e0f90ab6b44213ee9e0d6b6cc390
371
h
C
Classes/AYTextLabelCollectionView.h
alexyu1989/textExplosion
50d3e005f735f6b2545eb2cd1773108ecf753ce5
[ "MIT" ]
null
null
null
Classes/AYTextLabelCollectionView.h
alexyu1989/textExplosion
50d3e005f735f6b2545eb2cd1773108ecf753ce5
[ "MIT" ]
null
null
null
Classes/AYTextLabelCollectionView.h
alexyu1989/textExplosion
50d3e005f735f6b2545eb2cd1773108ecf753ce5
[ "MIT" ]
null
null
null
// // AYTextLabelCollectionView.h // TextExplosion // // Created by Alex Yu on 30/10/2016. // Copyright © 2016 Alex Yu. All rights reserved. // #import <UIKit/UIKit.h> @interface AYTextLabelCollectionView : UICollectionView @property (nonatomic, strong) NSArray<NSString *> *words; @property (nonatomic, strong, readonly) NSArray<NSString *> *selectedWords; @end
21.823529
75
0.733154
27b4b3fd1990b3fe60482d01cc0266570bb3102b
709
h
C
Util/fitsutil/fitsutil.h
xuanyuanstar/psrchive_CDFT
453c4dc05b8e901ea661cd02d4f0a30665dcaf35
[ "AFL-2.1" ]
null
null
null
Util/fitsutil/fitsutil.h
xuanyuanstar/psrchive_CDFT
453c4dc05b8e901ea661cd02d4f0a30665dcaf35
[ "AFL-2.1" ]
null
null
null
Util/fitsutil/fitsutil.h
xuanyuanstar/psrchive_CDFT
453c4dc05b8e901ea661cd02d4f0a30665dcaf35
[ "AFL-2.1" ]
null
null
null
//-*-C++-*- /*************************************************************************** * * Copyright (C) 2003 by Willem van Straten * Licensed under the Academic Free License version 2.1 * ***************************************************************************/ /* $Source: /cvsroot/psrchive/psrchive/Util/fitsutil/fitsutil.h,v $ $Revision: 1.5 $ $Date: 2009/11/30 11:39:01 $ $Author: straten $ */ #ifndef __FITS_UTIL_H #define __FITS_UTIL_H //! Infinity extern float fits_nullfloat; //! Convert FITS datatype to string const char* fits_datatype_str (int datatype); //! Checks that library and header version numbers match void fits_version_check (bool verbose = false); #endif
25.321429
77
0.552891
e0e5454676cb210598211b8eaa83d3d8ff50c160
2,484
h
C
apx/include/cpp-apx/numheader.h
cogu/cpp-apx
d4f0307115b10a24aa48139bb410d1869fcb161c
[ "MIT" ]
null
null
null
apx/include/cpp-apx/numheader.h
cogu/cpp-apx
d4f0307115b10a24aa48139bb410d1869fcb161c
[ "MIT" ]
null
null
null
apx/include/cpp-apx/numheader.h
cogu/cpp-apx
d4f0307115b10a24aa48139bb410d1869fcb161c
[ "MIT" ]
null
null
null
/***************************************************************************** * \file numheader.h * \author Conny Gustafsson * \date 2020-10-28 * \brief C++ implementation of the numheader protocol * * Copyright (c) 2020 Conny Gustafsson * 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. * ******************************************************************************/ #pragma once #include <cstdint> #include <cstddef> namespace numheader { constexpr std::uint16_t SHORT_MAX = 127u; constexpr std::uint16_t LONG16_MAX = INT16_MAX+INT8_MAX + 1u; constexpr std::uint32_t LONG32_MAX = INT32_MAX; constexpr std::size_t SHORT_SIZE = sizeof(std::uint8_t); constexpr std::size_t LONG16_SIZE = sizeof(std::uint16_t); constexpr std::size_t LONG32_SIZE = sizeof(std::uint32_t); constexpr std::uint16_t LONG16_FLAG = 0x8000ul; constexpr std::uint16_t LONG16_MASK = 0x7ffful; constexpr std::uint32_t LONG32_FLAG = 0x80000000ul; constexpr std::uint32_t LONG32_MASK = 0x7ffffffful; constexpr std::uint8_t LONG8_FLAG = 0x80u; std::size_t encode16(std::uint8_t* begin, std::uint8_t* end, std::uint16_t value); std::size_t decode16(std::uint8_t const* begin, std::uint8_t const* end, std::uint16_t& value); std::size_t encode32(std::uint8_t* begin, std::uint8_t* end, std::uint32_t value); std::size_t decode32(std::uint8_t const* begin, std::uint8_t const* end, std::uint32_t& value); }
52.851064
99
0.692029
f268a703886df505bc66d2e7656ac259b60461f0
657
h
C
redlib/include/Interval.h
alexandear/multi_threaded_prime_numbers
4b613f5d6e4b7db72b3375e530246bba3065853f
[ "Unlicense" ]
null
null
null
redlib/include/Interval.h
alexandear/multi_threaded_prime_numbers
4b613f5d6e4b7db72b3375e530246bba3065853f
[ "Unlicense" ]
null
null
null
redlib/include/Interval.h
alexandear/multi_threaded_prime_numbers
4b613f5d6e4b7db72b3375e530246bba3065853f
[ "Unlicense" ]
null
null
null
#pragma once #include <cstddef> #include "Utils.h" namespace red { class Interval { public: Interval() : Interval(0, 0) {} Interval(std::size_t low, std::size_t high); explicit Interval(const std::string& str); std::size_t GetLow() const { return m_low; } std::size_t GetHigh() const { return m_high; } std::string ToString() const; friend bool operator==(const Interval& lhs, const Interval& rhs); friend bool operator!=(const Interval& lhs, const Interval& rhs) { return !(lhs == rhs); } private: void Init(std::size_t low, std::size_t high); std::size_t m_low; std::size_t m_high; }; } // namespace red
21.9
94
0.656012
041475da7052739651faa50e8e65daa118f82c10
24
cats
C
data/1/175847.cats
ks2002119/EmailAnalysis
ea7b7499794061f73ac8141694833acdf813bdb3
[ "Apache-2.0" ]
null
null
null
data/1/175847.cats
ks2002119/EmailAnalysis
ea7b7499794061f73ac8141694833acdf813bdb3
[ "Apache-2.0" ]
null
null
null
data/1/175847.cats
ks2002119/EmailAnalysis
ea7b7499794061f73ac8141694833acdf813bdb3
[ "Apache-2.0" ]
null
null
null
1,1,2 2,2,2 2,3,2 3,6,2
4.8
5
0.5
1a2d737bb8784262db7e738594a3534c902e53c6
270
h
C
firmware/Inc/boot/main.h
SergeiSOficial/icaRUS
106ee24e6ce601df7046edd191da875ad957f360
[ "CC0-1.0" ]
1
2021-11-16T12:37:10.000Z
2021-11-16T12:37:10.000Z
firmware/Libs/wa1470/stm32l4x/Inc/boot/main.h
SergeiSOficial/icaRUS
106ee24e6ce601df7046edd191da875ad957f360
[ "CC0-1.0" ]
null
null
null
firmware/Libs/wa1470/stm32l4x/Inc/boot/main.h
SergeiSOficial/icaRUS
106ee24e6ce601df7046edd191da875ad957f360
[ "CC0-1.0" ]
null
null
null
#ifndef __MAIN_H #define __MAIN_H #include "stm32l4xx_ll_crc.h" #include "stm32l4xx_ll_bus.h" #include "stm32l4xx_ll_rcc.h" #include "stm32l4xx_ll_utils.h" #include "stm32l4xx_ll_system.h" #include "stm32l4xx_ll_pwr.h" void Error_Handler(void); #endif /* __MAIN_H */
19.285714
32
0.781481
1a7f24f634317a6631dc81b80f3c41a758bd9788
434
c
C
e5-process-management/t3-forking.c
chikarl/sys-programming-in-c
803dc629c90cda200f1df82184a95813a3717ec1
[ "MIT" ]
null
null
null
e5-process-management/t3-forking.c
chikarl/sys-programming-in-c
803dc629c90cda200f1df82184a95813a3717ec1
[ "MIT" ]
null
null
null
e5-process-management/t3-forking.c
chikarl/sys-programming-in-c
803dc629c90cda200f1df82184a95813a3717ec1
[ "MIT" ]
null
null
null
#include <sys/types.h> #include <unistd.h> #include <stdio.h> #include <stdlib.h> int global_var = 0; int main() { int local_var = 10; pid_t pid; pid_t cpid; pid = fork(); if(pid < 0) { printf("Error forking\n"); } else if (pid == 0) { printf("Child process\n"); sleep(20000); printf("Still sleeping"); } else { printf("Parent process\n"); //exit(0); } }
18.083333
35
0.525346
d233cb3b41d8ba0fae692c61942b91258b563c24
113,450
c
C
sound/core/pcm_native.c
jainsakshi2395/linux
7ccb860232bb83fb60cd6bcf5aaf0c008d903acb
[ "Linux-OpenIB" ]
2
2021-12-20T23:50:12.000Z
2022-01-03T16:06:00.000Z
sound/core/pcm_native.c
jainsakshi2395/linux
7ccb860232bb83fb60cd6bcf5aaf0c008d903acb
[ "Linux-OpenIB" ]
1
2021-01-27T01:29:47.000Z
2021-01-27T01:29:47.000Z
sound/core/pcm_native.c
jainsakshi2395/linux
7ccb860232bb83fb60cd6bcf5aaf0c008d903acb
[ "Linux-OpenIB" ]
1
2021-12-20T23:51:14.000Z
2021-12-20T23:51:14.000Z
// SPDX-License-Identifier: GPL-2.0-or-later /* * Digital Audio (PCM) abstract layer * Copyright (c) by Jaroslav Kysela <perex@perex.cz> */ #include <linux/compat.h> #include <linux/mm.h> #include <linux/module.h> #include <linux/file.h> #include <linux/slab.h> #include <linux/sched/signal.h> #include <linux/time.h> #include <linux/pm_qos.h> #include <linux/io.h> #include <linux/dma-mapping.h> #include <linux/vmalloc.h> #include <sound/core.h> #include <sound/control.h> #include <sound/info.h> #include <sound/pcm.h> #include <sound/pcm_params.h> #include <sound/timer.h> #include <sound/minors.h> #include <linux/uio.h> #include <linux/delay.h> #include "pcm_local.h" #ifdef CONFIG_SND_DEBUG #define CREATE_TRACE_POINTS #include "pcm_param_trace.h" #else #define trace_hw_mask_param_enabled() 0 #define trace_hw_interval_param_enabled() 0 #define trace_hw_mask_param(substream, type, index, prev, curr) #define trace_hw_interval_param(substream, type, index, prev, curr) #endif /* * Compatibility */ struct snd_pcm_hw_params_old { unsigned int flags; unsigned int masks[SNDRV_PCM_HW_PARAM_SUBFORMAT - SNDRV_PCM_HW_PARAM_ACCESS + 1]; struct snd_interval intervals[SNDRV_PCM_HW_PARAM_TICK_TIME - SNDRV_PCM_HW_PARAM_SAMPLE_BITS + 1]; unsigned int rmask; unsigned int cmask; unsigned int info; unsigned int msbits; unsigned int rate_num; unsigned int rate_den; snd_pcm_uframes_t fifo_size; unsigned char reserved[64]; }; #ifdef CONFIG_SND_SUPPORT_OLD_API #define SNDRV_PCM_IOCTL_HW_REFINE_OLD _IOWR('A', 0x10, struct snd_pcm_hw_params_old) #define SNDRV_PCM_IOCTL_HW_PARAMS_OLD _IOWR('A', 0x11, struct snd_pcm_hw_params_old) static int snd_pcm_hw_refine_old_user(struct snd_pcm_substream *substream, struct snd_pcm_hw_params_old __user * _oparams); static int snd_pcm_hw_params_old_user(struct snd_pcm_substream *substream, struct snd_pcm_hw_params_old __user * _oparams); #endif static int snd_pcm_open(struct file *file, struct snd_pcm *pcm, int stream); /* * */ static DECLARE_RWSEM(snd_pcm_link_rwsem); void snd_pcm_group_init(struct snd_pcm_group *group) { spin_lock_init(&group->lock); mutex_init(&group->mutex); INIT_LIST_HEAD(&group->substreams); refcount_set(&group->refs, 1); } /* define group lock helpers */ #define DEFINE_PCM_GROUP_LOCK(action, mutex_action) \ static void snd_pcm_group_ ## action(struct snd_pcm_group *group, bool nonatomic) \ { \ if (nonatomic) \ mutex_ ## mutex_action(&group->mutex); \ else \ spin_ ## action(&group->lock); \ } DEFINE_PCM_GROUP_LOCK(lock, lock); DEFINE_PCM_GROUP_LOCK(unlock, unlock); DEFINE_PCM_GROUP_LOCK(lock_irq, lock); DEFINE_PCM_GROUP_LOCK(unlock_irq, unlock); /** * snd_pcm_stream_lock - Lock the PCM stream * @substream: PCM substream * * This locks the PCM stream's spinlock or mutex depending on the nonatomic * flag of the given substream. This also takes the global link rw lock * (or rw sem), too, for avoiding the race with linked streams. */ void snd_pcm_stream_lock(struct snd_pcm_substream *substream) { snd_pcm_group_lock(&substream->self_group, substream->pcm->nonatomic); } EXPORT_SYMBOL_GPL(snd_pcm_stream_lock); /** * snd_pcm_stream_unlock - Unlock the PCM stream * @substream: PCM substream * * This unlocks the PCM stream that has been locked via snd_pcm_stream_lock(). */ void snd_pcm_stream_unlock(struct snd_pcm_substream *substream) { snd_pcm_group_unlock(&substream->self_group, substream->pcm->nonatomic); } EXPORT_SYMBOL_GPL(snd_pcm_stream_unlock); /** * snd_pcm_stream_lock_irq - Lock the PCM stream * @substream: PCM substream * * This locks the PCM stream like snd_pcm_stream_lock() and disables the local * IRQ (only when nonatomic is false). In nonatomic case, this is identical * as snd_pcm_stream_lock(). */ void snd_pcm_stream_lock_irq(struct snd_pcm_substream *substream) { snd_pcm_group_lock_irq(&substream->self_group, substream->pcm->nonatomic); } EXPORT_SYMBOL_GPL(snd_pcm_stream_lock_irq); static void snd_pcm_stream_lock_nested(struct snd_pcm_substream *substream) { struct snd_pcm_group *group = &substream->self_group; if (substream->pcm->nonatomic) mutex_lock_nested(&group->mutex, SINGLE_DEPTH_NESTING); else spin_lock_nested(&group->lock, SINGLE_DEPTH_NESTING); } /** * snd_pcm_stream_unlock_irq - Unlock the PCM stream * @substream: PCM substream * * This is a counter-part of snd_pcm_stream_lock_irq(). */ void snd_pcm_stream_unlock_irq(struct snd_pcm_substream *substream) { snd_pcm_group_unlock_irq(&substream->self_group, substream->pcm->nonatomic); } EXPORT_SYMBOL_GPL(snd_pcm_stream_unlock_irq); unsigned long _snd_pcm_stream_lock_irqsave(struct snd_pcm_substream *substream) { unsigned long flags = 0; if (substream->pcm->nonatomic) mutex_lock(&substream->self_group.mutex); else spin_lock_irqsave(&substream->self_group.lock, flags); return flags; } EXPORT_SYMBOL_GPL(_snd_pcm_stream_lock_irqsave); /** * snd_pcm_stream_unlock_irqrestore - Unlock the PCM stream * @substream: PCM substream * @flags: irq flags * * This is a counter-part of snd_pcm_stream_lock_irqsave(). */ void snd_pcm_stream_unlock_irqrestore(struct snd_pcm_substream *substream, unsigned long flags) { if (substream->pcm->nonatomic) mutex_unlock(&substream->self_group.mutex); else spin_unlock_irqrestore(&substream->self_group.lock, flags); } EXPORT_SYMBOL_GPL(snd_pcm_stream_unlock_irqrestore); /* Run PCM ioctl ops */ static int snd_pcm_ops_ioctl(struct snd_pcm_substream *substream, unsigned cmd, void *arg) { if (substream->ops->ioctl) return substream->ops->ioctl(substream, cmd, arg); else return snd_pcm_lib_ioctl(substream, cmd, arg); } int snd_pcm_info(struct snd_pcm_substream *substream, struct snd_pcm_info *info) { struct snd_pcm *pcm = substream->pcm; struct snd_pcm_str *pstr = substream->pstr; memset(info, 0, sizeof(*info)); info->card = pcm->card->number; info->device = pcm->device; info->stream = substream->stream; info->subdevice = substream->number; strscpy(info->id, pcm->id, sizeof(info->id)); strscpy(info->name, pcm->name, sizeof(info->name)); info->dev_class = pcm->dev_class; info->dev_subclass = pcm->dev_subclass; info->subdevices_count = pstr->substream_count; info->subdevices_avail = pstr->substream_count - pstr->substream_opened; strscpy(info->subname, substream->name, sizeof(info->subname)); return 0; } int snd_pcm_info_user(struct snd_pcm_substream *substream, struct snd_pcm_info __user * _info) { struct snd_pcm_info *info; int err; info = kmalloc(sizeof(*info), GFP_KERNEL); if (! info) return -ENOMEM; err = snd_pcm_info(substream, info); if (err >= 0) { if (copy_to_user(_info, info, sizeof(*info))) err = -EFAULT; } kfree(info); return err; } /* macro for simplified cast */ #define PARAM_MASK_BIT(b) (1U << (__force int)(b)) static bool hw_support_mmap(struct snd_pcm_substream *substream) { struct snd_dma_buffer *dmabuf; if (!(substream->runtime->hw.info & SNDRV_PCM_INFO_MMAP)) return false; if (substream->ops->mmap || substream->ops->page) return true; dmabuf = snd_pcm_get_dma_buf(substream); if (!dmabuf) dmabuf = &substream->dma_buffer; switch (dmabuf->dev.type) { case SNDRV_DMA_TYPE_UNKNOWN: /* we can't know the device, so just assume that the driver does * everything right */ return true; case SNDRV_DMA_TYPE_CONTINUOUS: case SNDRV_DMA_TYPE_VMALLOC: return true; default: return dma_can_mmap(dmabuf->dev.dev); } } static int constrain_mask_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params) { struct snd_pcm_hw_constraints *constrs = &substream->runtime->hw_constraints; struct snd_mask *m; unsigned int k; struct snd_mask old_mask; int changed; for (k = SNDRV_PCM_HW_PARAM_FIRST_MASK; k <= SNDRV_PCM_HW_PARAM_LAST_MASK; k++) { m = hw_param_mask(params, k); if (snd_mask_empty(m)) return -EINVAL; /* This parameter is not requested to change by a caller. */ if (!(params->rmask & PARAM_MASK_BIT(k))) continue; if (trace_hw_mask_param_enabled()) old_mask = *m; changed = snd_mask_refine(m, constrs_mask(constrs, k)); if (changed < 0) return changed; if (changed == 0) continue; /* Set corresponding flag so that the caller gets it. */ trace_hw_mask_param(substream, k, 0, &old_mask, m); params->cmask |= PARAM_MASK_BIT(k); } return 0; } static int constrain_interval_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params) { struct snd_pcm_hw_constraints *constrs = &substream->runtime->hw_constraints; struct snd_interval *i; unsigned int k; struct snd_interval old_interval; int changed; for (k = SNDRV_PCM_HW_PARAM_FIRST_INTERVAL; k <= SNDRV_PCM_HW_PARAM_LAST_INTERVAL; k++) { i = hw_param_interval(params, k); if (snd_interval_empty(i)) return -EINVAL; /* This parameter is not requested to change by a caller. */ if (!(params->rmask & PARAM_MASK_BIT(k))) continue; if (trace_hw_interval_param_enabled()) old_interval = *i; changed = snd_interval_refine(i, constrs_interval(constrs, k)); if (changed < 0) return changed; if (changed == 0) continue; /* Set corresponding flag so that the caller gets it. */ trace_hw_interval_param(substream, k, 0, &old_interval, i); params->cmask |= PARAM_MASK_BIT(k); } return 0; } static int constrain_params_by_rules(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params) { struct snd_pcm_hw_constraints *constrs = &substream->runtime->hw_constraints; unsigned int k; unsigned int *rstamps; unsigned int vstamps[SNDRV_PCM_HW_PARAM_LAST_INTERVAL + 1]; unsigned int stamp; struct snd_pcm_hw_rule *r; unsigned int d; struct snd_mask old_mask; struct snd_interval old_interval; bool again; int changed, err = 0; /* * Each application of rule has own sequence number. * * Each member of 'rstamps' array represents the sequence number of * recent application of corresponding rule. */ rstamps = kcalloc(constrs->rules_num, sizeof(unsigned int), GFP_KERNEL); if (!rstamps) return -ENOMEM; /* * Each member of 'vstamps' array represents the sequence number of * recent application of rule in which corresponding parameters were * changed. * * In initial state, elements corresponding to parameters requested by * a caller is 1. For unrequested parameters, corresponding members * have 0 so that the parameters are never changed anymore. */ for (k = 0; k <= SNDRV_PCM_HW_PARAM_LAST_INTERVAL; k++) vstamps[k] = (params->rmask & PARAM_MASK_BIT(k)) ? 1 : 0; /* Due to the above design, actual sequence number starts at 2. */ stamp = 2; retry: /* Apply all rules in order. */ again = false; for (k = 0; k < constrs->rules_num; k++) { r = &constrs->rules[k]; /* * Check condition bits of this rule. When the rule has * some condition bits, parameter without the bits is * never processed. SNDRV_PCM_HW_PARAMS_NO_PERIOD_WAKEUP * is an example of the condition bits. */ if (r->cond && !(r->cond & params->flags)) continue; /* * The 'deps' array includes maximum four dependencies * to SNDRV_PCM_HW_PARAM_XXXs for this rule. The fifth * member of this array is a sentinel and should be * negative value. * * This rule should be processed in this time when dependent * parameters were changed at former applications of the other * rules. */ for (d = 0; r->deps[d] >= 0; d++) { if (vstamps[r->deps[d]] > rstamps[k]) break; } if (r->deps[d] < 0) continue; if (trace_hw_mask_param_enabled()) { if (hw_is_mask(r->var)) old_mask = *hw_param_mask(params, r->var); } if (trace_hw_interval_param_enabled()) { if (hw_is_interval(r->var)) old_interval = *hw_param_interval(params, r->var); } changed = r->func(params, r); if (changed < 0) { err = changed; goto out; } /* * When the parameter is changed, notify it to the caller * by corresponding returned bit, then preparing for next * iteration. */ if (changed && r->var >= 0) { if (hw_is_mask(r->var)) { trace_hw_mask_param(substream, r->var, k + 1, &old_mask, hw_param_mask(params, r->var)); } if (hw_is_interval(r->var)) { trace_hw_interval_param(substream, r->var, k + 1, &old_interval, hw_param_interval(params, r->var)); } params->cmask |= PARAM_MASK_BIT(r->var); vstamps[r->var] = stamp; again = true; } rstamps[k] = stamp++; } /* Iterate to evaluate all rules till no parameters are changed. */ if (again) goto retry; out: kfree(rstamps); return err; } static int fixup_unreferenced_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params) { const struct snd_interval *i; const struct snd_mask *m; int err; if (!params->msbits) { i = hw_param_interval_c(params, SNDRV_PCM_HW_PARAM_SAMPLE_BITS); if (snd_interval_single(i)) params->msbits = snd_interval_value(i); } if (!params->rate_den) { i = hw_param_interval_c(params, SNDRV_PCM_HW_PARAM_RATE); if (snd_interval_single(i)) { params->rate_num = snd_interval_value(i); params->rate_den = 1; } } if (!params->fifo_size) { m = hw_param_mask_c(params, SNDRV_PCM_HW_PARAM_FORMAT); i = hw_param_interval_c(params, SNDRV_PCM_HW_PARAM_CHANNELS); if (snd_mask_single(m) && snd_interval_single(i)) { err = snd_pcm_ops_ioctl(substream, SNDRV_PCM_IOCTL1_FIFO_SIZE, params); if (err < 0) return err; } } if (!params->info) { params->info = substream->runtime->hw.info; params->info &= ~(SNDRV_PCM_INFO_FIFO_IN_FRAMES | SNDRV_PCM_INFO_DRAIN_TRIGGER); if (!hw_support_mmap(substream)) params->info &= ~(SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID); } return 0; } int snd_pcm_hw_refine(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params) { int err; params->info = 0; params->fifo_size = 0; if (params->rmask & PARAM_MASK_BIT(SNDRV_PCM_HW_PARAM_SAMPLE_BITS)) params->msbits = 0; if (params->rmask & PARAM_MASK_BIT(SNDRV_PCM_HW_PARAM_RATE)) { params->rate_num = 0; params->rate_den = 0; } err = constrain_mask_params(substream, params); if (err < 0) return err; err = constrain_interval_params(substream, params); if (err < 0) return err; err = constrain_params_by_rules(substream, params); if (err < 0) return err; params->rmask = 0; return 0; } EXPORT_SYMBOL(snd_pcm_hw_refine); static int snd_pcm_hw_refine_user(struct snd_pcm_substream *substream, struct snd_pcm_hw_params __user * _params) { struct snd_pcm_hw_params *params; int err; params = memdup_user(_params, sizeof(*params)); if (IS_ERR(params)) return PTR_ERR(params); err = snd_pcm_hw_refine(substream, params); if (err < 0) goto end; err = fixup_unreferenced_params(substream, params); if (err < 0) goto end; if (copy_to_user(_params, params, sizeof(*params))) err = -EFAULT; end: kfree(params); return err; } static int period_to_usecs(struct snd_pcm_runtime *runtime) { int usecs; if (! runtime->rate) return -1; /* invalid */ /* take 75% of period time as the deadline */ usecs = (750000 / runtime->rate) * runtime->period_size; usecs += ((750000 % runtime->rate) * runtime->period_size) / runtime->rate; return usecs; } static void snd_pcm_set_state(struct snd_pcm_substream *substream, snd_pcm_state_t state) { snd_pcm_stream_lock_irq(substream); if (substream->runtime->status->state != SNDRV_PCM_STATE_DISCONNECTED) substream->runtime->status->state = state; snd_pcm_stream_unlock_irq(substream); } static inline void snd_pcm_timer_notify(struct snd_pcm_substream *substream, int event) { #ifdef CONFIG_SND_PCM_TIMER if (substream->timer) snd_timer_notify(substream->timer, event, &substream->runtime->trigger_tstamp); #endif } void snd_pcm_sync_stop(struct snd_pcm_substream *substream, bool sync_irq) { if (substream->runtime && substream->runtime->stop_operating) { substream->runtime->stop_operating = false; if (substream->ops && substream->ops->sync_stop) substream->ops->sync_stop(substream); else if (sync_irq && substream->pcm->card->sync_irq > 0) synchronize_irq(substream->pcm->card->sync_irq); } } /** * snd_pcm_hw_params_choose - choose a configuration defined by @params * @pcm: PCM instance * @params: the hw_params instance * * Choose one configuration from configuration space defined by @params. * The configuration chosen is that obtained fixing in this order: * first access, first format, first subformat, min channels, * min rate, min period time, max buffer size, min tick time * * Return: Zero if successful, or a negative error code on failure. */ static int snd_pcm_hw_params_choose(struct snd_pcm_substream *pcm, struct snd_pcm_hw_params *params) { static const int vars[] = { SNDRV_PCM_HW_PARAM_ACCESS, SNDRV_PCM_HW_PARAM_FORMAT, SNDRV_PCM_HW_PARAM_SUBFORMAT, SNDRV_PCM_HW_PARAM_CHANNELS, SNDRV_PCM_HW_PARAM_RATE, SNDRV_PCM_HW_PARAM_PERIOD_TIME, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, SNDRV_PCM_HW_PARAM_TICK_TIME, -1 }; const int *v; struct snd_mask old_mask; struct snd_interval old_interval; int changed; for (v = vars; *v != -1; v++) { /* Keep old parameter to trace. */ if (trace_hw_mask_param_enabled()) { if (hw_is_mask(*v)) old_mask = *hw_param_mask(params, *v); } if (trace_hw_interval_param_enabled()) { if (hw_is_interval(*v)) old_interval = *hw_param_interval(params, *v); } if (*v != SNDRV_PCM_HW_PARAM_BUFFER_SIZE) changed = snd_pcm_hw_param_first(pcm, params, *v, NULL); else changed = snd_pcm_hw_param_last(pcm, params, *v, NULL); if (changed < 0) return changed; if (changed == 0) continue; /* Trace the changed parameter. */ if (hw_is_mask(*v)) { trace_hw_mask_param(pcm, *v, 0, &old_mask, hw_param_mask(params, *v)); } if (hw_is_interval(*v)) { trace_hw_interval_param(pcm, *v, 0, &old_interval, hw_param_interval(params, *v)); } } return 0; } static int snd_pcm_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params) { struct snd_pcm_runtime *runtime; int err, usecs; unsigned int bits; snd_pcm_uframes_t frames; if (PCM_RUNTIME_CHECK(substream)) return -ENXIO; runtime = substream->runtime; snd_pcm_stream_lock_irq(substream); switch (runtime->status->state) { case SNDRV_PCM_STATE_OPEN: case SNDRV_PCM_STATE_SETUP: case SNDRV_PCM_STATE_PREPARED: break; default: snd_pcm_stream_unlock_irq(substream); return -EBADFD; } snd_pcm_stream_unlock_irq(substream); #if IS_ENABLED(CONFIG_SND_PCM_OSS) if (!substream->oss.oss) #endif if (atomic_read(&substream->mmap_count)) return -EBADFD; snd_pcm_sync_stop(substream, true); params->rmask = ~0U; err = snd_pcm_hw_refine(substream, params); if (err < 0) goto _error; err = snd_pcm_hw_params_choose(substream, params); if (err < 0) goto _error; err = fixup_unreferenced_params(substream, params); if (err < 0) goto _error; if (substream->managed_buffer_alloc) { err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params)); if (err < 0) goto _error; runtime->buffer_changed = err > 0; } if (substream->ops->hw_params != NULL) { err = substream->ops->hw_params(substream, params); if (err < 0) goto _error; } runtime->access = params_access(params); runtime->format = params_format(params); runtime->subformat = params_subformat(params); runtime->channels = params_channels(params); runtime->rate = params_rate(params); runtime->period_size = params_period_size(params); runtime->periods = params_periods(params); runtime->buffer_size = params_buffer_size(params); runtime->info = params->info; runtime->rate_num = params->rate_num; runtime->rate_den = params->rate_den; runtime->no_period_wakeup = (params->info & SNDRV_PCM_INFO_NO_PERIOD_WAKEUP) && (params->flags & SNDRV_PCM_HW_PARAMS_NO_PERIOD_WAKEUP); bits = snd_pcm_format_physical_width(runtime->format); runtime->sample_bits = bits; bits *= runtime->channels; runtime->frame_bits = bits; frames = 1; while (bits % 8 != 0) { bits *= 2; frames *= 2; } runtime->byte_align = bits / 8; runtime->min_align = frames; /* Default sw params */ runtime->tstamp_mode = SNDRV_PCM_TSTAMP_NONE; runtime->period_step = 1; runtime->control->avail_min = runtime->period_size; runtime->start_threshold = 1; runtime->stop_threshold = runtime->buffer_size; runtime->silence_threshold = 0; runtime->silence_size = 0; runtime->boundary = runtime->buffer_size; while (runtime->boundary * 2 <= LONG_MAX - runtime->buffer_size) runtime->boundary *= 2; /* clear the buffer for avoiding possible kernel info leaks */ if (runtime->dma_area && !substream->ops->copy_user) { size_t size = runtime->dma_bytes; if (runtime->info & SNDRV_PCM_INFO_MMAP) size = PAGE_ALIGN(size); memset(runtime->dma_area, 0, size); } snd_pcm_timer_resolution_change(substream); snd_pcm_set_state(substream, SNDRV_PCM_STATE_SETUP); if (cpu_latency_qos_request_active(&substream->latency_pm_qos_req)) cpu_latency_qos_remove_request(&substream->latency_pm_qos_req); usecs = period_to_usecs(runtime); if (usecs >= 0) cpu_latency_qos_add_request(&substream->latency_pm_qos_req, usecs); return 0; _error: /* hardware might be unusable from this time, so we force application to retry to set the correct hardware parameter settings */ snd_pcm_set_state(substream, SNDRV_PCM_STATE_OPEN); if (substream->ops->hw_free != NULL) substream->ops->hw_free(substream); if (substream->managed_buffer_alloc) snd_pcm_lib_free_pages(substream); return err; } static int snd_pcm_hw_params_user(struct snd_pcm_substream *substream, struct snd_pcm_hw_params __user * _params) { struct snd_pcm_hw_params *params; int err; params = memdup_user(_params, sizeof(*params)); if (IS_ERR(params)) return PTR_ERR(params); err = snd_pcm_hw_params(substream, params); if (err < 0) goto end; if (copy_to_user(_params, params, sizeof(*params))) err = -EFAULT; end: kfree(params); return err; } static int do_hw_free(struct snd_pcm_substream *substream) { int result = 0; snd_pcm_sync_stop(substream, true); if (substream->ops->hw_free) result = substream->ops->hw_free(substream); if (substream->managed_buffer_alloc) snd_pcm_lib_free_pages(substream); return result; } static int snd_pcm_hw_free(struct snd_pcm_substream *substream) { struct snd_pcm_runtime *runtime; int result; if (PCM_RUNTIME_CHECK(substream)) return -ENXIO; runtime = substream->runtime; snd_pcm_stream_lock_irq(substream); switch (runtime->status->state) { case SNDRV_PCM_STATE_SETUP: case SNDRV_PCM_STATE_PREPARED: break; default: snd_pcm_stream_unlock_irq(substream); return -EBADFD; } snd_pcm_stream_unlock_irq(substream); if (atomic_read(&substream->mmap_count)) return -EBADFD; result = do_hw_free(substream); snd_pcm_set_state(substream, SNDRV_PCM_STATE_OPEN); cpu_latency_qos_remove_request(&substream->latency_pm_qos_req); return result; } static int snd_pcm_sw_params(struct snd_pcm_substream *substream, struct snd_pcm_sw_params *params) { struct snd_pcm_runtime *runtime; int err; if (PCM_RUNTIME_CHECK(substream)) return -ENXIO; runtime = substream->runtime; snd_pcm_stream_lock_irq(substream); if (runtime->status->state == SNDRV_PCM_STATE_OPEN) { snd_pcm_stream_unlock_irq(substream); return -EBADFD; } snd_pcm_stream_unlock_irq(substream); if (params->tstamp_mode < 0 || params->tstamp_mode > SNDRV_PCM_TSTAMP_LAST) return -EINVAL; if (params->proto >= SNDRV_PROTOCOL_VERSION(2, 0, 12) && params->tstamp_type > SNDRV_PCM_TSTAMP_TYPE_LAST) return -EINVAL; if (params->avail_min == 0) return -EINVAL; if (params->silence_size >= runtime->boundary) { if (params->silence_threshold != 0) return -EINVAL; } else { if (params->silence_size > params->silence_threshold) return -EINVAL; if (params->silence_threshold > runtime->buffer_size) return -EINVAL; } err = 0; snd_pcm_stream_lock_irq(substream); runtime->tstamp_mode = params->tstamp_mode; if (params->proto >= SNDRV_PROTOCOL_VERSION(2, 0, 12)) runtime->tstamp_type = params->tstamp_type; runtime->period_step = params->period_step; runtime->control->avail_min = params->avail_min; runtime->start_threshold = params->start_threshold; runtime->stop_threshold = params->stop_threshold; runtime->silence_threshold = params->silence_threshold; runtime->silence_size = params->silence_size; params->boundary = runtime->boundary; if (snd_pcm_running(substream)) { if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK && runtime->silence_size > 0) snd_pcm_playback_silence(substream, ULONG_MAX); err = snd_pcm_update_state(substream, runtime); } snd_pcm_stream_unlock_irq(substream); return err; } static int snd_pcm_sw_params_user(struct snd_pcm_substream *substream, struct snd_pcm_sw_params __user * _params) { struct snd_pcm_sw_params params; int err; if (copy_from_user(&params, _params, sizeof(params))) return -EFAULT; err = snd_pcm_sw_params(substream, &params); if (copy_to_user(_params, &params, sizeof(params))) return -EFAULT; return err; } static inline snd_pcm_uframes_t snd_pcm_calc_delay(struct snd_pcm_substream *substream) { snd_pcm_uframes_t delay; if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) delay = snd_pcm_playback_hw_avail(substream->runtime); else delay = snd_pcm_capture_avail(substream->runtime); return delay + substream->runtime->delay; } int snd_pcm_status64(struct snd_pcm_substream *substream, struct snd_pcm_status64 *status) { struct snd_pcm_runtime *runtime = substream->runtime; snd_pcm_stream_lock_irq(substream); snd_pcm_unpack_audio_tstamp_config(status->audio_tstamp_data, &runtime->audio_tstamp_config); /* backwards compatible behavior */ if (runtime->audio_tstamp_config.type_requested == SNDRV_PCM_AUDIO_TSTAMP_TYPE_COMPAT) { if (runtime->hw.info & SNDRV_PCM_INFO_HAS_WALL_CLOCK) runtime->audio_tstamp_config.type_requested = SNDRV_PCM_AUDIO_TSTAMP_TYPE_LINK; else runtime->audio_tstamp_config.type_requested = SNDRV_PCM_AUDIO_TSTAMP_TYPE_DEFAULT; runtime->audio_tstamp_report.valid = 0; } else runtime->audio_tstamp_report.valid = 1; status->state = runtime->status->state; status->suspended_state = runtime->status->suspended_state; if (status->state == SNDRV_PCM_STATE_OPEN) goto _end; status->trigger_tstamp_sec = runtime->trigger_tstamp.tv_sec; status->trigger_tstamp_nsec = runtime->trigger_tstamp.tv_nsec; if (snd_pcm_running(substream)) { snd_pcm_update_hw_ptr(substream); if (runtime->tstamp_mode == SNDRV_PCM_TSTAMP_ENABLE) { status->tstamp_sec = runtime->status->tstamp.tv_sec; status->tstamp_nsec = runtime->status->tstamp.tv_nsec; status->driver_tstamp_sec = runtime->driver_tstamp.tv_sec; status->driver_tstamp_nsec = runtime->driver_tstamp.tv_nsec; status->audio_tstamp_sec = runtime->status->audio_tstamp.tv_sec; status->audio_tstamp_nsec = runtime->status->audio_tstamp.tv_nsec; if (runtime->audio_tstamp_report.valid == 1) /* backwards compatibility, no report provided in COMPAT mode */ snd_pcm_pack_audio_tstamp_report(&status->audio_tstamp_data, &status->audio_tstamp_accuracy, &runtime->audio_tstamp_report); goto _tstamp_end; } } else { /* get tstamp only in fallback mode and only if enabled */ if (runtime->tstamp_mode == SNDRV_PCM_TSTAMP_ENABLE) { struct timespec64 tstamp; snd_pcm_gettime(runtime, &tstamp); status->tstamp_sec = tstamp.tv_sec; status->tstamp_nsec = tstamp.tv_nsec; } } _tstamp_end: status->appl_ptr = runtime->control->appl_ptr; status->hw_ptr = runtime->status->hw_ptr; status->avail = snd_pcm_avail(substream); status->delay = snd_pcm_running(substream) ? snd_pcm_calc_delay(substream) : 0; status->avail_max = runtime->avail_max; status->overrange = runtime->overrange; runtime->avail_max = 0; runtime->overrange = 0; _end: snd_pcm_stream_unlock_irq(substream); return 0; } static int snd_pcm_status_user64(struct snd_pcm_substream *substream, struct snd_pcm_status64 __user * _status, bool ext) { struct snd_pcm_status64 status; int res; memset(&status, 0, sizeof(status)); /* * with extension, parameters are read/write, * get audio_tstamp_data from user, * ignore rest of status structure */ if (ext && get_user(status.audio_tstamp_data, (u32 __user *)(&_status->audio_tstamp_data))) return -EFAULT; res = snd_pcm_status64(substream, &status); if (res < 0) return res; if (copy_to_user(_status, &status, sizeof(status))) return -EFAULT; return 0; } static int snd_pcm_status_user32(struct snd_pcm_substream *substream, struct snd_pcm_status32 __user * _status, bool ext) { struct snd_pcm_status64 status64; struct snd_pcm_status32 status32; int res; memset(&status64, 0, sizeof(status64)); memset(&status32, 0, sizeof(status32)); /* * with extension, parameters are read/write, * get audio_tstamp_data from user, * ignore rest of status structure */ if (ext && get_user(status64.audio_tstamp_data, (u32 __user *)(&_status->audio_tstamp_data))) return -EFAULT; res = snd_pcm_status64(substream, &status64); if (res < 0) return res; status32 = (struct snd_pcm_status32) { .state = status64.state, .trigger_tstamp_sec = status64.trigger_tstamp_sec, .trigger_tstamp_nsec = status64.trigger_tstamp_nsec, .tstamp_sec = status64.tstamp_sec, .tstamp_nsec = status64.tstamp_nsec, .appl_ptr = status64.appl_ptr, .hw_ptr = status64.hw_ptr, .delay = status64.delay, .avail = status64.avail, .avail_max = status64.avail_max, .overrange = status64.overrange, .suspended_state = status64.suspended_state, .audio_tstamp_data = status64.audio_tstamp_data, .audio_tstamp_sec = status64.audio_tstamp_sec, .audio_tstamp_nsec = status64.audio_tstamp_nsec, .driver_tstamp_sec = status64.audio_tstamp_sec, .driver_tstamp_nsec = status64.audio_tstamp_nsec, .audio_tstamp_accuracy = status64.audio_tstamp_accuracy, }; if (copy_to_user(_status, &status32, sizeof(status32))) return -EFAULT; return 0; } static int snd_pcm_channel_info(struct snd_pcm_substream *substream, struct snd_pcm_channel_info * info) { struct snd_pcm_runtime *runtime; unsigned int channel; channel = info->channel; runtime = substream->runtime; snd_pcm_stream_lock_irq(substream); if (runtime->status->state == SNDRV_PCM_STATE_OPEN) { snd_pcm_stream_unlock_irq(substream); return -EBADFD; } snd_pcm_stream_unlock_irq(substream); if (channel >= runtime->channels) return -EINVAL; memset(info, 0, sizeof(*info)); info->channel = channel; return snd_pcm_ops_ioctl(substream, SNDRV_PCM_IOCTL1_CHANNEL_INFO, info); } static int snd_pcm_channel_info_user(struct snd_pcm_substream *substream, struct snd_pcm_channel_info __user * _info) { struct snd_pcm_channel_info info; int res; if (copy_from_user(&info, _info, sizeof(info))) return -EFAULT; res = snd_pcm_channel_info(substream, &info); if (res < 0) return res; if (copy_to_user(_info, &info, sizeof(info))) return -EFAULT; return 0; } static void snd_pcm_trigger_tstamp(struct snd_pcm_substream *substream) { struct snd_pcm_runtime *runtime = substream->runtime; if (runtime->trigger_master == NULL) return; if (runtime->trigger_master == substream) { if (!runtime->trigger_tstamp_latched) snd_pcm_gettime(runtime, &runtime->trigger_tstamp); } else { snd_pcm_trigger_tstamp(runtime->trigger_master); runtime->trigger_tstamp = runtime->trigger_master->runtime->trigger_tstamp; } runtime->trigger_master = NULL; } #define ACTION_ARG_IGNORE (__force snd_pcm_state_t)0 struct action_ops { int (*pre_action)(struct snd_pcm_substream *substream, snd_pcm_state_t state); int (*do_action)(struct snd_pcm_substream *substream, snd_pcm_state_t state); void (*undo_action)(struct snd_pcm_substream *substream, snd_pcm_state_t state); void (*post_action)(struct snd_pcm_substream *substream, snd_pcm_state_t state); }; /* * this functions is core for handling of linked stream * Note: the stream state might be changed also on failure * Note2: call with calling stream lock + link lock */ static int snd_pcm_action_group(const struct action_ops *ops, struct snd_pcm_substream *substream, snd_pcm_state_t state, bool do_lock) { struct snd_pcm_substream *s = NULL; struct snd_pcm_substream *s1; int res = 0, depth = 1; snd_pcm_group_for_each_entry(s, substream) { if (do_lock && s != substream) { if (s->pcm->nonatomic) mutex_lock_nested(&s->self_group.mutex, depth); else spin_lock_nested(&s->self_group.lock, depth); depth++; } res = ops->pre_action(s, state); if (res < 0) goto _unlock; } snd_pcm_group_for_each_entry(s, substream) { res = ops->do_action(s, state); if (res < 0) { if (ops->undo_action) { snd_pcm_group_for_each_entry(s1, substream) { if (s1 == s) /* failed stream */ break; ops->undo_action(s1, state); } } s = NULL; /* unlock all */ goto _unlock; } } snd_pcm_group_for_each_entry(s, substream) { ops->post_action(s, state); } _unlock: if (do_lock) { /* unlock streams */ snd_pcm_group_for_each_entry(s1, substream) { if (s1 != substream) { if (s1->pcm->nonatomic) mutex_unlock(&s1->self_group.mutex); else spin_unlock(&s1->self_group.lock); } if (s1 == s) /* end */ break; } } return res; } /* * Note: call with stream lock */ static int snd_pcm_action_single(const struct action_ops *ops, struct snd_pcm_substream *substream, snd_pcm_state_t state) { int res; res = ops->pre_action(substream, state); if (res < 0) return res; res = ops->do_action(substream, state); if (res == 0) ops->post_action(substream, state); else if (ops->undo_action) ops->undo_action(substream, state); return res; } static void snd_pcm_group_assign(struct snd_pcm_substream *substream, struct snd_pcm_group *new_group) { substream->group = new_group; list_move(&substream->link_list, &new_group->substreams); } /* * Unref and unlock the group, but keep the stream lock; * when the group becomes empty and no longer referred, destroy itself */ static void snd_pcm_group_unref(struct snd_pcm_group *group, struct snd_pcm_substream *substream) { bool do_free; if (!group) return; do_free = refcount_dec_and_test(&group->refs); snd_pcm_group_unlock(group, substream->pcm->nonatomic); if (do_free) kfree(group); } /* * Lock the group inside a stream lock and reference it; * return the locked group object, or NULL if not linked */ static struct snd_pcm_group * snd_pcm_stream_group_ref(struct snd_pcm_substream *substream) { bool nonatomic = substream->pcm->nonatomic; struct snd_pcm_group *group; bool trylock; for (;;) { if (!snd_pcm_stream_linked(substream)) return NULL; group = substream->group; /* block freeing the group object */ refcount_inc(&group->refs); trylock = nonatomic ? mutex_trylock(&group->mutex) : spin_trylock(&group->lock); if (trylock) break; /* OK */ /* re-lock for avoiding ABBA deadlock */ snd_pcm_stream_unlock(substream); snd_pcm_group_lock(group, nonatomic); snd_pcm_stream_lock(substream); /* check the group again; the above opens a small race window */ if (substream->group == group) break; /* OK */ /* group changed, try again */ snd_pcm_group_unref(group, substream); } return group; } /* * Note: call with stream lock */ static int snd_pcm_action(const struct action_ops *ops, struct snd_pcm_substream *substream, snd_pcm_state_t state) { struct snd_pcm_group *group; int res; group = snd_pcm_stream_group_ref(substream); if (group) res = snd_pcm_action_group(ops, substream, state, true); else res = snd_pcm_action_single(ops, substream, state); snd_pcm_group_unref(group, substream); return res; } /* * Note: don't use any locks before */ static int snd_pcm_action_lock_irq(const struct action_ops *ops, struct snd_pcm_substream *substream, snd_pcm_state_t state) { int res; snd_pcm_stream_lock_irq(substream); res = snd_pcm_action(ops, substream, state); snd_pcm_stream_unlock_irq(substream); return res; } /* */ static int snd_pcm_action_nonatomic(const struct action_ops *ops, struct snd_pcm_substream *substream, snd_pcm_state_t state) { int res; /* Guarantee the group members won't change during non-atomic action */ down_read(&snd_pcm_link_rwsem); if (snd_pcm_stream_linked(substream)) res = snd_pcm_action_group(ops, substream, state, false); else res = snd_pcm_action_single(ops, substream, state); up_read(&snd_pcm_link_rwsem); return res; } /* * start callbacks */ static int snd_pcm_pre_start(struct snd_pcm_substream *substream, snd_pcm_state_t state) { struct snd_pcm_runtime *runtime = substream->runtime; if (runtime->status->state != SNDRV_PCM_STATE_PREPARED) return -EBADFD; if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK && !snd_pcm_playback_data(substream)) return -EPIPE; runtime->trigger_tstamp_latched = false; runtime->trigger_master = substream; return 0; } static int snd_pcm_do_start(struct snd_pcm_substream *substream, snd_pcm_state_t state) { if (substream->runtime->trigger_master != substream) return 0; return substream->ops->trigger(substream, SNDRV_PCM_TRIGGER_START); } static void snd_pcm_undo_start(struct snd_pcm_substream *substream, snd_pcm_state_t state) { if (substream->runtime->trigger_master == substream) substream->ops->trigger(substream, SNDRV_PCM_TRIGGER_STOP); } static void snd_pcm_post_start(struct snd_pcm_substream *substream, snd_pcm_state_t state) { struct snd_pcm_runtime *runtime = substream->runtime; snd_pcm_trigger_tstamp(substream); runtime->hw_ptr_jiffies = jiffies; runtime->hw_ptr_buffer_jiffies = (runtime->buffer_size * HZ) / runtime->rate; runtime->status->state = state; if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK && runtime->silence_size > 0) snd_pcm_playback_silence(substream, ULONG_MAX); snd_pcm_timer_notify(substream, SNDRV_TIMER_EVENT_MSTART); } static const struct action_ops snd_pcm_action_start = { .pre_action = snd_pcm_pre_start, .do_action = snd_pcm_do_start, .undo_action = snd_pcm_undo_start, .post_action = snd_pcm_post_start }; /** * snd_pcm_start - start all linked streams * @substream: the PCM substream instance * * Return: Zero if successful, or a negative error code. * The stream lock must be acquired before calling this function. */ int snd_pcm_start(struct snd_pcm_substream *substream) { return snd_pcm_action(&snd_pcm_action_start, substream, SNDRV_PCM_STATE_RUNNING); } /* take the stream lock and start the streams */ static int snd_pcm_start_lock_irq(struct snd_pcm_substream *substream) { return snd_pcm_action_lock_irq(&snd_pcm_action_start, substream, SNDRV_PCM_STATE_RUNNING); } /* * stop callbacks */ static int snd_pcm_pre_stop(struct snd_pcm_substream *substream, snd_pcm_state_t state) { struct snd_pcm_runtime *runtime = substream->runtime; if (runtime->status->state == SNDRV_PCM_STATE_OPEN) return -EBADFD; runtime->trigger_master = substream; return 0; } static int snd_pcm_do_stop(struct snd_pcm_substream *substream, snd_pcm_state_t state) { if (substream->runtime->trigger_master == substream && snd_pcm_running(substream)) { substream->ops->trigger(substream, SNDRV_PCM_TRIGGER_STOP); substream->runtime->stop_operating = true; } return 0; /* unconditionally stop all substreams */ } static void snd_pcm_post_stop(struct snd_pcm_substream *substream, snd_pcm_state_t state) { struct snd_pcm_runtime *runtime = substream->runtime; if (runtime->status->state != state) { snd_pcm_trigger_tstamp(substream); runtime->status->state = state; snd_pcm_timer_notify(substream, SNDRV_TIMER_EVENT_MSTOP); } wake_up(&runtime->sleep); wake_up(&runtime->tsleep); } static const struct action_ops snd_pcm_action_stop = { .pre_action = snd_pcm_pre_stop, .do_action = snd_pcm_do_stop, .post_action = snd_pcm_post_stop }; /** * snd_pcm_stop - try to stop all running streams in the substream group * @substream: the PCM substream instance * @state: PCM state after stopping the stream * * The state of each stream is then changed to the given state unconditionally. * * Return: Zero if successful, or a negative error code. */ int snd_pcm_stop(struct snd_pcm_substream *substream, snd_pcm_state_t state) { return snd_pcm_action(&snd_pcm_action_stop, substream, state); } EXPORT_SYMBOL(snd_pcm_stop); /** * snd_pcm_drain_done - stop the DMA only when the given stream is playback * @substream: the PCM substream * * After stopping, the state is changed to SETUP. * Unlike snd_pcm_stop(), this affects only the given stream. * * Return: Zero if successful, or a negative error code. */ int snd_pcm_drain_done(struct snd_pcm_substream *substream) { return snd_pcm_action_single(&snd_pcm_action_stop, substream, SNDRV_PCM_STATE_SETUP); } /** * snd_pcm_stop_xrun - stop the running streams as XRUN * @substream: the PCM substream instance * * This stops the given running substream (and all linked substreams) as XRUN. * Unlike snd_pcm_stop(), this function takes the substream lock by itself. * * Return: Zero if successful, or a negative error code. */ int snd_pcm_stop_xrun(struct snd_pcm_substream *substream) { unsigned long flags; snd_pcm_stream_lock_irqsave(substream, flags); if (substream->runtime && snd_pcm_running(substream)) __snd_pcm_xrun(substream); snd_pcm_stream_unlock_irqrestore(substream, flags); return 0; } EXPORT_SYMBOL_GPL(snd_pcm_stop_xrun); /* * pause callbacks: pass boolean (to start pause or resume) as state argument */ #define pause_pushed(state) (__force bool)(state) static int snd_pcm_pre_pause(struct snd_pcm_substream *substream, snd_pcm_state_t state) { struct snd_pcm_runtime *runtime = substream->runtime; if (!(runtime->info & SNDRV_PCM_INFO_PAUSE)) return -ENOSYS; if (pause_pushed(state)) { if (runtime->status->state != SNDRV_PCM_STATE_RUNNING) return -EBADFD; } else if (runtime->status->state != SNDRV_PCM_STATE_PAUSED) return -EBADFD; runtime->trigger_master = substream; return 0; } static int snd_pcm_do_pause(struct snd_pcm_substream *substream, snd_pcm_state_t state) { if (substream->runtime->trigger_master != substream) return 0; /* some drivers might use hw_ptr to recover from the pause - update the hw_ptr now */ if (pause_pushed(state)) snd_pcm_update_hw_ptr(substream); /* The jiffies check in snd_pcm_update_hw_ptr*() is done by * a delta between the current jiffies, this gives a large enough * delta, effectively to skip the check once. */ substream->runtime->hw_ptr_jiffies = jiffies - HZ * 1000; return substream->ops->trigger(substream, pause_pushed(state) ? SNDRV_PCM_TRIGGER_PAUSE_PUSH : SNDRV_PCM_TRIGGER_PAUSE_RELEASE); } static void snd_pcm_undo_pause(struct snd_pcm_substream *substream, snd_pcm_state_t state) { if (substream->runtime->trigger_master == substream) substream->ops->trigger(substream, pause_pushed(state) ? SNDRV_PCM_TRIGGER_PAUSE_RELEASE : SNDRV_PCM_TRIGGER_PAUSE_PUSH); } static void snd_pcm_post_pause(struct snd_pcm_substream *substream, snd_pcm_state_t state) { struct snd_pcm_runtime *runtime = substream->runtime; snd_pcm_trigger_tstamp(substream); if (pause_pushed(state)) { runtime->status->state = SNDRV_PCM_STATE_PAUSED; snd_pcm_timer_notify(substream, SNDRV_TIMER_EVENT_MPAUSE); wake_up(&runtime->sleep); wake_up(&runtime->tsleep); } else { runtime->status->state = SNDRV_PCM_STATE_RUNNING; snd_pcm_timer_notify(substream, SNDRV_TIMER_EVENT_MCONTINUE); } } static const struct action_ops snd_pcm_action_pause = { .pre_action = snd_pcm_pre_pause, .do_action = snd_pcm_do_pause, .undo_action = snd_pcm_undo_pause, .post_action = snd_pcm_post_pause }; /* * Push/release the pause for all linked streams. */ static int snd_pcm_pause(struct snd_pcm_substream *substream, bool push) { return snd_pcm_action(&snd_pcm_action_pause, substream, (__force snd_pcm_state_t)push); } static int snd_pcm_pause_lock_irq(struct snd_pcm_substream *substream, bool push) { return snd_pcm_action_lock_irq(&snd_pcm_action_pause, substream, (__force snd_pcm_state_t)push); } #ifdef CONFIG_PM /* suspend callback: state argument ignored */ static int snd_pcm_pre_suspend(struct snd_pcm_substream *substream, snd_pcm_state_t state) { struct snd_pcm_runtime *runtime = substream->runtime; switch (runtime->status->state) { case SNDRV_PCM_STATE_SUSPENDED: return -EBUSY; /* unresumable PCM state; return -EBUSY for skipping suspend */ case SNDRV_PCM_STATE_OPEN: case SNDRV_PCM_STATE_SETUP: case SNDRV_PCM_STATE_DISCONNECTED: return -EBUSY; } runtime->trigger_master = substream; return 0; } static int snd_pcm_do_suspend(struct snd_pcm_substream *substream, snd_pcm_state_t state) { struct snd_pcm_runtime *runtime = substream->runtime; if (runtime->trigger_master != substream) return 0; if (! snd_pcm_running(substream)) return 0; substream->ops->trigger(substream, SNDRV_PCM_TRIGGER_SUSPEND); runtime->stop_operating = true; return 0; /* suspend unconditionally */ } static void snd_pcm_post_suspend(struct snd_pcm_substream *substream, snd_pcm_state_t state) { struct snd_pcm_runtime *runtime = substream->runtime; snd_pcm_trigger_tstamp(substream); runtime->status->suspended_state = runtime->status->state; runtime->status->state = SNDRV_PCM_STATE_SUSPENDED; snd_pcm_timer_notify(substream, SNDRV_TIMER_EVENT_MSUSPEND); wake_up(&runtime->sleep); wake_up(&runtime->tsleep); } static const struct action_ops snd_pcm_action_suspend = { .pre_action = snd_pcm_pre_suspend, .do_action = snd_pcm_do_suspend, .post_action = snd_pcm_post_suspend }; /* * snd_pcm_suspend - trigger SUSPEND to all linked streams * @substream: the PCM substream * * After this call, all streams are changed to SUSPENDED state. * * Return: Zero if successful, or a negative error code. */ static int snd_pcm_suspend(struct snd_pcm_substream *substream) { int err; unsigned long flags; snd_pcm_stream_lock_irqsave(substream, flags); err = snd_pcm_action(&snd_pcm_action_suspend, substream, ACTION_ARG_IGNORE); snd_pcm_stream_unlock_irqrestore(substream, flags); return err; } /** * snd_pcm_suspend_all - trigger SUSPEND to all substreams in the given pcm * @pcm: the PCM instance * * After this call, all streams are changed to SUSPENDED state. * * Return: Zero if successful (or @pcm is %NULL), or a negative error code. */ int snd_pcm_suspend_all(struct snd_pcm *pcm) { struct snd_pcm_substream *substream; int stream, err = 0; if (! pcm) return 0; for_each_pcm_substream(pcm, stream, substream) { /* FIXME: the open/close code should lock this as well */ if (!substream->runtime) continue; /* * Skip BE dai link PCM's that are internal and may * not have their substream ops set. */ if (!substream->ops) continue; err = snd_pcm_suspend(substream); if (err < 0 && err != -EBUSY) return err; } for_each_pcm_substream(pcm, stream, substream) snd_pcm_sync_stop(substream, false); return 0; } EXPORT_SYMBOL(snd_pcm_suspend_all); /* resume callbacks: state argument ignored */ static int snd_pcm_pre_resume(struct snd_pcm_substream *substream, snd_pcm_state_t state) { struct snd_pcm_runtime *runtime = substream->runtime; if (!(runtime->info & SNDRV_PCM_INFO_RESUME)) return -ENOSYS; runtime->trigger_master = substream; return 0; } static int snd_pcm_do_resume(struct snd_pcm_substream *substream, snd_pcm_state_t state) { struct snd_pcm_runtime *runtime = substream->runtime; if (runtime->trigger_master != substream) return 0; /* DMA not running previously? */ if (runtime->status->suspended_state != SNDRV_PCM_STATE_RUNNING && (runtime->status->suspended_state != SNDRV_PCM_STATE_DRAINING || substream->stream != SNDRV_PCM_STREAM_PLAYBACK)) return 0; return substream->ops->trigger(substream, SNDRV_PCM_TRIGGER_RESUME); } static void snd_pcm_undo_resume(struct snd_pcm_substream *substream, snd_pcm_state_t state) { if (substream->runtime->trigger_master == substream && snd_pcm_running(substream)) substream->ops->trigger(substream, SNDRV_PCM_TRIGGER_SUSPEND); } static void snd_pcm_post_resume(struct snd_pcm_substream *substream, snd_pcm_state_t state) { struct snd_pcm_runtime *runtime = substream->runtime; snd_pcm_trigger_tstamp(substream); runtime->status->state = runtime->status->suspended_state; snd_pcm_timer_notify(substream, SNDRV_TIMER_EVENT_MRESUME); } static const struct action_ops snd_pcm_action_resume = { .pre_action = snd_pcm_pre_resume, .do_action = snd_pcm_do_resume, .undo_action = snd_pcm_undo_resume, .post_action = snd_pcm_post_resume }; static int snd_pcm_resume(struct snd_pcm_substream *substream) { return snd_pcm_action_lock_irq(&snd_pcm_action_resume, substream, ACTION_ARG_IGNORE); } #else static int snd_pcm_resume(struct snd_pcm_substream *substream) { return -ENOSYS; } #endif /* CONFIG_PM */ /* * xrun ioctl * * Change the RUNNING stream(s) to XRUN state. */ static int snd_pcm_xrun(struct snd_pcm_substream *substream) { struct snd_pcm_runtime *runtime = substream->runtime; int result; snd_pcm_stream_lock_irq(substream); switch (runtime->status->state) { case SNDRV_PCM_STATE_XRUN: result = 0; /* already there */ break; case SNDRV_PCM_STATE_RUNNING: __snd_pcm_xrun(substream); result = 0; break; default: result = -EBADFD; } snd_pcm_stream_unlock_irq(substream); return result; } /* * reset ioctl */ /* reset callbacks: state argument ignored */ static int snd_pcm_pre_reset(struct snd_pcm_substream *substream, snd_pcm_state_t state) { struct snd_pcm_runtime *runtime = substream->runtime; switch (runtime->status->state) { case SNDRV_PCM_STATE_RUNNING: case SNDRV_PCM_STATE_PREPARED: case SNDRV_PCM_STATE_PAUSED: case SNDRV_PCM_STATE_SUSPENDED: return 0; default: return -EBADFD; } } static int snd_pcm_do_reset(struct snd_pcm_substream *substream, snd_pcm_state_t state) { struct snd_pcm_runtime *runtime = substream->runtime; int err = snd_pcm_ops_ioctl(substream, SNDRV_PCM_IOCTL1_RESET, NULL); if (err < 0) return err; runtime->hw_ptr_base = 0; runtime->hw_ptr_interrupt = runtime->status->hw_ptr - runtime->status->hw_ptr % runtime->period_size; runtime->silence_start = runtime->status->hw_ptr; runtime->silence_filled = 0; return 0; } static void snd_pcm_post_reset(struct snd_pcm_substream *substream, snd_pcm_state_t state) { struct snd_pcm_runtime *runtime = substream->runtime; runtime->control->appl_ptr = runtime->status->hw_ptr; if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK && runtime->silence_size > 0) snd_pcm_playback_silence(substream, ULONG_MAX); } static const struct action_ops snd_pcm_action_reset = { .pre_action = snd_pcm_pre_reset, .do_action = snd_pcm_do_reset, .post_action = snd_pcm_post_reset }; static int snd_pcm_reset(struct snd_pcm_substream *substream) { return snd_pcm_action_nonatomic(&snd_pcm_action_reset, substream, ACTION_ARG_IGNORE); } /* * prepare ioctl */ /* pass f_flags as state argument */ static int snd_pcm_pre_prepare(struct snd_pcm_substream *substream, snd_pcm_state_t state) { struct snd_pcm_runtime *runtime = substream->runtime; int f_flags = (__force int)state; if (runtime->status->state == SNDRV_PCM_STATE_OPEN || runtime->status->state == SNDRV_PCM_STATE_DISCONNECTED) return -EBADFD; if (snd_pcm_running(substream)) return -EBUSY; substream->f_flags = f_flags; return 0; } static int snd_pcm_do_prepare(struct snd_pcm_substream *substream, snd_pcm_state_t state) { int err; snd_pcm_sync_stop(substream, true); err = substream->ops->prepare(substream); if (err < 0) return err; return snd_pcm_do_reset(substream, state); } static void snd_pcm_post_prepare(struct snd_pcm_substream *substream, snd_pcm_state_t state) { struct snd_pcm_runtime *runtime = substream->runtime; runtime->control->appl_ptr = runtime->status->hw_ptr; snd_pcm_set_state(substream, SNDRV_PCM_STATE_PREPARED); } static const struct action_ops snd_pcm_action_prepare = { .pre_action = snd_pcm_pre_prepare, .do_action = snd_pcm_do_prepare, .post_action = snd_pcm_post_prepare }; /** * snd_pcm_prepare - prepare the PCM substream to be triggerable * @substream: the PCM substream instance * @file: file to refer f_flags * * Return: Zero if successful, or a negative error code. */ static int snd_pcm_prepare(struct snd_pcm_substream *substream, struct file *file) { int f_flags; if (file) f_flags = file->f_flags; else f_flags = substream->f_flags; snd_pcm_stream_lock_irq(substream); switch (substream->runtime->status->state) { case SNDRV_PCM_STATE_PAUSED: snd_pcm_pause(substream, false); fallthrough; case SNDRV_PCM_STATE_SUSPENDED: snd_pcm_stop(substream, SNDRV_PCM_STATE_SETUP); break; } snd_pcm_stream_unlock_irq(substream); return snd_pcm_action_nonatomic(&snd_pcm_action_prepare, substream, (__force snd_pcm_state_t)f_flags); } /* * drain ioctl */ /* drain init callbacks: state argument ignored */ static int snd_pcm_pre_drain_init(struct snd_pcm_substream *substream, snd_pcm_state_t state) { struct snd_pcm_runtime *runtime = substream->runtime; switch (runtime->status->state) { case SNDRV_PCM_STATE_OPEN: case SNDRV_PCM_STATE_DISCONNECTED: case SNDRV_PCM_STATE_SUSPENDED: return -EBADFD; } runtime->trigger_master = substream; return 0; } static int snd_pcm_do_drain_init(struct snd_pcm_substream *substream, snd_pcm_state_t state) { struct snd_pcm_runtime *runtime = substream->runtime; if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { switch (runtime->status->state) { case SNDRV_PCM_STATE_PREPARED: /* start playback stream if possible */ if (! snd_pcm_playback_empty(substream)) { snd_pcm_do_start(substream, SNDRV_PCM_STATE_DRAINING); snd_pcm_post_start(substream, SNDRV_PCM_STATE_DRAINING); } else { runtime->status->state = SNDRV_PCM_STATE_SETUP; } break; case SNDRV_PCM_STATE_RUNNING: runtime->status->state = SNDRV_PCM_STATE_DRAINING; break; case SNDRV_PCM_STATE_XRUN: runtime->status->state = SNDRV_PCM_STATE_SETUP; break; default: break; } } else { /* stop running stream */ if (runtime->status->state == SNDRV_PCM_STATE_RUNNING) { snd_pcm_state_t new_state; new_state = snd_pcm_capture_avail(runtime) > 0 ? SNDRV_PCM_STATE_DRAINING : SNDRV_PCM_STATE_SETUP; snd_pcm_do_stop(substream, new_state); snd_pcm_post_stop(substream, new_state); } } if (runtime->status->state == SNDRV_PCM_STATE_DRAINING && runtime->trigger_master == substream && (runtime->hw.info & SNDRV_PCM_INFO_DRAIN_TRIGGER)) return substream->ops->trigger(substream, SNDRV_PCM_TRIGGER_DRAIN); return 0; } static void snd_pcm_post_drain_init(struct snd_pcm_substream *substream, snd_pcm_state_t state) { } static const struct action_ops snd_pcm_action_drain_init = { .pre_action = snd_pcm_pre_drain_init, .do_action = snd_pcm_do_drain_init, .post_action = snd_pcm_post_drain_init }; /* * Drain the stream(s). * When the substream is linked, sync until the draining of all playback streams * is finished. * After this call, all streams are supposed to be either SETUP or DRAINING * (capture only) state. */ static int snd_pcm_drain(struct snd_pcm_substream *substream, struct file *file) { struct snd_card *card; struct snd_pcm_runtime *runtime; struct snd_pcm_substream *s; struct snd_pcm_group *group; wait_queue_entry_t wait; int result = 0; int nonblock = 0; card = substream->pcm->card; runtime = substream->runtime; if (runtime->status->state == SNDRV_PCM_STATE_OPEN) return -EBADFD; if (file) { if (file->f_flags & O_NONBLOCK) nonblock = 1; } else if (substream->f_flags & O_NONBLOCK) nonblock = 1; snd_pcm_stream_lock_irq(substream); /* resume pause */ if (runtime->status->state == SNDRV_PCM_STATE_PAUSED) snd_pcm_pause(substream, false); /* pre-start/stop - all running streams are changed to DRAINING state */ result = snd_pcm_action(&snd_pcm_action_drain_init, substream, ACTION_ARG_IGNORE); if (result < 0) goto unlock; /* in non-blocking, we don't wait in ioctl but let caller poll */ if (nonblock) { result = -EAGAIN; goto unlock; } for (;;) { long tout; struct snd_pcm_runtime *to_check; if (signal_pending(current)) { result = -ERESTARTSYS; break; } /* find a substream to drain */ to_check = NULL; group = snd_pcm_stream_group_ref(substream); snd_pcm_group_for_each_entry(s, substream) { if (s->stream != SNDRV_PCM_STREAM_PLAYBACK) continue; runtime = s->runtime; if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) { to_check = runtime; break; } } snd_pcm_group_unref(group, substream); if (!to_check) break; /* all drained */ init_waitqueue_entry(&wait, current); set_current_state(TASK_INTERRUPTIBLE); add_wait_queue(&to_check->sleep, &wait); snd_pcm_stream_unlock_irq(substream); if (runtime->no_period_wakeup) tout = MAX_SCHEDULE_TIMEOUT; else { tout = 10; if (runtime->rate) { long t = runtime->period_size * 2 / runtime->rate; tout = max(t, tout); } tout = msecs_to_jiffies(tout * 1000); } tout = schedule_timeout(tout); snd_pcm_stream_lock_irq(substream); group = snd_pcm_stream_group_ref(substream); snd_pcm_group_for_each_entry(s, substream) { if (s->runtime == to_check) { remove_wait_queue(&to_check->sleep, &wait); break; } } snd_pcm_group_unref(group, substream); if (card->shutdown) { result = -ENODEV; break; } if (tout == 0) { if (substream->runtime->status->state == SNDRV_PCM_STATE_SUSPENDED) result = -ESTRPIPE; else { dev_dbg(substream->pcm->card->dev, "playback drain error (DMA or IRQ trouble?)\n"); snd_pcm_stop(substream, SNDRV_PCM_STATE_SETUP); result = -EIO; } break; } } unlock: snd_pcm_stream_unlock_irq(substream); return result; } /* * drop ioctl * * Immediately put all linked substreams into SETUP state. */ static int snd_pcm_drop(struct snd_pcm_substream *substream) { struct snd_pcm_runtime *runtime; int result = 0; if (PCM_RUNTIME_CHECK(substream)) return -ENXIO; runtime = substream->runtime; if (runtime->status->state == SNDRV_PCM_STATE_OPEN || runtime->status->state == SNDRV_PCM_STATE_DISCONNECTED) return -EBADFD; snd_pcm_stream_lock_irq(substream); /* resume pause */ if (runtime->status->state == SNDRV_PCM_STATE_PAUSED) snd_pcm_pause(substream, false); snd_pcm_stop(substream, SNDRV_PCM_STATE_SETUP); /* runtime->control->appl_ptr = runtime->status->hw_ptr; */ snd_pcm_stream_unlock_irq(substream); return result; } static bool is_pcm_file(struct file *file) { struct inode *inode = file_inode(file); struct snd_pcm *pcm; unsigned int minor; if (!S_ISCHR(inode->i_mode) || imajor(inode) != snd_major) return false; minor = iminor(inode); pcm = snd_lookup_minor_data(minor, SNDRV_DEVICE_TYPE_PCM_PLAYBACK); if (!pcm) pcm = snd_lookup_minor_data(minor, SNDRV_DEVICE_TYPE_PCM_CAPTURE); if (!pcm) return false; snd_card_unref(pcm->card); return true; } /* * PCM link handling */ static int snd_pcm_link(struct snd_pcm_substream *substream, int fd) { int res = 0; struct snd_pcm_file *pcm_file; struct snd_pcm_substream *substream1; struct snd_pcm_group *group, *target_group; bool nonatomic = substream->pcm->nonatomic; struct fd f = fdget(fd); if (!f.file) return -EBADFD; if (!is_pcm_file(f.file)) { res = -EBADFD; goto _badf; } pcm_file = f.file->private_data; substream1 = pcm_file->substream; if (substream == substream1) { res = -EINVAL; goto _badf; } group = kzalloc(sizeof(*group), GFP_KERNEL); if (!group) { res = -ENOMEM; goto _nolock; } snd_pcm_group_init(group); down_write(&snd_pcm_link_rwsem); if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN || substream->runtime->status->state != substream1->runtime->status->state || substream->pcm->nonatomic != substream1->pcm->nonatomic) { res = -EBADFD; goto _end; } if (snd_pcm_stream_linked(substream1)) { res = -EALREADY; goto _end; } snd_pcm_stream_lock_irq(substream); if (!snd_pcm_stream_linked(substream)) { snd_pcm_group_assign(substream, group); group = NULL; /* assigned, don't free this one below */ } target_group = substream->group; snd_pcm_stream_unlock_irq(substream); snd_pcm_group_lock_irq(target_group, nonatomic); snd_pcm_stream_lock_nested(substream1); snd_pcm_group_assign(substream1, target_group); refcount_inc(&target_group->refs); snd_pcm_stream_unlock(substream1); snd_pcm_group_unlock_irq(target_group, nonatomic); _end: up_write(&snd_pcm_link_rwsem); _nolock: kfree(group); _badf: fdput(f); return res; } static void relink_to_local(struct snd_pcm_substream *substream) { snd_pcm_stream_lock_nested(substream); snd_pcm_group_assign(substream, &substream->self_group); snd_pcm_stream_unlock(substream); } static int snd_pcm_unlink(struct snd_pcm_substream *substream) { struct snd_pcm_group *group; bool nonatomic = substream->pcm->nonatomic; bool do_free = false; int res = 0; down_write(&snd_pcm_link_rwsem); if (!snd_pcm_stream_linked(substream)) { res = -EALREADY; goto _end; } group = substream->group; snd_pcm_group_lock_irq(group, nonatomic); relink_to_local(substream); refcount_dec(&group->refs); /* detach the last stream, too */ if (list_is_singular(&group->substreams)) { relink_to_local(list_first_entry(&group->substreams, struct snd_pcm_substream, link_list)); do_free = refcount_dec_and_test(&group->refs); } snd_pcm_group_unlock_irq(group, nonatomic); if (do_free) kfree(group); _end: up_write(&snd_pcm_link_rwsem); return res; } /* * hw configurator */ static int snd_pcm_hw_rule_mul(struct snd_pcm_hw_params *params, struct snd_pcm_hw_rule *rule) { struct snd_interval t; snd_interval_mul(hw_param_interval_c(params, rule->deps[0]), hw_param_interval_c(params, rule->deps[1]), &t); return snd_interval_refine(hw_param_interval(params, rule->var), &t); } static int snd_pcm_hw_rule_div(struct snd_pcm_hw_params *params, struct snd_pcm_hw_rule *rule) { struct snd_interval t; snd_interval_div(hw_param_interval_c(params, rule->deps[0]), hw_param_interval_c(params, rule->deps[1]), &t); return snd_interval_refine(hw_param_interval(params, rule->var), &t); } static int snd_pcm_hw_rule_muldivk(struct snd_pcm_hw_params *params, struct snd_pcm_hw_rule *rule) { struct snd_interval t; snd_interval_muldivk(hw_param_interval_c(params, rule->deps[0]), hw_param_interval_c(params, rule->deps[1]), (unsigned long) rule->private, &t); return snd_interval_refine(hw_param_interval(params, rule->var), &t); } static int snd_pcm_hw_rule_mulkdiv(struct snd_pcm_hw_params *params, struct snd_pcm_hw_rule *rule) { struct snd_interval t; snd_interval_mulkdiv(hw_param_interval_c(params, rule->deps[0]), (unsigned long) rule->private, hw_param_interval_c(params, rule->deps[1]), &t); return snd_interval_refine(hw_param_interval(params, rule->var), &t); } static int snd_pcm_hw_rule_format(struct snd_pcm_hw_params *params, struct snd_pcm_hw_rule *rule) { snd_pcm_format_t k; const struct snd_interval *i = hw_param_interval_c(params, rule->deps[0]); struct snd_mask m; struct snd_mask *mask = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT); snd_mask_any(&m); pcm_for_each_format(k) { int bits; if (!snd_mask_test_format(mask, k)) continue; bits = snd_pcm_format_physical_width(k); if (bits <= 0) continue; /* ignore invalid formats */ if ((unsigned)bits < i->min || (unsigned)bits > i->max) snd_mask_reset(&m, (__force unsigned)k); } return snd_mask_refine(mask, &m); } static int snd_pcm_hw_rule_sample_bits(struct snd_pcm_hw_params *params, struct snd_pcm_hw_rule *rule) { struct snd_interval t; snd_pcm_format_t k; t.min = UINT_MAX; t.max = 0; t.openmin = 0; t.openmax = 0; pcm_for_each_format(k) { int bits; if (!snd_mask_test_format(hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT), k)) continue; bits = snd_pcm_format_physical_width(k); if (bits <= 0) continue; /* ignore invalid formats */ if (t.min > (unsigned)bits) t.min = bits; if (t.max < (unsigned)bits) t.max = bits; } t.integer = 1; return snd_interval_refine(hw_param_interval(params, rule->var), &t); } #if SNDRV_PCM_RATE_5512 != 1 << 0 || SNDRV_PCM_RATE_192000 != 1 << 12 #error "Change this table" #endif static const unsigned int rates[] = { 5512, 8000, 11025, 16000, 22050, 32000, 44100, 48000, 64000, 88200, 96000, 176400, 192000, 352800, 384000 }; const struct snd_pcm_hw_constraint_list snd_pcm_known_rates = { .count = ARRAY_SIZE(rates), .list = rates, }; static int snd_pcm_hw_rule_rate(struct snd_pcm_hw_params *params, struct snd_pcm_hw_rule *rule) { struct snd_pcm_hardware *hw = rule->private; return snd_interval_list(hw_param_interval(params, rule->var), snd_pcm_known_rates.count, snd_pcm_known_rates.list, hw->rates); } static int snd_pcm_hw_rule_buffer_bytes_max(struct snd_pcm_hw_params *params, struct snd_pcm_hw_rule *rule) { struct snd_interval t; struct snd_pcm_substream *substream = rule->private; t.min = 0; t.max = substream->buffer_bytes_max; t.openmin = 0; t.openmax = 0; t.integer = 1; return snd_interval_refine(hw_param_interval(params, rule->var), &t); } static int snd_pcm_hw_constraints_init(struct snd_pcm_substream *substream) { struct snd_pcm_runtime *runtime = substream->runtime; struct snd_pcm_hw_constraints *constrs = &runtime->hw_constraints; int k, err; for (k = SNDRV_PCM_HW_PARAM_FIRST_MASK; k <= SNDRV_PCM_HW_PARAM_LAST_MASK; k++) { snd_mask_any(constrs_mask(constrs, k)); } for (k = SNDRV_PCM_HW_PARAM_FIRST_INTERVAL; k <= SNDRV_PCM_HW_PARAM_LAST_INTERVAL; k++) { snd_interval_any(constrs_interval(constrs, k)); } snd_interval_setinteger(constrs_interval(constrs, SNDRV_PCM_HW_PARAM_CHANNELS)); snd_interval_setinteger(constrs_interval(constrs, SNDRV_PCM_HW_PARAM_BUFFER_SIZE)); snd_interval_setinteger(constrs_interval(constrs, SNDRV_PCM_HW_PARAM_BUFFER_BYTES)); snd_interval_setinteger(constrs_interval(constrs, SNDRV_PCM_HW_PARAM_SAMPLE_BITS)); snd_interval_setinteger(constrs_interval(constrs, SNDRV_PCM_HW_PARAM_FRAME_BITS)); err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_FORMAT, snd_pcm_hw_rule_format, NULL, SNDRV_PCM_HW_PARAM_SAMPLE_BITS, -1); if (err < 0) return err; err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_SAMPLE_BITS, snd_pcm_hw_rule_sample_bits, NULL, SNDRV_PCM_HW_PARAM_FORMAT, SNDRV_PCM_HW_PARAM_SAMPLE_BITS, -1); if (err < 0) return err; err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_SAMPLE_BITS, snd_pcm_hw_rule_div, NULL, SNDRV_PCM_HW_PARAM_FRAME_BITS, SNDRV_PCM_HW_PARAM_CHANNELS, -1); if (err < 0) return err; err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_FRAME_BITS, snd_pcm_hw_rule_mul, NULL, SNDRV_PCM_HW_PARAM_SAMPLE_BITS, SNDRV_PCM_HW_PARAM_CHANNELS, -1); if (err < 0) return err; err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_FRAME_BITS, snd_pcm_hw_rule_mulkdiv, (void*) 8, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, -1); if (err < 0) return err; err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_FRAME_BITS, snd_pcm_hw_rule_mulkdiv, (void*) 8, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, -1); if (err < 0) return err; err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, snd_pcm_hw_rule_div, NULL, SNDRV_PCM_HW_PARAM_FRAME_BITS, SNDRV_PCM_HW_PARAM_SAMPLE_BITS, -1); if (err < 0) return err; err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, snd_pcm_hw_rule_mulkdiv, (void*) 1000000, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, SNDRV_PCM_HW_PARAM_PERIOD_TIME, -1); if (err < 0) return err; err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, snd_pcm_hw_rule_mulkdiv, (void*) 1000000, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, SNDRV_PCM_HW_PARAM_BUFFER_TIME, -1); if (err < 0) return err; err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_PERIODS, snd_pcm_hw_rule_div, NULL, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, -1); if (err < 0) return err; err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, snd_pcm_hw_rule_div, NULL, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, SNDRV_PCM_HW_PARAM_PERIODS, -1); if (err < 0) return err; err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, snd_pcm_hw_rule_mulkdiv, (void*) 8, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, SNDRV_PCM_HW_PARAM_FRAME_BITS, -1); if (err < 0) return err; err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, snd_pcm_hw_rule_muldivk, (void*) 1000000, SNDRV_PCM_HW_PARAM_PERIOD_TIME, SNDRV_PCM_HW_PARAM_RATE, -1); if (err < 0) return err; err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, snd_pcm_hw_rule_mul, NULL, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, SNDRV_PCM_HW_PARAM_PERIODS, -1); if (err < 0) return err; err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, snd_pcm_hw_rule_mulkdiv, (void*) 8, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, SNDRV_PCM_HW_PARAM_FRAME_BITS, -1); if (err < 0) return err; err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, snd_pcm_hw_rule_muldivk, (void*) 1000000, SNDRV_PCM_HW_PARAM_BUFFER_TIME, SNDRV_PCM_HW_PARAM_RATE, -1); if (err < 0) return err; err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, snd_pcm_hw_rule_muldivk, (void*) 8, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, SNDRV_PCM_HW_PARAM_FRAME_BITS, -1); if (err < 0) return err; err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, snd_pcm_hw_rule_muldivk, (void*) 8, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, SNDRV_PCM_HW_PARAM_FRAME_BITS, -1); if (err < 0) return err; err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_TIME, snd_pcm_hw_rule_mulkdiv, (void*) 1000000, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, SNDRV_PCM_HW_PARAM_RATE, -1); if (err < 0) return err; err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_TIME, snd_pcm_hw_rule_mulkdiv, (void*) 1000000, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, SNDRV_PCM_HW_PARAM_RATE, -1); if (err < 0) return err; return 0; } static int snd_pcm_hw_constraints_complete(struct snd_pcm_substream *substream) { struct snd_pcm_runtime *runtime = substream->runtime; struct snd_pcm_hardware *hw = &runtime->hw; int err; unsigned int mask = 0; if (hw->info & SNDRV_PCM_INFO_INTERLEAVED) mask |= PARAM_MASK_BIT(SNDRV_PCM_ACCESS_RW_INTERLEAVED); if (hw->info & SNDRV_PCM_INFO_NONINTERLEAVED) mask |= PARAM_MASK_BIT(SNDRV_PCM_ACCESS_RW_NONINTERLEAVED); if (hw_support_mmap(substream)) { if (hw->info & SNDRV_PCM_INFO_INTERLEAVED) mask |= PARAM_MASK_BIT(SNDRV_PCM_ACCESS_MMAP_INTERLEAVED); if (hw->info & SNDRV_PCM_INFO_NONINTERLEAVED) mask |= PARAM_MASK_BIT(SNDRV_PCM_ACCESS_MMAP_NONINTERLEAVED); if (hw->info & SNDRV_PCM_INFO_COMPLEX) mask |= PARAM_MASK_BIT(SNDRV_PCM_ACCESS_MMAP_COMPLEX); } err = snd_pcm_hw_constraint_mask(runtime, SNDRV_PCM_HW_PARAM_ACCESS, mask); if (err < 0) return err; err = snd_pcm_hw_constraint_mask64(runtime, SNDRV_PCM_HW_PARAM_FORMAT, hw->formats); if (err < 0) return err; err = snd_pcm_hw_constraint_mask(runtime, SNDRV_PCM_HW_PARAM_SUBFORMAT, PARAM_MASK_BIT(SNDRV_PCM_SUBFORMAT_STD)); if (err < 0) return err; err = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_CHANNELS, hw->channels_min, hw->channels_max); if (err < 0) return err; err = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_RATE, hw->rate_min, hw->rate_max); if (err < 0) return err; err = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, hw->period_bytes_min, hw->period_bytes_max); if (err < 0) return err; err = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIODS, hw->periods_min, hw->periods_max); if (err < 0) return err; err = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, hw->period_bytes_min, hw->buffer_bytes_max); if (err < 0) return err; err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, snd_pcm_hw_rule_buffer_bytes_max, substream, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, -1); if (err < 0) return err; /* FIXME: remove */ if (runtime->dma_bytes) { err = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 0, runtime->dma_bytes); if (err < 0) return err; } if (!(hw->rates & (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS))) { err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, snd_pcm_hw_rule_rate, hw, SNDRV_PCM_HW_PARAM_RATE, -1); if (err < 0) return err; } /* FIXME: this belong to lowlevel */ snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIOD_SIZE); return 0; } static void pcm_release_private(struct snd_pcm_substream *substream) { if (snd_pcm_stream_linked(substream)) snd_pcm_unlink(substream); } void snd_pcm_release_substream(struct snd_pcm_substream *substream) { substream->ref_count--; if (substream->ref_count > 0) return; snd_pcm_drop(substream); if (substream->hw_opened) { if (substream->runtime->status->state != SNDRV_PCM_STATE_OPEN) do_hw_free(substream); substream->ops->close(substream); substream->hw_opened = 0; } if (cpu_latency_qos_request_active(&substream->latency_pm_qos_req)) cpu_latency_qos_remove_request(&substream->latency_pm_qos_req); if (substream->pcm_release) { substream->pcm_release(substream); substream->pcm_release = NULL; } snd_pcm_detach_substream(substream); } EXPORT_SYMBOL(snd_pcm_release_substream); int snd_pcm_open_substream(struct snd_pcm *pcm, int stream, struct file *file, struct snd_pcm_substream **rsubstream) { struct snd_pcm_substream *substream; int err; err = snd_pcm_attach_substream(pcm, stream, file, &substream); if (err < 0) return err; if (substream->ref_count > 1) { *rsubstream = substream; return 0; } err = snd_pcm_hw_constraints_init(substream); if (err < 0) { pcm_dbg(pcm, "snd_pcm_hw_constraints_init failed\n"); goto error; } err = substream->ops->open(substream); if (err < 0) goto error; substream->hw_opened = 1; err = snd_pcm_hw_constraints_complete(substream); if (err < 0) { pcm_dbg(pcm, "snd_pcm_hw_constraints_complete failed\n"); goto error; } *rsubstream = substream; return 0; error: snd_pcm_release_substream(substream); return err; } EXPORT_SYMBOL(snd_pcm_open_substream); static int snd_pcm_open_file(struct file *file, struct snd_pcm *pcm, int stream) { struct snd_pcm_file *pcm_file; struct snd_pcm_substream *substream; int err; err = snd_pcm_open_substream(pcm, stream, file, &substream); if (err < 0) return err; pcm_file = kzalloc(sizeof(*pcm_file), GFP_KERNEL); if (pcm_file == NULL) { snd_pcm_release_substream(substream); return -ENOMEM; } pcm_file->substream = substream; if (substream->ref_count == 1) substream->pcm_release = pcm_release_private; file->private_data = pcm_file; return 0; } static int snd_pcm_playback_open(struct inode *inode, struct file *file) { struct snd_pcm *pcm; int err = nonseekable_open(inode, file); if (err < 0) return err; pcm = snd_lookup_minor_data(iminor(inode), SNDRV_DEVICE_TYPE_PCM_PLAYBACK); err = snd_pcm_open(file, pcm, SNDRV_PCM_STREAM_PLAYBACK); if (pcm) snd_card_unref(pcm->card); return err; } static int snd_pcm_capture_open(struct inode *inode, struct file *file) { struct snd_pcm *pcm; int err = nonseekable_open(inode, file); if (err < 0) return err; pcm = snd_lookup_minor_data(iminor(inode), SNDRV_DEVICE_TYPE_PCM_CAPTURE); err = snd_pcm_open(file, pcm, SNDRV_PCM_STREAM_CAPTURE); if (pcm) snd_card_unref(pcm->card); return err; } static int snd_pcm_open(struct file *file, struct snd_pcm *pcm, int stream) { int err; wait_queue_entry_t wait; if (pcm == NULL) { err = -ENODEV; goto __error1; } err = snd_card_file_add(pcm->card, file); if (err < 0) goto __error1; if (!try_module_get(pcm->card->module)) { err = -EFAULT; goto __error2; } init_waitqueue_entry(&wait, current); add_wait_queue(&pcm->open_wait, &wait); mutex_lock(&pcm->open_mutex); while (1) { err = snd_pcm_open_file(file, pcm, stream); if (err >= 0) break; if (err == -EAGAIN) { if (file->f_flags & O_NONBLOCK) { err = -EBUSY; break; } } else break; set_current_state(TASK_INTERRUPTIBLE); mutex_unlock(&pcm->open_mutex); schedule(); mutex_lock(&pcm->open_mutex); if (pcm->card->shutdown) { err = -ENODEV; break; } if (signal_pending(current)) { err = -ERESTARTSYS; break; } } remove_wait_queue(&pcm->open_wait, &wait); mutex_unlock(&pcm->open_mutex); if (err < 0) goto __error; return err; __error: module_put(pcm->card->module); __error2: snd_card_file_remove(pcm->card, file); __error1: return err; } static int snd_pcm_release(struct inode *inode, struct file *file) { struct snd_pcm *pcm; struct snd_pcm_substream *substream; struct snd_pcm_file *pcm_file; pcm_file = file->private_data; substream = pcm_file->substream; if (snd_BUG_ON(!substream)) return -ENXIO; pcm = substream->pcm; /* block until the device gets woken up as it may touch the hardware */ snd_power_wait(pcm->card); mutex_lock(&pcm->open_mutex); snd_pcm_release_substream(substream); kfree(pcm_file); mutex_unlock(&pcm->open_mutex); wake_up(&pcm->open_wait); module_put(pcm->card->module); snd_card_file_remove(pcm->card, file); return 0; } /* check and update PCM state; return 0 or a negative error * call this inside PCM lock */ static int do_pcm_hwsync(struct snd_pcm_substream *substream) { switch (substream->runtime->status->state) { case SNDRV_PCM_STATE_DRAINING: if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) return -EBADFD; fallthrough; case SNDRV_PCM_STATE_RUNNING: return snd_pcm_update_hw_ptr(substream); case SNDRV_PCM_STATE_PREPARED: case SNDRV_PCM_STATE_PAUSED: return 0; case SNDRV_PCM_STATE_SUSPENDED: return -ESTRPIPE; case SNDRV_PCM_STATE_XRUN: return -EPIPE; default: return -EBADFD; } } /* increase the appl_ptr; returns the processed frames or a negative error */ static snd_pcm_sframes_t forward_appl_ptr(struct snd_pcm_substream *substream, snd_pcm_uframes_t frames, snd_pcm_sframes_t avail) { struct snd_pcm_runtime *runtime = substream->runtime; snd_pcm_sframes_t appl_ptr; int ret; if (avail <= 0) return 0; if (frames > (snd_pcm_uframes_t)avail) frames = avail; appl_ptr = runtime->control->appl_ptr + frames; if (appl_ptr >= (snd_pcm_sframes_t)runtime->boundary) appl_ptr -= runtime->boundary; ret = pcm_lib_apply_appl_ptr(substream, appl_ptr); return ret < 0 ? ret : frames; } /* decrease the appl_ptr; returns the processed frames or zero for error */ static snd_pcm_sframes_t rewind_appl_ptr(struct snd_pcm_substream *substream, snd_pcm_uframes_t frames, snd_pcm_sframes_t avail) { struct snd_pcm_runtime *runtime = substream->runtime; snd_pcm_sframes_t appl_ptr; int ret; if (avail <= 0) return 0; if (frames > (snd_pcm_uframes_t)avail) frames = avail; appl_ptr = runtime->control->appl_ptr - frames; if (appl_ptr < 0) appl_ptr += runtime->boundary; ret = pcm_lib_apply_appl_ptr(substream, appl_ptr); /* NOTE: we return zero for errors because PulseAudio gets depressed * upon receiving an error from rewind ioctl and stops processing * any longer. Returning zero means that no rewind is done, so * it's not absolutely wrong to answer like that. */ return ret < 0 ? 0 : frames; } static snd_pcm_sframes_t snd_pcm_rewind(struct snd_pcm_substream *substream, snd_pcm_uframes_t frames) { snd_pcm_sframes_t ret; if (frames == 0) return 0; snd_pcm_stream_lock_irq(substream); ret = do_pcm_hwsync(substream); if (!ret) ret = rewind_appl_ptr(substream, frames, snd_pcm_hw_avail(substream)); snd_pcm_stream_unlock_irq(substream); return ret; } static snd_pcm_sframes_t snd_pcm_forward(struct snd_pcm_substream *substream, snd_pcm_uframes_t frames) { snd_pcm_sframes_t ret; if (frames == 0) return 0; snd_pcm_stream_lock_irq(substream); ret = do_pcm_hwsync(substream); if (!ret) ret = forward_appl_ptr(substream, frames, snd_pcm_avail(substream)); snd_pcm_stream_unlock_irq(substream); return ret; } static int snd_pcm_hwsync(struct snd_pcm_substream *substream) { int err; snd_pcm_stream_lock_irq(substream); err = do_pcm_hwsync(substream); snd_pcm_stream_unlock_irq(substream); return err; } static int snd_pcm_delay(struct snd_pcm_substream *substream, snd_pcm_sframes_t *delay) { int err; snd_pcm_sframes_t n = 0; snd_pcm_stream_lock_irq(substream); err = do_pcm_hwsync(substream); if (!err) n = snd_pcm_calc_delay(substream); snd_pcm_stream_unlock_irq(substream); if (!err) *delay = n; return err; } static int snd_pcm_sync_ptr(struct snd_pcm_substream *substream, struct snd_pcm_sync_ptr __user *_sync_ptr) { struct snd_pcm_runtime *runtime = substream->runtime; struct snd_pcm_sync_ptr sync_ptr; volatile struct snd_pcm_mmap_status *status; volatile struct snd_pcm_mmap_control *control; int err; memset(&sync_ptr, 0, sizeof(sync_ptr)); if (get_user(sync_ptr.flags, (unsigned __user *)&(_sync_ptr->flags))) return -EFAULT; if (copy_from_user(&sync_ptr.c.control, &(_sync_ptr->c.control), sizeof(struct snd_pcm_mmap_control))) return -EFAULT; status = runtime->status; control = runtime->control; if (sync_ptr.flags & SNDRV_PCM_SYNC_PTR_HWSYNC) { err = snd_pcm_hwsync(substream); if (err < 0) return err; } snd_pcm_stream_lock_irq(substream); if (!(sync_ptr.flags & SNDRV_PCM_SYNC_PTR_APPL)) { err = pcm_lib_apply_appl_ptr(substream, sync_ptr.c.control.appl_ptr); if (err < 0) { snd_pcm_stream_unlock_irq(substream); return err; } } else { sync_ptr.c.control.appl_ptr = control->appl_ptr; } if (!(sync_ptr.flags & SNDRV_PCM_SYNC_PTR_AVAIL_MIN)) control->avail_min = sync_ptr.c.control.avail_min; else sync_ptr.c.control.avail_min = control->avail_min; sync_ptr.s.status.state = status->state; sync_ptr.s.status.hw_ptr = status->hw_ptr; sync_ptr.s.status.tstamp = status->tstamp; sync_ptr.s.status.suspended_state = status->suspended_state; sync_ptr.s.status.audio_tstamp = status->audio_tstamp; snd_pcm_stream_unlock_irq(substream); if (copy_to_user(_sync_ptr, &sync_ptr, sizeof(sync_ptr))) return -EFAULT; return 0; } struct snd_pcm_mmap_status32 { snd_pcm_state_t state; s32 pad1; u32 hw_ptr; s32 tstamp_sec; s32 tstamp_nsec; snd_pcm_state_t suspended_state; s32 audio_tstamp_sec; s32 audio_tstamp_nsec; } __attribute__((packed)); struct snd_pcm_mmap_control32 { u32 appl_ptr; u32 avail_min; }; struct snd_pcm_sync_ptr32 { u32 flags; union { struct snd_pcm_mmap_status32 status; unsigned char reserved[64]; } s; union { struct snd_pcm_mmap_control32 control; unsigned char reserved[64]; } c; } __attribute__((packed)); /* recalcuate the boundary within 32bit */ static snd_pcm_uframes_t recalculate_boundary(struct snd_pcm_runtime *runtime) { snd_pcm_uframes_t boundary; if (! runtime->buffer_size) return 0; boundary = runtime->buffer_size; while (boundary * 2 <= 0x7fffffffUL - runtime->buffer_size) boundary *= 2; return boundary; } static int snd_pcm_ioctl_sync_ptr_compat(struct snd_pcm_substream *substream, struct snd_pcm_sync_ptr32 __user *src) { struct snd_pcm_runtime *runtime = substream->runtime; volatile struct snd_pcm_mmap_status *status; volatile struct snd_pcm_mmap_control *control; u32 sflags; struct snd_pcm_mmap_control scontrol; struct snd_pcm_mmap_status sstatus; snd_pcm_uframes_t boundary; int err; if (snd_BUG_ON(!runtime)) return -EINVAL; if (get_user(sflags, &src->flags) || get_user(scontrol.appl_ptr, &src->c.control.appl_ptr) || get_user(scontrol.avail_min, &src->c.control.avail_min)) return -EFAULT; if (sflags & SNDRV_PCM_SYNC_PTR_HWSYNC) { err = snd_pcm_hwsync(substream); if (err < 0) return err; } status = runtime->status; control = runtime->control; boundary = recalculate_boundary(runtime); if (! boundary) boundary = 0x7fffffff; snd_pcm_stream_lock_irq(substream); /* FIXME: we should consider the boundary for the sync from app */ if (!(sflags & SNDRV_PCM_SYNC_PTR_APPL)) { err = pcm_lib_apply_appl_ptr(substream, scontrol.appl_ptr); if (err < 0) { snd_pcm_stream_unlock_irq(substream); return err; } } else scontrol.appl_ptr = control->appl_ptr % boundary; if (!(sflags & SNDRV_PCM_SYNC_PTR_AVAIL_MIN)) control->avail_min = scontrol.avail_min; else scontrol.avail_min = control->avail_min; sstatus.state = status->state; sstatus.hw_ptr = status->hw_ptr % boundary; sstatus.tstamp = status->tstamp; sstatus.suspended_state = status->suspended_state; sstatus.audio_tstamp = status->audio_tstamp; snd_pcm_stream_unlock_irq(substream); if (put_user(sstatus.state, &src->s.status.state) || put_user(sstatus.hw_ptr, &src->s.status.hw_ptr) || put_user(sstatus.tstamp.tv_sec, &src->s.status.tstamp_sec) || put_user(sstatus.tstamp.tv_nsec, &src->s.status.tstamp_nsec) || put_user(sstatus.suspended_state, &src->s.status.suspended_state) || put_user(sstatus.audio_tstamp.tv_sec, &src->s.status.audio_tstamp_sec) || put_user(sstatus.audio_tstamp.tv_nsec, &src->s.status.audio_tstamp_nsec) || put_user(scontrol.appl_ptr, &src->c.control.appl_ptr) || put_user(scontrol.avail_min, &src->c.control.avail_min)) return -EFAULT; return 0; } #define __SNDRV_PCM_IOCTL_SYNC_PTR32 _IOWR('A', 0x23, struct snd_pcm_sync_ptr32) static int snd_pcm_tstamp(struct snd_pcm_substream *substream, int __user *_arg) { struct snd_pcm_runtime *runtime = substream->runtime; int arg; if (get_user(arg, _arg)) return -EFAULT; if (arg < 0 || arg > SNDRV_PCM_TSTAMP_TYPE_LAST) return -EINVAL; runtime->tstamp_type = arg; return 0; } static int snd_pcm_xferi_frames_ioctl(struct snd_pcm_substream *substream, struct snd_xferi __user *_xferi) { struct snd_xferi xferi; struct snd_pcm_runtime *runtime = substream->runtime; snd_pcm_sframes_t result; if (runtime->status->state == SNDRV_PCM_STATE_OPEN) return -EBADFD; if (put_user(0, &_xferi->result)) return -EFAULT; if (copy_from_user(&xferi, _xferi, sizeof(xferi))) return -EFAULT; if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) result = snd_pcm_lib_write(substream, xferi.buf, xferi.frames); else result = snd_pcm_lib_read(substream, xferi.buf, xferi.frames); if (put_user(result, &_xferi->result)) return -EFAULT; return result < 0 ? result : 0; } static int snd_pcm_xfern_frames_ioctl(struct snd_pcm_substream *substream, struct snd_xfern __user *_xfern) { struct snd_xfern xfern; struct snd_pcm_runtime *runtime = substream->runtime; void *bufs; snd_pcm_sframes_t result; if (runtime->status->state == SNDRV_PCM_STATE_OPEN) return -EBADFD; if (runtime->channels > 128) return -EINVAL; if (put_user(0, &_xfern->result)) return -EFAULT; if (copy_from_user(&xfern, _xfern, sizeof(xfern))) return -EFAULT; bufs = memdup_user(xfern.bufs, sizeof(void *) * runtime->channels); if (IS_ERR(bufs)) return PTR_ERR(bufs); if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) result = snd_pcm_lib_writev(substream, bufs, xfern.frames); else result = snd_pcm_lib_readv(substream, bufs, xfern.frames); kfree(bufs); if (put_user(result, &_xfern->result)) return -EFAULT; return result < 0 ? result : 0; } static int snd_pcm_rewind_ioctl(struct snd_pcm_substream *substream, snd_pcm_uframes_t __user *_frames) { snd_pcm_uframes_t frames; snd_pcm_sframes_t result; if (get_user(frames, _frames)) return -EFAULT; if (put_user(0, _frames)) return -EFAULT; result = snd_pcm_rewind(substream, frames); if (put_user(result, _frames)) return -EFAULT; return result < 0 ? result : 0; } static int snd_pcm_forward_ioctl(struct snd_pcm_substream *substream, snd_pcm_uframes_t __user *_frames) { snd_pcm_uframes_t frames; snd_pcm_sframes_t result; if (get_user(frames, _frames)) return -EFAULT; if (put_user(0, _frames)) return -EFAULT; result = snd_pcm_forward(substream, frames); if (put_user(result, _frames)) return -EFAULT; return result < 0 ? result : 0; } static int snd_pcm_common_ioctl(struct file *file, struct snd_pcm_substream *substream, unsigned int cmd, void __user *arg) { struct snd_pcm_file *pcm_file = file->private_data; int res; if (PCM_RUNTIME_CHECK(substream)) return -ENXIO; res = snd_power_wait(substream->pcm->card); if (res < 0) return res; switch (cmd) { case SNDRV_PCM_IOCTL_PVERSION: return put_user(SNDRV_PCM_VERSION, (int __user *)arg) ? -EFAULT : 0; case SNDRV_PCM_IOCTL_INFO: return snd_pcm_info_user(substream, arg); case SNDRV_PCM_IOCTL_TSTAMP: /* just for compatibility */ return 0; case SNDRV_PCM_IOCTL_TTSTAMP: return snd_pcm_tstamp(substream, arg); case SNDRV_PCM_IOCTL_USER_PVERSION: if (get_user(pcm_file->user_pversion, (unsigned int __user *)arg)) return -EFAULT; return 0; case SNDRV_PCM_IOCTL_HW_REFINE: return snd_pcm_hw_refine_user(substream, arg); case SNDRV_PCM_IOCTL_HW_PARAMS: return snd_pcm_hw_params_user(substream, arg); case SNDRV_PCM_IOCTL_HW_FREE: return snd_pcm_hw_free(substream); case SNDRV_PCM_IOCTL_SW_PARAMS: return snd_pcm_sw_params_user(substream, arg); case SNDRV_PCM_IOCTL_STATUS32: return snd_pcm_status_user32(substream, arg, false); case SNDRV_PCM_IOCTL_STATUS_EXT32: return snd_pcm_status_user32(substream, arg, true); case SNDRV_PCM_IOCTL_STATUS64: return snd_pcm_status_user64(substream, arg, false); case SNDRV_PCM_IOCTL_STATUS_EXT64: return snd_pcm_status_user64(substream, arg, true); case SNDRV_PCM_IOCTL_CHANNEL_INFO: return snd_pcm_channel_info_user(substream, arg); case SNDRV_PCM_IOCTL_PREPARE: return snd_pcm_prepare(substream, file); case SNDRV_PCM_IOCTL_RESET: return snd_pcm_reset(substream); case SNDRV_PCM_IOCTL_START: return snd_pcm_start_lock_irq(substream); case SNDRV_PCM_IOCTL_LINK: return snd_pcm_link(substream, (int)(unsigned long) arg); case SNDRV_PCM_IOCTL_UNLINK: return snd_pcm_unlink(substream); case SNDRV_PCM_IOCTL_RESUME: return snd_pcm_resume(substream); case SNDRV_PCM_IOCTL_XRUN: return snd_pcm_xrun(substream); case SNDRV_PCM_IOCTL_HWSYNC: return snd_pcm_hwsync(substream); case SNDRV_PCM_IOCTL_DELAY: { snd_pcm_sframes_t delay; snd_pcm_sframes_t __user *res = arg; int err; err = snd_pcm_delay(substream, &delay); if (err) return err; if (put_user(delay, res)) return -EFAULT; return 0; } case __SNDRV_PCM_IOCTL_SYNC_PTR32: return snd_pcm_ioctl_sync_ptr_compat(substream, arg); case __SNDRV_PCM_IOCTL_SYNC_PTR64: return snd_pcm_sync_ptr(substream, arg); #ifdef CONFIG_SND_SUPPORT_OLD_API case SNDRV_PCM_IOCTL_HW_REFINE_OLD: return snd_pcm_hw_refine_old_user(substream, arg); case SNDRV_PCM_IOCTL_HW_PARAMS_OLD: return snd_pcm_hw_params_old_user(substream, arg); #endif case SNDRV_PCM_IOCTL_DRAIN: return snd_pcm_drain(substream, file); case SNDRV_PCM_IOCTL_DROP: return snd_pcm_drop(substream); case SNDRV_PCM_IOCTL_PAUSE: return snd_pcm_pause_lock_irq(substream, (unsigned long)arg); case SNDRV_PCM_IOCTL_WRITEI_FRAMES: case SNDRV_PCM_IOCTL_READI_FRAMES: return snd_pcm_xferi_frames_ioctl(substream, arg); case SNDRV_PCM_IOCTL_WRITEN_FRAMES: case SNDRV_PCM_IOCTL_READN_FRAMES: return snd_pcm_xfern_frames_ioctl(substream, arg); case SNDRV_PCM_IOCTL_REWIND: return snd_pcm_rewind_ioctl(substream, arg); case SNDRV_PCM_IOCTL_FORWARD: return snd_pcm_forward_ioctl(substream, arg); } pcm_dbg(substream->pcm, "unknown ioctl = 0x%x\n", cmd); return -ENOTTY; } static long snd_pcm_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { struct snd_pcm_file *pcm_file; pcm_file = file->private_data; if (((cmd >> 8) & 0xff) != 'A') return -ENOTTY; return snd_pcm_common_ioctl(file, pcm_file->substream, cmd, (void __user *)arg); } /** * snd_pcm_kernel_ioctl - Execute PCM ioctl in the kernel-space * @substream: PCM substream * @cmd: IOCTL cmd * @arg: IOCTL argument * * The function is provided primarily for OSS layer and USB gadget drivers, * and it allows only the limited set of ioctls (hw_params, sw_params, * prepare, start, drain, drop, forward). */ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream, unsigned int cmd, void *arg) { snd_pcm_uframes_t *frames = arg; snd_pcm_sframes_t result; switch (cmd) { case SNDRV_PCM_IOCTL_FORWARD: { /* provided only for OSS; capture-only and no value returned */ if (substream->stream != SNDRV_PCM_STREAM_CAPTURE) return -EINVAL; result = snd_pcm_forward(substream, *frames); return result < 0 ? result : 0; } case SNDRV_PCM_IOCTL_HW_PARAMS: return snd_pcm_hw_params(substream, arg); case SNDRV_PCM_IOCTL_SW_PARAMS: return snd_pcm_sw_params(substream, arg); case SNDRV_PCM_IOCTL_PREPARE: return snd_pcm_prepare(substream, NULL); case SNDRV_PCM_IOCTL_START: return snd_pcm_start_lock_irq(substream); case SNDRV_PCM_IOCTL_DRAIN: return snd_pcm_drain(substream, NULL); case SNDRV_PCM_IOCTL_DROP: return snd_pcm_drop(substream); case SNDRV_PCM_IOCTL_DELAY: return snd_pcm_delay(substream, frames); default: return -EINVAL; } } EXPORT_SYMBOL(snd_pcm_kernel_ioctl); static ssize_t snd_pcm_read(struct file *file, char __user *buf, size_t count, loff_t * offset) { struct snd_pcm_file *pcm_file; struct snd_pcm_substream *substream; struct snd_pcm_runtime *runtime; snd_pcm_sframes_t result; pcm_file = file->private_data; substream = pcm_file->substream; if (PCM_RUNTIME_CHECK(substream)) return -ENXIO; runtime = substream->runtime; if (runtime->status->state == SNDRV_PCM_STATE_OPEN) return -EBADFD; if (!frame_aligned(runtime, count)) return -EINVAL; count = bytes_to_frames(runtime, count); result = snd_pcm_lib_read(substream, buf, count); if (result > 0) result = frames_to_bytes(runtime, result); return result; } static ssize_t snd_pcm_write(struct file *file, const char __user *buf, size_t count, loff_t * offset) { struct snd_pcm_file *pcm_file; struct snd_pcm_substream *substream; struct snd_pcm_runtime *runtime; snd_pcm_sframes_t result; pcm_file = file->private_data; substream = pcm_file->substream; if (PCM_RUNTIME_CHECK(substream)) return -ENXIO; runtime = substream->runtime; if (runtime->status->state == SNDRV_PCM_STATE_OPEN) return -EBADFD; if (!frame_aligned(runtime, count)) return -EINVAL; count = bytes_to_frames(runtime, count); result = snd_pcm_lib_write(substream, buf, count); if (result > 0) result = frames_to_bytes(runtime, result); return result; } static ssize_t snd_pcm_readv(struct kiocb *iocb, struct iov_iter *to) { struct snd_pcm_file *pcm_file; struct snd_pcm_substream *substream; struct snd_pcm_runtime *runtime; snd_pcm_sframes_t result; unsigned long i; void __user **bufs; snd_pcm_uframes_t frames; pcm_file = iocb->ki_filp->private_data; substream = pcm_file->substream; if (PCM_RUNTIME_CHECK(substream)) return -ENXIO; runtime = substream->runtime; if (runtime->status->state == SNDRV_PCM_STATE_OPEN) return -EBADFD; if (!iter_is_iovec(to)) return -EINVAL; if (to->nr_segs > 1024 || to->nr_segs != runtime->channels) return -EINVAL; if (!frame_aligned(runtime, to->iov->iov_len)) return -EINVAL; frames = bytes_to_samples(runtime, to->iov->iov_len); bufs = kmalloc_array(to->nr_segs, sizeof(void *), GFP_KERNEL); if (bufs == NULL) return -ENOMEM; for (i = 0; i < to->nr_segs; ++i) bufs[i] = to->iov[i].iov_base; result = snd_pcm_lib_readv(substream, bufs, frames); if (result > 0) result = frames_to_bytes(runtime, result); kfree(bufs); return result; } static ssize_t snd_pcm_writev(struct kiocb *iocb, struct iov_iter *from) { struct snd_pcm_file *pcm_file; struct snd_pcm_substream *substream; struct snd_pcm_runtime *runtime; snd_pcm_sframes_t result; unsigned long i; void __user **bufs; snd_pcm_uframes_t frames; pcm_file = iocb->ki_filp->private_data; substream = pcm_file->substream; if (PCM_RUNTIME_CHECK(substream)) return -ENXIO; runtime = substream->runtime; if (runtime->status->state == SNDRV_PCM_STATE_OPEN) return -EBADFD; if (!iter_is_iovec(from)) return -EINVAL; if (from->nr_segs > 128 || from->nr_segs != runtime->channels || !frame_aligned(runtime, from->iov->iov_len)) return -EINVAL; frames = bytes_to_samples(runtime, from->iov->iov_len); bufs = kmalloc_array(from->nr_segs, sizeof(void *), GFP_KERNEL); if (bufs == NULL) return -ENOMEM; for (i = 0; i < from->nr_segs; ++i) bufs[i] = from->iov[i].iov_base; result = snd_pcm_lib_writev(substream, bufs, frames); if (result > 0) result = frames_to_bytes(runtime, result); kfree(bufs); return result; } static __poll_t snd_pcm_poll(struct file *file, poll_table *wait) { struct snd_pcm_file *pcm_file; struct snd_pcm_substream *substream; struct snd_pcm_runtime *runtime; __poll_t mask, ok; snd_pcm_uframes_t avail; pcm_file = file->private_data; substream = pcm_file->substream; if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ok = EPOLLOUT | EPOLLWRNORM; else ok = EPOLLIN | EPOLLRDNORM; if (PCM_RUNTIME_CHECK(substream)) return ok | EPOLLERR; runtime = substream->runtime; poll_wait(file, &runtime->sleep, wait); mask = 0; snd_pcm_stream_lock_irq(substream); avail = snd_pcm_avail(substream); switch (runtime->status->state) { case SNDRV_PCM_STATE_RUNNING: case SNDRV_PCM_STATE_PREPARED: case SNDRV_PCM_STATE_PAUSED: if (avail >= runtime->control->avail_min) mask = ok; break; case SNDRV_PCM_STATE_DRAINING: if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) { mask = ok; if (!avail) mask |= EPOLLERR; } break; default: mask = ok | EPOLLERR; break; } snd_pcm_stream_unlock_irq(substream); return mask; } /* * mmap support */ /* * Only on coherent architectures, we can mmap the status and the control records * for effcient data transfer. On others, we have to use HWSYNC ioctl... */ #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_ALPHA) /* * mmap status record */ static vm_fault_t snd_pcm_mmap_status_fault(struct vm_fault *vmf) { struct snd_pcm_substream *substream = vmf->vma->vm_private_data; struct snd_pcm_runtime *runtime; if (substream == NULL) return VM_FAULT_SIGBUS; runtime = substream->runtime; vmf->page = virt_to_page(runtime->status); get_page(vmf->page); return 0; } static const struct vm_operations_struct snd_pcm_vm_ops_status = { .fault = snd_pcm_mmap_status_fault, }; static int snd_pcm_mmap_status(struct snd_pcm_substream *substream, struct file *file, struct vm_area_struct *area) { long size; if (!(area->vm_flags & VM_READ)) return -EINVAL; size = area->vm_end - area->vm_start; if (size != PAGE_ALIGN(sizeof(struct snd_pcm_mmap_status))) return -EINVAL; area->vm_ops = &snd_pcm_vm_ops_status; area->vm_private_data = substream; area->vm_flags |= VM_DONTEXPAND | VM_DONTDUMP; return 0; } /* * mmap control record */ static vm_fault_t snd_pcm_mmap_control_fault(struct vm_fault *vmf) { struct snd_pcm_substream *substream = vmf->vma->vm_private_data; struct snd_pcm_runtime *runtime; if (substream == NULL) return VM_FAULT_SIGBUS; runtime = substream->runtime; vmf->page = virt_to_page(runtime->control); get_page(vmf->page); return 0; } static const struct vm_operations_struct snd_pcm_vm_ops_control = { .fault = snd_pcm_mmap_control_fault, }; static int snd_pcm_mmap_control(struct snd_pcm_substream *substream, struct file *file, struct vm_area_struct *area) { long size; if (!(area->vm_flags & VM_READ)) return -EINVAL; size = area->vm_end - area->vm_start; if (size != PAGE_ALIGN(sizeof(struct snd_pcm_mmap_control))) return -EINVAL; area->vm_ops = &snd_pcm_vm_ops_control; area->vm_private_data = substream; area->vm_flags |= VM_DONTEXPAND | VM_DONTDUMP; return 0; } static bool pcm_status_mmap_allowed(struct snd_pcm_file *pcm_file) { /* If drivers require the explicit sync (typically for non-coherent * pages), we have to disable the mmap of status and control data * to enforce the control via SYNC_PTR ioctl. */ if (pcm_file->substream->runtime->hw.info & SNDRV_PCM_INFO_EXPLICIT_SYNC) return false; /* See pcm_control_mmap_allowed() below. * Since older alsa-lib requires both status and control mmaps to be * coupled, we have to disable the status mmap for old alsa-lib, too. */ if (pcm_file->user_pversion < SNDRV_PROTOCOL_VERSION(2, 0, 14) && (pcm_file->substream->runtime->hw.info & SNDRV_PCM_INFO_SYNC_APPLPTR)) return false; return true; } static bool pcm_control_mmap_allowed(struct snd_pcm_file *pcm_file) { if (pcm_file->no_compat_mmap) return false; /* see above */ if (pcm_file->substream->runtime->hw.info & SNDRV_PCM_INFO_EXPLICIT_SYNC) return false; /* Disallow the control mmap when SYNC_APPLPTR flag is set; * it enforces the user-space to fall back to snd_pcm_sync_ptr(), * thus it effectively assures the manual update of appl_ptr. */ if (pcm_file->substream->runtime->hw.info & SNDRV_PCM_INFO_SYNC_APPLPTR) return false; return true; } #else /* ! coherent mmap */ /* * don't support mmap for status and control records. */ #define pcm_status_mmap_allowed(pcm_file) false #define pcm_control_mmap_allowed(pcm_file) false static int snd_pcm_mmap_status(struct snd_pcm_substream *substream, struct file *file, struct vm_area_struct *area) { return -ENXIO; } static int snd_pcm_mmap_control(struct snd_pcm_substream *substream, struct file *file, struct vm_area_struct *area) { return -ENXIO; } #endif /* coherent mmap */ /* * fault callback for mmapping a RAM page */ static vm_fault_t snd_pcm_mmap_data_fault(struct vm_fault *vmf) { struct snd_pcm_substream *substream = vmf->vma->vm_private_data; struct snd_pcm_runtime *runtime; unsigned long offset; struct page * page; size_t dma_bytes; if (substream == NULL) return VM_FAULT_SIGBUS; runtime = substream->runtime; offset = vmf->pgoff << PAGE_SHIFT; dma_bytes = PAGE_ALIGN(runtime->dma_bytes); if (offset > dma_bytes - PAGE_SIZE) return VM_FAULT_SIGBUS; if (substream->ops->page) page = substream->ops->page(substream, offset); else if (!snd_pcm_get_dma_buf(substream)) page = virt_to_page(runtime->dma_area + offset); else page = snd_sgbuf_get_page(snd_pcm_get_dma_buf(substream), offset); if (!page) return VM_FAULT_SIGBUS; get_page(page); vmf->page = page; return 0; } static const struct vm_operations_struct snd_pcm_vm_ops_data = { .open = snd_pcm_mmap_data_open, .close = snd_pcm_mmap_data_close, }; static const struct vm_operations_struct snd_pcm_vm_ops_data_fault = { .open = snd_pcm_mmap_data_open, .close = snd_pcm_mmap_data_close, .fault = snd_pcm_mmap_data_fault, }; /* * mmap the DMA buffer on RAM */ /** * snd_pcm_lib_default_mmap - Default PCM data mmap function * @substream: PCM substream * @area: VMA * * This is the default mmap handler for PCM data. When mmap pcm_ops is NULL, * this function is invoked implicitly. */ int snd_pcm_lib_default_mmap(struct snd_pcm_substream *substream, struct vm_area_struct *area) { area->vm_flags |= VM_DONTEXPAND | VM_DONTDUMP; if (!substream->ops->page && !snd_dma_buffer_mmap(snd_pcm_get_dma_buf(substream), area)) return 0; /* mmap with fault handler */ area->vm_ops = &snd_pcm_vm_ops_data_fault; return 0; } EXPORT_SYMBOL_GPL(snd_pcm_lib_default_mmap); /* * mmap the DMA buffer on I/O memory area */ #if SNDRV_PCM_INFO_MMAP_IOMEM /** * snd_pcm_lib_mmap_iomem - Default PCM data mmap function for I/O mem * @substream: PCM substream * @area: VMA * * When your hardware uses the iomapped pages as the hardware buffer and * wants to mmap it, pass this function as mmap pcm_ops. Note that this * is supposed to work only on limited architectures. */ int snd_pcm_lib_mmap_iomem(struct snd_pcm_substream *substream, struct vm_area_struct *area) { struct snd_pcm_runtime *runtime = substream->runtime; area->vm_page_prot = pgprot_noncached(area->vm_page_prot); return vm_iomap_memory(area, runtime->dma_addr, runtime->dma_bytes); } EXPORT_SYMBOL(snd_pcm_lib_mmap_iomem); #endif /* SNDRV_PCM_INFO_MMAP */ /* * mmap DMA buffer */ int snd_pcm_mmap_data(struct snd_pcm_substream *substream, struct file *file, struct vm_area_struct *area) { struct snd_pcm_runtime *runtime; long size; unsigned long offset; size_t dma_bytes; int err; if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { if (!(area->vm_flags & (VM_WRITE|VM_READ))) return -EINVAL; } else { if (!(area->vm_flags & VM_READ)) return -EINVAL; } runtime = substream->runtime; if (runtime->status->state == SNDRV_PCM_STATE_OPEN) return -EBADFD; if (!(runtime->info & SNDRV_PCM_INFO_MMAP)) return -ENXIO; if (runtime->access == SNDRV_PCM_ACCESS_RW_INTERLEAVED || runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) return -EINVAL; size = area->vm_end - area->vm_start; offset = area->vm_pgoff << PAGE_SHIFT; dma_bytes = PAGE_ALIGN(runtime->dma_bytes); if ((size_t)size > dma_bytes) return -EINVAL; if (offset > dma_bytes - size) return -EINVAL; area->vm_ops = &snd_pcm_vm_ops_data; area->vm_private_data = substream; if (substream->ops->mmap) err = substream->ops->mmap(substream, area); else err = snd_pcm_lib_default_mmap(substream, area); if (!err) atomic_inc(&substream->mmap_count); return err; } EXPORT_SYMBOL(snd_pcm_mmap_data); static int snd_pcm_mmap(struct file *file, struct vm_area_struct *area) { struct snd_pcm_file * pcm_file; struct snd_pcm_substream *substream; unsigned long offset; pcm_file = file->private_data; substream = pcm_file->substream; if (PCM_RUNTIME_CHECK(substream)) return -ENXIO; offset = area->vm_pgoff << PAGE_SHIFT; switch (offset) { case SNDRV_PCM_MMAP_OFFSET_STATUS_OLD: if (pcm_file->no_compat_mmap || !IS_ENABLED(CONFIG_64BIT)) return -ENXIO; fallthrough; case SNDRV_PCM_MMAP_OFFSET_STATUS_NEW: if (!pcm_status_mmap_allowed(pcm_file)) return -ENXIO; return snd_pcm_mmap_status(substream, file, area); case SNDRV_PCM_MMAP_OFFSET_CONTROL_OLD: if (pcm_file->no_compat_mmap || !IS_ENABLED(CONFIG_64BIT)) return -ENXIO; fallthrough; case SNDRV_PCM_MMAP_OFFSET_CONTROL_NEW: if (!pcm_control_mmap_allowed(pcm_file)) return -ENXIO; return snd_pcm_mmap_control(substream, file, area); default: return snd_pcm_mmap_data(substream, file, area); } return 0; } static int snd_pcm_fasync(int fd, struct file * file, int on) { struct snd_pcm_file * pcm_file; struct snd_pcm_substream *substream; struct snd_pcm_runtime *runtime; pcm_file = file->private_data; substream = pcm_file->substream; if (PCM_RUNTIME_CHECK(substream)) return -ENXIO; runtime = substream->runtime; return fasync_helper(fd, file, on, &runtime->fasync); } /* * ioctl32 compat */ #ifdef CONFIG_COMPAT #include "pcm_compat.c" #else #define snd_pcm_ioctl_compat NULL #endif /* * To be removed helpers to keep binary compatibility */ #ifdef CONFIG_SND_SUPPORT_OLD_API #define __OLD_TO_NEW_MASK(x) ((x&7)|((x&0x07fffff8)<<5)) #define __NEW_TO_OLD_MASK(x) ((x&7)|((x&0xffffff00)>>5)) static void snd_pcm_hw_convert_from_old_params(struct snd_pcm_hw_params *params, struct snd_pcm_hw_params_old *oparams) { unsigned int i; memset(params, 0, sizeof(*params)); params->flags = oparams->flags; for (i = 0; i < ARRAY_SIZE(oparams->masks); i++) params->masks[i].bits[0] = oparams->masks[i]; memcpy(params->intervals, oparams->intervals, sizeof(oparams->intervals)); params->rmask = __OLD_TO_NEW_MASK(oparams->rmask); params->cmask = __OLD_TO_NEW_MASK(oparams->cmask); params->info = oparams->info; params->msbits = oparams->msbits; params->rate_num = oparams->rate_num; params->rate_den = oparams->rate_den; params->fifo_size = oparams->fifo_size; } static void snd_pcm_hw_convert_to_old_params(struct snd_pcm_hw_params_old *oparams, struct snd_pcm_hw_params *params) { unsigned int i; memset(oparams, 0, sizeof(*oparams)); oparams->flags = params->flags; for (i = 0; i < ARRAY_SIZE(oparams->masks); i++) oparams->masks[i] = params->masks[i].bits[0]; memcpy(oparams->intervals, params->intervals, sizeof(oparams->intervals)); oparams->rmask = __NEW_TO_OLD_MASK(params->rmask); oparams->cmask = __NEW_TO_OLD_MASK(params->cmask); oparams->info = params->info; oparams->msbits = params->msbits; oparams->rate_num = params->rate_num; oparams->rate_den = params->rate_den; oparams->fifo_size = params->fifo_size; } static int snd_pcm_hw_refine_old_user(struct snd_pcm_substream *substream, struct snd_pcm_hw_params_old __user * _oparams) { struct snd_pcm_hw_params *params; struct snd_pcm_hw_params_old *oparams = NULL; int err; params = kmalloc(sizeof(*params), GFP_KERNEL); if (!params) return -ENOMEM; oparams = memdup_user(_oparams, sizeof(*oparams)); if (IS_ERR(oparams)) { err = PTR_ERR(oparams); goto out; } snd_pcm_hw_convert_from_old_params(params, oparams); err = snd_pcm_hw_refine(substream, params); if (err < 0) goto out_old; err = fixup_unreferenced_params(substream, params); if (err < 0) goto out_old; snd_pcm_hw_convert_to_old_params(oparams, params); if (copy_to_user(_oparams, oparams, sizeof(*oparams))) err = -EFAULT; out_old: kfree(oparams); out: kfree(params); return err; } static int snd_pcm_hw_params_old_user(struct snd_pcm_substream *substream, struct snd_pcm_hw_params_old __user * _oparams) { struct snd_pcm_hw_params *params; struct snd_pcm_hw_params_old *oparams = NULL; int err; params = kmalloc(sizeof(*params), GFP_KERNEL); if (!params) return -ENOMEM; oparams = memdup_user(_oparams, sizeof(*oparams)); if (IS_ERR(oparams)) { err = PTR_ERR(oparams); goto out; } snd_pcm_hw_convert_from_old_params(params, oparams); err = snd_pcm_hw_params(substream, params); if (err < 0) goto out_old; snd_pcm_hw_convert_to_old_params(oparams, params); if (copy_to_user(_oparams, oparams, sizeof(*oparams))) err = -EFAULT; out_old: kfree(oparams); out: kfree(params); return err; } #endif /* CONFIG_SND_SUPPORT_OLD_API */ #ifndef CONFIG_MMU static unsigned long snd_pcm_get_unmapped_area(struct file *file, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags) { struct snd_pcm_file *pcm_file = file->private_data; struct snd_pcm_substream *substream = pcm_file->substream; struct snd_pcm_runtime *runtime = substream->runtime; unsigned long offset = pgoff << PAGE_SHIFT; switch (offset) { case SNDRV_PCM_MMAP_OFFSET_STATUS_NEW: return (unsigned long)runtime->status; case SNDRV_PCM_MMAP_OFFSET_CONTROL_NEW: return (unsigned long)runtime->control; default: return (unsigned long)runtime->dma_area + offset; } } #else # define snd_pcm_get_unmapped_area NULL #endif /* * Register section */ const struct file_operations snd_pcm_f_ops[2] = { { .owner = THIS_MODULE, .write = snd_pcm_write, .write_iter = snd_pcm_writev, .open = snd_pcm_playback_open, .release = snd_pcm_release, .llseek = no_llseek, .poll = snd_pcm_poll, .unlocked_ioctl = snd_pcm_ioctl, .compat_ioctl = snd_pcm_ioctl_compat, .mmap = snd_pcm_mmap, .fasync = snd_pcm_fasync, .get_unmapped_area = snd_pcm_get_unmapped_area, }, { .owner = THIS_MODULE, .read = snd_pcm_read, .read_iter = snd_pcm_readv, .open = snd_pcm_capture_open, .release = snd_pcm_release, .llseek = no_llseek, .poll = snd_pcm_poll, .unlocked_ioctl = snd_pcm_ioctl, .compat_ioctl = snd_pcm_ioctl_compat, .mmap = snd_pcm_mmap, .fasync = snd_pcm_fasync, .get_unmapped_area = snd_pcm_get_unmapped_area, } };
28.053907
103
0.741772
cfc8762c55f4aeaf6d2b1a0e0801f05f58ee992b
72,248
c
C
linux-5.0.1/drivers/net/wireless/realtek/rtlwifi/rtl8188ee/hw.c
Ponny035/LFS
7ae2280072d71f43e395149d0ad0692483a24b70
[ "Unlicense" ]
1
2020-09-20T03:48:15.000Z
2020-09-20T03:48:15.000Z
drivers/net/wireless/realtek/rtlwifi/rtl8188ee/hw.c
YFShiftFinance/Unix
b82f0634af26793369af6df5fa9d374d0e09a54c
[ "MIT" ]
null
null
null
drivers/net/wireless/realtek/rtlwifi/rtl8188ee/hw.c
YFShiftFinance/Unix
b82f0634af26793369af6df5fa9d374d0e09a54c
[ "MIT" ]
null
null
null
/****************************************************************************** * * Copyright(c) 2009-2013 Realtek Corporation. * * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 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. * * The full GNU General Public License is included in this distribution in the * file called LICENSE. * * Contact Information: * wlanfae <wlanfae@realtek.com> * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park, * Hsinchu 300, Taiwan. * * Larry Finger <Larry.Finger@lwfinger.net> * *****************************************************************************/ #include "../wifi.h" #include "../efuse.h" #include "../base.h" #include "../regd.h" #include "../cam.h" #include "../ps.h" #include "../pci.h" #include "../pwrseqcmd.h" #include "reg.h" #include "def.h" #include "phy.h" #include "dm.h" #include "fw.h" #include "led.h" #include "hw.h" #include "pwrseq.h" #define LLT_CONFIG 5 static void _rtl88ee_set_bcn_ctrl_reg(struct ieee80211_hw *hw, u8 set_bits, u8 clear_bits) { struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); struct rtl_priv *rtlpriv = rtl_priv(hw); rtlpci->reg_bcn_ctrl_val |= set_bits; rtlpci->reg_bcn_ctrl_val &= ~clear_bits; rtl_write_byte(rtlpriv, REG_BCN_CTRL, (u8) rtlpci->reg_bcn_ctrl_val); } static void _rtl88ee_stop_tx_beacon(struct ieee80211_hw *hw) { struct rtl_priv *rtlpriv = rtl_priv(hw); u8 tmp1byte; tmp1byte = rtl_read_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2); rtl_write_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2, tmp1byte & (~BIT(6))); rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 1, 0x64); tmp1byte = rtl_read_byte(rtlpriv, REG_TBTT_PROHIBIT + 2); tmp1byte &= ~(BIT(0)); rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 2, tmp1byte); } static void _rtl88ee_resume_tx_beacon(struct ieee80211_hw *hw) { struct rtl_priv *rtlpriv = rtl_priv(hw); u8 tmp1byte; tmp1byte = rtl_read_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2); rtl_write_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2, tmp1byte | BIT(6)); rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 1, 0xff); tmp1byte = rtl_read_byte(rtlpriv, REG_TBTT_PROHIBIT + 2); tmp1byte |= BIT(0); rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 2, tmp1byte); } static void _rtl88ee_enable_bcn_sub_func(struct ieee80211_hw *hw) { _rtl88ee_set_bcn_ctrl_reg(hw, 0, BIT(1)); } static void _rtl88ee_return_beacon_queue_skb(struct ieee80211_hw *hw) { struct rtl_priv *rtlpriv = rtl_priv(hw); struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); struct rtl8192_tx_ring *ring = &rtlpci->tx_ring[BEACON_QUEUE]; unsigned long flags; spin_lock_irqsave(&rtlpriv->locks.irq_th_lock, flags); while (skb_queue_len(&ring->queue)) { struct rtl_tx_desc *entry = &ring->desc[ring->idx]; struct sk_buff *skb = __skb_dequeue(&ring->queue); pci_unmap_single(rtlpci->pdev, rtlpriv->cfg->ops->get_desc( hw, (u8 *)entry, true, HW_DESC_TXBUFF_ADDR), skb->len, PCI_DMA_TODEVICE); kfree_skb(skb); ring->idx = (ring->idx + 1) % ring->entries; } spin_unlock_irqrestore(&rtlpriv->locks.irq_th_lock, flags); } static void _rtl88ee_disable_bcn_sub_func(struct ieee80211_hw *hw) { _rtl88ee_set_bcn_ctrl_reg(hw, BIT(1), 0); } static void _rtl88ee_set_fw_clock_on(struct ieee80211_hw *hw, u8 rpwm_val, bool b_need_turn_off_ckk) { struct rtl_priv *rtlpriv = rtl_priv(hw); struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); bool b_support_remote_wake_up; u32 count = 0, isr_regaddr, content; bool schedule_timer = b_need_turn_off_ckk; rtlpriv->cfg->ops->get_hw_reg(hw, HAL_DEF_WOWLAN, (u8 *)(&b_support_remote_wake_up)); if (!rtlhal->fw_ready) return; if (!rtlpriv->psc.fw_current_inpsmode) return; while (1) { spin_lock_bh(&rtlpriv->locks.fw_ps_lock); if (rtlhal->fw_clk_change_in_progress) { while (rtlhal->fw_clk_change_in_progress) { spin_unlock_bh(&rtlpriv->locks.fw_ps_lock); count++; udelay(100); if (count > 1000) return; spin_lock_bh(&rtlpriv->locks.fw_ps_lock); } spin_unlock_bh(&rtlpriv->locks.fw_ps_lock); } else { rtlhal->fw_clk_change_in_progress = false; spin_unlock_bh(&rtlpriv->locks.fw_ps_lock); break; } } if (IS_IN_LOW_POWER_STATE_88E(rtlhal->fw_ps_state)) { rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_SET_RPWM, &rpwm_val); if (FW_PS_IS_ACK(rpwm_val)) { isr_regaddr = REG_HISR; content = rtl_read_dword(rtlpriv, isr_regaddr); while (!(content & IMR_CPWM) && (count < 500)) { udelay(50); count++; content = rtl_read_dword(rtlpriv, isr_regaddr); } if (content & IMR_CPWM) { rtl_write_word(rtlpriv, isr_regaddr, 0x0100); rtlhal->fw_ps_state = FW_PS_STATE_RF_ON_88E; RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD, "Receive CPWM INT!!! Set pHalData->FwPSState = %X\n", rtlhal->fw_ps_state); } } spin_lock_bh(&rtlpriv->locks.fw_ps_lock); rtlhal->fw_clk_change_in_progress = false; spin_unlock_bh(&rtlpriv->locks.fw_ps_lock); if (schedule_timer) { mod_timer(&rtlpriv->works.fw_clockoff_timer, jiffies + MSECS(10)); } } else { spin_lock_bh(&rtlpriv->locks.fw_ps_lock); rtlhal->fw_clk_change_in_progress = false; spin_unlock_bh(&rtlpriv->locks.fw_ps_lock); } } static void _rtl88ee_set_fw_clock_off(struct ieee80211_hw *hw, u8 rpwm_val) { struct rtl_priv *rtlpriv = rtl_priv(hw); struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); struct rtl8192_tx_ring *ring; enum rf_pwrstate rtstate; bool schedule_timer = false; u8 queue; if (!rtlhal->fw_ready) return; if (!rtlpriv->psc.fw_current_inpsmode) return; if (!rtlhal->allow_sw_to_change_hwclc) return; rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_RF_STATE, (u8 *)(&rtstate)); if (rtstate == ERFOFF || rtlpriv->psc.inactive_pwrstate == ERFOFF) return; for (queue = 0; queue < RTL_PCI_MAX_TX_QUEUE_COUNT; queue++) { ring = &rtlpci->tx_ring[queue]; if (skb_queue_len(&ring->queue)) { schedule_timer = true; break; } } if (schedule_timer) { mod_timer(&rtlpriv->works.fw_clockoff_timer, jiffies + MSECS(10)); return; } if (FW_PS_STATE(rtlhal->fw_ps_state) != FW_PS_STATE_RF_OFF_LOW_PWR_88E) { spin_lock_bh(&rtlpriv->locks.fw_ps_lock); if (!rtlhal->fw_clk_change_in_progress) { rtlhal->fw_clk_change_in_progress = true; spin_unlock_bh(&rtlpriv->locks.fw_ps_lock); rtlhal->fw_ps_state = FW_PS_STATE(rpwm_val); rtl_write_word(rtlpriv, REG_HISR, 0x0100); rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SET_RPWM, &rpwm_val); spin_lock_bh(&rtlpriv->locks.fw_ps_lock); rtlhal->fw_clk_change_in_progress = false; spin_unlock_bh(&rtlpriv->locks.fw_ps_lock); } else { spin_unlock_bh(&rtlpriv->locks.fw_ps_lock); mod_timer(&rtlpriv->works.fw_clockoff_timer, jiffies + MSECS(10)); } } } static void _rtl88ee_set_fw_ps_rf_on(struct ieee80211_hw *hw) { u8 rpwm_val = 0; rpwm_val |= (FW_PS_STATE_RF_OFF_88E | FW_PS_ACK); _rtl88ee_set_fw_clock_on(hw, rpwm_val, true); } static void _rtl88ee_set_fw_ps_rf_off_low_power(struct ieee80211_hw *hw) { u8 rpwm_val = 0; rpwm_val |= FW_PS_STATE_RF_OFF_LOW_PWR_88E; _rtl88ee_set_fw_clock_off(hw, rpwm_val); } void rtl88ee_fw_clk_off_timer_callback(struct timer_list *t) { struct rtl_priv *rtlpriv = from_timer(rtlpriv, t, works.fw_clockoff_timer); struct ieee80211_hw *hw = rtlpriv->hw; _rtl88ee_set_fw_ps_rf_off_low_power(hw); } static void _rtl88ee_fwlps_leave(struct ieee80211_hw *hw) { struct rtl_priv *rtlpriv = rtl_priv(hw); struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); bool fw_current_inps = false; u8 rpwm_val = 0, fw_pwrmode = FW_PS_ACTIVE_MODE; if (ppsc->low_power_enable) { rpwm_val = (FW_PS_STATE_ALL_ON_88E|FW_PS_ACK);/* RF on */ _rtl88ee_set_fw_clock_on(hw, rpwm_val, false); rtlhal->allow_sw_to_change_hwclc = false; rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_H2C_FW_PWRMODE, &fw_pwrmode); rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_FW_PSMODE_STATUS, (u8 *)(&fw_current_inps)); } else { rpwm_val = FW_PS_STATE_ALL_ON_88E; /* RF on */ rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SET_RPWM, &rpwm_val); rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_H2C_FW_PWRMODE, &fw_pwrmode); rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_FW_PSMODE_STATUS, (u8 *)(&fw_current_inps)); } } static void _rtl88ee_fwlps_enter(struct ieee80211_hw *hw) { struct rtl_priv *rtlpriv = rtl_priv(hw); struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); bool fw_current_inps = true; u8 rpwm_val; if (ppsc->low_power_enable) { rpwm_val = FW_PS_STATE_RF_OFF_LOW_PWR_88E; /* RF off */ rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_FW_PSMODE_STATUS, (u8 *)(&fw_current_inps)); rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_H2C_FW_PWRMODE, &ppsc->fwctrl_psmode); rtlhal->allow_sw_to_change_hwclc = true; _rtl88ee_set_fw_clock_off(hw, rpwm_val); } else { rpwm_val = FW_PS_STATE_RF_OFF_88E; /* RF off */ rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_FW_PSMODE_STATUS, (u8 *)(&fw_current_inps)); rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_H2C_FW_PWRMODE, &ppsc->fwctrl_psmode); rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SET_RPWM, &rpwm_val); } } void rtl88ee_get_hw_reg(struct ieee80211_hw *hw, u8 variable, u8 *val) { struct rtl_priv *rtlpriv = rtl_priv(hw); struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); switch (variable) { case HW_VAR_RCR: *((u32 *)(val)) = rtlpci->receive_config; break; case HW_VAR_RF_STATE: *((enum rf_pwrstate *)(val)) = ppsc->rfpwr_state; break; case HW_VAR_FWLPS_RF_ON:{ enum rf_pwrstate rfstate; u32 val_rcr; rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_RF_STATE, (u8 *)(&rfstate)); if (rfstate == ERFOFF) { *((bool *)(val)) = true; } else { val_rcr = rtl_read_dword(rtlpriv, REG_RCR); val_rcr &= 0x00070000; if (val_rcr) *((bool *)(val)) = false; else *((bool *)(val)) = true; } break; } case HW_VAR_FW_PSMODE_STATUS: *((bool *)(val)) = ppsc->fw_current_inpsmode; break; case HW_VAR_CORRECT_TSF:{ u64 tsf; u32 *ptsf_low = (u32 *)&tsf; u32 *ptsf_high = ((u32 *)&tsf) + 1; *ptsf_high = rtl_read_dword(rtlpriv, (REG_TSFTR + 4)); *ptsf_low = rtl_read_dword(rtlpriv, REG_TSFTR); *((u64 *)(val)) = tsf; break; } case HAL_DEF_WOWLAN: break; default: pr_err("switch case %#x not processed\n", variable); break; } } void rtl88ee_set_hw_reg(struct ieee80211_hw *hw, u8 variable, u8 *val) { struct rtl_priv *rtlpriv = rtl_priv(hw); struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); u8 idx; switch (variable) { case HW_VAR_ETHER_ADDR: for (idx = 0; idx < ETH_ALEN; idx++) { rtl_write_byte(rtlpriv, (REG_MACID + idx), val[idx]); } break; case HW_VAR_BASIC_RATE:{ u16 b_rate_cfg = ((u16 *)val)[0]; u8 rate_index = 0; b_rate_cfg = b_rate_cfg & 0x15f; b_rate_cfg |= 0x01; rtl_write_byte(rtlpriv, REG_RRSR, b_rate_cfg & 0xff); rtl_write_byte(rtlpriv, REG_RRSR + 1, (b_rate_cfg >> 8) & 0xff); while (b_rate_cfg > 0x1) { b_rate_cfg = (b_rate_cfg >> 1); rate_index++; } rtl_write_byte(rtlpriv, REG_INIRTS_RATE_SEL, rate_index); break; } case HW_VAR_BSSID: for (idx = 0; idx < ETH_ALEN; idx++) { rtl_write_byte(rtlpriv, (REG_BSSID + idx), val[idx]); } break; case HW_VAR_SIFS: rtl_write_byte(rtlpriv, REG_SIFS_CTX + 1, val[0]); rtl_write_byte(rtlpriv, REG_SIFS_TRX + 1, val[1]); rtl_write_byte(rtlpriv, REG_SPEC_SIFS + 1, val[0]); rtl_write_byte(rtlpriv, REG_MAC_SPEC_SIFS + 1, val[0]); if (!mac->ht_enable) rtl_write_word(rtlpriv, REG_RESP_SIFS_OFDM, 0x0e0e); else rtl_write_word(rtlpriv, REG_RESP_SIFS_OFDM, *((u16 *)val)); break; case HW_VAR_SLOT_TIME:{ u8 e_aci; RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD, "HW_VAR_SLOT_TIME %x\n", val[0]); rtl_write_byte(rtlpriv, REG_SLOT, val[0]); for (e_aci = 0; e_aci < AC_MAX; e_aci++) { rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_AC_PARAM, &e_aci); } break; } case HW_VAR_ACK_PREAMBLE:{ u8 reg_tmp; u8 short_preamble = (bool)*val; reg_tmp = rtl_read_byte(rtlpriv, REG_TRXPTCL_CTL+2); if (short_preamble) { reg_tmp |= 0x02; rtl_write_byte(rtlpriv, REG_TRXPTCL_CTL + 2, reg_tmp); } else { reg_tmp |= 0xFD; rtl_write_byte(rtlpriv, REG_TRXPTCL_CTL + 2, reg_tmp); } break; } case HW_VAR_WPA_CONFIG: rtl_write_byte(rtlpriv, REG_SECCFG, *val); break; case HW_VAR_AMPDU_MIN_SPACE:{ u8 min_spacing_to_set; u8 sec_min_space; min_spacing_to_set = *val; if (min_spacing_to_set <= 7) { sec_min_space = 0; if (min_spacing_to_set < sec_min_space) min_spacing_to_set = sec_min_space; mac->min_space_cfg = ((mac->min_space_cfg & 0xf8) | min_spacing_to_set); *val = min_spacing_to_set; RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD, "Set HW_VAR_AMPDU_MIN_SPACE: %#x\n", mac->min_space_cfg); rtl_write_byte(rtlpriv, REG_AMPDU_MIN_SPACE, mac->min_space_cfg); } break; } case HW_VAR_SHORTGI_DENSITY:{ u8 density_to_set; density_to_set = *val; mac->min_space_cfg |= (density_to_set << 3); RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD, "Set HW_VAR_SHORTGI_DENSITY: %#x\n", mac->min_space_cfg); rtl_write_byte(rtlpriv, REG_AMPDU_MIN_SPACE, mac->min_space_cfg); break; } case HW_VAR_AMPDU_FACTOR:{ u8 regtoset_normal[4] = { 0x41, 0xa8, 0x72, 0xb9 }; u8 factor_toset; u8 *p_regtoset = NULL; u8 index = 0; p_regtoset = regtoset_normal; factor_toset = *val; if (factor_toset <= 3) { factor_toset = (1 << (factor_toset + 2)); if (factor_toset > 0xf) factor_toset = 0xf; for (index = 0; index < 4; index++) { if ((p_regtoset[index] & 0xf0) > (factor_toset << 4)) p_regtoset[index] = (p_regtoset[index] & 0x0f) | (factor_toset << 4); if ((p_regtoset[index] & 0x0f) > factor_toset) p_regtoset[index] = (p_regtoset[index] & 0xf0) | (factor_toset); rtl_write_byte(rtlpriv, (REG_AGGLEN_LMT + index), p_regtoset[index]); } RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD, "Set HW_VAR_AMPDU_FACTOR: %#x\n", factor_toset); } break; } case HW_VAR_AC_PARAM:{ u8 e_aci = *val; rtl88e_dm_init_edca_turbo(hw); if (rtlpci->acm_method != EACMWAY2_SW) rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_ACM_CTRL, &e_aci); break; } case HW_VAR_ACM_CTRL:{ u8 e_aci = *val; union aci_aifsn *p_aci_aifsn = (union aci_aifsn *)(&(mac->ac[0].aifs)); u8 acm = p_aci_aifsn->f.acm; u8 acm_ctrl = rtl_read_byte(rtlpriv, REG_ACMHWCTRL); acm_ctrl = acm_ctrl | ((rtlpci->acm_method == 2) ? 0x0 : 0x1); if (acm) { switch (e_aci) { case AC0_BE: acm_ctrl |= ACMHW_BEQEN; break; case AC2_VI: acm_ctrl |= ACMHW_VIQEN; break; case AC3_VO: acm_ctrl |= ACMHW_VOQEN; break; default: RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING, "HW_VAR_ACM_CTRL acm set failed: eACI is %d\n", acm); break; } } else { switch (e_aci) { case AC0_BE: acm_ctrl &= (~ACMHW_BEQEN); break; case AC2_VI: acm_ctrl &= (~ACMHW_VIQEN); break; case AC3_VO: acm_ctrl &= (~ACMHW_VOQEN); break; default: pr_err("switch case %#x not processed\n", e_aci); break; } } RT_TRACE(rtlpriv, COMP_QOS, DBG_TRACE, "SetHwReg8190pci(): [HW_VAR_ACM_CTRL] Write 0x%X\n", acm_ctrl); rtl_write_byte(rtlpriv, REG_ACMHWCTRL, acm_ctrl); break; } case HW_VAR_RCR: rtl_write_dword(rtlpriv, REG_RCR, ((u32 *)(val))[0]); rtlpci->receive_config = ((u32 *)(val))[0]; break; case HW_VAR_RETRY_LIMIT:{ u8 retry_limit = *val; rtl_write_word(rtlpriv, REG_RL, retry_limit << RETRY_LIMIT_SHORT_SHIFT | retry_limit << RETRY_LIMIT_LONG_SHIFT); break; } case HW_VAR_DUAL_TSF_RST: rtl_write_byte(rtlpriv, REG_DUAL_TSF_RST, (BIT(0) | BIT(1))); break; case HW_VAR_EFUSE_BYTES: rtlefuse->efuse_usedbytes = *((u16 *)val); break; case HW_VAR_EFUSE_USAGE: rtlefuse->efuse_usedpercentage = *val; break; case HW_VAR_IO_CMD: rtl88e_phy_set_io_cmd(hw, (*(enum io_type *)val)); break; case HW_VAR_SET_RPWM:{ u8 rpwm_val; rpwm_val = rtl_read_byte(rtlpriv, REG_PCIE_HRPWM); udelay(1); if (rpwm_val & BIT(7)) { rtl_write_byte(rtlpriv, REG_PCIE_HRPWM, *val); } else { rtl_write_byte(rtlpriv, REG_PCIE_HRPWM, *val | BIT(7)); } break; } case HW_VAR_H2C_FW_PWRMODE: rtl88e_set_fw_pwrmode_cmd(hw, *val); break; case HW_VAR_FW_PSMODE_STATUS: ppsc->fw_current_inpsmode = *((bool *)val); break; case HW_VAR_RESUME_CLK_ON: _rtl88ee_set_fw_ps_rf_on(hw); break; case HW_VAR_FW_LPS_ACTION:{ bool enter_fwlps = *((bool *)val); if (enter_fwlps) _rtl88ee_fwlps_enter(hw); else _rtl88ee_fwlps_leave(hw); break; } case HW_VAR_H2C_FW_JOINBSSRPT:{ u8 mstatus = *val; u8 tmp_regcr, tmp_reg422, bcnvalid_reg; u8 count = 0, dlbcn_count = 0; bool b_recover = false; if (mstatus == RT_MEDIA_CONNECT) { rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_AID, NULL); tmp_regcr = rtl_read_byte(rtlpriv, REG_CR + 1); rtl_write_byte(rtlpriv, REG_CR + 1, (tmp_regcr | BIT(0))); _rtl88ee_set_bcn_ctrl_reg(hw, 0, BIT(3)); _rtl88ee_set_bcn_ctrl_reg(hw, BIT(4), 0); tmp_reg422 = rtl_read_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2); rtl_write_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2, tmp_reg422 & (~BIT(6))); if (tmp_reg422 & BIT(6)) b_recover = true; do { bcnvalid_reg = rtl_read_byte(rtlpriv, REG_TDECTRL+2); rtl_write_byte(rtlpriv, REG_TDECTRL+2, (bcnvalid_reg | BIT(0))); _rtl88ee_return_beacon_queue_skb(hw); rtl88e_set_fw_rsvdpagepkt(hw, 0); bcnvalid_reg = rtl_read_byte(rtlpriv, REG_TDECTRL+2); count = 0; while (!(bcnvalid_reg & BIT(0)) && count < 20) { count++; udelay(10); bcnvalid_reg = rtl_read_byte(rtlpriv, REG_TDECTRL+2); } dlbcn_count++; } while (!(bcnvalid_reg & BIT(0)) && dlbcn_count < 5); if (bcnvalid_reg & BIT(0)) rtl_write_byte(rtlpriv, REG_TDECTRL+2, BIT(0)); _rtl88ee_set_bcn_ctrl_reg(hw, BIT(3), 0); _rtl88ee_set_bcn_ctrl_reg(hw, 0, BIT(4)); if (b_recover) { rtl_write_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2, tmp_reg422); } rtl_write_byte(rtlpriv, REG_CR + 1, (tmp_regcr & ~(BIT(0)))); } rtl88e_set_fw_joinbss_report_cmd(hw, (*(u8 *)val)); break; } case HW_VAR_H2C_FW_P2P_PS_OFFLOAD: rtl88e_set_p2p_ps_offload_cmd(hw, *val); break; case HW_VAR_AID:{ u16 u2btmp; u2btmp = rtl_read_word(rtlpriv, REG_BCN_PSR_RPT); u2btmp &= 0xC000; rtl_write_word(rtlpriv, REG_BCN_PSR_RPT, (u2btmp | mac->assoc_id)); break; } case HW_VAR_CORRECT_TSF:{ u8 btype_ibss = *val; if (btype_ibss) _rtl88ee_stop_tx_beacon(hw); _rtl88ee_set_bcn_ctrl_reg(hw, 0, BIT(3)); rtl_write_dword(rtlpriv, REG_TSFTR, (u32)(mac->tsf & 0xffffffff)); rtl_write_dword(rtlpriv, REG_TSFTR + 4, (u32)((mac->tsf >> 32) & 0xffffffff)); _rtl88ee_set_bcn_ctrl_reg(hw, BIT(3), 0); if (btype_ibss) _rtl88ee_resume_tx_beacon(hw); break; } case HW_VAR_KEEP_ALIVE: { u8 array[2]; array[0] = 0xff; array[1] = *((u8 *)val); rtl88e_fill_h2c_cmd(hw, H2C_88E_KEEP_ALIVE_CTRL, 2, array); break; } default: pr_err("switch case %#x not processed\n", variable); break; } } static bool _rtl88ee_llt_write(struct ieee80211_hw *hw, u32 address, u32 data) { struct rtl_priv *rtlpriv = rtl_priv(hw); bool status = true; long count = 0; u32 value = _LLT_INIT_ADDR(address) | _LLT_INIT_DATA(data) | _LLT_OP(_LLT_WRITE_ACCESS); rtl_write_dword(rtlpriv, REG_LLT_INIT, value); do { value = rtl_read_dword(rtlpriv, REG_LLT_INIT); if (_LLT_NO_ACTIVE == _LLT_OP_VALUE(value)) break; if (count > POLLING_LLT_THRESHOLD) { pr_err("Failed to polling write LLT done at address %d!\n", address); status = false; break; } } while (++count); return status; } static bool _rtl88ee_llt_table_init(struct ieee80211_hw *hw) { struct rtl_priv *rtlpriv = rtl_priv(hw); unsigned short i; u8 txpktbuf_bndy; u8 maxpage; bool status; maxpage = 0xAF; txpktbuf_bndy = 0xAB; rtl_write_byte(rtlpriv, REG_RQPN_NPQ, 0x01); rtl_write_dword(rtlpriv, REG_RQPN, 0x80730d29); /*0x2600 MaxRxBuff=10k-max(TxReportSize(64*8), WOLPattern(16*24)) */ rtl_write_dword(rtlpriv, REG_TRXFF_BNDY, (0x25FF0000 | txpktbuf_bndy)); rtl_write_byte(rtlpriv, REG_TDECTRL + 1, txpktbuf_bndy); rtl_write_byte(rtlpriv, REG_TXPKTBUF_BCNQ_BDNY, txpktbuf_bndy); rtl_write_byte(rtlpriv, REG_TXPKTBUF_MGQ_BDNY, txpktbuf_bndy); rtl_write_byte(rtlpriv, 0x45D, txpktbuf_bndy); rtl_write_byte(rtlpriv, REG_PBP, 0x11); rtl_write_byte(rtlpriv, REG_RX_DRVINFO_SZ, 0x4); for (i = 0; i < (txpktbuf_bndy - 1); i++) { status = _rtl88ee_llt_write(hw, i, i + 1); if (true != status) return status; } status = _rtl88ee_llt_write(hw, (txpktbuf_bndy - 1), 0xFF); if (true != status) return status; for (i = txpktbuf_bndy; i < maxpage; i++) { status = _rtl88ee_llt_write(hw, i, (i + 1)); if (true != status) return status; } status = _rtl88ee_llt_write(hw, maxpage, txpktbuf_bndy); if (true != status) return status; return true; } static void _rtl88ee_gen_refresh_led_state(struct ieee80211_hw *hw) { struct rtl_priv *rtlpriv = rtl_priv(hw); struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); struct rtl_led *pled0 = &rtlpriv->ledctl.sw_led0; if (rtlpriv->rtlhal.up_first_time) return; if (ppsc->rfoff_reason == RF_CHANGE_BY_IPS) rtl88ee_sw_led_on(hw, pled0); else if (ppsc->rfoff_reason == RF_CHANGE_BY_INIT) rtl88ee_sw_led_on(hw, pled0); else rtl88ee_sw_led_off(hw, pled0); } static bool _rtl88ee_init_mac(struct ieee80211_hw *hw) { struct rtl_priv *rtlpriv = rtl_priv(hw); struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); u8 bytetmp; u16 wordtmp; /*Disable XTAL OUTPUT for power saving. YJ,add,111206. */ bytetmp = rtl_read_byte(rtlpriv, REG_XCK_OUT_CTRL) & (~BIT(0)); rtl_write_byte(rtlpriv, REG_XCK_OUT_CTRL, bytetmp); /*Auto Power Down to CHIP-off State*/ bytetmp = rtl_read_byte(rtlpriv, REG_APS_FSMCO + 1) & (~BIT(7)); rtl_write_byte(rtlpriv, REG_APS_FSMCO + 1, bytetmp); rtl_write_byte(rtlpriv, REG_RSV_CTRL, 0x00); /* HW Power on sequence */ if (!rtl_hal_pwrseqcmdparsing(rtlpriv, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_PCI_MSK, RTL8188EE_NIC_ENABLE_FLOW)) { RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "init MAC Fail as rtl_hal_pwrseqcmdparsing\n"); return false; } bytetmp = rtl_read_byte(rtlpriv, REG_APS_FSMCO) | BIT(4); rtl_write_byte(rtlpriv, REG_APS_FSMCO, bytetmp); bytetmp = rtl_read_byte(rtlpriv, REG_PCIE_CTRL_REG+2); rtl_write_byte(rtlpriv, REG_PCIE_CTRL_REG+2, bytetmp|BIT(2)); bytetmp = rtl_read_byte(rtlpriv, REG_WATCH_DOG+1); rtl_write_byte(rtlpriv, REG_WATCH_DOG+1, bytetmp|BIT(7)); bytetmp = rtl_read_byte(rtlpriv, REG_AFE_XTAL_CTRL_EXT+1); rtl_write_byte(rtlpriv, REG_AFE_XTAL_CTRL_EXT+1, bytetmp|BIT(1)); bytetmp = rtl_read_byte(rtlpriv, REG_TX_RPT_CTRL); rtl_write_byte(rtlpriv, REG_TX_RPT_CTRL, bytetmp|BIT(1)|BIT(0)); rtl_write_byte(rtlpriv, REG_TX_RPT_CTRL+1, 2); rtl_write_word(rtlpriv, REG_TX_RPT_TIME, 0xcdf0); /*Add for wake up online*/ bytetmp = rtl_read_byte(rtlpriv, REG_SYS_CLKR); rtl_write_byte(rtlpriv, REG_SYS_CLKR, bytetmp|BIT(3)); bytetmp = rtl_read_byte(rtlpriv, REG_GPIO_MUXCFG+1); rtl_write_byte(rtlpriv, REG_GPIO_MUXCFG+1, (bytetmp & (~BIT(4)))); rtl_write_byte(rtlpriv, 0x367, 0x80); rtl_write_word(rtlpriv, REG_CR, 0x2ff); rtl_write_byte(rtlpriv, REG_CR+1, 0x06); rtl_write_byte(rtlpriv, MSR, 0x00); if (!rtlhal->mac_func_enable) { if (_rtl88ee_llt_table_init(hw) == false) { RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "LLT table init fail\n"); return false; } } rtl_write_dword(rtlpriv, REG_HISR, 0xffffffff); rtl_write_dword(rtlpriv, REG_HISRE, 0xffffffff); wordtmp = rtl_read_word(rtlpriv, REG_TRXDMA_CTRL); wordtmp &= 0xf; wordtmp |= 0xE771; rtl_write_word(rtlpriv, REG_TRXDMA_CTRL, wordtmp); rtl_write_dword(rtlpriv, REG_RCR, rtlpci->receive_config); rtl_write_word(rtlpriv, REG_RXFLTMAP2, 0xffff); rtl_write_dword(rtlpriv, REG_TCR, rtlpci->transmit_config); rtl_write_dword(rtlpriv, REG_BCNQ_DESA, ((u64) rtlpci->tx_ring[BEACON_QUEUE].dma) & DMA_BIT_MASK(32)); rtl_write_dword(rtlpriv, REG_MGQ_DESA, (u64) rtlpci->tx_ring[MGNT_QUEUE].dma & DMA_BIT_MASK(32)); rtl_write_dword(rtlpriv, REG_VOQ_DESA, (u64) rtlpci->tx_ring[VO_QUEUE].dma & DMA_BIT_MASK(32)); rtl_write_dword(rtlpriv, REG_VIQ_DESA, (u64) rtlpci->tx_ring[VI_QUEUE].dma & DMA_BIT_MASK(32)); rtl_write_dword(rtlpriv, REG_BEQ_DESA, (u64) rtlpci->tx_ring[BE_QUEUE].dma & DMA_BIT_MASK(32)); rtl_write_dword(rtlpriv, REG_BKQ_DESA, (u64) rtlpci->tx_ring[BK_QUEUE].dma & DMA_BIT_MASK(32)); rtl_write_dword(rtlpriv, REG_HQ_DESA, (u64) rtlpci->tx_ring[HIGH_QUEUE].dma & DMA_BIT_MASK(32)); rtl_write_dword(rtlpriv, REG_RX_DESA, (u64) rtlpci->rx_ring[RX_MPDU_QUEUE].dma & DMA_BIT_MASK(32)); /* if we want to support 64 bit DMA, we should set it here, * but now we do not support 64 bit DMA */ rtl_write_dword(rtlpriv, REG_INT_MIG, 0); rtl_write_dword(rtlpriv, REG_MCUTST_1, 0x0); rtl_write_byte(rtlpriv, REG_PCIE_CTRL_REG+1, 0);/*Enable RX DMA */ if (rtlhal->earlymode_enable) {/*Early mode enable*/ bytetmp = rtl_read_byte(rtlpriv, REG_EARLY_MODE_CONTROL); bytetmp |= 0x1f; rtl_write_byte(rtlpriv, REG_EARLY_MODE_CONTROL, bytetmp); rtl_write_byte(rtlpriv, REG_EARLY_MODE_CONTROL+3, 0x81); } _rtl88ee_gen_refresh_led_state(hw); return true; } static void _rtl88ee_hw_configure(struct ieee80211_hw *hw) { struct rtl_priv *rtlpriv = rtl_priv(hw); u32 reg_prsr; reg_prsr = RATE_ALL_CCK | RATE_ALL_OFDM_AG; rtl_write_dword(rtlpriv, REG_RRSR, reg_prsr); rtl_write_byte(rtlpriv, REG_HWSEQ_CTRL, 0xFF); } static void _rtl88ee_enable_aspm_back_door(struct ieee80211_hw *hw) { struct rtl_priv *rtlpriv = rtl_priv(hw); struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); u8 tmp1byte = 0; u32 tmp4byte = 0, count = 0; rtl_write_word(rtlpriv, 0x354, 0x8104); rtl_write_word(rtlpriv, 0x358, 0x24); rtl_write_word(rtlpriv, 0x350, 0x70c); rtl_write_byte(rtlpriv, 0x352, 0x2); tmp1byte = rtl_read_byte(rtlpriv, 0x352); count = 0; while (tmp1byte && count < 20) { udelay(10); tmp1byte = rtl_read_byte(rtlpriv, 0x352); count++; } if (0 == tmp1byte) { tmp4byte = rtl_read_dword(rtlpriv, 0x34c); rtl_write_dword(rtlpriv, 0x348, tmp4byte|BIT(31)); rtl_write_word(rtlpriv, 0x350, 0xf70c); rtl_write_byte(rtlpriv, 0x352, 0x1); } tmp1byte = rtl_read_byte(rtlpriv, 0x352); count = 0; while (tmp1byte && count < 20) { udelay(10); tmp1byte = rtl_read_byte(rtlpriv, 0x352); count++; } rtl_write_word(rtlpriv, 0x350, 0x718); rtl_write_byte(rtlpriv, 0x352, 0x2); tmp1byte = rtl_read_byte(rtlpriv, 0x352); count = 0; while (tmp1byte && count < 20) { udelay(10); tmp1byte = rtl_read_byte(rtlpriv, 0x352); count++; } if (ppsc->support_backdoor || (0 == tmp1byte)) { tmp4byte = rtl_read_dword(rtlpriv, 0x34c); rtl_write_dword(rtlpriv, 0x348, tmp4byte|BIT(11)|BIT(12)); rtl_write_word(rtlpriv, 0x350, 0xf718); rtl_write_byte(rtlpriv, 0x352, 0x1); } tmp1byte = rtl_read_byte(rtlpriv, 0x352); count = 0; while (tmp1byte && count < 20) { udelay(10); tmp1byte = rtl_read_byte(rtlpriv, 0x352); count++; } } void rtl88ee_enable_hw_security_config(struct ieee80211_hw *hw) { struct rtl_priv *rtlpriv = rtl_priv(hw); u8 sec_reg_value; RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "PairwiseEncAlgorithm = %d GroupEncAlgorithm = %d\n", rtlpriv->sec.pairwise_enc_algorithm, rtlpriv->sec.group_enc_algorithm); if (rtlpriv->cfg->mod_params->sw_crypto || rtlpriv->sec.use_sw_sec) { RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "not open hw encryption\n"); return; } sec_reg_value = SCR_TXENCENABLE | SCR_RXDECENABLE; if (rtlpriv->sec.use_defaultkey) { sec_reg_value |= SCR_TXUSEDK; sec_reg_value |= SCR_RXUSEDK; } sec_reg_value |= (SCR_RXBCUSEDK | SCR_TXBCUSEDK); rtl_write_byte(rtlpriv, REG_CR + 1, 0x02); RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "The SECR-value %x\n", sec_reg_value); rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_WPA_CONFIG, &sec_reg_value); } int rtl88ee_hw_init(struct ieee80211_hw *hw) { struct rtl_priv *rtlpriv = rtl_priv(hw); struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); struct rtl_phy *rtlphy = &(rtlpriv->phy); struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); bool rtstatus = true; int err = 0; u8 tmp_u1b, u1byte; unsigned long flags; rtlpriv->rtlhal.being_init_adapter = true; /* As this function can take a very long time (up to 350 ms) * and can be called with irqs disabled, reenable the irqs * to let the other devices continue being serviced. * * It is safe doing so since our own interrupts will only be enabled * in a subsequent step. */ local_save_flags(flags); local_irq_enable(); rtlhal->fw_ready = false; rtlpriv->intf_ops->disable_aspm(hw); tmp_u1b = rtl_read_byte(rtlpriv, REG_SYS_CLKR+1); u1byte = rtl_read_byte(rtlpriv, REG_CR); if ((tmp_u1b & BIT(3)) && (u1byte != 0 && u1byte != 0xEA)) { rtlhal->mac_func_enable = true; } else { rtlhal->mac_func_enable = false; rtlhal->fw_ps_state = FW_PS_STATE_ALL_ON_88E; } rtstatus = _rtl88ee_init_mac(hw); if (rtstatus != true) { pr_info("Init MAC failed\n"); err = 1; goto exit; } err = rtl88e_download_fw(hw, false); if (err) { RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING, "Failed to download FW. Init HW without FW now..\n"); err = 1; goto exit; } rtlhal->fw_ready = true; /*fw related variable initialize */ rtlhal->last_hmeboxnum = 0; rtlhal->fw_ps_state = FW_PS_STATE_ALL_ON_88E; rtlhal->fw_clk_change_in_progress = false; rtlhal->allow_sw_to_change_hwclc = false; ppsc->fw_current_inpsmode = false; rtl88e_phy_mac_config(hw); /* because last function modify RCR, so we update * rcr var here, or TP will unstable for receive_config * is wrong, RX RCR_ACRC32 will cause TP unstabel & Rx * RCR_APP_ICV will cause mac80211 unassoc for cisco 1252 */ rtlpci->receive_config &= ~(RCR_ACRC32 | RCR_AICV); rtl_write_dword(rtlpriv, REG_RCR, rtlpci->receive_config); rtl88e_phy_bb_config(hw); rtl_set_bbreg(hw, RFPGA0_RFMOD, BCCKEN, 0x1); rtl_set_bbreg(hw, RFPGA0_RFMOD, BOFDMEN, 0x1); rtlphy->rf_mode = RF_OP_BY_SW_3WIRE; rtl88e_phy_rf_config(hw); rtlphy->rfreg_chnlval[0] = rtl_get_rfreg(hw, (enum radio_path)0, RF_CHNLBW, RFREG_OFFSET_MASK); rtlphy->rfreg_chnlval[0] = rtlphy->rfreg_chnlval[0] & 0xfff00fff; _rtl88ee_hw_configure(hw); rtl_cam_reset_all_entry(hw); rtl88ee_enable_hw_security_config(hw); rtlhal->mac_func_enable = true; ppsc->rfpwr_state = ERFON; rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_ETHER_ADDR, mac->mac_addr); _rtl88ee_enable_aspm_back_door(hw); rtlpriv->intf_ops->enable_aspm(hw); if (ppsc->rfpwr_state == ERFON) { if ((rtlefuse->antenna_div_type == CGCS_RX_HW_ANTDIV) || ((rtlefuse->antenna_div_type == CG_TRX_HW_ANTDIV) && (rtlhal->oem_id == RT_CID_819X_HP))) { rtl88e_phy_set_rfpath_switch(hw, true); rtlpriv->dm.fat_table.rx_idle_ant = MAIN_ANT; } else { rtl88e_phy_set_rfpath_switch(hw, false); rtlpriv->dm.fat_table.rx_idle_ant = AUX_ANT; } RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "rx idle ant %s\n", (rtlpriv->dm.fat_table.rx_idle_ant == MAIN_ANT) ? ("MAIN_ANT") : ("AUX_ANT")); if (rtlphy->iqk_initialized) { rtl88e_phy_iq_calibrate(hw, true); } else { rtl88e_phy_iq_calibrate(hw, false); rtlphy->iqk_initialized = true; } rtl88e_dm_check_txpower_tracking(hw); rtl88e_phy_lc_calibrate(hw); } tmp_u1b = efuse_read_1byte(hw, 0x1FA); if (!(tmp_u1b & BIT(0))) { rtl_set_rfreg(hw, RF90_PATH_A, 0x15, 0x0F, 0x05); RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "PA BIAS path A\n"); } if (!(tmp_u1b & BIT(4))) { tmp_u1b = rtl_read_byte(rtlpriv, 0x16); tmp_u1b &= 0x0F; rtl_write_byte(rtlpriv, 0x16, tmp_u1b | 0x80); udelay(10); rtl_write_byte(rtlpriv, 0x16, tmp_u1b | 0x90); RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "under 1.5V\n"); } rtl_write_byte(rtlpriv, REG_NAV_CTRL+2, ((30000+127)/128)); rtl88e_dm_init(hw); exit: local_irq_restore(flags); rtlpriv->rtlhal.being_init_adapter = false; return err; } static enum version_8188e _rtl88ee_read_chip_version(struct ieee80211_hw *hw) { struct rtl_priv *rtlpriv = rtl_priv(hw); struct rtl_phy *rtlphy = &(rtlpriv->phy); enum version_8188e version = VERSION_UNKNOWN; u32 value32; value32 = rtl_read_dword(rtlpriv, REG_SYS_CFG); if (value32 & TRP_VAUX_EN) { version = (enum version_8188e) VERSION_TEST_CHIP_88E; } else { version = NORMAL_CHIP; version = version | ((value32 & TYPE_ID) ? RF_TYPE_2T2R : 0); version = version | ((value32 & VENDOR_ID) ? CHIP_VENDOR_UMC : 0); } rtlphy->rf_type = RF_1T1R; RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "Chip RF Type: %s\n", (rtlphy->rf_type == RF_2T2R) ? "RF_2T2R" : "RF_1T1R"); return version; } static int _rtl88ee_set_media_status(struct ieee80211_hw *hw, enum nl80211_iftype type) { struct rtl_priv *rtlpriv = rtl_priv(hw); u8 bt_msr = rtl_read_byte(rtlpriv, MSR) & 0xfc; enum led_ctl_mode ledaction = LED_CTL_NO_LINK; u8 mode = MSR_NOLINK; switch (type) { case NL80211_IFTYPE_UNSPECIFIED: mode = MSR_NOLINK; RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, "Set Network type to NO LINK!\n"); break; case NL80211_IFTYPE_ADHOC: case NL80211_IFTYPE_MESH_POINT: mode = MSR_ADHOC; RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, "Set Network type to Ad Hoc!\n"); break; case NL80211_IFTYPE_STATION: mode = MSR_INFRA; ledaction = LED_CTL_LINK; RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, "Set Network type to STA!\n"); break; case NL80211_IFTYPE_AP: mode = MSR_AP; ledaction = LED_CTL_LINK; RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, "Set Network type to AP!\n"); break; default: pr_err("Network type %d not support!\n", type); return 1; break; } /* MSR_INFRA == Link in infrastructure network; * MSR_ADHOC == Link in ad hoc network; * Therefore, check link state is necessary. * * MSR_AP == AP mode; link state is not cared here. */ if (mode != MSR_AP && rtlpriv->mac80211.link_state < MAC80211_LINKED) { mode = MSR_NOLINK; ledaction = LED_CTL_NO_LINK; } if (mode == MSR_NOLINK || mode == MSR_INFRA) { _rtl88ee_stop_tx_beacon(hw); _rtl88ee_enable_bcn_sub_func(hw); } else if (mode == MSR_ADHOC || mode == MSR_AP) { _rtl88ee_resume_tx_beacon(hw); _rtl88ee_disable_bcn_sub_func(hw); } else { RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING, "Set HW_VAR_MEDIA_STATUS: No such media status(%x).\n", mode); } rtl_write_byte(rtlpriv, MSR, bt_msr | mode); rtlpriv->cfg->ops->led_control(hw, ledaction); if (mode == MSR_AP) rtl_write_byte(rtlpriv, REG_BCNTCFG + 1, 0x00); else rtl_write_byte(rtlpriv, REG_BCNTCFG + 1, 0x66); return 0; } void rtl88ee_set_check_bssid(struct ieee80211_hw *hw, bool check_bssid) { struct rtl_priv *rtlpriv = rtl_priv(hw); struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); u32 reg_rcr = rtlpci->receive_config; if (rtlpriv->psc.rfpwr_state != ERFON) return; if (check_bssid == true) { reg_rcr |= (RCR_CBSSID_DATA | RCR_CBSSID_BCN); rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_RCR, (u8 *)(&reg_rcr)); _rtl88ee_set_bcn_ctrl_reg(hw, 0, BIT(4)); } else if (check_bssid == false) { reg_rcr &= (~(RCR_CBSSID_DATA | RCR_CBSSID_BCN)); _rtl88ee_set_bcn_ctrl_reg(hw, BIT(4), 0); rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_RCR, (u8 *)(&reg_rcr)); } } int rtl88ee_set_network_type(struct ieee80211_hw *hw, enum nl80211_iftype type) { struct rtl_priv *rtlpriv = rtl_priv(hw); if (_rtl88ee_set_media_status(hw, type)) return -EOPNOTSUPP; if (rtlpriv->mac80211.link_state == MAC80211_LINKED) { if (type != NL80211_IFTYPE_AP && type != NL80211_IFTYPE_MESH_POINT) rtl88ee_set_check_bssid(hw, true); } else { rtl88ee_set_check_bssid(hw, false); } return 0; } /* don't set REG_EDCA_BE_PARAM here * because mac80211 will send pkt when scan */ void rtl88ee_set_qos(struct ieee80211_hw *hw, int aci) { struct rtl_priv *rtlpriv = rtl_priv(hw); rtl88e_dm_init_edca_turbo(hw); switch (aci) { case AC1_BK: rtl_write_dword(rtlpriv, REG_EDCA_BK_PARAM, 0xa44f); break; case AC0_BE: break; case AC2_VI: rtl_write_dword(rtlpriv, REG_EDCA_VI_PARAM, 0x5e4322); break; case AC3_VO: rtl_write_dword(rtlpriv, REG_EDCA_VO_PARAM, 0x2f3222); break; default: WARN_ONCE(true, "rtl8188ee: invalid aci: %d !\n", aci); break; } } void rtl88ee_enable_interrupt(struct ieee80211_hw *hw) { struct rtl_priv *rtlpriv = rtl_priv(hw); struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); rtl_write_dword(rtlpriv, REG_HIMR, rtlpci->irq_mask[0] & 0xFFFFFFFF); rtl_write_dword(rtlpriv, REG_HIMRE, rtlpci->irq_mask[1] & 0xFFFFFFFF); rtlpci->irq_enabled = true; /* there are some C2H CMDs have been sent * before system interrupt is enabled, e.g., C2H, CPWM. * So we need to clear all C2H events that FW has notified, * otherwise FW won't schedule any commands anymore. */ rtl_write_byte(rtlpriv, REG_C2HEVT_CLEAR, 0); /*enable system interrupt*/ rtl_write_dword(rtlpriv, REG_HSIMR, rtlpci->sys_irq_mask & 0xFFFFFFFF); } void rtl88ee_disable_interrupt(struct ieee80211_hw *hw) { struct rtl_priv *rtlpriv = rtl_priv(hw); struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); rtl_write_dword(rtlpriv, REG_HIMR, IMR_DISABLED); rtl_write_dword(rtlpriv, REG_HIMRE, IMR_DISABLED); rtlpci->irq_enabled = false; /*synchronize_irq(rtlpci->pdev->irq);*/ } static void _rtl88ee_poweroff_adapter(struct ieee80211_hw *hw) { struct rtl_priv *rtlpriv = rtl_priv(hw); struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); u8 u1b_tmp; u32 count = 0; rtlhal->mac_func_enable = false; rtlpriv->intf_ops->enable_aspm(hw); RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "POWER OFF adapter\n"); u1b_tmp = rtl_read_byte(rtlpriv, REG_TX_RPT_CTRL); rtl_write_byte(rtlpriv, REG_TX_RPT_CTRL, u1b_tmp & (~BIT(1))); u1b_tmp = rtl_read_byte(rtlpriv, REG_RXDMA_CONTROL); while (!(u1b_tmp & BIT(1)) && (count++ < 100)) { udelay(10); u1b_tmp = rtl_read_byte(rtlpriv, REG_RXDMA_CONTROL); count++; } rtl_write_byte(rtlpriv, REG_PCIE_CTRL_REG+1, 0xFF); rtl_hal_pwrseqcmdparsing(rtlpriv, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_PCI_MSK, RTL8188EE_NIC_LPS_ENTER_FLOW); rtl_write_byte(rtlpriv, REG_RF_CTRL, 0x00); if ((rtl_read_byte(rtlpriv, REG_MCUFWDL) & BIT(7)) && rtlhal->fw_ready) rtl88e_firmware_selfreset(hw); u1b_tmp = rtl_read_byte(rtlpriv, REG_SYS_FUNC_EN+1); rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN + 1, (u1b_tmp & (~BIT(2)))); rtl_write_byte(rtlpriv, REG_MCUFWDL, 0x00); u1b_tmp = rtl_read_byte(rtlpriv, REG_32K_CTRL); rtl_write_byte(rtlpriv, REG_32K_CTRL, (u1b_tmp & (~BIT(0)))); rtl_hal_pwrseqcmdparsing(rtlpriv, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_PCI_MSK, RTL8188EE_NIC_DISABLE_FLOW); u1b_tmp = rtl_read_byte(rtlpriv, REG_RSV_CTRL+1); rtl_write_byte(rtlpriv, REG_RSV_CTRL+1, (u1b_tmp & (~BIT(3)))); u1b_tmp = rtl_read_byte(rtlpriv, REG_RSV_CTRL+1); rtl_write_byte(rtlpriv, REG_RSV_CTRL+1, (u1b_tmp | BIT(3))); rtl_write_byte(rtlpriv, REG_RSV_CTRL, 0x0E); u1b_tmp = rtl_read_byte(rtlpriv, GPIO_IN); rtl_write_byte(rtlpriv, GPIO_OUT, u1b_tmp); rtl_write_byte(rtlpriv, GPIO_IO_SEL, 0x7F); u1b_tmp = rtl_read_byte(rtlpriv, REG_GPIO_IO_SEL); rtl_write_byte(rtlpriv, REG_GPIO_IO_SEL, (u1b_tmp << 4) | u1b_tmp); u1b_tmp = rtl_read_byte(rtlpriv, REG_GPIO_IO_SEL+1); rtl_write_byte(rtlpriv, REG_GPIO_IO_SEL+1, u1b_tmp | 0x0F); rtl_write_dword(rtlpriv, REG_GPIO_IO_SEL_2+2, 0x00080808); } void rtl88ee_card_disable(struct ieee80211_hw *hw) { struct rtl_priv *rtlpriv = rtl_priv(hw); struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); enum nl80211_iftype opmode; RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "RTL8188ee card disable\n"); mac->link_state = MAC80211_NOLINK; opmode = NL80211_IFTYPE_UNSPECIFIED; _rtl88ee_set_media_status(hw, opmode); if (rtlpriv->rtlhal.driver_is_goingto_unload || ppsc->rfoff_reason > RF_CHANGE_BY_PS) rtlpriv->cfg->ops->led_control(hw, LED_CTL_POWER_OFF); RT_SET_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_HALT_NIC); _rtl88ee_poweroff_adapter(hw); /* after power off we should do iqk again */ rtlpriv->phy.iqk_initialized = false; } void rtl88ee_interrupt_recognized(struct ieee80211_hw *hw, struct rtl_int *intvec) { struct rtl_priv *rtlpriv = rtl_priv(hw); struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); intvec->inta = rtl_read_dword(rtlpriv, ISR) & rtlpci->irq_mask[0]; rtl_write_dword(rtlpriv, ISR, intvec->inta); intvec->intb = rtl_read_dword(rtlpriv, REG_HISRE) & rtlpci->irq_mask[1]; rtl_write_dword(rtlpriv, REG_HISRE, intvec->intb); } void rtl88ee_set_beacon_related_registers(struct ieee80211_hw *hw) { struct rtl_priv *rtlpriv = rtl_priv(hw); struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); u16 bcn_interval, atim_window; bcn_interval = mac->beacon_interval; atim_window = 2; /*FIX MERGE */ rtl88ee_disable_interrupt(hw); rtl_write_word(rtlpriv, REG_ATIMWND, atim_window); rtl_write_word(rtlpriv, REG_BCN_INTERVAL, bcn_interval); rtl_write_word(rtlpriv, REG_BCNTCFG, 0x660f); rtl_write_byte(rtlpriv, REG_RXTSF_OFFSET_CCK, 0x18); rtl_write_byte(rtlpriv, REG_RXTSF_OFFSET_OFDM, 0x18); rtl_write_byte(rtlpriv, 0x606, 0x30); rtlpci->reg_bcn_ctrl_val |= BIT(3); rtl_write_byte(rtlpriv, REG_BCN_CTRL, (u8) rtlpci->reg_bcn_ctrl_val); /*rtl88ee_enable_interrupt(hw);*/ } void rtl88ee_set_beacon_interval(struct ieee80211_hw *hw) { struct rtl_priv *rtlpriv = rtl_priv(hw); struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); u16 bcn_interval = mac->beacon_interval; RT_TRACE(rtlpriv, COMP_BEACON, DBG_DMESG, "beacon_interval:%d\n", bcn_interval); /*rtl88ee_disable_interrupt(hw);*/ rtl_write_word(rtlpriv, REG_BCN_INTERVAL, bcn_interval); /*rtl88ee_enable_interrupt(hw);*/ } void rtl88ee_update_interrupt_mask(struct ieee80211_hw *hw, u32 add_msr, u32 rm_msr) { struct rtl_priv *rtlpriv = rtl_priv(hw); struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); RT_TRACE(rtlpriv, COMP_INTR, DBG_LOUD, "add_msr:%x, rm_msr:%x\n", add_msr, rm_msr); if (add_msr) rtlpci->irq_mask[0] |= add_msr; if (rm_msr) rtlpci->irq_mask[0] &= (~rm_msr); rtl88ee_disable_interrupt(hw); rtl88ee_enable_interrupt(hw); } static u8 _rtl88e_get_chnl_group(u8 chnl) { u8 group = 0; if (chnl < 3) group = 0; else if (chnl < 6) group = 1; else if (chnl < 9) group = 2; else if (chnl < 12) group = 3; else if (chnl < 14) group = 4; else if (chnl == 14) group = 5; return group; } static void set_24g_base(struct txpower_info_2g *pwrinfo24g, u32 rfpath) { int group, txcnt; for (group = 0 ; group < MAX_CHNL_GROUP_24G; group++) { pwrinfo24g->index_cck_base[rfpath][group] = 0x2D; pwrinfo24g->index_bw40_base[rfpath][group] = 0x2D; } for (txcnt = 0; txcnt < MAX_TX_COUNT; txcnt++) { if (txcnt == 0) { pwrinfo24g->bw20_diff[rfpath][0] = 0x02; pwrinfo24g->ofdm_diff[rfpath][0] = 0x04; } else { pwrinfo24g->bw20_diff[rfpath][txcnt] = 0xFE; pwrinfo24g->bw40_diff[rfpath][txcnt] = 0xFE; pwrinfo24g->cck_diff[rfpath][txcnt] = 0xFE; pwrinfo24g->ofdm_diff[rfpath][txcnt] = 0xFE; } } } static void read_power_value_fromprom(struct ieee80211_hw *hw, struct txpower_info_2g *pwrinfo24g, struct txpower_info_5g *pwrinfo5g, bool autoload_fail, u8 *hwinfo) { struct rtl_priv *rtlpriv = rtl_priv(hw); u32 rfpath, eeaddr = EEPROM_TX_PWR_INX, group, txcnt = 0; RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "hal_ReadPowerValueFromPROM88E():PROMContent[0x%x]=0x%x\n", (eeaddr+1), hwinfo[eeaddr+1]); if (0xFF == hwinfo[eeaddr+1]) /*YJ,add,120316*/ autoload_fail = true; if (autoload_fail) { RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "auto load fail : Use Default value!\n"); for (rfpath = 0 ; rfpath < MAX_RF_PATH ; rfpath++) { /* 2.4G default value */ set_24g_base(pwrinfo24g, rfpath); } return; } for (rfpath = 0 ; rfpath < MAX_RF_PATH ; rfpath++) { /*2.4G default value*/ for (group = 0 ; group < MAX_CHNL_GROUP_24G; group++) { pwrinfo24g->index_cck_base[rfpath][group] = hwinfo[eeaddr++]; if (pwrinfo24g->index_cck_base[rfpath][group] == 0xFF) pwrinfo24g->index_cck_base[rfpath][group] = 0x2D; } for (group = 0 ; group < MAX_CHNL_GROUP_24G-1; group++) { pwrinfo24g->index_bw40_base[rfpath][group] = hwinfo[eeaddr++]; if (pwrinfo24g->index_bw40_base[rfpath][group] == 0xFF) pwrinfo24g->index_bw40_base[rfpath][group] = 0x2D; } pwrinfo24g->bw40_diff[rfpath][0] = 0; if (hwinfo[eeaddr] == 0xFF) { pwrinfo24g->bw20_diff[rfpath][0] = 0x02; } else { pwrinfo24g->bw20_diff[rfpath][0] = (hwinfo[eeaddr]&0xf0)>>4; /*bit sign number to 8 bit sign number*/ if (pwrinfo24g->bw20_diff[rfpath][0] & BIT(3)) pwrinfo24g->bw20_diff[rfpath][0] |= 0xF0; } if (hwinfo[eeaddr] == 0xFF) { pwrinfo24g->ofdm_diff[rfpath][0] = 0x04; } else { pwrinfo24g->ofdm_diff[rfpath][0] = (hwinfo[eeaddr]&0x0f); /*bit sign number to 8 bit sign number*/ if (pwrinfo24g->ofdm_diff[rfpath][0] & BIT(3)) pwrinfo24g->ofdm_diff[rfpath][0] |= 0xF0; } pwrinfo24g->cck_diff[rfpath][0] = 0; eeaddr++; for (txcnt = 1; txcnt < MAX_TX_COUNT; txcnt++) { if (hwinfo[eeaddr] == 0xFF) { pwrinfo24g->bw40_diff[rfpath][txcnt] = 0xFE; } else { pwrinfo24g->bw40_diff[rfpath][txcnt] = (hwinfo[eeaddr]&0xf0)>>4; if (pwrinfo24g->bw40_diff[rfpath][txcnt] & BIT(3)) pwrinfo24g->bw40_diff[rfpath][txcnt] |= 0xF0; } if (hwinfo[eeaddr] == 0xFF) { pwrinfo24g->bw20_diff[rfpath][txcnt] = 0xFE; } else { pwrinfo24g->bw20_diff[rfpath][txcnt] = (hwinfo[eeaddr]&0x0f); if (pwrinfo24g->bw20_diff[rfpath][txcnt] & BIT(3)) pwrinfo24g->bw20_diff[rfpath][txcnt] |= 0xF0; } eeaddr++; if (hwinfo[eeaddr] == 0xFF) { pwrinfo24g->ofdm_diff[rfpath][txcnt] = 0xFE; } else { pwrinfo24g->ofdm_diff[rfpath][txcnt] = (hwinfo[eeaddr]&0xf0)>>4; if (pwrinfo24g->ofdm_diff[rfpath][txcnt] & BIT(3)) pwrinfo24g->ofdm_diff[rfpath][txcnt] |= 0xF0; } if (hwinfo[eeaddr] == 0xFF) { pwrinfo24g->cck_diff[rfpath][txcnt] = 0xFE; } else { pwrinfo24g->cck_diff[rfpath][txcnt] = (hwinfo[eeaddr]&0x0f); if (pwrinfo24g->cck_diff[rfpath][txcnt] & BIT(3)) pwrinfo24g->cck_diff[rfpath][txcnt] |= 0xF0; } eeaddr++; } /*5G default value*/ for (group = 0 ; group < MAX_CHNL_GROUP_5G; group++) { pwrinfo5g->index_bw40_base[rfpath][group] = hwinfo[eeaddr++]; if (pwrinfo5g->index_bw40_base[rfpath][group] == 0xFF) pwrinfo5g->index_bw40_base[rfpath][group] = 0xFE; } pwrinfo5g->bw40_diff[rfpath][0] = 0; if (hwinfo[eeaddr] == 0xFF) { pwrinfo5g->bw20_diff[rfpath][0] = 0; } else { pwrinfo5g->bw20_diff[rfpath][0] = (hwinfo[eeaddr]&0xf0)>>4; if (pwrinfo5g->bw20_diff[rfpath][0] & BIT(3)) pwrinfo5g->bw20_diff[rfpath][0] |= 0xF0; } if (hwinfo[eeaddr] == 0xFF) { pwrinfo5g->ofdm_diff[rfpath][0] = 0x04; } else { pwrinfo5g->ofdm_diff[rfpath][0] = (hwinfo[eeaddr]&0x0f); if (pwrinfo5g->ofdm_diff[rfpath][0] & BIT(3)) pwrinfo5g->ofdm_diff[rfpath][0] |= 0xF0; } eeaddr++; for (txcnt = 1; txcnt < MAX_TX_COUNT; txcnt++) { if (hwinfo[eeaddr] == 0xFF) { pwrinfo5g->bw40_diff[rfpath][txcnt] = 0xFE; } else { pwrinfo5g->bw40_diff[rfpath][txcnt] = (hwinfo[eeaddr]&0xf0)>>4; if (pwrinfo5g->bw40_diff[rfpath][txcnt] & BIT(3)) pwrinfo5g->bw40_diff[rfpath][txcnt] |= 0xF0; } if (hwinfo[eeaddr] == 0xFF) { pwrinfo5g->bw20_diff[rfpath][txcnt] = 0xFE; } else { pwrinfo5g->bw20_diff[rfpath][txcnt] = (hwinfo[eeaddr]&0x0f); if (pwrinfo5g->bw20_diff[rfpath][txcnt] & BIT(3)) pwrinfo5g->bw20_diff[rfpath][txcnt] |= 0xF0; } eeaddr++; } if (hwinfo[eeaddr] == 0xFF) { pwrinfo5g->ofdm_diff[rfpath][1] = 0xFE; pwrinfo5g->ofdm_diff[rfpath][2] = 0xFE; } else { pwrinfo5g->ofdm_diff[rfpath][1] = (hwinfo[eeaddr]&0xf0)>>4; pwrinfo5g->ofdm_diff[rfpath][2] = (hwinfo[eeaddr]&0x0f); } eeaddr++; if (hwinfo[eeaddr] == 0xFF) pwrinfo5g->ofdm_diff[rfpath][3] = 0xFE; else pwrinfo5g->ofdm_diff[rfpath][3] = (hwinfo[eeaddr]&0x0f); eeaddr++; for (txcnt = 1; txcnt < MAX_TX_COUNT; txcnt++) { if (pwrinfo5g->ofdm_diff[rfpath][txcnt] == 0xFF) pwrinfo5g->ofdm_diff[rfpath][txcnt] = 0xFE; else if (pwrinfo5g->ofdm_diff[rfpath][txcnt] & BIT(3)) pwrinfo5g->ofdm_diff[rfpath][txcnt] |= 0xF0; } } } static void _rtl88ee_read_txpower_info_from_hwpg(struct ieee80211_hw *hw, bool autoload_fail, u8 *hwinfo) { struct rtl_priv *rtlpriv = rtl_priv(hw); struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); struct txpower_info_2g pwrinfo24g; struct txpower_info_5g pwrinfo5g; u8 rf_path, index; u8 i; read_power_value_fromprom(hw, &pwrinfo24g, &pwrinfo5g, autoload_fail, hwinfo); for (rf_path = 0; rf_path < 2; rf_path++) { for (i = 0; i < 14; i++) { index = _rtl88e_get_chnl_group(i+1); rtlefuse->txpwrlevel_cck[rf_path][i] = pwrinfo24g.index_cck_base[rf_path][index]; rtlefuse->txpwrlevel_ht40_1s[rf_path][i] = pwrinfo24g.index_bw40_base[rf_path][index]; rtlefuse->txpwr_ht20diff[rf_path][i] = pwrinfo24g.bw20_diff[rf_path][0]; rtlefuse->txpwr_legacyhtdiff[rf_path][i] = pwrinfo24g.ofdm_diff[rf_path][0]; } for (i = 0; i < 14; i++) { RTPRINT(rtlpriv, FINIT, INIT_TXPOWER, "RF(%d)-Ch(%d) [CCK / HT40_1S ] = [0x%x / 0x%x ]\n", rf_path, i, rtlefuse->txpwrlevel_cck[rf_path][i], rtlefuse->txpwrlevel_ht40_1s[rf_path][i]); } } if (!autoload_fail) rtlefuse->eeprom_thermalmeter = hwinfo[EEPROM_THERMAL_METER_88E]; else rtlefuse->eeprom_thermalmeter = EEPROM_DEFAULT_THERMALMETER; if (rtlefuse->eeprom_thermalmeter == 0xff || autoload_fail) { rtlefuse->apk_thermalmeterignore = true; rtlefuse->eeprom_thermalmeter = EEPROM_DEFAULT_THERMALMETER; } rtlefuse->thermalmeter[0] = rtlefuse->eeprom_thermalmeter; RTPRINT(rtlpriv, FINIT, INIT_TXPOWER, "thermalmeter = 0x%x\n", rtlefuse->eeprom_thermalmeter); if (!autoload_fail) { rtlefuse->eeprom_regulatory = hwinfo[EEPROM_RF_BOARD_OPTION_88E] & 0x07;/*bit0~2*/ if (hwinfo[EEPROM_RF_BOARD_OPTION_88E] == 0xFF) rtlefuse->eeprom_regulatory = 0; } else { rtlefuse->eeprom_regulatory = 0; } RTPRINT(rtlpriv, FINIT, INIT_TXPOWER, "eeprom_regulatory = 0x%x\n", rtlefuse->eeprom_regulatory); } static void _rtl88ee_read_adapter_info(struct ieee80211_hw *hw) { struct rtl_priv *rtlpriv = rtl_priv(hw); struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); int params[] = {RTL8188E_EEPROM_ID, EEPROM_VID, EEPROM_DID, EEPROM_SVID, EEPROM_SMID, EEPROM_MAC_ADDR, EEPROM_CHANNELPLAN, EEPROM_VERSION, EEPROM_CUSTOMER_ID, COUNTRY_CODE_WORLD_WIDE_13}; u8 *hwinfo; hwinfo = kzalloc(HWSET_MAX_SIZE, GFP_KERNEL); if (!hwinfo) return; if (rtl_get_hwinfo(hw, rtlpriv, HWSET_MAX_SIZE, hwinfo, params)) goto exit; if (rtlefuse->eeprom_oemid == 0xFF) rtlefuse->eeprom_oemid = 0; RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "EEPROM Customer ID: 0x%2x\n", rtlefuse->eeprom_oemid); /* set channel plan from efuse */ rtlefuse->channel_plan = rtlefuse->eeprom_channelplan; /*tx power*/ _rtl88ee_read_txpower_info_from_hwpg(hw, rtlefuse->autoload_failflag, hwinfo); rtlefuse->txpwr_fromeprom = true; rtl8188ee_read_bt_coexist_info_from_hwpg(hw, rtlefuse->autoload_failflag, hwinfo); /*board type*/ rtlefuse->board_type = ((hwinfo[EEPROM_RF_BOARD_OPTION_88E] & 0xE0) >> 5); rtlhal->board_type = rtlefuse->board_type; /*Wake on wlan*/ rtlefuse->wowlan_enable = ((hwinfo[EEPROM_RF_FEATURE_OPTION_88E] & 0x40) >> 6); /*parse xtal*/ rtlefuse->crystalcap = hwinfo[EEPROM_XTAL_88E]; if (hwinfo[EEPROM_XTAL_88E]) rtlefuse->crystalcap = 0x20; /*antenna diversity*/ rtlefuse->antenna_div_cfg = (hwinfo[EEPROM_RF_BOARD_OPTION_88E] & 0x18) >> 3; if (hwinfo[EEPROM_RF_BOARD_OPTION_88E] == 0xFF) rtlefuse->antenna_div_cfg = 0; if (rtlpriv->btcoexist.eeprom_bt_coexist != 0 && rtlpriv->btcoexist.eeprom_bt_ant_num == ANT_X1) rtlefuse->antenna_div_cfg = 0; rtlefuse->antenna_div_type = hwinfo[EEPROM_RF_ANTENNA_OPT_88E]; if (rtlefuse->antenna_div_type == 0xFF) rtlefuse->antenna_div_type = 0x01; if (rtlefuse->antenna_div_type == CG_TRX_HW_ANTDIV || rtlefuse->antenna_div_type == CGCS_RX_HW_ANTDIV) rtlefuse->antenna_div_cfg = 1; if (rtlhal->oem_id == RT_CID_DEFAULT) { switch (rtlefuse->eeprom_oemid) { case EEPROM_CID_DEFAULT: if (rtlefuse->eeprom_did == 0x8179) { if (rtlefuse->eeprom_svid == 0x1025) { rtlhal->oem_id = RT_CID_819X_ACER; } else if ((rtlefuse->eeprom_svid == 0x10EC && rtlefuse->eeprom_smid == 0x0179) || (rtlefuse->eeprom_svid == 0x17AA && rtlefuse->eeprom_smid == 0x0179)) { rtlhal->oem_id = RT_CID_819X_LENOVO; } else if (rtlefuse->eeprom_svid == 0x103c && rtlefuse->eeprom_smid == 0x197d) { rtlhal->oem_id = RT_CID_819X_HP; } else { rtlhal->oem_id = RT_CID_DEFAULT; } } else { rtlhal->oem_id = RT_CID_DEFAULT; } break; case EEPROM_CID_TOSHIBA: rtlhal->oem_id = RT_CID_TOSHIBA; break; case EEPROM_CID_QMI: rtlhal->oem_id = RT_CID_819X_QMI; break; case EEPROM_CID_WHQL: default: rtlhal->oem_id = RT_CID_DEFAULT; break; } } exit: kfree(hwinfo); } static void _rtl88ee_hal_customized_behavior(struct ieee80211_hw *hw) { struct rtl_priv *rtlpriv = rtl_priv(hw); struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); rtlpriv->ledctl.led_opendrain = true; switch (rtlhal->oem_id) { case RT_CID_819X_HP: rtlpriv->ledctl.led_opendrain = true; break; case RT_CID_819X_LENOVO: case RT_CID_DEFAULT: case RT_CID_TOSHIBA: case RT_CID_CCX: case RT_CID_819X_ACER: case RT_CID_WHQL: default: break; } RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "RT Customized ID: 0x%02X\n", rtlhal->oem_id); } void rtl88ee_read_eeprom_info(struct ieee80211_hw *hw) { struct rtl_priv *rtlpriv = rtl_priv(hw); struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); struct rtl_phy *rtlphy = &(rtlpriv->phy); struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); u8 tmp_u1b; rtlhal->version = _rtl88ee_read_chip_version(hw); if (get_rf_type(rtlphy) == RF_1T1R) rtlpriv->dm.rfpath_rxenable[0] = true; else rtlpriv->dm.rfpath_rxenable[0] = rtlpriv->dm.rfpath_rxenable[1] = true; RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "VersionID = 0x%4x\n", rtlhal->version); tmp_u1b = rtl_read_byte(rtlpriv, REG_9346CR); if (tmp_u1b & BIT(4)) { RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "Boot from EEPROM\n"); rtlefuse->epromtype = EEPROM_93C46; } else { RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "Boot from EFUSE\n"); rtlefuse->epromtype = EEPROM_BOOT_EFUSE; } if (tmp_u1b & BIT(5)) { RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "Autoload OK\n"); rtlefuse->autoload_failflag = false; _rtl88ee_read_adapter_info(hw); } else { pr_err("Autoload ERR!!\n"); } _rtl88ee_hal_customized_behavior(hw); } static void rtl88ee_update_hal_rate_table(struct ieee80211_hw *hw, struct ieee80211_sta *sta) { struct rtl_priv *rtlpriv = rtl_priv(hw); struct rtl_phy *rtlphy = &(rtlpriv->phy); struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); u32 ratr_value; u8 ratr_index = 0; u8 b_nmode = mac->ht_enable; /*u8 mimo_ps = IEEE80211_SMPS_OFF;*/ u16 shortgi_rate; u32 tmp_ratr_value; u8 curtxbw_40mhz = mac->bw_40; u8 curshortgi_40mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40) ? 1 : 0; u8 curshortgi_20mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20) ? 1 : 0; enum wireless_mode wirelessmode = mac->mode; u32 ratr_mask; if (rtlhal->current_bandtype == BAND_ON_5G) ratr_value = sta->supp_rates[1] << 4; else ratr_value = sta->supp_rates[0]; if (mac->opmode == NL80211_IFTYPE_ADHOC) ratr_value = 0xfff; ratr_value |= (sta->ht_cap.mcs.rx_mask[1] << 20 | sta->ht_cap.mcs.rx_mask[0] << 12); switch (wirelessmode) { case WIRELESS_MODE_B: if (ratr_value & 0x0000000c) ratr_value &= 0x0000000d; else ratr_value &= 0x0000000f; break; case WIRELESS_MODE_G: ratr_value &= 0x00000FF5; break; case WIRELESS_MODE_N_24G: case WIRELESS_MODE_N_5G: b_nmode = 1; if (get_rf_type(rtlphy) == RF_1T2R || get_rf_type(rtlphy) == RF_1T1R) ratr_mask = 0x000ff005; else ratr_mask = 0x0f0ff005; ratr_value &= ratr_mask; break; default: if (rtlphy->rf_type == RF_1T2R) ratr_value &= 0x000ff0ff; else ratr_value &= 0x0f0ff0ff; break; } if ((rtlpriv->btcoexist.bt_coexistence) && (rtlpriv->btcoexist.bt_coexist_type == BT_CSR_BC4) && (rtlpriv->btcoexist.bt_cur_state) && (rtlpriv->btcoexist.bt_ant_isolation) && ((rtlpriv->btcoexist.bt_service == BT_SCO) || (rtlpriv->btcoexist.bt_service == BT_BUSY))) ratr_value &= 0x0fffcfc0; else ratr_value &= 0x0FFFFFFF; if (b_nmode && ((curtxbw_40mhz && curshortgi_40mhz) || (!curtxbw_40mhz && curshortgi_20mhz))) { ratr_value |= 0x10000000; tmp_ratr_value = (ratr_value >> 12); for (shortgi_rate = 15; shortgi_rate > 0; shortgi_rate--) { if ((1 << shortgi_rate) & tmp_ratr_value) break; } shortgi_rate = (shortgi_rate << 12) | (shortgi_rate << 8) | (shortgi_rate << 4) | (shortgi_rate); } rtl_write_dword(rtlpriv, REG_ARFR0 + ratr_index * 4, ratr_value); RT_TRACE(rtlpriv, COMP_RATR, DBG_DMESG, "%x\n", rtl_read_dword(rtlpriv, REG_ARFR0)); } static void rtl88ee_update_hal_rate_mask(struct ieee80211_hw *hw, struct ieee80211_sta *sta, u8 rssi_level, bool update_bw) { struct rtl_priv *rtlpriv = rtl_priv(hw); struct rtl_phy *rtlphy = &(rtlpriv->phy); struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); struct rtl_sta_info *sta_entry = NULL; u32 ratr_bitmap; u8 ratr_index; u8 curtxbw_40mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) ? 1 : 0; u8 curshortgi_40mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40) ? 1 : 0; u8 curshortgi_20mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20) ? 1 : 0; enum wireless_mode wirelessmode = 0; bool b_shortgi = false; u8 rate_mask[5]; u8 macid = 0; /*u8 mimo_ps = IEEE80211_SMPS_OFF;*/ sta_entry = (struct rtl_sta_info *)sta->drv_priv; wirelessmode = sta_entry->wireless_mode; if (mac->opmode == NL80211_IFTYPE_STATION || mac->opmode == NL80211_IFTYPE_MESH_POINT) curtxbw_40mhz = mac->bw_40; else if (mac->opmode == NL80211_IFTYPE_AP || mac->opmode == NL80211_IFTYPE_ADHOC) macid = sta->aid + 1; if (rtlhal->current_bandtype == BAND_ON_5G) ratr_bitmap = sta->supp_rates[1] << 4; else ratr_bitmap = sta->supp_rates[0]; if (mac->opmode == NL80211_IFTYPE_ADHOC) ratr_bitmap = 0xfff; ratr_bitmap |= (sta->ht_cap.mcs.rx_mask[1] << 20 | sta->ht_cap.mcs.rx_mask[0] << 12); switch (wirelessmode) { case WIRELESS_MODE_B: ratr_index = RATR_INX_WIRELESS_B; if (ratr_bitmap & 0x0000000c) ratr_bitmap &= 0x0000000d; else ratr_bitmap &= 0x0000000f; break; case WIRELESS_MODE_G: ratr_index = RATR_INX_WIRELESS_GB; if (rssi_level == 1) ratr_bitmap &= 0x00000f00; else if (rssi_level == 2) ratr_bitmap &= 0x00000ff0; else ratr_bitmap &= 0x00000ff5; break; case WIRELESS_MODE_N_24G: case WIRELESS_MODE_N_5G: ratr_index = RATR_INX_WIRELESS_NGB; if (rtlphy->rf_type == RF_1T2R || rtlphy->rf_type == RF_1T1R) { if (curtxbw_40mhz) { if (rssi_level == 1) ratr_bitmap &= 0x000f0000; else if (rssi_level == 2) ratr_bitmap &= 0x000ff000; else ratr_bitmap &= 0x000ff015; } else { if (rssi_level == 1) ratr_bitmap &= 0x000f0000; else if (rssi_level == 2) ratr_bitmap &= 0x000ff000; else ratr_bitmap &= 0x000ff005; } } else { if (curtxbw_40mhz) { if (rssi_level == 1) ratr_bitmap &= 0x0f8f0000; else if (rssi_level == 2) ratr_bitmap &= 0x0f8ff000; else ratr_bitmap &= 0x0f8ff015; } else { if (rssi_level == 1) ratr_bitmap &= 0x0f8f0000; else if (rssi_level == 2) ratr_bitmap &= 0x0f8ff000; else ratr_bitmap &= 0x0f8ff005; } } /*}*/ if ((curtxbw_40mhz && curshortgi_40mhz) || (!curtxbw_40mhz && curshortgi_20mhz)) { if (macid == 0) b_shortgi = true; else if (macid == 1) b_shortgi = false; } break; default: ratr_index = RATR_INX_WIRELESS_NGB; if (rtlphy->rf_type == RF_1T2R) ratr_bitmap &= 0x000ff0ff; else ratr_bitmap &= 0x0f0ff0ff; break; } sta_entry->ratr_index = ratr_index; RT_TRACE(rtlpriv, COMP_RATR, DBG_DMESG, "ratr_bitmap :%x\n", ratr_bitmap); *(u32 *)&rate_mask = (ratr_bitmap & 0x0fffffff) | (ratr_index << 28); rate_mask[4] = macid | (b_shortgi ? 0x20 : 0x00) | 0x80; RT_TRACE(rtlpriv, COMP_RATR, DBG_DMESG, "Rate_index:%x, ratr_val:%x, %x:%x:%x:%x:%x\n", ratr_index, ratr_bitmap, rate_mask[0], rate_mask[1], rate_mask[2], rate_mask[3], rate_mask[4]); rtl88e_fill_h2c_cmd(hw, H2C_88E_RA_MASK, 5, rate_mask); _rtl88ee_set_bcn_ctrl_reg(hw, BIT(3), 0); } void rtl88ee_update_hal_rate_tbl(struct ieee80211_hw *hw, struct ieee80211_sta *sta, u8 rssi_level, bool update_bw) { struct rtl_priv *rtlpriv = rtl_priv(hw); if (rtlpriv->dm.useramask) rtl88ee_update_hal_rate_mask(hw, sta, rssi_level, update_bw); else rtl88ee_update_hal_rate_table(hw, sta); } void rtl88ee_update_channel_access_setting(struct ieee80211_hw *hw) { struct rtl_priv *rtlpriv = rtl_priv(hw); struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); u16 sifs_timer; rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SLOT_TIME, &mac->slot_time); if (!mac->ht_enable) sifs_timer = 0x0a0a; else sifs_timer = 0x0e0e; rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SIFS, (u8 *)&sifs_timer); } bool rtl88ee_gpio_radio_on_off_checking(struct ieee80211_hw *hw, u8 *valid) { struct rtl_priv *rtlpriv = rtl_priv(hw); struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); enum rf_pwrstate e_rfpowerstate_toset; u32 u4tmp; bool b_actuallyset = false; if (rtlpriv->rtlhal.being_init_adapter) return false; if (ppsc->swrf_processing) return false; spin_lock(&rtlpriv->locks.rf_ps_lock); if (ppsc->rfchange_inprogress) { spin_unlock(&rtlpriv->locks.rf_ps_lock); return false; } else { ppsc->rfchange_inprogress = true; spin_unlock(&rtlpriv->locks.rf_ps_lock); } u4tmp = rtl_read_dword(rtlpriv, REG_GPIO_OUTPUT); e_rfpowerstate_toset = (u4tmp & BIT(31)) ? ERFON : ERFOFF; if (ppsc->hwradiooff && (e_rfpowerstate_toset == ERFON)) { RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG, "GPIOChangeRF - HW Radio ON, RF ON\n"); e_rfpowerstate_toset = ERFON; ppsc->hwradiooff = false; b_actuallyset = true; } else if ((!ppsc->hwradiooff) && (e_rfpowerstate_toset == ERFOFF)) { RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG, "GPIOChangeRF - HW Radio OFF, RF OFF\n"); e_rfpowerstate_toset = ERFOFF; ppsc->hwradiooff = true; b_actuallyset = true; } if (b_actuallyset) { spin_lock(&rtlpriv->locks.rf_ps_lock); ppsc->rfchange_inprogress = false; spin_unlock(&rtlpriv->locks.rf_ps_lock); } else { if (ppsc->reg_rfps_level & RT_RF_OFF_LEVL_HALT_NIC) RT_SET_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_HALT_NIC); spin_lock(&rtlpriv->locks.rf_ps_lock); ppsc->rfchange_inprogress = false; spin_unlock(&rtlpriv->locks.rf_ps_lock); } *valid = 1; return !ppsc->hwradiooff; } void rtl88ee_set_key(struct ieee80211_hw *hw, u32 key_index, u8 *p_macaddr, bool is_group, u8 enc_algo, bool is_wepkey, bool clear_all) { struct rtl_priv *rtlpriv = rtl_priv(hw); struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); u8 *macaddr = p_macaddr; u32 entry_id = 0; bool is_pairwise = false; static u8 cam_const_addr[4][6] = { {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x01}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x02}, {0x00, 0x00, 0x00, 0x00, 0x00, 0x03} }; static u8 cam_const_broad[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; if (clear_all) { u8 idx = 0; u8 cam_offset = 0; u8 clear_number = 5; RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "clear_all\n"); for (idx = 0; idx < clear_number; idx++) { rtl_cam_mark_invalid(hw, cam_offset + idx); rtl_cam_empty_entry(hw, cam_offset + idx); if (idx < 5) { memset(rtlpriv->sec.key_buf[idx], 0, MAX_KEY_LEN); rtlpriv->sec.key_len[idx] = 0; } } } else { switch (enc_algo) { case WEP40_ENCRYPTION: enc_algo = CAM_WEP40; break; case WEP104_ENCRYPTION: enc_algo = CAM_WEP104; break; case TKIP_ENCRYPTION: enc_algo = CAM_TKIP; break; case AESCCMP_ENCRYPTION: enc_algo = CAM_AES; break; default: pr_err("switch case %#x not processed\n", enc_algo); enc_algo = CAM_TKIP; break; } if (is_wepkey || rtlpriv->sec.use_defaultkey) { macaddr = cam_const_addr[key_index]; entry_id = key_index; } else { if (is_group) { macaddr = cam_const_broad; entry_id = key_index; } else { if (mac->opmode == NL80211_IFTYPE_AP || mac->opmode == NL80211_IFTYPE_MESH_POINT) { entry_id = rtl_cam_get_free_entry(hw, p_macaddr); if (entry_id >= TOTAL_CAM_ENTRY) { pr_err("Can not find free hw security cam entry\n"); return; } } else { entry_id = CAM_PAIRWISE_KEY_POSITION; } key_index = PAIRWISE_KEYIDX; is_pairwise = true; } } if (rtlpriv->sec.key_len[key_index] == 0) { RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "delete one entry, entry_id is %d\n", entry_id); if (mac->opmode == NL80211_IFTYPE_AP || mac->opmode == NL80211_IFTYPE_MESH_POINT) rtl_cam_del_entry(hw, p_macaddr); rtl_cam_delete_one_entry(hw, p_macaddr, entry_id); } else { RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "add one entry\n"); if (is_pairwise) { RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "set Pairwise key\n"); rtl_cam_add_one_entry(hw, macaddr, key_index, entry_id, enc_algo, CAM_CONFIG_NO_USEDK, rtlpriv->sec.key_buf[key_index]); } else { RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "set group key\n"); if (mac->opmode == NL80211_IFTYPE_ADHOC) { rtl_cam_add_one_entry(hw, rtlefuse->dev_addr, PAIRWISE_KEYIDX, CAM_PAIRWISE_KEY_POSITION, enc_algo, CAM_CONFIG_NO_USEDK, rtlpriv->sec.key_buf [entry_id]); } rtl_cam_add_one_entry(hw, macaddr, key_index, entry_id, enc_algo, CAM_CONFIG_NO_USEDK, rtlpriv->sec.key_buf[entry_id]); } } } } static void rtl8188ee_bt_var_init(struct ieee80211_hw *hw) { struct rtl_priv *rtlpriv = rtl_priv(hw); rtlpriv->btcoexist.bt_coexistence = rtlpriv->btcoexist.eeprom_bt_coexist; rtlpriv->btcoexist.bt_ant_num = rtlpriv->btcoexist.eeprom_bt_ant_num; rtlpriv->btcoexist.bt_coexist_type = rtlpriv->btcoexist.eeprom_bt_type; if (rtlpriv->btcoexist.reg_bt_iso == 2) rtlpriv->btcoexist.bt_ant_isolation = rtlpriv->btcoexist.eeprom_bt_ant_isol; else rtlpriv->btcoexist.bt_ant_isolation = rtlpriv->btcoexist.reg_bt_iso; rtlpriv->btcoexist.bt_radio_shared_type = rtlpriv->btcoexist.eeprom_bt_radio_shared; if (rtlpriv->btcoexist.bt_coexistence) { if (rtlpriv->btcoexist.reg_bt_sco == 1) rtlpriv->btcoexist.bt_service = BT_OTHER_ACTION; else if (rtlpriv->btcoexist.reg_bt_sco == 2) rtlpriv->btcoexist.bt_service = BT_SCO; else if (rtlpriv->btcoexist.reg_bt_sco == 4) rtlpriv->btcoexist.bt_service = BT_BUSY; else if (rtlpriv->btcoexist.reg_bt_sco == 5) rtlpriv->btcoexist.bt_service = BT_OTHERBUSY; else rtlpriv->btcoexist.bt_service = BT_IDLE; rtlpriv->btcoexist.bt_edca_ul = 0; rtlpriv->btcoexist.bt_edca_dl = 0; rtlpriv->btcoexist.bt_rssi_state = 0xff; } } void rtl8188ee_read_bt_coexist_info_from_hwpg(struct ieee80211_hw *hw, bool auto_load_fail, u8 *hwinfo) { struct rtl_priv *rtlpriv = rtl_priv(hw); u8 value; if (!auto_load_fail) { rtlpriv->btcoexist.eeprom_bt_coexist = ((hwinfo[EEPROM_RF_FEATURE_OPTION_88E] & 0xe0) >> 5); if (hwinfo[EEPROM_RF_FEATURE_OPTION_88E] == 0xFF) rtlpriv->btcoexist.eeprom_bt_coexist = 0; value = hwinfo[EEPROM_RF_BT_SETTING_88E]; rtlpriv->btcoexist.eeprom_bt_type = ((value & 0xe) >> 1); rtlpriv->btcoexist.eeprom_bt_ant_num = (value & 0x1); rtlpriv->btcoexist.eeprom_bt_ant_isol = ((value & 0x10) >> 4); rtlpriv->btcoexist.eeprom_bt_radio_shared = ((value & 0x20) >> 5); } else { rtlpriv->btcoexist.eeprom_bt_coexist = 0; rtlpriv->btcoexist.eeprom_bt_type = BT_2WIRE; rtlpriv->btcoexist.eeprom_bt_ant_num = ANT_X2; rtlpriv->btcoexist.eeprom_bt_ant_isol = 0; rtlpriv->btcoexist.eeprom_bt_radio_shared = BT_RADIO_SHARED; } rtl8188ee_bt_var_init(hw); } void rtl8188ee_bt_reg_init(struct ieee80211_hw *hw) { struct rtl_priv *rtlpriv = rtl_priv(hw); /* 0:Low, 1:High, 2:From Efuse. */ rtlpriv->btcoexist.reg_bt_iso = 2; /* 0:Idle, 1:None-SCO, 2:SCO, 3:From Counter. */ rtlpriv->btcoexist.reg_bt_sco = 3; /* 0:Disable BT control A-MPDU, 1:Enable BT control A-MPDU. */ rtlpriv->btcoexist.reg_bt_sco = 0; } void rtl8188ee_bt_hw_init(struct ieee80211_hw *hw) { struct rtl_priv *rtlpriv = rtl_priv(hw); struct rtl_phy *rtlphy = &rtlpriv->phy; u8 u1_tmp; if (rtlpriv->btcoexist.bt_coexistence && ((rtlpriv->btcoexist.bt_coexist_type == BT_CSR_BC4) || rtlpriv->btcoexist.bt_coexist_type == BT_CSR_BC8)) { if (rtlpriv->btcoexist.bt_ant_isolation) rtl_write_byte(rtlpriv, REG_GPIO_MUXCFG, 0xa0); u1_tmp = rtl_read_byte(rtlpriv, 0x4fd) & BIT_OFFSET_LEN_MASK_32(0, 1); u1_tmp = u1_tmp | ((rtlpriv->btcoexist.bt_ant_isolation == 1) ? 0 : BIT_OFFSET_LEN_MASK_32(1, 1)) | ((rtlpriv->btcoexist.bt_service == BT_SCO) ? 0 : BIT_OFFSET_LEN_MASK_32(2, 1)); rtl_write_byte(rtlpriv, 0x4fd, u1_tmp); rtl_write_dword(rtlpriv, REG_BT_COEX_TABLE+4, 0xaaaa9aaa); rtl_write_dword(rtlpriv, REG_BT_COEX_TABLE+8, 0xffbd0040); rtl_write_dword(rtlpriv, REG_BT_COEX_TABLE+0xc, 0x40000010); /* Config to 1T1R. */ if (rtlphy->rf_type == RF_1T1R) { u1_tmp = rtl_read_byte(rtlpriv, ROFDM0_TRXPATHENABLE); u1_tmp &= ~(BIT_OFFSET_LEN_MASK_32(1, 1)); rtl_write_byte(rtlpriv, ROFDM0_TRXPATHENABLE, u1_tmp); u1_tmp = rtl_read_byte(rtlpriv, ROFDM1_TRXPATHENABLE); u1_tmp &= ~(BIT_OFFSET_LEN_MASK_32(1, 1)); rtl_write_byte(rtlpriv, ROFDM1_TRXPATHENABLE, u1_tmp); } } } void rtl88ee_suspend(struct ieee80211_hw *hw) { } void rtl88ee_resume(struct ieee80211_hw *hw) { }
28.399371
79
0.697653
9ab67aacf19da86abddad8f0373f2e3874ce2369
23,713
h
C
components/soc/src/esp32s2/include/hal/uart_ll.h
jarijokinen/esp-idf
e599b794bebebe66c6bb6d0af31a9451510ad3d4
[ "Apache-2.0" ]
5
2020-07-13T05:38:29.000Z
2021-09-17T09:58:13.000Z
components/soc/src/esp32s2/include/hal/uart_ll.h
jarijokinen/esp-idf
e599b794bebebe66c6bb6d0af31a9451510ad3d4
[ "Apache-2.0" ]
1
2021-03-11T19:14:47.000Z
2021-03-11T19:14:47.000Z
components/soc/src/esp32s2/include/hal/uart_ll.h
jarijokinen/esp-idf
e599b794bebebe66c6bb6d0af31a9451510ad3d4
[ "Apache-2.0" ]
3
2021-03-11T16:53:42.000Z
2021-06-20T05:49:38.000Z
// Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD // // 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. // The LL layer for UART register operations. // Note that most of the register operations in this layer are non-atomic operations. #pragma once #include "hal/uart_types.h" #include "soc/uart_periph.h" #ifdef __cplusplus extern "C" { #endif // The default fifo depth #define UART_LL_FIFO_DEF_LEN (UART_FIFO_LEN) // Get UART hardware instance with giving uart num #define UART_LL_GET_HW(num) (((num) == 0) ? (&UART0) : (&UART1)) // Define UART interrupts typedef enum { UART_INTR_RXFIFO_FULL = (0x1<<0), UART_INTR_TXFIFO_EMPTY = (0x1<<1), UART_INTR_PARITY_ERR = (0x1<<2), UART_INTR_FRAM_ERR = (0x1<<3), UART_INTR_RXFIFO_OVF = (0x1<<4), UART_INTR_DSR_CHG = (0x1<<5), UART_INTR_CTS_CHG = (0x1<<6), UART_INTR_BRK_DET = (0x1<<7), UART_INTR_RXFIFO_TOUT = (0x1<<8), UART_INTR_SW_XON = (0x1<<9), UART_INTR_SW_XOFF = (0x1<<10), UART_INTR_GLITCH_DET = (0x1<<11), UART_INTR_TX_BRK_DONE = (0x1<<12), UART_INTR_TX_BRK_IDLE = (0x1<<13), UART_INTR_TX_DONE = (0x1<<14), UART_INTR_RS485_PARITY_ERR = (0x1<<15), UART_INTR_RS485_FRM_ERR = (0x1<<16), UART_INTR_RS485_CLASH = (0x1<<17), UART_INTR_CMD_CHAR_DET = (0x1<<18), } uart_intr_t; /** * @brief Configure the baud-rate. * * @param hw Beginning address of the peripheral registers. * @param baud The baud rate to be set. When the source clock is APB, the max baud rate is `UART_LL_BITRATE_MAX` * @param source_clk The UART source clock. The source clock can be APB clock or REF_TICK. * If the source clock is REF_TICK, the UART can still work when the APB changes. * * @return None */ static inline void uart_ll_set_baudrate(uart_dev_t *hw, uart_sclk_t source_clk, uint32_t baud) { uint32_t sclk_freq = (source_clk == UART_SCLK_APB) ? APB_CLK_FREQ : REF_CLK_FREQ; uint32_t clk_div = ((sclk_freq) << 4) / baud; // The baud rate configuration register is divided into // an integer part and a fractional part. hw->clk_div.div_int = clk_div >> 4; hw->clk_div.div_frag = clk_div & 0xf; // Configure the UART source clock. hw->conf0.tick_ref_always_on = (source_clk == UART_SCLK_APB); } /** * @brief Get the current baud-rate. * * @param hw Beginning address of the peripheral registers. * * @return The current baudrate */ static inline uint32_t uart_ll_get_baudrate(uart_dev_t *hw) { uint32_t src_clk = hw->conf0.tick_ref_always_on ? APB_CLK_FREQ : REF_CLK_FREQ; typeof(hw->clk_div) div_reg = hw->clk_div; return ((src_clk << 4)) / ((div_reg.div_int << 4) | div_reg.div_frag); } /** * @brief Enable the UART interrupt based on the given mask. * * @param hw Beginning address of the peripheral registers. * @param mask The bitmap of the interrupts need to be enabled. * * @return None */ static inline void uart_ll_ena_intr_mask(uart_dev_t *hw, uint32_t mask) { hw->int_ena.val |= mask; } /** * @brief Disable the UART interrupt based on the given mask. * * @param hw Beginning address of the peripheral registers. * @param mask The bitmap of the interrupts need to be disabled. * * @return None */ static inline void uart_ll_disable_intr_mask(uart_dev_t *hw, uint32_t mask) { hw->int_ena.val &= (~mask); } /** * @brief Get the UART interrupt status. * * @param hw Beginning address of the peripheral registers. * * @return The UART interrupt status. */ static inline uint32_t uart_ll_get_intsts_mask(uart_dev_t *hw) { return hw->int_st.val; } /** * @brief Clear the UART interrupt status based on the given mask. * * @param hw Beginning address of the peripheral registers. * @param mask The bitmap of the interrupts need to be cleared. * * @return None */ static inline void uart_ll_clr_intsts_mask(uart_dev_t *hw, uint32_t mask) { hw->int_clr.val = mask; } /** * @brief Get status of enabled interrupt. * * @param hw Beginning address of the peripheral registers. * * @return interrupt enable value */ static inline uint32_t uart_ll_get_intr_ena_status(uart_dev_t *hw) { return hw->int_ena.val; } /** * @brief Read the UART rxfifo. * * @param hw Beginning address of the peripheral registers. * @param buf The data buffer. The buffer size should be large than 128 byts. * @param rd_len The data length needs to be read. * * @return None. */ static inline void uart_ll_read_rxfifo(uart_dev_t *hw, uint8_t *buf, uint32_t rd_len) { //Get the UART fifo addr, ESP32-S2 have 2 UART uint32_t fifo_addr = (hw == &UART0) ? UART_FIFO_AHB_REG(0) : UART_FIFO_AHB_REG(1); for(int i = 0; i < rd_len; i++) { buf[i] = READ_PERI_REG(fifo_addr); } } /** * @brief Write byte to the UART txfifo. * * @param hw Beginning address of the peripheral registers. * @param buf The data buffer. * @param wr_len The data length needs to be writen. * * @return None */ static inline void uart_ll_write_txfifo(uart_dev_t *hw, const uint8_t *buf, uint32_t wr_len) { //Get the UART fifo addr, ESP32-S2 have 2 UART uint32_t fifo_addr = (hw == &UART0) ? UART_FIFO_AHB_REG(0) : UART_FIFO_AHB_REG(1); for(int i = 0; i < wr_len; i++) { WRITE_PERI_REG(fifo_addr, buf[i]); } } /** * @brief Reset the UART hw rxfifo. * * @param hw Beginning address of the peripheral registers. * * @return None */ static inline void uart_ll_rxfifo_rst(uart_dev_t *hw) { hw->conf0.rxfifo_rst = 1; hw->conf0.rxfifo_rst = 0; } /** * @brief Reset the UART hw txfifo. * * @param hw Beginning address of the peripheral registers. * * @return None */ static inline void uart_ll_txfifo_rst(uart_dev_t *hw) { hw->conf0.txfifo_rst = 1; hw->conf0.txfifo_rst = 0; } /** * @brief Get the length of readable data in UART rxfifo. * * @param hw Beginning address of the peripheral registers. * * @return The readable data length in rxfifo. */ static inline uint32_t uart_ll_get_rxfifo_len(uart_dev_t *hw) { return hw->status.rxfifo_cnt; } /** * @brief Get the writable data length of UART txfifo. * * @param hw Beginning address of the peripheral registers. * * @return The data length of txfifo can be written. */ static inline uint32_t uart_ll_get_txfifo_len(uart_dev_t *hw) { return UART_LL_FIFO_DEF_LEN - hw->status.txfifo_cnt; } /** * @brief Configure the UART stop bit. * * @param hw Beginning address of the peripheral registers. * @param stop_bit The stop bit number to be set. * * @return None. */ static inline void uart_ll_set_stop_bits(uart_dev_t *hw, uart_stop_bits_t stop_bit) { hw->conf0.stop_bit_num = stop_bit; } /** * @brief Get the configuration of the UART stop bit. * * @param hw Beginning address of the peripheral registers. * @param stop_bit The pointer to accept the stop bit configuration * * @return None. */ static inline void uart_ll_get_stop_bits(uart_dev_t *hw, uart_stop_bits_t *stop_bit) { *stop_bit = hw->conf0.stop_bit_num; } /** * @brief Configure the UART parity check mode. * * @param hw Beginning address of the peripheral registers. * @param parity_mode The parity check mode to be set. * * @return None. */ static inline void uart_ll_set_parity(uart_dev_t *hw, uart_parity_t parity_mode) { if(parity_mode != UART_PARITY_DISABLE) { hw->conf0.parity = parity_mode & 0x1; } hw->conf0.parity_en = (parity_mode >> 1) & 0x1; } /** * @brief Get the UART parity check mode configuration. * * @param hw Beginning address of the peripheral registers. * @param parity_mode The pointer to accept the parity check mode configuration. * * @return None. */ static inline void uart_ll_get_parity(uart_dev_t *hw, uart_parity_t *parity_mode) { if(hw->conf0.parity_en) { *parity_mode = 0X2 | hw->conf0.parity; } else { *parity_mode = UART_PARITY_DISABLE; } } /** * @brief Set the UART rxfifo full threshold value. When the data in rxfifo is more than the threshold value, * it will produce rxfifo_full_int_raw interrupt. * * @param hw Beginning address of the peripheral registers. * @param full_thrhd The full threshold value of the rxfifo. `full_thrhd` should be less than `UART_LL_FIFO_DEF_LEN`. * * @return None. */ static inline void uart_ll_set_rxfifo_full_thr(uart_dev_t *hw, uint16_t full_thrhd) { hw->conf1.rxfifo_full_thrhd = full_thrhd; } /** * @brief Set the txfifo empty threshold. when the data length in txfifo is less than threshold value, * it will produce txfifo_empty_int_raw interrupt. * * @param hw Beginning address of the peripheral registers. * @param empty_thrhd The empty threshold of txfifo. * * @return None. */ static inline void uart_ll_set_txfifo_empty_thr(uart_dev_t *hw, uint16_t empty_thrhd) { hw->conf1.txfifo_empty_thrhd = empty_thrhd; } /** * @brief Set the UART rx-idle threshold value. when receiver takes more time than rx_idle_thrhd to receive a byte data, * it will produce frame end signal for uhci to stop receiving data. * * @param hw Beginning address of the peripheral registers. * @param rx_idle_thr The rx-idle threshold to be set. * * @return None. */ static inline void uart_ll_set_rx_idle_thr(uart_dev_t *hw, uint32_t rx_idle_thr) { hw->idle_conf.rx_idle_thrhd = rx_idle_thr; } /** * @brief Configure the duration time between transfers. * * @param hw Beginning address of the peripheral registers. * @param idle_num the duration time between transfers. * * @return None. */ static inline void uart_ll_set_tx_idle_num(uart_dev_t *hw, uint32_t idle_num) { hw->idle_conf.tx_idle_num = idle_num; } /** * @brief Configure the transmiter to send break chars. * * @param hw Beginning address of the peripheral registers. * @param break_num The number of the break chars need to be send. * * @return None. */ static inline void uart_ll_tx_break(uart_dev_t *hw, uint32_t break_num) { if(break_num > 0) { hw->idle_conf.tx_brk_num = break_num; hw->conf0.txd_brk = 1; } else { hw->conf0.txd_brk = 0; } } /** * @brief Configure the UART hardware flow control. * * @param hw Beginning address of the peripheral registers. * @param flow_ctrl The hw flow control configuration. * @param rx_thrs The rx flow control signal will be active if the data length in rxfifo is more than this value. * * @return None. */ static inline void uart_ll_set_hw_flow_ctrl(uart_dev_t *hw, uart_hw_flowcontrol_t flow_ctrl, uint32_t rx_thrs) { //only when UART_HW_FLOWCTRL_RTS is set , will the rx_thresh value be set. if(flow_ctrl & UART_HW_FLOWCTRL_RTS) { hw->mem_conf.rx_flow_thrhd = rx_thrs; hw->conf1.rx_flow_en = 1; } else { hw->conf1.rx_flow_en = 0; } if(flow_ctrl & UART_HW_FLOWCTRL_CTS) { hw->conf0.tx_flow_en = 1; } else { hw->conf0.tx_flow_en = 0; } } /** * @brief Configure the hardware flow control. * * @param hw Beginning address of the peripheral registers. * @param flow_ctrl A pointer to accept the hw flow control configuration. * * @return None. */ static inline void uart_ll_get_hw_flow_ctrl(uart_dev_t *hw, uart_hw_flowcontrol_t *flow_ctrl) { *flow_ctrl = UART_HW_FLOWCTRL_DISABLE; if(hw->conf1.rx_flow_en) { *flow_ctrl |= UART_HW_FLOWCTRL_RTS; } if(hw->conf0.tx_flow_en) { *flow_ctrl |= UART_HW_FLOWCTRL_CTS; } } /** * @brief Configure the software flow control. * * @param hw Beginning address of the peripheral registers. * @param flow_ctrl The UART sofware flow control settings. * @param sw_flow_ctrl_en Set true to enable software flow control, otherwise set it false. * * @return None. */ static inline void uart_ll_set_sw_flow_ctrl(uart_dev_t *hw, uart_sw_flowctrl_t *flow_ctrl, bool sw_flow_ctrl_en) { if(sw_flow_ctrl_en) { hw->flow_conf.xonoff_del = 1; hw->flow_conf.sw_flow_con_en = 1; hw->swfc_conf1.xon_threshold = flow_ctrl->xon_thrd; hw->swfc_conf0.xoff_threshold = flow_ctrl->xoff_thrd; hw->swfc_conf1.xon_char = flow_ctrl->xon_char; hw->swfc_conf0.xoff_char = flow_ctrl->xoff_char; } else { hw->flow_conf.sw_flow_con_en = 0; hw->flow_conf.xonoff_del = 0; } } /** * @brief Configure the AT cmd char. When the receiver receives a continuous AT cmd char, it will produce at_cmd_char_det interrupt. * * @param hw Beginning address of the peripheral registers. * @param cmd_char The AT cmd char configuration.The configuration member is: * - cmd_char The AT cmd character * - char_num The number of received AT cmd char must be equal to or greater than this value * - gap_tout The interval between each AT cmd char, when the duration is less than this value, it will not take this data as AT cmd char * - pre_idle The idle time before the first AT cmd char, when the duration is less than this value, it will not take the previous data as the last AT cmd char * - post_idle The idle time after the last AT cmd char, when the duration is less than this value, it will not take this data as the first AT cmd char * * @return None. */ static inline void uart_ll_set_at_cmd_char(uart_dev_t *hw, uart_at_cmd_t *cmd_char) { hw->at_cmd_char.data = cmd_char->cmd_char; hw->at_cmd_char.char_num = cmd_char->char_num; hw->at_cmd_postcnt.post_idle_num = cmd_char->post_idle; hw->at_cmd_precnt.pre_idle_num = cmd_char->pre_idle; hw->at_cmd_gaptout.rx_gap_tout = cmd_char->gap_tout; } /** * @brief Set the UART data bit mode. * * @param hw Beginning address of the peripheral registers. * @param data_bit The data bit mode to be set. * * @return None. */ static inline void uart_ll_set_data_bit_num(uart_dev_t *hw, uart_word_length_t data_bit) { hw->conf0.bit_num = data_bit; } /** * @brief Get the UART source clock. * * @param hw Beginning address of the peripheral registers. * @param source_clk The pointer to accept the UART source clock configuration. * * @return None. */ static inline void uart_ll_get_sclk(uart_dev_t *hw, uart_sclk_t* source_clk) { *source_clk = hw->conf0.tick_ref_always_on ? UART_SCLK_APB : UART_SCLK_REF_TICK; } /** * @brief Set the rts active level. * * @param hw Beginning address of the peripheral registers. * @param level The rts active level, 0 or 1. * * @return None. */ static inline void uart_ll_set_rts_active_level(uart_dev_t *hw, int level) { hw->conf0.sw_rts = level & 0x1; } /** * @brief Set the dtr active level. * * @param hw Beginning address of the peripheral registers. * @param level The dtr active level, 0 or 1. * * @return None. */ static inline void uart_ll_set_dtr_active_level(uart_dev_t *hw, int level) { hw->conf0.sw_dtr = level & 0x1; } /** * @brief Set the UART wakeup threshold. * * @param hw Beginning address of the peripheral registers. * @param wakeup_thrd The wakeup threshold value to be set. When the input rx edge changes more than this value, * the UART will active from light sleeping mode. * * @return None. */ static inline void uart_ll_set_wakeup_thrd(uart_dev_t *hw, uint32_t wakeup_thrd) { hw->sleep_conf.active_threshold = wakeup_thrd - SOC_UART_MIN_WAKEUP_THRESH; } /** * @brief Configure the UART work in normal mode. * * @param hw Beginning address of the peripheral registers. * * @return None. */ static inline void uart_ll_set_mode_normal(uart_dev_t *hw) { hw->rs485_conf.en = 0; hw->rs485_conf.tx_rx_en = 0; hw->rs485_conf.rx_busy_tx_en = 0; hw->conf0.irda_en = 0; } /** * @brief Configure the UART work in rs485_app_ctrl mode. * * @param hw Beginning address of the peripheral registers. * * @return None. */ static inline void uart_ll_set_mode_rs485_app_ctrl(uart_dev_t *hw) { // Application software control, remove echo hw->rs485_conf.rx_busy_tx_en = 1; hw->conf0.irda_en = 0; hw->conf0.sw_rts = 0; hw->conf0.irda_en = 0; hw->rs485_conf.en = 1; } /** * @brief Configure the UART work in rs485_half_duplex mode. * * @param hw Beginning address of the peripheral registers. * * @return None. */ static inline void uart_ll_set_mode_rs485_half_duplex(uart_dev_t *hw) { // Enable receiver, sw_rts = 1 generates low level on RTS pin hw->conf0.sw_rts = 1; // Must be set to 0 to automatically remove echo hw->rs485_conf.tx_rx_en = 0; // This is to void collision hw->rs485_conf.rx_busy_tx_en = 1; hw->conf0.irda_en = 0; hw->rs485_conf.en = 1; } /** * @brief Configure the UART work in collision_detect mode. * * @param hw Beginning address of the peripheral registers. * * @return None. */ static inline void uart_ll_set_mode_collision_detect(uart_dev_t *hw) { hw->conf0.irda_en = 0; // Transmitters output signal loop back to the receivers input signal hw->rs485_conf.tx_rx_en = 1 ; // Transmitter should send data when the receiver is busy hw->rs485_conf.rx_busy_tx_en = 1; hw->conf0.sw_rts = 0; hw->rs485_conf.en = 1; } /** * @brief Configure the UART work in irda mode. * * @param hw Beginning address of the peripheral registers. * * @return None. */ static inline void uart_ll_set_mode_irda(uart_dev_t *hw) { hw->rs485_conf.en = 0; hw->rs485_conf.tx_rx_en = 0; hw->rs485_conf.rx_busy_tx_en = 0; hw->conf0.sw_rts = 0; hw->conf0.irda_en = 1; } /** * @brief Set uart mode. * * @param hw Beginning address of the peripheral registers. * @param mode The UART mode to be set. * * @return None. */ static inline void uart_ll_set_mode(uart_dev_t *hw, uart_mode_t mode) { switch (mode) { default: case UART_MODE_UART: uart_ll_set_mode_normal(hw); break; case UART_MODE_RS485_COLLISION_DETECT: uart_ll_set_mode_collision_detect(hw); break; case UART_MODE_RS485_APP_CTRL: uart_ll_set_mode_rs485_app_ctrl(hw); break; case UART_MODE_RS485_HALF_DUPLEX: uart_ll_set_mode_rs485_half_duplex(hw); break; case UART_MODE_IRDA: uart_ll_set_mode_irda(hw); break; } } /** * @brief Get the UART AT cmd char configuration. * * @param hw Beginning address of the peripheral registers. * @param cmd_char The Pointer to accept value of UART AT cmd char. * @param char_num Pointer to accept the repeat number of UART AT cmd char. * * @return None. */ static inline void uart_ll_get_at_cmd_char(uart_dev_t *hw, uint8_t *cmd_char, uint8_t *char_num) { *cmd_char = hw->at_cmd_char.data; *char_num = hw->at_cmd_char.char_num; } /** * @brief Get the UART wakeup threshold value. * * @param hw Beginning address of the peripheral registers. * * @return The UART wakeup threshold value. */ static inline uint32_t uart_ll_get_wakeup_thrd(uart_dev_t *hw) { return hw->sleep_conf.active_threshold + SOC_UART_MIN_WAKEUP_THRESH; } /** * @brief Get the UART data bit configuration. * * @param hw Beginning address of the peripheral registers. * @param data_bit The pointer to accept the UART data bit configuration. * * @return The bit mode. */ static inline void uart_ll_get_data_bit_num(uart_dev_t *hw, uart_word_length_t *data_bit) { *data_bit = hw->conf0.bit_num; } /** * @brief Check if the UART sending state machine is in the IDLE state. * * @param hw Beginning address of the peripheral registers. * * @return True if the state machine is in the IDLE state, otherwise false is returned. */ static inline bool uart_ll_is_tx_idle(uart_dev_t *hw) { return ((hw->status.txfifo_cnt == 0) && (hw->fsm_status.st_utx_out == 0)); } /** * @brief Check if the UART rts flow control is enabled. * * @param hw Beginning address of the peripheral registers. * * @return True if hw rts flow control is enabled, otherwise false is returned. */ static inline bool uart_ll_is_hw_rts_en(uart_dev_t *hw) { return hw->conf1.rx_flow_en; } /** * @brief Check if the UART cts flow control is enabled. * * @param hw Beginning address of the peripheral registers. * * @return True if hw cts flow control is enabled, otherwise false is returned. */ static inline bool uart_ll_is_hw_cts_en(uart_dev_t *hw) { return hw->conf0.tx_flow_en; } /** * @brief Configure TX signal loop back to RX module, just for the testing purposes * * @param hw Beginning address of the peripheral registers. * @param loop_back_en Set ture to enable the loop back function, else set it false. * * @return None */ static inline void uart_ll_set_loop_back(uart_dev_t *hw, bool loop_back_en) { hw->conf0.loopback = loop_back_en; } /** * @brief Inverse the UART signal with the given mask. * * @param hw Beginning address of the peripheral registers. * @param inv_mask The UART signal bitmap needs to be inversed. * Use the ORred mask of `uart_signal_inv_t`; * * @return None. */ static inline void uart_ll_inverse_signal(uart_dev_t *hw, uint32_t inv_mask) { typeof(hw->conf0) conf0_reg = hw->conf0; conf0_reg.irda_tx_inv = (inv_mask & UART_SIGNAL_IRDA_TX_INV) ? 1 : 0; conf0_reg.irda_rx_inv = (inv_mask & UART_SIGNAL_IRDA_RX_INV) ? 1 : 0; conf0_reg.rxd_inv = (inv_mask & UART_SIGNAL_RXD_INV) ? 1 : 0; conf0_reg.cts_inv = (inv_mask & UART_SIGNAL_CTS_INV) ? 1 : 0; conf0_reg.dsr_inv = (inv_mask & UART_SIGNAL_DSR_INV) ? 1 : 0; conf0_reg.txd_inv = (inv_mask & UART_SIGNAL_TXD_INV) ? 1 : 0; conf0_reg.rts_inv = (inv_mask & UART_SIGNAL_RTS_INV) ? 1 : 0; conf0_reg.dtr_inv = (inv_mask & UART_SIGNAL_DTR_INV) ? 1 : 0; hw->conf0.val = conf0_reg.val; } /** * @brief Configure the timeout value for receiver receiving a byte, and enable rx timeout function. * * @param hw Beginning address of the peripheral registers. * @param tout_thrd The timeout value as UART bit time. The rx timeout function will be disabled if `tout_thrd == 0`. * * @return None. */ static inline void uart_ll_set_rx_tout(uart_dev_t *hw, uint16_t tout_thrd) { uint16_t tout_val = tout_thrd; if(tout_thrd > 0) { hw->mem_conf.rx_tout_thrhd = tout_val; hw->conf1.rx_tout_en = 1; } else { hw->conf1.rx_tout_en = 0; } } /** * @brief Get the timeout value for receiver receiving a byte. * * @param hw Beginning address of the peripheral registers. * * @return tout_thr The timeout threshold value. If timeout feature is disabled returns 0. */ static inline uint16_t uart_ll_get_rx_tout_thr(uart_dev_t *hw) { uint16_t tout_thrd = 0; if(hw->conf1.rx_tout_en > 0) { tout_thrd = hw->mem_conf.rx_tout_thrhd; } return tout_thrd; } /** * @brief Get UART maximum timeout threshold. * * @param hw Beginning address of the peripheral registers. * * @return maximum timeout threshold. */ static inline uint16_t uart_ll_max_tout_thrd(uart_dev_t *hw) { return UART_RX_TOUT_THRHD_V; } #ifdef __cplusplus } #endif
29.420596
167
0.695779
828692838a0c1fb7fa3e0057efa0e27069d8ac38
2,396
h
C
game-client/src/DebugDraw.h
zfrye06/Loque
bbb0e7a0a5d5374c27b83bba5b13bc191b03ebb0
[ "MIT" ]
null
null
null
game-client/src/DebugDraw.h
zfrye06/Loque
bbb0e7a0a5d5374c27b83bba5b13bc191b03ebb0
[ "MIT" ]
null
null
null
game-client/src/DebugDraw.h
zfrye06/Loque
bbb0e7a0a5d5374c27b83bba5b13bc191b03ebb0
[ "MIT" ]
null
null
null
/** * @file DebugDraw.h * @brief Practically this entire file was rewritten by me, so I pretty much own it now. It had to be re-written due to the 2011 SFML being completely different... It is just the hooks for box2D to call in order to draw stuff. * @author Dalton Nell * @version 0.0.0 * @date 2016-12-06 */ /* Copyright (C) 2011 Allen Jordan () Copyright (C) 2011 Xabier Larrakoetxea (slok) 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 3 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, see <http://www.gnu.org/licenses/>. */ #ifndef DEBUGDRAW_H #define DEBUGDRAW_H #include <Box2D/Box2D.h> #include <iostream> #include <SFML/System.hpp> #include <SFML/Graphics.hpp> // meter to pixel ratio.. #define RATIO 64.f // Default alpha, lines have the same alpha + 50 #define ALPHA 75 class DebugDraw : public b2Draw { public: DebugDraw(sf::RenderTarget &window); virtual ~DebugDraw(); void DrawPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color); void DrawSolidPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color); void DrawCircle(const b2Vec2& center, float32 radius, const b2Color& color); void DrawSolidCircle(const b2Vec2& center, float32 radius, const b2Vec2& axis, const b2Color& color); void DrawSegment(const b2Vec2& p1, const b2Vec2& p2, const b2Color& color); void DrawTransform(const b2Transform& xf); void DrawPoint(const b2Vec2& p, float32 size, const b2Color& color); void DrawString(int x, int y, const char* string); void DrawAABB(b2AABB* aabb, const b2Color& color); sf::Color B2SFColor(const b2Color &color, int alpha); void DrawMouseJoint(b2Vec2& p1, b2Vec2& p2, const b2Color &boxColor, const b2Color &lineColor); private: sf::RenderTarget *window; }; #endif // DEBUGDRAW_H
38.645161
226
0.709098
9638c7db5a8ade17b1eec3f3903572d7a07811f5
22,808
h
C
components/esp_ringbuf/include/freertos/ringbuf.h
DCNick3/esp-idf
b0150615dff529662772a60dcb57d5b559f480e2
[ "Apache-2.0" ]
2
2021-03-24T01:20:25.000Z
2021-04-15T20:57:51.000Z
components/esp_ringbuf/include/freertos/ringbuf.h
DCNick3/esp-idf
b0150615dff529662772a60dcb57d5b559f480e2
[ "Apache-2.0" ]
null
null
null
components/esp_ringbuf/include/freertos/ringbuf.h
DCNick3/esp-idf
b0150615dff529662772a60dcb57d5b559f480e2
[ "Apache-2.0" ]
1
2020-11-25T10:54:24.000Z
2020-11-25T10:54:24.000Z
// Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD // // 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. #ifndef FREERTOS_RINGBUF_H #define FREERTOS_RINGBUF_H #ifndef INC_FREERTOS_H #error "include FreeRTOS.h" must appear in source files before "include ringbuf.h" #endif #ifdef __cplusplus extern "C" { #endif #include <freertos/queue.h> /** * Type by which ring buffers are referenced. For example, a call to xRingbufferCreate() * returns a RingbufHandle_t variable that can then be used as a parameter to * xRingbufferSend(), xRingbufferReceive(), etc. */ typedef void * RingbufHandle_t; typedef enum { /** * No-split buffers will only store an item in contiguous memory and will * never split an item. Each item requires an 8 byte overhead for a header * and will always internally occupy a 32-bit aligned size of space. */ RINGBUF_TYPE_NOSPLIT = 0, /** * Allow-split buffers will split an item into two parts if necessary in * order to store it. Each item requires an 8 byte overhead for a header, * splitting incurs an extra header. Each item will always internally occupy * a 32-bit aligned size of space. */ RINGBUF_TYPE_ALLOWSPLIT, /** * Byte buffers store data as a sequence of bytes and do not maintain separate * items, therefore byte buffers have no overhead. All data is stored as a * sequence of byte and any number of bytes can be sent or retrieved each * time. */ RINGBUF_TYPE_BYTEBUF, RINGBUF_TYPE_MAX, } RingbufferType_t; /** * @brief Struct that is equivalent in size to the ring buffer's data structure * * The contents of this struct are not meant to be used directly. This * structure is meant to be used when creating a statically allocated ring * buffer where this struct is of the exact size required to store a ring * buffer's control data structure. * * @note The CONFIG_FREERTOS_SUPPORT_STATIC_ALLOCATION option must be enabled for * this structure to be available. */ #if ( configSUPPORT_STATIC_ALLOCATION == 1) typedef struct xSTATIC_RINGBUFFER { /** @cond */ //Doxygen command to hide this structure from API Reference size_t xDummy1[2]; UBaseType_t uxDummy2; BaseType_t xDummy3; void *pvDummy4[11]; StaticSemaphore_t xDummy5[2]; portMUX_TYPE muxDummy; /** @endcond */ } StaticRingbuffer_t; #endif /** * @brief Create a ring buffer * * @param[in] xBufferSize Size of the buffer in bytes. Note that items require * space for overhead in no-split/allow-split buffers * @param[in] xBufferType Type of ring buffer, see documentation. * * @note xBufferSize of no-split/allow-split buffers will be rounded up to the nearest 32-bit aligned size. * * @return A handle to the created ring buffer, or NULL in case of error. */ RingbufHandle_t xRingbufferCreate(size_t xBufferSize, RingbufferType_t xBufferType); /** * @brief Create a ring buffer of type RINGBUF_TYPE_NOSPLIT for a fixed item_size * * This API is similar to xRingbufferCreate(), but it will internally allocate * additional space for the headers. * * @param[in] xItemSize Size of each item to be put into the ring buffer * @param[in] xItemNum Maximum number of items the buffer needs to hold simultaneously * * @return A RingbufHandle_t handle to the created ring buffer, or NULL in case of error. */ RingbufHandle_t xRingbufferCreateNoSplit(size_t xItemSize, size_t xItemNum); /** * @brief Create a ring buffer but manually provide the required memory * * @param[in] xBufferSize Size of the buffer in bytes. * @param[in] xBufferType Type of ring buffer, see documentation * @param[in] pucRingbufferStorage Pointer to the ring buffer's storage area. * Storage area must of the same size as specified by xBufferSize * @param[in] pxStaticRingbuffer Pointed to a struct of type StaticRingbuffer_t * which will be used to hold the ring buffer's data structure * * @note The CONFIG_FREERTOS_SUPPORT_STATIC_ALLOCATION option must be enabled * for this to be available * * @note xBufferSize of no-split/allow-split buffers MUST be 32-bit aligned. * * @return A handle to the created ring buffer */ #if ( configSUPPORT_STATIC_ALLOCATION == 1) RingbufHandle_t xRingbufferCreateStatic(size_t xBufferSize, RingbufferType_t xBufferType, uint8_t *pucRingbufferStorage, StaticRingbuffer_t *pxStaticRingbuffer); #endif /** * @brief Insert an item into the ring buffer * * Attempt to insert an item into the ring buffer. This function will block until * enough free space is available or until it times out. * * @param[in] xRingbuffer Ring buffer to insert the item into * @param[in] pvItem Pointer to data to insert. NULL is allowed if xItemSize is 0. * @param[in] xItemSize Size of data to insert. * @param[in] xTicksToWait Ticks to wait for room in the ring buffer. * * @note For no-split/allow-split ring buffers, the actual size of memory that * the item will occupy will be rounded up to the nearest 32-bit aligned * size. This is done to ensure all items are always stored in 32-bit * aligned fashion. * * @return * - pdTRUE if succeeded * - pdFALSE on time-out or when the data is larger than the maximum permissible size of the buffer */ BaseType_t xRingbufferSend(RingbufHandle_t xRingbuffer, const void *pvItem, size_t xItemSize, TickType_t xTicksToWait); /** * @brief Insert an item into the ring buffer in an ISR * * Attempt to insert an item into the ring buffer from an ISR. This function * will return immediately if there is insufficient free space in the buffer. * * @param[in] xRingbuffer Ring buffer to insert the item into * @param[in] pvItem Pointer to data to insert. NULL is allowed if xItemSize is 0. * @param[in] xItemSize Size of data to insert. * @param[out] pxHigherPriorityTaskWoken Value pointed to will be set to pdTRUE if the function woke up a higher priority task. * * @note For no-split/allow-split ring buffers, the actual size of memory that * the item will occupy will be rounded up to the nearest 32-bit aligned * size. This is done to ensure all items are always stored in 32-bit * aligned fashion. * * @return * - pdTRUE if succeeded * - pdFALSE when the ring buffer does not have space. */ BaseType_t xRingbufferSendFromISR(RingbufHandle_t xRingbuffer, const void *pvItem, size_t xItemSize, BaseType_t *pxHigherPriorityTaskWoken); /** * @brief Acquire memory from the ring buffer to be written to by an external * source and to be sent later. * * Attempt to allocate buffer for an item to be sent into the ring buffer. This * function will block until enough free space is available or until it * timesout. * * The item, as well as the following items ``SendAcquire`` or ``Send`` after it, * will not be able to be read from the ring buffer until this item is actually * sent into the ring buffer. * * @param[in] xRingbuffer Ring buffer to allocate the memory * @param[out] ppvItem Double pointer to memory acquired (set to NULL if no memory were retrieved) * @param[in] xItemSize Size of item to acquire. * @param[in] xTicksToWait Ticks to wait for room in the ring buffer. * * @note Only applicable for no-split ring buffers now, the actual size of * memory that the item will occupy will be rounded up to the nearest 32-bit * aligned size. This is done to ensure all items are always stored in 32-bit * aligned fashion. * * @return * - pdTRUE if succeeded * - pdFALSE on time-out or when the data is larger than the maximum permissible size of the buffer */ BaseType_t xRingbufferSendAcquire(RingbufHandle_t xRingbuffer, void **ppvItem, size_t xItemSize, TickType_t xTicksToWait); /** * @brief Actually send an item into the ring buffer allocated before by * ``xRingbufferSendAcquire``. * * @param[in] xRingbuffer Ring buffer to insert the item into * @param[in] pvItem Pointer to item in allocated memory to insert. * * @note Only applicable for no-split ring buffers. Only call for items * allocated by ``xRingbufferSendAcquire``. * * @return * - pdTRUE if succeeded * - pdFALSE if fail for some reason. */ BaseType_t xRingbufferSendComplete(RingbufHandle_t xRingbuffer, void *pvItem); /** * @brief Retrieve an item from the ring buffer * * Attempt to retrieve an item from the ring buffer. This function will block * until an item is available or until it times out. * * @param[in] xRingbuffer Ring buffer to retrieve the item from * @param[out] pxItemSize Pointer to a variable to which the size of the retrieved item will be written. * @param[in] xTicksToWait Ticks to wait for items in the ring buffer. * * @note A call to vRingbufferReturnItem() is required after this to free the item retrieved. * * @return * - Pointer to the retrieved item on success; *pxItemSize filled with the length of the item. * - NULL on timeout, *pxItemSize is untouched in that case. */ void *xRingbufferReceive(RingbufHandle_t xRingbuffer, size_t *pxItemSize, TickType_t xTicksToWait); /** * @brief Retrieve an item from the ring buffer in an ISR * * Attempt to retrieve an item from the ring buffer. This function returns immediately * if there are no items available for retrieval * * @param[in] xRingbuffer Ring buffer to retrieve the item from * @param[out] pxItemSize Pointer to a variable to which the size of the * retrieved item will be written. * * @note A call to vRingbufferReturnItemFromISR() is required after this to free the item retrieved. * @note Byte buffers do not allow multiple retrievals before returning an item * @note Two calls to RingbufferReceiveFromISR() are required if the bytes wrap around the end of the ring buffer. * * @return * - Pointer to the retrieved item on success; *pxItemSize filled with the length of the item. * - NULL when the ring buffer is empty, *pxItemSize is untouched in that case. */ void *xRingbufferReceiveFromISR(RingbufHandle_t xRingbuffer, size_t *pxItemSize); /** * @brief Retrieve a split item from an allow-split ring buffer * * Attempt to retrieve a split item from an allow-split ring buffer. If the item * is not split, only a single item is retried. If the item is split, both parts * will be retrieved. This function will block until an item is available or * until it times out. * * @param[in] xRingbuffer Ring buffer to retrieve the item from * @param[out] ppvHeadItem Double pointer to first part (set to NULL if no items were retrieved) * @param[out] ppvTailItem Double pointer to second part (set to NULL if item is not split) * @param[out] pxHeadItemSize Pointer to size of first part (unmodified if no items were retrieved) * @param[out] pxTailItemSize Pointer to size of second part (unmodified if item is not split) * @param[in] xTicksToWait Ticks to wait for items in the ring buffer. * * @note Call(s) to vRingbufferReturnItem() is required after this to free up the item(s) retrieved. * @note This function should only be called on allow-split buffers * * @return * - pdTRUE if an item (split or unsplit) was retrieved * - pdFALSE when no item was retrieved */ BaseType_t xRingbufferReceiveSplit(RingbufHandle_t xRingbuffer, void **ppvHeadItem, void **ppvTailItem, size_t *pxHeadItemSize, size_t *pxTailItemSize, TickType_t xTicksToWait); /** * @brief Retrieve a split item from an allow-split ring buffer in an ISR * * Attempt to retrieve a split item from an allow-split ring buffer. If the item * is not split, only a single item is retried. If the item is split, both parts * will be retrieved. This function returns immediately if there are no items * available for retrieval * * @param[in] xRingbuffer Ring buffer to retrieve the item from * @param[out] ppvHeadItem Double pointer to first part (set to NULL if no items were retrieved) * @param[out] ppvTailItem Double pointer to second part (set to NULL if item is not split) * @param[out] pxHeadItemSize Pointer to size of first part (unmodified if no items were retrieved) * @param[out] pxTailItemSize Pointer to size of second part (unmodified if item is not split) * * @note Calls to vRingbufferReturnItemFromISR() is required after this to free up the item(s) retrieved. * @note This function should only be called on allow-split buffers * * @return * - pdTRUE if an item (split or unsplit) was retrieved * - pdFALSE when no item was retrieved */ BaseType_t xRingbufferReceiveSplitFromISR(RingbufHandle_t xRingbuffer, void **ppvHeadItem, void **ppvTailItem, size_t *pxHeadItemSize, size_t *pxTailItemSize); /** * @brief Retrieve bytes from a byte buffer, specifying the maximum amount of bytes to retrieve * * Attempt to retrieve data from a byte buffer whilst specifying a maximum number * of bytes to retrieve. This function will block until there is data available * for retrieval or until it times out. * * @param[in] xRingbuffer Ring buffer to retrieve the item from * @param[out] pxItemSize Pointer to a variable to which the size of the retrieved item will be written. * @param[in] xTicksToWait Ticks to wait for items in the ring buffer. * @param[in] xMaxSize Maximum number of bytes to return. * * @note A call to vRingbufferReturnItem() is required after this to free up the data retrieved. * @note This function should only be called on byte buffers * @note Byte buffers do not allow multiple retrievals before returning an item * @note Two calls to RingbufferReceiveUpTo() are required if the bytes wrap around the end of the ring buffer. * * @return * - Pointer to the retrieved item on success; *pxItemSize filled with * the length of the item. * - NULL on timeout, *pxItemSize is untouched in that case. */ void *xRingbufferReceiveUpTo(RingbufHandle_t xRingbuffer, size_t *pxItemSize, TickType_t xTicksToWait, size_t xMaxSize); /** * @brief Retrieve bytes from a byte buffer, specifying the maximum amount of * bytes to retrieve. Call this from an ISR. * * Attempt to retrieve bytes from a byte buffer whilst specifying a maximum number * of bytes to retrieve. This function will return immediately if there is no data * available for retrieval. * * @param[in] xRingbuffer Ring buffer to retrieve the item from * @param[out] pxItemSize Pointer to a variable to which the size of the retrieved item will be written. * @param[in] xMaxSize Maximum number of bytes to return. * * @note A call to vRingbufferReturnItemFromISR() is required after this to free up the data received. * @note This function should only be called on byte buffers * @note Byte buffers do not allow multiple retrievals before returning an item * * @return * - Pointer to the retrieved item on success; *pxItemSize filled with * the length of the item. * - NULL when the ring buffer is empty, *pxItemSize is untouched in that case. */ void *xRingbufferReceiveUpToFromISR(RingbufHandle_t xRingbuffer, size_t *pxItemSize, size_t xMaxSize); /** * @brief Return a previously-retrieved item to the ring buffer * * @param[in] xRingbuffer Ring buffer the item was retrieved from * @param[in] pvItem Item that was received earlier * * @note If a split item is retrieved, both parts should be returned by calling this function twice */ void vRingbufferReturnItem(RingbufHandle_t xRingbuffer, void *pvItem); /** * @brief Return a previously-retrieved item to the ring buffer from an ISR * * @param[in] xRingbuffer Ring buffer the item was retrieved from * @param[in] pvItem Item that was received earlier * @param[out] pxHigherPriorityTaskWoken Value pointed to will be set to pdTRUE * if the function woke up a higher priority task. * * @note If a split item is retrieved, both parts should be returned by calling this function twice */ void vRingbufferReturnItemFromISR(RingbufHandle_t xRingbuffer, void *pvItem, BaseType_t *pxHigherPriorityTaskWoken); /** * @brief Delete a ring buffer * * @param[in] xRingbuffer Ring buffer to delete * * @note This function will not deallocate any memory if the ring buffer was * created using xRingbufferCreateStatic(). Deallocation must be done * manually be the user. */ void vRingbufferDelete(RingbufHandle_t xRingbuffer); /** * @brief Get maximum size of an item that can be placed in the ring buffer * * This function returns the maximum size an item can have if it was placed in * an empty ring buffer. * * @param[in] xRingbuffer Ring buffer to query * * @note The max item size for a no-split buffer is limited to * ((buffer_size/2)-header_size). This limit is imposed so that an item * of max item size can always be sent to the an empty no-split buffer * regardless of the internal positions of the buffer's read/write/free * pointers. * * @return Maximum size, in bytes, of an item that can be placed in a ring buffer. */ size_t xRingbufferGetMaxItemSize(RingbufHandle_t xRingbuffer); /** * @brief Get current free size available for an item/data in the buffer * * This gives the real time free space available for an item/data in the ring * buffer. This represents the maximum size an item/data can have if it was * currently sent to the ring buffer. * * @warning This API is not thread safe. So, if multiple threads are accessing * the same ring buffer, it is the application's responsibility to * ensure atomic access to this API and the subsequent Send * * @note An empty no-split buffer has a max current free size for an item * that is limited to ((buffer_size/2)-header_size). See API reference * for xRingbufferGetMaxItemSize(). * * @param[in] xRingbuffer Ring buffer to query * * @return Current free size, in bytes, available for an entry */ size_t xRingbufferGetCurFreeSize(RingbufHandle_t xRingbuffer); /** * @brief Add the ring buffer's read semaphore to a queue set. * * The ring buffer's read semaphore indicates that data has been written * to the ring buffer. This function adds the ring buffer's read semaphore to * a queue set. * * @param[in] xRingbuffer Ring buffer to add to the queue set * @param[in] xQueueSet Queue set to add the ring buffer's read semaphore to * * @return * - pdTRUE on success, pdFALSE otherwise */ BaseType_t xRingbufferAddToQueueSetRead(RingbufHandle_t xRingbuffer, QueueSetHandle_t xQueueSet); /** * @brief Check if the selected queue set member is the ring buffer's read semaphore * * This API checks if queue set member returned from xQueueSelectFromSet() * is the read semaphore of this ring buffer. If so, this indicates the ring buffer * has items waiting to be retrieved. * * @param[in] xRingbuffer Ring buffer which should be checked * @param[in] xMember Member returned from xQueueSelectFromSet * * @return * - pdTRUE when semaphore belongs to ring buffer * - pdFALSE otherwise. */ BaseType_t xRingbufferCanRead(RingbufHandle_t xRingbuffer, QueueSetMemberHandle_t xMember); /** * @brief Remove the ring buffer's read semaphore from a queue set. * * This specifically removes a ring buffer's read semaphore from a queue set. The * read semaphore is used to indicate when data has been written to the ring buffer * * @param[in] xRingbuffer Ring buffer to remove from the queue set * @param[in] xQueueSet Queue set to remove the ring buffer's read semaphore from * * @return * - pdTRUE on success * - pdFALSE otherwise */ BaseType_t xRingbufferRemoveFromQueueSetRead(RingbufHandle_t xRingbuffer, QueueSetHandle_t xQueueSet); /** * @brief Get information about ring buffer status * * Get information of the a ring buffer's current status such as * free/read/write pointer positions, and number of items waiting to be retrieved. * Arguments can be set to NULL if they are not required. * * @param[in] xRingbuffer Ring buffer to remove from the queue set * @param[out] uxFree Pointer use to store free pointer position * @param[out] uxRead Pointer use to store read pointer position * @param[out] uxWrite Pointer use to store write pointer position * @param[out] uxAcquire Pointer use to store acquire pointer position * @param[out] uxItemsWaiting Pointer use to store number of items (bytes for byte buffer) waiting to be retrieved */ void vRingbufferGetInfo(RingbufHandle_t xRingbuffer, UBaseType_t *uxFree, UBaseType_t *uxRead, UBaseType_t *uxWrite, UBaseType_t *uxAcquire, UBaseType_t *uxItemsWaiting); /** * @brief Debugging function to print the internal pointers in the ring buffer * * @param xRingbuffer Ring buffer to show */ void xRingbufferPrintInfo(RingbufHandle_t xRingbuffer); #ifdef __cplusplus } #endif #endif /* FREERTOS_RINGBUF_H */
43.526718
130
0.692915
aacee45616fc44792f768135abc99dd6f429f003
50,925
c
C
linux-3.0.1/mm/kmemleak.c
tonghua209/samsun6410_linux_3_0_0_1_for_aws
31aa0dc27c4aab51a92309a74fd84ca65e8c6a58
[ "Apache-2.0" ]
4
2016-07-01T04:50:02.000Z
2021-11-14T21:29:42.000Z
linux-3.0/mm/kmemleak.c
spartan263/vizio_oss
74270002d874391148119b48882db6816e7deedc
[ "Linux-OpenIB" ]
null
null
null
linux-3.0/mm/kmemleak.c
spartan263/vizio_oss
74270002d874391148119b48882db6816e7deedc
[ "Linux-OpenIB" ]
1
2020-04-03T14:00:39.000Z
2020-04-03T14:00:39.000Z
/* * mm/kmemleak.c * * Copyright (C) 2008 ARM Limited * Written by Catalin Marinas <catalin.marinas@arm.com> * * 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 * * * For more information on the algorithm and kmemleak usage, please see * Documentation/kmemleak.txt. * * Notes on locking * ---------------- * * The following locks and mutexes are used by kmemleak: * * - kmemleak_lock (rwlock): protects the object_list modifications and * accesses to the object_tree_root. The object_list is the main list * holding the metadata (struct kmemleak_object) for the allocated memory * blocks. The object_tree_root is a priority search tree used to look-up * metadata based on a pointer to the corresponding memory block. The * kmemleak_object structures are added to the object_list and * object_tree_root in the create_object() function called from the * kmemleak_alloc() callback and removed in delete_object() called from the * kmemleak_free() callback * - kmemleak_object.lock (spinlock): protects a kmemleak_object. Accesses to * the metadata (e.g. count) are protected by this lock. Note that some * members of this structure may be protected by other means (atomic or * kmemleak_lock). This lock is also held when scanning the corresponding * memory block to avoid the kernel freeing it via the kmemleak_free() * callback. This is less heavyweight than holding a global lock like * kmemleak_lock during scanning * - scan_mutex (mutex): ensures that only one thread may scan the memory for * unreferenced objects at a time. The gray_list contains the objects which * are already referenced or marked as false positives and need to be * scanned. This list is only modified during a scanning episode when the * scan_mutex is held. At the end of a scan, the gray_list is always empty. * Note that the kmemleak_object.use_count is incremented when an object is * added to the gray_list and therefore cannot be freed. This mutex also * prevents multiple users of the "kmemleak" debugfs file together with * modifications to the memory scanning parameters including the scan_thread * pointer * * The kmemleak_object structures have a use_count incremented or decremented * using the get_object()/put_object() functions. When the use_count becomes * 0, this count can no longer be incremented and put_object() schedules the * kmemleak_object freeing via an RCU callback. All calls to the get_object() * function must be protected by rcu_read_lock() to avoid accessing a freed * structure. */ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #include <linux/init.h> #include <linux/kernel.h> #include <linux/list.h> #include <linux/sched.h> #include <linux/jiffies.h> #include <linux/delay.h> #include <linux/module.h> #include <linux/kthread.h> #include <linux/prio_tree.h> #include <linux/fs.h> #include <linux/debugfs.h> #include <linux/seq_file.h> #include <linux/cpumask.h> #include <linux/spinlock.h> #include <linux/mutex.h> #include <linux/rcupdate.h> #include <linux/stacktrace.h> #include <linux/cache.h> #include <linux/percpu.h> #include <linux/hardirq.h> #include <linux/mmzone.h> #include <linux/slab.h> #include <linux/thread_info.h> #include <linux/err.h> #include <linux/uaccess.h> #include <linux/string.h> #include <linux/nodemask.h> #include <linux/mm.h> #include <linux/workqueue.h> #include <linux/crc32.h> #include <asm/sections.h> #include <asm/processor.h> #include <asm/atomic.h> #include <linux/kmemcheck.h> #include <linux/kmemleak.h> /* * Kmemleak configuration and common defines. */ #define MAX_TRACE 16 /* stack trace length */ #define MSECS_MIN_AGE 5000 /* minimum object age for reporting */ #define SECS_FIRST_SCAN 60 /* delay before the first scan */ #define SECS_SCAN_WAIT 600 /* subsequent auto scanning delay */ #define MAX_SCAN_SIZE 4096 /* maximum size of a scanned block */ #define BYTES_PER_POINTER sizeof(void *) /* GFP bitmask for kmemleak internal allocations */ #define gfp_kmemleak_mask(gfp) (((gfp) & (GFP_KERNEL | GFP_ATOMIC)) | \ __GFP_NORETRY | __GFP_NOMEMALLOC | \ __GFP_NOWARN) /* scanning area inside a memory block */ struct kmemleak_scan_area { struct hlist_node node; unsigned long start; size_t size; }; #define KMEMLEAK_GREY 0 #define KMEMLEAK_BLACK -1 /* * Structure holding the metadata for each allocated memory block. * Modifications to such objects should be made while holding the * object->lock. Insertions or deletions from object_list, gray_list or * tree_node are already protected by the corresponding locks or mutex (see * the notes on locking above). These objects are reference-counted * (use_count) and freed using the RCU mechanism. */ struct kmemleak_object { spinlock_t lock; unsigned long flags; /* object status flags */ struct list_head object_list; struct list_head gray_list; struct prio_tree_node tree_node; struct rcu_head rcu; /* object_list lockless traversal */ /* object usage count; object freed when use_count == 0 */ atomic_t use_count; unsigned long pointer; size_t size; /* minimum number of a pointers found before it is considered leak */ int min_count; /* the total number of pointers found pointing to this object */ int count; /* checksum for detecting modified objects */ u32 checksum; /* memory ranges to be scanned inside an object (empty for all) */ struct hlist_head area_list; unsigned long trace[MAX_TRACE]; unsigned int trace_len; unsigned long jiffies; /* creation timestamp */ pid_t pid; /* pid of the current task */ char comm[TASK_COMM_LEN]; /* executable name */ }; /* flag representing the memory block allocation status */ #define OBJECT_ALLOCATED (1 << 0) /* flag set after the first reporting of an unreference object */ #define OBJECT_REPORTED (1 << 1) /* flag set to not scan the object */ #define OBJECT_NO_SCAN (1 << 2) /* number of bytes to print per line; must be 16 or 32 */ #define HEX_ROW_SIZE 16 /* number of bytes to print at a time (1, 2, 4, 8) */ #define HEX_GROUP_SIZE 1 /* include ASCII after the hex output */ #define HEX_ASCII 1 /* max number of lines to be printed */ #define HEX_MAX_LINES 2 /* the list of all allocated objects */ static LIST_HEAD(object_list); /* the list of gray-colored objects (see color_gray comment below) */ static LIST_HEAD(gray_list); /* prio search tree for object boundaries */ static struct prio_tree_root object_tree_root; /* rw_lock protecting the access to object_list and prio_tree_root */ static DEFINE_RWLOCK(kmemleak_lock); /* allocation caches for kmemleak internal data */ static struct kmem_cache *object_cache; static struct kmem_cache *scan_area_cache; /* set if tracing memory operations is enabled */ static atomic_t kmemleak_enabled = ATOMIC_INIT(0); /* set in the late_initcall if there were no errors */ static atomic_t kmemleak_initialized = ATOMIC_INIT(0); /* enables or disables early logging of the memory operations */ static atomic_t kmemleak_early_log = ATOMIC_INIT(1); /* set if a fata kmemleak error has occurred */ static atomic_t kmemleak_error = ATOMIC_INIT(0); /* minimum and maximum address that may be valid pointers */ static unsigned long min_addr = ULONG_MAX; static unsigned long max_addr; static struct task_struct *scan_thread; /* used to avoid reporting of recently allocated objects */ static unsigned long jiffies_min_age; static unsigned long jiffies_last_scan; /* delay between automatic memory scannings */ static signed long jiffies_scan_wait; /* enables or disables the task stacks scanning */ static int kmemleak_stack_scan = 1; /* protects the memory scanning, parameters and debug/kmemleak file access */ static DEFINE_MUTEX(scan_mutex); /* setting kmemleak=on, will set this var, skipping the disable */ static int kmemleak_skip_disable; /* * Early object allocation/freeing logging. Kmemleak is initialized after the * kernel allocator. However, both the kernel allocator and kmemleak may * allocate memory blocks which need to be tracked. Kmemleak defines an * arbitrary buffer to hold the allocation/freeing information before it is * fully initialized. */ /* kmemleak operation type for early logging */ enum { KMEMLEAK_ALLOC, KMEMLEAK_FREE, KMEMLEAK_FREE_PART, KMEMLEAK_NOT_LEAK, KMEMLEAK_IGNORE, KMEMLEAK_SCAN_AREA, KMEMLEAK_NO_SCAN }; /* * Structure holding the information passed to kmemleak callbacks during the * early logging. */ struct early_log { int op_type; /* kmemleak operation type */ const void *ptr; /* allocated/freed memory block */ size_t size; /* memory block size */ int min_count; /* minimum reference count */ unsigned long trace[MAX_TRACE]; /* stack trace */ unsigned int trace_len; /* stack trace length */ }; /* early logging buffer and current position */ static struct early_log early_log[CONFIG_DEBUG_KMEMLEAK_EARLY_LOG_SIZE] __initdata; static int crt_early_log __initdata; static void kmemleak_disable(void); /* * Print a warning and dump the stack trace. */ #define kmemleak_warn(x...) do { \ pr_warning(x); \ dump_stack(); \ } while (0) /* * Macro invoked when a serious kmemleak condition occurred and cannot be * recovered from. Kmemleak will be disabled and further allocation/freeing * tracing no longer available. */ #define kmemleak_stop(x...) do { \ kmemleak_warn(x); \ kmemleak_disable(); \ } while (0) /* * Printing of the objects hex dump to the seq file. The number of lines to be * printed is limited to HEX_MAX_LINES to prevent seq file spamming. The * actual number of printed bytes depends on HEX_ROW_SIZE. It must be called * with the object->lock held. */ static void hex_dump_object(struct seq_file *seq, struct kmemleak_object *object) { const u8 *ptr = (const u8 *)object->pointer; int i, len, remaining; unsigned char linebuf[HEX_ROW_SIZE * 5]; /* limit the number of lines to HEX_MAX_LINES */ remaining = len = min(object->size, (size_t)(HEX_MAX_LINES * HEX_ROW_SIZE)); seq_printf(seq, " hex dump (first %d bytes):\n", len); for (i = 0; i < len; i += HEX_ROW_SIZE) { int linelen = min(remaining, HEX_ROW_SIZE); remaining -= HEX_ROW_SIZE; hex_dump_to_buffer(ptr + i, linelen, HEX_ROW_SIZE, HEX_GROUP_SIZE, linebuf, sizeof(linebuf), HEX_ASCII); seq_printf(seq, " %s\n", linebuf); } } /* * Object colors, encoded with count and min_count: * - white - orphan object, not enough references to it (count < min_count) * - gray - not orphan, not marked as false positive (min_count == 0) or * sufficient references to it (count >= min_count) * - black - ignore, it doesn't contain references (e.g. text section) * (min_count == -1). No function defined for this color. * Newly created objects don't have any color assigned (object->count == -1) * before the next memory scan when they become white. */ static bool color_white(const struct kmemleak_object *object) { return object->count != KMEMLEAK_BLACK && object->count < object->min_count; } static bool color_gray(const struct kmemleak_object *object) { return object->min_count != KMEMLEAK_BLACK && object->count >= object->min_count; } /* * Objects are considered unreferenced only if their color is white, they have * not be deleted and have a minimum age to avoid false positives caused by * pointers temporarily stored in CPU registers. */ static bool unreferenced_object(struct kmemleak_object *object) { return (color_white(object) && object->flags & OBJECT_ALLOCATED) && time_before_eq(object->jiffies + jiffies_min_age, jiffies_last_scan); } /* * Printing of the unreferenced objects information to the seq file. The * print_unreferenced function must be called with the object->lock held. */ static void print_unreferenced(struct seq_file *seq, struct kmemleak_object *object) { int i; unsigned int msecs_age = jiffies_to_msecs(jiffies - object->jiffies); seq_printf(seq, "unreferenced object 0x%08lx (size %zu):\n", object->pointer, object->size); seq_printf(seq, " comm \"%s\", pid %d, jiffies %lu (age %d.%03ds)\n", object->comm, object->pid, object->jiffies, msecs_age / 1000, msecs_age % 1000); hex_dump_object(seq, object); seq_printf(seq, " backtrace:\n"); for (i = 0; i < object->trace_len; i++) { void *ptr = (void *)object->trace[i]; seq_printf(seq, " [<%p>] %pS\n", ptr, ptr); } } /* * Print the kmemleak_object information. This function is used mainly for * debugging special cases when kmemleak operations. It must be called with * the object->lock held. */ static void dump_object_info(struct kmemleak_object *object) { struct stack_trace trace; trace.nr_entries = object->trace_len; trace.entries = object->trace; pr_notice("Object 0x%08lx (size %zu):\n", object->tree_node.start, object->size); pr_notice(" comm \"%s\", pid %d, jiffies %lu\n", object->comm, object->pid, object->jiffies); pr_notice(" min_count = %d\n", object->min_count); pr_notice(" count = %d\n", object->count); pr_notice(" flags = 0x%lx\n", object->flags); pr_notice(" checksum = %d\n", object->checksum); pr_notice(" backtrace:\n"); print_stack_trace(&trace, 4); } /* * Look-up a memory block metadata (kmemleak_object) in the priority search * tree based on a pointer value. If alias is 0, only values pointing to the * beginning of the memory block are allowed. The kmemleak_lock must be held * when calling this function. */ static struct kmemleak_object *lookup_object(unsigned long ptr, int alias) { struct prio_tree_node *node; struct prio_tree_iter iter; struct kmemleak_object *object; prio_tree_iter_init(&iter, &object_tree_root, ptr, ptr); node = prio_tree_next(&iter); if (node) { object = prio_tree_entry(node, struct kmemleak_object, tree_node); if (!alias && object->pointer != ptr) { pr_warning("Found object by alias at 0x%08lx\n", ptr); dump_stack(); dump_object_info(object); object = NULL; } } else object = NULL; return object; } /* * Increment the object use_count. Return 1 if successful or 0 otherwise. Note * that once an object's use_count reached 0, the RCU freeing was already * registered and the object should no longer be used. This function must be * called under the protection of rcu_read_lock(). */ static int get_object(struct kmemleak_object *object) { return atomic_inc_not_zero(&object->use_count); } /* * RCU callback to free a kmemleak_object. */ static void free_object_rcu(struct rcu_head *rcu) { struct hlist_node *elem, *tmp; struct kmemleak_scan_area *area; struct kmemleak_object *object = container_of(rcu, struct kmemleak_object, rcu); /* * Once use_count is 0 (guaranteed by put_object), there is no other * code accessing this object, hence no need for locking. */ hlist_for_each_entry_safe(area, elem, tmp, &object->area_list, node) { hlist_del(elem); kmem_cache_free(scan_area_cache, area); } kmem_cache_free(object_cache, object); } /* * Decrement the object use_count. Once the count is 0, free the object using * an RCU callback. Since put_object() may be called via the kmemleak_free() -> * delete_object() path, the delayed RCU freeing ensures that there is no * recursive call to the kernel allocator. Lock-less RCU object_list traversal * is also possible. */ static void put_object(struct kmemleak_object *object) { if (!atomic_dec_and_test(&object->use_count)) return; /* should only get here after delete_object was called */ WARN_ON(object->flags & OBJECT_ALLOCATED); call_rcu(&object->rcu, free_object_rcu); } /* * Look up an object in the prio search tree and increase its use_count. */ static struct kmemleak_object *find_and_get_object(unsigned long ptr, int alias) { unsigned long flags; struct kmemleak_object *object = NULL; rcu_read_lock(); read_lock_irqsave(&kmemleak_lock, flags); if (ptr >= min_addr && ptr < max_addr) object = lookup_object(ptr, alias); read_unlock_irqrestore(&kmemleak_lock, flags); /* check whether the object is still available */ if (object && !get_object(object)) object = NULL; rcu_read_unlock(); return object; } /* * Save stack trace to the given array of MAX_TRACE size. */ static int __save_stack_trace(unsigned long *trace) { struct stack_trace stack_trace; stack_trace.max_entries = MAX_TRACE; stack_trace.nr_entries = 0; stack_trace.entries = trace; stack_trace.skip = 2; save_stack_trace(&stack_trace); return stack_trace.nr_entries; } /* * Create the metadata (struct kmemleak_object) corresponding to an allocated * memory block and add it to the object_list and object_tree_root. */ static struct kmemleak_object *create_object(unsigned long ptr, size_t size, int min_count, gfp_t gfp) { unsigned long flags; struct kmemleak_object *object; struct prio_tree_node *node; object = kmem_cache_alloc(object_cache, gfp_kmemleak_mask(gfp)); if (!object) { pr_warning("Cannot allocate a kmemleak_object structure\n"); kmemleak_disable(); return NULL; } INIT_LIST_HEAD(&object->object_list); INIT_LIST_HEAD(&object->gray_list); INIT_HLIST_HEAD(&object->area_list); spin_lock_init(&object->lock); atomic_set(&object->use_count, 1); object->flags = OBJECT_ALLOCATED; object->pointer = ptr; object->size = size; object->min_count = min_count; object->count = 0; /* white color initially */ object->jiffies = jiffies; object->checksum = 0; /* task information */ if (in_irq()) { object->pid = 0; strncpy(object->comm, "hardirq", sizeof(object->comm)); } else if (in_softirq()) { object->pid = 0; strncpy(object->comm, "softirq", sizeof(object->comm)); } else { object->pid = current->pid; /* * There is a small chance of a race with set_task_comm(), * however using get_task_comm() here may cause locking * dependency issues with current->alloc_lock. In the worst * case, the command line is not correct. */ strncpy(object->comm, current->comm, sizeof(object->comm)); } /* kernel backtrace */ object->trace_len = __save_stack_trace(object->trace); INIT_PRIO_TREE_NODE(&object->tree_node); object->tree_node.start = ptr; object->tree_node.last = ptr + size - 1; write_lock_irqsave(&kmemleak_lock, flags); min_addr = min(min_addr, ptr); max_addr = max(max_addr, ptr + size); node = prio_tree_insert(&object_tree_root, &object->tree_node); /* * The code calling the kernel does not yet have the pointer to the * memory block to be able to free it. However, we still hold the * kmemleak_lock here in case parts of the kernel started freeing * random memory blocks. */ if (node != &object->tree_node) { kmemleak_stop("Cannot insert 0x%lx into the object search tree " "(already existing)\n", ptr); object = lookup_object(ptr, 1); spin_lock(&object->lock); dump_object_info(object); spin_unlock(&object->lock); goto out; } list_add_tail_rcu(&object->object_list, &object_list); out: write_unlock_irqrestore(&kmemleak_lock, flags); return object; } /* * Remove the metadata (struct kmemleak_object) for a memory block from the * object_list and object_tree_root and decrement its use_count. */ static void __delete_object(struct kmemleak_object *object) { unsigned long flags; write_lock_irqsave(&kmemleak_lock, flags); prio_tree_remove(&object_tree_root, &object->tree_node); list_del_rcu(&object->object_list); write_unlock_irqrestore(&kmemleak_lock, flags); WARN_ON(!(object->flags & OBJECT_ALLOCATED)); WARN_ON(atomic_read(&object->use_count) < 2); /* * Locking here also ensures that the corresponding memory block * cannot be freed when it is being scanned. */ spin_lock_irqsave(&object->lock, flags); object->flags &= ~OBJECT_ALLOCATED; spin_unlock_irqrestore(&object->lock, flags); put_object(object); } /* * Look up the metadata (struct kmemleak_object) corresponding to ptr and * delete it. */ static void delete_object_full(unsigned long ptr) { struct kmemleak_object *object; object = find_and_get_object(ptr, 0); if (!object) { #ifdef DEBUG kmemleak_warn("Freeing unknown object at 0x%08lx\n", ptr); #endif return; } __delete_object(object); put_object(object); } /* * Look up the metadata (struct kmemleak_object) corresponding to ptr and * delete it. If the memory block is partially freed, the function may create * additional metadata for the remaining parts of the block. */ static void delete_object_part(unsigned long ptr, size_t size) { struct kmemleak_object *object; unsigned long start, end; object = find_and_get_object(ptr, 1); if (!object) { #ifdef DEBUG kmemleak_warn("Partially freeing unknown object at 0x%08lx " "(size %zu)\n", ptr, size); #endif return; } __delete_object(object); /* * Create one or two objects that may result from the memory block * split. Note that partial freeing is only done by free_bootmem() and * this happens before kmemleak_init() is called. The path below is * only executed during early log recording in kmemleak_init(), so * GFP_KERNEL is enough. */ start = object->pointer; end = object->pointer + object->size; if (ptr > start) create_object(start, ptr - start, object->min_count, GFP_KERNEL); if (ptr + size < end) create_object(ptr + size, end - ptr - size, object->min_count, GFP_KERNEL); put_object(object); } static void __paint_it(struct kmemleak_object *object, int color) { object->min_count = color; if (color == KMEMLEAK_BLACK) object->flags |= OBJECT_NO_SCAN; } static void paint_it(struct kmemleak_object *object, int color) { unsigned long flags; spin_lock_irqsave(&object->lock, flags); __paint_it(object, color); spin_unlock_irqrestore(&object->lock, flags); } static void paint_ptr(unsigned long ptr, int color) { struct kmemleak_object *object; object = find_and_get_object(ptr, 0); if (!object) { kmemleak_warn("Trying to color unknown object " "at 0x%08lx as %s\n", ptr, (color == KMEMLEAK_GREY) ? "Grey" : (color == KMEMLEAK_BLACK) ? "Black" : "Unknown"); return; } paint_it(object, color); put_object(object); } /* * Mark an object permanently as gray-colored so that it can no longer be * reported as a leak. This is used in general to mark a false positive. */ static void make_gray_object(unsigned long ptr) { paint_ptr(ptr, KMEMLEAK_GREY); } /* * Mark the object as black-colored so that it is ignored from scans and * reporting. */ static void make_black_object(unsigned long ptr) { paint_ptr(ptr, KMEMLEAK_BLACK); } /* * Add a scanning area to the object. If at least one such area is added, * kmemleak will only scan these ranges rather than the whole memory block. */ static void add_scan_area(unsigned long ptr, size_t size, gfp_t gfp) { unsigned long flags; struct kmemleak_object *object; struct kmemleak_scan_area *area; object = find_and_get_object(ptr, 1); if (!object) { kmemleak_warn("Adding scan area to unknown object at 0x%08lx\n", ptr); return; } area = kmem_cache_alloc(scan_area_cache, gfp_kmemleak_mask(gfp)); if (!area) { pr_warning("Cannot allocate a scan area\n"); goto out; } spin_lock_irqsave(&object->lock, flags); if (ptr + size > object->pointer + object->size) { kmemleak_warn("Scan area larger than object 0x%08lx\n", ptr); dump_object_info(object); kmem_cache_free(scan_area_cache, area); goto out_unlock; } INIT_HLIST_NODE(&area->node); area->start = ptr; area->size = size; hlist_add_head(&area->node, &object->area_list); out_unlock: spin_unlock_irqrestore(&object->lock, flags); out: put_object(object); } /* * Set the OBJECT_NO_SCAN flag for the object corresponding to the give * pointer. Such object will not be scanned by kmemleak but references to it * are searched. */ static void object_no_scan(unsigned long ptr) { unsigned long flags; struct kmemleak_object *object; object = find_and_get_object(ptr, 0); if (!object) { kmemleak_warn("Not scanning unknown object at 0x%08lx\n", ptr); return; } spin_lock_irqsave(&object->lock, flags); object->flags |= OBJECT_NO_SCAN; spin_unlock_irqrestore(&object->lock, flags); put_object(object); } /* * Log an early kmemleak_* call to the early_log buffer. These calls will be * processed later once kmemleak is fully initialized. */ static void __init log_early(int op_type, const void *ptr, size_t size, int min_count) { unsigned long flags; struct early_log *log; if (crt_early_log >= ARRAY_SIZE(early_log)) { pr_warning("Early log buffer exceeded, " "please increase DEBUG_KMEMLEAK_EARLY_LOG_SIZE\n"); kmemleak_disable(); return; } /* * There is no need for locking since the kernel is still in UP mode * at this stage. Disabling the IRQs is enough. */ local_irq_save(flags); log = &early_log[crt_early_log]; log->op_type = op_type; log->ptr = ptr; log->size = size; log->min_count = min_count; if (op_type == KMEMLEAK_ALLOC) log->trace_len = __save_stack_trace(log->trace); crt_early_log++; local_irq_restore(flags); } /* * Log an early allocated block and populate the stack trace. */ static void early_alloc(struct early_log *log) { struct kmemleak_object *object; unsigned long flags; int i; if (!atomic_read(&kmemleak_enabled) || !log->ptr || IS_ERR(log->ptr)) return; /* * RCU locking needed to ensure object is not freed via put_object(). */ rcu_read_lock(); object = create_object((unsigned long)log->ptr, log->size, log->min_count, GFP_ATOMIC); if (!object) goto out; spin_lock_irqsave(&object->lock, flags); for (i = 0; i < log->trace_len; i++) object->trace[i] = log->trace[i]; object->trace_len = log->trace_len; spin_unlock_irqrestore(&object->lock, flags); out: rcu_read_unlock(); } /** * kmemleak_alloc - register a newly allocated object * @ptr: pointer to beginning of the object * @size: size of the object * @min_count: minimum number of references to this object. If during memory * scanning a number of references less than @min_count is found, * the object is reported as a memory leak. If @min_count is 0, * the object is never reported as a leak. If @min_count is -1, * the object is ignored (not scanned and not reported as a leak) * @gfp: kmalloc() flags used for kmemleak internal memory allocations * * This function is called from the kernel allocators when a new object * (memory block) is allocated (kmem_cache_alloc, kmalloc, vmalloc etc.). */ void __ref kmemleak_alloc(const void *ptr, size_t size, int min_count, gfp_t gfp) { pr_debug("%s(0x%p, %zu, %d)\n", __func__, ptr, size, min_count); if (atomic_read(&kmemleak_enabled) && ptr && !IS_ERR(ptr)) create_object((unsigned long)ptr, size, min_count, gfp); else if (atomic_read(&kmemleak_early_log)) log_early(KMEMLEAK_ALLOC, ptr, size, min_count); } EXPORT_SYMBOL_GPL(kmemleak_alloc); /** * kmemleak_free - unregister a previously registered object * @ptr: pointer to beginning of the object * * This function is called from the kernel allocators when an object (memory * block) is freed (kmem_cache_free, kfree, vfree etc.). */ void __ref kmemleak_free(const void *ptr) { pr_debug("%s(0x%p)\n", __func__, ptr); if (atomic_read(&kmemleak_enabled) && ptr && !IS_ERR(ptr)) delete_object_full((unsigned long)ptr); else if (atomic_read(&kmemleak_early_log)) log_early(KMEMLEAK_FREE, ptr, 0, 0); } EXPORT_SYMBOL_GPL(kmemleak_free); /** * kmemleak_free_part - partially unregister a previously registered object * @ptr: pointer to the beginning or inside the object. This also * represents the start of the range to be freed * @size: size to be unregistered * * This function is called when only a part of a memory block is freed * (usually from the bootmem allocator). */ void __ref kmemleak_free_part(const void *ptr, size_t size) { pr_debug("%s(0x%p)\n", __func__, ptr); if (atomic_read(&kmemleak_enabled) && ptr && !IS_ERR(ptr)) delete_object_part((unsigned long)ptr, size); else if (atomic_read(&kmemleak_early_log)) log_early(KMEMLEAK_FREE_PART, ptr, size, 0); } EXPORT_SYMBOL_GPL(kmemleak_free_part); /** * kmemleak_not_leak - mark an allocated object as false positive * @ptr: pointer to beginning of the object * * Calling this function on an object will cause the memory block to no longer * be reported as leak and always be scanned. */ void __ref kmemleak_not_leak(const void *ptr) { pr_debug("%s(0x%p)\n", __func__, ptr); if (atomic_read(&kmemleak_enabled) && ptr && !IS_ERR(ptr)) make_gray_object((unsigned long)ptr); else if (atomic_read(&kmemleak_early_log)) log_early(KMEMLEAK_NOT_LEAK, ptr, 0, 0); } EXPORT_SYMBOL(kmemleak_not_leak); /** * kmemleak_ignore - ignore an allocated object * @ptr: pointer to beginning of the object * * Calling this function on an object will cause the memory block to be * ignored (not scanned and not reported as a leak). This is usually done when * it is known that the corresponding block is not a leak and does not contain * any references to other allocated memory blocks. */ void __ref kmemleak_ignore(const void *ptr) { pr_debug("%s(0x%p)\n", __func__, ptr); if (atomic_read(&kmemleak_enabled) && ptr && !IS_ERR(ptr)) make_black_object((unsigned long)ptr); else if (atomic_read(&kmemleak_early_log)) log_early(KMEMLEAK_IGNORE, ptr, 0, 0); } EXPORT_SYMBOL(kmemleak_ignore); /** * kmemleak_scan_area - limit the range to be scanned in an allocated object * @ptr: pointer to beginning or inside the object. This also * represents the start of the scan area * @size: size of the scan area * @gfp: kmalloc() flags used for kmemleak internal memory allocations * * This function is used when it is known that only certain parts of an object * contain references to other objects. Kmemleak will only scan these areas * reducing the number false negatives. */ void __ref kmemleak_scan_area(const void *ptr, size_t size, gfp_t gfp) { pr_debug("%s(0x%p)\n", __func__, ptr); if (atomic_read(&kmemleak_enabled) && ptr && !IS_ERR(ptr)) add_scan_area((unsigned long)ptr, size, gfp); else if (atomic_read(&kmemleak_early_log)) log_early(KMEMLEAK_SCAN_AREA, ptr, size, 0); } EXPORT_SYMBOL(kmemleak_scan_area); /** * kmemleak_no_scan - do not scan an allocated object * @ptr: pointer to beginning of the object * * This function notifies kmemleak not to scan the given memory block. Useful * in situations where it is known that the given object does not contain any * references to other objects. Kmemleak will not scan such objects reducing * the number of false negatives. */ void __ref kmemleak_no_scan(const void *ptr) { pr_debug("%s(0x%p)\n", __func__, ptr); if (atomic_read(&kmemleak_enabled) && ptr && !IS_ERR(ptr)) object_no_scan((unsigned long)ptr); else if (atomic_read(&kmemleak_early_log)) log_early(KMEMLEAK_NO_SCAN, ptr, 0, 0); } EXPORT_SYMBOL(kmemleak_no_scan); /* * Update an object's checksum and return true if it was modified. */ static bool update_checksum(struct kmemleak_object *object) { u32 old_csum = object->checksum; if (!kmemcheck_is_obj_initialized(object->pointer, object->size)) return false; object->checksum = crc32(0, (void *)object->pointer, object->size); return object->checksum != old_csum; } /* * Memory scanning is a long process and it needs to be interruptable. This * function checks whether such interrupt condition occurred. */ static int scan_should_stop(void) { if (!atomic_read(&kmemleak_enabled)) return 1; /* * This function may be called from either process or kthread context, * hence the need to check for both stop conditions. */ if (current->mm) return signal_pending(current); else return kthread_should_stop(); return 0; } /* * Scan a memory block (exclusive range) for valid pointers and add those * found to the gray list. */ static void scan_block(void *_start, void *_end, struct kmemleak_object *scanned, int allow_resched) { unsigned long *ptr; unsigned long *start = PTR_ALIGN(_start, BYTES_PER_POINTER); unsigned long *end = _end - (BYTES_PER_POINTER - 1); for (ptr = start; ptr < end; ptr++) { struct kmemleak_object *object; unsigned long flags; unsigned long pointer; if (allow_resched) cond_resched(); if (scan_should_stop()) break; /* don't scan uninitialized memory */ if (!kmemcheck_is_obj_initialized((unsigned long)ptr, BYTES_PER_POINTER)) continue; pointer = *ptr; object = find_and_get_object(pointer, 1); if (!object) continue; if (object == scanned) { /* self referenced, ignore */ put_object(object); continue; } /* * Avoid the lockdep recursive warning on object->lock being * previously acquired in scan_object(). These locks are * enclosed by scan_mutex. */ spin_lock_irqsave_nested(&object->lock, flags, SINGLE_DEPTH_NESTING); if (!color_white(object)) { /* non-orphan, ignored or new */ spin_unlock_irqrestore(&object->lock, flags); put_object(object); continue; } /* * Increase the object's reference count (number of pointers * to the memory block). If this count reaches the required * minimum, the object's color will become gray and it will be * added to the gray_list. */ object->count++; if (color_gray(object)) { list_add_tail(&object->gray_list, &gray_list); spin_unlock_irqrestore(&object->lock, flags); continue; } spin_unlock_irqrestore(&object->lock, flags); put_object(object); } } /* * Scan a memory block corresponding to a kmemleak_object. A condition is * that object->use_count >= 1. */ static void scan_object(struct kmemleak_object *object) { struct kmemleak_scan_area *area; struct hlist_node *elem; unsigned long flags; /* * Once the object->lock is acquired, the corresponding memory block * cannot be freed (the same lock is acquired in delete_object). */ spin_lock_irqsave(&object->lock, flags); if (object->flags & OBJECT_NO_SCAN) goto out; if (!(object->flags & OBJECT_ALLOCATED)) /* already freed object */ goto out; if (hlist_empty(&object->area_list)) { void *start = (void *)object->pointer; void *end = (void *)(object->pointer + object->size); while (start < end && (object->flags & OBJECT_ALLOCATED) && !(object->flags & OBJECT_NO_SCAN)) { scan_block(start, min(start + MAX_SCAN_SIZE, end), object, 0); start += MAX_SCAN_SIZE; spin_unlock_irqrestore(&object->lock, flags); cond_resched(); spin_lock_irqsave(&object->lock, flags); } } else hlist_for_each_entry(area, elem, &object->area_list, node) scan_block((void *)area->start, (void *)(area->start + area->size), object, 0); out: spin_unlock_irqrestore(&object->lock, flags); } /* * Scan the objects already referenced (gray objects). More objects will be * referenced and, if there are no memory leaks, all the objects are scanned. */ static void scan_gray_list(void) { struct kmemleak_object *object, *tmp; /* * The list traversal is safe for both tail additions and removals * from inside the loop. The kmemleak objects cannot be freed from * outside the loop because their use_count was incremented. */ object = list_entry(gray_list.next, typeof(*object), gray_list); while (&object->gray_list != &gray_list) { cond_resched(); /* may add new objects to the list */ if (!scan_should_stop()) scan_object(object); tmp = list_entry(object->gray_list.next, typeof(*object), gray_list); /* remove the object from the list and release it */ list_del(&object->gray_list); put_object(object); object = tmp; } WARN_ON(!list_empty(&gray_list)); } /* * Scan data sections and all the referenced memory blocks allocated via the * kernel's standard allocators. This function must be called with the * scan_mutex held. */ static void kmemleak_scan(void) { unsigned long flags; struct kmemleak_object *object; int i; int new_leaks = 0; jiffies_last_scan = jiffies; /* prepare the kmemleak_object's */ rcu_read_lock(); list_for_each_entry_rcu(object, &object_list, object_list) { spin_lock_irqsave(&object->lock, flags); #ifdef DEBUG /* * With a few exceptions there should be a maximum of * 1 reference to any object at this point. */ if (atomic_read(&object->use_count) > 1) { pr_debug("object->use_count = %d\n", atomic_read(&object->use_count)); dump_object_info(object); } #endif /* reset the reference count (whiten the object) */ object->count = 0; if (color_gray(object) && get_object(object)) list_add_tail(&object->gray_list, &gray_list); spin_unlock_irqrestore(&object->lock, flags); } rcu_read_unlock(); /* data/bss scanning */ scan_block(_sdata, _edata, NULL, 1); scan_block(__bss_start, __bss_stop, NULL, 1); #ifdef CONFIG_SMP /* per-cpu sections scanning */ for_each_possible_cpu(i) scan_block(__per_cpu_start + per_cpu_offset(i), __per_cpu_end + per_cpu_offset(i), NULL, 1); #endif /* * Struct page scanning for each node. The code below is not yet safe * with MEMORY_HOTPLUG. */ for_each_online_node(i) { pg_data_t *pgdat = NODE_DATA(i); unsigned long start_pfn = pgdat->node_start_pfn; unsigned long end_pfn = start_pfn + pgdat->node_spanned_pages; unsigned long pfn; for (pfn = start_pfn; pfn < end_pfn; pfn++) { struct page *page; if (!pfn_valid(pfn)) continue; page = pfn_to_page(pfn); /* only scan if page is in use */ if (page_count(page) == 0) continue; scan_block(page, page + 1, NULL, 1); } } /* * Scanning the task stacks (may introduce false negatives). */ if (kmemleak_stack_scan) { struct task_struct *p, *g; read_lock(&tasklist_lock); do_each_thread(g, p) { scan_block(task_stack_page(p), task_stack_page(p) + THREAD_SIZE, NULL, 0); } while_each_thread(g, p); read_unlock(&tasklist_lock); } /* * Scan the objects already referenced from the sections scanned * above. */ scan_gray_list(); /* * Check for new or unreferenced objects modified since the previous * scan and color them gray until the next scan. */ rcu_read_lock(); list_for_each_entry_rcu(object, &object_list, object_list) { spin_lock_irqsave(&object->lock, flags); if (color_white(object) && (object->flags & OBJECT_ALLOCATED) && update_checksum(object) && get_object(object)) { /* color it gray temporarily */ object->count = object->min_count; list_add_tail(&object->gray_list, &gray_list); } spin_unlock_irqrestore(&object->lock, flags); } rcu_read_unlock(); /* * Re-scan the gray list for modified unreferenced objects. */ scan_gray_list(); /* * If scanning was stopped do not report any new unreferenced objects. */ if (scan_should_stop()) return; /* * Scanning result reporting. */ rcu_read_lock(); list_for_each_entry_rcu(object, &object_list, object_list) { spin_lock_irqsave(&object->lock, flags); if (unreferenced_object(object) && !(object->flags & OBJECT_REPORTED)) { object->flags |= OBJECT_REPORTED; new_leaks++; } spin_unlock_irqrestore(&object->lock, flags); } rcu_read_unlock(); if (new_leaks) pr_info("%d new suspected memory leaks (see " "/sys/kernel/debug/kmemleak)\n", new_leaks); } /* * Thread function performing automatic memory scanning. Unreferenced objects * at the end of a memory scan are reported but only the first time. */ static int kmemleak_scan_thread(void *arg) { static int first_run = 1; pr_info("Automatic memory scanning thread started\n"); set_user_nice(current, 10); /* * Wait before the first scan to allow the system to fully initialize. */ if (first_run) { first_run = 0; ssleep(SECS_FIRST_SCAN); } while (!kthread_should_stop()) { signed long timeout = jiffies_scan_wait; mutex_lock(&scan_mutex); kmemleak_scan(); mutex_unlock(&scan_mutex); /* wait before the next scan */ while (timeout && !kthread_should_stop()) timeout = schedule_timeout_interruptible(timeout); } pr_info("Automatic memory scanning thread ended\n"); return 0; } /* * Start the automatic memory scanning thread. This function must be called * with the scan_mutex held. */ static void start_scan_thread(void) { if (scan_thread) return; scan_thread = kthread_run(kmemleak_scan_thread, NULL, "kmemleak"); if (IS_ERR(scan_thread)) { pr_warning("Failed to create the scan thread\n"); scan_thread = NULL; } } /* * Stop the automatic memory scanning thread. This function must be called * with the scan_mutex held. */ static void stop_scan_thread(void) { if (scan_thread) { kthread_stop(scan_thread); scan_thread = NULL; } } /* * Iterate over the object_list and return the first valid object at or after * the required position with its use_count incremented. The function triggers * a memory scanning when the pos argument points to the first position. */ static void *kmemleak_seq_start(struct seq_file *seq, loff_t *pos) { struct kmemleak_object *object; loff_t n = *pos; int err; err = mutex_lock_interruptible(&scan_mutex); if (err < 0) return ERR_PTR(err); rcu_read_lock(); list_for_each_entry_rcu(object, &object_list, object_list) { if (n-- > 0) continue; if (get_object(object)) goto out; } object = NULL; out: return object; } /* * Return the next object in the object_list. The function decrements the * use_count of the previous object and increases that of the next one. */ static void *kmemleak_seq_next(struct seq_file *seq, void *v, loff_t *pos) { struct kmemleak_object *prev_obj = v; struct kmemleak_object *next_obj = NULL; struct list_head *n = &prev_obj->object_list; ++(*pos); list_for_each_continue_rcu(n, &object_list) { struct kmemleak_object *obj = list_entry(n, struct kmemleak_object, object_list); if (get_object(obj)) { next_obj = obj; break; } } put_object(prev_obj); return next_obj; } /* * Decrement the use_count of the last object required, if any. */ static void kmemleak_seq_stop(struct seq_file *seq, void *v) { if (!IS_ERR(v)) { /* * kmemleak_seq_start may return ERR_PTR if the scan_mutex * waiting was interrupted, so only release it if !IS_ERR. */ rcu_read_unlock(); mutex_unlock(&scan_mutex); if (v) put_object(v); } } /* * Print the information for an unreferenced object to the seq file. */ static int kmemleak_seq_show(struct seq_file *seq, void *v) { struct kmemleak_object *object = v; unsigned long flags; spin_lock_irqsave(&object->lock, flags); if ((object->flags & OBJECT_REPORTED) && unreferenced_object(object)) print_unreferenced(seq, object); spin_unlock_irqrestore(&object->lock, flags); return 0; } static const struct seq_operations kmemleak_seq_ops = { .start = kmemleak_seq_start, .next = kmemleak_seq_next, .stop = kmemleak_seq_stop, .show = kmemleak_seq_show, }; static int kmemleak_open(struct inode *inode, struct file *file) { if (!atomic_read(&kmemleak_enabled)) return -EBUSY; return seq_open(file, &kmemleak_seq_ops); } static int kmemleak_release(struct inode *inode, struct file *file) { return seq_release(inode, file); } static int dump_str_object_info(const char *str) { unsigned long flags; struct kmemleak_object *object; unsigned long addr; addr= simple_strtoul(str, NULL, 0); object = find_and_get_object(addr, 0); if (!object) { pr_info("Unknown object at 0x%08lx\n", addr); return -EINVAL; } spin_lock_irqsave(&object->lock, flags); dump_object_info(object); spin_unlock_irqrestore(&object->lock, flags); put_object(object); return 0; } /* * We use grey instead of black to ensure we can do future scans on the same * objects. If we did not do future scans these black objects could * potentially contain references to newly allocated objects in the future and * we'd end up with false positives. */ static void kmemleak_clear(void) { struct kmemleak_object *object; unsigned long flags; rcu_read_lock(); list_for_each_entry_rcu(object, &object_list, object_list) { spin_lock_irqsave(&object->lock, flags); if ((object->flags & OBJECT_REPORTED) && unreferenced_object(object)) __paint_it(object, KMEMLEAK_GREY); spin_unlock_irqrestore(&object->lock, flags); } rcu_read_unlock(); } /* * File write operation to configure kmemleak at run-time. The following * commands can be written to the /sys/kernel/debug/kmemleak file: * off - disable kmemleak (irreversible) * stack=on - enable the task stacks scanning * stack=off - disable the tasks stacks scanning * scan=on - start the automatic memory scanning thread * scan=off - stop the automatic memory scanning thread * scan=... - set the automatic memory scanning period in seconds (0 to * disable it) * scan - trigger a memory scan * clear - mark all current reported unreferenced kmemleak objects as * grey to ignore printing them * dump=... - dump information about the object found at the given address */ static ssize_t kmemleak_write(struct file *file, const char __user *user_buf, size_t size, loff_t *ppos) { char buf[64]; int buf_size; int ret; buf_size = min(size, (sizeof(buf) - 1)); if (strncpy_from_user(buf, user_buf, buf_size) < 0) return -EFAULT; buf[buf_size] = 0; ret = mutex_lock_interruptible(&scan_mutex); if (ret < 0) return ret; if (strncmp(buf, "off", 3) == 0) kmemleak_disable(); else if (strncmp(buf, "stack=on", 8) == 0) kmemleak_stack_scan = 1; else if (strncmp(buf, "stack=off", 9) == 0) kmemleak_stack_scan = 0; else if (strncmp(buf, "scan=on", 7) == 0) start_scan_thread(); else if (strncmp(buf, "scan=off", 8) == 0) stop_scan_thread(); else if (strncmp(buf, "scan=", 5) == 0) { unsigned long secs; ret = strict_strtoul(buf + 5, 0, &secs); if (ret < 0) goto out; stop_scan_thread(); if (secs) { jiffies_scan_wait = msecs_to_jiffies(secs * 1000); start_scan_thread(); } } else if (strncmp(buf, "scan", 4) == 0) kmemleak_scan(); else if (strncmp(buf, "clear", 5) == 0) kmemleak_clear(); else if (strncmp(buf, "dump=", 5) == 0) ret = dump_str_object_info(buf + 5); else ret = -EINVAL; out: mutex_unlock(&scan_mutex); if (ret < 0) return ret; /* ignore the rest of the buffer, only one command at a time */ *ppos += size; return size; } static const struct file_operations kmemleak_fops = { .owner = THIS_MODULE, .open = kmemleak_open, .read = seq_read, .write = kmemleak_write, .llseek = seq_lseek, .release = kmemleak_release, }; /* * Perform the freeing of the kmemleak internal objects after waiting for any * current memory scan to complete. */ static void kmemleak_do_cleanup(struct work_struct *work) { struct kmemleak_object *object; mutex_lock(&scan_mutex); stop_scan_thread(); rcu_read_lock(); list_for_each_entry_rcu(object, &object_list, object_list) delete_object_full(object->pointer); rcu_read_unlock(); mutex_unlock(&scan_mutex); } static DECLARE_WORK(cleanup_work, kmemleak_do_cleanup); /* * Disable kmemleak. No memory allocation/freeing will be traced once this * function is called. Disabling kmemleak is an irreversible operation. */ static void kmemleak_disable(void) { /* atomically check whether it was already invoked */ if (atomic_cmpxchg(&kmemleak_error, 0, 1)) return; /* stop any memory operation tracing */ atomic_set(&kmemleak_early_log, 0); atomic_set(&kmemleak_enabled, 0); /* check whether it is too early for a kernel thread */ if (atomic_read(&kmemleak_initialized)) schedule_work(&cleanup_work); pr_info("Kernel memory leak detector disabled\n"); } /* * Allow boot-time kmemleak disabling (enabled by default). */ static int kmemleak_boot_config(char *str) { if (!str) return -EINVAL; if (strcmp(str, "off") == 0) kmemleak_disable(); else if (strcmp(str, "on") == 0) kmemleak_skip_disable = 1; else return -EINVAL; return 0; } early_param("kmemleak", kmemleak_boot_config); /* * Kmemleak initialization. */ void __init kmemleak_init(void) { int i; unsigned long flags; #ifdef CONFIG_DEBUG_KMEMLEAK_DEFAULT_OFF if (!kmemleak_skip_disable) { kmemleak_disable(); return; } #endif jiffies_min_age = msecs_to_jiffies(MSECS_MIN_AGE); jiffies_scan_wait = msecs_to_jiffies(SECS_SCAN_WAIT * 1000); object_cache = KMEM_CACHE(kmemleak_object, SLAB_NOLEAKTRACE); scan_area_cache = KMEM_CACHE(kmemleak_scan_area, SLAB_NOLEAKTRACE); INIT_PRIO_TREE_ROOT(&object_tree_root); /* the kernel is still in UP mode, so disabling the IRQs is enough */ local_irq_save(flags); if (!atomic_read(&kmemleak_error)) { atomic_set(&kmemleak_enabled, 1); atomic_set(&kmemleak_early_log, 0); } local_irq_restore(flags); /* * This is the point where tracking allocations is safe. Automatic * scanning is started during the late initcall. Add the early logged * callbacks to the kmemleak infrastructure. */ for (i = 0; i < crt_early_log; i++) { struct early_log *log = &early_log[i]; switch (log->op_type) { case KMEMLEAK_ALLOC: early_alloc(log); break; case KMEMLEAK_FREE: kmemleak_free(log->ptr); break; case KMEMLEAK_FREE_PART: kmemleak_free_part(log->ptr, log->size); break; case KMEMLEAK_NOT_LEAK: kmemleak_not_leak(log->ptr); break; case KMEMLEAK_IGNORE: kmemleak_ignore(log->ptr); break; case KMEMLEAK_SCAN_AREA: kmemleak_scan_area(log->ptr, log->size, GFP_KERNEL); break; case KMEMLEAK_NO_SCAN: kmemleak_no_scan(log->ptr); break; default: WARN_ON(1); } } } /* * Late initialization function. */ static int __init kmemleak_late_init(void) { struct dentry *dentry; atomic_set(&kmemleak_initialized, 1); if (atomic_read(&kmemleak_error)) { /* * Some error occurred and kmemleak was disabled. There is a * small chance that kmemleak_disable() was called immediately * after setting kmemleak_initialized and we may end up with * two clean-up threads but serialized by scan_mutex. */ schedule_work(&cleanup_work); return -ENOMEM; } dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL, &kmemleak_fops); if (!dentry) pr_warning("Failed to create the debugfs kmemleak file\n"); mutex_lock(&scan_mutex); start_scan_thread(); mutex_unlock(&scan_mutex); pr_info("Kernel memory leak detector initialized\n"); return 0; } late_initcall(kmemleak_late_init);
28.918228
80
0.72326
d2cd4fe8f95562691e48e2992208850529bd63f9
10,201
c
C
jailkit-2.21/src/iniparser.c
mathzzz/jail
674cbf6fed5a7ab41c188642fae34a7bc668a680
[ "MIT" ]
null
null
null
jailkit-2.21/src/iniparser.c
mathzzz/jail
674cbf6fed5a7ab41c188642fae34a7bc668a680
[ "MIT" ]
null
null
null
jailkit-2.21/src/iniparser.c
mathzzz/jail
674cbf6fed5a7ab41c188642fae34a7bc668a680
[ "MIT" ]
null
null
null
/* Copyright (c) 2003, 2004, 2005, 2016 Olivier Sessink All rights reserved. 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. * The names of its contributors may not 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 OWNER 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 "config.h" #include <ctype.h> /* isspace() */ #include <stdio.h> /* fseek() */ #include <stdlib.h> /* malloc() */ #include <string.h> /* memset() */ #include <fcntl.h> /* fcntl() */ /*#define DEBUG*/ #ifdef DEBUG #include <syslog.h> #endif #include "jk_lib.h" #include "iniparser.h" Tiniparser *new_iniparser(char *filename) { FILE *tmp; tmp = fopen(filename, "r"); if (tmp) { Tiniparser *ip = malloc(sizeof(Tiniparser)); ip->filename = strdup(filename); ip->fd = tmp; /* set close-on-exec so this file descriptor will not be passed to the a process after an exec() call */ fcntl(fileno(ip->fd), F_SETFD, FD_CLOEXEC); DEBUG_MSG("new_iniparser, ip=%p for filename %s\n",ip,filename); return ip; } return NULL; } void iniparser_close(Tiniparser *ip) { DEBUG_MSG("close fd\n"); fclose(ip->fd); DEBUG_MSG("free filename=%p\n",ip->filename); free(ip->filename); DEBUG_MSG("free ip=%p\n",ip->filename); free(ip); DEBUG_MSG("done\n"); } char *iniparser_next_section(Tiniparser *ip, char *buf, int buflen) { int sectionNameChar=0, sectionStart=0; unsigned short int inComment = 0; char prevch='\0', ch; DEBUG_MSG("iniparser_next_section, looking for next section..\n"); while (!feof(ip->fd)){ ch=fgetc(ip->fd); if (ch == '#' && (prevch == '\n' || prevch=='\0')) { DEBUG_MSG("Comment start (%c)\n",ch); inComment = 1; } else if (ch == '\n' && inComment == 1) { DEBUG_MSG("Comment stop (%c)\n",ch); inComment = 0; } else if (inComment == 1) { /* do nothing if in comment */ /*DEBUG_MSG("do nothing, we're in a comment (%c)\n",ch);*/ } else if (!sectionStart && ch=='[') { DEBUG_MSG("Section begins (%c)\n",ch); sectionStart=1; } else if (sectionStart && ch != ']') { buf[sectionNameChar] = ch; sectionNameChar++; DEBUG_MSG("added '%c' to sectionname\n",ch); } else if (sectionStart && sectionNameChar != 0 && ch==']') { buf[sectionNameChar] = '\0'; DEBUG_MSG("iniparser_next_section, found '%c', sectionStart=%d, found [%s]\n", ch,sectionStart,buf); return buf; } prevch = ch; } return NULL; } /* test if section 'section' is available, and leaves the filepointer at the end of the section name */ unsigned short int iniparser_has_section(Tiniparser *ip, const char *section) { char buffer[256], *found; fseek(ip->fd,0,SEEK_SET); DEBUG_MSG("iniparser_has_section, looking for %s from position %d\n",section,0); while ((found = iniparser_next_section(ip, buffer, 256))) { DEBUG_MSG("comparing %s and %s\n",section,found); if (strcmp(found, section)==0) { DEBUG_MSG("iniparser_has_section, return 1\n"); return 1; } } return 0; } int iniparser_get_string_at_position(Tiniparser*ip, const char *section, const char *key, long position, char *buffer, int bufferlen) { char ch='\0', prevch='\0'; unsigned int sectionNameChar=0, keyNameChar=0, bufferChar=0; unsigned short int inSection=0, sectionStart=0, foundKey=0, inComment=0, inWrongKey=0; DEBUG_MSG("iniparser_get_string_at_position, looking for key %s in section %s, starting at pos %ld\n",key,section,position); if (fseek(ip->fd,position,SEEK_SET) != 0) { DEBUG_MSG("there was an error seeking to %ld, current position=%ld, reset to zero\n",position,ftell(ip->fd)); fseek(ip->fd, 0, SEEK_SET); } DEBUG_MSG("current position of the stream is %ld\n",ftell(ip->fd)); while (!feof(ip->fd)){ prevch = ch; ch=fgetc(ip->fd); if (inComment == 1) { if (ch == '\n') { DEBUG_MSG("end of comment found\n"); inComment = 0; } continue; } else if (ch == '#' && (prevch == '\n' || prevch == '\0')) { DEBUG_MSG("inComment!\n"); inComment = 1; continue; } if (!inSection) { if (!sectionStart && ch=='['){ if (inSection){ /* found nothing */ break; } DEBUG_MSG("Section begins. Looking for [%s]\n", section); sectionStart=1; } else if (sectionStart && ch==section[sectionNameChar]){ DEBUG_MSG("Matched section name character: %c\n", ch); sectionNameChar++; } else if (sectionStart && sectionNameChar != 0 && ch==']'){ DEBUG_MSG("Found section name end, inSection=%d, found [%s]\n",inSection,section); sectionStart=0; inSection=1; sectionNameChar=0; DEBUG_MSG("The correct section %s is now found, now we continue with the key %s\n", section, key); } else if (sectionStart){ DEBUG_MSG("Oops, wrong section, %c is not in position %d of %s\n", ch,sectionNameChar,section); sectionStart=0; sectionNameChar=0; } } else if (inWrongKey/* && inSection is implied */) { if (ch == '\n') { DEBUG_MSG("inWrongKey, found end of line!\n"); inWrongKey = 0; foundKey=0; keyNameChar=0; } else { /*DEBUG_MSG("inWrongKey, found %c, pass till end of line\n",ch);*/ } } else if (!foundKey /* && inSection is implied */) { if (ch==key[keyNameChar]){ DEBUG_MSG("Found a valid letter of the key: %c on position %d of %s, continue to test if next character is also valid\n", ch,keyNameChar,key); keyNameChar++; } else if (isspace(ch)) { /* *before* the key, and *after* the key, before the '=' there can be spaces */ DEBUG_MSG("found a space, we ignore spaces when we are looking for the key\n"); } else if (keyNameChar != 0 && ch == '='){ DEBUG_MSG("Character %c, found the key %s, set foundKey to 1\n", ch,key); foundKey=1; } else if (ch=='\n'){ DEBUG_MSG("End of line, start looking again for %s\n", key); inWrongKey=0; keyNameChar=0; } else if (ch=='[') { DEBUG_MSG("Found the start of a new section, abort, the key does not exist\n"); buffer[0]='\0'; return -1; } else { DEBUG_MSG("if all else fails: %c must be a character that is not on position %d of key %s, set inWrongKey\n",ch,keyNameChar,key); inWrongKey=1; } } else if (foundKey /* && inSection is implied */) { if (bufferChar < bufferlen){ if (ch != '\n') { DEBUG_MSG("Insection, found the key, getting the content for the key: %c\n", ch); buffer[bufferChar++]=ch; } else { DEBUG_MSG("found a newline: the end of the content of the key! "); buffer[bufferChar]='\0'; DEBUG_MSG("return '%s'\n",buffer); return bufferChar; } } else { DEBUG_MSG("Hit the buffer max, EOM, done w/ key %s=\n", key); break; } } else { DEBUG_MSG("unhandled character %c ?\n",ch); } prevch = ch; } buffer[bufferChar]='\0'; DEBUG_MSG("iniparser_get_string_at_position, end-of-file, bufferChar=%d\n",bufferChar); return bufferChar; } int iniparser_get_int_at_position(Tiniparser *ip, const char *section, const char *key, long position, int defaultval) { char data[25]; int ret=defaultval; memset(data, 0, 25); if (iniparser_get_string_at_position(ip, section, key, position, data, 25)==-1){ return defaultval; } strip_string(data); sscanf(data, "%u", &ret); return ret; } int iniparser_get_octalint_at_position(Tiniparser *ip, const char *section, const char *key, long position, int defaultval) { char data[25]; int ret=defaultval; memset(data, 0, 25); if (iniparser_get_string_at_position(ip, section, key, position, data, 25)==-1){ return defaultval; } strip_string(data); sscanf(data, "%o", &ret); return ret; } float iniparser_get_float_at_position(Tiniparser *ip, const char *section, const char *key, long position, float defaultval) { float ret = defaultval; char data[25]; memset(data, 0, 25); if (iniparser_get_string_at_position(ip, section, key, position, data, 25)==-1){ DEBUG_MSG("iniparser_get_float_at_position, no string found\n"); return 0.0; } strip_string(data); sscanf(data, "%f", &ret); return ret; } /* int iniparser_value_len(Tiniparser *ip, const char *section, const char *key){ char ch; unsigned int sectionNameChar=0, keyNameChar=0; unsigned int valueLength=0; unsigned short int inSection=0, sectionStart=0, foundKey=0; while (!feof(ip->fd)){ ch=fgetc(ip->fd); if (!sectionStart && ch=='['){ if (inSection){ break; } sectionStart=1; } else if (sectionStart && ch==section[sectionNameChar]){ sectionNameChar++; } else if (sectionStart && sectionNameChar != 0 && ch==']'){ sectionStart=0; inSection=1; sectionNameChar=0; } else if (sectionStart){ sectionStart=0; sectionNameChar=0; } if (inSection && !foundKey && ch==key[keyNameChar]){ keyNameChar++; } else if (inSection && !foundKey && keyNameChar != 0 && ch == '='){ foundKey=1; } else if (inSection && keyNameChar != 0 && !foundKey){ foundKey=0; keyNameChar=0; } else if (inSection && foundKey && (ch==13 || ch==10 || ch==';')){ foundKey=0; break; } else if (inSection && foundKey){ valueLength++; } } return valueLength; } */
33.890365
146
0.668954
c5bb9c0cc1b482501bf8aab23ca59a5b4ddc8d83
12,703
c
C
drivers/dpdk-16.11/app/test/test_cmdline_string.c
chandaweia/onvm-mos-new
9b46708e036514c9748b480aa09b46caf53fda94
[ "BSD-3-Clause" ]
262
2017-12-18T02:08:41.000Z
2022-01-14T12:48:11.000Z
drivers/dpdk-16.11/app/test/test_cmdline_string.c
chandaweia/onvm-mos-new
9b46708e036514c9748b480aa09b46caf53fda94
[ "BSD-3-Clause" ]
12
2018-03-21T10:38:21.000Z
2019-07-04T05:53:31.000Z
drivers/dpdk-16.11/app/test/test_cmdline_string.c
chandaweia/onvm-mos-new
9b46708e036514c9748b480aa09b46caf53fda94
[ "BSD-3-Clause" ]
92
2017-12-20T14:57:06.000Z
2022-01-05T00:40:18.000Z
/*- * BSD LICENSE * * Copyright(c) 2010-2014 Intel Corporation. All rights reserved. * All rights reserved. * * 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 of Intel Corporation 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 * OWNER 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 <stdio.h> #include <string.h> #include <inttypes.h> #include <rte_common.h> #include <rte_string_fns.h> #include <cmdline_parse.h> #include <cmdline_parse_string.h> #include "test_cmdline.h" /* structures needed to run tests */ struct string_elt_str { const char * str; /* parsed string */ const char * result; /* expected string */ int idx; /* position at which result is expected to be */ }; struct string_elt_str string_elt_strs[] = { {"one#two#three", "three", 2}, {"one#two with spaces#three", "three", 2}, {"one#two\twith\ttabs#three", "three", 2}, {"one#two\rwith\rreturns#three", "three", 2}, {"one#two\nwith\nnewlines#three", "three", 2}, {"one#two#three", "one", 0}, {"one#two#three", "two", 1}, {"one#two\0three", "two", 1}, {"one#two with spaces#three", "two with spaces", 1}, {"one#two\twith\ttabs#three", "two\twith\ttabs", 1}, {"one#two\rwith\rreturns#three", "two\rwith\rreturns", 1}, {"one#two\nwith\nnewlines#three", "two\nwith\nnewlines", 1}, }; #if (CMDLINE_TEST_BUFSIZE < STR_TOKEN_SIZE) \ || (CMDLINE_TEST_BUFSIZE < STR_MULTI_TOKEN_SIZE) #undef CMDLINE_TEST_BUFSIZE #define CMDLINE_TEST_BUFSIZE RTE_MAX(STR_TOKEN_SIZE, STR_MULTI_TOKEN_SIZE) #endif struct string_nb_str { const char * str; /* parsed string */ int nb_strs; /* expected number of strings in str */ }; struct string_nb_str string_nb_strs[] = { {"one#two#three", 3}, {"one", 1}, {"one# \t two \r # three \n #four", 4}, }; struct string_parse_str { const char * str; /* parsed string */ const char * fixed_str; /* parsing mode (any, fixed or multi) */ const char * result; /* expected result */ }; struct string_parse_str string_parse_strs[] = { {"one", NULL, "one"}, /* any string */ {"two", "one#two#three", "two"}, /* multiple choice string */ {"three", "three", "three"}, /* fixed string */ {"three", "one#two with\rgarbage\tcharacters\n#three", "three"}, {"two with\rgarbage\tcharacters\n", "one#two with\rgarbage\tcharacters\n#three", "two with\rgarbage\tcharacters\n"}, {"one two", "one", "one"}, /* fixed string */ {"one two", TOKEN_STRING_MULTI, "one two"}, /* multi string */ {"one two", NULL, "one"}, /* any string */ {"one two #three", TOKEN_STRING_MULTI, "one two "}, /* multi string with comment */ }; struct string_invalid_str { const char * str; /* parsed string */ const char * fixed_str; /* parsing mode (any, fixed or multi) */ }; struct string_invalid_str string_invalid_strs[] = { {"invalid", "one"}, /* fixed string */ {"invalid", "one#two#three"}, /* multiple choice string */ {"invalid", "invalidone"}, /* string that starts the same */ {"invalidone", "invalid"}, /* string that starts the same */ {"toolong!!!toolong!!!toolong!!!toolong!!!toolong!!!toolong!!!" "toolong!!!toolong!!!toolong!!!toolong!!!toolong!!!toolong!!!" "toolong!!!", NULL }, {"toolong!!!toolong!!!toolong!!!toolong!!!toolong!!!toolong!!!" "toolong!!!toolong!!!toolong!!!toolong!!!toolong!!!toolong!!!" "toolong!!!", "fixed" }, {"toolong!!!toolong!!!toolong!!!toolong!!!toolong!!!toolong!!!" "toolong!!!toolong!!!toolong!!!toolong!!!toolong!!!toolong!!!" "toolong!!!", "multi#choice#string" }, {"invalid", "toolong!!!toolong!!!toolong!!!toolong!!!toolong!!!toolong!!!" "toolong!!!toolong!!!toolong!!!toolong!!!toolong!!!toolong!!!" "toolong!!!" }, {"", "invalid"} }; const char * string_help_strs[] = { NULL, "fixed_str", "multi#str", }; #define STRING_PARSE_STRS_SIZE \ (sizeof(string_parse_strs) / sizeof(string_parse_strs[0])) #define STRING_HELP_STRS_SIZE \ (sizeof(string_help_strs) / sizeof(string_help_strs[0])) #define STRING_ELT_STRS_SIZE \ (sizeof(string_elt_strs) / sizeof(string_elt_strs[0])) #define STRING_NB_STRS_SIZE \ (sizeof(string_nb_strs) / sizeof(string_nb_strs[0])) #define STRING_INVALID_STRS_SIZE \ (sizeof(string_invalid_strs) / sizeof(string_invalid_strs[0])) #define SMALL_BUF 8 /* test invalid parameters */ int test_parse_string_invalid_param(void) { cmdline_parse_token_string_t token; int result; char buf[CMDLINE_TEST_BUFSIZE]; memset(&token, 0, sizeof(token)); snprintf(buf, sizeof(buf), "buffer"); /* test null token */ if (cmdline_get_help_string( NULL, buf, 0) != -1) { printf("Error: function accepted null token!\n"); return -1; } if (cmdline_complete_get_elt_string( NULL, 0, buf, 0) != -1) { printf("Error: function accepted null token!\n"); return -1; } if (cmdline_complete_get_nb_string(NULL) != -1) { printf("Error: function accepted null token!\n"); return -1; } if (cmdline_parse_string(NULL, buf, NULL, 0) != -1) { printf("Error: function accepted null token!\n"); return -1; } /* test null buffer */ if (cmdline_complete_get_elt_string( (cmdline_parse_token_hdr_t*)&token, 0, NULL, 0) != -1) { printf("Error: function accepted null buffer!\n"); return -1; } if (cmdline_parse_string( (cmdline_parse_token_hdr_t*)&token, NULL, (void*)&result, sizeof(result)) != -1) { printf("Error: function accepted null buffer!\n"); return -1; } if (cmdline_get_help_string( (cmdline_parse_token_hdr_t*)&token, NULL, 0) != -1) { printf("Error: function accepted null buffer!\n"); return -1; } /* test null result */ if (cmdline_parse_string( (cmdline_parse_token_hdr_t*)&token, buf, NULL, 0) == -1) { printf("Error: function rejected null result!\n"); return -1; } /* test negative index */ if (cmdline_complete_get_elt_string( (cmdline_parse_token_hdr_t*)&token, -1, buf, 0) != -1) { printf("Error: function accepted negative index!\n"); return -1; } return 0; } /* test valid parameters but invalid data */ int test_parse_string_invalid_data(void) { cmdline_parse_token_string_t token; cmdline_parse_token_string_t help_token; char buf[CMDLINE_TEST_BUFSIZE]; char help_str[CMDLINE_TEST_BUFSIZE]; char small_buf[SMALL_BUF]; unsigned i; /* test parsing invalid strings */ for (i = 0; i < STRING_INVALID_STRS_SIZE; i++) { memset(&token, 0, sizeof(token)); memset(buf, 0, sizeof(buf)); /* prepare test token data */ token.string_data.str = string_invalid_strs[i].fixed_str; if (cmdline_parse_string((cmdline_parse_token_hdr_t*)&token, string_invalid_strs[i].str, (void*)buf, sizeof(buf)) != -1) { memset(help_str, 0, sizeof(help_str)); memset(&help_token, 0, sizeof(help_token)); help_token.string_data.str = string_invalid_strs[i].fixed_str; /* get parse type so we can give a good error message */ cmdline_get_help_string((cmdline_parse_token_hdr_t*)&token, help_str, sizeof(help_str)); printf("Error: parsing %s as %s succeeded!\n", string_invalid_strs[i].str, help_str); return -1; } } /* misc tests (big comments signify test cases) */ memset(&token, 0, sizeof(token)); memset(small_buf, 0, sizeof(small_buf)); /* * try to get element from a null token */ token.string_data.str = NULL; if (cmdline_complete_get_elt_string( (cmdline_parse_token_hdr_t*)&token, 1, buf, sizeof(buf)) != -1) { printf("Error: getting token from null token string!\n"); return -1; } /* * try to get element into a buffer that is too small */ token.string_data.str = "too_small_buffer"; if (cmdline_complete_get_elt_string( (cmdline_parse_token_hdr_t*)&token, 0, small_buf, sizeof(small_buf)) != -1) { printf("Error: writing token into too small a buffer succeeded!\n"); return -1; } /* * get help string written into a buffer smaller than help string * truncation should occur */ token.string_data.str = NULL; if (cmdline_get_help_string( (cmdline_parse_token_hdr_t*)&token, small_buf, sizeof(small_buf)) == -1) { printf("Error: writing help string into too small a buffer failed!\n"); return -1; } /* get help string for "any string" so we can compare it with small_buf */ cmdline_get_help_string((cmdline_parse_token_hdr_t*)&token, help_str, sizeof(help_str)); if (strncmp(small_buf, help_str, sizeof(small_buf) - 1)) { printf("Error: help string mismatch!\n"); return -1; } /* check null terminator */ if (small_buf[sizeof(small_buf) - 1] != '\0') { printf("Error: small buffer doesn't have a null terminator!\n"); return -1; } /* * try to count tokens in a null token */ token.string_data.str = NULL; if (cmdline_complete_get_nb_string( (cmdline_parse_token_hdr_t*)&token) != 0) { printf("Error: getting token count from null token succeeded!\n"); return -1; } return 0; } /* test valid parameters and data */ int test_parse_string_valid(void) { cmdline_parse_token_string_t token; cmdline_parse_token_string_t help_token; char buf[CMDLINE_TEST_BUFSIZE]; char help_str[CMDLINE_TEST_BUFSIZE]; unsigned i; /* test parsing strings */ for (i = 0; i < STRING_PARSE_STRS_SIZE; i++) { memset(&token, 0, sizeof(token)); memset(buf, 0, sizeof(buf)); token.string_data.str = string_parse_strs[i].fixed_str; if (cmdline_parse_string((cmdline_parse_token_hdr_t*)&token, string_parse_strs[i].str, (void*)buf, sizeof(buf)) < 0) { /* clean help data */ memset(&help_token, 0, sizeof(help_token)); memset(help_str, 0, sizeof(help_str)); /* prepare help token */ help_token.string_data.str = string_parse_strs[i].fixed_str; /* get help string so that we get an informative error message */ cmdline_get_help_string((cmdline_parse_token_hdr_t*)&token, help_str, sizeof(help_str)); printf("Error: parsing %s as %s failed!\n", string_parse_strs[i].str, help_str); return -1; } if (strcmp(buf, string_parse_strs[i].result) != 0) { printf("Error: result mismatch!\n"); return -1; } } /* get number of string tokens and verify it's correct */ for (i = 0; i < STRING_NB_STRS_SIZE; i++) { memset(&token, 0, sizeof(token)); token.string_data.str = string_nb_strs[i].str; if (cmdline_complete_get_nb_string( (cmdline_parse_token_hdr_t*)&token) < string_nb_strs[i].nb_strs) { printf("Error: strings count mismatch!\n"); return -1; } } /* get token at specified position and verify it's correct */ for (i = 0; i < STRING_ELT_STRS_SIZE; i++) { memset(&token, 0, sizeof(token)); memset(buf, 0, sizeof(buf)); token.string_data.str = string_elt_strs[i].str; if (cmdline_complete_get_elt_string( (cmdline_parse_token_hdr_t*)&token, string_elt_strs[i].idx, buf, sizeof(buf)) < 0) { printf("Error: getting string element failed!\n"); return -1; } if (strncmp(buf, string_elt_strs[i].result, sizeof(buf)) != 0) { printf("Error: result mismatch!\n"); return -1; } } /* cover all cases with help strings */ for (i = 0; i < STRING_HELP_STRS_SIZE; i++) { memset(&help_token, 0, sizeof(help_token)); memset(help_str, 0, sizeof(help_str)); help_token.string_data.str = string_help_strs[i]; if (cmdline_get_help_string((cmdline_parse_token_hdr_t*)&help_token, help_str, sizeof(help_str)) < 0) { printf("Error: help operation failed!\n"); return -1; } } return 0; }
30.757869
75
0.685901
cf569b6ef19ee38be15c6f5350c858ee3844f744
1,384
h
C
dotnet/native/sealnet/batchencoder_wrapper.h
MasterMann/SEAL
791ae130de895e6323d36a12515cf2d59071e414
[ "MIT" ]
5
2019-04-29T01:46:05.000Z
2021-10-10T10:28:02.000Z
dotnet/native/sealnet/batchencoder_wrapper.h
MasterMann/SEAL
791ae130de895e6323d36a12515cf2d59071e414
[ "MIT" ]
null
null
null
dotnet/native/sealnet/batchencoder_wrapper.h
MasterMann/SEAL
791ae130de895e6323d36a12515cf2d59071e414
[ "MIT" ]
4
2019-04-18T11:28:13.000Z
2020-11-01T14:25:35.000Z
// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. #pragma once /////////////////////////////////////////////////////////////////////////// // // This API is provided as a simple interface for Microsoft SEAL library // that can be PInvoked by .Net code. // /////////////////////////////////////////////////////////////////////////// #include "sealnet/defines.h" #include <stdint.h> SEALNETNATIVE HRESULT SEALCALL BatchEncoder_Create(void *context, void **batch_encoder); SEALNETNATIVE HRESULT SEALCALL BatchEncoder_Destroy(void *thisptr); SEALNETNATIVE HRESULT SEALCALL BatchEncoder_Encode1(void *thisptr, uint64_t count, uint64_t *values, void *destination); SEALNETNATIVE HRESULT SEALCALL BatchEncoder_Encode2(void *thisptr, uint64_t count, int64_t *values, void *destination); SEALNETNATIVE HRESULT SEALCALL BatchEncoder_Encode3(void *thisptr, void *plain, void *pool); SEALNETNATIVE HRESULT SEALCALL BatchEncoder_Decode1(void *thisptr, void *plain, uint64_t *count, uint64_t *destination, void *pool); SEALNETNATIVE HRESULT SEALCALL BatchEncoder_Decode2(void *thisptr, void *plain, uint64_t *count, int64_t *destination, void *pool); SEALNETNATIVE HRESULT SEALCALL BatchEncoder_Decode3(void *thisptr, void *plain, void *pool); SEALNETNATIVE HRESULT SEALCALL BatchEncoder_GetSlotCount(void *thisptr, uint64_t *slot_count);
41.939394
132
0.71315
d6781c948af1b61828ed6e479c5149e2a4ad9d0c
36,575
c
C
sys/vfs/fuse/fuse_vnops.c
atrens/DragonFlyBSD-src
5fae20fd2cfd3e7ba6b543f20951209e328e5737
[ "BSD-3-Clause" ]
null
null
null
sys/vfs/fuse/fuse_vnops.c
atrens/DragonFlyBSD-src
5fae20fd2cfd3e7ba6b543f20951209e328e5737
[ "BSD-3-Clause" ]
null
null
null
sys/vfs/fuse/fuse_vnops.c
atrens/DragonFlyBSD-src
5fae20fd2cfd3e7ba6b543f20951209e328e5737
[ "BSD-3-Clause" ]
null
null
null
/*- * Copyright (c) 2019 Tomohiro Kusumi <tkusumi@netbsd.org> * Copyright (c) 2019 The DragonFly Project * 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. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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 "fuse.h" #include <sys/fcntl.h> #include <sys/dirent.h> #include <sys/uio.h> #include <sys/mountctl.h> #include <vm/vm_pager.h> #include <vm/vnode_pager.h> static int fuse_set_attr(struct fuse_node *fnp, struct fuse_attr *fat) { struct vattr *vap = &fnp->attr; int error = 0; vattr_null(vap); vap->va_type = IFTOVT(fat->mode); vap->va_size = fat->size; vap->va_bytes = fat->blocks * S_BLKSIZE; vap->va_mode = fat->mode & ~S_IFMT; if (!fat->nlink) /* XXX .fuse_hidden* has 0 link */ vap->va_nlink = 1; else vap->va_nlink = fat->nlink; vap->va_uid = fat->uid; vap->va_gid = fat->gid; vap->va_fsid = fnp->fmp->mp->mnt_stat.f_fsid.val[0]; vap->va_fileid = fat->ino; vap->va_blocksize = FUSE_BLKSIZE; vap->va_rmajor = VNOVAL; vap->va_rminor = VNOVAL; vap->va_atime.tv_sec = fat->atime; vap->va_atime.tv_nsec = fat->atimensec; vap->va_mtime.tv_sec = fat->mtime; vap->va_mtime.tv_nsec = fat->mtimensec; vap->va_ctime.tv_sec = fat->ctime; vap->va_ctime.tv_nsec = fat->ctimensec; vap->va_flags = 0; vap->va_gen = VNOVAL; vap->va_vaflags = 0; KKASSERT(vap->va_type == fnp->type); if (fnp->nlink != vap->va_nlink) { fuse_dbg("ino=%ju update nlink %d -> %ju\n", fnp->ino, fnp->nlink, vap->va_nlink); fnp->nlink = vap->va_nlink; } if (fnp->vp->v_object && fnp->size != vap->va_size) error = fuse_node_truncate(fnp, fnp->size, vap->va_size); return error; } static int fuse_vop_access(struct vop_access_args *ap) { struct vnode *vp = ap->a_vp; mode_t mode = ap->a_mode; struct fuse_mount *fmp = VFSTOFUSE(vp->v_mount); struct fuse_ipc *fip; struct fuse_access_in *fai; uint32_t mask; int error; if (fuse_test_dead(fmp)) return 0; if (fuse_test_nosys(fmp, FUSE_ACCESS)) return 0; switch (vp->v_type) { case VDIR: case VLNK: case VREG: if ((mode & VWRITE) && (vp->v_mount->mnt_flag & MNT_RDONLY)) return EROFS; break; case VBLK: case VCHR: case VSOCK: case VFIFO: break; default: return EINVAL; } mask = F_OK; if (mode & VEXEC) mask |= X_OK; if (mode & VWRITE) mask |= W_OK; if (mode & VREAD) mask |= R_OK; fip = fuse_ipc_get(fmp, sizeof(*fai)); fai = fuse_ipc_fill(fip, FUSE_ACCESS, VTOI(vp)->ino, ap->a_cred); fai->mask = mask; error = fuse_ipc_tx(fip); if (error) { if (error == ENOSYS) error = 0; if (error == ENOTCONN && (vp->v_flag & VROOT)) error = 0; return error; } fuse_ipc_put(fip); return 0; } static int fuse_vop_open(struct vop_open_args *ap) { struct vnode *vp = ap->a_vp; struct fuse_mount *fmp = VFSTOFUSE(vp->v_mount); struct fuse_node *fnp = VTOI(vp); struct fuse_ipc *fip; struct fuse_open_in *foi; struct fuse_open_out *foo; int error, op; if (fuse_test_dead(fmp)) return ENOTCONN; if (fuse_test_nosys(fmp, FUSE_OPEN)) return EOPNOTSUPP; if (vp->v_type == VDIR) op = FUSE_OPENDIR; else op = FUSE_OPEN; fip = fuse_ipc_get(fmp, sizeof(*foi)); foi = fuse_ipc_fill(fip, op, fnp->ino, ap->a_cred); foi->flags = OFLAGS(ap->a_mode); fuse_dbg("flags=%X\n", foi->flags); if (foi->flags & O_CREAT) { fuse_dbg("drop O_CREAT\n"); foi->flags &= ~O_CREAT; } error = fuse_ipc_tx(fip); if (error) return error; /* XXX unused */ foo = fuse_out_data(fip); if (foo->open_flags & FOPEN_DIRECT_IO) ; else if (foo->open_flags & FOPEN_KEEP_CACHE) ; else if (foo->open_flags & FOPEN_NONSEEKABLE) ; else if (foo->open_flags & FOPEN_CACHE_DIR) ; fnp->closed = false; fuse_get_nfh(VTOI(vp), foo->fh); if (ap->a_fp) { #if 1 fuse_get_fh(ap->a_fp, foo->fh); #else /* see #if0'd code in fuse_vop_setattr() */ if (!ap->a_fp->private_data) fuse_get_fh(ap->a_fp, foo->fh); else { uint64_t *fhp = ap->a_fp->private_data; *fhp = foo->fh; } #endif } fuse_ipc_put(fip); return vop_stdopen(ap); } static int fuse_vop_close(struct vop_close_args *ap) { struct vnode *vp = ap->a_vp; struct fuse_mount *fmp = VFSTOFUSE(vp->v_mount); struct fuse_node *fnp = VTOI(vp); struct fuse_ipc *fip; struct fuse_release_in *fri; int error, op; if (fuse_test_dead(fmp)) return 0; if (fuse_test_nosys(fmp, FUSE_RELEASE) || fuse_test_nosys(fmp, FUSE_RELEASEDIR)) return EOPNOTSUPP; if (vp->v_type == VDIR) op = FUSE_RELEASEDIR; else op = FUSE_RELEASE; fip = fuse_ipc_get(fmp, sizeof(*fri)); fri = fuse_ipc_fill(fip, op, fnp->ino, NULL); /* unused */ //fri->flags = ...; //fri->release_flags = ...; //fri->lock_owner = ...; fri->fh = fuse_nfh(VTOI(vp)); if (ap->a_fp) fri->fh = fuse_fh(ap->a_fp); error = fuse_ipc_tx(fip); if (error) return error; fuse_ipc_put(fip); fnp->closed = true; fuse_put_nfh(VTOI(vp)); if (ap->a_fp) fuse_put_fh(ap->a_fp); return vop_stdclose(ap); } static int fuse_vop_fsync(struct vop_fsync_args *ap) { struct vnode *vp = ap->a_vp; struct fuse_mount *fmp = VFSTOFUSE(vp->v_mount); struct fuse_ipc *fip; struct fuse_fsync_in *fsi; int error, op; if (fuse_test_dead(fmp)) return 0; if (fuse_test_nosys(fmp, FUSE_FSYNC)) return 0; if (vp->v_type == VDIR) op = FUSE_FSYNCDIR; else op = FUSE_FSYNC; fip = fuse_ipc_get(fmp, sizeof(*fsi)); fsi = fuse_ipc_fill(fip, op, VTOI(vp)->ino, NULL); fsi->fh = fuse_nfh(VTOI(vp)); if (ap->a_fp) fsi->fh = fuse_fh(ap->a_fp); fsi->fsync_flags = 1; /* datasync */ error = fuse_ipc_tx(fip); if (error) return error; fuse_ipc_put(fip); vn_syncer_remove(vp, 1); vfsync(ap->a_vp, ap->a_waitfor, 1, NULL, NULL); vclrisdirty(vp); return 0; } static int fuse_vop_getattr(struct vop_getattr_args *ap) { struct vnode *vp = ap->a_vp; struct vattr *vap = ap->a_vap; struct fuse_mount *fmp = VFSTOFUSE(vp->v_mount); struct fuse_node *fnp = VTOI(vp); struct fuse_ipc *fip; struct fuse_getattr_in *fgi; struct fuse_attr_out *fao; int error; if (fuse_test_dead(fmp)) return 0; if (fuse_test_nosys(fmp, FUSE_GETATTR)) return 0; fip = fuse_ipc_get(fmp, sizeof(*fgi)); fgi = fuse_ipc_fill(fip, FUSE_GETATTR, fnp->ino, NULL); #if 0 /* this may be called before open when fh is 0 */ fgi->getattr_flags |= FUSE_GETATTR_FH; fgi->fh = fuse_nfh(fnp); if (ap->a_fp) fgi->fh = fuse_fh(ap->a_fp); #endif error = fuse_ipc_tx(fip); if (error) { if (error == ENOSYS) error = 0; if (error == ENOTCONN && (vp->v_flag & VROOT)) { memset(vap, 0, sizeof(*vap)); vap->va_type = vp->v_type; error = 0; } return error; } fao = fuse_out_data(fip); mtx_lock(&fnp->node_lock); fuse_set_attr(fnp, &fao->attr); memcpy(vap, &fnp->attr, sizeof(*vap)); /* unused */ //fao->attr_valid; //fao->attr_valid_nsec; mtx_unlock(&fnp->node_lock); fuse_ipc_put(fip); if (vap->va_type != vp->v_type) return EINVAL; return 0; } static int fuse_vop_setattr(struct vop_setattr_args *ap) { struct vnode *vp = ap->a_vp; struct vattr *vap = ap->a_vap; struct fuse_mount *fmp = VFSTOFUSE(vp->v_mount); struct fuse_node *fnp = VTOI(vp); struct fuse_ipc *fip; struct fuse_setattr_in *fsi, arg; struct fuse_attr_out *fao; int kflags = 0; int error = 0; if (fuse_test_dead(fmp)) return 0; if (fuse_test_nosys(fmp, FUSE_SETATTR)) return 0; if (vp->v_mount->mnt_flag & MNT_RDONLY) return EROFS; memset(&arg, 0, sizeof(arg)); mtx_lock(&fnp->node_lock); if (!error && (vap->va_flags != VNOVAL)) { mtx_unlock(&fnp->node_lock); kflags |= NOTE_ATTRIB; return EOPNOTSUPP; /* XXX */ } if (!error && (vap->va_size != VNOVAL)) { if (vp->v_type == VDIR) { mtx_unlock(&fnp->node_lock); return EISDIR; } if (vp->v_type == VREG && (vp->v_mount->mnt_flag & MNT_RDONLY)) { mtx_unlock(&fnp->node_lock); return EROFS; } arg.size = vap->va_size; arg.valid |= FATTR_SIZE; if (vap->va_size > fnp->size) kflags |= NOTE_WRITE | NOTE_EXTEND; else kflags |= NOTE_WRITE; } if (!error && (vap->va_uid != (uid_t)VNOVAL || vap->va_gid != (gid_t)VNOVAL)) { mode_t mode; error = vop_helper_chown(vp, vap->va_uid, vap->va_gid, ap->a_cred, &arg.uid, &arg.gid, &mode); arg.valid |= FATTR_UID; arg.valid |= FATTR_GID; kflags |= NOTE_ATTRIB; } if (!error && (vap->va_mode != (mode_t)VNOVAL)) { error = vop_helper_chmod(vp, vap->va_mode, ap->a_cred, vap->va_uid, vap->va_gid, (mode_t*)&arg.mode); arg.valid |= FATTR_MODE; kflags |= NOTE_ATTRIB; } if (!error && (vap->va_atime.tv_sec != VNOVAL && vap->va_atime.tv_nsec != VNOVAL)) { arg.atime = vap->va_atime.tv_sec; arg.atimensec = vap->va_atime.tv_nsec; arg.valid |= FATTR_ATIME; kflags |= NOTE_ATTRIB; } if (!error && (vap->va_mtime.tv_sec != VNOVAL && vap->va_mtime.tv_nsec != VNOVAL)) { arg.mtime = vap->va_mtime.tv_sec; arg.mtimensec = vap->va_mtime.tv_nsec; arg.valid |= FATTR_MTIME; kflags |= NOTE_ATTRIB; } if (!error && (vap->va_ctime.tv_sec != VNOVAL && vap->va_ctime.tv_nsec != VNOVAL)) { arg.ctime = vap->va_ctime.tv_sec; arg.ctimensec = vap->va_ctime.tv_nsec; arg.valid |= FATTR_CTIME; kflags |= NOTE_ATTRIB; } mtx_unlock(&fnp->node_lock); if (error) return error; if (!arg.valid) return 0; fip = fuse_ipc_get(fmp, sizeof(*fsi)); fsi = fuse_ipc_fill(fip, FUSE_SETATTR, fnp->ino, ap->a_cred); memcpy(fsi, &arg, sizeof(arg)); #if 0 fsi->valid |= FATTR_FH; fsi->fh = fuse_nfh(fnp); if (ap->a_fp) { /* vn_open() may call VOP_SETATTR_FP() prior to VOP_OPEN(). */ if (!ap->a_fp->private_data) fuse_get_fh(ap->a_fp, 0); /* XXX */ fsi->fh = fuse_fh(ap->a_fp); } #endif error = fuse_ipc_tx(fip); if (error) return error; fao = fuse_out_data(fip); if (IFTOVT(fao->attr.mode) != vp->v_type) { fuse_ipc_put(fip); return EINVAL; } mtx_lock(&fnp->node_lock); fuse_set_attr(fnp, &fao->attr); /* unused */ //fao->attr_valid; //fao->attr_valid_nsec; mtx_unlock(&fnp->node_lock); fuse_ipc_put(fip); fuse_knote(vp, kflags); return 0; } static int fuse_vop_nresolve(struct vop_nresolve_args *ap) { struct vnode *dvp = ap->a_dvp; struct vnode *vp; struct namecache *ncp = ap->a_nch->ncp; struct fuse_mount *fmp = VFSTOFUSE(dvp->v_mount); struct fuse_node *dfnp = VTOI(dvp); struct fuse_ipc *fip; struct fuse_entry_out *feo; char *p, tmp[1024]; uint32_t mode; enum vtype vtyp; int error; if (fuse_test_dead(fmp)) return ENOTCONN; if (fuse_test_nosys(fmp, FUSE_LOOKUP)) return EOPNOTSUPP; fip = fuse_ipc_get(fmp, ncp->nc_nlen + 1); p = fuse_ipc_fill(fip, FUSE_LOOKUP, dfnp->ino, ap->a_cred); memcpy(p, ncp->nc_name, ncp->nc_nlen); p[ncp->nc_nlen] = '\0'; strlcpy(tmp, p, sizeof(tmp)); error = fuse_ipc_tx(fip); if (error == ENOENT) { cache_setvp(ap->a_nch, NULL); fuse_dbg("lookup \"%s\" ENOENT\n", tmp); return ENOENT; } else if (error) { fuse_dbg("lookup \"%s\" error=%d\n", tmp, error); return error; } feo = fuse_out_data(fip); fuse_dbg("lookup \"%s\" ino=%ju/%ju\n", p, feo->nodeid, feo->attr.ino); mode = feo->attr.mode; if (S_ISREG(mode)) vtyp = VREG; else if (S_ISDIR(mode)) vtyp = VDIR; else if (S_ISBLK(mode)) vtyp = VBLK; else if (S_ISCHR(mode)) vtyp = VCHR; else if (S_ISLNK(mode)) vtyp = VLNK; else if (S_ISSOCK(mode)) vtyp = VSOCK; else if (S_ISFIFO(mode)) vtyp = VFIFO; else vtyp = VBAD; error = fuse_alloc_node(dfnp, feo->nodeid, p, strlen(p), vtyp, &vp); if (error) { fuse_ipc_put(fip); return error; } KKASSERT(vp); KKASSERT(vn_islocked(vp)); vn_unlock(vp); cache_setvp(ap->a_nch, vp); vrele(vp); /* unused */ //feo->generation; //feo->entry_valid; //feo->attr_valid; //feo->entry_valid_nsec; //feo->attr_valid_nsec; fuse_ipc_put(fip); return 0; } static int fuse_vop_nlink(struct vop_nlink_args *ap) { struct vnode *dvp = ap->a_dvp; struct vnode *vp = ap->a_vp; struct namecache *ncp = ap->a_nch->ncp; struct fuse_mount *fmp = VFSTOFUSE(vp->v_mount); struct fuse_node *dfnp = VTOI(dvp); struct fuse_node *fnp = VTOI(vp); struct fuse_dent *fep; struct fuse_ipc *fip; struct fuse_link_in *fli; struct fuse_entry_out *feo; char *p; int error; if (fuse_test_dead(fmp)) return ENOTCONN; if (fuse_test_nosys(fmp, FUSE_LINK)) return EOPNOTSUPP; if (vp->v_type == VDIR) return EPERM; if (dvp->v_mount != vp->v_mount) return EXDEV; if (fnp->nlink >= LINK_MAX) return EMLINK; fip = fuse_ipc_get(fmp, sizeof(fli) + ncp->nc_nlen + 1); fli = fuse_ipc_fill(fip, FUSE_LINK, dfnp->ino, ap->a_cred); fli->oldnodeid = fnp->ino; p = (char*)(fli + 1); memcpy(p, ncp->nc_name, ncp->nc_nlen); p[ncp->nc_nlen] = '\0'; error = fuse_ipc_tx(fip); if (error) return error; feo = fuse_out_data(fip); if (IFTOVT(feo->attr.mode) != vp->v_type) { fuse_ipc_put(fip); return EINVAL; } mtx_lock(&dfnp->node_lock); mtx_lock(&fnp->node_lock); fuse_dent_new(fnp, p, strlen(p), &fep); fuse_dent_attach(dfnp, fep); fuse_set_attr(fnp, &feo->attr); mtx_unlock(&fnp->node_lock); mtx_unlock(&dfnp->node_lock); cache_setunresolved(ap->a_nch); cache_setvp(ap->a_nch, vp); fuse_knote(dvp, NOTE_WRITE); fuse_knote(vp, NOTE_LINK); /* unused */ //feo->nodeid; //feo->generation; //feo->entry_valid; //feo->attr_valid; //feo->entry_valid_nsec; //feo->attr_valid_nsec; fuse_ipc_put(fip); return 0; } static int fuse_vop_ncreate(struct vop_ncreate_args *ap) { struct vnode *dvp = ap->a_dvp; struct vnode *vp; struct namecache *ncp = ap->a_nch->ncp; struct fuse_mount *fmp = VFSTOFUSE(dvp->v_mount); struct fuse_node *dfnp = VTOI(dvp); struct fuse_node *fnp; struct fuse_ipc *fip; struct fuse_create_in *fci; struct fuse_entry_out *feo; struct fuse_open_out *foo; enum vtype vtyp; char *p; int error; if (fuse_test_dead(fmp)) return ENOTCONN; if (fuse_test_nosys(fmp, FUSE_CREATE)) return EOPNOTSUPP; fip = fuse_ipc_get(fmp, sizeof(*fci) + ncp->nc_nlen + 1); fci = fuse_ipc_fill(fip, FUSE_CREATE, dfnp->ino, ap->a_cred); fci->flags = OFLAGS(ap->a_vap->va_fuseflags); fci->mode = MAKEIMODE(ap->a_vap->va_type, ap->a_vap->va_mode); /* unused */ //fci->umask = ...; fuse_dbg("flags=%X mode=%X\n", fci->flags, fci->mode); p = (char*)(fci + 1); memcpy(p, ncp->nc_name, ncp->nc_nlen); p[ncp->nc_nlen] = '\0'; error = fuse_ipc_tx(fip); if (error) return error; feo = fuse_out_data(fip); foo = (struct fuse_open_out*)(feo + 1); vtyp = IFTOVT(feo->attr.mode); if (vtyp != VREG && vtyp != VSOCK) { fuse_ipc_put(fip); return EINVAL; } error = fuse_alloc_node(dfnp, feo->nodeid, p, strlen(p), VREG, &vp); if (error) { fuse_ipc_put(fip); return error; } KKASSERT(vp); KKASSERT(vn_islocked(vp)); fnp = VTOI(vp); mtx_lock(&fnp->node_lock); fuse_set_attr(fnp, &feo->attr); mtx_unlock(&fnp->node_lock); cache_setunresolved(ap->a_nch); cache_setvp(ap->a_nch, vp); *(ap->a_vpp) = vp; fuse_knote(dvp, NOTE_WRITE); /* unused */ //feo->generation; //feo->entry_valid; //feo->attr_valid; //feo->entry_valid_nsec; //feo->attr_valid_nsec; /* unused */ //foo->open_flags; fuse_ipc_put(fip); return 0; } static int fuse_vop_nmknod(struct vop_nmknod_args *ap) { struct vnode *dvp = ap->a_dvp; struct vnode *vp; struct namecache *ncp = ap->a_nch->ncp; struct fuse_mount *fmp = VFSTOFUSE(dvp->v_mount); struct fuse_node *dfnp = VTOI(dvp); struct fuse_node *fnp; struct fuse_ipc *fip; struct fuse_mknod_in *fmi; struct fuse_entry_out *feo; enum vtype vtyp; char *p; int error; if (fuse_test_dead(fmp)) return ENOTCONN; if (fuse_test_nosys(fmp, FUSE_MKNOD)) return EOPNOTSUPP; fip = fuse_ipc_get(fmp, sizeof(*fmi) + ncp->nc_nlen + 1); fmi = fuse_ipc_fill(fip, FUSE_MKNOD, dfnp->ino, ap->a_cred); fmi->mode = MAKEIMODE(ap->a_vap->va_type, ap->a_vap->va_mode); /* unused */ //fmi->rdev = ...; //fmi->umask = ...; p = (char*)(fmi + 1); memcpy(p, ncp->nc_name, ncp->nc_nlen); p[ncp->nc_nlen] = '\0'; error = fuse_ipc_tx(fip); if (error) return error; feo = fuse_out_data(fip); vtyp = IFTOVT(feo->attr.mode); if (vtyp != VBLK && vtyp != VCHR && vtyp != VFIFO) { fuse_ipc_put(fip); return EINVAL; } error = fuse_alloc_node(dfnp, feo->nodeid, p, strlen(p), ap->a_vap->va_type, &vp); if (error) { fuse_ipc_put(fip); return error; } KKASSERT(vp); KKASSERT(vn_islocked(vp)); fnp = VTOI(vp); mtx_lock(&fnp->node_lock); fuse_set_attr(fnp, &feo->attr); mtx_unlock(&fnp->node_lock); cache_setunresolved(ap->a_nch); cache_setvp(ap->a_nch, vp); *(ap->a_vpp) = vp; fuse_knote(dvp, NOTE_WRITE); /* unused */ //feo->generation; //feo->entry_valid; //feo->attr_valid; //feo->entry_valid_nsec; //feo->attr_valid_nsec; fuse_ipc_put(fip); return 0; } static int fuse_vop_nremove(struct vop_nremove_args *ap) { struct vnode *dvp = ap->a_dvp; struct vnode *vp; struct namecache *ncp = ap->a_nch->ncp; struct fuse_mount *fmp = VFSTOFUSE(dvp->v_mount); struct fuse_node *dfnp = VTOI(dvp); struct fuse_node *fnp; struct fuse_dent *fep; struct fuse_ipc *fip; char *p; int error; if (fuse_test_dead(fmp)) return ENOTCONN; if (fuse_test_nosys(fmp, FUSE_UNLINK)) return EOPNOTSUPP; error = cache_vget(ap->a_nch, ap->a_cred, LK_SHARED, &vp); KKASSERT(vp->v_mount == dvp->v_mount); KKASSERT(!error); /* from tmpfs */ vn_unlock(vp); fip = fuse_ipc_get(fmp, ncp->nc_nlen + 1); p = fuse_ipc_fill(fip, FUSE_UNLINK, dfnp->ino, ap->a_cred); memcpy(p, ncp->nc_name, ncp->nc_nlen); p[ncp->nc_nlen] = '\0'; error = fuse_ipc_tx(fip); if (error) { vrele(vp); return error; } fnp = VTOI(vp); mtx_lock(&dfnp->node_lock); mtx_lock(&fnp->node_lock); error = fuse_dent_find(dfnp, p, strlen(p), &fep); if (error == ENOENT) { mtx_unlock(&fnp->node_lock); mtx_unlock(&dfnp->node_lock); fuse_ipc_put(fip); vrele(vp); return error; } fuse_dent_detach(dfnp, fep); fuse_dent_free(fep); mtx_unlock(&fnp->node_lock); mtx_unlock(&dfnp->node_lock); cache_unlink(ap->a_nch); fuse_knote(dvp, NOTE_WRITE); fuse_knote(vp, NOTE_DELETE); fuse_ipc_put(fip); vrele(vp); return 0; } static int fuse_vop_nmkdir(struct vop_nmkdir_args *ap) { struct vnode *dvp = ap->a_dvp; struct vnode *vp; struct namecache *ncp = ap->a_nch->ncp; struct fuse_mount *fmp = VFSTOFUSE(dvp->v_mount); struct fuse_node *dfnp = VTOI(dvp); struct fuse_node *fnp; struct fuse_ipc *fip; struct fuse_mkdir_in *fmi; struct fuse_entry_out *feo; char *p; int error; if (fuse_test_dead(fmp)) return ENOTCONN; if (fuse_test_nosys(fmp, FUSE_MKDIR)) return EOPNOTSUPP; fip = fuse_ipc_get(fmp, sizeof(*fmi) + ncp->nc_nlen + 1); fmi = fuse_ipc_fill(fip, FUSE_MKDIR, dfnp->ino, ap->a_cred); fmi->mode = MAKEIMODE(ap->a_vap->va_type, ap->a_vap->va_mode); p = (char*)(fmi + 1); memcpy(p, ncp->nc_name, ncp->nc_nlen); p[ncp->nc_nlen] = '\0'; error = fuse_ipc_tx(fip); if (error) return error; feo = fuse_out_data(fip); if (IFTOVT(feo->attr.mode) != VDIR) { fuse_ipc_put(fip); return EINVAL; } error = fuse_alloc_node(dfnp, feo->nodeid, p, strlen(p), VDIR, &vp); if (error) { fuse_ipc_put(fip); return error; } KKASSERT(vp); KKASSERT(vn_islocked(vp)); fnp = VTOI(vp); mtx_lock(&fnp->node_lock); fuse_set_attr(fnp, &feo->attr); mtx_unlock(&fnp->node_lock); cache_setunresolved(ap->a_nch); cache_setvp(ap->a_nch, vp); *(ap->a_vpp) = vp; fuse_knote(dvp, NOTE_WRITE | NOTE_LINK); /* unused */ //feo->generation; //feo->entry_valid; //feo->attr_valid; //feo->entry_valid_nsec; //feo->attr_valid_nsec; fuse_ipc_put(fip); return 0; } static int fuse_vop_nrmdir(struct vop_nrmdir_args *ap) { struct vnode *dvp = ap->a_dvp; struct vnode *vp; struct namecache *ncp = ap->a_nch->ncp; struct fuse_mount *fmp = VFSTOFUSE(dvp->v_mount); struct fuse_node *dfnp = VTOI(dvp); struct fuse_node *fnp; struct fuse_dent *fep; struct fuse_ipc *fip; char *p; int error; if (fuse_test_dead(fmp)) return ENOTCONN; if (fuse_test_nosys(fmp, FUSE_RMDIR)) return EOPNOTSUPP; error = cache_vget(ap->a_nch, ap->a_cred, LK_SHARED, &vp); KKASSERT(vp->v_mount == dvp->v_mount); KKASSERT(!error); /* from tmpfs */ vn_unlock(vp); fip = fuse_ipc_get(fmp, ncp->nc_nlen + 1); p = fuse_ipc_fill(fip, FUSE_RMDIR, dfnp->ino, ap->a_cred); memcpy(p, ncp->nc_name, ncp->nc_nlen); p[ncp->nc_nlen] = '\0'; error = fuse_ipc_tx(fip); if (error) { vrele(vp); return error; } fnp = VTOI(vp); mtx_lock(&dfnp->node_lock); mtx_lock(&fnp->node_lock); error = fuse_dent_find(dfnp, p, strlen(p), &fep); if (error == ENOENT) { mtx_unlock(&fnp->node_lock); mtx_unlock(&dfnp->node_lock); fuse_ipc_put(fip); vrele(vp); return error; } fuse_dent_detach(dfnp, fep); fuse_dent_free(fep); mtx_unlock(&fnp->node_lock); mtx_unlock(&dfnp->node_lock); cache_unlink(ap->a_nch); fuse_knote(dvp, NOTE_WRITE | NOTE_LINK); fuse_ipc_put(fip); vrele(vp); return 0; } static int fuse_vop_pathconf(struct vop_pathconf_args *ap) { switch (ap->a_name) { case _PC_FILESIZEBITS: *ap->a_retval = 64; break; case _PC_NO_TRUNC: *ap->a_retval = 1; break; default: return vop_stdpathconf(ap); } return 0; } static int fuse_vop_readdir(struct vop_readdir_args *ap) { struct vnode *vp = ap->a_vp; struct uio *uio = ap->a_uio; struct fuse_mount *fmp = VFSTOFUSE(vp->v_mount); struct fuse_ipc *fip; struct fuse_read_in *fri; const char *buf; size_t len; off_t cur_offset = 0; int error; if (fuse_test_dead(fmp)) return ENOTCONN; if (fuse_test_nosys(fmp, FUSE_READDIR)) return EOPNOTSUPP; fip = fuse_ipc_get(fmp, sizeof(*fri)); fri = fuse_ipc_fill(fip, FUSE_READDIR, VTOI(vp)->ino, ap->a_cred); fri->fh = fuse_nfh(VTOI(vp)); if (ap->a_fp) fri->fh = fuse_fh(ap->a_fp); fri->offset = 0; /* * XXX This needs to be large enough to read all entries at once. * FUSE filesystems typically just opendir/readdir and return entries. */ fri->size = FUSE_BLKSIZE * 10; /* unused */ //fri->read_flags = ...; //fri->lock_owner = ...; //fri->flags = ...; error = fuse_ipc_tx(fip); if (error) return error; buf = fuse_out_data(fip); len = fuse_out_data_size(fip); while (1) { const struct fuse_dirent *fde; size_t freclen; fuse_dbg("uio_offset=%ju uio_resid=%ju\n", uio->uio_offset, uio->uio_resid); if (len < FUSE_NAME_OFFSET) { if (ap->a_eofflag) *ap->a_eofflag = 1; break; } if (uio->uio_resid < FUSE_NAME_OFFSET) break; fde = (const struct fuse_dirent*)buf; if (!fde->namelen) { error = EINVAL; break; } freclen = FUSE_DIRENT_SIZE(fde); /* * Also see * getdirentries(2) in sys/kern/vfs_syscalls.c * readdir(3) in lib/libc/gen/readdir.c */ if (cur_offset >= uio->uio_offset) { error = 0; if (vop_write_dirent(&error, uio, fde->ino, fde->type, fde->namelen, fde->name)) error = EINVAL; if (error) break; fuse_dbg("ino=%ju type=%d name=%s len=%u\n", fde->ino, fde->type, fde->name, fde->namelen); } cur_offset += _DIRENT_RECLEN(fde->namelen); buf += freclen; len -= freclen; } fuse_ipc_put(fip); return error; } static int fuse_vop_readlink(struct vop_readlink_args *ap) { struct vnode *vp = ap->a_vp; struct fuse_mount *fmp = VFSTOFUSE(vp->v_mount); struct fuse_ipc *fip; int error; if (fuse_test_dead(fmp)) return ENOTCONN; if (fuse_test_nosys(fmp, FUSE_READLINK)) return EOPNOTSUPP; if (vp->v_type != VLNK) return EINVAL; fip = fuse_ipc_get(fmp, 0); fuse_ipc_fill(fip, FUSE_READLINK, VTOI(vp)->ino, ap->a_cred); error = fuse_ipc_tx(fip); if (error) return error; error = uiomove(fuse_out_data(fip), fuse_out_data_size(fip), ap->a_uio); fuse_ipc_put(fip); return error; } static int fuse_vop_nrename(struct vop_nrename_args *ap) { struct namecache *fncp = ap->a_fnch->ncp; struct namecache *tncp = ap->a_tnch->ncp; struct vnode *fdvp = ap->a_fdvp; struct vnode *fvp = fncp->nc_vp; struct vnode *tdvp = ap->a_tdvp; struct vnode *tvp; struct fuse_mount *fmp = VFSTOFUSE(fdvp->v_mount); struct fuse_node *fdfnp = VTOI(fdvp); struct fuse_node *ffnp = VTOI(fvp); struct fuse_node *tdfnp = VTOI(tdvp); struct fuse_node *tfnp; struct fuse_dent *ffep; struct fuse_dent *tfep; struct fuse_ipc *fip; struct fuse_rename_in *fri; char *p, *newname, *oldname; int error; KKASSERT(fdvp->v_mount == fvp->v_mount); if (fuse_test_dead(fmp)) return ENOTCONN; if (fuse_test_nosys(fmp, FUSE_RENAME)) return EOPNOTSUPP; error = cache_vget(ap->a_tnch, ap->a_cred, LK_SHARED, &tvp); if (!error) { tfnp = VTOI(tvp); vn_unlock(tvp); } else tfnp = NULL; /* Disallow cross-device renames. * Why isn't this done by the caller? */ if (fvp->v_mount != tdvp->v_mount || (tvp && fvp->v_mount != tvp->v_mount)) { error = EXDEV; goto out; } if (fvp == tvp) { error = 0; goto out; } error = fuse_dent_find(fdfnp, fncp->nc_name, fncp->nc_nlen, &ffep); if (error == ENOENT) goto out; KKASSERT(ffep->fnp == ffnp); if (tvp) { KKASSERT(tfnp); if (ffnp->type == VDIR && tfnp->type == VDIR) { if (!RB_EMPTY(&tfnp->dent_head)) { error = ENOTEMPTY; goto out; } } else if (ffnp->type == VDIR && tfnp->type != VDIR) { error = ENOTDIR; goto out; } else if (ffnp->type != VDIR && tfnp->type == VDIR) { error = EISDIR; goto out; } else KKASSERT(ffnp->type != VDIR && tfnp->type != VDIR); } fip = fuse_ipc_get(fmp, sizeof(*fri) + fncp->nc_nlen + tncp->nc_nlen + 2); /* There is also fuse_rename2_in with flags. */ fri = fuse_ipc_fill(fip, FUSE_RENAME, fdfnp->ino, ap->a_cred); fri->newdir = tdfnp->ino; p = (char*)(fri + 1); memcpy(p, fncp->nc_name, fncp->nc_nlen); p[fncp->nc_nlen] = '\0'; memcpy(p + fncp->nc_nlen + 1, tncp->nc_name, tncp->nc_nlen); p[fncp->nc_nlen + 1 + tncp->nc_nlen] = '\0'; error = fuse_ipc_tx(fip); if (error) goto out; fuse_ipc_put(fip); if (fncp->nc_nlen != tncp->nc_nlen || memcmp(fncp->nc_name, tncp->nc_name, fncp->nc_nlen)) { newname = kmalloc(tncp->nc_nlen + 1, M_TEMP, M_WAITOK | M_ZERO); KKASSERT(newname); memcpy(newname, tncp->nc_name, tncp->nc_nlen); newname[tncp->nc_nlen] = '\0'; fuse_dbg("newname=\"%s\"\n", newname); } else newname = NULL; mtx_lock(&tdfnp->node_lock); mtx_lock(&fdfnp->node_lock); mtx_lock(&ffnp->node_lock); fuse_dbg("detach from_dent=\"%s\"\n", ffep->name); fuse_dent_detach(fdfnp, ffep); if (newname) { oldname = ffep->name; ffep->name = newname; newname = oldname; } if (tvp) { mtx_lock(&tfnp->node_lock); error = fuse_dent_find(tdfnp, tncp->nc_name, tncp->nc_nlen, &tfep); KKASSERT(!error); fuse_dbg("detach/free to_dent=\"%s\"\n", tfep->name); fuse_dent_detach(tdfnp, tfep); fuse_dent_free(tfep); mtx_unlock(&tfnp->node_lock); fuse_knote(tdvp, NOTE_DELETE); } fuse_dbg("attach from_dent=\"%s\"\n", ffep->name); fuse_dent_attach(tdfnp, ffep); mtx_unlock(&ffnp->node_lock); mtx_unlock(&fdfnp->node_lock); mtx_unlock(&tdfnp->node_lock); if (newname) kfree(newname, M_TEMP); cache_rename(ap->a_fnch, ap->a_tnch); fuse_knote(fdvp, NOTE_WRITE); fuse_knote(tdvp, NOTE_WRITE); fuse_knote(fvp, NOTE_RENAME); out: if (tvp) vrele(tvp); return error; } static int fuse_vop_nsymlink(struct vop_nsymlink_args *ap) { struct vnode *dvp = ap->a_dvp; struct vnode *vp; struct namecache *ncp = ap->a_nch->ncp; struct fuse_mount *fmp = VFSTOFUSE(dvp->v_mount); struct fuse_node *dfnp = VTOI(dvp); struct fuse_node *fnp; struct fuse_ipc *fip; struct fuse_entry_out *feo; char *p; int error; if (fuse_test_dead(fmp)) return ENOTCONN; if (fuse_test_nosys(fmp, FUSE_SYMLINK)) return EOPNOTSUPP; fip = fuse_ipc_get(fmp, strlen(ap->a_target) + 1 + ncp->nc_nlen + 1); p = fuse_ipc_fill(fip, FUSE_SYMLINK, dfnp->ino, ap->a_cred); memcpy(p, ncp->nc_name, ncp->nc_nlen); p[ncp->nc_nlen] = '\0'; memcpy(p + ncp->nc_nlen + 1, ap->a_target, strlen(ap->a_target) + 1); error = fuse_ipc_tx(fip); if (error) return error; feo = fuse_out_data(fip); if (IFTOVT(feo->attr.mode) != VLNK) { fuse_ipc_put(fip); return EINVAL; } error = fuse_alloc_node(dfnp, feo->nodeid, p, strlen(p), VLNK, &vp); if (error) { fuse_ipc_put(fip); return error; } KKASSERT(vp); KKASSERT(vn_islocked(vp)); fnp = VTOI(vp); mtx_lock(&fnp->node_lock); fuse_set_attr(fnp, &feo->attr); mtx_unlock(&fnp->node_lock); cache_setunresolved(ap->a_nch); cache_setvp(ap->a_nch, vp); *(ap->a_vpp) = vp; fuse_knote(vp, NOTE_WRITE); /* unused */ //feo->generation; //feo->entry_valid; //feo->attr_valid; //feo->entry_valid_nsec; //feo->attr_valid_nsec; fuse_ipc_put(fip); return 0; } static int fuse_vop_read(struct vop_read_args *ap) { struct vnode *vp = ap->a_vp; struct uio *uio = ap->a_uio; struct fuse_mount *fmp = VFSTOFUSE(vp->v_mount); fuse_dbg("ino=%ju ioflag=%x\n", VTOI(vp)->ino, ap->a_ioflag); if (fuse_test_dead(fmp)) return ENOTCONN; if (fuse_test_nosys(fmp, FUSE_READ)) return EOPNOTSUPP; if (!uio->uio_resid) return 0; return fuse_read(ap); } static int fuse_vop_write(struct vop_write_args *ap) { struct vnode *vp = ap->a_vp; struct uio *uio = ap->a_uio; struct fuse_mount *fmp = VFSTOFUSE(vp->v_mount); fuse_dbg("ino=%ju ioflag=%x\n", VTOI(vp)->ino, ap->a_ioflag); return EOPNOTSUPP; /* XXX disabled */ if (fuse_test_dead(fmp)) return ENOTCONN; if (fuse_test_nosys(fmp, FUSE_WRITE)) return EOPNOTSUPP; if (!uio->uio_resid) return 0; if (ap->a_ioflag & IO_DIRECT) return fuse_dio_write(ap); else return fuse_write(ap); } static int fuse_vop_strategy(struct vop_strategy_args *ap) { struct bio *bio = ap->a_bio; struct buf *bp = bio->bio_buf; fuse_dbg("ino=%ju b_cmd=%d\n", VTOI(ap->a_vp)->ino, bp->b_cmd); bp->b_resid = 0; bp->b_error = 0; biodone(bio); return 0; } static int fuse_bmap(struct vop_bmap_args *ap) { fuse_dbg("ino=%ju a_cmd=%d a_loffset=%ju\n", VTOI(ap->a_vp)->ino, ap->a_cmd, ap->a_loffset); return EOPNOTSUPP; } static int fuse_vop_print(struct vop_print_args *ap) { struct fuse_node *fnp = VTOI(ap->a_vp); fuse_print("tag VT_FUSE, node %p, ino %ju, parent ino %ju\n", fnp, VTOI(ap->a_vp)->ino, VTOI(fnp->pfnp->vp)->ino); return 0; } static int fuse_vop_inactive(struct vop_inactive_args *ap) { struct vnode *vp = ap->a_vp; struct mount *mp = vp->v_mount; struct fuse_node *fnp = VTOI(vp); lwkt_gettoken(&mp->mnt_token); if (!fnp) { vrecycle(ap->a_vp); lwkt_reltoken(&mp->mnt_token); return 0; } fuse_dbg("ino=%ju nlink=%d\n", fnp->ino, fnp->nlink); vinvalbuf(vp, V_SAVE, 0, 0); lwkt_reltoken(&mp->mnt_token); return 0; } static int fuse_vop_reclaim(struct vop_reclaim_args *ap) { struct vnode *vp = ap->a_vp; struct mount *mp = vp->v_mount; struct fuse_node *fnp = VTOI(vp); lwkt_gettoken(&mp->mnt_token); if (fnp) { fuse_dbg("ino=%ju\n", fnp->ino); fuse_node_free(fnp); vclrisdirty(vp); } lwkt_reltoken(&mp->mnt_token); return 0; } static int fuse_vop_mountctl(struct vop_mountctl_args *ap) { struct mount *mp; int res = 0; mp = ap->a_head.a_ops->head.vv_mount; lwkt_gettoken(&mp->mnt_token); switch (ap->a_op) { //case MOUNTCTL_MOUNTFLAGS: // ... // break; default: res = vop_stdmountctl(ap); break; } lwkt_reltoken(&mp->mnt_token); return res; } static void filt_fusedetach(struct knote*); static int filt_fuseread(struct knote*, long); static int filt_fusewrite(struct knote*, long); static int filt_fusevnode(struct knote*, long); static struct filterops fuseread_filtops = { FILTEROP_ISFD | FILTEROP_MPSAFE, NULL, filt_fusedetach, filt_fuseread }; static struct filterops fusewrite_filtops = { FILTEROP_ISFD | FILTEROP_MPSAFE, NULL, filt_fusedetach, filt_fusewrite }; static struct filterops fusevnode_filtops = { FILTEROP_ISFD | FILTEROP_MPSAFE, NULL, filt_fusedetach, filt_fusevnode }; static int fuse_kqfilter(struct vop_kqfilter_args *ap) { struct vnode *vp = ap->a_vp; struct knote *kn = ap->a_kn; switch (kn->kn_filter) { case EVFILT_READ: kn->kn_fop = &fuseread_filtops; break; case EVFILT_WRITE: kn->kn_fop = &fusewrite_filtops; break; case EVFILT_VNODE: kn->kn_fop = &fusevnode_filtops; break; default: return EOPNOTSUPP; } kn->kn_hook = (caddr_t)vp; knote_insert(&vp->v_pollinfo.vpi_kqinfo.ki_note, kn); return 0; } static void filt_fusedetach(struct knote *kn) { struct vnode *vp = (void*)kn->kn_hook; knote_remove(&vp->v_pollinfo.vpi_kqinfo.ki_note, kn); } static int filt_fuseread(struct knote *kn, long hint) { struct vnode *vp = (void*)kn->kn_hook; struct fuse_node *fnp = VTOI(vp); off_t off; if (hint == NOTE_REVOKE) { kn->kn_flags |= (EV_EOF | EV_NODATA | EV_ONESHOT); return 1; } /* * Interlock against MP races when performing this function. */ mtx_lock(&fnp->node_lock); off = fnp->size - kn->kn_fp->f_offset; kn->kn_data = (off < INTPTR_MAX) ? off : INTPTR_MAX; if (kn->kn_sfflags & NOTE_OLDAPI) { mtx_unlock(&fnp->node_lock); return 1; } if (!kn->kn_data) kn->kn_data = (off < INTPTR_MAX) ? off : INTPTR_MAX; mtx_unlock(&fnp->node_lock); return kn->kn_data != 0; } static int filt_fusewrite(struct knote *kn, long hint) { if (hint == NOTE_REVOKE) kn->kn_flags |= (EV_EOF | EV_NODATA | EV_ONESHOT); kn->kn_data = 0; return 1; } static int filt_fusevnode(struct knote *kn, long hint) { if (kn->kn_sfflags & hint) kn->kn_fflags |= hint; if (hint == NOTE_REVOKE) { kn->kn_flags |= (EV_EOF | EV_NODATA); return 1; } return kn->kn_fflags != 0; } static int fuse_vop_getpages(struct vop_getpages_args *ap) { if (!ap->a_vp->v_mount) return VM_PAGER_BAD; return vnode_pager_generic_getpages(ap->a_vp, ap->a_m, ap->a_count, ap->a_reqpage, ap->a_seqaccess); } static int fuse_vop_putpages(struct vop_putpages_args *ap) { if (!ap->a_vp->v_mount) return VM_PAGER_BAD; return vnode_pager_generic_putpages(ap->a_vp, ap->a_m, ap->a_count, ap->a_sync, ap->a_rtvals); } struct vop_ops fuse_vnode_vops = { .vop_default = vop_defaultop, .vop_access = fuse_vop_access, .vop_open = fuse_vop_open, .vop_close = fuse_vop_close, .vop_fsync = fuse_vop_fsync, .vop_getattr = fuse_vop_getattr, .vop_setattr = fuse_vop_setattr, .vop_nresolve = fuse_vop_nresolve, //.vop_nlookupdotdot = fuse_nlookupdotdot, .vop_nlink = fuse_vop_nlink, .vop_ncreate = fuse_vop_ncreate, .vop_nmknod = fuse_vop_nmknod, .vop_nremove = fuse_vop_nremove, .vop_nmkdir = fuse_vop_nmkdir, .vop_nrmdir = fuse_vop_nrmdir, .vop_pathconf = fuse_vop_pathconf, .vop_readdir = fuse_vop_readdir, .vop_readlink = fuse_vop_readlink, .vop_nrename = fuse_vop_nrename, .vop_nsymlink = fuse_vop_nsymlink, .vop_read = fuse_vop_read, .vop_write = fuse_vop_write, .vop_strategy = fuse_vop_strategy, .vop_bmap = fuse_bmap, //.vop_advlock = fuse_advlock, .vop_print = fuse_vop_print, .vop_inactive = fuse_vop_inactive, .vop_reclaim = fuse_vop_reclaim, .vop_mountctl = fuse_vop_mountctl, .vop_kqfilter = fuse_kqfilter, .vop_getpages = fuse_vop_getpages, .vop_putpages = fuse_vop_putpages, }; struct vop_ops fuse_spec_vops = { .vop_default = vop_defaultop, .vop_access = fuse_vop_access, .vop_close = fuse_vop_close, .vop_fsync = fuse_vop_fsync, .vop_getattr = fuse_vop_getattr, .vop_setattr = fuse_vop_setattr, .vop_read = vop_stdnoread, .vop_write = vop_stdnowrite, //.vop_markatime = fuse_vop_markatime, .vop_print = fuse_vop_print, .vop_inactive = fuse_vop_inactive, .vop_reclaim = fuse_vop_reclaim, };
22.220535
77
0.676828
c5ee9835e90790aeef58d57b6da7237fa26fbab6
2,065
h
C
chromeos/components/sync_wifi/fake_local_network_collector.h
iridium-browser/iridium-browser
907e31cf5ce5ad14d832796e3a7c11e496828959
[ "BSD-3-Clause-No-Nuclear-License-2014", "BSD-3-Clause" ]
575
2015-06-18T23:58:20.000Z
2022-03-23T09:32:39.000Z
chromeos/components/sync_wifi/fake_local_network_collector.h
iridium-browser/iridium-browser
907e31cf5ce5ad14d832796e3a7c11e496828959
[ "BSD-3-Clause-No-Nuclear-License-2014", "BSD-3-Clause" ]
113
2015-05-04T09:58:14.000Z
2022-01-31T19:35:03.000Z
chromeos/components/sync_wifi/fake_local_network_collector.h
iridium-browser/iridium-browser
907e31cf5ce5ad14d832796e3a7c11e496828959
[ "BSD-3-Clause-No-Nuclear-License-2014", "BSD-3-Clause" ]
52
2015-07-14T10:40:50.000Z
2022-03-15T01:11:49.000Z
// Copyright 2019 The Chromium 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 CHROMEOS_COMPONENTS_SYNC_WIFI_FAKE_LOCAL_NETWORK_COLLECTOR_H_ #define CHROMEOS_COMPONENTS_SYNC_WIFI_FAKE_LOCAL_NETWORK_COLLECTOR_H_ #include <map> #include "base/containers/flat_map.h" #include "base/optional.h" #include "chromeos/components/sync_wifi/local_network_collector.h" #include "chromeos/components/sync_wifi/network_identifier.h" namespace chromeos { namespace sync_wifi { // Test implementation of LocalNetworkCollector. class FakeLocalNetworkCollector : public LocalNetworkCollector { public: FakeLocalNetworkCollector(); ~FakeLocalNetworkCollector() override; // sync_wifi::LocalNetworkCollector:: void GetAllSyncableNetworks(ProtoListCallback callback) override; // For test purposes, |guid| == serialized NetworkIdentifier. void GetSyncableNetwork(const std::string& guid, ProtoCallback callback) override; void RecordZeroNetworksEligibleForSync() override {} // For test purposes, |guid| == serialized NetworkIdentifier. base::Optional<NetworkIdentifier> GetNetworkIdentifierFromGuid( const std::string& guid) override; void AddNetwork(sync_pb::WifiConfigurationSpecifics proto); void ClearNetworks(); void SetNetworkMetadataStore( base::WeakPtr<NetworkMetadataStore> network_metadata_store) override; void FixAutoconnect(std::vector<sync_pb::WifiConfigurationSpecifics> protos, base::OnceCallback<void()> success_callback) override; void ExecuteAfterNetworksLoaded(base::OnceCallback<void()> callback) override; bool has_fixed_autoconnect() { return has_fixed_autoconnect_; } private: std::vector<sync_pb::WifiConfigurationSpecifics> networks_; bool has_fixed_autoconnect_ = false; DISALLOW_COPY_AND_ASSIGN(FakeLocalNetworkCollector); }; } // namespace sync_wifi } // namespace chromeos #endif // CHROMEOS_COMPONENTS_SYNC_WIFI_FAKE_LOCAL_NETWORK_COLLECTOR_H_
36.22807
80
0.789346
45ea7b9f2c56dc24a11bc2ed036dc66f82ca4a69
3,603
h
C
src/terminal_renderer/DecorationRenderer.h
contour-terminal/contour
21c4dab7f97b41017fb7f57d742defe765157413
[ "Apache-2.0" ]
404
2021-07-01T11:38:20.000Z
2022-03-31T19:16:18.000Z
src/terminal_renderer/DecorationRenderer.h
dankamongmen/contour
21c4dab7f97b41017fb7f57d742defe765157413
[ "Apache-2.0" ]
204
2021-07-01T10:10:01.000Z
2022-03-26T09:46:05.000Z
src/terminal_renderer/DecorationRenderer.h
christianparpart/contour
ce8feb1332c3cc71ca22354b62bcceb2dbb511e4
[ "Apache-2.0" ]
38
2019-09-27T19:53:37.000Z
2021-07-01T09:47:44.000Z
/** * This file is part of the "contour" project. * Copyright (c) 2020 Christian Parpart <christian@parpart.family> * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * * 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. */ #pragma once #include <terminal/RenderBuffer.h> #include <terminal/Screen.h> #include <terminal_renderer/Atlas.h> #include <terminal_renderer/RenderTarget.h> namespace terminal::renderer { struct GridMetrics; /// Dectorator, to decorate a grid cell, eventually containing a character /// /// It should be possible to render multiple decoration onto the same coordinates. enum class Decorator { /// Draws an underline Underline, /// Draws a doubly underline DoubleUnderline, /// Draws a curly underline CurlyUnderline, /// Draws a dotted underline DottedUnderline, /// Draws a dashed underline DashedUnderline, /// Draws an overline Overline, /// Draws a strike-through line CrossedOut, /// Draws a box around the glyph, this is literally the bounding box of a grid cell. /// This could be used for debugging. /// TODO: That should span the box around the whole (potentially wide) character Framed, /// Puts a circle-shape around into the cell (and ideally around the glyph) /// TODO: How'd that look like with double-width characters? Encircle, }; std::optional<Decorator> to_decorator(std::string const& _value); /// Renders any kind of grid cell decorations, ranging from basic underline to surrounding boxes. class DecorationRenderer: public Renderable { public: /// Constructs the decoration renderer. /// /// @param _commandListener /// @param _monochromeTextureAtlas /// @param _gridMetrics DecorationRenderer(GridMetrics const& _gridMetrics, Decorator _hyperlinkNormal, Decorator _hyperlinkHover); void setRenderTarget(RenderTarget& _renderTarget) override; void clearCache() override; void setHyperlinkDecoration(Decorator _normal, Decorator _hover) { hyperlinkNormal_ = _normal; hyperlinkHover_ = _hover; } void renderCell(RenderCell const& _cell); void renderDecoration(Decorator _decoration, crispy::Point _pos, int _columnCount, RGBColor const& _color); constexpr Decorator hyperlinkNormal() const noexcept { return hyperlinkNormal_; } constexpr Decorator hyperlinkHover() const noexcept { return hyperlinkHover_; } constexpr int underlineThickness() const noexcept { return gridMetrics_.underline.thickness; } constexpr int underlinePosition() const noexcept { return gridMetrics_.underline.position; } private: using Atlas = atlas::MetadataTextureAtlas<Decorator, int>; // contains various glyph decorators using DataRef = Atlas::DataRef; void rebuild(); std::optional<DataRef> getDataRef(Decorator _decorator); // private data members // GridMetrics const& gridMetrics_; Decorator hyperlinkNormal_ = Decorator::DottedUnderline; Decorator hyperlinkHover_ = Decorator::Underline; std::unique_ptr<Atlas> atlas_; }; } // namespace terminal::renderer
32.459459
99
0.706911
3431936244e4dbb1b680032492f1efea44cdeac5
470
c
C
1.c
dtroshynski76/Project_Euler
70d05b32f6058b503bff797950d6f78d3a15e0f1
[ "MIT" ]
null
null
null
1.c
dtroshynski76/Project_Euler
70d05b32f6058b503bff797950d6f78d3a15e0f1
[ "MIT" ]
null
null
null
1.c
dtroshynski76/Project_Euler
70d05b32f6058b503bff797950d6f78d3a15e0f1
[ "MIT" ]
null
null
null
/* If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000. */ #include <stdio.h> #include <locale.h> int main(void) { unsigned int sum = 0; for(int i = 0; i < 1000; i++) { if(i % 3 == 0 || i % 5 == 0) { sum += i; } } setlocale(LC_NUMERIC, ""); printf("sum: %'d\n", sum); return 0; }
20.434783
129
0.544681
a2feab4c57a305d24f4714daf068349193a74bad
855
c
C
lib/wizards/nalle/jerusalem/jewa2.c
vlehtola/questmud
8bc3099b5ad00a9e0261faeb6637c76b521b6dbe
[ "MIT" ]
null
null
null
lib/wizards/nalle/jerusalem/jewa2.c
vlehtola/questmud
8bc3099b5ad00a9e0261faeb6637c76b521b6dbe
[ "MIT" ]
null
null
null
lib/wizards/nalle/jerusalem/jewa2.c
vlehtola/questmud
8bc3099b5ad00a9e0261faeb6637c76b521b6dbe
[ "MIT" ]
null
null
null
inherit "room/room"; object monster; reset(arg) { if(!monster) { monster = clone_object("/wizards/nalle/jerusalem/monsters/salesman"); move_object(monster, this_object()); } if(arg) return; add_exit("north","wizards/nalle/jerusalem/jewb2"); add_exit("east","wizards/nalle/jerusalem/jewa3"); add_exit("west","wizards/nalle/jerusalem/jewa1"); short_desc = "Southern part of the Jewish Quarter"; long_desc = "The southern part of the Jewish quarter is quite quiet.\n" + "There are only a few small houses here, and the only reason\n" + "for which people seem to come here for is to see the great\n" + "rock wall, which is of great religious significance to them.\n"; } init() { ::init(); add_action("map", "map"); } map(arg) { if (arg) { return 0; } cat("/wizards/nalle/jerusalem/jmap"); return 1; }
24.428571
73
0.670175
968cd1bee8b42b82b0a456c3314c91fc525ee5b5
298
h
C
ios/XTSample/FooClass.h
yyued/XT
27f6b6da501944997af5d87d6ac08067dcf8c3e6
[ "MIT" ]
3
2018-01-15T05:34:59.000Z
2018-01-24T03:20:47.000Z
ios/XTSample/FooClass.h
yyued/XT
27f6b6da501944997af5d87d6ac08067dcf8c3e6
[ "MIT" ]
null
null
null
ios/XTSample/FooClass.h
yyued/XT
27f6b6da501944997af5d87d6ac08067dcf8c3e6
[ "MIT" ]
null
null
null
// // FooClass.h // XTSample // // Created by 崔明辉 on 2018/1/26. // Copyright © 2018年 UED Center, YY Inc. All rights reserved. // #import <Foundation/Foundation.h> #import "XTExtObject.h" @interface FooClass : XTExtObjectImplementation @property (nonatomic, strong) NSString *fooValue; @end
17.529412
62
0.711409
cab908078b22fad96f8424233b2d24c460e297fa
3,797
h
C
engine/stl/Containers/Tuple.h
azhirnov/AE
31a42b9bf3bdd86304d565d66e4710e7d89d7392
[ "MIT" ]
2
2019-11-14T17:55:26.000Z
2022-01-12T09:38:29.000Z
engine/stl/Containers/Tuple.h
azhirnov/AE
31a42b9bf3bdd86304d565d66e4710e7d89d7392
[ "MIT" ]
null
null
null
engine/stl/Containers/Tuple.h
azhirnov/AE
31a42b9bf3bdd86304d565d66e4710e7d89d7392
[ "MIT" ]
1
2020-04-11T16:04:31.000Z
2020-04-11T16:04:31.000Z
// Copyright (c) 2018-2020, Zhirnov Andrey. For more information see 'LICENSE' #pragma once #include <tuple> #include "stl/CompileTime/TemplateUtils.h" namespace AE::STL { // // Tuple // template <typename ...Types> struct Tuple final : std::tuple< Types... > { // types using Self = Tuple< Types... >; using Base_t = std::tuple< Types... >; // methods constexpr Tuple () = default; constexpr Tuple (const Self &) = default; constexpr Tuple (Self &&) = default; constexpr Self& operator = (const Self &) = default; constexpr Self& operator = (Self &&) = default; template <typename ...UTypes> constexpr explicit Tuple (UTypes&& ...args) : Base_t{ std::forward<UTypes>(args)... } {} template <typename ...UTypes> constexpr Tuple (const Tuple<UTypes...> &other) : Base_t{ other.AsBase() } {} template <typename ...UTypes> constexpr Tuple (Tuple<UTypes...>&& other) : Base_t{ std::move(other).AsBase() } {} ND_ constexpr bool operator == (const Self &rhs) const { return Base_t::operator == ( rhs ); } ND_ constexpr bool operator != (const Self &rhs) const { return Base_t::operator != ( rhs ); } ND_ constexpr bool operator > (const Self &rhs) const { return Base_t::operator > ( rhs ); } ND_ constexpr bool operator < (const Self &rhs) const { return Base_t::operator < ( rhs ); } ND_ constexpr bool operator >= (const Self &rhs) const { return Base_t::operator >= ( rhs ); } ND_ constexpr bool operator <= (const Self &rhs) const { return Base_t::operator <= ( rhs ); } template <typename T> ND_ constexpr T& Get () & { return std::get<T>( *this ); } template <typename T> ND_ constexpr T const& Get () const& { return std::get<T>( *this ); } template <typename T> ND_ constexpr T && Get () && { return std::get<T>( std::move(*this) ); } template <size_t I> ND_ constexpr decltype(auto) Get () & { return std::get<I>( *this ); } template <size_t I> ND_ constexpr decltype(auto) Get () const& { return std::get<I>( *this ); } template <size_t I> ND_ constexpr decltype(auto) Get () && { return std::get<I>( std::move(*this) ); } ND_ constexpr size_t Count () const { return sizeof... (Types); } ND_ constexpr Base_t & AsBase () & { return static_cast<Base_t &>(*this); } ND_ constexpr Base_t && AsBase () && { return static_cast<Base_t &&>( std::move(*this) ); } template <typename Fn> constexpr decltype(auto) Apply (Fn &&fn) { return std::apply( std::forward<Fn>(fn), static_cast<Base_t &>(*this) ); } template <typename Fn> constexpr decltype(auto) Apply (Fn &&fn) const { return std::apply( std::forward<Fn>(fn), static_cast<const Base_t &>(*this) ); } }; template <typename ...Types> Tuple (Types...) -> Tuple< Types... >; template <typename T1, typename T2> Tuple (std::pair<T1, T2>) -> Tuple<T1, T2>; /* ================================================= MakeTuple ================================================= */ template <typename ...Types> ND_ forceinline constexpr auto MakeTuple (Types&& ...args) { using Result_t = Tuple< Unreference< std::decay_t< Types >>... >; return Result_t{ std::forward<Types>(args)... }; } } // AE::STL namespace std { template <typename ...Types> struct tuple_size< AE::STL::Tuple<Types...> > : public std::integral_constant< std::size_t, sizeof...(Types) > {}; template< size_t I, typename ...Types > struct tuple_element< I, AE::STL::Tuple<Types...> > { using type = typename tuple_element< I, std::tuple<Types...> >::type; }; template <typename ...Types> inline void swap (AE::STL::Tuple<Types...> &lhs, AE::STL::Tuple<Types...> &rhs) noexcept { return swap( static_cast<tuple< Types... > &>(lhs), static_cast<tuple< Types... > &>(rhs) ); } } // std
30.376
97
0.612326
e7c9ecbf4be0aca819aa3e14e545e231969c1aae
4,047
h
C
src/include/optimizer/newPlanner.h
apache/incubator-hawq
1d0859d744a289da1c77b9f7242306e380754663
[ "Apache-2.0" ]
450
2015-09-05T09:12:51.000Z
2018-08-30T01:45:36.000Z
src/include/optimizer/newPlanner.h
apache/incubator-hawq
1d0859d744a289da1c77b9f7242306e380754663
[ "Apache-2.0" ]
1,274
2015-09-22T20:06:16.000Z
2018-08-31T22:14:00.000Z
src/include/optimizer/newPlanner.h
apache/incubator-hawq
1d0859d744a289da1c77b9f7242306e380754663
[ "Apache-2.0" ]
278
2015-09-21T19:15:06.000Z
2018-08-31T00:36:51.000Z
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ /*------------------------------------------------------------------------- * * newPlanner.h * convert hawq plan to common plan in google protobuf * *------------------------------------------------------------------------- */ #ifndef SRC_INCLUDE_OPTIMIZER_NEWPLANNER_H_ #define SRC_INCLUDE_OPTIMIZER_NEWPLANNER_H_ #include "postgres.h" #include "nodes/plannodes.h" #include "optimizer/walkers.h" #include "univplan/cwrapper/univplan-c.h" extern const char *new_executor_mode_on; extern const char *new_executor_mode_auto; extern const char *new_executor_mode_off; extern char *new_executor_mode; extern char *new_executor_enable_partitioned_hashagg_mode; extern char *new_executor_enable_partitioned_hashjoin_mode; extern char *new_executor_enable_external_sort_mode; extern int new_executor_partitioned_hash_recursive_depth_limit; extern int new_executor_ic_tcp_client_limit_per_query_per_segment; extern int new_executor_external_sort_memory_limit_size_mb; extern const char *new_executor_runtime_filter_mode; extern const char *new_executor_runtime_filter_mode_local; extern const char *new_executor_runtime_filter_mode_global; extern int new_interconnect_type; extern const char *show_new_interconnect_type(); #define MAGMATYPE "magma" #define ORCTYPE "orc" #define TEXTTYPE "text" #define CSVTYPE "csv" typedef struct CommonPlanContext { plan_tree_base_prefix base; UnivPlanC *univplan; bool convertible; bool querySelect; // flag of query statement bool isMagma; // flag to indicate whether there is a magma table in the plan int magmaRelIndex; PlannedStmt *stmt; bool setDummyTListRef; bool scanReadStatsOnly; Expr *parent; // used for T_Var, T_Const List *exprBufStack; // used for T_Case int rangeNum; // magma range num bool isConvertingIndexQual; // flag to indicate if we are doing indexqual // conversion List *idxColumns; // orc index columns info } CommonPlanContext; extern bool can_convert_common_plan(QueryDesc *queryDesc, CommonPlanContext *ctx); extern void convert_to_common_plan(PlannedStmt *stmt, CommonPlanContext *ctx); extern void convert_rangenum_to_common_plan(PlannedStmt *stmt, CommonPlanContext *ctx); extern void convert_extscan_to_common_plan(Plan *node, List *splits, Relation rel, CommonPlanContext *ctx); extern void *convert_orcscan_qual_to_common_plan(Plan *node, CommonPlanContext *ctx); extern void *convert_orcscan_indexqualorig_to_common_plan( Plan *node, CommonPlanContext *ctx, List *idxColumns); extern void convert_querydesc_to_common_plan(QueryDesc *queryDesc, CommonPlanContext *ctx); extern void planner_init_common_plan_context(PlannedStmt *stmt, CommonPlanContext *ctx); extern void planner_destroy_common_plan_context(CommonPlanContext *ctx, bool enforce); #endif // SRC_INCLUDE_OPTIMIZER_NEWPLANNER_H_
42.15625
79
0.692859
23f5d6e4b331b1de35baa2660d71e6993cf4f16c
341
h
C
app_dumps/VKClient.folder/SketchControllerDelegate.h
turlodales/theos-projects
64d0df7c3aea5907b50886fae9a6d8df76732103
[ "MIT" ]
23
2017-09-05T17:47:09.000Z
2021-11-08T10:46:47.000Z
app_dumps/VKClient.folder/SketchControllerDelegate.h
turlodales/theos-projects
64d0df7c3aea5907b50886fae9a6d8df76732103
[ "MIT" ]
5
2017-06-08T08:06:42.000Z
2022-01-22T04:13:07.000Z
app_dumps/VKClient.folder/SketchControllerDelegate.h
turlodales/theos-projects
64d0df7c3aea5907b50886fae9a6d8df76732103
[ "MIT" ]
12
2017-09-18T08:50:44.000Z
2022-03-09T08:52:30.000Z
/** * This header is generated by class-dump-z 0.2-0. * class-dump-z is Copyright (C) 2009 by KennyTM~, licensed under GPLv3. * * Source: (null) */ #import "NSObject.h" @protocol SketchControllerDelegate <NSObject> -(void)cancelSketchController:(id)controller; -(void)sketchController:(id)controller imageReadyToSend:(id)send; @end
21.3125
72
0.730205
635a7b868008f07dd922172dc6001f76392acfc2
5,798
h
C
keystate.h
chrisandreae/keyboard-firmware
91e71bf6e46b9d0ef4880c023afcd32131c49ff4
[ "Ruby" ]
111
2015-01-06T21:14:49.000Z
2022-02-06T14:29:27.000Z
keystate.h
chrisandreae/keyboard-firmware
91e71bf6e46b9d0ef4880c023afcd32131c49ff4
[ "Ruby" ]
18
2015-01-31T15:16:54.000Z
2022-02-26T10:18:39.000Z
keystate.h
chrisandreae/keyboard-firmware
91e71bf6e46b9d0ef4880c023afcd32131c49ff4
[ "Ruby" ]
22
2015-05-13T00:29:46.000Z
2019-03-09T10:07:38.000Z
/* Kinesis ergonomic keyboard firmware replacement Copyright 2012 Chris Andreae (chris (at) andreae.gen.nz) Licensed under the GNU GPL v2 (see GPL2.txt). See Kinesis.h for keyboard hardware documentation. ========================== If built for V-USB, this program includes library and sample code from: V-USB, (C) Objective Development Software GmbH Licensed under the GNU GPL v2 (see GPL2.txt) ========================== If built for LUFA, this program includes library and sample code from: LUFA Library Copyright (C) Dean Camera, 2011. dean [at] fourwalledcubicle [dot] com www.lufa-lib.org Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com) Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies and that both that the copyright notice and this permission notice and warranty disclaimer appear in supporting documentation, and that the name of the author not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. The author disclaim all warranties with regard to this software, including all implied warranties of merchantability and fitness. In no event shall the author be liable for any special, indirect or consequential damages or any damages whatsoever resulting from loss of use, data or profits, whether in an action of contract, negligence or other tortious action, arising out of or in connection with the use or performance of this software. */ #ifndef __KEYSTATE_H #define __KEYSTATE_H #include "Keyboard.h" // types // Keycodes go through three transformations. // A raw keyboard matrix code maps to a index in the (keyboard specific) logical key positions table. // We then look up a HID keycode for this position using the key_defaults/key_config tables. typedef uint8_t keycode; typedef keycode logical_keycode; typedef keycode hid_keycode; typedef struct _key_state { logical_keycode l_key; unsigned char state:1; unsigned char debounce:7; // bit vector of last n physical reports: debounced state asserted when they're all the same } key_state; // constants #define KEYSTATE_COUNT 14 // maximum keys we track at once #define DEBOUNCE_MASK 0x07 // care about last 3 physical reports #define NO_KEY 0xFF /* Logical keys are mapped to HID codes. We want to be able to assign some extra actions that don't correspond to valid HID codes, so we assign some extra codes for our use at the end of the HID range, after E7, the last HID key. As these aren't valid keycodes, they'll never be sent via USB. */ #define SPECIAL_HID_KEYS_START 0xE8 enum SPECIAL_HID_KEYS { SPECIAL_HID_KEY_MOUSE_BTN1 = SPECIAL_HID_KEYS_START, SPECIAL_HID_KEY_MOUSE_BTN2, SPECIAL_HID_KEY_MOUSE_BTN3, SPECIAL_HID_KEY_MOUSE_BTN4, SPECIAL_HID_KEY_MOUSE_BTN5, SPECIAL_HID_KEY_MOUSE_FWD, SPECIAL_HID_KEY_MOUSE_BACK, SPECIAL_HID_KEY_MOUSE_LEFT, SPECIAL_HID_KEY_MOUSE_RIGHT, // And the special non-remappable program and keypad keys SPECIAL_HID_KEY_KEYPAD_SHIFT = 0xFC, SPECIAL_HID_KEY_KEYPAD_TOGGLE, SPECIAL_HID_KEY_PROGRAM = 0xFE // Must be last: we rely on sort order }; #define SPECIAL_HID_KEYS_MOUSE_START SPECIAL_HID_KEY_MOUSE_BTN1 #define SPECIAL_HID_KEYS_MOUSE_END SPECIAL_HID_KEY_MOUSE_RIGHT // Program and keypad keys are special: they don't participate in the keypad // layer and can't be remapped using onboard remapping. // We put these at the end after PROGRAM. #define SPECIAL_HID_KEY_NOREMAP(hkey) (hkey >= SPECIAL_HID_KEY_KEYPAD_SHIFT && hkey != NO_KEY) // fields extern uint8_t key_press_count; void keystate_init(void); void keystate_update(void); bool keystate_is_keypad_mode(void); /** * Types of keycode: * LOGICAL: `logical_keycode` corresponding to a given key * PHYSICAL: `logical_keycode` in the base keypad layer at the position matching a given key. * HID: `hid_keycode` in the current mapping for a given key */ typedef enum _keycode_type { PHYSICAL, LOGICAL, HID } keycode_type; /** Checks if the argument key is down. */ bool keystate_check_key(keycode l_key, keycode_type ktype); /** returns true if all argument keys are down */ bool keystate_check_keys(uint8_t count, keycode_type ktype, ...); /** returns true if any argument keys are down */ bool keystate_check_any_key(uint8_t count, keycode_type ktype, ...); /** writes up to key_press_count currently pressed key indexes to the * output buffer keys. */ void keystate_get_keys(keycode* keys, keycode_type ktype); void keystate_Fill_KeyboardReport(KeyboardReport_Data_t* KeyboardReport); void keystate_Fill_MouseReport(MouseReport_Data_t* MouseReport); /** * Checks whether a key mapped to the argument keycode (or any key if * argument 0) is pressed, returns keycode of first pressed key or * NO_KEY. */ hid_keycode keystate_check_hid_key(hid_keycode key); /** * Writes up to key_press_count currently pressed HID keycodes to the * output buffer keys. If exclude_special is set, do not write any * special keycodes. Returns number of keycodes written. */ int keystate_get_hid_keys(hid_keycode* h_keys, bool exclude_special); /** * Check for keys bound to programs, if found call vm_start */ void keystate_run_programs(void); /** * A keystate change hook function is invoked whenever the logical key * state is changed, passing the logical keycode and the type of event. */ typedef void (*keystate_change_hook)(logical_keycode key, bool press); /** * Sets the given function as the keystate change hook function. Set * null to unregister. */ void keystate_register_change_hook(keystate_change_hook hook); #endif // __KEYSTATE_H
33.709302
119
0.771473
6faadad7d0436f282725c7cd3f6567b87bd19a5a
1,078
h
C
tests/testAutopas/tests/containers/verletListsCellBased/verletListsCells/PairwiseVerletListsTest.h
neftlon/AutoPas
62866238968a5db9e7bd1f884b7571d5d5ad2370
[ "BSD-2-Clause" ]
null
null
null
tests/testAutopas/tests/containers/verletListsCellBased/verletListsCells/PairwiseVerletListsTest.h
neftlon/AutoPas
62866238968a5db9e7bd1f884b7571d5d5ad2370
[ "BSD-2-Clause" ]
null
null
null
tests/testAutopas/tests/containers/verletListsCellBased/verletListsCells/PairwiseVerletListsTest.h
neftlon/AutoPas
62866238968a5db9e7bd1f884b7571d5d5ad2370
[ "BSD-2-Clause" ]
null
null
null
/** * @file PairwiseVerletListsTest.h * @author tirgendetwas * @date 22.11.20 */ #pragma once #include <gtest/gtest.h> #include "AutoPasTestBase.h" #include "autopas/cells/FullParticleCell.h" #include "autopas/particles/Particle.h" #include "autopasTools/generators/RandomGenerator.h" #include "mocks/MockFunctor.h" #include "testingHelpers/commonTypedefs.h" #include "tests/containers/verletListsCellBased/verletLists/VerletListsTest.h" class PairwiseVerletListsTest : public AutoPasTestBase, public ::testing::WithParamInterface<std::pair<double, bool>> { public: struct PrintToStringParamName { template <class ParamType> std::string operator()(const testing::TestParamInfo<ParamType> &info) const { auto pairParams = static_cast<ParamType>(info.param); return "CellSizeFactor_" + std::to_string((int)pairParams.first) + "_useNewton3_" + boolToString(pairParams.second); } std::string boolToString(bool n3) const { if (n3 == true) { return "true"; } else { return "false"; } } }; };
29.135135
119
0.705937
c0ec8a5acb111831f17a3bd830bbc861fc950fcb
366
h
C
FastStub/SuggestionController/FSSuggestionView.h
music4kid/FastStub-Xcode
0e93345a6e5b7e221dd6e5d0b82012992e78727e
[ "MIT" ]
557
2016-05-25T13:27:14.000Z
2021-11-17T11:01:35.000Z
FastStub/SuggestionController/FSSuggestionView.h
music4kid/FastStub-Xcode
0e93345a6e5b7e221dd6e5d0b82012992e78727e
[ "MIT" ]
19
2016-05-26T01:49:46.000Z
2021-05-09T15:11:27.000Z
FastStub/SuggestionController/FSSuggestionView.h
music4kid/FastStub-Xcode
0e93345a6e5b7e221dd6e5d0b82012992e78727e
[ "MIT" ]
64
2016-05-26T11:24:03.000Z
2020-09-11T20:53:51.000Z
// // FSSuggestionView.h // FastStub // // Created by gao feng on 16/5/17. // Copyright © 2016年 music4kid. All rights reserved. // #import <Cocoa/Cocoa.h> @interface FSSuggestionView : NSView @property (nonatomic, strong) IBOutlet NSTableView* tableView; @property (nonatomic, strong) IBOutlet NSTextField* searchField; @end
20.333333
80
0.663934
8d64bae8ceecf72d3cdf2a7868edf4e92d05fa7c
861
h
C
ringsynth/src/mcp4921.h
ArchimedesPi/synths
089f449a0c5d5c82610da47805916096117ec8de
[ "MIT" ]
null
null
null
ringsynth/src/mcp4921.h
ArchimedesPi/synths
089f449a0c5d5c82610da47805916096117ec8de
[ "MIT" ]
null
null
null
ringsynth/src/mcp4921.h
ArchimedesPi/synths
089f449a0c5d5c82610da47805916096117ec8de
[ "MIT" ]
null
null
null
#ifndef __MCP4921_H__ #define __MCP4921_H__ #include <avr/io.h> #include "util.h" #define SLAVE_SELECT clear_bit(PORTB, PB2) #define SLAVE_DESELECT set_bit(PORTB, PB2) inline void spi_init() { DDRB |= _BV(PB1) | _BV(PB2) | _BV(PB3) | _BV(PB5); SPCR = _BV(SPE) | _BV(MSTR); SPSR |= _BV(SPI2X); // 2x SPI speed } inline u8 spi_swap_byte(u8 data) { SPDR = data; loop_until_bit_is_set(SPSR, SPIF); return (SPDR); } /* dacwrite(u16 data) * writes a 12 bit value out to the dac. * note: `data` *is* u16 but gets truncated to 12 bits and loses 4 lsbs of precision. * * speed: * bitbang: 8.8us * hw spi: 4.2us (!!!) */ inline void dac_write(u16 data) { SLAVE_SELECT; data &= 0xfff; // truncate to 12 bits spi_swap_byte(_BV(4) | _BV(5) | (data >> 8)); spi_swap_byte(data & 0x0ff); SLAVE_DESELECT; } #endif
20.5
85
0.639954
a05eb75fb63e32b4d065e58872fc303013e958c4
5,096
h
C
src/shared/secondary/spp_worker_th/data_types.h
Hideyuki-Yamashita/spp_20.02_doc
8a12d73cb8e82c784d61a4ce1628f2bc6b1a09cf
[ "BSD-3-Clause" ]
null
null
null
src/shared/secondary/spp_worker_th/data_types.h
Hideyuki-Yamashita/spp_20.02_doc
8a12d73cb8e82c784d61a4ce1628f2bc6b1a09cf
[ "BSD-3-Clause" ]
null
null
null
src/shared/secondary/spp_worker_th/data_types.h
Hideyuki-Yamashita/spp_20.02_doc
8a12d73cb8e82c784d61a4ce1628f2bc6b1a09cf
[ "BSD-3-Clause" ]
null
null
null
/* SPDX-License-Identifier: BSD-3-Clause * Copyright(c) 2019 Nippon Telegraph and Telephone Corporation */ #ifndef __SPPWK_DATA_TYPES_H__ #define __SPPWK_DATA_TYPES_H__ #include "shared/common.h" #define STR_LEN_SHORT 32 /* Size of short string. */ #define STR_LEN_NAME 128 /* Size of string for names. */ /** Identifier string for each interface */ #define SPPWK_PHY_STR "phy" #define SPPWK_VHOST_STR "vhost" #define SPPWK_RING_STR "ring" /* * Delimiter for phy port supporting multi queue. * Example of phy port supporting multi-queue: `phy: 0nq1`. */ #define DELIM_PHY_MQ "nq" /* TODO(yasufum) confirm usage of this value and why it is 4. */ #define PORT_CAPABL_MAX 4 /* Max num of port abilities. */ #define DEFAULT_QUEUE_ID 0 /* Queue ID is counted up from 0. */ /* Status of a component on lcore. */ enum sppwk_lcore_status { SPPWK_LCORE_UNUSED, SPPWK_LCORE_STOPPED, SPPWK_LCORE_IDLING, SPPWK_LCORE_RUNNING, SPPWK_LCORE_REQ_STOP /**< Request for stopping. */ }; /* Direction of RX or TX on a port. */ enum sppwk_port_dir { SPPWK_PORT_DIR_NONE, /**< None */ SPPWK_PORT_DIR_RX, /**< RX port */ SPPWK_PORT_DIR_TX, /**< TX port */ SPPWK_PORT_DIR_BOTH, /**< Both of RX and TX */ }; /** * Port ability operation which indicates vlan tag operation on the port * (e.g. add vlan tag or delete vlan tag) */ enum sppwk_port_ops { SPPWK_PORT_OPS_NONE, SPPWK_PORT_OPS_ADD_VLAN, /* Add vlan tag. */ SPPWK_PORT_OPS_DEL_VLAN, /* Delete vlan tag. */ }; /** VLAN tag information */ struct sppwk_vlan_tag { int vid; /**< VLAN ID */ int pcp; /**< Priority Code Point */ int tci; /**< Tag Control Information */ }; /* Ability for vlantag for a port. */ union sppwk_port_capability { /** VLAN tag information */ struct sppwk_vlan_tag vlantag; }; /* Port attributes of SPP worker processes. */ struct sppwk_port_attrs { enum sppwk_port_ops ops; /**< Port capability Operations */ enum sppwk_port_dir dir; /**< Direction of RX, TX or both */ union sppwk_port_capability capability; /**< Port capability */ }; /* Type of SPP worker thread. */ /* TODO(yasufum) it should be separated into each process. */ enum sppwk_worker_type { SPPWK_TYPE_NONE, /**< Not used */ SPPWK_TYPE_CLS, /**< Classifier_mac */ SPPWK_TYPE_MRG, /**< Merger */ SPPWK_TYPE_FWD, /**< Forwarder */ SPPWK_TYPE_MIR, /**< Mirror */ }; /* Attributes for classifying. */ struct sppwk_cls_attrs { uint64_t mac_addr; /**< Mac address (binary) */ char mac_addr_str[STR_LEN_SHORT]; /**< Mac address (text) */ struct sppwk_vlan_tag vlantag; /**< VLAN tag information */ }; /** * Simply define type and index of resource UID such as phy:0. For detailed * attributions, use `sppwk_port_info` which has additional port params. */ struct sppwk_port_idx { enum port_type iface_type; /**< phy, vhost or ring. */ int iface_no; int queue_no; }; /* Define detailed port params in addition to `sppwk_port_idx`. */ struct sppwk_port_info { enum port_type iface_type; /**< phy, vhost or ring */ int iface_no; int ethdev_port_id; /**< Consistent ID of ethdev */ int queue_no; struct sppwk_cls_attrs cls_attrs; struct sppwk_port_attrs port_attrs[PORT_CAPABL_MAX]; }; /* Attributes of SPP worker thread named as `component`. */ struct sppwk_comp_info { char name[STR_LEN_NAME]; /**< Component name */ enum sppwk_worker_type wk_type; /**< Type of worker thread */ unsigned int lcore_id; int comp_id; /**< Component ID */ int nof_rx; /**< The number of rx ports */ int nof_tx; /**< The number of tx ports */ /**< rx ports */ struct sppwk_port_info *rx_ports[RTE_MAX_QUEUES_PER_PORT]; /**< tx ports */ struct sppwk_port_info *tx_ports[RTE_MAX_QUEUES_PER_PORT]; }; /* Manage number of interfaces and port information as global variable. */ /** * TODO(yasufum) confirm why having arrays of types. it seems OK having * just one array. * TODO(yasufum) spp_pcap does not support vhost currently, consider support * or not. */ struct iface_info { struct sppwk_port_info phy[RTE_MAX_ETHPORTS][RTE_MAX_QUEUES_PER_PORT]; struct sppwk_port_info vhost[RTE_MAX_ETHPORTS]; struct sppwk_port_info ring[RTE_MAX_ETHPORTS]; }; struct sppwk_lcore_params; /** * Define func to iterate lcore to list core information for showing status * or so, as a member of struct `sppwk_lcore_params`. */ typedef int (*sppwk_lcore_proc)( struct sppwk_lcore_params *params, const unsigned int lcore_id, const char *wk_name, /* Name of worker named as component. */ const char *wk_type, /* Type of worker named as component. */ const int nof_rx, /* Number of RX ports */ const struct sppwk_port_idx *rx_ports, const int nof_tx, /* Number of TX ports */ const struct sppwk_port_idx *tx_ports); /** * iterate core table parameters used to list content of lcore table for. * showing status or so. */ /* TODO(yasufum) refactor name of func and vars, and comments. */ struct sppwk_lcore_params { char *output; /* Buffer used for output */ /** The function for creating core information */ sppwk_lcore_proc lcore_proc; }; #endif /* __SPPWK_DATA_TYPES_H__ */
30.51497
76
0.717229
5b2769c3f5297b8b751cfd7e382aea0eebb90256
1,742
h
C
Source/Applications/ptpd/src/dep/datatypes_dep.h
t-wynants/PTPSync
9f4552849f9e842ee5450766b91d7cb8f84fcef6
[ "MIT" ]
33
2019-11-30T15:10:40.000Z
2022-03-29T05:36:19.000Z
Source/Applications/ptpd/src/dep/datatypes_dep.h
t-wynants/PTPSync
9f4552849f9e842ee5450766b91d7cb8f84fcef6
[ "MIT" ]
2
2021-03-17T13:25:40.000Z
2021-03-19T18:21:02.000Z
Source/Applications/ptpd/src/dep/datatypes_dep.h
t-wynants/PTPSync
9f4552849f9e842ee5450766b91d7cb8f84fcef6
[ "MIT" ]
11
2019-09-08T02:24:30.000Z
2021-06-15T14:38:52.000Z
#ifndef DATATYPES_DEP_H_ #define DATATYPES_DEP_H_ /** *\file * \brief Implementation specific datatype */ typedef enum {FALSE=0, TRUE} Boolean; typedef char Octet; typedef signed char Integer8; typedef signed short Integer16; typedef signed int Integer32; typedef unsigned char UInteger8; typedef unsigned short UInteger16; typedef unsigned int UInteger32; typedef unsigned short Enumeration16; typedef unsigned char Enumeration8; typedef unsigned char Enumeration4; typedef unsigned char UInteger4; typedef unsigned char Nibble; /** * \brief Implementation specific of UInteger48 type */ typedef struct { unsigned int lsb; unsigned short msb; } UInteger48; /** * \brief Implementation specific of Integer64 type */ typedef struct { unsigned int lsb; int msb; } Integer64; /** * \brief Struct used to average the offset from master * * The FIR filtering of the offset from master input is a simple, two-sample average */ typedef struct { Integer32 nsec_prev, y; } offset_from_master_filter; /** * \brief Struct used to average the one way delay * * It is a variable cutoff/delay low-pass, infinite impulse response (IIR) filter. * * The one-way delay filter has the difference equation: s*y[n] - (s-1)*y[n-1] = x[n]/2 + x[n-1]/2, where increasing the stiffness (s) lowers the cutoff and increases the delay. */ typedef struct { Integer32 nsec_prev, y; Integer32 s_exp; } one_way_delay_filter; /** * \brief Struct used to store network datas */ typedef struct { Integer32 eventSock, generalSock, multicastAddr, peerMulticastAddr,unicastAddr; #if defined(__WIN32__) HANDLE eventHEvent; HANDLE generalHEvent; #endif #if defined(TIMESTAMPING_PCAP) pcap_t* eventPcap; #endif } NetPath; #endif /*DATATYPES_DEP_H_*/
23.226667
177
0.759472
3fee05a6b1fcdca3ba5223443e275325f7dd5f41
1,401
c
C
max_min_filt.c
breizhn/matlab-maxfilt-minfilt-in-mex
0d362b38ce23f850e2eb012f27181ef7c3e4341a
[ "BSD-3-Clause" ]
null
null
null
max_min_filt.c
breizhn/matlab-maxfilt-minfilt-in-mex
0d362b38ce23f850e2eb012f27181ef7c3e4341a
[ "BSD-3-Clause" ]
null
null
null
max_min_filt.c
breizhn/matlab-maxfilt-minfilt-in-mex
0d362b38ce23f850e2eb012f27181ef7c3e4341a
[ "BSD-3-Clause" ]
null
null
null
#include "mex.h" void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { double *data = (double*)mxGetData(prhs[0]);; int length_filter = (int)mxGetScalar(prhs[1]); int filter_type = (int)mxGetScalar(prhs[2]); int input_length = (int)mxGetNumberOfElements(prhs[0]); double memory[input_length]; double max = (double)data[0]; int n; int idx; plhs[0] = mxCreateDoubleMatrix(1, input_length, mxREAL); double *output = (double*)mxGetData(plhs[0]); for (n=0; n<length_filter; n++) { memory[n] = data[0]; } for (n=0; n<input_length; n++) { for (idx=0; idx<length_filter; idx++) { if(idx == (length_filter-1)){ memory[idx] = data[n]; } else{ memory[idx] = memory[idx+1]; } } max = memory[0]; for (idx=1; idx<length_filter; idx++) { if(filter_type == 1) // max filter { if(memory[idx] > max) { max = memory[idx]; } } else if(filter_type == 2) // min filter { if(memory[idx] < max) { max = memory[idx]; } } } output[n] = max; } }
26.942308
60
0.442541
e32e5c6e30d170c7c7a50d0da8785d17290221cd
1,124
h
C
PrivateFrameworks/SiriFoundation/SRFVoiceTriggerSuppressor.h
phatblat/macOSPrivateFrameworks
9047371eb80f925642c8a7c4f1e00095aec66044
[ "MIT" ]
17
2018-11-13T04:02:58.000Z
2022-01-20T09:27:13.000Z
PrivateFrameworks/SiriFoundation/SRFVoiceTriggerSuppressor.h
phatblat/macOSPrivateFrameworks
9047371eb80f925642c8a7c4f1e00095aec66044
[ "MIT" ]
3
2018-04-06T02:02:27.000Z
2018-10-02T01:12:10.000Z
PrivateFrameworks/SiriFoundation/SRFVoiceTriggerSuppressor.h
phatblat/macOSPrivateFrameworks
9047371eb80f925642c8a7c4f1e00095aec66044
[ "MIT" ]
1
2018-09-28T13:54:23.000Z
2018-09-28T13:54:23.000Z
// // Generated by class-dump 3.5 (64 bit). // // class-dump is Copyright (C) 1997-1998, 2000-2001, 2004-2013 by Steve Nygard. // #import "NSObject.h" @class NSMutableDictionary, NSMutableSet; @interface SRFVoiceTriggerSuppressor : NSObject { NSMutableDictionary *_voiceTriggerSuppressionsCountTable; NSMutableSet *_voiceTriggerSuppressingProcesses; } @property(retain) NSMutableSet *voiceTriggerSuppressingProcesses; // @synthesize voiceTriggerSuppressingProcesses=_voiceTriggerSuppressingProcesses; @property(retain) NSMutableDictionary *voiceTriggerSuppressionsCountTable; // @synthesize voiceTriggerSuppressionsCountTable=_voiceTriggerSuppressionsCountTable; - (void).cxx_destruct; - (void)observeValueForKeyPath:(id)arg1 ofObject:(id)arg2 change:(id)arg3 context:(void *)arg4; - (void)resetVoiceTriggerSuppression; - (void)verifyVoiceTriggerState; - (void)removeSuppressionsFromProcessWithPID:(id)arg1; - (void)endVoiceTriggerSuppressionActivityWithReason:(id)arg1 forPID:(id)arg2; - (void)beginVoiceTriggerSuppressionActivityWithReason:(id)arg1 forPID:(id)arg2; - (void)dealloc; - (id)init; @end
36.258065
161
0.80427
28f3a77fedae38554bc11c57f30b7cec664d5c21
4,162
h
C
inc/rpcmem.h
khadas/android_external_fastrpc
81249d5007dd3322a287878f64d961b834984f34
[ "BSD-3-Clause" ]
null
null
null
inc/rpcmem.h
khadas/android_external_fastrpc
81249d5007dd3322a287878f64d961b834984f34
[ "BSD-3-Clause" ]
null
null
null
inc/rpcmem.h
khadas/android_external_fastrpc
81249d5007dd3322a287878f64d961b834984f34
[ "BSD-3-Clause" ]
1
2020-10-11T09:45:04.000Z
2020-10-11T09:45:04.000Z
/** * Copyright (c) 2019, The Linux Foundation. All rights reserved. * * 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 of The Linux Foundation 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 "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 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. */ #ifndef RPCMEM_H #define RPCMEM_H #include "AEEStdDef.h" /** * RPCMEM_DEFAULT_HEAP * Dynamicaly select the heap to use. This should be ok for most usecases. */ #define RPCMEM_DEFAULT_HEAP -1 /** * RPCMEM_DEFAULT_FLAGS should allocate memory with the same properties * as the ION_FLAG_CACHED flag */ #ifdef ION_FLAG_CACHED #define RPCMEM_DEFAULT_FLAGS ION_FLAG_CACHED #else #define RPCMEM_DEFAULT_FLAGS 1 #endif /** * RPCMEM_FLAG_UNCACHED * ION_FLAG_CACHED should be defined as 1 */ #define RPCMEM_FLAG_UNCACHED 0 #define RPCMEM_FLAG_CACHED RPCMEM_DEFAULT_FLAGS /** * examples: * * heap 22, uncached, 1kb * rpcmem_alloc(22, 0, 1024); * rpcmem_alloc(22, RPCMEM_FLAG_UNCACHED, 1024); * * heap 21, cached, 2kb * rpcmem_alloc(21, RPCMEM_FLAG_CACHED, 2048); * #include <ion.h> * rpcmem_alloc(21, ION_FLAG_CACHED, 2048); * * just give me the defaults, 2kb * rpcmem_alloc(RPCMEM_DEFAULT_HEAP, RPCMEM_DEFAULT_FLAGS, 2048); * rpcmem_alloc_def(2048); * * give me the default flags, but from heap 18, 4kb * rpcmem_alloc(18, RPCMEM_DEFAULT_FLAGS, 4096); * */ #define ION_SECURE_FLAGS ((1 << 31) | (1 << 19)) #ifdef __cplusplus extern "C" { #endif /** * call once to initialize the library * Note: should not call this if rpcmem is linked from libadsprpc.so * /libcdsprpc.so/libmdsprpc.so/libsdsprpc.so */ void rpcmem_init(void); /** * call once for cleanup * Note: should not call this if rpcmem is linked from libadsprpc.so * /libcdsprpc.so/libmdsprpc.so/libsdsprpc.so */ void rpcmem_deinit(void); /** * Allocate via ION a buffer of size * @heapid, the heap id to use * @flags, ion flags to use to when allocating * @size, the buffer size to allocate * @retval, 0 on failure, pointer to buffer on success * * For example: * buf = rpcmem_alloc(RPCMEM_DEFAULT_HEAP, RPCMEM_DEFAULT_FLAGS, size); */ void* rpcmem_alloc(int heapid, uint32 flags, int size); /** * allocate with default settings */ #if !defined(WINNT) && !defined (_WIN32_WINNT) __attribute__((unused)) #endif static __inline void* rpcmem_alloc_def(int size) { return rpcmem_alloc(RPCMEM_DEFAULT_HEAP, RPCMEM_DEFAULT_FLAGS, size); } /** * free buffer, ignores invalid buffers */ void rpcmem_free(void* po); /** * returns associated fd */ int rpcmem_to_fd(void* po); #ifdef __cplusplus } #endif #define RPCMEM_HEAP_DEFAULT 0x80000000 #define RPCMEM_HEAP_NOREG 0x40000000 #define RPCMEM_HEAP_UNCACHED 0x20000000 #define RPCMEM_HEAP_NOVA 0x10000000 #define RPCMEM_HEAP_NONCOHERENT 0x08000000 #endif //RPCMEM_H
29.51773
75
0.736665
6aba771efe0e907eca16263888eb30db597fbe1b
1,374
h
C
src/objs/SimpleArray.h
nasa-jpl/Cassini_RADAR_Software
93a5be34d013c2913cf74f06e01c59b625bb4a17
[ "Apache-2.0" ]
4
2021-08-12T23:55:41.000Z
2022-02-23T03:32:46.000Z
src/objs/SimpleArray.h
nasa-jpl/Cassini_RADAR_Software
93a5be34d013c2913cf74f06e01c59b625bb4a17
[ "Apache-2.0" ]
null
null
null
src/objs/SimpleArray.h
nasa-jpl/Cassini_RADAR_Software
93a5be34d013c2913cf74f06e01c59b625bb4a17
[ "Apache-2.0" ]
null
null
null
//==============================================================// // Copyright (C) 1997-2002, California Institute of Technology. // // U.S. Government sponsorship acknowledged. // //==============================================================// #ifndef SIMPLE_ARRAY_H #define SIMPLE_ARRAY_H static const char rcs_id_array_h[] = "@(#) $Id: SimpleArray.h,v 11.5 2011/09/16 00:03:30 richw Exp $"; #include <stdarg.h> //====================================================================== // FUNCTIONS // make_array // free_array // write_array // size_array // dim_setup // dim_free // // See Array.C for function descriptions. //====================================================================== void* make_array(int type_size, int ndims, ...); int write_array(FILE* ofp, void* ptr, int type_size, int ndims, ...); int read_array(FILE* ifp, void* ptr, int type_size, int ndims, ...); void free_array(void* ptr, int ndims, ...); void* dim_setup(int level, int ndims, int dimsize[], int type_size); int dim_write(FILE*ofp, void* ptr, int level, int ndims, int dimsize[], int type_size); int dim_read(FILE*ifp, void* ptr, int level, int ndims, int dimsize[], int type_size); void dim_free(void* ptr, int level, int ndims, int dimsize[]); unsigned int size_array(int type_size, int ndims, ...); #endif
37.135135
90
0.533479
5c81500301607783f42c497b676aa80352c83bb5
1,362
h
C
tools/include/votca/tools/linalg.h
ipelupessy/votca
b0daafb6f503e6a55c878172ef9d68c6639da9e0
[ "Apache-2.0" ]
null
null
null
tools/include/votca/tools/linalg.h
ipelupessy/votca
b0daafb6f503e6a55c878172ef9d68c6639da9e0
[ "Apache-2.0" ]
null
null
null
tools/include/votca/tools/linalg.h
ipelupessy/votca
b0daafb6f503e6a55c878172ef9d68c6639da9e0
[ "Apache-2.0" ]
null
null
null
/* * Copyright 2009-2020 The VOTCA Development Team (http://www.votca.org) * * 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. * */ #ifndef VOTCA_TOOLS_LINALG_H #define VOTCA_TOOLS_LINALG_H // Local VOTCA includes #include "eigen.h" #include "eigensystem.h" #include "types.h" namespace votca { namespace tools { /** * \brief solves A*x=b under the constraint B*x = 0 * @return x * @param A matrix for linear equation system * @param b inhomogenity * @param constr constrained condition * * This function implements the qrsolver under constraints */ Eigen::VectorXd linalg_constrained_qrsolve(const Eigen::MatrixXd& A, const Eigen::VectorXd& b, const Eigen::MatrixXd& constr); } // namespace tools } // namespace votca #endif // VOTCA_TOOLS_LINALG_H
29.608696
75
0.692364
55b50ba6a2ad6eae12e836bd7084c0ac86d73381
219
h
C
iOS7CollisionDetectionTutorial/iOS7CollisionDetectionTutorial/myView.h
sachanand/ioscreator
bbe83ccdcd0bc97916e99d80e7cd510689262d25
[ "MIT" ]
4
2019-10-13T17:44:11.000Z
2022-03-21T06:53:12.000Z
iOS7CollisionDetectionTutorial/iOS7CollisionDetectionTutorial/myView.h
vfaHungnv/iOSCreator
79ac7b4cdb7b27d9efe6bf85dada0e0f7a5aca02
[ "MIT" ]
null
null
null
iOS7CollisionDetectionTutorial/iOS7CollisionDetectionTutorial/myView.h
vfaHungnv/iOSCreator
79ac7b4cdb7b27d9efe6bf85dada0e0f7a5aca02
[ "MIT" ]
2
2015-08-29T03:04:56.000Z
2016-06-02T11:54:24.000Z
// // myView.h // iOS7CollisionDetectionTutorial // // Created by Arthur Knopper on 25-01-14. // Copyright (c) 2014 Arthur Knopper. All rights reserved. // #import <UIKit/UIKit.h> @interface myView : UIView @end
15.642857
59
0.694064
590adfa65654435ea7ce98d5752646ec316b3396
1,623
h
C
camera/hal/rockchip/common/3awrapper/Rk3aAiq.h
strassek/chromiumos-platform2
12c953f41f48b8a6b0bd1c181d09bdb1de38325c
[ "BSD-3-Clause" ]
4
2020-07-24T06:54:16.000Z
2021-06-16T17:13:53.000Z
camera/hal/rockchip/common/3awrapper/Rk3aAiq.h
strassek/chromiumos-platform2
12c953f41f48b8a6b0bd1c181d09bdb1de38325c
[ "BSD-3-Clause" ]
1
2021-04-02T17:35:07.000Z
2021-04-02T17:35:07.000Z
camera/hal/rockchip/common/3awrapper/Rk3aAiq.h
strassek/chromiumos-platform2
12c953f41f48b8a6b0bd1c181d09bdb1de38325c
[ "BSD-3-Clause" ]
1
2020-11-04T22:31:45.000Z
2020-11-04T22:31:45.000Z
/* * Copyright (C) 2017 Intel Corporation. * Copyright (c) 2017, Fuzhou Rockchip Electronics Co., Ltd * * 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. */ #ifndef COMMON_3AWRAPPER_RK3AAIQ_H_ #define COMMON_3AWRAPPER_RK3AAIQ_H_ #include <rk_aiq.h> NAMESPACE_DECLARATION { class Rk3aAiq { public: Rk3aAiq(); virtual ~Rk3aAiq(); bool init(const char* xmlFilePath); void deinit(); status_t aeRun(const rk_aiq_ae_input_params* ae_input_params, rk_aiq_ae_results** ae_results); status_t awbRun(const rk_aiq_awb_input_params* awb_input_params, rk_aiq_awb_results** awb_results); status_t miscRun(const rk_aiq_misc_isp_input_params* misc_input_params, rk_aiq_misc_isp_results** misc_results); status_t statisticsSet(const rk_aiq_statistics_input_params* input_params, const rk_aiq_exposure_sensor_descriptor *sensor_desc = nullptr); const char* getVersion(void); bool isInitialized() const; private: rk_aiq* mAiq; }; } NAMESPACE_DECLARATION_END #endif // COMMON_3AWRAPPER_RK3AAIQ_H_
34.531915
91
0.727049
0d8f4dd746971ae097f3749830e92506b8d3d3d6
152
h
C
Wallet/OtherTool/AAChartKitLib/AAChartConfiger/AAChartKit.h
a7510774/wallet_ios
b7c1b654c5ecf1e868fb97f309c5f9190e572b21
[ "MIT" ]
3
2017-11-08T07:30:27.000Z
2018-08-01T09:41:55.000Z
AAChartKitSlim/AAChartConfiger/AAChartKit.h
YueWangChina/AAChartKit
1ef283ae97bf363a428f6c3f9c672407b2b57af1
[ "MIT" ]
1
2017-11-03T10:16:56.000Z
2017-11-03T10:16:56.000Z
AAChartKitSlim/AAChartConfiger/AAChartKit.h
YueWangChina/AAChartKit
1ef283ae97bf363a428f6c3f9c672407b2b57af1
[ "MIT" ]
7
2017-10-27T08:14:03.000Z
2018-06-21T10:01:50.000Z
// // AAChartKit.h // AAChartKit // // Created by An An on 2017/6/20. // Copyright © 2017年 An An. All rights reserved. // #import "AAChartView.h"
13.818182
49
0.631579
1d968869164fc7ad51e7dca5dba07c601d412e07
3,388
h
C
inc/hml/uart.h
MCU-ZHISHAN-IoT/HML_FwLib_8051
5a0263906cf6a4843b69235bca5780736e3a1caf
[ "WTFPL" ]
12
2018-10-21T02:33:43.000Z
2022-02-28T08:33:49.000Z
inc/hml/uart.h
MCU-ZHISHAN-IoT/HML_FwLib_8051
5a0263906cf6a4843b69235bca5780736e3a1caf
[ "WTFPL" ]
1
2020-02-03T10:04:18.000Z
2020-02-03T10:04:18.000Z
inc/hml/uart.h
MCU-ZHISHAN-IoT/HML_FwLib_8051
5a0263906cf6a4843b69235bca5780736e3a1caf
[ "WTFPL" ]
4
2019-03-12T11:42:27.000Z
2022-03-25T00:59:25.000Z
/*****************************************************************************/ /** * \file uart.h * \author Weilun Fong | wlf@zhishan-iot.tk * \brief operation for on-chip UART module * \note * \version v0.3 * \ingroup UART ******************************************************************************/ #ifndef ___HML_UART_H___ #define ___HML_UART_H___ /***************************************************************************** * header file * *****************************************************************************/ #include "hml/tim.h" #ifdef HAVE_TIM2 #include "hml/tim2.h" #endif /***************************************************************************** * macro * *****************************************************************************/ /** * \brief mark bits for bit operation */ #define BIT_NUM_SMOD 7 /***************************************************************************** * array define * *****************************************************************************/ static __code char hexTable[16] = { '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}; /***************************************************************************** * enumeration type * *****************************************************************************/ /** * \brief mark work mode */ typedef enum { UART_mode_0 = 0x0, /* 8-bit shift register */ UART_mode_1 = 0x1, /* 8-bit UART,variable baud rate */ UART_mode_2 = 0x2, /* 9-bit UART,baud rate = fosc/64 or fosc/32 */ UART_mode_3 = 0x3 /* 9-bit UART,variable baud rate */ } UART_mode; /** * \brief mark baud rate generator */ typedef enum { UART_baudGenerator_tim1 = 0x0, UART_baudGenerator_tim2 = 0x1 /* require macro HAVE_TIM2 */ } UART_baudGenerator; /***************************************************************************** * structure define * *****************************************************************************/ /** * \brief structure for configure UART module */ typedef struct { uint32_t baudrate; Action interruptState; Action interruptPriority; UART_mode mode; Action multiBaudrate; Action receiveState; #ifdef HAVE_TIM2 UART_baudGenerator baudGenertor; #endif } UART_configTypeDef; /***************************************************************************** * function declare * *****************************************************************************/ void UART_cmd_multiBaudrate(Action a); void UART_cmd_receive(Action a); void UART_config(UART_configTypeDef *uc); uint16_t UART_getBaudGeneratorInitValue(uint32_t baud, UART_baudGenerator g); byte UART_getByte(void); FunctionalState UART_isReceived(void); FunctionalState UART_isTransmitted(void); void UART_sendByte(byte dat); void UART_sendHex(uint8_t hex); void UART_sendString(char *str); void UART_setMode(UART_mode mode); void UART_INT_cmd(Action a); void UART_INT_setPriority(Action a); #endif
33.544554
101
0.386659
3d39582b2736feeb6c7f91ed0e3d6c2b852c29d8
316
h
C
src/util.h
patton450/ccds
01b7a76668978dc28d8c06c3982d8577aabc2ee6
[ "MIT" ]
null
null
null
src/util.h
patton450/ccds
01b7a76668978dc28d8c06c3982d8577aabc2ee6
[ "MIT" ]
null
null
null
src/util.h
patton450/ccds
01b7a76668978dc28d8c06c3982d8577aabc2ee6
[ "MIT" ]
null
null
null
#ifndef CCDS_UTIL_H #define CCDS_UTIL_H #include "log.h" #define MAX(a, b) ({ \ __typeof__(a) _a = (a); \ __typeof__(b) _b = (b); \ _a > _b ? _a : _b; \ }) #define MIN(a,b) ({ \ __typeof__(a) _a = (a); \ __typeof__(b) _b = (b); \ _a > _b ? _b : _a; \ }) #endif
15.8
30
0.455696
ce4ec114e56d7b54c8e9d2e5ce0934258c7875ed
3,534
h
C
CalibTracker/SiStripAPVAnalysis/interface/ApvAnalysisFactory.h
nistefan/cmssw
ea13af97f7f2117a4f590a5e654e06ecd9825a5b
[ "Apache-2.0" ]
3
2018-08-24T19:10:26.000Z
2019-02-19T11:45:32.000Z
CalibTracker/SiStripAPVAnalysis/interface/ApvAnalysisFactory.h
nistefan/cmssw
ea13af97f7f2117a4f590a5e654e06ecd9825a5b
[ "Apache-2.0" ]
3
2018-08-23T13:40:24.000Z
2019-12-05T21:16:03.000Z
CalibTracker/SiStripAPVAnalysis/interface/ApvAnalysisFactory.h
nistefan/cmssw
ea13af97f7f2117a4f590a5e654e06ecd9825a5b
[ "Apache-2.0" ]
5
2018-08-21T16:37:52.000Z
2020-01-09T13:33:17.000Z
#ifndef ApvAnalysisFactory_h #define ApvAnalysisFactory_h //#define DEBUG_INSTANCE_COUNTING #include "CalibTracker/SiStripAPVAnalysis/interface/ApvAnalysis.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" #include "CalibTracker/SiStripAPVAnalysis/interface/TkStateMachine.h" #include "CalibTracker/SiStripAPVAnalysis/interface/TkCommonMode.h" #include "CalibTracker/SiStripAPVAnalysis/interface/TT6ApvMask.h" #include "CalibTracker/SiStripAPVAnalysis/interface/TT6NoiseCalculator.h" #include "CalibTracker/SiStripAPVAnalysis/interface/TT6PedestalCalculator.h" #include "CalibTracker/SiStripAPVAnalysis/interface/TT6CommonModeCalculator.h" #include "CalibTracker/SiStripAPVAnalysis/interface/MedianCommonModeCalculator.h" #include "CalibTracker/SiStripAPVAnalysis/interface/SimplePedestalCalculator.h" #include "CalibTracker/SiStripAPVAnalysis/interface/SimpleNoiseCalculator.h" #include <vector> #include <iostream> #include<map> #include<algorithm> #include<string> class ApvAnalysisFactory { public: typedef std::vector<ApvAnalysis *> ApvAnalysisVector; ApvAnalysisFactory(std::string theAlgorithmType, int theNumCMstripsInGroup, int theMaskCalcFlag, float theMaskNoiseCut, float theMaskDeadCut, float theMaskTruncCut, float theCutToAvoidSignal, int theEventInitNumber, int theEventIterNumber); ApvAnalysisFactory(const edm::ParameterSet& pset ); ~ApvAnalysisFactory(); bool instantiateApvs(uint32_t det_id, int numberOfApvs); ApvAnalysisVector getApvAnalysis( const uint32_t nDET_ID); void getPedestal(uint32_t det_id , int apvNumber, ApvAnalysis::PedestalType& peds); void getPedestal(uint32_t det_id , ApvAnalysis::PedestalType& peds); float getStripPedestal(uint32_t det_id, int stripNumber); void getMask(uint32_t det_id, TkApvMask::MaskType& tmp); void getCommonMode(uint32_t det_id, ApvAnalysis::PedestalType& tmp); std::vector<float> getCommonMode(uint32_t det_id, int apvNumber); void getNoise(uint32_t det_id, int apvNumber, ApvAnalysis::PedestalType& noise); void getNoise(uint32_t det_id, ApvAnalysis::PedestalType& noise); float getStripNoise(uint32_t det_id, int stripNumber); void getRawNoise(uint32_t det_id, int apvNumber, ApvAnalysis::PedestalType& noise); void getRawNoise(uint32_t det_id, ApvAnalysis::PedestalType& noise); float getStripRawNoise(uint32_t det_id, int stripNumber); void getCommonModeSlope(uint32_t det_id, ApvAnalysis::PedestalType& tmp); float getCommonModeSlope(uint32_t det_id, int apvNumber); void update(uint32_t det_id, const edm::DetSet<SiStripRawDigi>& in); void updatePair(uint32_t det_id, size_t apvPair, const edm::DetSet<SiStripRawDigi>& in); std::string getStatus(uint32_t det_id); bool isUpdating(uint32_t detId); typedef std::map < uint32_t, ApvAnalysisVector> ApvAnalysisMap; typedef std::map < ApvAnalysis *,int > MapNumberingPosition; typedef std::map < ApvAnalysis *, uint32_t> InverseMap; private: // void constructAuxiliaryApvClasses (ApvAnalysis* thisApv); void constructAuxiliaryApvClasses (ApvAnalysis* theApv, uint32_t det_id, int thisApv); void deleteApv(ApvAnalysis* apv); ApvAnalysisMap apvMap_; std::string theAlgorithmType_; int theNumCMstripsInGroup_; int theMaskCalcFlag_; float theMaskNoiseCut_; float theMaskDeadCut_; float theMaskTruncCut_; float theCutToAvoidSignal_; int theEventInitNumber_; int theEventIterNumber_; std::string theCMType_; bool useDB_; }; #endif
36.8125
90
0.793718
0e07dbf36199ce04fad24b0037080b8dfa09ee55
3,544
h
C
src/cpu/vu/vif.h
GPUCode/ps2_emu
295e6def1ea0d58f1bf520332f986df5c8c92e02
[ "MIT" ]
10
2022-01-05T15:04:56.000Z
2022-02-23T05:59:44.000Z
src/cpu/vu/vif.h
GPUCode/ps2_emu
295e6def1ea0d58f1bf520332f986df5c8c92e02
[ "MIT" ]
null
null
null
src/cpu/vu/vif.h
GPUCode/ps2_emu
295e6def1ea0d58f1bf520332f986df5c8c92e02
[ "MIT" ]
null
null
null
#pragma once #include <common/component.h> #include <utils/queue.h> #include <array> namespace common { class Emulator; } namespace vu { union VIFSTAT { uint32_t value = 0; struct { uint32_t vif_status : 2; uint32_t e_wait : 1; uint32_t waiting_for_gif : 1; uint32_t : 2; uint32_t mark : 1; uint32_t double_buffer_flag : 1; uint32_t stalled_after_stop : 1; uint32_t stalled_after_break : 1; uint32_t stalled_on_intr : 1; uint32_t intr_detected : 1; uint32_t dmatag_mismatch : 1; uint32_t invalid_cmd : 1; uint32_t : 9; uint32_t fifo_detection : 1; uint32_t fifo_count : 5; }; }; union VIFFBRST { uint8_t value = 0; struct { uint8_t reset : 1; uint8_t force_break : 1; uint8_t stop_vif : 1; uint8_t stall_cancel : 1; }; }; union VIFCYCLE { uint16_t value; struct { uint16_t cycle_length : 8; uint16_t write_cycle_length : 8; }; }; union VIFCommand { uint32_t value; struct { union { uint16_t immediate; struct { uint16_t address : 10; uint16_t : 4; uint16_t sign_extend : 1; uint16_t flg : 1; }; }; /* The NUM field stores the subpacket length. However depending on whether the operation writes data or instructions to the VU its meaning can change. In data transfer operations the field is in qwords while in instruction transfers it's in dwords. */ uint8_t num; union { uint8_t command; struct { uint8_t vl : 2; uint8_t vn : 2; uint8_t mask : 1; }; }; }; }; enum VIFCommands { NOP = 0x0, STCYCL = 0x1, OFFSET = 0x2, BASE = 0x3, ITOP = 0x4, STMOD = 0x5, MSKPATH3 = 0x6, MARK = 0x7, FLUSHE = 0x10, FLUSH = 0x11, FLUSHA = 0x13, MSCAL = 0x14, MSCALF = 0x15, MSCNT = 0x17, STMASK = 0x20, STROW = 0x30, STCOL = 0x31, MPG = 0x4a, DIRECT = 0x50, DIRECTHL = 0x51, UNPACKSTART = 0x60, UNPACKEND = 0x7f }; enum VIFUFormat { S_32 = 0, S_16 = 1, S_8 = 2, V2_32 = 4, V2_16 = 5, V2_8 = 6, V3_32 = 8, V3_16 = 9, V3_8 = 10, V4_32 = 12, V4_16 = 13, V4_8 = 14, V4_5 = 15 }; enum WriteMode : bool { Skipping = 0, Filling = 1, }; /* Technically there are two VIFs (VIF0/VIF1) but they share 90% of their functionality so I'm merging them in a single class */ struct VIF : public common::Component { VIF(common::Emulator* parent, int N); ~VIF() = default; void tick(uint32_t cycles); void reset(); template <typename T> bool write_fifo(uint32_t, T data); uint32_t read(uint32_t address); void write(uint32_t address, uint32_t data); private: void process_command(); void process_unpack(); void execute_command(); void unpack_packet(); private: common::Emulator* emulator; int id; /* VIF registers */ VIFSTAT status = {}; VIFFBRST fbrst = {}; uint32_t err = 0, mark = 0; VIFCYCLE cycle; uint32_t mode = 0, num = 0; uint32_t mask = 0, code = 0, itops = 0; /* These only on exist on VIF1 */ uint32_t base = 0, ofst = 0; uint32_t tops = 0, itop = 0, top = 0; std::array<uint32_t, 4> rn = {}, cn = {}; /* VIF FIFO */ util::Queue<uint32_t, 64> fifo; WriteMode write_mode = WriteMode::Skipping; /* These is set by commands that expect data packets */ VIFCommand command = {}; uint32_t subpacket_count = 0, address = 0; uint32_t qwords_written = 0, word_cycles = 0; }; template<typename T> inline bool VIF::write_fifo(uint32_t, T data) { return fifo.push<T>(data); } }
18.081633
81
0.626693
33ce04a168a345275eda45b9a1b57942b8896790
444
h
C
cherry/src/shared/util/m_errno.h
mzxdream/bak
ceae06a4f40829f9c45b7f25758bf855ff348134
[ "Apache-2.0" ]
null
null
null
cherry/src/shared/util/m_errno.h
mzxdream/bak
ceae06a4f40829f9c45b7f25758bf855ff348134
[ "Apache-2.0" ]
null
null
null
cherry/src/shared/util/m_errno.h
mzxdream/bak
ceae06a4f40829f9c45b7f25758bf855ff348134
[ "Apache-2.0" ]
null
null
null
#ifndef _M_ERRNO_H_ #define _M_ERRNO_H_ #include <errno.h> enum class MError { No = 0, Unknown = 1, ConnectOpened = 2, ConnectFailed = 3, Disconnect = 4, OutOfMemory = 5, NotSupport = 6, NoData = 7, NotMatch = 8, ConvertFailed = 9, Running = 10, Created = 11, InProgress = 12, Again = 13, InterruptedSysCall = 14, Invalid = 15, Underflow = 16, Overflow = 17, }; #endif
15.310345
28
0.578829
b8902941b10978e6f71ab82cad05146ed6bd58d2
36,477
h
C
libcpp/Include/Proto/Trd_ReconfirmOrder.pb.h
stephenlyu/gofutuapi
1a60310dd142ac7049c9ef9cf22c7d78d0f880ef
[ "MIT" ]
2
2020-11-27T04:53:13.000Z
2021-11-15T02:15:27.000Z
libcpp/Include/Proto/Trd_ReconfirmOrder.pb.h
stephenlyu/gofutuapi
1a60310dd142ac7049c9ef9cf22c7d78d0f880ef
[ "MIT" ]
null
null
null
libcpp/Include/Proto/Trd_ReconfirmOrder.pb.h
stephenlyu/gofutuapi
1a60310dd142ac7049c9ef9cf22c7d78d0f880ef
[ "MIT" ]
null
null
null
// Generated by the protocol buffer compiler. DO NOT EDIT! // source: Trd_ReconfirmOrder.proto #ifndef PROTOBUF_Trd_5fReconfirmOrder_2eproto__INCLUDED #define PROTOBUF_Trd_5fReconfirmOrder_2eproto__INCLUDED #include <string> #include <google/protobuf/stubs/common.h> #if GOOGLE_PROTOBUF_VERSION < 3005000 #error This file was generated by a newer version of protoc which is #error incompatible with your Protocol Buffer headers. Please update #error your headers. #endif #if 3005001 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION #error This file was generated by an older version of protoc which is #error incompatible with your Protocol Buffer headers. Please #error regenerate this file with a newer version of protoc. #endif #include <google/protobuf/io/coded_stream.h> #include <google/protobuf/arena.h> #include <google/protobuf/arenastring.h> #include <google/protobuf/generated_message_table_driven.h> #include <google/protobuf/generated_message_util.h> #include <google/protobuf/metadata.h> #include <google/protobuf/message.h> #include <google/protobuf/repeated_field.h> // IWYU pragma: export #include <google/protobuf/extension_set.h> // IWYU pragma: export #include <google/protobuf/unknown_field_set.h> #include "Common.pb.h" #include "Trd_Common.pb.h" // @@protoc_insertion_point(includes) namespace protobuf_Trd_5fReconfirmOrder_2eproto { // Internal implementation detail -- do not use these members. struct TableStruct { static const ::google::protobuf::internal::ParseTableField entries[]; static const ::google::protobuf::internal::AuxillaryParseTableField aux[]; static const ::google::protobuf::internal::ParseTable schema[4]; static const ::google::protobuf::internal::FieldMetadata field_metadata[]; static const ::google::protobuf::internal::SerializationTable serialization_table[]; static const ::google::protobuf::uint32 offsets[]; }; void AddDescriptors(); void InitDefaultsC2SImpl(); void InitDefaultsC2S(); void InitDefaultsS2CImpl(); void InitDefaultsS2C(); void InitDefaultsRequestImpl(); void InitDefaultsRequest(); void InitDefaultsResponseImpl(); void InitDefaultsResponse(); inline void InitDefaults() { InitDefaultsC2S(); InitDefaultsS2C(); InitDefaultsRequest(); InitDefaultsResponse(); } } // namespace protobuf_Trd_5fReconfirmOrder_2eproto namespace Trd_ReconfirmOrder { class C2S; class C2SDefaultTypeInternal; extern C2SDefaultTypeInternal _C2S_default_instance_; class Request; class RequestDefaultTypeInternal; extern RequestDefaultTypeInternal _Request_default_instance_; class Response; class ResponseDefaultTypeInternal; extern ResponseDefaultTypeInternal _Response_default_instance_; class S2C; class S2CDefaultTypeInternal; extern S2CDefaultTypeInternal _S2C_default_instance_; } // namespace Trd_ReconfirmOrder namespace Trd_ReconfirmOrder { // =================================================================== class C2S : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:Trd_ReconfirmOrder.C2S) */ { public: C2S(); virtual ~C2S(); C2S(const C2S& from); inline C2S& operator=(const C2S& from) { CopyFrom(from); return *this; } #if LANG_CXX11 C2S(C2S&& from) noexcept : C2S() { *this = ::std::move(from); } inline C2S& operator=(C2S&& from) noexcept { if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { if (this != &from) InternalSwap(&from); } else { CopyFrom(from); } return *this; } #endif inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { return _internal_metadata_.unknown_fields(); } inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { return _internal_metadata_.mutable_unknown_fields(); } static const ::google::protobuf::Descriptor* descriptor(); static const C2S& default_instance(); static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY static inline const C2S* internal_default_instance() { return reinterpret_cast<const C2S*>( &_C2S_default_instance_); } static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = 0; void Swap(C2S* other); friend void swap(C2S& a, C2S& b) { a.Swap(&b); } // implements Message ---------------------------------------------- inline C2S* New() const PROTOBUF_FINAL { return New(NULL); } C2S* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL; void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL; void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL; void CopyFrom(const C2S& from); void MergeFrom(const C2S& from); void Clear() PROTOBUF_FINAL; bool IsInitialized() const PROTOBUF_FINAL; size_t ByteSizeLong() const PROTOBUF_FINAL; bool MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL; void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); void SharedDtor(); void SetCachedSize(int size) const PROTOBUF_FINAL; void InternalSwap(C2S* other); private: inline ::google::protobuf::Arena* GetArenaNoVirtual() const { return NULL; } inline void* MaybeArenaPtr() const { return NULL; } public: ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL; // nested types ---------------------------------------------------- // accessors ------------------------------------------------------- // required .Common.PacketID packetID = 1; bool has_packetid() const; void clear_packetid(); static const int kPacketIDFieldNumber = 1; const ::Common::PacketID& packetid() const; ::Common::PacketID* release_packetid(); ::Common::PacketID* mutable_packetid(); void set_allocated_packetid(::Common::PacketID* packetid); // required .Trd_Common.TrdHeader header = 2; bool has_header() const; void clear_header(); static const int kHeaderFieldNumber = 2; const ::Trd_Common::TrdHeader& header() const; ::Trd_Common::TrdHeader* release_header(); ::Trd_Common::TrdHeader* mutable_header(); void set_allocated_header(::Trd_Common::TrdHeader* header); // required uint64 orderID = 3; bool has_orderid() const; void clear_orderid(); static const int kOrderIDFieldNumber = 3; ::google::protobuf::uint64 orderid() const; void set_orderid(::google::protobuf::uint64 value); // required int32 reconfirmReason = 4; bool has_reconfirmreason() const; void clear_reconfirmreason(); static const int kReconfirmReasonFieldNumber = 4; ::google::protobuf::int32 reconfirmreason() const; void set_reconfirmreason(::google::protobuf::int32 value); // @@protoc_insertion_point(class_scope:Trd_ReconfirmOrder.C2S) private: void set_has_packetid(); void clear_has_packetid(); void set_has_header(); void clear_has_header(); void set_has_orderid(); void clear_has_orderid(); void set_has_reconfirmreason(); void clear_has_reconfirmreason(); // helper for ByteSizeLong() size_t RequiredFieldsByteSizeFallback() const; ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; ::google::protobuf::internal::HasBits<1> _has_bits_; mutable int _cached_size_; ::Common::PacketID* packetid_; ::Trd_Common::TrdHeader* header_; ::google::protobuf::uint64 orderid_; ::google::protobuf::int32 reconfirmreason_; friend struct ::protobuf_Trd_5fReconfirmOrder_2eproto::TableStruct; friend void ::protobuf_Trd_5fReconfirmOrder_2eproto::InitDefaultsC2SImpl(); }; // ------------------------------------------------------------------- class S2C : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:Trd_ReconfirmOrder.S2C) */ { public: S2C(); virtual ~S2C(); S2C(const S2C& from); inline S2C& operator=(const S2C& from) { CopyFrom(from); return *this; } #if LANG_CXX11 S2C(S2C&& from) noexcept : S2C() { *this = ::std::move(from); } inline S2C& operator=(S2C&& from) noexcept { if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { if (this != &from) InternalSwap(&from); } else { CopyFrom(from); } return *this; } #endif inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { return _internal_metadata_.unknown_fields(); } inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { return _internal_metadata_.mutable_unknown_fields(); } static const ::google::protobuf::Descriptor* descriptor(); static const S2C& default_instance(); static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY static inline const S2C* internal_default_instance() { return reinterpret_cast<const S2C*>( &_S2C_default_instance_); } static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = 1; void Swap(S2C* other); friend void swap(S2C& a, S2C& b) { a.Swap(&b); } // implements Message ---------------------------------------------- inline S2C* New() const PROTOBUF_FINAL { return New(NULL); } S2C* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL; void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL; void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL; void CopyFrom(const S2C& from); void MergeFrom(const S2C& from); void Clear() PROTOBUF_FINAL; bool IsInitialized() const PROTOBUF_FINAL; size_t ByteSizeLong() const PROTOBUF_FINAL; bool MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL; void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); void SharedDtor(); void SetCachedSize(int size) const PROTOBUF_FINAL; void InternalSwap(S2C* other); private: inline ::google::protobuf::Arena* GetArenaNoVirtual() const { return NULL; } inline void* MaybeArenaPtr() const { return NULL; } public: ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL; // nested types ---------------------------------------------------- // accessors ------------------------------------------------------- // required .Trd_Common.TrdHeader header = 1; bool has_header() const; void clear_header(); static const int kHeaderFieldNumber = 1; const ::Trd_Common::TrdHeader& header() const; ::Trd_Common::TrdHeader* release_header(); ::Trd_Common::TrdHeader* mutable_header(); void set_allocated_header(::Trd_Common::TrdHeader* header); // required uint64 orderID = 2; bool has_orderid() const; void clear_orderid(); static const int kOrderIDFieldNumber = 2; ::google::protobuf::uint64 orderid() const; void set_orderid(::google::protobuf::uint64 value); // @@protoc_insertion_point(class_scope:Trd_ReconfirmOrder.S2C) private: void set_has_header(); void clear_has_header(); void set_has_orderid(); void clear_has_orderid(); // helper for ByteSizeLong() size_t RequiredFieldsByteSizeFallback() const; ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; ::google::protobuf::internal::HasBits<1> _has_bits_; mutable int _cached_size_; ::Trd_Common::TrdHeader* header_; ::google::protobuf::uint64 orderid_; friend struct ::protobuf_Trd_5fReconfirmOrder_2eproto::TableStruct; friend void ::protobuf_Trd_5fReconfirmOrder_2eproto::InitDefaultsS2CImpl(); }; // ------------------------------------------------------------------- class Request : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:Trd_ReconfirmOrder.Request) */ { public: Request(); virtual ~Request(); Request(const Request& from); inline Request& operator=(const Request& from) { CopyFrom(from); return *this; } #if LANG_CXX11 Request(Request&& from) noexcept : Request() { *this = ::std::move(from); } inline Request& operator=(Request&& from) noexcept { if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { if (this != &from) InternalSwap(&from); } else { CopyFrom(from); } return *this; } #endif inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { return _internal_metadata_.unknown_fields(); } inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { return _internal_metadata_.mutable_unknown_fields(); } static const ::google::protobuf::Descriptor* descriptor(); static const Request& default_instance(); static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY static inline const Request* internal_default_instance() { return reinterpret_cast<const Request*>( &_Request_default_instance_); } static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = 2; void Swap(Request* other); friend void swap(Request& a, Request& b) { a.Swap(&b); } // implements Message ---------------------------------------------- inline Request* New() const PROTOBUF_FINAL { return New(NULL); } Request* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL; void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL; void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL; void CopyFrom(const Request& from); void MergeFrom(const Request& from); void Clear() PROTOBUF_FINAL; bool IsInitialized() const PROTOBUF_FINAL; size_t ByteSizeLong() const PROTOBUF_FINAL; bool MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL; void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); void SharedDtor(); void SetCachedSize(int size) const PROTOBUF_FINAL; void InternalSwap(Request* other); private: inline ::google::protobuf::Arena* GetArenaNoVirtual() const { return NULL; } inline void* MaybeArenaPtr() const { return NULL; } public: ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL; // nested types ---------------------------------------------------- // accessors ------------------------------------------------------- // required .Trd_ReconfirmOrder.C2S c2s = 1; bool has_c2s() const; void clear_c2s(); static const int kC2SFieldNumber = 1; const ::Trd_ReconfirmOrder::C2S& c2s() const; ::Trd_ReconfirmOrder::C2S* release_c2s(); ::Trd_ReconfirmOrder::C2S* mutable_c2s(); void set_allocated_c2s(::Trd_ReconfirmOrder::C2S* c2s); // @@protoc_insertion_point(class_scope:Trd_ReconfirmOrder.Request) private: void set_has_c2s(); void clear_has_c2s(); ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; ::google::protobuf::internal::HasBits<1> _has_bits_; mutable int _cached_size_; ::Trd_ReconfirmOrder::C2S* c2s_; friend struct ::protobuf_Trd_5fReconfirmOrder_2eproto::TableStruct; friend void ::protobuf_Trd_5fReconfirmOrder_2eproto::InitDefaultsRequestImpl(); }; // ------------------------------------------------------------------- class Response : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:Trd_ReconfirmOrder.Response) */ { public: Response(); virtual ~Response(); Response(const Response& from); inline Response& operator=(const Response& from) { CopyFrom(from); return *this; } #if LANG_CXX11 Response(Response&& from) noexcept : Response() { *this = ::std::move(from); } inline Response& operator=(Response&& from) noexcept { if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { if (this != &from) InternalSwap(&from); } else { CopyFrom(from); } return *this; } #endif inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { return _internal_metadata_.unknown_fields(); } inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { return _internal_metadata_.mutable_unknown_fields(); } static const ::google::protobuf::Descriptor* descriptor(); static const Response& default_instance(); static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY static inline const Response* internal_default_instance() { return reinterpret_cast<const Response*>( &_Response_default_instance_); } static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = 3; void Swap(Response* other); friend void swap(Response& a, Response& b) { a.Swap(&b); } // implements Message ---------------------------------------------- inline Response* New() const PROTOBUF_FINAL { return New(NULL); } Response* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL; void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL; void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL; void CopyFrom(const Response& from); void MergeFrom(const Response& from); void Clear() PROTOBUF_FINAL; bool IsInitialized() const PROTOBUF_FINAL; size_t ByteSizeLong() const PROTOBUF_FINAL; bool MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL; void SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } private: void SharedCtor(); void SharedDtor(); void SetCachedSize(int size) const PROTOBUF_FINAL; void InternalSwap(Response* other); private: inline ::google::protobuf::Arena* GetArenaNoVirtual() const { return NULL; } inline void* MaybeArenaPtr() const { return NULL; } public: ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL; // nested types ---------------------------------------------------- // accessors ------------------------------------------------------- // optional string retMsg = 2; bool has_retmsg() const; void clear_retmsg(); static const int kRetMsgFieldNumber = 2; const ::std::string& retmsg() const; void set_retmsg(const ::std::string& value); #if LANG_CXX11 void set_retmsg(::std::string&& value); #endif void set_retmsg(const char* value); void set_retmsg(const char* value, size_t size); ::std::string* mutable_retmsg(); ::std::string* release_retmsg(); void set_allocated_retmsg(::std::string* retmsg); // optional .Trd_ReconfirmOrder.S2C s2c = 4; bool has_s2c() const; void clear_s2c(); static const int kS2CFieldNumber = 4; const ::Trd_ReconfirmOrder::S2C& s2c() const; ::Trd_ReconfirmOrder::S2C* release_s2c(); ::Trd_ReconfirmOrder::S2C* mutable_s2c(); void set_allocated_s2c(::Trd_ReconfirmOrder::S2C* s2c); // optional int32 errCode = 3; bool has_errcode() const; void clear_errcode(); static const int kErrCodeFieldNumber = 3; ::google::protobuf::int32 errcode() const; void set_errcode(::google::protobuf::int32 value); // required int32 retType = 1 [default = -400]; bool has_rettype() const; void clear_rettype(); static const int kRetTypeFieldNumber = 1; ::google::protobuf::int32 rettype() const; void set_rettype(::google::protobuf::int32 value); // @@protoc_insertion_point(class_scope:Trd_ReconfirmOrder.Response) private: void set_has_rettype(); void clear_has_rettype(); void set_has_retmsg(); void clear_has_retmsg(); void set_has_errcode(); void clear_has_errcode(); void set_has_s2c(); void clear_has_s2c(); ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; ::google::protobuf::internal::HasBits<1> _has_bits_; mutable int _cached_size_; ::google::protobuf::internal::ArenaStringPtr retmsg_; ::Trd_ReconfirmOrder::S2C* s2c_; ::google::protobuf::int32 errcode_; ::google::protobuf::int32 rettype_; friend struct ::protobuf_Trd_5fReconfirmOrder_2eproto::TableStruct; friend void ::protobuf_Trd_5fReconfirmOrder_2eproto::InitDefaultsResponseImpl(); }; // =================================================================== // =================================================================== #ifdef __GNUC__ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wstrict-aliasing" #endif // __GNUC__ // C2S // required .Common.PacketID packetID = 1; inline bool C2S::has_packetid() const { return (_has_bits_[0] & 0x00000001u) != 0; } inline void C2S::set_has_packetid() { _has_bits_[0] |= 0x00000001u; } inline void C2S::clear_has_packetid() { _has_bits_[0] &= ~0x00000001u; } inline const ::Common::PacketID& C2S::packetid() const { const ::Common::PacketID* p = packetid_; // @@protoc_insertion_point(field_get:Trd_ReconfirmOrder.C2S.packetID) return p != NULL ? *p : *reinterpret_cast<const ::Common::PacketID*>( &::Common::_PacketID_default_instance_); } inline ::Common::PacketID* C2S::release_packetid() { // @@protoc_insertion_point(field_release:Trd_ReconfirmOrder.C2S.packetID) clear_has_packetid(); ::Common::PacketID* temp = packetid_; packetid_ = NULL; return temp; } inline ::Common::PacketID* C2S::mutable_packetid() { set_has_packetid(); if (packetid_ == NULL) { packetid_ = new ::Common::PacketID; } // @@protoc_insertion_point(field_mutable:Trd_ReconfirmOrder.C2S.packetID) return packetid_; } inline void C2S::set_allocated_packetid(::Common::PacketID* packetid) { ::google::protobuf::Arena* message_arena = GetArenaNoVirtual(); if (message_arena == NULL) { delete reinterpret_cast< ::google::protobuf::MessageLite*>(packetid_); } if (packetid) { ::google::protobuf::Arena* submessage_arena = NULL; if (message_arena != submessage_arena) { packetid = ::google::protobuf::internal::GetOwnedMessage( message_arena, packetid, submessage_arena); } set_has_packetid(); } else { clear_has_packetid(); } packetid_ = packetid; // @@protoc_insertion_point(field_set_allocated:Trd_ReconfirmOrder.C2S.packetID) } // required .Trd_Common.TrdHeader header = 2; inline bool C2S::has_header() const { return (_has_bits_[0] & 0x00000002u) != 0; } inline void C2S::set_has_header() { _has_bits_[0] |= 0x00000002u; } inline void C2S::clear_has_header() { _has_bits_[0] &= ~0x00000002u; } inline const ::Trd_Common::TrdHeader& C2S::header() const { const ::Trd_Common::TrdHeader* p = header_; // @@protoc_insertion_point(field_get:Trd_ReconfirmOrder.C2S.header) return p != NULL ? *p : *reinterpret_cast<const ::Trd_Common::TrdHeader*>( &::Trd_Common::_TrdHeader_default_instance_); } inline ::Trd_Common::TrdHeader* C2S::release_header() { // @@protoc_insertion_point(field_release:Trd_ReconfirmOrder.C2S.header) clear_has_header(); ::Trd_Common::TrdHeader* temp = header_; header_ = NULL; return temp; } inline ::Trd_Common::TrdHeader* C2S::mutable_header() { set_has_header(); if (header_ == NULL) { header_ = new ::Trd_Common::TrdHeader; } // @@protoc_insertion_point(field_mutable:Trd_ReconfirmOrder.C2S.header) return header_; } inline void C2S::set_allocated_header(::Trd_Common::TrdHeader* header) { ::google::protobuf::Arena* message_arena = GetArenaNoVirtual(); if (message_arena == NULL) { delete reinterpret_cast< ::google::protobuf::MessageLite*>(header_); } if (header) { ::google::protobuf::Arena* submessage_arena = NULL; if (message_arena != submessage_arena) { header = ::google::protobuf::internal::GetOwnedMessage( message_arena, header, submessage_arena); } set_has_header(); } else { clear_has_header(); } header_ = header; // @@protoc_insertion_point(field_set_allocated:Trd_ReconfirmOrder.C2S.header) } // required uint64 orderID = 3; inline bool C2S::has_orderid() const { return (_has_bits_[0] & 0x00000004u) != 0; } inline void C2S::set_has_orderid() { _has_bits_[0] |= 0x00000004u; } inline void C2S::clear_has_orderid() { _has_bits_[0] &= ~0x00000004u; } inline void C2S::clear_orderid() { orderid_ = GOOGLE_ULONGLONG(0); clear_has_orderid(); } inline ::google::protobuf::uint64 C2S::orderid() const { // @@protoc_insertion_point(field_get:Trd_ReconfirmOrder.C2S.orderID) return orderid_; } inline void C2S::set_orderid(::google::protobuf::uint64 value) { set_has_orderid(); orderid_ = value; // @@protoc_insertion_point(field_set:Trd_ReconfirmOrder.C2S.orderID) } // required int32 reconfirmReason = 4; inline bool C2S::has_reconfirmreason() const { return (_has_bits_[0] & 0x00000008u) != 0; } inline void C2S::set_has_reconfirmreason() { _has_bits_[0] |= 0x00000008u; } inline void C2S::clear_has_reconfirmreason() { _has_bits_[0] &= ~0x00000008u; } inline void C2S::clear_reconfirmreason() { reconfirmreason_ = 0; clear_has_reconfirmreason(); } inline ::google::protobuf::int32 C2S::reconfirmreason() const { // @@protoc_insertion_point(field_get:Trd_ReconfirmOrder.C2S.reconfirmReason) return reconfirmreason_; } inline void C2S::set_reconfirmreason(::google::protobuf::int32 value) { set_has_reconfirmreason(); reconfirmreason_ = value; // @@protoc_insertion_point(field_set:Trd_ReconfirmOrder.C2S.reconfirmReason) } // ------------------------------------------------------------------- // S2C // required .Trd_Common.TrdHeader header = 1; inline bool S2C::has_header() const { return (_has_bits_[0] & 0x00000001u) != 0; } inline void S2C::set_has_header() { _has_bits_[0] |= 0x00000001u; } inline void S2C::clear_has_header() { _has_bits_[0] &= ~0x00000001u; } inline const ::Trd_Common::TrdHeader& S2C::header() const { const ::Trd_Common::TrdHeader* p = header_; // @@protoc_insertion_point(field_get:Trd_ReconfirmOrder.S2C.header) return p != NULL ? *p : *reinterpret_cast<const ::Trd_Common::TrdHeader*>( &::Trd_Common::_TrdHeader_default_instance_); } inline ::Trd_Common::TrdHeader* S2C::release_header() { // @@protoc_insertion_point(field_release:Trd_ReconfirmOrder.S2C.header) clear_has_header(); ::Trd_Common::TrdHeader* temp = header_; header_ = NULL; return temp; } inline ::Trd_Common::TrdHeader* S2C::mutable_header() { set_has_header(); if (header_ == NULL) { header_ = new ::Trd_Common::TrdHeader; } // @@protoc_insertion_point(field_mutable:Trd_ReconfirmOrder.S2C.header) return header_; } inline void S2C::set_allocated_header(::Trd_Common::TrdHeader* header) { ::google::protobuf::Arena* message_arena = GetArenaNoVirtual(); if (message_arena == NULL) { delete reinterpret_cast< ::google::protobuf::MessageLite*>(header_); } if (header) { ::google::protobuf::Arena* submessage_arena = NULL; if (message_arena != submessage_arena) { header = ::google::protobuf::internal::GetOwnedMessage( message_arena, header, submessage_arena); } set_has_header(); } else { clear_has_header(); } header_ = header; // @@protoc_insertion_point(field_set_allocated:Trd_ReconfirmOrder.S2C.header) } // required uint64 orderID = 2; inline bool S2C::has_orderid() const { return (_has_bits_[0] & 0x00000002u) != 0; } inline void S2C::set_has_orderid() { _has_bits_[0] |= 0x00000002u; } inline void S2C::clear_has_orderid() { _has_bits_[0] &= ~0x00000002u; } inline void S2C::clear_orderid() { orderid_ = GOOGLE_ULONGLONG(0); clear_has_orderid(); } inline ::google::protobuf::uint64 S2C::orderid() const { // @@protoc_insertion_point(field_get:Trd_ReconfirmOrder.S2C.orderID) return orderid_; } inline void S2C::set_orderid(::google::protobuf::uint64 value) { set_has_orderid(); orderid_ = value; // @@protoc_insertion_point(field_set:Trd_ReconfirmOrder.S2C.orderID) } // ------------------------------------------------------------------- // Request // required .Trd_ReconfirmOrder.C2S c2s = 1; inline bool Request::has_c2s() const { return (_has_bits_[0] & 0x00000001u) != 0; } inline void Request::set_has_c2s() { _has_bits_[0] |= 0x00000001u; } inline void Request::clear_has_c2s() { _has_bits_[0] &= ~0x00000001u; } inline void Request::clear_c2s() { if (c2s_ != NULL) c2s_->Clear(); clear_has_c2s(); } inline const ::Trd_ReconfirmOrder::C2S& Request::c2s() const { const ::Trd_ReconfirmOrder::C2S* p = c2s_; // @@protoc_insertion_point(field_get:Trd_ReconfirmOrder.Request.c2s) return p != NULL ? *p : *reinterpret_cast<const ::Trd_ReconfirmOrder::C2S*>( &::Trd_ReconfirmOrder::_C2S_default_instance_); } inline ::Trd_ReconfirmOrder::C2S* Request::release_c2s() { // @@protoc_insertion_point(field_release:Trd_ReconfirmOrder.Request.c2s) clear_has_c2s(); ::Trd_ReconfirmOrder::C2S* temp = c2s_; c2s_ = NULL; return temp; } inline ::Trd_ReconfirmOrder::C2S* Request::mutable_c2s() { set_has_c2s(); if (c2s_ == NULL) { c2s_ = new ::Trd_ReconfirmOrder::C2S; } // @@protoc_insertion_point(field_mutable:Trd_ReconfirmOrder.Request.c2s) return c2s_; } inline void Request::set_allocated_c2s(::Trd_ReconfirmOrder::C2S* c2s) { ::google::protobuf::Arena* message_arena = GetArenaNoVirtual(); if (message_arena == NULL) { delete c2s_; } if (c2s) { ::google::protobuf::Arena* submessage_arena = NULL; if (message_arena != submessage_arena) { c2s = ::google::protobuf::internal::GetOwnedMessage( message_arena, c2s, submessage_arena); } set_has_c2s(); } else { clear_has_c2s(); } c2s_ = c2s; // @@protoc_insertion_point(field_set_allocated:Trd_ReconfirmOrder.Request.c2s) } // ------------------------------------------------------------------- // Response // required int32 retType = 1 [default = -400]; inline bool Response::has_rettype() const { return (_has_bits_[0] & 0x00000008u) != 0; } inline void Response::set_has_rettype() { _has_bits_[0] |= 0x00000008u; } inline void Response::clear_has_rettype() { _has_bits_[0] &= ~0x00000008u; } inline void Response::clear_rettype() { rettype_ = -400; clear_has_rettype(); } inline ::google::protobuf::int32 Response::rettype() const { // @@protoc_insertion_point(field_get:Trd_ReconfirmOrder.Response.retType) return rettype_; } inline void Response::set_rettype(::google::protobuf::int32 value) { set_has_rettype(); rettype_ = value; // @@protoc_insertion_point(field_set:Trd_ReconfirmOrder.Response.retType) } // optional string retMsg = 2; inline bool Response::has_retmsg() const { return (_has_bits_[0] & 0x00000001u) != 0; } inline void Response::set_has_retmsg() { _has_bits_[0] |= 0x00000001u; } inline void Response::clear_has_retmsg() { _has_bits_[0] &= ~0x00000001u; } inline void Response::clear_retmsg() { retmsg_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); clear_has_retmsg(); } inline const ::std::string& Response::retmsg() const { // @@protoc_insertion_point(field_get:Trd_ReconfirmOrder.Response.retMsg) return retmsg_.GetNoArena(); } inline void Response::set_retmsg(const ::std::string& value) { set_has_retmsg(); retmsg_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); // @@protoc_insertion_point(field_set:Trd_ReconfirmOrder.Response.retMsg) } #if LANG_CXX11 inline void Response::set_retmsg(::std::string&& value) { set_has_retmsg(); retmsg_.SetNoArena( &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value)); // @@protoc_insertion_point(field_set_rvalue:Trd_ReconfirmOrder.Response.retMsg) } #endif inline void Response::set_retmsg(const char* value) { GOOGLE_DCHECK(value != NULL); set_has_retmsg(); retmsg_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); // @@protoc_insertion_point(field_set_char:Trd_ReconfirmOrder.Response.retMsg) } inline void Response::set_retmsg(const char* value, size_t size) { set_has_retmsg(); retmsg_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(reinterpret_cast<const char*>(value), size)); // @@protoc_insertion_point(field_set_pointer:Trd_ReconfirmOrder.Response.retMsg) } inline ::std::string* Response::mutable_retmsg() { set_has_retmsg(); // @@protoc_insertion_point(field_mutable:Trd_ReconfirmOrder.Response.retMsg) return retmsg_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } inline ::std::string* Response::release_retmsg() { // @@protoc_insertion_point(field_release:Trd_ReconfirmOrder.Response.retMsg) clear_has_retmsg(); return retmsg_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); } inline void Response::set_allocated_retmsg(::std::string* retmsg) { if (retmsg != NULL) { set_has_retmsg(); } else { clear_has_retmsg(); } retmsg_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), retmsg); // @@protoc_insertion_point(field_set_allocated:Trd_ReconfirmOrder.Response.retMsg) } // optional int32 errCode = 3; inline bool Response::has_errcode() const { return (_has_bits_[0] & 0x00000004u) != 0; } inline void Response::set_has_errcode() { _has_bits_[0] |= 0x00000004u; } inline void Response::clear_has_errcode() { _has_bits_[0] &= ~0x00000004u; } inline void Response::clear_errcode() { errcode_ = 0; clear_has_errcode(); } inline ::google::protobuf::int32 Response::errcode() const { // @@protoc_insertion_point(field_get:Trd_ReconfirmOrder.Response.errCode) return errcode_; } inline void Response::set_errcode(::google::protobuf::int32 value) { set_has_errcode(); errcode_ = value; // @@protoc_insertion_point(field_set:Trd_ReconfirmOrder.Response.errCode) } // optional .Trd_ReconfirmOrder.S2C s2c = 4; inline bool Response::has_s2c() const { return (_has_bits_[0] & 0x00000002u) != 0; } inline void Response::set_has_s2c() { _has_bits_[0] |= 0x00000002u; } inline void Response::clear_has_s2c() { _has_bits_[0] &= ~0x00000002u; } inline void Response::clear_s2c() { if (s2c_ != NULL) s2c_->Clear(); clear_has_s2c(); } inline const ::Trd_ReconfirmOrder::S2C& Response::s2c() const { const ::Trd_ReconfirmOrder::S2C* p = s2c_; // @@protoc_insertion_point(field_get:Trd_ReconfirmOrder.Response.s2c) return p != NULL ? *p : *reinterpret_cast<const ::Trd_ReconfirmOrder::S2C*>( &::Trd_ReconfirmOrder::_S2C_default_instance_); } inline ::Trd_ReconfirmOrder::S2C* Response::release_s2c() { // @@protoc_insertion_point(field_release:Trd_ReconfirmOrder.Response.s2c) clear_has_s2c(); ::Trd_ReconfirmOrder::S2C* temp = s2c_; s2c_ = NULL; return temp; } inline ::Trd_ReconfirmOrder::S2C* Response::mutable_s2c() { set_has_s2c(); if (s2c_ == NULL) { s2c_ = new ::Trd_ReconfirmOrder::S2C; } // @@protoc_insertion_point(field_mutable:Trd_ReconfirmOrder.Response.s2c) return s2c_; } inline void Response::set_allocated_s2c(::Trd_ReconfirmOrder::S2C* s2c) { ::google::protobuf::Arena* message_arena = GetArenaNoVirtual(); if (message_arena == NULL) { delete s2c_; } if (s2c) { ::google::protobuf::Arena* submessage_arena = NULL; if (message_arena != submessage_arena) { s2c = ::google::protobuf::internal::GetOwnedMessage( message_arena, s2c, submessage_arena); } set_has_s2c(); } else { clear_has_s2c(); } s2c_ = s2c; // @@protoc_insertion_point(field_set_allocated:Trd_ReconfirmOrder.Response.s2c) } #ifdef __GNUC__ #pragma GCC diagnostic pop #endif // __GNUC__ // ------------------------------------------------------------------- // ------------------------------------------------------------------- // ------------------------------------------------------------------- // @@protoc_insertion_point(namespace_scope) } // namespace Trd_ReconfirmOrder // @@protoc_insertion_point(global_scope) #endif // PROTOBUF_Trd_5fReconfirmOrder_2eproto__INCLUDED
33.373285
130
0.700853
ed54794b29be78a9ce53232860900ade730795db
3,210
h
C
Applications/Setup/BuddyMigrationProgressController.h
zhangkn/iOS14Header
4323e9459ed6f6f5504ecbea2710bfd6c3d7c946
[ "MIT" ]
1
2020-11-04T15:43:01.000Z
2020-11-04T15:43:01.000Z
Applications/Setup/BuddyMigrationProgressController.h
zhangkn/iOS14Header
4323e9459ed6f6f5504ecbea2710bfd6c3d7c946
[ "MIT" ]
null
null
null
Applications/Setup/BuddyMigrationProgressController.h
zhangkn/iOS14Header
4323e9459ed6f6f5504ecbea2710bfd6c3d7c946
[ "MIT" ]
null
null
null
// // Generated by classdumpios 1.0.1 (64 bit) (iOS port by DreamDevLost)(Debug version compiled Sep 26 2020 13:48:20). // // Copyright (C) 1997-2019 Steve Nygard. // #import <SetupAssistantUI/BFFMigrationTimeRemainingController.h> #import "BFFFlowItem-Protocol.h" #import "BYDeviceMigrationDelegate-Protocol.h" @class BuddyMigrationBaseDisconnectController, BuddyMigrationLockscreenController, BuddyTargetDeviceMigrationManager, MBDeviceTransferConnectionInfo, NSObject, NSString; @protocol BFFFlowItemDelegate, OS_dispatch_queue; @interface BuddyMigrationProgressController : BFFMigrationTimeRemainingController <BFFFlowItem, BYDeviceMigrationDelegate> { NSString *_progressTitle; // 8 = 0x8 id <BFFFlowItemDelegate> _delegate; // 16 = 0x10 BuddyMigrationLockscreenController *_lockscreenController; // 24 = 0x18 BuddyMigrationBaseDisconnectController *_disconnectController; // 32 = 0x20 NSObject<OS_dispatch_queue> *_disconnectionQueue; // 40 = 0x28 long long _connectionState; // 48 = 0x30 BuddyTargetDeviceMigrationManager *_manager; // 56 = 0x38 MBDeviceTransferConnectionInfo *_connectionInfo; // 64 = 0x40 } + (id)cloudConfigSkipKey; // IMP=0x000000010009c948 - (void).cxx_destruct; // IMP=0x000000010009d358 @property(retain, nonatomic) MBDeviceTransferConnectionInfo *connectionInfo; // @synthesize connectionInfo=_connectionInfo; @property(retain, nonatomic) BuddyTargetDeviceMigrationManager *manager; // @synthesize manager=_manager; @property(nonatomic) long long connectionState; // @synthesize connectionState=_connectionState; @property(retain, nonatomic) NSObject<OS_dispatch_queue> *disconnectionQueue; // @synthesize disconnectionQueue=_disconnectionQueue; @property(retain, nonatomic) BuddyMigrationBaseDisconnectController *disconnectController; // @synthesize disconnectController=_disconnectController; @property(retain, nonatomic) BuddyMigrationLockscreenController *lockscreenController; // @synthesize lockscreenController=_lockscreenController; @property(nonatomic) __weak id <BFFFlowItemDelegate> delegate; // @synthesize delegate=_delegate; @property(retain, nonatomic) NSString *progressTitle; // @synthesize progressTitle=_progressTitle; - (void)deviceMigrationManager:(id)arg1 didCompleteWithError:(id)arg2; // IMP=0x000000010009d1b8 - (void)deviceMigrationManager:(id)arg1 didUpdateProgress:(id)arg2; // IMP=0x000000010009d0c0 - (void)deviceMigrationManager:(id)arg1 didChangeConnectionInformation:(id)arg2; // IMP=0x000000010009c958 - (_Bool)shouldAllowStartOver; // IMP=0x000000010009c950 - (void)_cancelTapped:(id)arg1; // IMP=0x000000010009c8e0 - (void)cancelMigration; // IMP=0x000000010009c87c - (void)confirmCancellation:(CDUnknownBlockType)arg1; // IMP=0x000000010009c878 - (id)createLockscreenController; // IMP=0x000000010009c874 - (void)viewDidAppear:(_Bool)arg1; // IMP=0x000000010009c604 - (void)loadView; // IMP=0x000000010009c50c - (id)initWithTitle:(id)arg1 icon:(id)arg2; // IMP=0x000000010009c3c0 // Remaining properties @property(readonly, copy) NSString *debugDescription; @property(readonly, copy) NSString *description; @property(readonly) unsigned long long hash; @property(readonly) Class superclass; @end
56.315789
169
0.809034
4bfb589d280f176255da4c2baff98ef7bcf24c20
771
h
C
Applications/PaintBrush/LineTool.h
karolba/serenity
51262e7e2d5b3d4859337a5df784ab4f470be41a
[ "BSD-2-Clause" ]
null
null
null
Applications/PaintBrush/LineTool.h
karolba/serenity
51262e7e2d5b3d4859337a5df784ab4f470be41a
[ "BSD-2-Clause" ]
null
null
null
Applications/PaintBrush/LineTool.h
karolba/serenity
51262e7e2d5b3d4859337a5df784ab4f470be41a
[ "BSD-2-Clause" ]
null
null
null
#pragma once #include "Tool.h" #include <LibDraw/Point.h> class GMenu; class LineTool final : public Tool { public: LineTool(); virtual ~LineTool() override; virtual void on_mousedown(GMouseEvent&) override; virtual void on_mousemove(GMouseEvent&) override; virtual void on_mouseup(GMouseEvent&) override; virtual void on_contextmenu(GContextMenuEvent&) override; virtual void on_second_paint(GPaintEvent&) override; virtual void on_keydown(GKeyEvent&) override; private: virtual const char* class_name() const override { return "LineTool"; } GMouseButton m_drawing_button { GMouseButton::None }; Point m_line_start_position; Point m_line_end_position; OwnPtr<GMenu> m_context_menu; int m_thickness { 1 }; };
26.586207
74
0.736706
722f2a07eea90f74087bc01ca721272067737009
1,187
h
C
GameCore/Texture.h
aitay721822/OpenGL_Pratice
72c2ffd6235f8913e77d2c525d08b005638d7d60
[ "MIT" ]
null
null
null
GameCore/Texture.h
aitay721822/OpenGL_Pratice
72c2ffd6235f8913e77d2c525d08b005638d7d60
[ "MIT" ]
null
null
null
GameCore/Texture.h
aitay721822/OpenGL_Pratice
72c2ffd6235f8913e77d2c525d08b005638d7d60
[ "MIT" ]
null
null
null
#pragma once #include <glm/glm.hpp> #include <GL/glew.h> #include "TextureType.h" using namespace std; using namespace glm; namespace GameCore { static u32 TextureGlobalId = 0; class Texture { private: Logger logger = Logger("Texture"); public: // object properties u32 id; TextureType type; string name; // texture properties (openGL) GLuint wrapS; GLuint wrapT; GLuint wrapR; GLuint magFilter; GLuint minFilter; GLboolean generateMipmaps; // image properties vector<string> imagePaths; // textureId GLuint textureId; Texture(vector<string> imagePaths, GLuint wrapS = GL_REPEAT, GLuint wrapT = GL_REPEAT, GLuint wrapR = GL_REPEAT, GLuint magFilter = GL_LINEAR_MIPMAP_LINEAR, GLuint minFilter = GL_LINEAR, GLboolean generateMipmaps = GL_TRUE) { this->id = TextureGlobalId++; this->type = TextureType::Texture; this->name = ""; this->wrapS = wrapS; this->wrapT = wrapT; this->wrapR = wrapR; this->magFilter = magFilter; this->minFilter = minFilter; this->generateMipmaps = generateMipmaps; this->textureId = 0; this->imagePaths = imagePaths; } virtual void load() = 0; }; }
18.546875
46
0.68492
725016da40b983c8e2c40259ba5a33bb6c129bbf
218
h
C
Sample/WalletDemo/Src/Custom/KeyBoard/WDSecurityTextField.h
cqmbr/MBRWallet-iOS
301f9c2ff26ed2468f94bc5af300a37800f796a4
[ "MIT" ]
2
2018-07-11T08:44:46.000Z
2018-09-21T13:44:02.000Z
Sample/WalletDemo/Src/Custom/KeyBoard/WDSecurityTextField.h
cqlinkoff/Wallet-iOS
71c3edbc1797ff8b0afbb2754180a4169292e423
[ "MIT" ]
null
null
null
Sample/WalletDemo/Src/Custom/KeyBoard/WDSecurityTextField.h
cqlinkoff/Wallet-iOS
71c3edbc1797ff8b0afbb2754180a4169292e423
[ "MIT" ]
null
null
null
// // WDSecurityTextField.h // MBRUIKit // // Created by lfl on 2018/5/15. // Copyright © 2018年 mbr. All rights reserved. // #import "WDCommonTextField.h" @interface WDSecurityTextField : WDCommonTextField @end
15.571429
50
0.711009
729e3f408089ddba18c9e80996d05c80dd85f26d
853
h
C
docs/examples/nested_structs/fridge.h
goatshriek/wrapture
daf2bf940d06bbaa801cfbdf04de7f880ea27dcf
[ "Apache-2.0" ]
1
2019-05-03T11:57:43.000Z
2019-05-03T11:57:43.000Z
docs/examples/nested_structs/fridge.h
goatshriek/wrapture
daf2bf940d06bbaa801cfbdf04de7f880ea27dcf
[ "Apache-2.0" ]
79
2019-05-25T13:46:45.000Z
2021-09-02T03:48:41.000Z
docs/examples/nested_structs/fridge.h
goatshriek/wrapture
daf2bf940d06bbaa801cfbdf04de7f880ea27dcf
[ "Apache-2.0" ]
1
2020-08-07T03:42:59.000Z
2020-08-07T03:42:59.000Z
#ifndef __FRIDGE_H #define __FRIDGE_H struct ice_maker { int size; int can_crush_ice; // boolean value }; struct water_filter { int purity_level; }; struct freezer { int minimum_temp; int set_temp; }; struct fridge { int temp; struct ice_maker *ice; struct water_filter *filter; struct freezer *freezer; }; struct fridge * new_fridge( int temperature ); struct ice_maker * new_ice_maker( int size, int can_crush_ice ); struct water_filter * new_water_filter( int purity_level ); struct freezer * new_freezer( int minimum_temp, int set_temp ); void add_ice_maker_to_fridge( struct fridge *fridge, struct ice_maker *maker ); void add_water_filter_to_fridge( struct fridge *fridge, struct water_filter *filter ); void add_freezer_to_fridge( struct fridge *fridge, struct freezer *freezer ); #endif
17.770833
74
0.73388
c26c135384c2e57f69d88574b2e8d64b53febed2
7,783
h
C
eos/nexthop_group.h
pchabermann/EosSdk
c7f96a18bb06d0bbdb0b15a9de501f2518102651
[ "BSD-3-Clause" ]
132
2015-02-04T20:25:20.000Z
2022-03-10T03:50:32.000Z
eos/nexthop_group.h
pchabermann/EosSdk
c7f96a18bb06d0bbdb0b15a9de501f2518102651
[ "BSD-3-Clause" ]
57
2015-05-20T22:34:28.000Z
2022-03-16T21:52:28.000Z
eos/nexthop_group.h
pchabermann/EosSdk
c7f96a18bb06d0bbdb0b15a9de501f2518102651
[ "BSD-3-Clause" ]
39
2015-02-17T21:04:47.000Z
2021-06-18T00:38:46.000Z
// Copyright (c) 2014 Arista Networks, Inc. All rights reserved. // Arista Networks, Inc. Confidential and Proprietary. /** * @file * Nexthop groups are a forwarding/tunneling abstraction in EOS. * * A nexthop group is comprised of a tunneling protocol (IP/GRE or * MPLS, for example) and a collection of nexthop (aka destination) * IP addresses and other forwarding information (such as MPLS stack * operations to apply for traffic sent to that nexthop). The same * IP address may be specified in more than one entry within the * group, allowing for unequal cost load balancing. By using distinct * addresses for each entry, equal cost load balancing can be achieved. * * The nexthop or destination IP is the tunnel (outer) destination IP * address for GRE and IP-in-IP. For MPLS, the nexthop address is used * to find (via ARP/ND) a MAC address for the MPLS next hop. * * Nexthop entries must be manually monitored and maintained by the * agent. If a tunnel destination (aka nexthop) becomes unreachable, * traffic hashed to that entry will be black-holed in the network * until a working entry is set in that index of the nexthop group, or * the entry is deleted. * * Presently, all nexthop groups encapsulate traffic directed to them, * either as an IP-in-IP (IP protocol 4) tunnel, a GRE (IP protocol * 47) tunnel encapsulating either IPv4, IPv6 or MPLS traffic, or as * pure MPLS frames. MPLS label switching operations are also * supported, see the nexthop_group_entry_t class for more * information. * * Presently, MPLS switching actions are only only supported when used * with PBR and cannot be used with IP routes. * * The following example creates a nexthop group called "nhg1" which * performs GRE encapsulation of traffic sent to it, sending traffic * to two different nexthop IP addresses unequally (at a 2/3 to 1/3 * ratio). For a usage of a nexthop group with policy routing, see the * policy_map.h file. * * @code * eos::nexthop_group_t nhg("nhg1", eos::NEXTHOP_GROUP_GRE); * // Specify two destinations (nexthop group entries) for the traffic * eos::nexthop_group_entry_t nhe1(eos::ip_addr_t("172.12.1.1")); * eos::nexthop_group_entry_t nhe2(eos::ip_addr_t("172.12.1.2")); * // Set the nexthop group entries on the group with unequal cost load balancing * // Balance traffic 2/3 to 172.12.1.1, 1/3 to 172.12.1.2. * nhg.nexthop_set(0, nhe1); * nhg.nexthop_set(1, nhe1); * nhg.nexthop_set(2, nhe2); * @endcode */ #ifndef EOS_NEXTHOP_GROUP_H #define EOS_NEXTHOP_GROUP_H #include <eos/base_handler.h> #include <eos/base_mgr.h> #include <eos/intf.h> #include <eos/ip.h> #include <eos/iterator.h> #include <eos/mpls.h> #include <eos/types/nexthop_group.h> namespace eos { class nexthop_group_mgr; /// This class handles changes to a nexthop group's status class EOS_SDK_PUBLIC nexthop_group_handler : public base_handler<nexthop_group_mgr, nexthop_group_handler> { public: explicit nexthop_group_handler(nexthop_group_mgr *); nexthop_group_mgr * get_nexthop_group_mgr() const; /** * Registers this class to receive change updates on all nexthop groups. * * Expects a boolean signifying whether notifications should be * propagated to this instance or not. */ void watch_all_nexthop_groups(bool); /** * Registers this class to receive change updates on the given nexthop group. * * Expects the name of the corresponding nexthop group and a * boolean signifying whether notifications should be propagated to * this instance or not. */ void watch_nexthop_group(std::string const & nexthop_group_name, bool); /// Handler called when the active status of a nexthop_group changes virtual void on_nexthop_group_active(std::string const & nexthop_group_name, bool active); /** * Handler called when the nexthop_group is programmed in response to a * configuration change. */ virtual void on_nexthop_group_programmed(std::string const & nexthop_group_name); }; class nexthop_group_iter_impl; // An iterator that yields nexthop group for each configured nexthop group class EOS_SDK_PUBLIC nexthop_group_iter_t : public iter_base<nexthop_group_t, nexthop_group_iter_impl> { private: friend class nexthop_group_iter_impl; explicit nexthop_group_iter_t(nexthop_group_iter_impl * const) EOS_SDK_PRIVATE; }; class programmed_nexthop_group_iter_impl; // An iterator that yields nexthop group name for each programmed nexthop group class EOS_SDK_PUBLIC programmed_nexthop_group_iter_t : public iter_base<std::string, programmed_nexthop_group_iter_impl> { private: friend class programmed_nexthop_group_iter_impl; explicit programmed_nexthop_group_iter_t( programmed_nexthop_group_iter_impl * const) EOS_SDK_PRIVATE; }; /** * A manager of 'nexthop-group' configurations. * * Create one of these via an sdk object prior to starting the agent main loop. * When your eos::agent_handler::on_initialized virtual function is called, the * manager is valid for use. */ class EOS_SDK_PUBLIC nexthop_group_mgr : public base_mgr<nexthop_group_handler, std::string> { public: virtual ~nexthop_group_mgr(); virtual void resync_init() = 0; virtual void resync_complete() = 0; /// Iterates over all the nexthop groups currently configured. virtual nexthop_group_iter_t nexthop_group_iter() const = 0; /** * Retrieves an existing nexthop_group_t by name, if it exists. * Otherwise this returns an empty `nexthop_group_t()` */ virtual nexthop_group_t nexthop_group(std::string const & nexthop_group_name) const = 0; /** * Returns the counter corresponding to the given nexthop group name and * entry, if it exists. * Otherwise this returns an empty 'nexthop_group_entry_counter_t()' * * Counters are reset whenever nexthop group entry configuration changes. */ virtual nexthop_group_entry_counter_t counter( std::string const & nexthop_group_name, uint16_t entry) const = 0; /// Returns true if a nexthop group with the given name has been configured. virtual bool exists(std::string const & nexthop_group_name) const = 0; /** * Returns whether or not the given nexthop group is active. * * Nexthop groups are active if the FIB has prefixes using this * group. Deleting an active nexthop group will cause all prefixes * that point to that nexthop group to blackhole their traffic. * * In order to hitlessly delete a nexthop group, first delete all * prefixes that point to it, wait for the nexthop group to no * longer be active (using * nexthop_group_handler::on_nexthop_group_active), and then delete * the nexthop group. */ virtual bool active(std::string const & nexthop_group_name) const = 0; /// Creates or updates a nexthop group. virtual void nexthop_group_set(nexthop_group_t const &) = 0; /// Removes the named nexthop group from the configuration if it exists virtual void nexthop_group_del(std::string const & nexthop_group_name) = 0; // Iterate over all successfully programmed nexthop groups. virtual programmed_nexthop_group_iter_t programmed_nexthop_group_iter() const = 0; // Returns the programmed nexthop group for a given nexthop group name. virtual nexthop_group_t programmed_nexthop_group(std::string const & nexthop_group_name) const = 0; protected: nexthop_group_mgr() EOS_SDK_PRIVATE; friend class nexthop_group_handler; private: EOS_SDK_DISALLOW_COPY_CTOR(nexthop_group_mgr); }; } // end namespace eos #include <eos/inline/nexthop_group.h> #endif // EOS_NEXTHOP_GROUP_H
37.781553
84
0.736477
b0a50fe59c90a69c6acc9bd907391f5e739cd340
355
h
C
netbsd/sys/arch/sbmips/include/pmap.h
MarginC/kame
2ef74fe29e4cca9b4a87a1d5041191a9e2e8be30
[ "BSD-3-Clause" ]
91
2015-01-05T15:18:31.000Z
2022-03-11T16:43:28.000Z
netbsd/sys/arch/sbmips/include/pmap.h
MarginC/kame
2ef74fe29e4cca9b4a87a1d5041191a9e2e8be30
[ "BSD-3-Clause" ]
1
2016-02-25T15:57:55.000Z
2016-02-25T16:01:02.000Z
netbsd/sys/arch/sbmips/include/pmap.h
MarginC/kame
2ef74fe29e4cca9b4a87a1d5041191a9e2e8be30
[ "BSD-3-Clause" ]
21
2015-02-07T08:23:07.000Z
2021-12-14T06:01:49.000Z
/* $NetBSD: pmap.h,v 1.1 2002/03/06 02:13:46 simonb Exp $ */ #include <mips/pmap.h> /* uncached accesses are bad; all accesses should be cached (and coherent) */ #undef PMAP_PAGEIDLEZERO #define PMAP_PAGEIDLEZERO(pa) (pmap_zero_page(pa), TRUE) int sbmips_cca_for_pa(paddr_t); #undef PMAP_CCA_FOR_PA #define PMAP_CCA_FOR_PA(pa) sbmips_cca_for_pa(pa)
27.307692
77
0.752113
61ea856742326e584f262124cd9bed8e2511d297
1,234
h
C
code/ToolBarRtf.h
omerdagan84/neomem
7d2f782bb37f1ab0ac6580d00672e114605afab7
[ "MIT" ]
1
2022-02-10T01:41:32.000Z
2022-02-10T01:41:32.000Z
code/ToolBarRtf.h
omerdagan84/neomem
7d2f782bb37f1ab0ac6580d00672e114605afab7
[ "MIT" ]
null
null
null
code/ToolBarRtf.h
omerdagan84/neomem
7d2f782bb37f1ab0ac6580d00672e114605afab7
[ "MIT" ]
null
null
null
// CToolBarRtf // This encapsulates the toolbar for the Text View. //----------------------------------------------------------------------------------------------------------------- #pragma once #include "ToolBarCtrlEx.h" #include "ColorButton.h" class CToolBarRtf : public CToolBarCtrlEx { DECLARE_DYNAMIC(CToolBarRtf) // Construction public: CToolBarRtf(); virtual ~CToolBarRtf(); // Operations public: // Public Attributes public: CComboBox m_cboFontName; CComboBox m_cboFontSize; CColorButton m_ctlForecolor; CColorButton m_ctlBackcolor; // Attributes protected: // CFont m_font; // Implementation protected: static int CALLBACK EnumFontFamExProc(ENUMLOGFONTEX *lpelfe, NEWTEXTMETRICEX *lpntme, int FontType, LPARAM lParam); // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CToolBarRtf) protected: //}}AFX_VIRTUAL // Generated message map functions protected: //{{AFX_MSG(CToolBarRtf) afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); //}}AFX_MSG afx_msg void OnSelectFont(); afx_msg void OnSelectSize(); afx_msg LRESULT OnSelEndOK(WPARAM wParam, LPARAM lParam); afx_msg LRESULT OnColorButtonClick(WPARAM wParam, LPARAM lParam); DECLARE_MESSAGE_MAP() };
19.28125
116
0.701783
52375ed7d80029ac0c81b607ef07efe61aaa93cd
508
h
C
swiftBAOS/swiftBAOS.h
hengel2810/swiftBAOS
f9ffe0ab2aee46d5c367896e418f2664fddddc47
[ "MIT" ]
null
null
null
swiftBAOS/swiftBAOS.h
hengel2810/swiftBAOS
f9ffe0ab2aee46d5c367896e418f2664fddddc47
[ "MIT" ]
null
null
null
swiftBAOS/swiftBAOS.h
hengel2810/swiftBAOS
f9ffe0ab2aee46d5c367896e418f2664fddddc47
[ "MIT" ]
null
null
null
// // swiftBAOS.h // swiftBAOS // // Created by Henrik Engelbrink on 09.12.15. // Copyright © 2015 Henrik Engelbrink. All rights reserved. // #import <UIKit/UIKit.h> //! Project version number for swiftBAOS. FOUNDATION_EXPORT double swiftBAOSVersionNumber; //! Project version string for swiftBAOS. FOUNDATION_EXPORT const unsigned char swiftBAOSVersionString[]; // In this header, you should import all the public headers of your framework using statements like #import <swiftBAOS/PublicHeader.h>
25.4
134
0.76378
76f70163de981a50490dc404e71ab368975506c2
633
c
C
FreeBSD/contrib/ntp/libntp/lib_strbuf.c
TigerBSD/FreeBSD-Custom-ThinkPad
3d092f261b362f73170871403397fc5d6b89d1dc
[ "0BSD" ]
4
2016-08-22T22:02:55.000Z
2017-03-04T22:56:44.000Z
FreeBSD/contrib/ntp/libntp/lib_strbuf.c
TigerBSD/FreeBSD-Custom-ThinkPad
3d092f261b362f73170871403397fc5d6b89d1dc
[ "0BSD" ]
21
2016-08-11T09:43:43.000Z
2017-01-29T12:52:56.000Z
FreeBSD/contrib/ntp/libntp/lib_strbuf.c
TigerBSD/TigerBSD
3d092f261b362f73170871403397fc5d6b89d1dc
[ "0BSD" ]
null
null
null
/* * lib_strbuf - library string storage */ #ifdef HAVE_CONFIG_H #include <config.h> #endif #include <isc/net.h> #include <isc/result.h> #include "ntp_fp.h" #include "ntp_stdlib.h" #include "lib_strbuf.h" /* * Storage declarations */ int debug; libbufstr lib_stringbuf[LIB_NUMBUF]; int lib_nextbuf; int ipv4_works; int ipv6_works; int lib_inited; /* * initialization routine. Might be needed if the code is ROMized. */ void init_lib(void) { if (lib_inited) return; ipv4_works = (ISC_R_SUCCESS == isc_net_probeipv4()); ipv6_works = (ISC_R_SUCCESS == isc_net_probeipv6()); init_systime(); lib_inited = TRUE; }
15.825
67
0.71406
a1f460bae6974e0f13e4904a9cdc3a83cdef3eda
12,746
h
C
src/I18Next.h
alexpezzi/i18next-ios
23f35feb120fa672f9382f1ac8654eb90839926b
[ "MIT" ]
26
2015-09-03T09:41:40.000Z
2021-08-22T14:27:05.000Z
src/I18Next.h
alexpezzi/i18next-ios
23f35feb120fa672f9382f1ac8654eb90839926b
[ "MIT" ]
3
2016-11-02T17:10:07.000Z
2021-01-01T19:42:31.000Z
src/I18Next.h
alexpezzi/i18next-ios
23f35feb120fa672f9382f1ac8654eb90839926b
[ "MIT" ]
9
2016-02-12T17:15:17.000Z
2021-03-24T12:00:29.000Z
// // I18Next.h // i18next // // Created by Jean Regisser on 28/10/13. // Copyright (c) 2013 PrePlay, Inc. All rights reserved. // #import <Foundation/Foundation.h> typedef enum { I18NextLangLoadTypeAll = 0, // Load current and unspecific (example: 'en-US' and 'en') I18NextLangLoadTypeCurrent, // Load current lang set I18NextLangLoadTypeUnspecific // Load unspecific lang (example: 'en') } I18NextLangLoadType; extern NSString* const kI18NextOptionLowercaseLang; extern NSString* const kI18NextOptionLangLoadType; extern NSString* const kI18NextOptionFallbackLang; extern NSString* const kI18NextOptionNamespace; extern NSString* const kI18NextOptionNamespaces; extern NSString* const kI18NextOptionDefaultNamespace; extern NSString* const kI18NextOptionFallbackToDefaultNamespace; extern NSString* const kI18NextOptionFallbackNamespaces; extern NSString* const kI18NextOptionFallbackOnNull; extern NSString* const kI18NextOptionReturnObjectTrees; extern NSString* const kI18NextOptionResourcesStore; extern NSString* const kI18NextOptionLoadFromLanguageBundles; extern NSString* const kI18NextOptionLoadFromLocalCache; extern NSString* const kI18NextOptionSynchronousLocalLoad; extern NSString* const kI18NextOptionUpdateLocalCache; extern NSString* const kI18NextOptionNamespaceSeparator; extern NSString* const kI18NextOptionKeySeparator; extern NSString* const kI18NextOptionInterpolationPrefix; extern NSString* const kI18NextOptionInterpolationSuffix; extern NSString* const kI18NextOptionReusePrefix; extern NSString* const kI18NextOptionReuseSuffix; extern NSString* const kI18NextOptionPluralSuffix; extern NSString* const kI18NextOptionLocalCachePath; extern NSString* const kI18NextOptionFilenameInLanguageBundles; extern NSString* const kI18NextOptionResourcesBaseURL; extern NSString* const kI18NextOptionResourcesGetPathTemplate; extern NSString* const kI18NextOptionDynamicLoad; extern NSString* const kI18NextNamespaceSeparator; extern NSString* const kI18NextDefaultNamespace; extern NSString* const kI18NextPluralSuffix; extern NSString* const kI18NextResourcesGetPathTemplate; extern NSString* const kI18NextTranslateOptionContext; extern NSString* const kI18NextTranslateOptionCount; extern NSString* const kI18NextTranslateOptionVariables; extern NSString* const kI18NextTranslateOptionDefaultValue; extern NSString* const kI18NextTranslateOptionSprintf; // The error domain for I18Next generated errors extern NSString * const I18NextErrorDomain; typedef enum { I18NextErrorLoadFailed = 1, I18NextErrorInvalidLangData = 2, I18NextErrorCacheReadFailed = 10, I18NextErrorCacheWriteFailed = 11 } I18NextError; extern NSString *const I18NextDetailedErrorsKey; // When multiple errors occur, they are stored in a composite error // Helper methods that end up using `t:options:` @protocol I18NextDynamicInterface <NSObject> @optional - (NSString*)t:(id)key; - (NSString*)t:(id)key defaultValue:(NSString*)defaultValue; - (NSString*)t:(id)key lang:(NSString*)lang; - (NSString*)t:(id)key lang:(NSString*)lang defaultValue:(NSString*)defaultValue; - (NSString*)t:(id)key count:(NSUInteger)count; - (NSString*)t:(id)key lang:(NSString*)lang count:(NSUInteger)count; - (NSString*)t:(id)key count:(NSUInteger)count defaultValue:(NSString*)defaultValue; - (NSString*)t:(id)key lang:(NSString*)lang count:(NSUInteger)count defaultValue:(NSString*)defaultValue; - (NSString*)t:(id)key context:(NSString*)context; - (NSString*)t:(id)key lang:(NSString*)lang context:(NSString*)context; - (NSString*)t:(id)key context:(NSString*)context count:(NSUInteger)count; - (NSString*)t:(id)key lang:(NSString*)lang context:(NSString*)context count:(NSUInteger)count; - (NSString*)t:(id)key context:(NSString*)context defaultValue:(NSString*)defaultValue; - (NSString*)t:(id)key lang:(NSString*)lang context:(NSString*)context defaultValue:(NSString*)defaultValue; - (NSString*)t:(id)key context:(NSString*)context count:(NSUInteger)count defaultValue:(NSString*)defaultValue; - (NSString*)t:(id)key lang:(NSString*)lang context:(NSString*)context count:(NSUInteger)count defaultValue:(NSString*)defaultValue; - (NSString*)t:(id)key variables:(NSDictionary*)variables; - (NSString*)t:(id)key lang:(NSString*)lang variables:(NSDictionary*)variables; - (NSString*)t:(id)key count:(NSUInteger)count variables:(NSDictionary*)variables; - (NSString*)t:(id)key lang:(NSString*)lang count:(NSUInteger)count variables:(NSDictionary*)variables; - (NSString*)t:(id)key variables:(NSDictionary*)variables defaultValue:(NSString*)defaultValue; - (NSString*)t:(id)key lang:(NSString*)lang variables:(NSDictionary*)variables defaultValue:(NSString*)defaultValue; - (NSString*)t:(id)key count:(NSUInteger)count variables:(NSDictionary*)variables defaultValue:(NSString*)defaultValue; - (NSString*)t:(id)key lang:(NSString*)lang count:(NSUInteger)count variables:(NSDictionary*)variables defaultValue:(NSString*)defaultValue; - (NSString*)t:(id)key context:(NSString*)context variables:(NSDictionary*)variables; - (NSString*)t:(id)key lang:(NSString*)lang context:(NSString*)context variables:(NSDictionary*)variables; - (NSString*)t:(id)key context:(NSString*)context count:(NSUInteger)count variables:(NSDictionary*)variables; - (NSString*)t:(id)key lang:(NSString*)lang context:(NSString*)context count:(NSUInteger)count variables:(NSDictionary*)variables; - (NSString*)t:(id)key context:(NSString*)context variables:(NSDictionary*)variables defaultValue:(NSString*)defaultValue; - (NSString*)t:(id)key lang:(NSString*)lang context:(NSString*)context variables:(NSDictionary*)variables defaultValue:(NSString*)defaultValue; - (NSString*)t:(id)key context:(NSString*)context count:(NSUInteger)count variables:(NSDictionary*)variables defaultValue:(NSString*)defaultValue; - (NSString*)t:(id)key lang:(NSString*)lang context:(NSString*)context count:(NSUInteger)count variables:(NSDictionary*)variables defaultValue:(NSString*)defaultValue; - (NSString*)t:(id)key namespace:(NSString*)ns; - (NSString*)t:(id)key lang:(NSString*)lang namespace:(NSString*)ns; - (NSString*)t:(id)key namespace:(NSString*)ns count:(NSUInteger)count; - (NSString*)t:(id)key lang:(NSString*)lang namespace:(NSString*)ns count:(NSUInteger)count; - (NSString*)t:(id)key namespace:(NSString*)ns defaultValue:(NSString*)defaultValue; - (NSString*)t:(id)key lang:(NSString*)lang namespace:(NSString*)ns defaultValue:(NSString*)defaultValue; - (NSString*)t:(id)key namespace:(NSString*)ns count:(NSUInteger)count defaultValue:(NSString*)defaultValue; - (NSString*)t:(id)key lang:(NSString*)lang namespace:(NSString*)ns count:(NSUInteger)count defaultValue:(NSString*)defaultValue; - (NSString*)t:(id)key namespace:(NSString*)ns context:(NSString*)context; - (NSString*)t:(id)key lang:(NSString*)lang namespace:(NSString*)ns context:(NSString*)context; - (NSString*)t:(id)key namespace:(NSString*)ns context:(NSString*)context count:(NSUInteger)count; - (NSString*)t:(id)key lang:(NSString*)lang namespace:(NSString*)ns context:(NSString*)context count:(NSUInteger)count; - (NSString*)t:(id)key namespace:(NSString*)ns context:(NSString*)context defaultValue:(NSString*)defaultValue; - (NSString*)t:(id)key lang:(NSString*)lang namespace:(NSString*)ns context:(NSString*)context defaultValue:(NSString*)defaultValue; - (NSString*)t:(id)key namespace:(NSString*)ns context:(NSString*)context count:(NSUInteger)count defaultValue:(NSString*)defaultValue; - (NSString*)t:(id)key lang:(NSString*)lang namespace:(NSString*)ns context:(NSString*)context count:(NSUInteger)count defaultValue:(NSString*)defaultValue; - (NSString*)t:(id)key namespace:(NSString*)ns variables:(NSDictionary*)variables; - (NSString*)t:(id)key lang:(NSString*)lang namespace:(NSString*)ns variables:(NSDictionary*)variables; - (NSString*)t:(id)key namespace:(NSString*)ns count:(NSUInteger)count variables:(NSDictionary*)variables; - (NSString*)t:(id)key lang:(NSString*)lang namespace:(NSString*)ns count:(NSUInteger)count variables:(NSDictionary*)variables; - (NSString*)t:(id)key namespace:(NSString*)ns variables:(NSDictionary*)variables defaultValue:(NSString*)defaultValue; - (NSString*)t:(id)key lang:(NSString*)lang namespace:(NSString*)ns variables:(NSDictionary*)variables defaultValue:(NSString*)defaultValue; - (NSString*)t:(id)key namespace:(NSString*)ns count:(NSUInteger)count variables:(NSDictionary*)variables defaultValue:(NSString*)defaultValue; - (NSString*)t:(id)key lang:(NSString*)lang namespace:(NSString*)ns count:(NSUInteger)count variables:(NSDictionary*)variables defaultValue:(NSString*)defaultValue; - (NSString*)t:(id)key namespace:(NSString*)ns context:(NSString*)context variables:(NSDictionary*)variables; - (NSString*)t:(id)key lang:(NSString*)lang namespace:(NSString*)ns context:(NSString*)context variables:(NSDictionary*)variables; - (NSString*)t:(id)key namespace:(NSString*)ns context:(NSString*)context count:(NSUInteger)count variables:(NSDictionary*)variables; - (NSString*)t:(id)key lang:(NSString*)lang namespace:(NSString*)ns context:(NSString*)context count:(NSUInteger)count variables:(NSDictionary*)variables; - (NSString*)t:(id)key namespace:(NSString*)ns context:(NSString*)context variables:(NSDictionary*)variables defaultValue:(NSString*)defaultValue; - (NSString*)t:(id)key lang:(NSString*)lang namespace:(NSString*)ns context:(NSString*)context variables:(NSDictionary*)variables defaultValue:(NSString*)defaultValue; - (NSString*)t:(id)key namespace:(NSString*)ns context:(NSString*)context count:(NSUInteger)count variables:(NSDictionary*)variables defaultValue:(NSString*)defaultValue; - (NSString*)t:(id)key lang:(NSString*)lang namespace:(NSString*)ns context:(NSString*)context count:(NSUInteger)count variables:(NSDictionary*)variables defaultValue:(NSString*)defaultValue; @end @class I18NextPlurals; @interface I18Next : NSObject<I18NextDynamicInterface> @property (nonatomic, copy) NSString* lang; @property (nonatomic, copy, readonly) NSDictionary* options; @property (nonatomic, strong) I18NextPlurals* plurals; + (instancetype)sharedInstance; + (void)setSharedInstance:(I18Next*)instance; + (NSString*)t:(id)key; - (void)loadWithOptions:(NSDictionary*)options completion:(void (^)(NSError* error))completionBlock; - (BOOL)exists:(NSString*)key; - (NSString*)tf:(id)key, ...; - (NSString*)t:(id)key options:(NSDictionary*)options; @end // Helper to deal with options @interface I18NextOptions : NSObject @property (nonatomic, copy) NSString* lang; @property (nonatomic, assign) BOOL lowercaseLang; @property (nonatomic, assign) I18NextLangLoadType langLoadType; @property (nonatomic, copy) NSString* fallbackLang; @property (nonatomic, copy) NSArray* namespaces; @property (nonatomic, copy) NSString* defaultNamespace; @property (nonatomic, assign) BOOL fallbackToDefaultNamespace; @property (nonatomic, copy) NSArray* fallbackNamespaces; @property (nonatomic, assign) BOOL fallbackOnNull; @property (nonatomic, assign) BOOL returnObjectTrees; @property (nonatomic, copy) NSDictionary* resourcesStore; @property (nonatomic, assign) BOOL loadFromLanguageBundles; @property (nonatomic, assign) BOOL loadFromLocalCache; @property (nonatomic, assign) BOOL synchronousLocalLoad; @property (nonatomic, assign) BOOL updateLocalCache; @property (nonatomic, copy) NSString* namespaceSeparator; @property (nonatomic, copy) NSString* keySeparator; @property (nonatomic, copy) NSString* interpolationPrefix; @property (nonatomic, copy) NSString* interpolationSuffix; @property (nonatomic, copy) NSString* reusePrefix; @property (nonatomic, copy) NSString* reuseSuffix; @property (nonatomic, copy) NSString* pluralSuffix; @property (nonatomic, copy) NSString* localCachePath; @property (nonatomic, copy) NSString* filenameInLanguageBundles; @property (nonatomic, strong) NSURL* resourcesBaseURL; @property (nonatomic, copy) NSString* resourcesGetPathTemplate; @property (nonatomic, assign) BOOL dynamicLoad; + (instancetype)optionsFromDict:(NSDictionary*)dict; - (void)setNamespace:(NSString*)ns; - (void)setFallbackNamespace:(NSString*)fallbackNS; - (NSDictionary*)asDictionary; @end #define I18NEXT(args) [[I18Next sharedInstance] t:args] #define I18NEXT_SPRINTF_ARGS(...) \ [I18NextSprintfArgs formatBlock:^(NSString* format) { \ return [I18NextSprintf sprintf:format, ##__VA_ARGS__]; \ }] @interface I18NextSprintfArgs : NSObject @property (nonatomic, copy) NSString* (^formatBlock)(NSString* format); + (instancetype)formatBlock:(NSString* (^)(NSString* format))formatBlock; @end @interface I18NextSprintf : NSObject + (NSString*)sprintf:(NSString*)format, ...; + (NSString*)vsprintf:(NSString*)format arguments:(va_list)argList; @end
52.669421
143
0.786835
9774d6e1e50549739acd363df7df9a16a4c9d86d
158
h
C
state_pattern/lib/Miles.h
deanagan/cpp-design-patterns
3657636aa0be9f48d518c4f5a9d84f9561df785c
[ "MIT" ]
1
2020-03-22T09:35:34.000Z
2020-03-22T09:35:34.000Z
state_pattern/lib/Miles.h
deanagan/cpp-design-patterns
3657636aa0be9f48d518c4f5a9d84f9561df785c
[ "MIT" ]
2
2020-02-19T20:08:28.000Z
2020-02-22T11:28:14.000Z
state_pattern/lib/Miles.h
deanagan/cpp-design-patterns
3657636aa0be9f48d518c4f5a9d84f9561df785c
[ "MIT" ]
null
null
null
#pragma once #include <string> namespace FrequentFlyers { struct Miles { int TotalAccumulatedMiles; std::string Level; }; }
10.533333
31
0.601266
ea5a94b4c5f4497eff9e2519ab08d4222eeeeee1
612
h
C
src/game/server/entities/base.h
teeworldsmods/teeworlds-dummycapture
f5c0561b42f9310848652b829d9eaef817f54714
[ "Zlib" ]
null
null
null
src/game/server/entities/base.h
teeworldsmods/teeworlds-dummycapture
f5c0561b42f9310848652b829d9eaef817f54714
[ "Zlib" ]
null
null
null
src/game/server/entities/base.h
teeworldsmods/teeworlds-dummycapture
f5c0561b42f9310848652b829d9eaef817f54714
[ "Zlib" ]
null
null
null
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ /* If you miss that file, contact Pikotee, because he changed some stuff here ... */ /* ... and would like to be mentioned in credits in case of using his code */ #ifndef GAME_SERVER_ENTITIES_BASE_H #define GAME_SERVER_ENTITIES_BASE_H class CBase : public CEntity { public: CBase(CGameWorld *pGameWorld, vec2 Pos, int Type); virtual void Reset(); virtual void Tick(); virtual void Snap(int SnappingClient); private: int m_Type; float m_Score; float m_LastDistance; int64 m_MoveTicks; }; #endif
23.538462
95
0.735294
f67bed523b8673a554bd20d1ebcc5dbc2d817162
973
h
C
System/Library/PrivateFrameworks/TextInputCore.framework/TIUserModeling.h
lechium/iOS1351Headers
6bed3dada5ffc20366b27f7f2300a24a48a6284e
[ "MIT" ]
2
2021-11-02T09:23:27.000Z
2022-03-28T08:21:57.000Z
System/Library/PrivateFrameworks/TextInputCore.framework/TIUserModeling.h
lechium/iOS1351Headers
6bed3dada5ffc20366b27f7f2300a24a48a6284e
[ "MIT" ]
null
null
null
System/Library/PrivateFrameworks/TextInputCore.framework/TIUserModeling.h
lechium/iOS1351Headers
6bed3dada5ffc20366b27f7f2300a24a48a6284e
[ "MIT" ]
1
2022-03-28T08:21:59.000Z
2022-03-28T08:21:59.000Z
/* * This header is generated by classdump-dyld 1.5 * on Wednesday, October 27, 2021 at 3:18:07 PM Mountain Standard Time * Operating System: Version 13.5.1 (Build 17F80) * Image Source: /System/Library/PrivateFrameworks/TextInputCore.framework/TextInputCore * classdump-dyld is licensed under GPLv3, Copyright © 2013-2016 by Elias Limneos. Updated by Kevin Bradley. */ @class NSArray; @protocol TIUserModeling <TITypingSessionAggregatedEventObserver> @property (nonatomic,readonly) NSArray * keys; @required -(NSArray *)keys; -(id)valuesForKey:(id)arg1; -(void)addToDurableCounter:(int)arg1 forKey:(id)arg2; -(void)addToTransientCounter:(int)arg1 forKey:(id)arg2 andCandidateLength:(int)arg3 andContext:(id)arg4; -(void)addNumberToTransientCounter:(id)arg1 forKey:(id)arg2 andCandidateLength:(int)arg3 andContext:(id)arg4; @end
42.304348
130
0.673176
4c0f8585abdc36ff401afde822895bd38713a76a
10,912
c
C
firmware/bootloader/sdboot.c
gregdavill/boson-sd-firmware
8475e67bb3f735328a679924bceb8e3ae1cf676f
[ "BSD-2-Clause" ]
1
2021-11-29T17:19:41.000Z
2021-11-29T17:19:41.000Z
firmware/bootloader/sdboot.c
gregdavill/boson-sd-firmware
8475e67bb3f735328a679924bceb8e3ae1cf676f
[ "BSD-2-Clause" ]
2
2021-11-08T22:02:19.000Z
2021-11-08T22:06:06.000Z
firmware/bootloader/sdboot.c
gregdavill/boson-sd-firmware
8475e67bb3f735328a679924bceb8e3ae1cf676f
[ "BSD-2-Clause" ]
null
null
null
// This file is Copyright (c) 2014-2021 Florent Kermarrec <florent@enjoy-digital.fr> // This file is Copyright (c) 2013-2014 Sebastien Bourdeauducq <sb@m-labs.hk> // This file is Copyright (c) 2018 Ewen McNeill <ewen@naos.co.nz> // This file is Copyright (c) 2018 Felix Held <felix-github@felixheld.de> // This file is Copyright (c) 2019 Gabriel L. Somlo <gsomlo@gmail.com> // This file is Copyright (c) 2017 Tim 'mithro' Ansell <mithro@mithis.com> // This file is Copyright (c) 2018 William D. Jones <thor0505@comcast.net> // This file is Copyright (c) 2021 Greg Davill <greg.davill@gmail.com> // License: BSD #include "sdboot.h" #include <generated/csr.h> #include <generated/mem.h> #include <generated/soc.h> #include <irq.h> #include <libbase/crc.h> #include <libbase/jsmn.h> #include <libbase/uart.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <system.h> #include "ff.h" #include "flash.h" #include "logger.h" #include "sdcard.h" /* Quick initial check to make sure binaries are actually for us */ #define MAGIC_MAIN 0xb5d930e9 #define MAGIC_BOOT 0x5d9ce906 /*-----------------------------------------------------------------------*/ /* Helpers */ /*-----------------------------------------------------------------------*/ #define max(x, y) (((x) > (y)) ? (x) : (y)) #define min(x, y) (((x) < (y)) ? (x) : (y)) void dump_bytes(unsigned int *ptr, int count, unsigned long addr); void copy_file_from_ram_to_flash(uint32_t src_addr, uint32_t dst_addr, uint32_t dst_len); static const char *put_rc(FRESULT rc) { const char *p; static const char str[] = "OK\0DISK_ERR\0INT_ERR\0NOT_READY\0NO_FILE\0NO_PATH\0INVALID_NAME\0" "DENIED\0EXIST\0INVALID_OBJECT\0WRITE_PROTECTED\0INVALID_DRIVE\0" "NOT_ENABLED\0NO_FILE_SYSTEM\0MKFS_ABORTED\0TIMEOUT\0LOCKED\0" "NOT_ENOUGH_CORE\0TOO_MANY_OPEN_FILES\0FR_INVALID_PARAMETER\0"; FRESULT i; for (p = str, i = 0; i != rc && *p; i++) { while (*p++) ; } return p; } #define FATFS_ERR(EXP) \ do { \ FRESULT rc; \ if ((rc = EXP) != FR_OK) { \ log_printf("FatFs: Error: \"" #EXP "\": FRESULT=%s", put_rc(rc)); \ } \ } while (0); #define NUMBER_OF_BYTES_ON_A_LINE 16 void dump_bytes(unsigned int *ptr, int count, unsigned long addr) { char *data = (char *)ptr; int line_bytes = 0, i = 0; fputs("Memory dump:", stdout); while (count > 0) { line_bytes = (count > NUMBER_OF_BYTES_ON_A_LINE) ? NUMBER_OF_BYTES_ON_A_LINE : count; printf("\n0x%08lx ", addr); for (i = 0; i < line_bytes; i++) printf("%02x ", *(unsigned char *)(data + i)); for (; i < NUMBER_OF_BYTES_ON_A_LINE; i++) printf(" "); printf(" "); for (i = 0; i < line_bytes; i++) { if ((*(data + i) < 0x20) || (*(data + i) > 0x7e)) printf("."); else printf("%c", *(data + i)); } for (; i < NUMBER_OF_BYTES_ON_A_LINE; i++) printf(" "); data += (char)line_bytes; count -= line_bytes; addr += line_bytes; } printf("\n"); } /*-----------------------------------------------------------------------*/ /* Boot */ /*-----------------------------------------------------------------------*/ void copy_file_from_ram_to_flash(uint32_t src_addr, uint32_t dst_addr, uint32_t dst_len) { log_printf("Boot: Copying 0x%08lx to flash_addr=0x%08lx (%ld bytes)", src_addr, dst_addr, dst_len); spiflash_set_high_perf_mode(); uint8_t *data = (uint8_t *)src_addr; for (uint32_t addr = dst_addr; addr < dst_addr + dst_len; addr += 0x10000) { uint32_t len = addr + 0x10000 > (dst_addr + dst_len) ? (((dst_addr + dst_len) - addr) + 0xFF) & ~0xFF : 0x10000; uint32_t flash_address = addr; log_printf("Boot: Programming: addr=%08lx, len=%08lx", addr, len); /* First block in 64K erase block */ spiflash_write_enable(); spiflash_sector_erase(flash_address); /* While FLASH erase is in progress update LEDs */ while (spiflash_read_status_register() & 1) { } for (int i = 0; i < len / 256; i++) { spiflash_write_enable(); spiflash_page_program(flash_address, data, 256); flash_address += 256; data += 256; /* While FLASH erase is in progress update LEDs */ while (spiflash_read_status_register() & 1) { } } } log_printf("Boot: FLASH loading complete"); } /*-----------------------------------------------------------------------*/ /* SDCard Boot */ /*-----------------------------------------------------------------------*/ #if defined(CSR_SPISDCARD_BASE) || defined(CSR_SDCORE_BASE) static uint32_t copy_file_from_sdcard_to_ram(const char *filename, unsigned long ram_address, uint32_t magic_check) { FRESULT fr; FATFS fs; FIL file; uint32_t br; uint32_t offset; unsigned long length; uint32_t crc_supplied; uint32_t crc_check; uint32_t magic_supplied; FATFS_ERR(fr = f_mount(&fs, "", 1)); if (fr != FR_OK) { return 0; } FATFS_ERR(fr = f_open(&file, filename, FA_READ)); if (fr != FR_OK) { log_printf("Boot: %s file not found", filename); FATFS_ERR(f_unmount("")); return 0; } length = f_size(&file); log_printf("Boot: Copy %s to 0x%08lx (%lu bytes)", filename, ram_address, length); offset = 0; for (;;) { FATFS_ERR(fr = f_read(&file, (void *)ram_address + offset, 0x8000, (UINT *)&br)); if (fr != FR_OK) { log_printf("Boot: File read error"); FATFS_ERR(f_close(&file)); FATFS_ERR(f_unmount("")); return 0; } if (br == 0) break; offset += br; } FATFS_ERR(f_close(&file)); FATFS_ERR(f_unmount("")); memcpy((void *)&crc_supplied, (void *)ram_address + 4, 4); memcpy((void *)&magic_supplied, (void *)ram_address, 4); log_printf("Boot: Check %s: len=%lu bytes, crc=%08lx", filename, length, crc_supplied); /* magic check */ if (magic_supplied == magic_check) { log_printf("Boot: Magic word passed, image is likely for us"); } else { log_printf("Boot: Error: Magic word failed, image not likely for us. magic_file=0x%08lx, magic=0x%08lx", magic_supplied, magic_check); return 0; } /* CRC32 check */ crc_check = crc32((void *)(ram_address + 8), length - 8); if (crc_check == crc_supplied) { log_printf("Boot: crc passed"); } else { log_printf("Boot: crc fail, crc_supplied=0x%08lx, crc_check=0x%08lx", crc_supplied, crc_check); return 0; } return length; } static void sdcardboot_from_bin(const char *filename) { /* Copy Image from SDCard to address */ uint32_t addr = 0x80000; log_printf("Boot: Loading %s @0x%08lx", filename, addr); uint32_t length = copy_file_from_sdcard_to_ram(filename, HYPERRAM_BASE, MAGIC_MAIN); if (length == 0) return; /* Check if firmware matches FLASH? */ if (memcmp((void *)HYPERRAM_BASE, (void *)SPIFLASH_BASE + addr, length) == 0) { log_printf("Boot: %s already matches FLASH", filename); return; } copy_file_from_ram_to_flash(HYPERRAM_BASE, addr, length); if (length == 0) return; } static void sdcardboot_from_json(const char *filename) { FRESULT fr; FATFS fs; FIL file; uint8_t i; uint8_t count; uint32_t length; /* FIXME: modify/increase if too limiting */ char json_buffer[1024]; char json_name[32]; char json_value[32]; /* Read JSON file */ FATFS_ERR(fr = f_mount(&fs, "", 1)); if (fr != FR_OK) return; FATFS_ERR(fr = f_open(&file, filename, FA_READ)); if (fr != FR_OK) { log_printf("Boot: %s file not found", filename); FATFS_ERR(f_unmount("")); return; } FATFS_ERR(fr = f_read(&file, json_buffer, sizeof(json_buffer), (UINT *)&length)); /* Close JSON file */ FATFS_ERR(f_close(&file)); FATFS_ERR(f_unmount("0:")); /* Parse JSON file */ jsmntok_t t[32]; jsmn_parser p; jsmn_init(&p); count = jsmn_parse(&p, json_buffer, strlen(json_buffer), t, sizeof(t) / sizeof(*t)); for (i = 0; i < count - 1; i++) { memset(json_name, 0, sizeof(json_name)); memset(json_value, 0, sizeof(json_value)); /* Elements are JSON strings with 1 children */ if ((t[i].type == JSMN_STRING) && (t[i].size == 1)) { /* Get Element's filename */ memcpy(json_name, json_buffer + t[i].start, t[i].end - t[i].start); /* Get Element's address */ memcpy(json_value, json_buffer + t[i + 1].start, t[i + 1].end - t[i + 1].start); /* Unlock bootloader sectors */ if (strncmp(json_name, "bootloader_protection", 21) == 0) { if (strncmp(json_value, "disable", 7) == 0) { spiflash_protection_clear(); log_printf("Boot: Warning: Bootloader sectors unprotected"); } } else { /* Copy Image from SDCard to address */ uint32_t addr = strtoul(json_value, NULL, 0); log_printf("Boot: Loading %s @0x%08lx", json_name, addr); uint32_t length = copy_file_from_sdcard_to_ram(json_name, HYPERRAM_BASE, (addr == 0) ? MAGIC_BOOT : MAGIC_MAIN); if (length == 0) continue; /* Check if firmware matches FLASH? */ if (memcmp((void *)HYPERRAM_BASE, (void *)SPIFLASH_BASE + addr, length) == 0) { log_printf("Boot: %s already matches FLASH", json_name); continue; } copy_file_from_ram_to_flash(HYPERRAM_BASE, addr, length); } } } } void sdcardboot(void) { log_printf("Boot: Using SDCard in SD-Mode"); /* Boot from boson_sd_main.bin */ log_printf("Boot: Checking boson_sd_main.bin"); sdcardboot_from_bin("boson_sd_main.bin"); /* Boot from boot.json */ log_printf("Boot: Checking boot.json"); sdcardboot_from_json("boot.json"); log_printf("SDCard: Go IDLE"); sdcard_go_idle(); busy_wait(20); } #endif
33.783282
142
0.543255
7b8dfea5c9289fb4f5faf746057b89bea678a3c4
1,003
c
C
libft/ft_lstadd.c
alexeyvilmost/ft_printf
cc05b0b0d9b18ed7a99c56686d2657fe2f8ceaac
[ "MIT" ]
null
null
null
libft/ft_lstadd.c
alexeyvilmost/ft_printf
cc05b0b0d9b18ed7a99c56686d2657fe2f8ceaac
[ "MIT" ]
null
null
null
libft/ft_lstadd.c
alexeyvilmost/ft_printf
cc05b0b0d9b18ed7a99c56686d2657fe2f8ceaac
[ "MIT" ]
null
null
null
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_lstadd.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: pallspic <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/13 21:59:49 by pallspic #+# #+# */ /* Updated: 2019/08/26 02:25:12 by pallspic ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" void ft_lstadd(t_list **alst, t_list *new) { new->next = *alst; *alst = new; return ; }
47.761905
80
0.162512
568bc4b0e4c4bbeb84e0d6ba3eb47a4ee42f964e
1,315
h
C
av/drm/mediadrm/plugins/clearkey/CryptoFactory.h
Keneral/aframeworks
af1d0010bfb88751837fb1afc355705bd8a9ad8b
[ "Unlicense" ]
null
null
null
av/drm/mediadrm/plugins/clearkey/CryptoFactory.h
Keneral/aframeworks
af1d0010bfb88751837fb1afc355705bd8a9ad8b
[ "Unlicense" ]
null
null
null
av/drm/mediadrm/plugins/clearkey/CryptoFactory.h
Keneral/aframeworks
af1d0010bfb88751837fb1afc355705bd8a9ad8b
[ "Unlicense" ]
2
2021-07-08T07:42:11.000Z
2021-07-09T21:56:10.000Z
/* * Copyright (C) 2014 The Android Open Source Project * * 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. */ #ifndef CLEARKEY_CRYPTO_FACTORY_H_ #define CLEARKEY_CRYPTO_FACTORY_H_ #include <media/hardware/CryptoAPI.h> #include <media/stagefright/foundation/ABase.h> #include <utils/Errors.h> namespace clearkeydrm { class CryptoFactory : public android::CryptoFactory { public: CryptoFactory() {} virtual ~CryptoFactory() {} virtual bool isCryptoSchemeSupported(const uint8_t uuid[16]) const; virtual android::status_t createPlugin( const uint8_t uuid[16], const void* data, size_t size, android::CryptoPlugin** plugin); private: DISALLOW_EVIL_CONSTRUCTORS(CryptoFactory); }; } // namespace clearkeydrm #endif // CLEARKEY_CRYPTO_FACTORY_H_
29.222222
75
0.734601
4c310390b3ed454b7819c1a260107a1cd7157c8b
3,135
c
C
usr/src/uts/common/syscall/sigaltstack.c
AsahiOS/gate
283d47da4e17a5871d9d575e7ffb81e8f6c52e51
[ "MIT" ]
null
null
null
usr/src/uts/common/syscall/sigaltstack.c
AsahiOS/gate
283d47da4e17a5871d9d575e7ffb81e8f6c52e51
[ "MIT" ]
null
null
null
usr/src/uts/common/syscall/sigaltstack.c
AsahiOS/gate
283d47da4e17a5871d9d575e7ffb81e8f6c52e51
[ "MIT" ]
1
2020-12-30T00:04:16.000Z
2020-12-30T00:04:16.000Z
/* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright 2004 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ #pragma ident "%Z%%M% %I% %E% SMI" #include <sys/param.h> #include <sys/types.h> #include <sys/sysmacros.h> #include <sys/systm.h> #include <sys/errno.h> #include <sys/proc.h> #include <sys/fault.h> #include <sys/signal.h> #include <sys/siginfo.h> #include <sys/debug.h> int sigaltstack(struct sigaltstack *ssp, struct sigaltstack *oss) { klwp_t *lwp = ttolwp(curthread); struct sigaltstack ss; /* * User's oss and ss might be the same address, so copyin first and * save before copying out. */ if (ssp) { if (lwp->lwp_sigaltstack.ss_flags & SS_ONSTACK) return (set_errno(EPERM)); if (copyin(ssp, &ss, sizeof (ss))) return (set_errno(EFAULT)); if (ss.ss_flags & ~SS_DISABLE) return (set_errno(EINVAL)); if (!(ss.ss_flags & SS_DISABLE) && ss.ss_size < MINSIGSTKSZ) return (set_errno(ENOMEM)); } if (oss) { if (copyout(&lwp->lwp_sigaltstack, oss, sizeof (struct sigaltstack))) return (set_errno(EFAULT)); } if (ssp) lwp->lwp_sigaltstack = ss; return (0); } #ifdef _LP64 int sigaltstack32(struct sigaltstack32 *ssp, struct sigaltstack32 *oss) { klwp_t *lwp = ttolwp(curthread); struct sigaltstack *ss; struct sigaltstack32 ss32, oss32; /* * User's oss and ss might be the same address, so copyin first and * save before copying out. */ if (ssp) { if (lwp->lwp_sigaltstack.ss_flags & SS_ONSTACK) return (set_errno(EPERM)); if (copyin(ssp, &ss32, sizeof (ss32))) return (set_errno(EFAULT)); if (ss32.ss_flags & ~SS_DISABLE) return (set_errno(EINVAL)); if (!(ss32.ss_flags & SS_DISABLE) && ss32.ss_size < MINSIGSTKSZ) return (set_errno(ENOMEM)); } if (oss) { /* * copy to ILP32 struct before copyout. */ ss = &lwp->lwp_sigaltstack; oss32.ss_sp = (caddr32_t)(uintptr_t)ss->ss_sp; oss32.ss_size = (size32_t)ss->ss_size; oss32.ss_flags = ss->ss_flags; if (copyout(&oss32, oss, sizeof (oss32))) return (set_errno(EFAULT)); } if (ssp) { ss = &lwp->lwp_sigaltstack; ss->ss_sp = (void *)(uintptr_t)ss32.ss_sp; ss->ss_size = (size_t)ss32.ss_size; ss->ss_flags = ss32.ss_flags; } return (0); } #endif /* _LP64 */
25.696721
70
0.685805
1efef0b981edff906ffeca4bd09a91ee57862e7b
3,051
c
C
learn/shader.c
tangs/learn_glfw
d8381656b89e8e186a94a21e16614f8029a39098
[ "Zlib" ]
null
null
null
learn/shader.c
tangs/learn_glfw
d8381656b89e8e186a94a21e16614f8029a39098
[ "Zlib" ]
null
null
null
learn/shader.c
tangs/learn_glfw
d8381656b89e8e186a94a21e16614f8029a39098
[ "Zlib" ]
null
null
null
// // Created by tangs on 2020/9/3. // #include "shader.h" #include <stdio.h> #include <string.h> #include "utils.h" enum ErrType { COMPILE, LINK, }; static int check_errors(unsigned int shader, enum ErrType type) { int success; char info_log[1024]; if (type == COMPILE) { glGetShaderiv(shader, GL_COMPILE_STATUS, &success); if (!success) { glGetShaderInfoLog(shader, sizeof(info_log), NULL, info_log); fprintf(stderr, "ERROR::SHADER_COMPILATION_ERROR of type: %d\n%s\n", type, info_log); } } else { glGetProgramiv(shader, GL_LINK_STATUS, &success); if (!success) { glGetProgramInfoLog(shader, sizeof(info_log), NULL, info_log); fprintf(stderr, "ERROR::PROGRAM_LINKING_ERROR of type %d\n%s\n", type, info_log); } } return success; } static GLuint compile_shader(const char *path, GLenum type) { char tmp[1024]; int ret_code = read_file(path, tmp, sizeof(tmp)); if (ret_code) { return 0; } const char* str = tmp; GLuint shader = glCreateShader(type); glShaderSource(shader, 1, &str, NULL); glCompileShader(shader); if (!check_errors(shader, COMPILE)) { return 0; } return shader; } int shader_init(struct Shader* shader, const char *vertex_path, const char *fragment_path) { memset(shader, 0, sizeof(struct Shader)); GLuint vertex_shader = compile_shader(vertex_path, GL_VERTEX_SHADER); if (!vertex_shader) { return 1; } GLuint frag_shader = compile_shader(fragment_path, GL_FRAGMENT_SHADER); if (!frag_shader) { return 2; } GLuint id = glCreateProgram(); glAttachShader(id, vertex_shader); glAttachShader(id, frag_shader); glLinkProgram(id); glDeleteShader(vertex_shader); glDeleteShader(frag_shader); if (!check_errors(id, LINK)) { return 3; } shader->id = id; return 0; } void shader_delete(struct Shader shader) { glDeleteShader(shader.id); } void shader_use(struct Shader shader) { glUseProgram(shader.id); } void shader_set_bool(struct Shader shader, const char *name, bool value) { glUniform1i(glGetUniformLocation(shader.id, name), value); } void shader_set_int(struct Shader shader, const char *name, int value) { glUniform1i(glGetUniformLocation(shader.id, name), value); } void shader_set_float(struct Shader shader, const char *name, float value) { glUniform1f(glGetUniformLocation(shader.id, name), value); } void shader_set_vec3(struct Shader shader, const char *name, vec3 value) { glUniform3f(glGetUniformLocation(shader.id, name), value[0], value[1], value[2]); } void shader_set_vec4(struct Shader shader, const char *name, vec4 value) { glUniform4f(glGetUniformLocation(shader.id, name), value[0], value[1], value[2], value[3]); } void shader_set_matrix(struct Shader shader, const char *name, mat4 value) { glUniformMatrix4fv(glGetUniformLocation(shader.id, name), 1, GL_FALSE, (const GLfloat*)value); }
28.514019
98
0.675188
290c1e486d92bb370404cbbd9dff96370a63e1f8
1,837
h
C
devtag-allinone.h
alpsayin/uhx1_programmer
23949d0a60131d6fef9c06770b2c874b43061c56
[ "MIT" ]
2
2021-07-02T19:34:00.000Z
2021-08-31T17:26:22.000Z
Headers/devtag-allinone.h
alpsayin/radiotftp
edc9e55863f02ae97e13e6bad61d46a036f5b052
[ "MIT" ]
null
null
null
Headers/devtag-allinone.h
alpsayin/radiotftp
edc9e55863f02ae97e13e6bad61d46a036f5b052
[ "MIT" ]
null
null
null
#ifndef DEVTAG_H #define DEVTAG_H #include <sys/types.h> /* * Lookup 'devtag' among the predefined device selections. * If a matching device is found return the name of this device in buf. * * If 'devtag' is prefixed with "/dev/" then the result is also * prefixed with "/dev/". * * Returns number of devices found or a negative value if an error occured. */ int devtag_lookup(char *buf, size_t bufsize, const char *devtag); /* also returns a constant name if supplied in the configuration */ int devtag_lookup2(char *buf, size_t bufsize, char *constbuf, size_t constsize, const char *devtag); /* * Simple lookup. * Returns a suitable replacement for devtag. * If no replacement can be determined a 'devtag' will be returned as a duplicated string. */ char *devtag_get(const char *devtag); #endif #ifndef LIBDEVTAG_H #define LIBDEVTAG_H #define LIBDEVTAG_VERSION "1.0.6" struct devname; struct devname_head { struct devname *head; }; struct devname { char *dev; char *devname; char *type; int pos; struct devname *next; }; struct devinfo; struct devinfo_head { struct devinfo *head; }; struct devinfo { const char *name; const char *value; struct devinfo *next; }; struct dev; struct dev_head { struct dev *head; }; struct dev { struct devinfo_head info; struct devname_head devnames; char *class; /* "usb", "pci" etc */ struct dev *next; }; /* * Find devices matching selections in list 'sel' (of type struct dev_info). * Put matching devices in result list 'result'. */ int devtag_dev_scan(struct dev_head *result, const struct devinfo_head *sel); /* * Find USB devices matching selections in list 'sel' (of type struct dev_info). * Put matching USB devices in result list 'result'. */ int devtag_usb_scan(struct dev_head *result, const struct devinfo_head *sel); #endif
22.13253
100
0.719652
29221fc465df21c8e2dec81a62703a137d339f88
1,527
c
C
examples/crate_client_connect.c
digikrit/crate-odbc
0ade0c2993e48b05372fbbb92b0a224835362772
[ "Apache-2.0" ]
null
null
null
examples/crate_client_connect.c
digikrit/crate-odbc
0ade0c2993e48b05372fbbb92b0a224835362772
[ "Apache-2.0" ]
null
null
null
examples/crate_client_connect.c
digikrit/crate-odbc
0ade0c2993e48b05372fbbb92b0a224835362772
[ "Apache-2.0" ]
null
null
null
#include <stdio.h> #include <string.h> #include <jansson.h> #include "crateclient.h" int main(void){ crate_client *client; json_t *root, *cols, *rows, *row_col_value; int i,j; const char *col; client = crate_connect("akhil-laptop.intranet.bizense.com", 4200); /*crate_sql(client, "CREATE TABLE IF NOT EXISTS locations(id string, date timestamp, description string, kind string, name string, position integer)"); crate_sql(client, "insert into locations (id, date, description, kind, name, position) values ('14','2013-09-12T21:43:59.000Z','Blagulon Kappa is the planet to which the police are native.','Planet','Blagulon Kappa',7)"); */ root = crate_sql(client, "select _id,* from locations"); if(root){ cols = json_object_get(root, "cols"); rows = json_object_get(root, "rows"); for(i=0;i<json_array_size(rows);i++){ fprintf(stdout, "------- row %d -------\n", i+1); for(j=0;j<json_array_size(cols);j++){ col = json_string_value(json_array_get(cols, j)); row_col_value = json_array_get(json_array_get(rows, i), j); switch(json_typeof(row_col_value)){ case JSON_STRING : fprintf(stdout, "col %s : %s\n", col, json_string_value(row_col_value)); break; case JSON_INTEGER : fprintf(stdout, "col %s : %d\n", col, json_integer_value(row_col_value)); break; case JSON_REAL : fprintf(stdout, "col %s : %f\n", col, json_real_value(row_col_value)); break; default : fprintf(stdout, "unknown col type %s\n", json_typeof(row_col_value)); } } } } }
37.243902
228
0.6778
ad41130257383873cbbe811da7f1ea105c44be7c
3,076
c
C
d/avatars/nienne/mysterydomain.c
gesslar/shadowgate
97ce5d33a2275bb75c0cf6556602564b7870bc77
[ "MIT" ]
13
2019-07-19T05:24:44.000Z
2021-11-18T04:08:19.000Z
d/avatars/nienne/mysterydomain.c
gesslar/shadowgate
97ce5d33a2275bb75c0cf6556602564b7870bc77
[ "MIT" ]
null
null
null
d/avatars/nienne/mysterydomain.c
gesslar/shadowgate
97ce5d33a2275bb75c0cf6556602564b7870bc77
[ "MIT" ]
13
2019-09-12T06:22:38.000Z
2022-01-31T01:15:12.000Z
#include <std.h> inherit OBJECT; void create() { ::create(); set_name("orb of mists"); set_id(({"orb","orb of mists"})); set_short("%^RESET%^%^CYAN%^Orb of %^BOLD%^%^BLACK%^M%^RESET%^i%^BOLD%^%^WHITE%^s%^RESET%^t%^BOLD%^%^BLACK%^s%^RESET%^"); set_long("%^RESET%^%^CYAN%^Set within a base of patterned %^BOLD%^%^BLACK%^s%^RESET%^i%^BOLD%^%^WHITE%^lv%^RESET%^e%^BOLD%^%^BLACK%^r " "%^RESET%^%^CYAN%^sits a sphere of glass, its flawless surface showing no scratches or marks. Within its depths swirl %^BLUE%^darkened " "mists%^CYAN%^, rising and falling independent of the motion of their cage, concealing unknown secrets within. Around the base have been " "etched a progression of images that show %^BOLD%^%^BLACK%^ravens %^RESET%^%^CYAN%^in flight, endlessly winging about its perimeter. As " "you watch, a faint %^MAGENTA%^aura %^CYAN%^seems to pulse forth from the orb itself, giving you a desire to simply abandon the trophy and " "begone from its presence.%^RESET%^"); set_lore("Tales tell of such talismans as this, in the possession of " "the very gods themselves. Each contains the power of a domain of " "influence, and is bound to the deity that controls that domain. The gods " "guard these jealously, with intense magics to ward them, including " "protections that would cause any mere mortal who finds them to stop at " "nothing to be rid of their presence. Generally the only ones who can " "bear to hold such an item are the gods themselves, or the chosen of the " "deity who possesses the domain in question. But, for some rare few mortals " "whose hearts are in true attunement, they may also take up such relics " "and in doing so, become something more than mortal themselves.\n\n" "This particular relic is known as the Orb of Mists, and is said to " "grant power over the domain of mystery.\n"); set_property("lore difficulty",45); set_weight(0); set_value(0); set_heart_beat(1); } void heart_beat(){ if(!userp(ETO)) return; if(!interactive(ETO)) return; if((string)ETO->query_name() != "sudelilah" && !avatarp(ETO)) { tell_object(ETO,"%^CYAN%^As you take up the orb, its roiling mists " "draw you inwards, offering a temptation of %^MAGENTA%^secrets " "%^CYAN%^revealed that could be yours and yours alone. Your mind longs " "for more, and your thoughts become clouded as you seek deeper and " "deeper into the foggy miasma that never quite uncovers what you know " "is only barely out of reach. You struggle to maintain your hold on reality..." "\n\n%^GREEN%^And then you gasp for air and return to your senses, realising " "that you have dropped the orb.%^RESET%^"); tell_room(EETO,"%^CYAN%^"+ETO->QCN+" takes up the orb and seems drawn " "to peer into its depths, eyes becoming distantly focussed. For long moments " +ETO->QS+" remains silent, lips moving soundlessly as "+ETO->QP+" features " "become strained. And then the orb tumbles from "+ETO->QP+" grasp, and " "suddenly "+ETO->QS+" is normal again!%^RESET%^",ETO); ETO->force_me("drop orb of mists"); } } int isMagic(){ return 8; }
54.928571
140
0.707412
bc1888fda0a3f96efe0030418f1d12607172b185
1,029
h
C
WFZoom/WildfireSDK/WFChatClient.framework/Headers/WFCCGroupMember.h
wildfirechat/ios-conference
909e0c306cd954638fd93f943047eaf545680a8d
[ "MIT" ]
2
2021-09-22T02:53:27.000Z
2021-11-27T12:10:41.000Z
WFZoom/WildfireSDK/WFChatClient.framework/Headers/WFCCGroupMember.h
wildfirechat/ios-conference
909e0c306cd954638fd93f943047eaf545680a8d
[ "MIT" ]
null
null
null
WFZoom/WildfireSDK/WFChatClient.framework/Headers/WFCCGroupMember.h
wildfirechat/ios-conference
909e0c306cd954638fd93f943047eaf545680a8d
[ "MIT" ]
3
2021-11-27T12:10:44.000Z
2021-12-10T01:54:07.000Z
// // WFCCGroupMember.h // WFChatClient // // Created by heavyrain on 2017/10/30. // Copyright © 2017年 WildFireChat. All rights reserved. // #import <Foundation/Foundation.h> /** 群成员类型 - Member_Type_Normal: 普通成员 - Member_Type_Manager: 管理员 - Member_Type_Owner: 群主 - Member_Type_Muted: 被禁言 - Member_Type_Deleted: 已删除成员,仅在群成员变动回调中存在。 - Member_Type_Allowed: 被允许发言 */ typedef NS_ENUM(NSInteger, WFCCGroupMemberType) { Member_Type_Normal = 0, Member_Type_Manager, Member_Type_Owner, Member_Type_Muted, Member_Type_Deleted, Member_Type_Allowed = 5 } ; /** 群成员信息 */ @interface WFCCGroupMember : NSObject /** 群ID */ @property(nonatomic, strong)NSString *groupId; /** 群成员ID */ @property(nonatomic, strong)NSString *memberId; /** 群昵称 */ @property(nonatomic, strong)NSString *alias; /** 群成员扩展信息 */ @property(nonatomic, strong)NSString *extra; /** 群成员类型 */ @property(nonatomic, assign)WFCCGroupMemberType type; /** 群成员加入时间戳 */ @property(nonatomic, assign)long long createTime; @end
15.590909
56
0.713314
5db571b9e4ae9796762ff342a00949a8e40e9058
403
h
C
Pods/PBHome/PBHome.framework/Headers/PBRouter.h
shanbozhu/PBNavigator
87277d779663e47d408ce23801098cb7b06c6812
[ "MIT" ]
null
null
null
Pods/PBHome/PBHome.framework/Headers/PBRouter.h
shanbozhu/PBNavigator
87277d779663e47d408ce23801098cb7b06c6812
[ "MIT" ]
null
null
null
Pods/PBHome/PBHome.framework/Headers/PBRouter.h
shanbozhu/PBNavigator
87277d779663e47d408ce23801098cb7b06c6812
[ "MIT" ]
null
null
null
// // PBRouter.h // PBMine // // Created by DaMaiIOS on 2017/11/30. // Copyright © 2017年 DaMaiIOS. All rights reserved. // #import <Foundation/Foundation.h> #import "UIViewController+PBRouter.h" @interface PBRouter : NSObject +(void)routerWithGoPageName:(NSString *)pageName andParas:(NSDictionary *)paras; +(void)routerWithBackPageName:(NSString *)pageName andParas:(NSDictionary *)paras; @end
22.388889
82
0.741935
a4168f8584a9b189ae4d67b69b5677f05f9b37df
1,389
h
C
src/monitor/cpu_core.h
pwnall/sanctum
ae0650c8d5048b968a6795db0fc152f81eb8480a
[ "MIT" ]
49
2016-02-04T22:02:17.000Z
2021-05-06T09:27:16.000Z
src/monitor/cpu_core.h
pwnall/sanctum
ae0650c8d5048b968a6795db0fc152f81eb8480a
[ "MIT" ]
2
2017-02-02T17:41:11.000Z
2019-07-11T08:26:03.000Z
src/monitor/cpu_core.h
pwnall/sanctum
ae0650c8d5048b968a6795db0fc152f81eb8480a
[ "MIT" ]
12
2016-08-16T03:22:16.000Z
2020-07-23T01:30:31.000Z
#if !defined(MONITOR_CPU_CORE_H_INCLUDED) #define MONITOR_CPU_CORE_H_INCLUDED #include "bare/base_types.h" #include "bare/cpu_context.h" #include "bare/phys_atomics.h" #include "public/api.h" namespace sanctum { namespace internal { using sanctum::api::enclave_id_t; using sanctum::api::thread_id_t; using sanctum::bare::atomic; using sanctum::bare::current_core; using sanctum::bare::phys_ptr; using sanctum::bare::size_t; using sanctum::bare::uintptr_t; struct thread_info_t; // Per-core accounting information. // // Most information is only modified on the core that it corresponds to, so we // don't need atomics or locking. The notable exception is the flushed_at // timestamp. struct core_info_t { enclave_id_t enclave_id; // 0 if the core isn't executing enclave code thread_id_t thread_id; // The DRAM backing the thread_info_t is guaranteed to be pinned // while the thread is executing on a core. phys_ptr<thread_info_t> thread; // The value of block_clock when this core's TLB was last flushed. // This is read on other cores, atomic<size_t> flushed_at; }; // Core costants. // // These values are computed during the boot process. Once computed, the values // never change. extern phys_ptr<core_info_t> g_core; extern size_t g_core_count; }; // namespace sanctum::internal }; // namespace sanctum #endif // !defined(MONITOR_CPU_CORE_H_INCLUDED)
26.711538
79
0.760259
51a46350000bfcd705cc13124895213b39844cda
2,930
h
C
include/il2cpp/System/Collections/Generic/Dictionary/KeyCollection_int__bool_.h
martmists-gh/BDSP
d6326c5d3ad9697ea65269ed47aa0b63abac2a0a
[ "MIT" ]
1
2022-01-15T20:20:27.000Z
2022-01-15T20:20:27.000Z
include/il2cpp/System/Collections/Generic/Dictionary/KeyCollection_int__bool_.h
martmists-gh/BDSP
d6326c5d3ad9697ea65269ed47aa0b63abac2a0a
[ "MIT" ]
null
null
null
include/il2cpp/System/Collections/Generic/Dictionary/KeyCollection_int__bool_.h
martmists-gh/BDSP
d6326c5d3ad9697ea65269ed47aa0b63abac2a0a
[ "MIT" ]
null
null
null
#pragma once #include "il2cpp.h" void System_Collections_Generic_Dictionary_KeyCollection_int__bool____ctor (System_Collections_Generic_Dictionary_KeyCollection_int__bool__o* __this, System_Collections_Generic_Dictionary_TKey__TValue__o* dictionary, const MethodInfo* method_info); System_Collections_Generic_Dictionary_KeyCollection_Enumerator_TKey__TValue__o System_Collections_Generic_Dictionary_KeyCollection_int__bool___GetEnumerator (System_Collections_Generic_Dictionary_KeyCollection_int__bool__o* __this, const MethodInfo* method_info); void System_Collections_Generic_Dictionary_KeyCollection_int__bool___CopyTo (System_Collections_Generic_Dictionary_KeyCollection_int__bool__o* __this, System_Int32_array* array, int32_t index, const MethodInfo* method_info); int32_t System_Collections_Generic_Dictionary_KeyCollection_int__bool___get_Count (System_Collections_Generic_Dictionary_KeyCollection_int__bool__o* __this, const MethodInfo* method_info); bool System_Collections_Generic_Dictionary_KeyCollection_int__bool___System_Collections_Generic_ICollection_TKey__get_IsReadOnly (System_Collections_Generic_Dictionary_KeyCollection_int__bool__o* __this, const MethodInfo* method_info); void System_Collections_Generic_Dictionary_KeyCollection_int__bool___System_Collections_Generic_ICollection_TKey__Add (System_Collections_Generic_Dictionary_KeyCollection_int__bool__o* __this, int32_t item, const MethodInfo* method_info); void System_Collections_Generic_Dictionary_KeyCollection_int__bool___System_Collections_Generic_ICollection_TKey__Clear (System_Collections_Generic_Dictionary_KeyCollection_int__bool__o* __this, const MethodInfo* method_info); bool System_Collections_Generic_Dictionary_KeyCollection_int__bool___System_Collections_Generic_ICollection_TKey__Contains (System_Collections_Generic_Dictionary_KeyCollection_int__bool__o* __this, int32_t item, const MethodInfo* method_info); bool System_Collections_Generic_Dictionary_KeyCollection_int__bool___System_Collections_Generic_ICollection_TKey__Remove (System_Collections_Generic_Dictionary_KeyCollection_int__bool__o* __this, int32_t item, const MethodInfo* method_info); System_Collections_Generic_IEnumerator_TKey__o* System_Collections_Generic_Dictionary_KeyCollection_int__bool___System_Collections_Generic_IEnumerable_TKey__GetEnumerator (System_Collections_Generic_Dictionary_KeyCollection_int__bool__o* __this, const MethodInfo* method_info); System_Collections_IEnumerator_o* System_Collections_Generic_Dictionary_KeyCollection_int__bool___System_Collections_IEnumerable_GetEnumerator (System_Collections_Generic_Dictionary_KeyCollection_int__bool__o* __this, const MethodInfo* method_info); void System_Collections_Generic_Dictionary_KeyCollection_int__bool___System_Collections_ICollection_CopyTo (System_Collections_Generic_Dictionary_KeyCollection_int__bool__o* __this, System_Array_o* array, int32_t index, const MethodInfo* method_info);
172.352941
277
0.933106
224c67ebe86a0addc278b5984344a67839810966
3,177
h
C
C++/DataStructures/LinkedList.h
mishrasunny174/DataStructuresAndAlgorithms
fe672a6558c53d128581b3a22973a70c5a541a28
[ "MIT" ]
3
2019-04-28T02:44:03.000Z
2020-04-12T14:14:12.000Z
C++/DataStructures/LinkedList.h
mishrasunny174/DataStructuresAndAlgorithms
fe672a6558c53d128581b3a22973a70c5a541a28
[ "MIT" ]
null
null
null
C++/DataStructures/LinkedList.h
mishrasunny174/DataStructuresAndAlgorithms
fe672a6558c53d128581b3a22973a70c5a541a28
[ "MIT" ]
1
2019-04-28T02:44:05.000Z
2019-04-28T02:44:05.000Z
#ifndef LINKED_LIST #define LINKED_LIST template <class T> class Node { private: T data; Node<T> *next; public: Node(T data=0, Node<T>* next=0) { this->data = data; this->next = next; } Node *getNext() { return this->next; } void setNext(Node *next) { this->next = next; } T getData() { return data; } }; template <class T> class LinkedList { private: Node<T> *head, *tail; int size; public: LinkedList() { head = tail = 0; size = 0; } ~LinkedList() { Node<T> *temp = head; while (head != 0) { head = head->getNext(); delete temp; temp = head; } } void pushAtHead(T data) { if (head == 0) { head = tail = new Node<T>(data); } else { head = new Node<T>(data, head); } size++; } void pushAtTail(T data) { if (tail == 0) { head = tail = new Node<T>(data); } else { Node<T> *temp = new Node<T>(data); tail->setNext(temp); tail = temp; } } T popFromHead() { if (head != 0) { T data = head->getData(); Node<T> *temp = head; if (head == tail) { head = tail = 0; } else { head = head->getNext(); } delete temp; return data; } } T popFromTail() { if (tail != 0) { T data = tail->getData(); if (head == tail) { delete head; head = tail = 0; } else { Node<T> *temp; for (temp = head; temp->getNext() != tail; temp = temp->getNext()) ; delete tail; tail = temp; } return data; } } void deleteNode(T data) { if (head == tail) { delete head; head = tail = 0; } else if (head->getData() == data) { Node<T> *temp = head; head = head->getNext(); delete temp; } else if (tail->getData() == data) { Node<T> *temp; for (temp = head; temp->getNext() != tail; temp = temp->getNext()) ; delete tail; tail = temp; } else { Node<T> *temp; for (temp = head->getNext(); temp->getNext()->getData() != data && temp != tail; temp = temp->getNext()) ; Node<T> *prev = temp; temp = temp->getNext(); prev->setNext(temp->getNext()); delete temp; } } }; #endif
19.611111
117
0.349701
2257d7f25fe473053a62c13417e5c82ec1125419
42,494
c
C
sdk-6.5.20/libs/sdklt/bcmfp/algorithms/bcmfp_compression_trie_mgmt.c
copslock/broadcom_cpri
8e2767676e26faae270cf485591902a4c50cf0c5
[ "Spencer-94" ]
null
null
null
sdk-6.5.20/libs/sdklt/bcmfp/algorithms/bcmfp_compression_trie_mgmt.c
copslock/broadcom_cpri
8e2767676e26faae270cf485591902a4c50cf0c5
[ "Spencer-94" ]
null
null
null
sdk-6.5.20/libs/sdklt/bcmfp/algorithms/bcmfp_compression_trie_mgmt.c
copslock/broadcom_cpri
8e2767676e26faae270cf485591902a4c50cf0c5
[ "Spencer-94" ]
null
null
null
/*! \file bcmfp_compression_trie_mgmt.c * * APIs to operate on compression id trie management. */ /* * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file. * * Copyright 2007-2020 Broadcom Inc. All rights reserved. */ #include <shr/shr_error.h> #include <sal/sal_alloc.h> #include <shr/shr_bitop.h> #include <bcmfp/bcmfp_trie_mgmt.h> #define BSL_LOG_MODULE BSL_LS_BCMFP_DEV /*! * \brief Compare prefix number of bits of in_node_key and curr_node_key * * \param [in] key1 Key 1 * \param [in] key2 Key 2 * \param [in] key1_pfx Prefix length for Key 1 * \param [in] key2_pfx Prefix length for Key 2 * \param [in] max_pfx Max prefix length for the trie * * \retval 1 If keys match on prefix bits * \retval 0 If keys don't match on prefix bits */ STATIC int bcmfp_compare_bits(SHR_BITDCL *key1, SHR_BITDCL *key2, uint32_t key1_pfx, uint32_t key2_pfx, uint8_t max_pfx) { if (key2_pfx < key1_pfx) { /* Always match with lower prefix length */ key1_pfx = key2_pfx; } return (SHR_BITEQ_RANGE(key1, key2, (max_pfx - key1_pfx), key1_pfx)); } /* * Insert current node under parent node * Assumes curr_node->prefix matches parent_node->prefix */ STATIC void bcmfp_compress_key_insert_child(bcmfp_shr_trie_md_t *trie, bcmfp_compress_key_t *curr_node, bcmfp_compress_key_t *parent_node) { bcmfp_compress_key_t *temp_node; int index; index = trie->max_prefix_mask - curr_node->prefix; if (parent_node->child[index]) { /* * If parent has existing child at curr_node->prefix * then curr_node will become a sibling to that child */ temp_node = parent_node->child[index]; while (temp_node->sibling) { temp_node = temp_node->sibling; } temp_node->sibling = curr_node; } else { parent_node->child[index] = curr_node; } parent_node->num_child++; } /* * Delete current node under parent node * Assumes curr_node->prefix matches parent_node->prefix */ STATIC void bcmfp_compress_key_delete_child(bcmfp_shr_trie_md_t *trie, bcmfp_compress_key_t *curr_node, bcmfp_compress_key_t *curr_node_prev_sib, bcmfp_compress_key_t *parent_node) { int index; index = trie->max_prefix_mask - curr_node->prefix; if (parent_node->child[index] == curr_node) { /* First child is curr_node */ parent_node->child[index] = curr_node->sibling; } else if ((curr_node->sibling == NULL) && (curr_node_prev_sib != NULL)) { /* Last child is curr_node */ curr_node_prev_sib->sibling = NULL; } else if (curr_node_prev_sib != NULL) { /* Mid child is deleted */ curr_node_prev_sib->sibling = curr_node->sibling; } curr_node->sibling = NULL; parent_node->num_child--; } STATIC int bcmfp_compress_key_node_alloc(int unit, bcmfp_basic_info_key_t *node_info, bcmfp_compress_key_t **node, bcmfp_shr_trie_md_t *trie) { int rv = SHR_E_MEMORY; if (trie->ckey_acquire) { rv = (trie->ckey_acquire(unit, trie->stage_id, trie->trie_type, node)); if (SHR_FAILURE(rv)) { return (rv); } } else { /* Allocate memory for new node */ BCMFP_COMP_ALLOC(*node, sizeof(bcmfp_compress_key_t), "bcmfpCompressionNode"); } (*node)->prefix = node_info->prefix; if (node_info->flags & BCMFP_TRIE_NODE_WIDTH_COMPRESSED) { (*node)->ref_count = node_info->ref_count; } else { (*node)->ref_count++; } if (node_info->flags) { (*node)->flags = node_info->flags; sal_memcpy(&(*node)->cid, &node_info->cid, sizeof(bcmfp_cid_t)); sal_memcpy(&(*node)->cid_mask, &node_info->cid_mask, sizeof(bcmfp_cid_t)); } if (node_info->prefix < trie->max_prefix_mask) { BCMFP_COMP_ALLOC((*node)->child, sizeof(bcmfp_compress_key_t *) * (trie->max_prefix_mask - node_info->prefix), "bcmfpCompressionNodeChildren"); } sal_memcpy(&(*node)->key, &node_info->key, sizeof(bcmfp_key_t)); rv = SHR_E_NONE; exit: return (rv); } STATIC void bcmfp_compress_key_node_free(int unit, bcmfp_compress_key_t *node, bcmfp_shr_trie_md_t *trie) { /* Free node */ if (node) { if (node->child) { BCMFP_COMP_FREE(node->child); } if (trie->ckey_release && node != trie->root) { (void)trie->ckey_release(unit, trie->stage_id, trie->trie_type, node); } else { BCMFP_COMP_FREE(node); } } } /*! * \brief This function is to be called after warmboot so that nodes/keys stored * in HA memory can be linked together appropriately to re-create the trie * This function will NOT reassign cid/cid_mask * * \param [in] unit Logical device id * \param [in] in_node Compress node to be inserted in trie * \param [in] trie Trie on which operation is to be performed * * \retval SHR_E_NONE Success * \retval SHR_E_INTERNAL */ int bcmfp_compress_key_recover(int unit, bcmfp_compress_key_t *in_node, bcmfp_shr_trie_md_t *trie) { int rv = SHR_E_PARAM, in_node_linked = 0, prefix, index; bcmfp_compress_key_t *parent_node; bcmfp_compress_key_t *curr_node, *curr_node_prev_sib; BCMFP_COMP_NULL_CHECK(trie); BCMFP_COMP_NULL_CHECK(trie->root); BCMFP_COMP_NULL_CHECK(in_node); if (in_node->prefix > trie->max_prefix_mask) { return (SHR_E_PARAM); } /* Alloc child pointer */ in_node->child = NULL; in_node->sibling = NULL; rv = SHR_E_MEMORY; if (in_node->prefix < trie->max_prefix_mask) { BCMFP_COMP_ALLOC(in_node->child, sizeof(bcmfp_compress_key_t *) * (trie->max_prefix_mask - in_node->prefix), "bcmfpCompressionNodeChildren"); } /* If node is list compressed */ if (in_node->flags & BCMFP_TRIE_NODE_LIST_COMPRESSED) { curr_node = trie->root; while (curr_node->sibling) { curr_node = curr_node->sibling; } curr_node->sibling = in_node; return (SHR_E_NONE); } /* Start with root node */ parent_node = trie->root; curr_node_prev_sib = NULL; /* Loop through all the prefix levels. Prefix 0 reserved for root */ for (prefix = 1; prefix <= trie->max_prefix_mask; prefix++) { index = trie->max_prefix_mask - prefix; curr_node = parent_node->child[index]; /* curr_node used as an iterator to find a match */ /* Loop through all nodes of the same prefix until a match is found */ while (curr_node != NULL) { rv = bcmfp_compare_bits(in_node->key.w, curr_node->key.w, in_node->prefix, curr_node->prefix, trie->max_prefix_mask); if (rv) { if (in_node->prefix < curr_node->prefix) { /* Current node sub-trie need to be moved under incoming node */ /* Unlink the current node from the parent node */ bcmfp_compress_key_delete_child(trie, curr_node, curr_node_prev_sib, parent_node); if (!in_node_linked) { /* Link the incoming node to the parent node as a child */ bcmfp_compress_key_insert_child(trie, in_node, parent_node); in_node_linked = 1; } /* Link the current node to incoming node as a child */ bcmfp_compress_key_insert_child(trie, curr_node, in_node); /* Loop through remaining nodes of curr_node->prefix */ if (curr_node_prev_sib == NULL) { curr_node = parent_node->child[index]; } else { curr_node = curr_node_prev_sib->sibling; } } else if (in_node->prefix > curr_node->prefix) { /* Incoming node need to be moved under sub-trie of current node */ /* Find correct place under sub-trie of current node */ parent_node = curr_node; curr_node = NULL; } else { /* Incoming key has same prefix as current nodes prefix * Duplicate nodes cannot be present in trie */ return (SHR_E_INTERNAL); } } else { /* No match with current node */ curr_node_prev_sib = curr_node; curr_node = curr_node->sibling; } } curr_node_prev_sib = NULL; } if (!in_node_linked) { /* Link incoming node to parent node */ bcmfp_compress_key_insert_child(trie, in_node, parent_node); } rv = SHR_E_NONE; exit: return (rv); } /*! * \brief Insert the new compression key info present in in_node to the trie. * * \param [in] unit Logical device id * \param [in] in_node_info New compress node info to be inserted * \param [in] trie Trie on which operation is to be performed * \param [in] user_data Data passed by caller application which will * be passed back to it if there are changes * in cid/cid_mask of existing keys in trie. * * \retval SHR_E_NONE Success * \retval SHR_E_RESOURCE Out of cid bits to assign */ int bcmfp_compress_key_insert(int unit, bcmfp_basic_info_key_t *in_node_info, bcmfp_shr_trie_md_t *trie, void *user_data) { int rv = SHR_E_PARAM, in_node_linked = 0, prefix, index; bcmfp_compress_key_t *parent_node, *in_node = NULL; bcmfp_compress_key_t *curr_node, *curr_node_prev_sib; bcmfp_basic_info_key_t node_info; BCMFP_COMP_NULL_CHECK(trie); BCMFP_COMP_NULL_CHECK(trie->root); BCMFP_COMP_NULL_CHECK(in_node_info); if (in_node_info->prefix > trie->max_prefix_mask) { return (SHR_E_PARAM); } if (in_node_info->prefix == 0) { /* Copy root cid/cid_mask to in_node_info */ trie->root->ref_count++; in_node_info->ref_count = trie->root->ref_count; in_node_info->flags = trie->root->flags; sal_memcpy(&in_node_info->cid, &trie->root->cid, sizeof(bcmfp_cid_t)); sal_memcpy(&in_node_info->cid_mask, &trie->root->cid_mask, sizeof(bcmfp_cid_t)); return (SHR_E_NONE); } if (in_node_info->flags & BCMFP_TRIE_NODE_LIST_COMPRESSED) { if (SHR_BITNULL_RANGE(in_node_info->cid.w, 0, trie->max_cid_mask) || SHR_BITNULL_RANGE(in_node_info->cid_mask.w, 0, trie->max_cid_mask)) { /* cid/cid_mask not valid for node to be list compressed */ return (SHR_E_PARAM); } } if (!(in_node_info->flags & BCMFP_TRIE_NODE_WIDTH_COMPRESSED)) { /* First search the list compressed nodes list */ curr_node_prev_sib = trie->root; /* List compressed node list present in root's sibling */ curr_node = trie->root->sibling; while (curr_node) { rv = bcmfp_compare_bits(in_node_info->key.w, curr_node->key.w, in_node_info->prefix, curr_node->prefix, trie->max_prefix_mask); if (rv) { if (in_node_info->prefix == curr_node->prefix) { if (in_node_info->flags & BCMFP_TRIE_NODE_LIST_COMPRESSED) { /* Same node */ curr_node->ref_count++; in_node_info->ref_count = curr_node->ref_count; return (SHR_E_NONE); } } sal_memset(&node_info, 0, sizeof(bcmfp_basic_info_key_t)); sal_memcpy(node_info.key.w, &curr_node->key, sizeof(bcmfp_key_t)); sal_memcpy(node_info.cid.w, &curr_node->cid, sizeof(bcmfp_cid_t)); sal_memcpy(node_info.cid_mask.w, &curr_node->cid_mask, sizeof(bcmfp_cid_t)); node_info.ref_count = curr_node->ref_count; node_info.prefix = curr_node->prefix; node_info.flags = BCMFP_TRIE_NODE_WIDTH_COMPRESSED; /* Unlink current node from list compressed nodes list */ curr_node_prev_sib->sibling = curr_node->sibling; /* Free current node */ bcmfp_compress_key_node_free(unit, curr_node, trie); curr_node = curr_node_prev_sib; /* Add current node in trie */ rv = bcmfp_compress_key_insert(unit, &node_info, trie, user_data); if (SHR_FAILURE(rv)) { if (rv == SHR_E_RESOURCE) { /* Add the node back in list compression list */ node_info.flags = BCMFP_TRIE_NODE_LIST_COMPRESSED; (void)(bcmfp_compress_key_insert(unit, &node_info, trie, user_data)); } return (rv); } if (!in_node_linked) { /* Add incoming node in trie */ in_node_info->flags = BCMFP_TRIE_NODE_WIDTH_COMPRESSED; in_node_info->ref_count = 1; sal_memset(in_node_info->cid.w, 0, sizeof(bcmfp_cid_t)); sal_memset(in_node_info->cid_mask.w, 0, sizeof(bcmfp_cid_t)); rv = (bcmfp_compress_key_insert(unit, in_node_info, trie, user_data)); if (SHR_FAILURE(rv)) { return (rv); } in_node_linked = 1; } } curr_node_prev_sib = curr_node; curr_node = curr_node->sibling; } } if (in_node_linked) { return (SHR_E_NONE); } rv = (bcmfp_compress_key_node_alloc(unit, in_node_info, &in_node, trie)); if (SHR_FAILURE(rv)) { return (rv); } /* Start with root node */ parent_node = trie->root; curr_node_prev_sib = NULL; /* Loop through all the prefix levels. Prefix 0 reserved for root */ for (prefix = 1; prefix <= trie->max_prefix_mask; prefix++) { index = trie->max_prefix_mask - prefix; curr_node = parent_node->child[index]; /* curr_node used as an iterator to find a match */ /* Loop through all nodes of the same prefix until a match is found */ while (curr_node != NULL) { rv = bcmfp_compare_bits(in_node_info->key.w, curr_node->key.w, in_node_info->prefix, curr_node->prefix, trie->max_prefix_mask); if (rv) { if (in_node_info->flags & BCMFP_TRIE_NODE_LIST_COMPRESSED) { /* Can't be list compressed */ in_node->flags &= ~BCMFP_TRIE_NODE_LIST_COMPRESSED; in_node_info->flags &= ~BCMFP_TRIE_NODE_LIST_COMPRESSED; sal_memset(in_node->cid.w, 0, sizeof(bcmfp_cid_t)); sal_memset(in_node_info->cid.w, 0, sizeof(bcmfp_cid_t)); } if (in_node_info->prefix < curr_node->prefix) { /* Current node sub-trie need to be moved under incoming node */ /* Unlink the current node from the parent node */ bcmfp_compress_key_delete_child(trie, curr_node, curr_node_prev_sib, parent_node); if (!in_node_linked) { /* Link the incoming node to the parent node as a child */ bcmfp_compress_key_insert_child(trie, in_node, parent_node); in_node_linked = 1; } /* Link the current node to incoming node as a child */ bcmfp_compress_key_insert_child(trie, curr_node, in_node); /* Loop through remaining nodes of curr_node->prefix */ if (curr_node_prev_sib == NULL) { curr_node = parent_node->child[index]; } else { curr_node = curr_node_prev_sib->sibling; } } else if (in_node_info->prefix > curr_node->prefix) { /* Incoming node need to be moved under sub-trie of current node */ /* Find correct place under sub-trie of current node */ parent_node = curr_node; curr_node = NULL; } else { /* Incoming key has same prefix as current nodes prefix */ /* Key is in use by multiple rules */ curr_node->ref_count++; in_node_info->ref_count = curr_node->ref_count; in_node_info->flags = curr_node->flags; /* Copy existing cid/cid_mask to in_node_info */ sal_memcpy(&in_node_info->cid, &curr_node->cid, sizeof(bcmfp_cid_t)); sal_memcpy(&in_node_info->cid_mask, &curr_node->cid_mask, sizeof(bcmfp_cid_t)); bcmfp_compress_key_node_free(unit, in_node, trie); in_node = NULL; return (SHR_E_NONE); } } else { /* No match with current node */ curr_node_prev_sib = curr_node; curr_node = curr_node->sibling; } } curr_node_prev_sib = NULL; } if (!in_node_linked) { if (in_node_info->flags & BCMFP_TRIE_NODE_LIST_COMPRESSED) { /* No match for incoming node in the list compressed nodes or in trie */ curr_node = trie->root; while (curr_node->sibling) { curr_node = curr_node->sibling; } curr_node->sibling = in_node; in_node_info->ref_count = in_node->ref_count; return (SHR_E_NONE); } else { /* Link incoming node to parent node */ bcmfp_compress_key_insert_child(trie, in_node, parent_node); } } /* Update CID/CID Mask */ rv = bcmfp_compress_id_update(unit, trie, parent_node, user_data); if (SHR_FAILURE(rv)) { if (rv == SHR_E_RESOURCE) { /* Delete the newly inserted node if we ran out of cid bits */ (void)(bcmfp_compress_key_delete(unit, in_node_info, trie, user_data)); } return (rv); } /* Copy updated cid/cid_mask to in_node_info */ in_node_info->ref_count = in_node->ref_count; sal_memcpy(&in_node_info->cid, &in_node->cid, sizeof(bcmfp_cid_t)); sal_memcpy(&in_node_info->cid_mask, &in_node->cid_mask, sizeof(bcmfp_cid_t)); rv = SHR_E_NONE; exit: return (rv); } /*! * \brief Lookup compression key in the trie. * * \param [in] unit Logical device id * \param [in] in_node_info key to be searched * \param [in] trie Trie on which operation is to be performed * \retval SHR_E_NONE If key is present * \retval SHR_E_NOT_FOUND If key is absent in the trie */ int bcmfp_compress_key_lookup(int unit, bcmfp_basic_info_key_t *in_node_info, bcmfp_shr_trie_md_t *trie) { bcmfp_compress_key_t *parent_node, *curr_node; int prefix, rv = SHR_E_PARAM, found = 0, index; BCMFP_COMP_NULL_CHECK(trie); BCMFP_COMP_NULL_CHECK(trie->root); BCMFP_COMP_NULL_CHECK(in_node_info); if (in_node_info->prefix > trie->max_prefix_mask) { return (SHR_E_PARAM); } /* Start with root node */ parent_node = trie->root; /* Fetching the root node. */ if (in_node_info->prefix == 0) { /* Copy cid/cid_mask to in_node_info */ sal_memcpy(&in_node_info->cid, &parent_node->cid, sizeof(bcmfp_cid_t)); sal_memcpy(&in_node_info->cid_mask, &parent_node->cid_mask, sizeof(bcmfp_cid_t)); return (SHR_E_NONE); } /* First search the list compressed nodes list */ curr_node = trie->root->sibling; while (curr_node) { rv = bcmfp_compare_bits(in_node_info->key.w, curr_node->key.w, in_node_info->prefix, curr_node->prefix, trie->max_prefix_mask); if (rv) { if (in_node_info->prefix == curr_node->prefix) { found = 1; in_node_info->flags = BCMFP_TRIE_NODE_LIST_COMPRESSED; break; } } curr_node = curr_node->sibling; } /* Loop through all the prefix levels */ for (prefix = 1; prefix <= trie->max_prefix_mask && found == 0; prefix++) { index = trie->max_prefix_mask - prefix; curr_node = parent_node->child[index]; /* Loop through all nodes of the same prefix until a match is found */ while (curr_node != NULL) { rv = bcmfp_compare_bits(in_node_info->key.w, curr_node->key.w, in_node_info->prefix, curr_node->prefix, trie->max_prefix_mask); if (rv) { if (in_node_info->prefix < curr_node->prefix) { /* Node not found in trie */ return (SHR_E_NOT_FOUND); } else if (in_node_info->prefix > curr_node->prefix) { /* Find correct place under sub-trie of current node */ parent_node = curr_node; curr_node = NULL; } else { /* Incoming key has same prefix as current nodes prefix */ found = 1; in_node_info->flags = 0; break; } } else { /* No match with curr_node */ curr_node = curr_node->sibling; } } } if (found) { /* Copy cid/cid_mask to in_node_info */ sal_memcpy(&in_node_info->cid, &curr_node->cid, sizeof(bcmfp_cid_t)); sal_memcpy(&in_node_info->cid_mask, &curr_node->cid_mask, sizeof(bcmfp_cid_t)); in_node_info->ref_count = curr_node->ref_count; rv = SHR_E_NONE; } else { /* Node not found in trie */ rv = SHR_E_NOT_FOUND; } exit: return (rv); } /*! * \brief Traverse the trie below. * * \param [in] unit Logical device id * \param [in] index Index for the output nodes * \param [in] in_node Incoming node whose trie is to be traversed * \param [out] out Trie traversal output * * \retval SHR_E_NONE Success * \retval SHR_E_INTERNAL Trie is not sane */ STATIC int bcmfp_compress_key_traverse_trie_children(int unit, uint32_t *oindex, bcmfp_compress_key_t *in_node, bcmfp_shr_trie_md_t *trie, bcmfp_basic_info_key_t *out) { int prefix = 0, rv = 0, index, p_cid_mask, cid_mask; uint32_t num_child; bcmfp_compress_key_t *curr_node; bcmfp_compress_key_t *list_cmp_node; num_child = 0; for (prefix = in_node->prefix + 1; prefix <= trie->max_prefix_mask; prefix++) { index = trie->max_prefix_mask - prefix; curr_node = in_node->child[index]; /* Get parent_node's CID mask length (in bits) */ SHR_BITCOUNT_RANGE(in_node->cid_mask.w, p_cid_mask, 0, trie->max_cid_mask); while (curr_node) { if (prefix != curr_node->prefix) { /* Child node is not correctly linked */ return (SHR_E_INTERNAL); } if (prefix <= in_node->prefix) { /* Child prefix should always be greater than parent prefix */ return (SHR_E_INTERNAL); } if (curr_node->sibling && curr_node->sibling->prefix != curr_node->prefix) { /* All siblings should have same prefix */ return (SHR_E_INTERNAL); } rv = bcmfp_compare_bits(in_node->key.w, curr_node->key.w, curr_node->prefix, in_node->prefix, trie->max_prefix_mask); if (rv == 0) { /* Child should always have matching prefix */ return (SHR_E_INTERNAL); } /* Get child node's CID mask length (in bits) */ SHR_BITCOUNT_RANGE(curr_node->cid_mask.w, cid_mask, 0, trie->max_cid_mask); if (cid_mask <= p_cid_mask) { /* Child cid_mask should always be greater than parent cid_mask */ return (SHR_E_INTERNAL); } rv = bcmfp_compare_bits(in_node->cid_mask.w, curr_node->cid_mask.w, (uint32_t)cid_mask, (uint32_t)p_cid_mask, trie->max_cid_mask); if (rv == 0) { /* Child should always have matching cid_mask */ return (SHR_E_INTERNAL); } /* Call in recursion till child present. */ rv = (bcmfp_compress_key_traverse_trie_children(unit, oindex, curr_node, trie, out)); if (SHR_FAILURE(rv)) { return rv; } /* Iterate all the list compressed nodes */ list_cmp_node = trie->root->sibling; while (list_cmp_node) { /* list compressed node should not have a match with a node in trie */ rv = bcmfp_compare_bits(list_cmp_node->key.w, curr_node->key.w, curr_node->prefix, list_cmp_node->prefix, trie->max_prefix_mask); if (rv != 0) { return (SHR_E_INTERNAL); } list_cmp_node = list_cmp_node->sibling; } if (out != NULL) { sal_memcpy(&out[*oindex].key, &curr_node->key, sizeof(bcmfp_key_t)); sal_memcpy(&out[*oindex].cid, &curr_node->cid, sizeof(bcmfp_cid_t)); sal_memcpy(&out[*oindex].cid_mask, &curr_node->cid_mask, sizeof(bcmfp_cid_t)); out[*oindex].prefix = curr_node->prefix; } /* Increment index value. */ (*oindex)++; num_child++; curr_node = curr_node->sibling; } } if (in_node->num_child != num_child) { /* Inconsistency in number of children nodes */ return (SHR_E_INTERNAL); } return SHR_E_NONE; } /*! * \brief Traverse the trie from root * * \param [in] unit Logical device id * \param [in] trie Trie on which operation is to be performed * \param [out] out Trie traversal output * \param [out] num_nodes Number of nodes in trie including list compressed nodes * * \retval SHR_E_NONE Success * \retval SHR_E_EMPTY Trie is empty * \retval SHR_E_INTERNAL Trie is not sane */ int bcmfp_compress_key_traverse(int unit, bcmfp_shr_trie_md_t *trie, bcmfp_basic_info_key_t *out, uint32_t *num_nodes) { uint32_t oindex = 0; bcmfp_compress_key_t *list_cmp_node; int rv = SHR_E_PARAM; BCMFP_COMP_NULL_CHECK(trie); BCMFP_COMP_NULL_CHECK(trie->root); /* Fill list compressed nodes first */ list_cmp_node = trie->root->sibling; while (list_cmp_node) { if (out != NULL) { sal_memcpy(&out[oindex].key, &list_cmp_node->key, sizeof(bcmfp_key_t)); sal_memcpy(&out[oindex].cid, &list_cmp_node->cid, sizeof(bcmfp_cid_t)); sal_memcpy(&out[oindex].cid_mask, &list_cmp_node->cid_mask, sizeof(bcmfp_cid_t)); out[oindex].prefix = list_cmp_node->prefix; } /* Increment index value. */ oindex++; list_cmp_node = list_cmp_node->sibling; } rv = (bcmfp_compress_key_traverse_trie_children(unit, &oindex, trie->root, trie, out)); if (SHR_FAILURE(rv)) { return rv; } if (oindex == 0) { return (SHR_E_EMPTY); } if (num_nodes != NULL) { *num_nodes = oindex; } exit: return (rv); } /*! * \brief Delete compression key info present in in_node_info from the trie. * * \param [in] unit Logical device id * \param [in] in_node_info Compressed node info to be deleted * \param [in] trie Trie on which operation is to be performed * \param [in] user_data Data passed by caller application which will * be passed back to it if there are changes * in cid/cid_mask of existing keys in trie. * * \retval SHR_E_NONE Success * \retval SHR_E_NOT_FOUND If key is absent in the trie */ int bcmfp_compress_key_delete(int unit, bcmfp_basic_info_key_t *in_node_info, bcmfp_shr_trie_md_t *trie, void *user_data) { bcmfp_compress_key_t *parent_node, *curr_node, *curr_node_prev_sib; bcmfp_compress_key_t *lc_node = NULL; bcmfp_basic_info_key_t node_info; int prefix, rv = SHR_E_PARAM, in_node_linked = 1, index; BCMFP_COMP_NULL_CHECK(trie); BCMFP_COMP_NULL_CHECK(trie->root); BCMFP_COMP_NULL_CHECK(in_node_info); if (in_node_info->prefix > trie->max_prefix_mask) { return (SHR_E_PARAM); } /* Root not allowed to be deleted. */ if (sal_memcmp(&in_node_info->key, &trie->root->key, sizeof(bcmfp_key_t)) == 0) { return (SHR_E_PARAM); } if (in_node_info->prefix == 0) { if (trie->root->ref_count > 1) { trie->root->ref_count--; } in_node_info->ref_count = trie->root->ref_count; return (SHR_E_NONE); } if (!(in_node_info->flags & BCMFP_TRIE_NODE_WIDTH_COMPRESSED)) { /* First search the list compressed nodes list */ curr_node_prev_sib = trie->root; curr_node = trie->root->sibling; while (curr_node) { rv = bcmfp_compare_bits(in_node_info->key.w, curr_node->key.w, in_node_info->prefix, curr_node->prefix, trie->max_prefix_mask); if (rv) { if (in_node_info->prefix == curr_node->prefix) { in_node_linked = 0; curr_node->ref_count--; in_node_info->ref_count--; if (curr_node->ref_count > 0) { /* Key is in use by multiple rules */ return (SHR_E_NONE); } /* Remove current node from list compressed nodes list */ curr_node_prev_sib->sibling = curr_node->sibling; /* Free current node */ bcmfp_compress_key_node_free(unit, curr_node, trie); curr_node = NULL; return (SHR_E_NONE); } } if (!(in_node_info->flags & BCMFP_TRIE_NODE_LIST_COMPRESSED)) { /* Node to be deleted is not list compressed */ if (SHR_BITEQ_RANGE(in_node_info->cid.w, curr_node->cid.w, 0, trie->max_cid_mask) && in_node_info->ref_count == 1) { /* * If there is a list compressed node using * the cid of the node to be deleted, * then it needs to be moved to the trie * only if ref_count of the node to be deleted is 1 */ sal_memcpy(node_info.key.w, &curr_node->key, sizeof(bcmfp_key_t)); sal_memcpy(node_info.cid.w, &curr_node->cid, sizeof(bcmfp_cid_t)); sal_memcpy(node_info.cid_mask.w, &curr_node->cid_mask, sizeof(bcmfp_cid_t)); node_info.ref_count = curr_node->ref_count; node_info.prefix = curr_node->prefix; node_info.flags = BCMFP_TRIE_NODE_WIDTH_COMPRESSED; /* Remove current node from list compressed nodes list */ curr_node_prev_sib->sibling = curr_node->sibling; lc_node = curr_node; break; } } curr_node_prev_sib = curr_node; curr_node = curr_node->sibling; } } /* Start with root node */ parent_node = trie->root; curr_node_prev_sib = NULL; /* Loop through all the prefix levels */ for (prefix = 1; prefix <= trie->max_prefix_mask; prefix++) { index = trie->max_prefix_mask - prefix; curr_node = parent_node->child[index]; /* Loop through all nodes of the same prefix until a match is found */ while (curr_node != NULL) { rv = bcmfp_compare_bits(in_node_info->key.w, curr_node->key.w, in_node_info->prefix, curr_node->prefix, trie->max_prefix_mask); if (rv) { if (in_node_info->prefix < curr_node->prefix) { /* Node not found in trie */ return (SHR_E_NOT_FOUND); } else if (in_node_info->prefix > curr_node->prefix) { /* Incoming node is present under sub-trie of current node */ /* Find correct place under sub-trie of current node */ parent_node = curr_node; curr_node = NULL; } else { /* Incoming key has same prefix as current nodes prefix */ curr_node->ref_count--; in_node_info->ref_count--; if (curr_node->ref_count > 0) { /* Key is in use by multiple rules */ return (SHR_E_NONE); } /* Unlink the current node from the parent node */ bcmfp_compress_key_delete_child(trie, curr_node, curr_node_prev_sib, parent_node); in_node_linked = 0; /* Link current node sub-trie to parent node */ parent_node->num_child += curr_node->num_child; for (prefix = curr_node->prefix + 1; prefix <= trie->max_prefix_mask; prefix++) { index = trie->max_prefix_mask - prefix; if (curr_node->child[index] == NULL) { continue; } bcmfp_compress_key_insert_child(trie, curr_node->child[index], parent_node); /* Already assigned */ parent_node->num_child--; } /* Free current node */ bcmfp_compress_key_node_free(unit, curr_node, trie); curr_node = NULL; } } else { /* No match with curr_node */ curr_node_prev_sib = curr_node; curr_node = curr_node->sibling; } } curr_node_prev_sib = NULL; } if (in_node_linked) { /* Node not found in trie */ return (SHR_E_NOT_FOUND); } if (lc_node) { /* Add list compressed node in trie */ rv = bcmfp_compress_key_insert(unit, &node_info, trie, user_data); if (SHR_FAILURE(rv)) { if (rv == SHR_E_RESOURCE) { /* Add the node back in list compression list */ node_info.flags = BCMFP_TRIE_NODE_LIST_COMPRESSED; (void)(bcmfp_compress_key_insert(unit, &node_info, trie, user_data)); /* Add the deleted node back to trie */ in_node_info->flags = BCMFP_TRIE_NODE_WIDTH_COMPRESSED; in_node_info->ref_count = 1; sal_memset(in_node_info->cid.w, 0, sizeof(bcmfp_cid_t)); sal_memset(in_node_info->cid_mask.w, 0, sizeof(bcmfp_cid_t)); (void)(bcmfp_compress_key_insert(unit, in_node_info, trie, user_data)); } return (rv); } /* Free list compressed node */ bcmfp_compress_key_node_free(unit, lc_node, trie); lc_node = NULL; } else { /* Update CID/CID Mask */ rv = (bcmfp_compress_id_update(unit, trie, parent_node, user_data)); if (SHR_FAILURE(rv)) { return (rv); } } rv = SHR_E_NONE; exit: return (rv); } /*! * \brief Create and initialize metadata of trie. * * \param [in] unit Logical device id * \param [in] max_prefix_mask Max prefix length(in bits) for a key in this trie * \param [in] max_cid_mask Max cid length(in bits) for a key in this trie * \param [in] compress_type Type of the trie to be created. * \param [in] trie pointer to created trie * * \retval SHR_E_NONE Success * \retval SHR_E_PARAM If memory allocation failure is detected */ int bcmfp_compress_trie_create(int unit, uint8_t max_prefix_mask, uint8_t max_cid_mask, uint8_t trie_type, bcmfp_fn_cid_update_t cid_update_cb, bcmfp_shr_trie_md_t **trie_new) { bcmfp_shr_trie_md_t *trie = NULL; bcmfp_basic_info_key_t root_info; int rv = SHR_E_MEMORY; BCMFP_COMP_ALLOC(trie, sizeof(bcmfp_shr_trie_md_t), "bcmfpTrieManagementDataStructure"); *trie_new = trie; trie->max_prefix_mask = max_prefix_mask; trie->max_cid_mask = max_cid_mask; trie->cid_update_cb = cid_update_cb; trie->trie_type = trie_type; sal_memset(&root_info, 0, sizeof(bcmfp_basic_info_key_t)); rv = (bcmfp_compress_key_node_alloc(unit, &root_info, &trie->root, trie)); if (SHR_FAILURE(rv)) { return (rv); } SHR_BITSET(trie->root->cid.w, trie->max_cid_mask - 1); SHR_BITSET(trie->root->cid_mask.w, trie->max_cid_mask - 1); exit: return (rv); } /*! * \brief Delete all the compression nodes in in_node's sub-trie. * * \param [in] Node Node to be freed. * * \retval SHR_E_NONE Success * \retval SHR_E_PARAM Invalid parameters */ STATIC void bcmfp_compress_key_nodes_delete(int unit, bcmfp_shr_trie_md_t *trie, bcmfp_compress_key_t *in_node) { int prefix; bcmfp_compress_key_t *curr_node = NULL; bcmfp_compress_key_t *curr_node_sib = NULL; for (prefix = in_node->prefix + 1; prefix <= trie->max_prefix_mask; prefix++) { curr_node = in_node->child[trie->max_prefix_mask - prefix]; while (curr_node) { curr_node_sib = curr_node->sibling; bcmfp_compress_key_nodes_delete(unit, trie, curr_node); curr_node = curr_node_sib; } } bcmfp_compress_key_node_free(unit, in_node, trie); in_node = NULL; } /*! * \brief Free the trie metadata sructure. * * \param [in] unit Logical device id * \param [in] trie Pointer to created trie * * \retval SHR_E_NONE Success * \retval SHR_E_PARAM Invalid parameters */ int bcmfp_compress_trie_deinit(int unit, bcmfp_shr_trie_md_t *trie) { bcmfp_compress_key_t *curr_node = NULL; bcmfp_compress_key_t *curr_node_tmp = NULL; if (trie) { if (trie->root) { curr_node = trie->root->sibling; while (curr_node) { /* Delete all list compressed nodes */ curr_node_tmp = curr_node; curr_node = curr_node->sibling; bcmfp_compress_key_node_free(unit, curr_node_tmp, trie); curr_node_tmp = NULL; } /* Delete all nodes in the trie. */ bcmfp_compress_key_nodes_delete(unit, trie, trie->root); } BCMFP_COMP_FREE(trie); trie = NULL; } return SHR_E_NONE; }
36.823224
134
0.536664
b2faab05b154ae906326273d632e8835cca5976f
130
h
C
dependencies/physx-4.1/source/physx/src/NpRigidActorTemplate.h
realtehcman/-UnderwaterSceneProject
72cbd375ef5e175bed8f4e8a4d117f5340f239a4
[ "MIT" ]
null
null
null
dependencies/physx-4.1/source/physx/src/NpRigidActorTemplate.h
realtehcman/-UnderwaterSceneProject
72cbd375ef5e175bed8f4e8a4d117f5340f239a4
[ "MIT" ]
null
null
null
dependencies/physx-4.1/source/physx/src/NpRigidActorTemplate.h
realtehcman/-UnderwaterSceneProject
72cbd375ef5e175bed8f4e8a4d117f5340f239a4
[ "MIT" ]
null
null
null
version https://git-lfs.github.com/spec/v1 oid sha256:8ab0544d0b352596011d5cb1cd0cd555e56987fc1ef0ff545105a507ad338341 size 15992
32.5
75
0.884615
053e3fa50a9c3000bbeeac462f5e8a15c4fda36e
10,461
h
C
components/include/osi_log.h
HEYAHONG/Luat_CSDK_Air724U
5607701b5dd6635eb3aefe41a2880bf3bd6bc07a
[ "MIT" ]
4
2021-07-23T06:33:02.000Z
2022-02-10T08:29:15.000Z
components/include/osi_log.h
HEYAHONG/Luat_CSDK_Air724U
5607701b5dd6635eb3aefe41a2880bf3bd6bc07a
[ "MIT" ]
null
null
null
components/include/osi_log.h
HEYAHONG/Luat_CSDK_Air724U
5607701b5dd6635eb3aefe41a2880bf3bd6bc07a
[ "MIT" ]
12
2021-07-01T11:46:37.000Z
2022-01-20T08:09:32.000Z
/* Copyright (C) 2018 RDA Technologies Limited and/or its affiliates("RDA"). * All rights reserved. * * This software is supplied "AS IS" without any warranties. * RDA assumes no responsibility or liability for the use of the software, * conveys no license or title under any patent, copyright, or mask work * right to the product. RDA reserves the right to make changes in the * software without notification. RDA also make no representation or * warranty that such application will be suitable for the specified use * without further testing or modification. */ #ifndef _OSI_LOG_H_ #define _OSI_LOG_H_ #include <stdarg.h> #include "kernel_config.h" #include "osi_compiler.h" OSI_EXTERN_C_BEGIN #ifndef DOXYGEN #ifndef OSI_LOCAL_LOG_LEVEL #define OSI_LOCAL_LOG_LEVEL OSI_LOG_LEVEL_INFO #endif #ifdef OSI_LOG_DISABLED #undef OSI_LOCAL_LOG_LEVEL #define OSI_LOCAL_LOG_LEVEL OSI_LOG_LEVEL_NEVER #endif #ifndef OSI_LOCAL_LOG_TAG #ifdef OSI_LOG_TAG #define OSI_LOCAL_LOG_TAG OSI_LOG_TAG #else #define OSI_LOCAL_LOG_TAG LOG_TAG_NONE #endif #endif #endif /** * trace level, larger value is less important */ enum { OSI_LOG_LEVEL_NEVER, ///< only used in control, for not to output trace OSI_LOG_LEVEL_ERROR, ///< error OSI_LOG_LEVEL_WARN, ///< warning OSI_LOG_LEVEL_INFO, ///< information OSI_LOG_LEVEL_DEBUG, ///< for debug OSI_LOG_LEVEL_VERBOSE ///< verbose }; /** * macro for trace tag */ #define OSI_MAKE_LOG_TAG(a, b, c, d) ((unsigned)(a) | ((unsigned)(b) << 7) | ((unsigned)(c) << 14) | ((unsigned)(d) << 21)) /** * macro for extended trace argument types */ #define OSI_LOGPAR(...) __OSI_LOGPAR(__VA_ARGS__) /** * macros for trace level condition * * \code{.cpp} * if (OSI_LOGD_EN) { * ...... * } * \endcode * * When DEBUG trace is not enabled, the above codes will be expanded as empty. */ #define OSI_LOGE_EN (OSI_LOCAL_LOG_LEVEL >= OSI_LOG_LEVEL_ERROR) #define OSI_LOGW_EN (OSI_LOCAL_LOG_LEVEL >= OSI_LOG_LEVEL_WARN) #define OSI_LOGI_EN (OSI_LOCAL_LOG_LEVEL >= OSI_LOG_LEVEL_INFO) #define OSI_LOGD_EN (OSI_LOCAL_LOG_LEVEL >= OSI_LOG_LEVEL_DEBUG) #define OSI_LOGV_EN (OSI_LOCAL_LOG_LEVEL >= OSI_LOG_LEVEL_VERBOSE) /** * macros for basic trace * * When the trace level is not enabled, the macro will be expanded as empty. * * At most 16 arguments are supported. * * @param trcid trace ID, 0 for not use trace ID * @param fmt format string, only used when trace ID is 0 */ #define OSI_LOGE(trcid, fmt, ...) __OSI_LOGB(OSI_LOG_LEVEL_ERROR, trcid, fmt, ##__VA_ARGS__) #define OSI_LOGW(trcid, fmt, ...) __OSI_LOGB(OSI_LOG_LEVEL_WARN, trcid, fmt, ##__VA_ARGS__) #define OSI_LOGI(trcid, fmt, ...) __OSI_LOGB(OSI_LOG_LEVEL_INFO, trcid, fmt, ##__VA_ARGS__) #define OSI_LOGD(trcid, fmt, ...) __OSI_LOGB(OSI_LOG_LEVEL_DEBUG, trcid, fmt, ##__VA_ARGS__) #define OSI_LOGV(trcid, fmt, ...) __OSI_LOGB(OSI_LOG_LEVEL_VERBOSE, trcid, fmt, ##__VA_ARGS__) /** * macros for extended trace * * When the trace level is not enabled, the macro will be expanded as empty. * * At most 16 arguments are supported. * * @param partype arguments types * @param trcid trace ID, 0 for not use trace ID * @param fmt format string, only used when trace ID is 0 */ #define OSI_LOGXE(partype, trcid, fmt, ...) __OSI_LOGX(OSI_LOG_LEVEL_ERROR, partype, trcid, fmt, ##__VA_ARGS__) #define OSI_LOGXW(partype, trcid, fmt, ...) __OSI_LOGX(OSI_LOG_LEVEL_WARN, partype, trcid, fmt, ##__VA_ARGS__) #define OSI_LOGXI(partype, trcid, fmt, ...) __OSI_LOGX(OSI_LOG_LEVEL_INFO, partype, trcid, fmt, ##__VA_ARGS__) #define OSI_LOGXD(partype, trcid, fmt, ...) __OSI_LOGX(OSI_LOG_LEVEL_DEBUG, partype, trcid, fmt, ##__VA_ARGS__) #define OSI_LOGXV(partype, trcid, fmt, ...) __OSI_LOGX(OSI_LOG_LEVEL_VERBOSE, partype, trcid, fmt, ##__VA_ARGS__) /** * macros for trace with format string parsing * * When the trace level is not enabled, the macro will be expanded as empty. * * At most 16 arguments are supported. * * @param fmt format string, only used when trace ID is 0 */ #define OSI_PRINTFE(fmt, ...) __OSI_PRINTF(OSI_LOG_LEVEL_ERROR, fmt, ##__VA_ARGS__) #define OSI_PRINTFW(fmt, ...) __OSI_PRINTF(OSI_LOG_LEVEL_WARN, fmt, ##__VA_ARGS__) #define OSI_PRINTFI(fmt, ...) __OSI_PRINTF(OSI_LOG_LEVEL_INFO, fmt, ##__VA_ARGS__) #define OSI_PRINTFD(fmt, ...) __OSI_PRINTF(OSI_LOG_LEVEL_DEBUG, fmt, ##__VA_ARGS__) #define OSI_PRINTFV(fmt, ...) __OSI_PRINTF(OSI_LOG_LEVEL_VERBOSE, fmt, ##__VA_ARGS__) /** * macros for SX style trace and dump * * \p id is a complex bit fields. The definition follows SX definition. */ #define OSI_SXPRINTF(id, fmt, ...) __OSI_SXPRINTF(id, fmt, ##__VA_ARGS__) #define OSI_SXDUMP(id, fmt, data, size) __OSI_SXDUMP(id, fmt, data, size) /** * macros for new SX style trace * * Only module level in \p id will be used. When SX style trace is wanted to * be kept, it is suggested to migrate to these 2 macros. */ #define OSI_SX_TRACE(id, trcid, fmt, ...) __OSI_SX_TRACE(id, trcid, fmt, ##__VA_ARGS__) #define OSI_SX_TRACEX(id, partype, trcid, fmt, ...) __OSI_SX_TRACEX(id, partype, trcid, fmt, ##__VA_ARGS__) /** * macros for stack trace of pub modules */ #define OSI_PUB_TRACE(module, category, trcid, fmt, ...) __OSI_PUB_TRACE(module, category, trcid, fmt, ##__VA_ARGS__) #define OSI_PUB_TRACEX(module, category, partype, trcid, fmt, ...) __OSI_PUB_TRACEX(module, category, partype, trcid, fmt, ##__VA_ARGS__) /** * macros for stack trace of lte modules */ #define OSI_LTE_TRACE(module, category, trcid, fmt, ...) __OSI_LTE_TRACE(module, category, trcid, fmt, ##__VA_ARGS__) #define OSI_LTE_TRACEX(module, category, partype, trcid, fmt, ...) __OSI_LTE_TRACEX(module, category, partype, trcid, fmt, ##__VA_ARGS__) /** * macros for stack trace without module and category control * * It is suggested to use these 2 for quick debug only. The above macros * with module and category control should be used. */ #define OSI_TRACE(trcid, fmt, ...) __OSI_TRACE(trcid, fmt, ##__VA_ARGS__) #define OSI_TRACEX(partype, trcid, fmt, ...) __OSI_TRACEX(partype, trcid, fmt, ##__VA_ARGS__) #define OSI_NAS_TRACE(category, fmtid, fmt, ...) OSI_PUB_TRACE(TRA_NAS, category, fmtid, fmt, ##__VA_ARGS__) #define OSI_NAS_TRACEX(category, partype, fmtid, fmt, ...) OSI_PUB_TRACEX(TRA_NAS, category, partype, fmtid, fmt, ##__VA_ARGS__) #define OSI_NAS_TRACE_DUMP(hint_info, dataLen, data) \ OSI_PUB_TRACEX(TRA_NAS, TRA_S1, OSI_LOGPAR_SIM, 0x10007460, "nas_dump_%s(%d bytes): %*s", hint_info, (dataLen), (dataLen), (data)) #define OSI_NASU_TRACE(category, fmtid, fmt, ...) OSI_LTE_TRACE(TRA_NASU, category, fmtid, fmt, ##__VA_ARGS__) #define OSI_NASU_TRACEX(category, partype, fmtid, fmt, ...) OSI_LTE_TRACEX(TRA_NASU, category, partype, fmtid, fmt, ##__VA_ARGS__) #define OSI_NASU_TRACE_DUMP(hint_info, dataLen, data) \ OSI_LTE_TRACEX(TRA_NAS, TRA_S1, OSI_LOGPAR_SIM, 0x10007461, "rab_dump_%s(%d bytes): %*s", hint_info, (dataLen), (dataLen), (data)) #define OSI_ERRC_TRACE(category, fmtid, fmt, ...) OSI_LTE_TRACE(TRA_ERRC, category, fmtid, fmt, ##__VA_ARGS__) #define OSI_ERRC_TRACEX(category, partype, fmtid, fmt, ...) OSI_LTE_TRACEX(TRA_ERRC, category, partype, fmtid, fmt, ##__VA_ARGS__) #define OSI_ERRC_TRACE_DUMP(hint_info, dataLen, data) \ OSI_LTE_TRACEX(TRA_ERRC, TRA_S1, OSI_LOGPAR_SIM, 0x10007462, "errc_dump_%s(%d bytes): %*s", hint_info, (dataLen), (dataLen), (data)) #define OSI_LPP_TRACE(category, fmtid, fmt, ...) OSI_LTE_TRACE(TRA_LPP, category, fmtid, fmt, ##__VA_ARGS__) #define OSI_LPP_TRACEX(category, partype, fmtid, fmt, ...) OSI_LTE_TRACEX(TRA_LPP, category, partype, fmtid, fmt, ##__VA_ARGS__) #define OSI_LPP_TRACE_DUMP(hint_info, dataLen, data) \ OSI_LTE_TRACEX(TRA_LPP, TRA_S1, OSI_LOGPAR_SIM, 0x10007463, "lpp_dump_%s(%d bytes): %*s", hint_info, (dataLen), (dataLen), (data)) #define OSI_EPDC_TRACE(category, fmtid, fmt, ...) OSI_LTE_TRACE(TRA_EPDC, category, fmtid, fmt, ##__VA_ARGS__) #define OSI_EPDC_TRACEX(category, partype, fmtid, fmt, ...) OSI_LTE_TRACEX(TRA_EPDC, category, partype, fmtid, fmt, ##__VA_ARGS__) #define OSI_EPDC_TRACE_DUMP(hint_info, dataLen, data) \ OSI_LTE_TRACEX(TRA_EPDC, TRA_S1, OSI_LOGPAR_SIM, 0x10007464, "epdc_dump_%s(%d bytes): %*s", hint_info, (dataLen), (dataLen), (data)) #define OSI_ROHC_TRACE(category, fmtid, fmt, ...) OSI_LTE_TRACE(TRA_ROHC, category, fmtid, fmt, ##__VA_ARGS__) #define OSI_ROHC_TRACEX(category, partype, fmtid, fmt, ...) OSI_LTE_TRACEX(TRA_ROHC, category, partype, fmtid, fmt, ##__VA_ARGS__) #define OSI_ROHC_TRACE_DUMP(hint_info, dataLen, data) \ OSI_LTE_TRACEX(TRA_ROHC, TRA_S1, OSI_LOGPAR_SIM, 0x10007465, "rohc_dump_%s(%d bytes): %*s", hint_info, (dataLen), (dataLen), (data)) #define OSI_ERLC_TRACE(category, fmtid, fmt, ...) OSI_LTE_TRACE(TRA_ERLC, category, fmtid, fmt, ##__VA_ARGS__) #define OSI_ERLC_TRACEX(category, partype, fmtid, fmt, ...) OSI_LTE_TRACEX(TRA_ERLC, category, partype, fmtid, fmt, ##__VA_ARGS__) #define OSI_ERLC_TRACE_DUMP(hint_info, dataLen, data) \ OSI_LTE_TRACEX(TRA_ERLC, TRA_S1, OSI_LOGPAR_SIM, 0x10007466, "erlc_dump_%s(%d bytes): %*s", hint_info, (dataLen), (dataLen), (data)) #define OSI_EMAC_TRACE(category, fmtid, fmt, ...) OSI_LTE_TRACE(TRA_EMAC, category, fmtid, fmt, ##__VA_ARGS__) #define OSI_EMAC_TRACEX(category, partype, fmtid, fmt, ...) OSI_LTE_TRACEX(TRA_EMAC, category, partype, fmtid, fmt, ##__VA_ARGS__) #define OSI_EMAC_TRACE_DUMP(hint_info, dataLen, data) \ OSI_LTE_TRACEX(TRA_EMAC, TRA_S1, OSI_LOGPAR_SIM, 0x10007467, "emac_dump_%s(%d bytes): %*s", hint_info, (dataLen), (dataLen), (data)) #define OSI_NL1C_TRACE(category, fmtid, fmt, ...) OSI_LTE_TRACE(TRA_NL1C, category, fmtid, fmt, ##__VA_ARGS__) #define OSI_NL1C_TRACEX(category, partype, fmtid, fmt, ...) OSI_LTE_TRACEX(TRA_NL1C, category, partype, fmtid, fmt, ##__VA_ARGS__) #define OSI_NL1C_TRACE_DUMP(hint_info, dataLen, data) \ OSI_LTE_TRACEX(TRA_NL1C, TRA_S1, OSI_LOGPAR_SIM, 0x10007468, "nl1c_dump_%s(%d bytes): %*s", hint_info, (dataLen), (dataLen), (data)) /** * \brief trace vprintf by parsing format string * * This can be used to implement trace functions in third party library. * When there are chances to modify source codes, the appropriate macros * from above should be used. * * @param tag packed trace tag and trace level * @param fmt format string * @param ap variadic argument list */ void osiTraceVprintf(unsigned tag, const char *fmt, va_list ap); #include "osi_log_imp.h" OSI_EXTERN_C_END #endif
47.334842
137
0.738075
9f7a44ba89346edf0634a932923e294c0133c739
1,887
h
C
include/frt/utility/visit.h
evanacox/freestanding-rt
44cb68d86654f07fe82c0a44a139f90ed5730ac3
[ "BSD-3-Clause" ]
null
null
null
include/frt/utility/visit.h
evanacox/freestanding-rt
44cb68d86654f07fe82c0a44a139f90ed5730ac3
[ "BSD-3-Clause" ]
null
null
null
include/frt/utility/visit.h
evanacox/freestanding-rt
44cb68d86654f07fe82c0a44a139f90ed5730ac3
[ "BSD-3-Clause" ]
null
null
null
//======---------------------------------------------------------------======// // // // Copyright 2021-2022 Evan Cox <evanacox00@gmail.com>. All rights reserved. // // // // Use of this source code is governed by a BSD-style license that can be // // found in the LICENSE.txt file at the root of this project, or at the // // following link: https://opensource.org/licenses/BSD-3-Clause // // // //======---------------------------------------------------------------======// #pragma once namespace frt { namespace internal { template <bool CanThrow, typename... Ts> class Visitor; template <bool CanThrow, typename T> class Visitor<CanThrow, T> { public: virtual void visit(T& object) noexcept(!CanThrow) = 0; }; template <bool CanThrow, typename T, typename... Ts> class Visitor<CanThrow, T, Ts...> : public Visitor<CanThrow, T>, public Visitor<CanThrow, Ts...> {}; } // namespace internal /// Creates a base Visitor type for a bounded set of types. /// /// For each type `T` in `Ts`, `Visitor` has a member function with the following signature: /// ``` /// virtual void visit(T& object) noexcept = 0; /// ``` template <typename... Ts> class Visitor : public internal::Visitor<false, Ts...> {}; /// Creates a base Visitor type for a bounded set of types, but allows each visit /// member function to throw. /// /// For each type `T` in `Ts`, `Visitor` has a member function with the following signature: /// ``` /// virtual void visit(T& object) = 0; /// ``` template <typename... Ts> class ThrowingVisitor : public internal::Visitor<false, Ts...> {}; } // namespace frt
44.928571
104
0.513514
1993586e7937ad8cc0a0022abb753198874bd992
746
h
C
ALSUniversalAccount/Classes/Plug/BaiChuan/SecondParty/AliVfsSDK/AliVfsSDK.framework/Headers/AVFSMonitorObserver.h
profiles/ALSUniversalAccount
2f49b1e5d374c2bba13d5ab0ed56bf94ddad7a81
[ "MIT" ]
6
2018-03-29T09:27:43.000Z
2021-09-06T09:23:13.000Z
Example/Pods/AliVfsSDK/AliVfsSDK.framework/Headers/AVFSMonitorObserver.h
AltairEven/ALSUniversalAccount
2f49b1e5d374c2bba13d5ab0ed56bf94ddad7a81
[ "MIT" ]
null
null
null
Example/Pods/AliVfsSDK/AliVfsSDK.framework/Headers/AVFSMonitorObserver.h
AltairEven/ALSUniversalAccount
2f49b1e5d374c2bba13d5ab0ed56bf94ddad7a81
[ "MIT" ]
3
2019-01-07T13:20:04.000Z
2022-03-11T03:43:43.000Z
// // AVFSMonitorObserver.h // AliVfsSDK // // Created by Dafeng Jin on 16/3/8. // Copyright © 2016年 taobao. All rights reserved. // #import <Foundation/Foundation.h> typedef NS_ENUM(NSUInteger, AVFSOperationFlag) { //文件读操作 AVFSOperationFileRead= 1, //文件创建 AVFSOperationFileCreate = 2, //文件写操作 AVFSOperationFileWrite = 3, //文件删操作 AVFSOperationFileDelete = 4, }; @interface AVFSMonitorObserver : NSObject /** * 单例 * * @return 单例 */ + (instancetype)sharedObserver; /** * 发送监听信号 * * @param key 键名 * @param module 模块名 * @param attrs 属性列表 */ - (void)notifyModule:(NSString *)module operate:(AVFSOperationFlag)operate attrs:(NSDictionary *)attrs; @end
16.577778
103
0.632708
e5d67088a5104611abb901aec7c7547ee25e17b7
1,109
c
C
src/tpm/hms2hms.c
cdeil/pytpm
02d149355b20eaed09805865948805e982c46bf2
[ "BSD-3-Clause" ]
2
2019-12-23T02:03:25.000Z
2020-05-30T14:11:05.000Z
src/tpm/hms2hms.c
cdeil/pytpm
02d149355b20eaed09805865948805e982c46bf2
[ "BSD-3-Clause" ]
1
2020-12-06T22:57:26.000Z
2020-12-06T23:01:57.000Z
src/tpm/hms2hms.c
astrojuanlu/pytpm
eb995ad10e2564da5e5c569df902eb267969d13c
[ "BSD-3-Clause" ]
1
2021-12-02T05:42:35.000Z
2021-12-02T05:42:35.000Z
/* file: $RCSfile: hms2hms.c,v $ ** rcsid: $Id: hms2hms.c 261 2007-10-19 19:07:02Z laidler $ ** Copyright Jeffrey W Percival ** ******************************************************************* ** Space Astronomy Laboratory ** University of Wisconsin ** 1150 University Avenue ** Madison, WI 53706 USA ** ******************************************************************* ** Do not use this software without attribution. ** Do not remove or alter any of the lines above. ** ******************************************************************* */ /* ** ******************************************************************* ** $RCSfile: hms2hms.c,v $ - normalize an hms time ** ******************************************************************* */ #include "times.h" HMS hms2hms(HMS hms) { double x; /* convert to decimal hours */ x = hms2h(hms); hmsSetHours(hms, floor(x)); /* promote the minutes part */ x = (x - floor(x)) * 60.0; hmsSetMinutes(hms, floor(x)); /* promote the seconds part */ x = (x - floor(x)) * 60.0; hmsSetSeconds(hms, x); return(hms); }
26.404762
70
0.42651
0f36910dd891cbc4a9637d0ff7e4c14d3e36c773
3,106
h
C
src/p5.h
LewisCheng-MSFT/p5fs
ffcb70944f28bf6757c2c27d0da288e30a41e50e
[ "MIT" ]
null
null
null
src/p5.h
LewisCheng-MSFT/p5fs
ffcb70944f28bf6757c2c27d0da288e30a41e50e
[ "MIT" ]
null
null
null
src/p5.h
LewisCheng-MSFT/p5fs
ffcb70944f28bf6757c2c27d0da288e30a41e50e
[ "MIT" ]
null
null
null
#ifndef P5_H #define P5_H #include <sys/types.h> #define MAX_FILE_NAME_LENGTH 62 #define MAX_OPEN_FILES 10 #define FS_VER 11 #define MAX_FILE_NUM 5000 #define I_NODE_BYTES 64 #define DIR_BYTES 64 #define DIR_PER_BLOCK 16 #define NR_DIRECT_ZONES 7 #define NR_IND1_ZONES 256 #define NR_IND2_ZONES 65536 #define INODES_PER_BLOCK 16 #define OK 0 #define IMAP_BLOCKS 1 #define ZMAP_BLOCKS 31 #define LOG_ZONE_SIZE 0 #define FIRSTDATAZONE 346 #define ZONES 249655 #define INODES_PER_BLOCK 16 #define FIRST_IMAP_BLOCK 1 #define FIRST_ZMAP_BLOCK 315 #define FIRST_INODE_BLOCK 2 #define BLOCKSIZE 1024 #define BIT_PER_BLOCK 8192 #define DIR_FILE 2 #define NORMAL_FILE 1 #define BIT1 0x80 #define BIT2 0x40 #define BIT3 0x20 #define BIT4 0x10 #define BIT5 0x08 #define BIT6 0x04 #define BIT7 0x02 #define BIT8 0x01 static char BIT[8] = {0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01}; typedef u32_t blockn_t; typedef u16_t inodesn_t; typedef struct { inodesn_t ninodes; /* # usable inodes on the minor device */ blockn_t imap_blocks; /* # of blocks used by inode bit map */ blockn_t zmap_blocks; /* # of blocks used by zone bit map */ blockn_t firstdatazone; /* number of first data zone */ u16_t log_zone_size; /* log2 of blocks/zone */ blockn_t zones; /* number of zones */ u16_t version; /* file system version */ inodesn_t inodes_per_block; blockn_t first_imap_block; blockn_t first_zmap_block; blockn_t first_inode_block; /* number of first block with inodes */ size_t dzmap_size; /* # of data zone blocks */ } super_t; typedef struct { /* summary of inode */ u16_t mode; u16_t links; u16_t uid; u16_t gid; u32_t size; time_t build_time; time_t alter_time; time_t sta_time; blockn_t direct[NR_DIRECT_ZONES]; /* block numbers for direct, * ind, ... */ blockn_t ind1; /* single indirect block number */ blockn_t ind2; /* double indirect block number */ blockn_t ind3; /* triple indirect block number */ } inode_t; typedef struct { inodesn_t inode_nr; char name[MAX_FILE_NAME_LENGTH]; } dir_t; typedef struct { inodesn_t inode_nr; inode_t inode; blockn_t block_nr; char buf[BLOCKSIZE]; int offset; char used; }fp_t; /*Global var */ fp_t fp[MAX_OPEN_FILES]; char zeros[BLOCKSIZE]; int last_free_zmap,last_free_zone; char zmap_buf[BLOCKSIZE]; /* file API */ extern int my_open (const char * path); extern int my_creat (const char * path); extern int my_read (int fd, void * buf, int count); extern int my_write (int fd, const void * buf, int count); extern int my_close (int fd); extern int my_remove (const char * path); extern int my_rename (const char * old, const char * new); extern int my_mkdir (const char * path); extern int my_rmdir (const char * path); extern void my_mkfs (void); /* provided by the lower layer */ /* not used in any declaration, just a reminder that each block is 1KB */ /* and may be useful inside the code. */ typedef char block [BLOCKSIZE]; extern int dev_open (); extern int read_block (int block_num, char * block); extern int write_block (int block_num, char * block); #endif /* P5_H */
24.265625
73
0.736639
66a883e1bf4baf1c9b7c0d3e94f94aa5ae3dec30
787
h
C
ds/ds/src/inc/base64.h
npocmaka/Windows-Server-2003
5c6fe3db626b63a384230a1aa6b92ac416b0765f
[ "Unlicense" ]
17
2020-11-13T13:42:52.000Z
2021-09-16T09:13:13.000Z
ds/ds/src/inc/base64.h
sancho1952007/Windows-Server-2003
5c6fe3db626b63a384230a1aa6b92ac416b0765f
[ "Unlicense" ]
2
2020-10-19T08:02:06.000Z
2020-10-19T08:23:18.000Z
ds/ds/src/inc/base64.h
sancho1952007/Windows-Server-2003
5c6fe3db626b63a384230a1aa6b92ac416b0765f
[ "Unlicense" ]
14
2020-11-14T09:43:20.000Z
2021-08-28T08:59:57.000Z
/*++ Copyright (c) 1997 Microsoft Corporation. All rights reserved. MODULE NAME: base64.h ABSTRACT: Base64 encoding and decoding functions. DETAILS: CREATED: REVISION HISTORY: --*/ #ifndef _BASE64_H_ #define _BASE64_H_ #ifdef __cplusplus extern "C" { #endif NTSTATUS base64encode( IN VOID * pDecodedBuffer, IN DWORD cbDecodedBufferSize, OUT LPSTR pszEncodedString, IN DWORD cchEncodedStringSize, OUT DWORD * pcchEncoded OPTIONAL ); NTSTATUS base64decode( IN LPSTR pszEncodedString, OUT VOID * pbDecodeBuffer, IN DWORD cbDecodeBufferSize, OUT DWORD * pcbDecoded OPTIONAL ); #ifdef __cplusplus } #endif #endif // _BASE64_H_
15.134615
49
0.6277
01e8d2991989b21f55df1d7825c992b992060367
320
h
C
project2D/StateReset.h
Lenammon/Oh-No-Dogo-
f51b8b0ddf79efe69d90e01fa481a68bf4cf0241
[ "MIT" ]
null
null
null
project2D/StateReset.h
Lenammon/Oh-No-Dogo-
f51b8b0ddf79efe69d90e01fa481a68bf4cf0241
[ "MIT" ]
null
null
null
project2D/StateReset.h
Lenammon/Oh-No-Dogo-
f51b8b0ddf79efe69d90e01fa481a68bf4cf0241
[ "MIT" ]
null
null
null
#pragma once #include "BaseState.h" #include "Renderer2D.h" #include "Font.h" class StateReset : public BaseState { public: StateReset(StateMachine* pStatMachine); ~StateReset(); void OnEnter(); void OnUpdate(float deltaTime); void OnExit(); void Draw(aie::Renderer2D* renderer); private: aie::Font* m_font; };
17.777778
40
0.728125
240b14d802756d0b5277a9cfc29e7918ea451806
485
h
C
App/src/UI/Windows/UIConfigWindow.h
Shorakie/GraphDelta
f930ccd7c3bffc7a12fa864d6dca72375623cbcf
[ "MIT" ]
1
2021-07-08T22:51:59.000Z
2021-07-08T22:51:59.000Z
App/src/UI/Windows/UIConfigWindow.h
Shorakie/GraphDelta
f930ccd7c3bffc7a12fa864d6dca72375623cbcf
[ "MIT" ]
null
null
null
App/src/UI/Windows/UIConfigWindow.h
Shorakie/GraphDelta
f930ccd7c3bffc7a12fa864d6dca72375623cbcf
[ "MIT" ]
null
null
null
#pragma once #include <UI/UIWindow.h> #include "Views/GraphView.h" namespace Project { class UIConfigWindow : public Engine::UIWindow { private: std::shared_ptr<GraphView> graphView; public: UIConfigWindow(std::shared_ptr<GraphView> graphView, std::string name = "Config"); void init() override; void deinit() override; void render() override; void update() override; void renderImGui() override; void save(); void load(); }; } // namespace Project
18.653846
84
0.696907
0ff592fcbb7a3cb6b18a827449d5ddc62e58c5cd
2,535
h
C
gcr-3.34.0/ui/gcr-key-renderer.h
BeanGreen247/surf
a56d1b0ceb43c578c6a3258e4ffb2903dc691fe2
[ "MIT" ]
null
null
null
gcr-3.34.0/ui/gcr-key-renderer.h
BeanGreen247/surf
a56d1b0ceb43c578c6a3258e4ffb2903dc691fe2
[ "MIT" ]
null
null
null
gcr-3.34.0/ui/gcr-key-renderer.h
BeanGreen247/surf
a56d1b0ceb43c578c6a3258e4ffb2903dc691fe2
[ "MIT" ]
null
null
null
/* * Copyright (C) 2010 Stefan Walter * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program; if not, see <http://www.gnu.org/licenses/>. */ #if !defined (__GCR_INSIDE_HEADER__) && !defined (GCR_COMPILATION) #error "Only <gcr/gcr.h> or <gcr/gcr-base.h> can be included directly." #endif #ifndef __GCR_KEY_RENDERER_H__ #define __GCR_KEY_RENDERER_H__ #include <glib-object.h> #include <gtk/gtk.h> #include "gcr/gcr-types.h" G_BEGIN_DECLS #define GCR_TYPE_KEY_RENDERER (gcr_key_renderer_get_type ()) #define GCR_KEY_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GCR_TYPE_KEY_RENDERER, GcrKeyRenderer)) #define GCR_KEY_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GCR_TYPE_KEY_RENDERER, GcrKeyRendererClass)) #define GCR_IS_KEY_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GCR_TYPE_KEY_RENDERER)) #define GCR_IS_KEY_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GCR_TYPE_KEY_RENDERER)) #define GCR_KEY_RENDERER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GCR_TYPE_KEY_RENDERER, GcrKeyRendererClass)) typedef struct _GcrKeyRenderer GcrKeyRenderer; typedef struct _GcrKeyRendererClass GcrKeyRendererClass; typedef struct _GcrKeyRendererPrivate GcrKeyRendererPrivate; struct _GcrKeyRenderer { GObject parent; /*< private >*/ GcrKeyRendererPrivate *pv; }; struct _GcrKeyRendererClass { GObjectClass parent_class; }; GType gcr_key_renderer_get_type (void); GcrKeyRenderer* gcr_key_renderer_new (const gchar *label, GckAttributes *attrs); void gcr_key_renderer_set_attributes (GcrKeyRenderer *self, GckAttributes *attrs); GckAttributes* gcr_key_renderer_get_attributes (GcrKeyRenderer *self); G_END_DECLS #endif /* __GCR_KEY_RENDERER_H__ */
37.835821
123
0.710848
d59d6ec6330f2eb36034e37415bdbeb076a1fcf1
47,206
h
C
visualization/FitAdam/include/AdamFastCost.h
alvaro-budria/body2hands
0eba438b4343604548120bdb03c7e1cb2b08bcd6
[ "BSD-3-Clause" ]
63
2021-05-14T02:55:16.000Z
2022-03-13T01:51:12.000Z
visualization/FitAdam/include/AdamFastCost.h
human2b/body2hands
8ab4b206dc397c3b326f2b4ec9448c84ee8801fe
[ "BSD-3-Clause" ]
9
2021-06-24T09:59:41.000Z
2021-12-31T08:15:20.000Z
visualization/FitAdam/include/AdamFastCost.h
human2b/body2hands
8ab4b206dc397c3b326f2b4ec9448c84ee8801fe
[ "BSD-3-Clause" ]
9
2021-05-17T03:33:28.000Z
2022-02-17T02:30:44.000Z
#pragma once #include <iostream> #include "totalmodel.h" #include <cassert> #include "pose_to_transforms.h" #include <cstring> #include <chrono> class AdamFastCost: public ceres::CostFunction { public: AdamFastCost(TotalModel &adam, Eigen::MatrixXd &Joints, Eigen::MatrixXd &rFoot, //3x2 //Heel, Toe Eigen::MatrixXd &lFoot, Eigen::MatrixXd &faceJoints, Eigen::MatrixXd &lHandJoints, Eigen::MatrixXd &rHandJoints, double* p_adam_coeff ): m_adam(adam), m_rfoot_joints(rFoot), m_lfoot_joints(lFoot), m_bodyJoints(Joints), m_FaceJoints(faceJoints), m_lHandJoints(lHandJoints), m_rHandJoints(rHandJoints), res_dim(3), verbose(false) { assert(p_adam_coeff != NULL); std::copy(p_adam_coeff, p_adam_coeff + TotalModel::NUM_SHAPE_COEFFICIENTS, m_pCoeff); SetupCost(); } virtual ~AdamFastCost() {} void UpdateJoints(Eigen::MatrixXd &Joints, Eigen::MatrixXd &rFoot, Eigen::MatrixXd &lFoot, Eigen::MatrixXd &faceJoints, Eigen::MatrixXd &lHandJoints, Eigen::MatrixXd &rHandJoints) { m_bodyJoints << Joints; m_rfoot_joints << rFoot; m_lfoot_joints << lFoot; m_FaceJoints << faceJoints; m_lHandJoints << lHandJoints; m_rHandJoints << rHandJoints; UpdateTarget(); } void SetupCost() { using namespace cv; using namespace Eigen; double BODYJOINT_WEIGHT_Strong = 1; double BODYJOINT_WEIGHT = 1; double HANDJOINT_WEIGHT = 1; double VERTEX_WEIGHT = 1; m_nCorrespond_adam2joints = m_adam.m_indices_jointConst_adamIdx.rows(); m_nCorrespond_adam2joints += m_adam.m_correspond_adam2lHand_adamIdx.rows(); m_nCorrespond_adam2joints += m_adam.m_correspond_adam2rHand_adamIdx.rows(); // 13 vertices in 11 constraints total_vertex.push_back(8130); // nose total_vertex.push_back(6731); // left eye total_vertex.push_back(6970); // left ear total_vertex.push_back(4131); // right eye total_vertex.push_back(10088); // right ear total_vertex.push_back(14328); // right bigtoe total_vertex.push_back(14288); // right littletoe total_vertex.push_back(14357); // right heel total_vertex.push_back(14361); // right heel total_vertex.push_back(12239); // left bigtoe total_vertex.push_back(12289); // left littletoe total_vertex.push_back(12368); // left heel total_vertex.push_back(12357); // left heel m_nCorrespond_adam2pts = 11; m_targetPts.resize((m_nCorrespond_adam2joints + m_nCorrespond_adam2pts) * 5); m_targetPts.setZero(); m_targetPts_weight.resize(m_nCorrespond_adam2joints + m_nCorrespond_adam2pts); m_targetPts_weight_buffer.resize(m_nCorrespond_adam2joints + m_nCorrespond_adam2pts); UpdateTarget(); // copy target int offset = 0; // set up the weights for (int ic = 0; ic < m_adam.m_indices_jointConst_adamIdx.rows(); ic++) { int smcjoint = m_adam.m_indices_jointConst_smcIdx(ic); if (smcjoint == 4 || smcjoint == 10 || smcjoint == 3 || smcjoint == 9 || smcjoint == 7 || smcjoint == 13) { m_targetPts_weight[ic] = BODYJOINT_WEIGHT_Strong; m_targetPts_weight_buffer[ic] = BODYJOINT_WEIGHT_Strong; } else { m_targetPts_weight[ic] = BODYJOINT_WEIGHT; m_targetPts_weight_buffer[ic] = BODYJOINT_WEIGHT; } } offset += m_adam.m_indices_jointConst_adamIdx.rows(); for (int ic = 0; ic < m_adam.m_correspond_adam2lHand_adamIdx.rows(); ic++) { m_targetPts_weight[ic + offset] = HANDJOINT_WEIGHT; m_targetPts_weight_buffer[ic + offset] = HANDJOINT_WEIGHT; } offset += m_adam.m_correspond_adam2lHand_adamIdx.rows(); for (int ic = 0; ic < m_adam.m_correspond_adam2rHand_adamIdx.rows(); ic++) { for (int i = 0; i < res_dim; i++) { m_targetPts_weight[ic + offset] = HANDJOINT_WEIGHT; m_targetPts_weight_buffer[ic + offset] = HANDJOINT_WEIGHT; } } offset += m_adam.m_correspond_adam2rHand_adamIdx.rows(); for (int ic = 0; ic < m_nCorrespond_adam2pts; ic++) { m_targetPts_weight[offset + ic] = VERTEX_WEIGHT; m_targetPts_weight_buffer[offset + ic] = VERTEX_WEIGHT; } m_nResiduals = (m_nCorrespond_adam2joints + m_nCorrespond_adam2pts) * res_dim; if(verbose) std::cout << "m_nResiduals " << m_nResiduals << std::endl; CostFunction::set_num_residuals(m_nResiduals); auto parameter_block_sizes = CostFunction::mutable_parameter_block_sizes(); parameter_block_sizes->clear(); parameter_block_sizes->push_back(3); // Translation parameter_block_sizes->push_back(TotalModel::NUM_JOINTS * 3); // SMPL Pose // perform regression from shape coeff to Joint Map< const Matrix<double, Dynamic, 1> > c_bodyshape(m_pCoeff, TotalModel::NUM_SHAPE_COEFFICIENTS); m_Vt.resize(TotalModel::NUM_VERTICES, 3); Map< Matrix<double, Dynamic, 1> > Vt_vec(m_Vt.data(), 3 * TotalModel::NUM_VERTICES); Vt_vec = m_adam.m_meanshape + m_adam.m_shapespace_u*c_bodyshape; m_J0.resize(TotalModel::NUM_JOINTS, 3); Map< Matrix<double, Dynamic, 1> > J_vec(m_J0.data(), TotalModel::NUM_JOINTS * 3); J_vec = m_adam.J_mu_ + m_adam.dJdc_ * c_bodyshape; } void UpdateTarget() { int offset = 0; for (int ic = 0; ic < m_adam.m_indices_jointConst_adamIdx.rows(); ic++) m_targetPts.block(ic * 5, 0, 5, 1) = m_bodyJoints.block(0, m_adam.m_indices_jointConst_smcIdx(ic), 5, 1); offset += m_adam.m_indices_jointConst_adamIdx.rows(); for (int ic = 0; ic < m_adam.m_correspond_adam2lHand_adamIdx.rows(); ic++) m_targetPts.block((offset + ic) * 5, 0, 5, 1) = m_lHandJoints.block(0, m_adam.m_correspond_adam2lHand_lHandIdx(ic), 5, 1); offset += m_adam.m_correspond_adam2lHand_adamIdx.rows(); for (int ic = 0; ic < m_adam.m_correspond_adam2rHand_adamIdx.rows(); ic++) m_targetPts.block((offset + ic) * 5, 0, 5, 1) = m_rHandJoints.block(0, m_adam.m_correspond_adam2rHand_rHandIdx(ic), 5, 1); offset += m_adam.m_correspond_adam2rHand_adamIdx.rows(); m_targetPts.block<5, 1>(offset * 5, 0) = m_bodyJoints.block<5, 1>(0, 1); offset++; m_targetPts.block<5, 1>(offset * 5, 0) = m_bodyJoints.block<5, 1>(0, 15); offset++; m_targetPts.block<5, 1>(offset * 5, 0) = m_bodyJoints.block<5, 1>(0, 16); offset++; m_targetPts.block<5, 1>(offset * 5, 0) = m_bodyJoints.block<5, 1>(0, 17); offset++; m_targetPts.block<5, 1>(offset * 5, 0) = m_bodyJoints.block<5, 1>(0, 18); offset++; m_targetPts.block<5, 1>(offset * 5, 0) = m_rfoot_joints.block<5, 1>(0, 0); offset++; m_targetPts.block<5, 1>(offset * 5, 0) = m_rfoot_joints.block<5, 1>(0, 1); offset++; m_targetPts.block<5, 1>(offset * 5, 0) = m_rfoot_joints.block<5, 1>(0, 2); offset++; m_targetPts.block<5, 1>(offset * 5, 0) = m_lfoot_joints.block<5, 1>(0, 0); offset++; m_targetPts.block<5, 1>(offset * 5, 0) = m_lfoot_joints.block<5, 1>(0, 1); offset++; m_targetPts.block<5, 1>(offset * 5, 0) = m_lfoot_joints.block<5, 1>(0, 2); offset++; } void toggle_activate(bool limb, bool finger) { for (int ic = 0; ic<m_adam.m_indices_jointConst_adamIdx.rows(); ic++) { int smcjoint = m_adam.m_indices_jointConst_smcIdx(ic); if (smcjoint != 3 && smcjoint != 6 && smcjoint != 9 && smcjoint != 12) { m_targetPts_weight[ic] = double(limb) * m_targetPts_weight_buffer[ic]; } } int offset = m_adam.m_indices_jointConst_smcIdx.rows(); for (int ic = 0; ic < m_adam.m_correspond_adam2lHand_adamIdx.rows(); ic++) m_targetPts_weight[ic + offset] = m_targetPts_weight_buffer[ic + offset] * double(finger); offset += m_adam.m_correspond_adam2lHand_adamIdx.rows(); for (int ic = 0; ic < m_adam.m_correspond_adam2rHand_adamIdx.rows(); ic++) m_targetPts_weight[ic + offset] = m_targetPts_weight_buffer[ic + offset] * double(finger); } virtual bool Evaluate(double const* const* parameters, double* residuals, double** jacobians) const; TotalModel m_adam; Eigen::Matrix<double, 5, Eigen::Dynamic, Eigen::RowMajor> m_rfoot_joints; Eigen::Matrix<double, 5, Eigen::Dynamic, Eigen::RowMajor> m_lfoot_joints; Eigen::Matrix<double, 5, Eigen::Dynamic, Eigen::RowMajor> m_bodyJoints; Eigen::Matrix<double, 5, Eigen::Dynamic, Eigen::RowMajor> m_FaceJoints; Eigen::Matrix<double, 5, Eigen::Dynamic, Eigen::RowMajor> m_lHandJoints; Eigen::Matrix<double, 5, Eigen::Dynamic, Eigen::RowMajor> m_rHandJoints; Eigen::VectorXd m_targetPts; Eigen::VectorXd m_targetPts_weight; Eigen::VectorXd m_targetPts_weight_buffer; double m_pCoeff[TotalModel::NUM_SHAPE_COEFFICIENTS]; std::vector<int> total_vertex; int m_nCorrespond_adam2joints; int m_nCorrespond_adam2pts; int m_nResiduals; Eigen::Matrix<double, Eigen::Dynamic, 3, Eigen::RowMajor> m_Vt; // the vertex given current shape (before translation) Eigen::Matrix<double, TotalModel::NUM_JOINTS, 3, Eigen::RowMajor> m_J0; // correspondent default joint given current shape int res_dim; bool verbose; }; struct AdamFitData { AdamFitData(const TotalModel &adam, const Eigen::MatrixXd &Joints, const Eigen::MatrixXd &rFoot, const Eigen::MatrixXd &lFoot, const Eigen::MatrixXd &faceJoints, const Eigen::MatrixXd &lHandJoints, const Eigen::MatrixXd &rHandJoints, const Eigen::MatrixXd& PAF, const Eigen::MatrixXd& surface_constraint, bool fit3D=false, bool fit2D=false, double* K=nullptr, bool fitPAF=false, bool fit_surface=false): adam(adam), bodyJoints(Joints), rFoot(rFoot), lFoot(lFoot), faceJoints(faceJoints), lHandJoints(lHandJoints), rHandJoints(rHandJoints), PAF(PAF), surface_constraint(surface_constraint), fit3D(fit3D), fit2D(fit2D), K(K), fitPAF(fitPAF), fit_surface(fit_surface) { inner_weight.clear(); inner_weight.push_back(5.0f); } const TotalModel &adam; const Eigen::MatrixXd& bodyJoints; const Eigen::MatrixXd& rFoot; //3x2 //Heel, Toe const Eigen::MatrixXd& lFoot; const Eigen::MatrixXd& faceJoints; const Eigen::MatrixXd& lHandJoints; const Eigen::MatrixXd& rHandJoints; const Eigen::MatrixXd& PAF; const Eigen::MatrixXd& surface_constraint; const bool fit3D; const bool fit2D; const double* K; const bool fitPAF; const bool fit_surface; std::vector<float> inner_weight; }; class AdamFullCost: public ceres::CostFunction { public: AdamFullCost(const AdamFitData& fit_data, const int regressor_type=0, const bool fit_face_exp=false, const bool euler=true): fit_data_(fit_data), res_dim(0), start_2d_dim(0), rigid_body(false), num_PAF_constraint(fit_data.PAF.cols()), num_inner(fit_data.inner_weight.size()), total_inner_dim(0), regressor_type(regressor_type), fit_face_exp(fit_face_exp), euler_(euler) { if(fit_data_.fit3D) { res_dim += 3; start_2d_dim += 3; } if(fit_data_.fit2D) { assert(fit_data_.K); res_dim += 2; } if(fit_data_.fitPAF) { assert(fit_data_.PAF.size() > 0 && fit_data_.PAF.rows() == 3); } if(fit_data_.fit_surface) { // assert(fit_data_.K); // Fit a vertex to a specific pixel location. assert(fit_data_.surface_constraint.rows() == 6); } assert(num_inner == DEFINED_INNER_CONSTRAINTS); inner_dim.clear(); inner_dim.push_back(3); assert(inner_dim.size() == DEFINED_INNER_CONSTRAINTS); assert(regressor_type >= 0 && regressor_type <= 2); // 0 for the default joints, 1 for Human3.6M regressor, 2 for COCO style output if (fit_face_exp) assert(regressor_type == 0 || regressor_type == 2); // must have face constraints in order to fit face expression. SetupCost(); // setup parent indexes, for fast LBS jacobian computation parentIndexes[0].clear(); parentIndexes[0].push_back(0); for(auto i = 0u; i < TotalModel::NUM_JOINTS; i++) { parentIndexes[i] = std::vector<int>(1, i); while (parentIndexes[i].back() != 0) parentIndexes[i].emplace_back(fit_data_.adam.m_parent[parentIndexes[i].back()]); std::sort(parentIndexes[i].begin(), parentIndexes[i].end()); } dVdP_data = new double[3 * total_vertex.size() * TotalModel::NUM_POSE_PARAMETERS]; dVdc_data = new double[3 * total_vertex.size() * TotalModel::NUM_SHAPE_COEFFICIENTS]; dOdP_data = new double[3 * (m_nCorrespond_adam2joints + m_nCorrespond_adam2pts) * TotalModel::NUM_POSE_PARAMETERS]; dOdc_data = new double[3 * (m_nCorrespond_adam2joints + m_nCorrespond_adam2pts) * TotalModel::NUM_SHAPE_COEFFICIENTS]; if(fit_face_exp) { dVdfc_data = new double[3 * total_vertex.size() * TotalModel::NUM_EXP_BASIS_COEFFICIENTS]; dOdfc_data = new double[3 * (m_nCorrespond_adam2joints + m_nCorrespond_adam2pts) * TotalModel::NUM_EXP_BASIS_COEFFICIENTS]; dTJdfc_data = new double[3 * TotalModel::NUM_JOINTS * TotalModel::NUM_EXP_BASIS_COEFFICIENTS]; std::fill(dTJdfc_data, dTJdfc_data + 3 * TotalModel::NUM_JOINTS * TotalModel::NUM_EXP_BASIS_COEFFICIENTS, 0); // always 0, output joint not related to face exp } } ~AdamFullCost() { delete[] dVdc_data; delete[] dVdP_data; delete[] dOdP_data; delete[] dOdc_data; if (fit_face_exp) { delete[] dVdfc_data; delete[] dOdfc_data; delete[] dTJdfc_data; } } void SetupCost() { using namespace cv; using namespace Eigen; if (regressor_type == 0) { // calculating the dim for 3D / 2D constraints m_nCorrespond_adam2joints = fit_data_.adam.m_indices_jointConst_adamIdx.rows(); if(fit_data_.lHandJoints.size() > 0) m_nCorrespond_adam2joints += fit_data_.adam.m_correspond_adam2lHand_adamIdx.rows(); if(fit_data_.rHandJoints.size() > 0) m_nCorrespond_adam2joints += fit_data_.adam.m_correspond_adam2rHand_adamIdx.rows(); // These are all the vertices to compute total_vertex.push_back(8130); //nose total_vertex.push_back(6970); //left ear total_vertex.push_back(10088); //right ear total_vertex.push_back(1372); //head top total_vertex.push_back(14328); //right bigtoe total_vertex.push_back(14288); //right littletoe total_vertex.push_back(14357); //right heel total_vertex.push_back(14361); //right heel total_vertex.push_back(12239); //left bigtoe total_vertex.push_back(12289); //left littletoe total_vertex.push_back(12368); //left heel total_vertex.push_back(12357); //left heel // face detector results for (int r = 0; r < fit_data_.adam.m_correspond_adam2face70_adamIdx.rows(); ++r) { int adamVertexIdx = fit_data_.adam.m_correspond_adam2face70_adamIdx(r); total_vertex.push_back(adamVertexIdx); } // setting up the vertex (specify the vertices with constraints to optimize) corres_vertex2targetpt.push_back(std::make_pair(0, std::vector<double>(5))); corres_vertex2targetpt.push_back(std::make_pair(1, std::vector<double>(5))); corres_vertex2targetpt.push_back(std::make_pair(2, std::vector<double>(5))); corres_vertex2targetpt.push_back(std::make_pair(3, std::vector<double>(5))); corres_vertex2targetpt.push_back(std::make_pair(4, std::vector<double>(5))); corres_vertex2targetpt.push_back(std::make_pair(5, std::vector<double>(5))); corres_vertex2targetpt.push_back(std::make_pair(6, std::vector<double>(5))); corres_vertex2targetpt.push_back(std::make_pair(7, std::vector<double>(5))); corres_vertex2targetpt.push_back(std::make_pair(8, std::vector<double>(5))); corres_vertex2targetpt.push_back(std::make_pair(9, std::vector<double>(5))); corres_vertex2targetpt.push_back(std::make_pair(10, std::vector<double>(5))); corres_vertex2targetpt.push_back(std::make_pair(11, std::vector<double>(5))); for (int r = 0; r < fit_data_.adam.m_correspond_adam2face70_adamIdx.rows(); ++r) { corres_vertex2targetpt.push_back(std::make_pair(12 + r, std::vector<double>(5))); } if (fit_data_.fit_surface) { for(auto i = 0; i < fit_data_.surface_constraint.cols(); i++) { corres_vertex2targetpt.push_back(std::make_pair(total_vertex.size()-1, std::vector<double>(5))); total_vertex.push_back(fit_data_.surface_constraint(5, i)); } } m_nCorrespond_adam2pts = corres_vertex2targetpt.size(); PAF_connection.resize(num_PAF_constraint); PAF_connection = {{ {{0, 12, 0, 2}}, {{0, 2, 0, 5}}, {{0, 5, 0, 8}}, {{0, 12, 0, 1}}, {{0, 1, 0, 4}}, {{0, 4, 0, 7}}, {{0, 12, 0, 17}}, {{0, 17, 0, 19}}, {{0, 19, 0, 21}}, // right arm {{0, 12, 0, 16}}, {{0, 16, 0, 18}}, {{0, 18, 0, 20}}, // left arm {{0, 12, 1, 0}}, {{0, 12, 1, 3}}, // neck -> nose, neck -> head top {{0, 17, 0, 21}}, {{0, 16, 0, 20}}, // shoulder -> wrist {{0, 2, 0, 21}}, {{0, 1, 0, 20}}, // hip -> wrist {{0, 2, 0, 8}}, {{0, 1, 0, 7}}, // hip -> ankle {{0, 20, 0, 22}}, {{0, 22, 0, 23}}, {{0, 23, 0, 24}}, {{0, 24, 0, 25}}, // left hand {{0, 20, 0, 26}}, {{0, 26, 0, 27}}, {{0, 27, 0, 28}}, {{0, 28, 0, 29}}, {{0, 20, 0, 30}}, {{0, 30, 0, 31}}, {{0, 31, 0, 32}}, {{0, 32, 0, 33}}, {{0, 20, 0, 34}}, {{0, 34, 0, 35}}, {{0, 35, 0, 36}}, {{0, 36, 0, 37}}, {{0, 20, 0, 38}}, {{0, 38, 0, 39}}, {{0, 39, 0, 40}}, {{0, 40, 0, 41}}, {{0, 21, 0, 22 + 20}}, {{0, 22 + 20, 0, 23 + 20}}, {{0, 23 + 20, 0, 24 + 20}}, {{0, 24 + 20, 0, 25 + 20}}, // right hand {{0, 21, 0, 26 + 20}}, {{0, 26 + 20, 0, 27 + 20}}, {{0, 27 + 20, 0, 28 + 20}}, {{0, 28 + 20, 0, 29 + 20}}, {{0, 21, 0, 30 + 20}}, {{0, 30 + 20, 0, 31 + 20}}, {{0, 31 + 20, 0, 32 + 20}}, {{0, 32 + 20, 0, 33 + 20}}, {{0, 21, 0, 34 + 20}}, {{0, 34 + 20, 0, 35 + 20}}, {{0, 35 + 20, 0, 36 + 20}}, {{0, 36 + 20, 0, 37 + 20}}, {{0, 21, 0, 38 + 20}}, {{0, 38 + 20, 0, 39 + 20}}, {{0, 39 + 20, 0, 40 + 20}}, {{0, 40 + 20, 0, 41 + 20}}, }}; PAF_weight.resize(num_PAF_constraint); PAF_weight = {{ 150., 150., 150., 150., 150., 150., 150., 150., 150., 150., 150., 150., 0., 0., 50., 50., 50., 50., 50., 50., 50., 50., 50., 50., // left hand 50., 50., 50., 50., 50., 50., 50., 50., 50., 50., 50., 50., 50., 50., 50., 50., 50., 50., 50., 50., // right hand 50., 50., 50., 50., 50., 50., 50., 50., 50., 50., 50., 50., 50., 50., 50., 50. }}; } else if (regressor_type == 1) { m_nCorrespond_adam2joints = fit_data_.adam.h36m_jointConst_smcIdx.size(); int count_vertex = 0; for (int k = 0; k < fit_data_.adam.m_cocoplus_reg.outerSize(); ++k) { for (SparseMatrix<double>::InnerIterator it(fit_data_.adam.m_cocoplus_reg, k); it; ++it) { total_vertex.push_back(k); count_vertex++; break; // now this vertex is used, go to next vertex } } corres_vertex2targetpt.clear(); m_nCorrespond_adam2pts = 0; if (fit_data_.fit_surface) { for(auto i = 0; i < fit_data_.surface_constraint.cols(); i++) { corres_vertex2targetpt.push_back(std::make_pair(i, std::vector<double>(5))); total_vertex.push_back(fit_data_.surface_constraint(5, i)); m_nCorrespond_adam2pts++; } } PAF_connection.resize(num_PAF_constraint); PAF_connection = {{ {{2, 12, 2, 2}}, {{2, 2, 2, 1}}, {{2, 1, 2, 0}}, {{2, 12, 2, 3}}, {{2, 3, 2, 4}}, {{2, 4, 2, 5}}, {{2, 12, 2, 8}}, {{2, 8, 2, 7}}, {{2, 7, 2, 6}}, // right arm {{2, 12, 2, 9}}, {{2, 9, 2, 10}}, {{2, 10, 2, 11}}, // left arm {{2, 12, 2, 14}}, {{2, 12, 2, 13}}, // neck -> nose, neck -> head top {{2, 12, 2, 19}}, {{2, 19, 2, 2}}, {{2, 19, 2, 3}}, {{2, 8, 2, 6}}, {{2, 9, 2, 11}}, // shoulder -> wrist {{2, 2, 2, 6}}, {{2, 3, 2, 11}}, // hip -> wrist {{2, 2, 2, 0}}, {{2, 3, 2, 5}}, // hip -> ankle {{0, 20, 0, 22}}, {{0, 22, 0, 23}}, {{0, 23, 0, 24}}, {{0, 24, 0, 25}}, // left hand {{0, 20, 0, 26}}, {{0, 26, 0, 27}}, {{0, 27, 0, 28}}, {{0, 28, 0, 29}}, {{0, 20, 0, 30}}, {{0, 30, 0, 31}}, {{0, 31, 0, 32}}, {{0, 32, 0, 33}}, {{0, 20, 0, 34}}, {{0, 34, 0, 35}}, {{0, 35, 0, 36}}, {{0, 36, 0, 37}}, {{0, 20, 0, 38}}, {{0, 38, 0, 39}}, {{0, 39, 0, 40}}, {{0, 40, 0, 41}}, {{0, 21, 0, 22 + 20}}, {{0, 22 + 20, 0, 23 + 20}}, {{0, 23 + 20, 0, 24 + 20}}, {{0, 24 + 20, 0, 25 + 20}}, // right hand {{0, 21, 0, 26 + 20}}, {{0, 26 + 20, 0, 27 + 20}}, {{0, 27 + 20, 0, 28 + 20}}, {{0, 28 + 20, 0, 29 + 20}}, {{0, 21, 0, 30 + 20}}, {{0, 30 + 20, 0, 31 + 20}}, {{0, 31 + 20, 0, 32 + 20}}, {{0, 32 + 20, 0, 33 + 20}}, {{0, 21, 0, 34 + 20}}, {{0, 34 + 20, 0, 35 + 20}}, {{0, 35 + 20, 0, 36 + 20}}, {{0, 36 + 20, 0, 37 + 20}}, {{0, 21, 0, 38 + 20}}, {{0, 38 + 20, 0, 39 + 20}}, {{0, 39 + 20, 0, 40 + 20}}, {{0, 40 + 20, 0, 41 + 20}}, }}; PAF_weight.resize(num_PAF_constraint); PAF_weight = {{ 150., 150., 150., 150., 150., 150., 150., 150., 150., 150., 150., 150., 50., 50., // neck to nose + neck to headtop 0., 0., 0., 50., 50., 50., 50., 50., 50., 50., 50., 50., 50., // left hand 50., 50., 50., 50., 50., 50., 50., 50., 50., 50., 50., 50., 50., 50., 50., 50., 50., 50., 50., 50., // right hand 50., 50., 50., 50., 50., 50., 50., 50., 50., 50., 50., 50., 50., 50., 50., 50. }}; map_regressor_to_constraint.clear(); for (int i = 0; i < m_nCorrespond_adam2joints; i++) map_regressor_to_constraint[i] = i; } else { assert(regressor_type == 2); m_nCorrespond_adam2joints = fit_data_.adam.coco_jointConst_smcIdx.size() + 20 * 2; // COCO keypoints plus fingers int count_vertex = 0; for (int k = 0; k < fit_data_.adam.m_small_coco_reg.outerSize(); ++k) { for (SparseMatrix<double>::InnerIterator it(fit_data_.adam.m_small_coco_reg, k); it; ++it) { total_vertex.push_back(k); count_vertex++; break; // now this vertex is used, go to next vertex } } // Set up vertex constraints corres_vertex2targetpt.clear(); // total_vertex.push_back(14328); //right bigtoe total_vertex.push_back(14238); //right bigtoe corres_vertex2targetpt.push_back(std::make_pair(count_vertex++, std::vector<double>(5))); total_vertex.push_back(14288); //right littletoe corres_vertex2targetpt.push_back(std::make_pair(count_vertex++, std::vector<double>(5))); total_vertex.push_back(14357); //right heel corres_vertex2targetpt.push_back(std::make_pair(count_vertex++, std::vector<double>(5))); total_vertex.push_back(14361); //right heel corres_vertex2targetpt.push_back(std::make_pair(count_vertex++, std::vector<double>(5))); total_vertex.push_back(12239); //left bigtoe corres_vertex2targetpt.push_back(std::make_pair(count_vertex++, std::vector<double>(5))); total_vertex.push_back(12289); //left littletoe corres_vertex2targetpt.push_back(std::make_pair(count_vertex++, std::vector<double>(5))); total_vertex.push_back(12368); //left heel corres_vertex2targetpt.push_back(std::make_pair(count_vertex++, std::vector<double>(5))); total_vertex.push_back(12357); //left heel corres_vertex2targetpt.push_back(std::make_pair(count_vertex++, std::vector<double>(5))); // face detector results for (int r = 0; r < fit_data_.adam.m_correspond_adam2face70_adamIdx.rows(); ++r) { int adamVertexIdx = fit_data_.adam.m_correspond_adam2face70_adamIdx(r); total_vertex.push_back(adamVertexIdx); corres_vertex2targetpt.push_back(std::make_pair(count_vertex++, std::vector<double>(5))); } // surface constraints (e.g., densepose) if (fit_data_.fit_surface) { for(auto i = 0; i < fit_data_.surface_constraint.cols(); i++) { total_vertex.push_back(fit_data_.surface_constraint(5, i)); corres_vertex2targetpt.push_back(std::make_pair(count_vertex++, std::vector<double>(5))); } } m_nCorrespond_adam2pts = corres_vertex2targetpt.size(); PAF_connection.resize(num_PAF_constraint); PAF_connection = {{ {{2, 12, 2, 2}}, {{2, 2, 2, 1}}, {{2, 1, 2, 0}}, {{2, 12, 2, 3}}, {{2, 3, 2, 4}}, {{2, 4, 2, 5}}, {{2, 12, 2, 8}}, {{2, 8, 2, 7}}, {{2, 7, 2, 6}}, // right arm {{2, 12, 2, 9}}, {{2, 9, 2, 10}}, {{2, 10, 2, 11}}, // left arm {{2, 12, 2, 14}}, {{2, 12, 2, 13}}, // neck -> nose, neck -> head top {{2, 12, 2, 19}}, {{2, 19, 2, 2}}, {{2, 19, 2, 3}}, {{2, 8, 2, 6}}, {{2, 9, 2, 11}}, // shoulder -> wrist {{2, 2, 2, 6}}, {{2, 3, 2, 11}}, // hip -> wrist {{2, 2, 2, 0}}, {{2, 3, 2, 5}}, // hip -> ankle {{0, 20, 0, 22}}, {{0, 22, 0, 23}}, {{0, 23, 0, 24}}, {{0, 24, 0, 25}}, // left hand {{0, 20, 0, 26}}, {{0, 26, 0, 27}}, {{0, 27, 0, 28}}, {{0, 28, 0, 29}}, {{0, 20, 0, 30}}, {{0, 30, 0, 31}}, {{0, 31, 0, 32}}, {{0, 32, 0, 33}}, {{0, 20, 0, 34}}, {{0, 34, 0, 35}}, {{0, 35, 0, 36}}, {{0, 36, 0, 37}}, {{0, 20, 0, 38}}, {{0, 38, 0, 39}}, {{0, 39, 0, 40}}, {{0, 40, 0, 41}}, {{0, 21, 0, 22 + 20}}, {{0, 22 + 20, 0, 23 + 20}}, {{0, 23 + 20, 0, 24 + 20}}, {{0, 24 + 20, 0, 25 + 20}}, // right hand {{0, 21, 0, 26 + 20}}, {{0, 26 + 20, 0, 27 + 20}}, {{0, 27 + 20, 0, 28 + 20}}, {{0, 28 + 20, 0, 29 + 20}}, {{0, 21, 0, 30 + 20}}, {{0, 30 + 20, 0, 31 + 20}}, {{0, 31 + 20, 0, 32 + 20}}, {{0, 32 + 20, 0, 33 + 20}}, {{0, 21, 0, 34 + 20}}, {{0, 34 + 20, 0, 35 + 20}}, {{0, 35 + 20, 0, 36 + 20}}, {{0, 36 + 20, 0, 37 + 20}}, {{0, 21, 0, 38 + 20}}, {{0, 38 + 20, 0, 39 + 20}}, {{0, 39 + 20, 0, 40 + 20}}, {{0, 40 + 20, 0, 41 + 20}}, }}; PAF_weight.resize(num_PAF_constraint); PAF_weight = {{ 150., 150., 150., 150., 150., 150., 150., 150., 150., 150., 150., 150., 50., 50., // neck to nose + neck to headtop 0., 0., 0., 50., 50., 50., 50., 50., 50., 50., 50., 50., 50., // left hand 50., 50., 50., 50., 50., 50., 50., 50., 50., 50., 50., 50., 50., 50., 50., 50., 50., 50., 50., 50., // right hand 50., 50., 50., 50., 50., 50., 50., 50., 50., 50., 50., 50., 50., 50., 50., 50. }}; map_regressor_to_constraint.clear(); for (int i = 0; i < 20; i++) map_regressor_to_constraint[i] = i; } m_targetPts.resize((m_nCorrespond_adam2joints + m_nCorrespond_adam2pts) * 5); m_targetPts.setZero(); m_targetPts_weight.resize((m_nCorrespond_adam2joints + m_nCorrespond_adam2pts) * 5); m_targetPts_weight_buffer.resize((m_nCorrespond_adam2joints + m_nCorrespond_adam2pts) * 5); // copy the fitting target in place SetupWeight(); UpdateTarget(); // start counting from PAF int count_dim = (m_nCorrespond_adam2joints + m_nCorrespond_adam2pts) * res_dim; start_PAF = count_dim; if (fit_data_.fitPAF) count_dim += 3 * num_PAF_constraint; // counting for inner constraints start_inner = count_dim; for (auto& n: inner_dim) { count_dim += n; total_inner_dim += n; } // setting num_residuals m_nResiduals = count_dim; std::cout << "m_nCorrespond_adam2joints " << m_nCorrespond_adam2joints << std::endl; std::cout << "m_nCorrespond_adam2pts " << m_nCorrespond_adam2pts << std::endl; std::cout << "m_nResiduals " << m_nResiduals << std::endl; std::cout << "res_dim " << res_dim << std::endl; std::cout << "start_2d_dim " << start_2d_dim << std::endl; std::cout << "start_PAF " << start_PAF << std::endl; std::cout << "start_inner " << start_inner << std::endl; CostFunction::set_num_residuals(m_nResiduals); auto parameter_block_sizes = CostFunction::mutable_parameter_block_sizes(); parameter_block_sizes->clear(); parameter_block_sizes->push_back(3); // Translation parameter_block_sizes->push_back(TotalModel::NUM_JOINTS * 3); // SMPL Pose parameter_block_sizes->push_back(TotalModel::NUM_SHAPE_COEFFICIENTS); // SMPL Pose if (fit_face_exp) parameter_block_sizes->push_back(TotalModel::NUM_EXP_BASIS_COEFFICIENTS); // facial expression } void SetupWeight() { double BODYJOINT_WEIGHT_Strong = 1; double BODYJOINT_WEIGHT = 1; double HANDJOINT_WEIGHT = 0.5; double VERTEX_WEIGHT = 0; if (regressor_type == 0) { int offset = 0; for (int ic = 0; ic < fit_data_.adam.m_indices_jointConst_adamIdx.rows(); ic++) { int smcjoint = fit_data_.adam.m_indices_jointConst_smcIdx(ic); if (smcjoint == 4 || smcjoint == 10 || smcjoint == 3 || smcjoint == 9 || smcjoint == 7 || smcjoint == 13) { // m_targetPts_weight[ic] = BODYJOINT_WEIGHT_Strong; // m_targetPts_weight_buffer[ic] = BODYJOINT_WEIGHT_Strong; std::fill(m_targetPts_weight.data() + 5 * ic, m_targetPts_weight.data() + 5 * ic + 5, BODYJOINT_WEIGHT_Strong); std::fill(m_targetPts_weight_buffer.data() + 5 * ic, m_targetPts_weight_buffer.data() + 5 * ic + 5, BODYJOINT_WEIGHT_Strong); } else { // m_targetPts_weight[ic] = BODYJOINT_WEIGHT; // m_targetPts_weight_buffer[ic] = BODYJOINT_WEIGHT; std::fill(m_targetPts_weight.data() + 5 * ic, m_targetPts_weight.data() + 5 * ic + 5, BODYJOINT_WEIGHT); std::fill(m_targetPts_weight_buffer.data() + 5 * ic, m_targetPts_weight_buffer.data() + 5 * ic + 5, BODYJOINT_WEIGHT); } } offset += fit_data_.adam.m_indices_jointConst_adamIdx.rows(); if (fit_data_.lHandJoints.size() > 0) { for (int ic = 0; ic < fit_data_.adam.m_correspond_adam2lHand_adamIdx.rows(); ic++) { // m_targetPts_weight[(ic + offset)] = HANDJOINT_WEIGHT; // m_targetPts_weight_buffer[(ic + offset)] = HANDJOINT_WEIGHT; std::fill(m_targetPts_weight.data() + 5 * (ic + offset), m_targetPts_weight.data() + 5 * (ic + offset) + 5, HANDJOINT_WEIGHT); std::fill(m_targetPts_weight_buffer.data() + 5 * (ic + offset), m_targetPts_weight_buffer.data() + 5 * (ic + offset) + 5, HANDJOINT_WEIGHT); } offset += fit_data_.adam.m_correspond_adam2lHand_adamIdx.rows(); } if (fit_data_.rHandJoints.size() > 0) { for (int ic = 0; ic < fit_data_.adam.m_correspond_adam2rHand_adamIdx.rows(); ic++) { // m_targetPts_weight[ic + offset] = HANDJOINT_WEIGHT; // m_targetPts_weight_buffer[ic + offset] = HANDJOINT_WEIGHT; std::fill(m_targetPts_weight.data() + 5 * (ic + offset), m_targetPts_weight.data() + 5 * (ic + offset) + 5, HANDJOINT_WEIGHT); std::fill(m_targetPts_weight_buffer.data() + 5 * (ic + offset), m_targetPts_weight_buffer.data() + 5 * (ic + offset) + 5, HANDJOINT_WEIGHT); } offset += fit_data_.adam.m_correspond_adam2rHand_adamIdx.rows(); } for (int i = 0; i < corres_vertex2targetpt.size(); i++) { // m_targetPts_weight[i + offset] = VERTEX_WEIGHT; // m_targetPts_weight_buffer[i + offset] = VERTEX_WEIGHT; std::fill(m_targetPts_weight.data() + 5 * (i + offset), m_targetPts_weight.data() + 5 * (i + offset) + 5, VERTEX_WEIGHT); std::fill(m_targetPts_weight_buffer.data() + 5 * (i + offset), m_targetPts_weight_buffer.data() + 5 * (i + offset) + 5, VERTEX_WEIGHT); } } else if (regressor_type == 1) { for(int i = 0; i < fit_data_.adam.h36m_jointConst_smcIdx.size(); i++) { // m_targetPts_weight[i] = BODYJOINT_WEIGHT; // m_targetPts_weight_buffer[i] = BODYJOINT_WEIGHT; std::fill(m_targetPts_weight.data() + 5 * i, m_targetPts_weight.data() + 5 * i + 5, BODYJOINT_WEIGHT); std::fill(m_targetPts_weight_buffer.data() + 5 * i, m_targetPts_weight_buffer.data() + 5 * i + 5, BODYJOINT_WEIGHT); } } else { assert(regressor_type == 2); for(int i = 0; i < fit_data_.adam.coco_jointConst_smcIdx.size(); i++) { // m_targetPts_weight[i] = BODYJOINT_WEIGHT; // m_targetPts_weight_buffer[i] = BODYJOINT_WEIGHT; std::fill(m_targetPts_weight.data() + 5 * i, m_targetPts_weight.data() + 5 * i + 5, BODYJOINT_WEIGHT); std::fill(m_targetPts_weight_buffer.data() + 5 * i, m_targetPts_weight_buffer.data() + 5 * i + 5, BODYJOINT_WEIGHT); } int offset = fit_data_.adam.coco_jointConst_smcIdx.size(); for (int i = 0; i < 20 * 2; i++) { // m_targetPts_weight[offset + i] = HANDJOINT_WEIGHT; // m_targetPts_weight_buffer[offset + i] = HANDJOINT_WEIGHT; std::fill(m_targetPts_weight.data() + 5 * (i + offset), m_targetPts_weight.data() + 5 * (i + offset) + 5, HANDJOINT_WEIGHT); std::fill(m_targetPts_weight_buffer.data() + 5 * (i + offset), m_targetPts_weight_buffer.data() + 5 * (i + offset) + 5, HANDJOINT_WEIGHT); } offset += 40; for (int i = 0; i < corres_vertex2targetpt.size(); i++) { // m_targetPts_weight[i + offset] = VERTEX_WEIGHT; // m_targetPts_weight_buffer[i + offset] = VERTEX_WEIGHT; std::fill(m_targetPts_weight.data() + 5 * (i + offset), m_targetPts_weight.data() + 5 * (i + offset) + 5, VERTEX_WEIGHT); std::fill(m_targetPts_weight_buffer.data() + 5 * (i + offset), m_targetPts_weight_buffer.data() + 5 * (i + offset) + 5, VERTEX_WEIGHT); } } } void UpdateTarget() { int offset = 0; if (regressor_type == 0) { for (int ic = 0; ic < fit_data_.adam.m_indices_jointConst_adamIdx.rows(); ic++) m_targetPts.block(ic * 5, 0, 5, 1) = fit_data_.bodyJoints.block(0, fit_data_.adam.m_indices_jointConst_smcIdx(ic), 5, 1); offset += fit_data_.adam.m_indices_jointConst_adamIdx.rows(); if (fit_data_.lHandJoints.size() > 0) { for (int ic = 0; ic < fit_data_.adam.m_correspond_adam2lHand_adamIdx.rows(); ic++) m_targetPts.block((offset + ic) * 5, 0, 5, 1) = fit_data_.lHandJoints.block(0, fit_data_.adam.m_correspond_adam2lHand_lHandIdx(ic), 5, 1); offset += fit_data_.adam.m_correspond_adam2lHand_adamIdx.rows(); } if (fit_data_.rHandJoints.size() > 0) { for (int ic = 0; ic < fit_data_.adam.m_correspond_adam2rHand_adamIdx.rows(); ic++) m_targetPts.block((offset + ic) * 5, 0, 5, 1) = fit_data_.rHandJoints.block(0, fit_data_.adam.m_correspond_adam2rHand_rHandIdx(ic), 5, 1); offset += fit_data_.adam.m_correspond_adam2rHand_adamIdx.rows(); } corres_vertex2targetpt[0].second = {fit_data_.bodyJoints(0, 1), fit_data_.bodyJoints(1, 1), fit_data_.bodyJoints(2, 1), fit_data_.bodyJoints(3, 1), fit_data_.bodyJoints(4, 1)}; corres_vertex2targetpt[1].second = {fit_data_.bodyJoints(0, 16), fit_data_.bodyJoints(1, 16), fit_data_.bodyJoints(2, 16), fit_data_.bodyJoints(3, 16), fit_data_.bodyJoints(4, 16)}; corres_vertex2targetpt[2].second = {fit_data_.bodyJoints(0, 18), fit_data_.bodyJoints(1, 18), fit_data_.bodyJoints(2, 18), fit_data_.bodyJoints(3, 18), fit_data_.bodyJoints(4, 18)}; corres_vertex2targetpt[3].second = {fit_data_.bodyJoints(0, 19), fit_data_.bodyJoints(1, 19), fit_data_.bodyJoints(2, 19), fit_data_.bodyJoints(3, 19), fit_data_.bodyJoints(4, 19)}; corres_vertex2targetpt[4].second = {fit_data_.rFoot(0, 0), fit_data_.rFoot(1, 0), fit_data_.rFoot(2, 0), fit_data_.rFoot(3, 0), fit_data_.rFoot(4, 0)}; corres_vertex2targetpt[5].second = {fit_data_.rFoot(0, 1), fit_data_.rFoot(1, 1), fit_data_.rFoot(2, 1), fit_data_.rFoot(3, 1), fit_data_.rFoot(4, 1)}; corres_vertex2targetpt[6].second = {fit_data_.rFoot(0, 2), fit_data_.rFoot(1, 2), fit_data_.rFoot(2, 2), fit_data_.rFoot(3, 2), fit_data_.rFoot(4, 2)}; corres_vertex2targetpt[7].second = {fit_data_.rFoot(0, 2), fit_data_.rFoot(1, 2), fit_data_.rFoot(2, 2), fit_data_.rFoot(3, 2), fit_data_.rFoot(4, 2)}; corres_vertex2targetpt[8].second = {fit_data_.lFoot(0, 0), fit_data_.lFoot(1, 0), fit_data_.lFoot(2, 0), fit_data_.lFoot(3, 0), fit_data_.lFoot(4, 0)}; corres_vertex2targetpt[9].second = {fit_data_.lFoot(0, 1), fit_data_.lFoot(1, 1), fit_data_.lFoot(2, 1), fit_data_.lFoot(3, 1), fit_data_.lFoot(4, 1)}; corres_vertex2targetpt[10].second = {fit_data_.lFoot(0, 2), fit_data_.lFoot(1, 2), fit_data_.lFoot(2, 2), fit_data_.lFoot(3, 2), fit_data_.lFoot(4, 2)}; corres_vertex2targetpt[11].second = {fit_data_.lFoot(0, 2), fit_data_.lFoot(1, 2), fit_data_.lFoot(2, 2), fit_data_.lFoot(3, 2), fit_data_.lFoot(4, 2)}; for (int r = 0; r < fit_data_.adam.m_correspond_adam2face70_adamIdx.rows(); ++r) { int face70ID = fit_data_.adam.m_correspond_adam2face70_face70Idx(r); if (face70ID < 0) corres_vertex2targetpt[12 + r].second = {{0.0, 0.0, 0.0, 0.0, 0.0}}; else corres_vertex2targetpt[12 + r].second = {{fit_data_.faceJoints(0, face70ID), fit_data_.faceJoints(1, face70ID), fit_data_.faceJoints(2, face70ID), fit_data_.faceJoints(3, face70ID), fit_data_.faceJoints(4, face70ID)}}; } if (fit_data_.fit_surface) { const int surface_offset = 12 + fit_data_.adam.m_correspond_adam2face70_face70Idx.rows(); for (int i = 0; i < fit_data_.surface_constraint.cols(); i++) { corres_vertex2targetpt[surface_offset + i].second = {fit_data_.surface_constraint(0, i), fit_data_.surface_constraint(1, i), fit_data_.surface_constraint(2, i), fit_data_.surface_constraint(3, i), fit_data_.surface_constraint(4, i)}; } assert(fit_data_.surface_constraint.cols() + surface_offset == corres_vertex2targetpt.size()); } for (int i = 0; i < corres_vertex2targetpt.size(); i++) { std::copy(corres_vertex2targetpt[i].second.data(), corres_vertex2targetpt[i].second.data() + 5, m_targetPts.data() + 5 * (i + offset)); } } else if (regressor_type == 1) { for(int i = 0; i < fit_data_.adam.h36m_jointConst_smcIdx.size(); i++) m_targetPts.block(5 * i, 0, 5, 1) = fit_data_.bodyJoints.col(fit_data_.adam.h36m_jointConst_smcIdx[i]); if (fit_data_.fit_surface) { offset = fit_data_.adam.h36m_jointConst_smcIdx.size(); for (int i = 0; i < fit_data_.surface_constraint.cols(); i++) { corres_vertex2targetpt[i].second = {fit_data_.surface_constraint(0, i), fit_data_.surface_constraint(1, i), fit_data_.surface_constraint(2, i), fit_data_.surface_constraint(3, i), fit_data_.surface_constraint(4, i)}; } for (int i = 0; i < corres_vertex2targetpt.size(); i++) { std::copy(corres_vertex2targetpt[i].second.data(), corres_vertex2targetpt[i].second.data() + 5, m_targetPts.data() + 5 * (i + offset)); } } } else { assert (regressor_type == 2); for(int i = 0; i < fit_data_.adam.coco_jointConst_smcIdx.size(); i++) m_targetPts.block(5 * i, 0, 5, 1) = fit_data_.bodyJoints.col(fit_data_.adam.coco_jointConst_smcIdx[i]); int offset = fit_data_.adam.coco_jointConst_smcIdx.size(); if (fit_data_.lHandJoints.size() > 0) { for (int ic = 0; ic < fit_data_.adam.m_correspond_adam2lHand_adamIdx.rows(); ic++) m_targetPts.block((offset + ic) * 5, 0, 5, 1) = fit_data_.lHandJoints.block(0, fit_data_.adam.m_correspond_adam2lHand_lHandIdx(ic), 5, 1); offset += fit_data_.adam.m_correspond_adam2lHand_adamIdx.rows(); } if (fit_data_.rHandJoints.size() > 0) { for (int ic = 0; ic < fit_data_.adam.m_correspond_adam2rHand_adamIdx.rows(); ic++) m_targetPts.block((offset + ic) * 5, 0, 5, 1) = fit_data_.rHandJoints.block(0, fit_data_.adam.m_correspond_adam2rHand_rHandIdx(ic), 5, 1); offset += fit_data_.adam.m_correspond_adam2rHand_adamIdx.rows(); } assert(offset == m_nCorrespond_adam2joints); // check the number of constraints offset = 0; corres_vertex2targetpt[offset++].second = {fit_data_.rFoot(0, 0), fit_data_.rFoot(1, 0), fit_data_.rFoot(2, 0), fit_data_.rFoot(3, 0), fit_data_.rFoot(4, 0)}; corres_vertex2targetpt[offset++].second = {fit_data_.rFoot(0, 1), fit_data_.rFoot(1, 1), fit_data_.rFoot(2, 1), fit_data_.rFoot(3, 1), fit_data_.rFoot(4, 1)}; corres_vertex2targetpt[offset++].second = {fit_data_.rFoot(0, 2), fit_data_.rFoot(1, 2), fit_data_.rFoot(2, 2), fit_data_.rFoot(3, 2), fit_data_.rFoot(4, 2)}; corres_vertex2targetpt[offset++].second = {fit_data_.rFoot(0, 2), fit_data_.rFoot(1, 2), fit_data_.rFoot(2, 2), fit_data_.rFoot(3, 2), fit_data_.rFoot(4, 2)}; corres_vertex2targetpt[offset++].second = {fit_data_.lFoot(0, 0), fit_data_.lFoot(1, 0), fit_data_.lFoot(2, 0), fit_data_.lFoot(3, 0), fit_data_.lFoot(4, 0)}; corres_vertex2targetpt[offset++].second = {fit_data_.lFoot(0, 1), fit_data_.lFoot(1, 1), fit_data_.lFoot(2, 1), fit_data_.lFoot(3, 1), fit_data_.lFoot(4, 1)}; corres_vertex2targetpt[offset++].second = {fit_data_.lFoot(0, 2), fit_data_.lFoot(1, 2), fit_data_.lFoot(2, 2), fit_data_.lFoot(3, 2), fit_data_.lFoot(4, 2)}; corres_vertex2targetpt[offset++].second = {fit_data_.lFoot(0, 2), fit_data_.lFoot(1, 2), fit_data_.lFoot(2, 2), fit_data_.lFoot(3, 2), fit_data_.lFoot(4, 2)}; for (int r = 0; r < fit_data_.adam.m_correspond_adam2face70_adamIdx.rows(); ++r) { int face70ID = fit_data_.adam.m_correspond_adam2face70_face70Idx(r); if (face70ID < 0) corres_vertex2targetpt[offset++].second = {{0.0, 0.0, 0.0, 0.0, 0.0}}; else corres_vertex2targetpt[offset++].second = {{fit_data_.faceJoints(0, face70ID), fit_data_.faceJoints(1, face70ID), fit_data_.faceJoints(2, face70ID), fit_data_.faceJoints(3, face70ID), fit_data_.faceJoints(4, face70ID)}}; } if (fit_data_.fit_surface) { for (int i = 0; i < fit_data_.surface_constraint.cols(); i++) { corres_vertex2targetpt[offset++].second = {fit_data_.surface_constraint(0, i), fit_data_.surface_constraint(1, i), fit_data_.surface_constraint(2, i), fit_data_.surface_constraint(3, i), fit_data_.surface_constraint(4, i)}; } } assert(offset == m_nCorrespond_adam2pts); // check the number of constraints offset = m_nCorrespond_adam2joints; for (int i = 0; i < corres_vertex2targetpt.size(); i++) { std::copy(corres_vertex2targetpt[i].second.data(), corres_vertex2targetpt[i].second.data() + 5, m_targetPts.data() + 5 * (i + offset)); } } } void toggle_activate(bool limb, bool palm, bool finger) { if (regressor_type == 0) { for (int ic = 0; ic < fit_data_.adam.m_indices_jointConst_adamIdx.rows(); ic++) { int smcjoint = fit_data_.adam.m_indices_jointConst_smcIdx(ic); if (smcjoint != 3 && smcjoint != 6 && smcjoint != 9 && smcjoint != 12) { for (auto d = 0; d < 5; d++) m_targetPts_weight[5 * ic + d] = double(limb) * m_targetPts_weight_buffer[5 * ic + d]; } } int offset = fit_data_.adam.m_indices_jointConst_smcIdx.rows(); for (int ic = 0; ic < fit_data_.adam.m_correspond_adam2lHand_adamIdx.rows(); ic++) { if (ic % 5 == 0) for (auto d = 0; d < 5; d++) m_targetPts_weight[5 * (ic + offset) + d] = m_targetPts_weight_buffer[5 * (ic + offset) + d] * double(palm); else for (auto d = 0; d < 5; d++) m_targetPts_weight[5 * (ic + offset) + d] = m_targetPts_weight_buffer[5 * (ic + offset) + d] * double(finger); } offset += fit_data_.adam.m_correspond_adam2lHand_adamIdx.rows(); for (int ic = 0; ic < fit_data_.adam.m_correspond_adam2rHand_adamIdx.rows(); ic++) { if (ic % 5 == 0) for (auto d = 0; d < 5; d++) m_targetPts_weight[5 * (ic + offset) + d] = m_targetPts_weight_buffer[5 * (ic + offset) + d] * double(palm); else for (auto d = 0; d < 5; d++) m_targetPts_weight[5 * (ic + offset) + d] = m_targetPts_weight_buffer[5 * (ic + offset) + d] * double(finger); } } else if (regressor_type == 1) { for (int ic = 0; ic < fit_data_.adam.h36m_jointConst_smcIdx.size(); ic++) { int smcjoint = fit_data_.adam.h36m_jointConst_smcIdx[ic]; if (smcjoint != 3 && smcjoint != 6 && smcjoint != 9 && smcjoint != 12) { // m_targetPts_weight[ic] = double(limb) * m_targetPts_weight_buffer[ic]; for (auto d = 0; d < 5; d++) m_targetPts_weight[5 * ic + d] = m_targetPts_weight_buffer[5 * ic + d] * double(limb); } } // no finger joints for Human3.6M } else { assert(regressor_type == 2); for (int ic = 0; ic < fit_data_.adam.coco_jointConst_smcIdx.size(); ic++) { int smcjoint = fit_data_.adam.coco_jointConst_smcIdx[ic]; if (smcjoint != 3 && smcjoint != 6 && smcjoint != 9 && smcjoint != 12) { // m_targetPts_weight[ic] = double(limb) * m_targetPts_weight_buffer[ic]; for (auto d = 0; d < 5; d++) m_targetPts_weight[5 * ic + d] = m_targetPts_weight_buffer[5 * ic + d] * double(limb); } } int offset = fit_data_.adam.coco_jointConst_smcIdx.size(); for (int ic = 0; ic < fit_data_.adam.m_correspond_adam2lHand_adamIdx.rows(); ic++) { if (ic % 5 == 0) for (auto d = 0; d < 5; d++) m_targetPts_weight[5 * (ic + offset) + d] = m_targetPts_weight_buffer[5 * (ic + offset) + d] * double(palm); else for (auto d = 0; d < 5; d++) m_targetPts_weight[5 * (ic + offset) + d] = m_targetPts_weight_buffer[5 * (ic + offset) + d] * double(finger); } offset += fit_data_.adam.m_correspond_adam2lHand_adamIdx.rows(); for (int ic = 0; ic < fit_data_.adam.m_correspond_adam2rHand_adamIdx.rows(); ic++) { if (ic % 5 == 0) for (auto d = 0; d < 5; d++) m_targetPts_weight[5 * (ic + offset) + d] = m_targetPts_weight_buffer[5 * (ic + offset) + d] * double(palm); else for (auto d = 0; d < 5; d++) m_targetPts_weight[5 * (ic + offset) + d] = m_targetPts_weight_buffer[5 * (ic + offset) + d] * double(finger); } } } void toggle_rigid_body(bool rigid) { rigid_body = rigid; } void select_lbs( const double* c, const Eigen::VectorXd& T, // transformation const MatrixXdr &dTdP, const MatrixXdr &dTdc, MatrixXdr &outVert, double* dVdP_data, //output double* dVdc_data, //output const double* face_coeff, double* dVdfc_data ) const; void select_lbs( const double* c, const Eigen::VectorXd& T, // transformation MatrixXdr &outVert, const double* face_coeff ) const; void SparseRegress(const Eigen::SparseMatrix<double>& reg, const double* V_data, const double* dVdP_data, const double* dVdc_data, const double* dVdfc_data, double* J_data, double* dJdP_data, double* dJdc_data, double* dJdfc_data) const; virtual bool Evaluate(double const* const* parameters, double* residuals, double** jacobians) const; Eigen::VectorXd m_targetPts_weight; Eigen::VectorXd m_targetPts_weight_buffer; std::vector<float> PAF_weight; int m_nCorrespond_adam2joints; int m_nCorrespond_adam2pts; int m_nResiduals; int res_dim; // number of residuals per joint / vertex constraints private: // input data const AdamFitData& fit_data_; const int regressor_type; // setting bool rigid_body; // data for joint / projection fitting Eigen::VectorXd m_targetPts; int start_2d_dim; // data for vertex fitting std::vector<int> total_vertex; // all vertices that needs to be computed std::vector< std::pair<int, std::vector<double>> > corres_vertex2targetpt; // vertices used as constraints // counter // data for PAF fitting const int num_PAF_constraint; std::vector<std::array<uint, 4>> PAF_connection; int start_PAF; // data for inner fitting std::vector<uint> inner_dim; const int num_inner; int total_inner_dim; static const int DEFINED_INNER_CONSTRAINTS = 1; int start_inner; // parent index std::array<std::vector<int>, TotalModel::NUM_JOINTS> parentIndexes; // jacobians double* dVdP_data; double* dVdc_data; double* dOdP_data; double* dOdc_data; double* dVdfc_data; double* dOdfc_data; double* dTJdfc_data; std::map<int, int> map_regressor_to_constraint; const bool fit_face_exp; const bool euler_; };
46.831349
238
0.644452
27cbd24da714fc3a166136c41f123baba0c503ca
426
h
C
SCCategories/Classes/UIKit/UIDevice/UIDevice+SCDiskInfo.h
SoloChow/SCCategories
ec8a10a4f7187eb2e04ac4e7714288dbab96ab22
[ "MIT" ]
4
2019-05-07T11:46:57.000Z
2020-11-03T08:54:53.000Z
SCCategories/Classes/UIKit/UIDevice/UIDevice+SCDiskInfo.h
SoloChow/SCCategories
ec8a10a4f7187eb2e04ac4e7714288dbab96ab22
[ "MIT" ]
null
null
null
SCCategories/Classes/UIKit/UIDevice/UIDevice+SCDiskInfo.h
SoloChow/SCCategories
ec8a10a4f7187eb2e04ac4e7714288dbab96ab22
[ "MIT" ]
null
null
null
// // UIDevice+SCDiskInfo.h // Pods // // Created by Solo on 17/2/11. // // 设备硬盘信息 #import <UIKit/UIKit.h> @interface UIDevice (SCDiskInfo) @property (nonatomic, readonly) int64_t sc_diskSpace; ///< 当前硬盘总空间(单位字节, error -> -1) @property (nonatomic, readonly) int64_t sc_diskSpaceFree; ///< 当前硬盘空闲空间(单位字节, error -> -1) @property (nonatomic, readonly) int64_t sc_diskSpaceUsed; ///< 当前硬盘已使用空间(单位字节, error -> -1) @end
23.666667
91
0.680751
7dad41c5116b96126c9e47f872b3a745bc61c1cc
4,151
h
C
include/mcc/core/vint.h
awsdert/mitsy
805bb63da117aa3f17795c85c3f2214ba12b895b
[ "MIT" ]
2
2019-10-26T08:09:29.000Z
2020-08-07T10:54:30.000Z
include/mcc/core/vint.h
awsdert/mitsy
805bb63da117aa3f17795c85c3f2214ba12b895b
[ "MIT" ]
3
2019-11-02T05:38:38.000Z
2019-12-31T21:17:19.000Z
include/mcc/core/vint.h
awsdert/mitsy
805bb63da117aa3f17795c85c3f2214ba12b895b
[ "MIT" ]
1
2019-11-02T05:30:35.000Z
2019-11-02T05:30:35.000Z
#ifndef INC_MCC_VINT_H #define INC_MCC_VINT_H #include <mcc/bitsof.h> #include <mcc/core/get.h> #include <errno.h> #include <string.h> #include <stdlib.h> #include <stdio.h> #include <time.h> #include <assert.h> #ifdef MCC_VINT_SEG_USE_LONG typedef unsigned long mcc_vint_seg_t; #define MCC_VINT_SEG_END_BIT (ULONG_MAX & LONG_MIN) #define MCC_VINT_SEG_PRI_PFX "l" #define MCC_VINT_SEG_SCN_PFX "l" #else typedef unsigned char mcc_vint_seg_t; #define MCC_VINT_SEG_END_BIT (UCHAR_MAX & SCHAR_MIN) #define MCC_VINT_SEG_PRI_PFX "" #define MCC_VINT_SEG_SCN_PFX "hh" #endif typedef struct mcc_bit { mcc_vint_seg_t i; mcc_vint_seg_t *seg; mcc_vint_seg_t b; mcc_vint_seg_t bit; } mcc_bit_t; void mcc_printb( char const *pfx, void *addr, size_t bits, char const *sfx ); int mcc_bit_op_cmp( mcc_bit_t num, mcc_bit_t val ); mcc_bit_t mcc_bit_op_inc( mcc_bit_t num ); mcc_bit_t mcc_bit_op_dec( mcc_bit_t num ); mcc_bit_t mcc__bit_op_add( mcc_bit_t num, mcc_vint_seg_t bits ); mcc_bit_t mcc__bit_op_sub( mcc_bit_t num, mcc_vint_seg_t bits ); mcc_bit_t mcc_bit_op_dec_for_bit( mcc_bit_t stop, mcc_bit_t zero ); typedef struct mcc__vint { int exit; size_t size; mcc_bit_t zero, stop, sign; mcc_vec_t buff; } mcc_vint_t, mcc_uvint_t; /** @brief Converts a character to it's integer equivalent * @param character the character returned by getc() or similar * @param lowercase added to result of character - 'a' * @param uppercase added to result of character - 'A' * @return -1 on failure or integer equivalent of the character **/ int mcc_geti( long character, long lowercase, long uppercase ); int mcc__vint_printb( mcc_vint_t num ); int mcc__vint_scanb( mcc_vint_t num ); int mcc__vint_get_sign( struct mcc__vint num ); int mcc_vint_validate( struct mcc__vint *num ); int mcc_vint_validate2( struct mcc__vint *num, struct mcc__vint *val ); int mcc_vint_validate3( struct mcc__vint *num, struct mcc__vint *val, struct mcc__vint *var ); void mcc_vint_print( struct mcc__vint num, mcc_vint_seg_t min ); struct mcc__vint mcc_vint_wrap( bool has_sign, void *addr, size_t size ); int mcc_vint_size( struct mcc__vint *num, size_t size ); int mcc_vint_fill( struct mcc__vint num, struct mcc__vint val ); int mcc_vint_to_val( struct mcc__vint num, intmax_t val ); int mcc_vint_to_uval( struct mcc__vint num, uintmax_t val ); int mcc_vint_size_and_fill( struct mcc__vint *num, struct mcc__vint val ); int mcc__vint_op_cmp( struct mcc__vint num, struct mcc__vint val ); #define mcc__vint_is_nil( num ) (mcc__vint_op_cmp( num, (struct mcc__vint){0} ) == 0) #define mcc__vint_is_eql( num, val ) (mcc__vint_op_cmp( num, val ) == 0) #define mcc__vint_is_neq( num, val ) (mcc__vint_op_cmp( num, val ) != 0) #define mcc__vint_is_gth( num, val ) (mcc__vint_op_cmp( num, val ) > 0) #define mcc__vint_is_gte( num, val ) (mcc__vint_op_cmp( num, val ) >= 0) #define mcc__vint_is_lth( num, val ) (mcc__vint_op_cmp( num, val ) < 0) #define mcc__vint_is_lte( num, val ) (mcc__vint_op_cmp( num, val ) <= 0) int mcc__vint_op_not( struct mcc__vint num ); int mcc__vint_op_inc( struct mcc__vint num ); int mcc__vint_op_dec( struct mcc__vint num ); int mcc__vint_op_aor( struct mcc__vint num, struct mcc__vint val ); int mcc__vint_op_xor( struct mcc__vint num, struct mcc__vint val ); int mcc__vint_op_and( struct mcc__vint num, struct mcc__vint val ); int mcc___vint_op_shl( struct mcc__vint num, mcc_vint_seg_t bits ); int mcc___vint_op_shr( struct mcc__vint num, mcc_vint_seg_t bits, bool neg ); int mcc__vint_op_shl( struct mcc__vint num, struct mcc__vint val ); int mcc__vint_op_shr( struct mcc__vint num, struct mcc__vint val, bool neg ); int mcc__vint_op_add( struct mcc__vint num, struct mcc__vint val ); int mcc___vint_op_mul( struct mcc__vint num, struct mcc__vint val, struct mcc__vint tmp ); int mcc__vint_op_mul( struct mcc__vint num, struct mcc__vint val ); int mcc__vint_op_sub( struct mcc__vint num, struct mcc__vint val ); int mcc___vint_op_div( struct mcc__vint num, struct mcc__vint val, struct mcc__vint rem ); int mcc__vint_op_div( struct mcc__vint num, struct mcc__vint val ); int mcc__vint_op_mod( struct mcc__vint num, struct mcc__vint val ); #endif
44.159574
94
0.780294
70289dcb765e55be7789fc0e4d69d63fd0432e58
1,843
h
C
third_party/silabs/gecko_sdk_suite/v1.0/hardware/kit/common/drivers/retargettextdisplay.h
syin2/openthread
a9f42768ec221380f42bfd311bc68e784b2163a6
[ "BSD-3-Clause" ]
1
2018-12-31T08:12:49.000Z
2018-12-31T08:12:49.000Z
third_party/silabs/gecko_sdk_suite/v1.0/hardware/kit/common/drivers/retargettextdisplay.h
syin2/openthread
a9f42768ec221380f42bfd311bc68e784b2163a6
[ "BSD-3-Clause" ]
null
null
null
third_party/silabs/gecko_sdk_suite/v1.0/hardware/kit/common/drivers/retargettextdisplay.h
syin2/openthread
a9f42768ec221380f42bfd311bc68e784b2163a6
[ "BSD-3-Clause" ]
null
null
null
/**************************************************************************//** * @file retargettextdisplay.h * @brief Retarget stdout to text display module. * @version 5.1.3 ****************************************************************************** * @section License * <b>Copyright 2015 Silicon Labs, Inc. http://www.silabs.com</b> ******************************************************************************* * * This file is licensed under the Silabs License Agreement. See the file * "Silabs_License_Agreement.txt" for details. Before using this software for * any purpose, you must agree to the terms of that agreement. * ******************************************************************************/ #ifndef _RETARGETTEXTDISPLAY_H_ #define _RETARGETTEXTDISPLAY_H_ #include "emstatus.h" /***************************************************************************//** * @addtogroup kitdrv * @{ ******************************************************************************/ /***************************************************************************//** * @addtogroup RetargetIo * @{ ******************************************************************************/ #ifdef __cplusplus extern "C" { #endif #if defined(__CROSSWORKS_ARM) int __putchar(int ch); int __getchar(void); #endif /******************************************************************************* ************************** FUNCTION PROTOTYPES ************************** ******************************************************************************/ EMSTATUS RETARGET_TextDisplayInit(void); EMSTATUS RETARGET_WriteString(char* str); #ifdef __cplusplus } #endif /** @} (end group RetargetIo) */ /** @} (end group Drivers) */ #endif /* _RETARGETTEXTDISPLAY_H_ */
32.333333
81
0.36408
2ab05cafdac3bf992aebdec03d74f6dc0c06bff4
22,882
c
C
project/code/ESP32/Demo/components/lcd/lcd.c
ATmega8/kiterf
8a6bf34747102c84da977304b04d857f64adabb1
[ "MIT" ]
19
2019-04-07T13:43:28.000Z
2021-09-28T22:21:00.000Z
project/code/ESP32/Demo/components/lcd/lcd.c
ATmega8/kiterf
8a6bf34747102c84da977304b04d857f64adabb1
[ "MIT" ]
5
2019-04-17T11:55:15.000Z
2020-04-01T02:22:55.000Z
project/code/ESP32/Demo/components/lcd/lcd.c
ATmega8/kiterf
8a6bf34747102c84da977304b04d857f64adabb1
[ "MIT" ]
10
2019-04-07T18:46:03.000Z
2020-10-17T11:14:01.000Z
#include <stdio.h> #include <string.h> #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "freertos/semphr.h" #include "esp_heap_caps.h" #include "lcd.h" static spi_device_handle_t spi; static SemaphoreHandle_t lcd_write_mux = NULL; static void lcd_delay_ms(uint32_t time) { vTaskDelay(time / portTICK_RATE_MS); } void lcd_spi_pre_transfer_callback(spi_transaction_t *t) { int dc = (int)t->user; lcd_set_dc(dc); } static void lcd_write_cmd(uint8_t data) { xSemaphoreTake(lcd_write_mux, portMAX_DELAY); spi_transaction_t t; memset(&t, 0, sizeof(t)); //Zero out the transaction t.length = 8; //Command is 8 bits t.tx_buffer = &data; //The data is the cmd itself t.user = (void*)0; //D/C needs to be set to 0 spi_device_polling_transmit(spi, &t); //Transmit! xSemaphoreGive(lcd_write_mux); } static void lcd_write_byte(uint8_t data) { xSemaphoreTake(lcd_write_mux, portMAX_DELAY); spi_transaction_t t; memset(&t, 0, sizeof(t)); //Zero out the transaction t.length = 8; //data is 8 bits t.tx_buffer = &data; //The data is the buf itself t.user = (void*)1; //D/C needs to be set to 1 spi_device_polling_transmit(spi, &t); //Transmit! xSemaphoreGive(lcd_write_mux); } static void lcd_hx8357_write_reg(uint8_t index, uint8_t data) { lcd_write_cmd(index); lcd_write_byte(data); } void lcd_write_data(uint16_t *data, int len) { if (len <= 0) { return; } if (data == NULL) { return; } xSemaphoreTake(lcd_write_mux, portMAX_DELAY); spi_transaction_t t, *rtrans; memset(&t, 0, sizeof(t)); //Zero out the transaction t.length = 16 * len; t.tx_buffer = data; t.user = (void*)1; //D/C needs to be set to 1 spi_device_queue_trans(spi, &t, portMAX_DELAY); spi_device_get_trans_result(spi, &rtrans, portMAX_DELAY); xSemaphoreGive(lcd_write_mux); } void lcd_rst() { lcd_set_res(0); lcd_delay_ms(1000); lcd_set_res(1); lcd_delay_ms(1000); } static void lcd_st7789v_config() { /* Memory Data Access Control, MX=MV=1, MY=ML=MH=0, RGB=0 */ lcd_write_cmd(0x36); lcd_write_byte((1<<5)|(1<<6)); /* Interface Pixel Format, 16bits/pixel for RGB/MCU interface */ lcd_write_cmd(0x3A); lcd_write_byte(0x55); /* Porch Setting */ lcd_write_cmd(0xB2); lcd_write_byte(0x0c); lcd_write_byte(0x0c); lcd_write_byte(0x00); lcd_write_byte(0x33); lcd_write_byte(0x33); /* Gate Control, Vgh=13.65V, Vgl=-10.43V */ lcd_write_cmd(0xB7); lcd_write_byte(0x45); /* VCOM Setting, VCOM=1.175V */ lcd_write_cmd(0xBB); lcd_write_byte(0x2B); /* LCM Control, XOR: BGR, MX, MH */ lcd_write_cmd(0xC0); lcd_write_byte(0x2C); /* VDV and VRH Command Enable, enable=1 */ lcd_write_cmd(0xC2); lcd_write_byte(0x01); lcd_write_byte(0xff); /* VRH Set, Vap=4.4+... */ lcd_write_cmd(0xC3); lcd_write_byte(0x11); /* VDV Set, VDV=0 */ lcd_write_cmd(0xC4); lcd_write_byte(0x20); /* Frame Rate Control, 60Hz, inversion=0 */ lcd_write_cmd(0xC6); lcd_write_byte(0x0f); /* Power Control 1, AVDD=6.8V, AVCL=-4.8V, VDDS=2.3V */ lcd_write_cmd(0xD0); lcd_write_byte(0xA4); // lcd_write_byte(0xA1); /* Positive Voltage Gamma Control */ lcd_write_cmd(0xE0); lcd_write_byte(0xD0); lcd_write_byte(0x00); lcd_write_byte(0x05); lcd_write_byte(0x0E); lcd_write_byte(0x15); lcd_write_byte(0x0D); lcd_write_byte(0x37); lcd_write_byte(0x43); lcd_write_byte(0x47); lcd_write_byte(0x09); lcd_write_byte(0x15); lcd_write_byte(0x12); lcd_write_byte(0x16); lcd_write_byte(0x19); /* Negative Voltage Gamma Control */ lcd_write_cmd(0xE1); lcd_write_byte(0xD0); lcd_write_byte(0x00); lcd_write_byte(0x05); lcd_write_byte(0x0D); lcd_write_byte(0x0C); lcd_write_byte(0x06); lcd_write_byte(0x2D); lcd_write_byte(0x44); lcd_write_byte(0x40); lcd_write_byte(0x0E); lcd_write_byte(0x1C); lcd_write_byte(0x18); lcd_write_byte(0x16); lcd_write_byte(0x19); /* Sleep Out */ lcd_write_cmd(0x11); lcd_delay_ms(100); /* Display On */ lcd_write_cmd(0x29); lcd_delay_ms(100); } static void lcd_ili9341_config() { /* Power contorl B, power control = 0, DC_ENA = 1 */ lcd_write_cmd(0xCF); lcd_write_byte(0x00); lcd_write_byte(0x83); lcd_write_byte(0X30); /* Power on sequence control, * cp1 keeps 1 frame, 1st frame enable * vcl = 0, ddvdh=3, vgh=1, vgl=2 * DDVDH_ENH=1 */ lcd_write_cmd(0xED); lcd_write_byte(0x64); lcd_write_byte(0x03); lcd_write_byte(0X12); lcd_write_byte(0X81); /* Driver timing control A, * non-overlap=default +1 * EQ=default - 1, CR=default * pre-charge=default - 1 */ lcd_write_cmd(0xE8); lcd_write_byte(0x85); lcd_write_byte(0x01); lcd_write_byte(0x79); /* Power control A, Vcore=1.6V, DDVDH=5.6V */ lcd_write_cmd(0xCB); lcd_write_byte(0x39); lcd_write_byte(0x2C); lcd_write_byte(0x00); lcd_write_byte(0x34); lcd_write_byte(0x02); /* Pump ratio control, DDVDH=2xVCl */ lcd_write_cmd(0xF7); lcd_write_byte(0x20); /* Driver timing control, all=0 unit */ lcd_write_cmd(0xEA); lcd_write_byte(0x00); lcd_write_byte(0x00); /* Power control 1, GVDD=4.75V */ lcd_write_cmd(0xC0); lcd_write_byte(0x26); /* Power control 2, DDVDH=VCl*2, VGH=VCl*7, VGL=-VCl*3 */ lcd_write_cmd(0xC1); lcd_write_byte(0x11); /* VCOM control 1, VCOMH=4.025V, VCOML=-0.950V */ lcd_write_cmd(0xC5); lcd_write_byte(0x35); lcd_write_byte(0x3E); /* VCOM control 2, VCOMH=VMH-2, VCOML=VML-2 */ lcd_write_cmd(0xC7); lcd_write_byte(0xBE); /* Memory access contorl, MX=MY=0, MV=1, ML=0, BGR=1, MH=0 */ lcd_write_cmd(0x36); lcd_write_byte(0x28); /* Pixel format, 16bits/pixel for RGB/MCU interface */ lcd_write_cmd(0x3A); lcd_write_byte(0x55); /* Frame rate control, f=fosc, 70Hz fps */ lcd_write_cmd(0xB1); lcd_write_byte(0x00); lcd_write_byte(0x1B); /* Enable 3G, disabled */ lcd_write_cmd(0xF2); lcd_write_byte(0x08); /* Gamma set, curve 1 */ lcd_write_cmd(0x26); lcd_write_byte(0x01); /* Positive gamma correction */ lcd_write_cmd(0xE0); lcd_write_byte(0x1F); lcd_write_byte(0x1A); lcd_write_byte(0x18); lcd_write_byte(0x0A); lcd_write_byte(0x0F); lcd_write_byte(0x06); lcd_write_byte(0x45); lcd_write_byte(0X87); lcd_write_byte(0x32); lcd_write_byte(0x0A); lcd_write_byte(0x07); lcd_write_byte(0x02); lcd_write_byte(0x07); lcd_write_byte(0x05); lcd_write_byte(0x00); /* Negative gamma correction */ lcd_write_cmd(0XE1); lcd_write_byte(0x00); lcd_write_byte(0x25); lcd_write_byte(0x27); lcd_write_byte(0x05); lcd_write_byte(0x10); lcd_write_byte(0x09); lcd_write_byte(0x3A); lcd_write_byte(0x78); lcd_write_byte(0x4D); lcd_write_byte(0x05); lcd_write_byte(0x18); lcd_write_byte(0x0D); lcd_write_byte(0x38); lcd_write_byte(0x3A); lcd_write_byte(0x1F); /* Column address set, SC=0, EC=0xEF */ lcd_write_cmd(0x2A); lcd_write_byte(0x00); lcd_write_byte(0x00); lcd_write_byte(0x00); lcd_write_byte(0xEF); /* Page address set, SP=0, EP=0x013F */ lcd_write_cmd(0x2B); lcd_write_byte(0x00); lcd_write_byte(0x00); lcd_write_byte(0x01); lcd_write_byte(0x3f); /* Memory write */ lcd_write_cmd(0x2C); // lcd_write_byte(0); /* Entry mode set, Low vol detect disabled, normal display */ lcd_write_cmd(0xB7); lcd_write_byte(0x07); /* Display function control */ lcd_write_cmd(0xB6); lcd_write_byte(0x0A); lcd_write_byte(0x82); lcd_write_byte(0x27); lcd_write_byte(0x00); /* Sleep out */ lcd_write_cmd(0x11); lcd_delay_ms(100); /* Display on */ lcd_write_cmd(0x29); lcd_delay_ms(100); } static void lcd_hx8357_set_index(unsigned int Xstart,unsigned int Xend,unsigned int Ystart,unsigned int Yend) { //HX8357-A lcd_hx8357_write_reg(0x80,Ystart>>8); // Set CAC=0x0000 lcd_hx8357_write_reg(0x81,Ystart); lcd_hx8357_write_reg(0x82,Xstart>>8); // Set RAC=0x0000 lcd_hx8357_write_reg(0x83,Xstart); lcd_hx8357_write_reg(0x02,Xstart>>8); lcd_hx8357_write_reg(0x03,Xstart); //Column Start lcd_hx8357_write_reg(0x04,Xend>>8); lcd_hx8357_write_reg(0x05,Xend); //Column End lcd_hx8357_write_reg(0x06,Ystart>>8); lcd_hx8357_write_reg(0x07,Ystart); //Row Start lcd_hx8357_write_reg(0x08,Yend>>8); lcd_hx8357_write_reg(0x09,Yend); //Row End lcd_write_cmd(0x22); } static void lcd_hx8357_config() { // LCD_FSMC_Config(); // LCD_Rst(); //================= Command page 0 ================= lcd_hx8357_write_reg(0xFF,0x00); // Command page 0 lcd_delay_ms(15); lcd_hx8357_write_reg(0x1A,0x04);//VGH VGL VCL DDVDH lcd_hx8357_write_reg(0x1B,0x1C); // Power Settng lcd_hx8357_write_reg(0x23,0x94); // Set VCOM offset, VMF=0x52 lcd_hx8357_write_reg(0x24,0x69); // Set VCOMH voltage, VHH=0x64 lcd_hx8357_write_reg(0x25,0x63); // Set VCOML voltage, VML=0x71 lcd_hx8357_write_reg(0x19,0x01); lcd_delay_ms(10); lcd_hx8357_write_reg(0x1A,0x00);//VGH VGL VCL DDVDH lcd_hx8357_write_reg(0x1F,0x8A);// lcd_hx8357_write_reg(0x01,0x00);// lcd_hx8357_write_reg(0x1C,0x05);// lcd_hx8357_write_reg(0x1F,0x82);// lcd_delay_ms(10); lcd_hx8357_write_reg(0x1F,0x92);// lcd_delay_ms(10); lcd_hx8357_write_reg(0x1F,0xD4);// // Set GRAM aea 320x480 lcd_hx8357_write_reg(0x02,0x00); lcd_hx8357_write_reg(0x03,0x00); lcd_hx8357_write_reg(0x04,0x01); lcd_hx8357_write_reg(0x05,0x3F); lcd_hx8357_write_reg(0x06,0x00); lcd_hx8357_write_reg(0x07,0x00); lcd_hx8357_write_reg(0x08,0x01); lcd_hx8357_write_reg(0x09,0xDF); lcd_hx8357_write_reg(0x16,0x88);//set my mx mv bgr... lcd_hx8357_write_reg(0x17,0x55);//262-bit/pixel 0X60 ;262-bit/pixel 0X50 lcd_hx8357_write_reg(0x18,0x21); //Fosc=130%*5.2MHZ 21 lcd_hx8357_write_reg(0x1D,0x00); // FS0[1:0]=01, Set the operating frequency of the step-up circuit 1 lcd_hx8357_write_reg(0x1E,0x00); lcd_hx8357_write_reg(0x26,0x33); lcd_hx8357_write_reg(0x27,0x01); lcd_hx8357_write_reg(0x29,0x00); lcd_hx8357_write_reg(0x2A,0x00); lcd_hx8357_write_reg(0x2B,0x01);//0A lcd_hx8357_write_reg(0x2C,0x0A); lcd_hx8357_write_reg(0x2D,0x20); lcd_hx8357_write_reg(0x2E,0xA3); lcd_hx8357_write_reg(0x2F,0x00);//00 100416 lcd_hx8357_write_reg(0x31,0x00);//RGB MODE1 0X03=RGB MODE2 lcd_hx8357_write_reg(0x32,0x00); lcd_hx8357_write_reg(0x33,0x08); lcd_hx8357_write_reg(0x34,0x08); lcd_hx8357_write_reg(0x36,0x02);//REV // Gamma lcd_hx8357_write_reg(0x40,0x01); lcd_hx8357_write_reg(0x41,0x0F); lcd_hx8357_write_reg(0x42,0x0F); lcd_hx8357_write_reg(0x43,0x26); lcd_hx8357_write_reg(0x44,0x2C); lcd_hx8357_write_reg(0x45,0x3C); lcd_hx8357_write_reg(0x46,0x0B); lcd_hx8357_write_reg(0x47,0x5F); lcd_hx8357_write_reg(0x48,0x00); lcd_hx8357_write_reg(0x49,0x06); lcd_hx8357_write_reg(0x4A,0x09); lcd_hx8357_write_reg(0x4B,0x0E); lcd_hx8357_write_reg(0x4C,0x16); lcd_hx8357_write_reg(0x50,0x01); lcd_hx8357_write_reg(0x51,0x1D); lcd_hx8357_write_reg(0x52,0x21); lcd_hx8357_write_reg(0x53,0x3A); lcd_hx8357_write_reg(0x54,0x39); lcd_hx8357_write_reg(0x55,0x3F); lcd_hx8357_write_reg(0x56,0x2D); lcd_hx8357_write_reg(0x57,0x7F); lcd_hx8357_write_reg(0x58,0x02); lcd_hx8357_write_reg(0x59,0x15); lcd_hx8357_write_reg(0x5A,0x1B); lcd_hx8357_write_reg(0x5B,0x1B); lcd_hx8357_write_reg(0x5C,0x1A); lcd_hx8357_write_reg(0x5D,0x55); //================= Command page 1 ================= lcd_hx8357_write_reg(0xff,0x01); lcd_hx8357_write_reg(0x00,0x01); lcd_hx8357_write_reg(0x01,0x00); lcd_hx8357_write_reg(0x02,0x01); lcd_hx8357_write_reg(0x03,0x03); lcd_hx8357_write_reg(0x04,0x05); lcd_hx8357_write_reg(0x05,0x06); lcd_hx8357_write_reg(0x06,0x08); lcd_hx8357_write_reg(0x07,0x0C); lcd_hx8357_write_reg(0x08,0x0E); lcd_hx8357_write_reg(0x09,0x11); lcd_hx8357_write_reg(0x0A,0x12); lcd_hx8357_write_reg(0x0B,0x14); lcd_hx8357_write_reg(0x0C,0x1B); lcd_hx8357_write_reg(0x0D,0x23); lcd_hx8357_write_reg(0x0E,0x29); lcd_hx8357_write_reg(0x0F,0x2F); lcd_hx8357_write_reg(0x10,0x34); lcd_hx8357_write_reg(0x11,0x39); lcd_hx8357_write_reg(0x12,0x3E); lcd_hx8357_write_reg(0x13,0x43); lcd_hx8357_write_reg(0x14,0x48); lcd_hx8357_write_reg(0x15,0x4C); lcd_hx8357_write_reg(0x16,0x51); lcd_hx8357_write_reg(0x17,0x55); lcd_hx8357_write_reg(0x18,0x59); lcd_hx8357_write_reg(0x19,0x5D); lcd_hx8357_write_reg(0x1A,0x60); lcd_hx8357_write_reg(0x1B,0x64); lcd_hx8357_write_reg(0x1C,0x68); lcd_hx8357_write_reg(0x1D,0x6C); lcd_hx8357_write_reg(0x1E,0x70); lcd_hx8357_write_reg(0x1F,0x73); lcd_hx8357_write_reg(0x20,0x77); lcd_hx8357_write_reg(0x21,0x7B); lcd_hx8357_write_reg(0x22,0x7F); lcd_hx8357_write_reg(0x23,0x83); lcd_hx8357_write_reg(0x24,0x87); lcd_hx8357_write_reg(0x25,0x8A); lcd_hx8357_write_reg(0x26,0x8E); lcd_hx8357_write_reg(0x27,0x92); lcd_hx8357_write_reg(0x28,0x96); lcd_hx8357_write_reg(0x29,0x9A); lcd_hx8357_write_reg(0x2A,0x9F); lcd_hx8357_write_reg(0x2B,0xA3); lcd_hx8357_write_reg(0x2C,0xA7); lcd_hx8357_write_reg(0x2D,0xAC); lcd_hx8357_write_reg(0x2E,0xAF); lcd_hx8357_write_reg(0x2F,0xB3); lcd_hx8357_write_reg(0x30,0xB7); lcd_hx8357_write_reg(0x31,0xBA); lcd_hx8357_write_reg(0x32,0xBE); lcd_hx8357_write_reg(0x33,0xC3); lcd_hx8357_write_reg(0x34,0xC7); lcd_hx8357_write_reg(0x35,0xCC); lcd_hx8357_write_reg(0x36,0xD1); lcd_hx8357_write_reg(0x37,0xD7); lcd_hx8357_write_reg(0x38,0xDD); lcd_hx8357_write_reg(0x39,0xE3); lcd_hx8357_write_reg(0x3A,0xE8); lcd_hx8357_write_reg(0x3B,0xEA); lcd_hx8357_write_reg(0x3C,0xEC); lcd_hx8357_write_reg(0x3D,0xEF); lcd_hx8357_write_reg(0x3E,0xF3); lcd_hx8357_write_reg(0x3F,0xF6); lcd_hx8357_write_reg(0x40,0xFE); lcd_hx8357_write_reg(0x41,0x00); lcd_hx8357_write_reg(0x42,0x01); lcd_hx8357_write_reg(0x43,0x03); lcd_hx8357_write_reg(0x44,0x05); lcd_hx8357_write_reg(0x45,0x06); lcd_hx8357_write_reg(0x46,0x08); lcd_hx8357_write_reg(0x47,0x0C); lcd_hx8357_write_reg(0x48,0x0E); lcd_hx8357_write_reg(0x49,0x11); lcd_hx8357_write_reg(0x4A,0x12); lcd_hx8357_write_reg(0x4B,0x14); lcd_hx8357_write_reg(0x4C,0x1B); lcd_hx8357_write_reg(0x4D,0x23); lcd_hx8357_write_reg(0x4E,0x29); lcd_hx8357_write_reg(0x4F,0x2F); lcd_hx8357_write_reg(0x50,0x34); lcd_hx8357_write_reg(0x51,0x39); lcd_hx8357_write_reg(0x52,0x3E); lcd_hx8357_write_reg(0x53,0x43); lcd_hx8357_write_reg(0x54,0x48); lcd_hx8357_write_reg(0x55,0x4C); lcd_hx8357_write_reg(0x56,0x51); lcd_hx8357_write_reg(0x57,0x55); lcd_hx8357_write_reg(0x58,0x59); lcd_hx8357_write_reg(0x59,0x5D); lcd_hx8357_write_reg(0x5A,0x60); lcd_hx8357_write_reg(0x5B,0x64); lcd_hx8357_write_reg(0x5C,0x68); lcd_hx8357_write_reg(0x5D,0x6C); lcd_hx8357_write_reg(0x5E,0x70); lcd_hx8357_write_reg(0x5F,0x73); lcd_hx8357_write_reg(0x60,0x77); lcd_hx8357_write_reg(0x61,0x7B); lcd_hx8357_write_reg(0x62,0x7F); lcd_hx8357_write_reg(0x63,0x83); lcd_hx8357_write_reg(0x64,0x87); lcd_hx8357_write_reg(0x65,0x8A); lcd_hx8357_write_reg(0x66,0x8E); lcd_hx8357_write_reg(0x67,0x92); lcd_hx8357_write_reg(0x68,0x96); lcd_hx8357_write_reg(0x69,0x9A); lcd_hx8357_write_reg(0x6A,0x9F); lcd_hx8357_write_reg(0x6B,0xA3); lcd_hx8357_write_reg(0x6C,0xA7); lcd_hx8357_write_reg(0x6D,0xAC); lcd_hx8357_write_reg(0x6E,0xAF); lcd_hx8357_write_reg(0x6F,0xB3); lcd_hx8357_write_reg(0x70,0xB7); lcd_hx8357_write_reg(0x71,0xBA); lcd_hx8357_write_reg(0x72,0xBE); lcd_hx8357_write_reg(0x73,0xC3); lcd_hx8357_write_reg(0x74,0xC7); lcd_hx8357_write_reg(0x75,0xCC); lcd_hx8357_write_reg(0x76,0xD1); lcd_hx8357_write_reg(0x77,0xD7); lcd_hx8357_write_reg(0x78,0xDD); lcd_hx8357_write_reg(0x79,0xE3); lcd_hx8357_write_reg(0x7A,0xE8); lcd_hx8357_write_reg(0x7B,0xEA); lcd_hx8357_write_reg(0x7C,0xEC); lcd_hx8357_write_reg(0x7D,0xEF); lcd_hx8357_write_reg(0x7E,0xF3); lcd_hx8357_write_reg(0x7F,0xF6); lcd_hx8357_write_reg(0x80,0xFE); lcd_hx8357_write_reg(0x81,0x00); lcd_hx8357_write_reg(0x82,0x01); lcd_hx8357_write_reg(0x83,0x03); lcd_hx8357_write_reg(0x84,0x05); lcd_hx8357_write_reg(0x85,0x06); lcd_hx8357_write_reg(0x86,0x08); lcd_hx8357_write_reg(0x87,0x0C); lcd_hx8357_write_reg(0x88,0x0E); lcd_hx8357_write_reg(0x89,0x11); lcd_hx8357_write_reg(0x8A,0x12); lcd_hx8357_write_reg(0x8B,0x14); lcd_hx8357_write_reg(0x8C,0x1B); lcd_hx8357_write_reg(0x8D,0x23); lcd_hx8357_write_reg(0x8E,0x29); lcd_hx8357_write_reg(0x8F,0x2F); lcd_hx8357_write_reg(0x90,0x34); lcd_hx8357_write_reg(0x91,0x39); lcd_hx8357_write_reg(0x92,0x3E); lcd_hx8357_write_reg(0x93,0x43); lcd_hx8357_write_reg(0x94,0x48); lcd_hx8357_write_reg(0x95,0x4C); lcd_hx8357_write_reg(0x96,0x51); lcd_hx8357_write_reg(0x97,0x55); lcd_hx8357_write_reg(0x98,0x59); lcd_hx8357_write_reg(0x99,0x5D); lcd_hx8357_write_reg(0x9A,0x60); lcd_hx8357_write_reg(0x9B,0x64); lcd_hx8357_write_reg(0x9C,0x68); lcd_hx8357_write_reg(0x9D,0x6C); lcd_hx8357_write_reg(0x9E,0x70); lcd_hx8357_write_reg(0x9F,0x73); lcd_hx8357_write_reg(0xA0,0x77); lcd_hx8357_write_reg(0xA1,0x7B); lcd_hx8357_write_reg(0xA2,0x7F); lcd_hx8357_write_reg(0xA3,0x83); lcd_hx8357_write_reg(0xA4,0x87); lcd_hx8357_write_reg(0xA5,0x8A); lcd_hx8357_write_reg(0xA6,0x8E); lcd_hx8357_write_reg(0xA7,0x92); lcd_hx8357_write_reg(0xA8,0x96); lcd_hx8357_write_reg(0xA9,0x9A); lcd_hx8357_write_reg(0xAA,0x9F); lcd_hx8357_write_reg(0xAB,0xA3); lcd_hx8357_write_reg(0xAC,0xA7); lcd_hx8357_write_reg(0xAD,0xAC); lcd_hx8357_write_reg(0xAE,0xAF); lcd_hx8357_write_reg(0xAF,0xB3); lcd_hx8357_write_reg(0xB0,0xB7); lcd_hx8357_write_reg(0xB1,0xBA); lcd_hx8357_write_reg(0xB2,0xBE); lcd_hx8357_write_reg(0xB3,0xC3); lcd_hx8357_write_reg(0xB4,0xC7); lcd_hx8357_write_reg(0xB5,0xCC); lcd_hx8357_write_reg(0xB6,0xD1); lcd_hx8357_write_reg(0xB7,0xD7); lcd_hx8357_write_reg(0xB8,0xDD); lcd_hx8357_write_reg(0xB9,0xE3); lcd_hx8357_write_reg(0xBA,0xE8); lcd_hx8357_write_reg(0xBB,0xEA); lcd_hx8357_write_reg(0xBC,0xEC); lcd_hx8357_write_reg(0xBD,0xEF); lcd_hx8357_write_reg(0xBE,0xF3); lcd_hx8357_write_reg(0xBF,0xF6); lcd_hx8357_write_reg(0xC0,0xFE); //================= Command page 0 ================= lcd_hx8357_write_reg(0xff,0x00); lcd_hx8357_write_reg(0x60,0x08); lcd_hx8357_write_reg(0xF2,0x00); lcd_hx8357_write_reg(0xE4,0x1F); //EQVCI_M1=0x00 lcd_hx8357_write_reg(0xE5,0x1F); //EQGND_M1=0x1C lcd_hx8357_write_reg(0xE6,0x20); //EQVCI_M0=0x1C lcd_hx8357_write_reg(0xE7,0x00); //EQGND_M0=0x1C lcd_hx8357_write_reg(0xE8,0xD1); lcd_hx8357_write_reg(0xE9,0xC0); lcd_hx8357_write_reg(0x28,0x38); lcd_delay_ms(80); lcd_hx8357_write_reg(0x28,0x3C);// GON=0, DTE=0, D[1:0]=01 lcd_hx8357_write_reg(0x80,0x00); lcd_hx8357_write_reg(0x81,0x00); lcd_hx8357_write_reg(0x82,0x00); lcd_hx8357_write_reg(0x83,0x00); lcd_delay_ms(100); lcd_hx8357_write_reg(0x16,0x28); lcd_write_cmd(0x22); lcd_delay_ms(120); } void lcd_init() { esp_err_t ret; spi_bus_config_t buscfg = { .miso_io_num = LCD_PIN_MISO, .mosi_io_num = LCD_PIN_MOSI, .sclk_io_num = LCD_PIN_CLK, .quadwp_io_num = -1, .quadhd_io_num = -1, .max_transfer_sz = LCD_BURST_MAX_LEN * 2 }; spi_device_interface_config_t devcfg = { .clock_speed_hz = 20*1000*1000, //Clock out at 10 MHz .mode = 0, //SPI mode 0 .spics_io_num = LCD_PIN_CS, //CS pin .queue_size = 1, //We want to be able to queue 1 transactions at a time .pre_cb = lcd_spi_pre_transfer_callback, //Specify pre-transfer callback to handle D/C line .flags = SPI_DEVICE_HALFDUPLEX }; //Initialize the SPI bus ret=spi_bus_initialize(HSPI_HOST, &buscfg, 1); ESP_ERROR_CHECK(ret); //Attach the LCD to the SPI bus ret=spi_bus_add_device(HSPI_HOST, &devcfg, &spi); ESP_ERROR_CHECK(ret); //Initialize non-SPI GPIOs gpio_set_direction(LCD_PIN_DC, GPIO_MODE_OUTPUT); gpio_set_direction(LCD_PIN_RST, GPIO_MODE_OUTPUT); gpio_set_direction(LCD_PIN_BCKL, GPIO_MODE_OUTPUT); lcd_write_mux = xSemaphoreCreateMutex(); lcd_rst();//lcd_rst before LCD Init. # if defined(LCD_ILI9341) lcd_ili9341_config(); #elif defined(LCD_HX8357) lcd_hx8357_config(); #elif defined(LCD_ST7789) lcd_st7789v_config(); #else #error "please define lcd type(LCD_ILI9341,LCD_HX8357,LCD_ST7789)" #endif lcd_set_blk(1); printf("lcd init ok\n"); } static void lcd_ili9341_set_index(uint16_t x_start, uint16_t y_start, uint16_t x_end, uint16_t y_end) { lcd_write_cmd(0x2a); // CASET (2Ah): Column Address Set // Must write byte than byte lcd_write_byte((x_start) >> 8); lcd_write_byte((x_start) & 0xff); lcd_write_byte((x_end) >> 8); lcd_write_byte((x_end) & 0xff); lcd_write_cmd(0x2b); // RASET (2Bh): Row Address Set lcd_write_byte((y_start) >> 8); lcd_write_byte((y_start) & 0xff); lcd_write_byte((y_end) >> 8); lcd_write_byte((y_end) & 0xff); lcd_write_cmd(0x2c); // RAMWR (2Ch): Memory Write } void lcd_set_index(uint16_t x_start, uint16_t y_start, uint16_t x_end, uint16_t y_end) { # if defined(LCD_ILI9341) lcd_ili9341_set_index(x_start, y_start, x_end, y_end); #elif defined(LCD_HX8357) lcd_hx8357_set_index(x_start, x_end, y_start, y_end); #elif defined(LCD_ST7789) lcd_ili9341_set_index(x_start, y_start, x_end, y_end); #else #error "please define lcd type(LCD_ILI9341,LCD_HX8357,LCD_ST7789)" #endif }
32.228169
109
0.697142
01ae08fbbf9f9f94a3007082cc6c8c39490b8169
1,743
h
C
modules/scene_manager/include/example_interfaces/action/dds_opensplice/Fibonacci_Result_Response_SplDcps.h
Omnirobotic/godot
d50b5d047bbf6c68fc458c1ad097321ca627185d
[ "CC-BY-3.0", "Apache-2.0", "MIT" ]
null
null
null
modules/scene_manager/include/example_interfaces/action/dds_opensplice/Fibonacci_Result_Response_SplDcps.h
Omnirobotic/godot
d50b5d047bbf6c68fc458c1ad097321ca627185d
[ "CC-BY-3.0", "Apache-2.0", "MIT" ]
3
2019-11-14T12:20:06.000Z
2020-08-07T13:51:10.000Z
modules/scene_manager/include/example_interfaces/action/dds_opensplice/Fibonacci_Result_Response_SplDcps.h
Omnirobotic/godot
d50b5d047bbf6c68fc458c1ad097321ca627185d
[ "CC-BY-3.0", "Apache-2.0", "MIT" ]
null
null
null
#ifndef FIBONACCI_RESULT_RESPONSE_SPLTYPES_H #define FIBONACCI_RESULT_RESPONSE_SPLTYPES_H #include <c_base.h> #include <c_misc.h> #include <c_sync.h> #include <c_collection.h> #include <c_field.h> #include <v_copyIn.h> #include "ccpp_Fibonacci_Result_Response_.h" #include "example_interfaces/msg/rosidl_typesupport_opensplice_cpp__visibility_control.h" extern c_metaObject __Fibonacci_Result_Response__example_interfaces__load (c_base base); extern c_metaObject __Fibonacci_Result_Response__example_interfaces_action__load (c_base base); extern c_metaObject __Fibonacci_Result_Response__example_interfaces_action_dds___load (c_base base); extern const char *example_interfaces_action_dds__Fibonacci_Result_Response__metaDescriptor[]; extern const int example_interfaces_action_dds__Fibonacci_Result_Response__metaDescriptorArrLength; extern const int example_interfaces_action_dds__Fibonacci_Result_Response__metaDescriptorLength; extern c_metaObject __example_interfaces_action_dds__Fibonacci_Result_Response___load (c_base base); struct _example_interfaces_action_dds__Fibonacci_Result_Response_ ; extern ROSIDL_TYPESUPPORT_OPENSPLICE_CPP_PUBLIC_example_interfaces v_copyin_result __example_interfaces_action_dds__Fibonacci_Result_Response___copyIn(c_base base, const struct example_interfaces::action::dds_::Fibonacci_Result_Response_ *from, struct _example_interfaces_action_dds__Fibonacci_Result_Response_ *to); extern ROSIDL_TYPESUPPORT_OPENSPLICE_CPP_PUBLIC_example_interfaces void __example_interfaces_action_dds__Fibonacci_Result_Response___copyOut(const void *_from, void *_to); struct _example_interfaces_action_dds__Fibonacci_Result_Response_ { c_octet action_status_; c_sequence sequence_; }; #undef OS_API #endif
51.264706
316
0.895582
adcb745e69871135836f847b504bec5106ccccea
3,836
h
C
Chapter8/2_ShadowMaps/Src/Trackball.h
liuxuanhai/Mastering-Android-NDK
e42f238ebd929865775d61e37164d7caabfe768e
[ "MIT" ]
77
2015-09-09T00:00:15.000Z
2021-08-28T04:37:35.000Z
Chapter8/2_ShadowMaps/Src/Trackball.h
liuxuanhai/Mastering-Android-NDK
e42f238ebd929865775d61e37164d7caabfe768e
[ "MIT" ]
null
null
null
Chapter8/2_ShadowMaps/Src/Trackball.h
liuxuanhai/Mastering-Android-NDK
e42f238ebd929865775d61e37164d7caabfe768e
[ "MIT" ]
53
2015-12-14T08:33:27.000Z
2021-12-28T04:51:43.000Z
/* * Copyright (C) 2013-2015 Sergey Kosarevsky (sk@linderdaum.com) * Copyright (C) 2013-2015 Viktor Latypov (vl@linderdaum.com) * Based on Linderdaum Engine http://www.linderdaum.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 display the names 'Sergey Kosarevsky' and * 'Viktor Latypov'in the credits of the application, if such credits exist. * The authors of this work must be notified via email (sk@linderdaum.com) in * this case of redistribution. * * 3. Neither the name of copyright holders 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 COPYRIGHT HOLDERS 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. */ #pragma once #include "Platform.h" #include "VecMath.h" /// Virtual trackball for user interaction with rotations class clVirtualTrackball { public: clVirtualTrackball() : FCurrentPoint( 0.0f ) , FPrevPoint( 0.0f ) , FStarted( false ) { FRotation.IdentityMatrix(); FRotationDelta.IdentityMatrix(); }; /** Get rotation matrix for new mouse point **/ virtual LMatrix4 DragTo( LVector2 ScreenPoint, float Speed, bool KeyPressed ) { if ( KeyPressed && !FStarted ) { StartDragging( ScreenPoint ); FStarted = KeyPressed; return mat4::Identity(); } FStarted = KeyPressed; if ( !KeyPressed ) { return mat4::Identity(); } FCurrentPoint = ProjectOnSphere( ScreenPoint ); LVector3 Direction = FCurrentPoint - FPrevPoint; LMatrix4 RotMatrix; RotMatrix.IdentityMatrix(); float Shift = Direction.Length(); if ( Shift > Math::EPSILON ) { LVector3 Axis = FPrevPoint.Cross( FCurrentPoint ); RotMatrix.RotateMatrixAxis( Shift * Speed, Axis ); } FRotationDelta = RotMatrix; return RotMatrix; } LMatrix4& GetRotationDelta() { return FRotationDelta; }; /** Get current rotation matrix **/ virtual LMatrix4 GetRotationMatrix() const { return FRotation * FRotationDelta; } static clVirtualTrackball* Create() { return new clVirtualTrackball(); } private: virtual void StartDragging( LVector2 ScreenPoint ) { FRotation = FRotation * FRotationDelta; FCurrentPoint = ProjectOnSphere( ScreenPoint ); FPrevPoint = FCurrentPoint; FRotationDelta.IdentityMatrix(); } LVector3 ProjectOnSphere( LVector2 ScreenPoint ) { LVector3 Proj; // convert to -1.0...1.0 range Proj.x = 2.0f * ScreenPoint.x - 1.0f; Proj.y = -( 2.0f * ScreenPoint.y - 1.0f ); Proj.z = 0.0f; float Length = Proj.Length(); Length = ( Length < 1.0f ) ? Length : 1.0f; Proj.z = sqrtf( 1.001f - Length * Length ); Proj.Normalize(); return Proj; } LVector3 FCurrentPoint; LVector3 FPrevPoint; LMatrix4 FRotation; LMatrix4 FRotationDelta; bool FStarted; };
26.638889
83
0.720021
34ca43492c9d4bac1347721f4ede6f9b3858e403
294
h
C
XMGFMBase/Classes/Tool/XMGCacheTool.h
Better-me3/XMGFMbase
e7bb12ee9457fe9213c4d3e9e6841851c4d95f4e
[ "MIT" ]
2
2018-12-27T12:32:01.000Z
2019-01-30T01:38:38.000Z
XMGFMBase/Classes/Tool/XMGCacheTool.h
Better-me3/XMGFMbase
e7bb12ee9457fe9213c4d3e9e6841851c4d95f4e
[ "MIT" ]
null
null
null
XMGFMBase/Classes/Tool/XMGCacheTool.h
Better-me3/XMGFMbase
e7bb12ee9457fe9213c4d3e9e6841851c4d95f4e
[ "MIT" ]
null
null
null
// // XMGCacheTool.h // 喜马拉雅FM // // Created by 王顺子 on 16/8/2. // Copyright © 2016年 小码哥. All rights reserved. // // #import <Foundation/Foundation.h> @interface XMGCacheTool : NSObject + (NSString *)getSizeWithPath: (NSString *)path; + (void)clearCacheWithPath: (NSString *)path; @end
15.473684
48
0.676871
42e13bcb274726a3e841b54deca68e4e53e82a99
94,691
h
C
src/vga9.h
GeneralLeeInept/inpet
620aba314023d3b4c12ef04ea28ce8c3e5401f28
[ "BSD-3-Clause" ]
null
null
null
src/vga9.h
GeneralLeeInept/inpet
620aba314023d3b4c12ef04ea28ce8c3e5401f28
[ "BSD-3-Clause" ]
null
null
null
src/vga9.h
GeneralLeeInept/inpet
620aba314023d3b4c12ef04ea28ce8c3e5401f28
[ "BSD-3-Clause" ]
null
null
null
#pragma once static const int vga9_glyph_width = 9; static const int vga9_glyph_height = 16; static const int vga9_glyph_count = 256; static const int vga9_glyphs[vga9_glyph_width * vga9_glyph_height * vga9_glyph_count] = { 0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0, 0,1,1,1,1,1,1,0,0, 1,0,0,0,0,0,0,1,0, 1,0,1,0,0,1,0,1,0, 1,0,0,0,0,0,0,1,0, 1,0,0,0,0,0,0,1,0, 1,0,1,1,1,1,0,1,0, 1,0,0,1,1,0,0,1,0, 1,0,0,0,0,0,0,1,0, 1,0,0,0,0,0,0,1,0, 0,1,1,1,1,1,1,0,0, 0,0,0,0,0,0,0,0,0,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,1,1,1,1,1,0,0,0, 0,1,1,1,1,1,0,0,0, 0,1,1,1,1,1,0,0,0, 0,1,1,1,1,1,0,0,0, 0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0, };
21.723102
89
0.39122
665cc16cc1242413517d64d01216d64bf8715445
15,334
c
C
sources/twi.c
binh8994/stm8s_template
474cf6b98cf7b8c26285ab455b7be5ba5c1feaba
[ "MIT" ]
null
null
null
sources/twi.c
binh8994/stm8s_template
474cf6b98cf7b8c26285ab455b7be5ba5c1feaba
[ "MIT" ]
null
null
null
sources/twi.c
binh8994/stm8s_template
474cf6b98cf7b8c26285ab455b7be5ba5c1feaba
[ "MIT" ]
null
null
null
/* twi.c - TWI/I2C library for Wiring & Arduino Copyright (c) 2006 Nicholas Zambetti. All right reserved. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Modified 2012 by Todd Krein (todd@krein.org) to implement repeated starts */ #include "twi.h" /* Begin Porting */ #define F_CPU 16000000L #define BEGIN_CRITICAL disableInterrupts(); #define END_CRITICAL enableInterrupts(); #define millis GetTick extern uint32_t GetTick(void); /* End Porting */ static volatile uint8_t twi_state; static volatile uint8_t twi_slarw; static volatile uint8_t twi_sendStop; // should the transaction end with a stop static volatile uint8_t twi_inRepStart; // in the middle of a repeated start static void (*twi_onSlaveTransmit)(void); static void (*twi_onSlaveReceive)(uint8_t*, int); static uint8_t twi_masterBuffer[TWI_BUFFER_LENGTH]; static volatile uint8_t twi_masterBufferIndex; static volatile uint8_t twi_masterBufferLength; static uint8_t twi_txBuffer[TWI_BUFFER_LENGTH]; static volatile uint8_t twi_txBufferIndex; static volatile uint8_t twi_txBufferLength; static uint8_t twi_rxBuffer[TWI_BUFFER_LENGTH]; static volatile uint8_t twi_rxBufferIndex; static volatile uint8_t twi_error; /* --- SDuino additions -------------------------------------------------- */ /* This part is common with the I2C library */ static uint16_t twi_timeOutDelay; static uint8_t returnStatus; static uint8_t twi_sendAddress(uint8_t, uint8_t); static uint8_t twi_sendByte(uint8_t); static uint8_t twi_receiveByte(void); static void twi_lockUp(void); static uint16_t startingTime; static bool timeout_expired; static void tout_start(void); static bool tout(void); #define SLA_W(address) (address << 1) #define SLA_R(address) ((address << 1) + 0x01) #define MODE_WRITE 4 #define SEND_ADDRESS_W(ADDR) \ returnStatus = twi_sendAddress(SLA_W(ADDR),MODE_WRITE); \ if (returnStatus) return(returnStatus); // wait while the condition is still true (wait for a bit to become zero) #define TIMEOUT_WAIT_FOR_ZERO(CONDITION,ERROR) \ while (CONDITION) /* wait while the condition is still true */ \ { \ if (tout()) \ { \ twi_lockUp(); \ return(ERROR);/* return the appropriate error code */ \ } \ } // wait while the condition is not true (wait for a bit to become one) #define TIMEOUT_WAIT_FOR_ONE(CONDITION,ERROR) TIMEOUT_WAIT_FOR_ZERO(!(CONDITION), ERROR) /* --- public methods ---------------------------------------------------- */ /* * Function twi_init * Desc readys twi pins and sets twi bitrate * Input none * Output none */ void twi_init(void) { // set I2C frequency to 100kHz and do a full init twi_setFrequency(I2C_MAX_STANDARD_FREQ); // set default timeout to 20ms twi_timeOutDelay = 20; } /* * Function twi_disable * Desc disables twi pins * Input none * Output none */ void twi_disable(void) { I2C->CR1 = 0; /* // disable twi module, acks, and twi interrupt TWCR &= ~(_BV(TWEN) | _BV(TWIE) | _BV(TWEA)); // deactivate internal pullups for twi. digitalWrite(SDA, 0); digitalWrite(SCL, 0); */ } /* * Function twi_slaveInit * Desc sets slave address (FIXME: and enables interrupt) * Input address to be set (gets shifted one bit left to skip the r/w bit) * Output none */ void twi_setAddress(uint8_t address) { // set twi slave address I2C->OARL = address << 1; I2C->OARH = I2C_OARH_ADDCONF; } /* * Function twi_setClock * Desc sets twi bit rate * Input Clock Frequency * Output none */ void twi_setFrequency(uint32_t frequency) { // the easiest way to change the frequency is a full re-init I2C_Init( frequency, // I2C_SPEED, 0xA0, // OwnAddress, doesn't matter I2C_DUTYCYCLE_2, // 0x00 I2C_ACK_CURR, // 0x01 I2C_ADDMODE_7BIT, // 0x00 F_CPU/1000000u // InputClockFrequencyMhz ); } /* * Function twi_readFrom * Desc attempts to become twi bus master and read a * series of bytes from a device on the bus * Input address: 7bit i2c device address * data: pointer to byte array * length: number of bytes to read into array * sendStop: Boolean indicating whether to send a stop at the end * Output number of bytes read *FIXME: no interrupt support, polling mode only */ uint8_t twi_readFrom(uint8_t address, uint8_t* data, uint8_t length, uint8_t sendStop) { uint8_t bytesAvailable; (void) sendStop; //FIXME: ignore sendStop for now bytesAvailable = 0; // method 2 (see RM0016, page 293): if (twi_sendAddress(SLA_R(address), length)) return 0; if (!length) return 0; tout_start(); if (length == 1) { // method 2, case single byte (see RM0016, page 294): // I2C->CR2 |= I2C_CR2_STOP; // send stop after receiving the one data byte // wait for RxNE flag if (twi_receiveByte()) return 0; // save the data data[0] = I2C->DR; bytesAvailable = 1; } else if (length == 2) { // method 2, case two bytes (see RM0016, page 294): // Case of two bytes to be received: // I2C->CR2 &= ~I2C_CR2_ACK; // clear ACK // Wait for BTF to be set TIMEOUT_WAIT_FOR_ONE(I2C->SR1 & I2C_SR1_BTF, 0);//6); // masking interrupts according to errata sheet #17140 rev. 5 BEGIN_CRITICAL I2C->CR2 |= I2C_CR2_STOP; // Program STOP data[0] = I2C->DR; // Read DR twice END_CRITICAL data[1] = I2C->DR; bytesAvailable = 2; } else { uint8_t tmp1, tmp2; // method 2, general case, n>2 (see RM0016, page 294): while (length > 3) { // Wait for BTF to be set TIMEOUT_WAIT_FOR_ONE(I2C->SR1 & I2C_SR1_BTF, bytesAvailable);//6); // save the data *data++ = I2C->DR; bytesAvailable++; length--; //FIXME: while ans Schleifenende } // Wait for BTF to be set TIMEOUT_WAIT_FOR_ONE(I2C->SR1 & I2C_SR1_BTF, bytesAvailable);//6); // clear ACK I2C->CR2 &= ~I2C_CR2_ACK; // masking interrupts according to errata sheet #17140 rev. 5 // using temporary variables to keep the critical section as // short as possible. The pointer arithmetics for dataBuffer // compiles to quite complex code. //TODO: Could be optimized with assembler code BEGIN_CRITICAL tmp1 = I2C->DR; // read DataN-2 I2C->CR2 |= I2C_CR2_STOP; // Program STOP tmp2 = I2C->DR; // read DataN-1 END_CRITICAL *data++ = tmp1; *data++ = tmp2; bytesAvailable += 2; if (twi_receiveByte()) return bytesAvailable;// wait for RxNE flag *data = I2C->DR; // read DataN bytesAvailable++; } // don't use the TIMEOUT macro. In the error case we would have to // return(bytesAvailable), which is done at the end anyway. // Wait for STOP end while (I2C->CR2 & I2C_CR2_STOP) { if (tout()) twi_lockUp(); } return (bytesAvailable); } /* * Function twi_writeTo * Desc attempts to become twi bus master and write a * series of bytes to a device on the bus * Input address: 7bit i2c device address * data: pointer to byte array * length: number of bytes in array * wait: boolean indicating to wait for write or not * sendStop: boolean indicating whether or not to send a stop at the end * Output 0 .. success * 1 .. length to long for buffer * 2 .. address send, NACK received * 3 .. data send, NACK received * 4 .. other twi error (lost bus arbitration, bus error, ..) */ uint8_t twi_writeTo(uint8_t address, uint8_t* data, uint8_t length, uint8_t wait, uint8_t sendStop) { (void) wait; //FIXME: no interrupt support, ignore the wait parameter for now SEND_ADDRESS_W(address); while (length--) { if (twi_sendByte(*data++)) return (3); } if (sendStop) { twi_stop(); } return 0; } /* * Function twi_transmit * Desc fills slave tx buffer with data * must be called in slave tx event callback * Input data: pointer to byte array * length: number of bytes in array * Output 1 length too long for buffer * 2 not slave transmitter * 0 ok */ uint8_t twi_transmit(const uint8_t* data, uint8_t length) { (void) data; (void) length; return 0; } /* * Function twi_attachSlaveRxEvent * Desc sets function called before a slave read operation * Input function: callback function to use * Output none */ /* void twi_attachSlaveRxEvent( void (*function)(uint8_t*, int) ) { twi_onSlaveReceive = function; } */ /* * Function twi_attachSlaveTxEvent * Desc sets function called before a slave write operation * Input function: callback function to use * Output none */ /* void twi_attachSlaveTxEvent( void (*function)(void) ) { twi_onSlaveTransmit = function; } */ /* * Function twi_reply * Desc sends byte or readys receive line * Input ack: byte indicating to ack or to nack * Output none */ /* void twi_reply(uint8_t ack) { // transmit master read ready signal, with or without ack if(ack){ TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWINT) | _BV(TWEA); }else{ TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWINT); } } */ /* * Function twi_stop * Desc relinquishes bus master status * Input none * Output none */ void twi_stop(void) { tout_start(); /* Test on EV8_2: TXE and BTF flags */ // TIMEOUT_WAIT_FOR_ONE((I2C->SR1 & (I2C_SR1_TXE | I2C_SR1_BTF)) == // (I2C_SR1_TXE | I2C_SR1_BTF)); while ((I2C->SR1 & (I2C_SR1_TXE | I2C_SR1_BTF)) != (I2C_SR1_TXE | I2C_SR1_BTF)) { if (tout()) { twi_lockUp(); return; // don't update twi_state } } /* Generate a STOP condition */ I2C->CR2 |= I2C_CR2_STOP; // wait for the end of the STOP condition // // The reference manual rm0016 is not clear on how to check for this // condition. Maybe BUSY, BTF, TRA or even MSL. // Waiting for BTF works. // AN3281, Fig. 4 specifies to wait for STOPF, but that does not work. // The source code attached to AN3281 waits for the STOP bit in CR2 // to flip back to zero. This works, so this method is used. // TIMEOUT_WAIT_FOR_ONE((I2C->SR1 & I2C_SR1_BTF), 7); // works // TIMEOUT_WAIT_FOR_ONE((I2C->SR1 & I2C_SR1_STOPF), 7); // doesn't work // TIMEOUT_WAIT_FOR_ZERO(I2C->CR2 & I2C_CR2_STOP); // works while (I2C->CR2 & I2C_CR2_STOP) // works { if (tout()) { twi_lockUp(); return; // don't update twi_state } } /* // send stop condition TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWEA) | _BV(TWINT) | _BV(TWSTO); // wait for stop condition to be exectued on bus // TWINT is not set after a stop condition! while(TWCR & _BV(TWSTO)){ continue; } */ // update twi state twi_state = TWI_READY; } /* * Function twi_releaseBus * Desc releases bus control * Input none * Output none */ /* void twi_releaseBus(void) { // release bus TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWEA) | _BV(TWINT); // update twi state twi_state = TWI_READY; } */ /* --- SDuino additions -------------------------------------------------- */ /** * send start condition and the target address and wait for the ADDR event * * The flag handling for POS and ACK is determined by the mode byte. * At the end, ADDR is cleared by reading CR3. * * @parms mode: set the flag handling for POS and ACK * 1: clear ACK in ADDR event, before clearing ADDR (receive 1) * 2: set ACK, POS before ADDR event (receive 2) * 3: set ACK before ADDR event (receive > 2, write) * @returns: 0 .. success * 2 .. address send, NACK received * 4 .. other twi error (lost bus arbitration, bus error, ..) */ static uint8_t twi_sendAddress(uint8_t i2cAddress, uint8_t mode) { tout_start(); /* do not wait for BUSY==0 as this would block for repeated start */ // TIMEOUT_WAIT_FOR_ZERO((I2C->SR3 & I2C_SR3_BUSY), 4); I2C->CR2 |= I2C_CR2_ACK; // set ACK /* send start sequence */ I2C->CR2 |= I2C_CR2_START; // send start sequence /* Test on EV5 and clear it (SB flag) */ TIMEOUT_WAIT_FOR_ONE(I2C->SR1 & I2C_SR1_SB, 4); /* Send the Address + Direction */ I2C->DR = i2cAddress; // I2C_Send7bitAddress() /* Test on EV6, but don't clear it yet (ADDR flag) */ // error code 2: no ACK received on address transmission TIMEOUT_WAIT_FOR_ONE(I2C->SR1 & I2C_SR1_ADDR, 2); if (mode == 1) { I2C->CR2 &= ~I2C_CR2_ACK; // clear ACK BEGIN_CRITICAL // disable interrupts (void) I2C->SR3; // read SR3 to clear ADDR event bit I2C->CR2 |= I2C_CR2_STOP; // send STOP soon END_CRITICAL // enable interrupts } else if (mode == 2) { I2C->CR2 |= I2C_CR2_POS; // set POS BEGIN_CRITICAL // disable interrupts (void) I2C->SR3; // read SR3 to clear ADDR event bit I2C->CR2 &= ~I2C_CR2_ACK; // clear ACK END_CRITICAL // enable interrupts } else { (void)I2C->SR3; // read SR3 to clear ADDR event bit } return 0; } /** * send one data byte via I2C (blocking) * * @returns:0 .. success * 3 .. data send, NACK received */ uint8_t twi_sendByte(uint8_t i2cData) { tout_start(); /* Test on EV8 (wait for TXE flag) */ /* On fail: 3: no ACK received on data transmission */ TIMEOUT_WAIT_FOR_ONE(I2C->SR1 & I2C_SR1_TXE, 3); I2C->DR = i2cData; return 0; } /** * EV7: wait for RxNE flag and check for lost arbitration * * The actual data byte is not read but available in I2C->DR * @returns: error code. possible values: * 0: ok * 1: timeout while waiting for RxNE * LOST_ARBTRTN: arbitration lost */ static uint8_t twi_receiveByte(void) { tout_start(); /* Test on EV7 (BUSY, MSL and RXNE flags) */ TIMEOUT_WAIT_FOR_ONE(I2C_CheckEvent(I2C_EVENT_MASTER_BYTE_RECEIVED), 1) if (I2C->SR2 & I2C_SR2_ARLO) // arbitration lost { twi_lockUp(); return (2);//FIXME: should be LOST_ARBTRTN); } return (0); } static void twi_lockUp(void) { #if 0 TWCR = 0; //releases SDA and SCL lines to high impedance TWCR = _BV(TWEN) | _BV(TWEA); //reinitialize TWI #endif //FIXME: this needs to be checked in detail. CR1 might be involved // don't do a full software reset here. That would require a full // re-initialization before the next transfer could happen. I2C->CR2 = 0; } /** * set the timeout delay * * @params: * ms: timeout value in ms. 0 to disable timeout (and wait indefinitly) */ void twi_setTimeout(uint16_t ms) { twi_timeOutDelay = ms; } /** * start the timeout timer * * The current time is set as the starting time. */ static void tout_start(void) { startingTime = millis(); timeout_expired = FALSE; } /** * check if the timeout period expired * * @returns: * false: Still within the waiting period * true: timeout expired */ static bool tout(void) { if (!twi_timeOutDelay) { return FALSE; // no timeout set } if (!timeout_expired) { timeout_expired = ((((uint16_t)millis()) - startingTime) >= twi_timeOutDelay); } return timeout_expired; }
26.807692
99
0.67471
c3e9d5b8da8a6f8c94cd0e091bd5f92f2ce8b7de
356
h
C
AUWPMC/Includes.h
daddyDinosaur/ARK-UWP-Source
4fb5958ef59c8313aa0b5692e21e46a3a9d458e5
[ "MIT" ]
4
2021-12-07T16:35:12.000Z
2022-01-01T23:17:32.000Z
AUWPMC/Includes.h
daddyDinosaur/ARK-UWP-Source
4fb5958ef59c8313aa0b5692e21e46a3a9d458e5
[ "MIT" ]
3
2021-12-07T19:43:52.000Z
2021-12-08T17:17:16.000Z
AUWPMC/Includes.h
daddyDinosaur/ARK-UWP-Source
4fb5958ef59c8313aa0b5692e21e46a3a9d458e5
[ "MIT" ]
5
2021-12-05T01:42:31.000Z
2021-12-21T13:54:25.000Z
#pragma once #include "imgui\imgui.h" #include "imgui\imgui_impl_win32.h" #include "imgui\imgui_impl_dx11.h" #include "imgui\imgui_internal.h" #include "Cheat.h" #include <d3d11.h> #include "Menu.h" #include <d3d11.h> #include "Logger.h" #include "MemHelper.h" #include <TlHelp32.h> #include <iostream> #include <stdio.h> #include "SDK/SDK.h"
23.733333
36
0.707865
d7bf4e1785e986fc0c32bd0baf65b83040348191
2,566
h
C
bot/src/cpp/message/ClientCommandDispatcher.h
Bots-United/whichbot
c5db2a6cc3f90930139503b344074376a9cdaabb
[ "BSD-2-Clause" ]
null
null
null
bot/src/cpp/message/ClientCommandDispatcher.h
Bots-United/whichbot
c5db2a6cc3f90930139503b344074376a9cdaabb
[ "BSD-2-Clause" ]
null
null
null
bot/src/cpp/message/ClientCommandDispatcher.h
Bots-United/whichbot
c5db2a6cc3f90930139503b344074376a9cdaabb
[ "BSD-2-Clause" ]
1
2020-04-06T02:02:28.000Z
2020-04-06T02:02:28.000Z
// // $Id: ClientCommandDispatcher.h,v 1.2 2003/10/18 02:03:45 clamatius Exp $ // Copyright (c) 2003, WhichBot Project // All rights reserved. // // 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 of the WhichBot Project 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 OWNER 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. #ifndef __MESSAGE_CLIENTCOMMANDDISPATCHER_H #define __MESSAGE_CLIENTCOMMANDDISPATCHER_H #include "BotTypedefs.h" #include "extern/halflifesdk/extdll.h" typedef void (*ClientCommandHandler) (edict_t* pEdict, vector<string>& args); class ClientCommandDispatcher { public: void interceptClientCommand(edict_t* pClientEdict); void dispatchCommand(edict_t* pEdict, const char* args[], int numArgs); void registerHandler(const string& cmd, ClientCommandHandler handler); void registerHandlers(); protected: class StringComparator { public: bool operator () (const string& lhs, const string& rhs) const { // for whatever fricken reason (lhs < rhs) doesn't work in MS's STL implementation. sigh. return strcmp(lhs.c_str(), rhs.c_str()) < 0; } }; typedef map<string, ClientCommandHandler, StringComparator> tHandlerMap; tHandlerMap _handlers; }; #endif
36.657143
92
0.754871