blob_id
stringlengths
40
40
directory_id
stringlengths
40
40
path
stringlengths
3
357
content_id
stringlengths
40
40
detected_licenses
listlengths
0
58
license_type
stringclasses
2 values
repo_name
stringlengths
4
115
snapshot_id
stringlengths
40
40
revision_id
stringlengths
40
40
branch_name
stringlengths
4
58
visit_date
timestamp[ns]date
2015-07-14 21:31:45
2023-09-06 10:45:08
revision_date
timestamp[ns]date
1970-01-01 00:00:00
2023-09-05 23:26:37
committer_date
timestamp[ns]date
1970-01-01 00:00:00
2023-09-05 23:26:37
github_id
int64
966
689M
star_events_count
int64
0
209k
fork_events_count
int64
0
110k
gha_license_id
stringclasses
24 values
gha_event_created_at
timestamp[ns]date
2012-06-07 00:51:45
2023-09-14 21:58:52
gha_created_at
timestamp[ns]date
2008-02-03 21:17:16
2023-08-24 19:49:39
gha_language
stringclasses
180 values
src_encoding
stringclasses
35 values
language
stringclasses
1 value
is_vendor
bool
1 class
is_generated
bool
2 classes
length_bytes
int64
6
10.4M
extension
stringclasses
121 values
filename
stringlengths
1
148
content
stringlengths
6
10.4M
fc54d0a2929536666311a1c4a0d42c62ceb54c3f
943dd54918355e8028fdd759bae6d9dd837e11e0
/third-party/u8g2/tools/font/build/single_font_files/u8g2_font_7x13B_tr.c
106b8da1fdb106f29e64ae6c5c2208e3c1f629c8
[ "BSD-3-Clause", "CC-BY-SA-3.0", "LicenseRef-scancode-x11-adobe-dec", "BSD-2-Clause" ]
permissive
fieldkit/firmware
06e920ad01c2f48142413d3a3447188bc9753004
45c51ce8dc51df886875e97de17980c839882adf
refs/heads/main
2023-08-23T22:29:02.022772
2023-07-24T22:18:01
2023-07-24T22:18:01
183,808,180
11
1
BSD-3-Clause
2023-04-04T20:42:38
2019-04-27T18:27:51
C++
UTF-8
C
false
false
3,087
c
u8g2_font_7x13B_tr.c
/* Fontname: -Misc-Fixed-Bold-R-Normal--13-120-75-75-C-70-ISO10646-1 Copyright: Public domain font. Share and enjoy. Glyphs: 95/1003 BBX Build Mode: 0 */ const uint8_t u8g2_font_7x13B_tr[1083] U8G2_FONT_SECTION("u8g2_font_7x13B_tr") = "_\0\3\3\3\4\3\5\4\6\15\0\376\11\376\11\0\1}\2\330\4\36 \5\0\356\7!\7J\303" "\307\241D\42\10\235\332\207\204E\0#\20\315\302OR$r\230\244\34&I\221\10\0$\17N\302\227" "\214\22\321F\223\250Dh\42\0%\17N\302\307H\22\251\4e\212\221JD\64&\17N\302\317H\242" "\247\221$\62\251\210&\1'\7\42\327\307!\0(\14\314\302\227D$\21\251\211d\2)\15\314\302\207" "L$\23\251\210$\42\0*\15\66\306O(&:\224d\241\10\0+\13\66\306\227Pt(\11E\0" ",\10\244\276\317\212\22\0-\6\16\316\207\1.\10\234\276\217\204\42\1/\14N\302\247\232P\246(\23" "\12\1\60\16N\302\227,\24\21\361$\11\305D\0\61\13N\302\227l\24\21\352\311\0\62\16N\302\17" "ED\22\212F\62\241\320\0\63\15N\302\207Q\246F\25\222$\24\0\64\15N\302\247lD\221\220H" "\207\240\2\65\16N\302\307!(\254\210\204B\222\204\2\66\16N\302\17ED\24VDL\22\12\0\67" "\15N\302\207QM(\23\312\204\62\0\70\16N\302\17E\304$\241\210\230$\24\0\71\16N\302\17E" "\304$)\12I\22\12\0:\14\304\276\217\204\42\207I(\22\0;\13\304\276\217\204\42\236L\224\0<" "\10N\302\247LW\35=\7&\312\207\35j>\11N\302\207T\67\35\1\77\16N\302\17ED\22\212" "fr\230P\4@\17N\302\17%\266R\211L\252\61\11\5\0A\13N\302\17E\304t\30q\22B" "\14N\302GE\304t\21\61]\0C\13N\302\17ED\324\223\204\2D\12N\302GE\304O\27\0" "E\13N\302\307!\250X\21*\32F\13N\302\307!\250X\21j\4G\14N\302\17EDT)\61" "I\12H\13N\302\207\210\323a\304I\0I\11N\302\207I\250O\6J\12N\302\247>\222$\24\0" "K\17N\302\207lD\221\220f$\211\22-\0L\10N\302\207P\77\32M\13N\302Gpt\70\210" "x\22N\15N\302\207\210T\251\34&M$\1O\13N\302\17E\304O\22\12\0P\13N\302GE" "\304t\21j\4Q\14V\276\17E\304S\205\62\241\12R\15N\302GE\304t!I\224h\1S\16" "N\302\17ED\224R\205$\11\5\0T\11N\302\207I\250\237\0U\12N\302\207\210\77I(\0V" "\15N\302\207\210I\22\312D\23*\1W\13N\302\207\210\247\303A\64\14X\17N\302Gp$\11\205" "h\62R\212h\30Y\14N\302\207\210$!\321\204:\1Z\12N\302\207QMG\241\1[\10\314\302" "\207I\237\10\134\14N\302\207P*\224*J\205\2]\10\314\302\7I\237\14^\11&\326\227\214\42\32" "\6_\7\26\276\307\241\0`\7\234\336\207L\1a\12\66\302\17Ur\42I\12b\13N\302\207P\261" "\42\342t\1c\13\66\302\17EDT\222P\0d\12N\302\247\226\23'I\1e\14\66\302\17Et" "\30\212$\24\0f\14N\302\327H\242(\243\11\265\1g\16F\272\317\22IB\221RD\22\12\0h" "\13N\302\207P\261\42\342I\0i\12N\302\227P\16\32\352dj\14^\272\247:L\250#IB\1" "k\15N\302\207P\23EB\42I\224\4l\10N\302\317P\77\31m\12\66\302\207Dr\70\61\11n" "\11\66\302GE\304\223\0o\12\66\302\17E\304IB\1p\13F\272GE\304t\21*\2q\12F" "\272\317\211IR\324\0r\11\66\302GED\324\10s\15\66\302\17E$\21KD\22\12\0t\14F" "\302\217PV\22j\21M\0u\11\66\302\207\210'I\1v\13\66\302\207\210IB\242\211\0w\13\66" "\302\207\210\351p\11E\0x\14\66\302\207\210$!QD$\1y\14F\272\207\210\223\244H\222P\0" "z\12\66\302\207Q&\222\11\15{\14\314\302OI&\221ID\262\1|\7J\303\307\3\1}\15\314" "\302\307L$\221Id\242\12\0~\11\36\332\217\350\20\222\0\0\0\0\4\377\377\0";
f1d9766434f52ae6fa341187489cc167a4f433fb
3e235d89f62287115d1cc7a53f40dc71ef27c47d
/libft/ft_strequ.c
53c5e6204e07f2d2f779151c56ab7ba2118cfa0c
[]
no_license
bnn92/school21
d7c2c8c360903b188a5e32b65fa886b7b307f55d
c804527b984330eaf645c0b612c5f7a8b1cec2c9
refs/heads/master
2022-02-24T08:20:04.715265
2019-10-21T16:52:15
2019-10-21T16:52:15
182,431,178
0
0
null
null
null
null
UTF-8
C
false
false
1,133
c
ft_strequ.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_strequ.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: dshirl <dshirl@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/05/06 17:54:19 by dshirl #+# #+# */ /* Updated: 2019/05/09 14:38:01 by dshirl ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" int ft_strequ(char const *s1, char const *s2) { if (!s1 || !s2) return (0); if (ft_strlen(s1) != ft_strlen(s2)) return (0); while (*s1 && *s2) { if (*s1 != *s2) return (0); s1++; s2++; } return (1); }
aa56915dc66a525a6005f0f50e78e50de28991e2
4dc9caed5cb3f4639587d3d596a82cd748254045
/bin/ch/HostConfigFlagsList.h
77d295834a62c7aae5802d83bf976a1e9f2370ec
[ "MIT" ]
permissive
jkrems/ChakraCore
2e68c27a8a278c36bfa144f77dbd79398279c52b
59b31e5821b7b8df3ed1f5021ed971da82cde9e1
refs/heads/master
2021-01-18T04:42:10.298111
2016-01-22T23:45:30
2016-01-22T23:45:30
50,215,307
2
0
null
2016-01-23T00:06:01
2016-01-23T00:06:00
null
UTF-8
C
false
false
600
h
HostConfigFlagsList.h
//------------------------------------------------------------------------------------------------------- // Copyright (C) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. //------------------------------------------------------------------------------------------------------- #ifdef FLAG FLAG(BSTR, Serialized, "If source is UTF8, deserializes from bytecode file", NULL) FLAG(BSTR, GenerateLibraryByteCodeHeader, "Generate bytecode header file from library code", NULL) #undef FLAG #endif
aec494dd58dd342dde0061f50f28c464309b05e1
f57b080763a64f79d69b03da5d529959c725d5cf
/501A.c
144c7ef45aede4e11d7fff215eed054d000aa144
[]
no_license
rahulnht/codeforces
d6691c44418aca2613d59e0349feb83088839f84
105a8ef228200dd66773bc738df2fa83af54dc16
refs/heads/master
2021-01-10T04:54:40.631663
2016-03-11T21:30:13
2016-03-11T21:30:13
53,697,764
0
0
null
null
null
null
UTF-8
C
false
false
408
c
501A.c
#include<stdio.h> #define max(x,y) x>y?x:y int main() { int a,b,c,d,vmax,mmax; scanf("%d %d %d %d",&a,&b,&c,&d); //For Misha mmax = a - (a*c/250); mmax = max(mmax,a*3/10); //For Vasya vmax = b - (b*d/250); vmax = max(vmax,b*3/10); if(vmax>mmax) printf("Vasya\n"); else if(mmax>vmax) printf("Misha\n"); else printf("Tie\n"); return 0; }
63ed4f1dffe0071641257489f1594f11b6ca2c7b
d7497af41f64e9f5e2aa4955a1d39d39722e184c
/test/integ_test/device/device.c
d12b00f50ee3c5a676eaace504a203797453a474
[]
no_license
huaxuan0827/CmdAgent
024172df92775a1c31d08d125410c71719e8c059
992ced5b6a2ae4fecfa321b6ac875ace78434500
refs/heads/master
2021-04-07T19:55:03.244540
2020-04-08T15:54:47
2020-04-08T15:54:47
248,704,055
0
0
null
null
null
null
UTF-8
C
false
false
2,573
c
device.c
#include <stdio.h> #include <stdlib.h> #include <sys/socket.h> #include <string.h> #include <errno.h> #include <netinet/in.h> #include <arpa/inet.h> #define MAXBUFFER 10240 int main(int argc, char** argv) { int serverFd, connfd,nread; socklen_t len; struct sockaddr_in serveraddr,clientaddr; char readBuf[MAXBUFFER]={0}; char ipaddr[32]; unsigned short usport; if(argc < 3){ printf("please input param: ipaddr and port!!!\n"); exit(-1); } strcpy(ipaddr, argv[1]); usport = atoi(argv[2]); serverFd=socket(AF_INET,SOCK_STREAM,0);//创建socket if(serverFd < 0){ printf("socket error:%s\n",strerror(errno)); exit(-1); } bzero(&serveraddr,sizeof(serveraddr)); serveraddr.sin_family=AF_INET; serveraddr.sin_port=htons(usport); inet_pton(AF_INET,ipaddr,&serveraddr.sin_addr);//将c语言字节序转换为网络字节序 int ret=bind(serverFd,(struct sockaddr *)&serveraddr,sizeof(serveraddr));//绑定IP和端口 if(ret!=0){ close(serverFd); printf("bind error:%s\n",strerror(errno)); exit(-1); } ret=listen(serverFd,5);//监听 if(ret!=0) { close(serverFd); printf("listen error:%s\n",strerror(errno)); exit(-1); } len=sizeof(clientaddr); bzero(&clientaddr,sizeof(clientaddr)); while (1) { connfd = accept(serverFd, (struct sockaddr *) &clientaddr, &len);//接受客户端的连接 printf("%s 连接到服务器 \n",inet_ntop(AF_INET,&clientaddr.sin_addr,ipaddr,sizeof(ipaddr))); if (serverFd < 0) { printf("accept error : %s\n", strerror(errno)); continue; } while((nread= read(connfd,readBuf,MAXBUFFER)))//读客户端发送的数据 { sleep(1); static int nCount = 0; nCount++; #if 0 if( nCount% 30 == 0){ for( unsigned i = 0; i < nread; i++){ readBuf[i] = 0xFF; } } if( nCount % 20 != 0){ write(connfd,readBuf,nread);//写回客户端 }else{ printf("recv len:%d but not resp! \n", nread); } #else write(connfd,readBuf,nread);//写回客户端 #endif printf("ncount:%d, read:%d \n",nCount, nread); bzero(readBuf,MAXBUFFER); } if(nread==0){ printf("客户端关闭连接\n"); }else{ printf("read error:%s\n",strerror(errno)); } close(connfd); } close(serverFd); return 0; }
550fc95c5276521290fd66fd44bc1f4c1edbef78
9d41f629b578af237a9a72d253aa715d92471bcb
/src/settings.h
135b28f845b1c06fff325545c07a9f774509f6b5
[ "Zlib", "LicenseRef-scancode-public-domain" ]
permissive
Ancurio/TileAttEditor
317ec041ae29db513c5d7ac0025114943c5d6351
f20fcfa58bbda9501e513c002d1c0e079b7acc9b
refs/heads/master
2020-05-18T04:15:44.257848
2012-03-16T19:45:50
2012-03-16T19:45:50
3,251,098
0
0
null
null
null
null
UTF-8
C
false
false
1,704
h
settings.h
/* * settings.h * * Copyright (c) 2011-2012 Jonas Kulla <Nyocurio@googlemail.com> * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages * arising from the use of this software. * * Permission is granted to anyone to use this software for any purpose, * including commercial applications, and to alter it and redistribute it * freely, subject to the following restrictions: * * 1. The origin of this software must not be misrepresented; you must not * claim that you wrote the original software. If you use this software * in a product, an acknowledgment in the product documentation would be * appreciated but is not required. * * 2. Altered source versions must be plainly marked as such, and must not be * misrepresented as being the original software. * * 3. This notice may not be removed or altered from any source * distribution. * * * WARNING: This is BAD code. Please do not try to learn from this. * You are, however, free to learn how NOT to write good software. * Have a nice day. */ struct Settings { gint active_attr_id; gdouble tileset_scale_ratio; gdouble attribute_alpha; gboolean smooth_zoom; gboolean show_button_labels; gboolean workspace_flipped; struct Color *bg_color; struct Color *grid_color; gint preferred_tile_width; gint preferred_tile_height; gint window_width; gint window_height; gchar *last_opened; }; struct Settings* settings_read ( struct TileAttribute **tile_attr ); void settings_write ( struct Settings *settings, struct TileAttribute **tile_attr ); void settings_destroy ( struct Settings *settings );
024727d4020541d937b7d34ad7a2863ce5bda928
956db5f041476d2c79c703fdfc1f74c7d1e2c189
/src/unix/devices.h
e6bd15ab7561baed24f601df78c4be66160e2dfb
[]
no_license
BirchJD/xmame-0.103-RPi
f2cade1b824a1720a636dcfe560009a63f2852e8
00da9d208d8a7186a51cecb5c494e17f33942d31
refs/heads/master
2021-01-10T19:31:30.529059
2012-11-28T18:26:10
2012-11-28T18:26:10
6,838,018
1
0
null
null
null
null
UTF-8
C
false
false
1,958
h
devices.h
#ifndef __DEVICES_H_ #define __DEVICES_H_ #include "sysdep/sysdep_display.h" #ifdef __DEVICES_C_ #define EXTERN #else #define EXTERN extern #endif #define JOY_MAX 8 #define JOY_BUTTONS 32 #define JOY_AXES 16 #define JOY_DIRS 2 #define JOY_NAME_LEN 20 #define HISTORY_LENGTH 16 #define GUN_MAX 4 /* now axis entries in the mouse_list, these are get through another way, like the analog joy-values */ #define MOUSE_LIST_TOTAL_ENTRIES SYSDEP_DISPLAY_MOUSE_BUTTONS #define MOUSE_LIST_LEN (MOUSE * MOUSE_LIST_TOTAL_ENTRIES) enum { JOY_NONE, JOY_STANDARD, JOY_PAD, JOY_USB, JOY_PS2, JOY_SDL, JOY_RPI }; int xmame_keyboard_init(void); void xmame_keyboard_exit(); void xmame_keyboard_register_event(struct sysdep_display_keyboard_event *event); void xmame_keyboard_clear(void); struct axisdata_struct { /* current value */ int val; /* calibration data */ int min; int mid; int max; /* boolean values */ int dirs[JOY_DIRS]; }; struct joydata_struct { int fd; int num_axes; int num_buttons; struct axisdata_struct axis[JOY_AXES]; int buttons[JOY_BUTTONS]; }; struct rapidfire_struct { int setting[10]; int status[10]; int enable; int ctrl_button; int ctrl_prev_status; }; EXTERN struct joydata_struct joy_data[JOY_MAX]; EXTERN struct rapidfire_struct rapidfire_data[4]; EXTERN void (*joy_poll_func)(void); EXTERN int joytype; EXTERN int is_usb_ps_gamepad; EXTERN int rapidfire_enable; extern struct rc_option joy_standard_opts[]; extern struct rc_option joy_pad_opts[]; extern struct rc_option joy_usb_opts[]; extern struct rc_option joy_ps2_opts[]; #ifdef USE_LIGHTGUN_ABS_EVENT #include "joystick-drivers/lightgun_abs_event.h" #endif /*** prototypes ***/ void joy_evaluate_moves(void); void joy_standard_init(void); void joy_pad_init(void); void joy_usb_init(void); void joy_ps2_init(void); void joy_ps2_exit(void); void joy_SDL_init(void); void joy_RPi_init(void); #undef EXTERN #endif /* ifndef __DEVICES_H_ */
2950d79978127e6c0c730f69ced49ca042d763f5
78e976c7851e45db8d6f9fa4a886f5c848a6e074
/print66.c
89cfa9a20746de00401e58cc9f3e0d2655047ce0
[]
no_license
geethakathir/cprogram
0ea086fa8c60bac323747503c9aef41df8a7a96c
cd7b8c088535c0014a3807a7aa3a3a2dbc2fbb56
refs/heads/master
2021-01-15T13:36:33.328663
2018-03-20T10:57:40
2018-03-20T10:57:40
99,681,223
0
1
null
null
null
null
UTF-8
C
false
false
257
c
print66.c
#include<stdio.h> void main() { int num,temp,digit,sum=0; printf("enter the number"); scanf("%d",&a); temp=num; while(n>0) { digit=num%10; sum=sum+digit; num/=10; printf("Given number = %ld\n", temp); printf("Sum of the digits %ld = %ld\n", temp, sum); } }
9824ea69d4b141dbdc059d16ab195f2886d0ac8c
bb5e52560ac3578ab4d1f1638cc78486259fc901
/App/Cursors.h
caa1a13859c649b71af50c6b6d49b2029670644f
[]
no_license
WowSoLaggy/Sandbox
db32a5ed9e8a5940924e91cc2107e23e89cfb80b
aeaeb3d6b75b8354a4494de7d2cfde2686be2d55
refs/heads/master
2023-01-22T19:49:23.304712
2020-12-11T19:52:19
2020-12-11T19:52:19
317,349,591
0
0
null
null
null
null
UTF-8
C
false
false
63
h
Cursors.h
#pragma once #include "Cursor.h" Cursor getDefaultCursor();
d608d169f8a181f64d3f9b089a3ebdd2512e5930
a39ccabd2b33817df0b1d5b3c542078b17421539
/Self-locationEstimation/coder/codegen/lib/GetSelfLocation/interface/_coder_GetSelfLocation_info.c
8542b42bf26a6fca92e457f0eb5d394ea0fd42db
[]
no_license
shimotoriharuki/2020RoboTrace_MATLAB
04019d91f89cfef04e23fe641b16c734f1b8fa26
1238893fa9506adcb42218687da54be8ab5c0abb
refs/heads/master
2023-03-23T14:29:58.541717
2021-03-14T05:38:58
2021-03-14T05:38:58
270,971,155
3
0
null
null
null
null
UTF-8
C
false
false
22,498
c
_coder_GetSelfLocation_info.c
/* * Academic License - for use in teaching, academic research, and meeting * course requirements at degree granting institutions only. Not for * government, commercial, or other organizational use. * File: _coder_GetSelfLocation_info.c * * MATLAB Coder version : 4.2 * C/C++ source code generated on : 24-Mar-2020 17:34:25 */ /* Include Files */ #include "_coder_GetSelfLocation_info.h" /* Function Definitions */ /* * Arguments : void * Return Type : const mxArray * */ const mxArray *emlrtMexFcnResolvedFunctionsInfo(void) { const mxArray *nameCaptureInfo; const char * data[76] = { "789ced7d6b8c2bc9755e4bda95effe90bd92114babe75e4958ac5e77f81c0e0548e2fb75f9e6cc9033abdd9926d9247bd8ec26bb9b1c920192119c18f92103eb" "08090c48488400712425415608602bb11150899d04b27f088e220b0a8204498c248613080624e44f94b0d9acb96c5ed665dfcb6291dd730a58f5f43dcdfaba8e", "4e9dd3754e9d53ccdb9299b7310cf38bd3ffde3efdafe57a07a3b577317a7b717e7d3b636ccbf4b7cdaf7f63e91eb5e799e70cbf43f4afcdaf354954b9a1aadf" "08bcc865fb9d2a274f6f44b6c3dd7653973abcc88aeaf1a8cb3132a748c280abcf280d5ee08ef90e9796166e12fcf4a6135b20ddde6824edef708babb54bfd0e", "23b79447af2b2cde300bfcf9b798f13f67923f2c863fda73ffe7af3ea2bf167d3dfcd983138593950359aa4aea4144aaf53b9ca82a0799e0713a183a70395c8e" "8be294762cb335eea0c4098dcf08528d5579498c2a2adf99fd755093ea9c7c10e754ed81f49cfea0b334ae4bcc7bbfd3e4b896afa8bdc0dc5bb87305d6e199e5", "e3f318bc17a7148d8f6156a89d30ebc76716ef9d4bf78ff0de39c3ab4bfdaac03dc2fbce8678652c9e2e27884e5a4e667c9b4a0745b9f87b7ffcd53f09d29543" "da72bf3bbc21a63fb372f82b183c248788de769c360747a566a276cd2ab576dee36ec5a4f0a3f7c8afc159f71e0ce69e56ffa0f7578fcb9c3c7a89e9fd757a58", "d35f45d5ba7abf82c5d3e504d1b7a1f78bea830e3db99894ff00f4bee5f57e283e68e4a74a3f9a3b6a3d2cc54ebb95f3c34ec23e7adf2ef3b98b794fb3f2f7f6" "a57bd45e587a7ede02fae51e35bddfe94ad7da7271577aff1b1be225b078ba9c20fa6bc97465262a79596aca6ce7656d0d7b2b224597c3e9670f544912aad2f0", "80eb0807025f3d984a86c0560fa4ae72a0f389a69ebff9c1affff087a0e7b784474bcf3bc75ccbe9beaef79dd160a5146f8e0eeb9db3987df4bc55e72f5dbdee" "0de857dfad5ebfc1f46f966f1fc1e023be21faccaa3de0459593455678c02ba13e2fa849313bb591325fdb99dedf745d58c3e2e9e347f4a7921ba5c5ca5c7dfe", "25a0ffefa7e617c4c183650ece578614f5d8f7989f835db0ba5db83e0f9d8cc7c3962fd7ed47a3ae70cd5b648f426017766d172e31ef4556de42c4beefef2ddd" "33b7cfdd9bf18957a68395f9e1aef4fc5b1be2a5b178ba1c20fa2672c009d33f0e10a774854e4f1e02dffd641cf4b9d5f579b6d62e27e558ad11532bee9ab3e0", "0d9d654271d0e777429fdfc4a8c567e7ee1acbfa6be2583c5d0e107d5339988b0145bd03fe9a6de26daac7ff12060fc91da28f1c7eb1950c5fe7129ca8888727" "87d5f37882013dbeebf94bd75ff320a05f9de0af61c05ff3a47181bf66b778e0af21d3ffa6ebf4fcd23db3f09cc64744276417ee370475f62755b90be403a4e4", "eebd183cc42f445fb2074a8d155839dadc991dd85b39d1fe7b4cf9237651dd9ff317677f08fa7e5ff5bdd97540d02336a494832f39ce0ef37967ba19f47a0406" "f4fddd99c7d3769309ac5b7f98e5d7bb96ee9985e7347e213aaf88fa77aaaa656aeccecfb3a97ce4b078fa7811fd99be071afc90ab77a5a9781c18f84577fffd", "3f2ebff4ef41cf6f098fd6777ddcdd1e957a4d5e081f87dbc55ea879dc3e894640cfdf553d8fc323178f6d681b4e5b56d5eb292c9e2e0f88beb95ed7f984122f" "40afdb038fd6f7fba0c745bb839ae2af5cbb2529af949ceeb373c63e7a9ddafe7ac27afd7e839715b5c1d3f5dbb0c4fcf81fc6e021be21fa940d17d3e15f3424", "5990a4ee8534e0e486205d5fd4b4bce9cdbfeb971bee7d5043789367c443fd5f2edd2fe321fa46fb7174317a02ffa8fa737eef4f9f077fcebeda03b3dff9cac3" "e8301a198ff3a9a1cb937139c285a0d311b58f3df81f98df9be5e3af61fa477c44f46dcfebfb4f7ee0a2c5095d33f94a64e5354e6c7df0dcd23d73fbdc73b7eb", "03ed7ec771065eac73c3a4a812db37105bf31e884e62dda0ad1928cac7777efa63582f58dd3e94465dbee3ed15cb4ebe5af724cf0bf98c7360233f10cc5f6333" "ca9bc3367efe75f6a5d662b5eda3e0e7c75c51037f101d3cf0f393e91fbeff8de3222baf496af518a643efb043ebda83adc6078cf95a334ed18f0fdc3cffa51f", "813fc8eaf6e04c6613a5417550f515b94874d4f1facb671cd803b00798711be3c574ed012f823d30670f7891be3d98fcee7b5f007b60757bd064cf7c397739db" "f355836ad8cbe63c9ca760a3fc5d8817afbea26690bf4b96987e7f5a7fffa678b4f3796dec1704bffe16f1c0af4fa67fcbeaf531274b4a7f37f5d8026f0466d7", "c9ebd4f47ca32f68e92396ddcf4fe33b5ee9b272a32f1e68bcda815fe7dbe0e7b7bebe570f5d9d62a41c6f9dbba5f140cd746219a76a237dbfe93cce2fdd330b" "cfd9264f977994a78bced579567ebd8ac143fc42f4a5fd336cb72b8c42bcc8caa3d2cce6c5fa624d2b334d2acefc4b6bde0bd11b73dc8b162bd6a70601e1533b", "9781c87703969dbb3897a150fe33f0f758dd4ec42a4aa852883fcc964e2289745296fd89bc68237f0fccefd5e332278f3e62f6e363183cc447445fb61f0389af" "0765991dc50456553991179bb3e7ac9a37f0c53578884e489e56b08f765d4fe6e66755b01356b713e354c21d3ee9563a856aae1eac341299612767a3735a2698", "df9be5e339a67fc4474427b59ed03d48170d4162d50b540c93a12c87812f421da00df1b6b60edd9bbc72a803b44d3ca80344a67f6ae7ad12d2ffa2a466d96c4e" "4e4ea77673aafce9cadf19b178c1ba3acfbc22b22263dd7841128ba7cb05a293a8db3fe5d40ed68937101fde221e2dfdde0bf6731dcfa8e2711465573fece4fc", "834e96b18f7e8779bcfafd8d72f77162f521a0ce330e0fea3c13c69bb5bb8207759ec9f40fdffbabafa8e1bef76f30fd99e5db073078886f88bed2cff3a02148" "92eee8da955dd8546e4eb078faf8119d8cbfe7533adf0e667c9b59028aeb826fc13e22ebdb816aeb305f1105b55e923ad1be987057a3a114c4876ffb6331fd23", "3e223ae9f3d9e39caa3d909ed377b45ef053cbffd2cea30faad6d5fba6f7171396139d6f54cf6b3fff83affe09e8fd2de1d1d2fbd19eab7ce848e6f8dca81112" "5bc7bd41af998bd947efc37c5e7d45cd287f1f24a6e7df81c17b714ad1f8a66849be8c75f3c0689c0b371590be78a0cc927ce9c941e0bb27afc0f7bcd5f53acb", "2642e7d7ed047f9a09f78550488cf8f2591be505c0fc35b66df9f75fc2e0213e21fa6a3f0ed2f2bbdbc7b9a9fd2fadc14374b27e1ce5b6b003c5fd3b81bffd4d" "d0fb56d7fb0e6fe2f0287c5d763942d7d782a32b7822cdb18dfcf9a0f78d0da7f7dfc4f467964f9fc0e0213e21faaa3c30634a4352cc0bd3f5cefc79bbe48355", "d7e0233ac17c91956cddc17931900fb6453c5a76a29f0f8787be70b99b3df672be6ccb9d49fbda61fbd80998dfabc7654e1e3f4dcc0fb4fe7c30ad0a82c25975" "df67168ba7cb09a293a813817845b72e50e0dee7de007d6f757d7f5d4e2a31a17d1a7335e49230b8caa5c47101f43de8fb597b603b7fd1b3da03f017adbea206", "fe223a78e02f22d33fc47f575f5133cadfcbd4e2bf354999dd43fc779d1f71ca29ba7e4488ff6e118f965eef1e0faf7c39357fe8cbb1c7a5ab63393eaa8936d2" "eb307f8d6d3fe3bf48cb43fcf7e9bee77599591cc725e63d09fa790ee17bdefa7aff484e2b6ca196392b57cf2ad550e8d0d36872a0f7ef9cde7f13d31fc47fc1", "5ff8a47199903388ff6e110fe2bf64fa87f9bd7a5cd68a07905b3fdcad7800ac1fec8607eb0732fd431ef0ea719993c7cf52cd032e431ef033c58dca54e34693" "d7210fd8fa7adfdb49b46bc9785dae849d4e51ae6473357fd746eb01bbcc679cdf642be786311f0ce857880b837f11e2c2dbc483b83099fe41cfeb6ddff53cd4", "7fd8d73c42a8ffb04d3ca8ff40a67fbbfa7170e76f9995475c9d7da4f75f5dfcc79b5840ffe373f36b48bfde84e7f7890029b97d37e6bd10bf117daa022f3a53" "9e71ca458b13bae8b81bd83fb4a67eec637ca35f0ffa3ffeef3f82b8b0d5ed463e542f0dcf47ad98333d76a55abe815888f8c06e3cbddd203f9fefd7a44e4712", "2f6a2daed65e8e8b525d2fdce402b36be0d1b9c33798fee11c017378708ec0ddd0e3b4f1e01c0132fdc377e0ea2b6a46f97b48cc2ebc1f8387f886e84b76a12a" "b0ca039d0f3addaa71e4632c9e3e7e4427b47f48e3db81ce37dae707df54ffc58fc00e58dd0e84ae4abd64410c253be73156ad24ca57f161c846e708c07c5e7d", "456d5b79689bd8015e1478719e8060553fd22ee446e71b75b939bcf7a51f801dd8121e353b5065834a28ebc90f84a382a8aa47e576af0776e08eda815789c511" "e0fcf8653c383ffed9f0f47657f0e0fc7832fddb45efbf89794fb3f287d37f285ee058fcc7db38735cbfdeccaf4c627e3fbf32c95ddb89f97a41b5ec3aa1b006", "0fd1c9ae13d41de4a304fedfaf7d1eecc5beda0bd3fb519b49a5e11d16062e7f742a91be702f762224c05eec9bbdb8c4bc2759f94b13f3177d088387f886e8ab" "f4bfda9239a5250975865cdce0b9a5fb47eff39c1edf6db1b3ad4ea4e4666be7563f416e6ef94677bfea6bd17f05fb55ad6e0732f5537f2e7bd48fc752f56c4f", "cae54f22637714ecc0ddb403855def2b9ad981bec25dc85c43fb7b67eb81c933e2a1fecfd6e0213a49b959e0db0ed60593bf5bff2d581758dd1e74ab83accbef" "2a0925672513aaf91ddeba14b1d17e22bbe62f5c62de9ba83cde046eed4317d39f593efe22060ff111d1a7e30e8a4d818b49723273b2bbfd44930df12e97ee99", "85e7343c44df82dc2cf08f6a5ce1abd2df81fa1456b707e78d5a57f4879dde52b89410c57ad29fec1edbe89cfa09e6f730af8d6d5be7d5aff3cf283d59d5eead" "9aaf9cc0e2e9f281e804f295a79ca2290790afbc4d3c5afadd138f365a8ec3e4552eea4eaaf982280ec2111bc50160fe1a9b51de5e21e6eff920060ff109d11f", "cb238b481d9617a3b22c19fcf09bae2f36ad53bda9dff0640d3ea293f1ff18d8385b1b52cc1ff8e77f5e05bf8fd5ed8090e9d43b6d99cb74c365f548ead71b67" "7dde467e1f98cfabafa819e5ef90d8f73d9c43ac373887d82c9edeee0a1e9c434ca67fd0efabafa819e5ef73b7fa1d57f7c82cdf3e86c1437c43f4e5f36a0612", "5f0fca323b8a09acaa72222f3667cf5935defbc53578884ee8dc8a15eca3be5fe0e667f0dd6f79bb304e25dce1936ea553a8e6eac14a2391197672e0ffb923fe" "1f72e7cd3c639e303a7f7eeee5873ce1a73c7f7e26338be3b8c4bc27c1b8eeeffcd7ff0e7eff7dd5fb66f3c58efae992e3d49d0bca497754aca48a8762f19001", "bd7fd7f4fe9b98fee0bc4a32fbc5aa6bf011dd86e7d9c179955bc483f32ac9f40ff37bf5b8eeeafae159e308b07e587d450dd60f74f060fd40a6ff09e6f7b02f" "d4d8b6b52ff41730782f4e291aff4449eec8627d67fafeeb1be27d018ba7cb07a2bf967c8ab2d32aabce2ad11eccb943351ff8a6f58932d48fdb57bd6efa3cca", "abb3f67870adf4e5b3634f24520e5787c9a28df281bf8ef9fdbece5b9cff633be7917d34a05f1fd50fdd54eede83c147fc42f4012bf07556e5585595f96a5f25" "5d3f7a6d1d084e1016f1f6763fc182ff5060c5e6c1e38ca3bdfff36ffd977f067e1eabeb7d7f36e129d41baa2a9df6075c309c13b389908dce9f81f9bcfa8a9a", "51fe32bbae07c42b7949498aaaeeeb62acebd739c5e2e9e3477452fbca16d946779f28f3993f17c1af63753b50ae85f2e1a69217e5bac2f9472157ace56fdb68" "3f10cce7d557d470fe9c1b4c7f5bf6eff30623c058d70e6ced1c228cdc188486a19a2ff00ad801ebdb81f6b9725a505cc7f9b41c8f54c552a73bca5e433ed81d", "9ccf5a23773e3dee9ce417a7148d6f0d419276f9bdffd68678492c9e2e1788bef9beb119a77651070aea3e6c118f967e3feaf972c73d21e26d875ac7857849ed" "4522351bd5f58179bcfafd717afd06d31f9c236c0eaf86c583738409e3cdda5dc1837384c9f40ff660f5fb6febdcc80f60f010bf107df57e4eb40ab06e3e18dd", "7c72b49ff391ec508cff7eabfc12ac07acaeffabadc37c4514d47a49ea44fb62c25d8d8652363a3712f4ffeaf7c7e9ff3731fd415e18e48d3c695c26e40cf2c2" "b68807796164fa87f9bd7a5ce6e4915c5ed8beac239ed5af04eb88d557d4601d41070fd61164fa87b8f1ea2b6abb8a1bf30a2f3618881b3f797d39fde360c6a9", "1dac2f6fbef3d31f837eb7ba7ef70e3342ac3da85f250f2bc3545d7679c4d221c48defd03cd61ab93801c48d71781037268c376b77050fe2c664fadfdbf5fb5e" "e68d956eedc28eea4a4fb9a031e001e286ccb1b3b4de9dc59127cf8887fa7f7d0d1ea213f2ffccf977b0c83fda7ea0fff4bffe08ec82d5ed424f8ec7fd4eb97b", "22b96a63a72a9c851dad631bd59198607e0ff3dad88c72f8c95bfbd0c5f467967fef5aba67169ed3f887e84d4e2d725d4956b97a32c250ac27d1620de7996dba" "4e6862f1f4f122ba262f798202d395f9c1545e0e0c7ca45a5788519effeb600fac6e0f9ab560bbdb394b87fd92839546e941a6e4936d545f6282f93dd8036333", "cae1a789d903b3fb793a6c9bbb18b0f285325d2689cd9dd983ef6f88c763f1f4f122fab6ecc1121f77e18704bbb0453c5a76617898763bc56235deccfac72709" "21158c0a2d1bd59bf83ae6f7fb5a6fee12f33edb3a7798567db9253f91563a74d676a5ffdfda10ef21164f1f37a293f95ed06444b7d014fd40d9f7db3a3e1078", "e3f77f7977e3a396673c3c193b0699444e2d7a5231573715ec72151be97798c7abdfdf28773ff902293dbbef75a1378d1755b078ba3c203aa1ef7af4398f3e04" "baa0df49e14d3ef84fd3bbab874d4bbfa71a51a1a3a8f151d775deebc6dd678d2cdf87f8ef1d9ccf5a7ba4e7a16ef4b3e1dd9dfd0250377a9b7850379a4cffa0", "ff575f51db96fe372b7fcb795f435610a49a75f30072583c7ddc884e663d3867175dffdf3f843caffdd5fb66cfff2a7b8faec34da99a68373dee52e734131bba" "55c63e7adfeaf3b88b79bfed9c1b1309cc2e3731627efdf762f011ff107d65de6f945c5c97b6fecf2fdd330bcf6978884e486ee6eca2794edce42fcefe10befb", "adaeff831eb121a51c7cc9717698cf3bd3cda0d72330a0fff745ff5f62de8fa8dcdd24f6a1ce0337ec06f58f7ec6ba751ee89effbbc836dae7ff065abfff0f40" "ff5b5dff77cecfe5d3d6b8ac944e787724e4748ccf5de78c7df43fcce7d557d48cf2e72096f7f5510c1ee21ba23fc10e64a5708babb5f5e776650f261be2bd86", "c5d3f980e8e4e567ce3eeaf9c093df81fa10fb6b17ccfa6355d7c351a5d7ac9cb69a6d5f31aeb653f961d446fb7d201eb0fa8adab6f6fdacabff23b3625d64ac" "ebf7dfda3eb085b8afc623adc2ec8c57f4eb3de43efc027cf75b5dbfcbc5a03394cab4fa597e9054c34e4fb3dd3885fa3f77691e4fdbabc4fcfc66d79b53165c", "f0ca8536e40b6ea8e51c29bce6f1d954df2f37dc7ba0462a9fb7be060fd19ffe3b6085a0a0af80954ca4bd5ebcf936c47fad6f07ea0fc3e5a3a4bf53ea5e97b9" "5c312d953d3d3b9d0f097660f5fb1be46ef206b1fcdd1796ee9985e7347e21baa6c2d0b7bed67695bfb5bfebc035fa7f2e2c14fdfdfffab80bdffdfbaaefcd7e", "7f456342c853bb4ea4fd8ee2a812b98ab219b6cbd847dfdb653ee3f4f056f6fddc2403fa1f6eea751cd0d0b5fa032e9e5cbed7d3da81c986786f60f1f4f122fa" "56e466ce3cedd381e2f77fe9037ff3df813dd8121eadefff96fbfab49e39a9799c2521747ec20587a3ac6aa3f35fec620f2e31ef4956fe7cc4fc41efc6e021be", "21fa2315d692dd354944f5cfac6a072e97ee9985e7343c44df921d983391eabae0377f22811fc8ea7640281d0a82bfeeeeb9bba9c6a89a8af9c78328d8813b6a" "07fcc4ecc033e67fa9525abae664ebd6f5a1bb6f78ce2eaafb8603bffdf997c11fb4af7adfac3fe8b49469360ad96426996f169caea2c2e7af5906f4feddd4fb", "9100297d7b6fe99eb97deede8c6f688856f5fb97b178ba5c20fa56e482aa9e8738ef36f1a8f97932dd11970d464f4ba1d0c39abf54f7387b71d8cfb977f31927" "0f66e5ef1d987120bffffb0cfffae9807e7d30bf3edaff0ffeffa7c303ffffb6f1f47657f0c0ff4fa67fbbd8854bcc7b9295bf2fec3a0f98576282c4aa618155", "f40270565d1fd0cd1b5c641bf57da0dffc10e40358de0e5c37dc7c671475391272ba5d72063df1523367a37da06007565f5133d6838810b303efc7e021be21fa" "eda76ca7d6741e1e397c17dae9065ca3af1ffbb8333bf0fd0df1b677be8b9975c163ccdcc5f92e5ffe25d8376a79fb100ba72282f3aac4960735b5241ec74a85", "a0df46f601e6f993c7674e2e3fbabbfd438805f37fb7aa1fe972e99e59786efbfb871013a9d691ab7fed57c13eecab7d301b473e2ab8837e5148663ccd62b1d8" "8c5f9d367a1e06ec03d88745b9f4dace3eacab2fd1e745d5ed02fb00f6613ff1c03e90e97f53fbd0c6f48ff888e8db9ed7f7d9aa12e11b8d70a76b18df25e6fd", "c9cae5ebc4f61fadd3cb53b5dc6187bbab3bf1d633e2a1fe536bf0107d93bc744e98fe71a0730a7d30508c2b3cffa51f81dedf57bd6fd66f7426b389d2a03aa8" "fa8a5c243aea78fde5330ece95b9a37185e8eee20a28350ae20a04f3cc20ae60573c5af6e1ea2a978eb7bd696fca99290cfb45ae560c0b36aa4307f3fcc9e3db", "fbb802e425435eb2293cbddd153cc84b26d33fd887278f6fefe30a5bb20f772bae00f6c16e78601fc8f46f0ffbf0a073bfc989abea7d7631efbf9d3a779781d9" "f53f5f128b33e0f2ed5e9c5234feb255b2790c4f7b9ec13736c48b63f174f941f4cde20c9af04c3945d51f39999cbc02fadfeafabf57add61b9e6e35779c2fc9", "05c9198f0b698f8df6a5c2fc3536a3bcbd4c2c9ef0110c1ee213a23f96af16eaf3829a14b3fd0e27f3b59de9f94dcf31a861f1f4f123fa53c989d26265ae7ea0" "67abcd73d61e4f5d3372907efdf3ef313f873882d5edc0f579e8643c1eb67cb96e3f1a75856bde227b0476e08ed80107313bf012060ff109d1579e57ff007ded", "ef6e5fd1a6fb114a6bf0109d4cdef2a774becd6566711c9798f724f8fdff1bffe1b3f0fd6f75bd7fe58d179af5c269d21fcb3afda7d582b7d9c8dbc8ff037adf" "d8f6ecbc62b6db1546a599128bf5c59aca4b7307d73aff16e93a4a8d39fa458b15ebd38501a9b800ddf38b57b093fe7aa050fe33580f58dd2ed45257f9b11a7e", "78d673394ff9e6d01f1f16cb51fbd88509e6f730af8d0d1727ded45e7c0c8387f887e8cbf66220f1f5a02cb3a398c0aa2a27f2f3c8f1aed60b9367c443fd7f71" "0d1ea21392a315eca35def88b9f95915ec83d5edc3389570874fba954ea19aab072b8d4466d8c9d9a81eea04f37bb00fc66694c384edfc48cf1a4f003fd2ea2b", "6ae047a283077e2432fd7f1ff37bbbec23bac4bc3fd9fcb51ab57d43dc50f71cc1bea1757ec729a7e8fa1dbf0bfb86acafef478e7225c35fe752876989bf4eba" "8e3c272367dc3efa1ee6afb1e1f2c96e30fdd1f9ce475a1ee2c54ff79dafcbcce2382e31ef49f03bffaffddf7f097adfea7a3fd948359c89b47a54669dbdd35a", "d6c156122d1bd5a300bd6f6c38bdff26a63fb37cfa04060ff109d1d7c78b93625e606bdcfcf97d891b6fba9fb4ba061fd1b7e63f9cb3957edd22881f6f138f96" "9de8e7c3e1a12f5cee668fbd9c2fdb7267d2beb68dfc4130bf578fcb9c3c3eb0ddfae16ec50960fd60373c583f90e91fead9adbea2668c07c488d901b3e7a53d", "2ad9aa3afd7eb78f958d05ed48d901daf5ecaeb078faf8117d4bf56f1f63e60ebe2ba09edd16f168d98772d8f9b077ac24f8c47961185292e9abe895df467105" "98e74f1edfd3faa13695cbf760f0103f11fd7116e8ffbe2b7bb1e97746058ba78f1bd137f15322317a9c7754cf3ff8ad17fe0aac1bac6e17a22e5f43f05544f5", "3adc4b71ceecb0303e3c813aa76017b654c76e5fecc2d3d6b103bbb0fa8a1ad8053a786017c8f4bf699ca1b974cf2c3ca7f111d1b7359feff3cac58015f8ba6e" "19e8cae3cb0d62fb4d7f0183f7e29432dbbfab70bd3e2bec2c8ef0d686780fb178ba9c203a81f370744e518f1f04fef81b5f06ffd0beea7bb3e7a0a5ba6367cf", "97ab9f9c39051757e4cae7aadbcfd847dfc33c5efdfeb8ba755d4c7f66f985fbff07f10bd135db361ff1454d92b95de9f9c98678af63f1f4f122fa46eb445d40" "1657898bac9b490c45bd0ffb89b688474bef7bbb43df30769895af8ed387ea2826e7479e1a631fbd3fc1fc1ee6b5b119e5f05562fe9ef761f010ff107d691f91", "c8ca4d5eacb5dabbca3f983c231eea7f2bf527ccd42dbde51cedfa1337bffcd9e20fc01e6c098f5afed9f03ae967638da6d751cb45a5d255acefbb86fa447b3b" "af717261560e71f9bee89c82f719fef5a301fdfacafcfa69627ea0e731eff1e294a2f1b52148921602b0aa1f2889c5d3e506d137cf5f99716a17e71d41fef116", "f168e9ffa39e2f77dc1322de76a8755c8897d45e2452b391dffffb98df9be5a380e91ff111d1b7ba1eb85fe5a7e66084fe75717c9798f7272a978153627affde" "d23d73fbdcbdb9ff5fe9b2b2b233bfd0a67a3f8bc5d3e505d137d1fb1a8734cd8f78a5297f8a7ea07b9f7b03fc4056d7fbd7e5a41213daa73157432e0983ab5c", "4a1c176c9457067affc9e333259737e55bbd0f754af7783d09754af7467fd3c6833aa564fab787bd40b77a7ae9e2f82e31ef4f769dc051f30ff18ac88a0cf887" "ccec2f98726a07fea19beffcf4c7e01fda57bd6f365edc0bf6731dcfa8e2711465573fece4fc834e96b18fdedfcbf30a9f665f68471df3cd665f6655c3b82e31", "ef4d765fe85f26a6efd7d52185f38bf7f5fc2338bf789b78707e3199fe37d5f32ca67fc44744df9a9e9fd79bee2f8deb12f3de44e5f1b24a4dcf735d327a7eb9" "99f5ef5843cf6bdff5534e51d5f337ffed2b1f073f8ed5f57c5d5053b198d2f5c7553ee4aa0523b1aa52b651dd2098bfc6863ba71287472a8f4bb3619a2e2785", "47bbaec331164f97034427eccfd38582a1a98702ffa4fc127cbf5b5daf8be757470fe5543b1e4fbb65891b4b4752de6b23bd0ef379f51535a3fc7dfc56cfdf60" "fadb725dd08620b16a66fa6f28ee61553b50c4e2e9e3477432f1da476ca35ff763f22db003d6b7038323b7c7c7a51ee61a11bf7aee638be930dfb1519c16ea38", "ac1e9729790c34779de7c58b756e9817facaaefcf89bda8302164f1f37a293b107b7ecdac5fefed3f7a890df65757b9028252a95923b5756e36cae7d957c9869" "7aaf6d540714e2b7abc7654a1ebbf4e2b7708ee4de9e4704795c5bc4837324c9f44fb31e23f1ba9e22cd7a8ccc4ece0358fece57629a2b232cb00ad97d3bfb1c", "0720f0bdbfc036eaf51cbef9a11720be6b753b70dd70f39d51d4e548c8e976c919f4c44bcd9c8df6f1801d587d45cd680752c4fc3defc6e021be21faa3354ead" "e93c3c72f8e6ff4eebbb7fb98ef36443bccba57b66e1390d0fd1b7540f7cce44aaf59ceb5ffb55b003fb6a07cceedb3f2ab8837e5148663ccd62b1d88c5f9d36", "7a1e06ecc0ddb403e9ddd901a525bb6b9288e22a60079ec50e2026d2949bc06ffe4402bfd0beda01b3eb01a1742808febabbe7eea61aa36a2ae61f0fa236aaf3" "b0bf7660e5021fcd6c51923bb2587fd0a52b7f3ff90229f9337baecb63753e45fddfadea0f3ac5e2e9e346f42dd40314e9d6f999fca3b77f05d601fbaaffcdae", "031295d32b21150cf2856ca7503df2374e726705c63efa9f5a5ed76c329f289cac1cc85255520f2252addfe144f57652bb1c2ec745714a3b96d91a7750e284c6" "6704a9c66aa7c4471595efccfe9acfef38a76a0fa4e7f45decef98ae0bc2c4e2bfebeaba75843a3fe0eb96adeb96c2e2e97282e89bc47fa5ae7280f8447fffe7", "cd0f7efd87a0eff755df9b8e03bbd347f1c1b53f3838947aa95029362c37b236aae709fa7ef5b8ccc96382de7e9f1137bb87fd3e6bf300471cddfd3efff3ef8b" "a0e7adaee7bda7eeb8477e3838cde5bc45c59f2d15325ed546fb7d60fe1a9b51de3ebfeb7dfc705e0b9cd7b2064f6f77050fce6b21d33fe87d6333fa6b1e7dbf", "bf89e9cf2c9f3e81c1437c42f425bd5f6b71b57650ac9758554b59e0a2c32e3bbde3c7dcfcf95d7def6fba2eac62f1747e203a997d9e7836d2f7fb04bef2dbff" "06d60356b70b2d57d9715c2d3b2b9e4cf461387fa614583963a3382fccefd5e332278f9f24e6f759176f6df40553e714dc653f3f3abf45e3d50efcfcdf863a0f", "d6d7f7eaa1ab538c94e3ad73b7341ea8994e2ce3546d54ef07f4fdea719993c747e734de60fa33cbc78f60f0101f11fdb1fcaf509f17d4a498ed773899af5976" "5db095fc70337ea2650ece0589a21c7d8ff939ac0bac6e27aecf4327e3f1b0e5cb75fbd1a82b5cf316d9231be583819d583d2e73f2e8beb5139b9eef751f8387", "f888e8cbe77b290a27aba75a41248d0b4199769ec0b2bd986c88778ec5d3f980e884cef77a8c7d3ba81bf7f6f035d809abdb0997ab3df64762a164333d2c9d8f" "13d584bfa8da28ae30c1fc1ee6b5b119e30d016afb43e1dc5f38f7d788a7b7bb8207e7fe92e97f82f93de8796333eaf920f88b18f0173d695ce02fda2d1ef88b", "c8f4bfe9fce696ee9985e766fbdee7f7dbb30ff77945a34f3b1518caf2383923b61e587fbe2f2f3618ebc691699eef3be5149cef6b333c6a7904c38c106b0fea" "57c9c3ca3055975d1eb17408f962fba6efab525fac2b0c6d7d5f20b62ef810060ff111d11f5b1724355bc7c9a89228ad7d4c96a81bf1843aa28b6ca3ec27faf2", "af401d51cbdb859898ce8782e5ec98ef0c7357dd7a27a7664736f213815d583d2e7376e184d83a60dd77f994051d76b83bbdbfe93a80c67ed2f93a60c6a91dec" "277dfe4b3f027d6f757d7f26b389d2a03aa8fa8a5c243aea78fde5330ef69382be9fb553aafa9e1741df9bd3f7bcb883fd3ebffb5ef8beb7bcbe6fb267be9cbb", "9cedf9aa4135ec65731ece53b051fd8809e6f7100736365c9d681c1ee879bd819e278da7b7bb82077a9e4cff13ccef41cf1b9b51cf67c17f63120ffc37a4f1f4" "7657f0c07f43a67fa80b646cdbf2cfc03e7dbdc13e7db3787abb2b78b04f9f4cffa0cf8dcdf87d5e26b6efe6c3183cc42744d78e9a9a7e815e34245990a4ee85", "34e0e486205d5fcc529637ff7e5f6eb8f7418dd4faee72e97e190fd13792137db9f704fe513dbff1f7fef479d0ff56d7ffcac3e8301a198ff3a9a1cb937139c2" "85a0d361837cdcff0fccd7fe82", "" }; nameCaptureInfo = NULL; emlrtNameCaptureMxArrayR2016a(data, 209536U, &nameCaptureInfo); return nameCaptureInfo; } /* * Arguments : void * Return Type : mxArray * */ mxArray *emlrtMexFcnProperties(void) { mxArray *xResult; mxArray *xEntryPoints; const char * fldNames[6] = { "Name", "NumberOfInputs", "NumberOfOutputs", "ConstantInputs", "FullPath", "TimeStamp" }; mxArray *xInputs; const char * b_fldNames[4] = { "Version", "ResolvedFunctions", "EntryPoints", "CoverageInfo" }; xEntryPoints = emlrtCreateStructMatrix(1, 1, 6, fldNames); xInputs = emlrtCreateLogicalMatrix(1, 5); emlrtSetField(xEntryPoints, 0, "Name", emlrtMxCreateString("GetSelfLocation")); emlrtSetField(xEntryPoints, 0, "NumberOfInputs", emlrtMxCreateDoubleScalar(5.0)); emlrtSetField(xEntryPoints, 0, "NumberOfOutputs", emlrtMxCreateDoubleScalar (3.0)); emlrtSetField(xEntryPoints, 0, "ConstantInputs", xInputs); emlrtSetField(xEntryPoints, 0, "FullPath", emlrtMxCreateString( "C:\\Users\\robot\\Documents\\MATLAB\\2020_RoboTrace\\Self-locationEstimation\\coder\\GetSelfLocation.m")); emlrtSetField(xEntryPoints, 0, "TimeStamp", emlrtMxCreateDoubleScalar (737874.73020833335)); xResult = emlrtCreateStructMatrix(1, 1, 4, b_fldNames); emlrtSetField(xResult, 0, "Version", emlrtMxCreateString( "9.6.0.1072779 (R2019a)")); emlrtSetField(xResult, 0, "ResolvedFunctions", (mxArray *) emlrtMexFcnResolvedFunctionsInfo()); emlrtSetField(xResult, 0, "EntryPoints", xEntryPoints); return xResult; } /* * File trailer for _coder_GetSelfLocation_info.c * * [EOF] */
25960ab182f54e4f7f9ac61a01326c61c61202e3
a096746ecca82fb62b15cf2f40dd03ec1c59f769
/src/kernel/jraid/persistent-data/jraid-space-map-metadata.h
385b29175e739c2823c696060ab5685eafbde081
[]
no_license
Jeoos/JSRAID
3959cb10175224788b398b41bd3142b2aae408b9
b8728cfb7e25d1c4eaa4687bc4f37ee0322d236d
refs/heads/master
2020-04-09T04:14:24.259033
2019-07-31T06:49:08
2019-07-31T06:49:08
160,015,350
0
0
null
null
null
null
UTF-8
C
false
false
1,409
h
jraid-space-map-metadata.h
/* * jraid-space-map-metadata.h * * Copyright(C) 2019 * Contact: JeCortex@yahoo.com * * 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. */ #ifndef __JD_SPACE_MAP_METADATA_H__ #define __JD_SPACE_MAP_METADATA_H__ #include "jraid-transaction-manager.h" #define JD_SM_METADATA_BLOCK_SIZE (4096 >> SECTOR_SHIFT) /* * The metadata device is currently limited in size. * * We have one block of index, which can hold 255 index entries. Each * index entry contains allocation info about ~16k metadata blocks. */ #define JD_SM_METADATA_MAX_BLOCKS (255 * ((1 << 14) - 64)) #define JD_SM_METADATA_MAX_SECTORS (JD_SM_METADATA_MAX_BLOCKS * JD_SM_METADATA_BLOCK_SIZE) /* * Unfortunately we have to use two-phase construction due to the cycle * between the tm and sm. */ struct jd_space_map *jd_sm_metadata_init(void); /* * Create a fresh space map. */ int jd_sm_metadata_create(struct jd_space_map *sm, struct jd_transaction_manager *tm, jd_block_t nr_blocks, jd_block_t superblock); /* * Open from a previously-recorded root. */ int jd_sm_metadata_open(struct jd_space_map *sm, struct jd_transaction_manager *tm, void *root_le, size_t len); #endif /* JD_SPACE_MAP_METADATA_H */
47b9c3815a1759e8206b0e992192f347f834619d
91b878cac077c5f682358a7e2f896275b6edde13
/Baekjoon/solved/2178/sol2.c
312a1f175ac9c077f159088c86b57d7444da654e
[]
no_license
ku-alps/cse17_keunbum
0151a8d8d9f62dc48201c830cbc60cd7d3322bc9
f144766a6bf723bb7453875d909808676e61ac3a
refs/heads/master
2020-04-28T17:29:39.071134
2020-03-24T13:41:29
2020-03-24T13:41:29
175,448,761
0
1
null
null
null
null
UTF-8
C
false
false
692
c
sol2.c
#include <stdio.h> #define N 123 typedef struct { int x; int y; } Point; int a[N][N]; Point que[4 * N * N]; int main() { int n, m; scanf("%d %d", &n, &m); for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { scanf("%1d", a[i] + j); } } int e = 0; que[e].x = 1, que[e++].y = 1; a[1][1] = 2; for (int i = 0; i < e; i++) { Point p = que[i]; if (p.x == n && p.y == m) break; for (int j = 0; j < 4; j++) { int x = p.x + "2101"[j] - '1'; int y = p.y + "1210"[j] - '1'; if (a[x][y] != 1) continue; a[x][y] = a[p.x][p.y] + 1; que[e].x = x, que[e++].y = y; } } printf("%d\n", a[n][m] - 1); return 0; }
c0e167a84f25cf5ef6326458a63f6dc550bf740c
c4afbfe1885e8d0c7a1c8b928563f7bb8ab6a683
/Simulation_EnvSim/CheckValidityPacket58_ProvidePositionReport_Pkg.c
241468937d6ecee13cabfcba30b696369d12b112
[]
no_license
VladislavLasmann/srcAndBinary
cd48ebaa2f1f7f697ba5df9f38abb9ed50658e10
13aa76e545b9596f6dac84fb20480dffae7584d8
refs/heads/master
2021-05-08T15:04:05.709079
2016-01-22T12:40:10
2016-01-22T12:40:10
null
0
0
null
null
null
null
UTF-8
C
false
false
1,368
c
CheckValidityPacket58_ProvidePositionReport_Pkg.c
/* $*************** KCG Version 6.1.3 (build i6) **************** ** Command: s2c613 -config S:/model/Scade/System/OBU_PreIntegrations/Testbench_Integration/Simulation_EnvSim\kcg_s2c_config.txt ** Generation date: 2015-11-23T09:24:23 *************************************************************$ */ #include "kcg_consts.h" #include "kcg_sensors.h" #include "CheckValidityPacket58_ProvidePositionReport_Pkg.h" /* ProvidePositionReport_Pkg::CheckValidityPacket58 */ void CheckValidityPacket58_ProvidePositionReport_Pkg( /* ProvidePositionReport_Pkg::CheckValidityPacket58::bgCommonHeader */BG_Header_T_BG_Types_Pkg *bgCommonHeader, /* ProvidePositionReport_Pkg::CheckValidityPacket58::reportedBGs */ReportedBGList_T_ProvidePositionReport_Pkg *reportedBGs, /* ProvidePositionReport_Pkg::CheckValidityPacket58::found */kcg_bool *found, /* ProvidePositionReport_Pkg::CheckValidityPacket58::updatedBGs */ReportedBGList_T_ProvidePositionReport_Pkg *updatedBGs) { /* 1 */ BG_hasBeenReported_ProvidePositionReport_Pkg( reportedBGs, (*bgCommonHeader).nid_bg, &(*bgCommonHeader).bgPosition.odo, found, updatedBGs); } /* $*************** KCG Version 6.1.3 (build i6) **************** ** CheckValidityPacket58_ProvidePositionReport_Pkg.c ** Generation date: 2015-11-23T09:24:23 *************************************************************$ */
6a6abe8bbda2bdc311fb2e644776b43848787f55
49d0403b0eb17fd434f438599281acc61db9e408
/Poj 2027 No Brainer/1.c
5da0a02e6ed67ff5dec45513b0a1b0bca4d082f6
[]
no_license
francisfsjiang/ACM
01795c0fd44941ce530e4aa7cfec54ad5f7705f6
5506cc5b9c94ca0866f9ee383676638b74ec5475
refs/heads/master
2021-05-27T01:02:39.419742
2014-02-26T12:45:06
2014-02-26T12:45:06
null
0
0
null
null
null
null
UTF-8
C
false
false
222
c
1.c
#include<stdio.h> int main() { int x,y,i,t; scanf("%d",&t); for(i=1;i<=t;i++) { scanf("%d%d",&x,&y); if(x<y)printf("NO BRAINS\n"); else printf("MMM BRAINS\n"); } return 0; }
762c9b5697904aef033d08dbb2146132fca10271
339278d6218035c26b040966e6879bbe364b6031
/PLOTS/mumu/MET130/n_vtx_CJVfail_log.C
6c383523e7e09f501e756108449d0fda2f690b89
[]
no_license
pjdunne/ichnnplots
a39a58780a5df4a09dcd2169e0275f9da96ca053
4f36e338299efc225c85ee16d11c4c25599404f9
refs/heads/master
2020-05-23T15:42:13.189894
2013-11-22T10:25:01
2013-11-22T10:25:01
null
0
0
null
null
null
null
UTF-8
C
false
false
30,499
c
n_vtx_CJVfail_log.C
{ //=========Macro generated from canvas: canv/canv //========= (Mon Nov 18 15:44:18 2013) by ROOT version5.32/00 TCanvas *canv = new TCanvas("canv", "canv",0,0,700,700); gStyle->SetOptFit(1); gStyle->SetOptTitle(0); canv->SetHighLightColor(2); canv->Range(0,0,1,1); canv->SetFillColor(0); canv->SetBorderMode(0); canv->SetBorderSize(2); canv->SetTickx(1); canv->SetTicky(1); canv->SetLeftMargin(0.16); canv->SetRightMargin(0.05); canv->SetTopMargin(0.05); canv->SetFrameFillStyle(0); canv->SetFrameLineStyle(0); canv->SetFrameLineWidth(2); canv->SetFrameBorderMode(0); canv->SetFrameBorderSize(10); // ------------>Primitives in pad: upper TPad *upper = new TPad("upper", "pad",0,0.26,1,1); upper->Draw(); upper->cd(); upper->Range(-8.101265,-2.827339,42.53165,5.832995); upper->SetFillColor(0); upper->SetBorderMode(0); upper->SetBorderSize(2); upper->SetLogy(); upper->SetTickx(1); upper->SetTicky(1); upper->SetLeftMargin(0.16); upper->SetRightMargin(0.05); upper->SetTopMargin(0.05); upper->SetBottomMargin(0.02); upper->SetFrameFillStyle(0); upper->SetFrameLineStyle(0); upper->SetFrameLineWidth(2); upper->SetFrameBorderMode(0); upper->SetFrameBorderSize(10); upper->SetFrameFillStyle(0); upper->SetFrameLineStyle(0); upper->SetFrameLineWidth(2); upper->SetFrameBorderMode(0); upper->SetFrameBorderSize(10); THStack *stack = new THStack(); stack->SetName("stack"); stack->SetTitle("stack"); stack->SetMinimum(0.01); stack->SetMaximum(104490.6); TH1F *n_vtx_stack_10 = new TH1F("n_vtx_stack_10","stack",40,0,40); n_vtx_stack_10->SetBinContent(6,0.05073027); n_vtx_stack_10->SetBinContent(7,0.09606801); n_vtx_stack_10->SetBinContent(8,0.06860681); n_vtx_stack_10->SetBinContent(9,0.03746735); n_vtx_stack_10->SetBinContent(10,0.103975); n_vtx_stack_10->SetBinContent(11,0.1145786); n_vtx_stack_10->SetBinContent(13,0.06633758); n_vtx_stack_10->SetBinContent(14,0.02761033); n_vtx_stack_10->SetBinContent(16,0.1114393); n_vtx_stack_10->SetBinContent(17,0.06324466); n_vtx_stack_10->SetBinContent(18,0.04154311); n_vtx_stack_10->SetBinContent(19,0.07390438); n_vtx_stack_10->SetBinContent(20,0.07313836); n_vtx_stack_10->SetBinContent(21,0.1180282); n_vtx_stack_10->SetBinContent(23,0.04309887); n_vtx_stack_10->SetBinError(6,0.05073027); n_vtx_stack_10->SetBinError(7,0.09606801); n_vtx_stack_10->SetBinError(8,0.06860681); n_vtx_stack_10->SetBinError(9,0.03746735); n_vtx_stack_10->SetBinError(10,0.103975); n_vtx_stack_10->SetBinError(11,0.08399034); n_vtx_stack_10->SetBinError(13,0.04691179); n_vtx_stack_10->SetBinError(14,0.02761033); n_vtx_stack_10->SetBinError(16,0.08366165); n_vtx_stack_10->SetBinError(17,0.06324466); n_vtx_stack_10->SetBinError(18,0.04154311); n_vtx_stack_10->SetBinError(19,0.07390438); n_vtx_stack_10->SetBinError(20,0.05171851); n_vtx_stack_10->SetBinError(21,0.08707963); n_vtx_stack_10->SetBinError(23,0.04309887); n_vtx_stack_10->SetMinimum(0.002217522); n_vtx_stack_10->SetMaximum(251176); n_vtx_stack_10->SetEntries(20); n_vtx_stack_10->SetStats(0); n_vtx_stack_10->SetFillColor(4); n_vtx_stack_10->SetLineColor(4); n_vtx_stack_10->SetLineWidth(2); n_vtx_stack_10->SetMarkerColor(4); n_vtx_stack_10->SetMarkerStyle(21); n_vtx_stack_10->SetMarkerSize(0.8); n_vtx_stack_10->GetXaxis()->SetTitle("Number of vertices"); n_vtx_stack_10->GetXaxis()->SetLabelFont(42); n_vtx_stack_10->GetXaxis()->SetLabelOffset(0.007); n_vtx_stack_10->GetXaxis()->SetLabelSize(0); n_vtx_stack_10->GetXaxis()->SetTitleSize(0); n_vtx_stack_10->GetXaxis()->SetTickLength(0.02); n_vtx_stack_10->GetXaxis()->SetTitleOffset(0.9); n_vtx_stack_10->GetXaxis()->SetTitleFont(42); n_vtx_stack_10->GetYaxis()->SetTitle("Events"); n_vtx_stack_10->GetYaxis()->SetLabelFont(42); n_vtx_stack_10->GetYaxis()->SetLabelOffset(0.007); n_vtx_stack_10->GetYaxis()->SetLabelSize(0.035); n_vtx_stack_10->GetYaxis()->SetTitleSize(0.045); n_vtx_stack_10->GetYaxis()->SetTickLength(0.02); n_vtx_stack_10->GetYaxis()->SetTitleOffset(1.55); n_vtx_stack_10->GetYaxis()->SetTitleFont(42); n_vtx_stack_10->GetZaxis()->SetLabelFont(42); n_vtx_stack_10->GetZaxis()->SetLabelOffset(0.007); n_vtx_stack_10->GetZaxis()->SetLabelSize(0.035); n_vtx_stack_10->GetZaxis()->SetTitleSize(0.045); n_vtx_stack_10->GetZaxis()->SetTickLength(0.02); n_vtx_stack_10->GetZaxis()->SetTitleFont(42); stack->SetHistogram(n_vtx_stack_10); TH1F *n_vtx = new TH1F("n_vtx","n_vtx",40,0,40); n_vtx->SetBinContent(6,0.05073027); n_vtx->SetBinContent(7,0.09606801); n_vtx->SetBinContent(8,0.06860681); n_vtx->SetBinContent(9,0.03746735); n_vtx->SetBinContent(10,0.103975); n_vtx->SetBinContent(11,0.1145786); n_vtx->SetBinContent(13,0.06633758); n_vtx->SetBinContent(14,0.02761033); n_vtx->SetBinContent(16,0.1114393); n_vtx->SetBinContent(17,0.06324466); n_vtx->SetBinContent(18,0.04154311); n_vtx->SetBinContent(19,0.07390438); n_vtx->SetBinContent(20,0.07313836); n_vtx->SetBinContent(21,0.1180282); n_vtx->SetBinContent(23,0.04309887); n_vtx->SetBinError(6,0.05073027); n_vtx->SetBinError(7,0.09606801); n_vtx->SetBinError(8,0.06860681); n_vtx->SetBinError(9,0.03746735); n_vtx->SetBinError(10,0.103975); n_vtx->SetBinError(11,0.08399034); n_vtx->SetBinError(13,0.04691179); n_vtx->SetBinError(14,0.02761033); n_vtx->SetBinError(16,0.08366165); n_vtx->SetBinError(17,0.06324466); n_vtx->SetBinError(18,0.04154311); n_vtx->SetBinError(19,0.07390438); n_vtx->SetBinError(20,0.05171851); n_vtx->SetBinError(21,0.08707963); n_vtx->SetBinError(23,0.04309887); n_vtx->SetMinimum(0.01); n_vtx->SetMaximum(105000); n_vtx->SetEntries(20); n_vtx->SetStats(0); n_vtx->SetFillColor(4); n_vtx->SetLineColor(4); n_vtx->SetLineWidth(2); n_vtx->SetMarkerColor(4); n_vtx->SetMarkerStyle(21); n_vtx->SetMarkerSize(0.8); n_vtx->GetXaxis()->SetTitle("Number of vertices"); n_vtx->GetXaxis()->SetLabelFont(42); n_vtx->GetXaxis()->SetLabelOffset(0.007); n_vtx->GetXaxis()->SetLabelSize(0); n_vtx->GetXaxis()->SetTitleSize(0); n_vtx->GetXaxis()->SetTickLength(0.02); n_vtx->GetXaxis()->SetTitleOffset(0.9); n_vtx->GetXaxis()->SetTitleFont(42); n_vtx->GetYaxis()->SetTitle("Events"); n_vtx->GetYaxis()->SetLabelFont(42); n_vtx->GetYaxis()->SetLabelOffset(0.007); n_vtx->GetYaxis()->SetLabelSize(0.035); n_vtx->GetYaxis()->SetTitleSize(0.045); n_vtx->GetYaxis()->SetTickLength(0.02); n_vtx->GetYaxis()->SetTitleOffset(1.55); n_vtx->GetYaxis()->SetTitleFont(42); n_vtx->GetZaxis()->SetLabelFont(42); n_vtx->GetZaxis()->SetLabelOffset(0.007); n_vtx->GetZaxis()->SetLabelSize(0.035); n_vtx->GetZaxis()->SetTitleSize(0.045); n_vtx->GetZaxis()->SetTickLength(0.02); n_vtx->GetZaxis()->SetTitleFont(42); stack->Add(n_vtx,"HIST"); TH1F *n_vtx = new TH1F("n_vtx","n_vtx",40,0,40); n_vtx->SetBinContent(5,0.7040896); n_vtx->SetBinContent(9,0.6532889); n_vtx->SetBinContent(11,0.7296048); n_vtx->SetBinContent(12,1.66247); n_vtx->SetBinContent(13,0.790862); n_vtx->SetBinContent(15,2.580399); n_vtx->SetBinContent(16,1.600786); n_vtx->SetBinContent(19,2.223935); n_vtx->SetBinContent(20,0.7287824); n_vtx->SetBinContent(21,0.3041099); n_vtx->SetBinContent(22,0.6406721); n_vtx->SetBinContent(25,0.542883); n_vtx->SetBinContent(31,0.088039); n_vtx->SetBinError(5,0.7040896); n_vtx->SetBinError(9,0.6532889); n_vtx->SetBinError(11,0.7296048); n_vtx->SetBinError(12,0.9863809); n_vtx->SetBinError(13,0.790862); n_vtx->SetBinError(15,1.558426); n_vtx->SetBinError(16,1.13273); n_vtx->SetBinError(19,1.289962); n_vtx->SetBinError(20,0.7287823); n_vtx->SetBinError(21,0.3041099); n_vtx->SetBinError(22,0.6406721); n_vtx->SetBinError(25,0.4872446); n_vtx->SetBinError(31,0.088039); n_vtx->SetEntries(22); n_vtx->SetStats(0); n_vtx->SetFillColor(5); n_vtx->SetLineColor(5); n_vtx->SetLineWidth(2); n_vtx->SetMarkerColor(5); n_vtx->SetMarkerStyle(21); n_vtx->SetMarkerSize(0.8); n_vtx->GetXaxis()->SetLabelFont(42); n_vtx->GetXaxis()->SetLabelOffset(0.007); n_vtx->GetXaxis()->SetLabelSize(0.035); n_vtx->GetXaxis()->SetTitleSize(0.045); n_vtx->GetXaxis()->SetTickLength(0.02); n_vtx->GetXaxis()->SetTitleOffset(0.9); n_vtx->GetXaxis()->SetTitleFont(42); n_vtx->GetYaxis()->SetLabelFont(42); n_vtx->GetYaxis()->SetLabelOffset(0.007); n_vtx->GetYaxis()->SetLabelSize(0.035); n_vtx->GetYaxis()->SetTitleSize(0.045); n_vtx->GetYaxis()->SetTickLength(0.02); n_vtx->GetYaxis()->SetTitleOffset(1.55); n_vtx->GetYaxis()->SetTitleFont(42); n_vtx->GetZaxis()->SetLabelFont(42); n_vtx->GetZaxis()->SetLabelOffset(0.007); n_vtx->GetZaxis()->SetLabelSize(0.035); n_vtx->GetZaxis()->SetTitleSize(0.045); n_vtx->GetZaxis()->SetTickLength(0.02); n_vtx->GetZaxis()->SetTitleFont(42); stack->Add(n_vtx,""); TH1F *n_vtx = new TH1F("n_vtx","n_vtx",40,0,40); n_vtx->SetStats(0); n_vtx->SetFillColor(6); n_vtx->SetLineColor(6); n_vtx->SetLineWidth(2); n_vtx->SetMarkerColor(6); n_vtx->SetMarkerStyle(21); n_vtx->SetMarkerSize(0.8); n_vtx->GetXaxis()->SetLabelFont(42); n_vtx->GetXaxis()->SetLabelOffset(0.007); n_vtx->GetXaxis()->SetLabelSize(0.035); n_vtx->GetXaxis()->SetTitleSize(0.045); n_vtx->GetXaxis()->SetTickLength(0.02); n_vtx->GetXaxis()->SetTitleOffset(0.9); n_vtx->GetXaxis()->SetTitleFont(42); n_vtx->GetYaxis()->SetLabelFont(42); n_vtx->GetYaxis()->SetLabelOffset(0.007); n_vtx->GetYaxis()->SetLabelSize(0.035); n_vtx->GetYaxis()->SetTitleSize(0.045); n_vtx->GetYaxis()->SetTickLength(0.02); n_vtx->GetYaxis()->SetTitleOffset(1.55); n_vtx->GetYaxis()->SetTitleFont(42); n_vtx->GetZaxis()->SetLabelFont(42); n_vtx->GetZaxis()->SetLabelOffset(0.007); n_vtx->GetZaxis()->SetLabelSize(0.035); n_vtx->GetZaxis()->SetTitleSize(0.045); n_vtx->GetZaxis()->SetTickLength(0.02); n_vtx->GetZaxis()->SetTitleFont(42); stack->Add(n_vtx,""); TH1F *n_vtx = new TH1F("n_vtx","n_vtx",40,0,40); n_vtx->SetStats(0); Int_t ci; // for color index setting ci = TColor::GetColor("#660099"); n_vtx->SetFillColor(ci); ci = TColor::GetColor("#660099"); n_vtx->SetLineColor(ci); n_vtx->SetLineWidth(2); ci = TColor::GetColor("#660099"); n_vtx->SetMarkerColor(ci); n_vtx->SetMarkerStyle(21); n_vtx->SetMarkerSize(0.8); n_vtx->GetXaxis()->SetLabelFont(42); n_vtx->GetXaxis()->SetLabelOffset(0.007); n_vtx->GetXaxis()->SetLabelSize(0.035); n_vtx->GetXaxis()->SetTitleSize(0.045); n_vtx->GetXaxis()->SetTickLength(0.02); n_vtx->GetXaxis()->SetTitleOffset(0.9); n_vtx->GetXaxis()->SetTitleFont(42); n_vtx->GetYaxis()->SetLabelFont(42); n_vtx->GetYaxis()->SetLabelOffset(0.007); n_vtx->GetYaxis()->SetLabelSize(0.035); n_vtx->GetYaxis()->SetTitleSize(0.045); n_vtx->GetYaxis()->SetTickLength(0.02); n_vtx->GetYaxis()->SetTitleOffset(1.55); n_vtx->GetYaxis()->SetTitleFont(42); n_vtx->GetZaxis()->SetLabelFont(42); n_vtx->GetZaxis()->SetLabelOffset(0.007); n_vtx->GetZaxis()->SetLabelSize(0.035); n_vtx->GetZaxis()->SetTitleSize(0.045); n_vtx->GetZaxis()->SetTickLength(0.02); n_vtx->GetZaxis()->SetTitleFont(42); stack->Add(n_vtx,""); TH1F *n_vtx = new TH1F("n_vtx","n_vtx",40,0,40); n_vtx->SetStats(0); n_vtx->SetFillColor(3); n_vtx->SetLineColor(3); n_vtx->SetLineWidth(2); n_vtx->SetMarkerColor(3); n_vtx->SetMarkerStyle(21); n_vtx->SetMarkerSize(0.8); n_vtx->GetXaxis()->SetLabelFont(42); n_vtx->GetXaxis()->SetLabelOffset(0.007); n_vtx->GetXaxis()->SetLabelSize(0.035); n_vtx->GetXaxis()->SetTitleSize(0.045); n_vtx->GetXaxis()->SetTickLength(0.02); n_vtx->GetXaxis()->SetTitleOffset(0.9); n_vtx->GetXaxis()->SetTitleFont(42); n_vtx->GetYaxis()->SetLabelFont(42); n_vtx->GetYaxis()->SetLabelOffset(0.007); n_vtx->GetYaxis()->SetLabelSize(0.035); n_vtx->GetYaxis()->SetTitleSize(0.045); n_vtx->GetYaxis()->SetTickLength(0.02); n_vtx->GetYaxis()->SetTitleOffset(1.55); n_vtx->GetYaxis()->SetTitleFont(42); n_vtx->GetZaxis()->SetLabelFont(42); n_vtx->GetZaxis()->SetLabelOffset(0.007); n_vtx->GetZaxis()->SetLabelSize(0.035); n_vtx->GetZaxis()->SetTitleSize(0.045); n_vtx->GetZaxis()->SetTickLength(0.02); n_vtx->GetZaxis()->SetTitleFont(42); stack->Add(n_vtx,""); TH1F *n_vtx = new TH1F("n_vtx","n_vtx",40,0,40); n_vtx->SetBinContent(3,0.07828738); n_vtx->SetBinContent(4,0.1414175); n_vtx->SetBinContent(5,0.108304); n_vtx->SetBinContent(6,0.6875985); n_vtx->SetBinContent(7,0.7147117); n_vtx->SetBinContent(8,1.720983); n_vtx->SetBinContent(9,1.253722); n_vtx->SetBinContent(10,2.292894); n_vtx->SetBinContent(11,3.866469); n_vtx->SetBinContent(12,2.747268); n_vtx->SetBinContent(13,3.506311); n_vtx->SetBinContent(14,3.322967); n_vtx->SetBinContent(15,2.88904); n_vtx->SetBinContent(16,3.074458); n_vtx->SetBinContent(17,2.998504); n_vtx->SetBinContent(18,3.401963); n_vtx->SetBinContent(19,3.016538); n_vtx->SetBinContent(20,2.214229); n_vtx->SetBinContent(21,1.196228); n_vtx->SetBinContent(22,1.419165); n_vtx->SetBinContent(23,0.9545948); n_vtx->SetBinContent(24,1.218055); n_vtx->SetBinContent(25,0.4855); n_vtx->SetBinContent(26,0.2237218); n_vtx->SetBinContent(27,0.08815857); n_vtx->SetBinContent(28,0.1938265); n_vtx->SetBinContent(29,0.3868202); n_vtx->SetBinContent(30,0.07886382); n_vtx->SetBinContent(31,0.002347397); n_vtx->SetBinContent(32,0.03860752); n_vtx->SetBinContent(33,0.09362461); n_vtx->SetBinContent(34,0.002100347); n_vtx->SetBinContent(35,0.0238703); n_vtx->SetBinContent(36,0.04222111); n_vtx->SetBinContent(37,0.006720755); n_vtx->SetBinContent(41,0.0001472983); n_vtx->SetBinError(3,0.06414551); n_vtx->SetBinError(4,0.1414175); n_vtx->SetBinError(5,0.0881789); n_vtx->SetBinError(6,0.294743); n_vtx->SetBinError(7,0.2876954); n_vtx->SetBinError(8,0.4432581); n_vtx->SetBinError(9,0.3696117); n_vtx->SetBinError(10,0.536729); n_vtx->SetBinError(11,0.6471583); n_vtx->SetBinError(12,0.5499902); n_vtx->SetBinError(13,0.5926243); n_vtx->SetBinError(14,0.5768604); n_vtx->SetBinError(15,0.5175146); n_vtx->SetBinError(16,0.5351808); n_vtx->SetBinError(17,0.5121); n_vtx->SetBinError(18,0.5503375); n_vtx->SetBinError(19,0.5432543); n_vtx->SetBinError(20,0.4391904); n_vtx->SetBinError(21,0.3201942); n_vtx->SetBinError(22,0.3452267); n_vtx->SetBinError(23,0.2850887); n_vtx->SetBinError(24,0.3254979); n_vtx->SetBinError(25,0.1965231); n_vtx->SetBinError(26,0.106367); n_vtx->SetBinError(27,0.05794831); n_vtx->SetBinError(28,0.110893); n_vtx->SetBinError(29,0.1672449); n_vtx->SetBinError(30,0.04545746); n_vtx->SetBinError(31,0.002347397); n_vtx->SetBinError(32,0.03860752); n_vtx->SetBinError(33,0.09342864); n_vtx->SetBinError(34,0.001546347); n_vtx->SetBinError(35,0.02385118); n_vtx->SetBinError(36,0.04222111); n_vtx->SetBinError(37,0.006308771); n_vtx->SetBinError(41,0.0001472983); n_vtx->SetEntries(530); n_vtx->SetStats(0); n_vtx->SetFillColor(3); n_vtx->SetLineColor(3); n_vtx->SetLineWidth(2); n_vtx->SetMarkerColor(3); n_vtx->SetMarkerStyle(21); n_vtx->SetMarkerSize(0.8); n_vtx->GetXaxis()->SetLabelFont(42); n_vtx->GetXaxis()->SetLabelOffset(0.007); n_vtx->GetXaxis()->SetLabelSize(0.035); n_vtx->GetXaxis()->SetTitleSize(0.045); n_vtx->GetXaxis()->SetTickLength(0.02); n_vtx->GetXaxis()->SetTitleOffset(0.9); n_vtx->GetXaxis()->SetTitleFont(42); n_vtx->GetYaxis()->SetLabelFont(42); n_vtx->GetYaxis()->SetLabelOffset(0.007); n_vtx->GetYaxis()->SetLabelSize(0.035); n_vtx->GetYaxis()->SetTitleSize(0.045); n_vtx->GetYaxis()->SetTickLength(0.02); n_vtx->GetYaxis()->SetTitleOffset(1.55); n_vtx->GetYaxis()->SetTitleFont(42); n_vtx->GetZaxis()->SetLabelFont(42); n_vtx->GetZaxis()->SetLabelOffset(0.007); n_vtx->GetZaxis()->SetLabelSize(0.035); n_vtx->GetZaxis()->SetTitleSize(0.045); n_vtx->GetZaxis()->SetTickLength(0.02); n_vtx->GetZaxis()->SetTitleFont(42); stack->Add(n_vtx,""); TH1F *n_vtx = new TH1F("n_vtx","n_vtx",40,0,40); n_vtx->SetBinContent(3,0.01200286); n_vtx->SetBinContent(4,0.005827657); n_vtx->SetBinContent(5,0.1511851); n_vtx->SetBinContent(6,0.2759911); n_vtx->SetBinContent(7,0.4648361); n_vtx->SetBinContent(8,0.5802456); n_vtx->SetBinContent(9,0.7968593); n_vtx->SetBinContent(10,1.064109); n_vtx->SetBinContent(11,1.067984); n_vtx->SetBinContent(12,1.508159); n_vtx->SetBinContent(13,1.258611); n_vtx->SetBinContent(14,1.090046); n_vtx->SetBinContent(15,1.496598); n_vtx->SetBinContent(16,1.441224); n_vtx->SetBinContent(17,1.455232); n_vtx->SetBinContent(18,1.17678); n_vtx->SetBinContent(19,0.8127122); n_vtx->SetBinContent(20,0.7422993); n_vtx->SetBinContent(21,0.6728876); n_vtx->SetBinContent(22,0.3947176); n_vtx->SetBinContent(23,0.5519482); n_vtx->SetBinContent(24,0.2973989); n_vtx->SetBinContent(25,0.2082458); n_vtx->SetBinContent(26,0.1261617); n_vtx->SetBinContent(27,0.1503758); n_vtx->SetBinContent(28,0.08080862); n_vtx->SetBinContent(29,0.07825356); n_vtx->SetBinContent(30,0.01572331); n_vtx->SetBinContent(31,0.03260526); n_vtx->SetBinContent(32,0.01380933); n_vtx->SetBinContent(33,0.003560861); n_vtx->SetBinContent(34,0.005436119); n_vtx->SetBinContent(35,0.0004869009); n_vtx->SetBinContent(36,0.01948288); n_vtx->SetBinContent(37,0.003629599); n_vtx->SetBinContent(38,0.0008120158); n_vtx->SetBinContent(39,5.000156e-06); n_vtx->SetBinContent(40,0.002108367); n_vtx->SetBinContent(41,4.946492e-06); n_vtx->SetBinError(3,0.008956971); n_vtx->SetBinError(4,0.004324972); n_vtx->SetBinError(5,0.04296497); n_vtx->SetBinError(6,0.05905175); n_vtx->SetBinError(7,0.07664539); n_vtx->SetBinError(8,0.08520366); n_vtx->SetBinError(9,0.09860399); n_vtx->SetBinError(10,0.1116876); n_vtx->SetBinError(11,0.1119905); n_vtx->SetBinError(12,0.1305362); n_vtx->SetBinError(13,0.1188291); n_vtx->SetBinError(14,0.1092546); n_vtx->SetBinError(15,0.1281548); n_vtx->SetBinError(16,0.1260957); n_vtx->SetBinError(17,0.1233163); n_vtx->SetBinError(18,0.1120955); n_vtx->SetBinError(19,0.08845784); n_vtx->SetBinError(20,0.08521948); n_vtx->SetBinError(21,0.07973374); n_vtx->SetBinError(22,0.05830111); n_vtx->SetBinError(23,0.07169088); n_vtx->SetBinError(24,0.05233831); n_vtx->SetBinError(25,0.0425704); n_vtx->SetBinError(26,0.02946411); n_vtx->SetBinError(27,0.03367296); n_vtx->SetBinError(28,0.02222677); n_vtx->SetBinError(29,0.0221685); n_vtx->SetBinError(30,0.00672539); n_vtx->SetBinError(31,0.01547269); n_vtx->SetBinError(32,0.01006282); n_vtx->SetBinError(33,0.002246514); n_vtx->SetBinError(34,0.002162354); n_vtx->SetBinError(35,0.0002494388); n_vtx->SetBinError(36,0.01453272); n_vtx->SetBinError(37,0.002581409); n_vtx->SetBinError(38,0.000603853); n_vtx->SetBinError(39,3.718351e-06); n_vtx->SetBinError(40,0.001571309); n_vtx->SetBinError(41,3.677911e-06); n_vtx->SetEntries(2155); n_vtx->SetStats(0); n_vtx->SetFillColor(3); n_vtx->SetLineColor(3); n_vtx->SetLineWidth(2); n_vtx->SetMarkerColor(3); n_vtx->SetMarkerStyle(21); n_vtx->SetMarkerSize(0.8); n_vtx->GetXaxis()->SetLabelFont(42); n_vtx->GetXaxis()->SetLabelOffset(0.007); n_vtx->GetXaxis()->SetLabelSize(0.035); n_vtx->GetXaxis()->SetTitleSize(0.045); n_vtx->GetXaxis()->SetTickLength(0.02); n_vtx->GetXaxis()->SetTitleOffset(0.9); n_vtx->GetXaxis()->SetTitleFont(42); n_vtx->GetYaxis()->SetLabelFont(42); n_vtx->GetYaxis()->SetLabelOffset(0.007); n_vtx->GetYaxis()->SetLabelSize(0.035); n_vtx->GetYaxis()->SetTitleSize(0.045); n_vtx->GetYaxis()->SetTickLength(0.02); n_vtx->GetYaxis()->SetTitleOffset(1.55); n_vtx->GetYaxis()->SetTitleFont(42); n_vtx->GetZaxis()->SetLabelFont(42); n_vtx->GetZaxis()->SetLabelOffset(0.007); n_vtx->GetZaxis()->SetLabelSize(0.035); n_vtx->GetZaxis()->SetTitleSize(0.045); n_vtx->GetZaxis()->SetTickLength(0.02); n_vtx->GetZaxis()->SetTitleFont(42); stack->Add(n_vtx,""); stack->Draw("hist"); TH1F *n_vtx = new TH1F("n_vtx","n_vtx",40,0,40); n_vtx->SetBinContent(6,1); n_vtx->SetBinContent(7,1); n_vtx->SetBinContent(8,1); n_vtx->SetBinContent(9,2); n_vtx->SetBinContent(10,4); n_vtx->SetBinContent(11,4); n_vtx->SetBinContent(12,6); n_vtx->SetBinContent(13,2); n_vtx->SetBinContent(14,5); n_vtx->SetBinContent(15,7); n_vtx->SetBinContent(16,7); n_vtx->SetBinContent(17,2); n_vtx->SetBinContent(18,4); n_vtx->SetBinContent(19,3); n_vtx->SetBinContent(20,2); n_vtx->SetBinContent(21,2); n_vtx->SetBinContent(22,2); n_vtx->SetBinContent(23,1); n_vtx->SetBinContent(24,2); n_vtx->SetBinContent(25,4); n_vtx->SetBinError(6,1); n_vtx->SetBinError(7,1); n_vtx->SetBinError(8,1); n_vtx->SetBinError(9,1.414214); n_vtx->SetBinError(10,2); n_vtx->SetBinError(11,2); n_vtx->SetBinError(12,2.44949); n_vtx->SetBinError(13,1.414214); n_vtx->SetBinError(14,2.236068); n_vtx->SetBinError(15,2.645751); n_vtx->SetBinError(16,2.645751); n_vtx->SetBinError(17,1.414214); n_vtx->SetBinError(18,2); n_vtx->SetBinError(19,1.732051); n_vtx->SetBinError(20,1.414214); n_vtx->SetBinError(21,1.414214); n_vtx->SetBinError(22,1.414214); n_vtx->SetBinError(23,1); n_vtx->SetBinError(24,1.414214); n_vtx->SetBinError(25,2); n_vtx->SetEntries(62); n_vtx->SetStats(0); n_vtx->SetFillColor(1); n_vtx->SetFillStyle(0); n_vtx->SetLineWidth(3); n_vtx->SetMarkerStyle(20); n_vtx->SetMarkerSize(1.3); n_vtx->GetXaxis()->SetLabelFont(42); n_vtx->GetXaxis()->SetLabelOffset(0.007); n_vtx->GetXaxis()->SetLabelSize(0.035); n_vtx->GetXaxis()->SetTitleSize(0.045); n_vtx->GetXaxis()->SetTickLength(0.02); n_vtx->GetXaxis()->SetTitleOffset(0.9); n_vtx->GetXaxis()->SetTitleFont(42); n_vtx->GetYaxis()->SetLabelFont(42); n_vtx->GetYaxis()->SetLabelOffset(0.007); n_vtx->GetYaxis()->SetLabelSize(0.035); n_vtx->GetYaxis()->SetTitleSize(0.045); n_vtx->GetYaxis()->SetTickLength(0.02); n_vtx->GetYaxis()->SetTitleOffset(1.55); n_vtx->GetYaxis()->SetTitleFont(42); n_vtx->GetZaxis()->SetLabelFont(42); n_vtx->GetZaxis()->SetLabelOffset(0.007); n_vtx->GetZaxis()->SetLabelSize(0.035); n_vtx->GetZaxis()->SetTitleSize(0.045); n_vtx->GetZaxis()->SetTickLength(0.02); n_vtx->GetZaxis()->SetTitleFont(42); n_vtx->Draw("SAMEPE1"); TH1F *n_vtx = new TH1F("n_vtx","n_vtx",40,0,40); n_vtx->SetStats(0); n_vtx->SetFillColor(1); n_vtx->SetFillStyle(0); n_vtx->SetLineStyle(2); n_vtx->SetLineWidth(3); n_vtx->SetMarkerSize(0.8); n_vtx->GetXaxis()->SetLabelFont(42); n_vtx->GetXaxis()->SetLabelOffset(0.007); n_vtx->GetXaxis()->SetLabelSize(0.035); n_vtx->GetXaxis()->SetTitleSize(0.045); n_vtx->GetXaxis()->SetTickLength(0.02); n_vtx->GetXaxis()->SetTitleOffset(0.9); n_vtx->GetXaxis()->SetTitleFont(42); n_vtx->GetYaxis()->SetLabelFont(42); n_vtx->GetYaxis()->SetLabelOffset(0.007); n_vtx->GetYaxis()->SetLabelSize(0.035); n_vtx->GetYaxis()->SetTitleSize(0.045); n_vtx->GetYaxis()->SetTickLength(0.02); n_vtx->GetYaxis()->SetTitleOffset(1.55); n_vtx->GetYaxis()->SetTitleFont(42); n_vtx->GetZaxis()->SetLabelFont(42); n_vtx->GetZaxis()->SetLabelOffset(0.007); n_vtx->GetZaxis()->SetLabelSize(0.035); n_vtx->GetZaxis()->SetTitleSize(0.045); n_vtx->GetZaxis()->SetTickLength(0.02); n_vtx->GetZaxis()->SetTitleFont(42); n_vtx->Draw("SAMEHIST"); TLatex * tex = new TLatex(0.95,0.965,"CJVfail"); tex->SetNDC(); tex->SetTextAlign(31); tex->SetTextSize(0.03); tex->SetLineWidth(2); tex->Draw(); tex = new TLatex(0.16,0.965,"CMS Preliminary 2012, #sqrt{s} = 8 TeV, 19.5 fb^{-1}"); tex->SetNDC(); tex->SetTextSize(0.03); tex->SetLineWidth(2); tex->Draw(); TLegend *leg = new TLegend(0.6,0.605,0.92,0.92,NULL,"brNDC"); leg->SetBorderSize(1); leg->SetLineColor(0); leg->SetLineStyle(1); leg->SetLineWidth(1); leg->SetFillColor(0); leg->SetFillStyle(1001); TLegendEntry *entry=leg->AddEntry("n_vtx","VBF m_{H}=120 GeV","fl"); entry->SetFillColor(1); entry->SetLineColor(1); entry->SetLineStyle(2); entry->SetLineWidth(3); entry->SetMarkerColor(1); entry->SetMarkerStyle(21); entry->SetMarkerSize(1); entry=leg->AddEntry("n_vtx","Data","lp"); entry->SetLineColor(1); entry->SetLineStyle(1); entry->SetLineWidth(3); entry->SetMarkerColor(1); entry->SetMarkerStyle(20); entry->SetMarkerSize(1.3); entry=leg->AddEntry("n_vtx","Z+jets,EWK Z","f"); entry->SetFillColor(3); entry->SetFillStyle(1001); entry->SetLineColor(3); entry->SetLineStyle(1); entry->SetLineWidth(2); entry->SetMarkerColor(1); entry->SetMarkerStyle(21); entry->SetMarkerSize(1); entry=leg->AddEntry("n_vtx","EWK W+jets","f"); ci = TColor::GetColor("#660099"); entry->SetFillColor(ci); entry->SetFillStyle(1001); ci = TColor::GetColor("#660099"); entry->SetLineColor(ci); entry->SetLineStyle(1); entry->SetLineWidth(2); entry->SetMarkerColor(1); entry->SetMarkerStyle(21); entry->SetMarkerSize(1); entry=leg->AddEntry("n_vtx","QCD W+jets","f"); entry->SetFillColor(6); entry->SetFillStyle(1001); entry->SetLineColor(6); entry->SetLineStyle(1); entry->SetLineWidth(2); entry->SetMarkerColor(1); entry->SetMarkerStyle(21); entry->SetMarkerSize(1); entry=leg->AddEntry("n_vtx","t#bar{t},t,tW","f"); entry->SetFillColor(5); entry->SetFillStyle(1001); entry->SetLineColor(5); entry->SetLineStyle(1); entry->SetLineWidth(2); entry->SetMarkerColor(1); entry->SetMarkerStyle(21); entry->SetMarkerSize(1); entry=leg->AddEntry("n_vtx","Dibosons","f"); entry->SetFillColor(4); entry->SetFillStyle(1001); entry->SetLineColor(4); entry->SetLineStyle(1); entry->SetLineWidth(2); entry->SetMarkerColor(1); entry->SetMarkerStyle(21); entry->SetMarkerSize(1); leg->Draw(); upper->Modified(); canv->cd(); // ------------>Primitives in pad: lower lower = new TPad("lower", "pad",0,0,1,0.26); lower->Draw(); lower->cd(); lower->Range(-8.101265,-0.653951,42.53165,2.070845); lower->SetFillColor(0); lower->SetBorderMode(0); lower->SetBorderSize(2); lower->SetGridy(); lower->SetTickx(1); lower->SetTicky(1); lower->SetLeftMargin(0.16); lower->SetRightMargin(0.05); lower->SetTopMargin(0.026); lower->SetBottomMargin(0.24); lower->SetFrameFillStyle(0); lower->SetFrameLineStyle(0); lower->SetFrameLineWidth(2); lower->SetFrameBorderMode(0); lower->SetFrameBorderSize(10); lower->SetFrameFillStyle(0); lower->SetFrameLineStyle(0); lower->SetFrameLineWidth(2); lower->SetFrameBorderMode(0); lower->SetFrameBorderSize(10); TH1F *n_vtx = new TH1F("n_vtx","n_vtx",40,0,40); n_vtx->SetBinContent(6,1.037786); n_vtx->SetBinContent(7,0.8477826); n_vtx->SetBinContent(8,0.4345504); n_vtx->SetBinContent(9,0.7396804); n_vtx->SetBinContent(10,1.191539); n_vtx->SetBinContent(11,0.7062074); n_vtx->SetBinContent(12,1.013874); n_vtx->SetBinContent(13,0.3599852); n_vtx->SetBinContent(14,1.133013); n_vtx->SetBinContent(15,1.004876); n_vtx->SetBinContent(16,1.144451); n_vtx->SetBinContent(17,0.4490612); n_vtx->SetBinContent(18,0.8736024); n_vtx->SetBinContent(19,0.4956068); n_vtx->SetBinContent(20,0.542695); n_vtx->SetBinContent(21,0.9202909); n_vtx->SetBinContent(22,0.8148116); n_vtx->SetBinContent(23,0.6637713); n_vtx->SetBinContent(24,1.319737); n_vtx->SetBinContent(25,3.234601); n_vtx->SetBinError(6,1.087112); n_vtx->SetBinError(7,0.8743721); n_vtx->SetBinError(8,0.4428307); n_vtx->SetBinError(9,0.5625427); n_vtx->SetBinError(10,0.6267422); n_vtx->SetBinError(11,0.3737154); n_vtx->SetBinError(12,0.4574491); n_vtx->SetBinError(13,0.2625916); n_vtx->SetBinError(14,0.5286451); n_vtx->SetBinError(15,0.4480036); n_vtx->SetBinError(16,0.4925594); n_vtx->SetBinError(17,0.3219451); n_vtx->SetBinError(18,0.4497534); n_vtx->SetBinError(19,0.3083196); n_vtx->SetBinError(20,0.4038772); n_vtx->SetBinError(21,0.6779213); n_vtx->SetBinError(22,0.6250587); n_vtx->SetBinError(23,0.6762894); n_vtx->SetBinError(24,0.9763606); n_vtx->SetBinError(25,2.125219); n_vtx->SetMinimum(0); n_vtx->SetMaximum(2); n_vtx->SetEntries(31.61001); n_vtx->SetStats(0); n_vtx->SetFillStyle(0); n_vtx->SetMarkerStyle(20); n_vtx->SetMarkerSize(0.8); n_vtx->GetXaxis()->SetTitle("Number of vertices"); n_vtx->GetXaxis()->SetLabelFont(42); n_vtx->GetXaxis()->SetLabelOffset(0.007); n_vtx->GetXaxis()->SetLabelSize(0.1); n_vtx->GetXaxis()->SetTitleSize(0.12); n_vtx->GetXaxis()->SetTickLength(0.02); n_vtx->GetXaxis()->SetTitleOffset(0.9); n_vtx->GetXaxis()->SetTitleFont(42); n_vtx->GetYaxis()->SetTitle("Data/MC"); n_vtx->GetYaxis()->SetNdivisions(505); n_vtx->GetYaxis()->SetLabelFont(42); n_vtx->GetYaxis()->SetLabelOffset(0.007); n_vtx->GetYaxis()->SetLabelSize(0.1); n_vtx->GetYaxis()->SetTitleSize(0.12); n_vtx->GetYaxis()->SetTickLength(0.02); n_vtx->GetYaxis()->SetTitleOffset(0.55); n_vtx->GetYaxis()->SetTitleFont(42); n_vtx->GetZaxis()->SetLabelFont(42); n_vtx->GetZaxis()->SetLabelOffset(0.007); n_vtx->GetZaxis()->SetLabelSize(0.035); n_vtx->GetZaxis()->SetTitleSize(0.045); n_vtx->GetZaxis()->SetTickLength(0.02); n_vtx->GetZaxis()->SetTitleFont(42); n_vtx->Draw("PE1"); lower->Modified(); canv->cd(); canv->Modified(); canv->cd(); canv->SetSelected(canv); }
753c99a62f1272c3f26698fc0137cdfb414f3f9c
7fdb8017a2f4d2150627d40f3d3a43f73340ed97
/eclipse-workspaceClases/Clase3_1/src/Prueba1.c
f1668f2fb021566b76e6e1cca0d42db5b35ebca3
[]
no_license
LudmilaMagri/Clases_LAB_1
a823ed6468457bef407ddd2c0c4d702449a9cc24
2c0675fc4045ce4e47931480c76cc346b29434d2
refs/heads/master
2023-04-03T22:55:47.279203
2021-04-22T11:54:40
2021-04-22T11:54:40
357,360,831
0
0
null
null
null
null
UTF-8
C
false
false
1,141
c
Prueba1.c
/* ============================================================================ Name : Prueba1.c Author : Version : Copyright : Your copyright notice Description : Hello World in C, Ansi-style ============================================================================ */ #include <stdio.h> #include <stdlib.h> int sumarConLimite (int operador1, int operador2); //declaro el prototipo int main(void) { setbuf (stdout, NULL); int num1; int num2; int suma; printf ("Ingrese un numero"); scanf ("%d", &num1); printf ("Ingrese otro numero"); scanf ("%d", &num2); suma = sumarConLimite (num1, num2); printf("La suma es %d", suma); return EXIT_SUCCESS; } //funciones auxiliares de mi programa //definicion de la funcion sumarConLimite //TIPO NOMBRE FUNCION (TIPO NOMBRE ARGUMENTO.. ) int sumarConLimite (int operador1, int operador2) //prototipo { int resultado; //variable local de la funcion. Adentro de esta funcion num1 y num2 no existen porque murieron en main resultado= operador1+operador2; if (resultado>100) { resultado= 100; } //retornar valor return resultado; }
f0210ff25dfdb7cb876ffe4c373e2ba84c7e303d
e9b7beb535c0791e11a9b10676b3b40c016da931
/.ss/data_analysys.c
323faa5e221ee374655409095a69bb3641c4d5c3
[]
no_license
lakshmirajkumar/backup
2de45fbeb10100ee0d1432fbdeb44e64abe22596
b28e3d15d59faaba0bc715178b85f9e54063a5db
refs/heads/master
2021-09-03T03:59:59.479361
2018-01-05T11:39:19
2018-01-05T11:39:19
103,488,022
0
0
null
null
null
null
UTF-8
C
false
false
766
c
data_analysys.c
#include <stdio.h> #include <string.h> #define arraylength 20 int main () { int data[arraylength],address[arraylength],pre_data[arraylength]; int temp = 0,temp1 = 0; for (int i = 0; i < arraylength; i++) { printf("address:"); scanf("%d", &temp); printf("data:"); scanf("%d", &temp1); if(address[i-1] > temp){ printf("less value\n"); for(int j=0;j<arraylength;j++){ pre_data[j]=data[j]; } i=0; for (int j =0; j < arraylength; j++ ) { if(pre_data[j] != data[i]) printf("error\n"); else printf("no error\n"); } } address[i]= temp ; data[i]=temp1; } /* for (int i =0; i < arraylength; i++ ) { printf("%d \t %d\n", address[i],data[i]); } */ }
225b95f3ee7c88e2d83eeceb7c330244d3a22cc2
2960450028949659192a05ecfec4ede020f3c05d
/src/libraries/lightning/app_lightning.c
c40e7555b92eb8c93d02f50bd065f9b340d835db
[]
no_license
Dersalis-BR/zephyr-rak5010
12c5d2862a9a3335b4c78d30df06f22afc893560
b193a50db23dafcbef69910ef39956530de79d86
refs/heads/master
2022-04-16T18:52:55.284363
2020-03-18T13:35:41
2020-03-18T13:35:41
238,657,225
2
3
null
null
null
null
UTF-8
C
false
false
65
c
app_lightning.c
#include "app_lightning.h" void app_lightning_init(void){ }
bb38c6963a8a5821bdea38edfeaab8f029fa9738
08d9329d782611129398ae9814a8e43991a8a979
/minishell.h
a7883bad18b0d97fdd9b573d177a9c818a20ac44
[]
no_license
yaellem/Minishell
2aa436e8906f39cfcf73905480e5f92cf910d0b9
eaa1699907cc0ce4551075c2ab4b884133feb809
refs/heads/master
2020-03-21T19:20:33.234947
2018-09-12T18:43:34
2018-09-12T18:43:34
138,943,481
0
0
null
null
null
null
UTF-8
C
false
false
3,291
h
minishell.h
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* minishell.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: ymarcill <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2018/09/09 02:52:07 by ymarcill #+# #+# */ /* Updated: 2018/09/12 19:58:22 by ymarcill ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef MINISHELL_H # define MINISHELL_H # include <stdlib.h> # include <unistd.h> # include <fcntl.h> # include <dirent.h> # include <sys/stat.h> # include <sys/wait.h> # include <signal.h> # include <stdio.h> # include "libft/libft.h" # include <errno.h> # define TEXT_COLOR_CYAN "\x1b[36m" # define TEXT_COLOR_GREEN "\x1b[32m" # define TEXT_COLOR_RED "\x1b[31m" # define TEXT_COLOR_RESET "\x1b[0m" typedef struct s_read { DIR *ptr; struct stat buf; char *getp; char **getl; char tmp[255]; char *path; char *temp; char *dst; struct dirent *file; } t_read; typedef struct s_env { char **tmp; char **nwenv; char ***nwav; char *str; char *freem; char *line; char *dst; char *temp; char *strim; char **envcopy; } t_env; typedef struct s_index { int i; int y; int x; int z; int check; int test; int opt; int j; char *tmp; pid_t father; } t_index; char *if_dollar(char *str, char **envp, char *dst, int x); char *is_good_end(char *temp, char *dst, char *tmp); char *if_not_var(char *strim, char *str, char *dst, int x); char *iscequal(char *str); char *check_occ_bis(char *envcopy, char *nwav, int *check); char **minishell_core(char **nwav, char **nwenv); int is_char(char *str, char c); int ft_tablen(char **tab); char *trim(char *str); void minishell(char *line, char **nwenv); char **envrmt(char **envp); char ***virgule_point(char *line); char *dollar(char *string, char **env); char **get_line(char **env); char *getpath(char **nwav, char **path); int builtin_gestion(char **nwav, char ***env); int binary_gestion(char **nwav, char **nwenv, char *str); void myecho(char **nwav, char **env); int ch_dir(char *str, char ***envp); char *change_dir_special(char *str, char **envp); char *tilde(char **envp); char *tiret(char **envp); void setold(char ***envp); void setpwd(char ***envp); char **set_env(char **nwav, char ***env, char *str); char **unset_env(char **name, char ***env); char **envi(char ***envp, char **nwav); void pwd(char **nwav); void pwd_bis(); int ft_is_here(char *str, char c); void ft_freetab(char **s1); void ft_freetrtab(char ***s1); void print_tab_a(char **str); char **ft_strsplitq(char const *s, char c); char *ft_strdupn(char *str, char c); char *ft_strldup(char *str, char c); char *ft_strinddup(char *str, char c); #endif
1152e3f720cd4aa9855ae56c1dc98f4cc9de79eb
f74c510024c241226c94c9021152808e237f8fd9
/Microchip Solutions v2012-10-15/USB/Device - Bootloaders/HID/Firmware - PIC18 Non-J/main.c
6da5d3c38bf3de8bfa975df90c61c6754819d6ac
[]
no_license
hardkernel/Odroid-USBIO
7818e6784aaead45469ef8e0def7b2ab6b18aff7
5a8bf576f6285b5fb569bb5ad84be194b37460c0
refs/heads/master
2021-01-18T08:26:34.267815
2019-03-21T06:01:10
2019-03-21T06:01:10
8,197,430
17
15
null
2015-10-15T05:35:06
2013-02-14T10:22:58
C
WINDOWS-1258
C
false
false
19,241
c
main.c
/********************************************************************* * * Microchip USB HID Bootloader for PIC18 (Non-J Family) USB Microcontrollers * ********************************************************************* * FileName: main.c * Dependencies: See INCLUDES section below * Processor: PIC18 * Compiler: C18 3.42+ * Company: Microchip Technology, Inc. * * Software License Agreement * * The software supplied herewith by Microchip Technology Incorporated * (the "Company") for its PIC® Microcontroller is intended and * supplied to you, the Company's customer, for use solely and * exclusively on Microchip PICmicro Microcontroller products. The * software is owned by the Company and/or its supplier, and is * protected under applicable copyright laws. All rights are reserved. * Any use in violation of the foregoing restrictions may subject the * user to criminal sanctions under applicable laws, as well as to * civil liability for the breach of the terms and conditions of this * license. * * THIS SOFTWARE IS PROVIDED IN AN "AS IS"” CONDITION. 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. THE COMPANY SHALL NOT, * IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. * * File Version Date Comment *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * 1.0 06/19/2008 Original Version. Adapted from * MCHPFSUSB v2.1 HID Bootloader * for PIC18F87J50 Family devices. * 2.9f 06/26/2012 Added PIC18F45K50 Family support. ********************************************************************/ /********************************************************************* IMPORTANT NOTES: This code is currently configured to work with the PIC18F4550 using the PICDEM FS USB Demo Board. However, this code can be readily adapted for use with the both the F and LF versions of the following devices: PIC18F4553/4458/2553/2458 PIC18F4550/4455/2550/2455 PIC18F4450/2450 PIC18F14K50/13K50 PIC18F45K50/25K50/24K50 To do so, replace the linker script with an appropriate version, and click "Configure --> Select Device" and select the proper microcontroller. Also double check to verify that the io_cfg.h and usbcfg.h are properly configured to match your desired application platform. Verify that the coniguration bits are set correctly for the intended target application, and fix any build errors that result from either the #error directives, or due to I/O pin count mismatch issues (such as when using a 28-pin device, but without making sufficient changes to the io_cfg.h file) This project needs to be built with the C18 compiler optimizations enabled, or the total code size will be too large to fit within the program memory range 0x000-0xFFF. The default linker script included in the project has this range reserved for the use by the bootloader, but marks the rest of program memory as "PROTECTED". If you try to build this project with the compiler optimizations turned off, or you try to modify some of this code, but add too much code to fit within the 0x000-0xFFF region, a linker error like that below may occur: Error - section '.code_main.o' can not fit the section. Section '.code_main.o' length=0x00000082 To fix this error, either optimize the program to fit within 0x000-0xFFF (such as by turning on compiler optimizations), or modify the linker and vector remapping (as well as the application projects) to allow this bootloader to use more program memory. *********************************************************************/ /** I N C L U D E S **********************************************************/ #include <p18cxxx.h> #include "typedefs.h" #include "usb.h" #include "io_cfg.h" #include "BootPIC18NonJ.h" /** C O N F I G U R A T I O N ************************************************/ // Note: For a complete list of the available config pragmas and their values, // see the compiler documentation, and/or click "Help --> Topics..." and then // select "PIC18 Config Settings" in the Language Tools section. #if defined(PIC18F4550_PICDEM_FS_USB) // Configuration bits for PICDEM FS USB Demo Board #if defined(__18F4550) || defined(__18F4553) #pragma config PLLDIV = 5 // (20 MHz crystal on PICDEM FS USB board) #pragma config CPUDIV = OSC1_PLL2 #pragma config USBDIV = 2 // Clock source from 96MHz PLL/2 #pragma config FOSC = HSPLL_HS #pragma config FCMEN = OFF #pragma config IESO = OFF #pragma config PWRT = OFF #pragma config BOR = ON #pragma config BORV = 3 #pragma config VREGEN = ON //USB Voltage Regulator #pragma config WDT = OFF #pragma config WDTPS = 32768 #pragma config MCLRE = ON #pragma config LPT1OSC = OFF #pragma config PBADEN = OFF //NOTE: modifying this value here won't have an effect //on the application. See the top of the main() function. //By default the RB4 I/O pin is used to detect if the //firmware should enter the bootloader or the main application //firmware after a reset. In order to do this, it needs to //configure RB4 as a digital input, thereby changing it from //the reset value according to this configuration bit. // #pragma config CCP2MX = ON #pragma config STVREN = ON #pragma config LVP = OFF // #pragma config ICPRT = OFF // Dedicated In-Circuit Debug/Programming #pragma config XINST = OFF // Extended Instruction Set #pragma config CP0 = OFF #pragma config CP1 = OFF // #pragma config CP2 = OFF // #pragma config CP3 = OFF #pragma config CPB = OFF // #pragma config CPD = OFF #pragma config WRT0 = OFF #pragma config WRT1 = OFF // #pragma config WRT2 = OFF // #pragma config WRT3 = OFF #pragma config WRTB = OFF // Boot Block Write Protection #pragma config WRTC = OFF // #pragma config WRTD = OFF #pragma config EBTR0 = OFF #pragma config EBTR1 = OFF // #pragma config EBTR2 = OFF // #pragma config EBTR3 = OFF #pragma config EBTRB = OFF #endif //18F4550 and 18F4553 #elif defined(PIC18F4550_PICDEM_FS_USB_K50) #pragma config PLLSEL = PLL3X // 3X PLL multiplier selected #pragma config CFGPLLEN = OFF // PLL turned on during execution #pragma config CPUDIV = NOCLKDIV // 1:1 mode (for 48MHz CPU) #pragma config LS48MHZ = SYS48X8 // Clock div / 8 in Low Speed USB mode #pragma config FOSC = INTOSCIO // HFINTOSC selected at powerup, no clock out #pragma config PCLKEN = OFF // Primary oscillator driver #pragma config FCMEN = OFF // Fail safe clock monitor #pragma config IESO = OFF // Internal/external switchover (two speed startup) #pragma config nPWRTEN = OFF // Power up timer #pragma config BOREN = SBORDIS // BOR enabled #pragma config nLPBOR = ON // Low Power BOR #pragma config WDTEN = SWON // Watchdog Timer controlled by SWDTEN #pragma config WDTPS = 32768 // WDT postscalar #pragma config PBADEN = OFF // Port B Digital/Analog Powerup Behavior #pragma config SDOMX = RC7 // SDO function location #pragma config LVP = OFF // Low voltage programming #pragma config MCLRE = ON // MCLR function enabled (RE3 disabled) #pragma config STVREN = ON // Stack overflow reset //#pragma config ICPRT = OFF // Dedicated ICPORT program/debug pins enable #pragma config XINST = OFF // Extended instruction set //If using the YOUR_BOARD hardware platform (see usbcfg.h), uncomment below and add pragmas //#elif defined(YOUR_BOARD) //Add the configuration pragmas here for your hardware platform //#pragma config ... = ... #elif defined(LOW_PIN_COUNT_USB_DEVELOPMENT_KIT) //14K50 #if !defined(__18F14K50) && !defined(__18F13K50) && !defined(__18LF14K50) && !defined(__18LF13K50) #error Wrong processor selected for the selected demo board. #endif #pragma config CPUDIV = NOCLKDIV #pragma config USBDIV = OFF #pragma config FOSC = HS #pragma config PLLEN = ON #pragma config FCMEN = OFF #pragma config IESO = OFF #pragma config PWRTEN = OFF #pragma config BOREN = OFF #pragma config BORV = 30 #pragma config WDTEN = OFF #pragma config WDTPS = 32768 #pragma config MCLRE = OFF #pragma config HFOFST = OFF #pragma config STVREN = ON #pragma config LVP = OFF #pragma config XINST = OFF #pragma config BBSIZ = OFF #pragma config CP0 = OFF #pragma config CP1 = OFF #pragma config CPB = OFF #pragma config WRT0 = OFF #pragma config WRT1 = OFF #pragma config WRTB = OFF #pragma config WRTC = OFF #pragma config EBTR0 = OFF #pragma config EBTR1 = OFF #pragma config EBTRB = OFF #else #error Not a supported board (yet), make sure the proper board is selected in usbcfg.h, and if so, set configuration bits in __FILE__, line __LINE__ #endif /** V A R I A B L E S ********************************************************/ #pragma udata /** P R I V A T E P R O T O T Y P E S ***************************************/ static void InitializeSystem(void); void USBTasks(void); #if !defined(__18F14K50) && !defined(__18F13K50) && !defined(__18LF14K50) && !defined(__18LF13K50) void BlinkUSBStatus(void); #else #define BlinkUSBStatus() #endif /** V E C T O R R E M A P P I N G *******************************************/ #pragma code high_vector=0x08 void interrupt_at_high_vector(void) { _asm goto 0x1008 _endasm } #pragma code low_vector=0x18 void interrupt_at_low_vector(void) { _asm goto 0x1018 _endasm } /** D E C L A R A T I O N S **************************************************/ #pragma code /****************************************************************************** * Function: void main(void) * * PreCondition: None * * Input: None * * Output: None * * Side Effects: None * * Overview: Main program entry point. * * Note: None *****************************************************************************/ void main(void) { //Need to make sure RB4 can be used as a digital input pin. #if defined(PIC18F4550_PICDEM_FS_USB_K50) #if defined(HARDKERNEL_PIC18F45K50) unsigned char ANSELDSave; ANSELDSave = ANSELD; ANSELDbits.ANSD3 = 0; //Configure RD3/AN23 for digital input capability #else unsigned char ANSELBSave; ANSELBSave = ANSELB; ANSELBbits.ANSB4 = 0; //Configure RB4/AN11 for digital input capability #endif #else ADCON1 = 0x0F; //Need to make sure RB4 can be used as a digital input pin #endif // TRISBbits.TRISB4 = 1; //No need to explicitly do this since reset state is = 1 already. //Check Bootload Mode Entry Condition if(sw2 == 1) { //Restore default "reset" value of registers we may have modified temporarily. #if defined(PIC18F4550_PICDEM_FS_USB_K50) #if defined(HARDKERNEL_PIC18F45K50) ANSELD = ANSELDSave; #else ANSELB = ANSELBSave; #endif #else ADCON1 = 0x07; //Restore "reset value" of the ADCON1 register #endif _asm goto 0x1000 //If the user is not trying to enter the bootloader, go straight to the main application remapped "reset" vector. _endasm } //We have decided to stay in this bootloader firwmare project. Initialize //this firmware and the USB module. InitializeSystem(); //Execute main loop while(1) { ClrWdt(); USBTasks(); // Need to call USBTasks() periodically // it handles SETUP packets needed for enumeration BlinkUSBStatus(); if((usb_device_state == CONFIGURED_STATE) && (UCONbits.SUSPND != 1)) { ProcessIO(); // This is where all the actual bootloader related data transfer/self programming takes place } // see ProcessIO() function in the Boot87J50Family.c file. }//end while }//end main /****************************************************************************** * Function: static void InitializeSystem(void) * * PreCondition: None * * Input: None * * Output: None * * Side Effects: None * * Overview: InitializeSystem is a centralize initialization routine. * All required USB initialization routines are called from * here. * * User application initialization routine should also be * called from here. * * Note: None *****************************************************************************/ static void InitializeSystem(void) { // The USB specifications require that USB peripheral devices must never source // current onto the Vbus pin. Additionally, USB peripherals should not source // current on D+ or D- when the host/hub is not actively powering the Vbus line. // When designing a self powered (as opposed to bus powered) USB peripheral // device, the firmware should make sure not to turn on the USB module and D+ // or D- pull up resistor unless Vbus is actively powered. Therefore, the // firmware needs some means to detect when Vbus is being powered by the host. // A 5V tolerant I/O pin can be connected to Vbus (through a resistor), and // can be used to detect when Vbus is high (host actively powering), or low // (host is shut down or otherwise not supplying power). The USB firmware // can then periodically poll this I/O pin to know when it is okay to turn on // the USB module/D+/D- pull up resistor. When designing a purely bus powered // peripheral device, it is not possible to source current on D+ or D- when the // host is not actively providing power on Vbus. Therefore, implementing this // bus sense feature is optional. This firmware can be made to use this bus // sense feature by making sure "USE_USB_BUS_SENSE_IO" has been defined in the // usbcfg.h file. #if defined(USE_USB_BUS_SENSE_IO) tris_usb_bus_sense = INPUT_PIN; // See io_cfg.h #endif // If the host PC sends a GetStatus (device) request, the firmware must respond // and let the host know if the USB peripheral device is currently bus powered // or self powered. See chapter 9 in the official USB specifications for details // regarding this request. If the peripheral device is capable of being both // self and bus powered, it should not return a hard coded value for this request. // Instead, firmware should check if it is currently self or bus powered, and // respond accordingly. If the hardware has been configured like demonstrated // on the PICDEM FS USB Demo Board, an I/O pin can be polled to determine the // currently selected power source. On the PICDEM FS USB Demo Board, "RA2" // is used for this purpose. If using this feature, make sure "USE_SELF_POWER_SENSE_IO" // has been defined in usbcfg.h, and that an appropriate I/O pin has been mapped // to it in io_cfg.h. #if defined(USE_SELF_POWER_SENSE_IO) tris_self_power = INPUT_PIN; #endif //Initialize oscillator settings compatible with USB operation. Note, //these may be application specific! #if defined(PIC18F4550_PICDEM_FS_USB_K50) OSCTUNE = 0x80; //3X PLL ratio mode selected OSCCON = 0x70; //Switch to 16MHz HFINTOSC OSCCON2 = 0x10; //Enable PLL, SOSC, PRI OSC drivers turned off while(OSCCON2bits.PLLRDY != 1); //Wait for PLL lock *((unsigned char*)0xFB5) = 0x90; //Enable active clock tuning for USB operation #endif mInitializeUSBDriver(); // See usbdrv.h UserInit(); // See user.c & .h }//end InitializeSystem /****************************************************************************** * Function: void USBTasks(void) * * PreCondition: InitializeSystem has been called. * * Input: None * * Output: None * * Side Effects: None * * Overview: Service loop for USB tasks. * * Note: None *****************************************************************************/ void USBTasks(void) { /* * Servicing Hardware */ USBCheckBusStatus(); // Must use polling method USBDriverService(); // Interrupt or polling method }// end USBTasks /****************************************************************************** * Function: void BlinkUSBStatus(void) * * PreCondition: None * * Input: None * * Output: None * * Side Effects: None * * Overview: BlinkUSBStatus turns on and off LEDs corresponding to * the USB device state. * * Note: mLED macros can be found in io_cfg.h * usb_device_state is declared in usbmmap.c and is modified * in usbdrv.c, usbctrltrf.c, and usb9.c *****************************************************************************/ #if !defined(__18F14K50) && !defined(__18F13K50) && !defined(__18LF14K50) && !defined(__18LF13K50) void BlinkUSBStatus(void) { static word led_count=0; if(led_count == 0)led_count = 10000U; led_count--; #define mLED_Both_Off() {mLED_1_Off();mLED_2_Off();} #define mLED_Both_On() {mLED_1_On();mLED_2_On();} #define mLED_Only_1_On() {mLED_1_On();mLED_2_Off();} #define mLED_Only_2_On() {mLED_1_Off();mLED_2_On();} if(usb_device_state < CONFIGURED_STATE) { mLED_Only_1_On(); } else { if(led_count==0) { mLED_1_Toggle(); mLED_2 = !mLED_1; // Alternate blink }//end if }//end if(...) }//end BlinkUSBStatus #endif /** EOF main.c ***************************************************************/
c047f933a120f55079e84583dfa87448dd60f0d6
2148c987c4b008453d5034ef33cbce886c241a3b
/firmware/blink/main.c
29c3807bd51a0fdfdcaa7f35f9d751dffe74d60f
[ "Apache-2.0" ]
permissive
ytai/ioio
94cebdb9b97163be2fefb6d9a362d184b2d157c2
42f156cd676f14c6a503464bb33feb83353484f6
refs/heads/master
2023-08-30T23:36:00.823993
2023-08-24T05:00:03
2023-08-24T05:00:03
2,272,409
477
201
Apache-2.0
2023-09-11T03:26:53
2011-08-26T04:59:57
C
UTF-8
C
false
false
350
c
main.c
#define GetSystemClock() 32000000UL #define GetPeripheralClock() (GetSystemClock()) #define GetInstructionClock() (GetSystemClock() / 2) #include "Compiler.h" #include "timer.h" #include "platform.h" int main() { led_init(); while (1) { led_on(); DelayMs(500); led_off(); DelayMs(500); } return 0; }
6a3e9b8a29f88f09f58d27bb4b6c1629bd82edf5
47f4448a71ff3c308198a6168391b458a92b3d1f
/sortSearch/sortSearch/sortSearch/sortSearch.c
241f00ef2a67e087b7a48ad7ca0aef505419d443
[]
no_license
audioshiba/COP1000C
f5da3474b10cec81b495654abf8737da0eb730b8
1cfd9c9c635b7216377edd954d1cb5fa393c7187
refs/heads/master
2020-05-04T15:15:56.511889
2019-04-03T07:30:32
2019-04-03T07:30:32
null
0
0
null
null
null
null
UTF-8
C
false
false
7,084
c
sortSearch.c
//Name: Jonathan De La Cruz //Date: 11/27/18 //Purpose: sortSearch #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #include <time.h> #include <ctype.h> #include <string.h> #include <math.h> #define PAUSE system("pause") #define CLS system("cls") #define FLUSH myFlush() #define SIZE 500 //prototype here float calcAdjAverage(float a[], int eS); float calcAverage(float a[], int eS); void displayAdjustedAverage(float a[], int eS, int flag); void displayAverage(float a[],int eS, int flag); void displayHighest(float gpa[], int eS, int flag); void displayLowest(float gpa[], int eS, int flag); void displayMenu(); void displaySorted(float a[], int eS, int flag); char getChoice(); int getGpa(float gpas[], int eS); void myFlush(); char swapValues(int array[], int location); void searchGpa(float a[], int eS, int flag); void sort(float array[], int eS); void sortAsc(float array[], int eS); int tripFlag(); main() { //decalre stuff here char choice; float gpaArray[SIZE] = { 0.00 }; int eSize = 0; int flag = 0; //do stuff here do { CLS; displayMenu(); choice = getChoice(); switch (choice) { case 'A': eSize = getGpa(gpaArray, eSize); flag = tripFlag(); break; case 'B': displayAverage(gpaArray, eSize, flag); break; case 'C': displayHighest(gpaArray, eSize, flag); break; case 'D': displayLowest(gpaArray, eSize, flag); break; case 'E': displayAdjustedAverage(gpaArray, eSize, flag); break; case 'F': searchGpa(gpaArray, eSize, flag); break; case 'G': displaySorted(gpaArray, eSize, flag); break; case 'Q': break; default: printf("\nPlease enter a valid selection!\n"); PAUSE; }//end switch } while (choice != 'Q'); PAUSE; }//end main /*=============================================================================================== ===============================================================================================*/ float calcAdjAverage(float a[], int eS) { float result; float sum = 0; for (int i = 0; i < eS - 1; i++) sum = a[i] + sum; result = sum / (eS - 1); return result; }//end calcAdjAverage float calcAverage(float a[], int eS) { float result; float sum = 0; for (int i = 0; i < eS; i++) sum = a[i] + sum; result = sum / eS; return result; }//end calcAverage void displayAdjustedAverage(float a[], int eS, int flag) { CLS; float adjAverage; if (flag == 0) { printf("Please go back and enter some GPAs first!\n\n"); PAUSE; return; }//end if if (eS == 1) { printf("Please enter 2 or more values before using this function.\n\n"); PAUSE; return; }//end if sort(a, eS); adjAverage = calcAdjAverage(a, eS); printf("The adjusted average is: %.2f\n", adjAverage); PAUSE; }//end displayAdjustedAverage void displayAverage(float a[], int eS, int flag) { float average; CLS; if (flag == 0) { printf("Please go back and enter some values first.\n\n"); PAUSE; return; }//end if average = calcAverage(a, eS); printf("The average GPA is: %.2f\n", average); PAUSE; }//end displayAverage void displayHighest(float gpa[], int eS, int flag) { CLS; float highest; if (flag == 0) printf("Please go back and enter some GPAs first!\n\n"); else { sort(gpa, eS); highest = gpa[0]; printf("The highest GPA is: %.2f\n\n", highest); }//end else PAUSE; }//end displayHighest void displayLowest(float gpa[], int eS, int flag) { CLS; float lowest; if (flag == 0) printf("Please go back and enter some GPAs first!\n\n"); else { sort(gpa, eS); lowest = gpa[eS - 1]; printf("The lowest GPA is: %.2f\n\n", lowest); }//end else PAUSE; }//end displayLowest void displayMenu() { char banner[20] = "M A I N M E N U"; int length = strlen(banner); for (int i = 0; i < length + 20; i++) printf("*"); printf("\n*** %s ***\n", banner); for (int i = 0; i < length + 20; i++) printf("*"); printf("\nA. Enter GPA\n"); printf("B. Display Average of all GPA's\n"); printf("C. Display the Highest GPA\n"); printf("D. Display the Lowest GPA\n"); printf("E. Display the Adjusted Average\n"); printf("F. See if a certain GPA was entered\n"); printf("G. Display the contents of the Array\n"); printf("Q. Quit\n\n"); }//end displayMenu void displaySorted(float a[], int eS, int flag) { CLS; if (flag == 0) printf("Please go back and enter some GPAs first!\n\n"); else { sortAsc(a, eS); printf("Here are all GPAs entered:\n"); for (int i = 0; i < eS; i++) { printf("\t%.2f\n", a[i]); }//end for }//end else PAUSE; }//end displaySorted char getChoice() { char result; printf("Please enter your choice: "); scanf("%c", &result); FLUSH; return toupper(result); }//end getChoice int getGpa(float a[], int eSize) { CLS; if (eSize == SIZE) { printf("Maximum number of GPAs entered.\n\n"); PAUSE; return eSize; }//end if printf("Please enter your GPA: "); scanf("%f", &a[eSize]); FLUSH; if (a[eSize] < 2.0) { printf("\n\nYou need to study harder.\n"); PAUSE; }//end if if (a[eSize] > 3.5) { printf("\n\nNice work.\n"); PAUSE; }//end if return eSize + 1; }//end getGpa void myFlush() { while (getchar() != '\n'); } // end myFlush void searchGpa(float a[], int eS, int flag) { float gpaToFind; int top = 0; int bottom = eS - 1; int middle = (top + bottom) / 2; char notFound = 'Y'; CLS; if (flag == 0) { printf("Please go back and enter some GPAs first!\n\n"); PAUSE; return; }//end if sort(a, eS); printf("Please enter a GPA to find: "); scanf("%f", &gpaToFind); FLUSH; while (top <= bottom && notFound == 'Y') { if (a[middle] > gpaToFind) top = middle + 1; else if (a[middle] < gpaToFind) bottom = middle - 1; else notFound = 'N'; middle = (top + bottom) / 2; } // end while if (notFound == 'Y') printf("A %.2f GPA was not entered\n\n.", gpaToFind); else printf("I found %.2f GPA in element %i\n\n", gpaToFind, middle + 1); PAUSE; }//end searchGpa void sort(float array[], int eS) { char swapped; int bottom = eS - 1; do { swapped = 'N'; for (int i = 0; i < bottom; i++) { if (array[i] < array[i + 1]) { swapped = swapValues(array, i); }// end if } // end for bottom--; } while (swapped == 'Y'); }//void sort void sortAsc(float array[], int eS) { char swapped; int bottom = eS - 1; do { swapped = 'N'; for (int i = 0; i < bottom; i++) { if (array[i] > array[i + 1]) { swapped = swapValues(array, i); }// end if } // end for bottom--; } while (swapped == 'Y'); }//void sort char swapValues(int array[], int location) { char result = 'Y'; int temp; temp = array[location]; array[location] = array[location + 1]; array[location + 1] = temp; return result; }//end swapValues int tripFlag() { return 1; }//end tripflag
5e69f3ff760813fb50f21c6e283cc04a661b20a6
3161173491d34339140265e4f6810e688aff1034
/ek-tm4c1294xl/project1/self/digitals/extended/extended_5_h.c
cde727b5bc5d4478a70a08c8edf340598f49c3bc
[]
no_license
ti-cortex-m4/tm4c1294ncpdt
853aaed9b7cb39c489568ae8023ed4bd64ba8d76
629defb60af370595d7c33917ee8459642d3b62e
refs/heads/master
2023-07-25T06:14:03.666763
2023-07-23T14:24:03
2023-07-23T14:24:03
28,406,657
5
3
null
2022-08-28T07:21:38
2014-12-23T16:03:26
C
WINDOWS-1251
C
false
false
2,523
c
extended_5_h.c
/*------------------------------------------------------------------------------ EXTENDED_5_H!C ------------------------------------------------------------------------------*/ /* #include "main.h" #include "xdata.h" #include "display.h" #include "delay.h" #include "ports.h" #include "engine.h" #include "energy.h" #include "general.h" #include "nexttime.h" #include "keyboard.h" #include "digitals.h" #include "device_h.h" #include "_automatic1.h" bit ReadOpenH_X5(uchar bTariff) { InitPop(3); bVersionCod = PopChar(); mpbCoder[0] = PopChar(); mpbCoder[1] = PopChar(); mpbCoder[2] = PopChar(); mpbCoder[3] = PopChar(); if (bTariff == 1) { sprintf(szLo," версия: %2bu ",bVersionCod); DelayInf(); Clear(); } if ((bVersionCod == 23) || (bVersionCod == 45) || (bVersionCod == 25) || (bVersionCod == 47) || (bVersionCod == 16) || (bVersionCod == 30) || (bVersionCod == 43)) return(1); ShowLo(szNoVersion); DelayInf(); Clear(); return(0); } bit QueryOpenDeviceH_X5(uchar bTariff) { uchar i; for (i=0; i<MaxRepeats(); i++) { DelayOff(); QueryOpenH(); if (CodInput() == SER_GOODCHECK) break; if (fKey == true) return(0); } if (i == MaxRepeats()) return(0); if (ReadOpenH_X5(bTariff) == 0) return(0); return(1); } bit QueryEnergyAbsTariffH_Full(uchar bTariff) { uchar i; for (i=0; i<MaxRepeats(); i++) { DelayOff(); QueryEnergyAbsH(bTariff-1); if (CodInput() == SER_GOODCHECK) break; if (fKey == true) return(0); } if (i == MaxRepeats()) return(0); if (ChecksumH(14) == 0) { sprintf(szLo," ошибка CRC: H8 "); Delay(1000); return(0); } InitPop(3); PopLongH(); mpreChannelsB[0] = (float)dwBuffC/1000; return(1); } bit ReadCntDayTariffH(uchar bTariff) { uchar i; if (QueryOpenDeviceH_X5(bTariff) == 0) return(0); if (QueryEnergyAbsTariffH_Full(bTariff) == 0) return(0); ShowPercent(60+bTariff); DelayInf(); // энергия за текущие сутки рассчитывается, а не запрашивается со счётчика (как должно быть) ! LoadImpDay(ibHardDay); i = 0x01 << (bTariff-1); reBuffA = *PGetCanImp2RealEng(mpimDayCan[ PrevSoftDay() ],ibDig,i); // по тарифам reBuffA = reBuffA / mpreTransEng[ibDig]; reBuffA = mpreChannelsB[0] * mpreTransCnt[ibDig] - reBuffA; mpreChannelsB[0] = reBuffA; mpboChannelsA[0] = true; return(1); } */
88d3d6f9082cf1351c6bbbca918f59a9bce3dabf
ddba28a8dd9e0a1f67dc898085007a3d543bd44d
/TP1_NA.c
e91ba1871a954b50289d992ed0725e67d9c6381b
[]
no_license
amit-patel96/web
87441d99178ef4ab13966c43463174983bd3fee9
9fb41c4d96a8b93634ece612e95e0936ddb5f09b
refs/heads/master
2020-12-22T01:26:35.545466
2020-01-28T00:54:04
2020-01-28T00:54:04
236,629,711
0
0
null
null
null
null
UTF-8
C
false
false
2,078
c
TP1_NA.c
#include <stdio.h> int main () { int salAnu; /* salaire Annuel reçu */ float sommeAnnu; const float PRIME_FIN_ANNEE = 0.025; float salAetprimeAn; float sommeInclu; /* nombre d'années en poste */ int nbAnn; float surPrime; /* Bonis selon le nombre d'années */ /* solution avec if et else selon l''anciennetés */ /* Demande d'information a l'employe''*/ printf ("votre salaire annuel est de $: \n "); scanf("%d",&salAnu); /* calcul salaire annuel + prime annuel */ salAetprimeAn= salAnu * PRIME_FIN_ANNEE; sommeAnnu = (salAnu + salAetprimeAn); printf("voici votre prime annuel est de %.2f $\n",salAetprimeAn); printf("voici votre salaire incluant avec prime annuel: %.2f \n\n", sommeAnnu); //scanf("%.2f",&sommeAnnu); do { printf("Tapez le nombre d'annee d experience (ans) : "); // Tapper le mois choisi scanf("%d", &nbAnn); } while (nbAnn <= 0 || nbAnn > 100); // mois doit etre entre 1 et 12 sinon - erreur if (nbAnn == 1 || nbAnn == 2 || nbAnn == 3 || nbAnn == 4) { surPrime = 300.00; // les mois de l'annee avec 31 jour printf("Votre prime est de : 300$ \n"); // il y a 31 jours dans ce mois } else if (nbAnn == 5 || nbAnn == 6 || nbAnn == 7 || nbAnn == 8 || nbAnn == 9) { surPrime = 725.00; // mois de l'annee avec 30 jour printf("Votre prime est de : 750$ \n"); // affichage du 30 jour } else if (nbAnn <= 10 || nbAnn > 100) { surPrime = 1200.00; // execption pour le mois de fevrier printf("Votre prime est de : 1200$ \n"); // affiche du mois sommeInclu = (surPrime + sommeAnnu); printf("voici votre salaire incluant avec prime annuel: %.2f \n\n", sommeInclu); } return 0 ; }
6cfb1d7c1ce8a246f7c31f3f3bf5cb43fb5b15b8
7fec5d8508decf592eeaffe92123acd53a1d8943
/num_jogadores.c
e11784833e257021bd5a32b64c74a071e402ae91
[]
no_license
iuridiniz/ufrn-porrinha-fight
6b8c5b412d245970a83a3193c594ad7e93d38c01
adb01ba6b38103c4fa941a81f24f1223809bb44c
refs/heads/master
2021-01-02T08:57:15.592458
2011-09-25T00:24:37
2011-09-25T00:24:37
null
0
0
null
null
null
null
UTF-8
C
false
false
157
c
num_jogadores.c
int num_jogadores () { int num=0; do { tela_num_jogadores(&num); } while (num < 1 || num > 3); ;; return(num); }
700bd1918d8e6eefcef59db0fb1c30e1fb0d644a
8a19591f2da200a5d2c2ecafe0444c6416414d17
/smth/smth/printmass.h
9f55bfe424acef37af23dbfb33fe39b556abd0c0
[]
no_license
softservedata/PMP112015
3612832e6da98d734b5f70a936c4081e87e1e9fc
47575840b6ec2cfa5a42d7c70bcac711ef1d3095
refs/heads/master
2020-04-07T02:48:39.910414
2017-03-13T20:54:37
2017-03-13T20:54:37
43,291,641
0
5
null
2016-05-04T18:51:43
2015-09-28T09:21:31
Python
UTF-8
C
false
false
79
h
printmass.h
#ifndef PRINTMASS_H #define PRINTMASS_H void printmass(int *a,int n); #endif
f0f675090e86c3dd3913e9c4e0c3a840dedf75a9
810dd984fd57ecc23a415b1756bfe4a01cafd47e
/oldkern/kernel/context_switch.h
9adf654a68988ca5cbf61aaa11cb9092e15d5cab
[]
no_license
qaovxtazypdl/RealTime
3f60a10a70953cf27a0bbc5bf16eee968f367f03
0023304494ab3878fc9578721f6bf1693f1e1c58
refs/heads/master
2021-06-30T20:53:00.834882
2017-09-14T06:07:41
2017-09-14T06:07:41
103,489,757
0
0
null
null
null
null
UTF-8
C
false
false
268
h
context_switch.h
#ifndef _KERNEL__CONTEXT_SWITCH_H_ #define _KERNEL__CONTEXT_SWITCH_H_ #include <ts7200.h> struct TaskDescriptor; struct KernelRequest; void kernel_entry_irq(); void kernel_entry(); void kernel_exit(struct TaskDescriptor *active, struct KernelRequest *req); #endif
ff24076c42e0b705ad1ee2beabde03313872cccb
a280aa9ac69d3834dc00219e9a4ba07996dfb4dd
/regularexpress/home/weilaidb/work/kernel/linux-3.0.8/drivers/usb/serial/sierra.c
e906cc0168b80cf06daebf661c9631e9aa42a14f
[]
no_license
weilaidb/PythonExample
b2cc6c514816a0e1bfb7c0cbd5045cf87bd28466
798bf1bdfdf7594f528788c4df02f79f0f7827ce
refs/heads/master
2021-01-12T13:56:19.346041
2017-07-22T16:30:33
2017-07-22T16:30:33
68,925,741
4
2
null
null
null
null
UTF-8
C
false
false
3,589
c
sierra.c
#define DRIVER_VERSION "v.1.7.16" #define DRIVER_AUTHOR "Kevin Lloyd, Elina Pasheva, Matthew Safar, Rory Filer" #define DRIVER_DESC "USB Driver for Sierra Wireless USB modems" #define SWIMS_USB_REQUEST_SetPower 0x00 #define SWIMS_USB_REQUEST_SetNmea 0x07 #define N_IN_URB_HM 8 #define N_OUT_URB_HM 64 #define N_IN_URB 4 #define N_OUT_URB 4 #define IN_BUFLEN 4096 #define MAX_TRANSFER (PAGE_SIZE - 512) static int debug; static int nmea; struct sierra_iface_info ; struct sierra_intf_private ; static int sierra_set_power_state(struct usb_device *udev, __u16 swiState) static int sierra_vsc_set_nmea(struct usb_device *udev, __u16 enable) static int sierra_calc_num_ports(struct usb_serial *serial) static int is_blacklisted(const u8 ifnum, const struct sierra_iface_info *blacklist) static int is_himemory(const u8 ifnum, const struct sierra_iface_info *himemorylist) static int sierra_calc_interface(struct usb_serial *serial) static int sierra_probe(struct usb_serial *serial, const struct usb_device_id *id) static const u8 hi_memory_typeA_ifaces[] = ; static const struct sierra_iface_info typeA_interface_list = ; static const u8 hi_memory_typeB_ifaces[] = ; static const struct sierra_iface_info typeB_interface_list = ; static const u8 direct_ip_non_serial_ifaces[] = ; static const struct sierra_iface_info direct_ip_interface_blacklist = ; static const struct usb_device_id id_table[] = ; MODULE_DEVICE_TABLE(usb, id_table); struct sierra_port_private ; static int sierra_send_setup(struct usb_serial_port *port) static void sierra_set_termios(struct tty_struct *tty, struct usb_serial_port *port, struct ktermios *old_termios) static int sierra_tiocmget(struct tty_struct *tty) static int sierra_tiocmset(struct tty_struct *tty, unsigned int set, unsigned int clear) static void sierra_release_urb(struct urb *urb) static void sierra_outdat_callback(struct urb *urb) static int sierra_write(struct tty_struct *tty, struct usb_serial_port *port, const unsigned char *buf, int count) static void sierra_indat_callback(struct urb *urb) static void sierra_instat_callback(struct urb *urb) static int sierra_write_room(struct tty_struct *tty) static void sierra_stop_rx_urbs(struct usb_serial_port *port) static int sierra_submit_rx_urbs(struct usb_serial_port *port, gfp_t mem_flags) static struct urb *sierra_setup_urb(struct usb_serial *serial, int endpoint, int dir, void *ctx, int len, gfp_t mem_flags, usb_complete_t callback) static void sierra_close(struct usb_serial_port *port) static int sierra_open(struct tty_struct *tty, struct usb_serial_port *port) static void sierra_dtr_rts(struct usb_serial_port *port, int on) static int sierra_startup(struct usb_serial *serial) static void sierra_release(struct usb_serial *serial) static void stop_read_write_urbs(struct usb_serial *serial) static int sierra_suspend(struct usb_serial *serial, pm_message_t message) static int sierra_resume(struct usb_serial *serial) static int sierra_reset_resume(struct usb_interface *intf) #define sierra_suspend NULL #define sierra_resume NULL #define sierra_reset_resume NULL static struct usb_driver sierra_driver = ; static struct usb_serial_driver sierra_device = ; static int __init sierra_init(void) static void __exit sierra_exit(void) module_init(sierra_init); module_exit(sierra_exit); MODULE_AUTHOR(DRIVER_AUTHOR); MODULE_DESCRIPTION(DRIVER_DESC); MODULE_VERSION(DRIVER_VERSION); MODULE_LICENSE("GPL"); module_param(nmea, bool, S_IRUGO | S_IWUSR); MODULE_PARM_DESC(nmea, "NMEA streaming"); module_param(debug, bool, S_IRUGO | S_IWUSR); MODULE_PARM_DESC(debug, "Debug messages");
a099afbc0ae32cdfc862f162fe4365c26277e40e
e6dd494f73f68067a85abba97bc513a79e05d143
/lbuiltin_condition.h
da166c3e4e95c72ecafcc7c7021279d236b85ef1
[ "MIT" ]
permissive
hipparcos/dialecte
7a2f4586f69c04ce357e83b5f6a947e33eb20011
8fe59f3caf3b39e9ff0ed1393e0aa3659619baba
refs/heads/master
2021-07-19T12:38:32.975661
2018-10-22T11:11:29
2018-10-22T11:11:29
140,613,627
0
0
null
null
null
null
UTF-8
C
false
false
702
h
lbuiltin_condition.h
#ifndef _H_LBUILTIN_CONDITION_ #define _H_LBUILTIN_CONDITION_ #include "lfunc.h" /* Conditions on lfunc. */ define_condition(must_have_max_argc); define_condition(must_have_min_argc); define_condition(must_have_func_ptr); /* Operators conditions. */ define_condition(must_be_numeric); define_condition(must_be_integral); define_condition(must_be_positive); define_condition(divisor_must_be_non_zero); define_condition(must_be_unsigned_long); /* List conditions. */ define_condition(must_be_of_type); define_condition(must_all_be_of_same_type); define_condition(must_have_min_len); define_condition(must_be_of_equal_len); define_condition(must_be_list_of); define_condition(must_be_a_list); #endif
79299703b01af106145c574d3c65b7b012088112
1c9ff3bafd2fb6b1f894f99224cbdeb05aed3ce0
/base64.c
9f1d20db3abe336868b9d4ac52fc50fa5a58e094
[]
no_license
cuckoohello/smssync
4367bd351a2f9ff574e73ce1e782998d4396577a
378713c13d410cf7c7ad4be0b14884db1d7adef6
refs/heads/master
2021-01-01T06:54:49.166582
2012-02-23T13:24:02
2012-02-23T13:24:02
3,512,011
1
0
null
2013-09-13T16:47:41
2012-02-22T06:31:21
C
UTF-8
C
false
false
5,586
c
base64.c
/* Get malloc. */ #include <stdlib.h> /* Get UCHAR_MAX. */ #include <limits.h> #include <string.h> # define BASE64_LENGTH(inlen) ((((inlen) + 2) / 3) * 4) /* C89 compliant way to cast 'char' to 'unsigned char'. */ static inline unsigned char to_uchar (char ch) { return ch; } /* Base64 encode IN array of size INLEN into OUT array of size OUTLEN. If OUTLEN is less than BASE64_LENGTH(INLEN), write as many bytes as possible. If OUTLEN is larger than BASE64_LENGTH(INLEN), also zero terminate the output buffer. */ void base64_encode (const char *in, size_t inlen, char *out, size_t outlen) { static const char b64str[64] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; while (inlen && outlen) { *out++ = b64str[(to_uchar (in[0]) >> 2) & 0x3f]; if (!--outlen) break; *out++ = b64str[((to_uchar (in[0]) << 4) + (--inlen ? to_uchar (in[1]) >> 4 : 0)) & 0x3f]; if (!--outlen) break; *out++ = (inlen ? b64str[((to_uchar (in[1]) << 2) + (--inlen ? to_uchar (in[2]) >> 6 : 0)) & 0x3f] : '='); if (!--outlen) break; *out++ = inlen ? b64str[to_uchar (in[2]) & 0x3f] : '='; if (!--outlen) break; if (inlen) inlen--; if (inlen) in += 3; } if (outlen) *out = '\0'; } /* Allocate a buffer and store zero terminated base64 encoded data from array IN of size INLEN, returning BASE64_LENGTH(INLEN), i.e., the length of the encoded data, excluding the terminating zero. On return, the OUT variable will hold a pointer to newly allocated memory that must be deallocated by the caller. If output string length would overflow, 0 is returned and OUT is set to NULL. If memory allocation failed, OUT is set to NULL, and the return value indicates length of the requested memory block, i.e., BASE64_LENGTH(inlen) + 1. */ size_t base64_encode_alloc (const char *in, size_t inlen, char **out) { size_t outlen = 1 + BASE64_LENGTH (inlen); /* Check for overflow in outlen computation. * * If there is no overflow, outlen >= inlen. * * If the operation (inlen + 2) overflows then it yields at most +1, so * outlen is 0. * * If the multiplication overflows, we lose at least half of the * correct value, so the result is < ((inlen + 2) / 3) * 2, which is * less than (inlen + 2) * 0.66667, which is less than inlen as soon as * (inlen > 4). */ if (inlen > outlen) { *out = NULL; return 0; } *out = malloc (outlen); if (!*out) return outlen; base64_encode (in, inlen, *out, outlen); return outlen - 1; } size_t base64_encode_alloc_with_header(const char*in,size_t inlen,char **out) { size_t outlen = 1 + BASE64_LENGTH (inlen); if (inlen > outlen) { *out = NULL; return 0; } outlen += 12; *out = malloc (outlen); if (!*out) return outlen; memcpy(*out,"=?UTF-8?B?",10); base64_encode (in, inlen, *out+10, outlen-12); memcpy(*out+outlen-3,"?=",2); *(*out+outlen) = 0; return outlen-1; } const char imap_subject_header[] = "Subject: "; const char imap_text_header[] = "\nMIME-Version: 1.0\nContent-Type: text/plain;\n charset=utf-8\nContent-Transfer-Encoding: base64\n"; /* memset message before use */ void imap_create_header(char* message, const char *subject) { char *encode; size_t len; memcpy(message,imap_subject_header,strlen(imap_subject_header)); len = base64_encode_alloc_with_header(subject,strlen(subject),&encode); if(len) { memcpy(message+strlen(message),encode,len); free(encode); } memcpy(message+strlen(message),imap_text_header,strlen(imap_text_header)); } void imap_add_address(char *message,const char* id, const char* name, const char* email) { char *encode; size_t len; memcpy(message+strlen(message),id,strlen(id)); memcpy(message+strlen(message),": ",2); len = base64_encode_alloc_with_header(name,strlen(name),&encode); if(len) { memcpy(message+strlen(message),encode,len); free(encode); } memcpy(message+strlen(message)," <",2); memcpy(message+strlen(message),email,strlen(email)); memcpy(message+strlen(message),">\n",2); } void imap_add_header(char* message,const char* id , const char *content) { memcpy(message+strlen(message),id,strlen(id)); memcpy(message+strlen(message),": ",2); memcpy(message+strlen(message),content,strlen(content)); *(message+strlen(message)) = '\n'; } void imap_add_identify(char* message,const char* id , const char *content) { memcpy(message+strlen(message),id,strlen(id)); memcpy(message+strlen(message),": <",3); memcpy(message+strlen(message),content,strlen(content)); memcpy(message+strlen(message),">\n",2); } void imap_add_contect(char *message,const char* content) { char *encode; size_t len,current; *(message+strlen(message)) = '\n'; len = base64_encode_alloc(content,strlen(content),&encode); current = 0; if (len) { while (len - current >= 76) { memcpy(message+strlen(message),encode+current,76); *(message+strlen(message)) = '\n'; current += 76; } if (len - current) { memcpy(message+strlen(message),encode+current,len-current); *(message+strlen(message)) = '\n'; } free(encode); } }
50e17a962d5485d10cce0a9c6ba32087653addb5
ad8271700e52ec93bc62a6fa3ee52ef080e320f2
/CatalystRichPresence/CatalystSDK/PamPrototypeBackendUpdatePlayerPositionResultMessage.h
9cee1d6211e2ca9fb9ebf8633aca7317dde894a4
[]
no_license
RubberDuckShobe/CatalystRPC
6b0cd4482d514a8be3b992b55ec143273b3ada7b
92d0e2723e600d03c33f9f027c3980d0f087c6bf
refs/heads/master
2022-07-29T20:50:50.640653
2021-03-25T06:21:35
2021-03-25T06:21:35
351,097,185
2
0
null
null
null
null
UTF-8
C
false
false
539
h
PamPrototypeBackendUpdatePlayerPositionResultMessage.h
// // Generated with FrostbiteGen by Chod // File: SDK\PamPrototypeBackendUpdatePlayerPositionResultMessage.h // Created: Wed Mar 10 19:04:09 2021 // #ifndef FBGEN_PamPrototypeBackendUpdatePlayerPositionResultMessage_H #define FBGEN_PamPrototypeBackendUpdatePlayerPositionResultMessage_H struct PamPrototypeBackendUpdatePlayerPositionResultMessage { static void* GetTypeInfo() { return (void*)0x00000001428773A0; } unsigned char _0x0[0x38]; }; // size = 0x38 #endif // FBGEN_PamPrototypeBackendUpdatePlayerPositionResultMessage_H
e3c09c60c364f4030782fef45d73960a18b211cb
fff063434ccddf9ac09d420232f952e8a49c8067
/C Programs/nstdlopastrks3.c
6b07f8402911880fcd09f1869144be70b5de9178
[]
no_license
saifsafsf/High-School-Work
9e83b9fdfb208bb3becaccec710b1f3d10ec3f5b
0592178098ab008602b19dd4357d0eae8451111e
refs/heads/main
2023-03-15T05:26:30.471462
2021-03-01T02:45:37
2021-03-01T02:45:37
343,268,893
0
0
null
null
null
null
UTF-8
C
false
false
260
c
nstdlopastrks3.c
#include <stdio.h> #include <conio.h> void main() { int a, b; for(a = 1 ; a <= 7 ; a++) { b = a; while(b <= 7) { printf("* "); b++; } printf("\n"); } getch(); }
9d75ed49c484834f03f425ecaa55691394f4b519
853ca345dc91a6a4b1df8789aa1a40053b7b1bd6
/UAV System/HARDWARE/mymath.h
a90c223a6d57749c80034020085a6b31e66c19a4
[ "MIT" ]
permissive
YanHuiGUO/UAV-Track-The-Black-Lines-Indoor
b35006a4aa3a67c4309fc301177484e766d5ceb5
eb8362b2b2db7c15a8c537c8130f69298bad097e
refs/heads/master
2020-05-03T13:58:26.878799
2019-05-14T04:40:49
2019-05-14T04:40:49
178,665,398
1
0
null
null
null
null
UTF-8
C
false
false
757
h
mymath.h
/*** *mymath.h * * * *Purpose: * This file defined the functions and variables used by users * to fast computation the result of trigonometric functions and * the square root. ****/ #include "stm32f4xx.h" #ifndef __MYMATH_H__ #define __MYMATH_H__ #define REAL float #define TAN_MAP_RES 0.003921569f /* (smallest non-zero value in table) */ #define RAD_PER_DEG 0.017453293f #define TAN_MAP_SIZE 256 #define MY_PPPIII 3.14159f #define MY_PPPIII_HALF 1.570796f float my_abs(float f); REAL fast_atan2(REAL y, REAL x); float my_pow(float a); float my_sqrt(float number); double mx_sin(double rad); double my_sin(double rad); float my_cos(double rad); float Moving_Average(u8 item,u8 width_num,float in); #endif
abf717fceea5168633f8224ce7f1b7d9aadb6c9d
01b8db44ebde6217e17adedc292d6e0a3078c174
/boot/rom-boot/nand_flash.c
d9f40cbee0a842761719dac269ed33359b42cf79
[]
no_license
luotao717/arsdk
6a616153c0c56cc5b902a63c42b3ffd6ddd7603f
9f9004157afcd26b915125576a815f6b3e0cd715
refs/heads/master
2021-05-01T17:45:46.249250
2014-08-16T10:30:39
2014-08-16T10:30:39
12,207,504
1
1
null
null
null
null
UTF-8
C
false
false
11,354
c
nand_flash.c
#include <asm/addrspace.h> #include <wasp_api.h> #include <nand_api.h> #include <apb_map.h> #include <ar7240_soc.h> #include <include/dv_dbg.h> uint32_t ath_nand_blk_size[] = { 64 << 10, 128 << 10, 256 << 10, 512 << 10 }; uint32_t ath_nand_page_size[] = { 1 << 10, 2 << 10, 4 << 10, 8 << 10 }; uint32_t ath_nf_ctrl_blk_size[] = { 32 << 10, 64 << 10, 128 << 10, 256 << 10, 0 }; uint32_t ath_nf_ctrl_page_size[] = { 256, 512, 1024, 2048, 4096, 8192, 16384, 0 }; ath_nand_vend_data_t ath_nand_arr[] = { { 0x20, 0xda, 0x10, 5, 3, 1, 1 }, // NU2g3B2D { 0x20, 0xf1, 0x00, 4, 3, 1, 1 }, // NU1g3B2C { 0x20, 0xdc, 0x10, 5, 3, 1, 1 }, // NU4g3B2D { 0x20, 0xd3, 0x10, 5, 4, 1, 1 }, // NU8g3F2A { 0x20, 0xd3, 0x14, 5, 3, 2, 1 }, // NU8g3C2B { 0xad, 0xf1, 0x00, 4, 3, 1, 1 }, // HY1g2b { 0xad, 0xda, 0x10, 5, 3, 1, 1 }, // HY2g2b { 0xec, 0xf1, 0x00, 4, 3, 1, 1 }, // Samsung 3,3V 8-bit [128MB] { 0x98, 0xd1, 0x90, 4, 3, 1, 1 }, // Toshiba }; ath_nand_otp_data_t ath_nand_otp_arr[OTP_NUM_NAND_ENTRIES]; #define NUM_ARRAY_ENTRIES(a) (sizeof((a)) / sizeof((a)[0])) #define NUM_ATH_NAND NUM_ARRAY_ENTRIES(ath_nand_arr) #define NUM_ATH_OTP_NAND NUM_ARRAY_ENTRIES(ath_nand_otp_arr) static ath_nand_id_t __ath_nand_id; ath_nand_id_t *nand_id = &__ath_nand_id; uint32_t nand_dev_ps; int nand_param_page(uint8_t *, unsigned); static unsigned nand_status(void) { unsigned rddata, i, j, dmastatus; rddata = ar7240_reg_rd(AR7240_NF_STATUS); for (i = 0; i < AR7240_NF_STATUS_RETRY && rddata != 0xff; i++) { udelay(25); rddata = ar7240_reg_rd(AR7240_NF_STATUS); } dmastatus = ar7240_reg_rd(AR7240_NF_DMA_CTRL); for (j = 0; j < AR7240_NF_STATUS_RETRY && !(dmastatus & 1); j++) { udelay(25); dmastatus = ar7240_reg_rd(AR7240_NF_DMA_CTRL); } if ((i == AR7240_NF_STATUS_RETRY) || (j == AR7240_NF_STATUS_RETRY)) { A_PRINTF("NF Status (%u) = 0x%x DMA Ctrl (%u) = 0x%x\n", i, rddata, j, dmastatus); //while (1); A_NAND_INIT(); return -1; } ath_nand_clear_int_status(); ar7240_reg_wr(AR7240_NF_CMD, 0x07024); // READ STATUS while (ath_nand_get_cmd_end_status() == 0); rddata = ar7240_reg_rd(AR7240_NF_RD_STATUS); return rddata; } void nand_read_id(void) { unsigned int rddata; ath_nand_clear_int_status(); ar7240_reg_wr(AR7240_NF_DMA_ADDR, (unsigned int)PHYSADDR(nand_id)); // DMA Start Addr ar7240_reg_wr(AR7240_NF_ADDR0_0, 0x0); // ADDR0_0 Reg Settings ar7240_reg_wr(AR7240_NF_ADDR0_1, 0x0); // ADDR0_1 Reg Settings ar7240_reg_wr(AR7240_NF_DMA_COUNT, sizeof(*nand_id)); // DMA count ar7240_reg_wr(AR7240_NF_PG_SIZE, 0x8); // Custom Page Size ar7240_reg_wr(AR7240_NF_DMA_CTRL, 0xcc); // DMA Control Reg ar7240_reg_wr(AR7240_NF_CMD, 0x9061); // READ ID while (ath_nand_get_cmd_end_status() == 0); rddata = A_NAND_STATUS(); } void * nand_get_entry(ath_nand_id_t *nand_id, ath_nand_table_t type, void *ptr, int count) { int i; ath_nand_otp_data_t *tbl = ptr; for (i = 0; i < count; i++) { if ((nand_id->id.vid == tbl->vid) && (nand_id->id.did == tbl->did) && (nand_id->byte_id[1] == tbl->b3)) { return tbl; } if (type == ATH_NAND_BR) { ptr = ((ath_nand_vend_data_t *)tbl) + 1; tbl = ptr; } else if (type == ATH_NAND_OTP) { tbl ++; } } return NULL; } void nand_init(void) { unsigned int i, rddata, status; uint8_t buf[128]; ath_nand_vend_data_t *entry; ar7240_reg_rmw_set(ATHR_RESET, RST_RESET_NANDF_RESET_MASK | RST_RESET_ETH_SWITCH_ARESET_MASK); udelay(250); // Pull Nand Flash and switch analog out of reset ar7240_reg_rmw_clear(ATHR_RESET, RST_RESET_ETH_SWITCH_ARESET_MASK); udelay(250); ar7240_reg_rmw_clear(AR7240_RESET, RST_RESET_NANDF_RESET_MASK); udelay(100); ar7240_reg_wr(AR7240_NF_INT_MASK, AR7240_NF_CMD_END_INT); ath_nand_clear_int_status(); // TIMINGS_ASYN Reg Settings ar7240_reg_wr(AR7240_NF_TIMINGS_ASYN, TIMING_ASYN); rddata = ar7240_reg_rd(AR7240_NF_CTRL); // Reset Command ar7240_reg_wr(AR7240_NF_CMD, 0xff00); while (ath_nand_get_cmd_end_status() == 0); udelay(1000); status = ar7240_reg_rd(AR7240_NF_STATUS); for (i = 0; i < AR7240_NF_STATUS_RETRY && status != 0xff; i++) { udelay(25); status = ar7240_reg_rd(AR7240_NF_STATUS); } if (i == AR7240_NF_STATUS_RETRY) { A_PRINTF("device reset failed\n"); while(1); } // Try to see the flash id A_NAND_READ_ID(); if (rddata == 0) { nand_dev_ps = (1 << 10) << nand_id->id.ps; // page size ar7240_reg_wr(AR7240_NF_TIMINGS_ASYN, TIMING_ASYN); entry = A_NAND_GET_ENTRY(nand_id, ATH_NAND_BR, ath_nand_arr, NUM_ATH_NAND); if (entry) { // Is it in the list of known devices ar7240_reg_wr(AR7240_NF_CTRL, (entry->addrcyc) | (entry->blk << 6) | (entry->pgsz << 8) | (CUSTOM_SIZE_EN << 11)); } else if ((A_OTP_GET_NAND_TABLE((u8 *)ath_nand_otp_arr, sizeof(ath_nand_otp_arr)) == 0) && (entry = A_NAND_GET_ENTRY(nand_id, ATH_NAND_OTP, ath_nand_otp_arr, NUM_ATH_OTP_NAND))) { // Is it available in the OTP ar7240_reg_wr(AR7240_NF_CTRL, (entry->addrcyc) | (entry->blk << 6) | (entry->pgsz << 8) | (CUSTOM_SIZE_EN << 11)); } else if (A_NAND_PARAM_PAGE(buf, sizeof(buf)) == 0) { // ONFI compliant? unsigned ps, // page size ppb; // pages per block rddata = buf[ONFI_NUM_ADDR_CYCLES]; rddata = ((rddata >> 4) & 0xf) + (rddata & 0xf); nand_dev_ps = ps = *(uint32_t *)(&buf[ONFI_PAGE_SIZE]); ppb = *(uint32_t *)(&buf[ONFI_PAGES_PER_BLOCK]); switch (ps) { case 256: ps = 0; break; case 512: ps = 1; break; case 1024: ps = 2; break; case 2048: ps = 3; break; case 4096: ps = 4; break; case 8192: ps = 5; break; case 16384: ps = 6; break; default: A_PRINTF("ONFI: Cannot handle ps = %u\n", ps); while(1); } switch (ppb) { case 32: ppb = 0; break; case 64: ppb = 1; break; case 128: ppb = 2; break; case 256: ppb = 3; break; default: A_PRINTF("ONFI: Cannot handle ppb = %u\n", ppb); while(1); } // Control Reg Setting ar7240_reg_wr(AR7240_NF_CTRL, (rddata) | (ppb << 6) | (ps << 8) | (CUSTOM_SIZE_EN << 11)); A_PRINTF("ONFI: Control Setting = 0x%x\n", ar7240_reg_rd(AR7240_NF_CTRL)); } else { unsigned ps, bs; DV_DBG_RECORD_LOCATION(NAND_C); for (ps = 0; ps < ath_nf_ctrl_page_size[ps]; ps ++) { if (ath_nf_ctrl_page_size[ps] == ath_nand_page_size[nand_id->id.ps]) break; } for (bs = 0; bs < ath_nf_ctrl_blk_size[bs]; bs ++) { if (ath_nf_ctrl_blk_size[bs] == ath_nand_blk_size[nand_id->id.bs]) break; } A_PRINTF("Unknown Nand device: 0x%x %x %x %x %x\n", nand_id->byte_id[0], nand_id->byte_id[1], nand_id->byte_id[2], nand_id->byte_id[3], nand_id->byte_id[4]); if (ath_nf_ctrl_page_size[ps] == 0 || ath_nf_ctrl_blk_size[bs] == 0) { A_PRINTF("Unknown Page size = %u and/or Blk size %u\n", ath_nand_page_size[nand_id->id.ps], ath_nand_blk_size[nand_id->id.bs]); while (1); } A_PRINTF("Attempting to use unknown device\n"); ar7240_reg_wr(AR7240_NF_CTRL, 5 | // Assume 5 addr cycles... (bs << 6) | (ps << 8) | (CUSTOM_SIZE_EN << 11)); } } // NAND Mem Control Reg ar7240_reg_wr(AR7240_NF_MEM_CTRL, 0xff00); } int nand_param_page(uint8_t *buf, unsigned count) { unsigned int tries, rddata; for (tries = 3; tries; tries --) { //A_PRINTF("%s: reading %p %p\n", __func__, nand_addr, buf); // ADDR0_0 Reg Settings ar7240_reg_wr(AR7240_NF_ADDR0_0, 0x0); // ADDR0_1 Reg Settings ar7240_reg_wr(AR7240_NF_ADDR0_1, 0x0); // DMA Start Addr ar7240_reg_wr(AR7240_NF_DMA_ADDR, PHYSADDR(buf)); // DMA count ar7240_reg_wr(AR7240_NF_DMA_COUNT, count); // Custom Page Size ar7240_reg_wr(AR7240_NF_PG_SIZE, count); // DMA Control Reg ar7240_reg_wr(AR7240_NF_DMA_CTRL, 0xcc); ath_nand_clear_int_status(); // READ PARAMETER PAGE ar7240_reg_wr(AR7240_NF_CMD, 0xec62); while (ath_nand_get_cmd_end_status() == 0); rddata = A_NAND_STATUS() & READ_PARAM_STATUS_MASK; if (rddata == READ_PARAM_STATUS_OK) { break; } else { A_PRINTF("\nParam Page Failure: 0x%x", rddata); DV_DBG_RECORD_LOCATION(NAND_C); } } if ((rddata == READ_PARAM_STATUS_OK) && (buf[3] == 'O' && buf[2] == 'N' && buf[1] == 'F' && buf[0] == 'I')) { DV_DBG_RECORD_LOCATION(NAND_C); return 0; } DV_DBG_RECORD_LOCATION(NAND_C); return 1; } int nand_read(unsigned nand_addr, unsigned count, unsigned buf) { unsigned int rddata, repeat = 0; //A_PRINTF("%s: reading %p %p\n", __func__, nand_addr, buf); #define MAX_REPEAT 3 while (repeat < MAX_REPEAT) { repeat ++; // ADDR0_0 Reg Settings ar7240_reg_wr(AR7240_NF_ADDR0_0, nand_addr); // ADDR0_1 Reg Settings ar7240_reg_wr(AR7240_NF_ADDR0_1, 0x0); // DMA Start Addr ar7240_reg_wr(AR7240_NF_DMA_ADDR, PHYSADDR(buf)); // DMA count ar7240_reg_wr(AR7240_NF_DMA_COUNT, count); // Custom Page Size ar7240_reg_wr(AR7240_NF_PG_SIZE, count); // DMA Control Reg ar7240_reg_wr(AR7240_NF_DMA_CTRL, 0xcc); ath_nand_clear_int_status(); // READ PAGE ar7240_reg_wr(AR7240_NF_CMD, 0x30006a); while (ath_nand_get_cmd_end_status() == 0); udelay(100); rddata = A_NAND_STATUS(); if ((rddata & READ_STATUS_MASK) != READ_STATUS_OK) { A_PRINTF("\nRead Failure: 0x%x", rddata); } else { break; } } return rddata; } void nand_dump_blk(unsigned fa, unsigned char *b, int count) { int i, j; for (i = 0; i < count; ) { A_PRINTF("%p:", i); for (j = 0;j < 16 && i < count; j++, i++) { A_PRINTF(" %02x", b[i]); } A_UART_PUTS("\n"); } } /* f/w addr in flash */ #if 0 const uint32_t img_fa[] = { 0x80000000u, 0x80050000u }; #define NUM_FW (sizeof(img_fa) / sizeof(img_fa[0])) #else #define NUM_FW 2 #endif typedef struct { uint32_t ep, /* entry point */ la, /* load addr */ sz, /* firmware size */ cs; /* firmware crc checksum */ } nf_fw_hdr_t; void nand_load_fw(void) { unsigned j, i, nbs = 65536, // for nand addr formation dbs, fa = 0x00000000u; nf_fw_hdr_t hdr, *tmp = (nf_fw_hdr_t *)0xbd004000; extern void call_fw(int, const unsigned int); extern __u32 checksum(__u32, __u32); dbs = nand_dev_ps; for (j = 0; j < NUM_FW; j++) { /* * The reads happen to uncached addresses, to avoid * cache invalidation etc... */ A_NAND_READ(fa, dbs, (unsigned)tmp); hdr = *tmp; A_PRINTF("hdr: [0x%x : 0x%x : 0x%x : 0x%x]\n", hdr.ep, hdr.la, hdr.sz, hdr.cs); A_PRINTF("%s: read %u pages\n", __func__, (hdr.sz / dbs)); A_MEMCPY((A_UINT8 *)hdr.la, tmp + 1, dbs - sizeof(hdr)); for (i = dbs, fa += nbs; i < hdr.sz; fa += nbs, i += dbs) { A_PRINTF("%s: 0x%x 0x%x 0x%x\n", __func__, fa, dbs, hdr.la + i - sizeof(hdr)); A_NAND_READ(fa, dbs, hdr.la + i - sizeof(hdr)); } if ((i = checksum(hdr.la, hdr.sz - sizeof(hdr))) != hdr.cs) { A_PRINTF("Checksum mismatch. 0x%x != 0x%x\n", hdr.cs, i); while(1); // What to do } else { A_PRINTF("f/w %u read complete, jumping to %p\n", j, hdr.ep); } call_fw(HIF_NAND, hdr.ep); A_PRINTF("f/w %u execution complete\n", j); } while (1); } void nand_module_install(struct nand_api *api) { api->_nand_init = nand_init; api->_nand_load_fw = nand_load_fw; api->_nand_read = nand_read; api->_nand_param_page = nand_param_page; api->_nand_read_id = nand_read_id; api->_nand_status = nand_status; api->_nand_get_entry = nand_get_entry; }
723e224c19632da0c09be0473cc8210553c9f650
f3eed0234b4d0ad2bbb2abd700cf1e2c7a0e8a1d
/AKWF-c/AKWF_oscchip/AKWF_oscchip_0044.h
fa823296c3f535c7ffb9d34e36a034456d1b0fde
[ "CC0-1.0" ]
permissive
KristofferKarlAxelEkstrand/AKWF-FREE
b2defa1a2d389d309be6dd2e9f968923daf80d1b
cf8171df36e9fec25416b5f568b72a6e2cb69194
refs/heads/master
2023-07-23T18:22:36.939705
2023-07-10T17:14:40
2023-07-10T17:14:40
145,817,187
359
59
CC0-1.0
2023-07-10T17:14:41
2018-08-23T07:26:56
null
UTF-8
C
false
false
4,688
h
AKWF_oscchip_0044.h
/* Adventure Kid Waveforms (AKWF) converted for use with Teensy Audio Library * * Adventure Kid Waveforms(AKWF) Open waveforms library * https://www.adventurekid.se/akrt/waveforms/adventure-kid-waveforms/ * * This code is in the public domain, CC0 1.0 Universal (CC0 1.0) * https://creativecommons.org/publicdomain/zero/1.0/ * * Converted by Brad Roy, https://github.com/prosper00 */ /* AKWF_oscchip_0044 256 samples +-----------------------------------------------------------------------------------------------------------------+ | * ******** | |************************************************* * ***** | | **************** ******* | | * | | **** | | **** | | * | | * | | * | | * ****| | * **** | | * ***** | | * * | | * **** | | * * | +-----------------------------------------------------------------------------------------------------------------+ */ const uint16_t AKWF_oscchip_0044 [] = { 36462, 38792, 37970, 38474, 38122, 38400, 38191, 38363, 38230, 38340, 38261, 38322, 38278, 38306, 38290, 38297, 38297, 38293, 38299, 38294, 38293, 38303, 38272, 38341, 37370, 36610, 36801, 36679, 36766, 36697, 36750, 36707, 36734, 36707, 36725, 36713, 36718, 36712, 36707, 36724, 37009, 37119, 37073, 37103, 37075, 37096, 37077, 37087, 37341, 37505, 37443, 37480, 37450, 37469, 37459, 37402, 37072, 37067, 37053, 37062, 37046, 37060, 37031, 37179, 38418, 38641, 38577, 38609, 38581, 38601, 38582, 38544, 37337, 36949, 37059, 36990, 37038, 36995, 37027, 36991, 37021, 36991, 37014, 36986, 37011, 36980, 37009, 36920, 36622, 36591, 36598, 36590, 36594, 36586, 36587, 36585, 36585, 36581, 36577, 36577, 36576, 36574, 36569, 36567, 36569, 36564, 36565, 36556, 36563, 36552, 36562, 36544, 36558, 36541, 36558, 36534, 36553, 36532, 36550, 36529, 36542, 36526, 36538, 36527, 36526, 36527, 36519, 36531, 36505, 36534, 36492, 36542, 36477, 36549, 36459, 36563, 36440, 36579, 36407, 36609, 36357, 36692, 36146, 38210, 43102, 43056, 43124, 43079, 43097, 43083, 43089, 43023, 42694, 42691, 42673, 42680, 42671, 42659, 42693, 42452, 40582, 40250, 40351, 40274, 40334, 40266, 40327, 40229, 39707, 39427, 39567, 39435, 39559, 39413, 39593, 39054, 37945, 37909, 37930, 37899, 37931, 37878, 37957, 37642, 36415, 36323, 36344, 36319, 36348, 36293, 36382, 36078, 34297, 33864, 34092, 33857, 34130, 33784, 34271, 32743, 30893, 30759, 31013, 30664, 31098, 30561, 31260, 29701, 27637, 27075, 27695, 26972, 27837, 26738, 28411, 22839, 2336, 582, 1166, 747, 1133, 796, 1078, 1227, 5270, 5655, 5701, 5662, 5666, 5793, 5452, 7604, 11407, 11066, 11251, 11208, 11175, 11331, 11064, 11946, 13484, 13728, 13468, 13813, 13427, 13900, 13342, 14431, 16394, 17097, 16511, 17156, 16451, 17316, 16126, 19402, };
03d81e0167d2dfee7931c873b09b39ff3025176d
5792b184e71a9de7779e0bd21b6833f8ddfdb4b5
/sysvr4/svr4/lib/libc/port/gen/rewinddir.c
36483d9a17214db0d5b0c0fe400b03b80dd4a44c
[]
no_license
ryanwoodsmall/oldsysv
1637a3e62bb1b9426a224e832f44a46f1e1a31d4
e68293af91e2dc39f5f29c20d7e429f9e0cabc75
refs/heads/master
2020-03-30T06:06:30.495611
2018-09-29T09:04:59
2018-09-29T09:04:59
150,839,670
7
0
null
null
null
null
UTF-8
C
false
false
712
c
rewinddir.c
/* Copyright (c) 1990 UNIX System Laboratories, Inc. */ /* Copyright (c) 1988 AT&T */ /* All Rights Reserved */ /* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF */ /* UNIX System Laboratories, Inc. */ /* The copyright notice above does not evidence any */ /* actual or intended publication of such source code. */ #ident "@(#)libc-port:gen/rewinddir.c 1.4" /* rewinddir -- C library extension routine */ #ifdef __STDC__ #pragma weak rewinddir = _rewinddir #endif #include "synonyms.h" #include <sys/types.h> #include <dirent.h> #undef rewinddir extern void seekdir(); void #ifdef __STDC__ _rewinddir(dirp) #else rewinddir(dirp) #endif DIR *dirp; { seekdir(dirp, 0L); }
d195eecdc0dcb911ffff390c21335c932041bde8
6c686851c0683c989afe0a0b93d839e354e4b085
/08.File.Status.n.Directory/symlink/symlink.c
bb5fdb127af49bf60e32ca0861e5f94c8cb1cecc
[ "MIT" ]
permissive
r4k0nb4k0n/unix-programming-homework
fdd3132543e6d3f810385a70bf1dd33761f0b994
a8bdc1958a54b6b3f82669c8045fc4d9c9076099
refs/heads/master
2021-09-01T09:51:40.987613
2017-12-26T09:46:27
2017-12-26T09:46:27
108,029,657
4
0
null
null
null
null
UTF-8
C
false
false
325
c
symlink.c
#include <stdio.h> int main(int argc, char **argv) { int fd; if( argc != 3 ) { printf("usage: symlink_1 actualname symname\n"); exit(1); } if( symlink(argv[1], argv[2]) < 0 ) { printf("symlink call error\n"); exit(2); } else printf("symlink: %s -> %s\n", argv[2], argv[1]); return 0; }
6468953dbef8a3f2ae2d9b2a7d11186c00ad6def
c784f4f6431a95b5a1487a9aa6a792a8d3fec462
/page9.h
cdf43d12a16108939468ff3eec675ba933112fd9
[]
no_license
VaneLord67/Automatic-charging-system_src
e8a3a9a8d2c8e17ee211c91b848eaa00d16fbc94
9270d9839be953156d596e4d4bdf1ce9ae152bec
refs/heads/master
2023-04-16T10:32:36.043977
2021-05-05T11:55:00
2021-05-05T11:55:00
null
0
0
null
null
null
null
GB18030
C
false
false
1,683
h
page9.h
#ifndef _PAGE9_H_ #define _PAGE9_H_ #include"myf.h" #define SIZE 2 //一页显示几条 #define MAX_RECORD 500 //最多几条记录 //声明记录结构体,包括索引、用户、时间、里程 typedef struct record { char index[10]; char user[20]; char time[60]; char mileage[50]; //char electricityLeft[5]; }RECORD,*pRECORD; /* 函数名:page9_screen 功能:绘制行驶记录查询界面 入口参数:void 返回值:void */ void page9_screen(void); /* 函数名:p9 功能:行驶记录查询界面 入口参数:汽车指针pCar 返回值:int类型,返回page的值 */ int p9(PCAR pCar); /* 函数名:maxPageQuery 功能:返回行驶记录文件(record.txt)中最大页数(一页显示3条) 入口参数:void 返回值:int最大页数 */ int maxPageQuery(int * getMax); /* 函数名:maxPageQueryForUser 功能:返回行驶记录文件(record.txt)中用户对应的最大页数(一页显示3条) 入口参数:void 返回值:int最大页数 */ int maxPageQueryForUser(PCAR pCar,int * skip); /* 函数名:findRecord 功能:输出行驶记录 入口参数:当前页面pageCurrent 返回值:void */ //@Deprecated //已被findRecordForAdmin和findRecordForUser取代 // void findRecord(int pageCurrent,PCAR pCar); /* 函数名:findRecordForAdmin 功能:向管理员输出行驶记录 入口参数:当前页面pageCurrent 返回值:void */ void findRecordForAdmin(int pageCurrent,int max); /* 函数名:findRecordForUser 功能:向用户输出行驶记录 入口参数:当前页面pageCurrent,用户对应的跳过数组skip 返回值:void */ void findRecordForUser(int pageCurrent,int * skip); #endif
f9c375f88ac10fc13f09e98b193ec1b958f6e9dd
e75208d54944310ca494ff52c0f6b5da223b9a4c
/proof/questao2.c
b79d1f670420810d4fa4a639cf54875b59c150dd
[]
no_license
Gustavohsdp/C-language-exercises
74e5cb13eb483cb171afdf073bc9066c2d7eeba6
de4a0bbe10047de55621a458d2e8fe3428f76496
refs/heads/master
2023-07-11T19:31:58.675083
2021-08-29T02:04:39
2021-08-29T02:04:39
376,165,098
0
0
null
null
null
null
UTF-8
C
false
false
1,421
c
questao2.c
// Esse progrma irá permitir que o professor coloque quantas notas ele quer adicionar e vai fazer o calculo // da media ponderada e vai informar se o aluno tirou nota A,B,C ou D #include <stdio.h> int main() { //Declarações de variaveis int count = 0, numero_notas = 0; float peso = 0, soma_peso = 0, nota = 0, media_parcial = 0, soma_media_parcial = 0, media = 0; //Entrada dos número de notas printf("Informe o número de notas que você pretende digitar: "); scanf("%d", &numero_notas); //loop para inserir nota, peso e o número das notas while (count < numero_notas) { //Inserção do valor da nota printf("Digite o valor da nota do aluno de 0 a 10: "); scanf("%f", &nota); //inserção do valor do peso printf("Digite o valor do peso: "); scanf("%f", &peso); soma_peso = soma_peso + peso; media_parcial = nota * peso; media = media + media_parcial; count++; } //calculo da media ponderada media = media / soma_peso; printf("A media ponderada das notas é %f", media); //verificação para saber a nota final do aluno if( media >= 8 && media <= 10) { printf("A nota final do aluno é A"); }else if (media >= 6 && media < 8) { printf("A nota do aluno é B"); }else if(media >= 5 && media < 6) { printf("A nota do aluno é C"); } else if (media < 5) { printf("A nota do aluno é D"); } }
8006ca2d27a6ef45476279b634da8b3a9cc734d5
26bb5c6ae3ad780c2171fc841614e5abcbb7f7a7
/src/camera/camera.h
ea47606ddb093103e51bd754beae7b9140b4dc7c
[]
no_license
wisper-shadow/Pixhawk_Controller_Using_RX23T
5271339196382d3579f049a745e9f05b0181b182
f3d37afbd4a9fb836a82851eb640b5a95ec550ff
refs/heads/master
2021-01-18T15:46:41.655207
2017-09-02T01:42:34
2017-09-02T01:42:34
100,387,181
0
1
null
null
null
null
UTF-8
C
false
false
585
h
camera.h
/* * camera.h * * Created on: Jul 31, 2017 * Author: Arthur */ #ifndef CAMERA_CAMERA_H_ #define CAMERA_CAMERA_H_ #include <stdint.h> #include <stdbool.h> #include "../cg_src/r_cg_macrodriver.h" #include "../remote_ctl/remote_ctl.h" #include "../sonar/sonar.h" #define CAMERA_W 160 #define CAMERA_H 120 #define CAMERA_STX 0xFF #define ALARM_STX 0xFD #define ALARM_END 0xFE #define CAMERA_MID_X 80 #define CAMERA_MID_Y 60 extern uint8_t g5_rx_char; extern volatile uint8_t get_x, get_y; extern void SCI5_IntHandler(void); #endif /* CAMERA_CAMERA_H_ */
2b93064341478a78f6b3e1c162fbdecd70666edd
98202e03f83ecb0f80bcad48078dc468a5dc0bc2
/gpio/zynq7000-pwm/zynq7000-pwm-msg.h
33cc0ebfef5f0daa46e98566f3bb08ace5fba8b0
[ "BSD-2-Clause", "BSD-3-Clause" ]
permissive
phoenix-rtos/phoenix-rtos-devices
e7de9531c8f1b418310bb3b1d6089d4d8905c4f7
5cb46807a914a0d5885ea0b98dc638c7ddabaeaa
refs/heads/master
2023-08-17T06:05:50.582582
2023-08-10T17:54:13
2023-08-11T13:56:30
125,824,524
17
39
BSD-3-Clause
2023-09-14T14:44:31
2018-03-19T08:21:41
C
UTF-8
C
false
false
505
h
zynq7000-pwm-msg.h
/* * Phoenix-RTOS * * Xilinx Zynq 7000 PWM driver binary interface * * Copyright 2023 Phoenix Systems * Author: Aleksander Kaminski * * This file is part of Phoenix-RTOS. * * %LICENSE% */ #ifndef ZYNQ7000_PWM_MSG_H #define ZYNQ7000_PWM_MSG_H #include <stdint.h> #include <sys/msg.h> #define ZYNQ7000_PWM_CHANNELS 8 int zynq7000pwm_set(oid_t *oid, uint32_t compval[ZYNQ7000_PWM_CHANNELS], uint8_t mask); int zynq7000pwm_get(oid_t *oid, uint32_t compval[ZYNQ7000_PWM_CHANNELS]); #endif
b096333844b0b4b4bd42e6127177f0ea0dc92aad
26962b46d140217d8b0cb87ced475e76737f0663
/soc_sw/software/evsoc_ispExample_demo2/src/main.c
e33a04ea04117229e67ee92008bd977e49aa6554
[ "MIT" ]
permissive
AzharRISC-V/evsoc
1ca1a342f04da4494f3908fb5b9e870c46305a45
74437dc9e089a390974c8f697d8696ec92d853ca
refs/heads/main
2023-06-29T08:09:03.060262
2021-08-04T08:27:53
2021-08-04T08:27:53
null
0
0
null
null
null
null
UTF-8
C
false
false
14,187
c
main.c
#include "bsp.h" #include "i2c.h" #include "i2cDemo.h" #include <stdint.h> #include "io.h" #include "machineTimer.h" #include "riscv.h" #include "plic.h" #include "timerAndGpioInterruptDemo.h" #include "gpio.h" #include "uart.h" #include "common.h" #include "PiCamDriver.h" #include "apb3_cam.h" #include "hdmi_config.h" #include "hdmi_driver.h" #include "dmasg.h" #include "dmasg_config.h" #include "axi4_hw_accel.h" #include "isp.h" #define FRAME_WIDTH 1280 //640 #define FRAME_HEIGHT 720 //480 //Start address to be divided evenly by 8. Otherwise DMA tkeep might be shifted, not handled in display and hw_accel blocks. #define CAM_START_ADDR 0x01000000 #define GRAYSCALE_START_ADDR 0x02000000 #define SOBEL_START_ADDR 0x03000000 #define cam_array ((volatile uint32_t*)CAM_START_ADDR) #define grayscale_array ((volatile uint32_t*)GRAYSCALE_START_ADDR) #define sobel_array ((volatile uint32_t*)SOBEL_START_ADDR) u32 select_demo_mode=0; /*******************************************************DMA-RELATED FUNCTIONS******************************************************/ //For DMA interrupt uint32_t hw_accel_mm2s_active; uint32_t hw_accel_s2mm_active; uint32_t cam_s2mm_active; uint32_t display_mm2s_active; void trigger_next_display_dma () { //SELECT start address of to be displayed data accordingly if(select_demo_mode==0) { dmasg_input_memory(DMASG_BASE, DMASG_DISPLAY_MM2S_CHANNEL, CAM_START_ADDR, 16); } else { dmasg_input_memory(DMASG_BASE, DMASG_DISPLAY_MM2S_CHANNEL, SOBEL_START_ADDR, 16); } dmasg_output_stream(DMASG_BASE, DMASG_DISPLAY_MM2S_CHANNEL, DMASG_DISPLAY_MM2S_PORT, 0, 0, 1); dmasg_interrupt_config(DMASG_BASE, DMASG_DISPLAY_MM2S_CHANNEL, DMASG_CHANNEL_INTERRUPT_CHANNEL_COMPLETION_MASK); dmasg_direct_start(DMASG_BASE, DMASG_DISPLAY_MM2S_CHANNEL, (FRAME_WIDTH*FRAME_HEIGHT)*4, 0); } void externalInterrupt(){ uint32_t claim; //While there is pending interrupts while(claim = plic_claim(BSP_PLIC, BSP_PLIC_CPU_0)){ switch(claim){ case PLIC_DMASG_CHANNEL: if(hw_accel_mm2s_active && !(dmasg_busy(DMASG_BASE, DMASG_HW_ACCEL_MM2S_CHANNEL))) { dmasg_interrupt_config(DMASG_BASE, DMASG_HW_ACCEL_MM2S_CHANNEL, 0); //Disable dmasg channel interrupt hw_accel_mm2s_active = 0; } if(hw_accel_s2mm_active && !(dmasg_busy(DMASG_BASE, DMASG_HW_ACCEL_S2MM_CHANNEL))) { dmasg_interrupt_config(DMASG_BASE, DMASG_HW_ACCEL_S2MM_CHANNEL, 0); //Disable dmasg channel interrupt hw_accel_s2mm_active = 0; } if(cam_s2mm_active && !(dmasg_busy(DMASG_BASE, DMASG_CAM_S2MM_CHANNEL))) { dmasg_interrupt_config(DMASG_BASE, DMASG_CAM_S2MM_CHANNEL, 0); //Disable dmasg channel interrupt cam_s2mm_active = 0; } if(display_mm2s_active && !(dmasg_busy(DMASG_BASE, DMASG_DISPLAY_MM2S_CHANNEL))) { trigger_next_display_dma(); } break; default: crash(); break; } plic_release(BSP_PLIC, BSP_PLIC_CPU_0, claim); //unmask the claimed interrupt } } //Called by trap_entry on both exceptions and interrupts events void trap(){ int32_t mcause = csr_read(mcause); int32_t interrupt = mcause < 0; //Interrupt if true, exception if false int32_t cause = mcause & 0xF; if(interrupt){ switch(cause){ case CAUSE_MACHINE_EXTERNAL: externalInterrupt(); break; default: crash(); break; } } else { crash(); } } /*******************************************************DEMO-RELATED FUNCTIONS******************************************************/ void ispExample_menu() { uart_writeStr(BSP_UART_TERMINAL, "================================================================================\n\r"); uart_writeStr(BSP_UART_TERMINAL, " ISP Example Design Scenario Selection\n\r"); uart_writeStr(BSP_UART_TERMINAL, "================================================================================\n\r"); uart_writeStr(BSP_UART_TERMINAL, "00 : Camera Capture + HDMI Display \n\r"); uart_writeStr(BSP_UART_TERMINAL, "01 : Camera Capture + RGB2Grayscale (SW) + Sobel (HW) + HDMI Display \n\r"); uart_writeStr(BSP_UART_TERMINAL, "10 : Camera Capture + RGB2Grayscale & Sobel (HW) + HDMI Display \n\r"); uart_writeStr(BSP_UART_TERMINAL, "11 : Camera Capture + RGB2Grayscale & Sobel & Dilation (HW) + HDMI Display \n\r"); uart_writeStr(BSP_UART_TERMINAL, "================================================================================\n\n\r"); } /****************************************************************MAIN**************************************************************/ void main() { /**************************************************SETUP PICAM & HDMI DISPLAY***************************************************/ Set_MipiRst(1); Set_MipiRst(0); uart_writeStr(BSP_UART_TERMINAL, "\n\rHello Efinix Edge Vision SoC Demo!!\n\n\r"); //Mode selection using User DIP switches uart_writeStr(BSP_UART_TERMINAL, "Init HDMI I2C....."); hdmi_i2c_init(); hdmi_init(); uart_writeStr(BSP_UART_TERMINAL, "Done !!\n\r"); uart_writeStr(BSP_UART_TERMINAL, "Init MIPI I2C....."); mipi_i2c_init(); PiCam_init(); uart_writeStr(BSP_UART_TERMINAL, "Done !!\n\n\r"); Set_RGBGain(1,5,3,4); //SET camera pre-processing RGB gain value /**********************************************************SETUP DMA***********************************************************/ uart_writeStr(BSP_UART_TERMINAL, "Init DMA....."); dma_init(); dmasg_priority(DMASG_BASE, DMASG_HW_ACCEL_MM2S_CHANNEL, 0); dmasg_priority(DMASG_BASE, DMASG_HW_ACCEL_S2MM_CHANNEL, 0); dmasg_priority(DMASG_BASE, DMASG_DISPLAY_MM2S_CHANNEL, 0); dmasg_priority(DMASG_BASE, DMASG_CAM_S2MM_CHANNEL, 0); uart_writeStr(BSP_UART_TERMINAL, "Done !!\n\n\r"); /*******************************************************Trigger Display********************************************************/ //Read demo mode from user DIP switches select_demo_mode = example_register_read(EXAMPLE_APB3_SLV_REG13_OFFSET); u32 rdata; //To check display functionality uart_writeStr(BSP_UART_TERMINAL, "Initialize test display content..\n\r"); //Array name to be modified to DDR location used for display //Colour bar & Red dots at 4 corners of active display if(select_demo_mode==0) { //Initialize test image in cam_array for (int y=0; y<FRAME_HEIGHT; y++) { for (int x=0; x<FRAME_WIDTH; x++) { if ((x<3 && y<3) || (x>=FRAME_WIDTH-3 && y<3) || (x<3 && y>=FRAME_HEIGHT-3) || (x>=FRAME_WIDTH-3 && y>=FRAME_HEIGHT-3)) { cam_array [y*FRAME_WIDTH + x] = 0x000000FF; //RED } else if (x<(FRAME_WIDTH/4)) { cam_array [y*FRAME_WIDTH + x] = 0x0000FF00; //GREEN } else if (x<(FRAME_WIDTH/4 *2)) { cam_array [y*FRAME_WIDTH + x] = 0x00FF0000; //BLUE } else if (x<(FRAME_WIDTH/4 *3)) { cam_array [y*FRAME_WIDTH + x] = 0x000000FF; //RED } else { cam_array [y*FRAME_WIDTH + x] = 0x00FF0000; //BLUE } } } } else { //Initialize test image in sobel_array for (int y=0; y<FRAME_HEIGHT; y++) { for (int x=0; x<FRAME_WIDTH; x++) { if ((x<3 && y<3) || (x>=FRAME_WIDTH-3 && y<3) || (x<3 && y>=FRAME_HEIGHT-3) || (x>=FRAME_WIDTH-3 && y>=FRAME_HEIGHT-3)) { sobel_array [y*FRAME_WIDTH + x] = 0x000000FF; //RED } else if (x<(FRAME_WIDTH/4)) { sobel_array [y*FRAME_WIDTH + x] = 0x0000FF00; //GREEN } else if (x<(FRAME_WIDTH/4 *2)) { sobel_array [y*FRAME_WIDTH + x] = 0x00FF0000; //BLUE } else if (x<(FRAME_WIDTH/4 *3)) { sobel_array [y*FRAME_WIDTH + x] = 0x000000FF; //RED } else { sobel_array [y*FRAME_WIDTH + x] = 0x00FF0000; //BLUE } } } } //Trigger display DMA once then the rest handled by DMA self restart uart_writeStr(BSP_UART_TERMINAL, "\nTrigger display DMA..\n\r"); //SELECT start address of to be displayed data accordingly if(select_demo_mode==0) { dmasg_input_memory(DMASG_BASE, DMASG_DISPLAY_MM2S_CHANNEL, CAM_START_ADDR, 16); } else { dmasg_input_memory(DMASG_BASE, DMASG_DISPLAY_MM2S_CHANNEL, SOBEL_START_ADDR, 16); } dmasg_output_stream(DMASG_BASE, DMASG_DISPLAY_MM2S_CHANNEL, DMASG_DISPLAY_MM2S_PORT, 0, 0, 1); dmasg_interrupt_config(DMASG_BASE, DMASG_DISPLAY_MM2S_CHANNEL, DMASG_CHANNEL_INTERRUPT_CHANNEL_COMPLETION_MASK); dmasg_direct_start(DMASG_BASE, DMASG_DISPLAY_MM2S_CHANNEL, (FRAME_WIDTH*FRAME_HEIGHT)*4, 0); display_mm2s_active = 1; //Display always active msDelay(5000); //Display test content for 5 seconds uart_writeStr(BSP_UART_TERMINAL, "Done !!\n\n\r"); ispExample_menu(); uart_writeStr(BSP_UART_TERMINAL, "Adjust user DIP switches for demo mode selection.\n\n\r"); while (1) { select_demo_mode = example_register_read(EXAMPLE_APB3_SLV_REG13_OFFSET); /**********************************************************CAMERA CAPTURE***********************************************************/ //uart_writeStr(BSP_UART_TERMINAL, "\nTrigger camera capture..\n\r"); //SELECT RGB or grayscale output from camera pre-processing block. if(select_demo_mode==2 || select_demo_mode==3) { EXAMPLE_APB3_REGW(EXAMPLE_APB3_SLV, EXAMPLE_APB3_SLV_REG3_OFFSET, 0x00000001); //grayscale } else { EXAMPLE_APB3_REGW(EXAMPLE_APB3_SLV, EXAMPLE_APB3_SLV_REG3_OFFSET, 0x00000000); //RGB } //Trigger camera DMA dmasg_input_stream(DMASG_BASE, DMASG_CAM_S2MM_CHANNEL, DMASG_CAM_S2MM_PORT, 1, 0); dmasg_output_memory(DMASG_BASE, DMASG_CAM_S2MM_CHANNEL, CAM_START_ADDR, 16); dmasg_direct_start(DMASG_BASE, DMASG_CAM_S2MM_CHANNEL, (FRAME_WIDTH*FRAME_HEIGHT)*4, 0); //Indicate start of S2MM DMA to camera building block via APB3 slave EXAMPLE_APB3_REGW(EXAMPLE_APB3_SLV, EXAMPLE_APB3_SLV_REG4_OFFSET, 0x00000001); EXAMPLE_APB3_REGW(EXAMPLE_APB3_SLV, EXAMPLE_APB3_SLV_REG4_OFFSET, 0x00000000); //Trigger storage of one captured frame via APB3 slave EXAMPLE_APB3_REGW(EXAMPLE_APB3_SLV, EXAMPLE_APB3_SLV_REG2_OFFSET, 0x00000001); EXAMPLE_APB3_REGW(EXAMPLE_APB3_SLV, EXAMPLE_APB3_SLV_REG2_OFFSET, 0x00000000); //Wait for DMA transfer completion while(dmasg_busy(DMASG_BASE, DMASG_CAM_S2MM_CHANNEL)); flush_data_cache(); //uart_writeStr(BSP_UART_TERMINAL, "Done !!\n\n\r"); /*******************************************************RISC-V Processing***********************************************************/ //uart_writeStr(BSP_UART_TERMINAL, "\nRISC-V processing..\n\r"); if(select_demo_mode==1) { rgb2grayscale (cam_array, grayscale_array, FRAME_WIDTH, FRAME_HEIGHT); } //uart_writeStr(BSP_UART_TERMINAL, "Done !!\n\n\r"); /**********************************************************HW Accelerator***********************************************************/ //uart_writeStr(BSP_UART_TERMINAL, "\nHardware acceleration..\n\r"); if(select_demo_mode>0) { //SET Sobel edge detection threshold via AXI4 slave write_u32(100, EXAMPLE_AXI4_SLV+EXAMPLE_AXI4_SLV_REG0_OFFSET); //Default value 100; Range 0 to 255 //SELECT HW accelerator mode - Make sure match with DMA transfer length setting if(select_demo_mode==3) { write_u32(0x00000001, EXAMPLE_AXI4_SLV+EXAMPLE_AXI4_SLV_REG1_OFFSET); //2'd1: Sobel+Dilation } else { write_u32(0x00000000, EXAMPLE_AXI4_SLV+EXAMPLE_AXI4_SLV_REG1_OFFSET); //2'd0: Sobel only } // write_u32(0x00000002, EXAMPLE_AXI4_SLV+EXAMPLE_AXI4_SLV_REG1_OFFSET); //2'd2: Sobel+Erosion //Trigger HW accel MM2S DMA //SELECT start address of DMA input to HW accel block if(select_demo_mode==2 || select_demo_mode==3) { dmasg_input_memory(DMASG_BASE, DMASG_HW_ACCEL_MM2S_CHANNEL, CAM_START_ADDR, 16); //Camera pre-processing block performs HW RGB2grayscale conversion } else { dmasg_input_memory(DMASG_BASE, DMASG_HW_ACCEL_MM2S_CHANNEL, GRAYSCALE_START_ADDR, 16); //RISC-V performs SW RGB2grayscale conversion } dmasg_output_stream(DMASG_BASE, DMASG_HW_ACCEL_MM2S_CHANNEL, DMASG_HW_ACCEL_MM2S_PORT, 0, 0, 1); //SELECT dma transfer length - Make sure match with HW accelerator mode selection //Additonal data is required to be fed for line buffer(s) data flushing if(select_demo_mode==3) { dmasg_direct_start(DMASG_BASE, DMASG_HW_ACCEL_MM2S_CHANNEL, ((FRAME_WIDTH*FRAME_HEIGHT)+(2*FRAME_WIDTH+2))*4, 0); //Sobel + Dilation/Erosion } else { dmasg_direct_start(DMASG_BASE, DMASG_HW_ACCEL_MM2S_CHANNEL, ((FRAME_WIDTH*FRAME_HEIGHT)+(FRAME_WIDTH+1))*4, 0); //Sobel only } //Trigger HW accel S2MM DMA dmasg_input_stream(DMASG_BASE, DMASG_HW_ACCEL_S2MM_CHANNEL, DMASG_HW_ACCEL_S2MM_PORT, 1, 0); dmasg_output_memory(DMASG_BASE, DMASG_HW_ACCEL_S2MM_CHANNEL, SOBEL_START_ADDR, 16); dmasg_direct_start(DMASG_BASE, DMASG_HW_ACCEL_S2MM_CHANNEL, (FRAME_WIDTH*FRAME_HEIGHT)*4, 0); //Indicate start of S2MM DMA to HW accel building block via APB3 slave write_u32(0x00000001, EXAMPLE_AXI4_SLV+EXAMPLE_AXI4_SLV_REG2_OFFSET); write_u32(0x00000000, EXAMPLE_AXI4_SLV+EXAMPLE_AXI4_SLV_REG2_OFFSET); //Wait for DMA transfer completion while(dmasg_busy(DMASG_BASE, DMASG_HW_ACCEL_MM2S_CHANNEL) || dmasg_busy(DMASG_BASE, DMASG_HW_ACCEL_S2MM_CHANNEL)); flush_data_cache(); } //uart_writeStr(BSP_UART_TERMINAL, "Done !!\n\n\r"); } }
af82109b4323541abc1d01a945c008f1af8e4549
b5e64752255e066e3a4229dd3b11fb7ff19635a7
/src/level/LevelLoader.h
4f8392c97d1de55757363678545a626c4bbc74f1
[ "MIT" ]
permissive
blenkush/Avara
118555d0f886ae4479237a4d6853f88b7381e788
728b12a96adc18354366c0e3208b8526bc9f6559
refs/heads/master
2022-11-18T19:30:45.806636
2020-07-22T23:17:11
2020-07-22T23:17:11
257,180,895
1
1
MIT
2020-06-05T05:36:47
2020-04-20T05:30:48
C++
UTF-8
C
false
false
5,239
h
LevelLoader.h
/* Copyright ©1994-1996, Juri Munkki All rights reserved. File: LevelLoader.h Created: Sunday, November 20, 1994, 19:48 Modified: Tuesday, September 3, 1996, 21:44 */ #pragma once #include "Types.h" enum { iDesignerName, iLevelInformation, iTimeLimit, iGravity, iCustomGravity, iShape, iAltShape, iScale, iYon, iWallYon, iHasFloor, iWallTemplateResource, iFloorTemplateResource, iHeight, iMask, iTeam, iWallHeight, iWallAltitude, iBaseHeight, iPixelToThickness, iMass, iVisible, iThickness, iWinTeam, iTargetGroup, // Sounds: iHitSound, iHitVolume, iHitSoundDefault, iShieldHitSoundDefault, iPlayerHitSoundDefault, iBlastSound, iBlastVolume, iBlastSoundDefault, iStepSound, iGroundStepSound, iIsTarget, iSound, iOpenSound, iCloseSound, iStopSound, iVolume, iDefaultLives, iLives, iIncarnateSound, iIncarnateVolume, iWinSound, iWinVolume, iLoseSound, iLoseVolume, // Scoring iDestructScore, iHitScore, iFriendlyHitMultiplier, // Explosions and damage: iSlivers0, iSlivers1, iSlivers2, iSliverL0, iSliverL1, iSliverL2, iCanGlow, // Messages sent when hit/destroyed. iDestructMessage, iHitMessage, // Other messages. iStepOnMessage, // Motion iAccelerate, // Toggle switches iTogglePower, iBlastToggle, // Doors & such iOpenMsg, iCloseMsg, iDidOpen, iDidClose, iOpenDelay, iCloseDelay, iGuardDelay, iStatus, iOpenSpeed, iCloseSpeed, iPitch, iYaw, iRoll, iDeltaX, iDeltaY, iDeltaZ, // Door2 specific: iMidState, iMidPitch, iMidYaw, iMidRoll, iMidX, iMidY, iMidZ, // Misc iPower, iMaxPower, iDrain, // Guns iFireMsg, iTrackMsg, iStopTrackMsg, iSpeed, iShotPower, // Ufos iCheckPeriod, iAttack, iDefense, iVisionScore, iHideScore, iMotionRange, iPitchRange, iVerticalRangeMin, iVerticalRangeMax, iBurstLength, iBurstSpeed, iBurstCharge, iHomeSick, iHomeRange, iHomeBase, // Mines iShieldEnergy, iActivateEnergy, iRange, iPhase, iActiveTimer, iBoom, iIdleShapeTimer, iIdleAltShapeTimer, iActiveShapeTimer, iActiveAltShapeTimer, iActivateSound, iActivateVolume, // Teleporters: iGroup, iDestGroup, iSpinFlag, iFragmentFlag, iWin, iDeadRange, iShowAlways, // Activators: (areas, etc.) iWatchMask, iFrequency, iEnter, iExit, // Text iText, iShowEveryone, iAlignment, // Goody iGrenades, iMissiles, iBoosters, iBoostTime, // Ball & goal iGoalMsg, iGoalAction, iGoalScore, iEjectPitch, iEjectPower, iEjectSound, iEjectVolume, iShieldChargeRate, iMaxShield, iShootShield, iGrabShield, iCarryScore, iDropEnergy, iChangeHolderPower, iChangeOwnerTime, iChangeOwnerSound, iChangeOwnerVolume, iSnapSound, iSnapVolume, // Sound objects: iIsMusic, iIsAmbient, iIsPlaced, iRate, iLoopCount, iVolume0, iVolume1, iStartMsg, iStopMsg, iKillMsg, // Logic: iInVar, iFirstIn, iLastIn = iFirstIn + 9, iOutVar, iFirstOut, iLastOut = iFirstOut + 9, iRestartFlag, iCount, iTimer, // Lights iAmbient, iLightsTable, iLightsTableEnd = iLightsTable + 11, // a 3 x 4 table // Advanced weapons iGrenadePower, iMissilePower, iMissileTurnRate, iMissileAcceleration, iMaxStartGrenades, iMaxStartMissiles, iMaxStartBoosts, // Hulls iFirstHull, iSecondHull, iThirdHull, // Traction/friction control: iDefaultTraction, iDefaultFriction, iWallTraction, iWallFriction, iTraction, iFriction, iWallShields, iWallPower, iVarInternalVariableCount }; double ReadVariable(short index); Fixed ReadFixedVar(short index); long ReadLongVar(short index); long ReadColorVar(short index); void ReadStringVar(short index, StringPtr dest); void ProgramVariable(short index, double value); void ProgramFixedVar(short index, Fixed value); void ProgramLongVar(short index, long value); void ProgramReference(short index, short ref); void ProgramOffsetAdd(short index, short ref, long addValue); void ProgramOffsetMultiply(short index, short ref, long addValue); void ProgramMessage(short index, long value); enum { TextBegin = 150, // 6 TTxtPicRec Begin text function TextEnd = 151, // 0 NIL End text function StringBegin = 152, // 0 NIL Begin string delimitation StringEnd = 153 // 0 NIL End string delimitation }; void ConvertToLevelMap(Handle levelData); void SVGConvertToLevelMap(); void GetLastArcLocation(Fixed *theLoc); Fixed GetLastArcDirection(); Fixed GetDome(Fixed *theLoc, Fixed *startAngle, Fixed *spanAngle); int GetPixelColor(); int GetOtherPixelColor(); Fixed GetLastOval(Fixed *theLoc);
dd53d9f5be42ffc62100b0101d10450b70bf3e0b
3ff00f6bc16e5487c2c524116864464b2bffbd33
/LCDm169/pause.c
97ad880ec216a76d2d001f14c8707c60e18ba157
[]
no_license
AdrianGin/avr-datalogger
c0bdde6c600cccf24a5994b8828b8b076df805b0
265d2be62cce9e8fd21a48850972c8eb815ed3a2
refs/heads/master
2021-01-13T00:45:10.518178
2016-04-20T12:08:35
2016-04-20T12:08:35
51,397,113
0
0
null
null
null
null
UTF-8
C
false
false
1,092
c
pause.c
/* pause.c * Delay and pause Routines for the AVR Mega8 * * Date: 16/04/06 * Author : Adrian Gin (amg94@student.canterbury.ac.nz) * * */ #include <stdint.h> #include <avr/io.h> #include <avr/iom169.h> #define F_CPU 8000000UL #include <util/delay.h> #define RESET 0x00 #define clk64 0x03 #define clk256 0x04 #define clk1024 0x05 #define CLK 1 /*Speed of micro in MHz*/ #define _INCLUDE_TIMER_DELAY 0 #if _INCLUDE_TIMER_DELAY /* pause: Set 8Bit Timer0 to clock at 256th the internal clock speed*/ void pause (uint16_t PDELAY) { uint16_t i; TCCR0 = clk256; for (i = 0; i < PDELAY; i++) { TCNT0 = RESET; while (TCNT0 < 4) {;} } } #endif /* pausems: * Do nothing for the passed number of milliseconds * * This function depends on the </util/delay.h> header file. */ #define TIMEMS 2045 /*for 1Mhz (91)*/ void pausems(uint16_t Delay) { uint16_t i; for(i = 0; i < Delay; i++) { _delay_loop_2(TIMEMS); } }
8d154b50a5a0f6915a83530df9620d3b360b92e5
664a14b0998a94c1c5f2695a66c6452aaf6c2c49
/from_boomerang/fromssa2/sparc_elf_from_boomerang/by_reko.globals.c
2bd7b36db57402d4f2388bfe18ff44b1058d6e80
[]
no_license
xiaobo996/decompiler-subjects
2d8712a3ef0c031d2cf44b3e69ec8b03983cd366
d8d55ee11f095405aeb420fa982f260dd85b5831
refs/heads/master
2023-03-15T10:26:13.249349
2021-03-14T16:47:33
2021-03-14T16:47:33
null
0
0
null
null
null
null
UTF-8
C
false
false
276
c
by_reko.globals.c
// subject.globals.c // Generated by decompiling subject.exe // using Reko decompiler version VERSION #include "subject.h" Eq_2 g_t1074C = Unexpected function type (fn void ()) ; char g_str10768[] = "%d "; char g_str10770[] = "a is %d, x is %d\n"; ptr32 g_ptr20930 = 0x00;
975badb2227fca3d546ce97f9f3cbfba276b7b00
debe3bab34f7b1c28fc67c3845269d6bc2c2a0c3
/writenew.c
6a2ae62aaccfc2cc02d006ac94e5270ded89de36
[]
no_license
jobbinejoseph/write2file
580987e6de7f4fed80606f6effe1ff5904814554
857a0bbe8c3af1ae66e474e9bf6a9d56ca1cc293
refs/heads/master
2022-12-18T15:14:59.473447
2020-09-29T19:36:23
2020-09-29T19:36:23
298,754,659
1
0
null
null
null
null
UTF-8
C
false
false
1,155
c
writenew.c
#include<stdio.h> #include<stdlib.h> #include<string.h> #include "writenew.h" int main_fun(int argc, char *argv){ char *argmv[] = {"./a.out",argv}; return(main(argc,argmv)); } int main(int argc , char *argv[]){ const char *filepath; char buffer[4] = { 0 }; int bytesize = 4; FILE *ptr_myfile; if(argc!=2){ fprintf(stderr, "Usage : Program <space> file"); fprintf(stderr, " Eg: ./binary file.txt\n"); } filepath = argv[1]; ptr_myfile = fopen(filepath,"wb"); if(!ptr_myfile){ printf("Cannot open file"); return (1); } fprintf(stderr,"Press ctrl+D once done\n"); if(!freopen(NULL,"rb",stdin)){ fprintf(stderr,"Can't open the file"); return (4); } while(!feof(stdin)){ fread(buffer,bytesize,1,stdin); fwrite(buffer,bytesize,1,ptr_myfile); memset(buffer,0,4); } fclose(stdin); fclose(ptr_myfile); fprintf(stderr,"\nExit reading\n"); return (0); }
46b28f38e28a19f8c909ada24c8f96b4befdfccf
6425e1939600a3519f554f9d231f2c742a72ddb6
/source/delay.h
83dfecb1a0bf13e85b05e95778363657ac0b836c
[]
no_license
hyq19921011/chogndianqi
04e10da8eaddad210263e5f90511041c716f1e9a
fc91e51a37affc5ab20df804427b2507199573b4
refs/heads/master
2020-05-18T02:27:23.796583
2015-07-02T01:41:03
2015-07-02T01:41:03
null
0
0
null
null
null
null
UTF-8
C
false
false
126
h
delay.h
#ifndef _delay_h_ #define _delay_h_ extern void Delay_nms(unsigned int count); extern void delay_ms(unsigned int ms); #endif
fe07c890056515eadc4b50af6ce9c8fa36117ae1
42401aa005f42f4d2e9a793634b8ff4cd0b0149a
/kernel/nvgpu/drivers/gpu/nvgpu/hal/clk/clk_gm20b.c
34d3ae904b6ca3e297af08f991fa408a6548cedc
[]
no_license
alliedvision/linux_nvidia_jetson
9d0b4123cf0fdde72ba954869793c2559a214b03
4609206e6594f1eb21e43e69afa8974cf20cc096
refs/heads/master
2023-07-25T03:30:15.803217
2023-03-30T10:49:34
2023-03-30T10:49:34
213,576,886
89
42
null
2023-08-22T04:03:17
2019-10-08T07:32:53
C
UTF-8
C
false
false
51,184
c
clk_gm20b.c
/* * GM20B Clocks * * Copyright (c) 2014-2022, NVIDIA CORPORATION. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include <nvgpu/soc.h> #include <nvgpu/fuse.h> #include <nvgpu/bug.h> #include <nvgpu/log.h> #include <nvgpu/types.h> #include <nvgpu/io.h> #include <nvgpu/utils.h> #include <nvgpu/timers.h> #include <nvgpu/gk20a.h> #include <nvgpu/nvgpu_init.h> #include <nvgpu/therm.h> #include <nvgpu/pmu/clk/clk.h> #include "clk_gm20b.h" #include <nvgpu/hw/gm20b/hw_trim_gm20b.h> #include <nvgpu/hw/gm20b/hw_fuse_gm20b.h> #define gk20a_dbg_clk(g, fmt, arg...) \ nvgpu_log(g, gpu_dbg_clk, fmt, ##arg) #define DFS_DET_RANGE 6U /* -2^6 ... 2^6-1 */ #define SDM_DIN_RANGE 12U /* -2^12 ... 2^12-1 */ #define DFS_TESTOUT_DET BIT32(0) #define DFS_EXT_CAL_EN BIT32(9) #define DFS_EXT_STROBE BIT32(16) #define BOOT_GPU_UV_B1 1000000 /* gpu rail boot voltage 1.0V */ #define BOOT_GPU_UV_C1 800000 /* gpu rail boot voltage 0.8V */ #define ADC_SLOPE_UV 10000 /* default ADC detection slope 10mV */ #define DVFS_SAFE_MARGIN 10U /* 10% */ static struct pll_parms gpc_pll_params_b1 = { 128000, 2600000, /* freq */ 1300000, 2600000, /* vco */ 12000, 38400, /* u */ 1, 255, /* M */ 8, 255, /* N */ 1, 31, /* PL */ -165230, 214007, /* DFS_COEFF */ 0, 0, /* ADC char coeff - to be read from fuses */ 0x7 << 3, /* vco control in NA mode */ 500, /* Locking and ramping timeout */ 40, /* Lock delay in NA mode */ 5, /* IDDQ mode exit delay */ 0, /* DFS control settings */ }; static struct pll_parms gpc_pll_params_c1 = { 76800, 2600000, /* freq */ 1300000, 2600000, /* vco */ 19200, 38400, /* u */ 1, 255, /* M */ 8, 255, /* N */ 1, 31, /* PL */ -172550, 195374, /* DFS_COEFF */ 0, 0, /* ADC char coeff - to be read from fuses */ (0x1 << 3) | 0x7, /* vco control in NA mode */ 500, /* Locking and ramping timeout */ 40, /* Lock delay in NA mode */ 5, /* IDDQ mode exit delay */ 0x3 << 10, /* DFS control settings */ }; static struct pll_parms gpc_pll_params; static void clk_setup_slide(struct gk20a *g, u32 clk_u); static void dump_gpc_pll(struct gk20a *g, struct pll *gpll, u32 last_cfg) { #define __DUMP_REG(__addr_str__) \ do { \ u32 __addr__ = trim_sys_ ## __addr_str__ ## _r(); \ u32 __data__ = gk20a_readl(g, __addr__); \ \ nvgpu_info(g, " " #__addr_str__ " [0x%x] = 0x%x", \ __addr__, __data__); \ } while (false) nvgpu_info(g, "GPCPLL DUMP:"); nvgpu_info(g, " gpcpll s/w M=%u N=%u P=%u\n", gpll->M, gpll->N, gpll->PL); nvgpu_info(g, " gpcpll_cfg_last = 0x%x\n", last_cfg); __DUMP_REG(gpcpll_cfg); __DUMP_REG(gpcpll_coeff); __DUMP_REG(sel_vco); #undef __DUMP_REG } #define PLDIV_GLITCHLESS 1 #if PLDIV_GLITCHLESS /* * Post divider tarnsition is glitchless only if there is common "1" in binary * representation of old and new settings. */ static u32 get_interim_pldiv(struct gk20a *g, u32 old_pl, u32 new_pl) { u32 pl; unsigned long ffs_old_pl = nvgpu_ffs(old_pl); unsigned long ffs_new_pl = nvgpu_ffs(new_pl); if ((g->clk.gpc_pll.id == GM20B_GPC_PLL_C1) || ((old_pl & new_pl) != 0U) || (ffs_old_pl == 0UL) || (ffs_new_pl == 0UL)) { return 0; } pl = old_pl | BIT32(nvgpu_safe_cast_u64_to_u32(ffs_new_pl) - 1U); /* pl never 0 */ new_pl |= BIT32(nvgpu_safe_cast_u64_to_u32(ffs_old_pl) - 1U); return min(pl, new_pl); } #endif /* Calculate and update M/N/PL as well as pll->freq ref_clk_f = clk_in_f; u_f = ref_clk_f / M; vco_f = u_f * N = ref_clk_f * N / M; PLL output = gpc2clk = target clock frequency = vco_f / pl_to_pdiv(PL); gpcclk = gpc2clk / 2; */ static void clk_config_pll(struct clk_gk20a *clk, struct pll *pll, struct pll_parms *pll_params, u32 *target_freq, bool best_fit) { struct gk20a *g = clk->g; u32 min_vco_f, max_vco_f; u32 best_M, best_N; u32 low_PL, high_PL, best_PL; u32 m, n, n2; u32 target_vco_f, vco_f; u32 ref_clk_f, target_clk_f, u_f; u32 delta, lwv, best_delta = ~U32(0U); u32 pl; BUG_ON(target_freq == NULL); nvgpu_log_fn(g, "request target freq %d MHz", *target_freq); ref_clk_f = pll->clk_in; target_clk_f = *target_freq; max_vco_f = pll_params->max_vco; min_vco_f = pll_params->min_vco; best_M = pll_params->max_M; best_N = pll_params->min_N; best_PL = pll_params->min_PL; target_vco_f = target_clk_f + target_clk_f / 50U; if (max_vco_f < target_vco_f) { max_vco_f = target_vco_f; } /* Set PL search boundaries. */ high_PL = nvgpu_div_to_pl((max_vco_f + target_vco_f - 1U) / target_vco_f); high_PL = min(high_PL, pll_params->max_PL); high_PL = max(high_PL, pll_params->min_PL); low_PL = nvgpu_div_to_pl(min_vco_f / target_vco_f); low_PL = min(low_PL, pll_params->max_PL); low_PL = max(low_PL, pll_params->min_PL); nvgpu_log_info(g, "low_PL %d(div%d), high_PL %d(div%d)", low_PL, nvgpu_pl_to_div(low_PL), high_PL, nvgpu_pl_to_div(high_PL)); for (pl = low_PL; pl <= high_PL; pl++) { target_vco_f = target_clk_f * nvgpu_pl_to_div(pl); for (m = pll_params->min_M; m <= pll_params->max_M; m++) { u_f = ref_clk_f / m; if (u_f < pll_params->min_u) { break; } if (u_f > pll_params->max_u) { continue; } n = (target_vco_f * m) / ref_clk_f; n2 = ((target_vco_f * m) + (ref_clk_f - 1U)) / ref_clk_f; if (n > pll_params->max_N) { break; } for (; n <= n2; n++) { if (n < pll_params->min_N) { continue; } if (n > pll_params->max_N) { break; } vco_f = ref_clk_f * n / m; if (vco_f >= min_vco_f && vco_f <= max_vco_f) { lwv = (vco_f + (nvgpu_pl_to_div(pl) / 2U)) / nvgpu_pl_to_div(pl); delta = (u32)abs(S32(lwv) - S32(target_clk_f)); if (delta < best_delta) { best_delta = delta; best_M = m; best_N = n; best_PL = pl; if (best_delta == 0U || /* 0.45% for non best fit */ (!best_fit && (vco_f / best_delta > 218U))) { goto found_match; } nvgpu_log_info(g, "delta %d @ M %d, N %d, PL %d", delta, m, n, pl); } } } } } found_match: BUG_ON(best_delta == ~0U); if (best_fit && best_delta != 0U) { gk20a_dbg_clk(g, "no best match for target @ %dMHz on gpc_pll", target_clk_f); } pll->M = best_M; pll->N = best_N; pll->PL = best_PL; /* save current frequency */ pll->freq = ref_clk_f * pll->N / (pll->M * nvgpu_pl_to_div(pll->PL)); *target_freq = pll->freq; gk20a_dbg_clk(g, "actual target freq %d kHz, M %d, N %d, PL %d(div%d)", *target_freq, pll->M, pll->N, pll->PL, nvgpu_pl_to_div(pll->PL)); nvgpu_log_fn(g, "done"); } /* GPCPLL NA/DVFS mode methods */ static inline u32 fuse_get_gpcpll_adc_rev(u32 val) { return (val >> 30) & 0x3U; } static inline int fuse_get_gpcpll_adc_slope_uv(u32 val) { /* Integer part in mV * 1000 + fractional part in uV */ return (int)(((val >> 24) & 0x3fU) * 1000U + ((val >> 14) & 0x3ffU)); } static inline int fuse_get_gpcpll_adc_intercept_uv(u32 val) { /* Integer part in mV * 1000 + fractional part in 100uV */ return (int)(((val >> 4) & 0x3ffU) * 1000U + ((val >> 0) & 0xfU) * 100U); } static int nvgpu_fuse_calib_gpcpll_get_adc(struct gk20a *g, int *slope_uv, int *intercept_uv) { u32 val; int ret; ret = nvgpu_tegra_fuse_read_reserved_calib(g, &val); if (ret != 0) { return ret; } if (fuse_get_gpcpll_adc_rev(val) == 0U) { return -EINVAL; } *slope_uv = fuse_get_gpcpll_adc_slope_uv(val); *intercept_uv = fuse_get_gpcpll_adc_intercept_uv(val); return 0; } /* * Read ADC characteristic parmeters from fuses. * Determine clibration settings. */ static void clk_config_calibration_params(struct gk20a *g) { int slope, offs; struct pll_parms *p = &gpc_pll_params; if (nvgpu_fuse_calib_gpcpll_get_adc(g, &slope, &offs) == 0) { p->uvdet_slope = slope; p->uvdet_offs = offs; } if ((p->uvdet_slope == 0) || (p->uvdet_offs == 0)) { /* * If ADC conversion slope/offset parameters are not fused * (non-production config), report error, but allow to use * boot internal calibration with default slope. */ nvgpu_err(g, "ADC coeff are not fused"); } } /* * Determine DFS_COEFF for the requested voltage. Always select external * calibration override equal to the voltage, and set maximum detection * limit "0" (to make sure that PLL output remains under F/V curve when * voltage increases). */ static void clk_config_dvfs_detection(int mv, struct na_dvfs *d) { u32 coeff, coeff_max; struct pll_parms *p = &gpc_pll_params; coeff_max = trim_sys_gpcpll_dvfs0_dfs_coeff_v( trim_sys_gpcpll_dvfs0_dfs_coeff_m()); coeff = (u32)(DIV_ROUND_CLOSEST(mv * p->coeff_slope, 1000) + p->coeff_offs); coeff = DIV_ROUND_CLOSEST(coeff, 1000U); coeff = min(coeff, coeff_max); d->dfs_coeff = (int)coeff; d->dfs_ext_cal = DIV_ROUND_CLOSEST(mv * 1000 - p->uvdet_offs, p->uvdet_slope); BUG_ON(U32(abs(d->dfs_ext_cal)) >= BIT32(DFS_DET_RANGE)); d->uv_cal = p->uvdet_offs + d->dfs_ext_cal * p->uvdet_slope; d->dfs_det_max = 0; } /* * Solve equation for integer and fractional part of the effective NDIV: * * n_eff = n_int + 1/2 + SDM_DIN / 2^(SDM_DIN_RANGE + 1) + * DVFS_COEFF * DVFS_DET_DELTA / 2^DFS_DET_RANGE * * The SDM_DIN LSB is finally shifted out, since it is not accessible by s/w. */ static void clk_config_dvfs_ndiv(int mv, u32 n_eff, struct na_dvfs *d) { int n, det_delta; u32 rem, rem_range; struct pll_parms *p = &gpc_pll_params; det_delta = DIV_ROUND_CLOSEST(mv * 1000 - p->uvdet_offs, p->uvdet_slope); det_delta -= d->dfs_ext_cal; det_delta = min(det_delta, d->dfs_det_max); det_delta = det_delta * d->dfs_coeff; n = ((int)n_eff << DFS_DET_RANGE) - det_delta; BUG_ON((n < 0) || (n > (int)p->max_N << DFS_DET_RANGE)); d->n_int = ((u32)n) >> DFS_DET_RANGE; rem = ((u32)n) & (BIT32(DFS_DET_RANGE) - 1U); rem_range = SDM_DIN_RANGE + 1U - DFS_DET_RANGE; d->sdm_din = (rem << rem_range) - BIT32(SDM_DIN_RANGE); d->sdm_din = (d->sdm_din >> BITS_PER_BYTE) & 0xffU; } /* Voltage dependent configuration */ static int clk_config_dvfs(struct gk20a *g, struct pll *gpll) { struct na_dvfs *d = &gpll->dvfs; d->mv = g->ops.clk.predict_mv_at_hz_cur_tfloor(&g->clk, rate_gpc2clk_to_gpu(gpll->freq)); if (d->mv < 0) { return d->mv; } clk_config_dvfs_detection(d->mv, d); clk_config_dvfs_ndiv(d->mv, gpll->N, d); return 0; } /* Update DVFS detection settings in flight */ static void clk_set_dfs_coeff(struct gk20a *g, u32 dfs_coeff) { u32 data = gk20a_readl(g, trim_gpc_bcast_gpcpll_dvfs2_r()); data |= DFS_EXT_STROBE; gk20a_writel(g, trim_gpc_bcast_gpcpll_dvfs2_r(), data); data = gk20a_readl(g, trim_sys_gpcpll_dvfs0_r()); data = set_field(data, trim_sys_gpcpll_dvfs0_dfs_coeff_m(), trim_sys_gpcpll_dvfs0_dfs_coeff_f(dfs_coeff)); gk20a_writel(g, trim_sys_gpcpll_dvfs0_r(), data); data = gk20a_readl(g, trim_gpc_bcast_gpcpll_dvfs2_r()); nvgpu_udelay(1); data &= ~DFS_EXT_STROBE; gk20a_writel(g, trim_gpc_bcast_gpcpll_dvfs2_r(), data); } static void __attribute__((unused)) clk_set_dfs_det_max(struct gk20a *g, u32 dfs_det_max) { u32 data = gk20a_readl(g, trim_gpc_bcast_gpcpll_dvfs2_r()); data |= DFS_EXT_STROBE; gk20a_writel(g, trim_gpc_bcast_gpcpll_dvfs2_r(), data); data = gk20a_readl(g, trim_sys_gpcpll_dvfs0_r()); data = set_field(data, trim_sys_gpcpll_dvfs0_dfs_det_max_m(), trim_sys_gpcpll_dvfs0_dfs_det_max_f(dfs_det_max)); gk20a_writel(g, trim_sys_gpcpll_dvfs0_r(), data); data = gk20a_readl(g, trim_gpc_bcast_gpcpll_dvfs2_r()); nvgpu_udelay(1); data &= ~DFS_EXT_STROBE; gk20a_writel(g, trim_gpc_bcast_gpcpll_dvfs2_r(), data); } static void clk_set_dfs_ext_cal(struct gk20a *g, u32 dfs_det_cal) { u32 data, ctrl; data = gk20a_readl(g, trim_gpc_bcast_gpcpll_dvfs2_r()); data &= ~(BIT32(DFS_DET_RANGE + 1U) - 1U); data |= dfs_det_cal & (BIT32(DFS_DET_RANGE + 1U) - 1U); gk20a_writel(g, trim_gpc_bcast_gpcpll_dvfs2_r(), data); data = gk20a_readl(g, trim_sys_gpcpll_dvfs1_r()); nvgpu_udelay(1); ctrl = trim_sys_gpcpll_dvfs1_dfs_ctrl_v(data); if ((~ctrl & DFS_EXT_CAL_EN) != 0U) { data = set_field(data, trim_sys_gpcpll_dvfs1_dfs_ctrl_m(), trim_sys_gpcpll_dvfs1_dfs_ctrl_f( ctrl | DFS_EXT_CAL_EN | DFS_TESTOUT_DET)); gk20a_writel(g, trim_sys_gpcpll_dvfs1_r(), data); } } static void clk_setup_dvfs_detection(struct gk20a *g, struct pll *gpll) { struct na_dvfs *d = &gpll->dvfs; u32 data = gk20a_readl(g, trim_gpc_bcast_gpcpll_dvfs2_r()); data |= DFS_EXT_STROBE; gk20a_writel(g, trim_gpc_bcast_gpcpll_dvfs2_r(), data); data = gk20a_readl(g, trim_sys_gpcpll_dvfs0_r()); data = set_field(data, trim_sys_gpcpll_dvfs0_dfs_coeff_m(), trim_sys_gpcpll_dvfs0_dfs_coeff_f(d->dfs_coeff)); data = set_field(data, trim_sys_gpcpll_dvfs0_dfs_det_max_m(), trim_sys_gpcpll_dvfs0_dfs_det_max_f(d->dfs_det_max)); gk20a_writel(g, trim_sys_gpcpll_dvfs0_r(), data); data = gk20a_readl(g, trim_gpc_bcast_gpcpll_dvfs2_r()); nvgpu_udelay(1); data &= ~DFS_EXT_STROBE; gk20a_writel(g, trim_gpc_bcast_gpcpll_dvfs2_r(), data); clk_set_dfs_ext_cal(g, (u32)d->dfs_ext_cal); } /* Enable NA/DVFS mode */ static int clk_enbale_pll_dvfs(struct gk20a *g) { u32 data, cfg = 0; u32 delay = gpc_pll_params.iddq_exit_delay; /* iddq & calib delay */ struct pll_parms *p = &gpc_pll_params; bool calibrated = (p->uvdet_slope != 0) && (p->uvdet_offs != 0); /* Enable NA DVFS */ data = gk20a_readl(g, trim_sys_gpcpll_dvfs1_r()); data |= trim_sys_gpcpll_dvfs1_en_dfs_m(); gk20a_writel(g, trim_sys_gpcpll_dvfs1_r(), data); /* Set VCO_CTRL */ if (p->vco_ctrl != 0U) { data = gk20a_readl(g, trim_sys_gpcpll_cfg3_r()); data = set_field(data, trim_sys_gpcpll_cfg3_vco_ctrl_m(), trim_sys_gpcpll_cfg3_vco_ctrl_f(p->vco_ctrl)); gk20a_writel(g, trim_sys_gpcpll_cfg3_r(), data); } /* Set NA mode DFS control */ if (p->dfs_ctrl != 0U) { data = gk20a_readl(g, trim_sys_gpcpll_dvfs1_r()); data = set_field(data, trim_sys_gpcpll_dvfs1_dfs_ctrl_m(), trim_sys_gpcpll_dvfs1_dfs_ctrl_f(p->dfs_ctrl)); gk20a_writel(g, trim_sys_gpcpll_dvfs1_r(), data); } /* * If calibration parameters are known (either from fuses, or from * internal calibration on boot) - use them. Internal calibration is * started anyway; it will complete, but results will not be used. */ if (calibrated) { data = gk20a_readl(g, trim_sys_gpcpll_dvfs1_r()); data |= trim_sys_gpcpll_dvfs1_en_dfs_cal_m(); gk20a_writel(g, trim_sys_gpcpll_dvfs1_r(), data); } /* Exit IDDQ mode */ data = gk20a_readl(g, trim_sys_gpcpll_cfg_r()); data = set_field(data, trim_sys_gpcpll_cfg_iddq_m(), trim_sys_gpcpll_cfg_iddq_power_on_v()); gk20a_writel(g, trim_sys_gpcpll_cfg_r(), data); (void) gk20a_readl(g, trim_sys_gpcpll_cfg_r()); nvgpu_udelay(delay); /* * Dynamic ramp setup based on update rate, which in DVFS mode on GM20b * is always 38.4 MHz, the same as reference clock rate. */ clk_setup_slide(g, g->clk.gpc_pll.clk_in); if (calibrated) { return 0; } /* * If calibration parameters are not fused, start internal calibration, * wait for completion, and use results along with default slope to * calculate ADC offset during boot. */ data = gk20a_readl(g, trim_sys_gpcpll_dvfs1_r()); data |= trim_sys_gpcpll_dvfs1_en_dfs_cal_m(); gk20a_writel(g, trim_sys_gpcpll_dvfs1_r(), data); /* C1 PLL must be enabled to read internal calibration results */ if (g->clk.gpc_pll.id == GM20B_GPC_PLL_C1) { cfg = gk20a_readl(g, trim_sys_gpcpll_cfg_r()); cfg = set_field(cfg, trim_sys_gpcpll_cfg_enable_m(), trim_sys_gpcpll_cfg_enable_yes_f()); gk20a_writel(g, trim_sys_gpcpll_cfg_r(), cfg); } /* Wait for internal calibration done (spec < 2us). */ do { data = gk20a_readl(g, trim_sys_gpcpll_dvfs1_r()); if (trim_sys_gpcpll_dvfs1_dfs_cal_done_v(data) != 0U) { break; } nvgpu_udelay(1); delay--; } while (delay > 0); /* Read calibration results */ data = gk20a_readl(g, trim_sys_gpcpll_cfg3_r()); data = trim_sys_gpcpll_cfg3_dfs_testout_v(data); if (g->clk.gpc_pll.id == GM20B_GPC_PLL_C1) { cfg = set_field(cfg, trim_sys_gpcpll_cfg_enable_m(), trim_sys_gpcpll_cfg_enable_no_f()); gk20a_writel(g, trim_sys_gpcpll_cfg_r(), cfg); cfg = gk20a_readl(g, trim_sys_gpcpll_cfg_r()); } if (delay <= 0) { nvgpu_err(g, "GPCPLL calibration timeout"); return -ETIMEDOUT; } p->uvdet_offs = g->clk.pll_poweron_uv - (int)data * ADC_SLOPE_UV; p->uvdet_slope = ADC_SLOPE_UV; return 0; } /* GPCPLL slide methods */ static void clk_setup_slide(struct gk20a *g, u32 clk_u) { u32 data, step_a, step_b; switch (clk_u) { case 12000: case 12800: case 13000: /* only on FPGA */ step_a = 0x2B; step_b = 0x0B; break; case 19200: step_a = 0x12; step_b = 0x08; break; case 38400: step_a = 0x04; step_b = 0x05; break; default: nvgpu_err(g, "Unexpected reference rate %u kHz", clk_u); BUG(); step_a = 0U; step_b = 0U; break; } /* setup */ data = gk20a_readl(g, trim_sys_gpcpll_cfg2_r()); data = set_field(data, trim_sys_gpcpll_cfg2_pll_stepa_m(), trim_sys_gpcpll_cfg2_pll_stepa_f(step_a)); gk20a_writel(g, trim_sys_gpcpll_cfg2_r(), data); data = gk20a_readl(g, trim_sys_gpcpll_cfg3_r()); data = set_field(data, trim_sys_gpcpll_cfg3_pll_stepb_m(), trim_sys_gpcpll_cfg3_pll_stepb_f(step_b)); gk20a_writel(g, trim_sys_gpcpll_cfg3_r(), data); } static int clk_slide_gpc_pll(struct gk20a *g, struct pll *gpll) { u32 data, coeff; u32 nold, sdm_old; int ramp_timeout = (int)gpc_pll_params.lock_timeout; /* get old coefficients */ coeff = gk20a_readl(g, trim_sys_gpcpll_coeff_r()); nold = trim_sys_gpcpll_coeff_ndiv_v(coeff); /* do nothing if NDIV is same */ if (gpll->mode == GPC_PLL_MODE_DVFS) { /* in DVFS mode check both integer and fraction */ coeff = gk20a_readl(g, trim_sys_gpcpll_cfg2_r()); sdm_old = trim_sys_gpcpll_cfg2_sdm_din_v(coeff); if ((gpll->dvfs.n_int == nold) && (gpll->dvfs.sdm_din == sdm_old)) { return 0; } } else { if (gpll->N == nold) { return 0; } /* dynamic ramp setup based on update rate */ clk_setup_slide(g, gpll->clk_in / gpll->M); } /* pll slowdown mode */ data = gk20a_readl(g, trim_sys_gpcpll_ndiv_slowdown_r()); data = set_field(data, trim_sys_gpcpll_ndiv_slowdown_slowdown_using_pll_m(), trim_sys_gpcpll_ndiv_slowdown_slowdown_using_pll_yes_f()); gk20a_writel(g, trim_sys_gpcpll_ndiv_slowdown_r(), data); /* new ndiv ready for ramp */ if (gpll->mode == GPC_PLL_MODE_DVFS) { /* in DVFS mode SDM is updated via "new" field */ coeff = gk20a_readl(g, trim_sys_gpcpll_cfg2_r()); coeff = set_field(coeff, trim_sys_gpcpll_cfg2_sdm_din_new_m(), trim_sys_gpcpll_cfg2_sdm_din_new_f(gpll->dvfs.sdm_din)); gk20a_writel(g, trim_sys_gpcpll_cfg2_r(), coeff); coeff = gk20a_readl(g, trim_sys_gpcpll_coeff_r()); coeff = set_field(coeff, trim_sys_gpcpll_coeff_ndiv_m(), trim_sys_gpcpll_coeff_ndiv_f(gpll->dvfs.n_int)); nvgpu_udelay(1); gk20a_writel(g, trim_sys_gpcpll_coeff_r(), coeff); } else { coeff = gk20a_readl(g, trim_sys_gpcpll_coeff_r()); coeff = set_field(coeff, trim_sys_gpcpll_coeff_ndiv_m(), trim_sys_gpcpll_coeff_ndiv_f(gpll->N)); nvgpu_udelay(1); gk20a_writel(g, trim_sys_gpcpll_coeff_r(), coeff); } /* dynamic ramp to new ndiv */ data = gk20a_readl(g, trim_sys_gpcpll_ndiv_slowdown_r()); data = set_field(data, trim_sys_gpcpll_ndiv_slowdown_en_dynramp_m(), trim_sys_gpcpll_ndiv_slowdown_en_dynramp_yes_f()); nvgpu_udelay(1); gk20a_writel(g, trim_sys_gpcpll_ndiv_slowdown_r(), data); do { nvgpu_udelay(1); ramp_timeout--; data = gk20a_readl( g, trim_gpc_bcast_gpcpll_ndiv_slowdown_debug_r()); if (trim_gpc_bcast_gpcpll_ndiv_slowdown_debug_pll_dynramp_done_synced_v(data) != 0U) { break; } } while (ramp_timeout > 0); if ((gpll->mode == GPC_PLL_MODE_DVFS) && (ramp_timeout > 0)) { /* in DVFS mode complete SDM update */ coeff = gk20a_readl(g, trim_sys_gpcpll_cfg2_r()); coeff = set_field(coeff, trim_sys_gpcpll_cfg2_sdm_din_m(), trim_sys_gpcpll_cfg2_sdm_din_f(gpll->dvfs.sdm_din)); gk20a_writel(g, trim_sys_gpcpll_cfg2_r(), coeff); } /* exit slowdown mode */ data = gk20a_readl(g, trim_sys_gpcpll_ndiv_slowdown_r()); data = set_field(data, trim_sys_gpcpll_ndiv_slowdown_slowdown_using_pll_m(), trim_sys_gpcpll_ndiv_slowdown_slowdown_using_pll_no_f()); data = set_field(data, trim_sys_gpcpll_ndiv_slowdown_en_dynramp_m(), trim_sys_gpcpll_ndiv_slowdown_en_dynramp_no_f()); gk20a_writel(g, trim_sys_gpcpll_ndiv_slowdown_r(), data); (void) gk20a_readl(g, trim_sys_gpcpll_ndiv_slowdown_r()); if (ramp_timeout <= 0) { nvgpu_err(g, "gpcpll dynamic ramp timeout"); return -ETIMEDOUT; } return 0; } /* GPCPLL bypass methods */ static void clk_change_pldiv_under_bypass(struct gk20a *g, struct pll *gpll) { u32 data, coeff, throt; /* put PLL in bypass before programming it */ throt = g->ops.therm.throttle_disable(g); data = gk20a_readl(g, trim_sys_sel_vco_r()); data = set_field(data, trim_sys_sel_vco_gpc2clk_out_m(), trim_sys_sel_vco_gpc2clk_out_bypass_f()); gk20a_writel(g, trim_sys_sel_vco_r(), data); g->ops.therm.throttle_enable(g, throt); /* change PLDIV */ coeff = gk20a_readl(g, trim_sys_gpcpll_coeff_r()); nvgpu_udelay(1); coeff = set_field(coeff, trim_sys_gpcpll_coeff_pldiv_m(), trim_sys_gpcpll_coeff_pldiv_f(gpll->PL)); gk20a_writel(g, trim_sys_gpcpll_coeff_r(), coeff); /* put PLL back on vco */ throt = g->ops.therm.throttle_disable(g); data = gk20a_readl(g, trim_sys_sel_vco_r()); nvgpu_udelay(1); data = set_field(data, trim_sys_sel_vco_gpc2clk_out_m(), trim_sys_sel_vco_gpc2clk_out_vco_f()); gk20a_writel(g, trim_sys_sel_vco_r(), data); g->ops.therm.throttle_enable(g, throt); } static void clk_lock_gpc_pll_under_bypass(struct gk20a *g, struct pll *gpll) { u32 data, cfg, coeff, timeout, throt; /* put PLL in bypass before programming it */ throt = g->ops.therm.throttle_disable(g); data = gk20a_readl(g, trim_sys_sel_vco_r()); data = set_field(data, trim_sys_sel_vco_gpc2clk_out_m(), trim_sys_sel_vco_gpc2clk_out_bypass_f()); gk20a_writel(g, trim_sys_sel_vco_r(), data); g->ops.therm.throttle_enable(g, throt); cfg = gk20a_readl(g, trim_sys_gpcpll_cfg_r()); nvgpu_udelay(1); if (trim_sys_gpcpll_cfg_iddq_v(cfg) != 0U) { /* get out from IDDQ (1st power up) */ cfg = set_field(cfg, trim_sys_gpcpll_cfg_iddq_m(), trim_sys_gpcpll_cfg_iddq_power_on_v()); gk20a_writel(g, trim_sys_gpcpll_cfg_r(), cfg); (void) gk20a_readl(g, trim_sys_gpcpll_cfg_r()); nvgpu_udelay(gpc_pll_params.iddq_exit_delay); } else { /* clear SYNC_MODE before disabling PLL */ cfg = set_field(cfg, trim_sys_gpcpll_cfg_sync_mode_m(), trim_sys_gpcpll_cfg_sync_mode_disable_f()); gk20a_writel(g, trim_sys_gpcpll_cfg_r(), cfg); (void) gk20a_readl(g, trim_sys_gpcpll_cfg_r()); /* disable running PLL before changing coefficients */ cfg = set_field(cfg, trim_sys_gpcpll_cfg_enable_m(), trim_sys_gpcpll_cfg_enable_no_f()); gk20a_writel(g, trim_sys_gpcpll_cfg_r(), cfg); (void) gk20a_readl(g, trim_sys_gpcpll_cfg_r()); } /* change coefficients */ if (gpll->mode == GPC_PLL_MODE_DVFS) { clk_setup_dvfs_detection(g, gpll); coeff = gk20a_readl(g, trim_sys_gpcpll_cfg2_r()); coeff = set_field(coeff, trim_sys_gpcpll_cfg2_sdm_din_m(), trim_sys_gpcpll_cfg2_sdm_din_f(gpll->dvfs.sdm_din)); gk20a_writel(g, trim_sys_gpcpll_cfg2_r(), coeff); coeff = trim_sys_gpcpll_coeff_mdiv_f(gpll->M) | trim_sys_gpcpll_coeff_ndiv_f(gpll->dvfs.n_int) | trim_sys_gpcpll_coeff_pldiv_f(gpll->PL); gk20a_writel(g, trim_sys_gpcpll_coeff_r(), coeff); } else { coeff = trim_sys_gpcpll_coeff_mdiv_f(gpll->M) | trim_sys_gpcpll_coeff_ndiv_f(gpll->N) | trim_sys_gpcpll_coeff_pldiv_f(gpll->PL); gk20a_writel(g, trim_sys_gpcpll_coeff_r(), coeff); } /* enable PLL after changing coefficients */ cfg = gk20a_readl(g, trim_sys_gpcpll_cfg_r()); cfg = set_field(cfg, trim_sys_gpcpll_cfg_enable_m(), trim_sys_gpcpll_cfg_enable_yes_f()); gk20a_writel(g, trim_sys_gpcpll_cfg_r(), cfg); /* just delay in DVFS mode (lock cannot be used) */ if (gpll->mode == GPC_PLL_MODE_DVFS) { (void) gk20a_readl(g, trim_sys_gpcpll_cfg_r()); nvgpu_udelay(gpc_pll_params.na_lock_delay); gk20a_dbg_clk(g, "NA config_pll under bypass: %u (%u) kHz %d mV", gpll->freq, gpll->freq / 2U, ((int)trim_sys_gpcpll_cfg3_dfs_testout_v( gk20a_readl(g, trim_sys_gpcpll_cfg3_r())) * gpc_pll_params.uvdet_slope + gpc_pll_params.uvdet_offs) / 1000); goto pll_locked; } /* lock pll */ cfg = gk20a_readl(g, trim_sys_gpcpll_cfg_r()); if ((cfg & trim_sys_gpcpll_cfg_enb_lckdet_power_off_f()) != 0U) { cfg = set_field(cfg, trim_sys_gpcpll_cfg_enb_lckdet_m(), trim_sys_gpcpll_cfg_enb_lckdet_power_on_f()); gk20a_writel(g, trim_sys_gpcpll_cfg_r(), cfg); cfg = gk20a_readl(g, trim_sys_gpcpll_cfg_r()); } /* wait pll lock */ timeout = gpc_pll_params.lock_timeout + 1U; do { nvgpu_udelay(1); cfg = gk20a_readl(g, trim_sys_gpcpll_cfg_r()); if ((cfg & trim_sys_gpcpll_cfg_pll_lock_true_f()) != 0U) { goto pll_locked; } timeout--; } while (timeout > 0U); /* PLL is messed up. What can we do here? */ dump_gpc_pll(g, gpll, cfg); BUG(); pll_locked: gk20a_dbg_clk(g, "locked config_pll under bypass r=0x%x v=0x%x", trim_sys_gpcpll_cfg_r(), cfg); /* set SYNC_MODE for glitchless switch out of bypass */ cfg = set_field(cfg, trim_sys_gpcpll_cfg_sync_mode_m(), trim_sys_gpcpll_cfg_sync_mode_enable_f()); gk20a_writel(g, trim_sys_gpcpll_cfg_r(), cfg); (void) gk20a_readl(g, trim_sys_gpcpll_cfg_r()); /* put PLL back on vco */ throt = g->ops.therm.throttle_disable(g); data = gk20a_readl(g, trim_sys_sel_vco_r()); data = set_field(data, trim_sys_sel_vco_gpc2clk_out_m(), trim_sys_sel_vco_gpc2clk_out_vco_f()); gk20a_writel(g, trim_sys_sel_vco_r(), data); g->ops.therm.throttle_enable(g, throt); } /* * Change GPCPLL frequency: * - in legacy (non-DVFS) mode * - in DVFS mode at constant DVFS detection settings, matching current/lower * voltage; the same procedure can be used in this case, since maximum DVFS * detection limit makes sure that PLL output remains under F/V curve when * voltage increases arbitrary. */ static int clk_program_gpc_pll(struct gk20a *g, struct pll *gpll_new, bool allow_slide) { u32 cfg, coeff, data; bool can_slide, pldiv_only; struct pll gpll; nvgpu_log_fn(g, " "); if (!nvgpu_platform_is_silicon(g)) { return 0; } /* get old coefficients */ coeff = gk20a_readl(g, trim_sys_gpcpll_coeff_r()); gpll.M = trim_sys_gpcpll_coeff_mdiv_v(coeff); gpll.N = trim_sys_gpcpll_coeff_ndiv_v(coeff); gpll.PL = trim_sys_gpcpll_coeff_pldiv_v(coeff); gpll.clk_in = gpll_new->clk_in; /* combine target dvfs with old coefficients */ gpll.dvfs = gpll_new->dvfs; gpll.mode = gpll_new->mode; /* do NDIV slide if there is no change in M and PL */ cfg = gk20a_readl(g, trim_sys_gpcpll_cfg_r()); can_slide = allow_slide && (trim_sys_gpcpll_cfg_enable_v(cfg) != 0U); if (can_slide && (gpll_new->M == gpll.M) && (gpll_new->PL == gpll.PL)) { return clk_slide_gpc_pll(g, gpll_new); } /* slide down to NDIV_LO */ if (can_slide) { int ret; gpll.N = DIV_ROUND_UP(gpll.M * gpc_pll_params.min_vco, gpll.clk_in); if (gpll.mode == GPC_PLL_MODE_DVFS) { clk_config_dvfs_ndiv(gpll.dvfs.mv, gpll.N, &gpll.dvfs); } ret = clk_slide_gpc_pll(g, &gpll); if (ret != 0) { return ret; } } pldiv_only = can_slide && (gpll_new->M == gpll.M); /* * Split FO-to-bypass jump in halfs by setting out divider 1:2. * (needed even if PLDIV_GLITCHLESS is set, since 1:1 <=> 1:2 direct * transition is not really glitch-less - see get_interim_pldiv * function header). */ if ((gpll_new->PL < 2U) || (gpll.PL < 2U)) { data = gk20a_readl(g, trim_sys_gpc2clk_out_r()); data = set_field(data, trim_sys_gpc2clk_out_vcodiv_m(), trim_sys_gpc2clk_out_vcodiv_f(2)); gk20a_writel(g, trim_sys_gpc2clk_out_r(), data); /* Intentional 2nd write to assure linear divider operation */ gk20a_writel(g, trim_sys_gpc2clk_out_r(), data); (void) gk20a_readl(g, trim_sys_gpc2clk_out_r()); nvgpu_udelay(2); } #if PLDIV_GLITCHLESS coeff = gk20a_readl(g, trim_sys_gpcpll_coeff_r()); if (pldiv_only) { /* Insert interim PLDIV state if necessary */ u32 interim_pl = get_interim_pldiv(g, gpll_new->PL, gpll.PL); if (interim_pl != 0U) { coeff = set_field(coeff, trim_sys_gpcpll_coeff_pldiv_m(), trim_sys_gpcpll_coeff_pldiv_f(interim_pl)); gk20a_writel(g, trim_sys_gpcpll_coeff_r(), coeff); coeff = gk20a_readl(g, trim_sys_gpcpll_coeff_r()); } goto set_pldiv; /* path A: no need to bypass */ } /* path B: bypass if either M changes or PLL is disabled */ #endif /* * Program and lock pll under bypass. On exit PLL is out of bypass, * enabled, and locked. VCO is at vco_min if sliding is allowed. * Otherwise it is at VCO target (and therefore last slide call below * is effectively NOP). PL is set to target. Output divider is engaged * at 1:2 if either entry, or exit PL setting is 1:1. */ gpll = *gpll_new; if (allow_slide) { gpll.N = DIV_ROUND_UP(gpll_new->M * gpc_pll_params.min_vco, gpll_new->clk_in); if (gpll.mode == GPC_PLL_MODE_DVFS) { clk_config_dvfs_ndiv(gpll.dvfs.mv, gpll.N, &gpll.dvfs); } } if (pldiv_only) { clk_change_pldiv_under_bypass(g, &gpll); } else { clk_lock_gpc_pll_under_bypass(g, &gpll); } #if PLDIV_GLITCHLESS coeff = gk20a_readl(g, trim_sys_gpcpll_coeff_r()); set_pldiv: /* coeff must be current from either path A or B */ if (trim_sys_gpcpll_coeff_pldiv_v(coeff) != gpll_new->PL) { coeff = set_field(coeff, trim_sys_gpcpll_coeff_pldiv_m(), trim_sys_gpcpll_coeff_pldiv_f(gpll_new->PL)); gk20a_writel(g, trim_sys_gpcpll_coeff_r(), coeff); } #endif /* restore out divider 1:1 */ data = gk20a_readl(g, trim_sys_gpc2clk_out_r()); if ((data & trim_sys_gpc2clk_out_vcodiv_m()) != trim_sys_gpc2clk_out_vcodiv_by1_f()) { data = set_field(data, trim_sys_gpc2clk_out_vcodiv_m(), trim_sys_gpc2clk_out_vcodiv_by1_f()); nvgpu_udelay(2); gk20a_writel(g, trim_sys_gpc2clk_out_r(), data); /* Intentional 2nd write to assure linear divider operation */ gk20a_writel(g, trim_sys_gpc2clk_out_r(), data); (void) gk20a_readl(g, trim_sys_gpc2clk_out_r()); } /* slide up to target NDIV */ return clk_slide_gpc_pll(g, gpll_new); } /* Find GPCPLL config safe at DVFS coefficient = 0, matching target frequency */ static void clk_config_pll_safe_dvfs(struct gk20a *g, struct pll *gpll) { u32 nsafe, nmin; if (gpll->freq > g->clk.dvfs_safe_max_freq) { gpll->freq = gpll->freq * (100U - DVFS_SAFE_MARGIN) / 100U; } nmin = DIV_ROUND_UP(gpll->M * gpc_pll_params.min_vco, gpll->clk_in); nsafe = gpll->M * gpll->freq / gpll->clk_in; /* * If safe frequency is above VCOmin, it can be used in safe PLL config * as is. Since safe frequency is below both old and new frequencies, * in this case all three configurations have same post divider 1:1, and * direct old=>safe=>new n-sliding will be used for transitions. * * Otherwise, if safe frequency is below VCO min, post-divider in safe * configuration (and possibly in old and/or new configurations) is * above 1:1, and each old=>safe and safe=>new transitions includes * sliding to/from VCOmin, as well as divider changes. To avoid extra * dynamic ramps from VCOmin during old=>safe transition and to VCOmin * during safe=>new transition, select nmin as safe NDIV, and set safe * post divider to assure PLL output is below safe frequency */ if (nsafe < nmin) { gpll->PL = DIV_ROUND_UP(nmin * gpll->clk_in, gpll->M * gpll->freq); nsafe = nmin; } gpll->N = nsafe; clk_config_dvfs_ndiv(gpll->dvfs.mv, gpll->N, &gpll->dvfs); gk20a_dbg_clk(g, "safe freq %d kHz, M %d, N %d, PL %d(div%d), mV(cal) %d(%d), DC %d", gpll->freq, gpll->M, gpll->N, gpll->PL, nvgpu_pl_to_div(gpll->PL), gpll->dvfs.mv, gpll->dvfs.uv_cal / 1000, gpll->dvfs.dfs_coeff); } /* Change GPCPLL frequency and DVFS detection settings in DVFS mode */ static int clk_program_na_gpc_pll(struct gk20a *g, struct pll *gpll_new, bool allow_slide) { int ret; struct pll gpll_safe; struct pll *gpll_old = &g->clk.gpc_pll_last; BUG_ON(gpll_new->M != 1U); /* the only MDIV in NA mode */ ret = clk_config_dvfs(g, gpll_new); if (ret < 0) { return ret; } /* * In cases below no intermediate steps in PLL DVFS configuration are * necessary because either * - PLL DVFS will be configured under bypass directly to target, or * - voltage is not changing, so DVFS detection settings are the same */ if (!allow_slide || !gpll_new->enabled || (gpll_old->dvfs.mv == gpll_new->dvfs.mv)) { return clk_program_gpc_pll(g, gpll_new, allow_slide); } /* * Interim step for changing DVFS detection settings: low enough * frequency to be safe at at DVFS coeff = 0. * * 1. If voltage is increasing: * - safe frequency target matches the lowest - old - frequency * - DVFS settings are still old * - Voltage already increased to new level by tegra DVFS, but maximum * detection limit assures PLL output remains under F/V curve * * 2. If voltage is decreasing: * - safe frequency target matches the lowest - new - frequency * - DVFS settings are still old * - Voltage is also old, it will be lowered by tegra DVFS afterwards * * Interim step can be skipped if old frequency is below safe minimum, * i.e., it is low enough to be safe at any voltage in operating range * with zero DVFS coefficient. */ if (gpll_old->freq > g->clk.dvfs_safe_max_freq) { if (gpll_old->dvfs.mv < gpll_new->dvfs.mv) { gpll_safe = *gpll_old; gpll_safe.dvfs.mv = gpll_new->dvfs.mv; } else { gpll_safe = *gpll_new; gpll_safe.dvfs = gpll_old->dvfs; } clk_config_pll_safe_dvfs(g, &gpll_safe); ret = clk_program_gpc_pll(g, &gpll_safe, true); if (ret != 0) { nvgpu_err(g, "Safe dvfs program fail"); return ret; } } /* * DVFS detection settings transition: * - Set DVFS coefficient zero (safe, since already at frequency safe * at DVFS coeff = 0 for the lowest of the old/new end-points) * - Set calibration level to new voltage (safe, since DVFS coeff = 0) * - Set DVFS coefficient to match new voltage (safe, since already at * frequency safe at DVFS coeff = 0 for the lowest of the old/new * end-points. */ clk_set_dfs_coeff(g, 0); clk_set_dfs_ext_cal(g, (u32)gpll_new->dvfs.dfs_ext_cal); clk_set_dfs_coeff(g, (u32)gpll_new->dvfs.dfs_coeff); gk20a_dbg_clk(g, "config_pll %d kHz, M %d, N %d, PL %d(div%d), mV(cal) %d(%d), DC %d", gpll_new->freq, gpll_new->M, gpll_new->N, gpll_new->PL, nvgpu_pl_to_div(gpll_new->PL), max(gpll_new->dvfs.mv, gpll_old->dvfs.mv), gpll_new->dvfs.uv_cal / 1000, gpll_new->dvfs.dfs_coeff); /* Finally set target rate (with DVFS detection settings already new) */ return clk_program_gpc_pll(g, gpll_new, true); } static void clk_disable_gpcpll(struct gk20a *g, bool allow_slide) { u32 cfg, coeff, throt; struct clk_gk20a *clk = &g->clk; struct pll gpll = clk->gpc_pll; int err = 0; /* slide to VCO min */ cfg = gk20a_readl(g, trim_sys_gpcpll_cfg_r()); if (allow_slide && (trim_sys_gpcpll_cfg_enable_v(cfg) != 0U)) { coeff = gk20a_readl(g, trim_sys_gpcpll_coeff_r()); gpll.M = trim_sys_gpcpll_coeff_mdiv_v(coeff); gpll.N = DIV_ROUND_UP(gpll.M * gpc_pll_params.min_vco, gpll.clk_in); if (gpll.mode == GPC_PLL_MODE_DVFS) { clk_config_dvfs_ndiv(gpll.dvfs.mv, gpll.N, &gpll.dvfs); } err = clk_slide_gpc_pll(g, &gpll); if (err != 0) { nvgpu_err(g, "slide_gpc failed, err=%d", err); } } /* put PLL in bypass before disabling it */ throt = g->ops.therm.throttle_disable(g); cfg = gk20a_readl(g, trim_sys_sel_vco_r()); cfg = set_field(cfg, trim_sys_sel_vco_gpc2clk_out_m(), trim_sys_sel_vco_gpc2clk_out_bypass_f()); gk20a_writel(g, trim_sys_sel_vco_r(), cfg); g->ops.therm.throttle_enable(g, throt); /* clear SYNC_MODE before disabling PLL */ cfg = gk20a_readl(g, trim_sys_gpcpll_cfg_r()); cfg = set_field(cfg, trim_sys_gpcpll_cfg_sync_mode_m(), trim_sys_gpcpll_cfg_sync_mode_disable_f()); gk20a_writel(g, trim_sys_gpcpll_cfg_r(), cfg); /* disable PLL */ cfg = gk20a_readl(g, trim_sys_gpcpll_cfg_r()); cfg = set_field(cfg, trim_sys_gpcpll_cfg_enable_m(), trim_sys_gpcpll_cfg_enable_no_f()); gk20a_writel(g, trim_sys_gpcpll_cfg_r(), cfg); (void) gk20a_readl(g, trim_sys_gpcpll_cfg_r()); clk->gpc_pll.enabled = false; clk->gpc_pll_last.enabled = false; } struct pll_parms *gm20b_get_gpc_pll_parms(void) { return &gpc_pll_params; } #ifdef CONFIG_TEGRA_USE_NA_GPCPLL static int nvgpu_fuse_can_use_na_gpcpll(struct gk20a *g, int *id) { return nvgpu_tegra_get_gpu_speedo_id(g, id); } static int nvgpu_clk_set_na_gpcpll(struct gk20a *g) { struct clk_gk20a *clk = &g->clk; int speedo_id; int err; err = nvgpu_fuse_can_use_na_gpcpll(g, &speedo_id); if (err == 0) { /* NA mode is supported only at max update rate 38.4 MHz */ if (speedo_id) { WARN_ON(clk->gpc_pll.clk_in != gpc_pll_params.max_u); clk->gpc_pll.mode = GPC_PLL_MODE_DVFS; gpc_pll_params.min_u = gpc_pll_params.max_u; } } return err; } #endif int gm20b_init_clk_setup_sw(struct gk20a *g) { struct clk_gk20a *clk = &g->clk; unsigned long safe_rate; int err = 0; nvgpu_log_fn(g, " "); nvgpu_mutex_init(&clk->clk_mutex); if (clk->sw_ready) { nvgpu_log_fn(g, "skip init"); return 0; } if (clk->gpc_pll.id == GM20B_GPC_PLL_C1) { gpc_pll_params = gpc_pll_params_c1; if (clk->pll_poweron_uv == 0) { clk->pll_poweron_uv = BOOT_GPU_UV_C1; } } else { gpc_pll_params = gpc_pll_params_b1; if (clk->pll_poweron_uv == 0) { clk->pll_poweron_uv = BOOT_GPU_UV_B1; } } clk->gpc_pll.clk_in = g->ops.clk.get_ref_clock_rate(g) / KHZ; if (clk->gpc_pll.clk_in == 0U) { nvgpu_err(g, "GPCPLL reference clock is zero"); err = -EINVAL; goto fail; } safe_rate = g->ops.clk.get_fmax_at_vmin_safe(g); safe_rate = safe_rate * (100UL - (unsigned long)DVFS_SAFE_MARGIN) / 100UL; clk->dvfs_safe_max_freq = rate_gpu_to_gpc2clk(safe_rate); clk->gpc_pll.PL = (clk->dvfs_safe_max_freq == 0UL) ? 0U : DIV_ROUND_UP(gpc_pll_params.min_vco, clk->dvfs_safe_max_freq); /* Initial freq: low enough to be safe at Vmin (default 1/3 VCO min) */ clk->gpc_pll.M = 1; clk->gpc_pll.N = DIV_ROUND_UP(gpc_pll_params.min_vco, clk->gpc_pll.clk_in); clk->gpc_pll.PL = max(clk->gpc_pll.PL, 3U); clk->gpc_pll.freq = clk->gpc_pll.clk_in * clk->gpc_pll.N; clk->gpc_pll.freq /= nvgpu_pl_to_div(clk->gpc_pll.PL); /* * All production parts should have ADC fuses burnt. Therefore, check * ADC fuses always, regardless of whether NA mode is selected; and if * NA mode is indeed selected, and part can support it, switch to NA * mode even when ADC calibration is not fused; less accurate s/w * self-calibration will be used for those parts. */ clk_config_calibration_params(g); #ifdef CONFIG_TEGRA_USE_NA_GPCPLL err = nvgpu_clk_set_na_gpcpll(g); if (err != 0) { nvgpu_err(g, "NA GPCPLL fuse info. not available"); goto fail; } #endif clk->sw_ready = true; nvgpu_log_fn(g, "done"); nvgpu_info(g, "GPCPLL initial settings:%s M=%u, N=%u, P=%u (id = %u)", clk->gpc_pll.mode == GPC_PLL_MODE_DVFS ? " NA mode," : "", clk->gpc_pll.M, clk->gpc_pll.N, clk->gpc_pll.PL, clk->gpc_pll.id); return 0; fail: nvgpu_mutex_destroy(&clk->clk_mutex); return err; } static int set_pll_freq(struct gk20a *g, bool allow_slide); static int set_pll_target(struct gk20a *g, u32 freq, u32 old_freq); int gm20b_clk_prepare(struct clk_gk20a *clk) { int ret = 0; nvgpu_mutex_acquire(&clk->clk_mutex); if (!clk->gpc_pll.enabled && clk->clk_hw_on) { ret = set_pll_freq(clk->g, true); } nvgpu_mutex_release(&clk->clk_mutex); return ret; } void gm20b_clk_unprepare(struct clk_gk20a *clk) { nvgpu_mutex_acquire(&clk->clk_mutex); if (clk->gpc_pll.enabled && clk->clk_hw_on) { clk_disable_gpcpll(clk->g, true); } nvgpu_mutex_release(&clk->clk_mutex); } int gm20b_clk_is_prepared(struct clk_gk20a *clk) { return clk->gpc_pll.enabled && clk->clk_hw_on; } unsigned long gm20b_recalc_rate(struct clk_gk20a *clk, unsigned long parent_rate) { (void)parent_rate; return rate_gpc2clk_to_gpu(clk->gpc_pll.freq); } int gm20b_gpcclk_set_rate(struct clk_gk20a *clk, unsigned long rate, unsigned long parent_rate) { u32 old_freq; int ret = -ENODATA; (void)parent_rate; nvgpu_mutex_acquire(&clk->clk_mutex); old_freq = clk->gpc_pll.freq; ret = set_pll_target(clk->g, (u32)rate_gpu_to_gpc2clk(rate), old_freq); if ((ret == 0) && clk->gpc_pll.enabled && clk->clk_hw_on) { ret = set_pll_freq(clk->g, true); } nvgpu_mutex_release(&clk->clk_mutex); return ret; } long gm20b_round_rate(struct clk_gk20a *clk, unsigned long rate, unsigned long *parent_rate) { u32 freq; struct pll tmp_pll; unsigned long maxrate; struct gk20a *g = clk->g; (void)parent_rate; maxrate = g->ops.clk.get_maxrate(g, CTRL_CLK_DOMAIN_GPCCLK); if (rate > maxrate) { rate = maxrate; } nvgpu_mutex_acquire(&clk->clk_mutex); freq = (u32)rate_gpu_to_gpc2clk(rate); if (freq > gpc_pll_params.max_freq) { freq = gpc_pll_params.max_freq; } else if (freq < gpc_pll_params.min_freq) { freq = gpc_pll_params.min_freq; } else { nvgpu_log_info(g, "frequency within range"); } tmp_pll = clk->gpc_pll; clk_config_pll(clk, &tmp_pll, &gpc_pll_params, &freq, true); nvgpu_mutex_release(&clk->clk_mutex); return (long)rate_gpc2clk_to_gpu(tmp_pll.freq); } static int gm20b_init_clk_setup_hw(struct gk20a *g) { u32 data; nvgpu_log_fn(g, " "); /* LDIV: Div4 mode (required); both bypass and vco ratios 1:1 */ data = gk20a_readl(g, trim_sys_gpc2clk_out_r()); data = set_field(data, trim_sys_gpc2clk_out_sdiv14_m() | trim_sys_gpc2clk_out_vcodiv_m() | trim_sys_gpc2clk_out_bypdiv_m(), trim_sys_gpc2clk_out_sdiv14_indiv4_mode_f() | trim_sys_gpc2clk_out_vcodiv_by1_f() | trim_sys_gpc2clk_out_bypdiv_f(0)); gk20a_writel(g, trim_sys_gpc2clk_out_r(), data); /* * Clear global bypass control; PLL is still under bypass, since SEL_VCO * is cleared by default. */ data = gk20a_readl(g, trim_sys_bypassctrl_r()); data = set_field(data, trim_sys_bypassctrl_gpcpll_m(), trim_sys_bypassctrl_gpcpll_vco_f()); gk20a_writel(g, trim_sys_bypassctrl_r(), data); /* If not fused, set RAM SVOP PDP data 0x2, and enable fuse override */ data = gk20a_readl(g, fuse_ctrl_opt_ram_svop_pdp_r()); if (fuse_ctrl_opt_ram_svop_pdp_data_v(data) == 0U) { data = set_field(data, fuse_ctrl_opt_ram_svop_pdp_data_m(), fuse_ctrl_opt_ram_svop_pdp_data_f(0x2)); gk20a_writel(g, fuse_ctrl_opt_ram_svop_pdp_r(), data); data = gk20a_readl(g, fuse_ctrl_opt_ram_svop_pdp_override_r()); data = set_field(data, fuse_ctrl_opt_ram_svop_pdp_override_data_m(), fuse_ctrl_opt_ram_svop_pdp_override_data_yes_f()); gk20a_writel(g, fuse_ctrl_opt_ram_svop_pdp_override_r(), data); } /* Disable idle slow down */ data = g->ops.therm.idle_slowdown_disable(g); if (g->clk.gpc_pll.mode == GPC_PLL_MODE_DVFS) { return clk_enbale_pll_dvfs(g); } return 0; } static int set_pll_target(struct gk20a *g, u32 freq, u32 old_freq) { struct clk_gk20a *clk = &g->clk; if (freq > gpc_pll_params.max_freq) { freq = gpc_pll_params.max_freq; } else if (freq < gpc_pll_params.min_freq) { freq = gpc_pll_params.min_freq; } else { nvgpu_log_info(g, "frequency within range"); } if (freq != old_freq) { /* gpc_pll.freq is changed to new value here */ clk_config_pll(clk, &clk->gpc_pll, &gpc_pll_params, &freq, true); } return 0; } static int set_pll_freq(struct gk20a *g, bool allow_slide) { struct clk_gk20a *clk = &g->clk; int err = 0; nvgpu_log_fn(g, "last freq: %dMHz, target freq %dMHz", clk->gpc_pll_last.freq, clk->gpc_pll.freq); /* If programming with dynamic sliding failed, re-try under bypass */ if (clk->gpc_pll.mode == GPC_PLL_MODE_DVFS) { err = clk_program_na_gpc_pll(g, &clk->gpc_pll, allow_slide); if ((err != 0) && allow_slide) { err = clk_program_na_gpc_pll(g, &clk->gpc_pll, false); } } else { err = clk_program_gpc_pll(g, &clk->gpc_pll, allow_slide); if ((err != 0) && allow_slide) { err = clk_program_gpc_pll(g, &clk->gpc_pll, false); } } if (err == 0) { clk->gpc_pll.enabled = true; clk->gpc_pll_last = clk->gpc_pll; return 0; } /* * Just report error but not restore PLL since dvfs could already change * voltage even when programming failed. */ nvgpu_err(g, "failed to set pll to %d", clk->gpc_pll.freq); return err; } int gm20b_init_clk_support(struct gk20a *g) { struct clk_gk20a *clk = &g->clk; int err; nvgpu_log_fn(g, " "); nvgpu_mutex_acquire(&clk->clk_mutex); clk->clk_hw_on = true; err = gm20b_init_clk_setup_hw(g); nvgpu_mutex_release(&clk->clk_mutex); if (err != 0) { return err; } /* FIXME: this effectively prevents host level clock gating */ err = g->ops.clk.prepare_enable(&g->clk); if (err != 0) { return err; } /* The prev call may not enable PLL if gbus is unbalanced - force it */ nvgpu_mutex_acquire(&clk->clk_mutex); if (!clk->gpc_pll.enabled) { err = set_pll_freq(g, true); } nvgpu_mutex_release(&clk->clk_mutex); return err; } void gm20b_suspend_clk_support(struct gk20a *g) { g->ops.clk.disable_unprepare(&g->clk); /* The prev call may not disable PLL if gbus is unbalanced - force it */ nvgpu_mutex_acquire(&g->clk.clk_mutex); if (g->clk.gpc_pll.enabled) { clk_disable_gpcpll(g, true); } g->clk.clk_hw_on = false; nvgpu_mutex_release(&g->clk.clk_mutex); nvgpu_mutex_destroy(&g->clk.clk_mutex); } int gm20b_clk_get_voltage(struct clk_gk20a *clk, u64 *val) { struct gk20a *g = clk->g; struct pll_parms *gpc_pll_params = gm20b_get_gpc_pll_parms(); u32 det_out; int err; if (clk->gpc_pll.mode != GPC_PLL_MODE_DVFS) { return -ENOSYS; } err = gk20a_busy(g); if (err != 0) { return err; } nvgpu_mutex_acquire(&g->clk.clk_mutex); det_out = gk20a_readl(g, trim_sys_gpcpll_cfg3_r()); det_out = trim_sys_gpcpll_cfg3_dfs_testout_v(det_out); *val = div64_u64((u64)det_out * (u64)gpc_pll_params->uvdet_slope + (u64)gpc_pll_params->uvdet_offs, 1000ULL); nvgpu_mutex_release(&g->clk.clk_mutex); gk20a_idle(g); return 0; } int gm20b_clk_get_gpcclk_clock_counter(struct clk_gk20a *clk, u64 *val) { struct gk20a *g = clk->g; u32 clk_slowdown_save; int err; u32 ncycle = 800; /* count GPCCLK for ncycle of clkin */ u64 freq = clk->gpc_pll.clk_in; u32 count1, count2; err = gk20a_busy(g); if (err != 0) { return err; } nvgpu_mutex_acquire(&g->clk.clk_mutex); /* Disable clock slowdown during measurements */ clk_slowdown_save = g->ops.therm.idle_slowdown_disable(g); gk20a_writel(g, trim_gpc_clk_cntr_ncgpcclk_cfg_r(0), trim_gpc_clk_cntr_ncgpcclk_cfg_reset_asserted_f()); gk20a_writel(g, trim_gpc_clk_cntr_ncgpcclk_cfg_r(0), trim_gpc_clk_cntr_ncgpcclk_cfg_enable_asserted_f() | trim_gpc_clk_cntr_ncgpcclk_cfg_write_en_asserted_f() | trim_gpc_clk_cntr_ncgpcclk_cfg_noofipclks_f(ncycle)); /* start */ /* It should take less than 25us to finish 800 cycle of 38.4MHz. * But longer than 100us delay is required here. */ (void) gk20a_readl(g, trim_gpc_clk_cntr_ncgpcclk_cfg_r(0)); nvgpu_udelay(200); count1 = gk20a_readl(g, trim_gpc_clk_cntr_ncgpcclk_cnt_r(0)); nvgpu_udelay(100); count2 = gk20a_readl(g, trim_gpc_clk_cntr_ncgpcclk_cnt_r(0)); freq *= trim_gpc_clk_cntr_ncgpcclk_cnt_value_v(count2); do_div(freq, ncycle); *val = freq; /* Restore clock slowdown */ g->ops.therm.idle_slowdown_enable(g, clk_slowdown_save); nvgpu_mutex_release(&g->clk.clk_mutex); gk20a_idle(g); if (count1 != count2) { return -EBUSY; } return 0; } int gm20b_clk_pll_reg_write(struct gk20a *g, u32 reg, u32 val) { if (((reg < trim_sys_gpcpll_cfg_r()) || (reg > trim_sys_gpcpll_dvfs2_r())) && (reg != trim_sys_sel_vco_r()) && (reg != trim_sys_gpc2clk_out_r()) && (reg != trim_sys_bypassctrl_r())) { return -EPERM; } if (reg == trim_sys_gpcpll_dvfs2_r()) { reg = trim_gpc_bcast_gpcpll_dvfs2_r(); } nvgpu_mutex_acquire(&g->clk.clk_mutex); if (!g->clk.clk_hw_on) { nvgpu_mutex_release(&g->clk.clk_mutex); return -EINVAL; } gk20a_writel(g, reg, val); nvgpu_mutex_release(&g->clk.clk_mutex); return 0; } int gm20b_clk_get_pll_debug_data(struct gk20a *g, struct nvgpu_clk_pll_debug_data *d) { u32 reg; nvgpu_mutex_acquire(&g->clk.clk_mutex); if (!g->clk.clk_hw_on) { nvgpu_mutex_release(&g->clk.clk_mutex); return -EINVAL; } d->trim_sys_bypassctrl_reg = trim_sys_bypassctrl_r(); d->trim_sys_bypassctrl_val = gk20a_readl(g, trim_sys_bypassctrl_r()); d->trim_sys_sel_vco_reg = trim_sys_sel_vco_r(); d->trim_sys_sel_vco_val = gk20a_readl(g, trim_sys_sel_vco_r()); d->trim_sys_gpc2clk_out_reg = trim_sys_gpc2clk_out_r(); d->trim_sys_gpc2clk_out_val = gk20a_readl(g, trim_sys_gpc2clk_out_r()); d->trim_sys_gpcpll_cfg_reg = trim_sys_gpcpll_cfg_r(); d->trim_sys_gpcpll_dvfs2_reg = trim_sys_gpcpll_dvfs2_r(); d->trim_bcast_gpcpll_dvfs2_reg = trim_gpc_bcast_gpcpll_dvfs2_r(); reg = gk20a_readl(g, trim_sys_gpcpll_cfg_r()); d->trim_sys_gpcpll_cfg_val = reg; d->trim_sys_gpcpll_cfg_enabled = trim_sys_gpcpll_cfg_enable_v(reg); d->trim_sys_gpcpll_cfg_locked = trim_sys_gpcpll_cfg_pll_lock_v(reg); d->trim_sys_gpcpll_cfg_sync_on = trim_sys_gpcpll_cfg_sync_mode_v(reg); reg = gk20a_readl(g, trim_sys_gpcpll_coeff_r()); d->trim_sys_gpcpll_coeff_val = reg; d->trim_sys_gpcpll_coeff_mdiv = trim_sys_gpcpll_coeff_mdiv_v(reg); d->trim_sys_gpcpll_coeff_ndiv = trim_sys_gpcpll_coeff_ndiv_v(reg); d->trim_sys_gpcpll_coeff_pldiv = trim_sys_gpcpll_coeff_pldiv_v(reg); reg = gk20a_readl(g, trim_sys_gpcpll_dvfs0_r()); d->trim_sys_gpcpll_dvfs0_val = reg; d->trim_sys_gpcpll_dvfs0_dfs_coeff = trim_sys_gpcpll_dvfs0_dfs_coeff_v(reg); d->trim_sys_gpcpll_dvfs0_dfs_det_max = trim_sys_gpcpll_dvfs0_dfs_det_max_v(reg); d->trim_sys_gpcpll_dvfs0_dfs_dc_offset = trim_sys_gpcpll_dvfs0_dfs_dc_offset_v(reg); nvgpu_mutex_release(&g->clk.clk_mutex); return 0; }
347390349664de812f9d6eb89919986423f3a8c3
f27557357c998bff0188b1a36ae3a502c06f2db4
/cycle1/exp1p7.c
684f9b3b6349c4af873f6f65e9f3f59f8401e3c9
[]
no_license
adarshpk/CS17L2
012b50892889724cfc8ea0731dcd0a12ae85d049
35a0418d0a6bf847254b877146cd18376598a09b
refs/heads/master
2021-01-11T07:46:21.852792
2016-11-02T18:45:03
2016-11-02T18:45:03
72,669,753
0
0
null
null
null
null
UTF-8
C
false
false
1,036
c
exp1p7.c
// CS 17L2 NETWORKS AND OPERATING SYSTEMS LABORATORY // Cycle 1 : Exp 1 - Program No: (vii): Familiarization of wait() system call // ADARSH P.K. CSU13203 #include <stdio.h> #include <unistd.h> #include <wait.h> int main() { pid_t pid1 = fork(); pid_t pid; if (pid1 > 0) { pid_t pid2 = fork(); if (pid2 > 0) { int status; printf(" Parent : Let the child processes complete.\n"); pid = wait(&status); printf(" Parent : Child process %d has completed.\n", pid); pid = wait(&status); printf(" Parent : Child process %d has completed.\n", pid); printf(" Parent : Hello from the parent process!\n"); } else if (pid2 == 0) { printf(" Hello from the child process 1 (%d)!\n\n",getpid()); } else if (pid2 == -1) { perror("Fork2 failed"); } } else if (pid1 == -1) { perror("Fork1 failed"); } else if (pid1 == 0) { printf(" Hello from the child process 2 (%d)!\n\n",getpid()); } return 0; }
2fa0bc00f51475d8893e3535165247867c7a8615
e91351c56bf7797c7580af312f8c882ed5dfc34f
/array3.c
2b5ffe386a7a39286808faedc108b48d75f34544
[]
no_license
premaluu/C-programming
1f69431a2a3c17b8408e40959665b7fa1ef27975
0ff08696f67c3542fc4f15ca20d7c6b18632d109
refs/heads/master
2021-01-02T05:31:51.028786
2020-02-10T13:02:37
2020-02-10T13:02:37
239,510,803
1
0
null
null
null
null
UTF-8
C
false
false
310
c
array3.c
//input array from user /* created by premal upadhyay */ #include<stdio.h> #include<conio.h> int main() { int a[5],i;; printf("\nEnter the array "); for(i=0;i<5;i++) { scanf("%d",&a[i]); } printf("\nYour array is :- "); for(i=0;i<5;i++) { printf("\n%d",a[i]); } return 0; }
9df4f37b21f51474c7ce92295e245cdc5fb896e4
0c8ecc072e21bddc74516bbfea98fd2db49529ab
/Hand/Source/OLED_SSD1306/Picture_SSD1306.h
35c315d1072dbf97c18f0d05baab83803ccacf1b
[]
no_license
xlz447/ee478final
c44da3b193c302b33bd348b218bf9c2e6a251f12
e7c8c4cfef064af6f2c0df9b76634408a1759fbf
refs/heads/master
2020-03-24T10:30:28.349318
2018-07-28T07:55:34
2018-07-28T07:55:34
142,658,277
0
0
null
null
null
null
UTF-8
C
false
false
474
h
Picture_SSD1306.h
/* This library file is found online from a chinese forum website * the thread can be found here: http://www.eyesourcecode.com/thread-23681-1-1.html * Author is Alen Jeck, and the date is 01/10/2012 */ #if !defined(__PICTURE__SSD1306__H__) #define __PICTURE__SSD1306__H__ //#include <io430.h> //#include <in430.h> #include <intrinsics.h> #include <msp430f2274.h> #include "MyType.h" extern UINT16 const Pic_SSD1306[800]; #endif
e626613c60cd40d4a1f5fc6b438d8d6870a61039
45216c54e06e6c7a895a3672a9ac01010362e67f
/Games/Delay_Timer_Test_Matthew_Mikolay_2010.h
b8bf76050fc58ade653d7b9f5e1501823da79b1c
[ "BSD-3-Clause", "CC-BY-4.0", "MIT", "ISC", "LicenseRef-scancode-unknown-license-reference" ]
permissive
jockm/KeyCadeNano
995608b0966e2f9c02638896ed0e78d5d5c47af3
7eb36582fee0bf0d1b40139f864944106f52a913
refs/heads/master
2021-05-01T21:03:44.500168
2018-02-23T23:27:08
2018-02-23T23:27:08
120,970,254
0
0
null
null
null
null
UTF-8
C
false
false
487
h
Delay_Timer_Test_Matthew_Mikolay_2010.h
const uint8_t Delay_Timer_Test_Matthew_Mikolay_2010_ch8[] = { 0x66, 0x01, 0x22, 0x1e, 0xf4, 0x0a, 0x44, 0x02, 0x73, 0x01, 0x44, 0x08, 0x83, 0x65, 0x34, 0x05, 0x12, 0x02, 0xf3, 0x15, 0xf3, 0x07, 0x22, 0x1e, 0x33, 0x00, 0x12, 0x14, 0x12, 0x02, 0x00, 0xe0, 0x65, 0x00, 0xa2, 0x3a, 0xf3, 0x33, 0xf2, 0x65, 0xf0, 0x29, 0xd5, 0x65, 0xf1, 0x29, 0x65, 0x05, 0xd5, 0x65, 0xf2, 0x29, 0x65, 0x0a, 0xd5, 0x65, 0x00, 0xee }; unsigned int Delay_Timer_Test_Matthew_Mikolay_2010_ch8_len = 58;
e4db1b26d6d8adce1099c8df84850186cc9117a2
a0a8f7ef43b7593c914a2a4e0d4b52b06703a251
/makefileTest/f1/f1.c
b24911831b81e7668fd9cf27e63b6746192426c3
[]
no_license
kkoma-yzy/nobody_supermarket
86868fd1b78b52673067d33f16c72ba7ae4a309e
7e5aa2c72890bb152086af75d69f91dcfc4192d5
refs/heads/master
2020-08-31T12:15:54.040692
2019-10-31T05:22:21
2019-10-31T05:22:21
218,689,447
0
0
null
null
null
null
UTF-8
C
false
false
97
c
f1.c
#include "../include/myinclude.h" void printf1() { printf("Message from f1.c...\h"); return; }
3ec752b147c3acf086df2a15e69ff51fd2c46548
9c9b7591553bd5ffd810a9b36c8347af5661eee7
/HAL.h
8b5d0e74cc5b5987a8a0b38f9f416a6d2633f2b5
[]
no_license
RiksAK/GCC-RTOS_ATMega32
0ef858af9e77f6bb4a7a6a1fa8ae89c3f714fcd7
697df41d60c10003f6167a641db196d3fcca0ab3
refs/heads/master
2020-12-02T16:16:22.684580
2017-07-07T10:42:21
2017-07-07T10:42:21
96,528,277
0
0
null
null
null
null
UTF-8
C
false
false
1,283
h
HAL.h
#ifndef HAL_H #define HAL_H #ifndef F_CPU #define F_CPU 16000000L // 16 MHz clock speed #endif #include <avr/io.h> #include <avr/interrupt.h> #include "avrlibtypes.h" #include "avrlibdefs.h" #include "avrlibtypes.h" #include "avr/pgmspace.h" #include <avr/wdt.h> #include <util/delay.h> //Clock Config //#define F_CPU 16000000L //System Timer Config #define Prescaler 64 #define TimerDivider (F_CPU/Prescaler/1000) // 1 mS //USART Config #define baudrate 9600L #define bauddivider (F_CPU/(16*baudrate)-1) #define HI(x) ((x)>>8) #define LO(x) ((x)& 0xFF) //PORT Defines #define LED1 4 //#define LED2 5 //#define LED3 7 //#define I_C 3 //#define I_L 6 #define LED_PORT PORTC #define LED_DDR DDRC //LCD Defines #define LCD_RS 2 #define LCD_EN 3 #define LCD_D4 4 #define LCD_D5 5 #define LCD_D6 6 #define LCD_D7 7 #define LCD_PORT PORTD #define LCD_DDR DDRD //Keyboard Defines /* #define ROW1 0 #define COL1 1 #define ROW4 2 #define COL3 3 #define ROW3 4 #define ROW2 5 #define COL2 6 */ #define COL2 DDB6 #define ROW1 PINB0 #define COL1 DDB1 #define ROW4 PINB2 #define COL3 DDB3 #define ROW3 PINB4 #define ROW2 PINB5 #define KEYB_PORT PORTB #define KEYB_PIN PINB #define KEYB_DDR DDRB extern void InitAll(void); #endif
848cbdec4ef992c867018c3e097b3b9e4f65bd16
243dd70b2592a7f2e75bc06598f61d400249627d
/user.enryo/lib/io/mutex/test/test_libs_mutex.c
5a7f84487ff80bad70eece6de132b8a0a94325b3
[ "LicenseRef-scancode-warranty-disclaimer" ]
no_license
vmlemon/Orion
4d1445f750c8450f9c5ac1979eb846dbaed178f5
61f894826a802c24076c22c1c9439bc7382a276a
refs/heads/master
2020-07-06T08:20:32.942117
2020-01-25T19:08:09
2020-01-25T19:08:09
202,951,911
6
0
null
2019-10-24T00:37:40
2019-08-18T02:40:09
C
UTF-8
C
false
false
1,931
c
test_libs_mutex.c
#include "test_libs_mutex.h" #include <mutex/mutex.h> #include <l4/thread.h> #include <check.h> START_TEST(test_mutex_basic) { /* Simple create mutex, release */ struct mutex m; mutex_t mtx = &m; mutex_init(mtx); fail_if(mtx->holder != 0, "Mutex has been initialised in locked state"); fail_if(mtx->needed != 0, "Mutex has not been initialised properly"); fail_if(mtx->count != 0, "Mutex has not been initialised properly"); mutex_lock(mtx); fail_if(mtx->holder == 0, "Mutex has not been locked"); fail_if(mtx->holder != L4_Myself().raw, "This thread doesn't hold the mutex"); mutex_unlock(mtx); fail_if(mtx->holder != 0, "Mutex has not been unlocked properly"); fail_if(mtx->needed != 0, "Mutex has not been unlocked properly"); fail_if(mtx->count != 0, "Mutex has not been unlocked properly"); } END_TEST START_TEST(test_mutex_count_lock) { struct mutex m; mutex_t mtx = &m; L4_Word_t me = L4_Myself().raw; mutex_init(mtx); mutex_count_lock(mtx); fail_if(mtx->holder != me, "Mutex is not held by me"); fail_if(mtx->count != 1, "Mutex count is wrong"); mutex_count_lock(mtx); fail_if(mtx->count != 2, "Mutex count is wrong"); mutex_count_lock(mtx); fail_if(mtx->count != 3, "Mutex count is wrong"); mutex_count_unlock(mtx); fail_if(mtx->holder != me, "Mutex is not held by me"); fail_if(mtx->count != 2, "Mutex count is wrong"); mutex_count_unlock(mtx); fail_if(mtx->holder != me, "Mutex is not held by me"); fail_if(mtx->count != 1, "Mutex count is wrong"); mutex_count_unlock(mtx); fail_if(mtx->holder != 0, "Mutex has not been unlocked properly"); fail_if(mtx->count != 0, "Mutex count is wrong"); } END_TEST Suite * make_test_libs_mutex_suite(void) { Suite *suite; TCase *tc; suite = suite_create("mutex tests"); tc = tcase_create("Core"); tcase_add_test(tc, test_mutex_basic); tcase_add_test(tc, test_mutex_count_lock); suite_add_tcase(suite, tc); return suite; }
f059321b8d35bfb7dcaafd3a6c8f919d0c78d503
927c2b11739dccab27a44d5c1c76bbbc38add8f1
/Practice/PTA(实验)/习题4-8 高空坠球/习题4-8 高空坠球/main.c
2813795eccbce76763da7ab53633f070e6dfc119
[]
no_license
civinx/ACM_Code
23034ca3eecb9758c3c00a519f61434a526e89cc
d194ee4e2554a29720ac455e6c6f86b3219724ee
refs/heads/master
2021-09-15T06:18:09.151529
2018-05-27T18:07:25
2018-05-27T18:07:25
105,544,957
1
0
null
null
null
null
UTF-8
C
false
false
495
c
main.c
// // main.c // 习题4-8 高空坠球 // // Created by czf on 15/9/16. // Copyright (c) 2015年 czf. All rights reserved. // #include <stdio.h> #include <math.h> int main(){ double h,n; double s1,s2; int i; scanf("%lf%lf",&h,&n); s1 = h; s2 = 0; for (i = 1; i < n; i ++) { s1 += (h / pow(2, i)) * 2; } s2 = h / pow(2, n); if (n == 0) { s1 = s2 = 0; } printf("%.1lf %.1lf",s1,s2); return 0; }
47d1acee22519668507d31b9a7039beb41999d54
852d9a3e3578712fec43a3a52dc207e924b8d2b3
/OpenMP/gemver.c
b1ceb0869eb5b7118c6a5e72f4a6a7dd40e83233
[]
no_license
Aleksyav/C-MPI-OMP-Gemver
70ab338b5cfa8f8cc4273e59343b108314d79504
bae6b6895dde5084288ee2c78697b009940f31ba
refs/heads/master
2021-01-06T00:47:33.662568
2020-02-17T18:44:40
2020-02-17T18:44:40
241,181,441
0
1
null
null
null
null
UTF-8
C
false
false
4,201
c
gemver.c
/* Include benchmark-specific header. */ #include "gemver.h" #define max(x, y) ( (x) > (y) ? (x) : (y) ) #define min(x, y) ( (x) < (y) ? (x) : (y) ) double bench_t_start, bench_t_end; static double rtclock() { struct timeval Tp; int stat; stat = gettimeofday (&Tp, NULL); if (stat != 0) printf ("Error return from gettimeofday: %d", stat); return (Tp.tv_sec + Tp.tv_usec * 1.0e-6); } void bench_timer_start() { bench_t_start = rtclock (); } void bench_timer_stop() { bench_t_end = rtclock (); } void bench_timer_print() { printf ("%0.6lf\n", bench_t_end - bench_t_start); } static void init_array (int n, double *alpha, double *beta, double A[ n][n], double u1[ n], double v1[ n], double u2[ n], double v2[ n], double w[ n], double x[ n], double y[ n], double z[ n]) { *alpha = 1.5; *beta = 1.2; double fn = (double)n; #pragma omp parallel for for (int i = 0; i < n; i++) { u1[i] = i; u2[i] = ((i+1)/fn)/2.0; v1[i] = ((i+1)/fn)/4.0; v2[i] = ((i+1)/fn)/6.0; y[i] = ((i+1)/fn)/8.0; z[i] = ((i+1)/fn)/9.0; x[i] = 0.0; w[i] = 0.0; for (int j = 0; j < n; j++) { A[i][j] = (double) (i*j % n) / n; } } } static void print_array(int n, double w[ n]) { int i; fprintf(stderr, "==BEGIN DUMP_ARRAYS==\n"); fprintf(stderr, "begin dump: %s", "w"); for (i = 0; i < n; i++) { if (i % 20 == 0) fprintf (stderr, "\n"); fprintf (stderr, "%0.2lf ", w[i]); } fprintf(stderr, "\nend dump: %s\n", "w"); fprintf(stderr, "==END DUMP_ARRAYS==\n"); } static void kernel_gemver(int n, double alpha, double beta, double A[ n][n], double u1[ n], double v1[ n], double u2[ n], double v2[ n], double w[ n], double x[ n], double y[ n], double z[ n]) { omp_set_num_threads(1); if (n < 400) { omp_set_num_threads(1); } #pragma omp parallel { int BLOCK_SIZE = n / omp_get_num_threads(); #pragma omp for for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { A[i][j] = A[i][j] + u1[i] * v1[j] + u2[i] * v2[j]; } } #pragma omp for for (int j1 = 0; j1 < n; j1 += BLOCK_SIZE) { for (int i = 0; i < n; ++i) { for (int j2 = 0; j2 < min(BLOCK_SIZE, n - j1); ++j2) { x[j1 + j2] = x[j1 + j2] + beta * A[i][j1 + j2] * y[i]; } } } #pragma omp for for (int i = 0; i < n; ++i) { x[i] = x[i] + z[i]; } #pragma omp for for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { w[i] = w[i] + alpha * A[i][j] * x[j]; } } } } int main(int argc, char** argv) { int n = atoi(argv[1]); double alpha; double beta; double (*A)[n][n]; A = (double(*)[n][n])malloc ((n) * (n) * sizeof(double)); double (*u1)[n]; u1 = (double(*)[n])malloc ((n) * sizeof(double)); double (*v1)[n]; v1 = (double(*)[n])malloc ((n) * sizeof(double)); double (*u2)[n]; u2 = (double(*)[n])malloc ((n) * sizeof(double)); double (*v2)[n]; v2 = (double(*)[n])malloc ((n) * sizeof(double)); double (*w)[n]; w = (double(*)[n])malloc ((n) * sizeof(double)); double (*x)[n]; x = (double(*)[n])malloc ((n) * sizeof(double)); double (*y)[n]; y = (double(*)[n])malloc ((n) * sizeof(double)); double (*z)[n]; z = (double(*)[n])malloc ((n) * sizeof(double)); init_array (n, &alpha, &beta, *A, *u1, *v1, *u2, *v2, *w, *x, *y, *z); bench_timer_start(); kernel_gemver (n, alpha, beta, *A, *u1, *v1, *u2, *v2, *w, *x, *y, *z); bench_timer_stop(); bench_timer_print(); // print_array(n, *w); free((void*)A); free((void*)u1); free((void*)v1); free((void*)u2); free((void*)v2); free((void*)w); free((void*)x); free((void*)y); free((void*)z); return 0; }
ff4dec735ded7211816b5a4bad1f9eb5ef64cb2a
464919df2f2285bdaf19b258007a89324d2e71b3
/ft_toupper.c
ef46646f1f9e2c88d55a07071385d6385b5fc3d4
[]
no_license
violettagoldman/Libft
b90e1ec1c473f52b21a493fa26c8b8e23d9de379
2b5437907c676347266fec987354326117b229f2
refs/heads/master
2020-09-04T10:28:18.064189
2019-11-05T09:51:46
2019-11-05T09:51:46
219,710,813
1
0
null
null
null
null
UTF-8
C
false
false
977
c
ft_toupper.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_toupper.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: vgoldman <vgoldman@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/10/04 14:13:06 by vgoldman #+# #+# */ /* Updated: 2019/10/16 10:58:41 by vgoldman ### ########.fr */ /* */ /* ************************************************************************** */ int ft_toupper(int c) { if (c >= 97 && c <= 122) return (c - 32); return (c); }
a69b33ac1170728952a1c4504b05ac7b7ab5a093
a0fb4a889d0699c4c3575fde490cee0e730ee3ed
/sum of digits.c
341dbcf7b0c512d382c5a98c004bd54c04fd1c04
[]
no_license
kalaikumarece/kalaikumar08
10135955e7a432df5b0c42a3fb30ef2e37c6f537
6e72ed7ffb71eeef1c2c3612dd21c3c8915f9022
refs/heads/master
2021-05-14T11:14:54.770431
2018-03-19T11:17:15
2018-03-19T11:17:15
116,373,539
0
1
null
null
null
null
UTF-8
C
false
false
259
c
sum of digits.c
#include <stdio.h> int main() { int num,temp,digit,sum=0; printf("enter the element"); scanf("%d",&num); temp=num; while(num>0) { digit=num%10; sum=sum+digit; num=num/10; } printf("sum of given no %d is = %d",temp,sum); return 0; }
a767c04aeb78625f2346a8fa629f0b5b576b73e0
cbbf08913443e99173fc71b0ff32e3e68b873244
/MsUnitTestPkg/MorLockTestApp/MorLockTestApp.c
236754dd4a665be08940444e933b155920d3d041
[]
no_license
kevinzhang1986/MsUEFI-Test
bc48d205d236948904e510b3d3bfd9c4ad79c264
8dc828ab323e3e907d7488a0443ca11bfe8c146c
refs/heads/master
2021-01-11T14:16:26.200117
2016-09-23T01:01:47
2016-09-23T01:01:47
null
0
0
null
null
null
null
UTF-8
C
false
false
49,659
c
MorLockTestApp.c
/** @file -- MorLockTestApp.c This application will test the MorLock v1 and v2 variable protection feature. 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. Copyright (C) 2016 Microsoft Corporation. All Rights Reserved. **/ #include <Uefi.h> #include <Library/UefiLib.h> #include <Library/DebugLib.h> #include <Library/BaseMemoryLib.h> #include <Library/UnitTestLib.h> #include <Library/UefiRuntimeServicesTableLib.h> #include <Guid/MemoryOverwriteControl.h> #include <IndustryStandard/MemoryOverwriteRequestControlLock.h> #define UNIT_TEST_APP_NAME L"MORLock v1 and v2 Test" #define UNIT_TEST_APP_SHORT_NAME L"MorLock_v1_and_v2_Test" #define UNIT_TEST_APP_VERSION L"0.1" #define MOR_LOCK_DATA_UNLOCKED 0x0 #define MOR_LOCK_DATA_LOCKED_WITHOUT_KEY 0x1 #define MOR_LOCK_DATA_LOCKED_WITH_KEY 0x2 #define MOR_LOCK_V1_SIZE 1 #define MOR_LOCK_V2_KEY_SIZE 8 #define MOR_VARIABLE_ATTRIBUTES (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS) #define MOR_VARIABLE_BAD_ATTRIBUTES1 (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS) #define MOR_VARIABLE_BAD_ATTRIBUTES2 (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS) UINT8 mTestKey1[] = { 0xD5, 0x80, 0xC6, 0x1D, 0x84, 0x44, 0x4E, 0x87 }; UINT8 mTestKey2[] = { 0x94, 0x88, 0x8F, 0xFE, 0x1D, 0x6C, 0xE0, 0x68 }; UINT8 mTestKey3[] = { 0x81, 0x51, 0x1E, 0x00, 0xCB, 0xFE, 0x48, 0xD9 }; ///================================================================================================ ///================================================================================================ /// /// HELPER FUNCTIONS /// ///================================================================================================ ///================================================================================================ UNIT_TEST_STATUS EFIAPI MorControlVariableShouldBeCorrect ( IN UNIT_TEST_FRAMEWORK_HANDLE Framework, IN UNIT_TEST_CONTEXT Context ) { EFI_STATUS Status; UINT32 Attributes; UINTN DataSize; UINT8 Data; UT_LOG_VERBOSE( __FUNCTION__"()\n" ); DataSize = sizeof( Data ); Status = gRT->GetVariable( MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME, &gEfiMemoryOverwriteControlDataGuid, &Attributes, &DataSize, &Data ); return (UT_ASSERT_NOT_EFI_ERROR( Status ) && UT_ASSERT_EQUAL( Attributes, MOR_VARIABLE_ATTRIBUTES ) && UT_ASSERT_EQUAL( DataSize, sizeof( Data ) )) ? UNIT_TEST_PASSED : UNIT_TEST_ERROR_TEST_FAILED; } // MorControlVariableShouldBeCorrect() STATIC EFI_STATUS GetMorControlVariable ( OUT UINT8 *MorControl ) { EFI_STATUS Status; UINTN DataSize; UINT8 Data; DataSize = sizeof( Data ); Status = gRT->GetVariable( MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME, &gEfiMemoryOverwriteControlDataGuid, NULL, &DataSize, &Data ); if (!EFI_ERROR( Status )) { if (DataSize != sizeof( *MorControl )) { Status = EFI_BAD_BUFFER_SIZE; } else { *MorControl = Data; } } return Status; } // GetMorControlVariable() STATIC EFI_STATUS SetMorControlVariable ( IN UINT8 *MorControl ) { EFI_STATUS Status; Status = gRT->SetVariable( MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME, &gEfiMemoryOverwriteControlDataGuid, MOR_VARIABLE_ATTRIBUTES, sizeof( *MorControl ), MorControl ); return Status; } // SetMorControlVariable() STATIC VOID UnitTestCleanupReboot ( IN UNIT_TEST_FRAMEWORK_HANDLE Framework ) { // Reboot this mother. SaveFrameworkStateAndReboot( Framework, NULL, 0, EfiResetCold ); return; } // UnitTestCleanupReboot() STATIC EFI_STATUS GetMorLockVariable ( OUT UINT8 *MorLock ) { EFI_STATUS Status; UINTN DataSize; UINT8 Data; DataSize = sizeof( Data ); Status = gRT->GetVariable( MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_NAME, &gEfiMemoryOverwriteRequestControlLockGuid, NULL, &DataSize, &Data ); if (!EFI_ERROR( Status )) { if (DataSize != sizeof( *MorLock )) { Status = EFI_BAD_BUFFER_SIZE; } else { *MorLock = Data; } } return Status; } // GetMorLockVariable() UNIT_TEST_STATUS EFIAPI MorLockShouldNotBeSet ( IN UNIT_TEST_FRAMEWORK_HANDLE Framework, IN UNIT_TEST_CONTEXT Context ) { EFI_STATUS Status; UINT8 MorLock; UT_LOG_VERBOSE( __FUNCTION__"()\n" ); Status = GetMorLockVariable( &MorLock ); return ((Status == EFI_NOT_FOUND) || (UT_ASSERT_NOT_EFI_ERROR( Status ) && UT_ASSERT_EQUAL( MorLock, MOR_LOCK_DATA_UNLOCKED ))) ? UNIT_TEST_PASSED : UNIT_TEST_ERROR_TEST_FAILED; } // MorLockShouldNotBeSet() ///================================================================================================ ///================================================================================================ /// /// TEST CASES /// ///================================================================================================ ///================================================================================================ UNIT_TEST_STATUS EFIAPI MorControlVariableShouldExist ( IN UNIT_TEST_FRAMEWORK_HANDLE Framework, IN UNIT_TEST_CONTEXT Context ) { EFI_STATUS Status; UINTN DataSize; UINT8 Data; DataSize = sizeof( Data ); Status = gRT->GetVariable( MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME, &gEfiMemoryOverwriteControlDataGuid, NULL, &DataSize, &Data ); return UT_ASSERT_NOT_EQUAL( Status, EFI_NOT_FOUND ) ? UNIT_TEST_PASSED : UNIT_TEST_ERROR_TEST_FAILED; } // MorControlVariableShouldExist() UNIT_TEST_STATUS EFIAPI MorControlVariableShouldHaveCorrectSize ( IN UNIT_TEST_FRAMEWORK_HANDLE Framework, IN UNIT_TEST_CONTEXT Context ) { EFI_STATUS Status; UINTN DataSize; UINT8 Data; DataSize = sizeof( Data ); Status = gRT->GetVariable( MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME, &gEfiMemoryOverwriteControlDataGuid, NULL, &DataSize, &Data ); return (UT_ASSERT_NOT_EFI_ERROR( Status ) && UT_ASSERT_EQUAL( DataSize, sizeof( Data ) )) ? UNIT_TEST_PASSED : UNIT_TEST_ERROR_TEST_FAILED; } // MorControlVariableShouldHaveCorrectSize() UNIT_TEST_STATUS EFIAPI MorControlVariableShouldHaveCorrectAttributes ( IN UNIT_TEST_FRAMEWORK_HANDLE Framework, IN UNIT_TEST_CONTEXT Context ) { EFI_STATUS Status; UINT32 Attributes; UINTN DataSize; UINT8 Data; DataSize = sizeof( Data ); Status = gRT->GetVariable( MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME, &gEfiMemoryOverwriteControlDataGuid, &Attributes, &DataSize, &Data ); return (!EFI_ERROR( Status ) && Attributes == MOR_VARIABLE_ATTRIBUTES) ? UNIT_TEST_PASSED : UNIT_TEST_ERROR_TEST_FAILED; } // MorControlVariableShouldHaveCorrectAttributes() UNIT_TEST_STATUS EFIAPI MorControlShouldEnforceCorrectAttributes ( IN UNIT_TEST_FRAMEWORK_HANDLE Framework, IN UNIT_TEST_CONTEXT Context ) { EFI_STATUS Status; UINT8 Data; UNIT_TEST_STATUS Result = UNIT_TEST_ERROR_TEST_FAILED; // First, we have to try to delete the Control variable, // given that it should exist. Status = gRT->SetVariable( MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME, &gEfiMemoryOverwriteControlDataGuid, 0, 0, NULL ); UT_ASSERT_NOT_EFI_ERROR( Status ); // Then we want to try to set it with bad attributes. if (!EFI_ERROR( Status )) { Data = FALSE; Status = gRT->SetVariable( MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME, &gEfiMemoryOverwriteControlDataGuid, MOR_VARIABLE_BAD_ATTRIBUTES1, sizeof( Data ), &Data ); if (Status == EFI_ACCESS_DENIED) { // TODO: This is my reminder to come back and finish this... // Result = UNIT_TEST_PASSED; UT_ASSERT_TRUE( TRUE == FALSE ); } } // TODO: Write a MOR_VARIABLE_BAD_ATTRIBUTES2 test that works with auth. return Result; } // MorControlShouldEnforceCorrectAttributes() UNIT_TEST_STATUS EFIAPI MorControlShouldChangeWhenNotLocked ( IN UNIT_TEST_FRAMEWORK_HANDLE Framework, IN UNIT_TEST_CONTEXT Context ) { EFI_STATUS Status; UINT8 MorControl; // Make sure that the variable can be set to TRUE. MorControl = TRUE; Status = SetMorControlVariable( &MorControl ); if (!EFI_ERROR( Status )) { Status = GetMorControlVariable( &MorControl ); if (!EFI_ERROR( Status) && MorControl != TRUE) { Status = EFI_ABORTED; } } // Make sure that the variable can be set to FALSE. if (!EFI_ERROR( Status )) { MorControl = FALSE; Status = SetMorControlVariable( &MorControl ); if (!EFI_ERROR( Status )) { Status = GetMorControlVariable( &MorControl ); if (!EFI_ERROR( Status) && MorControl != FALSE) { Status = EFI_ABORTED; } } } return !EFI_ERROR( Status ) ? UNIT_TEST_PASSED : UNIT_TEST_ERROR_TEST_FAILED; } // MorControlShouldChangeWhenNotLocked() UNIT_TEST_STATUS EFIAPI MorLockv1ShouldNotSetBadValue ( IN UNIT_TEST_FRAMEWORK_HANDLE Framework, IN UNIT_TEST_CONTEXT Context ) { EFI_STATUS Status; UINTN DataSize; UINT8 MorLock; UNIT_TEST_STATUS Result = UNIT_TEST_PASSED; // Attempt to set the MorLock to a non-key, non-TRUE/FALSE value. MorLock = 0xAA; DataSize = sizeof( MorLock ); Status = gRT->SetVariable( MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_NAME, &gEfiMemoryOverwriteRequestControlLockGuid, MOR_VARIABLE_ATTRIBUTES, DataSize, &MorLock ); // Make sure that the status is EFI_INVALID_PARAMETER. if (!UT_ASSERT_STATUS_EQUAL( Status, EFI_INVALID_PARAMETER )) { Result = UNIT_TEST_ERROR_TEST_FAILED; } // If the value was accepted, for some reason, // we need to reboot to clean up after ourselves. if (!EFI_ERROR( Status )) { // Check this trick out... // We're gonna pull the rug out from under ourselves. ((UNIT_TEST_FRAMEWORK*)Framework)->CurrentTest->CleanUp = UnitTestCleanupReboot; } return Result; } // MorLockv1ShouldNotSetBadValue() UNIT_TEST_STATUS EFIAPI MorLockv1ShouldNotSetBadBufferSize ( IN UNIT_TEST_FRAMEWORK_HANDLE Framework, IN UNIT_TEST_CONTEXT Context ) { EFI_STATUS Status; UINTN DataSize; UINT8 MorLock[] = { 0xDE, 0xAD, 0xBE, 0xEF }; UNIT_TEST_STATUS Result = UNIT_TEST_PASSED; // Attempt to set the MorLock to a non-key, non-TRUE/FALSE value. DataSize = sizeof( MorLock ); Status = gRT->SetVariable( MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_NAME, &gEfiMemoryOverwriteRequestControlLockGuid, MOR_VARIABLE_ATTRIBUTES, DataSize, &MorLock ); // Make sure that the status is EFI_INVALID_PARAMETER. if (!UT_ASSERT_STATUS_EQUAL( Status, EFI_INVALID_PARAMETER )) { Result = UNIT_TEST_ERROR_TEST_FAILED; } // If the value was accepted, for some reason, // we need to reboot to clean up after ourselves. if (!EFI_ERROR( Status )) { // Check this trick out... // We're gonna pull the rug out fromm under ourselves. ((UNIT_TEST_FRAMEWORK*)Framework)->CurrentTest->CleanUp = UnitTestCleanupReboot; } return Result; } // MorLockv1ShouldNotSetBadBufferSize() UNIT_TEST_STATUS EFIAPI MorLockShouldNotSetBadAttributes ( IN UNIT_TEST_FRAMEWORK_HANDLE Framework, IN UNIT_TEST_CONTEXT Context ) { EFI_STATUS Status; UINTN DataSize; UINT8 MorLock; // Attempt to set the MorLock. DataSize = sizeof( MorLock ); MorLock = TRUE; Status = gRT->SetVariable( MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_NAME, &gEfiMemoryOverwriteRequestControlLockGuid, MOR_VARIABLE_BAD_ATTRIBUTES1, DataSize, &MorLock ); return UT_ASSERT_STATUS_EQUAL( Status, EFI_INVALID_PARAMETER ) ? UNIT_TEST_PASSED : UNIT_TEST_ERROR_TEST_FAILED; } // MorLockShouldNotSetBadAttributes() UNIT_TEST_STATUS EFIAPI MorLockv1ShouldBeLockable ( IN UNIT_TEST_FRAMEWORK_HANDLE Framework, IN UNIT_TEST_CONTEXT Context ) { EFI_STATUS Status; UINTN DataSize; UINT8 MorLock; // Attempt to set the MorLock. DataSize = sizeof( MorLock ); MorLock = TRUE; Status = gRT->SetVariable( MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_NAME, &gEfiMemoryOverwriteRequestControlLockGuid, MOR_VARIABLE_ATTRIBUTES, DataSize, &MorLock ); // // NOTE: Strictly speaking, this isn't a good unit test. // After this test runs, the MorLock is set and the other tests // have some expectation that the lock will behave a certain way. // We *could* make better unit tests, but there would be a lot more // reboots. So let's say this is for efficiency. // return UT_ASSERT_NOT_EFI_ERROR( Status ) ? UNIT_TEST_PASSED : UNIT_TEST_ERROR_TEST_FAILED; } // MorLockv1ShouldBeLockable() UNIT_TEST_STATUS EFIAPI MorLockv1ShouldReportCorrectly ( IN UNIT_TEST_FRAMEWORK_HANDLE Framework, IN UNIT_TEST_CONTEXT Context ) { EFI_STATUS Status; UINT8 MorLock; UT_LOG_VERBOSE( __FUNCTION__"()\n" ); Status = GetMorLockVariable( &MorLock ); UT_LOG_VERBOSE( __FUNCTION__" - Status = %r, MorLock = %d\n", Status, MorLock ); return (UT_ASSERT_NOT_EFI_ERROR( Status ) && UT_ASSERT_EQUAL( MorLock, MOR_LOCK_DATA_LOCKED_WITHOUT_KEY )) ? UNIT_TEST_PASSED : UNIT_TEST_ERROR_TEST_FAILED; } // MorLockv1ShouldReportCorrectly() UNIT_TEST_STATUS EFIAPI MorControlShouldNotChange ( IN UNIT_TEST_FRAMEWORK_HANDLE Framework, IN UNIT_TEST_CONTEXT Context ) { EFI_STATUS Status; UINT8 MorControl; UNIT_TEST_STATUS Result = UNIT_TEST_PASSED; // Determine the current status. Status = GetMorControlVariable( &MorControl ); if (EFI_ERROR( Status )) { return UNIT_TEST_ERROR_TEST_FAILED; } // If we're set, try to unset. if (MorControl) { MorControl = FALSE; Status = SetMorControlVariable( &MorControl ); // If this was successful, that's not good. if (!EFI_ERROR( Status )) { Result = UNIT_TEST_ERROR_TEST_FAILED; } } // If we're unset, try to set. else { MorControl = TRUE; Status = SetMorControlVariable( &MorControl ); // If this was successful, that's not good. if (!EFI_ERROR( Status )) { Result = UNIT_TEST_ERROR_TEST_FAILED; } } return Result; } // MorControlShouldNotChange() UNIT_TEST_STATUS EFIAPI MorLockv1ShouldNotChangeWhenLocked ( IN UNIT_TEST_FRAMEWORK_HANDLE Framework, IN UNIT_TEST_CONTEXT Context ) { EFI_STATUS Status; UINTN DataSize; UINT8 MorLock; // Attempt to unset the MorLock. DataSize = sizeof( MorLock ); MorLock = FALSE; Status = gRT->SetVariable( MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_NAME, &gEfiMemoryOverwriteRequestControlLockGuid, MOR_VARIABLE_ATTRIBUTES, DataSize, &MorLock ); return UT_ASSERT_STATUS_EQUAL( Status, EFI_ACCESS_DENIED ) ? UNIT_TEST_PASSED : UNIT_TEST_ERROR_TEST_FAILED; } // MorLockv1ShouldNotChangeWhenLocked() UNIT_TEST_STATUS EFIAPI MorLockv1ShouldNotBeDeleteable ( IN UNIT_TEST_FRAMEWORK_HANDLE Framework, IN UNIT_TEST_CONTEXT Context ) { EFI_STATUS Status; // Attempt to delete the MorLock. Status = gRT->SetVariable( MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_NAME, &gEfiMemoryOverwriteRequestControlLockGuid, 0, 0, NULL ); return UT_ASSERT_STATUS_EQUAL( Status, EFI_ACCESS_DENIED ) ? UNIT_TEST_PASSED : UNIT_TEST_ERROR_TEST_FAILED; } // MorLockv1ShouldNotBeDeleteable() UNIT_TEST_STATUS EFIAPI MorLockShouldClearAfterReboot ( IN UNIT_TEST_FRAMEWORK_HANDLE Framework, IN UNIT_TEST_CONTEXT Context ) { EFI_STATUS Status; UINT8 MorLock; UNIT_TEST_STATUS Result = UNIT_TEST_ERROR_TEST_FAILED; BOOLEAN IsPostReboot = FALSE; // Because we're going to reboot, we need to check for // a saved context. if (Context != NULL) { IsPostReboot = *(BOOLEAN*)Context; } // If we haven't reboot yet, we need to reboot. if (!IsPostReboot) { // Indicate that we've gotten here already... IsPostReboot = TRUE; UT_LOG_INFO( "Going down for reboot!\n" ); // A warm reboot should be sufficient. SaveFrameworkStateAndReboot( Framework, &IsPostReboot, sizeof( IsPostReboot ), EfiResetWarm ); // We shouldn't get here. If we do, we'll just return failure from this function. UT_LOG_ERROR( "Reboot failed! Should never get here!!\n" ); } // Otherwise, we need to check the status of the MorLock. else { // Check the MorLock. Status = GetMorLockVariable( &MorLock ); if (!EFI_ERROR( Status ) && MorLock == MOR_LOCK_DATA_UNLOCKED) { Result = UNIT_TEST_PASSED; } } return Result; } // MorLockShouldClearAfterReboot() UNIT_TEST_STATUS EFIAPI MorLockv2ShouldNotSetSmallBuffer ( IN UNIT_TEST_FRAMEWORK_HANDLE Framework, IN UNIT_TEST_CONTEXT Context ) { EFI_STATUS Status; UINTN DataSize; UINT8 MorLock[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF }; UNIT_TEST_STATUS Result = UNIT_TEST_PASSED; // First off, let's just make sure that our test is rational. DataSize = sizeof( MorLock ); if (DataSize < MOR_LOCK_V2_KEY_SIZE + 1) { return UNIT_TEST_ERROR_TEST_FAILED; } // Attempt to set the MorLock to smaller than designated key size. DataSize = MOR_LOCK_V2_KEY_SIZE - 1; Status = gRT->SetVariable( MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_NAME, &gEfiMemoryOverwriteRequestControlLockGuid, MOR_VARIABLE_ATTRIBUTES, DataSize, &MorLock ); // Make sure that the status is EFI_INVALID_PARAMETER. if (!UT_ASSERT_STATUS_EQUAL( Status, EFI_INVALID_PARAMETER )) { Result = UNIT_TEST_ERROR_TEST_FAILED; } // If the value was accepted, for some reason, // we need to reboot to clean up after ourselves. if (!EFI_ERROR( Status )) { // Check this trick out... // We're gonna pull the rug out fromm under ourselves. ((UNIT_TEST_FRAMEWORK*)Framework)->CurrentTest->CleanUp = UnitTestCleanupReboot; } return Result; } // MorLockv2ShouldNotSetSmallBuffer() UNIT_TEST_STATUS EFIAPI MorLockv2ShouldNotSetLargeBuffer ( IN UNIT_TEST_FRAMEWORK_HANDLE Framework, IN UNIT_TEST_CONTEXT Context ) { EFI_STATUS Status; UINTN DataSize; UINT8 MorLock[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF }; UNIT_TEST_STATUS Result = UNIT_TEST_PASSED; // First off, let's just make sure that our test is rational. DataSize = sizeof( MorLock ); if (DataSize < MOR_LOCK_V2_KEY_SIZE + 1) { return UNIT_TEST_ERROR_TEST_FAILED; } // Attempt to set the MorLock to larger than designated key size. DataSize = MOR_LOCK_V2_KEY_SIZE + 1; Status = gRT->SetVariable( MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_NAME, &gEfiMemoryOverwriteRequestControlLockGuid, MOR_VARIABLE_ATTRIBUTES, DataSize, &MorLock ); // Make sure that the status is EFI_INVALID_PARAMETER. if (!UT_ASSERT_STATUS_EQUAL( Status, EFI_INVALID_PARAMETER )) { Result = UNIT_TEST_ERROR_TEST_FAILED; } // If the value was accepted, for some reason, // we need to reboot to clean up after ourselves. if (!EFI_ERROR( Status )) { // Check this trick out... // We're gonna pull the rug out fromm under ourselves. ((UNIT_TEST_FRAMEWORK*)Framework)->CurrentTest->CleanUp = UnitTestCleanupReboot; } return Result; } // MorLockv2ShouldNotSetLargeBuffer() UNIT_TEST_STATUS EFIAPI MorLockv2ShouldNotSetNoBuffer ( IN UNIT_TEST_FRAMEWORK_HANDLE Framework, IN UNIT_TEST_CONTEXT Context ) { EFI_STATUS Status; UINTN DataSize; UINT8 MorLock; UNIT_TEST_STATUS Result = UNIT_TEST_PASSED; // Attempt to set the MorLock v2 directly; DataSize = sizeof( MorLock ); MorLock = MOR_LOCK_DATA_LOCKED_WITH_KEY; Status = gRT->SetVariable( MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_NAME, &gEfiMemoryOverwriteRequestControlLockGuid, MOR_VARIABLE_ATTRIBUTES, DataSize, &MorLock ); // Make sure that the status is EFI_INVALID_PARAMETER. if (!UT_ASSERT_STATUS_EQUAL( Status, EFI_INVALID_PARAMETER )) { Result = UNIT_TEST_ERROR_TEST_FAILED; } // If the value was accepted, for some reason, // we need to reboot to clean up after ourselves. if (!EFI_ERROR( Status )) { // Check this trick out... // We're gonna pull the rug out fromm under ourselves. ((UNIT_TEST_FRAMEWORK*)Framework)->CurrentTest->CleanUp = UnitTestCleanupReboot; } return Result; } // MorLockv2ShouldNotSetNoBuffer() UNIT_TEST_STATUS EFIAPI MorLockv2ShouldBeLockable ( IN UNIT_TEST_FRAMEWORK_HANDLE Framework, IN UNIT_TEST_CONTEXT Context ) { EFI_STATUS Status; UINTN DataSize; // Attempt to set a key for MorLock v2. // For this test, we'll use Test Key 1. DataSize = sizeof( mTestKey1 ); Status = gRT->SetVariable( MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_NAME, &gEfiMemoryOverwriteRequestControlLockGuid, MOR_VARIABLE_ATTRIBUTES, DataSize, &mTestKey1[0] ); // // NOTE: Strictly speaking, this isn't a good unit test. // After this test runs, the MorLock is set and the other tests // have some expectation that the lock will behave a certain way. // We *could* make better unit tests, but there would be a lot more // reboots. So let's say this is for efficiency. // return UT_ASSERT_NOT_EFI_ERROR( Status ) ? UNIT_TEST_PASSED : UNIT_TEST_ERROR_TEST_FAILED; } // MorLockv2ShouldBeLockable() UNIT_TEST_STATUS EFIAPI MorLockv2ShouldReportCorrectly ( IN UNIT_TEST_FRAMEWORK_HANDLE Framework, IN UNIT_TEST_CONTEXT Context ) { EFI_STATUS Status; UINT8 MorLock; UT_LOG_VERBOSE( __FUNCTION__"()\n" ); Status = GetMorLockVariable( &MorLock ); UT_LOG_VERBOSE( __FUNCTION__" - Status = %r, MorLock = %d\n", Status, MorLock ); return (UT_ASSERT_NOT_EFI_ERROR( Status ) && UT_ASSERT_EQUAL( MorLock, MOR_LOCK_DATA_LOCKED_WITH_KEY )) ? UNIT_TEST_PASSED : UNIT_TEST_ERROR_TEST_FAILED; } // MorLockv2ShouldReportCorrectly() UNIT_TEST_STATUS EFIAPI MorLockv2ShouldOnlyReturnOneByte ( IN UNIT_TEST_FRAMEWORK_HANDLE Framework, IN UNIT_TEST_CONTEXT Context ) { EFI_STATUS Status; UINTN DataSize; UINT8 MorLock[MOR_LOCK_V2_KEY_SIZE]; // Blank the buffer so we know it doesn't contain the key. ZeroMem( &MorLock[0], sizeof( MorLock ) ); // Fetch the MorLock so we can see what we get. DataSize = sizeof( MorLock ); Status = gRT->GetVariable( MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_NAME, &gEfiMemoryOverwriteRequestControlLockGuid, NULL, &DataSize, &MorLock ); // Check to see how much data was returned. if (!EFI_ERROR( Status ) && DataSize > 1) { Status = EFI_ACCESS_DENIED; } return (!EFI_ERROR( Status )) ? UNIT_TEST_PASSED : UNIT_TEST_ERROR_TEST_FAILED; } // MorLockv2ShouldOnlyReturnOneByte() UNIT_TEST_STATUS EFIAPI MorLockv2ShouldNotReturnKey ( IN UNIT_TEST_FRAMEWORK_HANDLE Framework, IN UNIT_TEST_CONTEXT Context ) { EFI_STATUS Status; UINTN DataSize; UINT8 MorLock[MOR_LOCK_V2_KEY_SIZE]; // Blank the buffer so we know it doesn't contain the key. ZeroMem( &MorLock[0], sizeof( MorLock ) ); // Fetch the MorLock so we can see what we get. DataSize = sizeof( MorLock ); Status = gRT->GetVariable( MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_NAME, &gEfiMemoryOverwriteRequestControlLockGuid, NULL, &DataSize, &MorLock ); // Check for the key in the buffer. // We would EXPECT to only receive one byte, but you never know. if (!EFI_ERROR( Status ) && DataSize > 1) { // We're only using three keys in these tests. // Might as well check them all. if (CompareMem( &MorLock[0], &mTestKey1[0], sizeof( MorLock ) ) == 0 || CompareMem( &MorLock[0], &mTestKey2[0], sizeof( MorLock ) ) == 0 || CompareMem( &MorLock[0], &mTestKey3[0], sizeof( MorLock ) ) == 0) { Status = EFI_ACCESS_DENIED; } } return (!EFI_ERROR( Status )) ? UNIT_TEST_PASSED : UNIT_TEST_ERROR_TEST_FAILED; } // MorLockv2ShouldNotReturnKey() UNIT_TEST_STATUS EFIAPI MorLockv2ShouldNotChangeWhenLocked ( IN UNIT_TEST_FRAMEWORK_HANDLE Framework, IN UNIT_TEST_CONTEXT Context ) { EFI_STATUS Status; UINTN DataSize; // Attempt to change the key for MorLock v2. // For this test, we'll use Test Key 2. DataSize = sizeof( mTestKey2 ); Status = gRT->SetVariable( MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_NAME, &gEfiMemoryOverwriteRequestControlLockGuid, MOR_VARIABLE_ATTRIBUTES, DataSize, &mTestKey2[0] ); return UT_ASSERT_STATUS_EQUAL( Status, EFI_ACCESS_DENIED ) ? UNIT_TEST_PASSED : UNIT_TEST_ERROR_TEST_FAILED; } // MorLockv2ShouldNotChangeWhenLocked() UNIT_TEST_STATUS EFIAPI MorLockv2ShouldNotChangeTov1 ( IN UNIT_TEST_FRAMEWORK_HANDLE Framework, IN UNIT_TEST_CONTEXT Context ) { EFI_STATUS Status; UINTN DataSize; UINT8 MorLock; // Attempt to set the MorLock to v1. DataSize = sizeof( MorLock ); MorLock = TRUE; Status = gRT->SetVariable( MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_NAME, &gEfiMemoryOverwriteRequestControlLockGuid, MOR_VARIABLE_ATTRIBUTES, DataSize, &MorLock ); return UT_ASSERT_STATUS_EQUAL( Status, EFI_ACCESS_DENIED ) ? UNIT_TEST_PASSED : UNIT_TEST_ERROR_TEST_FAILED; } // MorLockv2ShouldNotChangeTov1() UNIT_TEST_STATUS EFIAPI MorLockv2ShouldNotBeDeleteable ( IN UNIT_TEST_FRAMEWORK_HANDLE Framework, IN UNIT_TEST_CONTEXT Context ) { EFI_STATUS Status; // Attempt to delete the MorLock. Status = gRT->SetVariable( MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_NAME, &gEfiMemoryOverwriteRequestControlLockGuid, 0, 0, NULL ); return UT_ASSERT_STATUS_EQUAL( Status, EFI_ACCESS_DENIED ) ? UNIT_TEST_PASSED : UNIT_TEST_ERROR_TEST_FAILED; } // MorLockv2ShouldNotBeDeleteable() UNIT_TEST_STATUS EFIAPI MorLockv2ShouldClearWithCorrectKey ( IN UNIT_TEST_FRAMEWORK_HANDLE Framework, IN UNIT_TEST_CONTEXT Context ) { EFI_STATUS Status; UINTN DataSize; UINT8 MorLock; UNIT_TEST_STATUS Result = UNIT_TEST_ERROR_TEST_FAILED; // Attempt to set a key for MorLock v2. // For this test, we'll use Test Key 1. DataSize = sizeof( mTestKey1 ); Status = gRT->SetVariable( MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_NAME, &gEfiMemoryOverwriteRequestControlLockGuid, MOR_VARIABLE_ATTRIBUTES, DataSize, &mTestKey1[0] ); // If this key failed to set, we're done here. if (EFI_ERROR( Status )) { goto Exit; } // Verify that the key was set. Status = GetMorLockVariable( &MorLock ); if (EFI_ERROR( Status ) || MorLock != MOR_LOCK_DATA_LOCKED_WITH_KEY) { goto Exit; } // Attempt to clear with the same key. DataSize = sizeof( mTestKey1 ); Status = gRT->SetVariable( MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_NAME, &gEfiMemoryOverwriteRequestControlLockGuid, MOR_VARIABLE_ATTRIBUTES, DataSize, &mTestKey1[0] ); // If this key failed to set, we're done here. if (EFI_ERROR( Status )) { goto Exit; } // Verify that mode is now disabled. Status = GetMorLockVariable( &MorLock ); if (EFI_ERROR( Status ) || MorLock != MOR_LOCK_DATA_UNLOCKED) { goto Exit; } // Only if we've made it this far are we good to return UNIT_TEST_PASSED. Result = UNIT_TEST_PASSED; Exit: return Result; } // MorLockv2ShouldClearWithCorrectKey() UNIT_TEST_STATUS EFIAPI MorLockv2ShouldNotClearWithWrongKey ( IN UNIT_TEST_FRAMEWORK_HANDLE Framework, IN UNIT_TEST_CONTEXT Context ) { EFI_STATUS Status; UINTN DataSize; UINT8 MorLock; UNIT_TEST_STATUS Result = UNIT_TEST_ERROR_TEST_FAILED; // Attempt to set a key for MorLock v2. // For this test, we'll use Test Key 1. DataSize = sizeof( mTestKey1 ); Status = gRT->SetVariable( MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_NAME, &gEfiMemoryOverwriteRequestControlLockGuid, MOR_VARIABLE_ATTRIBUTES, DataSize, &mTestKey1[0] ); // If this key failed to set, we're done here. if (!UT_ASSERT_NOT_EFI_ERROR( Status )) { goto Exit; } // Verify that the key was set. Status = GetMorLockVariable( &MorLock ); if (!UT_ASSERT_NOT_EFI_ERROR( Status ) || !UT_ASSERT_EQUAL( MorLock, MOR_LOCK_DATA_LOCKED_WITH_KEY )) { goto Exit; } // Attempt to clear with a different key. DataSize = sizeof( mTestKey2 ); Status = gRT->SetVariable( MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_NAME, &gEfiMemoryOverwriteRequestControlLockGuid, MOR_VARIABLE_ATTRIBUTES, DataSize, &mTestKey2[0] ); // If this key was successfully set, we're done here. if (!UT_ASSERT_STATUS_EQUAL( Status, EFI_ACCESS_DENIED )) { goto Exit; } // Verify that mode is still enabled. Status = GetMorLockVariable( &MorLock ); if (!UT_ASSERT_NOT_EFI_ERROR( Status ) || !UT_ASSERT_EQUAL( MorLock, MOR_LOCK_DATA_LOCKED_WITH_KEY )) { goto Exit; } // Only if we've made it this far are we good to return UNIT_TEST_PASSED. Result = UNIT_TEST_PASSED; Exit: return Result; } // MorLockv2ShouldNotClearWithWrongKey() UNIT_TEST_STATUS EFIAPI MorLockv2ShouldReleaseMorControlAfterClear ( IN UNIT_TEST_FRAMEWORK_HANDLE Framework, IN UNIT_TEST_CONTEXT Context ) { EFI_STATUS Status; UINTN DataSize; UINT8 MorLock; UNIT_TEST_STATUS Result = UNIT_TEST_ERROR_TEST_FAILED; // Attempt to set a key for MorLock v2. // For this test, we'll use Test Key 1. DataSize = sizeof( mTestKey1 ); Status = gRT->SetVariable( MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_NAME, &gEfiMemoryOverwriteRequestControlLockGuid, MOR_VARIABLE_ATTRIBUTES, DataSize, &mTestKey1[0] ); // If this key failed to set, we're done here. if (EFI_ERROR( Status )) { goto Exit; } // Verify that the key was set. Status = GetMorLockVariable( &MorLock ); if (EFI_ERROR( Status ) || MorLock != MOR_LOCK_DATA_LOCKED_WITH_KEY) { goto Exit; } // Attempt to clear with the same key. DataSize = sizeof( mTestKey1 ); Status = gRT->SetVariable( MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_NAME, &gEfiMemoryOverwriteRequestControlLockGuid, MOR_VARIABLE_ATTRIBUTES, DataSize, &mTestKey1[0] ); // If this key failed to set, we're done here. if (EFI_ERROR( Status )) { goto Exit; } // Verify that mode is now disabled. Status = GetMorLockVariable( &MorLock ); if (EFI_ERROR( Status ) || MorLock != MOR_LOCK_DATA_UNLOCKED) { goto Exit; } // If we've made it this far, the only thing left to do is make sure // that the MOR Control can change. Result = MorControlShouldChangeWhenNotLocked( Framework, NULL ); Exit: return Result; } // MorLockv2ShouldReleaseMorControlAfterClear() UNIT_TEST_STATUS EFIAPI MorLockv2ShouldSetClearSet ( IN UNIT_TEST_FRAMEWORK_HANDLE Framework, IN UNIT_TEST_CONTEXT Context ) { EFI_STATUS Status; UINTN DataSize; UINT8 MorLock; UNIT_TEST_STATUS Result = UNIT_TEST_ERROR_TEST_FAILED; // // Attempt to set a key for MorLock v2. // For this test, we'll use Test Key 1. // DataSize = sizeof( mTestKey1 ); Status = gRT->SetVariable( MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_NAME, &gEfiMemoryOverwriteRequestControlLockGuid, MOR_VARIABLE_ATTRIBUTES, DataSize, &mTestKey1[0] ); // If this key failed to set, we're done here. if (!UT_ASSERT_NOT_EFI_ERROR( Status )) { goto Exit; } // Verify that the key was set. Status = GetMorLockVariable( &MorLock ); if (!UT_ASSERT_NOT_EFI_ERROR( Status ) || !UT_ASSERT_EQUAL( MorLock, MOR_LOCK_DATA_LOCKED_WITH_KEY )) { goto Exit; } // // Attempt to clear with the same key. // DataSize = sizeof( mTestKey1 ); Status = gRT->SetVariable( MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_NAME, &gEfiMemoryOverwriteRequestControlLockGuid, MOR_VARIABLE_ATTRIBUTES, DataSize, &mTestKey1[0] ); // If this key failed to set, we're done here. if (!UT_ASSERT_NOT_EFI_ERROR( Status )) { goto Exit; } // Verify that mode is now disabled. Status = GetMorLockVariable( &MorLock ); if (!UT_ASSERT_NOT_EFI_ERROR( Status ) || !UT_ASSERT_EQUAL( MorLock, MOR_LOCK_DATA_UNLOCKED )) { goto Exit; } // // Attempt to set a second key. // DataSize = sizeof( mTestKey2 ); Status = gRT->SetVariable( MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_NAME, &gEfiMemoryOverwriteRequestControlLockGuid, MOR_VARIABLE_ATTRIBUTES, DataSize, &mTestKey2[0] ); // If this key failed to set, we're done here. if (!UT_ASSERT_NOT_EFI_ERROR( Status )) { goto Exit; } // Verify that the key was set. Status = GetMorLockVariable( &MorLock ); if (!UT_ASSERT_NOT_EFI_ERROR( Status ) || !UT_ASSERT_EQUAL( MorLock, MOR_LOCK_DATA_LOCKED_WITH_KEY )) { goto Exit; } // // Attempt to clear with a different key. // DataSize = sizeof( mTestKey3 ); Status = gRT->SetVariable( MEMORY_OVERWRITE_REQUEST_CONTROL_LOCK_NAME, &gEfiMemoryOverwriteRequestControlLockGuid, MOR_VARIABLE_ATTRIBUTES, DataSize, &mTestKey3[0] ); // If this key was successfully set, we're done here. if (!UT_ASSERT_STATUS_EQUAL( Status, EFI_ACCESS_DENIED )) { goto Exit; } // Verify that mode is still enabled. Status = GetMorLockVariable( &MorLock ); if (!UT_ASSERT_NOT_EFI_ERROR( Status ) || !UT_ASSERT_EQUAL( MorLock, MOR_LOCK_DATA_LOCKED_WITH_KEY )) { goto Exit; } // // Only if we've made it this far are we good to return UNIT_TEST_PASSED. // Result = UNIT_TEST_PASSED; Exit: return Result; } // MorLockv2ShouldSetClearSet() ///================================================================================================ ///================================================================================================ /// /// TEST ENGINE /// ///================================================================================================ ///================================================================================================ /** MorLockTestApp @param[in] ImageHandle The firmware allocated handle for the EFI image. @param[in] SystemTable A pointer to the EFI System Table. @retval EFI_SUCCESS The entry point executed successfully. @retval other Some error occured when executing this entry point. **/ EFI_STATUS EFIAPI MorLockTestApp ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_STATUS Status; UNIT_TEST_FRAMEWORK *Fw = NULL; UNIT_TEST_SUITE *EnvironmentalTests, *MorLockV1Tests, *MorLockV2Tests; BOOLEAN TestsRun = FALSE; DEBUG(( DEBUG_INFO, "%s v%s\n", UNIT_TEST_APP_NAME, UNIT_TEST_APP_VERSION )); // // Start setting up the test framework for running the tests. // Status = InitUnitTestFramework( &Fw, UNIT_TEST_APP_NAME, UNIT_TEST_APP_SHORT_NAME, UNIT_TEST_APP_VERSION ); if (EFI_ERROR( Status )) { DEBUG((DEBUG_ERROR, "Failed in InitUnitTestFramework. Status = %r\n", Status)); goto EXIT; } // // Populate the EnvironmentalTests Unit Test Suite. // Status = CreateUnitTestSuite( &EnvironmentalTests, Fw, L"Boot Environment Tests", NULL, NULL ); if (EFI_ERROR( Status )) { DEBUG((DEBUG_ERROR, "Failed in CreateUnitTestSuite for EnvironmentalTests\n")); Status = EFI_OUT_OF_RESOURCES; goto EXIT; } AddTestCase( EnvironmentalTests, L"On any given boot, the MOR control variable should exist", MorControlVariableShouldExist, NULL, NULL, NULL ); AddTestCase( EnvironmentalTests, L"MOR control variable should be the correct size", MorControlVariableShouldHaveCorrectSize, NULL, NULL, NULL ); AddTestCase( EnvironmentalTests, L"MOR control variable should have correct attributes", MorControlVariableShouldHaveCorrectAttributes, NULL, NULL, NULL ); AddTestCase( EnvironmentalTests, L"Should not be able to create MOR control variable with incorrect attributes", MorControlShouldEnforceCorrectAttributes, NULL, UnitTestCleanupReboot, NULL ); // IMPORTANT NOTE: On a reboot test, currently, prereqs will be run each time the test is continued. Ergo, a prereq that may be // valid on a single boot may not be valid on subsequent boots. THIS MUST BE SOLVED!! // // Populate the MorLockV1Tests Unit Test Suite. // Status = CreateUnitTestSuite( &MorLockV1Tests, Fw, L"MORLock v1 Tests", NULL, NULL ); if (EFI_ERROR( Status )) { DEBUG((DEBUG_ERROR, "Failed in CreateUnitTestSuite for MorLockV1Tests\n")); Status = EFI_OUT_OF_RESOURCES; goto EXIT; } AddTestCase( MorLockV1Tests, L"Should be able to change MOR control when not locked", MorControlShouldChangeWhenNotLocked, MorControlVariableShouldBeCorrect, NULL, NULL ); AddTestCase( MorLockV1Tests, L"Should not be able to set MORLock v1 with a bad value", MorLockv1ShouldNotSetBadValue, MorLockShouldNotBeSet, NULL, NULL ); AddTestCase( MorLockV1Tests, L"Should not be able to set MORLock v1 with strange buffer size", MorLockv1ShouldNotSetBadBufferSize, MorLockShouldNotBeSet, NULL, NULL ); AddTestCase( MorLockV1Tests, L"Should not be able to set MORLock v1 with bad attributes", MorLockShouldNotSetBadAttributes, MorLockShouldNotBeSet, NULL, NULL ); // // NOTE: Strictly speaking, this isn't a good unit test. // After this test runs, the MorLock is set and the other tests // have some expectation that the lock will behave a certain way. // We *could* make better unit tests, but there would be a lot more // reboots. So let's say this is for efficiency. // AddTestCase( MorLockV1Tests, L"Should be able to set the v1 MORLock", MorLockv1ShouldBeLockable, MorLockShouldNotBeSet, NULL, NULL ); AddTestCase( MorLockV1Tests, L"Should report version correctly when locked with MORLock v1", MorLockv1ShouldReportCorrectly, NULL, NULL, NULL ); AddTestCase( MorLockV1Tests, L"Should not be able to change the MOR control when locked with MORLock v1", MorControlShouldNotChange, MorLockv1ShouldReportCorrectly, NULL, NULL ); AddTestCase( MorLockV1Tests, L"Should not be able to change the MORLock when locked with MORLock v1", MorLockv1ShouldNotChangeWhenLocked, MorLockv1ShouldReportCorrectly, NULL, NULL ); AddTestCase( MorLockV1Tests, L"Should not be able to delete the MORLock when locked with MORLock v1", MorLockv1ShouldNotBeDeleteable, MorLockv1ShouldReportCorrectly, NULL, NULL ); AddTestCase( MorLockV1Tests, L"MORLock v1 should clear after reboot", MorLockShouldClearAfterReboot, MorLockv1ShouldReportCorrectly, NULL, NULL ); // // Populate the MorLockV2Tests Unit Test Suite. // Status = CreateUnitTestSuite( &MorLockV2Tests, Fw, L"MORLock v2 Tests", NULL, NULL ); if (EFI_ERROR( Status )) { DEBUG((DEBUG_ERROR, "Failed in CreateUnitTestSuite for MorLockV2Tests\n")); Status = EFI_OUT_OF_RESOURCES; goto EXIT; } AddTestCase( MorLockV2Tests, L"Should be able to change MOR control when not locked", MorControlShouldChangeWhenNotLocked, MorControlVariableShouldBeCorrect, NULL, NULL ); AddTestCase( MorLockV2Tests, L"Should not be able to set MORLock v2 with buffer too small", MorLockv2ShouldNotSetSmallBuffer, MorLockShouldNotBeSet, NULL, NULL ); AddTestCase( MorLockV2Tests, L"Should not be able to set MORLock v2 with buffer too large", MorLockv2ShouldNotSetLargeBuffer, MorLockShouldNotBeSet, NULL, NULL ); AddTestCase( MorLockV2Tests, L"Should not be able to set MORLock v2 without a key", MorLockv2ShouldNotSetNoBuffer, MorLockShouldNotBeSet, NULL, NULL ); AddTestCase( MorLockV2Tests, L"Should not be able to set MORLock v2 with bad attributes", MorLockShouldNotSetBadAttributes, MorLockShouldNotBeSet, NULL, NULL ); // // NOTE: Strictly speaking, this isn't a good unit test. // After this test runs, the MorLock is set and the other tests // have some expectation that the lock will behave a certain way. // We *could* make better unit tests, but there would be a lot more // reboots. So let's say this is for efficiency. // AddTestCase( MorLockV2Tests, L"Should be able to set the v2 MORLock", MorLockv2ShouldBeLockable, MorLockShouldNotBeSet, NULL, NULL ); AddTestCase( MorLockV2Tests, L"Should report version correctly when locked with MORLock v2", MorLockv2ShouldReportCorrectly, NULL, NULL, NULL ); AddTestCase( MorLockV2Tests, L"Should only return one byte when reading MORLock v2", MorLockv2ShouldOnlyReturnOneByte, MorLockv2ShouldReportCorrectly, NULL, NULL ); AddTestCase( MorLockV2Tests, L"Should not return the key contents when locked with MORLock v2", MorLockv2ShouldNotReturnKey, MorLockv2ShouldReportCorrectly, NULL, NULL ); AddTestCase( MorLockV2Tests, L"Should not be able to change the MOR control when locked with MORLock v2", MorControlShouldNotChange, MorLockv2ShouldReportCorrectly, NULL, NULL ); AddTestCase( MorLockV2Tests, L"Should not be able to change the key when locked with MORLock v2", MorLockv2ShouldNotChangeWhenLocked, MorLockv2ShouldReportCorrectly, NULL, NULL ); AddTestCase( MorLockV2Tests, L"Should not be able to change to MORLock v1 when locked with MORLock v2", MorLockv2ShouldNotChangeTov1, MorLockv2ShouldReportCorrectly, NULL, NULL ); AddTestCase( MorLockV2Tests, L"Should not be able to delete the MORLock when locked with MORLock v2", MorLockv2ShouldNotBeDeleteable, MorLockv2ShouldReportCorrectly, NULL, NULL ); AddTestCase( MorLockV2Tests, L"MORLock v2 should clear after reboot", MorLockShouldClearAfterReboot, MorLockv2ShouldReportCorrectly, NULL, NULL ); // // End of tests that assume precedence. // From here on, each test is isolated and will clean up after itself. // AddTestCase( MorLockV2Tests, L"MORLock v2 should clear with a correct key", MorLockv2ShouldClearWithCorrectKey, MorLockShouldNotBeSet, UnitTestCleanupReboot, NULL ); AddTestCase( MorLockV2Tests, L"MORLock v2 should not clear with an incorrect key", MorLockv2ShouldNotClearWithWrongKey, MorLockShouldNotBeSet, UnitTestCleanupReboot, NULL ); AddTestCase( MorLockV2Tests, L"Should be able to change MOR control after setting and clearing MORLock v2", MorLockv2ShouldReleaseMorControlAfterClear, MorLockShouldNotBeSet, UnitTestCleanupReboot, NULL ); AddTestCase( MorLockV2Tests, L"Should be able to change keys by setting, clearing, and setting MORLock v2", MorLockv2ShouldSetClearSet, MorLockShouldNotBeSet, UnitTestCleanupReboot, NULL ); // // Execute the tests. // TestsRun = TRUE; Status = RunAllTestSuites( Fw ); EXIT: if (TestsRun) { PrintUnitTestReport( Fw ); } if (Fw) { FreeUnitTestFramework( Fw ); } return Status; }
ef3daaca929bc2cf7239602c21e029e2799941f2
030388c2841d57747772f3403fa4ae4abaa49464
/CPD/Machine/mySimpleComputer.c
3dc3e63da5e4d697fa8715b111151f73c5ec81f6
[]
no_license
Sniper552/Progs
23de1ccbe30571dd65398484f487a80995bfc0a7
8faf9ceedd7f1d630c0325d004b437e0cd42d865
refs/heads/master
2023-05-01T07:33:30.636348
2020-07-30T10:11:25
2020-07-30T10:11:25
null
0
0
null
null
null
null
UTF-8
C
false
false
13,740
c
mySimpleComputer.c
#include "mySimpleComputer.h" // Инициализация памяти машины SimpleComputer (всего 100 ячеек) int sc_memoryInit() { // Цикл, инициализирующий 100 ячеек памяти нулями for (int i = 0; i < 100; i++) memory[i] = 0; return 0; } // Назначить новое значение для ячейки памяти. // В качестве первого аргумента - номер ячейки (от 0 до 99), // в качестве второго аргумента - новое значение int sc_memorySet(int address, int value) { // Если введен недопустимый номер ячейки if (address < 0 || address > 99) { // Перевести регистр "Выход за пределы памяти" в значение 1 sc_regSet(REG_MEMOUTSIDE, 1); // Вызов внешней функции, которая графически изменит значение регистра updateFlag(REG_MEMOUTSIDE); // Вернуть -1 (функция завершена с ошибкой) return -1; } // Если новое значение (которое по условию задания является 15 разрядным двоичным числом) // выходит за рамки 15 разрядов (0x7FFF(16) -> 111 1111 1111 1111(2)), то завершаем функцию с ошибкой. if (value > 0x7FFF) { // Перевести регистр "Переполнение" в значение 1 sc_regSet(REG_OVERFLOW, 1); // Вызов внешней функции, которая графически изменит значение регистра updateFlag(REG_OVERFLOW); // Вернуть -1 (функция завершена с ошибкой) return -1; } // Назначить значение (value) в ячейку по адресу (address) memory[address] = value; // Графически обновить содержимое ячейки по адресу address updateMemory(address); // Функция завершена успешно return 0; } // Получить значение ячейки по адресу (address) в переменную по адресу (value) int sc_memoryGet(int address, int *value) { // Если введен некорректный адрес, завершаем функцию с ошибкой, // переведя регистр "Выход за пределы памяти" в активное состояние if (address < 0 || address > 99) { // Перевести регистр "Выход за пределы памяти" в активное состояние" sc_regSet(REG_MEMOUTSIDE, 1); // Вернуть -1 (функция завершена с ошибкой) return -1; } // В переменную по адресу (value) заносим значение ячейки по адресу (address) *value = memory[address]; // Функция завершена успешно return 0; } // Сохранить содержимое памяти в бинарный файл int sc_memorySave(char *filename) { //int file = open(filename, O_WRONLY | O_EXCL | O_CREAT, S_IRWXU | S_IRWXO); // Открыть файл с названием (filename) для записи (0664 - флаг доступа, который содержит в себе требования к // записи файла с нуля, бинарная запись) int file = creat(filename, 0664); // Записать в файл по дескриптору (file) содержимое массива (memory), записать 100 записей этого массива, где каждая ячейка // имеет размер (short int) write(file, memory, 100 * sizeof(short int)); // Закрыть дескриптор по адресу (file). Просто закрыть файл close(file); // Функция завершена успешно return 0; } // Загрузить содержимое файла под названием (filename) в массив (memory) int sc_memoryLoad(char *filename) { // Открыть файл с правами доступа (O_RDONLY) - только чтение. int file = open(filename, O_RDONLY); // Если дескриптор равен -1, то не смогли открыть файл (не найден, нет доступа), завершаем функцию с ошибкой if (file == -1) return -1; // Считываем содержимое в массив (memory). С файла считывается 100 значений, где каждая область имеет размер (short int). read(file, memory, 100 * sizeof(short int)); // Закрыть дескриптор по адресу (file). Просто закрыть файл close(file); // Функция завершена успешно return 0; } // Вывести содержимое памяти. В курсовой не используется, было необходимо в лабораторных работах. void sc_memoryPrint(void) { int value; for (int i = 0; i < 100; i++) { sc_memoryGet(i, &value); printf("%d\t%s", value, ((i + 1) % 10 == 0) ? "\n" : ""); } } // Инициализация регистров int sc_regInit(void) { // Всего есть 5 регистров // (выход за пределы памяти, неизвестная команда, ошибка деления на ноль, переполнение, игнорирование тактовых импульсов). // Каждый регистр либо активен, либо нет. // Для хранения состояния отдельного регистра используется одна переменная (regs). // Активность отдельного регистра определяется наличием единичного бита в двоичной записи этой переменной. // То есть, имеется запись (regs) следующего вида - 00000ХХХХХ(2 система счисления). // Последние иксы определяют активность того или иного регистра. // Например, если самый крайний правый регистр содержит единицу, это значит, что регистр REG_MEMOUTSIDE (выход за пределы памяти) - активен. // mySimpleComputer.h содержит порядковый номер каждого регистра: // #define REG_MEMOUTSIDE 0x0 // #define REG_UNKNOWNCOMMAND 0x1 // #define REG_DIVIDEZERO 0x2 // #define REG_OVERFLOW 0x3 // #define REG_CLOCKIGNORE 0x4 // Эти номера значат, что самый крайний правый бит в (regs) отвечает за регистр выхода за пределы памяти, // за ним следует регистр неизвестной команды и т.д. // Все регистры изначально - неактивны. Инициализируем нулем regs = 0; // Функция завершена успешно. return 0; } // Перевести регистр (reg) в состояние (value) int sc_regSet(int reg, int value) { // Если передан неверный регистр или неверное значение, то завершаем функцию с ошибкой if (reg < 0 || reg > REG_MAX || value < 0 || value > 0x1) { return -1; } // Если новое значение регистра (reg) единица, то "создаем" новое число, где единица побитово сдвинута на (reg) шагов влево, // и побитово складываем это число с (regs). // То есть, имеется изначально такое содержимое (regs): 00...00000. Мы хотим назначить регистр REG_DIVIDEZERO - активным. // Для этого создаем число 00...00100 (где единица сдвинута на две позиции влево в соответствием со значением REG_DIVIDEZERO). // И затем побитово складываем (regs) и это число, получается 00...00100. Если захотим назначить активным регистром REG_CLOCKIGNORE, // то нужно новое число будет иметь вид 00...10000. Сложив с (regs) получится число 00...10100. if (value == 1) regs |= (1 << reg); // Если новое содержимое регистра (reg) ноль, то "создаем" новое число, где на месте нужного регистра стоит ноль, а остальные разряды // этого числа - единицы. Затем с этим числом проводится побитовое "И" с переменной (regs). // Чтобы "создать" такое число, нужно сначала сформировать, как выше, число для нужного регистра и затем его инвертировать. То есть, // в случае регистра REG_CLOCKIGNORE создается число 00...10000, затем оно инвертируется в 11...01111. Затем оно побитово перемножается // с переменной (regs). Было 00...0010100, стало 00...00100 else if (value == 0) regs &= (~(1 << reg)); // Графически обновить регистр updateFlag(reg); // Функция завершена успешно return 0; } // Получить содержимое регистра (reg) в переменную по адресу (value) int sc_regGet(int reg, int *value) { // Если указан неверный регистр, то завершаем функцию с ошибкой if (reg < 0 || reg > REG_MAX) { return -1; } // Если нужный регистр активен, то содержимое переменной (value) будет равно единице. Чтобы выявить активность регистра Х нужно сделать следующее: // 1) 01Х00 // 2) 0100Х // 3) 0000Х // То есть, нужно сдвинуть нужный регистр в крайнее правое положение, а затем побитово умножить на единицу, чтобы избавиться от содержимого // других регистров. *value = (regs >> reg) & 0x1; // Функция завершена успешно return 0; } // Закодировать команду. Каждая ячейка памяти имеет вид: // // 0 | 0110011 | 1011001 <------ // + | 33(16) | 59(16) // ----------------------------- // признак | код | операнд // команды | операции| // // как видно, первые 7 бит - это операнд, затем следует 7 бит - операция, затем еще 1 бит - признак того, что в данной ячейке содержится команда // На вход этой функции подается номер операции и операнд, которые являются 7 битными числами. int sc_commandEncode(int command, int operand, int *value) { // Если операция или операнд выходят за пределы 7 бит, то завершаем функцию с ошибкой. if (command < 0 || command > 0x7F || operand < 0 || operand > 0x7F) { return -1; } // В переменную по адресу (value) заносим первые 7 бит - операнд *value = operand; // Затем вносим операцию, предварительно сдвинув ее на 7 бит влево. *value |= command << 7; // Имеется операнд 000...0000000YYYYYYY. Необходимо к нему добавить операцию 000...0000000XXXXXXX. // Для этого, сдвигаем операцию на 7 бит влево, получая 000...XXXXXXX0000000. // И затем побитово складываем операцию и операнд: // 000...0000000YYYYYYY | // 000...XXXXXXX0000000 = // 000...XXXXXXXYYYYYYY // Функция завершена успешно return 0; } // Декодировать команду. Обратная функция кодированию команды. В функцию передается значение (value) (к примеру 000...XXXXXXXYYYYYYY), // после чего в переменные по адресам (command) и (operand) заносятся 000...XXXXXXX и 000...YYYYYYY соответственно. int sc_commandDecode(int value, int *command, int *operand) { // Если число имеет более 15 разрядов, то завершаем функцию с ошибкой. if (value > 0x7FFF) { return -1; } value = abs(value); // Для получения операции достаточно сдвинуть число на 7 разрядов вправо *command = value >> 7; // Для получения операнда нужно побитово умножить с 7 разрядным числом 1111111(2) -> 0x7F(16) *operand = value & 0x7F; // Функция завершена успешно return 0; }
e224e02e1efc7fed6942d591711556a70be64938
f7daf88cf26837da7292a359fecbeb7bc7e4390d
/RTV7/libft/ft_memcmp.c
f872aa3e723e43c02cc354c19d93174ca78f4a22
[]
no_license
psergean/42
6ca03e1e182eab4897968345b837fd00f395912d
faa4069c3293b8e1ef5b9506b709558865785905
refs/heads/master
2019-06-05T04:46:21.828066
2018-03-08T18:18:06
2018-03-08T18:18:06
73,694,649
0
0
null
null
null
null
UTF-8
C
false
false
1,198
c
ft_memcmp.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_memcmp.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: tzaaboul <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/04 12:01:58 by tzaaboul #+# #+# */ /* Updated: 2016/11/04 12:07:38 by tzaaboul ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" int ft_memcmp(const void *s1, const void *s2, size_t n) { size_t i; unsigned char *cmp1; unsigned char *cmp2; cmp1 = (unsigned char *)s1; cmp2 = (unsigned char *)s2; i = 0; while (i < n) { if (cmp1[i] != cmp2[i]) return (cmp1[i] - cmp2[i]); i++; } return (0); }
cfbaf3199b044bdbbfdf0439b5a35df08fed92ec
537e89998cf95e7c01a53f5e54baadfeed226c48
/linked_lists/ft_list_last.c
1fa5a9716b70a37069dbee7d8470e346fb2de05d
[]
no_license
GeoffLyle/c_functions
468366c356db6d98901b3978e842f7819d15d9ed
6c536e2922c8ce863bbe54f1f008eeff1ed294e9
refs/heads/master
2021-04-12T07:52:05.671156
2018-04-04T00:58:54
2018-04-04T00:58:54
125,798,536
0
0
null
null
null
null
UTF-8
C
false
false
1,116
c
ft_list_last.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_list_last.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: alyle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2018/03/27 16:45:00 by alyle #+# #+# */ /* Updated: 2018/03/27 16:53:40 by alyle ### ########.fr */ /* */ /* ************************************************************************** */ #include "ft_list.h" t_list *ft_list_last(t_list *begin_list) { t_list *last; last = begin_list; if (begin_list) { while (begin_list->next) begin_list = begin_list->next; last = begin_list; } return (last); }
424a48882e51fcd1e860f3e8a46e76106994e960
324a1c017043dc8bada9e4c7da845d557de14892
/src/ft_bzero.c
557c92c933599362b3ac5702bbe5c9916db4b4a3
[]
no_license
Odie8683/libft
a3087e9947e7056dab1ad6f6ce6877880277e3fa
9a0d9f7148ff40c1c475841a55188745c91676ac
refs/heads/main
2023-08-02T04:32:22.009869
2021-10-03T13:58:22
2021-10-03T13:58:22
null
0
0
null
null
null
null
UTF-8
C
false
false
163
c
ft_bzero.c
#include "../include/libft.h" void ft_bzero(void *s, size_t n) { unsigned char *temp; temp = (unsigned char *)s; while (n) { *(temp + n) = '\0'; n--; } }
7af214dfca5d079e184a536b00cdad254d1de17f
e10b6107828aa558853c1f1bdb74ab7e7f5b90bb
/display/SSD1306.h
11d41d628e419ba1e8c04489bd8610c9ea7544ef
[]
no_license
exosite/er_plat_microchip_pic32mzecsk
025e08e8ee6adce09720784386273217c9140293
7801da8f7ac6562e627af6a84588d9740f216419
refs/heads/master
2021-06-01T03:47:14.136421
2016-06-30T18:18:14
2016-06-30T18:18:14
null
0
0
null
null
null
null
UTF-8
C
false
false
6,508
h
SSD1306.h
/**The MIT License (MIT) Copyright (c) 2015 by Daniel Eichhorn 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. See more at http://blog.squix.ch Credits for parts of this code go to Mike Rankin. Thank you so much for sharing! */ #pragma once #define LINE1 17 #define LINE2 28 #define BLACK 0 #define WHITE 1 #define INVERSE 2 #define WIDTH_POS 0 #define HEIGHT_POS 1 #define FIRST_CHAR_POS 2 #define CHAR_NUM_POS 3 #define CHAR_WIDTH_START_POS 4 #define TEXT_ALIGN_LEFT 0 #define TEXT_ALIGN_CENTER 1 #define TEXT_ALIGN_RIGHT 2 #define CHARGEPUMP 0x8D #define COLUMNADDR 0x21 #define COMSCANDEC 0xC8 #define COMSCANINC 0xC0 #define DISPLAYALLON 0xA5 #define DISPLAYALLON_RESUME 0xA4 #define DISPLAYOFF 0xAE #define DISPLAYON 0xAF #define EXTERNALVCC 0x1 #define INVERTDISPLAY 0xA7 #define MEMORYMODE 0x20 #define NORMALDISPLAY 0xA6 #define PAGEADDR 0x22 #define SEGREMAP 0xA0 #define SETCOMPINS 0xDA #define SETCONTRAST 0x81 #define SETDISPLAYCLOCKDIV 0xD5 #define SETDISPLAYOFFSET 0xD3 #define SETHIGHCOLUMN 0x10 #define SETLOWCOLUMN 0x00 #define SETMULTIPLEX 0xA8 #define SETPRECHARGE 0xD9 #define SETSEGMENTREMAP 0xA1 #define SETSTARTLINE 0x40 #define SETVCOMDETECT 0xDB #define SWITCHCAPVCC 0x2 #define SSD1306_96_39 #define SSD1306_LCDWIDTH 96 #define SSD1306_LCDHEIGHT 39 #define SSD1306_DISPLAYOFF 0xAE #define SSD1306_SETDISPLAYCLOCKDIV 0xD5 #define SSD1306_SETMULTIPLEX 0xA8 #define SSD1306_SETDISPLAYOFFSET 0xD3 #define SSD1306_SETSTARTLINE 0x40 #define SSD1306_CHARGEPUMP 0x8D #define SSD1306_SETSEGMENTREMAP 0xA1 // ja #define SSD1306_SEGREMAP 0xA0 #define SSD1306_COMSCANDEC 0xC8 #define SSD1306_SETCOMPINS 0xDA #define SSD1306_SETCONTRAST 0x81 #define SSD1306_SETPRECHARGE 0xD9 #define SSD1306_SETVCOMDETECT 0xDB #define SSD1306_DISPLAYALLON_RESUME 0xA4 #define SSD1306_NORMALDISPLAY 0xA6 #define SSD1306_DISPLAYON 0xAF #define SSD1306_DISPLAYALLON 0xA5 #define SSD1306_INVERTDISPLAY 0xA7 #define SSD1306_SETLOWCOLUMN 0x00 #define SSD1306_SETHIGHCOLUMN 0x10 #define SSD1306_MEMORYMODE 0x20 #define SSD1306_COLUMNADDR 0x21 #define SSD1306_PAGEADDR 0x22 #define SSD1306_COMSCANINC 0xC0 #define SSD1306_SEGREMAP 0xA0 #define SSD1306_EXTERNALVCC 0x1 #define SSD1306_SWITCHCAPVCC 0x2 #define SSD1306_ACTIVATE_SCROLL 0x2F #define SSD1306_DEACTIVATE_SCROLL 0x2E #define SSD1306_SET_VERTICAL_SCROLL_AREA 0xA3 #define SSD1306_RIGHT_HORIZONTAL_SCROLL 0x26 #define SSD1306_LEFT_HORIZONTAL_SCROLL 0x27 #define SSD1306_VERTICAL_AND_RIGHT_HORIZONTAL_SCROLL 0x29 #define SSD1306_VERTICAL_AND_LEFT_HORIZONTAL_SCROLL 0x2A // uint8_t buffer[128 * 64 / 8]; // Create the display object connected to pin sda and sdc // Initialize the display void OLED_M_Init(); // Cycle through the initialization void resetDisplay(void); // Connect again to the display through I2C void reconnect(void); // Turn the display on void displayOn(void); // Turn the display offs void displayOff(void); // Clear the local pixel buffer void SSD1306_clearLine(unsigned char line); // Write the buffer to the display memory void display(void); // Set display contrast void setContrast(char contrast); // Turn the display upside down void flipScreenVertically(); // Send a command to the display (low level function) void sendCommand(unsigned char com); // Send all the init commands void sendInitCommands(void); // Draw a pixel at given position void setPixel(int x, int y); // Draw 8 bits at the given position void setChar(int x, int y, unsigned char data); // Draw the border of a rectangle at the given location void drawRect(int x, int y, int width, int height); // Fill the rectangle void fillRect(int x, int y, int width, int height); // Draw a bitmap with the given dimensions void drawBitmap(int x, int y, int width, int height, const char *bitmap); // Draw an XBM image with the given dimensions void drawXbm(int x, int y, int width, int height, const char *xbm); // Sets the color of all pixel operations void setColor(int color); // converts utf8 characters to extended ascii // taken from http://playground.arduino.cc/Main/Utf8ascii unsigned char utf8ascii(unsigned char ascii); // converts utf8 string to extended ascii // taken from http://playground.arduino.cc/Main/Utf8ascii //unsigned char utf8ascii(unsigned char * s); // Draws a string at the given location void SSD1306_drawString(int x, int y, unsigned char * text); // Draws a String with a maximum width at the given location. // If the given String is wider than the specified width // The text will be wrapped to the next line at a space or dash void SSD1306_drawStringMaxWidth(int x, int y, int maxLineWidth, unsigned char * text); // Returns the width of the String with the current // font settings int SSD1306_getStringWidth(unsigned char * text); // Specifies relative to which anchor point // the text is rendered. Available constants: // TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER, TEXT_ALIGN_RIGHT void setTextAlignment(int textAlignment); // Sets the current font. Available default fonts // defined in SSD1306Fonts.h: // ArialMT_Plain_10, ArialMT_Plain_16, ArialMT_Plain_24 void setFont(const char *fontData);
75c3541a50511a0eff717c32e92f02d8fe012c6f
7d3290ba6875a50c997645e8b46b70d3eed5dc9b
/Ex6/main.c
aa500ad669456bec5cd64d3cb47d600541333f76
[]
no_license
oriane17/ATI01
780b4b4022c71b6b3a8c3da4b955150402237715
f8cea3b02e17789fee0b92b4f794f39cfdb81203
refs/heads/master
2021-05-20T09:47:42.051458
2020-04-29T13:37:35
2020-04-29T13:37:35
252,233,128
0
0
null
null
null
null
UTF-8
C
false
false
414
c
main.c
//SAVIO Oriane #include <stdio.h> #include <stdlib.h> #include "palindrome.h" int main(int argc, char **argv, char **envv){ point_t chaine; sprintf((char*)chaine.message, "%s", argv[1]); chaine.longueur=longueur_chaine (chaine.message); for (int i=0; i<chaine.longueur; i++) { chaine.mirroir[i]=chaine.message[i]; } mirror (&chaine); palindrome (&chaine); return 0; }
5b48578169d39bede4b5cb41628c8fce23ced091
9fe4cb3b456ae18e247ad515187461035172df0b
/include/task6.h
740020d729b61806ac5197df1ab7085d21315eee
[]
no_license
tatyanashashalina/C-lab-6
14449a5dc4b1aa7eac99fe99572d001412989d7e
265cc84e338c576a56ac63afb66a284534f76579
refs/heads/master
2021-01-14T22:07:33.617643
2020-02-24T17:19:59
2020-02-24T17:19:59
242,774,762
0
0
null
2020-02-24T15:42:12
2020-02-24T15:42:11
null
WINDOWS-1251
C
false
false
196
h
task6.h
// Clab6 task6 #include <stdio.h> #include <stdlib.h> #include <time.h> #define SIZE 40 unsigned long long fib2(int N); // нахождение N - ого члена ряда Фибоначчи
9acc2c1799c7f3de4e8407929cf8690ee56c3865
89afd8f4d2c8512ff44f17f1fd3ebec3889ba2f0
/410/pebp3-master 2/kern/syscall/exec/exec.h
327a38adc2ca50be9a33026d38e6ed82310d5f04
[]
no_license
subnr01/Algorithms
409ff153d638fdc0aca0867d38b4b86a4e4327d4
1571b55ea58bda1e474cda72504e92bba83e2cd2
refs/heads/master
2021-03-30T18:01:38.427382
2017-02-20T12:25:01
2017-02-20T12:25:01
24,578,737
0
0
null
null
null
null
UTF-8
C
false
false
325
h
exec.h
/** @file exec.h * @brief The exec syscall kernel handler * * This is exec syscall kernel handler header file. * * @author Hongchao Deng (hongchad) * @bug now known bugs. */ #ifndef _EXEC_H #define _EXEC_H #include <stdint.h> void exec_wrapper(); int exec_handler(uintptr_t args); #endif // for #ifndef _EXEC_H
e559eb15f77cd93f68a7fe789895ec91bb5f076e
4e298b59e91f9088f36e9c488eb8c062b8a16c07
/open/main/room/M11a.c
c062f9b8e7b229faa3a2abaec072539dfd506078
[]
no_license
HexColors60/fs2
07714b1dbd27d666febf7ccc5e8d3476edaf0146
c1bc56122142ac741d2432551508d04c9be4694e
refs/heads/master
2021-05-27T11:06:07.272106
2012-08-03T04:15:15
2012-08-03T04:15:15
null
0
0
null
null
null
null
GB18030
C
false
false
402
c
M11a.c
// Room: /open/main/room/M11a.c inherit ROOM; void create() { set("light_up",1); set("short", "环山长廊"); set("long", @LONG 距离那火光越来越近了,但却感觉不到那火热的气息, 反而是给人一种祥和的感觉,令人觉得十分的温暖。 LONG ); set("exits", ([ /* sizeof() == 2 */ "westup" : __DIR__"M10", "eastdown" : __DIR__"M12b", ])); setup(); }
af113c2fcdfb5d90a3db7e65e8e5717382df8151
3d70e4adfe1909628ca05536f3bbe11d629e73fe
/Parser/util.h
f87180c688420067e4b66e0e2eb6260d141ec9f1
[]
no_license
StudentJeffRen/Parser
c88be5072b5321a15eb387de21cc80ffb7916c43
fbbb1c9967aeb0ae873ea9ae4a1555db37f1399f
refs/heads/master
2020-11-28T23:47:16.857616
2019-12-31T08:19:36
2019-12-31T08:19:36
229,952,766
0
0
null
null
null
null
UTF-8
C
false
false
1,157
h
util.h
/****************************************************/ /* File: util.h */ /* The interface of general tools for the */ /* C-Minus compiler */ /* Programming designed by Zhiyao Liang */ /* MUST 2016 Fall */ /****************************************************/ #ifndef _UTIL_H_ #define _UTIL_H_ #include "libs.h" typedef enum{ FALSE, TRUE }Boolean; /* Print the message msg, then wait for the user to hit the enter/return key. * The input queue is cleared before this function returns. */ void pause_msg(const char * msg); /* <Parameter:> * str: a character string. * <Return:> * A copy (a clone) of the input string str, including the ending '\0'. The space of the clone does not overlap with the space of str. * */ char * string_clone(const char* str); void clear_input_queue(void); void *checked_malloc(int len); int read_file_to_char_array( char * array, int arrayLength, FILE * stream); char * clone_string_section(const char * str, int begin, int end); #endif
b97444320114e01b4e67a3f8bdbe9af5f6e3da4c
d4ee6b6d9799b65173671ddba61f912c13a64e5e
/sender2.c
867868e2f39b29b7be5d825307156f06c92d3c69
[]
no_license
akcorp2003/CS118---Project-2
f5eda063b04f0fdf4161883ff14546ce5802bbbd
a262ba94ba459dc4c6c41ddc1430bdc73f5dae85
refs/heads/master
2016-08-12T07:03:24.099282
2015-12-02T05:13:26
2015-12-02T05:13:26
46,602,527
0
1
null
2015-11-21T18:54:18
2015-11-21T05:24:40
C
UTF-8
C
false
false
8,015
c
sender2.c
#include <stdio.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <stdlib.h> #include <strings.h> #include <string.h> #include <sys/wait.h> #include <signal.h> #include <errno.h> static int maxPacketSize = 30; static int headerLen = 20; static int packetBufferSize = 100; int timeout = 0; int fileRequest = 1; int dur = 8; struct Header { short srcPort; short destPort; int seq; int ack; short dataLen; short checkSum; int flag; }; void error(char *msg) { perror(msg); exit(1); } int isHit(int prob) { if (prob == 0) return 0; int num = rand() % 100; printf("%d\n", num); if (num < prob) return 1; return 0; } void setTimeout(int signum) { timeout = 1; printf("SIGNAL RECEIVED\n"); } int getAck(char * buffer) { struct Header packet; memcpy((struct Header *) &packet, buffer, headerLen); return packet.ack; } int getDataLen(char * buffer) { struct Header packet; memcpy((struct Header *) &packet, buffer, headerLen); return (int)packet.dataLen; } void getFileName(char * buffer, char * filename) { struct Header packet; memcpy((struct Header *) &packet, buffer, headerLen); memcpy(filename, buffer + headerLen, packet.dataLen); } void printPacket(char * packet) { struct Header pktHeader; memcpy((struct Header *) &pktHeader, packet, headerLen); printf("srcPort: %d\ndestPort: %d\nseq: %d\n", pktHeader.srcPort, pktHeader.destPort, pktHeader.seq); printf("ack: %d\ndataLen: %d\ncheckSum: %d\n", pktHeader.ack, pktHeader.dataLen, pktHeader.checkSum); printf("flag: %d\n", pktHeader.flag); printf("%s", packet + headerLen); printf("\n"); } int main(int argc, char *argv[]) { double probLoss, probCorruption; int sockfd, newsockfd, portno, pid, CWnd; socklen_t clilen; struct sockaddr_in serv_addr, cli_addr; struct Header packetHeader; struct sigaction sa; time_t t; srand((unsigned)time(&t)); if (argc < 5) { fprintf(stderr, "ERROR, missing argument\n"); exit(1); } CWnd = atoi(argv[2]); probLoss = atoi(argv[3]); probCorruption = atoi(argv[4]); sockfd = socket(AF_INET, SOCK_DGRAM, 0); if (sockfd < 0) error("ERROR opening socket"); memset(&serv_addr, 0, sizeof(serv_addr)); portno = atoi(argv[1]); serv_addr.sin_family = AF_INET; serv_addr.sin_addr.s_addr = INADDR_ANY; serv_addr.sin_port = htons(portno); if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) error("ERROR on binding"); int n, loss = 0, corruption = 0, base = 0, nextSeqnum = 0, seq = 0, ack = 0, numUnacked = 0, i, j, k, len, cumAck, sizeCliAddr; char buffer[1024]; char packetBuffer[packetBufferSize][maxPacketSize + 1]; int nxtPtr = 0, nxtFree = 0, count = 0; char unacked[CWnd][maxPacketSize + 1]; struct Header recvAck, data; char filename[1024]; FILE * fp; char packet[maxPacketSize + 1]; int cur; //col 1: 0 unacked, 1 acked or unused //col 2: window seq num //col 3: expected ack int window[CWnd][3]; memset(packet, 0, sizeof(packet)); for (i = 0; i < CWnd; i++) { window[i][0] = 1; window[i][1] = 0; window[i][2] = 0; } memset((struct sigaction *) &sa, 0, sizeof(sa)); sa.sa_handler = setTimeout; sa.sa_flags = SA_SIGINFO; sigaction(SIGALRM, &sa, NULL); while (1) { memset(buffer, 0, 1024); // read if timeout has not occured if (timeout != 1) { sizeCliAddr = sizeof(cli_addr); n = recvfrom(sockfd, buffer, sizeof(buffer), 0, (struct sockaddr *) &cli_addr, &sizeCliAddr); } else errno = EINTR; if (errno == EINTR) { if (timeout == 1) { timeout = 0; k = base + CWnd; for (i = base; i < k; i++) for (j = 0; j < CWnd; j++) if (window[j][0] == 0 && window[j][1] == i) { n = sendto(sockfd, unacked[j], sizeof(unacked[j]), 0, (struct sockaddr *) &cli_addr, sizeof(cli_addr)); if (n < 0) error("ERROR reading from socket"); printf("\nPacket Sent: \n"); printPacket(unacked[j]); break; } alarm(dur); errno = 0; continue; } else error("ERROR reading from socket"); } else if (n < 0) error("ERROR reading from socket"); // if no loss or corruption loss = isHit(probLoss); corruption = isHit(probCorruption); if (loss != 1 && corruption != 1) { // if client asks for file if (getDataLen(buffer) > 0) { printPacket(buffer); memset(filename, 0, 1024); getFileName(buffer, filename); printf("File Requested: %s\n", filename); fp = fopen(filename, "r"); if (fp == NULL) error("Failed to open file"); cur = fgetc(fp); len = 0; data.srcPort = ntohs(serv_addr.sin_port); data.destPort = ntohs(cli_addr.sin_port); data.ack = 0; data.flag = 0; i = headerLen; while (1) { if (len < maxPacketSize - headerLen && cur != EOF) { packet[i] = (char)cur; cur = fgetc(fp); len++; i++; } if (len == maxPacketSize - headerLen || cur == EOF) { data.seq = seq; data.dataLen = (short)len; data.checkSum = (short)1; if (cur == EOF) data.flag = 1; memcpy(packet, (struct Header *) &data, headerLen); if (nextSeqnum < base + CWnd) { for (i = 0; i < CWnd; i++) if (window[i][0] == 1) { window[i][0] = 0; window[i][1] = nextSeqnum; window[i][2] = ack + len; n = sendto(sockfd, packet, sizeof(packet), 0, (struct sockaddr *) &cli_addr, sizeof(cli_addr)); if (n < 0) error("ERROR writing to socket"); if (nextSeqnum == base) alarm(dur); printf("\nPacket sent:\n"); printPacket(packet); memcpy(&unacked[i][0], &packet[0], sizeof(packet)); seq += len; ack += len; i = headerLen; len = 0; nextSeqnum++; break; } } else { memcpy(packetBuffer[nxtFree], packet, maxPacketSize); nxtFree++; count++; len = 0; i = headerLen; } memset(packet, 0, sizeof(packet)); if (cur == EOF) { data.flag = 0; break; } } } fclose(fp); fileRequest = 0; } // if client sends ACK else { printf("\nPacket Received:\n"); printPacket(buffer); cumAck = getAck(buffer); j = 0; for (i = 0; i < CWnd; i++) { if (window[i][1] >= base && cumAck >= window[i][2] && window[i][0] == 0) { j++; window[i][0] = 1; if (window[i][1] == base) alarm(dur); if (count > 0) { count--; memcpy((struct Header *) &data, packetBuffer[nxtPtr], headerLen); data.seq = seq; memcpy(packetBuffer[nxtPtr], (struct Header *) &data, headerLen); n = sendto(sockfd, packetBuffer[nxtPtr], sizeof(packetBuffer[nxtPtr]), 0, (struct sockaddr *) &cli_addr, sizeof(cli_addr)); if (n < 0) error("ERROR writing to socket"); printf("\nPacket sent:\n"); printPacket(packetBuffer[nxtPtr]); for (i = 0; i < CWnd; i++) if (window[i][0] == 1) { window[i][0] = 0; window[i][1] = nextSeqnum; window[i][2] = ack + getDataLen(packetBuffer[nxtPtr]); memcpy(&unacked[i][0], packetBuffer[nxtPtr], sizeof(packetBuffer[nxtPtr])); seq += getDataLen(packetBuffer[nxtPtr]); ack += getDataLen(packetBuffer[nxtPtr]); nextSeqnum++; break; } nxtPtr = (nxtPtr + 1) % packetBufferSize; nxtFree = (nxtFree + 1) % packetBufferSize; } } } base += j; } } // if loss or corruption do nothing else { if (loss == 1 && corruption == 0) printf("Packet Lost:\n"); else if (corruption == 1 && loss == 0) printf("Packet Corrupted:\n"); else printf("Packet Corrupted and Lost:\n"); loss = 0; corruption = 0; printPacket(buffer); } } close(sockfd); return 0; }
95a58c386518473b87d6ef7a8d101227b93801aa
51686bfd5f1ba6864500fb2027e6ae1ff383b477
/redis-net2.0/anet/include/connction.h
7b9b9aa17340c1581038d092ba8342a5bb8d048d
[]
no_license
dingqinghui/network
2549d6e01fb8fc6ec5ce1b91d39fae41f1428c8d
22b88c55502671cf4e55a62f6033e06c2844a76f
refs/heads/master
2023-04-12T03:05:56.271199
2021-05-18T06:45:56
2021-05-18T06:45:56
261,646,115
1
0
null
null
null
null
UTF-8
C
false
false
721
h
connction.h
#ifndef __CONNECTION_H__ #define __CONNECTION_H__ #define CON_INIT 1 #define CON_CONNECTING 2 #define CON_CONNECTED 3 #define CON_BUF_MAX_LEN 65535 typedef struct connection { int fd; char* sbuffer; //send cache char* rbuffer; //read cache int css; //cur send size int crs; //cur read size }connection; connection* connectionCreate(int fd); void connectionFree(connection* con); int getReadBuf(connection* con,char* buf); int setReadBuf(connection* con,char* buf,int size); int connectionGetSendBuf(connection* con,char* buf); int connectionWriteSendBuf(connection* con,char* buf,int size); void connectionSetSendBufSize(connection* con,int size); #endif
57e22be39834573db8d16ff6fbd339925f5496ab
ffb8be31a1a364ccf4d7ff0324c2827b9f5a65d4
/week10_1_pointers/03.access-pointer-values.c
8a5a6aa5dea0f158abfa6a7389d1bccd5323d08d
[]
no_license
jigmetnamgyal/c-learn
9fc1a80b11da18974bfeb60134180a6e3631d676
8ad284674cb15a7e340b6027d19c50bba9db4662
refs/heads/master
2023-03-01T12:16:24.944754
2021-02-13T11:24:53
2021-02-13T11:24:53
338,558,644
1
0
null
null
null
null
UTF-8
C
false
false
996
c
03.access-pointer-values.c
#include <stdio.h> int main () { int num = 5; /* actual variable declaration */ int *p; /* pointer variable declaration */ p = &num; /* store address of num in pointer variable*/ printf("Address of num: %p\n", &num ); /* address stored in pointer variable */ printf("Address stored in p: %p\n", p ); /* access the value using the pointer */ printf("Value of *p : %d\n", *p ); // 5 *p = 7; /* access the value using the pointer */ printf("Value of *p : %d\n", *p); // 7 printf("Value of num: %d\n", num); // 7 int arr[3] = { 2, 5, 8 }; printf("Value of arr[0] = *arr : %d\n", *arr); // 2 printf("Value of arr[1] = *(arr+1) : %d\n", *(arr + 1)); // 5 printf("Value of arr[2] = *(arr+2) : %d\n", *(arr + 2)); // 8 int* pa = &arr; printf("Value of arr[0] = *pa : %d\n", *pa); // 2 pa++; printf("Value of arr[1] = *pa : %d\n", *pa); // 5 pa++; printf("Value of arr[2] = *pa : %d\n", *pa); // 8 return 0; }
1b15756ec6eddd89b781cf0a7f188e3a68aa476e
795a5dc1f37ba06f926f4bb25dade31abda3bdbe
/save/fft_correlation.C
32e65b0fc582494799d26ee060b7fa6209a84dd2
[]
no_license
zatserkl/macros
ade96a700a8ec6ee7ca05e0688d29d7ef6aec3e7
66d55d8e35253cf715da1e7e174150fec525d6aa
refs/heads/master
2020-12-24T10:31:31.466408
2018-06-04T17:46:53
2018-06-04T17:46:53
73,147,268
0
0
null
null
null
null
UTF-8
C
false
false
5,709
c
fft_correlation.C
#include <TROOT.h> #include <TFile.h> #include <TTree.h> #include <TGraph.h> #include <TCanvas.h> #include <TMath.h> #include <iostream> #include <cassert> using std::cout; using std::endl; void fft_inverse(const Int_t N, Double_t reX[], Double_t imX[], Double_t x[]) { assert(N%2 == 0); //-- Double_t x[N]; // amplitudes in the time domain == time samples Double_t reXX[N/2+1]; // scaled Re amplitudes in the frequency domain = frequency samples Double_t imXX[N/2+1]; // scaled Im amplitudes in the frequency domain = frequency samples for (int k=0; k<N/2+1; ++k) { reXX[k] = reX[k]/(N/2); imXX[k] = -1.*imX[k]/(N/2); } reXX[0] /= 2; reXX[N/2] /= 2; for (int isample=0; isample<N; ++isample) x[isample] = 0; for (int k=0; k<=N/2; ++k) { for (int isample=0; isample<N; ++isample) { x[isample] += reXX[k]*TMath::Cos(2.*TMath::Pi()*k*isample/N); x[isample] += imXX[k]*TMath::Sin(2.*TMath::Pi()*k*isample/N); } } } void fft_correlation(const Int_t N, Double_t* x, Double_t* reX, Double_t* imX) { // // Correlation is basically a projection, like projection of a vector to basis. // In statistics it's the same: each variable play role of a basis vector. // assert(N%2 == 0); for (int k=0; k<=N/2; ++k) { reX[k] = 0; imX[k] = 0; } for (int k=0; k<=N/2; ++k) { for (int isample=0; isample<N; ++isample) { reX[k] += x[isample]*TMath::Cos(2.*TMath::Pi()*k*isample/N); imX[k] -= x[isample]*TMath::Sin(2.*TMath::Pi()*k*isample/N); } } } void Polar(const Int_t N, Double_t reX[], Double_t imX[], Double_t magX[], Double_t phaX[]) { // NB: N is the number of samples in the time domain // The number of samples in the frequecy domain is N/2+1 // Consider the N as even number const Double_t eps = 1e-7; // calculate phase only for points with mag > eps for (int k=0; k<=N/2; ++k) { magX[k] = TMath::Sqrt(reX[k]*reX[k]+imX[k]*imX[k]); phaX[k] = magX[k] > eps? TMath::ATan2(imX[k],reX[k]): 0; } } void fft_correlation() { const char* ifname = "mppc-72.0V-dark.dat.root"; Int_t event = 0; TFile* ifile = new TFile(ifname); if (!ifile) { cout<< "Could not open file " << ifname <<endl; return; } TTree* tree = (TTree*) ifile->Get("p"); if (!tree) { cout<< "Could not find tree \"p\" in " << ifname <<endl; return; } tree->Draw("c1:t1",Form("Entry$==%d",event),"goff"); Double_t t[1024], v[1024]; Int_t np = tree->GetSelectedRows(); for (int i=0; i<np; ++i) { t[i] = tree->GetV2()[i]; v[i] = -1.*tree->GetV1()[i]; } //--64-- const Int_t N = 64; // the number of samples const Int_t N = 512; // the number of samples Int_t tmin = 0; Int_t i1 = 0; while (i1 < np && t[i1] < tmin) ++i1; cout<< "i1 = " << i1 << "\t t[i1] = " << t[i1] <<endl; Double_t baseline = 0; for (int isample=0; isample<N; ++isample) baseline += v[isample]; baseline /= N; for (int i=0; i<1024; ++i) v[i] -= baseline; Double_t* x = &v[i1]; // pointer to the first point TGraph* g = new TGraph(np, t, v); g->SetNameTitle(Form("g%d",event), Form("Event %d", event)); g->SetMarkerStyle(7); g->SetMarkerColor(2); g->SetLineColor(2); new TCanvas; g->Draw("apl"); Double_t reX[N/2+1]; Double_t imX[N/2+1]; for (int k=0; k<=N/2; ++k) { reX[k] = 0; imX[k] = 0; } // get the reX and imX fft_correlation(N, x, reX, imX); Double_t sample[1024]; for (int isample=0; isample<1024; ++isample) sample[isample] = isample; TGraph* gsample = new TGraph(N, sample, x); gsample->SetNameTitle("gsample", "Time Domain;sample number;V, mV"); gsample->SetMarkerStyle(7); gsample->SetMarkerColor(1); gsample->SetLineColor(1); new TCanvas; gsample->Draw("apl"); TGraph* gRe = new TGraph(N/2+1, sample, reX); gRe->SetNameTitle("gRe", "ReX"); gRe->SetMarkerStyle(2); gRe->SetMarkerColor(2); new TCanvas; gRe->Draw("ap"); TGraph* gIm = new TGraph(N/2+1, sample, imX); gIm->SetNameTitle("gIm", "ImX"); gIm->SetMarkerStyle(2); gIm->SetMarkerColor(4); new TCanvas; gIm->Draw("ap"); // polar coordinates Double_t magX[N]; Double_t phaX[N]; Polar(N, reX, imX, magX, phaX); // clean up the frequency domain for (int k=0; k<=N/2; ++k) { // if (k == 8 || k == 9 || k == 10 || k == 11) continue; if (k > 100) { reX[k] = 0; imX[k] = 0; } // if (magX[k] < 150) reX[k] = imX[k] = 0; if (magX[k] < 40) reX[k] = imX[k] = 0; } Double_t xinv[N]; fft_inverse(N, reX, imX, xinv); TGraph* ginv = new TGraph(N, sample, xinv); ginv->SetNameTitle("ginv", "Time Domain from inverse;sample number;amplitude"); ginv->SetMarkerStyle(7); ginv->SetMarkerColor(46); ginv->SetLineColor(46); new TCanvas; ginv->Draw("apl"); TGraph* gmag = new TGraph(N/2+1, sample, magX); gmag->SetNameTitle("gmag", "Magnitude;frequency sample number;magnitude"); gmag->SetMarkerStyle(2); gmag->SetMarkerColor(2); gmag->SetLineColor(2); new TCanvas; gmag->Draw("ap"); TGraph* gpha = new TGraph(N/2+1, sample, phaX); gpha->SetNameTitle("gpha", "Phase;frequency sample number;phase"); gpha->SetMarkerStyle(2); gpha->SetMarkerColor(4); gpha->SetLineColor(4); new TCanvas; gpha->Draw("ap"); }
4a43f2eff9a6e8a84e67fdd966e1ac05c3f7a5f1
d6fcc744ac250c308c1fd64483ebb051dce7e028
/C++/collatzfn.c
dd23b838e7a56f1a85dda6ece3c12ec16ea001b6
[]
no_license
mgncodes/pgming_qns
581f615413ef03b9ee3ab35ebc4a23755ada5228
7dc5c2c53ac9195c644e16a92ba6bc697943a0e9
refs/heads/main
2022-12-26T17:34:00.977561
2020-10-11T14:41:16
2020-10-11T14:41:16
303,048,750
0
0
null
2020-10-11T14:41:17
2020-10-11T05:24:57
C
UTF-8
C
false
false
369
c
collatzfn.c
//collatz function, repeat till 1 #include<stdio.h> int f(int n) { int res; if (n%2 != 0) res = (3*n)+1; else res = n/2; return res; } void main() { int n; scanf("%d",&n); int value; int count=1; value=f(n); while(value != 1) { value = f(value); count = count+1; } printf("%d",count); }
31be4ca6b506cf6cefeaef2627e3d51d113f34ce
9fa67dd469fd8d390fbcbad4530ce2c19dad72c3
/CharsetTest.h
5b10f3553129b1b84a5cea7a167ea4d950cdce46
[]
no_license
Kbdman/CharsetCheck
d971a130710eef883a10285e49ba477a118845ec
4df348f84745463c3fb49b02e00bb6ff0341fee7
refs/heads/master
2021-06-17T21:30:37.215852
2017-05-17T09:45:26
2017-05-17T09:45:26
null
0
0
null
null
null
null
UTF-8
C
false
false
76
h
CharsetTest.h
#pragma once bool isGBK(const char* input); bool isUTF_8(const char* input);
948c331da828d5e9e8722aebae1e1e9e628f4b92
f8c0a188d1cf8ae5221c4cd11552c221a86e259a
/Firmware/bleStack/debug.c
cf8fb68af5edcce0ff21a75865ee503b29683c3c
[ "CC-BY-3.0", "BSD-2-Clause" ]
permissive
digitalinteraction/openmovement
6310abf35b379655073485e84719cc2521733c0e
9c2ee2eeb5eae457673e60699b2842c6df82abb1
refs/heads/master
2023-08-03T23:48:42.973605
2023-07-26T17:52:37
2023-07-26T17:52:37
27,082,024
135
86
null
2018-06-21T23:32:43
2014-11-24T15:38:43
C
UTF-8
C
false
false
2,611
c
debug.c
/* * Copyright (c) 2013-2014, Newcastle University, UK. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE 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. */ // Debugging outputs // Karim Ladha, 2013-2014 #include <stdlib.h> #include <stdarg.h> #include <stdio.h> #include "bt config.h" #include "debug.h" #include "Utils\util.h" #if (DBG_ENABLE) // Allows remapping of default debug channel (e.g. to LCD) void DBG_printf(const char* file,const char* fmt,...) { va_list myargs; va_start(myargs, fmt); if(file)fprintf(stderr,"%s: ",file); vfprintf(stderr, fmt, myargs); // Divert to stderr va_end(myargs); } // Very fast call for small const packets void DBG_fast(const char* data,unsigned char len) { write(2,(void*)data,len);// 2 = stderr } inline void DBG_assert(unsigned char condition, const char* file, unsigned short line) { if(!condition) { DBG_printf(NULL,"ASSERT!: %s, %u\r\n",file,line); } } void DBG_dump(const unsigned char* data, unsigned short len) { unsigned short i; unsigned char trunc = FALSE_; if(len>24) { len = 24; // Clamp dump load trunc = TRUE_; } for(i=0;i<len;i++) { DBG_printf(NULL,"%02X ",(unsigned char)data[i]); } if(trunc == TRUE_) DBG_printf(NULL,"..\r\n"); else DBG_printf(NULL,"\r\n"); } #endif
65340d3fa91748ab4b9d3fd189e8e8d361b5f346
3d46dce9693c4eb1fad6d0dbcd6eb7d332e12558
/src/battle/item/ultra_shroom.h
2f38cff11008d16410aa2913ecfee605da0712b2
[]
no_license
Technoman589/papermario
b2d656d59cf1ed432d0a0933572b3ef46f7358b1
149b764045fc6f03074b3c21d15d1758fb541ee4
refs/heads/master
2023-08-28T10:39:37.588807
2021-10-20T11:45:35
2021-10-20T11:45:35
419,553,284
0
0
null
null
null
null
UTF-8
C
false
false
519
h
ultra_shroom.h
#ifndef BATTLE_ITEM_ULTRA_SHROOM #define BATTLE_ITEM_ULTRA_SHROOM #include "common.h" #include "script_api/battle.h" #undef NAMESPACE #define NAMESPACE battle_item_ultra_shroom ApiStatus func_802D7520(Evt* script, s32 isInitialCall); ApiStatus func_802D75D8(Evt* script, s32 isInitialCall); ApiStatus N(func_802A123C_7239BC)(Evt* script, s32 isInitialCall); ApiStatus N(func_802A12FC_723A7C)(Evt* script, s32 isInitialCall); EvtSource N(UseItemWithEffect); EvtSource N(PlayerGoHome); EvtSource N(EatItem); #endif
ddb5fcb08c815845c5ee0d44ff81c65b9f6e7722
c2cedcf36667730f558ab354bea4505b616c90d2
/obj/base_tele.c
d05a03d83433efa7a38ecafeb029b6eac248bb50
[]
no_license
wugouzi/Nirvlp312mudlib
965ed876c7080ab00e28c5d8cd5ea9fc9e46258f
616cad7472279cc97c9693f893940f5336916ff8
refs/heads/master
2023-03-16T03:45:05.510851
2017-09-21T17:05:00
2017-09-21T17:05:00
null
0
0
null
null
null
null
UTF-8
C
false
false
1,553
c
base_tele.c
/* teleportation error object - Mythos <12-3-97> file containing the list of room paths is /open/TELE_ERR <note: there are default error rooms in case file is wiped */ #define FILE "/open/TELE_ERR" #define DEF 10 /* used to be 10-15% failure */ #define FAIL_PERCENTAGE 5 + random(6) /* we boosted the cost. 5-10% failure [v] */ string path; int num_path; reset(arg) { if(arg) return; if(!read_file(FILE)) { path = allocate(DEF); num_path = DEF; pathset(); } else { setting(); } call_out("check",1); } check() { if(environment(this_object())) destruct(this_object()); return 1; } pathset() { path[0] = "room/shop"; path[1] = "room/church"; path[2] = "room/slope"; path[3] = "room/mount_pass"; path[4] = "room/farmroad1"; path[5] = "room/sea"; path[6] = "room/inn"; path[7] = "room/fortress"; path[8] = "room/path1"; path[9] = "room/big_tree"; } setting() { string reader; int h; reader = explode(read_file(FILE),"\n"); num_path = DEF + sizeof(reader); /*number of paths */ path = allocate(num_path); pathset(); for(h = 0;h<sizeof(reader);h++) path[(DEF - 1) + h] = reader[h]; } /* function to call when doing a teleport */ teleport() { if(random(100) < FAIL_PERCENTAGE) return path[random(num_path)]; return 0; } /* thus to do a teleport one does the following: string where; if(where = call_other("obj/base_tele","teleport")) teleportingobject->move_player("with an astonished look#"+where); else teleport_ok_code; */
6c7c825691c2f160fb231c23d8b52205535c5d23
1ea71198bc44d50ecbdc23655326e900b3f709c1
/src/common/invort_c.c
2b5be6e4ed3cd80f1f0fe856badb0bf33c251ac8
[]
no_license
OpenSpace/Spice
3bb42f22a22361459351a9226bb233873fb01ff3
711ffdb91865c48018ba2efef963ed645ed2557b
refs/heads/master
2023-07-12T10:08:18.991856
2023-06-22T14:49:35
2023-06-22T14:49:35
63,690,239
14
7
null
2023-06-21T22:22:07
2016-07-19T11:57:56
C
UTF-8
C
false
false
7,470
c
invort_c.c
/* -Procedure invort_c ( Invert nearly orthogonal matrices ) -Abstract Construct the inverse of a 3x3 matrix with orthogonal columns and non-zero column norms using a numerically stable algorithm. The rows of the output matrix are the columns of the input matrix divided by the length squared of the corresponding columns. -Disclaimer THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE SOFTWARE AND RELATED MATERIALS, HOWEVER USED. IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. -Required_Reading None. -Keywords MATRIX */ #include "SpiceUsr.h" #include "SpiceZfc.h" #include "SpiceZim.h" #undef invort_c void invort_c ( ConstSpiceDouble m [3][3], SpiceDouble mit[3][3] ) /* -Brief_I/O VARIABLE I/O DESCRIPTION -------- --- -------------------------------------------------- m I A 3x3 matrix. mit O m after transposition and scaling of rows. -Detailed_Input m is a 3x3 matrix. -Detailed_Output mit is the matrix obtained by transposing m and dividing the rows by squares of their norms. -Parameters None. -Exceptions 1) If any of the columns of `m' have zero length, the error SPICE(ZEROLENGTHCOLUMN) is signaled by a routine in the call tree of this routine. 2) If any column is too short to allow computation of the reciprocal of its length without causing a floating point overflow, the error SPICE(COLUMNTOOSMALL) is signaled by a routine in the call tree of this routine. -Files None. -Particulars Suppose that m is the matrix .- -. | A*u B*v C*w | | 1 1 1 | | | | A*u B*v C*w | | 2 2 2 | | | | A*u B*v C*w | | 3 3 3 | `- -' where the vectors (u , u , u ), (v , v , v ), and (w , w , w ) 1 2 3 1 2 3 1 2 3 are unit vectors. This routine produces the matrix: .- -. | a*u a*u a*u | | 1 2 3 | | | | b*v b*v b*v | | 1 2 3 | | | | c*w c*w c*w | | 1 2 3 | `- -' where a = 1/A, b = 1/B, and c = 1/C. -Examples The numerical results shown for this example may differ across platforms. The results depend on the SPICE kernels used as input, the compiler and supporting libraries, and the machine specific arithmetic implementation. 1) Given a double precision 3x3 matrix with mutually orthogonal rows of arbitrary length, compute its inverse. Check that the original matrix times the computed inverse produces the identity matrix. Example code begins here. /. Program invort_ex1 ./ #include <stdio.h> #include "SpiceUsr.h" int main( ) { /. Local variables. ./ SpiceDouble imat [3][3]; SpiceDouble mout [3][3]; SpiceInt i; /. Define a matrix to invert. ./ SpiceDouble m [3][3] = { {0.0, -1.0, 0.0}, {0.5, 0.0, 0.0}, {0.0, 0.0, 1.0} }; printf( "Original Matrix:\n" ); for ( i = 0; i < 3; i++ ) { printf( "%16.7f %15.7f %15.7f\n", m[i][0], m[i][1], m[i][2] ); } /. Invert the matrix, then output. ./ invort_c ( m, mout ); printf( " \n" ); printf( "Inverse Matrix:\n" ); for ( i = 0; i < 3; i++ ) { printf( "%16.7f %15.7f %15.7f\n", mout[i][0], mout[i][1], mout[i][2] ); } /. Check the `m' times `mout' produces the identity matrix. ./ mxm_c ( m, mout, imat ); printf( " \n" ); printf( "Original times inverse:\n" ); for ( i = 0; i < 3; i++ ) { printf( "%16.7f %15.7f %15.7f\n", imat[i][0], imat[i][1], imat[i][2] ); } return ( 0 ); } When this program was executed on a Mac/Intel/cc/64-bit platform, the output was: Original Matrix: 0.0000000 -1.0000000 0.0000000 0.5000000 0.0000000 0.0000000 0.0000000 0.0000000 1.0000000 Inverse Matrix: 0.0000000 2.0000000 0.0000000 -1.0000000 0.0000000 0.0000000 0.0000000 0.0000000 1.0000000 Original times inverse: 1.0000000 0.0000000 0.0000000 0.0000000 1.0000000 0.0000000 0.0000000 0.0000000 1.0000000 -Restrictions None. -Literature_References None. -Author_and_Institution N.J. Bachman (JPL) J. Diaz del Rio (ODC Space) W.L. Taber (JPL) -Version -CSPICE Version 1.0.1, 01-NOV-2021 (JDR) Edited the header to comply with NAIF standard. Fixed I/O type of argument "mit" in -Brief_I/O table. Extended -Abstract section. Added complete code example. -CSPICE Version 1.0.0, 02-JAN-2002 (WLT) (NJB) -Index_Entries Transpose a matrix and invert the lengths of the rows Invert a pseudo orthogonal matrix -& */ { /* Begin invort_c */ /* Local variables */ SpiceDouble temp[3][3]; /* Participate in error tracing. */ chkin_c ( "invort_c" ); /* Transpose the input matrix to obtain a Fortran-style matrix. */ xpose_c ( m, temp ); invort_ ( (SpiceDouble * )temp, (SpiceDouble * )mit ); /* Transpose the output matrix to obtain a C-style matrix. */ xpose_c ( mit, mit ); chkout_c ( "invort_c" ); } /* End invort_c */
392f6bc3e2156bf4a4c72d52caa0bf59a6abff65
67f74caa48f50d812f45e771c034cd5390b218c6
/tmx.c
f64d4b2c223b1b2b4643bca5dd6726ab0486c17f
[]
no_license
easyhunn/sdl2-game-loop
3b7c8a51c4302da44bf20cad13088d8f663a8e0f
e19a0b2979fe4ccad0c27325e193082a3855f688
refs/heads/master
2021-05-30T18:20:04.542717
2015-12-16T13:49:43
2015-12-16T13:49:43
null
0
0
null
null
null
null
UTF-8
C
false
false
9,096
c
tmx.c
/* Copyright (C) 2013 batiste.bieler@gmail.com TMX map reader in C using mxml */ #include "mxml.h" #include "string.h" #include <stdlib.h> #ifndef WIN32 # include <unistd.h> #endif /* !WIN32 */ #include <fcntl.h> #ifndef O_BINARY # define O_BINARY 0 #endif /* !O_BINARY */ // TMX Format documentation : https://github.com/bjorn/tiled/wiki/TMX-Map-Format struct TmxTileset { int tilewidth; int tileheight; char name[50]; int firstgid; char source[50]; int width; int height; int numTiles; int spacing; int margin; }; typedef struct TmxTileset TmxTileset; struct TmxLayer { int width; int height; int numTiles; int * tiles; char name[50]; }; typedef struct TmxLayer TmxLayer; struct TmxProperty { char * name; char * value; }; typedef struct TmxProperty TmxProperty; struct TmxObject { int width; int height; int x; int y; int xw; int yw; int numProperties; TmxProperty * properties; }; typedef struct TmxObject TmxObject; struct TmxObjectGroup { int width; int height; int numObjects; TmxObject * objects; char name[50]; }; typedef struct TmxObjectGroup TmxObjectGroup; struct TmxMap { int width; int height; int tilewidth; int tileheight; // "orthogonal", "isometric" and "staggered" char orientation[15]; TmxTileset * tilesets; int numTilesets; TmxObjectGroup * objectGroups; int numObjectGroups; TmxLayer * layers; int numLayers; int numTiles; }; typedef struct TmxMap TmxMap; /*TmxTileset * createTileset(mxml_node_t * node) { }*/ // mxmlLoadString TmxMap * TMX_LoadFile(char * filename) { FILE *fp; mxml_node_t * tree; fp = fopen(filename, "r"); tree = mxmlLoadFile(NULL, fp, MXML_TEXT_CALLBACK); fclose(fp); mxml_node_t * node; mxml_node_t * mapNode; /* Find the first "map" element */ mapNode = mxmlFindElement(tree, tree, "map", NULL, NULL, MXML_DESCEND); // create and fillup the map TmxMap * map = malloc(sizeof(TmxMap)); map->width = atoi(mxmlElementGetAttr(mapNode, "width")); map->height = atoi(mxmlElementGetAttr(mapNode, "height")); map->tilewidth = atoi(mxmlElementGetAttr(mapNode, "tilewidth")); map->tileheight = atoi(mxmlElementGetAttr(mapNode, "tileheight")); strncpy(map->orientation, mxmlElementGetAttr(mapNode, "orientation"), 12); map->numTilesets = 0; map->numObjectGroups = 0; map->numLayers = 0; map->tilesets = NULL; map->objectGroups = NULL; map->layers = NULL; map->numTiles = 0; node = mxmlFindElement(tree, tree, "tileset", NULL, NULL, MXML_DESCEND); if(node == NULL) { printf("Cannot go further without at least one tileset"); mxmlDelete(tree); return map; } const char * name; // First pass we count the tilesets, layers and object groups while(node != NULL) { name = mxmlGetElement(node); if(name) { if(strcmp(name, "tileset") == 0) { map->numTilesets += 1; } if(strcmp(name, "layer") == 0) { map->numLayers += 1; } if(strcmp(name, "objectgroup") == 0) { map->numObjectGroups += 1; } } node = mxmlWalkNext(node, mapNode, MXML_NO_DESCEND); } // create the map object in memory map->tilesets = malloc(map->numTilesets * sizeof(TmxTileset)); map->layers = malloc(map->numLayers * sizeof(TmxLayer)); map->objectGroups = malloc(map->numObjectGroups * sizeof(TmxObjectGroup)); node = mxmlFindElement(tree, tree, "tileset", NULL, NULL, MXML_DESCEND); int i = 0, j = 0, k = 0, l = 0, m=0; // Second pass we fill the tilesets, layers and object groups while(node != NULL) { name = mxmlGetElement(node); if(name) { if(strcmp(name, "tileset") == 0) { TmxTileset * set = &map->tilesets[i]; set->firstgid = atoi(mxmlElementGetAttr(node, "firstgid")); set->tilewidth = atoi(mxmlElementGetAttr(node, "tilewidth")); set->tileheight = atoi(mxmlElementGetAttr(node, "tileheight")); strncpy(set->name, mxmlElementGetAttr(node, "name"), 50); mxml_node_t * image = mxmlFindElement(node, node, "image", NULL, NULL, MXML_DESCEND); set->width = (atoi(mxmlElementGetAttr(image, "width")) / set->tilewidth) * set->tilewidth; set->height = (atoi(mxmlElementGetAttr(image, "height")) / set->tileheight) * set->tileheight; strncpy(set->source, mxmlElementGetAttr(image, "source"), 50); set->numTiles = (set->width / set->tilewidth) * (set->height / set->tileheight); i++; } if(strcmp(name, "layer") == 0) { TmxLayer * layer = &map->layers[j]; layer->width = atoi(mxmlElementGetAttr(node, "width")); layer->height = atoi(mxmlElementGetAttr(node, "height")); strncpy(layer->name, mxmlElementGetAttr(node, "name"), 50); layer->numTiles = layer->width * layer->height; map->numTiles = map->numTiles + layer->numTiles; // create the tiles layer->tiles = malloc(layer->numTiles * sizeof(int)); // filling up all the tiles mxml_node_t * tile = mxmlFindElement(node, node, "tile", NULL, NULL, MXML_DESCEND); mxml_node_t * data = mxmlFindElement(node, node, "data", NULL, NULL, MXML_DESCEND); l = 0; while(tile != NULL) { if(mxmlGetElement(tile)) { layer->tiles[l] = atoi(mxmlElementGetAttr(tile, "gid")); l++; } tile = mxmlWalkNext(tile, data, MXML_NO_DESCEND); } j++; } if(strcmp(name, "objectgroup") == 0) { TmxObjectGroup * group = &map->objectGroups[k]; group->width = atoi(mxmlElementGetAttr(node, "width")); group->height = atoi(mxmlElementGetAttr(node, "height")); strncpy(group->name, mxmlElementGetAttr(node, "name"), 50); // count the objects mxml_node_t * object = mxmlFindElement(node, node, "object", NULL, NULL, MXML_DESCEND); l = 0; while(object != NULL) { if(mxmlGetElement(object)) { l++; } object = mxmlWalkNext(object, node, MXML_NO_DESCEND); } // create the objects group->objects = malloc(l * sizeof(TmxObject)); group->numObjects = l; // fillup the objects object = mxmlFindElement(node, node, "object", NULL, NULL, MXML_DESCEND); l = 0; while(object != NULL) { if(mxmlGetElement(object)) { TmxObject * tobject = &group->objects[l]; // it seems that some object might have no height... tobject->width = atoi(mxmlElementGetAttr(object, "width")); tobject->height = atoi(mxmlElementGetAttr(object, "height")); tobject->x = atoi(mxmlElementGetAttr(object, "x")); tobject->y = atoi(mxmlElementGetAttr(object, "y")); tobject->xw = tobject->x + tobject->width; tobject->yw = tobject->y + tobject->height; tobject->numProperties = 0; // count the properties mxml_node_t * prop = mxmlFindElement(object, object, "property", NULL, NULL, MXML_DESCEND); while(prop != NULL) { if(mxmlGetElement(prop)) { tobject->numProperties = tobject->numProperties + 1; } prop = mxmlWalkNext(prop, object, MXML_NO_DESCEND); } tobject->properties = malloc(tobject->numProperties * sizeof(TmxProperty)); // fill the properties prop = mxmlFindElement(object, object, "property", NULL, NULL, MXML_DESCEND); m = 0; while(prop != NULL) { if(mxmlGetElement(prop)) { const char * name = mxmlElementGetAttr(prop, "name"); const char * value = mxmlElementGetAttr(prop, "name"); tobject->properties[m].name = malloc(sizeof(name)); strncpy(tobject->properties[m].name, name, sizeof(name)); tobject->properties[m].value = malloc(sizeof(value)); strncpy(tobject->properties[m].value, name, sizeof(value)); } prop = mxmlWalkNext(prop, object, MXML_NO_DESCEND); m = m + 1; } l++; } // next object object = mxmlWalkNext(object, node, MXML_NO_DESCEND); } k++; } } node = mxmlWalkNext(node, mapNode, MXML_NO_DESCEND); } mxmlDelete(tree); return map; }
4de856b578c0e5e12bb4388165f20004b20c05f1
fdbb74a95924e2677466614f6ab6e2bb13b2a95a
/tool/viz/printpeb.c
c1da85b284dc269dc2b7a93487557e9b07843c7d
[ "ISC" ]
permissive
jart/cosmopolitan
fb11b5658939023977060a7c6c71a74093d9cb44
0d748ad58e1063dd1f8560f18a0c75293b9415b7
refs/heads/master
2023-09-06T09:17:29.303607
2023-09-02T03:49:13
2023-09-02T03:50:18
272,457,606
11,887
435
ISC
2023-09-14T17:47:58
2020-06-15T14:16:13
C
UTF-8
C
false
false
28,426
c
printpeb.c
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ │vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ ╞══════════════════════════════════════════════════════════════════════════════╡ │ Copyright 2020 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ │ above copyright notice and this permission notice appear in all copies. │ │ │ │ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ │ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ │ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ │ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ │ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ │ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" #include "libc/calls/internal.h" #include "libc/dce.h" #include "libc/intrin/safemacros.internal.h" #include "libc/log/log.h" #include "libc/nt/dll.h" #include "libc/nt/enum/filetype.h" #include "libc/nt/enum/startf.h" #include "libc/nt/files.h" #include "libc/nt/process.h" #include "libc/nt/runtime.h" #include "libc/nt/struct/ldr.h" #include "libc/nt/struct/ldrdatatableentry.h" #include "libc/nt/struct/linkedlist.h" #include "libc/nt/struct/peb.h" #include "libc/nt/struct/systeminfo.h" #include "libc/nt/struct/teb.h" #include "libc/nt/struct/unicodestring.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" #include "libc/sysv/consts/madv.h" #include "libc/sysv/consts/o.h" #include "libc/time/time.h" #include "tool/decode/lib/flagger.h" #include "tool/decode/lib/idname.h" #if defined(__x86_64__) && SupportsWindows() char *GetString(const struct NtUnicodeString *s) { static char buf[1024]; unsigned len = min(sizeof(buf) - 1, s->Length); for (unsigned i = 0; i < len; ++i) { buf[i] = (unsigned char)s->Data[i]; } buf[len] = '\0'; return &buf[0]; } int NextBestThing(void) { int64_t fd = open("/proc/self/maps", O_RDONLY); posix_fadvise(fd, 0, 0, MADV_SEQUENTIAL); ssize_t wrote; while ((wrote = copyfd(fd, 1, -1)) != -1) { if (wrote == 0) break; } close(fd); return 0; } const struct IdName kNtStartfFlagNames[] = { {kNtStartfUseshowwindow, "kNtStartfUseshowwindow"}, {kNtStartfUsesize, "kNtStartfUsesize"}, {kNtStartfUseposition, "kNtStartfUseposition"}, {kNtStartfUsecountchars, "kNtStartfUsecountchars"}, {kNtStartfUsefillattribute, "kNtStartfUsefillattribute"}, {kNtStartfRunfullscreen, "kNtStartfRunfullscreen"}, {kNtStartfForceonfeedback, "kNtStartfForceonfeedback"}, {kNtStartfForceofffeedback, "kNtStartfForceofffeedback"}, {kNtStartfUsestdhandles, "kNtStartfUsestdhandles"}, {kNtStartfUsehotkey, "kNtStartfUsehotkey"}, {kNtStartfTitleislinkname, "kNtStartfTitleislinkname"}, {kNtStartfTitleisappid, "kNtStartfTitleisappid"}, {kNtStartfPreventpinning, "kNtStartfPreventpinning"}, {kNtStartfUntrustedsource, "kNtStartfUntrustedsource"}, {0, 0}, }; dontasan void PrintStartupInfo(void) { #if 0 printf("\n\ ╔──────────────────────────────────────────────────────────────────────────────╗\n\ │ new technology § startup info │\n\ ╚──────────────────────────────────────────────────────────────────────────────╝\n\ \n"); #define X(D, F) \ printf("%s.%-22s= " D "\n", "__nt_startupinfo", #F, __nt_startupinfo.F); X("%u", cb); X("%p", lpReserved); X("%hs", lpDesktop); X("%hs", lpTitle); X("%u", dwX); X("%u", dwY); X("%u", dwXSize); X("%u", dwYSize); X("%u", dwXCountChars); X("%u", dwYCountChars); X("%u", dwFillAttribute); printf("%s.%-22s: %s\n", "__nt_startupinfo", "dwFlags", RecreateFlags(kNtStartfFlagNames, __nt_startupinfo.dwFlags)); X("%hu", wShowWindow); X("%hu", cbReserved2); X("%s", lpReserved2); X("%ld", hStdInput); X("%ld", hStdOutput); X("%ld", hStdError); #undef X #endif } void PrintSystemInfo(void) { #if 0 printf("\n\ ╔──────────────────────────────────────────────────────────────────────────────╗\n\ │ new technology § system info │\n\ ╚──────────────────────────────────────────────────────────────────────────────╝\n\ \n"); #define X(D, F) \ printf("%s.%-28s= " D "\n", "__nt_systeminfo", #F, __nt_systeminfo.F); X("%08x", dwOemId); X("%04hx", wProcessorArchitecture); X("%d", dwPageSize); X("%p", lpMinimumApplicationAddress); X("%p", lpMaximumApplicationAddress); X("%p", dwActiveProcessorMask); X("%u", dwNumberOfProcessors); X("%u", dwProcessorType); X("%u", dwAllocationGranularity); X("%hu", wProcessorLevel); X("%hu", wProcessorRevision); #undef X #endif } const char *ft2str(int ft) { if (ft == kNtFileTypeUnknown) return "kNtFileTypeUnknown"; if (ft == kNtFileTypeDisk) return "kNtFileTypeDisk"; if (ft == kNtFileTypeChar) return "kNtFileTypeChar"; if (ft == kNtFileTypePipe) return "kNtFileTypePipe"; if (ft == kNtFileTypeRemote) return "kNtFileTypeRemote"; return "wut?"; } void PrintStdioInfo(void) { printf("\n\ ╔──────────────────────────────────────────────────────────────────────────────╗\n\ │ new technology § stdio info │\n\ ╚──────────────────────────────────────────────────────────────────────────────╝\n\ \n"); printf("%s: %ld (%s)\n", "g_fds.p[0].handle", g_fds.p[0].handle, ft2str(GetFileType(g_fds.p[0].handle))); printf("%s: %ld (%s)\n", "g_fds.p[1].handle", g_fds.p[1].handle, ft2str(GetFileType(g_fds.p[1].handle))); printf("%s: %ld (%s)\n", "g_fds.p[2].handle", g_fds.p[2].handle, ft2str(GetFileType(g_fds.p[2].handle))); } dontasan void PrintTeb(void) { GetCurrentProcessId(); SetLastError(0x1234); printf("\n\ ╔──────────────────────────────────────────────────────────────────────────────╗\n\ │ new technology § teb? │\n\ ╚──────────────────────────────────────────────────────────────────────────────╝\n\ \n"); printf("gs:0x%02x: %-39s = 0x%lx\n", 0x00, "NtGetSeh()", _NtGetSeh()); printf("gs:0x%02x: %-39s = 0x%lx\n", 0x08, "NtGetStackHigh()", _NtGetStackHigh()); printf("gs:0x%02x: %-39s = 0x%lx\n", 0x10, "NtGetStackLow()", _NtGetStackLow()); printf("gs:0x%02x: %-39s = 0x%lx\n", 0x18, "_NtGetSubsystemTib()", _NtGetSubsystemTib()); printf("gs:0x%02x: %-39s = 0x%lx\n", 0x20, "NtGetFib()", _NtGetFib()); printf("gs:0x%02x: %-39s = 0x%lx\n", 0x30, "NtGetTeb()", NtGetTeb()); printf("gs:0x%02x: %-39s = 0x%lx\n", 0x38, "NtGetEnv()", _NtGetEnv()); printf("gs:0x%02x: %-39s = 0x%lx\n", 0x40, "NtGetPid()", NtGetPid()); printf("gs:0x%02x: %-39s = 0x%lx\n", 0x48, "NtGetTid()", NtGetTid()); printf("gs:0x%02x: %-39s = 0x%lx\n", 0x50, "NtGetRpc()", _NtGetRpc()); printf("gs:0x%02x: %-39s = 0x%lx\n", 0x58, "NtGetTls()", _NtGetTls()); printf("gs:0x%02x: %-39s = 0x%lx\n", 0x60, "NtGetPeb()", NtGetPeb()); printf("gs:0x%02x: %-39s = 0x%lx\n", 0x68, "NtGetErr()", NtGetErr()); } void PrintPeb(void) { struct NtPeb *peb = NtGetPeb(); printf("\n\ ╔──────────────────────────────────────────────────────────────────────────────╗\n\ │ new technology § peb │\n\ ╚──────────────────────────────────────────────────────────────────────────────╝\n\ \n"); printf("0x%04x: %-40s = %u\n", offsetof(struct NtPeb, InheritedAddressSpace), "InheritedAddressSpace", (unsigned)peb->InheritedAddressSpace); printf("0x%04x: %-40s = %u\n", offsetof(struct NtPeb, ReadImageFileExecOptions), "ReadImageFileExecOptions", (unsigned)peb->ReadImageFileExecOptions); printf("0x%04x: %-40s = %u\n", offsetof(struct NtPeb, BeingDebugged), "BeingDebugged", (unsigned)peb->BeingDebugged); printf("0x%04x: %-40s = %u\n", offsetof(struct NtPeb, __wut1), "__wut1", (unsigned)peb->__wut1); printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, Mutant), "Mutant", peb->Mutant); printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, ImageBaseAddress), "ImageBaseAddress", peb->ImageBaseAddress); /* struct NtLdr *Ldr; */ printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, ProcessParameters), "ProcessParameters", peb->ProcessParameters); printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, SubSystemData), "SubSystemData", peb->SubSystemData); printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, ProcessHeap), "ProcessHeap", peb->ProcessHeap); printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, FastPebLock), "FastPebLock", peb->FastPebLock); printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, __wut3), "__wut3", peb->__wut3); printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, __wut4), "__wut4", peb->__wut4); printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, __wut5), "__wut5", peb->__wut5); printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, KernelCallbackTable), "KernelCallbackTable", peb->KernelCallbackTable); printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, UserSharedInfoPtr), "UserSharedInfoPtr", peb->UserSharedInfoPtr); printf("0x%04x: %-40s = 0x%x\n", offsetof(struct NtPeb, SystemReserved), "SystemReserved", peb->SystemReserved); printf("0x%04x: %-40s = 0x%x\n", offsetof(struct NtPeb, __wut6), "__wut6", peb->__wut6); printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, __wut7), "__wut7", peb->__wut7); printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, TlsExpansionCounter), "TlsExpansionCounter", peb->TlsExpansionCounter); printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, TlsBitmap), "TlsBitmap", peb->TlsBitmap); printf("0x%04x: %-40s = 0x%x 0x%x\n", offsetof(struct NtPeb, TlsBitmapBits), "TlsBitmapBits", peb->TlsBitmapBits[0], peb->TlsBitmapBits[1]); printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, ReadOnlySharedMemoryBase), "ReadOnlySharedMemoryBase", peb->ReadOnlySharedMemoryBase); printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, __wut8), "__wut8", peb->__wut8); printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, ReadOnlyStaticServerData), "ReadOnlyStaticServerData", peb->ReadOnlyStaticServerData); printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, AnsiCodePageData), "AnsiCodePageData", peb->AnsiCodePageData); printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, OemCodePageData), "OemCodePageData", peb->OemCodePageData); printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, UnicodeCaseTableData), "UnicodeCaseTableData", peb->UnicodeCaseTableData); printf("0x%04x: %-40s = 0x%x\n", offsetof(struct NtPeb, NumberOfProcessors), "NumberOfProcessors", peb->NumberOfProcessors); printf("0x%04x: %-40s = 0x%x\n", offsetof(struct NtPeb, NtGlobalFlag), "NtGlobalFlag", peb->NtGlobalFlag); printf("0x%04x: %-40s = %ld\n", offsetof(struct NtPeb, CriticalSectionTimeout), "CriticalSectionTimeout", peb->CriticalSectionTimeout); printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, HeapSegmentReserve), "HeapSegmentReserve", peb->HeapSegmentReserve); printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, HeapSegmentCommit), "HeapSegmentCommit", peb->HeapSegmentCommit); printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, HeapDeCommitTotalFreeThreshold), "HeapDeCommitTotalFreeThreshold", peb->HeapDeCommitTotalFreeThreshold); printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, HeapDeCommitFreeBlockThreshold), "HeapDeCommitFreeBlockThreshold", peb->HeapDeCommitFreeBlockThreshold); printf("0x%04x: %-40s = 0x%x\n", offsetof(struct NtPeb, NumberOfHeaps), "NumberOfHeaps", peb->NumberOfHeaps); printf("0x%04x: %-40s = 0x%x\n", offsetof(struct NtPeb, MaximumNumberOfHeaps), "MaximumNumberOfHeaps", peb->MaximumNumberOfHeaps); printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, ProcessHeaps), "ProcessHeaps", peb->ProcessHeaps); printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, GdiSharedHandleTable), "GdiSharedHandleTable", peb->GdiSharedHandleTable); printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, ProcessStarterHelper), "ProcessStarterHelper", peb->ProcessStarterHelper); printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, GdiDCAttributeList), "GdiDCAttributeList", peb->GdiDCAttributeList); printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, LoaderLock), "LoaderLock", peb->LoaderLock); printf("0x%04x: %-40s = 0x%x\n", offsetof(struct NtPeb, OSMajorVersion), "OSMajorVersion", peb->OSMajorVersion); printf("0x%04x: %-40s = 0x%x\n", offsetof(struct NtPeb, OSMinorVersion), "OSMinorVersion", peb->OSMinorVersion); printf("0x%04x: %-40s = %hu\n", offsetof(struct NtPeb, OSBuildNumber), "OSBuildNumber", peb->OSBuildNumber); printf("0x%04x: %-40s = %hu\n", offsetof(struct NtPeb, OSCSDVersion), "OSCSDVersion", peb->OSCSDVersion); printf("0x%04x: %-40s = 0x%x\n", offsetof(struct NtPeb, OSPlatformId), "OSPlatformId", peb->OSPlatformId); printf("0x%04x: %-40s = 0x%x\n", offsetof(struct NtPeb, ImageSubsystem), "ImageSubsystem", peb->ImageSubsystem); printf("0x%04x: %-40s = 0x%x\n", offsetof(struct NtPeb, ImageSubsystemMajorVersion), "ImageSubsystemMajorVersion", peb->ImageSubsystemMajorVersion); printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, ImageSubsystemMinorVersion), "ImageSubsystemMinorVersion", peb->ImageSubsystemMinorVersion); printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, ImageProcessAffinityMask), "ImageProcessAffinityMask", peb->ImageProcessAffinityMask); printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, ActiveProcessAffinityMask), "ActiveProcessAffinityMask", peb->ActiveProcessAffinityMask); /* "0x%lx", GdiHandleBuffer[38 - __SIZEOF_POINTER__]; */ printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, PostProcessInitRoutine), "PostProcessInitRoutine", peb->PostProcessInitRoutine); printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, TlsExpansionBitmap), "TlsExpansionBitmap", peb->TlsExpansionBitmap); /* "0x%x", TlsExpansionBitmapBits[32]; */ printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, SessionId), "SessionId", peb->SessionId); printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, AppCompatFlags), "AppCompatFlags", peb->AppCompatFlags); printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, AppCompatFlagsUser), "AppCompatFlagsUser", peb->AppCompatFlagsUser); printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, pShimData), "pShimData", peb->pShimData); printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, AppCompatInfo), "AppCompatInfo", peb->AppCompatInfo); printf("0x%04x: %-40s = \"%s\"\n", offsetof(struct NtPeb, CSDVersion), "CSDVersion", GetString(&peb->CSDVersion)); printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, ActivationContextData), "ActivationContextData", peb->ActivationContextData); printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, ProcessAssemblyStorageMap), "ProcessAssemblyStorageMap", peb->ProcessAssemblyStorageMap); printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, SystemDefaultActivationContextData), "SystemDefaultActivationContextData", peb->SystemDefaultActivationContextData); printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, SystemAssemblyStorageMap), "SystemAssemblyStorageMap", peb->SystemAssemblyStorageMap); printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtPeb, MinimumStackCommit), "MinimumStackCommit", peb->MinimumStackCommit); } void PrintPebLdr(void) { printf("\n\ ╔──────────────────────────────────────────────────────────────────────────────╗\n\ │ new technology § peb » ldr │\n\ ╚──────────────────────────────────────────────────────────────────────────────╝\n\ \n"); printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtLdr, SizeOfThis), "SizeOfThis", NtGetPeb()->Ldr->SizeOfThis); printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtLdr, IsInitialized), "IsInitialized", NtGetPeb()->Ldr->IsInitialized); printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtLdr, SsHandle), "SsHandle", NtGetPeb()->Ldr->SsHandle); printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtLdr, InLoadOrderModuleList), "InLoadOrderModuleList", NtGetPeb()->Ldr->InLoadOrderModuleList); printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtLdr, InMemoryOrderModuleList), "InMemoryOrderModuleList", NtGetPeb()->Ldr->InMemoryOrderModuleList); printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtLdr, InInitOrderModuleList), "InInitOrderModuleList", NtGetPeb()->Ldr->InInitOrderModuleList); } void PrintModulesLoadOrder(void) { { printf("\n\ ╔──────────────────────────────────────────────────────────────────────────────╗\n\ │ new technology § modules » load order │\n\ ╚──────────────────────────────────────────────────────────────────────────────╝\n\ \n"); struct NtLinkedList *head = &NtGetPeb()->Ldr->InLoadOrderModuleList; struct NtLinkedList *ldr = head->Next; do { const struct NtLdrDataTableEntry *dll = (const struct NtLdrDataTableEntry *)ldr; /* struct NtLinkedList InLoadOrderLinks; /\* msdn:reserved *\/ */ /* struct NtLinkedList InMemoryOrderLinks; */ /* struct NtLinkedList InInitOrderLinks; /\* msdn:reserved *\/ */ printf("%p\n", ldr); printf("%p vs. %p\n", dll, GetModuleHandleW(dll->FullDllName.Data)); printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtLdrDataTableEntry, DllBase), "DllBase", dll->DllBase); printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtLdrDataTableEntry, EntryPoint), "EntryPoint", dll->EntryPoint); printf("0x%04x: %-40s = 0x%x\n", offsetof(struct NtLdrDataTableEntry, SizeOfImage), "SizeOfImage", dll->SizeOfImage); printf("0x%04x: %-40s = \"%s\"\n", offsetof(struct NtLdrDataTableEntry, FullDllName), "FullDllName", GetString(&dll->FullDllName)); printf("0x%04x: %-40s = \"%s\"\n", offsetof(struct NtLdrDataTableEntry, BaseDllName), "BaseDllName", GetString(&dll->BaseDllName)); printf("0x%04x: %-40s = 0x%x\n", offsetof(struct NtLdrDataTableEntry, Flags), "Flags", dll->Flags); printf("0x%04x: %-40s = %hu\n", offsetof(struct NtLdrDataTableEntry, Load_Count), "Load_Count", dll->Load_Count); printf("0x%04x: %-40s = %hu\n", offsetof(struct NtLdrDataTableEntry, TlsIndex), "TlsIndex", dll->TlsIndex); /* union { */ /* struct NtLinkedList HashLinks; */ /* struct { */ /* void *SectionPointer; */ /* uint32_t CheckSum; */ /* }; */ /* }; */ /* union { */ /* void *LoadedImports; */ /* uint32_t TimeDateStamp; */ /* }; */ printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtLdrDataTableEntry, EntryPointActivationContext), "EntryPointActivationContext", dll->EntryPointActivationContext); printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtLdrDataTableEntry, PatchInformation), "PatchInformation", dll->PatchInformation); /* struct NtLinkedList ForwarderLinks; */ /* struct NtLinkedList ServiceTagLinks; */ /* struct NtLinkedList StaticLinks; */ printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtLdrDataTableEntry, ContextInformation), "ContextInformation", dll->ContextInformation); printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtLdrDataTableEntry, OriginalBase), "OriginalBase", dll->OriginalBase); printf("0x%04x: %-40s = %ld\n", offsetof(struct NtLdrDataTableEntry, LoadTime), "LoadTime", dll->LoadTime); printf("\n"); } while ((ldr = ldr->Next) && ldr != head); } } void PrintModulesMemoryOrder(void) { { printf("\n\ ╔──────────────────────────────────────────────────────────────────────────────╗\n\ │ new technology § modules » memory order │\n\ ╚──────────────────────────────────────────────────────────────────────────────╝\n\ \n"); struct NtLinkedList *head = &NtGetPeb()->Ldr->InMemoryOrderModuleList; struct NtLinkedList *ldr = head->Next; do { const struct NtLdrDataTableEntry *dll = (const struct NtLdrDataTableEntry *)ldr; /* struct NtLinkedList InLoadOrderLinks; /\* msdn:reserved *\/ */ /* struct NtLinkedList InMemoryOrderLinks; */ /* struct NtLinkedList InInitOrderLinks; /\* msdn:reserved *\/ */ printf("%p\n", dll); printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtLdrDataTableEntry, DllBase), "DllBase", dll->DllBase); printf("0x%04x: %-40s = 0x%lx\n", offsetof(struct NtLdrDataTableEntry, EntryPoint), "EntryPoint", dll->EntryPoint); printf("0x%04x: %-40s = 0x%x\n", offsetof(struct NtLdrDataTableEntry, SizeOfImage), "SizeOfImage", dll->SizeOfImage); printf("0x%04x: %-40s = \"%s\"\n", offsetof(struct NtLdrDataTableEntry, FullDllName), "FullDllName", GetString(&dll->FullDllName)); printf("0x%04x: %-40s = \"%s\"\n", offsetof(struct NtLdrDataTableEntry, BaseDllName), "BaseDllName", GetString(&dll->BaseDllName)); printf("0x%04x: %-40s = 0x%x\n", offsetof(struct NtLdrDataTableEntry, Flags), "Flags", dll->Flags); printf("0x%04x: %-40s = %hu\n", offsetof(struct NtLdrDataTableEntry, Load_Count), "Load_Count", dll->Load_Count); printf("0x%04x: %-40s = %hu\n", offsetof(struct NtLdrDataTableEntry, TlsIndex), "TlsIndex", dll->TlsIndex); /* /\* union { *\/ */ /* /\* struct NtLinkedList HashLinks; *\/ */ /* /\* struct { *\/ */ /* /\* void *SectionPointer; *\/ */ /* /\* uint32_t CheckSum; *\/ */ /* /\* }; *\/ */ /* /\* }; *\/ */ /* /\* union { *\/ */ /* /\* void *LoadedImports; *\/ */ /* /\* uint32_t TimeDateStamp; *\/ */ /* /\* }; *\/ */ /* printf("0x%04x: %-40s = 0x%lx\n", */ /* offsetof(struct NtLdrDataTableEntry, * EntryPointActivationContext), */ /* "EntryPointActivationContext", * dll->EntryPointActivationContext); */ /* printf("0x%04x: %-40s = 0x%lx\n", */ /* offsetof(struct NtLdrDataTableEntry, PatchInformation), */ /* "PatchInformation", dll->PatchInformation); */ /* /\* struct NtLinkedList ForwarderLinks; *\/ */ /* /\* struct NtLinkedList ServiceTagLinks; *\/ */ /* /\* struct NtLinkedList StaticLinks; *\/ */ /* printf("0x%04x: %-40s = 0x%lx\n", */ /* offsetof(struct NtLdrDataTableEntry, ContextInformation), */ /* "ContextInformation", dll->ContextInformation); */ /* printf("0x%04x: %-40s = 0x%lx\n", */ /* offsetof(struct NtLdrDataTableEntry, OriginalBase), * "OriginalBase", */ /* dll->OriginalBase); */ /* printf("0x%04x: %-40s = %ld\n", */ /* offsetof(struct NtLdrDataTableEntry, LoadTime), "LoadTime", */ /* dll->LoadTime); */ printf("\n"); } while ((ldr = ldr->Next) && ldr != head); } } int main(int argc, char *argv[]) { if (IsLinux()) { return NextBestThing(); } if (!IsWindows()) { fprintf(stderr, "error: this tool is intended for windows\n"); return 1; } PrintStartupInfo(); PrintSystemInfo(); PrintStdioInfo(); PrintTeb(); PrintPeb(); PrintPebLdr(); PrintModulesLoadOrder(); PrintModulesMemoryOrder(); return 0; } #else int main(int argc, char *argv[]) { fprintf(stderr, "printpeb not supported on this cpu arch or build config\n"); return 1; } #endif /* __x86_64__ && SupportsWindows() */
1caf719d72e4c49d85ba089488871aefe653c7c5
24b7b128a65de98a9ce393f1c8c6faf64b475834
/include/servoSensor.h
6f3bce879a51e17d21464b20c9f635dcff748c2f
[]
no_license
barsta1/MazeBot
e15f5d61260554228b445d0cbb0cc81630a2ad3a
f74e66b32bc1c2e99173fc0322792d2fc9fb1032
refs/heads/master
2020-04-03T03:09:30.049813
2018-10-27T16:34:45
2018-10-27T16:34:45
154,977,925
0
0
null
2018-10-27T15:13:14
2018-10-27T15:13:14
null
UTF-8
C
false
false
36
h
servoSensor.h
void turnServoSensor(int direction);
e1819c9aa83ab2adcdd25229ba4d987e32fb3dfa
1110a6bbb58be12e3fb23f657a01ef5d3aba9108
/src/conversion.h
dca405891e63b82e6cf85772f0991cddedb50c76
[]
no_license
sylwestersz/cpp_libs
a4ce5b1eb7cc74b70a8ef98a5440a8c77b4d3709
2e2ff59ad5c8552097531ed49aa42cb756395fb3
refs/heads/master
2022-07-25T03:57:25.896182
2020-05-12T17:04:12
2020-05-12T17:04:12
263,397,597
0
0
null
null
null
null
UTF-8
C
false
false
271
h
conversion.h
/* This is a sandbox for the C For Everyone course. * I will really quickly go through the course just to brush up a bit :) */ // INCLUDES #include <stdio.h> // FUNCTION DECLARATIONS float miles_2_km(float miles, float yards); int fahrenheit_2_celcius(int degrees);
1390e080e0d202b40091fd70ab21005c19d633d6
815ba6cc98dedf268cf66ef0a5207cfc4d3f5eb9
/mca-2.0.3/conker/src/tc_lock.c
c74b5241b710ec104216d40a0c8a1eb2a1867678
[]
no_license
ke4harper/MxAPI
65b0c1fca9e58dd4670d1752c7f2a1d8f9ba78a7
fc4e2e4037cfb41360f0d0974f3142ba948d9bd7
refs/heads/master
2023-04-03T07:09:04.452807
2023-03-14T21:23:35
2023-03-14T21:23:35
185,410,427
1
0
null
2022-09-29T23:45:15
2019-05-07T13:43:25
C
UTF-8
C
false
false
56,421
c
tc_lock.c
/* Copyright (c) 2010, The Multicore Association All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: (1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. (2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. (3) Neither the name of the Multicore Association nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /***************************************************************************** * Source: tc_lock.c * * Description: * *****************************************************************************/ #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ #include <th_include.h> #include <tc_include.h> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <unistd.h> #include <sched.h> #include <pthread.h> #include <mrapi.h> #include <mca_config.h> #define NUM_TASKS 4 #define TC_LOCK_MUTEX_ID 911 #define TC_LOCK_SEM_ID 1776 #define TC_LOCK_RWL_ID 2001 /* testcase config options */ typedef enum _op_types { USE_UNDEFINED = 0, USE_PTHREAD_MUTEX, USE_MRAPI_MUTEX, USE_SVR4_SEMAPHORE, USE_MRAPI_SEMAPHORE, USE_SVR4_RWL, USE_MRAPI_RWL } op_types; #define BIG_COUNT 10000 /* initial value of process counter */ #define SEMKEY ((key_t) 23456L) #define RWLKEY ((key_t) 34567L) /* Define the semaphore operation arrays for the semop() calls */ static struct sembuf op_lock[2] = { { 2, 0, 0 } , /* wait for [2] (lock) to equal 0 */ { 2, 1, SEM_UNDO } /* then increment [2] to 1 - this locks it */ /* UNDO to release the lock if processes exits */ /* before explicitly unlocking */ }; static struct sembuf op_endcreate[2] = { { 1, -1, SEM_UNDO } , /* decrement [1] (proc counter) with undo on exit */ /* UNDO to adjust proc counter if process exits */ /* before explicitly calling sem_close() */ { 2, -1, SEM_UNDO } /* then decrement [2] (lock) back to 0 */ }; static struct sembuf op_open[1] = { { 1, -1, SEM_UNDO } /* decrement [1] (proc counter) with undo on exit */ }; static struct sembuf op_close[3] = { { 2, 0, 0 }, /* wait for [2] (lock) to equal to 0 */ { 2, 1, SEM_UNDO }, /* then increment [2] to 1 - this locks it */ { 1, 1, SEM_UNDO } /* then increment [1] (proc counter) */ }; static struct sembuf op_unlock[1] = { { 2, -1, SEM_UNDO } /* decrement [2] (lock) back to 0 */ }; static struct sembuf op_op[1] = { { 0, 99, SEM_UNDO } /* decrement or increment [0] with undo on exit */ /* the 99 is set to the actual amount to add or */ /* subtract (positive or negative) */ }; union{ int val; struct semid_ds *buf; ushort *array; }semctl_arg; static op_types op_type = USE_UNDEFINED; static int op_count = 1; static int read_op_count = 0; static int max_nonexc_locks = 0; static int num_tasks = NUM_TASKS; static int using_pthreads = 0; static int using_trylocks = 0; static char* filename = NULL; static FILE* outfile; static tc_status final_status = TC_OK; static char status_buff[MRAPI_MAX_STATUS_SIZE]; static pthread_mutex_t p_mutex=PTHREAD_MUTEX_INITIALIZER; /* forward declaration of the task_bodies */ void task_body(int task_id, void* input_data, int input_data_size); /* forward declaration of the arg handler */ int arg_handler (char opt, const char* value); /* forward declaration of the task_bodies -- they setup the call to lock_driver */ void task_body_pthread_mutex(int task_id, void* input_data, int input_data_size); void task_body_mrapi_mutex(int task_id, void* input_data, int input_data_size); void task_body_mrapi_mutex_try(int task_id, void* input_data, int input_data_size); void task_body_svr4_semaphore(int task_id, void* input_data, int input_data_size); void task_body_mrapi_semaphore(int task_id, void* input_data, int input_data_size); void task_body_mrapi_semaphore_try(int task_id, void* input_data, int input_data_size); void task_body_svr4_rwl(int task_id, void* input_data, int input_data_size); void task_body_mrapi_rwl(int task_id, void* input_data, int input_data_size); void task_body_mrapi_rwl_try(int task_id, void* input_data, int input_data_size); /* other misc functions */ char* tc_get_testcase_name(void) { return "tc_lock"; } int tc_get_num_tasks(void) { return num_tasks; } char* op_type_string(void); int sem_create(key_t key, int initval); int sem_open(key_t key); int sem_rm(int id); int sem_close(int id); int sem_lock(int id, int num_locks); int sem_unlock(int id, int num_locks); int sem_op(int id, int value); /***************************************************************************** * tc_print_arg_usage -- print out the descriptions of arguments *****************************************************************************/ void tc_print_arg_usage(void) { if (using_pthreads) { th_log(" -m : test using pthread mutexes\n"); } th_log(" -M : test using MRAPI mutexes [default]\n"); th_log(" -s : test using SVR4 semaphores\n"); th_log(" -S : test using MRAPI semaphores\n"); th_log(" -w : test using SVR4-based reader/writer locks\n"); th_log(" -W : test using MRAPI reader/writer locks\n"); th_log(" -l : number of lock operations [default = 1]\n"); th_log(" -n : number of lockers [default = %d]\n", NUM_TASKS); th_log(" -r : number of reads for each write [default = 1]\n"); th_log(" -c : max concurrent non-exclusive locks [default = 1]\n"); th_log(" -a : use 'try' locks (asynch)\n"); th_log(" -f <filename> : append stats to file\n"); th_log("\n NOTES: \n"); if (using_pthreads) { th_log(" -m -M -s -S -w -W are mutually exclusive\n"); } else { th_log(" -M -s -S -w -W are mutually exclusive\n"); } th_log(" -r is only valid with -w or -W\n"); th_log(" -a is only valid with -M -S or -W\n"); } /***************************************************************************** * arg_handler *****************************************************************************/ int arg_handler (char opt, const char* value) { int error = 0; switch (opt) { case 'a': /* use try locks */ using_trylocks = 1; break; case 'm': /* use messages */ if (op_type == USE_UNDEFINED) { op_type = USE_PTHREAD_MUTEX; } else { error = 1; } break; case 'M': /* use messages */ if (op_type == USE_UNDEFINED) { op_type = USE_MRAPI_MUTEX; } else { error = 1; } break; case 's': /* use messages */ if (op_type == USE_UNDEFINED) { op_type = USE_SVR4_SEMAPHORE; } else { error = 1; } break; case 'S': /* use messages */ if (op_type == USE_UNDEFINED) { op_type = USE_MRAPI_SEMAPHORE; } else { error = 1; } break; case 'w': /* use messages */ if (op_type == USE_UNDEFINED) { op_type = USE_SVR4_RWL; } else { error = 1; } break; case 'W': /* use messages */ if (op_type == USE_UNDEFINED) { op_type = USE_MRAPI_RWL; } else { error = 1; } break; case 'f': /* filename */ if (value) { filename = malloc(strlen(value) + 1); strcpy(filename, value); } else { error = 1; } break; case 'l': /* number of operations */ if (value) { op_count = atoi(value); } else { error = 1; } break; case 'n': /* number of tasks */ if (value) { num_tasks = atoi(value); } else { error = 1; } break; case 'r': /* number of reads ops per each write op*/ if (value) { read_op_count = atoi(value); } else { error = 1; } break; case 'c': /* max non-exclusive locks */ if (value) { max_nonexc_locks = atoi(value); } else { error = 1; } break; default: break; } return error; } /***************************************************************************** * tc_setup -- do any basic setup here, including registering a handler * for command line args. Args will be parsed between the call * to tc_setup and the call to tc_initialize. *****************************************************************************/ tc_status tc_setup(void) { tc_status status = TC_OK; if (strcmp(th_get_impl_string(),"pthread") == 0) { using_pthreads = 1; } th_register_args("amMsSwWf:l:n:r:c:",arg_handler); return status; } /***************************************************************************** * tc_initialize -- called by test harness to initialize the testcase *****************************************************************************/ tc_status tc_initialize(void) { tc_status status = TC_OK; int i = 0; tc_task_body_fptr_t fp = NULL; if (op_type == USE_UNDEFINED) { op_type = USE_MRAPI_MUTEX; } /* check the operation count */ if (op_count < 1) { th_log_error("number of lock operations must be > 0\n"); status = TC_ERROR; } /* check the number of tasks */ if (num_tasks < 1 || num_tasks > CONKER_MAX_TASKS) { th_log_error("number of lockers out of range [1-%d]\n", CONKER_MAX_TASKS); status = TC_ERROR; } if (op_type == USE_PTHREAD_MUTEX && !using_pthreads) { th_log_error("%s not valid with fork test harness\n",op_type_string()); status = TC_ERROR; } if (op_type == USE_MRAPI_RWL || op_type == USE_SVR4_RWL) { if (read_op_count < 0) { th_log_error("read operation count less than one\n"); status = TC_ERROR; } else if (read_op_count == 0) { read_op_count = 1; } } else { if (read_op_count != 0) { th_log_error("-r argument not valid for %s\n",op_type_string()); status = TC_ERROR; } } if (op_type == USE_MRAPI_SEMAPHORE || op_type == USE_SVR4_SEMAPHORE || op_type == USE_MRAPI_RWL || op_type == USE_SVR4_RWL) { if (max_nonexc_locks < 0) { th_log_error("max non-exclusive locks less than one\n"); status = TC_ERROR; } else if (max_nonexc_locks == 0) { max_nonexc_locks = 1; } } else { if (max_nonexc_locks != 0) { th_log_error("-c argument not valid for %s\n",op_type_string()); status = TC_ERROR; } } if (using_trylocks && ((op_type == USE_PTHREAD_MUTEX) || (op_type == USE_SVR4_SEMAPHORE) || (op_type == USE_SVR4_RWL))) { th_log_error("-a argument not valid for %s\n",op_type_string()); status = TC_ERROR; } if (status == TC_ERROR) return status; /* if we got here we must have good args ... */ th_log("[TC_LOCK] -- tc_initialize, pid = %d\n", getpid()); /* display the config */ th_log("[TC_LOCK] -- using %s\n",op_type_string()); if (using_trylocks) { th_log("[TC_LOCK] -- using try locks\n"); } th_log("[TC_LOCK] -- node offset: %d\n", th_get_node_offset()); th_log("[TC_LOCK] -- number of lockers: %d\n",num_tasks); th_log("[TC_LOCK] -- number of lock operations: %d\n",op_count); if (read_op_count) { th_log("[TC_LOCK] -- number of lock reads per write: %d\n", read_op_count); } if (filename) { /* TODO -- how to deal with output log files in bare metal */ th_log("[TC_LOCK] -- results will be appended to file: %s\n",filename); outfile = fopen(filename, "a+"); } for (i = 0; status == TC_OK && i < num_tasks; i++) { switch (op_type) { case USE_PTHREAD_MUTEX: fp = task_body_pthread_mutex; break; case USE_MRAPI_MUTEX: if (!using_trylocks) { fp = task_body_mrapi_mutex; } else { fp = task_body_mrapi_mutex_try; } break; case USE_SVR4_SEMAPHORE: fp = task_body_svr4_semaphore; break; case USE_MRAPI_SEMAPHORE: if (!using_trylocks) { fp = task_body_mrapi_semaphore; } else { fp = task_body_mrapi_semaphore_try; } break; case USE_SVR4_RWL: fp = task_body_svr4_rwl; break; case USE_MRAPI_RWL: if (!using_trylocks) { fp = task_body_mrapi_rwl; } else { fp = task_body_mrapi_rwl_try; } break; default: /* TODO - this is an error and should be handled !! */ break; } if (th_register_task(i,"lock_task",fp,NULL,0) != TH_OK) { th_log_error("Unable to register task number %d. Status = %d\n", i, status); status = TC_ERROR; } else { th_log_info("[TC_LOCK] -- task registered, id = %d\n", i); } } return status; } /***************************************************************************** * tc_run -- called by test harness to execute the testcase * tc_run should: * (1) create all tasks * (2) collect results from all tasks * (3) wait for all tasks to complete * (4) return to the test harness * * NOTE - this example does prepare args for the task to allow * for testing of this capability in the test harness *****************************************************************************/ tc_status tc_run(void) { th_status status; int i = 0; void* return_data; int return_data_size; task_status_code task_status; /* create the tasks */ for (i = 0; i < num_tasks; i++) { if ((status = th_task_create(i)) != TH_OK) { th_log_error("Unable to create task number %d. Status = %d\n", i, status); return TC_ERROR; } else { th_log("[TC_LOCK] -- task created, id = %d\n", i); } } /* wait for tasks to complete */ for (i = 0; i < num_tasks; i++) { if (th_task_wait(i,&return_data,&return_data_size,&task_status) != TH_OK) { th_log_error("error waiting for task %d\n",i); return TC_ERROR; } else { if (task_status == TASK_EXITED) { /* print out the message from the task */ if (return_data_size > 0) { th_log_info("[TC_LOCK] -- return data from task %d = '%s'\n", i, (char *) (return_data)); } else { th_log_info("[TC_LOCK] -- return data from task %d = <empty>\n", i); } } else { final_status = TC_ERROR; th_log_error("Task %d exited with error.\n", i); } /* now free the return data */ free(return_data); } } return final_status; } /***************************************************************************** * tc_report -- called by test harness for testcase to report summary results *****************************************************************************/ tc_status tc_report(void) { th_log("[TC_LOCK] -- tc_report\n"); return TC_OK; } /***************************************************************************** * tc_finalize -- called by test harness to alow testcase to clean up *****************************************************************************/ tc_status tc_finalize(void) { if (final_status == TC_OK) { th_log("[TC_LOCK] -- testcase finished successfully, pid = %d\n", getpid()); } else { th_log("[TC_LOCK] -- testcase finished with errors, pid = %d\n", getpid()); } if (filename) { fclose(outfile); free(filename); filename = NULL; } return TC_OK; } /***************************************************************************** * task_body_pthread_mutex *****************************************************************************/ void task_body_pthread_mutex(int task_id, void* input_data, int input_data_size) { int i; long double delta = 0.0; for (i = 0; i < op_count; i++) { if (task_id == 0) { /* begin timer in MASTER only*/ if (th_start_timing() < 0) { th_log_error("Task id %d failed to acquire start time\n", task_id); th_task_exit(task_id,NULL,0,TC_ERROR); } } if (pthread_mutex_lock(&p_mutex) != 0) { th_log_error("Task id %d failed to lock: %s\n", task_id, strerror(errno)); th_task_exit(task_id,NULL,0,TC_ERROR); } if (task_id == 0) { delta += th_end_timing(); if (delta < 0) { th_log_error("Task id %d failed to acquire end time\n", task_id); th_task_exit(task_id,NULL,0,TC_ERROR); } } if (pthread_mutex_unlock(&p_mutex) != 0) { th_log_error("Task id %d failed to unlock: %s\n", task_id, strerror(errno)); th_task_exit(task_id,NULL,0,TC_ERROR); } } if (task_id == 0) { th_log("Locks acquired:\t%d\tAvg Lock Time (in seconds):\t%Lf" "\n\tTotal:\t%Lf\n", op_count, delta / op_count, delta); /* TODO - how to handle files for bare metal */ if (filename) { fprintf(outfile, "%s\t%s\t%d\t%d\t%Lf\n", th_get_impl_string(), op_type_string(), num_tasks, op_count, delta/op_count); } } th_task_exit(task_id,NULL,0,TC_OK); } /***************************************************************************** * task_body_mrapi_mutex *****************************************************************************/ void task_body_mrapi_mutex(int task_id, void* input_data, int input_data_size) { mrapi_status_t status; mrapi_info_t version; mrapi_parameters_t parms = 0; mrapi_mutex_hndl_t mutex; mrapi_key_t key; int i; long double delta = 0.0; mrapi_initialize(CONKER_TESTCASE_DOMAIN, task_id + th_get_node_offset(), parms,&version,&status); if (status != MRAPI_SUCCESS) { th_log_error("Task id %d failed to initialize: %s\n", task_id, mrapi_display_status(status,status_buff,sizeof(status_buff))); th_task_exit(task_id,NULL,0,TC_ERROR); } // get a mutex // attempt to lock it N times in a loop // measure the total time and divide by N mutex = mrapi_mutex_create(TC_LOCK_MUTEX_ID, MRAPI_NULL, &status); if (status == MRAPI_ERR_MUTEX_EXISTS) { mutex = mrapi_mutex_get(TC_LOCK_MUTEX_ID,&status); if (status != MRAPI_SUCCESS) { th_log_error("Task id %d failed to initialize: %s\n", task_id, mrapi_display_status(status,status_buff, sizeof(status_buff))); th_task_exit(task_id,NULL,0,TC_ERROR); } } else if (status != MRAPI_SUCCESS) { th_log_error("Task id %d failed to initialize: %s\n", task_id, mrapi_display_status(status,status_buff,sizeof(status_buff))); th_task_exit(task_id,NULL,0,TC_ERROR); } sleep(1); for (i = 0; i < op_count; i++) { if (task_id == 0) { /* begin timer in MASTER only*/ if (th_start_timing() < 0) { th_log_error("Task id %d failed to acquire start time\n", task_id); th_task_exit(task_id,NULL,0,TC_ERROR); } } mrapi_mutex_lock(mutex, &key, MRAPI_TIMEOUT_INFINITE, &status); if (status != MRAPI_SUCCESS) { th_log_error("Task id %d failed to lock: %s\n", task_id, mrapi_display_status(status,status_buff, sizeof(status_buff))); th_task_exit(task_id,NULL,0,TC_ERROR); } if (task_id == 0) { delta += th_end_timing(); if (delta < 0) { th_log_error("Task id %d failed to acquire end time\n", task_id); th_task_exit(task_id,NULL,0,TC_ERROR); } } mrapi_mutex_unlock(mutex, &key, &status); if (status != MRAPI_SUCCESS) { th_log_error("Task id %d failed to unlock: %s\n", task_id, mrapi_display_status(status,status_buff, sizeof(status_buff))); th_task_exit(task_id,NULL,0,TC_ERROR); } } if (task_id == 0) { th_log("Locks acquired:\t%d\tAvg Lock Time (in seconds):\t%Lf" "\n\tTotal:\t%Lf\n", op_count, delta / op_count, delta); /* TODO - how to handle files for bare metal */ if (filename) { fprintf(outfile, "%s\t%s\t%d\t%d\t%Lf\n", th_get_impl_string(), op_type_string(), num_tasks, op_count, delta/op_count); } } mrapi_finalize(&status); if (status != MRAPI_SUCCESS) { th_log_error("Task id %d failed to finalize %s\n", task_id, mrapi_display_status(status,status_buff,sizeof(status_buff))); th_task_exit(task_id,NULL,0,TC_ERROR); } th_task_exit(task_id,NULL,0,TC_OK); } /***************************************************************************** * task_body_mrapi_mutex_try *****************************************************************************/ void task_body_mrapi_mutex_try(int task_id, void* input_data, int input_data_size) { mrapi_status_t status; mrapi_info_t version; mrapi_parameters_t parms = 0; mrapi_mutex_hndl_t mutex; mrapi_key_t key; mrapi_boolean_t locked = MRAPI_FALSE; int i; long double delta = 0.0; mrapi_initialize(CONKER_TESTCASE_DOMAIN, task_id + th_get_node_offset(), parms,&version,&status); if (status != MRAPI_SUCCESS) { th_log_error("Task id %d failed to initialize: %s\n", task_id, mrapi_display_status(status,status_buff,sizeof(status_buff))); th_task_exit(task_id,NULL,0,TC_ERROR); } // get a mutex // attempt to lock it N times in a loop // measure the total time and divide by N mutex = mrapi_mutex_create(TC_LOCK_MUTEX_ID, MRAPI_NULL, &status); if (status == MRAPI_ERR_MUTEX_EXISTS) { mutex = mrapi_mutex_get(TC_LOCK_MUTEX_ID,&status); if (status != MRAPI_SUCCESS) { th_log_error("Task id %d failed to initialize: %s\n", task_id, mrapi_display_status(status,status_buff, sizeof(status_buff))); th_task_exit(task_id,NULL,0,TC_ERROR); } } else if (status != MRAPI_SUCCESS) { th_log_error("Task id %d failed to initialize: %s\n", task_id, mrapi_display_status(status,status_buff,sizeof(status_buff))); th_task_exit(task_id,NULL,0,TC_ERROR); } sleep(1); for (i = 0; i < op_count; i++) { locked = MRAPI_FALSE; if (task_id == 0) { /* begin timer in MASTER only*/ if (th_start_timing() < 0) { th_log_error("Task id %d failed to acquire start time\n", task_id); th_task_exit(task_id,NULL,0,TC_ERROR); } } while (locked == MRAPI_FALSE) { locked = mrapi_mutex_trylock(mutex, &key, &status); if ((status != MRAPI_SUCCESS) && (status != MRAPI_ERR_MUTEX_LOCKED)) { th_log_error("Task id %d failed to lock: %s\n", task_id, mrapi_display_status(status,status_buff, sizeof(status_buff))); th_task_exit(task_id,NULL,0,TC_ERROR); } } if (task_id == 0) { delta += th_end_timing(); if (delta < 0) { th_log_error("Task id %d failed to acquire end time\n", task_id); th_task_exit(task_id,NULL,0,TC_ERROR); } } mrapi_mutex_unlock(mutex, &key, &status); if (status != MRAPI_SUCCESS) { th_log_error("Task id %d failed to unlock: %s\n", task_id, mrapi_display_status(status,status_buff, sizeof(status_buff))); th_task_exit(task_id,NULL,0,TC_ERROR); } } if (task_id == 0) { th_log("Locks acquired:\t%d\tAvg Lock Time (in seconds):\t%Lf" "\n\tTotal:\t%Lf\n", op_count, delta / op_count, delta); /* TODO - how to handle files for bare metal */ if (filename) { fprintf(outfile, "%s\t%s\t%d\t%d\t%Lf\n", th_get_impl_string(), op_type_string(), num_tasks, op_count, delta/op_count); } } mrapi_finalize(&status); if (status != MRAPI_SUCCESS) { th_log_error("Task id %d failed to finalize %s\n", task_id, mrapi_display_status(status,status_buff,sizeof(status_buff))); th_task_exit(task_id,NULL,0,TC_ERROR); } th_task_exit(task_id,NULL,0,TC_OK); } /***************************************************************************** * task_body_svr4_semaphore *****************************************************************************/ void task_body_svr4_semaphore(int task_id, void* input_data, int input_data_size) { long double delta = 0.0; int i; int semid; if ((semid = sem_create(SEMKEY,1)) < 0) { th_log_error("Task id %d failed to create semaphore\n", task_id); th_task_exit(task_id, NULL, 0, TC_ERROR); } sleep(1); for (i = 0; i < op_count; i++) { if (task_id == 0) { /* begin timer in MASTER only*/ if (th_start_timing() < 0) { th_log_error("Task id %d failed to acquire start time\n", task_id); th_task_exit(task_id,NULL,0,TC_ERROR); } } if (sem_lock(semid,1) < 0) { th_log_error("Task id %d failed to lock semaphore\n", task_id); th_task_exit(task_id, NULL, 0, TC_ERROR); } if (task_id == 0) { delta += th_end_timing(); if (delta < 0) { th_log_error("Task id %d failed to acquire end time\n", task_id); th_task_exit(task_id,NULL,0,TC_ERROR); } } if (sem_unlock(semid,1) < 0) { th_log_error("Task id %d failed to lock semaphore\n", task_id); th_task_exit(task_id, NULL, 0, TC_ERROR); } } if (task_id == 0) { th_log("Locks acquired:\t%d\tAvg Lock Time (in seconds):\t%Lf" "\n\tTotal:\t%Lf\n", op_count, delta / op_count, delta); /* TODO - how to handle files for bare metal */ if (filename) { fprintf(outfile, "%s\t%s\t%d\t%d\t%Lf\n", th_get_impl_string(), op_type_string(), num_tasks, op_count, delta/op_count); } } if (sem_close(semid) < 0) { th_log_error("Task id %d failed to close semaphore\n", task_id); th_task_exit(task_id, NULL, 0, TC_ERROR); } th_task_exit(task_id,NULL,0,TC_OK); } /***************************************************************************** * task_body_mrapi_semaphore *****************************************************************************/ void task_body_mrapi_semaphore(int task_id, void* input_data, int input_data_size) { mrapi_status_t status; mrapi_info_t version; mrapi_parameters_t parms = 0; mrapi_sem_hndl_t semaphore; int i; long double delta = 0.0; mrapi_initialize(CONKER_TESTCASE_DOMAIN, task_id + th_get_node_offset(), parms,&version,&status); if (status != MRAPI_SUCCESS) { th_log_error("Task id %d failed to initialize: %s\n", task_id, mrapi_display_status(status,status_buff,sizeof(status_buff))); th_task_exit(task_id,NULL,0,TC_ERROR); } // get a semaphore // attempt to lock it N times in a loop // measure the total time and divide by N semaphore = mrapi_sem_create(TC_LOCK_SEM_ID, MRAPI_NULL, max_nonexc_locks, &status); if (status == MRAPI_ERR_SEM_EXISTS) { semaphore = mrapi_sem_get(TC_LOCK_SEM_ID,&status); if (status != MRAPI_SUCCESS) { th_log_error("Task id %d failed to initialize: %s\n", task_id, mrapi_display_status(status,status_buff, sizeof(status_buff))); th_task_exit(task_id,NULL,0,TC_ERROR); } } else if (status != MRAPI_SUCCESS) { th_log_error("Task id %d failed to initialize: %s\n", task_id, mrapi_display_status(status,status_buff,sizeof(status_buff))); th_task_exit(task_id,NULL,0,TC_ERROR); } for (i = 0; i < op_count; i++) { if (task_id == 0) { /* begin timer in MASTER only*/ if (th_start_timing() < 0) { th_log_error("Task id %d failed to acquire start time\n", task_id); th_task_exit(task_id,NULL,0,TC_ERROR); } } mrapi_sem_lock(semaphore, MRAPI_TIMEOUT_INFINITE, &status); if (status != MRAPI_SUCCESS) { th_log_error("Task id %d failed to lock: %s\n", task_id, mrapi_display_status(status,status_buff, sizeof(status_buff))); th_task_exit(task_id,NULL,0,TC_ERROR); } if (task_id == 0) { delta += th_end_timing(); if (delta < 0) { th_log_error("Task id %d failed to acquire end time\n", task_id); th_task_exit(task_id,NULL,0,TC_ERROR); } } mrapi_sem_unlock(semaphore, &status); if (status != MRAPI_SUCCESS) { th_log_error("Task id %d failed to unlock: %s\n", task_id, mrapi_display_status(status,status_buff, sizeof(status_buff))); th_task_exit(task_id,NULL,0,TC_ERROR); } } if (task_id == 0) { th_log("Locks acquired:\t%d\tAvg Lock Time (in seconds):\t%Lf" "\n\tTotal:\t%Lf\n", op_count, delta / op_count, delta); /* TODO - how to handle files for bare metal */ if (filename) { fprintf(outfile, "%s\t%s\t%d\t%d\t%Lf\n", th_get_impl_string(), op_type_string(), num_tasks, op_count, delta/op_count); } } mrapi_finalize(&status); if (status != MRAPI_SUCCESS) { th_log_error("Task id %d failed to finalize %s\n", task_id, mrapi_display_status(status,status_buff,sizeof(status_buff))); th_task_exit(task_id,NULL,0,TC_ERROR); } th_task_exit(task_id,NULL,0,TC_OK); } /***************************************************************************** * task_body_mrapi_semaphore_try *****************************************************************************/ void task_body_mrapi_semaphore_try(int task_id, void* input_data, int input_data_size) { mrapi_status_t status; mrapi_info_t version; mrapi_parameters_t parms = 0; mrapi_sem_hndl_t semaphore; int i; mrapi_boolean_t locked = MRAPI_FALSE; long double delta = 0.0; mrapi_initialize(CONKER_TESTCASE_DOMAIN, task_id + th_get_node_offset(), parms,&version,&status); if (status != MRAPI_SUCCESS) { th_log_error("Task id %d failed to initialize: %s\n", task_id, mrapi_display_status(status,status_buff,sizeof(status_buff))); th_task_exit(task_id,NULL,0,TC_ERROR); } // get a semaphore // attempt to lock it N times in a loop // measure the total time and divide by N semaphore = mrapi_sem_create(TC_LOCK_SEM_ID, MRAPI_NULL, max_nonexc_locks, &status); if (status == MRAPI_ERR_SEM_EXISTS) { semaphore = mrapi_sem_get(TC_LOCK_SEM_ID,&status); if (status != MRAPI_SUCCESS) { th_log_error("Task id %d failed to initialize: %s\n", task_id, mrapi_display_status(status,status_buff, sizeof(status_buff))); th_task_exit(task_id,NULL,0,TC_ERROR); } } else if (status != MRAPI_SUCCESS) { th_log_error("Task id %d failed to initialize: %s\n", task_id, mrapi_display_status(status,status_buff,sizeof(status_buff))); th_task_exit(task_id,NULL,0,TC_ERROR); } for (i = 0; i < op_count; i++) { locked = MRAPI_FALSE; if (task_id == 0) { /* begin timer in MASTER only*/ if (th_start_timing() < 0) { th_log_error("Task id %d failed to acquire start time\n", task_id); th_task_exit(task_id,NULL,0,TC_ERROR); } } while (locked == MRAPI_FALSE) { locked = mrapi_sem_trylock(semaphore, &status); if ((status != MRAPI_SUCCESS) && (status != MRAPI_ERR_SEM_LOCKED)) { th_log_error("Task id %d failed to lock: %s\n", task_id, mrapi_display_status(status,status_buff, sizeof(status_buff))); th_task_exit(task_id,NULL,0,TC_ERROR); } } if (task_id == 0) { delta += th_end_timing(); if (delta < 0) { th_log_error("Task id %d failed to acquire end time\n", task_id); th_task_exit(task_id,NULL,0,TC_ERROR); } } mrapi_sem_unlock(semaphore, &status); if (status != MRAPI_SUCCESS) { th_log_error("Task id %d failed to unlock: %s\n", task_id, mrapi_display_status(status,status_buff, sizeof(status_buff))); th_task_exit(task_id,NULL,0,TC_ERROR); } } if (task_id == 0) { th_log("Locks acquired:\t%d\tAvg Lock Time (in seconds):\t%Lf" "\n\tTotal:\t%Lf\n", op_count, delta / op_count, delta); /* TODO - how to handle files for bare metal */ if (filename) { fprintf(outfile, "%s\t%s\t%d\t%d\t%Lf\n", th_get_impl_string(), op_type_string(), num_tasks, op_count, delta/op_count); } } mrapi_finalize(&status); if (status != MRAPI_SUCCESS) { th_log_error("Task id %d failed to finalize %s\n", task_id, mrapi_display_status(status,status_buff,sizeof(status_buff))); th_task_exit(task_id,NULL,0,TC_ERROR); } th_task_exit(task_id,NULL,0,TC_OK); } /***************************************************************************** * task_body_svr4_rwl *****************************************************************************/ void task_body_svr4_rwl(int task_id, void* input_data, int input_data_size) { int i,j; long double delta_read = 0.0; long double delta_write = 0.0; int semid; if ((semid = sem_create(SEMKEY,max_nonexc_locks)) < 0) { th_log_error("Task id %d failed to create writer semaphore\n", task_id); th_task_exit(task_id, NULL, 0, TC_ERROR); } sleep(1); for (i = 0; i < op_count; i++) { for (j = 0; j < read_op_count; j++) { /* get and then release a reader lock */ if (task_id == 0) { /* begin timer in MASTER only*/ if (th_start_timing() < 0) { th_log_error("Task id %d failed to acquire start time\n", task_id); th_task_exit(task_id,NULL,0,TC_ERROR); } } if (sem_lock(semid,1) < 0) { th_log_error("Task id %d failed to lock reader semaphore\n", task_id); th_task_exit(task_id, NULL, 0, TC_ERROR); } if (task_id == 0) { delta_read += th_end_timing(); if (delta_read < 0) { th_log_error("Task id %d failed to acquire end time\n", task_id); th_task_exit(task_id,NULL,0,TC_ERROR); } } if (sem_unlock(semid,1) < 0) { th_log_error("Task id %d failed to lock reader semaphore\n", task_id); th_task_exit(task_id, NULL, 0, TC_ERROR); } } /* get and then release a writer lock */ if (task_id == 0) { /* begin timer in MASTER only*/ if (th_start_timing() < 0) { th_log_error("Task id %d failed to acquire start time\n", task_id); th_task_exit(task_id,NULL,0,TC_ERROR); } } if (sem_lock(semid,max_nonexc_locks) < 0) { th_log_error("Task id %d failed to lock writer semaphore\n", task_id); th_task_exit(task_id, NULL, 0, TC_ERROR); } if (task_id == 0) { delta_write += th_end_timing(); if (delta_write < 0) { th_log_error("Task id %d failed to acquire end time\n", task_id); th_task_exit(task_id,NULL,0,TC_ERROR); } } /* get and then release a writer lock */ if (sem_unlock(semid,max_nonexc_locks) < 0) { th_log_error("Task id %d failed to unlock writer semaphore\n", task_id); th_task_exit(task_id, NULL, 0, TC_ERROR); } } if (task_id == 0) { th_log("Locks acquired:\t%d\tAverage Read Time (in seconds):\t%Lf\n" "Average Write Time (in seconds):\t%Lf\n" "Total read:\t%Lf\t\tTotal write:\t%Lf\n", op_count, delta_read / (read_op_count * op_count), delta_write / op_count, delta_read, delta_write); /* TODO - how to handle files for bare metal */ if (filename) { fprintf(outfile, "%s\t%s\t%d\t%d\t%d\t%Lf\t%Lf\n", th_get_impl_string(), op_type_string(), num_tasks, op_count, read_op_count, delta_read / (read_op_count * op_count), delta_write / op_count); } } if (sem_close(semid) < 0) { th_log_error("Task id %d failed to close semaphore\n", task_id); th_task_exit(task_id, NULL, 0, TC_ERROR); } th_task_exit(task_id,NULL,0,TC_OK); } /***************************************************************************** * task_body_mrapi_rwl *****************************************************************************/ void task_body_mrapi_rwl(int task_id, void* input_data, int input_data_size) { mrapi_status_t status; mrapi_info_t version; mrapi_parameters_t parms = 0; mrapi_rwl_hndl_t rwl; int i,j; long double delta_read = 0.0; long double delta_write = 0.0; mrapi_initialize(CONKER_TESTCASE_DOMAIN, task_id + th_get_node_offset(), parms,&version,&status); if (status != MRAPI_SUCCESS) { th_log_error("Task id %d failed to initialize: %s\n", task_id, mrapi_display_status(status,status_buff,sizeof(status_buff))); th_task_exit(task_id,NULL,0,TC_ERROR); } // get a reader/writer lock // attempt to lock it M read times in a loop then one write lock // measure the total time and divide by N rwl = mrapi_rwl_create(TC_LOCK_RWL_ID, MRAPI_NULL, max_nonexc_locks, &status); if (status == MRAPI_ERR_RWL_EXISTS) { rwl = mrapi_rwl_get(TC_LOCK_RWL_ID,&status); if (status != MRAPI_SUCCESS) { th_log_error("Task id %d failed to initialize: %s\n", task_id, mrapi_display_status(status,status_buff, sizeof(status_buff))); th_task_exit(task_id,NULL,0,TC_ERROR); } } else if (status != MRAPI_SUCCESS) { th_log_error("Task id %d failed to initialize: %s\n", task_id, mrapi_display_status(status,status_buff,sizeof(status_buff))); th_task_exit(task_id,NULL,0,TC_ERROR); } sleep(1); for (i = 0; i < op_count; i++) { for (j = 0; j < read_op_count; j++) { if (task_id == 0) { /* begin timer in MASTER only*/ if (th_start_timing() < 0) { th_log_error("Task id %d failed to acquire start time\n", task_id); th_task_exit(task_id,NULL,0,TC_ERROR); } } mrapi_rwl_lock(rwl, MRAPI_RWL_READER, MRAPI_TIMEOUT_INFINITE, &status); if (status != MRAPI_SUCCESS) { th_log_error("Task id %d failed to lock: %s\n", task_id, mrapi_display_status(status,status_buff, sizeof(status_buff))); th_task_exit(task_id,NULL,0,TC_ERROR); } if (task_id == 0) { delta_read += th_end_timing(); if (delta_read < 0) { th_log_error("Task id %d failed to acquire end time\n", task_id); th_task_exit(task_id,NULL,0,TC_ERROR); } } mrapi_rwl_unlock(rwl, MRAPI_RWL_READER ,&status); if (status != MRAPI_SUCCESS) { th_log_error("Task id %d failed to unlock: %s\n", task_id, mrapi_display_status(status,status_buff, sizeof(status_buff))); th_task_exit(task_id,NULL,0,TC_ERROR); } } if (task_id == 0) { /* begin timer in MASTER only*/ if (th_start_timing() < 0) { th_log_error("Task id %d failed to acquire start time\n", task_id); th_task_exit(task_id,NULL,0,TC_ERROR); } } mrapi_rwl_lock(rwl, MRAPI_RWL_WRITER, MRAPI_TIMEOUT_INFINITE, &status); if (status != MRAPI_SUCCESS) { th_log_error("Task id %d failed to lock: %s\n", task_id, mrapi_display_status(status,status_buff, sizeof(status_buff))); th_task_exit(task_id,NULL,0,TC_ERROR); } if (task_id == 0) { delta_write += th_end_timing(); if (delta_write < 0) { th_log_error("Task id %d failed to acquire end time\n", task_id); th_task_exit(task_id,NULL,0,TC_ERROR); } } mrapi_rwl_unlock(rwl, MRAPI_RWL_WRITER ,&status); if (status != MRAPI_SUCCESS) { th_log_error("Task id %d failed to unlock: %s\n", task_id, mrapi_display_status(status,status_buff, sizeof(status_buff))); th_task_exit(task_id,NULL,0,TC_ERROR); } } if (task_id == 0) { th_log("Locks acquired:\t%d\tAverage Read Time (in seconds):\t%Lf\n" "Average Write Time (in seconds):\t%Lf\n" "Total read:\t%Lf\t\tTotal write:\t%Lf\n", op_count, delta_read / (read_op_count * op_count), delta_write / op_count, delta_read, delta_write); /* TODO - how to handle files for bare metal */ if (filename) { fprintf(outfile, "%s\t%s\t%d\t%d\t%d\t%Lf\t%Lf\n", th_get_impl_string(), op_type_string(), num_tasks, op_count, read_op_count, delta_read / (read_op_count * op_count), delta_write / op_count); } } mrapi_finalize(&status); if (status != MRAPI_SUCCESS) { th_log_error("Task id %d failed to finalize %s\n", task_id, mrapi_display_status(status,status_buff,sizeof(status_buff))); th_task_exit(task_id,NULL,0,TC_ERROR); } th_task_exit(task_id,NULL,0,TC_OK); } /***************************************************************************** * task_body_mrapi_rwl_try *****************************************************************************/ void task_body_mrapi_rwl_try(int task_id, void* input_data, int input_data_size) { mrapi_status_t status; mrapi_info_t version; mrapi_parameters_t parms = 0; mrapi_rwl_hndl_t rwl; int i,j; mrapi_boolean_t locked = MRAPI_FALSE; long double delta_read = 0.0; long double delta_write = 0.0; mrapi_initialize(CONKER_TESTCASE_DOMAIN, task_id + th_get_node_offset(), parms,&version,&status); if (status != MRAPI_SUCCESS) { th_log_error("Task id %d failed to initialize: %s\n", task_id, mrapi_display_status(status,status_buff,sizeof(status_buff))); th_task_exit(task_id,NULL,0,TC_ERROR); } // get a reader/writer lock // attempt to lock it M read times in a loop then one write lock // measure the total time and divide by N rwl = mrapi_rwl_create(TC_LOCK_RWL_ID, MRAPI_NULL, max_nonexc_locks, &status); if (status == MRAPI_ERR_RWL_EXISTS) { rwl = mrapi_rwl_get(TC_LOCK_RWL_ID,&status); if (status != MRAPI_SUCCESS) { th_log_error("Task id %d failed to initialize: %s\n", task_id, mrapi_display_status(status,status_buff, sizeof(status_buff))); th_task_exit(task_id,NULL,0,TC_ERROR); } } else if (status != MRAPI_SUCCESS) { th_log_error("Task id %d failed to initialize: %s\n", task_id, mrapi_display_status(status,status_buff,sizeof(status_buff))); th_task_exit(task_id,NULL,0,TC_ERROR); } sleep(1); for (i = 0; i < op_count; i++) { for (j = 0; j < read_op_count; j++) { locked = MRAPI_FALSE; if (task_id == 0) { /* begin timer in MASTER only*/ if (th_start_timing() < 0) { th_log_error("Task id %d failed to acquire start time\n", task_id); th_task_exit(task_id,NULL,0,TC_ERROR); } } while (locked == MRAPI_FALSE) { locked = mrapi_rwl_trylock(rwl, MRAPI_RWL_READER, &status); if ((status != MRAPI_SUCCESS) && (status != MRAPI_ERR_RWL_LOCKED)) { th_log_error("Task id %d failed to reader lock [attempt:%d]: %s\n", task_id, j, mrapi_display_status(status,status_buff, sizeof(status_buff))); th_task_exit(task_id,NULL,0,TC_ERROR); exit(1); } } if (task_id == 0) { delta_read += th_end_timing(); if (delta_read < 0) { th_log_error("Task id %d failed to acquire end time\n", task_id); th_task_exit(task_id,NULL,0,TC_ERROR); } } mrapi_rwl_unlock(rwl, MRAPI_RWL_READER ,&status); if (status != MRAPI_SUCCESS) { th_log_error("Task id %d failed to unlock: %s\n", task_id, mrapi_display_status(status,status_buff, sizeof(status_buff))); th_task_exit(task_id,NULL,0,TC_ERROR); } } locked = MRAPI_FALSE; if (task_id == 0) { /* begin timer in MASTER only*/ if (th_start_timing() < 0) { th_log_error("Task id %d failed to acquire start time\n", task_id); th_task_exit(task_id,NULL,0,TC_ERROR); } } while (locked == MRAPI_FALSE) { locked = mrapi_rwl_trylock(rwl, MRAPI_RWL_WRITER, &status); if ((status != MRAPI_SUCCESS) && (status != MRAPI_ERR_RWL_LOCKED)) { th_log_error("Task id %d failed to writer lock: %s\n", task_id, mrapi_display_status(status,status_buff, sizeof(status_buff))); th_task_exit(task_id,NULL,0,TC_ERROR); } } if (task_id == 0) { delta_write += th_end_timing(); if (delta_write < 0) { th_log_error("Task id %d failed to acquire end time\n", task_id); th_task_exit(task_id,NULL,0,TC_ERROR); } } mrapi_rwl_unlock(rwl, MRAPI_RWL_WRITER ,&status); if (status != MRAPI_SUCCESS) { th_log_error("Task id %d failed to unlock: %s\n", task_id, mrapi_display_status(status,status_buff, sizeof(status_buff))); th_task_exit(task_id,NULL,0,TC_ERROR); } } if (task_id == 0) { th_log("Locks acquired:\t%d\tAvg Read Time (in seconds):\t%Lf\n" "Avg Write Time (in seconds):\t%Lf\n" "Total Read Time:\t%Lf\tTotal Write Time:\t%Lf\n", op_count, delta_read / (read_op_count * op_count), delta_write / op_count, delta_read, delta_write); /* TODO - how to handle files for bare metal */ if (filename) { fprintf(outfile, "%s\t%s\t%d\t%d\t%d\t%Lf\t%Lf\n", th_get_impl_string(), op_type_string(), num_tasks, op_count, read_op_count, delta_read / (read_op_count * op_count), delta_write / op_count); } } mrapi_finalize(&status); if (status != MRAPI_SUCCESS) { th_log_error("Task id %d failed to finalize %s\n", task_id, mrapi_display_status(status,status_buff,sizeof(status_buff))); th_task_exit(task_id,NULL,0,TC_ERROR); } th_task_exit(task_id,NULL,0,TC_OK); } /************************************************************/ /* U T I L I T I E S */ /************************************************************/ /***************************************************************************** * op_type_string *****************************************************************************/ char* op_type_string() { switch (op_type) { case USE_PTHREAD_MUTEX: return "pthread mutex"; break; case USE_MRAPI_MUTEX: return "MRAPI mutex"; break; case USE_SVR4_SEMAPHORE: return "SVR4 semaphore"; break; case USE_MRAPI_SEMAPHORE: return "MRAPI semaphore"; break; case USE_SVR4_RWL: return "SVR4-based reader/writer locks"; break; case USE_MRAPI_RWL: return "MRAPI reader/writer locks"; break; default: return "FIXME"; break; } } /*--------------------------------------------------------------------------- Create a semaphore with a specified initial value. If the semaphore already exists, we don't initialize it (of course). We return the semaphore ID if all OK, else -1. ---------------------------------------------------------------------------*/ int sem_create(key_t key, int initval) { int id, semval; if (key == IPC_PRIVATE) return (-2); /* not intended for private semaphores */ else if (key == (key_t) -1) return (-1); /* probably an ftok() error by caller */ again: if ((id = semget(key, 3, 0666 | IPC_CREAT)) < 0) return(-1); /* permission problem or tables full */ /* When the semaphore is created, we know that the value of all 3 member is 0. Get a lock on the semaphore by waiting for [2] to equal to 0, then increment it. There is a race condition here. There is a possibility that between the semget() above and the semop() below, another process can call our sem_close() function which can remove the semaphore if that process is the last one using it. Therefore, we handle the error condition of an invalid semaphore ID specially below, and if it does happen, we just go back and create it again. */ if (semop(id, &op_lock[0], 2) < 0){ if (errno == EINVAL) goto again; th_log_error("Failed to lock semaphore [%s]\n", strerror(errno)); return(-1); } /* Get the value of the process counter. If it equals 0, then no one has initialized the semaphore yet. */ semctl_arg.val = 0; if ((semval = semctl(id, 1, GETVAL, semctl_arg)) < 0) th_log_error("Can't GETVAL [%s]\n", strerror(errno)); if (semval == 0){ /* We could initialize by doing a SETALL, but that would clear the adjust value that we set when we locked the semaphore above. Instead, we'll do 2 system calls to initialize [0] and [1]. */ semctl_arg.val = initval; if (semctl(id, 0, SETVAL, semctl_arg) < 0) th_log_error("can't SETVAL[0] [%s]\n", strerror(errno)); semctl_arg.val = BIG_COUNT; if (semctl(id, 1, SETVAL, semctl_arg) < 0) th_log_error("can't SETVAL[1] [%s]\n", strerror(errno)); } /* Decrement the process counter and then release the lock. */ if (semop(id, &op_endcreate[0], 2) < 0) th_log_error("can't end create [%s]\n", strerror(errno)); return(id); } /*------------------------------------------------------------------------- Open a semaphore that must already exist. This function should be used, instead of sem_create(), if the caller knows that the semaphore must already exist. For example a client from a client-server pair would use this, if it is the server's responsiblity to create the semaphore. We return the semaphore ID if all OK, else -1. -------------------------------------------------------------------------*/ int sem_open(key_t key) { int id; if (key == IPC_PRIVATE) return(-1); /* not intended for private semaphores */ else if (key == (key_t) -1) return(-1); /* probably an ftok() error by caller */ if ((id = semget(key, 3, 0)) < 0) return(-1); /* doesn't exist, or tables full */ /* Decrement the process counter. We don't need a lock to do this */ if (semop(id, &op_open[0], 1) < 0) th_log_error("can't open [%s]\n", strerror(errno)); return(id); } /*------------------------------------------------------------------------- Remove a semaphore This call is intended to be called by a server, for example, when it is being shut down, as we do an IPC_RMID on the semaphore, regardless whether other processes may be using it or not. Most other processes should use sem_close() below. ------------------------------------------------------------------------*/ int sem_rm(int id) { semctl_arg.val = 0; if (semctl(id, 0, IPC_RMID, semctl_arg) < 0) { th_log_error("can't IPC_RMID [%s]\n", strerror(errno)); } return 0; } /*------------------------------------------------------------------------ Close a semaphore Unlike the remove function above, this function is for a process to call before it exits, when it is done with the semaphore. We "decrement" the counter of processes using the semaphore, and if this was the last one, we can remove the semaphore. ------------------------------------------------------------------------*/ int sem_close(int id) { int semval; /* The following semop() first gets a lock on the semaphore, then increments [1] - the process counter */ if (semop(id, &op_close[0], 3) < 0) { th_log_error("can't semop [%s]\n", strerror(errno)); return -1; } /* Now that we have a lock, read the value of the process counter to see if this is the last reference to the semaphore. There is a race condition here - see the comments in sem_create(). */ semctl_arg.val = 0; if ((semval = semctl(id, 1, GETVAL, semctl_arg)) < 0) { th_log_error("can't GETVAL [%s]\n", strerror(errno)); return -1; } if (semval > BIG_COUNT) { th_log_error("sem[1] > BIG_COUNT"); return -1; } else if (semval == BIG_COUNT) { if (sem_rm(id) < 0) { return -1; } } else if (semop(id, &op_unlock[0], 1) < 0) { th_log_error("can't unlock [%s]\n", strerror(errno)); return -1; } return 0; } /*------------------------------------------------------------------------ Wait until a semaphore's value is greater than 0, then decrement it by 1 Dijkstra's P operation. Tanenbaum's DOWN operation. -----------------------------------------------------------------------*/ int sem_lock(int id, int num_locks) { return sem_op(id, -1 * num_locks); } /*------------------------------------------------------------------------ Increment a semaphore by 1. Dijkstra's V operation. Tanenbaum's UP operation. -----------------------------------------------------------------------*/ int sem_unlock(int id, int num_locks) { return sem_op(id, num_locks); } /*------------------------------------------------------------------------ General semaphore operation. Increment or decrement by a user-specified amount (positive or negative; amount can't be zero). -----------------------------------------------------------------------*/ int sem_op(int id, int value) { if ((op_op[0].sem_op = value) == 0) { th_log_error("can't have value == 0\n"); return -1; } return semop(id, &op_op[0], 1); } #ifdef __cplusplus extern } #endif /* __cplusplus */
2be1a261181640504220a485155e4098bf1360dc
8be211274f207a79d113b049597d8b0928123a08
/source/ADC_control.c
9016a32fa6169cba751d9524114afafbe8818619
[]
no_license
tld95/ECEN5813_Project_6
298954694303cb612eae606d8347af2a7102d305
30a7a4a98d1dc3741185893a7153dfc046cd5aee
refs/heads/master
2020-09-27T23:01:49.545171
2019-12-10T16:10:18
2019-12-10T16:10:18
226,630,225
0
0
null
null
null
null
UTF-8
C
false
false
2,666
c
ADC_control.c
/* * PES Project Six ADC Control source code implementation * Tristan Duenas * Refereneces: * https://www.freertos.org/FreeRTOS-timers-xTimerCreate.html * https://www.freertos.org * SDK_2.x_FRDM-KL25Z */ #include "ADC_control.h" TimerHandle_t ADC_Timer; adc16_config_t adc16ConfigStruct; adc16_channel_config_t adc16ChannelConfigStruct; uint16_t data[MAX_SINE_WAVE_VALUES]; uint16_t dspBuffer[MAX_SINE_WAVE_VALUES]; uint8_t transferComplete; uint8_t adcSineWaveCount = 0; // Referenced https://www.freertos.org/FreeRTOS-timers-xTimerCreate.html void vADC_CallBack(TimerHandle_t xTimer) { if (xSemaphoreTake(xSemaphore, (TickType_t) 10)) { ADC16_SetChannelConfig(ADC16_BASE, ADC16_CHANNEL_GROUP, &adc16ChannelConfigStruct); while (0U == (kADC16_ChannelConversionDoneFlag & ADC16_GetChannelStatusFlags(ADC16_BASE, ADC16_CHANNEL_GROUP))) { } static uint32_t index = 0; uint16_t rawRegValue = ADC16_GetChannelConversionValue(ADC16_BASE, ADC16_CHANNEL_GROUP); if (index < MAX_SINE_WAVE_VALUES) { Log_integer(DEBUG_LEVEL, ADC_CALL_BACK, rawRegValue); data[index] = rawRegValue; index++; } else { Log_string(STATUS_LEVEL, ADC_CALL_BACK, "DMA Transfer Starting"); LED_GREEN_OFF(); LED_BLUE_ON(); vTaskDelay(pdMS_TO_TICKS(500)); adcSineWaveCount++; DMA0_Transfer(&data[0], &dspBuffer[0]); } xSemaphoreGive(xSemaphore); } } // Referenced https://www.freertos.org/FreeRTOS-timers-xTimerCreate.html void initADC_Timer() { ADC_Timer = xTimerCreate("ADCTimer", pdMS_TO_TICKS(100), pdTRUE, (void *) 0, vADC_CallBack); if (ADC_Timer == NULL) { } else { if (xTimerStart(ADC_Timer, 0) != pdPASS) { } } } // Referenced ADC example from SDK_2.x_FRDM-KL25Z void initADC0() { // Configure the ADC adc16ConfigStruct.referenceVoltageSource = kADC16_ReferenceVoltageSourceVref; adc16ConfigStruct.clockSource = kADC16_ClockSourceAsynchronousClock; adc16ConfigStruct.enableAsynchronousClock = true; adc16ConfigStruct.clockDivider = kADC16_ClockDivider8; adc16ConfigStruct.resolution = kADC16_ResolutionSE12Bit; adc16ConfigStruct.longSampleMode = kADC16_LongSampleDisabled; adc16ConfigStruct.enableHighSpeed = false; adc16ConfigStruct.enableLowPower = false; adc16ConfigStruct.enableContinuousConversion = false; ADC16_GetDefaultConfig(&adc16ConfigStruct); ADC16_Init(ADC16_BASE, &adc16ConfigStruct); ADC16_EnableHardwareTrigger(ADC16_BASE, false); /* Make sure the software trigger is used. */ adc16ChannelConfigStruct.channelNumber = ADC16_USER_CHANNEL; adc16ChannelConfigStruct.enableInterruptOnConversionCompleted = false; adcSineWaveCount = 0; }
f446253c24042c74d74e58a51c2a46593f800272
2f0807a46f83f947449337ad687dee34372c5206
/lwea/lwea.h
14fff87ed2dc22139d2e67fb299a20096c3e8fed
[]
no_license
remnorton/stm32_common
bf478832f677aa67669b52df13351a19f850a3c7
f8fb6c94ee636cadf7174c499754565537b0b366
refs/heads/master
2023-04-23T05:45:10.381122
2021-05-07T13:08:23
2021-05-07T13:08:23
348,384,877
0
0
null
null
null
null
UTF-8
C
false
false
384
h
lwea.h
#ifndef LWEA_H #define LWEA_H /*********************************** * Lightweight encryption algorithm * Copyright (c) 2019 ***********************************/ #include <stdint.h> typedef uint8_t stm_uid[12]; void lwea_encrypt(uint8_t* data, uint32_t len, stm_uid uid, uint8_t* out); void lwea_decrypt(uint8_t* data, uint32_t len, stm_uid uid, uint8_t* out); #endif // LWEA_H
be9f058b3127a9aa3bf962838c5fc0f9a3b4745b
2e038c8e935f1a26ea65beab5388a8ea0d0bae45
/lab_12_05_01/main.c
c2f0bb99fcbba7654b675cbb8c3eae439dc50072
[]
no_license
teopalmer/cprog
c9666343de64eb5d31da4047738103aaffd9d490
d9c0693677740eefc75654fde3e011e7c437acd2
refs/heads/master
2020-12-31T08:30:58.596898
2019-12-28T12:51:45
2019-12-28T12:51:45
238,952,388
0
0
null
null
null
null
UTF-8
C
false
false
352
c
main.c
#include "defines.h" #include "user_interface.h" #include "main_funcs.h" int main() { switch (get_command()) { case (1): return out(); case (2): return cat(); case (3): return sps(); case (4): return pos(); default: return input_error; } }
404dd920130ba786b4142010774ce31a07a11c59
a2eef51a3e5f502b8474a2e78bb62989ef021da4
/1904377/20-02-2020/pattern2.c
dac7713af52bf192231e632b57a90009dd791090
[]
no_license
Dipanjanbakshi/Learning-C.
1218348cd66ac8b46655ad55667a5429645bb324
a00b3a6c3accb016a0ff3fbd0a4cf5f34beb7e3a
refs/heads/master
2022-04-14T12:58:02.361244
2020-03-11T18:23:52
2020-03-11T18:23:52
null
0
0
null
null
null
null
UTF-8
C
false
false
536
c
pattern2.c
#include <stdio.h> int main() { int x; printf("Enter a number odd number"); scanf("%d",&x); if(x%2==0) { printf("Invalid input"); } else { for(int i=0;i<x;i++) { printf(" * "); } printf("\n"); } for(int i=x/2;i>0;i--) { for(int j=i;j>0;j--) { printf(" * "); } printf("\n"); } for(int i=0;i<x/2;i++) { printf(" * "); } printf("\n"); for(int i=0;i<x;i++) { printf(" * "); } printf("\n"); }
a2f3a694411100ebdbcd589697cdd6ea64db86f4
cf454bb2b85405d2bd3133ae3c42a25799eef289
/Program 5/East.c
8aaf479ee6565ad0ba03947cadb5b8af83f558a3
[]
no_license
jdpreuth/Programming-at-the-HW-SW-Interface-Level
4d9a5a674b3cd69d2d9d5831db86bee6cf31734c
51eb61503082403d8e28a4b4177a06287015bbbf
refs/heads/master
2021-09-04T09:55:40.357659
2018-01-17T20:55:58
2018-01-17T20:55:58
117,890,867
0
0
null
null
null
null
UTF-8
C
false
false
4,387
c
East.c
/** * Name: Jon Preuth * Username: jdpreuth * Description: Reads in elevation data, prints out basic information, and the path of least resistance */ #include <stdio.h> #include <stdlib.h> #include <limits.h> #include <stdbool.h> int main(int argc, char** argv){ int width = 0; //The width of the data grid int height = 0; //The height of the data grid int size = 0; //The number of data points int data = 0; //Temp variable for reading data int wCursor = 0; //Position in the column int hCursor = 0; //Row position int minElevation = INT_MAX; //Minimum elevation int maxElevation = INT_MIN; //Maximum Elevation double averageElevation = 0; //Average Elevation int bestRow = 0; //Best starting row int bestCost = INT_MAX; //Cost of the best path int stepCost = 0; //Cost of a given step int cost = 0; //Cost of a given path bool verbose = false; //If verbose mode is enabled or not. Default to off char move; //Stores the move made for use in verbose mode //Check for verbose mode if(argc > 1){ int check = atoi(argv[1]); if(check != 0){ verbose = true; } } scanf("%d %d", &width, &height); //Reads in Width and Height int elevations[width][height]; //Creates an array of width x height to hold elevation data //Scan in elevation data and track size, min, max, and average elevation while(scanf("%d", &data) > 0){ if(wCursor < width){ elevations[wCursor][hCursor] = data; wCursor++; }else{ wCursor = 0; hCursor++; elevations[wCursor][hCursor] = data; wCursor++; } size++; if(data < minElevation){ minElevation = data; } if(data > maxElevation){ maxElevation = data; } averageElevation += data; } averageElevation = averageElevation / size; //Prints out the elevation stats printf("Data points: %d\nAvg elevation: %.2f\nMin elevation: %d\nMax elevation: %d\n", size, averageElevation, minElevation, maxElevation); //Greedy Algorihm for(int h = 0; h < height; h++){ //Calculate the greedy method cost starting at each row hCursor = h; //Starting height (row) cost = 0; for(wCursor = 0; wCursor < width - 1; wCursor++){ if(verbose){ //Output for verbose mode printf("(%d,%d) %d ", wCursor, hCursor, elevations[wCursor][hCursor]); } if(hCursor == 0){ //The current position is the first row int forward = abs(elevations[wCursor + 1][hCursor] - elevations[wCursor][hCursor]); int down = abs(elevations[wCursor + 1][hCursor + 1] - elevations[wCursor][hCursor]); stepCost = forward; //Assume forward is the lowest cost move = 'F'; if(down < stepCost){ //Down is the lowest cost stepCost = down; hCursor++; move = 'D'; } }else if(hCursor == height - 1){ //The current position is the last row int up = abs(elevations[wCursor + 1][hCursor - 1] - elevations[wCursor][hCursor]); int forward = abs(elevations[wCursor + 1][hCursor] - elevations[wCursor][hCursor]); stepCost = forward; //Assume forward is the lowest cost move = 'F'; if(up < stepCost){ //Up is the lowest cost stepCost = up; hCursor--; move = 'U'; } }else{ //The current position is not the first or last row int up = abs(elevations[wCursor + 1][hCursor - 1] - elevations[wCursor][hCursor]); int forward = abs(elevations[wCursor + 1][hCursor] - elevations[wCursor][hCursor]); int down = abs(elevations[wCursor + 1][hCursor + 1] - elevations[wCursor][hCursor]); stepCost = forward; //Assume forward is the lowest cost move = 'F'; if(down <= up){ //Down is lower than up. Down wins ties if(down < stepCost){ //Down is the lowest cost stepCost = down; hCursor++; move = 'D'; } }else{ //Up is lower than down if(up < stepCost){ //Up is the lowest cost stepCost = up; hCursor--; move = 'U'; } } } cost += stepCost; //Add the step cost to total cost of the row if(verbose){ printf("%c, ", move); } } if(verbose){ //Output for verbose mode printf("(%d,%d) %d, cost %d\n", wCursor, hCursor, elevations[wCursor][hCursor], cost); } if(cost < bestCost){ //Determines if the current row has a better cost than the current best row bestCost = cost; bestRow = h; } } //Print the best cost info printf("Best: row %d, cost %d\n", bestRow, bestCost); return 0; }
a24829f5ead878fea3b21827ca6c57213c91ce6d
24ae6d51b0a12d0671771a21fff35109f5f45148
/app/BCM53101 sdk-all-6.5.7/include/appl/dpp/UserInterface/ui_pure_defi_fe200.h
db1220960e9afe1895dd4fee4db1401bdef91f21
[]
no_license
jiaotilizi/cross
e3b7d37856353a20c55f0ddf4c49aaf3c36c79fc
aa3c064fc0fe0494129ddd57114a6f538175b205
refs/heads/master
2020-04-08T14:47:57.798814
2018-11-03T09:16:17
2018-11-03T09:16:17
null
0
0
null
null
null
null
UTF-8
C
false
false
7,162
h
ui_pure_defi_fe200.h
/* $Id: ui_pure_defi_fe200.h,v 1.2 Broadcom SDK $ * $Copyright: (c) 2016 Broadcom. * Broadcom Proprietary and Confidential. All rights reserved.$ */ #ifndef UI_PURE_DEFI_FE200_INCLUDED /* { */ #define UI_PURE_DEFI_FE200_INCLUDED /* * Note: * the following definitions must range between PARAM_FE200_START_RANGE_ID (320) * and PARAM_FE200_END_RANGE_ID (599). * See ui_pure_defi.h */ #define PARAM_FE200_GENRAL_API_ID 321 #define PARAM_FE200_DEFEREED_API_ID 322 #define PARAM_FE200_CELL_API_ID 323 #define PARAM_FE200_LINKS_API_ID 324 #define PARAM_FE200_ROUTING_API_ID 325 #define PARAM_FE200_DIAGNOSTICS_API_ID 326 #define PARAM_FE200_STATISTICS_API_ID 327 #define PARAM_FE200_TESTS_API_ID 328 #define PARAM_FE200_START_DRIVER_ID 331 #define PARAM_FE200_SHUTDOWN_DRIVER_ID 332 #define PARAM_FE200_REGISTER_DEVICE_ID 333 #define PARAM_FE200_UNREGISTER_DEVICE_ID 334 #define PARAM_FE200_CLEAR_DEVICE_PENDING_SERVICES_ID 335 #define PARAM_FE200_STOP_POLLING_TRANSACTON_ID 336 #define PARAM_FE200_START_AND_REGISTER_ID 337 #define PARAM_FE200_UNREGISTER_AND_SHUTDOWN_ID 338 #define PARAM_FE200_RESET_DEVICE_ID 339 #define PARAM_FE200_RESET_REMAIN_ACTIVE_ID 340 #define PARAM_FE200_STOP_ALL_POLLING_ID 341 #define PARAM_FE200_START_ALL_POLLING_ID 342 #define PARAM_FE200_GRACEFUL_SHUTDOWN_DEVICE_ID 343 #define PARAM_FE200_GRACEFUL_RESTORE_DEVICE_ID 344 #define PARAM_FE200_PHYSICAL_WRITE_ID 345 #define PARAM_FE200_LOGICAL_WRITE_ID 346 #define PARAM_FE200_PHYSICAL_READ_ID 347 #define PARAM_FE200_DEFERRED_PHYSICAL_READ_ID 348 #define PARAM_FE200_LOGICAL_READ_ID 349 #define PARAM_FE200_DEFERRED_LOGICAL_READ_ID 350 #define PARAM_FE200_PHYSICAL_DIRECT_ID 351 #define PARAM_FE200_PHYSICAL_INDIRECT_ID 352 #define PARAM_FE200_PHYSICAL_OFFSET_ID 353 #define PARAM_FE200_PHYSICAL_SIZE_ID 354 #define PARAM_FE200_PHYSICAL_DATA_ID 355 #define PARAM_FE200_POLLING_RATE_ID 356 #define PARAM_FE200_READ_FIELD_ID 358 #define PARAM_FE200_WRITE_FIELD_ID 359 #define PARAM_FE200_GET_PROFILE_ID 360 #define PARAM_FE200_SET_PROFILE_ID 361 #define PARAM_FE200_SEND_CELL_ID 370 #define PARAM_FE200_SEND_CELL_FE2_LINK_ID 371 #define PARAM_FE200_SEND_CELL_FE3_LINK_ID 372 #define PARAM_FE200_SEND_CELL_DEST_ENTITY_TYPE_ID 373 #define PARAM_FE200_SEND_CELL_SRC_ENTITY_TYPE_ID 374 #define PARAM_FE200_SEND_CELL_SRC_CHIP_ID 375 #define PARAM_FE200_SEND_CELL_INIT_OUT_LINK_ID 376 #define PARAM_FE200_SEND_CELL_BODY_ID 377 #define PARAM_FE200_ENTITY_TYPE_ID 378 #define PARAM_FE200_RECV_CELL_ID 380 #define PARAM_FE200_RECV_CELL_LINKS_ID 381 #define PARAM_FE200_DEFRRED_RECV_CELL_ID 382 #define PARAM_DEFERRED_FE200_RECV_CELL_POLL_MODE_ID 383 #define PARAM_DEFERRED_FE200_RECV_CELL_INT_MODE_ID 384 #define PARAM_FE200_GET_SERDES_PARAMS_ID 399 #define PARAM_FE200_SET_SERDES_PARAMS_ID 400 #define PARAM_FE200_RESET_SINGLE_SERDES_ID 401 #define PARAM_FE200_SET_SERDES_PARAMS_SERDES_NUMBER_ID 402 #define PARAM_FE200_SET_SERDES_PARAMS_AMPLITUDE_ID 403 #define PARAM_FE200_SET_SERDES_PARAMS_COMMON_MODE_ID 404 #define PARAM_FE200_SET_SERDES_PARAMS_MAIN_CONTROL_ID 405 #define PARAM_FE200_SET_SERDES_PARAMS_POWER_DOWN_RX_TX_ID 406 #define PARAM_FE200_SET_SERDES_PARAMS_PRE_EMPHASIS_ID 407 #define PARAM_FE200_GET_CONNECTIVITY_MAP_ID 410 #define PARAM_FE200_DEFERRED_GET_CONNECTIVITY_MAP_ID 411 #define PARAM_FE200_GET_LINKS_STATUS_ID 412 #define PARAM_FE200_DEFERRED_GET_LINKS_STATUS_ID 413 #define PARAM_FE200_LIST_OF_LINKS_ID 414 #define PARAM_FE200_LINKS_SET_TPVL 415 #define PARAM_FE200_LINKS_GET_TPVL 416 #define PARAM_FE200_TPVL_VALUE_ID 417 #define PARAM_FE200_STOP_REACHABILITY_ERRORS_ID 428 #define PARAM_FE200_START_REACHABILITY_ERRORS_ID 429 #define PARAM_FE200_GET_NEXT_REACHABILITY_ERROR_ID 430 #define PARAM_FE200_CLEAR_REACHABILITY_ERRORS_ID 431 #define PARAM_FE200_GET_UNICAST_TABLE_ID 432 #define PARAM_FE200_DEFERRED_GET_UNICAST_TABLE_ID 433 #define PARAM_FE200_GET_MULTICAST_TABLE_ID 434 #define PARAM_FE200_SET_MULTICAST_TABLE_ID 435 #define PARAM_FE200_STARTING_ROW_ID 436 #define PARAM_FE200_GET_REPEATER_TABLE_ID 437 #define PARAM_FE200_SET_REPEATER_TABLE_ID 438 #define PARAM_FE200_SET_REPEATER_TABLE_BODY_ID 439 #define PARAM_FE200_GET_LOOPBACK_TYPE_ID 450 #define PARAM_FE200_SET_LOOPBACK_TYPE_ID 451 #define PARAM_FE200_LOOPBACK_TYPE_ID 452 #define PARAM_FE200_GET_PRBS_MODE_ID 453 #define PARAM_FE200_SET_PRBS_MODE_ID 454 #define PARAM_FE200_PRBS_CHECKER_LINK_ID 455 #define PARAM_FE200_PRBS_GENERATOR_LINK_ID 456 #define PARAM_FE200_PRBS_ACTIVATE_GENERATOR_ID 457 #define PARAM_FE200_GET_BER_COUNTERS_ID 458 #define PARAM_FE200_DEFERRED_GET_BER_COUNTERS_ID 459 #define PARAM_FE200_START_PRBS_TEST_ID 460 #define PARAM_FE200_STOP_PRBS_TEST_ID 461 #define PARAM_FE200_DIAGNOSTICS_DUMP_REGS_ID 462 #define PARAM_FE200_GET_MAC_COUNTER_TYPE_ID 470 #define PARAM_FE200_SET_MAC_COUNTER_TYPE_ID 471 #if !MAC_RX_COUNTER_INTERFERE_WTITH_LEAKYBUCKET #define PARAM_FE200_MAC_COUNTER_RX_TYPE_ID 472 #endif #define PARAM_FE200_MAC_COUNTER_TX_TYPE_ID 473 #define PARAM_FE200_GET_MAC_COUNTERS_ID 475 #define PARAM_FE200_DEFERRED_GET_MAC_COUNTERS_ID 476 #define PARAM_FE200_START_MAC_COUNTERS_COLLECTION_ID 478 #define PARAM_FE200_STOP_MAC_COUNTERS_COLLECTION_ID 479 #define PARAM_FE200_TEST_SCENARIO_1_ID 481 #define PARAM_FE200_TEST_SCENARIO_2_ID 482 #define PARAM_FE200_TEST_SCENARIO_3_ID 483 #define PARAM_FE200_TEST_SCENARIO_4_ID 484 #define PARAM_FE200_TEST_SCENARIO_5_ID 485 #define PARAM_FE200_TEST_SCENARIO_6_ID 486 #define PARAM_FE200_TEST_SCENARIO_7_ID 487 #define PARAM_FE200_TEST_SCENARIO_8_ID 488 #define PARAM_FE200_TEST_SCENARIO_9_ID 489 #define PARAM_FE200_TEST_SCENARIO_10_ID 490 #define PARAM_FE200_TEST_SCENARIO_11_ID 491 #define PARAM_FE200_TEST_SSR_RESET_ID 500 #define PARAM_FE200_TEST_SSR_XOR_ID 501 /* } */ #endif /*UI_PURE_DEFI_FE200_INCLUDED*/
5c770337f4610f6d41442d9fb4aea0499cd19b51
2056c17ec067c3a31db42dd87969d7a1a1222c18
/src/hal/motor.h
36f230dd616e52a7dc1678d50bacb1fc9cee9412
[]
no_license
Stivy13/controller
dba3a71af8001b3e854db20b0c7547c2193c09b7
47573dda7110884825c8170998a19a04517e1fd6
refs/heads/master
2021-05-25T17:16:54.471706
2020-04-07T14:47:17
2020-04-07T14:47:17
253,838,826
0
0
null
2020-04-07T15:41:13
2020-04-07T15:41:12
null
UTF-8
C
false
false
510
h
motor.h
#ifndef PWM_BOUND_H_ #define PWM_BOUND_H_ void setup_motor(); void motor_enable(); void motor_disable(); void set_motor_goto_position_accel_exec( uint32_t target_position_abs, const uint16_t target_speed, const uint16_t step_num_base, const uint16_t step_freq_base); void set_motor_goto_position(const unsigned long position, const unsigned int speed); uint8_t motor_moving(); int32_t motor_remaining_distance(); extern volatile uint8_t motor_inmotion; #endif // PWM_BOUND_H_
312adb8cc851ec5cbc79345c2e9c92f255a64e37
d25d77ede20a3388e36d7a285fcf81df4c31ac68
/find k.c
d971de85ddb4efe0188c1a5468abd220d2a89f96
[]
no_license
diviraj/ND
54ad46eecc9f20e9c4cebb77874c138bb6bf06c0
f092e92e676c1665e810262258d3b468aff34d2b
refs/heads/master
2021-01-09T20:19:05.567895
2016-11-15T08:54:56
2016-11-15T08:54:56
62,898,531
0
0
null
null
null
null
UTF-8
C
false
false
310
c
find k.c
#include<stdio.h> #include<math.h> int main() { int n; scanf("%d",&n); int a[n],b[n],i,j,t; for(i=0;i<n;i++) scanf("%d",&a[i]); for(j=0;j<n;j++) scanf("%d",&b[j]); for(i=0;i<n;i++) { for(j=0;j<n;j++) { if(b[j]==a[i]) t=i; break; } } printf("%d",t); return 0; }
d81c2a8fecc413384c115f2154a41d1a1793a737
03d903aa1ffa286fb2d69d01cbea53dd1e44aa6a
/ft_putstr_hexa.c
040f19c715e5e6be7e6c52d511d1015d47a46b9e
[]
no_license
mbouanik/ft_printf_without_malloc2
0dd5f3f5569e5cf568b83984e13d711fe98a560d
fc696a1210b5567890efaf7834b51b4ed2aa5ece
refs/heads/master
2023-06-09T19:00:26.569892
2023-05-26T14:45:40
2023-05-26T14:45:40
86,036,476
0
0
null
null
null
null
UTF-8
C
false
false
1,355
c
ft_putstr_hexa.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_putstr_hexa.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: mbouanik <mbouanik@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/29 11:14:24 by mbouanik #+# #+# */ /* Updated: 2018/02/17 09:54:12 by mbouanik ### ########.fr */ /* */ /* ************************************************************************** */ #include "ft_printf.h" void ft_putstr_hexa_assign(uintmax_t n) { if (n) ft_putstr_hexa_assign(n / 16); if (n && (n % 16) <= 9) { if (g_p + 1 > BUFF_SIZE) ft_size_s(); ft_memset_g_set(g_str, (n % 16) + 48, 1); } if ((n % 16) > 9) { if (g_p + 1 > BUFF_SIZE) ft_size_s(); ft_memset_g_set(g_str, (n % 16) + 87, 1); } } void ft_putstr_hexa(uintmax_t n) { if (n == 0) { g_str[g_p++] = n + 48; return ; } ft_putstr_hexa_assign(n); }
9d04a5ded7efcf53976d7dc7a4258771d581c4b6
6ca6121566492154441c01d9bb377419ad66da23
/src/sra_sdk/libs/align/reader-cmn.c
20cee3b96c8e319f30fe4a0b85b16e5e3d03dd4b
[ "LicenseRef-scancode-us-govt-public-domain" ]
permissive
Pfiver/RNA-Seqlyze
f805573b3bcb67089d1210edabba626c8f889c99
20c58157ff1e3aa5be6df5bcd4d63ad6020c65c2
refs/heads/master
2021-08-23T00:18:22.679226
2012-08-08T23:44:38
2012-08-08T23:44:38
112,779,297
0
0
null
null
null
null
UTF-8
C
false
false
6,386
c
reader-cmn.c
/*=========================================================================== * * PUBLIC DOMAIN NOTICE * National Center for Biotechnology Information * * This software/database is a "United States Government Work" under the * terms of the United States Copyright Act. It was readten as part of * the author's official duties as a United States Government employee and * thus cannot be copyrighted. This software/database is freely available * to the public for use. The National Library of Medicine and the U.S. * Government have not placed any restriction on its use or reproduction. * * Although all reasonable efforts have been taken to ensure the accuracy * and reliability of the software and data, the NLM and the U.S. * Government do not and cannot warrant the performance or results that * may be obtained by using this software or data. The NLM and the U.S. * Government disclaim all warranties, express or implied, including * warranties of performance, merchantability or fitness for any particular * purpose. * * Please cite the author in any work or product based on this material. * * =========================================================================== * */ #include <klib/rc.h> #include <vdb/table.h> #include <vdb/cursor.h> #include <vdb/vdb-priv.h> #include "reader-cmn.h" #include "debug.h" #include <sysalloc.h> #include <stdlib.h> #include <string.h> struct TableReader { const VCursor* curs; const TableReaderColumn* cols; int64_t curr; }; rc_t CC TableReader_Make(const TableReader** cself, const VTable* table, TableReaderColumn* cols, size_t cache) { rc_t rc = 0; const VCursor* curs; if( table == NULL ) { rc = RC(rcAlign, rcType, rcConstructing, rcParam, rcInvalid); } else if( (rc = VTableCreateCachedCursorRead(table, &curs, cache)) == 0 ) { rc = TableReader_MakeCursor(cself, curs, cols); VCursorRelease(curs); } ALIGN_DBGERR(rc); return rc; } rc_t CC TableReader_MakeCursor(const TableReader** cself, const VCursor* cursor, TableReaderColumn* cols) { rc_t rc = 0; TableReader* obj = NULL; if( cself == NULL || cursor == NULL || cols == NULL || cols->name == NULL ) { rc = RC(rcAlign, rcType, rcConstructing, rcParam, rcInvalid); } else if( (obj = calloc(1, sizeof(*obj))) == NULL ) { rc = RC(rcAlign, rcType, rcConstructing, rcMemory, rcExhausted); } else if( (rc = VCursorAddRef(cursor)) == 0 ) { obj->curs = cursor; obj->cols = cols; while(rc == 0 && cols->name != NULL) { if( !(cols->flags & ercol_Skip) ) { if( (rc = VCursorAddColumn(obj->curs, &cols->idx, cols->name)) != 0 ) { if( (rc != 0 && (cols->flags & ercol_Optional)) || GetRCState(rc) == rcExists ) { rc = 0; } } } cols++; } if( rc == 0 ) { rc = VCursorOpen(obj->curs); } } if( rc == 0 ) { *cself = obj; ALIGN_DBG("ok%c", '!'); } else { TableReader_Whack(obj); ALIGN_DBGERRP("table", rc, 0); } return rc; } void CC TableReader_Whack(const TableReader* cself) { if( cself != NULL ) { VCursorRelease(cself->curs); free((TableReader*)cself); } } rc_t CC TableReader_ReadRow(const TableReader* cself, int64_t rowid) { rc_t rc = 0; TableReaderColumn* c = NULL; if( cself == NULL ) { rc = RC(rcAlign, rcType, rcOpening, rcSelf, rcNull); } else if( cself->curr != rowid && (rc = VCursorCloseRow(cself->curs)) == 0 && (rc = VCursorSetRowId(cself->curs, rowid)) == 0 && (rc = VCursorOpenRow(cself->curs)) == 0 ) { uint32_t boff = 0; c = (TableReaderColumn*)(cself->cols); while(c->name != NULL) { if (c->idx != 0) { rc = VCursorCellData(cself->curs, c->idx, NULL, (const void**)&c->base.var, &boff, &c->len); if (rc) { if (c->flags & ercol_Optional) { rc = 0; } c->base.var = NULL; c->len = 0; } else if (boff != 0) { rc = RC(rcAlign, rcType, rcReading, rcData, rcUnsupported); } } c++; } } if( rc != 0 ) { ALIGN_DBGERRP("column %s row %ld", rc, c ? c->name : "<none>", rowid); } else { ((TableReader*)cself)->curr = rowid; } return rc; } rc_t CC TableReader_IdRange(const TableReader* cself, int64_t* first, uint64_t* count) { rc_t rc = 0; if( cself == NULL ) { rc = RC(rcAlign, rcType, rcRetrieving, rcSelf, rcNull); } else { rc = VCursorIdRange(cself->curs, 0, first, count); } return rc; } rc_t CC TableReader_OpenIndex(const TableReader* cself, const char* name, const KIndex** idx) { rc_t rc = 0; const VTable* tbl; if( cself == NULL || name == NULL || idx == NULL ) { rc = RC(rcAlign, rcType, rcAccessing, rcParam, rcNull); } else if( (rc = VCursorOpenParentRead(cself->curs, &tbl)) == 0 ) { rc = VTableOpenIndexRead(tbl, idx, name); VTableRelease(tbl); } return rc; } rc_t CC TableReader_PageIdRange(const TableReader *cself, int64_t rowid, int64_t *pfirst, int64_t *plast) { rc_t rc = 0; if( cself == NULL ) { rc = RC(rcAlign, rcType, rcOpening, rcSelf, rcNull); } else if (pfirst != NULL || plast != NULL) { int64_t first = INT64_MAX; int64_t last = INT64_MIN; unsigned i; for (i = 0; cself->cols[i].name != NULL; ++i) { if (cself->cols[i].idx != 0) { int64_t tfirst; int64_t tlast; rc = VCursorPageIdRange(cself->curs, cself->cols[i].idx, rowid, &tfirst, &tlast); if (rc == 0) { if (first > tfirst) first = tfirst; if (last < tlast) last = tlast; } } } if (pfirst) *pfirst = first; if (plast) *plast = last; } return rc; }
c5df10fa873b5ec0cd8df4b5551bd7b9cac97aaa
88216ddc669547de054af36d1197146710496f19
/flub/appDefaults.h
3d0448042546ed8e51ce6048369ee28f417446bd
[]
no_license
Mojofreem/flub
731aef79cad26d804e3974badb93aa472ac34113
6b87c904b725dcaed1bf2e1cc9bb47c875def700
refs/heads/master
2020-05-17T05:33:51.114683
2015-10-08T22:57:08
2015-10-08T22:57:08
42,430,010
0
0
null
null
null
null
UTF-8
C
false
false
592
h
appDefaults.h
#ifndef _FLUB_APP_DEFAULTS_HEADER_ #define _FLUB_APP_DEFAULTS_HEADER_ #include <flub/app.h> #include <stdlib.h> appDefaults_t appDefaults = { .major = 1, .minor = 0, .title = "FlubApp", .configFile = NULL, .bindingFile = NULL, .archiveFile = NULL, .videoMode = "640x480", .fullscreen = "false", .allowVideoModeChange = 0, .allowFullscreenChange = 0, .cmdlineHandler = NULL, .cmdlineParamStr = NULL, .resources = NULL, }; #endif // _FLUB_APP_DEFAULTS_HEADER_
76b2f1e7d467bc7196270ed1ebe3affdc05cc02d
b6a26569f334ba847e474427ecf81b50b0362cea
/Intel/ClientOneSiliconPkg/Fru/EbgPch/LibraryPrivate/BaseIoExpanderLib/IoExpanderCommonLib.c
079e1affbbd3764b00ea90bc235c581603801adb
[]
no_license
marktsai0316/Transformer
fd553728daa5aaa5b3f3fed9b9a2352d70dcd51c
e39ec3030ef0fd1841c6d916bdb77cddaaebc6ad
refs/heads/master
2022-12-10T22:30:54.984958
2020-09-10T05:55:24
2020-09-10T05:55:24
null
0
0
null
null
null
null
UTF-8
C
false
false
2,864
c
IoExpanderCommonLib.c
/** @file This file is I/O Expander library. @copyright INTEL CONFIDENTIAL Copyright 2020 Intel Corporation. <BR> The source code contained or described herein and all documents related to the source code ("Material") are owned by Intel Corporation or its suppliers or licensors. Title to the Material remains with Intel Corporation or its suppliers and licensors. The Material may contain trade secrets and proprietary and confidential information of Intel Corporation and its suppliers and licensors, and is protected by worldwide copyright and trade secret laws and treaty provisions. No part of the Material may be used, copied, reproduced, modified, published, uploaded, posted, transmitted, distributed, or disclosed in any way without Intel's prior express written permission. No license under any patent, copyright, trade secret or other intellectual property right is granted to or conferred upon you by disclosure or delivery of the Materials, either expressly, by implication, inducement, estoppel or otherwise. Any license under such intellectual property rights must be express and approved by Intel in writing. Unless otherwise agreed by Intel in writing, you may not remove or alter this notice or any other notice embedded in Materials by Intel or Intel's suppliers or licensors in any way. **/ #include <Uefi.h> #include <PiDxe.h> #include <Library/UefiLib.h> #include <Library/DebugLib.h> #include <Library/PchIoExpander.h> /** Function returns PchId for devices of passed Segment and Bus. PchId is an index in IO_EXPANDER_PCH_INFO table incremented by 1 @param [in] Segment Segment to look for @param [in] Bus Bas to look for @param [in, out] PchId pointer to variable to return PchId @retval EFI_SUCCESS Function returned valid PchId @retval EFI_INVALID_PARAMETER Passed pointer is invalid @retval EFI_DEVICE_ERROR Not found valid IoExpanderInfo; @retval EFI_NOT_FOUND For given input parameters not found valid PchId **/ EFI_STATUS FindMultiPchInfo ( IN UINTN Segment, IN UINTN Bus, IN OUT UINTN *PchId ) { UINTN IoExpanderIndex; IO_EXPANDER_INFO *IoExpanderInfo; EFI_STATUS Status; if (PchId == NULL) { return EFI_INVALID_PARAMETER; } Status = PchGetIoExpanderInfo (&IoExpanderInfo); if (EFI_ERROR (Status)) { return Status; } IoExpanderIndex = 0; Status = EFI_NOT_FOUND; while (IoExpanderIndex < IO_EXPANDER_MAX) { if (IoExpanderInfo->Valid[IoExpanderIndex] && (Segment == IoExpanderInfo->Segment[IoExpanderIndex]) && (Bus == IoExpanderInfo->Bus[IoExpanderIndex])) { *PchId = IoExpanderIndex + 1; // Adding PCH Legacy Status = EFI_SUCCESS; break; } IoExpanderIndex++; } return Status; }
a2fe7871a96731caefa15352262d81767323a19b
976f5e0b583c3f3a87a142187b9a2b2a5ae9cf6f
/source/freebsd/sys/kern/extr_kern_umtx.c_umtx_thread_alloc.c
9d2ae98a3dbfeb4c248d49082b6a958246291454
[]
no_license
isabella232/AnghaBench
7ba90823cf8c0dd25a803d1688500eec91d1cf4e
9a5f60cdc907a0475090eef45e5be43392c25132
refs/heads/master
2023-04-20T09:05:33.024569
2021-05-07T18:36:26
2021-05-07T18:36:26
null
0
0
null
null
null
null
UTF-8
C
false
false
1,094
c
extr_kern_umtx.c_umtx_thread_alloc.c
#define NULL ((void*)0) typedef unsigned long size_t; // Customize by platform. typedef long intptr_t; typedef unsigned long uintptr_t; typedef long scalar_t__; // Either arithmetic or pointer type. /* By default, we understand bool (as a convenience). */ typedef int bool; #define false 0 #define true 1 /* Forward declarations */ /* Type definitions */ struct umtx_q {scalar_t__ uq_flags; int /*<<< orphan*/ uq_pi_contested; int /*<<< orphan*/ * uq_pi_blocked; struct thread* uq_thread; int /*<<< orphan*/ uq_inherited_pri; } ; struct thread {struct umtx_q* td_umtxq; } ; /* Variables and functions */ int /*<<< orphan*/ KASSERT (int,char*) ; int /*<<< orphan*/ PRI_MAX ; int TAILQ_EMPTY (int /*<<< orphan*/ *) ; void umtx_thread_alloc(struct thread *td) { struct umtx_q *uq; uq = td->td_umtxq; uq->uq_inherited_pri = PRI_MAX; KASSERT(uq->uq_flags == 0, ("uq_flags != 0")); KASSERT(uq->uq_thread == td, ("uq_thread != td")); KASSERT(uq->uq_pi_blocked == NULL, ("uq_pi_blocked != NULL")); KASSERT(TAILQ_EMPTY(&uq->uq_pi_contested), ("uq_pi_contested is not empty")); }
97bacfaf1f3019e792b5a4574232b511b2c73925
e3787902e80c98e132226cb7befa17ae0e75f380
/v0100/srclib/longjmp.c
29daabf0e6d8011caf16159d7d71ebcb9f6a5e43
[ "BSD-2-Clause-Views" ]
permissive
ssusun/SmallerC
fcc7374eac0868e6c78cacfc616e343148b079c5
dd5dd5c653aec778707c3d1341d68a47cc58553b
refs/heads/master
2021-01-18T02:43:48.319070
2018-06-28T07:55:25
2018-06-28T07:55:25
26,523,597
1
0
null
null
null
null
UTF-8
C
false
false
2,975
c
longjmp.c
/* Copyright (c) 2014, Alexey Frunze 2-clause BSD license. */ #include <setjmp.h> /* typedef struct { unsigned xip; // ip/cs:ip/eip unsigned xflags; // (e)flags unsigned xbp; // (e)bp unsigned xsp; // (e)sp } jmp_buf[1]; */ #ifdef __SMALLER_C_16__ int setjmp(jmp_buf jb) { asm("mov bx, [bp+4]"); // jb // ip asm("mov ax, [bp+2]"); // return address asm("mov [bx], ax"); // flags (mainly for IF) asm("pushf"); asm("pop word [bx+2]"); // bp asm("mov ax, [bp]"); // caller's bp asm("mov [bx+4], ax"); // sp asm("lea ax, [bp+2*2]"); // caller's sp asm("mov [bx+6], ax"); // return 0 asm("xor ax, ax"); } void longjmp(jmp_buf jb, int val) { asm("mov ax, [bp+6]"); // val // if val is 0, make it 1 asm("or ax, ax"); asm("setz bl"); asm("or al, bl"); asm("mov bx, [bp+4]"); // jb // sp asm("mov sp, [bx+6]"); // bp asm("mov bp, [bx+4]"); // flags (mainly for IF) asm("push word [bx+2]"); // cs asm("push cs"); // ip asm("push word [bx]"); // return val asm("iret"); } #endif // __SMALLER_C_16__ #ifdef __SMALLER_C_32__ #ifdef __HUGE__ int setjmp(jmp_buf jb) { asm("mov ebx, [bp+8]\n" // jb "ror ebx, 4\n" "mov ds, bx\n" "shr ebx, 28"); // cs:ip in xip asm("mov eax, [bp+4]"); // return address asm("mov [bx], eax"); // flags (mainly for IF) asm("pushf"); asm("pop word [bx+4]"); // bp asm("mov ax, [bp]"); // caller's bp asm("mov [bx+8], ax"); // sp asm("lea ax, [bp+2*4]"); // caller's sp asm("mov [bx+12], ax"); // return 0 asm("xor eax, eax"); } void longjmp(jmp_buf jb, int val) { asm("mov eax, [bp+12]"); // val // if val is 0, make it 1 asm("or eax, eax"); asm("setz bl"); asm("or al, bl"); asm("mov ebx, [bp+8]\n" // jb "ror ebx, 4\n" "mov ds, bx\n" "shr ebx, 28"); // sp asm("mov sp, [bx+12]"); // bp asm("mov bp, [bx+8]"); // flags (mainly for IF) asm("push word [bx+4]"); // cs:ip in xip asm("push dword [bx]"); // return val asm("iret"); } #else // and now __SMALLER_C_32__, not __HUGE__ int setjmp(jmp_buf jb) { asm("mov ebx, [ebp+8]"); // jb // eip asm("mov eax, [ebp+4]"); // return address asm("mov [ebx], eax"); // flags (mainly for IF) asm("pushfd"); asm("pop dword [ebx+4]"); // ebp asm("mov eax, [ebp]"); // caller's ebp asm("mov [ebx+8], eax"); // esp asm("lea eax, [ebp+4*2]"); // caller's esp asm("mov [ebx+12], eax"); // return 0 asm("xor eax, eax"); } void longjmp(jmp_buf jb, int val) { asm("mov eax, [ebp+12]"); // val // if val is 0, make it 1 asm("or eax, eax"); asm("setz bl"); asm("or al, bl"); asm("mov ebx, [ebp+8]"); // jb // esp asm("mov esp, [ebx+12]"); // ebp asm("mov ebp, [ebx+8]"); // flags (mainly for IF) asm("push dword [ebx+4]"); // cs asm("push cs"); // eip asm("push dword [ebx]"); // return val asm("iretd"); } #endif // __HUGE__ #endif // __SMALLER_C_32__
37ee88ff974a21f267b209dba78800197c0c1477
c3c8be15eec9e6e9fffe7e46ed28baace52a3b1f
/BaseEquations/t9/t9.c
6ca27ce3c80fffe3246ff69ec8cd6c3554435c36
[]
no_license
lipegemmal/PETGYN_Study
7fec031220e1f92579590554ef0232bbc0b08ca9
caeeb128f22fd43829c5ca414e4047b2251732be
refs/heads/master
2020-04-29T05:41:00.295809
2019-12-04T18:24:28
2019-12-04T18:24:28
175,891,311
0
0
null
null
null
null
UTF-8
C
false
false
412
c
t9.c
#include <math.h> #include <stdio.h> double t9(double ca,double va,double xa,double fa,double z,double y1,double y2){ return ((3.6 * ca)/va) *(1 + ((3*xa+z)/(10000*fa)) + pow((xa/(900*fa)),3) + pow(z/(1600*fa),3) ) + pow(y1/300,2) + pow(y2/300,2) ; } int main(){ double a0,a1,a2,a3,a4,a5,a6; scanf("%lf%lf%lf%lf%lf%lf%lf", &a0,&a1,&a2,&a3,&a4,&a5,&a6); printf("%lf\n", t9(a0,a1,a2,a3,a4,a5,a6)); return 0; }