blob_id
stringlengths 40
40
| directory_id
stringlengths 40
40
| path
stringlengths 4
721
| content_id
stringlengths 40
40
| detected_licenses
listlengths 0
57
| license_type
stringclasses 2
values | repo_name
stringlengths 5
91
| snapshot_id
stringlengths 40
40
| revision_id
stringlengths 40
40
| branch_name
stringclasses 321
values | visit_date
timestamp[ns]date 2016-08-12 09:31:09
2023-09-06 10:45:07
| revision_date
timestamp[ns]date 2010-09-28 14:01:40
2023-09-06 06:22:19
| committer_date
timestamp[ns]date 2010-09-28 14:01:40
2023-09-06 06:22:19
| github_id
int64 426
681M
| star_events_count
int64 101
243k
| fork_events_count
int64 0
110k
| gha_license_id
stringclasses 23
values | gha_event_created_at
timestamp[ns]date 2012-06-28 18:51:49
2023-09-14 21:59:16
⌀ | gha_created_at
timestamp[ns]date 2008-02-11 22:55:26
2023-08-10 11:14:58
⌀ | gha_language
stringclasses 147
values | src_encoding
stringclasses 26
values | language
stringclasses 2
values | is_vendor
bool 2
classes | is_generated
bool 2
classes | length_bytes
int64 6
10.2M
| extension
stringclasses 115
values | filename
stringlengths 3
113
| content
stringlengths 6
10.2M
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
90b1e8e4726eb6b3f9074200d6b313ef40939800
|
bed3ac926beac0f4e0293303d7b2a6031ee476c9
|
/Modules/ThirdParty/HDF5/src/itkhdf5/src/H5Obogus.c
|
c7fcdb901dec67d61675a75272c24d29a5b930eb
|
[
"LicenseRef-scancode-hdf5",
"LicenseRef-scancode-llnl",
"IJG",
"Zlib",
"LicenseRef-scancode-proprietary-license",
"SMLNJ",
"BSD-3-Clause",
"BSD-4.3TAHOE",
"LicenseRef-scancode-free-unknown",
"Spencer-86",
"FSFUL",
"Libpng",
"libtiff",
"LicenseRef-scancode-warranty-disclaimer",
"LicenseRef-scancode-other-permissive",
"MIT",
"NTP",
"LicenseRef-scancode-mit-old-style",
"GPL-1.0-or-later",
"LicenseRef-scancode-unknown-license-reference",
"MPL-2.0",
"Apache-2.0",
"LicenseRef-scancode-public-domain",
"BSD-2-Clause"
] |
permissive
|
InsightSoftwareConsortium/ITK
|
ed9dbbc5b8b3f7511f007c0fc0eebb3ad37b88eb
|
3eb8fd7cdfbc5ac2d0c2e5e776848a4cbab3d7e1
|
refs/heads/master
| 2023-08-31T17:21:47.754304
| 2023-08-31T00:58:51
| 2023-08-31T14:12:21
| 800,928
| 1,229
| 656
|
Apache-2.0
| 2023-09-14T17:54:00
| 2010-07-27T15:48:04
|
C++
|
UTF-8
|
C
| false
| false
| 8,878
|
c
|
H5Obogus.c
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the COPYING file, which can be found at the root of the source code *
* distribution tree, or in https://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*-------------------------------------------------------------------------
*
* Created: H5Obogus.c
* Jan 21 2003
* Quincey Koziol
*
* Purpose: "bogus" message. This message is guaranteed to never
* be found in a valid HDF5 file and is only used to
* generate a test file which verifies the library's
* correct operation when parsing unknown object header
* messages.
*
*-------------------------------------------------------------------------
*/
#include "H5Omodule.h" /* This source code file is part of the H5O module */
#include "H5private.h" /* Generic Functions */
#include "H5Eprivate.h" /* Error handling */
#include "H5MMprivate.h" /* Memory management */
#include "H5Opkg.h" /* Object headers */
#ifdef H5O_ENABLE_BOGUS
/* PRIVATE PROTOTYPES */
static void * H5O__bogus_decode(H5F_t *f, H5O_t *open_oh, unsigned mesg_flags, unsigned *ioflags,
size_t p_size, const uint8_t *p);
static herr_t H5O__bogus_encode(H5F_t *f, hbool_t disable_shared, uint8_t *p, const void *_mesg);
static size_t H5O__bogus_size(const H5F_t *f, hbool_t disable_shared, const void *_mesg);
static herr_t H5O__bogus_debug(H5F_t *f, const void *_mesg, FILE *stream, int indent, int fwidth);
/* This message derives from H5O message class */
const H5O_msg_class_t H5O_MSG_BOGUS_VALID[1] = {{
H5O_BOGUS_VALID_ID, /*message id number */
"bogus valid", /*message name for debugging */
0, /*native message size */
H5O_SHARE_IS_SHARABLE, /* messages are sharable? */
H5O__bogus_decode, /*decode message */
H5O__bogus_encode, /*encode message */
NULL, /*copy the native value */
H5O__bogus_size, /*raw message size */
NULL, /*free internal memory */
NULL, /*free method */
NULL, /* file delete method */
NULL, /* link method */
NULL, /*set share method */
NULL, /*can share method */
NULL, /* pre copy native value to file */
NULL, /* copy native value to file */
NULL, /* post copy native value to file */
NULL, /* get creation index */
NULL, /* set creation index */
H5O__bogus_debug /*debug the message */
}};
/* This message derives from H5O message class */
const H5O_msg_class_t H5O_MSG_BOGUS_INVALID[1] = {{
H5O_BOGUS_INVALID_ID, /*message id number */
"bogus invalid", /*message name for debugging */
0, /*native message size */
H5O_SHARE_IS_SHARABLE, /* messages are sharable? */
H5O__bogus_decode, /*decode message */
H5O__bogus_encode, /*encode message */
NULL, /*copy the native value */
H5O__bogus_size, /*raw message size */
NULL, /*free internal memory */
NULL, /*free method */
NULL, /* file delete method */
NULL, /* link method */
NULL, /*set share method */
NULL, /*can share method */
NULL, /* pre copy native value to file */
NULL, /* copy native value to file */
NULL, /* post copy native value to file */
NULL, /* get creation index */
NULL, /* set creation index */
H5O__bogus_debug /*debug the message */
}};
/*-------------------------------------------------------------------------
* Function: H5O__bogus_decode
*
* Purpose: Decode a "bogus" message and return a pointer to a new
* native message struct.
*
* Return: Success: Ptr to new message in native struct.
*
* Failure: NULL
*
* Programmer: Quincey Koziol
* Jan 21 2003
*
*-------------------------------------------------------------------------
*/
static void *
H5O__bogus_decode(H5F_t *f, H5O_t H5_ATTR_UNUSED *open_oh, unsigned H5_ATTR_UNUSED mesg_flags,
unsigned H5_ATTR_UNUSED *ioflags, size_t H5_ATTR_UNUSED p_size, const uint8_t *p)
{
H5O_bogus_t *mesg = NULL;
void * ret_value; /* Return value */
FUNC_ENTER_STATIC
/* check args */
HDassert(f);
HDassert(p);
/* Allocate the bogus message */
if (NULL == (mesg = (H5O_bogus_t *)H5MM_calloc(sizeof(H5O_bogus_t))))
HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed")
/* decode */
UINT32DECODE(p, mesg->u);
/* Validate the bogus info */
if (mesg->u != H5O_BOGUS_VALUE)
HGOTO_ERROR(H5E_OHDR, H5E_BADVALUE, NULL, "invalid bogus value :-)")
/* Set return value */
ret_value = mesg;
done:
if (ret_value == NULL && mesg != NULL)
H5MM_xfree(mesg);
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5O__bogus_decode() */
/*-------------------------------------------------------------------------
* Function: H5O__bogus_encode
*
* Purpose: Encodes a "bogus" message.
*
* Return: Non-negative on success/Negative on failure
*
* Programmer: Quincey Koziol
* Jan 21 2003
*
*-------------------------------------------------------------------------
*/
static herr_t
H5O__bogus_encode(H5F_t H5_ATTR_UNUSED *f, hbool_t H5_ATTR_UNUSED disable_shared, uint8_t *p,
const void H5_ATTR_UNUSED *mesg)
{
FUNC_ENTER_STATIC_NOERR
/* check args */
HDassert(f);
HDassert(p);
HDassert(mesg);
/* encode */
UINT32ENCODE(p, H5O_BOGUS_VALUE);
FUNC_LEAVE_NOAPI(SUCCEED)
} /* end H5O__bogus_encode() */
/*-------------------------------------------------------------------------
* Function: H5O__bogus_size
*
* Purpose: Returns the size of the raw message in bytes not
* counting the message typ or size fields, but only the data
* fields. This function doesn't take into account
* alignment.
*
* Return: Success: Message data size in bytes w/o alignment.
*
* Failure: Negative
*
* Programmer: Quincey Koziol
* Jan 21 2003
*
*-------------------------------------------------------------------------
*/
static size_t
H5O__bogus_size(const H5F_t H5_ATTR_UNUSED *f, hbool_t H5_ATTR_UNUSED disable_shared,
const void H5_ATTR_UNUSED *mesg)
{
FUNC_ENTER_STATIC_NOERR
FUNC_LEAVE_NOAPI(4)
} /* end H5O__bogus_size() */
/*-------------------------------------------------------------------------
* Function: H5O__bogus_debug
*
* Purpose: Prints debugging info for the message.
*
* Return: Non-negative on success/Negative on failure
*
* Programmer: Quincey Koziol
* Jan 21 2003
*
*-------------------------------------------------------------------------
*/
static herr_t
H5O__bogus_debug(H5F_t H5_ATTR_UNUSED *f, const void *_mesg, FILE *stream, int indent, int fwidth)
{
const H5O_bogus_t *mesg = (const H5O_bogus_t *)_mesg;
FUNC_ENTER_STATIC_NOERR
/* check args */
HDassert(f);
HDassert(mesg);
HDassert(stream);
HDassert(indent >= 0);
HDassert(fwidth >= 0);
HDfprintf(stream, "%*s%-*s `%u'\n", indent, "", fwidth, "Bogus Value:", mesg->u);
FUNC_LEAVE_NOAPI(SUCCEED)
} /* end H5O__bogus_debug() */
#endif /* H5O_ENABLE_BOGUS */
|
b47953f5bc8e8d5fd3c924ef70b2e26ee885f201
|
e5f4f37d941ceb8145d65f92028cc54658b1ac01
|
/Code/ThirdParty/RmlUi/Dependencies/lunasvg/3rdparty/software/sw_ft_stroker.h
|
95036c5eec4d9cbb4bd06ddb682efb6e34bb40ed
|
[
"MIT",
"FTL",
"LicenseRef-scancode-proprietary-license"
] |
permissive
|
ezEngine/ezEngine
|
19983d2733a5409fb2665c6c3a0a575dadcefb50
|
c46e3b4b2cd46798e4abb4938fbca281c054b039
|
refs/heads/dev
| 2023-09-06T02:17:28.152665
| 2023-09-05T18:25:43
| 2023-09-05T18:25:43
| 18,179,848
| 1,050
| 165
|
MIT
| 2023-09-14T21:44:39
| 2014-03-27T15:02:16
|
C++
|
UTF-8
|
C
| false
| false
| 10,132
|
h
|
sw_ft_stroker.h
|
#ifndef SW_FT_STROKER_H
#define SW_FT_STROKER_H
/***************************************************************************/
/* */
/* ftstroke.h */
/* */
/* FreeType path stroker (specification). */
/* */
/* Copyright 2002-2006, 2008, 2009, 2011-2012 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
/* modified, and distributed under the terms of the FreeType project */
/* license, LICENSE.TXT. By continuing to use, modify, or distribute */
/* this file you indicate that you have read the license and */
/* understand and accept it fully. */
/* */
/***************************************************************************/
#include "sw_ft_raster.h"
/**************************************************************
*
* @type:
* SW_FT_Stroker
*
* @description:
* Opaque handler to a path stroker object.
*/
typedef struct SW_FT_StrokerRec_* SW_FT_Stroker;
/**************************************************************
*
* @enum:
* SW_FT_Stroker_LineJoin
*
* @description:
* These values determine how two joining lines are rendered
* in a stroker.
*
* @values:
* SW_FT_STROKER_LINEJOIN_ROUND ::
* Used to render rounded line joins. Circular arcs are used
* to join two lines smoothly.
*
* SW_FT_STROKER_LINEJOIN_BEVEL ::
* Used to render beveled line joins. The outer corner of
* the joined lines is filled by enclosing the triangular
* region of the corner with a straight line between the
* outer corners of each stroke.
*
* SW_FT_STROKER_LINEJOIN_MITER_FIXED ::
* Used to render mitered line joins, with fixed bevels if the
* miter limit is exceeded. The outer edges of the strokes
* for the two segments are extended until they meet at an
* angle. If the segments meet at too sharp an angle (such
* that the miter would extend from the intersection of the
* segments a distance greater than the product of the miter
* limit value and the border radius), then a bevel join (see
* above) is used instead. This prevents long spikes being
* created. SW_FT_STROKER_LINEJOIN_MITER_FIXED generates a miter
* line join as used in PostScript and PDF.
*
* SW_FT_STROKER_LINEJOIN_MITER_VARIABLE ::
* SW_FT_STROKER_LINEJOIN_MITER ::
* Used to render mitered line joins, with variable bevels if
* the miter limit is exceeded. The intersection of the
* strokes is clipped at a line perpendicular to the bisector
* of the angle between the strokes, at the distance from the
* intersection of the segments equal to the product of the
* miter limit value and the border radius. This prevents
* long spikes being created.
* SW_FT_STROKER_LINEJOIN_MITER_VARIABLE generates a mitered line
* join as used in XPS. SW_FT_STROKER_LINEJOIN_MITER is an alias
* for SW_FT_STROKER_LINEJOIN_MITER_VARIABLE, retained for
* backwards compatibility.
*/
typedef enum SW_FT_Stroker_LineJoin_
{
SW_FT_STROKER_LINEJOIN_ROUND = 0,
SW_FT_STROKER_LINEJOIN_BEVEL = 1,
SW_FT_STROKER_LINEJOIN_MITER_VARIABLE = 2,
SW_FT_STROKER_LINEJOIN_MITER = SW_FT_STROKER_LINEJOIN_MITER_VARIABLE,
SW_FT_STROKER_LINEJOIN_MITER_FIXED = 3
} SW_FT_Stroker_LineJoin;
/**************************************************************
*
* @enum:
* SW_FT_Stroker_LineCap
*
* @description:
* These values determine how the end of opened sub-paths are
* rendered in a stroke.
*
* @values:
* SW_FT_STROKER_LINECAP_BUTT ::
* The end of lines is rendered as a full stop on the last
* point itself.
*
* SW_FT_STROKER_LINECAP_ROUND ::
* The end of lines is rendered as a half-circle around the
* last point.
*
* SW_FT_STROKER_LINECAP_SQUARE ::
* The end of lines is rendered as a square around the
* last point.
*/
typedef enum SW_FT_Stroker_LineCap_
{
SW_FT_STROKER_LINECAP_BUTT = 0,
SW_FT_STROKER_LINECAP_ROUND,
SW_FT_STROKER_LINECAP_SQUARE
} SW_FT_Stroker_LineCap;
/**************************************************************
*
* @enum:
* SW_FT_StrokerBorder
*
* @description:
* These values are used to select a given stroke border
* in @SW_FT_Stroker_GetBorderCounts and @SW_FT_Stroker_ExportBorder.
*
* @values:
* SW_FT_STROKER_BORDER_LEFT ::
* Select the left border, relative to the drawing direction.
*
* SW_FT_STROKER_BORDER_RIGHT ::
* Select the right border, relative to the drawing direction.
*
* @note:
* Applications are generally interested in the `inside' and `outside'
* borders. However, there is no direct mapping between these and the
* `left' and `right' ones, since this really depends on the glyph's
* drawing orientation, which varies between font formats.
*
* You can however use @SW_FT_Outline_GetInsideBorder and
* @SW_FT_Outline_GetOutsideBorder to get these.
*/
typedef enum SW_FT_StrokerBorder_
{
SW_FT_STROKER_BORDER_LEFT = 0,
SW_FT_STROKER_BORDER_RIGHT
} SW_FT_StrokerBorder;
/**************************************************************
*
* @function:
* SW_FT_Stroker_New
*
* @description:
* Create a new stroker object.
*
* @input:
* library ::
* FreeType library handle.
*
* @output:
* astroker ::
* A new stroker object handle. NULL in case of error.
*
* @return:
* FreeType error code. 0~means success.
*/
SW_FT_Error
SW_FT_Stroker_New( SW_FT_Stroker *astroker );
/**************************************************************
*
* @function:
* SW_FT_Stroker_Set
*
* @description:
* Reset a stroker object's attributes.
*
* @input:
* stroker ::
* The target stroker handle.
*
* radius ::
* The border radius.
*
* line_cap ::
* The line cap style.
*
* line_join ::
* The line join style.
*
* miter_limit ::
* The miter limit for the SW_FT_STROKER_LINEJOIN_MITER_FIXED and
* SW_FT_STROKER_LINEJOIN_MITER_VARIABLE line join styles,
* expressed as 16.16 fixed-point value.
*
* @note:
* The radius is expressed in the same units as the outline
* coordinates.
*/
void
SW_FT_Stroker_Set( SW_FT_Stroker stroker,
SW_FT_Fixed radius,
SW_FT_Stroker_LineCap line_cap,
SW_FT_Stroker_LineJoin line_join,
SW_FT_Fixed miter_limit );
/**************************************************************
*
* @function:
* SW_FT_Stroker_ParseOutline
*
* @description:
* A convenience function used to parse a whole outline with
* the stroker. The resulting outline(s) can be retrieved
* later by functions like @SW_FT_Stroker_GetCounts and @SW_FT_Stroker_Export.
*
* @input:
* stroker ::
* The target stroker handle.
*
* outline ::
* The source outline.
*
*
* @return:
* FreeType error code. 0~means success.
*
* @note:
* If `opened' is~0 (the default), the outline is treated as a closed
* path, and the stroker generates two distinct `border' outlines.
*
*
* This function calls @SW_FT_Stroker_Rewind automatically.
*/
SW_FT_Error
SW_FT_Stroker_ParseOutline( SW_FT_Stroker stroker,
const SW_FT_Outline* outline);
/**************************************************************
*
* @function:
* SW_FT_Stroker_GetCounts
*
* @description:
* Call this function once you have finished parsing your paths
* with the stroker. It returns the number of points and
* contours necessary to export all points/borders from the stroked
* outline/path.
*
* @input:
* stroker ::
* The target stroker handle.
*
* @output:
* anum_points ::
* The number of points.
*
* anum_contours ::
* The number of contours.
*
* @return:
* FreeType error code. 0~means success.
*/
SW_FT_Error
SW_FT_Stroker_GetCounts( SW_FT_Stroker stroker,
SW_FT_UInt *anum_points,
SW_FT_UInt *anum_contours );
/**************************************************************
*
* @function:
* SW_FT_Stroker_Export
*
* @description:
* Call this function after @SW_FT_Stroker_GetBorderCounts to
* export all borders to your own @SW_FT_Outline structure.
*
* Note that this function appends the border points and
* contours to your outline, but does not try to resize its
* arrays.
*
* @input:
* stroker ::
* The target stroker handle.
*
* outline ::
* The target outline handle.
*/
void
SW_FT_Stroker_Export( SW_FT_Stroker stroker,
SW_FT_Outline* outline );
/**************************************************************
*
* @function:
* SW_FT_Stroker_Done
*
* @description:
* Destroy a stroker object.
*
* @input:
* stroker ::
* A stroker handle. Can be NULL.
*/
void
SW_FT_Stroker_Done( SW_FT_Stroker stroker );
#endif // SW_FT_STROKER_H
|
df29f66489d24a9bfe12a27f66e647b0504b9b2e
|
131b6d5381fc3bb4403682135b77f9bce91e79f1
|
/nx/include/switch/runtime/nxlink.h
|
5072a58c6a0ef8220ec00b4b74e6ab760822525b
|
[
"ISC"
] |
permissive
|
switchbrew/libnx
|
53deb695b9ee6f3981c559125e8fce3bce6852b7
|
4fcdb6eb34b20f1f65eb9791fe513a710a001bea
|
refs/heads/master
| 2023-08-28T17:00:22.025929
| 2023-08-11T04:11:38
| 2023-08-12T14:51:58
| 103,794,142
| 1,286
| 299
|
ISC
| 2023-09-09T12:08:36
| 2017-09-17T01:12:38
|
C
|
UTF-8
|
C
| false
| false
| 1,106
|
h
|
nxlink.h
|
/**
* @file nxlink.h
* @brief Netloader (nxlink) utilities
* @author WinterMute
* @copyright libnx Authors
*/
#pragma once
#include "../types.h"
struct in_addr;
/// Address of the host connected through nxlink
extern struct in_addr __nxlink_host;
#define NXLINK_SERVER_PORT 28280 ///< nxlink TCP server port
#define NXLINK_CLIENT_PORT 28771 ///< nxlink TCP client port
/**
* @brief Connects to the nxlink host, setting up an output stream.
* @param[in] redirStdout Whether to redirect stdout to nxlink output.
* @param[in] redirStderr Whether to redirect stderr to nxlink output.
* @return Socket fd on success, negative number on failure.
* @note The socket should be closed with close() during application cleanup.
*/
int nxlinkConnectToHost(bool redirStdout, bool redirStderr);
/// Same as \ref nxlinkConnectToHost but redirecting both stdout/stderr.
NX_INLINE int nxlinkStdio(void) {
return nxlinkConnectToHost(true, true);
}
/// Same as \ref nxlinkConnectToHost but redirecting only stderr.
NX_INLINE int nxlinkStdioForDebug(void) {
return nxlinkConnectToHost(false, true);
}
|
45cc1f5d149bb18c8376879bc300163240cc5d51
|
9ceacf33fd96913cac7ef15492c126d96cae6911
|
/usr.sbin/ntpd/control.c
|
b86e615e86ca349cf5d8ddaf063111f994d2411d
|
[] |
no_license
|
openbsd/src
|
ab97ef834fd2d5a7f6729814665e9782b586c130
|
9e79f3a0ebd11a25b4bff61e900cb6de9e7795e9
|
refs/heads/master
| 2023-09-02T18:54:56.624627
| 2023-09-02T15:16:12
| 2023-09-02T15:16:12
| 66,966,208
| 3,394
| 1,235
| null | 2023-08-08T02:42:25
| 2016-08-30T18:18:25
|
C
|
UTF-8
|
C
| false
| false
| 10,280
|
c
|
control.c
|
/* $OpenBSD: control.c,v 1.19 2021/04/21 09:38:11 bluhm Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
* Copyright (c) 2012 Mike Miller <mmiller@mgm51.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS 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, DIRECT, 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.
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <errno.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <err.h>
#include "ntpd.h"
#define CONTROL_BACKLOG 5
#define square(x) ((x) * (x))
int
control_check(char *path)
{
struct sockaddr_un sun;
int fd;
bzero(&sun, sizeof(sun));
sun.sun_family = AF_UNIX;
strlcpy(sun.sun_path, path, sizeof(sun.sun_path));
if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
log_debug("control_check: socket check");
return (-1);
}
if (connect(fd, (struct sockaddr *)&sun, sizeof(sun)) == 0) {
log_debug("control_check: socket in use");
close(fd);
return (-1);
}
close(fd);
return (0);
}
int
control_init(char *path)
{
struct sockaddr_un sa;
int fd;
mode_t old_umask;
if ((fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0)) == -1) {
log_warn("control_init: socket");
return (-1);
}
memset(&sa, 0, sizeof(sa));
sa.sun_family = AF_UNIX;
if (strlcpy(sa.sun_path, path, sizeof(sa.sun_path)) >=
sizeof(sa.sun_path))
errx(1, "ctl socket name too long");
if (unlink(path) == -1)
if (errno != ENOENT) {
log_warn("control_init: unlink %s", path);
close(fd);
return (-1);
}
old_umask = umask(S_IXUSR|S_IXGRP|S_IWOTH|S_IROTH|S_IXOTH);
if (bind(fd, (struct sockaddr *)&sa, sizeof(sa)) == -1) {
log_warn("control_init: bind: %s", path);
close(fd);
umask(old_umask);
return (-1);
}
umask(old_umask);
if (chmod(path, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP) == -1) {
log_warn("control_init: chmod");
close(fd);
(void)unlink(path);
return (-1);
}
session_socket_nonblockmode(fd);
return (fd);
}
int
control_listen(int fd)
{
if (fd != -1 && listen(fd, CONTROL_BACKLOG) == -1) {
log_warn("control_listen: listen");
return (-1);
}
return (0);
}
void
control_shutdown(int fd)
{
close(fd);
}
int
control_accept(int listenfd)
{
int connfd;
socklen_t len;
struct sockaddr_un sa;
struct ctl_conn *ctl_conn;
len = sizeof(sa);
if ((connfd = accept(listenfd,
(struct sockaddr *)&sa, &len)) == -1) {
if (errno != EWOULDBLOCK && errno != EINTR)
log_warn("control_accept: accept");
return (0);
}
session_socket_nonblockmode(connfd);
if ((ctl_conn = calloc(1, sizeof(struct ctl_conn))) == NULL) {
log_warn("control_accept");
close(connfd);
return (0);
}
imsg_init(&ctl_conn->ibuf, connfd);
TAILQ_INSERT_TAIL(&ctl_conns, ctl_conn, entry);
return (1);
}
struct ctl_conn *
control_connbyfd(int fd)
{
struct ctl_conn *c;
TAILQ_FOREACH(c, &ctl_conns, entry) {
if (c->ibuf.fd == fd)
break;
}
return (c);
}
int
control_close(int fd)
{
struct ctl_conn *c;
if ((c = control_connbyfd(fd)) == NULL) {
log_warn("control_close: fd %d: not found", fd);
return (0);
}
msgbuf_clear(&c->ibuf.w);
TAILQ_REMOVE(&ctl_conns, c, entry);
close(c->ibuf.fd);
free(c);
return (1);
}
int
control_dispatch_msg(struct pollfd *pfd, u_int *ctl_cnt)
{
struct imsg imsg;
struct ctl_conn *c;
struct ntp_peer *p;
struct ntp_sensor *s;
struct ctl_show_status c_status;
struct ctl_show_peer c_peer;
struct ctl_show_sensor c_sensor;
int cnt;
ssize_t n;
if ((c = control_connbyfd(pfd->fd)) == NULL) {
log_warn("control_dispatch_msg: fd %d: not found", pfd->fd);
return (0);
}
if (pfd->revents & POLLOUT)
if (msgbuf_write(&c->ibuf.w) <= 0 && errno != EAGAIN) {
*ctl_cnt -= control_close(pfd->fd);
return (1);
}
if (!(pfd->revents & POLLIN))
return (0);
if (((n = imsg_read(&c->ibuf)) == -1 && errno != EAGAIN) || n == 0) {
*ctl_cnt -= control_close(pfd->fd);
return (1);
}
for (;;) {
if ((n = imsg_get(&c->ibuf, &imsg)) == -1) {
*ctl_cnt -= control_close(pfd->fd);
return (1);
}
if (n == 0)
break;
switch (imsg.hdr.type) {
case IMSG_CTL_SHOW_STATUS:
build_show_status(&c_status);
imsg_compose(&c->ibuf, IMSG_CTL_SHOW_STATUS, 0, 0, -1,
&c_status, sizeof (c_status));
break;
case IMSG_CTL_SHOW_PEERS:
cnt = 0;
TAILQ_FOREACH(p, &conf->ntp_peers, entry) {
build_show_peer(&c_peer, p);
imsg_compose(&c->ibuf, IMSG_CTL_SHOW_PEERS,
0, 0, -1, &c_peer, sizeof(c_peer));
cnt++;
}
imsg_compose(&c->ibuf, IMSG_CTL_SHOW_PEERS_END,
0, 0, -1, &cnt, sizeof(cnt));
break;
case IMSG_CTL_SHOW_SENSORS:
cnt = 0;
TAILQ_FOREACH(s, &conf->ntp_sensors, entry) {
build_show_sensor(&c_sensor, s);
imsg_compose(&c->ibuf, IMSG_CTL_SHOW_SENSORS,
0, 0, -1, &c_sensor, sizeof(c_sensor));
cnt++;
}
imsg_compose(&c->ibuf, IMSG_CTL_SHOW_SENSORS_END,
0, 0, -1, &cnt, sizeof(cnt));
break;
case IMSG_CTL_SHOW_ALL:
build_show_status(&c_status);
imsg_compose(&c->ibuf, IMSG_CTL_SHOW_STATUS, 0, 0, -1,
&c_status, sizeof (c_status));
cnt = 0;
TAILQ_FOREACH(p, &conf->ntp_peers, entry) {
build_show_peer(&c_peer, p);
imsg_compose(&c->ibuf, IMSG_CTL_SHOW_PEERS,
0, 0, -1, &c_peer, sizeof(c_peer));
cnt++;
}
imsg_compose(&c->ibuf, IMSG_CTL_SHOW_PEERS_END,
0, 0, -1, &cnt, sizeof(cnt));
cnt = 0;
TAILQ_FOREACH(s, &conf->ntp_sensors, entry) {
build_show_sensor(&c_sensor, s);
imsg_compose(&c->ibuf, IMSG_CTL_SHOW_SENSORS,
0, 0, -1, &c_sensor, sizeof(c_sensor));
cnt++;
}
imsg_compose(&c->ibuf, IMSG_CTL_SHOW_SENSORS_END,
0, 0, -1, &cnt, sizeof(cnt));
imsg_compose(&c->ibuf, IMSG_CTL_SHOW_ALL_END,
0, 0, -1, NULL, 0);
break;
default:
break;
}
imsg_free(&imsg);
}
return (0);
}
void
session_socket_nonblockmode(int fd)
{
int flags;
if ((flags = fcntl(fd, F_GETFL)) == -1)
fatal("fcntl F_GETFL");
flags |= O_NONBLOCK;
if ((flags = fcntl(fd, F_SETFL, flags)) == -1)
fatal("fcntl F_SETFL");
}
void
build_show_status(struct ctl_show_status *cs)
{
struct ntp_peer *p;
struct ntp_sensor *s;
cs->peercnt = cs->valid_peers = 0;
cs->sensorcnt = cs->valid_sensors = 0;
TAILQ_FOREACH(p, &conf->ntp_peers, entry) {
cs->peercnt++;
if (p->trustlevel >= TRUSTLEVEL_BADPEER)
cs->valid_peers++;
}
TAILQ_FOREACH(s, &conf->ntp_sensors, entry) {
cs->sensorcnt++;
if (s->update.good)
cs->valid_sensors++;
}
cs->synced = conf->status.synced;
cs->stratum = conf->status.stratum;
cs->clock_offset = getoffset() * 1000.0;
cs->constraints = !TAILQ_EMPTY(&conf->constraints);
cs->constraint_median = conf->constraint_median;
cs->constraint_last = conf->constraint_last;
cs->constraint_errors = conf->constraint_errors;
}
void
build_show_peer(struct ctl_show_peer *cp, struct ntp_peer *p)
{
const char *a = "not resolved";
const char *pool = "", *addr_head_name = "";
const char *auth = "";
int shift, best = -1, validdelaycnt = 0, jittercnt = 0;
time_t now;
now = getmonotime();
if (p->addr) {
a = log_sockaddr((struct sockaddr *)&p->addr->ss);
if (p->addr->notauth)
auth = " (non-dnssec lookup)";
}
if (p->addr_head.pool)
pool = "from pool ";
if (0 != strcmp(a, p->addr_head.name) || p->addr_head.pool)
addr_head_name = p->addr_head.name;
snprintf(cp->peer_desc, sizeof(cp->peer_desc),
"%s %s%s%s", a, pool, addr_head_name, auth);
cp->offset = cp->delay = 0.0;
for (shift = 0; shift < OFFSET_ARRAY_SIZE; shift++) {
if (p->reply[shift].delay > 0.0) {
cp->offset += p->reply[shift].offset;
cp->delay += p->reply[shift].delay;
if (best == -1 ||
p->reply[shift].delay < p->reply[best].delay)
best = shift;
validdelaycnt++;
}
}
if (validdelaycnt > 1) {
cp->offset /= validdelaycnt;
cp->delay /= validdelaycnt;
}
cp->jitter = 0.0;
if (best != -1) {
for (shift = 0; shift < OFFSET_ARRAY_SIZE; shift++) {
if (p->reply[shift].delay > 0.0 && shift != best) {
cp->jitter += square(p->reply[shift].delay -
p->reply[best].delay);
jittercnt++;
}
}
if (jittercnt > 1)
cp->jitter /= jittercnt;
cp->jitter = sqrt(cp->jitter);
}
if (p->shift == 0)
shift = OFFSET_ARRAY_SIZE - 1;
else
shift = p->shift - 1;
if (conf->status.synced == 1 &&
p->reply[shift].status.send_refid == conf->status.refid)
cp->syncedto = 1;
else
cp->syncedto = 0;
/* milliseconds to reduce number of leading zeroes */
cp->offset *= 1000.0;
cp->delay *= 1000.0;
cp->jitter *= 1000.0;
cp->weight = p->weight;
cp->trustlevel = p->trustlevel;
cp->stratum = p->reply[shift].status.stratum;
cp->next = p->next - now < 0 ? 0 : p->next - now;
cp->poll = p->poll;
}
void
build_show_sensor(struct ctl_show_sensor *cs, struct ntp_sensor *s)
{
time_t now;
u_int8_t shift;
u_int32_t refid;
now = getmonotime();
memcpy(&refid, SENSOR_DEFAULT_REFID, sizeof(refid));
refid = refid == s->refid ? 0 : s->refid;
snprintf(cs->sensor_desc, sizeof(cs->sensor_desc),
"%s %.4s", s->device, (char *)&refid);
if (s->shift == 0)
shift = SENSOR_OFFSETS - 1;
else
shift = s->shift - 1;
if (conf->status.synced == 1 &&
s->offsets[shift].status.send_refid == conf->status.refid)
cs->syncedto = 1;
else
cs->syncedto = 0;
cs->weight = s->weight;
cs->good = s->update.good;
cs->stratum = s->offsets[shift].status.stratum;
cs->next = s->next - now < 0 ? 0 : s->next - now;
cs->poll = SENSOR_QUERY_INTERVAL;
cs->offset = s->offsets[shift].offset * 1000.0;
cs->correction = (double)s->correction / 1000.0;
}
|
6615622179803a799e72d464631249b41cc1b557
|
06f2e78f4d736c8ac9cb7e98a5abcc28ed4f25b2
|
/public/build.h
|
2f8fffae300111af7eb77e0efd435526d6287682
|
[] |
no_license
|
FWGS/xash3d-fwgs
|
07a1002396f43754b49521681cc771c0d89051ed
|
435b95fc5ab3fc5b1a79212ffdc901a47769d056
|
refs/heads/master
| 2023-09-01T05:20:48.112400
| 2023-08-31T05:40:24
| 2023-08-31T05:40:24
| 127,814,982
| 1,078
| 275
| null | 2023-09-12T17:49:04
| 2018-04-02T21:33:02
|
C
|
UTF-8
|
C
| false
| false
| 7,484
|
h
|
build.h
|
/*
build.h - compile-time build information
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
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 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.
For more information, please refer to <http://unlicense.org/>
*/
#pragma once
#ifndef BUILD_H
#define BUILD_H
/*
All XASH_* macros set by this header are guaranteed to have positive value
otherwise not defined.
Every macro is intended to be the unified interface for buildsystems that lack
platform & CPU detection, and a neat quick way for checks in platform code
For Q_build* macros, refer to buildenums.h
Any new define must be undefined at first
You can generate #undef list below with this oneliner:
$ sed 's/\t//g' build.h | grep '^#define XASH' | awk '{ print $2 }' | \
sort | uniq | awk '{ print "#undef " $1 }'
Then you can use another oneliner to query all variables:
$ grep '^#undef XASH' build.h | awk '{ print $2 }'
*/
#undef XASH_64BIT
#undef XASH_AMD64
#undef XASH_ANDROID
#undef XASH_APPLE
#undef XASH_ARM
#undef XASH_ARM_HARDFP
#undef XASH_ARM_SOFTFP
#undef XASH_ARMv4
#undef XASH_ARMv5
#undef XASH_ARMv6
#undef XASH_ARMv7
#undef XASH_ARMv8
#undef XASH_BIG_ENDIAN
#undef XASH_DOS4GW
#undef XASH_E2K
#undef XASH_EMSCRIPTEN
#undef XASH_FREEBSD
#undef XASH_HAIKU
#undef XASH_IOS
#undef XASH_IRIX
#undef XASH_JS
#undef XASH_LINUX
#undef XASH_LINUX_UNKNOWN
#undef XASH_LITTLE_ENDIAN
#undef XASH_MIPS
#undef XASH_MOBILE_PLATFORM
#undef XASH_NETBSD
#undef XASH_OPENBSD
#undef XASH_POSIX
#undef XASH_PPC
#undef XASH_RISCV
#undef XASH_RISCV_DOUBLEFP
#undef XASH_RISCV_SINGLEFP
#undef XASH_RISCV_SOFTFP
#undef XASH_SERENITY
#undef XASH_WIN32
#undef XASH_X86
#undef XASH_NSWITCH
#undef XASH_PSVITA
//================================================================
//
// PLATFORM DETECTION CODE
//
//================================================================
#if defined _WIN32
#define XASH_WIN32 1
#elif defined __EMSCRIPTEN__
#define XASH_EMSCRIPTEN 1
#elif defined __WATCOMC__ && defined __DOS__
#define XASH_DOS4GW 1
#else // POSIX compatible
#define XASH_POSIX 1
#if defined __linux__
#if defined __ANDROID__
#define XASH_ANDROID 1
#else
#include <features.h>
// if our system libc has features.h header
// try to detect it to not confuse other libcs with built with glibc game libraries
#if !defined __GLIBC__
#define XASH_LINUX_UNKNOWN 1
#endif
#endif
#define XASH_LINUX 1
#elif defined __FreeBSD__
#define XASH_FREEBSD 1
#elif defined __NetBSD__
#define XASH_NETBSD 1
#elif defined __OpenBSD__
#define XASH_OPENBSD 1
#elif defined __HAIKU__
#define XASH_HAIKU 1
#elif defined __serenity__
#define XASH_SERENITY 1
#elif defined __sgi
#define XASH_IRIX 1
#elif defined __APPLE__
#include <TargetConditionals.h>
#define XASH_APPLE 1
#if TARGET_OS_IOS
#define XASH_IOS 1
#endif // TARGET_OS_IOS
#elif defined __SWITCH__
#define XASH_NSWITCH 1
#elif defined __vita__
#define XASH_PSVITA 1
#else
#error
#endif
#endif
// XASH_SAILFISH is special: SailfishOS by itself is a normal GNU/Linux platform
// It doesn't make sense to split it to separate platform
// but we still need XASH_MOBILE_PLATFORM for the engine.
// So this macro is defined entirely in build-system: see main wscript
// HLSDK/PrimeXT/other SDKs users note: you may ignore this macro
#if XASH_ANDROID || XASH_IOS || XASH_NSWITCH || XASH_PSVITA || XASH_SAILFISH
#define XASH_MOBILE_PLATFORM 1
#endif
//================================================================
//
// ENDIANNESS DEFINES
//
//================================================================
#if !defined XASH_ENDIANNESS
#if defined XASH_WIN32 || __LITTLE_ENDIAN__
//!!! Probably all WinNT installations runs in little endian
#define XASH_LITTLE_ENDIAN 1
#elif __BIG_ENDIAN__
#define XASH_BIG_ENDIAN 1
#elif defined __BYTE_ORDER__ && defined __ORDER_BIG_ENDIAN__ && defined __ORDER_LITTLE_ENDIAN__ // some compilers define this
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
#define XASH_BIG_ENDIAN 1
#elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#define XASH_LITTLE_ENDIAN 1
#endif
#else
#include <sys/param.h>
#if __BYTE_ORDER == __BIG_ENDIAN
#define XASH_BIG_ENDIAN 1
#elif __BYTE_ORDER == __LITTLE_ENDIAN
#define XASH_LITTLE_ENDIAN 1
#endif
#endif // !XASH_WIN32
#endif
//================================================================
//
// CPU ARCHITECTURE DEFINES
//
//================================================================
#if defined __x86_64__ || defined _M_X64
#define XASH_64BIT 1
#define XASH_AMD64 1
#elif defined __i386__ || defined _X86_ || defined _M_IX86
#define XASH_X86 1
#elif defined __aarch64__ || defined _M_ARM64
#define XASH_64BIT 1
#define XASH_ARM 8
#elif defined __mips__
#define XASH_MIPS 1
#elif defined __EMSCRIPTEN__
#define XASH_JS 1
#elif defined __e2k__
#define XASH_64BIT 1
#define XASH_E2K 1
#elif defined __PPC__ || defined __powerpc__
#define XASH_PPC 1
#if defined __PPC64__ || defined __powerpc64__
#define XASH_64BIT 1
#endif
#elif defined _M_ARM // msvc
#define XASH_ARM 7
#define XASH_ARM_HARDFP 1
#elif defined __arm__
#if __ARM_ARCH == 8 || __ARM_ARCH_8__
#define XASH_ARM 8
#elif __ARM_ARCH == 7 || __ARM_ARCH_7__
#define XASH_ARM 7
#elif __ARM_ARCH == 6 || __ARM_ARCH_6__ || __ARM_ARCH_6J__
#define XASH_ARM 6
#elif __ARM_ARCH == 5 || __ARM_ARCH_5__
#define XASH_ARM 5
#elif __ARM_ARCH == 4 || __ARM_ARCH_4__
#define XASH_ARM 4
#else
#error "Unknown ARM"
#endif
#if defined __SOFTFP__ || __ARM_PCS_VFP == 0
#define XASH_ARM_SOFTFP 1
#else // __SOFTFP__
#define XASH_ARM_HARDFP 1
#endif // __SOFTFP__
#elif defined __riscv
#define XASH_RISCV 1
#if __riscv_xlen == 64
#define XASH_64BIT 1
#elif __riscv_xlen != 32
#error "Unknown RISC-V ABI"
#endif
#if defined __riscv_float_abi_soft
#define XASH_RISCV_SOFTFP 1
#elif defined __riscv_float_abi_single
#define XASH_RISCV_SINGLEFP 1
#elif defined __riscv_float_abi_double
#define XASH_RISCV_DOUBLEFP 1
#else
#error "Unknown RISC-V float ABI"
#endif
#else
#error "Place your architecture name here! If this is a mistake, try to fix conditions above and report a bug"
#endif
#if XASH_ARM == 8
#define XASH_ARMv8 1
#elif XASH_ARM == 7
#define XASH_ARMv7 1
#elif XASH_ARM == 6
#define XASH_ARMv6 1
#elif XASH_ARM == 5
#define XASH_ARMv5 1
#elif XASH_ARM == 4
#define XASH_ARMv4 1
#endif
#endif // BUILD_H
|
b235a8ac80b8f079b95bdd1f21f3063864875f2c
|
25c64fb97b7cdb30ec1b6ddd2acf9a755fc33adf
|
/test/testdivert.c
|
6ad5fafdb390dd39654a8b55e7d7f93ad382d426
|
[
"MIT"
] |
permissive
|
arminbiere/kissat
|
386c1cfadf43562d36fccc47064c95296c9b812f
|
630d64d4d63c2816fc79a1a0340286b39677e97d
|
refs/heads/master
| 2023-09-04T01:39:44.293487
| 2023-06-24T15:51:43
| 2023-06-24T15:51:43
| 267,257,286
| 350
| 63
|
MIT
| 2022-06-23T12:15:24
| 2020-05-27T07:57:59
|
C
|
UTF-8
|
C
| false
| false
| 1,784
|
c
|
testdivert.c
|
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include "test.h"
static int dev_null = -1;
static int saved[3] = {-1, -1, -1};
void tissat_divert_stdout_and_stderr_to_dev_null (void) {
if (tissat_verbosity)
return;
assert (saved[1] < 0);
assert (saved[2] < 0);
if (dev_null < 0)
dev_null = open ("/dev/null", O_WRONLY);
assert (dev_null >= 3);
saved[1] = dup (1);
assert (saved[1] >= 4);
saved[2] = dup (2);
assert (saved[2] >= 5);
int res;
res = dup2 (dev_null, 1);
assert (res == 1);
res = dup2 (dev_null, 2);
assert (res == 2);
}
#define ASSERT(COND) \
do { \
if (COND) \
break; \
abort (); \
} while (true)
static void restore_stdout (void) {
if (saved[1] < 0)
return;
fflush (stdout);
ASSERT (saved[1] >= 4);
int res;
res = dup2 (saved[1], 1);
ASSERT (res == 1);
res = close (saved[1]);
ASSERT (!res);
saved[1] = -1;
}
static void restore_stderr (void) {
if (saved[2] < 0)
return;
fflush (stderr);
ASSERT (saved[2] >= 5);
int res;
res = dup2 (saved[2], 2);
ASSERT (res == 2);
res = close (saved[2]);
ASSERT (!res);
saved[2] = -1;
}
void tissat_restore_stdout_and_stderr (void) {
if (tissat_verbosity)
return;
restore_stdout ();
restore_stderr ();
}
void tissat_redirect_stderr_to_stdout (void) {
if (dev_null >= 0)
return;
assert (saved[2] < 0);
saved[2] = dup (2);
assert (saved[2] >= 3);
int res;
res = dup2 (1, 2);
assert (res == 2);
}
void tissat_restore_stderr (void) {
if (dev_null >= 0)
return;
if (saved[2] < 0)
return;
fflush (stderr);
ASSERT (saved[2] >= 3);
int res;
res = dup2 (saved[2], 2);
ASSERT (res == 2);
res = close (saved[2]);
ASSERT (!res);
saved[2] = -1;
}
|
017cac73c5fa366fc92b878a26e1aa3b79fe1d1f
|
7f6c235b0598353549959c18f69eefd20b766907
|
/examples/z88/macro.c
|
081d07ebd0e75c415a262ab4287105cb58ecf84d
|
[
"ClArtistic"
] |
permissive
|
z88dk/z88dk
|
46dfd4905f36d99333173cadd0a660839befc9f0
|
8b07f37cc43c5d9ffe69b563c80763491d8faff7
|
refs/heads/master
| 2023-09-04T19:29:49.254958
| 2023-09-03T20:51:24
| 2023-09-03T20:51:24
| 54,035,569
| 820
| 263
|
NOASSERTION
| 2023-09-05T11:09:04
| 2016-03-16T13:48:16
|
Assembly
|
UTF-8
|
C
| false
| false
| 378
|
c
|
macro.c
|
/*
* At Last! Macros for z80asm
*
* Short example of how to do macros in Small C, this required a bit
* of a rewrite of doasmfunc() but I think it needed it, anyway, here's
* how to do them. Recognise the code?!?! <grin>
*
* djm 18/3/99
*/
#define CLEAR(st,len) asm("ld\thl, "#st"\nld\tde,"#st"+1\nld\tbc,"#len"\nld\t(hl),0\nldir\n");
main()
{
CLEAR(16384,6911)
}
|
9ec62f8f79b881dc87b927d8af6e7d13be15973a
|
165cf5ce4f80ca7037237f3abf59eeef68e3105e
|
/lib/nghttp3_buf.c
|
aae075a73cc4bec5ab0122121cba86494a996c36
|
[
"MIT"
] |
permissive
|
ngtcp2/nghttp3
|
1eb043960397ec5bdd3f704d4ccc9b11613ec99c
|
dd5d9d55dcb13a1729b7ad1c8c30f8e5ad82c4df
|
refs/heads/main
| 2023-08-31T03:23:38.565595
| 2023-08-30T09:58:04
| 2023-08-30T09:58:04
| 156,868,263
| 693
| 82
|
MIT
| 2023-08-30T09:55:36
| 2018-11-09T13:49:36
|
C
|
UTF-8
|
C
| false
| false
| 2,709
|
c
|
nghttp3_buf.c
|
/*
* nghttp3
*
* Copyright (c) 2019 nghttp3 contributors
* Copyright (c) 2017 ngtcp2 contributors
*
* 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 "nghttp3_buf.h"
void nghttp3_buf_init(nghttp3_buf *buf) {
buf->begin = buf->end = buf->pos = buf->last = NULL;
}
void nghttp3_buf_wrap_init(nghttp3_buf *buf, uint8_t *src, size_t len) {
buf->begin = buf->pos = buf->last = src;
buf->end = buf->begin + len;
}
void nghttp3_buf_free(nghttp3_buf *buf, const nghttp3_mem *mem) {
nghttp3_mem_free(mem, buf->begin);
}
size_t nghttp3_buf_left(const nghttp3_buf *buf) {
return (size_t)(buf->end - buf->last);
}
size_t nghttp3_buf_len(const nghttp3_buf *buf) {
return (size_t)(buf->last - buf->pos);
}
size_t nghttp3_buf_cap(const nghttp3_buf *buf) {
return (size_t)(buf->end - buf->begin);
}
void nghttp3_buf_reset(nghttp3_buf *buf) { buf->pos = buf->last = buf->begin; }
int nghttp3_buf_reserve(nghttp3_buf *buf, size_t size, const nghttp3_mem *mem) {
uint8_t *p;
nghttp3_ssize pos_offset, last_offset;
if ((size_t)(buf->end - buf->begin) >= size) {
return 0;
}
pos_offset = buf->pos - buf->begin;
last_offset = buf->last - buf->begin;
p = nghttp3_mem_realloc(mem, buf->begin, size);
if (p == NULL) {
return NGHTTP3_ERR_NOMEM;
}
buf->begin = p;
buf->end = p + size;
buf->pos = p + pos_offset;
buf->last = p + last_offset;
return 0;
}
void nghttp3_buf_swap(nghttp3_buf *a, nghttp3_buf *b) {
nghttp3_buf c = *a;
*a = *b;
*b = c;
}
void nghttp3_typed_buf_init(nghttp3_typed_buf *tbuf, const nghttp3_buf *buf,
nghttp3_buf_type type) {
tbuf->buf = *buf;
tbuf->type = type;
}
|
d5438e2e83190067644f3e39281addcc66292d3c
|
581bdcc078d282e388f1b655d4cfc4e08152d117
|
/phlib/include/refp.h
|
944f738efca5efaa894215b84bee1e9b0708d479
|
[
"MIT",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Zlib",
"LGPL-2.1-or-later",
"GPL-2.0-only",
"LicenseRef-scancode-public-domain"
] |
permissive
|
winsiderss/systeminformer
|
774928be871f0055263ac5e62ae0a598b098486b
|
5a6b442acd45d681f699a133d476a3211d072871
|
refs/heads/master
| 2023-08-28T15:43:41.074679
| 2023-08-27T20:59:20
| 2023-08-27T20:59:20
| 50,824,485
| 2,137
| 292
|
MIT
| 2023-09-10T22:35:12
| 2016-02-01T08:10:21
|
C
|
UTF-8
|
C
| false
| false
| 4,595
|
h
|
refp.h
|
/*
* Copyright (c) 2022 Winsider Seminars & Solutions, Inc. All rights reserved.
*
* This file is part of System Informer.
*
* Authors:
*
* wj32 2009-2016
*
*/
#ifndef _PH_REFP_H
#define _PH_REFP_H
#define PH_OBJECT_TYPE_TABLE_SIZE 256
/** The object was allocated from the small free list. */
#define PH_OBJECT_FROM_SMALL_FREE_LIST 0x1
/** The object was allocated from the type free list. */
#define PH_OBJECT_FROM_TYPE_FREE_LIST 0x2
/**
* The object header contains object manager information including the reference count of an object
* and its type.
*/
typedef struct _PH_OBJECT_HEADER
{
union
{
struct
{
USHORT TypeIndex;
UCHAR Flags;
UCHAR Reserved1;
#ifdef _WIN64
ULONG Reserved2;
#endif
union
{
LONG RefCount;
struct
{
LONG SavedTypeIndex : 16;
LONG SavedFlags : 8;
LONG Reserved : 7;
LONG DeferDelete : 1; // MUST be the high bit, so that RefCount < 0 when deferring delete
};
};
#ifdef _WIN64
ULONG Reserved3;
#endif
};
SLIST_ENTRY DeferDeleteListEntry;
};
#ifdef DEBUG
PVOID StackBackTrace[16];
LIST_ENTRY ObjectListEntry;
#endif
/**
* The body of the object. For use by the \ref PhObjectToObjectHeader and
* \ref PhObjectHeaderToObject macros.
*/
QUAD_PTR Body;
} PH_OBJECT_HEADER, *PPH_OBJECT_HEADER;
#ifndef DEBUG
#ifdef _WIN64
C_ASSERT(FIELD_OFFSET(PH_OBJECT_HEADER, TypeIndex) == 0x0);
C_ASSERT(FIELD_OFFSET(PH_OBJECT_HEADER, Flags) == 0x2);
C_ASSERT(FIELD_OFFSET(PH_OBJECT_HEADER, Reserved1) == 0x3);
C_ASSERT(FIELD_OFFSET(PH_OBJECT_HEADER, Reserved2) == 0x4);
C_ASSERT(FIELD_OFFSET(PH_OBJECT_HEADER, RefCount) == 0x8);
C_ASSERT(FIELD_OFFSET(PH_OBJECT_HEADER, Reserved3) == 0xc);
C_ASSERT(FIELD_OFFSET(PH_OBJECT_HEADER, DeferDeleteListEntry) == 0x0);
C_ASSERT(FIELD_OFFSET(PH_OBJECT_HEADER, Body) == 0x10);
#else
C_ASSERT(FIELD_OFFSET(PH_OBJECT_HEADER, TypeIndex) == 0x0);
C_ASSERT(FIELD_OFFSET(PH_OBJECT_HEADER, Flags) == 0x2);
C_ASSERT(FIELD_OFFSET(PH_OBJECT_HEADER, Reserved1) == 0x3);
C_ASSERT(FIELD_OFFSET(PH_OBJECT_HEADER, RefCount) == 0x4);
C_ASSERT(FIELD_OFFSET(PH_OBJECT_HEADER, DeferDeleteListEntry) == 0x0);
C_ASSERT(FIELD_OFFSET(PH_OBJECT_HEADER, Body) == 0x8);
#endif
#endif
/**
* Gets a pointer to the object header for an object.
*
* \param Object A pointer to an object.
*
* \return A pointer to the object header of the object.
*/
#define PhObjectToObjectHeader(Object) ((PPH_OBJECT_HEADER)CONTAINING_RECORD((Object), PH_OBJECT_HEADER, Body))
/**
* Gets a pointer to an object from an object header.
*
* \param ObjectHeader A pointer to an object header.
*
* \return A pointer to an object.
*/
#define PhObjectHeaderToObject(ObjectHeader) ((PVOID)&((PPH_OBJECT_HEADER)(ObjectHeader))->Body)
/**
* Calculates the total size to allocate for an object.
*
* \param Size The size of the object to allocate.
*
* \return The new size, including space for the object header.
*/
#define PhAddObjectHeaderSize(Size) ((Size) + UFIELD_OFFSET(PH_OBJECT_HEADER, Body))
/** An object type specifies a kind of object and its delete procedure. */
typedef struct _PH_OBJECT_TYPE
{
/** The flags that were used to create the object type. */
USHORT Flags;
UCHAR TypeIndex;
UCHAR Reserved;
/** The total number of objects of this type that are alive. */
ULONG NumberOfObjects;
/** An optional procedure called when objects of this type are freed. */
PPH_TYPE_DELETE_PROCEDURE DeleteProcedure;
/** The name of the type. */
PWSTR Name;
/** A free list to use when allocating for this type. */
PH_FREE_LIST FreeList;
} PH_OBJECT_TYPE, *PPH_OBJECT_TYPE;
/**
* Increments a reference count, but will never increment from a nonpositive value to 1.
*
* \param RefCount A pointer to a reference count.
*/
FORCEINLINE
BOOLEAN
PhpInterlockedIncrementSafe(
_Inout_ PLONG RefCount
)
{
/* Here we will attempt to increment the reference count, making sure that it is positive. */
return _InterlockedIncrementPositive(RefCount);
}
PPH_OBJECT_HEADER PhpAllocateObject(
_In_ PPH_OBJECT_TYPE ObjectType,
_In_ SIZE_T ObjectSize
);
VOID PhpFreeObject(
_In_ PPH_OBJECT_HEADER ObjectHeader
);
VOID PhpDeferDeleteObject(
_In_ PPH_OBJECT_HEADER ObjectHeader
);
NTSTATUS PhpDeferDeleteObjectRoutine(
_In_ PVOID Parameter
);
#endif
|
104aaa49e92eae66cb6fa58568133e9250e62437
|
364bae9ced813c2b09b94226208675136ec97182
|
/src/tr/uv/pr_msg.h
|
494c4a82b17d4639b79fd5903da9448c86cdccb3
|
[
"MIT"
] |
permissive
|
NetEase/libpomelo2
|
4e12b87ae9183c64a44056400eaf4591833bb547
|
63e4ffdb1569cad58cb3f46aaec137cf59d07133
|
refs/heads/master
| 2023-09-06T08:22:51.958543
| 2016-04-29T02:36:55
| 2016-04-29T07:52:51
| 22,861,276
| 130
| 75
| null | 2016-12-02T19:37:23
| 2014-08-12T01:56:00
|
C
|
UTF-8
|
C
| false
| false
| 1,189
|
h
|
pr_msg.h
|
/**
* Copyright (c) 2014,2015 NetEase, Inc. and other Pomelo contributors
* MIT Licensed.
*/
#ifndef PR_MSG_H
#define PR_MSG_H
#include <stdint.h>
#include "pr_pkg.h"
#include <pc_JSON.h>
typedef struct tr_uv_tcp_transport_s tr_uv_tcp_transport_t;
typedef struct {
unsigned int id;
const char* route;
const char* msg;
} pc_msg_t;
uv_buf_t pr_default_msg_encoder(tr_uv_tcp_transport_t* tt, const pc_msg_t* msg);
pc_msg_t pr_default_msg_decoder(tr_uv_tcp_transport_t* tt, const uv_buf_t* buf);
/**
* internal use
*/
typedef struct {
char* base;
int len;
} pc_buf_t;
pc_buf_t pc_default_msg_encode(const pc_JSON* route2code, const pc_JSON* client_protos, const pc_msg_t* msg);
pc_msg_t pc_default_msg_decode(const pc_JSON* code2route, const pc_JSON* server_protos, const pc_buf_t* buf);
pc_buf_t pc_body_json_encode(const pc_JSON* msg);
pc_JSON* pc_body_json_decode(const char *data, size_t offset, size_t len);
pc_buf_t pc_body_pb_encode(const pc_JSON*msg, const pc_JSON* gprotos, const pc_JSON* pb_def);
pc_JSON* pc_body_pb_decode(const char* data, size_t offset, size_t len,
const pc_JSON* gprotos, const pc_JSON* pb_def);
#endif
|
e3bbef5a797b46dbd42f38643354df4ceb45c405
|
26d3db4534584624aa18cd2d297f4350682ea51f
|
/src/state.h
|
19f06a87fc8d71728e099aa8e8e92fb36fa29510
|
[
"MIT"
] |
permissive
|
sysprog21/rv32emu
|
b4da9ae47eff5ecb9a044f75b0191ddd3b5fe69a
|
1275468f2bc1a37ea412f40629a32062bacbb156
|
refs/heads/master
| 2023-09-05T23:13:39.631150
| 2023-09-05T13:27:31
| 2023-09-05T13:27:31
| 304,615,451
| 193
| 49
|
MIT
| 2023-09-12T11:24:34
| 2020-10-16T12:05:06
|
C
|
UTF-8
|
C
| false
| false
| 988
|
h
|
state.h
|
/*
* rv32emu is freely redistributable under the MIT License. See the file
* "LICENSE" for information on usage and redistribution of this file.
*/
#pragma once
#include <stdio.h>
#include <stdlib.h>
#include "io.h"
#include "map.h"
#include "riscv.h"
/* state structure passed to the runtime */
typedef struct {
memory_t *mem;
/* the data segment break address */
riscv_word_t break_addr;
/* file descriptor map: int -> (FILE *) */
map_t fd_map;
} state_t;
static inline state_t *state_new()
{
state_t *s = malloc(sizeof(state_t));
s->mem = memory_new();
s->break_addr = 0;
s->fd_map = map_init(int, FILE *, map_cmp_int);
FILE *files[] = {stdin, stdout, stderr};
for (size_t i = 0; i < sizeof(files) / sizeof(files[0]); i++)
map_insert(s->fd_map, &i, &files[i]);
return s;
}
static inline void state_delete(state_t *s)
{
if (!s)
return;
map_delete(s->fd_map);
memory_delete(s->mem);
free(s);
}
|
8e037ab13c355340da0dbac3d87df27077dcad16
|
d2253070a3a64b14dee5ca0b3d311919178e590c
|
/include/constants/item.h
|
a224291faf8602538e68fc88be7d817a8fed504b
|
[] |
no_license
|
pret/pokeemerald
|
ce232eccdde78502f3c251d672b26af3e1d7e508
|
d67914e114c937c4c80ce128ddc5523d4dc2cd40
|
refs/heads/master
| 2023-08-31T11:23:13.877932
| 2023-08-27T23:40:59
| 2023-08-27T23:40:59
| 43,677,244
| 1,944
| 1,903
| null | 2023-09-12T22:48:06
| 2015-10-05T10:09:22
|
C
|
UTF-8
|
C
| false
| false
| 484
|
h
|
item.h
|
#ifndef GUARD_ITEM_CONSTANTS_H
#define GUARD_ITEM_CONSTANTS_H
// These constants are used in gItems
#define POCKET_NONE 0
#define POCKET_ITEMS 1
#define POCKET_POKE_BALLS 2
#define POCKET_TM_HM 3
#define POCKET_BERRIES 4
#define POCKET_KEY_ITEMS 5
#define ITEMS_POCKET 0
#define BALLS_POCKET 1
#define TMHM_POCKET 2
#define BERRIES_POCKET 3
#define KEYITEMS_POCKET 4
#define POCKETS_COUNT 5
#endif // GUARD_ITEM_CONSTANTS_H
|
07d5959854e8ed7ff7bf9a30fa338dd43ebf3f5c
|
88ae8695987ada722184307301e221e1ba3cc2fa
|
/third_party/ffmpeg/libavfilter/vf_shuffleplanes.c
|
b2f64ad0763cb31727b2817c731e0672cf70b560
|
[
"BSD-3-Clause",
"LGPL-2.1-only",
"LGPL-3.0-only",
"LGPL-2.0-or-later",
"GPL-1.0-or-later",
"GPL-2.0-only",
"LGPL-2.1-or-later",
"GPL-3.0-or-later",
"LGPL-3.0-or-later",
"IJG",
"LicenseRef-scancode-other-permissive",
"MIT",
"GPL-2.0-or-later",
"Apache-2.0",
"GPL-3.0-only"
] |
permissive
|
iridium-browser/iridium-browser
|
71d9c5ff76e014e6900b825f67389ab0ccd01329
|
5ee297f53dc7f8e70183031cff62f37b0f19d25f
|
refs/heads/master
| 2023-08-03T16:44:16.844552
| 2023-07-20T15:17:00
| 2023-07-23T16:09:30
| 220,016,632
| 341
| 40
|
BSD-3-Clause
| 2021-08-13T13:54:45
| 2019-11-06T14:32:31
| null |
UTF-8
|
C
| false
| false
| 5,417
|
c
|
vf_shuffleplanes.c
|
/*
* This file is part of FFmpeg.
*
* FFmpeg 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.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libavutil/avstring.h"
#include "libavutil/common.h"
#include "libavutil/internal.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "libavutil/pixfmt.h"
#include "avfilter.h"
#include "internal.h"
#include "video.h"
typedef struct ShufflePlanesContext {
const AVClass *class;
/* number of planes in the selected pixel format */
int planes;
/* mapping indices */
int map[4];
/* set to 1 if some plane is used more than once, so we need to make a copy */
int copy;
} ShufflePlanesContext;
static int query_formats(AVFilterContext *ctx)
{
AVFilterFormats *formats = NULL;
ShufflePlanesContext *s = ctx->priv;
int fmt, ret, i;
for (fmt = 0; av_pix_fmt_desc_get(fmt); fmt++) {
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt);
int planes = av_pix_fmt_count_planes(fmt);
if (!(desc->flags & AV_PIX_FMT_FLAG_PAL) &&
!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL)) {
for (i = 0; i < 4; i++) {
if (s->map[i] >= planes)
break;
if ((desc->log2_chroma_h || desc->log2_chroma_w) &&
(i == 1 || i == 2) != (s->map[i] == 1 || s->map[i] == 2))
break;
}
if (i != 4)
continue;
if ((ret = ff_add_format(&formats, fmt)) < 0) {
return ret;
}
}
}
return ff_set_common_formats(ctx, formats);
}
static av_cold int shuffleplanes_config_input(AVFilterLink *inlink)
{
AVFilterContext *ctx = inlink->dst;
ShufflePlanesContext *s = ctx->priv;
int used[4] = { 0 };
int i;
s->copy = 0;
s->planes = av_pix_fmt_count_planes(inlink->format);
for (i = 0; i < s->planes; i++) {
if (used[s->map[i]])
s->copy = 1;
used[s->map[i]]++;
}
return 0;
}
static int shuffleplanes_filter_frame(AVFilterLink *inlink, AVFrame *frame)
{
AVFilterContext *ctx = inlink->dst;
ShufflePlanesContext *s = ctx->priv;
uint8_t *shuffled_data[4] = { NULL };
int shuffled_linesize[4] = { 0 };
int i, ret;
for (i = 0; i < s->planes; i++) {
shuffled_data[i] = frame->data[s->map[i]];
shuffled_linesize[i] = frame->linesize[s->map[i]];
}
memcpy(frame->data, shuffled_data, sizeof(shuffled_data));
memcpy(frame->linesize, shuffled_linesize, sizeof(shuffled_linesize));
if (s->copy) {
AVFrame *copy = ff_get_video_buffer(ctx->outputs[0], frame->width, frame->height);
if (!copy) {
ret = AVERROR(ENOMEM);
goto fail;
}
av_frame_copy(copy, frame);
ret = av_frame_copy_props(copy, frame);
if (ret < 0) {
av_frame_free(©);
goto fail;
}
av_frame_free(&frame);
frame = copy;
}
return ff_filter_frame(ctx->outputs[0], frame);
fail:
av_frame_free(&frame);
return ret;
}
#define OFFSET(x) offsetof(ShufflePlanesContext, x)
#define FLAGS (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
static const AVOption shuffleplanes_options[] = {
{ "map0", "Index of the input plane to be used as the first output plane ", OFFSET(map[0]), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 3, FLAGS },
{ "map1", "Index of the input plane to be used as the second output plane ", OFFSET(map[1]), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 3, FLAGS },
{ "map2", "Index of the input plane to be used as the third output plane ", OFFSET(map[2]), AV_OPT_TYPE_INT, { .i64 = 2 }, 0, 3, FLAGS },
{ "map3", "Index of the input plane to be used as the fourth output plane ", OFFSET(map[3]), AV_OPT_TYPE_INT, { .i64 = 3 }, 0, 3, FLAGS },
{ NULL },
};
AVFILTER_DEFINE_CLASS(shuffleplanes);
static const AVFilterPad shuffleplanes_inputs[] = {
{
.name = "default",
.type = AVMEDIA_TYPE_VIDEO,
.config_props = shuffleplanes_config_input,
.filter_frame = shuffleplanes_filter_frame,
},
};
static const AVFilterPad shuffleplanes_outputs[] = {
{
.name = "default",
.type = AVMEDIA_TYPE_VIDEO,
},
};
const AVFilter ff_vf_shuffleplanes = {
.name = "shuffleplanes",
.description = NULL_IF_CONFIG_SMALL("Shuffle video planes."),
.priv_size = sizeof(ShufflePlanesContext),
.priv_class = &shuffleplanes_class,
FILTER_INPUTS(shuffleplanes_inputs),
FILTER_OUTPUTS(shuffleplanes_outputs),
FILTER_QUERY_FUNC(query_formats),
.flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC,
};
|
989e9943913ce204a43ea93b4d71ba99fc767c09
|
c26d7b0ed875357278e61627da2da0650da77986
|
/src/cmd/mv.c
|
2ec647371bb9bb50f4754ca3a5fd05286bb9b4a1
|
[
"BSD-3-Clause"
] |
permissive
|
RetroBSD/retrobsd
|
5343d9e3c424637fc3ad5b03fe720b2744490025
|
486f81f6abff01c7dcc207235cd2979b226a95ff
|
refs/heads/master
| 2023-09-02T23:12:05.110883
| 2023-07-07T18:41:40
| 2023-07-07T18:41:40
| 18,598,087
| 282
| 59
|
BSD-3-Clause
| 2023-07-18T07:35:36
| 2014-04-09T13:25:46
|
C
|
UTF-8
|
C
| false
| false
| 6,737
|
c
|
mv.c
|
/*
* Copyright (c) 1980 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
*/
/*
* mv file1 file2
*/
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <sys/dir.h>
#include <errno.h>
#include <signal.h>
#define DELIM '/'
#define MODEBITS 07777
#define ISDIR(st) (((st).st_mode&S_IFMT) == S_IFDIR)
#define ISLNK(st) (((st).st_mode&S_IFMT) == S_IFLNK)
#define ISREG(st) (((st).st_mode&S_IFMT) == S_IFREG)
#define ISDEV(st) \
(((st).st_mode&S_IFMT) == S_IFCHR || ((st).st_mode&S_IFMT) == S_IFBLK)
char *dname();
struct stat s1, s2;
int iflag = 0; /* interactive mode */
int fflag = 0; /* force overwriting */
main(argc, argv)
register char *argv[];
{
register i, r;
register char *arg;
char *dest;
if (argc < 2)
goto usage;
while (argc > 1 && *argv[1] == '-') {
argc--;
arg = *++argv;
/*
* all files following a null option
* are considered file names
*/
if (*(arg+1) == '\0')
break;
while (*++arg != '\0') switch (*arg) {
case 'i':
iflag++;
break;
case 'f':
fflag++;
break;
default:
goto usage;
}
}
if (argc < 3)
goto usage;
dest = argv[argc-1];
if (stat(dest, &s2) >= 0 && ISDIR(s2)) {
r = 0;
for (i = 1; i < argc-1; i++)
r |= movewithshortname(argv[i], dest);
exit(r);
}
if (argc > 3)
goto usage;
r = move(argv[1], argv[2]);
exit(r);
/*NOTREACHED*/
usage:
fprintf(stderr,
"usage: mv [-if] f1 f2 or mv [-if] f1 ... fn d1 (`fn' is a file or directory)\n");
return (1);
}
movewithshortname(src, dest)
char *src, *dest;
{
register char *shortname;
char target[MAXPATHLEN + 1];
shortname = dname(src);
if (strlen(dest) + strlen(shortname) > MAXPATHLEN - 1) {
error("%s/%s: pathname too long", dest,
shortname);
return (1);
}
sprintf(target, "%s/%s", dest, shortname);
return (move(src, target));
}
int
query (char *prompt, ...)
{
va_list args;
register int i, c;
va_start (args, prompt);
vfprintf(stderr, prompt, args);
va_end (args);
i = c = getchar();
while (c != '\n' && c != EOF)
c = getchar();
return (i == 'y');
}
move(source, target)
char *source, *target;
{
int targetexists;
if (lstat(source, &s1) < 0) {
Perror2(source, "Cannot access");
return (1);
}
/*
* First, try to rename source to destination.
* The only reason we continue on failure is if
* the move is on a nondirectory and not across
* file systems.
*/
targetexists = lstat(target, &s2) >= 0;
if (targetexists) {
if (s1.st_dev == s2.st_dev && s1.st_ino == s2.st_ino) {
error("%s and %s are identical", source, target);
return (1);
}
if (iflag && !fflag && isatty(fileno(stdin)) &&
query("remove %s? ", target) == 0)
return (1);
if (access(target, 2) < 0 && !fflag && isatty(fileno(stdin))) {
if (query("override protection %o for %s? ",
s2.st_mode & MODEBITS, target) == 0)
return (1);
}
}
if (rename(source, target) >= 0)
return (0);
if (errno != EXDEV) {
Perror2(errno == ENOENT && targetexists == 0 ? target : source,
"rename");
return (1);
}
if (ISDIR(s1)) {
error("can't mv directories across file systems");
return (1);
}
if (targetexists && unlink(target) < 0) {
Perror2(target, "Cannot unlink");
return (1);
}
/*
* File can't be renamed, try to recreate the symbolic
* link or special device, or copy the file wholesale
* between file systems.
*/
if (ISLNK(s1)) {
register m;
char symln[MAXPATHLEN + 1];
m = readlink(source, symln, sizeof (symln) - 1);
if (m < 0) {
Perror(source);
return (1);
}
symln[m] = '\0';
m = umask(~(s1.st_mode & MODEBITS));
if (symlink(symln, target) < 0) {
Perror(target);
return (1);
}
(void) umask(m);
goto cleanup;
}
if (ISDEV(s1)) {
struct timeval tv[2];
if (mknod(target, s1.st_mode, s1.st_rdev) < 0) {
Perror(target);
return (1);
}
tv[0].tv_sec = s1.st_atime;
tv[0].tv_usec = 0;
tv[1].tv_sec = s1.st_mtime;
tv[1].tv_usec = 0;
(void) utimes(target, tv);
goto cleanup;
}
if (ISREG(s1)) {
register int fi, fo, n;
struct timeval tv[2];
char buf[MAXBSIZE];
fi = open(source, 0);
if (fi < 0) {
Perror(source);
return (1);
}
fo = creat(target, s1.st_mode & MODEBITS);
if (fo < 0) {
Perror(target);
close(fi);
return (1);
}
for (;;) {
n = read(fi, buf, sizeof buf);
if (n == 0) {
break;
} else if (n < 0) {
Perror2(source, "read");
close(fi);
close(fo);
return (1);
} else if (write(fo, buf, n) != n) {
Perror2(target, "write");
close(fi);
close(fo);
return (1);
}
}
close(fi);
close(fo);
tv[0].tv_sec = s1.st_atime;
tv[0].tv_usec = 0;
tv[1].tv_sec = s1.st_mtime;
tv[1].tv_usec = 0;
(void) utimes(target, tv);
goto cleanup;
}
error("%s: unknown file type %o", source, s1.st_mode);
return (1);
cleanup:
if (unlink(source) < 0) {
Perror2(source, "Cannot unlink");
return (1);
}
return (0);
}
char *
dname(name)
register char *name;
{
register char *p;
p = name;
while (*p)
if (*p++ == DELIM && *p)
name = p;
return name;
}
/*VARARGS*/
error(fmt, a1, a2)
char *fmt;
{
fprintf(stderr, "mv: ");
fprintf(stderr, fmt, a1, a2);
fprintf(stderr, "\n");
}
Perror(s)
char *s;
{
char buf[MAXPATHLEN + 10];
sprintf(buf, "mv: %s", s);
perror(buf);
}
Perror2(s1, s2)
char *s1, *s2;
{
char buf[MAXPATHLEN + 20];
sprintf(buf, "mv: %s: %s", s1, s2);
perror(buf);
}
|
4e0a0d1f9ce8115f049de95ec91528a525b3fd96
|
035660e8cc10571ebbd0d4393fef063bb7eb98f6
|
/src/audio/session_config.c
|
e0881913b8615d6285c1479434689a49d45b0788
|
[] |
no_license
|
zeldaret/mm
|
f163a5e7c4314105777369fa7671ce9c2a99922a
|
4ae00e909e74044f05155683b49d2561f91de7ba
|
refs/heads/master
| 2023-08-06T07:22:04.912966
| 2023-08-04T20:36:03
| 2023-08-04T20:36:03
| 247,875,852
| 915
| 328
| null | 2023-09-14T11:48:59
| 2020-03-17T04:03:07
|
C
|
UTF-8
|
C
| false
| false
| 7,152
|
c
|
session_config.c
|
#include "global.h"
#include "buffers.h"
const s16 gAudioTatumInit[] = {
0x1C00, // unused
TATUMS_PER_BEAT, // gTatumsPerBeat
};
// TODO: Extract from table?
#define NUM_SOUNDFONTS 41
#define SFX_SEQ_SIZE 0xC6A0
#define AMBIENCE_SEQ_SIZE 0xFC0
#define SOUNDFONT_0_SIZE 0x81C0
#define SOUNDFONT_1_SIZE 0x36D0
#define SOUNDFONT_2_SIZE 0xCE0
// Sizes of everything on the init pool
#define AI_BUFFERS_SIZE (AIBUF_SIZE * ARRAY_COUNT(gAudioCtx.aiBuffers))
#define SOUNDFONT_LIST_SIZE (NUM_SOUNDFONTS * sizeof(SoundFont))
// 0x19BD0
#define PERMANENT_POOL_SIZE \
(SFX_SEQ_SIZE + AMBIENCE_SEQ_SIZE + SOUNDFONT_0_SIZE + SOUNDFONT_1_SIZE + SOUNDFONT_2_SIZE + 0x430)
const AudioHeapInitSizes gAudioHeapInitSizes = {
ALIGN16(sizeof(gAudioHeap) - 0x100), // audio heap size
ALIGN16(PERMANENT_POOL_SIZE + AI_BUFFERS_SIZE + SOUNDFONT_LIST_SIZE + 0x40), // init pool size
ALIGN16(PERMANENT_POOL_SIZE), // permanent pool size
};
#define REVERB_INDEX_0_SETTINGS \
{ 1, 0x30, 0x3000, 0, 0, 0x7FFF, 0x0000, 0x0000, REVERB_INDEX_NONE, 0x3000, 0, 0 }
ReverbSettings reverbSettings0[3] = {
REVERB_INDEX_0_SETTINGS,
{ 1, 0x20, 0x0800, 0, 0, 0x7FFF, 0x0000, 0x0000, REVERB_INDEX_NONE, 0x0000, 0, 0 },
};
ReverbSettings reverbSettings1[3] = {
REVERB_INDEX_0_SETTINGS,
{ 1, 0x30, 0x1800, 0, 0, 0x7FFF, 0x0000, 0x0000, REVERB_INDEX_NONE, 0x0000, 11, 11 },
};
ReverbSettings reverbSettings2[3] = {
REVERB_INDEX_0_SETTINGS,
{ 1, 0x38, 0x2800, 0, 0, 0x7FFF, 0x0000, 0x0000, REVERB_INDEX_NONE, 0x0000, 7, 7 },
};
ReverbSettings reverbSettings3[3] = {
REVERB_INDEX_0_SETTINGS,
{ 1, 0x30, 0x6800, 0, 0, 0x7FFF, 0x1400, 0x1400, REVERB_INDEX_NONE, 0x3000, 6, 6 },
{ 2, 0x50, 0x6000, 0, 0, 0x7FFF, 0xD000, 0x3000, REVERB_INDEX_NONE, 0x3000, 0, 0 },
};
ReverbSettings reverbSettings4[3] = {
REVERB_INDEX_0_SETTINGS,
{ 1, 0x40, 0x5000, 0, 0, 0x7FFF, 0x1800, 0x1800, REVERB_INDEX_NONE, 0x3000, 7, 7 },
};
ReverbSettings reverbSettings5[3] = {
REVERB_INDEX_0_SETTINGS,
{ 1, 0x40, 0x5C00, 0, 0, 0x7FFF, 0x2000, 0x2000, REVERB_INDEX_NONE, 0x3000, 4, 4 },
};
ReverbSettings reverbSettings6[3] = {
REVERB_INDEX_0_SETTINGS,
{ 1, 0x30, 0x6000, 0, 0, 0x7FFF, 0x1000, 0x1000, REVERB_INDEX_NONE, 0x3000, 10, 10 },
};
ReverbSettings reverbSettings7[3] = {
REVERB_INDEX_0_SETTINGS,
{ 1, 0x30, 0x6800, 0, 0, 0x7FFF, 0x1400, 0x1400, REVERB_INDEX_NONE, 0x3000, 6, 6 },
};
ReverbSettings reverbSettings8[2] = {
REVERB_INDEX_0_SETTINGS,
{ 1, 0x50, 0x5000, 0, 0, 0x7FFF, 0xD000, 0x3000, REVERB_INDEX_NONE, 0x3000, 0, 0 },
};
ReverbSettings reverbSettings9[3] = {
REVERB_INDEX_0_SETTINGS,
{ 1, 0x20, 0x0000, 0, 0, 0x7FFF, 0x0000, 0x0000, REVERB_INDEX_NONE, 0x0000, 0, 0 },
};
ReverbSettings reverbSettingsA[3] = {
REVERB_INDEX_0_SETTINGS,
{ 1, 0x30, 0x1800, 0, 0, 0x7FFF, 0x0000, 0x0000, REVERB_INDEX_NONE, 0x0000, 11, 11 },
};
ReverbSettings reverbSettingsB[3] = {
REVERB_INDEX_0_SETTINGS,
};
ReverbSettings reverbSettingsC[3] = {
REVERB_INDEX_0_SETTINGS,
{ 1, 0x40, 0x5000, 0, 0, 0x7FFF, 0x0000, 0x0000, REVERB_INDEX_NONE, 0x3000, 0, 0 },
};
ReverbSettings reverbSettingsD[3] = {
REVERB_INDEX_0_SETTINGS,
{ 1, 0x30, 0x6800, 0, 0, 0x7FFF, 0x1400, 0x1400, REVERB_INDEX_NONE, 0x3000, 6, 6 },
{ 2, 0x50, 0x6000, 0, 0, 0x7FFF, 0xD000, 0x3000, REVERB_INDEX_NONE, 0x3000, 0, 0 },
};
ReverbSettings reverbSettingsE[3] = {
REVERB_INDEX_0_SETTINGS,
{ 1, 0x30, 0x1800, 0, 0, 0x7FFF, 0x0000, 0x0000, REVERB_INDEX_NONE, 0x0000, 11, 11 },
{ 1, 0x40, 0x5000, 0, 0, 0x7FFF, 0x1800, 0x1800, REVERB_INDEX_NONE, 0x3000, 7, 7 },
};
ReverbSettings reverbSettingsF[2] = {
REVERB_INDEX_0_SETTINGS,
{ 1, 0x50, 0x1800, 0, 0, 0x7FFF, 0x0000, 0x0000, REVERB_INDEX_NONE, 0x0000, 11, 11 },
};
ReverbSettings* gReverbSettingsTable[] = {
reverbSettings0, reverbSettings1, reverbSettings2, reverbSettings4, reverbSettings5,
reverbSettings6, reverbSettings7, reverbSettings8, reverbSettings9, reverbSettings3,
};
AudioSpec gAudioSpecs[21] = {
/* 0x0 */
{ 32000, 1, 24, 5, 0, 0, 2, reverbSettingsF, 0x500, 0x200, 0x7FFF, 0xAF0, 0x2D80, 0, 0x4100, 0x2D00, 0, 0,
0xDC800 },
/* 0x1 */
{ 32000, 1, 24, 5, 0, 0, 2, reverbSettingsF, 0x500, 0x200, 0x7FFF, 0xAF0, 0x2D80, 0, 0x4100, 0x2D00, 0, 0,
0xDC800 },
/* 0x2 */
{ 32000, 1, 24, 5, 0, 0, 2, reverbSettingsF, 0x500, 0x200, 0x7FFF, 0xAF0, 0x2D80, 0, 0x4100, 0x2D00, 0, 0,
0xDC800 },
/* 0x3 */
{ 32000, 1, 24, 5, 0, 0, 2, reverbSettingsF, 0x500, 0x200, 0x7FFF, 0xAF0, 0x2D80, 0, 0x4100, 0x2D00, 0, 0,
0xDC800 },
/* 0x4 */
{ 32000, 1, 24, 5, 0, 0, 2, reverbSettingsF, 0x500, 0x200, 0x7FFF, 0xAF0, 0x2D80, 0, 0x4100, 0x2D00, 0, 0,
0xDC800 },
/* 0x5 */
{ 32000, 1, 24, 5, 0, 0, 2, reverbSettingsF, 0x500, 0x200, 0x7FFF, 0xAF0, 0x2D80, 0, 0x4100, 0x2D00, 0, 0,
0xDC800 },
/* 0x6 */
{ 32000, 1, 24, 5, 0, 0, 2, reverbSettingsF, 0x500, 0x200, 0x7FFF, 0xAF0, 0x2D80, 0, 0x4100, 0x2D00, 0, 0,
0xDC800 },
/* 0x7 */
{ 32000, 1, 24, 5, 0, 0, 2, reverbSettingsF, 0x500, 0x200, 0x7FFF, 0xAF0, 0x2D80, 0, 0x4100, 0x2D00, 0, 0,
0xDC800 },
/* 0x8 */
{ 32000, 1, 24, 5, 0, 0, 2, reverbSettingsF, 0x500, 0x200, 0x7FFF, 0xAF0, 0x2D80, 0, 0x4100, 0x2D00, 0, 0,
0xDC800 },
/* 0x9 */
{ 32000, 1, 24, 5, 0, 0, 2, reverbSettingsF, 0x500, 0x200, 0x7FFF, 0xAF0, 0x2D80, 0, 0x4100, 0x2D00, 0, 0,
0xDC800 },
/* 0xA */
{ 32000, 1, 28, 3, 0, 0, 2, reverbSettingsA, 0x500, 0x200, 0x7FFF, 0xAF0, 0x2D80, 0, 0x2800, 0x2D00, 0, 0,
0xDC800 },
/* 0xB */
{ 32000, 1, 28, 3, 0, 0, 2, reverbSettingsA, 0x500, 0x200, 0x7FFF, 0xAF0, 0x2D80, 0, 0x4100, 0x2D00, 0, 0,
0xDC800 },
/* 0xC */
{ 32000, 1, 28, 5, 0, 0, 2, reverbSettingsA, 0x500, 0x200, 0x7FFF, 0xAF0, 0x2D80, 0, 0x4100, 0x2D00, 0, 0,
0xCC800 },
/* 0xD */
{ 32000, 1, 24, 5, 0, 0, 3, reverbSettingsD, 0x500, 0x200, 0x7FFF, 0xAF0, 0x2D80, 0, 0x4100, 0x2D00, 0, 0,
0xDC800 },
/* 0xE */
{ 32000, 1, 24, 5, 0, 0, 3, reverbSettingsE, 0x500, 0x200, 0x7FFF, 0xAF0, 0x2D80, 0, 0x4100, 0x2D00, 0, 0,
0xDC800 },
/* 0xF */
{ 32000, 1, 24, 5, 0, 0, 2, reverbSettingsF, 0x500, 0x200, 0x7FFF, 0xAF0, 0x2D80, 0, 0x4000, 0x2D00, 0, 0,
0xDC800 },
/* 0x10 */
{ 32000, 1, 22, 5, 0, 0, 2, reverbSettings0, 0x500, 0x200, 0x7FFF, 0xAF0, 0x2D80, 0, 0x4100, 0x2D00, 0, 0,
0xDC800 },
/* 0x11 */
{ 32000, 1, 22, 5, 0, 0, 2, reverbSettings8, 0x500, 0x200, 0x7FFF, 0xAF0, 0x2D80, 0, 0x4100, 0x2D00, 0, 0,
0xDC800 },
/* 0x12 */
{ 32000, 1, 16, 5, 0, 0, 2, reverbSettings0, 0x500, 0x200, 0x7FFF, 0xAF0, 0x2D80, 0, 0x4100, 0x2D00, 0, 0,
0xDC800 },
/* 0x13 */
{ 22050, 1, 24, 5, 0, 0, 2, reverbSettings0, 0x500, 0x200, 0x7FFF, 0xAF0, 0x2D80, 0, 0x4100, 0x2D00, 0, 0,
0xDC800 },
/* 0x14 */
{ 32000, 1, 24, 5, 0, 0, 2, reverbSettings2, 0x500, 0x200, 0x7FFF, 0xAF0, 0x2D80, 0, 0x3600, 0x2600, 0, 0,
0xDC800 },
};
|
5d796abad9f229dccdd9204a50cf3c8c9eed21be
|
7fc950026f2302bcf04fd1309e85aa9b766581f1
|
/SDK/src_int16/cnn.h
|
09019b9ee5828f4b9071e9a6369c66612ff9e0b6
|
[
"MIT"
] |
permissive
|
dhm2013724/yolov2_xilinx_fpga
|
83e39bc9d9bf8c9cee100bb1356fcbc514b18fb1
|
ee5ce94c46b19f242d8d10b7844b2d5f7afaf766
|
refs/heads/flex
| 2023-04-07T06:26:57.874886
| 2023-03-23T08:51:28
| 2023-03-23T08:51:28
| 150,732,901
| 643
| 223
|
MIT
| 2022-09-26T19:26:23
| 2018-09-28T11:48:26
|
C
|
UTF-8
|
C
| false
| false
| 4,940
|
h
|
cnn.h
|
#ifndef __MNV1_H
#define __MNV1_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <linux/fb.h>
#include <time.h>
#include <sys/time.h>
#include <stdint.h>
#include <math.h>
#define XFPGA_ACC_CTRL_BUS_ADDR_AP_CTRL 0x00
#define XFPGA_ACC_CTRL_BUS_ADDR_GIE 0x04
#define XFPGA_ACC_CTRL_BUS_ADDR_IER 0x08
#define XFPGA_ACC_CTRL_BUS_ADDR_ISR 0x0c
#define XFPGA_ACC_CTRL_BUS_ADDR_IFM_DATA 0x10
#define XFPGA_ACC_CTRL_BUS_BITS_IFM_DATA 32
#define XFPGA_ACC_CTRL_BUS_ADDR_OFM_DATA 0x18
#define XFPGA_ACC_CTRL_BUS_BITS_OFM_DATA 32
#define XFPGA_ACC_CTRL_BUS_ADDR_WEIGHT_DATA 0x20
#define XFPGA_ACC_CTRL_BUS_BITS_WEIGHT_DATA 32
#define XFPGA_ACC_CTRL_BUS_ADDR_BIAS_DATA 0x28
#define XFPGA_ACC_CTRL_BUS_BITS_BIAS_DATA 32
#define XFPGA_ACC_CTRL_BUS_ADDR_K_S_PAD_LTYPE_DATA 0x30
#define XFPGA_ACC_CTRL_BUS_BITS_K_S_PAD_LTYPE_DATA 32
#define XFPGA_ACC_CTRL_BUS_ADDR_IOFM_NUM_DATA 0x38
#define XFPGA_ACC_CTRL_BUS_BITS_IOFM_NUM_DATA 32
#define XFPGA_ACC_CTRL_BUS_ADDR_IFM_W_H_DATA 0x40
#define XFPGA_ACC_CTRL_BUS_BITS_IFM_W_H_DATA 32
#define XFPGA_ACC_CTRL_BUS_ADDR_OFM_W_H_DATA 0x48
#define XFPGA_ACC_CTRL_BUS_BITS_OFM_W_H_DATA 32
#define XFPGA_ACC_CTRL_BUS_ADDR_TRTC_DATA 0x50
#define XFPGA_ACC_CTRL_BUS_BITS_TRTC_DATA 32
#define XFPGA_ACC_CTRL_BUS_ADDR_TMTN_DATA 0x58
#define XFPGA_ACC_CTRL_BUS_BITS_TMTN_DATA 32
#define XFPGA_ACC_CTRL_BUS_ADDR_OFM_NUM_BOUND_DATA 0x60
#define XFPGA_ACC_CTRL_BUS_BITS_OFM_NUM_BOUND_DATA 32
#define XFPGA_ACC_CTRL_BUS_ADDR_MLOOPSXTM_DATA 0x68
#define XFPGA_ACC_CTRL_BUS_BITS_MLOOPSXTM_DATA 32
#define XFPGA_ACC_CTRL_BUS_ADDR_MLOOPS_A1XTM_DATA 0x70
#define XFPGA_ACC_CTRL_BUS_BITS_MLOOPS_A1XTM_DATA 32
#define XFPGA_ACC_CTRL_BUS_ADDR_PAD_VAL_DATA 0x78
#define XFPGA_ACC_CTRL_BUS_BITS_PAD_VAL_DATA 16
#define XFPGA_ACC_CTRL_BUS_ADDR_TROWTCOL_DATA 0x80
#define XFPGA_ACC_CTRL_BUS_BITS_TROWTCOL_DATA 32
#define XFPGA_ACC_CTRL_BUS_ADDR_IHW_DATA 0x88
#define XFPGA_ACC_CTRL_BUS_BITS_IHW_DATA 32
#define XFPGA_ACC_CTRL_BUS_ADDR_OHW_DATA 0x90
#define XFPGA_ACC_CTRL_BUS_BITS_OHW_DATA 32
#define XFPGA_ACC_CTRL_BUS_ADDR_KK_INUMXKK_DATA 0x98
#define XFPGA_ACC_CTRL_BUS_BITS_KK_INUMXKK_DATA 32
#define XFPGA_ACC_CTRL_BUS_ADDR_EN_BITS_DATA 0xa0
#define XFPGA_ACC_CTRL_BUS_BITS_EN_BITS_DATA 32
#define XFPGA_ACC_CTRL_BUS_ADDR_WEIGHTQ_DATA 0xa8
#define XFPGA_ACC_CTRL_BUS_BITS_WEIGHTQ_DATA 32
#define XFPGA_ACC_CTRL_BUS_ADDR_BETAQ_DATA 0xb0
#define XFPGA_ACC_CTRL_BUS_BITS_BETAQ_DATA 32
#define XFPGA_ACC_CTRL_BUS_ADDR_INPUTQ_DATA 0xb8
#define XFPGA_ACC_CTRL_BUS_BITS_INPUTQ_DATA 32
#define XFPGA_ACC_CTRL_BUS_ADDR_OUTPUTQ_DATA 0xc0
#define XFPGA_ACC_CTRL_BUS_BITS_OUTPUTQ_DATA 32
//#define ACC_BASEADDR 0x43c00000
//#define WEIGHT_BASEADDR 0x10000000//0x06129EC0 = 101883584 Bytes
//#define BETA_BASEADDR 0x16140000//0x00005414 = 21524 Bytes
//#define MEM_BASEADDR 0x16180000//
#define ACC_BASEADDR 0xA0000000
#define WEIGHT_BASEADDR 0x60000000//0x06129EC0 = 101883584 Bytes
#define BETA_BASEADDR 0x66140000//0x00005414 = 21524 Bytes
#define MEM_BASEADDR 0x66180000//
#define HW_S 2
#define K 3
#define Tn 2
#define Tm 60
#define Tr 26
#define Tc 26
#define MAX_BETA_LENGTH 1024
#define INTERWIDTH 19
#define WriteReg(BaseAddress, RegOffset, Data) *(volatile uint32_t*)((BaseAddress) + (RegOffset)) = (Data)
#define ReadReg(BaseAddress, RegOffset) *(volatile uint32_t*)((BaseAddress) + (RegOffset))
#define MIN_diy(x,y) ((x) < (y) ? (x) : (y))
#define MAX_diy(x,y) ((x) > (y) ? (x) : (y))
#define FALSE 0
#define TRUE 1
#define VALID 0
#define SAME 1
#define LT_CONV 0
#define LT_MAXPOOL 1
#define MIN_NEG (0x8001)
#define OnChipIB_Width ((Tc-1)*HW_S+K)
#define OnChipIB_Height ((Tr-1)*HW_S+K)
#define HPAGESIZE (2*1024*1024)
void copy_mem2dev(uint8_t *orig,uint32_t byte_num, unsigned long in_buffer);
void copy_dev2mem(uint8_t *dst,uint32_t byte_num, unsigned long in_buffer);
int copy_file2mem(char *bin_file,uint32_t byte_num,unsigned long in_buffer);
int copy_mem2file(char *bin_file,uint32_t byte_num,unsigned long in_buffer);
int FPGA_Acc(uint64_t In_Address, uint64_t Out_Address, uint64_t Weight_offset, uint64_t Beta_offset, uint32_t k_s_pad_ltype, uint32_t iofm_num, uint32_t ifm_w_h, uint32_t ofm_w_h,
uint32_t TRTC, uint32_t TMTN, int32_t OFM_num_bound, int32_t mLoopsxTM, int32_t mLoops_a1xTM, int16_t pad_val, uint32_t TRowTCol,
uint32_t IHW, uint32_t OHW, uint32_t KK_INumxKK, uint32_t en_bits, int32_t WeightQ, int32_t BetaQ, int32_t InputQ, int32_t OutputQ);//enable_bits[2:0]={IsReLU, LoadBias, IsNotConv}
#endif
|
e62e05795f69a3ffec9fed1247e35b24412d63da
|
21c92afbd7fd022a206fb31294c523aebb770104
|
/SuiteSparse/MATLAB_Tools/spok/spok.c
|
cc8cba2cd49e9d833a32479245b7e4fb8a29dc61
|
[
"BSD-3-Clause",
"LicenseRef-scancode-free-unknown",
"LicenseRef-scancode-unknown-license-reference",
"GPL-2.0-or-later",
"GPL-3.0-only",
"LGPL-2.1-or-later",
"LGPL-2.0-or-later",
"GPL-1.0-or-later",
"LicenseRef-scancode-other-copyleft",
"LicenseRef-scancode-warranty-disclaimer",
"Apache-2.0",
"LicenseRef-scancode-generic-cla"
] |
permissive
|
jlblancoc/suitesparse-metis-for-windows
|
70e6bcab2b525afb41758d61f823efa0618f67cf
|
5ee2eb4bc7bfd6d27af2f7fb027b1545cfc0fa3f
|
refs/heads/master
| 2023-08-30T21:15:39.624300
| 2023-03-09T10:16:48
| 2023-03-09T10:16:48
| 16,236,582
| 423
| 251
|
BSD-3-Clause
| 2023-03-09T10:18:08
| 2014-01-25T18:06:21
|
C
|
UTF-8
|
C
| false
| false
| 3,719
|
c
|
spok.c
|
#include "spok.h"
/* check the validity of a MATLAB sparse matrix */
SPOK_INT spok
(
/* inputs, not modified */
SPOK_INT m, /* number of rows */
SPOK_INT n, /* number of columns */
SPOK_INT nzmax, /* max # of entries */
SPOK_INT *Ap, /* size n+1, column pointers */
SPOK_INT *Ai, /* size nz = Ap [n], row indices */
double *Ax, /* double matrices always have Ax */
double *Az, /* imaginary matrices always have Az */
char *As, /* logical matrices always have As */
/* outputs, not defined on input */
SPOK_INT *p_njumbled, /* # of jumbled row indices (-1 if not computed) */
SPOK_INT *p_nzeros /* number of explicit zeros (-1 if not computed) */
)
{
double x, z ;
SPOK_INT i, j, p, pend, njumbled, nzeros, ilast ;
char s ;
/* ---------------------------------------------------------------------- */
/* in case of early return */
/* ---------------------------------------------------------------------- */
if (p_njumbled != NULL)
{
*p_njumbled = -1 ;
}
if (p_nzeros != NULL)
{
*p_nzeros = -1 ;
}
/* ---------------------------------------------------------------------- */
/* check the dimensions */
/* ---------------------------------------------------------------------- */
if (m < 0)
{
return (SPOK_FATAL_M) ;
}
if (n < 0)
{
return (SPOK_FATAL_N) ;
}
if (nzmax < 1)
{
/* note that nzmax cannot be zero */
return (SPOK_FATAL_NZMAX) ;
}
/* ---------------------------------------------------------------------- */
/* check the column pointers */
/* ---------------------------------------------------------------------- */
if (Ap == NULL || Ap [0] != 0)
{
/* column pointers invalid */
return (SPOK_FATAL_P) ;
}
for (j = 0 ; j < n ; j++)
{
p = Ap [j] ;
pend = Ap [j+1] ;
if (pend < p || pend > nzmax)
{
/* column pointers not monotonically non-decreasing */
return (SPOK_FATAL_P) ;
}
}
/* ---------------------------------------------------------------------- */
/* check the row indices and numerical values */
/* ---------------------------------------------------------------------- */
if (Ai == NULL)
{
/* row indices not present */
return (SPOK_FATAL_I) ;
}
njumbled = 0 ;
nzeros = 0 ;
for (j = 0 ; j < n ; j++)
{
ilast = -1 ;
for (p = Ap [j] ; p < Ap [j+1] ; p++)
{
i = Ai [p] ;
if (i < 0 || i >= m)
{
/* row indices out of range */
return (SPOK_FATAL_I) ;
}
if (i <= ilast)
{
/* row indices unsorted, or duplicates present */
njumbled++ ;
}
s = (As == NULL) ? 0 : As [p] ;
x = (Ax == NULL) ? 0 : Ax [p] ;
z = (Az == NULL) ? 0 : Az [p] ;
if (s == 0 && x == 0 && z == 0)
{
/* an explicit zero is present */
nzeros++ ;
}
ilast = i ;
}
}
/* ---------------------------------------------------------------------- */
/* return results */
/* ---------------------------------------------------------------------- */
if (p_njumbled != NULL)
{
*p_njumbled = njumbled ;
}
if (p_nzeros != NULL)
{
*p_nzeros = nzeros ;
}
return ((njumbled > 0 || nzeros > 0) ? SPOK_WARNING : SPOK_OK) ;
}
|
2534daaa9f88ba118c6043a7458d1a51a4801971
|
62bf09400de89c1aa77d8c2570d7f66cec0b5d36
|
/fnet_stack/service/autoip/fnet_autoip_config.h
|
e6c6265d264d7d5ac8a565394a950136ef5464b1
|
[
"Apache-2.0"
] |
permissive
|
butok/FNET
|
41b1d2ec4cc683c1b5c188a17ab6a4bb890a6af6
|
ea43715752e6f6823bfcc8bdc94e440443112e7c
|
refs/heads/master
| 2023-08-03T16:32:09.317085
| 2023-07-20T07:01:55
| 2023-07-20T07:01:55
| 50,664,554
| 115
| 40
|
Apache-2.0
| 2023-07-20T07:01:56
| 2016-01-29T13:39:30
|
C
|
UTF-8
|
C
| false
| false
| 3,713
|
h
|
fnet_autoip_config.h
|
/**************************************************************************
*
* Copyright 2016-2018 by Andrey Butok. FNET Community.
*
***************************************************************************
*
* 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 _FNET_AUTOIP_CONFIG_H_
#define _FNET_AUTOIP_CONFIG_H_
/*! @addtogroup fnet_autoip_config */
/*! @{ */
/**************************************************************************/ /*!
* @def FNET_CFG_AUTOIP
* @brief Auto-IP service support (RFC3927 "Dynamic Configuration of IPv4 Link-Local Addresses"):
* - @c 1..n = is enabled. Its value defines maximum number of the Auto-IP services that can be run simultaneously.
* @note It is not posible to run several Auto-IP servers on the same networking interface.
* - @b @c 0 = is disabled (Default value).
******************************************************************************/
#ifndef FNET_CFG_AUTOIP
#define FNET_CFG_AUTOIP (0)
#endif
/**************************************************************************/ /*!
* @def FNET_CFG_AUTOIP_DEFEND_INTERVAL
* @brief Auto-IP DEFEND_INTERVAL (RFC3927) support:
* - @c @c 1 = is enabled (Default value).@n
* Upon receiving a conflicting ARP packet, if a host has not seen any
* other conflicting ARP packets within the last DEFEND_INTERVAL (10)
* seconds, it attempts to defend its address by
* recording the time that the conflicting ARP packet was received, and
* then broadcasting one single ARP announcement, giving its own IP and
* hardware addresses as the sender addresses of the ARP. Having done
* this, the host can then continue to use the address normally without
* any further special action. However, if this is not the first
* conflicting ARP packet the host has seen, and the time recorded for
* the previous conflicting ARP packet is recent, within DEFEND_INTERVAL
* seconds, then the host MUST immediately cease using this address and
* configure a new IPv4 Link-Local address as described above. This is
* necessary to ensure that two hosts do not get stuck in an endless
* loop with both hosts trying to defend the same address.
* - @b @c 0 = is disabled.@n
* Upon receiving a conflicting ARP packet, a host
* immediately configure a new IPv4 Link-Local address.
******************************************************************************/
#ifndef FNET_CFG_AUTOIP_DEFEND_INTERVAL
#define FNET_CFG_AUTOIP_DEFEND_INTERVAL (1)
#endif
/*! @} */
#ifdef FNET_CFG_AUTOIP_MAX
#error "FNET_CFG_AUTOIP_MAX parameter is obsolete. Use FNET_CFG_AUTOIP."
#endif
#endif /*_FNET_AUTOIP_CONFIG_H_ */
|
6d7b3ab9d90a7c3414434a8679804d5785866bfe
|
cf56b5fcf51fddb219c47f5f006d8595a4483c57
|
/src/components/tl/ucp/alltoall/alltoall_pairwise.c
|
1233609cdd00ce4495063a81a003b8bf3f5c0d1b
|
[
"BSD-3-Clause"
] |
permissive
|
openucx/ucc
|
3b39fbd849a7850c559b60eaec7882292f8a5eca
|
f89cd7557e6ebb19b4c6ebd529647d8b42c30657
|
refs/heads/master
| 2023-08-18T03:18:54.072899
| 2023-08-17T18:05:44
| 2023-08-17T18:05:44
| 282,490,868
| 150
| 57
|
BSD-3-Clause
| 2023-09-12T09:49:18
| 2020-07-25T17:18:51
|
C
|
UTF-8
|
C
| false
| false
| 4,361
|
c
|
alltoall_pairwise.c
|
/**
* Copyright (c) 2021-2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
*
* See file LICENSE for terms.
*/
#include "config.h"
#include "tl_ucp.h"
#include "alltoall.h"
#include "core/ucc_progress_queue.h"
#include "utils/ucc_math.h"
#include "tl_ucp_sendrecv.h"
static inline ucc_rank_t get_recv_peer(ucc_rank_t rank, ucc_rank_t size,
ucc_rank_t step)
{
return (rank + step) % size;
}
static inline ucc_rank_t get_send_peer(ucc_rank_t rank, ucc_rank_t size,
ucc_rank_t step)
{
return (rank - step + size) % size;
}
void ucc_tl_ucp_alltoall_pairwise_progress(ucc_coll_task_t *coll_task)
{
ucc_tl_ucp_task_t *task = ucc_derived_of(coll_task, ucc_tl_ucp_task_t);
ucc_tl_ucp_team_t *team = TASK_TEAM(task);
ptrdiff_t sbuf = (ptrdiff_t)TASK_ARGS(task).src.info.buffer;
ptrdiff_t rbuf = (ptrdiff_t)TASK_ARGS(task).dst.info.buffer;
ucc_memory_type_t smem = TASK_ARGS(task).src.info.mem_type;
ucc_memory_type_t rmem = TASK_ARGS(task).dst.info.mem_type;
ucc_rank_t grank = UCC_TL_TEAM_RANK(team);
ucc_rank_t gsize = UCC_TL_TEAM_SIZE(team);
int polls = 0;
ucc_rank_t peer;
int posts, nreqs;
size_t data_size;
posts = UCC_TL_UCP_TEAM_LIB(team)->cfg.alltoall_pairwise_num_posts;
nreqs = (posts > gsize || posts == 0) ? gsize : posts;
data_size = (size_t)(TASK_ARGS(task).src.info.count / gsize) *
ucc_dt_size(TASK_ARGS(task).src.info.datatype);
while ((task->tagged.send_posted < gsize ||
task->tagged.recv_posted < gsize) &&
(polls++ < task->n_polls)) {
ucp_worker_progress(UCC_TL_UCP_TEAM_CTX(team)->worker.ucp_worker);
while ((task->tagged.recv_posted < gsize) &&
((task->tagged.recv_posted - task->tagged.recv_completed) <
nreqs)) {
peer = get_recv_peer(grank, gsize, task->tagged.recv_posted);
UCPCHECK_GOTO(ucc_tl_ucp_recv_nb((void *)(rbuf + peer * data_size),
data_size, rmem, peer, team, task),
task, out);
polls = 0;
}
while ((task->tagged.send_posted < gsize) &&
((task->tagged.send_posted - task->tagged.send_completed) <
nreqs)) {
peer = get_send_peer(grank, gsize, task->tagged.send_posted);
UCPCHECK_GOTO(ucc_tl_ucp_send_nb((void *)(sbuf + peer * data_size),
data_size, smem, peer, team, task),
task, out);
polls = 0;
}
}
if ((task->tagged.send_posted < gsize) ||
(task->tagged.recv_posted < gsize)) {
return;
}
task->super.status = ucc_tl_ucp_test(task);
out:
if (task->super.status != UCC_INPROGRESS) {
UCC_TL_UCP_PROFILE_REQUEST_EVENT(coll_task,
"ucp_alltoall_pairwise_done", 0);
}
}
ucc_status_t ucc_tl_ucp_alltoall_pairwise_start(ucc_coll_task_t *coll_task)
{
ucc_tl_ucp_task_t *task = ucc_derived_of(coll_task, ucc_tl_ucp_task_t);
ucc_tl_ucp_team_t *team = TASK_TEAM(task);
UCC_TL_UCP_PROFILE_REQUEST_EVENT(coll_task, "ucp_alltoall_pairwise_start", 0);
ucc_tl_ucp_task_reset(task, UCC_INPROGRESS);
return ucc_progress_queue_enqueue(UCC_TL_CORE_CTX(team)->pq, &task->super);
}
ucc_status_t ucc_tl_ucp_alltoall_pairwise_init_common(ucc_tl_ucp_task_t *task)
{
ucc_tl_ucp_team_t *team = TASK_TEAM(task);
ucc_coll_args_t *args = &TASK_ARGS(task);
size_t data_size;
task->super.post = ucc_tl_ucp_alltoall_pairwise_start;
task->super.progress = ucc_tl_ucp_alltoall_pairwise_progress;
task->n_polls = ucc_max(1, task->n_polls);
if (UCC_TL_UCP_TEAM_CTX(team)->cfg.pre_reg_mem) {
data_size =
(size_t)args->src.info.count * ucc_dt_size(args->src.info.datatype);
ucc_tl_ucp_pre_register_mem(team, args->src.info.buffer, data_size,
args->src.info.mem_type);
ucc_tl_ucp_pre_register_mem(team, args->dst.info.buffer, data_size,
args->dst.info.mem_type);
}
return UCC_OK;
}
|
d51424e75960ac83e34c16cb3129c821266539db
|
9de0cec678bc4a3bec2b4adabef9f39ff5b4afac
|
/PWGLF/SPECTRA/PiKaPr/TOF/PbPb276/grid/AliAnalysisEvent.h
|
b07a68795ec6e578027b7d266dc53987480cefb7
|
[] |
permissive
|
alisw/AliPhysics
|
91bf1bd01ab2af656a25ff10b25e618a63667d3e
|
5df28b2b415e78e81273b0d9bf5c1b99feda3348
|
refs/heads/master
| 2023-08-31T20:41:44.927176
| 2023-08-31T14:51:12
| 2023-08-31T14:51:12
| 61,661,378
| 129
| 1,150
|
BSD-3-Clause
| 2023-09-14T18:48:45
| 2016-06-21T19:31:29
|
C++
|
UTF-8
|
C
| false
| false
| 26
|
h
|
AliAnalysisEvent.h
|
../task/AliAnalysisEvent.h
|
1718c2b1a78717e1ecf52a57d884d5e686ae8b30
|
c1ff870879152fba2b54eddfb7591ec322eb3061
|
/core/sceneManager/network/3rdParty/raknet/DependentExtensions/speex-1.1.12/libspeex/cb_search_sse.h
|
8b039686fbfd02a411836908fc5202271c121276
|
[
"BSD-3-Clause",
"BSD-2-Clause",
"LicenseRef-scancode-free-unknown",
"MIT"
] |
permissive
|
MTASZTAKI/ApertusVR
|
1a9809fb7af81c3cd7fb732ed481ebe4ce66fefa
|
424ec5515ae08780542f33cc4841a8f9a96337b3
|
refs/heads/0.9
| 2022-12-11T20:03:42.926813
| 2019-10-11T09:29:45
| 2019-10-11T09:29:45
| 73,708,854
| 188
| 55
|
MIT
| 2022-12-11T08:53:21
| 2016-11-14T13:48:00
|
C++
|
UTF-8
|
C
| false
| false
| 3,120
|
h
|
cb_search_sse.h
|
/* Copyright (C) 2004 Jean-Marc Valin */
/**
@file cb_search_sse.h
@brief Fixed codebook functions (SSE version)
*/
/*
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 Xiph.org 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 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 FOUNDATION 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 <xmmintrin.h>
static inline void _spx_mm_getr_ps (__m128 U, float *__Z, float *__Y, float *__X, float *__W)
{
union {
float __a[4];
__m128 __v;
} __u;
__u.__v = U;
*__Z = __u.__a[0];
*__Y = __u.__a[1];
*__X = __u.__a[2];
*__W = __u.__a[3];
}
#define OVERRIDE_COMPUTE_WEIGHTED_CODEBOOK
static void compute_weighted_codebook(const signed char *shape_cb, const spx_sig_t *_r, float *resp, __m128 *resp2, __m128 *E, int shape_cb_size, int subvect_size, char *stack)
{
int i, j, k;
__m128 resj, EE;
VARDECL(__m128 *r);
VARDECL(__m128 *shape);
ALLOC(r, subvect_size, __m128);
ALLOC(shape, subvect_size, __m128);
for(j=0;j<subvect_size;j++)
r[j] = _mm_load_ps1(_r+j);
for (i=0;i<shape_cb_size;i+=4)
{
float *_res = resp+i*subvect_size;
const signed char *_shape = shape_cb+i*subvect_size;
EE = _mm_setzero_ps();
for(j=0;j<subvect_size;j++)
{
shape[j] = _mm_setr_ps(0.03125*_shape[j], 0.03125*_shape[subvect_size+j], 0.03125*_shape[2*subvect_size+j], 0.03125*_shape[3*subvect_size+j]);
}
for(j=0;j<subvect_size;j++)
{
resj = _mm_setzero_ps();
for (k=0;k<=j;k++)
resj = _mm_add_ps(resj, _mm_mul_ps(shape[k],r[j-k]));
_spx_mm_getr_ps(resj, _res+j, _res+subvect_size+j, _res+2*subvect_size+j, _res+3*subvect_size+j);
*resp2++ = resj;
EE = _mm_add_ps(EE, _mm_mul_ps(resj, resj));
}
E[i>>2] = EE;
}
}
|
b0c560659cf5ee1bf954a702f7dcbbd35795c599
|
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
|
/SOFTWARE/A64-TERES/linux-a64/drivers/pcmcia/db1xxx_ss.c
|
a31e69ea99f367ed7fb46e312c0290acecbc5d65
|
[
"Linux-syscall-note",
"GPL-2.0-only",
"GPL-1.0-or-later",
"LicenseRef-scancode-free-unknown",
"Apache-2.0"
] |
permissive
|
OLIMEX/DIY-LAPTOP
|
ae82f4ee79c641d9aee444db9a75f3f6709afa92
|
a3fafd1309135650bab27f5eafc0c32bc3ca74ee
|
refs/heads/rel3
| 2023-08-04T01:54:19.483792
| 2023-04-03T07:18:12
| 2023-04-03T07:18:12
| 80,094,055
| 507
| 92
|
Apache-2.0
| 2023-04-03T07:05:59
| 2017-01-26T07:25:50
|
C
|
UTF-8
|
C
| false
| false
| 15,367
|
c
|
db1xxx_ss.c
|
/*
* PCMCIA socket code for the Alchemy Db1xxx/Pb1xxx boards.
*
* Copyright (c) 2009 Manuel Lauss <manuel.lauss@gmail.com>
*
*/
/* This is a fairly generic PCMCIA socket driver suitable for the
* following Alchemy Development boards:
* Db1000, Db/Pb1500, Db/Pb1100, Db/Pb1550, Db/Pb1200, Db1300
*
* The Db1000 is used as a reference: Per-socket card-, carddetect- and
* statuschange IRQs connected to SoC GPIOs, control and status register
* bits arranged in per-socket groups in an external PLD. All boards
* listed here use this layout, including bit positions and meanings.
* Of course there are exceptions in later boards:
*
* - Pb1100/Pb1500: single socket only; voltage key bits VS are
* at STATUS[5:4] (instead of STATUS[1:0]).
* - Au1200-based: additional card-eject irqs, irqs not gpios!
* - Db1300: Db1200-like, no pwr ctrl, single socket (#1).
*/
#include <linux/delay.h>
#include <linux/gpio.h>
#include <linux/interrupt.h>
#include <linux/pm.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/resource.h>
#include <linux/slab.h>
#include <linux/spinlock.h>
#include <pcmcia/ss.h>
#include <asm/mach-au1x00/au1000.h>
#include <asm/mach-db1x00/bcsr.h>
#define MEM_MAP_SIZE 0x400000
#define IO_MAP_SIZE 0x1000
struct db1x_pcmcia_sock {
struct pcmcia_socket socket;
int nr; /* socket number */
void *virt_io;
phys_addr_t phys_io;
phys_addr_t phys_attr;
phys_addr_t phys_mem;
/* previous flags for set_socket() */
unsigned int old_flags;
/* interrupt sources: linux irq numbers! */
int insert_irq; /* default carddetect irq */
int stschg_irq; /* card-status-change irq */
int card_irq; /* card irq */
int eject_irq; /* db1200/pb1200 have these */
#define BOARD_TYPE_DEFAULT 0 /* most boards */
#define BOARD_TYPE_DB1200 1 /* IRQs aren't gpios */
#define BOARD_TYPE_PB1100 2 /* VS bits slightly different */
#define BOARD_TYPE_DB1300 3 /* no power control */
int board_type;
};
#define to_db1x_socket(x) container_of(x, struct db1x_pcmcia_sock, socket)
static int db1300_card_inserted(struct db1x_pcmcia_sock *sock)
{
return bcsr_read(BCSR_SIGSTAT) & (1 << 8);
}
/* DB/PB1200: check CPLD SIGSTATUS register bit 10/12 */
static int db1200_card_inserted(struct db1x_pcmcia_sock *sock)
{
unsigned short sigstat;
sigstat = bcsr_read(BCSR_SIGSTAT);
return sigstat & 1 << (8 + 2 * sock->nr);
}
/* carddetect gpio: low-active */
static int db1000_card_inserted(struct db1x_pcmcia_sock *sock)
{
return !gpio_get_value(irq_to_gpio(sock->insert_irq));
}
static int db1x_card_inserted(struct db1x_pcmcia_sock *sock)
{
switch (sock->board_type) {
case BOARD_TYPE_DB1200:
return db1200_card_inserted(sock);
case BOARD_TYPE_DB1300:
return db1300_card_inserted(sock);
default:
return db1000_card_inserted(sock);
}
}
/* STSCHG tends to bounce heavily when cards are inserted/ejected.
* To avoid this, the interrupt is normally disabled and only enabled
* after reset to a card has been de-asserted.
*/
static inline void set_stschg(struct db1x_pcmcia_sock *sock, int en)
{
if (sock->stschg_irq != -1) {
if (en)
enable_irq(sock->stschg_irq);
else
disable_irq(sock->stschg_irq);
}
}
static irqreturn_t db1000_pcmcia_cdirq(int irq, void *data)
{
struct db1x_pcmcia_sock *sock = data;
pcmcia_parse_events(&sock->socket, SS_DETECT);
return IRQ_HANDLED;
}
static irqreturn_t db1000_pcmcia_stschgirq(int irq, void *data)
{
struct db1x_pcmcia_sock *sock = data;
pcmcia_parse_events(&sock->socket, SS_STSCHG);
return IRQ_HANDLED;
}
static irqreturn_t db1200_pcmcia_cdirq(int irq, void *data)
{
struct db1x_pcmcia_sock *sock = data;
/* Db/Pb1200 have separate per-socket insertion and ejection
* interrupts which stay asserted as long as the card is
* inserted/missing. The one which caused us to be called
* needs to be disabled and the other one enabled.
*/
if (irq == sock->insert_irq) {
disable_irq_nosync(sock->insert_irq);
enable_irq(sock->eject_irq);
} else {
disable_irq_nosync(sock->eject_irq);
enable_irq(sock->insert_irq);
}
pcmcia_parse_events(&sock->socket, SS_DETECT);
return IRQ_HANDLED;
}
static int db1x_pcmcia_setup_irqs(struct db1x_pcmcia_sock *sock)
{
int ret;
if (sock->stschg_irq != -1) {
ret = request_irq(sock->stschg_irq, db1000_pcmcia_stschgirq,
0, "pcmcia_stschg", sock);
if (ret)
return ret;
}
/* Db/Pb1200 have separate per-socket insertion and ejection
* interrupts, which should show edge behaviour but don't.
* So interrupts are disabled until both insertion and
* ejection handler have been registered and the currently
* active one disabled.
*/
if ((sock->board_type == BOARD_TYPE_DB1200) ||
(sock->board_type == BOARD_TYPE_DB1300)) {
ret = request_irq(sock->insert_irq, db1200_pcmcia_cdirq,
0, "pcmcia_insert", sock);
if (ret)
goto out1;
ret = request_irq(sock->eject_irq, db1200_pcmcia_cdirq,
0, "pcmcia_eject", sock);
if (ret) {
free_irq(sock->insert_irq, sock);
goto out1;
}
/* enable the currently silent one */
if (db1x_card_inserted(sock))
enable_irq(sock->eject_irq);
else
enable_irq(sock->insert_irq);
} else {
/* all other (older) Db1x00 boards use a GPIO to show
* card detection status: use both-edge triggers.
*/
irq_set_irq_type(sock->insert_irq, IRQ_TYPE_EDGE_BOTH);
ret = request_irq(sock->insert_irq, db1000_pcmcia_cdirq,
0, "pcmcia_carddetect", sock);
if (ret)
goto out1;
}
return 0; /* all done */
out1:
if (sock->stschg_irq != -1)
free_irq(sock->stschg_irq, sock);
return ret;
}
static void db1x_pcmcia_free_irqs(struct db1x_pcmcia_sock *sock)
{
if (sock->stschg_irq != -1)
free_irq(sock->stschg_irq, sock);
free_irq(sock->insert_irq, sock);
if (sock->eject_irq != -1)
free_irq(sock->eject_irq, sock);
}
/*
* configure a PCMCIA socket on the Db1x00 series of boards (and
* compatibles).
*
* 2 external registers are involved:
* pcmcia_status (offset 0x04): bits [0:1/2:3]: read card voltage id
* pcmcia_control(offset 0x10):
* bits[0:1] set vcc for card
* bits[2:3] set vpp for card
* bit 4: enable data buffers
* bit 7: reset# for card
* add 8 for second socket.
*/
static int db1x_pcmcia_configure(struct pcmcia_socket *skt,
struct socket_state_t *state)
{
struct db1x_pcmcia_sock *sock = to_db1x_socket(skt);
unsigned short cr_clr, cr_set;
unsigned int changed;
int v, p, ret;
/* card voltage setup */
cr_clr = (0xf << (sock->nr * 8)); /* clear voltage settings */
cr_set = 0;
v = p = ret = 0;
switch (state->Vcc) {
case 50:
++v;
case 33:
++v;
case 0:
break;
default:
printk(KERN_INFO "pcmcia%d unsupported Vcc %d\n",
sock->nr, state->Vcc);
}
switch (state->Vpp) {
case 12:
++p;
case 33:
case 50:
++p;
case 0:
break;
default:
printk(KERN_INFO "pcmcia%d unsupported Vpp %d\n",
sock->nr, state->Vpp);
}
/* sanity check: Vpp must be 0, 12, or Vcc */
if (((state->Vcc == 33) && (state->Vpp == 50)) ||
((state->Vcc == 50) && (state->Vpp == 33))) {
printk(KERN_INFO "pcmcia%d bad Vcc/Vpp combo (%d %d)\n",
sock->nr, state->Vcc, state->Vpp);
v = p = 0;
ret = -EINVAL;
}
/* create new voltage code */
if (sock->board_type != BOARD_TYPE_DB1300)
cr_set |= ((v << 2) | p) << (sock->nr * 8);
changed = state->flags ^ sock->old_flags;
if (changed & SS_RESET) {
if (state->flags & SS_RESET) {
set_stschg(sock, 0);
/* assert reset, disable io buffers */
cr_clr |= (1 << (7 + (sock->nr * 8)));
cr_clr |= (1 << (4 + (sock->nr * 8)));
} else {
/* de-assert reset, enable io buffers */
cr_set |= 1 << (7 + (sock->nr * 8));
cr_set |= 1 << (4 + (sock->nr * 8));
}
}
/* update PCMCIA configuration */
bcsr_mod(BCSR_PCMCIA, cr_clr, cr_set);
sock->old_flags = state->flags;
/* reset was taken away: give card time to initialize properly */
if ((changed & SS_RESET) && !(state->flags & SS_RESET)) {
msleep(500);
set_stschg(sock, 1);
}
return ret;
}
/* VCC bits at [3:2]/[11:10] */
#define GET_VCC(cr, socknr) \
((((cr) >> 2) >> ((socknr) * 8)) & 3)
/* VS bits at [0:1]/[3:2] */
#define GET_VS(sr, socknr) \
(((sr) >> (2 * (socknr))) & 3)
/* reset bits at [7]/[15] */
#define GET_RESET(cr, socknr) \
((cr) & (1 << (7 + (8 * (socknr)))))
static int db1x_pcmcia_get_status(struct pcmcia_socket *skt,
unsigned int *value)
{
struct db1x_pcmcia_sock *sock = to_db1x_socket(skt);
unsigned short cr, sr;
unsigned int status;
status = db1x_card_inserted(sock) ? SS_DETECT : 0;
cr = bcsr_read(BCSR_PCMCIA);
sr = bcsr_read(BCSR_STATUS);
/* PB1100/PB1500: voltage key bits are at [5:4] */
if (sock->board_type == BOARD_TYPE_PB1100)
sr >>= 4;
/* determine card type */
switch (GET_VS(sr, sock->nr)) {
case 0:
case 2:
status |= SS_3VCARD; /* 3V card */
case 3:
break; /* 5V card: set nothing */
default:
status |= SS_XVCARD; /* treated as unsupported in core */
}
/* if Vcc is not zero, we have applied power to a card */
status |= GET_VCC(cr, sock->nr) ? SS_POWERON : 0;
/* DB1300: power always on, but don't tell when no card present */
if ((sock->board_type == BOARD_TYPE_DB1300) && (status & SS_DETECT))
status = SS_POWERON | SS_3VCARD | SS_DETECT;
/* reset de-asserted? then we're ready */
status |= (GET_RESET(cr, sock->nr)) ? SS_READY : SS_RESET;
*value = status;
return 0;
}
static int db1x_pcmcia_sock_init(struct pcmcia_socket *skt)
{
return 0;
}
static int db1x_pcmcia_sock_suspend(struct pcmcia_socket *skt)
{
return 0;
}
static int au1x00_pcmcia_set_io_map(struct pcmcia_socket *skt,
struct pccard_io_map *map)
{
struct db1x_pcmcia_sock *sock = to_db1x_socket(skt);
map->start = (u32)sock->virt_io;
map->stop = map->start + IO_MAP_SIZE;
return 0;
}
static int au1x00_pcmcia_set_mem_map(struct pcmcia_socket *skt,
struct pccard_mem_map *map)
{
struct db1x_pcmcia_sock *sock = to_db1x_socket(skt);
if (map->flags & MAP_ATTRIB)
map->static_start = sock->phys_attr + map->card_start;
else
map->static_start = sock->phys_mem + map->card_start;
return 0;
}
static struct pccard_operations db1x_pcmcia_operations = {
.init = db1x_pcmcia_sock_init,
.suspend = db1x_pcmcia_sock_suspend,
.get_status = db1x_pcmcia_get_status,
.set_socket = db1x_pcmcia_configure,
.set_io_map = au1x00_pcmcia_set_io_map,
.set_mem_map = au1x00_pcmcia_set_mem_map,
};
static int db1x_pcmcia_socket_probe(struct platform_device *pdev)
{
struct db1x_pcmcia_sock *sock;
struct resource *r;
int ret, bid;
sock = kzalloc(sizeof(struct db1x_pcmcia_sock), GFP_KERNEL);
if (!sock)
return -ENOMEM;
sock->nr = pdev->id;
bid = BCSR_WHOAMI_BOARD(bcsr_read(BCSR_WHOAMI));
switch (bid) {
case BCSR_WHOAMI_PB1500:
case BCSR_WHOAMI_PB1500R2:
case BCSR_WHOAMI_PB1100:
sock->board_type = BOARD_TYPE_PB1100;
break;
case BCSR_WHOAMI_DB1000 ... BCSR_WHOAMI_PB1550_SDR:
sock->board_type = BOARD_TYPE_DEFAULT;
break;
case BCSR_WHOAMI_PB1200 ... BCSR_WHOAMI_DB1200:
sock->board_type = BOARD_TYPE_DB1200;
break;
case BCSR_WHOAMI_DB1300:
sock->board_type = BOARD_TYPE_DB1300;
break;
default:
printk(KERN_INFO "db1xxx-ss: unknown board %d!\n", bid);
ret = -ENODEV;
goto out0;
};
/*
* gather resources necessary and optional nice-to-haves to
* operate a socket:
* This includes IRQs for Carddetection/ejection, the card
* itself and optional status change detection.
* Also, the memory areas covered by a socket. For these
* we require the real 36bit addresses (see the au1000.h
* header for more information).
*/
/* card: irq assigned to the card itself. */
r = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "card");
sock->card_irq = r ? r->start : 0;
/* insert: irq which triggers on card insertion/ejection */
r = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "insert");
sock->insert_irq = r ? r->start : -1;
/* stschg: irq which trigger on card status change (optional) */
r = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "stschg");
sock->stschg_irq = r ? r->start : -1;
/* eject: irq which triggers on ejection (DB1200/PB1200 only) */
r = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "eject");
sock->eject_irq = r ? r->start : -1;
ret = -ENODEV;
/* 36bit PCMCIA Attribute area address */
r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pcmcia-attr");
if (!r) {
printk(KERN_ERR "pcmcia%d has no 'pseudo-attr' resource!\n",
sock->nr);
goto out0;
}
sock->phys_attr = r->start;
/* 36bit PCMCIA Memory area address */
r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pcmcia-mem");
if (!r) {
printk(KERN_ERR "pcmcia%d has no 'pseudo-mem' resource!\n",
sock->nr);
goto out0;
}
sock->phys_mem = r->start;
/* 36bit PCMCIA IO area address */
r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pcmcia-io");
if (!r) {
printk(KERN_ERR "pcmcia%d has no 'pseudo-io' resource!\n",
sock->nr);
goto out0;
}
sock->phys_io = r->start;
/*
* PCMCIA client drivers use the inb/outb macros to access
* the IO registers. Since mips_io_port_base is added
* to the access address of the mips implementation of
* inb/outb, we need to subtract it here because we want
* to access the I/O or MEM address directly, without
* going through this "mips_io_port_base" mechanism.
*/
sock->virt_io = (void *)(ioremap(sock->phys_io, IO_MAP_SIZE) -
mips_io_port_base);
if (!sock->virt_io) {
printk(KERN_ERR "pcmcia%d: cannot remap IO area\n",
sock->nr);
ret = -ENOMEM;
goto out0;
}
sock->socket.ops = &db1x_pcmcia_operations;
sock->socket.owner = THIS_MODULE;
sock->socket.pci_irq = sock->card_irq;
sock->socket.features = SS_CAP_STATIC_MAP | SS_CAP_PCCARD;
sock->socket.map_size = MEM_MAP_SIZE;
sock->socket.io_offset = (unsigned long)sock->virt_io;
sock->socket.dev.parent = &pdev->dev;
sock->socket.resource_ops = &pccard_static_ops;
platform_set_drvdata(pdev, sock);
ret = db1x_pcmcia_setup_irqs(sock);
if (ret) {
printk(KERN_ERR "pcmcia%d cannot setup interrupts\n",
sock->nr);
goto out1;
}
set_stschg(sock, 0);
ret = pcmcia_register_socket(&sock->socket);
if (ret) {
printk(KERN_ERR "pcmcia%d failed to register\n", sock->nr);
goto out2;
}
printk(KERN_INFO "Alchemy Db/Pb1xxx pcmcia%d @ io/attr/mem %09llx"
"(%p) %09llx %09llx card/insert/stschg/eject irqs @ %d "
"%d %d %d\n", sock->nr, sock->phys_io, sock->virt_io,
sock->phys_attr, sock->phys_mem, sock->card_irq,
sock->insert_irq, sock->stschg_irq, sock->eject_irq);
return 0;
out2:
db1x_pcmcia_free_irqs(sock);
out1:
iounmap((void *)(sock->virt_io + (u32)mips_io_port_base));
out0:
kfree(sock);
return ret;
}
static int db1x_pcmcia_socket_remove(struct platform_device *pdev)
{
struct db1x_pcmcia_sock *sock = platform_get_drvdata(pdev);
db1x_pcmcia_free_irqs(sock);
pcmcia_unregister_socket(&sock->socket);
iounmap((void *)(sock->virt_io + (u32)mips_io_port_base));
kfree(sock);
return 0;
}
static struct platform_driver db1x_pcmcia_socket_driver = {
.driver = {
.name = "db1xxx_pcmcia",
.owner = THIS_MODULE,
},
.probe = db1x_pcmcia_socket_probe,
.remove = db1x_pcmcia_socket_remove,
};
module_platform_driver(db1x_pcmcia_socket_driver);
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("PCMCIA Socket Services for Alchemy Db/Pb1x00 boards");
MODULE_AUTHOR("Manuel Lauss");
|
f1f45893e90d98effe73fc778e7942288372ee9c
|
e19509bd2548f173aa492d7498812afa28fcfbb5
|
/src/core/globcmd.c
|
dc453073e63af305af81b156ef0119b628e20240
|
[
"BSD-2-Clause"
] |
permissive
|
stsaz/fmedia
|
ef28a25e88ef50411014cfc7faef8813a67cf486
|
6f6d05fde4a6eba2f1fa0d9e194cd2b405258c3e
|
refs/heads/master
| 2023-08-19T20:30:03.512098
| 2023-07-24T16:37:33
| 2023-07-24T16:37:33
| 36,122,394
| 194
| 28
|
BSD-2-Clause
| 2022-07-19T15:09:24
| 2015-05-23T12:32:52
|
C
|
UTF-8
|
C
| false
| false
| 7,803
|
c
|
globcmd.c
|
/** Global commands.
Copyright (c) 2016 Simon Zolin */
#include <fmedia.h>
#include <util/conf2.h>
static const fmed_core *core;
// FMEDIA MODULE
static const void* globcmd_iface(const char *name);
static int globcmd_conf(const char *name, fmed_conf_ctx *ctx);
static int globcmd_sig(uint signo);
static void globcmd_destroy(void);
static const fmed_mod fmed_globcmd_mod = {
.ver = FMED_VER_FULL, .ver_core = FMED_VER_CORE,
.iface = &globcmd_iface,
.conf = &globcmd_conf,
.sig = &globcmd_sig,
.destroy = &globcmd_destroy,
};
// GLOBCMD IFACE
static int globcmd_ctl(uint cmd, ...);
static int globcmd_write(const void *data, size_t len);
static const fmed_globcmd_iface fmed_globcmd = {
&globcmd_ctl, &globcmd_write
};
enum {
GCMD_PIPE_IN_BUFSIZE = 1028,
};
typedef struct globcmd {
ffkevent kev;
fffd lpipe;
ffkq_task accept_task;
fffd opened_fd;
ffarr pipename_full;
char *pipe_name;
const fmed_track *track;
} globcmd;
static globcmd *g;
static const fmed_conf_arg globcmd_conf_args[] = {
{ "pipe_name", FMC_STRZNE, FMC_O(globcmd, pipe_name) },
{}
};
static int globcmd_init(void);
static int globcmd_prep(const char *pipename);
static void globcmd_free(void);
static int globcmd_listen(void);
static void globcmd_accept(void *udata);
static int globcmd_accept1(void);
static void globcmd_onaccept(fffd peer);
typedef struct cmd_parser {
ffconf conf;
const fmed_queue *qu;
const fmed_que_entry *first;
} cmd_parser;
static int globcmd_parse(cmd_parser *c, const ffstr *in);
const fmed_mod* fmed_getmod_globcmd(const fmed_core *_core)
{
core = _core;
return &fmed_globcmd_mod;
}
static const void* globcmd_iface(const char *name)
{
if (!ffsz_cmp(name, "globcmd"))
return &fmed_globcmd;
return NULL;
}
static int globcmd_conf(const char *name, fmed_conf_ctx *ctx)
{
if (!ffsz_cmp(name, "globcmd")) {
g->pipe_name = ffsz_alcopyz("fmedia");
fmed_conf_addctx(ctx, g, globcmd_conf_args);
return 0;
}
return -1;
}
static int globcmd_sig(uint signo)
{
switch (signo) {
case FMED_SIG_INIT:
if (0 != globcmd_init())
return -1;
break;
}
return 0;
}
static void globcmd_destroy(void)
{
globcmd_free();
}
static int globcmd_ctl(uint cmd, ...)
{
int r = -1;
va_list va;
va_start(va, cmd);
switch (cmd) {
case FMED_GLOBCMD_START: {
const char *pipename = va_arg(va, void*);
if (0 != globcmd_prep(pipename))
goto end;
if (0 != globcmd_listen())
goto end;
if (NULL == (g->track = core->getmod("#core.track")))
goto end;
r = 0;
break;
}
case FMED_GLOBCMD_OPEN: {
const char *pipename = va_arg(va, void*);
if (0 != globcmd_prep(pipename))
goto end;
if (FF_BADFD == (g->opened_fd = ffpipe_connect(g->pipename_full.ptr))) {
syserrlog(core, NULL, "globcmd", "pipe connect: %s", g->pipename_full.ptr);
goto end;
}
dbglog(core, NULL, "globcmd", "connected");
r = 0;
break;
}
}
end:
va_end(va);
return r;
}
static int globcmd_write(const void *data, size_t len)
{
if (len != (size_t)fffile_write(g->opened_fd, data, len))
return -1;
dbglog(core, NULL, "globcmd", "written %L bytes", len);
return 0;
}
static int globcmd_init(void)
{
if (NULL == (g = ffmem_tcalloc1(globcmd)))
return -1;
g->opened_fd = FFPIPE_NULL;
g->lpipe = FFPIPE_NULL;
ffkev_init(&g->kev);
return 0;
}
/** Prepare name of pipe. */
static int globcmd_prep(const char *pipename)
{
if (g->pipename_full.len != 0)
return 0;
if (pipename == NULL)
pipename = g->pipe_name;
#ifdef FF_UNIX
if (0 == ffstr_catfmt(&g->pipename_full, "/tmp/.%s-unix-%u%Z", pipename, getuid()))
return -1;
#else
if (0 == ffstr_catfmt(&g->pipename_full, "\\\\.\\pipe\\%s%Z", pipename))
return -1;
#endif
ffmem_safefree0(g->pipe_name);
return 0;
}
static void globcmd_free(void)
{
if (g->lpipe != FFPIPE_NULL) {
ffpipe_close(g->lpipe);
#ifdef FF_UNIX
fffile_rm(g->pipename_full.ptr);
#endif
}
FF_SAFECLOSE(g->opened_fd, FF_BADFD, ffpipe_client_close);
ffarr_free(&g->pipename_full);
ffmem_safefree0(g->pipe_name);
ffmem_free0(g);
}
static int globcmd_listen(void)
{
if (FFPIPE_NULL == (g->lpipe = ffpipe_create_named(g->pipename_full.ptr, FFPIPE_ASYNC))) {
syserrlog(core, NULL, "globcmd", "pipe create: %s", g->pipename_full.ptr);
goto end;
}
dbglog(core, NULL, "globcmd", "created pipe: %s", g->pipename_full.ptr);
g->kev.udata = g;
g->kev.oneshot = 0;
if (0 != ffkq_attach(core->kq, g->lpipe, ffkev_ptr(&g->kev), FFKQ_READ)) {
syserrlog(core, NULL, "globcmd", "%s", "pipe kq attach");
goto end;
}
globcmd_accept(NULL);
return 0;
end:
FF_SAFECLOSE(g->lpipe, FFPIPE_NULL, ffpipe_close);
return -1;
}
static void globcmd_accept(void *udata)
{
for (;;) {
if (0 != globcmd_accept1())
break;
}
}
static int globcmd_accept1(void)
{
fffd peer = ffpipe_accept_async(g->lpipe, &g->accept_task);
if (peer == FFPIPE_NULL) {
if (fferr_last() == FFPIPE_EINPROGRESS) {
dbglog(core, NULL, "globcmd", "listening");
g->kev.handler = globcmd_accept;
} else {
syserrlog(core, NULL, "globcmd", "pipe accept: %s", g->pipename_full.ptr);
}
return -1;
}
globcmd_onaccept(peer);
ffpipe_peer_close(peer);
return 0;
}
static void globcmd_onaccept(fffd peer)
{
ffarr buf = {0};
ffstr in;
ssize_t r;
cmd_parser c = {};
dbglog(core, NULL, "globcmd", "accepted client");
c.qu = core->getmod("#queue.queue");
ffconf_init(&c.conf);
if (NULL == ffarr_alloc(&buf, GCMD_PIPE_IN_BUFSIZE)) {
syserrlog(core, NULL, "globcmd", "mem alloc", 0);
goto done;
}
for (;;) {
r = ffpipe_read(peer, buf.ptr, buf.cap);
if (r < 0) {
syserrlog(core, NULL, "globcmd", "%s", fffile_read_S);
break;
} else if (r == 0) {
ffstr_setcz(&in, "\n");
r = globcmd_parse(&c, &in);
if (r < 0)
goto done;
break;
}
ffstr_set(&in, buf.ptr, r);
dbglog(core, NULL, "globcmd", "read %L bytes", r);
r = globcmd_parse(&c, &in);
if (r < 0)
goto done;
}
done:
ffarr_free(&buf);
ffconf_fin(&c.conf);
dbglog(core, NULL, "globcmd", "done with client");
}
enum CMD {
CMD_ADD,
CMD_CLEAR,
CMD_NEXT,
CMD_PAUSE,
CMD_PLAY,
CMD_QUIT,
CMD_STOP,
CMD_UNPAUSE,
};
static const char* const cmds_sorted_str[] = {
"add", // "add INPUT..."
"clear",
"next",
"pause",
"play", // "play INPUT..."
"quit",
"stop",
"unpause",
};
static void exec_cmd(cmd_parser *c, int cmd, ffstr *val)
{
switch ((enum CMD)cmd) {
case CMD_CLEAR:
c->qu->cmd(FMED_QUE_CLEAR, NULL);
break;
case CMD_NEXT:
c->qu->cmd(FMED_QUE_NEXT2, NULL);
break;
case CMD_ADD:
case CMD_PLAY: {
if (val == NULL)
break;
fmed_que_entry e = {}, *ent;
e.url = *val;
ent = c->qu->add(&e);
if (cmd == CMD_PLAY)
c->qu->cmd(FMED_QUE_PLAY_EXCL, (void*)ent);
break;
}
case CMD_PAUSE:
g->track->cmd((void*)-1, FMED_TRACK_PAUSE);
break;
case CMD_UNPAUSE:
g->track->cmd((void*)-1, FMED_TRACK_UNPAUSE);
break;
case CMD_STOP:
g->track->cmd((void*)-1, FMED_TRACK_STOPALL);
break;
case CMD_QUIT:
g->track->cmd((void*)-1, FMED_TRACK_STOPALL_EXIT);
break;
}
}
/** Parse commands. Format:
CMD [PARAMS] \n
...
*/
static int globcmd_parse(cmd_parser *c, const ffstr *in)
{
ffstr data = *in;
int r, cmd = 0;
for (;;) {
ffstr val;
r = ffconf_parse3(&c->conf, &data, &val);
switch (r) {
case FFCONF_RMORE:
return 0;
case FFCONF_RKEY:
r = ffszarr_findsorted(cmds_sorted_str, FFCNT(cmds_sorted_str), val.ptr, val.len);
if (r < 0) {
warnlog(core, NULL, "globcmd", "unsupported command: %S", &val);
return -1;
}
dbglog(core, NULL, "globcmd", "received pipe command: %S", &val);
cmd = r;
exec_cmd(c, r, NULL);
break;
case FFCONF_RVAL:
case FFCONF_RVAL_NEXT:
exec_cmd(c, cmd, &val);
break;
default:
warnlog(core, NULL, "globcmd", "pipe command parse: (%d) %s", r, ffconf_errstr(r));
return -1;
}
}
return 0;
}
|
e81680f84dd4ace543a9ef8f906269da06264530
|
a5f3b0001cdb692aeffc444a16f79a0c4422b9d0
|
/main/sane/inc/sane.h
|
3d0602300eb3f41b075cfdc24a3b15f462b8be50
|
[
"Apache-2.0",
"CPL-1.0",
"bzip2-1.0.6",
"LicenseRef-scancode-other-permissive",
"Zlib",
"LZMA-exception",
"LGPL-2.0-or-later",
"LicenseRef-scancode-free-unknown",
"LicenseRef-scancode-philippe-de-muyter",
"OFL-1.1",
"LGPL-2.1-only",
"MPL-1.1",
"X11",
"LGPL-2.1-or-later",
"GPL-2.0-only",
"OpenSSL",
"LicenseRef-scancode-cpl-0.5",
"GPL-1.0-or-later",
"NPL-1.1",
"MIT",
"MPL-2.0",
"LicenseRef-scancode-other-copyleft",
"LicenseRef-scancode-unknown-license-reference",
"MPL-1.0",
"LicenseRef-scancode-openssl",
"LicenseRef-scancode-ssleay-windows",
"BSL-1.0",
"LicenseRef-scancode-docbook",
"LicenseRef-scancode-mit-old-style",
"Python-2.0",
"BSD-3-Clause",
"IJG",
"LicenseRef-scancode-warranty-disclaimer",
"GPL-2.0-or-later",
"LGPL-2.0-only",
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown",
"BSD-2-Clause",
"Autoconf-exception-generic",
"PSF-2.0",
"NTP",
"LicenseRef-scancode-python-cwi",
"Afmparse",
"W3C",
"W3C-19980720",
"curl",
"LicenseRef-scancode-x11-xconsortium-veillard",
"Bitstream-Vera",
"HPND-sell-variant",
"ICU"
] |
permissive
|
apache/openoffice
|
b9518e36d784898c6c2ea3ebd44458a5e47825bb
|
681286523c50f34f13f05f7b87ce0c70e28295de
|
refs/heads/trunk
| 2023-08-30T15:25:48.357535
| 2023-08-28T19:50:26
| 2023-08-28T19:50:26
| 14,357,669
| 907
| 379
|
Apache-2.0
| 2023-08-16T20:49:37
| 2013-11-13T08:00:13
|
C++
|
UTF-8
|
C
| false
| false
| 7,929
|
h
|
sane.h
|
/* sane - Scanner Access Now Easy.
Copyright (C) 1997-1999 David Mosberger-Tang and Andreas Beck
This file is part of the SANE package.
This file is in the public domain. You may use and modify it as
you see fit, as long as this copyright message is included and
that there is an indication as to what modifications have been
made (if any).
SANE 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.
This file declares SANE application interface. See the SANE
standard for a detailed explanation of the interface. */
#ifndef sane_h
#define sane_h
#ifdef __cplusplus
extern "C" {
#endif
/*
* SANE types and defines
*/
#define SANE_CURRENT_MAJOR 1
#define SANE_CURRENT_MINOR 0
#define SANE_VERSION_CODE(major, minor, build) \
( (((SANE_Word) (major) & 0xff) << 24) \
| (((SANE_Word) (minor) & 0xff) << 16) \
| (((SANE_Word) (build) & 0xffff) << 0))
#define SANE_VERSION_MAJOR(code) ((((SANE_Word)(code)) >> 24) & 0xff)
#define SANE_VERSION_MINOR(code) ((((SANE_Word)(code)) >> 16) & 0xff)
#define SANE_VERSION_BUILD(code) ((((SANE_Word)(code)) >> 0) & 0xffff)
#define SANE_FALSE 0
#define SANE_TRUE 1
typedef unsigned char SANE_Byte;
typedef int SANE_Word;
typedef SANE_Word SANE_Bool;
typedef SANE_Word SANE_Int;
typedef char SANE_Char;
typedef SANE_Char *SANE_String;
typedef const SANE_Char *SANE_String_Const;
typedef void *SANE_Handle;
typedef SANE_Word SANE_Fixed;
#define SANE_FIXED_SCALE_SHIFT 16
#define SANE_FIX(v) ((SANE_Word) ((v) * (1 << SANE_FIXED_SCALE_SHIFT)))
#define SANE_UNFIX(v) ((double)(v) / (1 << SANE_FIXED_SCALE_SHIFT))
typedef enum
{
SANE_STATUS_GOOD = 0, /* everything A-OK */
SANE_STATUS_UNSUPPORTED, /* operation is not supported */
SANE_STATUS_CANCELLED, /* operation was cancelled */
SANE_STATUS_DEVICE_BUSY, /* device is busy; try again later */
SANE_STATUS_INVAL, /* data is invalid (includes no dev at open) */
SANE_STATUS_EOF, /* no more data available (end-of-file) */
SANE_STATUS_JAMMED, /* document feeder jammed */
SANE_STATUS_NO_DOCS, /* document feeder out of documents */
SANE_STATUS_COVER_OPEN, /* scanner cover is open */
SANE_STATUS_IO_ERROR, /* error during device I/O */
SANE_STATUS_NO_MEM, /* out of memory */
SANE_STATUS_ACCESS_DENIED /* access to resource has been denied */
}
SANE_Status;
/* following are for later sane version, older frontends won't support */
#if 0
#define SANE_STATUS_WARMING_UP 12 /* lamp not ready, please retry */
#define SANE_STATUS_HW_LOCKED 13 /* scanner mechanism locked for transport */
#endif
typedef enum
{
SANE_TYPE_BOOL = 0,
SANE_TYPE_INT,
SANE_TYPE_FIXED,
SANE_TYPE_STRING,
SANE_TYPE_BUTTON,
SANE_TYPE_GROUP
}
SANE_Value_Type;
typedef enum
{
SANE_UNIT_NONE = 0, /* the value is unit-less (e.g., # of scans) */
SANE_UNIT_PIXEL, /* value is number of pixels */
SANE_UNIT_BIT, /* value is number of bits */
SANE_UNIT_MM, /* value is millimeters */
SANE_UNIT_DPI, /* value is resolution in dots/inch */
SANE_UNIT_PERCENT, /* value is a percentage */
SANE_UNIT_MICROSECOND /* value is micro seconds */
}
SANE_Unit;
typedef struct
{
SANE_String_Const name; /* unique device name */
SANE_String_Const vendor; /* device vendor string */
SANE_String_Const model; /* device model name */
SANE_String_Const type; /* device type (e.g., "flatbed scanner") */
}
SANE_Device;
#define SANE_CAP_SOFT_SELECT (1 << 0)
#define SANE_CAP_HARD_SELECT (1 << 1)
#define SANE_CAP_SOFT_DETECT (1 << 2)
#define SANE_CAP_EMULATED (1 << 3)
#define SANE_CAP_AUTOMATIC (1 << 4)
#define SANE_CAP_INACTIVE (1 << 5)
#define SANE_CAP_ADVANCED (1 << 6)
#define SANE_OPTION_IS_ACTIVE(cap) (((cap) & SANE_CAP_INACTIVE) == 0)
#define SANE_OPTION_IS_SETTABLE(cap) (((cap) & SANE_CAP_SOFT_SELECT) != 0)
#define SANE_INFO_INEXACT (1 << 0)
#define SANE_INFO_RELOAD_OPTIONS (1 << 1)
#define SANE_INFO_RELOAD_PARAMS (1 << 2)
typedef enum
{
SANE_CONSTRAINT_NONE = 0,
SANE_CONSTRAINT_RANGE,
SANE_CONSTRAINT_WORD_LIST,
SANE_CONSTRAINT_STRING_LIST
}
SANE_Constraint_Type;
typedef struct
{
SANE_Word min; /* minimum (element) value */
SANE_Word max; /* maximum (element) value */
SANE_Word quant; /* quantization value (0 if none) */
}
SANE_Range;
typedef struct
{
SANE_String_Const name; /* name of this option (command-line name) */
SANE_String_Const title; /* title of this option (single-line) */
SANE_String_Const desc; /* description of this option (multi-line) */
SANE_Value_Type type; /* how are values interpreted? */
SANE_Unit unit; /* what is the (physical) unit? */
SANE_Int size;
SANE_Int cap; /* capabilities */
SANE_Constraint_Type constraint_type;
union
{
const SANE_String_Const *string_list; /* NULL-terminated list */
const SANE_Word *word_list; /* first element is list-length */
const SANE_Range *range;
}
constraint;
}
SANE_Option_Descriptor;
typedef enum
{
SANE_ACTION_GET_VALUE = 0,
SANE_ACTION_SET_VALUE,
SANE_ACTION_SET_AUTO
}
SANE_Action;
typedef enum
{
SANE_FRAME_GRAY, /* band covering human visual range */
SANE_FRAME_RGB, /* pixel-interleaved red/green/blue bands */
SANE_FRAME_RED, /* red band only */
SANE_FRAME_GREEN, /* green band only */
SANE_FRAME_BLUE /* blue band only */
}
SANE_Frame;
/* push remaining types down to match existing backends */
/* these are to be exposed in a later version of SANE */
/* most front-ends will require updates to understand them */
#if 0
#define SANE_FRAME_TEXT 0x0A /* backend specific textual data */
#define SANE_FRAME_JPEG 0x0B /* complete baseline JPEG file */
#define SANE_FRAME_G31D 0x0C /* CCITT Group 3 1-D Compressed (MH) */
#define SANE_FRAME_G32D 0x0D /* CCITT Group 3 2-D Compressed (MR) */
#define SANE_FRAME_G42D 0x0E /* CCITT Group 4 2-D Compressed (MMR) */
#define SANE_FRAME_IR 0x0F /* bare infrared channel */
#define SANE_FRAME_RGBI 0x10 /* red+green+blue+infrared */
#define SANE_FRAME_GRAYI 0x11 /* gray+infrared */
#define SANE_FRAME_XML 0x12 /* undefined schema */
#endif
typedef struct
{
SANE_Frame format;
SANE_Bool last_frame;
SANE_Int bytes_per_line;
SANE_Int pixels_per_line;
SANE_Int lines;
SANE_Int depth;
}
SANE_Parameters;
struct SANE_Auth_Data;
#define SANE_MAX_USERNAME_LEN 128
#define SANE_MAX_PASSWORD_LEN 128
typedef void (*SANE_Auth_Callback) (SANE_String_Const resource,
SANE_Char *username,
SANE_Char *password);
extern SANE_Status sane_init (SANE_Int * version_code,
SANE_Auth_Callback authorize);
extern void sane_exit (void);
extern SANE_Status sane_get_devices (const SANE_Device *** device_list,
SANE_Bool local_only);
extern SANE_Status sane_open (SANE_String_Const devicename,
SANE_Handle * handle);
extern void sane_close (SANE_Handle handle);
extern const SANE_Option_Descriptor *
sane_get_option_descriptor (SANE_Handle handle, SANE_Int option);
extern SANE_Status sane_control_option (SANE_Handle handle, SANE_Int option,
SANE_Action action, void *value,
SANE_Int * info);
extern SANE_Status sane_get_parameters (SANE_Handle handle,
SANE_Parameters * params);
extern SANE_Status sane_start (SANE_Handle handle);
extern SANE_Status sane_read (SANE_Handle handle, SANE_Byte * data,
SANE_Int max_length, SANE_Int * length);
extern void sane_cancel (SANE_Handle handle);
extern SANE_Status sane_set_io_mode (SANE_Handle handle,
SANE_Bool non_blocking);
extern SANE_Status sane_get_select_fd (SANE_Handle handle,
SANE_Int * fd);
extern SANE_String_Const sane_strstatus (SANE_Status status);
#ifdef __cplusplus
}
#endif
#endif /* sane_h */
|
a6a51c5597003a2e3e05790ebbc45320e72de5a3
|
aa3befea459382dc5c01c925653d54f435b3fb0f
|
/drivers/audio/wm8776.c
|
ee11f2e95fd7788341cf554a992d0076596e7022
|
[
"MIT-open-group",
"BSD-3-Clause",
"HPND-sell-variant",
"BSD-4-Clause-UC",
"LicenseRef-scancode-warranty-disclaimer",
"MIT-0",
"LicenseRef-scancode-bsd-atmel",
"LicenseRef-scancode-gary-s-brown",
"LicenseRef-scancode-proprietary-license",
"SunPro",
"MIT",
"LicenseRef-scancode-public-domain-disclaimer",
"LicenseRef-scancode-other-permissive",
"HPND",
"ISC",
"Apache-2.0",
"LicenseRef-scancode-public-domain",
"BSD-2-Clause",
"GPL-1.0-or-later",
"CC-BY-2.0",
"CC-BY-4.0"
] |
permissive
|
apache/nuttx
|
14519a7bff4a87935d94fb8fb2b19edb501c7cec
|
606b6d9310fb25c7d92c6f95bf61737e3c79fa0f
|
refs/heads/master
| 2023-08-25T06:55:45.822534
| 2023-08-23T16:03:31
| 2023-08-24T21:25:47
| 228,103,273
| 407
| 241
|
Apache-2.0
| 2023-09-14T18:26:05
| 2019-12-14T23:27:55
|
C
|
UTF-8
|
C
| false
| false
| 37,955
|
c
|
wm8776.c
|
/****************************************************************************
* drivers/audio/wm8776.c
*
* 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
#include <fcntl.h>
#include <string.h>
#include <assert.h>
#include <errno.h>
#include <fixedmath.h>
#include <debug.h>
#include <nuttx/spinlock.h>
#include <nuttx/kmalloc.h>
#include <nuttx/queue.h>
#include <nuttx/semaphore.h>
#include <nuttx/clock.h>
#include <nuttx/wqueue.h>
#include <nuttx/i2c/i2c_master.h>
#include <nuttx/fs/fs.h>
#include <nuttx/fs/ioctl.h>
#include <nuttx/audio/i2s.h>
#include <nuttx/audio/audio.h>
#include <nuttx/audio/wm8776.h>
#include "wm8776.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
static void wm8776_writereg(FAR struct wm8776_dev_s *priv,
uint8_t regaddr, uint16_t regval);
static int wm8776_getcaps(FAR struct audio_lowerhalf_s *dev, int type,
FAR struct audio_caps_s *caps);
#ifdef CONFIG_AUDIO_MULTI_SESSION
static int wm8776_configure(FAR struct audio_lowerhalf_s *dev,
FAR void *session, FAR const struct audio_caps_s *caps);
#else
static int wm8776_configure(FAR struct audio_lowerhalf_s *dev,
FAR const struct audio_caps_s *caps);
#endif
static int wm8776_shutdown(FAR struct audio_lowerhalf_s *dev);
static void wm8776_senddone(FAR struct i2s_dev_s *i2s,
FAR struct ap_buffer_s *apb, FAR void *arg, int result);
static void wm8776_returnbuffers(FAR struct wm8776_dev_s *priv);
static int wm8776_sendbuffer(FAR struct wm8776_dev_s *priv);
#ifdef CONFIG_AUDIO_MULTI_SESSION
static int wm8776_start(FAR struct audio_lowerhalf_s *dev,
FAR void *session);
#else
static int wm8776_start(FAR struct audio_lowerhalf_s *dev);
#endif
#ifndef CONFIG_AUDIO_EXCLUDE_STOP
#ifdef CONFIG_AUDIO_MULTI_SESSION
static int wm8776_stop(FAR struct audio_lowerhalf_s *dev,
FAR void *session);
#else
static int wm8776_stop(FAR struct audio_lowerhalf_s *dev);
#endif
#endif
#ifndef CONFIG_AUDIO_EXCLUDE_PAUSE_RESUME
#ifdef CONFIG_AUDIO_MULTI_SESSION
static int wm8776_pause(FAR struct audio_lowerhalf_s *dev,
FAR void *session);
static int wm8776_resume(FAR struct audio_lowerhalf_s *dev,
FAR void *session);
#else
static int wm8776_pause(FAR struct audio_lowerhalf_s *dev);
static int wm8776_resume(FAR struct audio_lowerhalf_s *dev);
#endif
#endif
static int wm8776_enqueuebuffer(FAR struct audio_lowerhalf_s *dev,
FAR struct ap_buffer_s *apb);
static int wm8776_cancelbuffer(FAR struct audio_lowerhalf_s *dev,
FAR struct ap_buffer_s *apb);
static int wm8776_ioctl(FAR struct audio_lowerhalf_s *dev, int cmd,
unsigned long arg);
#ifdef CONFIG_AUDIO_MULTI_SESSION
static int wm8776_reserve(FAR struct audio_lowerhalf_s *dev,
FAR void **session);
#else
static int wm8776_reserve(FAR struct audio_lowerhalf_s *dev);
#endif
#ifdef CONFIG_AUDIO_MULTI_SESSION
static int wm8776_release(FAR struct audio_lowerhalf_s *dev,
FAR void *session);
#else
static int wm8776_release(FAR struct audio_lowerhalf_s *dev);
#endif
static void *wm8776_workerthread(pthread_addr_t pvarg);
/* Initialization */
static void wm8776_audio_output(FAR struct wm8776_dev_s *priv);
#if 0 /* Not used */
static void wm8776_audio_input(FAR struct wm8776_dev_s *priv);
#endif
static void wm8776_hw_reset(FAR struct wm8776_dev_s *priv);
/****************************************************************************
* Private Data
****************************************************************************/
static const struct audio_ops_s g_audioops =
{
wm8776_getcaps, /* getcaps */
wm8776_configure, /* configure */
wm8776_shutdown, /* shutdown */
wm8776_start, /* start */
#ifndef CONFIG_AUDIO_EXCLUDE_STOP
wm8776_stop, /* stop */
#endif
#ifndef CONFIG_AUDIO_EXCLUDE_PAUSE_RESUME
wm8776_pause, /* pause */
wm8776_resume, /* resume */
#endif
NULL, /* allocbuffer */
NULL, /* freebuffer */
wm8776_enqueuebuffer, /* enqueue_buffer */
wm8776_cancelbuffer, /* cancel_buffer */
wm8776_ioctl, /* ioctl */
NULL, /* read */
NULL, /* write */
wm8776_reserve, /* reserve */
wm8776_release /* release */
};
/****************************************************************************
* Name: wm8776_writereg
*
* Description:
* Write the specified 16-bit register to the WM8776 device.
*
****************************************************************************/
static void wm8776_writereg(FAR struct wm8776_dev_s *priv,
uint8_t regaddr,
uint16_t regval)
{
struct i2c_config_s config;
uint8_t data[2];
int ret;
/* Setup up the I2C configuration */
config.frequency = priv->lower->frequency;
config.address = priv->lower->address;
config.addrlen = 7;
/* Set up the data to write */
data[0] = (regaddr << 1) + ((regval >> 8) & 0x1);
data[1] = (regval & 0xff);
ret = i2c_write(priv->i2c, &config, data, sizeof(data));
if (ret < 0)
{
auderr("ERROR: I2C_TRANSFER failed: %d\n", ret);
}
}
/****************************************************************************
* Name: wm8776_setvolume
*
* Description:
* Set the right and left volume values in the WM8776 device based on the
* current volume and balance settings.
*
****************************************************************************/
#ifndef CONFIG_AUDIO_EXCLUDE_VOLUME
static void wm8776_setvolume(FAR struct wm8776_dev_s *priv, uint16_t volume,
bool mute)
{
uint16_t regval;
uint16_t tmp_vol;
/* TODO: balance */
if (mute)
{
tmp_vol = 0;
}
else
{
tmp_vol = volume;
}
/* limit the max vol */
if (tmp_vol > 0x69)
{
tmp_vol = 0x69; /* -10db */
}
regval = WM8776_UPDATE | WM8776_HPOUT_VOL(tmp_vol);
wm8776_writereg(priv, WM8776_MASTER_ATT, regval);
audinfo("volume=%d mute=%d tmp_vol=%d (regval=0x%x)\n",
volume, mute, tmp_vol, regval);
/* Remember the volume level and mute settings */
priv->volume = volume;
priv->mute = mute;
}
#endif /* CONFIG_AUDIO_EXCLUDE_VOLUME */
/****************************************************************************
* Name: wm8776_getcaps
*
* Description:
* Get the audio device capabilities
*
****************************************************************************/
static int wm8776_getcaps(FAR struct audio_lowerhalf_s *dev, int type,
FAR struct audio_caps_s *caps)
{
/* Validate the structure */
DEBUGASSERT(caps && caps->ac_len >= sizeof(struct audio_caps_s));
audinfo("type=%d ac_type=%d\n", type, caps->ac_type);
/* Fill in the caller's structure based on requested info */
caps->ac_format.hw = 0;
caps->ac_controls.w = 0;
switch (caps->ac_type)
{
/* Caller is querying for the types of units we support */
case AUDIO_TYPE_QUERY:
/* Provide our overall capabilities. The interfacing software
* must then call us back for specific info for each capability.
*/
caps->ac_channels = 2; /* Stereo output */
switch (caps->ac_subtype)
{
case AUDIO_TYPE_QUERY:
/* We don't decode any formats! Only something above us in
* the audio stream can perform decoding on our behalf.
*/
/* The types of audio units we implement */
caps->ac_controls.b[0] =
AUDIO_TYPE_OUTPUT | AUDIO_TYPE_FEATURE |
AUDIO_TYPE_PROCESSING;
break;
default:
caps->ac_controls.b[0] = AUDIO_SUBFMT_END;
break;
}
break;
/* Provide capabilities of our OUTPUT unit */
case AUDIO_TYPE_OUTPUT:
caps->ac_channels = 2;
switch (caps->ac_subtype)
{
case AUDIO_TYPE_QUERY:
/* Report the Sample rates we support */
caps->ac_controls.b[0] = AUDIO_SAMP_RATE_44K;
break;
case AUDIO_FMT_MP3:
case AUDIO_FMT_WMA:
case AUDIO_FMT_PCM:
default:
break;
}
break;
/* All others we don't support */
default:
/* Zero out the fields to indicate no support */
caps->ac_subtype = 0;
caps->ac_channels = 0;
break;
}
/* Return the length of the audio_caps_s struct for validation of
* proper Audio device type.
*/
return caps->ac_len;
}
/****************************************************************************
* Name: wm8776_configure
*
* Description:
* Configure the audio device for the specified mode of operation.
*
****************************************************************************/
#ifdef CONFIG_AUDIO_MULTI_SESSION
static int wm8776_configure(FAR struct audio_lowerhalf_s *dev,
FAR void *session,
FAR const struct audio_caps_s *caps)
#else
static int wm8776_configure(FAR struct audio_lowerhalf_s *dev,
FAR const struct audio_caps_s *caps)
#endif
{
FAR struct wm8776_dev_s *priv = (FAR struct wm8776_dev_s *)dev;
int ret = OK;
DEBUGASSERT(priv != NULL && caps != NULL);
audinfo("ac_type: %d\n", caps->ac_type);
/* Process the configure operation */
switch (caps->ac_type)
{
case AUDIO_TYPE_FEATURE:
audinfo(" AUDIO_TYPE_FEATURE\n");
/* Process based on Feature Unit */
switch (caps->ac_format.hw)
{
#ifndef CONFIG_AUDIO_EXCLUDE_VOLUME
case AUDIO_FU_VOLUME:
{
/* Set the volume */
uint16_t volume = caps->ac_controls.hw[0];
audinfo(" Volume: %d\n", volume);
if (volume >= 0 && volume <= 1000)
{
/* Scale the volume setting to the range {0x2f .. 0x79} */
wm8776_setvolume(priv, (0x4a * volume / 1000) + 0x2f,
priv->mute);
}
else
{
ret = -EDOM;
}
}
break;
#endif /* CONFIG_AUDIO_EXCLUDE_VOLUME */
default:
auderr(" ERROR: Unrecognized feature unit\n");
ret = -ENOTTY;
break;
}
break;
case AUDIO_TYPE_OUTPUT:
{
audinfo(" AUDIO_TYPE_OUTPUT:\n");
audinfo(" Number of channels: %u\n", caps->ac_channels);
audinfo(" Sample rate: %u\n", caps->ac_controls.hw[0]);
audinfo(" Sample width: %u\n", caps->ac_controls.b[2]);
/* Verify that all of the requested values are supported */
ret = -ERANGE;
if (caps->ac_channels != 1 && caps->ac_channels != 2)
{
auderr("ERROR: Unsupported number of channels: %d\n",
caps->ac_channels);
break;
}
if (caps->ac_controls.b[2] != 8 && caps->ac_controls.b[2] != 16)
{
auderr("ERROR: Unsupported bits per sample: %d\n",
caps->ac_controls.b[2]);
break;
}
/* Save the current stream configuration */
priv->samprate = caps->ac_controls.hw[0];
priv->nchannels = caps->ac_channels;
priv->bpsamp = caps->ac_controls.b[2];
/* TODO : channels, bits per sample, bitrate */
ret = OK;
}
break;
case AUDIO_TYPE_PROCESSING:
break;
}
return ret;
}
/****************************************************************************
* Name: wm8776_shutdown
*
* Description:
* Shutdown the WM8776 chip and put it in the lowest power state possible.
*
****************************************************************************/
static int wm8776_shutdown(FAR struct audio_lowerhalf_s *dev)
{
FAR struct wm8776_dev_s *priv = (FAR struct wm8776_dev_s *)dev;
DEBUGASSERT(priv);
/* Now issue a software reset. This puts all WM8776 registers back in
* their default state.
*/
wm8776_hw_reset(priv);
return OK;
}
/****************************************************************************
* Name: wm8776_senddone
*
* Description:
* This is the I2S callback function that is invoked when the transfer
* completes.
*
****************************************************************************/
static void wm8776_senddone(FAR struct i2s_dev_s *i2s,
FAR struct ap_buffer_s *apb, FAR void *arg,
int result)
{
FAR struct wm8776_dev_s *priv = (FAR struct wm8776_dev_s *)arg;
struct audio_msg_s msg;
irqstate_t flags;
int ret;
DEBUGASSERT(i2s && priv && priv->running && apb);
audinfo("apb=%p inflight=%d result=%d\n", apb, priv->inflight, result);
/* We do not place any restriction on the context in which this function
* is called. It may be called from an interrupt handler. Therefore, the
* doneq and in-flight values might be accessed from the interrupt level.
* Not the best design. But we will use interrupt controls to protect
* against that possibility.
*/
flags = spin_lock_irqsave(NULL);
/* Add the completed buffer to the end of our doneq. We do not yet
* decrement the reference count.
*/
dq_addlast((FAR dq_entry_t *)apb, &priv->doneq);
/* And decrement the number of buffers in-flight */
DEBUGASSERT(priv->inflight > 0);
priv->inflight--;
/* Save the result of the transfer */
/* REVISIT: This can be overwritten */
priv->result = result;
spin_unlock_irqrestore(NULL, flags);
/* Now send a message to the worker thread, informing it that there are
* buffers in the done queue that need to be cleaned up.
*/
msg.msg_id = AUDIO_MSG_COMPLETE;
ret = file_mq_send(&priv->mq, (FAR const char *)&msg, sizeof(msg),
CONFIG_WM8776_MSG_PRIO);
if (ret < 0)
{
auderr("ERROR: file_mq_send failed: %d\n", ret);
}
}
/****************************************************************************
* Name: wm8776_returnbuffers
*
* Description:
* This function is called after the complete of one or more data
* transfers. This function will empty the done queue and release our
* reference to each buffer.
*
****************************************************************************/
static void wm8776_returnbuffers(FAR struct wm8776_dev_s *priv)
{
FAR struct ap_buffer_s *apb;
irqstate_t flags;
/* The doneq and in-flight values might be accessed from the interrupt
* level in some implementations. Not the best design. But we will
* use interrupt controls to protect against that possibility.
*/
flags = spin_lock_irqsave(NULL);
while (dq_peek(&priv->doneq) != NULL)
{
/* Take the next buffer from the queue of completed transfers */
apb = (FAR struct ap_buffer_s *)dq_remfirst(&priv->doneq);
spin_unlock_irqrestore(NULL, flags);
audinfo("Returning: apb=%p curbyte=%d nbytes=%d flags=%04x\n",
apb, apb->curbyte, apb->nbytes, apb->flags);
/* Are we returning the final buffer in the stream? */
if ((apb->flags & AUDIO_APB_FINAL) != 0)
{
/* Both the pending and the done queues should be empty and there
* should be no buffers in-flight.
*/
DEBUGASSERT(dq_empty(&priv->doneq) && dq_empty(&priv->pendq) &&
priv->inflight == 0);
/* Set the terminating flag. This will, eventually, cause the
* worker thread to exit (if it is not already terminating).
*/
audinfo("Terminating\n");
priv->terminating = true;
}
/* Release our reference to the audio buffer */
apb_free(apb);
/* Send the buffer back up to the previous level. */
#ifdef CONFIG_AUDIO_MULTI_SESSION
priv->dev.upper(priv->dev.priv, AUDIO_CALLBACK_DEQUEUE, apb, OK, NULL);
#else
priv->dev.upper(priv->dev.priv, AUDIO_CALLBACK_DEQUEUE, apb, OK);
#endif
flags = spin_lock_irqsave(NULL);
}
spin_unlock_irqrestore(NULL, flags);
}
/****************************************************************************
* Name: wm8776_sendbuffer
*
* Description:
* Start the transfer an audio buffer to the WM8776 via I2S. This
* will not wait for the transfer to complete but will return immediately.
* the wmd8776_senddone called will be invoked when the transfer
* completes, stimulating the worker thread to call this function again.
*
****************************************************************************/
static int wm8776_sendbuffer(FAR struct wm8776_dev_s *priv)
{
FAR struct ap_buffer_s *apb;
irqstate_t flags;
uint32_t timeout;
int shift;
int ret;
/* Loop while there are audio buffers to be sent and we have few than
* CONFIG_WM8776_INFLIGHT then "in-flight"
*
* The 'inflight' value might be modified from the interrupt level in some
* implementations. We will use interrupt controls to protect against
* that possibility.
*
* The 'pendq', on the other hand, is protected via a semaphore. Let's
* hold the semaphore while we are busy here and disable the interrupts
* only while accessing 'inflight'.
*/
ret = nxmutex_lock(&priv->pendlock);
if (ret < 0)
{
return ret;
}
while (priv->inflight < CONFIG_WM8776_INFLIGHT &&
dq_peek(&priv->pendq) != NULL && !priv->paused)
{
/* Take next buffer from the queue of pending transfers */
apb = (FAR struct ap_buffer_s *)dq_remfirst(&priv->pendq);
audinfo("Sending apb=%p, size=%d inflight=%d\n",
apb, apb->nbytes, priv->inflight);
/* Increment the number of buffers in-flight before sending in order
* to avoid a possible race condition.
*/
flags = spin_lock_irqsave(NULL);
priv->inflight++;
spin_unlock_irqrestore(NULL, flags);
shift = (priv->bpsamp == 8) ? 14 - 3 : 14 - 4;
shift -= (priv->nchannels > 1) ? 1 : 0;
timeout = MSEC2TICK(((uint32_t)(apb->nbytes - apb->curbyte) << shift) /
(uint32_t)priv->samprate);
ret = I2S_SEND(priv->i2s, apb, wm8776_senddone, priv, timeout);
if (ret < 0)
{
auderr("ERROR: I2S_SEND failed: %d\n", ret);
break;
}
}
nxmutex_unlock(&priv->pendlock);
return ret;
}
/****************************************************************************
* Name: wm8776_start
*
* Description:
* Start the configured operation (audio streaming, volume enabled, etc.).
*
****************************************************************************/
#ifdef CONFIG_AUDIO_MULTI_SESSION
static int wm8776_start(FAR struct audio_lowerhalf_s *dev, FAR void *session)
#else
static int wm8776_start(FAR struct audio_lowerhalf_s *dev)
#endif
{
FAR struct wm8776_dev_s *priv = (FAR struct wm8776_dev_s *)dev;
struct sched_param sparam;
struct mq_attr attr;
pthread_attr_t tattr;
FAR void *value;
int ret;
audinfo("Entry\n");
/* Exit reduced power modes of operation */
/* REVISIT */
/* Create a message queue for the worker thread */
snprintf(priv->mqname, sizeof(priv->mqname), "/tmp/%" PRIXPTR,
(uintptr_t)priv);
attr.mq_maxmsg = 16;
attr.mq_msgsize = sizeof(struct audio_msg_s);
attr.mq_curmsgs = 0;
attr.mq_flags = 0;
ret = file_mq_open(&priv->mq, priv->mqname,
O_RDWR | O_CREAT, 0644, &attr);
if (ret < 0)
{
/* Error creating message queue! */
auderr("ERROR: Couldn't allocate message queue\n");
return -ENOMEM;
}
/* Join any old worker thread we had created to prevent a memory leak */
if (priv->threadid != 0)
{
audinfo("Joining old thread\n");
pthread_join(priv->threadid, &value);
}
/* Start our thread for sending data to the device */
pthread_attr_init(&tattr);
sparam.sched_priority = sched_get_priority_max(SCHED_FIFO) - 3;
pthread_attr_setschedparam(&tattr, &sparam);
pthread_attr_setstacksize(&tattr, CONFIG_WM8776_WORKER_STACKSIZE);
audinfo("Starting worker thread\n");
ret = pthread_create(&priv->threadid, &tattr, wm8776_workerthread,
(pthread_addr_t)priv);
if (ret != OK)
{
auderr("ERROR: pthread_create failed: %d\n", ret);
}
else
{
pthread_setname_np(priv->threadid, "wm8776");
audinfo("Created worker thread\n");
}
return ret;
}
/****************************************************************************
* Name: wm8776_stop
*
* Description: Stop the configured operation (audio streaming, volume
* disabled, etc.).
*
****************************************************************************/
#ifndef CONFIG_AUDIO_EXCLUDE_STOP
#ifdef CONFIG_AUDIO_MULTI_SESSION
static int wm8776_stop(FAR struct audio_lowerhalf_s *dev, FAR void *session)
#else
static int wm8776_stop(FAR struct audio_lowerhalf_s *dev)
#endif
{
FAR struct wm8776_dev_s *priv = (FAR struct wm8776_dev_s *)dev;
struct audio_msg_s term_msg;
FAR void *value;
/* Send a message to stop all audio streaming */
term_msg.msg_id = AUDIO_MSG_STOP;
term_msg.u.data = 0;
file_mq_send(&priv->mq, (FAR const char *)&term_msg, sizeof(term_msg),
CONFIG_WM8776_MSG_PRIO);
/* Join the worker thread */
pthread_join(priv->threadid, &value);
priv->threadid = 0;
/* Enter into a reduced power usage mode */
/* REVISIT: */
return OK;
}
#endif
/****************************************************************************
* Name: wm8776_pause
*
* Description: Pauses the playback.
*
****************************************************************************/
#ifndef CONFIG_AUDIO_EXCLUDE_PAUSE_RESUME
#ifdef CONFIG_AUDIO_MULTI_SESSION
static int wm8776_pause(FAR struct audio_lowerhalf_s *dev, FAR void *session)
#else
static int wm8776_pause(FAR struct audio_lowerhalf_s *dev)
#endif
{
FAR struct wm8776_dev_s *priv = (FAR struct wm8776_dev_s *)dev;
if (priv->running && !priv->paused)
{
priv->paused = true;
wm8776_setvolume(priv, priv->volume, true);
}
return OK;
}
#endif /* CONFIG_AUDIO_EXCLUDE_PAUSE_RESUME */
/****************************************************************************
* Name: wm8776_resume
*
* Description: Resumes the playback.
*
****************************************************************************/
#ifndef CONFIG_AUDIO_EXCLUDE_PAUSE_RESUME
#ifdef CONFIG_AUDIO_MULTI_SESSION
static int wm8776_resume(FAR struct audio_lowerhalf_s *dev,
FAR void *session)
#else
static int wm8776_resume(FAR struct audio_lowerhalf_s *dev)
#endif
{
FAR struct wm8776_dev_s *priv = (FAR struct wm8776_dev_s *)dev;
if (priv->running && priv->paused)
{
priv->paused = false;
wm8776_setvolume(priv, priv->volume, false);
wm8776_sendbuffer(priv);
}
return OK;
}
#endif /* CONFIG_AUDIO_EXCLUDE_PAUSE_RESUME */
/****************************************************************************
* Name: wm8776_enqueuebuffer
*
* Description: Enqueue an Audio Pipeline Buffer for playback/ processing.
*
****************************************************************************/
static int wm8776_enqueuebuffer(FAR struct audio_lowerhalf_s *dev,
FAR struct ap_buffer_s *apb)
{
FAR struct wm8776_dev_s *priv = (FAR struct wm8776_dev_s *)dev;
struct audio_msg_s term_msg;
int ret;
audinfo("Enqueueing: apb=%p curbyte=%d nbytes=%d flags=%04x\n",
apb, apb->curbyte, apb->nbytes, apb->flags);
/* Take a reference on the new audio buffer */
apb_reference(apb);
/* Add the new buffer to the tail of pending audio buffers */
ret = nxmutex_lock(&priv->pendlock);
if (ret < 0)
{
return ret;
}
apb->flags |= AUDIO_APB_OUTPUT_ENQUEUED;
dq_addlast(&apb->dq_entry, &priv->pendq);
nxmutex_unlock(&priv->pendlock);
/* Send a message to the worker thread indicating that a new buffer has
* been enqueued. If mq is NULL, then the playing has not yet started.
* In that case we are just "priming the pump" and we don't need to send
* any message.
*/
ret = OK;
if (priv->mq.f_inode != NULL)
{
term_msg.msg_id = AUDIO_MSG_ENQUEUE;
term_msg.u.data = 0;
ret = file_mq_send(&priv->mq, (FAR const char *)&term_msg,
sizeof(term_msg), CONFIG_WM8776_MSG_PRIO);
if (ret < 0)
{
auderr("ERROR: file_mq_send failed: %d\n", ret);
}
}
return ret;
}
/****************************************************************************
* Name: wm8776_cancelbuffer
*
* Description: Called when an enqueued buffer is being cancelled.
*
****************************************************************************/
static int wm8776_cancelbuffer(FAR struct audio_lowerhalf_s *dev,
FAR struct ap_buffer_s *apb)
{
audinfo("apb=%p\n", apb);
return OK;
}
/****************************************************************************
* Name: wm8776_ioctl
*
* Description: Perform a device ioctl
*
****************************************************************************/
static int wm8776_ioctl(FAR struct audio_lowerhalf_s *dev, int cmd,
unsigned long arg)
{
int ret = OK;
#ifdef CONFIG_AUDIO_DRIVER_SPECIFIC_BUFFERS
FAR struct ap_buffer_info_s *bufinfo;
#endif
/* Deal with ioctls passed from the upper-half driver */
switch (cmd)
{
/* Check for AUDIOIOC_HWRESET ioctl. This ioctl is passed straight
* through from the upper-half audio driver.
*/
case AUDIOIOC_HWRESET:
{
/* REVISIT: Should we completely re-initialize the chip? We
* can't just issue a software reset; that would puts all WM8776
* registers back in their default state.
*/
audinfo("AUDIOIOC_HWRESET:\n");
}
break;
/* Report our preferred buffer size and quantity */
#ifdef CONFIG_AUDIO_DRIVER_SPECIFIC_BUFFERS
case AUDIOIOC_GETBUFFERINFO:
{
audinfo("AUDIOIOC_GETBUFFERINFO:\n");
bufinfo = (FAR struct ap_buffer_info_s *) arg;
bufinfo->buffer_size = CONFIG_WM8776_BUFFER_SIZE;
bufinfo->nbuffers = CONFIG_WM8776_NUM_BUFFERS;
}
break;
#endif
default:
ret = -ENOTTY;
audinfo("Ignored\n");
break;
}
return ret;
}
/****************************************************************************
* Name: wm8776_reserve
*
* Description: Reserves a session (the only one we have).
*
****************************************************************************/
#ifdef CONFIG_AUDIO_MULTI_SESSION
static int wm8776_reserve(FAR struct audio_lowerhalf_s *dev,
FAR void **session)
#else
static int wm8776_reserve(FAR struct audio_lowerhalf_s *dev)
#endif
{
FAR struct wm8776_dev_s *priv = (FAR struct wm8776_dev_s *) dev;
int ret = OK;
/* Borrow the APBQ mutex for thread sync */
ret = nxmutex_lock(&priv->pendlock);
if (ret < 0)
{
return ret;
}
if (priv->reserved)
{
ret = -EBUSY;
}
else
{
/* Initialize the session context */
#ifdef CONFIG_AUDIO_MULTI_SESSION
*session = NULL;
#endif
priv->inflight = 0;
priv->running = false;
priv->paused = false;
#ifndef CONFIG_AUDIO_EXCLUDE_STOP
priv->terminating = false;
#endif
priv->reserved = true;
}
nxmutex_unlock(&priv->pendlock);
return ret;
}
/****************************************************************************
* Name: wm8776_release
*
* Description: Releases the session (the only one we have).
*
****************************************************************************/
#ifdef CONFIG_AUDIO_MULTI_SESSION
static int wm8776_release(FAR struct audio_lowerhalf_s *dev,
FAR void *session)
#else
static int wm8776_release(FAR struct audio_lowerhalf_s *dev)
#endif
{
FAR struct wm8776_dev_s *priv = (FAR struct wm8776_dev_s *)dev;
FAR void *value;
int ret;
/* Join any old worker thread we had created to prevent a memory leak */
if (priv->threadid != 0)
{
pthread_join(priv->threadid, &value);
priv->threadid = 0;
}
/* Borrow the APBQ mutex for thread sync */
ret = nxmutex_lock(&priv->pendlock);
/* Really we should free any queued buffers here */
priv->reserved = false;
nxmutex_unlock(&priv->pendlock);
return ret;
}
/****************************************************************************
* Name: wm8776_audio_output
*
* Description:
* Initialize and configure the WM8776 device as an audio output device.
*
* Input Parameters:
* priv - A reference to the driver state structure
*
* Returned Value:
* None. No failures are detected.
*
****************************************************************************/
static void wm8776_audio_output(FAR struct wm8776_dev_s *priv)
{
wm8776_writereg(priv, WM8776_MASTER_ATT,
WM8776_UPDATE | 0x58); /* -33db */
wm8776_writereg(priv, WM8776_DAC_IF, 0x32); /* 32bit, I2S, standard pol */
#ifdef CONFIG_WM8776_SWAP_HPOUT
wm8776_writereg(priv, WM8776_DAC_CC, 0x62); /* Swap HPOUT L/R */
#endif
wm8776_writereg(priv, WM8776_MASTER_MODE, 0x00); /* slave mode, 128fs */
wm8776_writereg(priv, WM8776_PWR_DOWN, 0x12); /* AINPD, ADCPD */
}
/****************************************************************************
* Name: wm8776_hw_reset
*
* Description:
* Reset and re-initialize the WM8776
*
* Input Parameters:
* priv - A reference to the driver state structure
*
* Returned Value:
* None
*
****************************************************************************/
static void wm8776_hw_reset(FAR struct wm8776_dev_s *priv)
{
/* Put audio output back to its initial configuration */
priv->samprate = WM8776_DEFAULT_SAMPRATE;
priv->nchannels = WM8776_DEFAULT_NCHANNELS;
priv->bpsamp = WM8776_DEFAULT_BPSAMP;
#if !defined(CONFIG_AUDIO_EXCLUDE_VOLUME) && !defined(CONFIG_AUDIO_EXCLUDE_BALANCE)
priv->balance = b16HALF; /* Center balance */
#endif
/* Software reset. This puts all WM8776 registers back in their
* default state.
*/
wm8776_writereg(priv, WM8776_SOFT_RESET, 0x00);
/* Configure the WM8776 hardware as an audio input device */
wm8776_audio_output(priv);
}
/****************************************************************************
* Name: wm8776_workerthread
*
* This is the thread that feeds data to the chip and keeps the audio
* stream going.
*
****************************************************************************/
static void *wm8776_workerthread(pthread_addr_t pvarg)
{
FAR struct wm8776_dev_s *priv = (struct wm8776_dev_s *) pvarg;
struct audio_msg_s msg;
FAR struct ap_buffer_s *apb;
int msglen;
unsigned int prio;
struct mq_attr attr;
audinfo("Entry\n");
#ifndef CONFIG_AUDIO_EXCLUDE_STOP
priv->terminating = false;
#endif
priv->running = true;
wm8776_setvolume(priv, priv->volume, false);
/* Loop as long as we are supposed to be running and as long as we have
* buffers in-flight.
*/
while (priv->running || priv->inflight > 0)
{
/* Check if we have been asked to terminate. We have to check if we
* still have buffers in-flight. If we do, then we can't stop until
* birds come back to roost.
*/
if (priv->terminating && priv->inflight <= 0)
{
/* We are IDLE. Break out of the loop and exit. */
break;
}
else
{
/* Check if we can send more audio buffers to the WM8776 */
wm8776_sendbuffer(priv);
}
repeat:
/* Wait for messages from our message queue */
msglen = file_mq_receive(&priv->mq, (FAR char *)&msg,
sizeof(msg), &prio);
/* Handle the case when we return with no message */
if (msglen < sizeof(struct audio_msg_s))
{
auderr("ERROR: Message too small: %d\n", msglen);
continue;
}
/* Process the message */
switch (msg.msg_id)
{
/* The ISR has requested more data. We will catch this case at
* the top of the loop.
*/
case AUDIO_MSG_DATA_REQUEST:
audinfo("AUDIO_MSG_DATA_REQUEST\n");
break;
/* Stop the playback */
#ifndef CONFIG_AUDIO_EXCLUDE_STOP
case AUDIO_MSG_STOP:
/* Indicate that we are terminating */
audinfo("AUDIO_MSG_STOP: Terminating\n");
priv->terminating = true;
break;
#endif
/* We have a new buffer to send. We will catch this case at
* the top of the loop.
*/
case AUDIO_MSG_ENQUEUE:
audinfo("AUDIO_MSG_ENQUEUE\n");
break;
/* We will wake up from the I2S callback with this message */
case AUDIO_MSG_COMPLETE:
audinfo("AUDIO_MSG_COMPLETE\n");
wm8776_returnbuffers(priv);
break;
default:
auderr("ERROR: Ignoring message ID %d\n", msg.msg_id);
break;
}
file_mq_getattr(&priv->mq, &attr);
/* If there is a message in the queue, process it */
if (0 < attr.mq_curmsgs)
{
goto repeat;
}
}
/* Reset the WM8776 hardware */
wm8776_hw_reset(priv);
/* Return any pending buffers in our pending queue */
nxmutex_lock(&priv->pendlock);
while ((apb = (FAR struct ap_buffer_s *)dq_remfirst(&priv->pendq)) != NULL)
{
/* Release our reference to the buffer */
apb_free(apb);
/* Send the buffer back up to the previous level. */
#ifdef CONFIG_AUDIO_MULTI_SESSION
priv->dev.upper(priv->dev.priv, AUDIO_CALLBACK_DEQUEUE, apb, OK, NULL);
#else
priv->dev.upper(priv->dev.priv, AUDIO_CALLBACK_DEQUEUE, apb, OK);
#endif
}
nxmutex_unlock(&priv->pendlock);
/* Return any pending buffers in our done queue */
wm8776_returnbuffers(priv);
/* Close the message queue */
file_mq_close(&priv->mq);
file_mq_unlink(priv->mqname);
/* Send an AUDIO_MSG_COMPLETE message to the client */
#ifdef CONFIG_AUDIO_MULTI_SESSION
priv->dev.upper(priv->dev.priv, AUDIO_CALLBACK_COMPLETE, NULL, OK, NULL);
#else
priv->dev.upper(priv->dev.priv, AUDIO_CALLBACK_COMPLETE, NULL, OK);
#endif
audinfo("Exit\n");
return NULL;
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: wm8776_initialize
*
* Description:
* Initialize the WM8776 device.
*
* Input Parameters:
* i2c - An I2C driver instance
* i2s - An I2S driver instance
* lower - Persistent board configuration data
*
* Returned Value:
* A new lower half audio interface for the WM8776 device is returned on
* success; NULL is returned on failure.
*
****************************************************************************/
FAR struct audio_lowerhalf_s *
wm8776_initialize(FAR struct i2c_master_s *i2c,
FAR struct i2s_dev_s *i2s,
FAR const struct wm8776_lower_s *lower)
{
FAR struct wm8776_dev_s *priv;
/* Sanity check */
DEBUGASSERT(i2c && i2s && lower);
/* Allocate a WM8776 device structure */
priv = (FAR struct wm8776_dev_s *)kmm_zalloc(sizeof(struct wm8776_dev_s));
if (priv)
{
priv->dev.ops = &g_audioops;
priv->lower = lower;
priv->i2c = i2c;
priv->i2s = i2s;
nxmutex_init(&priv->pendlock);
dq_init(&priv->pendq);
dq_init(&priv->doneq);
/* Reset and reconfigure the WM8776 hardwaqre */
wm8776_hw_reset(priv);
return &priv->dev;
}
return NULL;
}
|
352dabb27c986c81577b1781bf41bacf698698a1
|
4ba76056c744ada0a01fb27b7cad8464cefc7aa0
|
/supports/toolchains/LiveEditor/PainterEngine_Resource_import_traw.h
|
5f9b4ebd72d3f41fa57b04c1feda4ccc32431a6c
|
[
"BSD-3-Clause"
] |
permissive
|
matrixcascade/PainterEngine
|
23e110e25a39e1d016ed7936eac23e06932456b4
|
1d3e6e85f337e8a8db44680094ab3f4b988507cb
|
refs/heads/master
| 2023-08-29T11:29:26.934779
| 2023-08-23T09:23:04
| 2023-08-23T09:23:04
| 190,119,926
| 1,989
| 253
|
BSD-3-Clause
| 2023-09-05T12:19:31
| 2019-06-04T03:08:26
|
C
|
UTF-8
|
C
| false
| false
| 6,642
|
h
|
PainterEngine_Resource_import_traw.h
|
static char const import_traw[]={0x54,0x52,0x41,0x57,0x14,0x0,0x0,0x0,0x14,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x61,0x0,0x0,0x0,0xec,0x0,0x0,0x0,0xec,0x0,0x0,0x0,0xea,0x0,0x0,0x0,0xe3,0x0,0x0,0x0,0xe1,0x0,0x0,0x0,0xf1,0x0,0x0,0x0,0xd7,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x22,0x0,0x0,0x0,0x5d,0x0,0x0,0x0,0x5d,0x0,0x0,0x0,0x55,0x0,0x0,0x0,0x46,0x0,0x0,0x0,0xca,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xf9,0x0,0x0,0x0,0x18,0x0,0x0,0x0,0x73,0x0,0x0,0x0,0x93,0x0,0x0,0x0,0x90,0x0,0x0,0x0,0x8f,0x0,0x0,0x0,0x8f,0x0,0x0,0x0,0x8f,0x0,0x0,0x0,0x9a,0x0,0x0,0x0,0x57,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x6c,0x0,0x0,0x0,0xed,0x0,0x0,0x0,0xc6,0x0,0x0,0x0,0xe1,0x0,0x0,0x0,0xbd,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0xcd,0x0,0x0,0x0,0xc3,0x0,0x0,0x0,0xc7,0x0,0x0,0x0,0xc7,0x0,0x0,0x0,0xc8,0x0,0x0,0x0,0xd6,0x0,0x0,0x0,0x78,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x80,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0x65,0x0,0x0,0x0,0x43,0x0,0x0,0x0,0xe3,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0x89,0x0,0x0,0x0,0xd,0x0,0x0,0x0,0xb,0x0,0x0,0x0,0xc,0x0,0x0,0x0,0xc,0x0,0x0,0x0,0xc,0x0,0x0,0x0,0xd,0x0,0x0,0x0,0x6,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x84,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0x7d,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x4d,0x0,0x0,0x0,0xec,0x0,0x0,0x0,0xed,0x0,0x0,0x0,0x53,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x82,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0x7f,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x5f,0x0,0x0,0x0,0xfc,0x0,0x0,0x0,0xeb,0x0,0x0,0x0,0x59,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x7e,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0x7c,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x3c,0x0,0x0,0x0,0xab,0x0,0x0,0x0,0xeb,0x0,0x0,0x0,0x5a,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x7d,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0x77,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x3,0x0,0x0,0x0,0xeb,0x0,0x0,0x0,0x5a,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x3,0x0,0x0,0x0,0x81,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0x7a,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xeb,0x0,0x0,0x0,0x5a,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x70,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0x7e,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xeb,0x0,0x0,0x0,0x5a,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x5c,0x0,0x0,0x0,0x6e,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x2,0x0,0x0,0x0,0x3b,0x0,0x0,0x0,0x2c,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xeb,0x0,0x0,0x0,0x5a,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xa,0x0,0x0,0x0,0xc4,0x0,0x0,0x0,0x90,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xeb,0x0,0x0,0x0,0x5a,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xb,0x0,0x0,0x0,0xc9,0x0,0x0,0x0,0x93,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xeb,0x0,0x0,0x0,0x5a,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xb,0x0,0x0,0x0,0xc6,0x0,0x0,0x0,0x91,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xeb,0x0,0x0,0x0,0x5a,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xb,0x0,0x0,0x0,0xc6,0x0,0x0,0x0,0x91,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xeb,0x0,0x0,0x0,0x5a,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xb,0x0,0x0,0x0,0xc6,0x0,0x0,0x0,0x91,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xea,0x0,0x0,0x0,0x56,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x9,0x0,0x0,0x0,0xc2,0x0,0x0,0x0,0x92,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xf3,0x0,0x0,0x0,0x57,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xcd,0x0,0x0,0x0,0x95,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xee,0x0,0x0,0x0,0xcc,0x0,0x0,0x0,0x5c,0x0,0x0,0x0,0x54,0x0,0x0,0x0,0x58,0x0,0x0,0x0,0x58,0x0,0x0,0x0,0x58,0x0,0x0,0x0,0x58,0x0,0x0,0x0,0x58,0x0,0x0,0x0,0x58,0x0,0x0,0x0,0x58,0x0,0x0,0x0,0x58,0x0,0x0,0x0,0x58,0x0,0x0,0x0,0x57,0x0,0x0,0x0,0x54,0x0,0x0,0x0,0x87,0x0,0x0,0x0,0xff,0x0,0x0,0x0,0x74,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x6e,0x0,0x0,0x0,0xef,0x0,0x0,0x0,0xec,0x0,0x0,0x0,0xe9,0x0,0x0,0x0,0xea,0x0,0x0,0x0,0xea,0x0,0x0,0x0,0xea,0x0,0x0,0x0,0xea,0x0,0x0,0x0,0xea,0x0,0x0,0x0,0xea,0x0,0x0,0x0,0xea,0x0,0x0,0x0,0xea,0x0,0x0,0x0,0xea,0x0,0x0,0x0,0xea,0x0,0x0,0x0,0xe9,0x0,0x0,0x0,0xf7,0x0,0x0,0x0,0xbe,0x0,0x0,0x0,0x1a,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,};
|
3df3cdb8ab8335ec260aed54c01f957708438cc2
|
ea401c3e792a50364fe11f7cea0f35f99e8f4bde
|
/released_plugins/v3d_plugins/neurontracing_neutube/src_neutube/neurolabi/gui/ztreeiterator.h
|
d630304f91659399ec0028edd516b43790cfb417
|
[
"GPL-1.0-or-later",
"LicenseRef-scancode-unknown-license-reference",
"GPL-2.0-only",
"BSD-2-Clause",
"MIT"
] |
permissive
|
Vaa3D/vaa3d_tools
|
edb696aa3b9b59acaf83d6d27c6ae0a14bf75fe9
|
e6974d5223ae70474efaa85e1253f5df1814fae8
|
refs/heads/master
| 2023-08-03T06:12:01.013752
| 2023-08-02T07:26:01
| 2023-08-02T07:26:01
| 50,527,925
| 107
| 86
|
MIT
| 2023-05-22T23:43:48
| 2016-01-27T18:19:17
|
C++
|
UTF-8
|
C
| false
| false
| 77
|
h
|
ztreeiterator.h
|
#ifndef ZTREEITERATOR_H
#define ZTREEITERATOR_H
#endif // ZTREEITERATOR_H
|
bb4ad15fa1fe06c377633444218b8c8cbca40968
|
48c3101da2a27e0d46086b51f67f9a96a17ced68
|
/cpp/log.h
|
bb4a7b251392b9629b477e287395dfa2ac34207b
|
[
"ISC"
] |
permissive
|
jlguenego/node-expose-sspi
|
5e5aead713ab5fc342cbd9b9e342eda7ce996ff6
|
ebbe3046e6b346ee7cf9cfd6c6d0dc3b72fb115e
|
refs/heads/master
| 2023-01-24T02:51:22.270949
| 2023-01-18T11:39:59
| 2023-01-18T11:39:59
| 234,580,010
| 114
| 22
|
ISC
| 2023-01-18T11:40:00
| 2020-01-17T15:44:04
|
C++
|
UTF-8
|
C
| false
| false
| 402
|
h
|
log.h
|
#pragma once
#include <winsock.h>
#define SECURITY_WIN32
#include <sspi.h>
void log(const char* format, ...);
void logSecPkgInfo(PSecPkgInfo pSecPkgInfo);
void logHandle(const char* prefix, SecHandle* sec);
void logSecBufferDesc(const char* pBuffer, SecBufferDesc* pSecBufferDesc);
void logSecBuffer(const char* pBuffer, SecBuffer* pSecBuffer);
void PrintHexDump(DWORD length, const BYTE* buffer);
|
ad83e1df18b40b34476f4f74c4c54b0b9e722d84
|
39bcafc5f6b1672f31f0f6ea9c8d6047ee432950
|
/extension/tpcds/dsdgen/include/dsdgen-c/tpcds.idx.h
|
27b66260c90d746c93fa4462c985cff76653ab24
|
[
"MIT"
] |
permissive
|
duckdb/duckdb
|
315270af6b198d26eb41a20fc7a0eda04aeef294
|
f89ccfe0ec01eb613af9c8ac7c264a5ef86d7c3a
|
refs/heads/main
| 2023-09-05T08:14:21.278345
| 2023-09-05T07:28:59
| 2023-09-05T07:28:59
| 138,754,790
| 8,964
| 986
|
MIT
| 2023-09-14T18:42:49
| 2018-06-26T15:04:45
|
C++
|
UTF-8
|
C
| false
| false
| 7,342
|
h
|
tpcds.idx.h
|
/*
THIS IS AN AUTOMATICALLY GENERATED FILE
DO NOT EDIT
See distcomp.c for details
*/
/* aliases for values/weights in the first_names distribution */
#define first_names_name 1
#define first_names_male 1
#define first_names_female 2
#define first_names_unified 3
/* aliases for values/weights in the last_names distribution */
/* NONE DEFINED */
/* aliases for values/weights in the calendar distribution */
#define calendar_day_seq 1
#define calendar_month_name 2
#define calendar_date 3
#define calendar_season 4
#define calendar_month_num 5
#define calendar_quarter 6
#define calendar_fom 7
#define calendar_holiday 8
#define calendar_uniform 1
#define calendar_uniform_leap 2
#define calendar_sales 3
#define calendar_sales_leap 4
#define calendar_returns 5
#define calendar_returns_leap 6
#define calendar_skewed 7
#define calendar_low 8
#define calendar_medium 9
#define calendar_high 10
/* aliases for values/weights in the week_info distribution */
/* NONE DEFINED */
/* aliases for values/weights in the fips_county distribution */
#define fips_county_fips 1
#define fips_county_county 2
#define fips_county_st 3
#define fips_county_state 4
#define fips_county_zone 5
#define fips_county_gmt 6
#define fips_county_uniform 1
#define fips_county_population 2
#define fips_county_tz 3
#define fips_county_tz90 4
#define fips_county_tz9 5
#define fips_county_tz1 6
/* aliases for values/weights in the street_names distribution */
/* NONE DEFINED */
/* aliases for values/weights in the street_type distribution */
/* NONE DEFINED */
/* aliases for values/weights in the adjectives distribution */
/* NONE DEFINED */
/* aliases for values/weights in the adverbs distribution */
/* NONE DEFINED */
/* aliases for values/weights in the articles distribution */
/* NONE DEFINED */
/* aliases for values/weights in the nouns distribution */
/* NONE DEFINED */
/* aliases for values/weights in the prepositions distribution */
/* NONE DEFINED */
/* aliases for values/weights in the verbs distribution */
/* NONE DEFINED */
/* aliases for values/weights in the auxiliaries distribution */
/* NONE DEFINED */
/* aliases for values/weights in the terminators distribution */
/* NONE DEFINED */
/* aliases for values/weights in the sentences distribution */
/* NONE DEFINED */
/* aliases for values/weights in the syllables distribution */
/* NONE DEFINED */
/* aliases for values/weights in the cities distribution */
#define cities_name 1
#define cities_usgs 1
#define cities_uniform 2
#define cities_large 3
#define cities_medium 4
#define cities_small 5
#define cities_unified 6
/* aliases for values/weights in the categories distribution */
/* NONE DEFINED */
/* aliases for values/weights in the women_class distribution */
/* NONE DEFINED */
/* aliases for values/weights in the men_class distribution */
/* NONE DEFINED */
/* aliases for values/weights in the children_class distribution */
/* NONE DEFINED */
/* aliases for values/weights in the shoe_class distribution */
/* NONE DEFINED */
/* aliases for values/weights in the music_class distribution */
/* NONE DEFINED */
/* aliases for values/weights in the jewelry_class distribution */
/* NONE DEFINED */
/* aliases for values/weights in the home_class distribution */
/* NONE DEFINED */
/* aliases for values/weights in the sport_class distribution */
/* NONE DEFINED */
/* aliases for values/weights in the book_class distribution */
/* NONE DEFINED */
/* aliases for values/weights in the electronic_class distribution */
/* NONE DEFINED */
/* aliases for values/weights in the sizes distribution */
/* NONE DEFINED */
/* aliases for values/weights in the units distribution */
/* NONE DEFINED */
/* aliases for values/weights in the container distribution */
/* NONE DEFINED */
/* aliases for values/weights in the colors distribution */
#define colors_name 1
#define colors_uniform 1
#define colors_skewed 2
#define colors_low 3
#define colors_medium 4
#define colors_high 5
/* aliases for values/weights in the brand_syllables distribution */
/* NONE DEFINED */
/* aliases for values/weights in the i_current_price distribution */
#define i_current_price_index 1
#define i_current_price_low_bound 2
#define i_current_price_high_bound 3
#define i_current_price_skew 1
#define i_current_price_high 2
#define i_current_price_medium 3
#define i_current_price_low 4
/* aliases for values/weights in the i_manufact_id distribution */
/* NONE DEFINED */
/* aliases for values/weights in the i_manager_id distribution */
/* NONE DEFINED */
/* aliases for values/weights in the rowcounts distribution */
/* NONE DEFINED */
/* aliases for values/weights in the gender distribution */
/* NONE DEFINED */
/* aliases for values/weights in the marital_status distribution */
/* NONE DEFINED */
/* aliases for values/weights in the education distribution */
/* NONE DEFINED */
/* aliases for values/weights in the purchase_band distribution */
/* NONE DEFINED */
/* aliases for values/weights in the buy_potential distribution */
/* NONE DEFINED */
/* aliases for values/weights in the credit_rating distribution */
/* NONE DEFINED */
/* aliases for values/weights in the income_band distribution */
/* NONE DEFINED */
/* aliases for values/weights in the dependent_count distribution */
/* NONE DEFINED */
/* aliases for values/weights in the vehicle_count distribution */
/* NONE DEFINED */
/* aliases for values/weights in the promo_purpose distribution */
/* NONE DEFINED */
/* aliases for values/weights in the return_reasons distribution */
/* NONE DEFINED */
/* aliases for values/weights in the store_type distribution */
/* NONE DEFINED */
/* aliases for values/weights in the geography_class distribution */
/* NONE DEFINED */
/* aliases for values/weights in the divisions distribution */
/* NONE DEFINED */
/* aliases for values/weights in the stores distribution */
/* NONE DEFINED */
/* aliases for values/weights in the hours distribution */
/* NONE DEFINED */
/* aliases for values/weights in the call_centers distribution */
/* NONE DEFINED */
/* aliases for values/weights in the call_center_hours distribution */
/* NONE DEFINED */
/* aliases for values/weights in the call_center_class distribution */
/* NONE DEFINED */
/* aliases for values/weights in the salutations distribution */
/* NONE DEFINED */
/* aliases for values/weights in the ship_mode_code distribution */
/* NONE DEFINED */
/* aliases for values/weights in the ship_mode_type distribution */
/* NONE DEFINED */
/* aliases for values/weights in the ship_mode_carrier distribution */
/* NONE DEFINED */
/* aliases for values/weights in the web_page_use distribution */
/* NONE DEFINED */
/* aliases for values/weights in the web_page_type distribution */
/* NONE DEFINED */
/* aliases for values/weights in the catalog_page_type distribution */
/* NONE DEFINED */
/* aliases for values/weights in the location_type distribution */
/* NONE DEFINED */
/* aliases for values/weights in the top_domains distribution */
/* NONE DEFINED */
/* aliases for values/weights in the countries distribution */
/* NONE DEFINED */
|
c7e784ba608e767a16f1605830b691e725ab0bbd
|
ed98b77f3f09b392e68a0d59c48eec299e883bb9
|
/examples/GMI/doc/xternal_gmi.c
|
d17f32e883cddd35bf5424b6a366d38275e9ee07
|
[
"Apache-2.0"
] |
permissive
|
scipopt/scip
|
c8ddbe7cdec0a3af5a230c04b74b76ffacbdcc33
|
dc856a4c966ea50bd5f52c58d7be4fea33706f4c
|
refs/heads/master
| 2023-08-19T11:39:12.578790
| 2023-08-15T20:05:58
| 2023-08-15T20:05:58
| 342,522,859
| 262
| 46
|
NOASSERTION
| 2023-08-03T07:37:45
| 2021-02-26T09:16:17
|
C
|
UTF-8
|
C
| false
| false
| 2,891
|
c
|
xternal_gmi.c
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* This file is part of the program and library */
/* SCIP --- Solving Constraint Integer Programs */
/* */
/* Copyright (c) 2002-2023 Zuse Institute Berlin (ZIB) */
/* */
/* 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. */
/* */
/* You should have received a copy of the Apache-2.0 license */
/* along with SCIP; see the file LICENSE. If not visit scipopt.org. */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/**@file xternal_gmi.c
* @brief main document page
* @author Marc Pfetsch
*/
/*--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
/**@page GMI_MAIN Gomory Mixed Integer Cut
* @version 1.0
* @author Giacomo Nannicini
* @author Marc Pfetsch
*
*
* This example provides a textbook implementation of Gomory mixed integer (GMI) cuts.
*
* The default implementation in SCIP does not produce GMI cuts in the strict sense, since it applies the CMIR function
* to the aggregated row. This function can, among other things, take variable bounds into account. Thus, the resulting
* cuts cannot be used for comparison with standard GMI cuts. This example remedies this situation.
*
* The implementation has been used in the paper
*
* G. Cornuejols, F. Margot and G. Nannicini:@n
* On the safety of Gomory cut generators.@n
* Math. Program. Comput. 5(4), 2013.
*
* Installation
* ------------
*
* See the @ref INSTALL_APPLICATIONS_EXAMPLES "Install file"
*/
|
76837169a90c1cc36793d1ac3fb9e711e26c9936
|
9ceacf33fd96913cac7ef15492c126d96cae6911
|
/lib/csu/mips64/boot_md.h
|
09fb17f4d6ff2872d7d4334284ecdb69c3776448
|
[] |
no_license
|
openbsd/src
|
ab97ef834fd2d5a7f6729814665e9782b586c130
|
9e79f3a0ebd11a25b4bff61e900cb6de9e7795e9
|
refs/heads/master
| 2023-09-02T18:54:56.624627
| 2023-09-02T15:16:12
| 2023-09-02T15:16:12
| 66,966,208
| 3,394
| 1,235
| null | 2023-08-08T02:42:25
| 2016-08-30T18:18:25
|
C
|
UTF-8
|
C
| false
| false
| 5,336
|
h
|
boot_md.h
|
/* $OpenBSD: boot_md.h,v 1.3 2022/10/27 19:40:23 deraadt Exp $ */
/*
* Copyright (c) 1998 Per Fogelstrom, Opsycon AB
*
* 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 ``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 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.
*
*/
/*
* IMPORTANT: any functions below are NOT protected by SSP. Please
* do not add anything except what is required to reach GOT with
* an adjustment.
*/
#define _DYN_LOADER
#include <sys/exec_elf.h>
#include <sys/mman.h>
#include <machine/reloc.h>
__dead
void _dl_exit(int);
#include "archdep.h"
/*
* Use the internal, hidden name for any syscalls we need, to avoid
* accidental override by application code
*/
#define REDIRECT_SYSCALL(x) typeof(x) x asm("_libc_"#x) __dso_hidden
REDIRECT_SYSCALL(mprotect);
REDIRECT_SYSCALL(mimmutable);
#define DT_PROC(n) ((n) - DT_LOPROC)
#if RELOC_TAG == DT_RELA
typedef Elf_RelA RELOC_TYPE;
#elif RELOC_TAG == DT_REL
typedef Elf_Rel RELOC_TYPE;
#else
# error "unknown RELOC_TAG"
#endif
/* The set of dynamic tags that we're interested in for bootstrapping */
struct boot_dyn {
RELOC_TYPE *dt_reloc; /* DT_RELA or DT_REL */
Elf_Addr dt_relocsz; /* DT_RELASZ or DT_RELSZ */
Elf_Addr *dt_pltgot;
const Elf_Sym *dt_symtab;
u_long dt_proc[DT_PROCNUM];
};
static void *relro_addr;
static size_t relro_size;
#define RCRT0_RELRO() \
do { \
if (relro_addr != NULL && relro_size != 0) \
mprotect(relro_addr, relro_size, PROT_READ); \
mimmutable(relro_addr, relro_size); \
} while (0)
/*
* Local decls.
*/
void _dl_boot_bind(const long, long *, Elf_Dyn *);
void
_dl_boot_bind(const long sp, long *dl_data, Elf_Dyn *dynp)
{
struct boot_dyn dynld; /* Resolver data for the loader */
AuxInfo *auxstack;
long *stack;
int n, argc;
char **argv, **envp;
long loff;
RELOC_TYPE *rp;
Elf_Phdr *phdp;
Elf_Addr i;
/*
* Scan argument and environment vectors. Find dynamic
* data vector put after them.
*/
stack = (long *)sp;
argc = *stack++;
argv = (char **)stack;
envp = &argv[argc + 1];
stack = (long *)envp;
while (*stack++ != 0L)
;
/*
* Zero out dl_data.
*/
for (n = 0; n <= AUX_entry; n++)
dl_data[n] = 0;
/*
* Dig out auxiliary data set up by exec call. Move all known
* tags to an indexed local table for easy access.
*/
for (auxstack = (AuxInfo *)stack; auxstack->au_id != AUX_null;
auxstack++) {
if (auxstack->au_id > AUX_entry)
continue;
dl_data[auxstack->au_id] = auxstack->au_v;
}
loff = dl_data[AUX_base]; /* XXX assumes ld.so is linked at 0x0 */
/*
* We need to do 'selfreloc' in case the code weren't
* loaded at the address it was linked to.
*
* Scan the DYNAMIC section for the loader.
* Cache the data for easier access.
*/
_dl_memset(&dynld, 0, sizeof(dynld));
while (dynp->d_tag != DT_NULL) {
/* first the tags that are pointers to be relocated */
if (dynp->d_tag == DT_PLTGOT)
dynld.dt_pltgot = (void *)(dynp->d_un.d_ptr + loff);
else if (dynp->d_tag == DT_SYMTAB)
dynld.dt_symtab = (void *)(dynp->d_un.d_ptr + loff);
else if (dynp->d_tag == RELOC_TAG) /* DT_{RELA,REL} */
dynld.dt_reloc = (void *)(dynp->d_un.d_ptr + loff);
/* Now for the tags that are just sizes or counts */
else if (dynp->d_tag == RELOC_TAG+1) /* DT_{RELA,REL}SZ */
dynld.dt_relocsz = dynp->d_un.d_val;
else if (dynp->d_tag >= DT_LOPROC &&
dynp->d_tag < DT_LOPROC + DT_PROCNUM)
dynld.dt_proc[dynp->d_tag - DT_LOPROC] =
dynp->d_un.d_val;
dynp++;
}
rp = dynld.dt_reloc;
for (i = 0; i < dynld.dt_relocsz; i += sizeof *rp) {
Elf_Addr *ra;
const Elf_Sym *sp;
sp = dynld.dt_symtab + ELF_R_SYM(rp->r_info);
if (!ELF_R_SYM(rp->r_info) || sp->st_value != 0) {
ra = (Elf_Addr *)(rp->r_offset + loff);
RELOC_DYN(rp, sp, ra, loff);
}
rp++;
}
RELOC_GOT(&dynld, loff);
/* apply GNU_RELRO */
phdp = (Elf_Phdr *)dl_data[AUX_phdr];
for (i = 0; i < dl_data[AUX_phnum]; i++, phdp++) {
switch (phdp->p_type) {
case PT_GNU_RELRO:
relro_addr = (void *)(phdp->p_vaddr + loff);
relro_size = phdp->p_memsz;
/*
* GNU_RELRO (a) covers the GOT, and (b) comes after
* all LOAD sections, so if we found it then we're done
*/
break;
}
}
}
|
26835a4bee5c296af482febdd8a56cb22dbab110
|
4d317369bd7de599e0364e9097e50f381845e22c
|
/C Programs/C Programs - 7/Red_Blue_Balls.c
|
532690f2bb2c8d705c52a8fd9717e0c0f8741009
|
[] |
no_license
|
MathProgrammer/CodeForces
|
4865f0bad799c674ff9e6fde9a008b988af2aed0
|
e3483c1ac4a7c81662f6a0bc8af20be69e0c0a98
|
refs/heads/master
| 2023-04-07T11:27:31.766011
| 2023-04-01T06:29:19
| 2023-04-01T06:29:19
| 84,833,335
| 256
| 114
| null | 2021-10-02T21:14:47
| 2017-03-13T14:02:57
|
C++
|
UTF-8
|
C
| false
| false
| 393
|
c
|
Red_Blue_Balls.c
|
#include <stdio.h>
#define MAX_SIZE 50
int main()
{
long long equivalent_number = 0LL;
int no_of_balls, i;
char stack[MAX_SIZE + 1];
scanf("%d %s", &no_of_balls, stack);
for(i = 0; i < no_of_balls; i++)
if(stack[i] == 'B')
equivalent_number = equivalent_number| (1LL << i);
printf("%I64d\n",equivalent_number);
return 0;
}
|
c06d9edb580dddb60bdb26ecb3a54b2004913625
|
c8b39acfd4a857dc15ed3375e0d93e75fa3f1f64
|
/Engine/Source/ThirdParty/OSVRClientKit/include/osvr/Util/ClientReportTypesC.h
|
85fa5a5a1f3d310ddbd4828e47f94f0997a68157
|
[
"MIT",
"LicenseRef-scancode-proprietary-license"
] |
permissive
|
windystrife/UnrealEngine_NVIDIAGameWorks
|
c3c7863083653caf1bc67d3ef104fb4b9f302e2a
|
b50e6338a7c5b26374d66306ebc7807541ff815e
|
refs/heads/4.18-GameWorks
| 2023-03-11T02:50:08.471040
| 2022-01-13T20:50:29
| 2022-01-13T20:50:29
| 124,100,479
| 262
| 179
|
MIT
| 2022-12-16T05:36:38
| 2018-03-06T15:44:09
|
C++
|
UTF-8
|
C
| false
| false
| 11,168
|
h
|
ClientReportTypesC.h
|
/** @file
@brief Header
Must be c-safe!
@date 2014
@author
Sensics, Inc.
<http://sensics.com/osvr>
*/
/*
// Copyright 2014 Sensics, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
*/
#ifndef INCLUDED_ClientReportTypesC_h_GUID_E79DAB07_78B7_4795_1EB9_CA6EEB274AEE
#define INCLUDED_ClientReportTypesC_h_GUID_E79DAB07_78B7_4795_1EB9_CA6EEB274AEE
/* Internal Includes */
#include <osvr/Util/APIBaseC.h>
#include <osvr/Util/Pose3C.h>
#include <osvr/Util/StdInt.h>
#include <osvr/Util/Vec2C.h>
#include <osvr/Util/Vec3C.h>
#include <osvr/Util/ChannelCountC.h>
#include <osvr/Util/BoolC.h>
/* Library/third-party includes */
/* none */
/* Standard includes */
/* none */
OSVR_EXTERN_C_BEGIN
/** @addtogroup ClientKit
@{
*/
/** @name State types
@{
*/
/** @brief Type of position state */
typedef OSVR_Vec3 OSVR_PositionState;
/** @brief Type of orientation state */
typedef OSVR_Quaternion OSVR_OrientationState;
/** @brief Type of pose state */
typedef OSVR_Pose3 OSVR_PoseState;
/** @brief Type of linear velocity state */
typedef OSVR_Vec3 OSVR_LinearVelocityState;
/** @brief The quaternion represents the incremental rotation taking place over
a period of dt seconds. Use of dt (which does not necessarily
have to be 1, as other velocity/acceleration representations imply) and an
incremental quaternion allows device reports to be scaled to avoid aliasing
*/
typedef struct OSVR_IncrementalQuaternion {
OSVR_Quaternion incrementalRotation;
double dt;
} OSVR_IncrementalQuaternion;
/** @brief Type of angular velocity state: an incremental quaternion, providing
the incremental rotation taking place due to velocity over a period of dt
seconds.
*/
typedef OSVR_IncrementalQuaternion OSVR_AngularVelocityState;
/** @brief Struct for combined velocity state */
typedef struct OSVR_VelocityState {
OSVR_LinearVelocityState linearVelocity;
/** @brief Whether the data source reports valid data for
#OSVR_VelocityState::linearVelocity */
OSVR_CBool linearVelocityValid;
OSVR_AngularVelocityState angularVelocity;
/** @brief Whether the data source reports valid data for
#OSVR_VelocityState::angularVelocity */
OSVR_CBool angularVelocityValid;
} OSVR_VelocityState;
/** @brief Type of linear acceleration state */
typedef OSVR_Vec3 OSVR_LinearAccelerationState;
/** @brief Type of angular acceleration state
*/
typedef OSVR_IncrementalQuaternion OSVR_AngularAccelerationState;
/** @brief Struct for combined acceleration state */
typedef struct OSVR_AccelerationState {
OSVR_LinearAccelerationState linearAcceleration;
/** @brief Whether the data source reports valid data for
#OSVR_AccelerationState::linearAcceleration */
OSVR_CBool linearAccelerationValid;
OSVR_AngularAccelerationState angularAcceleration;
/** @brief Whether the data source reports valid data for
#OSVR_AccelerationState::angularAcceleration */
OSVR_CBool angularAccelerationValid;
} OSVR_AccelerationState;
/** @brief Type of button state */
typedef uint8_t OSVR_ButtonState;
/** @brief OSVR_ButtonState value indicating "button down" */
#define OSVR_BUTTON_PRESSED (1)
/** @brief OSVR_ButtonState value indicating "button up" */
#define OSVR_BUTTON_NOT_PRESSED (0)
/** @brief Type of analog channel state */
typedef double OSVR_AnalogState;
/** @} */
/** @name Report types
@{
*/
/** @brief Report type for a position callback on a tracker interface */
typedef struct OSVR_PositionReport {
/** @brief Identifies the sensor that the report comes from */
int32_t sensor;
/** @brief The position vector */
OSVR_PositionState xyz;
} OSVR_PositionReport;
/** @brief Report type for an orientation callback on a tracker interface */
typedef struct OSVR_OrientationReport {
/** @brief Identifies the sensor that the report comes from */
int32_t sensor;
/** @brief The rotation unit quaternion */
OSVR_OrientationState rotation;
} OSVR_OrientationReport;
/** @brief Report type for a pose (position and orientation) callback on a
tracker interface
*/
typedef struct OSVR_PoseReport {
/** @brief Identifies the sensor that the report comes from */
int32_t sensor;
/** @brief The pose structure, containing a position vector and a rotation
quaternion
*/
OSVR_PoseState pose;
} OSVR_PoseReport;
/** @brief Report type for a velocity (linear and angular) callback on a
tracker interface
*/
typedef struct OSVR_VelocityReport {
/** @brief Identifies the sensor that the report comes from */
int32_t sensor;
/** @brief The data state - note that not all fields are neccesarily valid,
use the `Valid` members to check the status of the other fields.
*/
OSVR_VelocityState state;
} OSVR_VelocityReport;
/** @brief Report type for a linear velocity callback on a tracker interface
*/
typedef struct OSVR_LinearVelocityReport {
/** @brief Identifies the sensor that the report comes from */
int32_t sensor;
/** @brief The state itself */
OSVR_LinearVelocityState state;
} OSVR_LinearVelocityReport;
/** @brief Report type for an angular velocity callback on a tracker interface
*/
typedef struct OSVR_AngularVelocityReport {
/** @brief Identifies the sensor that the report comes from */
int32_t sensor;
/** @brief The state itself */
OSVR_AngularVelocityState state;
} OSVR_AngularVelocityReport;
/** @brief Report type for an acceleration (linear and angular) callback on a
tracker interface
*/
typedef struct OSVR_AccelerationReport {
/** @brief Identifies the sensor that the report comes from */
int32_t sensor;
/** @brief The data state - note that not all fields are neccesarily valid,
use the `Valid` members to check the status of the other fields.
*/
OSVR_AccelerationState state;
} OSVR_AccelerationReport;
/** @brief Report type for a linear acceleration callback on a tracker interface
*/
typedef struct OSVR_LinearAccelerationReport {
/** @brief Identifies the sensor that the report comes from */
int32_t sensor;
/** @brief The state itself */
OSVR_LinearAccelerationState state;
} OSVR_LinearAccelerationReport;
/** @brief Report type for an angular acceleration callback on a tracker
interface
*/
typedef struct OSVR_AngularAccelerationReport {
/** @brief Identifies the sensor that the report comes from */
int32_t sensor;
/** @brief The state itself */
OSVR_AngularAccelerationState state;
} OSVR_AngularAccelerationReport;
/** @brief Report type for a callback on a button interface */
typedef struct OSVR_ButtonReport {
/** @brief Identifies the sensor that the report comes from */
int32_t sensor;
/** @brief The button state: 1 is pressed, 0 is not pressed. */
OSVR_ButtonState state;
} OSVR_ButtonReport;
/** @brief Report type for a callback on an analog interface */
typedef struct OSVR_AnalogReport {
/** @brief Identifies the sensor/channel that the report comes from */
int32_t sensor;
/** @brief The analog state. */
OSVR_AnalogState state;
} OSVR_AnalogReport;
/** @brief Type of location within a 2D region/surface, in normalized
coordinates (in range [0, 1] in standard OSVR coordinate system)
*/
typedef OSVR_Vec2 OSVR_Location2DState;
/** @brief Report type for 2D location */
typedef struct OSVR_Location2DReport {
OSVR_ChannelCount sensor;
OSVR_Location2DState location;
} OSVR_Location2DReport;
/** @brief Type of unit directional vector in 3D with no particular origin */
typedef OSVR_Vec3 OSVR_DirectionState;
/** @brief Report type for 3D Direction vector */
typedef struct OSVR_DirectionReport {
OSVR_ChannelCount sensor;
OSVR_DirectionState direction;
} OSVR_DirectionReport;
/** @brief Type of eye gaze direction in 3D which contains 3D vector (position)
containing gaze base point of the user's respective eye in 3D device
coordinates.
*/
typedef OSVR_PositionState OSVR_EyeGazeBasePoint3DState;
/** @brief Type of eye gaze position in 2D which contains users's gaze/point of
regard in normalized display coordinates (in range [0, 1] in standard OSVR
coordinate system)
*/
typedef OSVR_Location2DState OSVR_EyeGazePosition2DState;
// typedef OSVR_DirectionState OSVR_EyeGazeBasePoint3DState;
/** @brief Type of 3D vector (direction vector) containing the normalized gaze
direction of user's respective eye */
typedef OSVR_DirectionState OSVR_EyeGazeDirectionState;
/** @brief State for 3D gaze report */
typedef struct OSVR_EyeTracker3DState {
OSVR_CBool directionValid;
OSVR_DirectionState direction;
OSVR_CBool basePointValid;
OSVR_PositionState basePoint;
} OSVR_EyeTracker3DState;
/** @brief Report type for 3D gaze report */
typedef struct OSVR_EyeTracker3DReport {
OSVR_ChannelCount sensor;
OSVR_EyeTracker3DState state;
} OSVR_EyeTracker3DReport;
/** @brief State for 2D location report */
typedef OSVR_Location2DState OSVR_EyeTracker2DState;
/** @brief Report type for 2D location report */
typedef struct OSVR_EyeTracker2DReport {
OSVR_ChannelCount sensor;
OSVR_EyeTracker2DState state;
} OSVR_EyeTracker2DReport;
/** @brief State for a blink event */
typedef OSVR_ButtonState OSVR_EyeTrackerBlinkState;
/** @brief OSVR_EyeTrackerBlinkState value indicating an eyes blink had occurred
*/
#define OSVR_EYE_BLINK (1)
/** @brief OSVR_EyeTrackerBlinkState value indicating eyes are not blinking */
#define OSVR_EYE_NO_BLINK (0)
/** @brief Report type for a blink event */
typedef struct OSVR_EyeTrackerBlinkReport {
OSVR_ChannelCount sensor;
OSVR_EyeTrackerBlinkState state;
} OSVR_EyeTrackerBlinkReport;
/** @brief Report type for an Imaging callback (forward declaration) */
struct OSVR_ImagingReport;
/** @brief Type of Navigation Velocity state */
typedef OSVR_Vec2 OSVR_NaviVelocityState;
/** @brief Type of Navigation Position state */
typedef OSVR_Vec2 OSVR_NaviPositionState;
/** @brief Report type for an navigation velocity callback on a tracker
* interface */
typedef struct OSVR_NaviVelocityReport {
OSVR_ChannelCount sensor;
/** @brief The 2D vector in world coordinate system, in meters/second */
OSVR_NaviVelocityState state;
} OSVR_NaviVelocityReport;
/** @brief Report type for an navigation position callback on a tracker
* interface */
typedef struct OSVR_NaviPositionReport {
OSVR_ChannelCount sensor;
/** @brief The 2D vector in world coordinate system, in meters, relative to
* starting position */
OSVR_NaviPositionState state;
} OSVR_NaviPositionReport;
/** @} */
/** @} */
OSVR_EXTERN_C_END
#endif
|
3d7c3e07811e855b7402998805395d88255226a8
|
59bc6f245c1c8f1b65afdbde959db281d5747e63
|
/Examples/Polish/1. System licencyjny/FEATURE_x_START - indywidualnie szyfrowane sekcje/C/gui/gui.h
|
3668de070dd5117f29ba9e0ebb233b8bd09ec95f
|
[] |
no_license
|
PELock/PELock-Software-Protection-and-Licensing-SDK
|
70fc8cf20681b5799c7a016773851da5bfe258b6
|
45c3ee1f8d6f489f8abfbe8b4bb7a476d4d1c001
|
refs/heads/master
| 2023-06-24T13:35:18.095564
| 2023-03-11T14:35:50
| 2023-03-11T14:35:50
| 63,718,533
| 184
| 57
| null | 2018-08-30T18:51:48
| 2016-07-19T18:32:23
|
C++
|
UTF-8
|
C
| false
| false
| 64
|
h
|
gui.h
|
#define IDI_MAIN 999
#define DLG_MAIN 111
#define IDC_INFO 120
|
54f6822a5663a2376513a7bff413cb819e7844d2
|
a5a99f646e371b45974a6fb6ccc06b0a674818f2
|
/CalibMuon/DTCalibration/test/stubs/NoiseAnalyzer.c
|
9e0ce8c65fe664726be09e1e72eb50af010a4812
|
[
"Apache-2.0"
] |
permissive
|
cms-sw/cmssw
|
4ecd2c1105d59c66d385551230542c6615b9ab58
|
19c178740257eb48367778593da55dcad08b7a4f
|
refs/heads/master
| 2023-08-23T21:57:42.491143
| 2023-08-22T20:22:40
| 2023-08-22T20:22:40
| 10,969,551
| 1,006
| 3,696
|
Apache-2.0
| 2023-09-14T19:14:28
| 2013-06-26T14:09:07
|
C++
|
UTF-8
|
C
| false
| false
| 3,131
|
c
|
NoiseAnalyzer.c
|
#include "TROOT.h"
#include "TSystem.h"
#include "TH1D.h"
#include "THStack.h"
#include "TChain.h"
#include "TTree.h"
#include "TLegend.h"
#include "TFile.h"
#include "TCanvas.h"
#include "TLorentzVector.h"
#include <iostream>
#include <sstream>
#include <fstream.h>
#include "TPostScript.h"
using namespace std;
void NoiseAnalyzer();
void NoiseAnalyzer()
{
// the input file
TFile *f1 = new TFile("DTNoiseCalib.root");
// the output files
TPostScript *ps = new TPostScript("DTNoise.ps", 112);
ofstream summaryOutput("summaryNoise.txt");
ofstream detailedOutput("detailedNoise.txt");
TCanvas* c = new TCanvas("prova", "prova");
TLegend *leg=new TLegend(0.2,0.75,0.9,0.88);
for(int W=-2; W<=2; W++){
std::stringstream wheel; wheel << W;
for(int Sec=1; Sec<=14; Sec++){
std::stringstream sector; sector << Sec;
for(int St=1; St<=4; St++){
double counterSomehowNoisyCells=0;
double counterNoisyCells=0;
bool StationHasData=false;
std::stringstream station; station << St;
for(int SL=1; SL<=3; SL++){
leg->Clear();
bool SLhasData=false;
bool pageWritten=false;
std::stringstream superlayer; superlayer << SL;
TString newHistoName="AverageNoise_W"+wheel.str()+"_St"+station.str()+"_Sec"+sector.str()+"_SL"+superlayer.str();
for(int L=1; L<=4; L++){
std::stringstream layer; layer << L;
// find the histo
TString histoName="DigiOccupancy_W"+wheel.str()+"_St"+station.str()+"_Sec"+sector.str()+"_SL"+superlayer.str()+"_L"+layer.str();
TH1F* h =((TH1F*) f1->Get(histoName));
if(h){
StationHasData=true;
SLhasData=true;
//overimpose the plot per SL
c->cd();
TString legend= "layer_"+layer.str();
if(L==1){
h->SetTitle(newHistoName);
h->SetLineColor(L);
h->SetLineWidth(2);
h->Draw();
leg->AddEntry(h,legend,"L");
}
else{
h->SetLineColor(L);
h->SetLineWidth(2);
h->Draw("same");
leg->AddEntry(h,legend,"L");
}
//count the numeber of noisy/someHow noisy cells
int numBin = h->GetXaxis()->GetNbins();
for (int bin=1; bin<=numBin; bin++){
if(h->GetBinContent(bin)>100 && h->GetBinContent(bin)<500){
counterSomehowNoisyCells++;
detailedOutput<<"somehowNoisyCell: W"<<W<<" St"<<St<<" Sec"<<Sec<<" SL"<<SL<<" L"<<L<<" wire"<<bin<<endl;
}
if(h->GetBinContent(bin)>500){
counterNoisyCells++;
detailedOutput<<"noisyCell: W"<<W<<" St"<<St<<" Sec"<<Sec<<" SL"<<SL<<" L"<<L<<" wire"<<bin<<endl;
}
}
}
} // loop on layer
if(SLhasData && !(pageWritten)){
pageWritten=true;
leg->Draw("same");
gPad->SetLogy();
c->Update();
}
} // loop on SL
if(StationHasData){
summaryOutput<<" ------------ "<<endl;
summaryOutput<<"MB"<<St<<"_W"<<W<<"_Sec"<<Sec<<endl;
summaryOutput<<"# of somehow noisy cells: "<<counterSomehowNoisyCells<<endl;
summaryOutput<<"# of noisy cells: "<<counterNoisyCells<<endl;
}
} // loop on stations
} // loop on sectors
} // loop on wheels
ps->Close();
}
|
362c43e492f0a0fbc9e91f7bcb1ea5234c007742
|
dcbef06d5a00f07756339b9e62c684dec2fee425
|
/nuitka/build/static_src/HelpersOperationBinaryFloordiv.c
|
4d64b7edb3346291772d0b98371096ff53c2454a
|
[
"Apache-2.0",
"LicenseRef-scancode-warranty-disclaimer"
] |
permissive
|
Nuitka/Nuitka
|
f9543d8d95bfa0b81d4e60af0dfad99fb72893a4
|
d87faf2f7e1d6ed9bfe4cf8c1d648f34307e33f2
|
refs/heads/develop
| 2023-08-28T14:00:32.861328
| 2023-08-27T09:16:45
| 2023-08-27T09:16:45
| 9,626,741
| 8,573
| 599
|
Apache-2.0
| 2023-09-13T02:49:41
| 2013-04-23T15:40:33
|
Python
|
UTF-8
|
C
| false
| false
| 68,748
|
c
|
HelpersOperationBinaryFloordiv.c
|
// Copyright 2023, Kay Hayen, mailto:kay.hayen@gmail.com
//
// Part of "Nuitka", an optimizing Python compiler that is compatible and
// integrates with CPython, but also works on its own.
//
// 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.
//
/* WARNING, this code is GENERATED. Modify the template HelperOperationBinary.c.j2 instead! */
/* This file is included from another C file, help IDEs to still parse it on its own. */
#ifdef __IDE_ONLY__
#include "nuitka/prelude.h"
#endif
/* C helpers for type specialized "//" (FLOORDIV) operations */
#if PYTHON_VERSION < 0x300
/* Code referring to "INT" corresponds to Python2 'int' and "INT" to Python2 'int'. */
static PyObject *_BINARY_OPERATION_FLOORDIV_OBJECT_INT_INT(PyObject *operand1, PyObject *operand2) {
CHECK_OBJECT(operand1);
assert(PyInt_CheckExact(operand1));
CHECK_OBJECT(operand2);
assert(PyInt_CheckExact(operand2));
PyObject *result;
// Not every code path will make use of all possible results.
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4101)
#endif
NUITKA_MAY_BE_UNUSED bool cbool_result;
NUITKA_MAY_BE_UNUSED PyObject *obj_result;
NUITKA_MAY_BE_UNUSED long clong_result;
NUITKA_MAY_BE_UNUSED double cfloat_result;
#ifdef _MSC_VER
#pragma warning(pop)
#endif
CHECK_OBJECT(operand1);
assert(PyInt_CheckExact(operand1));
CHECK_OBJECT(operand2);
assert(PyInt_CheckExact(operand2));
const long a = PyInt_AS_LONG(operand1);
const long b = PyInt_AS_LONG(operand2);
if (unlikely(b == 0)) {
SET_CURRENT_EXCEPTION_TYPE0_STR(PyExc_ZeroDivisionError, "integer division or modulo by zero");
goto exit_result_exception;
}
/* TODO: Isn't this a very specific value only, of which we could
* hardcode the constant result. Not sure how well the C compiler
* optimizes UNARY_NEG_WOULD_OVERFLOW to this, but dividing by
* -1 has to be rare anyway.
*/
if (likely(b != -1 || !UNARY_NEG_WOULD_OVERFLOW(a))) {
long a_div_b = a / b;
long a_mod_b = (long)(a - (unsigned long)a_div_b * b);
if (a_mod_b && (b ^ a_mod_b) < 0) {
a_mod_b += b;
a_div_b -= 1;
}
clong_result = a_div_b;
goto exit_result_ok_clong;
}
{
PyObject *operand1_object = operand1;
PyObject *operand2_object = operand2;
PyObject *r = PyLong_Type.tp_as_number->nb_floor_divide(operand1_object, operand2_object);
assert(r != Py_NotImplemented);
obj_result = r;
goto exit_result_object;
}
exit_result_ok_clong:
result = PyInt_FromLong(clong_result);
goto exit_result_ok;
exit_result_object:
if (unlikely(obj_result == NULL)) {
goto exit_result_exception;
}
result = obj_result;
goto exit_result_ok;
exit_result_ok:
return result;
exit_result_exception:
return NULL;
}
PyObject *BINARY_OPERATION_FLOORDIV_OBJECT_INT_INT(PyObject *operand1, PyObject *operand2) {
return _BINARY_OPERATION_FLOORDIV_OBJECT_INT_INT(operand1, operand2);
}
#endif
#if PYTHON_VERSION < 0x300
/* Code referring to "OBJECT" corresponds to any Python object and "INT" to Python2 'int'. */
static HEDLEY_NEVER_INLINE PyObject *__BINARY_OPERATION_FLOORDIV_OBJECT_OBJECT_INT(PyObject *operand1,
PyObject *operand2) {
PyTypeObject *type1 = Py_TYPE(operand1);
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4101)
#endif
NUITKA_MAY_BE_UNUSED bool cbool_result;
NUITKA_MAY_BE_UNUSED PyObject *obj_result;
#ifdef _MSC_VER
#pragma warning(pop)
#endif
binaryfunc slot1 =
(type1->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type1)) ? type1->tp_as_number->nb_floor_divide : NULL;
binaryfunc slot2 = NULL;
if (!(type1 == &PyInt_Type)) {
// Different types, need to consider second value slot.
slot2 = PyInt_Type.tp_as_number->nb_floor_divide;
if (slot1 == slot2) {
slot2 = NULL;
}
}
if (slot1 != NULL) {
PyObject *x = slot1(operand1, operand2);
if (x != Py_NotImplemented) {
obj_result = x;
goto exit_binary_result_object;
}
Py_DECREF(x);
}
if (slot2 != NULL) {
PyObject *x = slot2(operand1, operand2);
if (x != Py_NotImplemented) {
obj_result = x;
goto exit_binary_result_object;
}
Py_DECREF(x);
}
#if PYTHON_VERSION < 0x300
if (!NEW_STYLE_NUMBER_TYPE(type1) || !1) {
coercion c1 =
(type1->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type1)) ? type1->tp_as_number->nb_coerce : NULL;
if (c1 != NULL) {
PyObject *coerced1 = operand1;
PyObject *coerced2 = operand2;
int err = c1(&coerced1, &coerced2);
if (unlikely(err < 0)) {
goto exit_binary_exception;
}
if (err == 0) {
PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
if (likely(mv == NULL)) {
binaryfunc slot = mv->nb_floor_divide;
if (likely(slot != NULL)) {
PyObject *x = slot(coerced1, coerced2);
Py_DECREF(coerced1);
Py_DECREF(coerced2);
obj_result = x;
goto exit_binary_result_object;
}
}
// nb_coerce took a reference.
Py_DECREF(coerced1);
Py_DECREF(coerced2);
}
}
coercion c2 = PyInt_Type.tp_as_number->nb_coerce;
if (c2 != NULL) {
PyObject *coerced1 = operand1;
PyObject *coerced2 = operand2;
int err = c2(&coerced2, &coerced1);
if (unlikely(err < 0)) {
goto exit_binary_exception;
}
if (err == 0) {
PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
if (likely(mv == NULL)) {
binaryfunc slot = mv->nb_floor_divide;
if (likely(slot != NULL)) {
PyObject *x = slot(coerced1, coerced2);
Py_DECREF(coerced1);
Py_DECREF(coerced2);
obj_result = x;
goto exit_binary_result_object;
}
}
// nb_coerce took a reference.
Py_DECREF(coerced1);
Py_DECREF(coerced2);
}
}
}
#endif
PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for //: '%s' and 'int'", type1->tp_name);
goto exit_binary_exception;
exit_binary_result_object:
return obj_result;
exit_binary_exception:
return NULL;
}
static PyObject *_BINARY_OPERATION_FLOORDIV_OBJECT_OBJECT_INT(PyObject *operand1, PyObject *operand2) {
CHECK_OBJECT(operand1);
CHECK_OBJECT(operand2);
assert(PyInt_CheckExact(operand2));
PyTypeObject *type1 = Py_TYPE(operand1);
if (type1 == &PyInt_Type) {
PyObject *result;
// return _BINARY_OPERATION_FLOORDIV_OBJECT_INT_INT(operand1, operand2);
// Not every code path will make use of all possible results.
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4101)
#endif
NUITKA_MAY_BE_UNUSED bool cbool_result;
NUITKA_MAY_BE_UNUSED PyObject *obj_result;
NUITKA_MAY_BE_UNUSED long clong_result;
NUITKA_MAY_BE_UNUSED double cfloat_result;
#ifdef _MSC_VER
#pragma warning(pop)
#endif
CHECK_OBJECT(operand1);
assert(PyInt_CheckExact(operand1));
CHECK_OBJECT(operand2);
assert(PyInt_CheckExact(operand2));
const long a = PyInt_AS_LONG(operand1);
const long b = PyInt_AS_LONG(operand2);
if (unlikely(b == 0)) {
SET_CURRENT_EXCEPTION_TYPE0_STR(PyExc_ZeroDivisionError, "integer division or modulo by zero");
goto exit_result_exception;
}
/* TODO: Isn't this a very specific value only, of which we could
* hardcode the constant result. Not sure how well the C compiler
* optimizes UNARY_NEG_WOULD_OVERFLOW to this, but dividing by
* -1 has to be rare anyway.
*/
if (likely(b != -1 || !UNARY_NEG_WOULD_OVERFLOW(a))) {
long a_div_b = a / b;
long a_mod_b = (long)(a - (unsigned long)a_div_b * b);
if (a_mod_b && (b ^ a_mod_b) < 0) {
a_mod_b += b;
a_div_b -= 1;
}
clong_result = a_div_b;
goto exit_result_ok_clong;
}
{
PyObject *operand1_object = operand1;
PyObject *operand2_object = operand2;
PyObject *r = PyLong_Type.tp_as_number->nb_floor_divide(operand1_object, operand2_object);
assert(r != Py_NotImplemented);
obj_result = r;
goto exit_result_object;
}
exit_result_ok_clong:
result = PyInt_FromLong(clong_result);
goto exit_result_ok;
exit_result_object:
if (unlikely(obj_result == NULL)) {
goto exit_result_exception;
}
result = obj_result;
goto exit_result_ok;
exit_result_ok:
return result;
exit_result_exception:
return NULL;
}
return __BINARY_OPERATION_FLOORDIV_OBJECT_OBJECT_INT(operand1, operand2);
}
PyObject *BINARY_OPERATION_FLOORDIV_OBJECT_OBJECT_INT(PyObject *operand1, PyObject *operand2) {
return _BINARY_OPERATION_FLOORDIV_OBJECT_OBJECT_INT(operand1, operand2);
}
#endif
#if PYTHON_VERSION < 0x300
/* Code referring to "INT" corresponds to Python2 'int' and "OBJECT" to any Python object. */
static HEDLEY_NEVER_INLINE PyObject *__BINARY_OPERATION_FLOORDIV_OBJECT_INT_OBJECT(PyObject *operand1,
PyObject *operand2) {
PyTypeObject *type2 = Py_TYPE(operand2);
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4101)
#endif
NUITKA_MAY_BE_UNUSED bool cbool_result;
NUITKA_MAY_BE_UNUSED PyObject *obj_result;
#ifdef _MSC_VER
#pragma warning(pop)
#endif
binaryfunc slot1 = PyInt_Type.tp_as_number->nb_floor_divide;
binaryfunc slot2 = NULL;
if (!(&PyInt_Type == type2)) {
// Different types, need to consider second value slot.
slot2 =
(type2->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type2)) ? type2->tp_as_number->nb_floor_divide : NULL;
if (slot1 == slot2) {
slot2 = NULL;
}
}
if (slot1 != NULL) {
if (slot2 != NULL) {
if (Nuitka_Type_IsSubtype(type2, &PyInt_Type)) {
PyObject *x = slot2(operand1, operand2);
if (x != Py_NotImplemented) {
obj_result = x;
goto exit_binary_result_object;
}
Py_DECREF(x);
slot2 = NULL;
}
}
PyObject *x = slot1(operand1, operand2);
if (x != Py_NotImplemented) {
obj_result = x;
goto exit_binary_result_object;
}
Py_DECREF(x);
}
if (slot2 != NULL) {
PyObject *x = slot2(operand1, operand2);
if (x != Py_NotImplemented) {
obj_result = x;
goto exit_binary_result_object;
}
Py_DECREF(x);
}
#if PYTHON_VERSION < 0x300
if (!1 || !NEW_STYLE_NUMBER_TYPE(type2)) {
coercion c1 = PyInt_Type.tp_as_number->nb_coerce;
if (c1 != NULL) {
PyObject *coerced1 = operand1;
PyObject *coerced2 = operand2;
int err = c1(&coerced1, &coerced2);
if (unlikely(err < 0)) {
goto exit_binary_exception;
}
if (err == 0) {
PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
if (likely(mv == NULL)) {
binaryfunc slot = mv->nb_floor_divide;
if (likely(slot != NULL)) {
PyObject *x = slot(coerced1, coerced2);
Py_DECREF(coerced1);
Py_DECREF(coerced2);
obj_result = x;
goto exit_binary_result_object;
}
}
// nb_coerce took a reference.
Py_DECREF(coerced1);
Py_DECREF(coerced2);
}
}
coercion c2 =
(type2->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type2)) ? type2->tp_as_number->nb_coerce : NULL;
if (c2 != NULL) {
PyObject *coerced1 = operand1;
PyObject *coerced2 = operand2;
int err = c2(&coerced2, &coerced1);
if (unlikely(err < 0)) {
goto exit_binary_exception;
}
if (err == 0) {
PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
if (likely(mv == NULL)) {
binaryfunc slot = mv->nb_floor_divide;
if (likely(slot != NULL)) {
PyObject *x = slot(coerced1, coerced2);
Py_DECREF(coerced1);
Py_DECREF(coerced2);
obj_result = x;
goto exit_binary_result_object;
}
}
// nb_coerce took a reference.
Py_DECREF(coerced1);
Py_DECREF(coerced2);
}
}
}
#endif
PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for //: 'int' and '%s'", type2->tp_name);
goto exit_binary_exception;
exit_binary_result_object:
return obj_result;
exit_binary_exception:
return NULL;
}
static PyObject *_BINARY_OPERATION_FLOORDIV_OBJECT_INT_OBJECT(PyObject *operand1, PyObject *operand2) {
CHECK_OBJECT(operand1);
assert(PyInt_CheckExact(operand1));
CHECK_OBJECT(operand2);
PyTypeObject *type2 = Py_TYPE(operand2);
if (&PyInt_Type == type2) {
PyObject *result;
// return _BINARY_OPERATION_FLOORDIV_OBJECT_INT_INT(operand1, operand2);
// Not every code path will make use of all possible results.
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4101)
#endif
NUITKA_MAY_BE_UNUSED bool cbool_result;
NUITKA_MAY_BE_UNUSED PyObject *obj_result;
NUITKA_MAY_BE_UNUSED long clong_result;
NUITKA_MAY_BE_UNUSED double cfloat_result;
#ifdef _MSC_VER
#pragma warning(pop)
#endif
CHECK_OBJECT(operand1);
assert(PyInt_CheckExact(operand1));
CHECK_OBJECT(operand2);
assert(PyInt_CheckExact(operand2));
const long a = PyInt_AS_LONG(operand1);
const long b = PyInt_AS_LONG(operand2);
if (unlikely(b == 0)) {
SET_CURRENT_EXCEPTION_TYPE0_STR(PyExc_ZeroDivisionError, "integer division or modulo by zero");
goto exit_result_exception;
}
/* TODO: Isn't this a very specific value only, of which we could
* hardcode the constant result. Not sure how well the C compiler
* optimizes UNARY_NEG_WOULD_OVERFLOW to this, but dividing by
* -1 has to be rare anyway.
*/
if (likely(b != -1 || !UNARY_NEG_WOULD_OVERFLOW(a))) {
long a_div_b = a / b;
long a_mod_b = (long)(a - (unsigned long)a_div_b * b);
if (a_mod_b && (b ^ a_mod_b) < 0) {
a_mod_b += b;
a_div_b -= 1;
}
clong_result = a_div_b;
goto exit_result_ok_clong;
}
{
PyObject *operand1_object = operand1;
PyObject *operand2_object = operand2;
PyObject *r = PyLong_Type.tp_as_number->nb_floor_divide(operand1_object, operand2_object);
assert(r != Py_NotImplemented);
obj_result = r;
goto exit_result_object;
}
exit_result_ok_clong:
result = PyInt_FromLong(clong_result);
goto exit_result_ok;
exit_result_object:
if (unlikely(obj_result == NULL)) {
goto exit_result_exception;
}
result = obj_result;
goto exit_result_ok;
exit_result_ok:
return result;
exit_result_exception:
return NULL;
}
return __BINARY_OPERATION_FLOORDIV_OBJECT_INT_OBJECT(operand1, operand2);
}
PyObject *BINARY_OPERATION_FLOORDIV_OBJECT_INT_OBJECT(PyObject *operand1, PyObject *operand2) {
return _BINARY_OPERATION_FLOORDIV_OBJECT_INT_OBJECT(operand1, operand2);
}
#endif
/* Code referring to "LONG" corresponds to Python2 'long', Python3 'int' and "LONG" to Python2 'long', Python3 'int'. */
static PyObject *_BINARY_OPERATION_FLOORDIV_OBJECT_LONG_LONG(PyObject *operand1, PyObject *operand2) {
CHECK_OBJECT(operand1);
assert(PyLong_CheckExact(operand1));
CHECK_OBJECT(operand2);
assert(PyLong_CheckExact(operand2));
PyObject *result;
// Not every code path will make use of all possible results.
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4101)
#endif
NUITKA_MAY_BE_UNUSED PyObject *obj_result;
NUITKA_MAY_BE_UNUSED long clong_result;
#ifdef _MSC_VER
#pragma warning(pop)
#endif
PyObject *x = PyLong_Type.tp_as_number->nb_floor_divide(operand1, operand2);
assert(x != Py_NotImplemented);
obj_result = x;
goto exit_result_object;
exit_result_object:
if (unlikely(obj_result == NULL)) {
goto exit_result_exception;
}
result = obj_result;
goto exit_result_ok;
exit_result_ok:
return result;
exit_result_exception:
return NULL;
}
PyObject *BINARY_OPERATION_FLOORDIV_OBJECT_LONG_LONG(PyObject *operand1, PyObject *operand2) {
return _BINARY_OPERATION_FLOORDIV_OBJECT_LONG_LONG(operand1, operand2);
}
/* Code referring to "OBJECT" corresponds to any Python object and "LONG" to Python2 'long', Python3 'int'. */
static HEDLEY_NEVER_INLINE PyObject *__BINARY_OPERATION_FLOORDIV_OBJECT_OBJECT_LONG(PyObject *operand1,
PyObject *operand2) {
PyTypeObject *type1 = Py_TYPE(operand1);
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4101)
#endif
NUITKA_MAY_BE_UNUSED bool cbool_result;
NUITKA_MAY_BE_UNUSED PyObject *obj_result;
#ifdef _MSC_VER
#pragma warning(pop)
#endif
binaryfunc slot1 =
(type1->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type1)) ? type1->tp_as_number->nb_floor_divide : NULL;
binaryfunc slot2 = NULL;
if (!(type1 == &PyLong_Type)) {
// Different types, need to consider second value slot.
slot2 = PyLong_Type.tp_as_number->nb_floor_divide;
if (slot1 == slot2) {
slot2 = NULL;
}
}
if (slot1 != NULL) {
PyObject *x = slot1(operand1, operand2);
if (x != Py_NotImplemented) {
obj_result = x;
goto exit_binary_result_object;
}
Py_DECREF(x);
}
if (slot2 != NULL) {
PyObject *x = slot2(operand1, operand2);
if (x != Py_NotImplemented) {
obj_result = x;
goto exit_binary_result_object;
}
Py_DECREF(x);
}
#if PYTHON_VERSION < 0x300
if (!NEW_STYLE_NUMBER_TYPE(type1) || !1) {
coercion c1 =
(type1->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type1)) ? type1->tp_as_number->nb_coerce : NULL;
if (c1 != NULL) {
PyObject *coerced1 = operand1;
PyObject *coerced2 = operand2;
int err = c1(&coerced1, &coerced2);
if (unlikely(err < 0)) {
goto exit_binary_exception;
}
if (err == 0) {
PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
if (likely(mv == NULL)) {
binaryfunc slot = mv->nb_floor_divide;
if (likely(slot != NULL)) {
PyObject *x = slot(coerced1, coerced2);
Py_DECREF(coerced1);
Py_DECREF(coerced2);
obj_result = x;
goto exit_binary_result_object;
}
}
// nb_coerce took a reference.
Py_DECREF(coerced1);
Py_DECREF(coerced2);
}
}
coercion c2 = PyLong_Type.tp_as_number->nb_coerce;
if (c2 != NULL) {
PyObject *coerced1 = operand1;
PyObject *coerced2 = operand2;
int err = c2(&coerced2, &coerced1);
if (unlikely(err < 0)) {
goto exit_binary_exception;
}
if (err == 0) {
PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
if (likely(mv == NULL)) {
binaryfunc slot = mv->nb_floor_divide;
if (likely(slot != NULL)) {
PyObject *x = slot(coerced1, coerced2);
Py_DECREF(coerced1);
Py_DECREF(coerced2);
obj_result = x;
goto exit_binary_result_object;
}
}
// nb_coerce took a reference.
Py_DECREF(coerced1);
Py_DECREF(coerced2);
}
}
}
#endif
#if PYTHON_VERSION < 0x300
PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for //: '%s' and 'long'", type1->tp_name);
#else
PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for //: '%s' and 'int'", type1->tp_name);
#endif
goto exit_binary_exception;
exit_binary_result_object:
return obj_result;
exit_binary_exception:
return NULL;
}
static PyObject *_BINARY_OPERATION_FLOORDIV_OBJECT_OBJECT_LONG(PyObject *operand1, PyObject *operand2) {
CHECK_OBJECT(operand1);
CHECK_OBJECT(operand2);
assert(PyLong_CheckExact(operand2));
PyTypeObject *type1 = Py_TYPE(operand1);
if (type1 == &PyLong_Type) {
PyObject *result;
// return _BINARY_OPERATION_FLOORDIV_OBJECT_LONG_LONG(operand1, operand2);
// Not every code path will make use of all possible results.
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4101)
#endif
NUITKA_MAY_BE_UNUSED PyObject *obj_result;
NUITKA_MAY_BE_UNUSED long clong_result;
#ifdef _MSC_VER
#pragma warning(pop)
#endif
PyObject *x = PyLong_Type.tp_as_number->nb_floor_divide(operand1, operand2);
assert(x != Py_NotImplemented);
obj_result = x;
goto exit_result_object;
exit_result_object:
if (unlikely(obj_result == NULL)) {
goto exit_result_exception;
}
result = obj_result;
goto exit_result_ok;
exit_result_ok:
return result;
exit_result_exception:
return NULL;
}
return __BINARY_OPERATION_FLOORDIV_OBJECT_OBJECT_LONG(operand1, operand2);
}
PyObject *BINARY_OPERATION_FLOORDIV_OBJECT_OBJECT_LONG(PyObject *operand1, PyObject *operand2) {
return _BINARY_OPERATION_FLOORDIV_OBJECT_OBJECT_LONG(operand1, operand2);
}
/* Code referring to "LONG" corresponds to Python2 'long', Python3 'int' and "OBJECT" to any Python object. */
static HEDLEY_NEVER_INLINE PyObject *__BINARY_OPERATION_FLOORDIV_OBJECT_LONG_OBJECT(PyObject *operand1,
PyObject *operand2) {
PyTypeObject *type2 = Py_TYPE(operand2);
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4101)
#endif
NUITKA_MAY_BE_UNUSED bool cbool_result;
NUITKA_MAY_BE_UNUSED PyObject *obj_result;
#ifdef _MSC_VER
#pragma warning(pop)
#endif
binaryfunc slot1 = PyLong_Type.tp_as_number->nb_floor_divide;
binaryfunc slot2 = NULL;
if (!(&PyLong_Type == type2)) {
// Different types, need to consider second value slot.
slot2 =
(type2->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type2)) ? type2->tp_as_number->nb_floor_divide : NULL;
if (slot1 == slot2) {
slot2 = NULL;
}
}
if (slot1 != NULL) {
if (slot2 != NULL) {
if (Nuitka_Type_IsSubtype(type2, &PyLong_Type)) {
PyObject *x = slot2(operand1, operand2);
if (x != Py_NotImplemented) {
obj_result = x;
goto exit_binary_result_object;
}
Py_DECREF(x);
slot2 = NULL;
}
}
PyObject *x = slot1(operand1, operand2);
if (x != Py_NotImplemented) {
obj_result = x;
goto exit_binary_result_object;
}
Py_DECREF(x);
}
if (slot2 != NULL) {
PyObject *x = slot2(operand1, operand2);
if (x != Py_NotImplemented) {
obj_result = x;
goto exit_binary_result_object;
}
Py_DECREF(x);
}
#if PYTHON_VERSION < 0x300
if (!1 || !NEW_STYLE_NUMBER_TYPE(type2)) {
coercion c1 = PyLong_Type.tp_as_number->nb_coerce;
if (c1 != NULL) {
PyObject *coerced1 = operand1;
PyObject *coerced2 = operand2;
int err = c1(&coerced1, &coerced2);
if (unlikely(err < 0)) {
goto exit_binary_exception;
}
if (err == 0) {
PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
if (likely(mv == NULL)) {
binaryfunc slot = mv->nb_floor_divide;
if (likely(slot != NULL)) {
PyObject *x = slot(coerced1, coerced2);
Py_DECREF(coerced1);
Py_DECREF(coerced2);
obj_result = x;
goto exit_binary_result_object;
}
}
// nb_coerce took a reference.
Py_DECREF(coerced1);
Py_DECREF(coerced2);
}
}
coercion c2 =
(type2->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type2)) ? type2->tp_as_number->nb_coerce : NULL;
if (c2 != NULL) {
PyObject *coerced1 = operand1;
PyObject *coerced2 = operand2;
int err = c2(&coerced2, &coerced1);
if (unlikely(err < 0)) {
goto exit_binary_exception;
}
if (err == 0) {
PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
if (likely(mv == NULL)) {
binaryfunc slot = mv->nb_floor_divide;
if (likely(slot != NULL)) {
PyObject *x = slot(coerced1, coerced2);
Py_DECREF(coerced1);
Py_DECREF(coerced2);
obj_result = x;
goto exit_binary_result_object;
}
}
// nb_coerce took a reference.
Py_DECREF(coerced1);
Py_DECREF(coerced2);
}
}
}
#endif
#if PYTHON_VERSION < 0x300
PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for //: 'long' and '%s'", type2->tp_name);
#else
PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for //: 'int' and '%s'", type2->tp_name);
#endif
goto exit_binary_exception;
exit_binary_result_object:
return obj_result;
exit_binary_exception:
return NULL;
}
static PyObject *_BINARY_OPERATION_FLOORDIV_OBJECT_LONG_OBJECT(PyObject *operand1, PyObject *operand2) {
CHECK_OBJECT(operand1);
assert(PyLong_CheckExact(operand1));
CHECK_OBJECT(operand2);
PyTypeObject *type2 = Py_TYPE(operand2);
if (&PyLong_Type == type2) {
PyObject *result;
// return _BINARY_OPERATION_FLOORDIV_OBJECT_LONG_LONG(operand1, operand2);
// Not every code path will make use of all possible results.
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4101)
#endif
NUITKA_MAY_BE_UNUSED PyObject *obj_result;
NUITKA_MAY_BE_UNUSED long clong_result;
#ifdef _MSC_VER
#pragma warning(pop)
#endif
PyObject *x = PyLong_Type.tp_as_number->nb_floor_divide(operand1, operand2);
assert(x != Py_NotImplemented);
obj_result = x;
goto exit_result_object;
exit_result_object:
if (unlikely(obj_result == NULL)) {
goto exit_result_exception;
}
result = obj_result;
goto exit_result_ok;
exit_result_ok:
return result;
exit_result_exception:
return NULL;
}
return __BINARY_OPERATION_FLOORDIV_OBJECT_LONG_OBJECT(operand1, operand2);
}
PyObject *BINARY_OPERATION_FLOORDIV_OBJECT_LONG_OBJECT(PyObject *operand1, PyObject *operand2) {
return _BINARY_OPERATION_FLOORDIV_OBJECT_LONG_OBJECT(operand1, operand2);
}
/* Code referring to "FLOAT" corresponds to Python 'float' and "FLOAT" to Python 'float'. */
static PyObject *_BINARY_OPERATION_FLOORDIV_OBJECT_FLOAT_FLOAT(PyObject *operand1, PyObject *operand2) {
CHECK_OBJECT(operand1);
assert(PyFloat_CheckExact(operand1));
CHECK_OBJECT(operand2);
assert(PyFloat_CheckExact(operand2));
PyObject *result;
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4101)
#endif
// Not every code path will make use of all possible results.
NUITKA_MAY_BE_UNUSED PyObject *obj_result;
NUITKA_MAY_BE_UNUSED long clong_result;
NUITKA_MAY_BE_UNUSED double cfloat_result;
#ifdef _MSC_VER
#pragma warning(pop)
#endif
CHECK_OBJECT(operand1);
assert(PyFloat_CheckExact(operand1));
CHECK_OBJECT(operand2);
assert(PyFloat_CheckExact(operand2));
const double a = PyFloat_AS_DOUBLE(operand1);
const double b = PyFloat_AS_DOUBLE(operand2);
if (unlikely(b == 0)) {
SET_CURRENT_EXCEPTION_TYPE0_STR(PyExc_ZeroDivisionError, "integer division or modulo by zero");
goto exit_result_exception;
}
{
double mod = fmod(a, b);
double div = (a - mod) / b;
if (mod) {
if ((a < 0) != (mod < 0)) {
div -= 1.0;
}
}
double floordiv;
if (div) {
floordiv = floor(div);
if (div - floordiv > 0.5) {
floordiv += 1.0;
}
} else {
floordiv = copysign(0.0, a / b);
}
cfloat_result = floordiv;
goto exit_result_ok_cfloat;
}
exit_result_ok_cfloat:
result = MAKE_FLOAT_FROM_DOUBLE(cfloat_result);
goto exit_result_ok;
exit_result_ok:
return result;
exit_result_exception:
return NULL;
}
PyObject *BINARY_OPERATION_FLOORDIV_OBJECT_FLOAT_FLOAT(PyObject *operand1, PyObject *operand2) {
return _BINARY_OPERATION_FLOORDIV_OBJECT_FLOAT_FLOAT(operand1, operand2);
}
/* Code referring to "OBJECT" corresponds to any Python object and "FLOAT" to Python 'float'. */
static HEDLEY_NEVER_INLINE PyObject *__BINARY_OPERATION_FLOORDIV_OBJECT_OBJECT_FLOAT(PyObject *operand1,
PyObject *operand2) {
PyTypeObject *type1 = Py_TYPE(operand1);
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4101)
#endif
NUITKA_MAY_BE_UNUSED bool cbool_result;
NUITKA_MAY_BE_UNUSED PyObject *obj_result;
#ifdef _MSC_VER
#pragma warning(pop)
#endif
binaryfunc slot1 =
(type1->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type1)) ? type1->tp_as_number->nb_floor_divide : NULL;
binaryfunc slot2 = NULL;
if (!(type1 == &PyFloat_Type)) {
// Different types, need to consider second value slot.
slot2 = PyFloat_Type.tp_as_number->nb_floor_divide;
if (slot1 == slot2) {
slot2 = NULL;
}
}
if (slot1 != NULL) {
PyObject *x = slot1(operand1, operand2);
if (x != Py_NotImplemented) {
obj_result = x;
goto exit_binary_result_object;
}
Py_DECREF(x);
}
if (slot2 != NULL) {
PyObject *x = slot2(operand1, operand2);
if (x != Py_NotImplemented) {
obj_result = x;
goto exit_binary_result_object;
}
Py_DECREF(x);
}
#if PYTHON_VERSION < 0x300
if (!NEW_STYLE_NUMBER_TYPE(type1) || !1) {
coercion c1 =
(type1->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type1)) ? type1->tp_as_number->nb_coerce : NULL;
if (c1 != NULL) {
PyObject *coerced1 = operand1;
PyObject *coerced2 = operand2;
int err = c1(&coerced1, &coerced2);
if (unlikely(err < 0)) {
goto exit_binary_exception;
}
if (err == 0) {
PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
if (likely(mv == NULL)) {
binaryfunc slot = mv->nb_floor_divide;
if (likely(slot != NULL)) {
PyObject *x = slot(coerced1, coerced2);
Py_DECREF(coerced1);
Py_DECREF(coerced2);
obj_result = x;
goto exit_binary_result_object;
}
}
// nb_coerce took a reference.
Py_DECREF(coerced1);
Py_DECREF(coerced2);
}
}
coercion c2 = PyFloat_Type.tp_as_number->nb_coerce;
if (c2 != NULL) {
PyObject *coerced1 = operand1;
PyObject *coerced2 = operand2;
int err = c2(&coerced2, &coerced1);
if (unlikely(err < 0)) {
goto exit_binary_exception;
}
if (err == 0) {
PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
if (likely(mv == NULL)) {
binaryfunc slot = mv->nb_floor_divide;
if (likely(slot != NULL)) {
PyObject *x = slot(coerced1, coerced2);
Py_DECREF(coerced1);
Py_DECREF(coerced2);
obj_result = x;
goto exit_binary_result_object;
}
}
// nb_coerce took a reference.
Py_DECREF(coerced1);
Py_DECREF(coerced2);
}
}
}
#endif
PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for //: '%s' and 'float'", type1->tp_name);
goto exit_binary_exception;
exit_binary_result_object:
return obj_result;
exit_binary_exception:
return NULL;
}
static PyObject *_BINARY_OPERATION_FLOORDIV_OBJECT_OBJECT_FLOAT(PyObject *operand1, PyObject *operand2) {
CHECK_OBJECT(operand1);
CHECK_OBJECT(operand2);
assert(PyFloat_CheckExact(operand2));
PyTypeObject *type1 = Py_TYPE(operand1);
if (type1 == &PyFloat_Type) {
PyObject *result;
// return _BINARY_OPERATION_FLOORDIV_OBJECT_FLOAT_FLOAT(operand1, operand2);
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4101)
#endif
// Not every code path will make use of all possible results.
NUITKA_MAY_BE_UNUSED PyObject *obj_result;
NUITKA_MAY_BE_UNUSED long clong_result;
NUITKA_MAY_BE_UNUSED double cfloat_result;
#ifdef _MSC_VER
#pragma warning(pop)
#endif
CHECK_OBJECT(operand1);
assert(PyFloat_CheckExact(operand1));
CHECK_OBJECT(operand2);
assert(PyFloat_CheckExact(operand2));
const double a = PyFloat_AS_DOUBLE(operand1);
const double b = PyFloat_AS_DOUBLE(operand2);
if (unlikely(b == 0)) {
SET_CURRENT_EXCEPTION_TYPE0_STR(PyExc_ZeroDivisionError, "integer division or modulo by zero");
goto exit_result_exception;
}
{
double mod = fmod(a, b);
double div = (a - mod) / b;
if (mod) {
if ((a < 0) != (mod < 0)) {
div -= 1.0;
}
}
double floordiv;
if (div) {
floordiv = floor(div);
if (div - floordiv > 0.5) {
floordiv += 1.0;
}
} else {
floordiv = copysign(0.0, a / b);
}
cfloat_result = floordiv;
goto exit_result_ok_cfloat;
}
exit_result_ok_cfloat:
result = MAKE_FLOAT_FROM_DOUBLE(cfloat_result);
goto exit_result_ok;
exit_result_ok:
return result;
exit_result_exception:
return NULL;
}
return __BINARY_OPERATION_FLOORDIV_OBJECT_OBJECT_FLOAT(operand1, operand2);
}
PyObject *BINARY_OPERATION_FLOORDIV_OBJECT_OBJECT_FLOAT(PyObject *operand1, PyObject *operand2) {
return _BINARY_OPERATION_FLOORDIV_OBJECT_OBJECT_FLOAT(operand1, operand2);
}
/* Code referring to "FLOAT" corresponds to Python 'float' and "OBJECT" to any Python object. */
static HEDLEY_NEVER_INLINE PyObject *__BINARY_OPERATION_FLOORDIV_OBJECT_FLOAT_OBJECT(PyObject *operand1,
PyObject *operand2) {
PyTypeObject *type2 = Py_TYPE(operand2);
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4101)
#endif
NUITKA_MAY_BE_UNUSED bool cbool_result;
NUITKA_MAY_BE_UNUSED PyObject *obj_result;
#ifdef _MSC_VER
#pragma warning(pop)
#endif
binaryfunc slot1 = PyFloat_Type.tp_as_number->nb_floor_divide;
binaryfunc slot2 = NULL;
if (!(&PyFloat_Type == type2)) {
// Different types, need to consider second value slot.
slot2 =
(type2->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type2)) ? type2->tp_as_number->nb_floor_divide : NULL;
if (slot1 == slot2) {
slot2 = NULL;
}
}
if (slot1 != NULL) {
if (slot2 != NULL) {
if (Nuitka_Type_IsSubtype(type2, &PyFloat_Type)) {
PyObject *x = slot2(operand1, operand2);
if (x != Py_NotImplemented) {
obj_result = x;
goto exit_binary_result_object;
}
Py_DECREF(x);
slot2 = NULL;
}
}
PyObject *x = slot1(operand1, operand2);
if (x != Py_NotImplemented) {
obj_result = x;
goto exit_binary_result_object;
}
Py_DECREF(x);
}
if (slot2 != NULL) {
PyObject *x = slot2(operand1, operand2);
if (x != Py_NotImplemented) {
obj_result = x;
goto exit_binary_result_object;
}
Py_DECREF(x);
}
#if PYTHON_VERSION < 0x300
if (!1 || !NEW_STYLE_NUMBER_TYPE(type2)) {
coercion c1 = PyFloat_Type.tp_as_number->nb_coerce;
if (c1 != NULL) {
PyObject *coerced1 = operand1;
PyObject *coerced2 = operand2;
int err = c1(&coerced1, &coerced2);
if (unlikely(err < 0)) {
goto exit_binary_exception;
}
if (err == 0) {
PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
if (likely(mv == NULL)) {
binaryfunc slot = mv->nb_floor_divide;
if (likely(slot != NULL)) {
PyObject *x = slot(coerced1, coerced2);
Py_DECREF(coerced1);
Py_DECREF(coerced2);
obj_result = x;
goto exit_binary_result_object;
}
}
// nb_coerce took a reference.
Py_DECREF(coerced1);
Py_DECREF(coerced2);
}
}
coercion c2 =
(type2->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type2)) ? type2->tp_as_number->nb_coerce : NULL;
if (c2 != NULL) {
PyObject *coerced1 = operand1;
PyObject *coerced2 = operand2;
int err = c2(&coerced2, &coerced1);
if (unlikely(err < 0)) {
goto exit_binary_exception;
}
if (err == 0) {
PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
if (likely(mv == NULL)) {
binaryfunc slot = mv->nb_floor_divide;
if (likely(slot != NULL)) {
PyObject *x = slot(coerced1, coerced2);
Py_DECREF(coerced1);
Py_DECREF(coerced2);
obj_result = x;
goto exit_binary_result_object;
}
}
// nb_coerce took a reference.
Py_DECREF(coerced1);
Py_DECREF(coerced2);
}
}
}
#endif
PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for //: 'float' and '%s'", type2->tp_name);
goto exit_binary_exception;
exit_binary_result_object:
return obj_result;
exit_binary_exception:
return NULL;
}
static PyObject *_BINARY_OPERATION_FLOORDIV_OBJECT_FLOAT_OBJECT(PyObject *operand1, PyObject *operand2) {
CHECK_OBJECT(operand1);
assert(PyFloat_CheckExact(operand1));
CHECK_OBJECT(operand2);
PyTypeObject *type2 = Py_TYPE(operand2);
if (&PyFloat_Type == type2) {
PyObject *result;
// return _BINARY_OPERATION_FLOORDIV_OBJECT_FLOAT_FLOAT(operand1, operand2);
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4101)
#endif
// Not every code path will make use of all possible results.
NUITKA_MAY_BE_UNUSED PyObject *obj_result;
NUITKA_MAY_BE_UNUSED long clong_result;
NUITKA_MAY_BE_UNUSED double cfloat_result;
#ifdef _MSC_VER
#pragma warning(pop)
#endif
CHECK_OBJECT(operand1);
assert(PyFloat_CheckExact(operand1));
CHECK_OBJECT(operand2);
assert(PyFloat_CheckExact(operand2));
const double a = PyFloat_AS_DOUBLE(operand1);
const double b = PyFloat_AS_DOUBLE(operand2);
if (unlikely(b == 0)) {
SET_CURRENT_EXCEPTION_TYPE0_STR(PyExc_ZeroDivisionError, "integer division or modulo by zero");
goto exit_result_exception;
}
{
double mod = fmod(a, b);
double div = (a - mod) / b;
if (mod) {
if ((a < 0) != (mod < 0)) {
div -= 1.0;
}
}
double floordiv;
if (div) {
floordiv = floor(div);
if (div - floordiv > 0.5) {
floordiv += 1.0;
}
} else {
floordiv = copysign(0.0, a / b);
}
cfloat_result = floordiv;
goto exit_result_ok_cfloat;
}
exit_result_ok_cfloat:
result = MAKE_FLOAT_FROM_DOUBLE(cfloat_result);
goto exit_result_ok;
exit_result_ok:
return result;
exit_result_exception:
return NULL;
}
return __BINARY_OPERATION_FLOORDIV_OBJECT_FLOAT_OBJECT(operand1, operand2);
}
PyObject *BINARY_OPERATION_FLOORDIV_OBJECT_FLOAT_OBJECT(PyObject *operand1, PyObject *operand2) {
return _BINARY_OPERATION_FLOORDIV_OBJECT_FLOAT_OBJECT(operand1, operand2);
}
/* Code referring to "FLOAT" corresponds to Python 'float' and "LONG" to Python2 'long', Python3 'int'. */
static PyObject *_BINARY_OPERATION_FLOORDIV_OBJECT_FLOAT_LONG(PyObject *operand1, PyObject *operand2) {
CHECK_OBJECT(operand1);
assert(PyFloat_CheckExact(operand1));
CHECK_OBJECT(operand2);
assert(PyLong_CheckExact(operand2));
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4101)
#endif
NUITKA_MAY_BE_UNUSED bool cbool_result;
NUITKA_MAY_BE_UNUSED PyObject *obj_result;
#ifdef _MSC_VER
#pragma warning(pop)
#endif
binaryfunc slot1 = PyFloat_Type.tp_as_number->nb_floor_divide;
// Slot2 ignored on purpose, type1 takes precedence.
if (slot1 != NULL) {
PyObject *x = slot1(operand1, operand2);
if (x != Py_NotImplemented) {
obj_result = x;
goto exit_binary_result_object;
}
Py_DECREF(x);
}
// Statically recognized that coercion is not possible with these types
#if PYTHON_VERSION < 0x300
PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for //: 'float' and 'long'");
#else
PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for //: 'float' and 'int'");
#endif
goto exit_binary_exception;
exit_binary_result_object:
return obj_result;
exit_binary_exception:
return NULL;
}
PyObject *BINARY_OPERATION_FLOORDIV_OBJECT_FLOAT_LONG(PyObject *operand1, PyObject *operand2) {
return _BINARY_OPERATION_FLOORDIV_OBJECT_FLOAT_LONG(operand1, operand2);
}
/* Code referring to "LONG" corresponds to Python2 'long', Python3 'int' and "FLOAT" to Python 'float'. */
static PyObject *_BINARY_OPERATION_FLOORDIV_OBJECT_LONG_FLOAT(PyObject *operand1, PyObject *operand2) {
CHECK_OBJECT(operand1);
assert(PyLong_CheckExact(operand1));
CHECK_OBJECT(operand2);
assert(PyFloat_CheckExact(operand2));
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4101)
#endif
NUITKA_MAY_BE_UNUSED bool cbool_result;
NUITKA_MAY_BE_UNUSED PyObject *obj_result;
#ifdef _MSC_VER
#pragma warning(pop)
#endif
// Slot1 ignored on purpose, type2 takes precedence.
binaryfunc slot2 = NULL;
if (!(0)) {
// Different types, need to consider second value slot.
slot2 = PyFloat_Type.tp_as_number->nb_floor_divide;
}
if (slot2 != NULL) {
PyObject *x = slot2(operand1, operand2);
if (x != Py_NotImplemented) {
obj_result = x;
goto exit_binary_result_object;
}
Py_DECREF(x);
}
// Statically recognized that coercion is not possible with these types
#if PYTHON_VERSION < 0x300
PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for //: 'long' and 'float'");
#else
PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for //: 'int' and 'float'");
#endif
goto exit_binary_exception;
exit_binary_result_object:
return obj_result;
exit_binary_exception:
return NULL;
}
PyObject *BINARY_OPERATION_FLOORDIV_OBJECT_LONG_FLOAT(PyObject *operand1, PyObject *operand2) {
return _BINARY_OPERATION_FLOORDIV_OBJECT_LONG_FLOAT(operand1, operand2);
}
#if PYTHON_VERSION < 0x300
/* Code referring to "FLOAT" corresponds to Python 'float' and "INT" to Python2 'int'. */
static PyObject *_BINARY_OPERATION_FLOORDIV_OBJECT_FLOAT_INT(PyObject *operand1, PyObject *operand2) {
CHECK_OBJECT(operand1);
assert(PyFloat_CheckExact(operand1));
CHECK_OBJECT(operand2);
assert(PyInt_CheckExact(operand2));
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4101)
#endif
NUITKA_MAY_BE_UNUSED bool cbool_result;
NUITKA_MAY_BE_UNUSED PyObject *obj_result;
#ifdef _MSC_VER
#pragma warning(pop)
#endif
binaryfunc slot1 = PyFloat_Type.tp_as_number->nb_floor_divide;
// Slot2 ignored on purpose, type1 takes precedence.
if (slot1 != NULL) {
PyObject *x = slot1(operand1, operand2);
if (x != Py_NotImplemented) {
obj_result = x;
goto exit_binary_result_object;
}
Py_DECREF(x);
}
// Statically recognized that coercion is not possible with these types
PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for //: 'float' and 'int'");
goto exit_binary_exception;
exit_binary_result_object:
return obj_result;
exit_binary_exception:
return NULL;
}
PyObject *BINARY_OPERATION_FLOORDIV_OBJECT_FLOAT_INT(PyObject *operand1, PyObject *operand2) {
return _BINARY_OPERATION_FLOORDIV_OBJECT_FLOAT_INT(operand1, operand2);
}
#endif
#if PYTHON_VERSION < 0x300
/* Code referring to "INT" corresponds to Python2 'int' and "FLOAT" to Python 'float'. */
static PyObject *_BINARY_OPERATION_FLOORDIV_OBJECT_INT_FLOAT(PyObject *operand1, PyObject *operand2) {
CHECK_OBJECT(operand1);
assert(PyInt_CheckExact(operand1));
CHECK_OBJECT(operand2);
assert(PyFloat_CheckExact(operand2));
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4101)
#endif
NUITKA_MAY_BE_UNUSED bool cbool_result;
NUITKA_MAY_BE_UNUSED PyObject *obj_result;
#ifdef _MSC_VER
#pragma warning(pop)
#endif
// Slot1 ignored on purpose, type2 takes precedence.
binaryfunc slot2 = NULL;
if (!(0)) {
// Different types, need to consider second value slot.
slot2 = PyFloat_Type.tp_as_number->nb_floor_divide;
}
if (slot2 != NULL) {
PyObject *x = slot2(operand1, operand2);
if (x != Py_NotImplemented) {
obj_result = x;
goto exit_binary_result_object;
}
Py_DECREF(x);
}
// Statically recognized that coercion is not possible with these types
PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for //: 'int' and 'float'");
goto exit_binary_exception;
exit_binary_result_object:
return obj_result;
exit_binary_exception:
return NULL;
}
PyObject *BINARY_OPERATION_FLOORDIV_OBJECT_INT_FLOAT(PyObject *operand1, PyObject *operand2) {
return _BINARY_OPERATION_FLOORDIV_OBJECT_INT_FLOAT(operand1, operand2);
}
#endif
#if PYTHON_VERSION < 0x300
/* Code referring to "LONG" corresponds to Python2 'long', Python3 'int' and "INT" to Python2 'int'. */
static PyObject *_BINARY_OPERATION_FLOORDIV_OBJECT_LONG_INT(PyObject *operand1, PyObject *operand2) {
CHECK_OBJECT(operand1);
assert(PyLong_CheckExact(operand1));
CHECK_OBJECT(operand2);
assert(PyInt_CheckExact(operand2));
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4101)
#endif
NUITKA_MAY_BE_UNUSED bool cbool_result;
NUITKA_MAY_BE_UNUSED PyObject *obj_result;
#ifdef _MSC_VER
#pragma warning(pop)
#endif
binaryfunc slot1 = PyLong_Type.tp_as_number->nb_floor_divide;
// Slot2 ignored on purpose, type1 takes precedence.
if (slot1 != NULL) {
PyObject *x = slot1(operand1, operand2);
if (x != Py_NotImplemented) {
obj_result = x;
goto exit_binary_result_object;
}
Py_DECREF(x);
}
// Statically recognized that coercion is not possible with these types
PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for //: 'long' and 'int'");
goto exit_binary_exception;
exit_binary_result_object:
return obj_result;
exit_binary_exception:
return NULL;
}
PyObject *BINARY_OPERATION_FLOORDIV_OBJECT_LONG_INT(PyObject *operand1, PyObject *operand2) {
return _BINARY_OPERATION_FLOORDIV_OBJECT_LONG_INT(operand1, operand2);
}
#endif
#if PYTHON_VERSION < 0x300
/* Code referring to "INT" corresponds to Python2 'int' and "LONG" to Python2 'long', Python3 'int'. */
static PyObject *_BINARY_OPERATION_FLOORDIV_OBJECT_INT_LONG(PyObject *operand1, PyObject *operand2) {
CHECK_OBJECT(operand1);
assert(PyInt_CheckExact(operand1));
CHECK_OBJECT(operand2);
assert(PyLong_CheckExact(operand2));
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4101)
#endif
NUITKA_MAY_BE_UNUSED bool cbool_result;
NUITKA_MAY_BE_UNUSED PyObject *obj_result;
#ifdef _MSC_VER
#pragma warning(pop)
#endif
// Slot1 ignored on purpose, type2 takes precedence.
binaryfunc slot2 = NULL;
if (!(0)) {
// Different types, need to consider second value slot.
slot2 = PyLong_Type.tp_as_number->nb_floor_divide;
}
if (slot2 != NULL) {
PyObject *x = slot2(operand1, operand2);
if (x != Py_NotImplemented) {
obj_result = x;
goto exit_binary_result_object;
}
Py_DECREF(x);
}
// Statically recognized that coercion is not possible with these types
PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for //: 'int' and 'long'");
goto exit_binary_exception;
exit_binary_result_object:
return obj_result;
exit_binary_exception:
return NULL;
}
PyObject *BINARY_OPERATION_FLOORDIV_OBJECT_INT_LONG(PyObject *operand1, PyObject *operand2) {
return _BINARY_OPERATION_FLOORDIV_OBJECT_INT_LONG(operand1, operand2);
}
#endif
#if PYTHON_VERSION < 0x300
/* Code referring to "INT" corresponds to Python2 'int' and "CLONG" to C platform long value. */
static PyObject *_BINARY_OPERATION_FLOORDIV_OBJECT_INT_CLONG(PyObject *operand1, long operand2) {
CHECK_OBJECT(operand1);
assert(PyInt_CheckExact(operand1));
PyObject *result;
// Not every code path will make use of all possible results.
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4101)
#endif
NUITKA_MAY_BE_UNUSED bool cbool_result;
NUITKA_MAY_BE_UNUSED PyObject *obj_result;
NUITKA_MAY_BE_UNUSED long clong_result;
NUITKA_MAY_BE_UNUSED double cfloat_result;
#ifdef _MSC_VER
#pragma warning(pop)
#endif
CHECK_OBJECT(operand1);
assert(PyInt_CheckExact(operand1));
const long a = PyInt_AS_LONG(operand1);
const long b = operand2;
if (unlikely(b == 0)) {
SET_CURRENT_EXCEPTION_TYPE0_STR(PyExc_ZeroDivisionError, "integer division or modulo by zero");
goto exit_result_exception;
}
/* TODO: Isn't this a very specific value only, of which we could
* hardcode the constant result. Not sure how well the C compiler
* optimizes UNARY_NEG_WOULD_OVERFLOW to this, but dividing by
* -1 has to be rare anyway.
*/
if (likely(b != -1 || !UNARY_NEG_WOULD_OVERFLOW(a))) {
long a_div_b = a / b;
long a_mod_b = (long)(a - (unsigned long)a_div_b * b);
if (a_mod_b && (b ^ a_mod_b) < 0) {
a_mod_b += b;
a_div_b -= 1;
}
clong_result = a_div_b;
goto exit_result_ok_clong;
}
{
PyObject *operand1_object = operand1;
PyObject *operand2_object = PyLong_FromLong(operand2);
PyObject *r = PyLong_Type.tp_as_number->nb_floor_divide(operand1_object, operand2_object);
assert(r != Py_NotImplemented);
Py_DECREF(operand2_object);
obj_result = r;
goto exit_result_object;
}
exit_result_ok_clong:
result = PyInt_FromLong(clong_result);
goto exit_result_ok;
exit_result_object:
if (unlikely(obj_result == NULL)) {
goto exit_result_exception;
}
result = obj_result;
goto exit_result_ok;
exit_result_ok:
return result;
exit_result_exception:
return NULL;
}
PyObject *BINARY_OPERATION_FLOORDIV_OBJECT_INT_CLONG(PyObject *operand1, long operand2) {
return _BINARY_OPERATION_FLOORDIV_OBJECT_INT_CLONG(operand1, operand2);
}
#endif
#if PYTHON_VERSION < 0x300
/* Code referring to "CLONG" corresponds to C platform long value and "INT" to Python2 'int'. */
static PyObject *_BINARY_OPERATION_FLOORDIV_OBJECT_CLONG_INT(long operand1, PyObject *operand2) {
CHECK_OBJECT(operand2);
assert(PyInt_CheckExact(operand2));
PyObject *result;
// Not every code path will make use of all possible results.
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4101)
#endif
NUITKA_MAY_BE_UNUSED bool cbool_result;
NUITKA_MAY_BE_UNUSED PyObject *obj_result;
NUITKA_MAY_BE_UNUSED long clong_result;
NUITKA_MAY_BE_UNUSED double cfloat_result;
#ifdef _MSC_VER
#pragma warning(pop)
#endif
CHECK_OBJECT(operand2);
assert(PyInt_CheckExact(operand2));
const long a = operand1;
const long b = PyInt_AS_LONG(operand2);
if (unlikely(b == 0)) {
SET_CURRENT_EXCEPTION_TYPE0_STR(PyExc_ZeroDivisionError, "integer division or modulo by zero");
goto exit_result_exception;
}
/* TODO: Isn't this a very specific value only, of which we could
* hardcode the constant result. Not sure how well the C compiler
* optimizes UNARY_NEG_WOULD_OVERFLOW to this, but dividing by
* -1 has to be rare anyway.
*/
if (likely(b != -1 || !UNARY_NEG_WOULD_OVERFLOW(a))) {
long a_div_b = a / b;
long a_mod_b = (long)(a - (unsigned long)a_div_b * b);
if (a_mod_b && (b ^ a_mod_b) < 0) {
a_mod_b += b;
a_div_b -= 1;
}
clong_result = a_div_b;
goto exit_result_ok_clong;
}
{
PyObject *operand1_object = PyLong_FromLong(operand1);
PyObject *operand2_object = operand2;
PyObject *r = PyLong_Type.tp_as_number->nb_floor_divide(operand1_object, operand2_object);
assert(r != Py_NotImplemented);
Py_DECREF(operand1_object);
obj_result = r;
goto exit_result_object;
}
exit_result_ok_clong:
result = PyInt_FromLong(clong_result);
goto exit_result_ok;
exit_result_object:
if (unlikely(obj_result == NULL)) {
goto exit_result_exception;
}
result = obj_result;
goto exit_result_ok;
exit_result_ok:
return result;
exit_result_exception:
return NULL;
}
PyObject *BINARY_OPERATION_FLOORDIV_OBJECT_CLONG_INT(long operand1, PyObject *operand2) {
return _BINARY_OPERATION_FLOORDIV_OBJECT_CLONG_INT(operand1, operand2);
}
#endif
/* Code referring to "FLOAT" corresponds to Python 'float' and "CFLOAT" to C platform float value. */
static PyObject *_BINARY_OPERATION_FLOORDIV_OBJECT_FLOAT_CFLOAT(PyObject *operand1, double operand2) {
CHECK_OBJECT(operand1);
assert(PyFloat_CheckExact(operand1));
PyObject *result;
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4101)
#endif
// Not every code path will make use of all possible results.
NUITKA_MAY_BE_UNUSED PyObject *obj_result;
NUITKA_MAY_BE_UNUSED long clong_result;
NUITKA_MAY_BE_UNUSED double cfloat_result;
#ifdef _MSC_VER
#pragma warning(pop)
#endif
CHECK_OBJECT(operand1);
assert(PyFloat_CheckExact(operand1));
const double a = PyFloat_AS_DOUBLE(operand1);
const double b = operand2;
if (unlikely(b == 0)) {
SET_CURRENT_EXCEPTION_TYPE0_STR(PyExc_ZeroDivisionError, "integer division or modulo by zero");
goto exit_result_exception;
}
{
double mod = fmod(a, b);
double div = (a - mod) / b;
if (mod) {
if ((a < 0) != (mod < 0)) {
div -= 1.0;
}
}
double floordiv;
if (div) {
floordiv = floor(div);
if (div - floordiv > 0.5) {
floordiv += 1.0;
}
} else {
floordiv = copysign(0.0, a / b);
}
cfloat_result = floordiv;
goto exit_result_ok_cfloat;
}
exit_result_ok_cfloat:
result = MAKE_FLOAT_FROM_DOUBLE(cfloat_result);
goto exit_result_ok;
exit_result_ok:
return result;
exit_result_exception:
return NULL;
}
PyObject *BINARY_OPERATION_FLOORDIV_OBJECT_FLOAT_CFLOAT(PyObject *operand1, double operand2) {
return _BINARY_OPERATION_FLOORDIV_OBJECT_FLOAT_CFLOAT(operand1, operand2);
}
/* Code referring to "CFLOAT" corresponds to C platform float value and "FLOAT" to Python 'float'. */
static PyObject *_BINARY_OPERATION_FLOORDIV_OBJECT_CFLOAT_FLOAT(double operand1, PyObject *operand2) {
CHECK_OBJECT(operand2);
assert(PyFloat_CheckExact(operand2));
PyObject *result;
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4101)
#endif
// Not every code path will make use of all possible results.
NUITKA_MAY_BE_UNUSED PyObject *obj_result;
NUITKA_MAY_BE_UNUSED long clong_result;
NUITKA_MAY_BE_UNUSED double cfloat_result;
#ifdef _MSC_VER
#pragma warning(pop)
#endif
CHECK_OBJECT(operand2);
assert(PyFloat_CheckExact(operand2));
const double a = operand1;
const double b = PyFloat_AS_DOUBLE(operand2);
if (unlikely(b == 0)) {
SET_CURRENT_EXCEPTION_TYPE0_STR(PyExc_ZeroDivisionError, "integer division or modulo by zero");
goto exit_result_exception;
}
{
double mod = fmod(a, b);
double div = (a - mod) / b;
if (mod) {
if ((a < 0) != (mod < 0)) {
div -= 1.0;
}
}
double floordiv;
if (div) {
floordiv = floor(div);
if (div - floordiv > 0.5) {
floordiv += 1.0;
}
} else {
floordiv = copysign(0.0, a / b);
}
cfloat_result = floordiv;
goto exit_result_ok_cfloat;
}
exit_result_ok_cfloat:
result = MAKE_FLOAT_FROM_DOUBLE(cfloat_result);
goto exit_result_ok;
exit_result_ok:
return result;
exit_result_exception:
return NULL;
}
PyObject *BINARY_OPERATION_FLOORDIV_OBJECT_CFLOAT_FLOAT(double operand1, PyObject *operand2) {
return _BINARY_OPERATION_FLOORDIV_OBJECT_CFLOAT_FLOAT(operand1, operand2);
}
/* Code referring to "OBJECT" corresponds to any Python object and "OBJECT" to any Python object. */
static PyObject *_BINARY_OPERATION_FLOORDIV_OBJECT_OBJECT_OBJECT(PyObject *operand1, PyObject *operand2) {
CHECK_OBJECT(operand1);
CHECK_OBJECT(operand2);
#if PYTHON_VERSION < 0x300
if (PyInt_CheckExact(operand1) && PyInt_CheckExact(operand2)) {
PyObject *result;
// Not every code path will make use of all possible results.
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4101)
#endif
NUITKA_MAY_BE_UNUSED bool cbool_result;
NUITKA_MAY_BE_UNUSED PyObject *obj_result;
NUITKA_MAY_BE_UNUSED long clong_result;
NUITKA_MAY_BE_UNUSED double cfloat_result;
#ifdef _MSC_VER
#pragma warning(pop)
#endif
CHECK_OBJECT(operand1);
assert(PyInt_CheckExact(operand1));
CHECK_OBJECT(operand2);
assert(PyInt_CheckExact(operand2));
const long a = PyInt_AS_LONG(operand1);
const long b = PyInt_AS_LONG(operand2);
if (unlikely(b == 0)) {
SET_CURRENT_EXCEPTION_TYPE0_STR(PyExc_ZeroDivisionError, "integer division or modulo by zero");
goto exit_result_exception;
}
/* TODO: Isn't this a very specific value only, of which we could
* hardcode the constant result. Not sure how well the C compiler
* optimizes UNARY_NEG_WOULD_OVERFLOW to this, but dividing by
* -1 has to be rare anyway.
*/
if (likely(b != -1 || !UNARY_NEG_WOULD_OVERFLOW(a))) {
long a_div_b = a / b;
long a_mod_b = (long)(a - (unsigned long)a_div_b * b);
if (a_mod_b && (b ^ a_mod_b) < 0) {
a_mod_b += b;
a_div_b -= 1;
}
clong_result = a_div_b;
goto exit_result_ok_clong;
}
{
PyObject *operand1_object = operand1;
PyObject *operand2_object = operand2;
PyObject *r = PyLong_Type.tp_as_number->nb_floor_divide(operand1_object, operand2_object);
assert(r != Py_NotImplemented);
obj_result = r;
goto exit_result_object;
}
exit_result_ok_clong:
result = PyInt_FromLong(clong_result);
goto exit_result_ok;
exit_result_object:
if (unlikely(obj_result == NULL)) {
goto exit_result_exception;
}
result = obj_result;
goto exit_result_ok;
exit_result_ok:
return result;
exit_result_exception:
return NULL;
}
#endif
PyTypeObject *type1 = Py_TYPE(operand1);
PyTypeObject *type2 = Py_TYPE(operand2);
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4101)
#endif
NUITKA_MAY_BE_UNUSED bool cbool_result;
NUITKA_MAY_BE_UNUSED PyObject *obj_result;
#ifdef _MSC_VER
#pragma warning(pop)
#endif
binaryfunc slot1 =
(type1->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type1)) ? type1->tp_as_number->nb_floor_divide : NULL;
binaryfunc slot2 = NULL;
if (!(type1 == type2)) {
// Different types, need to consider second value slot.
slot2 =
(type2->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type2)) ? type2->tp_as_number->nb_floor_divide : NULL;
if (slot1 == slot2) {
slot2 = NULL;
}
}
if (slot1 != NULL) {
if (slot2 != NULL) {
if (Nuitka_Type_IsSubtype(type2, type1)) {
PyObject *x = slot2(operand1, operand2);
if (x != Py_NotImplemented) {
obj_result = x;
goto exit_binary_result_object;
}
Py_DECREF(x);
slot2 = NULL;
}
}
PyObject *x = slot1(operand1, operand2);
if (x != Py_NotImplemented) {
obj_result = x;
goto exit_binary_result_object;
}
Py_DECREF(x);
}
if (slot2 != NULL) {
PyObject *x = slot2(operand1, operand2);
if (x != Py_NotImplemented) {
obj_result = x;
goto exit_binary_result_object;
}
Py_DECREF(x);
}
#if PYTHON_VERSION < 0x300
if (!NEW_STYLE_NUMBER_TYPE(type1) || !NEW_STYLE_NUMBER_TYPE(type2)) {
coercion c1 =
(type1->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type1)) ? type1->tp_as_number->nb_coerce : NULL;
if (c1 != NULL) {
PyObject *coerced1 = operand1;
PyObject *coerced2 = operand2;
int err = c1(&coerced1, &coerced2);
if (unlikely(err < 0)) {
goto exit_binary_exception;
}
if (err == 0) {
PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
if (likely(mv == NULL)) {
binaryfunc slot = mv->nb_floor_divide;
if (likely(slot != NULL)) {
PyObject *x = slot(coerced1, coerced2);
Py_DECREF(coerced1);
Py_DECREF(coerced2);
obj_result = x;
goto exit_binary_result_object;
}
}
// nb_coerce took a reference.
Py_DECREF(coerced1);
Py_DECREF(coerced2);
}
}
coercion c2 =
(type2->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type2)) ? type2->tp_as_number->nb_coerce : NULL;
if (c2 != NULL) {
PyObject *coerced1 = operand1;
PyObject *coerced2 = operand2;
int err = c2(&coerced2, &coerced1);
if (unlikely(err < 0)) {
goto exit_binary_exception;
}
if (err == 0) {
PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
if (likely(mv == NULL)) {
binaryfunc slot = mv->nb_floor_divide;
if (likely(slot != NULL)) {
PyObject *x = slot(coerced1, coerced2);
Py_DECREF(coerced1);
Py_DECREF(coerced2);
obj_result = x;
goto exit_binary_result_object;
}
}
// nb_coerce took a reference.
Py_DECREF(coerced1);
Py_DECREF(coerced2);
}
}
}
#endif
PyErr_Format(PyExc_TypeError, "unsupported operand type(s) for //: '%s' and '%s'", type1->tp_name, type2->tp_name);
goto exit_binary_exception;
exit_binary_result_object:
return obj_result;
exit_binary_exception:
return NULL;
}
PyObject *BINARY_OPERATION_FLOORDIV_OBJECT_OBJECT_OBJECT(PyObject *operand1, PyObject *operand2) {
return _BINARY_OPERATION_FLOORDIV_OBJECT_OBJECT_OBJECT(operand1, operand2);
}
|
768a42690ffcefe38e040fb8aa594b5ac16a04f1
|
0da5c3a085933224fc9052502f6027d20c884fae
|
/lucet-wasi/tests/guests/clock_getres.c
|
1a7d90afc8e7fdc45874e1920809065a7db9ac31
|
[
"LLVM-exception",
"Apache-2.0",
"BSD-2-Clause"
] |
permissive
|
bytecodealliance/lucet
|
12720a7234a2aded610d699de79979300e078ea6
|
d0b358c5b4177f6d7382ef4e88e688bca19b4b8d
|
refs/heads/main
| 2022-04-29T04:21:23.430211
| 2022-03-23T22:18:14
| 2022-03-23T22:18:14
| 160,877,137
| 1,669
| 97
|
Apache-2.0
| 2022-03-23T22:18:15
| 2018-12-07T21:27:18
|
Rust
|
UTF-8
|
C
| false
| false
| 462
|
c
|
clock_getres.c
|
#include <assert.h>
#include <time.h>
#include <stdio.h>
#include <errno.h>
int main()
{
struct timespec ts;
// supported clocks
assert(clock_getres(CLOCK_REALTIME, &ts) == 0);
assert(clock_getres(CLOCK_MONOTONIC, &ts) == 0);
// unsupported:
assert(clock_getres(CLOCK_PROCESS_CPUTIME_ID, &ts) != 0);
assert(errno == EBADF);
assert(clock_getres(CLOCK_THREAD_CPUTIME_ID, &ts) != 0);
assert(errno == EBADF);
return 0;
}
|
67707e45d7d0f1abfd6c2660c6854b1f3164a9a6
|
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
|
/stage0/stdlib/Init/Data/UInt/Log2.c
|
923b1da822c374f27a6bea2ac4973365751c7121
|
[
"Apache-2.0",
"LLVM-exception",
"NCSA",
"LGPL-3.0-only",
"LicenseRef-scancode-inner-net-2.0",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Spencer-94",
"LGPL-2.1-or-later",
"HPND",
"LicenseRef-scancode-pcre",
"ISC",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"
] |
permissive
|
leanprover/lean4
|
4bdf9790294964627eb9be79f5e8f6157780b4cc
|
f1f9dc0f2f531af3312398999d8b8303fa5f096b
|
refs/heads/master
| 2023-08-30T01:57:45.786981
| 2023-08-29T23:14:28
| 2023-08-29T23:14:28
| 129,571,436
| 2,827
| 311
|
Apache-2.0
| 2023-09-14T18:29:16
| 2018-04-15T02:49:20
|
Lean
|
UTF-8
|
C
| false
| false
| 2,652
|
c
|
Log2.c
|
// Lean compiler output
// Module: Init.Data.UInt.Log2
// Imports: Init.Data.Fin.Log2
#include <lean/lean.h>
#if defined(__clang__)
#pragma clang diagnostic ignored "-Wunused-parameter"
#pragma clang diagnostic ignored "-Wunused-label"
#elif defined(__GNUC__) && !defined(__CLANG__)
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wunused-label"
#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
#endif
#ifdef __cplusplus
extern "C" {
#endif
LEAN_EXPORT lean_object* l_UInt8_log2___boxed(lean_object*);
uint16_t lean_uint16_log2(uint16_t);
uint32_t lean_uint32_log2(uint32_t);
LEAN_EXPORT lean_object* l_UInt16_log2___boxed(lean_object*);
uint8_t lean_uint8_log2(uint8_t);
LEAN_EXPORT lean_object* l_USize_log2___boxed(lean_object*);
LEAN_EXPORT lean_object* l_UInt32_log2___boxed(lean_object*);
uint64_t lean_uint64_log2(uint64_t);
LEAN_EXPORT lean_object* l_UInt64_log2___boxed(lean_object*);
size_t lean_usize_log2(size_t);
LEAN_EXPORT lean_object* l_UInt8_log2___boxed(lean_object* x_1) {
_start:
{
uint8_t x_2; uint8_t x_3; lean_object* x_4;
x_2 = lean_unbox(x_1);
lean_dec(x_1);
x_3 = lean_uint8_log2(x_2);
x_4 = lean_box(x_3);
return x_4;
}
}
LEAN_EXPORT lean_object* l_UInt16_log2___boxed(lean_object* x_1) {
_start:
{
uint16_t x_2; uint16_t x_3; lean_object* x_4;
x_2 = lean_unbox(x_1);
lean_dec(x_1);
x_3 = lean_uint16_log2(x_2);
x_4 = lean_box(x_3);
return x_4;
}
}
LEAN_EXPORT lean_object* l_UInt32_log2___boxed(lean_object* x_1) {
_start:
{
uint32_t x_2; uint32_t x_3; lean_object* x_4;
x_2 = lean_unbox_uint32(x_1);
lean_dec(x_1);
x_3 = lean_uint32_log2(x_2);
x_4 = lean_box_uint32(x_3);
return x_4;
}
}
LEAN_EXPORT lean_object* l_UInt64_log2___boxed(lean_object* x_1) {
_start:
{
uint64_t x_2; uint64_t x_3; lean_object* x_4;
x_2 = lean_unbox_uint64(x_1);
lean_dec(x_1);
x_3 = lean_uint64_log2(x_2);
x_4 = lean_box_uint64(x_3);
return x_4;
}
}
LEAN_EXPORT lean_object* l_USize_log2___boxed(lean_object* x_1) {
_start:
{
size_t x_2; size_t x_3; lean_object* x_4;
x_2 = lean_unbox_usize(x_1);
lean_dec(x_1);
x_3 = lean_usize_log2(x_2);
x_4 = lean_box_usize(x_3);
return x_4;
}
}
lean_object* initialize_Init_Data_Fin_Log2(uint8_t builtin, lean_object*);
static bool _G_initialized = false;
LEAN_EXPORT lean_object* initialize_Init_Data_UInt_Log2(uint8_t builtin, lean_object* w) {
lean_object * res;
if (_G_initialized) return lean_io_result_mk_ok(lean_box(0));
_G_initialized = true;
res = initialize_Init_Data_Fin_Log2(builtin, lean_io_mk_world());
if (lean_io_result_is_error(res)) return res;
lean_dec_ref(res);
return lean_io_result_mk_ok(lean_box(0));
}
#ifdef __cplusplus
}
#endif
|
c56a6013a70beb69acefeffb6a18871aa4e8cb56
|
3f2489ba277fb3e414884eb5f0051175e9702edf
|
/asf/routes/asf_route_dot.c
|
61b61ac8c3bec721be375e17596c2dbc34c37833
|
[
"PHP-3.01"
] |
permissive
|
yulonghu/asf
|
1790ddbc170960d2e03999835970de60f074f855
|
5542977fa5bd973b79c8750cd8e862bc02ec0ea9
|
refs/heads/master
| 2022-09-04T21:54:29.766735
| 2021-12-21T15:02:23
| 2021-12-21T15:02:23
| 132,080,229
| 291
| 14
|
NOASSERTION
| 2020-04-10T23:17:09
| 2018-05-04T03:18:55
|
C
|
UTF-8
|
C
| false
| false
| 3,809
|
c
|
asf_route_dot.c
|
/*
+----------------------------------------------------------------------+
| API Services Framework |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2018 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Jiapeng Fan <fanjiapeng@126.com> |
+----------------------------------------------------------------------+
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "php_asf.h"
#include "kernel/asf_namespace.h"
#include "asf_router.h"
#include "http/asf_http_request.h"
#include "routes/asf_route_dot.h"
#include "routes/asf_route_query.h"
zend_class_entry *asf_route_dot_ce;
_Bool asf_route_dot_run(asf_route_t *route, asf_http_req_t *request) /* {{{ */
{
zval *dot_name = NULL, *uri = NULL;
zend_string *req_uri = NULL;
int tok_count = 0;
zval *module = NULL, *service = NULL, *action = NULL;
zval args;
dot_name = zend_read_property(asf_route_dot_ce, route, ZEND_STRL(ASF_ROUTE_DOT_PROPETY_NAME), 1, NULL);
uri = asf_http_req_pg_find_len(TRACK_VARS_GET, Z_STRVAL_P(dot_name), Z_STRLEN_P(dot_name));
if (uri && strstr(Z_STRVAL_P(uri), ".") != NULL) {
char *seg = NULL, *saveptr = NULL, *skey = NULL;
size_t len = 0;
array_init(&args);
ASF_G(settled_uri) = zend_string_copy(Z_STR_P(uri));
/* Create string the 'skey' */
skey = estrndup(Z_STRVAL_P(uri), Z_STRLEN_P(uri));
seg = php_strtok_r(skey, ".", &saveptr);
while(seg) {
if (tok_count > 2) {
break;
}
len = strlen(seg);
if (len) {
add_index_string(&args, tok_count, seg);
tok_count++;
}
seg = php_strtok_r(NULL, ".", &saveptr);
}
efree(skey);
switch (tok_count) {
case 2:
service = zend_hash_index_find(Z_ARRVAL(args), 0);
action = zend_hash_index_find(Z_ARRVAL(args), 1);
break;
case 3:
module = zend_hash_index_find(Z_ARRVAL(args), 0);
service = zend_hash_index_find(Z_ARRVAL(args), 1);
action = zend_hash_index_find(Z_ARRVAL(args), 2);
break;
}
}
tok_count = asf_route_query_set(request, module, service, action);
if (IS_ARRAY == Z_TYPE(args)) {
zval_ptr_dtor(&args);
}
return tok_count;
}
/* }}} */
void asf_route_dot_instance(asf_route_t *this_ptr, zval *name) /* {{{ */
{
if (Z_ISUNDEF_P(this_ptr)) {
object_init_ex(this_ptr, asf_route_dot_ce);
}
if (!name || IS_STRING != Z_TYPE_P(name) || Z_STRLEN_P(name) < 1) {
zend_update_property_stringl(asf_route_dot_ce, this_ptr, ZEND_STRL(ASF_ROUTE_DOT_PROPETY_NAME), "method", 6);
} else {
zend_update_property(asf_route_dot_ce, this_ptr, ZEND_STRL(ASF_ROUTE_DOT_PROPETY_NAME), name);
}
}
/* }}} */
ASF_INIT_CLASS(route_dot) /* {{{ */
{
ASF_REGISTER_CLASS_INTERNAL(asf_route_dot, Asf_Route_Dot, Asf\\Route\\Dot, asf_router_ce, NULL);
zend_declare_property_null(asf_route_dot_ce, ZEND_STRL(ASF_ROUTE_DOT_PROPETY_NAME), ZEND_ACC_PROTECTED);
return SUCCESS;
}
/* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/
|
03c9548971af219bbae1ac25e03be1a889fb4c4f
|
4d28185e7a78a569f9a449f39f183cac3024f711
|
/packages/Python/lldbsuite/test/functionalities/signal/handle-segv/main.c
|
27d9b8e500abcb3d0424444989ee96cdaaed0c61
|
[
"NCSA",
"Apache-2.0",
"LLVM-exception"
] |
permissive
|
apple/swift-lldb
|
2789bf44f648609a1674ee520ac20b64c95de072
|
d74be846ef3e62de946df343e8c234bde93a8912
|
refs/heads/stable
| 2023-04-06T00:28:15.882479
| 2019-10-25T22:46:59
| 2019-10-25T22:46:59
| 44,838,862
| 780
| 291
|
Apache-2.0
| 2020-01-10T19:28:43
| 2015-10-23T21:13:18
|
C++
|
UTF-8
|
C
| false
| false
| 1,200
|
c
|
main.c
|
#include <sys/mman.h>
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
enum {
kMmapSize = 0x1000,
kMagicValue = 47,
};
void *address;
volatile sig_atomic_t signaled = 0;
void handler(int sig)
{
signaled = 1;
if (munmap(address, kMmapSize) != 0)
{
perror("munmap");
_exit(5);
}
void* newaddr = mmap(address, kMmapSize, PROT_READ | PROT_WRITE,
MAP_ANON | MAP_FIXED | MAP_PRIVATE, -1, 0);
if (newaddr != address)
{
fprintf(stderr, "Newly mmaped address (%p) does not equal old address (%p).\n",
newaddr, address);
_exit(6);
}
*(int*)newaddr = kMagicValue;
}
int main()
{
if (signal(SIGSEGV, handler) == SIG_ERR)
{
perror("signal");
return 1;
}
address = mmap(NULL, kMmapSize, PROT_NONE, MAP_ANON | MAP_PRIVATE, -1, 0);
if (address == MAP_FAILED)
{
perror("mmap");
return 2;
}
// This should first trigger a segfault. Our handler will make the memory readable and write
// the magic value into memory.
if (*(int*)address != kMagicValue)
return 3;
if (! signaled)
return 4;
return 0;
}
|
87468ee6ea654943a7994fb0dd1ee0f621df67f8
|
5ed64b3dd7ebd036e05240969d621d0c307f367a
|
/rtl-sdr/src/rtl_test.c
|
1f9dda1b441244863c3da9b39541c03e5558e40f
|
[
"Apache-2.0",
"MIT",
"GPL-2.0-only"
] |
permissive
|
bareboat-necessities/my-bareboat
|
bb640fa265e29abaa0619368997343195cb347ff
|
3f72313a1edb175fb1beea4011b406f28bba89bf
|
refs/heads/master
| 2023-08-07T22:48:08.712219
| 2023-07-23T18:25:12
| 2023-07-23T18:25:12
| 221,806,712
| 168
| 24
|
Apache-2.0
| 2023-07-22T21:38:44
| 2019-11-14T23:45:58
|
C
|
UTF-8
|
C
| false
| false
| 11,762
|
c
|
rtl_test.c
|
/*
* rtl-sdr, turns your Realtek RTL2832 based DVB dongle into a SDR receiver
* rtl_test, test and benchmark tool
*
* Copyright (C) 2012-2014 by Steve Markgraf <steve@steve-m.de>
* Copyright (C) 2012-2014 by Kyle Keen <keenerd@gmail.com>
* Copyright (C) 2014 by Michael Tatarinov <kukabu@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <errno.h>
#include <signal.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#ifdef __APPLE__
#include <sys/time.h>
#else
#include <time.h>
#endif
#ifndef _WIN32
#include <unistd.h>
#else
#include <windows.h>
#include "getopt/getopt.h"
#endif
#include "rtl-sdr.h"
#include "convenience/convenience.h"
#define DEFAULT_SAMPLE_RATE 2048000
#define DEFAULT_BUF_LENGTH (16 * 16384)
#define MINIMAL_BUF_LENGTH 512
#define MAXIMAL_BUF_LENGTH (256 * 16384)
#define MHZ(x) ((x)*1000*1000)
#define PPM_DURATION 10
#define PPM_DUMP_TIME 5
#define SCAN_LIMIT 2500000000
struct time_generic
/* holds all the platform specific values */
{
#ifndef _WIN32
time_t tv_sec;
long tv_nsec;
#else
long tv_sec;
long tv_nsec;
int init;
LARGE_INTEGER frequency;
LARGE_INTEGER ticks;
#endif
};
static enum {
NO_BENCHMARK,
TUNER_BENCHMARK,
PPM_BENCHMARK
} test_mode = NO_BENCHMARK;
static int do_exit = 0;
static rtlsdr_dev_t *dev = NULL;
static uint32_t samp_rate = DEFAULT_SAMPLE_RATE;
static uint32_t total_samples = 0;
static uint32_t dropped_samples = 0;
static unsigned int ppm_duration = PPM_DURATION;
void usage(void)
{
fprintf(stderr,
"rtl_test, a benchmark tool for RTL2832 based DVB-T receivers\n\n"
"Usage:\n"
"\t[-s samplerate (default: 2048000 Hz)]\n"
"\t[-d device_index (default: 0)]\n"
"\t[-t enable tuner range benchmark]\n"
"\t[-p[seconds] enable PPM error measurement (default: 10 seconds)]\n"
"\t[-b output_block_size (default: 16 * 16384)]\n"
"\t[-S force sync output (default: async)]\n");
exit(1);
}
#ifdef _WIN32
BOOL WINAPI
sighandler(int signum)
{
if (CTRL_C_EVENT == signum) {
fprintf(stderr, "Signal caught, exiting!\n");
do_exit = 1;
rtlsdr_cancel_async(dev);
return TRUE;
}
return FALSE;
}
#else
static void sighandler(int signum)
{
fprintf(stderr, "Signal caught, exiting!\n");
do_exit = 1;
rtlsdr_cancel_async(dev);
}
#endif
static void underrun_test(unsigned char *buf, uint32_t len, int mute)
{
uint32_t i, lost = 0;
static uint8_t bcnt, uninit = 1;
if (uninit) {
bcnt = buf[0];
uninit = 0;
}
for (i = 0; i < len; i++) {
if(bcnt != buf[i]) {
lost += (buf[i] > bcnt) ? (buf[i] - bcnt) : (bcnt - buf[i]);
bcnt = buf[i];
}
bcnt++;
}
total_samples += len;
dropped_samples += lost;
if (mute)
return;
if (lost)
printf("lost at least %d bytes\n", lost);
}
#ifndef _WIN32
static int ppm_gettime(struct time_generic *tg)
{
int rv = ENOSYS;
struct timespec ts;
#ifdef __unix__
rv = clock_gettime(CLOCK_MONOTONIC, &ts);
tg->tv_sec = ts.tv_sec;
tg->tv_nsec = ts.tv_nsec;
#elif __APPLE__
struct timeval tv;
rv = gettimeofday(&tv, NULL);
ts->tv_sec = tv.tv_sec;
ts->tv_nsec = tv.tv_usec * 1000;
#endif
return rv;
}
#endif
#ifdef _WIN32
static int ppm_gettime(struct time_generic *tg)
{
int rv;
int64_t frac;
if (!tg->init) {
QueryPerformanceFrequency(&tg->frequency);
tg->init = 1;
}
rv = QueryPerformanceCounter(&tg->ticks);
tg->tv_sec = tg->ticks.QuadPart / tg->frequency.QuadPart;
frac = (int64_t)(tg->ticks.QuadPart - (tg->tv_sec * tg->frequency.QuadPart));
tg->tv_nsec = (long)(frac * 1000000000L / (int64_t)tg->frequency.QuadPart);
return !rv;
}
#endif
static int ppm_report(uint64_t nsamples, uint64_t interval)
{
double real_rate, ppm;
real_rate = nsamples * 1e9 / interval;
ppm = 1e6 * (real_rate / (double)samp_rate - 1.);
return (int)round(ppm);
}
static void ppm_test(uint32_t len)
{
static uint64_t nsamples = 0;
static uint64_t interval = 0;
static uint64_t nsamples_total = 0;
static uint64_t interval_total = 0;
static struct time_generic ppm_now;
static struct time_generic ppm_recent;
static enum {
PPM_INIT_NO,
PPM_INIT_DUMP,
PPM_INIT_RUN
} ppm_init = PPM_INIT_NO;
ppm_gettime(&ppm_now);
if (ppm_init != PPM_INIT_RUN) {
/*
* Kyle Keen wrote:
* PPM_DUMP_TIME throws out the first N seconds of data.
* The dongle's PPM is usually very bad when first starting up,
* typically incorrect by more than twice the final value.
* Discarding the first few seconds allows the value to stabilize much faster.
*/
if (ppm_init == PPM_INIT_NO) {
ppm_recent.tv_sec = ppm_now.tv_sec + PPM_DUMP_TIME;
ppm_init = PPM_INIT_DUMP;
return;
}
if (ppm_init == PPM_INIT_DUMP && ppm_recent.tv_sec < ppm_now.tv_sec)
return;
ppm_recent = ppm_now;
ppm_init = PPM_INIT_RUN;
return;
}
nsamples += (uint64_t)(len / 2UL);
interval = (uint64_t)(ppm_now.tv_sec - ppm_recent.tv_sec);
if (interval < ppm_duration)
return;
interval *= 1000000000UL;
interval += (int64_t)(ppm_now.tv_nsec - ppm_recent.tv_nsec);
nsamples_total += nsamples;
interval_total += interval;
printf("real sample rate: %i current PPM: %i cumulative PPM: %i\n",
(int)((1000000000UL * nsamples) / interval),
ppm_report(nsamples, interval),
ppm_report(nsamples_total, interval_total));
ppm_recent = ppm_now;
nsamples = 0;
}
static void rtlsdr_callback(unsigned char *buf, uint32_t len, void *ctx)
{
underrun_test(buf, len, 0);
if (test_mode == PPM_BENCHMARK)
ppm_test(len);
}
/* smallest band or band gap that tuner_benchmark() will notice */
static uint32_t max_step(uint32_t freq) {
if (freq < 1e6)
return 1e4;
if (freq > 1e8)
return 1e6;
return freq / 1e2;
}
/* precision with which tuner_benchmark() will measure the edges of bands */
static uint32_t min_step(uint32_t freq) {
return 100;
}
int confirm_pll_lock(uint32_t f)
{
int i;
for (i=0; i<20; i++) {
if (rtlsdr_set_center_freq(dev, f) >= 0)
return 1;
}
return 0;
}
/* returns last frequency before achieving status of 'lock' */
uint32_t coarse_search(uint32_t start, int lock)
{
uint32_t f = start, f2;
int status;
while (f < SCAN_LIMIT) {
if (do_exit)
break;
f2 = f + max_step(f);
status = rtlsdr_set_center_freq(dev, f2) >= 0;
if (!lock && !status)
status = confirm_pll_lock(f2);
if (status == lock)
return f;
f = f2;
}
return SCAN_LIMIT + 1;
}
/* returns frequency of a transition
* must have one transition between start and start+step */
uint32_t fine_search(uint32_t start, uint32_t step)
{
int low_status, mid_status, high_status;
uint32_t f, stop;
stop = start + step;
f = start + step / 2;
low_status = rtlsdr_set_center_freq(dev, start) >= 0;
high_status = rtlsdr_set_center_freq(dev, stop) >= 0;
if (low_status == high_status)
return start;
while (step > min_step(start)) {
if (do_exit)
break;
mid_status = rtlsdr_set_center_freq(dev, f) >= 0;
if (low_status == mid_status)
start = f;
else
stop = f;
step = stop - start;
f = start + step / 2;
}
return f;
}
void tuner_benchmark(void)
{
uint32_t f = 0, low_bound, high_bound;
fprintf(stderr, "Testing tuner range. This may take a couple of minutes...\n");
while (!do_exit) {
/* find start of a band */
f = coarse_search(f, 1);
low_bound = fine_search(f, max_step(f));
f += max_step(f);
/* find stop of a band */
f = coarse_search(f, 0);
high_bound = fine_search(f, max_step(f));
f += max_step(f);
if (f > SCAN_LIMIT)
break;
fprintf(stderr, "Band: %u - %u Hz\n", low_bound, high_bound);
}
}
int main(int argc, char **argv)
{
#ifndef _WIN32
struct sigaction sigact;
#endif
int n_read, r, opt, i;
int sync_mode = 0;
uint8_t *buffer;
int dev_index = 0;
int dev_given = 0;
uint32_t out_block_size = DEFAULT_BUF_LENGTH;
int count;
int gains[100];
while ((opt = getopt(argc, argv, "d:s:b:tp::Sh")) != -1) {
switch (opt) {
case 'd':
dev_index = verbose_device_search(optarg);
dev_given = 1;
break;
case 's':
samp_rate = (uint32_t)atof(optarg);
break;
case 'b':
out_block_size = (uint32_t)atof(optarg);
break;
case 't':
test_mode = TUNER_BENCHMARK;
break;
case 'p':
test_mode = PPM_BENCHMARK;
if (optarg)
ppm_duration = atoi(optarg);
break;
case 'S':
sync_mode = 1;
break;
case 'h':
default:
usage();
break;
}
}
if(out_block_size < MINIMAL_BUF_LENGTH ||
out_block_size > MAXIMAL_BUF_LENGTH ){
fprintf(stderr,
"Output block size wrong value, falling back to default\n");
fprintf(stderr,
"Minimal length: %u\n", MINIMAL_BUF_LENGTH);
fprintf(stderr,
"Maximal length: %u\n", MAXIMAL_BUF_LENGTH);
out_block_size = DEFAULT_BUF_LENGTH;
}
buffer = malloc(out_block_size * sizeof(uint8_t));
if (!dev_given) {
dev_index = verbose_device_search("0");
}
if (dev_index < 0) {
exit(1);
}
r = rtlsdr_open(&dev, (uint32_t)dev_index);
if (r < 0) {
fprintf(stderr, "Failed to open rtlsdr device #%d.\n", dev_index);
exit(1);
}
#ifndef _WIN32
sigact.sa_handler = sighandler;
sigemptyset(&sigact.sa_mask);
sigact.sa_flags = 0;
sigaction(SIGINT, &sigact, NULL);
sigaction(SIGTERM, &sigact, NULL);
sigaction(SIGQUIT, &sigact, NULL);
sigaction(SIGPIPE, &sigact, NULL);
#else
SetConsoleCtrlHandler( (PHANDLER_ROUTINE) sighandler, TRUE );
#endif
count = rtlsdr_get_tuner_gains(dev, NULL);
fprintf(stderr, "Supported gain values (%d): ", count);
count = rtlsdr_get_tuner_gains(dev, gains);
for (i = 0; i < count; i++)
fprintf(stderr, "%.1f ", gains[i] / 10.0);
fprintf(stderr, "\n");
/* Set the sample rate */
verbose_set_sample_rate(dev, samp_rate);
if (test_mode == TUNER_BENCHMARK) {
tuner_benchmark();
goto exit;
}
/* Enable test mode */
r = rtlsdr_set_testmode(dev, 1);
/* Reset endpoint before we start reading from it (mandatory) */
verbose_reset_buffer(dev);
if ((test_mode == PPM_BENCHMARK) && !sync_mode) {
fprintf(stderr, "Reporting PPM error measurement every %u seconds...\n", ppm_duration);
fprintf(stderr, "Press ^C after a few minutes.\n");
}
if (test_mode == NO_BENCHMARK) {
fprintf(stderr, "\nInfo: This tool will continuously"
" read from the device, and report if\n"
"samples get lost. If you observe no "
"further output, everything is fine.\n\n");
}
if (sync_mode) {
fprintf(stderr, "Reading samples in sync mode...\n");
fprintf(stderr, "(Samples are being lost but not reported.)\n");
while (!do_exit) {
r = rtlsdr_read_sync(dev, buffer, out_block_size, &n_read);
if (r < 0) {
fprintf(stderr, "WARNING: sync read failed.\n");
break;
}
if ((uint32_t)n_read < out_block_size) {
fprintf(stderr, "Short read, samples lost, exiting!\n");
break;
}
underrun_test(buffer, n_read, 1);
}
} else {
fprintf(stderr, "Reading samples in async mode...\n");
r = rtlsdr_read_async(dev, rtlsdr_callback, NULL,
0, out_block_size);
}
if (do_exit) {
fprintf(stderr, "\nUser cancel, exiting...\n");
fprintf(stderr, "Samples per million lost (minimum): %i\n", (int)(1000000L * dropped_samples / total_samples));
}
else
fprintf(stderr, "\nLibrary error %d, exiting...\n", r);
exit:
rtlsdr_close(dev);
free (buffer);
return r >= 0 ? r : -r;
}
|
78eec9e0f21845c5f6ce1ee7ff8150f134ae72d3
|
aa3befea459382dc5c01c925653d54f435b3fb0f
|
/net/ipforward/ipv6_forward.c
|
48698a2e7e423a5efcd65c67eff8174e115f2e43
|
[
"MIT-open-group",
"BSD-3-Clause",
"HPND-sell-variant",
"BSD-4-Clause-UC",
"LicenseRef-scancode-warranty-disclaimer",
"MIT-0",
"LicenseRef-scancode-bsd-atmel",
"LicenseRef-scancode-gary-s-brown",
"LicenseRef-scancode-proprietary-license",
"SunPro",
"MIT",
"LicenseRef-scancode-public-domain-disclaimer",
"LicenseRef-scancode-other-permissive",
"HPND",
"ISC",
"Apache-2.0",
"LicenseRef-scancode-public-domain",
"BSD-2-Clause",
"GPL-1.0-or-later",
"CC-BY-2.0",
"CC-BY-4.0"
] |
permissive
|
apache/nuttx
|
14519a7bff4a87935d94fb8fb2b19edb501c7cec
|
606b6d9310fb25c7d92c6f95bf61737e3c79fa0f
|
refs/heads/master
| 2023-08-25T06:55:45.822534
| 2023-08-23T16:03:31
| 2023-08-24T21:25:47
| 228,103,273
| 407
| 241
|
Apache-2.0
| 2023-09-14T18:26:05
| 2019-12-14T23:27:55
|
C
|
UTF-8
|
C
| false
| false
| 21,884
|
c
|
ipv6_forward.c
|
/****************************************************************************
* net/ipforward/ipv6_forward.c
*
* 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <string.h>
#include <assert.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/mm/iob.h>
#include <nuttx/net/ipv6ext.h>
#include <nuttx/net/net.h>
#include <nuttx/net/netdev.h>
#include <nuttx/net/netstats.h>
#include "netdev/netdev.h"
#include "sixlowpan/sixlowpan.h"
#include "devif/devif.h"
#include "icmpv6/icmpv6.h"
#include "ipforward/ipforward.h"
#if defined(CONFIG_NET_IPFORWARD) && defined(CONFIG_NET_IPv6)
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define PACKET_FORWARDED 0
#define PACKET_NOT_FORWARDED 1
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: ipv6_hdrsize
*
* Description:
* Return the size of the IPv6 header and the following.
*
* Input Parameters:
* ipv6 - A pointer to the IPv6 header in within the IPv6 packet. This
* is immediately followed by the L3 header which may be TCP, UDP,
* or ICMPv6.
*
* Returned Value:
* The size of the combined L2 + L3 headers is returned on success. An
* error is returned only if the prototype is not supported.
*
****************************************************************************/
#ifdef CONFIG_DEBUG_NET_WARN
static int ipv6_hdrsize(FAR struct ipv6_hdr_s *ipv6)
{
/* Size is determined by the following protocol header, */
switch (ipv6->proto)
{
#ifdef CONFIG_NET_TCP
case IP_PROTO_TCP:
{
FAR struct tcp_hdr_s *tcp =
(FAR struct tcp_hdr_s *)((FAR uint8_t *)ipv6 + IPv6_HDRLEN);
unsigned int tcpsize;
/* The TCP header length is encoded in the top 4 bits of the
* tcpoffset field (in units of 32-bit words).
*/
tcpsize = ((uint16_t)tcp->tcpoffset >> 4) << 2;
return IPv6_HDRLEN + tcpsize;
}
break;
#endif
#ifdef CONFIG_NET_UDP
case IP_PROTO_UDP:
return IPv6_HDRLEN + UDP_HDRLEN;
break;
#endif
#ifdef CONFIG_NET_ICMPv6
case IP_PROTO_ICMP6:
return IPv6_HDRLEN + ICMPv6_HDRLEN;
break;
#endif
#ifdef CONFIG_NET_IPFRAG
case NEXT_FRAGMENT_EH:
return IPv6_HDRLEN + EXTHDR_FRAG_LEN;
break;
#endif
default:
nwarn("WARNING: Unrecognized proto: %u\n", ipv6->proto);
return -EPROTONOSUPPORT;
}
}
#endif
/****************************************************************************
* Name: ipv6_decr_ttl
*
* Description:
* Decrement the IPv6 TTL (time to live value). TTL field is set by the
* sender of the packet and reduced by every router on the route to its
* destination. If the TTL field reaches zero before the datagram arrives
* at its destination, then the datagram is discarded and an ICMP error
* packet (11 - Time Exceeded) is sent back to the sender.
*
* The purpose of the TTL field is to avoid a situation in which an
* undeliverable datagram keeps circulating on an Internet system, and
* such a system eventually becoming swamped by such "immortals".
*
* Input Parameters:
* ipv6 - A pointer to the IPv6 header in within the IPv6 packet to be
* forwarded.
*
* Returned Value:
* The new TTL value is returned. A value <= 0 means the hop limit has
* expired.
*
****************************************************************************/
static int ipv6_decr_ttl(FAR struct ipv6_hdr_s *ipv6)
{
int ttl = (int)ipv6->ttl - 1;
if (ttl <= 0)
{
/* Return zero which must cause the packet to be dropped */
return 0;
}
/* Save the updated TTL value */
ipv6->ttl = ttl;
/* NOTE: We do not have to recalculate the IPv6 checksum because (1) the
* IPv6 header does not include a checksum itself and (2) the TTL is not
* included in the sum for the TCP and UDP headers.
*/
return ttl;
}
/****************************************************************************
* Name: ipv6_packet_conversion
*
* Description:
* Generic output conversion hook. Only needed for IEEE802.15.4 for now
* but this is a point where support for other conversions may be
* provided.
*
* Returned Value:
* PACKET_FORWARDED - Packet was forwarded
* PACKET_NOT_FORWARDED - Packet was not forwarded
* < 0 - And error occurred (and packet not forwarded).
*
****************************************************************************/
#ifdef CONFIG_NET_6LOWPAN
static int ipv6_packet_conversion(FAR struct net_driver_s *dev,
FAR struct net_driver_s *fwddev,
FAR struct ipv6_hdr_s *ipv6)
{
int ret = PACKET_NOT_FORWARDED;
if (dev->d_len > 0)
{
/* Check if this is a device served by 6LoWPAN */
if (fwddev->d_lltype != NET_LL_IEEE802154 &&
fwddev->d_lltype != NET_LL_PKTRADIO)
{
nwarn("WARNING: Unsupported link layer... Not forwarded\n");
}
else
#ifdef CONFIG_NET_TCP
if (ipv6->proto == IP_PROTO_TCP)
{
/* Decrement the TTL in the IPv6 header. If it decrements to
* zero, then drop the packet.
*/
ret = ipv6_decr_ttl(ipv6);
if (ret < 1)
{
nwarn("WARNING: Hop limit exceeded... Dropping!\n");
ret = -EMULTIHOP;
}
else
{
/* Let 6LoWPAN convert IPv6 TCP output into IEEE802.15.4
* frames.
*/
sixlowpan_tcp_send(dev, fwddev, ipv6);
/* The packet was forwarded */
dev->d_len = 0;
return PACKET_FORWARDED;
}
}
else
#endif
#ifdef CONFIG_NET_UDP
if (ipv6->proto == IP_PROTO_UDP)
{
/* Decrement the TTL in the IPv6 header. If it decrements to
* zero, then drop the packet.
*/
ret = ipv6_decr_ttl(ipv6);
if (ret < 1)
{
nwarn("WARNING: Hop limit exceeded... Dropping!\n");
ret = -EMULTIHOP;
}
else
{
/* Let 6LoWPAN convert IPv6 UDP output into IEEE802.15.4
* frames.
*/
sixlowpan_udp_send(dev, fwddev, ipv6);
/* The packet was forwarded */
dev->d_len = 0;
return PACKET_FORWARDED;
}
}
else
#endif
#ifdef CONFIG_NET_ICMPv6
if (ipv6->proto == IP_PROTO_ICMP6)
{
/* Decrement the TTL in the IPv6 header. If it decrements to
* zero, then drop the packet.
*/
ret = ipv6_decr_ttl(ipv6);
if (ret < 1)
{
nwarn("WARNING: Hop limit exceeded... Dropping!\n");
ret = -EMULTIHOP;
}
else
{
/* Let 6LoWPAN convert IPv6 ICMPv6 output into IEEE802.15.4
* frames.
*/
sixlowpan_icmpv6_send(dev, fwddev, ipv6);
/* The packet was forwarded */
dev->d_len = 0;
return PACKET_FORWARDED;
}
}
else
#endif
{
/* Otherwise, we cannot forward the packet */
nwarn("WARNING: Dropping. Unsupported 6LoWPAN protocol: %d\n",
ipv6->proto);
}
}
/* The packet was not forwarded (or the HOP limit was exceeded) */
ipv6_dropstats(ipv6);
return ret;
}
#else
# define ipv6_packet_conversion(dev, fwddev, ipv6) (PACKET_NOT_FORWARDED)
#endif /* CONFIG_NET_6LOWPAN */
/****************************************************************************
* Name: ipv6_dev_forward
*
* Description:
* This function is called from ipv6_forward when it is necessary to
* forward a packet from the current device to different device. In this
* case, the forwarding operation must be performed asynchronously when
* the TX poll is received from the forwarding device.
*
* Input Parameters:
* dev - The device on which the packet was received and which
* contains the IPv6 packet.
* fwdddev - The device on which the packet must be forwarded.
* ipv6 - A pointer to the IPv6 header in within the IPv6 packet
*
* Returned Value:
* Zero is returned if the packet was successfully forwarded; A negated
* errno value is returned if the packet is not forwardable. In that
* latter case, the caller (ipv6_input()) should drop the packet.
*
****************************************************************************/
static int ipv6_dev_forward(FAR struct net_driver_s *dev,
FAR struct net_driver_s *fwddev,
FAR struct ipv6_hdr_s *ipv6)
{
FAR struct forward_s *fwd = NULL;
#ifdef CONFIG_DEBUG_NET_WARN
int hdrsize;
#endif
int ret;
/* If the interface isn't "up", we can't forward. */
if ((fwddev->d_flags & IFF_UP) == 0)
{
nwarn("WARNING: device is DOWN\n");
ret = -EHOSTUNREACH;
goto errout;
}
/* Perform any necessary packet conversions. */
ret = ipv6_packet_conversion(dev, fwddev, ipv6);
if (ret < 0)
{
nwarn("WARNING: ipv6_packet_conversion failed: %d\n", ret);
goto errout;
}
else if (ret == PACKET_NOT_FORWARDED)
{
/* Verify that the full packet will fit within the forwarding devices
* MTU. We provide no support for fragmenting forwarded packets.
*/
if (NET_LL_HDRLEN(fwddev) + dev->d_len > NETDEV_PKTSIZE(fwddev))
{
nwarn("WARNING: Packet > MTU... Dropping\n");
ret = -EFBIG;
goto errout;
}
/* Get a pre-allocated forwarding structure, This structure will be
* completely zeroed when we receive it.
*/
fwd = ipfwd_alloc();
if (fwd == NULL)
{
nwarn("WARNING: Failed to allocate forwarding structure\n");
ret = -ENOMEM;
goto errout;
}
/* Initialize the easy stuff in the forwarding structure */
fwd->f_dev = fwddev; /* Forwarding device */
#ifdef CONFIG_NET_IPv4
fwd->f_domain = PF_INET6; /* IPv6 address domain */
#endif
#ifdef CONFIG_DEBUG_NET_WARN
/* Get the size of the IPv6 + L3 header. */
hdrsize = ipv6_hdrsize(ipv6);
if (hdrsize < IPv6_HDRLEN)
{
nwarn("WARNING: Could not determine L2+L3 header size\n");
ret = -EPROTONOSUPPORT;
goto errout_with_fwd;
}
/* The L2/L3 headers must fit within one, contiguous IOB. */
if (hdrsize > CONFIG_IOB_BUFSIZE)
{
nwarn("WARNING: Header is too big for pre-allocated structure\n");
ret = -E2BIG;
goto errout_with_fwd;
}
#endif
/* Relay the device buffer */
fwd->f_iob = dev->d_iob;
/* Decrement the TTL in the copy of the IPv6 header (retaining the
* original TTL in the sourcee to handle the broadcast case). If the
* TTL decrements to zero, then do not forward the packet.
*/
ret = ipv6_decr_ttl(ipv6);
if (ret < 1)
{
nwarn("WARNING: Hop limit exceeded... Dropping!\n");
ret = -EMULTIHOP;
goto errout_with_fwd;
}
/* Then set up to forward the packet according to the protocol. */
ret = ipfwd_forward(fwd);
if (ret >= 0)
{
netdev_iob_clear(dev);
return OK;
}
}
errout_with_fwd:
if (fwd != NULL)
{
ipfwd_free(fwd);
}
errout:
return ret;
}
/****************************************************************************
* Name: ipv6_forward_callback
*
* Description:
* This function is a callback from netdev_foreach. It implements the
* the broadcast forwarding action for each network device (other than, of
* course, the device that received the packet).
*
* Input Parameters:
* dev - The device on which the packet was received and which contains
* the IPv6 packet.
* ipv6 - A convenience pointer to the IPv6 header in within the IPv6
* packet
*
* Returned Value:
* Typically returns zero (meaning to continue the enumeration), but will
* return a non-zero to stop the enumeration if an error occurs.
*
****************************************************************************/
#ifdef CONFIG_NET_IPFORWARD_BROADCAST
static int ipv6_forward_callback(FAR struct net_driver_s *fwddev,
FAR void *arg)
{
FAR struct net_driver_s *dev = (FAR struct net_driver_s *)arg;
FAR struct ipv6_hdr_s *ipv6;
FAR struct iob_s *iob;
int ret;
DEBUGASSERT(fwddev != NULL);
/* Only IFF_UP device and non-loopback device need forward packet */
if (!IFF_IS_UP(fwddev->d_flags) || fwddev->d_lltype == NET_LL_LOOPBACK)
{
return OK;
}
DEBUGASSERT(dev != NULL && dev->d_buf != NULL);
/* Check if we are forwarding on the same device that we received the
* packet from.
*/
if (fwddev != dev)
{
/* Backup the forward IP packet */
iob = iob_tryalloc(true);
if (iob == NULL)
{
nerr("ERROR: iob alloc failed when forward broadcast\n");
return -ENOMEM;
}
iob_reserve(iob, CONFIG_NET_LL_GUARDSIZE);
ret = iob_clone_partial(dev->d_iob, dev->d_iob->io_pktlen, 0,
iob, 0, true, false);
if (ret < 0)
{
iob_free_chain(iob);
return ret;
}
/* Recover the pointer to the IPv6 header in the receiving device's
* d_buf.
*/
ipv6 = IPv6BUF;
/* Send the packet asynchrously on the forwarding device. */
ret = ipv6_dev_forward(dev, fwddev, ipv6);
if (ret < 0)
{
iob_free_chain(iob);
nwarn("WARNING: ipv6_dev_forward failed: %d\n", ret);
return ret;
}
/* Restore device iob with backup iob */
netdev_iob_replace(dev, iob);
}
return OK;
}
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: ipv6_forward
*
* Description:
* This function is called from ipv6_input when a packet is received that
* is not destined for us. In this case, the packet may need to be
* forwarded to another device (or sent back out the same device)
* depending configuration, routing table information, and the IPv6
* networks served by various network devices.
*
* Input Parameters:
* dev - The device on which the packet was received and which contains
* the IPv6 packet.
* ipv6 - A convenience pointer to the IPv6 header in within the IPv6
* packet
*
* On input:
* - dev->d_buf holds the received packet.
* - dev->d_len holds the length of the received packet MINUS the
* size of the L1 header. That was subtracted out by ipv6_input.
* - ipv6 points to the IPv6 header with dev->d_buf.
*
* Returned Value:
* Zero is returned if the packet was successfully forward; A negated
* errno value is returned if the packet is not forwardable. In that
* latter case, the caller (ipv6_input()) should drop the packet.
*
****************************************************************************/
int ipv6_forward(FAR struct net_driver_s *dev, FAR struct ipv6_hdr_s *ipv6)
{
FAR struct net_driver_s *fwddev;
int ret;
/* Search for a device that can forward this packet. */
fwddev = netdev_findby_ripv6addr(ipv6->srcipaddr, ipv6->destipaddr);
if (fwddev == NULL)
{
nwarn("WARNING: Not routable\n");
ret = -ENETUNREACH;
goto drop;
}
/* Check if we are forwarding on the same device that we received the
* packet from.
*/
if (fwddev != dev)
{
/* Send the packet asynchrously on the forwarding device. */
ret = ipv6_dev_forward(dev, fwddev, ipv6);
if (ret < 0)
{
nwarn("WARNING: ipv6_dev_forward failed: %d\n", ret);
goto drop;
}
}
else
#if defined(CONFIG_NET_6LOWPAN) /* REVISIT: Currently only support for 6LoWPAN */
{
/* Single network device. The use case here is where an endpoint acts
* as a hub in a star configuration. This is typical for a wireless
* star configuration where not all endpoints are accessible from all
* other endpoints, but seems less useful for a wired network.
*/
/* Perform any necessary packet conversions. If the packet was handled
* via a backdoor path (or dropped), then dev->d_len will be zero. If
* the packet needs to be forwarded in the normal manner then
* dev->d_len will be unchanged.
*/
ret = ipv6_packet_conversion(dev, dev, ipv6);
if (ret < 0)
{
nwarn("WARNING: ipv6_packet_conversion failed: %d\n", ret);
goto drop;
}
else if (ret == PACKET_NOT_FORWARDED)
{
#ifdef CONFIG_NET_ETHERNET
/* REVISIT:
* For Ethernet we may have to fix up the Ethernet header:
* - source MAC, the MAC of the current device.
* - dest MAC, the MAC associated with the destination IPv6
* address.
* This will involve ICMPv6 and Neighbor Discovery.
*/
/* Correct dev->d_buf by adding back the L1 header length */
#endif
/* Nothing other 6LoWPAN forwarding is currently handled and that
* case was dealt with in ipv6_packet_conversion().
*
* REVISIT: Is this an issue? Do other use cases make sense?
*/
nwarn("WARNING: Packet forwarding supported only for 6LoWPAN\n");
ret = -ENOSYS;
goto drop;
}
}
#else /* CONFIG_NET_6LOWPAN */
{
nwarn(
"WARNING: Packet forwarding not supported in this configuration\n");
ret = -ENOSYS;
goto drop;
}
#endif /* CONFIG_NET_6LOWPAN */
/* Return success. ipv6_input will return to the network driver with
* dev->d_len set to the packet size and the network driver will perform
* the transfer.
*/
return OK;
drop:
ipv6_dropstats(ipv6);
#ifdef CONFIG_NET_ICMPv6
/* Try reply ICMPv6 to the sender. */
switch (ret)
{
case -ENETUNREACH:
icmpv6_reply(dev, ICMPv6_DEST_UNREACHABLE, ICMPv6_ADDR_UNREACH, 0);
return OK;
case -EFBIG:
icmpv6_reply(dev, ICMPv6_PACKET_TOO_BIG, 0,
NETDEV_PKTSIZE(fwddev) - NET_LL_HDRLEN(fwddev));
return OK;
case -EMULTIHOP:
icmpv6_reply(dev, ICMPv6_PACKET_TIME_EXCEEDED, ICMPV6_EXC_HOPLIMIT,
0);
return OK;
default:
break; /* We don't know how to reply, just go on (to drop). */
}
#endif
dev->d_len = 0;
return ret;
}
/****************************************************************************
* Name: ipv6_forward_broadcast
*
* Description:
* This function is called from ipv6_input when a broadcast or multicast
* packet is received. If CONFIG_NET_IPFORWARD_BROADCAST is enabled, this
* function will forward the broadcast packet to other networks through
* other network devices.
*
* Input Parameters:
* dev - The device on which the packet was received and which contains
* the IPv6 packet.
* ipv6 - A convenience pointer to the IPv6 header in within the IPv6
* packet
*
* On input:
* - dev->d_buf holds the received packet.
* - dev->d_len holds the length of the received packet MINUS the
* size of the L1 header. That was subtracted out by ipv6_input.
* - ipv6 points to the IPv6 header with dev->d_buf.
*
* Returned Value:
* None
*
****************************************************************************/
#ifdef CONFIG_NET_IPFORWARD_BROADCAST
void ipv6_forward_broadcast(FAR struct net_driver_s *dev,
FAR struct ipv6_hdr_s *ipv6)
{
/* Don't bother if the TTL would expire */
if (ipv6->ttl > 1)
{
/* Forward the the broadcast/multicast packet to all devices except,
* of course, the device that received the packet.
*/
netdev_foreach(ipv6_forward_callback, dev);
}
}
#endif
#endif /* CONFIG_NET_IPFORWARD && CONFIG_NET_IPv6 */
|
85cf5b556307d05f7344fcc93574333ba7ca4002
|
d453a1364f27ae3c99c1f77f46b084b93d616ccb
|
/rts/c/cache.h
|
5a7d16877002daea5e76a61cae621dee60e3b437
|
[
"ISC"
] |
permissive
|
diku-dk/futhark
|
a41f2f5d3851ea8f854c025482dac00a7b471a9d
|
ea2b8d2600b1d361904091d057ecdadc1deb46a2
|
refs/heads/master
| 2023-08-17T23:44:04.185732
| 2023-08-17T12:05:52
| 2023-08-17T12:05:52
| 7,960,131
| 1,929
| 165
|
ISC
| 2023-08-30T11:38:33
| 2013-02-01T15:07:26
|
Haskell
|
UTF-8
|
C
| false
| false
| 3,786
|
h
|
cache.h
|
// Start of cache.h
#define CACHE_HASH_SIZE 8 // In 32-bit words.
struct cache_hash {
uint32_t hash[CACHE_HASH_SIZE];
};
// Initialise a blank cache.
static void cache_hash_init(struct cache_hash *c);
// Hash some bytes and add them to the accumulated hash.
static void cache_hash(struct cache_hash *out, const char *in, size_t n);
// Try to restore cache contents from a file with the given name.
// Assumes the cache is invalid if it contains the given hash.
// Allocates memory and reads the cache conents, which is returned in
// *buf with size *buflen. If the cache is successfully loaded, this
// function returns 0. Otherwise it returns nonzero. Errno is set if
// the failure to load the cache is due to anything except invalid
// cache conents. Note that failing to restore the cache is not
// necessarily a problem: it might just be invalid or not created yet.
static int cache_restore(const char *fname, const struct cache_hash *hash,
unsigned char **buf, size_t *buflen);
// Store cache contents in the given file, with the given hash.
static int cache_store(const char *fname, const struct cache_hash *hash,
const unsigned char *buf, size_t buflen);
// Now for the implementation.
static void cache_hash_init(struct cache_hash *c) {
memset(c->hash, 0, CACHE_HASH_SIZE * sizeof(uint32_t));
}
static void cache_hash(struct cache_hash *out, const char *in, size_t n) {
// Adaptation of djb2 for larger output size by storing intermediate
// states.
uint32_t hash = 5381;
for (size_t i = 0; i < n; i++) {
hash = ((hash << 5) + hash) + in[i];
out->hash[i % CACHE_HASH_SIZE] ^= hash;
}
}
#define CACHE_HEADER_SIZE 8
static const char cache_header[CACHE_HEADER_SIZE] = "FUTHARK\0";
static int cache_restore(const char *fname, const struct cache_hash *hash,
unsigned char **buf, size_t *buflen) {
FILE *f = fopen(fname, "rb");
if (f == NULL) {
return 1;
}
char f_header[CACHE_HEADER_SIZE];
if (fread(f_header, sizeof(char), CACHE_HEADER_SIZE, f) != CACHE_HEADER_SIZE) {
goto error;
}
if (memcmp(f_header, cache_header, CACHE_HEADER_SIZE) != 0) {
goto error;
}
if (fseek(f, 0, SEEK_END) != 0) {
goto error;
}
int64_t f_size = (int64_t)ftell(f);
if (fseek(f, CACHE_HEADER_SIZE, SEEK_SET) != 0) {
goto error;
}
int64_t expected_size;
if (fread(&expected_size, sizeof(int64_t), 1, f) != 1) {
goto error;
}
if (f_size != expected_size) {
errno = 0;
goto error;
}
int32_t f_hash[CACHE_HASH_SIZE];
if (fread(f_hash, sizeof(int32_t), CACHE_HASH_SIZE, f) != CACHE_HASH_SIZE) {
goto error;
}
if (memcmp(f_hash, hash->hash, CACHE_HASH_SIZE) != 0) {
errno = 0;
goto error;
}
*buflen = f_size - CACHE_HEADER_SIZE - sizeof(int64_t) - CACHE_HASH_SIZE*sizeof(int32_t);
*buf = malloc(*buflen);
if (fread(*buf, sizeof(char), *buflen, f) != *buflen) {
free(*buf);
goto error;
}
fclose(f);
return 0;
error:
fclose(f);
return 1;
}
static int cache_store(const char *fname, const struct cache_hash *hash,
const unsigned char *buf, size_t buflen) {
FILE *f = fopen(fname, "wb");
if (f == NULL) {
return 1;
}
if (fwrite(cache_header, CACHE_HEADER_SIZE, 1, f) != 1) {
goto error;
}
int64_t size = CACHE_HEADER_SIZE + sizeof(int64_t) + CACHE_HASH_SIZE*sizeof(int32_t) + buflen;
if (fwrite(&size, sizeof(size), 1, f) != 1) {
goto error;
}
if (fwrite(hash->hash, sizeof(int32_t), CACHE_HASH_SIZE, f) != CACHE_HASH_SIZE) {
goto error;
}
if (fwrite(buf, sizeof(unsigned char), buflen, f) != buflen) {
goto error;
}
fclose(f);
return 0;
error:
fclose(f);
return 1;
}
// End of cache.h
|
bb0a1d936330db4bed8a024314ef94ea60997f90
|
376e1818d427b5e4d32fa6dd6c7b71e9fd88afdb
|
/geography/gpxsee/patches/patch-src_config.h
|
88a34d7391891db7a95f301e16c86e3a966271f8
|
[] |
no_license
|
NetBSD/pkgsrc
|
a0732c023519650ef821ab89c23ab6ab59e25bdb
|
d042034ec4896cc5b47ed6f2e5b8802d9bc5c556
|
refs/heads/trunk
| 2023-09-01T07:40:12.138283
| 2023-09-01T05:25:19
| 2023-09-01T05:25:19
| 88,439,572
| 321
| 138
| null | 2023-07-12T22:34:14
| 2017-04-16T20:04:15
| null |
UTF-8
|
C
| false
| false
| 1,098
|
h
|
patch-src_config.h
|
$NetBSD: patch-src_config.h,v 1.1.1.1 2018/10/19 08:57:22 abs Exp $
Allow GLOBAL_DIR to be overridden by build system
--- src/config.h.orig 2018-10-11 16:19:35.000000000 +0000
+++ src/config.h
@@ -21,14 +21,19 @@
#if defined(Q_OS_WIN32)
#define USER_DIR QDir::homePath() + QString("/GPXSee")
-#define GLOBAL_DIR QApplication::applicationDirPath()
+#define DEFAULT_GLOBAL_DIR QApplication::applicationDirPath()
#elif defined(Q_OS_MAC)
#define USER_DIR QDir::homePath() + QString("/.gpxsee")
-#define GLOBAL_DIR QApplication::applicationDirPath() \
+#define DEFAULT_GLOBAL_DIR QApplication::applicationDirPath() \
+ QString("/../Resources")
#else
#define USER_DIR QDir::homePath() + QString("/.gpxsee")
-#define GLOBAL_DIR QString("/usr/share/gpxsee")
+#define DEFAULT_GLOBAL_DIR QString("/usr/share/gpxsee")
+#endif
+#ifdef GPXSEE_GLOBAL_DIR
+#define GLOBAL_DIR QString(GPXSEE_GLOBAL_DIR)
+#else
+#define GLOBAL_DIR DEFAULT_GLOBAL_DIR
#endif
#define USER_CSV_DIR USER_DIR + QString("/") + CSV_DIR
|
62c620adad1d2e596c5bb5280dffeeb71cc148a3
|
8ef75ec298e38373a3b9b212eac2762f6c452a25
|
/SDL2_mixer/music.c
|
a09373f8dc1ffb810a3d1236f25a760ef350d519
|
[
"MIT",
"Zlib",
"GPL-1.0-or-later"
] |
permissive
|
mozeal/SDL_gui
|
dc0d529ba300df41ed0fcb26ec3e176a49cfb316
|
31bcfbf9c9a5803dc0ffb022b7e7abd76e5c3cfd
|
refs/heads/master
| 2022-05-05T06:18:51.640215
| 2022-04-01T11:23:12
| 2022-04-01T11:23:12
| 48,752,765
| 321
| 67
|
MIT
| 2021-04-21T14:38:23
| 2015-12-29T15:06:32
|
C
|
UTF-8
|
C
| false
| false
| 31,484
|
c
|
music.c
|
/*
SDL_mixer: An audio mixer library based on the SDL library
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include <string.h> /* for strtok() and strtok_s() */
#include "SDL_hints.h"
#include "SDL_log.h"
#include "SDL_timer.h"
#include "SDL_mixer.h"
#include "mixer.h"
#include "music.h"
#include "music_cmd.h"
#include "music_wav.h"
#include "music_mikmod.h"
#include "music_modplug.h"
#include "music_nativemidi.h"
#include "music_fluidsynth.h"
#include "music_timidity.h"
#include "music_ogg.h"
#include "music_opus.h"
#include "music_mpg123.h"
#include "music_mad.h"
#include "music_flac.h"
#include "native_midi/native_midi.h"
/* Check to make sure we are building with a new enough SDL */
#if SDL_COMPILEDVERSION < SDL_VERSIONNUM(2, 0, 7)
#error You need SDL 2.0.7 or newer from http://www.libsdl.org
#endif
/* Set this hint to true if you want verbose logging of music interfaces */
#define SDL_MIXER_HINT_DEBUG_MUSIC_INTERFACES \
"SDL_MIXER_DEBUG_MUSIC_INTERFACES"
char *music_cmd = NULL;
static SDL_bool music_active = SDL_TRUE;
static int music_volume = MIX_MAX_VOLUME;
static Mix_Music * volatile music_playing = NULL;
SDL_AudioSpec music_spec;
struct _Mix_Music {
Mix_MusicInterface *interface;
void *context;
SDL_bool playing;
Mix_Fading fading;
int fade_step;
int fade_steps;
};
/* Used to calculate fading steps */
static int ms_per_step;
/* rcg06042009 report available decoders at runtime. */
static const char **music_decoders = NULL;
static int num_decoders = 0;
/* Semicolon-separated SoundFont paths */
static char* soundfont_paths = NULL;
/* Interfaces for the various music interfaces, ordered by priority */
static Mix_MusicInterface *s_music_interfaces[] =
{
#ifdef MUSIC_CMD
&Mix_MusicInterface_CMD,
#endif
#ifdef MUSIC_WAV
&Mix_MusicInterface_WAV,
#endif
#ifdef MUSIC_FLAC
&Mix_MusicInterface_FLAC,
#endif
#ifdef MUSIC_OGG
&Mix_MusicInterface_OGG,
#endif
#ifdef MUSIC_OPUS
&Mix_MusicInterface_Opus,
#endif
#ifdef MUSIC_MP3_MPG123
&Mix_MusicInterface_MPG123,
#endif
#ifdef MUSIC_MP3_MAD
&Mix_MusicInterface_MAD,
#endif
#ifdef MUSIC_MOD_MODPLUG
&Mix_MusicInterface_MODPLUG,
#endif
#ifdef MUSIC_MOD_MIKMOD
&Mix_MusicInterface_MIKMOD,
#endif
#ifdef MUSIC_MID_FLUIDSYNTH
&Mix_MusicInterface_FLUIDSYNTH,
#endif
#ifdef MUSIC_MID_TIMIDITY
&Mix_MusicInterface_TIMIDITY,
#endif
#ifdef MUSIC_MID_NATIVE
&Mix_MusicInterface_NATIVEMIDI,
#endif
};
int get_num_music_interfaces(void)
{
return SDL_arraysize(s_music_interfaces);
}
Mix_MusicInterface *get_music_interface(int index)
{
return s_music_interfaces[index];
}
int Mix_GetNumMusicDecoders(void)
{
return(num_decoders);
}
const char *Mix_GetMusicDecoder(int index)
{
if ((index < 0) || (index >= num_decoders)) {
return NULL;
}
return(music_decoders[index]);
}
static void add_music_decoder(const char *decoder)
{
void *ptr;
int i;
/* Check to see if we already have this decoder */
for (i = 0; i < num_decoders; ++i) {
if (SDL_strcmp(music_decoders[i], decoder) == 0) {
return;
}
}
ptr = SDL_realloc((void *)music_decoders, (num_decoders + 1) * sizeof (const char *));
if (ptr == NULL) {
return; /* oh well, go on without it. */
}
music_decoders = (const char **) ptr;
music_decoders[num_decoders++] = decoder;
}
/* Local low-level functions prototypes */
static void music_internal_initialize_volume(void);
static void music_internal_volume(int volume);
static int music_internal_play(Mix_Music *music, int play_count, double position);
static int music_internal_position(double position);
static SDL_bool music_internal_playing(void);
static void music_internal_halt(void);
/* Support for hooking when the music has finished */
static void (SDLCALL *music_finished_hook)(void) = NULL;
void Mix_HookMusicFinished(void (SDLCALL *music_finished)(void))
{
Mix_LockAudio();
music_finished_hook = music_finished;
Mix_UnlockAudio();
}
/* Convenience function to fill audio and mix at the specified volume
This is called from many music player's GetAudio callback.
*/
int music_pcm_getaudio(void *context, void *data, int bytes, int volume,
int (*GetSome)(void *context, void *data, int bytes, SDL_bool *done))
{
Uint8 *snd = (Uint8 *)data;
Uint8 *dst;
int len = bytes;
SDL_bool done = SDL_FALSE;
if (volume == MIX_MAX_VOLUME) {
dst = snd;
} else {
dst = SDL_stack_alloc(Uint8, bytes);
}
while (len > 0 && !done) {
int consumed = GetSome(context, dst, len, &done);
if (consumed < 0) {
break;
}
if (volume == MIX_MAX_VOLUME) {
dst += consumed;
} else {
SDL_MixAudioFormat(snd, dst, music_spec.format, (Uint32)consumed, volume);
snd += consumed;
}
len -= consumed;
}
if (volume != MIX_MAX_VOLUME) {
SDL_stack_free(dst);
}
return len;
}
/* Mixing function */
void SDLCALL music_mixer(void *udata, Uint8 *stream, int len)
{
while (music_playing && music_active && len > 0) {
/* Handle fading */
if (music_playing->fading != MIX_NO_FADING) {
if (music_playing->fade_step++ < music_playing->fade_steps) {
int volume;
int fade_step = music_playing->fade_step;
int fade_steps = music_playing->fade_steps;
if (music_playing->fading == MIX_FADING_OUT) {
volume = (music_volume * (fade_steps-fade_step)) / fade_steps;
} else { /* Fading in */
volume = (music_volume * fade_step) / fade_steps;
}
music_internal_volume(volume);
} else {
if (music_playing->fading == MIX_FADING_OUT) {
music_internal_halt();
if (music_finished_hook) {
music_finished_hook();
}
return;
}
music_playing->fading = MIX_NO_FADING;
}
}
if (music_playing->interface->GetAudio) {
int left = music_playing->interface->GetAudio(music_playing->context, stream, len);
if (left != 0) {
/* Either an error or finished playing with data left */
music_playing->playing = SDL_FALSE;
}
if (left > 0) {
stream += (len - left);
len = left;
} else {
len = 0;
}
} else {
len = 0;
}
if (!music_internal_playing()) {
music_internal_halt();
if (music_finished_hook) {
music_finished_hook();
}
}
}
}
/* Load the music interface libraries for a given music type */
SDL_bool load_music_type(Mix_MusicType type)
{
int i, loaded = 0;
for (i = 0; i < SDL_arraysize(s_music_interfaces); ++i) {
Mix_MusicInterface *interface = s_music_interfaces[i];
if (interface->type != type) {
continue;
}
if (!interface->loaded) {
char hint[64];
SDL_snprintf(hint, sizeof(hint), "SDL_MIXER_DISABLE_%s", interface->tag);
if (SDL_GetHintBoolean(hint, SDL_FALSE)) {
continue;
}
if (interface->Load && interface->Load() < 0) {
if (SDL_GetHintBoolean(SDL_MIXER_HINT_DEBUG_MUSIC_INTERFACES, SDL_FALSE)) {
SDL_Log("Couldn't load %s: %s\n", interface->tag, Mix_GetError());
}
continue;
}
interface->loaded = SDL_TRUE;
}
++loaded;
}
return (loaded > 0) ? SDL_TRUE : SDL_FALSE;
}
/* Open the music interfaces for a given music type */
SDL_bool open_music_type(Mix_MusicType type)
{
int i, opened = 0;
SDL_bool use_native_midi = SDL_FALSE;
if (!music_spec.format) {
/* Music isn't opened yet */
return SDL_FALSE;
}
#ifdef MUSIC_MID_NATIVE
if (type == MUS_MID && SDL_GetHintBoolean("SDL_NATIVE_MUSIC", SDL_FALSE) && native_midi_detect()) {
use_native_midi = SDL_TRUE;
}
#endif
for (i = 0; i < SDL_arraysize(s_music_interfaces); ++i) {
Mix_MusicInterface *interface = s_music_interfaces[i];
if (!interface->loaded) {
continue;
}
if (type != MUS_NONE && interface->type != type) {
continue;
}
if (interface->type == MUS_MID && use_native_midi && interface->api != MIX_MUSIC_NATIVEMIDI) {
continue;
}
if (!interface->opened) {
if (interface->Open && interface->Open(&music_spec) < 0) {
if (SDL_GetHintBoolean(SDL_MIXER_HINT_DEBUG_MUSIC_INTERFACES, SDL_FALSE)) {
SDL_Log("Couldn't open %s: %s\n", interface->tag, Mix_GetError());
}
continue;
}
interface->opened = SDL_TRUE;
add_music_decoder(interface->tag);
}
++opened;
}
if (has_music(MUS_MOD)) {
add_music_decoder("MOD");
add_chunk_decoder("MOD");
}
if (has_music(MUS_MID)) {
add_music_decoder("MIDI");
add_chunk_decoder("MID");
}
if (has_music(MUS_OGG)) {
add_music_decoder("OGG");
add_chunk_decoder("OGG");
}
if (has_music(MUS_OPUS)) {
add_music_decoder("OPUS");
add_chunk_decoder("OPUS");
}
if (has_music(MUS_MP3)) {
add_music_decoder("MP3");
add_chunk_decoder("MP3");
}
if (has_music(MUS_FLAC)) {
add_music_decoder("FLAC");
add_chunk_decoder("FLAC");
}
return (opened > 0) ? SDL_TRUE : SDL_FALSE;
}
/* Initialize the music interfaces with a certain desired audio format */
void open_music(const SDL_AudioSpec *spec)
{
#ifdef MIX_INIT_SOUNDFONT_PATHS
if (!soundfont_paths) {
soundfont_paths = SDL_strdup(MIX_INIT_SOUNDFONT_PATHS);
}
#endif
/* Load the music interfaces that don't have explicit initialization */
load_music_type(MUS_CMD);
load_music_type(MUS_WAV);
/* Open all the interfaces that are loaded */
music_spec = *spec;
open_music_type(MUS_NONE);
Mix_VolumeMusic(MIX_MAX_VOLUME);
/* Calculate the number of ms for each callback */
ms_per_step = (int) (((float)spec->samples * 1000.0) / spec->freq);
}
/* Return SDL_TRUE if the music type is available */
SDL_bool has_music(Mix_MusicType type)
{
int i;
for (i = 0; i < SDL_arraysize(s_music_interfaces); ++i) {
Mix_MusicInterface *interface = s_music_interfaces[i];
if (interface->type != type) {
continue;
}
if (interface->opened) {
return SDL_TRUE;
}
}
return SDL_FALSE;
}
Mix_MusicType detect_music_type_from_magic(const Uint8 *magic)
{
/* Ogg Vorbis files have the magic four bytes "OggS" */
if (SDL_memcmp(magic, "OggS", 4) == 0) {
return MUS_OGG;
}
/* FLAC files have the magic four bytes "fLaC" */
if (SDL_memcmp(magic, "fLaC", 4) == 0) {
return MUS_FLAC;
}
/* MIDI files have the magic four bytes "MThd" */
if (SDL_memcmp(magic, "MThd", 4) == 0) {
return MUS_MID;
}
if (SDL_memcmp(magic, "ID3", 3) == 0 ||
(magic[0] == 0xFF && (magic[1] & 0xFE) == 0xFA)) {
return MUS_MP3;
}
/* Assume MOD format.
*
* Apparently there is no way to check if the file is really a MOD,
* or there are too many formats supported by MikMod/ModPlug, or
* MikMod/ModPlug does this check by itself. */
return MUS_MOD;
}
static Mix_MusicType detect_music_type(SDL_RWops *src)
{
Uint8 magic[12];
Mix_MusicType t;
if (SDL_RWread(src, magic, 1, 12) != 12) {
Mix_SetError("Couldn't read first 12 bytes of audio data");
return MUS_NONE;
}
SDL_RWseek(src, -12, RW_SEEK_CUR);
/* WAVE files have the magic four bytes "RIFF"
AIFF files have the magic 12 bytes "FORM" XXXX "AIFF" */
if (((SDL_memcmp(magic, "RIFF", 4) == 0) && (SDL_memcmp((magic+8), "WAVE", 4) == 0)) ||
(SDL_memcmp(magic, "FORM", 4) == 0)) {
return MUS_WAV;
}
t = detect_music_type_from_magic(magic);
if (t == MUS_OGG) {
Sint64 pos = SDL_RWtell(src);
SDL_RWseek(src, 28, RW_SEEK_CUR);
SDL_RWread(src, magic, 1, 8);
SDL_RWseek(src, pos, RW_SEEK_SET);
if (SDL_memcmp(magic, "OpusHead", 8) == 0) {
return MUS_OPUS;
}
}
return t;
}
/* Load a music file */
Mix_Music *Mix_LoadMUS(const char *file)
{
int i;
void *context;
char *ext;
Mix_MusicType type;
SDL_RWops *src;
for (i = 0; i < SDL_arraysize(s_music_interfaces); ++i) {
Mix_MusicInterface *interface = s_music_interfaces[i];
if (!interface->opened || !interface->CreateFromFile) {
continue;
}
context = interface->CreateFromFile(file);
if (context) {
/* Allocate memory for the music structure */
Mix_Music *music = (Mix_Music *)SDL_calloc(1, sizeof(Mix_Music));
if (music == NULL) {
Mix_SetError("Out of memory");
return NULL;
}
music->interface = interface;
music->context = context;
return music;
}
}
src = SDL_RWFromFile(file, "rb");
if (src == NULL) {
Mix_SetError("Couldn't open '%s'", file);
return NULL;
}
/* Use the extension as a first guess on the file type */
type = MUS_NONE;
ext = strrchr(file, '.');
if (ext) {
++ext; /* skip the dot in the extension */
if (SDL_strcasecmp(ext, "WAV") == 0) {
type = MUS_WAV;
} else if (SDL_strcasecmp(ext, "MID") == 0 ||
SDL_strcasecmp(ext, "MIDI") == 0 ||
SDL_strcasecmp(ext, "KAR") == 0) {
type = MUS_MID;
} else if (SDL_strcasecmp(ext, "OGG") == 0) {
type = MUS_OGG;
} else if (SDL_strcasecmp(ext, "OPUS") == 0) {
type = MUS_OPUS;
} else if (SDL_strcasecmp(ext, "FLAC") == 0) {
type = MUS_FLAC;
} else if (SDL_strcasecmp(ext, "MPG") == 0 ||
SDL_strcasecmp(ext, "MPEG") == 0 ||
SDL_strcasecmp(ext, "MP3") == 0 ||
SDL_strcasecmp(ext, "MAD") == 0) {
type = MUS_MP3;
} else if (SDL_strcasecmp(ext, "669") == 0 ||
SDL_strcasecmp(ext, "AMF") == 0 ||
SDL_strcasecmp(ext, "AMS") == 0 ||
SDL_strcasecmp(ext, "DBM") == 0 ||
SDL_strcasecmp(ext, "DSM") == 0 ||
SDL_strcasecmp(ext, "FAR") == 0 ||
SDL_strcasecmp(ext, "IT") == 0 ||
SDL_strcasecmp(ext, "MED") == 0 ||
SDL_strcasecmp(ext, "MDL") == 0 ||
SDL_strcasecmp(ext, "MOD") == 0 ||
SDL_strcasecmp(ext, "MOL") == 0 ||
SDL_strcasecmp(ext, "MTM") == 0 ||
SDL_strcasecmp(ext, "NST") == 0 ||
SDL_strcasecmp(ext, "OKT") == 0 ||
SDL_strcasecmp(ext, "PTM") == 0 ||
SDL_strcasecmp(ext, "S3M") == 0 ||
SDL_strcasecmp(ext, "STM") == 0 ||
SDL_strcasecmp(ext, "ULT") == 0 ||
SDL_strcasecmp(ext, "UMX") == 0 ||
SDL_strcasecmp(ext, "WOW") == 0 ||
SDL_strcasecmp(ext, "XM") == 0) {
type = MUS_MOD;
}
}
return Mix_LoadMUSType_RW(src, type, SDL_TRUE);
}
Mix_Music *Mix_LoadMUS_RW(SDL_RWops *src, int freesrc)
{
return Mix_LoadMUSType_RW(src, MUS_NONE, freesrc);
}
Mix_Music *Mix_LoadMUSType_RW(SDL_RWops *src, Mix_MusicType type, int freesrc)
{
int i;
void *context;
Sint64 start;
if (!src) {
Mix_SetError("RWops pointer is NULL");
return NULL;
}
start = SDL_RWtell(src);
/* If the caller wants auto-detection, figure out what kind of file
* this is. */
if (type == MUS_NONE) {
if ((type = detect_music_type(src)) == MUS_NONE) {
/* Don't call Mix_SetError() since detect_music_type() does that. */
if (freesrc) {
SDL_RWclose(src);
}
return NULL;
}
}
Mix_ClearError();
if (load_music_type(type) && open_music_type(type)) {
for (i = 0; i < SDL_arraysize(s_music_interfaces); ++i) {
Mix_MusicInterface *interface = s_music_interfaces[i];
if (!interface->opened || type != interface->type || !interface->CreateFromRW) {
continue;
}
context = interface->CreateFromRW(src, freesrc);
if (context) {
/* Allocate memory for the music structure */
Mix_Music *music = (Mix_Music *)SDL_calloc(1, sizeof(Mix_Music));
if (music == NULL) {
interface->Delete(context);
Mix_SetError("Out of memory");
return NULL;
}
music->interface = interface;
music->context = context;
if (SDL_GetHintBoolean(SDL_MIXER_HINT_DEBUG_MUSIC_INTERFACES, SDL_FALSE)) {
SDL_Log("Loaded music with %s\n", interface->tag);
}
return music;
}
/* Reset the stream for the next decoder */
SDL_RWseek(src, start, RW_SEEK_SET);
}
}
if (!*Mix_GetError()) {
Mix_SetError("Unrecognized audio format");
}
if (freesrc) {
SDL_RWclose(src);
} else {
SDL_RWseek(src, start, RW_SEEK_SET);
}
return NULL;
}
/* Free a music chunk previously loaded */
void Mix_FreeMusic(Mix_Music *music)
{
if (music) {
/* Stop the music if it's currently playing */
Mix_LockAudio();
if (music == music_playing) {
/* Wait for any fade out to finish */
while (music->fading == MIX_FADING_OUT) {
Mix_UnlockAudio();
SDL_Delay(100);
Mix_LockAudio();
}
if (music == music_playing) {
music_internal_halt();
}
}
Mix_UnlockAudio();
music->interface->Delete(music->context);
SDL_free(music);
}
}
/* Find out the music format of a mixer music, or the currently playing
music, if 'music' is NULL.
*/
Mix_MusicType Mix_GetMusicType(const Mix_Music *music)
{
Mix_MusicType type = MUS_NONE;
if (music) {
type = music->interface->type;
} else {
Mix_LockAudio();
if (music_playing) {
type = music_playing->interface->type;
}
Mix_UnlockAudio();
}
return(type);
}
/* Play a music chunk. Returns 0, or -1 if there was an error.
*/
static int music_internal_play(Mix_Music *music, int play_count, double position)
{
int retval = 0;
#if defined(__MACOSX__) && defined(MID_MUSIC_NATIVE)
/* This fixes a bug with native MIDI on Mac OS X, where you
can't really stop and restart MIDI from the audio callback.
*/
if (music == music_playing && music->api == MIX_MUSIC_NATIVEMIDI) {
/* Just a seek suffices to restart playing */
music_internal_position(position);
return 0;
}
#endif
/* Note the music we're playing */
if (music_playing) {
music_internal_halt();
}
music_playing = music;
music_playing->playing = SDL_TRUE;
/* Set the initial volume */
music_internal_initialize_volume();
/* Set up for playback */
retval = music->interface->Play(music->context, play_count);
/* Set the playback position, note any errors if an offset is used */
if (retval == 0) {
if (position > 0.0) {
if (music_internal_position(position) < 0) {
Mix_SetError("Position not implemented for music type");
retval = -1;
}
} else {
music_internal_position(0.0);
}
}
/* If the setup failed, we're not playing any music anymore */
if (retval < 0) {
music->playing = SDL_FALSE;
music_playing = NULL;
}
return(retval);
}
int Mix_FadeInMusicPos(Mix_Music *music, int loops, int ms, double position)
{
int retval;
if (ms_per_step == 0) {
SDL_SetError("Audio device hasn't been opened");
return(-1);
}
/* Don't play null pointers :-) */
if (music == NULL) {
Mix_SetError("music parameter was NULL");
return(-1);
}
/* Setup the data */
if (ms) {
music->fading = MIX_FADING_IN;
} else {
music->fading = MIX_NO_FADING;
}
music->fade_step = 0;
music->fade_steps = ms/ms_per_step;
/* Play the puppy */
Mix_LockAudio();
/* If the current music is fading out, wait for the fade to complete */
while (music_playing && (music_playing->fading == MIX_FADING_OUT)) {
Mix_UnlockAudio();
SDL_Delay(100);
Mix_LockAudio();
}
if (loops == 0) {
/* Loop is the number of times to play the audio */
loops = 1;
}
retval = music_internal_play(music, loops, position);
music_active = (retval == 0);
Mix_UnlockAudio();
return(retval);
}
int Mix_FadeInMusic(Mix_Music *music, int loops, int ms)
{
return Mix_FadeInMusicPos(music, loops, ms, 0.0);
}
int Mix_PlayMusic(Mix_Music *music, int loops)
{
return Mix_FadeInMusicPos(music, loops, 0, 0.0);
}
/* Set the playing music position */
int music_internal_position(double position)
{
if (music_playing->interface->Seek) {
return music_playing->interface->Seek(music_playing->context, position);
}
return -1;
}
int Mix_SetMusicPosition(double position)
{
int retval;
Mix_LockAudio();
if (music_playing) {
retval = music_internal_position(position);
if (retval < 0) {
Mix_SetError("Position not implemented for music type");
}
} else {
Mix_SetError("Music isn't playing");
retval = -1;
}
Mix_UnlockAudio();
return(retval);
}
/* Set the music's initial volume */
static void music_internal_initialize_volume(void)
{
if (music_playing->fading == MIX_FADING_IN) {
music_internal_volume(0);
} else {
music_internal_volume(music_volume);
}
}
/* Set the music volume */
static void music_internal_volume(int volume)
{
if (music_playing->interface->SetVolume) {
music_playing->interface->SetVolume(music_playing->context, volume);
}
}
int Mix_VolumeMusic(int volume)
{
int prev_volume;
prev_volume = music_volume;
if (volume < 0) {
return prev_volume;
}
if (volume > SDL_MIX_MAXVOLUME) {
volume = SDL_MIX_MAXVOLUME;
}
music_volume = volume;
Mix_LockAudio();
if (music_playing) {
music_internal_volume(music_volume);
}
Mix_UnlockAudio();
return(prev_volume);
}
/* Halt playing of music */
static void music_internal_halt(void)
{
if (music_playing->interface->Stop) {
music_playing->interface->Stop(music_playing->context);
}
music_playing->playing = SDL_FALSE;
music_playing->fading = MIX_NO_FADING;
music_playing = NULL;
}
int Mix_HaltMusic(void)
{
Mix_LockAudio();
if (music_playing) {
music_internal_halt();
if (music_finished_hook) {
music_finished_hook();
}
}
Mix_UnlockAudio();
return(0);
}
/* Progressively stop the music */
int Mix_FadeOutMusic(int ms)
{
int retval = 0;
if (ms_per_step == 0) {
SDL_SetError("Audio device hasn't been opened");
return 0;
}
if (ms <= 0) { /* just halt immediately. */
Mix_HaltMusic();
return 1;
}
Mix_LockAudio();
if (music_playing) {
int fade_steps = (ms + ms_per_step - 1) / ms_per_step;
if (music_playing->fading == MIX_NO_FADING) {
music_playing->fade_step = 0;
} else {
int step;
int old_fade_steps = music_playing->fade_steps;
if (music_playing->fading == MIX_FADING_OUT) {
step = music_playing->fade_step;
} else {
step = old_fade_steps - music_playing->fade_step + 1;
}
music_playing->fade_step = (step * fade_steps) / old_fade_steps;
}
music_playing->fading = MIX_FADING_OUT;
music_playing->fade_steps = fade_steps;
retval = 1;
}
Mix_UnlockAudio();
return(retval);
}
Mix_Fading Mix_FadingMusic(void)
{
Mix_Fading fading = MIX_NO_FADING;
Mix_LockAudio();
if (music_playing) {
fading = music_playing->fading;
}
Mix_UnlockAudio();
return(fading);
}
/* Pause/Resume the music stream */
void Mix_PauseMusic(void)
{
Mix_LockAudio();
if (music_playing) {
if (music_playing->interface->Pause) {
music_playing->interface->Pause(music_playing->context);
}
}
music_active = SDL_FALSE;
Mix_UnlockAudio();
}
void Mix_ResumeMusic(void)
{
Mix_LockAudio();
if (music_playing) {
if (music_playing->interface->Resume) {
music_playing->interface->Resume(music_playing->context);
}
}
music_active = SDL_TRUE;
Mix_UnlockAudio();
}
void Mix_RewindMusic(void)
{
Mix_SetMusicPosition(0.0);
}
int Mix_PausedMusic(void)
{
return (music_active == SDL_FALSE);
}
/* Check the status of the music */
static SDL_bool music_internal_playing(void)
{
if (!music_playing) {
return SDL_FALSE;
}
if (music_playing->interface->IsPlaying) {
music_playing->playing = music_playing->interface->IsPlaying(music_playing->context);
}
return music_playing->playing;
}
int Mix_PlayingMusic(void)
{
SDL_bool playing;
Mix_LockAudio();
playing = music_internal_playing();
Mix_UnlockAudio();
return playing ? 1 : 0;
}
/* Set the external music playback command */
int Mix_SetMusicCMD(const char *command)
{
Mix_HaltMusic();
if (music_cmd) {
SDL_free(music_cmd);
music_cmd = NULL;
}
if (command) {
size_t length = SDL_strlen(command) + 1;
music_cmd = (char *)SDL_malloc(length);
if (music_cmd == NULL) {
return SDL_OutOfMemory();
}
SDL_memcpy(music_cmd, command, length);
}
return 0;
}
int Mix_SetSynchroValue(int i)
{
/* Not supported by any players at this time */
return(-1);
}
int Mix_GetSynchroValue(void)
{
/* Not supported by any players at this time */
return(-1);
}
/* Uninitialize the music interfaces */
void close_music(void)
{
int i;
Mix_HaltMusic();
for (i = 0; i < SDL_arraysize(s_music_interfaces); ++i) {
Mix_MusicInterface *interface = s_music_interfaces[i];
if (!interface || !interface->opened) {
continue;
}
if (interface->Close) {
interface->Close();
}
interface->opened = SDL_FALSE;
}
if (soundfont_paths) {
SDL_free(soundfont_paths);
soundfont_paths = NULL;
}
/* rcg06042009 report available decoders at runtime. */
if (music_decoders) {
SDL_free((void *)music_decoders);
music_decoders = NULL;
}
num_decoders = 0;
ms_per_step = 0;
}
/* Unload the music interface libraries */
void unload_music(void)
{
int i;
for (i = 0; i < SDL_arraysize(s_music_interfaces); ++i) {
Mix_MusicInterface *interface = s_music_interfaces[i];
if (!interface || !interface->loaded) {
continue;
}
if (interface->Unload) {
interface->Unload();
}
interface->loaded = SDL_FALSE;
}
}
int Mix_SetSoundFonts(const char *paths)
{
if (soundfont_paths) {
SDL_free(soundfont_paths);
soundfont_paths = NULL;
}
if (paths) {
if (!(soundfont_paths = SDL_strdup(paths))) {
Mix_SetError("Insufficient memory to set SoundFonts");
return 0;
}
}
return 1;
}
const char* Mix_GetSoundFonts(void)
{
const char *env_paths = SDL_getenv("SDL_SOUNDFONTS");
SDL_bool force_env_paths = SDL_GetHintBoolean("SDL_FORCE_SOUNDFONTS", SDL_FALSE);
if (force_env_paths && (!env_paths || !*env_paths)) {
force_env_paths = SDL_FALSE;
}
if (soundfont_paths && *soundfont_paths && !force_env_paths) {
return soundfont_paths;
}
if (env_paths) {
return env_paths;
}
/* We don't have any sound fonts set programmatically or in the environment
Time to start guessing where they might be...
*/
{
static char *s_soundfont_paths[] = {
"/usr/share/sounds/sf2/FluidR3_GM.sf2" /* Remember to add ',' here */
};
unsigned i;
for (i = 0; i < SDL_arraysize(s_soundfont_paths); ++i) {
SDL_RWops *rwops = SDL_RWFromFile(s_soundfont_paths[i], "rb");
if (rwops) {
SDL_RWclose(rwops);
return s_soundfont_paths[i];
}
}
}
return NULL;
}
int Mix_EachSoundFont(int (SDLCALL *function)(const char*, void*), void *data)
{
char *context, *path, *paths;
const char* cpaths = Mix_GetSoundFonts();
int soundfonts_found = 0;
if (!cpaths) {
Mix_SetError("No SoundFonts have been requested");
return 0;
}
if (!(paths = SDL_strdup(cpaths))) {
Mix_SetError("Insufficient memory to iterate over SoundFonts");
return 0;
}
#if defined(__MINGW32__) || defined(__MINGW64__) || defined(__WATCOMC__)
for (path = strtok(paths, ";"); path; path = strtok(NULL, ";")) {
#elif defined(_WIN32)
for (path = strtok_s(paths, ";", &context); path; path = strtok_s(NULL, ";", &context)) {
#else
for (path = strtok_r(paths, ":;", &context); path; path = strtok_r(NULL, ":;", &context)) {
#endif
if (!function(path, data)) {
continue;
} else {
soundfonts_found++;
}
}
SDL_free(paths);
if (soundfonts_found > 0)
return 1;
else
return 0;
}
/* vi: set ts=4 sw=4 expandtab: */
|
0424f87b1c1b8a91af181555c4b18cfc9e61c550
|
aa3befea459382dc5c01c925653d54f435b3fb0f
|
/arch/risc-v/src/bl602/bl602_spiflash.c
|
732f94fe1f5335765966dca9d7f12ffac98d007b
|
[
"MIT-open-group",
"BSD-3-Clause",
"HPND-sell-variant",
"BSD-4-Clause-UC",
"LicenseRef-scancode-warranty-disclaimer",
"MIT-0",
"LicenseRef-scancode-bsd-atmel",
"LicenseRef-scancode-gary-s-brown",
"LicenseRef-scancode-proprietary-license",
"SunPro",
"MIT",
"LicenseRef-scancode-public-domain-disclaimer",
"LicenseRef-scancode-other-permissive",
"HPND",
"ISC",
"Apache-2.0",
"LicenseRef-scancode-public-domain",
"BSD-2-Clause",
"GPL-1.0-or-later",
"CC-BY-2.0",
"CC-BY-4.0"
] |
permissive
|
apache/nuttx
|
14519a7bff4a87935d94fb8fb2b19edb501c7cec
|
606b6d9310fb25c7d92c6f95bf61737e3c79fa0f
|
refs/heads/master
| 2023-08-25T06:55:45.822534
| 2023-08-23T16:03:31
| 2023-08-24T21:25:47
| 228,103,273
| 407
| 241
|
Apache-2.0
| 2023-09-14T18:26:05
| 2019-12-14T23:27:55
|
C
|
UTF-8
|
C
| false
| false
| 11,537
|
c
|
bl602_spiflash.c
|
/****************************************************************************
* arch/risc-v/src/bl602/bl602_spiflash.c
*
* 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <debug.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <errno.h>
#include <syslog.h>
#ifdef CONFIG_BL602_SPIFLASH
#include <nuttx/arch.h>
#include <nuttx/init.h>
#include <nuttx/irq.h>
#include <nuttx/semaphore.h>
#include <nuttx/mtd/mtd.h>
#include <nuttx/timers/timer.h>
#include <arch/board/board.h>
#include <bl602_flash.h>
#include <bl602_spiflash.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define SPIFLASH_BLOCKSIZE (0x1000)
#define MTD2PRIV(_dev) ((struct bl602_spiflash_s *)_dev)
/****************************************************************************
* Private Types
****************************************************************************/
/* SPI Flash device hardware configuration */
struct bl602_spiflash_config_s
{
/* SPI register base address */
uint32_t flash_offset;
uint32_t flash_size;
uint32_t flash_offset_xip;
};
/* SPI Flash device private data */
struct bl602_spiflash_s
{
struct mtd_dev_s mtd;
struct bl602_spiflash_config_s *config;
};
/****************************************************************************
* ROM function prototypes
****************************************************************************/
/* MTD driver methods */
static int bl602_erase(struct mtd_dev_s *dev, off_t startblock,
size_t nblocks);
static ssize_t bl602_bread(struct mtd_dev_s *dev, off_t startblock,
size_t nblocks, uint8_t *buffer);
static ssize_t bl602_bwrite(struct mtd_dev_s *dev, off_t startblock,
size_t nblocks, const uint8_t *buffer);
static ssize_t bl602_read(struct mtd_dev_s *dev, off_t offset,
size_t nbytes, uint8_t *buffer);
static int bl602_ioctl(struct mtd_dev_s *dev, int cmd,
unsigned long arg);
/****************************************************************************
* Private Data
****************************************************************************/
static struct bl602_spiflash_config_s g_bl602_spiflash_config =
{
.flash_offset = 0,
.flash_size = 0,
.flash_offset_xip = 0,
};
static struct bl602_spiflash_s g_bl602_spiflash =
{
.mtd =
{
.erase = bl602_erase,
.bread = bl602_bread,
.bwrite = bl602_bwrite,
.read = bl602_read,
.ioctl = bl602_ioctl,
.name = "bl602_media"
},
.config = &g_bl602_spiflash_config,
};
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: bl602_erase
*
* Description:
* Erase SPI Flash designated sectors.
*
* Input Parameters:
* dev - bl602 MTD device data
* startblock - start block number, it is not equal to SPI Flash's block
* nblocks - blocks number
*
* Returned Value:
* 0 if success or a negative value if fail.
*
****************************************************************************/
static int bl602_erase(struct mtd_dev_s *dev, off_t startblock,
size_t nblocks)
{
int ret = 0;
struct bl602_spiflash_s *priv = MTD2PRIV(dev);
uint32_t addr = priv->config->flash_offset \
+ startblock * SPIFLASH_BLOCKSIZE;
uint32_t size = nblocks * SPIFLASH_BLOCKSIZE;
finfo("dev=%p, addr=0x%lx, size=0x%lx\n", dev, addr, size);
ret = bl602_flash_erase(addr, size);
if (ret == 0)
{
ret = nblocks;
}
return ret;
}
/****************************************************************************
* Name: bl602_read
*
* Description:
* Read data from SPI Flash at designated address.
*
* Input Parameters:
* dev - bl602 MTD device data
* offset - target address offset
* nbytes - data number
* buffer - data buffer pointer
*
* Returned Value:
* Read data bytes if success or a negative value if fail.
*
****************************************************************************/
static ssize_t bl602_read(struct mtd_dev_s *dev, off_t offset,
size_t nbytes, uint8_t *buffer)
{
int ret = 0;
struct bl602_spiflash_s *priv = MTD2PRIV(dev);
uint32_t addr = priv->config->flash_offset + offset;
uint32_t size = nbytes;
finfo("dev=%p, addr=0x%lx, size=0x%lx\n", dev, addr, size);
if (0 == bl602_flash_read(addr, buffer, size))
{
return ret = size;
}
return (ssize_t)ret;
}
/****************************************************************************
* Name: bl602_bread
*
* Description:
* Read data from designated blocks.
*
* Input Parameters:
* dev - bl602 MTD device data
* startblock - start block number, it is not equal to SPI Flash's block
* nblocks - blocks number
* buffer - data buffer pointer
*
* Returned Value:
* Read block number if success or a negative value if fail.
*
****************************************************************************/
static ssize_t bl602_bread(struct mtd_dev_s *dev, off_t startblock,
size_t nblocks, uint8_t *buffer)
{
int ret = 0;
struct bl602_spiflash_s *priv = MTD2PRIV(dev);
uint32_t addr = priv->config->flash_offset \
+ startblock * SPIFLASH_BLOCKSIZE;
uint32_t size = nblocks * SPIFLASH_BLOCKSIZE;
finfo("dev=%p, addr=0x%lx, size=0x%lx\n", dev, addr, size);
if (0 == bl602_flash_read(addr, buffer, size))
{
ret = nblocks;
}
return (ssize_t)ret;
}
/****************************************************************************
* Name: bl602_bwrite
*
* Description:
* Write data to designated blocks.
*
* Input Parameters:
* dev - bl602 MTD device data
* startblock - start MTD block number,
* it is not equal to SPI Flash's block
* nblocks - blocks number
* buffer - data buffer pointer
*
* Returned Value:
* Written block number if success or a negative value if fail.
*
****************************************************************************/
static ssize_t bl602_bwrite(struct mtd_dev_s *dev, off_t startblock,
size_t nblocks, const uint8_t *buffer)
{
int ret = 0;
struct bl602_spiflash_s *priv = MTD2PRIV(dev);
uint32_t addr = priv->config->flash_offset \
+ startblock * SPIFLASH_BLOCKSIZE;
uint32_t size = nblocks * SPIFLASH_BLOCKSIZE;
finfo("bl602_bwrite dev=%p, addr=0x%lx, size=0x%lx\n", dev, addr, size);
if (0 == bl602_flash_write(addr, buffer, size))
{
ret = nblocks;
}
return (ssize_t)ret;
}
/****************************************************************************
* Name: bl602_ioctl
*
* Description:
* Set/Get option to/from bl602 SPI Flash MTD device data.
*
* Input Parameters:
* dev - bl602 MTD device data
* cmd - operation command
* arg - operation argument
*
* Returned Value:
* 0 if success or a negative value if fail.
*
****************************************************************************/
int bl602_ioctl(struct mtd_dev_s *dev, int cmd,
unsigned long arg)
{
int ret = -EINVAL;
struct bl602_spiflash_s *priv = MTD2PRIV(dev);
switch (cmd)
{
case MTDIOC_GEOMETRY:
{
finfo("cmd(0x%x) MTDIOC_GEOMETRY.\n", cmd);
struct mtd_geometry_s *geo = (struct mtd_geometry_s *)arg;
if (geo)
{
memset(geo, 0, sizeof(*geo));
geo->blocksize = SPIFLASH_BLOCKSIZE;
geo->erasesize = SPIFLASH_BLOCKSIZE;
geo->neraseblocks = (priv->config->flash_size) / \
SPIFLASH_BLOCKSIZE;
ret = OK;
finfo("blocksize: %ld erasesize: %ld neraseblocks: %ld\n",
geo->blocksize, geo->erasesize, geo->neraseblocks);
}
}
break;
case BIOC_PARTINFO:
{
struct partition_info_s *info =
(struct partition_info_s *)arg;
if (info != NULL)
{
info->numsectors = priv->config->flash_size /
SPIFLASH_BLOCKSIZE;
info->sectorsize = SPIFLASH_BLOCKSIZE;
info->startsector = 0;
info->parent[0] = '\0';
ret = OK;
}
}
break;
default:
{
finfo("cmd(0x%x) not support.\n", cmd);
ret = -ENOTTY;
}
break;
}
return ret;
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: bl602_spiflash_alloc_mtdpart
*
* Description:
* Alloc bl602 SPI Flash MTD
*
* Input Parameters:
* None
*
* Returned Value:
* bl602 SPI Flash MTD data pointer if success or NULL if fail
*
****************************************************************************/
struct mtd_dev_s *bl602_spiflash_alloc_mtdpart(void)
{
struct bl602_spiflash_s *priv = &g_bl602_spiflash;
struct mtd_dev_s *mtd_part = NULL;
priv->config->flash_offset = CONFIG_BL602_MTD_OFFSET;
priv->config->flash_size = CONFIG_BL602_MTD_SIZE;
mtd_part = mtd_partition(&priv->mtd, 0,
CONFIG_BL602_MTD_SIZE / SPIFLASH_BLOCKSIZE);
if (!mtd_part)
{
ferr("ERROR: create MTD partition");
return NULL;
}
return mtd_part;
}
/****************************************************************************
* Name: bl602_spiflash_get_mtd
*
* Description:
* Get bl602 SPI Flash raw MTD.
*
* Input Parameters:
* None
*
* Returned Value:
* bl602 SPI Flash raw MTD data pointer.
*
****************************************************************************/
struct mtd_dev_s *bl602_spiflash_get_mtd(void)
{
struct bl602_spiflash_s *priv = &g_bl602_spiflash;
return &priv->mtd;
}
#endif /* CONFIG_BL602_SPIFLASH */
|
d0e854e89f7016864b67d8bf6fcd0c6eb225ae88
|
79d343002bb63a44f8ab0dbac0c9f4ec54078c3a
|
/lib/tsan/sanitizer_common/sanitizer_allocator_interface.h
|
c1b27563e2fc7023f60d85a06903fd7bd9991828
|
[
"LLVM-exception",
"Apache-2.0",
"MIT"
] |
permissive
|
ziglang/zig
|
4aa75d8d3bcc9e39bf61d265fd84b7f005623fc5
|
f4c9e19bc3213c2bc7e03d7b06d7129882f39f6c
|
refs/heads/master
| 2023-08-31T13:16:45.980913
| 2023-08-31T05:50:29
| 2023-08-31T05:50:29
| 40,276,274
| 25,560
| 2,399
|
MIT
| 2023-09-14T21:09:50
| 2015-08-06T00:51:28
|
Zig
|
UTF-8
|
C
| false
| false
| 1,877
|
h
|
sanitizer_allocator_interface.h
|
//===-- sanitizer_allocator_interface.h ------------------------- C++ -----===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// Re-declaration of functions from public sanitizer allocator interface.
//
//===----------------------------------------------------------------------===//
#ifndef SANITIZER_ALLOCATOR_INTERFACE_H
#define SANITIZER_ALLOCATOR_INTERFACE_H
#include "sanitizer_internal_defs.h"
using __sanitizer::uptr;
extern "C" {
SANITIZER_INTERFACE_ATTRIBUTE
uptr __sanitizer_get_estimated_allocated_size(uptr size);
SANITIZER_INTERFACE_ATTRIBUTE int __sanitizer_get_ownership(const void *p);
SANITIZER_INTERFACE_ATTRIBUTE uptr
__sanitizer_get_allocated_size(const void *p);
SANITIZER_INTERFACE_ATTRIBUTE uptr __sanitizer_get_current_allocated_bytes();
SANITIZER_INTERFACE_ATTRIBUTE uptr __sanitizer_get_heap_size();
SANITIZER_INTERFACE_ATTRIBUTE uptr __sanitizer_get_free_bytes();
SANITIZER_INTERFACE_ATTRIBUTE uptr __sanitizer_get_unmapped_bytes();
SANITIZER_INTERFACE_ATTRIBUTE int __sanitizer_install_malloc_and_free_hooks(
void (*malloc_hook)(const void *, uptr),
void (*free_hook)(const void *));
SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
void __sanitizer_malloc_hook(void *ptr, uptr size);
SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
void __sanitizer_free_hook(void *ptr);
SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE void
__sanitizer_purge_allocator();
SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE void
__sanitizer_print_memory_profile(uptr top_percent, uptr max_number_of_contexts);
} // extern "C"
#endif // SANITIZER_ALLOCATOR_INTERFACE_H
|
5943202b79131df1dc7f56ece1bf12882564552e
|
d665d4f48d9208eb3bc65bba929395a009cd7a7d
|
/extlibs/headers/FLAC/format.h
|
e4c1c1a613212802d4aed241f4b23f166a4525ec
|
[
"Zlib",
"GPL-1.0-or-later",
"LGPL-2.0-or-later",
"CC0-1.0",
"BSD-3-Clause",
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] |
permissive
|
SFML/SFML
|
bb46b4d0d274a1e47e02bfb5c983bd2687e1a8a8
|
78973e4a06dd5ace2185329ad165d391cc3c01a8
|
refs/heads/master
| 2023-08-31T06:55:51.690962
| 2023-08-26T22:24:50
| 2023-08-30T05:18:00
| 1,524,684
| 8,409
| 2,458
|
Zlib
| 2023-09-13T22:48:52
| 2011-03-25T08:05:25
|
C++
|
UTF-8
|
C
| false
| false
| 40,308
|
h
|
format.h
|
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2000-2009 Josh Coalson
* Copyright (C) 2011-2013 Xiph.Org Foundation
*
* 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 Xiph.org 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 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 FOUNDATION 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 FLAC__FORMAT_H
#define FLAC__FORMAT_H
#include "export.h"
#include "ordinals.h"
#ifdef __cplusplus
extern "C" {
#endif
/** \file include/FLAC/format.h
*
* \brief
* This module contains structure definitions for the representation
* of FLAC format components in memory. These are the basic
* structures used by the rest of the interfaces.
*
* See the detailed documentation in the
* \link flac_format format \endlink module.
*/
/** \defgroup flac_format FLAC/format.h: format components
* \ingroup flac
*
* \brief
* This module contains structure definitions for the representation
* of FLAC format components in memory. These are the basic
* structures used by the rest of the interfaces.
*
* First, you should be familiar with the
* <A HREF="../format.html">FLAC format</A>. Many of the values here
* follow directly from the specification. As a user of libFLAC, the
* interesting parts really are the structures that describe the frame
* header and metadata blocks.
*
* The format structures here are very primitive, designed to store
* information in an efficient way. Reading information from the
* structures is easy but creating or modifying them directly is
* more complex. For the most part, as a user of a library, editing
* is not necessary; however, for metadata blocks it is, so there are
* convenience functions provided in the \link flac_metadata metadata
* module \endlink to simplify the manipulation of metadata blocks.
*
* \note
* It's not the best convention, but symbols ending in _LEN are in bits
* and _LENGTH are in bytes. _LENGTH symbols are \#defines instead of
* global variables because they are usually used when declaring byte
* arrays and some compilers require compile-time knowledge of array
* sizes when declared on the stack.
*
* \{
*/
/*
Most of the values described in this file are defined by the FLAC
format specification. There is nothing to tune here.
*/
/** The largest legal metadata type code. */
#define FLAC__MAX_METADATA_TYPE_CODE (126u)
/** The minimum block size, in samples, permitted by the format. */
#define FLAC__MIN_BLOCK_SIZE (16u)
/** The maximum block size, in samples, permitted by the format. */
#define FLAC__MAX_BLOCK_SIZE (65535u)
/** The maximum block size, in samples, permitted by the FLAC subset for
* sample rates up to 48kHz. */
#define FLAC__SUBSET_MAX_BLOCK_SIZE_48000HZ (4608u)
/** The maximum number of channels permitted by the format. */
#define FLAC__MAX_CHANNELS (8u)
/** The minimum sample resolution permitted by the format. */
#define FLAC__MIN_BITS_PER_SAMPLE (4u)
/** The maximum sample resolution permitted by the format. */
#define FLAC__MAX_BITS_PER_SAMPLE (32u)
/** The maximum sample resolution permitted by libFLAC.
*
* \warning
* FLAC__MAX_BITS_PER_SAMPLE is the limit of the FLAC format. However,
* the reference encoder/decoder is currently limited to 24 bits because
* of prevalent 32-bit math, so make sure and use this value when
* appropriate.
*/
#define FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE (24u)
/** The maximum sample rate permitted by the format. The value is
* ((2 ^ 16) - 1) * 10; see <A HREF="../format.html">FLAC format</A>
* as to why.
*/
#define FLAC__MAX_SAMPLE_RATE (655350u)
/** The maximum LPC order permitted by the format. */
#define FLAC__MAX_LPC_ORDER (32u)
/** The maximum LPC order permitted by the FLAC subset for sample rates
* up to 48kHz. */
#define FLAC__SUBSET_MAX_LPC_ORDER_48000HZ (12u)
/** The minimum quantized linear predictor coefficient precision
* permitted by the format.
*/
#define FLAC__MIN_QLP_COEFF_PRECISION (5u)
/** The maximum quantized linear predictor coefficient precision
* permitted by the format.
*/
#define FLAC__MAX_QLP_COEFF_PRECISION (15u)
/** The maximum order of the fixed predictors permitted by the format. */
#define FLAC__MAX_FIXED_ORDER (4u)
/** The maximum Rice partition order permitted by the format. */
#define FLAC__MAX_RICE_PARTITION_ORDER (15u)
/** The maximum Rice partition order permitted by the FLAC Subset. */
#define FLAC__SUBSET_MAX_RICE_PARTITION_ORDER (8u)
/** The version string of the release, stamped onto the libraries and binaries.
*
* \note
* This does not correspond to the shared library version number, which
* is used to determine binary compatibility.
*/
extern FLAC_API const char *FLAC__VERSION_STRING;
/** The vendor string inserted by the encoder into the VORBIS_COMMENT block.
* This is a NUL-terminated ASCII string; when inserted into the
* VORBIS_COMMENT the trailing null is stripped.
*/
extern FLAC_API const char *FLAC__VENDOR_STRING;
/** The byte string representation of the beginning of a FLAC stream. */
extern FLAC_API const FLAC__byte FLAC__STREAM_SYNC_STRING[4]; /* = "fLaC" */
/** The 32-bit integer big-endian representation of the beginning of
* a FLAC stream.
*/
extern FLAC_API const unsigned FLAC__STREAM_SYNC; /* = 0x664C6143 */
/** The length of the FLAC signature in bits. */
extern FLAC_API const unsigned FLAC__STREAM_SYNC_LEN; /* = 32 bits */
/** The length of the FLAC signature in bytes. */
#define FLAC__STREAM_SYNC_LENGTH (4u)
/*****************************************************************************
*
* Subframe structures
*
*****************************************************************************/
/*****************************************************************************/
/** An enumeration of the available entropy coding methods. */
typedef enum {
FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE = 0,
/**< Residual is coded by partitioning into contexts, each with it's own
* 4-bit Rice parameter. */
FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2 = 1
/**< Residual is coded by partitioning into contexts, each with it's own
* 5-bit Rice parameter. */
} FLAC__EntropyCodingMethodType;
/** Maps a FLAC__EntropyCodingMethodType to a C string.
*
* Using a FLAC__EntropyCodingMethodType as the index to this array will
* give the string equivalent. The contents should not be modified.
*/
extern FLAC_API const char * const FLAC__EntropyCodingMethodTypeString[];
/** Contents of a Rice partitioned residual
*/
typedef struct {
unsigned *parameters;
/**< The Rice parameters for each context. */
unsigned *raw_bits;
/**< Widths for escape-coded partitions. Will be non-zero for escaped
* partitions and zero for unescaped partitions.
*/
unsigned capacity_by_order;
/**< The capacity of the \a parameters and \a raw_bits arrays
* specified as an order, i.e. the number of array elements
* allocated is 2 ^ \a capacity_by_order.
*/
} FLAC__EntropyCodingMethod_PartitionedRiceContents;
/** Header for a Rice partitioned residual. (c.f. <A HREF="../format.html#partitioned_rice">format specification</A>)
*/
typedef struct {
unsigned order;
/**< The partition order, i.e. # of contexts = 2 ^ \a order. */
const FLAC__EntropyCodingMethod_PartitionedRiceContents *contents;
/**< The context's Rice parameters and/or raw bits. */
} FLAC__EntropyCodingMethod_PartitionedRice;
extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN; /**< == 4 (bits) */
extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN; /**< == 4 (bits) */
extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN; /**< == 5 (bits) */
extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN; /**< == 5 (bits) */
extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
/**< == (1<<FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN)-1 */
extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER;
/**< == (1<<FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN)-1 */
/** Header for the entropy coding method. (c.f. <A HREF="../format.html#residual">format specification</A>)
*/
typedef struct {
FLAC__EntropyCodingMethodType type;
union {
FLAC__EntropyCodingMethod_PartitionedRice partitioned_rice;
} data;
} FLAC__EntropyCodingMethod;
extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_TYPE_LEN; /**< == 2 (bits) */
/*****************************************************************************/
/** An enumeration of the available subframe types. */
typedef enum {
FLAC__SUBFRAME_TYPE_CONSTANT = 0, /**< constant signal */
FLAC__SUBFRAME_TYPE_VERBATIM = 1, /**< uncompressed signal */
FLAC__SUBFRAME_TYPE_FIXED = 2, /**< fixed polynomial prediction */
FLAC__SUBFRAME_TYPE_LPC = 3 /**< linear prediction */
} FLAC__SubframeType;
/** Maps a FLAC__SubframeType to a C string.
*
* Using a FLAC__SubframeType as the index to this array will
* give the string equivalent. The contents should not be modified.
*/
extern FLAC_API const char * const FLAC__SubframeTypeString[];
/** CONSTANT subframe. (c.f. <A HREF="../format.html#subframe_constant">format specification</A>)
*/
typedef struct {
FLAC__int32 value; /**< The constant signal value. */
} FLAC__Subframe_Constant;
/** VERBATIM subframe. (c.f. <A HREF="../format.html#subframe_verbatim">format specification</A>)
*/
typedef struct {
const FLAC__int32 *data; /**< A pointer to verbatim signal. */
} FLAC__Subframe_Verbatim;
/** FIXED subframe. (c.f. <A HREF="../format.html#subframe_fixed">format specification</A>)
*/
typedef struct {
FLAC__EntropyCodingMethod entropy_coding_method;
/**< The residual coding method. */
unsigned order;
/**< The polynomial order. */
FLAC__int32 warmup[FLAC__MAX_FIXED_ORDER];
/**< Warmup samples to prime the predictor, length == order. */
const FLAC__int32 *residual;
/**< The residual signal, length == (blocksize minus order) samples. */
} FLAC__Subframe_Fixed;
/** LPC subframe. (c.f. <A HREF="../format.html#subframe_lpc">format specification</A>)
*/
typedef struct {
FLAC__EntropyCodingMethod entropy_coding_method;
/**< The residual coding method. */
unsigned order;
/**< The FIR order. */
unsigned qlp_coeff_precision;
/**< Quantized FIR filter coefficient precision in bits. */
int quantization_level;
/**< The qlp coeff shift needed. */
FLAC__int32 qlp_coeff[FLAC__MAX_LPC_ORDER];
/**< FIR filter coefficients. */
FLAC__int32 warmup[FLAC__MAX_LPC_ORDER];
/**< Warmup samples to prime the predictor, length == order. */
const FLAC__int32 *residual;
/**< The residual signal, length == (blocksize minus order) samples. */
} FLAC__Subframe_LPC;
extern FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN; /**< == 4 (bits) */
extern FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN; /**< == 5 (bits) */
/** FLAC subframe structure. (c.f. <A HREF="../format.html#subframe">format specification</A>)
*/
typedef struct {
FLAC__SubframeType type;
union {
FLAC__Subframe_Constant constant;
FLAC__Subframe_Fixed fixed;
FLAC__Subframe_LPC lpc;
FLAC__Subframe_Verbatim verbatim;
} data;
unsigned wasted_bits;
} FLAC__Subframe;
/** == 1 (bit)
*
* This used to be a zero-padding bit (hence the name
* FLAC__SUBFRAME_ZERO_PAD_LEN) but is now a reserved bit. It still has a
* mandatory value of \c 0 but in the future may take on the value \c 0 or \c 1
* to mean something else.
*/
extern FLAC_API const unsigned FLAC__SUBFRAME_ZERO_PAD_LEN;
extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LEN; /**< == 6 (bits) */
extern FLAC_API const unsigned FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN; /**< == 1 (bit) */
extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK; /**< = 0x00 */
extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK; /**< = 0x02 */
extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK; /**< = 0x10 */
extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK; /**< = 0x40 */
/*****************************************************************************/
/*****************************************************************************
*
* Frame structures
*
*****************************************************************************/
/** An enumeration of the available channel assignments. */
typedef enum {
FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT = 0, /**< independent channels */
FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE = 1, /**< left+side stereo */
FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE = 2, /**< right+side stereo */
FLAC__CHANNEL_ASSIGNMENT_MID_SIDE = 3 /**< mid+side stereo */
} FLAC__ChannelAssignment;
/** Maps a FLAC__ChannelAssignment to a C string.
*
* Using a FLAC__ChannelAssignment as the index to this array will
* give the string equivalent. The contents should not be modified.
*/
extern FLAC_API const char * const FLAC__ChannelAssignmentString[];
/** An enumeration of the possible frame numbering methods. */
typedef enum {
FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER, /**< number contains the frame number */
FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER /**< number contains the sample number of first sample in frame */
} FLAC__FrameNumberType;
/** Maps a FLAC__FrameNumberType to a C string.
*
* Using a FLAC__FrameNumberType as the index to this array will
* give the string equivalent. The contents should not be modified.
*/
extern FLAC_API const char * const FLAC__FrameNumberTypeString[];
/** FLAC frame header structure. (c.f. <A HREF="../format.html#frame_header">format specification</A>)
*/
typedef struct {
unsigned blocksize;
/**< The number of samples per subframe. */
unsigned sample_rate;
/**< The sample rate in Hz. */
unsigned channels;
/**< The number of channels (== number of subframes). */
FLAC__ChannelAssignment channel_assignment;
/**< The channel assignment for the frame. */
unsigned bits_per_sample;
/**< The sample resolution. */
FLAC__FrameNumberType number_type;
/**< The numbering scheme used for the frame. As a convenience, the
* decoder will always convert a frame number to a sample number because
* the rules are complex. */
union {
FLAC__uint32 frame_number;
FLAC__uint64 sample_number;
} number;
/**< The frame number or sample number of first sample in frame;
* use the \a number_type value to determine which to use. */
FLAC__uint8 crc;
/**< CRC-8 (polynomial = x^8 + x^2 + x^1 + x^0, initialized with 0)
* of the raw frame header bytes, meaning everything before the CRC byte
* including the sync code.
*/
} FLAC__FrameHeader;
extern FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC; /**< == 0x3ffe; the frame header sync code */
extern FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC_LEN; /**< == 14 (bits) */
extern FLAC_API const unsigned FLAC__FRAME_HEADER_RESERVED_LEN; /**< == 1 (bits) */
extern FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN; /**< == 1 (bits) */
extern FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCK_SIZE_LEN; /**< == 4 (bits) */
extern FLAC_API const unsigned FLAC__FRAME_HEADER_SAMPLE_RATE_LEN; /**< == 4 (bits) */
extern FLAC_API const unsigned FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN; /**< == 4 (bits) */
extern FLAC_API const unsigned FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN; /**< == 3 (bits) */
extern FLAC_API const unsigned FLAC__FRAME_HEADER_ZERO_PAD_LEN; /**< == 1 (bit) */
extern FLAC_API const unsigned FLAC__FRAME_HEADER_CRC_LEN; /**< == 8 (bits) */
/** FLAC frame footer structure. (c.f. <A HREF="../format.html#frame_footer">format specification</A>)
*/
typedef struct {
FLAC__uint16 crc;
/**< CRC-16 (polynomial = x^16 + x^15 + x^2 + x^0, initialized with
* 0) of the bytes before the crc, back to and including the frame header
* sync code.
*/
} FLAC__FrameFooter;
extern FLAC_API const unsigned FLAC__FRAME_FOOTER_CRC_LEN; /**< == 16 (bits) */
/** FLAC frame structure. (c.f. <A HREF="../format.html#frame">format specification</A>)
*/
typedef struct {
FLAC__FrameHeader header;
FLAC__Subframe subframes[FLAC__MAX_CHANNELS];
FLAC__FrameFooter footer;
} FLAC__Frame;
/*****************************************************************************/
/*****************************************************************************
*
* Meta-data structures
*
*****************************************************************************/
/** An enumeration of the available metadata block types. */
typedef enum {
FLAC__METADATA_TYPE_STREAMINFO = 0,
/**< <A HREF="../format.html#metadata_block_streaminfo">STREAMINFO</A> block */
FLAC__METADATA_TYPE_PADDING = 1,
/**< <A HREF="../format.html#metadata_block_padding">PADDING</A> block */
FLAC__METADATA_TYPE_APPLICATION = 2,
/**< <A HREF="../format.html#metadata_block_application">APPLICATION</A> block */
FLAC__METADATA_TYPE_SEEKTABLE = 3,
/**< <A HREF="../format.html#metadata_block_seektable">SEEKTABLE</A> block */
FLAC__METADATA_TYPE_VORBIS_COMMENT = 4,
/**< <A HREF="../format.html#metadata_block_vorbis_comment">VORBISCOMMENT</A> block (a.k.a. FLAC tags) */
FLAC__METADATA_TYPE_CUESHEET = 5,
/**< <A HREF="../format.html#metadata_block_cuesheet">CUESHEET</A> block */
FLAC__METADATA_TYPE_PICTURE = 6,
/**< <A HREF="../format.html#metadata_block_picture">PICTURE</A> block */
FLAC__METADATA_TYPE_UNDEFINED = 7
/**< marker to denote beginning of undefined type range; this number will increase as new metadata types are added */
} FLAC__MetadataType;
/** Maps a FLAC__MetadataType to a C string.
*
* Using a FLAC__MetadataType as the index to this array will
* give the string equivalent. The contents should not be modified.
*/
extern FLAC_API const char * const FLAC__MetadataTypeString[];
/** FLAC STREAMINFO structure. (c.f. <A HREF="../format.html#metadata_block_streaminfo">format specification</A>)
*/
typedef struct {
unsigned min_blocksize, max_blocksize;
unsigned min_framesize, max_framesize;
unsigned sample_rate;
unsigned channels;
unsigned bits_per_sample;
FLAC__uint64 total_samples;
FLAC__byte md5sum[16];
} FLAC__StreamMetadata_StreamInfo;
extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN; /**< == 16 (bits) */
extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN; /**< == 16 (bits) */
extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN; /**< == 24 (bits) */
extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN; /**< == 24 (bits) */
extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN; /**< == 20 (bits) */
extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN; /**< == 3 (bits) */
extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN; /**< == 5 (bits) */
extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN; /**< == 36 (bits) */
extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MD5SUM_LEN; /**< == 128 (bits) */
/** The total stream length of the STREAMINFO block in bytes. */
#define FLAC__STREAM_METADATA_STREAMINFO_LENGTH (34u)
/** FLAC PADDING structure. (c.f. <A HREF="../format.html#metadata_block_padding">format specification</A>)
*/
typedef struct {
int dummy;
/**< Conceptually this is an empty struct since we don't store the
* padding bytes. Empty structs are not allowed by some C compilers,
* hence the dummy.
*/
} FLAC__StreamMetadata_Padding;
/** FLAC APPLICATION structure. (c.f. <A HREF="../format.html#metadata_block_application">format specification</A>)
*/
typedef struct {
FLAC__byte id[4];
FLAC__byte *data;
} FLAC__StreamMetadata_Application;
extern FLAC_API const unsigned FLAC__STREAM_METADATA_APPLICATION_ID_LEN; /**< == 32 (bits) */
/** SeekPoint structure used in SEEKTABLE blocks. (c.f. <A HREF="../format.html#seekpoint">format specification</A>)
*/
typedef struct {
FLAC__uint64 sample_number;
/**< The sample number of the target frame. */
FLAC__uint64 stream_offset;
/**< The offset, in bytes, of the target frame with respect to
* beginning of the first frame. */
unsigned frame_samples;
/**< The number of samples in the target frame. */
} FLAC__StreamMetadata_SeekPoint;
extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN; /**< == 64 (bits) */
extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN; /**< == 64 (bits) */
extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN; /**< == 16 (bits) */
/** The total stream length of a seek point in bytes. */
#define FLAC__STREAM_METADATA_SEEKPOINT_LENGTH (18u)
/** The value used in the \a sample_number field of
* FLAC__StreamMetadataSeekPoint used to indicate a placeholder
* point (== 0xffffffffffffffff).
*/
extern FLAC_API const FLAC__uint64 FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
/** FLAC SEEKTABLE structure. (c.f. <A HREF="../format.html#metadata_block_seektable">format specification</A>)
*
* \note From the format specification:
* - The seek points must be sorted by ascending sample number.
* - Each seek point's sample number must be the first sample of the
* target frame.
* - Each seek point's sample number must be unique within the table.
* - Existence of a SEEKTABLE block implies a correct setting of
* total_samples in the stream_info block.
* - Behavior is undefined when more than one SEEKTABLE block is
* present in a stream.
*/
typedef struct {
unsigned num_points;
FLAC__StreamMetadata_SeekPoint *points;
} FLAC__StreamMetadata_SeekTable;
/** Vorbis comment entry structure used in VORBIS_COMMENT blocks. (c.f. <A HREF="../format.html#metadata_block_vorbis_comment">format specification</A>)
*
* For convenience, the APIs maintain a trailing NUL character at the end of
* \a entry which is not counted toward \a length, i.e.
* \code strlen(entry) == length \endcode
*/
typedef struct {
FLAC__uint32 length;
FLAC__byte *entry;
} FLAC__StreamMetadata_VorbisComment_Entry;
extern FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN; /**< == 32 (bits) */
/** FLAC VORBIS_COMMENT structure. (c.f. <A HREF="../format.html#metadata_block_vorbis_comment">format specification</A>)
*/
typedef struct {
FLAC__StreamMetadata_VorbisComment_Entry vendor_string;
FLAC__uint32 num_comments;
FLAC__StreamMetadata_VorbisComment_Entry *comments;
} FLAC__StreamMetadata_VorbisComment;
extern FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN; /**< == 32 (bits) */
/** FLAC CUESHEET track index structure. (See the
* <A HREF="../format.html#cuesheet_track_index">format specification</A> for
* the full description of each field.)
*/
typedef struct {
FLAC__uint64 offset;
/**< Offset in samples, relative to the track offset, of the index
* point.
*/
FLAC__byte number;
/**< The index point number. */
} FLAC__StreamMetadata_CueSheet_Index;
extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN; /**< == 64 (bits) */
extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN; /**< == 8 (bits) */
extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN; /**< == 3*8 (bits) */
/** FLAC CUESHEET track structure. (See the
* <A HREF="../format.html#cuesheet_track">format specification</A> for
* the full description of each field.)
*/
typedef struct {
FLAC__uint64 offset;
/**< Track offset in samples, relative to the beginning of the FLAC audio stream. */
FLAC__byte number;
/**< The track number. */
char isrc[13];
/**< Track ISRC. This is a 12-digit alphanumeric code plus a trailing \c NUL byte */
unsigned type:1;
/**< The track type: 0 for audio, 1 for non-audio. */
unsigned pre_emphasis:1;
/**< The pre-emphasis flag: 0 for no pre-emphasis, 1 for pre-emphasis. */
FLAC__byte num_indices;
/**< The number of track index points. */
FLAC__StreamMetadata_CueSheet_Index *indices;
/**< NULL if num_indices == 0, else pointer to array of index points. */
} FLAC__StreamMetadata_CueSheet_Track;
extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN; /**< == 64 (bits) */
extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN; /**< == 8 (bits) */
extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN; /**< == 12*8 (bits) */
extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN; /**< == 1 (bit) */
extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN; /**< == 1 (bit) */
extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN; /**< == 6+13*8 (bits) */
extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN; /**< == 8 (bits) */
/** FLAC CUESHEET structure. (See the
* <A HREF="../format.html#metadata_block_cuesheet">format specification</A>
* for the full description of each field.)
*/
typedef struct {
char media_catalog_number[129];
/**< Media catalog number, in ASCII printable characters 0x20-0x7e. In
* general, the media catalog number may be 0 to 128 bytes long; any
* unused characters should be right-padded with NUL characters.
*/
FLAC__uint64 lead_in;
/**< The number of lead-in samples. */
FLAC__bool is_cd;
/**< \c true if CUESHEET corresponds to a Compact Disc, else \c false. */
unsigned num_tracks;
/**< The number of tracks. */
FLAC__StreamMetadata_CueSheet_Track *tracks;
/**< NULL if num_tracks == 0, else pointer to array of tracks. */
} FLAC__StreamMetadata_CueSheet;
extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN; /**< == 128*8 (bits) */
extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN; /**< == 64 (bits) */
extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN; /**< == 1 (bit) */
extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN; /**< == 7+258*8 (bits) */
extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN; /**< == 8 (bits) */
/** An enumeration of the PICTURE types (see FLAC__StreamMetadataPicture and id3 v2.4 APIC tag). */
typedef enum {
FLAC__STREAM_METADATA_PICTURE_TYPE_OTHER = 0, /**< Other */
FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD = 1, /**< 32x32 pixels 'file icon' (PNG only) */
FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON = 2, /**< Other file icon */
FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER = 3, /**< Cover (front) */
FLAC__STREAM_METADATA_PICTURE_TYPE_BACK_COVER = 4, /**< Cover (back) */
FLAC__STREAM_METADATA_PICTURE_TYPE_LEAFLET_PAGE = 5, /**< Leaflet page */
FLAC__STREAM_METADATA_PICTURE_TYPE_MEDIA = 6, /**< Media (e.g. label side of CD) */
FLAC__STREAM_METADATA_PICTURE_TYPE_LEAD_ARTIST = 7, /**< Lead artist/lead performer/soloist */
FLAC__STREAM_METADATA_PICTURE_TYPE_ARTIST = 8, /**< Artist/performer */
FLAC__STREAM_METADATA_PICTURE_TYPE_CONDUCTOR = 9, /**< Conductor */
FLAC__STREAM_METADATA_PICTURE_TYPE_BAND = 10, /**< Band/Orchestra */
FLAC__STREAM_METADATA_PICTURE_TYPE_COMPOSER = 11, /**< Composer */
FLAC__STREAM_METADATA_PICTURE_TYPE_LYRICIST = 12, /**< Lyricist/text writer */
FLAC__STREAM_METADATA_PICTURE_TYPE_RECORDING_LOCATION = 13, /**< Recording Location */
FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_RECORDING = 14, /**< During recording */
FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_PERFORMANCE = 15, /**< During performance */
FLAC__STREAM_METADATA_PICTURE_TYPE_VIDEO_SCREEN_CAPTURE = 16, /**< Movie/video screen capture */
FLAC__STREAM_METADATA_PICTURE_TYPE_FISH = 17, /**< A bright coloured fish */
FLAC__STREAM_METADATA_PICTURE_TYPE_ILLUSTRATION = 18, /**< Illustration */
FLAC__STREAM_METADATA_PICTURE_TYPE_BAND_LOGOTYPE = 19, /**< Band/artist logotype */
FLAC__STREAM_METADATA_PICTURE_TYPE_PUBLISHER_LOGOTYPE = 20, /**< Publisher/Studio logotype */
FLAC__STREAM_METADATA_PICTURE_TYPE_UNDEFINED
} FLAC__StreamMetadata_Picture_Type;
/** Maps a FLAC__StreamMetadata_Picture_Type to a C string.
*
* Using a FLAC__StreamMetadata_Picture_Type as the index to this array
* will give the string equivalent. The contents should not be
* modified.
*/
extern FLAC_API const char * const FLAC__StreamMetadata_Picture_TypeString[];
/** FLAC PICTURE structure. (See the
* <A HREF="../format.html#metadata_block_picture">format specification</A>
* for the full description of each field.)
*/
typedef struct {
FLAC__StreamMetadata_Picture_Type type;
/**< The kind of picture stored. */
char *mime_type;
/**< Picture data's MIME type, in ASCII printable characters
* 0x20-0x7e, NUL terminated. For best compatibility with players,
* use picture data of MIME type \c image/jpeg or \c image/png. A
* MIME type of '-->' is also allowed, in which case the picture
* data should be a complete URL. In file storage, the MIME type is
* stored as a 32-bit length followed by the ASCII string with no NUL
* terminator, but is converted to a plain C string in this structure
* for convenience.
*/
FLAC__byte *description;
/**< Picture's description in UTF-8, NUL terminated. In file storage,
* the description is stored as a 32-bit length followed by the UTF-8
* string with no NUL terminator, but is converted to a plain C string
* in this structure for convenience.
*/
FLAC__uint32 width;
/**< Picture's width in pixels. */
FLAC__uint32 height;
/**< Picture's height in pixels. */
FLAC__uint32 depth;
/**< Picture's color depth in bits-per-pixel. */
FLAC__uint32 colors;
/**< For indexed palettes (like GIF), picture's number of colors (the
* number of palette entries), or \c 0 for non-indexed (i.e. 2^depth).
*/
FLAC__uint32 data_length;
/**< Length of binary picture data in bytes. */
FLAC__byte *data;
/**< Binary picture data. */
} FLAC__StreamMetadata_Picture;
extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_TYPE_LEN; /**< == 32 (bits) */
extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN; /**< == 32 (bits) */
extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN; /**< == 32 (bits) */
extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN; /**< == 32 (bits) */
extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN; /**< == 32 (bits) */
extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN; /**< == 32 (bits) */
extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_COLORS_LEN; /**< == 32 (bits) */
extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN; /**< == 32 (bits) */
/** Structure that is used when a metadata block of unknown type is loaded.
* The contents are opaque. The structure is used only internally to
* correctly handle unknown metadata.
*/
typedef struct {
FLAC__byte *data;
} FLAC__StreamMetadata_Unknown;
/** FLAC metadata block structure. (c.f. <A HREF="../format.html#metadata_block">format specification</A>)
*/
typedef struct {
FLAC__MetadataType type;
/**< The type of the metadata block; used determine which member of the
* \a data union to dereference. If type >= FLAC__METADATA_TYPE_UNDEFINED
* then \a data.unknown must be used. */
FLAC__bool is_last;
/**< \c true if this metadata block is the last, else \a false */
unsigned length;
/**< Length, in bytes, of the block data as it appears in the stream. */
union {
FLAC__StreamMetadata_StreamInfo stream_info;
FLAC__StreamMetadata_Padding padding;
FLAC__StreamMetadata_Application application;
FLAC__StreamMetadata_SeekTable seek_table;
FLAC__StreamMetadata_VorbisComment vorbis_comment;
FLAC__StreamMetadata_CueSheet cue_sheet;
FLAC__StreamMetadata_Picture picture;
FLAC__StreamMetadata_Unknown unknown;
} data;
/**< Polymorphic block data; use the \a type value to determine which
* to use. */
} FLAC__StreamMetadata;
extern FLAC_API const unsigned FLAC__STREAM_METADATA_IS_LAST_LEN; /**< == 1 (bit) */
extern FLAC_API const unsigned FLAC__STREAM_METADATA_TYPE_LEN; /**< == 7 (bits) */
extern FLAC_API const unsigned FLAC__STREAM_METADATA_LENGTH_LEN; /**< == 24 (bits) */
/** The total stream length of a metadata block header in bytes. */
#define FLAC__STREAM_METADATA_HEADER_LENGTH (4u)
/*****************************************************************************/
/*****************************************************************************
*
* Utility functions
*
*****************************************************************************/
/** Tests that a sample rate is valid for FLAC.
*
* \param sample_rate The sample rate to test for compliance.
* \retval FLAC__bool
* \c true if the given sample rate conforms to the specification, else
* \c false.
*/
FLAC_API FLAC__bool FLAC__format_sample_rate_is_valid(unsigned sample_rate);
/** Tests that a blocksize at the given sample rate is valid for the FLAC
* subset.
*
* \param blocksize The blocksize to test for compliance.
* \param sample_rate The sample rate is needed, since the valid subset
* blocksize depends on the sample rate.
* \retval FLAC__bool
* \c true if the given blocksize conforms to the specification for the
* subset at the given sample rate, else \c false.
*/
FLAC_API FLAC__bool FLAC__format_blocksize_is_subset(unsigned blocksize, unsigned sample_rate);
/** Tests that a sample rate is valid for the FLAC subset. The subset rules
* for valid sample rates are slightly more complex since the rate has to
* be expressible completely in the frame header.
*
* \param sample_rate The sample rate to test for compliance.
* \retval FLAC__bool
* \c true if the given sample rate conforms to the specification for the
* subset, else \c false.
*/
FLAC_API FLAC__bool FLAC__format_sample_rate_is_subset(unsigned sample_rate);
/** Check a Vorbis comment entry name to see if it conforms to the Vorbis
* comment specification.
*
* Vorbis comment names must be composed only of characters from
* [0x20-0x3C,0x3E-0x7D].
*
* \param name A NUL-terminated string to be checked.
* \assert
* \code name != NULL \endcode
* \retval FLAC__bool
* \c false if entry name is illegal, else \c true.
*/
FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_name_is_legal(const char *name);
/** Check a Vorbis comment entry value to see if it conforms to the Vorbis
* comment specification.
*
* Vorbis comment values must be valid UTF-8 sequences.
*
* \param value A string to be checked.
* \param length A the length of \a value in bytes. May be
* \c (unsigned)(-1) to indicate that \a value is a plain
* UTF-8 NUL-terminated string.
* \assert
* \code value != NULL \endcode
* \retval FLAC__bool
* \c false if entry name is illegal, else \c true.
*/
FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_value_is_legal(const FLAC__byte *value, unsigned length);
/** Check a Vorbis comment entry to see if it conforms to the Vorbis
* comment specification.
*
* Vorbis comment entries must be of the form 'name=value', and 'name' and
* 'value' must be legal according to
* FLAC__format_vorbiscomment_entry_name_is_legal() and
* FLAC__format_vorbiscomment_entry_value_is_legal() respectively.
*
* \param entry An entry to be checked.
* \param length The length of \a entry in bytes.
* \assert
* \code value != NULL \endcode
* \retval FLAC__bool
* \c false if entry name is illegal, else \c true.
*/
FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_is_legal(const FLAC__byte *entry, unsigned length);
/** Check a seek table to see if it conforms to the FLAC specification.
* See the format specification for limits on the contents of the
* seek table.
*
* \param seek_table A pointer to a seek table to be checked.
* \assert
* \code seek_table != NULL \endcode
* \retval FLAC__bool
* \c false if seek table is illegal, else \c true.
*/
FLAC_API FLAC__bool FLAC__format_seektable_is_legal(const FLAC__StreamMetadata_SeekTable *seek_table);
/** Sort a seek table's seek points according to the format specification.
* This includes a "unique-ification" step to remove duplicates, i.e.
* seek points with identical \a sample_number values. Duplicate seek
* points are converted into placeholder points and sorted to the end of
* the table.
*
* \param seek_table A pointer to a seek table to be sorted.
* \assert
* \code seek_table != NULL \endcode
* \retval unsigned
* The number of duplicate seek points converted into placeholders.
*/
FLAC_API unsigned FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *seek_table);
/** Check a cue sheet to see if it conforms to the FLAC specification.
* See the format specification for limits on the contents of the
* cue sheet.
*
* \param cue_sheet A pointer to an existing cue sheet to be checked.
* \param check_cd_da_subset If \c true, check CUESHEET against more
* stringent requirements for a CD-DA (audio) disc.
* \param violation Address of a pointer to a string. If there is a
* violation, a pointer to a string explanation of the
* violation will be returned here. \a violation may be
* \c NULL if you don't need the returned string. Do not
* free the returned string; it will always point to static
* data.
* \assert
* \code cue_sheet != NULL \endcode
* \retval FLAC__bool
* \c false if cue sheet is illegal, else \c true.
*/
FLAC_API FLAC__bool FLAC__format_cuesheet_is_legal(const FLAC__StreamMetadata_CueSheet *cue_sheet, FLAC__bool check_cd_da_subset, const char **violation);
/** Check picture data to see if it conforms to the FLAC specification.
* See the format specification for limits on the contents of the
* PICTURE block.
*
* \param picture A pointer to existing picture data to be checked.
* \param violation Address of a pointer to a string. If there is a
* violation, a pointer to a string explanation of the
* violation will be returned here. \a violation may be
* \c NULL if you don't need the returned string. Do not
* free the returned string; it will always point to static
* data.
* \assert
* \code picture != NULL \endcode
* \retval FLAC__bool
* \c false if picture data is illegal, else \c true.
*/
FLAC_API FLAC__bool FLAC__format_picture_is_legal(const FLAC__StreamMetadata_Picture *picture, const char **violation);
/* \} */
#ifdef __cplusplus
}
#endif
#endif
|
1441d089dfcdb9558459c8ce83801a74bd145299
|
aa3befea459382dc5c01c925653d54f435b3fb0f
|
/arch/mips/src/pic32mx/excptmacros.h
|
81487185d901b73f9754add08480664c2636e2ee
|
[
"MIT-open-group",
"BSD-3-Clause",
"HPND-sell-variant",
"BSD-4-Clause-UC",
"LicenseRef-scancode-warranty-disclaimer",
"MIT-0",
"LicenseRef-scancode-bsd-atmel",
"LicenseRef-scancode-gary-s-brown",
"LicenseRef-scancode-proprietary-license",
"SunPro",
"MIT",
"LicenseRef-scancode-public-domain-disclaimer",
"LicenseRef-scancode-other-permissive",
"HPND",
"ISC",
"Apache-2.0",
"LicenseRef-scancode-public-domain",
"BSD-2-Clause",
"GPL-1.0-or-later",
"CC-BY-2.0",
"CC-BY-4.0"
] |
permissive
|
apache/nuttx
|
14519a7bff4a87935d94fb8fb2b19edb501c7cec
|
606b6d9310fb25c7d92c6f95bf61737e3c79fa0f
|
refs/heads/master
| 2023-08-25T06:55:45.822534
| 2023-08-23T16:03:31
| 2023-08-24T21:25:47
| 228,103,273
| 407
| 241
|
Apache-2.0
| 2023-09-14T18:26:05
| 2019-12-14T23:27:55
|
C
|
UTF-8
|
C
| false
| false
| 11,597
|
h
|
excptmacros.h
|
/****************************************************************************
* arch/mips/src/pic32mx/excptmacros.h
*
* 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.
*
****************************************************************************/
#ifndef __ARCH_MIPS_SRC_PIC32MX_EXCPTMACROS_H
#define __ARCH_MIPS_SRC_PIC32MX_EXCPTMACROS_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <arch/irq.h>
#include <arch/pic32mx/cp0.h>
#ifdef __ASSEMBLY__
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Public Symbols
****************************************************************************/
#if CONFIG_ARCH_INTERRUPTSTACK > 3
.global g_intstackalloc
.global g_intstacktop
#ifdef CONFIG_PIC32MX_NESTED_INTERRUPTS
.global g_nestlevel
#endif
#endif
/****************************************************************************
* Assembly Language Macros
****************************************************************************/
/****************************************************************************
* General Usage Example:
*
* my_exception:
* EXCPT_PROLOGUE t0 - Save registers on stack, enable nested interrupts
* move a0, sp - Pass register save structure as the parameter 1
* USE_INTSTACK t0, t1, t2, t3 - Switch to the interrupt stack
* jal handler - Handle the exception IN=old regs OUT=new regs
* di - Disable interrupts
* RESTORE_STACK t0, t1 - Undo the operations of USE_STACK
* EXCPT_EPILOGUE v0 - Return to the context returned by handler()
*
****************************************************************************/
/****************************************************************************
* Name: EXCPT_PROLOGUE
*
* Description:
* Provides the "prologue" logic that should appear at the beginning of
* every exception handler.
*
* On Entry:
* sp - Points to the top of the stack
* tmp - Is a register the can be modified for scratch usage (after it has
* been saved)
* k0 and k1 - Since we are in an exception handler,
* these are available for use
*
* At completion:
* Register state is saved on the stack; All registers are available for
* usage except sp and k1:
*
* - sp points the beginning of the register save area
* - k1 holds the value of the STATUS register
*
* The following registers are modified: k0, k1, sp, a0
*
****************************************************************************/
.macro EXCPT_PROLOGUE, tmp
.set noat
/* Get the SP from the previous shadow set */
#if 0
rdpgpr sp, sp
#endif
/* "When entering the interrupt handler routine, the interrupt controller
* must first save the current priority and exception PC counter from
* Interrupt Priority (IPL) bits (Status<15:10>) and the ErrorEPC
* register, respectively, on the stack. ..."
*/
#ifdef CONFIG_PIC32MX_NESTED_INTERRUPTS /* Does not work! */
mfc0 k0, MIPS32_CP0_CAUSE
mfc0 k1, MIPS32_CP0_EPC
/* Isolate the pending interrupt level in bits 0-5 of k0 */
srl k0, k0, CP0_CAUSE_IP_SHIFT
/* Create the register context stack frame large enough to hold the entire
* register save array.
*/
addiu sp, sp, -XCPTCONTEXT_SIZE
/* Save the EPC and STATUS in the register context array */
sw k1, REG_EPC(sp)
mfc0 k1, MIPS32_CP0_STATUS
sw k1, REG_STATUS(sp)
/* Then insert pending interrupt level as the current mask level in the CP0
* status register.
* Also clear bits 1-4 in new value of the status register:
*
* Bit 1: Exception Level
* Bit 2: Error Level
* Bit 3: (not used in PIC32MX)
* Bit 4: Operating mode == USER
*/
ins k1, k0, CP0_STATUS_IPL_SHIFT, 6
ins k1, zero, 1, 4
/* And Enable interrupts */
mtc0 k1, MIPS32_CP0_STATUS
#else
/* Get the EPC and STATUS register (Don't bother with the CAUSE register if
* we are not supporting nested interrupts)
*/
mfc0 k0, MIPS32_CP0_EPC
mfc0 k1, MIPS32_CP0_STATUS
/* Create the register context stack frame large enough to hold the entire
* register save array.
*/
addiu sp, sp, -XCPTCONTEXT_SIZE
/* Save the EPC and STATUS in the register context array */
sw k0, REG_EPC(sp)
sw k1, REG_STATUS(sp)
#endif
/* Save floating point registers */
mfhi k0
sw k0, REG_MFHI(sp)
mflo k0
sw k0, REG_MFLO(sp)
/* Save general purpose registers */
/* $1: at_reg, assembler temporary */
sw $1, REG_AT(sp)
/* $2-$3 = v0-v1: Return value registers */
sw v0, REG_V0(sp)
sw v1, REG_V1(sp)
/* $4-$7 = a0-a3: Argument registers */
sw a0, REG_A0(sp)
sw a1, REG_A1(sp)
sw a2, REG_A2(sp)
sw a3, REG_A3(sp)
/* $8-$15 = t0-t7: Volatile registers */
sw t0, REG_T0(sp)
sw t1, REG_T1(sp)
sw t2, REG_T2(sp)
sw t3, REG_T3(sp)
sw t4, REG_T4(sp)
sw t5, REG_T5(sp)
sw t6, REG_T6(sp)
sw t7, REG_T7(sp)
/* $16-$23 = s0-s7: Static registers */
sw s0, REG_S0(sp)
sw s1, REG_S1(sp)
sw s2, REG_S2(sp)
sw s3, REG_S3(sp)
sw s4, REG_S4(sp)
sw s5, REG_S5(sp)
sw s6, REG_S6(sp)
sw s7, REG_S7(sp)
/* $24-25 = t8-t9: More Volatile registers */
sw t8, REG_T8(sp)
sw t9, REG_T9(sp)
/* $26-$27 = ko-k1: Reserved for use in exception handers.
* These do not need to be saved.
*
* $28 = gp: Only needs to be saved under conditions where there are
* multiple, per- thread values for the GP.
*/
#ifdef MIPS32_SAVE_GP
sw gp, REG_GP(sp)
#endif
/* $30 = either s8 or fp: Depends if a frame pointer is used or not */
sw s8, REG_S8(sp)
/* $31 = ra: Return address */
sw ra, REG_RA(sp)
/* $29 = sp: The value of the stack pointer on return from the exception.
* a0 is used as a temporary
*/
addiu \tmp, sp, XCPTCONTEXT_SIZE
sw \tmp, REG_SP(sp)
.endm
/****************************************************************************
* Name: EXCPT_EPILOGUE
*
* Description:
* Provides the "epilogue" logic that should appear at the end of every
* exception handler.
*
* On input:
* regs - points to the register save structure.
* NOTE: This *may not* be an address lying in a stack!
* It might be an address in a TCB!
* Interrupts are disabled (via 'di')
*
* On completion:
* All registers restored
* eret is executed to return from the exception
*
****************************************************************************/
.macro EXCPT_EPILOGUE, regs
.set noat
/* Since interrupts are disabled via di can now use k0 and k1 again.
* Use k1 as the pointer to the register save array.
*/
move k1, \regs
/* Restore the floating point register state */
lw k0, REG_MFLO(k1)
mtlo k0
lw k0, REG_MFHI(k1)
mthi k0
/* Restore general purpose registers */
/* $1: at_reg, assembler temporary */
lw $1, REG_AT(k1)
/* $2-$3 = v0-v1: Return value registers */
lw v0, REG_V0(k1)
lw v1, REG_V1(k1)
/* $4-$7 = a0-a3: Argument registers */
lw a0, REG_A0(k1)
lw a1, REG_A1(k1)
lw a2, REG_A2(k1)
lw a3, REG_A3(k1)
/* $8-$15 = t0-t7: Volatile registers */
lw t0, REG_T0(k1)
lw t1, REG_T1(k1)
lw t2, REG_T2(k1)
lw t3, REG_T3(k1)
lw t4, REG_T4(k1)
lw t5, REG_T5(k1)
lw t6, REG_T6(k1)
lw t7, REG_T7(k1)
/* $16-$23 = s0-s7: Static registers */
lw s0, REG_S0(k1)
lw s1, REG_S1(k1)
lw s2, REG_S2(k1)
lw s3, REG_S3(k1)
lw s4, REG_S4(k1)
lw s5, REG_S5(k1)
lw s6, REG_S6(k1)
lw s7, REG_S7(k1)
/* $24-25 = t8-t9: More Volatile registers */
lw t8, REG_T8(k1)
lw t9, REG_T9(k1)
/* $26-$27 = ko-k1: Reserved for use in exception handers.
* These do not need to be saved.
*
* $28 = gp: Only needs to be saved under conditions where there
* are multiple, per- thread values for the GP.
*/
#ifdef MIPS32_SAVE_GP
lw gp, REG_GP(k1)
#endif
/* $29 = sp: Stack pointer */
lw sp, REG_SP(k1)
/* $30 = either s8 or fp: Depends if a frame pointer is used or not */
lw s8, REG_S8(k1)
/* $31 = ra: Return address */
lw ra, REG_RA(k1)
/* Finally, restore CP status and the EPC */
lw k0, REG_STATUS(k1)
lw k1, REG_EPC(k1)
mtc0 k0, MIPS32_CP0_STATUS
ehb
mtc0 k1, MIPS32_CP0_EPC
eret
nop
.endm
/****************************************************************************
* Name: USE_INTSTACK
*
* Description:
* Switch to the interrupt stack (if enabled in the configuration).
*
* On Entry:
* sp - Current value of the user stack pointer
* tmp1, tmp2, tmp3, and tmp4 are registers that can be used temporarily.
* All interrupts should still be disabled.
*
* At completion:
* If the nesting level is 0, then (1) the user stack pointer is saved
* at the base of the interrupt stack and sp points to the interrupt stack.
* The values of tmp1, tmp2, tmp3, and sp have been altered
*
****************************************************************************/
.macro USE_INTSTACK, tmp1, tmp2, tmp3, tmp4
#if CONFIG_ARCH_INTERRUPTSTACK > 3
#ifdef CONFIG_PIC32MX_NESTED_INTERRUPTS
/* Check the nesting level. If there are no nested interrupts, then we can
* claim the interrupt stack.
*/
la \tmp1, g_nestlevel
lw \tmp2, (\tmp1)
bne 1f
nop
#endif
/* Use the interrupt stack, pushing the user stack pointer onto the
* interrupt stack first.
*/
la \tmp3, g_intstacktop
lw \tmp4, (\tmp3)
sw sp, (\tmp4)
move sp, \tmp4
#ifdef CONFIG_PIC32MX_NESTED_INTERRUPTS
1:
/* Increment the interrupt nesting level */
addiu \tmp2, \tmp2, 1
sw \tmp2, 0(\tmp1)
#endif
#endif
.endm
/****************************************************************************
* Name: RESTORE_STACK
*
* Description:
* Restore the user stack. Not really.. actually only decrements the
* nesting level. We always get the new stack pointer for the register
* save array.
*
* On Entry:
* tmp1 and tmp2 are registers that can be used temporarily.
* All interrupts must be disabled.
*
* At completion:
* Current nesting level is decremented
* The values of tmp1 and tmp2 have been altered
*
****************************************************************************/
.macro RESTORE_STACK, tmp1, tmp2
#if CONFIG_ARCH_INTERRUPTSTACK > 3
#ifdef CONFIG_PIC32MX_NESTED_INTERRUPTS
/* Decrement the nesting level */
la \tmp1, g_nestlevel
lw \tmp2, (\tmp1)
addiu \tmp2, \tmp2, -1
sw \tmp2, 0(\tmp1)
#endif
#endif
.endm
#endif /* __ASSEMBLY__ */
#endif /* __ARCH_MIPS_SRC_PIC32MX_EXCPTMACROS_H */
|
16d5d1ab38055d303a6f4f6261912f7fb47ba5af
|
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
|
/SOFTWARE/A64-TERES/linux-a64/arch/cris/arch-v10/mm/init.c
|
e7f8066105aa39e9e81505b762393492261329cc
|
[
"Linux-syscall-note",
"GPL-2.0-only",
"GPL-1.0-or-later",
"LicenseRef-scancode-free-unknown",
"Apache-2.0"
] |
permissive
|
OLIMEX/DIY-LAPTOP
|
ae82f4ee79c641d9aee444db9a75f3f6709afa92
|
a3fafd1309135650bab27f5eafc0c32bc3ca74ee
|
refs/heads/rel3
| 2023-08-04T01:54:19.483792
| 2023-04-03T07:18:12
| 2023-04-03T07:18:12
| 80,094,055
| 507
| 92
|
Apache-2.0
| 2023-04-03T07:05:59
| 2017-01-26T07:25:50
|
C
|
UTF-8
|
C
| false
| false
| 9,119
|
c
|
init.c
|
/*
* linux/arch/cris/arch-v10/mm/init.c
*
*/
#include <linux/mmzone.h>
#include <linux/init.h>
#include <linux/bootmem.h>
#include <linux/mm.h>
#include <asm/pgtable.h>
#include <asm/page.h>
#include <asm/types.h>
#include <asm/mmu.h>
#include <asm/io.h>
#include <asm/mmu_context.h>
#include <arch/svinto.h>
extern void tlb_init(void);
/*
* The kernel is already mapped with a kernel segment at kseg_c so
* we don't need to map it with a page table. However head.S also
* temporarily mapped it at kseg_4 so we should set up the ksegs again,
* clear the TLB and do some other paging setup stuff.
*/
void __init
paging_init(void)
{
int i;
unsigned long zones_size[MAX_NR_ZONES];
printk("Setting up paging and the MMU.\n");
/* clear out the init_mm.pgd that will contain the kernel's mappings */
for(i = 0; i < PTRS_PER_PGD; i++)
swapper_pg_dir[i] = __pgd(0);
/* make sure the current pgd table points to something sane
* (even if it is most probably not used until the next
* switch_mm)
*/
per_cpu(current_pgd, smp_processor_id()) = init_mm.pgd;
/* initialise the TLB (tlb.c) */
tlb_init();
/* see README.mm for details on the KSEG setup */
#ifdef CONFIG_CRIS_LOW_MAP
/* Etrax-100 LX version 1 has a bug so that we cannot map anything
* across the 0x80000000 boundary, so we need to shrink the user-virtual
* area to 0x50000000 instead of 0xb0000000 and map things slightly
* different. The unused areas are marked as paged so that we can catch
* freak kernel accesses there.
*
* The ARTPEC chip is mapped at 0xa so we pass that segment straight
* through. We cannot vremap it because the vmalloc area is below 0x8
* and Juliette needs an uncached area above 0x8.
*
* Same thing with 0xc and 0x9, which is memory-mapped I/O on some boards.
* We map them straight over in LOW_MAP, but use vremap in LX version 2.
*/
#define CACHED_BOOTROM (KSEG_F | 0x08000000UL)
*R_MMU_KSEG = ( IO_STATE(R_MMU_KSEG, seg_f, seg ) | /* bootrom */
IO_STATE(R_MMU_KSEG, seg_e, page ) |
IO_STATE(R_MMU_KSEG, seg_d, page ) |
IO_STATE(R_MMU_KSEG, seg_c, page ) |
IO_STATE(R_MMU_KSEG, seg_b, seg ) | /* kernel reg area */
#ifdef CONFIG_JULIETTE
IO_STATE(R_MMU_KSEG, seg_a, seg ) | /* ARTPEC etc. */
#else
IO_STATE(R_MMU_KSEG, seg_a, page ) |
#endif
IO_STATE(R_MMU_KSEG, seg_9, seg ) | /* LED's on some boards */
IO_STATE(R_MMU_KSEG, seg_8, seg ) | /* CSE0/1, flash and I/O */
IO_STATE(R_MMU_KSEG, seg_7, page ) | /* kernel vmalloc area */
IO_STATE(R_MMU_KSEG, seg_6, seg ) | /* kernel DRAM area */
IO_STATE(R_MMU_KSEG, seg_5, seg ) | /* cached flash */
IO_STATE(R_MMU_KSEG, seg_4, page ) | /* user area */
IO_STATE(R_MMU_KSEG, seg_3, page ) | /* user area */
IO_STATE(R_MMU_KSEG, seg_2, page ) | /* user area */
IO_STATE(R_MMU_KSEG, seg_1, page ) | /* user area */
IO_STATE(R_MMU_KSEG, seg_0, page ) ); /* user area */
*R_MMU_KBASE_HI = ( IO_FIELD(R_MMU_KBASE_HI, base_f, 0x3 ) |
IO_FIELD(R_MMU_KBASE_HI, base_e, 0x0 ) |
IO_FIELD(R_MMU_KBASE_HI, base_d, 0x0 ) |
IO_FIELD(R_MMU_KBASE_HI, base_c, 0x0 ) |
IO_FIELD(R_MMU_KBASE_HI, base_b, 0xb ) |
#ifdef CONFIG_JULIETTE
IO_FIELD(R_MMU_KBASE_HI, base_a, 0xa ) |
#else
IO_FIELD(R_MMU_KBASE_HI, base_a, 0x0 ) |
#endif
IO_FIELD(R_MMU_KBASE_HI, base_9, 0x9 ) |
IO_FIELD(R_MMU_KBASE_HI, base_8, 0x8 ) );
*R_MMU_KBASE_LO = ( IO_FIELD(R_MMU_KBASE_LO, base_7, 0x0 ) |
IO_FIELD(R_MMU_KBASE_LO, base_6, 0x4 ) |
IO_FIELD(R_MMU_KBASE_LO, base_5, 0x0 ) |
IO_FIELD(R_MMU_KBASE_LO, base_4, 0x0 ) |
IO_FIELD(R_MMU_KBASE_LO, base_3, 0x0 ) |
IO_FIELD(R_MMU_KBASE_LO, base_2, 0x0 ) |
IO_FIELD(R_MMU_KBASE_LO, base_1, 0x0 ) |
IO_FIELD(R_MMU_KBASE_LO, base_0, 0x0 ) );
#else
/* This code is for the corrected Etrax-100 LX version 2... */
#define CACHED_BOOTROM (KSEG_A | 0x08000000UL)
*R_MMU_KSEG = ( IO_STATE(R_MMU_KSEG, seg_f, seg ) | /* cached flash */
IO_STATE(R_MMU_KSEG, seg_e, seg ) | /* uncached flash */
IO_STATE(R_MMU_KSEG, seg_d, page ) | /* vmalloc area */
IO_STATE(R_MMU_KSEG, seg_c, seg ) | /* kernel area */
IO_STATE(R_MMU_KSEG, seg_b, seg ) | /* kernel reg area */
IO_STATE(R_MMU_KSEG, seg_a, seg ) | /* bootrom */
IO_STATE(R_MMU_KSEG, seg_9, page ) | /* user area */
IO_STATE(R_MMU_KSEG, seg_8, page ) |
IO_STATE(R_MMU_KSEG, seg_7, page ) |
IO_STATE(R_MMU_KSEG, seg_6, page ) |
IO_STATE(R_MMU_KSEG, seg_5, page ) |
IO_STATE(R_MMU_KSEG, seg_4, page ) |
IO_STATE(R_MMU_KSEG, seg_3, page ) |
IO_STATE(R_MMU_KSEG, seg_2, page ) |
IO_STATE(R_MMU_KSEG, seg_1, page ) |
IO_STATE(R_MMU_KSEG, seg_0, page ) );
*R_MMU_KBASE_HI = ( IO_FIELD(R_MMU_KBASE_HI, base_f, 0x0 ) |
IO_FIELD(R_MMU_KBASE_HI, base_e, 0x8 ) |
IO_FIELD(R_MMU_KBASE_HI, base_d, 0x0 ) |
IO_FIELD(R_MMU_KBASE_HI, base_c, 0x4 ) |
IO_FIELD(R_MMU_KBASE_HI, base_b, 0xb ) |
IO_FIELD(R_MMU_KBASE_HI, base_a, 0x3 ) |
IO_FIELD(R_MMU_KBASE_HI, base_9, 0x0 ) |
IO_FIELD(R_MMU_KBASE_HI, base_8, 0x0 ) );
*R_MMU_KBASE_LO = ( IO_FIELD(R_MMU_KBASE_LO, base_7, 0x0 ) |
IO_FIELD(R_MMU_KBASE_LO, base_6, 0x0 ) |
IO_FIELD(R_MMU_KBASE_LO, base_5, 0x0 ) |
IO_FIELD(R_MMU_KBASE_LO, base_4, 0x0 ) |
IO_FIELD(R_MMU_KBASE_LO, base_3, 0x0 ) |
IO_FIELD(R_MMU_KBASE_LO, base_2, 0x0 ) |
IO_FIELD(R_MMU_KBASE_LO, base_1, 0x0 ) |
IO_FIELD(R_MMU_KBASE_LO, base_0, 0x0 ) );
#endif
*R_MMU_CONTEXT = ( IO_FIELD(R_MMU_CONTEXT, page_id, 0 ) );
/* The MMU has been enabled ever since head.S but just to make
* it totally obvious we do it here as well.
*/
*R_MMU_CTRL = ( IO_STATE(R_MMU_CTRL, inv_excp, enable ) |
IO_STATE(R_MMU_CTRL, acc_excp, enable ) |
IO_STATE(R_MMU_CTRL, we_excp, enable ) );
*R_MMU_ENABLE = IO_STATE(R_MMU_ENABLE, mmu_enable, enable);
/*
* initialize the bad page table and bad page to point
* to a couple of allocated pages
*/
empty_zero_page = (unsigned long)alloc_bootmem_pages(PAGE_SIZE);
memset((void *)empty_zero_page, 0, PAGE_SIZE);
/* All pages are DMA'able in Etrax, so put all in the DMA'able zone */
zones_size[0] = ((unsigned long)high_memory - PAGE_OFFSET) >> PAGE_SHIFT;
for (i = 1; i < MAX_NR_ZONES; i++)
zones_size[i] = 0;
/* Use free_area_init_node instead of free_area_init, because the former
* is designed for systems where the DRAM starts at an address substantially
* higher than 0, like us (we start at PAGE_OFFSET). This saves space in the
* mem_map page array.
*/
free_area_init_node(0, zones_size, PAGE_OFFSET >> PAGE_SHIFT, 0);
}
/* Initialize remaps of some I/O-ports. It is important that this
* is called before any driver is initialized.
*/
static int
__init init_ioremap(void)
{
/* Give the external I/O-port addresses their values */
#ifdef CONFIG_CRIS_LOW_MAP
/* Simply a linear map (see the KSEG map above in paging_init) */
port_cse1_addr = (volatile unsigned long *)(MEM_CSE1_START |
MEM_NON_CACHEABLE);
port_csp0_addr = (volatile unsigned long *)(MEM_CSP0_START |
MEM_NON_CACHEABLE);
port_csp4_addr = (volatile unsigned long *)(MEM_CSP4_START |
MEM_NON_CACHEABLE);
#else
/* Note that nothing blows up just because we do this remapping
* it's ok even if the ports are not used or connected
* to anything (or connected to a non-I/O thing) */
port_cse1_addr = (volatile unsigned long *)
ioremap((unsigned long)(MEM_CSE1_START | MEM_NON_CACHEABLE), 16);
port_csp0_addr = (volatile unsigned long *)
ioremap((unsigned long)(MEM_CSP0_START | MEM_NON_CACHEABLE), 16);
port_csp4_addr = (volatile unsigned long *)
ioremap((unsigned long)(MEM_CSP4_START | MEM_NON_CACHEABLE), 16);
#endif
return 0;
}
__initcall(init_ioremap);
/* Helper function for the two below */
static inline void
flush_etrax_cacherange(void *startadr, int length)
{
/* CACHED_BOOTROM is mapped to the boot-rom area (cached) which
* we can use to get fast dummy-reads of cachelines
*/
volatile short *flushadr = (volatile short *)(((unsigned long)startadr & ~PAGE_MASK) |
CACHED_BOOTROM);
length = length > 8192 ? 8192 : length; /* No need to flush more than cache size */
while(length > 0) {
*flushadr; /* dummy read to flush */
flushadr += (32/sizeof(short)); /* a cacheline is 32 bytes */
length -= 32;
}
}
/* Due to a bug in Etrax100(LX) all versions, receiving DMA buffers
* will occasionally corrupt certain CPU writes if the DMA buffers
* happen to be hot in the cache.
*
* As a workaround, we have to flush the relevant parts of the cache
* before (re) inserting any receiving descriptor into the DMA HW.
*/
void
prepare_rx_descriptor(struct etrax_dma_descr *desc)
{
flush_etrax_cacherange((void *)desc->buf, desc->sw_len ? desc->sw_len : 65536);
}
/* Do the same thing but flush the entire cache */
void
flush_etrax_cache(void)
{
flush_etrax_cacherange(0, 8192);
}
|
44806ba94bc65fad9dd974990ffa5061bd6d6c6c
|
88ae8695987ada722184307301e221e1ba3cc2fa
|
/third_party/ffmpeg/libavfilter/af_asetrate.c
|
76f29144e5e489010214cb70e33927abf2f6609d
|
[
"Apache-2.0",
"LGPL-2.0-or-later",
"MIT",
"GPL-1.0-or-later",
"BSD-3-Clause",
"LGPL-2.1-only",
"LGPL-3.0-only",
"GPL-2.0-only",
"LGPL-2.1-or-later",
"GPL-3.0-or-later",
"LGPL-3.0-or-later",
"IJG",
"LicenseRef-scancode-other-permissive",
"GPL-2.0-or-later",
"GPL-3.0-only"
] |
permissive
|
iridium-browser/iridium-browser
|
71d9c5ff76e014e6900b825f67389ab0ccd01329
|
5ee297f53dc7f8e70183031cff62f37b0f19d25f
|
refs/heads/master
| 2023-08-03T16:44:16.844552
| 2023-07-20T15:17:00
| 2023-07-23T16:09:30
| 220,016,632
| 341
| 40
|
BSD-3-Clause
| 2021-08-13T13:54:45
| 2019-11-06T14:32:31
| null |
UTF-8
|
C
| false
| false
| 3,881
|
c
|
af_asetrate.c
|
/*
* Copyright (c) 2013 Nicolas George
*
* This file is part of FFmpeg.
*
* FFmpeg 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.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libavutil/opt.h"
#include "avfilter.h"
#include "internal.h"
typedef struct ASetRateContext {
const AVClass *class;
int sample_rate;
int rescale_pts;
} ASetRateContext;
#define CONTEXT ASetRateContext
#define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
#define OPT_GENERIC(name, field, def, min, max, descr, type, deffield, ...) \
{ name, descr, offsetof(CONTEXT, field), AV_OPT_TYPE_ ## type, \
{ .deffield = def }, min, max, FLAGS, __VA_ARGS__ }
#define OPT_INT(name, field, def, min, max, descr, ...) \
OPT_GENERIC(name, field, def, min, max, descr, INT, i64, __VA_ARGS__)
static const AVOption asetrate_options[] = {
OPT_INT("sample_rate", sample_rate, 44100, 1, INT_MAX, "set the sample rate",),
OPT_INT("r", sample_rate, 44100, 1, INT_MAX, "set the sample rate",),
{NULL},
};
AVFILTER_DEFINE_CLASS(asetrate);
static av_cold int query_formats(AVFilterContext *ctx)
{
ASetRateContext *sr = ctx->priv;
int sample_rates[] = { sr->sample_rate, -1 };
return ff_formats_ref(ff_make_format_list(sample_rates),
&ctx->outputs[0]->incfg.samplerates);
}
static av_cold int config_props(AVFilterLink *outlink)
{
AVFilterContext *ctx = outlink->src;
ASetRateContext *sr = ctx->priv;
AVFilterLink *inlink = ctx->inputs[0];
AVRational intb = ctx->inputs[0]->time_base;
int inrate = inlink->sample_rate;
if (intb.num == 1 && intb.den == inrate) {
outlink->time_base.num = 1;
outlink->time_base.den = outlink->sample_rate;
} else {
outlink->time_base = intb;
sr->rescale_pts = 1;
if (av_q2d(intb) > 1.0 / FFMAX(inrate, outlink->sample_rate))
av_log(ctx, AV_LOG_WARNING, "Time base is inaccurate\n");
}
return 0;
}
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
{
AVFilterContext *ctx = inlink->dst;
ASetRateContext *sr = ctx->priv;
AVFilterLink *outlink = ctx->outputs[0];
frame->sample_rate = outlink->sample_rate;
if (sr->rescale_pts)
frame->pts = av_rescale(frame->pts, inlink->sample_rate,
outlink->sample_rate);
return ff_filter_frame(outlink, frame);
}
static const AVFilterPad asetrate_inputs[] = {
{
.name = "default",
.type = AVMEDIA_TYPE_AUDIO,
.filter_frame = filter_frame,
},
};
static const AVFilterPad asetrate_outputs[] = {
{
.name = "default",
.type = AVMEDIA_TYPE_AUDIO,
.config_props = config_props,
},
};
const AVFilter ff_af_asetrate = {
.name = "asetrate",
.description = NULL_IF_CONFIG_SMALL("Change the sample rate without "
"altering the data."),
.priv_size = sizeof(ASetRateContext),
FILTER_INPUTS(asetrate_inputs),
FILTER_OUTPUTS(asetrate_outputs),
FILTER_QUERY_FUNC(query_formats),
.priv_class = &asetrate_class,
.flags = AVFILTER_FLAG_METADATA_ONLY,
};
|
cc259f989ad77df6a745f53b3e8059a9d21e535d
|
88ae8695987ada722184307301e221e1ba3cc2fa
|
/third_party/grpc/src/src/core/ext/upb-generated/xds/annotations/v3/security.upb.c
|
3ffb371b3d2efca0ee98dfa5a916073b513ba238
|
[
"Apache-2.0",
"LGPL-2.0-or-later",
"MIT",
"GPL-1.0-or-later",
"BSD-3-Clause",
"MPL-2.0"
] |
permissive
|
iridium-browser/iridium-browser
|
71d9c5ff76e014e6900b825f67389ab0ccd01329
|
5ee297f53dc7f8e70183031cff62f37b0f19d25f
|
refs/heads/master
| 2023-08-03T16:44:16.844552
| 2023-07-20T15:17:00
| 2023-07-23T16:09:30
| 220,016,632
| 341
| 40
|
BSD-3-Clause
| 2021-08-13T13:54:45
| 2019-11-06T14:32:31
| null |
UTF-8
|
C
| false
| false
| 1,839
|
c
|
security.upb.c
|
/* This file was generated by upbc (the upb compiler) from the input
* file:
*
* xds/annotations/v3/security.proto
*
* Do not edit -- your changes will be discarded when the file is
* regenerated. */
#include <stddef.h>
#include "upb/msg_internal.h"
#include "xds/annotations/v3/security.upb.h"
#include "xds/annotations/v3/status.upb.h"
#include "google/protobuf/descriptor.upb.h"
#include "upb/port_def.inc"
static const upb_MiniTable_Field xds_annotations_v3_FieldSecurityAnnotation__fields[2] = {
{1, UPB_SIZE(0, 0), UPB_SIZE(0, 0), kUpb_NoSub, 8, kUpb_FieldMode_Scalar | (kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)},
{2, UPB_SIZE(1, 1), UPB_SIZE(0, 0), kUpb_NoSub, 8, kUpb_FieldMode_Scalar | (kUpb_FieldRep_1Byte << kUpb_FieldRep_Shift)},
};
const upb_MiniTable xds_annotations_v3_FieldSecurityAnnotation_msginit = {
NULL,
&xds_annotations_v3_FieldSecurityAnnotation__fields[0],
UPB_SIZE(8, 8), 2, kUpb_ExtMode_NonExtendable, 2, 255, 0,
};
static const upb_MiniTable *messages_layout[1] = {
&xds_annotations_v3_FieldSecurityAnnotation_msginit,
};
extern const upb_MiniTable google_protobuf_FieldOptions_msginit;
extern const upb_MiniTable xds_annotations_v3_FieldSecurityAnnotation_msginit;
const upb_MiniTable_Extension xds_annotations_v3_security_ext = {
{99044135, UPB_SIZE(0, 0), UPB_SIZE(0, 0), 0, 11, kUpb_FieldMode_Scalar | kUpb_LabelFlags_IsExtension | (kUpb_FieldRep_Pointer << kUpb_FieldRep_Shift)},
&google_protobuf_FieldOptions_msginit,
{.submsg = &xds_annotations_v3_FieldSecurityAnnotation_msginit},
};
static const upb_MiniTable_Extension *extensions_layout[1] = {
&xds_annotations_v3_security_ext,
};
const upb_MiniTable_File xds_annotations_v3_security_proto_upb_file_layout = {
messages_layout,
NULL,
extensions_layout,
1,
0,
1,
};
#include "upb/port_undef.inc"
|
04756273c773bc09a28f69db91081c2de1ba5d5b
|
eecd5e4c50d8b78a769bcc2675250576bed34066
|
/src/sys/objects/pgname.c
|
7445afaf51051b254763fdcd37fd22b0d8cf6c55
|
[
"BSD-2-Clause"
] |
permissive
|
petsc/petsc
|
3b1a04fea71858e0292f9fd4d04ea11618c50969
|
9c5460f9064ca60dd71a234a1f6faf93e7a6b0c9
|
refs/heads/main
| 2023-08-17T20:51:16.507070
| 2023-08-17T16:08:06
| 2023-08-17T16:08:06
| 8,691,401
| 341
| 169
|
NOASSERTION
| 2023-03-29T11:02:58
| 2013-03-10T20:55:21
|
C
|
UTF-8
|
C
| false
| false
| 864
|
c
|
pgname.c
|
#include <petsc/private/petscimpl.h> /*I "petscsys.h" I*/
/*@C
PetscObjectGetName - Gets a string name associated with a PETSc object.
Not Collective unless object has not been named yet
Input Parameters:
+ obj - the Petsc variable
Thus must be cast with a (`PetscObject`), for example,
`PetscObjectGetName`((`PetscObject`)mat,&name);
- name - the name associated with obj
Note:
Calls `PetscObjectName()` if a name has not yet been provided to the object.
Level: intermediate
.seealso: `PetscObjectSetName()`, `PetscObjectName()`, `PetscObject`, `PetscObjectGetId()`
@*/
PetscErrorCode PetscObjectGetName(PetscObject obj, const char *name[])
{
PetscFunctionBegin;
PetscValidHeader(obj, 1);
PetscAssertPointer(name, 2);
PetscCall(PetscObjectName(obj));
*name = obj->name;
PetscFunctionReturn(PETSC_SUCCESS);
}
|
818c98c91e9a8b9a446b5a1e96d7f34d5621744b
|
a5a7c59b04a1a64fe34653c7970c3cf173f9c1df
|
/numerics/src/VI/VI_cst.h
|
f61ae5f6288a561e8c794a82cc668c76c7e86010
|
[
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] |
permissive
|
siconos/siconos
|
a7afdba41a2bc1192ad8dcd93ac7266fa281f4cf
|
82a8d1338bfc1be0d36b5e8a9f40c1ad5384a641
|
refs/heads/master
| 2023-08-21T22:22:55.625941
| 2023-07-17T13:07:32
| 2023-07-17T13:07:32
| 37,709,357
| 166
| 33
|
Apache-2.0
| 2023-07-17T12:31:16
| 2015-06-19T07:55:53
|
C
|
UTF-8
|
C
| false
| false
| 3,259
|
h
|
VI_cst.h
|
/* Siconos is a program dedicated to modeling, simulation and control
* of non smooth dynamical systems.
*
* Copyright 2022 INRIA.
*
* 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 VI_CST_H
#define VI_CST_H
/*!\file VI_cst.h
\brief Enum and constants relative to Variational Inequality problems and solvers.
*/
/** \enum VI_SOLVER
Available ids for VI solvers.
*/
enum VI_SOLVER
{
SICONOS_VI_EG = 1000,
SICONOS_VI_FPP = 1001,
SICONOS_VI_HP = 1002,
SICONOS_VI_BOX_QI = 1020,
SICONOS_VI_BOX_AVI_LSA = 1021,
SICONOS_VI_BOX_PATH = 1022
};
enum SICONOS_VI_IPARAM
{
SICONOS_VI_IPARAM_DECREASE_RHO = 3,
/** index in iparam to store the linesearch method */
SICONOS_VI_IPARAM_LINESEARCH_METHOD = 6,
/** index in iparam to store the error evaluation method */
SICONOS_VI_IPARAM_ERROR_EVALUATION = 7,
/** index in iparam to store the frequency of error evaluation method */
SICONOS_VI_IPARAM_ERROR_EVALUATION_FREQUENCY = 8,
/** index for max number of iterations allowed in line search*/
SICONOS_VI_IPARAM_LS_MAX_ITER = 9,
/** activate the update in the loop (0:false default choice) */
SICONOS_VI_IPARAM_ACTIVATE_UPDATE = 10,
};
/** Allowed values for iparam[SICONOS_VI_IPARAM_LINESEARCH_METHOD]
*/
enum SICONOS_VI_LINESEARCH_METHOD
{
/** : Armijo rule with Khotbotov ratio (default) */
SICONOS_VI_LS_ARMIJO = 0,
/** : Armijo rule with Solodov.Tseng ratio */
SICONOS_VI_LS_SOLODOV = 1,
/** Armijo rule with Han.Sun ratio */
SICONOS_VI_LS_HANSUN = 2,
};
enum SICONOS_VI_DPARAM
{
/** index in dparam to store the initial value of rho */
SICONOS_VI_DPARAM_RHO = 3,
/** index in dparam to store the tau coeff of line-search */
SICONOS_VI_DPARAM_LS_TAU = 4,
/** index in dparam to store the tauinv coeff of line-search */
SICONOS_VI_DPARAM_LS_TAUINV = 5,
/** index in dparam to store the L coeff of line-search */
SICONOS_VI_DPARAM_LS_L = 6,
/** index in dparam to store the LMIN coeff of line-search */
SICONOS_VI_DPARAM_LS_LMIN = 7,
/** index in dparam to store the sigma coeff (HP) */
SICONOS_VI_DPARAM_SIGMA = 8,
};
/** Allowed values for iparam[SICONOS_VI_IPARAM_ERROR_EVALUATION]
*/
enum SICONOS_VI_ERROR_EVALUATION_ENUM
{
SICONOS_VI_ERROR_EVALUATION_FULL = 0,
SICONOS_VI_ERROR_EVALUATION_LIGHT_WITH_FULL_FINAL = 1,
SICONOS_VI_ERROR_EVALUATION_LIGHT = 2,
SICONOS_VI_ERROR_EVALUATION_ADAPTIVE =3,
};
extern const char* const SICONOS_VI_EG_STR ;
extern const char* const SICONOS_VI_FPP_STR ;
extern const char* const SICONOS_VI_HP_STR ;
extern const char* const SICONOS_VI_BOX_QI_STR ;
extern const char* const SICONOS_VI_BOX_AVI_LSA_STR ;
extern const char* const SICONOS_VI_BOX_PATH_STR ;
#endif
|
46c805cb2e9244027f10fb0c4abd653f370d3313
|
376e1818d427b5e4d32fa6dd6c7b71e9fd88afdb
|
/net/tcl-scotty/patches/patch-tnm_snmp_tnmMibParser.c
|
9758d4514565704cd104cc991d19e71063caaecc
|
[] |
no_license
|
NetBSD/pkgsrc
|
a0732c023519650ef821ab89c23ab6ab59e25bdb
|
d042034ec4896cc5b47ed6f2e5b8802d9bc5c556
|
refs/heads/trunk
| 2023-09-01T07:40:12.138283
| 2023-09-01T05:25:19
| 2023-09-01T05:25:19
| 88,439,572
| 321
| 138
| null | 2023-07-12T22:34:14
| 2017-04-16T20:04:15
| null |
UTF-8
|
C
| false
| false
| 453
|
c
|
patch-tnm_snmp_tnmMibParser.c
|
$NetBSD: patch-tnm_snmp_tnmMibParser.c,v 1.1 2014/03/05 13:52:29 he Exp $
Constify.
--- tnm/snmp/tnmMibParser.c.orig 1998-10-20 15:51:08.000000000 +0000
+++ tnm/snmp/tnmMibParser.c
@@ -336,8 +336,8 @@ AddNewNode (nodeList, label, parentName,
Tnm_MibNode*
Tnm_MibParse(file, frozen, root)
- char *file;
- char *frozen;
+ const char *file;
+ const char *frozen;
Tnm_MibNode *root;
{
FILE *fp; /* The current FILE pointer. */
|
9e893ee0fda0fe5905281775f68037dc32d2744b
|
79d343002bb63a44f8ab0dbac0c9f4ec54078c3a
|
/lib/libc/include/any-linux-any/asm/types.h
|
57452ead0c63b99c937ee355c4f1d5378c106452
|
[
"MIT"
] |
permissive
|
ziglang/zig
|
4aa75d8d3bcc9e39bf61d265fd84b7f005623fc5
|
f4c9e19bc3213c2bc7e03d7b06d7129882f39f6c
|
refs/heads/master
| 2023-08-31T13:16:45.980913
| 2023-08-31T05:50:29
| 2023-08-31T05:50:29
| 40,276,274
| 25,560
| 2,399
|
MIT
| 2023-09-14T21:09:50
| 2015-08-06T00:51:28
|
Zig
|
UTF-8
|
C
| false
| false
| 30
|
h
|
types.h
|
#include <asm-generic/types.h>
|
dd5e71afb8b8ed6d4f465910f8ebfeaac4b2df4c
|
94b153fe49c2e7bd901c4f26d3cc4134920b4ccf
|
/docs/examples/c/ssession_test/session_test.c
|
4440eb01225b870145a74746c9e17e9cfd352224
|
[
"LicenseRef-scancode-proprietary-license",
"Apache-2.0"
] |
permissive
|
cossacklabs/themis
|
d6d39836fcebe88d228d25a670a35c556b6a117d
|
86096502c48a80edb11f567c92e26eb463eae36c
|
refs/heads/master
| 2023-08-17T03:48:03.760843
| 2023-07-10T19:57:46
| 2023-07-10T19:57:46
| 35,159,920
| 1,831
| 168
|
Apache-2.0
| 2023-09-14T04:05:12
| 2015-05-06T13:25:25
|
C
|
UTF-8
|
C
| false
| false
| 999
|
c
|
session_test.c
|
/*
* Copyright (c) 2015 Cossack Labs Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdio.h>
#include <stdlib.h>
#include "common.h"
#include <pthread.h>
int main(void)
{
pthread_t server_thread;
pthread_t client_thread;
pthread_create(&server_thread, NULL, run_server, NULL);
sleep(1); /* for server to become ready */
pthread_create(&client_thread, NULL, run_client, NULL);
pthread_join(server_thread, NULL);
pthread_join(client_thread, NULL);
return EXIT_SUCCESS;
}
|
4a4dbe194fed54212f4739d0df413b8774e18067
|
07bbe7a0a829cfbc9789831d981aedf36e4e94d9
|
/examples/lexbor/selectors/normal_way.c
|
97417d43a785d5b19a6944f18bc273c60668b177
|
[
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] |
permissive
|
lexbor/lexbor
|
0bf3a22898d8e295fa20cc1391e31a68502c458a
|
31e3d9d7f9032cd475d5afa788999de2d4b891dd
|
refs/heads/master
| 2023-08-31T23:25:49.903737
| 2023-08-30T08:25:12
| 2023-08-30T08:25:12
| 122,375,902
| 758
| 95
|
Apache-2.0
| 2023-08-30T08:25:13
| 2018-02-21T18:28:52
|
C
|
UTF-8
|
C
| false
| false
| 4,490
|
c
|
normal_way.c
|
/*
* Copyright (C) 2021 Alexander Borisov
*
* Author: Alexander Borisov <borisov@lexbor.com>
*/
#include <lexbor/html/html.h>
#include <lexbor/css/css.h>
#include <lexbor/selectors/selectors.h>
lxb_status_t
callback(const lxb_char_t *data, size_t len, void *ctx)
{
printf("%.*s", (int) len, (const char *) data);
return LXB_STATUS_OK;
}
lxb_status_t
find_callback(lxb_dom_node_t *node, lxb_css_selector_specificity_t spec,
void *ctx)
{
unsigned *count = ctx;
(*count)++;
printf("%u) ", *count);
(void) lxb_html_serialize_cb(node, callback, NULL);
printf("\n");
return LXB_STATUS_OK;
}
int
main(int argc, const char *argv[])
{
unsigned count = 0;
lxb_status_t status;
lxb_dom_node_t *body;
lxb_selectors_t *selectors;
lxb_css_selectors_t *css_selectors;
lxb_html_document_t *document;
lxb_css_parser_t *parser;
lxb_css_memory_t *memory;
lxb_css_selector_list_t *list_one;
lxb_css_selector_list_t *list_two;
/* HTML Data. */
static const lxb_char_t html[] = "<div><p class='x z'> </p><p id='y'>abc</p></div>";
/* CSS Data. */
static const lxb_char_t slctrs_one[] = ".x, div:has(p[id=Y i])";
static const lxb_char_t slctrs_two[] = "p:blank";
/* Create HTML Document. */
document = lxb_html_document_create();
status = lxb_html_document_parse(document, html,
sizeof(html) / sizeof(lxb_char_t) - 1);
if (status != LXB_STATUS_OK) {
return EXIT_FAILURE;
}
body = lxb_dom_interface_node(lxb_html_document_body_element(document));
/* Memory for all parsed structures. */
memory = lxb_css_memory_create();
status = lxb_css_memory_init(memory, 128);
if (status != LXB_STATUS_OK) {
return EXIT_FAILURE;
}
/* Create CSS parser. */
parser = lxb_css_parser_create();
status = lxb_css_parser_init(parser, NULL);
if (status != LXB_STATUS_OK) {
return EXIT_FAILURE;
}
lxb_css_parser_memory_set(parser, memory);
/* Create CSS Selector parser. */
css_selectors = lxb_css_selectors_create();
status = lxb_css_selectors_init(css_selectors);
if (status != LXB_STATUS_OK) {
return EXIT_FAILURE;
}
/* It is important that a new selector object is not created internally
* for each call to the parser.
*/
lxb_css_parser_selectors_set(parser, css_selectors);
/* Selectors. */
selectors = lxb_selectors_create();
status = lxb_selectors_init(selectors);
if (status != LXB_STATUS_OK) {
return EXIT_FAILURE;
}
/* Parse and get the log. */
list_one = lxb_css_selectors_parse(parser, slctrs_one,
sizeof(slctrs_one) / sizeof(lxb_char_t) - 1);
if (list_one == NULL) {
return EXIT_FAILURE;
}
list_two = lxb_css_selectors_parse(parser, slctrs_two,
sizeof(slctrs_two) / sizeof(lxb_char_t) - 1);
if (list_two == NULL) {
return EXIT_FAILURE;
}
/* HTML serialization. */
printf("HTML:\n");
(void) lxb_html_serialize_pretty_deep_cb(body, 0, 0, callback, NULL);
printf("\n");
/* Selector List Serialization. */
printf("First Selectors: ");
(void) lxb_css_selector_serialize_list_chain(list_one, callback, NULL);
printf("\n");
printf("Second Selectors: ");
(void) lxb_css_selector_serialize_list_chain(list_two, callback, NULL);
printf("\n");
/* Find HTML nodes by CSS Selectors. */
printf("\nFirst found:\n");
status = lxb_selectors_find(selectors, body, list_one,
find_callback, &count);
if (status != LXB_STATUS_OK) {
return EXIT_FAILURE;
}
printf("\nSecond found:\n");
status = lxb_selectors_find(selectors, body, list_two,
find_callback, &count);
if (status != LXB_STATUS_OK) {
return EXIT_FAILURE;
}
/* Destroy Objects. */
(void) lxb_selectors_destroy(selectors, true);
(void) lxb_css_parser_destroy(parser, true);
(void) lxb_css_memory_destroy(memory, true);
/*
* or use lxb_css_memory_destroy(parser->memory, true);
* or use lxb_css_selector_list_destroy_memory(list_one);
* for destroy all allocation memory.
*/
(void) lxb_css_selectors_destroy(css_selectors, true);
(void) lxb_html_document_destroy(document);
return EXIT_SUCCESS;
}
|
95312b804f6f428d0cd026bfce40aa72791f69fb
|
b36f34b6a24d019d624d1cc74f5b29062eef2ba4
|
/frameworks/cclua/src/bugly/lua_bugly.h
|
b1a06adc73b2778e4974b570dc5cead2659888d0
|
[
"MIT"
] |
permissive
|
zhongfq/cocos-lua
|
f49c1639f2c9a2a7678f9ed67e58114986ac882f
|
c2cf0f36ac0f0c91fb3456b555cacd8e8587be46
|
refs/heads/main
| 2023-08-17T17:13:05.705639
| 2023-08-17T06:06:36
| 2023-08-17T06:06:36
| 192,316,318
| 165
| 63
|
MIT
| 2023-08-14T23:59:30
| 2019-06-17T09:27:37
|
C
|
UTF-8
|
C
| false
| false
| 207
|
h
|
lua_bugly.h
|
//
// AUTO BUILD, DON'T MODIFY!
//
#ifndef __AUTO_GEN_LUA_BUGLY_H__
#define __AUTO_GEN_LUA_BUGLY_H__
#include "olua/olua.h"
OLUA_BEGIN_DECLS
OLUA_LIB int luaopen_bugly(lua_State *L);
OLUA_END_DECLS
#endif
|
d9af719a6e9a4a19117af3a9769e1c5d5c630609
|
035660e8cc10571ebbd0d4393fef063bb7eb98f6
|
/src/overlays/actors/ovl_En_Ge3/z_en_ge3.h
|
909ed7599ce1c5cf4ceaede69fbcf45f670f0b7d
|
[] |
no_license
|
zeldaret/mm
|
f163a5e7c4314105777369fa7671ce9c2a99922a
|
4ae00e909e74044f05155683b49d2561f91de7ba
|
refs/heads/master
| 2023-08-06T07:22:04.912966
| 2023-08-04T20:36:03
| 2023-08-04T20:36:03
| 247,875,852
| 915
| 328
| null | 2023-09-14T11:48:59
| 2020-03-17T04:03:07
|
C
|
UTF-8
|
C
| false
| false
| 316
|
h
|
z_en_ge3.h
|
#ifndef Z_EN_GE3_H
#define Z_EN_GE3_H
#include "global.h"
struct EnGe3;
typedef void (*EnGe3ActionFunc)(struct EnGe3*, PlayState*);
typedef struct EnGe3 {
/* 0x000 */ Actor actor;
/* 0x144 */ char unk_144[0x1D8];
/* 0x31C */ EnGe3ActionFunc actionFunc;
} EnGe3; // size = 0x320
#endif // Z_EN_GE3_H
|
8249d8905312897f2ede867ad726131bab874393
|
fb47ab6337a71029dee71933e449cf7f6805fc0f
|
/external/platform/cc13xx/cc13xxware/inc/hw_prcm.h
|
a377661a6c76b780c209823cd3afdc0aaf25f4a3
|
[
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] |
permissive
|
littlekernel/lk
|
7e7ba50b87b1f2e0b6e2f052c59249825c91975b
|
30dc320054f70910e1c1ee40a6948ee99672acec
|
refs/heads/master
| 2023-09-02T00:47:52.203963
| 2023-06-21T22:42:35
| 2023-06-21T22:42:35
| 3,058,456
| 3,077
| 618
|
MIT
| 2023-08-30T09:41:31
| 2011-12-27T19:19:36
|
C
|
UTF-8
|
C
| false
| false
| 65,731
|
h
|
hw_prcm.h
|
/******************************************************************************
* Filename: hw_prcm_h
* Revised: 2015-11-12 13:07:02 +0100 (Thu, 12 Nov 2015)
* Revision: 45056
*
* Copyright (c) 2015, Texas Instruments Incorporated
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1) Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2) Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3) Neither the name of the ORGANIZATION nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************/
#ifndef __HW_PRCM_H__
#define __HW_PRCM_H__
//*****************************************************************************
//
// This section defines the register offsets of
// PRCM component
//
//*****************************************************************************
// Infrastructure Clock Division Factor For Run Mode
#define PRCM_O_INFRCLKDIVR 0x00000000
// Infrastructure Clock Division Factor For Sleep Mode
#define PRCM_O_INFRCLKDIVS 0x00000004
// Infrastructure Clock Division Factor For DeepSleep Mode
#define PRCM_O_INFRCLKDIVDS 0x00000008
// MCU Voltage Domain Control
#define PRCM_O_VDCTL 0x0000000C
// Clock Load Control
#define PRCM_O_CLKLOADCTL 0x00000028
// RFC Clock Gate
#define PRCM_O_RFCCLKG 0x0000002C
// VIMS Clock Gate
#define PRCM_O_VIMSCLKG 0x00000030
// TRNG, CRYPTO And UDMA Clock Gate For Run Mode
#define PRCM_O_SECDMACLKGR 0x0000003C
// TRNG, CRYPTO And UDMA Clock Gate For Sleep Mode
#define PRCM_O_SECDMACLKGS 0x00000040
// TRNG, CRYPTO And UDMA Clock Gate For Deep Sleep Mode
#define PRCM_O_SECDMACLKGDS 0x00000044
// GPIO Clock Gate For Run Mode
#define PRCM_O_GPIOCLKGR 0x00000048
// GPIO Clock Gate For Sleep Mode
#define PRCM_O_GPIOCLKGS 0x0000004C
// GPIO Clock Gate For Deep Sleep Mode
#define PRCM_O_GPIOCLKGDS 0x00000050
// GPT Clock Gate For Run Mode
#define PRCM_O_GPTCLKGR 0x00000054
// GPT Clock Gate For Sleep Mode
#define PRCM_O_GPTCLKGS 0x00000058
// GPT Clock Gate For Deep Sleep Mode
#define PRCM_O_GPTCLKGDS 0x0000005C
// I2C Clock Gate For Run Mode
#define PRCM_O_I2CCLKGR 0x00000060
// I2C Clock Gate For Sleep Mode
#define PRCM_O_I2CCLKGS 0x00000064
// I2C Clock Gate For Deep Sleep Mode
#define PRCM_O_I2CCLKGDS 0x00000068
// UART Clock Gate For Run Mode
#define PRCM_O_UARTCLKGR 0x0000006C
// UART Clock Gate For Sleep Mode
#define PRCM_O_UARTCLKGS 0x00000070
// UART Clock Gate For Deep Sleep Mode
#define PRCM_O_UARTCLKGDS 0x00000074
// SSI Clock Gate For Run Mode
#define PRCM_O_SSICLKGR 0x00000078
// SSI Clock Gate For Sleep Mode
#define PRCM_O_SSICLKGS 0x0000007C
// SSI Clock Gate For Deep Sleep Mode
#define PRCM_O_SSICLKGDS 0x00000080
// I2S Clock Gate For Run Mode
#define PRCM_O_I2SCLKGR 0x00000084
// I2S Clock Gate For Sleep Mode
#define PRCM_O_I2SCLKGS 0x00000088
// I2S Clock Gate For Deep Sleep Mode
#define PRCM_O_I2SCLKGDS 0x0000008C
// Internal
#define PRCM_O_CPUCLKDIV 0x000000B8
// I2S Clock Control
#define PRCM_O_I2SBCLKSEL 0x000000C8
// GPT Scalar
#define PRCM_O_GPTCLKDIV 0x000000CC
// I2S Clock Control
#define PRCM_O_I2SCLKCTL 0x000000D0
// MCLK Division Ratio
#define PRCM_O_I2SMCLKDIV 0x000000D4
// BCLK Division Ratio
#define PRCM_O_I2SBCLKDIV 0x000000D8
// WCLK Division Ratio
#define PRCM_O_I2SWCLKDIV 0x000000DC
// SW Initiated Resets
#define PRCM_O_SWRESET 0x0000010C
// WARM Reset Control And Status
#define PRCM_O_WARMRESET 0x00000110
// Power Domain Control
#define PRCM_O_PDCTL0 0x0000012C
// RFC Power Domain Control
#define PRCM_O_PDCTL0RFC 0x00000130
// SERIAL Power Domain Control
#define PRCM_O_PDCTL0SERIAL 0x00000134
// PERIPH Power Domain Control
#define PRCM_O_PDCTL0PERIPH 0x00000138
// Power Domain Status
#define PRCM_O_PDSTAT0 0x00000140
// RFC Power Domain Status
#define PRCM_O_PDSTAT0RFC 0x00000144
// SERIAL Power Domain Status
#define PRCM_O_PDSTAT0SERIAL 0x00000148
// PERIPH Power Domain Status
#define PRCM_O_PDSTAT0PERIPH 0x0000014C
// Power Domain Control
#define PRCM_O_PDCTL1 0x0000017C
// CPU Power Domain Control
#define PRCM_O_PDCTL1CPU 0x00000184
// RFC Power Domain Control
#define PRCM_O_PDCTL1RFC 0x00000188
// VIMS Power Domain Control
#define PRCM_O_PDCTL1VIMS 0x0000018C
// Power Domain Status
#define PRCM_O_PDSTAT1 0x00000194
// BUS Power Domain Status
#define PRCM_O_PDSTAT1BUS 0x00000198
// RFC Power Domain Status
#define PRCM_O_PDSTAT1RFC 0x0000019C
// CPU Power Domain Status
#define PRCM_O_PDSTAT1CPU 0x000001A0
// VIMS Power Domain Status
#define PRCM_O_PDSTAT1VIMS 0x000001A4
// Selected RFC Mode
#define PRCM_O_RFCMODESEL 0x000001D0
// Memory Retention Control
#define PRCM_O_RAMRETEN 0x00000224
//*****************************************************************************
//
// Register: PRCM_O_INFRCLKDIVR
//
//*****************************************************************************
// Field: [1:0] RATIO
//
// Division rate for clocks driving modules in the MCU_AON domain when system
// CPU is in run mode. Division ratio affects both infrastructure clock and
// perbusull clock.
// ENUMs:
// DIV32 Divide by 32
// DIV8 Divide by 8
// DIV2 Divide by 2
// DIV1 Divide by 1
#define PRCM_INFRCLKDIVR_RATIO_W 2
#define PRCM_INFRCLKDIVR_RATIO_M 0x00000003
#define PRCM_INFRCLKDIVR_RATIO_S 0
#define PRCM_INFRCLKDIVR_RATIO_DIV32 0x00000003
#define PRCM_INFRCLKDIVR_RATIO_DIV8 0x00000002
#define PRCM_INFRCLKDIVR_RATIO_DIV2 0x00000001
#define PRCM_INFRCLKDIVR_RATIO_DIV1 0x00000000
//*****************************************************************************
//
// Register: PRCM_O_INFRCLKDIVS
//
//*****************************************************************************
// Field: [1:0] RATIO
//
// Division rate for clocks driving modules in the MCU_AON domain when system
// CPU is in sleep mode. Division ratio affects both infrastructure clock and
// perbusull clock.
// ENUMs:
// DIV32 Divide by 32
// DIV8 Divide by 8
// DIV2 Divide by 2
// DIV1 Divide by 1
#define PRCM_INFRCLKDIVS_RATIO_W 2
#define PRCM_INFRCLKDIVS_RATIO_M 0x00000003
#define PRCM_INFRCLKDIVS_RATIO_S 0
#define PRCM_INFRCLKDIVS_RATIO_DIV32 0x00000003
#define PRCM_INFRCLKDIVS_RATIO_DIV8 0x00000002
#define PRCM_INFRCLKDIVS_RATIO_DIV2 0x00000001
#define PRCM_INFRCLKDIVS_RATIO_DIV1 0x00000000
//*****************************************************************************
//
// Register: PRCM_O_INFRCLKDIVDS
//
//*****************************************************************************
// Field: [1:0] RATIO
//
// Division rate for clocks driving modules in the MCU_AON domain when system
// CPU is in seepsleep mode. Division ratio affects both infrastructure clock
// and perbusull clock.
// ENUMs:
// DIV32 Divide by 32
// DIV8 Divide by 8
// DIV2 Divide by 2
// DIV1 Divide by 1
#define PRCM_INFRCLKDIVDS_RATIO_W 2
#define PRCM_INFRCLKDIVDS_RATIO_M 0x00000003
#define PRCM_INFRCLKDIVDS_RATIO_S 0
#define PRCM_INFRCLKDIVDS_RATIO_DIV32 0x00000003
#define PRCM_INFRCLKDIVDS_RATIO_DIV8 0x00000002
#define PRCM_INFRCLKDIVDS_RATIO_DIV2 0x00000001
#define PRCM_INFRCLKDIVDS_RATIO_DIV1 0x00000000
//*****************************************************************************
//
// Register: PRCM_O_VDCTL
//
//*****************************************************************************
// Field: [2] MCU_VD
//
// Request WUC to power down the MCU voltage domain
//
// 0: No request
// 1: Assert request when possible. An asserted power down request will result
// in a boot of the MCU system when powered up again.
//
// The bit will have no effect before the following requirements are met:
// 1. PDCTL1.CPU_ON = 0
// 2. PDCTL1.VIMS_MODE = 0
// 3. SECDMACLKGDS.DMA_CLK_EN = 0 (Note: Setting must be loaded with
// CLKLOADCTL.LOAD)
// 4. SECDMACLKGDS.CRYPTO_CLK_EN = 0 (Note: Setting must be loaded with
// CLKLOADCTL.LOAD)
// 5. RFC do no request access to BUS
// 6. System CPU in deepsleep
#define PRCM_VDCTL_MCU_VD 0x00000004
#define PRCM_VDCTL_MCU_VD_BITN 2
#define PRCM_VDCTL_MCU_VD_M 0x00000004
#define PRCM_VDCTL_MCU_VD_S 2
// Field: [0] ULDO
//
// Request WUC to switch to uLDO.
//
// 0: No request
// 1: Assert request when possible
//
// The bit will have no effect before the following requirements are met:
// 1. PDCTL1.CPU_ON = 0
// 2. PDCTL1.VIMS_MODE = 0
// 3. SECDMACLKGDS.DMA_CLK_EN = 0 (Note: Setting must be loaded with
// CLKLOADCTL.LOAD)
// 4. SECDMACLKGDS.CRYPTO_CLK_EN = 0 (Note: Setting must be loaded with
// CLKLOADCTL.LOAD)
// 5. RFC do no request access to BUS
// 6. System CPU in deepsleep
#define PRCM_VDCTL_ULDO 0x00000001
#define PRCM_VDCTL_ULDO_BITN 0
#define PRCM_VDCTL_ULDO_M 0x00000001
#define PRCM_VDCTL_ULDO_S 0
//*****************************************************************************
//
// Register: PRCM_O_CLKLOADCTL
//
//*****************************************************************************
// Field: [1] LOAD_DONE
//
// Status of LOAD.
// Will be cleared to 0 when any of the registers requiring a LOAD is written
// to, and be set to 1 when a LOAD is done.
// Note that writing no change to a register will result in the LOAD_DONE being
// cleared.
//
// 0 : One or more registers have been write accessed after last LOAD
// 1 : No registers are write accessed after last LOAD
#define PRCM_CLKLOADCTL_LOAD_DONE 0x00000002
#define PRCM_CLKLOADCTL_LOAD_DONE_BITN 1
#define PRCM_CLKLOADCTL_LOAD_DONE_M 0x00000002
#define PRCM_CLKLOADCTL_LOAD_DONE_S 1
// Field: [0] LOAD
//
// 0: No action
// 1: Load settings to CLKCTRL. Bit is HW cleared.
//
// Multiple changes to settings may be done before LOAD is written once so all
// changes takes place at the same time. LOAD can also be done after single
// setting updates.
//
// Registers that needs to be followed by LOAD before settings being applied
// are:
// - RFCCLKG
// - VIMSCLKG
// - SECDMACLKGR
// - SECDMACLKGS
// - SECDMACLKGDS
// - GPIOCLKGR
// - GPIOCLKGS
// - GPIOCLKGDS
// - GPTCLKGR
// - GPTCLKGS
// - GPTCLKGDS
// - GPTCLKDIV
// - I2CCLKGR
// - I2CCLKGS
// - I2CCLKGDS
// - SSICLKGR
// - SSICLKGS
// - SSICLKGDS
// - UARTCLKGR
// - UARTCLKGS
// - UARTCLKGDS
// - I2SCLKGR
// - I2SCLKGS
// - I2SCLKGDS
// - I2SBCLKSEL
// - I2SCLKCTL
// - I2SMCLKDIV
// - I2SBCLKDIV
// - I2SWCLKDIV
#define PRCM_CLKLOADCTL_LOAD 0x00000001
#define PRCM_CLKLOADCTL_LOAD_BITN 0
#define PRCM_CLKLOADCTL_LOAD_M 0x00000001
#define PRCM_CLKLOADCTL_LOAD_S 0
//*****************************************************************************
//
// Register: PRCM_O_RFCCLKG
//
//*****************************************************************************
// Field: [0] CLK_EN
//
//
// 0: Disable clock
// 1: Enable clock if RFC power domain is on
//
// For changes to take effect, CLKLOADCTL.LOAD needs to be written
#define PRCM_RFCCLKG_CLK_EN 0x00000001
#define PRCM_RFCCLKG_CLK_EN_BITN 0
#define PRCM_RFCCLKG_CLK_EN_M 0x00000001
#define PRCM_RFCCLKG_CLK_EN_S 0
//*****************************************************************************
//
// Register: PRCM_O_VIMSCLKG
//
//*****************************************************************************
// Field: [1:0] CLK_EN
//
// 00: Disable clock
// 01: Disable clock when SYSBUS clock is disabled
// 11: Enable clock
//
// For changes to take effect, CLKLOADCTL.LOAD needs to be written
#define PRCM_VIMSCLKG_CLK_EN_W 2
#define PRCM_VIMSCLKG_CLK_EN_M 0x00000003
#define PRCM_VIMSCLKG_CLK_EN_S 0
//*****************************************************************************
//
// Register: PRCM_O_SECDMACLKGR
//
//*****************************************************************************
// Field: [8] DMA_CLK_EN
//
//
// 0: Disable clock
// 1: Enable clock
//
// For changes to take effect, CLKLOADCTL.LOAD needs to be written
#define PRCM_SECDMACLKGR_DMA_CLK_EN 0x00000100
#define PRCM_SECDMACLKGR_DMA_CLK_EN_BITN 8
#define PRCM_SECDMACLKGR_DMA_CLK_EN_M 0x00000100
#define PRCM_SECDMACLKGR_DMA_CLK_EN_S 8
// Field: [1] TRNG_CLK_EN
//
//
// 0: Disable clock
// 1: Enable clock
//
// For changes to take effect, CLKLOADCTL.LOAD needs to be written
#define PRCM_SECDMACLKGR_TRNG_CLK_EN 0x00000002
#define PRCM_SECDMACLKGR_TRNG_CLK_EN_BITN 1
#define PRCM_SECDMACLKGR_TRNG_CLK_EN_M 0x00000002
#define PRCM_SECDMACLKGR_TRNG_CLK_EN_S 1
// Field: [0] CRYPTO_CLK_EN
//
//
// 0: Disable clock
// 1: Enable clock
//
// For changes to take effect, CLKLOADCTL.LOAD needs to be written
#define PRCM_SECDMACLKGR_CRYPTO_CLK_EN 0x00000001
#define PRCM_SECDMACLKGR_CRYPTO_CLK_EN_BITN 0
#define PRCM_SECDMACLKGR_CRYPTO_CLK_EN_M 0x00000001
#define PRCM_SECDMACLKGR_CRYPTO_CLK_EN_S 0
//*****************************************************************************
//
// Register: PRCM_O_SECDMACLKGS
//
//*****************************************************************************
// Field: [8] DMA_CLK_EN
//
//
// 0: Disable clock
// 1: Enable clock
//
// For changes to take effect, CLKLOADCTL.LOAD needs to be written
#define PRCM_SECDMACLKGS_DMA_CLK_EN 0x00000100
#define PRCM_SECDMACLKGS_DMA_CLK_EN_BITN 8
#define PRCM_SECDMACLKGS_DMA_CLK_EN_M 0x00000100
#define PRCM_SECDMACLKGS_DMA_CLK_EN_S 8
// Field: [1] TRNG_CLK_EN
//
//
// 0: Disable clock
// 1: Enable clock
//
// For changes to take effect, CLKLOADCTL.LOAD needs to be written
#define PRCM_SECDMACLKGS_TRNG_CLK_EN 0x00000002
#define PRCM_SECDMACLKGS_TRNG_CLK_EN_BITN 1
#define PRCM_SECDMACLKGS_TRNG_CLK_EN_M 0x00000002
#define PRCM_SECDMACLKGS_TRNG_CLK_EN_S 1
// Field: [0] CRYPTO_CLK_EN
//
//
// 0: Disable clock
// 1: Enable clock
//
// For changes to take effect, CLKLOADCTL.LOAD needs to be written
#define PRCM_SECDMACLKGS_CRYPTO_CLK_EN 0x00000001
#define PRCM_SECDMACLKGS_CRYPTO_CLK_EN_BITN 0
#define PRCM_SECDMACLKGS_CRYPTO_CLK_EN_M 0x00000001
#define PRCM_SECDMACLKGS_CRYPTO_CLK_EN_S 0
//*****************************************************************************
//
// Register: PRCM_O_SECDMACLKGDS
//
//*****************************************************************************
// Field: [8] DMA_CLK_EN
//
//
// 0: Disable clock
// 1: Enable clock
//
// For changes to take effect, CLKLOADCTL.LOAD needs to be written
#define PRCM_SECDMACLKGDS_DMA_CLK_EN 0x00000100
#define PRCM_SECDMACLKGDS_DMA_CLK_EN_BITN 8
#define PRCM_SECDMACLKGDS_DMA_CLK_EN_M 0x00000100
#define PRCM_SECDMACLKGDS_DMA_CLK_EN_S 8
// Field: [1] TRNG_CLK_EN
//
//
// 0: Disable clock
// 1: Enable clock
//
// For changes to take effect, CLKLOADCTL.LOAD needs to be written
#define PRCM_SECDMACLKGDS_TRNG_CLK_EN 0x00000002
#define PRCM_SECDMACLKGDS_TRNG_CLK_EN_BITN 1
#define PRCM_SECDMACLKGDS_TRNG_CLK_EN_M 0x00000002
#define PRCM_SECDMACLKGDS_TRNG_CLK_EN_S 1
// Field: [0] CRYPTO_CLK_EN
//
//
// 0: Disable clock
// 1: Enable clock
//
// For changes to take effect, CLKLOADCTL.LOAD needs to be written
#define PRCM_SECDMACLKGDS_CRYPTO_CLK_EN 0x00000001
#define PRCM_SECDMACLKGDS_CRYPTO_CLK_EN_BITN 0
#define PRCM_SECDMACLKGDS_CRYPTO_CLK_EN_M 0x00000001
#define PRCM_SECDMACLKGDS_CRYPTO_CLK_EN_S 0
//*****************************************************************************
//
// Register: PRCM_O_GPIOCLKGR
//
//*****************************************************************************
// Field: [0] CLK_EN
//
//
// 0: Disable clock
// 1: Enable clock
//
// For changes to take effect, CLKLOADCTL.LOAD needs to be written
#define PRCM_GPIOCLKGR_CLK_EN 0x00000001
#define PRCM_GPIOCLKGR_CLK_EN_BITN 0
#define PRCM_GPIOCLKGR_CLK_EN_M 0x00000001
#define PRCM_GPIOCLKGR_CLK_EN_S 0
//*****************************************************************************
//
// Register: PRCM_O_GPIOCLKGS
//
//*****************************************************************************
// Field: [0] CLK_EN
//
//
// 0: Disable clock
// 1: Enable clock
//
// For changes to take effect, CLKLOADCTL.LOAD needs to be written
#define PRCM_GPIOCLKGS_CLK_EN 0x00000001
#define PRCM_GPIOCLKGS_CLK_EN_BITN 0
#define PRCM_GPIOCLKGS_CLK_EN_M 0x00000001
#define PRCM_GPIOCLKGS_CLK_EN_S 0
//*****************************************************************************
//
// Register: PRCM_O_GPIOCLKGDS
//
//*****************************************************************************
// Field: [0] CLK_EN
//
//
// 0: Disable clock
// 1: Enable clock
//
// For changes to take effect, CLKLOADCTL.LOAD needs to be written
#define PRCM_GPIOCLKGDS_CLK_EN 0x00000001
#define PRCM_GPIOCLKGDS_CLK_EN_BITN 0
#define PRCM_GPIOCLKGDS_CLK_EN_M 0x00000001
#define PRCM_GPIOCLKGDS_CLK_EN_S 0
//*****************************************************************************
//
// Register: PRCM_O_GPTCLKGR
//
//*****************************************************************************
// Field: [3:0] CLK_EN
//
// Each bit below has the following meaning:
//
// 0: Disable clock
// 1: Enable clock
//
// ENUMs can be combined
// For changes to take effect, CLKLOADCTL.LOAD needs to be written
// ENUMs:
// GPT3 Enable clock for GPT3
// GPT2 Enable clock for GPT2
// GPT1 Enable clock for GPT1
// GPT0 Enable clock for GPT0
#define PRCM_GPTCLKGR_CLK_EN_W 4
#define PRCM_GPTCLKGR_CLK_EN_M 0x0000000F
#define PRCM_GPTCLKGR_CLK_EN_S 0
#define PRCM_GPTCLKGR_CLK_EN_GPT3 0x00000008
#define PRCM_GPTCLKGR_CLK_EN_GPT2 0x00000004
#define PRCM_GPTCLKGR_CLK_EN_GPT1 0x00000002
#define PRCM_GPTCLKGR_CLK_EN_GPT0 0x00000001
//*****************************************************************************
//
// Register: PRCM_O_GPTCLKGS
//
//*****************************************************************************
// Field: [3:0] CLK_EN
//
// Each bit below has the following meaning:
//
// 0: Disable clock
// 1: Enable clock
//
// ENUMs can be combined
// For changes to take effect, CLKLOADCTL.LOAD needs to be written
// ENUMs:
// GPT3 Enable clock for GPT3
// GPT2 Enable clock for GPT2
// GPT1 Enable clock for GPT1
// GPT0 Enable clock for GPT0
#define PRCM_GPTCLKGS_CLK_EN_W 4
#define PRCM_GPTCLKGS_CLK_EN_M 0x0000000F
#define PRCM_GPTCLKGS_CLK_EN_S 0
#define PRCM_GPTCLKGS_CLK_EN_GPT3 0x00000008
#define PRCM_GPTCLKGS_CLK_EN_GPT2 0x00000004
#define PRCM_GPTCLKGS_CLK_EN_GPT1 0x00000002
#define PRCM_GPTCLKGS_CLK_EN_GPT0 0x00000001
//*****************************************************************************
//
// Register: PRCM_O_GPTCLKGDS
//
//*****************************************************************************
// Field: [3:0] CLK_EN
//
// Each bit below has the following meaning:
//
// 0: Disable clock
// 1: Enable clock
//
// ENUMs can be combined
// For changes to take effect, CLKLOADCTL.LOAD needs to be written
// ENUMs:
// GPT3 Enable clock for GPT3
// GPT2 Enable clock for GPT2
// GPT1 Enable clock for GPT1
// GPT0 Enable clock for GPT0
#define PRCM_GPTCLKGDS_CLK_EN_W 4
#define PRCM_GPTCLKGDS_CLK_EN_M 0x0000000F
#define PRCM_GPTCLKGDS_CLK_EN_S 0
#define PRCM_GPTCLKGDS_CLK_EN_GPT3 0x00000008
#define PRCM_GPTCLKGDS_CLK_EN_GPT2 0x00000004
#define PRCM_GPTCLKGDS_CLK_EN_GPT1 0x00000002
#define PRCM_GPTCLKGDS_CLK_EN_GPT0 0x00000001
//*****************************************************************************
//
// Register: PRCM_O_I2CCLKGR
//
//*****************************************************************************
// Field: [0] CLK_EN
//
//
// 0: Disable clock
// 1: Enable clock
//
// For changes to take effect, CLKLOADCTL.LOAD needs to be written
#define PRCM_I2CCLKGR_CLK_EN 0x00000001
#define PRCM_I2CCLKGR_CLK_EN_BITN 0
#define PRCM_I2CCLKGR_CLK_EN_M 0x00000001
#define PRCM_I2CCLKGR_CLK_EN_S 0
//*****************************************************************************
//
// Register: PRCM_O_I2CCLKGS
//
//*****************************************************************************
// Field: [0] CLK_EN
//
//
// 0: Disable clock
// 1: Enable clock
//
// For changes to take effect, CLKLOADCTL.LOAD needs to be written
#define PRCM_I2CCLKGS_CLK_EN 0x00000001
#define PRCM_I2CCLKGS_CLK_EN_BITN 0
#define PRCM_I2CCLKGS_CLK_EN_M 0x00000001
#define PRCM_I2CCLKGS_CLK_EN_S 0
//*****************************************************************************
//
// Register: PRCM_O_I2CCLKGDS
//
//*****************************************************************************
// Field: [0] CLK_EN
//
//
// 0: Disable clock
// 1: Enable clock
//
// For changes to take effect, CLKLOADCTL.LOAD needs to be written
#define PRCM_I2CCLKGDS_CLK_EN 0x00000001
#define PRCM_I2CCLKGDS_CLK_EN_BITN 0
#define PRCM_I2CCLKGDS_CLK_EN_M 0x00000001
#define PRCM_I2CCLKGDS_CLK_EN_S 0
//*****************************************************************************
//
// Register: PRCM_O_UARTCLKGR
//
//*****************************************************************************
// Field: [0] CLK_EN
//
//
// 0: Disable clock
// 1: Enable clock
//
// For changes to take effect, CLKLOADCTL.LOAD needs to be written
#define PRCM_UARTCLKGR_CLK_EN 0x00000001
#define PRCM_UARTCLKGR_CLK_EN_BITN 0
#define PRCM_UARTCLKGR_CLK_EN_M 0x00000001
#define PRCM_UARTCLKGR_CLK_EN_S 0
//*****************************************************************************
//
// Register: PRCM_O_UARTCLKGS
//
//*****************************************************************************
// Field: [0] CLK_EN
//
//
// 0: Disable clock
// 1: Enable clock
//
// For changes to take effect, CLKLOADCTL.LOAD needs to be written
#define PRCM_UARTCLKGS_CLK_EN 0x00000001
#define PRCM_UARTCLKGS_CLK_EN_BITN 0
#define PRCM_UARTCLKGS_CLK_EN_M 0x00000001
#define PRCM_UARTCLKGS_CLK_EN_S 0
//*****************************************************************************
//
// Register: PRCM_O_UARTCLKGDS
//
//*****************************************************************************
// Field: [0] CLK_EN
//
//
// 0: Disable clock
// 1: Enable clock
//
// For changes to take effect, CLKLOADCTL.LOAD needs to be written
#define PRCM_UARTCLKGDS_CLK_EN 0x00000001
#define PRCM_UARTCLKGDS_CLK_EN_BITN 0
#define PRCM_UARTCLKGDS_CLK_EN_M 0x00000001
#define PRCM_UARTCLKGDS_CLK_EN_S 0
//*****************************************************************************
//
// Register: PRCM_O_SSICLKGR
//
//*****************************************************************************
// Field: [1:0] CLK_EN
//
//
// 0: Disable clock
// 1: Enable clock
//
// For changes to take effect, CLKLOADCTL.LOAD needs to be written
// ENUMs:
// SSI1 Enable clock for SSI1
// SSI0 Enable clock for SSI0
#define PRCM_SSICLKGR_CLK_EN_W 2
#define PRCM_SSICLKGR_CLK_EN_M 0x00000003
#define PRCM_SSICLKGR_CLK_EN_S 0
#define PRCM_SSICLKGR_CLK_EN_SSI1 0x00000002
#define PRCM_SSICLKGR_CLK_EN_SSI0 0x00000001
//*****************************************************************************
//
// Register: PRCM_O_SSICLKGS
//
//*****************************************************************************
// Field: [1:0] CLK_EN
//
//
// 0: Disable clock
// 1: Enable clock
//
// For changes to take effect, CLKLOADCTL.LOAD needs to be written
// ENUMs:
// SSI1 Enable clock for SSI1
// SSI0 Enable clock for SSI0
#define PRCM_SSICLKGS_CLK_EN_W 2
#define PRCM_SSICLKGS_CLK_EN_M 0x00000003
#define PRCM_SSICLKGS_CLK_EN_S 0
#define PRCM_SSICLKGS_CLK_EN_SSI1 0x00000002
#define PRCM_SSICLKGS_CLK_EN_SSI0 0x00000001
//*****************************************************************************
//
// Register: PRCM_O_SSICLKGDS
//
//*****************************************************************************
// Field: [1:0] CLK_EN
//
//
// 0: Disable clock
// 1: Enable clock
//
// For changes to take effect, CLKLOADCTL.LOAD needs to be written
// ENUMs:
// SSI1 Enable clock for SSI1
// SSI0 Enable clock for SSI0
#define PRCM_SSICLKGDS_CLK_EN_W 2
#define PRCM_SSICLKGDS_CLK_EN_M 0x00000003
#define PRCM_SSICLKGDS_CLK_EN_S 0
#define PRCM_SSICLKGDS_CLK_EN_SSI1 0x00000002
#define PRCM_SSICLKGDS_CLK_EN_SSI0 0x00000001
//*****************************************************************************
//
// Register: PRCM_O_I2SCLKGR
//
//*****************************************************************************
// Field: [0] CLK_EN
//
//
// 0: Disable clock
// 1: Enable clock
//
// For changes to take effect, CLKLOADCTL.LOAD needs to be written
#define PRCM_I2SCLKGR_CLK_EN 0x00000001
#define PRCM_I2SCLKGR_CLK_EN_BITN 0
#define PRCM_I2SCLKGR_CLK_EN_M 0x00000001
#define PRCM_I2SCLKGR_CLK_EN_S 0
//*****************************************************************************
//
// Register: PRCM_O_I2SCLKGS
//
//*****************************************************************************
// Field: [0] CLK_EN
//
//
// 0: Disable clock
// 1: Enable clock
//
// For changes to take effect, CLKLOADCTL.LOAD needs to be written
#define PRCM_I2SCLKGS_CLK_EN 0x00000001
#define PRCM_I2SCLKGS_CLK_EN_BITN 0
#define PRCM_I2SCLKGS_CLK_EN_M 0x00000001
#define PRCM_I2SCLKGS_CLK_EN_S 0
//*****************************************************************************
//
// Register: PRCM_O_I2SCLKGDS
//
//*****************************************************************************
// Field: [0] CLK_EN
//
//
// 0: Disable clock
// 1: Enable clock
//
// For changes to take effect, CLKLOADCTL.LOAD needs to be written
#define PRCM_I2SCLKGDS_CLK_EN 0x00000001
#define PRCM_I2SCLKGDS_CLK_EN_BITN 0
#define PRCM_I2SCLKGDS_CLK_EN_M 0x00000001
#define PRCM_I2SCLKGDS_CLK_EN_S 0
//*****************************************************************************
//
// Register: PRCM_O_CPUCLKDIV
//
//*****************************************************************************
// Field: [0] RATIO
//
// Internal. Only to be used through TI provided API.
// ENUMs:
// DIV2 Internal. Only to be used through TI provided API.
// DIV1 Internal. Only to be used through TI provided API.
#define PRCM_CPUCLKDIV_RATIO 0x00000001
#define PRCM_CPUCLKDIV_RATIO_BITN 0
#define PRCM_CPUCLKDIV_RATIO_M 0x00000001
#define PRCM_CPUCLKDIV_RATIO_S 0
#define PRCM_CPUCLKDIV_RATIO_DIV2 0x00000001
#define PRCM_CPUCLKDIV_RATIO_DIV1 0x00000000
//*****************************************************************************
//
// Register: PRCM_O_I2SBCLKSEL
//
//*****************************************************************************
// Field: [0] SRC
//
// BCLK source selector
//
// 0: Use external BCLK
// 1: Use internally generated clock
//
// For changes to take effect, CLKLOADCTL.LOAD needs to be written
#define PRCM_I2SBCLKSEL_SRC 0x00000001
#define PRCM_I2SBCLKSEL_SRC_BITN 0
#define PRCM_I2SBCLKSEL_SRC_M 0x00000001
#define PRCM_I2SBCLKSEL_SRC_S 0
//*****************************************************************************
//
// Register: PRCM_O_GPTCLKDIV
//
//*****************************************************************************
// Field: [3:0] RATIO
//
// Scalar used for GPTs. The division rate will be constant and ungated for Run
// / Sleep / DeepSleep mode.
//
// For changes to take effect, CLKLOADCTL.LOAD needs to be written
// Other values are not supported.
// ENUMs:
// DIV256 Divide by 256
// DIV128 Divide by 128
// DIV64 Divide by 64
// DIV32 Divide by 32
// DIV16 Divide by 16
// DIV8 Divide by 8
// DIV4 Divide by 4
// DIV2 Divide by 2
// DIV1 Divide by 1
#define PRCM_GPTCLKDIV_RATIO_W 4
#define PRCM_GPTCLKDIV_RATIO_M 0x0000000F
#define PRCM_GPTCLKDIV_RATIO_S 0
#define PRCM_GPTCLKDIV_RATIO_DIV256 0x00000008
#define PRCM_GPTCLKDIV_RATIO_DIV128 0x00000007
#define PRCM_GPTCLKDIV_RATIO_DIV64 0x00000006
#define PRCM_GPTCLKDIV_RATIO_DIV32 0x00000005
#define PRCM_GPTCLKDIV_RATIO_DIV16 0x00000004
#define PRCM_GPTCLKDIV_RATIO_DIV8 0x00000003
#define PRCM_GPTCLKDIV_RATIO_DIV4 0x00000002
#define PRCM_GPTCLKDIV_RATIO_DIV2 0x00000001
#define PRCM_GPTCLKDIV_RATIO_DIV1 0x00000000
//*****************************************************************************
//
// Register: PRCM_O_I2SCLKCTL
//
//*****************************************************************************
// Field: [3] SMPL_ON_POSEDGE
//
// On the I2S serial interface, data and WCLK is sampled and clocked out on
// opposite edges of BCLK.
//
// 0 - data and WCLK are sampled on the negative edge and clocked out on the
// positive edge.
// 1 - data and WCLK are sampled on the positive edge and clocked out on the
// negative edge.
//
// For changes to take effect, CLKLOADCTL.LOAD needs to be written
#define PRCM_I2SCLKCTL_SMPL_ON_POSEDGE 0x00000008
#define PRCM_I2SCLKCTL_SMPL_ON_POSEDGE_BITN 3
#define PRCM_I2SCLKCTL_SMPL_ON_POSEDGE_M 0x00000008
#define PRCM_I2SCLKCTL_SMPL_ON_POSEDGE_S 3
// Field: [2:1] WCLK_PHASE
//
// Decides how the WCLK division ratio is calculated and used to generate
// different duty cycles (See I2SWCLKDIV.WDIV).
//
// 0: Single phase
// 1: Dual phase
// 2: User Defined
// 3: Reserved/Undefined
//
// For changes to take effect, CLKLOADCTL.LOAD needs to be written
#define PRCM_I2SCLKCTL_WCLK_PHASE_W 2
#define PRCM_I2SCLKCTL_WCLK_PHASE_M 0x00000006
#define PRCM_I2SCLKCTL_WCLK_PHASE_S 1
// Field: [0] EN
//
//
// 0: MCLK, BCLK and **WCLK** will be static low
// 1: Enables the generation of MCLK, BCLK and WCLK
//
// For changes to take effect, CLKLOADCTL.LOAD needs to be written
#define PRCM_I2SCLKCTL_EN 0x00000001
#define PRCM_I2SCLKCTL_EN_BITN 0
#define PRCM_I2SCLKCTL_EN_M 0x00000001
#define PRCM_I2SCLKCTL_EN_S 0
//*****************************************************************************
//
// Register: PRCM_O_I2SMCLKDIV
//
//*****************************************************************************
// Field: [9:0] MDIV
//
// An unsigned factor of the division ratio used to generate MCLK [2-1024]:
//
// MCLK = MCUCLK/MDIV[Hz]
// MCUCLK is 48MHz in normal mode. For powerdown mode the frequency is defined
// by AON_WUC:MCUCLK.PWR_DWN_SRC
//
// A value of 0 is interpreted as 1024.
// A value of 1 is invalid.
// If MDIV is odd the low phase of the clock is one MCUCLK period longer than
// the high phase.
//
// For changes to take effect, CLKLOADCTL.LOAD needs to be written
#define PRCM_I2SMCLKDIV_MDIV_W 10
#define PRCM_I2SMCLKDIV_MDIV_M 0x000003FF
#define PRCM_I2SMCLKDIV_MDIV_S 0
//*****************************************************************************
//
// Register: PRCM_O_I2SBCLKDIV
//
//*****************************************************************************
// Field: [9:0] BDIV
//
// An unsigned factor of the division ratio used to generate I2S BCLK [2-1024]:
//
// BCLK = MCUCLK/BDIV[Hz]
// MCUCLK is 48MHz in normal mode. For powerdown mode the frequency is defined
// by AON_WUC:MCUCLK.PWR_DWN_SRC
//
// A value of 0 is interpreted as 1024.
// A value of 1 is invalid.
// If BDIV is odd and I2SCLKCTL.SMPL_ON_POSEDGE = 0, the low phase of the clock
// is one MCUCLK period longer than the high phase.
// If BDIV is odd and I2SCLKCTL.SMPL_ON_POSEDGE = 1 , the high phase of the
// clock is one MCUCLK period longer than the low phase.
//
// For changes to take effect, CLKLOADCTL.LOAD needs to be written
#define PRCM_I2SBCLKDIV_BDIV_W 10
#define PRCM_I2SBCLKDIV_BDIV_M 0x000003FF
#define PRCM_I2SBCLKDIV_BDIV_S 0
//*****************************************************************************
//
// Register: PRCM_O_I2SWCLKDIV
//
//*****************************************************************************
// Field: [15:0] WDIV
//
// If I2SCLKCTL.WCLK_PHASE = 0, Single phase.
// WCLK is high one BCLK period and low WDIV[9:0] (unsigned, [1-1023]) BCLK
// periods.
//
// WCLK = MCUCLK / BDIV*(WDIV[9:0] + 1) [Hz]
// MCUCLK is 48MHz in normal mode. For powerdown mode the frequency is defined
// by AON_WUC:MCUCLK.PWR_DWN_SRC
//
// If I2SCLKCTL.WCLK_PHASE = 1, Dual phase.
// Each phase on WCLK (50% duty cycle) is WDIV[9:0] (unsigned, [1-1023]) BCLK
// periods.
//
// WCLK = MCUCLK / BDIV*(2*WDIV[9:0]) [Hz]
//
// If I2SCLKCTL.WCLK_PHASE = 2, User defined.
// WCLK is high WDIV[7:0] (unsigned, [1-255]) BCLK periods and low WDIV[15:8]
// (unsigned, [1-255]) BCLK periods.
//
// WCLK = MCUCLK / (BDIV*(WDIV[7:0] + WDIV[15:8]) [Hz]
//
// For changes to take effect, CLKLOADCTL.LOAD needs to be written
#define PRCM_I2SWCLKDIV_WDIV_W 16
#define PRCM_I2SWCLKDIV_WDIV_M 0x0000FFFF
#define PRCM_I2SWCLKDIV_WDIV_S 0
//*****************************************************************************
//
// Register: PRCM_O_SWRESET
//
//*****************************************************************************
// Field: [2] MCU
//
// Internal. Only to be used through TI provided API.
#define PRCM_SWRESET_MCU 0x00000004
#define PRCM_SWRESET_MCU_BITN 2
#define PRCM_SWRESET_MCU_M 0x00000004
#define PRCM_SWRESET_MCU_S 2
//*****************************************************************************
//
// Register: PRCM_O_WARMRESET
//
//*****************************************************************************
// Field: [2] WR_TO_PINRESET
//
// 0: No action
// 1: A warm system reset event triggered by the below listed sources will
// result in an emulated pin reset.
//
// Warm reset sources included:
// ICEPick sysreset
// System CPU reset request, CPU_SCS:AIRCR.SYSRESETREQ
// System CPU Lockup
// WDT timeout
//
// An active ICEPick block system reset will gate all sources except ICEPick
// sysreset
//
// SW can read AON_SYSCTL:RESETCTL.RESET_SRC to find the source of the last
// reset resulting in a full power up sequence. WARMRESET in this register is
// set in the scenario that WR_TO_PINRESET=1 and one of the above listed
// sources is triggered.
#define PRCM_WARMRESET_WR_TO_PINRESET 0x00000004
#define PRCM_WARMRESET_WR_TO_PINRESET_BITN 2
#define PRCM_WARMRESET_WR_TO_PINRESET_M 0x00000004
#define PRCM_WARMRESET_WR_TO_PINRESET_S 2
// Field: [1] LOCKUP_STAT
//
//
// 0: No registred event
// 1: A system CPU LOCKUP event has occured since last SW clear of the
// register.
//
// A read of this register clears both WDT_STAT and LOCKUP_STAT.
#define PRCM_WARMRESET_LOCKUP_STAT 0x00000002
#define PRCM_WARMRESET_LOCKUP_STAT_BITN 1
#define PRCM_WARMRESET_LOCKUP_STAT_M 0x00000002
#define PRCM_WARMRESET_LOCKUP_STAT_S 1
// Field: [0] WDT_STAT
//
//
// 0: No registered event
// 1: A WDT event has occured since last SW clear of the register.
//
// A read of this register clears both WDT_STAT and LOCKUP_STAT.
#define PRCM_WARMRESET_WDT_STAT 0x00000001
#define PRCM_WARMRESET_WDT_STAT_BITN 0
#define PRCM_WARMRESET_WDT_STAT_M 0x00000001
#define PRCM_WARMRESET_WDT_STAT_S 0
//*****************************************************************************
//
// Register: PRCM_O_PDCTL0
//
//*****************************************************************************
// Field: [2] PERIPH_ON
//
// PERIPH Power domain.
//
// 0: PERIPH power domain is powered down
// 1: PERIPH power domain is powered up
#define PRCM_PDCTL0_PERIPH_ON 0x00000004
#define PRCM_PDCTL0_PERIPH_ON_BITN 2
#define PRCM_PDCTL0_PERIPH_ON_M 0x00000004
#define PRCM_PDCTL0_PERIPH_ON_S 2
// Field: [1] SERIAL_ON
//
// SERIAL Power domain.
//
// 0: SERIAL power domain is powered down
// 1: SERIAL power domain is powered up
#define PRCM_PDCTL0_SERIAL_ON 0x00000002
#define PRCM_PDCTL0_SERIAL_ON_BITN 1
#define PRCM_PDCTL0_SERIAL_ON_M 0x00000002
#define PRCM_PDCTL0_SERIAL_ON_S 1
// Field: [0] RFC_ON
//
//
// 0: RFC power domain powered off if also PDCTL1.RFC_ON = 0
// 1: RFC power domain powered on
#define PRCM_PDCTL0_RFC_ON 0x00000001
#define PRCM_PDCTL0_RFC_ON_BITN 0
#define PRCM_PDCTL0_RFC_ON_M 0x00000001
#define PRCM_PDCTL0_RFC_ON_S 0
//*****************************************************************************
//
// Register: PRCM_O_PDCTL0RFC
//
//*****************************************************************************
// Field: [0] ON
//
// Alias for PDCTL0.RFC_ON
#define PRCM_PDCTL0RFC_ON 0x00000001
#define PRCM_PDCTL0RFC_ON_BITN 0
#define PRCM_PDCTL0RFC_ON_M 0x00000001
#define PRCM_PDCTL0RFC_ON_S 0
//*****************************************************************************
//
// Register: PRCM_O_PDCTL0SERIAL
//
//*****************************************************************************
// Field: [0] ON
//
// Alias for PDCTL0.SERIAL_ON
#define PRCM_PDCTL0SERIAL_ON 0x00000001
#define PRCM_PDCTL0SERIAL_ON_BITN 0
#define PRCM_PDCTL0SERIAL_ON_M 0x00000001
#define PRCM_PDCTL0SERIAL_ON_S 0
//*****************************************************************************
//
// Register: PRCM_O_PDCTL0PERIPH
//
//*****************************************************************************
// Field: [0] ON
//
// Alias for PDCTL0.PERIPH_ON
#define PRCM_PDCTL0PERIPH_ON 0x00000001
#define PRCM_PDCTL0PERIPH_ON_BITN 0
#define PRCM_PDCTL0PERIPH_ON_M 0x00000001
#define PRCM_PDCTL0PERIPH_ON_S 0
//*****************************************************************************
//
// Register: PRCM_O_PDSTAT0
//
//*****************************************************************************
// Field: [2] PERIPH_ON
//
// PERIPH Power domain.
//
// 0: Domain may be powered down
// 1: Domain powered up (guaranteed)
#define PRCM_PDSTAT0_PERIPH_ON 0x00000004
#define PRCM_PDSTAT0_PERIPH_ON_BITN 2
#define PRCM_PDSTAT0_PERIPH_ON_M 0x00000004
#define PRCM_PDSTAT0_PERIPH_ON_S 2
// Field: [1] SERIAL_ON
//
// SERIAL Power domain.
//
// 0: Domain may be powered down
// 1: Domain powered up (guaranteed)
#define PRCM_PDSTAT0_SERIAL_ON 0x00000002
#define PRCM_PDSTAT0_SERIAL_ON_BITN 1
#define PRCM_PDSTAT0_SERIAL_ON_M 0x00000002
#define PRCM_PDSTAT0_SERIAL_ON_S 1
// Field: [0] RFC_ON
//
// RFC Power domain
//
// 0: Domain may be powered down
// 1: Domain powered up (guaranteed)
#define PRCM_PDSTAT0_RFC_ON 0x00000001
#define PRCM_PDSTAT0_RFC_ON_BITN 0
#define PRCM_PDSTAT0_RFC_ON_M 0x00000001
#define PRCM_PDSTAT0_RFC_ON_S 0
//*****************************************************************************
//
// Register: PRCM_O_PDSTAT0RFC
//
//*****************************************************************************
// Field: [0] ON
//
// Alias for PDSTAT0.RFC_ON
#define PRCM_PDSTAT0RFC_ON 0x00000001
#define PRCM_PDSTAT0RFC_ON_BITN 0
#define PRCM_PDSTAT0RFC_ON_M 0x00000001
#define PRCM_PDSTAT0RFC_ON_S 0
//*****************************************************************************
//
// Register: PRCM_O_PDSTAT0SERIAL
//
//*****************************************************************************
// Field: [0] ON
//
// Alias for PDSTAT0.SERIAL_ON
#define PRCM_PDSTAT0SERIAL_ON 0x00000001
#define PRCM_PDSTAT0SERIAL_ON_BITN 0
#define PRCM_PDSTAT0SERIAL_ON_M 0x00000001
#define PRCM_PDSTAT0SERIAL_ON_S 0
//*****************************************************************************
//
// Register: PRCM_O_PDSTAT0PERIPH
//
//*****************************************************************************
// Field: [0] ON
//
// Alias for PDSTAT0.PERIPH_ON
#define PRCM_PDSTAT0PERIPH_ON 0x00000001
#define PRCM_PDSTAT0PERIPH_ON_BITN 0
#define PRCM_PDSTAT0PERIPH_ON_M 0x00000001
#define PRCM_PDSTAT0PERIPH_ON_S 0
//*****************************************************************************
//
// Register: PRCM_O_PDCTL1
//
//*****************************************************************************
// Field: [3] VIMS_MODE
//
//
// 0: VIMS power domain is only powered when CPU power domain is powered.
// 1: VIMS power domain is powered whenever the BUS power domain is powered.
#define PRCM_PDCTL1_VIMS_MODE 0x00000008
#define PRCM_PDCTL1_VIMS_MODE_BITN 3
#define PRCM_PDCTL1_VIMS_MODE_M 0x00000008
#define PRCM_PDCTL1_VIMS_MODE_S 3
// Field: [2] RFC_ON
//
//
// 0: RFC power domain powered off if also PDCTL0.RFC_ON = 0
// 1: RFC power domain powered on
//
// Bit shall be used by RFC in autonomus mode but there is no HW restrictions
// fom system CPU to access the bit.
#define PRCM_PDCTL1_RFC_ON 0x00000004
#define PRCM_PDCTL1_RFC_ON_BITN 2
#define PRCM_PDCTL1_RFC_ON_M 0x00000004
#define PRCM_PDCTL1_RFC_ON_S 2
// Field: [1] CPU_ON
//
//
// 0: Causes a power down of the CPU power domain when system CPU indicates it
// is idle.
// 1: Initiates power-on of the CPU power domain.
//
// This bit is automatically set by a WIC power-on event.
#define PRCM_PDCTL1_CPU_ON 0x00000002
#define PRCM_PDCTL1_CPU_ON_BITN 1
#define PRCM_PDCTL1_CPU_ON_M 0x00000002
#define PRCM_PDCTL1_CPU_ON_S 1
//*****************************************************************************
//
// Register: PRCM_O_PDCTL1CPU
//
//*****************************************************************************
// Field: [0] ON
//
// This is an alias for PDCTL1.CPU_ON
#define PRCM_PDCTL1CPU_ON 0x00000001
#define PRCM_PDCTL1CPU_ON_BITN 0
#define PRCM_PDCTL1CPU_ON_M 0x00000001
#define PRCM_PDCTL1CPU_ON_S 0
//*****************************************************************************
//
// Register: PRCM_O_PDCTL1RFC
//
//*****************************************************************************
// Field: [0] ON
//
// This is an alias for PDCTL1.RFC_ON
#define PRCM_PDCTL1RFC_ON 0x00000001
#define PRCM_PDCTL1RFC_ON_BITN 0
#define PRCM_PDCTL1RFC_ON_M 0x00000001
#define PRCM_PDCTL1RFC_ON_S 0
//*****************************************************************************
//
// Register: PRCM_O_PDCTL1VIMS
//
//*****************************************************************************
// Field: [0] ON
//
// This is an alias for PDCTL1.VIMS_MODE
#define PRCM_PDCTL1VIMS_ON 0x00000001
#define PRCM_PDCTL1VIMS_ON_BITN 0
#define PRCM_PDCTL1VIMS_ON_M 0x00000001
#define PRCM_PDCTL1VIMS_ON_S 0
//*****************************************************************************
//
// Register: PRCM_O_PDSTAT1
//
//*****************************************************************************
// Field: [4] BUS_ON
//
//
// 0: BUS domain not accessible
// 1: BUS domain is currently accessible
#define PRCM_PDSTAT1_BUS_ON 0x00000010
#define PRCM_PDSTAT1_BUS_ON_BITN 4
#define PRCM_PDSTAT1_BUS_ON_M 0x00000010
#define PRCM_PDSTAT1_BUS_ON_S 4
// Field: [3] VIMS_MODE
//
//
// 0: VIMS domain not accessible
// 1: VIMS domain is currently accessible
#define PRCM_PDSTAT1_VIMS_MODE 0x00000008
#define PRCM_PDSTAT1_VIMS_MODE_BITN 3
#define PRCM_PDSTAT1_VIMS_MODE_M 0x00000008
#define PRCM_PDSTAT1_VIMS_MODE_S 3
// Field: [2] RFC_ON
//
//
// 0: RFC domain not accessible
// 1: RFC domain is currently accessible
#define PRCM_PDSTAT1_RFC_ON 0x00000004
#define PRCM_PDSTAT1_RFC_ON_BITN 2
#define PRCM_PDSTAT1_RFC_ON_M 0x00000004
#define PRCM_PDSTAT1_RFC_ON_S 2
// Field: [1] CPU_ON
//
//
// 0: CPU and BUS domain not accessible
// 1: CPU and BUS domains are both currently accessible
#define PRCM_PDSTAT1_CPU_ON 0x00000002
#define PRCM_PDSTAT1_CPU_ON_BITN 1
#define PRCM_PDSTAT1_CPU_ON_M 0x00000002
#define PRCM_PDSTAT1_CPU_ON_S 1
//*****************************************************************************
//
// Register: PRCM_O_PDSTAT1BUS
//
//*****************************************************************************
// Field: [0] ON
//
// This is an alias for PDSTAT1.BUS_ON
#define PRCM_PDSTAT1BUS_ON 0x00000001
#define PRCM_PDSTAT1BUS_ON_BITN 0
#define PRCM_PDSTAT1BUS_ON_M 0x00000001
#define PRCM_PDSTAT1BUS_ON_S 0
//*****************************************************************************
//
// Register: PRCM_O_PDSTAT1RFC
//
//*****************************************************************************
// Field: [0] ON
//
// This is an alias for PDSTAT1.RFC_ON
#define PRCM_PDSTAT1RFC_ON 0x00000001
#define PRCM_PDSTAT1RFC_ON_BITN 0
#define PRCM_PDSTAT1RFC_ON_M 0x00000001
#define PRCM_PDSTAT1RFC_ON_S 0
//*****************************************************************************
//
// Register: PRCM_O_PDSTAT1CPU
//
//*****************************************************************************
// Field: [0] ON
//
// This is an alias for PDSTAT1.CPU_ON
#define PRCM_PDSTAT1CPU_ON 0x00000001
#define PRCM_PDSTAT1CPU_ON_BITN 0
#define PRCM_PDSTAT1CPU_ON_M 0x00000001
#define PRCM_PDSTAT1CPU_ON_S 0
//*****************************************************************************
//
// Register: PRCM_O_PDSTAT1VIMS
//
//*****************************************************************************
// Field: [0] ON
//
// This is an alias for PDSTAT1.VIMS_MODE
#define PRCM_PDSTAT1VIMS_ON 0x00000001
#define PRCM_PDSTAT1VIMS_ON_BITN 0
#define PRCM_PDSTAT1VIMS_ON_M 0x00000001
#define PRCM_PDSTAT1VIMS_ON_S 0
//*****************************************************************************
//
// Register: PRCM_O_RFCMODESEL
//
//*****************************************************************************
// Field: [2:0] CURR
//
// Written by MCU - Outputs to RFC. Only modes permitted by RFCMODEHWOPT.AVAIL
// are writeable.
// ENUMs:
// MODE7 Select Mode 7
// MODE6 Select Mode 6
// MODE5 Select Mode 5
// MODE4 Select Mode 4
// MODE3 Select Mode 3
// MODE2 Select Mode 2
// MODE1 Select Mode 1
// MODE0 Select Mode 0
#define PRCM_RFCMODESEL_CURR_W 3
#define PRCM_RFCMODESEL_CURR_M 0x00000007
#define PRCM_RFCMODESEL_CURR_S 0
#define PRCM_RFCMODESEL_CURR_MODE7 0x00000007
#define PRCM_RFCMODESEL_CURR_MODE6 0x00000006
#define PRCM_RFCMODESEL_CURR_MODE5 0x00000005
#define PRCM_RFCMODESEL_CURR_MODE4 0x00000004
#define PRCM_RFCMODESEL_CURR_MODE3 0x00000003
#define PRCM_RFCMODESEL_CURR_MODE2 0x00000002
#define PRCM_RFCMODESEL_CURR_MODE1 0x00000001
#define PRCM_RFCMODESEL_CURR_MODE0 0x00000000
//*****************************************************************************
//
// Register: PRCM_O_RAMRETEN
//
//*****************************************************************************
// Field: [2] RFC
//
//
// 0: Retention for RFC SRAM disabled
// 1: Retention for RFC SRAM enabled
#define PRCM_RAMRETEN_RFC 0x00000004
#define PRCM_RAMRETEN_RFC_BITN 2
#define PRCM_RAMRETEN_RFC_M 0x00000004
#define PRCM_RAMRETEN_RFC_S 2
// Field: [1:0] VIMS
//
//
// 0: Memory retention disabled
// 1: Memory retention enabled
//
// Bit 0: VIMS_TRAM
// Bit 1: VIMS_CRAM
//
// Legal modes depend on settings in VIMS:CTL.MODE
//
// 00: VIMS:CTL.MODE must be OFF before DEEPSLEEP is asserted - must be set to
// CACHE or SPLIT mode after waking up again
// 01: VIMS:CTL.MODE must be GPRAM before DEEPSLEEP is asserted. Must remain in
// GPRAM mode after wake up, alternatively select OFF mode first and then CACHE
// or SPILT mode.
// 10: Illegal mode
// 11: No restrictions
#define PRCM_RAMRETEN_VIMS_W 2
#define PRCM_RAMRETEN_VIMS_M 0x00000003
#define PRCM_RAMRETEN_VIMS_S 0
#endif // __PRCM__
|
9712435d007a194478ae5b3e420c6be45f4676fb
|
3249f58665a3d5a35acf20668095f03cf473cc3d
|
/cbits/gradient_descent.c
|
77dee2c113faa891c08bb05bf8a7c0b24803528d
|
[
"BSD-2-Clause"
] |
permissive
|
HuwCampbell/grenade
|
3813e009824a2ac1b75cd97fca77f043a79ad931
|
0e01175386523ac1176b48d024497ee16357f322
|
refs/heads/master
| 2023-04-29T23:20:18.543613
| 2023-04-22T15:02:24
| 2023-04-23T02:48:25
| 61,802,157
| 1,558
| 106
|
BSD-2-Clause
| 2023-04-23T02:48:26
| 2016-06-23T12:04:52
|
Haskell
|
UTF-8
|
C
| false
| false
| 440
|
c
|
gradient_descent.c
|
#include "gradient_descent.h"
void descend_cpu(int len, double rate, double momentum, double regulariser,
const double* weights,
const double* gradient,
const double* last,
double* outputWeights, double* outputMomentum) {
for (int i = 0; i < len; i++) {
outputMomentum[i] = momentum * last[i] - rate * gradient[i];
outputWeights[i] = weights[i] + outputMomentum[i] - (rate * regulariser) * weights[i];
}
}
|
6cccd64aae810d488224bb04fe63d9ce047d28c7
|
fb0f9abad373cd635c2635bbdf491ea0f32da5ff
|
/src/native/eventpipe/ep-session.h
|
6b26dc055e09209d7b990ef6f81a24165af9fd41
|
[
"MIT"
] |
permissive
|
dotnet/runtime
|
f6fd23936752e202f8e4d6d94f3a4f3b0e77f58f
|
47bb554d298e1e34c4e3895d7731e18ad1c47d02
|
refs/heads/main
| 2023-09-03T15:35:46.493337
| 2023-09-03T08:13:23
| 2023-09-03T08:13:23
| 210,716,005
| 13,765
| 5,179
|
MIT
| 2023-09-14T21:58:52
| 2019-09-24T23:36:39
|
C#
|
UTF-8
|
C
| false
| false
| 7,002
|
h
|
ep-session.h
|
#ifndef __EVENTPIPE_SESSION_H__
#define __EVENTPIPE_SESSION_H__
#include "ep-rt-config.h"
#ifdef ENABLE_PERFTRACING
#include "ep-types.h"
#include "ep-thread.h"
#undef EP_IMPL_GETTER_SETTER
#ifdef EP_IMPL_SESSION_GETTER_SETTER
#define EP_IMPL_GETTER_SETTER
#endif
#include "ep-getter-setter.h"
/*
* EventPipeSession.
*/
//! Encapsulates an EventPipe session information and memory management.
#if defined(EP_INLINE_GETTER_SETTER) || defined(EP_IMPL_SESSION_GETTER_SETTER)
struct _EventPipeSession {
#else
struct _EventPipeSession_Internal {
#endif
// When the session is of IPC or FILE stream type, this becomes a reference to the streaming thread.
ep_rt_thread_handle_t streaming_thread;
// Event object used to signal Disable that the streaming thread is done.
ep_rt_wait_event_handle_t rt_thread_shutdown_event;
// The set of configurations for each provider in the session.
EventPipeSessionProviderList *providers;
// Session buffer manager.
EventPipeBufferManager *buffer_manager;
// Object used to flush event data (File, IPC stream, etc.).
EventPipeFile *file;
// For synchoronous sessions.
EventPipeSessionSynchronousCallback synchronous_callback;
// Additional data to pass to the callback
void *callback_additional_data;
// Start date and time in UTC.
ep_system_timestamp_t session_start_time;
// Start timestamp.
ep_timestamp_t session_start_timestamp;
uint32_t index;
// True if rundown is enabled.
volatile uint32_t rundown_enabled;
// Data members used when an streaming thread is used.
volatile uint32_t streaming_enabled;
// The type of the session.
// This determines behavior within the system (e.g. policies around which events to drop, etc.)
EventPipeSessionType session_type;
// For file/IPC sessions this controls the format emitted. For in-proc EventListener it is
// irrelevant.
EventPipeSerializationFormat format;
// For determininig if a particular session needs rundown events.
bool rundown_requested;
// Note - access to this field is NOT synchronized
// This functionality is a workaround because we couldn't safely enable/disable the session where we wanted to due to lock-leveling.
// we expect to remove it in the future once that limitation is resolved other scenarios are discouraged from using this given that
// we plan to make it go away
bool paused;
// Set via environment variable to enable or disable stack collection globally
bool enable_stackwalk;
// Indicate that session is fully running (streaming thread started).
volatile uint32_t started;
};
#if !defined(EP_INLINE_GETTER_SETTER) && !defined(EP_IMPL_SESSION_GETTER_SETTER)
struct _EventPipeSession {
uint8_t _internal [sizeof (struct _EventPipeSession_Internal)];
};
#endif
EP_DEFINE_GETTER(EventPipeSession *, session, uint32_t, index)
EP_DEFINE_GETTER(EventPipeSession *, session, EventPipeSessionProviderList *, providers)
EP_DEFINE_GETTER(EventPipeSession *, session, EventPipeBufferManager *, buffer_manager)
EP_DEFINE_GETTER_REF(EventPipeSession *, session, volatile uint32_t *, rundown_enabled)
EP_DEFINE_GETTER(EventPipeSession *, session, bool, rundown_requested)
EP_DEFINE_GETTER(EventPipeSession *, session, ep_timestamp_t, session_start_time)
EP_DEFINE_GETTER(EventPipeSession *, session, ep_timestamp_t, session_start_timestamp)
EP_DEFINE_GETTER(EventPipeSession *, session, EventPipeFile *, file)
EP_DEFINE_GETTER(EventPipeSession *, session, bool, enable_stackwalk)
EventPipeSession *
ep_session_alloc (
uint32_t index,
const ep_char8_t *output_path,
IpcStream *stream,
EventPipeSessionType session_type,
EventPipeSerializationFormat format,
bool rundown_requested,
uint32_t circular_buffer_size_in_mb,
const EventPipeProviderConfiguration *providers,
uint32_t providers_len,
EventPipeSessionSynchronousCallback sync_callback,
void *callback_additional_data);
void
ep_session_free (EventPipeSession *session);
// _Requires_lock_held (ep)
EventPipeSessionProvider *
ep_session_get_session_provider (
const EventPipeSession *session,
const EventPipeProvider *provider);
// _Requires_lock_held (ep)
bool
ep_session_enable_rundown (EventPipeSession *session);
// _Requires_lock_held (ep)
void
ep_session_execute_rundown (
EventPipeSession *session,
dn_vector_ptr_t *execution_checkpoints);
// Force all in-progress writes to either finish or cancel
// This is required to ensure we can safely flush and delete the buffers
// _Requires_lock_held (ep)
void
ep_session_suspend_write_event (EventPipeSession *session);
// Write a sequence point into the output stream synchronously.
void
ep_session_write_sequence_point_unbuffered (EventPipeSession *session);
// Enable a session in the event pipe.
// MUST be called AFTER sending the IPC response
// Side effects:
// - sends file header information for nettrace format
// - turns on streaming thread which flushes events to stream
// _Requires_lock_held (ep)
void
ep_session_start_streaming (EventPipeSession *session);
// Determine if the session is valid or not.
// Invalid sessions can be detected before they are enabled.
bool
ep_session_is_valid (const EventPipeSession *session);
bool
ep_session_add_session_provider (
EventPipeSession *session,
EventPipeSessionProvider *session_provider);
// Disable a session in the event pipe.
// side-effects: writes all buffers to stream/file
void
ep_session_disable (EventPipeSession *session);
bool
ep_session_write_all_buffers_to_file (
EventPipeSession *session,
bool *events_written);
// If a session is non-synchronous (i.e. a file, pipe, etc) WriteEvent will
// put the event in a buffer and return as quick as possible. If a session is
// synchronous (callback to the profiler) then this method will block until the
// profiler is done parsing and reacting to it.
bool
ep_session_write_event (
EventPipeSession *session,
ep_rt_thread_handle_t thread,
EventPipeEvent *ep_event,
EventPipeEventPayload *payload,
const uint8_t *activity_id,
const uint8_t *related_activity_id,
ep_rt_thread_handle_t event_thread,
EventPipeStackContents *stack);
EventPipeEventInstance *
ep_session_get_next_event (EventPipeSession *session);
ep_rt_wait_event_handle_t *
ep_session_get_wait_event (EventPipeSession *session);
uint64_t
ep_session_get_mask (const EventPipeSession *session);
bool
ep_session_get_rundown_enabled (const EventPipeSession *session);
void
ep_session_set_rundown_enabled (
EventPipeSession *session,
bool enabled);
bool
ep_session_get_streaming_enabled (const EventPipeSession *session);
void
ep_session_set_streaming_enabled (
EventPipeSession *session,
bool enabled);
// Please do not use this function, see EventPipeSession paused field for more information.
void
ep_session_pause (EventPipeSession *session);
// Please do not use this function, see EventPipeSession paused field for more information.
void
ep_session_resume (EventPipeSession *session);
bool
ep_session_has_started (EventPipeSession *session);
#endif /* ENABLE_PERFTRACING */
#endif /* __EVENTPIPE_SESSION_H__ */
|
68d6b377a0720d364b6c8e0c9f815221e23501b1
|
85ccd32aa73eecf274a937f1fc3b6f4d484b77da
|
/test cases/common/23 endian/prog.c
|
90bd9583aef75b1688e1f446e9077d6aafb871b1
|
[
"Apache-2.0"
] |
permissive
|
mesonbuild/meson
|
48321cf4235dfcc0194fed90ff43a57367592bf7
|
cf5adf0c646474f0259d123fad60ca5ed38ec891
|
refs/heads/master
| 2023-09-01T05:58:50.807952
| 2023-03-17T20:27:37
| 2023-08-31T11:52:41
| 19,784,232
| 5,122
| 1,848
|
Apache-2.0
| 2023-09-14T15:47:23
| 2014-05-14T15:08:16
|
Python
|
UTF-8
|
C
| false
| false
| 375
|
c
|
prog.c
|
#include<stdint.h>
int is_big_endian(void) {
uint32_t one = 1;
if(*((uint8_t*) &one) == 1)
return 0;
return 1;
}
int main(void) {
int is_be_check = is_big_endian();
int is_be;
#ifdef IS_BE
is_be = 1;
#else
is_be = 0;
#endif
if(is_be_check && is_be)
return 0;
if(!is_be_check && !is_be)
return 0;
return 1;
}
|
20e136bec512190f88756fc5e5884db71dde96be
|
9467e2502183e843a67736800199e31674b1d8f6
|
/HybridCLRData/LocalIl2CppData-WindowsEditor/il2cpp/external/bdwgc/extra/pcr_interface.c
|
ff4618743d05b88e8c163eab9ab8a146e658c1fb
|
[
"LicenseRef-scancode-other-permissive",
"Boehm-GC",
"GPL-1.0-or-later",
"LicenseRef-scancode-other-copyleft",
"MIT",
"Apache-2.0"
] |
permissive
|
yimengfan/BDFramework.Core
|
3a046fcd755a84ba55d648dd3ad52c37a1cc1a04
|
81380fce8e84367f912777717665b53f074ab617
|
refs/heads/master
| 2023-09-04T10:08:47.644992
| 2023-07-05T16:22:11
| 2023-07-05T16:22:11
| 85,928,537
| 2,421
| 497
|
Apache-2.0
| 2023-03-21T06:56:21
| 2017-03-23T09:03:48
|
C#
|
UTF-8
|
C
| false
| false
| 4,884
|
c
|
pcr_interface.c
|
/*
* Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved.
*
* THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
* OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
*
* Permission is hereby granted to use or copy this program
* for any purpose, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*/
# include "private/gc_priv.h"
# ifdef PCR
/*
* We wrap all of the allocator functions to avoid questions of
* compatibility between the prototyped and nonprototyped versions of the f
*/
# include "config/PCR_StdTypes.h"
# include "mm/PCR_MM.h"
# include <errno.h>
# define MY_MAGIC 17L
# define MY_DEBUGMAGIC 42L
void * GC_AllocProc(size_t size, PCR_Bool ptrFree, PCR_Bool clear )
{
if (ptrFree) {
void * result = (void *)GC_malloc_atomic(size);
if (clear && result != 0) BZERO(result, size);
return(result);
} else {
return((void *)GC_malloc(size));
}
}
void * GC_DebugAllocProc(size_t size, PCR_Bool ptrFree, PCR_Bool clear )
{
if (ptrFree) {
void * result = (void *)GC_debug_malloc_atomic(size, __FILE__,
__LINE__);
if (clear && result != 0) BZERO(result, size);
return(result);
} else {
return((void *)GC_debug_malloc(size, __FILE__, __LINE__));
}
}
# define GC_ReallocProc GC_realloc
void * GC_DebugReallocProc(void * old_object, size_t new_size_in_bytes)
{
return(GC_debug_realloc(old_object, new_size_in_bytes, __FILE__, __LINE__));
}
# define GC_FreeProc GC_free
# define GC_DebugFreeProc GC_debug_free
typedef struct {
PCR_ERes (*ed_proc)(void *p, size_t size, PCR_Any data);
GC_bool ed_pointerfree;
PCR_ERes ed_fail_code;
PCR_Any ed_client_data;
} enumerate_data;
void GC_enumerate_block(struct hblk *h, enumerate_data * ed)
{
hdr * hhdr;
size_t sz;
ptr_t p;
ptr_t lim;
word descr;
# if !defined(CPPCHECK)
# error This code was updated without testing.
# error and its precursor was clearly broken.
# endif
hhdr = HDR(h);
descr = hhdr -> hb_descr;
sz = (size_t)hhdr->hb_sz;
if (descr != 0 && ed -> ed_pointerfree
|| descr == 0 && !(ed -> ed_pointerfree)) return;
lim = (ptr_t)(h+1) - sz;
p = (ptr_t)h;
do {
if (PCR_ERes_IsErr(ed -> ed_fail_code)) return;
ed -> ed_fail_code =
(*(ed -> ed_proc))(p, sz, ed -> ed_client_data);
p+= sz;
} while ((word)p <= (word)lim);
}
struct PCR_MM_ProcsRep * GC_old_allocator = 0;
PCR_ERes GC_EnumerateProc(
PCR_Bool ptrFree,
PCR_ERes (*proc)(void *p, size_t size, PCR_Any data),
PCR_Any data
)
{
enumerate_data ed;
ed.ed_proc = proc;
ed.ed_pointerfree = ptrFree;
ed.ed_fail_code = PCR_ERes_okay;
ed.ed_client_data = data;
GC_apply_to_all_blocks(GC_enumerate_block, &ed);
if (ed.ed_fail_code != PCR_ERes_okay) {
return(ed.ed_fail_code);
} else {
/* Also enumerate objects allocated by my predecessors */
return((*(GC_old_allocator->mmp_enumerate))(ptrFree, proc, data));
}
}
void GC_DummyFreeProc(void *p) {}
void GC_DummyShutdownProc(void) {}
struct PCR_MM_ProcsRep GC_Rep = {
MY_MAGIC,
GC_AllocProc,
GC_ReallocProc,
GC_DummyFreeProc, /* mmp_free */
GC_FreeProc, /* mmp_unsafeFree */
GC_EnumerateProc,
GC_DummyShutdownProc /* mmp_shutdown */
};
struct PCR_MM_ProcsRep GC_DebugRep = {
MY_DEBUGMAGIC,
GC_DebugAllocProc,
GC_DebugReallocProc,
GC_DummyFreeProc, /* mmp_free */
GC_DebugFreeProc, /* mmp_unsafeFree */
GC_EnumerateProc,
GC_DummyShutdownProc /* mmp_shutdown */
};
GC_bool GC_use_debug = 0;
void GC_pcr_install()
{
PCR_MM_Install((GC_use_debug? &GC_DebugRep : &GC_Rep), &GC_old_allocator);
}
PCR_ERes
PCR_GC_Setup(void)
{
return PCR_ERes_okay;
}
PCR_ERes
PCR_GC_Run(void)
{
if( !PCR_Base_TestPCRArg("-nogc") ) {
GC_quiet = ( PCR_Base_TestPCRArg("-gctrace") ? 0 : 1 );
GC_use_debug = (GC_bool)PCR_Base_TestPCRArg("-debug_alloc");
GC_init();
if( !PCR_Base_TestPCRArg("-nogc_incremental") ) {
/*
* awful hack to test whether VD is implemented ...
*/
if( PCR_VD_Start( 0, NIL, 0) != PCR_ERes_FromErr(ENOSYS) ) {
GC_enable_incremental();
}
}
}
return PCR_ERes_okay;
}
void GC_push_thread_structures(void)
{
/* PCR doesn't work unless static roots are pushed. Can't get here. */
ABORT("In GC_push_thread_structures()");
}
# endif
|
962940f5e94644d663d3d9b0dfbf8f6960eed290
|
f37bed43adb2e588156192aebb45f63ae2a88d09
|
/mkfs/mkfs.c
|
1ec326bade687078337805c101643b0e080d4826
|
[
"MIT"
] |
permissive
|
mit-pdos/xv6-riscv
|
4233d77ae18dee530c507230629a002c01fa6cd4
|
f5b93ef12f7159f74f80f94729ee4faabe42c360
|
refs/heads/riscv
| 2023-08-23T18:35:21.573540
| 2022-08-25T18:20:52
| 2022-08-25T18:20:52
| 204,459,250
| 4,546
| 1,981
|
NOASSERTION
| 2023-09-13T03:37:58
| 2019-08-26T11:15:28
|
C
|
UTF-8
|
C
| false
| false
| 6,309
|
c
|
mkfs.c
|
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <assert.h>
#define stat xv6_stat // avoid clash with host struct stat
#include "kernel/types.h"
#include "kernel/fs.h"
#include "kernel/stat.h"
#include "kernel/param.h"
#ifndef static_assert
#define static_assert(a, b) do { switch (0) case 0: case (a): ; } while (0)
#endif
#define NINODES 200
// Disk layout:
// [ boot block | sb block | log | inode blocks | free bit map | data blocks ]
int nbitmap = FSSIZE/(BSIZE*8) + 1;
int ninodeblocks = NINODES / IPB + 1;
int nlog = LOGSIZE;
int nmeta; // Number of meta blocks (boot, sb, nlog, inode, bitmap)
int nblocks; // Number of data blocks
int fsfd;
struct superblock sb;
char zeroes[BSIZE];
uint freeinode = 1;
uint freeblock;
void balloc(int);
void wsect(uint, void*);
void winode(uint, struct dinode*);
void rinode(uint inum, struct dinode *ip);
void rsect(uint sec, void *buf);
uint ialloc(ushort type);
void iappend(uint inum, void *p, int n);
void die(const char *);
// convert to riscv byte order
ushort
xshort(ushort x)
{
ushort y;
uchar *a = (uchar*)&y;
a[0] = x;
a[1] = x >> 8;
return y;
}
uint
xint(uint x)
{
uint y;
uchar *a = (uchar*)&y;
a[0] = x;
a[1] = x >> 8;
a[2] = x >> 16;
a[3] = x >> 24;
return y;
}
int
main(int argc, char *argv[])
{
int i, cc, fd;
uint rootino, inum, off;
struct dirent de;
char buf[BSIZE];
struct dinode din;
static_assert(sizeof(int) == 4, "Integers must be 4 bytes!");
if(argc < 2){
fprintf(stderr, "Usage: mkfs fs.img files...\n");
exit(1);
}
assert((BSIZE % sizeof(struct dinode)) == 0);
assert((BSIZE % sizeof(struct dirent)) == 0);
fsfd = open(argv[1], O_RDWR|O_CREAT|O_TRUNC, 0666);
if(fsfd < 0)
die(argv[1]);
// 1 fs block = 1 disk sector
nmeta = 2 + nlog + ninodeblocks + nbitmap;
nblocks = FSSIZE - nmeta;
sb.magic = FSMAGIC;
sb.size = xint(FSSIZE);
sb.nblocks = xint(nblocks);
sb.ninodes = xint(NINODES);
sb.nlog = xint(nlog);
sb.logstart = xint(2);
sb.inodestart = xint(2+nlog);
sb.bmapstart = xint(2+nlog+ninodeblocks);
printf("nmeta %d (boot, super, log blocks %u inode blocks %u, bitmap blocks %u) blocks %d total %d\n",
nmeta, nlog, ninodeblocks, nbitmap, nblocks, FSSIZE);
freeblock = nmeta; // the first free block that we can allocate
for(i = 0; i < FSSIZE; i++)
wsect(i, zeroes);
memset(buf, 0, sizeof(buf));
memmove(buf, &sb, sizeof(sb));
wsect(1, buf);
rootino = ialloc(T_DIR);
assert(rootino == ROOTINO);
bzero(&de, sizeof(de));
de.inum = xshort(rootino);
strcpy(de.name, ".");
iappend(rootino, &de, sizeof(de));
bzero(&de, sizeof(de));
de.inum = xshort(rootino);
strcpy(de.name, "..");
iappend(rootino, &de, sizeof(de));
for(i = 2; i < argc; i++){
// get rid of "user/"
char *shortname;
if(strncmp(argv[i], "user/", 5) == 0)
shortname = argv[i] + 5;
else
shortname = argv[i];
assert(index(shortname, '/') == 0);
if((fd = open(argv[i], 0)) < 0)
die(argv[i]);
// Skip leading _ in name when writing to file system.
// The binaries are named _rm, _cat, etc. to keep the
// build operating system from trying to execute them
// in place of system binaries like rm and cat.
if(shortname[0] == '_')
shortname += 1;
inum = ialloc(T_FILE);
bzero(&de, sizeof(de));
de.inum = xshort(inum);
strncpy(de.name, shortname, DIRSIZ);
iappend(rootino, &de, sizeof(de));
while((cc = read(fd, buf, sizeof(buf))) > 0)
iappend(inum, buf, cc);
close(fd);
}
// fix size of root inode dir
rinode(rootino, &din);
off = xint(din.size);
off = ((off/BSIZE) + 1) * BSIZE;
din.size = xint(off);
winode(rootino, &din);
balloc(freeblock);
exit(0);
}
void
wsect(uint sec, void *buf)
{
if(lseek(fsfd, sec * BSIZE, 0) != sec * BSIZE)
die("lseek");
if(write(fsfd, buf, BSIZE) != BSIZE)
die("write");
}
void
winode(uint inum, struct dinode *ip)
{
char buf[BSIZE];
uint bn;
struct dinode *dip;
bn = IBLOCK(inum, sb);
rsect(bn, buf);
dip = ((struct dinode*)buf) + (inum % IPB);
*dip = *ip;
wsect(bn, buf);
}
void
rinode(uint inum, struct dinode *ip)
{
char buf[BSIZE];
uint bn;
struct dinode *dip;
bn = IBLOCK(inum, sb);
rsect(bn, buf);
dip = ((struct dinode*)buf) + (inum % IPB);
*ip = *dip;
}
void
rsect(uint sec, void *buf)
{
if(lseek(fsfd, sec * BSIZE, 0) != sec * BSIZE)
die("lseek");
if(read(fsfd, buf, BSIZE) != BSIZE)
die("read");
}
uint
ialloc(ushort type)
{
uint inum = freeinode++;
struct dinode din;
bzero(&din, sizeof(din));
din.type = xshort(type);
din.nlink = xshort(1);
din.size = xint(0);
winode(inum, &din);
return inum;
}
void
balloc(int used)
{
uchar buf[BSIZE];
int i;
printf("balloc: first %d blocks have been allocated\n", used);
assert(used < BSIZE*8);
bzero(buf, BSIZE);
for(i = 0; i < used; i++){
buf[i/8] = buf[i/8] | (0x1 << (i%8));
}
printf("balloc: write bitmap block at sector %d\n", sb.bmapstart);
wsect(sb.bmapstart, buf);
}
#define min(a, b) ((a) < (b) ? (a) : (b))
void
iappend(uint inum, void *xp, int n)
{
char *p = (char*)xp;
uint fbn, off, n1;
struct dinode din;
char buf[BSIZE];
uint indirect[NINDIRECT];
uint x;
rinode(inum, &din);
off = xint(din.size);
// printf("append inum %d at off %d sz %d\n", inum, off, n);
while(n > 0){
fbn = off / BSIZE;
assert(fbn < MAXFILE);
if(fbn < NDIRECT){
if(xint(din.addrs[fbn]) == 0){
din.addrs[fbn] = xint(freeblock++);
}
x = xint(din.addrs[fbn]);
} else {
if(xint(din.addrs[NDIRECT]) == 0){
din.addrs[NDIRECT] = xint(freeblock++);
}
rsect(xint(din.addrs[NDIRECT]), (char*)indirect);
if(indirect[fbn - NDIRECT] == 0){
indirect[fbn - NDIRECT] = xint(freeblock++);
wsect(xint(din.addrs[NDIRECT]), (char*)indirect);
}
x = xint(indirect[fbn-NDIRECT]);
}
n1 = min(n, (fbn + 1) * BSIZE - off);
rsect(x, buf);
bcopy(p, buf + off - (fbn * BSIZE), n1);
wsect(x, buf);
n -= n1;
off += n1;
p += n1;
}
din.size = xint(off);
winode(inum, &din);
}
void
die(const char *s)
{
perror(s);
exit(1);
}
|
70cfe14f2adf005e6a038e782a767f72a6512a03
|
2898fa4f2ad766afa0495a837f59fe95daa081a7
|
/tests/unit-pass/pr29156.c
|
d496f91865dd4391ec51baa7f397088613d55bc0
|
[
"NCSA"
] |
permissive
|
kframework/c-semantics
|
12fcc1b1bf1f7792636d1c37f6f7bb1b89a392b5
|
e6879d14455771aa0cb3e3d201131d4d763a73a2
|
refs/heads/master
| 2023-07-31T23:57:03.316456
| 2022-02-01T17:50:31
| 2022-02-01T17:50:31
| 11,747,541
| 312
| 52
|
NOASSERTION
| 2022-02-01T17:50:33
| 2013-07-29T19:13:25
|
C
|
UTF-8
|
C
| false
| false
| 358
|
c
|
pr29156.c
|
#include <stdlib.h>
extern void abort(void);
struct test1
{
int a;
int b;
};
struct test2
{
float d;
struct test1 sub;
};
int global;
int bla(struct test1 *xa, struct test2 *xb)
{
global = 1;
xb->sub.a = 1;
xa->a = 8;
return xb->sub.a;
}
int main(void)
{
struct test2 pom;
if (bla (&pom.sub, &pom) != 8)
abort ();
return 0;
}
|
b0dd9575b72dcc4b40bc8995d975448599925624
|
2d11442aa09b51e10c245ee2b64231aeb051744f
|
/platforms/Cross/plugins/SqueakFFIPrims/sqFFIPlugin.c
|
5bafac2ea2ebac87d4979fed4ea19b928a4fa719
|
[
"MIT"
] |
permissive
|
OpenSmalltalk/opensmalltalk-vm
|
622b01c10017a93fdff4f1ef2188c45342384c78
|
330d6779ad2ecbce1f07131f53d75cd168165f0b
|
refs/heads/Cog
| 2023-09-04T05:36:54.320281
| 2023-08-17T11:32:52
| 2023-08-31T12:26:44
| 59,481,716
| 556
| 153
|
NOASSERTION
| 2023-06-19T19:58:13
| 2016-05-23T12:40:27
|
C
|
UTF-8
|
C
| false
| false
| 2,245
|
c
|
sqFFIPlugin.c
|
/****************************************************************************
* PROJECT: Squeak threaded foreign function interface
* FILE: sqFFIPlugin.c
* CONTENT: C support code for the threaded FFIPlugin
*
* AUTHOR: Eliot Miranda
*
*****************************************************************************/
#include "config.h"
#include <stdio.h>
#include <stdlib.h> /* proto for alloca in MINGW */
#if !_WIN32 && !__FreeBSD__ && !__OpenBSD__
# include <alloca.h>
#endif
#include <string.h>
#ifdef _MSC_VER
# include <windows.h>
# define alloca _alloca
#endif
#include "sqVirtualMachine.h"
extern struct VirtualMachine* interpreterProxy;
/* this is a stub through which floating-point register arguments can be loaded
* prior to an FFI call proper. e.g. on the PowerPC this would be declared as
* extern void loadFloatRegs(double, double, double, double,
* double, double, double, double);
* and called with the appropriate values necessary to load the floating-point
* argument registers. Immediately after the actual call is made, using the
* undisturbed register contents created by the call of loadFloatRegs.
*/
void
loadFloatRegs(void) { return; }
/* this is the call logging interface.
*/
static FILE *ffiLogFile = NULL;
int
ffiLogFileNameOfLength(void *nameIndex, int nameLength)
{
if (nameIndex && nameLength) {
char *fileName;
FILE *fp;
if (!(fileName = alloca(nameLength+1)))
return 0;
strncpy(fileName, nameIndex, nameLength);
fileName[nameLength] = 0;
/* attempt to open the file and if we can't, fail */
if (!(fp = fopen(fileName, "at")))
return 0;
/* close the old log file if needed and use the new one */
if (ffiLogFile)
fclose(ffiLogFile);
ffiLogFile = fp;
fprintf(ffiLogFile, "------- Log started -------\n");
fflush(fp);
}
else {
if (ffiLogFile)
fclose(ffiLogFile);
ffiLogFile = NULL;
}
return 1;
}
void
doFFILogCallout(sqInt externalFunctionName)
{
if (!ffiLogFile || !interpreterProxy->isBytes(externalFunctionName))
return;
fprintf(ffiLogFile,
"%.*s\n",
interpreterProxy->byteSizeOf(externalFunctionName),
interpreterProxy->firstIndexableField(externalFunctionName));
fflush(ffiLogFile);
}
|
21567d4dc19acf6292e2e68f3dd4b5c32cf21d2a
|
fdbb74a95924e2677466614f6ab6e2bb13b2a95a
|
/libc/nt/enum/systeminformationclass.h
|
eab431b18501e5c3189fbfd40ee46b6192c9d31e
|
[
"ISC"
] |
permissive
|
jart/cosmopolitan
|
fb11b5658939023977060a7c6c71a74093d9cb44
|
0d748ad58e1063dd1f8560f18a0c75293b9415b7
|
refs/heads/master
| 2023-09-06T09:17:29.303607
| 2023-09-02T03:49:13
| 2023-09-02T03:50:18
| 272,457,606
| 11,887
| 435
|
ISC
| 2023-09-14T17:47:58
| 2020-06-15T14:16:13
|
C
|
UTF-8
|
C
| false
| false
| 765
|
h
|
systeminformationclass.h
|
#ifndef COSMOPOLITAN_LIBC_NT_ENUM_SYSTEMINFORMATIONCLASS_H_
#define COSMOPOLITAN_LIBC_NT_ENUM_SYSTEMINFORMATIONCLASS_H_
#define kNtSystemBasicInformation 0
#define kNtSystemProcessorInformation 1
#define kNtSystemPerformanceInformation 2
#define kNtSystemTimeOfDayInformation 3
#define kNtSystemProcessInformation 5
#define kNtSystemProcessorTimes 8
#define kNtSystemGlobalFlag 9
#define kNtSystemModuleInformation 11
#define kNtSystemLockInformation 12
#define kNtSystemHandleInformation 16
#define kNtSystemObjectInformation 17
#define kNtSystemInterruptInformation 23
#define kNtSystemExceptionInformation 33
#define kNtSystemRegistryQuotaInformation 37
#define kNtSystemLookasideInformation 45
#endif /* COSMOPOLITAN_LIBC_NT_ENUM_SYSTEMINFORMATIONCLASS_H_ */
|
188a32a5e2e4a41173fa0d83c80caef9dde1eebe
|
e51d227e06363817463efa2650e97d07290aed34
|
/src/Cedar/IPsec_IPC.h
|
2340788e9d9dd44ee3817cbaed0c93bcaa739071
|
[
"LicenseRef-scancode-warranty-disclaimer",
"Apache-2.0"
] |
permissive
|
SoftEtherVPN/SoftEtherVPN_Stable
|
21426b5fdcf3b518be5d9174441192450e54e836
|
89939eb52f1f40e4f75c76e8d5eca019de103532
|
refs/heads/master
| 2023-08-08T09:51:40.139112
| 2023-06-30T03:19:06
| 2023-06-30T03:19:06
| 107,487,278
| 1,710
| 553
|
Apache-2.0
| 2023-06-24T02:56:31
| 2017-10-19T02:19:51
|
C
|
UTF-8
|
C
| false
| false
| 11,633
|
h
|
IPsec_IPC.h
|
// SoftEther VPN Source Code - Stable Edition Repository
// Cedar Communication Module
//
// SoftEther VPN Server, Client and Bridge are free software under the Apache License, Version 2.0.
//
// Copyright (c) Daiyuu Nobori.
// Copyright (c) SoftEther VPN Project, University of Tsukuba, Japan.
// Copyright (c) SoftEther Corporation.
// Copyright (c) all contributors on SoftEther VPN project in GitHub.
//
// All Rights Reserved.
//
// http://www.softether.org/
//
// This stable branch is officially managed by Daiyuu Nobori, the owner of SoftEther VPN Project.
// Pull requests should be sent to the Developer Edition Master Repository on https://github.com/SoftEtherVPN/SoftEtherVPN
//
// License: The Apache License, Version 2.0
// https://www.apache.org/licenses/LICENSE-2.0
//
// DISCLAIMER
// ==========
//
// 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.
//
// THIS SOFTWARE IS DEVELOPED IN JAPAN, AND DISTRIBUTED FROM JAPAN, UNDER
// JAPANESE LAWS. YOU MUST AGREE IN ADVANCE TO USE, COPY, MODIFY, MERGE, PUBLISH,
// DISTRIBUTE, SUBLICENSE, AND/OR SELL COPIES OF THIS SOFTWARE, THAT ANY
// JURIDICAL DISPUTES WHICH ARE CONCERNED TO THIS SOFTWARE OR ITS CONTENTS,
// AGAINST US (SOFTETHER PROJECT, SOFTETHER CORPORATION, DAIYUU NOBORI OR OTHER
// SUPPLIERS), OR ANY JURIDICAL DISPUTES AGAINST US WHICH ARE CAUSED BY ANY KIND
// OF USING, COPYING, MODIFYING, MERGING, PUBLISHING, DISTRIBUTING, SUBLICENSING,
// AND/OR SELLING COPIES OF THIS SOFTWARE SHALL BE REGARDED AS BE CONSTRUED AND
// CONTROLLED BY JAPANESE LAWS, AND YOU MUST FURTHER CONSENT TO EXCLUSIVE
// JURISDICTION AND VENUE IN THE COURTS SITTING IN TOKYO, JAPAN. YOU MUST WAIVE
// ALL DEFENSES OF LACK OF PERSONAL JURISDICTION AND FORUM NON CONVENIENS.
// PROCESS MAY BE SERVED ON EITHER PARTY IN THE MANNER AUTHORIZED BY APPLICABLE
// LAW OR COURT RULE.
//
// USE ONLY IN JAPAN. DO NOT USE THIS SOFTWARE IN ANOTHER COUNTRY UNLESS YOU HAVE
// A CONFIRMATION THAT THIS SOFTWARE DOES NOT VIOLATE ANY CRIMINAL LAWS OR CIVIL
// RIGHTS IN THAT PARTICULAR COUNTRY. USING THIS SOFTWARE IN OTHER COUNTRIES IS
// COMPLETELY AT YOUR OWN RISK. THE SOFTETHER VPN PROJECT HAS DEVELOPED AND
// DISTRIBUTED THIS SOFTWARE TO COMPLY ONLY WITH THE JAPANESE LAWS AND EXISTING
// CIVIL RIGHTS INCLUDING PATENTS WHICH ARE SUBJECTS APPLY IN JAPAN. OTHER
// COUNTRIES' LAWS OR CIVIL RIGHTS ARE NONE OF OUR CONCERNS NOR RESPONSIBILITIES.
// WE HAVE NEVER INVESTIGATED ANY CRIMINAL REGULATIONS, CIVIL LAWS OR
// INTELLECTUAL PROPERTY RIGHTS INCLUDING PATENTS IN ANY OF OTHER 200+ COUNTRIES
// AND TERRITORIES. BY NATURE, THERE ARE 200+ REGIONS IN THE WORLD, WITH
// DIFFERENT LAWS. IT IS IMPOSSIBLE TO VERIFY EVERY COUNTRIES' LAWS, REGULATIONS
// AND CIVIL RIGHTS TO MAKE THE SOFTWARE COMPLY WITH ALL COUNTRIES' LAWS BY THE
// PROJECT. EVEN IF YOU WILL BE SUED BY A PRIVATE ENTITY OR BE DAMAGED BY A
// PUBLIC SERVANT IN YOUR COUNTRY, THE DEVELOPERS OF THIS SOFTWARE WILL NEVER BE
// LIABLE TO RECOVER OR COMPENSATE SUCH DAMAGES, CRIMINAL OR CIVIL
// RESPONSIBILITIES. NOTE THAT THIS LINE IS NOT LICENSE RESTRICTION BUT JUST A
// STATEMENT FOR WARNING AND DISCLAIMER.
//
// READ AND UNDERSTAND THE 'WARNING.TXT' FILE BEFORE USING THIS SOFTWARE.
// SOME SOFTWARE PROGRAMS FROM THIRD PARTIES ARE INCLUDED ON THIS SOFTWARE WITH
// LICENSE CONDITIONS WHICH ARE DESCRIBED ON THE 'THIRD_PARTY.TXT' FILE.
//
//
// SOURCE CODE CONTRIBUTION
// ------------------------
//
// Your contribution to SoftEther VPN Project is much appreciated.
// Please send patches to us through GitHub.
// Read the SoftEther VPN Patch Acceptance Policy in advance:
// http://www.softether.org/5-download/src/9.patch
//
//
// DEAR SECURITY EXPERTS
// ---------------------
//
// If you find a bug or a security vulnerability please kindly inform us
// about the problem immediately so that we can fix the security problem
// to protect a lot of users around the world as soon as possible.
//
// Our e-mail address for security reports is:
// softether-vpn-security [at] softether.org
//
// Please note that the above e-mail address is not a technical support
// inquiry address. If you need technical assistance, please visit
// http://www.softether.org/ and ask your question on the users forum.
//
// Thank you for your cooperation.
//
//
// NO MEMORY OR RESOURCE LEAKS
// ---------------------------
//
// The memory-leaks and resource-leaks verification under the stress
// test has been passed before release this source code.
// IPsec_IPC.h
// Header of IPsec_IPC.c
#ifndef IPSEC_IPC
#define IPSEC_IPC
// Constants
#define IPC_ARP_LIFETIME (3 * 60 * 1000)
#define IPC_ARP_GIVEUPTIME (1 * 1000)
#define IPC_DHCP_TIMEOUT (5 * 1000)
#define IPC_DHCP_TIMEOUT_TOTAL_GIVEUP (20 * 1000)
#define IPC_DHCP_MIN_LEASE 5
#define IPC_DHCP_DEFAULT_LEASE 3600
#define IPC_MAX_PACKET_QUEUE_LEN 10000
#define IPC_DHCP_VENDOR_ID "MSFT 5.0"
#define IPC_PASSWORD_MSCHAPV2_TAG "xH7DiNlurDhcYV4a:"
#define IPC_LAYER_2 2
#define IPC_LAYER_3 3
// ARP table entry
struct IPC_ARP
{
IP Ip; // IP address
bool Resolved; // Whether the MAC address have been resolved
UCHAR MacAddress[6]; // MAC address
UINT64 GiveupTime; // Time to give up (in the case of unresolved)
UINT64 ExpireTime; // Expiration date (If resolved)
QUEUE *PacketQueue; // Transmission packet queue
};
// DHCP release queue
struct IPC_DHCP_RELESAE_QUEUE
{
DHCP_OPTION_LIST Req;
UINT TranId;
UCHAR MacAddress[6];
};
// IPC_SESSION_SHARED_BUFFER_DATA
struct IPC_SESSION_SHARED_BUFFER_DATA
{
char ProtocolDetails[256]; // Protocol Details
bool EnableUdpAccel;
bool UsingUdpAccel;
};
// IPC_PARAM
struct IPC_PARAM
{
char ClientName[MAX_SIZE];
char Postfix[MAX_SIZE];
char HubName[MAX_HUBNAME_LEN + 1];
char UserName[MAX_USERNAME_LEN + 1];
char Password[MAX_PASSWORD_LEN + 1];
IP ClientIp;
UINT ClientPort;
IP ServerIp;
UINT ServerPort;
char ClientHostname[MAX_SIZE];
char CryptName[MAX_SIZE];
bool BridgeMode;
UINT Mss;
bool IsL3Mode;
bool IsOpenVPN;
X *ClientCertificate;
UINT Layer;
};
// IPC_ASYNC object
struct IPC_ASYNC
{
CEDAR *Cedar; // Cedar
IPC_PARAM Param; // Parameters for creating IPC
THREAD *Thread; // Thread
SOCK_EVENT *SockEvent; // Socket events that is set when the connection is completed
bool Done; // Processing completion flag
IPC *Ipc; // IPC object (if it fails to connect, the value is NULL)
TUBE *TubeForDisconnect; // Tube for disconnection notification
UINT ErrorCode; // Error code in the case of failing to connect
DHCP_OPTION_LIST L3ClientAddressOption; // Client IP address option (Only in the case of L3 mode)
UINT64 L3DhcpRenewInterval; // DHCP update interval
UINT64 L3NextDhcpRenewTick; // DHCP renewal time of the next
bool DhcpAllocFailed; // Failed to get IP address from the DHCP server
};
// IPC object
struct IPC
{
CEDAR *Cedar;
char HubName[MAX_HUBNAME_LEN + 1];
char UserName[MAX_USERNAME_LEN + 1];
char Password[MAX_PASSWORD_LEN + 1];
char ClientHostname[MAX_SIZE];
UCHAR random[SHA1_SIZE];
char SessionName[MAX_SESSION_NAME_LEN + 1];
char ConnectionName[MAX_CONNECTION_NAME_LEN + 1];
POLICY *Policy;
SOCK *Sock;
INTERRUPT_MANAGER *Interrupt; // Interrupt manager
IP ClientIPAddress; // IP address of the client
IP SubnetMask; // Subnet mask of the client
IP DefaultGateway; // Default gateway address
IP BroadcastAddress; // Broadcast address
UCHAR MacAddress[6]; // MAC address
UCHAR Padding[2];
LIST *ArpTable; // ARP table
QUEUE *IPv4RecviedQueue; // IPv4 reception queue
TUBE_FLUSH_LIST *FlushList; // Tube Flush List
UCHAR MsChapV2_ServerResponse[20]; // Server response
DHCP_CLASSLESS_ROUTE_TABLE ClasslessRoute; // Classless routing table
SHARED_BUFFER *IpcSessionSharedBuffer; // A shared buffer between IPC and Session
IPC_SESSION_SHARED_BUFFER_DATA *IpcSessionShared; // A shared data between IPC and Session
UINT Layer;
};
// MS-CHAPv2 authentication information
struct IPC_MSCHAP_V2_AUTHINFO
{
char MsChapV2_PPPUsername[MAX_SIZE]; // MS-CHAPv2 Username
UCHAR MsChapV2_ServerChallenge[16]; // MS-CHAPv2 Server Challenge
UCHAR MsChapV2_ClientChallenge[16]; // MS-CHAPv2 Client Challenge
UCHAR MsChapV2_ClientResponse[24]; // MS-CHAPv2 Client Response
EAP_CLIENT *MsChapV2_EapClient; // EAP client
};
IPC *NewIPC(CEDAR *cedar, char *client_name, char *postfix, char *hubname, char *username, char *password,
UINT *error_code, IP *client_ip, UINT client_port, IP *server_ip, UINT server_port,
char *client_hostname, char *crypt_name,
bool bridge_mode, UINT mss, EAP_CLIENT *eap_client, X *client_certificate,
UINT layer);
IPC *NewIPCByParam(CEDAR *cedar, IPC_PARAM *param, UINT *error_code);
IPC *NewIPCBySock(CEDAR *cedar, SOCK *s, void *mac_address);
void FreeIPC(IPC *ipc);
bool IsIPCConnected(IPC *ipc);
void IPCSetSockEventWhenRecvL2Packet(IPC *ipc, SOCK_EVENT *e);
void IPCSendL2(IPC *ipc, void *data, UINT size);
void IPCSendIPv4(IPC *ipc, void *data, UINT size);
BLOCK *IPCRecvL2(IPC *ipc);
BLOCK *IPCRecvIPv4(IPC *ipc);
void IPCProcessInterrupts(IPC *ipc);
void IPCProcessL3Events(IPC *ipc);
void IPCProcessL3EventsEx(IPC *ipc, UINT64 now);
bool IPCSetIPv4Parameters(IPC *ipc, IP *ip, IP *subnet, IP *gw, DHCP_CLASSLESS_ROUTE_TABLE *rt);
IPC_ARP *IPCNewARP(IP *ip, UCHAR *mac_address);
void IPCFreeARP(IPC_ARP *a);
int IPCCmpArpTable(void *p1, void *p2);
void IPCSendIPv4Unicast(IPC *ipc, void *data, UINT size, IP *next_ip);
IPC_ARP *IPCSearchArpTable(IPC *ipc, IP *ip);
void IPCSendIPv4WithDestMacAddr(IPC *ipc, void *data, UINT size, UCHAR *dest_mac_addr);
void IPCFlushArpTable(IPC *ipc);
void IPCFlushArpTableEx(IPC *ipc, UINT64 now);
void IPCProcessArp(IPC *ipc, BLOCK *b);
void IPCAssociateOnArpTable(IPC *ipc, IP *ip, UCHAR *mac_address);
bool IsValidUnicastMacAddress(UCHAR *mac);
bool IsValidUnicastIPAddress4(IP *ip);
bool IsValidUnicastIPAddressUINT4(UINT ip);
DHCPV4_DATA *IPCSendDhcpRequest(IPC *ipc, IP *dest_ip, UINT tran_id, DHCP_OPTION_LIST *opt, UINT expecting_code, UINT timeout, TUBE *discon_poll_tube);
BUF *IPCBuildDhcpRequest(IPC *ipc, IP *dest_ip, UINT tran_id, DHCP_OPTION_LIST *opt);
BUF *IPCBuildDhcpRequestOptions(IPC *ipc, DHCP_OPTION_LIST *opt);
bool IPCDhcpAllocateIP(IPC *ipc, DHCP_OPTION_LIST *opt, TUBE *discon_poll_tube);
bool IPCDhcpAllocateIPEx(IPC *ipc, DHCP_OPTION_LIST *opt, TUBE *discon_poll_tube, bool openvpn_compatible);
bool IPCDhcpRequestInformIP(IPC *ipc, DHCP_OPTION_LIST *opt, TUBE *discon_poll_tube, IP *client_ip);
void IPCDhcpRenewIP(IPC *ipc, IP *dhcp_server);
void IPCDhcpFreeIP(IPC *ipc, IP *dhcp_server);
IPC_ASYNC *NewIPCAsync(CEDAR *cedar, IPC_PARAM *param, SOCK_EVENT *sock_event);
void IPCAsyncThreadProc(THREAD *thread, void *param);
void FreeIPCAsync(IPC_ASYNC *a);
bool ParseAndExtractMsChapV2InfoFromPassword(IPC_MSCHAP_V2_AUTHINFO *d, char *password);
#endif // IPSEC_IPC
|
ea4fae5e6e0a0ffe9514fa2856cb1f41d814e9e9
|
971b2cea2d1c3001aadc8ca1a48110b7db1ed5f2
|
/deps/abc/src/bdd/cudd/cuddExport.c
|
41735a8c8fbf1e2739526f574b19dc282e164275
|
[
"LicenseRef-scancode-warranty-disclaimer",
"MIT",
"MIT-Modern-Variant"
] |
permissive
|
emsec/hal
|
70ad2921739967d914dd458984bd7d6d497d3b0a
|
e4fae37bec9168a61100eacfda37a1f291b4d0be
|
refs/heads/master
| 2023-09-02T20:27:32.909426
| 2023-09-01T13:03:24
| 2023-09-01T13:03:24
| 169,076,171
| 510
| 72
|
MIT
| 2023-09-01T13:03:26
| 2019-02-04T12:37:20
|
C++
|
UTF-8
|
C
| false
| false
| 48,108
|
c
|
cuddExport.c
|
/**CFile***********************************************************************
FileName [cuddExport.c]
PackageName [cudd]
Synopsis [Export functions.]
Description [External procedures included in this module:
<ul>
<li> Cudd_DumpBlif()
<li> Cudd_DumpBlifBody()
<li> Cudd_DumpDot()
<li> Cudd_DumpDaVinci()
<li> Cudd_DumpDDcal()
<li> Cudd_DumpFactoredForm()
</ul>
Internal procedures included in this module:
<ul>
</ul>
Static procedures included in this module:
<ul>
<li> ddDoDumpBlif()
<li> ddDoDumpDaVinci()
<li> ddDoDumpDDcal()
<li> ddDoDumpFactoredForm()
</ul>]
Author [Fabio Somenzi]
Copyright [Copyright (c) 1995-2004, Regents of the University of Colorado
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 University of Colorado 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 "misc/util/util_hack.h"
#include "cuddInt.h"
ABC_NAMESPACE_IMPL_START
/*---------------------------------------------------------------------------*/
/* Constant declarations */
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/* Stucture declarations */
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/* Type declarations */
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/* Variable declarations */
/*---------------------------------------------------------------------------*/
#ifndef lint
static char rcsid[] DD_UNUSED = "$Id: cuddExport.c,v 1.22 2009/03/08 02:49:02 fabio Exp $";
#endif
/*---------------------------------------------------------------------------*/
/* Macro declarations */
/*---------------------------------------------------------------------------*/
/**AutomaticStart*************************************************************/
/*---------------------------------------------------------------------------*/
/* Static function prototypes */
/*---------------------------------------------------------------------------*/
static int ddDoDumpBlif (DdManager *dd, DdNode *f, FILE *fp, st__table *visited, char **names, int mv);
static int ddDoDumpDaVinci (DdManager *dd, DdNode *f, FILE *fp, st__table *visited, char **names, ptruint mask);
static int ddDoDumpDDcal (DdManager *dd, DdNode *f, FILE *fp, st__table *visited, char **names, ptruint mask);
static int ddDoDumpFactoredForm (DdManager *dd, DdNode *f, FILE *fp, char **names);
/**AutomaticEnd***************************************************************/
/*---------------------------------------------------------------------------*/
/* Definition of exported functions */
/*---------------------------------------------------------------------------*/
/**Function********************************************************************
Synopsis [Writes a blif file representing the argument BDDs.]
Description [Writes a blif file representing the argument BDDs as a
network of multiplexers. One multiplexer is written for each BDD
node. It returns 1 in case of success; 0 otherwise (e.g.,
out-of-memory, file system full, or an ADD with constants different
from 0 and 1). Cudd_DumpBlif does not close the file: This is the
caller responsibility. Cudd_DumpBlif uses a minimal unique subset of
the hexadecimal address of a node as name for it. If the argument
inames is non-null, it is assumed to hold the pointers to the names
of the inputs. Similarly for onames.]
SideEffects [None]
SeeAlso [Cudd_DumpBlifBody Cudd_DumpDot Cudd_PrintDebug Cudd_DumpDDcal
Cudd_DumpDaVinci Cudd_DumpFactoredForm]
******************************************************************************/
int
Cudd_DumpBlif(
DdManager * dd /* manager */,
int n /* number of output nodes to be dumped */,
DdNode ** f /* array of output nodes to be dumped */,
char ** inames /* array of input names (or NULL) */,
char ** onames /* array of output names (or NULL) */,
char * mname /* model name (or NULL) */,
FILE * fp /* pointer to the dump file */,
int mv /* 0: blif, 1: blif-MV */)
{
DdNode *support = NULL;
DdNode *scan;
int *sorted = NULL;
int nvars = dd->size;
int retval;
int i;
/* Build a bit array with the support of f. */
sorted = ABC_ALLOC(int,nvars);
if (sorted == NULL) {
dd->errorCode = CUDD_MEMORY_OUT;
goto failure;
}
for (i = 0; i < nvars; i++) sorted[i] = 0;
/* Take the union of the supports of each output function. */
support = Cudd_VectorSupport(dd,f,n);
if (support == NULL) goto failure;
cuddRef(support);
scan = support;
while (!cuddIsConstant(scan)) {
sorted[scan->index] = 1;
scan = cuddT(scan);
}
Cudd_RecursiveDeref(dd,support);
support = NULL; /* so that we do not try to free it in case of failure */
/* Write the header (.model .inputs .outputs). */
if (mname == NULL) {
retval = fprintf(fp,".model DD\n.inputs");
} else {
retval = fprintf(fp,".model %s\n.inputs",mname);
}
if (retval == EOF) {
ABC_FREE(sorted);
return(0);
}
/* Write the input list by scanning the support array. */
for (i = 0; i < nvars; i++) {
if (sorted[i]) {
if (inames == NULL) {
retval = fprintf(fp," %d", i);
} else {
retval = fprintf(fp," %s", inames[i]);
}
if (retval == EOF) goto failure;
}
}
ABC_FREE(sorted);
sorted = NULL;
/* Write the .output line. */
retval = fprintf(fp,"\n.outputs");
if (retval == EOF) goto failure;
for (i = 0; i < n; i++) {
if (onames == NULL) {
retval = fprintf(fp," f%d", i);
} else {
retval = fprintf(fp," %s", onames[i]);
}
if (retval == EOF) goto failure;
}
retval = fprintf(fp,"\n");
if (retval == EOF) goto failure;
retval = Cudd_DumpBlifBody(dd, n, f, inames, onames, fp, mv);
if (retval == 0) goto failure;
/* Write trailer and return. */
retval = fprintf(fp,".end\n");
if (retval == EOF) goto failure;
return(1);
failure:
if (sorted != NULL) ABC_FREE(sorted);
if (support != NULL) Cudd_RecursiveDeref(dd,support);
return(0);
} /* end of Cudd_DumpBlif */
/**Function********************************************************************
Synopsis [Writes a blif body representing the argument BDDs.]
Description [Writes a blif body representing the argument BDDs as a
network of multiplexers. No header (.model, .inputs, and .outputs) and
footer (.end) are produced by this function. One multiplexer is written
for each BDD node. It returns 1 in case of success; 0 otherwise (e.g.,
out-of-memory, file system full, or an ADD with constants different
from 0 and 1). Cudd_DumpBlifBody does not close the file: This is the
caller responsibility. Cudd_DumpBlifBody uses a minimal unique subset of
the hexadecimal address of a node as name for it. If the argument
inames is non-null, it is assumed to hold the pointers to the names
of the inputs. Similarly for onames. This function prints out only
.names part.]
SideEffects [None]
SeeAlso [Cudd_DumpBlif Cudd_DumpDot Cudd_PrintDebug Cudd_DumpDDcal
Cudd_DumpDaVinci Cudd_DumpFactoredForm]
******************************************************************************/
int
Cudd_DumpBlifBody(
DdManager * dd /* manager */,
int n /* number of output nodes to be dumped */,
DdNode ** f /* array of output nodes to be dumped */,
char ** inames /* array of input names (or NULL) */,
char ** onames /* array of output names (or NULL) */,
FILE * fp /* pointer to the dump file */,
int mv /* 0: blif, 1: blif-MV */)
{
st__table *visited = NULL;
int retval;
int i;
/* Initialize symbol table for visited nodes. */
visited = st__init_table( st__ptrcmp, st__ptrhash);
if (visited == NULL) goto failure;
/* Call the function that really gets the job done. */
for (i = 0; i < n; i++) {
retval = ddDoDumpBlif(dd,Cudd_Regular(f[i]),fp,visited,inames,mv);
if (retval == 0) goto failure;
}
/* To account for the possible complement on the root,
** we put either a buffer or an inverter at the output of
** the multiplexer representing the top node.
*/
for (i = 0; i < n; i++) {
if (onames == NULL) {
retval = fprintf(fp,
#if SIZEOF_VOID_P == 8
".names %lx f%d\n", (ptruint) f[i] / (ptruint) sizeof(DdNode), i);
#else
".names %x f%d\n", (ptruint) f[i] / (ptruint) sizeof(DdNode), i);
#endif
} else {
retval = fprintf(fp,
#if SIZEOF_VOID_P == 8
".names %lx %s\n", (ptruint) f[i] / (ptruint) sizeof(DdNode), onames[i]);
#else
".names %x %s\n", (ptruint) f[i] / (ptruint) sizeof(DdNode), onames[i]);
#endif
}
if (retval == EOF) goto failure;
if (Cudd_IsComplement(f[i])) {
retval = fprintf(fp,"%s0 1\n", mv ? ".def 0\n" : "");
} else {
retval = fprintf(fp,"%s1 1\n", mv ? ".def 0\n" : "");
}
if (retval == EOF) goto failure;
}
st__free_table(visited);
return(1);
failure:
if (visited != NULL) st__free_table(visited);
return(0);
} /* end of Cudd_DumpBlifBody */
/**Function********************************************************************
Synopsis [Writes a dot file representing the argument DDs.]
Description [Writes a file representing the argument DDs in a format
suitable for the graph drawing program dot.
It returns 1 in case of success; 0 otherwise (e.g., out-of-memory,
file system full).
Cudd_DumpDot does not close the file: This is the caller
responsibility. Cudd_DumpDot uses a minimal unique subset of the
hexadecimal address of a node as name for it.
If the argument inames is non-null, it is assumed to hold the pointers
to the names of the inputs. Similarly for onames.
Cudd_DumpDot uses the following convention to draw arcs:
<ul>
<li> solid line: THEN arcs;
<li> dotted line: complement arcs;
<li> dashed line: regular ELSE arcs.
</ul>
The dot options are chosen so that the drawing fits on a letter-size
sheet.
]
SideEffects [None]
SeeAlso [Cudd_DumpBlif Cudd_PrintDebug Cudd_DumpDDcal
Cudd_DumpDaVinci Cudd_DumpFactoredForm]
******************************************************************************/
int
Cudd_DumpDot(
DdManager * dd /* manager */,
int n /* number of output nodes to be dumped */,
DdNode ** f /* array of output nodes to be dumped */,
char ** inames /* array of input names (or NULL) */,
char ** onames /* array of output names (or NULL) */,
FILE * fp /* pointer to the dump file */)
{
DdNode *support = NULL;
DdNode *scan;
int *sorted = NULL;
int nvars = dd->size;
st__table *visited = NULL;
st__generator *gen = NULL;
int retval;
int i, j;
int slots;
DdNodePtr *nodelist;
long refAddr, diff, mask;
/* Build a bit array with the support of f. */
sorted = ABC_ALLOC(int,nvars);
if (sorted == NULL) {
dd->errorCode = CUDD_MEMORY_OUT;
goto failure;
}
for (i = 0; i < nvars; i++) sorted[i] = 0;
/* Take the union of the supports of each output function. */
support = Cudd_VectorSupport(dd,f,n);
if (support == NULL) goto failure;
cuddRef(support);
scan = support;
while (!cuddIsConstant(scan)) {
sorted[scan->index] = 1;
scan = cuddT(scan);
}
Cudd_RecursiveDeref(dd,support);
support = NULL; /* so that we do not try to free it in case of failure */
/* Initialize symbol table for visited nodes. */
visited = st__init_table( st__ptrcmp, st__ptrhash);
if (visited == NULL) goto failure;
/* Collect all the nodes of this DD in the symbol table. */
for (i = 0; i < n; i++) {
retval = cuddCollectNodes(Cudd_Regular(f[i]),visited);
if (retval == 0) goto failure;
}
/* Find how many most significant hex digits are identical
** in the addresses of all the nodes. Build a mask based
** on this knowledge, so that digits that carry no information
** will not be printed. This is done in two steps.
** 1. We scan the symbol table to find the bits that differ
** in at least 2 addresses.
** 2. We choose one of the possible masks. There are 8 possible
** masks for 32-bit integer, and 16 possible masks for 64-bit
** integers.
*/
/* Find the bits that are different. */
refAddr = (long) Cudd_Regular(f[0]);
diff = 0;
gen = st__init_gen(visited);
if (gen == NULL) goto failure;
while ( st__gen(gen, (const char **)&scan, NULL)) {
diff |= refAddr ^ (long) scan;
}
st__free_gen(gen); gen = NULL;
/* Choose the mask. */
for (i = 0; (unsigned) i < 8 * sizeof(long); i += 4) {
mask = (1 << i) - 1;
if (diff <= mask) break;
}
/* Write the header and the global attributes. */
retval = fprintf(fp,"digraph \"DD\" {\n");
if (retval == EOF) return(0);
retval = fprintf(fp,
"size = \"7.5,10\"\ncenter = true;\nedge [dir = none];\n");
if (retval == EOF) return(0);
/* Write the input name subgraph by scanning the support array. */
retval = fprintf(fp,"{ node [shape = plaintext];\n");
if (retval == EOF) goto failure;
retval = fprintf(fp," edge [style = invis];\n");
if (retval == EOF) goto failure;
/* We use a name ("CONST NODES") with an embedded blank, because
** it is unlikely to appear as an input name.
*/
retval = fprintf(fp," \"CONST NODES\" [style = invis];\n");
if (retval == EOF) goto failure;
for (i = 0; i < nvars; i++) {
if (sorted[dd->invperm[i]]) {
if (inames == NULL || inames[dd->invperm[i]] == NULL) {
retval = fprintf(fp,"\" %d \" -> ", dd->invperm[i]);
} else {
retval = fprintf(fp,"\" %s \" -> ", inames[dd->invperm[i]]);
}
if (retval == EOF) goto failure;
}
}
retval = fprintf(fp,"\"CONST NODES\"; \n}\n");
if (retval == EOF) goto failure;
/* Write the output node subgraph. */
retval = fprintf(fp,"{ rank = same; node [shape = box]; edge [style = invis];\n");
if (retval == EOF) goto failure;
for (i = 0; i < n; i++) {
if (onames == NULL) {
retval = fprintf(fp,"\"F%d\"", i);
} else {
retval = fprintf(fp,"\" %s \"", onames[i]);
}
if (retval == EOF) goto failure;
if (i == n - 1) {
retval = fprintf(fp,"; }\n");
} else {
retval = fprintf(fp," -> ");
}
if (retval == EOF) goto failure;
}
/* Write rank info: All nodes with the same index have the same rank. */
for (i = 0; i < nvars; i++) {
if (sorted[dd->invperm[i]]) {
retval = fprintf(fp,"{ rank = same; ");
if (retval == EOF) goto failure;
if (inames == NULL || inames[dd->invperm[i]] == NULL) {
retval = fprintf(fp,"\" %d \";\n", dd->invperm[i]);
} else {
retval = fprintf(fp,"\" %s \";\n", inames[dd->invperm[i]]);
}
if (retval == EOF) goto failure;
nodelist = dd->subtables[i].nodelist;
slots = dd->subtables[i].slots;
for (j = 0; j < slots; j++) {
scan = nodelist[j];
while (scan != NULL) {
if ( st__is_member(visited,(char *) scan)) {
retval = fprintf(fp,"\"%lx\";\n", ((mask & (ptrint) scan) / sizeof(DdNode)));
if (retval == EOF) goto failure;
}
scan = scan->next;
}
}
retval = fprintf(fp,"}\n");
if (retval == EOF) goto failure;
}
}
/* All constants have the same rank. */
retval = fprintf(fp,
"{ rank = same; \"CONST NODES\";\n{ node [shape = box]; ");
if (retval == EOF) goto failure;
nodelist = dd->constants.nodelist;
slots = dd->constants.slots;
for (j = 0; j < slots; j++) {
scan = nodelist[j];
while (scan != NULL) {
if ( st__is_member(visited,(char *) scan)) {
retval = fprintf(fp,"\"%lx\";\n", ((mask & (ptrint) scan) / sizeof(DdNode)));
if (retval == EOF) goto failure;
}
scan = scan->next;
}
}
retval = fprintf(fp,"}\n}\n");
if (retval == EOF) goto failure;
/* Write edge info. */
/* Edges from the output nodes. */
for (i = 0; i < n; i++) {
if (onames == NULL) {
retval = fprintf(fp,"\"F%d\"", i);
} else {
retval = fprintf(fp,"\" %s \"", onames[i]);
}
if (retval == EOF) goto failure;
/* Account for the possible complement on the root. */
if (Cudd_IsComplement(f[i])) {
retval = fprintf(fp," -> \"%lx\" [style = dotted];\n", ((mask & (ptrint) f[i]) / sizeof(DdNode)));
} else {
retval = fprintf(fp," -> \"%lx\" [style = solid];\n", ((mask & (ptrint) f[i]) / sizeof(DdNode)));
}
if (retval == EOF) goto failure;
}
/* Edges from internal nodes. */
for (i = 0; i < nvars; i++) {
if (sorted[dd->invperm[i]]) {
nodelist = dd->subtables[i].nodelist;
slots = dd->subtables[i].slots;
for (j = 0; j < slots; j++) {
scan = nodelist[j];
while (scan != NULL) {
if ( st__is_member(visited,(char *) scan)) {
retval = fprintf(fp, "\"%lx\" -> \"%lx\";\n",
((mask & (ptrint) scan) / sizeof(DdNode)),
((mask & (ptrint) cuddT(scan)) / sizeof(DdNode)));
if (retval == EOF) goto failure;
if (Cudd_IsComplement(cuddE(scan))) {
retval = fprintf(fp,"\"%lx\" -> \"%lx\" [style = dotted];\n",
((mask & (ptrint) scan) / sizeof(DdNode)),
((mask & (ptrint) cuddE(scan)) / sizeof(DdNode)));
} else {
retval = fprintf(fp, "\"%lx\" -> \"%lx\" [style = dashed];\n",
((mask & (ptrint) scan) / sizeof(DdNode)),
((mask & (ptrint) cuddE(scan)) / sizeof(DdNode)));
}
if (retval == EOF) goto failure;
}
scan = scan->next;
}
}
}
}
/* Write constant labels. */
nodelist = dd->constants.nodelist;
slots = dd->constants.slots;
for (j = 0; j < slots; j++) {
scan = nodelist[j];
while (scan != NULL) {
if ( st__is_member(visited,(char *) scan)) {
retval = fprintf(fp,"\"%lx\" [label = \"%g\"];\n",
((mask & (ptrint) scan) / sizeof(DdNode)), cuddV(scan));
if (retval == EOF) goto failure;
}
scan = scan->next;
}
}
/* Write trailer and return. */
retval = fprintf(fp,"}\n");
if (retval == EOF) goto failure;
st__free_table(visited);
ABC_FREE(sorted);
return(1);
failure:
if (sorted != NULL) ABC_FREE(sorted);
if (support != NULL) Cudd_RecursiveDeref(dd,support);
if (visited != NULL) st__free_table(visited);
return(0);
} /* end of Cudd_DumpDot */
/**Function********************************************************************
Synopsis [Writes a daVinci file representing the argument BDDs.]
Description [Writes a daVinci file representing the argument BDDs.
It returns 1 in case of success; 0 otherwise (e.g., out-of-memory or
file system full). Cudd_DumpDaVinci does not close the file: This
is the caller responsibility. Cudd_DumpDaVinci uses a minimal unique
subset of the hexadecimal address of a node as name for it. If the
argument inames is non-null, it is assumed to hold the pointers to
the names of the inputs. Similarly for onames.]
SideEffects [None]
SeeAlso [Cudd_DumpDot Cudd_PrintDebug Cudd_DumpBlif Cudd_DumpDDcal
Cudd_DumpFactoredForm]
******************************************************************************/
int
Cudd_DumpDaVinci(
DdManager * dd /* manager */,
int n /* number of output nodes to be dumped */,
DdNode ** f /* array of output nodes to be dumped */,
char ** inames /* array of input names (or NULL) */,
char ** onames /* array of output names (or NULL) */,
FILE * fp /* pointer to the dump file */)
{
DdNode *support = NULL;
DdNode *scan;
st__table *visited = NULL;
int retval;
int i;
st__generator *gen;
ptruint refAddr, diff, mask;
/* Initialize symbol table for visited nodes. */
visited = st__init_table( st__ptrcmp, st__ptrhash);
if (visited == NULL) goto failure;
/* Collect all the nodes of this DD in the symbol table. */
for (i = 0; i < n; i++) {
retval = cuddCollectNodes(Cudd_Regular(f[i]),visited);
if (retval == 0) goto failure;
}
/* Find how many most significant hex digits are identical
** in the addresses of all the nodes. Build a mask based
** on this knowledge, so that digits that carry no information
** will not be printed. This is done in two steps.
** 1. We scan the symbol table to find the bits that differ
** in at least 2 addresses.
** 2. We choose one of the possible masks. There are 8 possible
** masks for 32-bit integer, and 16 possible masks for 64-bit
** integers.
*/
/* Find the bits that are different. */
refAddr = (ptruint) Cudd_Regular(f[0]);
diff = 0;
gen = st__init_gen(visited);
while ( st__gen(gen, (const char **)&scan, NULL)) {
diff |= refAddr ^ (ptruint) scan;
}
st__free_gen(gen);
/* Choose the mask. */
for (i = 0; (unsigned) i < 8 * sizeof(ptruint); i += 4) {
mask = (1 << i) - 1;
if (diff <= mask) break;
}
st__free_table(visited);
/* Initialize symbol table for visited nodes. */
visited = st__init_table( st__ptrcmp, st__ptrhash);
if (visited == NULL) goto failure;
retval = fprintf(fp, "[");
if (retval == EOF) goto failure;
/* Call the function that really gets the job done. */
for (i = 0; i < n; i++) {
if (onames == NULL) {
retval = fprintf(fp,
"l(\"f%d\",n(\"root\",[a(\"OBJECT\",\"f%d\")],",
i,i);
} else {
retval = fprintf(fp,
"l(\"%s\",n(\"root\",[a(\"OBJECT\",\"%s\")],",
onames[i], onames[i]);
}
if (retval == EOF) goto failure;
retval = fprintf(fp, "[e(\"edge\",[a(\"EDGECOLOR\",\"%s\"),a(\"_DIR\",\"none\")],",
Cudd_IsComplement(f[i]) ? "red" : "blue");
if (retval == EOF) goto failure;
retval = ddDoDumpDaVinci(dd,Cudd_Regular(f[i]),fp,visited,inames,mask);
if (retval == 0) goto failure;
retval = fprintf(fp, ")]))%s", i == n-1 ? "" : ",");
if (retval == EOF) goto failure;
}
/* Write trailer and return. */
retval = fprintf(fp, "]\n");
if (retval == EOF) goto failure;
st__free_table(visited);
return(1);
failure:
if (support != NULL) Cudd_RecursiveDeref(dd,support);
if (visited != NULL) st__free_table(visited);
return(0);
} /* end of Cudd_DumpDaVinci */
/**Function********************************************************************
Synopsis [Writes a DDcal file representing the argument BDDs.]
Description [Writes a DDcal file representing the argument BDDs.
It returns 1 in case of success; 0 otherwise (e.g., out-of-memory or
file system full). Cudd_DumpDDcal does not close the file: This
is the caller responsibility. Cudd_DumpDDcal uses a minimal unique
subset of the hexadecimal address of a node as name for it. If the
argument inames is non-null, it is assumed to hold the pointers to
the names of the inputs. Similarly for onames.]
SideEffects [None]
SeeAlso [Cudd_DumpDot Cudd_PrintDebug Cudd_DumpBlif Cudd_DumpDaVinci
Cudd_DumpFactoredForm]
******************************************************************************/
int
Cudd_DumpDDcal(
DdManager * dd /* manager */,
int n /* number of output nodes to be dumped */,
DdNode ** f /* array of output nodes to be dumped */,
char ** inames /* array of input names (or NULL) */,
char ** onames /* array of output names (or NULL) */,
FILE * fp /* pointer to the dump file */)
{
DdNode *support = NULL;
DdNode *scan;
int *sorted = NULL;
int nvars = dd->size;
st__table *visited = NULL;
int retval;
int i;
st__generator *gen;
ptruint refAddr, diff, mask;
/* Initialize symbol table for visited nodes. */
visited = st__init_table( st__ptrcmp, st__ptrhash);
if (visited == NULL) goto failure;
/* Collect all the nodes of this DD in the symbol table. */
for (i = 0; i < n; i++) {
retval = cuddCollectNodes(Cudd_Regular(f[i]),visited);
if (retval == 0) goto failure;
}
/* Find how many most significant hex digits are identical
** in the addresses of all the nodes. Build a mask based
** on this knowledge, so that digits that carry no information
** will not be printed. This is done in two steps.
** 1. We scan the symbol table to find the bits that differ
** in at least 2 addresses.
** 2. We choose one of the possible masks. There are 8 possible
** masks for 32-bit integer, and 16 possible masks for 64-bit
** integers.
*/
/* Find the bits that are different. */
refAddr = (ptruint) Cudd_Regular(f[0]);
diff = 0;
gen = st__init_gen(visited);
while ( st__gen(gen, (const char **)&scan, NULL)) {
diff |= refAddr ^ (ptruint) scan;
}
st__free_gen(gen);
/* Choose the mask. */
for (i = 0; (unsigned) i < 8 * sizeof(ptruint); i += 4) {
mask = (1 << i) - 1;
if (diff <= mask) break;
}
st__free_table(visited);
visited = NULL;
/* Build a bit array with the support of f. */
sorted = ABC_ALLOC(int,nvars);
if (sorted == NULL) {
dd->errorCode = CUDD_MEMORY_OUT;
goto failure;
}
for (i = 0; i < nvars; i++) sorted[i] = 0;
/* Take the union of the supports of each output function. */
support = Cudd_VectorSupport(dd,f,n);
if (support == NULL) goto failure;
cuddRef(support);
scan = support;
while (!cuddIsConstant(scan)) {
sorted[scan->index] = 1;
scan = cuddT(scan);
}
Cudd_RecursiveDeref(dd,support);
support = NULL; /* so that we do not try to free it in case of failure */
for (i = 0; i < nvars; i++) {
if (sorted[dd->invperm[i]]) {
if (inames == NULL || inames[dd->invperm[i]] == NULL) {
retval = fprintf(fp,"v%d", dd->invperm[i]);
} else {
retval = fprintf(fp,"%s", inames[dd->invperm[i]]);
}
if (retval == EOF) goto failure;
}
retval = fprintf(fp,"%s", i == nvars - 1 ? "\n" : " * ");
if (retval == EOF) goto failure;
}
ABC_FREE(sorted);
sorted = NULL;
/* Initialize symbol table for visited nodes. */
visited = st__init_table( st__ptrcmp, st__ptrhash);
if (visited == NULL) goto failure;
/* Call the function that really gets the job done. */
for (i = 0; i < n; i++) {
retval = ddDoDumpDDcal(dd,Cudd_Regular(f[i]),fp,visited,inames,mask);
if (retval == 0) goto failure;
if (onames == NULL) {
retval = fprintf(fp, "f%d = ", i);
} else {
retval = fprintf(fp, "%s = ", onames[i]);
}
if (retval == EOF) goto failure;
retval = fprintf(fp, "n%p%s\n",
(void *) (((ptruint) f[i] & mask) /
(ptruint) sizeof(DdNode)),
Cudd_IsComplement(f[i]) ? "'" : "");
if (retval == EOF) goto failure;
}
/* Write trailer and return. */
retval = fprintf(fp, "[");
if (retval == EOF) goto failure;
for (i = 0; i < n; i++) {
if (onames == NULL) {
retval = fprintf(fp, "f%d", i);
} else {
retval = fprintf(fp, "%s", onames[i]);
}
retval = fprintf(fp, "%s", i == n-1 ? "" : " ");
if (retval == EOF) goto failure;
}
retval = fprintf(fp, "]\n");
if (retval == EOF) goto failure;
if ( visited )
st__free_table(visited);
return(1);
failure:
if (sorted != NULL) ABC_FREE(sorted);
if (support != NULL) Cudd_RecursiveDeref(dd,support);
if (visited != NULL) st__free_table(visited);
return(0);
} /* end of Cudd_DumpDDcal */
/**Function********************************************************************
Synopsis [Writes factored forms representing the argument BDDs.]
Description [Writes factored forms representing the argument BDDs.
The format of the factored form is the one used in the genlib files
for technology mapping in sis. It returns 1 in case of success; 0
otherwise (e.g., file system full). Cudd_DumpFactoredForm does not
close the file: This is the caller responsibility. Caution must be
exercised because a factored form may be exponentially larger than
the argument BDD. If the argument inames is non-null, it is assumed
to hold the pointers to the names of the inputs. Similarly for
onames.]
SideEffects [None]
SeeAlso [Cudd_DumpDot Cudd_PrintDebug Cudd_DumpBlif Cudd_DumpDaVinci
Cudd_DumpDDcal]
******************************************************************************/
int
Cudd_DumpFactoredForm(
DdManager * dd /* manager */,
int n /* number of output nodes to be dumped */,
DdNode ** f /* array of output nodes to be dumped */,
char ** inames /* array of input names (or NULL) */,
char ** onames /* array of output names (or NULL) */,
FILE * fp /* pointer to the dump file */)
{
int retval;
int i;
/* Call the function that really gets the job done. */
for (i = 0; i < n; i++) {
if (onames == NULL) {
retval = fprintf(fp, "f%d = ", i);
} else {
retval = fprintf(fp, "%s = ", onames[i]);
}
if (retval == EOF) return(0);
if (f[i] == DD_ONE(dd)) {
retval = fprintf(fp, "CONST1");
if (retval == EOF) return(0);
} else if (f[i] == Cudd_Not(DD_ONE(dd)) || f[i] == DD_ZERO(dd)) {
retval = fprintf(fp, "CONST0");
if (retval == EOF) return(0);
} else {
retval = fprintf(fp, "%s", Cudd_IsComplement(f[i]) ? "!(" : "");
if (retval == EOF) return(0);
retval = ddDoDumpFactoredForm(dd,Cudd_Regular(f[i]),fp,inames);
if (retval == 0) return(0);
retval = fprintf(fp, "%s", Cudd_IsComplement(f[i]) ? ")" : "");
if (retval == EOF) return(0);
}
retval = fprintf(fp, "%s", i == n-1 ? "" : "\n");
if (retval == EOF) return(0);
}
return(1);
} /* end of Cudd_DumpFactoredForm */
/*---------------------------------------------------------------------------*/
/* Definition of internal functions */
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/* Definition of static functions */
/*---------------------------------------------------------------------------*/
/**Function********************************************************************
Synopsis [Performs the recursive step of Cudd_DumpBlif.]
Description [Performs the recursive step of Cudd_DumpBlif. Traverses
the BDD f and writes a multiplexer-network description to the file
pointed by fp in blif format. f is assumed to be a regular pointer
and ddDoDumpBlif guarantees this assumption in the recursive calls.]
SideEffects [None]
SeeAlso []
******************************************************************************/
static int
ddDoDumpBlif(
DdManager * dd,
DdNode * f,
FILE * fp,
st__table * visited,
char ** names,
int mv)
{
DdNode *T, *E;
int retval;
#ifdef DD_DEBUG
assert(!Cudd_IsComplement(f));
#endif
/* If already visited, nothing to do. */
if ( st__is_member(visited, (char *) f) == 1)
return(1);
/* Check for abnormal condition that should never happen. */
if (f == NULL)
return(0);
/* Mark node as visited. */
if ( st__insert(visited, (char *) f, NULL) == st__OUT_OF_MEM)
return(0);
/* Check for special case: If constant node, generate constant 1. */
if (f == DD_ONE(dd)) {
#if SIZEOF_VOID_P == 8
retval = fprintf(fp, ".names %lx\n1\n",(ptruint) f / (ptruint) sizeof(DdNode));
#else
retval = fprintf(fp, ".names %x\n1\n",(ptruint) f / (ptruint) sizeof(DdNode));
#endif
if (retval == EOF) {
return(0);
} else {
return(1);
}
}
/* Check whether this is an ADD. We deal with 0-1 ADDs, but not
** with the general case.
*/
if (f == DD_ZERO(dd)) {
#if SIZEOF_VOID_P == 8
retval = fprintf(fp, ".names %lx\n%s",
(ptruint) f / (ptruint) sizeof(DdNode),
mv ? "0\n" : "");
#else
retval = fprintf(fp, ".names %x\n%s",
(ptruint) f / (ptruint) sizeof(DdNode),
mv ? "0\n" : "");
#endif
if (retval == EOF) {
return(0);
} else {
return(1);
}
}
if (cuddIsConstant(f))
return(0);
/* Recursive calls. */
T = cuddT(f);
retval = ddDoDumpBlif(dd,T,fp,visited,names,mv);
if (retval != 1) return(retval);
E = Cudd_Regular(cuddE(f));
retval = ddDoDumpBlif(dd,E,fp,visited,names,mv);
if (retval != 1) return(retval);
/* Write multiplexer taking complement arc into account. */
if (names != NULL) {
retval = fprintf(fp,".names %s", names[f->index]);
} else {
#if SIZEOF_VOID_P == 8 && SIZEOF_INT == 4
retval = fprintf(fp,".names %u", f->index);
#else
retval = fprintf(fp,".names %hu", f->index);
#endif
}
if (retval == EOF)
return(0);
#if SIZEOF_VOID_P == 8
if (mv) {
if (Cudd_IsComplement(cuddE(f))) {
retval = fprintf(fp," %lx %lx %lx\n.def 0\n1 1 - 1\n0 - 0 1\n",
(ptruint) T / (ptruint) sizeof(DdNode),
(ptruint) E / (ptruint) sizeof(DdNode),
(ptruint) f / (ptruint) sizeof(DdNode));
} else {
retval = fprintf(fp," %lx %lx %lx\n.def 0\n1 1 - 1\n0 - 1 1\n",
(ptruint) T / (ptruint) sizeof(DdNode),
(ptruint) E / (ptruint) sizeof(DdNode),
(ptruint) f / (ptruint) sizeof(DdNode));
}
} else {
if (Cudd_IsComplement(cuddE(f))) {
retval = fprintf(fp," %lx %lx %lx\n11- 1\n0-0 1\n",
(ptruint) T / (ptruint) sizeof(DdNode),
(ptruint) E / (ptruint) sizeof(DdNode),
(ptruint) f / (ptruint) sizeof(DdNode));
} else {
retval = fprintf(fp," %lx %lx %lx\n11- 1\n0-1 1\n",
(ptruint) T / (ptruint) sizeof(DdNode),
(ptruint) E / (ptruint) sizeof(DdNode),
(ptruint) f / (ptruint) sizeof(DdNode));
}
}
#else
if (mv) {
if (Cudd_IsComplement(cuddE(f))) {
retval = fprintf(fp," %x %x %x\n.def 0\n1 1 - 1\n0 - 0 1\n",
(ptruint) T / (ptruint) sizeof(DdNode),
(ptruint) E / (ptruint) sizeof(DdNode),
(ptruint) f / (ptruint) sizeof(DdNode));
} else {
retval = fprintf(fp," %x %x %x\n.def 0\n1 1 - 1\n0 - 1 1\n",
(ptruint) T / (ptruint) sizeof(DdNode),
(ptruint) E / (ptruint) sizeof(DdNode),
(ptruint) f / (ptruint) sizeof(DdNode));
}
} else {
if (Cudd_IsComplement(cuddE(f))) {
retval = fprintf(fp," %x %x %x\n11- 1\n0-0 1\n",
(ptruint) T / (ptruint) sizeof(DdNode),
(ptruint) E / (ptruint) sizeof(DdNode),
(ptruint) f / (ptruint) sizeof(DdNode));
} else {
retval = fprintf(fp," %x %x %x\n11- 1\n0-1 1\n",
(ptruint) T / (ptruint) sizeof(DdNode),
(ptruint) E / (ptruint) sizeof(DdNode),
(ptruint) f / (ptruint) sizeof(DdNode));
}
}
#endif
if (retval == EOF) {
return(0);
} else {
return(1);
}
} /* end of ddDoDumpBlif */
/**Function********************************************************************
Synopsis [Performs the recursive step of Cudd_DumpDaVinci.]
Description [Performs the recursive step of Cudd_DumpDaVinci. Traverses
the BDD f and writes a term expression to the file
pointed by fp in daVinci format. f is assumed to be a regular pointer
and ddDoDumpDaVinci guarantees this assumption in the recursive calls.]
SideEffects [None]
SeeAlso []
******************************************************************************/
static int
ddDoDumpDaVinci(
DdManager * dd,
DdNode * f,
FILE * fp,
st__table * visited,
char ** names,
ptruint mask)
{
DdNode *T, *E;
int retval;
ptruint id;
#ifdef DD_DEBUG
assert(!Cudd_IsComplement(f));
#endif
id = ((ptruint) f & mask) / sizeof(DdNode);
/* If already visited, insert a reference. */
if ( st__is_member(visited, (char *) f) == 1) {
retval = fprintf(fp,"r(\"%p\")", (void *) id);
if (retval == EOF) {
return(0);
} else {
return(1);
}
}
/* Check for abnormal condition that should never happen. */
if (f == NULL)
return(0);
/* Mark node as visited. */
if ( st__insert(visited, (char *) f, NULL) == st__OUT_OF_MEM)
return(0);
/* Check for special case: If constant node, generate constant 1. */
if (Cudd_IsConstant(f)) {
retval = fprintf(fp,
"l(\"%p\",n(\"constant\",[a(\"OBJECT\",\"%g\")],[]))",
(void *) id, cuddV(f));
if (retval == EOF) {
return(0);
} else {
return(1);
}
}
/* Recursive calls. */
if (names != NULL) {
retval = fprintf(fp,
"l(\"%p\",n(\"internal\",[a(\"OBJECT\",\"%s\"),",
(void *) id, names[f->index]);
} else {
retval = fprintf(fp,
#if SIZEOF_VOID_P == 8
"l(\"%p\",n(\"internal\",[a(\"OBJECT\",\"%u\"),",
#else
"l(\"%p\",n(\"internal\",[a(\"OBJECT\",\"%hu\"),",
#endif
(void *) id, f->index);
}
retval = fprintf(fp, "a(\"_GO\",\"ellipse\")],[e(\"then\",[a(\"EDGECOLOR\",\"blue\"),a(\"_DIR\",\"none\")],");
if (retval == EOF) return(0);
T = cuddT(f);
retval = ddDoDumpDaVinci(dd,T,fp,visited,names,mask);
if (retval != 1) return(retval);
retval = fprintf(fp, "),e(\"else\",[a(\"EDGECOLOR\",\"%s\"),a(\"_DIR\",\"none\")],",
Cudd_IsComplement(cuddE(f)) ? "red" : "green");
if (retval == EOF) return(0);
E = Cudd_Regular(cuddE(f));
retval = ddDoDumpDaVinci(dd,E,fp,visited,names,mask);
if (retval != 1) return(retval);
retval = fprintf(fp,")]))");
if (retval == EOF) {
return(0);
} else {
return(1);
}
} /* end of ddDoDumpDaVinci */
/**Function********************************************************************
Synopsis [Performs the recursive step of Cudd_DumpDDcal.]
Description [Performs the recursive step of Cudd_DumpDDcal. Traverses
the BDD f and writes a line for each node to the file
pointed by fp in DDcal format. f is assumed to be a regular pointer
and ddDoDumpDDcal guarantees this assumption in the recursive calls.]
SideEffects [None]
SeeAlso []
******************************************************************************/
static int
ddDoDumpDDcal(
DdManager * dd,
DdNode * f,
FILE * fp,
st__table * visited,
char ** names,
ptruint mask)
{
DdNode *T, *E;
int retval;
ptruint id, idT, idE;
#ifdef DD_DEBUG
assert(!Cudd_IsComplement(f));
#endif
id = ((ptruint) f & mask) / sizeof(DdNode);
/* If already visited, do nothing. */
if ( st__is_member(visited, (char *) f) == 1) {
return(1);
}
/* Check for abnormal condition that should never happen. */
if (f == NULL)
return(0);
/* Mark node as visited. */
if ( st__insert(visited, (char *) f, NULL) == st__OUT_OF_MEM)
return(0);
/* Check for special case: If constant node, assign constant. */
if (Cudd_IsConstant(f)) {
if (f != DD_ONE(dd) && f != DD_ZERO(dd))
return(0);
retval = fprintf(fp, "n%p = %g\n", (void *) id, cuddV(f));
if (retval == EOF) {
return(0);
} else {
return(1);
}
}
/* Recursive calls. */
T = cuddT(f);
retval = ddDoDumpDDcal(dd,T,fp,visited,names,mask);
if (retval != 1) return(retval);
E = Cudd_Regular(cuddE(f));
retval = ddDoDumpDDcal(dd,E,fp,visited,names,mask);
if (retval != 1) return(retval);
idT = ((ptruint) T & mask) / sizeof(DdNode);
idE = ((ptruint) E & mask) / sizeof(DdNode);
if (names != NULL) {
retval = fprintf(fp, "n%p = %s * n%p + %s' * n%p%s\n",
(void *) id, names[f->index],
(void *) idT, names[f->index],
(void *) idE, Cudd_IsComplement(cuddE(f)) ? "'" : "");
} else {
#if SIZEOF_VOID_P == 8
retval = fprintf(fp, "n%p = v%u * n%p + v%u' * n%p%s\n",
#else
retval = fprintf(fp, "n%p = v%hu * n%p + v%hu' * n%p%s\n",
#endif
(void *) id, f->index,
(void *) idT, f->index,
(void *) idE, Cudd_IsComplement(cuddE(f)) ? "'" : "");
}
if (retval == EOF) {
return(0);
} else {
return(1);
}
} /* end of ddDoDumpDDcal */
/**Function********************************************************************
Synopsis [Performs the recursive step of Cudd_DumpFactoredForm.]
Description [Performs the recursive step of
Cudd_DumpFactoredForm. Traverses the BDD f and writes a factored
form for each node to the file pointed by fp in terms of the
factored forms of the children. Constants are propagated, and
absorption is applied. f is assumed to be a regular pointer and
ddDoDumpFActoredForm guarantees this assumption in the recursive
calls.]
SideEffects [None]
SeeAlso [Cudd_DumpFactoredForm]
******************************************************************************/
static int
ddDoDumpFactoredForm(
DdManager * dd,
DdNode * f,
FILE * fp,
char ** names)
{
DdNode *T, *E;
int retval;
#ifdef DD_DEBUG
assert(!Cudd_IsComplement(f));
assert(!Cudd_IsConstant(f));
#endif
/* Check for abnormal condition that should never happen. */
if (f == NULL)
return(0);
/* Recursive calls. */
T = cuddT(f);
E = cuddE(f);
if (T != DD_ZERO(dd)) {
if (E != DD_ONE(dd)) {
if (names != NULL) {
retval = fprintf(fp, "%s", names[f->index]);
} else {
#if SIZEOF_VOID_P == 8 && SIZEOF_INT == 4
retval = fprintf(fp, "x%u", f->index);
#else
retval = fprintf(fp, "x%hu", f->index);
#endif
}
if (retval == EOF) return(0);
}
if (T != DD_ONE(dd)) {
retval = fprintf(fp, "%s(", E != DD_ONE(dd) ? " * " : "");
if (retval == EOF) return(0);
retval = ddDoDumpFactoredForm(dd,T,fp,names);
if (retval != 1) return(retval);
retval = fprintf(fp, ")");
if (retval == EOF) return(0);
}
if (E == Cudd_Not(DD_ONE(dd)) || E == DD_ZERO(dd)) return(1);
retval = fprintf(fp, " + ");
if (retval == EOF) return(0);
}
E = Cudd_Regular(E);
if (T != DD_ONE(dd)) {
if (names != NULL) {
retval = fprintf(fp, "!%s", names[f->index]);
} else {
#if SIZEOF_VOID_P == 8 && SIZEOF_INT == 4
retval = fprintf(fp, "!x%u", f->index);
#else
retval = fprintf(fp, "!x%hu", f->index);
#endif
}
if (retval == EOF) return(0);
}
if (E != DD_ONE(dd)) {
retval = fprintf(fp, "%s%s(", T != DD_ONE(dd) ? " * " : "",
E != cuddE(f) ? "!" : "");
if (retval == EOF) return(0);
retval = ddDoDumpFactoredForm(dd,E,fp,names);
if (retval != 1) return(retval);
retval = fprintf(fp, ")");
if (retval == EOF) return(0);
}
return(1);
} /* end of ddDoDumpFactoredForm */
ABC_NAMESPACE_IMPL_END
|
eda672145ef24c097eaa2715c1d290826025e423
|
3f55217e912141e04815bc8bcb6fbd5638d0896e
|
/src/common/font.h
|
923c1761744460a40241081a5707b46afb623fd1
|
[
"BSD-2-Clause"
] |
permissive
|
NREL/Radiance
|
bfbb93c99d86368ad0f27052a2a5504aeced47f8
|
2fcca99ace2f2435f32a09525ad31f2b3be3c1bc
|
refs/heads/master
| 2021-12-26T12:42:04.586614
| 2021-12-18T00:43:56
| 2021-12-18T00:43:56
| 8,210,805
| 164
| 68
|
NOASSERTION
| 2019-06-06T19:57:11
| 2013-02-15T00:47:56
|
C
|
UTF-8
|
C
| false
| false
| 1,036
|
h
|
font.h
|
/* RCSid $Id: font.h,v 2.9 2021/11/20 00:40:33 greg Exp $ */
/*
* Header file for font handling routines
*/
#ifndef _RAD_FONT_H_
#define _RAD_FONT_H_
#ifdef __cplusplus
extern "C" {
#endif
typedef unsigned char GORD;
typedef struct {
short nverts; /* number of vertices */
GORD left, right, top, bottom; /* glyph extent */
/* followed by vertex list */
} GLYPH;
#define gvlist(g) ((GORD *)((g)+1))
typedef struct font {
char name[64]; /* font file name */
struct font *next; /* next font in list */
int nref; /* number of references */
short mwidth, mheight; /* mean glyph width and height */
GLYPH *fg[256]; /* font glyphs */
} FONT;
extern int retainfonts; /* retain loaded fonts? */
extern FONT *getfont(char *fname);
extern void freefont(FONT *f);
extern int uniftext(short *sp, char *tp, FONT *f);
extern int squeeztext(short *sp, char *tp, FONT *f, int cis);
extern int proptext(short *sp, char *tp, FONT *f, int cis, int nsi);
#ifdef __cplusplus
}
#endif
#endif /* _RAD_FONT_H_ */
|
804b39bcb76ad8e2cadbc93534114bcf72eb92a8
|
fdbb74a95924e2677466614f6ab6e2bb13b2a95a
|
/libc/fmt/strtoul.c
|
af0aaf26ec62a6942636482ab5683cff41f3f07a
|
[
"ISC"
] |
permissive
|
jart/cosmopolitan
|
fb11b5658939023977060a7c6c71a74093d9cb44
|
0d748ad58e1063dd1f8560f18a0c75293b9415b7
|
refs/heads/master
| 2023-09-06T09:17:29.303607
| 2023-09-02T03:49:13
| 2023-09-02T03:50:18
| 272,457,606
| 11,887
| 435
|
ISC
| 2023-09-14T17:47:58
| 2020-06-15T14:16:13
|
C
|
UTF-8
|
C
| false
| false
| 3,360
|
c
|
strtoul.c
|
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
╞══════════════════════════════════════════════════════════════════════════════╡
│ Copyright 2020 Justine Alexandra Roberts Tunney │
│ │
│ Permission to use, copy, modify, and/or distribute this software for │
│ any purpose with or without fee is hereby granted, provided that the │
│ above copyright notice and this permission notice appear in all copies. │
│ │
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS 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, DIRECT, 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. │
╚─────────────────────────────────────────────────────────────────────────────*/
#include "libc/errno.h"
#include "libc/fmt/conv.h"
#include "libc/fmt/strtol.internal.h"
#include "libc/limits.h"
#include "libc/stdckdint.h"
#include "libc/str/str.h"
#include "libc/str/tab.internal.h"
/**
* Decodes unsigned integer from ASCII string.
*
* @param s is a non-null nul-terminated string
* @param endptr if non-null will always receive a pointer to the char
* following the last one this function processed, which is usually
* the NUL byte, or in the case of invalid strings, would point to
* the first invalid character
* @param base can be anywhere between [2,36] or 0 to auto-detect based
* on the the prefixes 0 (octal), 0x (hexadecimal), 0b (binary), or
* decimal (base 10) by default
* @return decoded integer mod 2⁶⁴ negated if leading `-`
* @raise ERANGE on overflow
*/
unsigned long strtoul(const char *s, char **endptr, int base) {
char t = 0;
int d, c = *s;
unsigned long x = 0;
CONSUME_SPACES(char, s, c);
GET_SIGN(s, c, d);
GET_RADIX(s, c, base);
if ((c = kBase36[c & 255]) && --c < base) {
t |= 1;
do {
if (ckd_mul(&x, x, base) || ckd_add(&x, x, c)) {
if (endptr) {
*endptr = (char *)(s + 1);
}
errno = ERANGE;
return ULONG_MAX;
}
} while ((c = kBase36[*++s & 255]) && --c < base);
}
if (t && endptr) {
*endptr = (char *)s;
}
return d > 0 ? x : -x;
}
__weak_reference(strtoul, strtoumax);
__weak_reference(strtoul, strtoull);
__weak_reference(strtoul, strtoull_l);
|
4924796bf9a2023cd717cc8d83ab66a44d72fc15
|
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
|
/SOFTWARE/A64-TERES/linux-a64/drivers/net/wireless/ath/ath6kl/core.h
|
26b0f92424e16fb91beca55f3f07e9d907a9db04
|
[
"Linux-syscall-note",
"GPL-2.0-only",
"GPL-1.0-or-later",
"LicenseRef-scancode-free-unknown",
"Apache-2.0",
"LicenseRef-scancode-warranty-disclaimer"
] |
permissive
|
OLIMEX/DIY-LAPTOP
|
ae82f4ee79c641d9aee444db9a75f3f6709afa92
|
a3fafd1309135650bab27f5eafc0c32bc3ca74ee
|
refs/heads/rel3
| 2023-08-04T01:54:19.483792
| 2023-04-03T07:18:12
| 2023-04-03T07:18:12
| 80,094,055
| 507
| 92
|
Apache-2.0
| 2023-04-03T07:05:59
| 2017-01-26T07:25:50
|
C
|
UTF-8
|
C
| false
| false
| 25,673
|
h
|
core.h
|
/*
* Copyright (c) 2010-2011 Atheros Communications Inc.
* Copyright (c) 2011-2012 Qualcomm Atheros, Inc.
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS 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, DIRECT, 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 CORE_H
#define CORE_H
#include <linux/etherdevice.h>
#include <linux/rtnetlink.h>
#include <linux/firmware.h>
#include <linux/sched.h>
#include <linux/circ_buf.h>
#include <net/cfg80211.h>
#include "htc.h"
#include "wmi.h"
#include "bmi.h"
#include "target.h"
#define MAX_ATH6KL 1
#define ATH6KL_MAX_RX_BUFFERS 16
#define ATH6KL_BUFFER_SIZE 1664
#define ATH6KL_MAX_AMSDU_RX_BUFFERS 4
#define ATH6KL_AMSDU_REFILL_THRESHOLD 3
#define ATH6KL_AMSDU_BUFFER_SIZE (WMI_MAX_AMSDU_RX_DATA_FRAME_LENGTH + 128)
#define MAX_MSDU_SUBFRAME_PAYLOAD_LEN 1508
#define MIN_MSDU_SUBFRAME_PAYLOAD_LEN 46
#define USER_SAVEDKEYS_STAT_INIT 0
#define USER_SAVEDKEYS_STAT_RUN 1
#define ATH6KL_TX_TIMEOUT 10
#define ATH6KL_MAX_ENDPOINTS 4
#define MAX_NODE_NUM 15
#define ATH6KL_APSD_ALL_FRAME 0xFFFF
#define ATH6KL_APSD_NUM_OF_AC 0x4
#define ATH6KL_APSD_FRAME_MASK 0xF
/* Extra bytes for htc header alignment */
#define ATH6KL_HTC_ALIGN_BYTES 3
/* MAX_HI_COOKIE_NUM are reserved for high priority traffic */
#define MAX_DEF_COOKIE_NUM 180
#define MAX_HI_COOKIE_NUM 18 /* 10% of MAX_COOKIE_NUM */
#define MAX_COOKIE_NUM (MAX_DEF_COOKIE_NUM + MAX_HI_COOKIE_NUM)
#define MAX_DEFAULT_SEND_QUEUE_DEPTH (MAX_DEF_COOKIE_NUM / WMM_NUM_AC)
#define DISCON_TIMER_INTVAL 10000 /* in msec */
/* Channel dwell time in fg scan */
#define ATH6KL_FG_SCAN_INTERVAL 50 /* in ms */
/* includes also the null byte */
#define ATH6KL_FIRMWARE_MAGIC "QCA-ATH6KL"
enum ath6kl_fw_ie_type {
ATH6KL_FW_IE_FW_VERSION = 0,
ATH6KL_FW_IE_TIMESTAMP = 1,
ATH6KL_FW_IE_OTP_IMAGE = 2,
ATH6KL_FW_IE_FW_IMAGE = 3,
ATH6KL_FW_IE_PATCH_IMAGE = 4,
ATH6KL_FW_IE_RESERVED_RAM_SIZE = 5,
ATH6KL_FW_IE_CAPABILITIES = 6,
ATH6KL_FW_IE_PATCH_ADDR = 7,
ATH6KL_FW_IE_BOARD_ADDR = 8,
ATH6KL_FW_IE_VIF_MAX = 9,
};
enum ath6kl_fw_capability {
ATH6KL_FW_CAPABILITY_HOST_P2P = 0,
ATH6KL_FW_CAPABILITY_SCHED_SCAN = 1,
/*
* Firmware is capable of supporting P2P mgmt operations on a
* station interface. After group formation, the station
* interface will become a P2P client/GO interface as the case may be
*/
ATH6KL_FW_CAPABILITY_STA_P2PDEV_DUPLEX,
/*
* Firmware has support to cleanup inactive stations
* in AP mode.
*/
ATH6KL_FW_CAPABILITY_INACTIVITY_TIMEOUT,
/* Firmware has support to override rsn cap of rsn ie */
ATH6KL_FW_CAPABILITY_RSN_CAP_OVERRIDE,
/*
* Multicast support in WOW and host awake mode.
* Allow all multicast in host awake mode.
* Apply multicast filter in WOW mode.
*/
ATH6KL_FW_CAPABILITY_WOW_MULTICAST_FILTER,
/* Firmware supports enhanced bmiss detection */
ATH6KL_FW_CAPABILITY_BMISS_ENHANCE,
/*
* FW supports matching of ssid in schedule scan
*/
ATH6KL_FW_CAPABILITY_SCHED_SCAN_MATCH_LIST,
/* Firmware supports filtering BSS results by RSSI */
ATH6KL_FW_CAPABILITY_RSSI_SCAN_THOLD,
/* FW sets mac_addr[4] ^= 0x80 for newly created interfaces */
ATH6KL_FW_CAPABILITY_CUSTOM_MAC_ADDR,
/* Firmware supports TX error rate notification */
ATH6KL_FW_CAPABILITY_TX_ERR_NOTIFY,
/* supports WMI_SET_REGDOMAIN_CMDID command */
ATH6KL_FW_CAPABILITY_REGDOMAIN,
/* Firmware supports sched scan decoupled from host sleep */
ATH6KL_FW_CAPABILITY_SCHED_SCAN_V2,
/*
* Firmware capability for hang detection through heart beat
* challenge messages.
*/
ATH6KL_FW_CAPABILITY_HEART_BEAT_POLL,
/* this needs to be last */
ATH6KL_FW_CAPABILITY_MAX,
};
#define ATH6KL_CAPABILITY_LEN (ALIGN(ATH6KL_FW_CAPABILITY_MAX, 32) / 32)
struct ath6kl_fw_ie {
__le32 id;
__le32 len;
u8 data[0];
};
enum ath6kl_hw_flags {
ATH6KL_HW_64BIT_RATES = BIT(0),
ATH6KL_HW_AP_INACTIVITY_MINS = BIT(1),
ATH6KL_HW_MAP_LP_ENDPOINT = BIT(2),
ATH6KL_HW_SDIO_CRC_ERROR_WAR = BIT(3),
};
#define ATH6KL_FW_API2_FILE "fw-2.bin"
#define ATH6KL_FW_API3_FILE "fw-3.bin"
#define ATH6KL_FW_API4_FILE "fw-4.bin"
/* AR6003 1.0 definitions */
#define AR6003_HW_1_0_VERSION 0x300002ba
/* AR6003 2.0 definitions */
#define AR6003_HW_2_0_VERSION 0x30000384
#define AR6003_HW_2_0_PATCH_DOWNLOAD_ADDRESS 0x57e910
#define AR6003_HW_2_0_FW_DIR "ath6k/AR6003/hw2.0"
#define AR6003_HW_2_0_OTP_FILE "otp.bin.z77"
#define AR6003_HW_2_0_FIRMWARE_FILE "athwlan.bin.z77"
#define AR6003_HW_2_0_TCMD_FIRMWARE_FILE "athtcmd_ram.bin"
#define AR6003_HW_2_0_PATCH_FILE "data.patch.bin"
#define AR6003_HW_2_0_BOARD_DATA_FILE AR6003_HW_2_0_FW_DIR "/bdata.bin"
#define AR6003_HW_2_0_DEFAULT_BOARD_DATA_FILE \
AR6003_HW_2_0_FW_DIR "/bdata.SD31.bin"
/* AR6003 3.0 definitions */
#define AR6003_HW_2_1_1_VERSION 0x30000582
#define AR6003_HW_2_1_1_FW_DIR "ath6k/AR6003/hw2.1.1"
#define AR6003_HW_2_1_1_OTP_FILE "otp.bin"
#define AR6003_HW_2_1_1_FIRMWARE_FILE "athwlan.bin"
#define AR6003_HW_2_1_1_TCMD_FIRMWARE_FILE "athtcmd_ram.bin"
#define AR6003_HW_2_1_1_UTF_FIRMWARE_FILE "utf.bin"
#define AR6003_HW_2_1_1_TESTSCRIPT_FILE "nullTestFlow.bin"
#define AR6003_HW_2_1_1_PATCH_FILE "data.patch.bin"
#define AR6003_HW_2_1_1_BOARD_DATA_FILE AR6003_HW_2_1_1_FW_DIR "/bdata.bin"
#define AR6003_HW_2_1_1_DEFAULT_BOARD_DATA_FILE \
AR6003_HW_2_1_1_FW_DIR "/bdata.SD31.bin"
/* AR6004 1.0 definitions */
#define AR6004_HW_1_0_VERSION 0x30000623
#define AR6004_HW_1_0_FW_DIR "ath6k/AR6004/hw1.0"
#define AR6004_HW_1_0_FIRMWARE_FILE "fw.ram.bin"
#define AR6004_HW_1_0_BOARD_DATA_FILE AR6004_HW_1_0_FW_DIR "/bdata.bin"
#define AR6004_HW_1_0_DEFAULT_BOARD_DATA_FILE \
AR6004_HW_1_0_FW_DIR "/bdata.DB132.bin"
/* AR6004 1.1 definitions */
#define AR6004_HW_1_1_VERSION 0x30000001
#define AR6004_HW_1_1_FW_DIR "ath6k/AR6004/hw1.1"
#define AR6004_HW_1_1_FIRMWARE_FILE "fw.ram.bin"
#define AR6004_HW_1_1_BOARD_DATA_FILE AR6004_HW_1_1_FW_DIR "/bdata.bin"
#define AR6004_HW_1_1_DEFAULT_BOARD_DATA_FILE \
AR6004_HW_1_1_FW_DIR "/bdata.DB132.bin"
/* AR6004 1.2 definitions */
#define AR6004_HW_1_2_VERSION 0x300007e8
#define AR6004_HW_1_2_FW_DIR "ath6k/AR6004/hw1.2"
#define AR6004_HW_1_2_FIRMWARE_FILE "fw.ram.bin"
#define AR6004_HW_1_2_BOARD_DATA_FILE AR6004_HW_1_2_FW_DIR "/bdata.bin"
#define AR6004_HW_1_2_DEFAULT_BOARD_DATA_FILE \
AR6004_HW_1_2_FW_DIR "/bdata.bin"
/* AR6004 1.3 definitions */
#define AR6004_HW_1_3_VERSION 0x31c8088a
#define AR6004_HW_1_3_FW_DIR "ath6k/AR6004/hw1.3"
#define AR6004_HW_1_3_FIRMWARE_FILE "fw.ram.bin"
#define AR6004_HW_1_3_BOARD_DATA_FILE "ath6k/AR6004/hw1.3/bdata.bin"
#define AR6004_HW_1_3_DEFAULT_BOARD_DATA_FILE "ath6k/AR6004/hw1.3/bdata.bin"
/* Per STA data, used in AP mode */
#define STA_PS_AWAKE BIT(0)
#define STA_PS_SLEEP BIT(1)
#define STA_PS_POLLED BIT(2)
#define STA_PS_APSD_TRIGGER BIT(3)
#define STA_PS_APSD_EOSP BIT(4)
/* HTC TX packet tagging definitions */
#define ATH6KL_CONTROL_PKT_TAG HTC_TX_PACKET_TAG_USER_DEFINED
#define ATH6KL_DATA_PKT_TAG (ATH6KL_CONTROL_PKT_TAG + 1)
#define AR6003_CUST_DATA_SIZE 16
#define AGGR_WIN_IDX(x, y) ((x) % (y))
#define AGGR_INCR_IDX(x, y) AGGR_WIN_IDX(((x) + 1), (y))
#define AGGR_DCRM_IDX(x, y) AGGR_WIN_IDX(((x) - 1), (y))
#define ATH6KL_MAX_SEQ_NO 0xFFF
#define ATH6KL_NEXT_SEQ_NO(x) (((x) + 1) & ATH6KL_MAX_SEQ_NO)
#define NUM_OF_TIDS 8
#define AGGR_SZ_DEFAULT 8
#define AGGR_WIN_SZ_MIN 2
#define AGGR_WIN_SZ_MAX 8
#define TID_WINDOW_SZ(_x) ((_x) << 1)
#define AGGR_NUM_OF_FREE_NETBUFS 16
#define AGGR_RX_TIMEOUT 100 /* in ms */
#define WMI_TIMEOUT (2 * HZ)
#define MBOX_YIELD_LIMIT 99
#define ATH6KL_DEFAULT_LISTEN_INTVAL 100 /* in TUs */
#define ATH6KL_DEFAULT_BMISS_TIME 1500
#define ATH6KL_MAX_WOW_LISTEN_INTL 300 /* in TUs */
#define ATH6KL_MAX_BMISS_TIME 5000
/* configuration lags */
/*
* ATH6KL_CONF_IGNORE_ERP_BARKER: Ignore the barker premable in
* ERP IE of beacon to determine the short premable support when
* sending (Re)Assoc req.
* ATH6KL_CONF_IGNORE_PS_FAIL_EVT_IN_SCAN: Don't send the power
* module state transition failure events which happen during
* scan, to the host.
*/
#define ATH6KL_CONF_IGNORE_ERP_BARKER BIT(0)
#define ATH6KL_CONF_IGNORE_PS_FAIL_EVT_IN_SCAN BIT(1)
#define ATH6KL_CONF_ENABLE_11N BIT(2)
#define ATH6KL_CONF_ENABLE_TX_BURST BIT(3)
#define ATH6KL_CONF_UART_DEBUG BIT(4)
#define P2P_WILDCARD_SSID_LEN 7 /* DIRECT- */
enum wlan_low_pwr_state {
WLAN_POWER_STATE_ON,
WLAN_POWER_STATE_CUT_PWR,
WLAN_POWER_STATE_DEEP_SLEEP,
WLAN_POWER_STATE_WOW
};
enum sme_state {
SME_DISCONNECTED,
SME_CONNECTING,
SME_CONNECTED
};
struct skb_hold_q {
struct sk_buff *skb;
bool is_amsdu;
u16 seq_no;
};
struct rxtid {
bool aggr;
bool timer_mon;
u16 win_sz;
u16 seq_next;
u32 hold_q_sz;
struct skb_hold_q *hold_q;
struct sk_buff_head q;
/*
* lock mainly protects seq_next and hold_q. Movement of seq_next
* needs to be protected between aggr_timeout() and
* aggr_process_recv_frm(). hold_q will be holding the pending
* reorder frames and it's access should also be protected.
* Some of the other fields like hold_q_sz, win_sz and aggr are
* initialized/reset when receiving addba/delba req, also while
* deleting aggr state all the pending buffers are flushed before
* resetting these fields, so there should not be any race in accessing
* these fields.
*/
spinlock_t lock;
};
struct rxtid_stats {
u32 num_into_aggr;
u32 num_dups;
u32 num_oow;
u32 num_mpdu;
u32 num_amsdu;
u32 num_delivered;
u32 num_timeouts;
u32 num_hole;
u32 num_bar;
};
struct aggr_info_conn {
u8 aggr_sz;
u8 timer_scheduled;
struct timer_list timer;
struct net_device *dev;
struct rxtid rx_tid[NUM_OF_TIDS];
struct rxtid_stats stat[NUM_OF_TIDS];
struct aggr_info *aggr_info;
};
struct aggr_info {
struct aggr_info_conn *aggr_conn;
struct sk_buff_head rx_amsdu_freeq;
};
struct ath6kl_wep_key {
u8 key_index;
u8 key_len;
u8 key[64];
};
#define ATH6KL_KEY_SEQ_LEN 8
struct ath6kl_key {
u8 key[WLAN_MAX_KEY_LEN];
u8 key_len;
u8 seq[ATH6KL_KEY_SEQ_LEN];
u8 seq_len;
u32 cipher;
};
struct ath6kl_node_mapping {
u8 mac_addr[ETH_ALEN];
u8 ep_id;
u8 tx_pend;
};
struct ath6kl_cookie {
struct sk_buff *skb;
u32 map_no;
struct htc_packet htc_pkt;
struct ath6kl_cookie *arc_list_next;
};
struct ath6kl_mgmt_buff {
struct list_head list;
u32 freq;
u32 wait;
u32 id;
bool no_cck;
size_t len;
u8 buf[0];
};
struct ath6kl_sta {
u16 sta_flags;
u8 mac[ETH_ALEN];
u8 aid;
u8 keymgmt;
u8 ucipher;
u8 auth;
u8 wpa_ie[ATH6KL_MAX_IE];
struct sk_buff_head psq;
/* protects psq, mgmt_psq, apsdq, and mgmt_psq_len fields */
spinlock_t psq_lock;
struct list_head mgmt_psq;
size_t mgmt_psq_len;
u8 apsd_info;
struct sk_buff_head apsdq;
struct aggr_info_conn *aggr_conn;
};
struct ath6kl_version {
u32 target_ver;
u32 wlan_ver;
u32 abi_ver;
};
struct ath6kl_bmi {
u32 cmd_credits;
bool done_sent;
u8 *cmd_buf;
u32 max_data_size;
u32 max_cmd_size;
};
struct target_stats {
u64 tx_pkt;
u64 tx_byte;
u64 tx_ucast_pkt;
u64 tx_ucast_byte;
u64 tx_mcast_pkt;
u64 tx_mcast_byte;
u64 tx_bcast_pkt;
u64 tx_bcast_byte;
u64 tx_rts_success_cnt;
u64 tx_pkt_per_ac[4];
u64 tx_err;
u64 tx_fail_cnt;
u64 tx_retry_cnt;
u64 tx_mult_retry_cnt;
u64 tx_rts_fail_cnt;
u64 rx_pkt;
u64 rx_byte;
u64 rx_ucast_pkt;
u64 rx_ucast_byte;
u64 rx_mcast_pkt;
u64 rx_mcast_byte;
u64 rx_bcast_pkt;
u64 rx_bcast_byte;
u64 rx_frgment_pkt;
u64 rx_err;
u64 rx_crc_err;
u64 rx_key_cache_miss;
u64 rx_decrypt_err;
u64 rx_dupl_frame;
u64 tkip_local_mic_fail;
u64 tkip_cnter_measures_invoked;
u64 tkip_replays;
u64 tkip_fmt_err;
u64 ccmp_fmt_err;
u64 ccmp_replays;
u64 pwr_save_fail_cnt;
u64 cs_bmiss_cnt;
u64 cs_low_rssi_cnt;
u64 cs_connect_cnt;
u64 cs_discon_cnt;
s32 tx_ucast_rate;
s32 rx_ucast_rate;
u32 lq_val;
u32 wow_pkt_dropped;
u16 wow_evt_discarded;
s16 noise_floor_calib;
s16 cs_rssi;
s16 cs_ave_beacon_rssi;
u8 cs_ave_beacon_snr;
u8 cs_last_roam_msec;
u8 cs_snr;
u8 wow_host_pkt_wakeups;
u8 wow_host_evt_wakeups;
u32 arp_received;
u32 arp_matched;
u32 arp_replied;
};
struct ath6kl_mbox_info {
u32 htc_addr;
u32 htc_ext_addr;
u32 htc_ext_sz;
u32 block_size;
u32 gmbox_addr;
u32 gmbox_sz;
};
/*
* 802.11i defines an extended IV for use with non-WEP ciphers.
* When the EXTIV bit is set in the key id byte an additional
* 4 bytes immediately follow the IV for TKIP. For CCMP the
* EXTIV bit is likewise set but the 8 bytes represent the
* CCMP header rather than IV+extended-IV.
*/
#define ATH6KL_KEYBUF_SIZE 16
#define ATH6KL_MICBUF_SIZE (8+8) /* space for both tx and rx */
#define ATH6KL_KEY_XMIT 0x01
#define ATH6KL_KEY_RECV 0x02
#define ATH6KL_KEY_DEFAULT 0x80 /* default xmit key */
/* Initial group key for AP mode */
struct ath6kl_req_key {
bool valid;
u8 key_index;
int key_type;
u8 key[WLAN_MAX_KEY_LEN];
u8 key_len;
};
enum ath6kl_hif_type {
ATH6KL_HIF_TYPE_SDIO,
ATH6KL_HIF_TYPE_USB,
};
enum ath6kl_htc_type {
ATH6KL_HTC_TYPE_MBOX,
ATH6KL_HTC_TYPE_PIPE,
};
/* Max number of filters that hw supports */
#define ATH6K_MAX_MC_FILTERS_PER_LIST 7
struct ath6kl_mc_filter {
struct list_head list;
char hw_addr[ATH6KL_MCAST_FILTER_MAC_ADDR_SIZE];
};
struct ath6kl_htcap {
bool ht_enable;
u8 ampdu_factor;
unsigned short cap_info;
};
/*
* Driver's maximum limit, note that some firmwares support only one vif
* and the runtime (current) limit must be checked from ar->vif_max.
*/
#define ATH6KL_VIF_MAX 3
/* vif flags info */
enum ath6kl_vif_state {
CONNECTED,
CONNECT_PEND,
WMM_ENABLED,
NETQ_STOPPED,
DTIM_EXPIRED,
CLEAR_BSSFILTER_ON_BEACON,
DTIM_PERIOD_AVAIL,
WLAN_ENABLED,
STATS_UPDATE_PEND,
HOST_SLEEP_MODE_CMD_PROCESSED,
NETDEV_MCAST_ALL_ON,
NETDEV_MCAST_ALL_OFF,
SCHED_SCANNING,
};
struct ath6kl_vif {
struct list_head list;
struct wireless_dev wdev;
struct net_device *ndev;
struct ath6kl *ar;
/* Lock to protect vif specific net_stats and flags */
spinlock_t if_lock;
u8 fw_vif_idx;
unsigned long flags;
int ssid_len;
u8 ssid[IEEE80211_MAX_SSID_LEN];
u8 dot11_auth_mode;
u8 auth_mode;
u8 prwise_crypto;
u8 prwise_crypto_len;
u8 grp_crypto;
u8 grp_crypto_len;
u8 def_txkey_index;
u8 next_mode;
u8 nw_type;
u8 bssid[ETH_ALEN];
u8 req_bssid[ETH_ALEN];
u16 ch_hint;
u16 bss_ch;
struct ath6kl_wep_key wep_key_list[WMI_MAX_KEY_INDEX + 1];
struct ath6kl_key keys[WMI_MAX_KEY_INDEX + 1];
struct aggr_info *aggr_cntxt;
struct ath6kl_htcap htcap[IEEE80211_NUM_BANDS];
struct timer_list disconnect_timer;
struct timer_list sched_scan_timer;
struct cfg80211_scan_request *scan_req;
enum sme_state sme_state;
int reconnect_flag;
u32 last_roc_id;
u32 last_cancel_roc_id;
u32 send_action_id;
bool probe_req_report;
u16 assoc_bss_beacon_int;
u16 listen_intvl_t;
u16 bmiss_time_t;
u32 txe_intvl;
u16 bg_scan_period;
u8 assoc_bss_dtim_period;
struct net_device_stats net_stats;
struct target_stats target_stats;
struct wmi_connect_cmd profile;
u16 rsn_capab;
struct list_head mc_filter;
};
static inline struct ath6kl_vif *ath6kl_vif_from_wdev(struct wireless_dev *wdev)
{
return container_of(wdev, struct ath6kl_vif, wdev);
}
#define WOW_LIST_ID 0
#define WOW_HOST_REQ_DELAY 500 /* ms */
#define ATH6KL_SCHED_SCAN_RESULT_DELAY 5000 /* ms */
/* Flag info */
enum ath6kl_dev_state {
WMI_ENABLED,
WMI_READY,
WMI_CTRL_EP_FULL,
TESTMODE,
DESTROY_IN_PROGRESS,
SKIP_SCAN,
ROAM_TBL_PEND,
FIRST_BOOT,
RECOVERY_CLEANUP,
};
enum ath6kl_state {
ATH6KL_STATE_OFF,
ATH6KL_STATE_ON,
ATH6KL_STATE_SUSPENDING,
ATH6KL_STATE_RESUMING,
ATH6KL_STATE_DEEPSLEEP,
ATH6KL_STATE_CUTPOWER,
ATH6KL_STATE_WOW,
ATH6KL_STATE_RECOVERY,
};
/* Fw error recovery */
#define ATH6KL_HB_RESP_MISS_THRES 5
enum ath6kl_fw_err {
ATH6KL_FW_ASSERT,
ATH6KL_FW_HB_RESP_FAILURE,
ATH6KL_FW_EP_FULL,
};
struct ath6kl {
struct device *dev;
struct wiphy *wiphy;
enum ath6kl_state state;
unsigned int testmode;
struct ath6kl_bmi bmi;
const struct ath6kl_hif_ops *hif_ops;
const struct ath6kl_htc_ops *htc_ops;
struct wmi *wmi;
int tx_pending[ENDPOINT_MAX];
int total_tx_data_pend;
struct htc_target *htc_target;
enum ath6kl_hif_type hif_type;
void *hif_priv;
struct list_head vif_list;
/* Lock to avoid race in vif_list entries among add/del/traverse */
spinlock_t list_lock;
u8 num_vif;
unsigned int vif_max;
u8 max_norm_iface;
u8 avail_idx_map;
/*
* Protects at least amsdu_rx_buffer_queue, ath6kl_alloc_cookie()
* calls, tx_pending and total_tx_data_pend.
*/
spinlock_t lock;
struct semaphore sem;
u8 lrssi_roam_threshold;
struct ath6kl_version version;
u32 target_type;
u8 tx_pwr;
struct ath6kl_node_mapping node_map[MAX_NODE_NUM];
u8 ibss_ps_enable;
bool ibss_if_active;
u8 node_num;
u8 next_ep_id;
struct ath6kl_cookie *cookie_list;
u32 cookie_count;
enum htc_endpoint_id ac2ep_map[WMM_NUM_AC];
bool ac_stream_active[WMM_NUM_AC];
u8 ac_stream_pri_map[WMM_NUM_AC];
u8 hiac_stream_active_pri;
u8 ep2ac_map[ENDPOINT_MAX];
enum htc_endpoint_id ctrl_ep;
struct ath6kl_htc_credit_info credit_state_info;
u32 connect_ctrl_flags;
u32 user_key_ctrl;
u8 usr_bss_filter;
struct ath6kl_sta sta_list[AP_MAX_NUM_STA];
u8 sta_list_index;
struct ath6kl_req_key ap_mode_bkey;
struct sk_buff_head mcastpsq;
u32 want_ch_switch;
u16 last_ch;
/*
* FIXME: protects access to mcastpsq but is actually useless as
* all skbe_queue_*() functions provide serialisation themselves
*/
spinlock_t mcastpsq_lock;
u8 intra_bss;
struct wmi_ap_mode_stat ap_stats;
u8 ap_country_code[3];
struct list_head amsdu_rx_buffer_queue;
u8 rx_meta_ver;
enum wlan_low_pwr_state wlan_pwr_state;
u8 mac_addr[ETH_ALEN];
#define AR_MCAST_FILTER_MAC_ADDR_SIZE 4
struct {
void *rx_report;
size_t rx_report_len;
} tm;
struct ath6kl_hw {
u32 id;
const char *name;
u32 dataset_patch_addr;
u32 app_load_addr;
u32 app_start_override_addr;
u32 board_ext_data_addr;
u32 reserved_ram_size;
u32 board_addr;
u32 refclk_hz;
u32 uarttx_pin;
u32 testscript_addr;
enum wmi_phy_cap cap;
u32 flags;
struct ath6kl_hw_fw {
const char *dir;
const char *otp;
const char *fw;
const char *tcmd;
const char *patch;
const char *utf;
const char *testscript;
} fw;
const char *fw_board;
const char *fw_default_board;
} hw;
u16 conf_flags;
u16 suspend_mode;
u16 wow_suspend_mode;
wait_queue_head_t event_wq;
struct ath6kl_mbox_info mbox_info;
struct ath6kl_cookie cookie_mem[MAX_COOKIE_NUM];
unsigned long flag;
u8 *fw_board;
size_t fw_board_len;
u8 *fw_otp;
size_t fw_otp_len;
u8 *fw;
size_t fw_len;
u8 *fw_patch;
size_t fw_patch_len;
u8 *fw_testscript;
size_t fw_testscript_len;
unsigned int fw_api;
unsigned long fw_capabilities[ATH6KL_CAPABILITY_LEN];
struct workqueue_struct *ath6kl_wq;
struct dentry *debugfs_phy;
bool p2p;
bool wiphy_registered;
struct ath6kl_fw_recovery {
struct work_struct recovery_work;
unsigned long err_reason;
unsigned long hb_poll;
struct timer_list hb_timer;
u32 seq_num;
bool hb_pending;
u8 hb_misscnt;
bool enable;
} fw_recovery;
#ifdef CONFIG_ATH6KL_DEBUG
struct {
struct sk_buff_head fwlog_queue;
struct completion fwlog_completion;
bool fwlog_open;
u32 fwlog_mask;
unsigned int dbgfs_diag_reg;
u32 diag_reg_addr_wr;
u32 diag_reg_val_wr;
struct {
unsigned int invalid_rate;
} war_stats;
u8 *roam_tbl;
unsigned int roam_tbl_len;
u8 keepalive;
u8 disc_timeout;
} debug;
#endif /* CONFIG_ATH6KL_DEBUG */
};
static inline struct ath6kl *ath6kl_priv(struct net_device *dev)
{
return ((struct ath6kl_vif *) netdev_priv(dev))->ar;
}
static inline u32 ath6kl_get_hi_item_addr(struct ath6kl *ar,
u32 item_offset)
{
u32 addr = 0;
if (ar->target_type == TARGET_TYPE_AR6003)
addr = ATH6KL_AR6003_HI_START_ADDR + item_offset;
else if (ar->target_type == TARGET_TYPE_AR6004)
addr = ATH6KL_AR6004_HI_START_ADDR + item_offset;
return addr;
}
int ath6kl_configure_target(struct ath6kl *ar);
void ath6kl_detect_error(unsigned long ptr);
void disconnect_timer_handler(unsigned long ptr);
void init_netdev(struct net_device *dev);
void ath6kl_cookie_init(struct ath6kl *ar);
void ath6kl_cookie_cleanup(struct ath6kl *ar);
void ath6kl_rx(struct htc_target *target, struct htc_packet *packet);
void ath6kl_tx_complete(struct htc_target *context,
struct list_head *packet_queue);
enum htc_send_full_action ath6kl_tx_queue_full(struct htc_target *target,
struct htc_packet *packet);
void ath6kl_stop_txrx(struct ath6kl *ar);
void ath6kl_cleanup_amsdu_rxbufs(struct ath6kl *ar);
int ath6kl_diag_write32(struct ath6kl *ar, u32 address, __le32 value);
int ath6kl_diag_write(struct ath6kl *ar, u32 address, void *data, u32 length);
int ath6kl_diag_read32(struct ath6kl *ar, u32 address, u32 *value);
int ath6kl_diag_read(struct ath6kl *ar, u32 address, void *data, u32 length);
int ath6kl_read_fwlogs(struct ath6kl *ar);
void ath6kl_init_profile_info(struct ath6kl_vif *vif);
void ath6kl_tx_data_cleanup(struct ath6kl *ar);
struct ath6kl_cookie *ath6kl_alloc_cookie(struct ath6kl *ar);
void ath6kl_free_cookie(struct ath6kl *ar, struct ath6kl_cookie *cookie);
int ath6kl_data_tx(struct sk_buff *skb, struct net_device *dev);
struct aggr_info *aggr_init(struct ath6kl_vif *vif);
void aggr_conn_init(struct ath6kl_vif *vif, struct aggr_info *aggr_info,
struct aggr_info_conn *aggr_conn);
void ath6kl_rx_refill(struct htc_target *target,
enum htc_endpoint_id endpoint);
void ath6kl_refill_amsdu_rxbufs(struct ath6kl *ar, int count);
struct htc_packet *ath6kl_alloc_amsdu_rxbuf(struct htc_target *target,
enum htc_endpoint_id endpoint,
int len);
void aggr_module_destroy(struct aggr_info *aggr_info);
void aggr_reset_state(struct aggr_info_conn *aggr_conn);
struct ath6kl_sta *ath6kl_find_sta(struct ath6kl_vif *vif, u8 *node_addr);
struct ath6kl_sta *ath6kl_find_sta_by_aid(struct ath6kl *ar, u8 aid);
void ath6kl_ready_event(void *devt, u8 *datap, u32 sw_ver, u32 abi_ver,
enum wmi_phy_cap cap);
int ath6kl_control_tx(void *devt, struct sk_buff *skb,
enum htc_endpoint_id eid);
void ath6kl_connect_event(struct ath6kl_vif *vif, u16 channel,
u8 *bssid, u16 listen_int,
u16 beacon_int, enum network_type net_type,
u8 beacon_ie_len, u8 assoc_req_len,
u8 assoc_resp_len, u8 *assoc_info);
void ath6kl_connect_ap_mode_bss(struct ath6kl_vif *vif, u16 channel);
void ath6kl_connect_ap_mode_sta(struct ath6kl_vif *vif, u16 aid, u8 *mac_addr,
u8 keymgmt, u8 ucipher, u8 auth,
u8 assoc_req_len, u8 *assoc_info, u8 apsd_info);
void ath6kl_disconnect_event(struct ath6kl_vif *vif, u8 reason,
u8 *bssid, u8 assoc_resp_len,
u8 *assoc_info, u16 prot_reason_status);
void ath6kl_tkip_micerr_event(struct ath6kl_vif *vif, u8 keyid, bool ismcast);
void ath6kl_txpwr_rx_evt(void *devt, u8 tx_pwr);
void ath6kl_scan_complete_evt(struct ath6kl_vif *vif, int status);
void ath6kl_tgt_stats_event(struct ath6kl_vif *vif, u8 *ptr, u32 len);
void ath6kl_indicate_tx_activity(void *devt, u8 traffic_class, bool active);
enum htc_endpoint_id ath6kl_ac2_endpoint_id(void *devt, u8 ac);
void ath6kl_pspoll_event(struct ath6kl_vif *vif, u8 aid);
void ath6kl_dtimexpiry_event(struct ath6kl_vif *vif);
void ath6kl_disconnect(struct ath6kl_vif *vif);
void aggr_recv_delba_req_evt(struct ath6kl_vif *vif, u8 tid);
void aggr_recv_addba_req_evt(struct ath6kl_vif *vif, u8 tid, u16 seq_no,
u8 win_sz);
void ath6kl_wakeup_event(void *dev);
void ath6kl_init_control_info(struct ath6kl_vif *vif);
struct ath6kl_vif *ath6kl_vif_first(struct ath6kl *ar);
void ath6kl_cfg80211_vif_stop(struct ath6kl_vif *vif, bool wmi_ready);
int ath6kl_init_hw_start(struct ath6kl *ar);
int ath6kl_init_hw_stop(struct ath6kl *ar);
int ath6kl_init_fetch_firmwares(struct ath6kl *ar);
int ath6kl_init_hw_params(struct ath6kl *ar);
void ath6kl_check_wow_status(struct ath6kl *ar);
void ath6kl_core_tx_complete(struct ath6kl *ar, struct sk_buff *skb);
void ath6kl_core_rx_complete(struct ath6kl *ar, struct sk_buff *skb, u8 pipe);
struct ath6kl *ath6kl_core_create(struct device *dev);
int ath6kl_core_init(struct ath6kl *ar, enum ath6kl_htc_type htc_type);
void ath6kl_core_cleanup(struct ath6kl *ar);
void ath6kl_core_destroy(struct ath6kl *ar);
/* Fw error recovery */
void ath6kl_init_hw_restart(struct ath6kl *ar);
void ath6kl_recovery_err_notify(struct ath6kl *ar, enum ath6kl_fw_err reason);
void ath6kl_recovery_hb_event(struct ath6kl *ar, u32 cookie);
void ath6kl_recovery_init(struct ath6kl *ar);
void ath6kl_recovery_cleanup(struct ath6kl *ar);
void ath6kl_recovery_suspend(struct ath6kl *ar);
void ath6kl_recovery_resume(struct ath6kl *ar);
#endif /* CORE_H */
|
00e3799d8f457320dc196e0e8f0b634c3e7b2d28
|
99bdb3251fecee538e0630f15f6574054dfc1468
|
/bsp/stm32/stm32l475-atk-pandora/board/ports/fal/fal_flash_sfud_port.c
|
fc9a1c7adae6a0a151d5b0a25c5fe460edf5d438
|
[
"Apache-2.0",
"Zlib",
"LicenseRef-scancode-proprietary-license",
"MIT",
"BSD-3-Clause",
"X11",
"BSD-4-Clause-UC",
"LicenseRef-scancode-unknown-license-reference"
] |
permissive
|
RT-Thread/rt-thread
|
03a7c52c2aeb1b06a544143b0e803d72f47d1ece
|
3602f891211904a27dcbd51e5ba72fefce7326b2
|
refs/heads/master
| 2023-09-01T04:10:20.295801
| 2023-08-31T16:20:55
| 2023-08-31T16:20:55
| 7,408,108
| 9,599
| 5,805
|
Apache-2.0
| 2023-09-14T13:37:26
| 2013-01-02T14:49:21
|
C
|
UTF-8
|
C
| false
| false
| 1,258
|
c
|
fal_flash_sfud_port.c
|
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2018-01-26 armink the first version
* 2018-08-21 MurphyZhao update to stm32l4xx
*/
#include <fal.h>
#include <sfud.h>
#include <spi_flash_sfud.h>
sfud_flash sfud_norflash0;
static int fal_sfud_init(void)
{
sfud_flash_t sfud_flash0 = NULL;
sfud_flash0 = (sfud_flash_t)rt_sfud_flash_find("qspi10");
if (NULL == sfud_flash0)
{
return -1;
}
sfud_norflash0 = *sfud_flash0;
return 0;
}
static int read(long offset, uint8_t *buf, size_t size)
{
sfud_read(&sfud_norflash0, nor_flash0.addr + offset, size, buf);
return size;
}
static int write(long offset, const uint8_t *buf, size_t size)
{
if (sfud_write(&sfud_norflash0, nor_flash0.addr + offset, size, buf) != SFUD_SUCCESS)
{
return -1;
}
return size;
}
static int erase(long offset, size_t size)
{
if (sfud_erase(&sfud_norflash0, nor_flash0.addr + offset, size) != SFUD_SUCCESS)
{
return -1;
}
return size;
}
const struct fal_flash_dev nor_flash0 = { "nor_flash", 0, (16 * 1024 * 1024), 4096, {fal_sfud_init, read, write, erase} };
|
da691fb0536cd2ce7a7a8853cddb87939661a9f6
|
c9bc99866cfab223c777cfb741083be3e9439d81
|
/product/rcar/scp_ramfw/config_timer.c
|
0535364bc6f2ce73c4635f8d8036c4997de864ee
|
[
"BSD-3-Clause"
] |
permissive
|
ARM-software/SCP-firmware
|
4738ca86ce42d82588ddafc2226a1f353ff2c797
|
f6bcca436768359ffeadd84d65e8ea0c3efc7ef1
|
refs/heads/master
| 2023-09-01T16:13:36.962036
| 2023-08-17T13:00:20
| 2023-08-31T07:43:37
| 134,399,880
| 211
| 165
|
NOASSERTION
| 2023-09-13T14:27:10
| 2018-05-22T10:35:56
|
C
|
UTF-8
|
C
| false
| false
| 1,522
|
c
|
config_timer.c
|
/*
* Renesas SCP/MCP Software
* Copyright (c) 2020-2021, Renesas Electronics Corporation. All rights
* reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include "rcar_alarm_idx.h"
#include "system_clock.h"
#include "rcar_irq.h"
#include <mod_timer.h>
#include <mod_rcar_arch_timer.h>
#include <fwk_element.h>
#include <fwk_id.h>
#include <fwk_module.h>
#include <fwk_module_idx.h>
#include <fwk_time.h>
static const struct fwk_element rcar_arch_timer_element_table[] = {
[0] = {
.name = "",
.data = &(struct mod_arch_timer_dev_config) {
.clock_id = FWK_ID_NONE_INIT,
}
},
[1] = { 0 },
};
struct fwk_module_config config_rcar_arch_timer = {
.elements = FWK_MODULE_STATIC_ELEMENTS_PTR(rcar_arch_timer_element_table),
};
static const struct fwk_element timer_element_table[] = {
[0] = {
.name = "REFCLK",
.sub_element_count = RCAR_ALARM_IDX_COUNT,
.data = &(struct mod_timer_dev_config) {
.id = FWK_ID_ELEMENT_INIT(FWK_MODULE_IDX_RCAR_ARCH_TIMER, 0),
.timer_irq = NS_PHYSICAL_TIMER_IRQ,
},
},
[1] = { 0 },
};
struct fwk_time_driver fmw_time_driver(const void **ctx)
{
return mod_arch_timer_driver(ctx, config_rcar_arch_timer.elements.table[0].data);
}
static const struct fwk_element *timer_get_element_table(fwk_id_t module_id)
{
return timer_element_table;
}
struct fwk_module_config config_timer = {
.elements = FWK_MODULE_DYNAMIC_ELEMENTS(timer_get_element_table),
};
|
5b46a38d1f15e724c55a7e6c1fdf1c3764f844d4
|
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
|
/SOFTWARE/A64-TERES/linux-a64/drivers/media/usb/cx231xx/cx231xx.h
|
5ad9fd61d3c887953e0512e217f1388c989dcf0b
|
[
"LicenseRef-scancode-free-unknown",
"Apache-2.0",
"Linux-syscall-note",
"GPL-2.0-only",
"GPL-1.0-or-later"
] |
permissive
|
OLIMEX/DIY-LAPTOP
|
ae82f4ee79c641d9aee444db9a75f3f6709afa92
|
a3fafd1309135650bab27f5eafc0c32bc3ca74ee
|
refs/heads/rel3
| 2023-08-04T01:54:19.483792
| 2023-04-03T07:18:12
| 2023-04-03T07:18:12
| 80,094,055
| 507
| 92
|
Apache-2.0
| 2023-04-03T07:05:59
| 2017-01-26T07:25:50
|
C
|
UTF-8
|
C
| false
| false
| 29,299
|
h
|
cx231xx.h
|
/*
cx231xx.h - driver for Conexant Cx23100/101/102 USB video capture devices
Copyright (C) 2008 <srinivasa.deevi at conexant dot com>
Based on em28xx driver
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef _CX231XX_H
#define _CX231XX_H
#include <linux/videodev2.h>
#include <linux/types.h>
#include <linux/ioctl.h>
#include <linux/i2c.h>
#include <linux/workqueue.h>
#include <linux/mutex.h>
#include <media/cx2341x.h>
#include <media/videobuf-vmalloc.h>
#include <media/v4l2-device.h>
#include <media/v4l2-ctrls.h>
#include <media/v4l2-fh.h>
#include <media/rc-core.h>
#include <media/ir-kbd-i2c.h>
#include <media/videobuf-dvb.h>
#include "cx231xx-reg.h"
#include "cx231xx-pcb-cfg.h"
#include "cx231xx-conf-reg.h"
#define DRIVER_NAME "cx231xx"
#define PWR_SLEEP_INTERVAL 10
/* I2C addresses for control block in Cx231xx */
#define AFE_DEVICE_ADDRESS 0x60
#define I2S_BLK_DEVICE_ADDRESS 0x98
#define VID_BLK_I2C_ADDRESS 0x88
#define VERVE_I2C_ADDRESS 0x40
#define DIF_USE_BASEBAND 0xFFFFFFFF
/* Boards supported by driver */
#define CX231XX_BOARD_UNKNOWN 0
#define CX231XX_BOARD_CNXT_CARRAERA 1
#define CX231XX_BOARD_CNXT_SHELBY 2
#define CX231XX_BOARD_CNXT_RDE_253S 3
#define CX231XX_BOARD_CNXT_RDU_253S 4
#define CX231XX_BOARD_CNXT_VIDEO_GRABBER 5
#define CX231XX_BOARD_CNXT_RDE_250 6
#define CX231XX_BOARD_CNXT_RDU_250 7
#define CX231XX_BOARD_HAUPPAUGE_EXETER 8
#define CX231XX_BOARD_HAUPPAUGE_USBLIVE2 9
#define CX231XX_BOARD_PV_PLAYTV_USB_HYBRID 10
#define CX231XX_BOARD_PV_XCAPTURE_USB 11
#define CX231XX_BOARD_KWORLD_UB430_USB_HYBRID 12
#define CX231XX_BOARD_ICONBIT_U100 13
#define CX231XX_BOARD_HAUPPAUGE_USB2_FM_PAL 14
#define CX231XX_BOARD_HAUPPAUGE_USB2_FM_NTSC 15
#define CX231XX_BOARD_ELGATO_VIDEO_CAPTURE_V2 16
#define CX231XX_BOARD_OTG102 17
/* Limits minimum and default number of buffers */
#define CX231XX_MIN_BUF 4
#define CX231XX_DEF_BUF 12
#define CX231XX_DEF_VBI_BUF 6
#define VBI_LINE_COUNT 17
#define VBI_LINE_LENGTH 1440
/*Limits the max URB message size */
#define URB_MAX_CTRL_SIZE 80
/* Params for validated field */
#define CX231XX_BOARD_NOT_VALIDATED 1
#define CX231XX_BOARD_VALIDATED 0
/* maximum number of cx231xx boards */
#define CX231XX_MAXBOARDS 8
/* maximum number of frames that can be queued */
#define CX231XX_NUM_FRAMES 5
/* number of buffers for isoc transfers */
#define CX231XX_NUM_BUFS 8
/* number of packets for each buffer
windows requests only 40 packets .. so we better do the same
this is what I found out for all alternate numbers there!
*/
#define CX231XX_NUM_PACKETS 40
/* default alternate; 0 means choose the best */
#define CX231XX_PINOUT 0
#define CX231XX_INTERLACED_DEFAULT 1
/* time to wait when stopping the isoc transfer */
#define CX231XX_URB_TIMEOUT \
msecs_to_jiffies(CX231XX_NUM_BUFS * CX231XX_NUM_PACKETS)
#define CX231xx_NORMS (\
V4L2_STD_NTSC_M | V4L2_STD_NTSC_M_JP | V4L2_STD_NTSC_443 | \
V4L2_STD_PAL_BG | V4L2_STD_PAL_DK | V4L2_STD_PAL_I | \
V4L2_STD_PAL_M | V4L2_STD_PAL_N | V4L2_STD_PAL_Nc | \
V4L2_STD_PAL_60 | V4L2_STD_SECAM_L | V4L2_STD_SECAM_DK)
#define SLEEP_S5H1432 30
#define CX23417_OSC_EN 8
#define CX23417_RESET 9
struct cx23417_fmt {
char *name;
u32 fourcc; /* v4l2 format id */
int depth;
int flags;
u32 cxformat;
};
enum cx231xx_mode {
CX231XX_SUSPEND,
CX231XX_ANALOG_MODE,
CX231XX_DIGITAL_MODE,
};
enum cx231xx_std_mode {
CX231XX_TV_AIR = 0,
CX231XX_TV_CABLE
};
enum cx231xx_stream_state {
STREAM_OFF,
STREAM_INTERRUPT,
STREAM_ON,
};
struct cx231xx;
struct cx231xx_isoc_ctl {
/* max packet size of isoc transaction */
int max_pkt_size;
/* number of allocated urbs */
int num_bufs;
/* urb for isoc transfers */
struct urb **urb;
/* transfer buffers for isoc transfer */
char **transfer_buffer;
/* Last buffer command and region */
u8 cmd;
int pos, size, pktsize;
/* Last field: ODD or EVEN? */
int field;
/* Stores incomplete commands */
u32 tmp_buf;
int tmp_buf_len;
/* Stores already requested buffers */
struct cx231xx_buffer *buf;
/* Stores the number of received fields */
int nfields;
/* isoc urb callback */
int (*isoc_copy) (struct cx231xx *dev, struct urb *urb);
};
struct cx231xx_bulk_ctl {
/* max packet size of bulk transaction */
int max_pkt_size;
/* number of allocated urbs */
int num_bufs;
/* urb for bulk transfers */
struct urb **urb;
/* transfer buffers for bulk transfer */
char **transfer_buffer;
/* Last buffer command and region */
u8 cmd;
int pos, size, pktsize;
/* Last field: ODD or EVEN? */
int field;
/* Stores incomplete commands */
u32 tmp_buf;
int tmp_buf_len;
/* Stores already requested buffers */
struct cx231xx_buffer *buf;
/* Stores the number of received fields */
int nfields;
/* bulk urb callback */
int (*bulk_copy) (struct cx231xx *dev, struct urb *urb);
};
struct cx231xx_fmt {
char *name;
u32 fourcc; /* v4l2 format id */
int depth;
int reg;
};
/* buffer for one video frame */
struct cx231xx_buffer {
/* common v4l buffer stuff -- must be first */
struct videobuf_buffer vb;
struct list_head frame;
int top_field;
int receiving;
};
enum ps_package_head {
CX231XX_NEED_ADD_PS_PACKAGE_HEAD = 0,
CX231XX_NONEED_PS_PACKAGE_HEAD
};
struct cx231xx_dmaqueue {
struct list_head active;
struct list_head queued;
wait_queue_head_t wq;
/* Counters to control buffer fill */
int pos;
u8 is_partial_line;
u8 partial_buf[8];
u8 last_sav;
int current_field;
u32 bytes_left_in_line;
u32 lines_completed;
u8 field1_done;
u32 lines_per_field;
/*Mpeg2 control buffer*/
u8 *p_left_data;
u32 left_data_count;
u8 mpeg_buffer_done;
u32 mpeg_buffer_completed;
enum ps_package_head add_ps_package_head;
char ps_head[10];
};
/* inputs */
#define MAX_CX231XX_INPUT 4
enum cx231xx_itype {
CX231XX_VMUX_COMPOSITE1 = 1,
CX231XX_VMUX_SVIDEO,
CX231XX_VMUX_TELEVISION,
CX231XX_VMUX_CABLE,
CX231XX_RADIO,
CX231XX_VMUX_DVB,
CX231XX_VMUX_DEBUG
};
enum cx231xx_v_input {
CX231XX_VIN_1_1 = 0x1,
CX231XX_VIN_2_1,
CX231XX_VIN_3_1,
CX231XX_VIN_4_1,
CX231XX_VIN_1_2 = 0x01,
CX231XX_VIN_2_2,
CX231XX_VIN_3_2,
CX231XX_VIN_1_3 = 0x1,
CX231XX_VIN_2_3,
CX231XX_VIN_3_3,
};
/* cx231xx has two audio inputs: tuner and line in */
enum cx231xx_amux {
/* This is the only entry for cx231xx tuner input */
CX231XX_AMUX_VIDEO, /* cx231xx tuner */
CX231XX_AMUX_LINE_IN, /* Line In */
};
struct cx231xx_reg_seq {
unsigned char bit;
unsigned char val;
int sleep;
};
struct cx231xx_input {
enum cx231xx_itype type;
unsigned int vmux;
enum cx231xx_amux amux;
struct cx231xx_reg_seq *gpio;
};
#define INPUT(nr) (&cx231xx_boards[dev->model].input[nr])
enum cx231xx_decoder {
CX231XX_NODECODER,
CX231XX_AVDECODER
};
enum CX231XX_I2C_MASTER_PORT {
I2C_0 = 0,
I2C_1 = 1,
I2C_2 = 2,
I2C_3 = 3
};
struct cx231xx_board {
char *name;
int vchannels;
int tuner_type;
int tuner_addr;
v4l2_std_id norm; /* tv norm */
/* demod related */
int demod_addr;
u8 demod_xfer_mode; /* 0 - Serial; 1 - parallel */
/* GPIO Pins */
struct cx231xx_reg_seq *dvb_gpio;
struct cx231xx_reg_seq *suspend_gpio;
struct cx231xx_reg_seq *tuner_gpio;
/* Negative means don't use it */
s8 tuner_sif_gpio;
s8 tuner_scl_gpio;
s8 tuner_sda_gpio;
/* PIN ctrl */
u32 ctl_pin_status_mask;
u8 agc_analog_digital_select_gpio;
u32 gpio_pin_status_mask;
/* i2c masters */
u8 tuner_i2c_master;
u8 demod_i2c_master;
u8 ir_i2c_master;
/* for devices with I2C chips for IR */
char *rc_map_name;
unsigned int max_range_640_480:1;
unsigned int has_dvb:1;
unsigned int has_417:1;
unsigned int valid:1;
unsigned int no_alt_vanc:1;
unsigned int external_av:1;
unsigned int dont_use_port_3:1;
unsigned char xclk, i2c_speed;
enum cx231xx_decoder decoder;
int output_mode;
struct cx231xx_input input[MAX_CX231XX_INPUT];
struct cx231xx_input radio;
struct rc_map *ir_codes;
};
/* device states */
enum cx231xx_dev_state {
DEV_INITIALIZED = 0x01,
DEV_DISCONNECTED = 0x02,
};
enum AFE_MODE {
AFE_MODE_LOW_IF,
AFE_MODE_BASEBAND,
AFE_MODE_EU_HI_IF,
AFE_MODE_US_HI_IF,
AFE_MODE_JAPAN_HI_IF
};
enum AUDIO_INPUT {
AUDIO_INPUT_MUTE,
AUDIO_INPUT_LINE,
AUDIO_INPUT_TUNER_TV,
AUDIO_INPUT_SPDIF,
AUDIO_INPUT_TUNER_FM
};
#define CX231XX_AUDIO_BUFS 5
#define CX231XX_NUM_AUDIO_PACKETS 16
#define CX231XX_ISO_NUM_AUDIO_PACKETS 64
/* cx231xx extensions */
#define CX231XX_AUDIO 0x10
#define CX231XX_DVB 0x20
struct cx231xx_audio {
char name[50];
char *transfer_buffer[CX231XX_AUDIO_BUFS];
struct urb *urb[CX231XX_AUDIO_BUFS];
struct usb_device *udev;
unsigned int capture_transfer_done;
struct snd_pcm_substream *capture_pcm_substream;
unsigned int hwptr_done_capture;
struct snd_card *sndcard;
int users, shutdown;
/* locks */
spinlock_t slock;
int alt; /* alternate */
int max_pkt_size; /* max packet size of isoc transaction */
int num_alt; /* Number of alternative settings */
unsigned int *alt_max_pkt_size; /* array of wMaxPacketSize */
u16 end_point_addr;
};
struct cx231xx;
struct cx231xx_fh {
struct v4l2_fh fh;
struct cx231xx *dev;
unsigned int stream_on:1; /* Locks streams */
enum v4l2_buf_type type;
struct videobuf_queue vb_vidq;
/* vbi capture */
struct videobuf_queue vidq;
struct videobuf_queue vbiq;
/* MPEG Encoder specifics ONLY */
atomic_t v4l_reading;
};
/*****************************************************************/
/* set/get i2c */
/* 00--1Mb/s, 01-400kb/s, 10--100kb/s, 11--5Mb/s */
#define I2C_SPEED_1M 0x0
#define I2C_SPEED_400K 0x1
#define I2C_SPEED_100K 0x2
#define I2C_SPEED_5M 0x3
/* 0-- STOP transaction */
#define I2C_STOP 0x0
/* 1-- do not transmit STOP at end of transaction */
#define I2C_NOSTOP 0x1
/* 1--allow slave to insert clock wait states */
#define I2C_SYNC 0x1
struct cx231xx_i2c {
struct cx231xx *dev;
int nr;
/* i2c i/o */
struct i2c_adapter i2c_adap;
struct i2c_client i2c_client;
u32 i2c_rc;
/* different settings for each bus */
u8 i2c_period;
u8 i2c_nostop;
u8 i2c_reserve;
};
struct cx231xx_i2c_xfer_data {
u8 dev_addr;
u8 direction; /* 1 - IN, 0 - OUT */
u8 saddr_len; /* sub address len */
u16 saddr_dat; /* sub addr data */
u8 buf_size; /* buffer size */
u8 *p_buffer; /* pointer to the buffer */
};
struct VENDOR_REQUEST_IN {
u8 bRequest;
u16 wValue;
u16 wIndex;
u16 wLength;
u8 direction;
u8 bData;
u8 *pBuff;
};
struct cx231xx_tvnorm {
char *name;
v4l2_std_id id;
u32 cxiformat;
u32 cxoformat;
};
enum TRANSFER_TYPE {
Raw_Video = 0,
Audio,
Vbi, /* VANC */
Sliced_cc, /* HANC */
TS1_serial_mode,
TS2,
TS1_parallel_mode
} ;
struct cx231xx_video_mode {
/* Isoc control struct */
struct cx231xx_dmaqueue vidq;
struct cx231xx_isoc_ctl isoc_ctl;
struct cx231xx_bulk_ctl bulk_ctl;
/* locks */
spinlock_t slock;
/* usb transfer */
int alt; /* alternate */
int max_pkt_size; /* max packet size of isoc transaction */
int num_alt; /* Number of alternative settings */
unsigned int *alt_max_pkt_size; /* array of wMaxPacketSize */
u16 end_point_addr;
};
/*
struct cx23885_dmaqueue {
struct list_head active;
struct list_head queued;
struct timer_list timeout;
struct btcx_riscmem stopper;
u32 count;
};
*/
struct cx231xx_tsport {
struct cx231xx *dev;
int nr;
int sram_chno;
struct videobuf_dvb_frontends frontends;
/* dma queues */
u32 ts_packet_size;
u32 ts_packet_count;
int width;
int height;
/* locks */
spinlock_t slock;
/* registers */
u32 reg_gpcnt;
u32 reg_gpcnt_ctl;
u32 reg_dma_ctl;
u32 reg_lngth;
u32 reg_hw_sop_ctrl;
u32 reg_gen_ctrl;
u32 reg_bd_pkt_status;
u32 reg_sop_status;
u32 reg_fifo_ovfl_stat;
u32 reg_vld_misc;
u32 reg_ts_clk_en;
u32 reg_ts_int_msk;
u32 reg_ts_int_stat;
u32 reg_src_sel;
/* Default register vals */
int pci_irqmask;
u32 dma_ctl_val;
u32 ts_int_msk_val;
u32 gen_ctrl_val;
u32 ts_clk_en_val;
u32 src_sel_val;
u32 vld_misc_val;
u32 hw_sop_ctrl_val;
/* Allow a single tsport to have multiple frontends */
u32 num_frontends;
void *port_priv;
};
/* main device struct */
struct cx231xx {
/* generic device properties */
char name[30]; /* name (including minor) of the device */
int model; /* index in the device_data struct */
int devno; /* marks the number of this device */
struct cx231xx_board board;
/* For I2C IR support */
struct IR_i2c_init_data init_data;
struct i2c_client *ir_i2c_client;
unsigned int stream_on:1; /* Locks streams */
unsigned int vbi_stream_on:1; /* Locks streams for VBI */
unsigned int has_audio_class:1;
unsigned int has_alsa_audio:1;
struct cx231xx_fmt *format;
struct v4l2_device v4l2_dev;
struct v4l2_subdev *sd_cx25840;
struct v4l2_subdev *sd_tuner;
struct v4l2_ctrl_handler ctrl_handler;
struct v4l2_ctrl_handler radio_ctrl_handler;
struct cx2341x_handler mpeg_ctrl_handler;
struct work_struct wq_trigger; /* Trigger to start/stop audio for alsa module */
atomic_t stream_started; /* stream should be running if true */
struct list_head devlist;
int tuner_type; /* type of the tuner */
int tuner_addr; /* tuner address */
/* I2C adapters: Master 1 & 2 (External) & Master 3 (Internal only) */
struct cx231xx_i2c i2c_bus[3];
unsigned int xc_fw_load_done:1;
/* locks */
struct mutex gpio_i2c_lock;
struct mutex i2c_lock;
/* video for linux */
int users; /* user count for exclusive use */
struct video_device *vdev; /* video for linux device struct */
v4l2_std_id norm; /* selected tv norm */
int ctl_freq; /* selected frequency */
unsigned int ctl_ainput; /* selected audio input */
/* frame properties */
int width; /* current frame width */
int height; /* current frame height */
int interlaced; /* 1=interlace fileds, 0=just top fileds */
struct cx231xx_audio adev;
/* states */
enum cx231xx_dev_state state;
struct work_struct request_module_wk;
/* locks */
struct mutex lock;
struct mutex ctrl_urb_lock; /* protects urb_buf */
struct list_head inqueue, outqueue;
wait_queue_head_t open, wait_frame, wait_stream;
struct video_device *vbi_dev;
struct video_device *radio_dev;
unsigned char eedata[256];
struct cx231xx_video_mode video_mode;
struct cx231xx_video_mode vbi_mode;
struct cx231xx_video_mode sliced_cc_mode;
struct cx231xx_video_mode ts1_mode;
atomic_t devlist_count;
struct usb_device *udev; /* the usb device */
char urb_buf[URB_MAX_CTRL_SIZE]; /* urb control msg buffer */
/* helper funcs that call usb_control_msg */
int (*cx231xx_read_ctrl_reg) (struct cx231xx *dev, u8 req, u16 reg,
char *buf, int len);
int (*cx231xx_write_ctrl_reg) (struct cx231xx *dev, u8 req, u16 reg,
char *buf, int len);
int (*cx231xx_send_usb_command) (struct cx231xx_i2c *i2c_bus,
struct cx231xx_i2c_xfer_data *req_data);
int (*cx231xx_gpio_i2c_read) (struct cx231xx *dev, u8 dev_addr,
u8 *buf, u8 len);
int (*cx231xx_gpio_i2c_write) (struct cx231xx *dev, u8 dev_addr,
u8 *buf, u8 len);
int (*cx231xx_set_analog_freq) (struct cx231xx *dev, u32 freq);
int (*cx231xx_reset_analog_tuner) (struct cx231xx *dev);
enum cx231xx_mode mode;
struct cx231xx_dvb *dvb;
/* Cx231xx supported PCB config's */
struct pcb_config current_pcb_config;
u8 current_scenario_idx;
u8 interface_count;
u8 max_iad_interface_count;
/* GPIO related register direction and values */
u32 gpio_dir;
u32 gpio_val;
/* Power Modes */
int power_mode;
/* afe parameters */
enum AFE_MODE afe_mode;
u32 afe_ref_count;
/* video related parameters */
u32 video_input;
u32 active_mode;
u8 vbi_or_sliced_cc_mode; /* 0 - vbi ; 1 - sliced cc mode */
enum cx231xx_std_mode std_mode; /* 0 - Air; 1 - cable */
/*mode: digital=1 or analog=0*/
u8 mode_tv;
u8 USE_ISO;
struct cx231xx_tvnorm encodernorm;
struct cx231xx_tsport ts1, ts2;
struct video_device *v4l_device;
atomic_t v4l_reader_count;
u32 freq;
unsigned int input;
u32 cx23417_mailbox;
u32 __iomem *lmmio;
u8 __iomem *bmmio;
};
extern struct list_head cx231xx_devlist;
#define cx25840_call(cx231xx, o, f, args...) \
v4l2_subdev_call(cx231xx->sd_cx25840, o, f, ##args)
#define tuner_call(cx231xx, o, f, args...) \
v4l2_subdev_call(cx231xx->sd_tuner, o, f, ##args)
#define call_all(dev, o, f, args...) \
v4l2_device_call_until_err(&dev->v4l2_dev, 0, o, f, ##args)
struct cx231xx_ops {
struct list_head next;
char *name;
int id;
int (*init) (struct cx231xx *);
int (*fini) (struct cx231xx *);
};
/* call back functions in dvb module */
int cx231xx_set_analog_freq(struct cx231xx *dev, u32 freq);
int cx231xx_reset_analog_tuner(struct cx231xx *dev);
/* Provided by cx231xx-i2c.c */
void cx231xx_do_i2c_scan(struct cx231xx *dev, struct i2c_client *c);
int cx231xx_i2c_register(struct cx231xx_i2c *bus);
int cx231xx_i2c_unregister(struct cx231xx_i2c *bus);
/* Internal block control functions */
int cx231xx_read_i2c_master(struct cx231xx *dev, u8 dev_addr, u16 saddr,
u8 saddr_len, u32 *data, u8 data_len, int master);
int cx231xx_write_i2c_master(struct cx231xx *dev, u8 dev_addr, u16 saddr,
u8 saddr_len, u32 data, u8 data_len, int master);
int cx231xx_read_i2c_data(struct cx231xx *dev, u8 dev_addr,
u16 saddr, u8 saddr_len, u32 *data, u8 data_len);
int cx231xx_write_i2c_data(struct cx231xx *dev, u8 dev_addr,
u16 saddr, u8 saddr_len, u32 data, u8 data_len);
int cx231xx_reg_mask_write(struct cx231xx *dev, u8 dev_addr, u8 size,
u16 register_address, u8 bit_start, u8 bit_end,
u32 value);
int cx231xx_read_modify_write_i2c_dword(struct cx231xx *dev, u8 dev_addr,
u16 saddr, u32 mask, u32 value);
u32 cx231xx_set_field(u32 field_mask, u32 data);
/*verve r/w*/
void initGPIO(struct cx231xx *dev);
void uninitGPIO(struct cx231xx *dev);
/* afe related functions */
int cx231xx_afe_init_super_block(struct cx231xx *dev, u32 ref_count);
int cx231xx_afe_init_channels(struct cx231xx *dev);
int cx231xx_afe_setup_AFE_for_baseband(struct cx231xx *dev);
int cx231xx_afe_set_input_mux(struct cx231xx *dev, u32 input_mux);
int cx231xx_afe_set_mode(struct cx231xx *dev, enum AFE_MODE mode);
int cx231xx_afe_update_power_control(struct cx231xx *dev,
enum AV_MODE avmode);
int cx231xx_afe_adjust_ref_count(struct cx231xx *dev, u32 video_input);
/* i2s block related functions */
int cx231xx_i2s_blk_initialize(struct cx231xx *dev);
int cx231xx_i2s_blk_update_power_control(struct cx231xx *dev,
enum AV_MODE avmode);
int cx231xx_i2s_blk_set_audio_input(struct cx231xx *dev, u8 audio_input);
/* DIF related functions */
int cx231xx_dif_configure_C2HH_for_low_IF(struct cx231xx *dev, u32 mode,
u32 function_mode, u32 standard);
void cx231xx_set_Colibri_For_LowIF(struct cx231xx *dev, u32 if_freq,
u8 spectral_invert, u32 mode);
u32 cx231xx_Get_Colibri_CarrierOffset(u32 mode, u32 standerd);
void cx231xx_set_DIF_bandpass(struct cx231xx *dev, u32 if_freq,
u8 spectral_invert, u32 mode);
void cx231xx_Setup_AFE_for_LowIF(struct cx231xx *dev);
void reset_s5h1432_demod(struct cx231xx *dev);
void cx231xx_dump_HH_reg(struct cx231xx *dev);
void update_HH_register_after_set_DIF(struct cx231xx *dev);
void cx231xx_dump_SC_reg(struct cx231xx *dev);
int cx231xx_dif_set_standard(struct cx231xx *dev, u32 standard);
int cx231xx_tuner_pre_channel_change(struct cx231xx *dev);
int cx231xx_tuner_post_channel_change(struct cx231xx *dev);
/* video parser functions */
u8 cx231xx_find_next_SAV_EAV(u8 *p_buffer, u32 buffer_size,
u32 *p_bytes_used);
u8 cx231xx_find_boundary_SAV_EAV(u8 *p_buffer, u8 *partial_buf,
u32 *p_bytes_used);
int cx231xx_do_copy(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q,
u8 *p_buffer, u32 bytes_to_copy);
void cx231xx_reset_video_buffer(struct cx231xx *dev,
struct cx231xx_dmaqueue *dma_q);
u8 cx231xx_is_buffer_done(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q);
u32 cx231xx_copy_video_line(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q,
u8 *p_line, u32 length, int field_number);
u32 cx231xx_get_video_line(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q,
u8 sav_eav, u8 *p_buffer, u32 buffer_size);
void cx231xx_swab(u16 *from, u16 *to, u16 len);
/* Provided by cx231xx-core.c */
u32 cx231xx_request_buffers(struct cx231xx *dev, u32 count);
void cx231xx_queue_unusedframes(struct cx231xx *dev);
void cx231xx_release_buffers(struct cx231xx *dev);
/* read from control pipe */
int cx231xx_read_ctrl_reg(struct cx231xx *dev, u8 req, u16 reg,
char *buf, int len);
/* write to control pipe */
int cx231xx_write_ctrl_reg(struct cx231xx *dev, u8 req, u16 reg,
char *buf, int len);
int cx231xx_mode_register(struct cx231xx *dev, u16 address, u32 mode);
int cx231xx_send_vendor_cmd(struct cx231xx *dev,
struct VENDOR_REQUEST_IN *ven_req);
int cx231xx_send_usb_command(struct cx231xx_i2c *i2c_bus,
struct cx231xx_i2c_xfer_data *req_data);
/* Gpio related functions */
int cx231xx_send_gpio_cmd(struct cx231xx *dev, u32 gpio_bit, u8 *gpio_val,
u8 len, u8 request, u8 direction);
int cx231xx_set_gpio_value(struct cx231xx *dev, int pin_number, int pin_value);
int cx231xx_set_gpio_direction(struct cx231xx *dev, int pin_number,
int pin_value);
int cx231xx_gpio_i2c_start(struct cx231xx *dev);
int cx231xx_gpio_i2c_end(struct cx231xx *dev);
int cx231xx_gpio_i2c_write_byte(struct cx231xx *dev, u8 data);
int cx231xx_gpio_i2c_read_byte(struct cx231xx *dev, u8 *buf);
int cx231xx_gpio_i2c_read_ack(struct cx231xx *dev);
int cx231xx_gpio_i2c_write_ack(struct cx231xx *dev);
int cx231xx_gpio_i2c_write_nak(struct cx231xx *dev);
int cx231xx_gpio_i2c_read(struct cx231xx *dev, u8 dev_addr, u8 *buf, u8 len);
int cx231xx_gpio_i2c_write(struct cx231xx *dev, u8 dev_addr, u8 *buf, u8 len);
/* audio related functions */
int cx231xx_set_audio_decoder_input(struct cx231xx *dev,
enum AUDIO_INPUT audio_input);
int cx231xx_capture_start(struct cx231xx *dev, int start, u8 media_type);
int cx231xx_set_video_alternate(struct cx231xx *dev);
int cx231xx_set_alt_setting(struct cx231xx *dev, u8 index, u8 alt);
int is_fw_load(struct cx231xx *dev);
int cx231xx_check_fw(struct cx231xx *dev);
int cx231xx_init_isoc(struct cx231xx *dev, int max_packets,
int num_bufs, int max_pkt_size,
int (*isoc_copy) (struct cx231xx *dev,
struct urb *urb));
int cx231xx_init_bulk(struct cx231xx *dev, int max_packets,
int num_bufs, int max_pkt_size,
int (*bulk_copy) (struct cx231xx *dev,
struct urb *urb));
void cx231xx_stop_TS1(struct cx231xx *dev);
void cx231xx_start_TS1(struct cx231xx *dev);
void cx231xx_uninit_isoc(struct cx231xx *dev);
void cx231xx_uninit_bulk(struct cx231xx *dev);
int cx231xx_set_mode(struct cx231xx *dev, enum cx231xx_mode set_mode);
int cx231xx_unmute_audio(struct cx231xx *dev);
int cx231xx_ep5_bulkout(struct cx231xx *dev, u8 *firmware, u16 size);
void cx231xx_disable656(struct cx231xx *dev);
void cx231xx_enable656(struct cx231xx *dev);
int cx231xx_demod_reset(struct cx231xx *dev);
int cx231xx_gpio_set(struct cx231xx *dev, struct cx231xx_reg_seq *gpio);
/* Device list functions */
void cx231xx_release_resources(struct cx231xx *dev);
void cx231xx_release_analog_resources(struct cx231xx *dev);
int cx231xx_register_analog_devices(struct cx231xx *dev);
void cx231xx_remove_from_devlist(struct cx231xx *dev);
void cx231xx_add_into_devlist(struct cx231xx *dev);
void cx231xx_init_extension(struct cx231xx *dev);
void cx231xx_close_extension(struct cx231xx *dev);
/* hardware init functions */
int cx231xx_dev_init(struct cx231xx *dev);
void cx231xx_dev_uninit(struct cx231xx *dev);
void cx231xx_config_i2c(struct cx231xx *dev);
int cx231xx_config(struct cx231xx *dev);
/* Stream control functions */
int cx231xx_start_stream(struct cx231xx *dev, u32 ep_mask);
int cx231xx_stop_stream(struct cx231xx *dev, u32 ep_mask);
int cx231xx_initialize_stream_xfer(struct cx231xx *dev, u32 media_type);
/* Power control functions */
int cx231xx_set_power_mode(struct cx231xx *dev, enum AV_MODE mode);
int cx231xx_power_suspend(struct cx231xx *dev);
/* chip specific control functions */
int cx231xx_init_ctrl_pin_status(struct cx231xx *dev);
int cx231xx_set_agc_analog_digital_mux_select(struct cx231xx *dev,
u8 analog_or_digital);
int cx231xx_enable_i2c_port_3(struct cx231xx *dev, bool is_port_3);
/* video audio decoder related functions */
void video_mux(struct cx231xx *dev, int index);
int cx231xx_set_video_input_mux(struct cx231xx *dev, u8 input);
int cx231xx_set_decoder_video_input(struct cx231xx *dev, u8 pin_type, u8 input);
int cx231xx_do_mode_ctrl_overrides(struct cx231xx *dev);
int cx231xx_set_audio_input(struct cx231xx *dev, u8 input);
/* Provided by cx231xx-video.c */
int cx231xx_register_extension(struct cx231xx_ops *dev);
void cx231xx_unregister_extension(struct cx231xx_ops *dev);
void cx231xx_init_extension(struct cx231xx *dev);
void cx231xx_close_extension(struct cx231xx *dev);
int cx231xx_querycap(struct file *file, void *priv,
struct v4l2_capability *cap);
int cx231xx_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t);
int cx231xx_s_tuner(struct file *file, void *priv, const struct v4l2_tuner *t);
int cx231xx_g_frequency(struct file *file, void *priv,
struct v4l2_frequency *f);
int cx231xx_s_frequency(struct file *file, void *priv,
const struct v4l2_frequency *f);
int cx231xx_enum_input(struct file *file, void *priv,
struct v4l2_input *i);
int cx231xx_g_input(struct file *file, void *priv, unsigned int *i);
int cx231xx_s_input(struct file *file, void *priv, unsigned int i);
int cx231xx_g_chip_ident(struct file *file, void *fh, struct v4l2_dbg_chip_ident *chip);
int cx231xx_g_register(struct file *file, void *priv,
struct v4l2_dbg_register *reg);
int cx231xx_s_register(struct file *file, void *priv,
const struct v4l2_dbg_register *reg);
/* Provided by cx231xx-cards.c */
extern void cx231xx_pre_card_setup(struct cx231xx *dev);
extern void cx231xx_card_setup(struct cx231xx *dev);
extern struct cx231xx_board cx231xx_boards[];
extern struct usb_device_id cx231xx_id_table[];
extern const unsigned int cx231xx_bcount;
int cx231xx_tuner_callback(void *ptr, int component, int command, int arg);
/* cx23885-417.c */
extern int cx231xx_417_register(struct cx231xx *dev);
extern void cx231xx_417_unregister(struct cx231xx *dev);
/* cx23885-input.c */
#if defined(CONFIG_VIDEO_CX231XX_RC)
int cx231xx_ir_init(struct cx231xx *dev);
void cx231xx_ir_exit(struct cx231xx *dev);
#else
#define cx231xx_ir_init(dev) (0)
#define cx231xx_ir_exit(dev) (0)
#endif
/* printk macros */
#define cx231xx_err(fmt, arg...) do {\
printk(KERN_ERR fmt , ##arg); } while (0)
#define cx231xx_errdev(fmt, arg...) do {\
printk(KERN_ERR "%s: "fmt,\
dev->name , ##arg); } while (0)
#define cx231xx_info(fmt, arg...) do {\
printk(KERN_INFO "%s: "fmt,\
dev->name , ##arg); } while (0)
#define cx231xx_warn(fmt, arg...) do {\
printk(KERN_WARNING "%s: "fmt,\
dev->name , ##arg); } while (0)
static inline unsigned int norm_maxw(struct cx231xx *dev)
{
if (dev->board.max_range_640_480)
return 640;
else
return 720;
}
static inline unsigned int norm_maxh(struct cx231xx *dev)
{
if (dev->board.max_range_640_480)
return 480;
else
return (dev->norm & V4L2_STD_625_50) ? 576 : 480;
}
#endif
|
f15a20a8b5da00b710a83855c3d8112cd8ddf705
|
724f3b4ef1f540bce8593ed90887704d28d8006b
|
/extern/glfw/deps/tinycthread.c
|
f9cea2ed8c8587b442bffb1167c672af62826dc4
|
[
"MIT",
"Zlib"
] |
permissive
|
InteractiveComputerGraphics/PositionBasedDynamics
|
c1a1540b3f46d5c080e9b19dd0c86ac94f4eaebd
|
00db2e091a88a628099787cf6fada941e851dbfa
|
refs/heads/master
| 2023-09-01T11:14:03.256028
| 2023-08-18T14:53:38
| 2023-08-18T14:53:38
| 35,102,707
| 1,569
| 320
|
MIT
| 2023-08-18T14:53:39
| 2015-05-05T13:50:44
|
C++
|
UTF-8
|
C
| false
| false
| 13,065
|
c
|
tinycthread.c
|
/* -*- mode: c; tab-width: 2; indent-tabs-mode: nil; -*-
Copyright (c) 2012 Marcus Geelnard
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*/
/* 2013-01-06 Camilla Löwy <elmindreda@glfw.org>
*
* Added casts from time_t to DWORD to avoid warnings on VC++.
* Fixed time retrieval on POSIX systems.
*/
#include "tinycthread.h"
#include <stdlib.h>
/* Platform specific includes */
#if defined(_TTHREAD_POSIX_)
#include <signal.h>
#include <sched.h>
#include <unistd.h>
#include <sys/time.h>
#include <errno.h>
#elif defined(_TTHREAD_WIN32_)
#include <process.h>
#include <sys/timeb.h>
#endif
/* Standard, good-to-have defines */
#ifndef NULL
#define NULL (void*)0
#endif
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
int mtx_init(mtx_t *mtx, int type)
{
#if defined(_TTHREAD_WIN32_)
mtx->mAlreadyLocked = FALSE;
mtx->mRecursive = type & mtx_recursive;
InitializeCriticalSection(&mtx->mHandle);
return thrd_success;
#else
int ret;
pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr);
if (type & mtx_recursive)
{
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
}
ret = pthread_mutex_init(mtx, &attr);
pthread_mutexattr_destroy(&attr);
return ret == 0 ? thrd_success : thrd_error;
#endif
}
void mtx_destroy(mtx_t *mtx)
{
#if defined(_TTHREAD_WIN32_)
DeleteCriticalSection(&mtx->mHandle);
#else
pthread_mutex_destroy(mtx);
#endif
}
int mtx_lock(mtx_t *mtx)
{
#if defined(_TTHREAD_WIN32_)
EnterCriticalSection(&mtx->mHandle);
if (!mtx->mRecursive)
{
while(mtx->mAlreadyLocked) Sleep(1000); /* Simulate deadlock... */
mtx->mAlreadyLocked = TRUE;
}
return thrd_success;
#else
return pthread_mutex_lock(mtx) == 0 ? thrd_success : thrd_error;
#endif
}
int mtx_timedlock(mtx_t *mtx, const struct timespec *ts)
{
/* FIXME! */
(void)mtx;
(void)ts;
return thrd_error;
}
int mtx_trylock(mtx_t *mtx)
{
#if defined(_TTHREAD_WIN32_)
int ret = TryEnterCriticalSection(&mtx->mHandle) ? thrd_success : thrd_busy;
if ((!mtx->mRecursive) && (ret == thrd_success) && mtx->mAlreadyLocked)
{
LeaveCriticalSection(&mtx->mHandle);
ret = thrd_busy;
}
return ret;
#else
return (pthread_mutex_trylock(mtx) == 0) ? thrd_success : thrd_busy;
#endif
}
int mtx_unlock(mtx_t *mtx)
{
#if defined(_TTHREAD_WIN32_)
mtx->mAlreadyLocked = FALSE;
LeaveCriticalSection(&mtx->mHandle);
return thrd_success;
#else
return pthread_mutex_unlock(mtx) == 0 ? thrd_success : thrd_error;;
#endif
}
#if defined(_TTHREAD_WIN32_)
#define _CONDITION_EVENT_ONE 0
#define _CONDITION_EVENT_ALL 1
#endif
int cnd_init(cnd_t *cond)
{
#if defined(_TTHREAD_WIN32_)
cond->mWaitersCount = 0;
/* Init critical section */
InitializeCriticalSection(&cond->mWaitersCountLock);
/* Init events */
cond->mEvents[_CONDITION_EVENT_ONE] = CreateEvent(NULL, FALSE, FALSE, NULL);
if (cond->mEvents[_CONDITION_EVENT_ONE] == NULL)
{
cond->mEvents[_CONDITION_EVENT_ALL] = NULL;
return thrd_error;
}
cond->mEvents[_CONDITION_EVENT_ALL] = CreateEvent(NULL, TRUE, FALSE, NULL);
if (cond->mEvents[_CONDITION_EVENT_ALL] == NULL)
{
CloseHandle(cond->mEvents[_CONDITION_EVENT_ONE]);
cond->mEvents[_CONDITION_EVENT_ONE] = NULL;
return thrd_error;
}
return thrd_success;
#else
return pthread_cond_init(cond, NULL) == 0 ? thrd_success : thrd_error;
#endif
}
void cnd_destroy(cnd_t *cond)
{
#if defined(_TTHREAD_WIN32_)
if (cond->mEvents[_CONDITION_EVENT_ONE] != NULL)
{
CloseHandle(cond->mEvents[_CONDITION_EVENT_ONE]);
}
if (cond->mEvents[_CONDITION_EVENT_ALL] != NULL)
{
CloseHandle(cond->mEvents[_CONDITION_EVENT_ALL]);
}
DeleteCriticalSection(&cond->mWaitersCountLock);
#else
pthread_cond_destroy(cond);
#endif
}
int cnd_signal(cnd_t *cond)
{
#if defined(_TTHREAD_WIN32_)
int haveWaiters;
/* Are there any waiters? */
EnterCriticalSection(&cond->mWaitersCountLock);
haveWaiters = (cond->mWaitersCount > 0);
LeaveCriticalSection(&cond->mWaitersCountLock);
/* If we have any waiting threads, send them a signal */
if(haveWaiters)
{
if (SetEvent(cond->mEvents[_CONDITION_EVENT_ONE]) == 0)
{
return thrd_error;
}
}
return thrd_success;
#else
return pthread_cond_signal(cond) == 0 ? thrd_success : thrd_error;
#endif
}
int cnd_broadcast(cnd_t *cond)
{
#if defined(_TTHREAD_WIN32_)
int haveWaiters;
/* Are there any waiters? */
EnterCriticalSection(&cond->mWaitersCountLock);
haveWaiters = (cond->mWaitersCount > 0);
LeaveCriticalSection(&cond->mWaitersCountLock);
/* If we have any waiting threads, send them a signal */
if(haveWaiters)
{
if (SetEvent(cond->mEvents[_CONDITION_EVENT_ALL]) == 0)
{
return thrd_error;
}
}
return thrd_success;
#else
return pthread_cond_signal(cond) == 0 ? thrd_success : thrd_error;
#endif
}
#if defined(_TTHREAD_WIN32_)
static int _cnd_timedwait_win32(cnd_t *cond, mtx_t *mtx, DWORD timeout)
{
int result, lastWaiter;
/* Increment number of waiters */
EnterCriticalSection(&cond->mWaitersCountLock);
++ cond->mWaitersCount;
LeaveCriticalSection(&cond->mWaitersCountLock);
/* Release the mutex while waiting for the condition (will decrease
the number of waiters when done)... */
mtx_unlock(mtx);
/* Wait for either event to become signaled due to cnd_signal() or
cnd_broadcast() being called */
result = WaitForMultipleObjects(2, cond->mEvents, FALSE, timeout);
if (result == WAIT_TIMEOUT)
{
return thrd_timeout;
}
else if (result == (int)WAIT_FAILED)
{
return thrd_error;
}
/* Check if we are the last waiter */
EnterCriticalSection(&cond->mWaitersCountLock);
-- cond->mWaitersCount;
lastWaiter = (result == (WAIT_OBJECT_0 + _CONDITION_EVENT_ALL)) &&
(cond->mWaitersCount == 0);
LeaveCriticalSection(&cond->mWaitersCountLock);
/* If we are the last waiter to be notified to stop waiting, reset the event */
if (lastWaiter)
{
if (ResetEvent(cond->mEvents[_CONDITION_EVENT_ALL]) == 0)
{
return thrd_error;
}
}
/* Re-acquire the mutex */
mtx_lock(mtx);
return thrd_success;
}
#endif
int cnd_wait(cnd_t *cond, mtx_t *mtx)
{
#if defined(_TTHREAD_WIN32_)
return _cnd_timedwait_win32(cond, mtx, INFINITE);
#else
return pthread_cond_wait(cond, mtx) == 0 ? thrd_success : thrd_error;
#endif
}
int cnd_timedwait(cnd_t *cond, mtx_t *mtx, const struct timespec *ts)
{
#if defined(_TTHREAD_WIN32_)
struct timespec now;
if (clock_gettime(CLOCK_REALTIME, &now) == 0)
{
DWORD delta = (DWORD) ((ts->tv_sec - now.tv_sec) * 1000 +
(ts->tv_nsec - now.tv_nsec + 500000) / 1000000);
return _cnd_timedwait_win32(cond, mtx, delta);
}
else
return thrd_error;
#else
int ret;
ret = pthread_cond_timedwait(cond, mtx, ts);
if (ret == ETIMEDOUT)
{
return thrd_timeout;
}
return ret == 0 ? thrd_success : thrd_error;
#endif
}
/** Information to pass to the new thread (what to run). */
typedef struct {
thrd_start_t mFunction; /**< Pointer to the function to be executed. */
void * mArg; /**< Function argument for the thread function. */
} _thread_start_info;
/* Thread wrapper function. */
#if defined(_TTHREAD_WIN32_)
static unsigned WINAPI _thrd_wrapper_function(void * aArg)
#elif defined(_TTHREAD_POSIX_)
static void * _thrd_wrapper_function(void * aArg)
#endif
{
thrd_start_t fun;
void *arg;
int res;
#if defined(_TTHREAD_POSIX_)
void *pres;
#endif
/* Get thread startup information */
_thread_start_info *ti = (_thread_start_info *) aArg;
fun = ti->mFunction;
arg = ti->mArg;
/* The thread is responsible for freeing the startup information */
free((void *)ti);
/* Call the actual client thread function */
res = fun(arg);
#if defined(_TTHREAD_WIN32_)
return res;
#else
pres = malloc(sizeof(int));
if (pres != NULL)
{
*(int*)pres = res;
}
return pres;
#endif
}
int thrd_create(thrd_t *thr, thrd_start_t func, void *arg)
{
/* Fill out the thread startup information (passed to the thread wrapper,
which will eventually free it) */
_thread_start_info* ti = (_thread_start_info*)malloc(sizeof(_thread_start_info));
if (ti == NULL)
{
return thrd_nomem;
}
ti->mFunction = func;
ti->mArg = arg;
/* Create the thread */
#if defined(_TTHREAD_WIN32_)
*thr = (HANDLE)_beginthreadex(NULL, 0, _thrd_wrapper_function, (void *)ti, 0, NULL);
#elif defined(_TTHREAD_POSIX_)
if(pthread_create(thr, NULL, _thrd_wrapper_function, (void *)ti) != 0)
{
*thr = 0;
}
#endif
/* Did we fail to create the thread? */
if(!*thr)
{
free(ti);
return thrd_error;
}
return thrd_success;
}
thrd_t thrd_current(void)
{
#if defined(_TTHREAD_WIN32_)
return GetCurrentThread();
#else
return pthread_self();
#endif
}
int thrd_detach(thrd_t thr)
{
/* FIXME! */
(void)thr;
return thrd_error;
}
int thrd_equal(thrd_t thr0, thrd_t thr1)
{
#if defined(_TTHREAD_WIN32_)
return thr0 == thr1;
#else
return pthread_equal(thr0, thr1);
#endif
}
void thrd_exit(int res)
{
#if defined(_TTHREAD_WIN32_)
ExitThread(res);
#else
void *pres = malloc(sizeof(int));
if (pres != NULL)
{
*(int*)pres = res;
}
pthread_exit(pres);
#endif
}
int thrd_join(thrd_t thr, int *res)
{
#if defined(_TTHREAD_WIN32_)
if (WaitForSingleObject(thr, INFINITE) == WAIT_FAILED)
{
return thrd_error;
}
if (res != NULL)
{
DWORD dwRes;
GetExitCodeThread(thr, &dwRes);
*res = dwRes;
}
#elif defined(_TTHREAD_POSIX_)
void *pres;
int ires = 0;
if (pthread_join(thr, &pres) != 0)
{
return thrd_error;
}
if (pres != NULL)
{
ires = *(int*)pres;
free(pres);
}
if (res != NULL)
{
*res = ires;
}
#endif
return thrd_success;
}
int thrd_sleep(const struct timespec *time_point, struct timespec *remaining)
{
struct timespec now;
#if defined(_TTHREAD_WIN32_)
DWORD delta;
#else
long delta;
#endif
/* Get the current time */
if (clock_gettime(CLOCK_REALTIME, &now) != 0)
return -2; // FIXME: Some specific error code?
#if defined(_TTHREAD_WIN32_)
/* Delta in milliseconds */
delta = (DWORD) ((time_point->tv_sec - now.tv_sec) * 1000 +
(time_point->tv_nsec - now.tv_nsec + 500000) / 1000000);
if (delta > 0)
{
Sleep(delta);
}
#else
/* Delta in microseconds */
delta = (time_point->tv_sec - now.tv_sec) * 1000000L +
(time_point->tv_nsec - now.tv_nsec + 500L) / 1000L;
/* On some systems, the usleep argument must be < 1000000 */
while (delta > 999999L)
{
usleep(999999);
delta -= 999999L;
}
if (delta > 0L)
{
usleep((useconds_t)delta);
}
#endif
/* We don't support waking up prematurely (yet) */
if (remaining)
{
remaining->tv_sec = 0;
remaining->tv_nsec = 0;
}
return 0;
}
void thrd_yield(void)
{
#if defined(_TTHREAD_WIN32_)
Sleep(0);
#else
sched_yield();
#endif
}
int tss_create(tss_t *key, tss_dtor_t dtor)
{
#if defined(_TTHREAD_WIN32_)
/* FIXME: The destructor function is not supported yet... */
if (dtor != NULL)
{
return thrd_error;
}
*key = TlsAlloc();
if (*key == TLS_OUT_OF_INDEXES)
{
return thrd_error;
}
#else
if (pthread_key_create(key, dtor) != 0)
{
return thrd_error;
}
#endif
return thrd_success;
}
void tss_delete(tss_t key)
{
#if defined(_TTHREAD_WIN32_)
TlsFree(key);
#else
pthread_key_delete(key);
#endif
}
void *tss_get(tss_t key)
{
#if defined(_TTHREAD_WIN32_)
return TlsGetValue(key);
#else
return pthread_getspecific(key);
#endif
}
int tss_set(tss_t key, void *val)
{
#if defined(_TTHREAD_WIN32_)
if (TlsSetValue(key, val) == 0)
{
return thrd_error;
}
#else
if (pthread_setspecific(key, val) != 0)
{
return thrd_error;
}
#endif
return thrd_success;
}
#if defined(_TTHREAD_EMULATE_CLOCK_GETTIME_)
int _tthread_clock_gettime(clockid_t clk_id, struct timespec *ts)
{
#if defined(_TTHREAD_WIN32_)
struct _timeb tb;
_ftime(&tb);
ts->tv_sec = (time_t)tb.time;
ts->tv_nsec = 1000000L * (long)tb.millitm;
#else
struct timeval tv;
gettimeofday(&tv, NULL);
ts->tv_sec = (time_t)tv.tv_sec;
ts->tv_nsec = 1000L * (long)tv.tv_usec;
#endif
return 0;
}
#endif // _TTHREAD_EMULATE_CLOCK_GETTIME_
|
35f0d1edd04822f4ffce4d35cb4b3ab9b1ad9210
|
05819963250c2ae0ba59ffef48d7c99a5b6b7cfd
|
/examples/usb_printer_basic/main.c
|
1856e88cd00cffe05736721e89be61ed4da43b43
|
[
"LicenseRef-scancode-bsd-atmel"
] |
permissive
|
atmelcorp/atmel-software-package
|
cefa3213069995d453d3b47b8b3aa7a7aca683ac
|
e0428c7c8175a42a2460cff27bb0501db0bbe160
|
refs/heads/master
| 2023-04-13T16:34:56.181081
| 2023-04-06T17:30:10
| 2023-04-11T06:05:12
| 47,840,424
| 117
| 94
|
NOASSERTION
| 2022-10-20T03:07:15
| 2015-12-11T17:18:56
|
C
|
UTF-8
|
C
| false
| false
| 10,605
|
c
|
main.c
|
/* ----------------------------------------------------------------------------
* SAM Software Package License
* ----------------------------------------------------------------------------
* Copyright (c) 2019, Atmel Corporation
*
* 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 disclaimer below.
*
* Atmel's name may not be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "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 ATMEL 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.
* ----------------------------------------------------------------------------
*/
/** \cond usb_printer_basic
* \page usb_printer USB PRINTER Example
*
* \section Purpose
*
* This demo implements a bare-metal(non RTOS) USB Printer Device application.
*
* \section Requirements
*
* This package can be used with some of Atmel evaluation kits that have UDP
* interface, depending on the functions included.
*
* \section Description
*
* This demo shows how the board connected to the Windows PC enumerate as a USB
* printer device is capable of printing.
* This demo uses PC running Windows as a Host. The demo application on top of USB printer
* function driver when connected to the host, enumerates as "USB Printing Support" device under
* USB controllers in Device Manager. This demo allows the user to print the text from Notepad
* or similar application in Windows using built in "Generic/Text Only" print driver.
* Generic / Text Only driver simply outputs the data to the connected USB printer in raw
* format without performing any translation on the data to be printed.
* There is no Printer head mechanism used in this demo, instead, the print data received from
* the host is sent to the serial terminal application running in the host itself by the demo
* application. Open any serial terminal application with 115200/8-N-1 settings for the Virtual
* COM port associated with the DEBUG.
*
* \section Usage
*
* -# Build the program and download it inside the evaluation board. Please
* refer to the
* <a href="http://www.atmel.com/dyn/resources/prod_documents/doc6421.pdf">
* SAM-BA User Guide</a>, the
* <a href="http://www.atmel.com/dyn/resources/prod_documents/doc6310.pdf">
* GNU-Based Software Development</a> application note or to the
* <a href="ftp://ftp.iar.se/WWWfiles/arm/Guides/EWARM_UserGuide.ENU.pdf">
* IAR EWARM User Guide</a>, depending on your chosen solution.
* -# On the computer, open and configure a terminal application
* (e.g. HyperTerminal on Microsoft Windows) with these settings:
* - 115200 bauds
* - 8 bits of data
* - No parity
* - 1 stop bit
* - No flow control
* -# Start the application.
* -# In the terminal window, the following text should appear:
* \code
* -- USB Printer basic Project xxx --
* -- SAMxxxxx-xx
* -- Compiled: xxx xx xxxx xx:xx:xx --
* \endcode
* -# When connecting USB cable to windows, the LED blinks, and the host
* reports a new USB device attachment.
*
* \section Reference
* - usb_printer/main.c
* - \ref usbd_framework
* - \ref usbd_api
* - \ref usbd_printer
* - \ref usbd_printer_driver
*
*/
/**
* \file
*
* This file contains all the specific code for the
* usb_printer project
*/
/*----------------------------------------------------------------------------
* Headers
*----------------------------------------------------------------------------*/
#include "board.h"
#include "chip.h"
#include "trace.h"
#include "compiler.h"
#include "serial/console.h"
#include "mm/cache.h"
#include "usb/device/printer/printer_driver.h"
#include "usb/device/usbd_hal.h"
#include "main_descriptors.h"
#include "../usb_common/main_usb_common.h"
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
/*---------------------------------------------------------------------------
* Types
*---------------------------------------------------------------------------*/
typedef struct
{
/* 1 = No Error, 0 = Error */
uint8_t errorStatus;
/* 1 = Selected, 0 = Not Selected */
uint8_t selectStatus;
/* 1 = Paper Empty, 0 = Paper Not Empty */
uint8_t paperEmptyStatus;
} printer_port_status;
/*---------------------------------------------------------------------------
* Definitions
*---------------------------------------------------------------------------*/
/* Length of the Device ID string including length in the first two bytes */
#define USB_DEVICE_PRINTER_DEVICE_ID_STRING_LENGTH 77
/* Device ID string including length in the first two bytes */
#define USB_DEVICE_PRINTER_DEVICE_ID_STRING {0,77,'M','F','G',':','A','T','M','E','L',';','M','D','L',':','G','e','n','e','r','i','c',';','C','M','D',':','E','P','S','O','N',';','C','L','S',':','P','R','I','N','T','E','R',';','D','E','S',':','G','e','n','e','r','i','c','T','e','x','t','O','n','l','y','P','r','i','n','t','e','r','D','e','m','o',';'}
/** Size in bytes of the packet used for reading data from USB */
#define DATAPACKETSIZE CHIP_USB_ENDPOINT_MAXPACKETSIZE(PRINTER_Descriptors_DATAOUT0)
/** Size in bytes of the buffer used for reading data from the USB & USART */
#define DATABUFFERSIZE (DATAPACKETSIZE + 2)
/*----------------------------------------------------------------------------
* Local variables
*----------------------------------------------------------------------------*/
bool usb_is_read_complete = false;
CACHE_ALIGNED uint8_t printer_read_buf[DATABUFFERSIZE];
/*----------------------------------------------------------------------------
* External variables
*----------------------------------------------------------------------------*/
extern const USBDDriverDescriptors printer_driver_descriptors;
/*---------------------------------------------------------------------------
* Internal variables
*---------------------------------------------------------------------------*/
uint8_t deviceID_String[USB_DEVICE_PRINTER_DEVICE_ID_STRING_LENGTH] = USB_DEVICE_PRINTER_DEVICE_ID_STRING;
printer_port_status prntrStatus;
/*-----------------------------------------------------------------------------
* Callback re-implementation
*-----------------------------------------------------------------------------*/
/**
* Invoked whenever a SETUP request is received from the host. Forwards the
* request to the standard handler.
*/
void usbd_callbacks_request_received(const USBGenericRequest *request)
{
printer_driver_request_handler(request);
}
/**
* Invoked when the configuration of the device changes. Resets the usb printer driver.
* \param cfgnum New configuration number.
*/
void usbd_driver_callbacks_configuration_changed(unsigned char cfgnum)
{
printer_driver_configuration_change_handler(cfgnum);
}
/*---------------------------------------------------------------------------
* Internal functions
*---------------------------------------------------------------------------*/
/**
* Callback invoked when data has been received on the USB.
*/
static void _usb_data_received(void *read, uint8_t status, uint32_t received, uint32_t remaining)
{
uint32_t i;
uint8_t* p;
/* Check that data has been received successfully */
if (status == USBD_STATUS_SUCCESS) {
/* Send data through USART */
p = (uint8_t*)printer_read_buf;
for (i = 0; i < received; i++) {
console_put_char(*p);
p++;
}
/* Check if bytes have been discarded */
if ((received == DATAPACKETSIZE) && (remaining > 0)) {
trace_warning(
"_usb_data_received: %u bytes discarded\n\r",
(unsigned int)remaining);
}
} else {
trace_warning( "_usb_data_received: Transfer error\n\r");
}
}
/*---------------------------------------------------------------------------
* Exported function
*---------------------------------------------------------------------------*/
void printet_driver_get_port_status(uint8_t* status)
{
/* The host wants to know the printer's current status, in a format which is compatible
with the status register of a standard PC parallel port. This is a control transfer request.
Use the USB_DEVICE_ControlSend() function to send the data to host. */
*status = (uint8_t)(((prntrStatus.errorStatus << 3) & 0x08) |
((prntrStatus.selectStatus << 4) & 0x10) |
((prntrStatus.paperEmptyStatus << 5) & 0x20));
return;
}
/*---------------------------------------------------------------------------
* Main
*---------------------------------------------------------------------------*/
/**
* Initializes drivers and start the USB printer device.
*/
int main(void)
{
uint8_t usb_connected = 0;
prntrStatus.errorStatus = 0;
prntrStatus.paperEmptyStatus = 1;
prntrStatus.selectStatus = 0;
/* Output example information */
console_example_info("USB Printer basic Example");
/* If there is on board power, switch it off */
usb_power_configure();
/* USB printer driver initialization */
printer_driver_initialize(&printer_driver_descriptors,
deviceID_String,
USB_DEVICE_PRINTER_DEVICE_ID_STRING_LENGTH );
/* connect if needed */
usb_vbus_configure();
/* Driver loop */
while (1) {
/* Device is not configured */
if (usbd_get_state() < USBD_STATE_CONFIGURED) {
if (usb_connected) {
printf("-I- USB Disconnect/Suspend\n\r");
usb_connected = 0;
}
} else {
if (usb_connected == 0) {
printf("-I- USB Connect\n\r");
usb_connected = 1;
}
if (!usb_is_read_complete) {
printer_driver_read(printer_read_buf,
DATAPACKETSIZE,
_usb_data_received,
&usb_is_read_complete);
}
}
}
}
/** \endcond */
|
5c21b1f895f93cb2d6d838487621bb8b18a464b4
|
a09d2734b97a58d06e79182666a4ebc27360d3d5
|
/vkFFT/vkFFT/vkFFT_CodeGen/vkFFT_KernelsLevel1/vkFFT_ReadWrite.h
|
f8a978c6e8516a06fc1b99bdce13668258e08285
|
[
"MIT"
] |
permissive
|
DTolm/VkFFT
|
9c4aadb51ab776918822c7483fc1f6db62eba415
|
116bf7ff92a9dde115957bb7beb33c2d89c87fda
|
refs/heads/master
| 2023-08-10T03:53:00.613036
| 2023-08-01T17:42:19
| 2023-08-01T17:42:19
| 284,421,891
| 1,320
| 77
|
MIT
| 2023-09-12T23:27:43
| 2020-08-02T08:28:36
|
C++
|
UTF-8
|
C
| false
| false
| 64,760
|
h
|
vkFFT_ReadWrite.h
|
// This file is part of VkFFT
//
// Copyright (C) 2021 - present Dmitrii Tolmachev <dtolm96@gmail.com>
//
// 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.
#ifndef VKFFT_READWRITE_H
#define VKFFT_READWRITE_H
#include "vkFFT/vkFFT_Structs/vkFFT_Structs.h"
#include "vkFFT/vkFFT_CodeGen/vkFFT_StringManagement/vkFFT_StringManager.h"
#include "vkFFT/vkFFT_CodeGen/vkFFT_MathUtils/vkFFT_MathUtils.h"
#include "vkFFT/vkFFT_CodeGen/vkFFT_KernelsLevel0/vkFFT_KernelUtils.h"
#include "vkFFT/vkFFT_CodeGen/vkFFT_KernelsLevel0/vkFFT_Zeropad.h"
#include "vkFFT/vkFFT_CodeGen/vkFFT_KernelsLevel0/vkFFT_MemoryManagement/vkFFT_MemoryTransfers/vkFFT_Transfers.h"
static inline void setReadToRegisters(VkFFTSpecializationConstantsLayout* sc, int readType) {
if (sc->res != VKFFT_SUCCESS) return;
switch (readType) {
case 0: //single_c2c
{
if ((sc->localSize[1].data.i > 1) || ((sc->performR2C) && (sc->actualInverse)) || ((sc->fftDim.data.i>1)&&((sc->localSize[0].data.i * sc->stageRadix[0] * (sc->registers_per_thread_per_radix[sc->stageRadix[0]] / sc->stageRadix[0]) > sc->fftDim.data.i) || (sc->rader_generator[0] > 0))))
sc->readToRegisters = 0;
else
sc->readToRegisters = 1;
break;
}
case 1: //grouped_c2c
{
if ((sc->fftDim.data.i>1)&&(((sc->localSize[1].data.i * sc->stageRadix[0] * (sc->registers_per_thread_per_radix[sc->stageRadix[0]] / sc->stageRadix[0]) > sc->fftDim.data.i) || (sc->rader_generator[0] > 0))))
sc->readToRegisters = 0;
else
sc->readToRegisters = 1;
break;
}
case 2: //single_c2c_strided
{
if ((sc->fftDim.data.i>1)&&(((sc->localSize[1].data.i * sc->stageRadix[0] * (sc->registers_per_thread_per_radix[sc->stageRadix[0]] / sc->stageRadix[0]) > sc->fftDim.data.i) || (sc->rader_generator[0] > 0))))
sc->readToRegisters = 0;
else
sc->readToRegisters = 1;
break;
}
case 5://single_r2c
{
if ((sc->stridedSharedLayout) || (sc->localSize[1].data.i > 1) || (sc->fftDim.data.i == 1) || ((sc->fftDim.data.i>1)&&((sc->localSize[0].data.i * sc->stageRadix[0] * (sc->registers_per_thread_per_radix[sc->stageRadix[0]] / sc->stageRadix[0]) > sc->fftDim.data.i) || (sc->rader_generator[0] > 0))))
sc->readToRegisters = 0;
else
sc->readToRegisters = 1;
break;
}
case 6: //single_c2r
{
sc->readToRegisters = 0;
/*if ((sc->rader_generator[0] > 0) || ((sc->fftDim.data.i % sc->localSize[0].data.i) && (!sc->stridedSharedLayout)) || ((sc->fftDim.data.i % sc->localSize[1].data.i) && (sc->stridedSharedLayout)))
sc->readToRegisters = 0;
else
sc->readToRegisters = 1;*/
break;
}
case 110: case 111: case 130: case 131: case 140: case 141: case 144: case 145:
{
sc->readToRegisters = 0;
break;
}
case 142: case 143:
{
#if(((VKFFT_BACKEND==3)||(VKFFT_BACKEND==4)||(VKFFT_BACKEND==5)))
sc->readToRegisters = 1;
#else
sc->readToRegisters = 0;
#endif
break;
}
case 120: case 121:
{
sc->readToRegisters = 1;
break;
}
}
return;
}
static inline void setWriteFromRegisters(VkFFTSpecializationConstantsLayout* sc, int writeType) {
if (sc->res != VKFFT_SUCCESS) return;
switch (writeType) {
case 0: //single_c2c
{
if ((sc->localSize[1].data.i > 1) || ((sc->fftDim.data.i>1)&&((sc->localSize[0].data.i * sc->stageRadix[sc->numStages - 1] * (sc->registers_per_thread_per_radix[sc->stageRadix[sc->numStages - 1]] / sc->stageRadix[sc->numStages - 1]) > sc->fftDim.data.i) || (sc->rader_generator[sc->numStages - 1] > 0)))) {
sc->writeFromRegisters = 0;
}
else
sc->writeFromRegisters = 1;
break;
}
case 1: //grouped_c2c
{
if ((sc->fftDim.data.i>1)&&(((sc->localSize[1].data.i * sc->stageRadix[sc->numStages - 1] * (sc->registers_per_thread_per_radix[sc->stageRadix[sc->numStages - 1]] / sc->stageRadix[sc->numStages - 1]) > sc->fftDim.data.i) || (sc->rader_generator[sc->numStages - 1] > 0)))) {
sc->writeFromRegisters = 0;
}
else
sc->writeFromRegisters = 1;
break;
}
case 2: //single_c2c_strided
{
if ((sc->fftDim.data.i>1)&&(((sc->localSize[1].data.i * sc->stageRadix[sc->numStages - 1] * (sc->registers_per_thread_per_radix[sc->stageRadix[sc->numStages - 1]] / sc->stageRadix[sc->numStages - 1]) > sc->fftDim.data.i) || (sc->rader_generator[sc->numStages - 1] > 0)))) {
sc->writeFromRegisters = 0;
}
else
sc->writeFromRegisters = 1;
break;
}
case 5://single_r2c
{
sc->writeFromRegisters = 0;
break;
}
case 6: //single_c2r
{
if ((sc->stridedSharedLayout) || (sc->localSize[1].data.i > 1) || (sc->fftDim.data.i==1) || ((sc->fftDim.data.i>1)&&((sc->localSize[0].data.i * sc->stageRadix[sc->numStages - 1] * (sc->registers_per_thread_per_radix[sc->stageRadix[sc->numStages - 1]] / sc->stageRadix[sc->numStages - 1]) > sc->fftDim.data.i) || (sc->rader_generator[sc->numStages - 1] > 0)))) {
sc->writeFromRegisters = 0;
}
else
sc->writeFromRegisters = 1;
break;
}
case 110: case 111: case 120: case 121: case 130: case 131: case 140: case 141: case 142: case 143: case 144: case 145:
{
sc->writeFromRegisters = 0;
break;
}
}
return;
}
static inline void appendOffset(VkFFTSpecializationConstantsLayout* sc, int readWrite, int type) {
if (sc->res != VKFFT_SUCCESS) return;
PfContainer temp_int = VKFFT_ZERO_INIT;
temp_int.type = 31;
PfContainer* bufferStride = (readWrite) ? sc->outputStride : sc->inputStride;
if (sc->numFFTdims > 2) {
if (sc->numCoordinates * sc->matrixConvolution * sc->numBatches.data.i > 1) {
if (sc->performWorkGroupShift[2]) {
PfMul(sc, &sc->tempInt, &sc->workGroupShiftZ, &sc->gl_WorkGroupSize_z, 0);
PfAdd(sc, &sc->tempInt, &sc->tempInt, &sc->gl_GlobalInvocationID_z);
PfMod(sc, &sc->tempInt, &sc->tempInt, &sc->dispatchZactualFFTSize);
}
else {
PfMod(sc, &sc->tempInt, &sc->gl_GlobalInvocationID_z, &sc->dispatchZactualFFTSize);
}
}
else {
if (sc->performWorkGroupShift[2]) {
PfMul(sc, &sc->tempInt, &sc->workGroupShiftZ, &sc->gl_WorkGroupSize_z, 0);
PfAdd(sc, &sc->tempInt, &sc->tempInt, &sc->gl_GlobalInvocationID_z);
}
else {
PfMov(sc, &sc->tempInt, &sc->gl_GlobalInvocationID_z);
}
}
/*if (sc->axis_id == 2)
checkZeropad(sc, &sc->tempInt, 1);
else
checkZeropad(sc, &sc->tempInt, 2);
PfMul(sc, &sc->tempInt, &sc->tempInt, &bufferStride[2], 0);
PfAdd(sc, &sc->shiftZ, &sc->shiftZ, &sc->tempInt);*/
int locStrideOrder = 2;
for (int i = 1; i < sc->numFFTdims; i++){
if (((i != sc->axis_id)&&(sc->axis_id > 0)) || ((i>1) && (sc->axis_id == 0))) {
PfMod(sc, &sc->inoutID_y, &sc->tempInt, &sc->size[i]);
checkZeropad(sc, &sc->inoutID_y, i);
PfMul(sc, &sc->inoutID_y, &sc->inoutID_y, &bufferStride[locStrideOrder], 0);
PfAdd(sc, &sc->shiftZ, &sc->shiftZ, &sc->inoutID_y);
if ((i!=(sc->numFFTdims-1) && (sc->axis_id != (sc->numFFTdims-1))) || ((i!=(sc->numFFTdims-2)) && (sc->axis_id == (sc->numFFTdims-1))))
PfDiv(sc, &sc->tempInt, &sc->tempInt, &sc->size[i]);
locStrideOrder++;
}
}
}
int64_t maxCoordinate = sc->numCoordinates * sc->matrixConvolution;
if (sc->numCoordinates * sc->matrixConvolution > 1) {
PfDiv(sc, &sc->tempInt, &sc->gl_GlobalInvocationID_z, &sc->dispatchZactualFFTSize);
temp_int.data.i = maxCoordinate;
PfMod(sc, &sc->tempInt, &sc->tempInt, &temp_int);
PfMul(sc, &sc->tempInt, &sc->tempInt, &bufferStride[sc->numFFTdims], 0);
PfAdd(sc, &sc->shiftZ, &sc->shiftZ, &sc->tempInt);
}
if ((sc->matrixConvolution > 1) && (sc->convolutionStep)) {
maxCoordinate = 1;
PfMul(sc, &temp_int, &sc->coordinate, &bufferStride[sc->numFFTdims], 0);
PfAdd(sc, &sc->shiftZ, &sc->shiftZ, &temp_int);
}
if ((sc->numBatches.data.i > 1) || (sc->numKernels.data.i > 1)) {
if (sc->convolutionStep && (sc->numKernels.data.i > 1)) {
PfMul(sc, &sc->tempInt, &sc->batchID, &bufferStride[sc->numFFTdims+1], 0);
PfAdd(sc, &sc->shiftZ, &sc->shiftZ, &sc->tempInt);
}
else {
temp_int.data.i = sc->dispatchZactualFFTSize.data.i * maxCoordinate;
PfDiv(sc, &sc->tempInt, &sc->gl_GlobalInvocationID_z, &temp_int);
PfMul(sc, &sc->tempInt, &sc->tempInt, &bufferStride[sc->numFFTdims+1], 0);
PfAdd(sc, &sc->shiftZ, &sc->shiftZ, &sc->tempInt);
}
}
if (readWrite) {
if (sc->outputOffset.type < 100) {
temp_int.data.i = sc->outputOffset.data.i / sc->outputNumberByteSize;
PfAdd(sc, &sc->shiftZ, &sc->shiftZ, &temp_int);
}
else {
if (sc->outputOffset.type == 101) {
if (sc->performPostCompilationOutputOffset) {
PfAdd(sc, &sc->shiftZ, &sc->shiftZ, &sc->outputOffset);
}
}
}
}
else {
if (sc->inputOffset.type < 100) {
temp_int.data.i = sc->inputOffset.data.i / sc->inputNumberByteSize;
PfAdd(sc, &sc->shiftZ, &sc->shiftZ, &temp_int);
}
else {
if (sc->inputOffset.type == 101) {
if (sc->performPostCompilationInputOffset) {
PfAdd(sc, &sc->shiftZ, &sc->shiftZ, &sc->inputOffset);
}
}
}
}
return;
}
static inline void appendKernelOffset(VkFFTSpecializationConstantsLayout* sc, int readWrite, int type) {
if (sc->res != VKFFT_SUCCESS) return;
PfContainer temp_int = VKFFT_ZERO_INIT;
temp_int.type = 31;
PfContainer* bufferStride = sc->inputStride;
PfContainer batching_localSize = VKFFT_ZERO_INIT;
batching_localSize.type = 31;
if (sc->stridedSharedLayout) {
batching_localSize.data.i = sc->localSize[0].data.i;
}
else {
batching_localSize.data.i = sc->localSize[1].data.i;
}
if (type == 1) {
if (sc->axis_id == 0) {
if (sc->size[1].data.i > 1) {
if (sc->performWorkGroupShift[1]) {
PfAdd(sc, &sc->blockInvocationID, &sc->gl_WorkGroupID_y, &sc->workGroupShiftY);
temp_int.data.i = sc->inputStride[1].data.i;
PfMul(sc, &sc->blockInvocationID, &sc->blockInvocationID, &temp_int, 0);
}
else
{
PfMov(sc, &sc->blockInvocationID, &sc->gl_WorkGroupID_y);
temp_int.data.i = sc->inputStride[1].data.i;
PfMul(sc, &sc->blockInvocationID, &sc->blockInvocationID, &temp_int, 0);
}
}
}
else {
PfSetToZero(sc, &sc->blockInvocationID);
}
}
else {
if (sc->size[1].data.i > 1) {
if (sc->numAxisUploads != 1) {
if (sc->performWorkGroupShift[1]) {
PfAdd(sc, &sc->blockInvocationID, &sc->gl_WorkGroupID_y, &sc->workGroupShiftY);
temp_int.data.i = sc->inputStride[1].data.i;
PfMul(sc, &sc->blockInvocationID, &sc->blockInvocationID, &temp_int, 0);
}
else
{
PfMov(sc, &sc->blockInvocationID, &sc->gl_WorkGroupID_y);
temp_int.data.i = sc->inputStride[1].data.i;
PfMul(sc, &sc->blockInvocationID, &sc->blockInvocationID, &temp_int, 0);
}
}
}
else {
PfSetToZero(sc, &sc->blockInvocationID);
}
}
if (sc->numFFTdims > 2) {
if (sc->numCoordinates * sc->matrixConvolution * sc->numBatches.data.i > 1) {
if (sc->performWorkGroupShift[2]) {
PfMul(sc, &sc->tempInt, &sc->workGroupShiftZ, &sc->gl_WorkGroupSize_z, 0);
PfAdd(sc, &sc->tempInt, &sc->tempInt, &sc->gl_GlobalInvocationID_z);
PfMod(sc, &sc->tempInt, &sc->tempInt, &sc->dispatchZactualFFTSize);
//PfMul(sc, &sc->tempInt, &sc->tempInt, &bufferStride[2], 0);
//PfAdd(sc, &sc->blockInvocationID, &sc->blockInvocationID, &sc->tempInt);
}
else {
PfMod(sc, &sc->tempInt, &sc->gl_GlobalInvocationID_z, &sc->dispatchZactualFFTSize);
//PfMul(sc, &sc->tempInt, &sc->tempInt, &bufferStride[2], 0);
//PfAdd(sc, &sc->blockInvocationID, &sc->blockInvocationID, &sc->tempInt);
}
}
else {
if (sc->performWorkGroupShift[2]) {
PfMul(sc, &sc->tempInt, &sc->workGroupShiftZ, &sc->gl_WorkGroupSize_z, 0);
PfAdd(sc, &sc->tempInt, &sc->tempInt, &sc->gl_GlobalInvocationID_z);
//PfMul(sc, &sc->tempInt, &sc->tempInt, &bufferStride[2], 0);
//PfAdd(sc, &sc->blockInvocationID, &sc->blockInvocationID, &sc->tempInt);
}
else {
PfMov(sc, &sc->tempInt, &sc->gl_GlobalInvocationID_z);
//PfMul(sc, &sc->tempInt, &sc->gl_GlobalInvocationID_z, &bufferStride[2], 0);
//PfAdd(sc, &sc->blockInvocationID, &sc->blockInvocationID, &sc->tempInt);
}
}
int locStrideOrder = 2;
for (int i = 1; i < sc->numFFTdims; i++){
if (((i != sc->axis_id)&&(sc->axis_id > 0)) || ((i>1) && (sc->axis_id == 0))) {
PfMod(sc, &sc->inoutID_y, &sc->tempInt, &sc->size[i]);
checkZeropad(sc, &sc->inoutID_y, i);
PfMul(sc, &sc->inoutID_y, &sc->inoutID_y, &bufferStride[locStrideOrder], 0);
PfAdd(sc, &sc->shiftZ, &sc->shiftZ, &sc->inoutID_y);
if ((i!=(sc->numFFTdims-1) && (sc->axis_id != (sc->numFFTdims-1))) || ((i!=(sc->numFFTdims-2)) && (sc->axis_id == (sc->numFFTdims-1))))
PfDiv(sc, &sc->tempInt, &sc->tempInt, &sc->size[i]);
locStrideOrder++;
}
}
}
int64_t maxCoordinate = sc->numCoordinates * sc->matrixConvolution;
if (sc->numCoordinates * sc->matrixConvolution > 1) {
PfDiv(sc, &sc->tempInt, &sc->gl_GlobalInvocationID_z, &sc->dispatchZactualFFTSize);
temp_int.data.i = maxCoordinate;
PfMod(sc, &sc->tempInt, &sc->tempInt, &temp_int);
PfMul(sc, &sc->tempInt, &sc->tempInt, &bufferStride[sc->numFFTdims], 0);
PfAdd(sc, &sc->blockInvocationID, &sc->blockInvocationID, &sc->tempInt);
}
if ((sc->matrixConvolution > 1) && (sc->convolutionStep)) {
maxCoordinate = 1;
PfMul(sc, &temp_int, &sc->coordinate, &bufferStride[sc->numFFTdims], 0);
PfAdd(sc, &sc->blockInvocationID, &sc->blockInvocationID, &temp_int);
}
if ((sc->numBatches.data.i > 1) || (sc->numKernels.data.i > 1)) {
if (sc->convolutionStep && (sc->numKernels.data.i > 1)) {
PfMul(sc, &sc->tempInt, &sc->batchID, &sc->inputStride[sc->numFFTdims+1], 0);
PfAdd(sc, &sc->blockInvocationID, &sc->blockInvocationID, &sc->tempInt);
}
else {
temp_int.data.i = sc->dispatchZactualFFTSize.data.i * maxCoordinate;
PfDiv(sc, &sc->tempInt, &sc->gl_GlobalInvocationID_z, &temp_int);
PfMul(sc, &sc->tempInt, &sc->tempInt, &bufferStride[sc->numFFTdims+1], 0);
PfAdd(sc, &sc->blockInvocationID, &sc->blockInvocationID, &sc->tempInt);
}
}
if (sc->kernelOffset.type < 100) {
temp_int.data.i = sc->kernelOffset.data.i / sc->kernelNumberByteSize;
PfAdd(sc, &sc->blockInvocationID, &sc->blockInvocationID, &temp_int);
}
else {
if (sc->kernelOffset.type == 101) {
if (sc->performPostCompilationKernelOffset) {
PfAdd(sc, &sc->blockInvocationID, &sc->blockInvocationID, &sc->kernelOffset);
}
}
}
return;
}
static inline void appendReadWriteDataVkFFT_nonstrided(VkFFTSpecializationConstantsLayout* sc, int readWrite, int type) {
if (sc->res != VKFFT_SUCCESS) return;
//&sc->tempIntLen = sprintf(&sc->tempIntStr, " return;\n");
//char shiftX[500] = "";
//if (&sc->performWorkGroupShift[0])
// sprintf(shiftX, " + consts.workGroupShiftX ");
PfContainer temp_int = VKFFT_ZERO_INIT;
temp_int.type = 31;
PfContainer temp_int1 = VKFFT_ZERO_INIT;
temp_int1.type = 31;
if ((!sc->writeFromRegisters) && (readWrite == 1))
appendBarrierVkFFT(sc);
//move to initialization
//char shiftY[100] = "";
//if (&sc->performWorkGroupShift[1])
// sprintf(shiftY, " + consts.workGroupShiftY ");
//&sc->shiftY = &sc->workGroupShiftX;
PfContainer localSize = VKFFT_ZERO_INIT;
localSize.type = 31;
PfContainer batching_localSize = VKFFT_ZERO_INIT;
batching_localSize.type = 31;
PfContainer* localInvocationID = VKFFT_ZERO_INIT;
PfContainer* batchingInvocationID = VKFFT_ZERO_INIT;
if (sc->stridedSharedLayout) {
batching_localSize.data.i = sc->localSize[0].data.i;
localSize.data.i = sc->localSize[1].data.i;
localInvocationID = &sc->gl_LocalInvocationID_y;
batchingInvocationID = &sc->gl_LocalInvocationID_x;
}
else {
batching_localSize.data.i = sc->localSize[1].data.i;
localSize.data.i = sc->localSize[0].data.i;
localInvocationID = &sc->gl_LocalInvocationID_x;
batchingInvocationID = &sc->gl_LocalInvocationID_y;
}
PfContainer used_registers = VKFFT_ZERO_INIT;
used_registers.type = 31;
PfContainer* bufferStride = (readWrite) ? sc->outputStride : sc->inputStride;
PfContainer mult = VKFFT_ZERO_INIT;
mult.type = 31;
PfContainer fftDim = VKFFT_ZERO_INIT;
fftDim.type = 31;
if (sc->zeropadBluestein[readWrite]) {
if (sc->numAxisUploads == 1) {
if (readWrite) {
fftDim.data.i = sc->fft_zeropad_Bluestein_left_write[sc->axis_id].data.i;
}
else {
if (sc->readToRegisters == 0) {
appendSetSMToZero(sc);
appendBarrierVkFFT(sc);
}
fftDim.data.i = sc->fft_zeropad_Bluestein_left_read[sc->axis_id].data.i;
}
}
else {
fftDim.data.i = sc->fftDim.data.i;
}
}
else
fftDim.data.i = sc->fftDim.data.i;
if (((type == 6) && (readWrite == 0)) || ((type == 5) && (readWrite == 1))) {
temp_int.data.i = 2;
PfDiv(sc, &fftDim, &fftDim, &temp_int);
PfInc(sc, &fftDim);
}
else if (type == 110) {
fftDim.data.i = (fftDim.data.i + 2) / 2;
}
else if ((type == 142) && (readWrite == 0)) {
fftDim.data.i = 2 * fftDim.data.i;
}
if (sc->mergeSequencesR2C)
mult.data.i = 2;
else
mult.data.i = 1;
//prepare offsets
if (readWrite == 0) {
if (sc->performWorkGroupShift[0]) {
PfAdd(sc, &sc->shiftX, &sc->gl_WorkGroupID_x, &sc->workGroupShiftX);
}
else {
PfMov(sc, &sc->shiftX, &sc->gl_WorkGroupID_x);
}
if (sc->size[1].data.i > 1) {
if (sc->numAxisUploads == 1) {
if (sc->performWorkGroupShift[1]) {
PfAdd(sc, &sc->shiftY, &sc->gl_WorkGroupID_y, &sc->workGroupShiftY);
temp_int.data.i = mult.data.i * batching_localSize.data.i;
PfMul(sc, &sc->shiftY, &sc->shiftY, &temp_int, 0);
checkZeropad(sc, &sc->shiftY, 1);
}
else {
PfMov(sc, &sc->shiftY, &sc->gl_WorkGroupID_y);
temp_int.data.i = mult.data.i * batching_localSize.data.i;
PfMul(sc, &sc->shiftY, &sc->shiftY, &temp_int, 0);
checkZeropad(sc, &sc->shiftY, 1);
}
PfSetToZero(sc, &sc->shiftZ);
}
else {
if (sc->performWorkGroupShift[1]) {
PfAdd(sc, &sc->shiftY, &sc->gl_WorkGroupID_y, &sc->workGroupShiftY);
checkZeropad(sc, &sc->shiftY, 1);
temp_int.data.i = sc->inputStride[1].data.i;
PfMul(sc, &sc->shiftZ, &sc->shiftY, &temp_int, 0);
}
else
{
PfMov(sc, &sc->shiftY, &sc->gl_WorkGroupID_y);
checkZeropad(sc, &sc->shiftY, 1);
temp_int.data.i = sc->inputStride[1].data.i;
PfMul(sc, &sc->shiftZ, &sc->shiftY, &temp_int, 0);
}
}
}
else {
PfSetToZero(sc, &sc->shiftZ);
}
appendOffset(sc, readWrite, type);
}
else {
int isInputStrideNotEqualToOutput = 0;
for (int i = 0; i < sc->numFFTdims+2; i++){
if ((sc->inputStride[i].type>100)||(sc->outputStride[i].type>100)||(sc->inputStride[i].data.i != sc->outputStride[i].data.i)) {
isInputStrideNotEqualToOutput = 1;
}
}
if ((isInputStrideNotEqualToOutput) || (sc->performPostCompilationInputOffset) || (sc->performPostCompilationOutputOffset) || ((sc->inputOffset.data.i != sc->outputOffset.data.i) && (sc->inputOffset.type < 100) && (sc->outputOffset.type < 100)) || ((sc->convolutionStep) && (sc->matrixConvolution > 1)) || (sc->batchID.data.i > 0)) {
if ((sc->size[1].data.i > 1) && (sc->numAxisUploads != 1)) {
if (sc->performWorkGroupShift[1]) {
temp_int.data.i = sc->outputStride[1].data.i;
PfMul(sc, &sc->shiftZ, &sc->shiftY, &temp_int, 0);
}
else
{
temp_int.data.i = sc->outputStride[1].data.i;
PfMul(sc, &sc->shiftZ, &sc->shiftY, &temp_int, 0);
}
}
else {
PfSetToZero(sc, &sc->shiftZ);
}
appendOffset(sc, readWrite, type);
}
}
if (((type == 6) && (readWrite == 0)) || ((type == 5) && (readWrite == 1))) {
PfMul(sc, &used_registers, &fftDim, &mult, 0);
mult.data.i = 1;
}
else {
PfMov(sc, &used_registers, &fftDim);
}
PfDivCeil(sc, &used_registers, &used_registers, &localSize);
PfContainer size1 = VKFFT_ZERO_INIT;
size1.type = 31;
PfDivCeil(sc, &size1, &sc->size[1], &mult);
if (sc->registerBoost > 1) {
temp_int.data.i = sc->registerBoost;
PfDiv(sc, &used_registers, &used_registers, &temp_int);
}
if (sc->fftDim.data.i != sc->fft_dim_full.data.i) {
if ((sc->reorderFourStep) && (readWrite == 1)) {
//sc->tempLen = sprintf(sc->tempStr, " if (((%s + %" PRIu64 " * %s) %% %" PRIu64 " + ((%s%s) / %" PRIu64 ")*%" PRIu64 " < %" PRIu64 ")){\n", sc->gl_LocalInvocationID_x, sc->localSize[0], sc->gl_LocalInvocationID_y, sc->localSize[1], sc->gl_WorkGroupID_x, shiftX, sc->firstStageStartSize / sc->fftDim, sc->localSize[1], sc->fft_dim_full / sc->firstStageStartSize);
PfMul(sc, &sc->tempInt2, &sc->localSize[0], &sc->gl_LocalInvocationID_y, 0);
PfAdd(sc, &sc->tempInt2, &sc->tempInt2, &sc->gl_LocalInvocationID_x);
PfMod(sc, &sc->tempInt2, &sc->tempInt2, &batching_localSize);
PfDiv(sc, &temp_int, &sc->firstStageStartSize, &sc->fftDim);
PfDiv(sc, &sc->tempInt, &sc->shiftX, &temp_int);
PfMul(sc, &sc->tempInt, &sc->tempInt, &batching_localSize, 0);
PfAdd(sc, &sc->tempInt2, &sc->tempInt2, &sc->tempInt);
PfDiv(sc, &temp_int, &sc->fft_dim_full, &sc->firstStageStartSize);
PfIf_lt_start(sc, &sc->tempInt2, &temp_int);
}
else {
PfDiv(sc, &temp_int, &sc->firstStageStartSize, &sc->fftDim);
PfMod(sc, &sc->tempInt, &sc->shiftX, &temp_int);
PfMul(sc, &sc->tempInt2, &sc->tempInt, &sc->fftDim, 0);
PfDiv(sc, &sc->tempInt, &sc->shiftX, &temp_int);
PfMul(sc, &temp_int, &batching_localSize, &sc->firstStageStartSize, 0);
PfMul(sc, &sc->tempInt, &sc->tempInt, &temp_int, 0);
PfAdd(sc, &sc->tempInt2, &sc->tempInt2, &sc->tempInt);
//sc->tempLen = sprintf(sc->tempStr, " %s numActiveThreads = ((%s/%" PRIu64 ")==%" PRIu64 ") ? %" PRIu64 " : %" PRIu64 ";\n", uintType, sc->gl_WorkGroupID_x, sc->firstStageStartSize / sc->fftDim, ((uint64_t)floor(sc->fft_dim_full / ((double)sc->localSize[0] * sc->fftDim))) / (sc->firstStageStartSize / sc->fftDim), (uint64_t)ceil(((sc->fft_dim_full - (sc->firstStageStartSize / sc->fftDim) * ((((uint64_t)floor(sc->fft_dim_full / ((double)sc->localSize[0] * sc->fftDim))) / (sc->firstStageStartSize / sc->fftDim)) * sc->localSize[0] * sc->fftDim)) / (sc->firstStageStartSize / sc->fftDim)) / (double)used_registers_read), sc->localSize[0] * sc->localSize[1]);// sc->fft_dim_full, sc->gl_WorkGroupID_x, shiftX, sc->firstStageStartSize / sc->fftDim, sc->fftDim, sc->gl_WorkGroupID_x, shiftX, sc->firstStageStartSize / sc->fftDim, sc->localSize[0] * sc->firstStageStartSize, sc->fft_dim_full / (sc->localSize[0] * sc->fftDim));
temp_int.data.i = sc->firstStageStartSize.data.i / sc->fftDim.data.i;
PfDiv(sc, &sc->tempInt, &sc->gl_WorkGroupID_x, &temp_int);
temp_int1.data.i = ((int64_t)floor(sc->fft_dim_full.data.i / ((long double)batching_localSize.data.i * sc->fftDim.data.i))) / (sc->firstStageStartSize.data.i / sc->fftDim.data.i);
PfIf_eq_start(sc, &sc->tempInt, &temp_int1);
temp_int1.data.i = ((sc->fft_dim_full.data.i - (sc->firstStageStartSize.data.i / sc->fftDim.data.i) * ((((int64_t)floor(sc->fft_dim_full.data.i / ((long double)batching_localSize.data.i * sc->fftDim.data.i))) / (sc->firstStageStartSize.data.i / sc->fftDim.data.i)) * batching_localSize.data.i * sc->fftDim.data.i)) / (sc->firstStageStartSize.data.i / sc->fftDim.data.i));
PfMov(sc, &sc->blockInvocationID, &temp_int1);
PfIf_else(sc);
temp_int1.data.i = fftDim.data.i * batching_localSize.data.i;
PfMov(sc, &sc->blockInvocationID, &temp_int1);
PfIf_end(sc);
if (sc->stridedSharedLayout) {
PfMul(sc, &sc->tempInt, &sc->gl_LocalInvocationID_x, &sc->firstStageStartSize, 0);
PfAdd(sc, &sc->tempInt, &sc->tempInt, &sc->tempInt2);
}
else {
PfMul(sc, &sc->tempInt, &sc->gl_LocalInvocationID_y, &sc->firstStageStartSize, 0);
PfAdd(sc, &sc->tempInt, &sc->tempInt, &sc->tempInt2);
}
/*sc->useDisableThreads = 1;
PfIf_ge_start(sc, &sc->tempInt, &sc->fft_dim_full);
temp_int.data.i = 0;
PfMov(sc, &sc->disableThreads, &temp_int);
PfIf_end(sc);*/
}
}
if (sc->useDisableThreads) {
temp_int.data.i = 0;
PfIf_gt_start(sc, &sc->disableThreads, &temp_int);
}
if (bufferStride[1].data.i == fftDim.data.i) {
PfMul(sc, &sc->inoutID, &bufferStride[1], &sc->shiftY, 0);
PfAdd(sc, &sc->inoutID, &sc->inoutID, &sc->shiftZ);
if (sc->localSize[1].data.i == 1) {
PfAdd(sc, &sc->inoutID, &sc->inoutID, &sc->gl_LocalInvocationID_x);
}
else {
PfAdd(sc, &sc->inoutID, &sc->inoutID, &sc->gl_LocalInvocationID_x);
PfMul(sc, &sc->combinedID, &sc->localSize[0], &sc->gl_LocalInvocationID_y, 0);
PfAdd(sc, &sc->inoutID, &sc->inoutID, &sc->combinedID);
}
}
//for (uint64_t k = 0; k < &sc->registerBoost; k++) {
for (int k = 0; k < sc->registerBoost; k++) {
//for (uint64_t i = 0; i < used_registers; i++) {
for (int i = 0; i < used_registers.data.i; i++) {
//combined thread numeration
if (sc->localSize[1].data.i == 1) {
//&sc->tempIntLen = sprintf(&sc->tempIntStr, " combinedID = %s + %" PRIu64 ";\n", &sc->gl_LocalInvocationID_x, (i + k * used_registers) * &sc->localSize[0]);
temp_int.data.i = (k * used_registers.data.i + i) * sc->localSize[0].data.i;
PfAdd(sc, &sc->combinedID, &sc->gl_LocalInvocationID_x, &temp_int);
}
else {
//&sc->tempIntLen = sprintf(&sc->tempIntStr, " combinedID = (%s + %" PRIu64 " * %s) + %" PRIu64 ";\n", &sc->gl_LocalInvocationID_x, &sc->localSize[0], &sc->gl_LocalInvocationID_y, (i + k * used_registers) * &sc->localSize[0] * &sc->localSize[1]);
PfMul(sc, &sc->combinedID, &sc->localSize[0], &sc->gl_LocalInvocationID_y, 0);
PfAdd(sc, &sc->combinedID, &sc->combinedID, &sc->gl_LocalInvocationID_x);
temp_int.data.i = (k * used_registers.data.i + i) * sc->localSize[0].data.i * sc->localSize[1].data.i;
PfAdd(sc, &sc->combinedID, &sc->combinedID, &temp_int);
}
//set inoutID - global array index. Two batching options - in consecutive x (if multi-upload), &in y if multidimensional.
if (sc->fftDim.data.i == sc->fft_dim_full.data.i) {
//&sc->tempIntLen = sprintf(&sc->tempIntStr, " inoutID = (combinedID %% %" PRIu64 ") + (combinedID / %" PRIu64 ") * %" PRIu64 ";\n", &sc->fftDim, &sc->fftDim, &sc->inputStride[1]);
PfMod(sc, &sc->inoutID_x, &sc->combinedID, &fftDim);
PfDiv(sc, &sc->inoutID_y, &sc->combinedID, &fftDim);
if (mult.data.i > 1) {
PfMul(sc, &sc->inoutID_y, &sc->inoutID_y, &mult, 0);
}
PfAdd(sc, &sc->inoutID_y, &sc->inoutID_y, &sc->shiftY);
checkZeropadStart(sc, &sc->inoutID_y, 1);
//PfMul(sc, &sc->tempInt, &batching_localSize, &sc->shiftY,0);
//PfAdd(sc, &sc->inoutID_y, &sc->inoutID_y, &sc->tempInt);
temp_int.data.i = batching_localSize.data.i;
//we switched to reading 2x more data, but we still need to check out of bounds for odd size1
if ((sc->mergeSequencesR2C) && (mult.data.i == 1))
temp_int.data.i *= 2;
if ((size1.data.i % temp_int.data.i) != 0) {
#if (VKFFT_BACKEND!=2) //AMD compiler fix
//&sc->tempIntLen = sprintf(&sc->tempIntStr, " if(combinedID / %" PRIu64 " + (%s%s)*%" PRIu64 "< %" PRIu64 "){\n", &sc->fftDim, &sc->gl_WorkGroupID_y, shiftY, &sc->localSize[0], &sc->size[&sc->axis_id + 1]);
if ((sc->mergeSequencesR2C) && (sc->size[1].data.i % 2) && (readWrite == 0)) {
PfIf_ge_start(sc, &sc->inoutID_y, &sc->size[1]);
PfSetToZero(sc, &sc->inoutID_x);
PfSetToZero(sc, &sc->inoutID_y);
PfIf_end(sc);
}
else {
PfIf_lt_start(sc, &sc->inoutID_y, &sc->size[1]);
}
#else
//&sc->tempIntLen = sprintf(&sc->tempIntStr, " if(!(combinedID / %" PRIu64 " + (%s%s)*%" PRIu64 "< %" PRIu64 ")) %s = 0; {\n", &sc->fftDim, &sc->gl_WorkGroupID_y, shiftY, &sc->localSize[0], &sc->size[&sc->axis_id + 1], &sc->inoutID);
if (readWrite == 0) {
PfIf_ge_start(sc, &sc->inoutID_y, &sc->size[1]);
PfSetToZero(sc, &sc->inoutID_x);
PfSetToZero(sc, &sc->inoutID_y);
PfIf_end(sc);
}
else {
PfIf_lt_start(sc, &sc->inoutID_y, &sc->size[1]);
}
#endif
}
}
else {
//&sc->tempIntLen = sprintf(&sc->tempIntStr, " inoutID = (combinedID %% %" PRIu64 ") + (combinedID / %" PRIu64 ") * %" PRIu64 " + ((%s%s) %% %" PRIu64 ") * %" PRIu64 " + ((%s%s) / %" PRIu64 ") * %" PRIu64 ";\n", &sc->fftDim, &sc->fftDim, &sc->firstStageStartSize, &sc->gl_WorkGroupID_x, shiftX, &sc->firstStageStartSize / &sc->fftDim, &sc->fftDim, &sc->gl_WorkGroupID_x, shiftX, &sc->firstStageStartSize / &sc->fftDim, &sc->localSize[0] * &sc->firstStageStartSize);
if ((sc->reorderFourStep) && (readWrite == 1)) {
PfMod(sc, &sc->inoutID_x, &sc->combinedID, &batching_localSize);
temp_int.data.i = sc->firstStageStartSize.data.i / sc->fftDim.data.i;
PfDiv(sc, &sc->tempInt, &sc->shiftX, &temp_int);
PfMul(sc, &sc->tempInt, &sc->tempInt, &batching_localSize, 0);
PfAdd(sc, &sc->inoutID_x, &sc->inoutID_x, &sc->tempInt);
PfDiv(sc, &sc->tempInt2, &sc->combinedID, &batching_localSize);
temp_int.data.i = sc->fft_dim_full.data.i / sc->fftDim.data.i;
PfMul(sc, &sc->tempInt2, &sc->tempInt2, &temp_int, 0);
temp_int.data.i = sc->firstStageStartSize.data.i / sc->fftDim.data.i;
PfMod(sc, &sc->tempInt, &sc->shiftX, &temp_int);
temp_int.data.i = sc->fft_dim_full.data.i / sc->firstStageStartSize.data.i;
PfMul(sc, &sc->tempInt, &sc->tempInt, &temp_int, 0);
PfAdd(sc, &sc->tempInt2, &sc->tempInt2, &sc->tempInt);
PfAdd(sc, &sc->inoutID_x, &sc->inoutID_x, &sc->tempInt2);
}
else {
PfMod(sc, &sc->inoutID_x, &sc->combinedID, &sc->fftDim);
PfDiv(sc, &sc->tempInt, &sc->combinedID, &sc->fftDim);
PfMul(sc, &sc->tempInt, &sc->tempInt, &sc->firstStageStartSize, 0);
PfAdd(sc, &sc->inoutID_x, &sc->inoutID_x, &sc->tempInt);
PfAdd(sc, &sc->inoutID_x, &sc->inoutID_x, &sc->tempInt2);
//PfIf_lt_start(sc, &sc->inoutID_x, &sc->size[sc->axis_id]);
}
}
if ((sc->fftDim.data.i != sc->fft_dim_full.data.i) && (!((sc->reorderFourStep) && (readWrite == 1)))) {
PfIf_lt_start(sc, &sc->combinedID, &sc->blockInvocationID);
}
else {
temp_int.data.i = (k * used_registers.data.i + i + 1) * sc->localSize[0].data.i * sc->localSize[1].data.i;
temp_int1.data.i = fftDim.data.i * batching_localSize.data.i;
if ((sc->mergeSequencesR2C) && (mult.data.i == 1))
temp_int1.data.i *= 2;
if (temp_int.data.i > temp_int1.data.i) {
//check that we only read fftDim * local batch data
//&sc->tempIntLen = sprintf(&sc->tempIntStr, " if(combinedID < %" PRIu64 "){\n", &sc->fftDim * &sc->localSize[0]);
PfIf_lt_start(sc, &sc->combinedID, &temp_int1);
}
}
temp_int.data.i = batching_localSize.data.i;
//we switched to reading 2x more data, but we still need to check out of bounds for odd size1
if ((sc->mergeSequencesR2C) && (mult.data.i == 1))
temp_int.data.i *= 2;
#if (VKFFT_BACKEND!=2) //AMD compiler fix
if ((bufferStride[1].data.i == fftDim.data.i) && (!(((size1.data.i % temp_int.data.i) != 0) && (sc->mergeSequencesR2C) && (sc->size[1].data.i % 2) && (readWrite == 0))) && (!sc->mergeSequencesR2C)) {
#else
if ((bufferStride[1].data.i == fftDim.data.i) && (!(((size1.data.i % temp_int.data.i) != 0) && (readWrite == 0))) && (!sc->mergeSequencesR2C)) {
#endif
if (k * used_registers.data.i + i > 0) {
temp_int.data.i = sc->localSize[0].data.i * sc->localSize[1].data.i;
PfAdd(sc, &sc->inoutID, &sc->inoutID, &temp_int);
}
}
else {
PfMov(sc, &sc->inoutID, &sc->inoutID_x);
if (sc->fftDim.data.i == sc->fft_dim_full.data.i) {
PfMul(sc, &sc->tempInt, &sc->inoutID_y, &bufferStride[1], 0);
PfAdd(sc, &sc->inoutID, &sc->inoutID, &sc->tempInt);
}
PfAdd(sc, &sc->inoutID, &sc->inoutID, &sc->shiftZ);
}
if ((sc->readToRegisters && (readWrite == 0)) || (sc->writeFromRegisters && (readWrite == 1))) {
//no need to calculate register addresses
}
else {
if (sc->stridedSharedLayout) {
if ((sc->reorderFourStep) && (readWrite == 1)) {
//sc->tempLen = sprintf(sc->tempStr, " %s[%s] = %ssdata[(combinedID %% %s)+(combinedID/%s)*sharedStride]%s;\n", outputsStruct, sc->inoutID, convTypeLeft, sc->gl_WorkGroupSize_x, sc->gl_WorkGroupSize_x, convTypeRight);
PfMod(sc, &sc->sdataID, &sc->combinedID, &sc->localSize[0]);
PfDiv(sc, &sc->tempInt, &sc->combinedID, &sc->localSize[0]);
PfMul(sc, &sc->tempInt, &sc->tempInt, &sc->sharedStride, 0);
PfAdd(sc, &sc->sdataID, &sc->sdataID, &sc->tempInt);
}
else {
//&sc->tempIntLen = sprintf(&sc->tempIntStr, " sdata[(combinedID %% %" PRIu64 ") * sharedStride + (combinedID / %" PRIu64 ")] = %s%s[%s]%s;\n", &sc->fftDim, &sc->fftDim, convTypeLeft, &inputsStruct, &sc->inoutID, convTypeRight);
temp_int.data.i = fftDim.data.i;
if ((sc->mergeSequencesR2C) && (mult.data.i == 1))
temp_int.data.i *= 2;
PfMod(sc, &sc->sdataID, &sc->combinedID, &temp_int);
if ((type == 142) && (!sc->readToRegisters) && (readWrite == 0)) {
temp_int1.data.i = 2;
PfDiv(sc, &sc->sdataID, &sc->sdataID, &temp_int1);
}
PfMul(sc, &sc->sdataID, &sc->sdataID, &sc->sharedStride, 0);
PfDiv(sc, &sc->tempInt, &sc->combinedID, &temp_int);
PfAdd(sc, &sc->sdataID, &sc->sdataID, &sc->tempInt);
}
}
else {
if ((sc->reorderFourStep) && (readWrite == 1)) {
//sc->tempLen = sprintf(sc->tempStr, " %s[%s] = %ssdata[(combinedID %% %s)*sharedStride+combinedID/%s]%s;\n", outputsStruct, sc->inoutID, convTypeLeft, sc->gl_WorkGroupSize_y, sc->gl_WorkGroupSize_y, convTypeRight);
PfMod(sc, &sc->sdataID, &sc->combinedID, &sc->localSize[1]);
PfMul(sc, &sc->sdataID, &sc->sdataID, &sc->sharedStride, 0);
PfDiv(sc, &sc->tempInt, &sc->combinedID, &sc->localSize[1]);
PfAdd(sc, &sc->sdataID, &sc->sdataID, &sc->tempInt);
}
else {
//&sc->tempIntLen = sprintf(&sc->tempIntStr, " sdata[(combinedID %% %" PRIu64 ") + (combinedID / %" PRIu64 ") * sharedStride] = %s%s[%s]%s;\n", &sc->fftDim, &sc->fftDim, convTypeLeft, &inputsStruct, &sc->inoutID, convTypeRight);
temp_int.data.i = fftDim.data.i;
if ((sc->mergeSequencesR2C) && (mult.data.i == 1))
temp_int.data.i *= 2;
PfMod(sc, &sc->sdataID, &sc->combinedID, &temp_int);
if ((type == 142) && (!sc->readToRegisters) && (readWrite == 0)) {
temp_int1.data.i = 2;
PfDiv(sc, &sc->sdataID, &sc->sdataID, &temp_int1);
}
PfDiv(sc, &sc->tempInt, &sc->combinedID, &temp_int);
PfMul(sc, &sc->tempInt, &sc->tempInt, &sc->sharedStride, 0);
PfAdd(sc, &sc->sdataID, &sc->sdataID, &sc->tempInt);
}
}
}
if ((sc->zeropad[readWrite]) || ((sc->numAxisUploads > 1) && (sc->zeropadBluestein[readWrite]))) {
//sc->tempLen = sprintf(sc->tempStr, " if((inoutID %% %" PRIu64 " < %" PRIu64 ")||(inoutID %% %" PRIu64 " >= %" PRIu64 ")){\n", sc->fft_dim_full, sc->fft_zeropad_left_read[sc->axis_id], sc->fft_dim_full, sc->fft_zeropad_right_read[sc->axis_id]);
PfSetToZero(sc, &sc->tempInt);
//PfMod(sc, &sc->combinedID, &sc->inoutID_x, &sc->fft_dim_full);
if (sc->zeropad[readWrite]) {
if (readWrite)
PfIf_lt_start(sc, &sc->inoutID_x, &sc->fft_zeropad_left_write[sc->axis_id]);
else
PfIf_lt_start(sc, &sc->inoutID_x, &sc->fft_zeropad_left_read[sc->axis_id]);
temp_int.data.i = 1;
PfMov(sc, &sc->tempInt, &temp_int);
PfIf_else(sc);
if (readWrite) {
PfIf_ge_start(sc, &sc->inoutID_x, &sc->fft_zeropad_right_write[sc->axis_id]);
}
else {
PfIf_ge_start(sc, &sc->inoutID_x, &sc->fft_zeropad_right_read[sc->axis_id]);
}
temp_int.data.i = 1;
PfMov(sc, &sc->tempInt, &temp_int);
PfIf_end(sc);
PfIf_end(sc);
}
if (sc->numAxisUploads > 1) {
if (sc->zeropadBluestein[readWrite]) {
if (readWrite)
PfIf_lt_start(sc, &sc->inoutID_x, &sc->fft_zeropad_Bluestein_left_write[sc->axis_id]);
else
PfIf_lt_start(sc, &sc->inoutID_x, &sc->fft_zeropad_Bluestein_left_read[sc->axis_id]);
temp_int.data.i = 1;
PfMov(sc, &sc->tempInt, &temp_int);
PfIf_end(sc);
}
}
temp_int.data.i = 0;
PfIf_gt_start(sc, &sc->tempInt, &temp_int);
}
if (readWrite == 0) {
if ((type == 5) || (type == 110) || (type == 120) || (type == 130) || (type == 144)) {
if (sc->readToRegisters) {
appendGlobalToRegisters_x(sc, &sc->regIDs[k * sc->registers_per_thread + i], &sc->inputsStruct, &sc->inoutID);
if (sc->mergeSequencesR2C) {
if ((sc->size[1].data.i % 2) != 0) {
temp_int.data.i = sc->size[1].data.i - 1;
PfIf_lt_start(sc, &sc->inoutID_y, &temp_int);
}
PfAdd(sc, &sc->inoutID, &sc->inoutID, &sc->inputStride[1]);
if ((sc->size[1].data.i % 2) != 0) {
PfIf_end(sc);
}
appendGlobalToRegisters_y(sc, &sc->regIDs[k * sc->registers_per_thread + i], &sc->inputsStruct, &sc->inoutID);
}
}
else {
appendGlobalToRegisters_x(sc, &sc->temp, &sc->inputsStruct, &sc->inoutID);
if (sc->mergeSequencesR2C) {
if ((sc->size[1].data.i % 2) != 0) {
temp_int.data.i = sc->size[1].data.i - 1;
PfIf_lt_start(sc, &sc->inoutID_y, &temp_int);
}
PfAdd(sc, &sc->inoutID, &sc->inoutID, &sc->inputStride[1]);
if ((sc->size[1].data.i % 2) != 0) {
PfIf_end(sc);
}
appendGlobalToRegisters_y(sc, &sc->temp, &sc->inputsStruct, &sc->inoutID);
}
appendRegistersToShared(sc, &sc->sdataID, &sc->temp);
}
}
else if (type == 142) {
if (sc->readToRegisters) {
if (i < used_registers.data.i / 2) {
appendGlobalToRegisters_x(sc, &sc->regIDs[k * sc->registers_per_thread + i], &sc->inputsStruct, &sc->inoutID);
}
else {
appendGlobalToRegisters_y(sc, &sc->regIDs[k * sc->registers_per_thread + i - used_registers.data.i / 2], &sc->inputsStruct, &sc->inoutID);
}
}
else {
PfMod(sc, &sc->tempInt, &sc->combinedID, &fftDim);
temp_int.data.i = 2;
PfMod(sc, &sc->tempInt, &sc->tempInt, &temp_int);
appendGlobalToRegisters_x(sc, &sc->temp, &sc->inputsStruct, &sc->inoutID);
temp_int.data.i = 0;
PfIf_eq_start(sc, &sc->tempInt, &temp_int);
appendRegistersToShared_x_x(sc, &sc->sdataID, &sc->temp);
PfIf_else(sc);
appendRegistersToShared_y_x(sc, &sc->sdataID, &sc->temp);
PfIf_end(sc);
}
}
else {
if (sc->readToRegisters) {
appendGlobalToRegisters(sc, &sc->regIDs[k * sc->registers_per_thread + i], &sc->inputsStruct, &sc->inoutID);
}
else {
appendGlobalToShared(sc, &sc->sdataID, &sc->inputsStruct, &sc->inoutID);
}
}
if ((sc->zeropad[readWrite]) || ((sc->numAxisUploads > 1) && (sc->zeropadBluestein[readWrite]))) {
PfIf_else(sc);
if (sc->readToRegisters) {
PfSetToZero(sc, &sc->regIDs[k * sc->registers_per_thread + i]);
}
else {
PfSetToZeroShared(sc, &sc->sdataID);
}
}
}
else {
if ((type == 6) || (type == 110) || (type == 120) || (type == 130) || (type == 144)) {
if (sc->writeFromRegisters) {
appendRegistersToGlobal_x(sc, &sc->outputsStruct, &sc->inoutID, &sc->regIDs[k * sc->registers_per_thread + i]);
if (sc->mergeSequencesR2C) {
if ((sc->size[1].data.i % 2) != 0) {
temp_int.data.i = sc->size[1].data.i - 1;
PfIf_lt_start(sc, &sc->inoutID_y, &temp_int);
}
PfAdd(sc, &sc->inoutID, &sc->inoutID, &sc->outputStride[1]);
appendRegistersToGlobal_y(sc, &sc->outputsStruct, &sc->inoutID, &sc->regIDs[k * sc->registers_per_thread + i]);
if ((sc->size[1].data.i % 2) != 0) {
PfIf_end(sc);
}
}
}
else {
appendSharedToRegisters(sc, &sc->temp, &sc->sdataID);
appendRegistersToGlobal_x(sc, &sc->outputsStruct, &sc->inoutID, &sc->temp);
if (sc->mergeSequencesR2C) {
if ((sc->size[1].data.i % 2) != 0) {
temp_int.data.i = sc->size[1].data.i - 1;
PfIf_lt_start(sc, &sc->inoutID_y, &temp_int);
}
PfAdd(sc, &sc->inoutID, &sc->inoutID, &sc->outputStride[1]);
appendRegistersToGlobal_y(sc, &sc->outputsStruct, &sc->inoutID, &sc->temp);
if ((sc->size[1].data.i % 2) != 0) {
PfIf_end(sc);
}
}
}
}
else if (type == 142) {
if (sc->writeFromRegisters) {
appendRegistersToGlobal_x(sc, &sc->outputsStruct, &sc->inoutID, &sc->regIDs[k * sc->registers_per_thread + i]);
PfAdd(sc, &sc->inoutID, &sc->inoutID, &fftDim);
appendRegistersToGlobal_y(sc, &sc->outputsStruct, &sc->inoutID, &sc->regIDs[k * sc->registers_per_thread + i]);
}
else {
}
}
else {
if (sc->writeFromRegisters) {
appendRegistersToGlobal(sc, &sc->outputsStruct, &sc->inoutID, &sc->regIDs[k * sc->registers_per_thread + i]);
}
else {
appendSharedToGlobal(sc, &sc->outputsStruct, &sc->inoutID, &sc->sdataID);
}
}
}
if ((sc->zeropad[readWrite]) || ((sc->numAxisUploads > 1) && (sc->zeropadBluestein[readWrite]))) {
PfIf_end(sc);
}
if ((sc->fftDim.data.i != sc->fft_dim_full.data.i) && (!((sc->reorderFourStep) && (readWrite == 1)))) {
PfIf_end(sc);
}
else {
temp_int.data.i = (k * used_registers.data.i + i + 1) * sc->localSize[0].data.i * sc->localSize[1].data.i;
temp_int1.data.i = fftDim.data.i * batching_localSize.data.i;
if ((sc->mergeSequencesR2C) && (mult.data.i == 1))
temp_int1.data.i *= 2;
if (temp_int.data.i > temp_int1.data.i) {
PfIf_end(sc);
}
}
if (sc->fftDim.data.i == sc->fft_dim_full.data.i) {
checkZeropadEnd(sc, 1);
temp_int.data.i = batching_localSize.data.i;
//we switched to reading 2x more data, but we still need to check out of bounds for odd size1
if ((sc->mergeSequencesR2C) && (mult.data.i == 1))
temp_int.data.i *= 2;
if ((size1.data.i % temp_int.data.i) != 0) {
#if (VKFFT_BACKEND!=2) //AMD compiler fix
if ((sc->mergeSequencesR2C) && (sc->size[1].data.i % 2) && (readWrite == 0)) {
}
else {
PfIf_end(sc);
}
#else
if (readWrite != 0) {
PfIf_end(sc);
}
#endif
}
}
else {
if ((sc->reorderFourStep) && (readWrite == 1)) {
}
else {
//PfIf_end(sc);
}
}
}
}
if (sc->useDisableThreads) {
PfIf_end(sc);
}
if ((sc->fftDim.data.i != sc->fft_dim_full.data.i) && ((sc->reorderFourStep) && (readWrite == 1))) {
PfIf_end(sc);
}
return;
}
static inline void appendReadWriteDataVkFFT_strided(VkFFTSpecializationConstantsLayout* sc, int readWrite, int type) {
if (sc->res != VKFFT_SUCCESS) return;
PfContainer temp_int = VKFFT_ZERO_INIT;
temp_int.type = 31;
PfContainer temp_int1 = VKFFT_ZERO_INIT;
temp_int1.type = 31;
PfContainer used_registers = VKFFT_ZERO_INIT;
used_registers.type = 31;
PfContainer* bufferStride = (readWrite) ? sc->outputStride : sc->inputStride;
if ((!sc->writeFromRegisters) && (readWrite == 1))
appendBarrierVkFFT(sc);
//char shiftX[500] = "";
//if (&sc->performWorkGroupShift[0])
// sprintf(shiftX, " + consts.workGroupShiftX * %s ", &sc->gl_WorkGroupSize_x);
PfContainer fftDim = VKFFT_ZERO_INIT;
fftDim.type = 31;
if (sc->zeropadBluestein[readWrite]) {
if (sc->numAxisUploads == 1) {
if (readWrite) {
fftDim.data.i = sc->fft_zeropad_Bluestein_left_write[sc->axis_id].data.i;
}
else {
if (sc->readToRegisters == 0) {
appendSetSMToZero(sc);
appendBarrierVkFFT(sc);
}
fftDim.data.i = sc->fft_zeropad_Bluestein_left_read[sc->axis_id].data.i;
}
}
else {
fftDim.data.i = sc->fftDim.data.i;
}
}
else
fftDim.data.i = sc->fftDim.data.i;
if (type == 111) {
fftDim.data.i = (fftDim.data.i + 2) / 2;
}
else if ((type == 143) && (readWrite == 0)) {
fftDim.data.i = 2 * fftDim.data.i;
}
if (readWrite == 0) {
if (sc->performWorkGroupShift[0]) {
PfMul(sc, &sc->shiftX, &sc->workGroupShiftX, &sc->gl_WorkGroupSize_x, 0);
PfAdd(sc, &sc->shiftX, &sc->gl_GlobalInvocationID_x, &sc->shiftX);
}
else {
PfMov(sc, &sc->shiftX, &sc->gl_GlobalInvocationID_x);
}
if (sc->axis_id == 0) {
if (sc->size[1].data.i > 1) {
if (sc->performWorkGroupShift[1]) {
PfAdd(sc, &sc->shiftY, &sc->gl_WorkGroupID_y, &sc->workGroupShiftY);
checkZeropad(sc, &sc->shiftY, 1);
temp_int.data.i = sc->inputStride[1].data.i;
PfMul(sc, &sc->shiftZ, &sc->shiftY, &temp_int, 0);
}
else
{
PfMov(sc, &sc->shiftY, &sc->gl_WorkGroupID_y);
checkZeropad(sc, &sc->shiftY, 1);
temp_int.data.i = sc->inputStride[1].data.i;
PfMul(sc, &sc->shiftZ, &sc->shiftY, &temp_int, 0);
}
}
else
{
PfSetToZero(sc, &sc->shiftZ);
}
}
else {
PfSetToZero(sc, &sc->shiftZ);
}
appendOffset(sc, readWrite, type);
if (sc->axis_id > 0) {
PfMod(sc, &sc->inoutID_x, &sc->shiftX, &sc->fft_dim_x);
checkZeropad(sc, &sc->inoutID_x, 0);
//&sc->tempIntLen = sprintf(&sc->tempIntStr, " disableThreads = (((%s%s) / %" PRIu64 ") %% (%" PRIu64 ")+((%s%s) / %" PRIu64 ") * (%" PRIu64 ") < %" PRIu64 ") ? 1 : 0;\n", &sc->gl_GlobalInvocationID_x, shiftX, &sc->fft_dim_x, &sc->stageStartSize, &sc->gl_GlobalInvocationID_x, shiftX, &sc->fft_dim_x * &sc->stageStartSize, &sc->fftDim * &sc->stageStartSize, &sc->size[&sc->axis_id]);
PfDiv(sc, &sc->tempInt2, &sc->shiftX, &sc->fft_dim_x);
PfMod(sc, &sc->tempInt2, &sc->tempInt2, &sc->stageStartSize);
PfMul(sc, &temp_int, &sc->fft_dim_x, &sc->stageStartSize, 0);
PfDiv(sc, &sc->tempInt, &sc->shiftX, &temp_int); // disableThreads - tempInt3
PfMul(sc, &temp_int, &fftDim, &sc->stageStartSize, 0);
PfMul(sc, &sc->tempInt, &sc->tempInt, &temp_int, 0);
PfAdd(sc, &sc->tempInt2, &sc->tempInt2, &sc->tempInt);
if (sc->numAxisUploads > 1) {
PfIf_lt_start(sc, &sc->tempInt2, &sc->fft_dim_full);
}
else {
PfIf_lt_start(sc, &sc->tempInt2, &sc->sourceFFTSize);
}
}
else {
//&sc->tempIntLen = sprintf(&sc->tempIntStr, " disableThreads = (((%s%s) / %" PRIu64 ") * (%" PRIu64 ") < %" PRIu64 ") ? 1 : 0;\n", &sc->gl_GlobalInvocationID_x, shiftX, &sc->stageStartSize, &sc->stageStartSize * &sc->fftDim, &sc->fft_dim_full);
PfDiv(sc, &sc->tempInt2, &sc->shiftX, &sc->stageStartSize);
PfMul(sc, &temp_int, &sc->fftDim, &sc->stageStartSize, 0);
PfMul(sc, &sc->tempInt2, &sc->tempInt2, &temp_int, 0);
PfIf_lt_start(sc, &sc->tempInt2, &sc->fft_dim_full);
}
//PfIf_gt_start(sc, &sc->disableThreads, &temp_int1);
}
else {
int isInputStrideNotEqualToOutput = 0;
for (int i = 0; i < sc->numFFTdims+2; i++){
if ((sc->inputStride[i].type>100)||(sc->outputStride[i].type>100)||(sc->inputStride[i].data.i != sc->outputStride[i].data.i)) {
isInputStrideNotEqualToOutput = 1;
}
}
if ((isInputStrideNotEqualToOutput) || (sc->performPostCompilationInputOffset) || (sc->performPostCompilationOutputOffset) || ((sc->inputOffset.data.i != sc->outputOffset.data.i) && (sc->inputOffset.type < 100) && (sc->outputOffset.type < 100)) || ((sc->convolutionStep) && (sc->matrixConvolution > 1)) || (sc->batchID.data.i > 0)) {
if (sc->axis_id == 0) {
if (sc->size[1].data.i > 1) {
if (sc->performWorkGroupShift[1]) {
PfAdd(sc, &sc->shiftY, &sc->gl_WorkGroupID_y, &sc->workGroupShiftY);
temp_int.data.i = sc->outputStride[1].data.i;
PfMul(sc, &sc->shiftZ, &sc->shiftY, &temp_int, 0);
}
else
{
PfMov(sc, &sc->shiftY, &sc->gl_WorkGroupID_y);
temp_int.data.i = sc->outputStride[1].data.i;
PfMul(sc, &sc->shiftZ, &sc->shiftY, &temp_int, 0);
}
}
else {
PfSetToZero(sc, &sc->shiftZ);
}
}
else {
PfSetToZero(sc, &sc->shiftZ);
}
appendOffset(sc, readWrite, type);
}
if ((sc->reorderFourStep) && (sc->stageStartSize.data.i == 1) && (sc->numAxisUploads > 1)) {
PfDiv(sc, &sc->inoutID, &sc->shiftX, &sc->fft_dim_x);
temp_int.data.i = sc->firstStageStartSize.data.i / fftDim.data.i;
PfMod(sc, &sc->tempInt2, &sc->inoutID, &temp_int);
temp_int.data.i = sc->fft_dim_full.data.i / sc->firstStageStartSize.data.i;
PfMul(sc, &sc->tempInt2, &sc->tempInt2, &temp_int, 0);
temp_int.data.i = sc->fft_dim_x.data.i * (sc->firstStageStartSize.data.i / fftDim.data.i);
PfDiv(sc, &sc->tempInt, &sc->shiftX, &temp_int);
PfAdd(sc, &sc->tempInt2, &sc->tempInt2, &sc->tempInt);
//sc->tempLen = sprintf(sc->tempStr, " if (((%s%s) / %" PRIu64 ") %% (%" PRIu64 ")+((%s%s) / %" PRIu64 ") * (%" PRIu64 ") < %" PRIu64 ") {\n", sc->gl_GlobalInvocationID_x, shiftX, sc->fft_dim_x, sc->stageStartSize, sc->gl_GlobalInvocationID_x, shiftX, sc->fft_dim_x * sc->stageStartSize, sc->fftDim * sc->stageStartSize, sc->size[sc->axis_id]);
PfMod(sc, &sc->tempInt, &sc->inoutID, &sc->stageStartSize);
temp_int.data.i = sc->fft_dim_x.data.i * sc->stageStartSize.data.i;
PfDiv(sc, &sc->inoutID, &sc->shiftX, &temp_int);
temp_int.data.i = fftDim.data.i * sc->stageStartSize.data.i;
PfMul(sc, &sc->inoutID, &sc->inoutID, &temp_int, 0);
PfAdd(sc, &sc->tempInt, &sc->tempInt, &sc->inoutID);
PfIf_lt_start(sc, &sc->tempInt, &sc->fft_dim_full);
}
else {
if (sc->axis_id > 0) {
if (sc->numAxisUploads > 1) {
PfIf_lt_start(sc, &sc->tempInt2, &sc->fft_dim_full);
}
else {
PfIf_lt_start(sc, &sc->tempInt2, &sc->sourceFFTSize);
}
}
else {
PfIf_lt_start(sc, &sc->tempInt2, &sc->fft_dim_full);
}
}
}
if (sc->useDisableThreads) {
temp_int.data.i = 0;
PfIf_gt_start(sc, &sc->disableThreads, &temp_int);
}
PfDivCeil(sc, &used_registers, &fftDim, &sc->localSize[1]);
if (sc->registerBoost > 1) {
temp_int.data.i = sc->registerBoost;
PfDiv(sc, &used_registers, &used_registers, &temp_int);
}
if (sc->axis_id > 0) {
//&sc->tempIntLen = sprintf(&sc->tempIntStr, " inoutID = (%" PRIu64 " * (%s + %" PRIu64 ") + ((%s%s) / %" PRIu64 ") %% (%" PRIu64 ")+((%s%s) / %" PRIu64 ") * (%" PRIu64 "));\n", &sc->stageStartSize, &sc->gl_LocalInvocationID_y, (i + k * used_registers) * &sc->localSize[1], &sc->gl_GlobalInvocationID_x, shiftX, &sc->fft_dim_x, &sc->stageStartSize, &sc->gl_GlobalInvocationID_x, shiftX, &sc->fft_dim_x * &sc->stageStartSize, &sc->fftDim * &sc->stageStartSize);
if ((readWrite == 1) && (sc->reorderFourStep) && (sc->stageStartSize.data.i == 1) && (sc->numAxisUploads > 1)) {
temp_int1.data.i = sc->fft_dim_full.data.i / fftDim.data.i;
PfMul(sc, &sc->inoutID_y, &sc->gl_LocalInvocationID_y, &temp_int1, 0);
PfAdd(sc, &sc->inoutID_y, &sc->inoutID_y, &sc->tempInt2);
}
else {
PfMul(sc, &sc->inoutID_y, &sc->gl_LocalInvocationID_y, &sc->stageStartSize, 0);
PfAdd(sc, &sc->inoutID_y, &sc->inoutID_y, &sc->tempInt2);
}
}
else {
//&sc->tempIntLen = sprintf(&sc->tempIntStr, " inoutID = (%s%s) %% (%" PRIu64 ") + %" PRIu64 " * (%s + %" PRIu64 ") + ((%s%s) / %" PRIu64 ") * (%" PRIu64 ");\n", &sc->gl_GlobalInvocationID_x, shiftX, &sc->stageStartSize, &sc->stageStartSize, &sc->gl_LocalInvocationID_y, (i + k * used_registers) * &sc->localSize[1], &sc->gl_GlobalInvocationID_x, shiftX, &sc->stageStartSize, &sc->stageStartSize * &sc->fftDim);
PfMod(sc, &sc->inoutID_x, &sc->shiftX, &sc->stageStartSize);
PfMul(sc, &sc->tempInt, &sc->gl_LocalInvocationID_y, &sc->stageStartSize, 0);
PfAdd(sc, &sc->inoutID_x, &sc->inoutID_x, &sc->tempInt);
PfAdd(sc, &sc->inoutID_x, &sc->inoutID_x, &sc->tempInt2);
}
PfMov(sc, &sc->inoutID, &sc->inoutID_x);
if (sc->axis_id > 0) {
PfMul(sc, &sc->tempInt, &sc->inoutID_y, &bufferStride[1], 0);
PfAdd(sc, &sc->inoutID, &sc->inoutID, &sc->tempInt);
}
PfAdd(sc, &sc->inoutID, &sc->inoutID, &sc->shiftZ);
//for (uint64_t k = 0; k < &sc->registerBoost; k++) {
for (int k = 0; k < sc->registerBoost; k++) {
//for (uint64_t i = 0; i < used_registers; i++) {
for (int i = 0; i < used_registers.data.i; i++) {
temp_int1.data.i = (k * used_registers.data.i + i + 1) * sc->localSize[1].data.i;
if (temp_int1.data.i > fftDim.data.i) {
//&sc->tempIntLen = sprintf(&sc->tempIntStr, " if(%s < %" PRIu64 "){\n", &sc->gl_LocalInvocationID_y, &sc->fftDim - (i + k * used_registers) * &sc->localSize[1]);
temp_int1.data.i = sc->localSize[1].data.i - (temp_int1.data.i - fftDim.data.i);
PfIf_lt_start(sc, &sc->gl_LocalInvocationID_y, &temp_int1);
}
/*if (bufferStride[0].data.i != 1)
PfMul(sc, &sc->inoutID, &sc->inoutID_x, &bufferStride[0], 0);
else
PfMov(sc, &sc->inoutID, &sc->inoutID_x);
if (sc->axis_id > 0) {
PfMul(sc, &sc->tempInt, &sc->inoutID_y, &bufferStride[1], 0);
PfAdd(sc, &sc->inoutID, &sc->inoutID, &sc->tempInt);
}
PfAdd(sc, &sc->inoutID, &sc->inoutID, &sc->shiftZ);*/
if ((i > 0) || (k > 0)) {
if (sc->axis_id > 0) {
//&sc->tempIntLen = sprintf(&sc->tempIntStr, " inoutID = (%" PRIu64 " * (%s + %" PRIu64 ") + ((%s%s) / %" PRIu64 ") %% (%" PRIu64 ")+((%s%s) / %" PRIu64 ") * (%" PRIu64 "));\n", &sc->stageStartSize, &sc->gl_LocalInvocationID_y, (i + k * used_registers) * &sc->localSize[1], &sc->gl_GlobalInvocationID_x, shiftX, &sc->fft_dim_x, &sc->stageStartSize, &sc->gl_GlobalInvocationID_x, shiftX, &sc->fft_dim_x * &sc->stageStartSize, &sc->fftDim * &sc->stageStartSize);
if ((readWrite == 1) && (sc->reorderFourStep) && (sc->stageStartSize.data.i == 1) && (sc->numAxisUploads > 1)) {
temp_int1.data.i = sc->fft_dim_full.data.i / fftDim.data.i * bufferStride[1].data.i * sc->localSize[1].data.i;
PfAdd(sc, &sc->inoutID, &sc->inoutID, &temp_int1);
}
else {
temp_int1.data.i = sc->stageStartSize.data.i * bufferStride[1].data.i * sc->localSize[1].data.i;
PfAdd(sc, &sc->inoutID, &sc->inoutID, &temp_int1);
}
}
else {
//&sc->tempIntLen = sprintf(&sc->tempIntStr, " inoutID = (%s%s) %% (%" PRIu64 ") + %" PRIu64 " * (%s + %" PRIu64 ") + ((%s%s) / %" PRIu64 ") * (%" PRIu64 ");\n", &sc->gl_GlobalInvocationID_x, shiftX, &sc->stageStartSize, &sc->stageStartSize, &sc->gl_LocalInvocationID_y, (i + k * used_registers) * &sc->localSize[1], &sc->gl_GlobalInvocationID_x, shiftX, &sc->stageStartSize, &sc->stageStartSize * &sc->fftDim);
temp_int1.data.i = sc->stageStartSize.data.i * sc->localSize[1].data.i;
PfAdd(sc, &sc->inoutID, &sc->inoutID, &temp_int1);
}
}
temp_int.data.i = (k * used_registers.data.i + i) * sc->localSize[1].data.i;
if ((sc->readToRegisters && (readWrite == 0)) || (sc->writeFromRegisters && (readWrite == 1))) {
//if (&sc->inputBufferBlockNum == 1)
// &sc->tempIntLen = sprintf(&sc->tempIntStr, " %s=%s%s[%s]%s;\n", &sc->regIDs[i + k * &sc->registers_per_thread], convTypeLeft, &inputsStruct, &sc->inoutID, convTypeRight);
//else
// &sc->tempIntLen = sprintf(&sc->tempIntStr, " %s=%sinputBlocks[%s / %" PRIu64 "]%s[%s %% %" PRIu64 "]%s;\n", &sc->regIDs[i + k * &sc->registers_per_thread], convTypeLeft, &sc->inoutID, &sc->inputBufferBlockSize, &inputsStruct, &sc->inoutID, &sc->inputBufferBlockSize, convTypeRight);
}
else {
//if (&sc->inputBufferBlockNum == 1)
// &sc->tempIntLen = sprintf(&sc->tempIntStr, " sdata[%s*(%s+%" PRIu64 ")+%s]=%s%s[%s]%s;\n", &sc->sharedStride, &sc->gl_LocalInvocationID_y, (i + k * used_registers) * &sc->localSize[1], &sc->gl_LocalInvocationID_x, convTypeLeft, &inputsStruct, &sc->inoutID, convTypeRight);
//else
// &sc->tempIntLen = sprintf(&sc->tempIntStr, " sdata[%s*(%s+%" PRIu64 ")+%s]=%sinputBlocks[%s / %" PRIu64 "]%s[%s %% %" PRIu64 "]%s;\n", &sc->sharedStride, &sc->gl_LocalInvocationID_y, (i + k * used_registers) * &sc->localSize[1], &sc->gl_LocalInvocationID_x, convTypeLeft, &sc->inoutID, &sc->inputBufferBlockSize, &inputsStruct, &sc->inoutID, &sc->inputBufferBlockSize, convTypeRight);
PfAdd(sc, &sc->sdataID, &sc->gl_LocalInvocationID_y, &temp_int);
if ((type == 143) && (!sc->readToRegisters) && (readWrite == 0)) {
temp_int1.data.i = 2;
PfDiv(sc, &sc->sdataID, &sc->sdataID, &temp_int1);
}
PfMul(sc, &sc->sdataID, &sc->sharedStride, &sc->sdataID, 0);
PfAdd(sc, &sc->sdataID, &sc->sdataID, &sc->gl_LocalInvocationID_x);
}
if ((sc->zeropad[readWrite]) || ((sc->numAxisUploads > 1) && (sc->zeropadBluestein[readWrite]))) {
//sc->tempLen = sprintf(sc->tempStr, " if((inoutID %% %" PRIu64 " < %" PRIu64 ")||(inoutID %% %" PRIu64 " >= %" PRIu64 ")){\n", sc->fft_dim_full, sc->fft_zeropad_left_read[sc->axis_id], sc->fft_dim_full, sc->fft_zeropad_right_read[sc->axis_id]);
temp_int.data.i = 1;
PfSetToZero(sc, &sc->tempInt);
if ((i > 0) && (k == 0)) {
if (sc->axis_id > 0) {
//&sc->tempIntLen = sprintf(&sc->tempIntStr, " inoutID = (%" PRIu64 " * (%s + %" PRIu64 ") + ((%s%s) / %" PRIu64 ") %% (%" PRIu64 ")+((%s%s) / %" PRIu64 ") * (%" PRIu64 "));\n", &sc->stageStartSize, &sc->gl_LocalInvocationID_y, (i + k * used_registers) * &sc->localSize[1], &sc->gl_GlobalInvocationID_x, shiftX, &sc->fft_dim_x, &sc->stageStartSize, &sc->gl_GlobalInvocationID_x, shiftX, &sc->fft_dim_x * &sc->stageStartSize, &sc->fftDim * &sc->stageStartSize);
if ((readWrite == 1) && (sc->reorderFourStep) && (sc->stageStartSize.data.i == 1) && (sc->numAxisUploads > 1)) {
temp_int1.data.i = sc->fft_dim_full.data.i / fftDim.data.i * sc->localSize[1].data.i;
PfAdd(sc, &sc->inoutID_y, &sc->inoutID_y, &temp_int1);
}
else {
temp_int1.data.i = sc->stageStartSize.data.i * sc->localSize[1].data.i;
PfAdd(sc, &sc->inoutID_y, &sc->inoutID_y, &temp_int1);
}
}
else {
//&sc->tempIntLen = sprintf(&sc->tempIntStr, " inoutID = (%s%s) %% (%" PRIu64 ") + %" PRIu64 " * (%s + %" PRIu64 ") + ((%s%s) / %" PRIu64 ") * (%" PRIu64 ");\n", &sc->gl_GlobalInvocationID_x, shiftX, &sc->stageStartSize, &sc->stageStartSize, &sc->gl_LocalInvocationID_y, (i + k * used_registers) * &sc->localSize[1], &sc->gl_GlobalInvocationID_x, shiftX, &sc->stageStartSize, &sc->stageStartSize * &sc->fftDim);
temp_int1.data.i = sc->stageStartSize.data.i * sc->localSize[1].data.i;
PfAdd(sc, &sc->inoutID_x, &sc->inoutID_x, &temp_int1);
}
}
if (sc->axis_id > 0)
PfMod(sc, &sc->combinedID, &sc->inoutID_y, &sc->fft_dim_full);
else
PfMod(sc, &sc->combinedID, &sc->inoutID_x, &sc->fft_dim_full);
if (sc->zeropad[readWrite]) {
if (readWrite)
PfIf_lt_start(sc, &sc->combinedID, &sc->fft_zeropad_left_write[sc->axis_id]);
else
PfIf_lt_start(sc, &sc->combinedID, &sc->fft_zeropad_left_read[sc->axis_id]);
PfMov(sc, &sc->tempInt, &temp_int);
PfIf_else(sc);
if (readWrite)
PfIf_ge_start(sc, &sc->combinedID, &sc->fft_zeropad_right_write[sc->axis_id]);
else
PfIf_ge_start(sc, &sc->combinedID, &sc->fft_zeropad_right_read[sc->axis_id]);
PfMov(sc, &sc->tempInt, &temp_int);
PfIf_end(sc);
PfIf_end(sc);
}
if (sc->numAxisUploads > 1) {
if (sc->zeropadBluestein[readWrite]) {
if (readWrite)
PfIf_lt_start(sc, &sc->combinedID, &sc->fft_zeropad_Bluestein_left_write[sc->axis_id]);
else
PfIf_lt_start(sc, &sc->combinedID, &sc->fft_zeropad_Bluestein_left_read[sc->axis_id]);
PfMov(sc, &sc->tempInt, &temp_int);
PfIf_end(sc);
}
}
temp_int.data.i = 0;
PfIf_gt_start(sc, &sc->tempInt, &temp_int);
}
temp_int1.data.i = k * used_registers.data.i + i;
if (readWrite == 0) {
if ((type == 111) || (type == 121) || (type == 131) || (type == 145)) {
if (sc->readToRegisters) {
appendGlobalToRegisters_x(sc, &sc->regIDs[temp_int1.data.i], &sc->inputsStruct, &sc->inoutID);
}
else {
appendGlobalToRegisters_x(sc, &sc->temp, &sc->inputsStruct, &sc->inoutID);
appendRegistersToShared(sc, &sc->sdataID, &sc->temp);
}
}
else if (type == 143) {
if (sc->readToRegisters) {
if (i < used_registers.data.i / 2) {
appendGlobalToRegisters_x(sc, &sc->regIDs[k * sc->registers_per_thread + i], &sc->inputsStruct, &sc->inoutID);
}
else {
appendGlobalToRegisters_y(sc, &sc->regIDs[k * sc->registers_per_thread + i - used_registers.data.i / 2], &sc->inputsStruct, &sc->inoutID);
}
}
else {
PfAdd(sc, &sc->combinedID, &sc->gl_LocalInvocationID_y, &temp_int);
temp_int.data.i = 2;
PfMod(sc, &sc->tempInt, &sc->combinedID, &temp_int);
appendGlobalToRegisters_x(sc, &sc->temp, &sc->inputsStruct, &sc->inoutID);
temp_int.data.i = 0;
PfIf_eq_start(sc, &sc->tempInt, &temp_int);
appendRegistersToShared_x_x(sc, &sc->sdataID, &sc->temp);
PfIf_else(sc);
appendRegistersToShared_y_x(sc, &sc->sdataID, &sc->temp);
PfIf_end(sc);
}
}
else {
if (sc->readToRegisters) {
appendGlobalToRegisters(sc, &sc->regIDs[temp_int1.data.i], &sc->inputsStruct, &sc->inoutID);
}
else {
appendGlobalToShared(sc, &sc->sdataID, &sc->inputsStruct, &sc->inoutID);
}
}
if ((sc->zeropad[readWrite]) || ((sc->numAxisUploads > 1) && (sc->zeropadBluestein[readWrite]))) {
PfIf_else(sc);
if (sc->readToRegisters) {
PfSetToZero(sc, &sc->regIDs[temp_int1.data.i]);
}
else {
PfSetToZeroShared(sc, &sc->sdataID);
}
}
}
else {
if ((type == 111) || (type == 121) || (type == 131) || (type == 145)) {
if (sc->writeFromRegisters) {
appendRegistersToGlobal_x(sc, &sc->outputsStruct, &sc->inoutID, &sc->regIDs[temp_int1.data.i]);
}
else {
appendSharedToRegisters(sc, &sc->temp, &sc->sdataID);
appendRegistersToGlobal_x(sc, &sc->outputsStruct, &sc->inoutID, &sc->temp);
}
}
else if (type == 143) {
if (sc->writeFromRegisters) {
appendRegistersToGlobal_x(sc, &sc->outputsStruct, &sc->inoutID, &sc->regIDs[k * sc->registers_per_thread + i]);
temp_int.data.i = fftDim.data.i * bufferStride[1].data.i;
PfAdd(sc, &sc->tempInt, &sc->inoutID, &temp_int);
appendRegistersToGlobal_y(sc, &sc->outputsStruct, &sc->tempInt, &sc->regIDs[k * sc->registers_per_thread + i]);
}
else {
}
}
else {
if (sc->writeFromRegisters) {
appendRegistersToGlobal(sc, &sc->outputsStruct, &sc->inoutID, &sc->regIDs[temp_int1.data.i]);
}
else {
appendSharedToGlobal(sc, &sc->outputsStruct, &sc->inoutID, &sc->sdataID);
}
}
}
if ((sc->zeropad[readWrite]) || ((sc->numAxisUploads > 1) && (sc->zeropadBluestein[readWrite]))) {
PfIf_end(sc);
}
temp_int1.data.i = (k * used_registers.data.i + i + 1) * sc->localSize[1].data.i;
if (temp_int1.data.i > fftDim.data.i) {
//&sc->tempIntLen = sprintf(&sc->tempIntStr, " }\n");
PfIf_end(sc);
}
}
}
//&sc->tempIntLen = sprintf(&sc->tempIntStr, " }\n");
if (sc->useDisableThreads) {
temp_int.data.i = 0;
PfIf_end(sc);
}
PfIf_end(sc);
return;
}
static inline void appendReadDataVkFFT(VkFFTSpecializationConstantsLayout* sc, int type) {
if (sc->res != VKFFT_SUCCESS) return;
switch (type) {
case 0: case 5: case 6: case 110: case 120: case 130: case 140: case 142: case 144:
appendReadWriteDataVkFFT_nonstrided(sc, 0, type);
break;
case 1: case 2: case 111: case 121: case 131: case 141: case 143: case 145://grouped_c2c + single_c2c_strided
appendReadWriteDataVkFFT_strided(sc, 0, type);
break;
}
return;
}
static inline void appendWriteDataVkFFT(VkFFTSpecializationConstantsLayout* sc, int type) {
if (sc->res != VKFFT_SUCCESS) return;
switch (type) {
case 0: case 5: case 6: case 110: case 120: case 130: case 140: case 142: case 144:
appendReadWriteDataVkFFT_nonstrided(sc, 1, type);
break;
case 1: case 2: case 111: case 121: case 131: case 141: case 143: case 145://grouped_c2c + single_c2c_strided
appendReadWriteDataVkFFT_strided(sc, 1, type);
break;
}
return;
}
#endif
|
a336f8cee219ac7893b5e1c074bede7c72508b1a
|
88ae8695987ada722184307301e221e1ba3cc2fa
|
/third_party/wayland-protocols/gtk/examples/application9/exampleappprefs.c
|
4bdf6542ca845be1ee0ff004d8c2bca494c4aac1
|
[
"LGPL-2.0-only",
"Apache-2.0",
"LGPL-2.1-only",
"LGPL-2.0-or-later",
"MIT",
"GPL-1.0-or-later",
"BSD-3-Clause"
] |
permissive
|
iridium-browser/iridium-browser
|
71d9c5ff76e014e6900b825f67389ab0ccd01329
|
5ee297f53dc7f8e70183031cff62f37b0f19d25f
|
refs/heads/master
| 2023-08-03T16:44:16.844552
| 2023-07-20T15:17:00
| 2023-07-23T16:09:30
| 220,016,632
| 341
| 40
|
BSD-3-Clause
| 2021-08-13T13:54:45
| 2019-11-06T14:32:31
| null |
UTF-8
|
C
| false
| false
| 1,620
|
c
|
exampleappprefs.c
|
#include <gtk/gtk.h>
#include "exampleapp.h"
#include "exampleappwin.h"
#include "exampleappprefs.h"
struct _ExampleAppPrefs
{
GtkDialog parent;
GSettings *settings;
GtkWidget *font;
GtkWidget *transition;
};
G_DEFINE_TYPE (ExampleAppPrefs, example_app_prefs, GTK_TYPE_DIALOG)
static void
example_app_prefs_init (ExampleAppPrefs *prefs)
{
gtk_widget_init_template (GTK_WIDGET (prefs));
prefs->settings = g_settings_new ("org.gtk.exampleapp");
g_settings_bind (prefs->settings, "font",
prefs->font, "font",
G_SETTINGS_BIND_DEFAULT);
g_settings_bind (prefs->settings, "transition",
prefs->transition, "active-id",
G_SETTINGS_BIND_DEFAULT);
}
static void
example_app_prefs_dispose (GObject *object)
{
ExampleAppPrefs *prefs;
prefs = EXAMPLE_APP_PREFS (object);
g_clear_object (&prefs->settings);
G_OBJECT_CLASS (example_app_prefs_parent_class)->dispose (object);
}
static void
example_app_prefs_class_init (ExampleAppPrefsClass *class)
{
G_OBJECT_CLASS (class)->dispose = example_app_prefs_dispose;
gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (class),
"/org/gtk/exampleapp/prefs.ui");
gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (class), ExampleAppPrefs, font);
gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (class), ExampleAppPrefs, transition);
}
ExampleAppPrefs *
example_app_prefs_new (ExampleAppWindow *win)
{
return g_object_new (EXAMPLE_APP_PREFS_TYPE, "transient-for", win, "use-header-bar", TRUE, NULL);
}
|
b08b8873a8ee9439c558cbfe6c6716a93b6593a3
|
7c857119fe1505b1d80d6e62969661c06dc1a2f4
|
/Trash/OsxMmcDxe/MmcBlockIo.c
|
47f4aebcdf90eb239f46f6416e183b4a87f5b2af
|
[
"BSD-2-Clause"
] |
permissive
|
CloverHackyColor/CloverBootloader
|
7042ca7dd6b513d22be591a295e49071ae1482ee
|
2711170df4f60b2ae5aa20add3e00f35cf57b7e5
|
refs/heads/master
| 2023-08-30T22:14:34.590134
| 2023-08-27T19:14:02
| 2023-08-27T19:14:02
| 205,810,121
| 4,734
| 770
|
BSD-2-Clause
| 2023-09-03T12:41:33
| 2019-09-02T08:22:14
|
C
|
UTF-8
|
C
| false
| false
| 22,840
|
c
|
MmcBlockIo.c
|
/** @file
*
* Copyright (c) 2011, ARM Limited. All rights reserved.
*
* This program and the accompanying materials
* are licensed and made available under the terms and conditions of the BSD License
* which accompanies this distribution. The full text of the license may be found at
* http://opensource.org/licenses/bsd-license.php
*
* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
*
**/
#include <Protocol/MmcHost.h>
#include <Library/DebugLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/TimerLib.h>
#include "Mmc.h"
// Untested ...
//#define USE_STREAM
#define MAX_RETRY_COUNT 1000
#define CMD_RETRY_COUNT 20
EFI_STATUS
MmcNotifyState (
IN MMC_HOST_INSTANCE *MmcHostInstance,
IN MMC_STATE State
)
{
MmcHostInstance->State = State;
return MmcHostInstance->MmcHost->NotifyState (MmcHostInstance->MmcHost, State);
}
VOID
PrintOCR (
IN UINT32 Ocr
)
{
UINTN minv, maxv, volts;
UINTN loop;
minv = 36; // 3.6
maxv = 20; // 2.0
volts = 20; // 2.0
// The MMC register bits [23:8] indicate the working range of the card
for (loop = 8; loop < 24; loop++) {
if (Ocr & (1 << loop)) {
if (minv > volts) minv = volts;
if (maxv < volts) maxv = volts + 1;
}
volts = volts + 1;
}
DEBUG((EFI_D_ERROR, "- PrintOCR Ocr (0x%X)\n",Ocr));
DEBUG((EFI_D_ERROR, "\t- Card operating voltage: %d.%d to %d.%d\n", minv/10, minv % 10, maxv/10, maxv % 10));
if (((Ocr >> 29) & 3) == 0) {
DEBUG((EFI_D_ERROR, "\t- AccessMode: Byte Mode\n"));
} else {
DEBUG((EFI_D_ERROR, "\t- AccessMode: Block Mode (0x%X)\n",((Ocr >> 29) & 3)));
}
if (Ocr & MMC_OCR_POWERUP) {
DEBUG((EFI_D_ERROR, "\t- PowerUp\n"));
} else {
DEBUG((EFI_D_ERROR, "\t- Voltage Not Supported\n"));
}
}
VOID PrintCID (
IN UINT32* Cid
)
{
DEBUG((EFI_D_ERROR, "- PrintCID\n"));
DEBUG((EFI_D_ERROR, "\t- Manufacturing date: %d/%d\n",(Cid[0] >> 8) & 0xF,(Cid[0] >> 12) & 0xFF));
DEBUG((EFI_D_ERROR, "\t- Product serial number: 0x%X%X\n",Cid[1] & 0xFFFFFF,(Cid[0] >> 24) & 0xFF));
DEBUG((EFI_D_ERROR, "\t- Product revision: %d\n",Cid[1] >> 24));
//DEBUG((EFI_D_ERROR, "\t- Product name: %s\n",(char*)(Cid + 2)));
DEBUG((EFI_D_ERROR, "\t- OEM ID: %c%c\n",(Cid[3] >> 8) & 0xFF,(Cid[3] >> 16) & 0xFF));
}
VOID
PrintCSD (
IN UINT32* Csd
)
{
UINTN Value;
#if !defined(MDEPKG_NDEBUG)
CONST CHAR8* str_unit[] = { "100kbit/s","1Mbit/s","10Mbit/s","100MBit/s","Unkbown","Unkbown","Unkbown","Unkbown" };
CONST CHAR8* str_value[] = { "1.0","1.2","1.3","1.5","2.0","2.5","3.0","3.5","4.0","4.5","5.0","Unknown","Unknown","Unknown","Unknown" };
#endif
if (((Csd[2] >> 30) & 0x3) == 0) {
DEBUG((EFI_D_ERROR, "- PrintCSD Version 1.01-1.10/Version 2.00/Standard Capacity\n"));
} else if (((Csd[2] >> 30) & 0x3) == 1) {
DEBUG((EFI_D_ERROR, "- PrintCSD Version 2.00/High Capacity\n"));
} else {
DEBUG((EFI_D_ERROR, "- PrintCSD Version Higher than v3.3\n"));
}
DEBUG((EFI_D_ERROR, "\t- Supported card command class: 0x%X\n",MMC_CSD_GET_CCC(Csd)));
DEBUG((EFI_D_ERROR, "\t- Speed: %a %a\n",str_value[(MMC_CSD_GET_TRANSPEED(Csd) >> 3) & 0xF],str_unit[MMC_CSD_GET_TRANSPEED(Csd) & 7]));
DEBUG((EFI_D_ERROR, "\t- Maximum Read Data Block: %d\n",2 << (MMC_CSD_GET_READBLLEN(Csd)-1)));
DEBUG((EFI_D_ERROR, "\t- Maximum Write Data Block: %d\n",2 << (MMC_CSD_GET_WRITEBLLEN(Csd)-1)));
if (!MMC_CSD_GET_FILEFORMATGRP(Csd)) {
Value = MMC_CSD_GET_FILEFORMAT(Csd);
if (Value == 0) DEBUG((EFI_D_ERROR, "\t- Format(0): Hard disk-like file system with partition table\n"));
else if (Value == 1) DEBUG((EFI_D_ERROR, "\t- Format(1): DOS FAT (floppy-like) with boot sector only (no partition table)\n"));
else if (Value == 2) DEBUG((EFI_D_ERROR, "\t- Format(2): Universal File Format\n"));
else DEBUG((EFI_D_ERROR, "\t- Format(3): Others/Unknown\n"));
} else {
DEBUG((EFI_D_ERROR, "\t- Format: Reserved\n"));
}
}
VOID
PrintRCA (
IN UINT32 Rca
)
{
DEBUG((EFI_D_ERROR, "- PrintRCA: 0x%X\n",Rca));
DEBUG((EFI_D_ERROR, "\t- Status: 0x%X\n",Rca & 0xFFFF));
DEBUG((EFI_D_ERROR, "\t- RCA: 0x%X\n",(Rca >> 16) & 0xFFFF));
}
VOID
PrintResponseR1 (
IN UINT32 Response
)
{
DEBUG((EFI_D_INFO, "Response: 0x%X\n",Response));
if (Response & (1 << 8)) DEBUG((EFI_D_INFO, "\t- READY_FOR_DATA\n"));
if (((Response >> 9) & 0xF) == 0) DEBUG((EFI_D_INFO, "\t- State: Idle\n"));
else if (((Response >> 9) & 0xF) == 1) DEBUG((EFI_D_INFO, "\t- State: Ready\n"));
else if (((Response >> 9) & 0xF) == 2) DEBUG((EFI_D_INFO, "\t- State: Ident\n"));
else if (((Response >> 9) & 0xF) == 3) DEBUG((EFI_D_INFO, "\t- State: StandBy\n"));
else if (((Response >> 9) & 0xF) == 4) DEBUG((EFI_D_INFO, "\t- State: Tran\n"));
else if (((Response >> 9) & 0xF) == 5) DEBUG((EFI_D_INFO, "\t- State: Data\n"));
else if (((Response >> 9) & 0xF) == 6) DEBUG((EFI_D_INFO, "\t- State: Rcv\n"));
else if (((Response >> 9) & 0xF) == 7) DEBUG((EFI_D_INFO, "\t- State: Prg\n"));
else if (((Response >> 9) & 0xF) == 8) DEBUG((EFI_D_INFO, "\t- State: Dis\n"));
else DEBUG((EFI_D_INFO, "\t- State: Reserved\n"));
}
EFI_STATUS
EFIAPI
MmcGetCardStatus(
IN MMC_HOST_INSTANCE *MmcHostInstance
)
{
EFI_STATUS Status;
UINT32 Response[4];
UINTN CmdArg;
EFI_MMC_HOST_PROTOCOL *MmcHost;
Status = EFI_SUCCESS;
MmcHost = MmcHostInstance->MmcHost;
CmdArg = 0;
if (MmcHost == NULL) {
return EFI_INVALID_PARAMETER;
}
if(MmcHostInstance->State != MmcHwInitializationState){
//Get the Status of the card.
CmdArg = MmcHostInstance->CardInfo.RCA << 16;
Status = MmcHost->SendCommand (MmcHost, MMC_CMD13, CmdArg);
if (EFI_ERROR(Status)) {
DEBUG((EFI_D_ERROR, "MmcGetCardStatus(MMC_CMD13): Error and Status = %r\n", Status));
return Status;
}
//Read Response
MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_R1,Response);
PrintResponseR1(Response[0]);
}
return Status;
}
EFI_STATUS
EFIAPI
MmcIdentificationMode (
IN MMC_HOST_INSTANCE *MmcHostInstance
)
{
EFI_STATUS Status;
UINT32 Response[4];
UINTN Timeout;
UINTN CmdArg;
BOOLEAN IsHCS;
EFI_MMC_HOST_PROTOCOL *MmcHost;
MmcHost = MmcHostInstance->MmcHost;
CmdArg = 0;
IsHCS = FALSE;
if (MmcHost == NULL) {
return EFI_INVALID_PARAMETER;
}
// We can get into this function if we restart the identification mode
if (MmcHostInstance->State == MmcHwInitializationState) {
// Initialize the MMC Host HW
Status = MmcNotifyState (MmcHostInstance, MmcHwInitializationState);
if (EFI_ERROR(Status)) {
DEBUG((EFI_D_ERROR, "MmcIdentificationMode() : Error MmcHwInitializationState\n"));
return Status;
}
} else {
//Note: Could even be used in all cases. But it looks this command could put the state machine into inactive for some cards
Status = MmcHost->SendCommand (MmcHost, MMC_CMD0, 0);
if (EFI_ERROR(Status)) {
DEBUG((EFI_D_ERROR, "MmcIdentificationMode(MMC_CMD0): Error\n"));
return Status;
}
}
Status = MmcNotifyState (MmcHostInstance, MmcIdleState);
if (EFI_ERROR(Status)) {
DEBUG((EFI_D_ERROR, "MmcIdentificationMode() : Error MmcIdleState\n"));
return Status;
}
// Are we using SDIO ?
Status = MmcHost->SendCommand (MmcHost, MMC_CMD5, 0);
if (Status == EFI_SUCCESS) {
DEBUG((EFI_D_ERROR, "MmcIdentificationMode(MMC_CMD5): Error - SDIO not supported.\n"));
return EFI_UNSUPPORTED;
}
// Check which kind of card we are using. Ver2.00 or later SD Memory Card (PL180 is SD v1.1)
CmdArg = (0x0UL << 12 | BIT8 | 0xCEUL << 0);
Status = MmcHost->SendCommand (MmcHost, MMC_CMD8, CmdArg);
if (Status == EFI_SUCCESS) {
DEBUG ((EFI_D_ERROR, "Card is SD2.0 => Supports high capacity\n"));
IsHCS = TRUE;
MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_R7,Response);
PrintResponseR1(Response[0]);
//check if it is valid response
if(Response[0] != CmdArg){
DEBUG ((EFI_D_ERROR, "The Card is not usable\n"));
return EFI_UNSUPPORTED;
}
} else {
DEBUG ((EFI_D_ERROR, "Not a SD2.0 Card\n"));
}
// We need to wait for the MMC or SD card is ready => (gCardInfo.OCRData.Busy == 1)
Timeout = MAX_RETRY_COUNT;
while (Timeout > 0) {
// SD Card or MMC Card ? CMD55 indicates to the card that the next command is an application specific command
Status = MmcHost->SendCommand (MmcHost, MMC_CMD55, 0);
if (Status == EFI_SUCCESS) {
DEBUG ((EFI_D_INFO, "Card should be SD\n"));
if (IsHCS) {
MmcHostInstance->CardInfo.CardType = SD_CARD_2;
} else {
MmcHostInstance->CardInfo.CardType = SD_CARD;
}
// Note: The first time CmdArg will be zero
CmdArg = ((UINTN *) &(MmcHostInstance->CardInfo.OCRData))[0];
if (IsHCS) {
CmdArg |= BIT30;
}
Status = MmcHost->SendCommand (MmcHost, MMC_ACMD41, CmdArg);
if (!EFI_ERROR(Status)) {
MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_OCR,Response);
((UINT32 *) &(MmcHostInstance->CardInfo.OCRData))[0] = Response[0];
}
} else {
DEBUG ((EFI_D_INFO, "Card should be MMC\n"));
MmcHostInstance->CardInfo.CardType = MMC_CARD;
Status = MmcHost->SendCommand (MmcHost, MMC_CMD1, 0x800000);
if (!EFI_ERROR(Status)) {
MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_OCR,Response);
((UINT32 *) &(MmcHostInstance->CardInfo.OCRData))[0] = Response[0];
}
}
if (!EFI_ERROR(Status)) {
if (MmcHostInstance->CardInfo.OCRData.Busy == 0) {
MicroSecondDelay(1);
Timeout--;
} else {
if ((MmcHostInstance->CardInfo.CardType == SD_CARD_2) && (MmcHostInstance->CardInfo.OCRData.AccessMode & BIT1)) {
MmcHostInstance->CardInfo.CardType = SD_CARD_2_HIGH;
DEBUG ((EFI_D_ERROR, "High capacity card.\n"));
}
break; // The MMC/SD card is ready. Continue the Identification Mode
}
} else {
MicroSecondDelay(1);
Timeout--;
}
}
if (Timeout == 0) {
DEBUG((EFI_D_ERROR, "MmcIdentificationMode(): No Card\n"));
return EFI_NO_MEDIA;
} else {
PrintOCR(Response[0]);
}
Status = MmcNotifyState (MmcHostInstance, MmcReadyState);
if (EFI_ERROR(Status)) {
DEBUG((EFI_D_ERROR, "MmcIdentificationMode() : Error MmcReadyState\n"));
return Status;
}
Status = MmcHost->SendCommand (MmcHost, MMC_CMD2, 0);
if (EFI_ERROR(Status)) {
DEBUG((EFI_D_ERROR, "MmcIdentificationMode(MMC_CMD2): Error\n"));
return Status;
}
MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_CID,Response);
PrintCID(Response);
Status = MmcNotifyState (MmcHostInstance, MmcIdentificationState);
if (EFI_ERROR(Status)) {
DEBUG((EFI_D_ERROR, "MmcIdentificationMode() : Error MmcIdentificationState\n"));
return Status;
}
//
// Note, SD specifications say that "if the command execution causes a state change, it
// will be visible to the host in the response to the next command"
// The status returned for this CMD3 will be 2 - identification
//
CmdArg = 1;
Status = MmcHost->SendCommand (MmcHost, MMC_CMD3, CmdArg);
if (EFI_ERROR(Status)) {
DEBUG((EFI_D_ERROR, "MmcIdentificationMode(MMC_CMD3): Error\n"));
return Status;
}
MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_RCA,Response);
PrintRCA(Response[0]);
// For MMC card, RCA is assigned by CMD3 while CMD3 dumps the RCA for SD card
if (MmcHostInstance->CardInfo.CardType != MMC_CARD) {
MmcHostInstance->CardInfo.RCA = Response[0] >> 16;
} else {
MmcHostInstance->CardInfo.RCA = CmdArg;
}
Status = MmcNotifyState (MmcHostInstance, MmcStandByState);
if (EFI_ERROR(Status)) {
DEBUG((EFI_D_ERROR, "MmcIdentificationMode() : Error MmcStandByState\n"));
return Status;
}
return EFI_SUCCESS;
}
EFI_STATUS InitializeMmcDevice (
IN MMC_HOST_INSTANCE *MmcHostInstance
)
{
UINT32 Response[4];
EFI_STATUS Status;
UINTN CardSize, NumBlocks, BlockSize, CmdArg;
EFI_MMC_HOST_PROTOCOL *MmcHost;
UINTN BlockCount = 1;
MmcHost = MmcHostInstance->MmcHost;
MmcIdentificationMode (MmcHostInstance);
//Send a command to get Card specific data
CmdArg = MmcHostInstance->CardInfo.RCA << 16;
Status = MmcHost->SendCommand (MmcHost, MMC_CMD9, CmdArg);
if (EFI_ERROR(Status)) {
DEBUG((EFI_D_ERROR, "MmcIdentificationMode(MMC_CMD9): Error, Status=%r\n", Status));
return Status;
}
//Read Response
MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_CSD,Response);
PrintCSD(Response);
if (MmcHostInstance->CardInfo.CardType == SD_CARD_2_HIGH) {
CardSize = HC_MMC_CSD_GET_DEVICESIZE(Response);
NumBlocks = ((CardSize + 1) * 1024);
BlockSize = 1 << MMC_CSD_GET_READBLLEN(Response);
} else {
CardSize = MMC_CSD_GET_DEVICESIZE(Response);
NumBlocks = (CardSize + 1) * (1 << (MMC_CSD_GET_DEVICESIZEMULT(Response) + 2));
BlockSize = 1 << MMC_CSD_GET_READBLLEN(Response);
}
//For >=2G card, BlockSize may be 1K, but the transfer size is 512 bytes.
if (BlockSize > 512) {
NumBlocks = MultU64x32(NumBlocks, BlockSize/512);
BlockSize = 512;
}
MmcHostInstance->BlockIo.Media->LastBlock = (NumBlocks - 1);
MmcHostInstance->BlockIo.Media->BlockSize = BlockSize;
MmcHostInstance->BlockIo.Media->ReadOnly = MmcHost->IsReadOnly (MmcHost);
MmcHostInstance->BlockIo.Media->MediaPresent = TRUE;
MmcHostInstance->BlockIo.Media->MediaId++;
CmdArg = MmcHostInstance->CardInfo.RCA << 16;
Status = MmcHost->SendCommand (MmcHost, MMC_CMD7, CmdArg);
if (EFI_ERROR(Status)) {
DEBUG((EFI_D_ERROR, "MmcIdentificationMode(MMC_CMD7): Error and Status = %r\n", Status));
return Status;
}
Status = MmcNotifyState (MmcHostInstance, MmcTransferState);
if (EFI_ERROR(Status)) {
DEBUG((EFI_D_ERROR, "MmcIdentificationMode() : Error MmcTransferState\n"));
return Status;
}
// Set Block Length
Status = MmcHost->SendCommand (MmcHost, MMC_CMD16, MmcHostInstance->BlockIo.Media->BlockSize);
if (EFI_ERROR(Status)) {
DEBUG((EFI_D_ERROR, "MmcIdentificationMode(MMC_CMD16): Error MmcHostInstance->BlockIo.Media->BlockSize: %d and Error = %r\n",MmcHostInstance->BlockIo.Media->BlockSize, Status));
return Status;
}
// Block Count (not used). Could return an error for SD card
if (MmcHostInstance->CardInfo.CardType == MMC_CARD) {
MmcHost->SendCommand (MmcHost, MMC_CMD23, BlockCount);
}
return EFI_SUCCESS;
}
EFI_STATUS
EFIAPI
MmcReset (
IN EFI_BLOCK_IO_PROTOCOL *This,
IN BOOLEAN ExtendedVerification
)
{
MMC_HOST_INSTANCE *MmcHostInstance;
MmcHostInstance = MMC_HOST_INSTANCE_FROM_BLOCK_IO_THIS(This);
if (MmcHostInstance->MmcHost == NULL) {
// Nothing to do
return EFI_SUCCESS;
}
// If a card is not present then clear all media settings
if (!MmcHostInstance->MmcHost->IsCardPresent (MmcHostInstance->MmcHost)) {
MmcHostInstance->BlockIo.Media->MediaPresent = FALSE;
MmcHostInstance->BlockIo.Media->LastBlock = 0;
MmcHostInstance->BlockIo.Media->BlockSize = 512; // Should be zero but there is a bug in DiskIo
MmcHostInstance->BlockIo.Media->ReadOnly = FALSE;
// Indicate that the driver requires initialization
MmcHostInstance->State = MmcHwInitializationState;
return EFI_SUCCESS;
}
// Implement me. Either send a CMD0 (could not work for some MMC host) or just turn off/turn
// on power and restart Identification mode
return EFI_SUCCESS;
}
EFI_STATUS
MmcDetectCard (
EFI_MMC_HOST_PROTOCOL *MmcHost
)
{
if (!MmcHost->IsCardPresent (MmcHost)) {
return EFI_NO_MEDIA;
} else {
return EFI_SUCCESS;
}
}
#define MMCI0_BLOCKLEN 512
#define MMCI0_TIMEOUT 10000
EFI_STATUS
MmcIoBlocks (
IN EFI_BLOCK_IO_PROTOCOL *This,
IN UINTN Transfer,
IN UINT32 MediaId,
IN EFI_LBA Lba,
IN UINTN BufferSize,
OUT VOID *Buffer
)
{
UINT32 Response[4];
EFI_STATUS Status;
UINTN CmdArg;
INTN Timeout;
UINTN Cmd;
MMC_HOST_INSTANCE *MmcHostInstance;
EFI_MMC_HOST_PROTOCOL *MmcHost;
UINTN BytesRemainingToBeTransfered;
UINTN BlockCount = 1;
MmcHostInstance = MMC_HOST_INSTANCE_FROM_BLOCK_IO_THIS(This);
ASSERT(MmcHostInstance != 0);
MmcHost = MmcHostInstance->MmcHost;
ASSERT(MmcHost);
if ((MmcHost == 0)|| (Buffer == NULL)) {
return EFI_INVALID_PARAMETER;
}
// Check if a Card is Present
if (!MmcHostInstance->BlockIo.Media->MediaPresent) {
return EFI_NO_MEDIA;
}
// All blocks must be within the device
if ((Lba + (BufferSize / This->Media->BlockSize)) > (This->Media->LastBlock + 1)){
return EFI_INVALID_PARAMETER;
}
// The buffer size must not be zero and it must be an exact multiple of the block size
if ((BufferSize == 0) || ((BufferSize % This->Media->BlockSize) != 0)) {
return EFI_BAD_BUFFER_SIZE;
}
if (This->Media->MediaId != MediaId) {
return EFI_MEDIA_CHANGED;
}
if((Transfer == MMC_IOBLOCKS_WRITE) && (This->Media->ReadOnly == TRUE)) {
return EFI_WRITE_PROTECTED;
}
BytesRemainingToBeTransfered = BufferSize;
while (BytesRemainingToBeTransfered > 0) {
// Check if the Card is in Ready status
CmdArg = MmcHostInstance->CardInfo.RCA << 16;
Response[0] = 0;
Timeout = 20;
while(!(Response[0] & MMC_R0_READY_FOR_DATA) && (MMC_R0_CURRENTSTATE(Response) != MMC_R0_STATE_TRAN) && Timeout--) {
Status = MmcHost->SendCommand (MmcHost, MMC_CMD13, CmdArg);
if (!EFI_ERROR(Status)) {
MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_R1,Response);
}
}
if (0 == Timeout) {
DEBUG((EFI_D_ERROR, "The Card is busy\n"));
return EFI_NOT_READY;
}
//Set command argument based on the card access mode (Byte mode or Block mode)
if (MmcHostInstance->CardInfo.OCRData.AccessMode & BIT1) {
CmdArg = Lba;
} else {
CmdArg = Lba * This->Media->BlockSize;
}
if (Transfer == MMC_IOBLOCKS_READ) {
#ifndef USE_STREAM
// Read a single block
Cmd = MMC_CMD17;
#else
//TODO: Should we support read stream (MMC_CMD11)
#endif
} else {
#ifndef USE_STREAM
// Write a single block
Cmd = MMC_CMD24;
#else
//TODO: Should we support write stream (MMC_CMD20)
#endif
}
Status = MmcHost->SendCommand (MmcHost, Cmd, CmdArg);
if (EFI_ERROR(Status)) {
DEBUG((EFI_D_ERROR, "MmcIdentificationMode(MMC_CMD%d): Error %r\n",Cmd, Status));
return Status;
}
if (Transfer == MMC_IOBLOCKS_READ) {
#ifndef USE_STREAM
// Read one block of Data
Status = MmcHost->ReadBlockData (MmcHost, Lba,This->Media->BlockSize,Buffer);
if (EFI_ERROR(Status)) {
DEBUG((EFI_D_BLKIO, "MmcIdentificationMode(): Error Read Block Data and Status = %r\n", Status));
return Status;
}
#else
//TODO: Read a steam
ASSERT(0);
#endif
Status = MmcNotifyState (MmcHostInstance, MmcProgrammingState);
if (EFI_ERROR(Status)) {
DEBUG((EFI_D_ERROR, "MmcIdentificationMode() : Error MmcProgrammingState\n"));
return Status;
}
} else {
#ifndef USE_STREAM
// Write one block of Data
Status = MmcHost->WriteBlockData (MmcHost, Lba,This->Media->BlockSize,Buffer);
if (EFI_ERROR(Status)) {
DEBUG((EFI_D_BLKIO, "MmcIdentificationMode(): Error Write Block Data and Status = %r\n", Status));
return Status;
}
#else
//TODO: Write a steam
ASSERT(0);
#endif
}
// Command 12 - Stop transmission (ends read)
Status = MmcHost->SendCommand (MmcHost, MMC_CMD12, 0);
if (!EFI_ERROR(Status)) {
MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_R1b,Response);
}
// Command 13 - Read status and wait for programming to complete (return to tran)
Timeout = MMCI0_TIMEOUT;
CmdArg = MmcHostInstance->CardInfo.RCA << 16;
Response[0] = 0;
while(!(Response[0] & MMC_R0_READY_FOR_DATA) && (MMC_R0_CURRENTSTATE(Response) != MMC_R0_STATE_TRAN) && Timeout--) {
Status = MmcHost->SendCommand (MmcHost, MMC_CMD13, CmdArg);
if (!EFI_ERROR(Status)) {
MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_R1,Response);
}
NanoSecondDelay(100);
Timeout--;
}
Status = MmcNotifyState (MmcHostInstance, MmcTransferState);
if (EFI_ERROR(Status)) {
DEBUG((EFI_D_ERROR, "MmcIdentificationMode() : Error MmcTransferState\n"));
return Status;
}
BytesRemainingToBeTransfered -= This->Media->BlockSize;
Lba += BlockCount;
Buffer = (UINT8 *)Buffer + This->Media->BlockSize;
}
return EFI_SUCCESS;
}
EFI_STATUS
EFIAPI
MmcReadBlocks (
IN EFI_BLOCK_IO_PROTOCOL *This,
IN UINT32 MediaId,
IN EFI_LBA Lba,
IN UINTN BufferSize,
OUT VOID *Buffer
)
{
return MmcIoBlocks (This, MMC_IOBLOCKS_READ, MediaId, Lba, BufferSize, Buffer);
}
EFI_STATUS
EFIAPI
MmcWriteBlocks (
IN EFI_BLOCK_IO_PROTOCOL *This,
IN UINT32 MediaId,
IN EFI_LBA Lba,
IN UINTN BufferSize,
IN VOID *Buffer
)
{
return MmcIoBlocks (This, MMC_IOBLOCKS_WRITE, MediaId, Lba, BufferSize, Buffer);
}
EFI_STATUS
EFIAPI
MmcFlushBlocks (
IN EFI_BLOCK_IO_PROTOCOL *This
)
{
return EFI_SUCCESS;
}
|
b813722a68d82b5d0279e3934bf12021cffb234f
|
62bf09400de89c1aa77d8c2570d7f66cec0b5d36
|
/third_party/qca-3.3.5/port/drivers/dspi_edma_freertos/wifi_spi.c
|
eb0448f1e9efffaf6d6415f2ed381a8101b37ad5
|
[
"Apache-2.0"
] |
permissive
|
butok/FNET
|
41b1d2ec4cc683c1b5c188a17ab6a4bb890a6af6
|
ea43715752e6f6823bfcc8bdc94e440443112e7c
|
refs/heads/master
| 2023-08-03T16:32:09.317085
| 2023-07-20T07:01:55
| 2023-07-20T07:01:55
| 50,664,554
| 115
| 40
|
Apache-2.0
| 2023-07-20T07:01:56
| 2016-01-29T13:39:30
|
C
|
UTF-8
|
C
| false
| false
| 12,505
|
c
|
wifi_spi.c
|
/*
* Copyright (c) 2016, NXP Semiconductor, Inc.
* All rights reserved.
*
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include "wifi_common.h"
#include "athdefs.h"
#include "fsl_dspi.h"
#include "fsl_dmamux.h"
#include "fsl_edma.h"
#include "fsl_dspi_edma.h"
#include "wifi_spi.h"
static dspi_master_edma_handle_t g_dspi_edma_m_handle;
static edma_handle_t dspiEdmaMasterRxRegToRxDataHandle;
static edma_handle_t dspiEdmaMasterTxDataToIntermediaryHandle;
static edma_handle_t dspiEdmaMasterIntermediaryToTxRegHandle;
static dspi_master_handle_t g_m_handle;
static SemaphoreHandle_t mutex;
static SemaphoreHandle_t event;
static int32_t g_dma_chunk = 500;
static enum IRQn g_dma_irqs[][FSL_FEATURE_EDMA_MODULE_CHANNEL] = DMA_CHN_IRQS;
static enum IRQn g_spi_irqs[] = SPI_IRQS;
static dspi_master_config_t g_spi_config;
static SPI_Type *g_spi_base = NULL;
static uint32_t g_xfer_cs = 0;
static uint32_t g_irq_threshold = 0;
extern uint32_t DSPI_GetInstance(SPI_Type *base);
/* taken from fsl_edma.c */
static DMA_Type *const s_edmaBases[] = DMA_BASE_PTRS;
static uint32_t EDMA_GetInstance(DMA_Type *base)
{
uint32_t instance;
/* Find the instance index from base address mappings. */
for (instance = 0; instance < ARRAY_SIZE(s_edmaBases); instance++)
{
if (s_edmaBases[instance] == base)
{
break;
}
}
assert(instance < ARRAY_SIZE(s_edmaBases));
return instance;
}
/*
* DMA handler, release transfer semaphore
*/
static void DSPI_DMA_MasterUserCallback(SPI_Type *base, dspi_master_edma_handle_t *handle, status_t status, void *userData)
{
/* disable DMA requests before invoke callback */
BaseType_t reschedule = pdFALSE;
xSemaphoreGiveFromISR(event, &reschedule);
portYIELD_FROM_ISR(reschedule);
}
/*
* IRQ handler, release transfer semaphore
*/
static void DSPI_MasterUserCallback(SPI_Type *base, dspi_master_handle_t *handle, status_t status, void *userData)
{
/* disable IRQ requests before invoke callback */
BaseType_t reschedule = pdFALSE;
xSemaphoreGiveFromISR(event, &reschedule);
portYIELD_FROM_ISR(reschedule);
}
/*
* Initialize SPI IRQ mode
*/
static A_STATUS WIFIDRVS_SPI_InitIRQMode(WIFIDRVS_SPI_config_t *config)
{
uint32_t spi_id = DSPI_GetInstance(config->spi.base);
NVIC_SetPriority(g_spi_irqs[spi_id], config->irq_mode.spi_irq_prio);
/* DSPI IRQ non-blocking handle */
DSPI_MasterTransferCreateHandle(config->spi.base, &g_m_handle, DSPI_MasterUserCallback, NULL);
return A_OK;
}
/*
* Initialize SPI DMA mode
*/
static A_STATUS WIFIDRVS_SPI_InitDMAMode(WIFIDRVS_SPI_config_t *config)
{
DMAMUX_Init(config->dma_mode.dmamux_base);
if ((config->dma_mode.dma_rx_chnl >= 0) && (config->dma_mode.dmamux_rx_req))
{
DMAMUX_SetSource(config->dma_mode.dmamux_base, config->dma_mode.dma_rx_chnl, config->dma_mode.dmamux_rx_req);
DMAMUX_EnableChannel(config->dma_mode.dmamux_base, config->dma_mode.dma_rx_chnl);
}
if ((config->dma_mode.dma_tx_chnl >= 0) && (config->dma_mode.dmamux_tx_req))
{
DMAMUX_SetSource(config->dma_mode.dmamux_base, config->dma_mode.dma_tx_chnl, config->dma_mode.dmamux_tx_req);
DMAMUX_EnableChannel(config->dma_mode.dmamux_base, config->dma_mode.dma_tx_chnl);
}
/* Init DMA */
edma_config_t edma_config = {0};
EDMA_GetDefaultConfig(&edma_config);
EDMA_Init(config->dma_mode.dma_base, &edma_config);
/* Setup DMA/SPI handles */
memset(&dspiEdmaMasterRxRegToRxDataHandle, 0, sizeof(dspiEdmaMasterRxRegToRxDataHandle));
memset(&dspiEdmaMasterTxDataToIntermediaryHandle, 0, sizeof(dspiEdmaMasterTxDataToIntermediaryHandle));
memset(&dspiEdmaMasterIntermediaryToTxRegHandle, 0, sizeof(dspiEdmaMasterIntermediaryToTxRegHandle));
EDMA_CreateHandle(&dspiEdmaMasterRxRegToRxDataHandle, config->dma_mode.dma_base, config->dma_mode.dma_rx_chnl);
EDMA_CreateHandle(&dspiEdmaMasterTxDataToIntermediaryHandle, config->dma_mode.dma_base, config->dma_mode.dma_im_chnl);
EDMA_CreateHandle(&dspiEdmaMasterIntermediaryToTxRegHandle, config->dma_mode.dma_base, config->dma_mode.dma_tx_chnl);
DSPI_MasterTransferCreateHandleEDMA(config->spi.base, &g_dspi_edma_m_handle, DSPI_DMA_MasterUserCallback, NULL,
&dspiEdmaMasterRxRegToRxDataHandle, &dspiEdmaMasterTxDataToIntermediaryHandle,
&dspiEdmaMasterIntermediaryToTxRegHandle);
/* Set up chnl priorities */
uint32_t edma_id = EDMA_GetInstance(config->dma_mode.dma_base);
if (config->dma_mode.dma_rx_chnl >= 0)
{
NVIC_SetPriority(g_dma_irqs[edma_id][config->dma_mode.dma_rx_chnl], config->dma_mode.dma_irq_prio);
}
if (config->dma_mode.dma_im_chnl >= 0)
{
NVIC_SetPriority(g_dma_irqs[edma_id][config->dma_mode.dma_im_chnl], config->dma_mode.dma_irq_prio);
}
if (config->dma_mode.dma_tx_chnl >= 0)
{
NVIC_SetPriority(g_dma_irqs[edma_id][config->dma_mode.dma_tx_chnl], config->dma_mode.dma_irq_prio);
}
return A_OK;
}
/*
* Initialize SPI peripheral
*/
static A_STATUS WIFIDRVS_SPI_InitPeriph(
SPI_Type *base,
uint32_t src_clk_hz,
uint32_t xfer_cs,
dspi_master_config_t *user_config
)
{
assert(NULL != base);
assert(NULL != user_config);
mutex = xSemaphoreCreateMutex();
assert(NULL != mutex);
event = xSemaphoreCreateBinary();
assert(NULL != event);
/* DSPI init */
DSPI_MasterInit(base, &g_spi_config, src_clk_hz);
return A_OK;
}
/*
* Transfer data in DMA mode
*/
static A_STATUS WIFIDRVS_SPI_DMA_Transfer(dspi_transfer_t *transfer)
{
assert(NULL != transfer);
status_t result = DSPI_MasterTransferEDMA(g_spi_base, &g_dspi_edma_m_handle, transfer);
if (kStatus_Success != result)
{
assert(0);
return A_ERROR;
}
/* semaphore is released in callback fn */
if (pdTRUE != xSemaphoreTake(event, portMAX_DELAY))
{
assert(0);
return A_ERROR;
}
return A_OK;
}
/*
* Transfer data in IRQ mode
*/
static A_STATUS WIFIDRVS_SPI_IRQ_Transfer(dspi_transfer_t *transfer)
{
assert(NULL != transfer);
status_t result = DSPI_MasterTransferNonBlocking(g_spi_base, &g_m_handle, transfer);
if (kStatus_Success != result)
{
assert(0);
return A_ERROR;
}
if (pdTRUE != xSemaphoreTake(event, portMAX_DELAY))
{
assert(0);
result = A_ERROR;
}
return A_OK;
}
/*
* Transfer data
*/
static A_STATUS WIFIDRVS_SPI_Transfer(dspi_transfer_t *transfer)
{
A_STATUS result = A_OK;
/* NOTE: following code expects that SDK drivers do not
* modify members of 'transfer' argument */
for (int32_t to_transfer = transfer->dataSize; to_transfer;)
{
if (to_transfer < g_irq_threshold)
{
/* DMA is unefficient for small amount of data, so use IRQ mode.
* IRQ mode can transfer unlimited number of data */
transfer->dataSize = to_transfer;
result = WIFIDRVS_SPI_IRQ_Transfer(transfer);
if (A_OK != result)
break;
to_transfer = 0;
}
else
{
/* DSPI over EDMA can transfer only limited number of bytes
* so we have to split transfer into chunks */
transfer->dataSize = to_transfer < g_dma_chunk ? to_transfer : g_dma_chunk;
result = WIFIDRVS_SPI_DMA_Transfer(transfer);
if (A_OK != result)
break;
to_transfer -= transfer->dataSize;
/* recalculate rx/rx offsets */
if (NULL != transfer->txData)
{
transfer->txData += transfer->dataSize;
}
if (NULL != transfer->rxData)
{
transfer->rxData += transfer->dataSize;
}
}
}
return result;
}
/*!
* @brief Initialize SPI driver
*/
A_STATUS WIFIDRVS_SPI_Init(WIFIDRVS_SPI_config_t *config)
{
/* No SPI base address, invalid config*/
assert(!((NULL == config) || (NULL == config->spi.base)));
if ((NULL == config) || (NULL == config->spi.base)) return A_ERROR;
/* IRQ mode only - set threshold to max value */
if ((config->irq_mode.enabled) && (!config->dma_mode.enabled))
{
g_irq_threshold = (uint32_t)-1;
}
/* DMA mode only - set threshold to 0 */
else if ((!config->irq_mode.enabled) && (config->dma_mode.enabled))
{
g_irq_threshold = 0;
}
/* DMA and IRQ mode - set user defined value */
else if ((config->irq_mode.enabled) && (config->dma_mode.enabled))
{
g_irq_threshold = config->spi.irq_threshold;
}
/* Neither of modes is enabled, return error */
else
{
return A_ERROR;
}
/* Prepare driver internal context */
g_spi_base = config->spi.base;
g_xfer_cs = config->spi.xfer_cs;
g_spi_config = config->spi.config;
/* Initialize SPI peripheral */
WIFIDRVS_SPI_InitPeriph(config->spi.base, config->spi.clk_hz, config->spi.xfer_cs, &config->spi.config);
/* Enable IRQ mode */
if (config->irq_mode.enabled)
{
WIFIDRVS_SPI_InitIRQMode(config);
}
/* Enable DMA mode */
if (config->dma_mode.enabled)
{
WIFIDRVS_SPI_InitDMAMode(config);
}
return A_OK;
}
/*!
* @brief Deinitialize SPI driver
*/
A_STATUS WIFIDRVS_SPI_Deinit(WIFIDRVS_SPI_config_t *config)
{
assert(!(NULL == config));
if (NULL == config) return A_ERROR;
if (NULL == config->spi.base) return A_ERROR;
DSPI_Deinit(config->spi.base);
return A_OK;
}
/*!
* @brief Return default configuration
*/
A_STATUS WIFIDRVS_SPI_GetDefaultConfig(WIFIDRVS_SPI_config_t *config)
{
assert(!(NULL == config));
if (NULL == config) return A_ERROR;
memset(config, 0, sizeof(*config));
config->dma_mode.dma_rx_chnl = -1;
config->dma_mode.dma_im_chnl = -1;
config->dma_mode.dma_tx_chnl = -1;
return A_OK;
}
/*!
* @brief Return default SPI peripheral settings
*/
A_STATUS WIFIDRVS_SPI_GetSPIConfig(dspi_master_config_t *user_config, uint32_t baudrate, dspi_which_pcs_t cs)
{
assert(!(NULL == user_config));
if (NULL == user_config) return A_ERROR;
memset(user_config, 0, sizeof(*user_config));
DSPI_MasterGetDefaultConfig(user_config);
user_config->whichCtar = kDSPI_Ctar0;
user_config->ctarConfig.baudRate = baudrate;
user_config->ctarConfig.bitsPerFrame = 8;
user_config->ctarConfig.cpol = kDSPI_ClockPolarityActiveLow;
user_config->ctarConfig.cpha = kDSPI_ClockPhaseSecondEdge;
user_config->ctarConfig.direction = kDSPI_MsbFirst;
user_config->ctarConfig.pcsToSckDelayInNanoSec = 1000000000U / baudrate;
user_config->ctarConfig.lastSckToPcsDelayInNanoSec = 1000000000U / baudrate;
user_config->ctarConfig.betweenTransferDelayInNanoSec = 1000000000U / baudrate;
user_config->whichPcs = cs;
user_config->pcsActiveHighOrLow = kDSPI_PcsActiveLow;
user_config->enableContinuousSCK = false;
user_config->enableRxFifoOverWrite = false;
user_config->enableModifiedTimingFormat = false;
user_config->samplePoint = kDSPI_SckToSin0Clock;
return A_OK;
}
/*!
* @brief WiFi SPI transfer SPI
*/
A_STATUS WIFIDRVS_SPI_InOutToken(uint32_t OutToken, uint8_t DataSize, uint32_t *pInToken)
{
A_STATUS result;
dspi_transfer_t transfer = {0};
transfer.txData = (uint8_t *)&OutToken;
transfer.rxData = (uint8_t *)pInToken;
transfer.dataSize = DataSize;
transfer.configFlags = g_xfer_cs;
/* Protect transmit by mutex */
if (pdTRUE != xSemaphoreTake(mutex, portMAX_DELAY))
{
return A_ERROR;
}
result = WIFIDRVS_SPI_Transfer(&transfer);
xSemaphoreGive(mutex);
return result;
}
/*!
* @brief WiFi SPI transfer SPI
*/
A_STATUS WIFIDRVS_SPI_InOutBuffer(uint8_t *pBuffer, uint16_t length, uint8_t doRead, boolean sync)
{
A_STATUS result;
dspi_transfer_t transfer = {0};
if (doRead)
{
transfer.txData = NULL;
transfer.rxData = pBuffer;
}
else
{
transfer.txData = pBuffer;
transfer.rxData = NULL;
}
transfer.dataSize = length;
transfer.configFlags = g_xfer_cs;
/* Protect transmit by mutex */
if (pdTRUE != xSemaphoreTake(mutex, portMAX_DELAY))
{
return A_ERROR;
}
result = WIFIDRVS_SPI_Transfer(&transfer);
xSemaphoreGive(mutex);
return result;
}
|
b61324066c4307cb56804ae3dd106c1530a2bfd0
|
b4995c17067e4c16e287b4d0d454a9437ed38751
|
/src/njs_rbtree.c
|
f7d8bf16da1017836c9c792311169ab3147e6617
|
[
"BSD-2-Clause"
] |
permissive
|
nginx/njs
|
95f44a9128d26f8ed6a052b2e00dd7cff1410efb
|
e694d61a94c711b7c48b0ae23909a4cef7c65700
|
refs/heads/master
| 2023-08-24T18:52:57.529281
| 2023-08-23T17:09:22
| 2023-08-23T17:09:22
| 43,038,779
| 742
| 120
|
BSD-2-Clause
| 2023-07-30T09:23:31
| 2015-09-24T02:03:58
|
C
|
UTF-8
|
C
| false
| false
| 13,755
|
c
|
njs_rbtree.c
|
/*
* Copyright (C) Igor Sysoev
* Copyright (C) NGINX, Inc.
*/
#include <njs_main.h>
/*
* The red-black tree code is based on the algorithm described in
* the "Introduction to Algorithms" by Cormen, Leiserson and Rivest.
*/
static void njs_rbtree_insert_fixup(njs_rbtree_node_t *node);
static void njs_rbtree_delete_fixup(njs_rbtree_t *tree,
njs_rbtree_node_t *node);
njs_inline void njs_rbtree_left_rotate(njs_rbtree_node_t *node);
njs_inline void njs_rbtree_right_rotate(njs_rbtree_node_t *node);
njs_inline void njs_rbtree_parent_relink(njs_rbtree_node_t *subst,
njs_rbtree_node_t *node);
#define NJS_RBTREE_BLACK 0
#define NJS_RBTREE_RED 1
#define njs_rbtree_comparison_callback(tree) \
((njs_rbtree_compare_t) (tree)->sentinel.right)
void
njs_rbtree_init(njs_rbtree_t *tree, njs_rbtree_compare_t compare)
{
/*
* The sentinel is used as a leaf node sentinel and as a tree root
* sentinel: it is a parent of a root node and the root node is
* the left child of the sentinel. Combining two sentinels in one
* entry and the fact that the sentinel's left child is a root node
* simplifies njs_rbtree_node_successor() and eliminates explicit
* root node test before or inside njs_rbtree_min().
*/
/* The root is empty. */
tree->sentinel.left = &tree->sentinel;
/*
* The sentinel's right child is never used so
* comparison callback can be safely stored here.
*/
tree->sentinel.right = (void *) compare;
/* The root and leaf sentinel must be black. */
tree->sentinel.color = NJS_RBTREE_BLACK;
}
void
njs_rbtree_insert(njs_rbtree_t *tree, njs_rbtree_part_t *part)
{
njs_rbtree_node_t *node, *new_node, *sentinel, **child;
njs_rbtree_compare_t compare;
new_node = (njs_rbtree_node_t *) part;
node = njs_rbtree_root(tree);
sentinel = njs_rbtree_sentinel(tree);
new_node->left = sentinel;
new_node->right = sentinel;
new_node->color = NJS_RBTREE_RED;
compare = (njs_rbtree_compare_t) tree->sentinel.right;
child = &njs_rbtree_root(tree);
while (*child != sentinel) {
node = *child;
njs_prefetch(node->left);
njs_prefetch(node->right);
child = (compare(new_node, node) < 0) ? &node->left : &node->right;
}
*child = new_node;
new_node->parent = node;
njs_rbtree_insert_fixup(new_node);
node = njs_rbtree_root(tree);
node->color = NJS_RBTREE_BLACK;
}
static void
njs_rbtree_insert_fixup(njs_rbtree_node_t *node)
{
njs_rbtree_node_t *parent, *grandparent, *uncle;
/*
* Prefetching parent nodes does not help here because they are
* already traversed during insertion.
*/
for ( ;; ) {
parent = node->parent;
/*
* Testing whether a node is a tree root is not required here since
* a root node's parent is the sentinel and it is always black.
*/
if (parent->color == NJS_RBTREE_BLACK) {
return;
}
grandparent = parent->parent;
if (parent == grandparent->left) {
uncle = grandparent->right;
if (uncle->color == NJS_RBTREE_BLACK) {
if (node == parent->right) {
node = parent;
njs_rbtree_left_rotate(node);
}
/*
* njs_rbtree_left_rotate() swaps parent and
* child whilst keeps grandparent the same.
*/
parent = node->parent;
parent->color = NJS_RBTREE_BLACK;
grandparent->color = NJS_RBTREE_RED;
njs_rbtree_right_rotate(grandparent);
/*
* njs_rbtree_right_rotate() does not change node->parent
* color which is now black, so testing color is not required
* to return from function.
*/
return;
}
} else {
uncle = grandparent->left;
if (uncle->color == NJS_RBTREE_BLACK) {
if (node == parent->left) {
node = parent;
njs_rbtree_right_rotate(node);
}
/* See the comment in the symmetric branch above. */
parent = node->parent;
parent->color = NJS_RBTREE_BLACK;
grandparent->color = NJS_RBTREE_RED;
njs_rbtree_left_rotate(grandparent);
/* See the comment in the symmetric branch above. */
return;
}
}
uncle->color = NJS_RBTREE_BLACK;
parent->color = NJS_RBTREE_BLACK;
grandparent->color = NJS_RBTREE_RED;
node = grandparent;
}
}
njs_rbtree_node_t *
njs_rbtree_find(njs_rbtree_t *tree, njs_rbtree_part_t *part)
{
intptr_t n;
njs_rbtree_node_t *node, *next, *sentinel;
njs_rbtree_compare_t compare;
node = (njs_rbtree_node_t *) part;
next = njs_rbtree_root(tree);
sentinel = njs_rbtree_sentinel(tree);
compare = njs_rbtree_comparison_callback(tree);
while (next != sentinel) {
njs_prefetch(next->left);
njs_prefetch(next->right);
n = compare(node, next);
if (n < 0) {
next = next->left;
} else if (n > 0) {
next = next->right;
} else {
return next;
}
}
return NULL;
}
njs_rbtree_node_t *
njs_rbtree_find_less_or_equal(njs_rbtree_t *tree, njs_rbtree_part_t *part)
{
intptr_t n;
njs_rbtree_node_t *node, *retval, *next, *sentinel;
njs_rbtree_compare_t compare;
node = (njs_rbtree_node_t *) part;
retval = NULL;
next = njs_rbtree_root(tree);
sentinel = njs_rbtree_sentinel(tree);
compare = njs_rbtree_comparison_callback(tree);
while (next != sentinel) {
njs_prefetch(next->left);
njs_prefetch(next->right);
n = compare(node, next);
if (n < 0) {
next = next->left;
} else if (n > 0) {
retval = next;
next = next->right;
} else {
/* Exact match. */
return next;
}
}
return retval;
}
njs_rbtree_node_t *
njs_rbtree_find_greater_or_equal(njs_rbtree_t *tree, njs_rbtree_part_t *part)
{
intptr_t n;
njs_rbtree_node_t *node, *retval, *next, *sentinel;
njs_rbtree_compare_t compare;
node = (njs_rbtree_node_t *) part;
retval = NULL;
next = njs_rbtree_root(tree);
sentinel = njs_rbtree_sentinel(tree);
compare = njs_rbtree_comparison_callback(tree);
while (next != sentinel) {
njs_prefetch(next->left);
njs_prefetch(next->right);
n = compare(node, next);
if (n < 0) {
retval = next;
next = next->left;
} else if (n > 0) {
next = next->right;
} else {
/* Exact match. */
return next;
}
}
return retval;
}
void
njs_rbtree_delete(njs_rbtree_t *tree, njs_rbtree_part_t *part)
{
uint8_t color;
njs_rbtree_node_t *node, *sentinel, *subst, *child;
node = (njs_rbtree_node_t *) part;
subst = node;
sentinel = njs_rbtree_sentinel(tree);
if (node->left == sentinel) {
child = node->right;
} else if (node->right == sentinel) {
child = node->left;
} else {
subst = njs_rbtree_branch_min(tree, node->right);
child = subst->right;
}
njs_rbtree_parent_relink(child, subst);
color = subst->color;
if (subst != node) {
/* Move the subst node to the deleted node position in the tree. */
subst->color = node->color;
subst->left = node->left;
subst->left->parent = subst;
subst->right = node->right;
subst->right->parent = subst;
njs_rbtree_parent_relink(subst, node);
}
#if (NJS_DEBUG)
node->left = NULL;
node->right = NULL;
node->parent = NULL;
#endif
if (color == NJS_RBTREE_BLACK) {
njs_rbtree_delete_fixup(tree, child);
}
}
static void
njs_rbtree_delete_fixup(njs_rbtree_t *tree, njs_rbtree_node_t *node)
{
njs_rbtree_node_t *parent, *sibling;
while (node != njs_rbtree_root(tree) && node->color == NJS_RBTREE_BLACK) {
/*
* Prefetching parent nodes does not help here according
* to microbenchmarks.
*/
parent = node->parent;
if (node == parent->left) {
sibling = parent->right;
if (sibling->color != NJS_RBTREE_BLACK) {
sibling->color = NJS_RBTREE_BLACK;
parent->color = NJS_RBTREE_RED;
njs_rbtree_left_rotate(parent);
sibling = parent->right;
}
if (sibling->right->color == NJS_RBTREE_BLACK) {
sibling->color = NJS_RBTREE_RED;
if (sibling->left->color == NJS_RBTREE_BLACK) {
node = parent;
continue;
}
sibling->left->color = NJS_RBTREE_BLACK;
njs_rbtree_right_rotate(sibling);
/*
* If the node is the leaf sentinel then the right
* rotate above changes its parent so a sibling below
* becames the leaf sentinel as well and this causes
* segmentation fault. This is the reason why usual
* red-black tree implementations with a leaf sentinel
* which does not require to test leaf nodes at all
* nevertheless test the leaf sentinel in the left and
* right rotate procedures. Since according to the
* algorithm node->parent must not be changed by both
* the left and right rotates above, it can be cached
* in a local variable. This not only eliminates the
* sentinel test in njs_rbtree_parent_relink() but also
* decreases the code size because C forces to reload
* non-restrict pointers.
*/
sibling = parent->right;
}
sibling->color = parent->color;
parent->color = NJS_RBTREE_BLACK;
sibling->right->color = NJS_RBTREE_BLACK;
njs_rbtree_left_rotate(parent);
return;
} else {
sibling = parent->left;
if (sibling->color != NJS_RBTREE_BLACK) {
sibling->color = NJS_RBTREE_BLACK;
parent->color = NJS_RBTREE_RED;
njs_rbtree_right_rotate(parent);
sibling = parent->left;
}
if (sibling->left->color == NJS_RBTREE_BLACK) {
sibling->color = NJS_RBTREE_RED;
if (sibling->right->color == NJS_RBTREE_BLACK) {
node = parent;
continue;
}
sibling->right->color = NJS_RBTREE_BLACK;
njs_rbtree_left_rotate(sibling);
/* See the comment in the symmetric branch above. */
sibling = parent->left;
}
sibling->color = parent->color;
parent->color = NJS_RBTREE_BLACK;
sibling->left->color = NJS_RBTREE_BLACK;
njs_rbtree_right_rotate(parent);
return;
}
}
node->color = NJS_RBTREE_BLACK;
}
njs_inline void
njs_rbtree_left_rotate(njs_rbtree_node_t *node)
{
njs_rbtree_node_t *child;
child = node->right;
node->right = child->left;
child->left->parent = node;
child->left = node;
njs_rbtree_parent_relink(child, node);
node->parent = child;
}
njs_inline void
njs_rbtree_right_rotate(njs_rbtree_node_t *node)
{
njs_rbtree_node_t *child;
child = node->left;
node->left = child->right;
child->right->parent = node;
child->right = node;
njs_rbtree_parent_relink(child, node);
node->parent = child;
}
/* Relink a parent from the node to the subst node. */
njs_inline void
njs_rbtree_parent_relink(njs_rbtree_node_t *subst, njs_rbtree_node_t *node)
{
njs_rbtree_node_t *parent, **link;
parent = node->parent;
/*
* The leaf sentinel's parent can be safely changed here.
* See the comment in njs_rbtree_delete_fixup() for details.
*/
subst->parent = parent;
/*
* If the node's parent is the root sentinel it is safely changed
* because the root sentinel's left child is the tree root.
*/
link = (node == parent->left) ? &parent->left : &parent->right;
*link = subst;
}
njs_rbtree_node_t *
njs_rbtree_destroy_next(njs_rbtree_t *tree, njs_rbtree_node_t **next)
{
njs_rbtree_node_t *node, *subst, *parent, *sentinel;
sentinel = njs_rbtree_sentinel(tree);
/* Find the leftmost node. */
for (node = *next; node->left != sentinel; node = node->left);
/* Replace the leftmost node with its right child. */
subst = node->right;
parent = node->parent;
parent->left = subst;
subst->parent = parent;
/*
* The right child is used as the next start node. If the right child
* is the sentinel then parent of the leftmost node is used as the next
* start node. The parent of the root node is the sentinel so after
* the single root node will be replaced with the sentinel, the next
* start node will be equal to the sentinel and iteration will stop.
*/
if (subst == sentinel) {
subst = parent;
}
*next = subst;
return node;
}
|
5b9e93edec15e9fd7e86a6e8ea7173e928e427eb
|
03666e5f961946fc1a0ac67781ac1425562ef0d7
|
/src/plots/Label/quant_vector_lookup.C
|
63ad8215fb610836734cd81a83c4f7ca859bc523
|
[
"BSD-3-Clause",
"LicenseRef-scancode-unknown-license-reference"
] |
permissive
|
visit-dav/visit
|
e9f81b4d4b9b9930a0db9d5282cd1bcabf465e2e
|
601ae46e0bef2e18425b482a755d03490ade0493
|
refs/heads/develop
| 2023-09-06T08:19:38.397058
| 2023-09-05T21:29:32
| 2023-09-05T21:29:32
| 165,565,988
| 335
| 120
|
BSD-3-Clause
| 2023-09-14T00:53:37
| 2019-01-13T23:27:26
|
C
|
UTF-8
|
C
| false
| false
| 8,938
|
c
|
quant_vector_lookup.C
|
// Copyright (c) Lawrence Livermore National Security, LLC and other VisIt
// Project developers. See the top-level LICENSE file for dates and other
// details. No copyright assignment is required to contribute to VisIt.
#define MAX_QUANT_VECTORS 226
const float quant_vector_lookup[226][3] = {
// Bin 0 starts at index 0
{0, 0, 1},
{0.207912, 0, 0.978148},
{0.406737, 0, 0.913545},
{0.587785, 0, 0.809017},
{0.743145, 0, 0.669131},
{0.866025, 0, 0.5},
{0.951057, 0, 0.309017},
{0.994522, 0, 0.104528},
{0.192085, 0.0795644, 0.978148},
{0.375776, 0.155651, 0.913545},
{0.543043, 0.224936, 0.809017},
{0.686576, 0.284389, 0.669131},
{0.800103, 0.331414, 0.5},
{0.878662, 0.363954, 0.309017},
{0.918818, 0.380587, 0.104528},
{0.147016, 0.147016, 0.978148},
{0.287606, 0.287606, 0.913545},
{0.415627, 0.415627, 0.809017},
{0.525483, 0.525483, 0.669131},
{0.612372, 0.612372, 0.5},
{0.672499, 0.672499, 0.309017},
{0.703233, 0.703233, 0.104528},
{0.0795644, 0.192085, 0.978148},
{0.155651, 0.375776, 0.913545},
{0.224936, 0.543043, 0.809017},
{0.284389, 0.686576, 0.669131},
{0.331414, 0.800103, 0.5},
{0.363954, 0.878662, 0.309017},
{0.380587, 0.918818, 0.104528},
// Bin 1 starts at index 29
{-9.08811e-09, 0.207912, 0.978148},
{-1.7779e-08, 0.406737, 0.913545},
{-2.56929e-08, 0.587785, 0.809017},
{-3.24839e-08, 0.743145, 0.669131},
{-3.78552e-08, 0.866025, 0.5},
{-4.1572e-08, 0.951057, 0.309017},
{-4.34719e-08, 0.994522, 0.104528},
{-0.0795644, 0.192085, 0.978148},
{-0.155651, 0.375776, 0.913545},
{-0.224936, 0.543043, 0.809017},
{-0.284389, 0.686576, 0.669131},
{-0.331414, 0.800103, 0.5},
{-0.363954, 0.878662, 0.309017},
{-0.380587, 0.918818, 0.104528},
{-0.147016, 0.147016, 0.978148},
{-0.287606, 0.287606, 0.913545},
{-0.415627, 0.415627, 0.809017},
{-0.525483, 0.525483, 0.669131},
{-0.612372, 0.612372, 0.5},
{-0.672499, 0.672499, 0.309017},
{-0.703233, 0.703233, 0.104528},
{-0.192085, 0.0795643, 0.978148},
{-0.375776, 0.155651, 0.913545},
{-0.543043, 0.224936, 0.809017},
{-0.686576, 0.284389, 0.669131},
{-0.800103, 0.331413, 0.5},
{-0.878662, 0.363953, 0.309017},
{-0.918819, 0.380587, 0.104528},
// Bin 2 starts at index 57
{2.47932e-09, -0.207912, 0.978148},
{4.85029e-09, -0.406737, 0.913545},
{7.00927e-09, -0.587785, 0.809017},
{8.86191e-09, -0.743145, 0.669131},
{1.03273e-08, -0.866025, 0.5},
{1.13412e-08, -0.951057, 0.309017},
{1.18596e-08, -0.994522, 0.104528},
{0.0795644, -0.192085, 0.978148},
{0.155651, -0.375776, 0.913545},
{0.224936, -0.543043, 0.809017},
{0.284389, -0.686576, 0.669131},
{0.331414, -0.800103, 0.5},
{0.363954, -0.878662, 0.309017},
{0.380587, -0.918818, 0.104528},
{0.147016, -0.147016, 0.978148},
{0.287606, -0.287606, 0.913545},
{0.415627, -0.415627, 0.809017},
{0.525483, -0.525483, 0.669131},
{0.612373, -0.612372, 0.5},
{0.672499, -0.672498, 0.309017},
{0.703233, -0.703233, 0.104528},
{0.192085, -0.0795644, 0.978148},
{0.375776, -0.155651, 0.913545},
{0.543043, -0.224936, 0.809017},
{0.686576, -0.284389, 0.669131},
{0.800103, -0.331414, 0.5},
{0.878662, -0.363954, 0.309017},
{0.918818, -0.380587, 0.104528},
// Bin 3 starts at index 85
{-0.207912, -1.81762e-08, 0.978148},
{-0.406737, -3.5558e-08, 0.913545},
{-0.587785, -5.13858e-08, 0.809017},
{-0.743145, -6.49678e-08, 0.669131},
{-0.866025, -7.57104e-08, 0.5},
{-0.951057, -8.3144e-08, 0.309017},
{-0.994522, -8.69439e-08, 0.104528},
{-0.192085, -0.0795644, 0.978148},
{-0.375776, -0.155651, 0.913545},
{-0.543043, -0.224936, 0.809017},
{-0.686576, -0.284389, 0.669131},
{-0.800103, -0.331414, 0.5},
{-0.878662, -0.363954, 0.309017},
{-0.918818, -0.380587, 0.104528},
{-0.147016, -0.147016, 0.978148},
{-0.287606, -0.287606, 0.913545},
{-0.415627, -0.415627, 0.809017},
{-0.525483, -0.525483, 0.669131},
{-0.612372, -0.612373, 0.5},
{-0.672498, -0.672499, 0.309017},
{-0.703233, -0.703233, 0.104528},
{-0.0795643, -0.192085, 0.978148},
{-0.155651, -0.375776, 0.913545},
{-0.224936, -0.543043, 0.809017},
{-0.284389, -0.686576, 0.669131},
{-0.331413, -0.800103, 0.5},
{-0.363953, -0.878662, 0.309017},
{-0.380587, -0.918819, 0.104528},
// Bin 4 starts at index 113
{0, 0, -1},
{0.994522, 0, -0.104529},
{0.951056, 0, -0.309017},
{0.866025, 0, -0.5},
{0.743145, 0, -0.669131},
{0.587785, 0, -0.809017},
{0.406737, 0, -0.913545},
{0.207912, 0, -0.978148},
{0.918818, 0.380587, -0.104529},
{0.878662, 0.363954, -0.309017},
{0.800103, 0.331414, -0.5},
{0.686576, 0.284389, -0.669131},
{0.543043, 0.224936, -0.809017},
{0.375776, 0.155651, -0.913545},
{0.192085, 0.0795643, -0.978148},
{0.703233, 0.703233, -0.104529},
{0.672498, 0.672499, -0.309017},
{0.612372, 0.612372, -0.5},
{0.525483, 0.525483, -0.669131},
{0.415627, 0.415627, -0.809017},
{0.287606, 0.287606, -0.913545},
{0.147016, 0.147016, -0.978148},
{0.380587, 0.918818, -0.104529},
{0.363954, 0.878662, -0.309017},
{0.331414, 0.800103, -0.5},
{0.284389, 0.686576, -0.669131},
{0.224936, 0.543043, -0.809017},
{0.155651, 0.375776, -0.913545},
{0.0795643, 0.192085, -0.978148},
// Bin 5 starts at index 142
{-4.34719e-08, 0.994522, -0.104529},
{-4.1572e-08, 0.951056, -0.309017},
{-3.78552e-08, 0.866025, -0.5},
{-3.24839e-08, 0.743145, -0.669131},
{-2.56929e-08, 0.587785, -0.809017},
{-1.7779e-08, 0.406737, -0.913545},
{-9.08811e-09, 0.207912, -0.978148},
{-0.380587, 0.918818, -0.104529},
{-0.363954, 0.878662, -0.309017},
{-0.331414, 0.800103, -0.5},
{-0.284389, 0.686576, -0.669131},
{-0.224936, 0.543043, -0.809017},
{-0.155651, 0.375776, -0.913545},
{-0.0795643, 0.192085, -0.978148},
{-0.703233, 0.703233, -0.104529},
{-0.672498, 0.672498, -0.309017},
{-0.612372, 0.612372, -0.5},
{-0.525483, 0.525483, -0.669131},
{-0.415627, 0.415627, -0.809017},
{-0.287606, 0.287606, -0.913545},
{-0.147016, 0.147016, -0.978148},
{-0.918819, 0.380587, -0.104529},
{-0.878662, 0.363953, -0.309017},
{-0.800103, 0.331413, -0.5},
{-0.686576, 0.284389, -0.669131},
{-0.543043, 0.224936, -0.809017},
{-0.375776, 0.155651, -0.913545},
{-0.192085, 0.0795643, -0.978148},
// Bin 6 starts at index 170
{1.18596e-08, -0.994522, -0.104529},
{1.13412e-08, -0.951056, -0.309017},
{1.03272e-08, -0.866025, -0.5},
{8.86191e-09, -0.743145, -0.669131},
{7.00927e-09, -0.587785, -0.809017},
{4.85029e-09, -0.406737, -0.913545},
{2.47932e-09, -0.207912, -0.978148},
{0.380587, -0.918818, -0.104529},
{0.363954, -0.878662, -0.309017},
{0.331414, -0.800103, -0.5},
{0.284389, -0.686576, -0.669131},
{0.224936, -0.543043, -0.809017},
{0.155651, -0.375776, -0.913545},
{0.0795644, -0.192085, -0.978148},
{0.703233, -0.703233, -0.104529},
{0.672499, -0.672498, -0.309017},
{0.612373, -0.612372, -0.5},
{0.525483, -0.525483, -0.669131},
{0.415627, -0.415627, -0.809017},
{0.287606, -0.287606, -0.913545},
{0.147016, -0.147016, -0.978148},
{0.918818, -0.380587, -0.104529},
{0.878662, -0.363954, -0.309017},
{0.800103, -0.331414, -0.5},
{0.686576, -0.284389, -0.669131},
{0.543043, -0.224936, -0.809017},
{0.375776, -0.155651, -0.913545},
{0.192085, -0.0795643, -0.978148},
// Bin 7 starts at index 198
{-0.994522, -8.69439e-08, -0.104529},
{-0.951056, -8.3144e-08, -0.309017},
{-0.866025, -7.57103e-08, -0.5},
{-0.743145, -6.49678e-08, -0.669131},
{-0.587785, -5.13858e-08, -0.809017},
{-0.406737, -3.5558e-08, -0.913545},
{-0.207912, -1.81762e-08, -0.978148},
{-0.918818, -0.380587, -0.104529},
{-0.878662, -0.363954, -0.309017},
{-0.800103, -0.331414, -0.5},
{-0.686576, -0.284389, -0.669131},
{-0.543043, -0.224936, -0.809017},
{-0.375776, -0.155651, -0.913545},
{-0.192085, -0.0795643, -0.978148},
{-0.703233, -0.703233, -0.104529},
{-0.672498, -0.672499, -0.309017},
{-0.612372, -0.612373, -0.5},
{-0.525483, -0.525483, -0.669131},
{-0.415627, -0.415627, -0.809017},
{-0.287606, -0.287606, -0.913545},
{-0.147016, -0.147016, -0.978148},
{-0.380587, -0.918819, -0.104529},
{-0.363953, -0.878662, -0.309017},
{-0.331413, -0.800103, -0.5},
{-0.284389, -0.686576, -0.669131},
{-0.224935, -0.543043, -0.809017},
{-0.155651, -0.375776, -0.913545},
{-0.0795643, -0.192085, -0.978148}
};
const unsigned char quant_vector_lookup_binbounds[] = {
0, 29, 57, 85, 113, 142, 170, 198, 226
};
|
4a2b3b30f3c1b0a99a311b7a5b9918efcf496905
|
d2b10e3573c6a106fb431199537b8eb26ca14b29
|
/src/path/sentry_path_windows.c
|
b953af9a6b9ad506caea8a3b167136e2f33c17a4
|
[
"MIT"
] |
permissive
|
getsentry/sentry-native
|
51485a2bad5d53210e95f7be11e1f59d35c52702
|
d9e901951ac5ba068e095e54a7d9c59a9330665d
|
refs/heads/master
| 2023-08-28T08:23:44.357073
| 2023-07-31T09:18:44
| 2023-07-31T09:18:44
| 173,787,329
| 324
| 175
|
MIT
| 2023-09-14T12:02:50
| 2019-03-04T17:08:34
|
C
|
UTF-8
|
C
| false
| false
| 13,824
|
c
|
sentry_path_windows.c
|
#include "sentry_boot.h"
#include "sentry_alloc.h"
#include "sentry_core.h"
#include "sentry_path.h"
#include "sentry_string.h"
#include "sentry_utils.h"
#include <errno.h>
#include <fcntl.h>
#include <io.h>
#include <stdlib.h>
#include <sys/locking.h>
#include <sys/stat.h>
#include <sys/types.h>
// only read this many bytes to memory ever
static const size_t MAX_READ_TO_BUFFER = 134217728;
#ifndef __MINGW32__
# define S_ISREG(m) (((m)&_S_IFMT) == _S_IFREG)
# define S_ISDIR(m) (((m)&_S_IFMT) == _S_IFDIR)
#endif
struct sentry_pathiter_s {
HANDLE dir_handle;
const sentry_path_t *parent;
sentry_path_t *current;
};
static size_t
write_loop(FILE *f, const char *buf, size_t buf_len)
{
while (buf_len > 0) {
size_t n = fwrite(buf, 1, buf_len, f);
if (n == 0 && errno == EINVAL) {
continue;
} else if (n < buf_len) {
break;
}
buf += n;
buf_len -= n;
}
fflush(f);
return buf_len;
}
bool
sentry__filelock_try_lock(sentry_filelock_t *lock)
{
lock->is_locked = false;
int fd = _wopen(
lock->path->path, _O_RDWR | _O_CREAT | _O_TRUNC, _S_IREAD | _S_IWRITE);
if (fd < 0) {
return false;
}
if (_locking(fd, _LK_NBLCK, 1) != 0) {
_close(fd);
return false;
}
lock->fd = fd;
lock->is_locked = true;
return true;
}
void
sentry__filelock_unlock(sentry_filelock_t *lock)
{
if (!lock->is_locked) {
return;
}
_locking(lock->fd, LK_UNLCK, 1);
_close(lock->fd);
// the remove function will fail if we, or any other process still has an
// open handle to the file.
sentry__path_remove(lock->path);
lock->is_locked = false;
}
static sentry_path_t *
path_with_len(size_t len)
{
sentry_path_t *rv = SENTRY_MAKE(sentry_path_t);
rv->path = sentry_malloc(sizeof(wchar_t) * len);
if (!rv->path) {
sentry_free(rv);
return NULL;
}
return rv;
}
sentry_path_t *
sentry__path_absolute(const sentry_path_t *path)
{
wchar_t full[_MAX_PATH];
if (!_wfullpath(full, path->path, _MAX_PATH)) {
return NULL;
}
return sentry__path_from_wstr(full);
}
sentry_path_t *
sentry__path_current_exe(void)
{
// inspired by:
// https://github.com/rust-lang/rust/blob/183e893aaae581bd0ab499ba56b6c5e118557dc7/src/libstd/sys/windows/os.rs#L234-L239
sentry_path_t *path = path_with_len(MAX_PATH);
size_t len = GetModuleFileNameW(NULL, path->path, MAX_PATH);
if (!len) {
SENTRY_DEBUG("unable to get current exe path");
sentry__path_free(path);
return NULL;
}
return path;
}
sentry_path_t *
sentry__path_dir(const sentry_path_t *path)
{
sentry_path_t *dir_path = sentry__path_clone(path);
if (!dir_path) {
return NULL;
}
// find the filename part and truncate just in front of it if possible
sentry_pathchar_t *filename
= (sentry_pathchar_t *)sentry__path_filename(dir_path);
if (filename > dir_path->path) {
*(filename - 1) = L'\0';
}
return dir_path;
}
sentry_path_t *
sentry__path_from_wstr_n(const wchar_t *s, size_t s_len)
{
if (!s) {
return NULL;
}
sentry_path_t *rv = path_with_len(s_len + 1);
if (rv) {
memcpy(rv->path, s, s_len * sizeof(wchar_t));
rv->path[s_len] = 0;
}
return rv;
}
sentry_path_t *
sentry__path_from_wstr(const wchar_t *s)
{
if (!s) {
return NULL;
}
return sentry__path_from_wstr_n(s, wcslen(s));
}
sentry_path_t *
sentry__path_join_wstr(const sentry_path_t *base, const wchar_t *other)
{
if (isalpha(other[0]) && other[1] == L':') {
return sentry__path_from_wstr(other);
} else if (other[0] == L'/' || other[0] == L'\\') {
if (isalpha(base->path[0]) && base->path[1] == L':') {
size_t len = wcslen(other) + 3;
sentry_path_t *rv = path_with_len(len);
if (!rv) {
return NULL;
}
rv->path[0] = base->path[0];
rv->path[1] = L':';
memcpy(rv->path + 2, other, sizeof(wchar_t) * len);
return rv;
} else {
return sentry__path_from_wstr(other);
}
} else {
size_t base_len = wcslen(base->path);
size_t other_len = wcslen(other);
size_t len = base_len + other_len + 1;
bool need_sep = false;
if (base_len && base->path[base_len - 1] != L'/'
&& base->path[base_len - 1] != L'\\') {
len += 1;
need_sep = true;
}
sentry_path_t *rv = path_with_len(len);
if (!rv) {
return NULL;
}
memcpy(rv->path, base->path, sizeof(wchar_t) * base_len);
if (need_sep) {
rv->path[base_len] = L'\\';
}
memcpy(rv->path + base_len + (need_sep ? 1 : 0), other,
sizeof(wchar_t) * (other_len + 1));
return rv;
}
}
sentry_path_t *
sentry__path_from_str_n(const char *s, size_t s_len)
{
if (!s) {
return NULL;
}
sentry_path_t *rv = SENTRY_MAKE(sentry_path_t);
if (!rv) {
return NULL;
}
size_t src_size = sizeof(char) * s_len;
size_t dst_size = sizeof(wchar_t) * (s_len + 1);
rv->path = sentry_malloc(dst_size);
if (!rv->path) {
goto error;
}
int conv_len = MultiByteToWideChar(
CP_ACP, 0, s, (int)src_size, rv->path, (int)s_len);
if (conv_len == 0) {
goto error;
}
rv->path[conv_len] = 0;
return rv;
error:
sentry_free(rv);
return NULL;
}
sentry_path_t *
sentry__path_from_str(const char *s)
{
if (!s) {
return NULL;
}
return sentry__path_from_str_n(s, strlen(s));
}
sentry_path_t *
sentry__path_from_str_owned(char *s)
{
sentry_path_t *rv = sentry__path_from_str(s);
sentry_free(s);
return rv;
}
const sentry_pathchar_t *
sentry__path_filename(const sentry_path_t *path)
{
const wchar_t *s = path->path;
const wchar_t *ptr = s;
size_t idx = wcslen(s);
while (true) {
if (s[idx] == L'/' || s[idx] == L'\\') {
ptr = s + idx + 1;
break;
}
if (idx > 0) {
idx -= 1;
} else {
break;
}
}
return ptr;
}
bool
sentry__path_filename_matches(const sentry_path_t *path, const char *filename)
{
sentry_path_t *fn = sentry__path_from_str(filename);
bool matches = _wcsicmp(sentry__path_filename(path), fn->path) == 0;
sentry__path_free(fn);
return matches;
}
bool
sentry__path_ends_with(const sentry_path_t *path, const char *suffix)
{
sentry_path_t *s = sentry__path_from_str(suffix);
size_t pathlen = wcslen(path->path);
size_t suffixlen = wcslen(s->path);
if (suffixlen > pathlen) {
sentry__path_free(s);
return false;
}
bool matches = _wcsicmp(&path->path[pathlen - suffixlen], s->path) == 0;
sentry__path_free(s);
return matches;
}
bool
sentry__path_is_dir(const sentry_path_t *path)
{
struct _stat buf;
return _wstat(path->path, &buf) == 0 && S_ISDIR(buf.st_mode);
}
bool
sentry__path_is_file(const sentry_path_t *path)
{
struct _stat buf;
return _wstat(path->path, &buf) == 0 && S_ISREG(buf.st_mode);
}
size_t
sentry__path_get_size(const sentry_path_t *path)
{
struct _stat buf;
if (_wstat(path->path, &buf) == 0 && S_ISREG(buf.st_mode)) {
return (size_t)buf.st_size;
} else {
return 0;
}
}
sentry_path_t *
sentry__path_append_str(const sentry_path_t *base, const char *suffix)
{
// convert to wstr
sentry_path_t *suffix_path = sentry__path_from_str(suffix);
if (!suffix_path) {
return NULL;
}
// concat into new path
size_t len_base = wcslen(base->path);
size_t len_suffix = wcslen(suffix_path->path);
size_t len = len_base + len_suffix + 1;
sentry_path_t *rv = path_with_len(len);
if (rv) {
memcpy(rv->path, base->path, len_base * sizeof(wchar_t));
memcpy(rv->path + len_base, suffix_path->path,
(len_suffix + 1) * sizeof(wchar_t));
}
sentry__path_free(suffix_path);
return rv;
}
sentry_path_t *
sentry__path_join_str(const sentry_path_t *base, const char *other)
{
sentry_path_t *other_path = sentry__path_from_str(other);
if (!other_path) {
return NULL;
}
sentry_path_t *rv = sentry__path_join_wstr(base, other_path->path);
sentry__path_free(other_path);
return rv;
}
sentry_path_t *
sentry__path_clone(const sentry_path_t *path)
{
sentry_path_t *rv = SENTRY_MAKE(sentry_path_t);
if (!rv) {
return NULL;
}
rv->path = _wcsdup(path->path);
return rv;
}
int
sentry__path_remove(const sentry_path_t *path)
{
if (!sentry__path_is_dir(path)) {
if (DeleteFileW(path->path)) {
return 0;
}
return GetLastError() == ERROR_FILE_NOT_FOUND ? 0 : 1;
} else {
if (RemoveDirectoryW(path->path)) {
return 0;
}
return 1;
}
}
int
sentry__path_create_dir_all(const sentry_path_t *path)
{
wchar_t *p = NULL;
wchar_t *ptr = NULL;
int rv = 0;
#define _TRY_MAKE_DIR \
do { \
if (!CreateDirectoryW(p, NULL) \
&& GetLastError() != ERROR_ALREADY_EXISTS) { \
rv = 1; \
goto done; \
} \
} while (0)
size_t len = wcslen(path->path) + 1;
p = sentry_malloc(sizeof(wchar_t) * len);
memcpy(p, path->path, len * sizeof(wchar_t));
for (ptr = p; *ptr; ptr++) {
if ((*ptr == L'\\' || *ptr == L'/') && ptr != p && ptr[-1] != L':') {
*ptr = 0;
_TRY_MAKE_DIR;
*ptr = L'\\';
}
}
_TRY_MAKE_DIR;
#undef _TRY_MAKE_DIR
done:
sentry_free(p);
return rv;
}
sentry_pathiter_t *
sentry__path_iter_directory(const sentry_path_t *path)
{
sentry_pathiter_t *rv = SENTRY_MAKE(sentry_pathiter_t);
if (!rv) {
return NULL;
}
rv->dir_handle = INVALID_HANDLE_VALUE;
rv->parent = path;
rv->current = NULL;
return rv;
}
const sentry_path_t *
sentry__pathiter_next(sentry_pathiter_t *piter)
{
WIN32_FIND_DATAW data;
while (true) {
if (piter->dir_handle == INVALID_HANDLE_VALUE) {
size_t path_len = wcslen(piter->parent->path);
wchar_t *pattern = sentry_malloc(sizeof(wchar_t) * (path_len + 3));
if (!pattern) {
return NULL;
}
memcpy(pattern, piter->parent->path, sizeof(wchar_t) * path_len);
pattern[path_len] = L'\\';
pattern[path_len + 1] = L'*';
pattern[path_len + 2] = 0;
piter->dir_handle = FindFirstFileW(pattern, &data);
sentry_free(pattern);
if (piter->dir_handle == INVALID_HANDLE_VALUE) {
return NULL;
}
} else {
if (!FindNextFileW(piter->dir_handle, &data)) {
return NULL;
}
}
if (wcscmp(data.cFileName, L".") == 0
|| wcscmp(data.cFileName, L"..") == 0) {
continue;
} else {
break;
}
}
if (piter->current) {
sentry__path_free(piter->current);
}
piter->current = sentry__path_join_wstr(piter->parent, data.cFileName);
return piter->current;
}
void
sentry__pathiter_free(sentry_pathiter_t *piter)
{
if (!piter) {
return;
}
if (piter->dir_handle != INVALID_HANDLE_VALUE) {
FindClose(piter->dir_handle);
}
sentry__path_free(piter->current);
sentry_free(piter);
}
int
sentry__path_touch(const sentry_path_t *path)
{
FILE *f = _wfopen(path->path, L"a");
if (f) {
fclose(f);
return 0;
}
return 1;
}
char *
sentry__path_read_to_buffer(const sentry_path_t *path, size_t *size_out)
{
FILE *f = _wfopen(path->path, L"rb");
if (!f) {
return NULL;
}
size_t len = sentry__path_get_size(path);
if (len == 0) {
fclose(f);
char *rv = sentry_malloc(1);
rv[0] = '\0';
if (size_out) {
*size_out = 0;
}
return rv;
} else if (len > MAX_READ_TO_BUFFER) {
fclose(f);
return NULL;
}
// this is completely not sane in concurrent situations but hey
char *rv = sentry_malloc(len + 1);
if (!rv) {
fclose(f);
return NULL;
}
size_t remaining = len;
size_t offset = 0;
while (remaining > 0) {
size_t n = fread(rv + offset, 1, remaining, f);
if (n == 0) {
break;
}
offset += n;
remaining -= n;
}
rv[offset] = '\0';
fclose(f);
if (size_out) {
*size_out = offset;
}
return rv;
}
static int
write_buffer_with_mode(const sentry_path_t *path, const char *buf,
size_t buf_len, const wchar_t *mode)
{
FILE *f = _wfopen(path->path, mode);
if (!f) {
return 1;
}
size_t remaining = write_loop(f, buf, buf_len);
fclose(f);
return remaining == 0 ? 0 : 1;
}
int
sentry__path_write_buffer(
const sentry_path_t *path, const char *buf, size_t buf_len)
{
return write_buffer_with_mode(path, buf, buf_len, L"wb");
}
int
sentry__path_append_buffer(
const sentry_path_t *path, const char *buf, size_t buf_len)
{
return write_buffer_with_mode(path, buf, buf_len, L"ab");
}
|
78026ff3ab499a27b53fbfbc6bec3559a7c3dadf
|
9ceacf33fd96913cac7ef15492c126d96cae6911
|
/sys/dev/pci/drm/i915/i915_mm.c
|
f720c48df2bcdb3a293f36ef85f45484feca2024
|
[] |
no_license
|
openbsd/src
|
ab97ef834fd2d5a7f6729814665e9782b586c130
|
9e79f3a0ebd11a25b4bff61e900cb6de9e7795e9
|
refs/heads/master
| 2023-09-02T18:54:56.624627
| 2023-09-02T15:16:12
| 2023-09-02T15:16:12
| 66,966,208
| 3,394
| 1,235
| null | 2023-08-08T02:42:25
| 2016-08-30T18:18:25
|
C
|
UTF-8
|
C
| false
| false
| 4,472
|
c
|
i915_mm.c
|
/*
* Copyright © 2014 Intel Corporation
*
* 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 (including the next
* paragraph) 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 <linux/mm.h>
#include <linux/io-mapping.h>
#include "i915_drv.h"
#include "i915_mm.h"
struct remap_pfn {
struct mm_struct *mm;
unsigned long pfn;
pgprot_t prot;
struct sgt_iter sgt;
resource_size_t iobase;
};
#define use_dma(io) ((io) != -1)
static inline unsigned long sgt_pfn(const struct remap_pfn *r)
{
if (use_dma(r->iobase))
return (r->sgt.dma + r->sgt.curr + r->iobase) >> PAGE_SHIFT;
else
return r->sgt.pfn + (r->sgt.curr >> PAGE_SHIFT);
}
#ifdef notyet
static int remap_sg(pte_t *pte, unsigned long addr, void *data)
{
struct remap_pfn *r = data;
if (GEM_WARN_ON(!r->sgt.sgp))
return -EINVAL;
/* Special PTE are not associated with any struct vm_page */
set_pte_at(r->mm, addr, pte,
pte_mkspecial(pfn_pte(sgt_pfn(r), r->prot)));
r->pfn++; /* track insertions in case we need to unwind later */
r->sgt.curr += PAGE_SIZE;
if (r->sgt.curr >= r->sgt.max)
r->sgt = __sgt_iter(__sg_next(r->sgt.sgp), use_dma(r->iobase));
return 0;
}
#define EXPECTED_FLAGS (VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP)
#if IS_ENABLED(CONFIG_X86)
#ifdef notyet
static int remap_pfn(pte_t *pte, unsigned long addr, void *data)
{
struct remap_pfn *r = data;
/* Special PTE are not associated with any struct page */
set_pte_at(r->mm, addr, pte, pte_mkspecial(pfn_pte(r->pfn, r->prot)));
r->pfn++;
return 0;
}
#endif
/**
* remap_io_mapping - remap an IO mapping to userspace
* @vma: user vma to map to
* @addr: target user address to start at
* @pfn: physical address of kernel memory
* @size: size of map area
* @iomap: the source io_mapping
*
* Note: this is only safe if the mm semaphore is held when called.
*/
int remap_io_mapping(struct vm_area_struct *vma,
unsigned long addr, unsigned long pfn, unsigned long size,
struct io_mapping *iomap)
{
struct remap_pfn r;
int err;
GEM_BUG_ON((vma->vm_flags & EXPECTED_FLAGS) != EXPECTED_FLAGS);
/* We rely on prevalidation of the io-mapping to skip track_pfn(). */
r.mm = vma->vm_mm;
r.pfn = pfn;
r.prot = __pgprot((pgprot_val(iomap->prot) & _PAGE_CACHE_MASK) |
(pgprot_val(vma->vm_page_prot) & ~_PAGE_CACHE_MASK));
err = apply_to_page_range(r.mm, addr, size, remap_pfn, &r);
if (unlikely(err)) {
zap_vma_ptes(vma, addr, (r.pfn - pfn) << PAGE_SHIFT);
return err;
}
return 0;
}
#endif
/**
* remap_io_sg - remap an IO mapping to userspace
* @vma: user vma to map to
* @addr: target user address to start at
* @size: size of map area
* @sgl: Start sg entry
* @iobase: Use stored dma address offset by this address or pfn if -1
*
* Note: this is only safe if the mm semaphore is held when called.
*/
int remap_io_sg(struct vm_area_struct *vma,
unsigned long addr, unsigned long size,
struct scatterlist *sgl, resource_size_t iobase)
{
struct remap_pfn r = {
.mm = vma->vm_mm,
.prot = vma->vm_page_prot,
.sgt = __sgt_iter(sgl, use_dma(iobase)),
.iobase = iobase,
};
int err;
/* We rely on prevalidation of the io-mapping to skip track_pfn(). */
GEM_BUG_ON((vma->vm_flags & EXPECTED_FLAGS) != EXPECTED_FLAGS);
if (!use_dma(iobase))
flush_cache_range(vma, addr, size);
err = apply_to_page_range(r.mm, addr, size, remap_sg, &r);
if (unlikely(err)) {
zap_vma_ptes(vma, addr, r.pfn << PAGE_SHIFT);
return err;
}
return 0;
}
#endif /* notyet */
|
5633add81303ebe3f31abb6316222430927e8e6b
|
f6e5f3c038fb15cb1bfd2e0a6e8038324656bd28
|
/3rdparty/openssl-win32/openssl/bio_lcl.h
|
0653380eff670eb4612c2e7ff48057fd3d607185
|
[
"OpenSSL",
"MIT"
] |
permissive
|
vslavik/winsparkle
|
c838830255f0fc0d0d1c4c6251e450ebf0eb9a45
|
415acf557e8c15a12d8168d298b3b577fdbc6d54
|
refs/heads/master
| 2023-09-01T13:39:55.053989
| 2023-08-31T16:20:45
| 2023-08-31T17:17:37
| 467,582
| 1,105
| 279
|
NOASSERTION
| 2023-09-13T21:46:13
| 2010-01-11T16:13:10
|
C++
|
UTF-8
|
C
| false
| false
| 46
|
h
|
bio_lcl.h
|
#include "../../openssl/crypto/bio/bio_lcl.h"
|
9050248c06e1bb05c705dd411f8cc1c5fc4caf13
|
dd90a566f56722a602207ceee39a4e1803915c5c
|
/src/nanopolish_vcf2fasta.h
|
729cebe87b6d0a661a835a89aaa301941621322f
|
[
"MPL-1.1",
"LicenseRef-scancode-public-domain",
"MIT"
] |
permissive
|
jts/nanopolish
|
98b3a8996ab44283990fe707ffc44d45b2a61695
|
28e774088b4a780b86066571896348e790f4113c
|
refs/heads/master
| 2023-08-14T02:02:30.379708
| 2023-08-05T15:27:20
| 2023-08-05T15:27:20
| 28,145,157
| 524
| 202
|
MIT
| 2023-08-05T15:27:21
| 2014-12-17T16:23:00
|
C++
|
UTF-8
|
C
| false
| false
| 456
|
h
|
nanopolish_vcf2fasta.h
|
//---------------------------------------------------------
// Copyright 2018 Ontario Institute for Cancer Research
// Written by Jared Simpson (jared.simpson@oicr.on.ca)
//---------------------------------------------------------
//
// nanopolish_vcf2fasta - write a new genome sequence
// by introducing variants from a set of vcf files
//
#ifndef NANOPOLISH_VCF2FASTA_H
#define NANOPOLISH_VCF2FASTA_H
int vcf2fasta_main(int argc, char** argv);
#endif
|
79a8ea85873446028dc4299cb21eaa64a18535f7
|
ff477a586b946c575441b6189123ab86c175e5ae
|
/htslib/bcf_sr_sort.c
|
01e98bb39797f492033ae01e55c3534569c52ea6
|
[
"MIT",
"BSD-3-Clause",
"BSD-2-Clause"
] |
permissive
|
pysam-developers/pysam
|
5552e4903106fc253869a405f4a2c068c6bd65c5
|
0663ca85739877e5dd05c0eb2512a8bcaa515b39
|
refs/heads/master
| 2023-08-16T19:10:17.566296
| 2023-08-15T10:06:59
| 2023-08-15T12:28:29
| 16,557,526
| 678
| 332
|
MIT
| 2023-09-14T10:40:22
| 2014-02-05T20:38:10
|
C
|
UTF-8
|
C
| false
| false
| 22,986
|
c
|
bcf_sr_sort.c
|
/*
Copyright (C) 2017-2021 Genome Research Ltd.
Author: Petr Danecek <pd3@sanger.ac.uk>
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.
*/
#define HTS_BUILDING_LIBRARY // Enables HTSLIB_EXPORT, see htslib/hts_defs.h
#include <config.h>
#include <assert.h>
#include <strings.h>
#include "bcf_sr_sort.h"
#include "htslib/khash_str2int.h"
#include "htslib/kbitset.h"
#define SR_REF 1
#define SR_SNP 2
#define SR_INDEL 4
#define SR_OTHER 8
#define SR_SCORE(srt,a,b) (srt)->score[((a)<<4)|(b)]
// Logical AND
static inline int kbs_logical_and(kbitset_t *bs1, kbitset_t *bs2)
{
// General case, bitsets of unequal size:
// int i, n = bs1->n < bs2->n ? bs1->n : bs2->n;
int i, n = bs1->n;
for (i=0; i<n; i++) if ( bs1->b[i] & bs2->b[i] ) return 1;
return 0;
}
// Bitwise OR, dst will be modified, src will be left unchanged
static inline void kbs_bitwise_or(kbitset_t *dst, kbitset_t *src)
{
int i;
for (i=0; i<dst->n; i++) dst->b[i] |= src->b[i];
}
static void bcf_sr_init_scores(sr_sort_t *srt)
{
int i,jbit,kbit;
// lower number = lower priority, zero means forbidden
if ( srt->pair & BCF_SR_PAIR_ANY ) srt->pair |= (BCF_SR_PAIR_SNPS | BCF_SR_PAIR_INDELS | BCF_SR_PAIR_SNP_REF | BCF_SR_PAIR_INDEL_REF);
if ( srt->pair & BCF_SR_PAIR_SNPS ) SR_SCORE(srt,SR_SNP,SR_SNP) = 3;
if ( srt->pair & BCF_SR_PAIR_INDELS ) SR_SCORE(srt,SR_INDEL,SR_INDEL) = 3;
if ( srt->pair & BCF_SR_PAIR_SNP_REF )
{
SR_SCORE(srt,SR_SNP,SR_REF) = 2;
SR_SCORE(srt,SR_REF,SR_SNP) = 2;
}
if ( srt->pair & BCF_SR_PAIR_INDEL_REF )
{
SR_SCORE(srt,SR_INDEL,SR_REF) = 2;
SR_SCORE(srt,SR_REF,SR_INDEL) = 2;
}
if ( srt->pair & BCF_SR_PAIR_ANY )
{
for (i=0; i<256; i++)
if ( !srt->score[i] ) srt->score[i] = 1;
}
// set all combinations
for (i=0; i<256; i++)
{
if ( srt->score[i] ) continue; // already set
int max = 0;
for (jbit=0; jbit<4; jbit++) // high bits
{
int j = 1<<jbit;
if ( !(i & (j<<4)) ) continue;
for (kbit=0; kbit<4; kbit++) // low bits
{
int k = 1<<kbit;
if ( !(i & k) ) continue;
if ( max < SR_SCORE(srt,j,k) ) max = SR_SCORE(srt,j,k);
}
}
srt->score[i] = max;
}
}
static int multi_is_exact(var_t *avar, var_t *bvar)
{
if ( avar->nalt != bvar->nalt ) return 0;
int alen = strlen(avar->str);
int blen = strlen(bvar->str);
if ( alen != blen ) return 0;
char *abeg = avar->str;
while ( *abeg )
{
char *aend = abeg;
while ( *aend && *aend!=',' ) aend++;
char *bbeg = bvar->str;
while ( *bbeg )
{
char *bend = bbeg;
while ( *bend && *bend!=',' ) bend++;
if ( bend - bbeg == aend - abeg && !strncasecmp(abeg,bbeg,bend-bbeg) ) break;
bbeg = *bend ? bend+1 : bend;
}
if ( !*bbeg ) return 0;
abeg = *aend ? aend+1 : aend;
}
return 1;
}
static int multi_is_subset(var_t *avar, var_t *bvar)
{
char *abeg = avar->str;
while ( *abeg )
{
char *aend = abeg;
while ( *aend && *aend!=',' ) aend++;
char *bbeg = bvar->str;
while ( *bbeg )
{
char *bend = bbeg;
while ( *bend && *bend!=',' ) bend++;
if ( bend - bbeg == aend - abeg && !strncasecmp(abeg,bbeg,bend-bbeg) ) return 1;
bbeg = *bend ? bend+1 : bend;
}
abeg = *aend ? aend+1 : aend;
}
return 0;
}
static uint32_t pairing_score(sr_sort_t *srt, int ivset, int jvset)
{
varset_t *iv = &srt->vset[ivset];
varset_t *jv = &srt->vset[jvset];
// Restrictive logic: the strictest type from a group is selected,
// so that, for example, snp+ref does not lead to the inclusion of an indel
int i,j;
uint32_t min = UINT32_MAX;
for (i=0; i<iv->nvar; i++)
{
var_t *ivar = &srt->var[iv->var[i]];
for (j=0; j<jv->nvar; j++)
{
var_t *jvar = &srt->var[jv->var[j]];
if ( srt->pair & BCF_SR_PAIR_EXACT )
{
if ( ivar->type != jvar->type ) continue;
if ( !strcmp(ivar->str,jvar->str) ) return UINT32_MAX; // exact match, best possibility
if ( multi_is_exact(ivar,jvar) ) return UINT32_MAX; // identical alleles
continue;
}
if ( ivar->type==jvar->type && !strcmp(ivar->str,jvar->str) ) return UINT32_MAX; // exact match, best possibility
if ( ivar->type & jvar->type && multi_is_subset(ivar,jvar) ) return UINT32_MAX; // one of the alleles is identical
uint32_t score = SR_SCORE(srt,ivar->type,jvar->type);
if ( !score ) return 0; // some of the varsets in the two groups are not compatible, will not pair
if ( min>score ) min = score;
}
}
if ( srt->pair & BCF_SR_PAIR_EXACT ) return 0;
assert( min!=UINT32_MAX );
uint32_t cnt = 0;
for (i=0; i<iv->nvar; i++) cnt += srt->var[iv->var[i]].nvcf;
for (j=0; j<jv->nvar; j++) cnt += srt->var[jv->var[j]].nvcf;
return (1u<<(28+min)) + cnt;
}
static void remove_vset(sr_sort_t *srt, int jvset)
{
if ( jvset+1 < srt->nvset )
{
varset_t tmp = srt->vset[jvset];
memmove(&srt->vset[jvset], &srt->vset[jvset+1], sizeof(varset_t)*(srt->nvset - jvset - 1));
srt->vset[srt->nvset-1] = tmp;
int *jmat = srt->pmat + jvset*srt->ngrp;
memmove(jmat, &jmat[srt->ngrp],sizeof(int)*(srt->nvset - jvset - 1)*srt->ngrp);
memmove(&srt->cnt[jvset], &srt->cnt[jvset+1], sizeof(int)*(srt->nvset - jvset - 1));
}
srt->nvset--;
}
static int merge_vsets(sr_sort_t *srt, int ivset, int jvset)
{
int i,j;
if ( ivset > jvset ) { i = ivset; ivset = jvset; jvset = i; }
varset_t *iv = &srt->vset[ivset];
varset_t *jv = &srt->vset[jvset];
kbs_bitwise_or(iv->mask,jv->mask);
i = iv->nvar;
iv->nvar += jv->nvar;
hts_expand(int, iv->nvar, iv->mvar, iv->var);
for (j=0; j<jv->nvar; j++,i++) iv->var[i] = jv->var[j];
int *imat = srt->pmat + ivset*srt->ngrp;
int *jmat = srt->pmat + jvset*srt->ngrp;
for (i=0; i<srt->ngrp; i++) imat[i] += jmat[i];
srt->cnt[ivset] += srt->cnt[jvset];
remove_vset(srt, jvset);
return ivset;
}
static int push_vset(sr_sort_t *srt, int ivset)
{
varset_t *iv = &srt->vset[ivset];
int i,j;
for (i=0; i<srt->sr->nreaders; i++)
{
vcf_buf_t *buf = &srt->vcf_buf[i];
buf->nrec++;
hts_expand(bcf1_t*,buf->nrec,buf->mrec,buf->rec);
buf->rec[buf->nrec-1] = NULL;
}
for (i=0; i<iv->nvar; i++)
{
var_t *var = &srt->var[ iv->var[i] ];
for (j=0; j<var->nvcf; j++)
{
int jvcf = var->vcf[j];
vcf_buf_t *buf = &srt->vcf_buf[jvcf];
buf->rec[buf->nrec-1] = var->rec[j];
}
}
remove_vset(srt, ivset);
return 0; // FIXME: check for errs in this function
}
static int cmpstringp(const void *p1, const void *p2)
{
return strcmp(* (char * const *) p1, * (char * const *) p2);
}
#define DEBUG_VSETS 0
#if DEBUG_VSETS
void debug_vsets(sr_sort_t *srt)
{
int i,j,k;
for (i=0; i<srt->nvset; i++)
{
fprintf(stderr,"dbg_vset %d:", i);
for (j=0; j<srt->vset[i].mask->n; j++) fprintf(stderr,"%c%lu",j==0?' ':':',srt->vset[i].mask->b[j]);
fprintf(stderr,"\t");
for (j=0; j<srt->vset[i].nvar; j++)
{
var_t *var = &srt->var[srt->vset[i].var[j]];
fprintf(stderr,"\t%s",var->str);
for (k=0; k<var->nvcf; k++)
fprintf(stderr,"%c%d", k==0?':':',',var->vcf[k]);
}
fprintf(stderr,"\n");
}
}
#endif
#define DEBUG_VBUF 0
#if DEBUG_VBUF
void debug_vbuf(sr_sort_t *srt)
{
int i, j;
for (j=0; j<srt->vcf_buf[0].nrec; j++)
{
fprintf(stderr,"dbg_vbuf %d:\t", j);
for (i=0; i<srt->sr->nreaders; i++)
{
vcf_buf_t *buf = &srt->vcf_buf[i];
fprintf(stderr,"\t%"PRIhts_pos, buf->rec[j] ? buf->rec[j]->pos+1 : 0);
}
fprintf(stderr,"\n");
}
}
#endif
static char *grp_create_key(sr_sort_t *srt)
{
if ( !srt->str.l ) return strdup("");
int i;
hts_expand(char*,srt->noff,srt->mcharp,srt->charp);
for (i=0; i<srt->noff; i++)
{
srt->charp[i] = srt->str.s + srt->off[i];
if ( i>0 ) srt->charp[i][-1] = 0;
}
qsort(srt->charp, srt->noff, sizeof(*srt->charp), cmpstringp);
char *ret = (char*) malloc(srt->str.l + 1), *ptr = ret;
for (i=0; i<srt->noff; i++)
{
int len = strlen(srt->charp[i]);
memcpy(ptr, srt->charp[i], len);
ptr += len + 1;
ptr[-1] = i+1==srt->noff ? 0 : ';';
}
return ret;
}
int bcf_sr_sort_set_active(sr_sort_t *srt, int idx)
{
hts_expand(int,idx+1,srt->mactive,srt->active);
srt->nactive = 1;
srt->active[srt->nactive - 1] = idx;
return 0; // FIXME: check for errs in this function
}
int bcf_sr_sort_add_active(sr_sort_t *srt, int idx)
{
hts_expand(int,idx+1,srt->mactive,srt->active);
srt->nactive++;
srt->active[srt->nactive - 1] = idx;
return 0; // FIXME: check for errs in this function
}
static int bcf_sr_sort_set(bcf_srs_t *readers, sr_sort_t *srt, const char *chr, hts_pos_t min_pos)
{
if ( !srt->grp_str2int )
{
// first time here, initialize
if ( !srt->pair )
{
if ( readers->collapse==COLLAPSE_NONE ) readers->collapse = BCF_SR_PAIR_EXACT;
bcf_sr_set_opt(readers, BCF_SR_PAIR_LOGIC, readers->collapse);
}
bcf_sr_init_scores(srt);
srt->grp_str2int = khash_str2int_init();
srt->var_str2int = khash_str2int_init();
}
int k;
khash_t(str2int) *hash;
hash = srt->grp_str2int;
for (k=0; k < kh_end(hash); k++)
if ( kh_exist(hash,k) ) free((char*)kh_key(hash,k));
hash = srt->var_str2int;
for (k=0; k < kh_end(hash); k++)
if ( kh_exist(hash,k) ) free((char*)kh_key(hash,k));
kh_clear(str2int, srt->grp_str2int);
kh_clear(str2int, srt->var_str2int);
srt->ngrp = srt->nvar = srt->nvset = 0;
grp_t grp;
memset(&grp,0,sizeof(grp_t));
// group VCFs into groups, each with a unique combination of variants in the duplicate lines
int ireader,ivar,irec,igrp,ivset,iact;
for (ireader=0; ireader<readers->nreaders; ireader++) srt->vcf_buf[ireader].nrec = 0;
for (iact=0; iact<srt->nactive; iact++)
{
ireader = srt->active[iact];
bcf_sr_t *reader = &readers->readers[ireader];
int rid = bcf_hdr_name2id(reader->header, chr);
grp.nvar = 0;
hts_expand(int,reader->nbuffer,srt->moff,srt->off);
srt->noff = 0;
srt->str.l = 0;
for (irec=1; irec<=reader->nbuffer; irec++)
{
bcf1_t *line = reader->buffer[irec];
if ( line->rid!=rid || line->pos!=min_pos ) break;
if ( srt->str.l ) kputc(';',&srt->str);
srt->off[srt->noff++] = srt->str.l;
size_t beg = srt->str.l;
int end_pos = -1;
for (ivar=1; ivar<line->n_allele; ivar++)
{
if ( ivar>1 ) kputc(',',&srt->str);
kputs(line->d.allele[0],&srt->str);
kputc('>',&srt->str);
kputs(line->d.allele[ivar],&srt->str);
// If symbolic allele, check also the END tag in case there are multiple events,
// such as <DEL>s, starting at the same positions
if ( line->d.allele[ivar][0]=='<' )
{
if ( end_pos==-1 )
{
bcf_info_t *end_info = bcf_get_info(reader->header,line,"END");
if ( end_info )
end_pos = (int)end_info->v1.i; // this is only to create a unique id, we don't mind a potential int64 overflow
else
end_pos = 0;
}
if ( end_pos )
{
kputc('/',&srt->str);
kputw(end_pos, &srt->str);
}
}
}
if ( line->n_allele==1 )
{
kputs(line->d.allele[0],&srt->str);
kputsn(">.",2,&srt->str);
}
// Create new variant or attach to existing one. But careful, there can be duplicate
// records with the same POS,REF,ALT (e.g. in dbSNP-b142)
char *var_str = beg + srt->str.s;
int ret, var_idx = 0, var_end = srt->str.l;
while ( 1 )
{
ret = khash_str2int_get(srt->var_str2int, var_str, &ivar);
if ( ret==-1 ) break;
var_t *var = &srt->var[ivar];
if ( var->vcf[var->nvcf-1] != ireader ) break;
srt->str.l = var_end;
kputw(var_idx, &srt->str);
var_str = beg + srt->str.s;
var_idx++;
}
if ( ret==-1 )
{
ivar = srt->nvar++;
hts_expand0(var_t,srt->nvar,srt->mvar,srt->var);
srt->var[ivar].nvcf = 0;
khash_str2int_set(srt->var_str2int, strdup(var_str), ivar);
free(srt->var[ivar].str); // possible left-over from the previous position
}
var_t *var = &srt->var[ivar];
var->nalt = line->n_allele - 1;
var->type = bcf_get_variant_types(line);
srt->str.s[var_end] = 0;
if ( ret==-1 )
var->str = strdup(var_str);
int mvcf = var->mvcf;
var->nvcf++;
hts_expand0(int*, var->nvcf, var->mvcf, var->vcf);
if ( mvcf != var->mvcf ) var->rec = (bcf1_t **) realloc(var->rec,sizeof(bcf1_t*)*var->mvcf);
var->vcf[var->nvcf-1] = ireader;
var->rec[var->nvcf-1] = line;
grp.nvar++;
hts_expand(var_t,grp.nvar,grp.mvar,grp.var);
grp.var[grp.nvar-1] = ivar;
}
char *grp_key = grp_create_key(srt);
int ret = khash_str2int_get(srt->grp_str2int, grp_key, &igrp);
if ( ret==-1 )
{
igrp = srt->ngrp++;
hts_expand0(grp_t, srt->ngrp, srt->mgrp, srt->grp);
free(srt->grp[igrp].var);
srt->grp[igrp] = grp;
srt->grp[igrp].key = grp_key;
khash_str2int_set(srt->grp_str2int, grp_key, igrp);
memset(&grp,0,sizeof(grp_t));
}
else
free(grp_key);
srt->grp[igrp].nvcf++;
}
free(grp.var);
// initialize bitmask - which groups is the variant present in
for (ivar=0; ivar<srt->nvar; ivar++)
{
if ( kbs_resize(&srt->var[ivar].mask, srt->ngrp) < 0 )
{
fprintf(stderr, "[%s:%d %s] kbs_resize failed\n", __FILE__,__LINE__,__func__);
exit(1);
}
kbs_clear(srt->var[ivar].mask);
}
for (igrp=0; igrp<srt->ngrp; igrp++)
{
for (ivar=0; ivar<srt->grp[igrp].nvar; ivar++)
{
int i = srt->grp[igrp].var[ivar];
kbs_insert(srt->var[i].mask, igrp);
}
}
// create the initial list of variant sets
for (ivar=0; ivar<srt->nvar; ivar++)
{
ivset = srt->nvset++;
hts_expand0(varset_t, srt->nvset, srt->mvset, srt->vset);
varset_t *vset = &srt->vset[ivset];
vset->nvar = 1;
hts_expand0(var_t, vset->nvar, vset->mvar, vset->var);
vset->var[vset->nvar-1] = ivar;
var_t *var = &srt->var[ivar];
vset->cnt = var->nvcf;
if ( kbs_resize(&vset->mask, srt->ngrp) < 0 )
{
fprintf(stderr, "[%s:%d %s] kbs_resize failed\n", __FILE__,__LINE__,__func__);
exit(1);
}
kbs_clear(vset->mask);
kbs_bitwise_or(vset->mask, var->mask);
int type = 0;
if ( var->type==VCF_REF ) type |= SR_REF;
else
{
if ( var->type & VCF_SNP ) type |= SR_SNP;
if ( var->type & VCF_MNP ) type |= SR_SNP;
if ( var->type & VCF_INDEL ) type |= SR_INDEL;
if ( var->type & VCF_OTHER ) type |= SR_OTHER;
}
var->type = type;
}
#if DEBUG_VSETS
debug_vsets(srt);
#endif
// initialize the pairing matrix
hts_expand(int, srt->ngrp*srt->nvset, srt->mpmat, srt->pmat);
hts_expand(int, srt->nvset, srt->mcnt, srt->cnt);
memset(srt->pmat, 0, sizeof(*srt->pmat)*srt->ngrp*srt->nvset);
for (ivset=0; ivset<srt->nvset; ivset++)
{
varset_t *vset = &srt->vset[ivset];
for (igrp=0; igrp<srt->ngrp; igrp++) srt->pmat[ivset*srt->ngrp+igrp] = 0;
srt->cnt[ivset] = vset->cnt;
}
// pair the lines
while ( srt->nvset )
{
#if DEBUG_VSETS
fprintf(stderr,"\n");
debug_vsets(srt);
#endif
int imax = 0;
for (ivset=1; ivset<srt->nvset; ivset++)
if ( srt->cnt[imax] < srt->cnt[ivset] ) imax = ivset;
int ipair = -1;
uint32_t max_score = 0;
for (ivset=0; ivset<srt->nvset; ivset++)
{
if ( kbs_logical_and(srt->vset[imax].mask,srt->vset[ivset].mask) ) continue; // cannot be merged
uint32_t score = pairing_score(srt, imax, ivset);
// fprintf(stderr,"score: %d %d, logic=%d \t..\t %u\n", imax,ivset,srt->pair,score);
if ( max_score < score ) { max_score = score; ipair = ivset; }
}
// merge rows creating a new variant set this way
if ( ipair!=-1 && ipair!=imax )
{
imax = merge_vsets(srt, imax, ipair);
continue;
}
push_vset(srt, imax);
}
srt->chr = chr;
srt->pos = min_pos;
return 0; // FIXME: check for errs in this function
}
int bcf_sr_sort_next(bcf_srs_t *readers, sr_sort_t *srt, const char *chr, hts_pos_t min_pos)
{
int i,j;
assert( srt->nactive>0 );
if ( srt->nsr != readers->nreaders )
{
srt->sr = readers;
if ( srt->nsr < readers->nreaders )
{
srt->vcf_buf = (vcf_buf_t*) realloc(srt->vcf_buf,readers->nreaders*sizeof(vcf_buf_t));
memset(srt->vcf_buf + srt->nsr, 0, sizeof(vcf_buf_t)*(readers->nreaders - srt->nsr));
if ( srt->msr < srt->nsr ) srt->msr = srt->nsr;
}
srt->nsr = readers->nreaders;
srt->chr = NULL;
}
if ( srt->nactive == 1 )
{
if ( readers->nreaders>1 )
memset(readers->has_line, 0, readers->nreaders*sizeof(*readers->has_line));
bcf_sr_t *reader = &readers->readers[srt->active[0]];
assert( reader->buffer[1]->pos==min_pos );
bcf1_t *tmp = reader->buffer[0];
for (j=1; j<=reader->nbuffer; j++) reader->buffer[j-1] = reader->buffer[j];
reader->buffer[ reader->nbuffer ] = tmp;
reader->nbuffer--;
readers->has_line[srt->active[0]] = 1;
return 1;
}
if ( !srt->chr || srt->pos!=min_pos || strcmp(srt->chr,chr) ) bcf_sr_sort_set(readers, srt, chr, min_pos);
if ( !srt->vcf_buf[0].nrec ) return 0;
#if DEBUG_VBUF
debug_vbuf(srt);
#endif
int nret = 0;
for (i=0; i<srt->sr->nreaders; i++)
{
vcf_buf_t *buf = &srt->vcf_buf[i];
if ( buf->rec[0] )
{
bcf_sr_t *reader = &srt->sr->readers[i];
for (j=1; j<=reader->nbuffer; j++)
if ( reader->buffer[j] == buf->rec[0] ) break;
assert( j<=reader->nbuffer );
bcf1_t *tmp = reader->buffer[0];
reader->buffer[0] = reader->buffer[j++];
for (; j<=reader->nbuffer; j++) reader->buffer[j-1] = reader->buffer[j];
reader->buffer[ reader->nbuffer ] = tmp;
reader->nbuffer--;
nret++;
srt->sr->has_line[i] = 1;
}
else
srt->sr->has_line[i] = 0;
buf->nrec--;
if ( buf->nrec > 0 )
memmove(buf->rec, &buf->rec[1], buf->nrec*sizeof(bcf1_t*));
}
return nret;
}
void bcf_sr_sort_remove_reader(bcf_srs_t *readers, sr_sort_t *srt, int i)
{
//vcf_buf is allocated only in bcf_sr_sort_next
//So, a call to bcf_sr_add_reader() followed immediately by bcf_sr_remove_reader()
//would cause the program to crash in this segment
if (srt->vcf_buf)
{
free(srt->vcf_buf[i].rec);
if ( i+1 < srt->nsr )
memmove(&srt->vcf_buf[i], &srt->vcf_buf[i+1], (srt->nsr - i - 1)*sizeof(vcf_buf_t));
memset(srt->vcf_buf + srt->nsr - 1, 0, sizeof(vcf_buf_t));
}
}
sr_sort_t *bcf_sr_sort_init(sr_sort_t *srt)
{
if ( !srt ) return calloc(1,sizeof(sr_sort_t));
memset(srt,0,sizeof(sr_sort_t));
return srt;
}
void bcf_sr_sort_reset(sr_sort_t *srt)
{
srt->chr = NULL;
}
void bcf_sr_sort_destroy(sr_sort_t *srt)
{
free(srt->active);
if ( srt->var_str2int ) khash_str2int_destroy_free(srt->var_str2int);
if ( srt->grp_str2int ) khash_str2int_destroy_free(srt->grp_str2int);
int i;
for (i=0; i<srt->nsr; i++) free(srt->vcf_buf[i].rec);
free(srt->vcf_buf);
for (i=0; i<srt->mvar; i++)
{
free(srt->var[i].str);
free(srt->var[i].vcf);
free(srt->var[i].rec);
kbs_destroy(srt->var[i].mask);
}
free(srt->var);
for (i=0; i<srt->mgrp; i++)
free(srt->grp[i].var);
free(srt->grp);
for (i=0; i<srt->mvset; i++)
{
kbs_destroy(srt->vset[i].mask);
free(srt->vset[i].var);
}
free(srt->vset);
free(srt->str.s);
free(srt->off);
free(srt->charp);
free(srt->cnt);
free(srt->pmat);
memset(srt,0,sizeof(*srt));
}
|
12ddd98f7f54d3cc265c7da3c1afd5fec7fc77ef
|
efe37ebcbadc6dda488f321f59b34b3a8f918960
|
/tools/gfx2snes/gfx2snes.c
|
2d0b748a176854bca40f8d01e82ea97809e7faa5
|
[
"MIT"
] |
permissive
|
alekmaul/pvsneslib
|
83fd163e1fdca6a4ce7bc49b5562cb7e49a021df
|
69203c23f3e0c0f8a61e9452819f8690aefa476b
|
refs/heads/master
| 2023-08-31T21:09:17.036094
| 2023-08-26T06:21:28
| 2023-08-26T06:21:28
| 32,628,824
| 673
| 83
| null | 2023-09-06T04:23:42
| 2015-03-21T10:49:52
|
C
|
UTF-8
|
C
| false
| false
| 21,993
|
c
|
gfx2snes.c
|
/*---------------------------------------------------------------------------------
Copyright (C) 2012-2022
Alekmaul
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any
damages arising from the use of this software.
Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you
must not claim that you wrote the original software. If you use
this software in a product, an acknowledgment in the product
documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
Image converter for snes.
Parts from pcx2snes from Neviksti
palette rounded option from Artemio Urbina
BMP BI_RLE8 compression support by Andrey Beletsky
***************************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <memory.h>
#include <string.h>
#include "gfx2snes.h"
#include "imgtools.h"
#include "lodepng.h"
#include "loadimg.h"
#define RED_ERROR "\e[0;31merror\e[0m" // ANSI color codes for more noticeable errors
int border=1; // options and their defaults
int packed=0; //
int size=0; //
int screen=0; //
int colors=0; //
int output_palette=-1; //
int rearrange=0; //
int palette_entry=0; //
int file_type=1; // 1 = bmp, 2 = pcx, 3 = tga, 4 = png
int quietmode=0; // 0 = not quiet, 1 = i can't say anything :P
int collision=0; // 1 = generated only collision map
int collisionsp=0; // n = 1st sprite entry regarding the map (so remove it from collision map)
int tile_reduction=1; // 0 = no tile reduction (warning !)
int savepalette=1; // 1 = save the palette
int savemap=1; // 1 = save the map
int colortabinc=16; // 16 for 16 color mode, 4 for 4 color mode
int lzpacked=0; // 1 = compress file with LZSS algorithm
int highpriority=0; // 1 = high priority for map
int blanktile=0; // 1 = blank tile generated
int palette_rnd=0; // 1 = round palette up & down
int offset_tile=0; // n = offset in tile number
int pagemap32 = 0; // 1 = create tile maps organized in 32x32 pages
int hi512 = 0; // 1 = create a 512 width map for mode 5 & 6
pcx_picture image; // file with image to convert
char filebase[256]; // name of output file
char filename[256+4]; // use to manage filenames
//////////////////////////////////////////////////////////////////////////////
void PutWord(int data, FILE *fp)
{
putc(LOW_BYTE(data),fp);
putc(HI_BYTE(data),fp);
} //end of PutWord
//////////////////////////////////////////////////////////////////////////////
int LoadPicture(void)
{
if (filebase[strlen(filebase)-4] == '.')
{
filebase[strlen(filebase)-4] = '\0';
}
switch (file_type) {
case 2 : // PCX
sprintf(filename,"%s.pcx",filebase);
if (quietmode == 0)
printf("\ngfx2snes: 'Opening graphics file: [%s]'",filename);
if(!PCX_Load(filename,(pcx_picture_ptr) &image))
return 1;
break;
case 3 : // TGA
sprintf(filename,"%s.tga",filebase);
if (quietmode == 0)
printf("\ngfx2snes: 'Opening graphics file: [%s]'",filename);
if(!TGA_Load(filename,(pcx_picture_ptr) &image))
return 1;
break;
case 4 : // PNG
sprintf(filename,"%s.png",filebase);
if (quietmode == 0)
printf("\ngfx2snes: 'Opening graphics file: [%s]'",filename);
if(!PNG_Load(filename,(pcx_picture_ptr) &image))
return 1;
break;
default : // BMP for everything else
sprintf(filename,"%s.bmp",filebase);
if (quietmode == 0)
printf("\ngfx2snes: 'Opening graphics file: [%s]'",filename);
if(!BMP_Load(filename,(pcx_picture_ptr) &image))
return 1;
break;
}
return 0;
}
//////////////////////////////////////////////////////////////////////////////
void PrintOptions(char *str)
{
printf("\n\nUsage : gfx2snes [options] bmp/pcx/tga filename ...");
printf("\n where filename is a 256 color PNG, BMP, PCX or TGA file");
if(str[0]!=0)
printf("\ngfx2snes: %s 'The [%s] parameter is not recognized'", RED_ERROR, str);
printf("\n\nOptions are:");
printf("\n\n--- Graphics options ---");
printf("\n-gb add blank tile management (for multiple bgs)");
printf("\n-gp Output in packed pixel format");
printf("\n-glz Output in lz77 compressed pixel format");
printf("\n-gs(8|16|32|64) Size of image blocks in pixels [8]");
printf("\n\n--- Map options ---");
printf("\n-m! Exclude map from output");
printf("\n-m Convert the whole picture");
printf("\n-mp Convert the whole picture with high priority");
printf("\n-m7 Convert the whole picture for mode 7 format");
printf("\n-m5 Convert the whole picture for mode 5 & 6 512 width hires");
printf("\n-mc Generate collision map only");
printf("\n-ms# Generate collision map only with sprites table");
printf("\n where # is the 1st tile corresponding to a sprite (0 to 255)");
printf("\n-mn# Generate the whole picture with an offset for tile number");
printf("\n where # is the offset in decimal (0 to 2047)");
printf("\n-mR! No tile reduction (not advised)");
printf("\n-m32p Generate tile map organized in pages of 32x32 (good for scrolling)");
printf("\n-me Convert the map for PVSneslib map engine");
printf("\n\n--- Palette options ---");
printf("\n-p! Exclude palette from output.");
printf("\n-pc(4|16|128|256) The number of colors to use [256]");
printf("\n-po# The number of colors to output (0 to 256) to the filename.pal");
printf("\n-pe# The palette entry to add to map tiles (0 to 16)");
printf("\n-pr Rearrange palette, and preserve palette numbers in the tilemap");
printf("\n-pR Palette rounding");
printf("\n\n--- File options ---");
printf("\n-f[bmp|pcx|tga|png] convert a bmp or pcx or tga or png file [bmp]");
printf("\n\n--- Misc options ---");
printf("\n-n no border");
printf("\n-q quiet mode");
printf("\n-v Display gfx2snes version information");
printf("\n");
} //end of PrintOptions()
//////////////////////////////////////////////////////////////////////////////
void PrintVersion(void)
{
printf("gfx2snes ("GFX2SNESVERSION") version "GFX2SNESDATE"");
printf("\nCopyright (c) 2013-2021 Alekmaul");
printf("\nBased on pcx2snes by Neviksti\n");
}
/// M A I N ////////////////////////////////////////////////////////////
int main(int argc, char **arg)
{
int palette[256];
int tile_x, tile_y;
unsigned char clr;
int height, width;
int xsize, ysize;
int num_tiles;
int blank_absent=0;
unsigned char *buffer;
unsigned char *temp;
int *tilemap;
int tileobj[MAXTILES];
FILE *fp;
int i, j;
// init all filenames
strcpy(filebase,"");
strcpy(filename,"");
// init all buffers
buffer=NULL;
//parse the arguments
for(i=1;i<argc;i++)
{
if(arg[i][0]=='-')
{
if(arg[i][1]=='g') // graphics options
{
if( strcmp(&arg[i][1],"gb") == 0) // blank tile
{
blanktile=1;
}
else if( strcmp(&arg[i][1],"gp") == 0) //packed pixels
{
packed=1;
}
else if( strcmp(&arg[i][1],"glz") == 0) // lzss compressed pixels
{
lzpacked=1;
}
else if(arg[i][2]=='s') //size specification
{
size=atoi(&arg[i][3]);
if( (size != 8) && (size !=16) && (size != 32) && (size != 64) )
{
PrintOptions(arg[i]);
return 1;
}
}
}
else if(arg[i][1]=='n') //no border
{
border=0;
}
else if(arg[i][1]=='q') //quiet mode
{
quietmode=1;
}
else if(arg[i][1]=='m') //map options
{
if( strcmp(&arg[i][1],"m") == 0)
{
screen=1;
border=0;
}
else if( strcmp(&arg[i][1],"mp") == 0)
{
screen=1;
border=0;
highpriority=1;
}
else if( strcmp(&arg[i][1],"m!") == 0)
{
screen=1;
border=0;
savemap=0;
}
else if( strcmp(&arg[i][1],"m7") == 0)
{
screen=7;
border=0;
packed=1;
}
else if( strcmp(&arg[i][1],"m5") == 0)
{
screen=1;
border=0;
hi512=1;
}
else if( strcmp(&arg[i][1],"mc") == 0)
{
screen=1;
border=0;
collision=1;
}
else if(arg[i][2]=='s') //sprite entry location
{
screen=1;
border=0;
collision=2;
collisionsp = atoi(&arg[i][3]);
}
else if(arg[i][2]=='n') //offset for tiles
{
offset_tile = atoi(&arg[i][3]);
}
else if( strcmp(&arg[i][1],"mR!") == 0)
{
tile_reduction=0;
}
else if( strcmp(&arg[i][1],"m32p") == 0)
{
screen=1;
border=0;
pagemap32 = 1;
}
else
{
PrintOptions(arg[i]);
return 1;
}
}
else if(arg[i][1]=='p') //palette options
{
if(arg[i][2]=='c') //color number specification
{
colors=atoi(&arg[i][3]);
if( (colors != 4) && (colors !=16) && (colors !=32) && (colors != 128) && (colors != 256) )
{
PrintOptions(arg[i]);
return 1;
}
if (colors == 4)
colortabinc = 4;
}
else if(arg[i][2]=='o') //color number specification
{
output_palette=atoi(&arg[i][3]);
if( (output_palette < 0) || (output_palette > 256) )
{
PrintOptions(arg[i]);
return 1;
}
}
else if( strcmp(&arg[i][1],"pr") == 0) //re-arrange palette option
{
rearrange=1;
}
else if( strcmp(&arg[i][1],"p!") == 0) //re-arrange palette option
{
savepalette=0;
}
else if( strcmp(&arg[i][1],"pR") == 0)
{
palette_rnd=1;
}
else if(arg[i][2]=='e') //palette entry specification
{
palette_entry=atoi(&arg[i][3]);
if( (palette_entry < 0) || (palette_entry > 16 ) )
{
PrintOptions(arg[i]);
return 1;
}
}
}
else if (arg[i][1]=='f') //file type specification
{
if( strcmp(&arg[i][1],"fpcx") == 0)
{
file_type = 2; // PCX,
}
else if( strcmp(&arg[i][1],"ftga") == 0)
{
file_type = 3; // TGA
}
else if( strcmp(&arg[i][1],"fpng") == 0)
{
file_type = 4; // PNG, evething else is bmp
}
}
else if (arg[i][1]=='v') //version information
{
PrintVersion();
return 0;
}
else //invalid option
{
PrintOptions(arg[i]);
return 1;
}
}
else
{
//its not an option flag, so it must be the filebase
if(filebase[0]!=0) // if already defined... there's a problem
{
PrintOptions(arg[i]);
return 1;
}
else
strcpy(filebase,arg[i]);
}
}
//make sure options are valid
if((colors==0) && screen)
colors=256;
if( filebase[0] == 0 )
{
printf("\ngfx2snes: %s 'You must specify a base filename'", RED_ERROR);
PrintOptions("");
return 1;
}
if( colors == 0 )
{
printf("\ngfx2snes: %s 'The Number of Colors parameter must be specified'", RED_ERROR);
PrintOptions("");
return 1;
}
if((size == 0) && (border == 0) && (screen == 0))
{
printf("\ngfx2snes: %s 'The Size parameter must be specified when the border is turned off'", RED_ERROR);
PrintOptions("");
return 1;
}
if(rearrange)
{
//let i = the number of colors in all 8 palettes
i = colors*8;
if(i>256)
i=256;
if((colors == 256) || (colors == 128))
{
printf("\n***gfx2snes: WARNING '-c128 and -c256 override the -r option. The palette will not be rearranged'");
rearrange=0;
}
if(screen == 0)
{
printf("\n***gfx2snes: warning 'the -r option means nothing in image block mode. The palette will not be rearranged'");
rearrange=0;
}
else if((output_palette != i) && (output_palette != -1))
{
printf("\n***gfx2snes: warning '-o# is not over-riden, but because -r was selected, anything other than the 8 palettes won't mean much after all the colors are re-arranged'");
}
else
output_palette=i;
}
if(output_palette==-1)
output_palette=256;
//Load picture
if (LoadPicture())
{
return 1;
}
else
{
//convert the palette
ConvertPalette(image.palette, palette);
height = image.header.height;
width = image.header.width;
}
// go out if size if not multiple of 8
if ( ((width%8) != 0) || ((height%8) !=0) )
{
printf("\ngfx2snes: error 'size %d x %d is not a multiple of 8 pixels for width or height.'\n",width,height);
return 1;
}
//autodetect size if necessary
if((size == 0) && (screen == 0))
{
if (quietmode == 0)
printf("\ngfx2snes: %s 'Auto-detecting size of image blocks...'", RED_ERROR);
clr = image.buffer[0]; //get the border color
for(i=1; i<width; i++)
if(image.buffer[i]!=clr)
break;
xsize = i-1; //if size = n, then xsize = multiple of (n+1)
for(i=1; i<height; i++)
if(image.buffer[i*width]!=clr)
break;
ysize = i-1; //if size = n, then xsize = multiple of (n+1)
//look along line 1 until we hit the border color
//this should be the end of the first image block
for(i=1; i<width; i++)
if(image.buffer[i + width]==clr)
break;
size = i-1;
if( (xsize%(size+1) != 0 ) || (ysize%(size+1) != 0 ) )
{
printf("\ngfx2snes: %s 'Border format is incorrect... autodetect size failed.'\n", RED_ERROR);
return 1;
}
xsize = xsize/(size+1); //the number of blocks across
ysize = ysize/(size+1); //the number of blocks down
}
else
{
//determine the constants if in screen mode
//or image block mode with no borders
if (screen) {
size=8;
// Get out if hires and not 512 width
if( (hi512) && (width != 512) )
{
printf("\ngfx2snes: %s 'EHiRes mode 5 format is not 512 pixels width.'\n", RED_ERROR);
return 1;
}
}
xsize = width/size;
if (width%size)
xsize++;
ysize = height/size;
if (height%size)
ysize++;
}
//if its a full screen, determine the number of tiles
tile_x=tile_y=32; // default value
if(screen)
{
//ALEK 09/08 if(width>256)
//tile_x=64;
//ALEK 01/11/18 tile_x=width/8;
tile_x=width/size;
if (hi512)
tile_x>>=1;
//ALEK 09/08 else
//ALEK 09/08 tile_x=32;
//ALEK 09/08 if(height>256)
//tile_y=64;
tile_y=height/8;
//ALEK 09/08 else
//ALEK 09/08 tile_y=32;
if(screen==7)
{
tile_x=128;
tile_y=128;
}
}
//Print what the user has selected
if (quietmode == 0) {
printf("\ngfx2snes: ("GFX2SNESVERSION") version "GFX2SNESDATE"");
printf("\ngfx2snes: ****** O P T I O N S ***************");
printf(border ? "\ngfx2snes: border=ON" : "'\ngfx2snes: border=OFF");
printf(highpriority ? "\ngfx2snes: highpriority=ON" : "\ngfx2snes: highpriority=OFF");
printf(blanktile ? "\ngfx2snes: blanktile=ON" : "\ngfx2snes: blanktile=OFF");
printf(collision ? "\ngfx2snes: collisionmap=ON" : "\ngfx2snes: collisionmap=OFF");
printf(pagemap32 ? "\ngfx2snes: tile map pages of 32x32=ON" : "\ngfx2snes: tile map pages of 32x32=OFF");
printf(hi512 ? "\ngfx2snes: tile map mode 512=ON" : "\ngfx2snes: tile map mode 512=OFF");
printf(tile_reduction ? "\ngfx2snes: Optimize tilemap=ON" : "\ngfx2snes: Optimize tilemap=OFF");
printf(lzpacked ? "\ngfx2snes: LZSS compression=ON" : "\ngfx2snes: LZSS compression=OFF");
printf(packed ? "\ngfx2snes: pixel format=packed-bit" : "\ngfx2snes: pixel format=bit-plane");
if (file_type == 2)
printf("\ngfx2snes: 'PCX file: %dx%d pixels'",width,height);
else if (file_type == 3)
printf("\ngfx2snes: TGA file: %dx%d pixels",width,height);
else if (file_type == 4)
printf("\ngfx2snes: PNG file: %dx%d pixels",width,height);
else
printf("\ngfx2snes: BMP file: %dx%d pixels",width,height);
if(screen)
{
printf("\ngfx2snes: Screen mode selected: %dx%d tile map",tile_x,tile_y);
printf(rearrange ? "\ngfx2snes: Palette rearrange: ON" : "\ngfx2snes: Palette rearrange: OFF");
}
else
{
printf("\ngfx2snes: Image mode selected: %dx%d pixel blocks",size,size);
printf("\ngfx2snes: image has: %dx%d blocks",xsize,ysize);
}
printf("\ngfx2snes: Total colors = %d", colors);
if(output_palette)
printf("\ngfx2snes: Palette section to convert: Color #0 to %d", output_palette-1);
if(palette_entry)
printf("\ngfx2snes: Palette entry to be for map tiles: Entry#%d", palette_entry);
printf("\ngfx2snes: ************************************");
}
//truncate the colors if necessary
if(colors == 128)
{
j = colors - 1; //color truncation mask
temp = image.buffer;
for(i=0;i<width*height;i++)
temp[i] = temp[i] & j;
}
//arrange the blocks according to how we would like them represented.
tilemap=NULL;
memset(tileobj,0x00,sizeof(tileobj));
if(screen)
{
j=xsize;
num_tiles=ysize;
//first arrange into a list of 8x8 blocks
buffer=ArrangeBlocks(image.buffer, width, height, size, &j, &num_tiles, (hi512 ? 16 : 8), 0);
free(image.buffer);
if(buffer==NULL)
{
printf("\ngfx2snes: %s 'Not enough memory to do image operations...'\n", RED_ERROR);
return 1;
}
//if re-arranging is wanted, attempt it now
if(rearrange)
{
if(!RearrangePalette(buffer, palette, num_tiles, colors))
{
free(buffer);
return 1;
}
}
//make the tile map now
tilemap=MakeMap(buffer, &num_tiles, (int *) &tileobj, xsize, ysize, tile_x, tile_y, colors, rearrange, palette_entry);
if(tilemap==NULL)
{
free(buffer);
printf("\ngfx2snes: %s 'Not enough memory to do tile map optimizations...'\n", RED_ERROR);
return 1;
}
if(num_tiles<0)
{
num_tiles = -num_tiles;
blank_absent = 1;
}
if((screen == 7) && (num_tiles+blank_absent)>256)
{
printf("\ngfx2snes: %s 'Need %d tiles to represent the screen in mode7. SNES only has room for 256 tiles'", RED_ERROR, num_tiles+blank_absent);
free(tilemap);
return 1;
}
if (quietmode == 0) {
if (tile_reduction)
printf("\ngfx2snes: 'Reduced screen to %d tiles'",num_tiles+blank_absent);
else
printf("\ngfx2snes: 'Computed screen with %d tiles'",num_tiles+blank_absent);
}
}
else //image block mode
{
//first arrange in SNES image block format
buffer=ArrangeBlocks(image.buffer, width, height, size, &xsize, &ysize, 16*8, border);
free(image.buffer);
if(buffer==NULL)
{
printf("\ngfx2snes: %s 'Not enough memory to do image operations...'\n", RED_ERROR);
return 1;
}
//now re-arrange into a list of 8x8 blocks for easy conversion
xsize *= size/8;
ysize *= size/8;
temp=ArrangeBlocks(buffer, xsize*8, ysize*8, 8, &xsize, &ysize, 8, 0);
free(buffer);
if(temp==NULL)
{
printf("\ngfx2snes: %s 'Not enough memory to do image operations...'\n", RED_ERROR);
return 1;
}
buffer=temp;
num_tiles=xsize*ysize;
}
//convert pictures and save to file
if (collision == 0)
{
if(!Convert2Pic(filebase, buffer, num_tiles, blank_absent, colors, packed, lzpacked))
{
if(screen)
{
free(tilemap);
}
free(buffer);
return 1;
}
}
//free up image memory
free(buffer);
//save the map
if ( (screen) && (savemap))
{
if(screen==7)
sprintf(filename,"%s.mp7",filebase);
else {
if (collision >= 1)
sprintf(filename,"%s.clm",filebase);
else
sprintf(filename,"%s.map",filebase);
}
if (quietmode == 0)
printf("\ngfx2snes: 'Saving tile map file: [%s]'",filename);
fp = fopen(filename,"wb");
if(fp==NULL)
{
printf("\ngfx2snes: %s 'Can't open file [%s] for writing'\n", RED_ERROR, filename);
free(tilemap);
return 1;
}
// Little warning for more than one bank
if ( (tile_x*tile_y*2) >=32768)
{
printf("\ngfx2snes: WARNING 'Map is too big for 1 32KB bank (%d)'\n",tile_x*tile_y);
}
// add all the tiles
for(i=0;i<tile_x*tile_y;i++)
{
if(screen==7)
fputc(tilemap[i]+offset_tile,fp);
else {
if (collision == 2) {
if (tilemap[i]<collisionsp) PutWord(tilemap[i]+offset_tile,fp); else PutWord(0+offset_tile,fp);
}
else PutWord((tilemap[i]+offset_tile) | (highpriority<<13),fp);
}
}
fclose(fp);
// save the sprite table if needed
if (collision == 2) {
sprintf(filename,"%s.spr",filebase);
if (quietmode == 0)
printf("\ngfx2snes: 'Saving sprite table for map file: [%s]'",filename);
fp = fopen(filename,"wb");
if(fp==NULL)
{
printf("\ngfx2snes: %s Can't open file [%s] for writing'\n", RED_ERROR, filename);
free(tilemap);
return 1;
}
for(i=0;i<tile_x*tile_y;i++)
{
if (tilemap[i]>=collisionsp) {
//printf("\ni=%d tile_x=%d collision=%d %d %d\n",i,tile_x,i % tile_x, i / tile_x,tilemap[i]);
PutWord(tilemap[i],fp); // Entry
PutWord(i % tile_x,fp); // x coordinate
PutWord(i / tile_x,fp); // y coordinate
}
}
fclose(fp);
}
//free up tilemap memory
free(tilemap);
}
//convert and save the palette if necessary
if ((output_palette) && (collision == 0) && (savepalette))
{
sprintf(filename,"%s.pal",filebase);
if (quietmode == 0)
printf("\ngfx2snes: 'Saving palette file: [%s]'",filename);
fp = fopen(filename,"wb");
if(fp==NULL)
{
printf("\ngfx2snes: %s 'Can't open file [%s] for writing'\n", RED_ERROR, filename);
return 0;
}
for(i=0;i<output_palette;i++)
PutWord(palette[i],fp);
fclose(fp);
}
if (quietmode == 0)
printf("\ngfx2snes: 'Done !'\n\n");
return 0;
}
|
6d0e6df44a01bc12ad69751067a963e0f3708c69
|
60e96ca65710f36b79c8e080abec8750ced7e6a0
|
/platform/example/functions/_PDCLIB/_PDCLIB_changemode.c
|
0a0cf58b33dc085fb440296c311df56a6a8f719b
|
[
"LicenseRef-scancode-public-domain",
"CC0-1.0"
] |
permissive
|
DevSolar/pdclib
|
9301c5411942266bfbb3e8eb22cf8357365a67f5
|
7d471427fa986a9f4cafb069af17821ee7868141
|
refs/heads/master
| 2022-04-26T23:16:41.517901
| 2022-03-28T08:05:43
| 2022-03-28T08:05:43
| 138,836,991
| 203
| 37
|
NOASSERTION
| 2021-04-14T15:51:24
| 2018-06-27T06:07:39
|
C
|
UTF-8
|
C
| false
| false
| 2,228
|
c
|
_PDCLIB_changemode.c
|
/* _PDCLIB_changemode( FILE * stream, int mode )
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
/* This is a utility function used by freopen, to allow for a rather
specific bit of trickery.
ISO/IEC 9899:2011 (i.e., the ISO C standard) is ambiguous in the case
of the filename argument being NULL. It states that the mode of the
open stream could be _changed_ in implementation-defined circumstances.
While it goes on to state that freopen will "first attempt to close any
file that is associated with the specified stream", it is not quite
clear if the "implementation-defined circumstances" mentioned earlier
would include changing the mode without actually closing the file.
IEEE Std 1003.1, 2004 Edition (POSIX) on the other hand is less
ambiguous, as it states that "the file descriptor associated with the
stream need not be closed if the call to freopen() succeeds" for the
same case (filename being NULL).
This function gets called by PDCLib's freopen() in just that case,
allowing you to perform whatever mode changes YOUR implementation
decides to support. Return zero if the change requested is not
supported and freopen() should attempt the close-and-open-again way.
Return INT_MIN if the change request is not supported and freopen()
should fail. Return any other value if the requested mode change was
supported and successful.
*/
/* This is a dummy implementation of _PDCLIB_open() not supporting any
mode changes.
*/
#ifndef REGTEST
#include "pdclib/_PDCLIB_glue.h"
#include <limits.h>
#include <stddef.h>
int _PDCLIB_changemode( struct _PDCLIB_file_t * stream, unsigned int mode )
{
if ( mode == 0 )
{
return INT_MIN;
}
/* Attempt mode change without closing the stream */
if ( stream->filename == NULL )
{
/* Standard stream, no filename for reopen */
return INT_MIN;
}
else
{
/* Stream with file associated, attempt reopen */
return 0;
}
}
#endif
#ifdef TEST
#include "_PDCLIB_test.h"
int main( void )
{
/* No test drivers. */
return TEST_RESULTS;
}
#endif
|
aeee2c26b5d95244642b2bb378d55d008d833197
|
88ae8695987ada722184307301e221e1ba3cc2fa
|
/third_party/ffmpeg/libavcodec/cinepakenc.c
|
f15325ad0d0ad5f49ee18102d74071623b197bfc
|
[
"Apache-2.0",
"LGPL-2.0-or-later",
"MIT",
"GPL-1.0-or-later",
"BSD-3-Clause",
"LGPL-2.1-only",
"LGPL-3.0-only",
"GPL-2.0-only",
"LGPL-2.1-or-later",
"GPL-3.0-or-later",
"LGPL-3.0-or-later",
"IJG",
"LicenseRef-scancode-other-permissive",
"GPL-2.0-or-later",
"GPL-3.0-only"
] |
permissive
|
iridium-browser/iridium-browser
|
71d9c5ff76e014e6900b825f67389ab0ccd01329
|
5ee297f53dc7f8e70183031cff62f37b0f19d25f
|
refs/heads/master
| 2023-08-03T16:44:16.844552
| 2023-07-20T15:17:00
| 2023-07-23T16:09:30
| 220,016,632
| 341
| 40
|
BSD-3-Clause
| 2021-08-13T13:54:45
| 2019-11-06T14:32:31
| null |
UTF-8
|
C
| false
| false
| 49,436
|
c
|
cinepakenc.c
|
/*
* Cinepak encoder (c) 2011 Tomas Härdin
* http://titan.codemill.se/~tomhar/cinepakenc.patch
*
* Fixes and improvements, vintage decoders compatibility
* (c) 2013, 2014 Rl, Aetey Global Technologies AB
*
* 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.
*/
/*
* TODO:
* - optimize: color space conversion (move conversion to libswscale), ...
* MAYBE:
* - "optimally" split the frame into several non-regular areas
* using a separate codebook pair for each area and approximating
* the area by several rectangular strips (generally not full width ones)
* (use quadtree splitting? a simple fixed-granularity grid?)
*/
#include <string.h>
#include "libavutil/avassert.h"
#include "libavutil/common.h"
#include "libavutil/internal.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/lfg.h"
#include "libavutil/opt.h"
#include "avcodec.h"
#include "codec_internal.h"
#include "elbg.h"
#include "encode.h"
#define CVID_HEADER_SIZE 10
#define STRIP_HEADER_SIZE 12
#define CHUNK_HEADER_SIZE 4
#define MB_SIZE 4 //4x4 MBs
#define MB_AREA (MB_SIZE * MB_SIZE)
#define VECTOR_MAX 6 // six or four entries per vector depending on format
#define CODEBOOK_MAX 256 // size of a codebook
#define MAX_STRIPS 32 // Note: having fewer choices regarding the number of strips speeds up encoding (obviously)
#define MIN_STRIPS 1 // Note: having more strips speeds up encoding the frame (this is less obvious)
// MAX_STRIPS limits the maximum quality you can reach
// when you want high quality on high resolutions,
// MIN_STRIPS limits the minimum efficiently encodable bit rate
// on low resolutions
// the numbers are only used for brute force optimization for the first frame,
// for the following frames they are adaptively readjusted
// NOTE the decoder in ffmpeg has its own arbitrary limitation on the number
// of strips, currently 32
typedef enum CinepakMode {
MODE_V1_ONLY = 0,
MODE_V1_V4,
MODE_MC,
MODE_COUNT,
} CinepakMode;
typedef enum mb_encoding {
ENC_V1,
ENC_V4,
ENC_SKIP,
ENC_UNCERTAIN
} mb_encoding;
typedef struct mb_info {
int v1_vector; // index into v1 codebook
int v1_error; // error when using V1 encoding
int v4_vector[4]; // indices into v4 codebook
int v4_error; // error when using V4 encoding
int skip_error; // error when block is skipped (aka copied from last frame)
mb_encoding best_encoding; // last result from calculate_mode_score()
} mb_info;
typedef struct strip_info {
int v1_codebook[CODEBOOK_MAX * VECTOR_MAX];
int v4_codebook[CODEBOOK_MAX * VECTOR_MAX];
int v1_size;
int v4_size;
CinepakMode mode;
} strip_info;
typedef struct CinepakEncContext {
const AVClass *class;
AVCodecContext *avctx;
unsigned char *pict_bufs[4], *strip_buf, *frame_buf;
AVFrame *last_frame;
AVFrame *best_frame;
AVFrame *scratch_frame;
AVFrame *input_frame;
enum AVPixelFormat pix_fmt;
int w, h;
int frame_buf_size;
int curframe;
AVLFG randctx;
uint64_t lambda;
int *codebook_input;
int *codebook_closest;
mb_info *mb; // MB RD state
int min_strips; // the current limit
int max_strips; // the current limit
// options
int max_extra_cb_iterations;
int skip_empty_cb;
int min_min_strips;
int max_max_strips;
int strip_number_delta_range;
struct ELBGContext *elbg;
} CinepakEncContext;
#define OFFSET(x) offsetof(CinepakEncContext, x)
#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
static const AVOption options[] = {
{ "max_extra_cb_iterations", "Max extra codebook recalculation passes, more is better and slower",
OFFSET(max_extra_cb_iterations), AV_OPT_TYPE_INT, { .i64 = 2 }, 0, INT_MAX, VE },
{ "skip_empty_cb", "Avoid wasting bytes, ignore vintage MacOS decoder",
OFFSET(skip_empty_cb), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
{ "max_strips", "Limit strips/frame, vintage compatible is 1..3, otherwise the more the better",
OFFSET(max_max_strips), AV_OPT_TYPE_INT, { .i64 = 3 }, MIN_STRIPS, MAX_STRIPS, VE },
{ "min_strips", "Enforce min strips/frame, more is worse and faster, must be <= max_strips",
OFFSET(min_min_strips), AV_OPT_TYPE_INT, { .i64 = MIN_STRIPS }, MIN_STRIPS, MAX_STRIPS, VE },
{ "strip_number_adaptivity", "How fast the strip number adapts, more is slightly better, much slower",
OFFSET(strip_number_delta_range), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, MAX_STRIPS - MIN_STRIPS, VE },
{ NULL },
};
static const AVClass cinepak_class = {
.class_name = "cinepak",
.item_name = av_default_item_name,
.option = options,
.version = LIBAVUTIL_VERSION_INT,
};
static av_cold int cinepak_encode_init(AVCodecContext *avctx)
{
CinepakEncContext *s = avctx->priv_data;
int x, mb_count, strip_buf_size, frame_buf_size;
if (avctx->width & 3 || avctx->height & 3) {
av_log(avctx, AV_LOG_ERROR, "width and height must be multiples of four (got %ix%i)\n",
avctx->width, avctx->height);
return AVERROR(EINVAL);
}
if (s->min_min_strips > s->max_max_strips) {
av_log(avctx, AV_LOG_ERROR, "minimum number of strips must not exceed maximum (got %i and %i)\n",
s->min_min_strips, s->max_max_strips);
return AVERROR(EINVAL);
}
if (!(s->last_frame = av_frame_alloc()))
return AVERROR(ENOMEM);
if (!(s->best_frame = av_frame_alloc()))
return AVERROR(ENOMEM);
if (!(s->scratch_frame = av_frame_alloc()))
return AVERROR(ENOMEM);
if (avctx->pix_fmt == AV_PIX_FMT_RGB24)
if (!(s->input_frame = av_frame_alloc()))
return AVERROR(ENOMEM);
if (!(s->codebook_input = av_malloc_array((avctx->pix_fmt == AV_PIX_FMT_RGB24 ? 6 : 4) * (avctx->width * avctx->height) >> 2, sizeof(*s->codebook_input))))
return AVERROR(ENOMEM);
if (!(s->codebook_closest = av_malloc_array((avctx->width * avctx->height) >> 2, sizeof(*s->codebook_closest))))
return AVERROR(ENOMEM);
for (x = 0; x < (avctx->pix_fmt == AV_PIX_FMT_RGB24 ? 4 : 3); x++)
if (!(s->pict_bufs[x] = av_malloc((avctx->pix_fmt == AV_PIX_FMT_RGB24 ? 6 : 4) * (avctx->width * avctx->height) >> 2)))
return AVERROR(ENOMEM);
mb_count = avctx->width * avctx->height / MB_AREA;
// the largest possible chunk is 0x31 with all MBs encoded in V4 mode
// and full codebooks being replaced in INTER mode,
// which is 34 bits per MB
// and 2*256 extra flag bits per strip
strip_buf_size = STRIP_HEADER_SIZE + 3 * CHUNK_HEADER_SIZE + 2 * VECTOR_MAX * CODEBOOK_MAX + 4 * (mb_count + (mb_count + 15) / 16) + (2 * CODEBOOK_MAX) / 8;
frame_buf_size = CVID_HEADER_SIZE + s->max_max_strips * strip_buf_size;
if (!(s->strip_buf = av_malloc(strip_buf_size)))
return AVERROR(ENOMEM);
if (!(s->frame_buf = av_malloc(frame_buf_size)))
return AVERROR(ENOMEM);
if (!(s->mb = av_malloc_array(mb_count, sizeof(mb_info))))
return AVERROR(ENOMEM);
av_lfg_init(&s->randctx, 1);
s->avctx = avctx;
s->w = avctx->width;
s->h = avctx->height;
s->frame_buf_size = frame_buf_size;
s->curframe = 0;
s->pix_fmt = avctx->pix_fmt;
// set up AVFrames
s->last_frame->data[0] = s->pict_bufs[0];
s->last_frame->linesize[0] = s->w;
s->best_frame->data[0] = s->pict_bufs[1];
s->best_frame->linesize[0] = s->w;
s->scratch_frame->data[0] = s->pict_bufs[2];
s->scratch_frame->linesize[0] = s->w;
if (s->pix_fmt == AV_PIX_FMT_RGB24) {
s->last_frame->data[1] = s->last_frame->data[0] + s->w * s->h;
s->last_frame->data[2] = s->last_frame->data[1] + ((s->w * s->h) >> 2);
s->last_frame->linesize[1] =
s->last_frame->linesize[2] = s->w >> 1;
s->best_frame->data[1] = s->best_frame->data[0] + s->w * s->h;
s->best_frame->data[2] = s->best_frame->data[1] + ((s->w * s->h) >> 2);
s->best_frame->linesize[1] =
s->best_frame->linesize[2] = s->w >> 1;
s->scratch_frame->data[1] = s->scratch_frame->data[0] + s->w * s->h;
s->scratch_frame->data[2] = s->scratch_frame->data[1] + ((s->w * s->h) >> 2);
s->scratch_frame->linesize[1] =
s->scratch_frame->linesize[2] = s->w >> 1;
s->input_frame->data[0] = s->pict_bufs[3];
s->input_frame->linesize[0] = s->w;
s->input_frame->data[1] = s->input_frame->data[0] + s->w * s->h;
s->input_frame->data[2] = s->input_frame->data[1] + ((s->w * s->h) >> 2);
s->input_frame->linesize[1] =
s->input_frame->linesize[2] = s->w >> 1;
}
s->min_strips = s->min_min_strips;
s->max_strips = s->max_max_strips;
return 0;
}
static int64_t calculate_mode_score(CinepakEncContext *s, int h,
strip_info *info, int report,
int *training_set_v1_shrunk,
int *training_set_v4_shrunk)
{
// score = FF_LAMBDA_SCALE * error + lambda * bits
int x;
int entry_size = s->pix_fmt == AV_PIX_FMT_RGB24 ? 6 : 4;
int mb_count = s->w * h / MB_AREA;
mb_info *mb;
int64_t score1, score2, score3;
int64_t ret = s->lambda * ((info->v1_size ? CHUNK_HEADER_SIZE + info->v1_size * entry_size : 0) +
(info->v4_size ? CHUNK_HEADER_SIZE + info->v4_size * entry_size : 0) +
CHUNK_HEADER_SIZE) << 3;
switch (info->mode) {
case MODE_V1_ONLY:
// one byte per MB
ret += s->lambda * 8 * mb_count;
// while calculating we assume all blocks are ENC_V1
for (x = 0; x < mb_count; x++) {
mb = &s->mb[x];
ret += FF_LAMBDA_SCALE * mb->v1_error;
// this function is never called for report in MODE_V1_ONLY
// if (!report)
mb->best_encoding = ENC_V1;
}
break;
case MODE_V1_V4:
// 9 or 33 bits per MB
if (report) {
// no moves between the corresponding training sets are allowed
*training_set_v1_shrunk = *training_set_v4_shrunk = 0;
for (x = 0; x < mb_count; x++) {
int mberr;
mb = &s->mb[x];
if (mb->best_encoding == ENC_V1)
score1 = s->lambda * 9 + FF_LAMBDA_SCALE * (mberr = mb->v1_error);
else
score1 = s->lambda * 33 + FF_LAMBDA_SCALE * (mberr = mb->v4_error);
ret += score1;
}
} else { // find best mode per block
for (x = 0; x < mb_count; x++) {
mb = &s->mb[x];
score1 = s->lambda * 9 + FF_LAMBDA_SCALE * mb->v1_error;
score2 = s->lambda * 33 + FF_LAMBDA_SCALE * mb->v4_error;
if (score1 <= score2) {
ret += score1;
mb->best_encoding = ENC_V1;
} else {
ret += score2;
mb->best_encoding = ENC_V4;
}
}
}
break;
case MODE_MC:
// 1, 10 or 34 bits per MB
if (report) {
int v1_shrunk = 0, v4_shrunk = 0;
for (x = 0; x < mb_count; x++) {
mb = &s->mb[x];
// it is OK to move blocks to ENC_SKIP here
// but not to any codebook encoding!
score1 = s->lambda * 1 + FF_LAMBDA_SCALE * mb->skip_error;
if (mb->best_encoding == ENC_SKIP) {
ret += score1;
} else if (mb->best_encoding == ENC_V1) {
if ((score2 = s->lambda * 10 + FF_LAMBDA_SCALE * mb->v1_error) >= score1) {
mb->best_encoding = ENC_SKIP;
++v1_shrunk;
ret += score1;
} else {
ret += score2;
}
} else {
if ((score3 = s->lambda * 34 + FF_LAMBDA_SCALE * mb->v4_error) >= score1) {
mb->best_encoding = ENC_SKIP;
++v4_shrunk;
ret += score1;
} else {
ret += score3;
}
}
}
*training_set_v1_shrunk = v1_shrunk;
*training_set_v4_shrunk = v4_shrunk;
} else { // find best mode per block
for (x = 0; x < mb_count; x++) {
mb = &s->mb[x];
score1 = s->lambda * 1 + FF_LAMBDA_SCALE * mb->skip_error;
score2 = s->lambda * 10 + FF_LAMBDA_SCALE * mb->v1_error;
score3 = s->lambda * 34 + FF_LAMBDA_SCALE * mb->v4_error;
if (score1 <= score2 && score1 <= score3) {
ret += score1;
mb->best_encoding = ENC_SKIP;
} else if (score2 <= score3) {
ret += score2;
mb->best_encoding = ENC_V1;
} else {
ret += score3;
mb->best_encoding = ENC_V4;
}
}
}
break;
}
return ret;
}
static int write_chunk_header(unsigned char *buf, int chunk_type, int chunk_size)
{
buf[0] = chunk_type;
AV_WB24(&buf[1], chunk_size + CHUNK_HEADER_SIZE);
return CHUNK_HEADER_SIZE;
}
static int encode_codebook(CinepakEncContext *s, int *codebook, int size,
int chunk_type_yuv, int chunk_type_gray,
unsigned char *buf)
{
int x, y, ret, entry_size = s->pix_fmt == AV_PIX_FMT_RGB24 ? 6 : 4;
int incremental_codebook_replacement_mode = 0; // hardcoded here,
// the compiler should notice that this is a constant -- rl
ret = write_chunk_header(buf,
s->pix_fmt == AV_PIX_FMT_RGB24 ?
chunk_type_yuv + (incremental_codebook_replacement_mode ? 1 : 0) :
chunk_type_gray + (incremental_codebook_replacement_mode ? 1 : 0),
entry_size * size +
(incremental_codebook_replacement_mode ? (size + 31) / 32 * 4 : 0));
// we do codebook encoding according to the "intra" mode
// but we keep the "dead" code for reference in case we will want
// to use incremental codebook updates (which actually would give us
// "kind of" motion compensation, especially in 1 strip/frame case) -- rl
// (of course, the code will be not useful as-is)
if (incremental_codebook_replacement_mode) {
int flags = 0;
int flagsind;
for (x = 0; x < size; x++) {
if (flags == 0) {
flagsind = ret;
ret += 4;
flags = 0x80000000;
} else
flags = ((flags >> 1) | 0x80000000);
for (y = 0; y < entry_size; y++)
buf[ret++] = codebook[y + x * entry_size] ^ (y >= 4 ? 0x80 : 0);
if ((flags & 0xffffffff) == 0xffffffff) {
AV_WB32(&buf[flagsind], flags);
flags = 0;
}
}
if (flags)
AV_WB32(&buf[flagsind], flags);
} else
for (x = 0; x < size; x++)
for (y = 0; y < entry_size; y++)
buf[ret++] = codebook[y + x * entry_size] ^ (y >= 4 ? 0x80 : 0);
return ret;
}
// sets out to the sub picture starting at (x,y) in in
static void get_sub_picture(CinepakEncContext *s, int x, int y,
uint8_t *const in_data[4], const int in_linesize[4],
uint8_t *out_data[4], int out_linesize[4])
{
out_data[0] = in_data[0] + x + y * in_linesize[0];
out_linesize[0] = in_linesize[0];
if (s->pix_fmt == AV_PIX_FMT_RGB24) {
out_data[1] = in_data[1] + (x >> 1) + (y >> 1) * in_linesize[1];
out_linesize[1] = in_linesize[1];
out_data[2] = in_data[2] + (x >> 1) + (y >> 1) * in_linesize[2];
out_linesize[2] = in_linesize[2];
}
}
// decodes the V1 vector in mb into the 4x4 MB pointed to by data
static void decode_v1_vector(CinepakEncContext *s, uint8_t *data[4],
int linesize[4], int v1_vector, strip_info *info)
{
int entry_size = s->pix_fmt == AV_PIX_FMT_RGB24 ? 6 : 4;
data[0][0] =
data[0][1] =
data[0][ linesize[0]] =
data[0][1 + linesize[0]] = info->v1_codebook[v1_vector * entry_size];
data[0][2] =
data[0][3] =
data[0][2 + linesize[0]] =
data[0][3 + linesize[0]] = info->v1_codebook[v1_vector * entry_size + 1];
data[0][ 2 * linesize[0]] =
data[0][1 + 2 * linesize[0]] =
data[0][ 3 * linesize[0]] =
data[0][1 + 3 * linesize[0]] = info->v1_codebook[v1_vector * entry_size + 2];
data[0][2 + 2 * linesize[0]] =
data[0][3 + 2 * linesize[0]] =
data[0][2 + 3 * linesize[0]] =
data[0][3 + 3 * linesize[0]] = info->v1_codebook[v1_vector * entry_size + 3];
if (s->pix_fmt == AV_PIX_FMT_RGB24) {
data[1][0] =
data[1][1] =
data[1][ linesize[1]] =
data[1][1 + linesize[1]] = info->v1_codebook[v1_vector * entry_size + 4];
data[2][0] =
data[2][1] =
data[2][ linesize[2]] =
data[2][1 + linesize[2]] = info->v1_codebook[v1_vector * entry_size + 5];
}
}
// decodes the V4 vectors in mb into the 4x4 MB pointed to by data
static void decode_v4_vector(CinepakEncContext *s, uint8_t *data[4],
int linesize[4], int *v4_vector, strip_info *info)
{
int i, x, y, entry_size = s->pix_fmt == AV_PIX_FMT_RGB24 ? 6 : 4;
for (i = y = 0; y < 4; y += 2) {
for (x = 0; x < 4; x += 2, i++) {
data[0][x + y * linesize[0]] = info->v4_codebook[v4_vector[i] * entry_size];
data[0][x + 1 + y * linesize[0]] = info->v4_codebook[v4_vector[i] * entry_size + 1];
data[0][x + (y + 1) * linesize[0]] = info->v4_codebook[v4_vector[i] * entry_size + 2];
data[0][x + 1 + (y + 1) * linesize[0]] = info->v4_codebook[v4_vector[i] * entry_size + 3];
if (s->pix_fmt == AV_PIX_FMT_RGB24) {
data[1][(x >> 1) + (y >> 1) * linesize[1]] = info->v4_codebook[v4_vector[i] * entry_size + 4];
data[2][(x >> 1) + (y >> 1) * linesize[2]] = info->v4_codebook[v4_vector[i] * entry_size + 5];
}
}
}
}
static void copy_mb(CinepakEncContext *s,
uint8_t *a_data[4], int a_linesize[4],
uint8_t *b_data[4], int b_linesize[4])
{
int y, p;
for (y = 0; y < MB_SIZE; y++)
memcpy(a_data[0] + y * a_linesize[0], b_data[0] + y * b_linesize[0],
MB_SIZE);
if (s->pix_fmt == AV_PIX_FMT_RGB24) {
for (p = 1; p <= 2; p++)
for (y = 0; y < MB_SIZE / 2; y++)
memcpy(a_data[p] + y * a_linesize[p],
b_data[p] + y * b_linesize[p],
MB_SIZE / 2);
}
}
static int encode_mode(CinepakEncContext *s, int h,
uint8_t *scratch_data[4], int scratch_linesize[4],
uint8_t *last_data[4], int last_linesize[4],
strip_info *info, unsigned char *buf)
{
int x, y, z, bits, temp_size, header_ofs, ret = 0, mb_count = s->w * h / MB_AREA;
int needs_extra_bit, should_write_temp;
uint32_t flags;
unsigned char temp[64]; // 32/2 = 16 V4 blocks at 4 B each -> 64 B
mb_info *mb;
uint8_t *sub_scratch_data[4] = { 0 }, *sub_last_data[4] = { 0 };
int sub_scratch_linesize[4] = { 0 }, sub_last_linesize[4] = { 0 };
// encode codebooks
////// MacOS vintage decoder compatibility dictates the presence of
////// the codebook chunk even when the codebook is empty - pretty dumb...
////// and also the certain order of the codebook chunks -- rl
if (info->v4_size || !s->skip_empty_cb)
ret += encode_codebook(s, info->v4_codebook, info->v4_size, 0x20, 0x24, buf + ret);
if (info->v1_size || !s->skip_empty_cb)
ret += encode_codebook(s, info->v1_codebook, info->v1_size, 0x22, 0x26, buf + ret);
// update scratch picture
for (z = y = 0; y < h; y += MB_SIZE)
for (x = 0; x < s->w; x += MB_SIZE, z++) {
mb = &s->mb[z];
get_sub_picture(s, x, y, scratch_data, scratch_linesize,
sub_scratch_data, sub_scratch_linesize);
if (info->mode == MODE_MC && mb->best_encoding == ENC_SKIP) {
get_sub_picture(s, x, y, last_data, last_linesize,
sub_last_data, sub_last_linesize);
copy_mb(s, sub_scratch_data, sub_scratch_linesize,
sub_last_data, sub_last_linesize);
} else if (info->mode == MODE_V1_ONLY || mb->best_encoding == ENC_V1)
decode_v1_vector(s, sub_scratch_data, sub_scratch_linesize,
mb->v1_vector, info);
else
decode_v4_vector(s, sub_scratch_data, sub_scratch_linesize,
mb->v4_vector, info);
}
switch (info->mode) {
case MODE_V1_ONLY:
ret += write_chunk_header(buf + ret, 0x32, mb_count);
for (x = 0; x < mb_count; x++)
buf[ret++] = s->mb[x].v1_vector;
break;
case MODE_V1_V4:
// remember header position
header_ofs = ret;
ret += CHUNK_HEADER_SIZE;
for (x = 0; x < mb_count; x += 32) {
flags = 0;
for (y = x; y < FFMIN(x + 32, mb_count); y++)
if (s->mb[y].best_encoding == ENC_V4)
flags |= 1U << (31 - y + x);
AV_WB32(&buf[ret], flags);
ret += 4;
for (y = x; y < FFMIN(x + 32, mb_count); y++) {
mb = &s->mb[y];
if (mb->best_encoding == ENC_V1)
buf[ret++] = mb->v1_vector;
else
for (z = 0; z < 4; z++)
buf[ret++] = mb->v4_vector[z];
}
}
write_chunk_header(buf + header_ofs, 0x30, ret - header_ofs - CHUNK_HEADER_SIZE);
break;
case MODE_MC:
// remember header position
header_ofs = ret;
ret += CHUNK_HEADER_SIZE;
flags = bits = temp_size = 0;
for (x = 0; x < mb_count; x++) {
mb = &s->mb[x];
flags |= (uint32_t)(mb->best_encoding != ENC_SKIP) << (31 - bits++);
needs_extra_bit = 0;
should_write_temp = 0;
if (mb->best_encoding != ENC_SKIP) {
if (bits < 32)
flags |= (uint32_t)(mb->best_encoding == ENC_V4) << (31 - bits++);
else
needs_extra_bit = 1;
}
if (bits == 32) {
AV_WB32(&buf[ret], flags);
ret += 4;
flags = bits = 0;
if (mb->best_encoding == ENC_SKIP || needs_extra_bit) {
memcpy(&buf[ret], temp, temp_size);
ret += temp_size;
temp_size = 0;
} else
should_write_temp = 1;
}
if (needs_extra_bit) {
flags = (uint32_t)(mb->best_encoding == ENC_V4) << 31;
bits = 1;
}
if (mb->best_encoding == ENC_V1)
temp[temp_size++] = mb->v1_vector;
else if (mb->best_encoding == ENC_V4)
for (z = 0; z < 4; z++)
temp[temp_size++] = mb->v4_vector[z];
if (should_write_temp) {
memcpy(&buf[ret], temp, temp_size);
ret += temp_size;
temp_size = 0;
}
}
if (bits > 0) {
AV_WB32(&buf[ret], flags);
ret += 4;
memcpy(&buf[ret], temp, temp_size);
ret += temp_size;
}
write_chunk_header(buf + header_ofs, 0x31, ret - header_ofs - CHUNK_HEADER_SIZE);
break;
}
return ret;
}
// computes distortion of 4x4 MB in b compared to a
static int compute_mb_distortion(CinepakEncContext *s,
uint8_t *a_data[4], int a_linesize[4],
uint8_t *b_data[4], int b_linesize[4])
{
int x, y, p, d, ret = 0;
for (y = 0; y < MB_SIZE; y++)
for (x = 0; x < MB_SIZE; x++) {
d = a_data[0][x + y * a_linesize[0]] - b_data[0][x + y * b_linesize[0]];
ret += d * d;
}
if (s->pix_fmt == AV_PIX_FMT_RGB24) {
for (p = 1; p <= 2; p++) {
for (y = 0; y < MB_SIZE / 2; y++)
for (x = 0; x < MB_SIZE / 2; x++) {
d = a_data[p][x + y * a_linesize[p]] - b_data[p][x + y * b_linesize[p]];
ret += d * d;
}
}
}
return ret;
}
// return the possibly adjusted size of the codebook
#define CERTAIN(x) ((x) != ENC_UNCERTAIN)
static int quantize(CinepakEncContext *s, int h, uint8_t *data[4],
int linesize[4], int v1mode, strip_info *info,
mb_encoding encoding)
{
int x, y, i, j, k, x2, y2, x3, y3, plane, shift, mbn;
int entry_size = s->pix_fmt == AV_PIX_FMT_RGB24 ? 6 : 4;
int *codebook = v1mode ? info->v1_codebook : info->v4_codebook;
int size = v1mode ? info->v1_size : info->v4_size;
uint8_t vq_pict_buf[(MB_AREA * 3) / 2];
uint8_t *sub_data[4], *vq_data[4];
int sub_linesize[4], vq_linesize[4];
int ret;
for (mbn = i = y = 0; y < h; y += MB_SIZE) {
for (x = 0; x < s->w; x += MB_SIZE, ++mbn) {
int *base;
if (CERTAIN(encoding)) {
// use for the training only the blocks known to be to be encoded [sic:-]
if (s->mb[mbn].best_encoding != encoding)
continue;
}
base = s->codebook_input + i * entry_size;
if (v1mode) {
// subsample
for (j = y2 = 0; y2 < entry_size; y2 += 2)
for (x2 = 0; x2 < 4; x2 += 2, j++) {
plane = y2 < 4 ? 0 : 1 + (x2 >> 1);
shift = y2 < 4 ? 0 : 1;
x3 = shift ? 0 : x2;
y3 = shift ? 0 : y2;
base[j] = (data[plane][((x + x3) >> shift) + ((y + y3) >> shift) * linesize[plane]] +
data[plane][((x + x3) >> shift) + 1 + ((y + y3) >> shift) * linesize[plane]] +
data[plane][((x + x3) >> shift) + (((y + y3) >> shift) + 1) * linesize[plane]] +
data[plane][((x + x3) >> shift) + 1 + (((y + y3) >> shift) + 1) * linesize[plane]]) >> 2;
}
} else {
// copy
for (j = y2 = 0; y2 < MB_SIZE; y2 += 2) {
for (x2 = 0; x2 < MB_SIZE; x2 += 2)
for (k = 0; k < entry_size; k++, j++) {
plane = k >= 4 ? k - 3 : 0;
if (k >= 4) {
x3 = (x + x2) >> 1;
y3 = (y + y2) >> 1;
} else {
x3 = x + x2 + (k & 1);
y3 = y + y2 + (k >> 1);
}
base[j] = data[plane][x3 + y3 * linesize[plane]];
}
}
}
i += v1mode ? 1 : 4;
}
}
if (i == 0) // empty training set, nothing to do
return 0;
if (i < size)
size = i;
ret = avpriv_elbg_do(&s->elbg, s->codebook_input, entry_size, i, codebook,
size, 1, s->codebook_closest, &s->randctx, 0);
if (ret < 0)
return ret;
// set up vq_data, which contains a single MB
vq_data[0] = vq_pict_buf;
vq_linesize[0] = MB_SIZE;
vq_data[1] = &vq_pict_buf[MB_AREA];
vq_data[2] = vq_data[1] + (MB_AREA >> 2);
vq_linesize[1] =
vq_linesize[2] = MB_SIZE >> 1;
// copy indices
for (i = j = y = 0; y < h; y += MB_SIZE)
for (x = 0; x < s->w; x += MB_SIZE, j++) {
mb_info *mb = &s->mb[j];
// skip uninteresting blocks if we know their preferred encoding
if (CERTAIN(encoding) && mb->best_encoding != encoding)
continue;
// point sub_data to current MB
get_sub_picture(s, x, y, data, linesize, sub_data, sub_linesize);
if (v1mode) {
mb->v1_vector = s->codebook_closest[i];
// fill in vq_data with V1 data
decode_v1_vector(s, vq_data, vq_linesize, mb->v1_vector, info);
mb->v1_error = compute_mb_distortion(s, sub_data, sub_linesize,
vq_data, vq_linesize);
} else {
for (k = 0; k < 4; k++)
mb->v4_vector[k] = s->codebook_closest[i + k];
// fill in vq_data with V4 data
decode_v4_vector(s, vq_data, vq_linesize, mb->v4_vector, info);
mb->v4_error = compute_mb_distortion(s, sub_data, sub_linesize,
vq_data, vq_linesize);
}
i += v1mode ? 1 : 4;
}
// check that we did it right in the beginning of the function
av_assert0(i >= size); // training set is no smaller than the codebook
return size;
}
static void calculate_skip_errors(CinepakEncContext *s, int h,
uint8_t *last_data[4], int last_linesize[4],
uint8_t *data[4], int linesize[4],
strip_info *info)
{
int x, y, i;
uint8_t *sub_last_data [4], *sub_pict_data [4];
int sub_last_linesize[4], sub_pict_linesize[4];
for (i = y = 0; y < h; y += MB_SIZE)
for (x = 0; x < s->w; x += MB_SIZE, i++) {
get_sub_picture(s, x, y, last_data, last_linesize,
sub_last_data, sub_last_linesize);
get_sub_picture(s, x, y, data, linesize,
sub_pict_data, sub_pict_linesize);
s->mb[i].skip_error =
compute_mb_distortion(s,
sub_last_data, sub_last_linesize,
sub_pict_data, sub_pict_linesize);
}
}
static void write_strip_keyframe(unsigned char *buf, int keyframe)
{
// actually we are exclusively using intra strip coding (how much can we win
// otherwise? how to choose which part of a codebook to update?),
// keyframes are different only because we disallow ENC_SKIP on them -- rl
// (besides, the logic here used to be inverted: )
// buf[0] = keyframe ? 0x11: 0x10;
buf[0] = keyframe ? 0x10 : 0x11;
}
static void write_strip_header(CinepakEncContext *s, int y, int h, int keyframe,
unsigned char *buf, int strip_size)
{
write_strip_keyframe(buf, keyframe);
AV_WB24(&buf[1], strip_size + STRIP_HEADER_SIZE);
// AV_WB16(&buf[4], y); /* using absolute y values works -- rl */
AV_WB16(&buf[4], 0); /* using relative values works as well -- rl */
AV_WB16(&buf[6], 0);
// AV_WB16(&buf[8], y + h); /* using absolute y values works -- rl */
AV_WB16(&buf[8], h); /* using relative values works as well -- rl */
AV_WB16(&buf[10], s->w);
}
static int rd_strip(CinepakEncContext *s, int y, int h, int keyframe,
uint8_t *last_data[4], int last_linesize[4],
uint8_t *data[4], int linesize[4],
uint8_t *scratch_data[4], int scratch_linesize[4],
unsigned char *buf, int64_t *best_score, int *no_skip)
{
int64_t score = 0;
int best_size = 0;
strip_info info;
// for codebook optimization:
int v1enough, v1_size, v4enough, v4_size;
int new_v1_size, new_v4_size;
int v1shrunk, v4shrunk;
if (!keyframe)
calculate_skip_errors(s, h, last_data, last_linesize, data, linesize,
&info);
// try some powers of 4 for the size of the codebooks
// constraint the v4 codebook to be no bigger than v1 one,
// (and no less than v1_size/4)
// thus making v1 preferable and possibly losing small details? should be ok
#define SMALLEST_CODEBOOK 1
for (v1enough = 0, v1_size = SMALLEST_CODEBOOK; v1_size <= CODEBOOK_MAX && !v1enough; v1_size <<= 2) {
for (v4enough = 0, v4_size = 0; v4_size <= v1_size && !v4enough; v4_size = v4_size ? v4_size << 2 : v1_size >= SMALLEST_CODEBOOK << 2 ? v1_size >> 2 : SMALLEST_CODEBOOK) {
CinepakMode mode;
// try all modes
for (mode = 0; mode < MODE_COUNT; mode++) {
// don't allow MODE_MC in intra frames
if (keyframe && mode == MODE_MC)
continue;
if (mode == MODE_V1_ONLY) {
info.v1_size = v1_size;
// the size may shrink even before optimizations if the input is short:
if ((new_v1_size = quantize(s, h, data, linesize, 1,
&info, ENC_UNCERTAIN)) < 0)
return new_v1_size;
info.v1_size = new_v1_size;
if (info.v1_size < v1_size)
// too few eligible blocks, no sense in trying bigger sizes
v1enough = 1;
info.v4_size = 0;
} else { // mode != MODE_V1_ONLY
// if v4 codebook is empty then only allow V1-only mode
if (!v4_size)
continue;
if (mode == MODE_V1_V4) {
info.v4_size = v4_size;
new_v4_size = quantize(s, h, data, linesize, 0,
&info, ENC_UNCERTAIN);
if (new_v4_size < 0)
return new_v4_size;
info.v4_size = new_v4_size;
if (info.v4_size < v4_size)
// too few eligible blocks, no sense in trying bigger sizes
v4enough = 1;
}
}
info.mode = mode;
// choose the best encoding per block, based on current experience
score = calculate_mode_score(s, h, &info, 0,
&v1shrunk, &v4shrunk);
if (mode != MODE_V1_ONLY) {
int extra_iterations_limit = s->max_extra_cb_iterations;
// recompute the codebooks, omitting the extra blocks
// we assume we _may_ come here with more blocks to encode than before
info.v1_size = v1_size;
new_v1_size = quantize(s, h, data, linesize, 1, &info, ENC_V1);
if (new_v1_size < 0)
return new_v1_size;
if (new_v1_size < info.v1_size)
info.v1_size = new_v1_size;
// we assume we _may_ come here with more blocks to encode than before
info.v4_size = v4_size;
new_v4_size = quantize(s, h, data, linesize, 0, &info, ENC_V4);
if (new_v4_size < 0)
return new_v4_size;
if (new_v4_size < info.v4_size)
info.v4_size = new_v4_size;
// calculate the resulting score
// (do not move blocks to codebook encodings now, as some blocks may have
// got bigger errors despite a smaller training set - but we do not
// ever grow the training sets back)
for (;;) {
score = calculate_mode_score(s, h, &info, 1,
&v1shrunk, &v4shrunk);
// do we have a reason to reiterate? if so, have we reached the limit?
if ((!v1shrunk && !v4shrunk) || !extra_iterations_limit--)
break;
// recompute the codebooks, omitting the extra blocks
if (v1shrunk) {
info.v1_size = v1_size;
new_v1_size = quantize(s, h, data, linesize, 1, &info, ENC_V1);
if (new_v1_size < 0)
return new_v1_size;
if (new_v1_size < info.v1_size)
info.v1_size = new_v1_size;
}
if (v4shrunk) {
info.v4_size = v4_size;
new_v4_size = quantize(s, h, data, linesize, 0, &info, ENC_V4);
if (new_v4_size < 0)
return new_v4_size;
if (new_v4_size < info.v4_size)
info.v4_size = new_v4_size;
}
}
}
if (best_size == 0 || score < *best_score) {
*best_score = score;
best_size = encode_mode(s, h,
scratch_data, scratch_linesize,
last_data, last_linesize, &info,
s->strip_buf + STRIP_HEADER_SIZE);
// in theory we could have MODE_MC without ENC_SKIP,
// but MODE_V1_V4 will always be more efficient
*no_skip = info.mode != MODE_MC;
write_strip_header(s, y, h, keyframe, s->strip_buf, best_size);
}
}
}
}
best_size += STRIP_HEADER_SIZE;
memcpy(buf, s->strip_buf, best_size);
return best_size;
}
static int write_cvid_header(CinepakEncContext *s, unsigned char *buf,
int num_strips, int data_size, int isakeyframe)
{
buf[0] = isakeyframe ? 0 : 1;
AV_WB24(&buf[1], data_size + CVID_HEADER_SIZE);
AV_WB16(&buf[4], s->w);
AV_WB16(&buf[6], s->h);
AV_WB16(&buf[8], num_strips);
return CVID_HEADER_SIZE;
}
static int rd_frame(CinepakEncContext *s, const AVFrame *frame,
int isakeyframe, unsigned char *buf, int buf_size, int *got_keyframe)
{
int num_strips, strip, i, y, nexty, size, temp_size, best_size;
uint8_t *last_data [4], *data [4], *scratch_data [4];
int last_linesize[4], linesize[4], scratch_linesize[4];
int64_t best_score = 0, score, score_temp;
int best_nstrips, best_strip_offsets[MAX_STRIPS];
if (s->pix_fmt == AV_PIX_FMT_RGB24) {
int x;
// build a copy of the given frame in the correct colorspace
for (y = 0; y < s->h; y += 2)
for (x = 0; x < s->w; x += 2) {
const uint8_t *ir[2];
int32_t r, g, b, rr, gg, bb;
ir[0] = frame->data[0] + x * 3 + y * frame->linesize[0];
ir[1] = ir[0] + frame->linesize[0];
get_sub_picture(s, x, y,
s->input_frame->data, s->input_frame->linesize,
scratch_data, scratch_linesize);
r = g = b = 0;
for (i = 0; i < 4; ++i) {
int i1, i2;
i1 = (i & 1);
i2 = (i >= 2);
rr = ir[i2][i1 * 3 + 0];
gg = ir[i2][i1 * 3 + 1];
bb = ir[i2][i1 * 3 + 2];
r += rr;
g += gg;
b += bb;
// using fixed point arithmetic for portable repeatability, scaling by 2^23
// "Y"
// rr = 0.2857 * rr + 0.5714 * gg + 0.1429 * bb;
rr = (2396625 * rr + 4793251 * gg + 1198732 * bb) >> 23;
if (rr < 0)
rr = 0;
else if (rr > 255)
rr = 255;
scratch_data[0][i1 + i2 * scratch_linesize[0]] = rr;
}
// let us scale down as late as possible
// r /= 4; g /= 4; b /= 4;
// "U"
// rr = -0.1429 * r - 0.2857 * g + 0.4286 * b;
rr = (-299683 * r - 599156 * g + 898839 * b) >> 23;
if (rr < -128)
rr = -128;
else if (rr > 127)
rr = 127;
scratch_data[1][0] = rr + 128; // quantize needs unsigned
// "V"
// rr = 0.3571 * r - 0.2857 * g - 0.0714 * b;
rr = (748893 * r - 599156 * g - 149737 * b) >> 23;
if (rr < -128)
rr = -128;
else if (rr > 127)
rr = 127;
scratch_data[2][0] = rr + 128; // quantize needs unsigned
}
}
// would be nice but quite certainly incompatible with vintage players:
// support encoding zero strips (meaning skip the whole frame)
for (num_strips = s->min_strips; num_strips <= s->max_strips && num_strips <= s->h / MB_SIZE; num_strips++) {
int strip_offsets[MAX_STRIPS];
int all_no_skip = 1;
score = 0;
size = 0;
for (y = 0, strip = 1; y < s->h; strip++, y = nexty) {
int strip_height, no_skip;
strip_offsets[strip-1] = size + CVID_HEADER_SIZE;
nexty = strip * s->h / num_strips; // <= s->h
// make nexty the next multiple of 4 if not already there
if (nexty & 3)
nexty += 4 - (nexty & 3);
strip_height = nexty - y;
if (strip_height <= 0) { // can this ever happen?
av_log(s->avctx, AV_LOG_INFO, "skipping zero height strip %i of %i\n", strip, num_strips);
continue;
}
if (s->pix_fmt == AV_PIX_FMT_RGB24)
get_sub_picture(s, 0, y,
s->input_frame->data, s->input_frame->linesize,
data, linesize);
else
get_sub_picture(s, 0, y,
frame->data, frame->linesize,
data, linesize);
get_sub_picture(s, 0, y,
s->last_frame->data, s->last_frame->linesize,
last_data, last_linesize);
get_sub_picture(s, 0, y,
s->scratch_frame->data, s->scratch_frame->linesize,
scratch_data, scratch_linesize);
if ((temp_size = rd_strip(s, y, strip_height, isakeyframe,
last_data, last_linesize, data, linesize,
scratch_data, scratch_linesize,
s->frame_buf + strip_offsets[strip-1],
&score_temp, &no_skip)) < 0)
return temp_size;
score += score_temp;
size += temp_size;
all_no_skip &= no_skip;
}
if (best_score == 0 || score < best_score) {
best_score = score;
best_size = size + write_cvid_header(s, s->frame_buf, num_strips, size, all_no_skip);
FFSWAP(AVFrame *, s->best_frame, s->scratch_frame);
memcpy(buf, s->frame_buf, best_size);
best_nstrips = num_strips;
*got_keyframe = all_no_skip; // no skip MBs in any strip -> keyframe
memcpy(best_strip_offsets, strip_offsets, sizeof(strip_offsets));
}
// avoid trying too many strip numbers without a real reason
// (this makes the processing of the very first frame faster)
if (num_strips - best_nstrips > 4)
break;
}
// update strip headers
for (i = 0; i < best_nstrips; i++) {
write_strip_keyframe(s->frame_buf + best_strip_offsets[i], *got_keyframe);
}
// let the number of strips slowly adapt to the changes in the contents,
// compared to full bruteforcing every time this will occasionally lead
// to some r/d performance loss but makes encoding up to several times faster
if (!s->strip_number_delta_range) {
if (best_nstrips == s->max_strips) { // let us try to step up
s->max_strips = best_nstrips + 1;
if (s->max_strips >= s->max_max_strips)
s->max_strips = s->max_max_strips;
} else { // try to step down
s->max_strips = best_nstrips;
}
s->min_strips = s->max_strips - 1;
if (s->min_strips < s->min_min_strips)
s->min_strips = s->min_min_strips;
} else {
s->max_strips = best_nstrips + s->strip_number_delta_range;
if (s->max_strips >= s->max_max_strips)
s->max_strips = s->max_max_strips;
s->min_strips = best_nstrips - s->strip_number_delta_range;
if (s->min_strips < s->min_min_strips)
s->min_strips = s->min_min_strips;
}
return best_size;
}
static int cinepak_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
const AVFrame *frame, int *got_packet)
{
CinepakEncContext *s = avctx->priv_data;
int ret, got_keyframe;
s->lambda = frame->quality ? frame->quality - 1 : 2 * FF_LAMBDA_SCALE;
if ((ret = ff_alloc_packet(avctx, pkt, s->frame_buf_size)) < 0)
return ret;
ret = rd_frame(s, frame, (s->curframe == 0), pkt->data, s->frame_buf_size, &got_keyframe);
pkt->size = ret;
if (got_keyframe) {
pkt->flags |= AV_PKT_FLAG_KEY;
s->curframe = 0;
}
*got_packet = 1;
FFSWAP(AVFrame *, s->last_frame, s->best_frame);
if (++s->curframe >= avctx->gop_size)
s->curframe = 0;
return 0;
}
static av_cold int cinepak_encode_end(AVCodecContext *avctx)
{
CinepakEncContext *s = avctx->priv_data;
int x;
avpriv_elbg_free(&s->elbg);
av_frame_free(&s->last_frame);
av_frame_free(&s->best_frame);
av_frame_free(&s->scratch_frame);
if (avctx->pix_fmt == AV_PIX_FMT_RGB24)
av_frame_free(&s->input_frame);
av_freep(&s->codebook_input);
av_freep(&s->codebook_closest);
av_freep(&s->strip_buf);
av_freep(&s->frame_buf);
av_freep(&s->mb);
for (x = 0; x < (avctx->pix_fmt == AV_PIX_FMT_RGB24 ? 4 : 3); x++)
av_freep(&s->pict_bufs[x]);
return 0;
}
const FFCodec ff_cinepak_encoder = {
.p.name = "cinepak",
CODEC_LONG_NAME("Cinepak"),
.p.type = AVMEDIA_TYPE_VIDEO,
.p.id = AV_CODEC_ID_CINEPAK,
.p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
.priv_data_size = sizeof(CinepakEncContext),
.init = cinepak_encode_init,
FF_CODEC_ENCODE_CB(cinepak_encode_frame),
.close = cinepak_encode_end,
.p.pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_RGB24, AV_PIX_FMT_GRAY8, AV_PIX_FMT_NONE },
.p.priv_class = &cinepak_class,
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
};
|
1e4f891c1f0ec6ac9f7fa164d9046112b9999c97
|
28d0f8c01599f8f6c711bdde0b59f9c2cd221203
|
/sys/dev/ic/rtwn_data.h
|
d737424bfe835499f4768ea4deaece1cf96a3b2b
|
[] |
no_license
|
NetBSD/src
|
1a9cbc22ed778be638b37869ed4fb5c8dd616166
|
23ee83f7c0aea0777bd89d8ebd7f0cde9880d13c
|
refs/heads/trunk
| 2023-08-31T13:24:58.105962
| 2023-08-27T15:50:47
| 2023-08-27T15:50:47
| 88,439,547
| 656
| 348
| null | 2023-07-20T20:07:24
| 2017-04-16T20:03:43
| null |
UTF-8
|
C
| false
| false
| 64,712
|
h
|
rtwn_data.h
|
/* $NetBSD: rtwn_data.h,v 1.2 2022/09/26 19:04:49 martin Exp $ */
/* $OpenBSD: r92creg.h,v 1.16 2017/09/22 13:41:56 kevlo Exp $ */
/*-
* Copyright (c) 2010 Damien Bergamini <damien.bergamini@free.fr>
* Copyright (c) 2015 Stefan Sperling <stsp@openbsd.org>
* Copyright (c) 2016 Nathanial Sloss <nathanialsloss@yahoo.com.au>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS 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, DIRECT, 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 _DEV_IC_RTWN_DATA_H_
#define _DEV_IC_RTWN_DATA_H_
/*
* MAC initialization values.
*/
static const struct {
uint16_t reg;
uint8_t val;
} rtl8192ce_mac[] = {
{ 0x420, 0x80 }, { 0x423, 0x00 }, { 0x430, 0x00 }, { 0x431, 0x00 },
{ 0x432, 0x00 }, { 0x433, 0x01 }, { 0x434, 0x04 }, { 0x435, 0x05 },
{ 0x436, 0x06 }, { 0x437, 0x07 }, { 0x438, 0x00 }, { 0x439, 0x00 },
{ 0x43a, 0x00 }, { 0x43b, 0x01 }, { 0x43c, 0x04 }, { 0x43d, 0x05 },
{ 0x43e, 0x06 }, { 0x43f, 0x07 }, { 0x440, 0x5d }, { 0x441, 0x01 },
{ 0x442, 0x00 }, { 0x444, 0x15 }, { 0x445, 0xf0 }, { 0x446, 0x0f },
{ 0x447, 0x00 }, { 0x458, 0x41 }, { 0x459, 0xa8 }, { 0x45a, 0x72 },
{ 0x45b, 0xb9 }, { 0x460, 0x88 }, { 0x461, 0x88 }, { 0x462, 0x06 },
{ 0x463, 0x03 }, { 0x4c8, 0x04 }, { 0x4c9, 0x08 }, { 0x4cc, 0x02 },
{ 0x4cd, 0x28 }, { 0x4ce, 0x01 }, { 0x500, 0x26 }, { 0x501, 0xa2 },
{ 0x502, 0x2f }, { 0x503, 0x00 }, { 0x504, 0x28 }, { 0x505, 0xa3 },
{ 0x506, 0x5e }, { 0x507, 0x00 }, { 0x508, 0x2b }, { 0x509, 0xa4 },
{ 0x50a, 0x5e }, { 0x50b, 0x00 }, { 0x50c, 0x4f }, { 0x50d, 0xa4 },
{ 0x50e, 0x00 }, { 0x50f, 0x00 }, { 0x512, 0x1c }, { 0x514, 0x0a },
{ 0x515, 0x10 }, { 0x516, 0x0a }, { 0x517, 0x10 }, { 0x51a, 0x16 },
{ 0x524, 0x0f }, { 0x525, 0x4f }, { 0x546, 0x20 }, { 0x547, 0x00 },
{ 0x559, 0x02 }, { 0x55a, 0x02 }, { 0x55d, 0xff }, { 0x605, 0x30 },
{ 0x608, 0x0e }, { 0x609, 0x2a }, { 0x652, 0x20 }, { 0x63c, 0x0a },
{ 0x63d, 0x0e }, { 0x700, 0x21 }, { 0x701, 0x43 }, { 0x702, 0x65 },
{ 0x703, 0x87 }, { 0x708, 0x21 }, { 0x709, 0x43 }, { 0x70a, 0x65 },
{ 0x70b, 0x87 }
}, rtl8192eu_mac[] = {
{ 0x011, 0xeb }, { 0x012, 0x07 }, { 0x014, 0x75 }, { 0x303, 0xa7 },
{ 0x428, 0x0a }, { 0x429, 0x10 }, { 0x430, 0x00 }, { 0x431, 0x00 },
{ 0x432, 0x00 }, { 0x433, 0x01 }, { 0x434, 0x04 }, { 0x435, 0x05 },
{ 0x436, 0x07 }, { 0x437, 0x08 }, { 0x43c, 0x04 }, { 0x43d, 0x05 },
{ 0x43e, 0x07 }, { 0x43f, 0x08 }, { 0x440, 0x5d }, { 0x441, 0x01 },
{ 0x442, 0x00 }, { 0x444, 0x10 }, { 0x445, 0x00 }, { 0x446, 0x00 },
{ 0x447, 0x00 }, { 0x448, 0x00 }, { 0x449, 0xf0 }, { 0x44a, 0x0f },
{ 0x44b, 0x3e }, { 0x44c, 0x10 }, { 0x44d, 0x00 }, { 0x44e, 0x00 },
{ 0x44f, 0x00 }, { 0x450, 0x00 }, { 0x451, 0xf0 }, { 0x452, 0x0f },
{ 0x453, 0x00 }, { 0x456, 0x5e }, { 0x460, 0x66 }, { 0x461, 0x66 },
{ 0x4c8, 0xff }, { 0x4c9, 0x08 }, { 0x4cc, 0xff }, { 0x4cd, 0xff },
{ 0x4ce, 0x01 }, { 0x500, 0x26 }, { 0x501, 0xa2 }, { 0x502, 0x2f },
{ 0x503, 0x00 }, { 0x504, 0x28 }, { 0x505, 0xa3 }, { 0x506, 0x5e },
{ 0x507, 0x00 }, { 0x508, 0x2b }, { 0x509, 0xa4 }, { 0x50a, 0x5e },
{ 0x50b, 0x00 }, { 0x50c, 0x4f }, { 0x50d, 0xa4 }, { 0x50e, 0x00 },
{ 0x50f, 0x00 }, { 0x512, 0x1c }, { 0x514, 0x0a }, { 0x516, 0x0a },
{ 0x525, 0x4f }, { 0x540, 0x12 }, { 0x541, 0x64 }, { 0x550, 0x10 },
{ 0x551, 0x10 }, { 0x559, 0x02 }, { 0x55c, 0x50 }, { 0x55d, 0xff },
{ 0x605, 0x30 }, { 0x608, 0x0e }, { 0x609, 0x2a }, { 0x620, 0xff },
{ 0x621, 0xff }, { 0x622, 0xff }, { 0x623, 0xff }, { 0x624, 0xff },
{ 0x625, 0xff }, { 0x626, 0xff }, { 0x627, 0xff }, { 0x638, 0x50 },
{ 0x63c, 0x0a }, { 0x63d, 0x0a }, { 0x63e, 0x0e }, { 0x63f, 0x0e },
{ 0x640, 0x40 }, { 0x642, 0x40 }, { 0x643, 0x00 }, { 0x652, 0xc8 },
{ 0x66e, 0x05 }, { 0x700, 0x21 }, { 0x701, 0x43 }, { 0x702, 0x65 },
{ 0x703, 0x87 }, { 0x708, 0x21 }, { 0x709, 0x43 }, { 0x70a, 0x65 },
{ 0x70b, 0x87 },
}, rtl8188eu_mac[] = {
{ 0x026, 0x41 }, { 0x027, 0x35 }, { 0x040, 0x00 }, { 0x428, 0x0a },
{ 0x429, 0x10 }, { 0x430, 0x00 }, { 0x431, 0x01 }, { 0x432, 0x02 },
{ 0x433, 0x04 }, { 0x434, 0x05 }, { 0x435, 0x06 }, { 0x436, 0x07 },
{ 0x437, 0x08 }, { 0x438, 0x00 }, { 0x439, 0x00 }, { 0x43a, 0x01 },
{ 0x43b, 0x02 }, { 0x43c, 0x04 }, { 0x43d, 0x05 }, { 0x43e, 0x06 },
{ 0x43f, 0x07 }, { 0x440, 0x5d }, { 0x441, 0x01 }, { 0x442, 0x00 },
{ 0x444, 0x15 }, { 0x445, 0xf0 }, { 0x446, 0x0f }, { 0x447, 0x00 },
{ 0x458, 0x41 }, { 0x459, 0xa8 }, { 0x45a, 0x72 }, { 0x45b, 0xb9 },
{ 0x460, 0x66 }, { 0x461, 0x66 }, { 0x480, 0x08 }, { 0x4c8, 0xff },
{ 0x4c9, 0x08 }, { 0x4cc, 0xff }, { 0x4cd, 0xff }, { 0x4ce, 0x01 },
{ 0x4d3, 0x01 }, { 0x500, 0x26 }, { 0x501, 0xa2 }, { 0x502, 0x2f },
{ 0x503, 0x00 }, { 0x504, 0x28 }, { 0x505, 0xa3 }, { 0x506, 0x5e },
{ 0x507, 0x00 }, { 0x508, 0x2b }, { 0x509, 0xa4 }, { 0x50a, 0x5e },
{ 0x50b, 0x00 }, { 0x50c, 0x4f }, { 0x50d, 0xa4 }, { 0x50e, 0x00 },
{ 0x50f, 0x00 }, { 0x512, 0x1c }, { 0x514, 0x0a }, { 0x516, 0x0a },
{ 0x525, 0x4f }, { 0x550, 0x10 }, { 0x551, 0x10 }, { 0x559, 0x02 },
{ 0x55d, 0xff }, { 0x605, 0x30 }, { 0x608, 0x0e }, { 0x609, 0x2a },
{ 0x620, 0xff }, { 0x621, 0xff }, { 0x622, 0xff }, { 0x623, 0xff },
{ 0x624, 0xff }, { 0x625, 0xff }, { 0x626, 0xff }, { 0x627, 0xff },
{ 0x652, 0x20 }, { 0x63c, 0x0a }, { 0x63d, 0x0a }, { 0x63e, 0x0e },
{ 0x63f, 0x0e }, { 0x640, 0x40 }, { 0x66e, 0x05 }, { 0x700, 0x21 },
{ 0x701, 0x43 }, { 0x702, 0x65 }, { 0x703, 0x87 }, { 0x708, 0x21 },
{ 0x709, 0x43 }, { 0x70a, 0x65 }, { 0x70b, 0x87 }
}, rtl8192cu_mac[] = {
{ 0x420, 0x80 }, { 0x423, 0x00 }, { 0x430, 0x00 }, { 0x431, 0x00 },
{ 0x432, 0x00 }, { 0x433, 0x01 }, { 0x434, 0x04 }, { 0x435, 0x05 },
{ 0x436, 0x06 }, { 0x437, 0x07 }, { 0x438, 0x00 }, { 0x439, 0x00 },
{ 0x43a, 0x00 }, { 0x43b, 0x01 }, { 0x43c, 0x04 }, { 0x43d, 0x05 },
{ 0x43e, 0x06 }, { 0x43f, 0x07 }, { 0x440, 0x5d }, { 0x441, 0x01 },
{ 0x442, 0x00 }, { 0x444, 0x15 }, { 0x445, 0xf0 }, { 0x446, 0x0f },
{ 0x447, 0x00 }, { 0x458, 0x41 }, { 0x459, 0xa8 }, { 0x45a, 0x72 },
{ 0x45b, 0xb9 }, { 0x460, 0x66 }, { 0x461, 0x66 }, { 0x462, 0x08 },
{ 0x463, 0x03 }, { 0x4c8, 0xff }, { 0x4c9, 0x08 }, { 0x4cc, 0xff },
{ 0x4cd, 0xff }, { 0x4ce, 0x01 }, { 0x500, 0x26 }, { 0x501, 0xa2 },
{ 0x502, 0x2f }, { 0x503, 0x00 }, { 0x504, 0x28 }, { 0x505, 0xa3 },
{ 0x506, 0x5e }, { 0x507, 0x00 }, { 0x508, 0x2b }, { 0x509, 0xa4 },
{ 0x50a, 0x5e }, { 0x50b, 0x00 }, { 0x50c, 0x4f }, { 0x50d, 0xa4 },
{ 0x50e, 0x00 }, { 0x50f, 0x00 }, { 0x512, 0x1c }, { 0x514, 0x0a },
{ 0x515, 0x10 }, { 0x516, 0x0a }, { 0x517, 0x10 }, { 0x51a, 0x16 },
{ 0x524, 0x0f }, { 0x525, 0x4f }, { 0x546, 0x40 }, { 0x547, 0x00 },
{ 0x550, 0x10 }, { 0x551, 0x10 }, { 0x559, 0x02 }, { 0x55a, 0x02 },
{ 0x55d, 0xff }, { 0x605, 0x30 }, { 0x608, 0x0e }, { 0x609, 0x2a },
{ 0x652, 0x20 }, { 0x63c, 0x0a }, { 0x63d, 0x0e }, { 0x63e, 0x0a },
{ 0x63f, 0x0e }, { 0x66e, 0x05 }, { 0x700, 0x21 }, { 0x701, 0x43 },
{ 0x702, 0x65 }, { 0x703, 0x87 }, { 0x708, 0x21 }, { 0x709, 0x43 },
{ 0x70a, 0x65 }, { 0x70b, 0x87 }
};
/*
* Baseband initialization values.
*/
struct rtwn_bb_prog {
int count;
const uint16_t *regs;
const uint32_t *vals;
int agccount;
const uint32_t *agcvals;
};
/*
* RTL8192CU and RTL8192CE-VAU.
*/
static const uint16_t rtl8192ce_bb_regs[] = {
0x024, 0x028, 0x800, 0x804, 0x808, 0x80c, 0x810, 0x814, 0x818,
0x81c, 0x820, 0x824, 0x828, 0x82c, 0x830, 0x834, 0x838, 0x83c,
0x840, 0x844, 0x848, 0x84c, 0x850, 0x854, 0x858, 0x85c, 0x860,
0x864, 0x868, 0x86c, 0x870, 0x874, 0x878, 0x87c, 0x880, 0x884,
0x888, 0x88c, 0x890, 0x894, 0x898, 0x89c, 0x900, 0x904, 0x908,
0x90c, 0xa00, 0xa04, 0xa08, 0xa0c, 0xa10, 0xa14, 0xa18, 0xa1c,
0xa20, 0xa24, 0xa28, 0xa2c, 0xa70, 0xa74, 0xc00, 0xc04, 0xc08,
0xc0c, 0xc10, 0xc14, 0xc18, 0xc1c, 0xc20, 0xc24, 0xc28, 0xc2c,
0xc30, 0xc34, 0xc38, 0xc3c, 0xc40, 0xc44, 0xc48, 0xc4c, 0xc50,
0xc54, 0xc58, 0xc5c, 0xc60, 0xc64, 0xc68, 0xc6c, 0xc70, 0xc74,
0xc78, 0xc7c, 0xc80, 0xc84, 0xc88, 0xc8c, 0xc90, 0xc94, 0xc98,
0xc9c, 0xca0, 0xca4, 0xca8, 0xcac, 0xcb0, 0xcb4, 0xcb8, 0xcbc,
0xcc0, 0xcc4, 0xcc8, 0xccc, 0xcd0, 0xcd4, 0xcd8, 0xcdc, 0xce0,
0xce4, 0xce8, 0xcec, 0xd00, 0xd04, 0xd08, 0xd0c, 0xd10, 0xd14,
0xd18, 0xd2c, 0xd30, 0xd34, 0xd38, 0xd3c, 0xd40, 0xd44, 0xd48,
0xd4c, 0xd50, 0xd54, 0xd58, 0xd5c, 0xd60, 0xd64, 0xd68, 0xd6c,
0xd70, 0xd74, 0xd78, 0xe00, 0xe04, 0xe08, 0xe10, 0xe14, 0xe18,
0xe1c, 0xe28, 0xe30, 0xe34, 0xe38, 0xe3c, 0xe40, 0xe44, 0xe48,
0xe4c, 0xe50, 0xe54, 0xe58, 0xe5c, 0xe60, 0xe68, 0xe6c, 0xe70,
0xe74, 0xe78, 0xe7c, 0xe80, 0xe84, 0xe88, 0xe8c, 0xed0, 0xed4,
0xed8, 0xedc, 0xee0, 0xeec, 0xf14, 0xf4c, 0xf00
};
static const uint32_t rtl8192ce_bb_vals[] = {
0x0011800d, 0x00ffdb83, 0x80040002, 0x00000003, 0x0000fc00,
0x0000000a, 0x10005388, 0x020c3d10, 0x02200385, 0x00000000,
0x01000100, 0x00390004, 0x01000100, 0x00390004, 0x27272727,
0x27272727, 0x27272727, 0x27272727, 0x00010000, 0x00010000,
0x27272727, 0x27272727, 0x00000000, 0x00000000, 0x569a569a,
0x0c1b25a4, 0x66e60230, 0x061f0130, 0x27272727, 0x2b2b2b27,
0x07000700, 0x22184000, 0x08080808, 0x00000000, 0xc0083070,
0x000004d5, 0x00000000, 0xcc0000c0, 0x00000800, 0xfffffffe,
0x40302010, 0x00706050, 0x00000000, 0x00000023, 0x00000000,
0x81121313, 0x00d047c8, 0x80ff000c, 0x8c838300, 0x2e68120f,
0x9500bb78, 0x11144028, 0x00881117, 0x89140f00, 0x1a1b0000,
0x090e1317, 0x00000204, 0x00d30000, 0x101fbf00, 0x00000007,
0x48071d40, 0x03a05633, 0x000000e4, 0x6c6c6c6c, 0x08800000,
0x40000100, 0x08800000, 0x40000100, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x69e9ac44, 0x469652cf, 0x49795994,
0x0a97971c, 0x1f7c403f, 0x000100b7, 0xec020107, 0x007f037f,
0x6954341e, 0x43bc0094, 0x6954341e, 0x433c0094, 0x00000000,
0x5116848b, 0x47c00bff, 0x00000036, 0x2c7f000d, 0x018610db,
0x0000001f, 0x00b91612, 0x40000100, 0x20f60000, 0x40000100,
0x20200000, 0x00121820, 0x00000000, 0x00121820, 0x00007f7f,
0x00000000, 0x00000080, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x28000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x64b22427,
0x00766932, 0x00222222, 0x00000000, 0x37644302, 0x2f97d40c,
0x00080740, 0x00020403, 0x0000907f, 0x20010201, 0xa0633333,
0x3333bc43, 0x7a8f5b6b, 0xcc979975, 0x00000000, 0x80608000,
0x00000000, 0x00027293, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x6437140a, 0x00000000, 0x00000000, 0x30032064,
0x4653de68, 0x04518a3c, 0x00002101, 0x2a201c16, 0x1812362e,
0x322c2220, 0x000e3c24, 0x2a2a2a2a, 0x2a2a2a2a, 0x03902a2a,
0x2a2a2a2a, 0x2a2a2a2a, 0x2a2a2a2a, 0x2a2a2a2a, 0x00000000,
0x1000dc1f, 0x10008c1f, 0x02140102, 0x681604c2, 0x01007c00,
0x01004800, 0xfb000000, 0x000028d1, 0x1000dc1f, 0x10008c1f,
0x02140102, 0x28160d05, 0x00000010, 0x001b25a4, 0x63db25a4,
0x63db25a4, 0x0c1b25a4, 0x0c1b25a4, 0x0c1b25a4, 0x0c1b25a4,
0x63db25a4, 0x0c1b25a4, 0x63db25a4, 0x63db25a4, 0x63db25a4,
0x63db25a4, 0x001b25a4, 0x001b25a4, 0x6fdb25a4, 0x00000003,
0x00000000, 0x00000300
};
static const uint32_t rtl8192ce_bb_vals_2t[] = {
0x0011800f, 0x00ffdb83, 0x80040002, 0x00000003, 0x0000fc00,
0x0000000a, 0x10005388, 0x020c3d10, 0x02200385, 0x00000000,
0x01000100, 0x00390004, 0x01000100, 0x00390004, 0x27272727,
0x27272727, 0x27272727, 0x27272727, 0x00010000, 0x00010000,
0x27272727, 0x27272727, 0x00000000, 0x00000000, 0x569a569a,
0x0c1b25a4, 0x66e60230, 0x061f0130, 0x27272727, 0x2b2b2b27,
0x07000700, 0x22184000, 0x08080808, 0x00000000, 0xc0083070,
0x000004d5, 0x00000000, 0xcc0000c0, 0x00000800, 0xfffffffe,
0x40302010, 0x00706050, 0x00000000, 0x00000023, 0x00000000,
0x81121313, 0x00d047c8, 0x80ff000c, 0x8c838300, 0x2e68120f,
0x9500bb78, 0x11144028, 0x00881117, 0x89140f00, 0x1a1b0000,
0x090e1317, 0x00000204, 0x00d30000, 0x101fbf00, 0x00000007,
0x48071d40, 0x03a05633, 0x000000e4, 0x6c6c6c6c, 0x08800000,
0x40000100, 0x08800000, 0x40000100, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x69e9ac44, 0x469652cf, 0x49795994,
0x0a97971c, 0x1f7c403f, 0x000100b7, 0xec020107, 0x007f037f,
0x69543420, 0x43bc0094, 0x69543420, 0x433c0094, 0x00000000,
0x5116848b, 0x47c00bff, 0x00000036, 0x2c7f000d, 0x018610db,
0x0000001f, 0x00b91612, 0x40000100, 0x20f60000, 0x40000100,
0x20200000, 0x00121820, 0x00000000, 0x00121820, 0x00007f7f,
0x00000000, 0x00000080, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x28000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x64b22427,
0x00766932, 0x00222222, 0x00000000, 0x37644302, 0x2f97d40c,
0x00080740, 0x00020403, 0x0000907f, 0x20010201, 0xa0633333,
0x3333bc43, 0x7a8f5b6b, 0xcc979975, 0x00000000, 0x80608000,
0x00000000, 0x00027293, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x6437140a, 0x00000000, 0x00000000, 0x30032064,
0x4653de68, 0x04518a3c, 0x00002101, 0x2a201c16, 0x1812362e,
0x322c2220, 0x000e3c24, 0x2a2a2a2a, 0x2a2a2a2a, 0x03902a2a,
0x2a2a2a2a, 0x2a2a2a2a, 0x2a2a2a2a, 0x2a2a2a2a, 0x00000000,
0x1000dc1f, 0x10008c1f, 0x02140102, 0x681604c2, 0x01007c00,
0x01004800, 0xfb000000, 0x000028d1, 0x1000dc1f, 0x10008c1f,
0x02140102, 0x28160d05, 0x00000010, 0x001b25a4, 0x63db25a4,
0x63db25a4, 0x0c1b25a4, 0x0c1b25a4, 0x0c1b25a4, 0x0c1b25a4,
0x63db25a4, 0x0c1b25a4, 0x63db25a4, 0x63db25a4, 0x63db25a4,
0x63db25a4, 0x001b25a4, 0x001b25a4, 0x6fdb25a4, 0x00000003,
0x00000000, 0x00000300
};
static const uint32_t rtl8192ce_bb_vals_1t[] = {
0x0011800f, 0x00ffdb83, 0x80040000, 0x00000001, 0x0000fc00,
0x0000000a, 0x10005388, 0x020c3d10, 0x02200385, 0x00000000,
0x01000100, 0x00390004, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00010000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x569a569a,
0x001b25a4, 0x66e60230, 0x061f0130, 0x00000000, 0x32323200,
0x07000700, 0x22004000, 0x00000808, 0x00000000, 0xc0083070,
0x000004d5, 0x00000000, 0xccc000c0, 0x00000800, 0xfffffffe,
0x40302010, 0x00706050, 0x00000000, 0x00000023, 0x00000000,
0x81121111, 0x00d047c8, 0x80ff000c, 0x8c838300, 0x2e68120f,
0x9500bb78, 0x11144028, 0x00881117, 0x89140f00, 0x1a1b0000,
0x090e1317, 0x00000204, 0x00d30000, 0x101fbf00, 0x00000007,
0x48071d40, 0x03a05611, 0x000000e4, 0x6c6c6c6c, 0x08800000,
0x40000100, 0x08800000, 0x40000100, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x69e9ac44, 0x469652cf, 0x49795994,
0x0a97971c, 0x1f7c403f, 0x000100b7, 0xec020107, 0x007f037f,
0x69543420, 0x43bc0094, 0x69543420, 0x433c0094, 0x00000000,
0x5116848b, 0x47c00bff, 0x00000036, 0x2c7f000d, 0x018610db,
0x0000001f, 0x00b91612, 0x40000100, 0x20f60000, 0x40000100,
0x20200000, 0x00121820, 0x00000000, 0x00121820, 0x00007f7f,
0x00000000, 0x00000080, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x28000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x64b22427,
0x00766932, 0x00222222, 0x00000000, 0x37644302, 0x2f97d40c,
0x00080740, 0x00020401, 0x0000907f, 0x20010201, 0xa0633333,
0x3333bc43, 0x7a8f5b6b, 0xcc979975, 0x00000000, 0x80608000,
0x00000000, 0x00027293, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x6437140a, 0x00000000, 0x00000000, 0x30032064,
0x4653de68, 0x04518a3c, 0x00002101, 0x2a201c16, 0x1812362e,
0x322c2220, 0x000e3c24, 0x2a2a2a2a, 0x2a2a2a2a, 0x03902a2a,
0x2a2a2a2a, 0x2a2a2a2a, 0x2a2a2a2a, 0x2a2a2a2a, 0x00000000,
0x1000dc1f, 0x10008c1f, 0x02140102, 0x681604c2, 0x01007c00,
0x01004800, 0xfb000000, 0x000028d1, 0x1000dc1f, 0x10008c1f,
0x02140102, 0x28160d05, 0x00000010, 0x001b25a4, 0x631b25a0,
0x631b25a0, 0x081b25a0, 0x081b25a0, 0x081b25a0, 0x081b25a0,
0x631b25a0, 0x081b25a0, 0x631b25a0, 0x631b25a0, 0x631b25a0,
0x631b25a0, 0x001b25a0, 0x001b25a0, 0x6b1b25a0, 0x00000003,
0x00000000, 0x00000300,
};
static const uint32_t rtl8192ce_agc_vals[] = {
0x7b000001, 0x7b010001, 0x7b020001, 0x7b030001, 0x7b040001,
0x7b050001, 0x7a060001, 0x79070001, 0x78080001, 0x77090001,
0x760a0001, 0x750b0001, 0x740c0001, 0x730d0001, 0x720e0001,
0x710f0001, 0x70100001, 0x6f110001, 0x6e120001, 0x6d130001,
0x6c140001, 0x6b150001, 0x6a160001, 0x69170001, 0x68180001,
0x67190001, 0x661a0001, 0x651b0001, 0x641c0001, 0x631d0001,
0x621e0001, 0x611f0001, 0x60200001, 0x49210001, 0x48220001,
0x47230001, 0x46240001, 0x45250001, 0x44260001, 0x43270001,
0x42280001, 0x41290001, 0x402a0001, 0x262b0001, 0x252c0001,
0x242d0001, 0x232e0001, 0x222f0001, 0x21300001, 0x20310001,
0x06320001, 0x05330001, 0x04340001, 0x03350001, 0x02360001,
0x01370001, 0x00380001, 0x00390001, 0x003a0001, 0x003b0001,
0x003c0001, 0x003d0001, 0x003e0001, 0x003f0001, 0x7b400001,
0x7b410001, 0x7b420001, 0x7b430001, 0x7b440001, 0x7b450001,
0x7a460001, 0x79470001, 0x78480001, 0x77490001, 0x764a0001,
0x754b0001, 0x744c0001, 0x734d0001, 0x724e0001, 0x714f0001,
0x70500001, 0x6f510001, 0x6e520001, 0x6d530001, 0x6c540001,
0x6b550001, 0x6a560001, 0x69570001, 0x68580001, 0x67590001,
0x665a0001, 0x655b0001, 0x645c0001, 0x635d0001, 0x625e0001,
0x615f0001, 0x60600001, 0x49610001, 0x48620001, 0x47630001,
0x46640001, 0x45650001, 0x44660001, 0x43670001, 0x42680001,
0x41690001, 0x406a0001, 0x266b0001, 0x256c0001, 0x246d0001,
0x236e0001, 0x226f0001, 0x21700001, 0x20710001, 0x06720001,
0x05730001, 0x04740001, 0x03750001, 0x02760001, 0x01770001,
0x00780001, 0x00790001, 0x007a0001, 0x007b0001, 0x007c0001,
0x007d0001, 0x007e0001, 0x007f0001, 0x3800001e, 0x3801001e,
0x3802001e, 0x3803001e, 0x3804001e, 0x3805001e, 0x3806001e,
0x3807001e, 0x3808001e, 0x3c09001e, 0x3e0a001e, 0x400b001e,
0x440c001e, 0x480d001e, 0x4c0e001e, 0x500f001e, 0x5210001e,
0x5611001e, 0x5a12001e, 0x5e13001e, 0x6014001e, 0x6015001e,
0x6016001e, 0x6217001e, 0x6218001e, 0x6219001e, 0x621a001e,
0x621b001e, 0x621c001e, 0x621d001e, 0x621e001e, 0x621f001e
};
static const struct rtwn_bb_prog rtl8192ce_bb_prog = {
__arraycount(rtl8192ce_bb_regs),
rtl8192ce_bb_regs,
rtl8192ce_bb_vals,
__arraycount(rtl8192ce_agc_vals),
rtl8192ce_agc_vals
};
static const struct rtwn_bb_prog rtl8192ce_bb_prog_2t = {
__arraycount(rtl8192ce_bb_regs),
rtl8192ce_bb_regs,
rtl8192ce_bb_vals_2t,
__arraycount(rtl8192ce_agc_vals),
rtl8192ce_agc_vals
};
static const struct rtwn_bb_prog rtl8192ce_bb_prog_1t = {
__arraycount(rtl8192ce_bb_regs),
rtl8192ce_bb_regs,
rtl8192ce_bb_vals_1t,
__arraycount(rtl8192ce_agc_vals),
rtl8192ce_agc_vals
};
/*
* RTL8188CU.
*/
static const uint32_t rtl8192cu_bb_vals[] = {
0x0011800d, 0x00ffdb83, 0x80040002, 0x00000003, 0x0000fc00,
0x0000000a, 0x10005388, 0x020c3d10, 0x02200385, 0x00000000,
0x01000100, 0x00390004, 0x01000100, 0x00390004, 0x27272727,
0x27272727, 0x27272727, 0x27272727, 0x00010000, 0x00010000,
0x27272727, 0x27272727, 0x00000000, 0x00000000, 0x569a569a,
0x0c1b25a4, 0x66e60230, 0x061f0130, 0x27272727, 0x2b2b2b27,
0x07000700, 0x22184000, 0x08080808, 0x00000000, 0xc0083070,
0x000004d5, 0x00000000, 0xcc0000c0, 0x00000800, 0xfffffffe,
0x40302010, 0x00706050, 0x00000000, 0x00000023, 0x00000000,
0x81121313, 0x00d047c8, 0x80ff000c, 0x8c838300, 0x2e68120f,
0x9500bb78, 0x11144028, 0x00881117, 0x89140f00, 0x1a1b0000,
0x090e1317, 0x00000204, 0x00d30000, 0x101fbf00, 0x00000007,
0x48071d40, 0x03a05633, 0x000000e4, 0x6c6c6c6c, 0x08800000,
0x40000100, 0x08800000, 0x40000100, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x69e9ac44, 0x469652cf, 0x49795994,
0x0a97971c, 0x1f7c403f, 0x000100b7, 0xec020107, 0x007f037f,
0x6954341e, 0x43bc0094, 0x6954341e, 0x433c0094, 0x00000000,
0x5116848b, 0x47c00bff, 0x00000036, 0x2c7f000d, 0x0186115b,
0x0000001f, 0x00b99612, 0x40000100, 0x20f60000, 0x40000100,
0x20200000, 0x00121820, 0x00000000, 0x00121820, 0x00007f7f,
0x00000000, 0x00000080, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x28000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x64b22427,
0x00766932, 0x00222222, 0x00000000, 0x37644302, 0x2f97d40c,
0x00080740, 0x00020403, 0x0000907f, 0x20010201, 0xa0633333,
0x3333bc43, 0x7a8f5b6b, 0xcc979975, 0x00000000, 0x80608000,
0x00000000, 0x00027293, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x6437140a, 0x00000000, 0x00000000, 0x30032064,
0x4653de68, 0x04518a3c, 0x00002101, 0x2a201c16, 0x1812362e,
0x322c2220, 0x000e3c24, 0x2a2a2a2a, 0x2a2a2a2a, 0x03902a2a,
0x2a2a2a2a, 0x2a2a2a2a, 0x2a2a2a2a, 0x2a2a2a2a, 0x00000000,
0x1000dc1f, 0x10008c1f, 0x02140102, 0x681604c2, 0x01007c00,
0x01004800, 0xfb000000, 0x000028d1, 0x1000dc1f, 0x10008c1f,
0x02140102, 0x28160d05, 0x00000010, 0x001b25a4, 0x63db25a4,
0x63db25a4, 0x0c1b25a4, 0x0c1b25a4, 0x0c1b25a4, 0x0c1b25a4,
0x63db25a4, 0x0c1b25a4, 0x63db25a4, 0x63db25a4, 0x63db25a4,
0x63db25a4, 0x001b25a4, 0x001b25a4, 0x6fdb25a4, 0x00000003,
0x00000000, 0x00000300
};
static const struct rtwn_bb_prog rtl8192cu_bb_prog = {
__arraycount(rtl8192ce_bb_regs),
rtl8192ce_bb_regs,
rtl8192cu_bb_vals,
__arraycount(rtl8192ce_agc_vals),
rtl8192ce_agc_vals
};
/*
* RTL8188CE-VAU.
*/
static const uint32_t rtl8188ce_bb_vals[] = {
0x0011800d, 0x00ffdb83, 0x80040000, 0x00000001, 0x0000fc00,
0x0000000a, 0x10005388, 0x020c3d10, 0x02200385, 0x00000000,
0x01000100, 0x00390004, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00010000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x569a569a,
0x001b25a4, 0x66e60230, 0x061f0130, 0x00000000, 0x32323200,
0x07000700, 0x22004000, 0x00000808, 0x00000000, 0xc0083070,
0x000004d5, 0x00000000, 0xccc000c0, 0x00000800, 0xfffffffe,
0x40302010, 0x00706050, 0x00000000, 0x00000023, 0x00000000,
0x81121111, 0x00d047c8, 0x80ff000c, 0x8c838300, 0x2e68120f,
0x9500bb78, 0x11144028, 0x00881117, 0x89140f00, 0x1a1b0000,
0x090e1317, 0x00000204, 0x00d30000, 0x101fbf00, 0x00000007,
0x48071d40, 0x03a05611, 0x000000e4, 0x6c6c6c6c, 0x08800000,
0x40000100, 0x08800000, 0x40000100, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x69e9ac44, 0x469652cf, 0x49795994,
0x0a97971c, 0x1f7c403f, 0x000100b7, 0xec020107, 0x007f037f,
0x6954341e, 0x43bc0094, 0x6954341e, 0x433c0094, 0x00000000,
0x5116848b, 0x47c00bff, 0x00000036, 0x2c7f000d, 0x018610db,
0x0000001f, 0x00b91612, 0x40000100, 0x20f60000, 0x40000100,
0x20200000, 0x00121820, 0x00000000, 0x00121820, 0x00007f7f,
0x00000000, 0x00000080, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x28000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x64b22427,
0x00766932, 0x00222222, 0x00000000, 0x37644302, 0x2f97d40c,
0x00080740, 0x00020401, 0x0000907f, 0x20010201, 0xa0633333,
0x3333bc43, 0x7a8f5b6b, 0xcc979975, 0x00000000, 0x80608000,
0x00000000, 0x00027293, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x6437140a, 0x00000000, 0x00000000, 0x30032064,
0x4653de68, 0x04518a3c, 0x00002101, 0x2a201c16, 0x1812362e,
0x322c2220, 0x000e3c24, 0x2a2a2a2a, 0x2a2a2a2a, 0x03902a2a,
0x2a2a2a2a, 0x2a2a2a2a, 0x2a2a2a2a, 0x2a2a2a2a, 0x00000000,
0x1000dc1f, 0x10008c1f, 0x02140102, 0x681604c2, 0x01007c00,
0x01004800, 0xfb000000, 0x000028d1, 0x1000dc1f, 0x10008c1f,
0x02140102, 0x28160d05, 0x00000008, 0x001b25a4, 0x631b25a0,
0x631b25a0, 0x081b25a0, 0x081b25a0, 0x081b25a0, 0x081b25a0,
0x631b25a0, 0x081b25a0, 0x631b25a0, 0x631b25a0, 0x631b25a0,
0x631b25a0, 0x001b25a0, 0x001b25a0, 0x6b1b25a0, 0x00000003,
0x00000000, 0x00000300
};
static const uint32_t rtl8188ce_agc_vals[] = {
0x7b000001, 0x7b010001, 0x7b020001, 0x7b030001, 0x7b040001,
0x7b050001, 0x7a060001, 0x79070001, 0x78080001, 0x77090001,
0x760a0001, 0x750b0001, 0x740c0001, 0x730d0001, 0x720e0001,
0x710f0001, 0x70100001, 0x6f110001, 0x6e120001, 0x6d130001,
0x6c140001, 0x6b150001, 0x6a160001, 0x69170001, 0x68180001,
0x67190001, 0x661a0001, 0x651b0001, 0x641c0001, 0x631d0001,
0x621e0001, 0x611f0001, 0x60200001, 0x49210001, 0x48220001,
0x47230001, 0x46240001, 0x45250001, 0x44260001, 0x43270001,
0x42280001, 0x41290001, 0x402a0001, 0x262b0001, 0x252c0001,
0x242d0001, 0x232e0001, 0x222f0001, 0x21300001, 0x20310001,
0x06320001, 0x05330001, 0x04340001, 0x03350001, 0x02360001,
0x01370001, 0x00380001, 0x00390001, 0x003a0001, 0x003b0001,
0x003c0001, 0x003d0001, 0x003e0001, 0x003f0001, 0x7b400001,
0x7b410001, 0x7b420001, 0x7b430001, 0x7b440001, 0x7b450001,
0x7a460001, 0x79470001, 0x78480001, 0x77490001, 0x764a0001,
0x754b0001, 0x744c0001, 0x734d0001, 0x724e0001, 0x714f0001,
0x70500001, 0x6f510001, 0x6e520001, 0x6d530001, 0x6c540001,
0x6b550001, 0x6a560001, 0x69570001, 0x68580001, 0x67590001,
0x665a0001, 0x655b0001, 0x645c0001, 0x635d0001, 0x625e0001,
0x615f0001, 0x60600001, 0x49610001, 0x48620001, 0x47630001,
0x46640001, 0x45650001, 0x44660001, 0x43670001, 0x42680001,
0x41690001, 0x406a0001, 0x266b0001, 0x256c0001, 0x246d0001,
0x236e0001, 0x226f0001, 0x21700001, 0x20710001, 0x06720001,
0x05730001, 0x04740001, 0x03750001, 0x02760001, 0x01770001,
0x00780001, 0x00790001, 0x007a0001, 0x007b0001, 0x007c0001,
0x007d0001, 0x007e0001, 0x007f0001, 0x3800001e, 0x3801001e,
0x3802001e, 0x3803001e, 0x3804001e, 0x3805001e, 0x3806001e,
0x3807001e, 0x3808001e, 0x3c09001e, 0x3e0a001e, 0x400b001e,
0x440c001e, 0x480d001e, 0x4c0e001e, 0x500f001e, 0x5210001e,
0x5611001e, 0x5a12001e, 0x5e13001e, 0x6014001e, 0x6015001e,
0x6016001e, 0x6217001e, 0x6218001e, 0x6219001e, 0x621a001e,
0x621b001e, 0x621c001e, 0x621d001e, 0x621e001e, 0x621f001e
};
static const struct rtwn_bb_prog rtl8188ce_bb_prog = {
__arraycount(rtl8192ce_bb_regs),
rtl8192ce_bb_regs,
rtl8188ce_bb_vals,
__arraycount(rtl8188ce_agc_vals),
rtl8188ce_agc_vals
};
static const uint32_t rtl8188cu_bb_vals[] = {
0x0011800d, 0x00ffdb83, 0x80040000, 0x00000001, 0x0000fc00,
0x0000000a, 0x10005388, 0x020c3d10, 0x02200385, 0x00000000,
0x01000100, 0x00390004, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00010000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x569a569a,
0x001b25a4, 0x66e60230, 0x061f0130, 0x00000000, 0x32323200,
0x07000700, 0x22004000, 0x00000808, 0x00000000, 0xc0083070,
0x000004d5, 0x00000000, 0xccc000c0, 0x00000800, 0xfffffffe,
0x40302010, 0x00706050, 0x00000000, 0x00000023, 0x00000000,
0x81121111, 0x00d047c8, 0x80ff000c, 0x8c838300, 0x2e68120f,
0x9500bb78, 0x11144028, 0x00881117, 0x89140f00, 0x1a1b0000,
0x090e1317, 0x00000204, 0x00d30000, 0x101fbf00, 0x00000007,
0x48071d40, 0x03a05611, 0x000000e4, 0x6c6c6c6c, 0x08800000,
0x40000100, 0x08800000, 0x40000100, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x69e9ac44, 0x469652cf, 0x49795994,
0x0a97971c, 0x1f7c403f, 0x000100b7, 0xec020107, 0x007f037f,
0x6954341e, 0x43bc0094, 0x6954341e, 0x433c0094, 0x00000000,
0x5116848b, 0x47c00bff, 0x00000036, 0x2c7f000d, 0x018610db,
0x0000001f, 0x00b91612, 0x40000100, 0x20f60000, 0x40000100,
0x20200000, 0x00121820, 0x00000000, 0x00121820, 0x00007f7f,
0x00000000, 0x00000080, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x28000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x64b22427,
0x00766932, 0x00222222, 0x00000000, 0x37644302, 0x2f97d40c,
0x00080740, 0x00020401, 0x0000907f, 0x20010201, 0xa0633333,
0x3333bc43, 0x7a8f5b6b, 0xcc979975, 0x00000000, 0x80608000,
0x00000000, 0x00027293, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x6437140a, 0x00000000, 0x00000000, 0x30032064,
0x4653de68, 0x04518a3c, 0x00002101, 0x2a201c16, 0x1812362e,
0x322c2220, 0x000e3c24, 0x2a2a2a2a, 0x2a2a2a2a, 0x03902a2a,
0x2a2a2a2a, 0x2a2a2a2a, 0x2a2a2a2a, 0x2a2a2a2a, 0x00000000,
0x1000dc1f, 0x10008c1f, 0x02140102, 0x681604c2, 0x01007c00,
0x01004800, 0xfb000000, 0x000028d1, 0x1000dc1f, 0x10008c1f,
0x02140102, 0x28160d05, 0x00000008, 0x001b25a4, 0x631b25a0,
0x631b25a0, 0x081b25a0, 0x081b25a0, 0x081b25a0, 0x081b25a0,
0x631b25a0, 0x081b25a0, 0x631b25a0, 0x631b25a0, 0x631b25a0,
0x631b25a0, 0x001b25a0, 0x001b25a0, 0x6b1b25a0, 0x00000003,
0x00000000, 0x00000300
};
static const struct rtwn_bb_prog rtl8188cu_bb_prog = {
__arraycount(rtl8192ce_bb_regs),
rtl8192ce_bb_regs,
rtl8188cu_bb_vals,
__arraycount(rtl8188ce_agc_vals),
rtl8188ce_agc_vals
};
/*
* RTL8188EU.
*/
static const uint16_t rtl8188eu_bb_regs[] = {
0x800, 0x804, 0x808, 0x80c, 0x810, 0x814, 0x818, 0x81c,
0x820, 0x824, 0x828, 0x82c, 0x830, 0x834, 0x838, 0x83c,
0x840, 0x844, 0x848, 0x84c, 0x850, 0x854, 0x858, 0x85c,
0x860, 0x864, 0x868, 0x86c, 0x870, 0x874, 0x878, 0x87c,
0x880, 0x884, 0x888, 0x88c, 0x890, 0x894, 0x898, 0x89c,
0x900, 0x904, 0x908, 0x90c, 0x910, 0x914, 0xa00, 0xa04,
0xa08, 0xa0c, 0xa10, 0xa14, 0xa18, 0xa1c, 0xa20, 0xa24,
0xa28, 0xa2c, 0xa70, 0xa74, 0xa78, 0xa7c, 0xa80, 0xb2c,
0xc00, 0xc04, 0xc08, 0xc0c, 0xc10, 0xc14, 0xc18, 0xc1c,
0xc20, 0xc24, 0xc28, 0xc2c, 0xc30, 0xc34, 0xc38, 0xc3c,
0xc40, 0xc44, 0xc48, 0xc4c, 0xc50, 0xc54, 0xc58, 0xc5c,
0xc60, 0xc64, 0xc68, 0xc6c, 0xc70, 0xc74, 0xc78, 0xc7c,
0xc80, 0xc84, 0xc88, 0xc8c, 0xc90, 0xc94, 0xc98, 0xc9c,
0xca0, 0xca4, 0xca8, 0xcac, 0xcb0, 0xcb4, 0xcb8, 0xcbc,
0xcc0, 0xcc4, 0xcc8, 0xccc, 0xcd0, 0xcd4, 0xcd8, 0xcdc,
0xce0, 0xce4, 0xce8, 0xcec, 0xd00, 0xd04, 0xd08, 0xd0c,
0xd10, 0xd14, 0xd18, 0xd2c, 0xd30, 0xd34, 0xd38, 0xd3c,
0xd40, 0xd44, 0xd48, 0xd4c, 0xd50, 0xd54, 0xd58, 0xd5c,
0xd60, 0xd64, 0xd68, 0xd6c, 0xd70, 0xd74, 0xd78, 0xe00,
0xe04, 0xe08, 0xe10, 0xe14, 0xe18, 0xe1c, 0xe28, 0xe30,
0xe34, 0xe38, 0xe3c, 0xe40, 0xe44, 0xe48, 0xe4c, 0xe50,
0xe54, 0xe58, 0xe5c, 0xe60, 0xe68, 0xe6c, 0xe70, 0xe74,
0xe78, 0xe7c, 0xe80, 0xe84, 0xe88, 0xe8c, 0xed0, 0xed4,
0xed8, 0xedc, 0xee0, 0xee8, 0xeec, 0xf14, 0xf4c, 0xf00
};
static const uint32_t rtl8188eu_bb_vals[] = {
0x80040000, 0x00000003, 0x0000fc00, 0x0000000a, 0x10001331,
0x020c3d10, 0x02200385, 0x00000000, 0x01000100, 0x00390204,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00010000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x569a11a9, 0x01000014, 0x66f60110,
0x061f0649, 0x00000000, 0x27272700, 0x07000760, 0x25004000,
0x00000808, 0x00000000, 0xb0000c1c, 0x00000001, 0x00000000,
0xccc000c0, 0x00000800, 0xfffffffe, 0x40302010, 0x00706050,
0x00000000, 0x00000023, 0x00000000, 0x81121111, 0x00000002,
0x00000201, 0x00d047c8, 0x80ff000c, 0x8c838300, 0x2e7f120f,
0x9500bb78, 0x1114d028, 0x00881117, 0x89140f00, 0x1a1b0000,
0x090e1317, 0x00000204, 0x00d30000, 0x101fbf00, 0x00000007,
0x00000900, 0x225b0606, 0x218075b1, 0x80000000, 0x48071d40,
0x03a05611, 0x000000e4, 0x6c6c6c6c, 0x08800000, 0x40000100,
0x08800000, 0x40000100, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x69e9ac47, 0x469652af, 0x49795994, 0x0a97971c,
0x1f7c403f, 0x000100b7, 0xec020107, 0x007f037f, 0x69553420,
0x43bc0094, 0x00013169, 0x00250492, 0x00000000, 0x7112848b,
0x47c00bff, 0x00000036, 0x2c7f000d, 0x020610db, 0x0000001f,
0x00b91612, 0x390000e4, 0x20f60000, 0x40000100, 0x20200000,
0x00091521, 0x00000000, 0x00121820, 0x00007f7f, 0x00000000,
0x000300a0, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x28000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x64b22427, 0x00766932,
0x00222222, 0x00000000, 0x37644302, 0x2f97d40c, 0x00000740,
0x00020401, 0x0000907f, 0x20010201, 0xa0633333, 0x3333bc43,
0x7a8f5b6f, 0xcc979975, 0x00000000, 0x80608000, 0x00000000,
0x00127353, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x6437140a, 0x00000000, 0x00000282, 0x30032064, 0x4653de68,
0x04518a3c, 0x00002101, 0x2a201c16, 0x1812362e, 0x322c2220,
0x000e3c24, 0x2d2d2d2d, 0x2d2d2d2d, 0x0390272d, 0x2d2d2d2d,
0x2d2d2d2d, 0x2d2d2d2d, 0x2d2d2d2d, 0x00000000, 0x1000dc1f,
0x10008c1f, 0x02140102, 0x681604c2, 0x01007c00, 0x01004800,
0xfb000000, 0x000028d1, 0x1000dc1f, 0x10008c1f, 0x02140102,
0x28160d05, 0x00000008, 0x001b25a4, 0x00c00014, 0x00c00014,
0x01000014, 0x01000014, 0x01000014, 0x01000014, 0x00c00014,
0x01000014, 0x00c00014, 0x00c00014, 0x00c00014, 0x00c00014,
0x00000014, 0x00000014, 0x21555448, 0x01c00014, 0x00000003,
0x00000000, 0x00000300
};
static const uint32_t rtl8188eu_agc_vals[] = {
0xfb000001, 0xfb010001, 0xfb020001, 0xfb030001, 0xfb040001,
0xfb050001, 0xfa060001, 0xf9070001, 0xf8080001, 0xf7090001,
0xf60a0001, 0xf50b0001, 0xf40c0001, 0xf30d0001, 0xf20e0001,
0xf10f0001, 0xf0100001, 0xef110001, 0xee120001, 0xed130001,
0xec140001, 0xeb150001, 0xea160001, 0xe9170001, 0xe8180001,
0xe7190001, 0xe61a0001, 0xe51b0001, 0xe41c0001, 0xe31d0001,
0xe21e0001, 0xe11f0001, 0x8a200001, 0x89210001, 0x88220001,
0x87230001, 0x86240001, 0x85250001, 0x84260001, 0x83270001,
0x82280001, 0x6b290001, 0x6a2a0001, 0x692b0001, 0x682c0001,
0x672d0001, 0x662e0001, 0x652f0001, 0x64300001, 0x63310001,
0x62320001, 0x61330001, 0x46340001, 0x45350001, 0x44360001,
0x43370001, 0x42380001, 0x41390001, 0x403a0001, 0x403b0001,
0x403c0001, 0x403d0001, 0x403e0001, 0x403f0001, 0xfb400001,
0xfb410001, 0xfb420001, 0xfb430001, 0xfb440001, 0xfb450001,
0xfb460001, 0xfb470001, 0xfb480001, 0xfa490001, 0xf94a0001,
0xf84B0001, 0xf74c0001, 0xf64d0001, 0xf54e0001, 0xf44f0001,
0xf3500001, 0xf2510001, 0xf1520001, 0xf0530001, 0xef540001,
0xee550001, 0xed560001, 0xec570001, 0xeb580001, 0xea590001,
0xe95a0001, 0xe85b0001, 0xe75c0001, 0xe65d0001, 0xe55e0001,
0xe45f0001, 0xe3600001, 0xe2610001, 0xc3620001, 0xc2630001,
0xc1640001, 0x8b650001, 0x8a660001, 0x89670001, 0x88680001,
0x87690001, 0x866a0001, 0x856b0001, 0x846c0001, 0x676d0001,
0x666e0001, 0x656f0001, 0x64700001, 0x63710001, 0x62720001,
0x61730001, 0x60740001, 0x46750001, 0x45760001, 0x44770001,
0x43780001, 0x42790001, 0x417a0001, 0x407b0001, 0x407c0001,
0x407d0001, 0x407e0001, 0x407f0001
};
static const struct rtwn_bb_prog rtl8188eu_bb_prog = {
__arraycount(rtl8188eu_bb_regs),
rtl8188eu_bb_regs,
rtl8188eu_bb_vals,
__arraycount(rtl8188eu_agc_vals),
rtl8188eu_agc_vals
};
/*
* RTL819E.
*/
static const uint16_t rtl8192eu_bb_regs[] = {
0x800, 0x804, 0x808, 0x80c, 0x810, 0x814, 0x818, 0x81c,
0x820, 0x824, 0x828, 0x82c, 0x830, 0x834, 0x838, 0x83c,
0x840, 0x844, 0x848, 0x84c, 0x850, 0x854, 0x858, 0x85c,
0x860, 0x864, 0x868, 0x86c, 0x870, 0x874, 0x878, 0x87c,
0x880, 0x884, 0x888, 0x88c, 0x890, 0x894, 0x898, 0x900,
0x904, 0x908, 0x90c, 0x910, 0x914, 0x918, 0x91c, 0x924,
0x928, 0x92c, 0x930, 0x934, 0x938, 0x93c, 0x940, 0x944,
0x94c, 0xa00, 0xa04, 0xa08, 0xa0c, 0xa10, 0xa14, 0xa18,
0xa1c, 0xa20, 0xa24, 0xa28, 0xa2c, 0xa70, 0xa74, 0xa78,
0xa7c, 0xa80, 0xb38, 0xc00, 0xc04, 0xc08, 0xc0c, 0xc10,
0xc14, 0xc18, 0xc1c, 0xc20, 0xc24, 0xc28, 0xc2c, 0xc30,
0xc34, 0xc38, 0xc3c, 0xc40, 0xc44, 0xc48, 0xc4c, 0xc50,
0xc54, 0xc58, 0xc5c, 0xc60, 0xc64, 0xc68, 0xc6c, 0xc70,
0xc74, 0xc78, 0xc7c, 0xc80, 0xc84, 0xc88, 0xc8c, 0xc90,
0xc94, 0xc98, 0xc9c, 0xca0, 0xca4, 0xca8, 0xcac, 0xcb0,
0xcb4, 0xcb8, 0xcbc, 0xcc0, 0xcc4, 0xcc8, 0xccc, 0xcd0,
0xcd4, 0xcd8, 0xcdc, 0xce0, 0xce4, 0xce8, 0xcec, 0xd00,
0xd04, 0xd08, 0xd0c, 0xd10, 0xd14, 0xd18, 0xd1c, 0xd2c,
0xd30, 0xd34, 0xd38, 0xd3c, 0xd40, 0xd44, 0xd48, 0xd4c,
0xd50, 0xd54, 0xd58, 0xd5c, 0xd60, 0xd64, 0xd68, 0xd6c,
0xd70, 0xd74, 0xd78, 0xd80, 0xd84, 0xd88, 0xe00, 0xe04,
0xe08, 0xe10, 0xe14, 0xe18, 0xe1c, 0xe28, 0xe30, 0xe34,
0xe38, 0xe3c, 0xe40, 0xe44, 0xe48, 0xe4c, 0xe50, 0xe54,
0xe58, 0xe5c, 0xe60, 0xe68, 0xe6c, 0xe70, 0xe74, 0xe78,
0xe7c, 0xe80, 0xe84, 0xe88, 0xe8c, 0xed0, 0xed4, 0xed8,
0xedc, 0xee0, 0xeec, 0xee4, 0xee8, 0xf14, 0xf4c, 0xf00,
};
static const uint32_t rtl8192eu_bb_vals[] = {
0x80040000, 0x00000003, 0x0000fc00, 0x0000000a, 0x10001331,
0x020c3d10, 0x02220385, 0x00000000, 0x01000100, 0x00390204,
0x01000100, 0x00390204, 0x32323232, 0x30303030, 0x30303030,
0x30303030, 0x00010000, 0x00010000, 0x28282828, 0x28282828,
0x00000000, 0x00000000, 0x009a009a, 0x01000014, 0x66f60000,
0x061f0000, 0x30303030, 0x30303030, 0x00000000, 0x55004200,
0x08080808, 0x00000000, 0xb0000c1c, 0x00000001, 0x00000000,
0xcc0000c0, 0x00000800, 0xfffffffe, 0x40302010, 0x00000000,
0x00000023, 0x00000000, 0x81121313, 0x806c0001, 0x00000001,
0x00000000, 0x00010000, 0x00000001, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000008, 0x00d0c7c8, 0x81ff000c, 0x8c838300,
0x2e68120f, 0x95009b78, 0x1114d028, 0x00881117, 0x89140f00,
0x1a1b0000, 0x090e1317, 0x00000204, 0x00d30000, 0x101fff00,
0x00000007, 0x00000900, 0x225b0606, 0x218075b1, 0x00000000,
0x48071d40, 0x03a05633, 0x000000e4, 0x6c6c6c6c, 0x08800000,
0x40000100, 0x08800000, 0x40000100, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x69e9ac47, 0x469652af, 0x49795994,
0x0a97971c, 0x1f7c403f, 0x000100b7, 0xec020107, 0x007f037f,
0x00340020, 0x0080801f, 0x00000020, 0x00248492, 0x00000000,
0x7112848b, 0x47c00bff, 0x00000036, 0x00000600, 0x02013169,
0x0000001f, 0x00b91612, 0x40000100, 0x21f60000, 0x40000100,
0xa0e40000, 0x00121820, 0x00000000, 0x00121820, 0x00007f7f,
0x00000000, 0x000300a0, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x28000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x64b22427,
0x00766932, 0x00222222, 0x00040000, 0x77644302, 0x2f97d40c,
0x00080740, 0x00020403, 0x0000907f, 0x20010201, 0xa0633333,
0x3333bc43, 0x7a8f5b6b, 0x0000007f, 0xcc979975, 0x00000000,
0x80608000, 0x00000000, 0x00127353, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x6437140a, 0x00000000, 0x00000282,
0x30032064, 0x4653de68, 0x04518a3c, 0x00002101, 0x2a201c16,
0x1812362e, 0x322c2220, 0x000e3c24, 0x01081008, 0x00000800,
0xf0b50000, 0x30303030, 0x30303030, 0x03903030, 0x30303030,
0x30303030, 0x30303030, 0x30303030, 0x00000000, 0x1000dc1f,
0x10008c1f, 0x02140102, 0x681604c2, 0x01007c00, 0x01004800,
0xfb000000, 0x000028d1, 0x1000dc1f, 0x10008c1f, 0x02140102,
0x28160d05, 0x00000008, 0x0fc05656, 0x03c09696, 0x03c09696,
0x0c005656, 0x0c005656, 0x0c005656, 0x0c005656, 0x03c09696,
0x0c005656, 0x03c09696, 0x03c09696, 0x03c09696, 0x03c09696,
0x0000d6d6, 0x0000d6d6, 0x0fc01616, 0xb0000c1c, 0x00000001,
0x00000003, 0x00000000, 0x00000300,
};
static const uint32_t rtl8192eu_agc_vals[] = {
0xfb000001, 0xfb010001, 0xfb020001, 0xfb030001, 0xfb040001,
0xfb050001, 0xfa060001, 0xf9070001, 0xf8080001, 0xf7090001,
0xf60a0001, 0xf50b0001, 0xf40c0001, 0xf30d0001, 0xf20e0001,
0xf10f0001, 0xf0100001, 0xef110001, 0xee120001, 0xed130001,
0xec140001, 0xeb150001, 0xea160001, 0xe9170001, 0xe8180001,
0xe7190001, 0xc81a0001, 0xc71b0001, 0xc61c0001, 0x071d0001,
0x061e0001, 0x051f0001, 0x04200001, 0x03210001, 0xaa220001,
0xa9230001, 0xa8240001, 0xa7250001, 0xa6260001, 0x85270001,
0x84280001, 0x83290001, 0x252a0001, 0x242b0001, 0x232c0001,
0x222d0001, 0x672e0001, 0x662f0001, 0x65300001, 0x64310001,
0x63320001, 0x62330001, 0x61340001, 0x45350001, 0x44360001,
0x43370001, 0x42380001, 0x41390001, 0x403a0001, 0x403b0001,
0x403c0001, 0x403d0001, 0x403e0001, 0x403f0001, 0xfb400001,
0xfb410001, 0xfb420001, 0xfb430001, 0xfb440001, 0xfb450001,
0xfa460001, 0xf9470001, 0xf8480001, 0xf7490001, 0xf64a0001,
0xf54b0001, 0xf44c0001, 0xf34d0001, 0xf24e0001, 0xf14f0001,
0xf0500001, 0xef510001, 0xee520001, 0xed530001, 0xec540001,
0xeb550001, 0xea560001, 0xe9570001, 0xe8580001, 0xe7590001,
0xe65a0001, 0xe55b0001, 0xe45c0001, 0xe35d0001, 0xe25e0001,
0xe15f0001, 0x8a600001, 0x89610001, 0x88620001, 0x87630001,
0x86640001, 0x85650001, 0x84660001, 0x83670001, 0x82680001,
0x6b690001, 0x6a6a0001, 0x696b0001, 0x686c0001, 0x676d0001,
0x666e0001, 0x656f0001, 0x64700001, 0x63710001, 0x62720001,
0x61730001, 0x49740001, 0x48750001, 0x47760001, 0x46770001,
0x45780001, 0x44790001, 0x437a0001, 0x427b0001, 0x417c0001,
0x407d0001, 0x407e0001, 0x407f0001,
};
static const struct rtwn_bb_prog rtl8192eu_bb_prog = {
__arraycount(rtl8192eu_bb_regs),
rtl8192eu_bb_regs,
rtl8192eu_bb_vals,
__arraycount(rtl8192eu_agc_vals),
rtl8192eu_agc_vals
};
/*
* RTL8188RU.
*/
static const uint16_t rtl8188ru_bb_regs[] = {
0x024, 0x028, 0x040, 0x800, 0x804, 0x808, 0x80c, 0x810, 0x814,
0x818, 0x81c, 0x820, 0x824, 0x828, 0x82c, 0x830, 0x834, 0x838,
0x83c, 0x840, 0x844, 0x848, 0x84c, 0x850, 0x854, 0x858, 0x85c,
0x860, 0x864, 0x868, 0x86c, 0x870, 0x874, 0x878, 0x87c, 0x880,
0x884, 0x888, 0x88c, 0x890, 0x894, 0x898, 0x89c, 0x900, 0x904,
0x908, 0x90c, 0xa00, 0xa04, 0xa08, 0xa0c, 0xa10, 0xa14, 0xa18,
0xa1c, 0xa20, 0xa24, 0xa28, 0xa2c, 0xa70, 0xa74, 0xc00, 0xc04,
0xc08, 0xc0c, 0xc10, 0xc14, 0xc18, 0xc1c, 0xc20, 0xc24, 0xc28,
0xc2c, 0xc30, 0xc34, 0xc38, 0xc3c, 0xc40, 0xc44, 0xc48, 0xc4c,
0xc50, 0xc54, 0xc58, 0xc5c, 0xc60, 0xc64, 0xc68, 0xc6c, 0xc70,
0xc74, 0xc78, 0xc7c, 0xc80, 0xc84, 0xc88, 0xc8c, 0xc90, 0xc94,
0xc98, 0xc9c, 0xca0, 0xca4, 0xca8, 0xcac, 0xcb0, 0xcb4, 0xcb8,
0xcbc, 0xcc0, 0xcc4, 0xcc8, 0xccc, 0xcd0, 0xcd4, 0xcd8, 0xcdc,
0xce0, 0xce4, 0xce8, 0xcec, 0xd00, 0xd04, 0xd08, 0xd0c, 0xd10,
0xd14, 0xd18, 0xd2c, 0xd30, 0xd34, 0xd38, 0xd3c, 0xd40, 0xd44,
0xd48, 0xd4c, 0xd50, 0xd54, 0xd58, 0xd5c, 0xd60, 0xd64, 0xd68,
0xd6c, 0xd70, 0xd74, 0xd78, 0xe00, 0xe04, 0xe08, 0xe10, 0xe14,
0xe18, 0xe1c, 0xe28, 0xe30, 0xe34, 0xe38, 0xe3c, 0xe40, 0xe44,
0xe48, 0xe4c, 0xe50, 0xe54, 0xe58, 0xe5c, 0xe60, 0xe68, 0xe6c,
0xe70, 0xe74, 0xe78, 0xe7c, 0xe80, 0xe84, 0xe88, 0xe8c, 0xed0,
0xed4, 0xed8, 0xedc, 0xee0, 0xeec, 0xee8, 0xf14, 0xf4c, 0xf00
};
static const uint32_t rtl8188ru_bb_vals[] = {
0x0011800d, 0x00ffdb83, 0x000c0004, 0x80040000, 0x00000001,
0x0000fc00, 0x0000000a, 0x10005388, 0x020c3d10, 0x02200385,
0x00000000, 0x01000100, 0x00390204, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00010000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x569a569a, 0x001b25a4, 0x66e60230, 0x061f0130, 0x00000000,
0x32323200, 0x03000300, 0x22004000, 0x00000808, 0x00ffc3f1,
0xc0083070, 0x000004d5, 0x00000000, 0xccc000c0, 0x00000800,
0xfffffffe, 0x40302010, 0x00706050, 0x00000000, 0x00000023,
0x00000000, 0x81121111, 0x00d047c8, 0x80ff000c, 0x8c838300,
0x2e68120f, 0x9500bb78, 0x11144028, 0x00881117, 0x89140f00,
0x15160000, 0x070b0f12, 0x00000104, 0x00d30000, 0x101fbf00,
0x00000007, 0x48071d40, 0x03a05611, 0x000000e4, 0x6c6c6c6c,
0x08800000, 0x40000100, 0x08800000, 0x40000100, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x69e9ac44, 0x469652cf,
0x49795994, 0x0a97971c, 0x1f7c403f, 0x000100b7, 0xec020107,
0x007f037f, 0x6954342e, 0x43bc0094, 0x6954342f, 0x433c0094,
0x00000000, 0x5116848b, 0x47c00bff, 0x00000036, 0x2c56000d,
0x018610db, 0x0000001f, 0x00b91612, 0x24000090, 0x20f60000,
0x24000090, 0x20200000, 0x00121820, 0x00000000, 0x00121820,
0x00007f7f, 0x00000000, 0x00000080, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x28000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x64b22427, 0x00766932, 0x00222222, 0x00000000, 0x37644302,
0x2f97d40c, 0x00080740, 0x00020401, 0x0000907f, 0x20010201,
0xa0633333, 0x3333bc43, 0x7a8f5b6b, 0xcc979975, 0x00000000,
0x80608000, 0x00000000, 0x00027293, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x6437140a, 0x00000000, 0x00000000,
0x30032064, 0x4653de68, 0x04518a3c, 0x00002101, 0x2a201c16,
0x1812362e, 0x322c2220, 0x000e3c24, 0x2a2a2a2a, 0x2a2a2a2a,
0x03902a2a, 0x2a2a2a2a, 0x2a2a2a2a, 0x2a2a2a2a, 0x2a2a2a2a,
0x00000000, 0x1000dc1f, 0x10008c1f, 0x02140102, 0x681604c2,
0x01007c00, 0x01004800, 0xfb000000, 0x000028d1, 0x1000dc1f,
0x10008c1f, 0x02140102, 0x28160d05, 0x00000010, 0x001b25a4,
0x631b25a0, 0x631b25a0, 0x081b25a0, 0x081b25a0, 0x081b25a0,
0x081b25a0, 0x631b25a0, 0x081b25a0, 0x631b25a0, 0x631b25a0,
0x631b25a0, 0x631b25a0, 0x001b25a0, 0x001b25a0, 0x6b1b25a0,
0x31555448, 0x00000003, 0x00000000, 0x00000300
};
static const uint32_t rtl8188ru_agc_vals[] = {
0x7b000001, 0x7b010001, 0x7b020001, 0x7b030001, 0x7b040001,
0x7b050001, 0x7b060001, 0x7b070001, 0x7b080001, 0x7a090001,
0x790a0001, 0x780b0001, 0x770c0001, 0x760d0001, 0x750e0001,
0x740f0001, 0x73100001, 0x72110001, 0x71120001, 0x70130001,
0x6f140001, 0x6e150001, 0x6d160001, 0x6c170001, 0x6b180001,
0x6a190001, 0x691a0001, 0x681b0001, 0x671c0001, 0x661d0001,
0x651e0001, 0x641f0001, 0x63200001, 0x62210001, 0x61220001,
0x60230001, 0x46240001, 0x45250001, 0x44260001, 0x43270001,
0x42280001, 0x41290001, 0x402a0001, 0x262b0001, 0x252c0001,
0x242d0001, 0x232e0001, 0x222f0001, 0x21300001, 0x20310001,
0x06320001, 0x05330001, 0x04340001, 0x03350001, 0x02360001,
0x01370001, 0x00380001, 0x00390001, 0x003a0001, 0x003b0001,
0x003c0001, 0x003d0001, 0x003e0001, 0x003f0001, 0x7b400001,
0x7b410001, 0x7b420001, 0x7b430001, 0x7b440001, 0x7b450001,
0x7b460001, 0x7b470001, 0x7b480001, 0x7a490001, 0x794a0001,
0x784b0001, 0x774c0001, 0x764d0001, 0x754e0001, 0x744f0001,
0x73500001, 0x72510001, 0x71520001, 0x70530001, 0x6f540001,
0x6e550001, 0x6d560001, 0x6c570001, 0x6b580001, 0x6a590001,
0x695a0001, 0x685b0001, 0x675c0001, 0x665d0001, 0x655e0001,
0x645f0001, 0x63600001, 0x62610001, 0x61620001, 0x60630001,
0x46640001, 0x45650001, 0x44660001, 0x43670001, 0x42680001,
0x41690001, 0x406a0001, 0x266b0001, 0x256c0001, 0x246d0001,
0x236e0001, 0x226f0001, 0x21700001, 0x20710001, 0x06720001,
0x05730001, 0x04740001, 0x03750001, 0x02760001, 0x01770001,
0x00780001, 0x00790001, 0x007a0001, 0x007b0001, 0x007c0001,
0x007d0001, 0x007e0001, 0x007f0001, 0x3800001e, 0x3801001e,
0x3802001e, 0x3803001e, 0x3804001e, 0x3805001e, 0x3806001e,
0x3807001e, 0x3808001e, 0x3c09001e, 0x3e0a001e, 0x400b001e,
0x440c001e, 0x480d001e, 0x4c0e001e, 0x500f001e, 0x5210001e,
0x5611001e, 0x5a12001e, 0x5e13001e, 0x6014001e, 0x6015001e,
0x6016001e, 0x6217001e, 0x6218001e, 0x6219001e, 0x621a001e,
0x621b001e, 0x621c001e, 0x621d001e, 0x621e001e, 0x621f001e
};
static const struct rtwn_bb_prog rtl8188ru_bb_prog = {
__arraycount(rtl8188ru_bb_regs),
rtl8188ru_bb_regs,
rtl8188ru_bb_vals,
__arraycount(rtl8188ru_agc_vals),
rtl8188ru_agc_vals
};
/*
* RF initialization values.
*/
struct rtwn_rf_prog {
int count;
const uint8_t *regs;
const uint32_t *vals;
};
/*
* RTL8192CU and RTL8192CE-VAU.
*/
static const uint8_t rtl8192ce_rf1_regs[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
0x0f, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22,
0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2a, 0x2b,
0x2a, 0x2b, 0x2b, 0x2c, 0x2a, 0x2b, 0x2b, 0x2c, 0x2a, 0x2b, 0x2b,
0x2c, 0x2a, 0x2b, 0x2b, 0x2c, 0x2a, 0x2b, 0x2b, 0x2c, 0x2a, 0x2b,
0x2b, 0x2c, 0x2a, 0x2b, 0x2b, 0x2c, 0x2a, 0x2b, 0x2b, 0x2c, 0x2a,
0x2b, 0x2b, 0x2c, 0x2a, 0x2b, 0x2b, 0x2c, 0x2a, 0x2b, 0x2b, 0x2c,
0x2a, 0x2b, 0x2b, 0x2c, 0x2a, 0x2b, 0x2b, 0x2c, 0x2a, 0x2b, 0x2b,
0x2c, 0x2a, 0x10, 0x11, 0x10, 0x11, 0x10, 0x11, 0x10, 0x11, 0x10,
0x11, 0x10, 0x11, 0x10, 0x11, 0x12, 0x12, 0x12, 0x12, 0x13, 0x13,
0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x14, 0x14,
0x14, 0x14, 0x15, 0x15, 0x15, 0x15, 0x16, 0x16, 0x16, 0x16, 0x00,
0x18, 0xfe, 0xfe, 0x1f, 0xfe, 0xfe, 0x1e, 0x1f, 0x00
};
static const uint32_t rtl8192ce_rf1_vals[] = {
0x30159, 0x31284, 0x98000, 0x18c63, 0x210e7, 0x2044f, 0x1adb1,
0x54867, 0x8992e, 0x0e52c, 0x39ce7, 0x00451, 0x00000, 0x10255,
0x60a00, 0xfc378, 0xa1250, 0x4445f, 0x80001, 0x0b614, 0x6c000,
0x00000, 0x01558, 0x00060, 0x00483, 0x4f000, 0xec7d9, 0x577c0,
0x04783, 0x00001, 0x21334, 0x00000, 0x00054, 0x00001, 0x00808,
0x53333, 0x0000c, 0x00002, 0x00808, 0x5b333, 0x0000d, 0x00003,
0x00808, 0x63333, 0x0000d, 0x00004, 0x00808, 0x6b333, 0x0000d,
0x00005, 0x00808, 0x73333, 0x0000d, 0x00006, 0x00709, 0x5b333,
0x0000d, 0x00007, 0x00709, 0x63333, 0x0000d, 0x00008, 0x0060a,
0x4b333, 0x0000d, 0x00009, 0x0060a, 0x53333, 0x0000d, 0x0000a,
0x0060a, 0x5b333, 0x0000d, 0x0000b, 0x0060a, 0x63333, 0x0000d,
0x0000c, 0x0060a, 0x6b333, 0x0000d, 0x0000d, 0x0060a, 0x73333,
0x0000d, 0x0000e, 0x0050b, 0x66666, 0x0001a, 0xe0000, 0x4000f,
0xe31fc, 0x6000f, 0xff9f8, 0x2000f, 0x203f9, 0x3000f, 0xff500,
0x00000, 0x00000, 0x8000f, 0x3f100, 0x9000f, 0x23100, 0x32000,
0x71000, 0xb0000, 0xfc000, 0x287af, 0x244b7, 0x204ab, 0x1c49f,
0x18493, 0x14297, 0x10295, 0x0c298, 0x0819c, 0x040a8, 0x0001c,
0x1944c, 0x59444, 0x9944c, 0xd9444, 0x0f424, 0x4f424, 0x8f424,
0xcf424, 0xe0330, 0xa0330, 0x60330, 0x20330, 0x10159, 0x0f401,
0x00000, 0x00000, 0x80003, 0x00000, 0x00000, 0x44457, 0x80000,
0x30159
};
static const uint8_t rtl8192ce_rf2_regs[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
0x0f, 0x12, 0x12, 0x12, 0x12, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13,
0x13, 0x13, 0x13, 0x13, 0x13, 0x14, 0x14, 0x14, 0x14, 0x15, 0x15,
0x15, 0x15, 0x16, 0x16, 0x16, 0x16
};
static const uint32_t rtl8192ce_rf2_vals[] = {
0x30159, 0x31284, 0x98000, 0x18c63, 0x210e7, 0x2044f, 0x1adb1,
0x54867, 0x8992e, 0x0e52c, 0x39ce7, 0x00451, 0x32000, 0x71000,
0xb0000, 0xfc000, 0x287af, 0x244b7, 0x204ab, 0x1c49f, 0x18493,
0x14297, 0x10295, 0x0c298, 0x0819c, 0x040a8, 0x0001c, 0x1944c,
0x59444, 0x9944c, 0xd9444, 0x0f424, 0x4f424, 0x8f424, 0xcf424,
0xe0330, 0xa0330, 0x60330, 0x20330
};
static const struct rtwn_rf_prog rtl8192ce_rf_prog[] = {
{
__arraycount(rtl8192ce_rf1_regs),
rtl8192ce_rf1_regs,
rtl8192ce_rf1_vals
},
{
__arraycount(rtl8192ce_rf2_regs),
rtl8192ce_rf2_regs,
rtl8192ce_rf2_vals
}
};
/*
* RTL8188CE-VAU.
*/
static const uint32_t rtl8188ce_rf_vals[] = {
0x30159, 0x31284, 0x98000, 0x18c63, 0x210e7, 0x2044f, 0x1adb1,
0x54867, 0x8992e, 0x0e52c, 0x39ce7, 0x00451, 0x00000, 0x10255,
0x60a00, 0xfc378, 0xa1250, 0x4445f, 0x80001, 0x0b614, 0x6c000,
0x00000, 0x01558, 0x00060, 0x00483, 0x4f200, 0xec7d9, 0x577c0,
0x04783, 0x00001, 0x21334, 0x00000, 0x00054, 0x00001, 0x00808,
0x53333, 0x0000c, 0x00002, 0x00808, 0x5b333, 0x0000d, 0x00003,
0x00808, 0x63333, 0x0000d, 0x00004, 0x00808, 0x6b333, 0x0000d,
0x00005, 0x00808, 0x73333, 0x0000d, 0x00006, 0x00709, 0x5b333,
0x0000d, 0x00007, 0x00709, 0x63333, 0x0000d, 0x00008, 0x0060a,
0x4b333, 0x0000d, 0x00009, 0x0060a, 0x53333, 0x0000d, 0x0000a,
0x0060a, 0x5b333, 0x0000d, 0x0000b, 0x0060a, 0x63333, 0x0000d,
0x0000c, 0x0060a, 0x6b333, 0x0000d, 0x0000d, 0x0060a, 0x73333,
0x0000d, 0x0000e, 0x0050b, 0x66666, 0x0001a, 0xe0000, 0x4000f,
0xe31fc, 0x6000f, 0xff9f8, 0x2000f, 0x203f9, 0x3000f, 0xff500,
0x00000, 0x00000, 0x8000f, 0x3f100, 0x9000f, 0x23100, 0x32000,
0x71000, 0xb0000, 0xfc000, 0x287b3, 0x244b7, 0x204ab, 0x1c49f,
0x18493, 0x1429b, 0x10299, 0x0c29c, 0x081a0, 0x040ac, 0x00020,
0x1944c, 0x59444, 0x9944c, 0xd9444, 0x0f424, 0x4f424, 0x8f424,
0xcf424, 0xe0330, 0xa0330, 0x60330, 0x20330, 0x10159, 0x0f401,
0x00000, 0x00000, 0x80003, 0x00000, 0x00000, 0x44457, 0x80000,
0x30159
};
static const struct rtwn_rf_prog rtl8188ce_rf_prog[] = {
{
__arraycount(rtl8192ce_rf1_regs),
rtl8192ce_rf1_regs,
rtl8188ce_rf_vals
}
};
/*
* RTL8188CU.
*/
static const uint32_t rtl8188cu_rf_vals[] = {
0x30159, 0x31284, 0x98000, 0x18c63, 0x210e7, 0x2044f, 0x1adb1,
0x54867, 0x8992e, 0x0e52c, 0x39ce7, 0x00451, 0x00000, 0x10255,
0x60a00, 0xfc378, 0xa1250, 0x4445f, 0x80001, 0x0b614, 0x6c000,
0x00000, 0x01558, 0x00060, 0x00483, 0x4f000, 0xec7d9, 0x577c0,
0x04783, 0x00001, 0x21334, 0x00000, 0x00054, 0x00001, 0x00808,
0x53333, 0x0000c, 0x00002, 0x00808, 0x5b333, 0x0000d, 0x00003,
0x00808, 0x63333, 0x0000d, 0x00004, 0x00808, 0x6b333, 0x0000d,
0x00005, 0x00808, 0x73333, 0x0000d, 0x00006, 0x00709, 0x5b333,
0x0000d, 0x00007, 0x00709, 0x63333, 0x0000d, 0x00008, 0x0060a,
0x4b333, 0x0000d, 0x00009, 0x0060a, 0x53333, 0x0000d, 0x0000a,
0x0060a, 0x5b333, 0x0000d, 0x0000b, 0x0060a, 0x63333, 0x0000d,
0x0000c, 0x0060a, 0x6b333, 0x0000d, 0x0000d, 0x0060a, 0x73333,
0x0000d, 0x0000e, 0x0050b, 0x66666, 0x0001a, 0xe0000, 0x4000f,
0xe31fc, 0x6000f, 0xff9f8, 0x2000f, 0x203f9, 0x3000f, 0xff500,
0x00000, 0x00000, 0x8000f, 0x3f100, 0x9000f, 0x23100, 0x32000,
0x71000, 0xb0000, 0xfc000, 0x287b3, 0x244b7, 0x204ab, 0x1c49f,
0x18493, 0x1429b, 0x10299, 0x0c29c, 0x081a0, 0x040ac, 0x00020,
0x1944c, 0x59444, 0x9944c, 0xd9444, 0x0f405, 0x4f405, 0x8f405,
0xcf405, 0xe0330, 0xa0330, 0x60330, 0x20330, 0x10159, 0x0f401,
0x00000, 0x00000, 0x80003, 0x00000, 0x00000, 0x44457, 0x80000,
0x30159
};
static const struct rtwn_rf_prog rtl8188cu_rf_prog[] = {
{
__arraycount(rtl8192ce_rf1_regs),
rtl8192ce_rf1_regs,
rtl8188cu_rf_vals
}
};
/*
* RTL8192EU.
*/
static const uint8_t rtl8192eu_rf_regs[] = {
0x7f, 0x81, 0x00, 0x08, 0x18, 0x19, 0x1b, 0x1e, 0x1f, 0x2f,
0x3f, 0x42, 0x57, 0x58, 0x67, 0x83, 0xb0, 0xb1, 0xb2, 0xb4,
0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbf, 0xc2, 0xc3,
0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xdf, 0xef, 0x51,
0x52, 0x53, 0x56, 0x35, 0x35, 0x35, 0x36, 0x36, 0x36, 0x36,
0x18, 0x5a, 0x19, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34,
0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34,
0x34, 0x34, 0x34, 0x34, 0x34, 0x00, 0x84, 0x86, 0x87, 0x8e,
0x8f, 0xef, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
0xef, 0xfe, 0x18, 0xfe, 0xfe, 0xfe, 0xfe, 0x1e, 0x1f, 0x00,
};
static const uint32_t rtl8192eu_rf_vals[] = {
0x00082, 0x3fc00, 0x30000, 0x08400, 0x00407, 0x00012, 0x00064,
0x80009, 0x00880, 0x1a060, 0x00000, 0x060c0, 0xd0000, 0xbe180,
0x01552, 0x00000, 0xff9f1, 0x55418, 0x8cc00, 0x43083, 0x08166,
0x0803e, 0x1c69f, 0x0407f, 0x80001, 0x40001, 0x00400, 0xc0000,
0x02400, 0x00009, 0x40c91, 0x99999, 0x000a3, 0x88820, 0x76c06,
0x00000, 0x80000, 0x00180, 0x001a0, 0x69545, 0x7e45e, 0x00071,
0x51ff3, 0x000a8, 0x001e2, 0x002a8, 0x01c24, 0x09c24, 0x11c24,
0x19c24, 0x00c07, 0x48000, 0x739d0, 0x0a093, 0x0908f, 0x0808c,
0x0704d, 0x0604a, 0x05047, 0x0400a, 0x03007, 0x02004, 0x01001,
0x00000, 0x0add7, 0x09dd4, 0x08dd1, 0x07dce, 0x06dcb, 0x05dc8,
0x04dc5, 0x034cc, 0x0244f, 0x0144c, 0x00014, 0x30159, 0x68180,
0x0014e, 0x48e00, 0x65540, 0x88000, 0x020a0, 0xf07b0, 0xf02b0,
0xef7b0, 0xd4fb0, 0xcf060, 0xb0090, 0xa0080, 0x90080, 0x8f780,
0x787b0, 0x78730, 0x60fb0, 0x5ffa0, 0x40620, 0x37090, 0x20080,
0x1f060, 0x0ffb0, 0x000a0, 0x00000, 0x0fc07, 0x00000, 0x00000,
0x00000, 0x00000, 0x00001, 0x80000, 0x33e70,
};
static const uint8_t rtl8192eu_rf2_regs[] = {
0x7f, 0x81, 0x00, 0x08, 0x18, 0x19, 0x1b, 0x1e, 0x1f, 0x2f,
0x3f, 0x42, 0x57, 0x58, 0x67, 0x7f, 0x81, 0x83, 0xdf, 0xef,
0x51, 0x52, 0x53, 0x56, 0x35, 0x35, 0x35, 0x36, 0x36, 0x36,
0x36, 0x18, 0x5a, 0x19, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34,
0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34,
0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x00, 0x84, 0x86, 0x87,
0x8e, 0x8f, 0xef, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
0x3b, 0xef, 0x00, 0xfe, 0xfe, 0xfe, 0xfe, 0x1e, 0x1f, 0x00,
};
static const uint32_t rtl8192eu_rf2_vals[] = {
0x00082, 0x3fc00, 0x30000, 0x08400, 0x00407, 0x00012, 0x00064,
0x80009, 0x00880, 0x1a060, 0x00000, 0x060c0, 0xd0000, 0xbe180,
0x01552, 0x00082, 0x3f000, 0x00000, 0x00180, 0x001a0, 0x69545,
0x7e42e, 0x00071, 0x51ff3, 0x000a8, 0x001e0, 0x002a8, 0x01ca8,
0x09c24, 0x11c24, 0x19c24, 0x00c07, 0x48000, 0x739d0, 0x0a093,
0x0908f, 0x0808c, 0x0704d, 0x0604a, 0x05047, 0x0400a, 0x03007,
0x02004, 0x01001, 0x00000, 0x0add7, 0x09dd4, 0x08dd1, 0x07dce,
0x06dcb, 0x05dc8, 0x04dc5, 0x034cc, 0x0244f, 0x0144c, 0x00014,
0x30159, 0x68180, 0x000ce, 0x48a00, 0x65540, 0x88000, 0x020a0,
0xf07b0, 0xf02b0, 0xef7b0, 0xd4fb0, 0xcf060, 0xb0090, 0xa0080,
0x90080, 0x8f780, 0x787b0, 0x78730, 0x60fb0, 0x5ffa0, 0x40620,
0x37090, 0x20080, 0x1f060, 0x0ffb0, 0x000a0, 0x10159, 0x00000,
0x00000, 0x00000, 0x00000, 0x00001, 0x80000, 0x33e70,
};
static const struct rtwn_rf_prog rtl8192eu_rf_prog[] = {
{
__arraycount(rtl8192eu_rf_regs),
rtl8192eu_rf_regs,
rtl8192eu_rf_vals
},
{
__arraycount(rtl8192eu_rf2_regs),
rtl8192eu_rf2_regs,
rtl8192eu_rf2_vals
}
};
/*
* RTL8188EU.
*/
static const uint8_t rtl8188eu_rf_regs[] = {
0x00, 0x08, 0x18, 0x19, 0x1e, 0x1f, 0x2f, 0x3f, 0x42, 0x57,
0x58, 0x67, 0x83, 0xb0, 0xb1, 0xb2, 0xb4, 0xb6, 0xb7, 0xb8,
0xb9, 0xba, 0xbb, 0xbf, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
0xc8, 0xc9, 0xca, 0xdf, 0xef, 0x51, 0x52, 0x53, 0x56,
0x35, 0x35, 0x35, 0x36, 0x36, 0x36, 0x36, 0xb6, 0x18, 0x5a,
0x19, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34, 0x34,
0x34, 0x34, 0x00, 0x84, 0x86, 0x87, 0x8e, 0x8f, 0xef, 0x3b,
0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b,
0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0xef, 0x00, 0x18, 0xfe, 0xfe,
0x1f, 0xfe, 0xfe, 0x1e, 0x1f, 0x00
};
static const uint32_t rtl8188eu_rf_vals[] = {
0x30000, 0x84000, 0x00407, 0x00012, 0x80009, 0x00880, 0x1a060,
0x00000, 0x060c0, 0xd0000, 0xbe180, 0x01552, 0x00000, 0xff8fc,
0x54400, 0xccc19, 0x43003, 0x4953e, 0x1c718, 0x060ff, 0x80001,
0x40000, 0x00400, 0xc0000, 0x02400, 0x00009, 0x40c91, 0x99999,
0x000a3, 0x88820, 0x76c06, 0x00000, 0x80000, 0x00180, 0x001a0,
0x6b27d, 0x7e49d, 0x00073, 0x51ff3, 0x00086, 0x00186,
0x00286, 0x01c25, 0x09c25, 0x11c25, 0x19c25, 0x48538, 0x00c07,
0x4bd00, 0x739d0, 0x0adf3, 0x09df0, 0x08ded, 0x07dea, 0x06de7,
0x054ee, 0x044eb, 0x034e8, 0x0246b, 0x01468, 0x0006d, 0x30159,
0x68200, 0x000ce, 0x48a00, 0x65540, 0x88000, 0x020a0, 0xf02b0,
0xef7b0, 0xd4fb0, 0xcf060, 0xb0090, 0xa0080, 0x90080, 0x8f780,
0x722b0, 0x6f7b0, 0x54fb0, 0x4f060, 0x30090, 0x20080, 0x10080,
0x0f780, 0x000a0, 0x10159, 0x0f407, 0x00000, 0x00000, 0x80003,
0x00000, 0x00000, 0x00001, 0x80000, 0x33e60
};
static const struct rtwn_rf_prog rtl8188eu_rf_prog[] = {
{
__arraycount(rtl8188eu_rf_regs),
rtl8188eu_rf_regs,
rtl8188eu_rf_vals
}
};
/*
* RTL8188RU.
*/
static const uint32_t rtl8188ru_rf_vals[] = {
0x30159, 0x31284, 0x98000, 0x18c63, 0x210e7, 0x2044f, 0x1adb0,
0x54867, 0x8992e, 0x0e529, 0x39ce7, 0x00451, 0x00000, 0x00255,
0x60a00, 0xfc378, 0xa1250, 0x4445f, 0x80001, 0x0b614, 0x6c000,
0x0083c, 0x01558, 0x00060, 0x00483, 0x4f000, 0xec7d9, 0x977c0,
0x04783, 0x00001, 0x21334, 0x00000, 0x00054, 0x00001, 0x00808,
0x53333, 0x0000c, 0x00002, 0x00808, 0x5b333, 0x0000d, 0x00003,
0x00808, 0x63333, 0x0000d, 0x00004, 0x00808, 0x6b333, 0x0000d,
0x00005, 0x00808, 0x73333, 0x0000d, 0x00006, 0x00709, 0x5b333,
0x0000d, 0x00007, 0x00709, 0x63333, 0x0000d, 0x00008, 0x0060a,
0x4b333, 0x0000d, 0x00009, 0x0060a, 0x53333, 0x0000d, 0x0000a,
0x0060a, 0x5b333, 0x0000d, 0x0000b, 0x0060a, 0x63333, 0x0000d,
0x0000c, 0x0060a, 0x6b333, 0x0000d, 0x0000d, 0x0060a, 0x73333,
0x0000d, 0x0000e, 0x0050b, 0x66666, 0x0001a, 0xe0000, 0x4000f,
0xe31fc, 0x6000f, 0xff9f8, 0x2000f, 0x203f9, 0x3000f, 0xff500,
0x00000, 0x00000, 0x8000f, 0x3f100, 0x9000f, 0x23100, 0xd8000,
0x90000, 0x51000, 0x12000, 0x28fb4, 0x24fa8, 0x207a4, 0x1c798,
0x183a4, 0x14398, 0x101a4, 0x0c198, 0x080a4, 0x04098, 0x00014,
0x1944c, 0x59444, 0x9944c, 0xd9444, 0x0f405, 0x4f405, 0x8f405,
0xcf405, 0xe0330, 0xa0330, 0x60330, 0x20330, 0x10159, 0x0f401,
0x00000, 0x00000, 0x80003, 0x00000, 0x00000, 0x44457, 0x80000,
0x30159
};
static const struct rtwn_rf_prog rtl8188ru_rf_prog[] = {
{
__arraycount(rtl8192ce_rf1_regs),
rtl8192ce_rf1_regs,
rtl8188ru_rf_vals
}
};
struct rtwn_txpwr {
uint8_t pwr[3][28];
};
struct rtwn_r88e_txpwr {
uint8_t pwr[6][28];
};
/*
* Per RF chain/group/rate Tx gain values.
*/
static const struct rtwn_txpwr rtl8192cu_txagc[] = {
{ { /* Chain 0. */
{ /* Group 0. */
0x00, 0x00, 0x00, 0x00, /* CCK1~11. */
0x0c, 0x0c, 0x0c, 0x0a, 0x08, 0x06, 0x04, 0x02, /* OFDM6~54. */
0x0e, 0x0d, 0x0c, 0x0a, 0x08, 0x06, 0x04, 0x02, /* MCS0~7. */
0x0e, 0x0d, 0x0c, 0x0a, 0x08, 0x06, 0x04, 0x02 /* MCS8~15. */
},
{ /* Group 1. */
0x00, 0x00, 0x00, 0x00, /* CCK1~11. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* OFDM6~54. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* MCS0~7. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* MCS8~15. */
},
{ /* Group 2. */
0x00, 0x00, 0x00, 0x00, /* CCK1~11. */
0x04, 0x04, 0x04, 0x04, 0x04, 0x02, 0x02, 0x00, /* OFDM6~54. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* MCS0~7. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* MCS8~15. */
}
} },
{ { /* Chain 1. */
{ /* Group 0. */
0x00, 0x00, 0x00, 0x00, /* CCK1~11. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* OFDM6~54. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* MCS0~7. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* MCS8~15. */
},
{ /* Group 1. */
0x00, 0x00, 0x00, 0x00, /* CCK1~11. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* OFDM6~54. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* MCS0~7. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* MCS8~15. */
},
{ /* Group 2. */
0x00, 0x00, 0x00, 0x00, /* CCK1~11. */
0x04, 0x04, 0x04, 0x04, 0x04, 0x02, 0x02, 0x00, /* OFDM6~54. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* MCS0~7. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* MCS8~15. */
}
} }
};
static const struct rtwn_txpwr rtl8188ru_txagc[] = {
{ { /* Chain 0. */
{ /* Group 0. */
0x00, 0x00, 0x00, 0x00, /* CCK1~11. */
0x08, 0x08, 0x08, 0x06, 0x06, 0x04, 0x04, 0x00, /* OFDM6~54. */
0x08, 0x06, 0x06, 0x04, 0x04, 0x02, 0x02, 0x00, /* MCS0~7. */
0x08, 0x06, 0x06, 0x04, 0x04, 0x02, 0x02, 0x00 /* MCS8~15. */
},
{ /* Group 1. */
0x00, 0x00, 0x00, 0x00, /* CCK1~11. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* OFDM6~54. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* MCS0~7. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* MCS8~15. */
},
{ /* Group 2. */
0x00, 0x00, 0x00, 0x00, /* CCK1~11. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* OFDM6~54. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* MCS0~7. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* MCS8~15. */
}
} }
};
static const struct rtwn_r88e_txpwr rtl8188eu_txagc[] = {
{ { /* Chain 0. */
{ /* Group 0. */
0x00, 0x00, 0x00, 0x00, /* CCK1~11. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* OFDM6~54. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* MCS0~7. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* MCS8~15. */
},
{ /* Group 1. */
0x00, 0x00, 0x00, 0x00, /* CCK1~11. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* OFDM6~54. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* MCS0~7. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* MCS8~15. */
},
{ /* Group 2. */
0x00, 0x00, 0x00, 0x00, /* CCK1~11. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* OFDM6~54. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* MCS0~7. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* MCS8~15. */
},
{ /* Group 3. */
0x00, 0x00, 0x00, 0x00, /* CCK1~11. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* OFDM6~54. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* MCS0~7. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* MCS8~15. */
},
{ /* Group 4. */
0x00, 0x00, 0x00, 0x00, /* CCK1~11. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* OFDM6~54. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* MCS0~7. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* MCS8~15. */
},
{ /* Group 5. */
0x00, 0x00, 0x00, 0x00, /* CCK1~11. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* OFDM6~54. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* MCS0~7. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* MCS8~15. */
}
} },
{ { /* Chain 1. */
{ /* Group 0. */
0x00, 0x00, 0x00, 0x00, /* CCK1~11. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* OFDM6~54. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* MCS0~7. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* MCS8~15. */
},
{ /* Group 1. */
0x00, 0x00, 0x00, 0x00, /* CCK1~11. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* OFDM6~54. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* MCS0~7. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* MCS8~15. */
},
{ /* Group 2. */
0x00, 0x00, 0x00, 0x00, /* CCK1~11. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* OFDM6~54. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* MCS0~7. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* MCS8~15. */
},
{ /* Group 3. */
0x00, 0x00, 0x00, 0x00, /* CCK1~11. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* OFDM6~54. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* MCS0~7. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* MCS8~15. */
},
{ /* Group 4. */
0x00, 0x00, 0x00, 0x00, /* CCK1~11. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* OFDM6~54. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* MCS0~7. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* MCS8~15. */
},
{ /* Group 5. */
0x00, 0x00, 0x00, 0x00, /* CCK1~11. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* OFDM6~54. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* MCS0~7. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* MCS8~15. */
}
} }
};
#endif /* _DEV_IC_RTWN_DATA_H_ */
|
a9122d266e0041992d55149c1079e475b86d65d5
|
192f6a4c9d934be58bca0e610ec1a75e7777fcd1
|
/include/parrot/namespace.h
|
ecf0ef59f2765294a48857e784318e6942e29ca1
|
[
"Artistic-2.0"
] |
permissive
|
parrot/parrot
|
39a74fbb015829cef901211d6d173b71eea475ea
|
f89a111c06ad0367817c52fda6ff5c24165c005b
|
refs/heads/master
| 2023-07-20T07:41:40.386067
| 2021-08-25T17:59:15
| 2021-08-25T17:59:15
| 1,071,734
| 450
| 134
| null | 2016-11-09T10:57:41
| 2010-11-11T15:14:10
|
C
|
UTF-8
|
C
| false
| false
| 6,487
|
h
|
namespace.h
|
/* namespace.h
* Copyright (C) 2004-2010, Parrot Foundation.
* Overview:
* Contains accessor functions for globals
* Data Structure and Algorithms:
* History:
* Notes:
* References:
*/
#ifndef PARROT_GLOBAL_H_GUARD
#define PARROT_GLOBAL_H_GUARD
/* HEADERIZER BEGIN: src/namespace.c */
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
PMC * Parrot_ns_find_current_namespace_global(PARROT_INTERP,
ARGIN_NULLOK(STRING *globalname))
__attribute__nonnull__(1);
PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
PMC * Parrot_ns_find_global_from_op(PARROT_INTERP,
ARGIN(PMC *ns),
ARGIN_NULLOK(STRING *globalname),
void *next)
__attribute__nonnull__(1)
__attribute__nonnull__(2);
PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
PMC * Parrot_ns_find_named_item(PARROT_INTERP,
ARGIN(STRING *name),
ARGIN(void *next))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(3);
PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
PMC * Parrot_ns_find_namespace_global(PARROT_INTERP,
ARGIN_NULLOK(PMC *ns),
ARGIN_NULLOK(STRING *globalname))
__attribute__nonnull__(1);
PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
PMC * Parrot_ns_get_global(PARROT_INTERP,
ARGIN_NULLOK(PMC *ns),
ARGIN_NULLOK(STRING *globalname))
__attribute__nonnull__(1);
PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
PARROT_CAN_RETURN_NULL
PMC * Parrot_ns_get_name(PARROT_INTERP, ARGIN(PMC *_namespace))
__attribute__nonnull__(1)
__attribute__nonnull__(2);
PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
PMC * Parrot_ns_get_namespace_keyed(PARROT_INTERP,
ARGIN(PMC *base_ns),
ARGIN(PMC *pmc_key))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(3);
PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
PMC * Parrot_ns_get_namespace_keyed_str(PARROT_INTERP,
ARGIN(PMC *base_ns),
ARGIN_NULLOK(STRING *str_key))
__attribute__nonnull__(1)
__attribute__nonnull__(2);
PARROT_EXPORT
PARROT_PURE_FUNCTION
Parrot_PMC Parrot_ns_get_root_namespace(PARROT_INTERP)
__attribute__nonnull__(1);
PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
PMC * Parrot_ns_make_namespace_autobase(PARROT_INTERP, ARGIN(PMC *key))
__attribute__nonnull__(1)
__attribute__nonnull__(2);
PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
PMC * Parrot_ns_make_namespace_keyed(PARROT_INTERP,
ARGIN(PMC *base_ns),
ARGIN(PMC *pmc_key))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(3);
PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
PMC * Parrot_ns_make_namespace_keyed_str(PARROT_INTERP,
ARGIN(PMC *base_ns),
ARGIN(STRING *str_key))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(3);
PARROT_EXPORT
void Parrot_ns_set_global(PARROT_INTERP,
ARGIN(PMC *ns),
ARGIN_NULLOK(STRING *globalname),
ARGIN_NULLOK(PMC *val))
__attribute__nonnull__(1)
__attribute__nonnull__(2);
PARROT_EXPORT
void Parrot_ns_store_global(PARROT_INTERP,
ARGIN_NULLOK(PMC *ns),
ARGIN_NULLOK(STRING *globalname),
ARGIN_NULLOK(PMC *val))
__attribute__nonnull__(1);
PARROT_EXPORT
void Parrot_ns_store_sub(PARROT_INTERP, ARGIN(PMC *sub_pmc))
__attribute__nonnull__(1)
__attribute__nonnull__(2);
#define ASSERT_ARGS_Parrot_ns_find_current_namespace_global \
__attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
#define ASSERT_ARGS_Parrot_ns_find_global_from_op __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(ns))
#define ASSERT_ARGS_Parrot_ns_find_named_item __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(name) \
, PARROT_ASSERT_ARG(next_unused))
#define ASSERT_ARGS_Parrot_ns_find_namespace_global \
__attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
#define ASSERT_ARGS_Parrot_ns_get_global __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
#define ASSERT_ARGS_Parrot_ns_get_name __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(_namespace))
#define ASSERT_ARGS_Parrot_ns_get_namespace_keyed __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(base_ns) \
, PARROT_ASSERT_ARG(pmc_key))
#define ASSERT_ARGS_Parrot_ns_get_namespace_keyed_str \
__attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(base_ns))
#define ASSERT_ARGS_Parrot_ns_get_root_namespace __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
#define ASSERT_ARGS_Parrot_ns_make_namespace_autobase \
__attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(key))
#define ASSERT_ARGS_Parrot_ns_make_namespace_keyed \
__attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(base_ns) \
, PARROT_ASSERT_ARG(pmc_key))
#define ASSERT_ARGS_Parrot_ns_make_namespace_keyed_str \
__attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(base_ns) \
, PARROT_ASSERT_ARG(str_key))
#define ASSERT_ARGS_Parrot_ns_set_global __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(ns))
#define ASSERT_ARGS_Parrot_ns_store_global __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
#define ASSERT_ARGS_Parrot_ns_store_sub __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(sub_pmc))
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
/* HEADERIZER END: src/namespace.c */
#endif /* PARROT_GLOBAL_H_GUARD */
/*
* Local variables:
* c-file-style: "parrot"
* End:
* vim: expandtab shiftwidth=4 cinoptions='\:2=2' :
*/
|
aa12108831aab2b99e0be88475ee208bbebc6212
|
72a2fc906bb1219257b5cd02ba46a9f77c60c762
|
/components/disk.c
|
e19a6935508464815694a1662a511b1560e98ed6
|
[
"ISC"
] |
permissive
|
drkhsh/slstatus
|
fac0cc8d1855c0447a54a2d2ac032134c32dd3ad
|
f68f49273e70b3767b30c549dda04ddd4d25fc91
|
refs/heads/master
| 2023-07-07T01:53:56.359434
| 2023-07-04T18:47:18
| 2023-07-04T18:47:18
| 53,124,988
| 219
| 123
|
ISC
| 2022-12-26T15:27:31
| 2016-03-04T09:46:18
|
C
|
UTF-8
|
C
| false
| false
| 1,016
|
c
|
disk.c
|
/* See LICENSE file for copyright and license details. */
#include <stdio.h>
#include <sys/statvfs.h>
#include "../slstatus.h"
#include "../util.h"
const char *
disk_free(const char *path)
{
struct statvfs fs;
if (statvfs(path, &fs) < 0) {
warn("statvfs '%s':", path);
return NULL;
}
return fmt_human(fs.f_frsize * fs.f_bavail, 1024);
}
const char *
disk_perc(const char *path)
{
struct statvfs fs;
if (statvfs(path, &fs) < 0) {
warn("statvfs '%s':", path);
return NULL;
}
return bprintf("%d", (int)(100 *
(1 - ((double)fs.f_bavail / (double)fs.f_blocks))));
}
const char *
disk_total(const char *path)
{
struct statvfs fs;
if (statvfs(path, &fs) < 0) {
warn("statvfs '%s':", path);
return NULL;
}
return fmt_human(fs.f_frsize * fs.f_blocks, 1024);
}
const char *
disk_used(const char *path)
{
struct statvfs fs;
if (statvfs(path, &fs) < 0) {
warn("statvfs '%s':", path);
return NULL;
}
return fmt_human(fs.f_frsize * (fs.f_blocks - fs.f_bfree), 1024);
}
|
713ce118943cb6e791de536b6cb6fdc414ae3a0f
|
8149d6751e142ecbc200b43c2da2d5a94c0735df
|
/modules/contact/contact.c
|
af8081cd0ab630c94746ddfce33d17440deed6f7
|
[
"BSD-3-Clause"
] |
permissive
|
baresip/baresip
|
3c8ebef031f6a01a1462a9f36264197f90ce6ffe
|
5ace2f75b317bba60d46030ca3fd5e8fa045fecf
|
refs/heads/main
| 2023-08-25T12:55:24.860248
| 2023-08-17T06:56:31
| 2023-08-17T06:56:31
| 16,664,594
| 834
| 205
|
BSD-3-Clause
| 2023-09-14T12:47:57
| 2014-02-09T10:44:09
|
C
|
UTF-8
|
C
| false
| false
| 6,491
|
c
|
contact.c
|
/**
* @file modules/contact/contact.c Contacts module
*
* Copyright (C) 2010 - 2015 Alfred E. Heggestad
*/
#include <string.h>
#include <re.h>
#include <baresip.h>
/**
* @defgroup contact contact
*
* Contact module reading contacts from a file
*
* - read contact entries from ~/.baresip/contacts
* - populate local database of contacts
*/
static int confline_handler(const struct pl *addr, void *arg)
{
struct contacts *contacts = arg;
return contact_add(contacts, NULL, addr);
}
static int print_contacts(struct re_printf *pf, void *unused)
{
(void)unused;
return contacts_print(pf, baresip_contacts());
}
static int save_current(const struct contact *cnt)
{
char path[256] = "", file[256] = "";
FILE *f = NULL;
int err;
err = conf_path_get(path, sizeof(path));
if (err)
return err;
if (re_snprintf(file, sizeof(file), "%s/current_contact", path) < 0)
return ENOMEM;
f = fopen(file, "w");
if (!f)
return errno;
if (re_fprintf(f, "%s", contact_uri(cnt)) < 0) {
err = errno;
goto out;
}
out:
if (f)
(void)fclose(f);
return err;
}
static void send_resp_handler(int err, const struct sip_msg *msg, void *arg)
{
(void)arg;
if (err) {
(void)re_fprintf(stderr, " \x1b[31m%m\x1b[;m\n", err);
return;
}
if (msg->scode >= 300) {
(void)re_fprintf(stderr, " \x1b[31m%u %r\x1b[;m\n",
msg->scode, &msg->reason);
}
}
static int cmd_dial_contact(struct re_printf *pf, void *arg)
{
struct contact *cnt;
const char *uri;
int err = 0;
(void)arg;
cnt = contacts_current(baresip_contacts());
if (!cnt) {
return re_hprintf(pf, "contact: current contact not set\n");
}
uri = contact_uri(cnt);
err = ua_connect(uag_find_requri(uri), NULL, NULL, uri, VIDMODE_ON);
if (err) {
warning("contact: ua_connect(%s) failed: %m\n",
uri, err);
}
return 0;
}
static int cmd_message(struct re_printf *pf, void *arg)
{
const struct cmd_arg *carg = arg;
struct contact *cnt;
const char *uri;
int err = 0;
cnt = contacts_current(baresip_contacts());
if (!cnt) {
return re_hprintf(pf, "contact: current contact not set\n");
}
uri = contact_uri(cnt);
err = message_send(uag_find_requri(uri), uri, carg->prm,
send_resp_handler, NULL);
if (err) {
(void)re_hprintf(pf, "contact: message_send(%s) failed (%m)\n",
uri, err);
}
return err;
}
static int load_current_contact(struct contacts *contacts, const char *path)
{
char file[256] = "";
char buf[1024];
struct contact *cnt = NULL;
struct sip_addr addr;
struct pl pl;
FILE *f = NULL;
int err = 0;
if (re_snprintf(file, sizeof(file), "%s/current_contact", path) < 0)
return ENOMEM;
if (fs_isfile(file)) {
f = fopen(file, "r");
if (!f)
return errno;
if (!fgets(buf, (int)sizeof(buf), f)) {
err = errno;
goto out;
}
pl_set_str(&pl, buf);
if (0 == sip_addr_decode(&addr, &pl))
pl_strcpy(&addr.auri, buf, sizeof(buf));
cnt = contact_find(contacts, buf);
if (!cnt) {
info("contact from disk not found (%s)\n", buf);
}
}
if (!cnt) {
cnt = list_ledata(list_head(contact_list(contacts)));
err = save_current(cnt);
if (err)
goto out;
}
if (cnt)
contacts_set_current(contacts, cnt);
out:
if (f)
(void)fclose(f);
return err;
}
static int cycle_current(struct re_printf *pf, bool next)
{
struct contacts *contacts = baresip_contacts();
struct contact *cnt;
struct le *le;
int err;
cnt = contacts_current(contacts);
if (cnt) {
le = contact_le(cnt);
if (next)
le = le->next ? le->next : le;
else
le = le->prev ? le->prev : le;
}
else {
/* No current contact, set the first one */
le = list_head(contact_list(contacts));
if (!le)
return re_hprintf(pf, "(no contacts)\n");
}
cnt = list_ledata(le);
contacts_set_current(contacts, cnt);
re_hprintf(pf, "Current contact: %H\n", contact_print, cnt);
err = save_current(cnt);
if (err) {
warning("contact: failed to save"
" current contact (%m)\n", err);
}
return 0;
}
static int cmd_current_prev(struct re_printf *pf, void *arg)
{
(void)arg;
return cycle_current(pf, false);
}
static int cmd_current_next(struct re_printf *pf, void *arg)
{
(void)arg;
return cycle_current(pf, true);
}
static const struct cmd cmdv[] = {
{"contacts", 'C', 0, "List contacts", print_contacts },
{"dialcontact", 'D', 0, "Dial current contact", cmd_dial_contact },
{"message", 'M', CMD_PRM, "Message current contact",cmd_message },
{"contact_prev", '<', 0, "Set previous contact", cmd_current_prev },
{"contact_next", '>', 0, "Set next contact", cmd_current_next },
};
static int write_template(const char *file)
{
FILE *f = NULL;
info("contact: creating contacts template %s\n", file);
f = fopen(file, "w");
if (!f)
return errno;
(void)re_fprintf(f,
"#\n"
"# SIP contacts\n"
"#\n"
"# Displayname <sip:user@domain>;addr-params\n"
"#\n"
"# addr-params:\n"
"# ;presence={none,p2p}\n"
"# ;access={allow,block}\n"
"#\n"
"\n"
"\n"
"\"Music Server\" <sip:music@iptel.org>\n"
"\"User\" <sip:user@domain>;presence=p2p\n"
"\n"
"# Access rules\n"
"#\"Catch All\" <sip:*@*>;access=block\n"
"\"Good Friend\" <sip:good@example.com>;"
"access=allow\n"
"\n"
);
if (f)
(void)fclose(f);
return 0;
}
static int module_init(void)
{
struct contacts *contacts = baresip_contacts();
char path[256] = "", file[256] = "";
int err;
err = conf_path_get(path, sizeof(path));
if (err)
return err;
if (re_snprintf(file, sizeof(file), "%s/contacts", path) < 0)
return ENOMEM;
if (!fs_isfile(file)) {
(void)fs_mkdir(path, 0700);
err = write_template(file);
if (err)
return err;
}
err = conf_parse(file, confline_handler, contacts);
if (err)
return err;
err = cmd_register(baresip_commands(), cmdv, RE_ARRAY_SIZE(cmdv));
if (err)
return err;
info("Populated %u contacts\n",
list_count(contact_list(contacts)));
/* Load current contact after list was populated */
if (!list_isempty(contact_list(contacts))) {
err = load_current_contact(contacts, path);
if (err) {
warning("could not load current contact (%m)\n", err);
err = 0;
}
}
return err;
}
static int module_close(void)
{
cmd_unregister(baresip_commands(), cmdv);
list_flush(contact_list(baresip_contacts()));
return 0;
}
const struct mod_export DECL_EXPORTS(contact) = {
"contact",
"application",
module_init,
module_close
};
|
d3ad4a37abce5dc7dd642dcc3aaef794f385cd9e
|
2308899071a849a199e3b70806b4dd1c396efc8a
|
/0.76b_My_PuTTY/windows/dialog.c
|
63528298d7de22149c9cce85e7b24042d39a6e7d
|
[
"MIT"
] |
permissive
|
cyd01/KiTTY
|
b0b06d771508668ccbd6316474382b538a65bac0
|
0e5d8582aad192db96ba240444a6840fa82ccf05
|
refs/heads/master
| 2023-08-10T21:25:06.926589
| 2023-05-23T17:23:03
| 2023-05-23T17:56:00
| 154,540,955
| 1,451
| 147
|
NOASSERTION
| 2023-05-30T17:16:10
| 2018-10-24T17:26:24
|
C
|
UTF-8
|
C
| false
| false
| 44,313
|
c
|
dialog.c
|
/*
* windlg.c - dialogs for PuTTY(tel), including the configuration dialog.
*/
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <assert.h>
#include <ctype.h>
#include <time.h>
#include "putty.h"
#include "ssh.h"
#include "putty-rc.h"
#include "win-gui-seat.h"
#include "storage.h"
#include "dialog.h"
#include "licence.h"
#include <commctrl.h>
#include <commdlg.h>
#include <shellapi.h>
#ifdef MSVC4
#define TVINSERTSTRUCT TV_INSERTSTRUCT
#define TVITEM TV_ITEM
#define ICON_BIG 1
#endif
/*
* These are the various bits of data required to handle the
* portable-dialog stuff in the config box. Having them at file
* scope in here isn't too bad a place to put them; if we were ever
* to need more than one config box per process we could always
* shift them to a per-config-box structure stored in GWL_USERDATA.
*/
static struct controlbox *ctrlbox;
/*
* ctrls_base holds the OK and Cancel buttons: the controls which
* are present in all dialog panels. ctrls_panel holds the ones
* which change from panel to panel.
*/
static struct winctrls ctrls_base, ctrls_panel;
static struct dlgparam dp;
#define LOGEVENT_INITIAL_MAX 128
#define LOGEVENT_CIRCULAR_MAX 128
static char *events_initial[LOGEVENT_INITIAL_MAX];
static char *events_circular[LOGEVENT_CIRCULAR_MAX];
static int ninitial = 0, ncircular = 0, circular_first = 0;
#ifdef MOD_PERSO
#include <math.h>
#include <process.h>
#include "kitty.h"
#include "kitty_commun.h"
#include "kitty_registry.h"
extern char BuildVersionTime[256] ;
void CenterDlgInParent(HWND hDlg) ;
int get_param( const char * val ) ;
void CheckVersionFromWebSite( HWND hwnd ) ;
bool SessPathIsInitial( void ) ;
bool IsThereDefaultSessionFile( void ) ;
#ifndef TIMER_SLIDEBG
//#define TIMER_SLIDEBG 12343
#define TIMER_SLIDEBG 8703
#endif
static char *getevent(int i) ;
int print_event_log( FILE * fp, int i ) {
char * pst = getevent(i) ;
if( pst == NULL ) { return 0 ; }
fprintf( fp, "%s\n", pst ) ;
return 1 ;
}
void do_eventlog( const char * st ) ;
#endif
#ifdef MOD_PRINTCLIP
#define PRINT_TO_CLIPBOARD_STRING "Windows clipboard"
#endif
#define PRINTER_DISABLED_STRING "None (printing disabled)"
void force_normal(HWND hwnd)
{
static bool recurse = false;
WINDOWPLACEMENT wp;
if (recurse)
return;
recurse = true;
wp.length = sizeof(wp);
if (GetWindowPlacement(hwnd, &wp) && wp.showCmd == SW_SHOWMAXIMIZED) {
wp.showCmd = SW_SHOWNORMAL;
SetWindowPlacement(hwnd, &wp);
}
recurse = false;
}
static char *getevent(int i)
{
if (i < ninitial)
return events_initial[i];
if ((i -= ninitial) < ncircular)
return events_circular[(circular_first + i) % LOGEVENT_CIRCULAR_MAX];
return NULL;
}
static HWND logbox;
HWND event_log_window(void) { return logbox; }
static INT_PTR CALLBACK LogProc(HWND hwnd, UINT msg,
WPARAM wParam, LPARAM lParam)
{
int i;
switch (msg) {
case WM_INITDIALOG: {
char *str = dupprintf("%s Event Log", appname);
SetWindowText(hwnd, str);
sfree(str);
static int tabs[4] = { 78, 108 };
SendDlgItemMessage(hwnd, IDN_LIST, LB_SETTABSTOPS, 2,
(LPARAM) tabs);
for (i = 0; i < ninitial; i++)
SendDlgItemMessage(hwnd, IDN_LIST, LB_ADDSTRING,
0, (LPARAM) events_initial[i]);
for (i = 0; i < ncircular; i++)
SendDlgItemMessage(hwnd, IDN_LIST, LB_ADDSTRING,
0, (LPARAM) events_circular[(circular_first + i) % LOGEVENT_CIRCULAR_MAX]);
return 1;
}
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDOK:
case IDCANCEL:
logbox = NULL;
SetActiveWindow(GetParent(hwnd));
DestroyWindow(hwnd);
return 0;
case IDN_COPY:
if (HIWORD(wParam) == BN_CLICKED ||
HIWORD(wParam) == BN_DOUBLECLICKED) {
int selcount;
int *selitems;
selcount = SendDlgItemMessage(hwnd, IDN_LIST,
LB_GETSELCOUNT, 0, 0);
if (selcount == 0) { /* don't even try to copy zero items */
MessageBeep(0);
break;
}
selitems = snewn(selcount, int);
if (selitems) {
int count = SendDlgItemMessage(hwnd, IDN_LIST,
LB_GETSELITEMS,
selcount,
(LPARAM) selitems);
int i;
int size;
char *clipdata;
static unsigned char sel_nl[] = SEL_NL;
if (count == 0) { /* can't copy zero stuff */
MessageBeep(0);
break;
}
size = 0;
for (i = 0; i < count; i++)
size +=
strlen(getevent(selitems[i])) + sizeof(sel_nl);
clipdata = snewn(size, char);
if (clipdata) {
char *p = clipdata;
for (i = 0; i < count; i++) {
char *q = getevent(selitems[i]);
int qlen = strlen(q);
memcpy(p, q, qlen);
p += qlen;
memcpy(p, sel_nl, sizeof(sel_nl));
p += sizeof(sel_nl);
}
write_aclip(CLIP_SYSTEM, clipdata, size, true);
sfree(clipdata);
}
sfree(selitems);
for (i = 0; i < (ninitial + ncircular); i++)
SendDlgItemMessage(hwnd, IDN_LIST, LB_SETSEL,
false, i);
}
}
return 0;
}
return 0;
case WM_CLOSE:
logbox = NULL;
SetActiveWindow(GetParent(hwnd));
DestroyWindow(hwnd);
return 0;
}
return 0;
}
static INT_PTR CALLBACK LicenceProc(HWND hwnd, UINT msg,
WPARAM wParam, LPARAM lParam)
{
switch (msg) {
case WM_INITDIALOG: {
char *str = dupprintf("%s Licence", appname);
SetWindowText(hwnd, str);
sfree(str);
SetDlgItemText(hwnd, IDA_TEXT, LICENCE_TEXT("\r\n\r\n"));
return 1;
}
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDOK:
case IDCANCEL:
EndDialog(hwnd, 1);
return 0;
}
return 0;
case WM_CLOSE:
EndDialog(hwnd, 1);
return 0;
}
return 0;
}
#if (defined MOD_PERSO) && (!defined FLJ)
//static const char MESSAGE[] = "";
static const char MESSAGE[] = " KiTTY software is developed by Cyd for 9bis.com, copyright \251 2005-2023, thanks to Leo for bcrypt and mini libraries, thanks to all contributors " ;
static INT_PTR CALLBACK AboutProc(HWND hwnd, UINT msg,
WPARAM wParam, LPARAM lParam)
{
char *str;
static HFONT hFontTitle ;
static HFONT hFontHover ;
static HFONT hFontNormal ;
static BOOL hover_email;
static BOOL capture_email;
static BOOL hover_webpage;
static BOOL capture_webpage;
static HCURSOR hCursorNormal;
static HCURSOR hCursorHover;
static int message_timer = 1000 ;
static char * mess = NULL ;
switch (msg) {
case WM_INITDIALOG: {
char buffer[1024] ;
LOGFONT lf;
#ifdef FLJ
/* Positionnement du ssh handler */
CreateSSHHandler() ;
/* Creation des association de fichiers .ktx */
CreateFileAssoc() ;
#endif
sprintf( buffer, "KiTTY - %s", BuildVersionTime ) ;
SetDlgItemText(hwnd,IDA_VERSION,buffer);
str = dupprintf("About %s That's all folks !", appname);
SetWindowText(hwnd, str);
sfree(str);
if (hFontTitle == NULL) {
if (NULL == (hFontTitle = (HFONT)SendDlgItemMessage(hwnd,IDA_VERSION,WM_GETFONT,0,0)))
hFontTitle = GetStockObject(DEFAULT_GUI_FONT);
GetObject(hFontTitle,sizeof(LOGFONT),&lf);
lf.lfWeight = FW_BOLD;
hFontTitle = CreateFontIndirect(&lf);
}
// Font setup
if (NULL == (hFontHover = (HFONT)SendDlgItemMessage(hwnd,IDC_EMAIL,WM_GETFONT,0,0)))
hFontHover = GetStockObject(DEFAULT_GUI_FONT);
GetObject(hFontHover,sizeof(LOGFONT),&lf);
lf.lfUnderline = TRUE;
hFontNormal = CreateFontIndirect(&lf);
// Cursor setup
hCursorNormal = LoadCursor( NULL, MAKEINTRESOURCE((DWORD)IDC_ARROW) ) ;
if (!(hCursorHover = LoadCursor( NULL, (LPCTSTR)MAKEINTRESOURCE((DWORD)IDC_HAND) )))
hCursorHover = LoadCursor( GetModuleHandle(NULL), MAKEINTRESOURCE(IDC_HOVER) ) ;
hover_email = FALSE;
capture_email = FALSE;
hover_webpage = FALSE;
capture_webpage = FALSE;
CenterDlgInParent(hwnd);
mess = (char*)MESSAGE ;
SetDlgItemText(hwnd,IDC_BAN,mess);
if( strlen( mess ) > 0 ) SetTimer(hwnd, message_timer, 100, NULL) ;
return 1;
}
break ;
case WM_TIMER:
if ((UINT_PTR)wParam == message_timer) {
mess++ ;
SetDlgItemText(hwnd,IDC_BAN,mess);
if( strlen( mess ) < strlen(" ") ) mess = (char*)MESSAGE ;
}
break ;
case WM_NCACTIVATE:
if (!(BOOL)wParam) { // we're not active, clear hover states
hover_email = FALSE;
capture_email = FALSE;
hover_webpage = FALSE;
capture_webpage = FALSE;
InvalidateRect(GetDlgItem(hwnd,IDC_EMAIL),NULL,FALSE);
InvalidateRect(GetDlgItem(hwnd,IDC_WEBPAGE),NULL,FALSE);
}
return FALSE;
case WM_CTLCOLORSTATIC: {
DWORD dwId = GetWindowLong((HWND)lParam,GWL_ID);
HDC hdc = (HDC)wParam;
if (dwId == IDA_VERSION) {
SetBkMode(hdc,TRANSPARENT);
SetTextColor(hdc,GetSysColor(COLOR_BTNTEXT));
SelectObject(hdc,hFontTitle);
return(LONG)GetSysColorBrush(COLOR_BTNFACE);
}
if (dwId == IDC_EMAIL || dwId == IDC_WEBPAGE) {
SetBkMode(hdc,TRANSPARENT);
if (GetSysColorBrush(26))
SetTextColor(hdc,GetSysColor(26));
else
SetTextColor(hdc,RGB(0,0,255));
if (dwId == IDC_EMAIL)
SelectObject(hdc,hover_email?hFontHover:hFontNormal);
else
SelectObject(hdc,hover_webpage?hFontHover:hFontNormal);
return(LONG)GetSysColorBrush(COLOR_BTNFACE);
}
}
break ;
case WM_MOUSEMOVE: {
POINT pt = { LOWORD(lParam), HIWORD(lParam) };
HWND hwndHover = ChildWindowFromPoint(hwnd,pt);
DWORD dwId = GetWindowLong(hwndHover,GWL_ID);
if (GetActiveWindow() == hwnd) {
if (wParam & MK_LBUTTON && !capture_email && !capture_webpage) {
;
}
else if (hover_email != (dwId == IDC_EMAIL) && !capture_webpage) {
hover_email = !hover_email;
InvalidateRect(GetDlgItem(hwnd,IDC_EMAIL),NULL,FALSE);
}
else if (hover_webpage != (dwId == IDC_WEBPAGE) && !capture_email) {
hover_webpage = !hover_webpage;
InvalidateRect(GetDlgItem(hwnd,IDC_WEBPAGE),NULL,FALSE);
}
SetCursor((hover_email || hover_webpage)?hCursorHover:hCursorNormal);
}
}
break;
case WM_LBUTTONDOWN: {
POINT pt = { LOWORD(lParam), HIWORD(lParam) };
HWND hwndHover = ChildWindowFromPoint(hwnd,pt);
DWORD dwId = GetWindowLong(hwndHover,GWL_ID);
if (dwId == IDC_EMAIL) {
GetCapture();
hover_email = TRUE;
capture_email = TRUE;
InvalidateRect(GetDlgItem(hwnd,IDC_EMAIL),NULL,FALSE);
}
else if (dwId == IDC_WEBPAGE) {
GetCapture();
hover_webpage = TRUE;
capture_webpage = TRUE;
InvalidateRect(GetDlgItem(hwnd,IDC_WEBPAGE),NULL,FALSE);
}
SetCursor((hover_email || hover_webpage)?hCursorHover:hCursorNormal);
}
break;
case WM_LBUTTONUP: {
POINT pt = { LOWORD(lParam), HIWORD(lParam) };
HWND hwndHover = ChildWindowFromPoint(hwnd,pt);
DWORD dwId = GetWindowLong(hwndHover,GWL_ID);
if (capture_email || capture_webpage) {
ReleaseCapture();
if (dwId == IDC_EMAIL && capture_email) {
ShellExecute(hwnd,"open","mailto:kitty@9bis.com",NULL,NULL,SW_SHOWNORMAL);
}
else if (dwId == IDC_WEBPAGE && capture_webpage) {
ShellExecute(hwnd,"open","https://www.9bis.net/kitty",NULL,NULL,SW_SHOWNORMAL);
}
capture_email = FALSE;
capture_webpage = FALSE;
}
SetCursor((hover_email || hover_webpage)?hCursorHover:hCursorNormal);
}
break;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDOK:
case IDCANCEL:
hover_email = FALSE;
capture_email = FALSE;
hover_webpage = FALSE;
capture_webpage = FALSE;
KillTimer(hwnd, message_timer);
EndDialog(hwnd, TRUE);
return 0;
case IDA_LICENCE:
EnableWindow(hwnd, 0);
DialogBox(hinst, MAKEINTRESOURCE(IDD_LICENCEBOX),
hwnd, LicenceProc);
EnableWindow(hwnd, 1);
SetActiveWindow(hwnd);
return 0;
case IDA_WEB:
/* Load web browser */
CheckVersionFromWebSite( hwnd ) ;
/* {
char buffer[1024]="", vers[1024]="" ;
int i ;
strcpy( vers, BuildVersionTime ) ;
for( i = 0 ; i < strlen( vers ) ; i ++ ) {
if( !(((vers[i]>='0')&&(vers[i]<='9'))||(vers[i]=='.')) ) { vers[i] = '\0' ; break ; }
}
sprintf( buffer, "https://www.9bis.net/kitty/check_update.php?version=%s", vers ) ;
ShellExecute(hwnd, "open", buffer, 0, 0, SW_SHOWDEFAULT);
}*/
return 0;
case IDA_DON:
/* Load web browser */
{ char buffer[1024]="";
sprintf( buffer, "https://www.9bis.net/kitty/#!pages/donation.md" ) ;
ShellExecute(hwnd, "open", buffer, 0, 0, SW_SHOWDEFAULT);
}
return 0;
}
return 0;
case WM_CLOSE:
KillTimer(hwnd, message_timer);
EndDialog(hwnd, TRUE);
return 0;
}
return 0;
}
static INT_PTR CALLBACK AboutProcOrig(HWND hwnd, UINT msg,
WPARAM wParam, LPARAM lParam)
{
#else
static INT_PTR CALLBACK AboutProc(HWND hwnd, UINT msg,
WPARAM wParam, LPARAM lParam)
{
#endif
char *str;
switch (msg) {
case WM_INITDIALOG: {
str = dupprintf("About %s", appname);
SetWindowText(hwnd, str);
sfree(str);
char *buildinfo_text = buildinfo("\r\n");
char *text = dupprintf
("%s\r\n\r\n%s\r\n\r\n%s\r\n\r\n%s",
appname, ver, buildinfo_text,
"\251 " SHORT_COPYRIGHT_DETAILS ". All rights reserved.");
sfree(buildinfo_text);
SetDlgItemText(hwnd, IDA_TEXT, text);
MakeDlgItemBorderless(hwnd, IDA_TEXT);
sfree(text);
#ifdef MOD_PERSO
if( get_param("PUTTY") ) SetDlgItemText(hwnd, IDA_TEXT2, "" ) ;
#endif
return 1;
}
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDOK:
case IDCANCEL:
EndDialog(hwnd, true);
return 0;
case IDA_LICENCE:
EnableWindow(hwnd, 0);
DialogBox(hinst, MAKEINTRESOURCE(IDD_LICENCEBOX),
hwnd, LicenceProc);
EnableWindow(hwnd, 1);
SetActiveWindow(hwnd);
return 0;
case IDA_WEB:
/* Load web browser */
ShellExecute(hwnd, "open",
"https://www.chiark.greenend.org.uk/~sgtatham/putty/",
0, 0, SW_SHOWDEFAULT);
return 0;
}
return 0;
case WM_CLOSE:
EndDialog(hwnd, true);
return 0;
}
return 0;
}
static int SaneDialogBox(HINSTANCE hinst,
LPCTSTR tmpl,
HWND hwndparent,
DLGPROC lpDialogFunc)
{
WNDCLASS wc;
HWND hwnd;
MSG msg;
int flags;
int ret;
int gm;
wc.style = CS_DBLCLKS | CS_SAVEBITS | CS_BYTEALIGNWINDOW;
wc.lpfnWndProc = DefDlgProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = DLGWINDOWEXTRA + 2*sizeof(LONG_PTR);
wc.hInstance = hinst;
wc.hIcon = NULL;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH) (COLOR_BACKGROUND +1);
wc.lpszMenuName = NULL;
wc.lpszClassName = "PuTTYConfigBox";
RegisterClass(&wc);
hwnd = CreateDialog(hinst, tmpl, hwndparent, lpDialogFunc);
SetWindowLongPtr(hwnd, BOXFLAGS, 0); /* flags */
SetWindowLongPtr(hwnd, BOXRESULT, 0); /* result from SaneEndDialog */
while ((gm=GetMessage(&msg, NULL, 0, 0)) > 0) {
flags=GetWindowLongPtr(hwnd, BOXFLAGS);
if (!(flags & DF_END) && !IsDialogMessage(hwnd, &msg))
DispatchMessage(&msg);
if (flags & DF_END)
break;
}
if (gm == 0)
PostQuitMessage(msg.wParam); /* We got a WM_QUIT, pass it on */
ret=GetWindowLongPtr(hwnd, BOXRESULT);
DestroyWindow(hwnd);
return ret;
}
static void SaneEndDialog(HWND hwnd, int ret)
{
SetWindowLongPtr(hwnd, BOXRESULT, ret);
SetWindowLongPtr(hwnd, BOXFLAGS, DF_END);
}
/*
* Null dialog procedure.
*/
static INT_PTR CALLBACK NullDlgProc(HWND hwnd, UINT msg,
WPARAM wParam, LPARAM lParam)
{
return 0;
}
enum {
IDCX_ABOUT = IDC_ABOUT,
IDCX_TVSTATIC,
IDCX_TREEVIEW,
IDCX_STDBASE,
IDCX_PANELBASE = IDCX_STDBASE + 32
};
struct treeview_faff {
HWND treeview;
HTREEITEM lastat[4];
};
static HTREEITEM treeview_insert(struct treeview_faff *faff,
int level, char *text, char *path)
{
TVINSERTSTRUCT ins;
int i;
HTREEITEM newitem;
ins.hParent = (level > 0 ? faff->lastat[level - 1] : TVI_ROOT);
ins.hInsertAfter = faff->lastat[level];
#if _WIN32_IE >= 0x0400 && defined NONAMELESSUNION
#define INSITEM DUMMYUNIONNAME.item
#else
#define INSITEM item
#endif
ins.INSITEM.mask = TVIF_TEXT | TVIF_PARAM;
ins.INSITEM.pszText = text;
ins.INSITEM.cchTextMax = strlen(text)+1;
ins.INSITEM.lParam = (LPARAM)path;
newitem = TreeView_InsertItem(faff->treeview, &ins);
if (level > 0)
TreeView_Expand(faff->treeview, faff->lastat[level - 1],
(level > 1 ? TVE_COLLAPSE : TVE_EXPAND));
faff->lastat[level] = newitem;
for (i = level + 1; i < 4; i++)
faff->lastat[i] = NULL;
return newitem;
}
/*
* Create the panelfuls of controls in the configuration box.
*/
static void create_controls(HWND hwnd, char *path)
{
struct ctlpos cp;
int index;
int base_id;
struct winctrls *wc;
if (!path[0]) {
/*
* Here we must create the basic standard controls.
*/
ctlposinit(&cp, hwnd, 3, 3, 235);
wc = &ctrls_base;
base_id = IDCX_STDBASE;
} else {
/*
* Otherwise, we're creating the controls for a particular
* panel.
*/
ctlposinit(&cp, hwnd, 100, 3, 13);
wc = &ctrls_panel;
base_id = IDCX_PANELBASE;
}
for (index=-1; (index = ctrl_find_path(ctrlbox, path, index)) >= 0 ;) {
struct controlset *s = ctrlbox->ctrlsets[index];
winctrl_layout(&dp, wc, &cp, s, &base_id);
}
}
/*
* This function is the configuration box.
* (Being a dialog procedure, in general it returns 0 if the default
* dialog processing should be performed, and 1 if it should not.)
*/
static INT_PTR CALLBACK GenericMainDlgProc(HWND hwnd, UINT msg,
WPARAM wParam, LPARAM lParam)
{
HWND hw, treeview;
struct treeview_faff tvfaff;
int ret;
switch (msg) {
case WM_INITDIALOG:
#ifdef MOD_PERSO
{
RECT rcClient ;
int h ;
GetWindowRect(hwnd, &rcClient) ;
int NormalSize = 555 ;
if( GetConfigBoxWindowHeight() > 0 ) { h = GetConfigBoxWindowHeight() ; }
else if( GetConfigBoxHeight() >= 100 ) { h = GetConfigBoxHeight() ; }
else {
if( GetConfigBoxHeight() <= 7 ) { h = ceil(12*7+354) ; }
else if( GetConfigBoxHeight() <= 16 ) { h = NormalSize ; }
else {
h = NormalSize + 12 * ( GetConfigBoxHeight()-16 ) ;
if( h < NormalSize ) h = NormalSize ;
}
}
if( get_param("INIFILE")==SAVEMODE_DIR ) {
h = h - 12 ; // il n'y a pas la liste déroulant des folders en mode portable
}
#ifdef MOD_PROXY
if( GetProxySelectionFlag() ) { h = h + 20 ; }
#endif
// Initialise la taille de la ConfigBox (en cas de DPI speciaux)
double ScaleY = GetDeviceCaps(GetDC(hwnd),LOGPIXELSY)/96.0 ; // La police standard (100%) vaut 96ppp (pixels per pouce)
if( ScaleY!=1.0 ) { h = (int)( h*ScaleY ) ; }
MoveWindow( hwnd, rcClient.left, rcClient.top, rcClient.right-rcClient.left, h, TRUE ) ;
}
#endif
dp.hwnd = hwnd;
create_controls(hwnd, ""); /* Open and Cancel buttons etc */
SetWindowText(hwnd, dp.wintitle);
SetWindowLongPtr(hwnd, GWLP_USERDATA, 0);
if (has_help())
SetWindowLongPtr(hwnd, GWL_EXSTYLE,
GetWindowLongPtr(hwnd, GWL_EXSTYLE) |
WS_EX_CONTEXTHELP);
else {
HWND item = GetDlgItem(hwnd, IDC_HELPBTN);
if (item)
DestroyWindow(item);
}
SendMessage(hwnd, WM_SETICON, (WPARAM) ICON_BIG,
(LPARAM) LoadIcon(hinst, MAKEINTRESOURCE(IDI_CFGICON)));
/*
* Centre the window.
*/
{ /* centre the window */
RECT rs, rd;
hw = GetDesktopWindow();
if (GetWindowRect(hw, &rs) && GetWindowRect(hwnd, &rd))
MoveWindow(hwnd,
#ifdef MOD_PERSO
GetConfigBoxLeft()>0 ? GetConfigBoxLeft() : (rs.right + rs.left + rd.left - rd.right) / 2,
GetConfigBoxTop()>0 ? GetConfigBoxTop() : (rs.bottom + rs.top + rd.top - rd.bottom) / 2,
#else
(rs.right + rs.left + rd.left - rd.right) / 2,
(rs.bottom + rs.top + rd.top - rd.bottom) / 2,
#endif
rd.right - rd.left, rd.bottom - rd.top, true);
}
/*
* Create the tree view.
*/
{
RECT r;
WPARAM font;
HWND tvstatic;
r.left = 3;
r.right = r.left + 95;
r.top = 3;
r.bottom = r.top + 10;
MapDialogRect(hwnd, &r);
tvstatic = CreateWindowEx(0, "STATIC", "Cate&gory:",
WS_CHILD | WS_VISIBLE,
r.left, r.top,
r.right - r.left, r.bottom - r.top,
hwnd, (HMENU) IDCX_TVSTATIC, hinst,
NULL);
font = SendMessage(hwnd, WM_GETFONT, 0, 0);
SendMessage(tvstatic, WM_SETFONT, font, MAKELPARAM(true, 0));
r.left = 3;
r.right = r.left + 95;
r.top = 13;
r.bottom = r.top + 219;
MapDialogRect(hwnd, &r);
treeview = CreateWindowEx(WS_EX_CLIENTEDGE, WC_TREEVIEW, "",
WS_CHILD | WS_VISIBLE |
WS_TABSTOP | TVS_HASLINES |
TVS_DISABLEDRAGDROP | TVS_HASBUTTONS
| TVS_LINESATROOT |
TVS_SHOWSELALWAYS, r.left, r.top,
r.right - r.left, r.bottom - r.top,
hwnd, (HMENU) IDCX_TREEVIEW, hinst,
NULL);
font = SendMessage(hwnd, WM_GETFONT, 0, 0);
SendMessage(treeview, WM_SETFONT, font, MAKELPARAM(true, 0));
tvfaff.treeview = treeview;
memset(tvfaff.lastat, 0, sizeof(tvfaff.lastat));
}
/*
* Set up the tree view contents.
*/
{
HTREEITEM hfirst = NULL;
int i;
char *path = NULL;
char *firstpath = NULL;
for (i = 0; i < ctrlbox->nctrlsets; i++) {
struct controlset *s = ctrlbox->ctrlsets[i];
HTREEITEM item;
int j;
char *c;
if (!s->pathname[0])
continue;
j = path ? ctrl_path_compare(s->pathname, path) : 0;
if (j == INT_MAX)
continue; /* same path, nothing to add to tree */
/*
* We expect never to find an implicit path
* component. For example, we expect never to see
* A/B/C followed by A/D/E, because that would
* _implicitly_ create A/D. All our path prefixes
* are expected to contain actual controls and be
* selectable in the treeview; so we would expect
* to see A/D _explicitly_ before encountering
* A/D/E.
*/
assert(j == ctrl_path_elements(s->pathname) - 1);
c = strrchr(s->pathname, '/');
if (!c)
c = s->pathname;
else
c++;
item = treeview_insert(&tvfaff, j, c, s->pathname);
if (!hfirst) {
hfirst = item;
firstpath = s->pathname;
}
path = s->pathname;
}
/*
* Put the treeview selection on to the first panel in the
* ctrlbox.
*/
TreeView_SelectItem(treeview, hfirst);
/*
* And create the actual control set for that panel, to
* match the initial treeview selection.
*/
assert(firstpath); /* config.c must have given us _something_ */
create_controls(hwnd, firstpath);
dlg_refresh(NULL, &dp); /* and set up control values */
}
/*
* Set focus into the first available control.
*/
{
int i;
struct winctrl *c;
for (i = 0; (c = winctrl_findbyindex(&ctrls_panel, i)) != NULL;
i++) {
if (c->ctrl) {
dlg_set_focus(c->ctrl, &dp);
break;
}
}
}
/*
* Now we've finished creating our initial set of controls,
* it's safe to actually show the window without risking setup
* flicker.
*/
ShowWindow(hwnd, SW_SHOWNORMAL);
/*
* Set the flag that activates a couple of the other message
* handlers below, which were disabled until now to avoid
* spurious firing during the above setup procedure.
*/
SetWindowLongPtr(hwnd, GWLP_USERDATA, 1);
#ifdef MOD_PERSO
//ShowWindow(hwnd,SW_HIDE);
ShowWindow(hwnd,SW_SHOW);
#endif
return 0;
case WM_LBUTTONUP:
/*
* Button release should trigger WM_OK if there was a
* previous double click on the session list.
*/
ReleaseCapture();
if (dp.ended)
SaneEndDialog(hwnd, dp.endresult ? 1 : 0);
break;
case WM_NOTIFY:
if (LOWORD(wParam) == IDCX_TREEVIEW &&
((LPNMHDR) lParam)->code == TVN_SELCHANGED) {
/*
* Selection-change events on the treeview cause us to do
* a flurry of control deletion and creation - but only
* after WM_INITDIALOG has finished. The initial
* selection-change event(s) during treeview setup are
* ignored.
*/
HTREEITEM i;
TVITEM item;
char buffer[64];
if (GetWindowLongPtr(hwnd, GWLP_USERDATA) != 1)
return 0;
i = TreeView_GetSelection(((LPNMHDR) lParam)->hwndFrom);
SendMessage (hwnd, WM_SETREDRAW, false, 0);
item.hItem = i;
item.pszText = buffer;
item.cchTextMax = sizeof(buffer);
item.mask = TVIF_TEXT | TVIF_PARAM;
TreeView_GetItem(((LPNMHDR) lParam)->hwndFrom, &item);
{
/* Destroy all controls in the currently visible panel. */
int k;
HWND item;
struct winctrl *c;
while ((c = winctrl_findbyindex(&ctrls_panel, 0)) != NULL) {
for (k = 0; k < c->num_ids; k++) {
item = GetDlgItem(hwnd, c->base_id + k);
if (item)
DestroyWindow(item);
}
winctrl_rem_shortcuts(&dp, c);
winctrl_remove(&ctrls_panel, c);
sfree(c->data);
sfree(c);
}
}
create_controls(hwnd, (char *)item.lParam);
dlg_refresh(NULL, &dp); /* set up control values */
SendMessage (hwnd, WM_SETREDRAW, true, 0);
InvalidateRect (hwnd, NULL, true);
SetFocus(((LPNMHDR) lParam)->hwndFrom); /* ensure focus stays */
return 0;
}
break;
case WM_COMMAND:
case WM_DRAWITEM:
default: /* also handle drag list msg here */
/*
* Only process WM_COMMAND once the dialog is fully formed.
*/
if (GetWindowLongPtr(hwnd, GWLP_USERDATA) == 1) {
ret = winctrl_handle_command(&dp, msg, wParam, lParam);
if (dp.ended && GetCapture() != hwnd)
SaneEndDialog(hwnd, dp.endresult ? 1 : 0);
} else
ret = 0;
return ret;
case WM_HELP:
if (!winctrl_context_help(&dp, hwnd,
((LPHELPINFO)lParam)->iCtrlId))
MessageBeep(0);
break;
case WM_CLOSE:
quit_help(hwnd);
SaneEndDialog(hwnd, 0);
return 0;
/* Grrr Explorer will maximize Dialogs! */
case WM_SIZE:
if (wParam == SIZE_MAXIMIZED)
force_normal(hwnd);
return 0;
}
return 0;
}
void modal_about_box(HWND hwnd)
{
EnableWindow(hwnd, 0);
#if (defined MOD_PERSO) && (!defined FLJ)
if( GetPuttyFlag() ) {
DialogBox(hinst, MAKEINTRESOURCE(IDD_ABOUTBOX), hwnd, AboutProcOrig) ;
} else {
DialogBox(hinst, MAKEINTRESOURCE(IDD_KITTYABOUT), hwnd, AboutProc) ;
}
#else
DialogBox(hinst, MAKEINTRESOURCE(IDD_ABOUTBOX), hwnd, AboutProc);
#endif
EnableWindow(hwnd, 1);
SetActiveWindow(hwnd);
}
void show_help(HWND hwnd)
{
launch_help(hwnd, NULL);
}
void defuse_showwindow(void)
{
/*
* Work around the fact that the app's first call to ShowWindow
* will ignore the default in favour of the shell-provided
* setting.
*/
{
HWND hwnd;
hwnd = CreateDialog(hinst, MAKEINTRESOURCE(IDD_ABOUTBOX),
NULL, NullDlgProc);
ShowWindow(hwnd, SW_HIDE);
SetActiveWindow(hwnd);
DestroyWindow(hwnd);
}
}
bool do_config(Conf *conf)
{
bool ret;
#ifdef MOD_PERSO
// On cree la session "Default Settings" si elle n'existe pas
if( GetDefaultSettingsFlag() ) if( (IniFileFlag==SAVEMODE_REG) || SessPathIsInitial() ) {
char buffer[1024] ;
if( !IsThereDefaultSessionFile() ) {
Conf *defconf = conf_new() ;
load_settings(NULL,defconf);
if( !strcmp(FileExtension,"") ) {
if( save_settings( "Default Settings", defconf ) != NULL ) {
do_eventlog( "Can not create Default Settings file" ) ;
}
} else {
sprintf(buffer,"Default Settings%s", FileExtension);
if( save_settings( buffer, defconf ) != NULL ) {
do_eventlog("Can not create Default Settings file" ) ;
}
}
conf_free( defconf ) ;
}
}
#endif
ctrlbox = ctrl_new_box();
setup_config_box(ctrlbox, false, 0, 0);
win_setup_config_box(ctrlbox, &dp.hwnd, has_help(), false, 0);
dp_init(&dp);
winctrl_init(&ctrls_base);
winctrl_init(&ctrls_panel);
dp_add_tree(&dp, &ctrls_base);
dp_add_tree(&dp, &ctrls_panel);
dp.wintitle = dupprintf("%s Configuration", appname);
dp.errtitle = dupprintf("%s Error", appname);
dp.data = conf;
dlg_auto_set_fixed_pitch_flag(&dp);
dp.shortcuts['g'] = true; /* the treeview: `Cate&gory' */
ret =
SaneDialogBox(hinst, MAKEINTRESOURCE(IDD_MAINBOX), NULL,
GenericMainDlgProc);
ctrl_free_box(ctrlbox);
winctrl_cleanup(&ctrls_panel);
winctrl_cleanup(&ctrls_base);
dp_cleanup(&dp);
#ifdef MOD_PERSO
GotoConfigDirectory() ;
if( ret==false ) SaveRegistryKey( ) ; // On sort de la config box par ESCAPE ou cancel
else _beginthread( routine_SaveRegistryKey, 0, (void*)NULL ) ; // On démarre une session
#endif
return ret;
}
bool do_reconfig(HWND hwnd, Conf *conf, int protcfginfo)
{
Conf *backup_conf;
bool ret;
int protocol;
backup_conf = conf_copy(conf);
ctrlbox = ctrl_new_box();
protocol = conf_get_int(conf, CONF_protocol);
setup_config_box(ctrlbox, true, protocol, protcfginfo);
win_setup_config_box(ctrlbox, &dp.hwnd, has_help(), true, protocol);
dp_init(&dp);
winctrl_init(&ctrls_base);
winctrl_init(&ctrls_panel);
dp_add_tree(&dp, &ctrls_base);
dp_add_tree(&dp, &ctrls_panel);
dp.wintitle = dupprintf("%s Reconfiguration", appname);
dp.errtitle = dupprintf("%s Error", appname);
dp.data = conf;
dlg_auto_set_fixed_pitch_flag(&dp);
dp.shortcuts['g'] = true; /* the treeview: `Cate&gory' */
ret = SaneDialogBox(hinst, MAKEINTRESOURCE(IDD_MAINBOX), NULL,
GenericMainDlgProc) ;
ctrl_free_box(ctrlbox);
winctrl_cleanup(&ctrls_base);
winctrl_cleanup(&ctrls_panel);
dp_cleanup(&dp);
if (!ret)
conf_copy_into(conf, backup_conf);
#if (defined MOD_BACKGROUNDIMAGE) && (!defined FLJ)
if( GetBackgroundImageFlag() && (conf_get_int(conf,CONF_bg_slideshow)!=conf_get_int(backup_conf,CONF_bg_slideshow)) ) {
KillTimer( hwnd, TIMER_SLIDEBG ) ;
if((conf_get_int(conf,CONF_bg_type)!=0)&&(conf_get_int(conf,CONF_bg_slideshow)>0))
SetTimer(hwnd, TIMER_SLIDEBG, (int)(conf_get_int(conf,CONF_bg_slideshow)*1000), NULL) ;
InvalidateRect(hwnd, NULL, TRUE);
}
#endif
conf_free(backup_conf);
return ret;
}
static void win_gui_eventlog(LogPolicy *lp, const char *string)
{
char timebuf[40];
char **location;
struct tm tm;
tm=ltime();
strftime(timebuf, sizeof(timebuf), "%Y-%m-%d %H:%M:%S\t", &tm);
if (ninitial < LOGEVENT_INITIAL_MAX)
location = &events_initial[ninitial];
else
location = &events_circular[(circular_first + ncircular) % LOGEVENT_CIRCULAR_MAX];
if (*location)
sfree(*location);
*location = dupcat(timebuf, string);
if (logbox) {
int count;
SendDlgItemMessage(logbox, IDN_LIST, LB_ADDSTRING,
0, (LPARAM) *location);
count = SendDlgItemMessage(logbox, IDN_LIST, LB_GETCOUNT, 0, 0);
SendDlgItemMessage(logbox, IDN_LIST, LB_SETTOPINDEX, count - 1, 0);
}
if (ninitial < LOGEVENT_INITIAL_MAX) {
ninitial++;
} else if (ncircular < LOGEVENT_CIRCULAR_MAX) {
ncircular++;
} else if (ncircular == LOGEVENT_CIRCULAR_MAX) {
circular_first = (circular_first + 1) % LOGEVENT_CIRCULAR_MAX;
sfree(events_circular[circular_first]);
events_circular[circular_first] = dupstr("..");
}
}
static void win_gui_logging_error(LogPolicy *lp, const char *event)
{
WinGuiSeat *wgs = container_of(lp, WinGuiSeat, logpolicy);
/* Send 'can't open log file' errors to the terminal window.
* (Marked as stderr, although terminal.c won't care.) */
seat_stderr_pl(&wgs->seat, ptrlen_from_asciz(event));
seat_stderr_pl(&wgs->seat, PTRLEN_LITERAL("\r\n"));
}
void showeventlog(HWND hwnd)
{
if (!logbox) {
logbox = CreateDialog(hinst, MAKEINTRESOURCE(IDD_LOGBOX),
hwnd, LogProc);
ShowWindow(logbox, SW_SHOWNORMAL);
}
SetActiveWindow(logbox);
}
#if (defined MOD_PERSO) && (!defined FLJ)
void showabout(HWND hwnd)
{
/*
char buffer[1024] ;
DialogBox(hinst, MAKEINTRESOURCE(IDD_ABOUTBOX), hwnd, AboutProc);
sprintf( buffer, "That's all folks ! version\r\n%s", BuildVersionTime ) ;
MessageBox( hwnd, buffer, "Info", MB_OK ) ;
*/
if( get_param("PUTTY") ) DialogBox(hinst, MAKEINTRESOURCE(IDD_ABOUTBOX), hwnd, AboutProcOrig);
else {
DialogBox(hinst, MAKEINTRESOURCE(IDD_KITTYABOUT), hwnd, AboutProc);
/*if( GetIconeFlag() != -1 ) SetNewIcon( hwnd, conf_get_filename(conf,CONF_iconefile)->path, conf_get_int(conf,CONF_icone), SI_NEXT ) ;
if( GetIconeFlag() > 0 ) {
time_t ttime = time( NULL ) % GetNumberOfIcons() ;
SendMessage( hwnd, WM_SETICON, ICON_BIG, (LPARAM)LoadIcon( hinst, MAKEINTRESOURCE(IDI_MAINICON_0 + ttime ) ) );
}*/
}
}
#else
void showabout(HWND hwnd)
{
DialogBox(hinst, MAKEINTRESOURCE(IDD_ABOUTBOX), hwnd, AboutProc);
}
#endif
struct hostkey_dialog_ctx {
const char *const *keywords;
const char *const *values;
FingerprintType fptype_default;
char **fingerprints;
const char *keydisp;
LPCTSTR iconid;
const char *helpctx;
};
static INT_PTR CALLBACK HostKeyMoreInfoProc(HWND hwnd, UINT msg,
WPARAM wParam, LPARAM lParam)
{
switch (msg) {
case WM_INITDIALOG: {
const struct hostkey_dialog_ctx *ctx =
(const struct hostkey_dialog_ctx *)lParam;
SetWindowLongPtr(hwnd, GWLP_USERDATA, (INT_PTR)ctx);
if (ctx->fingerprints[SSH_FPTYPE_SHA256])
SetDlgItemText(hwnd, IDC_HKI_SHA256,
ctx->fingerprints[SSH_FPTYPE_SHA256]);
if (ctx->fingerprints[SSH_FPTYPE_MD5])
SetDlgItemText(hwnd, IDC_HKI_MD5,
ctx->fingerprints[SSH_FPTYPE_MD5]);
SetDlgItemText(hwnd, IDA_TEXT, ctx->keydisp);
return 1;
}
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDOK:
EndDialog(hwnd, 0);
return 0;
}
return 0;
case WM_CLOSE:
EndDialog(hwnd, 0);
return 0;
}
return 0;
}
static INT_PTR CALLBACK HostKeyDialogProc(HWND hwnd, UINT msg,
WPARAM wParam, LPARAM lParam)
{
switch (msg) {
case WM_INITDIALOG: {
strbuf *sb = strbuf_new();
const struct hostkey_dialog_ctx *ctx =
(const struct hostkey_dialog_ctx *)lParam;
SetWindowLongPtr(hwnd, GWLP_USERDATA, (INT_PTR)ctx);
for (int id = 100;; id++) {
char buf[256];
if (!GetDlgItemText(hwnd, id, buf, (int)lenof(buf)))
break;
strbuf_clear(sb);
for (const char *p = buf; *p ;) {
if (*p == '{') {
for (size_t i = 0; ctx->keywords[i]; i++) {
if (strstartswith(p, ctx->keywords[i])) {
p += strlen(ctx->keywords[i]);
put_datapl(sb, ptrlen_from_asciz(ctx->values[i]));
goto matched;
}
}
} else {
put_byte(sb, *p++);
}
matched:;
}
SetDlgItemText(hwnd, id, sb->s);
}
strbuf_free(sb);
SetDlgItemText(hwnd, IDC_HK_FINGERPRINT,
ctx->fingerprints[ctx->fptype_default]);
MakeDlgItemBorderless(hwnd, IDC_HK_FINGERPRINT);
HANDLE icon = LoadImage(
NULL, ctx->iconid, IMAGE_ICON,
GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON),
LR_SHARED);
SendDlgItemMessage(hwnd, IDC_HK_ICON, STM_SETICON, (WPARAM)icon, 0);
if (!has_help()) {
HWND item = GetDlgItem(hwnd, IDHELP);
if (item)
DestroyWindow(item);
}
#ifdef MOD_PERSO
SaveRegistryKey() ;
#endif
return 1;
}
case WM_CTLCOLORSTATIC: {
HDC hdc = (HDC)wParam;
HWND control = (HWND)lParam;
if (GetWindowLongPtr(control, GWLP_ID) == IDC_HK_TITLE) {
SetBkMode(hdc, TRANSPARENT);
HFONT prev_font = (HFONT)SelectObject(
hdc, (HFONT)GetStockObject(SYSTEM_FONT));
LOGFONT lf;
if (GetObject(prev_font, sizeof(lf), &lf)) {
lf.lfWeight = FW_BOLD;
lf.lfHeight = lf.lfHeight * 3 / 2;
HFONT bold_font = CreateFontIndirect(&lf);
if (bold_font)
SelectObject(hdc, bold_font);
}
return (INT_PTR)GetSysColorBrush(COLOR_BTNFACE);
}
return 0;
}
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDC_HK_ACCEPT:
case IDC_HK_ONCE:
case IDCANCEL:
EndDialog(hwnd, LOWORD(wParam));
return 0;
case IDHELP: {
const struct hostkey_dialog_ctx *ctx =
(const struct hostkey_dialog_ctx *)
GetWindowLongPtr(hwnd, GWLP_USERDATA);
launch_help(hwnd, ctx->helpctx);
return 0;
}
case IDC_HK_MOREINFO: {
const struct hostkey_dialog_ctx *ctx =
(const struct hostkey_dialog_ctx *)
GetWindowLongPtr(hwnd, GWLP_USERDATA);
DialogBoxParam(hinst, MAKEINTRESOURCE(IDD_HK_MOREINFO),
hwnd, HostKeyMoreInfoProc, (LPARAM)ctx);
}
}
return 0;
case WM_CLOSE:
EndDialog(hwnd, IDCANCEL);
return 0;
}
return 0;
}
int win_seat_verify_ssh_host_key(
Seat *seat, const char *host, int port, const char *keytype,
char *keystr, const char *keydisp, char **fingerprints,
void (*callback)(void *ctx, int result), void *ctx)
{
int ret;
WinGuiSeat *wgs = container_of(seat, WinGuiSeat, seat);
/*
* Verify the key against the registry.
*/
ret = verify_host_key(host, port, keytype, keystr);
if (ret == 0) /* success - key matched OK */
return 1;
else {
static const char *const keywords[] =
{ "{KEYTYPE}", "{APPNAME}", NULL };
const char *values[2];
values[0] = keytype;
values[1] = appname;
struct hostkey_dialog_ctx ctx[1];
ctx->keywords = keywords;
ctx->values = values;
ctx->fingerprints = fingerprints;
ctx->fptype_default = ssh2_pick_default_fingerprint(fingerprints);
ctx->keydisp = keydisp;
ctx->iconid = (ret == 2 ? IDI_WARNING : IDI_QUESTION);
ctx->helpctx = (ret == 2 ? WINHELP_CTX_errors_hostkey_changed :
WINHELP_CTX_errors_hostkey_absent);
int dlgid = (ret == 2 ? IDD_HK_WRONG : IDD_HK_ABSENT);
#ifdef MOD_PERSO
int mbret ;
if( GetAutoStoreSSHKeyFlag() ) {
do_eventlog("Auto update host key") ;
mbret=IDC_HK_ACCEPT ;
} else
mbret = DialogBoxParam(
hinst, MAKEINTRESOURCE(dlgid), wgs->term_hwnd,
HostKeyDialogProc, (LPARAM)ctx);
#else
int mbret = DialogBoxParam(
hinst, MAKEINTRESOURCE(dlgid), wgs->term_hwnd,
HostKeyDialogProc, (LPARAM)ctx);
#endif
assert(mbret==IDC_HK_ACCEPT || mbret==IDC_HK_ONCE || mbret==IDCANCEL);
if (mbret == IDC_HK_ACCEPT) {
store_host_key(host, port, keytype, keystr);
return 1;
} else if (mbret == IDC_HK_ONCE)
return 1;
}
return 0; /* abandon the connection */
}
/*
* Ask whether the selected algorithm is acceptable (since it was
* below the configured 'warn' threshold).
*/
int win_seat_confirm_weak_crypto_primitive(
Seat *seat, const char *algtype, const char *algname,
void (*callback)(void *ctx, int result), void *ctx)
{
static const char mbtitle[] = "%s Security Alert";
static const char msg[] =
"The first %s supported by the server\n"
"is %s, which is below the configured\n"
"warning threshold.\n"
"Do you want to continue with this connection?\n";
char *message, *title;
int mbret;
message = dupprintf(msg, algtype, algname);
title = dupprintf(mbtitle, appname);
mbret = MessageBox(NULL, message, title,
MB_ICONWARNING | MB_YESNO | MB_DEFBUTTON2);
socket_reselect_all();
sfree(message);
sfree(title);
if (mbret == IDYES)
return 1;
else
return 0;
}
int win_seat_confirm_weak_cached_hostkey(
Seat *seat, const char *algname, const char *betteralgs,
void (*callback)(void *ctx, int result), void *ctx)
{
static const char mbtitle[] = "%s Security Alert";
static const char msg[] =
"The first host key type we have stored for this server\n"
"is %s, which is below the configured warning threshold.\n"
"The server also provides the following types of host key\n"
"above the threshold, which we do not have stored:\n"
"%s\n"
"Do you want to continue with this connection?\n";
char *message, *title;
int mbret;
message = dupprintf(msg, algname, betteralgs);
title = dupprintf(mbtitle, appname);
mbret = MessageBox(NULL, message, title,
MB_ICONWARNING | MB_YESNO | MB_DEFBUTTON2);
socket_reselect_all();
sfree(message);
sfree(title);
if (mbret == IDYES)
return 1;
else
return 0;
}
/*
* Ask whether to wipe a session log file before writing to it.
* Returns 2 for wipe, 1 for append, 0 for cancel (don't log).
*/
static int win_gui_askappend(LogPolicy *lp, Filename *filename,
void (*callback)(void *ctx, int result),
void *ctx)
{
static const char msgtemplate[] =
"The session log file \"%.*s\" already exists.\n"
"You can overwrite it with a new session log,\n"
"append your session log to the end of it,\n"
"or disable session logging for this session.\n"
"Hit Yes to wipe the file, No to append to it,\n"
"or Cancel to disable logging.";
char *message;
char *mbtitle;
int mbret;
message = dupprintf(msgtemplate, FILENAME_MAX, filename->path);
mbtitle = dupprintf("%s Log to File", appname);
mbret = MessageBox(NULL, message, mbtitle,
MB_ICONQUESTION | MB_YESNOCANCEL | MB_DEFBUTTON3);
socket_reselect_all();
sfree(message);
sfree(mbtitle);
if (mbret == IDYES)
return 2;
else if (mbret == IDNO)
return 1;
else
return 0;
}
const LogPolicyVtable win_gui_logpolicy_vt = {
.eventlog = win_gui_eventlog,
.askappend = win_gui_askappend,
.logging_error = win_gui_logging_error,
.verbose = null_lp_verbose_yes,
};
/*
* Warn about the obsolescent key file format.
*
* Uniquely among these functions, this one does _not_ expect a
* frontend handle. This means that if PuTTY is ported to a
* platform which requires frontend handles, this function will be
* an anomaly. Fortunately, the problem it addresses will not have
* been present on that platform, so it can plausibly be
* implemented as an empty function.
*/
void old_keyfile_warning(void)
{
static const char mbtitle[] = "%s Key File Warning";
static const char message[] =
"You are loading an SSH-2 private key which has an\n"
"old version of the file format. This means your key\n"
"file is not fully tamperproof. Future versions of\n"
"%s may stop supporting this private key format,\n"
"so we recommend you convert your key to the new\n"
"format.\n"
"\n"
"You can perform this conversion by loading the key\n"
"into PuTTYgen and then saving it again.";
char *msg, *title;
msg = dupprintf(message, appname);
title = dupprintf(mbtitle, appname);
MessageBox(NULL, msg, title, MB_OK);
socket_reselect_all();
sfree(msg);
sfree(title);
}
|
17478e4160535ad9ba7bd06a0fe21b34e4f8a67f
|
d2a4f0f156eee9d89e34eddf80d2e65083617143
|
/cl.h
|
730ef0a79efcaf5f2a42162d9e201421911af323
|
[] |
no_license
|
yo8192/fcron
|
a5afeadc1a7ce3aa511cd51483d7e31ba684bebe
|
8cdee4a0deae5807818892e4431b8036ce1de6cd
|
refs/heads/master
| 2023-07-24T01:22:50.972896
| 2023-07-09T20:51:24
| 2023-07-09T20:51:24
| 198,474,775
| 112
| 13
| null | 2022-02-11T15:33:38
| 2019-07-23T17:07:01
|
C
|
UTF-8
|
C
| false
| false
| 3,544
|
h
|
cl.h
|
/*
* FCRON - periodic command scheduler
*
* Copyright 2000-2021 Thibault Godouet <fcron@free.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* The GNU General Public License can also be found in the file
* `LICENSE' that comes with the fcron source distribution.
*/
/* cl: Cron Line type and associated functions */
#ifndef __CL_H__
#define __CL_H__
/*
* TYPES
*/
#define OPTION_SIZE 4 /* number of bytes to hold the cl_option bit array */
#define LAVG_SIZE 3
/* warning : do not change the order of the members of this structure
* because some tests made are dependent to that order */
/* warning : if you change a field type, you may have to also make some changes
* in the save/load binary fcrontab functions */
typedef struct cl_t {
struct cl_t *cl_next;
struct cf_t *cl_file; /* the file in which the line is */
char *cl_shell; /* shell command */
char *cl_runas; /* determine permissions of the job */
char *cl_mailfrom; /* use this as email From header */
char *cl_mailto; /* mail output to cl_mailto */
char *cl_tz; /* time zone of the line */
unsigned long cl_id; /* line's unique id number */
time_t cl_until; /* timeout of the wait for a lavg value */
time_t cl_first; /* initial delay preserved for volatile entries */
time_t cl_nextexe; /* time and date of the next execution */
long int cl_timefreq; /* Run every n seconds */
unsigned short cl_remain; /* remaining until next execution */
unsigned short cl_runfreq; /* Run once every n matches(=1 for %-lines) */
unsigned char cl_option[OPTION_SIZE]; /* line's option (see option.h) */
unsigned char cl_lavg[LAVG_SIZE]; /*load averages needed (1,5,15 mins) */
unsigned char cl_numexe; /* entries in queues & running processes */
char cl_nice; /* nice value to control priority */
unsigned char cl_jitter; /* run randomly late up to jitter seconds */
/* see bitstring(3) man page for more details */
bitstr_t bit_decl(cl_mins, 60); /* 0-59 */
bitstr_t bit_decl(cl_hrs, 24); /* 0-23 */
bitstr_t bit_decl(cl_days, 32); /* 1-31 */
bitstr_t bit_decl(cl_mons, 12); /* 0-11 */
bitstr_t bit_decl(cl_dow, 8); /* 0-7, 0 and 7 are both Sunday */
} cl_t;
/*
* functions prototypes
*/
/* duplicate a line, including strings it points to */
cl_t *dups_cl(cl_t * orig);
void free_line(cl_t * cl);
#endif /* __CL_H__ */
|
537a4dd7bf6f0b5f8e54ba1ed58bb30e30ae378c
|
ae31542273a142210a1ff30fb76ed9d45d38eba9
|
/src/include/executor/execUtils.h
|
ed5b17538eec33c2f62e5a7119ed5a243a8b2c10
|
[
"Apache-2.0",
"LicenseRef-scancode-generic-cla",
"PostgreSQL",
"OpenSSL",
"LicenseRef-scancode-stream-benchmark",
"ISC",
"LicenseRef-scancode-openssl",
"LicenseRef-scancode-other-copyleft",
"LicenseRef-scancode-ssleay-windows",
"BSD-2-Clause",
"Python-2.0"
] |
permissive
|
greenplum-db/gpdb
|
8334837bceb2d5d51a684500793d11b190117c6a
|
2c0f8f0fb24a2d7a7da114dc80f5f5a2712fca50
|
refs/heads/main
| 2023-08-22T02:03:03.806269
| 2023-08-21T22:59:53
| 2023-08-22T01:17:10
| 44,781,140
| 6,417
| 2,082
|
Apache-2.0
| 2023-09-14T20:33:42
| 2015-10-23T00:25:17
|
C
|
UTF-8
|
C
| false
| false
| 1,192
|
h
|
execUtils.h
|
/*-------------------------------------------------------------------------
*
* execUtils.h
*
* Portions Copyright (c) 2005-2008, Greenplum inc
* Portions Copyright (c) 2012-Present VMware, Inc. or its affiliates.
*
*
* IDENTIFICATION
* src/include/executor/execUtils.h
*
*-------------------------------------------------------------------------
*/
#ifndef _EXECUTILS_H_
#define _EXECUTILS_H_
#include "executor/execdesc.h"
struct EState;
struct QueryDesc;
struct CdbDispatcherState;
extern SliceTable *InitSliceTable(struct EState *estate, PlannedStmt *plannedstmt);
extern ExecSlice *getCurrentSlice(struct EState *estate, int sliceIndex);
extern bool sliceRunsOnQD(ExecSlice *slice);
extern bool sliceRunsOnQE(ExecSlice *slice);
extern void AssignGangs(struct CdbDispatcherState *ds, QueryDesc *queryDesc);
extern Motion *findSenderMotion(PlannedStmt *plannedstmt, int sliceIndex);
extern Bitmapset *getLocallyExecutableSubplans(PlannedStmt *plannedstmt, Plan *root);
extern void InstallDispatchedExecParams(QueryDispatchDesc *ddesc, EState *estate);
#ifdef USE_ASSERT_CHECKING
struct PlannedStmt;
extern void AssertSliceTableIsValid(SliceTable *st);
#endif
#endif
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.