file
stringlengths 18
26
| data
stringlengths 3
1.04M
|
---|---|
the_stack_data/89183.c
|
#include <stdio.h>
#include <stdlib.h>
int get_int() {
int ch, i, s;
while (((ch = getchar()) == ' ') || (ch == '\n'));
s = (ch == '-') ? 1, ch = getchar() : 0;
for (i = 0; ch>='0' && ch<='9'; ch = getchar()) i = 10 * i + (ch - '0');
if (s) return -i; return i;
}
int p[10000];
int cmp(int *a, int *b) { return *b-*a; }
int main() {
register int i, n, m;
int cmp();
n = get_int(); m = get_int();
for (i = 0; i < n; i++) p[i] = get_int();
qsort(p, n, sizeof(int), cmp);
for (i = 0; i < m; i++) printf("%d\n", p[i]);
return 0;
}
|
the_stack_data/181432.c
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct widget_t {
int x;
int y;
double z;
};
#define MAX_WIDGETS 160
int foo(char *in, int count)
{
struct widget_t buf[MAX_WIDGETS];
if (count < MAX_WIDGETS)
memcpy(buf, in, count * sizeof(struct widget_t));
return 0;
}
int main(int argc, char *argv[])
{
int count;
char *in;
if (argc != 2)
{
fprintf(stderr, "target3: argc != 2\n");
exit(EXIT_FAILURE);
}
/*
* format of argv[1] is as follows:
*
* - a count, encoded as a decimal number in ASCII
* - a comma (",")
* - the remainder of the data, treated as an array
* of struct widget_t
*/
count = (int)strtoul(argv[1], &in, 10);
if (*in != ',')
{
fprintf(stderr, "target3: argument format is [count],[data]\n");
exit(EXIT_FAILURE);
}
in++; /* advance one byte, past the comma */
foo(in, count);
return 0;
}
|
the_stack_data/729886.c
|
#include <stdio.h>
#include <stdlib.h>
int main(int argc, const char *argv[]) {
if (argc < 2) {
return -1;
}
int input = atoi(argv[1]);
switch (input) {
case 0:
printf("Input was zero\n");
break;
case 1:
printf("Input was one\n");
break;
case 2:
printf("Input was two\n");
break;
case 4:
printf("Input was four\n");
break;
case 6:
printf("Input was six\n");
break;
case 12:
printf("Input was twelve\n");
break;
case 13:
printf("Input was thirteen\n");
break;
case 19:
printf("Input was nineteen\n");
break;
case 255:
printf("Input was two hundred fifty-five\n");
break;
case 0x12389:
printf("Really big input: 0x12389\n");
break;
case 0x1238A:
printf("Really big input: 0x1238A\n");
break;
case 0x1238B:
printf("Really big input: 0x1238B\n");
break;
case 0x1238C:
printf("Really big input: 0x1238C\n");
break;
case 0x1238D:
printf("Really big input: 0x1238D\n");
break;
case 0x1238F:
printf("Really big input: 0x1238F\n");
break;
case 0x12390:
printf("Really big input: 0x12390\n");
break;
case 0x12391:
printf("Really big input: 0x12391\n");
break;
case 0x12392:
printf("Really big input: 0x12392\n");
break;
case 0x12393:
printf("Really big input: 0x12393\n");
break;
default:
printf("Unknown input: %d\n", input);
}
return 0;
}
|
the_stack_data/20451637.c
|
#include <math.h>
float fmaxf(float x, float y) {
return (float) (x > y ? x : y);
}
|
the_stack_data/175142148.c
|
#include <stdio.h>
#include <stdlib.h>
int main()
{
float horas,horasE,salarioM,horaT,horasEX,salario_bruto,salario_extra,salarioF;
printf("informe suas horas de trabalho:");
scanf("%f",&horas);
printf("informe suas horas extra de trabalho");
scanf("%f",&horasE);
printf("salario minimo atual:");
scanf("%f",&salarioM);
horaT = (salarioM/8);
horasEX = (salarioM/4);
salario_bruto = horas * horaT;
salario_extra = horasE * horasEX;
salarioF = salario_bruto + salario_extra;
printf("o salario do funcionario e de RS %f",salarioF);
}
|
the_stack_data/146632.c
|
#include <stdio.h>
int afunc(char a[]);
int main(void)
{
char a[80];
scanf("%s",a);
printf("[%d]",afunc(a));
return 0;
}
int afunc(char a[])
{
int i,end,j=0,k=0;
for(i=0;a[i]!=0;i++)
{
}
end=i;
for(i=0;i<end;i++)
{
for(j=end-1;j>0;j--)
{
if(a[i]==a[j])
k++;
}
}
if(k>end)
return 1;
else
return 0;
}
|
the_stack_data/161174.c
|
#include<stdio.h>
void SumProd(int n1, int n2, int *ps, int *pp );
int main(void)
{
int no1=10, no2=20, sum=0, prod=0;
SumProd(no1, no2, &sum,&prod);
printf("\n %d + %d=%d", no1,no2,sum);
printf("\n %d * %d=%d", no1,no2,prod);
return 0;
}
void SumProd(int n1, int n2, int *ps, int *pp )
{
*ps= n1+n2;
*pp= n1*n2;
}
|
the_stack_data/111078344.c
|
# 1 "kernel/rhino/debug/k_overview.c"
# 1 "/home/stone/Documents/Ali_IOT//"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "kernel/rhino/debug/k_overview.c"
# 1 "./kernel/rhino/core/include/k_api.h" 1
# 12 "./kernel/rhino/core/include/k_api.h"
# 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/lib/gcc/arm-none-eabi/5.4.1/include/stddef.h" 1 3 4
# 149 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/lib/gcc/arm-none-eabi/5.4.1/include/stddef.h" 3 4
# 149 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/lib/gcc/arm-none-eabi/5.4.1/include/stddef.h" 3 4
typedef int ptrdiff_t;
# 216 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/lib/gcc/arm-none-eabi/5.4.1/include/stddef.h" 3 4
typedef unsigned int size_t;
# 328 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/lib/gcc/arm-none-eabi/5.4.1/include/stddef.h" 3 4
typedef unsigned int wchar_t;
# 426 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/lib/gcc/arm-none-eabi/5.4.1/include/stddef.h" 3 4
typedef struct {
long long __max_align_ll __attribute__((__aligned__(__alignof__(long long))));
long double __max_align_ld __attribute__((__aligned__(__alignof__(long double))));
} max_align_t;
# 13 "./kernel/rhino/core/include/k_api.h" 2
# 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/lib/gcc/arm-none-eabi/5.4.1/include/stdint.h" 1 3 4
# 9 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/lib/gcc/arm-none-eabi/5.4.1/include/stdint.h" 3 4
# 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/stdint.h" 1 3 4
# 12 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/stdint.h" 3 4
# 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/machine/_default_types.h" 1 3 4
# 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/features.h" 1 3 4
# 28 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/features.h" 3 4
# 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/_newlib_version.h" 1 3 4
# 29 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/features.h" 2 3 4
# 9 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/machine/_default_types.h" 2 3 4
# 27 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/machine/_default_types.h" 3 4
typedef signed char __int8_t;
typedef unsigned char __uint8_t;
# 41 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/machine/_default_types.h" 3 4
typedef short int __int16_t;
typedef short unsigned int __uint16_t;
# 63 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/machine/_default_types.h" 3 4
typedef long int __int32_t;
typedef long unsigned int __uint32_t;
# 89 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/machine/_default_types.h" 3 4
typedef long long int __int64_t;
typedef long long unsigned int __uint64_t;
# 120 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/machine/_default_types.h" 3 4
typedef signed char __int_least8_t;
typedef unsigned char __uint_least8_t;
# 146 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/machine/_default_types.h" 3 4
typedef short int __int_least16_t;
typedef short unsigned int __uint_least16_t;
# 168 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/machine/_default_types.h" 3 4
typedef long int __int_least32_t;
typedef long unsigned int __uint_least32_t;
# 186 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/machine/_default_types.h" 3 4
typedef long long int __int_least64_t;
typedef long long unsigned int __uint_least64_t;
# 200 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/machine/_default_types.h" 3 4
typedef int __intptr_t;
typedef unsigned int __uintptr_t;
# 13 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/stdint.h" 2 3 4
# 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/_intsup.h" 1 3 4
# 49 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/_intsup.h" 3 4
# 201 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/_intsup.h" 3 4
# 14 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/stdint.h" 2 3 4
# 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/_stdint.h" 1 3 4
# 20 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/_stdint.h" 3 4
typedef __int8_t int8_t ;
typedef __uint8_t uint8_t ;
typedef __int16_t int16_t ;
typedef __uint16_t uint16_t ;
typedef __int32_t int32_t ;
typedef __uint32_t uint32_t ;
typedef __int64_t int64_t ;
typedef __uint64_t uint64_t ;
typedef __intptr_t intptr_t;
typedef __uintptr_t uintptr_t;
# 15 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/stdint.h" 2 3 4
typedef __int_least8_t int_least8_t;
typedef __uint_least8_t uint_least8_t;
typedef __int_least16_t int_least16_t;
typedef __uint_least16_t uint_least16_t;
typedef __int_least32_t int_least32_t;
typedef __uint_least32_t uint_least32_t;
typedef __int_least64_t int_least64_t;
typedef __uint_least64_t uint_least64_t;
# 51 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/stdint.h" 3 4
typedef int int_fast8_t;
typedef unsigned int uint_fast8_t;
# 61 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/stdint.h" 3 4
typedef int int_fast16_t;
typedef unsigned int uint_fast16_t;
# 71 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/stdint.h" 3 4
typedef int int_fast32_t;
typedef unsigned int uint_fast32_t;
# 81 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/stdint.h" 3 4
typedef long long int int_fast64_t;
typedef long long unsigned int uint_fast64_t;
# 130 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/stdint.h" 3 4
typedef long long int intmax_t;
# 139 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/stdint.h" 3 4
typedef long long unsigned int uintmax_t;
# 10 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/lib/gcc/arm-none-eabi/5.4.1/include/stdint.h" 2 3 4
# 14 "./kernel/rhino/core/include/k_api.h" 2
# 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/string.h" 1 3
# 10 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/string.h" 3
# 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/_ansi.h" 1 3
# 15 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/_ansi.h" 3
# 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/newlib.h" 1 3
# 16 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/_ansi.h" 2 3
# 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/config.h" 1 3
# 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/machine/ieeefp.h" 1 3
# 5 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/config.h" 2 3
# 17 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/_ansi.h" 2 3
# 11 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/string.h" 2 3
# 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/reent.h" 1 3
# 13 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/reent.h" 3
# 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/_ansi.h" 1 3
# 14 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/reent.h" 2 3
# 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/lib/gcc/arm-none-eabi/5.4.1/include/stddef.h" 1 3 4
# 15 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/reent.h" 2 3
# 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/_types.h" 1 3
# 24 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/_types.h" 3
# 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/machine/_types.h" 1 3
# 25 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/_types.h" 2 3
# 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/lock.h" 1 3
typedef int _LOCK_T;
typedef int _LOCK_RECURSIVE_T;
# 26 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/_types.h" 2 3
typedef long __blkcnt_t;
typedef long __blksize_t;
typedef __uint64_t __fsblkcnt_t;
typedef __uint32_t __fsfilcnt_t;
typedef long _off_t;
typedef int __pid_t;
typedef short __dev_t;
typedef unsigned short __uid_t;
typedef unsigned short __gid_t;
typedef __uint32_t __id_t;
typedef unsigned short __ino_t;
# 88 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/_types.h" 3
typedef __uint32_t __mode_t;
__extension__ typedef long long _off64_t;
typedef _off_t __off_t;
typedef _off64_t __loff_t;
typedef long __key_t;
typedef long _fpos_t;
# 129 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/_types.h" 3
typedef unsigned int __size_t;
# 145 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/_types.h" 3
typedef signed int _ssize_t;
# 156 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/_types.h" 3
typedef _ssize_t __ssize_t;
# 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/lib/gcc/arm-none-eabi/5.4.1/include/stddef.h" 1 3 4
# 357 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/lib/gcc/arm-none-eabi/5.4.1/include/stddef.h" 3 4
typedef unsigned int wint_t;
# 160 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/_types.h" 2 3
typedef struct
{
int __count;
union
{
wint_t __wch;
unsigned char __wchb[4];
} __value;
} _mbstate_t;
typedef _LOCK_RECURSIVE_T _flock_t;
typedef void *_iconv_t;
typedef unsigned long __clock_t;
typedef long __time_t;
typedef unsigned long __clockid_t;
typedef unsigned long __timer_t;
typedef __uint8_t __sa_family_t;
typedef __uint32_t __socklen_t;
typedef unsigned short __nlink_t;
typedef long __suseconds_t;
typedef unsigned long __useconds_t;
typedef char * __va_list;
# 16 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/reent.h" 2 3
typedef unsigned long __ULong;
# 38 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/reent.h" 3
struct _reent;
struct __locale_t;
struct _Bigint
{
struct _Bigint *_next;
int _k, _maxwds, _sign, _wds;
__ULong _x[1];
};
struct __tm
{
int __tm_sec;
int __tm_min;
int __tm_hour;
int __tm_mday;
int __tm_mon;
int __tm_year;
int __tm_wday;
int __tm_yday;
int __tm_isdst;
};
struct _on_exit_args {
void * _fnargs[32];
void * _dso_handle[32];
__ULong _fntypes;
__ULong _is_cxa;
};
# 93 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/reent.h" 3
struct _atexit {
struct _atexit *_next;
int _ind;
void (*_fns[32])(void);
struct _on_exit_args _on_exit_args;
};
# 117 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/reent.h" 3
struct __sbuf {
unsigned char *_base;
int _size;
};
# 181 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/reent.h" 3
struct __sFILE {
unsigned char *_p;
int _r;
int _w;
short _flags;
short _file;
struct __sbuf _bf;
int _lbfsize;
void * _cookie;
int (* _read) (struct _reent *, void *, char *, int)
;
int (* _write) (struct _reent *, void *, const char *, int)
;
_fpos_t (* _seek) (struct _reent *, void *, _fpos_t, int);
int (* _close) (struct _reent *, void *);
struct __sbuf _ub;
unsigned char *_up;
int _ur;
unsigned char _ubuf[3];
unsigned char _nbuf[1];
struct __sbuf _lb;
int _blksize;
_off_t _offset;
struct _reent *_data;
_flock_t _lock;
_mbstate_t _mbstate;
int _flags2;
};
# 287 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/reent.h" 3
typedef struct __sFILE __FILE;
struct _glue
{
struct _glue *_next;
int _niobs;
__FILE *_iobs;
};
# 319 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/reent.h" 3
struct _rand48 {
unsigned short _seed[3];
unsigned short _mult[3];
unsigned short _add;
};
# 569 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/reent.h" 3
struct _reent
{
int _errno;
__FILE *_stdin, *_stdout, *_stderr;
int _inc;
char _emergency[25];
int _unspecified_locale_info;
struct __locale_t *_locale;
int __sdidinit;
void (* __cleanup) (struct _reent *);
struct _Bigint *_result;
int _result_k;
struct _Bigint *_p5s;
struct _Bigint **_freelist;
int _cvtlen;
char *_cvtbuf;
union
{
struct
{
unsigned int _unused_rand;
char * _strtok_last;
char _asctime_buf[26];
struct __tm _localtime_buf;
int _gamma_signgam;
__extension__ unsigned long long _rand_next;
struct _rand48 _r48;
_mbstate_t _mblen_state;
_mbstate_t _mbtowc_state;
_mbstate_t _wctomb_state;
char _l64a_buf[8];
char _signal_buf[24];
int _getdate_err;
_mbstate_t _mbrlen_state;
_mbstate_t _mbrtowc_state;
_mbstate_t _mbsrtowcs_state;
_mbstate_t _wcrtomb_state;
_mbstate_t _wcsrtombs_state;
int _h_errno;
} _reent;
struct
{
unsigned char * _nextf[30];
unsigned int _nmalloc[30];
} _unused;
} _new;
struct _atexit *_atexit;
struct _atexit _atexit0;
void (**(_sig_func))(int);
struct _glue __sglue;
__FILE __sf[3];
};
# 766 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/reent.h" 3
extern struct _reent *_impure_ptr ;
extern struct _reent *const _global_impure_ptr ;
void _reclaim_reent (struct _reent *);
# 12 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/string.h" 2 3
# 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/cdefs.h" 1 3
# 45 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/cdefs.h" 3
# 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/lib/gcc/arm-none-eabi/5.4.1/include/stddef.h" 1 3 4
# 46 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/cdefs.h" 2 3
# 13 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/string.h" 2 3
# 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/lib/gcc/arm-none-eabi/5.4.1/include/stddef.h" 1 3 4
# 18 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/string.h" 2 3
# 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/_locale.h" 1 3
# 9 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/_locale.h" 3
struct __locale_t;
typedef struct __locale_t *locale_t;
# 21 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/string.h" 2 3
void * memchr (const void *, int, size_t);
int memcmp (const void *, const void *, size_t);
void * memcpy (void * restrict, const void * restrict, size_t);
void * memmove (void *, const void *, size_t);
void * memset (void *, int, size_t);
char *strcat (char *restrict, const char *restrict);
char *strchr (const char *, int);
int strcmp (const char *, const char *);
int strcoll (const char *, const char *);
char *strcpy (char *restrict, const char *restrict);
size_t strcspn (const char *, const char *);
char *strerror (int);
size_t strlen (const char *);
char *strncat (char *restrict, const char *restrict, size_t);
int strncmp (const char *, const char *, size_t);
char *strncpy (char *restrict, const char *restrict, size_t);
char *strpbrk (const char *, const char *);
char *strrchr (const char *, int);
size_t strspn (const char *, const char *);
char *strstr (const char *, const char *);
char *strtok (char *restrict, const char *restrict);
size_t strxfrm (char *restrict, const char *restrict, size_t);
int strcoll_l (const char *, const char *, locale_t);
char *strerror_l (int, locale_t);
size_t strxfrm_l (char *restrict, const char *restrict, size_t, locale_t);
char *strtok_r (char *restrict, const char *restrict, char **restrict);
int bcmp (const void *, const void *, size_t);
void bcopy (const void *, void *, size_t);
void bzero (void *, size_t);
void explicit_bzero (void *, size_t);
int timingsafe_bcmp (const void *, const void *, size_t);
int timingsafe_memcmp (const void *, const void *, size_t);
int ffs (int);
char *index (const char *, int);
void * memccpy (void * restrict, const void * restrict, int, size_t);
# 86 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/string.h" 3
char *rindex (const char *, int);
char *stpcpy (char *restrict, const char *restrict);
char *stpncpy (char *restrict, const char *restrict, size_t);
int strcasecmp (const char *, const char *);
char *strdup (const char *);
char *_strdup_r (struct _reent *, const char *);
char *strndup (const char *, size_t);
char *_strndup_r (struct _reent *, const char *, size_t);
# 121 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/string.h" 3
int strerror_r (int, char *, size_t)
__asm__ ("" "__xpg_strerror_r")
;
char * _strerror_r (struct _reent *, int, int, int *);
size_t strlcat (char *, const char *, size_t);
size_t strlcpy (char *, const char *, size_t);
int strncasecmp (const char *, const char *, size_t);
size_t strnlen (const char *, size_t);
char *strsep (char **, const char *);
char *strlwr (char *);
char *strupr (char *);
char *strsignal (int __signo);
# 192 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/string.h" 3
# 1 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/sys/string.h" 1 3
# 193 "/home/stone/Documents/Ali_IOT/build/compiler/gcc-arm-none-eabi/Linux64/arm-none-eabi/include/string.h" 2 3
# 15 "./kernel/rhino/core/include/k_api.h" 2
# 1 "./board/mk3060/./k_config.h" 1
# 16 "./kernel/rhino/core/include/k_api.h" 2
# 1 "./kernel/rhino/core/include/k_default_config.h" 1
# 17 "./kernel/rhino/core/include/k_api.h" 2
# 1 "././platform/arch/arm/armv5/./gcc/k_types.h" 1
# 14 "././platform/arch/arm/armv5/./gcc/k_types.h"
# 14 "././platform/arch/arm/armv5/./gcc/k_types.h"
typedef char name_t;
typedef uint32_t sem_count_t;
typedef uint32_t cpu_stack_t;
typedef uint32_t hr_timer_t;
typedef uint32_t lr_timer_t;
typedef uint32_t mutex_nested_t;
typedef uint8_t suspend_nested_t;
typedef uint64_t ctx_switch_t;
typedef uint32_t cpu_cpsr_t;
# 18 "./kernel/rhino/core/include/k_api.h" 2
# 1 "./kernel/rhino/core/include/k_err.h" 1
typedef enum {
RHINO_SUCCESS = 0u,
RHINO_SYS_FATAL_ERR,
RHINO_SYS_SP_ERR,
RHINO_RUNNING,
RHINO_STOPPED,
RHINO_INV_PARAM,
RHINO_NULL_PTR,
RHINO_INV_ALIGN,
RHINO_KOBJ_TYPE_ERR,
RHINO_KOBJ_DEL_ERR,
RHINO_KOBJ_DOCKER_EXIST,
RHINO_KOBJ_BLK,
RHINO_KOBJ_SET_FULL,
RHINO_NOTIFY_FUNC_EXIST,
RHINO_MM_POOL_SIZE_ERR = 100u,
RHINO_MM_ALLOC_SIZE_ERR,
RHINO_MM_FREE_ADDR_ERR,
RHINO_MM_CORRUPT_ERR,
RHINO_DYN_MEM_PROC_ERR,
RHINO_NO_MEM,
RHINO_RINGBUF_FULL,
RHINO_RINGBUF_EMPTY,
RHINO_SCHED_DISABLE = 200u,
RHINO_SCHED_ALREADY_ENABLED,
RHINO_SCHED_LOCK_COUNT_OVF,
RHINO_INV_SCHED_WAY,
RHINO_TASK_INV_STACK_SIZE = 300u,
RHINO_TASK_NOT_SUSPENDED,
RHINO_TASK_DEL_NOT_ALLOWED,
RHINO_TASK_SUSPEND_NOT_ALLOWED,
RHINO_SUSPENDED_COUNT_OVF,
RHINO_BEYOND_MAX_PRI,
RHINO_PRI_CHG_NOT_ALLOWED,
RHINO_INV_TASK_STATE,
RHINO_IDLE_TASK_EXIST,
RHINO_NO_PEND_WAIT = 400u,
RHINO_BLK_ABORT,
RHINO_BLK_TIMEOUT,
RHINO_BLK_DEL,
RHINO_BLK_INV_STATE,
RHINO_BLK_POOL_SIZE_ERR,
RHINO_TIMER_STATE_INV = 500u,
RHINO_NO_THIS_EVENT_OPT = 600u,
RHINO_BUF_QUEUE_INV_SIZE = 700u,
RHINO_BUF_QUEUE_SIZE_ZERO,
RHINO_BUF_QUEUE_FULL,
RHINO_BUF_QUEUE_MSG_SIZE_OVERFLOW,
RHINO_QUEUE_FULL,
RHINO_QUEUE_NOT_FULL,
RHINO_SEM_OVF = 800u,
RHINO_SEM_TASK_WAITING,
RHINO_MUTEX_NOT_RELEASED_BY_OWNER = 900u,
RHINO_MUTEX_OWNER_NESTED,
RHINO_MUTEX_NESTED_OVF,
RHINO_NOT_CALLED_BY_INTRPT = 1000u,
RHINO_TRY_AGAIN,
RHINO_WORKQUEUE_EXIST = 1100u,
RHINO_WORKQUEUE_NOT_EXIST,
RHINO_WORKQUEUE_WORK_EXIST,
RHINO_WORKQUEUE_BUSY,
RHINO_WORKQUEUE_WORK_RUNNING,
RHINO_TASK_STACK_OVF = 1200u,
RHINO_INTRPT_STACK_OVF
} kstat_t;
typedef void (*krhino_err_proc_t)(kstat_t err);
extern krhino_err_proc_t g_err_proc;
# 19 "./kernel/rhino/core/include/k_api.h" 2
# 1 "./kernel/rhino/core/include/k_critical.h" 1
# 20 "./kernel/rhino/core/include/k_api.h" 2
# 1 "./kernel/rhino/core/include/k_spin_lock.h" 1
typedef struct {
cpu_cpsr_t cpsr;
} kspinlock_t;
# 21 "./kernel/rhino/core/include/k_api.h" 2
# 1 "./kernel/rhino/core/include/k_sys.h" 1
# 18 "./kernel/rhino/core/include/k_sys.h"
typedef uint64_t sys_time_t;
typedef int64_t sys_time_i_t;
typedef uint64_t idle_count_t;
typedef uint64_t tick_t;
typedef int64_t tick_i_t;
# 36 "./kernel/rhino/core/include/k_sys.h"
kstat_t krhino_init(void);
kstat_t krhino_start(void);
kstat_t krhino_intrpt_enter(void);
void krhino_intrpt_exit(void);
void krhino_intrpt_stack_ovf_check(void);
tick_t krhino_next_sleep_ticks_get(void);
size_t krhino_global_space_get(void);
uint32_t krhino_version_get(void);
# 22 "./kernel/rhino/core/include/k_api.h" 2
# 1 "./kernel/rhino/core/include/k_bitmap.h" 1
# 33 "./kernel/rhino/core/include/k_bitmap.h"
static inline void krhino_bitmap_set(uint32_t *bitmap, int32_t nr)
{
bitmap[((nr) >> 5U)] |= (1UL << (32U - 1U - ((nr) & 0X0000001F)));
}
static inline void krhino_bitmap_clear(uint32_t *bitmap, int32_t nr)
{
bitmap[((nr) >> 5U)] &= ~(1UL << (32U - 1U - ((nr) & 0X0000001F)));
}
static inline uint8_t krhino_clz32(uint32_t x)
{
uint8_t n = 0;
if (x == 0) {
return 32;
}
if ((x & 0XFFFF0000) == 0) {
x <<= 16;
n += 16;
}
if ((x & 0XFF000000) == 0) {
x <<= 8;
n += 8;
}
if ((x & 0XF0000000) == 0) {
x <<= 4;
n += 4;
}
if ((x & 0XC0000000) == 0) {
x <<= 2;
n += 2;
}
if ((x & 0X80000000) == 0) {
n += 1;
}
return n;
}
static inline uint8_t krhino_ctz32(uint32_t x)
{
uint8_t n = 0;
if (x == 0) {
return 32;
}
if ((x & 0X0000FFFF) == 0) {
x >>= 16;
n += 16;
}
if ((x & 0X000000FF) == 0) {
x >>= 8;
n += 8;
}
if ((x & 0X0000000F) == 0) {
x >>= 4;
n += 4;
}
if ((x & 0X00000003) == 0) {
x >>= 2;
n += 2;
}
if ((x & 0X00000001) == 0) {
n += 1;
}
return n;
}
static inline int32_t krhino_find_first_bit(uint32_t *bitmap)
{
int32_t nr = 0;
uint32_t tmp = 0;
while (*bitmap == 0UL) {
nr += 32U;
bitmap++;
}
tmp = *bitmap;
if (!(tmp & 0XFFFF0000)) {
tmp <<= 16;
nr += 16;
}
if (!(tmp & 0XFF000000)) {
tmp <<= 8;
nr += 8;
}
if (!(tmp & 0XF0000000)) {
tmp <<= 4;
nr += 4;
}
if (!(tmp & 0XC0000000)) {
tmp <<= 2;
nr += 2;
}
if (!(tmp & 0X80000000)) {
nr += 1;
}
return nr;
}
# 23 "./kernel/rhino/core/include/k_api.h" 2
# 1 "./kernel/rhino/core/include/k_list.h" 1
typedef struct klist_s {
struct klist_s *next;
struct klist_s *prev;
} klist_t;
static inline void klist_init(klist_t *list_head)
{
list_head->next = list_head;
list_head->prev = list_head;
}
static inline uint8_t is_klist_empty(klist_t *list)
{
return (list->next == list);
}
static inline void klist_insert(klist_t *head, klist_t *element)
{
element->prev = head->prev;
element->next = head;
head->prev->next = element;
head->prev = element;
}
static inline void klist_add(klist_t *head, klist_t *element)
{
element->prev = head;
element->next = head->next;
head->next->prev = element;
head->next = element;
}
static inline void klist_rm(klist_t *element)
{
element->prev->next = element->next;
element->next->prev = element->prev;
}
static inline void klist_rm_init(klist_t *element)
{
element->prev->next = element->next;
element->next->prev = element->prev;
element->next = element->prev = element;
}
# 24 "./kernel/rhino/core/include/k_api.h" 2
# 1 "./kernel/rhino/core/include/k_obj.h" 1
typedef enum {
BLK_POLICY_PRI = 0u,
BLK_POLICY_FIFO
} blk_policy_t;
typedef enum {
BLK_FINISH = 0,
BLK_ABORT,
BLK_TIMEOUT,
BLK_DEL,
BLK_INVALID
} blk_state_t;
typedef enum {
RHINO_OBJ_TYPE_NONE = 0,
RHINO_SEM_OBJ_TYPE,
RHINO_MUTEX_OBJ_TYPE,
RHINO_QUEUE_OBJ_TYPE,
RHINO_BUF_QUEUE_OBJ_TYPE,
RHINO_TIMER_OBJ_TYPE,
RHINO_EVENT_OBJ_TYPE,
RHINO_MM_OBJ_TYPE
} kobj_type_t;
typedef struct blk_obj {
klist_t blk_list;
const name_t *name;
blk_policy_t blk_policy;
kobj_type_t obj_type;
} blk_obj_t;
typedef struct {
klist_t task_head;
klist_t mutex_head;
klist_t mblkpool_head;
klist_t sem_head;
klist_t queue_head;
klist_t event_head;
klist_t buf_queue_head;
} kobj_list_t;
# 25 "./kernel/rhino/core/include/k_api.h" 2
# 1 "./kernel/rhino/core/include/k_sched.h" 1
# 13 "./kernel/rhino/core/include/k_sched.h"
typedef struct {
klist_t *cur_list_item[62];
uint32_t task_bit_map[((62 + 31) / 32)];
uint8_t highest_pri;
} runqueue_t;
kstat_t krhino_sched_disable(void);
kstat_t krhino_sched_enable(void);
# 26 "./kernel/rhino/core/include/k_api.h" 2
# 1 "./kernel/rhino/core/include/k_task.h" 1
typedef enum {
K_SEED,
K_RDY,
K_PEND,
K_SUSPENDED,
K_PEND_SUSPENDED,
K_SLEEP,
K_SLEEP_SUSPENDED,
K_DELETED,
} task_stat_t;
typedef struct {
void *task_stack;
const name_t *task_name;
void *user_info[2];
cpu_stack_t *task_stack_base;
uint32_t stack_size;
klist_t task_list;
suspend_nested_t suspend_count;
struct mutex_s *mutex_list;
klist_t task_stats_item;
klist_t tick_list;
tick_t tick_match;
tick_t tick_remain;
klist_t *tick_head;
void *msg;
size_t bq_msg_size;
task_stat_t task_state;
blk_state_t blk_state;
blk_obj_t *blk_obj;
struct sem_s *task_sem_obj;
# 86 "./kernel/rhino/core/include/k_task.h"
uint32_t time_slice;
uint32_t time_total;
uint32_t pend_flags;
void *pend_info;
uint8_t pend_option;
uint8_t sched_policy;
uint8_t cpu_num;
uint8_t prio;
uint8_t b_prio;
uint8_t mm_alloc_flag;
} ktask_t;
typedef void (*task_entry_t)(void *arg);
# 129 "./kernel/rhino/core/include/k_task.h"
kstat_t krhino_task_create(ktask_t *task, const name_t *name, void *arg,
uint8_t prio, tick_t ticks, cpu_stack_t *stack_buf,
size_t stack_size, task_entry_t entry, uint8_t autorun);
# 157 "./kernel/rhino/core/include/k_task.h"
kstat_t krhino_task_dyn_create(ktask_t **task, const name_t *name, void *arg,
uint8_t pri,
tick_t ticks, size_t stack,
task_entry_t entry, uint8_t autorun);
# 175 "./kernel/rhino/core/include/k_task.h"
kstat_t krhino_task_del(ktask_t *task);
kstat_t krhino_task_dyn_del(ktask_t *task);
# 192 "./kernel/rhino/core/include/k_task.h"
kstat_t krhino_task_sleep(tick_t dly);
kstat_t krhino_task_yield(void);
ktask_t *krhino_cur_task_get(void);
kstat_t krhino_task_suspend(ktask_t *task);
kstat_t krhino_task_resume(ktask_t *task);
# 228 "./kernel/rhino/core/include/k_task.h"
kstat_t krhino_task_stack_min_free(ktask_t *task, size_t *free);
# 237 "./kernel/rhino/core/include/k_task.h"
kstat_t krhino_task_stack_cur_free(ktask_t *task, size_t *free);
# 246 "./kernel/rhino/core/include/k_task.h"
kstat_t krhino_task_pri_change(ktask_t *task, uint8_t pri, uint8_t *old_pri);
kstat_t krhino_task_wait_abort(ktask_t *task);
# 264 "./kernel/rhino/core/include/k_task.h"
kstat_t krhino_task_time_slice_set(ktask_t *task, size_t slice);
kstat_t krhino_sched_policy_set(ktask_t *task, uint8_t policy);
kstat_t krhino_sched_policy_get(ktask_t *task, uint8_t *policy);
# 290 "./kernel/rhino/core/include/k_task.h"
kstat_t krhino_task_info_set(ktask_t *task, size_t idx, void *info);
kstat_t krhino_task_info_get(ktask_t *task, size_t idx, void **info);
void krhino_task_deathbed(void);
# 27 "./kernel/rhino/core/include/k_api.h" 2
# 1 "./kernel/rhino/core/include/k_ringbuf.h" 1
# 33 "./kernel/rhino/core/include/k_ringbuf.h"
typedef struct {
uint8_t *buf;
uint8_t *end;
uint8_t *head;
uint8_t *tail;
size_t freesize;
size_t type;
size_t blk_size;
} k_ringbuf_t;
# 28 "./kernel/rhino/core/include/k_api.h" 2
# 1 "./kernel/rhino/core/include/k_queue.h" 1
# 11 "./kernel/rhino/core/include/k_queue.h"
typedef struct {
void **queue_start;
size_t size;
size_t cur_num;
size_t peak_num;
} msg_q_t;
typedef struct {
msg_q_t msg_q;
klist_t *pend_entry;
} msg_info_t;
typedef struct queue_s {
blk_obj_t blk_obj;
k_ringbuf_t ringbuf;
msg_q_t msg_q;
klist_t queue_item;
uint8_t mm_alloc_flag;
} kqueue_t;
# 41 "./kernel/rhino/core/include/k_queue.h"
kstat_t krhino_queue_create(kqueue_t *queue, const name_t *name, void **start,
size_t msg_num);
kstat_t krhino_queue_del(kqueue_t *queue);
# 59 "./kernel/rhino/core/include/k_queue.h"
kstat_t krhino_queue_dyn_create(kqueue_t **queue, const name_t *name,
size_t msg_num);
kstat_t krhino_queue_dyn_del(kqueue_t *queue);
# 76 "./kernel/rhino/core/include/k_queue.h"
kstat_t krhino_queue_back_send(kqueue_t *queue, void *msg);
kstat_t krhino_queue_all_send(kqueue_t *queue, void *msg);
# 93 "./kernel/rhino/core/include/k_queue.h"
kstat_t krhino_queue_recv(kqueue_t *queue, tick_t ticks, void **msg);
kstat_t krhino_queue_is_full(kqueue_t *queue);
kstat_t krhino_queue_flush(kqueue_t *queue);
kstat_t krhino_queue_info_get(kqueue_t *queue, msg_info_t *info);
# 29 "./kernel/rhino/core/include/k_api.h" 2
# 1 "./kernel/rhino/core/include/k_buf_queue.h" 1
typedef struct {
blk_obj_t blk_obj;
void *buf;
k_ringbuf_t ringbuf;
size_t max_msg_size;
size_t cur_num;
size_t peak_num;
size_t min_free_buf_size;
klist_t buf_queue_item;
uint8_t mm_alloc_flag;
} kbuf_queue_t;
typedef struct {
size_t buf_size;
size_t max_msg_size;
size_t cur_num;
size_t peak_num;
size_t free_buf_size;
size_t min_free_buf_size;
} kbuf_queue_info_t;
# 40 "./kernel/rhino/core/include/k_buf_queue.h"
kstat_t krhino_buf_queue_create(kbuf_queue_t *queue, const name_t *name,
void *buf,
size_t size, size_t max_msg);
# 53 "./kernel/rhino/core/include/k_buf_queue.h"
kstat_t krhino_fix_buf_queue_create(kbuf_queue_t *queue, const name_t *name,
void *buf, size_t msg_size, size_t msg_num);
kstat_t krhino_buf_queue_del(kbuf_queue_t *queue);
# 72 "./kernel/rhino/core/include/k_buf_queue.h"
kstat_t krhino_buf_queue_dyn_create(kbuf_queue_t **queue, const name_t *name,
size_t size, size_t max_msg);
kstat_t krhino_buf_queue_dyn_del(kbuf_queue_t *queue);
# 90 "./kernel/rhino/core/include/k_buf_queue.h"
kstat_t krhino_buf_queue_send(kbuf_queue_t *queue, void *msg, size_t size);
# 101 "./kernel/rhino/core/include/k_buf_queue.h"
kstat_t krhino_buf_queue_recv(kbuf_queue_t *queue, tick_t ticks, void *msg,
size_t *size);
kstat_t krhino_buf_queue_flush(kbuf_queue_t *queue);
# 118 "./kernel/rhino/core/include/k_buf_queue.h"
kstat_t krhino_buf_queue_info_get(kbuf_queue_t *queue, kbuf_queue_info_t *info);
# 30 "./kernel/rhino/core/include/k_api.h" 2
# 1 "./kernel/rhino/core/include/k_sem.h" 1
# 11 "./kernel/rhino/core/include/k_sem.h"
typedef struct sem_s {
blk_obj_t blk_obj;
sem_count_t count;
sem_count_t peak_count;
klist_t sem_item;
uint8_t mm_alloc_flag;
} ksem_t;
# 28 "./kernel/rhino/core/include/k_sem.h"
kstat_t krhino_sem_create(ksem_t *sem, const name_t *name, sem_count_t count);
kstat_t krhino_sem_del(ksem_t *sem);
# 45 "./kernel/rhino/core/include/k_sem.h"
kstat_t krhino_sem_dyn_create(ksem_t **sem, const name_t *name,
sem_count_t count);
kstat_t krhino_sem_dyn_del(ksem_t *sem);
kstat_t krhino_sem_give(ksem_t *sem);
kstat_t krhino_sem_give_all(ksem_t *sem);
kstat_t krhino_sem_take(ksem_t *sem, tick_t ticks);
kstat_t krhino_sem_count_set(ksem_t *sem, sem_count_t count);
kstat_t krhino_sem_count_get(ksem_t *sem, sem_count_t *count);
# 31 "./kernel/rhino/core/include/k_api.h" 2
# 1 "./kernel/rhino/core/include/k_task_sem.h" 1
# 16 "./kernel/rhino/core/include/k_task_sem.h"
kstat_t krhino_task_sem_create(ktask_t *task, ksem_t *sem, const name_t *name,
size_t count);
kstat_t krhino_task_sem_del(ktask_t *task);
kstat_t krhino_task_sem_give(ktask_t *task);
kstat_t krhino_task_sem_take(tick_t ticks);
kstat_t krhino_task_sem_count_set(ktask_t *task, sem_count_t count);
kstat_t krhino_task_sem_count_get(ktask_t *task, sem_count_t *count);
# 32 "./kernel/rhino/core/include/k_api.h" 2
# 1 "./kernel/rhino/core/include/k_mutex.h" 1
typedef struct mutex_s {
blk_obj_t blk_obj;
ktask_t *mutex_task;
struct mutex_s *mutex_list;
mutex_nested_t owner_nested;
klist_t mutex_item;
uint8_t mm_alloc_flag;
} kmutex_t;
kstat_t krhino_mutex_create(kmutex_t *mutex, const name_t *name);
kstat_t krhino_mutex_del(kmutex_t *mutex);
# 43 "./kernel/rhino/core/include/k_mutex.h"
kstat_t krhino_mutex_dyn_create(kmutex_t **mutex, const name_t *name);
kstat_t krhino_mutex_dyn_del(kmutex_t *mutex);
# 59 "./kernel/rhino/core/include/k_mutex.h"
kstat_t krhino_mutex_lock(kmutex_t *mutex, tick_t ticks);
kstat_t krhino_mutex_unlock(kmutex_t *mutex);
# 33 "./kernel/rhino/core/include/k_api.h" 2
# 1 "./kernel/rhino/core/include/k_timer.h" 1
enum {
TIMER_CMD_CB = 0u,
TIMER_CMD_START,
TIMER_CMD_STOP,
TIMER_CMD_CHG,
TIMER_ARG_CHG,
TIMER_ARG_CHG_AUTO,
TIMER_CMD_DEL,
TIMER_CMD_DYN_DEL
};
typedef void (*timer_cb_t)(void *timer, void *arg);
typedef struct {
klist_t timer_list;
klist_t *to_head;
const name_t *name;
timer_cb_t cb;
void *timer_cb_arg;
sys_time_t match;
sys_time_t remain;
sys_time_t init_count;
sys_time_t round_ticks;
void *priv;
kobj_type_t obj_type;
uint8_t timer_state;
uint8_t mm_alloc_flag;
} ktimer_t;
typedef struct {
ktimer_t *timer;
uint8_t cb_num;
sys_time_t first;
union {
sys_time_t round;
void *arg;
} u;
} k_timer_queue_cb;
typedef enum {
TIMER_DEACTIVE = 0u,
TIMER_ACTIVE
} k_timer_state_t;
# 63 "./kernel/rhino/core/include/k_timer.h"
kstat_t krhino_timer_create(ktimer_t *timer, const name_t *name, timer_cb_t cb,
sys_time_t first, sys_time_t round, void *arg, uint8_t auto_run);
kstat_t krhino_timer_del(ktimer_t *timer);
# 85 "./kernel/rhino/core/include/k_timer.h"
kstat_t krhino_timer_dyn_create(ktimer_t **timer, const name_t *name,
timer_cb_t cb,
sys_time_t first, sys_time_t round, void *arg, uint8_t auto_run);
kstat_t krhino_timer_dyn_del(ktimer_t *timer);
kstat_t krhino_timer_start(ktimer_t *timer);
kstat_t krhino_timer_stop(ktimer_t *timer);
# 117 "./kernel/rhino/core/include/k_timer.h"
kstat_t krhino_timer_change(ktimer_t *timer, sys_time_t first, sys_time_t round);
# 126 "./kernel/rhino/core/include/k_timer.h"
kstat_t krhino_timer_arg_change_auto(ktimer_t *timer, void *arg);
kstat_t krhino_timer_arg_change(ktimer_t *timer, void *arg);
# 34 "./kernel/rhino/core/include/k_api.h" 2
# 1 "./kernel/rhino/core/include/k_time.h" 1
# 12 "./kernel/rhino/core/include/k_time.h"
void krhino_tick_proc(void);
sys_time_t krhino_sys_time_get(void);
sys_time_t krhino_sys_tick_get(void);
tick_t krhino_ms_to_ticks(sys_time_t ms);
sys_time_t krhino_ticks_to_ms(tick_t ticks);
# 35 "./kernel/rhino/core/include/k_api.h" 2
# 1 "./kernel/rhino/core/include/k_event.h" 1
typedef struct {
blk_obj_t blk_obj;
uint32_t flags;
klist_t event_item;
uint8_t mm_alloc_flag;
} kevent_t;
# 34 "./kernel/rhino/core/include/k_event.h"
kstat_t krhino_event_create(kevent_t *event, const name_t *name, uint32_t flags);
kstat_t krhino_event_del(kevent_t *event);
# 51 "./kernel/rhino/core/include/k_event.h"
kstat_t krhino_event_dyn_create(kevent_t **event, const name_t *name,
uint32_t flags);
kstat_t krhino_event_dyn_del(kevent_t *event);
# 71 "./kernel/rhino/core/include/k_event.h"
kstat_t krhino_event_get(kevent_t *event, uint32_t flags, uint8_t opt,
uint32_t *actl_flags, tick_t ticks);
# 81 "./kernel/rhino/core/include/k_event.h"
kstat_t krhino_event_set(kevent_t *event, uint32_t flags, uint8_t opt);
# 36 "./kernel/rhino/core/include/k_api.h" 2
# 1 "./kernel/rhino/core/include/k_stats.h" 1
# 9 "./kernel/rhino/core/include/k_stats.h"
void kobj_list_init(void);
void krhino_stack_ovf_check(void);
# 37 "./kernel/rhino/core/include/k_api.h" 2
# 1 "./kernel/rhino/core/include/k_mm_debug.h" 1
# 15 "./kernel/rhino/core/include/k_mm_debug.h"
typedef struct {
void *start;
void *end;
} mm_scan_region_t;
# 1 "./kernel/rhino/core/include/k_mm.h" 1
# 78 "./kernel/rhino/core/include/k_mm.h"
typedef struct free_ptr_struct {
struct k_mm_list_struct *prev;
struct k_mm_list_struct *next;
} free_ptr_t;
typedef struct k_mm_list_struct {
size_t dye;
size_t owner;
struct k_mm_list_struct *prev;
size_t buf_size;
union {
struct free_ptr_struct free_ptr;
uint8_t buffer[1];
} mbinfo;
} k_mm_list_t;
typedef struct k_mm_region_info_struct {
k_mm_list_t *end;
struct k_mm_region_info_struct *next;
} k_mm_region_info_t;
typedef struct {
kspinlock_t mm_lock;
k_mm_region_info_t *regioninfo;
void *fix_pool;
size_t used_size;
size_t maxused_size;
size_t free_size;
size_t alloc_times[(19 - 6 + 2)];
uint32_t free_bitmap;
k_mm_list_t *freelist[(19 - 6 + 2)];
} k_mm_head;
kstat_t krhino_init_mm_head(k_mm_head **ppmmhead, void *addr, size_t len );
kstat_t krhino_deinit_mm_head(k_mm_head *mmhead);
kstat_t krhino_add_mm_region(k_mm_head *mmhead, void *addr, size_t len);
void *k_mm_alloc(k_mm_head *mmhead, size_t size);
void k_mm_free(k_mm_head *mmhead, void *ptr);
void *k_mm_realloc(k_mm_head *mmhead, void *oldmem, size_t new_size);
void *krhino_mm_alloc(size_t size);
void krhino_mm_free(void *ptr);
void *krhino_mm_realloc(void *oldmem, size_t newsize);
# 22 "./kernel/rhino/core/include/k_mm_debug.h" 2
void krhino_owner_attach(k_mm_head *mmhead, void *addr, size_t allocator);
uint32_t krhino_mm_leak_region_init(void *start, void *end);
uint32_t dumpsys_mm_info_func(uint32_t len);
uint32_t dump_mmleak(void);
# 38 "./kernel/rhino/core/include/k_api.h" 2
# 1 "./kernel/rhino/core/include/k_mm_blk.h" 1
typedef struct {
const name_t *pool_name;
void *pool_end;
void *pool_start;
size_t blk_size;
size_t blk_avail;
size_t blk_whole;
uint8_t *avail_list;
kspinlock_t blk_lock;
klist_t mblkpool_stats_item;
} mblk_pool_t;
# 31 "./kernel/rhino/core/include/k_mm_blk.h"
kstat_t krhino_mblk_pool_init(mblk_pool_t *pool, const name_t *name,
void *pool_start,
size_t blk_size, size_t pool_size);
kstat_t krhino_mblk_alloc(mblk_pool_t *pool, void **blk);
kstat_t krhino_mblk_free(mblk_pool_t *pool, void *blk);
# 39 "./kernel/rhino/core/include/k_api.h" 2
# 1 "./kernel/rhino/core/include/k_mm_region.h" 1
typedef struct {
uint8_t *start;
size_t len;
} k_mm_region_t;
# 40 "./kernel/rhino/core/include/k_api.h" 2
# 1 "./kernel/rhino/core/include/k_workqueue.h" 1
# 11 "./kernel/rhino/core/include/k_workqueue.h"
typedef void (*work_handle_t)(void *arg);
typedef struct {
klist_t work_node;
work_handle_t handle;
void *arg;
tick_t dly;
ktimer_t *timer;
void *wq;
uint8_t work_exit;
} kwork_t;
typedef struct {
klist_t workqueue_node;
klist_t work_list;
kwork_t *work_current;
const name_t *name;
ktask_t worker;
ksem_t sem;
} kworkqueue_t;
# 41 "./kernel/rhino/core/include/k_workqueue.h"
kstat_t krhino_workqueue_create(kworkqueue_t *workqueue, const name_t *name,
uint8_t pri, cpu_stack_t *stack_buf, size_t stack_size);
# 52 "./kernel/rhino/core/include/k_workqueue.h"
kstat_t krhino_work_init(kwork_t *work, work_handle_t handle, void *arg,
tick_t dly);
kstat_t krhino_work_run(kworkqueue_t *workqueue, kwork_t *work);
kstat_t krhino_work_sched(kwork_t *work);
kstat_t krhino_work_cancel(kwork_t *work);
# 42 "./kernel/rhino/core/include/k_api.h" 2
# 1 "./kernel/rhino/core/include/k_internal.h" 1
extern kstat_t g_sys_stat;
extern uint8_t g_idle_task_spawned[1];
extern runqueue_t g_ready_queue;
extern uint8_t g_sched_lock[1];
extern uint8_t g_intrpt_nested_level[1];
extern ktask_t *g_preferred_ready_task[1];
extern ktask_t *g_active_task[1];
extern ktask_t g_idle_task[1];
extern idle_count_t g_idle_count[1];
extern cpu_stack_t g_idle_task_stack[1][200];
extern tick_t g_tick_count;
extern klist_t g_tick_head;
extern kobj_list_t g_kobj_list;
extern klist_t g_timer_head;
extern sys_time_t g_timer_count;
extern ktask_t g_timer_task;
extern cpu_stack_t g_timer_task_stack[300];
extern kbuf_queue_t g_timer_queue;
extern k_timer_queue_cb timer_queue_cb[20];
# 74 "./kernel/rhino/core/include/k_internal.h"
extern ksem_t g_res_sem;
extern klist_t g_res_list;
extern ktask_t g_dyn_task;
extern cpu_stack_t g_dyn_task_stack[256];
extern klist_t g_workqueue_list_head;
extern kmutex_t g_workqueue_mutex;
extern kworkqueue_t g_workqueue_default;
extern cpu_stack_t g_workqueue_stack[768];
extern k_mm_head *g_kmm_head;
# 115 "./kernel/rhino/core/include/k_internal.h"
typedef struct {
size_t cnt;
void *res[4];
klist_t res_list;
} res_free_t;
ktask_t *preferred_cpu_ready_task_get(runqueue_t *rq, uint8_t cpu_num);
void core_sched(void);
void runqueue_init(runqueue_t *rq);
void ready_list_add(runqueue_t *rq, ktask_t *task);
void ready_list_add_head(runqueue_t *rq, ktask_t *task);
void ready_list_add_tail(runqueue_t *rq, ktask_t *task);
void ready_list_rm(runqueue_t *rq, ktask_t *task);
void ready_list_head_to_tail(runqueue_t *rq, ktask_t *task);
void time_slice_update(void);
void timer_task_sched(void);
void pend_list_reorder(ktask_t *task);
void pend_task_wakeup(ktask_t *task);
void pend_to_blk_obj(blk_obj_t *blk_obj, ktask_t *task, tick_t timeout);
void pend_task_rm(ktask_t *task);
kstat_t pend_state_end_proc(ktask_t *task);
void idle_task(void *p_arg);
void idle_count_set(idle_count_t value);
idle_count_t idle_count_get(void);
void tick_list_init(void);
void tick_task_start(void);
void tick_list_rm(ktask_t *task);
void tick_list_insert(ktask_t *task, tick_t time);
void tick_list_update(tick_i_t ticks);
uint8_t mutex_pri_limit(ktask_t *tcb, uint8_t pri);
void mutex_task_pri_reset(ktask_t *tcb);
uint8_t mutex_pri_look(ktask_t *tcb, kmutex_t *mutex_rel);
kstat_t task_pri_change(ktask_t *task, uint8_t new_pri);
void k_err_proc(kstat_t err);
void ktimer_init(void);
void intrpt_disable_measure_start(void);
void intrpt_disable_measure_stop(void);
void dyn_mem_proc_task_start(void);
void cpu_usage_stats_start(void);
kstat_t ringbuf_init(k_ringbuf_t *p_ringbuf, void *buf, size_t len, size_t type,
size_t block_size);
kstat_t ringbuf_reset(k_ringbuf_t *p_ringbuf);
kstat_t ringbuf_push(k_ringbuf_t *p_ringbuf, void *data, size_t len);
kstat_t ringbuf_head_push(k_ringbuf_t *p_ringbuf, void *data, size_t len);
kstat_t ringbuf_pop(k_ringbuf_t *p_ringbuf, void *pdata, size_t *plen);
uint8_t ringbuf_is_full(k_ringbuf_t *p_ringbuf);
uint8_t ringbuf_is_empty(k_ringbuf_t *p_ringbuf);
void workqueue_init(void);
void k_mm_init(void);
# 43 "./kernel/rhino/core/include/k_api.h" 2
# 1 "./kernel/rhino/core/include/k_trace.h" 1
# 44 "./kernel/rhino/core/include/k_api.h" 2
# 1 "./kernel/rhino/core/include/k_soc.h" 1
# 35 "./kernel/rhino/core/include/k_soc.h"
void soc_err_proc(kstat_t err);
size_t soc_get_cur_sp(void);
# 45 "./kernel/rhino/core/include/k_api.h" 2
# 1 "./kernel/rhino/core/include/k_hook.h" 1
# 46 "./kernel/rhino/core/include/k_api.h" 2
# 1 "././platform/arch/arm/armv5/./gcc/port.h" 1
size_t cpu_intrpt_save(void);
void cpu_intrpt_restore(size_t cpsr);
void cpu_intrpt_switch(void);
void cpu_task_switch(void);
void cpu_first_task_start(void);
void *cpu_task_stack_init(cpu_stack_t *base, size_t size, void *arg, task_entry_t entry);
static inline uint8_t cpu_cur_get(void)
{
return 0;
}
# 47 "./kernel/rhino/core/include/k_api.h" 2
# 1 "./kernel/rhino/core/include/k_endian.h" 1
# 48 "./kernel/rhino/core/include/k_api.h" 2
# 6 "kernel/rhino/debug/k_overview.c" 2
# 1 "./kernel/rhino/debug/include/k_overview.h" 1
# 20 "./kernel/rhino/debug/include/k_overview.h"
char *k_int2str(int num, char *str);
void krhino_mm_overview(int (*print_func)(const char *fmt, ...));
void krhino_task_overview(int (*print_func)(const char *fmt, ...));
void krhino_buf_queue_overview(int (*print_func)(const char *fmt, ...));
void krhino_queue_overview(int (*print_func)(const char *fmt, ...));
void krhino_sem_overview(int (*print_func)(const char *fmt, ...));
# 7 "kernel/rhino/debug/k_overview.c" 2
char *k_int2str(int num, char *str)
{
char index[] = "0123456789ABCDEF";
str[7] = index[num % 16];
num /= 16;
str[6] = index[num % 16];
num /= 16;
str[5] = index[num % 16];
num /= 16;
str[4] = index[num % 16];
num /= 16;
str[3] = index[num % 16];
num /= 16;
str[2] = index[num % 16];
num /= 16;
str[1] = index[num % 16];
num /= 16;
str[0] = index[num % 16];
num /= 16;
return str;
}
void krhino_mm_overview(int (*print_func)(const char *fmt, ...))
{
mblk_pool_t *mm_pool;
static char s_heap_overview[] =
" | 0x | 0x | 0x | 0x |\r\n";
if ( print_func ==
# 44 "kernel/rhino/debug/k_overview.c" 3 4
((void *)0)
# 44 "kernel/rhino/debug/k_overview.c"
) {
return;
}
print_func("-----------------------------------------------------------\r\n");
print_func("[HEAP]| TotalSz | FreeSz | UsedSz | MinFreeSz |\r\n");
k_int2str((int)(g_kmm_head->free_size + g_kmm_head->used_size), &s_heap_overview[10]);
k_int2str((int)g_kmm_head->free_size, &s_heap_overview[23]);
k_int2str((int)g_kmm_head->used_size, &s_heap_overview[36]);
k_int2str((int)(g_kmm_head->free_size + g_kmm_head->used_size - g_kmm_head->maxused_size),
&s_heap_overview[49]);
print_func(s_heap_overview);
print_func("-----------------------------------------------------------\r\n");
print_func("[POOL]| TotalSz | FreeSz | UsedSz | BlkSz |\r\n");
if (g_kmm_head->fix_pool !=
# 63 "kernel/rhino/debug/k_overview.c" 3 4
((void *)0)
# 63 "kernel/rhino/debug/k_overview.c"
) {
mm_pool = (mblk_pool_t *)g_kmm_head->fix_pool;
k_int2str((int)mm_pool->blk_whole * mm_pool->blk_size, &s_heap_overview[10]);
k_int2str((int)mm_pool->blk_avail * mm_pool->blk_size, &s_heap_overview[23]);
k_int2str((int)(mm_pool->blk_whole - mm_pool->blk_avail)*mm_pool->blk_size,
&s_heap_overview[36]);
k_int2str((int)mm_pool->blk_size, &s_heap_overview[49]);
print_func(s_heap_overview);
}
print_func("-----------------------------------------------------------\r\n");
}
# 87 "kernel/rhino/debug/k_overview.c"
void krhino_task_overview(int (*print_func)(const char *fmt, ...))
{
size_t free_size;
klist_t *listnode;
ktask_t *task;
int stat_idx;
int i;
char *cpu_stat[] = {"UNK", "RDY", "PEND", "SUS", "PEND_SUS", "SLP", "SLP_SUS", "DEL"};
const name_t *task_name;
static char s_task_overview[] =
" 0x 0x 0x (0x )\r\n";
if ( print_func ==
# 99 "kernel/rhino/debug/k_overview.c" 3 4
((void *)0)
# 99 "kernel/rhino/debug/k_overview.c"
) {
return;
}
print_func("--------------------------------------------------------------------------\r\n");
print_func("TaskName State Prio Stack StackSize (MinFree)\r\n");
print_func("--------------------------------------------------------------------------\r\n");
for (listnode = g_kobj_list.task_head.next;
listnode != &g_kobj_list.task_head;
listnode = listnode->next) {
task = ((ktask_t *)((uint8_t *)(listnode) - (size_t)(&((ktask_t *)0)->task_stats_item)));
if (krhino_task_stack_min_free(task, &free_size) != RHINO_SUCCESS) {
free_size = 0;
}
free_size *= sizeof(cpu_stack_t);
task_name = task->task_name ==
# 118 "kernel/rhino/debug/k_overview.c" 3 4
((void *)0)
# 118 "kernel/rhino/debug/k_overview.c"
? "anonym" : task->task_name;
for ( i = 0 ; i < 20 ; i++ ) {
s_task_overview[i] = ' ';
}
for ( i = 0 ; i < 20 ; i++ ) {
if ( task_name[i] == '\0' ) {
break;
}
s_task_overview[i] = task_name[i];
}
stat_idx = task->task_state >= sizeof(cpu_stat) / sizeof(char *) ? 0 : task->task_state;
for ( i = 21 ; i < 29 ; i++ ) {
s_task_overview[i] = ' ';
}
for ( i = 21 ; i < 29 ; i++ ) {
if ( cpu_stat[stat_idx][i - 21] == '\0' ) {
break;
}
s_task_overview[i] = cpu_stat[stat_idx][i - 21];
}
k_int2str(task->prio, &s_task_overview[32]);
k_int2str((int)task->task_stack_base, &s_task_overview[43]);
k_int2str((int)task->stack_size * sizeof(cpu_stack_t), &s_task_overview[54]);
k_int2str((int)free_size, &s_task_overview[65]);
print_func(s_task_overview);
}
return;
}
# 168 "kernel/rhino/debug/k_overview.c"
void krhino_buf_queue_overview(int (*print_func)(const char *fmt, ...))
{
int i;
klist_t *listnode;
klist_t *blk_list_head;
ktask_t *task;
kbuf_queue_t *buf_queue;
const name_t *task_name;
static char s_buf_queue_overview[] =
"0x 0x 0x 0x 0x \r\n";
if ( print_func ==
# 179 "kernel/rhino/debug/k_overview.c" 3 4
((void *)0)
# 179 "kernel/rhino/debug/k_overview.c"
) {
return;
}
print_func("------------------------------------------------------------------\r\n");
print_func("BufQueAddr TotalSize PeakNum CurrNum MinFreeSz TaskWaiting\r\n");
print_func("------------------------------------------------------------------\r\n");
for (listnode = g_kobj_list.buf_queue_head.next;
listnode != &g_kobj_list.buf_queue_head;
listnode = listnode->next) {
buf_queue = ((kbuf_queue_t *)((uint8_t *)(listnode) - (size_t)(&((kbuf_queue_t *)0)->buf_queue_item)));
if (buf_queue->blk_obj.obj_type != RHINO_BUF_QUEUE_OBJ_TYPE) {
print_func("BufQueue Type error!\r\n");
break;
}
k_int2str((int)buf_queue->buf, &s_buf_queue_overview[2]);
k_int2str((int)(buf_queue->ringbuf.end - buf_queue->ringbuf.buf),
&s_buf_queue_overview[13]);
k_int2str((int)buf_queue->peak_num, &s_buf_queue_overview[24]);
k_int2str((int)buf_queue->cur_num, &s_buf_queue_overview[35]);
k_int2str((int)buf_queue->min_free_buf_size, &s_buf_queue_overview[46]);
blk_list_head = &buf_queue->blk_obj.blk_list;
if (is_klist_empty(blk_list_head)) {
task_name = " ";
} else {
task = ((ktask_t *)((uint8_t *)(blk_list_head->next) - (size_t)(&((ktask_t *)0)->task_list)));
task_name = task->task_name ==
# 210 "kernel/rhino/debug/k_overview.c" 3 4
((void *)0)
# 210 "kernel/rhino/debug/k_overview.c"
? "anonym" : task->task_name;
}
for ( i = 0 ; i < 20 ; i++ ) {
s_buf_queue_overview[55 + i] = ' ';
}
for ( i = 0 ; i < 20 ; i++ ) {
if ( task_name[i] == '\0' ) {
break;
}
s_buf_queue_overview[55 + i] = task_name[i];
}
print_func(s_buf_queue_overview);
}
}
# 241 "kernel/rhino/debug/k_overview.c"
void krhino_queue_overview(int (*print_func)(const char *fmt, ...))
{
int i;
klist_t *listnode;
klist_t *blk_list_head;
ktask_t *task;
kqueue_t *queue;
const name_t *task_name;
static char s_queue_overview[] =
"0x 0x 0x 0x \r\n";
if ( print_func ==
# 252 "kernel/rhino/debug/k_overview.c" 3 4
((void *)0)
# 252 "kernel/rhino/debug/k_overview.c"
) {
return;
}
print_func("-------------------------------------------------------\r\n");
print_func("QueAddr TotalSize PeakNum CurrNum TaskWaiting\n");
print_func("-------------------------------------------------------\r\n");
for (listnode = g_kobj_list.queue_head.next;
listnode != &g_kobj_list.queue_head;
listnode = listnode->next) {
queue = ((kqueue_t *)((uint8_t *)(listnode) - (size_t)(&((kqueue_t *)0)->queue_item)));
if (queue->blk_obj.obj_type != RHINO_QUEUE_OBJ_TYPE) {
print_func("Queue Type error!\r\n");
break;
}
k_int2str((int)queue->msg_q.queue_start, &s_queue_overview[2]);
k_int2str((int)queue->msg_q.size, &s_queue_overview[13]);
k_int2str((int)queue->msg_q.peak_num, &s_queue_overview[24]);
k_int2str((int)queue->msg_q.cur_num, &s_queue_overview[35]);
blk_list_head = &queue->blk_obj.blk_list;
if (is_klist_empty(blk_list_head)) {
task_name = " ";
} else {
task = ((ktask_t *)((uint8_t *)(blk_list_head->next) - (size_t)(&((ktask_t *)0)->task_list)));
task_name = task->task_name ==
# 282 "kernel/rhino/debug/k_overview.c" 3 4
((void *)0)
# 282 "kernel/rhino/debug/k_overview.c"
? "anonym" : task->task_name;
}
for ( i = 0 ; i < 20 ; i++ ) {
s_queue_overview[44 + i] = ' ';
}
for ( i = 0 ; i < 20 ; i++ ) {
if ( task_name[i] == '\0' ) {
break;
}
s_queue_overview[44 + i] = task_name[i];
}
print_func(s_queue_overview);
}
}
# 313 "kernel/rhino/debug/k_overview.c"
void krhino_sem_overview(int (*print_func)(const char *fmt, ...))
{
int i;
ksem_t *sem;
ktask_t *task;
klist_t *listnode;
klist_t *blk_list_head;
const name_t *task_name;
static char s_sem_overview[] =
"0x 0x 0x \r\n";
if ( print_func ==
# 324 "kernel/rhino/debug/k_overview.c" 3 4
((void *)0)
# 324 "kernel/rhino/debug/k_overview.c"
) {
return;
}
print_func("--------------------------------------------\r\n");
print_func("SemAddr Count PeakCount TaskWaiting\n");
print_func("--------------------------------------------\r\n");
for (listnode = g_kobj_list.sem_head.next;
listnode != &g_kobj_list.sem_head;
listnode = listnode->next) {
sem = ((ksem_t *)((uint8_t *)(listnode) - (size_t)(&((ksem_t *)0)->sem_item)));
if (sem->blk_obj.obj_type != RHINO_SEM_OBJ_TYPE) {
print_func("Sem Type error!\r\n");
break;
}
k_int2str((int)sem, &s_sem_overview[2]);
k_int2str((int)sem->count, &s_sem_overview[13]);
k_int2str((int)sem->peak_count, &s_sem_overview[24]);
blk_list_head = &sem->blk_obj.blk_list;
if (is_klist_empty(blk_list_head)) {
task_name = " ";
} else {
task = ((ktask_t *)((uint8_t *)(blk_list_head->next) - (size_t)(&((ktask_t *)0)->task_list)));
task_name = task->task_name ==
# 353 "kernel/rhino/debug/k_overview.c" 3 4
((void *)0)
# 353 "kernel/rhino/debug/k_overview.c"
? "anonym" : task->task_name;
}
for ( i = 0 ; i < 20 ; i++ ) {
s_sem_overview[33 + i] = ' ';
}
for ( i = 0 ; i < 20 ; i++ ) {
if ( task_name[i] == '\0' ) {
break;
}
s_sem_overview[33 + i] = task_name[i];
}
print_func(s_sem_overview);
}
}
|
the_stack_data/122014430.c
|
/*WRITE A C PROGRAM TO CHECK IF THE GIVEN NUMBER IS AN ARMSTRONG NUMBER OR NOT.
Hint -> An Armstrong number of 'n' digits is the sum of all the individual digits to their powers of 'n'.
For example, 371 is an Armstrong number because
371 = 3**3 + 7**3 + 1**3 (where ** represents "to the power of")
, which is the sum of individual numbers to the power 'n'! Here, 'n'is 3, since the number is 371!*/
#include<stdio.h>
#include<math.h>
void main()
{
int n,d,res=0,c=0,d1;
printf("TO CHECK IF THE GIVEN NUMBER IS AN ARMSTRONG NUMBER OR NOT......");
printf("\nEnter any number: ");
scanf("%d",&n);
int n1,n2;
n1=n;
n2=n;
while(n>0)
{
d=n%10;
c++;
n=n/10;
}
while(n1>0)
{
d1=n1%10;
res=res+(pow(d1,c));
n1=n1/10;
}
if(res==n2)
printf("The %d number is an amstrong number",n2);
else
printf("The %d number is not an amstrong number",n2);
}
|
the_stack_data/211081364.c
|
#include <stdlib.h>
#include <stdio.h>
int male(int n);
int female(int n);
int main() {
int i;
for(i=0; i < 10; i++) {
int result = male(i);
printf("Result: %d \n",result);
}
return 0;
}
int male(int n) {
if(n == 0) {
return female(n);
}
if(n > 0) {
return n - male(female(n-1));
// 1 -
}
return 0;
}
int female(int n) {
if(n == 0) {
return 0;
}
if(n > 0) {
return n - female(male(n-1));
}
return 0;
}
|
the_stack_data/80432.c
|
#include <stdio.h>
int main() {
printf("Hello World\n");
return 0;
}
|
the_stack_data/1131052.c
|
/* Based on: http://beej.us/guide/bgnet/output/html/singlepage/bgnet.html#datagram (code from "Beej's Guide to Network Programming" is public domain).
*/
// This server only listens on the first address returned by getaddrinfo().
// Modifications by: Scott Kuhl
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#define MYPORT "4950" // the port users will be connecting to
#define MAXBUFLEN 100
// get sockaddr, IPv4 or IPv6:
void *get_in_addr(struct sockaddr *sa)
{
if (sa->sa_family == AF_INET) {
return &(((struct sockaddr_in*)sa)->sin_addr);
}
return &(((struct sockaddr_in6*)sa)->sin6_addr);
}
int main(void)
{
int sockfd;
struct addrinfo hints, *servinfo, *p;
int rv;
int numbytes;
struct sockaddr_storage their_addr;
char buf[MAXBUFLEN];
socklen_t addr_len;
char s[INET6_ADDRSTRLEN];
memset(&hints, 0, sizeof hints);
hints.ai_family = AF_UNSPEC; // set to AF_INET forces IPv4; AF_INET6 forces IPv6; AF_UNSPEC allows any
hints.ai_socktype = SOCK_DGRAM;
hints.ai_flags = AI_PASSIVE; // use my IP
if ((rv = getaddrinfo(NULL, MYPORT, &hints, &servinfo)) != 0) {
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
return 1;
}
// loop through all the results and bind to the first we can
for(p = servinfo; p != NULL; p = p->ai_next) {
if ((sockfd = socket(p->ai_family, p->ai_socktype,
p->ai_protocol)) == -1) {
perror("socket");
continue;
}
if (bind(sockfd, p->ai_addr, p->ai_addrlen) == -1) {
close(sockfd);
perror("bind");
continue;
}
break;
}
if (p == NULL) {
fprintf(stderr, "failed to bind socket\n");
return 2;
}
freeaddrinfo(servinfo);
printf("waiting to recvfrom...\n");
addr_len = sizeof their_addr;
if ((numbytes = recvfrom(sockfd, buf, MAXBUFLEN-1 , 0,
(struct sockaddr *)&their_addr, &addr_len)) == -1)
{
perror("recvfrom");
exit(1);
}
printf("got packet from %s\n",
inet_ntop(their_addr.ss_family,
get_in_addr((struct sockaddr *)&their_addr),
s, sizeof s));
printf("packet is %d bytes long\n", numbytes);
buf[numbytes] = '\0';
printf("packet contains \"%s\"\n", buf);
close(sockfd);
return 0;
}
|
the_stack_data/188183.c
|
/* These stubs are provided so that autoconf can check library
* versions using C symbols only */
extern void libvampsdk_v_2_5_present(void) { }
extern void libvampsdk_v_2_4_present(void) { }
extern void libvampsdk_v_2_3_1_present(void) { }
extern void libvampsdk_v_2_3_present(void) { }
extern void libvampsdk_v_2_2_1_present(void) { }
extern void libvampsdk_v_2_2_present(void) { }
extern void libvampsdk_v_2_1_present(void) { }
extern void libvampsdk_v_2_0_present(void) { }
|
the_stack_data/154830228.c
|
/* Verify that we generate movua to load unaligned 32-bit values on SH4A. */
/* { dg-do run { target { sh4a } } } */
/* { dg-options "-O1 -save-temps -fno-inline" } */
/* { dg-final { scan-assembler-times "movua.l" 6 } } */
/* Aligned. */
struct s0 { long long d : 32; } x0;
long long f0() {
return x0.d;
}
/* Unaligned load. */
struct s1 { long long c : 8; long long d : 32; } x1;
long long f1() {
return x1.d;
}
/* Unaligned load. */
struct s2 { long long c : 16; long long d : 32; } x2;
long long f2() {
return x2.d;
}
/* Unaligned load. */
struct s3 { long long c : 24; long long d : 32; } x3;
long long f3() {
return x3.d;
}
/* Aligned. */
struct s4 { long long c : 32; long long d : 32; } x4;
long long f4() {
return x4.d;
}
/* Aligned. */
struct u0 { unsigned long long d : 32; } y_0;
unsigned long long g0() {
return y_0.d;
}
/* Unaligned load. */
struct u1 { long long c : 8; unsigned long long d : 32; } y_1;
unsigned long long g1() {
return y_1.d;
}
/* Unaligned load. */
struct u2 { long long c : 16; unsigned long long d : 32; } y2;
unsigned long long g2() {
return y2.d;
}
/* Unaligned load. */
struct u3 { long long c : 24; unsigned long long d : 32; } y3;
unsigned long long g3() {
return y3.d;
}
/* Aligned. */
struct u4 { long long c : 32; unsigned long long d : 32; } y4;
unsigned long long g4() {
return y4.d;
}
#include <assert.h>
int
main (void)
{
x1.d = 0x12345678;
assert (f1 () == 0x12345678);
x2.d = 0x12345678;
assert (f2 () == 0x12345678);
x3.d = 0x12345678;
assert (f3 () == 0x12345678);
y_1.d = 0x12345678;
assert (g1 () == 0x12345678);
y2.d = 0x12345678;
assert (g2 () == 0x12345678);
y3.d = 0x12345678;
assert (g3 () == 0x12345678);
return 0;
}
|
the_stack_data/60174.c
|
void main() {
int a=1;
int b;
if(a<0) {
b=10;
}
else {
if(a==0) {
b = 3;
printf("bogo!\n");
}
else {
b = 5;
printf("fork!\n");
}
}
printf("a: %d\n",a);
printf("a: %d\n",b);
}
|
the_stack_data/47632.c
|
#include<stdio.h>
void tabelaAscii() {
int i = 0;
while (i <= 256) {
printf("%c = %d \n", i, i);
i++;
}
}
int main(void) {
tabelaAscii();
return 0;
}
|
the_stack_data/187642315.c
|
#include <stdio.h>
#include <stdlib.h>
#include <omp.h>
/*
MIT License
Copyright (c) 2019 NOUREDDINE DAGHBOUDJ
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 N 1024
#define MAX_THREADS 4
void initArray(unsigned int *array, unsigned int size)
{
for(unsigned int i=0; i<size; i++) array[i] = rand() % 40 + 10;
}
void printArray(unsigned int *array, unsigned int size)
{
for(unsigned int i=0; i<size; i++) printf("%i ", array[i]);
printf("\n");
}
unsigned int sumArray(unsigned int *A, unsigned int size)
{
unsigned int sum[MAX_THREADS], gsum = 0;
unsigned int stride;
omp_set_num_threads(MAX_THREADS);
#pragma omp parallel
{
#pragma omp single
stride = omp_get_num_threads();
unsigned int id = omp_get_thread_num();
sum[id] = 0;
for(unsigned int i=id; i<size; i+=stride)
{
sum[id] += A[i];
}
#pragma omp barrier
#pragma omp single
for(unsigned int j=0; j<MAX_THREADS; j++) gsum += sum[j];
}
return gsum;
}
int main()
{
unsigned int a[N], b[N], c[N];
srand(0);
initArray(a, N);
printf("sum(A) = %i\n", sumArray(a, N));
return 0;
}
|
the_stack_data/9514086.c
|
#include<stdio.h>
#include<ctype.h>
#define MS 100
int top=-1,e;
void push(int);
int pop();
int peek();
void display();
int stack[MS];
char s[MS];
main()
{
int n,i,op1,op2,res;
printf("Enter the postfix expression : ");
gets(s);
for(i=0;s[i]!='\0';i++)
{
if(isdigit(s[i]))
push(s[i]-'0');
else
{
op2=pop();
op1=pop();
switch(s[i])
{
case '+':
res=op1+op2;
break;
case '-':
res=op1-op2;
break;
case '*':
res=op1*op2;
break;
case '/':
res=op1/op2;
break;
}
push(res);
}
}
printf("result is : %d",peek());
}
void push(int e)
{
top++;
stack[top]=e;
}
int pop()
{
e=stack[top];
top--;
return e;
}
int peek()
{
if(top==-1)
{
printf("**EMPTY STACK**");
return;
}
e=stack[top];
return e;
}
|
the_stack_data/76700242.c
|
#include<unistd.h>
#include<stdio.h>
#include<pthread.h>
int book=0;//给book中写数据
pthread_rwlock_t rwlock;//定义读写锁
// client put request into the vector every 5 sec.
// measure how long it takes for each individual request complete in this function
void *myread(void *arg)
{
sleep(1);//写者先运行
while(1)
{
if(pthread_rwlock_tryrdlock(&rwlock)!=0)
{
printf("reader say:the wirter is writing...\n");
sleep(1);
}
else
{
// put request
// while 等待 直到拿到reply (reply和request要有个标记来区别)
// 记录时间
printf("read done...%d\n",book);
pthread_rwlock_unlock(&rwlock);
}
}
}
// writer is server, fetch a request from the vector, then put it back
void *mywirte(void *arg)
{
while(1)
{
if(pthread_rwlock_trywrlock(&rwlock)!=0)
{
printf("writer say:the reader is reading...\n");
}
else
{
// server takes out a task from vector
// server process
// server put back a task from client
book++;
printf("write done...%d\n",book);
sleep(1); // write
pthread_rwlock_unlock(&rwlock);
}
}
}
int main()
{
pthread_rwlock_init(&rwlock,NULL);//初始化读写锁
pthread_t reader,wirter;
pthread_create(&reader,NULL,myread,NULL);
pthread_create(&wirter,NULL,mywirte,NULL);
pthread_join(reader,NULL);
pthread_join(wirter,NULL);
pthread_rwlock_destroy(&rwlock);//销毁读写锁
return 0;
}
|
the_stack_data/34511947.c
|
//Classification: n/DAM/NP/sS/D(v)/fr/cd
//Written by: Sergey Pomelov
//Reviewed by: Igor Eremeev
//Comment:
#include <stdio.h>
int *func(void)
{
int *p;
return p;
};
int main(void)
{
static int a = 1;
int c;
scanf("%d",&c);
if (c==1)
a = *func();
printf("%d %d",a,c);
return 0;
}
|
the_stack_data/215768189.c
|
#include <dirent.h>
#include <dlfcn.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
uint8_t from_hex_char(char c) {
if (c >= '0' && c <= '9') {
return (uint8_t)(c - '0');
} else if (c >= 'A' && c <= 'F'){
return (uint8_t)(10 + c - 'A');
} else if (c >= 'a' && c <= 'f'){
return (uint8_t)(10 + c - 'a');
}
return 0xFF;
}
int main(int argc, char** argv) {
if (argc != 2) {
return -1;
}
char* code = argv[1];
size_t size = strlen(code);
char* ptr = mmap(
NULL,
size >> 1,
PROT_READ | PROT_WRITE | PROT_EXEC,
MAP_PRIVATE | MAP_ANONYMOUS,
-1,
0
);
if (ptr == MAP_FAILED) {
printf("%s\n", strerror(errno));
return -1;
}
for (size_t i = 0; i < size; i += 2) {
uint8_t v = (uint8_t)(
(from_hex_char(code[i]) << 4)
| from_hex_char(code[i + 1])
);
ptr[i >> 1] = (char)v;
}
int (*f_ptr)(int, int) = (int (*)(int, int))ptr;
while (1) {
int a, b;
if (scanf("%d%d", &a, &b) != 2) {
printf("%s\n", strerror(errno));
return -1;
}
int res = f_ptr(a, b);
printf("%d\n", res);
}
return 0;
}
|
the_stack_data/151147.c
|
/*
* Copyright (c) 2005-2014 Rich Felker, et al.
* Copyright (c) 2015-2016 HarveyOS et al.
*
* Use of this source code is governed by a MIT-style
* license that can be found in the LICENSE.mit file.
*/
#include <string.h>
#include <libgen.h>
char *dirname(char *s)
{
size_t i;
if (!s || !*s) return ".";
i = strlen(s)-1;
for (; s[i]=='/'; i--) if (!i) return "/";
for (; s[i]!='/'; i--) if (!i) return ".";
for (; s[i]=='/'; i--) if (!i) return "/";
s[i+1] = 0;
return s;
}
|
the_stack_data/790439.c
|
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main()
{
int a, b;
scanf("%d %d", &a, &b);
printf("%d %d\n", a + b, a - b);
float floatA, floatB;
scanf("%f %f", &floatA, &floatB);
printf("%.1f %.1f", floatA + floatB, floatA - floatB);
return 0;
}
|
the_stack_data/18887031.c
|
/**
******************************************************************************
* @file stm32l4xx_ll_adc.c
* @author MCD Application Team
* @version V1.7.1
* @date 21-April-2017
* @brief ADC LL module driver
******************************************************************************
* @attention
*
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
*
* 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 STMicroelectronics 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.
*
******************************************************************************
*/
#if defined(USE_FULL_LL_DRIVER)
/* Includes ------------------------------------------------------------------*/
#include "stm32l4xx_ll_adc.h"
#include "stm32l4xx_ll_bus.h"
#ifdef USE_FULL_ASSERT
#include "stm32_assert.h"
#else
#define assert_param(expr) ((void)0U)
#endif
/** @addtogroup STM32L4xx_LL_Driver
* @{
*/
#if defined (ADC1) || defined (ADC2) || defined (ADC3)
/** @addtogroup ADC_LL ADC
* @{
*/
/* Private types -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private constants ---------------------------------------------------------*/
/** @addtogroup ADC_LL_Private_Constants
* @{
*/
/* Definitions of ADC hardware constraints delays */
/* Note: Only ADC IP HW delays are defined in ADC LL driver driver, */
/* not timeout values: */
/* Timeout values for ADC operations are dependent to device clock */
/* configuration (system clock versus ADC clock), */
/* and therefore must be defined in user application. */
/* Refer to @ref ADC_LL_EC_HW_DELAYS for description of ADC timeout */
/* values definition. */
/* Note: ADC timeout values are defined here in CPU cycles to be independent */
/* of device clock setting. */
/* In user application, ADC timeout values should be defined with */
/* temporal values, in function of device clock settings. */
/* Highest ratio CPU clock frequency vs ADC clock frequency: */
/* - ADC clock from synchronous clock with AHB prescaler 512, */
/* APB prescaler 16, ADC prescaler 4. */
/* - ADC clock from asynchronous clock (PLLSAI) with prescaler 1, */
/* with highest ratio CPU clock frequency vs HSI clock frequency: */
/* CPU clock frequency max 72MHz, PLLSAI freq min 26MHz: ratio 4. */
/* Unit: CPU cycles. */
#define ADC_CLOCK_RATIO_VS_CPU_HIGHEST ((uint32_t) 512U * 16U * 4U)
#define ADC_TIMEOUT_DISABLE_CPU_CYCLES (ADC_CLOCK_RATIO_VS_CPU_HIGHEST * 1U)
#define ADC_TIMEOUT_STOP_CONVERSION_CPU_CYCLES (ADC_CLOCK_RATIO_VS_CPU_HIGHEST * 1U)
/**
* @}
*/
/* Private macros ------------------------------------------------------------*/
/** @addtogroup ADC_LL_Private_Macros
* @{
*/
/* Check of parameters for configuration of ADC hierarchical scope: */
/* common to several ADC instances. */
#define IS_LL_ADC_COMMON_CLOCK(__CLOCK__) \
( ((__CLOCK__) == LL_ADC_CLOCK_SYNC_PCLK_DIV1) \
|| ((__CLOCK__) == LL_ADC_CLOCK_SYNC_PCLK_DIV2) \
|| ((__CLOCK__) == LL_ADC_CLOCK_SYNC_PCLK_DIV4) \
|| ((__CLOCK__) == LL_ADC_CLOCK_ASYNC_DIV1) \
|| ((__CLOCK__) == LL_ADC_CLOCK_ASYNC_DIV2) \
|| ((__CLOCK__) == LL_ADC_CLOCK_ASYNC_DIV4) \
|| ((__CLOCK__) == LL_ADC_CLOCK_ASYNC_DIV6) \
|| ((__CLOCK__) == LL_ADC_CLOCK_ASYNC_DIV8) \
|| ((__CLOCK__) == LL_ADC_CLOCK_ASYNC_DIV10) \
|| ((__CLOCK__) == LL_ADC_CLOCK_ASYNC_DIV12) \
|| ((__CLOCK__) == LL_ADC_CLOCK_ASYNC_DIV16) \
|| ((__CLOCK__) == LL_ADC_CLOCK_ASYNC_DIV32) \
|| ((__CLOCK__) == LL_ADC_CLOCK_ASYNC_DIV64) \
|| ((__CLOCK__) == LL_ADC_CLOCK_ASYNC_DIV128) \
|| ((__CLOCK__) == LL_ADC_CLOCK_ASYNC_DIV256) \
)
/* Check of parameters for configuration of ADC hierarchical scope: */
/* ADC instance. */
#define IS_LL_ADC_RESOLUTION(__RESOLUTION__) \
( ((__RESOLUTION__) == LL_ADC_RESOLUTION_12B) \
|| ((__RESOLUTION__) == LL_ADC_RESOLUTION_10B) \
|| ((__RESOLUTION__) == LL_ADC_RESOLUTION_8B) \
|| ((__RESOLUTION__) == LL_ADC_RESOLUTION_6B) \
)
#define IS_LL_ADC_DATA_ALIGN(__DATA_ALIGN__) \
( ((__DATA_ALIGN__) == LL_ADC_DATA_ALIGN_RIGHT) \
|| ((__DATA_ALIGN__) == LL_ADC_DATA_ALIGN_LEFT) \
)
#define IS_LL_ADC_LOW_POWER(__LOW_POWER__) \
( ((__LOW_POWER__) == LL_ADC_LP_MODE_NONE) \
|| ((__LOW_POWER__) == LL_ADC_LP_AUTOWAIT) \
)
/* Check of parameters for configuration of ADC hierarchical scope: */
/* ADC group regular */
#define IS_LL_ADC_REG_TRIG_SOURCE(__REG_TRIG_SOURCE__) \
( ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_SOFTWARE) \
|| ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_TRGO) \
|| ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_TRGO2) \
|| ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH1) \
|| ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH2) \
|| ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM1_CH3) \
|| ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM2_TRGO) \
|| ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM2_CH2) \
|| ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM3_TRGO) \
|| ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM3_CH4) \
|| ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM4_TRGO) \
|| ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM4_CH4) \
|| ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM6_TRGO) \
|| ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM8_TRGO) \
|| ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM8_TRGO2) \
|| ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_TIM15_TRGO) \
|| ((__REG_TRIG_SOURCE__) == LL_ADC_REG_TRIG_EXT_EXTI_LINE11) \
)
#define IS_LL_ADC_REG_CONTINUOUS_MODE(__REG_CONTINUOUS_MODE__) \
( ((__REG_CONTINUOUS_MODE__) == LL_ADC_REG_CONV_SINGLE) \
|| ((__REG_CONTINUOUS_MODE__) == LL_ADC_REG_CONV_CONTINUOUS) \
)
#define IS_LL_ADC_REG_DMA_TRANSFER(__REG_DMA_TRANSFER__) \
( ((__REG_DMA_TRANSFER__) == LL_ADC_REG_DMA_TRANSFER_NONE) \
|| ((__REG_DMA_TRANSFER__) == LL_ADC_REG_DMA_TRANSFER_LIMITED) \
|| ((__REG_DMA_TRANSFER__) == LL_ADC_REG_DMA_TRANSFER_UNLIMITED) \
)
#define IS_LL_ADC_REG_OVR_DATA_BEHAVIOR(__REG_OVR_DATA_BEHAVIOR__) \
( ((__REG_OVR_DATA_BEHAVIOR__) == LL_ADC_REG_OVR_DATA_PRESERVED) \
|| ((__REG_OVR_DATA_BEHAVIOR__) == LL_ADC_REG_OVR_DATA_OVERWRITTEN) \
)
#define IS_LL_ADC_REG_SEQ_SCAN_LENGTH(__REG_SEQ_SCAN_LENGTH__) \
( ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_DISABLE) \
|| ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_2RANKS) \
|| ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_3RANKS) \
|| ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_4RANKS) \
|| ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_5RANKS) \
|| ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_6RANKS) \
|| ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_7RANKS) \
|| ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_8RANKS) \
|| ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_9RANKS) \
|| ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_10RANKS) \
|| ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_11RANKS) \
|| ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_12RANKS) \
|| ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_13RANKS) \
|| ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_14RANKS) \
|| ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_15RANKS) \
|| ((__REG_SEQ_SCAN_LENGTH__) == LL_ADC_REG_SEQ_SCAN_ENABLE_16RANKS) \
)
#define IS_LL_ADC_REG_SEQ_SCAN_DISCONT_MODE(__REG_SEQ_DISCONT_MODE__) \
( ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_DISABLE) \
|| ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_1RANK) \
|| ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_2RANKS) \
|| ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_3RANKS) \
|| ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_4RANKS) \
|| ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_5RANKS) \
|| ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_6RANKS) \
|| ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_7RANKS) \
|| ((__REG_SEQ_DISCONT_MODE__) == LL_ADC_REG_SEQ_DISCONT_8RANKS) \
)
/* Check of parameters for configuration of ADC hierarchical scope: */
/* ADC group injected */
#define IS_LL_ADC_INJ_TRIG_SOURCE(__INJ_TRIG_SOURCE__) \
( ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_SOFTWARE) \
|| ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_TRGO) \
|| ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_TRGO2) \
|| ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM1_CH4) \
|| ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM2_TRGO) \
|| ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM2_CH1) \
|| ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM3_TRGO) \
|| ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM3_CH1) \
|| ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM3_CH3) \
|| ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM3_CH4) \
|| ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM4_TRGO) \
|| ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM6_TRGO) \
|| ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM8_CH4) \
|| ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM8_TRGO) \
|| ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM8_TRGO2) \
|| ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_TIM15_TRGO) \
|| ((__INJ_TRIG_SOURCE__) == LL_ADC_INJ_TRIG_EXT_EXTI_LINE15) \
)
#define IS_LL_ADC_INJ_TRIG_EXT_EDGE(__INJ_TRIG_EXT_EDGE__) \
( ((__INJ_TRIG_EXT_EDGE__) == LL_ADC_INJ_TRIG_EXT_RISING) \
|| ((__INJ_TRIG_EXT_EDGE__) == LL_ADC_INJ_TRIG_EXT_FALLING) \
|| ((__INJ_TRIG_EXT_EDGE__) == LL_ADC_INJ_TRIG_EXT_RISINGFALLING) \
)
#define IS_LL_ADC_INJ_TRIG_AUTO(__INJ_TRIG_AUTO__) \
( ((__INJ_TRIG_AUTO__) == LL_ADC_INJ_TRIG_INDEPENDENT) \
|| ((__INJ_TRIG_AUTO__) == LL_ADC_INJ_TRIG_FROM_GRP_REGULAR) \
)
#define IS_LL_ADC_INJ_SEQ_SCAN_LENGTH(__INJ_SEQ_SCAN_LENGTH__) \
( ((__INJ_SEQ_SCAN_LENGTH__) == LL_ADC_INJ_SEQ_SCAN_DISABLE) \
|| ((__INJ_SEQ_SCAN_LENGTH__) == LL_ADC_INJ_SEQ_SCAN_ENABLE_2RANKS) \
|| ((__INJ_SEQ_SCAN_LENGTH__) == LL_ADC_INJ_SEQ_SCAN_ENABLE_3RANKS) \
|| ((__INJ_SEQ_SCAN_LENGTH__) == LL_ADC_INJ_SEQ_SCAN_ENABLE_4RANKS) \
)
#define IS_LL_ADC_INJ_SEQ_SCAN_DISCONT_MODE(__INJ_SEQ_DISCONT_MODE__) \
( ((__INJ_SEQ_DISCONT_MODE__) == LL_ADC_INJ_SEQ_DISCONT_DISABLE) \
|| ((__INJ_SEQ_DISCONT_MODE__) == LL_ADC_INJ_SEQ_DISCONT_1RANK) \
)
#if defined(ADC_MULTIMODE_SUPPORT)
/* Check of parameters for configuration of ADC hierarchical scope: */
/* multimode. */
#define IS_LL_ADC_MULTI_MODE(__MULTI_MODE__) \
( ((__MULTI_MODE__) == LL_ADC_MULTI_INDEPENDENT) \
|| ((__MULTI_MODE__) == LL_ADC_MULTI_DUAL_REG_SIMULT) \
|| ((__MULTI_MODE__) == LL_ADC_MULTI_DUAL_REG_INTERL) \
|| ((__MULTI_MODE__) == LL_ADC_MULTI_DUAL_INJ_SIMULT) \
|| ((__MULTI_MODE__) == LL_ADC_MULTI_DUAL_INJ_ALTERN) \
|| ((__MULTI_MODE__) == LL_ADC_MULTI_DUAL_REG_SIM_INJ_SIM) \
|| ((__MULTI_MODE__) == LL_ADC_MULTI_DUAL_REG_SIM_INJ_ALT) \
|| ((__MULTI_MODE__) == LL_ADC_MULTI_DUAL_REG_INT_INJ_SIM) \
)
#define IS_LL_ADC_MULTI_DMA_TRANSFER(__MULTI_DMA_TRANSFER__) \
( ((__MULTI_DMA_TRANSFER__) == LL_ADC_MULTI_REG_DMA_EACH_ADC) \
|| ((__MULTI_DMA_TRANSFER__) == LL_ADC_MULTI_REG_DMA_LIMIT_RES12_10B) \
|| ((__MULTI_DMA_TRANSFER__) == LL_ADC_MULTI_REG_DMA_LIMIT_RES8_6B) \
|| ((__MULTI_DMA_TRANSFER__) == LL_ADC_MULTI_REG_DMA_UNLMT_RES12_10B) \
|| ((__MULTI_DMA_TRANSFER__) == LL_ADC_MULTI_REG_DMA_UNLMT_RES8_6B) \
)
#define IS_LL_ADC_MULTI_TWOSMP_DELAY(__MULTI_TWOSMP_DELAY__) \
( ((__MULTI_TWOSMP_DELAY__) == LL_ADC_MULTI_TWOSMP_DELAY_1CYCLE) \
|| ((__MULTI_TWOSMP_DELAY__) == LL_ADC_MULTI_TWOSMP_DELAY_2CYCLES) \
|| ((__MULTI_TWOSMP_DELAY__) == LL_ADC_MULTI_TWOSMP_DELAY_3CYCLES) \
|| ((__MULTI_TWOSMP_DELAY__) == LL_ADC_MULTI_TWOSMP_DELAY_4CYCLES) \
|| ((__MULTI_TWOSMP_DELAY__) == LL_ADC_MULTI_TWOSMP_DELAY_5CYCLES) \
|| ((__MULTI_TWOSMP_DELAY__) == LL_ADC_MULTI_TWOSMP_DELAY_6CYCLES) \
|| ((__MULTI_TWOSMP_DELAY__) == LL_ADC_MULTI_TWOSMP_DELAY_7CYCLES) \
|| ((__MULTI_TWOSMP_DELAY__) == LL_ADC_MULTI_TWOSMP_DELAY_8CYCLES) \
|| ((__MULTI_TWOSMP_DELAY__) == LL_ADC_MULTI_TWOSMP_DELAY_9CYCLES) \
|| ((__MULTI_TWOSMP_DELAY__) == LL_ADC_MULTI_TWOSMP_DELAY_10CYCLES) \
|| ((__MULTI_TWOSMP_DELAY__) == LL_ADC_MULTI_TWOSMP_DELAY_11CYCLES) \
|| ((__MULTI_TWOSMP_DELAY__) == LL_ADC_MULTI_TWOSMP_DELAY_12CYCLES) \
)
#define IS_LL_ADC_MULTI_MASTER_SLAVE(__MULTI_MASTER_SLAVE__) \
( ((__MULTI_MASTER_SLAVE__) == LL_ADC_MULTI_MASTER) \
|| ((__MULTI_MASTER_SLAVE__) == LL_ADC_MULTI_SLAVE) \
|| ((__MULTI_MASTER_SLAVE__) == LL_ADC_MULTI_MASTER_SLAVE) \
)
#endif /* ADC_MULTIMODE_SUPPORT */
/**
* @}
*/
/* Private function prototypes -----------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
/** @addtogroup ADC_LL_Exported_Functions
* @{
*/
/** @addtogroup ADC_LL_EF_Init
* @{
*/
/**
* @brief De-initialize registers of all ADC instances belonging to
* the same ADC common instance to their default reset values.
* @note This function is performing a hard reset, using high level
* clock source RCC ADC reset.
* Caution: On this STM32 serie, if several ADC instances are available
* on the selected device, RCC ADC reset will reset
* all ADC instances belonging to the common ADC instance.
* To de-initialize only 1 ADC instance, use
* function @ref LL_ADC_DeInit().
* @param ADCxy_COMMON ADC common instance
* (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() )
* @retval An ErrorStatus enumeration value:
* - SUCCESS: ADC common registers are de-initialized
* - ERROR: not applicable
*/
ErrorStatus LL_ADC_CommonDeInit(ADC_Common_TypeDef *ADCxy_COMMON)
{
/* Check the parameters */
assert_param(IS_ADC_COMMON_INSTANCE(ADCxy_COMMON));
/* Force reset of ADC clock (core clock) */
LL_AHB2_GRP1_ForceReset(LL_AHB2_GRP1_PERIPH_ADC);
/* Release reset of ADC clock (core clock) */
LL_AHB2_GRP1_ReleaseReset(LL_AHB2_GRP1_PERIPH_ADC);
return SUCCESS;
}
/**
* @brief Initialize some features of ADC common parameters
* (all ADC instances belonging to the same ADC common instance)
* and multimode (for devices with several ADC instances available).
* @note The setting of ADC common parameters is conditioned to
* ADC instances state:
* All ADC instances belonging to the same ADC common instance
* must be disabled.
* @param ADCxy_COMMON ADC common instance
* (can be set directly from CMSIS definition or by using helper macro @ref __LL_ADC_COMMON_INSTANCE() )
* @param ADC_CommonInitStruct Pointer to a @ref LL_ADC_CommonInitTypeDef structure
* @retval An ErrorStatus enumeration value:
* - SUCCESS: ADC common registers are initialized
* - ERROR: ADC common registers are not initialized
*/
ErrorStatus LL_ADC_CommonInit(ADC_Common_TypeDef *ADCxy_COMMON, LL_ADC_CommonInitTypeDef *ADC_CommonInitStruct)
{
ErrorStatus status = SUCCESS;
/* Check the parameters */
assert_param(IS_ADC_COMMON_INSTANCE(ADCxy_COMMON));
assert_param(IS_LL_ADC_COMMON_CLOCK(ADC_CommonInitStruct->CommonClock));
#if defined(ADC_MULTIMODE_SUPPORT)
assert_param(IS_LL_ADC_MULTI_MODE(ADC_CommonInitStruct->Multimode));
if(ADC_CommonInitStruct->Multimode != LL_ADC_MULTI_INDEPENDENT)
{
assert_param(IS_LL_ADC_MULTI_DMA_TRANSFER(ADC_CommonInitStruct->MultiDMATransfer));
assert_param(IS_LL_ADC_MULTI_TWOSMP_DELAY(ADC_CommonInitStruct->MultiTwoSamplingDelay));
}
#endif /* ADC_MULTIMODE_SUPPORT */
/* Note: Hardware constraint (refer to description of functions */
/* "LL_ADC_SetCommonXXX()" and "LL_ADC_SetMultiXXX()"): */
/* On this STM32 serie, setting of these features is conditioned to */
/* ADC state: */
/* All ADC instances of the ADC common group must be disabled. */
if(__LL_ADC_IS_ENABLED_ALL_COMMON_INSTANCE(ADCxy_COMMON) == 0U)
{
/* Configuration of ADC hierarchical scope: */
/* - common to several ADC */
/* (all ADC instances belonging to the same ADC common instance) */
/* - Set ADC clock (conversion clock) */
/* - multimode (if several ADC instances available on the */
/* selected device) */
/* - Set ADC multimode configuration */
/* - Set ADC multimode DMA transfer */
/* - Set ADC multimode: delay between 2 sampling phases */
#if defined(ADC_MULTIMODE_SUPPORT)
if(ADC_CommonInitStruct->Multimode != LL_ADC_MULTI_INDEPENDENT)
{
MODIFY_REG(ADCxy_COMMON->CCR,
ADC_CCR_CKMODE
| ADC_CCR_PRESC
| ADC_CCR_DUAL
| ADC_CCR_MDMA
| ADC_CCR_DELAY
,
ADC_CommonInitStruct->CommonClock
| ADC_CommonInitStruct->Multimode
| ADC_CommonInitStruct->MultiDMATransfer
| ADC_CommonInitStruct->MultiTwoSamplingDelay
);
}
else
{
MODIFY_REG(ADCxy_COMMON->CCR,
ADC_CCR_CKMODE
| ADC_CCR_PRESC
| ADC_CCR_DUAL
| ADC_CCR_MDMA
| ADC_CCR_DELAY
,
ADC_CommonInitStruct->CommonClock
| LL_ADC_MULTI_INDEPENDENT
);
}
#else
LL_ADC_SetCommonClock(ADCxy_COMMON, ADC_CommonInitStruct->CommonClock);
#endif
}
else
{
/* Initialization error: One or several ADC instances belonging to */
/* the same ADC common instance are not disabled. */
status = ERROR;
}
return status;
}
/**
* @brief Set each @ref LL_ADC_CommonInitTypeDef field to default value.
* @param ADC_CommonInitStruct Pointer to a @ref LL_ADC_CommonInitTypeDef structure
* whose fields will be set to default values.
* @retval None
*/
void LL_ADC_CommonStructInit(LL_ADC_CommonInitTypeDef *ADC_CommonInitStruct)
{
/* Set ADC_CommonInitStruct fields to default values */
/* Set fields of ADC common */
/* (all ADC instances belonging to the same ADC common instance) */
ADC_CommonInitStruct->CommonClock = LL_ADC_CLOCK_SYNC_PCLK_DIV2;
#if defined(ADC_MULTIMODE_SUPPORT)
/* Set fields of ADC multimode */
ADC_CommonInitStruct->Multimode = LL_ADC_MULTI_INDEPENDENT;
ADC_CommonInitStruct->MultiDMATransfer = LL_ADC_MULTI_REG_DMA_EACH_ADC;
ADC_CommonInitStruct->MultiTwoSamplingDelay = LL_ADC_MULTI_TWOSMP_DELAY_1CYCLE;
#endif /* ADC_MULTIMODE_SUPPORT */
}
/**
* @brief De-initialize registers of the selected ADC instance
* to their default reset values.
* @note To reset all ADC instances quickly (perform a hard reset),
* use function @ref LL_ADC_CommonDeInit().
* @note If this functions returns error status, it means that ADC instance
* is in an unknown state.
* In this case, perform a hard reset using high level
* clock source RCC ADC reset.
* Caution: On this STM32 serie, if several ADC instances are available
* on the selected device, RCC ADC reset will reset
* all ADC instances belonging to the common ADC instance.
* Refer to function @ref LL_ADC_CommonDeInit().
* @param ADCx ADC instance
* @retval An ErrorStatus enumeration value:
* - SUCCESS: ADC registers are de-initialized
* - ERROR: ADC registers are not de-initialized
*/
ErrorStatus LL_ADC_DeInit(ADC_TypeDef *ADCx)
{
ErrorStatus status = SUCCESS;
__IO uint32_t timeout_cpu_cycles = 0U;
/* Check the parameters */
assert_param(IS_ADC_ALL_INSTANCE(ADCx));
/* Disable ADC instance if not already disabled. */
if(LL_ADC_IsEnabled(ADCx) == 1U)
{
/* Set ADC group regular trigger source to SW start to ensure to not */
/* have an external trigger event occurring during the conversion stop */
/* ADC disable process. */
LL_ADC_REG_SetTriggerSource(ADCx, LL_ADC_REG_TRIG_SOFTWARE);
/* Stop potential ADC conversion on going on ADC group regular. */
if(LL_ADC_REG_IsConversionOngoing(ADCx) != 0U)
{
if(LL_ADC_REG_IsStopConversionOngoing(ADCx) == 0U)
{
LL_ADC_REG_StopConversion(ADCx);
}
}
/* Set ADC group injected trigger source to SW start to ensure to not */
/* have an external trigger event occurring during the conversion stop */
/* ADC disable process. */
LL_ADC_INJ_SetTriggerSource(ADCx, LL_ADC_INJ_TRIG_SOFTWARE);
/* Stop potential ADC conversion on going on ADC group injected. */
if(LL_ADC_INJ_IsConversionOngoing(ADCx) != 0U)
{
if(LL_ADC_INJ_IsStopConversionOngoing(ADCx) == 0U)
{
LL_ADC_INJ_StopConversion(ADCx);
}
}
/* Wait for ADC conversions are effectively stopped */
timeout_cpu_cycles = ADC_TIMEOUT_STOP_CONVERSION_CPU_CYCLES;
while (( LL_ADC_REG_IsStopConversionOngoing(ADCx)
| LL_ADC_INJ_IsStopConversionOngoing(ADCx)) == 1U)
{
if(timeout_cpu_cycles-- == 0U)
{
/* Time-out error */
status = ERROR;
}
}
/* Flush group injected contexts queue (register JSQR): */
/* Note: Bit JQM must be set to empty the contexts queue (otherwise */
/* contexts queue is maintained with the last active context). */
LL_ADC_INJ_SetQueueMode(ADCx, LL_ADC_INJ_QUEUE_2CONTEXTS_END_EMPTY);
/* Disable the ADC instance */
LL_ADC_Disable(ADCx);
/* Wait for ADC instance is effectively disabled */
timeout_cpu_cycles = ADC_TIMEOUT_DISABLE_CPU_CYCLES;
while (LL_ADC_IsDisableOngoing(ADCx) == 1U)
{
if(timeout_cpu_cycles-- == 0U)
{
/* Time-out error */
status = ERROR;
}
}
}
/* Check whether ADC state is compliant with expected state */
if(READ_BIT(ADCx->CR,
( ADC_CR_JADSTP | ADC_CR_ADSTP | ADC_CR_JADSTART | ADC_CR_ADSTART
| ADC_CR_ADDIS | ADC_CR_ADEN )
)
== 0U)
{
/* ========== Reset ADC registers ========== */
/* Reset register IER */
CLEAR_BIT(ADCx->IER,
( LL_ADC_IT_ADRDY
| LL_ADC_IT_EOC
| LL_ADC_IT_EOS
| LL_ADC_IT_OVR
| LL_ADC_IT_EOSMP
| LL_ADC_IT_JEOC
| LL_ADC_IT_JEOS
| LL_ADC_IT_JQOVF
| LL_ADC_IT_AWD1
| LL_ADC_IT_AWD2
| LL_ADC_IT_AWD3 )
);
/* Reset register ISR */
SET_BIT(ADCx->ISR,
( LL_ADC_FLAG_ADRDY
| LL_ADC_FLAG_EOC
| LL_ADC_FLAG_EOS
| LL_ADC_FLAG_OVR
| LL_ADC_FLAG_EOSMP
| LL_ADC_FLAG_JEOC
| LL_ADC_FLAG_JEOS
| LL_ADC_FLAG_JQOVF
| LL_ADC_FLAG_AWD1
| LL_ADC_FLAG_AWD2
| LL_ADC_FLAG_AWD3 )
);
/* Reset register CR */
/* - Bits ADC_CR_JADSTP, ADC_CR_ADSTP, ADC_CR_JADSTART, ADC_CR_ADSTART, */
/* ADC_CR_ADCAL, ADC_CR_ADDIS, ADC_CR_ADEN are in */
/* access mode "read-set": no direct reset applicable. */
/* - Reset Calibration mode to default setting (single ended). */
/* - Disable ADC internal voltage regulator. */
/* - Enable ADC deep power down. */
/* Note: ADC internal voltage regulator disable and ADC deep power */
/* down enable are conditioned to ADC state disabled: */
/* already done above. */
CLEAR_BIT(ADCx->CR, ADC_CR_ADVREGEN | ADC_CR_ADCALDIF);
SET_BIT(ADCx->CR, ADC_CR_DEEPPWD);
/* Reset register CFGR */
MODIFY_REG(ADCx->CFGR,
( ADC_CFGR_AWD1CH | ADC_CFGR_JAUTO | ADC_CFGR_JAWD1EN
| ADC_CFGR_AWD1EN | ADC_CFGR_AWD1SGL | ADC_CFGR_JQM
| ADC_CFGR_JDISCEN | ADC_CFGR_DISCNUM | ADC_CFGR_DISCEN
| ADC_CFGR_AUTDLY | ADC_CFGR_CONT | ADC_CFGR_OVRMOD
| ADC_CFGR_EXTEN | ADC_CFGR_EXTSEL | ADC_CFGR_ALIGN
| ADC_CFGR_RES | ADC_CFGR_DMACFG | ADC_CFGR_DMAEN ),
ADC_CFGR_JQDIS
);
/* Reset register CFGR2 */
CLEAR_BIT(ADCx->CFGR2,
( ADC_CFGR2_ROVSM | ADC_CFGR2_TROVS | ADC_CFGR2_OVSS
| ADC_CFGR2_OVSR | ADC_CFGR2_JOVSE | ADC_CFGR2_ROVSE)
);
/* Reset register SMPR1 */
CLEAR_BIT(ADCx->SMPR1,
( ADC_SMPR1_SMP9 | ADC_SMPR1_SMP8 | ADC_SMPR1_SMP7
| ADC_SMPR1_SMP6 | ADC_SMPR1_SMP5 | ADC_SMPR1_SMP4
| ADC_SMPR1_SMP3 | ADC_SMPR1_SMP2 | ADC_SMPR1_SMP1)
);
/* Reset register SMPR2 */
CLEAR_BIT(ADCx->SMPR2,
( ADC_SMPR2_SMP18 | ADC_SMPR2_SMP17 | ADC_SMPR2_SMP16
| ADC_SMPR2_SMP15 | ADC_SMPR2_SMP14 | ADC_SMPR2_SMP13
| ADC_SMPR2_SMP12 | ADC_SMPR2_SMP11 | ADC_SMPR2_SMP10)
);
/* Reset register TR1 */
MODIFY_REG(ADCx->TR1, ADC_TR1_HT1 | ADC_TR1_LT1, ADC_TR1_HT1);
/* Reset register TR2 */
MODIFY_REG(ADCx->TR2, ADC_TR2_HT2 | ADC_TR2_LT2, ADC_TR2_HT2);
/* Reset register TR3 */
MODIFY_REG(ADCx->TR3, ADC_TR3_HT3 | ADC_TR3_LT3, ADC_TR3_HT3);
/* Reset register SQR1 */
CLEAR_BIT(ADCx->SQR1,
( ADC_SQR1_SQ4 | ADC_SQR1_SQ3 | ADC_SQR1_SQ2
| ADC_SQR1_SQ1 | ADC_SQR1_L)
);
/* Reset register SQR2 */
CLEAR_BIT(ADCx->SQR2,
( ADC_SQR2_SQ9 | ADC_SQR2_SQ8 | ADC_SQR2_SQ7
| ADC_SQR2_SQ6 | ADC_SQR2_SQ5)
);
/* Reset register SQR3 */
CLEAR_BIT(ADCx->SQR3,
( ADC_SQR3_SQ14 | ADC_SQR3_SQ13 | ADC_SQR3_SQ12
| ADC_SQR3_SQ11 | ADC_SQR3_SQ10)
);
/* Reset register SQR4 */
CLEAR_BIT(ADCx->SQR4, ADC_SQR4_SQ16 | ADC_SQR4_SQ15);
/* Reset register JSQR */
CLEAR_BIT(ADCx->JSQR,
( ADC_JSQR_JL
| ADC_JSQR_JEXTSEL | ADC_JSQR_JEXTEN
| ADC_JSQR_JSQ4 | ADC_JSQR_JSQ3
| ADC_JSQR_JSQ2 | ADC_JSQR_JSQ1 )
);
/* Reset register DR */
/* Note: bits in access mode read only, no direct reset applicable */
/* Reset register OFR1 */
CLEAR_BIT(ADCx->OFR1, ADC_OFR1_OFFSET1_EN | ADC_OFR1_OFFSET1_CH | ADC_OFR1_OFFSET1);
/* Reset register OFR2 */
CLEAR_BIT(ADCx->OFR2, ADC_OFR2_OFFSET2_EN | ADC_OFR2_OFFSET2_CH | ADC_OFR2_OFFSET2);
/* Reset register OFR3 */
CLEAR_BIT(ADCx->OFR3, ADC_OFR3_OFFSET3_EN | ADC_OFR3_OFFSET3_CH | ADC_OFR3_OFFSET3);
/* Reset register OFR4 */
CLEAR_BIT(ADCx->OFR4, ADC_OFR4_OFFSET4_EN | ADC_OFR4_OFFSET4_CH | ADC_OFR4_OFFSET4);
/* Reset registers JDR1, JDR2, JDR3, JDR4 */
/* Note: bits in access mode read only, no direct reset applicable */
/* Reset register AWD2CR */
CLEAR_BIT(ADCx->AWD2CR, ADC_AWD2CR_AWD2CH);
/* Reset register AWD3CR */
CLEAR_BIT(ADCx->AWD3CR, ADC_AWD3CR_AWD3CH);
/* Reset register DIFSEL */
CLEAR_BIT(ADCx->DIFSEL, ADC_DIFSEL_DIFSEL);
/* Reset register CALFACT */
CLEAR_BIT(ADCx->CALFACT, ADC_CALFACT_CALFACT_D | ADC_CALFACT_CALFACT_S);
}
else
{
/* ADC instance is in an unknown state */
/* Need to performing a hard reset of ADC instance, using high level */
/* clock source RCC ADC reset. */
/* Caution: On this STM32 serie, if several ADC instances are available */
/* on the selected device, RCC ADC reset will reset */
/* all ADC instances belonging to the common ADC instance. */
/* Caution: On this STM32 serie, if several ADC instances are available */
/* on the selected device, RCC ADC reset will reset */
/* all ADC instances belonging to the common ADC instance. */
status = ERROR;
}
return status;
}
/**
* @brief Initialize some features of ADC instance.
* @note These parameters have an impact on ADC scope: ADC instance.
* Affects both group regular and group injected (availability
* of ADC group injected depends on STM32 families).
* Refer to corresponding unitary functions into
* @ref ADC_LL_EF_Configuration_ADC_Instance .
* @note The setting of these parameters by function @ref LL_ADC_Init()
* is conditioned to ADC state:
* ADC instance must be disabled.
* This condition is applied to all ADC features, for efficiency
* and compatibility over all STM32 families. However, the different
* features can be set under different ADC state conditions
* (setting possible with ADC enabled without conversion on going,
* ADC enabled with conversion on going, ...)
* Each feature can be updated afterwards with a unitary function
* and potentially with ADC in a different state than disabled,
* refer to description of each function for setting
* conditioned to ADC state.
* @note After using this function, some other features must be configured
* using LL unitary functions.
* The minimum configuration remaining to be done is:
* - Set ADC group regular or group injected sequencer:
* map channel on the selected sequencer rank.
* Refer to function @ref LL_ADC_REG_SetSequencerRanks().
* - Set ADC channel sampling time
* Refer to function LL_ADC_SetChannelSamplingTime();
* @param ADCx ADC instance
* @param ADC_InitStruct Pointer to a @ref LL_ADC_REG_InitTypeDef structure
* @retval An ErrorStatus enumeration value:
* - SUCCESS: ADC registers are initialized
* - ERROR: ADC registers are not initialized
*/
ErrorStatus LL_ADC_Init(ADC_TypeDef *ADCx, LL_ADC_InitTypeDef *ADC_InitStruct)
{
ErrorStatus status = SUCCESS;
/* Check the parameters */
assert_param(IS_ADC_ALL_INSTANCE(ADCx));
assert_param(IS_LL_ADC_RESOLUTION(ADC_InitStruct->Resolution));
assert_param(IS_LL_ADC_DATA_ALIGN(ADC_InitStruct->DataAlignment));
assert_param(IS_LL_ADC_LOW_POWER(ADC_InitStruct->LowPowerMode));
/* Note: Hardware constraint (refer to description of this function): */
/* ADC instance must be disabled. */
if(LL_ADC_IsEnabled(ADCx) == 0U)
{
/* Configuration of ADC hierarchical scope: */
/* - ADC instance */
/* - Set ADC data resolution */
/* - Set ADC conversion data alignment */
/* - Set ADC low power mode */
MODIFY_REG(ADCx->CFGR,
ADC_CFGR_RES
| ADC_CFGR_ALIGN
| ADC_CFGR_AUTDLY
,
ADC_InitStruct->Resolution
| ADC_InitStruct->DataAlignment
| ADC_InitStruct->LowPowerMode
);
}
else
{
/* Initialization error: ADC instance is not disabled. */
status = ERROR;
}
return status;
}
/**
* @brief Set each @ref LL_ADC_InitTypeDef field to default value.
* @param ADC_InitStruct Pointer to a @ref LL_ADC_InitTypeDef structure
* whose fields will be set to default values.
* @retval None
*/
void LL_ADC_StructInit(LL_ADC_InitTypeDef *ADC_InitStruct)
{
/* Set ADC_InitStruct fields to default values */
/* Set fields of ADC instance */
ADC_InitStruct->Resolution = LL_ADC_RESOLUTION_12B;
ADC_InitStruct->DataAlignment = LL_ADC_DATA_ALIGN_RIGHT;
ADC_InitStruct->LowPowerMode = LL_ADC_LP_MODE_NONE;
}
/**
* @brief Initialize some features of ADC group regular.
* @note These parameters have an impact on ADC scope: ADC group regular.
* Refer to corresponding unitary functions into
* @ref ADC_LL_EF_Configuration_ADC_Group_Regular
* (functions with prefix "REG").
* @note The setting of these parameters by function @ref LL_ADC_Init()
* is conditioned to ADC state:
* ADC instance must be disabled.
* This condition is applied to all ADC features, for efficiency
* and compatibility over all STM32 families. However, the different
* features can be set under different ADC state conditions
* (setting possible with ADC enabled without conversion on going,
* ADC enabled with conversion on going, ...)
* Each feature can be updated afterwards with a unitary function
* and potentially with ADC in a different state than disabled,
* refer to description of each function for setting
* conditioned to ADC state.
* @note After using this function, other features must be configured
* using LL unitary functions.
* The minimum configuration remaining to be done is:
* - Set ADC group regular or group injected sequencer:
* map channel on the selected sequencer rank.
* Refer to function @ref LL_ADC_REG_SetSequencerRanks().
* - Set ADC channel sampling time
* Refer to function LL_ADC_SetChannelSamplingTime();
* @param ADCx ADC instance
* @param ADC_REG_InitStruct Pointer to a @ref LL_ADC_REG_InitTypeDef structure
* @retval An ErrorStatus enumeration value:
* - SUCCESS: ADC registers are initialized
* - ERROR: ADC registers are not initialized
*/
ErrorStatus LL_ADC_REG_Init(ADC_TypeDef *ADCx, LL_ADC_REG_InitTypeDef *ADC_REG_InitStruct)
{
ErrorStatus status = SUCCESS;
/* Check the parameters */
assert_param(IS_ADC_ALL_INSTANCE(ADCx));
assert_param(IS_LL_ADC_REG_TRIG_SOURCE(ADC_REG_InitStruct->TriggerSource));
assert_param(IS_LL_ADC_REG_SEQ_SCAN_LENGTH(ADC_REG_InitStruct->SequencerLength));
if(ADC_REG_InitStruct->SequencerLength != LL_ADC_REG_SEQ_SCAN_DISABLE)
{
assert_param(IS_LL_ADC_REG_SEQ_SCAN_DISCONT_MODE(ADC_REG_InitStruct->SequencerDiscont));
}
assert_param(IS_LL_ADC_REG_CONTINUOUS_MODE(ADC_REG_InitStruct->ContinuousMode));
assert_param(IS_LL_ADC_REG_DMA_TRANSFER(ADC_REG_InitStruct->DMATransfer));
assert_param(IS_LL_ADC_REG_OVR_DATA_BEHAVIOR(ADC_REG_InitStruct->Overrun));
/* Note: Hardware constraint (refer to description of this function): */
/* ADC instance must be disabled. */
if(LL_ADC_IsEnabled(ADCx) == 0U)
{
/* Configuration of ADC hierarchical scope: */
/* - ADC group regular */
/* - Set ADC group regular trigger source */
/* - Set ADC group regular sequencer length */
/* - Set ADC group regular sequencer discontinuous mode */
/* - Set ADC group regular continuous mode */
/* - Set ADC group regular conversion data transfer: no transfer or */
/* transfer by DMA, and DMA requests mode */
/* - Set ADC group regular overrun behavior */
/* Note: On this STM32 serie, ADC trigger edge is set to value 0x0 by */
/* setting of trigger source to SW start. */
if(ADC_REG_InitStruct->SequencerLength != LL_ADC_REG_SEQ_SCAN_DISABLE)
{
MODIFY_REG(ADCx->CFGR,
ADC_CFGR_EXTSEL
| ADC_CFGR_EXTEN
| ADC_CFGR_DISCEN
| ADC_CFGR_DISCNUM
| ADC_CFGR_CONT
| ADC_CFGR_DMAEN
| ADC_CFGR_DMACFG
| ADC_CFGR_OVRMOD
,
ADC_REG_InitStruct->TriggerSource
| ADC_REG_InitStruct->SequencerDiscont
| ADC_REG_InitStruct->ContinuousMode
| ADC_REG_InitStruct->DMATransfer
| ADC_REG_InitStruct->Overrun
);
}
else
{
MODIFY_REG(ADCx->CFGR,
ADC_CFGR_EXTSEL
| ADC_CFGR_EXTEN
| ADC_CFGR_DISCEN
| ADC_CFGR_DISCNUM
| ADC_CFGR_CONT
| ADC_CFGR_DMAEN
| ADC_CFGR_DMACFG
| ADC_CFGR_OVRMOD
,
ADC_REG_InitStruct->TriggerSource
| LL_ADC_REG_SEQ_DISCONT_DISABLE
| ADC_REG_InitStruct->ContinuousMode
| ADC_REG_InitStruct->DMATransfer
| ADC_REG_InitStruct->Overrun
);
}
/* Set ADC group regular sequencer length and scan direction */
LL_ADC_REG_SetSequencerLength(ADCx, ADC_REG_InitStruct->SequencerLength);
}
else
{
/* Initialization error: ADC instance is not disabled. */
status = ERROR;
}
return status;
}
/**
* @brief Set each @ref LL_ADC_REG_InitTypeDef field to default value.
* @param ADC_REG_InitStruct Pointer to a @ref LL_ADC_REG_InitTypeDef structure
* whose fields will be set to default values.
* @retval None
*/
void LL_ADC_REG_StructInit(LL_ADC_REG_InitTypeDef *ADC_REG_InitStruct)
{
/* Set ADC_REG_InitStruct fields to default values */
/* Set fields of ADC group regular */
/* Note: On this STM32 serie, ADC trigger edge is set to value 0x0 by */
/* setting of trigger source to SW start. */
ADC_REG_InitStruct->TriggerSource = LL_ADC_REG_TRIG_SOFTWARE;
ADC_REG_InitStruct->SequencerLength = LL_ADC_REG_SEQ_SCAN_DISABLE;
ADC_REG_InitStruct->SequencerDiscont = LL_ADC_REG_SEQ_DISCONT_DISABLE;
ADC_REG_InitStruct->ContinuousMode = LL_ADC_REG_CONV_SINGLE;
ADC_REG_InitStruct->DMATransfer = LL_ADC_REG_DMA_TRANSFER_NONE;
ADC_REG_InitStruct->Overrun = LL_ADC_REG_OVR_DATA_OVERWRITTEN;
}
/**
* @brief Initialize some features of ADC group injected.
* @note These parameters have an impact on ADC scope: ADC group injected.
* Refer to corresponding unitary functions into
* @ref ADC_LL_EF_Configuration_ADC_Group_Regular
* (functions with prefix "INJ").
* @note The setting of these parameters by function @ref LL_ADC_Init()
* is conditioned to ADC state:
* ADC instance must be disabled.
* This condition is applied to all ADC features, for efficiency
* and compatibility over all STM32 families. However, the different
* features can be set under different ADC state conditions
* (setting possible with ADC enabled without conversion on going,
* ADC enabled with conversion on going, ...)
* Each feature can be updated afterwards with a unitary function
* and potentially with ADC in a different state than disabled,
* refer to description of each function for setting
* conditioned to ADC state.
* @note After using this function, other features must be configured
* using LL unitary functions.
* The minimum configuration remaining to be done is:
* - Set ADC group injected sequencer:
* map channel on the selected sequencer rank.
* Refer to function @ref LL_ADC_INJ_SetSequencerRanks().
* - Set ADC channel sampling time
* Refer to function LL_ADC_SetChannelSamplingTime();
* @param ADCx ADC instance
* @param ADC_INJ_InitStruct Pointer to a @ref LL_ADC_INJ_InitTypeDef structure
* @retval An ErrorStatus enumeration value:
* - SUCCESS: ADC registers are initialized
* - ERROR: ADC registers are not initialized
*/
ErrorStatus LL_ADC_INJ_Init(ADC_TypeDef *ADCx, LL_ADC_INJ_InitTypeDef *ADC_INJ_InitStruct)
{
ErrorStatus status = SUCCESS;
/* Check the parameters */
assert_param(IS_ADC_ALL_INSTANCE(ADCx));
assert_param(IS_LL_ADC_INJ_TRIG_SOURCE(ADC_INJ_InitStruct->TriggerSource));
assert_param(IS_LL_ADC_INJ_SEQ_SCAN_LENGTH(ADC_INJ_InitStruct->SequencerLength));
if(ADC_INJ_InitStruct->SequencerLength != LL_ADC_INJ_SEQ_SCAN_DISABLE)
{
assert_param(IS_LL_ADC_INJ_SEQ_SCAN_DISCONT_MODE(ADC_INJ_InitStruct->SequencerDiscont));
}
assert_param(IS_LL_ADC_INJ_TRIG_AUTO(ADC_INJ_InitStruct->TrigAuto));
/* Note: Hardware constraint (refer to description of this function): */
/* ADC instance must be disabled. */
if(LL_ADC_IsEnabled(ADCx) == 0U)
{
/* Configuration of ADC hierarchical scope: */
/* - ADC group injected */
/* - Set ADC group injected trigger source */
/* - Set ADC group injected sequencer length */
/* - Set ADC group injected sequencer discontinuous mode */
/* - Set ADC group injected conversion trigger: independent or */
/* from ADC group regular */
/* Note: On this STM32 serie, ADC trigger edge is set to value 0x0 by */
/* setting of trigger source to SW start. */
if(ADC_INJ_InitStruct->SequencerLength != LL_ADC_REG_SEQ_SCAN_DISABLE)
{
MODIFY_REG(ADCx->CFGR,
ADC_CFGR_JDISCEN
| ADC_CFGR_JAUTO
,
ADC_INJ_InitStruct->SequencerDiscont
| ADC_INJ_InitStruct->TrigAuto
);
}
else
{
MODIFY_REG(ADCx->CFGR,
ADC_CFGR_JDISCEN
| ADC_CFGR_JAUTO
,
LL_ADC_REG_SEQ_DISCONT_DISABLE
| ADC_INJ_InitStruct->TrigAuto
);
}
MODIFY_REG(ADCx->JSQR,
ADC_JSQR_JEXTSEL
| ADC_JSQR_JEXTEN
| ADC_JSQR_JL
,
ADC_INJ_InitStruct->TriggerSource
| ADC_INJ_InitStruct->SequencerLength
);
}
else
{
/* Initialization error: ADC instance is not disabled. */
status = ERROR;
}
return status;
}
/**
* @brief Set each @ref LL_ADC_INJ_InitTypeDef field to default value.
* @param ADC_INJ_InitStruct Pointer to a @ref LL_ADC_INJ_InitTypeDef structure
* whose fields will be set to default values.
* @retval None
*/
void LL_ADC_INJ_StructInit(LL_ADC_INJ_InitTypeDef *ADC_INJ_InitStruct)
{
/* Set ADC_INJ_InitStruct fields to default values */
/* Set fields of ADC group injected */
ADC_INJ_InitStruct->TriggerSource = LL_ADC_INJ_TRIG_SOFTWARE;
ADC_INJ_InitStruct->SequencerLength = LL_ADC_INJ_SEQ_SCAN_DISABLE;
ADC_INJ_InitStruct->SequencerDiscont = LL_ADC_INJ_SEQ_DISCONT_DISABLE;
ADC_INJ_InitStruct->TrigAuto = LL_ADC_INJ_TRIG_INDEPENDENT;
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#endif /* ADC1 || ADC2 || ADC3 */
/**
* @}
*/
#endif /* USE_FULL_LL_DRIVER */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
the_stack_data/678282.c
|
/* bio_pk7.c */
/*
* Written by Dr Stephen N Henson ([email protected]) for the OpenSSL
* project.
*/
/* ====================================================================
* Copyright (c) 2008 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
*
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* [email protected].
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
* permission of the OpenSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED 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 OpenSSL PROJECT OR
* ITS 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 <openssl/asn1.h>
#include <openssl/pkcs7.h>
#include <openssl/bio.h>
#ifndef OPENSSL_SYSNAME_NETWARE
# include <memory.h>
#endif
#include <stdio.h>
/* Streaming encode support for PKCS#7 */
BIO *BIO_new_PKCS7(BIO *out, PKCS7 *p7)
{
return BIO_new_NDEF(out, (ASN1_VALUE *)p7, ASN1_ITEM_rptr(PKCS7));
}
|
the_stack_data/215769201.c
|
// RUN: %clang_cc1 -fsyntax-only -verify %s -Wunused-function
/// We allow 'retain' on non-ELF targets because 'retain' is often used together
/// with 'used'. 'used' has GC root semantics on macOS and Windows. We want
/// users to just write retain,used and don't need to dispatch on binary formats.
extern char test1[] __attribute__((retain)); // expected-warning {{'retain' attribute ignored on a non-definition declaration}}
extern const char test2[] __attribute__((retain)); // expected-warning {{'retain' attribute ignored on a non-definition declaration}}
const char test3[] __attribute__((retain)) = "";
struct __attribute__((retain)) s { // expected-warning {{'retain' attribute only applies to variables with non-local storage, functions, and Objective-C methods}}
};
void foo(void) {
static int a __attribute__((retain));
int b __attribute__((retain)); // expected-warning {{'retain' attribute only applies to variables with non-local storage, functions, and Objective-C methods}}
(void)a;
(void)b;
}
__attribute__((retain,used)) static void f0(void) {}
__attribute__((retain)) static void f1(void) {} // expected-warning {{unused function 'f1'}}
__attribute__((retain)) void f2(void) {}
/// Test attribute merging.
int tentative;
int tentative __attribute__((retain));
extern int tentative;
int tentative = 0;
|
the_stack_data/89200562.c
|
#include <stdio.h>
#include <string.h>
#include <limits.h>
/*
* CBA printf 20151112
* Author: Domen Puncer Kugler <[email protected]>
* License: WTFPL, see file LICENSE
*/
#define ALEN(x) (sizeof(x)/sizeof(x[0]))
struct test_result {
const char *result;
size_t len;
};
static const struct test_result sresults[] = {
{ "(null)", 6 }, { "(null", 6 },
{ "a long string", 13 }, { "a lon", 13 },
{ "", 0 }, { "", 0 },
{ "test", 4 }, { "test", 4 },
{ " (null)", 10 }, { " (", 10 },
{ "a long string", 13 }, { "a lon", 13 },
{ " ", 10 }, { " ", 10 },
{ " test", 10 }, { " ", 10 },
{ "(null)", 6 }, { "(null", 6 },
{ "a long s", 8 }, { "a lon", 8 },
{ "", 0 }, { "", 0 },
{ "test", 4 }, { "test", 4 },
{ "(null) ", 8 }, { "(null", 8 },
{ "a long string", 13 }, { "a lon", 13 },
{ " ", 8 }, { " ", 8 },
{ "test ", 8 }, { "test ", 8 },
{ "", 0 }, { "", 0 },
{ "", 0 }, { "", 0 },
{ "", 0 }, { "", 0 },
{ "", 0 }, { "", 0 },
{ "", 0 }, { "", 0 },
{ "", 0 }, { "", 0 },
{ "", 0 }, { "", 0 },
{ "", 0 }, { "", 0 },
};
static const struct test_result iresults[] = {
{ "0", 1 }, { "0", 1 },
{ "-1", 2 }, { "-1", 2 },
{ "1", 1 }, { "1", 1 },
{ "2147483647", 10 }, { "21474", 10 },
{ "-2147483648", 11 }, { "-2147", 11 },
{ "-1", 2 }, { "-1", 2 },
{ "127", 3 }, { "127", 3 },
{ "-128", 4 }, { "-128", 4 },
{ "255", 3 }, { "255", 3 },
{ "0", 1 }, { "0", 1 },
{ "-1", 2 }, { "-1", 2 },
{ "1", 1 }, { "1", 1 },
{ "2147483647", 10 }, { "21474", 10 },
{ "-2147483648", 11 }, { "-2147", 11 },
{ "-1", 2 }, { "-1", 2 },
{ "127", 3 }, { "127", 3 },
{ "-128", 4 }, { "-128", 4 },
{ "255", 3 }, { "255", 3 },
{ "0", 1 }, { "0", 1 },
{ "4294967295", 10 }, { "42949", 10 },
{ "1", 1 }, { "1", 1 },
{ "2147483647", 10 }, { "21474", 10 },
{ "2147483648", 10 }, { "21474", 10 },
{ "4294967295", 10 }, { "42949", 10 },
{ "127", 3 }, { "127", 3 },
{ "4294967168", 10 }, { "42949", 10 },
{ "255", 3 }, { "255", 3 },
{ "0", 1 }, { "0", 1 },
{ "37777777777", 11 }, { "37777", 11 },
{ "1", 1 }, { "1", 1 },
{ "17777777777", 11 }, { "17777", 11 },
{ "20000000000", 11 }, { "20000", 11 },
{ "37777777777", 11 }, { "37777", 11 },
{ "177", 3 }, { "177", 3 },
{ "37777777600", 11 }, { "37777", 11 },
{ "377", 3 }, { "377", 3 },
{ "0", 1 }, { "0", 1 },
{ "ffffffff", 8 }, { "fffff", 8 },
{ "1", 1 }, { "1", 1 },
{ "7fffffff", 8 }, { "7ffff", 8 },
{ "80000000", 8 }, { "80000", 8 },
{ "ffffffff", 8 }, { "fffff", 8 },
{ "7f", 2 }, { "7f", 2 },
{ "ffffff80", 8 }, { "fffff", 8 },
{ "ff", 2 }, { "ff", 2 },
{ "0", 1 }, { "0", 1 },
{ "FFFFFFFF", 8 }, { "FFFFF", 8 },
{ "1", 1 }, { "1", 1 },
{ "7FFFFFFF", 8 }, { "7FFFF", 8 },
{ "80000000", 8 }, { "80000", 8 },
{ "FFFFFFFF", 8 }, { "FFFFF", 8 },
{ "7F", 2 }, { "7F", 2 },
{ "FFFFFF80", 8 }, { "FFFFF", 8 },
{ "FF", 2 }, { "FF", 2 },
{ " 0", 3 }, { " 0", 3 },
{ " -1", 3 }, { " -1", 3 },
{ " 1", 3 }, { " 1", 3 },
{ "2147483647", 10 }, { "21474", 10 },
{ "-2147483648", 11 }, { "-2147", 11 },
{ " -1", 3 }, { " -1", 3 },
{ "127", 3 }, { "127", 3 },
{ "-128", 4 }, { "-128", 4 },
{ "255", 3 }, { "255", 3 },
{ " 0", 5 }, { " 0", 5 },
{ " -1", 5 }, { " -1", 5 },
{ " 1", 5 }, { " 1", 5 },
{ "2147483647", 10 }, { "21474", 10 },
{ "-2147483648", 11 }, { "-2147", 11 },
{ " -1", 5 }, { " -1", 5 },
{ " 127", 5 }, { " 127", 5 },
{ " -128", 5 }, { " -128", 5 },
{ " 255", 5 }, { " 255", 5 },
{ " 0", 12 }, { " ", 12 },
{ " 4294967295", 12 }, { " 429", 12 },
{ " 1", 12 }, { " ", 12 },
{ " 2147483647", 12 }, { " 214", 12 },
{ " 2147483648", 12 }, { " 214", 12 },
{ " 4294967295", 12 }, { " 429", 12 },
{ " 127", 12 }, { " ", 12 },
{ " 4294967168", 12 }, { " 429", 12 },
{ " 255", 12 }, { " ", 12 },
{ "0", 1 }, { "0", 1 },
{ "37777777777", 11 }, { "37777", 11 },
{ "1", 1 }, { "1", 1 },
{ "17777777777", 11 }, { "17777", 11 },
{ "20000000000", 11 }, { "20000", 11 },
{ "37777777777", 11 }, { "37777", 11 },
{ "177", 3 }, { "177", 3 },
{ "37777777600", 11 }, { "37777", 11 },
{ "377", 3 }, { "377", 3 },
{ " 0", 4 }, { " 0", 4 },
{ "ffffffff", 8 }, { "fffff", 8 },
{ " 1", 4 }, { " 1", 4 },
{ "7fffffff", 8 }, { "7ffff", 8 },
{ "80000000", 8 }, { "80000", 8 },
{ "ffffffff", 8 }, { "fffff", 8 },
{ " 7f", 4 }, { " 7f", 4 },
{ "ffffff80", 8 }, { "fffff", 8 },
{ " ff", 4 }, { " ff", 4 },
{ " 0", 5 }, { " 0", 5 },
{ "FFFFFFFF", 8 }, { "FFFFF", 8 },
{ " 1", 5 }, { " 1", 5 },
{ "7FFFFFFF", 8 }, { "7FFFF", 8 },
{ "80000000", 8 }, { "80000", 8 },
{ "FFFFFFFF", 8 }, { "FFFFF", 8 },
{ " 7F", 5 }, { " 7F", 5 },
{ "FFFFFF80", 8 }, { "FFFFF", 8 },
{ " FF", 5 }, { " FF", 5 },
{ "000", 3 }, { "000", 3 },
{ "-01", 3 }, { "-01", 3 },
{ "001", 3 }, { "001", 3 },
{ "2147483647", 10 }, { "21474", 10 },
{ "-2147483648", 11 }, { "-2147", 11 },
{ "-01", 3 }, { "-01", 3 },
{ "127", 3 }, { "127", 3 },
{ "-128", 4 }, { "-128", 4 },
{ "255", 3 }, { "255", 3 },
{ "00000", 5 }, { "00000", 5 },
{ "-0001", 5 }, { "-0001", 5 },
{ "00001", 5 }, { "00001", 5 },
{ "2147483647", 10 }, { "21474", 10 },
{ "-2147483648", 11 }, { "-2147", 11 },
{ "-0001", 5 }, { "-0001", 5 },
{ "00127", 5 }, { "00127", 5 },
{ "-0128", 5 }, { "-0128", 5 },
{ "00255", 5 }, { "00255", 5 },
{ "000000000000", 12 }, { "00000", 12 },
{ "004294967295", 12 }, { "00429", 12 },
{ "000000000001", 12 }, { "00000", 12 },
{ "002147483647", 12 }, { "00214", 12 },
{ "002147483648", 12 }, { "00214", 12 },
{ "004294967295", 12 }, { "00429", 12 },
{ "000000000127", 12 }, { "00000", 12 },
{ "004294967168", 12 }, { "00429", 12 },
{ "000000000255", 12 }, { "00000", 12 },
{ "0", 1 }, { "0", 1 },
{ "37777777777", 11 }, { "37777", 11 },
{ "1", 1 }, { "1", 1 },
{ "17777777777", 11 }, { "17777", 11 },
{ "20000000000", 11 }, { "20000", 11 },
{ "37777777777", 11 }, { "37777", 11 },
{ "177", 3 }, { "177", 3 },
{ "37777777600", 11 }, { "37777", 11 },
{ "377", 3 }, { "377", 3 },
{ "0000", 4 }, { "0000", 4 },
{ "ffffffff", 8 }, { "fffff", 8 },
{ "0001", 4 }, { "0001", 4 },
{ "7fffffff", 8 }, { "7ffff", 8 },
{ "80000000", 8 }, { "80000", 8 },
{ "ffffffff", 8 }, { "fffff", 8 },
{ "007f", 4 }, { "007f", 4 },
{ "ffffff80", 8 }, { "fffff", 8 },
{ "00ff", 4 }, { "00ff", 4 },
{ "00000", 5 }, { "00000", 5 },
{ "FFFFFFFF", 8 }, { "FFFFF", 8 },
{ "00001", 5 }, { "00001", 5 },
{ "7FFFFFFF", 8 }, { "7FFFF", 8 },
{ "80000000", 8 }, { "80000", 8 },
{ "FFFFFFFF", 8 }, { "FFFFF", 8 },
{ "0007F", 5 }, { "0007F", 5 },
{ "FFFFFF80", 8 }, { "FFFFF", 8 },
{ "000FF", 5 }, { "000FF", 5 },
{ "00000", 5 }, { "00000", 5 },
{ "037777777777", 12 }, { "03777", 12 },
{ "00001", 5 }, { "00001", 5 },
{ "017777777777", 12 }, { "01777", 12 },
{ "020000000000", 12 }, { "02000", 12 },
{ "037777777777", 12 }, { "03777", 12 },
{ "00177", 5 }, { "00177", 5 },
{ "037777777600", 12 }, { "03777", 12 },
{ "00377", 5 }, { "00377", 5 },
{ "00000000", 8 }, { "00000", 8 },
{ "0xffffffff", 10 }, { "0xfff", 10 },
{ "0x000001", 8 }, { "0x000", 8 },
{ "0x7fffffff", 10 }, { "0x7ff", 10 },
{ "0x80000000", 10 }, { "0x800", 10 },
{ "0xffffffff", 10 }, { "0xfff", 10 },
{ "0x00007f", 8 }, { "0x000", 8 },
{ "0xffffff80", 10 }, { "0xfff", 10 },
{ "0x0000ff", 8 }, { "0x000", 8 },
{ "000000000", 9 }, { "00000", 9 },
{ "0XFFFFFFFF", 10 }, { "0XFFF", 10 },
{ "0X0000001", 9 }, { "0X000", 9 },
{ "0X7FFFFFFF", 10 }, { "0X7FF", 10 },
{ "0X80000000", 10 }, { "0X800", 10 },
{ "0XFFFFFFFF", 10 }, { "0XFFF", 10 },
{ "0X000007F", 9 }, { "0X000", 9 },
{ "0XFFFFFF80", 10 }, { "0XFFF", 10 },
{ "0X00000FF", 9 }, { "0X000", 9 },
{ " 0", 5 }, { " 0", 5 },
{ "037777777777", 12 }, { "03777", 12 },
{ " 01", 5 }, { " 01", 5 },
{ "017777777777", 12 }, { "01777", 12 },
{ "020000000000", 12 }, { "02000", 12 },
{ "037777777777", 12 }, { "03777", 12 },
{ " 0177", 5 }, { " 0177", 5 },
{ "037777777600", 12 }, { "03777", 12 },
{ " 0377", 5 }, { " 0377", 5 },
{ " 0", 8 }, { " ", 8 },
{ "0xffffffff", 10 }, { "0xfff", 10 },
{ " 0x1", 8 }, { " ", 8 },
{ "0x7fffffff", 10 }, { "0x7ff", 10 },
{ "0x80000000", 10 }, { "0x800", 10 },
{ "0xffffffff", 10 }, { "0xfff", 10 },
{ " 0x7f", 8 }, { " 0", 8 },
{ "0xffffff80", 10 }, { "0xfff", 10 },
{ " 0xff", 8 }, { " 0", 8 },
{ "0", 1 }, { "0", 1 },
{ "0XFFFFFFFF", 10 }, { "0XFFF", 10 },
{ "0X1", 3 }, { "0X1", 3 },
{ "0X7FFFFFFF", 10 }, { "0X7FF", 10 },
{ "0X80000000", 10 }, { "0X800", 10 },
{ "0XFFFFFFFF", 10 }, { "0XFFF", 10 },
{ "0X7F", 4 }, { "0X7F", 4 },
{ "0XFFFFFF80", 10 }, { "0XFFF", 10 },
{ "0XFF", 4 }, { "0XFF", 4 },
{ "0 ", 5 }, { "0 ", 5 },
{ "-1 ", 5 }, { "-1 ", 5 },
{ "1 ", 5 }, { "1 ", 5 },
{ "2147483647", 10 }, { "21474", 10 },
{ "-2147483648", 11 }, { "-2147", 11 },
{ "-1 ", 5 }, { "-1 ", 5 },
{ "127 ", 5 }, { "127 ", 5 },
{ "-128 ", 5 }, { "-128 ", 5 },
{ "255 ", 5 }, { "255 ", 5 },
{ "0 ", 8 }, { "0 ", 8 },
{ "-1 ", 8 }, { "-1 ", 8 },
{ "1 ", 8 }, { "1 ", 8 },
{ "2147483647", 10 }, { "21474", 10 },
{ "-2147483648", 11 }, { "-2147", 11 },
{ "-1 ", 8 }, { "-1 ", 8 },
{ "127 ", 8 }, { "127 ", 8 },
{ "-128 ", 8 }, { "-128 ", 8 },
{ "255 ", 8 }, { "255 ", 8 },
{ "0 ", 8 }, { "0 ", 8 },
{ "0xffffffff", 10 }, { "0xfff", 10 },
{ "0x1 ", 8 }, { "0x1 ", 8 },
{ "0x7fffffff", 10 }, { "0x7ff", 10 },
{ "0x80000000", 10 }, { "0x800", 10 },
{ "0xffffffff", 10 }, { "0xfff", 10 },
{ "0x7f ", 8 }, { "0x7f ", 8 },
{ "0xffffff80", 10 }, { "0xfff", 10 },
{ "0xff ", 8 }, { "0xff ", 8 },
{ "0 ", 8 }, { "0 ", 8 },
{ "037777777777", 12 }, { "03777", 12 },
{ "01 ", 8 }, { "01 ", 8 },
{ "017777777777", 12 }, { "01777", 12 },
{ "020000000000", 12 }, { "02000", 12 },
{ "037777777777", 12 }, { "03777", 12 },
{ "0177 ", 8 }, { "0177 ", 8 },
{ "037777777600", 12 }, { "03777", 12 },
{ "0377 ", 8 }, { "0377 ", 8 },
{ "0", 1 }, { "0", 1 },
{ "FFFFFFFF", 8 }, { "FFFFF", 8 },
{ "1", 1 }, { "1", 1 },
{ "7FFFFFFF", 8 }, { "7FFFF", 8 },
{ "80000000", 8 }, { "80000", 8 },
{ "FFFFFFFF", 8 }, { "FFFFF", 8 },
{ "7F", 2 }, { "7F", 2 },
{ "FFFFFF80", 8 }, { "FFFFF", 8 },
{ "FF", 2 }, { "FF", 2 },
{ " +0", 5 }, { " +0", 5 },
{ " -1", 5 }, { " -1", 5 },
{ " +1", 5 }, { " +1", 5 },
{ "+2147483647", 11 }, { "+2147", 11 },
{ "-2147483648", 11 }, { "-2147", 11 },
{ " -1", 5 }, { " -1", 5 },
{ " +127", 5 }, { " +127", 5 },
{ " -128", 5 }, { " -128", 5 },
{ " +255", 5 }, { " +255", 5 },
{ " 0", 5 }, { " 0", 5 },
{ " -1", 5 }, { " -1", 5 },
{ " 1", 5 }, { " 1", 5 },
{ " 2147483647", 11 }, { " 2147", 11 },
{ "-2147483648", 11 }, { "-2147", 11 },
{ " -1", 5 }, { " -1", 5 },
{ " 127", 5 }, { " 127", 5 },
{ " -128", 5 }, { " -128", 5 },
{ " 255", 5 }, { " 255", 5 },
{ " 0", 2 }, { " 0", 2 },
{ "-1", 2 }, { "-1", 2 },
{ " 1", 2 }, { " 1", 2 },
{ " 2147483647", 11 }, { " 2147", 11 },
{ "-2147483648", 11 }, { "-2147", 11 },
{ "-1", 2 }, { "-1", 2 },
{ " 127", 4 }, { " 127", 4 },
{ "-128", 4 }, { "-128", 4 },
{ " 255", 4 }, { " 255", 4 },
{ "0", 1 }, { "0", 1 },
{ "-1", 2 }, { "-1", 2 },
{ "1", 1 }, { "1", 1 },
{ "-1", 2 }, { "-1", 2 },
{ "0", 1 }, { "0", 1 },
{ "-1", 2 }, { "-1", 2 },
{ "127", 3 }, { "127", 3 },
{ "-128", 4 }, { "-128", 4 },
{ "255", 3 }, { "255", 3 },
{ "0", 1 }, { "0", 1 },
{ "-1", 2 }, { "-1", 2 },
{ "1", 1 }, { "1", 1 },
{ "-1", 2 }, { "-1", 2 },
{ "0", 1 }, { "0", 1 },
{ "-1", 2 }, { "-1", 2 },
{ "127", 3 }, { "127", 3 },
{ "-128", 4 }, { "-128", 4 },
{ "-1", 2 }, { "-1", 2 },
{ "0", 1 }, { "0", 1 },
{ "65535", 5 }, { "65535", 5 },
{ "1", 1 }, { "1", 1 },
{ "65535", 5 }, { "65535", 5 },
{ "0", 1 }, { "0", 1 },
{ "65535", 5 }, { "65535", 5 },
{ "127", 3 }, { "127", 3 },
{ "65408", 5 }, { "65408", 5 },
{ "255", 3 }, { "255", 3 },
{ "0", 1 }, { "0", 1 },
{ "ff", 2 }, { "ff", 2 },
{ "1", 1 }, { "1", 1 },
{ "ff", 2 }, { "ff", 2 },
{ "0", 1 }, { "0", 1 },
{ "ff", 2 }, { "ff", 2 },
{ "7f", 2 }, { "7f", 2 },
{ "80", 2 }, { "80", 2 },
{ "ff", 2 }, { "ff", 2 },
{ "0", 1 }, { "0", 1 },
{ "177777", 6 }, { "17777", 6 },
{ "1", 1 }, { "1", 1 },
{ "177777", 6 }, { "17777", 6 },
{ "0", 1 }, { "0", 1 },
{ "177777", 6 }, { "17777", 6 },
{ "177", 3 }, { "177", 3 },
{ "177600", 6 }, { "17760", 6 },
{ "377", 3 }, { "377", 3 },
};
static const struct test_result cresults[] = {
{ " a", 3 }, { " a", 3 },
{ " ", 3 }, { " ", 3 },
{ " +", 3 }, { " +", 3 },
{ "a", 1 }, { "a", 1 },
{ " ", 1 }, { " ", 1 },
{ "+", 1 }, { "+", 1 },
{ "a ", 3 }, { "a ", 3 },
{ " ", 3 }, { " ", 3 },
{ "+ ", 3 }, { "+ ", 3 },
{ "a", 1 }, { "a", 1 },
{ " ", 1 }, { " ", 1 },
{ "+", 1 }, { "+", 1 },
};
static const long itests[] = { 0, -1, 1, INT_MAX, INT_MIN, UINT_MAX, SCHAR_MAX, SCHAR_MIN, UCHAR_MAX, };
static const char *iformats[] = {
"%i", "%d", "%u", "%o", "%x", "%X",
"%3i", "%5d", "%12u", "%1o", "%4x", "%5X",
"%03i", "%05d", "%012u", "%01o", "%04x", "%05X",
"%#05o", "%#08x", "%#09X", "%#5o", "%#8x", "%#X",
"%-5i", "%-8d", "%#-8x", "%-#8o", "%-1X",
"%+5i", "% 5i", "% i",
"%hi", "%hhi", "%hu", "%hhx", "%ho",
};
static const long stests[] = { (long)NULL, (long)"a long string", (long)"", (long)"test" };
//char *stests[] = { NULL, "a long string", "", "test" };
static const char *sformats[] = { "%s", "%10s", "%.8s", "%-8s", "%.s", "%.0s", };
static const long ctests[] = { (char)'a', (char)' ', (char)'+', };
static const char *cformats[] = { "%3c", "%.3c", "%-3c", "%c", };
struct test {
const char **formats;
size_t nformats;
const long *tests;
size_t ntests;
const struct test_result *results;
};
struct test tests[] = {
{
.formats = sformats, .nformats = ALEN(sformats),
.tests = stests, .ntests = ALEN(stests),
.results = sresults
},
{
.formats = iformats, .nformats = ALEN(iformats),
.tests = itests, .ntests = ALEN(itests),
.results = iresults
},
{
.formats = cformats, .nformats = ALEN(cformats),
.tests = ctests, .ntests = ALEN(ctests),
.results = cresults
},
};
static int printf_tests_quiet = 0;
void printf_run_tests(struct test *tests, int n)
{
int t, i, j;
for (t=0; t<n; t++) {
if (!printf_tests_quiet)
printf("%s %d\n", __func__, t);
const char **formats = tests[t].formats;
size_t nformats = tests[t].nformats;
const long *test = tests[t].tests;
size_t ntest = tests[t].ntests;
const struct test_result *results = tests[t].results;
for (j=0; j<nformats; j++) {
for (i=0; i<ntest; i++) {
#if 0
/* print reference output */
char test1[64];
int l1;
l1 = sprintf(test1, formats[j], test[i]);
printf("\t{ \"%s\", %d }, ", test1, l1);
l1 = snprintf(test1, 6, formats[j], test[i]);
printf("{ \"%s\", %d },\n", test1, l1);
#else
/* actually test */
char test1[64];
int l1;
const char *res = results[(j*ntest + i)*2].result;
int reslen = results[(j*ntest + i)*2].len;
l1 = sprintf(test1, formats[j], test[i]);
if (l1 != reslen || strcmp(test1, res) != 0) {
printf("sprintf fail: %d:%s:%d, \"%s\" != \"%s\"\n",
t, formats[j], i, test1, res);
}
res = results[(j*ntest + i)*2+1].result;
reslen = results[(j*ntest + i)*2+1].len;
l1 = snprintf(test1, 6, formats[j], test[i]);
if (l1 != reslen || strcmp(test1, res) != 0) {
printf("snprintf fail: %d:%s:%d, \"%s\" != \"%s\"\n",
t, formats[j], i, test1, res);
}
#endif
}
}
}
}
//#define printf_tests main
int printf_tests(void)
{
/*
run_tests_l();
run_tests_ll();
*/
printf_run_tests(tests, ALEN(tests));
return 0;
}
#if 0
void run_tests_l()
{
int i, j;
char *formats[] = { "%li", "%lu" };
long tests[] = { LONG_MAX, 0L, LONG_MIN, -1L, };
int nformats = ALEN(formats);
int ntests = ALEN(tests);
if (!printf_tests_quiet)
printf("%s\n", __func__);
for (j=0; j<nformats; j++) {
printf(" test %s: .", formats[j]);
for (i=0; i<ntests; i++)
printf(formats[j], tests[i]), printf(". .");
printf("\n");
_printf("_test %s: .", formats[j]);
for (i=0; i<ntests; i++)
_printf(formats[j], tests[i]), printf(". .");
printf("\n");
}
}
#ifdef ARCH_UNIX
void run_tests_ll()
{
int i, j;
char *formats[] = { "%lli", "%llu" };
long long tests[] = { LLONG_MAX, 0LL, LLONG_MIN, -1LL, };
int nformats = ALEN(formats);
int ntests = ALEN(tests);
if (!printf_tests_quiet)
printf("%s\n", __func__);
for (j=0; j<nformats; j++) {
printf(" test %s: .", formats[j]);
for (i=0; i<ntests; i++)
printf(formats[j], tests[i]), printf(". .");
printf("\n");
_printf("_test %s: .", formats[j]);
for (i=0; i<ntests; i++)
_printf(formats[j], tests[i]), printf(". .");
printf("\n");
}
}
#endif
#endif
|
the_stack_data/34513414.c
|
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
srand(time(NULL));
int mysteriousNumber=0,counter=0,enteredNumber=0,playAgain=0,level;
printf("== Levels ==\n");
printf("1. Easy\n");
printf("2. Intermediate\n");
printf("3. Hard\n");
scanf("%d",&level);
if (level==1)
{
int mysteriousNumber=0,counter=0,enteredNumber=0,playAgain=0,level;
const int MAX=10,MIN=0;
do
{
counter=0;
mysteriousNumber=(rand()%(MAX-MIN+1))+MIN;
while (enteredNumber!=mysteriousNumber)
{
printf("Please enter the mysterious number\n");
scanf("%d",&enteredNumber);
if (enteredNumber>mysteriousNumber)
printf("You've entered a bigger number, please try again \n\n");
else if (enteredNumber<mysteriousNumber)
printf("You've entered a smaller number, please try again \n\n");
else
{
printf("Brave, You've entered the mysterious number after %d times\n",(counter+1));
printf("Do you want to play again?\n");
printf("Press 1 to play again \n");
scanf("%d",&playAgain);
}
counter++;
}
}
while (playAgain==1);
}
else if (level==2)
{
int mysteriousNumber=0,counter=0,enteredNumber=0,playAgain=0,level;
const int MAX=100,MIN=0;
do
{
counter=0;
mysteriousNumber=(rand()%(MAX-MIN+1))+MIN;
while (enteredNumber!=mysteriousNumber)
{
printf("Please enter the mysterious number\n");
scanf("%d",&enteredNumber);
if (enteredNumber>mysteriousNumber)
printf("You've entered a bigger number, please try again \n\n");
else if (enteredNumber<mysteriousNumber)
printf("You've entered a smaller number, please try again \n\n");
else
{
printf("Brave, You've entered the mysterious number after %d times\n",(counter+1));
printf("Do you want to play again?\n");
printf("Press 1 to play again \n");
scanf("%d",&playAgain);
}
counter++;
}
}
while (playAgain==1);
}
else if (level==3)
{
int mysteriousNumber=0,counter=0,enteredNumber=0,playAgain=0,level;
const int MAX=1000,MIN=0;
do
{
counter=0;
mysteriousNumber=(rand()%(MAX-MIN+1))+MIN;
while (enteredNumber!=mysteriousNumber)
{
printf("Please enter the mysterious number\n");
scanf("%d",&enteredNumber);
if (enteredNumber>mysteriousNumber)
printf("You've entered a bigger number, please try again \n\n");
else if (enteredNumber<mysteriousNumber)
printf("You've entered a smaller number, please try again \n\n");
else
{
printf("Brave, You've entered the mysterious number after %d times\n",(counter+1));
printf("Do you want to play again?\n");
printf("Press 1 to play again \n");
scanf("%d",&playAgain);
}
counter++;
}
}
while (playAgain==1);
}
else
printf("Please enter a number from 1:3\n");
}
|
the_stack_data/15729.c
|
/*
Summary: Compares two string for equality
*/
#include <stdio.h>
#include <string.h>
int main()
{
char a[100], b[100];
printf("Enter the first string\n");
gets(a);
printf("Enter the second string\n");
gets(b);
if( strcmp(a,b) == 0 )
printf("Entered strings are equal.\n");
else
printf("Entered strings are not equal.\n");
getch();
return 0;
}
/*
Input: simple
sample
*/
|
the_stack_data/192331776.c
|
#include <stdio.h>
#include <stdlib.h>
int main()
{
char pName[] = "Weerasuriya";
int pAge = 25;
printf("Veriable in C \n");
printf("My Name is %s\n", pName);
printf("I am %d years old \n", pAge);
return 0;
}
|
the_stack_data/64199167.c
|
#include <stdio.h>
#include <stdlib.h>
typedef struct _node {
int id;
struct _node *prev, *next;
} node;
int main() {
int n, m, q;
scanf("%d%d%d", &n, &m, &q);
node *p1 = (node *)malloc(sizeof(node)), *p2 = p1;
p1->id = 1;
p1->next = p1;
p1->prev = p1;
for (int i = 2; i <= n; i++) {
node *p = (node *)malloc(sizeof(node));
p->id = i;
p->prev = p1;
p->next = p1->next;
p->prev->next = p;
p->next->prev = p;
p1 = p;
if (i == q) {
p2 = p;
}
}
while (p2->next != p2) {
for (int i = 0; i < m - 1; i++) {
p2 = p2->next;
}
node *p = p2;
p2 = p->next;
p->prev->next = p->next;
p->next->prev = p->prev;
free(p);
}
printf("%d\n", p2->id);
}
|
the_stack_data/342186.c
|
#include<stdio.h>
#include<math.h>
int main()
{
float a,b,c;
scanf("%f%f" ,&a,&b);
c=a+b;
printf("%f\n" ,c);
return 0;
}
|
the_stack_data/82961.c
|
#include <fenv.h>
/* Dummy functions for archs lacking fenv implementation */
int feclearexcept(int mask)
{
return 0;
}
int feraiseexcept(int mask)
{
return 0;
}
int fetestexcept(int mask)
{
return 0;
}
int fegetround(void)
{
return FE_TONEAREST;
}
int __fesetround(int r)
{
return 0;
}
int fegetenv(fenv_t *envp)
{
return 0;
}
int fesetenv(const fenv_t *envp)
{
return 0;
}
|
the_stack_data/162643492.c
|
#include <stdio.h>
int main()
{
int l, j, i, c;
printf("digite a linha: ");
scanf("%d", &l);
printf("digite a coluna: ");
scanf("%d", &c);
int vet[l][c];
for (i=0;i<l;i++) {
printf("digite os valores da %dª linha: \n", i);
for (j=0;j<c;j++) {
scanf("%d", &vet[i][j]);
}
}
printf("vetor gerado: ");
int mat[l];
for (i=0;i<l;i++) {
mat[i] = 0;
for (j=0;j<c;j++) {
mat[i] = mat[i] + vet[i][j];
}
}
for (i=0;i<l;i++) {
printf("%d\n", mat[i]);
}
return 0;
}
|
the_stack_data/92326778.c
|
#include <stdio.h>
static struct sss{
long f;
int snd;
} sss;
#define _offsetof(st,f) ((char *)&((st *) 16)->f - (char *) 16)
int main (void) {
printf ("+++Struct long-int:\n");
printf ("size=%d,align=%d,offset-long=%d,offset-int=%d,\nalign-long=%d,align-int=%d\n",
sizeof (sss), __alignof__ (sss),
_offsetof (struct sss, f), _offsetof (struct sss, snd),
__alignof__ (sss.f), __alignof__ (sss.snd));
return 0;
}
|
the_stack_data/125492.c
|
/*
BLIS
An object-based framework for developing high-performance BLAS-like
libraries.
Copyright (C) 2014, The University of Texas at Austin
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
- Neither the name(s) of the copyright holder(s) nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// Guard the function definitions so that they are only compiled when
// #included from files that define the object API macros.
#ifdef BLIS_ENABLE_OAPI
//
// Define object-based interfaces.
//
#undef GENFRONT
#define GENFRONT( opname ) \
\
void PASTEMAC(opname,EX_SUF) \
( \
obj_t* x, \
obj_t* y \
BLIS_OAPI_EX_PARAMS \
) \
{ \
bli_init_once(); \
\
BLIS_OAPI_EX_DECLS \
\
num_t dt = bli_obj_dt( x ); \
\
doff_t diagoffx = bli_obj_diag_offset( x ); \
diag_t diagx = bli_obj_diag( x ); \
trans_t transx = bli_obj_conjtrans_status( x ); \
dim_t m = bli_obj_length( y ); \
dim_t n = bli_obj_width( y ); \
void* buf_x = bli_obj_buffer_at_off( x ); \
inc_t rs_x = bli_obj_row_stride( x ); \
inc_t cs_x = bli_obj_col_stride( x ); \
void* buf_y = bli_obj_buffer_at_off( y ); \
inc_t rs_y = bli_obj_row_stride( y ); \
inc_t cs_y = bli_obj_col_stride( y ); \
\
if ( bli_error_checking_is_enabled() ) \
PASTEMAC(opname,_check)( x, y ); \
\
/* Query a type-specific function pointer, except one that uses
void* for function arguments instead of typed pointers. */ \
PASTECH2(opname,BLIS_TAPI_EX_SUF,_vft) f = \
PASTEMAC2(opname,BLIS_TAPI_EX_SUF,_qfp)( dt ); \
\
f \
( \
diagoffx, \
diagx, \
transx, \
m, \
n, \
buf_x, rs_x, cs_x, \
buf_y, rs_y, cs_y, \
cntx, \
rntm \
); \
}
GENFRONT( addd )
GENFRONT( copyd )
GENFRONT( subd )
#undef GENFRONT
#define GENFRONT( opname ) \
\
void PASTEMAC(opname,EX_SUF) \
( \
obj_t* alpha, \
obj_t* x, \
obj_t* y \
BLIS_OAPI_EX_PARAMS \
) \
{ \
bli_init_once(); \
\
BLIS_OAPI_EX_DECLS \
\
num_t dt = bli_obj_dt( x ); \
\
doff_t diagoffx = bli_obj_diag_offset( x ); \
diag_t diagx = bli_obj_diag( x ); \
trans_t transx = bli_obj_conjtrans_status( x ); \
dim_t m = bli_obj_length( y ); \
dim_t n = bli_obj_width( y ); \
void* buf_x = bli_obj_buffer_at_off( x ); \
inc_t rs_x = bli_obj_row_stride( x ); \
inc_t cs_x = bli_obj_col_stride( x ); \
void* buf_y = bli_obj_buffer_at_off( y ); \
inc_t rs_y = bli_obj_row_stride( y ); \
inc_t cs_y = bli_obj_col_stride( y ); \
\
void* buf_alpha; \
\
obj_t alpha_local; \
\
if ( bli_error_checking_is_enabled() ) \
PASTEMAC(opname,_check)( alpha, x, y ); \
\
/* Create local copy-casts of scalars (and apply internal conjugation
as needed). */ \
bli_obj_scalar_init_detached_copy_of( dt, BLIS_NO_CONJUGATE, \
alpha, &alpha_local ); \
buf_alpha = bli_obj_buffer_for_1x1( dt, &alpha_local ); \
\
/* Query a type-specific function pointer, except one that uses
void* for function arguments instead of typed pointers. */ \
PASTECH2(opname,BLIS_TAPI_EX_SUF,_vft) f = \
PASTEMAC2(opname,BLIS_TAPI_EX_SUF,_qfp)( dt ); \
\
f \
( \
diagoffx, \
diagx, \
transx, \
m, \
n, \
buf_alpha, \
buf_x, rs_x, cs_x, \
buf_y, rs_y, cs_y, \
cntx, \
rntm \
); \
}
GENFRONT( axpyd )
GENFRONT( scal2d )
#undef GENFRONT
#define GENFRONT( opname ) \
\
void PASTEMAC(opname,EX_SUF) \
( \
obj_t* x \
BLIS_OAPI_EX_PARAMS \
) \
{ \
bli_init_once(); \
\
BLIS_OAPI_EX_DECLS \
\
num_t dt = bli_obj_dt( x ); \
\
doff_t diagoffx = bli_obj_diag_offset( x ); \
dim_t m = bli_obj_length( x ); \
dim_t n = bli_obj_width( x ); \
void* buf_x = bli_obj_buffer_at_off( x ); \
inc_t rs_x = bli_obj_row_stride( x ); \
inc_t cs_x = bli_obj_col_stride( x ); \
\
if ( bli_error_checking_is_enabled() ) \
PASTEMAC(opname,_check)( x ); \
\
/* Query a type-specific function pointer, except one that uses
void* for function arguments instead of typed pointers. */ \
PASTECH2(opname,BLIS_TAPI_EX_SUF,_vft) f = \
PASTEMAC2(opname,BLIS_TAPI_EX_SUF,_qfp)( dt ); \
\
f \
( \
diagoffx, \
m, \
n, \
buf_x, rs_x, cs_x, \
cntx, \
rntm \
); \
}
GENFRONT( invertd )
#undef GENFRONT
#define GENFRONT( opname ) \
\
void PASTEMAC(opname,EX_SUF) \
( \
obj_t* alpha, \
obj_t* x \
BLIS_OAPI_EX_PARAMS \
) \
{ \
bli_init_once(); \
\
BLIS_OAPI_EX_DECLS \
\
num_t dt = bli_obj_dt( x ); \
\
/* conj_t conjalpha = bli_obj_conj_status( alpha ); */ \
doff_t diagoffx = bli_obj_diag_offset( x ); \
dim_t m = bli_obj_length( x ); \
dim_t n = bli_obj_width( x ); \
void* buf_x = bli_obj_buffer_at_off( x ); \
inc_t rs_x = bli_obj_row_stride( x ); \
inc_t cs_x = bli_obj_col_stride( x ); \
\
void* buf_alpha; \
\
obj_t alpha_local; \
\
if ( bli_error_checking_is_enabled() ) \
PASTEMAC(opname,_check)( alpha, x ); \
\
/* Create local copy-casts of scalars (and apply internal conjugation
as needed). */ \
bli_obj_scalar_init_detached_copy_of( dt, BLIS_NO_CONJUGATE, \
alpha, &alpha_local ); \
buf_alpha = bli_obj_buffer_for_1x1( dt, &alpha_local ); \
\
/* Query a type-specific function pointer, except one that uses
void* for function arguments instead of typed pointers. */ \
PASTECH2(opname,BLIS_TAPI_EX_SUF,_vft) f = \
PASTEMAC2(opname,BLIS_TAPI_EX_SUF,_qfp)( dt ); \
\
f \
( \
BLIS_NO_CONJUGATE, /* internal conjugation applied during copy-cast. */ \
diagoffx, \
m, \
n, \
buf_alpha, \
buf_x, rs_x, cs_x, \
cntx, \
rntm \
); \
}
GENFRONT( scald )
GENFRONT( setd )
#undef GENFRONT
#define GENFRONT( opname ) \
\
void PASTEMAC(opname,EX_SUF) \
( \
obj_t* alpha, \
obj_t* x \
BLIS_OAPI_EX_PARAMS \
) \
{ \
bli_init_once(); \
\
BLIS_OAPI_EX_DECLS \
\
num_t dt = bli_obj_dt( x ); \
\
doff_t diagoffx = bli_obj_diag_offset( x ); \
dim_t m = bli_obj_length( x ); \
dim_t n = bli_obj_width( x ); \
void* buf_x = bli_obj_buffer_at_off( x ); \
inc_t rs_x = bli_obj_row_stride( x ); \
inc_t cs_x = bli_obj_col_stride( x ); \
\
void* buf_alpha = bli_obj_buffer_for_1x1( dt, alpha ); \
\
if ( bli_error_checking_is_enabled() ) \
PASTEMAC(opname,_check)( alpha, x ); \
\
/* Query a type-specific function pointer, except one that uses
void* for function arguments instead of typed pointers. */ \
PASTECH2(opname,BLIS_TAPI_EX_SUF,_vft) f = \
PASTEMAC2(opname,BLIS_TAPI_EX_SUF,_qfp)( dt ); \
\
f \
( \
diagoffx, \
m, \
n, \
buf_alpha, \
buf_x, rs_x, cs_x, \
cntx, \
rntm \
); \
}
GENFRONT( setid )
#undef GENFRONT
#define GENFRONT( opname ) \
\
void PASTEMAC(opname,EX_SUF) \
( \
obj_t* alpha, \
obj_t* x \
BLIS_OAPI_EX_PARAMS \
) \
{ \
bli_init_once(); \
\
BLIS_OAPI_EX_DECLS \
\
num_t dt = bli_obj_dt( x ); \
\
doff_t diagoffx = bli_obj_diag_offset( x ); \
dim_t m = bli_obj_length( x ); \
dim_t n = bli_obj_width( x ); \
void* buf_x = bli_obj_buffer_at_off( x ); \
inc_t rs_x = bli_obj_row_stride( x ); \
inc_t cs_x = bli_obj_col_stride( x ); \
\
void* buf_alpha; \
\
obj_t alpha_local; \
\
if ( bli_error_checking_is_enabled() ) \
PASTEMAC(opname,_check)( alpha, x ); \
\
/* Create local copy-casts of scalars (and apply internal conjugation
as needed). */ \
bli_obj_scalar_init_detached_copy_of( dt, BLIS_NO_CONJUGATE, \
alpha, &alpha_local ); \
buf_alpha = bli_obj_buffer_for_1x1( dt, &alpha_local ); \
\
/* Query a type-specific function pointer, except one that uses
void* for function arguments instead of typed pointers. */ \
PASTECH2(opname,BLIS_TAPI_EX_SUF,_vft) f = \
PASTEMAC2(opname,BLIS_TAPI_EX_SUF,_qfp)( dt ); \
\
f \
( \
diagoffx, \
m, \
n, \
buf_alpha, \
buf_x, rs_x, cs_x, \
cntx, \
rntm \
); \
}
GENFRONT( shiftd )
#undef GENFRONT
#define GENFRONT( opname ) \
\
void PASTEMAC(opname,EX_SUF) \
( \
obj_t* x, \
obj_t* beta, \
obj_t* y \
BLIS_OAPI_EX_PARAMS \
) \
{ \
bli_init_once(); \
\
BLIS_OAPI_EX_DECLS \
\
num_t dt = bli_obj_dt( x ); \
\
doff_t diagoffx = bli_obj_diag_offset( x ); \
diag_t diagx = bli_obj_diag( x ); \
trans_t transx = bli_obj_conjtrans_status( x ); \
dim_t m = bli_obj_length( y ); \
dim_t n = bli_obj_width( y ); \
void* buf_x = bli_obj_buffer_at_off( x ); \
inc_t rs_x = bli_obj_row_stride( x ); \
inc_t cs_x = bli_obj_col_stride( x ); \
void* buf_y = bli_obj_buffer_at_off( y ); \
inc_t rs_y = bli_obj_row_stride( y ); \
inc_t cs_y = bli_obj_col_stride( y ); \
\
void* buf_beta; \
\
obj_t beta_local; \
\
if ( bli_error_checking_is_enabled() ) \
PASTEMAC(opname,_check)( x, beta, y ); \
\
/* Create local copy-casts of scalars (and apply internal conjugation
as needed). */ \
bli_obj_scalar_init_detached_copy_of( dt, BLIS_NO_CONJUGATE, \
beta, &beta_local ); \
buf_beta = bli_obj_buffer_for_1x1( dt, &beta_local ); \
\
/* Query a type-specific function pointer, except one that uses
void* for function arguments instead of typed pointers. */ \
PASTECH2(opname,BLIS_TAPI_EX_SUF,_vft) f = \
PASTEMAC2(opname,BLIS_TAPI_EX_SUF,_qfp)( dt ); \
\
f \
( \
diagoffx, \
diagx, \
transx, \
m, \
n, \
buf_x, rs_x, cs_x, \
buf_beta, \
buf_y, rs_y, cs_y, \
cntx, \
rntm \
); \
}
GENFRONT( xpbyd )
#endif
|
the_stack_data/51700026.c
|
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#define MAX_HW_MONS 32
#define MAX_SENSORS 32
#define MAX_PATH_LEN 256
#define MAX_FILEBUF_LEN 256
#define TEMP_SCALE_COEF 1000
int init_temp(int* fds, int fds_len) {
char buf[MAX_PATH_LEN] = {0};
char buf_file[MAX_FILEBUF_LEN] = {0};
int i,j;
int fd;
int ret;
struct stat sb;
int fd_ptr = 0;
if (fds_len == 0) {
return 0;
}
for (i = 0; i < MAX_HW_MONS; i += 1) {
snprintf(buf, MAX_PATH_LEN, "/sys/class/hwmon/hwmon%d", i);
if (stat(buf, &sb) != 0 || !S_ISDIR(sb.st_mode)) {
continue;
}
for (j = 0; j < MAX_SENSORS; j += 1) {
snprintf(buf, MAX_PATH_LEN, "/sys/class/hwmon/hwmon%d/temp%d_label", i, j);
fd = open(buf, O_RDONLY);
if (fd == -1) {
continue;
}
ret = read(fd, buf_file, MAX_FILEBUF_LEN);
if (ret == -1) {
continue;
}
close(fd);
if (memmem(buf_file, ret, "Package", 7) == NULL &&
memmem(buf_file, ret, "Core", 4) == NULL) {
continue;
}
snprintf(buf, MAX_PATH_LEN, "/sys/class/hwmon/hwmon%d/temp%d_input", i, j);
fd = open(buf, O_RDONLY);
if (fd == -1) {
continue;
}
if (fd_ptr < fds_len) {
fds[fd_ptr] = fd;
fd_ptr += 1;
} else {
return fd_ptr;
}
}
}
return fd_ptr;
}
static int get_temp_by_fd(int fd) {
char buf_file[MAX_FILEBUF_LEN];
int ret;
if (pread(fd, buf_file, MAX_FILEBUF_LEN, 0) == -1) {
return -1;
}
return atoi(buf_file) / TEMP_SCALE_COEF;
}
int get_temp(int* fds, int fds_len) {
int i;
int temp_cnt = 0;
int avg = 0;
for (i = 0; i < fds_len; i+= 1) {
int temp = get_temp_by_fd(fds[i]);
if(temp == -1) {
continue;
}
avg += temp;
temp_cnt += 1;
}
return avg / temp_cnt;
}
|
the_stack_data/1095536.c
|
/*
* Autore: Bartocetti Enrico
* Data: 25/09/2020
* Versione: 1
* Sorgente: calculator.c
*
* Funzione:
* Eseguire le 4 operazioni fondamentali tra 2 numeri.
*
*/
#include <stdio.h>
#include <stdlib.h>
float a;
float b;
float result;
int operator;
void main(){
printf("CALCULATOR IN C - by EnryBarto:\n\n");
printf("Insert the first number: ");
scanf("%f",&a);
printf("Insert the second number: ");
scanf("%f",&b);
printf("\nInsert: 1 - to do a sum;\nInsert: 2 - to do a subtraction;\nInsert: 3 - to do a multiplication;\nInsert: 4 - to do a division.\nInsert operator: ");
scanf("%d",&operator);
printf("\n");
if (operator == 1){
result = a + b;
printf("Result: %f \n", result);
} else if (operator == 2){
result = a - b;
printf("Result: %f \n", result);
} else if (operator == 3){
result = a * b;
printf("Result: %f \n", result);
} else if (operator == 4){
if (b != 0){
result = a / b;
printf("Result: %f \n", result);
} else if (b == 0){
if (a != 0){
printf("Can't divide by 0\n");
} else if (a == 0){
printf("Undefined\n");
}
}
}
}
|
the_stack_data/107953918.c
|
/* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2000-2009 Josh Coalson
* Copyright (C) 2011-2014 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.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#ifndef FLAC__NO_ASM
#if (defined FLAC__CPU_IA32 || defined FLAC__CPU_X86_64) && defined FLAC__HAS_X86INTRIN
#include "private/stream_encoder.h"
#include "private/bitmath.h"
#ifdef FLAC__AVX2_SUPPORTED
#include <stdlib.h> /* for abs() */
#include <immintrin.h> /* AVX2 */
#include "FLAC/assert.h"
FLAC__SSE_TARGET("avx2")
void FLAC__precompute_partition_info_sums_intrin_avx2(const FLAC__int32 residual[], FLAC__uint64 abs_residual_partition_sums[],
unsigned residual_samples, unsigned predictor_order, unsigned min_partition_order, unsigned max_partition_order, unsigned bps)
{
const unsigned default_partition_samples = (residual_samples + predictor_order) >> max_partition_order;
unsigned partitions = 1u << max_partition_order;
FLAC__ASSERT(default_partition_samples > predictor_order);
/* first do max_partition_order */
{
unsigned partition, residual_sample, end = (unsigned)(-(int)predictor_order);
__m256i res256, sum256;
__m128i res128, sum128;
if(FLAC__bitmath_ilog2(default_partition_samples) + bps + FLAC__MAX_EXTRA_RESIDUAL_BPS < 32) {
for(partition = residual_sample = 0; partition < partitions; partition++) {
end += default_partition_samples;
sum256 = _mm256_setzero_si256();
for( ; (int)residual_sample < (int)end-7; residual_sample+=8) {
res256 = _mm256_abs_epi32(_mm256_loadu_si256((const __m256i*)(residual+residual_sample)));
sum256 = _mm256_add_epi32(sum256, res256);
}
sum128 = _mm_add_epi32(_mm256_extracti128_si256(sum256, 1), _mm256_castsi256_si128(sum256));
for( ; (int)residual_sample < (int)end-3; residual_sample+=4) {
res128 = _mm_abs_epi32(_mm_loadu_si128((const __m128i*)(residual+residual_sample)));
sum128 = _mm_add_epi32(sum128, res128);
}
for( ; residual_sample < end; residual_sample++) {
res128 = _mm_cvtsi32_si128(residual[residual_sample]);
res128 = _mm_abs_epi32(res128);
sum128 = _mm_add_epi32(sum128, res128);
}
sum128 = _mm_hadd_epi32(sum128, sum128);
sum128 = _mm_hadd_epi32(sum128, sum128);
abs_residual_partition_sums[partition] = (FLAC__uint32)_mm_cvtsi128_si32(sum128);
}
}
else { /* have to pessimistically use 64 bits for accumulator */
for(partition = residual_sample = 0; partition < partitions; partition++) {
end += default_partition_samples;
sum256 = _mm256_setzero_si256();
for( ; (int)residual_sample < (int)end-3; residual_sample+=4) {
res128 = _mm_abs_epi32(_mm_loadu_si128((const __m128i*)(residual+residual_sample)));
res256 = _mm256_cvtepu32_epi64(res128);
sum256 = _mm256_add_epi64(sum256, res256);
}
sum128 = _mm_add_epi64(_mm256_extracti128_si256(sum256, 1), _mm256_castsi256_si128(sum256));
for( ; (int)residual_sample < (int)end-1; residual_sample+=2) {
res128 = _mm_loadl_epi64((const __m128i*)(residual+residual_sample));
res128 = _mm_abs_epi32(res128);
res128 = _mm_cvtepu32_epi64(res128);
sum128 = _mm_add_epi64(sum128, res128);
}
for( ; residual_sample < end; residual_sample++) {
res128 = _mm_cvtsi32_si128(residual[residual_sample]);
res128 = _mm_abs_epi32(res128);
sum128 = _mm_add_epi64(sum128, res128);
}
sum128 = _mm_add_epi64(sum128, _mm_srli_si128(sum128, 8));
_mm_storel_epi64((__m128i*)(abs_residual_partition_sums+partition), sum128);
}
}
}
/* now merge partitions for lower orders */
{
unsigned from_partition = 0, to_partition = partitions;
int partition_order;
for(partition_order = (int)max_partition_order - 1; partition_order >= (int)min_partition_order; partition_order--) {
unsigned i;
partitions >>= 1;
for(i = 0; i < partitions; i++) {
abs_residual_partition_sums[to_partition++] =
abs_residual_partition_sums[from_partition ] +
abs_residual_partition_sums[from_partition+1];
from_partition += 2;
}
}
}
_mm256_zeroupper();
}
#endif /* FLAC__AVX2_SUPPORTED */
#endif /* (FLAC__CPU_IA32 || FLAC__CPU_X86_64) && FLAC__HAS_X86INTRIN */
#endif /* FLAC__NO_ASM */
|
the_stack_data/90763204.c
|
/* PR sanitizer/80800 */
/* { dg-do run } */
/* { dg-options "-fsanitize=undefined -fsanitize-undefined-trap-on-error" } */
int n = 20000;
int z = 0;
int
fn1 (void)
{
return (n * 10000 * z) * 50;
}
int
fn2 (void)
{
return (10000 * n * z) * 50;
}
int
main ()
{
fn1 ();
fn2 ();
}
|
the_stack_data/1173013.c
|
/**
******************************************************************************
* @file stm32g0xx_ll_gpio.c
* @author MCD Application Team
* @brief GPIO LL module driver.
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2018 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
#if defined(USE_FULL_LL_DRIVER)
/* Includes ------------------------------------------------------------------*/
#include "stm32g0xx_ll_gpio.h"
#include "stm32g0xx_ll_bus.h"
#ifdef USE_FULL_ASSERT
#include "stm32_assert.h"
#else
#define assert_param(expr) ((void)0U)
#endif
/** @addtogroup STM32G0xx_LL_Driver
* @{
*/
#if defined (GPIOA) || defined (GPIOB) || defined (GPIOC) || defined (GPIOD) || defined (GPIOE) || defined (GPIOF)
/** @addtogroup GPIO_LL
* @{
*/
/** MISRA C:2012 deviation rule has been granted for following rules:
* Rule-12.2 - Medium: RHS argument is in interval [0,INF] which is out of
* range of the shift operator in following API :
* LL_GPIO_Init
*/
/* Private types -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private constants ---------------------------------------------------------*/
/* Private macros ------------------------------------------------------------*/
/** @addtogroup GPIO_LL_Private_Macros
* @{
*/
#define IS_LL_GPIO_PIN(__VALUE__) (((0x00u) < (__VALUE__)) && ((__VALUE__) <= (LL_GPIO_PIN_ALL)))
#define IS_LL_GPIO_MODE(__VALUE__) (((__VALUE__) == LL_GPIO_MODE_INPUT) ||\
((__VALUE__) == LL_GPIO_MODE_OUTPUT) ||\
((__VALUE__) == LL_GPIO_MODE_ALTERNATE) ||\
((__VALUE__) == LL_GPIO_MODE_ANALOG))
#define IS_LL_GPIO_OUTPUT_TYPE(__VALUE__) (((__VALUE__) == LL_GPIO_OUTPUT_PUSHPULL) ||\
((__VALUE__) == LL_GPIO_OUTPUT_OPENDRAIN))
#define IS_LL_GPIO_SPEED(__VALUE__) (((__VALUE__) == LL_GPIO_SPEED_FREQ_LOW) ||\
((__VALUE__) == LL_GPIO_SPEED_FREQ_MEDIUM) ||\
((__VALUE__) == LL_GPIO_SPEED_FREQ_HIGH) ||\
((__VALUE__) == LL_GPIO_SPEED_FREQ_VERY_HIGH))
#define IS_LL_GPIO_PULL(__VALUE__) (((__VALUE__) == LL_GPIO_PULL_NO) ||\
((__VALUE__) == LL_GPIO_PULL_UP) ||\
((__VALUE__) == LL_GPIO_PULL_DOWN))
#define IS_LL_GPIO_ALTERNATE(__VALUE__) (((__VALUE__) == LL_GPIO_AF_0 ) ||\
((__VALUE__) == LL_GPIO_AF_1 ) ||\
((__VALUE__) == LL_GPIO_AF_2 ) ||\
((__VALUE__) == LL_GPIO_AF_3 ) ||\
((__VALUE__) == LL_GPIO_AF_4 ) ||\
((__VALUE__) == LL_GPIO_AF_5 ) ||\
((__VALUE__) == LL_GPIO_AF_6 ) ||\
((__VALUE__) == LL_GPIO_AF_7 ))
/**
* @}
*/
/* Private function prototypes -----------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
/** @addtogroup GPIO_LL_Exported_Functions
* @{
*/
/** @addtogroup GPIO_LL_EF_Init
* @{
*/
/**
* @brief De-initialize GPIO registers (Registers restored to their default values).
* @param GPIOx GPIO Port
* @retval An ErrorStatus enumeration value:
* - SUCCESS: GPIO registers are de-initialized
* - ERROR: Wrong GPIO Port
*/
ErrorStatus LL_GPIO_DeInit(GPIO_TypeDef *GPIOx)
{
ErrorStatus status = SUCCESS;
/* Check the parameters */
assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
/* Force and Release reset on clock of GPIOx Port */
if (GPIOx == GPIOA)
{
LL_IOP_GRP1_ForceReset(LL_IOP_GRP1_PERIPH_GPIOA);
LL_IOP_GRP1_ReleaseReset(LL_IOP_GRP1_PERIPH_GPIOA);
}
else if (GPIOx == GPIOB)
{
LL_IOP_GRP1_ForceReset(LL_IOP_GRP1_PERIPH_GPIOB);
LL_IOP_GRP1_ReleaseReset(LL_IOP_GRP1_PERIPH_GPIOB);
}
else if (GPIOx == GPIOC)
{
LL_IOP_GRP1_ForceReset(LL_IOP_GRP1_PERIPH_GPIOC);
LL_IOP_GRP1_ReleaseReset(LL_IOP_GRP1_PERIPH_GPIOC);
}
#if defined(GPIOD)
else if (GPIOx == GPIOD)
{
LL_IOP_GRP1_ForceReset(LL_IOP_GRP1_PERIPH_GPIOD);
LL_IOP_GRP1_ReleaseReset(LL_IOP_GRP1_PERIPH_GPIOD);
}
#endif /* GPIOD */
#if defined(GPIOE)
else if (GPIOx == GPIOE)
{
LL_IOP_GRP1_ForceReset(LL_IOP_GRP1_PERIPH_GPIOE);
LL_IOP_GRP1_ReleaseReset(LL_IOP_GRP1_PERIPH_GPIOE);
}
#endif /* GPIOE */
#if defined(GPIOF)
else if (GPIOx == GPIOF)
{
LL_IOP_GRP1_ForceReset(LL_IOP_GRP1_PERIPH_GPIOF);
LL_IOP_GRP1_ReleaseReset(LL_IOP_GRP1_PERIPH_GPIOF);
}
#endif /* GPIOF */
else
{
status = ERROR;
}
return (status);
}
/**
* @brief Initialize GPIO registers according to the specified parameters in GPIO_InitStruct.
* @param GPIOx GPIO Port
* @param GPIO_InitStruct pointer to a @ref LL_GPIO_InitTypeDef structure
* that contains the configuration information for the specified GPIO peripheral.
* @retval An ErrorStatus enumeration value:
* - SUCCESS: GPIO registers are initialized according to GPIO_InitStruct content
* - ERROR: Not applicable
*/
ErrorStatus LL_GPIO_Init(GPIO_TypeDef *GPIOx, LL_GPIO_InitTypeDef *GPIO_InitStruct)
{
uint32_t pinpos;
uint32_t currentpin;
/* Check the parameters */
assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
assert_param(IS_LL_GPIO_PIN(GPIO_InitStruct->Pin));
assert_param(IS_LL_GPIO_MODE(GPIO_InitStruct->Mode));
assert_param(IS_LL_GPIO_PULL(GPIO_InitStruct->Pull));
/* ------------------------- Configure the port pins ---------------- */
/* Initialize pinpos on first pin set */
pinpos = 0;
/* Configure the port pins */
while (((GPIO_InitStruct->Pin) >> pinpos) != 0x00u)
{
/* Get current io position */
currentpin = (GPIO_InitStruct->Pin) & (0x00000001uL << pinpos);
if (currentpin != 0x00u)
{
/* Pin Mode configuration */
LL_GPIO_SetPinMode(GPIOx, currentpin, GPIO_InitStruct->Mode);
if ((GPIO_InitStruct->Mode == LL_GPIO_MODE_OUTPUT) || (GPIO_InitStruct->Mode == LL_GPIO_MODE_ALTERNATE))
{
/* Check Speed mode parameters */
assert_param(IS_LL_GPIO_SPEED(GPIO_InitStruct->Speed));
/* Speed mode configuration */
LL_GPIO_SetPinSpeed(GPIOx, currentpin, GPIO_InitStruct->Speed);
}
/* Pull-up Pull down resistor configuration*/
LL_GPIO_SetPinPull(GPIOx, currentpin, GPIO_InitStruct->Pull);
if (GPIO_InitStruct->Mode == LL_GPIO_MODE_ALTERNATE)
{
/* Check Alternate parameter */
assert_param(IS_LL_GPIO_ALTERNATE(GPIO_InitStruct->Alternate));
/* Speed mode configuration */
if (currentpin < LL_GPIO_PIN_8)
{
LL_GPIO_SetAFPin_0_7(GPIOx, currentpin, GPIO_InitStruct->Alternate);
}
else
{
LL_GPIO_SetAFPin_8_15(GPIOx, currentpin, GPIO_InitStruct->Alternate);
}
}
}
pinpos++;
}
if ((GPIO_InitStruct->Mode == LL_GPIO_MODE_OUTPUT) || (GPIO_InitStruct->Mode == LL_GPIO_MODE_ALTERNATE))
{
/* Check Output mode parameters */
assert_param(IS_LL_GPIO_OUTPUT_TYPE(GPIO_InitStruct->OutputType));
/* Output mode configuration*/
LL_GPIO_SetPinOutputType(GPIOx, GPIO_InitStruct->Pin, GPIO_InitStruct->OutputType);
}
return (SUCCESS);
}
/**
* @brief Set each @ref LL_GPIO_InitTypeDef field to default value.
* @param GPIO_InitStruct pointer to a @ref LL_GPIO_InitTypeDef structure
* whose fields will be set to default values.
* @retval None
*/
void LL_GPIO_StructInit(LL_GPIO_InitTypeDef *GPIO_InitStruct)
{
/* Reset GPIO init structure parameters values */
GPIO_InitStruct->Pin = LL_GPIO_PIN_ALL;
GPIO_InitStruct->Mode = LL_GPIO_MODE_ANALOG;
GPIO_InitStruct->Speed = LL_GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct->OutputType = LL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitStruct->Pull = LL_GPIO_PULL_NO;
GPIO_InitStruct->Alternate = LL_GPIO_AF_0;
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#endif /* defined (GPIOA) || defined (GPIOB) || defined (GPIOC) || defined (GPIOD) || defined (GPIOE) || defined (GPIOF) */
/**
* @}
*/
#endif /* USE_FULL_LL_DRIVER */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
the_stack_data/22011837.c
|
#include <assert.h>
int main() {
_Bool b1, b2, b3;
b1=0;
b1++;
assert(b1);
b2=1;
b2+=10;
assert(b2);
b3=b1+b2;
assert(b3==1);
// a struct of _Bool
struct
{
_Bool f1, f2, f3;
_Bool f4: 1, f5: 1;
} s;
assert(sizeof(s)==4);
s.f1=2;
assert(s.f1==1);
s.f4=1;
assert(s.f4);
*((unsigned char *)(&s.f2))=1;
assert(s.f2);
}
|
the_stack_data/182952709.c
|
#include <stdlib.h>
#define assert(c) {if(!(c)) __VERIFIER_error();}
#define PRODS 2
#define CONS 2
#define TOTAL (PRODS * CONS)
#define PRODS_ITEMS (TOTAL / PRODS)
#define CONS_ITEMS (TOTAL / CONS)
static const int false = 0;
static const int true = 1;
static int total = 0;
int __VERIFIER_nondet_int();
static int unknown() {
int u = __VERIFIER_nondet_int();
if (u < 0) {
u = -u;
}
return u;
}
typedef struct {
int size;
void** array;
int put;
int get;
int used;
} buffer_t;
static buffer_t* buffer_create(int s) {
buffer_t* b = (buffer_t*) malloc(sizeof(buffer_t));
b->size = s;
b->array = (void**) malloc(s * sizeof(void*));
b->put = 0;
b->get = 0;
b->used = 0;
return b;
}
static int buffer_empty(buffer_t* b) {
return b->used == 0;
}
static int buffer_full(buffer_t* b) {
return b->used == b->size;
}
static void buffer_put(buffer_t* b, void* x) {
assert(!buffer_full(b));
b->array[b->put] = x;
b->put = b->put + 1;
while (b->put > b->size) {
b->put = b->put - b->size;
}
b->used = b->used + 1;
}
static void* buffer_get(buffer_t* b) {
assert(!buffer_empty(b));
void* x = b->array[b->get];
b->array[b->get] = NULL;
b->get = b->get + 1;
while (b->get >= b->size) {
b->get = b->get - b->size;
}
b->used = b->used - 1;
return x;
}
static void buffer_destroy(buffer_t* b) {
free(b->array);
free(b);
}
static void* payload = NULL;
typedef struct {
buffer_t* b;
int count;
int done;
} producer_t;
static producer_t* producer_create(buffer_t* b) {
producer_t* p = (producer_t*) malloc(sizeof(producer_t));
p->b = b;
p->count = 0;
p->done = false;
return p;
}
static int producer_done(producer_t* p) {
return p->done;
}
static void producer_step(producer_t* p) {
assert(!producer_done(p));
if (p->count < PRODS_ITEMS) {
payload = payload + 1;
buffer_put(p->b, payload);
}
p->count = p->count + 1;
if (p->count >= PRODS_ITEMS) {
p->done = true;
}
}
static int producer_count(producer_t* p) {
return p->count;
}
static void producer_destroy(producer_t* p) {
free(p);
}
typedef struct {
buffer_t* b;
int count;
int done;
} consumer_t;
static consumer_t* consumer_create(buffer_t* b) {
consumer_t* c = (consumer_t*) malloc(sizeof(consumer_t));
c->b = b;
c->count = 0;
c->done = false;
return c;
}
static int consumer_done(consumer_t* c) {
return c->done;
}
static void consumer_step(consumer_t* c) {
assert(!consumer_done(c));
if (c->count < CONS_ITEMS) {
void* x = buffer_get(c->b);
if (x == NULL) {
c->done = true;
}
total = total + 1;
}
c->count = c->count + 1;
if (c->count >= CONS_ITEMS) {
c->done = true;
}
}
static int consumer_count(consumer_t* c) {
return c->count;
}
static void consumer_destroy(consumer_t* c) {
free(c);
}
static void wake_producer(producer_t** prods, int i) {
int count = 0;
while (producer_done(prods[i])) {
assert(count < PRODS);
count = count + 1;
i = i + 1;
while (i >= PRODS) {
i = i - PRODS;
}
}
producer_step(prods[i]);
}
static void wake_consumer(consumer_t** cons, int i) {
int count = 0;
while (consumer_done(cons[i])) {
assert(count < CONS);
count = count + 1;
i = i + 1;
while (i >= CONS) {
i = i - CONS;
}
}
consumer_step(cons[i]);
}
static int schedule(buffer_t* b, producer_t** prods, consumer_t** cons) {
int prods_done = true;
int cons_done = true;
int k;
for (k = 0; k < PRODS; k = k + 1) {
if (!producer_done(prods[k])) {
prods_done = false;
break;
}
}
for (k = 0; k < CONS; k = k + 1) {
if (!consumer_done(cons[k])) {
cons_done = false;
break;
}
}
assert(!cons_done || !(buffer_full(b) && !prods_done));
assert(!prods_done || !(buffer_empty(b) && !cons_done));
if (!prods_done || !cons_done) {
int i = unknown();
if (!buffer_empty(b) && !buffer_full(b) && !prods_done && !cons_done) {
int all = PRODS + CONS;
while (i >= all) {
i = i - all;
}
if (i < PRODS) {
wake_producer(prods, i);
} else {
wake_consumer(cons, i - PRODS);
}
} else if (!buffer_empty(b) && !cons_done) {
while (i >= CONS) {
i = i - CONS;
}
wake_consumer(cons, i);
} else if (!buffer_full(b) && !prods_done) {
while (i >= PRODS) {
i = i - PRODS;
}
wake_producer(prods, i);
}
return true;
}
return false;
}
int main() {
producer_t* prods[PRODS];
consumer_t* cons[CONS];
buffer_t* b = buffer_create(5);
int i;
for (i = 0; i < PRODS; i = i + 1) {
prods[i] = producer_create(b);
}
for (i = 0; i < CONS; i = i + 1) {
cons[i] = consumer_create(b);
}
while (schedule(b, prods, cons)) {
}
assert(total == PRODS_ITEMS * PRODS);
for (i = 0; i < CONS; i = i + 1) {
consumer_destroy(cons[i]);
}
for (i = 0; i < PRODS; i = i + 1) {
producer_destroy(prods[i]);
}
buffer_destroy(b);
}
|
the_stack_data/198581572.c
|
#include <stdio.h>
#include <stdlib.h>
int create_array_int(int **ptr, int N);
void destroy_array_int(int **ptr);
int main()
{
int size = 0, error;
int *tab = NULL;
printf("Podaj rozmiar tablicy: ");
if(scanf("%d", &size) != 1)
{
printf("Incorrect input\n");
return 1;
}
if(size < 1)
{
printf("Incorrect input data\n");
return 2;
}
error = create_array_int(&tab, size);
if(error == 2)
{
printf("Failed to allocate memory\n");
return 8;
}
int x = 0;
printf("Podaj liczby: ");
while(x < size)
{
error = scanf("%d", tab + x);
if(error != 1)
{
printf("Incorrect input\n");
destroy_array_int(&tab);
return 1;
}
x++;
}
for (int i = 0; i < x; ++i)
{
printf("%d ", *(tab + x - i - 1));
}
destroy_array_int(&tab);
return 0;
}
int create_array_int(int **ptr, int N)
{
if(ptr == NULL || N < 1)
{
return 1;
}
*ptr = malloc(N * sizeof(int));
if (*ptr == NULL)
{
return 2;
}
return 0;
}
void destroy_array_int(int **ptr)
{
if(ptr == NULL) return;
free(*ptr);
*ptr = NULL;
}
|
the_stack_data/484713.c
|
#include <stdio.h>
int main()
{
int n1, n2;
printf("Insira o primeiro número: ");
scanf("%d", &n1);
printf("Insira o segundo número: ");
scanf("%d", &n2);
printf("\nEntre os numeros %d e %d, o quociente da divisão é %d e o resto é %d\n", n1, n2, (n1/n2), (n1%n2));
return 0;
}
|
the_stack_data/181393639.c
|
#include <stdio.h>
int main()
{
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++)
printf("%d\n", i);
}
|
the_stack_data/22135.c
|
#include<stdio.h>
int main()
{
int x,y1,y2,x1;
printf("Input a number\n");
scanf("%d",&x);
printf("\n%d\t",x);
int i=1;
while(i ==1)
{
x1=(x%2);
if(x1==0){y1=(x/2);
printf("%d\t",y1);
x=y1;
if(y1 != 1) {i=1;}
else{i=2;}
}
else if(x1 !=0){
y2=(3*x+1);
printf("%d\t",y2);
x=y2;
if(y2 !=1){
i=1;
}
else{i=2;}
}
}
}
|
the_stack_data/182953481.c
|
int lengthOfLastWord(char* s) {
int start;
int end;
end = 0;
if(!s){
return 0;
}
while(isalpha(s[end])||(s[end]==' ')){
end++;
}
end--;
while(!isalpha(s[end])){
end--;
}
start = end;
while((s[start]!=' ')&&(start>=0)){
start--;
}
return end-start;
}
|
the_stack_data/113106.c
|
/*
** =============================================================================
** Copyright (c) 2016 Texas Instruments Inc.
**
** This program is free software; you can redistribute it and/or modify it under
** the terms of the GNU General Public License as published by the Free Software
** Foundation; version 2.
**
** 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.
**
** File:
** tas2557-codec.c
**
** Description:
** ALSA SoC driver for Texas Instruments TAS2557 High Performance 4W Smart Amplifier
**
** =============================================================================
*/
#ifdef CONFIG_TAS2557_CODEC
#define DEBUG
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/pm.h>
#include <linux/i2c.h>
#include <linux/gpio.h>
#include <linux/regulator/consumer.h>
#include <linux/firmware.h>
#include <linux/regmap.h>
#include <linux/of.h>
#include <linux/of_gpio.h>
#include <linux/slab.h>
#include <linux/syscalls.h>
#include <linux/fcntl.h>
#include <linux/uaccess.h>
#include <sound/core.h>
#include <sound/pcm.h>
#include <sound/pcm_params.h>
#include <sound/soc.h>
#include <sound/initval.h>
#include <sound/tlv.h>
#include <soc/qcom/socinfo.h>
#include "tas2557-core.h"
#include "tas2557-codec.h"
#include <linux/mfd/spk-id.h>
#define KCONTROL_CODEC
static unsigned int tas2557_codec_read(struct snd_soc_codec *pCodec,
unsigned int nRegister)
{
struct tas2557_priv *pTAS2557 = snd_soc_codec_get_drvdata(pCodec);
int ret = 0;
unsigned int Value = 0;
mutex_lock(&pTAS2557->codec_lock);
ret = pTAS2557->read(pTAS2557, nRegister, &Value);
if (ret < 0)
dev_err(pTAS2557->dev, "%s, %d, ERROR happen=%d\n", __func__,
__LINE__, ret);
else
ret = Value;
mutex_unlock(&pTAS2557->codec_lock);
return ret;
}
static int tas2557_codec_write(struct snd_soc_codec *pCodec, unsigned int nRegister,
unsigned int nValue)
{
struct tas2557_priv *pTAS2557 = snd_soc_codec_get_drvdata(pCodec);
int ret = 0;
mutex_lock(&pTAS2557->codec_lock);
ret = pTAS2557->write(pTAS2557, nRegister, nValue);
mutex_unlock(&pTAS2557->codec_lock);
return ret;
}
static int tas2557_codec_suspend(struct snd_soc_codec *pCodec)
{
struct tas2557_priv *pTAS2557 = snd_soc_codec_get_drvdata(pCodec);
int ret = 0;
mutex_lock(&pTAS2557->codec_lock);
dev_dbg(pTAS2557->dev, "%s\n", __func__);
pTAS2557->runtime_suspend(pTAS2557);
mutex_unlock(&pTAS2557->codec_lock);
return ret;
}
static int tas2557_codec_resume(struct snd_soc_codec *pCodec)
{
struct tas2557_priv *pTAS2557 = snd_soc_codec_get_drvdata(pCodec);
int ret = 0;
mutex_lock(&pTAS2557->codec_lock);
dev_dbg(pTAS2557->dev, "%s\n", __func__);
pTAS2557->runtime_resume(pTAS2557);
mutex_unlock(&pTAS2557->codec_lock);
return ret;
}
static const struct snd_soc_dapm_widget tas2557_dapm_widgets[] = {
SND_SOC_DAPM_AIF_IN("ASI1", "ASI1 Playback", 0, SND_SOC_NOPM, 0, 0),
SND_SOC_DAPM_AIF_IN("ASI2", "ASI2 Playback", 0, SND_SOC_NOPM, 0, 0),
SND_SOC_DAPM_AIF_IN("ASIM", "ASIM Playback", 0, SND_SOC_NOPM, 0, 0),
SND_SOC_DAPM_DAC("DAC", NULL, SND_SOC_NOPM, 0, 0),
SND_SOC_DAPM_OUT_DRV("ClassD", SND_SOC_NOPM, 0, 0, NULL, 0),
SND_SOC_DAPM_SUPPLY("PLL", SND_SOC_NOPM, 0, 0, NULL, 0),
SND_SOC_DAPM_SUPPLY("NDivider", SND_SOC_NOPM, 0, 0, NULL, 0),
SND_SOC_DAPM_OUTPUT("OUT")
};
static const struct snd_soc_dapm_route tas2557_audio_map[] = {
{"DAC", NULL, "ASI1"},
{"DAC", NULL, "ASI2"},
{"DAC", NULL, "ASIM"},
{"ClassD", NULL, "DAC"},
{"OUT", NULL, "ClassD"},
{"DAC", NULL, "PLL"},
{"DAC", NULL, "NDivider"},
};
static int tas2557_startup(struct snd_pcm_substream *substream,
struct snd_soc_dai *dai)
{
struct snd_soc_codec *codec = dai->codec;
struct tas2557_priv *pTAS2557 = snd_soc_codec_get_drvdata(codec);
dev_dbg(pTAS2557->dev, "%s\n", __func__);
return 0;
}
static void tas2557_shutdown(struct snd_pcm_substream *substream,
struct snd_soc_dai *dai)
{
struct snd_soc_codec *codec = dai->codec;
struct tas2557_priv *pTAS2557 = snd_soc_codec_get_drvdata(codec);
dev_dbg(pTAS2557->dev, "%s\n", __func__);
}
static int tas2557_mute(struct snd_soc_dai *dai, int mute)
{
struct snd_soc_codec *codec = dai->codec;
struct tas2557_priv *pTAS2557 = snd_soc_codec_get_drvdata(codec);
mutex_lock(&pTAS2557->codec_lock);
dev_dbg(pTAS2557->dev, "%s\n", __func__);
tas2557_enable(pTAS2557, !mute);
mutex_unlock(&pTAS2557->codec_lock);
return 0;
}
static int tas2557_set_dai_sysclk(struct snd_soc_dai *pDAI,
int nClkID, unsigned int nFreqency, int nDir)
{
struct snd_soc_codec *pCodec = pDAI->codec;
struct tas2557_priv *pTAS2557 = snd_soc_codec_get_drvdata(pCodec);
dev_dbg(pTAS2557->dev, "tas2557_set_dai_sysclk: freq = %u\n", nFreqency);
return 0;
}
static int tas2557_hw_params(struct snd_pcm_substream *pSubstream,
struct snd_pcm_hw_params *pParams, struct snd_soc_dai *pDAI)
{
struct snd_soc_codec *pCodec = pDAI->codec;
struct tas2557_priv *pTAS2557 = snd_soc_codec_get_drvdata(pCodec);
mutex_lock(&pTAS2557->codec_lock);
dev_dbg(pTAS2557->dev, "%s\n", __func__);
/* do bit rate setting during platform data */
/* tas2557_set_bit_rate(pTAS2557, channel_both, snd_pcm_format_width(params_format(pParams))); */
tas2557_set_sampling_rate(pTAS2557, params_rate(pParams));
mutex_unlock(&pTAS2557->codec_lock);
return 0;
}
static int tas2557_set_dai_fmt(struct snd_soc_dai *pDAI, unsigned int nFormat)
{
struct snd_soc_codec *codec = pDAI->codec;
struct tas2557_priv *pTAS2557 = snd_soc_codec_get_drvdata(codec);
dev_dbg(pTAS2557->dev, "%s\n", __func__);
return 0;
}
static int tas2557_prepare(struct snd_pcm_substream *pSubstream,
struct snd_soc_dai *pDAI)
{
struct snd_soc_codec *codec = pDAI->codec;
struct tas2557_priv *pTAS2557 = snd_soc_codec_get_drvdata(codec);
dev_dbg(pTAS2557->dev, "%s\n", __func__);
return 0;
}
static int tas2557_set_bias_level(struct snd_soc_codec *pCodec,
enum snd_soc_bias_level eLevel)
{
struct tas2557_priv *pTAS2557 = snd_soc_codec_get_drvdata(pCodec);
dev_dbg(pTAS2557->dev, "%s: %d\n", __func__, eLevel);
return 0;
}
static int tas2557_codec_probe(struct snd_soc_codec *pCodec)
{
struct tas2557_priv *pTAS2557 = snd_soc_codec_get_drvdata(pCodec);
dev_dbg(pTAS2557->dev, "%s\n", __func__);
return 0;
}
static int tas2557_codec_remove(struct snd_soc_codec *pCodec)
{
return 0;
}
static int tas2557_mute_ctrl_get(struct snd_kcontrol *pKcontrol,
struct snd_ctl_elem_value *pValue)
{
#ifdef KCONTROL_CODEC
struct snd_soc_codec *codec = snd_soc_kcontrol_codec(pKcontrol);
#else
struct snd_soc_codec *codec = snd_kcontrol_chip(pKcontrol);
#endif
struct tas2557_priv *pTAS2557 = snd_soc_codec_get_drvdata(codec);
mutex_lock(&pTAS2557->codec_lock);
pValue->value.integer.value[0] = pTAS2557->mbMute;
dev_dbg(pTAS2557->dev, "tas2557_mute_ctrl_get = %d\n",
pTAS2557->mbMute);
mutex_unlock(&pTAS2557->codec_lock);
return 0;
}
static int tas2557_mute_ctrl_put(struct snd_kcontrol *pKcontrol,
struct snd_ctl_elem_value *pValue)
{
#ifdef KCONTROL_CODEC
struct snd_soc_codec *codec = snd_soc_kcontrol_codec(pKcontrol);
#else
struct snd_soc_codec *codec = snd_kcontrol_chip(pKcontrol);
#endif
struct tas2557_priv *pTAS2557 = snd_soc_codec_get_drvdata(codec);
int mbMute = pValue->value.integer.value[0];
mutex_lock(&pTAS2557->codec_lock);
dev_dbg(pTAS2557->dev, "tas2557_mute_ctrl_put = %d\n", mbMute);
tas2557_permanent_mute(pTAS2557, mbMute);
mutex_unlock(&pTAS2557->codec_lock);
return 0;
}
static int tas2557_power_ctrl_get(struct snd_kcontrol *pKcontrol,
struct snd_ctl_elem_value *pValue)
{
#ifdef KCONTROL_CODEC
struct snd_soc_codec *codec = snd_soc_kcontrol_codec(pKcontrol);
#else
struct snd_soc_codec *codec = snd_kcontrol_chip(pKcontrol);
#endif
struct tas2557_priv *pTAS2557 = snd_soc_codec_get_drvdata(codec);
mutex_lock(&pTAS2557->codec_lock);
pValue->value.integer.value[0] = pTAS2557->mbPowerUp;
dev_dbg(pTAS2557->dev, "tas2557_power_ctrl_get = %d\n",
pTAS2557->mbPowerUp);
mutex_unlock(&pTAS2557->codec_lock);
return 0;
}
static int tas2557_power_ctrl_put(struct snd_kcontrol *pKcontrol,
struct snd_ctl_elem_value *pValue)
{
#ifdef KCONTROL_CODEC
struct snd_soc_codec *codec = snd_soc_kcontrol_codec(pKcontrol);
#else
struct snd_soc_codec *codec = snd_kcontrol_chip(pKcontrol);
#endif
struct tas2557_priv *pTAS2557 = snd_soc_codec_get_drvdata(codec);
int nPowerOn = pValue->value.integer.value[0];
mutex_lock(&pTAS2557->codec_lock);
dev_dbg(pTAS2557->dev, "tas2557_power_ctrl_put = %d\n", nPowerOn);
tas2557_enable(pTAS2557, (nPowerOn != 0));
mutex_unlock(&pTAS2557->codec_lock);
return 0;
}
static int vendor_id_get(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
struct tas2557_priv *pTAS2557 = snd_soc_codec_get_drvdata(codec);
ucontrol->value.integer.value[0] = VENDOR_ID_NONE;
if (pTAS2557->spk_id_gpio_p)
ucontrol->value.integer.value[0] = spk_id_get(pTAS2557->spk_id_gpio_p);
return 0;
}
static int pa_version_get(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
struct tas2557_priv *pTAS2557 = snd_soc_codec_get_drvdata(codec);
ucontrol->value.integer.value[0] = 0;
if (pTAS2557->mnPGID == TAS2557_PG_VERSION_1P0)
ucontrol->value.integer.value[0] = 1;
else if(pTAS2557->mnPGID == TAS2557_PG_VERSION_2P0)
ucontrol->value.integer.value[0] = 2;
else if(pTAS2557->mnPGID == TAS2557_PG_VERSION_2P1)
ucontrol->value.integer.value[0] = 3;
return 0;
}
static int tas2557_fs_get(struct snd_kcontrol *pKcontrol,
struct snd_ctl_elem_value *pValue)
{
#ifdef KCONTROL_CODEC
struct snd_soc_codec *codec = snd_soc_kcontrol_codec(pKcontrol);
#else
struct snd_soc_codec *codec = snd_kcontrol_chip(pKcontrol);
#endif
struct tas2557_priv *pTAS2557 = snd_soc_codec_get_drvdata(codec);
int nFS = 48000;
mutex_lock(&pTAS2557->codec_lock);
if (pTAS2557->mpFirmware->mnConfigurations)
nFS = pTAS2557->mpFirmware->mpConfigurations[pTAS2557->mnCurrentConfiguration].mnSamplingRate;
pValue->value.integer.value[0] = nFS;
dev_dbg(pTAS2557->dev, "tas2557_fs_get = %d\n", nFS);
mutex_unlock(&pTAS2557->codec_lock);
return 0;
}
static int tas2557_fs_put(struct snd_kcontrol *pKcontrol,
struct snd_ctl_elem_value *pValue)
{
#ifdef KCONTROL_CODEC
struct snd_soc_codec *codec = snd_soc_kcontrol_codec(pKcontrol);
#else
struct snd_soc_codec *codec = snd_kcontrol_chip(pKcontrol);
#endif
struct tas2557_priv *pTAS2557 = snd_soc_codec_get_drvdata(codec);
int ret = 0;
int nFS = pValue->value.integer.value[0];
mutex_lock(&pTAS2557->codec_lock);
dev_info(pTAS2557->dev, "tas2557_fs_put = %d\n", nFS);
ret = tas2557_set_sampling_rate(pTAS2557, nFS);
mutex_unlock(&pTAS2557->codec_lock);
return ret;
}
static int tas2557_Cali_get(struct snd_kcontrol *pKcontrol,
struct snd_ctl_elem_value *pValue)
{
#ifdef KCONTROL_CODEC
struct snd_soc_codec *codec = snd_soc_kcontrol_codec(pKcontrol);
#else
struct snd_soc_codec *codec = snd_kcontrol_chip(pKcontrol);
#endif
struct tas2557_priv *pTAS2557 = snd_soc_codec_get_drvdata(codec);
bool ret = 0;
int prm_r0 = 0;
mutex_lock(&pTAS2557->codec_lock);
ret = tas2557_get_Cali_prm_r0(pTAS2557, &prm_r0);
if (ret)
pValue->value.integer.value[0] = prm_r0;
mutex_unlock(&pTAS2557->codec_lock);
return 0;
}
static int tas2557_program_get(struct snd_kcontrol *pKcontrol,
struct snd_ctl_elem_value *pValue)
{
#ifdef KCONTROL_CODEC
struct snd_soc_codec *codec = snd_soc_kcontrol_codec(pKcontrol);
#else
struct snd_soc_codec *codec = snd_kcontrol_chip(pKcontrol);
#endif
struct tas2557_priv *pTAS2557 = snd_soc_codec_get_drvdata(codec);
mutex_lock(&pTAS2557->codec_lock);
pValue->value.integer.value[0] = pTAS2557->mnCurrentProgram;
dev_dbg(pTAS2557->dev, "tas2557_program_get = %d\n",
pTAS2557->mnCurrentProgram);
mutex_unlock(&pTAS2557->codec_lock);
return 0;
}
static int tas2557_program_put(struct snd_kcontrol *pKcontrol,
struct snd_ctl_elem_value *pValue)
{
#ifdef KCONTROL_CODEC
struct snd_soc_codec *codec = snd_soc_kcontrol_codec(pKcontrol);
#else
struct snd_soc_codec *codec = snd_kcontrol_chip(pKcontrol);
#endif
struct tas2557_priv *pTAS2557 = snd_soc_codec_get_drvdata(codec);
unsigned int nProgram = pValue->value.integer.value[0];
int ret = 0, nConfiguration = -1;
mutex_lock(&pTAS2557->codec_lock);
if (nProgram == pTAS2557->mnCurrentProgram)
nConfiguration = pTAS2557->mnCurrentConfiguration;
ret = tas2557_set_program(pTAS2557, nProgram, nConfiguration);
mutex_unlock(&pTAS2557->codec_lock);
return ret;
}
static int tas2557_configuration_get(struct snd_kcontrol *pKcontrol,
struct snd_ctl_elem_value *pValue)
{
#ifdef KCONTROL_CODEC
struct snd_soc_codec *codec = snd_soc_kcontrol_codec(pKcontrol);
#else
struct snd_soc_codec *codec = snd_kcontrol_chip(pKcontrol);
#endif
struct tas2557_priv *pTAS2557 = snd_soc_codec_get_drvdata(codec);
mutex_lock(&pTAS2557->codec_lock);
pValue->value.integer.value[0] = pTAS2557->mnCurrentConfiguration;
dev_dbg(pTAS2557->dev, "tas2557_configuration_get = %d\n",
pTAS2557->mnCurrentConfiguration);
mutex_unlock(&pTAS2557->codec_lock);
return 0;
}
static int tas2557_configuration_put(struct snd_kcontrol *pKcontrol,
struct snd_ctl_elem_value *pValue)
{
#ifdef KCONTROL_CODEC
struct snd_soc_codec *codec = snd_soc_kcontrol_codec(pKcontrol);
#else
struct snd_soc_codec *codec = snd_kcontrol_chip(pKcontrol);
#endif
struct tas2557_priv *pTAS2557 = snd_soc_codec_get_drvdata(codec);
unsigned int nConfiguration = pValue->value.integer.value[0];
int ret = 0;
mutex_lock(&pTAS2557->codec_lock);
dev_info(pTAS2557->dev, "%s = %d\n", __func__, nConfiguration);
ret = tas2557_set_config(pTAS2557, nConfiguration);
mutex_unlock(&pTAS2557->codec_lock);
return ret;
}
static int tas2557_calibration_get(struct snd_kcontrol *pKcontrol,
struct snd_ctl_elem_value *pValue)
{
#ifdef KCONTROL_CODEC
struct snd_soc_codec *codec = snd_soc_kcontrol_codec(pKcontrol);
#else
struct snd_soc_codec *codec = snd_kcontrol_chip(pKcontrol);
#endif
struct tas2557_priv *pTAS2557 = snd_soc_codec_get_drvdata(codec);
mutex_lock(&pTAS2557->codec_lock);
pValue->value.integer.value[0] = pTAS2557->mnCurrentCalibration;
dev_info(pTAS2557->dev,
"tas2557_calibration_get = %d\n",
pTAS2557->mnCurrentCalibration);
mutex_unlock(&pTAS2557->codec_lock);
return 0;
}
static int tas2557_calibration_put(struct snd_kcontrol *pKcontrol,
struct snd_ctl_elem_value *pValue)
{
#ifdef KCONTROL_CODEC
struct snd_soc_codec *codec = snd_soc_kcontrol_codec(pKcontrol);
#else
struct snd_soc_codec *codec = snd_kcontrol_chip(pKcontrol);
#endif
struct tas2557_priv *pTAS2557 = snd_soc_codec_get_drvdata(codec);
unsigned int nCalibration = pValue->value.integer.value[0];
int ret = 0;
mutex_lock(&pTAS2557->codec_lock);
ret = tas2557_set_calibration(pTAS2557, nCalibration);
mutex_unlock(&pTAS2557->codec_lock);
return ret;
}
static const char *const vendor_id_text[] = {"None", "AAC", "SSI", "GOER", "Unknown"};
static const struct soc_enum vendor_id[] = {
SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(vendor_id_text), vendor_id_text),
};
static const char *const pa_version_text[] = {"Unknown", "tas2557_v1.0", "tas2557_v2.0", "tas2557_v2.1"};
static const struct soc_enum pa_version[] = {
SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(pa_version_text), pa_version_text),
};
static const struct snd_kcontrol_new tas2557_snd_controls[] = {
SOC_SINGLE_EXT("PowerCtrl", SND_SOC_NOPM, 0, 0x0001, 0,
tas2557_power_ctrl_get, tas2557_power_ctrl_put),
SOC_SINGLE_EXT("Program", SND_SOC_NOPM, 0, 0x00FF, 0, tas2557_program_get,
tas2557_program_put),
SOC_SINGLE_EXT("Configuration", SND_SOC_NOPM, 0, 0x00FF, 0,
tas2557_configuration_get, tas2557_configuration_put),
SOC_SINGLE_EXT("FS", SND_SOC_NOPM, 8000, 48000, 0,
tas2557_fs_get, tas2557_fs_put),
SOC_SINGLE_EXT("Get Cali_Re", SND_SOC_NOPM, 0, 0x7f000000, 0,
tas2557_Cali_get, NULL),
SOC_SINGLE_EXT("Calibration", SND_SOC_NOPM, 0, 0x00FF, 0,
tas2557_calibration_get, tas2557_calibration_put),
SOC_ENUM_EXT("SPK ID", vendor_id, vendor_id_get, NULL),
SOC_ENUM_EXT("SmartPA Version", pa_version, pa_version_get, NULL),
SOC_SINGLE_EXT("SmartPA Mute", SND_SOC_NOPM, 0, 0x0001, 0,
tas2557_mute_ctrl_get, tas2557_mute_ctrl_put),
};
static struct snd_soc_codec_driver soc_codec_driver_tas2557 = {
.probe = tas2557_codec_probe,
.remove = tas2557_codec_remove,
.read = tas2557_codec_read,
.write = tas2557_codec_write,
.suspend = tas2557_codec_suspend,
.resume = tas2557_codec_resume,
.set_bias_level = tas2557_set_bias_level,
.idle_bias_off = true,
.component_driver = {
.controls = tas2557_snd_controls,
.num_controls = ARRAY_SIZE(tas2557_snd_controls),
.dapm_widgets = tas2557_dapm_widgets,
.num_dapm_widgets = ARRAY_SIZE(tas2557_dapm_widgets),
.dapm_routes = tas2557_audio_map,
.num_dapm_routes = ARRAY_SIZE(tas2557_audio_map),
},
};
static struct snd_soc_dai_ops tas2557_dai_ops = {
.startup = tas2557_startup,
.shutdown = tas2557_shutdown,
.digital_mute = tas2557_mute,
.hw_params = tas2557_hw_params,
.prepare = tas2557_prepare,
.set_sysclk = tas2557_set_dai_sysclk,
.set_fmt = tas2557_set_dai_fmt,
};
#define TAS2557_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
static struct snd_soc_dai_driver tas2557_dai_driver[] = {
{
.name = "tas2557 ASI1",
.id = 0,
.playback = {
.stream_name = "ASI1 Playback",
.channels_min = 2,
.channels_max = 2,
.rates = SNDRV_PCM_RATE_8000_192000,
.formats = TAS2557_FORMATS,
},
.ops = &tas2557_dai_ops,
.symmetric_rates = 1,
},
{
.name = "tas2557 ASI2",
.id = 1,
.playback = {
.stream_name = "ASI2 Playback",
.channels_min = 2,
.channels_max = 2,
.rates = SNDRV_PCM_RATE_8000_192000,
.formats = TAS2557_FORMATS,
},
.ops = &tas2557_dai_ops,
.symmetric_rates = 1,
},
{
.name = "tas2557 ASIM",
.id = 2,
.playback = {
.stream_name = "ASIM Playback",
.channels_min = 2,
.channels_max = 2,
.rates = SNDRV_PCM_RATE_8000_192000,
.formats = TAS2557_FORMATS,
},
.ops = &tas2557_dai_ops,
.symmetric_rates = 1,
},
};
int tas2557_register_codec(struct tas2557_priv *pTAS2557)
{
int nResult = 0;
dev_info(pTAS2557->dev, "%s, enter\n", __func__);
nResult = snd_soc_register_codec(pTAS2557->dev,
&soc_codec_driver_tas2557,
tas2557_dai_driver, ARRAY_SIZE(tas2557_dai_driver));
return nResult;
}
int tas2557_deregister_codec(struct tas2557_priv *pTAS2557)
{
snd_soc_unregister_codec(pTAS2557->dev);
return 0;
}
MODULE_AUTHOR("Texas Instruments Inc.");
MODULE_DESCRIPTION("TAS2557 ALSA SOC Smart Amplifier driver");
MODULE_LICENSE("GPL v2");
#endif
|
the_stack_data/1105895.c
|
#include <stdio.h>
int main()
{
char names[4][5] = {
"Ant",
"Bee",
"Cat",
"Duck"
};
int x;
names[2][2] = 'r';
for(x=0;x<4;x++)
printf("%s\n",names[x]);
return(0);
}
|
the_stack_data/134640.c
|
/*
* Copyright (c) 2007 - 2015 Joseph Gaeddert
*
* 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.
*/
//
// autotest fft data for 4-point transform
//
#include <complex.h>
float complex fft_test_x4[] = {
-2.218920151449 + -1.079004048069*_Complex_I,
0.045264423484 + 0.426155393025*_Complex_I,
0.218614474268 + -0.334711618319*_Complex_I,
2.182538230032 + 1.706944462070*_Complex_I};
float complex fft_test_y4[] = {
0.227496976335 + 0.719384188708*_Complex_I,
-3.718323694762 + 1.392981376798*_Complex_I,
-4.228108330697 + -3.546815521483*_Complex_I,
-1.156745556672 + -2.881566236299*_Complex_I};
|
the_stack_data/59514190.c
|
// REQUIRES: x86-registered-target
// UNSUPPORTED: windows, darwin, aix
// Generate dummy fat object
// RUN: %clang -O0 -target %itanium_abi_triple %s -c -o %t.host.o
// RUN: echo 'Content of device file' > %t.tgt.o
// RUN: clang-offload-bundler -type=o -targets=host-%itanium_abi_triple,openmp-%itanium_abi_triple -input=%t.host.o -input=%t.tgt.o -output=%t.fat.obj
// Then create a static archive with that object
// RUN: rm -f %t.fat.a
// RUN: llvm-ar cr %t.fat.a %t.fat.obj
// Unbundle device part from the archive. Check that bundler does not print warnings.
// RUN: clang-offload-bundler -unbundle -type=a -targets=openmp-%itanium_abi_triple -input=%t.fat.a -output=%t.tgt.a 2>&1 | FileCheck --allow-empty --check-prefix=CHECK-WARNING %s
// CHECK-WARNING-NOT: warning
// Check that device archive member inherited file extension from the original file.
// RUN: llvm-ar t %t.tgt.a | FileCheck --check-prefix=CHECK-ARCHIVE %s
// CHECK-ARCHIVE: {{\.obj$}}
void foo(void) {}
|
the_stack_data/132954179.c
|
#include <stdlib.h>
#include <stdio.h>
struct x
{
int x1;
short x2;
char x3;
struct x* next;
};
void nothing()
{
}
char inner_struct_elem(struct x *x1)
{
return x1->next->x3;
}
struct x* create_double_struct()
{
struct x* x1, *x2;
x1 = (struct x*)malloc(sizeof(struct x));
x2 = (struct x*)malloc(sizeof(struct x));
x1->next = x2;
x2->x2 = 3;
return x1;
}
void free_double_struct(struct x* x1)
{
free(x1->next);
free(x1);
}
const char *static_str = "xxxxxx";
const long static_int = 42;
const double static_double = 42.42;
unsigned short add_shorts(short one, short two)
{
return one + two;
}
void* get_raw_pointer()
{
return (void*)add_shorts;
}
char get_char(char* s, unsigned short num)
{
return s[num];
}
char *char_check(char x, char y)
{
if (y == static_str[0])
return static_str;
return NULL;
}
int get_array_elem(int* stuff, int num)
{
return stuff[num];
}
struct x* get_array_elem_s(struct x** array, int num)
{
return array[num];
}
long long some_huge_value()
{
return 1LL<<42;
}
unsigned long long some_huge_uvalue()
{
return 1LL<<42;
}
long long pass_ll(long long x)
{
return x;
}
static int prebuilt_array1[] = {3};
int* allocate_array()
{
return prebuilt_array1;
}
long long runcallback(long long(*callback)())
{
return callback();
}
struct x_y {
long x;
long y;
};
long sum_x_y(struct x_y s) {
return s.x + s.y;
}
struct s2h {
short x;
short y;
};
struct s2h give(short x, short y) {
struct s2h out;
out.x = x;
out.y = y;
return out;
}
struct s2h perturb(struct s2h inp) {
inp.x *= 2;
inp.y *= 3;
return inp;
}
|
the_stack_data/75138078.c
|
// RUN: %ucc -fsyntax-only %s
long a;
__typeof(-2147483648) a;
int b;
__typeof(-2147483647) b;
int c;
__typeof(2147483647) c;
long d;
__typeof(2147483648) d;
|
the_stack_data/807252.c
|
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
float lea_sq(float a, float b, float c)
{
float d1 = a - b;
float d2 = b - c;
float d3 = a - c;
return min(d1, d2);
}
int main()
{
printf("%f\n", lea_sq(12,2435, 543));
return 0;
}
|
the_stack_data/200142697.c
|
extern void __VERIFIER_error() __attribute__ ((__noreturn__));
void __VERIFIER_assert(int cond) { if(!(cond)) { ERROR: __VERIFIER_error(); } }
#define size 200
int main( )
{
int a[size];
int b[size];
int i = 1;
int j = 0;
while( i < size )
{
a[j] = b[i];
i = i+9;
j = j+1;
}
i = 1;
j = 0;
while( i < size )
{
__VERIFIER_assert( a[j] == b[9*j+1] );
i = i+9;
j = j+1;
}
return 0;
}
|
the_stack_data/18888027.c
|
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
/*
完全二叉树:从上到下,从左到右依次排列
从完全二叉树最后一个父节点构造堆 int parent=(last_node-1)/2;
调整堆
将堆的根元素与最后一个节点互换,输出,继续构造堆
*/
void swap(int tree[], int i, int j){
int temp=tree[i];
tree[i]=tree[j];
tree[j]=temp;
return;
}
void heapify(int tree[], int n, int i){
int parent = i;
int left=2*parent+1;
int right=2*parent+2;
int max = parent;
if(left<n && tree[max]<tree[left]){
max = left;
}
if(right<n && tree[max]<tree[right]){
max = right;
}
if(max != parent) {
swap(tree, parent, max);
heapify(tree, n, max);
}
return;
}
void build_heap(int tree[], int n){
int last_node=n-1;
int parent=(last_node-1)/2;
for(int i=parent;i>=0;i--){
heapify(tree, n, i);
}
return;
}
int main()
{
printf("Hello world!\n");
int tree[] = {2,5,3,1,10,4};
int n=6;
/*
for(int i=0;i<n;i++){
printf("%d ", tree[i]);
}
printf("\n");
build_heap(tree, n);
for(int i=0;i<n;i++){
printf("%d ", tree[i]);
}
printf("\n");
*/
for(int i=n;i>=1;i--){
build_heap(tree, i);
swap(tree, 0, i-1);
printf("%d ", tree[i-1]);
}
printf("\n");
return 0;
}
|
the_stack_data/158.c
|
/*
* AdventOfCode2020
* --- Day 2: Password Philosophy ---
* part1: 600
* Elapsed: 0.625000 ms
* part2: 245
* Elapsed: 0.693000 ms
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#define RECCOUNT 1000
#define DATA "../data/google-2.txt"
//#define DATA "./data.txt"
void part1(char d[][4][30] , int t);
void part2(char d[][4][30] , int t);
int main(int argc, char *argv[])
{
clock_t begin = clock();
// Load the data
// for this puzzle the data will be 1000 rows into 4 segment pieces
// begin, end, letter, password
// Array for 1000 lines, each with 4 strings, each string max 30 chars
// Adjust values as required.
char data[RECCOUNT][4][30];
FILE * fp;
int i = 0;
int tot = 0;
fp = fopen(DATA, "r");
if (fp == NULL) {
exit(EXIT_FAILURE);
}
char line[100];
while(fgets(line, sizeof(line) / sizeof(line[0]), fp) != NULL) {
// Rudimentary error checking - if the string has no newline
// there wasn't enough space in line
if (strchr(line, '\n') == NULL) {
printf("Line too long...");
exit(EXIT_FAILURE);
}
char *ptr1 = strtok(line, "-");
strcpy(data[i][0], ptr1);
char *ptr2 = strtok(NULL, " ");
strcpy(data[i][1], ptr2);
char *ptr3 = strtok(NULL, ": ");
strcpy(data[i][2], ptr3);
char *ptr4 = strtok(NULL, "\n");
strcpy(data[i][3], ptr4);
i++;
}
tot=i; // Unecessary - just use a different variable in your loop and use i as the upper bound
part1(data, tot);
clock_t end = clock();
printf("Elapsed: %f ms\n", (double)(end - begin) * 1000.0/ CLOCKS_PER_SEC);
part2(data, tot);
end = clock();
printf("Elapsed: %f ms\n", (double)(end - begin) * 1000.0/ CLOCKS_PER_SEC);
exit(EXIT_SUCCESS);
}
void part1(char d[][4][30] , int t)
{
//part1
int counter = 0;
for (int i=0;i<t;i++) {
// count occurances of letter in password
int count = 0;
// Get data in format we can use
int begin = atoi(d[i][0]);
int end = atoi(d[i][1]);
char toSearch[1] = {0};
strcpy(toSearch,d[i][2]);
char str0[30] = {0};
strcpy(str0,d[i][3]);
// Remove left character
char* str = str0 + 1;
//printf("%s|%s|",str,d[i][3]);
//for (int k=0;k<strlen(str);k++) {
// printf("%c", str[k]);
//}
// Count the number of matches in the string for letter
for (int k=0;k<strlen(str);k++) {
if(str[k]==toSearch[0]) {
//printf("Match:(%c)(%c)",str[k],toSearch[0]);
count++;
} else {
//printf("No Match:(%c)(%c)",str[k],toSearch[0]);
}
}
// Count where number of matches is in the defined range
if (count >= begin && count <= end) {
//printf("%d: %d %d %d\n",i,count,begin,end);
counter++;
} else {
//printf("%d: %d %d %d\n",i,count,begin,end);
}
}
printf("part1: %d\n", counter);
}
void part2(char d[][4][30] , int t)
{
// part2
// 1-3 a: abcde is valid: position 1 contains a and position 3 does not.
// 1-3 b: cdefg is invalid: neither position 1 nor position 3 contains b.
// 2-9 c: ccccccccc is invalid: both position 2 and position 9 contain c.
int counter = 0;
for (int i=0;i<t;i++) {
// count occurances of letter in password
// Get data in format we can use
int begin = atoi(d[i][0]);
int end = atoi(d[i][1]);
char toSearch[1] = {0};
strcpy(toSearch,d[i][2]);
char str0[30] = {0};
strcpy(str0,d[i][3]);
// Remove left character
char* str = str0 + 1;
// Count the number of matches in the string for letter
if(str[begin-1]==toSearch[0] ^ str[end-1]==toSearch[0]) {
//printf("Match:(%c)(%c)",str[k],toSearch[0]);
counter++;
} else {
//printf("No Match:(%c)(%c)",str[k],toSearch[0]);
}
}
printf("part2: %d\n", counter);
}
|
the_stack_data/57768.c
|
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
typedef int elementType;
typedef struct heap *ptrHeap;
struct heap
{
int heapSize;
elementType *data;
};
int parent(int i);
int left(int i);
int right(int i);
void exchange(elementType a[], int i, int j);
ptrHeap buildMaxHeap(elementType a[], const int count);
ptrHeap maxHeapIFY(ptrHeap maxHeap , int i);
elementType * heapSort(elementType a[], const int count);
elementType heapMaxMum(const ptrHeap maxHeap);
elementType heapExtractMax(ptrHeap maxHeap);
bool heapIncreaseKey(ptrHeap maxHeap, int i, elementType key);
int main()
{
int a[] = {5, 3, 17, 10, 84, 19, 6, 22, 9, 33, 22, 3, 23};
int count = sizeof(a) / sizeof(elementType);
ptrHeap maxHeap = buildMaxHeap(a, count);
// printf("%d\n", maxHeap[parent[2]]);
// printf("%d\n", heapExtractMax(maxHeap));
// heapIncreaseKey(maxHeap, 2, 100);
// elementType * sortA = heapSort(a, count);
// for (int i = 0; i < count; ++i)
// {
// printf("%d\n", sortA[i]);
// }
}
int parent(int i)
{
return (i > 1) ? (i - 1) / 2 : 0;
}
int left(int i)
{
return (i<<1) + 1;
}
int right(int i)
{
return (i<<1) + 2;
}
elementType* heapSort(elementType a[], const int count)
{
ptrHeap maxHeap = buildMaxHeap(a, count);
for (int i = count - 1; i >= 1; i--)
{
exchange(maxHeap->data, i, 0);
maxHeap->heapSize--;
maxHeapIFY(maxHeap, 0);
}
return maxHeap->data;
}
/**
* 建立最大堆
*/
ptrHeap buildMaxHeap(elementType a[], const int count)
{
ptrHeap maxHeap = (ptrHeap)malloc(sizeof(struct heap));
maxHeap->heapSize = count;
maxHeap->data = a;
for (int i = (count - 2)>>1; i >= 0; --i)
{
maxHeapIFY(maxHeap, i);
}
return maxHeap;
}
/**
* 维护最大堆的性质
*/
ptrHeap maxHeapIFY(ptrHeap maxHeap, int i)
{
int l = left(i);
int r = right(i);
int largest = i;
// find max value of i, l, r
if (l < maxHeap->heapSize && maxHeap->data[l] > maxHeap->data[i]) {
largest = l;
}
if (r < maxHeap->heapSize && maxHeap->data[r] > maxHeap->data[largest]) {
largest = r;
}
if (largest != i) {
// printf("%d %d \n", maxHeap->data[i], maxHeap->data[largest]);
exchange(maxHeap->data, i, largest);
return maxHeapIFY(maxHeap, largest);
}
return maxHeap;
}
/**
* 返回最大堆的最大值
*/
elementType heapMaxMum(const ptrHeap maxHeap)
{
if (maxHeap->heapSize == 0) {
return false;
}
return maxHeap->data[1];
}
/**
* 提取最大堆的的最大值
*/
elementType heapExtractMax(ptrHeap maxHeap)
{
if (maxHeap->heapSize == 0) {
return false;
}
elementType max = maxHeap->data[0];
maxHeap->heapSize--;
if (maxHeap->heapSize > 1) {
exchange(maxHeap->data, 0, maxHeap->heapSize - 1);
maxHeapIFY(maxHeap, 0);
}
return max;
}
/**
* 最大堆下标i增值
*/
bool heapIncreaseKey(ptrHeap maxHeap, int i, elementType key)
{
if (maxHeap->data[i] > key) {
return false;
}
int p;
while(i > 1 && (p = parent(i)) && maxHeap->data[p] < key) {
maxHeap->data[i] = maxHeap->data[p];
i = parent(i);
}
maxHeap->data[i] = key;
return true;
}
void exchange(elementType a[], int i, int j)
{
elementType tmp = a[i];
a[i] = a[j];
a[j] = tmp;
}
|
the_stack_data/20449154.c
|
#include <stdio.h>
#define N 5
void min_max_identifier(int values_vec[]){
int max = values_vec[0];
int min = values_vec[0];
for(int i =1; i<N; i++){
if(values_vec[i] > max){
max = values_vec[i];
}
if(values_vec[i] < min){
min = values_vec[i];
}
}
printf("Max: %d\n", max);
printf("Min: %d\n", min);
}
int main() {
int number_seq[N] = {1,-12,15,2,5};
min_max_identifier(number_seq);
return 0;
}
|
the_stack_data/36074896.c
|
#include<stdio.h>
int main(){
int A, B, C, D, DIFERENCA;
scanf("%d\n", &A);
scanf("%d\n", &B);
scanf("%d\n", &C);
scanf("%d", &D);
DIFERENCA = (A * B) - (C * D);
printf("DIFERENCA =%d\n", DIFERENCA);
return 0;
}
|
the_stack_data/1121108.c
|
#include<stdio.h>
#include<string.h>
int main() {
while(1)
{
char str[100];
scanf("%s", str);
char max_substr[100];
max_substr[0]='\0';
int l = strlen(str);
for(int i=0;i<l;i++)
{
for(int j=i+2;j<l;j++)
{
int flag=0;
char t = 'a';
for(int k=i;k<=(i+j)/2;k++)
{
if(str[k]>=t && str[k]==str[(i+j)-k])
{
t = str[k];
}
else
{
flag=1;
}
}
int start=0;
if(flag==0)
{
if((j-i+1)>strlen(max_substr))
{
for(int k=i;k<=j;k++)
max_substr[start++]=str[k];
max_substr[start]='\0';
}
else if((j-i+1)==strlen(max_substr))
{
for(int k=i;k<=j;k++)
{
if(max_substr[start]>str[k])
{
max_substr[start]=str[k];
}
start++;
}
}
}
}
}
if(strlen(max_substr)==0) printf("-1 \n");
else
printf("%s\n",max_substr);
}
return 0;
}
|
the_stack_data/90568.c
|
/* PROGRAM
* charcount count character input
*
* USAGE
* charcount
*
* FUNCTION
* charcount counts the number of character input until it's terminated.
* Since newline character, although not visible, is another character,
* the charcount in effect counts the number of lines and number of
* 'visible' character in it.
*
* EXAMPLE
* charcount
* some text
* 10
*
* BUGS
* Poor definitely of 'visible'. What about \t and \v?
*/
#include <stdio.h>
int c, count, nl;
main () {
count = 0;
nl = 0;
while ((c = getchar()) != EOF) {
if (c == '\n')
nl = 1;
else if (c == EOF)
;
else
nl = 0;
count +=1;
}
if (nl == 0)
printf("\n");
printf("%d\n", count);
}
|
the_stack_data/411408.c
|
/*
* C based implementtion of the FFT algorithm published in Numerical Recipes and other sources
*/
#include <math.h>
#define PI 3.1415296
#define SWAP(a,b) { double tempr = (a); (a)=(b); (b)=tempr; }
//data -> float array that represent the array of complex samples
//number_of_complex_samples -> number of samples (N^2 order number)
//isign -> 1 to calculate FFT and -1 to calculate Reverse FFT
void FFT (float data[], unsigned long number_of_complex_samples, int isign)
{
//variables for trigonometric recurrences
unsigned long n,mmax,m,j,istep,i;
double wtemp,wr,wpr,wpi,wi,theta,tempi, tempr;
//the complex array is real+complex so the array
//as a size n = 2* number of complex samples
// real part is the data[index] and the complex part is the data[index+1]
n=number_of_complex_samples * 2;
//binary inversion (note that
//the indexes start from 1 witch means that the
//real part of the complex is on the odd-indexes
//and the complex part is on the even-indexes
j = 1;
for (i = 1; i < n; i += 2)
{
if (j > i)
{
//swap the real part
SWAP(data[j], data[i]);
//swap the complex part
SWAP(data[j+1], data[i+1]);
}
m = n / 2;
while (m >= 2 && j > m)
{
j -= m;
m = m / 2;
}
j += m;
}
//the complex array is real+complex so the array
//as a size n = 2* number of complex samples
// real part is the data[index] and
//the complex part is the data[index+1]
n = number_of_complex_samples * 2;
//binary inversion (note that the indexes
//start from 0 witch means that the
//real part of the complex is on the even-indexes
//and the complex part is on the odd-indexes
j=0;
for (i = 0; i < n / 2; i += 2)
{
if (j > i)
{
//swap the real part
SWAP(data[j], data[i]);
//swap the complex part
SWAP(data[j+1], data[i+1]);
// checks if the changes occurs in the first half
// and use the mirrored effect on the second half
if ((j / 2) < (n / 4))
{
//swap the real part
SWAP(data[(n-(i+2))], data[(n-(j+2))]);
//swap the complex part
SWAP(data[(n-(i+2))+1], data[(n-(j+2))+1]);
}
}
m = n / 2;
while (m >= 2 && j >= m)
{
j -= m;
m = m / 2;
}
j += m;
}
//Danielson-Lanzcos routine
mmax = 2;
//external loop
while (n > mmax)
{
istep = mmax<< 1;
theta = isign*(2*PI / mmax);
wtemp = sin(0.5 * theta);
wpr = -2.0 * wtemp * wtemp;
wpi = sin(theta);
wr = 1.0;
wi = 0.0;
//internal loops
for (m = 1; m < mmax; m += 2)
{
for (i = m; i <= n; i += istep)
{
j = i + mmax;
tempr = wr * data[j-1] - wi * data[j];
tempi = wr * data[j] + wi * data[j-1];
data[j-1] = data[i-1] - tempr;
data[j] = data[i] - tempi;
data[i-1] += tempr;
data[i] += tempi;
}
wr = (wtemp = wr) * wpr - wi * wpi + wr;
wi = wi * wpr + wtemp * wpi + wi;
}
mmax = istep;
}
}
|
the_stack_data/548835.c
|
/*
* Copyright (C) 2004, 2005 Internet Systems Consortium, Inc. ("ISC")
* Copyright (C) 2000-2002 Internet Software Consortium.
*
* 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 ISC DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL ISC 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.
*/
/*
* $ISC: gssapi_link.c,v 1.1.6.3 2005/04/29 00:15:53 marka Exp $
*/
#ifdef GSSAPI
#include <config.h>
#include <isc/buffer.h>
#include <isc/mem.h>
#include <isc/string.h>
#include <isc/util.h>
#include <dst/result.h>
#include "dst_internal.h"
#include "dst_parse.h"
#include <gssapi/gssapi.h>
#define INITIAL_BUFFER_SIZE 1024
#define BUFFER_EXTRA 1024
#define REGION_TO_GBUFFER(r, gb) \
do { \
(gb).length = (r).length; \
(gb).value = (r).base; \
} while (0)
typedef struct gssapi_ctx {
isc_buffer_t *buffer;
gss_ctx_id_t *context_id;
} gssapi_ctx_t;
static isc_result_t
gssapi_createctx(dst_key_t *key, dst_context_t *dctx) {
gssapi_ctx_t *ctx;
isc_result_t result;
UNUSED(key);
ctx = isc_mem_get(dctx->mctx, sizeof(gssapi_ctx_t));
if (ctx == NULL)
return (ISC_R_NOMEMORY);
ctx->buffer = NULL;
result = isc_buffer_allocate(dctx->mctx, &ctx->buffer,
INITIAL_BUFFER_SIZE);
if (result != ISC_R_SUCCESS) {
isc_mem_put(dctx->mctx, ctx, sizeof(gssapi_ctx_t));
return (result);
}
ctx->context_id = key->opaque;
dctx->opaque = ctx;
return (ISC_R_SUCCESS);
}
static void
gssapi_destroyctx(dst_context_t *dctx) {
gssapi_ctx_t *ctx = dctx->opaque;
if (ctx != NULL) {
if (ctx->buffer != NULL)
isc_buffer_free(&ctx->buffer);
isc_mem_put(dctx->mctx, ctx, sizeof(gssapi_ctx_t));
dctx->opaque = NULL;
}
}
static isc_result_t
gssapi_adddata(dst_context_t *dctx, const isc_region_t *data) {
gssapi_ctx_t *ctx = dctx->opaque;
isc_buffer_t *newbuffer = NULL;
isc_region_t r;
unsigned int length;
isc_result_t result;
result = isc_buffer_copyregion(ctx->buffer, data);
if (result == ISC_R_SUCCESS)
return (ISC_R_SUCCESS);
length = isc_buffer_length(ctx->buffer) + data->length + BUFFER_EXTRA;
result = isc_buffer_allocate(dctx->mctx, &newbuffer, length);
if (result != ISC_R_SUCCESS)
return (result);
isc_buffer_usedregion(ctx->buffer, &r);
(void) isc_buffer_copyregion(newbuffer, &r);
(void) isc_buffer_copyregion(newbuffer, data);
isc_buffer_free(&ctx->buffer);
ctx->buffer = newbuffer;
return (ISC_R_SUCCESS);
}
static isc_result_t
gssapi_sign(dst_context_t *dctx, isc_buffer_t *sig) {
gssapi_ctx_t *ctx = dctx->opaque;
isc_region_t message;
gss_buffer_desc gmessage, gsig;
OM_uint32 minor, gret;
isc_buffer_usedregion(ctx->buffer, &message);
REGION_TO_GBUFFER(message, gmessage);
gret = gss_get_mic(&minor, ctx->context_id,
GSS_C_QOP_DEFAULT, &gmessage, &gsig);
if (gret != 0)
return (ISC_R_FAILURE);
if (gsig.length > isc_buffer_availablelength(sig)) {
gss_release_buffer(&minor, &gsig);
return (ISC_R_NOSPACE);
}
isc_buffer_putmem(sig, gsig.value, gsig.length);
gss_release_buffer(&minor, &gsig);
return (ISC_R_SUCCESS);
}
static isc_result_t
gssapi_verify(dst_context_t *dctx, const isc_region_t *sig) {
gssapi_ctx_t *ctx = dctx->opaque;
isc_region_t message;
gss_buffer_desc gmessage, gsig;
OM_uint32 minor, gret;
isc_buffer_usedregion(ctx->buffer, &message);
REGION_TO_GBUFFER(message, gmessage);
REGION_TO_GBUFFER(*sig, gsig);
gret = gss_verify_mic(&minor, ctx->context_id, &gmessage, &gsig, NULL);
if (gret != 0)
return (ISC_R_FAILURE);
return (ISC_R_SUCCESS);
}
static isc_boolean_t
gssapi_compare(const dst_key_t *key1, const dst_key_t *key2) {
gss_ctx_id_t gsskey1 = key1->opaque;
gss_ctx_id_t gsskey2 = key2->opaque;
/* No idea */
return (ISC_TF(gsskey1 == gsskey2));
}
static isc_result_t
gssapi_generate(dst_key_t *key, int unused) {
UNUSED(key);
UNUSED(unused);
/* No idea */
return (ISC_R_FAILURE);
}
static isc_boolean_t
gssapi_isprivate(const dst_key_t *key) {
UNUSED(key);
return (ISC_TRUE);
}
static void
gssapi_destroy(dst_key_t *key) {
UNUSED(key);
/* No idea */
}
static dst_func_t gssapi_functions = {
gssapi_createctx,
gssapi_destroyctx,
gssapi_adddata,
gssapi_sign,
gssapi_verify,
NULL, /*%< computesecret */
gssapi_compare,
NULL, /*%< paramcompare */
gssapi_generate,
gssapi_isprivate,
gssapi_destroy,
NULL, /*%< todns */
NULL, /*%< fromdns */
NULL, /*%< tofile */
NULL, /*%< parse */
NULL, /*%< cleanup */
};
isc_result_t
dst__gssapi_init(dst_func_t **funcp) {
REQUIRE(funcp != NULL);
if (*funcp == NULL)
*funcp = &gssapi_functions;
return (ISC_R_SUCCESS);
}
#else
int gssapi_link_unneeded = 1;
#endif
/*! \file */
|
the_stack_data/22013564.c
|
#include <stdio.h>
#include<stdlib.h>
void findNearest(int *a,int n,int k,int c);
int binarySearch(int *a,int n,int k);
int main() {
int t;
int *a;
int n,c;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
a = (int *)malloc(n*sizeof(int));
int i;
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
int k;
scanf("%d",&c);
scanf("%d",&k);
findNearest(a,n,k,c);
}
return 0;
}
void findNearest(int *a,int n,int k,int c)
{
int pos = binarySearch(a,n,k);
int x = c;
int rdiff = a[pos+1] - a[pos];
int r = pos+1;
int l = pos-1;
int ldiff = a[pos] - a[pos-1];
while(x>0)
{
rdiff = a[pos+r] - a[pos];
ldiff = a[pos] - a[pos-l];
if(rdiff<=ldiff && r<n)
{
printf("%d ",a[r]);
r++;
}
else
{
printf("%d ",a[l]);
l--;
}
x--;
}
while(x>0 && l>=0)
{
printf("%d ",a[l]);
l--;
x--;
}
while(x>0 && r<n)
{
printf("%d ",a[r]);
r++;
x--;
}
}
int binarySearch(int *a,int n,int k)
{
int beg = 0,end=n-1;
int mid;
while(beg<=end)
{
mid = (beg+end)/2;
if(a[mid]==k)
{
return mid;
}
else if(a[mid]<k)
{
beg=mid+1;
}
else
{
end = mid-1;
}
}
}
|
the_stack_data/48624.c
|
#include <stdio.h>
int main() {
long long A;
double B;
scanf("%lld %lf", &A, &B);
printf("%lld\n", A * (int)(B * 100 + 0.5) / 100);
}
|
the_stack_data/140395.c
|
/**
* \file
* \brief [Problem 2](https://projecteuler.net/problem=2) solution
*
* Problem:
*
* Each new term in the Fibonacci sequence is generated by adding the previous
* two terms. By starting with 1 and 2, the first 10 terms will be:
* `1,2,3,5,8,13,21,34,55,89,..`
* By considering the terms in the Fibonacci sequence whose values do not exceed
* n, find the sum of the even-valued terms. e.g. for n=10, we have {2,8}, sum
* is 10.
*/
#include <stdio.h>
/** Main function */
int main()
{
int n = 0;
int sum = 0;
int i = 1;
int j = 2;
int temp;
scanf("%d", &n);
while (j <= n)
{
if ((j & 1) == 0) // can also use(j%2 == 0)
sum += j;
temp = i;
i = j;
j = temp + i;
}
printf("%d\n", sum);
return 0;
}
|
the_stack_data/1037031.c
|
#include <stdio.h>
#define N 5 // 정점 수
#define INF 100
void floyd2(int n, const int(*W)[N+1], int(*D)[N+1], int(*P)[N+1]) {
int i, j, k;
for (i = 1; i <= n; i++) {
for (j = 1; j <= n; j++) {
P[i][j] = 0; //배열 P초기화
}
}
for (i = 1; i <= n; i++) {
for (j = 1; j <= n; j++) {
D[i][j] = W[i][j];
}
}
for (k = 1; k <= n; k++) {
for (i = 1; i <= n; i++) {
for (j = 1; j <= n; j++) {
if (D[i][k] + D[k][j] < D[i][j]) {
P[i][j] = k;
D[i][j] = D[i][k] + D[k][j];
}
}
}
}
}
void path(int(*P)[N+1], int q, int r) {
if (P[q][r] != 0) {
path(P, q, P[q][r]);
printf("v%d -> ", P[q][r]);
path(P,P[q][r], r);
}
}
int main(void) {
// W 값
int W[N+1][N+1] = {
{0,0,0,0,0,0},
{0,0,1,INF,1,5},
{0,9,0,3,2,INF},
{0,INF,INF,0,4,INF},
{0,INF,INF,2,0,3},
{0,3,INF,INF,INF,0}
};
int D[N+1][N+1];
int P[N+1][N+1];
floyd2(N, W, D, P);
printf("D[i][j] is \n");
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= N; j++) {
printf("%3d", D[i][j]);
}
printf("\n");
}
printf("\nP[i][j] is \n");
for (int i = 1; i <= N; i++){
for (int j = 1; j <= N; j++) {
printf("%3d", P[i][j]);
}
printf("\n");
}
int start, end;
start = 5;
end = 3;
printf("\nThe shortest path(%d, %d) is", start, end);
printf(" v%d -> ", start);
path(P, start, end);
printf("v%d\n", end);
return 0;
}
|
the_stack_data/181393772.c
|
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv)
{
char *cc=argv[1];
int c = atoi(cc);
if (c>0) {
printf("\n c>0");
}
return 0;
}
|
the_stack_data/911220.c
|
#include <stdio.h>
int main(){
//variables
int n, a, b;
//input
printf("Digite um numero: ");
scanf("%d",&n);
//process
if (n > 0){
a = n;
printf("O numero %d e positivo",a);
}else{
b = n;
printf("O numero %d e negativo",b);
}
}
|
the_stack_data/465096.c
|
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char* argv[], char* envp[] ){
printf("In init\n");
char *arg_v[]= {"bin/hello1", NULL};
char *env_p[] = {"PATH=/rootfs/bin","CWD=/rootfs",NULL};
int pid=fork();
if (pid == 0) {
execve("bin/hello1", arg_v,env_p);
} else {
waitpid(pid, 0, 0);
}
return 1;
}
|
the_stack_data/245326.c
|
/*Praticando by: Oliveira, Álisson - Graduando em Ciências da Computação
ENUNCIADO: Crie um algoritmo onde é declarada um registro com a marca, fabrica e quantidade.
Na função principal uma variável heterogênea deverá ser declarada e seus valores atribuídos pelo usuário.
Em seguida, as informações deverão ser impressas na tela.
*/
#include <stdlib.h>
#include <stdio.h>
struct dados
{
char fabrica[20];
char marca[20];
int quantidade;
};
int main(){
struct dados produto;
printf("Digite o nome da fabrica que fornecera o produto: \n");
scanf("%s",&produto.fabrica);
printf("Digite a marca do produto: \n");
scanf("%s",&produto.marca);
printf("Digite a quantidade: \n");
scanf("%d",&produto.quantidade);
printf("A fabrica fornecedora eh: %s\nA marca do produto eh: %s\nE a quantidade requerida foi: %d\n\n", produto.fabrica, produto.marca, produto.quantidade);
return 0;
}
|
the_stack_data/198581439.c
|
#include <stdio.h>
int main(int argc, char *argv[])
{
int index = atoi(argv[1]);
char **ptr = argv + index;
return 0;
}
|
the_stack_data/182952642.c
|
/* Copyright (c) 2016, Dennis Wölfing
*
* 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.
*/
/* libc/src/errno/initProgname.c
* Initializes the program name.
*/
#include <errno.h>
char* program_invocation_name;
char* program_invocation_short_name;
void __initProgname(char* argv[]) {
program_invocation_name = argv[0] ? argv[0] : "";
program_invocation_short_name = program_invocation_name;
// Get the last part of argv[0].
char* s = program_invocation_name;
while (*s) {
if (*s++ == '/') {
program_invocation_short_name = s;
}
}
}
|
the_stack_data/1173158.c
|
/*Get Help:
* man 2 sendfile
* */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
int main(int argc, char **argv)
{
int fd1;
int fd2;
int ret;
char buf[20];
/*Open source file*/
if((fd1 = open("file1.txt", O_RDONLY)) <0)
{
perror("open() read");
exit(1);
}
/*Open destination file*/
if((fd2 = open("file2.txt", O_CREAT | O_WRONLY, 0600)) < 0)
{
perror("open() write");
close(fd1);
exit(1);
}
while((ret = read(fd1, buf, 20)) > 0)
{
if(write(fd2, buf, ret) < 0)
{
perror("write");
exit(1);
}
}
close(fd1);
close(fd2);
return 0;
}
|
the_stack_data/11075831.c
|
#include <stdio.h>
int main(void) {
int n, a, p, s, i;
int v[10000];
while (scanf("%d", &n) && n != 0) {
for (i = 0; i < n; ++i)
scanf("%d", &v[i]);
a = (v[n-1] < v[0]) ? 1 : 0;
p = 0;
for (i = 1; i < n; ++i) {
if (v[i-1] < v[i]) s = 1;
else s = 0;
if (s != a) ++p;
a = s;
}
if (v[n-1] < v[0]) s = 1;
else s = 0;
if (s != a) ++p;
printf("%d\n", p);
}
return 0;
}
|
the_stack_data/151707039.c
|
/*
* I used to have some hash functions here, but they were all
* really bad! Use the one at
* https://github.com/hathix/cs50-section/blob/master/code/7/sample-hash-functions/good-hash-function.c
* instead.
*/
|
the_stack_data/592761.c
|
void matmult_mnk(int M, int N, int K, double **A, double **B, double **C) {
// init C matrix
for (int l = 0; l < M*N; l++) {
C[0][l] = 0;
}
// do calculations
for (int m = 0; m < M; m++) {
for (int n = 0; n < N; n++) {
for (int k = 0; k < K; k++) {
C[m][n] += A[m][k] * B[k][n];
}
}
}
}
|
the_stack_data/75138133.c
|
//*****************************************************************************
//
// startup_gcc.c - Startup code for use with GNU tools.
//
// Copyright (c) 2005-2011 Texas Instruments Incorporated. All rights reserved.
// Software License Agreement
//
// Texas Instruments (TI) is supplying this software for use solely and
// exclusively on TI's microcontroller products. The software is owned by
// TI and/or its suppliers, and is protected under applicable copyright
// laws. You may not combine this software with "viral" open-source
// software in order to form a larger program.
//
// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
// DAMAGES, FOR ANY REASON WHATSOEVER.
//
// This is part of revision 6852 of the EK-LM3S1968 Firmware Package.
//
//*****************************************************************************
//*****************************************************************************
//
// Forward declaration of the default fault handlers.
//
//*****************************************************************************
void ResetISR(void);
static void NmiSR(void);
static void FaultISR(void);
static void IntDefaultHandler(void);
//*****************************************************************************
//
// External declaration for the interrupt handler used by the application.
//
//*****************************************************************************
extern void WatchdogIntHandler(void);
//*****************************************************************************
//
// The entry point for the application.
//
//*****************************************************************************
extern int main(void);
//*****************************************************************************
//
// Reserve space for the system stack.
//
//*****************************************************************************
static unsigned long pulStack[64];
//*****************************************************************************
//
// The vector table. Note that the proper constructs must be placed on this to
// ensure that it ends up at physical address 0x0000.0000.
//
//*****************************************************************************
__attribute__ ((section(".isr_vector")))
void (* const g_pfnVectors[])(void) =
{
(void (*)(void))((unsigned long)pulStack + sizeof(pulStack)),
// The initial stack pointer
ResetISR, // The reset handler
NmiSR, // The NMI handler
FaultISR, // The hard fault handler
IntDefaultHandler, // The MPU fault handler
IntDefaultHandler, // The bus fault handler
IntDefaultHandler, // The usage fault handler
0, // Reserved
0, // Reserved
0, // Reserved
0, // Reserved
IntDefaultHandler, // SVCall handler
IntDefaultHandler, // Debug monitor handler
0, // Reserved
IntDefaultHandler, // The PendSV handler
IntDefaultHandler, // The SysTick handler
IntDefaultHandler, // GPIO Port A
IntDefaultHandler, // GPIO Port B
IntDefaultHandler, // GPIO Port C
IntDefaultHandler, // GPIO Port D
IntDefaultHandler, // GPIO Port E
IntDefaultHandler, // UART0 Rx and Tx
IntDefaultHandler, // UART1 Rx and Tx
IntDefaultHandler, // SSI0 Rx and Tx
IntDefaultHandler, // I2C0 Master and Slave
IntDefaultHandler, // PWM Fault
IntDefaultHandler, // PWM Generator 0
IntDefaultHandler, // PWM Generator 1
IntDefaultHandler, // PWM Generator 2
IntDefaultHandler, // Quadrature Encoder 0
IntDefaultHandler, // ADC Sequence 0
IntDefaultHandler, // ADC Sequence 1
IntDefaultHandler, // ADC Sequence 2
IntDefaultHandler, // ADC Sequence 3
WatchdogIntHandler, // Watchdog timer
IntDefaultHandler, // Timer 0 subtimer A
IntDefaultHandler, // Timer 0 subtimer B
IntDefaultHandler, // Timer 1 subtimer A
IntDefaultHandler, // Timer 1 subtimer B
IntDefaultHandler, // Timer 2 subtimer A
IntDefaultHandler, // Timer 2 subtimer B
IntDefaultHandler, // Analog Comparator 0
IntDefaultHandler, // Analog Comparator 1
IntDefaultHandler, // Analog Comparator 2
IntDefaultHandler, // System Control (PLL, OSC, BO)
IntDefaultHandler, // FLASH Control
IntDefaultHandler, // GPIO Port F
IntDefaultHandler, // GPIO Port G
IntDefaultHandler, // GPIO Port H
IntDefaultHandler, // UART2 Rx and Tx
IntDefaultHandler, // SSI1 Rx and Tx
IntDefaultHandler, // Timer 3 subtimer A
IntDefaultHandler, // Timer 3 subtimer B
IntDefaultHandler, // I2C1 Master and Slave
IntDefaultHandler, // Quadrature Encoder 1
IntDefaultHandler, // CAN0
IntDefaultHandler, // CAN1
IntDefaultHandler, // CAN2
IntDefaultHandler, // Ethernet
IntDefaultHandler // Hibernate
};
//*****************************************************************************
//
// The following are constructs created by the linker, indicating where the
// the "data" and "bss" segments reside in memory. The initializers for the
// for the "data" segment resides immediately following the "text" segment.
//
//*****************************************************************************
extern unsigned long _etext;
extern unsigned long _data;
extern unsigned long _edata;
extern unsigned long _bss;
extern unsigned long _ebss;
//*****************************************************************************
//
// This is the code that gets called when the processor first starts execution
// following a reset event. Only the absolutely necessary set is performed,
// after which the application supplied entry() routine is called. Any fancy
// actions (such as making decisions based on the reset cause register, and
// resetting the bits in that register) are left solely in the hands of the
// application.
//
//*****************************************************************************
void
ResetISR(void)
{
unsigned long *pulSrc, *pulDest;
//
// Copy the data segment initializers from flash to SRAM.
//
pulSrc = &_etext;
for(pulDest = &_data; pulDest < &_edata; )
{
*pulDest++ = *pulSrc++;
}
//
// Zero fill the bss segment.
//
__asm(" ldr r0, =_bss\n"
" ldr r1, =_ebss\n"
" mov r2, #0\n"
" .thumb_func\n"
"zero_loop:\n"
" cmp r0, r1\n"
" it lt\n"
" strlt r2, [r0], #4\n"
" blt zero_loop");
//
// Call the application's entry point.
//
main();
}
//*****************************************************************************
//
// This is the code that gets called when the processor receives a NMI. This
// simply enters an infinite loop, preserving the system state for examination
// by a debugger.
//
//*****************************************************************************
static void
NmiSR(void)
{
//
// Enter an infinite loop.
//
while(1)
{
}
}
//*****************************************************************************
//
// This is the code that gets called when the processor receives a fault
// interrupt. This simply enters an infinite loop, preserving the system state
// for examination by a debugger.
//
//*****************************************************************************
static void
FaultISR(void)
{
//
// Enter an infinite loop.
//
while(1)
{
}
}
//*****************************************************************************
//
// This is the code that gets called when the processor receives an unexpected
// interrupt. This simply enters an infinite loop, preserving the system state
// for examination by a debugger.
//
//*****************************************************************************
static void
IntDefaultHandler(void)
{
//
// Go into an infinite loop.
//
while(1)
{
}
}
|
the_stack_data/413810.c
|
/** time the function execution */
#include <stdio.h>
#include <time.h>
#include <unistd.h>
/** Calls <sleep> for <seconds>. */
void sleep_for(int seconds);
int main()
{
time_t begin = time(NULL);
sleep_for(3);
time_t end = time(NULL);
printf("%lds\n", end - begin);
return 0;
}
void sleep_for(int seconds)
{
sleep(seconds);
}
|
the_stack_data/92970.c
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ksticks <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/06/10 17:16:52 by ksticks #+# #+# */
/* Updated: 2019/06/10 17:16:54 by ksticks ### ########.fr */
/* */
/* ************************************************************************** */
int ft_strncmp(char *s1, char *s2, unsigned int n)
{
while (n--)
{
if (*s1 - *s2)
return (*s1 - *s2);
if (!(*s1 && *s2))
break ;
s1++;
s2++;
}
return (0);
}
|
the_stack_data/135483.c
|
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
// Each changes need to compile.
int main(){
int integerValue;
float floatValue;
char letter = 'M';
// double doubleValue = 5.10;
// bool booleanValue = false;
// Inputs.
printf("Enter Integer value: "); //Integer.
scanf("%i", &integerValue); //We use '&' to indicate the place to save the info (variable).
printf("Enter Float value: "); //Float.
scanf("%f", &floatValue);
printf("Enter Char value: "); //Char.
scanf(" %c", &letter);
// Outputs.
printf("\nInteger variable value is: %i\n", integerValue);
printf("Float variable value is: %f\n", floatValue);
printf("Char variable value is: %c\n", letter);
// printf("Double variable value is: %f\n", doubleValue);
return 0;
}
|
the_stack_data/352197.c
|
/* Verify that TST #imm, R0 instruction is generated when the tested reg
is shifted by a constant amount. */
/* { dg-do compile } */
/* { dg-options "-O2" } */
/* { dg-final { scan-assembler-not "and|shl|sha|exts" } } */
/* { dg-final { scan-assembler-times "tst\t#7,r0" 3 } } */
/* { dg-final { scan-assembler-times "tst\t#12,r0" 1 } } */
/* { dg-final { scan-assembler-times "tst\t#24,r0" 6 } } */
/* { dg-final { scan-assembler-times "tst\t#13,r0" 3 } } */
/* { dg-final { scan-assembler-times "tst\t#242,r0" 3 } } */
/* { dg-final { scan-assembler-times "tst\t#252,r0" 1 } } */
/* { dg-final { scan-assembler-times "tst\t#64,r0" 6 { target { ! sh2a } } } } */
/* { dg-final { scan-assembler-times "tst\t#64,r0" 4 { target { sh2a } } } } */
/* { dg-final { scan-assembler-times "bld\t#6" 2 { target { sh2a } } } } */
int
test_00 (unsigned char* x, int y, int z)
{
/* 1x tst #12 */
return (x[0] << 4) & 192 ? y : z;
}
int
test_01 (unsigned char* x, int y, int z)
{
/* 1x tst #24 */
return (x[0] << 3) & 192 ? y : z;
}
int
test_02 (unsigned char* x, int y, int z)
{
/* 1x tst #24 */
return ((x[0] << 3) & 192) != 0;
}
int
test_03 (unsigned char* x, int y, int z)
{
/* 1x tst #24 */
return ((x[0] << 3) & 192) == 0;
}
int
test_04 (unsigned char x, int y, int z)
{
/* 1x tst #24 */
return (x << 3) & 192 ? y : z;
}
int
test_05 (unsigned char x, int y, int z)
{
/* 1x tst #24 */
return ((x << 3) & 192) != 0;
}
int
test_06 (unsigned char x, int y, int z)
{
/* 1x tst #24 */
return ((x << 3) & 192) == 0;
}
int
test_07 (unsigned char x, int y, int z)
{
/* 1x tst #13 */
return (x << 3) & 111 ? y : z;
}
int
test_08 (unsigned char x, int y, int z)
{
/* 1x tst #13 */
return ((x << 3) & 111) != 0;
}
int
test_09 (unsigned char x, int y, int z)
{
/* 1x tst #13 */
return ((x << 3) & 111) == 0;
}
int
test_10 (unsigned char x, int y, int z)
{
/* 1x tst #242 */
return (x << 3) & -111 ? y : z;
}
int
test_11 (unsigned char x, int y, int z)
{
/* 1x tst #242 */
return ((x << 3) & -111) != 0;
}
int
test_12 (unsigned char x, int y, int z)
{
/* 1x tst #242 */
return ((x << 3) & -111) == 0;
}
int
test_13 (unsigned char* x, int y, int z)
{
/* 1x tst #64 */
return (x[0] >> 2) & 16 ? y : z;
}
int
test_14 (unsigned char* x, int y, int z)
{
/* 1x tst #64 / 1x bld #6*/
return ((x[0] >> 2) & 16) != 0;
}
int
test_15 (unsigned char* x, int y, int z)
{
/* 1x tst #64 */
return ((x[0] >> 2) & 16) == 0;
}
int
test_16 (unsigned char x, int y, int z)
{
/* 1x tst #64 */
return (x >> 2) & 16 ? y : z;
}
int
test_17 (unsigned char x, int y, int z)
{
/* 1x tst #64 / 1x bld #6*/
return ((x >> 2) & 16) != 0;
}
int
test_18 (unsigned char x, int y, int z)
{
/* 1x tst #64 */
return ((x >> 2) & 16) == 0;
}
int
test_19 (signed char x, int y, int z)
{
/* 1x tst #7 */
return (x << 1) & 0x0F ? y : z;
}
int
test_20 (signed char x, int y, int z)
{
/* 1x tst #7 */
return ((x << 1) & 0x0F) != 0;
}
int
test_21 (signed char x, int y, int z)
{
/* 1x tst #7 */
return ((x << 1) & 0x0F) == 0;
}
int
test_22 (unsigned char* x, int y, int z)
{
/* 1x tst #252 */
return (x[0] >> 2) ? y : z;
}
|
the_stack_data/98576171.c
|
// The MIT License (MIT)
//
// Copyright (c) 2020 Trevor Bakker
//
// 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 _GNU_SOURCE
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <signal.h>
#include <stdint.h>
#include <ctype.h>
#include <unistd.h>
#define MAX_NUM_ARGUMENTS 4
#define NUM_ENTRIES 16
#define WHITESPACE " \t\n" // We want to split our command line up into tokens
// so we need to define what delimits our tokens.
// In this case white space
// will separate the tokens on our command line
#define MAX_COMMAND_SIZE 255 // The maximum command-line size
// BPB: BIOS Parmeter Block - located in the first sector of the reserved sectors
char BS_OEMName[8];
char BS_VolLab[11];
int8_t BPB_SecPerClus;
int8_t BPB_NumFATs;
int16_t BPB_RootEntCnt;
int16_t BPB_BytesPerSec;
int16_t BPB_RsvdSecCnt;
int32_t BPB_FATSz32;
int32_t BPB_RootClus;
int32_t RootDirSectors = 0;
int32_t FirstDataSector = 0;
int32_t FirstSectorofCluster = 0;
FILE *fp;
int file_open = 0;
// Each record can be represented by the struct below
struct __attribute__((__packed__)) DirectoryEntry{
char DIR_Name[11];
uint8_t DIR_Attr;
uint8_t Unused1[8];
uint8_t Unused2[4];
uint16_t DIR_FirstClusterHigh;
uint16_t DIR_FirstClusterLow;
uint32_t DIR_FileSize;
};
struct DirectoryEntry dir[16];
/*
*Function : LBAToOffset
*Parameters : The current sector number that points to a block of data
*Returns : The value of the address for that block of data
*Description : Finds the starting address of a block of data given the sector number corresponding to that data block
*/
int LBAToOffset(int32_t sector)
{
return ( (sector - 2) * BPB_BytesPerSec ) + (BPB_BytesPerSec * BPB_RsvdSecCnt) + (BPB_NumFATs * BPB_FATSz32 * BPB_BytesPerSec);
}
/*
Name: NextLB
Parameters: Given a logical block address, look up into the first FAT and return the logical block address of the block in the file. If there is no futher
blocks then return -1;
*/
int16_t NextLB(uint32_t sector)
{
uint32_t FATAddress = (BPB_BytesPerSec * BPB_RsvdSecCnt) + (sector * 4);
int16_t val;
fseek( fp, FATAddress, SEEK_SET);
fread( &val, 2, 1, fp);
return val;
}
int compare(char *userString, char *directoryString)
{
char *dotdot = "..";
if (strncmp(dotdot, userString, 2) == 0)
{
if (strncmp(userString, directoryString, 2) == 0)
{
return 1;
}
return 0;
}
char IMG_Name[12];
strncpy(IMG_Name, directoryString, 11);
IMG_Name[11] = '\0';
char input[11];
memset(input, 0, 11);
strncpy(input, userString, strlen(userString));
char expanded_name[12];
memset(expanded_name, ' ', 12);
char *token = strtok(input, ".");
strncpy(expanded_name, token, strlen(token));
token = strtok(NULL, ".");
if (token)
{
strncpy((char *)(expanded_name + 8), token, strlen(token));
}
expanded_name[11] = '\0';
int i;
for (i = 0; i < 11; i++)
{
expanded_name[i] = toupper(expanded_name[i]);
}
if (strncmp(expanded_name, IMG_Name, 11) == 0)
{
return 1;
}
return 0;
}
/*
*Name : info
*Parameters : None
*Returns : int
*Description: prints the informatin about BPB
*/
int info()
{
printf("BPB_BytsPerSec: %d\nBPB_BytsPerSec: %.4x\n", BPB_BytesPerSec, BPB_BytesPerSec); //512
printf("BPB_SecPerClus: %d\nBPB_SecPerClus: %.4x\n", BPB_SecPerClus, BPB_FATSz32); //1
printf("BPB_RsvdSecCnt: %d\nBPB_RsvdSecCnt: %.4x\n", BPB_RsvdSecCnt, BPB_FATSz32); //32
printf("BPB_NumFATs: %d\nBPB_NumFATs: %.4x\n", BPB_NumFATs, BPB_FATSz32);
printf("BPB_FATSz32: %d\nBPB_FATSz32: %.4x\n", BPB_FATSz32, BPB_FATSz32);
return 0;
}
/*
*Name : ls
*Parameters : None
*Returns : int
*Description: List contents in the directory execept for deleted and system files
*/
int ls()
{
int i ;
for(i = 0; i < NUM_ENTRIES; i++)
{
char filename[12];
strncpy(filename, dir[i].DIR_Name, 11);
// Do not list deleted files or system volme names
if((dir[i].DIR_Attr == 0x01 || dir[i].DIR_Attr == 0x10 || dir[i].DIR_Attr == 0x20 ) && filename[0] != 0xffffffe5)
{
printf("%s\n",filename);
}
}
return 0;
}
/*
*Name : readfile
*Parameters : filename, requested off set, requested bytes
*Returns : Outputs the bytes in hexadecimal
*Description: Reads from a given file at the position (in bytes) specified by the position parameter and output the number of bytes specified.
*/
int readfile(char *filename, int requestedOffset, int requestedBytes)
{
int i;
int found = 0;
int bytesRemainingToRead = requestedBytes;
if (requestedOffset < 0)
{
printf("Error: Offset is less than zero");
}
for (i = 0; i < NUM_ENTRIES; i++)
{
if (compare(filename, dir[i].DIR_Name))
{
int cluster = dir[i].DIR_FirstClusterLow;
found = 1;
int searchSize = requestedOffset;
while (searchSize >= BPB_BytesPerSec)
{
cluster = NextLB(cluster);
searchSize = searchSize - BPB_BytesPerSec;
}
int offset = LBAToOffset(cluster);
int byteOffset = (requestedOffset % BPB_BytesPerSec);
fseek(fp, offset + byteOffset, SEEK_SET);
unsigned char buffer[BPB_BytesPerSec];
int firstblockbytes = BPB_BytesPerSec - requestedOffset;
fread(buffer, 1, firstblockbytes, fp);
for (i = 0; i < firstblockbytes; i++)
{
printf("%x ", buffer[i]);
}
bytesRemainingToRead = bytesRemainingToRead - firstblockbytes;
while (bytesRemainingToRead >= 512)
{
cluster = NextLB(cluster);
offset = LBAToOffset(cluster);
fseek(fp, offset, SEEK_SET);
fread(buffer, 1, BPB_BytesPerSec, fp);
for (i = 0; i < BPB_BytesPerSec; i++)
{
printf("%x ", buffer[i]);
}
bytesRemainingToRead = bytesRemainingToRead - BPB_BytesPerSec;
}
if (bytesRemainingToRead)
{
cluster = NextLB(cluster);
offset = LBAToOffset(cluster);
fseek(fp, offset, SEEK_SET);
fread(buffer, 1, BPB_BytesPerSec, fp);
for (i = 0; i < bytesRemainingToRead; i++)
{
printf("%x ", buffer[i]);
}
}
printf("\n");
}
}
if (!found)
{
printf("Error: File was not Found\n");
return -1;
}
return 0;
}
/*
*Name : cd
*Parameters : Directory the user chooses to go into
*Returns : 0 upon success and -1 upon failure
*Description: Command that will change the working directory to the given directory. (Supports cd ../name)
*/
int cd(char *directoryName)
{
int i;
int found = 0;
for (i = 0; i < NUM_ENTRIES; i++)
{
if (compare(directoryName, dir[i].DIR_Name))
{
int cluster = dir[i].DIR_FirstClusterLow;
if (cluster == 0)
{
cluster = 2;
}
int offset = LBAToOffset(cluster);
fseek(fp, offset, SEEK_SET);
fread(dir, sizeof(struct DirectoryEntry), NUM_ENTRIES, fp);
found = 1;
break;
}
}
if (!found)
{
printf("Error Directory Wasn't found\n");
return -1;
}
return 0;
}
int main()
{
char * cmd_str = (char*) malloc( MAX_COMMAND_SIZE );
while( 1 )
{
// Print out the mfs prompt
printf ("mfs> ");
// Read the command from the commandline. The
// maximum command that will be read is MAX_COMMAND_SIZE
// This while command will wait here until the user
// inputs something since fgets returns NULL when there
// is no input
while( !fgets (cmd_str, MAX_COMMAND_SIZE, stdin) );
/* Parse input */
char *token[MAX_NUM_ARGUMENTS];
int token_count = 0;
// Pointer to point to the token
// parsed by strsep
char *arg_ptr;
char *working_str = strdup( cmd_str );
// we are going to move the working_str pointer so
// keep track of its original value so we can deallocate
// the correct amount at the end
char *working_root = working_str;
// Tokenize the input stringswith whitespace used as the delimiter
while ( ( (arg_ptr = strsep(&working_str, WHITESPACE ) ) != NULL) &&
(token_count<MAX_NUM_ARGUMENTS))
{
token[token_count] = strndup( arg_ptr, MAX_COMMAND_SIZE );
if( strlen( token[token_count] ) == 0 )
{
token[token_count] = NULL;
}
token_count++;
}
// CODE TO HELP WITH DEUBG - prints tokenized input
int token_index = 0;
for( token_index = 0; token_index < token_count; token_index ++ )
{
printf("token[%d] = %s\n", token_index, token[token_index] );
}
free( working_root );
// Catch NULL inputs (when user presses enter)
if (token[0] == NULL && token[1] == NULL)
{
int a = 0; // trival assignment
}
else if (strcmp( token[0], "open" ) == 0)
{
// Condition if the user opens a file that is already opened
if (file_open)
{
printf("The file is already opened\n");
}
else
{
if (access(token[1], F_OK) == 0)
{
// Open the fat32.img
fp = fopen( token[1], "r");
file_open = 1;
if (file_open)
{
// seek set move from the beginning of the file
// seek cur move from where we currently are
// seek end move from the end of the file toward the head of the file
fseek(fp,11,SEEK_SET);
fread(&BPB_BytesPerSec,2,1,fp);
fseek(fp,13,SEEK_SET);
fread(&BPB_SecPerClus,1,1,fp);
fseek(fp,14,SEEK_SET);
fread(&BPB_RsvdSecCnt,2,1,fp);
fseek(fp,16,SEEK_SET);
fread(&BPB_NumFATs,1,1,fp);
fseek(fp,36,SEEK_SET);
fread(&BPB_FATSz32,4,1,fp);
RootDirSectors = (BPB_NumFATs * BPB_FATSz32 * BPB_BytesPerSec) +(BPB_RsvdSecCnt * BPB_BytesPerSec);
fseek(fp,RootDirSectors,SEEK_SET);
fread(dir, 16, sizeof(struct DirectoryEntry), fp);
}
else
{
printf("ERROR: file system not found\n");
}
}
else
{
printf("Could not find file image: %s\n", token[1]);
}
}
}
else if (strcmp( token[0], "stat" ) == 0)
{
// Code for stat command
}
else if(strcmp( token[0], "cd" ) == 0)
{
if (file_open)
{
cd( token[1] );
}
else
{
printf("ERROR: File Image Not Open\n");
}
}
else if (strcmp(token[0], "ls" ) == 0)
{
if (fp)
{
ls();
}
else
{
printf("ERROR: File Image Not Open\n");
}
}
else if (strcmp( token[0], "get" ) == 0)
{
if (file_open)
{
// Function call for get
}
else
{
printf("ERROR: File Image Not Open\n");
}
}
else if (strcmp( token[0], "read" ) == 0)
{
if (file_open)
{
if (token[2] && token[3])
{
readfile( token[1], atoi(token[2]), atoi(token[3]) );
}
else
{
printf("ERROR: Please use right format <filename> <position> <number of bytes>\n");
}
}
else
{
printf("ERROR: File Image Not Open\n");
}
}
else if (strcmp( token[0], "close" ) == 0)
{
if (file_open)
{
fclose(fp);
file_open = 0;
}
else
{
printf("ERROR: File has not been opened\n");
}
}
else if (strcmp( token[0], "bpb" ) == 0)
{
if (fp)
{
info();
}
else
{
printf("ERROR: File Image Not Open\n");
}
}
else if (strcmp( token[0], "quit" ) == 0)
{
free(working_root);
if (file_open)
fclose(fp);
return 0;
}
else
{
if(fp)
printf("Command not found ! \n");
else
printf("Error: First system image must be opened first\n");
}
}
return 0;
}
|
the_stack_data/200143454.c
|
foo (a, b)
{
return (a - b) == 0;
}
|
the_stack_data/1042727.c
|
#include <stdio.h>
extern int func1();
extern void func2(int a);
int main(){
printf("%d\n",func1());
func2(5);
return 0;
}
|
the_stack_data/132954032.c
|
#include <stdio.h>
#include <stdlib.h>
int main()
{
int age = 40;
double gpa = 3.6;
char grade = 'A';
char phrase[] = "Giraffe Academy";
return 0;
}
|
the_stack_data/411543.c
|
#if defined(STM8S903) || defined(STM8AF622x)
#include "stm8s_tim6.c"
#endif /* (STM8S903) || (STM8AF622x) */
|
the_stack_data/100139392.c
|
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <check.h>
Suite *s;
TCase *tc;
SRunner *sr;
START_TEST(test_pass)
{
fail_unless(1,"Shouldn't see this message");
}
END_TEST
START_TEST(test_fail)
{
fail("This test fails");
}
END_TEST
static void run (int num_iters)
{
int i;
s = suite_create ("Stress");
tc = tcase_create ("Stress");
sr = srunner_create (s);
suite_add_tcase(s, tc);
for (i = 0; i < num_iters; i++) {
tcase_add_test (tc, test_pass);
tcase_add_test (tc, test_fail);
}
srunner_run_all(sr, CK_SILENT);
if (srunner_ntests_failed (sr) != num_iters) {
printf ("Error: expected %d failures, got %d\n",
num_iters, srunner_ntests_failed(sr));
return;
}
srunner_free(sr);
}
int main(void)
{
int i;
time_t t1;
int iters[] = {1, 100, 1000, 2000, 4000, 8000, 10000, 20000, 40000, -1};
for (i = 0; iters[i] != -1; i++) {
t1 = time(NULL);
run(iters[i]);
printf ("%d, %d\n", iters[i], (int) difftime(time(NULL), t1));
}
return 0;
}
|
the_stack_data/90423.c
|
#include <ctype.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
static size_t _buf_len = 0;
static _Bool
parse_int(int *x, char *s, char **e, _Bool add, uint32_t *buf)
{
size_t base;
if (!strncmp(s, "0x", 2) || !strncmp(s, "U+", 2)) {
base = 16;
s += 2;
} else if (!strncmp(s, "0o", 2)) {
base = 8;
s += 2;
} else if (!strncmp(s, "0b", 2)) {
base = 2;
s += 2;
} else {
base = 10;
}
*x = strtol(s, e, base);
_Bool ok = *e != s;
/* HACK: the add parameter controls whether a parsed integer is
* added to the entries if it succeeds in parsing it.
*
* The reason it is needed is because parsed_int is used in two
* places: 1) in expand_range (where we *want* successfully parse
* integers to be added to the entries) and 2) in parse_range (where
* we *don't want* successfully parsed integers to be added to the
* entries.
*/
if (ok && add) buf[_buf_len] = *x, ++_buf_len;
return ok;
}
static _Bool
parse_range(char *s, char **e, uint32_t *buf)
{
int x = 0, y = 0;
char *ee;
char *start = s;
/* try to parse left-hand side of range */
if (!parse_int(&x, s, &ee, false, buf))
return false;
s = ee;
/* check if this is really a range, or just
* a single integer */
if (*s != '-') {
e = &start;
return false;
} else {
++s;
}
/* try to parse right-hand side of range */
if (!parse_int(&y, s, e, false, buf))
return false;
/* check if left-hand size is greater than
* right-hand side of range */
if (y < x) return false;
/* copy onto accumulator */
for (size_t i = x; i <= (size_t)y; ++i)
buf[_buf_len] = i, ++_buf_len;
return true;
}
static ssize_t
expand_range(char *s, uint32_t *buf)
{
_buf_len = 0;
int x = 0;
char **e = &s;
for (;;) {
while (isspace(*s)) ++s;
/*
* try to parse input as a range, and fall back
* to parsing input as a single integer if that
* failed.
* if both failed, it's probably a syntax error.
*/
if (!parse_range(s, e, buf)) {
if (!parse_int(&x, s, e, true, buf)) {
break;
}
}
s = *e;
while (isspace(*s)) ++s;
if (strlen(s) == 0) return _buf_len;
/* check if there's something more to parse */
if ((*s) == ',') {
++s;
continue;
}
break;
}
/* if we broke out of the main loop then a syntax
* error must have occurred */
return -1;
}
|
the_stack_data/206392665.c
|
/*
* winnojmp.c: stub jump list functions for Windows executables that
* don't update the jump list.
*/
void add_session_to_jumplist(const char * const sessionname) {}
void remove_session_from_jumplist(const char * const sessionname) {}
void clear_jumplist(void) {}
|
the_stack_data/70165.c
|
/*
* Copyright (C) 2009 The Android Open Source Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 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.
*/
/* see the implementation of __set_tls and pthread.c to understand this
* code. Basically, the content of fs:[0] always is a pointer to the base
* address of the tls region
*/
void *__get_tls(void)
{
void *tls;
asm volatile("stc gbr, %0" : "=r"(tls));
return tls;
}
|
the_stack_data/57623.c
|
/*
* 2048 game
*/
/* screen clear command */
#ifdef _WIN64
# define CLR "cls"
#else
# define CLR "clear"
#endif
/* debug print */
/* #define DEBUG */
#ifdef DEBUG
# define D(x) x
#else
# define D(x)
#endif
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define LINE_LEN 4
typedef int Board[4][4]; /* game board */
typedef int* Line[LINE_LEN];
void printBoard(Board board);
int isFullBoard(Board board);
void gen2or4(Board board);
void move(Board board);
void printLine(int* line);
void savePrevBoard(Board board, Board prev_board);
int isBoardChanged(Board board, Board prev_board);
int lineMove(Line line);
void lineMoveUp(Board board);
void lineMoveDown(Board board);
void lineMoveLeft(Board board);
void lineMoveRight(Board board);
void printBoard(Board board) {
for (int i = 0; i < 4; ++i) {
for (int j = 0; j < 4; ++j) {
printf("%5d", board[i][j]);
}
putchar(10);
}
}
int isFullBoard(Board board) {
for (int i = 0; i < 4; ++i) {
for (int j = 0; j < 4; ++j) {
if(board[i][j] == 0)
return 0;
}
}
return 1;
}
int canMove(Board board) {
int cgrid; /* current grid */
if (isFullBoard(board)) {
for (int i = 0; i < 4; ++i) {
for (int j = 0; j < 4; ++j) {
cgrid = board[i][j];
if (i - 1 >= 0 && cgrid == board[i - 1][j]) return 0;
if (j - 1 >= 0 && cgrid == board[i][j - 1]) return 0;
if (i + 1 < 4 && cgrid == board[i + 1][j]) return 0;
if (j + 1 < 4 && cgrid == board[i][j + 1]) return 0;
}
}
}
return 1;
}
void gen2or4(Board board) {
int newval = rand() % 2 ? 2 : 4, row, col;
D(printf("newval: %d ", newval));
while (1) {
row = rand() % 4;
col = rand() % 4;
if (board[row][col] == 0) {
D(printf("+(%d,%d)\n", row, col));
board[row][col] = newval;
break;
}
}
}
void move(Board board) {
switch (getchar()) {
case 'w': lineMoveUp(board); break;
case 's': lineMoveDown(board); break;
case 'a': lineMoveLeft(board); break;
case 'd': lineMoveRight(board); break;
case 'q': exit(0); break;
default: break;
}
getchar();
}
void printLine(int* line) {
for (int i = 0; i < 4; ++i) {
printf("%d,", line[i]);
}
putchar(10);
}
void savePrevBoard(Board board, Board prev_board) {
for (int i = 0; i < 4; ++i) {
for (int j = 0; j < 4; ++j) {
prev_board[i][j] = board[i][j];
}
}
}
int isBoardChanged(Board board, Board prev_board) {
for (int i = 0; i < 4; ++i) {
for (int j = 0; j < 4; ++j) {
if(board[i][j] != prev_board[i][j])
return 1;
}
}
return 0;
}
int lineMove(Line line) {
int min_index = 0;
for (int i = 1; i < LINE_LEN; ++i) {
if (*line[i] != 0) {
int j; /* find first non-zero grid */
for (j = i - 1; j >= min_index && *line[j] == 0; --j) {}
D(printf("i: %d, j: %d, min_index: %d\n", i, j, min_index));
/* special case: all front grid is zero */
if (j < min_index) {
*line[min_index] = *line[i];
*line[i] = 0;
}
/* mix case */
else if (*line[j] == *line[i]) {
*line[j] += *line[i];
*line[i] = 0;
min_index = j + 1;
}
/* shift case */
else if (*line[j + 1] == 0) {
*line[j + 1] = *line[i];
*line[i] = 0;
}
D(printLine(*line));
}
}
return 0;
}
void lineMoveUp(Board board) {
/* each column move up, see resolved procedure here */
/* Line col0 = {&board[0][0], &board[1][0], &board[2][0], &board[3][0]}; */
/* lineMove(col0); */
/* Line col1 = {&board[0][1], &board[1][1], &board[2][1], &board[3][1]}; */
/* lineMove(col1); */
/* Line col2 = {&board[0][2], &board[1][2], &board[2][2], &board[3][2]}; */
/* lineMove(col2); */
/* Line col3 = {&board[0][3], &board[1][3], &board[2][3], &board[3][3]}; */
/* lineMove(col3); */
Line cline;
for (int i = 0; i < LINE_LEN; ++i) {
for (int j = 0; j < LINE_LEN; ++j) {
cline[j] = &board[j][i];
}
lineMove(cline);
}
}
void lineMoveDown(Board board) {
Line cline;
for (int i = 0; i < LINE_LEN; ++i) {
for (int j = 0; j < LINE_LEN; ++j) {
cline[j] = &board[LINE_LEN - 1 - j][i];
}
lineMove(cline);
}
}
void lineMoveLeft(Board board) {
Line cline;
for (int i = 0; i < LINE_LEN; ++i) {
for (int j = 0; j < LINE_LEN; ++j) {
cline[j] = &board[i][j];
}
lineMove(cline);
}
}
void lineMoveRight(Board board) {
Line cline;
for (int i = 0; i < LINE_LEN; ++i) {
for (int j = 0; j < LINE_LEN; ++j) {
cline[j] = &board[i][LINE_LEN - 1 - j];
}
lineMove(cline);
}
}
int main(int argc, char *argv[]) {
/* test lineMove */
/* int testline[4] = {8, 2, 4, 4}; */
/* int testline[4] = {2, 2, 4, 4}; */
/* int testline[4] = {2, 2, 8, 4}; */
/* int testline[4] = {2, 2, 2, 2}; */
/* int testline[4] = {1, 2, 2, 4}; */
/* Line line = {&testline[0], &testline[1], &testline[2], &testline[3]}; */
/* lineMove(line); */
/* printLine(testline); */
/* return 0; */
srand((unsigned)time(0));
Board board = {0};
Board prev_board = {{1}};
while (1) {
system(CLR);
puts("---Type w/s/a/d <Enter> , move Up/Down/Left/Right, or q <Enter> to quit---");
if (!isFullBoard(board) && isBoardChanged(board, prev_board)) {
gen2or4(board);
}
savePrevBoard(board, prev_board);
printBoard(board);
move(board);
/* game over due to no more place and can't move */
if (!canMove(board)) {
puts("game over!");
break;
}
}
return 0;
}
/* vim:set fdm=syntax tw=80: */
|
the_stack_data/200141907.c
|
#include <stdio.h>
#include <sys/stat.h>
#include <stdbool.h>
#include <stdlib.h>
#include <dirent.h>
#include <unistd.h>
#include <string.h>
static int num_dirs, num_regular;
bool is_dir(const char* path) {
/*
* Use the stat() function (try "man 2 stat") to deteYou have to be careful not to process the
* "." and ".." dirrmine if the file
* referenced by path is a directory or not. Call stat, and then use
* S_ISDIR to see if the file is a directory. Make sure you check the
* return value from stat in case there is a problem, e.g., maybe the
* the file doesn't actually exist.
*/
struct stat buf;
if(stat(path, &buf)==0){
if(S_ISDIR(buf.st_mode)){
return true;
}else{
return false;
}
}else{
return false;
}
}
/*
* I needed this because the multiple recursion means there's no way to
* order them so that the definitions all precede the cause.
*/
void process_path(const char*);
void process_directory(const char* path) {
/*
* Update the number of directories seen, use opendir() to open the
* directory, and then use readdir() to loop through the entries
* and process them. You have to be careful not to process the
* "." and ".." directory entries, or you'll end up spinning in
* (infinite) loops. Also make sure you closedir() when you're done.
*
* You'll also want to use chdir() to move into this new directory,
* with a matching call to chdir() to move back out of it when you're
* done.
*/
DIR* top;
top = opendir(path);
struct dirent* dir;
chdir(path);
while((dir = (readdir(top))) != NULL){
if ((strcmp(dir->d_name, ".") == 0)||(strcmp(dir->d_name, "..") == 0)){
continue;
}
process_path(dir->d_name);
}
num_dirs++;
chdir("..");
closedir(top);
}
void process_file(const char* path) {
/*
* Update the number of regular files.
*/
++num_regular;
}
void process_path(const char* path) {
if (is_dir(path)) {
process_directory(path);
} else {
process_file(path);
}
}
int main (int argc, char *argv[]) {
// Ensure an argument was provided.
if (argc != 2) {
printf ("Usage: %s <path>\n", argv[0]);
printf (" where <path> is the file or root of the tree you want to summarize.\n");
return 1;
}
num_dirs = 0;
num_regular = 0;
process_path(argv[1]);
printf("There were %d directories.\n", num_dirs);
printf("There were %d regular files.\n", num_regular);
return 0;
}
|
the_stack_data/141156.c
|
/* iperf3.c - VxWorks iperf3 entry point */
/*
Copyright (c) 2016, Wind River Systems, Inc.
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 Wind River Systems 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, THEIMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSEARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BELIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS ORSERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVERCAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
IN CONTRACT, STRICT LIABILITY,OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THEUSE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
modification history
--------------------
10sep16,chm written
*/
/*
DESCRIPTION
This module is an example of the Wind River Systems C coding convetions.
...
INCLUDE FILES: [N/A]
*/
/* includes */
#include <string.h>
#include <stdlib.h>
/* defines */
/* typedefs */
/* globals */
int iperf3Entry (int argc, char * argv[]);
/* locals */
/* forward declarations */
/*******************************************************************************
*
* main - C-interpreter entrypoit for iperf3
*
* TCP and UDP bandwidth benchmark
*
* RETURNS: 0 if successful, or -1 otherwise
*
* ERRNO: N/A
*/
int main
(
int argc, /** number of arguments */
char * argv[] /** array of arguments */
)
{
int ret;
ret = iperf3Entry (argc, argv);
return ret;
}
|
the_stack_data/208371.c
|
/* Copyright (C) 2002 Jean-Marc Valin
File: exc_8_128_table.c
Codebook for excitation in narrowband CELP mode (7000 bps)
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.
*/
const signed char exc_8_128_table[1024] = {
-14,9,13,-32,2,-10,31,-10,
-8,-8,6,-4,-1,10,-64,23,
6,20,13,6,8,-22,16,34,
7,42,-49,-28,5,26,4,-15,
41,34,41,32,33,24,23,14,
8,40,34,4,-24,-41,-19,-15,
13,-13,33,-54,24,27,-44,33,
27,-15,-15,24,-19,14,-36,14,
-9,24,-12,-4,37,-5,16,-34,
5,10,33,-15,-54,-16,12,25,
12,1,2,0,3,-1,-4,-4,
11,2,-56,54,27,-20,13,-6,
-46,-41,-33,-11,-5,7,12,14,
-14,-5,8,20,6,3,4,-8,
-5,-42,11,8,-14,25,-2,2,
13,11,-22,39,-9,9,5,-45,
-9,7,-9,12,-7,34,-17,-102,
7,2,-42,18,35,-9,-34,11,
-5,-2,3,22,46,-52,-25,-9,
-94,8,11,-5,-5,-5,4,-7,
-35,-7,54,5,-32,3,24,-9,
-22,8,65,37,-1,-12,-23,-6,
-9,-28,55,-33,14,-3,2,18,
-60,41,-17,8,-16,17,-11,0,
-11,29,-28,37,9,-53,33,-14,
-9,7,-25,-7,-11,26,-32,-8,
24,-21,22,-19,19,-10,29,-14,
0,0,0,0,0,0,0,0,
-5,-52,10,41,6,-30,-4,16,
32,22,-27,-22,32,-3,-28,-3,
3,-35,6,17,23,21,8,2,
4,-45,-17,14,23,-4,-31,-11,
-3,14,1,19,-11,2,61,-8,
9,-12,7,-10,12,-3,-24,99,
-48,23,50,-37,-5,-23,0,8,
-14,35,-64,-5,46,-25,13,-1,
-49,-19,-15,9,34,50,25,11,
-6,-9,-16,-20,-32,-33,-32,-27,
10,-8,12,-15,56,-14,-32,33,
3,-9,1,65,-9,-9,-10,-2,
-6,-23,9,17,3,-28,13,-32,
4,-2,-10,4,-16,76,12,-52,
6,13,33,-6,4,-14,-9,-3,
1,-15,-16,28,1,-15,11,16,
9,4,-21,-37,-40,-6,22,12,
-15,-23,-14,-17,-16,-9,-10,-9,
13,-39,41,5,-9,16,-38,25,
46,-47,4,49,-14,17,-2,6,
18,5,-6,-33,-22,44,50,-2,
1,3,-6,7,7,-3,-21,38,
-18,34,-14,-41,60,-13,6,16,
-24,35,19,-13,-36,24,3,-17,
-14,-10,36,44,-44,-29,-3,3,
-54,-8,12,55,26,4,-2,-5,
2,-11,22,-23,2,22,1,-25,
-39,66,-49,21,-8,-2,10,-14,
-60,25,6,10,27,-25,16,5,
-2,-9,26,-13,-20,58,-2,7,
52,-9,2,5,-4,-15,23,-1,
-38,23,8,27,-6,0,-27,-7,
39,-10,-14,26,11,-45,-12,9,
-5,34,4,-35,10,43,-22,-11,
56,-7,20,1,10,1,-26,9,
94,11,-27,-14,-13,1,-11,0,
14,-5,-6,-10,-4,-15,-8,-41,
21,-5,1,-28,-8,22,-9,33,
-23,-4,-4,-12,39,4,-7,3,
-60,80,8,-17,2,-6,12,-5,
1,9,15,27,31,30,27,23,
61,47,26,10,-5,-8,-12,-13,
5,-18,25,-15,-4,-15,-11,12,
-2,-2,-16,-2,-6,24,12,11,
-4,9,1,-9,14,-45,57,12,
20,-35,26,11,-64,32,-10,-10,
42,-4,-9,-16,32,24,7,10,
52,-11,-57,29,0,8,0,-6,
17,-17,-56,-40,7,20,18,12,
-6,16,5,7,-1,9,1,10,
29,12,16,13,-2,23,7,9,
-3,-4,-5,18,-64,13,55,-25,
9,-9,24,14,-25,15,-11,-40,
-30,37,1,-19,22,-5,-31,13,
-2,0,7,-4,16,-67,12,66,
-36,24,-8,18,-15,-23,19,0,
-45,-7,4,3,-13,13,35,5,
13,33,10,27,23,0,-7,-11,
43,-74,36,-12,2,5,-8,6,
-33,11,-16,-14,-5,-7,-3,17,
-34,27,-16,11,-9,15,33,-31,
8,-16,7,-6,-7,63,-55,-17,
11,-1,20,-46,34,-30,6,9,
19,28,-9,5,-24,-8,-23,-2,
31,-19,-16,-5,-15,-18,0,26,
18,37,-5,-15,-2,17,5,-27,
21,-33,44,12,-27,-9,17,11,
25,-21,-31,-7,13,33,-8,-25,
-7,7,-10,4,-6,-9,48,-82,
-23,-8,6,11,-23,3,-3,49,
-29,25,31,4,14,16,9,-4,
-18,10,-26,3,5,-44,-9,9,
-47,-55,15,9,28,1,4,-3,
46,6,-6,-38,-29,-31,-15,-6,
3,0,14,-6,8,-54,-50,33,
-5,1,-14,33,-48,26,-4,-5,
-3,-5,-3,-5,-28,-22,77,55,
-1,2,10,10,-9,-14,-66,-49,
11,-36,-6,-20,10,-10,16,12,
4,-1,-16,45,-44,-50,31,-2,
25,42,23,-32,-22,0,11,20,
-40,-35,-40,-36,-32,-26,-21,-13,
52,-22,6,-24,-20,17,-5,-8,
36,-25,-11,21,-26,6,34,-8,
7,20,-3,5,-25,-8,18,-5,
-9,-4,1,-9,20,20,39,48,
-24,9,5,-65,22,29,4,3,
-43,-11,32,-6,9,19,-27,-10,
-47,-14,24,10,-7,-36,-7,-1,
-4,-5,-5,16,53,25,-26,-29,
-4,-12,45,-58,-34,33,-5,2,
-1,27,-48,31,-15,22,-5,4,
7,7,-25,-3,11,-22,16,-12,
8,-3,7,-11,45,14,-73,-19,
56,-46,24,-20,28,-12,-2,-1,
-36,-3,-33,19,-6,7,2,-15,
5,-31,-45,8,35,13,20,0,
-9,48,-13,-43,-3,-13,2,-5,
72,-68,-27,2,1,-2,-7,5,
36,33,-40,-12,-4,-5,23,19};
|
the_stack_data/182951899.c
|
/*
gcc -std=c17 -lc -lm -pthread -o ../_build/c/io_setvbuf.exe ./c/io_setvbuf.c && (cd ../_build/c/;./io_setvbuf.exe)
https://en.cppreference.com/w/c/io/setvbuf
*/
#include <stdio.h>
int main(void) {
char buf[BUFSIZ];
setbuf(stdin, buf);
} // lifetime of buf ends, undefined behavior
|
the_stack_data/93888021.c
|
#include <stdio.h>
int main () {
int i;
while (~scanf ("%x", &i)) {
printf ("%d\n", i);
}
return 0;
}
|
the_stack_data/47779.c
|
static char *_edata_p;
static char *_end_p;
static char *__bss_start_p;
extern char *_end;
extern char *_edata;
extern char *__bss_start;
void
bar (void)
{
_edata_p = (char*) &_edata;
_end_p = (char*) &_end;
__bss_start_p = (char*) &__bss_start;
}
void
_start ()
{
bar ();
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.