blob_id
stringlengths
40
40
directory_id
stringlengths
40
40
path
stringlengths
4
721
content_id
stringlengths
40
40
detected_licenses
listlengths
0
57
license_type
stringclasses
2 values
repo_name
stringlengths
5
91
snapshot_id
stringlengths
40
40
revision_id
stringlengths
40
40
branch_name
stringclasses
321 values
visit_date
timestamp[ns]date
2016-08-12 09:31:09
2023-09-06 10:45:07
revision_date
timestamp[ns]date
2010-09-28 14:01:40
2023-09-06 06:22:19
committer_date
timestamp[ns]date
2010-09-28 14:01:40
2023-09-06 06:22:19
github_id
int64
426
681M
star_events_count
int64
101
243k
fork_events_count
int64
0
110k
gha_license_id
stringclasses
23 values
gha_event_created_at
timestamp[ns]date
2012-06-28 18:51:49
2023-09-14 21:59:16
gha_created_at
timestamp[ns]date
2008-02-11 22:55:26
2023-08-10 11:14:58
gha_language
stringclasses
147 values
src_encoding
stringclasses
26 values
language
stringclasses
2 values
is_vendor
bool
2 classes
is_generated
bool
2 classes
length_bytes
int64
6
10.2M
extension
stringclasses
115 values
filename
stringlengths
3
113
content
stringlengths
6
10.2M
66d71cd91e207fcb425e82686c116d7f19bf4606
89ac799bd004042f913c9205abd22feaf847f5be
/src/Okajima/bullet.h
9023ea94e84a6da17fce721091033e7de934f5e4
[]
no_license
FoxdieTeam/mgs_reversing
de0b501e9a6318bf817e0d0f03af34c836a2f0b6
d057e3eb8bebeb645ca23db6ce690577268f59d5
refs/heads/master
2023-07-21T02:31:57.827478
2023-07-17T10:50:39
2023-07-17T10:50:39
223,033,157
270
35
null
2023-09-14T21:49:31
2019-11-20T21:44:13
C
UTF-8
C
false
false
1,277
h
bullet.h
#ifndef _BULLET_H #define _BULLET_H #include "libdg/libdg.h" #include "libgv/libgv.h" #include "Game/target.h" typedef struct Bullet_vecs { SVECTOR vecs[4]; } Bullet_vecs; typedef struct Bullet_0x130 { char field_0_pad[6]; short field_6; } Bullet_0x130; typedef struct Actor_Bullet { GV_ACT field_0_actor; int field_20; MATRIX field_24; TARGET field_44_target; DG_PRIM *field_8C_pPrim; SVECTOR field_90[8]; Bullet_vecs field_D0[2]; SVECTOR field_110; SVECTOR field_118; SVECTOR field_120; SVECTOR field_128; Bullet_0x130 *field_130; int field_134; int field_138; int field_13C; int field_140; int field_144_noise_len; int field_148_side; int field_14C; int field_150; int field_154_hp; int field_158; int field_15C; int field_160; int field_164; int field_168; int field_16C; } Actor_Bullet; STATIC_ASSERT_SIZE(Actor_Bullet, 0x170); GV_ACT *bullet_init_80076584(MATRIX *pMtx, int whichSide, int a3, int noiseLen); #endif // _BULLET_H
7ddcc8700cacddbc356dc37414635d4819552076
317410b28757af216145d23259d63fc96d07f613
/apps/spp_and_le/modules/bt/edr_emitter.c
e40224217f054d5717e8d0b2f2b3bb8799de5c75
[ "Apache-2.0" ]
permissive
Jieli-Tech/fw-AC63_BT_SDK
48c757dca7e8000ec763bf5466583a4cd8c4a11c
393d63758081d56f0bf0a39ac596bee32c33d493
refs/heads/master
2023-07-18T02:14:56.187266
2023-06-21T03:14:20
2023-06-21T03:14:20
272,586,610
113
76
Apache-2.0
2022-10-20T23:07:31
2020-06-16T02:02:15
C
UTF-8
C
false
false
19,917
c
edr_emitter.c
/************************************************************* 此文件函数主要是蓝牙发射器接口处理 **************************************************************/ #include "system/app_core.h" #include "system/includes.h" #include "app_config.h" #include "app_task.h" #include "btstack/btstack_task.h" #include "btcontroller_modules.h" #include "btstack/avctp_user.h" #include "classic/hci_lmp.h" #include "user_cfg.h" #include "vm.h" #include "app_main.h" #include "key_event_deal.h" #include "edr_emitter.h" /* #include "rcsp_bluetooth.h" */ #if (EDR_EMITTER_EN && TCFG_USER_EDR_ENABLE) #define LOG_TAG_CONST EDR_EM #define LOG_TAG "[EDR_EM]" #define LOG_ERROR_ENABLE #define LOG_DEBUG_ENABLE #define LOG_INFO_ENABLE #define LOG_DUMP_ENABLE #define LOG_CLI_ENABLE #include "debug.h" /* #undef log_info */ /* #define log_info y_printf */ #define SEARCH_BD_ADDR_LIMITED 0 //匹配mac地址搜索 #define SEARCH_BD_NAME_LIMITED 1 //匹配名字搜索 #define SEARCH_CUSTOM_LIMITED 2 //搜索结果自定义处理 #define SEARCH_NULL_LIMITED 3 //搜索到设备就直接连接,不限制 //搜索方式配置 #define SEARCH_LIMITED_MODE SEARCH_BD_NAME_LIMITED #define SEARCH_NAME_DEBUG 0 struct list_head inquiry_noname_list; struct inquiry_noname_remote { struct list_head entry; u8 match; s8 rssi; u8 addr[6]; u32 class; }; typedef struct { u8 emitter_mode: 2; u8 read_name_start: 1; u8 bt_search_busy: 1; u8 bt_connect_start: 1; u8 bt_emitter_start: 1; u8 res_bits: 2; } bt_user_var_t; static bt_user_var_t bt_user_private_var; #define __this (&bt_user_private_var) #if (SEARCH_LIMITED_MODE == SEARCH_BD_ADDR_LIMITED) static const u8 bd_addr_filt[][6] = { {0x38, 0x7C, 0x78, 0x1C, 0xFC, 0x02}, /*Bluetooth*/ }; #endif #if (SEARCH_LIMITED_MODE == SEARCH_BD_NAME_LIMITED) /* static const u8 bd_name_filt[][30] = { */ /* "BlueTooth_Keyboard 3.0", */ /* "AC630N_mx", */ /* }; */ static const *bd_name_filt; static u8 bd_name_filt_nums; #endif extern u16 get_emitter_curr_channel_state(); //=============================================================================== //define to Device ID SPEC #define BT_SDP_DID_VendorID 0x0201 #define BT_SDP_DID_ProductID 0x0202 #define BT_SDP_DID_Version 0x0203 #define BT_SDP_DID_VendorIDSource 0x0205 //define to hid server #define BT_SDP_HID_DescriptorList 0x0206 #define BT_PNP_INFO_ID 0x1200 #define BT_UUID_HID_DE 0x1124 /*----------------------------------------------------------------------------*/ /**@brief @param 无 @return 无 @note //协议栈回调输出 */ /*----------------------------------------------------------------------------*/ void sdp_decode_response_info_output(u16 service_uuid, u16 attribute_id, const u8 *packet, int size) { log_info("sdp_output:service_uuid= %04x,attribute_id= %04x,size= %d", service_uuid, attribute_id, size); /* put_buf(packet,size); */ switch (service_uuid) { case BT_PNP_INFO_ID: { switch (attribute_id) { case BT_SDP_DID_VendorID: case BT_SDP_DID_ProductID: case BT_SDP_DID_Version: case BT_SDP_DID_VendorIDSource: log_info("PNP_INFO,data_type= %d:", packet[0]); put_buf(packet + 1, size - 1); break; } } break; /* case BT_UUID_HID_DE: if (BT_SDP_HID_DescriptorList == attribute_id) { log_info("REPORT_MAP:"); put_buf(packet, size); } break; */ } } /*----------------------------------------------------------------------------*/ /**@brief @param 无 @return 无 @note */ /*----------------------------------------------------------------------------*/ static void __bt_search_device(void) { if (__this->bt_search_busy) { log_info("bt_search_busy >>>>>>>>>>>>>>>>>>>>>>>\n"); return; } user_send_cmd_prepare(USER_CTRL_WRITE_SCAN_DISABLE, 0, NULL); user_send_cmd_prepare(USER_CTRL_WRITE_CONN_DISABLE, 0, NULL); log_info("bt_search_start >>>>>>>>>\n"); __this->read_name_start = 0; __this->bt_search_busy = 1; u8 inquiry_length = 20; // inquiry_length * 1.28s user_send_cmd_prepare(USER_CTRL_SEARCH_DEVICE, 1, &inquiry_length); } /*----------------------------------------------------------------------------*/ /**@brief @param 无 @return 无 @note */ /*----------------------------------------------------------------------------*/ u8 bt_emitter_get_search_status() { return __this->bt_search_busy; } /*----------------------------------------------------------------------------*/ /**@brief @param 无 @return 无 @note */ /*----------------------------------------------------------------------------*/ void bt_emitter_stop_search_device(void) { if (__this->bt_search_busy) { __this->bt_search_busy = 0; log_info("%s\n", __FUNCTION__); user_send_cmd_prepare(USER_CTRL_INQUIRY_CANCEL, 0, NULL); } } /*----------------------------------------------------------------------------*/ /**@brief @param 无 @return 无 @note */ /*----------------------------------------------------------------------------*/ void bt_emitter_start_search_device(void) { if (__this->emitter_mode != BT_EMITTER_EN || __this->bt_search_busy) { return; } log_info("%s\n", __FUNCTION__); while (hci_standard_connect_check() == 0x80) { //wait profile connect ok; if (get_curr_channel_state()) { break; } os_time_dly(10); } ////断开链接 if (get_curr_channel_state() != 0) { user_send_cmd_prepare(USER_CTRL_POWER_OFF, 0, NULL); } else { if (hci_standard_connect_check()) { user_send_cmd_prepare(USER_CTRL_PAGE_CANCEL, 0, NULL); user_send_cmd_prepare(USER_CTRL_CONNECTION_CANCEL, 0, NULL); } } /* if there are some connected channel ,then disconnect*/ while (hci_standard_connect_check() != 0) { //wait disconnect; os_time_dly(10); } ////关闭可发现可链接 user_send_cmd_prepare(USER_CTRL_WRITE_SCAN_DISABLE, 0, NULL); user_send_cmd_prepare(USER_CTRL_WRITE_CONN_DISABLE, 0, NULL); ////切换样机状态 __bt_search_device(); } /*----------------------------------------------------------------------------*/ /**@brief @param 无 @return 无 @note */ /*----------------------------------------------------------------------------*/ bool bt_emitter_connect(u8 *mac) { if (__this->emitter_mode != BT_EMITTER_EN) { return false; } while (hci_standard_connect_check() == 0x80) { //wait profile connect ok; if (get_curr_channel_state()) { break; } os_time_dly(10); } ////断开链接 if (get_curr_channel_state() != 0) { user_send_cmd_prepare(USER_CTRL_POWER_OFF, 0, NULL); } else { if (hci_standard_connect_check()) { user_send_cmd_prepare(USER_CTRL_PAGE_CANCEL, 0, NULL); user_send_cmd_prepare(USER_CTRL_CONNECTION_CANCEL, 0, NULL); } } /* if there are some connected channel ,then disconnect*/ while (hci_standard_connect_check() != 0) { //wait disconnect; os_time_dly(10); } user_send_cmd_prepare(USER_CTRL_START_CONNEC_VIA_ADDR, 6, mac); return true; } /*----------------------------------------------------------------------------*/ /**@brief @param 无 @return 无 @note */ /*----------------------------------------------------------------------------*/ bool bt_emitter_connect_last_vm_device(void) { if (connect_last_device_from_vm()) { log_info("start connect device vm addr\n"); return true; } return false; } /*----------------------------------------------------------------------------*/ /**@brief @param 无 @return 无 @note */ /*----------------------------------------------------------------------------*/ void bt_emitter_role_set(u8 flag) { /*如果上一次操作记录跟传进来的参数一致,则不操作*/ if (__this->emitter_mode == flag) { return ; } while (hci_standard_connect_check() == 0x80) { //wait profile connect ok; if (__this->emitter_mode == BT_EMITTER_EN) { ///蓝牙发射器 log_info("cur_ch:0x%x", get_emitter_curr_channel_state()); if (get_emitter_curr_channel_state()) { break; } } else { log_info("cur_ch:0x%x", get_curr_channel_state()); if (get_curr_channel_state()) { break; } } os_time_dly(10); } ////断开链接 if ((get_curr_channel_state() != 0) || (get_emitter_curr_channel_state() != 0)) { user_send_cmd_prepare(USER_CTRL_POWER_OFF, 0, NULL); } else { if (hci_standard_connect_check()) { user_send_cmd_prepare(USER_CTRL_PAGE_CANCEL, 0, NULL); user_send_cmd_prepare(USER_CTRL_CONNECTION_CANCEL, 0, NULL); } } /* if there are some connected channel ,then disconnect*/ while (hci_standard_connect_check() != 0) { //wait disconnect; os_time_dly(10); } __this->emitter_mode = flag; if (flag == BT_EMITTER_EN) { ///蓝牙发射器 bredr_bulk_change(0); ////关闭可发现可链接 user_send_cmd_prepare(USER_CTRL_WRITE_SCAN_DISABLE, 0, NULL); user_send_cmd_prepare(USER_CTRL_WRITE_CONN_DISABLE, 0, NULL); ////切换样机状态 __set_emitter_enable_flag(1); ////开启搜索设备 if (0) { // (bt_emitter_connect_last_vm_device()) { log_info("start connect device vm addr\n"); } else { __bt_search_device(); } } } /*----------------------------------------------------------------------------*/ /**@brief 蓝牙变量初始化 @param 无 @return 无 @note */ /*----------------------------------------------------------------------------*/ void bt_emitter_init(void) { log_info("%s\n", __FUNCTION__); memset(__this, 0, sizeof(bt_user_var_t)); __this->bt_emitter_start = 1; INIT_LIST_HEAD(&inquiry_noname_list); lmp_set_sniff_establish_by_remote(1); } /*----------------------------------------------------------------------------*/ /**@brief 蓝牙配置搜索name @param 无 @return 无 @note */ /*----------------------------------------------------------------------------*/ void bt_emitter_set_match_name(const char *name_table, u8 name_count) { log_info("%s,bd_name_filt_nums= %d\n", __FUNCTION__, name_count); bd_name_filt = name_table; bd_name_filt_nums = name_count; } /*----------------------------------------------------------------------------*/ /**@brief 蓝牙搜索设备没有名字的设备,放进需要获取名字链表 @param status : !=0 获取成功 0:获取失败 addr:设备地址 name:设备名字 @return 无 @note */ /*----------------------------------------------------------------------------*/ void bt_emitter_search_noname(u8 status, u8 *addr, u8 *name) { struct inquiry_noname_remote *remote, *n; if (!__this->bt_emitter_start) { return ; } if (status) { log_info("remote_name fail!!!\n"); } else { log_info("remote_name: %s\n", name); } u8 res = 0; local_irq_disable(); if (status) { list_for_each_entry_safe(remote, n, &inquiry_noname_list, entry) { if (!memcmp(addr, remote->addr, 6)) { list_del(&remote->entry); free(remote); } } goto __find_next; } list_for_each_entry_safe(remote, n, &inquiry_noname_list, entry) { if (!memcmp(addr, remote->addr, 6)) { res = bt_emitter_search_result(name, strlen(name), addr, remote->class, remote->rssi); if (res) { __this->read_name_start = 0; remote->match = 1; user_send_cmd_prepare(USER_CTRL_INQUIRY_CANCEL, 0, NULL); local_irq_enable(); return; } list_del(&remote->entry); free(remote); } } __find_next: __this->read_name_start = 0; remote = NULL; if (!list_empty(&inquiry_noname_list)) { remote = list_first_entry(&inquiry_noname_list, struct inquiry_noname_remote, entry); } local_irq_enable(); if (remote) { __this->read_name_start = 1; user_send_cmd_prepare(USER_CTRL_READ_REMOTE_NAME, 6, remote->addr); } } /*----------------------------------------------------------------------------*/ /**@brief 蓝牙搜索时间结束 @param 无 @return 无 @note */ /*----------------------------------------------------------------------------*/ void bt_emitter_search_complete(u8 result) { struct inquiry_noname_remote *remote, *n; __this->bt_search_busy = 0; set_start_search_spp_device(0); u8 wait_connect_flag = 1; log_info("%s,%d\n", __FUNCTION__, __LINE__); if (__this->bt_connect_start) { __this->bt_connect_start = 0; log_info("connecting..."); return; } if (!list_empty(&inquiry_noname_list)) { user_send_cmd_prepare(USER_CTRL_PAGE_CANCEL, 0, NULL); } if (!result) { list_for_each_entry_safe(remote, n, &inquiry_noname_list, entry) { if (remote->match) { user_send_cmd_prepare(USER_CTRL_START_CONNEC_VIA_ADDR, 6, remote->addr); wait_connect_flag = 0; } list_del(&remote->entry); free(remote); } } __this->read_name_start = 0; if (wait_connect_flag) { /* log_info("wait conenct\n"); */ user_send_cmd_prepare(USER_CTRL_WRITE_SCAN_DISABLE, 0, NULL); if (!result) { user_send_cmd_prepare(USER_CTRL_WRITE_CONN_ENABLE, 0, NULL); } user_send_cmd_prepare(USER_CTRL_PAGE_CANCEL, 0, NULL); __bt_search_device(); /* #endif */ } } /*----------------------------------------------------------------------------*/ /**@brief 蓝牙搜索通过地址过滤 @param 无 @return 无 @note */ /*----------------------------------------------------------------------------*/ static u8 __search_bd_addr_filt(u8 *addr) { #if (SEARCH_LIMITED_MODE == SEARCH_BD_ADDR_LIMITED) u8 i; log_info("bd_addr:"); log_info_hexdump(addr, 6); for (i = 0; i < (sizeof(bd_addr_filt) / sizeof(bd_addr_filt[0])); i++) { if (memcmp(addr, bd_addr_filt[i], 6) == 0) { log_info("bd_addr match:%d\n", i); return TRUE; } } #endif return FALSE; } /*----------------------------------------------------------------------------*/ /**@brief 蓝牙搜索通过名字过滤 @param 无 @return 无 @note */ /*----------------------------------------------------------------------------*/ static u8 __search_bd_name_filt(char *data, u8 len, u32 dev_class, char rssi) { #if (SEARCH_LIMITED_MODE == SEARCH_BD_NAME_LIMITED) char bd_name[64] = {0}; u8 i; char *targe_name = NULL; char char_a = 0, char_b = 0; if ((len > (sizeof(bd_name))) || (len == 0)) { //printf("bd_name_len error:%d\n", len); return FALSE; } memset(bd_name, 0, sizeof(bd_name)); memcpy(bd_name, data, len); log_info("name:%s,len:%d,class %x ,rssi %d\n", bd_name, len, dev_class, rssi); #if SEARCH_NAME_DEBUG extern char *get_edr_name(void); printf("tar name:%s,len:%d\n", get_edr_name(), strlen(get_edr_name())); targe_name = (char *)get_edr_name(); #if 1 //不区分大小写 for (i = 0; i < len; i++) { char_a = bd_name[i]; char_b = targe_name[i]; if ('A' <= char_a && char_a <= 'Z') { char_a += 32; //转换成小写 } if ('A' <= char_b && char_b <= 'Z') { char_b += 32; //转换成小写 } //printf("{%d-%d}",char_a,char_b); if (char_a != char_b) { return FALSE; } } log_info("\n*****find dev ok******\n"); return TRUE; #else //区分大小写 if (memcmp(data, bt_get_emitter_connect_name(), len) == 0) { log_info("\n*****find dev ok******\n"); return TRUE; } return FALSE; #endif #else /* for (i = 0; i < (sizeof(bd_name_filt) / sizeof(bd_name_filt[0])); i++) { */ for (i = 0; i < bd_name_filt_nums; i++) { if (memcmp(data, bd_name_filt[i], len) == 0) { puts("\n*****find dev ok******\n"); return TRUE; } } return FALSE; #endif #else return FALSE; #endif } /*----------------------------------------------------------------------------*/ /**@brief 蓝牙搜索结果回调处理 @param name : 设备名字 name_len: 设备名字长度 addr: 设备地址 dev_class: 设备类型 rssi: 设备信号强度 @return 无 @note 蓝牙设备搜索结果,可以做名字/地址过滤,也可以保存搜到的所有设备 在选择一个进行连接,获取其他你想要的操作。 返回TRUE,表示搜到指定的想要的设备,搜索结束,直接连接当前设备 返回FALSE,则继续搜索,直到搜索完成或者超时 */ /*----------------------------------------------------------------------------*/ u8 bt_emitter_search_result(char *name, u8 name_len, u8 *addr, u32 dev_class, char rssi) { u8 ret = FALSE; /* put_buf(addr,6); */ #if (SEARCH_LIMITED_MODE == SEARCH_BD_NAME_LIMITED) if (name == NULL) { struct inquiry_noname_remote *remote = malloc(sizeof(struct inquiry_noname_remote)); log_info("search no_name:"); put_buf(addr, 6); remote->match = 0; remote->class = dev_class; remote->rssi = rssi; memcpy(remote->addr, addr, 6); local_irq_disable(); list_add_tail(&remote->entry, &inquiry_noname_list); local_irq_enable(); if (__this->read_name_start == 0) { __this->read_name_start = 1; user_send_cmd_prepare(USER_CTRL_READ_REMOTE_NAME, 6, addr); } } #endif /* #if (RCSP_BTMATE_EN) */ /* rcsp_msg_post(RCSP_MSG_BT_SCAN, 5, dev_class, addr, rssi, name, name_len); */ /* #endif */ #if (SEARCH_LIMITED_MODE == SEARCH_BD_NAME_LIMITED) ret = __search_bd_name_filt(name, name_len, dev_class, rssi); #endif #if (SEARCH_LIMITED_MODE == SEARCH_BD_ADDR_LIMITED) ret = __search_bd_addr_filt(addr); #endif #if (SEARCH_LIMITED_MODE == SEARCH_CUSTOM_LIMITED) /*以下为搜索结果自定义处理*/ char bt_name[63] = {0}; u8 len; if (name_len == 0) { log_info("No_eir\n"); } else { len = (name_len > 63) ? 63 : name_len; /* display bd_name */ memcpy(bt_name, name, len); log_info("name:%s,len:%d,class %x ,rssi %d\n", bt_name, name_len, dev_class, rssi); } /* display bd_addr */ log_info_hexdump(addr, 6); /* You can connect the specified bd_addr by below api */ //user_send_cmd_prepare(USER_CTRL_START_CONNEC_VIA_ADDR,6,addr); ret = FALSE; #endif #if (SEARCH_LIMITED_MODE == SEARCH_NULL_LIMITED) /*没有指定限制,则搜到什么就连接什么*/ ret = TRUE; #endif if (ret) { log_info("get device,start to connect\n"); __this->bt_connect_start = 1; } return ret; } #endif //#if (EDR_EMITTER_EN && TCFG_USER_EDR_ENABLE)
2e89cd691c7170823298d1947a55ea52ffc077c8
fb0f9abad373cd635c2635bbdf491ea0f32da5ff
/src/native/external/libunwind/src/sh/Gis_signal_frame.c
4481fe1a498e1122cf2848e81aa7206857b7fb8c
[ "MIT" ]
permissive
dotnet/runtime
f6fd23936752e202f8e4d6d94f3a4f3b0e77f58f
47bb554d298e1e34c4e3895d7731e18ad1c47d02
refs/heads/main
2023-09-03T15:35:46.493337
2023-09-03T08:13:23
2023-09-03T08:13:23
210,716,005
13,765
5,179
MIT
2023-09-14T21:58:52
2019-09-24T23:36:39
C#
UTF-8
C
false
false
3,396
c
Gis_signal_frame.c
/* libunwind - a platform-independent unwind library Copyright (C) 2012 Tommi Rantala <tt.rantala@gmail.com> This file is part of libunwind. 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 "unwind_i.h" /* Disassembly of the Linux VDSO sigreturn functions: 00000000 <__kernel_sigreturn>: 0: 05 93 mov.w e <__kernel_sigreturn+0xe>,r3 ! 77 2: 10 c3 trapa #16 4: 0b 20 or r0,r0 6: 0b 20 or r0,r0 8: 0b 20 or r0,r0 a: 0b 20 or r0,r0 c: 0b 20 or r0,r0 e: 77 00 .word 0x0077 10: 09 00 nop 12: 09 00 nop 14: 09 00 nop 16: 09 00 nop 18: 09 00 nop 1a: 09 00 nop 1c: 09 00 nop 1e: 09 00 nop 00000020 <__kernel_rt_sigreturn>: 20: 05 93 mov.w 2e <__kernel_rt_sigreturn+0xe>,r3 ! ad 22: 10 c3 trapa #16 24: 0b 20 or r0,r0 26: 0b 20 or r0,r0 28: 0b 20 or r0,r0 2a: 0b 20 or r0,r0 2c: 0b 20 or r0,r0 2e: ad 00 mov.w @(r0,r10),r0 30: 09 00 nop 32: 09 00 nop 34: 09 00 nop 36: 09 00 nop 38: 09 00 nop 3a: 09 00 nop 3c: 09 00 nop 3e: 09 00 nop */ int unw_is_signal_frame (unw_cursor_t *cursor) { #ifdef __linux__ struct cursor *c = (struct cursor *) cursor; unw_word_t w0, ip; unw_addr_space_t as; unw_accessors_t *a; void *arg; int ret; as = c->dwarf.as; a = unw_get_accessors_int (as); arg = c->dwarf.as_arg; ip = c->dwarf.ip; ret = (*a->access_mem) (as, ip, &w0, 0, arg); if (ret < 0) return ret; if (w0 != 0xc3109305) return 0; ret = (*a->access_mem) (as, ip+4, &w0, 0, arg); if (ret < 0) return ret; if (w0 != 0x200b200b) return 0; ret = (*a->access_mem) (as, ip+8, &w0, 0, arg); if (ret < 0) return ret; if (w0 != 0x200b200b) return 0; ret = (*a->access_mem) (as, ip+12, &w0, 0, arg); if (ret < 0) return ret; if (w0 == 0x0077200b) return 1; /* non-RT */ else if (w0 == 0x00ad200b) return 2; /* RT */ /* does not look like a signal frame */ return 0; #else return -UNW_ENOINFO; #endif }
7ad0bd6b2bfaf5b571748992d8086b55206d6921
9de0cec678bc4a3bec2b4adabef9f39ff5b4afac
/PWGCF/FEMTOSCOPY/macros/Train/MS/2015/AddTaskFemtoAzimtuhalHBT.C
aa526878dfb70e6be98d2c2ee518fb7707fa03b0
[]
permissive
alisw/AliPhysics
91bf1bd01ab2af656a25ff10b25e618a63667d3e
5df28b2b415e78e81273b0d9bf5c1b99feda3348
refs/heads/master
2023-08-31T20:41:44.927176
2023-08-31T14:51:12
2023-08-31T14:51:12
61,661,378
129
1,150
BSD-3-Clause
2023-09-14T18:48:45
2016-06-21T19:31:29
C++
UTF-8
C
false
false
4,577
c
AddTaskFemtoAzimtuhalHBT.C
//============================================================================= // // *** AddTaskFemtoAzimtuhalHBT.C *** // // This macro initialize a complete AnalysisTask object for femtoscopy. // //============================================================================= AliAnalysisTaskFemto *AddTaskFemtoAzimtuhalHBT(TString configMacroName="ConfigFemtoAnalysis.C", const char *containerName="femtolist", const char *configMacroParameters="10,20,3", const char *containername="femto") { // Creates a proton analysis task and adds it to the analysis manager. // A. Get the pointer to the existing analysis manager via the static access method. //============================================================================== AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager(); if (!mgr) { Error("AddTaskFemtoAzimtuhalHBT", "No analysis manager to connect to."); return NULL; } TString inputDataType = mgr->GetInputEventHandler()->GetDataType(); // can be "ESD" or "AOD" Bool_t useEtaGap=kFALSE; Float_t etaGap=0.; Bool_t posTPCAOD=kFALSE; // TString containername = "EPStat_ttd"; // B. Check the analysis type using the event handlers connected to the analysis // manager. The availability of MC handler cann also be checked here. //============================================================================== if (!mgr->GetInputEventHandler()) { ::Error("AddTaskFemtoAzimtuhalHBT", "This task requires an input event handler"); return NULL; } TString type = mgr->GetInputEventHandler()->GetDataType(); // can be "ESD" or "AOD" // cout << "Found " <<type << " event handler" << endl; //gROOT->LoadMacro("AliEPSelectionTask3.cxx+g"); //gROOT->LoadMacro("AddTaskEventplane.C"); //AliEPSelectionTask3* epsel = AddTaskEventplane(); AliEPSelectionTask *eventplaneTask = new AliEPSelectionTask("EventplaneSelection4"); eventplaneTask->SelectCollisionCandidates(AliVEvent::kINT7); if (inputDataType == "AOD"){ eventplaneTask->SetInput("AOD"); } eventplaneTask->SetTrackType("TPC"); eventplaneTask->SetUsePtWeight(); eventplaneTask->SetUsePhiWeight(); eventplaneTask->SetSaveTrackContribution(); if(useEtaGap){ eventplaneTask->SetSubeventsSplitMethod(AliEPSelectionTask3::kEta); eventplaneTask->SetEtaGap(etaGap); } if(posTPCAOD){ eventplaneTask->SetPersonalAODtrackCuts(128,0.,0.8,0.15,20.); eventplaneTask->SetSubeventsSplitMethod(AliEPSelectionTask3::kRandom); } mgr->AddTask(eventplaneTask); // C. Create the task, add it to manager. //=========================================================================== // gSystem->SetIncludePath("-I$ROOTSYS/include -I./PWG2AOD/AOD -I./PWG2femtoscopy/FEMTOSCOPY/AliFemto -I./PWG2femtoscopyUser/FEMTOSCOPY/AliFemtoUser -I$ALICE_PHYSICS/include"); if (TProofMgr::GetListOfManagers()->GetEntries()) { // if (dynamic_cast<TProofLite *> gProof) { // char *macrocommand[10000]; // sprintf(macrocommand, ".L %s", configMacroName); // gProof->Exec(macrocommand); // } // else gProof->Load(configMacroName); } // gROOT->LoadMacro("ConfigFemtoAnalysis.C++"); AliAnalysisTaskFemto *taskfemto = new AliAnalysisTaskFemto("TaskFemto",configMacroName,configMacroParameters,kFALSE); taskfemto->SelectCollisionCandidates(AliVEvent::kINT7); mgr->AddTask(taskfemto); // D. Configure the analysis task. Extra parameters can be used via optional // arguments of the AddTaskXXX() function. //=========================================================================== // E. Create ONLY the output containers for the data produced by the task. // Get and connect other common input/output containers via the manager as below //============================================================================== TString outputfile = AliAnalysisManager::GetCommonFileName(); // outputfile += ":PWG2FEMTO"; AliAnalysisDataContainer *cout_femto = mgr->CreateContainer(containerName, TList::Class(), AliAnalysisManager::kOutputContainer,outputfile); mgr->ConnectInput(taskfemto, 0, mgr->GetCommonInputContainer()); mgr->ConnectOutput(taskfemto, 0, cout_femto); AliAnalysisDataContainer *cinput0 = mgr->GetCommonInputContainer(); AliAnalysisDataContainer *coutput1 = mgr->CreateContainer(containername, TList::Class(), AliAnalysisManager::kOutputContainer,outputfile); mgr->ConnectInput(eventplaneTask, 0, mgr->GetCommonInputContainer()); mgr->ConnectOutput(eventplaneTask,1,coutput1); // Return task pointer at the end return taskfemto; }
8b3b7c86d4fb1b7712421d262c683890d4fdf859
c59784458e4dcb34eadd6941bc4297c28c1a7e53
/Compilers/glcc/gigatron/libc/_fwrite.c
841cdb57634629ed8c18f4fb337f433e64c37da2
[ "LicenseRef-scancode-public-domain", "LicenseRef-scancode-unknown-license-reference", "LicenseRef-scancode-proprietary-license", "GPL-1.0-or-later", "BSD-2-Clause" ]
permissive
kervinck/gigatron-rom
42af9ce548d34d64ee667f662337ea7aa6d331e8
5d24889a661793ef0a9fb8d714bab9127307ee30
refs/heads/master
2023-07-30T02:11:24.748356
2023-07-07T06:27:20
2023-07-07T06:27:20
106,879,621
216
85
BSD-2-Clause
2023-08-08T09:40:32
2017-10-13T22:40:14
C
UTF-8
C
false
false
412
c
_fwrite.c
#include "_stdio.h" size_t _fwrite(register FILE *fp, register const char *buf, register size_t sz) { register int n; register size_t written = 0; register int (*write)(FILE*,const char*,size_t) = fp->_v->write; if (_schkwrite(fp)) return 0; while (written < sz) { n = (*write)(fp, buf + written, sz - written); if (n <= 0) { _serror(fp, EIO); break; } written += n; } return written; }
c74508cb42336341afe0c369b1501e855c753af9
e65a4dbfbfb0e54e59787ba7741efee12f7687f3
/security/pgpin/files/patch-armor.c
df2d953c9b375a7fdbd2333ac024c7badddec219
[ "BSD-2-Clause" ]
permissive
freebsd/freebsd-ports
86f2e89d43913412c4f6b2be3e255bc0945eac12
605a2983f245ac63f5420e023e7dce56898ad801
refs/heads/main
2023-08-30T21:46:28.720924
2023-08-30T19:33:44
2023-08-30T19:33:44
1,803,961
916
918
NOASSERTION
2023-09-08T04:06:26
2011-05-26T11:15:35
null
UTF-8
C
false
false
1,572
c
patch-armor.c
--- armor.c.orig 1998-01-12 08:13:03 UTC +++ armor.c @@ -343,7 +343,7 @@ copyline(FILE * in, FILE * out) * idea. */ static int -getline(char *buf, int n, FILE * f) +get_line(char *buf, int n, FILE * f) { int state; char *p; @@ -376,7 +376,7 @@ getline(char *buf, int n, FILE * f) return 0; /* Out of buffer space */ } } /* for (;;) */ -} /* getline */ +} /* get_line */ #if 1 /* This limit is advisory only; longer lines are handled properly. @@ -547,7 +547,7 @@ armor_file(char *infilename, char *outfi return 1; } fprintf(outFile, "-----BEGIN PGP SIGNED MESSAGE-----\n\n"); - while ((i = getline(buffer, sizeof buffer, clearFile)) >= 0) { + while ((i = get_line(buffer, sizeof buffer, clearFile)) >= 0) { /* Quote lines beginning with '-' as per RFC1113; * Also quote lines beginning with "From "; this is * for Unix mailers which add ">" to such lines. @@ -1231,7 +1231,7 @@ LANG("\n\007Unable to write ciphertext o for (;;) { ++infile_line; nline = status; - status = getline(buf, sizeof buf, in); + status = get_line(buf, sizeof buf, in); if (status < 0) { fprintf(pgpout, LANG("ERROR: ASCII armor decode input ended unexpectedly!\n")); @@ -1249,7 +1249,7 @@ LANG("ERROR: ASCII armor decode input en /* Copy trailing part of line, if any. */ if (!status) status = copyline(in, litout); - /* Ignore error; getline will discover it again */ + /* Ignore error; get_line will discover it again */ } fflush(litout); if (ferror(litout)) {
e1bd7753d18daf09e1c5815d94b528d16569e880
0ab22620ebb8b0301c353bd09a4d4c2108f6b109
/unittests/general/Several/bin32/firebird/examples/udf/ib_udf.h
31a7c1c3cacfcff716be06986ec3c03cd7e2558e
[ "Apache-2.0" ]
permissive
danieleteti/delphimvcframework
f31bd2964f61251b63f54bcd0454c96b22fa951d
03b0463ca2116779433288b1ef4b2c8d2cdfbb90
refs/heads/master
2023-09-04T11:54:06.720380
2023-09-04T09:34:18
2023-09-04T09:34:18
36,435,897
1,238
444
Apache-2.0
2023-09-04T09:34:37
2015-05-28T12:08:43
Pascal
UTF-8
C
false
false
1,347
h
ib_udf.h
/* * The contents of this file are subject to the Interbase Public * License Version 1.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy * of the License at http://www.Inprise.com/IPL.html * * Software distributed under the License is distributed on an * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express * or implied. See the License for the specific language governing * rights and limitations under the License. * * The Original Code was created by Inprise Corporation * and its predecessors. Portions created by Inprise Corporation are * Copyright (C) Inprise Corporation. * * All Rights Reserved. * Contributor(s): ______________________________________. */ #if defined(__cplusplus) && defined(DARWIN) #include "firebird.h" #define EXPORT API_ROUTINE #else #define EXPORT #endif #define MATHERR matherr #include <stdarg.h> #define IB_E 2.7182818284590452354 #define IB_PI 3.14159265358979323846 #define IB_PI_2 1.57079632679489661923 #define IB_PI_4 0.78539816339744830962 #define IB_1_PI 0.31830988618379067154 #define IB_2_PI 0.63661977236758134308 #define IB_2_SQRTPI 1.12837916709551257390 #define IB_SQRT2 1.41421356237309504880 #define IB_SQRT1_2 0.70710678118654752440
eeabf04947beefbf4853c25928a1a15f89ba4db7
3a30cfb29aac91e5c75d4dbcefddfd1f34d5f18c
/c-tests/gcc/960302-1.c
de7553141a08b0df41f88bfdce859f4fc6926413
[ "GPL-3.0-only", "GPL-2.0-only", "MIT", "MPL-1.0", "LicenseRef-scancode-warranty-disclaimer", "Apache-2.0", "LGPL-2.0-only" ]
permissive
vnmakarov/mir
a1725bc9c828e8580df6b7ae94e04175db8abe93
928e28fb3acaa50d051a906e76a55cc48a556574
refs/heads/master
2023-09-02T11:10:37.434581
2023-08-25T19:25:40
2023-08-25T19:25:40
178,932,492
2,005
156
MIT
2023-08-01T20:29:59
2019-04-01T19:24:56
C
UTF-8
C
false
false
249
c
960302-1.c
extern void exit (int); long a = 1; foo () { switch (a % 2 % 2 % 2 % 2 % 2 % 2 % 2 % 2) { case 0: return 0; case 1: return 1; default: return -1; } } main () { if (foo () != 1) abort (); exit (0); }
df94ecc1fd4e4581f214f294677c9e79dfd0fc0a
8cfa5dbe99dd5b2c8913e35a41395c64b1ea2740
/algorithms/sorting/recursive_selection_sort.c
3904228f69b095a1eb62a49d168ce328301e5f92
[ "MIT" ]
permissive
AllAlgorithms/c
cf925338018a94d4952203181ba6aab0ea921bef
4e6e311a95d5ce64b953faf83edca351813d262c
refs/heads/master
2023-08-30T12:51:56.967619
2022-06-17T02:50:03
2022-06-17T02:50:03
149,231,271
1,536
630
MIT
2023-08-27T00:09:50
2018-09-18T04:57:57
C
UTF-8
C
false
false
1,127
c
recursive_selection_sort.c
//************************************** // C implementation of recursive selection sort // // Author: Rafael Rodrigues Silva //************************************** #include<stdio.h> // A utility function to swap two elements void swap(int* a, int* b) { int t = *a; *a = *b; *b = t; } ///selection int search_smallest(int V[],int i,int j,int smallest){ if(i<=j) return smallest; if(V[smallest]>V[j]) smallest=j; search_smallest(V,i,j+1,smallest); } void recursive_selection_sort(int V[],int vt,int index){ if(index>=vt) return; int smallest=search_smallest(V,vt,index,index); if(V[index]!=V[smallest]) swap(&V[index],&V[smallest]); recursive_selection_sort(V,vt,index+1); } /* UTILITY FUNCTIONS */ /* Function to print an array */ void printArray(int A[], int size) { int i; for (i=0; i < size; i++) printf("%d ", A[i]); printf("\n"); } int main() { int arr[] = {12, 11, 13, 5, 6}; int n = sizeof(arr)/sizeof(arr[0]); recursive_selection_sort(arr,n,0); printArray(arr, n); return 0; }
dcd32f7733d2625bc2eb70dfe08b76d10ddac1f3
aa3befea459382dc5c01c925653d54f435b3fb0f
/include/nuttx/fs/loopmtd.h
eadc41365d542a8c5e81498baaf1b05244ab350f
[ "MIT-open-group", "BSD-3-Clause", "HPND-sell-variant", "BSD-4-Clause-UC", "LicenseRef-scancode-warranty-disclaimer", "MIT-0", "LicenseRef-scancode-bsd-atmel", "LicenseRef-scancode-gary-s-brown", "LicenseRef-scancode-proprietary-license", "SunPro", "MIT", "LicenseRef-scancode-public-domain-disclaimer", "LicenseRef-scancode-other-permissive", "HPND", "ISC", "Apache-2.0", "LicenseRef-scancode-public-domain", "BSD-2-Clause", "GPL-1.0-or-later", "CC-BY-2.0", "CC-BY-4.0" ]
permissive
apache/nuttx
14519a7bff4a87935d94fb8fb2b19edb501c7cec
606b6d9310fb25c7d92c6f95bf61737e3c79fa0f
refs/heads/master
2023-08-25T06:55:45.822534
2023-08-23T16:03:31
2023-08-24T21:25:47
228,103,273
407
241
Apache-2.0
2023-09-14T18:26:05
2019-12-14T23:27:55
C
UTF-8
C
false
false
3,554
h
loopmtd.h
/**************************************************************************** * include/nuttx/fs/loopmtd.h * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. The * ASF licenses this file to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance with the * License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. * ****************************************************************************/ #ifndef __INCLUDE_NUTTX_FS_LOOPMTD_H #define __INCLUDE_NUTTX_FS_LOOPMTD_H /**************************************************************************** * Included Files ****************************************************************************/ #include <nuttx/config.h> #include <sys/types.h> #include <sys/ioctl.h> #include <stdint.h> #include <stdbool.h> /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ #ifdef CONFIG_MTD_LOOP /* Loop device IOCTL commands */ /* Command: MTD_LOOPIOC_SETUP * Description: Setup the loop device * Argument: A pointer to a read-only instance of struct losetup_s. * Dependencies: The loop device must be enabled (CONFIG_MTD_LOOP=y) */ /* Command: MTD_LOOPIOC_TEARDOWN * Description: Teardown a loop device previously setup vis LOOPIOC_SETUP * Argument: A read-able pointer to the path of the device to be * torn down * Dependencies: The loop device must be enabled (CONFIG_MTD_LOOP=y) */ #define MTD_LOOPIOC_SETUP _LOOPIOC(0x0001) #define MTD_LOOPIOC_TEARDOWN _LOOPIOC(0x0002) #endif /**************************************************************************** * Public Types ****************************************************************************/ #ifdef CONFIG_MTD_LOOP /* This is the structure referred to in the argument to the LOOPIOC_SETUP * IOCTL command. */ struct mtd_losetup_s { FAR const char *devname; /* The loop mtd device to be created */ FAR const char *filename; /* The file or character device to use */ size_t erasesize; /* The erase size to use on the file */ size_t sectsize; /* The sector / page size of the file */ off_t offset; /* An offset that may be applied to the device */ }; #endif /**************************************************************************** * Public Data ****************************************************************************/ #ifndef __ASSEMBLY__ #ifdef __cplusplus #define EXTERN extern "C" extern "C" { #else #define EXTERN extern #endif /**************************************************************************** * Public Function Prototypes ****************************************************************************/ #ifdef CONFIG_MTD_LOOP int mtd_loop_register(void); #endif #undef EXTERN #ifdef __cplusplus } #endif #endif /* __ASSEMBLY__ */ #endif /* __INCLUDE_NUTTX_FS_LOOPMTD_H */
1fbe367a464c07480d75efe95425480829e83898
88ae8695987ada722184307301e221e1ba3cc2fa
/third_party/ffmpeg/libavfilter/af_dynaudnorm.c
e9d8ad8ec86c12c49a3112307f7cd2343b16e6fe
[ "BSD-3-Clause", "LGPL-2.1-only", "LGPL-3.0-only", "LGPL-2.0-or-later", "GPL-1.0-or-later", "GPL-2.0-only", "LGPL-2.1-or-later", "GPL-3.0-or-later", "LGPL-3.0-or-later", "IJG", "LicenseRef-scancode-other-permissive", "MIT", "GPL-2.0-or-later", "Apache-2.0", "GPL-3.0-only" ]
permissive
iridium-browser/iridium-browser
71d9c5ff76e014e6900b825f67389ab0ccd01329
5ee297f53dc7f8e70183031cff62f37b0f19d25f
refs/heads/master
2023-08-03T16:44:16.844552
2023-07-20T15:17:00
2023-07-23T16:09:30
220,016,632
341
40
BSD-3-Clause
2021-08-13T13:54:45
2019-11-06T14:32:31
null
UTF-8
C
false
false
35,603
c
af_dynaudnorm.c
/* * Dynamic Audio Normalizer * Copyright (c) 2015 LoRd_MuldeR <mulder2@gmx.de>. Some rights reserved. * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /** * @file * Dynamic Audio Normalizer */ #include <float.h> #include "libavutil/avassert.h" #include "libavutil/channel_layout.h" #include "libavutil/eval.h" #include "libavutil/opt.h" #define MIN_FILTER_SIZE 3 #define MAX_FILTER_SIZE 301 #define FF_BUFQUEUE_SIZE (MAX_FILTER_SIZE + 1) #include "libavfilter/bufferqueue.h" #include "audio.h" #include "avfilter.h" #include "filters.h" #include "internal.h" static const char * const var_names[] = { "ch", ///< the value of the current channel "sn", ///< number of samples "nb_channels", "t", ///< timestamp expressed in seconds "sr", ///< sample rate "p", ///< peak value NULL }; enum var_name { VAR_CH, VAR_SN, VAR_NB_CHANNELS, VAR_T, VAR_SR, VAR_P, VAR_VARS_NB }; typedef struct local_gain { double max_gain; double threshold; } local_gain; typedef struct cqueue { double *elements; int size; int max_size; int nb_elements; } cqueue; typedef struct DynamicAudioNormalizerContext { const AVClass *class; struct FFBufQueue queue; int frame_len; int frame_len_msec; int filter_size; int dc_correction; int channels_coupled; int alt_boundary_mode; double overlap; char *expr_str; double peak_value; double max_amplification; double target_rms; double compress_factor; double threshold; double *prev_amplification_factor; double *dc_correction_value; double *compress_threshold; double *weights; int channels; int sample_advance; int eof; char *channels_to_filter; AVChannelLayout ch_layout; int64_t pts; cqueue **gain_history_original; cqueue **gain_history_minimum; cqueue **gain_history_smoothed; cqueue **threshold_history; cqueue *is_enabled; AVFrame *window; AVExpr *expr; double var_values[VAR_VARS_NB]; } DynamicAudioNormalizerContext; typedef struct ThreadData { AVFrame *in, *out; int enabled; } ThreadData; #define OFFSET(x) offsetof(DynamicAudioNormalizerContext, x) #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM static const AVOption dynaudnorm_options[] = { { "framelen", "set the frame length in msec", OFFSET(frame_len_msec), AV_OPT_TYPE_INT, {.i64 = 500}, 10, 8000, FLAGS }, { "f", "set the frame length in msec", OFFSET(frame_len_msec), AV_OPT_TYPE_INT, {.i64 = 500}, 10, 8000, FLAGS }, { "gausssize", "set the filter size", OFFSET(filter_size), AV_OPT_TYPE_INT, {.i64 = 31}, 3, 301, FLAGS }, { "g", "set the filter size", OFFSET(filter_size), AV_OPT_TYPE_INT, {.i64 = 31}, 3, 301, FLAGS }, { "peak", "set the peak value", OFFSET(peak_value), AV_OPT_TYPE_DOUBLE, {.dbl = 0.95}, 0.0, 1.0, FLAGS }, { "p", "set the peak value", OFFSET(peak_value), AV_OPT_TYPE_DOUBLE, {.dbl = 0.95}, 0.0, 1.0, FLAGS }, { "maxgain", "set the max amplification", OFFSET(max_amplification), AV_OPT_TYPE_DOUBLE, {.dbl = 10.0}, 1.0, 100.0, FLAGS }, { "m", "set the max amplification", OFFSET(max_amplification), AV_OPT_TYPE_DOUBLE, {.dbl = 10.0}, 1.0, 100.0, FLAGS }, { "targetrms", "set the target RMS", OFFSET(target_rms), AV_OPT_TYPE_DOUBLE, {.dbl = 0.0}, 0.0, 1.0, FLAGS }, { "r", "set the target RMS", OFFSET(target_rms), AV_OPT_TYPE_DOUBLE, {.dbl = 0.0}, 0.0, 1.0, FLAGS }, { "coupling", "set channel coupling", OFFSET(channels_coupled), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, FLAGS }, { "n", "set channel coupling", OFFSET(channels_coupled), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, FLAGS }, { "correctdc", "set DC correction", OFFSET(dc_correction), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, FLAGS }, { "c", "set DC correction", OFFSET(dc_correction), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, FLAGS }, { "altboundary", "set alternative boundary mode", OFFSET(alt_boundary_mode), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, FLAGS }, { "b", "set alternative boundary mode", OFFSET(alt_boundary_mode), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, FLAGS }, { "compress", "set the compress factor", OFFSET(compress_factor), AV_OPT_TYPE_DOUBLE, {.dbl = 0.0}, 0.0, 30.0, FLAGS }, { "s", "set the compress factor", OFFSET(compress_factor), AV_OPT_TYPE_DOUBLE, {.dbl = 0.0}, 0.0, 30.0, FLAGS }, { "threshold", "set the threshold value", OFFSET(threshold), AV_OPT_TYPE_DOUBLE, {.dbl = 0.0}, 0.0, 1.0, FLAGS }, { "t", "set the threshold value", OFFSET(threshold), AV_OPT_TYPE_DOUBLE, {.dbl = 0.0}, 0.0, 1.0, FLAGS }, { "channels", "set channels to filter", OFFSET(channels_to_filter),AV_OPT_TYPE_STRING, {.str="all"}, 0, 0, FLAGS }, { "h", "set channels to filter", OFFSET(channels_to_filter),AV_OPT_TYPE_STRING, {.str="all"}, 0, 0, FLAGS }, { "overlap", "set the frame overlap", OFFSET(overlap), AV_OPT_TYPE_DOUBLE, {.dbl=.0}, 0.0, 1.0, FLAGS }, { "o", "set the frame overlap", OFFSET(overlap), AV_OPT_TYPE_DOUBLE, {.dbl=.0}, 0.0, 1.0, FLAGS }, { "curve", "set the custom peak mapping curve",OFFSET(expr_str), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS }, { "v", "set the custom peak mapping curve",OFFSET(expr_str), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS }, { NULL } }; AVFILTER_DEFINE_CLASS(dynaudnorm); static av_cold int init(AVFilterContext *ctx) { DynamicAudioNormalizerContext *s = ctx->priv; if (!(s->filter_size & 1)) { av_log(ctx, AV_LOG_WARNING, "filter size %d is invalid. Changing to an odd value.\n", s->filter_size); s->filter_size |= 1; } return 0; } static inline int frame_size(int sample_rate, int frame_len_msec) { const int frame_size = lrint((double)sample_rate * (frame_len_msec / 1000.0)); return frame_size + (frame_size % 2); } static cqueue *cqueue_create(int size, int max_size) { cqueue *q; if (max_size < size) return NULL; q = av_malloc(sizeof(cqueue)); if (!q) return NULL; q->max_size = max_size; q->size = size; q->nb_elements = 0; q->elements = av_malloc_array(max_size, sizeof(double)); if (!q->elements) { av_free(q); return NULL; } return q; } static void cqueue_free(cqueue *q) { if (q) av_free(q->elements); av_free(q); } static int cqueue_size(cqueue *q) { return q->nb_elements; } static int cqueue_empty(cqueue *q) { return q->nb_elements <= 0; } static int cqueue_enqueue(cqueue *q, double element) { av_assert2(q->nb_elements < q->max_size); q->elements[q->nb_elements] = element; q->nb_elements++; return 0; } static double cqueue_peek(cqueue *q, int index) { av_assert2(index < q->nb_elements); return q->elements[index]; } static int cqueue_dequeue(cqueue *q, double *element) { av_assert2(!cqueue_empty(q)); *element = q->elements[0]; memmove(&q->elements[0], &q->elements[1], (q->nb_elements - 1) * sizeof(double)); q->nb_elements--; return 0; } static int cqueue_pop(cqueue *q) { av_assert2(!cqueue_empty(q)); memmove(&q->elements[0], &q->elements[1], (q->nb_elements - 1) * sizeof(double)); q->nb_elements--; return 0; } static void cqueue_resize(cqueue *q, int new_size) { av_assert2(q->max_size >= new_size); av_assert2(MIN_FILTER_SIZE <= new_size); if (new_size > q->nb_elements) { const int side = (new_size - q->nb_elements) / 2; memmove(q->elements + side, q->elements, sizeof(double) * q->nb_elements); for (int i = 0; i < side; i++) q->elements[i] = q->elements[side]; q->nb_elements = new_size - 1 - side; } else { int count = (q->size - new_size + 1) / 2; while (count-- > 0) cqueue_pop(q); } q->size = new_size; } static void init_gaussian_filter(DynamicAudioNormalizerContext *s) { double total_weight = 0.0; const double sigma = (((s->filter_size / 2.0) - 1.0) / 3.0) + (1.0 / 3.0); double adjust; // Pre-compute constants const int offset = s->filter_size / 2; const double c1 = 1.0 / (sigma * sqrt(2.0 * M_PI)); const double c2 = 2.0 * sigma * sigma; // Compute weights for (int i = 0; i < s->filter_size; i++) { const int x = i - offset; s->weights[i] = c1 * exp(-x * x / c2); total_weight += s->weights[i]; } // Adjust weights adjust = 1.0 / total_weight; for (int i = 0; i < s->filter_size; i++) { s->weights[i] *= adjust; } } static av_cold void uninit(AVFilterContext *ctx) { DynamicAudioNormalizerContext *s = ctx->priv; av_freep(&s->prev_amplification_factor); av_freep(&s->dc_correction_value); av_freep(&s->compress_threshold); for (int c = 0; c < s->channels; c++) { if (s->gain_history_original) cqueue_free(s->gain_history_original[c]); if (s->gain_history_minimum) cqueue_free(s->gain_history_minimum[c]); if (s->gain_history_smoothed) cqueue_free(s->gain_history_smoothed[c]); if (s->threshold_history) cqueue_free(s->threshold_history[c]); } av_freep(&s->gain_history_original); av_freep(&s->gain_history_minimum); av_freep(&s->gain_history_smoothed); av_freep(&s->threshold_history); cqueue_free(s->is_enabled); s->is_enabled = NULL; av_freep(&s->weights); av_channel_layout_uninit(&s->ch_layout); ff_bufqueue_discard_all(&s->queue); av_frame_free(&s->window); av_expr_free(s->expr); s->expr = NULL; } static int config_input(AVFilterLink *inlink) { AVFilterContext *ctx = inlink->dst; DynamicAudioNormalizerContext *s = ctx->priv; int ret = 0; uninit(ctx); s->channels = inlink->ch_layout.nb_channels; s->frame_len = frame_size(inlink->sample_rate, s->frame_len_msec); av_log(ctx, AV_LOG_DEBUG, "frame len %d\n", s->frame_len); s->prev_amplification_factor = av_malloc_array(inlink->ch_layout.nb_channels, sizeof(*s->prev_amplification_factor)); s->dc_correction_value = av_calloc(inlink->ch_layout.nb_channels, sizeof(*s->dc_correction_value)); s->compress_threshold = av_calloc(inlink->ch_layout.nb_channels, sizeof(*s->compress_threshold)); s->gain_history_original = av_calloc(inlink->ch_layout.nb_channels, sizeof(*s->gain_history_original)); s->gain_history_minimum = av_calloc(inlink->ch_layout.nb_channels, sizeof(*s->gain_history_minimum)); s->gain_history_smoothed = av_calloc(inlink->ch_layout.nb_channels, sizeof(*s->gain_history_smoothed)); s->threshold_history = av_calloc(inlink->ch_layout.nb_channels, sizeof(*s->threshold_history)); s->weights = av_malloc_array(MAX_FILTER_SIZE, sizeof(*s->weights)); s->is_enabled = cqueue_create(s->filter_size, MAX_FILTER_SIZE); if (!s->prev_amplification_factor || !s->dc_correction_value || !s->compress_threshold || !s->gain_history_original || !s->gain_history_minimum || !s->gain_history_smoothed || !s->threshold_history || !s->is_enabled || !s->weights) return AVERROR(ENOMEM); for (int c = 0; c < inlink->ch_layout.nb_channels; c++) { s->prev_amplification_factor[c] = 1.0; s->gain_history_original[c] = cqueue_create(s->filter_size, MAX_FILTER_SIZE); s->gain_history_minimum[c] = cqueue_create(s->filter_size, MAX_FILTER_SIZE); s->gain_history_smoothed[c] = cqueue_create(s->filter_size, MAX_FILTER_SIZE); s->threshold_history[c] = cqueue_create(s->filter_size, MAX_FILTER_SIZE); if (!s->gain_history_original[c] || !s->gain_history_minimum[c] || !s->gain_history_smoothed[c] || !s->threshold_history[c]) return AVERROR(ENOMEM); } init_gaussian_filter(s); s->window = ff_get_audio_buffer(ctx->outputs[0], s->frame_len * 2); if (!s->window) return AVERROR(ENOMEM); s->sample_advance = FFMAX(1, lrint(s->frame_len * (1. - s->overlap))); s->var_values[VAR_SR] = inlink->sample_rate; s->var_values[VAR_NB_CHANNELS] = s->channels; if (s->expr_str) ret = av_expr_parse(&s->expr, s->expr_str, var_names, NULL, NULL, NULL, NULL, 0, ctx); return ret; } static inline double fade(double prev, double next, int pos, int length) { const double step_size = 1.0 / length; const double f0 = 1.0 - (step_size * (pos + 1.0)); const double f1 = 1.0 - f0; return f0 * prev + f1 * next; } static inline double pow_2(const double value) { return value * value; } static inline double bound(const double threshold, const double val) { const double CONST = 0.8862269254527580136490837416705725913987747280611935; //sqrt(PI) / 2.0 return erf(CONST * (val / threshold)) * threshold; } static double find_peak_magnitude(AVFrame *frame, int channel) { double max = DBL_EPSILON; if (channel == -1) { for (int c = 0; c < frame->ch_layout.nb_channels; c++) { double *data_ptr = (double *)frame->extended_data[c]; for (int i = 0; i < frame->nb_samples; i++) max = fmax(max, fabs(data_ptr[i])); } } else { double *data_ptr = (double *)frame->extended_data[channel]; for (int i = 0; i < frame->nb_samples; i++) max = fmax(max, fabs(data_ptr[i])); } return max; } static double compute_frame_rms(AVFrame *frame, int channel) { double rms_value = 0.0; if (channel == -1) { for (int c = 0; c < frame->ch_layout.nb_channels; c++) { const double *data_ptr = (double *)frame->extended_data[c]; for (int i = 0; i < frame->nb_samples; i++) { rms_value += pow_2(data_ptr[i]); } } rms_value /= frame->nb_samples * frame->ch_layout.nb_channels; } else { const double *data_ptr = (double *)frame->extended_data[channel]; for (int i = 0; i < frame->nb_samples; i++) { rms_value += pow_2(data_ptr[i]); } rms_value /= frame->nb_samples; } return fmax(sqrt(rms_value), DBL_EPSILON); } static local_gain get_max_local_gain(DynamicAudioNormalizerContext *s, AVFrame *frame, int channel) { const double peak_magnitude = find_peak_magnitude(frame, channel); const double maximum_gain = s->peak_value / peak_magnitude; const double rms_gain = s->target_rms > DBL_EPSILON ? (s->target_rms / compute_frame_rms(frame, channel)) : DBL_MAX; double target_gain = DBL_MAX; local_gain gain; if (s->expr_str) { double var_values[VAR_VARS_NB]; memcpy(var_values, s->var_values, sizeof(var_values)); var_values[VAR_CH] = channel; var_values[VAR_P] = peak_magnitude; target_gain = av_expr_eval(s->expr, var_values, s) / peak_magnitude; } gain.threshold = peak_magnitude > s->threshold; gain.max_gain = bound(s->max_amplification, fmin(target_gain, fmin(maximum_gain, rms_gain))); return gain; } static double minimum_filter(cqueue *q) { double min = DBL_MAX; for (int i = 0; i < cqueue_size(q); i++) { min = fmin(min, cqueue_peek(q, i)); } return min; } static double gaussian_filter(DynamicAudioNormalizerContext *s, cqueue *q, cqueue *tq) { const double *weights = s->weights; double result = 0.0, tsum = 0.0; for (int i = 0; i < cqueue_size(q); i++) { double tq_item = cqueue_peek(tq, i); double q_item = cqueue_peek(q, i); tsum += tq_item * weights[i]; result += tq_item * weights[i] * q_item; } if (tsum == 0.0) result = 1.0; return result; } static void update_gain_history(DynamicAudioNormalizerContext *s, int channel, local_gain gain) { if (cqueue_empty(s->gain_history_original[channel])) { const int pre_fill_size = s->filter_size / 2; const double initial_value = s->alt_boundary_mode ? gain.max_gain : fmin(1.0, gain.max_gain); s->prev_amplification_factor[channel] = initial_value; while (cqueue_size(s->gain_history_original[channel]) < pre_fill_size) { cqueue_enqueue(s->gain_history_original[channel], initial_value); cqueue_enqueue(s->threshold_history[channel], gain.threshold); } } cqueue_enqueue(s->gain_history_original[channel], gain.max_gain); while (cqueue_size(s->gain_history_original[channel]) >= s->filter_size) { double minimum; if (cqueue_empty(s->gain_history_minimum[channel])) { const int pre_fill_size = s->filter_size / 2; double initial_value = s->alt_boundary_mode ? cqueue_peek(s->gain_history_original[channel], 0) : 1.0; int input = pre_fill_size; while (cqueue_size(s->gain_history_minimum[channel]) < pre_fill_size) { input++; initial_value = fmin(initial_value, cqueue_peek(s->gain_history_original[channel], input)); cqueue_enqueue(s->gain_history_minimum[channel], initial_value); } } minimum = minimum_filter(s->gain_history_original[channel]); cqueue_enqueue(s->gain_history_minimum[channel], minimum); cqueue_enqueue(s->threshold_history[channel], gain.threshold); cqueue_pop(s->gain_history_original[channel]); } while (cqueue_size(s->gain_history_minimum[channel]) >= s->filter_size) { double smoothed, limit; smoothed = gaussian_filter(s, s->gain_history_minimum[channel], s->threshold_history[channel]); limit = cqueue_peek(s->gain_history_original[channel], 0); smoothed = fmin(smoothed, limit); cqueue_enqueue(s->gain_history_smoothed[channel], smoothed); cqueue_pop(s->gain_history_minimum[channel]); cqueue_pop(s->threshold_history[channel]); } } static int update_gain_histories(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) { DynamicAudioNormalizerContext *s = ctx->priv; AVFrame *analyze_frame = arg; const int channels = s->channels; const int start = (channels * jobnr) / nb_jobs; const int end = (channels * (jobnr+1)) / nb_jobs; for (int c = start; c < end; c++) update_gain_history(s, c, get_max_local_gain(s, analyze_frame, c)); return 0; } static inline double update_value(double new, double old, double aggressiveness) { av_assert0((aggressiveness >= 0.0) && (aggressiveness <= 1.0)); return aggressiveness * new + (1.0 - aggressiveness) * old; } static inline int bypass_channel(DynamicAudioNormalizerContext *s, AVFrame *frame, int ch) { enum AVChannel channel = av_channel_layout_channel_from_index(&frame->ch_layout, ch); return av_channel_layout_index_from_channel(&s->ch_layout, channel) < 0; } static void perform_dc_correction(DynamicAudioNormalizerContext *s, AVFrame *frame) { const double diff = 1.0 / frame->nb_samples; int is_first_frame = cqueue_empty(s->gain_history_original[0]); for (int c = 0; c < s->channels; c++) { const int bypass = bypass_channel(s, frame, c); double *dst_ptr = (double *)frame->extended_data[c]; double current_average_value = 0.0; double prev_value; for (int i = 0; i < frame->nb_samples; i++) current_average_value += dst_ptr[i] * diff; prev_value = is_first_frame ? current_average_value : s->dc_correction_value[c]; s->dc_correction_value[c] = is_first_frame ? current_average_value : update_value(current_average_value, s->dc_correction_value[c], 0.1); for (int i = 0; i < frame->nb_samples && !bypass; i++) { dst_ptr[i] -= fade(prev_value, s->dc_correction_value[c], i, frame->nb_samples); } } } static double setup_compress_thresh(double threshold) { if ((threshold > DBL_EPSILON) && (threshold < (1.0 - DBL_EPSILON))) { double current_threshold = threshold; double step_size = 1.0; while (step_size > DBL_EPSILON) { while ((llrint((current_threshold + step_size) * (UINT64_C(1) << 63)) > llrint(current_threshold * (UINT64_C(1) << 63))) && (bound(current_threshold + step_size, 1.0) <= threshold)) { current_threshold += step_size; } step_size /= 2.0; } return current_threshold; } else { return threshold; } } static double compute_frame_std_dev(DynamicAudioNormalizerContext *s, AVFrame *frame, int channel) { double variance = 0.0; if (channel == -1) { for (int c = 0; c < s->channels; c++) { const double *data_ptr = (double *)frame->extended_data[c]; for (int i = 0; i < frame->nb_samples; i++) { variance += pow_2(data_ptr[i]); // Assume that MEAN is *zero* } } variance /= (s->channels * frame->nb_samples) - 1; } else { const double *data_ptr = (double *)frame->extended_data[channel]; for (int i = 0; i < frame->nb_samples; i++) { variance += pow_2(data_ptr[i]); // Assume that MEAN is *zero* } variance /= frame->nb_samples - 1; } return fmax(sqrt(variance), DBL_EPSILON); } static void perform_compression(DynamicAudioNormalizerContext *s, AVFrame *frame) { int is_first_frame = cqueue_empty(s->gain_history_original[0]); if (s->channels_coupled) { const double standard_deviation = compute_frame_std_dev(s, frame, -1); const double current_threshold = fmin(1.0, s->compress_factor * standard_deviation); const double prev_value = is_first_frame ? current_threshold : s->compress_threshold[0]; double prev_actual_thresh, curr_actual_thresh; s->compress_threshold[0] = is_first_frame ? current_threshold : update_value(current_threshold, s->compress_threshold[0], (1.0/3.0)); prev_actual_thresh = setup_compress_thresh(prev_value); curr_actual_thresh = setup_compress_thresh(s->compress_threshold[0]); for (int c = 0; c < s->channels; c++) { double *const dst_ptr = (double *)frame->extended_data[c]; const int bypass = bypass_channel(s, frame, c); if (bypass) continue; for (int i = 0; i < frame->nb_samples; i++) { const double localThresh = fade(prev_actual_thresh, curr_actual_thresh, i, frame->nb_samples); dst_ptr[i] = copysign(bound(localThresh, fabs(dst_ptr[i])), dst_ptr[i]); } } } else { for (int c = 0; c < s->channels; c++) { const int bypass = bypass_channel(s, frame, c); const double standard_deviation = compute_frame_std_dev(s, frame, c); const double current_threshold = setup_compress_thresh(fmin(1.0, s->compress_factor * standard_deviation)); const double prev_value = is_first_frame ? current_threshold : s->compress_threshold[c]; double prev_actual_thresh, curr_actual_thresh; double *dst_ptr; s->compress_threshold[c] = is_first_frame ? current_threshold : update_value(current_threshold, s->compress_threshold[c], 1.0/3.0); prev_actual_thresh = setup_compress_thresh(prev_value); curr_actual_thresh = setup_compress_thresh(s->compress_threshold[c]); dst_ptr = (double *)frame->extended_data[c]; for (int i = 0; i < frame->nb_samples && !bypass; i++) { const double localThresh = fade(prev_actual_thresh, curr_actual_thresh, i, frame->nb_samples); dst_ptr[i] = copysign(bound(localThresh, fabs(dst_ptr[i])), dst_ptr[i]); } } } } static int analyze_frame(AVFilterContext *ctx, AVFilterLink *outlink, AVFrame **frame) { DynamicAudioNormalizerContext *s = ctx->priv; AVFrame *analyze_frame; if (s->dc_correction || s->compress_factor > DBL_EPSILON) { int ret; if (!av_frame_is_writable(*frame)) { AVFrame *out = ff_get_audio_buffer(outlink, (*frame)->nb_samples); if (!out) { av_frame_free(frame); return AVERROR(ENOMEM); } ret = av_frame_copy_props(out, *frame); if (ret < 0) { av_frame_free(frame); av_frame_free(&out); return ret; } ret = av_frame_copy(out, *frame); if (ret < 0) { av_frame_free(frame); av_frame_free(&out); return ret; } av_frame_free(frame); *frame = out; } } if (s->dc_correction) perform_dc_correction(s, *frame); if (s->compress_factor > DBL_EPSILON) perform_compression(s, *frame); if (s->frame_len != s->sample_advance) { const int offset = s->frame_len - s->sample_advance; for (int c = 0; c < s->channels; c++) { double *src = (double *)s->window->extended_data[c]; memmove(src, &src[s->sample_advance], offset * sizeof(double)); memcpy(&src[offset], (*frame)->extended_data[c], (*frame)->nb_samples * sizeof(double)); memset(&src[offset + (*frame)->nb_samples], 0, (s->sample_advance - (*frame)->nb_samples) * sizeof(double)); } analyze_frame = s->window; } else { av_samples_copy(s->window->extended_data, (*frame)->extended_data, 0, 0, FFMIN(s->frame_len, (*frame)->nb_samples), (*frame)->ch_layout.nb_channels, (*frame)->format); analyze_frame = *frame; } s->var_values[VAR_SN] = outlink->sample_count_in; s->var_values[VAR_T] = s->var_values[VAR_SN] * (double)1/outlink->sample_rate; if (s->channels_coupled) { const local_gain gain = get_max_local_gain(s, analyze_frame, -1); for (int c = 0; c < s->channels; c++) update_gain_history(s, c, gain); } else { ff_filter_execute(ctx, update_gain_histories, analyze_frame, NULL, FFMIN(s->channels, ff_filter_get_nb_threads(ctx))); } return 0; } static void amplify_channel(DynamicAudioNormalizerContext *s, AVFrame *in, AVFrame *frame, int enabled, int c) { const int bypass = bypass_channel(s, frame, c); const double *src_ptr = (const double *)in->extended_data[c]; double *dst_ptr = (double *)frame->extended_data[c]; double current_amplification_factor; cqueue_dequeue(s->gain_history_smoothed[c], &current_amplification_factor); for (int i = 0; i < frame->nb_samples && enabled && !bypass; i++) { const double amplification_factor = fade(s->prev_amplification_factor[c], current_amplification_factor, i, frame->nb_samples); dst_ptr[i] = src_ptr[i] * amplification_factor; } s->prev_amplification_factor[c] = current_amplification_factor; } static int amplify_channels(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) { DynamicAudioNormalizerContext *s = ctx->priv; ThreadData *td = arg; AVFrame *out = td->out; AVFrame *in = td->in; const int enabled = td->enabled; const int channels = s->channels; const int start = (channels * jobnr) / nb_jobs; const int end = (channels * (jobnr+1)) / nb_jobs; for (int ch = start; ch < end; ch++) amplify_channel(s, in, out, enabled, ch); return 0; } static int filter_frame(AVFilterLink *inlink, AVFrame *in) { AVFilterContext *ctx = inlink->dst; DynamicAudioNormalizerContext *s = ctx->priv; AVFilterLink *outlink = ctx->outputs[0]; ThreadData td; int ret; while (((s->queue.available >= s->filter_size) || (s->eof && s->queue.available)) && !cqueue_empty(s->gain_history_smoothed[0])) { AVFrame *in = ff_bufqueue_get(&s->queue); AVFrame *out; double is_enabled; cqueue_dequeue(s->is_enabled, &is_enabled); if (av_frame_is_writable(in)) { out = in; } else { out = ff_get_audio_buffer(outlink, in->nb_samples); if (!out) { av_frame_free(&in); return AVERROR(ENOMEM); } av_frame_copy_props(out, in); } td.in = in; td.out = out; td.enabled = is_enabled > 0.; ff_filter_execute(ctx, amplify_channels, &td, NULL, FFMIN(s->channels, ff_filter_get_nb_threads(ctx))); s->pts = out->pts + av_rescale_q(out->nb_samples, av_make_q(1, outlink->sample_rate), outlink->time_base); if (out != in) av_frame_free(&in); ret = ff_filter_frame(outlink, out); if (ret < 0) return ret; } ret = analyze_frame(ctx, outlink, &in); if (ret < 0) return ret; if (!s->eof) { ff_bufqueue_add(ctx, &s->queue, in); cqueue_enqueue(s->is_enabled, !ctx->is_disabled); } else { av_frame_free(&in); } return 1; } static int flush_buffer(DynamicAudioNormalizerContext *s, AVFilterLink *inlink, AVFilterLink *outlink) { AVFrame *out = ff_get_audio_buffer(outlink, s->sample_advance); if (!out) return AVERROR(ENOMEM); for (int c = 0; c < s->channels; c++) { double *dst_ptr = (double *)out->extended_data[c]; for (int i = 0; i < out->nb_samples; i++) { dst_ptr[i] = s->alt_boundary_mode ? DBL_EPSILON : ((s->target_rms > DBL_EPSILON) ? fmin(s->peak_value, s->target_rms) : s->peak_value); if (s->dc_correction) { dst_ptr[i] *= ((i % 2) == 1) ? -1 : 1; dst_ptr[i] += s->dc_correction_value[c]; } } } return filter_frame(inlink, out); } static int flush(AVFilterLink *outlink) { AVFilterContext *ctx = outlink->src; AVFilterLink *inlink = ctx->inputs[0]; DynamicAudioNormalizerContext *s = ctx->priv; while (s->eof && cqueue_empty(s->gain_history_smoothed[0])) { for (int c = 0; c < s->channels; c++) update_gain_history(s, c, (local_gain){ cqueue_peek(s->gain_history_original[c], 0), 1.0}); } return flush_buffer(s, inlink, outlink); } static int activate(AVFilterContext *ctx) { AVFilterLink *inlink = ctx->inputs[0]; AVFilterLink *outlink = ctx->outputs[0]; DynamicAudioNormalizerContext *s = ctx->priv; AVFrame *in = NULL; int ret = 0, status; int64_t pts; ret = av_channel_layout_copy(&s->ch_layout, &inlink->ch_layout); if (ret < 0) return ret; if (strcmp(s->channels_to_filter, "all")) av_channel_layout_from_string(&s->ch_layout, s->channels_to_filter); FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink); if (!s->eof) { ret = ff_inlink_consume_samples(inlink, s->sample_advance, s->sample_advance, &in); if (ret < 0) return ret; if (ret > 0) { ret = filter_frame(inlink, in); if (ret <= 0) return ret; } if (ff_inlink_check_available_samples(inlink, s->sample_advance) > 0) { ff_filter_set_ready(ctx, 10); return 0; } } if (!s->eof && ff_inlink_acknowledge_status(inlink, &status, &pts)) { if (status == AVERROR_EOF) s->eof = 1; } if (s->eof && s->queue.available) return flush(outlink); if (s->eof && !s->queue.available) { ff_outlink_set_status(outlink, AVERROR_EOF, s->pts); return 0; } if (!s->eof) FF_FILTER_FORWARD_WANTED(outlink, inlink); return FFERROR_NOT_READY; } static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags) { DynamicAudioNormalizerContext *s = ctx->priv; AVFilterLink *inlink = ctx->inputs[0]; int prev_filter_size = s->filter_size; int ret; ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags); if (ret < 0) return ret; s->filter_size |= 1; if (prev_filter_size != s->filter_size) { init_gaussian_filter(s); for (int c = 0; c < s->channels; c++) { cqueue_resize(s->gain_history_original[c], s->filter_size); cqueue_resize(s->gain_history_minimum[c], s->filter_size); cqueue_resize(s->threshold_history[c], s->filter_size); } } s->frame_len = frame_size(inlink->sample_rate, s->frame_len_msec); s->sample_advance = FFMAX(1, lrint(s->frame_len * (1. - s->overlap))); if (s->expr_str) { ret = av_expr_parse(&s->expr, s->expr_str, var_names, NULL, NULL, NULL, NULL, 0, ctx); if (ret < 0) return ret; } return 0; } static const AVFilterPad avfilter_af_dynaudnorm_inputs[] = { { .name = "default", .type = AVMEDIA_TYPE_AUDIO, .config_props = config_input, }, }; static const AVFilterPad avfilter_af_dynaudnorm_outputs[] = { { .name = "default", .type = AVMEDIA_TYPE_AUDIO, }, }; const AVFilter ff_af_dynaudnorm = { .name = "dynaudnorm", .description = NULL_IF_CONFIG_SMALL("Dynamic Audio Normalizer."), .priv_size = sizeof(DynamicAudioNormalizerContext), .init = init, .uninit = uninit, .activate = activate, FILTER_INPUTS(avfilter_af_dynaudnorm_inputs), FILTER_OUTPUTS(avfilter_af_dynaudnorm_outputs), FILTER_SINGLE_SAMPLEFMT(AV_SAMPLE_FMT_DBLP), .priv_class = &dynaudnorm_class, .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL | AVFILTER_FLAG_SLICE_THREADS, .process_command = process_command, };
7fcb3aa2e5bb8a9189c56fa62230b65800eabb31
8f890a2893268f48b63a973714a4084563138418
/components/DAP/include/dap_utility.h
08ea438863e10ddc00c51b43268a636290b42d77
[ "MIT" ]
permissive
windowsair/wireless-esp8266-dap
8bfc78d2104762aca361cec5f34906cf0647d6f7
6ffe17fb137aa0e29781943daf93308d8ae1b482
refs/heads/master
2023-05-11T18:44:01.545045
2023-04-15T03:59:56
2023-04-15T03:59:56
238,219,109
326
186
MIT
2023-04-28T19:00:33
2020-02-04T13:58:44
C
UTF-8
C
false
false
734
h
dap_utility.h
#ifndef __DAP_UTILITY_H__ #define __DAP_UTILITY_H__ #include <stdint.h> #ifndef __STATIC_FORCEINLINE #define __STATIC_FORCEINLINE static inline __attribute__((always_inline)) #endif #ifndef __STATIC_INLINE #define __STATIC_INLINE static inline __attribute__((always_inline)) #endif #ifndef __WEAK #define __WEAK __attribute__((weak)) #endif extern const uint8_t kParityByteTable[256]; __STATIC_FORCEINLINE uint8_t ParityEvenUint32(uint32_t v) { v ^= v >> 16; v ^= v >> 8; v ^= v >> 4; v &= 0xf; return (0x6996 >> v) & 1; } __STATIC_FORCEINLINE uint8_t ParityEvenUint8(uint8_t v) { return kParityByteTable[v]; } #endif
00920061db4e5dfb88df896ca2db19c1603b95a1
f4ea6db9183b38e0cb1af1d317b0a02db24455d1
/test/t-0000257/inh_xxxx.c
cfaef487054af17766c77eb322c09150153d6541
[ "BSD-3-Clause", "LicenseRef-scancode-public-domain", "BSD-2-Clause" ]
permissive
ldmud/ldmud
1446ff7101f5a47ee1dfa4cfb97d5a326f2edcce
f1cfc9a8d911412d854055058889bb32432da2db
refs/heads/master
2023-05-25T00:36:28.318383
2023-02-14T21:07:35
2023-02-18T10:20:44
1,085,012
124
71
NOASSERTION
2023-09-01T16:54:48
2010-11-16T12:13:17
C
UTF-8
C
false
false
101
c
inh_xxxx.c
string* fun(varargs mixed* args) { return ({"Inh4"})+args; } void count(int x) { x += 8; }
b1505702e8bee0e187d597ae71b2be5298674493
83b8b30ebb633eecd29ca0a7a20cc43a293c9333
/shared-module/vectorio/Rectangle.c
4c2bdc66cbef51205cbfadbe04965f054a6a909b
[ "MIT", "GPL-1.0-or-later" ]
permissive
adafruit/circuitpython
430ec895149d1eb814b505db39b4977a35ee88a7
506dca71b0cbb7af749bb51f86b01021db5483b3
refs/heads/main
2023-08-21T16:30:46.781068
2023-08-20T00:39:44
2023-08-20T00:39:44
66,166,069
3,806
1,560
MIT
2023-09-14T19:23:51
2016-08-20T20:10:40
C
UTF-8
C
false
false
2,460
c
Rectangle.c
#include "shared-module/vectorio/__init__.h" #include "shared-bindings/vectorio/Rectangle.h" #include "shared-module/displayio/area.h" #include "py/runtime.h" #include "stdlib.h" void common_hal_vectorio_rectangle_construct(vectorio_rectangle_t *self, uint32_t width, uint32_t height, uint16_t color_index) { self->width = width; self->height = height; self->color_index = color_index + 1; } void common_hal_vectorio_rectangle_set_on_dirty(vectorio_rectangle_t *self, vectorio_event_t on_dirty) { if (self->on_dirty.obj != NULL) { mp_raise_TypeError(translate("can only have one parent")); } self->on_dirty = on_dirty; } uint32_t common_hal_vectorio_rectangle_get_pixel(void *obj, int16_t x, int16_t y) { vectorio_rectangle_t *self = obj; if (x >= 0 && y >= 0 && x < self->width && y < self->height) { return self->color_index; } return 0; } void common_hal_vectorio_rectangle_get_area(void *rectangle, displayio_area_t *out_area) { vectorio_rectangle_t *self = rectangle; out_area->x1 = 0; out_area->y1 = 0; out_area->x2 = self->width; out_area->y2 = self->height; } mp_obj_t common_hal_vectorio_rectangle_get_draw_protocol(void *rectangle) { vectorio_rectangle_t *self = rectangle; return self->draw_protocol_instance; } int16_t common_hal_vectorio_rectangle_get_width(void *obj) { vectorio_rectangle_t *self = obj; return self->width; } void common_hal_vectorio_rectangle_set_width(void *obj, int16_t width) { vectorio_rectangle_t *self = obj; self->width = abs(width); if (self->on_dirty.obj != NULL) { self->on_dirty.event(self->on_dirty.obj); } } int16_t common_hal_vectorio_rectangle_get_height(void *obj) { vectorio_rectangle_t *self = obj; return self->height; } void common_hal_vectorio_rectangle_set_height(void *obj, int16_t height) { vectorio_rectangle_t *self = obj; self->height = abs(height); if (self->on_dirty.obj != NULL) { self->on_dirty.event(self->on_dirty.obj); } } uint16_t common_hal_vectorio_rectangle_get_color_index(void *obj) { vectorio_rectangle_t *self = obj; return self->color_index - 1; } void common_hal_vectorio_rectangle_set_color_index(void *obj, uint16_t color_index) { vectorio_rectangle_t *self = obj; self->color_index = abs(color_index + 1); if (self->on_dirty.obj != NULL) { self->on_dirty.event(self->on_dirty.obj); } }
9103fd7cd2d03f134c8fc87fee7a2bc10ceb26d9
d61b532db0d3e08818338cfaac530a1ced1ffe3b
/util/ego/ud/ud_aux.h
f9b57592d471fe8b75fa2ba4cade56908f76d90d
[ "LicenseRef-scancode-other-permissive" ]
permissive
davidgiven/ack
61049c7a8e95ff61a77b1edd3c22bb290720e276
db5a32c68c4a60ca26a3927a799ea662b5b2b0e5
refs/heads/default
2023-08-29T07:33:12.771205
2023-07-08T20:17:27
2023-07-08T20:17:27
37,686,316
376
74
NOASSERTION
2023-07-08T20:17:28
2015-06-18T21:33:42
C
UTF-8
C
false
false
631
h
ud_aux.h
/* $Id$ */ /* * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. * See the copyright notice in the ACK home directory, in the file "Copyright". */ /* C O P Y P R O P A G A T I O N * * A U X I L I A R Y R O U T I N E S */ void repl_line(line_p old, line_p new, bblock_p b); /* * Replace EM instruction 'old' by a * copy of 'new'. Update doubly-linked * list. */ bool same_var(line_p use, line_p def); /* * 'use' is an instruction that uses a variable * for which we maintain ud-info (e.g. a LOL). * See if 'def' references the same variable. */
213594f7e70f3bcb4254c1cee0cd635121de4955
99bdb3251fecee538e0630f15f6574054dfc1468
/bsp/imxrt/libraries/drivers/drv_flexspi.c
0cacdc75f0e0168346a9a9971eaf11237f7833a9
[ "Apache-2.0", "Zlib", "LicenseRef-scancode-proprietary-license", "MIT", "BSD-3-Clause", "X11", "BSD-4-Clause-UC", "LicenseRef-scancode-unknown-license-reference" ]
permissive
RT-Thread/rt-thread
03a7c52c2aeb1b06a544143b0e803d72f47d1ece
3602f891211904a27dcbd51e5ba72fefce7326b2
refs/heads/master
2023-09-01T04:10:20.295801
2023-08-31T16:20:55
2023-08-31T16:20:55
7,408,108
9,599
5,805
Apache-2.0
2023-09-14T13:37:26
2013-01-02T14:49:21
C
UTF-8
C
false
false
4,127
c
drv_flexspi.c
/* * Copyright (c) 2006-2023, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * * Change Logs: * Date Author Notes * 2022-09-14 xjy198903 the first version for 1170 */ #include <rtthread.h> #ifdef BSP_USING_FLEXSPI #include "board.h" #include <rtdevice.h> #ifdef RT_USING_FINSH #include <finsh.h> #endif #include "flexspi_port.h" #include "fsl_flexspi.h" #define COMBINATION_MODE 1U #define FREE_RUNNING_MODE 1U #define FLEXSPI_DEBUG #define LOG_TAG "drv.flexspi" #include <drv_log.h> static flexspi_device_config_t deviceconfig = { .flexspiRootClk = 12000000, .flashSize = FLASH_SIZE, .CSIntervalUnit = kFLEXSPI_CsIntervalUnit1SckCycle, .CSInterval = 2, .CSHoldTime = 3, .CSSetupTime = 3, .dataValidTime = 0, .columnspace = 0, .enableWordAddress = 0, .AWRSeqIndex = AWR_SEQ_INDEX, .AWRSeqNumber = AWR_SEQ_NUMBER, .ARDSeqIndex = ARD_SEQ_INDEX, .ARDSeqNumber = ARD_SEQ_NUMBER, .AHBWriteWaitUnit = kFLEXSPI_AhbWriteWaitUnit2AhbCycle, .AHBWriteWaitInterval = 0, }; const uint32_t customLUT[CUSTOM_LUT_LENGTH] = { /* 8bit mode */ [4 * ARD_SEQ_INDEX] = FLEXSPI_LUT_SEQ(kFLEXSPI_Command_READ_DDR, kFLEXSPI_8PAD, 0x04, kFLEXSPI_Command_STOP, kFLEXSPI_8PAD, 0), }; static void flexspi_clock_init(clock_root_t root, uint8_t src, uint8_t div) { /*Clock setting for flexspi1*/ CLOCK_SetRootClockDiv(root, div); CLOCK_SetRootClockMux(root, src); } static int rt_hw_imxrt_flexspi_init(void) { flexspi_config_t config; FLEXSPI_Type *base; #ifdef BSP_USING_FLEXSPI1 base = FLEXSPI1_CONTROL_BASE; #else base = FLEXSPI2_CONTROL_BASE; #endif //Set root clk 80MHz flexspi_clock_init(kCLOCK_Root_Flexspi1, CLOCK_SRC, CLOCK_DIV); /*Get FLEXSPI default settings and configure the flexspi. */ FLEXSPI_GetDefaultConfig(&config); /*Set AHB buffer size for reading data through AHB bus. */ config.ahbConfig.enableAHBPrefetch = true; config.ahbConfig.enableAHBBufferable = true; config.ahbConfig.enableReadAddressOpt = true; config.ahbConfig.enableAHBCachable = true; config.ahbConfig.enableClearAHBBufferOpt = true; config.rxSampleClock = FLEXSPI_RX_SAMPLE_CLOCK; if(COMBINATION_MODE) { config.enableCombination = true; } if(FREE_RUNNING_MODE) { config.enableSckFreeRunning = true; } FLEXSPI_Init(base, &config); /* Configure flash settings according to serial flash feature. */ FLEXSPI_SetFlashConfig(base, &deviceconfig, FLASH_PORT); /* Update LUT table. */ FLEXSPI_UpdateLUT(base, 0, customLUT, CUSTOM_LUT_LENGTH); /* Do software reset. */ FLEXSPI_SoftwareReset(base); return 0; } INIT_DEVICE_EXPORT(rt_hw_imxrt_flexspi_init); #ifdef FLEXSPI_DEBUG #ifdef FINSH_USING_MSH #define FLEXSPI_DATALEN 4U static rt_uint32_t send_buf[FLEXSPI_DATALEN] = {0x11223344, 0x55667788, 0x12345678, 0x9900aabb}; static uint32_t recv_buf[FLEXSPI_DATALEN]; /* read write 32bit test */ static void flexspi_test(void) { volatile rt_uint32_t *flexspi = (rt_uint32_t *)FLEXSPI1_AHB_DATA_ADDRESS; /* FLEXSPI1 start address. */ LOG_D("FLEXSPI Memory 32 bit Write Start\n"); *(flexspi + 15) = send_buf[3]; *(flexspi + 8) = send_buf[1]; *(flexspi + 11) = send_buf[2]; *(flexspi + 3) = send_buf[0]; LOG_D("FLEXSPI Memory 32 bit Write End\n"); rt_memset(recv_buf, 0, sizeof(recv_buf)); LOG_D("FLEXSPI Memory 32 bit Read Start\n"); recv_buf[2] = *(flexspi + 11); recv_buf[3] = *(flexspi + 15); recv_buf[1] = *(flexspi + 8); recv_buf[0] = *(flexspi + 3); LOG_D("FLEXSPI Memory 32 bit Read End\n"); LOG_D("addr12 is 0x%x\n", recv_buf[0]); LOG_D("addr32 is 0x%x\n", recv_buf[1]); LOG_D("addr44 is 0x%x\n", recv_buf[2]); LOG_D("addr60 is 0x%x\n", recv_buf[3]); } MSH_CMD_EXPORT(flexspi_test, flexspi test) #endif /* FLEXSPI_DEBUG */ #endif /* FINSH_USING_MSH */ #endif /* BSP_USING_FLEXSPI */
96ecb5e9b9e67d19c169b95bb8c00e90bd4eefef
c8b39acfd4a857dc15ed3375e0d93e75fa3f1f64
/Engine/Source/ThirdParty/Oculus/LibOVRPlatform/LibOVRPlatform/include/OVR_MatchmakingAdminSnapshot.h
e9f2f6ae1915df5c3259b955c8d15753d45fdd7c
[ "MIT", "LicenseRef-scancode-proprietary-license" ]
permissive
windystrife/UnrealEngine_NVIDIAGameWorks
c3c7863083653caf1bc67d3ef104fb4b9f302e2a
b50e6338a7c5b26374d66306ebc7807541ff815e
refs/heads/4.18-GameWorks
2023-03-11T02:50:08.471040
2022-01-13T20:50:29
2022-01-13T20:50:29
124,100,479
262
179
MIT
2022-12-16T05:36:38
2018-03-06T15:44:09
C++
UTF-8
C
false
false
662
h
OVR_MatchmakingAdminSnapshot.h
// This file was @generated with LibOVRPlatform/codegen/main. Do not modify it! #ifndef OVR_MATCHMAKINGADMINSNAPSHOT_H #define OVR_MATCHMAKINGADMINSNAPSHOT_H #include "OVR_Platform_Defs.h" #include "OVR_MatchmakingAdminSnapshotCandidateArray.h" typedef struct ovrMatchmakingAdminSnapshot *ovrMatchmakingAdminSnapshotHandle; OVRP_PUBLIC_FUNCTION(ovrMatchmakingAdminSnapshotCandidateArrayHandle) ovr_MatchmakingAdminSnapshot_GetCandidates(const ovrMatchmakingAdminSnapshotHandle obj); OVRP_PUBLIC_FUNCTION(double) ovr_MatchmakingAdminSnapshot_GetMyCurrentThreshold(const ovrMatchmakingAdminSnapshotHandle obj); #endif
36a910096ce6a1d586754154666cd1f41fd30297
42ab733e143d02091d13424fb4df16379d5bba0d
/third_party/libsdl2/include/SDL_power.h
a4fe8a9359c247678ad56a47f8b8106fa465f4a9
[ "Apache-2.0", "CC0-1.0", "LicenseRef-scancode-unknown-license-reference", "Zlib" ]
permissive
google/filament
11cd37ac68790fcf8b33416b7d8d8870e48181f0
0aa0efe1599798d887fa6e33c412c09e81bea1bf
refs/heads/main
2023-08-29T17:58:22.496956
2023-08-28T17:27:38
2023-08-28T17:27:38
143,455,116
16,631
1,961
Apache-2.0
2023-09-14T16:23:39
2018-08-03T17:26:00
C++
UTF-8
C
false
false
2,463
h
SDL_power.h
/* Simple DirectMedia Layer Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifndef SDL_power_h_ #define SDL_power_h_ /** * \file SDL_power.h * * Header for the SDL power management routines. */ #include "SDL_stdinc.h" #include "begin_code.h" /* Set up for C function definitions, even when using C++ */ #ifdef __cplusplus extern "C" { #endif /** * \brief The basic state for the system's power supply. */ typedef enum { SDL_POWERSTATE_UNKNOWN, /**< cannot determine power status */ SDL_POWERSTATE_ON_BATTERY, /**< Not plugged in, running on the battery */ SDL_POWERSTATE_NO_BATTERY, /**< Plugged in, no battery available */ SDL_POWERSTATE_CHARGING, /**< Plugged in, charging battery */ SDL_POWERSTATE_CHARGED /**< Plugged in, battery charged */ } SDL_PowerState; /** * \brief Get the current power supply details. * * \param secs Seconds of battery life left. You can pass a NULL here if * you don't care. Will return -1 if we can't determine a * value, or we're not running on a battery. * * \param pct Percentage of battery life left, between 0 and 100. You can * pass a NULL here if you don't care. Will return -1 if we * can't determine a value, or we're not running on a battery. * * \return The state of the battery (if any). */ extern DECLSPEC SDL_PowerState SDLCALL SDL_GetPowerInfo(int *secs, int *pct); /* Ends C function definitions when using C++ */ #ifdef __cplusplus } #endif #include "close_code.h" #endif /* SDL_power_h_ */ /* vi: set ts=4 sw=4 expandtab: */
dd0350eb1c35faffea125694923a63b86ca2a2b2
850efbcf8fe84eb06ab06976aabf7403f66c623e
/include/driver/i2c_pcf8591.h
dbebf44d868b49f904c7d159e5bca83dde9571ed
[]
no_license
nekromant/esp8266-frankenstein
696c3c64526be0d4baf3953cd344ffe6dee3efaf
3188970703aceb67587f6081baa2ae5cc8bf9350
refs/heads/master
2022-06-02T16:38:43.886778
2020-06-03T08:38:23
2020-06-03T08:38:23
26,371,166
292
87
null
2020-06-03T08:38:24
2014-11-08T18:59:52
C
UTF-8
C
false
false
363
h
i2c_pcf8591.h
#ifndef __I2C_PCF8591_H #define __I2C_PCF8591_H #include "c_types.h" #include "ets_sys.h" #include "osapi.h" #define PCF8591_ADDRESS 0x90 #define PCF8591_REG_READ_ALL 0x04 #define PCF8591_REG_DAC 0x40 uint8 LAST_PCF8591_A[4]; static bool IS_ALREADY_INITED = false; bool PCF8591_Init(void); bool PCF8591_Read(void); bool PCF8591_Write(uint8_t value); #endif
2fb141368800e79324bd9b071d45df7af68cec04
ce32e0e1b9568c710a3168abc3c638d6f9f6c31b
/vnpy/api/xtp/generator/xtp_td_header_define.h
2c6d6ed0bce6d5f156c5a664f8034b599ecd3fc6
[ "MIT" ]
permissive
msincenselee/vnpy
55ae76ca32cae47369a66bd2d6589c13d7a0bdd4
7f4fd3cd202712b083ed7dc2f346ba4bb1bda6d7
refs/heads/vnpy2
2022-05-19T10:06:55.504408
2022-03-19T15:26:01
2022-03-19T15:26:01
38,525,806
359
158
MIT
2020-09-09T00:09:12
2015-07-04T07:27:46
C++
UTF-8
C
false
false
736
h
xtp_td_header_define.h
#define ONDISCONNECTED 0 #define ONERROR 1 #define ONORDEREVENT 2 #define ONTRADEEVENT 3 #define ONCANCELORDERERROR 4 #define ONQUERYORDER 5 #define ONQUERYTRADE 6 #define ONQUERYPOSITION 7 #define ONQUERYASSET 8 #define ONQUERYSTRUCTUREDFUND 9 #define ONQUERYFUNDTRANSFER 10 #define ONFUNDTRANSFER 11 #define ONQUERYETF 12 #define ONQUERYETFBASKET 13 #define ONQUERYIPOINFOLIST 14 #define ONQUERYIPOQUOTAINFO 15 #define ONQUERYOPTIONAUCTIONINFO 16 #define ONCREDITCASHREPAY 17 #define ONQUERYCREDITCASHREPAYINFO 18 #define ONQUERYCREDITFUNDINFO 19 #define ONQUERYCREDITDEBTINFO 20 #define ONQUERYCREDITTICKERDEBTINFO 21 #define ONQUERYCREDITASSETDEBTINFO 22 #define ONQUERYCREDITTICKERASSIGNINFO 23 #define ONQUERYCREDITEXCESSSTOCK 24
ab6e7c854b40ca5c48f5864b9c3d843ea21f83ae
8d7d6f609ba65eb2650e5f04ab7b2d6db8a192d4
/src/diff2_lowlevel.h
501232d64afab68cc6e66d2658fd4747a62cc6f9
[]
no_license
HenrikBengtsson/matrixStats
78e0edb5e23265b39a0ceb14f59e317fde401a79
3e8f9ddafc0de61e870534b75fb5f90429a7bd31
refs/heads/develop
2023-07-26T10:52:03.035332
2023-07-10T20:20:44
2023-07-10T20:20:44
20,844,530
196
41
null
2023-05-26T22:51:17
2014-06-14T23:59:10
R
UTF-8
C
false
false
658
h
diff2_lowlevel.h
#include <Rdefines.h> #include <R_ext/Constants.h> #include "000.types.h" #include "000.utils.h" #include "000.macros.h" /* Native API (dynamically generated via macros): void diff2_int(int *x, R_xlen_t nx, R_xlen_t *idxs, R_xlen_t nidxs, int idxsHasNA R_xlen_t lag, R_xlen_t differences, int *ans, R_xlen_t nans) void diff2_dbl(double *x, R_xlen_t nx, R_xlen_t *idxs, R_xlen_t nidxs, int idxsHasNA R_xlen_t lag, R_xlen_t differences, int *ans, R_xlen_t nans) */ #define X_TYPE 'i' #include "diff2_lowlevel_template.h" #include "000.templates-types_undef.h" #define X_TYPE 'r' #include "diff2_lowlevel_template.h" #include "000.templates-types_undef.h"
9218c8701722c04194351b8733a2d2aeffe2b151
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
/SOFTWARE/A64-TERES/u-boot_new/arch/powerpc/cpu/mpc8260/cpu.c
6eed6f53a3a184df7463dbb4416796fb2f78a3a5
[ "GPL-2.0-or-later", "LicenseRef-scancode-free-unknown", "Apache-2.0" ]
permissive
OLIMEX/DIY-LAPTOP
ae82f4ee79c641d9aee444db9a75f3f6709afa92
a3fafd1309135650bab27f5eafc0c32bc3ca74ee
refs/heads/rel3
2023-08-04T01:54:19.483792
2023-04-03T07:18:12
2023-04-03T07:18:12
80,094,055
507
92
Apache-2.0
2023-04-03T07:05:59
2017-01-26T07:25:50
C
UTF-8
C
false
false
7,449
c
cpu.c
/* * (C) Copyright 2000-2006 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. * * SPDX-License-Identifier: GPL-2.0+ */ /* * CPU specific code for the MPC825x / MPC826x / MPC827x / MPC828x * * written or collected and sometimes rewritten by * Magnus Damm <damm@bitsmart.com> * * modified by * Wolfgang Denk <wd@denx.de> * * modified for 8260 by * Murray Jensen <Murray.Jensen@cmst.csiro.au> * * added 8260 masks by * Marius Groeger <mag@sysgo.de> * * added HiP7 (824x/827x/8280) processors support by * Yuli Barcohen <yuli@arabellasw.com> */ #include <common.h> #include <watchdog.h> #include <command.h> #include <mpc8260.h> #include <netdev.h> #include <asm/processor.h> #include <asm/cpm_8260.h> #if defined(CONFIG_OF_LIBFDT) #include <libfdt.h> #include <fdt_support.h> #endif DECLARE_GLOBAL_DATA_PTR; #if defined(CONFIG_GET_CPU_STR_F) extern int get_cpu_str_f (char *buf); #endif int checkcpu (void) { volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; ulong clock = gd->cpu_clk; uint pvr = get_pvr (); uint immr, rev, m, k; char buf[32]; puts ("CPU: "); switch (pvr) { case PVR_8260: case PVR_8260_HIP3: k = 3; break; case PVR_8260_HIP4: k = 4; break; case PVR_8260_HIP7R1: case PVR_8260_HIP7RA: case PVR_8260_HIP7: k = 7; break; default: return -1; /* whoops! not an MPC8260 */ } rev = pvr & 0xff; immr = immap->im_memctl.memc_immr; if ((immr & IMMR_ISB_MSK) != CONFIG_SYS_IMMR) return -1; /* whoops! someone moved the IMMR */ #if defined(CONFIG_GET_CPU_STR_F) get_cpu_str_f (buf); printf ("%s (HiP%d Rev %02x, Mask ", buf, k, rev); #else printf (CPU_ID_STR " (HiP%d Rev %02x, Mask ", k, rev); #endif /* * the bottom 16 bits of the immr are the Part Number and Mask Number * (4-34); the 16 bits at PROFF_REVNUM (0x8af0) in dual port ram is the * RISC Microcode Revision Number (13-10). * For the 8260, Motorola doesn't include the Microcode Revision * in the mask. */ m = immr & (IMMR_PARTNUM_MSK | IMMR_MASKNUM_MSK); k = immap->im_dprambase16[PROFF_REVNUM / sizeof(u16)]; switch (m) { case 0x0000: puts ("0.2 2J24M"); break; case 0x0010: puts ("A.0 K22A"); break; case 0x0011: puts ("A.1 1K22A-XC"); break; case 0x0001: puts ("B.1 1K23A"); break; case 0x0021: puts ("B.2 2K23A-XC"); break; case 0x0023: puts ("B.3 3K23A"); break; case 0x0024: puts ("C.2 6K23A"); break; case 0x0060: puts ("A.0(A) 2K25A"); break; case 0x0062: puts ("B.1 4K25A"); break; case 0x0064: puts ("C.0 5K25A"); break; case 0x0A00: puts ("0.0 0K49M"); break; case 0x0A01: puts ("0.1 1K49M"); break; case 0x0A10: puts ("1.0 1K49M"); break; case 0x0C00: puts ("0.0 0K50M"); break; case 0x0C10: puts ("1.0 1K50M"); break; case 0x0D00: puts ("0.0 0K50M"); break; case 0x0D10: puts ("1.0 1K50M"); break; default: printf ("unknown [immr=0x%04x,k=0x%04x]", m, k); break; } printf (") at %s MHz\n", strmhz (buf, clock)); return 0; } /* ------------------------------------------------------------------------- */ /* configures a UPM by writing into the UPM RAM array */ /* uses bank 11 and a dummy physical address (=BRx_BA_MSK) */ /* NOTE: the physical address chosen must not overlap into any other area */ /* mapped by the memory controller because bank 11 has the lowest priority */ void upmconfig (uint upm, uint * table, uint size) { volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; volatile memctl8260_t *memctl = &immap->im_memctl; volatile uchar *dummy = (uchar *) BRx_BA_MSK; /* set all BA bits */ uint i; /* first set up bank 11 to reference the correct UPM at a dummy address */ memctl->memc_or11 = ORxU_AM_MSK; /* set all AM bits */ switch (upm) { case UPMA: memctl->memc_br11 = ((uint)dummy & BRx_BA_MSK) | BRx_PS_32 | BRx_MS_UPMA | BRx_V; memctl->memc_mamr = MxMR_OP_WARR; break; case UPMB: memctl->memc_br11 = ((uint)dummy & BRx_BA_MSK) | BRx_PS_32 | BRx_MS_UPMB | BRx_V; memctl->memc_mbmr = MxMR_OP_WARR; break; case UPMC: memctl->memc_br11 = ((uint)dummy & BRx_BA_MSK) | BRx_PS_32 | BRx_MS_UPMC | BRx_V; memctl->memc_mcmr = MxMR_OP_WARR; break; default: panic ("upmconfig passed invalid UPM number (%u)\n", upm); break; } /* * at this point, the dummy address is set up to access the selected UPM, * the MAD pointer is zero, and the MxMR OP is set for writing to RAM * * now we simply load the mdr with each word and poke the dummy address. * the MAD is incremented on each access. */ for (i = 0; i < size; i++) { memctl->memc_mdr = table[i]; *dummy = 0; } /* now kill bank 11 */ memctl->memc_br11 = 0; } /* ------------------------------------------------------------------------- */ #if !defined(CONFIG_HAVE_OWN_RESET) int do_reset (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) { ulong msr, addr; volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; immap->im_clkrst.car_rmr = RMR_CSRE; /* Checkstop Reset enable */ /* Interrupts and MMU off */ __asm__ __volatile__ ("mfmsr %0":"=r" (msr):); msr &= ~(MSR_ME | MSR_EE | MSR_IR | MSR_DR); __asm__ __volatile__ ("mtmsr %0"::"r" (msr)); /* * Trying to execute the next instruction at a non-existing address * should cause a machine check, resulting in reset */ #ifdef CONFIG_SYS_RESET_ADDRESS addr = CONFIG_SYS_RESET_ADDRESS; #else /* * note: when CONFIG_SYS_MONITOR_BASE points to a RAM address, CONFIG_SYS_MONITOR_BASE * - sizeof (ulong) is usually a valid address. Better pick an address * known to be invalid on your system and assign it to CONFIG_SYS_RESET_ADDRESS. */ addr = CONFIG_SYS_MONITOR_BASE - sizeof (ulong); #endif ((void (*)(void)) addr) (); return 1; } #endif /* CONFIG_HAVE_OWN_RESET */ /* ------------------------------------------------------------------------- */ /* * Get timebase clock frequency (like cpu_clk in Hz) * */ unsigned long get_tbclk (void) { ulong tbclk; tbclk = (gd->bus_clk + 3L) / 4L; return (tbclk); } /* ------------------------------------------------------------------------- */ #if defined(CONFIG_WATCHDOG) void watchdog_reset (void) { int re_enable = disable_interrupts (); reset_8260_watchdog ((immap_t *) CONFIG_SYS_IMMR); if (re_enable) enable_interrupts (); } #endif /* CONFIG_WATCHDOG */ /* ------------------------------------------------------------------------- */ #if defined(CONFIG_OF_LIBFDT) && defined (CONFIG_OF_BOARD_SETUP) void ft_cpu_setup (void *blob, bd_t *bd) { #if defined(CONFIG_HAS_ETH0) || defined(CONFIG_HAS_ETH1) ||\ defined(CONFIG_HAS_ETH2) || defined(CONFIG_HAS_ETH3) fdt_fixup_ethernet(blob); #endif do_fixup_by_compat_u32(blob, "fsl,cpm2-brg", "clock-frequency", bd->bi_brgfreq, 1); do_fixup_by_prop_u32(blob, "device_type", "cpu", 4, "bus-frequency", bd->bi_busfreq, 1); do_fixup_by_prop_u32(blob, "device_type", "cpu", 4, "timebase-frequency", OF_TBCLK, 1); do_fixup_by_prop_u32(blob, "device_type", "cpu", 4, "clock-frequency", bd->bi_intfreq, 1); fdt_fixup_memory(blob, (u64)bd->bi_memstart, (u64)bd->bi_memsize); } #endif /* CONFIG_OF_LIBFDT */ /* * Initializes on-chip ethernet controllers. * to override, implement board_eth_init() */ int cpu_eth_init(bd_t *bis) { #if defined(CONFIG_ETHER_ON_FCC) fec_initialize(bis); #endif #if defined(CONFIG_ETHER_ON_SCC) mpc82xx_scc_enet_initialize(bis); #endif return 0; }
a5979a1fa6bb81d12f9514ba74cbc8ed7209b173
ce99bd11ca505967277f4689c621479c1987698e
/assets/obseg/text/LeldJ.c
cd22fde33afd3c5d47d6c2bb82bf15052629d77a
[]
no_license
n64decomp/007
5951258890f15431f273e1503674c5e0402c66e0
c46751089ddc18b12ef7a45b6a3e03de2054c422
refs/heads/master
2022-11-08T23:34:54.021033
2022-10-29T14:41:01
2022-10-29T14:41:01
241,212,109
359
48
null
2020-11-21T23:30:31
2020-02-17T21:31:00
C
UTF-8
C
false
false
41
c
LeldJ.c
char *LeldJ[] = { 0, 0, 0, 0, 0 };
777e05a965a11b772712ebfa5f2ef9e01720a737
8f76cee606ca901d6b9c1ecdcadaa172aa861c00
/languages/cprogs/Ex_7.4.c
3d1224b7881d5976a980d748880d6a629b6712ff
[ "BSD-3-Clause" ]
permissive
uthcode/learntosolveit
b0cdc386ab17dadcefef9867aacc5ef0326b7215
88b1cbfea313fdca50f48573c396bed9ba38c354
refs/heads/master
2023-05-24T14:00:34.115585
2023-05-15T00:18:02
2023-05-15T00:18:02
14,986,557
171
1,714
NOASSERTION
2022-09-13T13:37:07
2013-12-06T15:44:38
Java
UTF-8
C
false
false
1,822
c
Ex_7.4.c
/* minscanf: minimalistic scanf function */ #include<stdarg.h> #include<stdio.h> void minscanf(char *fmt,...); int main(void) { int i; minscanf("%d", &i); printf("minscanf input: %d\n", i); char * a; minscanf("%s", a); printf("minscanf input: %s\n", a); float f; minscanf("%f", &f); printf("minscanf input: %f\n", f); int o; minscanf("%o", &o); printf("minscanf input in octal %o, in decimal %d\n", o, o); int x; minscanf("%x", &x); printf("minscanf input in hex %x, in decimal %d\n", x, x); return 0; } void minscanf(char *fmt,...) { va_list ap; /* points to each unnamed arg in turn */ char *p,*sval; int *ival; float *dval; va_start(ap,fmt); /* make ap point to 1st unnamed arg */ for(p=fmt;*p;p++) { if(*p != '%') { continue; } switch(*++p) { case 'd': ival = va_arg(ap,int*); char * d = "44"; sscanf(d,"%d",ival); break; case 'f': dval = va_arg(ap,float*); char * f = "5.33"; sscanf(f,"%f",dval); break; case 's': sval = va_arg(ap,char*); sscanf("test char", "%s", sval); break; case 'o': ival = va_arg(ap,int*); char * o = "011"; sscanf(o, "%o", ival); break; case 'x': ival =va_arg(ap,int*); char * x = "1a"; sscanf(x, "%x", ival); break; default: putchar(*p); break; } } va_end(ap); /* clean up when done */ }
6178f55f2c6a1b64be681b0bfded38b550aa7aba
010279e2ba272d09e9d2c4e903722e5faba2cf7a
/contrib/python/numpy/py3/numpy/core/include/numpy/config-darwin-arm64.h
430b3fb05dbb64d647efff5b892b1a5beef44008
[ "BSD-3-Clause", "Zlib", "MIT", "Apache-2.0" ]
permissive
catboost/catboost
854c1a1f439a96f1ae6b48e16644be20aa04dba2
f5042e35b945aded77b23470ead62d7eacefde92
refs/heads/master
2023-09-01T12:14:14.174108
2023-09-01T10:01:01
2023-09-01T10:22:12
97,556,265
8,012
1,425
Apache-2.0
2023-09-11T03:32:32
2017-07-18T05:29:04
Python
UTF-8
C
false
false
511
h
config-darwin-arm64.h
#pragma once #include "config-darwin-x86_64.h" #undef HAVE_XMMINTRIN_H #undef HAVE_EMMINTRIN_H #undef HAVE_IMMINTRIN_H #undef HAVE_ATTRIBUTE_TARGET_AVX #undef HAVE_ATTRIBUTE_TARGET_AVX2 #undef HAVE_ATTRIBUTE_TARGET_AVX512F #undef HAVE_ATTRIBUTE_TARGET_AVX512_SKX #undef HAVE_ATTRIBUTE_TARGET_AVX2_WITH_INTRINSICS #undef HAVE_ATTRIBUTE_TARGET_AVX512F_WITH_INTRINSICS #undef HAVE_ATTRIBUTE_TARGET_AVX512_SKX_WITH_INTRINSICS #undef HAVE_LDOUBLE_INTEL_EXTENDED_16_BYTES_LE #define HAVE_LDOUBLE_IEEE_DOUBLE_LE 1
72c338ef040a6ced90c920b05fad32fa8ef5ae13
99bdb3251fecee538e0630f15f6574054dfc1468
/bsp/bouffalo_lab/libraries/bl_mcu_sdk/drivers/lhal/src/bflb_l1c.c
4e377e9f8a5e8cf3eab9b2fb32d7cd97b9a01f70
[ "Apache-2.0", "Zlib", "LicenseRef-scancode-proprietary-license", "MIT", "BSD-3-Clause", "X11", "BSD-4-Clause-UC", "LicenseRef-scancode-unknown-license-reference" ]
permissive
RT-Thread/rt-thread
03a7c52c2aeb1b06a544143b0e803d72f47d1ece
3602f891211904a27dcbd51e5ba72fefce7326b2
refs/heads/master
2023-09-01T04:10:20.295801
2023-08-31T16:20:55
2023-08-31T16:20:55
7,408,108
9,599
5,805
Apache-2.0
2023-09-14T13:37:26
2013-01-02T14:49:21
C
UTF-8
C
false
false
3,830
c
bflb_l1c.c
#include "bflb_l1c.h" #if (defined(BL616) || defined(BL606P) || defined(BL808) || defined(BL628)) && !defined(CPU_LP) #include "csi_core.h" void bflb_l1c_icache_enable(void) { csi_icache_enable(); } void bflb_l1c_icache_disable(void) { csi_icache_disable(); } ATTR_TCM_SECTION void bflb_l1c_icache_invalid_all(void) { csi_icache_invalid(); } void bflb_l1c_dcache_enable(void) { csi_dcache_enable(); } void bflb_l1c_dcache_disable(void) { csi_dcache_disable(); } ATTR_TCM_SECTION void bflb_l1c_dcache_clean_all(void) { csi_dcache_clean(); } ATTR_TCM_SECTION void bflb_l1c_dcache_invalidate_all(void) { csi_dcache_invalid(); } ATTR_TCM_SECTION void bflb_l1c_dcache_clean_invalidate_all(void) { csi_dcache_clean_invalid(); } ATTR_TCM_SECTION void bflb_l1c_dcache_clean_range(void *addr, uint32_t size) { csi_dcache_clean_range(addr, size); } ATTR_TCM_SECTION void bflb_l1c_dcache_invalidate_range(void *addr, uint32_t size) { csi_dcache_invalid_range(addr, size); } ATTR_TCM_SECTION void bflb_l1c_dcache_clean_invalidate_range(void *addr, uint32_t size) { csi_dcache_clean_invalid_range(addr, size); } #else #if defined(BL702) || defined(BL702L) extern void L1C_Cache_Enable_Set(uint8_t wayDisable); extern void L1C_Cache_Flush(void); #endif void bflb_l1c_icache_enable(void) { } void bflb_l1c_icache_disable(void) { #if defined(BL702) || defined(BL702L) L1C_Cache_Enable_Set(0x0f); #endif } void bflb_l1c_icache_invalid_all(void) { } void bflb_l1c_dcache_enable(void) { } void bflb_l1c_dcache_disable(void) { } void bflb_l1c_dcache_clean_all(void) { } void bflb_l1c_dcache_invalidate_all(void) { #if defined(BL702) || defined(BL702L) L1C_Cache_Flush(); #endif } void bflb_l1c_dcache_clean_invalidate_all(void) { #if defined(BL702) || defined(BL702L) L1C_Cache_Flush(); #endif } void bflb_l1c_dcache_clean_range(void *addr, uint32_t size) { } ATTR_TCM_SECTION void bflb_l1c_dcache_invalidate_range(void *addr, uint32_t size) { #if defined(BL702) || defined(BL702L) L1C_Cache_Flush(); #endif } #if defined(BL702) || defined(BL702L) /****************************************************************************/ /** * @brief L1C cache write set * * @param wt_en: L1C write through enable * @param wb_en: L1C write back enable * @param wa_en: L1C write allocate enable * * @return None * *******************************************************************************/ __WEAK void ATTR_TCM_SECTION bflb_l1c_cache_write_set(uint8_t wt_en, uint8_t wb_en, uint8_t wa_en) { uint32_t regval = 0; regval = getreg32(0x40009000 + 0x0); if (wt_en) { regval |= (1<<4); } else { regval &= ~(1<<4); } if (wb_en) { regval |= (1<<5); } else { regval &= ~(1<<5); } if (wa_en) { regval |= (1<<6); } else { regval &= ~(1<<6); } putreg32(regval, 0x40009000+0x0); } #endif /****************************************************************************/ /** * @brief Get hit count * * @param hit_count_low: hit count low 32 bits pointer * @param hit_count_high: hit count high 32 bits pointer * * @return None * *******************************************************************************/ __WEAK void ATTR_TCM_SECTION bflb_l1c_hit_count_get(uint32_t *hit_count_low, uint32_t *hit_count_high) { *hit_count_low = getreg32(0x40009000 + 0x4); *hit_count_high = getreg32(0x40009000 + 0x8); } /****************************************************************************/ /** * @brief Get miss count * * @param None * * @return Miss count * *******************************************************************************/ __WEAK uint32_t ATTR_TCM_SECTION bflb_l1c_miss_count_get(void) { return getreg32(0x40009000 + 0xC); } #endif
868f0339f1e2890d2f0a623859ddb97142f37fd9
89edd785fe88d2fafc6d6d1847cfa24b7bd855bd
/grbl_controller_esp32/icons/bmp74/sdcard_button.h
7f23b3ca12497589ab77fead95d036ada54dafa3
[]
no_license
mstrens/grbl_controller_esp32
a6f65a96bf9911121f3a92231690f3b540993de6
014861320d4872bec7209abe03ac99c6ea363805
refs/heads/master
2023-05-24T18:47:37.110322
2022-05-24T06:59:23
2022-05-24T06:59:23
170,190,948
156
82
null
2023-05-10T07:20:29
2019-02-11T19:45:27
C
UTF-8
C
false
false
4,807
h
sdcard_button.h
0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x07, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x03, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xfe, 0x3e, 0x7c, 0xf9, 0xf1, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xfc, 0x3e, 0x7c, 0xf9, 0xf1, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xf8, 0x3e, 0x7c, 0xf9, 0xf1, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xf1, 0x3e, 0x7c, 0xf9, 0xf1, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xe3, 0x3e, 0x7c, 0xf9, 0xf1, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xc7, 0x3e, 0x7c, 0xf9, 0xf1, 0xff, 0xff, 0xc0, 0xff, 0xff, 0x8f, 0x3e, 0x7c, 0xf9, 0xf1, 0xff, 0xff, 0xc0, 0xff, 0xff, 0x8f, 0x3e, 0x7c, 0xf9, 0xf1, 0xff, 0xff, 0xc0, 0xff, 0xff, 0x8f, 0x3e, 0x7c, 0xf9, 0xf1, 0xff, 0xff, 0xc0, 0xff, 0xff, 0x8f, 0x3e, 0x7c, 0xf9, 0xf1, 0xff, 0xff, 0xc0, 0xff, 0xff, 0x8f, 0x3e, 0x7c, 0xf9, 0xf1, 0xff, 0xff, 0xc0, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xc0, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xc0, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xc0, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xc0, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xc0, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xc0, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xc0, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xc0, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xc0, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xc0, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xc0, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xc0, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xc0, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xc0, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xc0, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xc0, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xc0, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xc0, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xc0, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xc0, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xc0, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xc0, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xc0, 0xff, 0xff, 0x81, 0xff, 0x9b, 0x60, 0x01, 0xff, 0xff, 0xc0, 0xff, 0xff, 0x83, 0xff, 0x12, 0xf0, 0x01, 0xff, 0xff, 0xc0, 0xff, 0xff, 0x83, 0xe0, 0x35, 0xf8, 0x01, 0xff, 0xff, 0xc0, 0xff, 0xff, 0x81, 0xf0, 0x01, 0xf8, 0x01, 0xff, 0xff, 0xc0, 0xff, 0xff, 0x80, 0xf8, 0x03, 0xf0, 0x01, 0xff, 0xff, 0xc0, 0xff, 0xff, 0x80, 0x3c, 0x07, 0xe0, 0x01, 0xff, 0xff, 0xc0, 0xff, 0xff, 0x83, 0xfc, 0x1f, 0xc0, 0x01, 0xff, 0xff, 0xc0, 0xff, 0xff, 0x87, 0xfc, 0x3f, 0x00, 0x01, 0xff, 0xff, 0xc0, 0xff, 0xff, 0x8f, 0xf8, 0x7c, 0x00, 0x01, 0xff, 0xff, 0xc0, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xc0, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x07, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xfe, 0x01, 0x81, 0x80, 0x7f, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xfe, 0x01, 0x81, 0x80, 0x7f, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0xcf, 0x9f, 0xf3, 0xff, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0xcf, 0x9f, 0xf3, 0xff, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0xcf, 0x87, 0xf3, 0xff, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0xcf, 0x87, 0xf3, 0xff, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0xcf, 0x9f, 0xf3, 0xff, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0xcf, 0x9f, 0xf3, 0xff, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0xcf, 0x9f, 0xf3, 0xff, 0xff, 0xff, 0xc0, 0xff, 0xff, 0xff, 0xcf, 0x9f, 0xf3, 0xff, 0xff, 0xff, 0xc0, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00
77be63e6edf0cd15c3fd357071d8b1edbb80335a
c26d7b0ed875357278e61627da2da0650da77986
/src/games/atc/list.c
d9d6f4f51056bce7bbf5a5440d0a93cb1b90f18c
[ "BSD-3-Clause" ]
permissive
RetroBSD/retrobsd
5343d9e3c424637fc3ad5b03fe720b2744490025
486f81f6abff01c7dcc207235cd2979b226a95ff
refs/heads/master
2023-09-02T23:12:05.110883
2023-07-07T18:41:40
2023-07-07T18:41:40
18,598,087
282
59
BSD-3-Clause
2023-07-18T07:35:36
2014-04-09T13:25:46
C
UTF-8
C
false
false
1,298
c
list.c
/* * Copyright (c) 1987 by Ed James, UC Berkeley. All rights reserved. * * Copy permission is hereby granted provided that this notice is * retained on all partial or complete copies. * * For more info on this and all of my stuff, mail edjames@berkeley.edu. */ #include "include.h" PLANE * newplane() { return ((PLANE *) calloc(1, sizeof (PLANE))); } void append(l, p) LIST *l; PLANE *p; { PLANE *q = NULL, *r = NULL; if (l->head == NULL) { p->next = p->prev = NULL; l->head = l->tail = p; } else { q = l -> head; while (q != NULL && q->plane_no < p->plane_no) { r = q; q = q -> next; } if (q) { if (r) { p->prev = r; r->next = p; p->next = q; q->prev = p; } else { p->next = q; p->prev = NULL; q->prev = p; l->head = p; } } else { l->tail->next = p; p->next = NULL; p->prev = l->tail; l->tail = p; } } } void delete(l, p) LIST *l; PLANE *p; { if (l->head == NULL) loser(p, "deleted a non-existant plane! Get help!"); if (l->head == p && l->tail == p) l->head = l->tail = NULL; else if (l->head == p) { l->head = p->next; l->head->prev = NULL; } else if (l->tail == p) { l->tail = p->prev; l->tail->next = NULL; } else { p->prev->next = p->next; p->next->prev = p->prev; } }
984942ec58107945d482eb588ec2a6fa9f25054c
65fdaca13c290f2fa22da50001853e1fd552c0b1
/src/libjasper/mif/mif_cod.c
a3518da4849fef2e98ce4457b5476909d77388e2
[ "JasPer-2.0" ]
permissive
jasper-software/jasper
3455612cf8883ab56ca4feae3809f6dc5b96e9b4
354722a9a42e502092c31941913f4552bb72eb63
refs/heads/master
2023-04-12T22:07:31.034524
2023-04-11T02:36:07
2023-04-11T02:36:07
68,406,758
104
49
NOASSERTION
2023-03-27T13:58:42
2016-09-16T18:52:32
C
UTF-8
C
false
false
22,670
c
mif_cod.c
/* * Copyright (c) 2001-2002 Michael David Adams. * All rights reserved. */ /* __START_OF_JASPER_LICENSE__ * * JasPer License Version 2.0 * * Copyright (c) 2001-2006 Michael David Adams * Copyright (c) 1999-2000 Image Power, Inc. * Copyright (c) 1999-2000 The University of British Columbia * * All rights reserved. * * Permission is hereby granted, free of charge, to any person (the * "User") 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, 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: * * 1. The above copyright notices and this permission notice (which * includes the disclaimer below) shall be included in all copies or * substantial portions of the Software. * * 2. The name of a copyright holder shall not be used to endorse or * promote products derived from the Software without specific prior * written permission. * * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS * LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER * THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS * "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 OF THIRD PARTY RIGHTS. IN NO * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE * PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE * THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY. * EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS * BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL * PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS * GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE * ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE * IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL * SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES, * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL * SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH * THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH, * PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH * RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY * EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. * * __END_OF_JASPER_LICENSE__ */ /******************************************************************************\ * Includes. \******************************************************************************/ #include "mif_cod.h" #include "jasper/jas_cm.h" #include "jasper/jas_tvp.h" #include "jasper/jas_stream.h" #include "jasper/jas_image.h" #include "jasper/jas_seq.h" #include "jasper/jas_string.h" #include "jasper/jas_malloc.h" #include "jasper/jas_debug.h" #include <assert.h> #include <stdio.h> #include <stdlib.h> #include <string.h> /******************************************************************************\ * Local types. \******************************************************************************/ typedef enum { MIF_END = 0, MIF_CMPT } mif_tagid2_t; typedef enum { MIF_TLX = 0, MIF_TLY, MIF_WIDTH, MIF_HEIGHT, MIF_HSAMP, MIF_VSAMP, MIF_PREC, MIF_SGND, MIF_DATA } mif_tagid_t; /******************************************************************************\ * Local functions. \******************************************************************************/ static mif_hdr_t *mif_hdr_create(int maxcmpts); static void mif_hdr_destroy(mif_hdr_t *hdr); static int mif_hdr_growcmpts(mif_hdr_t *hdr, int maxcmpts); static mif_hdr_t *mif_hdr_get(jas_stream_t *in); static int mif_process_cmpt(mif_hdr_t *hdr, char *buf); static int mif_hdr_put(mif_hdr_t *hdr, jas_stream_t *out); static int mif_hdr_addcmpt(mif_hdr_t *hdr, int cmptno, mif_cmpt_t *cmpt); static mif_cmpt_t *mif_cmpt_create(void); static void mif_cmpt_destroy(mif_cmpt_t *cmpt); static char *mif_getline(jas_stream_t *jas_stream, char *buf, int bufsize); static int mif_getc(jas_stream_t *in); static mif_hdr_t *mif_makehdrfromimage(jas_image_t *image); /******************************************************************************\ * Local data. \******************************************************************************/ static const jas_taginfo_t mif_tags2[] = { {MIF_CMPT, "component"}, {MIF_END, "end"}, {-1, 0} }; static const jas_taginfo_t mif_tags[] = { {MIF_TLX, "tlx"}, {MIF_TLY, "tly"}, {MIF_WIDTH, "width"}, {MIF_HEIGHT, "height"}, {MIF_HSAMP, "sampperx"}, {MIF_VSAMP, "samppery"}, {MIF_PREC, "prec"}, {MIF_SGND, "sgnd"}, {MIF_DATA, "data"}, {-1, 0} }; /******************************************************************************\ * Code for load operation. \******************************************************************************/ /* Load an image from a stream in the MIF format. */ jas_image_t *mif_decode(jas_stream_t *in, const char *optstr) { mif_hdr_t *hdr; jas_image_t *image; jas_image_t *tmpimage; jas_stream_t *tmpstream; int cmptno; mif_cmpt_t *cmpt; jas_image_cmptparm_t cmptparm; jas_seq2d_t *data; int_fast32_t x; int_fast32_t y; int bias; JAS_LOGDEBUGF(10, "mif_decode(%p, \"%s\")\n", in, (optstr ? optstr : "")); JAS_UNUSED(optstr); hdr = 0; image = 0; tmpimage = 0; tmpstream = 0; data = 0; JAS_LOGDEBUGF(10, "getting MIF header\n"); if (!(hdr = mif_hdr_get(in))) { jas_logerrorf("cannot get MIF header\n"); goto error; } if (!(image = jas_image_create0())) { jas_logerrorf("cannot create image\n"); goto error; } for (cmptno = 0; cmptno < hdr->numcmpts; ++cmptno) { JAS_LOGDEBUGF(10, "processing component %d of %d\n", cmptno, hdr->numcmpts); cmpt = hdr->cmpts[cmptno]; tmpstream = cmpt->data ? jas_stream_fopen(cmpt->data, "rb") : in; if (!tmpstream) { jas_logerrorf("cannot open component file %s\n", cmpt->data); goto error; } JAS_LOGDEBUGF(10, "decoding component %d\n", cmptno); if (!(tmpimage = jas_image_decode(tmpstream, -1, "allow_trunc=1"))) { jas_logerrorf("cannot decode image\n"); goto error; } if (tmpstream != in) { jas_stream_close(tmpstream); tmpstream = 0; } if (!cmpt->width) { cmpt->width = jas_image_cmptwidth(tmpimage, 0); } if (!cmpt->height) { cmpt->height = jas_image_cmptwidth(tmpimage, 0); } if (!cmpt->prec) { cmpt->prec = jas_image_cmptprec(tmpimage, 0); } if (cmpt->sgnd < 0) { cmpt->sgnd = jas_image_cmptsgnd(tmpimage, 0); } cmptparm.tlx = cmpt->tlx; cmptparm.tly = cmpt->tly; cmptparm.hstep = cmpt->sampperx; cmptparm.vstep = cmpt->samppery; cmptparm.width = cmpt->width; cmptparm.height = cmpt->height; cmptparm.prec = cmpt->prec; cmptparm.sgnd = cmpt->sgnd; JAS_LOGDEBUGF(10, "adding component %d\n", cmptno); if (jas_image_addcmpt(image, jas_image_numcmpts(image), &cmptparm)) { jas_logerrorf("cannot add component\n"); goto error; } JAS_LOGDEBUGF(10, "copying component %d\n", cmptno); if (!(data = jas_seq2d_create(0, 0, cmpt->width, cmpt->height))) { jas_logerrorf("cannot create sequence\n"); goto error; } JAS_LOGDEBUGF(10, "reading component %d\n", cmptno); if (jas_image_readcmpt(tmpimage, 0, 0, 0, cmpt->width, cmpt->height, data)) { jas_logerrorf("cannot read component\n"); goto error; } if (cmpt->sgnd) { bias = 1 << (cmpt->prec - 1); for (y = 0; y < cmpt->height; ++y) { for (x = 0; x < cmpt->width; ++x) { *jas_seq2d_getref(data, x, y) -= bias; } } } JAS_LOGDEBUGF(10, "writing component %d\n", cmptno); if (jas_image_writecmpt(image, jas_image_numcmpts(image) - 1, 0, 0, cmpt->width, cmpt->height, data)) { jas_logerrorf("cannot write component\n"); goto error; } jas_seq2d_destroy(data); data = 0; jas_image_destroy(tmpimage); tmpimage = 0; } mif_hdr_destroy(hdr); hdr = 0; return image; error: if (image) { jas_image_destroy(image); } if (hdr) { mif_hdr_destroy(hdr); } if (tmpstream && tmpstream != in) { jas_stream_close(tmpstream); } if (tmpimage) { jas_image_destroy(tmpimage); } if (data) { jas_seq2d_destroy(data); } return 0; } /******************************************************************************\ * Code for save operation. \******************************************************************************/ /* Save an image to a stream in the the MIF format. */ int mif_encode(jas_image_t *image, jas_stream_t *out, const char *optstr) { mif_hdr_t *hdr; jas_image_t *tmpimage; int fmt; int cmptno; mif_cmpt_t *cmpt; jas_image_cmptparm_t cmptparm; jas_seq2d_t *data; int_fast32_t x; int_fast32_t y; int bias; JAS_LOGDEBUGF(10, "mif_encode(%p, %p, \"%s\")\n", image, out, (optstr ? optstr : "")); hdr = 0; tmpimage = 0; data = 0; if (optstr && *optstr != '\0') { jas_logwarnf("warning: ignoring unsupported options\n"); } if ((fmt = jas_image_strtofmt("pnm")) < 0) { jas_logerrorf("error: PNM support required\n"); goto error; } if (!(hdr = mif_makehdrfromimage(image))) { jas_logerrorf("cannot make MIF header\n"); goto error; } if (mif_hdr_put(hdr, out)) { jas_logerrorf("cannot write MIF header\n"); goto error; } /* Output component data. */ for (cmptno = 0; cmptno < hdr->numcmpts; ++cmptno) { cmpt = hdr->cmpts[cmptno]; if (!cmpt->data) { if (!(tmpimage = jas_image_create0())) { jas_logerrorf("cannot create image\n"); goto error; } cmptparm.tlx = 0; cmptparm.tly = 0; cmptparm.hstep = cmpt->sampperx; cmptparm.vstep = cmpt->samppery; cmptparm.width = cmpt->width; cmptparm.height = cmpt->height; cmptparm.prec = cmpt->prec; cmptparm.sgnd = false; if (jas_image_addcmpt(tmpimage, jas_image_numcmpts(tmpimage), &cmptparm)) { jas_logerrorf("cannot add component\n"); goto error; } jas_image_setclrspc(tmpimage, JAS_CLRSPC_SGRAY); jas_image_setcmpttype(tmpimage, 0, JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_GRAY_Y)); if (!(data = jas_seq2d_create(0, 0, cmpt->width, cmpt->height))) { jas_logerrorf("cannot create sequence\n"); goto error; } if (jas_image_readcmpt(image, cmptno, 0, 0, cmpt->width, cmpt->height, data)) { jas_logerrorf("cannot read component\n"); goto error; } if (cmpt->sgnd) { bias = 1 << (cmpt->prec - 1); for (y = 0; y < cmpt->height; ++y) { for (x = 0; x < cmpt->width; ++x) { *jas_seq2d_getref(data, x, y) += bias; } } } if (jas_image_writecmpt(tmpimage, 0, 0, 0, cmpt->width, cmpt->height, data)) { jas_logerrorf("cannot write component\n"); goto error; } jas_seq2d_destroy(data); data = 0; if (jas_image_encode(tmpimage, out, fmt, 0)) { jas_logerrorf("cannot encode image\n"); goto error; } jas_image_destroy(tmpimage); tmpimage = 0; } } mif_hdr_destroy(hdr); return 0; error: if (hdr) { mif_hdr_destroy(hdr); } if (tmpimage) { jas_image_destroy(tmpimage); } if (data) { jas_seq2d_destroy(data); } return -1; } /******************************************************************************\ * Code for validate operation. \******************************************************************************/ int mif_validate(jas_stream_t *in) { jas_uchar buf[MIF_MAGICLEN]; uint_fast32_t magic; JAS_LOGDEBUGF(10, "mif_validate(%p)\n", in); assert(JAS_STREAM_MAXPUTBACK >= MIF_MAGICLEN); /* Read the validation data (i.e., the data used for detecting the format). */ if (jas_stream_peek(in, buf, sizeof(buf)) != sizeof(buf)) { JAS_LOGDEBUGF(10, "mif_validate peek failed\n"); return -1; } /* Compute the signature value. */ magic = (JAS_CAST(uint_fast32_t, buf[0]) << 24) | (JAS_CAST(uint_fast32_t, buf[1]) << 16) | (JAS_CAST(uint_fast32_t, buf[2]) << 8) | buf[3]; /* Ensure that the signature is correct for this format. */ if (magic != MIF_MAGIC) { JAS_LOGDEBUGF(10, "mif_validate magic mismatch %x %x\n", magic, MIF_MAGIC); return -1; } return 0; } /******************************************************************************\ * Code for MIF header class. \******************************************************************************/ static mif_hdr_t *mif_hdr_create(int maxcmpts) { JAS_LOGDEBUGF(10, "mif_hdr_create(%d)\n", maxcmpts); mif_hdr_t *hdr; if (!(hdr = jas_malloc(sizeof(mif_hdr_t)))) { return 0; } hdr->numcmpts = 0; hdr->maxcmpts = 0; hdr->cmpts = 0; if (mif_hdr_growcmpts(hdr, maxcmpts)) { mif_hdr_destroy(hdr); return 0; } return hdr; } static void mif_hdr_destroy(mif_hdr_t *hdr) { JAS_LOGDEBUGF(10, "mif_hdr_destroy(%p)\n", hdr); int cmptno; if (hdr->cmpts) { for (cmptno = 0; cmptno < hdr->numcmpts; ++cmptno) { mif_cmpt_destroy(hdr->cmpts[cmptno]); } jas_free(hdr->cmpts); } jas_free(hdr); } static int mif_hdr_growcmpts(mif_hdr_t *hdr, int maxcmpts) { JAS_LOGDEBUGF(10, "mif_hdr_growcmpts(%p, %d)\n", hdr, maxcmpts); int cmptno; mif_cmpt_t **newcmpts; assert(maxcmpts >= hdr->numcmpts); newcmpts = (!hdr->cmpts) ? jas_alloc2(maxcmpts, sizeof(mif_cmpt_t *)) : jas_realloc2(hdr->cmpts, maxcmpts, sizeof(mif_cmpt_t *)); if (!newcmpts) { return -1; } hdr->maxcmpts = maxcmpts; hdr->cmpts = newcmpts; for (cmptno = hdr->numcmpts; cmptno < hdr->maxcmpts; ++cmptno) { hdr->cmpts[cmptno] = 0; } return 0; } static mif_hdr_t *mif_hdr_get(jas_stream_t *in) { jas_uchar magicbuf[MIF_MAGICLEN]; char buf[4096]; mif_hdr_t *hdr; bool done; jas_tvparser_t *tvp; int id; JAS_LOGDEBUGF(10, "mif_hdr_get(%p)\n", in); hdr = 0; tvp = 0; if (jas_stream_read(in, magicbuf, MIF_MAGICLEN) != MIF_MAGICLEN) { jas_logerrorf("cannot read MIF signature\n"); goto error; } if (magicbuf[0] != (MIF_MAGIC >> 24) || magicbuf[1] != ((MIF_MAGIC >> 16) & 0xff) || magicbuf[2] != ((MIF_MAGIC >> 8) & 0xff) || magicbuf[3] != (MIF_MAGIC & 0xff)) { jas_logerrorf("bad signature\n"); goto error; } if (!(hdr = mif_hdr_create(0))) { jas_logerrorf("cannot create MIF header\n"); goto error; } done = false; do { JAS_LOGDEBUGF(10, "top of loop\n"); if (!mif_getline(in, buf, sizeof(buf))) { jas_logerrorf("mif_hdr_get: mif_getline failed\n"); goto error; } if (buf[0] == '\0') { continue; } JAS_LOGDEBUGF(10, "header line: len=%d; %s\n", strlen(buf), buf); if (!(tvp = jas_tvparser_create(buf))) { jas_logerrorf("mif_hdr_get: jas_tvparser_create failed\n"); goto error; } JAS_LOGDEBUGF(10, "mif_hdr_get: invoking jas_tvparser_next\n"); if (jas_tvparser_next(tvp)) { jas_logerrorf("cannot get record type\n"); goto error; } JAS_LOGDEBUGF(10, "mif_hdr_get: looking up tag\n"); id = jas_taginfo_nonull(jas_taginfos_lookup(mif_tags2, jas_tvparser_gettag(tvp)))->id; jas_tvparser_destroy(tvp); tvp = 0; switch (id) { case MIF_CMPT: if (mif_process_cmpt(hdr, buf)) { jas_logerrorf("cannot get component information\n"); goto error; } break; case MIF_END: done = 1; break; default: jas_logerrorf("invalid header information: %s\n", buf); goto error; break; } } while (!done); JAS_LOGDEBUGF(10, "mif_hdr_get: returning (success)\n"); return hdr; error: JAS_LOGDEBUGF(10, "mif_hdr_get: returning (failure)\n"); if (hdr) { mif_hdr_destroy(hdr); } if (tvp) { jas_tvparser_destroy(tvp); } return 0; } static int mif_process_cmpt(mif_hdr_t *hdr, char *buf) { jas_tvparser_t *tvp; mif_cmpt_t *cmpt; int id; cmpt = 0; tvp = 0; JAS_LOGDEBUGF(10, "mif_process_cmpt(%p, %p)\n", hdr, buf); if (!(cmpt = mif_cmpt_create())) { jas_logerrorf("cannot create component\n"); goto error; } cmpt->tlx = 0; cmpt->tly = 0; cmpt->sampperx = 0; cmpt->samppery = 0; cmpt->width = 0; cmpt->height = 0; cmpt->prec = 0; cmpt->sgnd = -1; cmpt->data = 0; if (!(tvp = jas_tvparser_create(buf))) { jas_logerrorf("cannot create parser\n"); goto error; } // Skip the component keyword if ((id = jas_tvparser_next(tvp))) { // This should never happen. abort(); } // Process the tag-value pairs. while (!(id = jas_tvparser_next(tvp))) { switch (jas_taginfo_nonull(jas_taginfos_lookup(mif_tags, jas_tvparser_gettag(tvp)))->id) { case MIF_TLX: cmpt->tlx = atoi(jas_tvparser_getval(tvp)); break; case MIF_TLY: cmpt->tly = atoi(jas_tvparser_getval(tvp)); break; case MIF_WIDTH: cmpt->width = atoi(jas_tvparser_getval(tvp)); break; case MIF_HEIGHT: cmpt->height = atoi(jas_tvparser_getval(tvp)); break; case MIF_HSAMP: cmpt->sampperx = atoi(jas_tvparser_getval(tvp)); break; case MIF_VSAMP: cmpt->samppery = atoi(jas_tvparser_getval(tvp)); break; case MIF_PREC: cmpt->prec = atoi(jas_tvparser_getval(tvp)); break; case MIF_SGND: cmpt->sgnd = atoi(jas_tvparser_getval(tvp)); break; case MIF_DATA: if (!(cmpt->data = jas_strdup(jas_tvparser_getval(tvp)))) { goto error; } break; default: jas_logerrorf("invalid component information: %s\n", buf); goto error; break; } } if (!cmpt->sampperx || !cmpt->samppery) { goto error; } if (!cmpt->width || !cmpt->height || !cmpt->prec || cmpt->sgnd < 0) { goto error; } if (mif_hdr_addcmpt(hdr, hdr->numcmpts, cmpt)) { jas_logerrorf("cannot add component\n"); goto error; } jas_tvparser_destroy(tvp); JAS_LOGDEBUGF(10, "mif_process_cmpt returning (success)\n"); return 0; error: if (cmpt) { mif_cmpt_destroy(cmpt); } if (tvp) { jas_tvparser_destroy(tvp); } JAS_LOGDEBUGF(10, "mif_process_cmpt returning (error)\n"); return -1; } static int mif_hdr_put(mif_hdr_t *hdr, jas_stream_t *out) { int cmptno; mif_cmpt_t *cmpt; JAS_LOGDEBUGF(10, "mif_hdr_put(%p, %p)\n", hdr, out); /* Output signature. */ if (jas_stream_putc(out, (MIF_MAGIC >> 24) & 0xff) == EOF || jas_stream_putc(out, (MIF_MAGIC >> 16) & 0xff) == EOF || jas_stream_putc(out, (MIF_MAGIC >> 8) & 0xff) == EOF || jas_stream_putc(out, MIF_MAGIC & 0xff) == EOF) return -1; /* Output component information. */ for (cmptno = 0; cmptno < hdr->numcmpts; ++cmptno) { cmpt = hdr->cmpts[cmptno]; jas_stream_printf(out, "component tlx=%ld tly=%ld " "sampperx=%ld samppery=%ld width=%ld height=%ld prec=%d sgnd=%d", cmpt->tlx, cmpt->tly, cmpt->sampperx, cmpt->samppery, cmpt->width, cmpt->height, cmpt->prec, cmpt->sgnd); if (cmpt->data) { jas_stream_printf(out, " data=%s", cmpt->data); } jas_stream_printf(out, "\n"); } /* Output end of header indicator. */ jas_stream_printf(out, "end\n"); return 0; } static int mif_hdr_addcmpt(mif_hdr_t *hdr, int cmptno, mif_cmpt_t *cmpt) { assert(cmptno >= hdr->numcmpts); JAS_LOGDEBUGF(10, "mif_hdr_addcmpt(%p, %d, %p)\n", hdr, cmptno, cmpt); JAS_UNUSED(cmptno); if (hdr->numcmpts >= hdr->maxcmpts) { if (mif_hdr_growcmpts(hdr, hdr->numcmpts + 128)) { return -1; } } hdr->cmpts[hdr->numcmpts] = cmpt; ++hdr->numcmpts; return 0; } /******************************************************************************\ * Code for MIF component class. \******************************************************************************/ static mif_cmpt_t *mif_cmpt_create() { JAS_LOGDEBUGF(10, "mif_cmpt_create()\n"); mif_cmpt_t *cmpt; if (!(cmpt = jas_malloc(sizeof(mif_cmpt_t)))) { return 0; } memset(cmpt, 0, sizeof(mif_cmpt_t)); return cmpt; } static void mif_cmpt_destroy(mif_cmpt_t *cmpt) { JAS_LOGDEBUGF(10, "mif_cmpt_destroy(%p)\n", cmpt); if (cmpt->data) { jas_free(cmpt->data); } jas_free(cmpt); } /******************************************************************************\ * MIF parsing code. \******************************************************************************/ static char *mif_getline(jas_stream_t *stream, char *buf, int bufsize) { int c; char *bufptr; assert(bufsize > 0); JAS_LOGDEBUGF(10, "mif_getline(%p, %p, %d)\n", stream, buf, bufsize); bufptr = buf; while (bufsize > 1) { if ((c = mif_getc(stream)) == EOF) { break; } *bufptr++ = c; --bufsize; if (c == '\n') { break; } } *bufptr = '\0'; if (!(bufptr = strchr(buf, '\n'))) { return 0; } *bufptr = '\0'; return buf; } static int mif_getc(jas_stream_t *in) { int c; bool done; JAS_LOGDEBUGF(10, "mif_getc(%p)\n", in); done = false; do { switch (c = jas_stream_getc(in)) { case EOF: done = true; break; case '#': for (;;) { if ((c = jas_stream_getc(in)) == EOF) { done = true; break; } if (c == '\n') { done = true; break; } } break; case '\\': if (jas_stream_peekc(in) == '\n') { jas_stream_getc(in); } break; default: done = true; break; } } while (!done); JAS_LOGDEBUGF(10, "mif_getc(%p) returning %d\n", in, c); return c; } /******************************************************************************\ * Miscellaneous functions. \******************************************************************************/ static mif_hdr_t *mif_makehdrfromimage(jas_image_t *image) { mif_hdr_t *hdr; int cmptno; mif_cmpt_t *cmpt; JAS_LOGDEBUGF(10, "mif_makehdrfromimage(%p)\n", image); if (!(hdr = mif_hdr_create(jas_image_numcmpts(image)))) { return 0; } hdr->magic = MIF_MAGIC; hdr->numcmpts = jas_image_numcmpts(image); for (cmptno = 0; cmptno < hdr->numcmpts; ++cmptno) { if (!(hdr->cmpts[cmptno] = jas_malloc(sizeof(mif_cmpt_t)))) { goto error; } cmpt = hdr->cmpts[cmptno]; cmpt->tlx = jas_image_cmpttlx(image, cmptno); cmpt->tly = jas_image_cmpttly(image, cmptno); cmpt->width = jas_image_cmptwidth(image, cmptno); cmpt->height = jas_image_cmptheight(image, cmptno); cmpt->sampperx = jas_image_cmpthstep(image, cmptno); cmpt->samppery = jas_image_cmptvstep(image, cmptno); cmpt->prec = jas_image_cmptprec(image, cmptno); cmpt->sgnd = jas_image_cmptsgnd(image, cmptno); cmpt->data = 0; } return hdr; error: for (cmptno = 0; cmptno < hdr->numcmpts; ++cmptno) { if (hdr->cmpts[cmptno]) { jas_free(hdr->cmpts[cmptno]); } } if (hdr) { jas_free(hdr); } return 0; }
ab09c36a5d8c5c318c23b5a553f94d812fbf45f8
376e1818d427b5e4d32fa6dd6c7b71e9fd88afdb
/mail/cyrus-imapd24/patches/patch-imap_idlemsg.c
fa6e86ea2444b30c54764d70c51f5f4ff73a8655
[]
no_license
NetBSD/pkgsrc
a0732c023519650ef821ab89c23ab6ab59e25bdb
d042034ec4896cc5b47ed6f2e5b8802d9bc5c556
refs/heads/trunk
2023-09-01T07:40:12.138283
2023-09-01T05:25:19
2023-09-01T05:25:19
88,439,572
321
138
null
2023-07-12T22:34:14
2017-04-16T20:04:15
null
UTF-8
C
false
false
504
c
patch-imap_idlemsg.c
$NetBSD: patch-imap_idlemsg.c,v 1.1 2022/04/30 00:25:49 gutteridge Exp $ Fix SunOS build, where "sun" is defined, which clashes with variable naming. --- imap/idlemsg.c.orig 2017-08-18 00:29:14.000000000 +0000 +++ imap/idlemsg.c @@ -64,6 +64,11 @@ #include "idlemsg.h" #include "global.h" +/* SunOS defines the macro "sun", which clashes with variable naming here. */ +#ifdef sun +#undef sun +#endif + /* UNIX socket variables */ static int idle_sock = -1; static struct sockaddr_un idle_local;
d94096c02c3770103e6715ba868c0cfef4be2206
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
/stage0/stdlib/Lean/Server/Requests.c
02164e20b15139b7eac4a0ff49cd282c56163dea
[ "Apache-2.0", "LLVM-exception", "NCSA", "LGPL-3.0-only", "LicenseRef-scancode-inner-net-2.0", "BSD-3-Clause", "LGPL-2.0-or-later", "Spencer-94", "LGPL-2.1-or-later", "HPND", "LicenseRef-scancode-pcre", "ISC", "LGPL-2.1-only", "LicenseRef-scancode-other-permissive", "SunPro", "CMU-Mach" ]
permissive
leanprover/lean4
4bdf9790294964627eb9be79f5e8f6157780b4cc
f1f9dc0f2f531af3312398999d8b8303fa5f096b
refs/heads/master
2023-08-30T01:57:45.786981
2023-08-29T23:14:28
2023-08-29T23:14:28
129,571,436
2,827
311
Apache-2.0
2023-09-14T18:29:16
2018-04-15T02:49:20
Lean
UTF-8
C
false
false
126,007
c
Requests.c
// Lean compiler output // Module: Lean.Server.Requests // Imports: Init Lean.DeclarationRange Lean.Data.Json Lean.Data.Lsp Lean.Elab.Command Lean.Server.FileSource Lean.Server.FileWorker.Utils Lean.Server.Rpc.Basic #include <lean/lean.h> #if defined(__clang__) #pragma clang diagnostic ignored "-Wunused-parameter" #pragma clang diagnostic ignored "-Wunused-label" #elif defined(__GNUC__) && !defined(__CLANG__) #pragma GCC diagnostic ignored "-Wunused-parameter" #pragma GCC diagnostic ignored "-Wunused-label" #pragma GCC diagnostic ignored "-Wunused-but-set-variable" #endif #ifdef __cplusplus extern "C" { #endif LEAN_EXPORT lean_object* l_Lean_Server_RequestM_mapTask___rarg(lean_object*, lean_object*, lean_object*, lean_object*); static lean_object* l_Lean_Server_registerLspRequestHandler___lambda__3___closed__1; LEAN_EXPORT lean_object* l_Lean_PersistentHashMap_find_x3f___at_Lean_Server_lookupLspRequestHandler___spec__1(lean_object*, lean_object*); static lean_object* l_Lean_Server_parseRequestParams___rarg___closed__1; static lean_object* l_Lean_Server_RequestError_methodNotFound___closed__2; lean_object* l_EIO_toBaseIO___rarg(lean_object*, lean_object*); lean_object* l_Lean_Json_compress(lean_object*); size_t lean_usize_shift_right(size_t, size_t); LEAN_EXPORT lean_object* l_Lean_Server_RequestM_readDoc___at_Lean_Server_RequestM_withWaitFindSnapAtPos___spec__1___boxed(lean_object*, lean_object*); static lean_object* l_Lean_Server_chainLspRequestHandler___lambda__1___closed__1; LEAN_EXPORT lean_object* l_liftExcept___at_Lean_Server_registerLspRequestHandler___spec__1(lean_object*); LEAN_EXPORT lean_object* l_Lean_Server_RequestError_ofException(lean_object*, lean_object*); LEAN_EXPORT lean_object* l_liftExcept___at_Lean_Server_chainLspRequestHandler___spec__1___rarg(lean_object*, lean_object*, lean_object*); lean_object* l_String_decEq___boxed(lean_object*, lean_object*); uint8_t lean_usize_dec_le(size_t, size_t); lean_object* l_Lean_MessageData_toString(lean_object*, lean_object*); LEAN_EXPORT lean_object* l_Lean_Server_RequestM_runCommandElabM___rarg(lean_object*, lean_object*, lean_object*, lean_object*); size_t lean_uint64_to_usize(uint64_t); lean_object* lean_io_as_task(lean_object*, lean_object*, lean_object*); lean_object* lean_array_push(lean_object*, lean_object*); size_t lean_usize_mul(size_t, size_t); static lean_object* l_Lean_Server_chainLspRequestHandler___lambda__1___closed__2; LEAN_EXPORT lean_object* l_Lean_Server_RequestM_asTask(lean_object*); LEAN_EXPORT lean_object* l_Lean_PersistentHashMap_findAtAux___at_Lean_Server_lookupLspRequestHandler___spec__3(lean_object*, lean_object*, lean_object*, lean_object*, lean_object*); static lean_object* l_Lean_Server_RequestM_withWaitFindSnapAtPos___rarg___closed__2; lean_object* lean_array_fget(lean_object*, lean_object*); lean_object* lean_array_fset(lean_object*, lean_object*, lean_object*); LEAN_EXPORT lean_object* l_Lean_Server_RequestM_bindTask___rarg(lean_object*, lean_object*, lean_object*, lean_object*); LEAN_EXPORT lean_object* l_Lean_Server_RequestM_withWaitFindSnap___rarg(lean_object*, lean_object*, lean_object*, lean_object*, lean_object*, lean_object*, lean_object*); LEAN_EXPORT lean_object* l_Lean_Server_registerLspRequestHandler___lambda__1(lean_object*, lean_object*, lean_object*); LEAN_EXPORT lean_object* l_Lean_Server_RequestTask_pure___rarg(lean_object*); LEAN_EXPORT lean_object* l_Lean_Server_RequestM_withWaitFindSnapAtPos___rarg___lambda__2___boxed(lean_object*, lean_object*, lean_object*); LEAN_EXPORT lean_object* l_Lean_Server_RequestM_withWaitFindSnapAtPos___rarg___lambda__3(lean_object*, lean_object*); LEAN_EXPORT lean_object* l_Lean_Server_chainLspRequestHandler___lambda__3(lean_object*, lean_object*, lean_object*, lean_object*, lean_object*, lean_object*, lean_object*); LEAN_EXPORT lean_object* l_liftExcept___at_Lean_Server_RequestM_mapTask___spec__1(lean_object*); lean_object* l_IO_AsyncList_waitFind_x3f___rarg(lean_object*, lean_object*); uint64_t lean_string_hash(lean_object*); LEAN_EXPORT lean_object* l_Lean_Server_parseRequestParams___rarg(lean_object*, lean_object*); LEAN_EXPORT lean_object* l_Lean_Server_requestHandlers; static lean_object* l_Lean_Server_initFn____x40_Lean_Server_Requests___hyg_1811____closed__1; LEAN_EXPORT lean_object* l_Lean_Server_instMonadLiftIORequestM___rarg___boxed(lean_object*, lean_object*, lean_object*); uint8_t lean_string_dec_eq(lean_object*, lean_object*); LEAN_EXPORT lean_object* l_Lean_PersistentHashMap_contains___at_Lean_Server_registerLspRequestHandler___spec__6___boxed(lean_object*, lean_object*); lean_object* l_Lean_Exception_toMessageData(lean_object*); static lean_object* l_Lean_Server_registerLspRequestHandler___lambda__4___closed__1; static lean_object* l_Lean_Server_registerLspRequestHandler___lambda__4___closed__2; LEAN_EXPORT lean_object* l_Lean_Server_instMonadLiftIORequestM___rarg(lean_object*, lean_object*, lean_object*); lean_object* l_Lean_initializing(lean_object*); LEAN_EXPORT lean_object* l_Lean_PersistentHashMap_insertAux___at_Lean_Server_registerLspRequestHandler___spec__3(lean_object*, size_t, size_t, lean_object*, lean_object*); LEAN_EXPORT uint8_t l_Lean_Server_RequestM_withWaitFindSnapAtPos___rarg___lambda__1(lean_object*, lean_object*); LEAN_EXPORT lean_object* l_Lean_Server_RequestError_toLspResponseError___boxed(lean_object*, lean_object*); LEAN_EXPORT lean_object* l_Lean_Server_instMonadLiftEIOExceptionRequestM___rarg(lean_object*, lean_object*, lean_object*); LEAN_EXPORT lean_object* l_Lean_Server_instInhabitedRequestError; LEAN_EXPORT lean_object* l_Lean_Server_RequestM_bindWaitFindSnap___rarg(lean_object*, lean_object*, lean_object*, lean_object*, lean_object*, lean_object*, lean_object*); lean_object* lean_task_pure(lean_object*); lean_object* l_Lean_FileMap_lspPosToUtf8Pos(lean_object*, lean_object*); static lean_object* l_Lean_Server_registerLspRequestHandler___closed__1; lean_object* lean_st_ref_take(lean_object*, lean_object*); static lean_object* l_Lean_Server_handleLspRequest___closed__1; LEAN_EXPORT lean_object* l_Lean_Server_RequestM_runCommandElabM(lean_object*); LEAN_EXPORT lean_object* l_Lean_Server_registerLspRequestHandler___lambda__4(lean_object*, lean_object*, lean_object*, lean_object*, lean_object*, lean_object*, lean_object*); LEAN_EXPORT lean_object* l_Lean_Server_registerLspRequestHandler___lambda__3___boxed(lean_object*, lean_object*, lean_object*, lean_object*, lean_object*, lean_object*, lean_object*); LEAN_EXPORT lean_object* l_Lean_PersistentHashMap_insertAtCollisionNodeAux___at_Lean_Server_registerLspRequestHandler___spec__5(lean_object*, lean_object*, lean_object*, lean_object*); LEAN_EXPORT lean_object* l_Lean_PersistentHashMap_insertAux_traverse___at_Lean_Server_registerLspRequestHandler___spec__4___boxed(lean_object*, lean_object*, lean_object*, lean_object*, lean_object*, lean_object*); LEAN_EXPORT lean_object* l_Lean_Server_RequestM_withWaitFindSnapAtPos___rarg___lambda__3___boxed(lean_object*, lean_object*); LEAN_EXPORT lean_object* l_Lean_Server_RequestError_internalError(lean_object*); static size_t l_Lean_PersistentHashMap_insertAux___at_Lean_Server_registerLspRequestHandler___spec__3___closed__2; lean_object* l_Except_map___rarg(lean_object*, lean_object*); LEAN_EXPORT lean_object* l_Lean_Server_RequestError_fileChanged; lean_object* lean_st_ref_get(lean_object*, lean_object*); LEAN_EXPORT lean_object* l_liftExcept___at_Lean_Server_registerLspRequestHandler___spec__1___rarg(lean_object*, lean_object*, lean_object*); LEAN_EXPORT lean_object* l_Lean_Server_routeLspRequest(lean_object*, lean_object*, lean_object*); LEAN_EXPORT lean_object* l_Lean_Server_RequestError_methodNotFound___boxed(lean_object*); LEAN_EXPORT lean_object* l_Lean_Server_RequestM_bindWaitFindSnap(lean_object*); lean_object* lean_st_mk_ref(lean_object*, lean_object*); LEAN_EXPORT lean_object* l_Lean_Server_instMonadLiftEIOExceptionRequestM___rarg___boxed(lean_object*, lean_object*, lean_object*); static lean_object* l_Lean_Server_chainLspRequestHandler___lambda__3___closed__2; static lean_object* l_Lean_Server_parseRequestParams___rarg___closed__2; lean_object* lean_io_map_task(lean_object*, lean_object*, lean_object*, lean_object*); LEAN_EXPORT lean_object* l_Lean_PersistentHashMap_insert___at_Lean_Server_registerLspRequestHandler___spec__2(lean_object*, lean_object*, lean_object*); LEAN_EXPORT lean_object* l_Lean_PersistentHashMap_insertAux___at_Lean_Server_registerLspRequestHandler___spec__3___boxed(lean_object*, lean_object*, lean_object*, lean_object*, lean_object*); LEAN_EXPORT uint8_t l_Lean_PersistentHashMap_containsAtAux___at_Lean_Server_registerLspRequestHandler___spec__8(lean_object*, lean_object*, lean_object*, lean_object*, lean_object*); LEAN_EXPORT lean_object* l_Lean_Server_RequestM_asTask___rarg(lean_object*, lean_object*, lean_object*); static lean_object* l_Lean_Server_RequestM_withWaitFindSnapAtPos___rarg___closed__4; LEAN_EXPORT lean_object* l_Lean_Server_registerLspRequestHandler(lean_object*, lean_object*, lean_object*, lean_object*, lean_object*, lean_object*, lean_object*, lean_object*); LEAN_EXPORT lean_object* l_liftExcept___at_Lean_Server_RequestM_asTask___spec__1(lean_object*); static lean_object* l_Lean_Server_RequestM_withWaitFindSnapAtPos___rarg___closed__3; extern lean_object* l_Task_Priority_default; LEAN_EXPORT lean_object* l_Lean_Server_chainLspRequestHandler(lean_object*, lean_object*, lean_object*, lean_object*, lean_object*, lean_object*, lean_object*, lean_object*); LEAN_EXPORT lean_object* l_Lean_Server_RequestError_toLspResponseError(lean_object*, lean_object*); LEAN_EXPORT lean_object* l_Lean_Server_RequestM_runCoreM(lean_object*); LEAN_EXPORT lean_object* l_Lean_Server_RequestError_methodNotFound(lean_object*); LEAN_EXPORT lean_object* l_liftExcept___at_Lean_Server_RequestM_mapTask___spec__1___rarg(lean_object*); static lean_object* l_Lean_Server_RequestError_methodNotFound___closed__1; LEAN_EXPORT lean_object* l_Lean_Server_chainLspRequestHandler___lambda__1___boxed(lean_object*, lean_object*, lean_object*); static lean_object* l_Lean_Server_initFn____x40_Lean_Server_Requests___hyg_1811____closed__4; lean_object* l_Lean_Server_Snapshots_Snapshot_runCommandElabM___rarg(lean_object*, lean_object*, lean_object*, lean_object*); LEAN_EXPORT lean_object* l_Lean_Server_RequestM_bindTask___rarg___lambda__1(lean_object*, lean_object*, lean_object*, lean_object*); lean_object* lean_usize_to_nat(size_t); LEAN_EXPORT lean_object* l_Lean_PersistentHashMap_findAux___at_Lean_Server_lookupLspRequestHandler___spec__2___boxed(lean_object*, lean_object*, lean_object*); lean_object* l_Lean_Server_Snapshots_Snapshot_runTermElabM___rarg(lean_object*, lean_object*, lean_object*, lean_object*); LEAN_EXPORT lean_object* l_Lean_Server_RequestM_readDoc___at_Lean_Server_RequestM_withWaitFindSnapAtPos___spec__1(lean_object*, lean_object*); LEAN_EXPORT lean_object* l_Lean_Server_registerLspRequestHandler___lambda__2(lean_object*, lean_object*, lean_object*, lean_object*, lean_object*, lean_object*); LEAN_EXPORT lean_object* l_Lean_Server_instMonadLiftIORequestM(lean_object*); LEAN_EXPORT lean_object* l_Lean_Server_RequestM_bindTask(lean_object*, lean_object*); LEAN_EXPORT lean_object* l_Lean_Server_registerLspRequestHandler___lambda__3(lean_object*, lean_object*, lean_object*, lean_object*, lean_object*, lean_object*, lean_object*); LEAN_EXPORT lean_object* l_liftExcept___at_Lean_Server_chainLspRequestHandler___spec__1___rarg___boxed(lean_object*, lean_object*, lean_object*); LEAN_EXPORT lean_object* l_Lean_Server_RequestM_withWaitFindSnapAtPos___rarg(lean_object*, lean_object*, lean_object*, lean_object*); static lean_object* l_Lean_Server_instInhabitedRequestError___closed__2; static lean_object* l_Lean_Server_chainLspRequestHandler___lambda__3___closed__1; static lean_object* l_Lean_Server_RequestM_withWaitFindSnapAtPos___rarg___closed__5; LEAN_EXPORT lean_object* l_Lean_PersistentHashMap_findAtAux___at_Lean_Server_lookupLspRequestHandler___spec__3___boxed(lean_object*, lean_object*, lean_object*, lean_object*, lean_object*); uint8_t lean_nat_dec_lt(lean_object*, lean_object*); LEAN_EXPORT lean_object* l_Lean_Server_chainLspRequestHandler___lambda__2(lean_object*, lean_object*, lean_object*, lean_object*, lean_object*, lean_object*, lean_object*, lean_object*, lean_object*); LEAN_EXPORT lean_object* l_Lean_Server_RequestTask_pure(lean_object*); LEAN_EXPORT lean_object* l_Lean_Server_RequestM_readDoc(lean_object*); static lean_object* l_Lean_Server_handleLspRequest___closed__2; lean_object* l_Lean_PersistentHashMap_mkEmptyEntries(lean_object*, lean_object*); static lean_object* l_Lean_Server_initFn____x40_Lean_Server_Requests___hyg_1811____closed__5; LEAN_EXPORT lean_object* l_Lean_Server_RequestM_runTermElabM___rarg(lean_object*, lean_object*, lean_object*, lean_object*); LEAN_EXPORT lean_object* l_Lean_Server_RequestM_withWaitFindSnapAtPos___rarg___lambda__2(lean_object*, lean_object*, lean_object*); LEAN_EXPORT lean_object* l_Lean_Server_RequestM_waitFindSnapAux(lean_object*); LEAN_EXPORT lean_object* l_Lean_Server_RequestM_withWaitFindSnap(lean_object*); LEAN_EXPORT lean_object* l_Lean_Server_parseRequestParams(lean_object*); lean_object* lean_task_map(lean_object*, lean_object*, lean_object*); LEAN_EXPORT lean_object* l_Lean_PersistentHashMap_findAux___at_Lean_Server_lookupLspRequestHandler___spec__2(lean_object*, size_t, lean_object*); lean_object* lean_io_bind_task(lean_object*, lean_object*, lean_object*, lean_object*); LEAN_EXPORT lean_object* l_Lean_PersistentHashMap_containsAtAux___at_Lean_Server_registerLspRequestHandler___spec__8___boxed(lean_object*, lean_object*, lean_object*, lean_object*, lean_object*); LEAN_EXPORT lean_object* l_Lean_Server_RequestM_runTermElabM(lean_object*); LEAN_EXPORT lean_object* l_Lean_Server_RequestM_readDoc___rarg(lean_object*, lean_object*); lean_object* l_Lean_PersistentHashMap_mkCollisionNode___rarg(lean_object*, lean_object*, lean_object*, lean_object*); static size_t l_Lean_PersistentHashMap_insertAux___at_Lean_Server_registerLspRequestHandler___spec__3___closed__1; lean_object* l_Lean_PersistentHashMap_mkEmptyEntriesArray(lean_object*, lean_object*); LEAN_EXPORT lean_object* l_Lean_Server_chainLspRequestHandler___lambda__1(lean_object*, lean_object*, lean_object*); LEAN_EXPORT uint8_t l_Lean_PersistentHashMap_containsAux___at_Lean_Server_registerLspRequestHandler___spec__7(lean_object*, size_t, lean_object*); static lean_object* l_Lean_Server_RequestError_fileChanged___closed__1; size_t lean_usize_sub(size_t, size_t); LEAN_EXPORT lean_object* l_Lean_Server_RequestM_mapTask___rarg___lambda__1(lean_object*, lean_object*, lean_object*, lean_object*); LEAN_EXPORT lean_object* l_Lean_Server_chainLspRequestHandler___lambda__3___boxed(lean_object*, lean_object*, lean_object*, lean_object*, lean_object*, lean_object*, lean_object*); size_t lean_usize_add(size_t, size_t); LEAN_EXPORT lean_object* l_Lean_Server_lookupLspRequestHandler(lean_object*, lean_object*); LEAN_EXPORT lean_object* l_Lean_Server_RequestM_withWaitFindSnapAtPos___rarg___lambda__1___boxed(lean_object*, lean_object*); static lean_object* l_Lean_PersistentHashMap_insertAux___at_Lean_Server_registerLspRequestHandler___spec__3___closed__3; lean_object* lean_io_error_to_string(lean_object*); lean_object* lean_st_ref_set(lean_object*, lean_object*, lean_object*); static lean_object* l_Lean_Server_RequestError_fileChanged___closed__2; LEAN_EXPORT lean_object* l_Lean_Server_RequestM_readDoc___rarg___lambda__1(lean_object*, lean_object*); static lean_object* l_Lean_Server_instInhabitedRequestError___closed__1; size_t lean_usize_shift_left(size_t, size_t); LEAN_EXPORT lean_object* l_liftExcept___at_Lean_Server_registerLspRequestHandler___spec__1___rarg___boxed(lean_object*, lean_object*, lean_object*); lean_object* l_instBEq___rarg(lean_object*, lean_object*, lean_object*); LEAN_EXPORT lean_object* l_Lean_Server_RequestM_withWaitFindSnapAtPos(lean_object*); static lean_object* l_Lean_Server_initFn____x40_Lean_Server_Requests___hyg_1811____closed__2; lean_object* lean_string_append(lean_object*, lean_object*); static lean_object* l_Lean_Server_RequestM_withWaitFindSnapAtPos___rarg___closed__1; LEAN_EXPORT uint8_t l_Lean_PersistentHashMap_contains___at_Lean_Server_registerLspRequestHandler___spec__6(lean_object*, lean_object*); lean_object* lean_array_get_size(lean_object*); LEAN_EXPORT lean_object* l_Lean_PersistentHashMap_insertAux_traverse___at_Lean_Server_registerLspRequestHandler___spec__4(size_t, lean_object*, lean_object*, lean_object*, lean_object*, lean_object*); uint8_t lean_nat_dec_le(lean_object*, lean_object*); lean_object* l_Lean_Server_Snapshots_Snapshot_runCoreM___rarg(lean_object*, lean_object*, lean_object*, lean_object*); LEAN_EXPORT lean_object* l_liftExcept___at_Lean_Server_chainLspRequestHandler___spec__1(lean_object*); LEAN_EXPORT lean_object* l_Lean_Server_initFn____x40_Lean_Server_Requests___hyg_1811_(lean_object*); LEAN_EXPORT lean_object* l_Lean_Server_RequestM_runCoreM___rarg(lean_object*, lean_object*, lean_object*, lean_object*); LEAN_EXPORT lean_object* l_Lean_PersistentHashMap_containsAux___at_Lean_Server_registerLspRequestHandler___spec__7___boxed(lean_object*, lean_object*, lean_object*); LEAN_EXPORT lean_object* l_Lean_Server_RequestM_waitFindSnapAux___rarg(lean_object*, lean_object*, lean_object*, lean_object*, lean_object*, lean_object*); lean_object* lean_nat_add(lean_object*, lean_object*); lean_object* l_Lean_PersistentHashMap_getCollisionNodeSize___rarg(lean_object*); LEAN_EXPORT lean_object* l_Lean_Server_RequestError_ofIoError(lean_object*); LEAN_EXPORT lean_object* l_liftExcept___at_Lean_Server_RequestM_asTask___spec__1___rarg(lean_object*); LEAN_EXPORT lean_object* l_Lean_Server_RequestM_mapTask(lean_object*, lean_object*); static lean_object* l_Lean_Server_initFn____x40_Lean_Server_Requests___hyg_1811____closed__3; lean_object* lean_array_get(lean_object*, lean_object*, lean_object*); LEAN_EXPORT lean_object* l_Lean_Server_handleLspRequest(lean_object*, lean_object*, lean_object*, lean_object*); lean_object* l_Lean_Server_Snapshots_Snapshot_endPos(lean_object*); lean_object* l_Nat_repr(lean_object*); size_t lean_usize_land(size_t, size_t); LEAN_EXPORT lean_object* l_Lean_Server_instMonadLiftEIOExceptionRequestM(lean_object*); LEAN_EXPORT lean_object* l_Lean_Server_RequestError_invalidParams(lean_object*); static lean_object* _init_l_Lean_Server_instInhabitedRequestError___closed__1() { _start: { lean_object* x_1; x_1 = lean_mk_string_from_bytes("", 0); return x_1; } } static lean_object* _init_l_Lean_Server_instInhabitedRequestError___closed__2() { _start: { uint8_t x_1; lean_object* x_2; lean_object* x_3; x_1 = 0; x_2 = l_Lean_Server_instInhabitedRequestError___closed__1; x_3 = lean_alloc_ctor(0, 1, 1); lean_ctor_set(x_3, 0, x_2); lean_ctor_set_uint8(x_3, sizeof(void*)*1, x_1); return x_3; } } static lean_object* _init_l_Lean_Server_instInhabitedRequestError() { _start: { lean_object* x_1; x_1 = l_Lean_Server_instInhabitedRequestError___closed__2; return x_1; } } static lean_object* _init_l_Lean_Server_RequestError_fileChanged___closed__1() { _start: { lean_object* x_1; x_1 = lean_mk_string_from_bytes("File changed.", 13); return x_1; } } static lean_object* _init_l_Lean_Server_RequestError_fileChanged___closed__2() { _start: { uint8_t x_1; lean_object* x_2; lean_object* x_3; x_1 = 7; x_2 = l_Lean_Server_RequestError_fileChanged___closed__1; x_3 = lean_alloc_ctor(0, 1, 1); lean_ctor_set(x_3, 0, x_2); lean_ctor_set_uint8(x_3, sizeof(void*)*1, x_1); return x_3; } } static lean_object* _init_l_Lean_Server_RequestError_fileChanged() { _start: { lean_object* x_1; x_1 = l_Lean_Server_RequestError_fileChanged___closed__2; return x_1; } } static lean_object* _init_l_Lean_Server_RequestError_methodNotFound___closed__1() { _start: { lean_object* x_1; x_1 = lean_mk_string_from_bytes("No request handler found for '", 30); return x_1; } } static lean_object* _init_l_Lean_Server_RequestError_methodNotFound___closed__2() { _start: { lean_object* x_1; x_1 = lean_mk_string_from_bytes("'", 1); return x_1; } } LEAN_EXPORT lean_object* l_Lean_Server_RequestError_methodNotFound(lean_object* x_1) { _start: { lean_object* x_2; lean_object* x_3; lean_object* x_4; lean_object* x_5; uint8_t x_6; lean_object* x_7; x_2 = l_Lean_Server_RequestError_methodNotFound___closed__1; x_3 = lean_string_append(x_2, x_1); x_4 = l_Lean_Server_RequestError_methodNotFound___closed__2; x_5 = lean_string_append(x_3, x_4); x_6 = 2; x_7 = lean_alloc_ctor(0, 1, 1); lean_ctor_set(x_7, 0, x_5); lean_ctor_set_uint8(x_7, sizeof(void*)*1, x_6); return x_7; } } LEAN_EXPORT lean_object* l_Lean_Server_RequestError_methodNotFound___boxed(lean_object* x_1) { _start: { lean_object* x_2; x_2 = l_Lean_Server_RequestError_methodNotFound(x_1); lean_dec(x_1); return x_2; } } LEAN_EXPORT lean_object* l_Lean_Server_RequestError_invalidParams(lean_object* x_1) { _start: { uint8_t x_2; lean_object* x_3; x_2 = 3; x_3 = lean_alloc_ctor(0, 1, 1); lean_ctor_set(x_3, 0, x_1); lean_ctor_set_uint8(x_3, sizeof(void*)*1, x_2); return x_3; } } LEAN_EXPORT lean_object* l_Lean_Server_RequestError_internalError(lean_object* x_1) { _start: { uint8_t x_2; lean_object* x_3; x_2 = 4; x_3 = lean_alloc_ctor(0, 1, 1); lean_ctor_set(x_3, 0, x_1); lean_ctor_set_uint8(x_3, sizeof(void*)*1, x_2); return x_3; } } LEAN_EXPORT lean_object* l_Lean_Server_RequestError_ofException(lean_object* x_1, lean_object* x_2) { _start: { lean_object* x_3; lean_object* x_4; x_3 = l_Lean_Exception_toMessageData(x_1); x_4 = l_Lean_MessageData_toString(x_3, x_2); if (lean_obj_tag(x_4) == 0) { uint8_t x_5; x_5 = !lean_is_exclusive(x_4); if (x_5 == 0) { lean_object* x_6; uint8_t x_7; lean_object* x_8; x_6 = lean_ctor_get(x_4, 0); x_7 = 4; x_8 = lean_alloc_ctor(0, 1, 1); lean_ctor_set(x_8, 0, x_6); lean_ctor_set_uint8(x_8, sizeof(void*)*1, x_7); lean_ctor_set(x_4, 0, x_8); return x_4; } else { lean_object* x_9; lean_object* x_10; uint8_t x_11; lean_object* x_12; lean_object* x_13; x_9 = lean_ctor_get(x_4, 0); x_10 = lean_ctor_get(x_4, 1); lean_inc(x_10); lean_inc(x_9); lean_dec(x_4); x_11 = 4; x_12 = lean_alloc_ctor(0, 1, 1); lean_ctor_set(x_12, 0, x_9); lean_ctor_set_uint8(x_12, sizeof(void*)*1, x_11); x_13 = lean_alloc_ctor(0, 2, 0); lean_ctor_set(x_13, 0, x_12); lean_ctor_set(x_13, 1, x_10); return x_13; } } else { uint8_t x_14; x_14 = !lean_is_exclusive(x_4); if (x_14 == 0) { return x_4; } else { lean_object* x_15; lean_object* x_16; lean_object* x_17; x_15 = lean_ctor_get(x_4, 0); x_16 = lean_ctor_get(x_4, 1); lean_inc(x_16); lean_inc(x_15); lean_dec(x_4); x_17 = lean_alloc_ctor(1, 2, 0); lean_ctor_set(x_17, 0, x_15); lean_ctor_set(x_17, 1, x_16); return x_17; } } } } LEAN_EXPORT lean_object* l_Lean_Server_RequestError_ofIoError(lean_object* x_1) { _start: { lean_object* x_2; uint8_t x_3; lean_object* x_4; x_2 = lean_io_error_to_string(x_1); x_3 = 4; x_4 = lean_alloc_ctor(0, 1, 1); lean_ctor_set(x_4, 0, x_2); lean_ctor_set_uint8(x_4, sizeof(void*)*1, x_3); return x_4; } } LEAN_EXPORT lean_object* l_Lean_Server_RequestError_toLspResponseError(lean_object* x_1, lean_object* x_2) { _start: { uint8_t x_3; lean_object* x_4; lean_object* x_5; lean_object* x_6; x_3 = lean_ctor_get_uint8(x_2, sizeof(void*)*1); x_4 = lean_ctor_get(x_2, 0); x_5 = lean_box(0); lean_inc(x_4); x_6 = lean_alloc_ctor(0, 3, 1); lean_ctor_set(x_6, 0, x_1); lean_ctor_set(x_6, 1, x_4); lean_ctor_set(x_6, 2, x_5); lean_ctor_set_uint8(x_6, sizeof(void*)*3, x_3); return x_6; } } LEAN_EXPORT lean_object* l_Lean_Server_RequestError_toLspResponseError___boxed(lean_object* x_1, lean_object* x_2) { _start: { lean_object* x_3; x_3 = l_Lean_Server_RequestError_toLspResponseError(x_1, x_2); lean_dec(x_2); return x_3; } } static lean_object* _init_l_Lean_Server_parseRequestParams___rarg___closed__1() { _start: { lean_object* x_1; x_1 = lean_mk_string_from_bytes("Cannot parse request params: ", 29); return x_1; } } static lean_object* _init_l_Lean_Server_parseRequestParams___rarg___closed__2() { _start: { lean_object* x_1; x_1 = lean_mk_string_from_bytes("\n", 1); return x_1; } } LEAN_EXPORT lean_object* l_Lean_Server_parseRequestParams___rarg(lean_object* x_1, lean_object* x_2) { _start: { lean_object* x_3; lean_inc(x_2); x_3 = lean_apply_1(x_1, x_2); if (lean_obj_tag(x_3) == 0) { uint8_t x_4; x_4 = !lean_is_exclusive(x_3); if (x_4 == 0) { lean_object* x_5; lean_object* x_6; lean_object* x_7; lean_object* x_8; lean_object* x_9; lean_object* x_10; lean_object* x_11; lean_object* x_12; lean_object* x_13; uint8_t x_14; lean_object* x_15; x_5 = lean_ctor_get(x_3, 0); x_6 = l_Lean_Json_compress(x_2); x_7 = l_Lean_Server_parseRequestParams___rarg___closed__1; x_8 = lean_string_append(x_7, x_6); lean_dec(x_6); x_9 = l_Lean_Server_parseRequestParams___rarg___closed__2; x_10 = lean_string_append(x_8, x_9); x_11 = lean_string_append(x_10, x_5); lean_dec(x_5); x_12 = l_Lean_Server_instInhabitedRequestError___closed__1; x_13 = lean_string_append(x_11, x_12); x_14 = 0; x_15 = lean_alloc_ctor(0, 1, 1); lean_ctor_set(x_15, 0, x_13); lean_ctor_set_uint8(x_15, sizeof(void*)*1, x_14); lean_ctor_set(x_3, 0, x_15); return x_3; } else { lean_object* x_16; lean_object* x_17; lean_object* x_18; lean_object* x_19; lean_object* x_20; lean_object* x_21; lean_object* x_22; lean_object* x_23; lean_object* x_24; uint8_t x_25; lean_object* x_26; lean_object* x_27; x_16 = lean_ctor_get(x_3, 0); lean_inc(x_16); lean_dec(x_3); x_17 = l_Lean_Json_compress(x_2); x_18 = l_Lean_Server_parseRequestParams___rarg___closed__1; x_19 = lean_string_append(x_18, x_17); lean_dec(x_17); x_20 = l_Lean_Server_parseRequestParams___rarg___closed__2; x_21 = lean_string_append(x_19, x_20); x_22 = lean_string_append(x_21, x_16); lean_dec(x_16); x_23 = l_Lean_Server_instInhabitedRequestError___closed__1; x_24 = lean_string_append(x_22, x_23); x_25 = 0; x_26 = lean_alloc_ctor(0, 1, 1); lean_ctor_set(x_26, 0, x_24); lean_ctor_set_uint8(x_26, sizeof(void*)*1, x_25); x_27 = lean_alloc_ctor(0, 1, 0); lean_ctor_set(x_27, 0, x_26); return x_27; } } else { uint8_t x_28; lean_dec(x_2); x_28 = !lean_is_exclusive(x_3); if (x_28 == 0) { return x_3; } else { lean_object* x_29; lean_object* x_30; x_29 = lean_ctor_get(x_3, 0); lean_inc(x_29); lean_dec(x_3); x_30 = lean_alloc_ctor(1, 1, 0); lean_ctor_set(x_30, 0, x_29); return x_30; } } } } LEAN_EXPORT lean_object* l_Lean_Server_parseRequestParams(lean_object* x_1) { _start: { lean_object* x_2; x_2 = lean_alloc_closure((void*)(l_Lean_Server_parseRequestParams___rarg), 2, 0); return x_2; } } LEAN_EXPORT lean_object* l_Lean_Server_RequestTask_pure___rarg(lean_object* x_1) { _start: { lean_object* x_2; lean_object* x_3; x_2 = lean_alloc_ctor(1, 1, 0); lean_ctor_set(x_2, 0, x_1); x_3 = lean_task_pure(x_2); return x_3; } } LEAN_EXPORT lean_object* l_Lean_Server_RequestTask_pure(lean_object* x_1) { _start: { lean_object* x_2; x_2 = lean_alloc_closure((void*)(l_Lean_Server_RequestTask_pure___rarg), 1, 0); return x_2; } } LEAN_EXPORT lean_object* l_Lean_Server_instMonadLiftIORequestM___rarg(lean_object* x_1, lean_object* x_2, lean_object* x_3) { _start: { lean_object* x_4; x_4 = lean_apply_1(x_1, x_3); if (lean_obj_tag(x_4) == 0) { uint8_t x_5; x_5 = !lean_is_exclusive(x_4); if (x_5 == 0) { return x_4; } else { lean_object* x_6; lean_object* x_7; lean_object* x_8; x_6 = lean_ctor_get(x_4, 0); x_7 = lean_ctor_get(x_4, 1); lean_inc(x_7); lean_inc(x_6); lean_dec(x_4); x_8 = lean_alloc_ctor(0, 2, 0); lean_ctor_set(x_8, 0, x_6); lean_ctor_set(x_8, 1, x_7); return x_8; } } else { uint8_t x_9; x_9 = !lean_is_exclusive(x_4); if (x_9 == 0) { lean_object* x_10; lean_object* x_11; x_10 = lean_ctor_get(x_4, 0); x_11 = l_Lean_Server_RequestError_ofIoError(x_10); lean_ctor_set(x_4, 0, x_11); return x_4; } else { lean_object* x_12; lean_object* x_13; lean_object* x_14; lean_object* x_15; x_12 = lean_ctor_get(x_4, 0); x_13 = lean_ctor_get(x_4, 1); lean_inc(x_13); lean_inc(x_12); lean_dec(x_4); x_14 = l_Lean_Server_RequestError_ofIoError(x_12); x_15 = lean_alloc_ctor(1, 2, 0); lean_ctor_set(x_15, 0, x_14); lean_ctor_set(x_15, 1, x_13); return x_15; } } } } LEAN_EXPORT lean_object* l_Lean_Server_instMonadLiftIORequestM(lean_object* x_1) { _start: { lean_object* x_2; x_2 = lean_alloc_closure((void*)(l_Lean_Server_instMonadLiftIORequestM___rarg___boxed), 3, 0); return x_2; } } LEAN_EXPORT lean_object* l_Lean_Server_instMonadLiftIORequestM___rarg___boxed(lean_object* x_1, lean_object* x_2, lean_object* x_3) { _start: { lean_object* x_4; x_4 = l_Lean_Server_instMonadLiftIORequestM___rarg(x_1, x_2, x_3); lean_dec(x_2); return x_4; } } LEAN_EXPORT lean_object* l_Lean_Server_instMonadLiftEIOExceptionRequestM___rarg(lean_object* x_1, lean_object* x_2, lean_object* x_3) { _start: { lean_object* x_4; x_4 = lean_apply_1(x_1, x_3); if (lean_obj_tag(x_4) == 0) { uint8_t x_5; x_5 = !lean_is_exclusive(x_4); if (x_5 == 0) { return x_4; } else { lean_object* x_6; lean_object* x_7; lean_object* x_8; x_6 = lean_ctor_get(x_4, 0); x_7 = lean_ctor_get(x_4, 1); lean_inc(x_7); lean_inc(x_6); lean_dec(x_4); x_8 = lean_alloc_ctor(0, 2, 0); lean_ctor_set(x_8, 0, x_6); lean_ctor_set(x_8, 1, x_7); return x_8; } } else { lean_object* x_9; lean_object* x_10; lean_object* x_11; x_9 = lean_ctor_get(x_4, 0); lean_inc(x_9); x_10 = lean_ctor_get(x_4, 1); lean_inc(x_10); lean_dec(x_4); x_11 = l_Lean_Server_RequestError_ofException(x_9, x_10); if (lean_obj_tag(x_11) == 0) { uint8_t x_12; x_12 = !lean_is_exclusive(x_11); if (x_12 == 0) { lean_ctor_set_tag(x_11, 1); return x_11; } else { lean_object* x_13; lean_object* x_14; lean_object* x_15; x_13 = lean_ctor_get(x_11, 0); x_14 = lean_ctor_get(x_11, 1); lean_inc(x_14); lean_inc(x_13); lean_dec(x_11); x_15 = lean_alloc_ctor(1, 2, 0); lean_ctor_set(x_15, 0, x_13); lean_ctor_set(x_15, 1, x_14); return x_15; } } else { uint8_t x_16; x_16 = !lean_is_exclusive(x_11); if (x_16 == 0) { lean_object* x_17; lean_object* x_18; x_17 = lean_ctor_get(x_11, 0); x_18 = l_Lean_Server_RequestError_ofIoError(x_17); lean_ctor_set(x_11, 0, x_18); return x_11; } else { lean_object* x_19; lean_object* x_20; lean_object* x_21; lean_object* x_22; x_19 = lean_ctor_get(x_11, 0); x_20 = lean_ctor_get(x_11, 1); lean_inc(x_20); lean_inc(x_19); lean_dec(x_11); x_21 = l_Lean_Server_RequestError_ofIoError(x_19); x_22 = lean_alloc_ctor(1, 2, 0); lean_ctor_set(x_22, 0, x_21); lean_ctor_set(x_22, 1, x_20); return x_22; } } } } } LEAN_EXPORT lean_object* l_Lean_Server_instMonadLiftEIOExceptionRequestM(lean_object* x_1) { _start: { lean_object* x_2; x_2 = lean_alloc_closure((void*)(l_Lean_Server_instMonadLiftEIOExceptionRequestM___rarg___boxed), 3, 0); return x_2; } } LEAN_EXPORT lean_object* l_Lean_Server_instMonadLiftEIOExceptionRequestM___rarg___boxed(lean_object* x_1, lean_object* x_2, lean_object* x_3) { _start: { lean_object* x_4; x_4 = l_Lean_Server_instMonadLiftEIOExceptionRequestM___rarg(x_1, x_2, x_3); lean_dec(x_2); return x_4; } } LEAN_EXPORT lean_object* l_Lean_Server_RequestM_readDoc___rarg___lambda__1(lean_object* x_1, lean_object* x_2) { _start: { lean_object* x_3; lean_object* x_4; lean_object* x_5; lean_object* x_6; x_3 = lean_ctor_get(x_1, 0); lean_inc(x_3); lean_dec(x_1); x_4 = lean_ctor_get(x_3, 1); lean_inc(x_4); lean_dec(x_3); x_5 = lean_ctor_get(x_2, 2); lean_inc(x_5); lean_dec(x_2); x_6 = lean_apply_2(x_4, lean_box(0), x_5); return x_6; } } LEAN_EXPORT lean_object* l_Lean_Server_RequestM_readDoc___rarg(lean_object* x_1, lean_object* x_2) { _start: { lean_object* x_3; lean_object* x_4; lean_object* x_5; x_3 = lean_ctor_get(x_1, 1); lean_inc(x_3); x_4 = lean_alloc_closure((void*)(l_Lean_Server_RequestM_readDoc___rarg___lambda__1), 2, 1); lean_closure_set(x_4, 0, x_1); x_5 = lean_apply_4(x_3, lean_box(0), lean_box(0), x_2, x_4); return x_5; } } LEAN_EXPORT lean_object* l_Lean_Server_RequestM_readDoc(lean_object* x_1) { _start: { lean_object* x_2; x_2 = lean_alloc_closure((void*)(l_Lean_Server_RequestM_readDoc___rarg), 2, 0); return x_2; } } LEAN_EXPORT lean_object* l_liftExcept___at_Lean_Server_RequestM_asTask___spec__1___rarg(lean_object* x_1) { _start: { if (lean_obj_tag(x_1) == 0) { uint8_t x_2; x_2 = !lean_is_exclusive(x_1); if (x_2 == 0) { return x_1; } else { lean_object* x_3; lean_object* x_4; x_3 = lean_ctor_get(x_1, 0); lean_inc(x_3); lean_dec(x_1); x_4 = lean_alloc_ctor(0, 1, 0); lean_ctor_set(x_4, 0, x_3); return x_4; } } else { uint8_t x_5; x_5 = !lean_is_exclusive(x_1); if (x_5 == 0) { return x_1; } else { lean_object* x_6; lean_object* x_7; x_6 = lean_ctor_get(x_1, 0); lean_inc(x_6); lean_dec(x_1); x_7 = lean_alloc_ctor(1, 1, 0); lean_ctor_set(x_7, 0, x_6); return x_7; } } } } LEAN_EXPORT lean_object* l_liftExcept___at_Lean_Server_RequestM_asTask___spec__1(lean_object* x_1) { _start: { lean_object* x_2; x_2 = lean_alloc_closure((void*)(l_liftExcept___at_Lean_Server_RequestM_asTask___spec__1___rarg), 1, 0); return x_2; } } LEAN_EXPORT lean_object* l_Lean_Server_RequestM_asTask___rarg(lean_object* x_1, lean_object* x_2, lean_object* x_3) { _start: { lean_object* x_4; lean_object* x_5; lean_object* x_6; lean_object* x_7; uint8_t x_8; x_4 = lean_apply_1(x_1, x_2); x_5 = lean_alloc_closure((void*)(l_EIO_toBaseIO___rarg), 2, 1); lean_closure_set(x_5, 0, x_4); x_6 = l_Task_Priority_default; x_7 = lean_io_as_task(x_5, x_6, x_3); x_8 = !lean_is_exclusive(x_7); if (x_8 == 0) { lean_object* x_9; lean_object* x_10; lean_object* x_11; x_9 = lean_ctor_get(x_7, 0); x_10 = lean_alloc_closure((void*)(l_liftExcept___at_Lean_Server_RequestM_asTask___spec__1___rarg), 1, 0); x_11 = lean_task_map(x_10, x_9, x_6); lean_ctor_set(x_7, 0, x_11); return x_7; } else { lean_object* x_12; lean_object* x_13; lean_object* x_14; lean_object* x_15; lean_object* x_16; x_12 = lean_ctor_get(x_7, 0); x_13 = lean_ctor_get(x_7, 1); lean_inc(x_13); lean_inc(x_12); lean_dec(x_7); x_14 = lean_alloc_closure((void*)(l_liftExcept___at_Lean_Server_RequestM_asTask___spec__1___rarg), 1, 0); x_15 = lean_task_map(x_14, x_12, x_6); x_16 = lean_alloc_ctor(0, 2, 0); lean_ctor_set(x_16, 0, x_15); lean_ctor_set(x_16, 1, x_13); return x_16; } } } LEAN_EXPORT lean_object* l_Lean_Server_RequestM_asTask(lean_object* x_1) { _start: { lean_object* x_2; x_2 = lean_alloc_closure((void*)(l_Lean_Server_RequestM_asTask___rarg), 3, 0); return x_2; } } LEAN_EXPORT lean_object* l_liftExcept___at_Lean_Server_RequestM_mapTask___spec__1___rarg(lean_object* x_1) { _start: { if (lean_obj_tag(x_1) == 0) { uint8_t x_2; x_2 = !lean_is_exclusive(x_1); if (x_2 == 0) { return x_1; } else { lean_object* x_3; lean_object* x_4; x_3 = lean_ctor_get(x_1, 0); lean_inc(x_3); lean_dec(x_1); x_4 = lean_alloc_ctor(0, 1, 0); lean_ctor_set(x_4, 0, x_3); return x_4; } } else { uint8_t x_5; x_5 = !lean_is_exclusive(x_1); if (x_5 == 0) { return x_1; } else { lean_object* x_6; lean_object* x_7; x_6 = lean_ctor_get(x_1, 0); lean_inc(x_6); lean_dec(x_1); x_7 = lean_alloc_ctor(1, 1, 0); lean_ctor_set(x_7, 0, x_6); return x_7; } } } } LEAN_EXPORT lean_object* l_liftExcept___at_Lean_Server_RequestM_mapTask___spec__1(lean_object* x_1) { _start: { lean_object* x_2; x_2 = lean_alloc_closure((void*)(l_liftExcept___at_Lean_Server_RequestM_mapTask___spec__1___rarg), 1, 0); return x_2; } } LEAN_EXPORT lean_object* l_Lean_Server_RequestM_mapTask___rarg___lambda__1(lean_object* x_1, lean_object* x_2, lean_object* x_3, lean_object* x_4) { _start: { lean_object* x_5; x_5 = lean_apply_3(x_1, x_3, x_2, x_4); if (lean_obj_tag(x_5) == 0) { uint8_t x_6; x_6 = !lean_is_exclusive(x_5); if (x_6 == 0) { lean_object* x_7; lean_object* x_8; x_7 = lean_ctor_get(x_5, 0); x_8 = lean_alloc_ctor(1, 1, 0); lean_ctor_set(x_8, 0, x_7); lean_ctor_set(x_5, 0, x_8); return x_5; } else { lean_object* x_9; lean_object* x_10; lean_object* x_11; lean_object* x_12; x_9 = lean_ctor_get(x_5, 0); x_10 = lean_ctor_get(x_5, 1); lean_inc(x_10); lean_inc(x_9); lean_dec(x_5); x_11 = lean_alloc_ctor(1, 1, 0); lean_ctor_set(x_11, 0, x_9); x_12 = lean_alloc_ctor(0, 2, 0); lean_ctor_set(x_12, 0, x_11); lean_ctor_set(x_12, 1, x_10); return x_12; } } else { uint8_t x_13; x_13 = !lean_is_exclusive(x_5); if (x_13 == 0) { lean_object* x_14; lean_object* x_15; x_14 = lean_ctor_get(x_5, 0); x_15 = lean_alloc_ctor(0, 1, 0); lean_ctor_set(x_15, 0, x_14); lean_ctor_set_tag(x_5, 0); lean_ctor_set(x_5, 0, x_15); return x_5; } else { lean_object* x_16; lean_object* x_17; lean_object* x_18; lean_object* x_19; x_16 = lean_ctor_get(x_5, 0); x_17 = lean_ctor_get(x_5, 1); lean_inc(x_17); lean_inc(x_16); lean_dec(x_5); x_18 = lean_alloc_ctor(0, 1, 0); lean_ctor_set(x_18, 0, x_16); x_19 = lean_alloc_ctor(0, 2, 0); lean_ctor_set(x_19, 0, x_18); lean_ctor_set(x_19, 1, x_17); return x_19; } } } } LEAN_EXPORT lean_object* l_Lean_Server_RequestM_mapTask___rarg(lean_object* x_1, lean_object* x_2, lean_object* x_3, lean_object* x_4) { _start: { lean_object* x_5; lean_object* x_6; lean_object* x_7; uint8_t x_8; x_5 = lean_alloc_closure((void*)(l_Lean_Server_RequestM_mapTask___rarg___lambda__1), 4, 2); lean_closure_set(x_5, 0, x_2); lean_closure_set(x_5, 1, x_3); x_6 = l_Task_Priority_default; x_7 = lean_io_map_task(x_5, x_1, x_6, x_4); x_8 = !lean_is_exclusive(x_7); if (x_8 == 0) { lean_object* x_9; lean_object* x_10; lean_object* x_11; x_9 = lean_ctor_get(x_7, 0); x_10 = lean_alloc_closure((void*)(l_liftExcept___at_Lean_Server_RequestM_mapTask___spec__1___rarg), 1, 0); x_11 = lean_task_map(x_10, x_9, x_6); lean_ctor_set(x_7, 0, x_11); return x_7; } else { lean_object* x_12; lean_object* x_13; lean_object* x_14; lean_object* x_15; lean_object* x_16; x_12 = lean_ctor_get(x_7, 0); x_13 = lean_ctor_get(x_7, 1); lean_inc(x_13); lean_inc(x_12); lean_dec(x_7); x_14 = lean_alloc_closure((void*)(l_liftExcept___at_Lean_Server_RequestM_mapTask___spec__1___rarg), 1, 0); x_15 = lean_task_map(x_14, x_12, x_6); x_16 = lean_alloc_ctor(0, 2, 0); lean_ctor_set(x_16, 0, x_15); lean_ctor_set(x_16, 1, x_13); return x_16; } } } LEAN_EXPORT lean_object* l_Lean_Server_RequestM_mapTask(lean_object* x_1, lean_object* x_2) { _start: { lean_object* x_3; x_3 = lean_alloc_closure((void*)(l_Lean_Server_RequestM_mapTask___rarg), 4, 0); return x_3; } } LEAN_EXPORT lean_object* l_Lean_Server_RequestM_bindTask___rarg___lambda__1(lean_object* x_1, lean_object* x_2, lean_object* x_3, lean_object* x_4) { _start: { lean_object* x_5; x_5 = lean_apply_3(x_1, x_3, x_2, x_4); if (lean_obj_tag(x_5) == 0) { uint8_t x_6; x_6 = !lean_is_exclusive(x_5); if (x_6 == 0) { return x_5; } else { lean_object* x_7; lean_object* x_8; lean_object* x_9; x_7 = lean_ctor_get(x_5, 0); x_8 = lean_ctor_get(x_5, 1); lean_inc(x_8); lean_inc(x_7); lean_dec(x_5); x_9 = lean_alloc_ctor(0, 2, 0); lean_ctor_set(x_9, 0, x_7); lean_ctor_set(x_9, 1, x_8); return x_9; } } else { uint8_t x_10; x_10 = !lean_is_exclusive(x_5); if (x_10 == 0) { lean_object* x_11; lean_object* x_12; lean_object* x_13; x_11 = lean_ctor_get(x_5, 0); x_12 = lean_alloc_ctor(0, 1, 0); lean_ctor_set(x_12, 0, x_11); x_13 = lean_task_pure(x_12); lean_ctor_set_tag(x_5, 0); lean_ctor_set(x_5, 0, x_13); return x_5; } else { lean_object* x_14; lean_object* x_15; lean_object* x_16; lean_object* x_17; lean_object* x_18; x_14 = lean_ctor_get(x_5, 0); x_15 = lean_ctor_get(x_5, 1); lean_inc(x_15); lean_inc(x_14); lean_dec(x_5); x_16 = lean_alloc_ctor(0, 1, 0); lean_ctor_set(x_16, 0, x_14); x_17 = lean_task_pure(x_16); x_18 = lean_alloc_ctor(0, 2, 0); lean_ctor_set(x_18, 0, x_17); lean_ctor_set(x_18, 1, x_15); return x_18; } } } } LEAN_EXPORT lean_object* l_Lean_Server_RequestM_bindTask___rarg(lean_object* x_1, lean_object* x_2, lean_object* x_3, lean_object* x_4) { _start: { lean_object* x_5; lean_object* x_6; lean_object* x_7; uint8_t x_8; x_5 = lean_alloc_closure((void*)(l_Lean_Server_RequestM_bindTask___rarg___lambda__1), 4, 2); lean_closure_set(x_5, 0, x_2); lean_closure_set(x_5, 1, x_3); x_6 = l_Task_Priority_default; x_7 = lean_io_bind_task(x_1, x_5, x_6, x_4); x_8 = !lean_is_exclusive(x_7); if (x_8 == 0) { return x_7; } else { lean_object* x_9; lean_object* x_10; lean_object* x_11; x_9 = lean_ctor_get(x_7, 0); x_10 = lean_ctor_get(x_7, 1); lean_inc(x_10); lean_inc(x_9); lean_dec(x_7); x_11 = lean_alloc_ctor(0, 2, 0); lean_ctor_set(x_11, 0, x_9); lean_ctor_set(x_11, 1, x_10); return x_11; } } } LEAN_EXPORT lean_object* l_Lean_Server_RequestM_bindTask(lean_object* x_1, lean_object* x_2) { _start: { lean_object* x_3; x_3 = lean_alloc_closure((void*)(l_Lean_Server_RequestM_bindTask___rarg), 4, 0); return x_3; } } LEAN_EXPORT lean_object* l_Lean_Server_RequestM_waitFindSnapAux___rarg(lean_object* x_1, lean_object* x_2, lean_object* x_3, lean_object* x_4, lean_object* x_5, lean_object* x_6) { _start: { if (lean_obj_tag(x_4) == 0) { lean_object* x_7; lean_dec(x_3); lean_dec(x_1); x_7 = lean_ctor_get(x_4, 0); lean_inc(x_7); lean_dec(x_4); if (lean_obj_tag(x_7) == 0) { lean_object* x_8; x_8 = lean_apply_2(x_2, x_5, x_6); return x_8; } else { lean_object* x_9; lean_object* x_10; lean_object* x_11; lean_dec(x_5); lean_dec(x_2); x_9 = lean_ctor_get(x_7, 0); lean_inc(x_9); lean_dec(x_7); x_10 = l_Lean_Server_RequestError_ofIoError(x_9); x_11 = lean_alloc_ctor(1, 2, 0); lean_ctor_set(x_11, 0, x_10); lean_ctor_set(x_11, 1, x_6); return x_11; } } else { lean_object* x_12; lean_dec(x_2); x_12 = lean_ctor_get(x_4, 0); lean_inc(x_12); lean_dec(x_4); if (lean_obj_tag(x_12) == 0) { lean_object* x_13; lean_dec(x_3); x_13 = lean_apply_2(x_1, x_5, x_6); return x_13; } else { lean_object* x_14; lean_object* x_15; lean_dec(x_1); x_14 = lean_ctor_get(x_12, 0); lean_inc(x_14); lean_dec(x_12); x_15 = lean_apply_3(x_3, x_14, x_5, x_6); return x_15; } } } } LEAN_EXPORT lean_object* l_Lean_Server_RequestM_waitFindSnapAux(lean_object* x_1) { _start: { lean_object* x_2; x_2 = lean_alloc_closure((void*)(l_Lean_Server_RequestM_waitFindSnapAux___rarg), 6, 0); return x_2; } } LEAN_EXPORT lean_object* l_Lean_Server_RequestM_withWaitFindSnap___rarg(lean_object* x_1, lean_object* x_2, lean_object* x_3, lean_object* x_4, lean_object* x_5, lean_object* x_6, lean_object* x_7) { _start: { lean_object* x_8; lean_object* x_9; lean_object* x_10; lean_object* x_11; x_8 = lean_ctor_get(x_1, 1); lean_inc(x_8); lean_dec(x_1); x_9 = l_IO_AsyncList_waitFind_x3f___rarg(x_2, x_8); x_10 = lean_alloc_closure((void*)(l_Lean_Server_RequestM_waitFindSnapAux___rarg), 6, 3); lean_closure_set(x_10, 0, x_3); lean_closure_set(x_10, 1, x_5); lean_closure_set(x_10, 2, x_4); x_11 = l_Lean_Server_RequestM_mapTask___rarg(x_9, x_10, x_6, x_7); return x_11; } } LEAN_EXPORT lean_object* l_Lean_Server_RequestM_withWaitFindSnap(lean_object* x_1) { _start: { lean_object* x_2; x_2 = lean_alloc_closure((void*)(l_Lean_Server_RequestM_withWaitFindSnap___rarg), 7, 0); return x_2; } } LEAN_EXPORT lean_object* l_Lean_Server_RequestM_bindWaitFindSnap___rarg(lean_object* x_1, lean_object* x_2, lean_object* x_3, lean_object* x_4, lean_object* x_5, lean_object* x_6, lean_object* x_7) { _start: { lean_object* x_8; lean_object* x_9; lean_object* x_10; lean_object* x_11; x_8 = lean_ctor_get(x_1, 1); lean_inc(x_8); lean_dec(x_1); x_9 = l_IO_AsyncList_waitFind_x3f___rarg(x_2, x_8); x_10 = lean_alloc_closure((void*)(l_Lean_Server_RequestM_waitFindSnapAux___rarg), 6, 3); lean_closure_set(x_10, 0, x_3); lean_closure_set(x_10, 1, x_5); lean_closure_set(x_10, 2, x_4); x_11 = l_Lean_Server_RequestM_bindTask___rarg(x_9, x_10, x_6, x_7); return x_11; } } LEAN_EXPORT lean_object* l_Lean_Server_RequestM_bindWaitFindSnap(lean_object* x_1) { _start: { lean_object* x_2; x_2 = lean_alloc_closure((void*)(l_Lean_Server_RequestM_bindWaitFindSnap___rarg), 7, 0); return x_2; } } LEAN_EXPORT lean_object* l_Lean_Server_RequestM_readDoc___at_Lean_Server_RequestM_withWaitFindSnapAtPos___spec__1(lean_object* x_1, lean_object* x_2) { _start: { lean_object* x_3; lean_object* x_4; x_3 = lean_ctor_get(x_1, 2); lean_inc(x_3); x_4 = lean_alloc_ctor(0, 2, 0); lean_ctor_set(x_4, 0, x_3); lean_ctor_set(x_4, 1, x_2); return x_4; } } LEAN_EXPORT uint8_t l_Lean_Server_RequestM_withWaitFindSnapAtPos___rarg___lambda__1(lean_object* x_1, lean_object* x_2) { _start: { lean_object* x_3; uint8_t x_4; x_3 = l_Lean_Server_Snapshots_Snapshot_endPos(x_2); x_4 = lean_nat_dec_le(x_1, x_3); lean_dec(x_3); return x_4; } } LEAN_EXPORT lean_object* l_Lean_Server_RequestM_withWaitFindSnapAtPos___rarg___lambda__2(lean_object* x_1, lean_object* x_2, lean_object* x_3) { _start: { lean_object* x_4; x_4 = lean_alloc_ctor(1, 2, 0); lean_ctor_set(x_4, 0, x_1); lean_ctor_set(x_4, 1, x_3); return x_4; } } LEAN_EXPORT lean_object* l_Lean_Server_RequestM_withWaitFindSnapAtPos___rarg___lambda__3(lean_object* x_1, lean_object* x_2) { _start: { lean_object* x_3; lean_object* x_4; x_3 = l_Lean_Server_RequestError_fileChanged; x_4 = lean_alloc_ctor(1, 2, 0); lean_ctor_set(x_4, 0, x_3); lean_ctor_set(x_4, 1, x_2); return x_4; } } static lean_object* _init_l_Lean_Server_RequestM_withWaitFindSnapAtPos___rarg___closed__1() { _start: { lean_object* x_1; x_1 = lean_mk_string_from_bytes("(", 1); return x_1; } } static lean_object* _init_l_Lean_Server_RequestM_withWaitFindSnapAtPos___rarg___closed__2() { _start: { lean_object* x_1; x_1 = lean_mk_string_from_bytes(", ", 2); return x_1; } } static lean_object* _init_l_Lean_Server_RequestM_withWaitFindSnapAtPos___rarg___closed__3() { _start: { lean_object* x_1; x_1 = lean_mk_string_from_bytes(")", 1); return x_1; } } static lean_object* _init_l_Lean_Server_RequestM_withWaitFindSnapAtPos___rarg___closed__4() { _start: { lean_object* x_1; x_1 = lean_mk_string_from_bytes("no snapshot found at ", 21); return x_1; } } static lean_object* _init_l_Lean_Server_RequestM_withWaitFindSnapAtPos___rarg___closed__5() { _start: { lean_object* x_1; x_1 = lean_alloc_closure((void*)(l_Lean_Server_RequestM_withWaitFindSnapAtPos___rarg___lambda__3___boxed), 2, 0); return x_1; } } LEAN_EXPORT lean_object* l_Lean_Server_RequestM_withWaitFindSnapAtPos___rarg(lean_object* x_1, lean_object* x_2, lean_object* x_3, lean_object* x_4) { _start: { lean_object* x_5; lean_object* x_6; lean_object* x_7; lean_object* x_8; lean_object* x_9; lean_object* x_10; lean_object* x_11; lean_object* x_12; lean_object* x_13; lean_object* x_14; lean_object* x_15; lean_object* x_16; lean_object* x_17; lean_object* x_18; lean_object* x_19; lean_object* x_20; lean_object* x_21; lean_object* x_22; lean_object* x_23; lean_object* x_24; lean_object* x_25; lean_object* x_26; uint8_t x_27; lean_object* x_28; lean_object* x_29; lean_object* x_30; lean_object* x_31; x_5 = l_Lean_Server_RequestM_readDoc___at_Lean_Server_RequestM_withWaitFindSnapAtPos___spec__1(x_3, x_4); x_6 = lean_ctor_get(x_5, 0); lean_inc(x_6); x_7 = lean_ctor_get(x_5, 1); lean_inc(x_7); lean_dec(x_5); x_8 = lean_ctor_get(x_6, 0); lean_inc(x_8); x_9 = lean_ctor_get(x_8, 2); lean_inc(x_9); lean_dec(x_8); lean_inc(x_1); x_10 = l_Lean_FileMap_lspPosToUtf8Pos(x_9, x_1); lean_dec(x_9); x_11 = lean_alloc_closure((void*)(l_Lean_Server_RequestM_withWaitFindSnapAtPos___rarg___lambda__1___boxed), 2, 1); lean_closure_set(x_11, 0, x_10); x_12 = lean_ctor_get(x_1, 0); lean_inc(x_12); x_13 = l_Nat_repr(x_12); x_14 = l_Lean_Server_RequestM_withWaitFindSnapAtPos___rarg___closed__1; x_15 = lean_string_append(x_14, x_13); lean_dec(x_13); x_16 = l_Lean_Server_RequestM_withWaitFindSnapAtPos___rarg___closed__2; x_17 = lean_string_append(x_15, x_16); x_18 = lean_ctor_get(x_1, 1); lean_inc(x_18); lean_dec(x_1); x_19 = l_Nat_repr(x_18); x_20 = lean_string_append(x_17, x_19); lean_dec(x_19); x_21 = l_Lean_Server_RequestM_withWaitFindSnapAtPos___rarg___closed__3; x_22 = lean_string_append(x_20, x_21); x_23 = l_Lean_Server_RequestM_withWaitFindSnapAtPos___rarg___closed__4; x_24 = lean_string_append(x_23, x_22); lean_dec(x_22); x_25 = l_Lean_Server_instInhabitedRequestError___closed__1; x_26 = lean_string_append(x_24, x_25); x_27 = 3; x_28 = lean_alloc_ctor(0, 1, 1); lean_ctor_set(x_28, 0, x_26); lean_ctor_set_uint8(x_28, sizeof(void*)*1, x_27); x_29 = lean_alloc_closure((void*)(l_Lean_Server_RequestM_withWaitFindSnapAtPos___rarg___lambda__2___boxed), 3, 1); lean_closure_set(x_29, 0, x_28); x_30 = l_Lean_Server_RequestM_withWaitFindSnapAtPos___rarg___closed__5; x_31 = l_Lean_Server_RequestM_withWaitFindSnap___rarg(x_6, x_11, x_29, x_2, x_30, x_3, x_7); return x_31; } } LEAN_EXPORT lean_object* l_Lean_Server_RequestM_withWaitFindSnapAtPos(lean_object* x_1) { _start: { lean_object* x_2; x_2 = lean_alloc_closure((void*)(l_Lean_Server_RequestM_withWaitFindSnapAtPos___rarg), 4, 0); return x_2; } } LEAN_EXPORT lean_object* l_Lean_Server_RequestM_readDoc___at_Lean_Server_RequestM_withWaitFindSnapAtPos___spec__1___boxed(lean_object* x_1, lean_object* x_2) { _start: { lean_object* x_3; x_3 = l_Lean_Server_RequestM_readDoc___at_Lean_Server_RequestM_withWaitFindSnapAtPos___spec__1(x_1, x_2); lean_dec(x_1); return x_3; } } LEAN_EXPORT lean_object* l_Lean_Server_RequestM_withWaitFindSnapAtPos___rarg___lambda__1___boxed(lean_object* x_1, lean_object* x_2) { _start: { uint8_t x_3; lean_object* x_4; x_3 = l_Lean_Server_RequestM_withWaitFindSnapAtPos___rarg___lambda__1(x_1, x_2); lean_dec(x_2); lean_dec(x_1); x_4 = lean_box(x_3); return x_4; } } LEAN_EXPORT lean_object* l_Lean_Server_RequestM_withWaitFindSnapAtPos___rarg___lambda__2___boxed(lean_object* x_1, lean_object* x_2, lean_object* x_3) { _start: { lean_object* x_4; x_4 = l_Lean_Server_RequestM_withWaitFindSnapAtPos___rarg___lambda__2(x_1, x_2, x_3); lean_dec(x_2); return x_4; } } LEAN_EXPORT lean_object* l_Lean_Server_RequestM_withWaitFindSnapAtPos___rarg___lambda__3___boxed(lean_object* x_1, lean_object* x_2) { _start: { lean_object* x_3; x_3 = l_Lean_Server_RequestM_withWaitFindSnapAtPos___rarg___lambda__3(x_1, x_2); lean_dec(x_1); return x_3; } } LEAN_EXPORT lean_object* l_Lean_Server_RequestM_runCommandElabM___rarg(lean_object* x_1, lean_object* x_2, lean_object* x_3, lean_object* x_4) { _start: { lean_object* x_5; lean_object* x_6; lean_object* x_7; lean_object* x_8; x_5 = lean_ctor_get(x_3, 2); lean_inc(x_5); x_6 = lean_ctor_get(x_5, 0); lean_inc(x_6); lean_dec(x_5); x_7 = lean_apply_1(x_2, x_3); x_8 = l_Lean_Server_Snapshots_Snapshot_runCommandElabM___rarg(x_1, x_6, x_7, x_4); lean_dec(x_6); if (lean_obj_tag(x_8) == 0) { lean_object* x_9; x_9 = lean_ctor_get(x_8, 0); lean_inc(x_9); if (lean_obj_tag(x_9) == 0) { uint8_t x_10; x_10 = !lean_is_exclusive(x_8); if (x_10 == 0) { lean_object* x_11; lean_object* x_12; x_11 = lean_ctor_get(x_8, 0); lean_dec(x_11); x_12 = lean_ctor_get(x_9, 0); lean_inc(x_12); lean_dec(x_9); lean_ctor_set_tag(x_8, 1); lean_ctor_set(x_8, 0, x_12); return x_8; } else { lean_object* x_13; lean_object* x_14; lean_object* x_15; x_13 = lean_ctor_get(x_8, 1); lean_inc(x_13); lean_dec(x_8); x_14 = lean_ctor_get(x_9, 0); lean_inc(x_14); lean_dec(x_9); x_15 = lean_alloc_ctor(1, 2, 0); lean_ctor_set(x_15, 0, x_14); lean_ctor_set(x_15, 1, x_13); return x_15; } } else { uint8_t x_16; x_16 = !lean_is_exclusive(x_8); if (x_16 == 0) { lean_object* x_17; lean_object* x_18; x_17 = lean_ctor_get(x_8, 0); lean_dec(x_17); x_18 = lean_ctor_get(x_9, 0); lean_inc(x_18); lean_dec(x_9); lean_ctor_set(x_8, 0, x_18); return x_8; } else { lean_object* x_19; lean_object* x_20; lean_object* x_21; x_19 = lean_ctor_get(x_8, 1); lean_inc(x_19); lean_dec(x_8); x_20 = lean_ctor_get(x_9, 0); lean_inc(x_20); lean_dec(x_9); x_21 = lean_alloc_ctor(0, 2, 0); lean_ctor_set(x_21, 0, x_20); lean_ctor_set(x_21, 1, x_19); return x_21; } } } else { lean_object* x_22; lean_object* x_23; lean_object* x_24; x_22 = lean_ctor_get(x_8, 0); lean_inc(x_22); x_23 = lean_ctor_get(x_8, 1); lean_inc(x_23); lean_dec(x_8); x_24 = l_Lean_Server_RequestError_ofException(x_22, x_23); if (lean_obj_tag(x_24) == 0) { uint8_t x_25; x_25 = !lean_is_exclusive(x_24); if (x_25 == 0) { lean_ctor_set_tag(x_24, 1); return x_24; } else { lean_object* x_26; lean_object* x_27; lean_object* x_28; x_26 = lean_ctor_get(x_24, 0); x_27 = lean_ctor_get(x_24, 1); lean_inc(x_27); lean_inc(x_26); lean_dec(x_24); x_28 = lean_alloc_ctor(1, 2, 0); lean_ctor_set(x_28, 0, x_26); lean_ctor_set(x_28, 1, x_27); return x_28; } } else { uint8_t x_29; x_29 = !lean_is_exclusive(x_24); if (x_29 == 0) { lean_object* x_30; lean_object* x_31; x_30 = lean_ctor_get(x_24, 0); x_31 = l_Lean_Server_RequestError_ofIoError(x_30); lean_ctor_set(x_24, 0, x_31); return x_24; } else { lean_object* x_32; lean_object* x_33; lean_object* x_34; lean_object* x_35; x_32 = lean_ctor_get(x_24, 0); x_33 = lean_ctor_get(x_24, 1); lean_inc(x_33); lean_inc(x_32); lean_dec(x_24); x_34 = l_Lean_Server_RequestError_ofIoError(x_32); x_35 = lean_alloc_ctor(1, 2, 0); lean_ctor_set(x_35, 0, x_34); lean_ctor_set(x_35, 1, x_33); return x_35; } } } } } LEAN_EXPORT lean_object* l_Lean_Server_RequestM_runCommandElabM(lean_object* x_1) { _start: { lean_object* x_2; x_2 = lean_alloc_closure((void*)(l_Lean_Server_RequestM_runCommandElabM___rarg), 4, 0); return x_2; } } LEAN_EXPORT lean_object* l_Lean_Server_RequestM_runCoreM___rarg(lean_object* x_1, lean_object* x_2, lean_object* x_3, lean_object* x_4) { _start: { lean_object* x_5; lean_object* x_6; lean_object* x_7; lean_object* x_8; x_5 = lean_ctor_get(x_3, 2); lean_inc(x_5); x_6 = lean_ctor_get(x_5, 0); lean_inc(x_6); lean_dec(x_5); x_7 = lean_apply_1(x_2, x_3); x_8 = l_Lean_Server_Snapshots_Snapshot_runCoreM___rarg(x_1, x_6, x_7, x_4); lean_dec(x_6); if (lean_obj_tag(x_8) == 0) { lean_object* x_9; x_9 = lean_ctor_get(x_8, 0); lean_inc(x_9); if (lean_obj_tag(x_9) == 0) { uint8_t x_10; x_10 = !lean_is_exclusive(x_8); if (x_10 == 0) { lean_object* x_11; lean_object* x_12; x_11 = lean_ctor_get(x_8, 0); lean_dec(x_11); x_12 = lean_ctor_get(x_9, 0); lean_inc(x_12); lean_dec(x_9); lean_ctor_set_tag(x_8, 1); lean_ctor_set(x_8, 0, x_12); return x_8; } else { lean_object* x_13; lean_object* x_14; lean_object* x_15; x_13 = lean_ctor_get(x_8, 1); lean_inc(x_13); lean_dec(x_8); x_14 = lean_ctor_get(x_9, 0); lean_inc(x_14); lean_dec(x_9); x_15 = lean_alloc_ctor(1, 2, 0); lean_ctor_set(x_15, 0, x_14); lean_ctor_set(x_15, 1, x_13); return x_15; } } else { uint8_t x_16; x_16 = !lean_is_exclusive(x_8); if (x_16 == 0) { lean_object* x_17; lean_object* x_18; x_17 = lean_ctor_get(x_8, 0); lean_dec(x_17); x_18 = lean_ctor_get(x_9, 0); lean_inc(x_18); lean_dec(x_9); lean_ctor_set(x_8, 0, x_18); return x_8; } else { lean_object* x_19; lean_object* x_20; lean_object* x_21; x_19 = lean_ctor_get(x_8, 1); lean_inc(x_19); lean_dec(x_8); x_20 = lean_ctor_get(x_9, 0); lean_inc(x_20); lean_dec(x_9); x_21 = lean_alloc_ctor(0, 2, 0); lean_ctor_set(x_21, 0, x_20); lean_ctor_set(x_21, 1, x_19); return x_21; } } } else { lean_object* x_22; lean_object* x_23; lean_object* x_24; x_22 = lean_ctor_get(x_8, 0); lean_inc(x_22); x_23 = lean_ctor_get(x_8, 1); lean_inc(x_23); lean_dec(x_8); x_24 = l_Lean_Server_RequestError_ofException(x_22, x_23); if (lean_obj_tag(x_24) == 0) { uint8_t x_25; x_25 = !lean_is_exclusive(x_24); if (x_25 == 0) { lean_ctor_set_tag(x_24, 1); return x_24; } else { lean_object* x_26; lean_object* x_27; lean_object* x_28; x_26 = lean_ctor_get(x_24, 0); x_27 = lean_ctor_get(x_24, 1); lean_inc(x_27); lean_inc(x_26); lean_dec(x_24); x_28 = lean_alloc_ctor(1, 2, 0); lean_ctor_set(x_28, 0, x_26); lean_ctor_set(x_28, 1, x_27); return x_28; } } else { uint8_t x_29; x_29 = !lean_is_exclusive(x_24); if (x_29 == 0) { lean_object* x_30; lean_object* x_31; x_30 = lean_ctor_get(x_24, 0); x_31 = l_Lean_Server_RequestError_ofIoError(x_30); lean_ctor_set(x_24, 0, x_31); return x_24; } else { lean_object* x_32; lean_object* x_33; lean_object* x_34; lean_object* x_35; x_32 = lean_ctor_get(x_24, 0); x_33 = lean_ctor_get(x_24, 1); lean_inc(x_33); lean_inc(x_32); lean_dec(x_24); x_34 = l_Lean_Server_RequestError_ofIoError(x_32); x_35 = lean_alloc_ctor(1, 2, 0); lean_ctor_set(x_35, 0, x_34); lean_ctor_set(x_35, 1, x_33); return x_35; } } } } } LEAN_EXPORT lean_object* l_Lean_Server_RequestM_runCoreM(lean_object* x_1) { _start: { lean_object* x_2; x_2 = lean_alloc_closure((void*)(l_Lean_Server_RequestM_runCoreM___rarg), 4, 0); return x_2; } } LEAN_EXPORT lean_object* l_Lean_Server_RequestM_runTermElabM___rarg(lean_object* x_1, lean_object* x_2, lean_object* x_3, lean_object* x_4) { _start: { lean_object* x_5; lean_object* x_6; lean_object* x_7; lean_object* x_8; x_5 = lean_ctor_get(x_3, 2); lean_inc(x_5); x_6 = lean_ctor_get(x_5, 0); lean_inc(x_6); lean_dec(x_5); x_7 = lean_apply_1(x_2, x_3); x_8 = l_Lean_Server_Snapshots_Snapshot_runTermElabM___rarg(x_1, x_6, x_7, x_4); lean_dec(x_6); if (lean_obj_tag(x_8) == 0) { lean_object* x_9; x_9 = lean_ctor_get(x_8, 0); lean_inc(x_9); if (lean_obj_tag(x_9) == 0) { uint8_t x_10; x_10 = !lean_is_exclusive(x_8); if (x_10 == 0) { lean_object* x_11; lean_object* x_12; x_11 = lean_ctor_get(x_8, 0); lean_dec(x_11); x_12 = lean_ctor_get(x_9, 0); lean_inc(x_12); lean_dec(x_9); lean_ctor_set_tag(x_8, 1); lean_ctor_set(x_8, 0, x_12); return x_8; } else { lean_object* x_13; lean_object* x_14; lean_object* x_15; x_13 = lean_ctor_get(x_8, 1); lean_inc(x_13); lean_dec(x_8); x_14 = lean_ctor_get(x_9, 0); lean_inc(x_14); lean_dec(x_9); x_15 = lean_alloc_ctor(1, 2, 0); lean_ctor_set(x_15, 0, x_14); lean_ctor_set(x_15, 1, x_13); return x_15; } } else { uint8_t x_16; x_16 = !lean_is_exclusive(x_8); if (x_16 == 0) { lean_object* x_17; lean_object* x_18; x_17 = lean_ctor_get(x_8, 0); lean_dec(x_17); x_18 = lean_ctor_get(x_9, 0); lean_inc(x_18); lean_dec(x_9); lean_ctor_set(x_8, 0, x_18); return x_8; } else { lean_object* x_19; lean_object* x_20; lean_object* x_21; x_19 = lean_ctor_get(x_8, 1); lean_inc(x_19); lean_dec(x_8); x_20 = lean_ctor_get(x_9, 0); lean_inc(x_20); lean_dec(x_9); x_21 = lean_alloc_ctor(0, 2, 0); lean_ctor_set(x_21, 0, x_20); lean_ctor_set(x_21, 1, x_19); return x_21; } } } else { lean_object* x_22; lean_object* x_23; lean_object* x_24; x_22 = lean_ctor_get(x_8, 0); lean_inc(x_22); x_23 = lean_ctor_get(x_8, 1); lean_inc(x_23); lean_dec(x_8); x_24 = l_Lean_Server_RequestError_ofException(x_22, x_23); if (lean_obj_tag(x_24) == 0) { uint8_t x_25; x_25 = !lean_is_exclusive(x_24); if (x_25 == 0) { lean_ctor_set_tag(x_24, 1); return x_24; } else { lean_object* x_26; lean_object* x_27; lean_object* x_28; x_26 = lean_ctor_get(x_24, 0); x_27 = lean_ctor_get(x_24, 1); lean_inc(x_27); lean_inc(x_26); lean_dec(x_24); x_28 = lean_alloc_ctor(1, 2, 0); lean_ctor_set(x_28, 0, x_26); lean_ctor_set(x_28, 1, x_27); return x_28; } } else { uint8_t x_29; x_29 = !lean_is_exclusive(x_24); if (x_29 == 0) { lean_object* x_30; lean_object* x_31; x_30 = lean_ctor_get(x_24, 0); x_31 = l_Lean_Server_RequestError_ofIoError(x_30); lean_ctor_set(x_24, 0, x_31); return x_24; } else { lean_object* x_32; lean_object* x_33; lean_object* x_34; lean_object* x_35; x_32 = lean_ctor_get(x_24, 0); x_33 = lean_ctor_get(x_24, 1); lean_inc(x_33); lean_inc(x_32); lean_dec(x_24); x_34 = l_Lean_Server_RequestError_ofIoError(x_32); x_35 = lean_alloc_ctor(1, 2, 0); lean_ctor_set(x_35, 0, x_34); lean_ctor_set(x_35, 1, x_33); return x_35; } } } } } LEAN_EXPORT lean_object* l_Lean_Server_RequestM_runTermElabM(lean_object* x_1) { _start: { lean_object* x_2; x_2 = lean_alloc_closure((void*)(l_Lean_Server_RequestM_runTermElabM___rarg), 4, 0); return x_2; } } static lean_object* _init_l_Lean_Server_initFn____x40_Lean_Server_Requests___hyg_1811____closed__1() { _start: { lean_object* x_1; x_1 = lean_alloc_closure((void*)(l_String_decEq___boxed), 2, 0); return x_1; } } static lean_object* _init_l_Lean_Server_initFn____x40_Lean_Server_Requests___hyg_1811____closed__2() { _start: { lean_object* x_1; lean_object* x_2; x_1 = l_Lean_Server_initFn____x40_Lean_Server_Requests___hyg_1811____closed__1; x_2 = lean_alloc_closure((void*)(l_instBEq___rarg), 3, 1); lean_closure_set(x_2, 0, x_1); return x_2; } } static lean_object* _init_l_Lean_Server_initFn____x40_Lean_Server_Requests___hyg_1811____closed__3() { _start: { lean_object* x_1; x_1 = l_Lean_PersistentHashMap_mkEmptyEntriesArray(lean_box(0), lean_box(0)); return x_1; } } static lean_object* _init_l_Lean_Server_initFn____x40_Lean_Server_Requests___hyg_1811____closed__4() { _start: { lean_object* x_1; lean_object* x_2; x_1 = l_Lean_Server_initFn____x40_Lean_Server_Requests___hyg_1811____closed__3; x_2 = lean_alloc_ctor(0, 1, 0); lean_ctor_set(x_2, 0, x_1); return x_2; } } static lean_object* _init_l_Lean_Server_initFn____x40_Lean_Server_Requests___hyg_1811____closed__5() { _start: { lean_object* x_1; lean_object* x_2; lean_object* x_3; x_1 = l_Lean_Server_initFn____x40_Lean_Server_Requests___hyg_1811____closed__4; x_2 = lean_unsigned_to_nat(0u); x_3 = lean_alloc_ctor(0, 2, 0); lean_ctor_set(x_3, 0, x_1); lean_ctor_set(x_3, 1, x_2); return x_3; } } LEAN_EXPORT lean_object* l_Lean_Server_initFn____x40_Lean_Server_Requests___hyg_1811_(lean_object* x_1) { _start: { lean_object* x_2; lean_object* x_3; uint8_t x_4; x_2 = l_Lean_Server_initFn____x40_Lean_Server_Requests___hyg_1811____closed__5; x_3 = lean_st_mk_ref(x_2, x_1); x_4 = !lean_is_exclusive(x_3); if (x_4 == 0) { return x_3; } else { lean_object* x_5; lean_object* x_6; lean_object* x_7; x_5 = lean_ctor_get(x_3, 0); x_6 = lean_ctor_get(x_3, 1); lean_inc(x_6); lean_inc(x_5); lean_dec(x_3); x_7 = lean_alloc_ctor(0, 2, 0); lean_ctor_set(x_7, 0, x_5); lean_ctor_set(x_7, 1, x_6); return x_7; } } } LEAN_EXPORT lean_object* l_liftExcept___at_Lean_Server_registerLspRequestHandler___spec__1___rarg(lean_object* x_1, lean_object* x_2, lean_object* x_3) { _start: { if (lean_obj_tag(x_1) == 0) { lean_object* x_4; lean_object* x_5; x_4 = lean_ctor_get(x_1, 0); lean_inc(x_4); x_5 = lean_alloc_ctor(1, 2, 0); lean_ctor_set(x_5, 0, x_4); lean_ctor_set(x_5, 1, x_3); return x_5; } else { lean_object* x_6; lean_object* x_7; x_6 = lean_ctor_get(x_1, 0); lean_inc(x_6); x_7 = lean_alloc_ctor(0, 2, 0); lean_ctor_set(x_7, 0, x_6); lean_ctor_set(x_7, 1, x_3); return x_7; } } } LEAN_EXPORT lean_object* l_liftExcept___at_Lean_Server_registerLspRequestHandler___spec__1(lean_object* x_1) { _start: { lean_object* x_2; x_2 = lean_alloc_closure((void*)(l_liftExcept___at_Lean_Server_registerLspRequestHandler___spec__1___rarg___boxed), 3, 0); return x_2; } } LEAN_EXPORT lean_object* l_Lean_PersistentHashMap_insertAux_traverse___at_Lean_Server_registerLspRequestHandler___spec__4(size_t x_1, lean_object* x_2, lean_object* x_3, lean_object* x_4, lean_object* x_5, lean_object* x_6) { _start: { lean_object* x_7; uint8_t x_8; x_7 = lean_array_get_size(x_2); x_8 = lean_nat_dec_lt(x_5, x_7); lean_dec(x_7); if (x_8 == 0) { lean_dec(x_5); return x_6; } else { lean_object* x_9; lean_object* x_10; uint64_t x_11; size_t x_12; size_t x_13; size_t x_14; size_t x_15; size_t x_16; size_t x_17; lean_object* x_18; lean_object* x_19; lean_object* x_20; x_9 = lean_array_fget(x_2, x_5); x_10 = lean_array_fget(x_3, x_5); x_11 = lean_string_hash(x_9); x_12 = lean_uint64_to_usize(x_11); x_13 = 1; x_14 = lean_usize_sub(x_1, x_13); x_15 = 5; x_16 = lean_usize_mul(x_15, x_14); x_17 = lean_usize_shift_right(x_12, x_16); x_18 = lean_unsigned_to_nat(1u); x_19 = lean_nat_add(x_5, x_18); lean_dec(x_5); x_20 = l_Lean_PersistentHashMap_insertAux___at_Lean_Server_registerLspRequestHandler___spec__3(x_6, x_17, x_1, x_9, x_10); x_4 = lean_box(0); x_5 = x_19; x_6 = x_20; goto _start; } } } LEAN_EXPORT lean_object* l_Lean_PersistentHashMap_insertAtCollisionNodeAux___at_Lean_Server_registerLspRequestHandler___spec__5(lean_object* x_1, lean_object* x_2, lean_object* x_3, lean_object* x_4) { _start: { lean_object* x_5; lean_object* x_6; lean_object* x_7; uint8_t x_8; x_5 = lean_ctor_get(x_1, 0); lean_inc(x_5); x_6 = lean_ctor_get(x_1, 1); lean_inc(x_6); x_7 = lean_array_get_size(x_5); x_8 = lean_nat_dec_lt(x_2, x_7); lean_dec(x_7); if (x_8 == 0) { uint8_t x_9; lean_dec(x_2); x_9 = !lean_is_exclusive(x_1); if (x_9 == 0) { lean_object* x_10; lean_object* x_11; lean_object* x_12; lean_object* x_13; x_10 = lean_ctor_get(x_1, 1); lean_dec(x_10); x_11 = lean_ctor_get(x_1, 0); lean_dec(x_11); x_12 = lean_array_push(x_5, x_3); x_13 = lean_array_push(x_6, x_4); lean_ctor_set(x_1, 1, x_13); lean_ctor_set(x_1, 0, x_12); return x_1; } else { lean_object* x_14; lean_object* x_15; lean_object* x_16; lean_dec(x_1); x_14 = lean_array_push(x_5, x_3); x_15 = lean_array_push(x_6, x_4); x_16 = lean_alloc_ctor(1, 2, 0); lean_ctor_set(x_16, 0, x_14); lean_ctor_set(x_16, 1, x_15); return x_16; } } else { lean_object* x_17; uint8_t x_18; x_17 = lean_array_fget(x_5, x_2); x_18 = lean_string_dec_eq(x_3, x_17); lean_dec(x_17); if (x_18 == 0) { lean_object* x_19; lean_object* x_20; lean_dec(x_6); lean_dec(x_5); x_19 = lean_unsigned_to_nat(1u); x_20 = lean_nat_add(x_2, x_19); lean_dec(x_2); x_2 = x_20; goto _start; } else { uint8_t x_22; x_22 = !lean_is_exclusive(x_1); if (x_22 == 0) { lean_object* x_23; lean_object* x_24; lean_object* x_25; lean_object* x_26; x_23 = lean_ctor_get(x_1, 1); lean_dec(x_23); x_24 = lean_ctor_get(x_1, 0); lean_dec(x_24); x_25 = lean_array_fset(x_5, x_2, x_3); x_26 = lean_array_fset(x_6, x_2, x_4); lean_dec(x_2); lean_ctor_set(x_1, 1, x_26); lean_ctor_set(x_1, 0, x_25); return x_1; } else { lean_object* x_27; lean_object* x_28; lean_object* x_29; lean_dec(x_1); x_27 = lean_array_fset(x_5, x_2, x_3); x_28 = lean_array_fset(x_6, x_2, x_4); lean_dec(x_2); x_29 = lean_alloc_ctor(1, 2, 0); lean_ctor_set(x_29, 0, x_27); lean_ctor_set(x_29, 1, x_28); return x_29; } } } } } static size_t _init_l_Lean_PersistentHashMap_insertAux___at_Lean_Server_registerLspRequestHandler___spec__3___closed__1() { _start: { size_t x_1; size_t x_2; size_t x_3; x_1 = 1; x_2 = 5; x_3 = lean_usize_shift_left(x_1, x_2); return x_3; } } static size_t _init_l_Lean_PersistentHashMap_insertAux___at_Lean_Server_registerLspRequestHandler___spec__3___closed__2() { _start: { size_t x_1; size_t x_2; size_t x_3; x_1 = 1; x_2 = l_Lean_PersistentHashMap_insertAux___at_Lean_Server_registerLspRequestHandler___spec__3___closed__1; x_3 = lean_usize_sub(x_2, x_1); return x_3; } } static lean_object* _init_l_Lean_PersistentHashMap_insertAux___at_Lean_Server_registerLspRequestHandler___spec__3___closed__3() { _start: { lean_object* x_1; x_1 = l_Lean_PersistentHashMap_mkEmptyEntries(lean_box(0), lean_box(0)); return x_1; } } LEAN_EXPORT lean_object* l_Lean_PersistentHashMap_insertAux___at_Lean_Server_registerLspRequestHandler___spec__3(lean_object* x_1, size_t x_2, size_t x_3, lean_object* x_4, lean_object* x_5) { _start: { if (lean_obj_tag(x_1) == 0) { uint8_t x_6; x_6 = !lean_is_exclusive(x_1); if (x_6 == 0) { lean_object* x_7; size_t x_8; size_t x_9; size_t x_10; size_t x_11; lean_object* x_12; lean_object* x_13; uint8_t x_14; x_7 = lean_ctor_get(x_1, 0); x_8 = 1; x_9 = 5; x_10 = l_Lean_PersistentHashMap_insertAux___at_Lean_Server_registerLspRequestHandler___spec__3___closed__2; x_11 = lean_usize_land(x_2, x_10); x_12 = lean_usize_to_nat(x_11); x_13 = lean_array_get_size(x_7); x_14 = lean_nat_dec_lt(x_12, x_13); lean_dec(x_13); if (x_14 == 0) { lean_dec(x_12); lean_dec(x_5); lean_dec(x_4); return x_1; } else { lean_object* x_15; lean_object* x_16; lean_object* x_17; x_15 = lean_array_fget(x_7, x_12); x_16 = lean_box(0); x_17 = lean_array_fset(x_7, x_12, x_16); switch (lean_obj_tag(x_15)) { case 0: { uint8_t x_18; x_18 = !lean_is_exclusive(x_15); if (x_18 == 0) { lean_object* x_19; lean_object* x_20; uint8_t x_21; x_19 = lean_ctor_get(x_15, 0); x_20 = lean_ctor_get(x_15, 1); x_21 = lean_string_dec_eq(x_4, x_19); if (x_21 == 0) { lean_object* x_22; lean_object* x_23; lean_object* x_24; lean_free_object(x_15); x_22 = l_Lean_PersistentHashMap_mkCollisionNode___rarg(x_19, x_20, x_4, x_5); x_23 = lean_alloc_ctor(1, 1, 0); lean_ctor_set(x_23, 0, x_22); x_24 = lean_array_fset(x_17, x_12, x_23); lean_dec(x_12); lean_ctor_set(x_1, 0, x_24); return x_1; } else { lean_object* x_25; lean_dec(x_20); lean_dec(x_19); lean_ctor_set(x_15, 1, x_5); lean_ctor_set(x_15, 0, x_4); x_25 = lean_array_fset(x_17, x_12, x_15); lean_dec(x_12); lean_ctor_set(x_1, 0, x_25); return x_1; } } else { lean_object* x_26; lean_object* x_27; uint8_t x_28; x_26 = lean_ctor_get(x_15, 0); x_27 = lean_ctor_get(x_15, 1); lean_inc(x_27); lean_inc(x_26); lean_dec(x_15); x_28 = lean_string_dec_eq(x_4, x_26); if (x_28 == 0) { lean_object* x_29; lean_object* x_30; lean_object* x_31; x_29 = l_Lean_PersistentHashMap_mkCollisionNode___rarg(x_26, x_27, x_4, x_5); x_30 = lean_alloc_ctor(1, 1, 0); lean_ctor_set(x_30, 0, x_29); x_31 = lean_array_fset(x_17, x_12, x_30); lean_dec(x_12); lean_ctor_set(x_1, 0, x_31); return x_1; } else { lean_object* x_32; lean_object* x_33; lean_dec(x_27); lean_dec(x_26); x_32 = lean_alloc_ctor(0, 2, 0); lean_ctor_set(x_32, 0, x_4); lean_ctor_set(x_32, 1, x_5); x_33 = lean_array_fset(x_17, x_12, x_32); lean_dec(x_12); lean_ctor_set(x_1, 0, x_33); return x_1; } } } case 1: { uint8_t x_34; x_34 = !lean_is_exclusive(x_15); if (x_34 == 0) { lean_object* x_35; size_t x_36; size_t x_37; lean_object* x_38; lean_object* x_39; x_35 = lean_ctor_get(x_15, 0); x_36 = lean_usize_shift_right(x_2, x_9); x_37 = lean_usize_add(x_3, x_8); x_38 = l_Lean_PersistentHashMap_insertAux___at_Lean_Server_registerLspRequestHandler___spec__3(x_35, x_36, x_37, x_4, x_5); lean_ctor_set(x_15, 0, x_38); x_39 = lean_array_fset(x_17, x_12, x_15); lean_dec(x_12); lean_ctor_set(x_1, 0, x_39); return x_1; } else { lean_object* x_40; size_t x_41; size_t x_42; lean_object* x_43; lean_object* x_44; lean_object* x_45; x_40 = lean_ctor_get(x_15, 0); lean_inc(x_40); lean_dec(x_15); x_41 = lean_usize_shift_right(x_2, x_9); x_42 = lean_usize_add(x_3, x_8); x_43 = l_Lean_PersistentHashMap_insertAux___at_Lean_Server_registerLspRequestHandler___spec__3(x_40, x_41, x_42, x_4, x_5); x_44 = lean_alloc_ctor(1, 1, 0); lean_ctor_set(x_44, 0, x_43); x_45 = lean_array_fset(x_17, x_12, x_44); lean_dec(x_12); lean_ctor_set(x_1, 0, x_45); return x_1; } } default: { lean_object* x_46; lean_object* x_47; x_46 = lean_alloc_ctor(0, 2, 0); lean_ctor_set(x_46, 0, x_4); lean_ctor_set(x_46, 1, x_5); x_47 = lean_array_fset(x_17, x_12, x_46); lean_dec(x_12); lean_ctor_set(x_1, 0, x_47); return x_1; } } } } else { lean_object* x_48; size_t x_49; size_t x_50; size_t x_51; size_t x_52; lean_object* x_53; lean_object* x_54; uint8_t x_55; x_48 = lean_ctor_get(x_1, 0); lean_inc(x_48); lean_dec(x_1); x_49 = 1; x_50 = 5; x_51 = l_Lean_PersistentHashMap_insertAux___at_Lean_Server_registerLspRequestHandler___spec__3___closed__2; x_52 = lean_usize_land(x_2, x_51); x_53 = lean_usize_to_nat(x_52); x_54 = lean_array_get_size(x_48); x_55 = lean_nat_dec_lt(x_53, x_54); lean_dec(x_54); if (x_55 == 0) { lean_object* x_56; lean_dec(x_53); lean_dec(x_5); lean_dec(x_4); x_56 = lean_alloc_ctor(0, 1, 0); lean_ctor_set(x_56, 0, x_48); return x_56; } else { lean_object* x_57; lean_object* x_58; lean_object* x_59; x_57 = lean_array_fget(x_48, x_53); x_58 = lean_box(0); x_59 = lean_array_fset(x_48, x_53, x_58); switch (lean_obj_tag(x_57)) { case 0: { lean_object* x_60; lean_object* x_61; lean_object* x_62; uint8_t x_63; x_60 = lean_ctor_get(x_57, 0); lean_inc(x_60); x_61 = lean_ctor_get(x_57, 1); lean_inc(x_61); if (lean_is_exclusive(x_57)) { lean_ctor_release(x_57, 0); lean_ctor_release(x_57, 1); x_62 = x_57; } else { lean_dec_ref(x_57); x_62 = lean_box(0); } x_63 = lean_string_dec_eq(x_4, x_60); if (x_63 == 0) { lean_object* x_64; lean_object* x_65; lean_object* x_66; lean_object* x_67; lean_dec(x_62); x_64 = l_Lean_PersistentHashMap_mkCollisionNode___rarg(x_60, x_61, x_4, x_5); x_65 = lean_alloc_ctor(1, 1, 0); lean_ctor_set(x_65, 0, x_64); x_66 = lean_array_fset(x_59, x_53, x_65); lean_dec(x_53); x_67 = lean_alloc_ctor(0, 1, 0); lean_ctor_set(x_67, 0, x_66); return x_67; } else { lean_object* x_68; lean_object* x_69; lean_object* x_70; lean_dec(x_61); lean_dec(x_60); if (lean_is_scalar(x_62)) { x_68 = lean_alloc_ctor(0, 2, 0); } else { x_68 = x_62; } lean_ctor_set(x_68, 0, x_4); lean_ctor_set(x_68, 1, x_5); x_69 = lean_array_fset(x_59, x_53, x_68); lean_dec(x_53); x_70 = lean_alloc_ctor(0, 1, 0); lean_ctor_set(x_70, 0, x_69); return x_70; } } case 1: { lean_object* x_71; lean_object* x_72; size_t x_73; size_t x_74; lean_object* x_75; lean_object* x_76; lean_object* x_77; lean_object* x_78; x_71 = lean_ctor_get(x_57, 0); lean_inc(x_71); if (lean_is_exclusive(x_57)) { lean_ctor_release(x_57, 0); x_72 = x_57; } else { lean_dec_ref(x_57); x_72 = lean_box(0); } x_73 = lean_usize_shift_right(x_2, x_50); x_74 = lean_usize_add(x_3, x_49); x_75 = l_Lean_PersistentHashMap_insertAux___at_Lean_Server_registerLspRequestHandler___spec__3(x_71, x_73, x_74, x_4, x_5); if (lean_is_scalar(x_72)) { x_76 = lean_alloc_ctor(1, 1, 0); } else { x_76 = x_72; } lean_ctor_set(x_76, 0, x_75); x_77 = lean_array_fset(x_59, x_53, x_76); lean_dec(x_53); x_78 = lean_alloc_ctor(0, 1, 0); lean_ctor_set(x_78, 0, x_77); return x_78; } default: { lean_object* x_79; lean_object* x_80; lean_object* x_81; x_79 = lean_alloc_ctor(0, 2, 0); lean_ctor_set(x_79, 0, x_4); lean_ctor_set(x_79, 1, x_5); x_80 = lean_array_fset(x_59, x_53, x_79); lean_dec(x_53); x_81 = lean_alloc_ctor(0, 1, 0); lean_ctor_set(x_81, 0, x_80); return x_81; } } } } } else { uint8_t x_82; x_82 = !lean_is_exclusive(x_1); if (x_82 == 0) { lean_object* x_83; lean_object* x_84; size_t x_85; uint8_t x_86; x_83 = lean_unsigned_to_nat(0u); x_84 = l_Lean_PersistentHashMap_insertAtCollisionNodeAux___at_Lean_Server_registerLspRequestHandler___spec__5(x_1, x_83, x_4, x_5); x_85 = 7; x_86 = lean_usize_dec_le(x_85, x_3); if (x_86 == 0) { lean_object* x_87; lean_object* x_88; uint8_t x_89; x_87 = l_Lean_PersistentHashMap_getCollisionNodeSize___rarg(x_84); x_88 = lean_unsigned_to_nat(4u); x_89 = lean_nat_dec_lt(x_87, x_88); lean_dec(x_87); if (x_89 == 0) { lean_object* x_90; lean_object* x_91; lean_object* x_92; lean_object* x_93; x_90 = lean_ctor_get(x_84, 0); lean_inc(x_90); x_91 = lean_ctor_get(x_84, 1); lean_inc(x_91); lean_dec(x_84); x_92 = l_Lean_PersistentHashMap_insertAux___at_Lean_Server_registerLspRequestHandler___spec__3___closed__3; x_93 = l_Lean_PersistentHashMap_insertAux_traverse___at_Lean_Server_registerLspRequestHandler___spec__4(x_3, x_90, x_91, lean_box(0), x_83, x_92); lean_dec(x_91); lean_dec(x_90); return x_93; } else { return x_84; } } else { return x_84; } } else { lean_object* x_94; lean_object* x_95; lean_object* x_96; lean_object* x_97; lean_object* x_98; size_t x_99; uint8_t x_100; x_94 = lean_ctor_get(x_1, 0); x_95 = lean_ctor_get(x_1, 1); lean_inc(x_95); lean_inc(x_94); lean_dec(x_1); x_96 = lean_alloc_ctor(1, 2, 0); lean_ctor_set(x_96, 0, x_94); lean_ctor_set(x_96, 1, x_95); x_97 = lean_unsigned_to_nat(0u); x_98 = l_Lean_PersistentHashMap_insertAtCollisionNodeAux___at_Lean_Server_registerLspRequestHandler___spec__5(x_96, x_97, x_4, x_5); x_99 = 7; x_100 = lean_usize_dec_le(x_99, x_3); if (x_100 == 0) { lean_object* x_101; lean_object* x_102; uint8_t x_103; x_101 = l_Lean_PersistentHashMap_getCollisionNodeSize___rarg(x_98); x_102 = lean_unsigned_to_nat(4u); x_103 = lean_nat_dec_lt(x_101, x_102); lean_dec(x_101); if (x_103 == 0) { lean_object* x_104; lean_object* x_105; lean_object* x_106; lean_object* x_107; x_104 = lean_ctor_get(x_98, 0); lean_inc(x_104); x_105 = lean_ctor_get(x_98, 1); lean_inc(x_105); lean_dec(x_98); x_106 = l_Lean_PersistentHashMap_insertAux___at_Lean_Server_registerLspRequestHandler___spec__3___closed__3; x_107 = l_Lean_PersistentHashMap_insertAux_traverse___at_Lean_Server_registerLspRequestHandler___spec__4(x_3, x_104, x_105, lean_box(0), x_97, x_106); lean_dec(x_105); lean_dec(x_104); return x_107; } else { return x_98; } } else { return x_98; } } } } } LEAN_EXPORT lean_object* l_Lean_PersistentHashMap_insert___at_Lean_Server_registerLspRequestHandler___spec__2(lean_object* x_1, lean_object* x_2, lean_object* x_3) { _start: { uint8_t x_4; x_4 = !lean_is_exclusive(x_1); if (x_4 == 0) { lean_object* x_5; lean_object* x_6; uint64_t x_7; size_t x_8; size_t x_9; lean_object* x_10; lean_object* x_11; lean_object* x_12; x_5 = lean_ctor_get(x_1, 0); x_6 = lean_ctor_get(x_1, 1); x_7 = lean_string_hash(x_2); x_8 = lean_uint64_to_usize(x_7); x_9 = 1; x_10 = l_Lean_PersistentHashMap_insertAux___at_Lean_Server_registerLspRequestHandler___spec__3(x_5, x_8, x_9, x_2, x_3); x_11 = lean_unsigned_to_nat(1u); x_12 = lean_nat_add(x_6, x_11); lean_dec(x_6); lean_ctor_set(x_1, 1, x_12); lean_ctor_set(x_1, 0, x_10); return x_1; } else { lean_object* x_13; lean_object* x_14; uint64_t x_15; size_t x_16; size_t x_17; lean_object* x_18; lean_object* x_19; lean_object* x_20; lean_object* x_21; x_13 = lean_ctor_get(x_1, 0); x_14 = lean_ctor_get(x_1, 1); lean_inc(x_14); lean_inc(x_13); lean_dec(x_1); x_15 = lean_string_hash(x_2); x_16 = lean_uint64_to_usize(x_15); x_17 = 1; x_18 = l_Lean_PersistentHashMap_insertAux___at_Lean_Server_registerLspRequestHandler___spec__3(x_13, x_16, x_17, x_2, x_3); x_19 = lean_unsigned_to_nat(1u); x_20 = lean_nat_add(x_14, x_19); lean_dec(x_14); x_21 = lean_alloc_ctor(0, 2, 0); lean_ctor_set(x_21, 0, x_18); lean_ctor_set(x_21, 1, x_20); return x_21; } } } LEAN_EXPORT uint8_t l_Lean_PersistentHashMap_containsAtAux___at_Lean_Server_registerLspRequestHandler___spec__8(lean_object* x_1, lean_object* x_2, lean_object* x_3, lean_object* x_4, lean_object* x_5) { _start: { lean_object* x_6; uint8_t x_7; x_6 = lean_array_get_size(x_1); x_7 = lean_nat_dec_lt(x_4, x_6); lean_dec(x_6); if (x_7 == 0) { uint8_t x_8; lean_dec(x_4); x_8 = 0; return x_8; } else { lean_object* x_9; uint8_t x_10; x_9 = lean_array_fget(x_1, x_4); x_10 = lean_string_dec_eq(x_5, x_9); lean_dec(x_9); if (x_10 == 0) { lean_object* x_11; lean_object* x_12; x_11 = lean_unsigned_to_nat(1u); x_12 = lean_nat_add(x_4, x_11); lean_dec(x_4); x_3 = lean_box(0); x_4 = x_12; goto _start; } else { uint8_t x_14; lean_dec(x_4); x_14 = 1; return x_14; } } } } LEAN_EXPORT uint8_t l_Lean_PersistentHashMap_containsAux___at_Lean_Server_registerLspRequestHandler___spec__7(lean_object* x_1, size_t x_2, lean_object* x_3) { _start: { if (lean_obj_tag(x_1) == 0) { lean_object* x_4; size_t x_5; size_t x_6; size_t x_7; lean_object* x_8; lean_object* x_9; lean_object* x_10; x_4 = lean_ctor_get(x_1, 0); lean_inc(x_4); lean_dec(x_1); x_5 = 5; x_6 = l_Lean_PersistentHashMap_insertAux___at_Lean_Server_registerLspRequestHandler___spec__3___closed__2; x_7 = lean_usize_land(x_2, x_6); x_8 = lean_usize_to_nat(x_7); x_9 = lean_box(2); x_10 = lean_array_get(x_9, x_4, x_8); lean_dec(x_8); lean_dec(x_4); switch (lean_obj_tag(x_10)) { case 0: { lean_object* x_11; uint8_t x_12; x_11 = lean_ctor_get(x_10, 0); lean_inc(x_11); lean_dec(x_10); x_12 = lean_string_dec_eq(x_3, x_11); lean_dec(x_11); return x_12; } case 1: { lean_object* x_13; size_t x_14; x_13 = lean_ctor_get(x_10, 0); lean_inc(x_13); lean_dec(x_10); x_14 = lean_usize_shift_right(x_2, x_5); x_1 = x_13; x_2 = x_14; goto _start; } default: { uint8_t x_16; x_16 = 0; return x_16; } } } else { lean_object* x_17; lean_object* x_18; lean_object* x_19; uint8_t x_20; x_17 = lean_ctor_get(x_1, 0); lean_inc(x_17); x_18 = lean_ctor_get(x_1, 1); lean_inc(x_18); lean_dec(x_1); x_19 = lean_unsigned_to_nat(0u); x_20 = l_Lean_PersistentHashMap_containsAtAux___at_Lean_Server_registerLspRequestHandler___spec__8(x_17, x_18, lean_box(0), x_19, x_3); lean_dec(x_18); lean_dec(x_17); return x_20; } } } LEAN_EXPORT uint8_t l_Lean_PersistentHashMap_contains___at_Lean_Server_registerLspRequestHandler___spec__6(lean_object* x_1, lean_object* x_2) { _start: { lean_object* x_3; uint64_t x_4; size_t x_5; uint8_t x_6; x_3 = lean_ctor_get(x_1, 0); lean_inc(x_3); lean_dec(x_1); x_4 = lean_string_hash(x_2); x_5 = lean_uint64_to_usize(x_4); x_6 = l_Lean_PersistentHashMap_containsAux___at_Lean_Server_registerLspRequestHandler___spec__7(x_3, x_5, x_2); lean_dec(x_2); return x_6; } } LEAN_EXPORT lean_object* l_Lean_Server_registerLspRequestHandler___lambda__1(lean_object* x_1, lean_object* x_2, lean_object* x_3) { _start: { lean_object* x_4; x_4 = l_Lean_Server_parseRequestParams___rarg(x_1, x_3); if (lean_obj_tag(x_4) == 0) { uint8_t x_5; lean_dec(x_2); x_5 = !lean_is_exclusive(x_4); if (x_5 == 0) { return x_4; } else { lean_object* x_6; lean_object* x_7; x_6 = lean_ctor_get(x_4, 0); lean_inc(x_6); lean_dec(x_4); x_7 = lean_alloc_ctor(0, 1, 0); lean_ctor_set(x_7, 0, x_6); return x_7; } } else { uint8_t x_8; x_8 = !lean_is_exclusive(x_4); if (x_8 == 0) { lean_object* x_9; lean_object* x_10; x_9 = lean_ctor_get(x_4, 0); x_10 = lean_apply_1(x_2, x_9); lean_ctor_set(x_4, 0, x_10); return x_4; } else { lean_object* x_11; lean_object* x_12; lean_object* x_13; x_11 = lean_ctor_get(x_4, 0); lean_inc(x_11); lean_dec(x_4); x_12 = lean_apply_1(x_2, x_11); x_13 = lean_alloc_ctor(1, 1, 0); lean_ctor_set(x_13, 0, x_12); return x_13; } } } } LEAN_EXPORT lean_object* l_Lean_Server_registerLspRequestHandler___lambda__2(lean_object* x_1, lean_object* x_2, lean_object* x_3, lean_object* x_4, lean_object* x_5, lean_object* x_6) { _start: { lean_object* x_7; lean_object* x_8; x_7 = l_Lean_Server_parseRequestParams___rarg(x_1, x_4); x_8 = l_liftExcept___at_Lean_Server_registerLspRequestHandler___spec__1___rarg(x_7, x_5, x_6); lean_dec(x_7); if (lean_obj_tag(x_8) == 0) { lean_object* x_9; lean_object* x_10; lean_object* x_11; x_9 = lean_ctor_get(x_8, 0); lean_inc(x_9); x_10 = lean_ctor_get(x_8, 1); lean_inc(x_10); lean_dec(x_8); x_11 = lean_apply_3(x_2, x_9, x_5, x_10); if (lean_obj_tag(x_11) == 0) { uint8_t x_12; x_12 = !lean_is_exclusive(x_11); if (x_12 == 0) { lean_object* x_13; lean_object* x_14; lean_object* x_15; lean_object* x_16; x_13 = lean_ctor_get(x_11, 0); x_14 = lean_alloc_closure((void*)(l_Except_map___rarg), 2, 1); lean_closure_set(x_14, 0, x_3); x_15 = l_Task_Priority_default; x_16 = lean_task_map(x_14, x_13, x_15); lean_ctor_set(x_11, 0, x_16); return x_11; } else { lean_object* x_17; lean_object* x_18; lean_object* x_19; lean_object* x_20; lean_object* x_21; lean_object* x_22; x_17 = lean_ctor_get(x_11, 0); x_18 = lean_ctor_get(x_11, 1); lean_inc(x_18); lean_inc(x_17); lean_dec(x_11); x_19 = lean_alloc_closure((void*)(l_Except_map___rarg), 2, 1); lean_closure_set(x_19, 0, x_3); x_20 = l_Task_Priority_default; x_21 = lean_task_map(x_19, x_17, x_20); x_22 = lean_alloc_ctor(0, 2, 0); lean_ctor_set(x_22, 0, x_21); lean_ctor_set(x_22, 1, x_18); return x_22; } } else { uint8_t x_23; lean_dec(x_3); x_23 = !lean_is_exclusive(x_11); if (x_23 == 0) { return x_11; } else { lean_object* x_24; lean_object* x_25; lean_object* x_26; x_24 = lean_ctor_get(x_11, 0); x_25 = lean_ctor_get(x_11, 1); lean_inc(x_25); lean_inc(x_24); lean_dec(x_11); x_26 = lean_alloc_ctor(1, 2, 0); lean_ctor_set(x_26, 0, x_24); lean_ctor_set(x_26, 1, x_25); return x_26; } } } else { uint8_t x_27; lean_dec(x_5); lean_dec(x_3); lean_dec(x_2); x_27 = !lean_is_exclusive(x_8); if (x_27 == 0) { return x_8; } else { lean_object* x_28; lean_object* x_29; lean_object* x_30; x_28 = lean_ctor_get(x_8, 0); x_29 = lean_ctor_get(x_8, 1); lean_inc(x_29); lean_inc(x_28); lean_dec(x_8); x_30 = lean_alloc_ctor(1, 2, 0); lean_ctor_set(x_30, 0, x_28); lean_ctor_set(x_30, 1, x_29); return x_30; } } } } static lean_object* _init_l_Lean_Server_registerLspRequestHandler___lambda__3___closed__1() { _start: { lean_object* x_1; x_1 = l_Lean_Server_requestHandlers; return x_1; } } LEAN_EXPORT lean_object* l_Lean_Server_registerLspRequestHandler___lambda__3(lean_object* x_1, lean_object* x_2, lean_object* x_3, lean_object* x_4, lean_object* x_5, lean_object* x_6, lean_object* x_7) { _start: { lean_object* x_8; lean_object* x_9; lean_object* x_10; lean_object* x_11; lean_object* x_12; lean_object* x_13; lean_object* x_14; lean_object* x_15; lean_object* x_16; uint8_t x_17; lean_inc(x_1); x_8 = lean_alloc_closure((void*)(l_Lean_Server_registerLspRequestHandler___lambda__1), 3, 2); lean_closure_set(x_8, 0, x_1); lean_closure_set(x_8, 1, x_2); x_9 = lean_alloc_closure((void*)(l_Lean_Server_registerLspRequestHandler___lambda__2), 6, 3); lean_closure_set(x_9, 0, x_1); lean_closure_set(x_9, 1, x_3); lean_closure_set(x_9, 2, x_4); x_10 = l_Lean_Server_registerLspRequestHandler___lambda__3___closed__1; x_11 = lean_st_ref_take(x_10, x_7); x_12 = lean_ctor_get(x_11, 0); lean_inc(x_12); x_13 = lean_ctor_get(x_11, 1); lean_inc(x_13); lean_dec(x_11); x_14 = lean_alloc_ctor(0, 2, 0); lean_ctor_set(x_14, 0, x_8); lean_ctor_set(x_14, 1, x_9); x_15 = l_Lean_PersistentHashMap_insert___at_Lean_Server_registerLspRequestHandler___spec__2(x_12, x_5, x_14); x_16 = lean_st_ref_set(x_10, x_15, x_13); x_17 = !lean_is_exclusive(x_16); if (x_17 == 0) { return x_16; } else { lean_object* x_18; lean_object* x_19; lean_object* x_20; x_18 = lean_ctor_get(x_16, 0); x_19 = lean_ctor_get(x_16, 1); lean_inc(x_19); lean_inc(x_18); lean_dec(x_16); x_20 = lean_alloc_ctor(0, 2, 0); lean_ctor_set(x_20, 0, x_18); lean_ctor_set(x_20, 1, x_19); return x_20; } } } static lean_object* _init_l_Lean_Server_registerLspRequestHandler___lambda__4___closed__1() { _start: { lean_object* x_1; x_1 = lean_mk_string_from_bytes("Failed to register LSP request handler for '", 44); return x_1; } } static lean_object* _init_l_Lean_Server_registerLspRequestHandler___lambda__4___closed__2() { _start: { lean_object* x_1; x_1 = lean_mk_string_from_bytes("': already registered", 21); return x_1; } } LEAN_EXPORT lean_object* l_Lean_Server_registerLspRequestHandler___lambda__4(lean_object* x_1, lean_object* x_2, lean_object* x_3, lean_object* x_4, lean_object* x_5, lean_object* x_6, lean_object* x_7) { _start: { lean_object* x_8; lean_object* x_9; uint8_t x_10; lean_dec(x_6); x_8 = l_Lean_Server_registerLspRequestHandler___lambda__3___closed__1; x_9 = lean_st_ref_get(x_8, x_7); x_10 = !lean_is_exclusive(x_9); if (x_10 == 0) { lean_object* x_11; lean_object* x_12; uint8_t x_13; x_11 = lean_ctor_get(x_9, 0); x_12 = lean_ctor_get(x_9, 1); lean_inc(x_5); x_13 = l_Lean_PersistentHashMap_contains___at_Lean_Server_registerLspRequestHandler___spec__6(x_11, x_5); if (x_13 == 0) { lean_object* x_14; lean_object* x_15; lean_free_object(x_9); x_14 = lean_box(0); x_15 = l_Lean_Server_registerLspRequestHandler___lambda__3(x_1, x_2, x_3, x_4, x_5, x_14, x_12); return x_15; } else { lean_object* x_16; lean_object* x_17; lean_object* x_18; lean_object* x_19; lean_object* x_20; lean_dec(x_4); lean_dec(x_3); lean_dec(x_2); lean_dec(x_1); x_16 = l_Lean_Server_registerLspRequestHandler___lambda__4___closed__1; x_17 = lean_string_append(x_16, x_5); lean_dec(x_5); x_18 = l_Lean_Server_registerLspRequestHandler___lambda__4___closed__2; x_19 = lean_string_append(x_17, x_18); x_20 = lean_alloc_ctor(18, 1, 0); lean_ctor_set(x_20, 0, x_19); lean_ctor_set_tag(x_9, 1); lean_ctor_set(x_9, 0, x_20); return x_9; } } else { lean_object* x_21; lean_object* x_22; uint8_t x_23; x_21 = lean_ctor_get(x_9, 0); x_22 = lean_ctor_get(x_9, 1); lean_inc(x_22); lean_inc(x_21); lean_dec(x_9); lean_inc(x_5); x_23 = l_Lean_PersistentHashMap_contains___at_Lean_Server_registerLspRequestHandler___spec__6(x_21, x_5); if (x_23 == 0) { lean_object* x_24; lean_object* x_25; x_24 = lean_box(0); x_25 = l_Lean_Server_registerLspRequestHandler___lambda__3(x_1, x_2, x_3, x_4, x_5, x_24, x_22); return x_25; } else { lean_object* x_26; lean_object* x_27; lean_object* x_28; lean_object* x_29; lean_object* x_30; lean_object* x_31; lean_dec(x_4); lean_dec(x_3); lean_dec(x_2); lean_dec(x_1); x_26 = l_Lean_Server_registerLspRequestHandler___lambda__4___closed__1; x_27 = lean_string_append(x_26, x_5); lean_dec(x_5); x_28 = l_Lean_Server_registerLspRequestHandler___lambda__4___closed__2; x_29 = lean_string_append(x_27, x_28); x_30 = lean_alloc_ctor(18, 1, 0); lean_ctor_set(x_30, 0, x_29); x_31 = lean_alloc_ctor(1, 2, 0); lean_ctor_set(x_31, 0, x_30); lean_ctor_set(x_31, 1, x_22); return x_31; } } } } static lean_object* _init_l_Lean_Server_registerLspRequestHandler___closed__1() { _start: { lean_object* x_1; x_1 = lean_mk_string_from_bytes("': only possible during initialization", 38); return x_1; } } LEAN_EXPORT lean_object* l_Lean_Server_registerLspRequestHandler(lean_object* x_1, lean_object* x_2, lean_object* x_3, lean_object* x_4, lean_object* x_5, lean_object* x_6, lean_object* x_7, lean_object* x_8) { _start: { lean_object* x_9; lean_object* x_10; uint8_t x_11; x_9 = l_Lean_initializing(x_8); x_10 = lean_ctor_get(x_9, 0); lean_inc(x_10); x_11 = lean_unbox(x_10); lean_dec(x_10); if (x_11 == 0) { uint8_t x_12; lean_dec(x_7); lean_dec(x_6); lean_dec(x_4); lean_dec(x_3); x_12 = !lean_is_exclusive(x_9); if (x_12 == 0) { lean_object* x_13; lean_object* x_14; lean_object* x_15; lean_object* x_16; lean_object* x_17; lean_object* x_18; x_13 = lean_ctor_get(x_9, 0); lean_dec(x_13); x_14 = l_Lean_Server_registerLspRequestHandler___lambda__4___closed__1; x_15 = lean_string_append(x_14, x_1); lean_dec(x_1); x_16 = l_Lean_Server_registerLspRequestHandler___closed__1; x_17 = lean_string_append(x_15, x_16); x_18 = lean_alloc_ctor(18, 1, 0); lean_ctor_set(x_18, 0, x_17); lean_ctor_set_tag(x_9, 1); lean_ctor_set(x_9, 0, x_18); return x_9; } else { lean_object* x_19; lean_object* x_20; lean_object* x_21; lean_object* x_22; lean_object* x_23; lean_object* x_24; lean_object* x_25; x_19 = lean_ctor_get(x_9, 1); lean_inc(x_19); lean_dec(x_9); x_20 = l_Lean_Server_registerLspRequestHandler___lambda__4___closed__1; x_21 = lean_string_append(x_20, x_1); lean_dec(x_1); x_22 = l_Lean_Server_registerLspRequestHandler___closed__1; x_23 = lean_string_append(x_21, x_22); x_24 = lean_alloc_ctor(18, 1, 0); lean_ctor_set(x_24, 0, x_23); x_25 = lean_alloc_ctor(1, 2, 0); lean_ctor_set(x_25, 0, x_24); lean_ctor_set(x_25, 1, x_19); return x_25; } } else { lean_object* x_26; lean_object* x_27; lean_object* x_28; x_26 = lean_ctor_get(x_9, 1); lean_inc(x_26); lean_dec(x_9); x_27 = lean_box(0); x_28 = l_Lean_Server_registerLspRequestHandler___lambda__4(x_3, x_4, x_7, x_6, x_1, x_27, x_26); return x_28; } } } LEAN_EXPORT lean_object* l_liftExcept___at_Lean_Server_registerLspRequestHandler___spec__1___rarg___boxed(lean_object* x_1, lean_object* x_2, lean_object* x_3) { _start: { lean_object* x_4; x_4 = l_liftExcept___at_Lean_Server_registerLspRequestHandler___spec__1___rarg(x_1, x_2, x_3); lean_dec(x_2); lean_dec(x_1); return x_4; } } LEAN_EXPORT lean_object* l_Lean_PersistentHashMap_insertAux_traverse___at_Lean_Server_registerLspRequestHandler___spec__4___boxed(lean_object* x_1, lean_object* x_2, lean_object* x_3, lean_object* x_4, lean_object* x_5, lean_object* x_6) { _start: { size_t x_7; lean_object* x_8; x_7 = lean_unbox_usize(x_1); lean_dec(x_1); x_8 = l_Lean_PersistentHashMap_insertAux_traverse___at_Lean_Server_registerLspRequestHandler___spec__4(x_7, x_2, x_3, x_4, x_5, x_6); lean_dec(x_3); lean_dec(x_2); return x_8; } } LEAN_EXPORT lean_object* l_Lean_PersistentHashMap_insertAux___at_Lean_Server_registerLspRequestHandler___spec__3___boxed(lean_object* x_1, lean_object* x_2, lean_object* x_3, lean_object* x_4, lean_object* x_5) { _start: { size_t x_6; size_t x_7; lean_object* x_8; x_6 = lean_unbox_usize(x_2); lean_dec(x_2); x_7 = lean_unbox_usize(x_3); lean_dec(x_3); x_8 = l_Lean_PersistentHashMap_insertAux___at_Lean_Server_registerLspRequestHandler___spec__3(x_1, x_6, x_7, x_4, x_5); return x_8; } } LEAN_EXPORT lean_object* l_Lean_PersistentHashMap_containsAtAux___at_Lean_Server_registerLspRequestHandler___spec__8___boxed(lean_object* x_1, lean_object* x_2, lean_object* x_3, lean_object* x_4, lean_object* x_5) { _start: { uint8_t x_6; lean_object* x_7; x_6 = l_Lean_PersistentHashMap_containsAtAux___at_Lean_Server_registerLspRequestHandler___spec__8(x_1, x_2, x_3, x_4, x_5); lean_dec(x_5); lean_dec(x_2); lean_dec(x_1); x_7 = lean_box(x_6); return x_7; } } LEAN_EXPORT lean_object* l_Lean_PersistentHashMap_containsAux___at_Lean_Server_registerLspRequestHandler___spec__7___boxed(lean_object* x_1, lean_object* x_2, lean_object* x_3) { _start: { size_t x_4; uint8_t x_5; lean_object* x_6; x_4 = lean_unbox_usize(x_2); lean_dec(x_2); x_5 = l_Lean_PersistentHashMap_containsAux___at_Lean_Server_registerLspRequestHandler___spec__7(x_1, x_4, x_3); lean_dec(x_3); x_6 = lean_box(x_5); return x_6; } } LEAN_EXPORT lean_object* l_Lean_PersistentHashMap_contains___at_Lean_Server_registerLspRequestHandler___spec__6___boxed(lean_object* x_1, lean_object* x_2) { _start: { uint8_t x_3; lean_object* x_4; x_3 = l_Lean_PersistentHashMap_contains___at_Lean_Server_registerLspRequestHandler___spec__6(x_1, x_2); x_4 = lean_box(x_3); return x_4; } } LEAN_EXPORT lean_object* l_Lean_Server_registerLspRequestHandler___lambda__3___boxed(lean_object* x_1, lean_object* x_2, lean_object* x_3, lean_object* x_4, lean_object* x_5, lean_object* x_6, lean_object* x_7) { _start: { lean_object* x_8; x_8 = l_Lean_Server_registerLspRequestHandler___lambda__3(x_1, x_2, x_3, x_4, x_5, x_6, x_7); lean_dec(x_6); return x_8; } } LEAN_EXPORT lean_object* l_Lean_PersistentHashMap_findAtAux___at_Lean_Server_lookupLspRequestHandler___spec__3(lean_object* x_1, lean_object* x_2, lean_object* x_3, lean_object* x_4, lean_object* x_5) { _start: { lean_object* x_6; uint8_t x_7; x_6 = lean_array_get_size(x_1); x_7 = lean_nat_dec_lt(x_4, x_6); lean_dec(x_6); if (x_7 == 0) { lean_object* x_8; lean_dec(x_4); x_8 = lean_box(0); return x_8; } else { lean_object* x_9; uint8_t x_10; x_9 = lean_array_fget(x_1, x_4); x_10 = lean_string_dec_eq(x_5, x_9); lean_dec(x_9); if (x_10 == 0) { lean_object* x_11; lean_object* x_12; x_11 = lean_unsigned_to_nat(1u); x_12 = lean_nat_add(x_4, x_11); lean_dec(x_4); x_3 = lean_box(0); x_4 = x_12; goto _start; } else { lean_object* x_14; lean_object* x_15; x_14 = lean_array_fget(x_2, x_4); lean_dec(x_4); x_15 = lean_alloc_ctor(1, 1, 0); lean_ctor_set(x_15, 0, x_14); return x_15; } } } } LEAN_EXPORT lean_object* l_Lean_PersistentHashMap_findAux___at_Lean_Server_lookupLspRequestHandler___spec__2(lean_object* x_1, size_t x_2, lean_object* x_3) { _start: { if (lean_obj_tag(x_1) == 0) { lean_object* x_4; size_t x_5; size_t x_6; size_t x_7; lean_object* x_8; lean_object* x_9; lean_object* x_10; x_4 = lean_ctor_get(x_1, 0); lean_inc(x_4); lean_dec(x_1); x_5 = 5; x_6 = l_Lean_PersistentHashMap_insertAux___at_Lean_Server_registerLspRequestHandler___spec__3___closed__2; x_7 = lean_usize_land(x_2, x_6); x_8 = lean_usize_to_nat(x_7); x_9 = lean_box(2); x_10 = lean_array_get(x_9, x_4, x_8); lean_dec(x_8); lean_dec(x_4); switch (lean_obj_tag(x_10)) { case 0: { lean_object* x_11; lean_object* x_12; uint8_t x_13; x_11 = lean_ctor_get(x_10, 0); lean_inc(x_11); x_12 = lean_ctor_get(x_10, 1); lean_inc(x_12); lean_dec(x_10); x_13 = lean_string_dec_eq(x_3, x_11); lean_dec(x_11); if (x_13 == 0) { lean_object* x_14; lean_dec(x_12); x_14 = lean_box(0); return x_14; } else { lean_object* x_15; x_15 = lean_alloc_ctor(1, 1, 0); lean_ctor_set(x_15, 0, x_12); return x_15; } } case 1: { lean_object* x_16; size_t x_17; x_16 = lean_ctor_get(x_10, 0); lean_inc(x_16); lean_dec(x_10); x_17 = lean_usize_shift_right(x_2, x_5); x_1 = x_16; x_2 = x_17; goto _start; } default: { lean_object* x_19; x_19 = lean_box(0); return x_19; } } } else { lean_object* x_20; lean_object* x_21; lean_object* x_22; lean_object* x_23; x_20 = lean_ctor_get(x_1, 0); lean_inc(x_20); x_21 = lean_ctor_get(x_1, 1); lean_inc(x_21); lean_dec(x_1); x_22 = lean_unsigned_to_nat(0u); x_23 = l_Lean_PersistentHashMap_findAtAux___at_Lean_Server_lookupLspRequestHandler___spec__3(x_20, x_21, lean_box(0), x_22, x_3); lean_dec(x_21); lean_dec(x_20); return x_23; } } } LEAN_EXPORT lean_object* l_Lean_PersistentHashMap_find_x3f___at_Lean_Server_lookupLspRequestHandler___spec__1(lean_object* x_1, lean_object* x_2) { _start: { lean_object* x_3; uint64_t x_4; size_t x_5; lean_object* x_6; x_3 = lean_ctor_get(x_1, 0); lean_inc(x_3); lean_dec(x_1); x_4 = lean_string_hash(x_2); x_5 = lean_uint64_to_usize(x_4); x_6 = l_Lean_PersistentHashMap_findAux___at_Lean_Server_lookupLspRequestHandler___spec__2(x_3, x_5, x_2); lean_dec(x_2); return x_6; } } LEAN_EXPORT lean_object* l_Lean_Server_lookupLspRequestHandler(lean_object* x_1, lean_object* x_2) { _start: { lean_object* x_3; lean_object* x_4; uint8_t x_5; x_3 = l_Lean_Server_registerLspRequestHandler___lambda__3___closed__1; x_4 = lean_st_ref_get(x_3, x_2); x_5 = !lean_is_exclusive(x_4); if (x_5 == 0) { lean_object* x_6; lean_object* x_7; x_6 = lean_ctor_get(x_4, 0); x_7 = l_Lean_PersistentHashMap_find_x3f___at_Lean_Server_lookupLspRequestHandler___spec__1(x_6, x_1); lean_ctor_set(x_4, 0, x_7); return x_4; } else { lean_object* x_8; lean_object* x_9; lean_object* x_10; lean_object* x_11; x_8 = lean_ctor_get(x_4, 0); x_9 = lean_ctor_get(x_4, 1); lean_inc(x_9); lean_inc(x_8); lean_dec(x_4); x_10 = l_Lean_PersistentHashMap_find_x3f___at_Lean_Server_lookupLspRequestHandler___spec__1(x_8, x_1); x_11 = lean_alloc_ctor(0, 2, 0); lean_ctor_set(x_11, 0, x_10); lean_ctor_set(x_11, 1, x_9); return x_11; } } } LEAN_EXPORT lean_object* l_Lean_PersistentHashMap_findAtAux___at_Lean_Server_lookupLspRequestHandler___spec__3___boxed(lean_object* x_1, lean_object* x_2, lean_object* x_3, lean_object* x_4, lean_object* x_5) { _start: { lean_object* x_6; x_6 = l_Lean_PersistentHashMap_findAtAux___at_Lean_Server_lookupLspRequestHandler___spec__3(x_1, x_2, x_3, x_4, x_5); lean_dec(x_5); lean_dec(x_2); lean_dec(x_1); return x_6; } } LEAN_EXPORT lean_object* l_Lean_PersistentHashMap_findAux___at_Lean_Server_lookupLspRequestHandler___spec__2___boxed(lean_object* x_1, lean_object* x_2, lean_object* x_3) { _start: { size_t x_4; lean_object* x_5; x_4 = lean_unbox_usize(x_2); lean_dec(x_2); x_5 = l_Lean_PersistentHashMap_findAux___at_Lean_Server_lookupLspRequestHandler___spec__2(x_1, x_4, x_3); lean_dec(x_3); return x_5; } } LEAN_EXPORT lean_object* l_liftExcept___at_Lean_Server_chainLspRequestHandler___spec__1___rarg(lean_object* x_1, lean_object* x_2, lean_object* x_3) { _start: { if (lean_obj_tag(x_1) == 0) { lean_object* x_4; lean_object* x_5; x_4 = lean_ctor_get(x_1, 0); lean_inc(x_4); x_5 = lean_alloc_ctor(1, 2, 0); lean_ctor_set(x_5, 0, x_4); lean_ctor_set(x_5, 1, x_3); return x_5; } else { lean_object* x_6; lean_object* x_7; x_6 = lean_ctor_get(x_1, 0); lean_inc(x_6); x_7 = lean_alloc_ctor(0, 2, 0); lean_ctor_set(x_7, 0, x_6); lean_ctor_set(x_7, 1, x_3); return x_7; } } } LEAN_EXPORT lean_object* l_liftExcept___at_Lean_Server_chainLspRequestHandler___spec__1(lean_object* x_1) { _start: { lean_object* x_2; x_2 = lean_alloc_closure((void*)(l_liftExcept___at_Lean_Server_chainLspRequestHandler___spec__1___rarg___boxed), 3, 0); return x_2; } } static lean_object* _init_l_Lean_Server_chainLspRequestHandler___lambda__1___closed__1() { _start: { lean_object* x_1; x_1 = lean_mk_string_from_bytes("Failed to parse original LSP response for `", 43); return x_1; } } static lean_object* _init_l_Lean_Server_chainLspRequestHandler___lambda__1___closed__2() { _start: { lean_object* x_1; x_1 = lean_mk_string_from_bytes("` when chaining: ", 17); return x_1; } } LEAN_EXPORT lean_object* l_Lean_Server_chainLspRequestHandler___lambda__1(lean_object* x_1, lean_object* x_2, lean_object* x_3) { _start: { if (lean_obj_tag(x_3) == 0) { uint8_t x_4; lean_dec(x_1); x_4 = !lean_is_exclusive(x_3); if (x_4 == 0) { return x_3; } else { lean_object* x_5; lean_object* x_6; x_5 = lean_ctor_get(x_3, 0); lean_inc(x_5); lean_dec(x_3); x_6 = lean_alloc_ctor(0, 1, 0); lean_ctor_set(x_6, 0, x_5); return x_6; } } else { lean_object* x_7; lean_object* x_8; x_7 = lean_ctor_get(x_3, 0); lean_inc(x_7); lean_dec(x_3); x_8 = lean_apply_1(x_1, x_7); if (lean_obj_tag(x_8) == 0) { uint8_t x_9; x_9 = !lean_is_exclusive(x_8); if (x_9 == 0) { lean_object* x_10; lean_object* x_11; lean_object* x_12; lean_object* x_13; lean_object* x_14; lean_object* x_15; lean_object* x_16; lean_object* x_17; uint8_t x_18; lean_object* x_19; x_10 = lean_ctor_get(x_8, 0); x_11 = l_Lean_Server_chainLspRequestHandler___lambda__1___closed__1; x_12 = lean_string_append(x_11, x_2); x_13 = l_Lean_Server_chainLspRequestHandler___lambda__1___closed__2; x_14 = lean_string_append(x_12, x_13); x_15 = lean_string_append(x_14, x_10); lean_dec(x_10); x_16 = l_Lean_Server_instInhabitedRequestError___closed__1; x_17 = lean_string_append(x_15, x_16); x_18 = 4; x_19 = lean_alloc_ctor(0, 1, 1); lean_ctor_set(x_19, 0, x_17); lean_ctor_set_uint8(x_19, sizeof(void*)*1, x_18); lean_ctor_set(x_8, 0, x_19); return x_8; } else { lean_object* x_20; lean_object* x_21; lean_object* x_22; lean_object* x_23; lean_object* x_24; lean_object* x_25; lean_object* x_26; lean_object* x_27; uint8_t x_28; lean_object* x_29; lean_object* x_30; x_20 = lean_ctor_get(x_8, 0); lean_inc(x_20); lean_dec(x_8); x_21 = l_Lean_Server_chainLspRequestHandler___lambda__1___closed__1; x_22 = lean_string_append(x_21, x_2); x_23 = l_Lean_Server_chainLspRequestHandler___lambda__1___closed__2; x_24 = lean_string_append(x_22, x_23); x_25 = lean_string_append(x_24, x_20); lean_dec(x_20); x_26 = l_Lean_Server_instInhabitedRequestError___closed__1; x_27 = lean_string_append(x_25, x_26); x_28 = 4; x_29 = lean_alloc_ctor(0, 1, 1); lean_ctor_set(x_29, 0, x_27); lean_ctor_set_uint8(x_29, sizeof(void*)*1, x_28); x_30 = lean_alloc_ctor(0, 1, 0); lean_ctor_set(x_30, 0, x_29); return x_30; } } else { uint8_t x_31; x_31 = !lean_is_exclusive(x_8); if (x_31 == 0) { return x_8; } else { lean_object* x_32; lean_object* x_33; x_32 = lean_ctor_get(x_8, 0); lean_inc(x_32); lean_dec(x_8); x_33 = lean_alloc_ctor(1, 1, 0); lean_ctor_set(x_33, 0, x_32); return x_33; } } } } } LEAN_EXPORT lean_object* l_Lean_Server_chainLspRequestHandler___lambda__2(lean_object* x_1, lean_object* x_2, lean_object* x_3, lean_object* x_4, lean_object* x_5, lean_object* x_6, lean_object* x_7, lean_object* x_8, lean_object* x_9) { _start: { lean_object* x_10; lean_object* x_11; x_10 = lean_ctor_get(x_1, 1); lean_inc(x_10); lean_dec(x_1); lean_inc(x_8); lean_inc(x_7); x_11 = lean_apply_3(x_10, x_7, x_8, x_9); if (lean_obj_tag(x_11) == 0) { lean_object* x_12; lean_object* x_13; lean_object* x_14; lean_object* x_15; lean_object* x_16; lean_object* x_17; lean_object* x_18; x_12 = lean_ctor_get(x_11, 0); lean_inc(x_12); x_13 = lean_ctor_get(x_11, 1); lean_inc(x_13); lean_dec(x_11); x_14 = lean_alloc_closure((void*)(l_Lean_Server_chainLspRequestHandler___lambda__1___boxed), 3, 2); lean_closure_set(x_14, 0, x_2); lean_closure_set(x_14, 1, x_3); x_15 = l_Task_Priority_default; x_16 = lean_task_map(x_14, x_12, x_15); x_17 = l_Lean_Server_parseRequestParams___rarg(x_4, x_7); x_18 = l_liftExcept___at_Lean_Server_chainLspRequestHandler___spec__1___rarg(x_17, x_8, x_13); lean_dec(x_17); if (lean_obj_tag(x_18) == 0) { lean_object* x_19; lean_object* x_20; lean_object* x_21; x_19 = lean_ctor_get(x_18, 0); lean_inc(x_19); x_20 = lean_ctor_get(x_18, 1); lean_inc(x_20); lean_dec(x_18); x_21 = lean_apply_4(x_5, x_19, x_16, x_8, x_20); if (lean_obj_tag(x_21) == 0) { uint8_t x_22; x_22 = !lean_is_exclusive(x_21); if (x_22 == 0) { lean_object* x_23; lean_object* x_24; lean_object* x_25; x_23 = lean_ctor_get(x_21, 0); x_24 = lean_alloc_closure((void*)(l_Except_map___rarg), 2, 1); lean_closure_set(x_24, 0, x_6); x_25 = lean_task_map(x_24, x_23, x_15); lean_ctor_set(x_21, 0, x_25); return x_21; } else { lean_object* x_26; lean_object* x_27; lean_object* x_28; lean_object* x_29; lean_object* x_30; x_26 = lean_ctor_get(x_21, 0); x_27 = lean_ctor_get(x_21, 1); lean_inc(x_27); lean_inc(x_26); lean_dec(x_21); x_28 = lean_alloc_closure((void*)(l_Except_map___rarg), 2, 1); lean_closure_set(x_28, 0, x_6); x_29 = lean_task_map(x_28, x_26, x_15); x_30 = lean_alloc_ctor(0, 2, 0); lean_ctor_set(x_30, 0, x_29); lean_ctor_set(x_30, 1, x_27); return x_30; } } else { uint8_t x_31; lean_dec(x_6); x_31 = !lean_is_exclusive(x_21); if (x_31 == 0) { return x_21; } else { lean_object* x_32; lean_object* x_33; lean_object* x_34; x_32 = lean_ctor_get(x_21, 0); x_33 = lean_ctor_get(x_21, 1); lean_inc(x_33); lean_inc(x_32); lean_dec(x_21); x_34 = lean_alloc_ctor(1, 2, 0); lean_ctor_set(x_34, 0, x_32); lean_ctor_set(x_34, 1, x_33); return x_34; } } } else { uint8_t x_35; lean_dec(x_16); lean_dec(x_8); lean_dec(x_6); lean_dec(x_5); x_35 = !lean_is_exclusive(x_18); if (x_35 == 0) { return x_18; } else { lean_object* x_36; lean_object* x_37; lean_object* x_38; x_36 = lean_ctor_get(x_18, 0); x_37 = lean_ctor_get(x_18, 1); lean_inc(x_37); lean_inc(x_36); lean_dec(x_18); x_38 = lean_alloc_ctor(1, 2, 0); lean_ctor_set(x_38, 0, x_36); lean_ctor_set(x_38, 1, x_37); return x_38; } } } else { uint8_t x_39; lean_dec(x_8); lean_dec(x_7); lean_dec(x_6); lean_dec(x_5); lean_dec(x_4); lean_dec(x_3); lean_dec(x_2); x_39 = !lean_is_exclusive(x_11); if (x_39 == 0) { return x_11; } else { lean_object* x_40; lean_object* x_41; lean_object* x_42; x_40 = lean_ctor_get(x_11, 0); x_41 = lean_ctor_get(x_11, 1); lean_inc(x_41); lean_inc(x_40); lean_dec(x_11); x_42 = lean_alloc_ctor(1, 2, 0); lean_ctor_set(x_42, 0, x_40); lean_ctor_set(x_42, 1, x_41); return x_42; } } } } static lean_object* _init_l_Lean_Server_chainLspRequestHandler___lambda__3___closed__1() { _start: { lean_object* x_1; x_1 = lean_mk_string_from_bytes("Failed to chain LSP request handler for '", 41); return x_1; } } static lean_object* _init_l_Lean_Server_chainLspRequestHandler___lambda__3___closed__2() { _start: { lean_object* x_1; x_1 = lean_mk_string_from_bytes("': no initial handler registered", 32); return x_1; } } LEAN_EXPORT lean_object* l_Lean_Server_chainLspRequestHandler___lambda__3(lean_object* x_1, lean_object* x_2, lean_object* x_3, lean_object* x_4, lean_object* x_5, lean_object* x_6, lean_object* x_7) { _start: { lean_object* x_8; lean_object* x_9; lean_inc(x_1); x_8 = l_Lean_Server_lookupLspRequestHandler(x_1, x_7); x_9 = lean_ctor_get(x_8, 0); lean_inc(x_9); if (lean_obj_tag(x_9) == 0) { uint8_t x_10; lean_dec(x_5); lean_dec(x_4); lean_dec(x_3); lean_dec(x_2); x_10 = !lean_is_exclusive(x_8); if (x_10 == 0) { lean_object* x_11; lean_object* x_12; lean_object* x_13; lean_object* x_14; lean_object* x_15; lean_object* x_16; x_11 = lean_ctor_get(x_8, 0); lean_dec(x_11); x_12 = l_Lean_Server_chainLspRequestHandler___lambda__3___closed__1; x_13 = lean_string_append(x_12, x_1); lean_dec(x_1); x_14 = l_Lean_Server_chainLspRequestHandler___lambda__3___closed__2; x_15 = lean_string_append(x_13, x_14); x_16 = lean_alloc_ctor(18, 1, 0); lean_ctor_set(x_16, 0, x_15); lean_ctor_set_tag(x_8, 1); lean_ctor_set(x_8, 0, x_16); return x_8; } else { lean_object* x_17; lean_object* x_18; lean_object* x_19; lean_object* x_20; lean_object* x_21; lean_object* x_22; lean_object* x_23; x_17 = lean_ctor_get(x_8, 1); lean_inc(x_17); lean_dec(x_8); x_18 = l_Lean_Server_chainLspRequestHandler___lambda__3___closed__1; x_19 = lean_string_append(x_18, x_1); lean_dec(x_1); x_20 = l_Lean_Server_chainLspRequestHandler___lambda__3___closed__2; x_21 = lean_string_append(x_19, x_20); x_22 = lean_alloc_ctor(18, 1, 0); lean_ctor_set(x_22, 0, x_21); x_23 = lean_alloc_ctor(1, 2, 0); lean_ctor_set(x_23, 0, x_22); lean_ctor_set(x_23, 1, x_17); return x_23; } } else { lean_object* x_24; lean_object* x_25; lean_object* x_26; lean_object* x_27; lean_object* x_28; lean_object* x_29; lean_object* x_30; uint8_t x_31; x_24 = lean_ctor_get(x_8, 1); lean_inc(x_24); lean_dec(x_8); x_25 = lean_ctor_get(x_9, 0); lean_inc(x_25); lean_dec(x_9); lean_inc(x_1); lean_inc(x_25); x_26 = lean_alloc_closure((void*)(l_Lean_Server_chainLspRequestHandler___lambda__2), 9, 6); lean_closure_set(x_26, 0, x_25); lean_closure_set(x_26, 1, x_2); lean_closure_set(x_26, 2, x_1); lean_closure_set(x_26, 3, x_3); lean_closure_set(x_26, 4, x_4); lean_closure_set(x_26, 5, x_5); x_27 = l_Lean_Server_registerLspRequestHandler___lambda__3___closed__1; x_28 = lean_st_ref_take(x_27, x_24); x_29 = lean_ctor_get(x_28, 0); lean_inc(x_29); x_30 = lean_ctor_get(x_28, 1); lean_inc(x_30); lean_dec(x_28); x_31 = !lean_is_exclusive(x_25); if (x_31 == 0) { lean_object* x_32; lean_object* x_33; lean_object* x_34; uint8_t x_35; x_32 = lean_ctor_get(x_25, 1); lean_dec(x_32); lean_ctor_set(x_25, 1, x_26); x_33 = l_Lean_PersistentHashMap_insert___at_Lean_Server_registerLspRequestHandler___spec__2(x_29, x_1, x_25); x_34 = lean_st_ref_set(x_27, x_33, x_30); x_35 = !lean_is_exclusive(x_34); if (x_35 == 0) { return x_34; } else { lean_object* x_36; lean_object* x_37; lean_object* x_38; x_36 = lean_ctor_get(x_34, 0); x_37 = lean_ctor_get(x_34, 1); lean_inc(x_37); lean_inc(x_36); lean_dec(x_34); x_38 = lean_alloc_ctor(0, 2, 0); lean_ctor_set(x_38, 0, x_36); lean_ctor_set(x_38, 1, x_37); return x_38; } } else { lean_object* x_39; lean_object* x_40; lean_object* x_41; lean_object* x_42; lean_object* x_43; lean_object* x_44; lean_object* x_45; lean_object* x_46; x_39 = lean_ctor_get(x_25, 0); lean_inc(x_39); lean_dec(x_25); x_40 = lean_alloc_ctor(0, 2, 0); lean_ctor_set(x_40, 0, x_39); lean_ctor_set(x_40, 1, x_26); x_41 = l_Lean_PersistentHashMap_insert___at_Lean_Server_registerLspRequestHandler___spec__2(x_29, x_1, x_40); x_42 = lean_st_ref_set(x_27, x_41, x_30); x_43 = lean_ctor_get(x_42, 0); lean_inc(x_43); x_44 = lean_ctor_get(x_42, 1); lean_inc(x_44); if (lean_is_exclusive(x_42)) { lean_ctor_release(x_42, 0); lean_ctor_release(x_42, 1); x_45 = x_42; } else { lean_dec_ref(x_42); x_45 = lean_box(0); } if (lean_is_scalar(x_45)) { x_46 = lean_alloc_ctor(0, 2, 0); } else { x_46 = x_45; } lean_ctor_set(x_46, 0, x_43); lean_ctor_set(x_46, 1, x_44); return x_46; } } } } LEAN_EXPORT lean_object* l_Lean_Server_chainLspRequestHandler(lean_object* x_1, lean_object* x_2, lean_object* x_3, lean_object* x_4, lean_object* x_5, lean_object* x_6, lean_object* x_7, lean_object* x_8) { _start: { lean_object* x_9; lean_object* x_10; uint8_t x_11; x_9 = l_Lean_initializing(x_8); x_10 = lean_ctor_get(x_9, 0); lean_inc(x_10); x_11 = lean_unbox(x_10); lean_dec(x_10); if (x_11 == 0) { uint8_t x_12; lean_dec(x_7); lean_dec(x_6); lean_dec(x_5); lean_dec(x_3); x_12 = !lean_is_exclusive(x_9); if (x_12 == 0) { lean_object* x_13; lean_object* x_14; lean_object* x_15; lean_object* x_16; lean_object* x_17; lean_object* x_18; x_13 = lean_ctor_get(x_9, 0); lean_dec(x_13); x_14 = l_Lean_Server_chainLspRequestHandler___lambda__3___closed__1; x_15 = lean_string_append(x_14, x_1); lean_dec(x_1); x_16 = l_Lean_Server_registerLspRequestHandler___closed__1; x_17 = lean_string_append(x_15, x_16); x_18 = lean_alloc_ctor(18, 1, 0); lean_ctor_set(x_18, 0, x_17); lean_ctor_set_tag(x_9, 1); lean_ctor_set(x_9, 0, x_18); return x_9; } else { lean_object* x_19; lean_object* x_20; lean_object* x_21; lean_object* x_22; lean_object* x_23; lean_object* x_24; lean_object* x_25; x_19 = lean_ctor_get(x_9, 1); lean_inc(x_19); lean_dec(x_9); x_20 = l_Lean_Server_chainLspRequestHandler___lambda__3___closed__1; x_21 = lean_string_append(x_20, x_1); lean_dec(x_1); x_22 = l_Lean_Server_registerLspRequestHandler___closed__1; x_23 = lean_string_append(x_21, x_22); x_24 = lean_alloc_ctor(18, 1, 0); lean_ctor_set(x_24, 0, x_23); x_25 = lean_alloc_ctor(1, 2, 0); lean_ctor_set(x_25, 0, x_24); lean_ctor_set(x_25, 1, x_19); return x_25; } } else { lean_object* x_26; lean_object* x_27; lean_object* x_28; x_26 = lean_ctor_get(x_9, 1); lean_inc(x_26); lean_dec(x_9); x_27 = lean_box(0); x_28 = l_Lean_Server_chainLspRequestHandler___lambda__3(x_1, x_5, x_3, x_7, x_6, x_27, x_26); return x_28; } } } LEAN_EXPORT lean_object* l_liftExcept___at_Lean_Server_chainLspRequestHandler___spec__1___rarg___boxed(lean_object* x_1, lean_object* x_2, lean_object* x_3) { _start: { lean_object* x_4; x_4 = l_liftExcept___at_Lean_Server_chainLspRequestHandler___spec__1___rarg(x_1, x_2, x_3); lean_dec(x_2); lean_dec(x_1); return x_4; } } LEAN_EXPORT lean_object* l_Lean_Server_chainLspRequestHandler___lambda__1___boxed(lean_object* x_1, lean_object* x_2, lean_object* x_3) { _start: { lean_object* x_4; x_4 = l_Lean_Server_chainLspRequestHandler___lambda__1(x_1, x_2, x_3); lean_dec(x_2); return x_4; } } LEAN_EXPORT lean_object* l_Lean_Server_chainLspRequestHandler___lambda__3___boxed(lean_object* x_1, lean_object* x_2, lean_object* x_3, lean_object* x_4, lean_object* x_5, lean_object* x_6, lean_object* x_7) { _start: { lean_object* x_8; x_8 = l_Lean_Server_chainLspRequestHandler___lambda__3(x_1, x_2, x_3, x_4, x_5, x_6, x_7); lean_dec(x_6); return x_8; } } LEAN_EXPORT lean_object* l_Lean_Server_routeLspRequest(lean_object* x_1, lean_object* x_2, lean_object* x_3) { _start: { lean_object* x_4; lean_object* x_5; lean_inc(x_1); x_4 = l_Lean_Server_lookupLspRequestHandler(x_1, x_3); x_5 = lean_ctor_get(x_4, 0); lean_inc(x_5); if (lean_obj_tag(x_5) == 0) { uint8_t x_6; lean_dec(x_2); x_6 = !lean_is_exclusive(x_4); if (x_6 == 0) { lean_object* x_7; lean_object* x_8; lean_object* x_9; x_7 = lean_ctor_get(x_4, 0); lean_dec(x_7); x_8 = l_Lean_Server_RequestError_methodNotFound(x_1); lean_dec(x_1); x_9 = lean_alloc_ctor(0, 1, 0); lean_ctor_set(x_9, 0, x_8); lean_ctor_set(x_4, 0, x_9); return x_4; } else { lean_object* x_10; lean_object* x_11; lean_object* x_12; lean_object* x_13; x_10 = lean_ctor_get(x_4, 1); lean_inc(x_10); lean_dec(x_4); x_11 = l_Lean_Server_RequestError_methodNotFound(x_1); lean_dec(x_1); x_12 = lean_alloc_ctor(0, 1, 0); lean_ctor_set(x_12, 0, x_11); x_13 = lean_alloc_ctor(0, 2, 0); lean_ctor_set(x_13, 0, x_12); lean_ctor_set(x_13, 1, x_10); return x_13; } } else { uint8_t x_14; lean_dec(x_1); x_14 = !lean_is_exclusive(x_4); if (x_14 == 0) { lean_object* x_15; lean_object* x_16; lean_object* x_17; lean_object* x_18; x_15 = lean_ctor_get(x_4, 0); lean_dec(x_15); x_16 = lean_ctor_get(x_5, 0); lean_inc(x_16); lean_dec(x_5); x_17 = lean_ctor_get(x_16, 0); lean_inc(x_17); lean_dec(x_16); x_18 = lean_apply_1(x_17, x_2); lean_ctor_set(x_4, 0, x_18); return x_4; } else { lean_object* x_19; lean_object* x_20; lean_object* x_21; lean_object* x_22; lean_object* x_23; x_19 = lean_ctor_get(x_4, 1); lean_inc(x_19); lean_dec(x_4); x_20 = lean_ctor_get(x_5, 0); lean_inc(x_20); lean_dec(x_5); x_21 = lean_ctor_get(x_20, 0); lean_inc(x_21); lean_dec(x_20); x_22 = lean_apply_1(x_21, x_2); x_23 = lean_alloc_ctor(0, 2, 0); lean_ctor_set(x_23, 0, x_22); lean_ctor_set(x_23, 1, x_19); return x_23; } } } } static lean_object* _init_l_Lean_Server_handleLspRequest___closed__1() { _start: { lean_object* x_1; x_1 = lean_mk_string_from_bytes("request '", 9); return x_1; } } static lean_object* _init_l_Lean_Server_handleLspRequest___closed__2() { _start: { lean_object* x_1; x_1 = lean_mk_string_from_bytes("' routed through watchdog but unknown in worker; are both using the same plugins?", 81); return x_1; } } LEAN_EXPORT lean_object* l_Lean_Server_handleLspRequest(lean_object* x_1, lean_object* x_2, lean_object* x_3, lean_object* x_4) { _start: { lean_object* x_5; lean_object* x_6; lean_inc(x_1); x_5 = l_Lean_Server_lookupLspRequestHandler(x_1, x_4); x_6 = lean_ctor_get(x_5, 0); lean_inc(x_6); if (lean_obj_tag(x_6) == 0) { uint8_t x_7; lean_dec(x_3); lean_dec(x_2); x_7 = !lean_is_exclusive(x_5); if (x_7 == 0) { lean_object* x_8; lean_object* x_9; lean_object* x_10; lean_object* x_11; lean_object* x_12; uint8_t x_13; lean_object* x_14; x_8 = lean_ctor_get(x_5, 0); lean_dec(x_8); x_9 = l_Lean_Server_handleLspRequest___closed__1; x_10 = lean_string_append(x_9, x_1); lean_dec(x_1); x_11 = l_Lean_Server_handleLspRequest___closed__2; x_12 = lean_string_append(x_10, x_11); x_13 = 4; x_14 = lean_alloc_ctor(0, 1, 1); lean_ctor_set(x_14, 0, x_12); lean_ctor_set_uint8(x_14, sizeof(void*)*1, x_13); lean_ctor_set_tag(x_5, 1); lean_ctor_set(x_5, 0, x_14); return x_5; } else { lean_object* x_15; lean_object* x_16; lean_object* x_17; lean_object* x_18; lean_object* x_19; uint8_t x_20; lean_object* x_21; lean_object* x_22; x_15 = lean_ctor_get(x_5, 1); lean_inc(x_15); lean_dec(x_5); x_16 = l_Lean_Server_handleLspRequest___closed__1; x_17 = lean_string_append(x_16, x_1); lean_dec(x_1); x_18 = l_Lean_Server_handleLspRequest___closed__2; x_19 = lean_string_append(x_17, x_18); x_20 = 4; x_21 = lean_alloc_ctor(0, 1, 1); lean_ctor_set(x_21, 0, x_19); lean_ctor_set_uint8(x_21, sizeof(void*)*1, x_20); x_22 = lean_alloc_ctor(1, 2, 0); lean_ctor_set(x_22, 0, x_21); lean_ctor_set(x_22, 1, x_15); return x_22; } } else { lean_object* x_23; lean_object* x_24; lean_object* x_25; lean_object* x_26; lean_dec(x_1); x_23 = lean_ctor_get(x_5, 1); lean_inc(x_23); lean_dec(x_5); x_24 = lean_ctor_get(x_6, 0); lean_inc(x_24); lean_dec(x_6); x_25 = lean_ctor_get(x_24, 1); lean_inc(x_25); lean_dec(x_24); x_26 = lean_apply_3(x_25, x_2, x_3, x_23); return x_26; } } } lean_object* initialize_Init(uint8_t builtin, lean_object*); lean_object* initialize_Lean_DeclarationRange(uint8_t builtin, lean_object*); lean_object* initialize_Lean_Data_Json(uint8_t builtin, lean_object*); lean_object* initialize_Lean_Data_Lsp(uint8_t builtin, lean_object*); lean_object* initialize_Lean_Elab_Command(uint8_t builtin, lean_object*); lean_object* initialize_Lean_Server_FileSource(uint8_t builtin, lean_object*); lean_object* initialize_Lean_Server_FileWorker_Utils(uint8_t builtin, lean_object*); lean_object* initialize_Lean_Server_Rpc_Basic(uint8_t builtin, lean_object*); static bool _G_initialized = false; LEAN_EXPORT lean_object* initialize_Lean_Server_Requests(uint8_t builtin, lean_object* w) { lean_object * res; if (_G_initialized) return lean_io_result_mk_ok(lean_box(0)); _G_initialized = true; res = initialize_Init(builtin, lean_io_mk_world()); if (lean_io_result_is_error(res)) return res; lean_dec_ref(res); res = initialize_Lean_DeclarationRange(builtin, lean_io_mk_world()); if (lean_io_result_is_error(res)) return res; lean_dec_ref(res); res = initialize_Lean_Data_Json(builtin, lean_io_mk_world()); if (lean_io_result_is_error(res)) return res; lean_dec_ref(res); res = initialize_Lean_Data_Lsp(builtin, lean_io_mk_world()); if (lean_io_result_is_error(res)) return res; lean_dec_ref(res); res = initialize_Lean_Elab_Command(builtin, lean_io_mk_world()); if (lean_io_result_is_error(res)) return res; lean_dec_ref(res); res = initialize_Lean_Server_FileSource(builtin, lean_io_mk_world()); if (lean_io_result_is_error(res)) return res; lean_dec_ref(res); res = initialize_Lean_Server_FileWorker_Utils(builtin, lean_io_mk_world()); if (lean_io_result_is_error(res)) return res; lean_dec_ref(res); res = initialize_Lean_Server_Rpc_Basic(builtin, lean_io_mk_world()); if (lean_io_result_is_error(res)) return res; lean_dec_ref(res); l_Lean_Server_instInhabitedRequestError___closed__1 = _init_l_Lean_Server_instInhabitedRequestError___closed__1(); lean_mark_persistent(l_Lean_Server_instInhabitedRequestError___closed__1); l_Lean_Server_instInhabitedRequestError___closed__2 = _init_l_Lean_Server_instInhabitedRequestError___closed__2(); lean_mark_persistent(l_Lean_Server_instInhabitedRequestError___closed__2); l_Lean_Server_instInhabitedRequestError = _init_l_Lean_Server_instInhabitedRequestError(); lean_mark_persistent(l_Lean_Server_instInhabitedRequestError); l_Lean_Server_RequestError_fileChanged___closed__1 = _init_l_Lean_Server_RequestError_fileChanged___closed__1(); lean_mark_persistent(l_Lean_Server_RequestError_fileChanged___closed__1); l_Lean_Server_RequestError_fileChanged___closed__2 = _init_l_Lean_Server_RequestError_fileChanged___closed__2(); lean_mark_persistent(l_Lean_Server_RequestError_fileChanged___closed__2); l_Lean_Server_RequestError_fileChanged = _init_l_Lean_Server_RequestError_fileChanged(); lean_mark_persistent(l_Lean_Server_RequestError_fileChanged); l_Lean_Server_RequestError_methodNotFound___closed__1 = _init_l_Lean_Server_RequestError_methodNotFound___closed__1(); lean_mark_persistent(l_Lean_Server_RequestError_methodNotFound___closed__1); l_Lean_Server_RequestError_methodNotFound___closed__2 = _init_l_Lean_Server_RequestError_methodNotFound___closed__2(); lean_mark_persistent(l_Lean_Server_RequestError_methodNotFound___closed__2); l_Lean_Server_parseRequestParams___rarg___closed__1 = _init_l_Lean_Server_parseRequestParams___rarg___closed__1(); lean_mark_persistent(l_Lean_Server_parseRequestParams___rarg___closed__1); l_Lean_Server_parseRequestParams___rarg___closed__2 = _init_l_Lean_Server_parseRequestParams___rarg___closed__2(); lean_mark_persistent(l_Lean_Server_parseRequestParams___rarg___closed__2); l_Lean_Server_RequestM_withWaitFindSnapAtPos___rarg___closed__1 = _init_l_Lean_Server_RequestM_withWaitFindSnapAtPos___rarg___closed__1(); lean_mark_persistent(l_Lean_Server_RequestM_withWaitFindSnapAtPos___rarg___closed__1); l_Lean_Server_RequestM_withWaitFindSnapAtPos___rarg___closed__2 = _init_l_Lean_Server_RequestM_withWaitFindSnapAtPos___rarg___closed__2(); lean_mark_persistent(l_Lean_Server_RequestM_withWaitFindSnapAtPos___rarg___closed__2); l_Lean_Server_RequestM_withWaitFindSnapAtPos___rarg___closed__3 = _init_l_Lean_Server_RequestM_withWaitFindSnapAtPos___rarg___closed__3(); lean_mark_persistent(l_Lean_Server_RequestM_withWaitFindSnapAtPos___rarg___closed__3); l_Lean_Server_RequestM_withWaitFindSnapAtPos___rarg___closed__4 = _init_l_Lean_Server_RequestM_withWaitFindSnapAtPos___rarg___closed__4(); lean_mark_persistent(l_Lean_Server_RequestM_withWaitFindSnapAtPos___rarg___closed__4); l_Lean_Server_RequestM_withWaitFindSnapAtPos___rarg___closed__5 = _init_l_Lean_Server_RequestM_withWaitFindSnapAtPos___rarg___closed__5(); lean_mark_persistent(l_Lean_Server_RequestM_withWaitFindSnapAtPos___rarg___closed__5); l_Lean_Server_initFn____x40_Lean_Server_Requests___hyg_1811____closed__1 = _init_l_Lean_Server_initFn____x40_Lean_Server_Requests___hyg_1811____closed__1(); lean_mark_persistent(l_Lean_Server_initFn____x40_Lean_Server_Requests___hyg_1811____closed__1); l_Lean_Server_initFn____x40_Lean_Server_Requests___hyg_1811____closed__2 = _init_l_Lean_Server_initFn____x40_Lean_Server_Requests___hyg_1811____closed__2(); lean_mark_persistent(l_Lean_Server_initFn____x40_Lean_Server_Requests___hyg_1811____closed__2); l_Lean_Server_initFn____x40_Lean_Server_Requests___hyg_1811____closed__3 = _init_l_Lean_Server_initFn____x40_Lean_Server_Requests___hyg_1811____closed__3(); lean_mark_persistent(l_Lean_Server_initFn____x40_Lean_Server_Requests___hyg_1811____closed__3); l_Lean_Server_initFn____x40_Lean_Server_Requests___hyg_1811____closed__4 = _init_l_Lean_Server_initFn____x40_Lean_Server_Requests___hyg_1811____closed__4(); lean_mark_persistent(l_Lean_Server_initFn____x40_Lean_Server_Requests___hyg_1811____closed__4); l_Lean_Server_initFn____x40_Lean_Server_Requests___hyg_1811____closed__5 = _init_l_Lean_Server_initFn____x40_Lean_Server_Requests___hyg_1811____closed__5(); lean_mark_persistent(l_Lean_Server_initFn____x40_Lean_Server_Requests___hyg_1811____closed__5); if (builtin) {res = l_Lean_Server_initFn____x40_Lean_Server_Requests___hyg_1811_(lean_io_mk_world()); if (lean_io_result_is_error(res)) return res; l_Lean_Server_requestHandlers = lean_io_result_get_value(res); lean_mark_persistent(l_Lean_Server_requestHandlers); lean_dec_ref(res); }l_Lean_PersistentHashMap_insertAux___at_Lean_Server_registerLspRequestHandler___spec__3___closed__1 = _init_l_Lean_PersistentHashMap_insertAux___at_Lean_Server_registerLspRequestHandler___spec__3___closed__1(); l_Lean_PersistentHashMap_insertAux___at_Lean_Server_registerLspRequestHandler___spec__3___closed__2 = _init_l_Lean_PersistentHashMap_insertAux___at_Lean_Server_registerLspRequestHandler___spec__3___closed__2(); l_Lean_PersistentHashMap_insertAux___at_Lean_Server_registerLspRequestHandler___spec__3___closed__3 = _init_l_Lean_PersistentHashMap_insertAux___at_Lean_Server_registerLspRequestHandler___spec__3___closed__3(); lean_mark_persistent(l_Lean_PersistentHashMap_insertAux___at_Lean_Server_registerLspRequestHandler___spec__3___closed__3); l_Lean_Server_registerLspRequestHandler___lambda__3___closed__1 = _init_l_Lean_Server_registerLspRequestHandler___lambda__3___closed__1(); lean_mark_persistent(l_Lean_Server_registerLspRequestHandler___lambda__3___closed__1); l_Lean_Server_registerLspRequestHandler___lambda__4___closed__1 = _init_l_Lean_Server_registerLspRequestHandler___lambda__4___closed__1(); lean_mark_persistent(l_Lean_Server_registerLspRequestHandler___lambda__4___closed__1); l_Lean_Server_registerLspRequestHandler___lambda__4___closed__2 = _init_l_Lean_Server_registerLspRequestHandler___lambda__4___closed__2(); lean_mark_persistent(l_Lean_Server_registerLspRequestHandler___lambda__4___closed__2); l_Lean_Server_registerLspRequestHandler___closed__1 = _init_l_Lean_Server_registerLspRequestHandler___closed__1(); lean_mark_persistent(l_Lean_Server_registerLspRequestHandler___closed__1); l_Lean_Server_chainLspRequestHandler___lambda__1___closed__1 = _init_l_Lean_Server_chainLspRequestHandler___lambda__1___closed__1(); lean_mark_persistent(l_Lean_Server_chainLspRequestHandler___lambda__1___closed__1); l_Lean_Server_chainLspRequestHandler___lambda__1___closed__2 = _init_l_Lean_Server_chainLspRequestHandler___lambda__1___closed__2(); lean_mark_persistent(l_Lean_Server_chainLspRequestHandler___lambda__1___closed__2); l_Lean_Server_chainLspRequestHandler___lambda__3___closed__1 = _init_l_Lean_Server_chainLspRequestHandler___lambda__3___closed__1(); lean_mark_persistent(l_Lean_Server_chainLspRequestHandler___lambda__3___closed__1); l_Lean_Server_chainLspRequestHandler___lambda__3___closed__2 = _init_l_Lean_Server_chainLspRequestHandler___lambda__3___closed__2(); lean_mark_persistent(l_Lean_Server_chainLspRequestHandler___lambda__3___closed__2); l_Lean_Server_handleLspRequest___closed__1 = _init_l_Lean_Server_handleLspRequest___closed__1(); lean_mark_persistent(l_Lean_Server_handleLspRequest___closed__1); l_Lean_Server_handleLspRequest___closed__2 = _init_l_Lean_Server_handleLspRequest___closed__2(); lean_mark_persistent(l_Lean_Server_handleLspRequest___closed__2); return lean_io_result_mk_ok(lean_box(0)); } #ifdef __cplusplus } #endif
239c8ba920a24481bbbbfbec32957cb4e646d05f
d3c958632858e84bedcce26d6245f93328fdbced
/tests/kvm-unit-tests/x86/svm.c
25ac0ce4a6452d320b589bf02abee53946d949ba
[ "GPL-2.0-only", "LGPL-2.0-only", "BSD-2-Clause", "LicenseRef-scancode-unknown-license-reference" ]
permissive
copy/v86
0cf989542ca0634dc40927da9b0d3c0932c0e361
b8a39b11dd2076870699e6cac053556271b9bfab
refs/heads/master
2023-08-17T02:32:24.107665
2023-08-06T20:54:51
2023-08-06T20:54:51
14,158,237
17,313
1,555
BSD-2-Clause
2023-09-14T19:35:47
2013-11-06T00:12:12
Rust
UTF-8
C
false
false
26,692
c
svm.c
#include "svm.h" #include "libcflat.h" #include "processor.h" #include "desc.h" #include "msr.h" #include "vm.h" #include "smp.h" #include "types.h" /* for the nested page table*/ u64 *pml4e; u64 *pdpe; u64 *pde[4]; u64 *pte[2048]; void *scratch_page; #define LATENCY_RUNS 1000000 u64 tsc_start; u64 tsc_end; u64 vmrun_sum, vmexit_sum; u64 vmsave_sum, vmload_sum; u64 stgi_sum, clgi_sum; u64 latvmrun_max; u64 latvmrun_min; u64 latvmexit_max; u64 latvmexit_min; u64 latvmload_max; u64 latvmload_min; u64 latvmsave_max; u64 latvmsave_min; u64 latstgi_max; u64 latstgi_min; u64 latclgi_max; u64 latclgi_min; u64 runs; u8 *io_bitmap; u8 io_bitmap_area[16384]; static bool npt_supported(void) { return cpuid(0x8000000A).d & 1; } static void setup_svm(void) { void *hsave = alloc_page(); u64 *page, address; int i,j; wrmsr(MSR_VM_HSAVE_PA, virt_to_phys(hsave)); wrmsr(MSR_EFER, rdmsr(MSR_EFER) | EFER_SVME); wrmsr(MSR_EFER, rdmsr(MSR_EFER) | EFER_NX); scratch_page = alloc_page(); io_bitmap = (void *) (((ulong)io_bitmap_area + 4095) & ~4095); if (!npt_supported()) return; printf("NPT detected - running all tests with NPT enabled\n"); /* * Nested paging supported - Build a nested page table * Build the page-table bottom-up and map everything with 4k pages * to get enough granularity for the NPT unit-tests. */ address = 0; /* PTE level */ for (i = 0; i < 2048; ++i) { page = alloc_page(); for (j = 0; j < 512; ++j, address += 4096) page[j] = address | 0x067ULL; pte[i] = page; } /* PDE level */ for (i = 0; i < 4; ++i) { page = alloc_page(); for (j = 0; j < 512; ++j) page[j] = (u64)pte[(i * 512) + j] | 0x027ULL; pde[i] = page; } /* PDPe level */ pdpe = alloc_page(); for (i = 0; i < 4; ++i) pdpe[i] = ((u64)(pde[i])) | 0x27; /* PML4e level */ pml4e = alloc_page(); pml4e[0] = ((u64)pdpe) | 0x27; } static u64 *npt_get_pde(u64 address) { int i1, i2; address >>= 21; i1 = (address >> 9) & 0x3; i2 = address & 0x1ff; return &pde[i1][i2]; } static u64 *npt_get_pte(u64 address) { int i1, i2; address >>= 12; i1 = (address >> 9) & 0x7ff; i2 = address & 0x1ff; return &pte[i1][i2]; } static void vmcb_set_seg(struct vmcb_seg *seg, u16 selector, u64 base, u32 limit, u32 attr) { seg->selector = selector; seg->attrib = attr; seg->limit = limit; seg->base = base; } static void vmcb_ident(struct vmcb *vmcb) { u64 vmcb_phys = virt_to_phys(vmcb); struct vmcb_save_area *save = &vmcb->save; struct vmcb_control_area *ctrl = &vmcb->control; u32 data_seg_attr = 3 | SVM_SELECTOR_S_MASK | SVM_SELECTOR_P_MASK | SVM_SELECTOR_DB_MASK | SVM_SELECTOR_G_MASK; u32 code_seg_attr = 9 | SVM_SELECTOR_S_MASK | SVM_SELECTOR_P_MASK | SVM_SELECTOR_L_MASK | SVM_SELECTOR_G_MASK; struct descriptor_table_ptr desc_table_ptr; memset(vmcb, 0, sizeof(*vmcb)); asm volatile ("vmsave" : : "a"(vmcb_phys) : "memory"); vmcb_set_seg(&save->es, read_es(), 0, -1U, data_seg_attr); vmcb_set_seg(&save->cs, read_cs(), 0, -1U, code_seg_attr); vmcb_set_seg(&save->ss, read_ss(), 0, -1U, data_seg_attr); vmcb_set_seg(&save->ds, read_ds(), 0, -1U, data_seg_attr); sgdt(&desc_table_ptr); vmcb_set_seg(&save->gdtr, 0, desc_table_ptr.base, desc_table_ptr.limit, 0); sidt(&desc_table_ptr); vmcb_set_seg(&save->idtr, 0, desc_table_ptr.base, desc_table_ptr.limit, 0); ctrl->asid = 1; save->cpl = 0; save->efer = rdmsr(MSR_EFER); save->cr4 = read_cr4(); save->cr3 = read_cr3(); save->cr0 = read_cr0(); save->dr7 = read_dr7(); save->dr6 = read_dr6(); save->cr2 = read_cr2(); save->g_pat = rdmsr(MSR_IA32_CR_PAT); save->dbgctl = rdmsr(MSR_IA32_DEBUGCTLMSR); ctrl->intercept = (1ULL << INTERCEPT_VMRUN) | (1ULL << INTERCEPT_VMMCALL); ctrl->iopm_base_pa = virt_to_phys(io_bitmap); if (npt_supported()) { ctrl->nested_ctl = 1; ctrl->nested_cr3 = (u64)pml4e; } } struct test { const char *name; bool (*supported)(void); void (*prepare)(struct test *test); void (*guest_func)(struct test *test); bool (*finished)(struct test *test); bool (*succeeded)(struct test *test); struct vmcb *vmcb; int exits; ulong scratch; }; static inline void vmmcall(void) { asm volatile ("vmmcall" : : : "memory"); } static void test_thunk(struct test *test) { test->guest_func(test); vmmcall(); } struct regs { u64 rax; u64 rcx; u64 rdx; u64 rbx; u64 cr2; u64 rbp; u64 rsi; u64 rdi; u64 r8; u64 r9; u64 r10; u64 r11; u64 r12; u64 r13; u64 r14; u64 r15; u64 rflags; }; struct regs regs; // rax handled specially below #define SAVE_GPR_C \ "xchg %%rbx, regs+0x8\n\t" \ "xchg %%rcx, regs+0x10\n\t" \ "xchg %%rdx, regs+0x18\n\t" \ "xchg %%rbp, regs+0x28\n\t" \ "xchg %%rsi, regs+0x30\n\t" \ "xchg %%rdi, regs+0x38\n\t" \ "xchg %%r8, regs+0x40\n\t" \ "xchg %%r9, regs+0x48\n\t" \ "xchg %%r10, regs+0x50\n\t" \ "xchg %%r11, regs+0x58\n\t" \ "xchg %%r12, regs+0x60\n\t" \ "xchg %%r13, regs+0x68\n\t" \ "xchg %%r14, regs+0x70\n\t" \ "xchg %%r15, regs+0x78\n\t" #define LOAD_GPR_C SAVE_GPR_C static void test_run(struct test *test, struct vmcb *vmcb) { u64 vmcb_phys = virt_to_phys(vmcb); u64 guest_stack[10000]; test->vmcb = vmcb; test->prepare(test); vmcb->save.rip = (ulong)test_thunk; vmcb->save.rsp = (ulong)(guest_stack + ARRAY_SIZE(guest_stack)); regs.rdi = (ulong)test; do { tsc_start = rdtsc(); asm volatile ( "clgi \n\t" "vmload \n\t" "mov regs+0x80, %%r15\n\t" // rflags "mov %%r15, 0x170(%0)\n\t" "mov regs, %%r15\n\t" // rax "mov %%r15, 0x1f8(%0)\n\t" LOAD_GPR_C "vmrun \n\t" SAVE_GPR_C "mov 0x170(%0), %%r15\n\t" // rflags "mov %%r15, regs+0x80\n\t" "mov 0x1f8(%0), %%r15\n\t" // rax "mov %%r15, regs\n\t" "vmsave \n\t" "stgi" : : "a"(vmcb_phys) : "rbx", "rcx", "rdx", "rsi", "r8", "r9", "r10", "r11" , "r12", "r13", "r14", "r15", "memory"); tsc_end = rdtsc(); ++test->exits; } while (!test->finished(test)); report("%s", test->succeeded(test), test->name); } static bool smp_supported(void) { return cpu_count() > 1; } static bool default_supported(void) { return true; } static void default_prepare(struct test *test) { vmcb_ident(test->vmcb); cli(); } static bool default_finished(struct test *test) { return true; /* one vmexit */ } static void null_test(struct test *test) { } static bool null_check(struct test *test) { return test->vmcb->control.exit_code == SVM_EXIT_VMMCALL; } static void prepare_no_vmrun_int(struct test *test) { test->vmcb->control.intercept &= ~(1ULL << INTERCEPT_VMRUN); } static bool check_no_vmrun_int(struct test *test) { return test->vmcb->control.exit_code == SVM_EXIT_ERR; } static void test_vmrun(struct test *test) { asm volatile ("vmrun" : : "a"(virt_to_phys(test->vmcb))); } static bool check_vmrun(struct test *test) { return test->vmcb->control.exit_code == SVM_EXIT_VMRUN; } static void prepare_cr3_intercept(struct test *test) { default_prepare(test); test->vmcb->control.intercept_cr_read |= 1 << 3; } static void test_cr3_intercept(struct test *test) { asm volatile ("mov %%cr3, %0" : "=r"(test->scratch) : : "memory"); } static bool check_cr3_intercept(struct test *test) { return test->vmcb->control.exit_code == SVM_EXIT_READ_CR3; } static bool check_cr3_nointercept(struct test *test) { return null_check(test) && test->scratch == read_cr3(); } static void corrupt_cr3_intercept_bypass(void *_test) { struct test *test = _test; extern volatile u32 mmio_insn; while (!__sync_bool_compare_and_swap(&test->scratch, 1, 2)) pause(); pause(); pause(); pause(); mmio_insn = 0x90d8200f; // mov %cr3, %rax; nop } static void prepare_cr3_intercept_bypass(struct test *test) { default_prepare(test); test->vmcb->control.intercept_cr_read |= 1 << 3; on_cpu_async(1, corrupt_cr3_intercept_bypass, test); } static void test_cr3_intercept_bypass(struct test *test) { ulong a = 0xa0000; test->scratch = 1; while (test->scratch != 2) barrier(); asm volatile ("mmio_insn: mov %0, (%0); nop" : "+a"(a) : : "memory"); test->scratch = a; } static bool next_rip_supported(void) { return (cpuid(SVM_CPUID_FUNC).d & 8); } static void prepare_next_rip(struct test *test) { test->vmcb->control.intercept |= (1ULL << INTERCEPT_RDTSC); } static void test_next_rip(struct test *test) { asm volatile ("rdtsc\n\t" ".globl exp_next_rip\n\t" "exp_next_rip:\n\t" ::: "eax", "edx"); } static bool check_next_rip(struct test *test) { extern char exp_next_rip; unsigned long address = (unsigned long)&exp_next_rip; return address == test->vmcb->control.next_rip; } static void prepare_mode_switch(struct test *test) { test->vmcb->control.intercept_exceptions |= (1ULL << GP_VECTOR) | (1ULL << UD_VECTOR) | (1ULL << DF_VECTOR) | (1ULL << PF_VECTOR); test->scratch = 0; } static void test_mode_switch(struct test *test) { asm volatile(" cli\n" " ljmp *1f\n" /* jump to 32-bit code segment */ "1:\n" " .long 2f\n" " .long " xstr(KERNEL_CS32) "\n" ".code32\n" "2:\n" " movl %%cr0, %%eax\n" " btcl $31, %%eax\n" /* clear PG */ " movl %%eax, %%cr0\n" " movl $0xc0000080, %%ecx\n" /* EFER */ " rdmsr\n" " btcl $8, %%eax\n" /* clear LME */ " wrmsr\n" " movl %%cr4, %%eax\n" " btcl $5, %%eax\n" /* clear PAE */ " movl %%eax, %%cr4\n" " movw %[ds16], %%ax\n" " movw %%ax, %%ds\n" " ljmpl %[cs16], $3f\n" /* jump to 16 bit protected-mode */ ".code16\n" "3:\n" " movl %%cr0, %%eax\n" " btcl $0, %%eax\n" /* clear PE */ " movl %%eax, %%cr0\n" " ljmpl $0, $4f\n" /* jump to real-mode */ "4:\n" " vmmcall\n" " movl %%cr0, %%eax\n" " btsl $0, %%eax\n" /* set PE */ " movl %%eax, %%cr0\n" " ljmpl %[cs32], $5f\n" /* back to protected mode */ ".code32\n" "5:\n" " movl %%cr4, %%eax\n" " btsl $5, %%eax\n" /* set PAE */ " movl %%eax, %%cr4\n" " movl $0xc0000080, %%ecx\n" /* EFER */ " rdmsr\n" " btsl $8, %%eax\n" /* set LME */ " wrmsr\n" " movl %%cr0, %%eax\n" " btsl $31, %%eax\n" /* set PG */ " movl %%eax, %%cr0\n" " ljmpl %[cs64], $6f\n" /* back to long mode */ ".code64\n\t" "6:\n" " vmmcall\n" :: [cs16] "i"(KERNEL_CS16), [ds16] "i"(KERNEL_DS16), [cs32] "i"(KERNEL_CS32), [cs64] "i"(KERNEL_CS64) : "rax", "rbx", "rcx", "rdx", "memory"); } static bool mode_switch_finished(struct test *test) { u64 cr0, cr4, efer; cr0 = test->vmcb->save.cr0; cr4 = test->vmcb->save.cr4; efer = test->vmcb->save.efer; /* Only expect VMMCALL intercepts */ if (test->vmcb->control.exit_code != SVM_EXIT_VMMCALL) return true; /* Jump over VMMCALL instruction */ test->vmcb->save.rip += 3; /* Do sanity checks */ switch (test->scratch) { case 0: /* Test should be in real mode now - check for this */ if ((cr0 & 0x80000001) || /* CR0.PG, CR0.PE */ (cr4 & 0x00000020) || /* CR4.PAE */ (efer & 0x00000500)) /* EFER.LMA, EFER.LME */ return true; break; case 2: /* Test should be back in long-mode now - check for this */ if (((cr0 & 0x80000001) != 0x80000001) || /* CR0.PG, CR0.PE */ ((cr4 & 0x00000020) != 0x00000020) || /* CR4.PAE */ ((efer & 0x00000500) != 0x00000500)) /* EFER.LMA, EFER.LME */ return true; break; } /* one step forward */ test->scratch += 1; return test->scratch == 2; } static bool check_mode_switch(struct test *test) { return test->scratch == 2; } static void prepare_ioio(struct test *test) { test->vmcb->control.intercept |= (1ULL << INTERCEPT_IOIO_PROT); test->scratch = 0; memset(io_bitmap, 0, 8192); io_bitmap[8192] = 0xFF; } int get_test_stage(struct test *test) { barrier(); return test->scratch; } void inc_test_stage(struct test *test) { barrier(); test->scratch++; barrier(); } static void test_ioio(struct test *test) { // stage 0, test IO pass inb(0x5000); outb(0x0, 0x5000); if (get_test_stage(test) != 0) goto fail; // test IO width, in/out io_bitmap[0] = 0xFF; inc_test_stage(test); inb(0x0); if (get_test_stage(test) != 2) goto fail; outw(0x0, 0x0); if (get_test_stage(test) != 3) goto fail; inl(0x0); if (get_test_stage(test) != 4) goto fail; // test low/high IO port io_bitmap[0x5000 / 8] = (1 << (0x5000 % 8)); inb(0x5000); if (get_test_stage(test) != 5) goto fail; io_bitmap[0x9000 / 8] = (1 << (0x9000 % 8)); inw(0x9000); if (get_test_stage(test) != 6) goto fail; // test partial pass io_bitmap[0x5000 / 8] = (1 << (0x5000 % 8)); inl(0x4FFF); if (get_test_stage(test) != 7) goto fail; // test across pages inc_test_stage(test); inl(0x7FFF); if (get_test_stage(test) != 8) goto fail; inc_test_stage(test); io_bitmap[0x8000 / 8] = 1 << (0x8000 % 8); inl(0x7FFF); if (get_test_stage(test) != 10) goto fail; io_bitmap[0] = 0; inl(0xFFFF); if (get_test_stage(test) != 11) goto fail; io_bitmap[0] = 0xFF; io_bitmap[8192] = 0; inl(0xFFFF); inc_test_stage(test); if (get_test_stage(test) != 12) goto fail; return; fail: report("stage %d", false, get_test_stage(test)); test->scratch = -1; } static bool ioio_finished(struct test *test) { unsigned port, size; /* Only expect IOIO intercepts */ if (test->vmcb->control.exit_code == SVM_EXIT_VMMCALL) return true; if (test->vmcb->control.exit_code != SVM_EXIT_IOIO) return true; /* one step forward */ test->scratch += 1; port = test->vmcb->control.exit_info_1 >> 16; size = (test->vmcb->control.exit_info_1 >> SVM_IOIO_SIZE_SHIFT) & 7; while (size--) { io_bitmap[port / 8] &= ~(1 << (port & 7)); port++; } return false; } static bool check_ioio(struct test *test) { memset(io_bitmap, 0, 8193); return test->scratch != -1; } static void prepare_asid_zero(struct test *test) { test->vmcb->control.asid = 0; } static void test_asid_zero(struct test *test) { asm volatile ("vmmcall\n\t"); } static bool check_asid_zero(struct test *test) { return test->vmcb->control.exit_code == SVM_EXIT_ERR; } static void sel_cr0_bug_prepare(struct test *test) { vmcb_ident(test->vmcb); test->vmcb->control.intercept |= (1ULL << INTERCEPT_SELECTIVE_CR0); } static bool sel_cr0_bug_finished(struct test *test) { return true; } static void sel_cr0_bug_test(struct test *test) { unsigned long cr0; /* read cr0, clear CD, and write back */ cr0 = read_cr0(); cr0 |= (1UL << 30); write_cr0(cr0); /* * If we are here the test failed, not sure what to do now because we * are not in guest-mode anymore so we can't trigger an intercept. * Trigger a tripple-fault for now. */ report("sel_cr0 test. Can not recover from this - exiting", false); exit(report_summary()); } static bool sel_cr0_bug_check(struct test *test) { return test->vmcb->control.exit_code == SVM_EXIT_CR0_SEL_WRITE; } static void npt_nx_prepare(struct test *test) { u64 *pte; vmcb_ident(test->vmcb); pte = npt_get_pte((u64)null_test); *pte |= (1ULL << 63); } static bool npt_nx_check(struct test *test) { u64 *pte = npt_get_pte((u64)null_test); *pte &= ~(1ULL << 63); test->vmcb->save.efer |= (1 << 11); return (test->vmcb->control.exit_code == SVM_EXIT_NPF) && (test->vmcb->control.exit_info_1 == 0x100000015ULL); } static void npt_us_prepare(struct test *test) { u64 *pte; vmcb_ident(test->vmcb); pte = npt_get_pte((u64)scratch_page); *pte &= ~(1ULL << 2); } static void npt_us_test(struct test *test) { (void) *(volatile u64 *)scratch_page; } static bool npt_us_check(struct test *test) { u64 *pte = npt_get_pte((u64)scratch_page); *pte |= (1ULL << 2); return (test->vmcb->control.exit_code == SVM_EXIT_NPF) && (test->vmcb->control.exit_info_1 == 0x100000005ULL); } u64 save_pde; static void npt_rsvd_prepare(struct test *test) { u64 *pde; vmcb_ident(test->vmcb); pde = npt_get_pde((u64) null_test); save_pde = *pde; *pde = (1ULL << 19) | (1ULL << 7) | 0x27; } static bool npt_rsvd_check(struct test *test) { u64 *pde = npt_get_pde((u64) null_test); *pde = save_pde; return (test->vmcb->control.exit_code == SVM_EXIT_NPF) && (test->vmcb->control.exit_info_1 == 0x10000001dULL); } static void npt_rw_prepare(struct test *test) { u64 *pte; vmcb_ident(test->vmcb); pte = npt_get_pte(0x80000); *pte &= ~(1ULL << 1); } static void npt_rw_test(struct test *test) { u64 *data = (void*)(0x80000); *data = 0; } static bool npt_rw_check(struct test *test) { u64 *pte = npt_get_pte(0x80000); *pte |= (1ULL << 1); return (test->vmcb->control.exit_code == SVM_EXIT_NPF) && (test->vmcb->control.exit_info_1 == 0x100000007ULL); } static void npt_rw_pfwalk_prepare(struct test *test) { u64 *pte; vmcb_ident(test->vmcb); pte = npt_get_pte(read_cr3()); *pte &= ~(1ULL << 1); } static bool npt_rw_pfwalk_check(struct test *test) { u64 *pte = npt_get_pte(read_cr3()); *pte |= (1ULL << 1); return (test->vmcb->control.exit_code == SVM_EXIT_NPF) && (test->vmcb->control.exit_info_1 == 0x200000006ULL) && (test->vmcb->control.exit_info_2 == read_cr3()); } static void npt_rsvd_pfwalk_prepare(struct test *test) { vmcb_ident(test->vmcb); pdpe[0] |= (1ULL << 8); } static bool npt_rsvd_pfwalk_check(struct test *test) { pdpe[0] &= ~(1ULL << 8); return (test->vmcb->control.exit_code == SVM_EXIT_NPF) && (test->vmcb->control.exit_info_1 == 0x200000006ULL); } static void npt_l1mmio_prepare(struct test *test) { vmcb_ident(test->vmcb); } u32 nested_apic_version1; u32 nested_apic_version2; static void npt_l1mmio_test(struct test *test) { volatile u32 *data = (volatile void*)(0xfee00030UL); nested_apic_version1 = *data; nested_apic_version2 = *data; } static bool npt_l1mmio_check(struct test *test) { volatile u32 *data = (volatile void*)(0xfee00030); u32 lvr = *data; return nested_apic_version1 == lvr && nested_apic_version2 == lvr; } static void npt_rw_l1mmio_prepare(struct test *test) { u64 *pte; vmcb_ident(test->vmcb); pte = npt_get_pte(0xfee00080); *pte &= ~(1ULL << 1); } static void npt_rw_l1mmio_test(struct test *test) { volatile u32 *data = (volatile void*)(0xfee00080); *data = *data; } static bool npt_rw_l1mmio_check(struct test *test) { u64 *pte = npt_get_pte(0xfee00080); *pte |= (1ULL << 1); return (test->vmcb->control.exit_code == SVM_EXIT_NPF) && (test->vmcb->control.exit_info_1 == 0x100000007ULL); } static void latency_prepare(struct test *test) { default_prepare(test); runs = LATENCY_RUNS; latvmrun_min = latvmexit_min = -1ULL; latvmrun_max = latvmexit_max = 0; vmrun_sum = vmexit_sum = 0; } static void latency_test(struct test *test) { u64 cycles; start: tsc_end = rdtsc(); cycles = tsc_end - tsc_start; if (cycles > latvmrun_max) latvmrun_max = cycles; if (cycles < latvmrun_min) latvmrun_min = cycles; vmrun_sum += cycles; tsc_start = rdtsc(); asm volatile ("vmmcall" : : : "memory"); goto start; } static bool latency_finished(struct test *test) { u64 cycles; tsc_end = rdtsc(); cycles = tsc_end - tsc_start; if (cycles > latvmexit_max) latvmexit_max = cycles; if (cycles < latvmexit_min) latvmexit_min = cycles; vmexit_sum += cycles; test->vmcb->save.rip += 3; runs -= 1; return runs == 0; } static bool latency_check(struct test *test) { printf(" Latency VMRUN : max: %ld min: %ld avg: %ld\n", latvmrun_max, latvmrun_min, vmrun_sum / LATENCY_RUNS); printf(" Latency VMEXIT: max: %ld min: %ld avg: %ld\n", latvmexit_max, latvmexit_min, vmexit_sum / LATENCY_RUNS); return true; } static void lat_svm_insn_prepare(struct test *test) { default_prepare(test); runs = LATENCY_RUNS; latvmload_min = latvmsave_min = latstgi_min = latclgi_min = -1ULL; latvmload_max = latvmsave_max = latstgi_max = latclgi_max = 0; vmload_sum = vmsave_sum = stgi_sum = clgi_sum; } static bool lat_svm_insn_finished(struct test *test) { u64 vmcb_phys = virt_to_phys(test->vmcb); u64 cycles; for ( ; runs != 0; runs--) { tsc_start = rdtsc(); asm volatile("vmload\n\t" : : "a"(vmcb_phys) : "memory"); cycles = rdtsc() - tsc_start; if (cycles > latvmload_max) latvmload_max = cycles; if (cycles < latvmload_min) latvmload_min = cycles; vmload_sum += cycles; tsc_start = rdtsc(); asm volatile("vmsave\n\t" : : "a"(vmcb_phys) : "memory"); cycles = rdtsc() - tsc_start; if (cycles > latvmsave_max) latvmsave_max = cycles; if (cycles < latvmsave_min) latvmsave_min = cycles; vmsave_sum += cycles; tsc_start = rdtsc(); asm volatile("stgi\n\t"); cycles = rdtsc() - tsc_start; if (cycles > latstgi_max) latstgi_max = cycles; if (cycles < latstgi_min) latstgi_min = cycles; stgi_sum += cycles; tsc_start = rdtsc(); asm volatile("clgi\n\t"); cycles = rdtsc() - tsc_start; if (cycles > latclgi_max) latclgi_max = cycles; if (cycles < latclgi_min) latclgi_min = cycles; clgi_sum += cycles; } return true; } static bool lat_svm_insn_check(struct test *test) { printf(" Latency VMLOAD: max: %ld min: %ld avg: %ld\n", latvmload_max, latvmload_min, vmload_sum / LATENCY_RUNS); printf(" Latency VMSAVE: max: %ld min: %ld avg: %ld\n", latvmsave_max, latvmsave_min, vmsave_sum / LATENCY_RUNS); printf(" Latency STGI: max: %ld min: %ld avg: %ld\n", latstgi_max, latstgi_min, stgi_sum / LATENCY_RUNS); printf(" Latency CLGI: max: %ld min: %ld avg: %ld\n", latclgi_max, latclgi_min, clgi_sum / LATENCY_RUNS); return true; } static struct test tests[] = { { "null", default_supported, default_prepare, null_test, default_finished, null_check }, { "vmrun", default_supported, default_prepare, test_vmrun, default_finished, check_vmrun }, { "ioio", default_supported, prepare_ioio, test_ioio, ioio_finished, check_ioio }, { "vmrun intercept check", default_supported, prepare_no_vmrun_int, null_test, default_finished, check_no_vmrun_int }, { "cr3 read intercept", default_supported, prepare_cr3_intercept, test_cr3_intercept, default_finished, check_cr3_intercept }, { "cr3 read nointercept", default_supported, default_prepare, test_cr3_intercept, default_finished, check_cr3_nointercept }, { "cr3 read intercept emulate", smp_supported, prepare_cr3_intercept_bypass, test_cr3_intercept_bypass, default_finished, check_cr3_intercept }, { "next_rip", next_rip_supported, prepare_next_rip, test_next_rip, default_finished, check_next_rip }, { "mode_switch", default_supported, prepare_mode_switch, test_mode_switch, mode_switch_finished, check_mode_switch }, { "asid_zero", default_supported, prepare_asid_zero, test_asid_zero, default_finished, check_asid_zero }, { "sel_cr0_bug", default_supported, sel_cr0_bug_prepare, sel_cr0_bug_test, sel_cr0_bug_finished, sel_cr0_bug_check }, { "npt_nx", npt_supported, npt_nx_prepare, null_test, default_finished, npt_nx_check }, { "npt_us", npt_supported, npt_us_prepare, npt_us_test, default_finished, npt_us_check }, { "npt_rsvd", npt_supported, npt_rsvd_prepare, null_test, default_finished, npt_rsvd_check }, { "npt_rw", npt_supported, npt_rw_prepare, npt_rw_test, default_finished, npt_rw_check }, { "npt_rsvd_pfwalk", npt_supported, npt_rsvd_pfwalk_prepare, null_test, default_finished, npt_rsvd_pfwalk_check }, { "npt_rw_pfwalk", npt_supported, npt_rw_pfwalk_prepare, null_test, default_finished, npt_rw_pfwalk_check }, { "npt_l1mmio", npt_supported, npt_l1mmio_prepare, npt_l1mmio_test, default_finished, npt_l1mmio_check }, { "npt_rw_l1mmio", npt_supported, npt_rw_l1mmio_prepare, npt_rw_l1mmio_test, default_finished, npt_rw_l1mmio_check }, { "latency_run_exit", default_supported, latency_prepare, latency_test, latency_finished, latency_check }, { "latency_svm_insn", default_supported, lat_svm_insn_prepare, null_test, lat_svm_insn_finished, lat_svm_insn_check }, }; int main(int ac, char **av) { int i, nr; struct vmcb *vmcb; setup_vm(); smp_init(); if (!(cpuid(0x80000001).c & 4)) { printf("SVM not availble\n"); return report_summary(); } setup_svm(); vmcb = alloc_page(); nr = ARRAY_SIZE(tests); for (i = 0; i < nr; ++i) { if (!tests[i].supported()) continue; test_run(&tests[i], vmcb); } return report_summary(); }
e5d4359e94214cab4f2fe54cf8a88cec424989e4
28d0f8c01599f8f6c711bdde0b59f9c2cd221203
/sys/external/bsd/compiler_rt/dist/test/profile/instrprof-value-prof-2.c
989353e1f53e212fe6b01e23718708f5584c3dd4
[ "NCSA", "MIT" ]
permissive
NetBSD/src
1a9cbc22ed778be638b37869ed4fb5c8dd616166
23ee83f7c0aea0777bd89d8ebd7f0cde9880d13c
refs/heads/trunk
2023-08-31T13:24:58.105962
2023-08-27T15:50:47
2023-08-27T15:50:47
88,439,547
656
348
null
2023-07-20T20:07:24
2017-04-16T20:03:43
null
UTF-8
C
false
false
4,998
c
instrprof-value-prof-2.c
// RUN: %clang_profgen -O2 -o %t %s // RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t // RUN: llvm-profdata merge -o %t.profdata %t.profraw // RUN: llvm-profdata show --all-functions -ic-targets %t.profdata | FileCheck %s #include <stdint.h> #include <stdio.h> #include <stdlib.h> typedef struct __llvm_profile_data __llvm_profile_data; const __llvm_profile_data *__llvm_profile_begin_data(void); const __llvm_profile_data *__llvm_profile_end_data(void); void __llvm_profile_set_num_value_sites(__llvm_profile_data *Data, uint32_t ValueKind, uint16_t NumValueSites); __llvm_profile_data * __llvm_profile_iterate_data(const __llvm_profile_data *Data); void *__llvm_get_function_addr(const __llvm_profile_data *Data); void __llvm_profile_instrument_target(uint64_t TargetValue, void *Data, uint32_t CounterIndex); void callee1() {} void callee2() {} void caller_without_value_site1() {} void caller_with_value_site_never_called1() {} void caller_with_vp1() {} void caller_with_value_site_never_called2() {} void caller_without_value_site2() {} void caller_with_vp2() {} int main(int argc, const char *argv[]) { unsigned S, NS = 10, V; const __llvm_profile_data *Data, *DataEnd; Data = __llvm_profile_begin_data(); DataEnd = __llvm_profile_end_data(); for (; Data < DataEnd; Data = __llvm_profile_iterate_data(Data)) { void *func = __llvm_get_function_addr(Data); if (func == caller_without_value_site1 || func == caller_without_value_site2 || func == callee1 || func == callee2 || func == main) continue; __llvm_profile_set_num_value_sites((__llvm_profile_data *)Data, 0 /*IPVK_IndirectCallTarget */, 10); if (func == caller_with_value_site_never_called1 || func == caller_with_value_site_never_called2) continue; for (S = 0; S < NS; S++) { unsigned C; for (C = 0; C < S + 1; C++) { __llvm_profile_instrument_target((uint64_t)&callee1, (void *)Data, S); if (C % 2 == 0) __llvm_profile_instrument_target((uint64_t)&callee2, (void *)Data, S); } } } } // CHECK-LABEL: caller_with_value_site_never_called2: // CHECK-NEXT: Hash: 0x0000000000000000 // CHECK-NEXT: Counters: // CHECK-NEXT: Function count // CHECK-NEXT: Indirect Call Site Count: 10 // CHECK-NEXT: Indirect Target Results: // CHECK-LABEL: caller_with_vp2: // CHECK-NEXT: Hash: 0x0000000000000000 // CHECK-NEXT: Counters: // CHECK-NEXT: Function count: // CHECK-NEXT: Indirect Call Site Count: 10 // CHECK-NEXT: Indirect Target Results: // CHECK-NEXT: [ 0, callee1, 1 ] // CHECK-NEXT: [ 0, callee2, 1 ] // CHECK-NEXT: [ 1, callee1, 2 ] // CHECK-NEXT: [ 1, callee2, 1 ] // CHECK-NEXT: [ 2, callee1, 3 ] // CHECK-NEXT: [ 2, callee2, 2 ] // CHECK-NEXT: [ 3, callee1, 4 ] // CHECK-NEXT: [ 3, callee2, 2 ] // CHECK-NEXT: [ 4, callee1, 5 ] // CHECK-NEXT: [ 4, callee2, 3 ] // CHECK-NEXT: [ 5, callee1, 6 ] // CHECK-NEXT: [ 5, callee2, 3 ] // CHECK-NEXT: [ 6, callee1, 7 ] // CHECK-NEXT: [ 6, callee2, 4 ] // CHECK-NEXT: [ 7, callee1, 8 ] // CHECK-NEXT: [ 7, callee2, 4 ] // CHECK-NEXT: [ 8, callee1, 9 ] // CHECK-NEXT: [ 8, callee2, 5 ] // CHECK-NEXT: [ 9, callee1, 10 ] // CHECK-NEXT: [ 9, callee2, 5 ] // CHECK-LABEL: caller_with_vp1: // CHECK-NEXT: Hash: 0x0000000000000000 // CHECK-NEXT: Counters: // CHECK-NEXT: Function count // CHECK-NEXT: Indirect Call Site Count: 10 // CHECK-NEXT: Indirect Target Results: // CHECK-NEXT: [ 0, callee1, 1 ] // CHECK-NEXT: [ 0, callee2, 1 ] // CHECK-NEXT: [ 1, callee1, 2 ] // CHECK-NEXT: [ 1, callee2, 1 ] // CHECK-NEXT: [ 2, callee1, 3 ] // CHECK-NEXT: [ 2, callee2, 2 ] // CHECK-NEXT: [ 3, callee1, 4 ] // CHECK-NEXT: [ 3, callee2, 2 ] // CHECK-NEXT: [ 4, callee1, 5 ] // CHECK-NEXT: [ 4, callee2, 3 ] // CHECK-NEXT: [ 5, callee1, 6 ] // CHECK-NEXT: [ 5, callee2, 3 ] // CHECK-NEXT: [ 6, callee1, 7 ] // CHECK-NEXT: [ 6, callee2, 4 ] // CHECK-NEXT: [ 7, callee1, 8 ] // CHECK-NEXT: [ 7, callee2, 4 ] // CHECK-NEXT: [ 8, callee1, 9 ] // CHECK-NEXT: [ 8, callee2, 5 ] // CHECK-NEXT: [ 9, callee1, 10 ] // CHECK-NEXT: [ 9, callee2, 5 ] // CHECK-LABEL: caller_with_value_site_never_called1: // CHECK-NEXT: Hash: 0x0000000000000000 // CHECK-NEXT: Counters: // CHECK-NEXT: Function count: // CHECK-NEXT: Indirect Call Site Count: 10 // CHECK-NEXT: Indirect Target Results: // CHECK-LABEL: caller_without_value_site2: // CHECK-NEXT: Hash: 0x0000000000000000 // CHECK-NEXT: Counters: // CHECK-NEXT: Function count: // CHECK-NEXT: Indirect Call Site Count: 0 // CHECK-NEXT: Indirect Target Results: // CHECK-LABEL: caller_without_value_site1: // CHECK-NEXT: Hash: 0x0000000000000000 // CHECK-NEXT: Counters: // CHECK-NEXT: Function count: // CHECK-NEXT: Indirect Call Site Count: 0 // CHECK-NEXT: Indirect Target Results:
84638eb3f15b142646b3d68ac1c23a3cde1d60c1
8a51a96f61699f0318315ccc89cef39f6866f2b5
/src/backend/commands/matview.c
ac2e74fa3fbbfb35ee269adf4ba3880260739fa2
[ "PostgreSQL" ]
permissive
postgres/postgres
979febf2b41c00090d1256228f768f33e7ef3b6f
b5934bfd6071fed3a38cea0cfaa93afda63d9c0c
refs/heads/master
2023-08-31T00:10:01.373472
2023-08-30T23:07:48
2023-08-30T23:07:48
927,442
13,691
4,807
NOASSERTION
2023-09-09T13:59:15
2010-09-21T11:35:45
C
UTF-8
C
false
false
30,414
c
matview.c
/*------------------------------------------------------------------------- * * matview.c * materialized view support * * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * * * IDENTIFICATION * src/backend/commands/matview.c * *------------------------------------------------------------------------- */ #include "postgres.h" #include "access/genam.h" #include "access/heapam.h" #include "access/htup_details.h" #include "access/multixact.h" #include "access/tableam.h" #include "access/xact.h" #include "access/xlog.h" #include "catalog/catalog.h" #include "catalog/indexing.h" #include "catalog/namespace.h" #include "catalog/pg_am.h" #include "catalog/pg_opclass.h" #include "catalog/pg_operator.h" #include "commands/cluster.h" #include "commands/matview.h" #include "commands/tablecmds.h" #include "commands/tablespace.h" #include "executor/executor.h" #include "executor/spi.h" #include "miscadmin.h" #include "parser/parse_relation.h" #include "pgstat.h" #include "rewrite/rewriteHandler.h" #include "storage/lmgr.h" #include "storage/smgr.h" #include "tcop/tcopprot.h" #include "utils/builtins.h" #include "utils/lsyscache.h" #include "utils/rel.h" #include "utils/snapmgr.h" #include "utils/syscache.h" typedef struct { DestReceiver pub; /* publicly-known function pointers */ Oid transientoid; /* OID of new heap into which to store */ /* These fields are filled by transientrel_startup: */ Relation transientrel; /* relation to write to */ CommandId output_cid; /* cmin to insert in output tuples */ int ti_options; /* table_tuple_insert performance options */ BulkInsertState bistate; /* bulk insert state */ } DR_transientrel; static int matview_maintenance_depth = 0; static void transientrel_startup(DestReceiver *self, int operation, TupleDesc typeinfo); static bool transientrel_receive(TupleTableSlot *slot, DestReceiver *self); static void transientrel_shutdown(DestReceiver *self); static void transientrel_destroy(DestReceiver *self); static uint64 refresh_matview_datafill(DestReceiver *dest, Query *query, const char *queryString); static char *make_temptable_name_n(char *tempname, int n); static void refresh_by_match_merge(Oid matviewOid, Oid tempOid, Oid relowner, int save_sec_context); static void refresh_by_heap_swap(Oid matviewOid, Oid OIDNewHeap, char relpersistence); static bool is_usable_unique_index(Relation indexRel); static void OpenMatViewIncrementalMaintenance(void); static void CloseMatViewIncrementalMaintenance(void); /* * SetMatViewPopulatedState * Mark a materialized view as populated, or not. * * NOTE: caller must be holding an appropriate lock on the relation. */ void SetMatViewPopulatedState(Relation relation, bool newstate) { Relation pgrel; HeapTuple tuple; Assert(relation->rd_rel->relkind == RELKIND_MATVIEW); /* * Update relation's pg_class entry. Crucial side-effect: other backends * (and this one too!) are sent SI message to make them rebuild relcache * entries. */ pgrel = table_open(RelationRelationId, RowExclusiveLock); tuple = SearchSysCacheCopy1(RELOID, ObjectIdGetDatum(RelationGetRelid(relation))); if (!HeapTupleIsValid(tuple)) elog(ERROR, "cache lookup failed for relation %u", RelationGetRelid(relation)); ((Form_pg_class) GETSTRUCT(tuple))->relispopulated = newstate; CatalogTupleUpdate(pgrel, &tuple->t_self, tuple); heap_freetuple(tuple); table_close(pgrel, RowExclusiveLock); /* * Advance command counter to make the updated pg_class row locally * visible. */ CommandCounterIncrement(); } /* * ExecRefreshMatView -- execute a REFRESH MATERIALIZED VIEW command * * This refreshes the materialized view by creating a new table and swapping * the relfilenumbers of the new table and the old materialized view, so the OID * of the original materialized view is preserved. Thus we do not lose GRANT * nor references to this materialized view. * * If WITH NO DATA was specified, this is effectively like a TRUNCATE; * otherwise it is like a TRUNCATE followed by an INSERT using the SELECT * statement associated with the materialized view. The statement node's * skipData field shows whether the clause was used. * * Indexes are rebuilt too, via REINDEX. Since we are effectively bulk-loading * the new heap, it's better to create the indexes afterwards than to fill them * incrementally while we load. * * The matview's "populated" state is changed based on whether the contents * reflect the result set of the materialized view's query. */ ObjectAddress ExecRefreshMatView(RefreshMatViewStmt *stmt, const char *queryString, ParamListInfo params, QueryCompletion *qc) { Oid matviewOid; Relation matviewRel; RewriteRule *rule; List *actions; Query *dataQuery; Oid tableSpace; Oid relowner; Oid OIDNewHeap; DestReceiver *dest; uint64 processed = 0; bool concurrent; LOCKMODE lockmode; char relpersistence; Oid save_userid; int save_sec_context; int save_nestlevel; ObjectAddress address; /* Determine strength of lock needed. */ concurrent = stmt->concurrent; lockmode = concurrent ? ExclusiveLock : AccessExclusiveLock; /* * Get a lock until end of transaction. */ matviewOid = RangeVarGetRelidExtended(stmt->relation, lockmode, 0, RangeVarCallbackOwnsTable, NULL); matviewRel = table_open(matviewOid, NoLock); relowner = matviewRel->rd_rel->relowner; /* * Switch to the owner's userid, so that any functions are run as that * user. Also lock down security-restricted operations and arrange to * make GUC variable changes local to this command. */ GetUserIdAndSecContext(&save_userid, &save_sec_context); SetUserIdAndSecContext(relowner, save_sec_context | SECURITY_RESTRICTED_OPERATION); save_nestlevel = NewGUCNestLevel(); /* Make sure it is a materialized view. */ if (matviewRel->rd_rel->relkind != RELKIND_MATVIEW) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("\"%s\" is not a materialized view", RelationGetRelationName(matviewRel)))); /* Check that CONCURRENTLY is not specified if not populated. */ if (concurrent && !RelationIsPopulated(matviewRel)) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("CONCURRENTLY cannot be used when the materialized view is not populated"))); /* Check that conflicting options have not been specified. */ if (concurrent && stmt->skipData) ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), errmsg("%s and %s options cannot be used together", "CONCURRENTLY", "WITH NO DATA"))); /* * Check that everything is correct for a refresh. Problems at this point * are internal errors, so elog is sufficient. */ if (matviewRel->rd_rel->relhasrules == false || matviewRel->rd_rules->numLocks < 1) elog(ERROR, "materialized view \"%s\" is missing rewrite information", RelationGetRelationName(matviewRel)); if (matviewRel->rd_rules->numLocks > 1) elog(ERROR, "materialized view \"%s\" has too many rules", RelationGetRelationName(matviewRel)); rule = matviewRel->rd_rules->rules[0]; if (rule->event != CMD_SELECT || !(rule->isInstead)) elog(ERROR, "the rule for materialized view \"%s\" is not a SELECT INSTEAD OF rule", RelationGetRelationName(matviewRel)); actions = rule->actions; if (list_length(actions) != 1) elog(ERROR, "the rule for materialized view \"%s\" is not a single action", RelationGetRelationName(matviewRel)); /* * Check that there is a unique index with no WHERE clause on one or more * columns of the materialized view if CONCURRENTLY is specified. */ if (concurrent) { List *indexoidlist = RelationGetIndexList(matviewRel); ListCell *indexoidscan; bool hasUniqueIndex = false; foreach(indexoidscan, indexoidlist) { Oid indexoid = lfirst_oid(indexoidscan); Relation indexRel; indexRel = index_open(indexoid, AccessShareLock); hasUniqueIndex = is_usable_unique_index(indexRel); index_close(indexRel, AccessShareLock); if (hasUniqueIndex) break; } list_free(indexoidlist); if (!hasUniqueIndex) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("cannot refresh materialized view \"%s\" concurrently", quote_qualified_identifier(get_namespace_name(RelationGetNamespace(matviewRel)), RelationGetRelationName(matviewRel))), errhint("Create a unique index with no WHERE clause on one or more columns of the materialized view."))); } /* * The stored query was rewritten at the time of the MV definition, but * has not been scribbled on by the planner. */ dataQuery = linitial_node(Query, actions); /* * Check for active uses of the relation in the current transaction, such * as open scans. * * NB: We count on this to protect us against problems with refreshing the * data using TABLE_INSERT_FROZEN. */ CheckTableNotInUse(matviewRel, "REFRESH MATERIALIZED VIEW"); /* * Tentatively mark the matview as populated or not (this will roll back * if we fail later). */ SetMatViewPopulatedState(matviewRel, !stmt->skipData); /* Concurrent refresh builds new data in temp tablespace, and does diff. */ if (concurrent) { tableSpace = GetDefaultTablespace(RELPERSISTENCE_TEMP, false); relpersistence = RELPERSISTENCE_TEMP; } else { tableSpace = matviewRel->rd_rel->reltablespace; relpersistence = matviewRel->rd_rel->relpersistence; } /* * Create the transient table that will receive the regenerated data. Lock * it against access by any other process until commit (by which time it * will be gone). */ OIDNewHeap = make_new_heap(matviewOid, tableSpace, matviewRel->rd_rel->relam, relpersistence, ExclusiveLock); LockRelationOid(OIDNewHeap, AccessExclusiveLock); dest = CreateTransientRelDestReceiver(OIDNewHeap); /* Generate the data, if wanted. */ if (!stmt->skipData) processed = refresh_matview_datafill(dest, dataQuery, queryString); /* Make the matview match the newly generated data. */ if (concurrent) { int old_depth = matview_maintenance_depth; PG_TRY(); { refresh_by_match_merge(matviewOid, OIDNewHeap, relowner, save_sec_context); } PG_CATCH(); { matview_maintenance_depth = old_depth; PG_RE_THROW(); } PG_END_TRY(); Assert(matview_maintenance_depth == old_depth); } else { refresh_by_heap_swap(matviewOid, OIDNewHeap, relpersistence); /* * Inform cumulative stats system about our activity: basically, we * truncated the matview and inserted some new data. (The concurrent * code path above doesn't need to worry about this because the * inserts and deletes it issues get counted by lower-level code.) */ pgstat_count_truncate(matviewRel); if (!stmt->skipData) pgstat_count_heap_insert(matviewRel, processed); } table_close(matviewRel, NoLock); /* Roll back any GUC changes */ AtEOXact_GUC(false, save_nestlevel); /* Restore userid and security context */ SetUserIdAndSecContext(save_userid, save_sec_context); ObjectAddressSet(address, RelationRelationId, matviewOid); /* * Save the rowcount so that pg_stat_statements can track the total number * of rows processed by REFRESH MATERIALIZED VIEW command. Note that we * still don't display the rowcount in the command completion tag output, * i.e., the display_rowcount flag of CMDTAG_REFRESH_MATERIALIZED_VIEW * command tag is left false in cmdtaglist.h. Otherwise, the change of * completion tag output might break applications using it. */ if (qc) SetQueryCompletion(qc, CMDTAG_REFRESH_MATERIALIZED_VIEW, processed); return address; } /* * refresh_matview_datafill * * Execute the given query, sending result rows to "dest" (which will * insert them into the target matview). * * Returns number of rows inserted. */ static uint64 refresh_matview_datafill(DestReceiver *dest, Query *query, const char *queryString) { List *rewritten; PlannedStmt *plan; QueryDesc *queryDesc; Query *copied_query; uint64 processed; /* Lock and rewrite, using a copy to preserve the original query. */ copied_query = copyObject(query); AcquireRewriteLocks(copied_query, true, false); rewritten = QueryRewrite(copied_query); /* SELECT should never rewrite to more or less than one SELECT query */ if (list_length(rewritten) != 1) elog(ERROR, "unexpected rewrite result for REFRESH MATERIALIZED VIEW"); query = (Query *) linitial(rewritten); /* Check for user-requested abort. */ CHECK_FOR_INTERRUPTS(); /* Plan the query which will generate data for the refresh. */ plan = pg_plan_query(query, queryString, CURSOR_OPT_PARALLEL_OK, NULL); /* * Use a snapshot with an updated command ID to ensure this query sees * results of any previously executed queries. (This could only matter if * the planner executed an allegedly-stable function that changed the * database contents, but let's do it anyway to be safe.) */ PushCopiedSnapshot(GetActiveSnapshot()); UpdateActiveSnapshotCommandId(); /* Create a QueryDesc, redirecting output to our tuple receiver */ queryDesc = CreateQueryDesc(plan, queryString, GetActiveSnapshot(), InvalidSnapshot, dest, NULL, NULL, 0); /* call ExecutorStart to prepare the plan for execution */ ExecutorStart(queryDesc, 0); /* run the plan */ ExecutorRun(queryDesc, ForwardScanDirection, 0, true); processed = queryDesc->estate->es_processed; /* and clean up */ ExecutorFinish(queryDesc); ExecutorEnd(queryDesc); FreeQueryDesc(queryDesc); PopActiveSnapshot(); return processed; } DestReceiver * CreateTransientRelDestReceiver(Oid transientoid) { DR_transientrel *self = (DR_transientrel *) palloc0(sizeof(DR_transientrel)); self->pub.receiveSlot = transientrel_receive; self->pub.rStartup = transientrel_startup; self->pub.rShutdown = transientrel_shutdown; self->pub.rDestroy = transientrel_destroy; self->pub.mydest = DestTransientRel; self->transientoid = transientoid; return (DestReceiver *) self; } /* * transientrel_startup --- executor startup */ static void transientrel_startup(DestReceiver *self, int operation, TupleDesc typeinfo) { DR_transientrel *myState = (DR_transientrel *) self; Relation transientrel; transientrel = table_open(myState->transientoid, NoLock); /* * Fill private fields of myState for use by later routines */ myState->transientrel = transientrel; myState->output_cid = GetCurrentCommandId(true); myState->ti_options = TABLE_INSERT_SKIP_FSM | TABLE_INSERT_FROZEN; myState->bistate = GetBulkInsertState(); /* * Valid smgr_targblock implies something already wrote to the relation. * This may be harmless, but this function hasn't planned for it. */ Assert(RelationGetTargetBlock(transientrel) == InvalidBlockNumber); } /* * transientrel_receive --- receive one tuple */ static bool transientrel_receive(TupleTableSlot *slot, DestReceiver *self) { DR_transientrel *myState = (DR_transientrel *) self; /* * Note that the input slot might not be of the type of the target * relation. That's supported by table_tuple_insert(), but slightly less * efficient than inserting with the right slot - but the alternative * would be to copy into a slot of the right type, which would not be * cheap either. This also doesn't allow accessing per-AM data (say a * tuple's xmin), but since we don't do that here... */ table_tuple_insert(myState->transientrel, slot, myState->output_cid, myState->ti_options, myState->bistate); /* We know this is a newly created relation, so there are no indexes */ return true; } /* * transientrel_shutdown --- executor end */ static void transientrel_shutdown(DestReceiver *self) { DR_transientrel *myState = (DR_transientrel *) self; FreeBulkInsertState(myState->bistate); table_finish_bulk_insert(myState->transientrel, myState->ti_options); /* close transientrel, but keep lock until commit */ table_close(myState->transientrel, NoLock); myState->transientrel = NULL; } /* * transientrel_destroy --- release DestReceiver object */ static void transientrel_destroy(DestReceiver *self) { pfree(self); } /* * Given a qualified temporary table name, append an underscore followed by * the given integer, to make a new table name based on the old one. * The result is a palloc'd string. * * As coded, this would fail to make a valid SQL name if the given name were, * say, "FOO"."BAR". Currently, the table name portion of the input will * never be double-quoted because it's of the form "pg_temp_NNN", cf * make_new_heap(). But we might have to work harder someday. */ static char * make_temptable_name_n(char *tempname, int n) { StringInfoData namebuf; initStringInfo(&namebuf); appendStringInfoString(&namebuf, tempname); appendStringInfo(&namebuf, "_%d", n); return namebuf.data; } /* * refresh_by_match_merge * * Refresh a materialized view with transactional semantics, while allowing * concurrent reads. * * This is called after a new version of the data has been created in a * temporary table. It performs a full outer join against the old version of * the data, producing "diff" results. This join cannot work if there are any * duplicated rows in either the old or new versions, in the sense that every * column would compare as equal between the two rows. It does work correctly * in the face of rows which have at least one NULL value, with all non-NULL * columns equal. The behavior of NULLs on equality tests and on UNIQUE * indexes turns out to be quite convenient here; the tests we need to make * are consistent with default behavior. If there is at least one UNIQUE * index on the materialized view, we have exactly the guarantee we need. * * The temporary table used to hold the diff results contains just the TID of * the old record (if matched) and the ROW from the new table as a single * column of complex record type (if matched). * * Once we have the diff table, we perform set-based DELETE and INSERT * operations against the materialized view, and discard both temporary * tables. * * Everything from the generation of the new data to applying the differences * takes place under cover of an ExclusiveLock, since it seems as though we * would want to prohibit not only concurrent REFRESH operations, but also * incremental maintenance. It also doesn't seem reasonable or safe to allow * SELECT FOR UPDATE or SELECT FOR SHARE on rows being updated or deleted by * this command. */ static void refresh_by_match_merge(Oid matviewOid, Oid tempOid, Oid relowner, int save_sec_context) { StringInfoData querybuf; Relation matviewRel; Relation tempRel; char *matviewname; char *tempname; char *diffname; TupleDesc tupdesc; bool foundUniqueIndex; List *indexoidlist; ListCell *indexoidscan; int16 relnatts; Oid *opUsedForQual; initStringInfo(&querybuf); matviewRel = table_open(matviewOid, NoLock); matviewname = quote_qualified_identifier(get_namespace_name(RelationGetNamespace(matviewRel)), RelationGetRelationName(matviewRel)); tempRel = table_open(tempOid, NoLock); tempname = quote_qualified_identifier(get_namespace_name(RelationGetNamespace(tempRel)), RelationGetRelationName(tempRel)); diffname = make_temptable_name_n(tempname, 2); relnatts = RelationGetNumberOfAttributes(matviewRel); /* Open SPI context. */ if (SPI_connect() != SPI_OK_CONNECT) elog(ERROR, "SPI_connect failed"); /* Analyze the temp table with the new contents. */ appendStringInfo(&querybuf, "ANALYZE %s", tempname); if (SPI_exec(querybuf.data, 0) != SPI_OK_UTILITY) elog(ERROR, "SPI_exec failed: %s", querybuf.data); /* * We need to ensure that there are not duplicate rows without NULLs in * the new data set before we can count on the "diff" results. Check for * that in a way that allows showing the first duplicated row found. Even * after we pass this test, a unique index on the materialized view may * find a duplicate key problem. * * Note: here and below, we use "tablename.*::tablerowtype" as a hack to * keep ".*" from being expanded into multiple columns in a SELECT list. * Compare ruleutils.c's get_variable(). */ resetStringInfo(&querybuf); appendStringInfo(&querybuf, "SELECT newdata.*::%s FROM %s newdata " "WHERE newdata.* IS NOT NULL AND EXISTS " "(SELECT 1 FROM %s newdata2 WHERE newdata2.* IS NOT NULL " "AND newdata2.* OPERATOR(pg_catalog.*=) newdata.* " "AND newdata2.ctid OPERATOR(pg_catalog.<>) " "newdata.ctid)", tempname, tempname, tempname); if (SPI_execute(querybuf.data, false, 1) != SPI_OK_SELECT) elog(ERROR, "SPI_exec failed: %s", querybuf.data); if (SPI_processed > 0) { /* * Note that this ereport() is returning data to the user. Generally, * we would want to make sure that the user has been granted access to * this data. However, REFRESH MAT VIEW is only able to be run by the * owner of the mat view (or a superuser) and therefore there is no * need to check for access to data in the mat view. */ ereport(ERROR, (errcode(ERRCODE_CARDINALITY_VIOLATION), errmsg("new data for materialized view \"%s\" contains duplicate rows without any null columns", RelationGetRelationName(matviewRel)), errdetail("Row: %s", SPI_getvalue(SPI_tuptable->vals[0], SPI_tuptable->tupdesc, 1)))); } SetUserIdAndSecContext(relowner, save_sec_context | SECURITY_LOCAL_USERID_CHANGE); /* Start building the query for creating the diff table. */ resetStringInfo(&querybuf); appendStringInfo(&querybuf, "CREATE TEMP TABLE %s AS " "SELECT mv.ctid AS tid, newdata.*::%s AS newdata " "FROM %s mv FULL JOIN %s newdata ON (", diffname, tempname, matviewname, tempname); /* * Get the list of index OIDs for the table from the relcache, and look up * each one in the pg_index syscache. We will test for equality on all * columns present in all unique indexes which only reference columns and * include all rows. */ tupdesc = matviewRel->rd_att; opUsedForQual = (Oid *) palloc0(sizeof(Oid) * relnatts); foundUniqueIndex = false; indexoidlist = RelationGetIndexList(matviewRel); foreach(indexoidscan, indexoidlist) { Oid indexoid = lfirst_oid(indexoidscan); Relation indexRel; indexRel = index_open(indexoid, RowExclusiveLock); if (is_usable_unique_index(indexRel)) { Form_pg_index indexStruct = indexRel->rd_index; int indnkeyatts = indexStruct->indnkeyatts; oidvector *indclass; Datum indclassDatum; int i; /* Must get indclass the hard way. */ indclassDatum = SysCacheGetAttrNotNull(INDEXRELID, indexRel->rd_indextuple, Anum_pg_index_indclass); indclass = (oidvector *) DatumGetPointer(indclassDatum); /* Add quals for all columns from this index. */ for (i = 0; i < indnkeyatts; i++) { int attnum = indexStruct->indkey.values[i]; Oid opclass = indclass->values[i]; Form_pg_attribute attr = TupleDescAttr(tupdesc, attnum - 1); Oid attrtype = attr->atttypid; HeapTuple cla_ht; Form_pg_opclass cla_tup; Oid opfamily; Oid opcintype; Oid op; const char *leftop; const char *rightop; /* * Identify the equality operator associated with this index * column. First we need to look up the column's opclass. */ cla_ht = SearchSysCache1(CLAOID, ObjectIdGetDatum(opclass)); if (!HeapTupleIsValid(cla_ht)) elog(ERROR, "cache lookup failed for opclass %u", opclass); cla_tup = (Form_pg_opclass) GETSTRUCT(cla_ht); Assert(cla_tup->opcmethod == BTREE_AM_OID); opfamily = cla_tup->opcfamily; opcintype = cla_tup->opcintype; ReleaseSysCache(cla_ht); op = get_opfamily_member(opfamily, opcintype, opcintype, BTEqualStrategyNumber); if (!OidIsValid(op)) elog(ERROR, "missing operator %d(%u,%u) in opfamily %u", BTEqualStrategyNumber, opcintype, opcintype, opfamily); /* * If we find the same column with the same equality semantics * in more than one index, we only need to emit the equality * clause once. * * Since we only remember the last equality operator, this * code could be fooled into emitting duplicate clauses given * multiple indexes with several different opclasses ... but * that's so unlikely it doesn't seem worth spending extra * code to avoid. */ if (opUsedForQual[attnum - 1] == op) continue; opUsedForQual[attnum - 1] = op; /* * Actually add the qual, ANDed with any others. */ if (foundUniqueIndex) appendStringInfoString(&querybuf, " AND "); leftop = quote_qualified_identifier("newdata", NameStr(attr->attname)); rightop = quote_qualified_identifier("mv", NameStr(attr->attname)); generate_operator_clause(&querybuf, leftop, attrtype, op, rightop, attrtype); foundUniqueIndex = true; } } /* Keep the locks, since we're about to run DML which needs them. */ index_close(indexRel, NoLock); } list_free(indexoidlist); /* * There must be at least one usable unique index on the matview. * * ExecRefreshMatView() checks that after taking the exclusive lock on the * matview. So at least one unique index is guaranteed to exist here * because the lock is still being held; so an Assert seems sufficient. */ Assert(foundUniqueIndex); appendStringInfoString(&querybuf, " AND newdata.* OPERATOR(pg_catalog.*=) mv.*) " "WHERE newdata.* IS NULL OR mv.* IS NULL " "ORDER BY tid"); /* Create the temporary "diff" table. */ if (SPI_exec(querybuf.data, 0) != SPI_OK_UTILITY) elog(ERROR, "SPI_exec failed: %s", querybuf.data); SetUserIdAndSecContext(relowner, save_sec_context | SECURITY_RESTRICTED_OPERATION); /* * We have no further use for data from the "full-data" temp table, but we * must keep it around because its type is referenced from the diff table. */ /* Analyze the diff table. */ resetStringInfo(&querybuf); appendStringInfo(&querybuf, "ANALYZE %s", diffname); if (SPI_exec(querybuf.data, 0) != SPI_OK_UTILITY) elog(ERROR, "SPI_exec failed: %s", querybuf.data); OpenMatViewIncrementalMaintenance(); /* Deletes must come before inserts; do them first. */ resetStringInfo(&querybuf); appendStringInfo(&querybuf, "DELETE FROM %s mv WHERE ctid OPERATOR(pg_catalog.=) ANY " "(SELECT diff.tid FROM %s diff " "WHERE diff.tid IS NOT NULL " "AND diff.newdata IS NULL)", matviewname, diffname); if (SPI_exec(querybuf.data, 0) != SPI_OK_DELETE) elog(ERROR, "SPI_exec failed: %s", querybuf.data); /* Inserts go last. */ resetStringInfo(&querybuf); appendStringInfo(&querybuf, "INSERT INTO %s SELECT (diff.newdata).* " "FROM %s diff WHERE tid IS NULL", matviewname, diffname); if (SPI_exec(querybuf.data, 0) != SPI_OK_INSERT) elog(ERROR, "SPI_exec failed: %s", querybuf.data); /* We're done maintaining the materialized view. */ CloseMatViewIncrementalMaintenance(); table_close(tempRel, NoLock); table_close(matviewRel, NoLock); /* Clean up temp tables. */ resetStringInfo(&querybuf); appendStringInfo(&querybuf, "DROP TABLE %s, %s", diffname, tempname); if (SPI_exec(querybuf.data, 0) != SPI_OK_UTILITY) elog(ERROR, "SPI_exec failed: %s", querybuf.data); /* Close SPI context. */ if (SPI_finish() != SPI_OK_FINISH) elog(ERROR, "SPI_finish failed"); } /* * Swap the physical files of the target and transient tables, then rebuild * the target's indexes and throw away the transient table. Security context * swapping is handled by the called function, so it is not needed here. */ static void refresh_by_heap_swap(Oid matviewOid, Oid OIDNewHeap, char relpersistence) { finish_heap_swap(matviewOid, OIDNewHeap, false, false, true, true, RecentXmin, ReadNextMultiXactId(), relpersistence); } /* * Check whether specified index is usable for match merge. */ static bool is_usable_unique_index(Relation indexRel) { Form_pg_index indexStruct = indexRel->rd_index; /* * Must be unique, valid, immediate, non-partial, and be defined over * plain user columns (not expressions). We also require it to be a * btree. Even if we had any other unique index kinds, we'd not know how * to identify the corresponding equality operator, nor could we be sure * that the planner could implement the required FULL JOIN with non-btree * operators. */ if (indexStruct->indisunique && indexStruct->indimmediate && indexRel->rd_rel->relam == BTREE_AM_OID && indexStruct->indisvalid && RelationGetIndexPredicate(indexRel) == NIL && indexStruct->indnatts > 0) { /* * The point of groveling through the index columns individually is to * reject both index expressions and system columns. Currently, * matviews couldn't have OID columns so there's no way to create an * index on a system column; but maybe someday that wouldn't be true, * so let's be safe. */ int numatts = indexStruct->indnatts; int i; for (i = 0; i < numatts; i++) { int attnum = indexStruct->indkey.values[i]; if (attnum <= 0) return false; } return true; } return false; } /* * This should be used to test whether the backend is in a context where it is * OK to allow DML statements to modify materialized views. We only want to * allow that for internal code driven by the materialized view definition, * not for arbitrary user-supplied code. * * While the function names reflect the fact that their main intended use is * incremental maintenance of materialized views (in response to changes to * the data in referenced relations), they are initially used to allow REFRESH * without blocking concurrent reads. */ bool MatViewIncrementalMaintenanceIsEnabled(void) { return matview_maintenance_depth > 0; } static void OpenMatViewIncrementalMaintenance(void) { matview_maintenance_depth++; } static void CloseMatViewIncrementalMaintenance(void) { matview_maintenance_depth--; Assert(matview_maintenance_depth >= 0); }
7bec6198638380df397517ace4aa7b8286662ad3
ea8fc70c7dbf49059431fa45a940742736c68fb8
/ext/mvc/model/transactioninterface.c
86caebfaa59c99628b2018e395cdec014663d3ff
[ "BSD-3-Clause" ]
permissive
dreamsxin/cphalcon7
1bd2194a251657b48857326927db69fef617ab91
1b8c6b04b4ca237a5ead87d4752df0d2e85c7a9d
refs/heads/master
2023-03-08T04:53:08.829432
2022-07-07T07:48:59
2022-07-07T07:48:59
47,245,335
298
73
null
2021-06-22T11:53:25
2015-12-02T07:44:43
C
UTF-8
C
false
false
4,764
c
transactioninterface.c
/* +------------------------------------------------------------------------+ | Phalcon Framework | +------------------------------------------------------------------------+ | Copyright (c) 2011-2014 Phalcon Team (http://www.phalconphp.com) | +------------------------------------------------------------------------+ | This source file is subject to the New BSD License that is bundled | | with this package in the file docs/LICENSE.txt. | | | | If you did not receive a copy of the license and are unable to | | obtain it through the world-wide-web, please send an email | | to license@phalconphp.com so we can send you a copy immediately. | +------------------------------------------------------------------------+ | Authors: Andres Gutierrez <andres@phalconphp.com> | | Eduar Carvajal <eduar@phalconphp.com> | +------------------------------------------------------------------------+ */ #include "mvc/model/transactioninterface.h" #include "kernel/main.h" zend_class_entry *phalcon_mvc_model_transactioninterface_ce; static const zend_function_entry phalcon_mvc_model_transactioninterface_method_entry[] = { PHP_ABSTRACT_ME(Phalcon_Mvc_Model_TransactionInterface, setTransactionManager, arginfo_phalcon_mvc_model_transactioninterface_settransactionmanager) PHP_ABSTRACT_ME(Phalcon_Mvc_Model_TransactionInterface, begin, arginfo_empty) PHP_ABSTRACT_ME(Phalcon_Mvc_Model_TransactionInterface, commit, arginfo_empty) PHP_ABSTRACT_ME(Phalcon_Mvc_Model_TransactionInterface, rollback, arginfo_phalcon_mvc_model_transactioninterface_rollback) PHP_ABSTRACT_ME(Phalcon_Mvc_Model_TransactionInterface, getConnection, arginfo_empty) PHP_ABSTRACT_ME(Phalcon_Mvc_Model_TransactionInterface, setIsNewTransaction, arginfo_phalcon_mvc_model_transactioninterface_setisnewtransaction) PHP_ABSTRACT_ME(Phalcon_Mvc_Model_TransactionInterface, setRollbackOnAbort, arginfo_phalcon_mvc_model_transactioninterface_setrollbackonabort) PHP_ABSTRACT_ME(Phalcon_Mvc_Model_TransactionInterface, isManaged, arginfo_empty) PHP_ABSTRACT_ME(Phalcon_Mvc_Model_TransactionInterface, getMessages, arginfo_empty) PHP_ABSTRACT_ME(Phalcon_Mvc_Model_TransactionInterface, isValid, arginfo_empty) PHP_ABSTRACT_ME(Phalcon_Mvc_Model_TransactionInterface, setRollbackedRecord, arginfo_phalcon_mvc_model_transactioninterface_setrollbackedrecord) PHP_FE_END }; /** * Phalcon\Mvc\Model\TransactionInterface initializer */ PHALCON_INIT_CLASS(Phalcon_Mvc_Model_TransactionInterface){ PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc\\Model, TransactionInterface, mvc_model_transactioninterface, phalcon_mvc_model_transactioninterface_method_entry); return SUCCESS; } /** * Sets transaction manager related to the transaction * * @param Phalcon\Mvc\Model\Transaction\ManagerInterface $manager */ PHALCON_DOC_METHOD(Phalcon_Mvc_Model_TransactionInterface, setTransactionManager); /** * Starts the transaction * * @return boolean */ PHALCON_DOC_METHOD(Phalcon_Mvc_Model_TransactionInterface, begin); /** * Commits the transaction * * @return boolean */ PHALCON_DOC_METHOD(Phalcon_Mvc_Model_TransactionInterface, commit); /** * Rollbacks the transaction * * @param string $rollbackMessage * @param Phalcon\Mvc\ModelInterface $rollbackRecord * @return boolean */ PHALCON_DOC_METHOD(Phalcon_Mvc_Model_TransactionInterface, rollback); /** * Returns connection related to transaction * * @return string */ PHALCON_DOC_METHOD(Phalcon_Mvc_Model_TransactionInterface, getConnection); /** * Sets if is a reused transaction or new once * * @param boolean $isNew */ PHALCON_DOC_METHOD(Phalcon_Mvc_Model_TransactionInterface, setIsNewTransaction); /** * Sets flag to rollback on abort the HTTP connection * * @param boolean $rollbackOnAbort */ PHALCON_DOC_METHOD(Phalcon_Mvc_Model_TransactionInterface, setRollbackOnAbort); /** * Checks whether transaction is managed by a transaction manager * * @return boolean */ PHALCON_DOC_METHOD(Phalcon_Mvc_Model_TransactionInterface, isManaged); /** * Returns validations messages from last save try * * @return array */ PHALCON_DOC_METHOD(Phalcon_Mvc_Model_TransactionInterface, getMessages); /** * Checks whether internal connection is under an active transaction * * @return boolean */ PHALCON_DOC_METHOD(Phalcon_Mvc_Model_TransactionInterface, isValid); /** * Sets object which generates rollback action * * @param Phalcon\Mvc\ModelInterface $record */ PHALCON_DOC_METHOD(Phalcon_Mvc_Model_TransactionInterface, setRollbackedRecord);
f56dcd09f168eac4392a7e39ffd047b784983f16
ca4c4631f3d47a90b8415bbe70dbc7cae18c071e
/src/overset/TiogaSTKIface.C
9bef139a7c3f09f074f14f136c48cc9aa7d7b39b
[ "BSD-3-Clause", "BSD-2-Clause" ]
permissive
Exawind/nalu-wind
5765078c445d379ea952d2b25a01f5ff490837a6
722cd7757a412c9306645963808047824c312a17
refs/heads/master
2023-08-16T17:44:54.744168
2023-08-15T18:05:23
2023-08-15T18:05:23
132,016,365
111
87
NOASSERTION
2023-09-14T04:02:07
2018-05-03T15:39:32
C
UTF-8
C
false
false
18,703
c
TiogaSTKIface.C
// Copyright 2017 National Technology & Engineering Solutions of Sandia, LLC // (NTESS), National Renewable Energy Laboratory, University of Texas Austin, // Northwest Research Associates. Under the terms of Contract DE-NA0003525 // with NTESS, the U.S. Government retains certain rights in this software. // // This software is released under the BSD 3-clause license. See LICENSE file // for more details. // #ifdef NALU_USES_TIOGA #include "overset/TiogaSTKIface.h" #include "overset/TiogaBlock.h" #include "overset/TiogaRef.h" #include "overset/OversetManagerTIOGA.h" #include "overset/OversetInfo.h" #include "utils/StkHelpers.h" #include "ngp_utils/NgpFieldUtils.h" #include "NaluEnv.h" #include "Realm.h" #include "master_element/MasterElement.h" #include "master_element/MasterElementRepo.h" #include "stk_util/parallel/ParallelReduce.hpp" #include "stk_mesh/base/FieldParallel.hpp" #include "stk_mesh/base/FieldBLAS.hpp" #include "stk_mesh/base/SkinBoundary.hpp" #include "yaml-cpp/yaml.h" #include <iostream> #include <cmath> #include <algorithm> #include <numeric> #include "tioga.h" namespace tioga_nalu { TiogaSTKIface::TiogaSTKIface( sierra::nalu::OversetManagerTIOGA& oversetManager, const YAML::Node& node, const std::string& coordsName) : oversetManager_(oversetManager), meta_(*oversetManager.metaData_), bulk_(*oversetManager.bulkData_), tg_(TiogaRef::self().get()), coordsName_(coordsName) { load(node); } TiogaSTKIface::~TiogaSTKIface() {} void TiogaSTKIface::load(const YAML::Node& node) { const YAML::Node& oset_groups = node["mesh_group"]; if (node["tioga_options"]) tiogaOpts_.load(node["tioga_options"]); int num_meshes = oset_groups.size(); blocks_.resize(num_meshes); int offset = 0; if (node["mesh_tag_offset"]) { offset = node["mesh_tag_offset"].as<int>(); } for (int i = 0; i < num_meshes; i++) { blocks_[i].reset(new TiogaBlock( meta_, bulk_, tiogaOpts_, oset_groups[i], coordsName_, offset + i + 1)); } sierra::nalu::NaluEnv::self().naluOutputP0() << "TIOGA: Using coordinates field: " << coordsName_ << std::endl; if (node["tioga_symmetry_direction"]) sierra::nalu::NaluEnv::self().naluOutputP0() << "WARNING!! TiogaSTKIface: tioga_symmetry_direction is no longer " "supported. " << "Use tioga_options to specify options that control TIOGA behavior" << std::endl; } void TiogaSTKIface::setup(stk::mesh::PartVector& bcPartVec) { for (auto& tb : blocks_) { tb->setup(bcPartVec); } } void TiogaSTKIface::initialize() { tiogaOpts_.set_options(tg_); sierra::nalu::NaluEnv::self().naluOutputP0() << "TIOGA: Initializing overset mesh blocks: " << std::endl; for (auto& tb : blocks_) { tb->initialize(); } sierra::nalu::NaluEnv::self().naluOutputP0() << "TIOGA: Initialized " << blocks_.size() << " overset blocks" << std::endl; } void TiogaSTKIface::execute(const bool isDecoupled) { #if defined(KOKKOS_ENABLE_GPU) // Bail out early if this is a GPU build and is using non-decoupled solve if (!isDecoupled) { throw std::runtime_error( "Non-decoupled overset connectivity not available in NGP build"); } #endif register_mesh(); // Determine overset connectivity tg_.profile(); tg_.performConnectivity(); if (tiogaOpts_.reduce_fringes()) tg_.reduce_fringes(); post_connectivity_work(isDecoupled); } void TiogaSTKIface::register_mesh() { reset_data_structures(); // Synchronize fields to host during transition period pre_connectivity_sync(); // Update the coordinates for TIOGA and register updates to the TIOGA mesh // block. for (auto& tb : blocks_) { tb->update_coords(); tb->update_element_volumes(); if (tiogaOpts_.adjust_resolutions()) tb->adjust_cell_resolutions(); } if (tiogaOpts_.adjust_resolutions()) { auto* nodeVol = meta_.get_field(stk::topology::NODE_RANK, "tioga_nodal_volume"); stk::mesh::parallel_max(bulk_, {nodeVol}); } for (auto& tb : blocks_) { if (tiogaOpts_.adjust_resolutions()) tb->adjust_node_resolutions(); tb->register_block(tg_); } } void TiogaSTKIface::post_connectivity_work(const bool isDecoupled) { for (auto& tb : blocks_) { // Update IBLANK information at nodes and elements tb->update_iblanks( oversetManager_.holeNodes_, oversetManager_.fringeNodes_); tb->update_iblank_cell(); // For each block determine donor elements that needs to be ghosted to other // MPI ranks if (!isDecoupled) tb->get_donor_info(tg_, elemsToGhost_); } // Synchronize IBLANK data for shared nodes ScalarIntFieldType* ibf = meta_.get_field<ScalarIntFieldType>(stk::topology::NODE_RANK, "iblank"); std::vector<const stk::mesh::FieldBase*> pvec{ibf}; stk::mesh::copy_owned_to_shared(bulk_, pvec); post_connectivity_sync(); if (!isDecoupled) { get_receptor_info(); // Collect all elements to be ghosted and update ghosting so that the // elements are available when generating {fringeNode, donorElement} pairs // in the next step. update_ghosting(); // Update overset fringe connectivity information for Constraint based // algorithm populate_overset_info(); } } void TiogaSTKIface::reset_data_structures() { oversetManager_.reset_data_structures(); elemsToGhost_.clear(); donorIDs_.clear(); receptorIDs_.clear(); } void TiogaSTKIface::update_ghosting() { stk::mesh::Ghosting* ovsetGhosting = oversetManager_.oversetGhosting_; std::vector<stk::mesh::EntityKey> recvGhostsToRemove; if (ovsetGhosting != nullptr) { stk::mesh::EntityProcVec currentSendGhosts; ovsetGhosting->send_list(currentSendGhosts); sierra::nalu::compute_precise_ghosting_lists( bulk_, elemsToGhost_, currentSendGhosts, recvGhostsToRemove); } size_t local[2] = {elemsToGhost_.size(), recvGhostsToRemove.size()}; size_t global[2] = {0, 0}; stk::all_reduce_sum(bulk_.parallel(), local, global, 2); if ((global[0] > 0) || (global[1] > 0)) { bulk_.modification_begin(); if (ovsetGhosting == nullptr) { const std::string ghostName = "nalu_overset_ghosting"; oversetManager_.oversetGhosting_ = &(bulk_.create_ghosting(ghostName)); } bulk_.change_ghosting( *(oversetManager_.oversetGhosting_), elemsToGhost_, recvGhostsToRemove); bulk_.modification_end(); sierra::nalu::populate_ghost_comm_procs( bulk_, *(oversetManager_.oversetGhosting_), oversetManager_.ghostCommProcs_); #if 1 sierra::nalu::NaluEnv::self().naluOutputP0() << "TIOGA: Overset algorithm will ghost " << global[0] << " elements" << std::endl; #endif } #if 1 else { sierra::nalu::NaluEnv::self().naluOutputP0() << "TIOGA: Overset ghosting unchanged for this timestep" << std::endl; } #endif // Communicate coordinates field when populating oversetInfoVec if (oversetManager_.oversetGhosting_ != nullptr) { VectorFieldType* coords = meta_.get_field<VectorFieldType>(stk::topology::NODE_RANK, coordsName_); std::vector<const stk::mesh::FieldBase*> fVec = {coords}; stk::mesh::communicate_field_data(*oversetManager_.oversetGhosting_, fVec); } } void TiogaSTKIface::get_receptor_info() { ScalarIntFieldType* ibf = meta_.get_field<ScalarIntFieldType>(stk::topology::NODE_RANK, "iblank"); std::vector<unsigned long> nodesToReset; // Ask TIOGA for the fringe points and their corresponding donor element // information std::vector<int> receptors; tg_.getReceptorInfo(receptors); // Process TIOGA receptors array and fill in the oversetInfoVec used for // subsequent Nalu computations. // // TIOGA returns a integer array that contains 3 entries per receptor node: // - the local node index within the tioga mesh data array // - the local mesh tag (block index) for that mesh during registration // - the STK global ID for the donor element (can be 8-byte or 4-byte) // size_t ncount = receptors.size(); stk::mesh::EntityId donorID = std::numeric_limits<stk::mesh::EntityId>::max(); #ifdef TIOGA_HAS_UINT64T // The donor ID is stored in 2 4-byte integer entries (2 + 2 = 4). See above // for description on what is returned for each receptor node. const int rec_offset = 4; #else // The donor ID is stored in a single 4-byte integer entry (2 + 1 = 3) const int rec_offset = 3; #endif for (size_t i = 0; i < ncount; i += rec_offset) { int nid = receptors[i]; // TiogaBlock node index int mtag = receptors[i + 1] - 1; // Block index #ifdef TIOGA_HAS_UINT64T std::memcpy(&donorID, &receptors[i + 2], sizeof(uint64_t)); #else donorID = receptors[i + 2]; // STK Global ID of the donor element #endif auto nodeID = blocks_[mtag]->node_id_map()[nid]; // STK Global ID of the fringe node stk::mesh::Entity node = bulk_.get_entity(stk::topology::NODE_RANK, nodeID); if (!bulk_.bucket(node).owned()) { // We have a shared node that is marked as fringe. Ensure that the owning // proc also has this marked as fringe. int ibval = *stk::mesh::field_data(*ibf, node); if (ibval > -1) { // Disagreement between owner and shared status of iblank. Communicate // to owner and other shared procs that it must be a fringe. std::vector<int> sprocs; bulk_.comm_shared_procs(bulk_.entity_key(node), sprocs); for (auto jproc : sprocs) { if (jproc == bulk_.parallel_rank()) continue; nodesToReset.push_back(jproc); nodesToReset.push_back(nodeID); nodesToReset.push_back(donorID); } } } // Stash the IDs for populating OversetInfo donorIDs_.push_back(donorID); receptorIDs_.push_back(nodeID); } int numLocal = nodesToReset.size(); int iproc = bulk_.parallel_rank(); int nproc = bulk_.parallel_size(); std::vector<int> nbPerProc(nproc); MPI_Allgather( &numLocal, 1, MPI_INT, nbPerProc.data(), 1, MPI_INT, bulk_.parallel()); // Total number of entities across all procs int nTotalEntities = std::accumulate(nbPerProc.begin(), nbPerProc.end(), 0); // If no disagreements were detected then we are done here if (nTotalEntities < 1) return; #if 1 sierra::nalu::NaluEnv::self().naluOutputP0() << "TIOGA: Detected fringe/field mismatch on " << (nTotalEntities / 3) << " entities" << std::endl; #endif // Prepare data structures for reconciliation std::vector<int> offsets(nproc + 1); std::vector<unsigned long> allEntities(nTotalEntities); offsets[0] = 0; for (int i = 1; i <= nproc; ++i) { offsets[i] = offsets[i - 1] + nbPerProc[i - 1]; } MPI_Allgatherv( nodesToReset.data(), numLocal, MPI_UNSIGNED_LONG, allEntities.data(), nbPerProc.data(), offsets.data(), MPI_UNSIGNED_LONG, bulk_.parallel()); for (int i = 0; i < nTotalEntities; i += 3) { int nodeProc = allEntities[i]; stk::mesh::EntityId nodeID = allEntities[i + 1]; stk::mesh::EntityId donorID = allEntities[i + 2]; // Add the receptor donor pair to populate OversetInfo if (iproc == nodeProc) { receptorIDs_.push_back(nodeID); donorIDs_.push_back(donorID); } // Setup for ghosting stk::mesh::Entity elem = bulk_.get_entity(stk::topology::ELEM_RANK, donorID); if ( bulk_.is_valid(elem) && (bulk_.parallel_owner_rank(elem) == iproc) && (nodeProc != iproc)) { // Found the owning proc for this donor element. Request ghosting stk::mesh::EntityProc elem_proc(elem, nodeProc); elemsToGhost_.push_back(elem_proc); } } } void TiogaSTKIface::populate_overset_info() { auto& osetInfo = oversetManager_.oversetInfoVec_; int nDim = meta_.spatial_dimension(); std::vector<double> elemCoords; std::unordered_set<stk::mesh::EntityId> seenIDs; // Ensure that the oversetInfoVec has been cleared out ThrowAssert(osetInfo.size() == 0); VectorFieldType* coords = meta_.get_field<VectorFieldType>(stk::topology::NODE_RANK, coordsName_); size_t numReceptors = receptorIDs_.size(); for (size_t i = 0; i < numReceptors; i++) { stk::mesh::EntityId nodeID = receptorIDs_[i]; stk::mesh::EntityId donorID = donorIDs_[i]; stk::mesh::Entity node = bulk_.get_entity(stk::topology::NODE_RANK, nodeID); stk::mesh::Entity elem = bulk_.get_entity(stk::topology::ELEM_RANK, donorID); // Track fringe nodes that have already been processed. // // This is necessary when handling fringe-field mismatch across processors, // multiple shared procs might indicate that the owner must reset their // status. This check ensures the fringe is processed only once. auto hasIt = seenIDs.find(nodeID); if (hasIt != seenIDs.end()) continue; seenIDs.insert(nodeID); #if 1 // The donor element must have already been ghosted to the required MPI // rank, so validity check should always succeed. if (!bulk_.is_valid(elem)) throw std::runtime_error( "Invalid element encountered in overset mesh connectivity"); #endif // At this point, we have all the necessary information to create an // OversetInfo instance for this {receptor node, donor element} pair. sierra::nalu::OversetInfo* oinfo = new sierra::nalu::OversetInfo(node, nDim); osetInfo.push_back(oinfo); // Store away the coordinates for this receptor node for later use const double* xyz = stk::mesh::field_data(*coords, node); for (int i = 0; i < nDim; i++) { oinfo->nodalCoords_[i] = xyz[i]; } const stk::topology elemTopo = bulk_.bucket(elem).topology(); const stk::mesh::Entity* enodes = bulk_.begin_nodes(elem); sierra::nalu::MasterElement* meSCS = sierra::nalu::MasterElementRepo::get_surface_master_element_on_host( elemTopo); int num_nodes = bulk_.num_nodes(elem); elemCoords.resize(nDim * num_nodes); for (int ni = 0; ni < num_nodes; ++ni) { stk::mesh::Entity enode = enodes[ni]; const double* xyz = stk::mesh::field_data(*coords, enode); for (int j = 0; j < nDim; j++) { const int offset = j * num_nodes + ni; elemCoords[offset] = xyz[j]; } } const double nearestDistance = meSCS->isInElement( elemCoords.data(), oinfo->nodalCoords_.data(), oinfo->isoParCoords_.data()); #if 0 if (nearestDistance > (1.0 + 1.0e-8)) sierra::nalu::NaluEnv::self().naluOutput() << "TIOGA WARNING: In pair (" << nodeID << ", " << donorID << "): " << "iso-parametric distance is greater than 1.0: " << nearestDistance << std::endl; #endif oinfo->owningElement_ = elem; oinfo->meSCS_ = meSCS; oinfo->bestX_ = nearestDistance; oinfo->elemIsGhosted_ = bulk_.bucket(elem).owned() ? 0 : 1; } #if 1 // Debugging information size_t numFringeLocal = osetInfo.size(); size_t numFringeGlobal = 0; stk::all_reduce_sum(bulk_.parallel(), &numFringeLocal, &numFringeGlobal, 1); sierra::nalu::NaluEnv::self().naluOutputP0() << "TIOGA: Num. receptor nodes = " << numFringeGlobal << std::endl; #endif } void TiogaSTKIface::overset_update_fields( const std::vector<sierra::nalu::OversetFieldData>& fields) { constexpr int row_major = 0; int nComp = 0; for (auto& f : fields) { f.field_->sync_to_host(); nComp += f.sizeRow_ * f.sizeCol_; } for (auto& tb : blocks_) tb->register_solution(tg_, fields, nComp); tg_.dataUpdate(nComp, row_major); for (auto& tb : blocks_) tb->update_solution(fields); for (auto& finfo : fields) { auto* fld = finfo.field_; fld->modify_on_host(); fld->sync_to_device(); } } int TiogaSTKIface::register_solution( const std::vector<sierra::nalu::OversetFieldData>& fields) { int nComp = 0; for (auto& f : fields) { f.field_->sync_to_host(); nComp += f.sizeRow_ * f.sizeCol_; } for (auto& tb : blocks_) tb->register_solution(tg_, fields, nComp); return nComp; } void TiogaSTKIface::update_solution( const std::vector<sierra::nalu::OversetFieldData>& fields) { for (auto& tb : blocks_) tb->update_solution(fields); for (auto& finfo : fields) { auto* fld = finfo.field_; fld->modify_on_host(); fld->sync_to_device(); } } void TiogaSTKIface::overset_update_field( stk::mesh::FieldBase* field, const int nrows, const int ncols, const bool doFinalSyncToDevice) { constexpr int row_major = 0; sierra::nalu::OversetFieldData fdata{field, nrows, ncols}; field->sync_to_host(); for (auto& tb : blocks_) tb->register_solution(tg_, fdata); tg_.dataUpdate(nrows * ncols, row_major); for (auto& tb : blocks_) tb->update_solution(fdata); field->modify_on_host(); if (doFinalSyncToDevice) field->sync_to_device(); } void TiogaSTKIface::pre_connectivity_sync() { auto* coords = meta_.get_field<VectorFieldType>(stk::topology::NODE_RANK, coordsName_); auto* dualVol = meta_.get_field<ScalarFieldType>( stk::topology::NODE_RANK, "dual_nodal_volume"); auto* elemVol = meta_.get_field<ScalarFieldType>( stk::topology::ELEMENT_RANK, "element_volume"); coords->sync_to_host(); dualVol->sync_to_host(); elemVol->sync_to_host(); // Needed for adjusting resolutions auto* tgNodalVol = meta_.get_field(stk::topology::NODE_RANK, "tioga_nodal_volume"); stk::mesh::field_copy(*dualVol, *tgNodalVol); } void TiogaSTKIface::post_connectivity_sync() { // Push iblank fields to device { auto* ibnode = meta_.get_field<ScalarIntFieldType>(stk::topology::NODE_RANK, "iblank"); auto* ibcell = meta_.get_field<ScalarIntFieldType>( stk::topology::ELEM_RANK, "iblank_cell"); ibnode->modify_on_host(); ibnode->sync_to_device(); ibcell->modify_on_host(); ibcell->sync_to_device(); } // Create device version of the fringe/hole lists for reset rows const auto& fringes = oversetManager_.fringeNodes_; const auto& holes = oversetManager_.holeNodes_; auto& ngpFringes = oversetManager_.ngpFringeNodes_; auto& ngpHoles = oversetManager_.ngpHoleNodes_; ngpFringes = sierra::nalu::OversetManager::EntityList("ngp_fringe_list", fringes.size()); ngpHoles = sierra::nalu::OversetManager::EntityList("ngp_hole_list", holes.size()); auto h_fringes = Kokkos::create_mirror_view(ngpFringes); auto h_holes = Kokkos::create_mirror_view(ngpHoles); for (size_t i = 0; i < fringes.size(); ++i) { h_fringes[i] = fringes[i]; } for (size_t i = 0; i < holes.size(); ++i) { h_holes[i] = holes[i]; } Kokkos::deep_copy(ngpFringes, h_fringes); Kokkos::deep_copy(ngpHoles, h_holes); } } // namespace tioga_nalu #endif // NALU_USES_TIOGA
35edcf3db18fe8b2efbfe49a517431c832f6efba
3e1d99ff9d80cf10f363cc6b35b69ec18fd27cce
/NppExec/src/resource.h
1545a02930b99d637f7b143ff06011cbe7bc788e
[]
no_license
d0vgan/nppexec
09a4a02981667707a4d7f33a2111f5921f054b72
796f643e9e7fdac7f21c8f6f72350cb3b599a89a
refs/heads/master
2023-08-17T16:28:59.853598
2023-08-14T15:44:28
2023-08-14T15:44:28
124,396,499
113
27
null
2023-09-13T10:04:21
2018-03-08T13:36:30
C++
UTF-8
C
false
false
11,217
h
resource.h
#ifndef IDC_STATIC #define IDC_STATIC (-1) #endif #define IDD_DOEXEC 101 #define IDD_CONSOLE 102 #define IDD_SCRIPTNAME 103 #define IDD_HELP_ABOUT 104 #define IDD_CONSOLE_FILTER 106 #define IDD_CONSOLE_OUTPUTFILTER 107 #define IDD_CONSOLE_REPLACEFILTER 108 #define IDD_CONSOLE_HIGHLIGHTFILTER 109 #define IDD_ADVANCEDOPTIONS 111 #define IDD_INPUTBOX 112 #define IDD_CONSOLE_ENCODING 113 #define IDI_CONSOLEICON 121 #define IDI_CONSOLEICONDARK 122 #define IDI_CONSOLEBITMAP 123 #define IDC_ED_CMDLINE 1001 #define IDC_RE_CONSOLE 1002 #define IDSAVE 1003 #define IDC_CB_SCRIPT 1004 #define IDC_CB_SCRIPTNAME 1005 #define IDC_BT_DELETE 1006 #define IDC_ED_INFO 1007 #define IDC_CH_FILTER_ENABLE 1008 #define IDC_ST_FILTER_INCLUDE 1009 #define IDC_ST_FILTER_EXCLUDE 1010 #define IDC_ST_FILTER_HIGHLIGHT 1011 #define IDC_CH_EXCLUDE_DUPEMPTY 1012 #define IDC_CH_EXCLUDE_ALLEMPTY 1013 #define IDC_ST_HELP_MASK 1016 #define IDC_ST_HELP_HIGHLIGHT 1017 #define IDC_RED 1018 #define IDC_GREEN 1019 #define IDC_BLUE 1020 #define IDC_ITALIC 1021 #define IDC_BOLD 1022 #define IDC_UNDERLINED 1023 #define IDC_BT_DONATE 1025 #define IDC_ST_HOME_ADDR 1026 #define IDC_CH_INCLUDE1 1031 #define IDC_CH_INCLUDE2 1032 #define IDC_CH_INCLUDE3 1033 #define IDC_CH_INCLUDE4 1034 #define IDC_CH_INCLUDE5 1035 #define IDC_CH_EXCLUDE1 1041 #define IDC_CH_EXCLUDE2 1042 #define IDC_CH_EXCLUDE3 1043 #define IDC_CH_EXCLUDE4 1044 #define IDC_CH_EXCLUDE5 1045 #define IDC_CB_INCLUDE1 1051 #define IDC_CB_INCLUDE2 1052 #define IDC_CB_INCLUDE3 1053 #define IDC_CB_INCLUDE4 1054 #define IDC_CB_INCLUDE5 1055 #define IDC_CB_EXCLUDE1 1061 #define IDC_CB_EXCLUDE2 1062 #define IDC_CB_EXCLUDE3 1063 #define IDC_CB_EXCLUDE4 1064 #define IDC_CB_EXCLUDE5 1065 #define IDC_CH_HIGHLIGHT1 1071 #define IDC_CH_HIGHLIGHT2 1072 #define IDC_CH_HIGHLIGHT3 1073 #define IDC_CH_HIGHLIGHT4 1074 #define IDC_CH_HIGHLIGHT5 1075 #define IDC_CH_HIGHLIGHT6 1076 #define IDC_CH_HIGHLIGHT7 1077 #define IDC_CH_HIGHLIGHT8 1078 #define IDC_CH_HIGHLIGHT9 1079 #define IDC_CH_HIGHLIGHT10 1080 #define IDC_CB_HIGHLIGHT1 1081 #define IDC_CB_HIGHLIGHT2 1082 #define IDC_CB_HIGHLIGHT3 1083 #define IDC_CB_HIGHLIGHT4 1084 #define IDC_CB_HIGHLIGHT5 1085 #define IDC_CB_HIGHLIGHT6 1086 #define IDC_CB_HIGHLIGHT7 1087 #define IDC_CB_HIGHLIGHT8 1088 #define IDC_CB_HIGHLIGHT9 1089 #define IDC_CB_HIGHLIGHT10 1090 #define IDC_HIGHLIGHT_COLOR1 1091 #define IDC_HIGHLIGHT_COLOR2 1092 #define IDC_HIGHLIGHT_COLOR3 1093 #define IDC_HIGHLIGHT_COLOR4 1094 #define IDC_HIGHLIGHT_COLOR5 1095 #define IDC_HIGHLIGHT_COLOR6 1096 #define IDC_HIGHLIGHT_COLOR7 1097 #define IDC_HIGHLIGHT_COLOR8 1098 #define IDC_HIGHLIGHT_COLOR9 1099 #define IDC_HIGHLIGHT_COLOR10 1100 #define IDC_CH_HIGHLIGHT_U1 1121 #define IDC_CH_HIGHLIGHT_U2 1122 #define IDC_CH_HIGHLIGHT_U3 1123 #define IDC_CH_HIGHLIGHT_U4 1124 #define IDC_CH_HIGHLIGHT_U5 1125 #define IDC_CH_HIGHLIGHT_U6 1126 #define IDC_CH_HIGHLIGHT_U7 1127 #define IDC_CH_HIGHLIGHT_U8 1128 #define IDC_CH_HIGHLIGHT_U9 1129 #define IDC_CH_HIGHLIGHT_U10 1130 #define IDC_CH_HIGHLIGHT_B1 1131 #define IDC_CH_HIGHLIGHT_B2 1132 #define IDC_CH_HIGHLIGHT_B3 1133 #define IDC_CH_HIGHLIGHT_B4 1134 #define IDC_CH_HIGHLIGHT_B5 1135 #define IDC_CH_HIGHLIGHT_B6 1136 #define IDC_CH_HIGHLIGHT_B7 1137 #define IDC_CH_HIGHLIGHT_B8 1138 #define IDC_CH_HIGHLIGHT_B9 1139 #define IDC_CH_HIGHLIGHT_B10 1140 #define IDC_CH_HIGHLIGHT_I1 1141 #define IDC_CH_HIGHLIGHT_I2 1142 #define IDC_CH_HIGHLIGHT_I3 1143 #define IDC_CH_HIGHLIGHT_I4 1144 #define IDC_CH_HIGHLIGHT_I5 1145 #define IDC_CH_HIGHLIGHT_I6 1146 #define IDC_CH_HIGHLIGHT_I7 1147 #define IDC_CH_HIGHLIGHT_I8 1148 #define IDC_CH_HIGHLIGHT_I9 1149 #define IDC_CH_HIGHLIGHT_I10 1150 #define IDC_ED_FIND 1151 #define IDC_CH_CASE 1152 #define IDC_BT_FINDCLOSE 1153 #define IDC_CH_WORDWRAP 1154 #define IDC_CH_HIDETOGGLED 1155 #define IDC_CH_TABASCHAR 1156 #define IDC_CH_RPLCFILTER_ENABLE 1200 #define IDC_CH_EXCLUDE_EMPTYRSLT 1201 #define IDC_ST_FILTER_RPLC1 1211 #define IDC_ST_FILTER_RPLC2 1212 #define IDC_ST_FILTER_RPLC3 1213 #define IDC_ST_FILTER_RPLC4 1214 #define IDC_CH_RPLC1 1221 #define IDC_CH_RPLC2 1222 #define IDC_CH_RPLC3 1223 #define IDC_CH_RPLC4 1224 #define IDC_ST_RFIND1 1231 #define IDC_ST_RFIND2 1232 #define IDC_ST_RFIND3 1233 #define IDC_ST_RFIND4 1234 #define IDC_CB_RFIND1 1241 #define IDC_CB_RFIND2 1242 #define IDC_CB_RFIND3 1243 #define IDC_CB_RFIND4 1244 #define IDC_CH_RCASE1 1251 #define IDC_CH_RCASE2 1252 #define IDC_CH_RCASE3 1253 #define IDC_CH_RCASE4 1254 #define IDC_ST_RRPLC1 1261 #define IDC_ST_RRPLC2 1262 #define IDC_ST_RRPLC3 1263 #define IDC_ST_RRPLC4 1264 #define IDC_CB_RRPLC1 1271 #define IDC_CB_RRPLC2 1272 #define IDC_CB_RRPLC3 1273 #define IDC_CB_RRPLC4 1274 #define IDC_GB_MENUITEMS 1301 #define IDC_LB_MENUITEMS 1302 #define IDC_BT_MOVEUP 1303 #define IDC_BT_MOVEDOWN 1304 #define IDC_GB_MENUITEM 1305 #define IDC_ST_ITEMSCRIPT 1306 #define IDC_CB_ITEMSCRIPT 1307 #define IDC_ST_ITEMNAME 1308 #define IDC_ED_ITEMNAME 1309 #define IDC_BT_ITEMNEW 1310 #define IDC_BT_ITEMDELETE 1311 #define IDC_CH_MACROS_SUBMENU 1312 #define IDC_ST_MENUITEMSHINT 1313 #define IDC_GB_ADVANCEDOPTIONS 1321 #define IDC_ST_OPT_SCRIPTNPPSTART 1322 #define IDC_CB_OPT_SCRIPTNPPSTART 1323 #define IDC_ST_OPT_SCRIPTNPPEXIT 1324 #define IDC_CB_OPT_SCRIPTNPPEXIT 1325 #define IDC_GB_OPT_OPTIONS 1326 #define IDC_ST_OPT_HOTKEY 1327 #define IDC_CB_OPT_HOTKEY 1328 #define IDC_ST_OPT_TOOLBARBTN 1329 #define IDC_CB_OPT_TOOLBARBTN 1330 #define IDC_GB_OPT_CONSOLE 1331 #define IDC_ST_OPT_CONVISIBLE 1332 #define IDC_CB_OPT_CONVISIBLE 1333 #define IDC_ST_OPT_SHOWHELP 1334 #define IDC_CB_OPT_SHOWHELP 1335 #define IDC_ST_OPT_SAVECMDHST 1336 #define IDC_CB_OPT_SAVECMDHST 1337 #define IDC_ST_OPT_COMMENTDELIM 1338 #define IDC_ED_OPT_COMMENTDELIM 1339 #define IDC_ST_OPT_TEXTCOLORNORM 1340 #define IDC_ED_OPT_TEXTCOLORNORM 1341 #define IDC_ST_OPT_TEXTCOLORERR 1342 #define IDC_ED_OPT_TEXTCOLORERR 1343 #define IDC_ST_OPT_TEXTCOLORMSG 1344 #define IDC_ED_OPT_TEXTCOLORMSG 1345 #define IDC_ST_OPT_BKCOLOR 1346 #define IDC_ED_OPT_BKCOLOR 1347 #define IDC_CH_OPT_USEEDITORCOLORS_CONSOLE 1348 #define IDC_CH_OPT_USEEDITORCOLORS_EXECDLG 1349 #define IDC_ST_VARMESSAGE 1380 #define IDC_ST_VARNAME 1381 #define IDC_CB_VARVALUE 1382 #define IDC_BT_KILL 1386 #define IDC_RB_OUTPUT_ANSI 1390 #define IDC_RB_OUTPUT_OEM 1391 #define IDC_RB_OUTPUT_UTF8 1392 #define IDC_RB_INPUT_ANSI 1395 #define IDC_RB_INPUT_OEM 1396 #define IDC_RB_INPUT_UTF8 1397 #define IDC_CH_INPUT_AS_OUTPUT 1400
d6eba30d632910d81f44e5b59d0f795b1dc00f82
ce99bd11ca505967277f4689c621479c1987698e
/include/os_extension.h
b9b6f07c7a98e07117cb982c4292951dd553dedb
[]
no_license
n64decomp/007
5951258890f15431f273e1503674c5e0402c66e0
c46751089ddc18b12ef7a45b6a3e03de2054c422
refs/heads/master
2022-11-08T23:34:54.021033
2022-10-29T14:41:01
2022-10-29T14:41:01
241,212,109
359
48
null
2020-11-21T23:30:31
2020-02-17T21:31:00
C
UTF-8
C
false
false
803
h
os_extension.h
#ifndef _OS_EXTENSION_H_ #define _OS_EXTENSION_H_ /* ******************************************************************************** */ // controller /* ******************************************************************************** */ #define ANY_BUTTON 0xFFFF /* ******************************************************************************** */ // audio /* ******************************************************************************** */ #define AL_USEC_PER_FRAME_60FPS 16000 #define AL_USEC_PER_FRAME_30FPS 33000 // Used while iterating during AL_SNDP_PLAY_EVT; // Seems to be used to flag visited ALEvents. #define AL_UNKOWN_3 3 // Maybe: call to alSynAllocVoice failed #define AL_UNKOWN_4 4 // Maybe: currently initializing state? #define AL_UNKOWN_5 5 #endif
5502909e30e8cf28d5cef6e5e3fc980c73b08cf1
9de0cec678bc4a3bec2b4adabef9f39ff5b4afac
/PWGJE/macros/AddTaskJetBackgroundSubtract.C
1a15bfdc5d9886591920120b36d02962fe9bc71e
[]
permissive
alisw/AliPhysics
91bf1bd01ab2af656a25ff10b25e618a63667d3e
5df28b2b415e78e81273b0d9bf5c1b99feda3348
refs/heads/master
2023-08-31T20:41:44.927176
2023-08-31T14:51:12
2023-08-31T14:51:12
61,661,378
129
1,150
BSD-3-Clause
2023-09-14T18:48:45
2016-06-21T19:31:29
C++
UTF-8
C
false
false
1,682
c
AddTaskJetBackgroundSubtract.C
AliAnalysisTaskJetBackgroundSubtract *AddTaskJetBackgroundSubtract(TString sJetBranches,Int_t iSubtraction = 1,char* cToReplace = "B0",char* cReplaceMask = "B%d", char* cSuffix = ""){ //get the current analysis manager AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager(); if (!mgr) { Error("AddTask_obusch_jets", "No analysis manager found."); return 0; } //========= Add task to the ANALYSIS manager ===== // TOkenize... TObjArray *objArr = sJetBranches.Tokenize(" "); TString cAdd; cAdd += Form(cReplaceMask,iSubtraction); if(cSuffix!="") cAdd += Form("_%s",cSuffix); AliAnalysisTaskJetBackgroundSubtract *task = new AliAnalysisTaskJetBackgroundSubtract(Form("JetSubtract_%s",cAdd.Data())); for(int iJB = 0;iJB<objArr->GetEntries();iJB++){ TObjString *ostr = (TObjString*)objArr->At(iJB); task->AddJetBranch(ostr->GetString().Data()); } task->SetToReplace(cToReplace); task->SetReplacementMask(cReplaceMask); task->SetSubtractionMethod(iSubtraction); mgr->AddTask(task); //================================================ // data containers //================================================ // find input container AliAnalysisDataContainer *cinput = mgr->GetCommonInputContainer(); AliAnalysisDataContainer *coutput = mgr->CreateContainer( Form("pwgjeJetSubtract_%s",cAdd.Data()), TList::Class(), AliAnalysisManager::kOutputContainer, Form("%s:PWGJE_JetSubtract_%s",AliAnalysisManager::GetCommonFileName(),cAdd.Data())); mgr->ConnectInput(task,0,cinput ); mgr->ConnectOutput(task,1,coutput); return task; }
c0429418ec144f65c82c08b3462111aa06bed3f0
8551168c7b71c31eebad0f9b0c71eebbcc743000
/src/include/game/game_097aa0.h
875220ad5c48a94b982495dcc8f65febd93dc06d
[ "MIT" ]
permissive
n64decomp/perfect_dark
0db80e8ecba74741b959962e55c835a91c920f44
0235a971d6fb1a0d4421856d5a65aa8067bd4658
refs/heads/master
2023-08-31T04:27:53.864767
2023-08-29T11:36:58
2023-08-29T11:36:58
241,214,589
452
47
MIT
2023-08-21T08:53:40
2020-02-17T21:46:45
C
UTF-8
C
false
false
270
h
game_097aa0.h
#ifndef _IN_GAME_GAME_097AA0_H #define _IN_GAME_GAME_097AA0_H #include <ultra64.h> #include "data.h" #include "types.h" f32 func0f097aa0(f32 arg0); void func0f097b40(f32 *a, f32 *b, f32 *dst); void func0f097b64(f32 *param_1, f32 *param_2, f32 scale, f32 *dst); #endif
0cbfcdff733f0ad4725da3ec1b20992d4310da30
03666e5f961946fc1a0ac67781ac1425562ef0d7
/src/tools/data/datagen/lineout_test.C
aeb4360c6df53b80107cc3e1e21b8a9e6a68a02b
[ "BSD-3-Clause", "LicenseRef-scancode-unknown-license-reference" ]
permissive
visit-dav/visit
e9f81b4d4b9b9930a0db9d5282cd1bcabf465e2e
601ae46e0bef2e18425b482a755d03490ade0493
refs/heads/develop
2023-09-06T08:19:38.397058
2023-09-05T21:29:32
2023-09-05T21:29:32
165,565,988
335
120
BSD-3-Clause
2023-09-14T00:53:37
2019-01-13T23:27:26
C
UTF-8
C
false
false
4,034
c
lineout_test.C
// Copyright (c) Lawrence Livermore National Security, LLC and other VisIt // Project developers. See the top-level LICENSE file for dates and other // details. No copyright assignment is required to contribute to VisIt. #include <math.h> #include <stdlib.h> #include <string.h> #include <silo.h> // suppress the following since silo uses char * in its API #if defined(__clang__) # pragma clang diagnostic ignored "-Wwritable-strings" #elif defined(__GNUC__) # pragma GCC diagnostic ignored "-Wwrite-strings" #endif int main(int argc, char **argv) { DBfile *dbfile; int N = 21; int driver = DB_PDB; int i = 1; while (i < argc) { if (strcmp(argv[i], "DB_HDF5") == 0) driver = DB_HDF5; else if (strcmp(argv[i], "DB_PDB") == 0) driver = DB_PDB; else if (strcmp(argv[i], "-n") == 0) { i++; N = atoi(argv[i]); if (N < 0 || N > 10000) { fprintf(stderr,"size, %d, too large\n", N); exit(-1); } if (N % 2 != 1) { fprintf(stderr,"size, %d, should be an odd number\n", N); exit(-1); } } else fprintf(stderr,"Uncrecognized driver name \"%s\"\n", argv[i]); i++; } float x[] = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0}; float y[] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0}; float *coords[2] = {x, y}; dbfile = DBCreate("lineout_test.silo", DB_CLOBBER, DB_LOCAL, "2D grid with stair-step and linear fields", driver); char *coordnames[2]; coordnames[0] = "xcoords"; coordnames[1] = "ycoords"; int zonelist[] = {0,1,7,6, 1,2,8,7, 2,3,9,8, 3,4,10,9, 4,5,11,10}; int zshapetype = DB_ZONETYPE_QUAD; int zshapesize = 4; int zshapecnt = 5; DBPutZonelist2(dbfile, "zl2d", 5, 2, zonelist, sizeof(zonelist)/sizeof(zonelist[0]), 0, 0, 0, &zshapetype, &zshapesize, &zshapecnt, 1, NULL); DBPutUcdmesh(dbfile, "mesh", 2, coordnames, coords, 12, 5, "zl2d", NULL, DB_FLOAT, NULL); float zc_var[] = {0.5, 1.5, 2.5, 3.5, 4.5}; DBPutUcdvar1(dbfile, "zonal_var", "mesh", zc_var, 5, NULL, 0, DB_FLOAT, DB_ZONECENT, NULL); float nc_var[] = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0}; DBPutUcdvar1(dbfile, "nodal_var", "mesh", nc_var, 12, NULL, 0, DB_FLOAT, DB_NODECENT, NULL); float x1[] = {-1.5, -.5, 0.5, 1.5, -1.5, -.5, 0.5, 1.5, -1.5, -.5, 0.5, 1.5, -1.5, -.5, 0.5, 1.5}; float y1[] = {-1.5, -1.5, -1.5, -1.5, -0.5, -0.5, -0.5, -0.5, 0.5, 0.5, 0.5, 0.5, 1.5, 1.5, 1.5, 1.5}; int zonelist2[] = {0,1,5,4, 1,2,6,5, 2,3,7,6, 4,5,9,8, 5,6,10,9, 6,7,11,10, 8,9,13,12, 9,10,14,13,10,11,15,14}; zshapecnt = 9; DBPutZonelist2(dbfile, "zl2d2", 9, 2, zonelist2, sizeof(zonelist2)/sizeof(zonelist2[0]), 0, 0, 0, &zshapetype, &zshapesize, &zshapecnt, 1, NULL); coords[0] = x1; coords[1] = y1; DBPutUcdmesh(dbfile, "mesh2", 2, coordnames, coords, 16, 9, "zl2d2", NULL, DB_FLOAT, NULL); float zc_var2[] = {1.5, 0, -1.5, 0, 0, 0, -1.5, 0, 1.5}; DBPutUcdvar1(dbfile, "zonal_var2", "mesh2", zc_var2, 9, NULL, 0, DB_FLOAT, DB_ZONECENT, NULL); // This is designed to yield a perfect quadratic along the diagonal // y=x and y=-x lineouts such that value of nc_var2 is equal to distance // from origin (0,0), squared. A resulting lineout *should* look like a // perfect quadratic curve. float a = (1.5*1.5 + 1.5*1.5); float b = (0.5*0.5 + 1.5*1.5); float c = (0.5*0.5 + 0.5*0.5); float nc_var2[] = {-a, -b, b, a, -b, -c, c, b, b, c, -c, -b, a, b, -b, -a}; DBPutUcdvar1(dbfile, "nodal_var2", "mesh2", nc_var2, 16, NULL, 0, DB_FLOAT, DB_NODECENT, NULL); DBClose(dbfile); }
cffcdb4bc8aaf97da651563558c3e7dad42e451f
aa5c1a530f95d629e686ac9124caf1a49a9f23e9
/runtime/src/iree/builtins/ukernel/tools/mmt4d_test.c
548cf1b1cb79237922636e3251176fc708c5fde3
[ "Apache-2.0", "LLVM-exception", "LicenseRef-scancode-unknown-license-reference" ]
permissive
openxla/iree
eacf5b239559e1d3b40c38039ac4c26315b523f7
13ef677e556d0a1d154e45b052fe016256057f65
refs/heads/main
2023-09-06T01:19:49.598662
2023-09-04T07:01:30
2023-09-04T07:01:30
208,145,128
387
110
Apache-2.0
2023-09-14T20:48:00
2019-09-12T20:57:39
C++
UTF-8
C
false
false
18,093
c
mmt4d_test.c
// Copyright 2022 The IREE Authors // // Licensed under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception #include <iree/builtins/ukernel/common.h> #include "iree/base/api.h" #include "iree/base/internal/math.h" #include "iree/builtins/ukernel/api.h" #include "iree/builtins/ukernel/mmt4d_internal.h" #include "iree/builtins/ukernel/tools/test.h" #include "iree/builtins/ukernel/tools/util.h" static void iree_mmt4d_reference_innerloop_f32f32f32( float* out_ptr, const float* lhs_ptr, const float* rhs_ptr, const iree_uk_mmt4d_params_t* params) { float acc = params->flags & IREE_UK_FLAG_MMT4D_ACCUMULATE ? *out_ptr : 0.f; for (iree_uk_index_t k = 0; k < params->K; ++k) { for (iree_uk_index_t k0 = 0; k0 < params->K0; ++k0) { float lhs_f32 = lhs_ptr[k * params->M0 * params->K0 + k0]; float rhs_f32 = rhs_ptr[k * params->N0 * params->K0 + k0]; acc += lhs_f32 * rhs_f32; } } *out_ptr = acc; } static void iree_mmt4d_reference_innerloop_f16f16f32( float* out_ptr, const uint16_t* lhs_ptr, const uint16_t* rhs_ptr, const iree_uk_mmt4d_params_t* params) { float acc = params->flags & IREE_UK_FLAG_MMT4D_ACCUMULATE ? *out_ptr : 0.f; for (iree_uk_index_t k = 0; k < params->K; ++k) { for (iree_uk_index_t k0 = 0; k0 < params->K0; ++k0) { float lhs_f32 = iree_math_f16_to_f32(lhs_ptr[k * params->M0 * params->K0 + k0]); float rhs_f32 = iree_math_f16_to_f32(rhs_ptr[k * params->N0 * params->K0 + k0]); acc += lhs_f32 * rhs_f32; } } *out_ptr = acc; } static void iree_mmt4d_reference_innerloop_f16f16f16_noskipround( uint16_t* out_ptr, const uint16_t* lhs_ptr, const uint16_t* rhs_ptr, const iree_uk_mmt4d_params_t* params) { uint16_t acc = params->flags & IREE_UK_FLAG_MMT4D_ACCUMULATE ? *out_ptr : 0; for (iree_uk_index_t k = 0; k < params->K; ++k) { for (iree_uk_index_t k0 = 0; k0 < params->K0; ++k0) { float lhs_f32 = iree_math_f16_to_f32(lhs_ptr[k * params->M0 * params->K0 + k0]); float rhs_f32 = iree_math_f16_to_f32(rhs_ptr[k * params->N0 * params->K0 + k0]); float acc_f32 = iree_math_f16_to_f32(acc); acc = iree_math_f32_to_f16(acc_f32 + lhs_f32 * rhs_f32); } } *out_ptr = acc; } static void iree_mmt4d_reference_innerloop_f16f16f16_skipround( uint16_t* out_ptr, const uint16_t* lhs_ptr, const uint16_t* rhs_ptr, const iree_uk_mmt4d_params_t* params) { float acc_f32 = params->flags & IREE_UK_FLAG_MMT4D_ACCUMULATE ? iree_math_f16_to_f32(*out_ptr) : 0.f; for (iree_uk_index_t k = 0; k < params->K; ++k) { for (iree_uk_index_t k0 = 0; k0 < params->K0; ++k0) { float lhs_f32 = iree_math_f16_to_f32(lhs_ptr[k * params->M0 * params->K0 + k0]); float rhs_f32 = iree_math_f16_to_f32(rhs_ptr[k * params->N0 * params->K0 + k0]); acc_f32 += lhs_f32 * rhs_f32; } } *out_ptr = iree_math_f32_to_f16(acc_f32); } static void iree_mmt4d_reference_innerloop_f16f16f16( uint16_t* out_ptr, const uint16_t* lhs_ptr, const uint16_t* rhs_ptr, const iree_uk_mmt4d_params_t* params) { if (params->flags & IREE_UK_FLAG_MMT4D_SKIP_INTERMEDIATE_ROUNDINGS) { iree_mmt4d_reference_innerloop_f16f16f16_skipround(out_ptr, lhs_ptr, rhs_ptr, params); } else { iree_mmt4d_reference_innerloop_f16f16f16_noskipround(out_ptr, lhs_ptr, rhs_ptr, params); } } static void iree_mmt4d_reference_innerloop_bf16bf16f32( float* out_ptr, const uint16_t* lhs_ptr, const uint16_t* rhs_ptr, const iree_uk_mmt4d_params_t* params) { float acc = params->flags & IREE_UK_FLAG_MMT4D_ACCUMULATE ? *out_ptr : 0.f; for (iree_uk_index_t k = 0; k < params->K; ++k) { for (iree_uk_index_t k0 = 0; k0 < params->K0; ++k0) { float lhs_f32 = iree_math_bf16_to_f32(lhs_ptr[k * params->M0 * params->K0 + k0]); float rhs_f32 = iree_math_bf16_to_f32(rhs_ptr[k * params->N0 * params->K0 + k0]); acc += lhs_f32 * rhs_f32; } } *out_ptr = acc; } static void iree_mmt4d_reference_innerloop_bf16bf16bf16( uint16_t* out_ptr, const uint16_t* lhs_ptr, const uint16_t* rhs_ptr, const iree_uk_mmt4d_params_t* params) { uint16_t acc = params->flags & IREE_UK_FLAG_MMT4D_ACCUMULATE ? *out_ptr : 0; for (iree_uk_index_t k = 0; k < params->K; ++k) { for (iree_uk_index_t k0 = 0; k0 < params->K0; ++k0) { float lhs_f32 = iree_math_bf16_to_f32(lhs_ptr[k * params->M0 * params->K0 + k0]); float rhs_f32 = iree_math_bf16_to_f32(rhs_ptr[k * params->N0 * params->K0 + k0]); float acc_f32 = iree_math_bf16_to_f32(acc); acc = iree_math_f32_to_bf16(acc_f32 + lhs_f32 * rhs_f32); } } *out_ptr = acc; } static void iree_mmt4d_reference_innerloop_i8i8i32( int32_t* out_ptr, const int8_t* lhs_ptr, const int8_t* rhs_ptr, const iree_uk_mmt4d_params_t* params) { int32_t acc = params->flags & IREE_UK_FLAG_MMT4D_ACCUMULATE ? *out_ptr : 0; for (iree_uk_index_t k = 0; k < params->K; ++k) { for (iree_uk_index_t k0 = 0; k0 < params->K0; ++k0) { int32_t lhs_i32 = lhs_ptr[k * params->M0 * params->K0 + k0]; int32_t rhs_i32 = rhs_ptr[k * params->N0 * params->K0 + k0]; acc += lhs_i32 * rhs_i32; } } *out_ptr = acc; } static void iree_mmt4d_reference(const iree_uk_mmt4d_params_t* params) { iree_uk_mmt4d_type_t mmt4d_type = iree_uk_mmt4d_type(params->flags); iree_uk_index_t lhs_elem_size = iree_uk_type_size(iree_uk_mmt4d_lhs_type(mmt4d_type)); iree_uk_index_t rhs_elem_size = iree_uk_type_size(iree_uk_mmt4d_rhs_type(mmt4d_type)); iree_uk_index_t out_elem_size = iree_uk_type_size(iree_uk_mmt4d_out_type(mmt4d_type)); for (iree_uk_index_t i = 0; i < params->M; ++i) { for (iree_uk_index_t j = 0; j < params->N; ++j) { void* out_tile_ptr = ((char*)params->out_buffer) + (params->out_offset + i * params->out_stride0 + j * params->M0 * params->N0) * out_elem_size; const void* lhs_panel_ptr = ((const char*)params->lhs_buffer) + (params->lhs_offset + i * params->lhs_stride0) * lhs_elem_size; const void* rhs_panel_ptr = ((const char*)params->rhs_buffer) + (params->rhs_offset + j * params->rhs_stride0) * rhs_elem_size; for (iree_uk_index_t i0 = 0; i0 < params->M0; ++i0) { for (iree_uk_index_t j0 = 0; j0 < params->N0; ++j0) { void* out_ptr = ((char*)out_tile_ptr) + (i0 * params->N0 + j0) * out_elem_size; const void* lhs_ptr = ((char*)lhs_panel_ptr) + i0 * params->K0 * lhs_elem_size; const void* rhs_ptr = ((char*)rhs_panel_ptr) + j0 * params->K0 * rhs_elem_size; switch (params->flags & IREE_UK_FLAG_MMT4D_TYPE_MASK) { case IREE_UK_FLAG_MMT4D_TYPE_F32F32F32: iree_mmt4d_reference_innerloop_f32f32f32( (float*)out_ptr, (const float*)lhs_ptr, (const float*)rhs_ptr, params); break; case IREE_UK_FLAG_MMT4D_TYPE_F16F16F32: iree_mmt4d_reference_innerloop_f16f16f32( (float*)out_ptr, (const uint16_t*)lhs_ptr, (const uint16_t*)rhs_ptr, params); break; case IREE_UK_FLAG_MMT4D_TYPE_F16F16F16: iree_mmt4d_reference_innerloop_f16f16f16( (uint16_t*)out_ptr, (const uint16_t*)lhs_ptr, (const uint16_t*)rhs_ptr, params); break; case IREE_UK_FLAG_MMT4D_TYPE_BF16BF16F32: iree_mmt4d_reference_innerloop_bf16bf16f32( (float*)out_ptr, (const uint16_t*)lhs_ptr, (const uint16_t*)rhs_ptr, params); break; case IREE_UK_FLAG_MMT4D_TYPE_BF16BF16BF16: iree_mmt4d_reference_innerloop_bf16bf16bf16( (uint16_t*)out_ptr, (const uint16_t*)lhs_ptr, (const uint16_t*)rhs_ptr, params); break; case IREE_UK_FLAG_MMT4D_TYPE_I8I8I32: iree_mmt4d_reference_innerloop_i8i8i32( (int32_t*)out_ptr, (const int8_t*)lhs_ptr, (const int8_t*)rhs_ptr, params); break; default: IREE_UK_ASSERT(false && "unhandled type"); } out_ptr = ((char*)out_ptr) + out_elem_size; } } } } } static void iree_uk_test_mmt4d_for_shape_params( iree_uk_test_t* test, const iree_uk_mmt4d_params_t* src_params) { iree_uk_mmt4d_params_t params; memcpy(&params, src_params, sizeof params); // Populate strides first - we need them below to compute buffer lengths. // Randomly make strides either tight or not to exercise all cases. iree_uk_random_engine_t* engine = iree_uk_test_random_engine(test); params.lhs_stride0 = params.K * params.M0 * params.K0 + iree_uk_random_engine_get_0_1(engine); params.rhs_stride0 = params.K * params.N0 * params.K0 + iree_uk_random_engine_get_0_1(engine); params.out_stride0 = params.N * params.M0 * params.N0 + iree_uk_random_engine_get_0_1(engine); iree_uk_mmt4d_type_t mmt4d_type = iree_uk_mmt4d_type(params.flags); iree_uk_type_t lhs_type = iree_uk_mmt4d_lhs_type(mmt4d_type); iree_uk_type_t rhs_type = iree_uk_mmt4d_rhs_type(mmt4d_type); iree_uk_type_t out_type = iree_uk_mmt4d_out_type(mmt4d_type); iree_uk_index_t lhs_buffer_size = iree_uk_2d_buffer_length(lhs_type, params.M, params.lhs_stride0); iree_uk_index_t rhs_buffer_size = iree_uk_2d_buffer_length(rhs_type, params.N, params.rhs_stride0); void* lhs_buffer = malloc(lhs_buffer_size); void* rhs_buffer = malloc(rhs_buffer_size); iree_uk_write_random_buffer(lhs_buffer, lhs_buffer_size, lhs_type, engine); iree_uk_write_random_buffer(rhs_buffer, rhs_buffer_size, rhs_type, engine); params.lhs_offset = iree_uk_random_engine_get_0_65535(engine); params.rhs_offset = iree_uk_random_engine_get_0_65535(engine); params.out_offset = iree_uk_random_engine_get_0_65535(engine); params.lhs_buffer = (const char*)lhs_buffer - (params.lhs_offset * iree_uk_type_size(lhs_type)); params.rhs_buffer = (const char*)rhs_buffer - (params.rhs_offset * iree_uk_type_size(rhs_type)); iree_uk_mmt4d_params_t reference_params; memcpy(&reference_params, &params, sizeof params); iree_uk_index_t out_buffer_size = iree_uk_2d_buffer_length(out_type, params.M, params.out_stride0); void* init_out_buffer = malloc(out_buffer_size); iree_uk_write_random_buffer(init_out_buffer, out_buffer_size, out_type, engine); void* reference_out_buffer = malloc(out_buffer_size); memcpy(reference_out_buffer, init_out_buffer, out_buffer_size); reference_params.out_buffer = (char*)reference_out_buffer - (params.out_offset * iree_uk_type_size(out_type)); iree_uk_mmt4d_params_t actual_params; memcpy(&actual_params, &params, sizeof params); void* actual_out_buffer = malloc(out_buffer_size); memcpy(actual_out_buffer, init_out_buffer, out_buffer_size); actual_params.out_buffer = (char*)actual_out_buffer - (params.out_offset * iree_uk_type_size(out_type)); iree_mmt4d_reference(&reference_params); iree_uk_mmt4d(&actual_params); // For now we use exact comparisons, even for float, even though the reference // code accumulates in a different order compared to the actual code. This // relies on picking input test matrix elements so that all intermediate // values are exactly representable - i.e. small integer numerators. bool fail = memcmp(actual_out_buffer, reference_out_buffer, out_buffer_size); if (fail) { // The one thing that causes legitimate bit differences at the moment is // when we enable skipping intermediate roundings but the actual kernel does // not skip intermediate roundings, such as when falling back on a generic // code path. In that case, we retry with reference code not skipping // intermediate roundings. This currently only happens when the output type // is f16. if (out_type == IREE_UK_TYPE_FLOAT_16 && (params.flags & IREE_UK_FLAG_MMT4D_SKIP_INTERMEDIATE_ROUNDINGS)) { reference_params.flags &= ~IREE_UK_FLAG_MMT4D_SKIP_INTERMEDIATE_ROUNDINGS; memcpy(reference_out_buffer, init_out_buffer, out_buffer_size); iree_mmt4d_reference(&reference_params); fail = memcmp(actual_out_buffer, reference_out_buffer, out_buffer_size); } } if (fail) { IREE_UK_TEST_FAIL(test); } free(init_out_buffer); free(reference_out_buffer); free(actual_out_buffer); free(lhs_buffer); free(rhs_buffer); } static void iree_uk_test_mmt4d_for_tile_params(iree_uk_test_t* test, const void* src_params) { typedef struct shape_mnk_t { int m, n, k; } shape_mnk_t; const shape_mnk_t shapes[] = { // Degenerate case M==0. Vacuous. {0, 1, 1}, {0, 5, 7}, // Degenerate case N==0. Vacuous. {1, 0, 1}, {5, 0, 7}, // Degenerate case K==0. Vacuous if flags have ACCUMULATE. Zeroing the // output buffer otherwise. {1, 1, 0}, {5, 7, 0}, // Non-degenerate cases. {1, 1, 1}, {1, 1, 2}, {1, 1, 10}, {1, 1, 1000}, {2, 1, 1}, {1, 2, 1}, {2, 2, 2}, {5, 7, 13}, }; for (int i = 0; i < IREE_ARRAYSIZE(shapes); ++i) { iree_uk_mmt4d_params_t params; memcpy(&params, src_params, sizeof params); params.cpu_data = iree_uk_test_cpu_data(test); shape_mnk_t shape = shapes[i]; params.M = shape.m; params.N = shape.n; params.K = shape.k; for (int accumulate = 0; accumulate <= 1; ++accumulate) { if (accumulate) params.flags |= IREE_UK_FLAG_MMT4D_ACCUMULATE; iree_uk_test_mmt4d_for_shape_params(test, &params); } } } static void iree_uk_test_mmt4d_impl(iree_uk_uint32_t flags, int M0, int N0, int K0, const char* cpu_features, const char* code_path_suffix) { char types_str[32]; iree_uk_mmt4d_type_t mmt4d_type = iree_uk_mmt4d_type(flags); iree_uk_type_triple_str(types_str, sizeof types_str, mmt4d_type); iree_uk_mmt4d_params_t params = { .flags = flags, .M0 = M0, .N0 = N0, .K0 = K0}; char test_label_str[256]; snprintf(test_label_str, sizeof test_label_str, "types:%s tile:%dx%dx%d%s", types_str, M0, N0, K0, code_path_suffix); iree_uk_test(test_label_str, iree_uk_test_mmt4d_for_tile_params, &params, cpu_features); } static void iree_uk_test_mmt4d(iree_uk_uint32_t flags, int M0, int N0, int K0, const char* cpu_features) { iree_uk_test_mmt4d_impl(flags, M0, N0, K0, cpu_features, ""); } static void iree_uk_test_mmt4d_default_and_skip_intermediate_roundings( iree_uk_uint32_t flags, int M0, int N0, int K0, const char* cpu_features) { iree_uk_test_mmt4d_impl(flags, M0, N0, K0, cpu_features, ""); iree_uk_test_mmt4d_impl( flags | IREE_UK_FLAG_MMT4D_SKIP_INTERMEDIATE_ROUNDINGS, M0, N0, K0, cpu_features, " skipround"); } int main(int argc, char** argv) { // Generic tests, not matching any particular CPU feature. This is the place // to test weird M0, N0, K0 to ensure e.g. that we haven't unwittingly baked // in a power-of-two assumption iree_uk_test_mmt4d(IREE_UK_FLAG_MMT4D_TYPE_F32F32F32, 3, 5, 7, ""); iree_uk_test_mmt4d(IREE_UK_FLAG_MMT4D_TYPE_I8I8I32, 9, 6, 3, ""); iree_uk_test_mmt4d(IREE_UK_FLAG_MMT4D_TYPE_F16F16F32, 4, 6, 5, ""); iree_uk_test_mmt4d(IREE_UK_FLAG_MMT4D_TYPE_F16F16F16, 3, 5, 8, ""); iree_uk_test_mmt4d(IREE_UK_FLAG_MMT4D_TYPE_BF16BF16F32, 11, 4, 1, ""); iree_uk_test_mmt4d(IREE_UK_FLAG_MMT4D_TYPE_BF16BF16BF16, 2, 9, 3, ""); #if defined(IREE_ARCH_ARM_64) iree_uk_test_mmt4d(IREE_UK_FLAG_MMT4D_TYPE_F32F32F32, 8, 8, 1, ""); iree_uk_test_mmt4d(IREE_UK_FLAG_MMT4D_TYPE_F16F16F32, 8, 8, 1, ""); iree_uk_test_mmt4d(IREE_UK_FLAG_MMT4D_TYPE_F16F16F32, 8, 8, 1, "fp16fml"); iree_uk_test_mmt4d_default_and_skip_intermediate_roundings( IREE_UK_FLAG_MMT4D_TYPE_F16F16F16, 8, 8, 1, ""); iree_uk_test_mmt4d_default_and_skip_intermediate_roundings( IREE_UK_FLAG_MMT4D_TYPE_F16F16F16, 8, 8, 1, "fp16"); iree_uk_test_mmt4d(IREE_UK_FLAG_MMT4D_TYPE_BF16BF16F32, 8, 8, 4, "bf16"); iree_uk_test_mmt4d(IREE_UK_FLAG_MMT4D_TYPE_I8I8I32, 8, 8, 1, ""); iree_uk_test_mmt4d(IREE_UK_FLAG_MMT4D_TYPE_I8I8I32, 8, 8, 4, "dotprod"); iree_uk_test_mmt4d(IREE_UK_FLAG_MMT4D_TYPE_I8I8I32, 8, 8, 8, "i8mm"); #elif defined(IREE_ARCH_X86_64) iree_uk_test_mmt4d(IREE_UK_FLAG_MMT4D_TYPE_F32F32F32, 8, 4, 1, ""); // SSE iree_uk_test_mmt4d(IREE_UK_FLAG_MMT4D_TYPE_F32F32F32, 8, 8, 1, "avx2_fma"); iree_uk_test_mmt4d(IREE_UK_FLAG_MMT4D_TYPE_F32F32F32, 16, 16, 1, "avx512_base"); iree_uk_test_mmt4d(IREE_UK_FLAG_MMT4D_TYPE_F16F16F32, 8, 8, 1, "avx2_fma"); iree_uk_test_mmt4d(IREE_UK_FLAG_MMT4D_TYPE_F16F16F32, 16, 16, 1, "avx512_base"); iree_uk_test_mmt4d_default_and_skip_intermediate_roundings( IREE_UK_FLAG_MMT4D_TYPE_F16F16F16, 8, 8, 1, "avx2_fma"); iree_uk_test_mmt4d_default_and_skip_intermediate_roundings( IREE_UK_FLAG_MMT4D_TYPE_F16F16F16, 16, 16, 1, "avx512_base"); iree_uk_test_mmt4d(IREE_UK_FLAG_MMT4D_TYPE_I8I8I32, 8, 4, 2, ""); // SSE2 iree_uk_test_mmt4d(IREE_UK_FLAG_MMT4D_TYPE_I8I8I32, 8, 8, 2, "avx2_fma"); iree_uk_test_mmt4d(IREE_UK_FLAG_MMT4D_TYPE_I8I8I32, 16, 16, 2, "avx512_base"); iree_uk_test_mmt4d(IREE_UK_FLAG_MMT4D_TYPE_I8I8I32, 16, 16, 2, "avx512_vnni"); #endif // defined(IREE_ARCH_ARM_64) return iree_uk_test_exit_status(); }
b2524564a210bcd1147cd781537cd36e8843ae50
30c2631ed046d7662476b94fb7f5286c47377f60
/examples/c/reflection/nested_set_member/include/nested_set_member.h
a02259f279a0623eb6a0a034144fbe5930b88a81
[ "MIT" ]
permissive
SanderMertens/flecs
a840093340f0d1eb2bd30ec1585296f81f2aab39
41fb856c4e1162f44b59d7881ef508d64d56bf10
refs/heads/master
2023-08-24T16:21:41.790084
2023-08-24T08:38:57
2023-08-24T08:49:52
146,155,284
4,731
456
MIT
2023-09-05T16:01:58
2018-08-26T05:53:05
C
UTF-8
C
false
false
247
h
nested_set_member.h
#ifndef NESTED_SET_MEMBER_H #define NESTED_SET_MEMBER_H /* This generated file contains includes for project dependencies */ #include "nested_set_member/bake_config.h" #ifdef __cplusplus extern "C" { #endif #ifdef __cplusplus } #endif #endif
aa1f4ae74ab22402050ba35f8474430e2d939a8e
010279e2ba272d09e9d2c4e903722e5faba2cf7a
/contrib/tools/python3/src/Python/thread.c
940d8b8093ab533c5a55a8555d8d607e8282a9cd
[ "LicenseRef-scancode-python-cwi", "LicenseRef-scancode-other-copyleft", "Python-2.0", "BSD-3-Clause", "0BSD", "GPL-1.0-or-later", "LicenseRef-scancode-free-unknown", "Apache-2.0" ]
permissive
catboost/catboost
854c1a1f439a96f1ae6b48e16644be20aa04dba2
f5042e35b945aded77b23470ead62d7eacefde92
refs/heads/master
2023-09-01T12:14:14.174108
2023-09-01T10:01:01
2023-09-01T10:22:12
97,556,265
8,012
1,425
Apache-2.0
2023-09-11T03:32:32
2017-07-18T05:29:04
Python
UTF-8
C
false
false
6,396
c
thread.c
/* Thread package. This is intended to be usable independently from Python. The implementation for system foobar is in a file thread_foobar.h which is included by this file dependent on config settings. Stuff shared by all thread_*.h files is collected here. */ #include "Python.h" #include "pycore_pystate.h" // _PyInterpreterState_GET() #include "pycore_structseq.h" // _PyStructSequence_FiniType() #ifndef _POSIX_THREADS /* This means pthreads are not implemented in libc headers, hence the macro not present in unistd.h. But they still can be implemented as an external library (e.g. gnu pth in pthread emulation) */ # ifdef HAVE_PTHREAD_H # include <pthread.h> /* _POSIX_THREADS */ # endif #endif #ifndef DONT_HAVE_STDIO_H #include <stdio.h> #endif #include <stdlib.h> #ifndef _POSIX_THREADS /* Check if we're running on HP-UX and _SC_THREADS is defined. If so, then enough of the Posix threads package is implemented to support python threads. This is valid for HP-UX 11.23 running on an ia64 system. If needed, add a check of __ia64 to verify that we're running on an ia64 system instead of a pa-risc system. */ #ifdef __hpux #ifdef _SC_THREADS #define _POSIX_THREADS #endif #endif #endif /* _POSIX_THREADS */ #ifdef Py_DEBUG static int thread_debug = 0; # define dprintf(args) (void)((thread_debug & 1) && printf args) #else # define dprintf(args) #endif static int initialized; static void PyThread__init_thread(void); /* Forward */ void PyThread_init_thread(void) { #ifdef Py_DEBUG const char *p = Py_GETENV("PYTHONTHREADDEBUG"); if (p) { if (*p) thread_debug = atoi(p); else thread_debug = 1; } #endif /* Py_DEBUG */ if (initialized) return; initialized = 1; dprintf(("PyThread_init_thread called\n")); PyThread__init_thread(); } void _PyThread_debug_deprecation(void) { #ifdef Py_DEBUG if (thread_debug) { // Flush previous dprintf() logs fflush(stdout); if (PyErr_WarnEx(PyExc_DeprecationWarning, "The threading debug (PYTHONTHREADDEBUG environment " "variable) is deprecated and will be removed " "in Python 3.12", 0)) { _PyErr_WriteUnraisableMsg("at Python startup", NULL); } } #endif } #if defined(HAVE_PTHREAD_STUBS) # define PYTHREAD_NAME "pthread-stubs" # include "thread_pthread_stubs.h" #elif defined(_POSIX_THREADS) # if defined(__EMSCRIPTEN__) && !defined(__EMSCRIPTEN_PTHREADS__) # define PYTHREAD_NAME "pthread-stubs" # else # define PYTHREAD_NAME "pthread" # endif # include "thread_pthread.h" #elif defined(NT_THREADS) # define PYTHREAD_NAME "nt" # include "thread_nt.h" #else # error "Require native threads. See https://bugs.python.org/issue31370" #endif /* return the current thread stack size */ size_t PyThread_get_stacksize(void) { return _PyInterpreterState_GET()->threads.stacksize; } /* Only platforms defining a THREAD_SET_STACKSIZE() macro in thread_<platform>.h support changing the stack size. Return 0 if stack size is valid, -1 if stack size value is invalid, -2 if setting stack size is not supported. */ int PyThread_set_stacksize(size_t size) { #if defined(THREAD_SET_STACKSIZE) return THREAD_SET_STACKSIZE(size); #else return -2; #endif } /* Thread Specific Storage (TSS) API Cross-platform components of TSS API implementation. */ Py_tss_t * PyThread_tss_alloc(void) { Py_tss_t *new_key = (Py_tss_t *)PyMem_RawMalloc(sizeof(Py_tss_t)); if (new_key == NULL) { return NULL; } new_key->_is_initialized = 0; return new_key; } void PyThread_tss_free(Py_tss_t *key) { if (key != NULL) { PyThread_tss_delete(key); PyMem_RawFree((void *)key); } } int PyThread_tss_is_created(Py_tss_t *key) { assert(key != NULL); return key->_is_initialized; } PyDoc_STRVAR(threadinfo__doc__, "sys.thread_info\n\ \n\ A named tuple holding information about the thread implementation."); static PyStructSequence_Field threadinfo_fields[] = { {"name", "name of the thread implementation"}, {"lock", "name of the lock implementation"}, {"version", "name and version of the thread library"}, {0} }; static PyStructSequence_Desc threadinfo_desc = { "sys.thread_info", /* name */ threadinfo__doc__, /* doc */ threadinfo_fields, /* fields */ 3 }; static PyTypeObject ThreadInfoType; PyObject* PyThread_GetInfo(void) { PyObject *threadinfo, *value; int pos = 0; #if (defined(_POSIX_THREADS) && defined(HAVE_CONFSTR) \ && defined(_CS_GNU_LIBPTHREAD_VERSION)) char buffer[255]; int len; #endif if (ThreadInfoType.tp_name == 0) { if (PyStructSequence_InitType2(&ThreadInfoType, &threadinfo_desc) < 0) return NULL; } threadinfo = PyStructSequence_New(&ThreadInfoType); if (threadinfo == NULL) return NULL; value = PyUnicode_FromString(PYTHREAD_NAME); if (value == NULL) { Py_DECREF(threadinfo); return NULL; } PyStructSequence_SET_ITEM(threadinfo, pos++, value); #ifdef HAVE_PTHREAD_STUBS value = Py_NewRef(Py_None); #elif defined(_POSIX_THREADS) #ifdef USE_SEMAPHORES value = PyUnicode_FromString("semaphore"); #else value = PyUnicode_FromString("mutex+cond"); #endif if (value == NULL) { Py_DECREF(threadinfo); return NULL; } #else value = Py_NewRef(Py_None); #endif PyStructSequence_SET_ITEM(threadinfo, pos++, value); #if (defined(_POSIX_THREADS) && defined(HAVE_CONFSTR) \ && defined(_CS_GNU_LIBPTHREAD_VERSION)) value = NULL; len = confstr(_CS_GNU_LIBPTHREAD_VERSION, buffer, sizeof(buffer)); if (1 < len && (size_t)len < sizeof(buffer)) { value = PyUnicode_DecodeFSDefaultAndSize(buffer, len-1); if (value == NULL) PyErr_Clear(); } if (value == NULL) #endif { Py_INCREF(Py_None); value = Py_None; } PyStructSequence_SET_ITEM(threadinfo, pos++, value); return threadinfo; } void _PyThread_FiniType(PyInterpreterState *interp) { if (!_Py_IsMainInterpreter(interp)) { return; } _PyStructSequence_FiniType(&ThreadInfoType); }
567d6adc264bdf887dc14c99771fbd662749b220
22f5ec4d85105dc2cb9b2ae38ad806fa5a138f3a
/src/mulle-objc-universe-global.c
fd52d19707921ecb60789334035d571b9ee4525b
[ "BSD-3-Clause" ]
permissive
mulle-objc/mulle-objc-runtime
0fd0fd4c0a4221f693bf7aa33bc43cf5e091dd12
558d9cb71a331315fff0dfbfb1ea20b90d20652f
refs/heads/release
2023-05-01T08:44:16.846552
2023-04-21T21:47:23
2023-04-21T21:47:23
73,371,608
133
8
NOASSERTION
2022-01-12T13:56:19
2016-11-10T10:29:50
C
UTF-8
C
false
false
5,898
c
mulle-objc-universe-global.c
// // mulle_objc_universe_global.h // mulle-objc-runtime // // Created by Nat! on 07.09.16. // Copyright (c) 2016 Nat! - Mulle kybernetiK. // Copyright (c) 2016 Codeon GmbH. // All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // // Redistributions of source code must retain the above copyright notice, this // list of conditions and the following disclaimer. // // Redistributions in binary form must reproduce the above copyright notice, // this list of conditions and the following disclaimer in the documentation // and/or other materials provided with the distribution. // // Neither the name of Mulle kybernetiK nor the names of its contributors // may be used to endorse or promote products derived from this software // without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. // #include "mulle-objc-universe-struct.h" #include "include-private.h" // // Globals I can't get rid off // They must be initialized because of windows // long __mulle_objc_personality_v0 = 1848; // no idea what this is used for // // the mulle_objc_defaultuniverse is special and has universeid 0 // struct _mulle_objc_universe mulle_objc_defaultuniverse = { .version = (void *) mulle_objc_universe_is_uninitialized }; struct init_wrapper_for_windows { struct mulle_concurrent_hashmap map; int initvalue; }; // // other universes are stored here // the mulle_objc_defaultuniverse is not part of it // static const struct _mulle_concurrent_hashmapstorage empty_hashmapstorage = { (void *) -1, 0, { { MULLE_CONCURRENT_NO_HASH, NULL } } }; struct init_wrapper_for_windows mulle_objc_universetable = { { { (struct _mulle_concurrent_hashmapstorage *) &empty_hashmapstorage }, { (struct _mulle_concurrent_hashmapstorage *) &empty_hashmapstorage } }, 1848 }; struct _mulle_objc_universe * __mulle_objc_global_register_universe( mulle_objc_universeid_t universeid, struct _mulle_objc_universe *universe) { struct mulle_allocator *allocator; assert( universeid != MULLE_OBJC_DEFAULTUNIVERSEID); allocator = _mulle_atomic_pointer_read( &mulle_objc_universetable.map.allocator); if( ! allocator) { // // use stdlib allocator for this, since we leak here // allocator = &mulle_stdlib_allocator; assert( allocator->abafree && allocator->abafree != (int (*)()) abort); _mulle_atomic_pointer_cas( &mulle_objc_universetable.map.allocator, allocator, NULL); } return( mulle_concurrent_hashmap_register( &mulle_objc_universetable.map, universeid, universe)); } void __mulle_objc_global_unregister_universe( mulle_objc_universeid_t universeid, struct _mulle_objc_universe *universe) { assert( universeid != MULLE_OBJC_DEFAULTUNIVERSEID); mulle_concurrent_hashmap_remove( &mulle_objc_universetable.map, universeid, universe); } size_t __mulle_objc_global_get_alluniverses( struct _mulle_objc_universe **buf, size_t n) { struct _mulle_objc_universe *universe; struct _mulle_objc_universe **p; struct _mulle_objc_universe **sentinel; struct mulle_concurrent_hashmapenumerator rover; intptr_t hash; size_t i; size_t j; int rval; if( ! buf && n) return( -1); p = buf; sentinel = &p[ n]; i = 0; universe = &mulle_objc_defaultuniverse; if( _mulle_objc_universe_is_initialized( universe)) { if( p < sentinel) *p++ = universe; ++i; } // // add alternate universes they are known to be initialized if present // retry: j = 0; rover = mulle_concurrent_hashmap_enumerate( &mulle_objc_universetable.map); for(;;) { rval = mulle_concurrent_hashmapenumerator_next( &rover, &hash, (void **) &universe); if( rval == 1) { if( p < sentinel) *p++ = universe; ++j; continue; } break; } mulle_concurrent_hashmapenumerator_done( &rover); if( rval == EBUSY) goto retry; if( buf) memset( p, 0, (sentinel - p) * sizeof( struct _mulle_objc_universe *)); return( i + j); } void mulle_objc_global_reset_universetable( void) { assert( mulle_concurrent_hashmap_count( &mulle_objc_universetable.map) == 0); mulle_concurrent_hashmap_done( &mulle_objc_universetable.map); mulle_objc_universetable.map.storage.storage = mulle_objc_universetable.map.next_storage.storage = (struct _mulle_concurrent_hashmapstorage *) &empty_hashmapstorage; }
4e58357f92c615af4102415dc425954b3877e7db
88ae8695987ada722184307301e221e1ba3cc2fa
/third_party/ffmpeg/libavfilter/vf_scale_vulkan.c
3b09f0dcc120dc6bff31fee37d51b86bb46c64f6
[ "BSD-3-Clause", "Apache-2.0", "LGPL-2.0-or-later", "MIT", "GPL-1.0-or-later", "LGPL-2.1-only", "LGPL-3.0-only", "GPL-2.0-only", "LGPL-2.1-or-later", "GPL-3.0-or-later", "LGPL-3.0-or-later", "IJG", "LicenseRef-scancode-other-permissive", "GPL-2.0-or-later", "GPL-3.0-only" ]
permissive
iridium-browser/iridium-browser
71d9c5ff76e014e6900b825f67389ab0ccd01329
5ee297f53dc7f8e70183031cff62f37b0f19d25f
refs/heads/master
2023-08-03T16:44:16.844552
2023-07-20T15:17:00
2023-07-23T16:09:30
220,016,632
341
40
BSD-3-Clause
2021-08-13T13:54:45
2019-11-06T14:32:31
null
UTF-8
C
false
false
21,075
c
vf_scale_vulkan.c
/* * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "libavutil/random_seed.h" #include "libavutil/opt.h" #include "vulkan_filter.h" #include "scale_eval.h" #include "internal.h" #include "colorspace.h" #define CGROUPS (int [3]){ 32, 32, 1 } enum ScalerFunc { F_BILINEAR = 0, F_NEAREST, F_NB, }; typedef struct ScaleVulkanContext { FFVulkanContext vkctx; FFVkQueueFamilyCtx qf; FFVkExecContext *exec; FFVulkanPipeline *pl; FFVkBuffer params_buf; /* Shader updators, must be in the main filter struct */ VkDescriptorImageInfo input_images[3]; VkDescriptorImageInfo output_images[3]; VkDescriptorBufferInfo params_desc; char *out_format_string; char *w_expr; char *h_expr; enum ScalerFunc scaler; enum AVColorRange out_range; int initialized; } ScaleVulkanContext; static const char scale_bilinear[] = { C(0, vec4 scale_bilinear(int idx, ivec2 pos, vec2 crop_range, vec2 crop_off)) C(0, { ) C(1, vec2 npos = (vec2(pos) + 0.5f) / imageSize(output_img[idx]); ) C(1, npos *= crop_range; /* Reduce the range */ ) C(1, npos += crop_off; /* Offset the start */ ) C(1, return texture(input_img[idx], npos); ) C(0, } ) }; static const char rgb2yuv[] = { C(0, vec4 rgb2yuv(vec4 src, int fullrange) ) C(0, { ) C(1, src *= yuv_matrix; ) C(1, if (fullrange == 1) { ) C(2, src += vec4(0.0, 0.5, 0.5, 0.0); ) C(1, } else { ) C(2, src *= vec4(219.0 / 255.0, 224.0 / 255.0, 224.0 / 255.0, 1.0); ) C(2, src += vec4(16.0 / 255.0, 128.0 / 255.0, 128.0 / 255.0, 0.0); ) C(1, } ) C(1, return src; ) C(0, } ) }; static const char write_nv12[] = { C(0, void write_nv12(vec4 src, ivec2 pos) ) C(0, { ) C(1, imageStore(output_img[0], pos, vec4(src.r, 0.0, 0.0, 0.0)); ) C(1, pos /= ivec2(2); ) C(1, imageStore(output_img[1], pos, vec4(src.g, src.b, 0.0, 0.0)); ) C(0, } ) }; static const char write_420[] = { C(0, void write_420(vec4 src, ivec2 pos) ) C(0, { ) C(1, imageStore(output_img[0], pos, vec4(src.r, 0.0, 0.0, 0.0)); ) C(1, pos /= ivec2(2); ) C(1, imageStore(output_img[1], pos, vec4(src.g, 0.0, 0.0, 0.0)); ) C(1, imageStore(output_img[2], pos, vec4(src.b, 0.0, 0.0, 0.0)); ) C(0, } ) }; static const char write_444[] = { C(0, void write_444(vec4 src, ivec2 pos) ) C(0, { ) C(1, imageStore(output_img[0], pos, vec4(src.r, 0.0, 0.0, 0.0)); ) C(1, imageStore(output_img[1], pos, vec4(src.g, 0.0, 0.0, 0.0)); ) C(1, imageStore(output_img[2], pos, vec4(src.b, 0.0, 0.0, 0.0)); ) C(0, } ) }; static av_cold int init_filter(AVFilterContext *ctx, AVFrame *in) { int err; FFVkSampler *sampler; VkFilter sampler_mode; ScaleVulkanContext *s = ctx->priv; FFVulkanContext *vkctx = &s->vkctx; int crop_x = in->crop_left; int crop_y = in->crop_top; int crop_w = in->width - (in->crop_left + in->crop_right); int crop_h = in->height - (in->crop_top + in->crop_bottom); int in_planes = av_pix_fmt_count_planes(s->vkctx.input_format); ff_vk_qf_init(vkctx, &s->qf, VK_QUEUE_COMPUTE_BIT, 0); switch (s->scaler) { case F_NEAREST: sampler_mode = VK_FILTER_NEAREST; break; case F_BILINEAR: sampler_mode = VK_FILTER_LINEAR; break; }; /* Create a sampler */ sampler = ff_vk_init_sampler(vkctx, 0, sampler_mode); if (!sampler) return AVERROR_EXTERNAL; s->pl = ff_vk_create_pipeline(vkctx, &s->qf); if (!s->pl) return AVERROR(ENOMEM); { /* Create the shader */ FFVulkanDescriptorSetBinding desc_i[2] = { { .name = "input_img", .type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, .dimensions = 2, .elems = in_planes, .stages = VK_SHADER_STAGE_COMPUTE_BIT, .updater = s->input_images, .sampler = sampler, }, { .name = "output_img", .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, .mem_layout = ff_vk_shader_rep_fmt(s->vkctx.output_format), .mem_quali = "writeonly", .dimensions = 2, .elems = av_pix_fmt_count_planes(s->vkctx.output_format), .stages = VK_SHADER_STAGE_COMPUTE_BIT, .updater = s->output_images, }, }; FFVulkanDescriptorSetBinding desc_b = { .name = "params", .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, .mem_quali = "readonly", .mem_layout = "std430", .stages = VK_SHADER_STAGE_COMPUTE_BIT, .updater = &s->params_desc, .buf_content = "mat4 yuv_matrix;", }; FFVkSPIRVShader *shd = ff_vk_init_shader(s->pl, "scale_compute", VK_SHADER_STAGE_COMPUTE_BIT); if (!shd) return AVERROR(ENOMEM); ff_vk_set_compute_shader_sizes(shd, CGROUPS); RET(ff_vk_add_descriptor_set(vkctx, s->pl, shd, desc_i, FF_ARRAY_ELEMS(desc_i), 0)); /* set 0 */ RET(ff_vk_add_descriptor_set(vkctx, s->pl, shd, &desc_b, 1, 0)); /* set 1 */ GLSLD( scale_bilinear ); if (s->vkctx.output_format != s->vkctx.input_format) { GLSLD( rgb2yuv ); } switch (s->vkctx.output_format) { case AV_PIX_FMT_NV12: GLSLD(write_nv12); break; case AV_PIX_FMT_YUV420P: GLSLD( write_420); break; case AV_PIX_FMT_YUV444P: GLSLD( write_444); break; default: break; } GLSLC(0, void main() ); GLSLC(0, { ); GLSLC(1, ivec2 size; ); GLSLC(1, ivec2 pos = ivec2(gl_GlobalInvocationID.xy); ); GLSLF(1, vec2 in_d = vec2(%i, %i); ,in->width, in->height); GLSLF(1, vec2 c_r = vec2(%i, %i) / in_d; ,crop_w, crop_h); GLSLF(1, vec2 c_o = vec2(%i, %i) / in_d; ,crop_x,crop_y); GLSLC(0, ); if (s->vkctx.output_format == s->vkctx.input_format) { for (int i = 0; i < desc_i[1].elems; i++) { GLSLF(1, size = imageSize(output_img[%i]); ,i); GLSLC(1, if (IS_WITHIN(pos, size)) { ); switch (s->scaler) { case F_NEAREST: case F_BILINEAR: GLSLF(2, vec4 res = scale_bilinear(%i, pos, c_r, c_o); ,i); GLSLF(2, imageStore(output_img[%i], pos, res); ,i); break; }; GLSLC(1, } ); } } else { GLSLC(1, vec4 res = scale_bilinear(0, pos, c_r, c_o); ); GLSLF(1, res = rgb2yuv(res, %i); ,s->out_range == AVCOL_RANGE_JPEG); switch (s->vkctx.output_format) { case AV_PIX_FMT_NV12: GLSLC(1, write_nv12(res, pos); ); break; case AV_PIX_FMT_YUV420P: GLSLC(1, write_420(res, pos); ); break; case AV_PIX_FMT_YUV444P: GLSLC(1, write_444(res, pos); ); break; default: return AVERROR(EINVAL); } } GLSLC(0, } ); RET(ff_vk_compile_shader(vkctx, shd, "main")); } RET(ff_vk_init_pipeline_layout(vkctx, s->pl)); RET(ff_vk_init_compute_pipeline(vkctx, s->pl)); if (s->vkctx.output_format != s->vkctx.input_format) { const AVLumaCoefficients *lcoeffs; double tmp_mat[3][3]; struct { float yuv_matrix[4][4]; } *par; lcoeffs = av_csp_luma_coeffs_from_avcsp(in->colorspace); if (!lcoeffs) { av_log(ctx, AV_LOG_ERROR, "Unsupported colorspace\n"); return AVERROR(EINVAL); } RET(ff_vk_create_buf(vkctx, &s->params_buf, sizeof(*par), VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT)); RET(ff_vk_map_buffers(vkctx, &s->params_buf, (uint8_t **)&par, 1, 0)); ff_fill_rgb2yuv_table(lcoeffs, tmp_mat); memset(par, 0, sizeof(*par)); for (int y = 0; y < 3; y++) for (int x = 0; x < 3; x++) par->yuv_matrix[x][y] = tmp_mat[x][y]; par->yuv_matrix[3][3] = 1.0; RET(ff_vk_unmap_buffers(vkctx, &s->params_buf, 1, 1)); s->params_desc.buffer = s->params_buf.buf; s->params_desc.range = VK_WHOLE_SIZE; ff_vk_update_descriptor_set(vkctx, s->pl, 1); } /* Execution context */ RET(ff_vk_create_exec_ctx(vkctx, &s->exec, &s->qf)); s->initialized = 1; return 0; fail: return err; } static int process_frames(AVFilterContext *avctx, AVFrame *out_f, AVFrame *in_f) { int err = 0; VkCommandBuffer cmd_buf; ScaleVulkanContext *s = avctx->priv; FFVulkanContext *vkctx = &s->vkctx; FFVulkanFunctions *vk = &vkctx->vkfn; AVVkFrame *in = (AVVkFrame *)in_f->data[0]; AVVkFrame *out = (AVVkFrame *)out_f->data[0]; VkImageMemoryBarrier barriers[AV_NUM_DATA_POINTERS*2]; int barrier_count = 0; const int planes = av_pix_fmt_count_planes(s->vkctx.input_format); const VkFormat *input_formats = av_vkfmt_from_pixfmt(s->vkctx.input_format); const VkFormat *output_formats = av_vkfmt_from_pixfmt(s->vkctx.output_format); /* Update descriptors and init the exec context */ ff_vk_start_exec_recording(vkctx, s->exec); cmd_buf = ff_vk_get_exec_buf(s->exec); for (int i = 0; i < planes; i++) { RET(ff_vk_create_imageview(vkctx, s->exec, &s->input_images[i].imageView, in->img[i], input_formats[i], ff_comp_identity_map)); RET(ff_vk_create_imageview(vkctx, s->exec, &s->output_images[i].imageView, out->img[i], output_formats[i], ff_comp_identity_map)); s->input_images[i].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; s->output_images[i].imageLayout = VK_IMAGE_LAYOUT_GENERAL; } ff_vk_update_descriptor_set(vkctx, s->pl, 0); for (int i = 0; i < planes; i++) { VkImageMemoryBarrier bar = { .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .srcAccessMask = 0, .dstAccessMask = VK_ACCESS_SHADER_READ_BIT, .oldLayout = in->layout[i], .newLayout = s->input_images[i].imageLayout, .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, .image = in->img[i], .subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT, .subresourceRange.levelCount = 1, .subresourceRange.layerCount = 1, }; memcpy(&barriers[barrier_count++], &bar, sizeof(VkImageMemoryBarrier)); in->layout[i] = bar.newLayout; in->access[i] = bar.dstAccessMask; } for (int i = 0; i < av_pix_fmt_count_planes(s->vkctx.output_format); i++) { VkImageMemoryBarrier bar = { .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, .srcAccessMask = 0, .dstAccessMask = VK_ACCESS_SHADER_WRITE_BIT, .oldLayout = out->layout[i], .newLayout = s->output_images[i].imageLayout, .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, .image = out->img[i], .subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT, .subresourceRange.levelCount = 1, .subresourceRange.layerCount = 1, }; memcpy(&barriers[barrier_count++], &bar, sizeof(VkImageMemoryBarrier)); out->layout[i] = bar.newLayout; out->access[i] = bar.dstAccessMask; } vk->CmdPipelineBarrier(cmd_buf, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0, 0, NULL, 0, NULL, barrier_count, barriers); ff_vk_bind_pipeline_exec(vkctx, s->exec, s->pl); vk->CmdDispatch(cmd_buf, FFALIGN(vkctx->output_width, CGROUPS[0])/CGROUPS[0], FFALIGN(vkctx->output_height, CGROUPS[1])/CGROUPS[1], 1); ff_vk_add_exec_dep(vkctx, s->exec, in_f, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT); ff_vk_add_exec_dep(vkctx, s->exec, out_f, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT); err = ff_vk_submit_exec_queue(vkctx, s->exec); if (err) return err; ff_vk_qf_rotate(&s->qf); return err; fail: ff_vk_discard_exec_deps(s->exec); return err; } static int scale_vulkan_filter_frame(AVFilterLink *link, AVFrame *in) { int err; AVFilterContext *ctx = link->dst; ScaleVulkanContext *s = ctx->priv; AVFilterLink *outlink = ctx->outputs[0]; AVFrame *out = ff_get_video_buffer(outlink, outlink->w, outlink->h); if (!out) { err = AVERROR(ENOMEM); goto fail; } if (!s->initialized) RET(init_filter(ctx, in)); RET(process_frames(ctx, out, in)); err = av_frame_copy_props(out, in); if (err < 0) goto fail; if (s->out_range != AVCOL_RANGE_UNSPECIFIED) out->color_range = s->out_range; if (s->vkctx.output_format != s->vkctx.input_format) out->chroma_location = AVCHROMA_LOC_TOPLEFT; av_frame_free(&in); return ff_filter_frame(outlink, out); fail: av_frame_free(&in); av_frame_free(&out); return err; } static int scale_vulkan_config_output(AVFilterLink *outlink) { int err; AVFilterContext *avctx = outlink->src; ScaleVulkanContext *s = avctx->priv; FFVulkanContext *vkctx = &s->vkctx; AVFilterLink *inlink = outlink->src->inputs[0]; err = ff_scale_eval_dimensions(s, s->w_expr, s->h_expr, inlink, outlink, &vkctx->output_width, &vkctx->output_height); if (err < 0) return err; if (s->out_format_string) { s->vkctx.output_format = av_get_pix_fmt(s->out_format_string); if (s->vkctx.output_format == AV_PIX_FMT_NONE) { av_log(avctx, AV_LOG_ERROR, "Invalid output format.\n"); return AVERROR(EINVAL); } } else { s->vkctx.output_format = s->vkctx.input_format; } if (s->vkctx.output_format != s->vkctx.input_format) { if (!ff_vk_mt_is_np_rgb(s->vkctx.input_format)) { av_log(avctx, AV_LOG_ERROR, "Unsupported input format for conversion\n"); return AVERROR(EINVAL); } if (s->vkctx.output_format != AV_PIX_FMT_NV12 && s->vkctx.output_format != AV_PIX_FMT_YUV420P && s->vkctx.output_format != AV_PIX_FMT_YUV444P) { av_log(avctx, AV_LOG_ERROR, "Unsupported output format\n"); return AVERROR(EINVAL); } } else if (s->out_range != AVCOL_RANGE_UNSPECIFIED) { av_log(avctx, AV_LOG_ERROR, "Cannot change range without converting format\n"); return AVERROR(EINVAL); } return ff_vk_filter_config_output(outlink); } static void scale_vulkan_uninit(AVFilterContext *avctx) { ScaleVulkanContext *s = avctx->priv; ff_vk_free_buf(&s->vkctx, &s->params_buf); ff_vk_uninit(&s->vkctx); s->initialized = 0; } #define OFFSET(x) offsetof(ScaleVulkanContext, x) #define FLAGS (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM) static const AVOption scale_vulkan_options[] = { { "w", "Output video width", OFFSET(w_expr), AV_OPT_TYPE_STRING, {.str = "iw"}, .flags = FLAGS }, { "h", "Output video height", OFFSET(h_expr), AV_OPT_TYPE_STRING, {.str = "ih"}, .flags = FLAGS }, { "scaler", "Scaler function", OFFSET(scaler), AV_OPT_TYPE_INT, {.i64 = F_BILINEAR}, 0, F_NB, .flags = FLAGS, "scaler" }, { "bilinear", "Bilinear interpolation (fastest)", 0, AV_OPT_TYPE_CONST, {.i64 = F_BILINEAR}, 0, 0, .flags = FLAGS, "scaler" }, { "nearest", "Nearest (useful for pixel art)", 0, AV_OPT_TYPE_CONST, {.i64 = F_NEAREST}, 0, 0, .flags = FLAGS, "scaler" }, { "format", "Output video format (software format of hardware frames)", OFFSET(out_format_string), AV_OPT_TYPE_STRING, .flags = FLAGS }, { "out_range", "Output colour range (from 0 to 2) (default 0)", OFFSET(out_range), AV_OPT_TYPE_INT, {.i64 = AVCOL_RANGE_UNSPECIFIED}, AVCOL_RANGE_UNSPECIFIED, AVCOL_RANGE_JPEG, .flags = FLAGS, "range" }, { "full", "Full range", 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_RANGE_JPEG }, 0, 0, FLAGS, "range" }, { "limited", "Limited range", 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_RANGE_MPEG }, 0, 0, FLAGS, "range" }, { "jpeg", "Full range", 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_RANGE_JPEG }, 0, 0, FLAGS, "range" }, { "mpeg", "Limited range", 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_RANGE_MPEG }, 0, 0, FLAGS, "range" }, { "tv", "Limited range", 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_RANGE_MPEG }, 0, 0, FLAGS, "range" }, { "pc", "Full range", 0, AV_OPT_TYPE_CONST, { .i64 = AVCOL_RANGE_JPEG }, 0, 0, FLAGS, "range" }, { NULL }, }; AVFILTER_DEFINE_CLASS(scale_vulkan); static const AVFilterPad scale_vulkan_inputs[] = { { .name = "default", .type = AVMEDIA_TYPE_VIDEO, .filter_frame = &scale_vulkan_filter_frame, .config_props = &ff_vk_filter_config_input, }, }; static const AVFilterPad scale_vulkan_outputs[] = { { .name = "default", .type = AVMEDIA_TYPE_VIDEO, .config_props = &scale_vulkan_config_output, }, }; const AVFilter ff_vf_scale_vulkan = { .name = "scale_vulkan", .description = NULL_IF_CONFIG_SMALL("Scale Vulkan frames"), .priv_size = sizeof(ScaleVulkanContext), .init = &ff_vk_filter_init, .uninit = &scale_vulkan_uninit, FILTER_INPUTS(scale_vulkan_inputs), FILTER_OUTPUTS(scale_vulkan_outputs), FILTER_SINGLE_PIXFMT(AV_PIX_FMT_VULKAN), .priv_class = &scale_vulkan_class, .flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE, .flags = AVFILTER_FLAG_HWDEVICE, };
6c6cdde3251137146ad30670c1ec22d14cb542e1
e814383d36a10839104efaa4df277996ab220fa3
/ompi/mca/topo/example/topo_example.h
8e2b2903d7dd0725a8c0f170e65155882f3d8c86
[ "mpich2", "BSD-3-Clause-Open-MPI" ]
permissive
open-mpi/ompi
a1d7483ae1d83dd8fd8ae3ee95e832e0a0ee04e3
1edfdb025c4450f694600083ad871cf06c8d45cd
refs/heads/main
2023-09-01T01:30:02.040705
2023-08-29T17:32:18
2023-08-29T17:32:18
24,107,001
2,008
973
NOASSERTION
2023-09-14T20:59:26
2014-09-16T16:08:30
C
UTF-8
C
false
false
2,873
h
topo_example.h
/* * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana * University Research and Technology * Corporation. All rights reserved. * Copyright (c) 2004-2013 The University of Tennessee and The University * of Tennessee Research Foundation. All rights * reserved. * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. * Copyright (c) 2009 Cisco Systems, Inc. All rights reserved. * Copyright (c) 2012-2013 Inria. All rights reserved. * $COPYRIGHT$ * * Additional copyrights may follow * * $HEADER$ */ #ifndef MCA_TOPO_UNTIY_H #define MCA_TOPO_UNTIY_H #include "ompi_config.h" #include "ompi/mca/topo/topo.h" /* * ****************************************************************** * ******** functions which provide MCA interface compliance ******** * ****************************************************************** * These functions are: * - mca_topo_example_module_open * - mca_topo_example_module_close * - mca_topo_example_module_query * - mca_topo_example_module_finalize * These functions are always found on the mca_topo_example_module * structure. They are the "meta" functions to ensure smooth op. * ****************************************************************** */ BEGIN_C_DECLS /* * Public component instance */ OMPI_DECLSPEC extern mca_topo_base_component_2_2_0_t mca_topo_example_component; /* * A unique module class for the module so that we can both cache * module-specific information on the module and have a * module-specific constructor and destructor. */ typedef struct { mca_topo_base_module_t super; /* Modules can add their own information here */ int example_module_specific_data; } mca_topo_example_module_t; OBJ_CLASS_DECLARATION(mca_topo_example_module_t); /* * Module functions */ int mca_topo_example_cart_map(struct ompi_communicator_t *comm, int ndims, int *dims, int *periods, int *newrank); int mca_topo_example_graph_map(struct ompi_communicator_t *comm, int nnodes, int *index, int *edges, int *newrank); /* * ****************************************************************** * ************ functions implemented in this module end ************ * ****************************************************************** */ END_C_DECLS #endif /* MCA_TOPO_EXAMPLE_H */
f8c6adaa1c545fa61bb78a30a4f8fa9503f62fc2
fa1ad2e2ac7e376fc7cb3b3a6e1bb88eed3e80be
/govern/data-security/krb-1.2.1/src/util/support/t_unal.c
156070d5e8abd72cf49bb13ff9d4e96a9daf79f6
[ "LicenseRef-scancode-mit-modification-obligations", "BSD-4-Clause", "LicenseRef-scancode-generic-export-compliance", "LicenseRef-scancode-other-permissive", "LicenseRef-scancode-mit-old-style", "BSD-4-Clause-UC", "LicenseRef-scancode-rsa-1990", "BSD-3-Clause", "MIT-CMU", "LicenseRef-scancode-mit-no-advert-export-control", "CC-BY-SA-3.0", "LicenseRef-scancode-proprietary-license", "GPL-2.0-or-later", "LicenseRef-scancode-michigan-disclaimer", "ISC", "LicenseRef-scancode-nrl-permission", "FreeBSD-DOC", "LicenseRef-scancode-rsa-md4", "RSA-MD", "OLDAP-2.8", "FSFULLRWD", "BSD-2-Clause", "LicenseRef-scancode-brian-gladman", "MIT", "Apache-2.0" ]
permissive
alldatacenter/alldata
7bc7713c9f1d56ad6b8e59ea03206d1073b7e047
8d5f9a2d49ab8f9e85ccf058cb02c2fda287afc6
refs/heads/master
2023-08-05T07:32:25.442740
2023-08-03T13:17:24
2023-08-03T13:17:24
213,321,771
774
250
Apache-2.0
2023-09-06T17:35:32
2019-10-07T07:36:18
null
UTF-8
C
false
false
1,623
c
t_unal.c
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */ #undef NDEBUG #include "k5-platform.h" int main () { /* Test some low-level assumptions the Kerberos code depends on. */ union { uint64_t n64; uint32_t n32; uint16_t n16; unsigned char b[9]; } u; static unsigned char buf[9] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 }; assert(load_64_be(buf+1) == 0x0102030405060708LL); assert(load_64_le(buf+1) == 0x0807060504030201LL); assert(load_32_le(buf+2) == 0x05040302); assert(load_32_be(buf+2) == 0x02030405); assert(load_16_be(buf+3) == 0x0304); assert(load_16_le(buf+3) == 0x0403); u.b[0] = 0; assert((store_64_be(0x0102030405060708LL, u.b+1), !memcmp(buf, u.b, 9))); u.b[1] = 9; assert((store_64_le(0x0807060504030201LL, u.b+1), !memcmp(buf, u.b, 9))); u.b[2] = 10; assert((store_32_be(0x02030405, u.b+2), !memcmp(buf, u.b, 9))); u.b[3] = 11; assert((store_32_le(0x05040302, u.b+2), !memcmp(buf, u.b, 9))); u.b[4] = 12; assert((store_16_be(0x0304, u.b+3), !memcmp(buf, u.b, 9))); u.b[4] = 13; assert((store_16_le(0x0403, u.b+3), !memcmp(buf, u.b, 9))); /* Verify that load_*_n properly does native format. Assume the unaligned thing is okay. */ u.n64 = 0x090a0b0c0d0e0f00LL; assert(load_64_n((unsigned char *) &u.n64) == 0x090a0b0c0d0e0f00LL); u.n32 = 0x06070809; assert(load_32_n((unsigned char *) &u.n32) == 0x06070809); u.n16 = 0x0a0b; assert(load_16_n((unsigned char *) &u.n16) == 0x0a0b); return 0; }
228201ab9407efa17e7a97a8d845943e569d93b6
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
/SOFTWARE/A64-TERES/linux-a64/arch/arm/mach-s3c24xx/pm-s3c2416.c
44923895f558633251adc07ce589cfbcb8d86480
[ "Linux-syscall-note", "GPL-2.0-only", "GPL-1.0-or-later", "LicenseRef-scancode-free-unknown", "Apache-2.0" ]
permissive
OLIMEX/DIY-LAPTOP
ae82f4ee79c641d9aee444db9a75f3f6709afa92
a3fafd1309135650bab27f5eafc0c32bc3ca74ee
refs/heads/rel3
2023-08-04T01:54:19.483792
2023-04-03T07:18:12
2023-04-03T07:18:12
80,094,055
507
92
Apache-2.0
2023-04-03T07:05:59
2017-01-26T07:25:50
C
UTF-8
C
false
false
2,045
c
pm-s3c2416.c
/* linux/arch/arm/mach-s3c2416/pm.c * * Copyright (c) 2010 Samsung Electronics Co., Ltd. * http://www.samsung.com * * S3C2416 - PM support (Based on Ben Dooks' S3C2412 PM support) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. */ #include <linux/device.h> #include <linux/syscore_ops.h> #include <linux/io.h> #include <asm/cacheflush.h> #include <mach/regs-s3c2443-clock.h> #include <plat/cpu.h> #include <plat/pm.h> #include "s3c2412-power.h" extern void s3c2412_sleep_enter(void); static int s3c2416_cpu_suspend(unsigned long arg) { /* enable wakeup sources regardless of battery state */ __raw_writel(S3C2443_PWRCFG_SLEEP, S3C2443_PWRCFG); /* set the mode as sleep, 2BED represents "Go to BED" */ __raw_writel(0x2BED, S3C2443_PWRMODE); s3c2412_sleep_enter(); pr_info("Failed to suspend the system\n"); return 1; /* Aborting suspend */ } static void s3c2416_pm_prepare(void) { /* * write the magic value u-boot uses to check for resume into * the INFORM0 register, and ensure INFORM1 is set to the * correct address to resume from. */ __raw_writel(0x2BED, S3C2412_INFORM0); __raw_writel(virt_to_phys(s3c_cpu_resume), S3C2412_INFORM1); } static int s3c2416_pm_add(struct device *dev, struct subsys_interface *sif) { pm_cpu_prep = s3c2416_pm_prepare; pm_cpu_sleep = s3c2416_cpu_suspend; return 0; } static struct subsys_interface s3c2416_pm_interface = { .name = "s3c2416_pm", .subsys = &s3c2416_subsys, .add_dev = s3c2416_pm_add, }; static __init int s3c2416_pm_init(void) { return subsys_interface_register(&s3c2416_pm_interface); } arch_initcall(s3c2416_pm_init); static void s3c2416_pm_resume(void) { /* unset the return-from-sleep amd inform flags */ __raw_writel(0x0, S3C2443_PWRMODE); __raw_writel(0x0, S3C2412_INFORM0); __raw_writel(0x0, S3C2412_INFORM1); } struct syscore_ops s3c2416_pm_syscore_ops = { .resume = s3c2416_pm_resume, };
a13572c7b347f134f105de1fcccccb5230e1f509
42ab733e143d02091d13424fb4df16379d5bba0d
/third_party/libpng/contrib/pngminus/png2pnm.c
35e2c9d398464c9b81d69f1e1221d6faa0c81c86
[ "Libpng", "Apache-2.0", "CC0-1.0", "LicenseRef-scancode-unknown-license-reference", "MIT" ]
permissive
google/filament
11cd37ac68790fcf8b33416b7d8d8870e48181f0
0aa0efe1599798d887fa6e33c412c09e81bea1bf
refs/heads/main
2023-08-29T17:58:22.496956
2023-08-28T17:27:38
2023-08-28T17:27:38
143,455,116
16,631
1,961
Apache-2.0
2023-09-14T16:23:39
2018-08-03T17:26:00
C++
UTF-8
C
false
false
11,774
c
png2pnm.c
/* * png2pnm.c --- conversion from PNG-file to PGM/PPM-file * copyright (C) 1999-2019 by Willem van Schaik <willem at schaik dot com> * * This software is released under the MIT license. For conditions of * distribution and use, see the LICENSE file part of this package. */ #include <stdio.h> #include <stdlib.h> #include <fcntl.h> #ifndef BOOL #define BOOL unsigned char #endif #ifndef TRUE #define TRUE (BOOL) 1 #endif #ifndef FALSE #define FALSE (BOOL) 0 #endif /* make png2pnm verbose so we can find problems (needs to be before png.h) */ #ifndef PNG_DEBUG #define PNG_DEBUG 0 #endif #include "png.h" /* function prototypes */ int main (int argc, char *argv[]); void usage (); BOOL png2pnm (FILE *png_file, FILE *pnm_file, FILE *alpha_file, BOOL raw, BOOL alpha); /* * main */ int main (int argc, char *argv[]) { FILE *fp_rd = stdin; FILE *fp_wr = stdout; FILE *fp_al = NULL; BOOL raw = TRUE; BOOL alpha = FALSE; int argi; for (argi = 1; argi < argc; argi++) { if (argv[argi][0] == '-') { switch (argv[argi][1]) { case 'n': raw = FALSE; break; case 'r': raw = TRUE; break; case 'a': alpha = TRUE; argi++; if ((fp_al = fopen (argv[argi], "wb")) == NULL) { fprintf (stderr, "PNM2PNG\n"); fprintf (stderr, "Error: cannot create alpha-channel file %s\n", argv[argi]); exit (1); } break; case 'h': case '?': usage (); exit (0); break; default: fprintf (stderr, "PNG2PNM\n"); fprintf (stderr, "Error: unknown option %s\n", argv[argi]); usage (); exit (1); break; } /* end switch */ } else if (fp_rd == stdin) { if ((fp_rd = fopen (argv[argi], "rb")) == NULL) { fprintf (stderr, "PNG2PNM\n"); fprintf (stderr, "Error: file %s does not exist\n", argv[argi]); exit (1); } } else if (fp_wr == stdout) { if ((fp_wr = fopen (argv[argi], "wb")) == NULL) { fprintf (stderr, "PNG2PNM\n"); fprintf (stderr, "Error: cannot create file %s\n", argv[argi]); exit (1); } } else { fprintf (stderr, "PNG2PNM\n"); fprintf (stderr, "Error: too many parameters\n"); usage (); exit (1); } } /* end for */ #if defined(O_BINARY) && (O_BINARY != 0) /* set stdin/stdout if required to binary */ if (fp_rd == stdin) setmode (fileno (stdin), O_BINARY); if ((raw) && (fp_wr == stdout)) setmode (fileno (stdout), O_BINARY); #endif /* call the conversion program itself */ if (png2pnm (fp_rd, fp_wr, fp_al, raw, alpha) == FALSE) { fprintf (stderr, "PNG2PNM\n"); fprintf (stderr, "Error: unsuccessful conversion of PNG-image\n"); exit (1); } /* close input file */ fclose (fp_rd); /* close output file */ fclose (fp_wr); /* close alpha file */ if (alpha) fclose (fp_al); return 0; } /* * usage */ void usage () { fprintf (stderr, "PNG2PNM\n"); fprintf (stderr, " by Willem van Schaik, 1999\n"); fprintf (stderr, "Usage: png2pnm [options] <file>.png [<file>.pnm]\n"); fprintf (stderr, " or: ... | png2pnm [options]\n"); fprintf (stderr, "Options:\n"); fprintf (stderr, " -r[aw] write pnm-file in binary format (P4/P5/P6) (default)\n"); fprintf (stderr, " -n[oraw] write pnm-file in ascii format (P1/P2/P3)\n"); fprintf (stderr, " -a[lpha] <file>.pgm write PNG alpha channel as pgm-file\n"); fprintf (stderr, " -h | -? print this help-information\n"); } /* * png2pnm */ BOOL png2pnm (FILE *png_file, FILE *pnm_file, FILE *alpha_file, BOOL raw, BOOL alpha) { png_struct *png_ptr = NULL; png_info *info_ptr = NULL; png_byte buf[8]; png_byte *png_pixels = NULL; png_byte **row_pointers = NULL; png_byte *pix_ptr = NULL; png_uint_32 row_bytes; png_uint_32 width; png_uint_32 height; int bit_depth; int channels; int color_type; int alpha_present; int row, col; int ret; int i; long dep_16; /* read and check signature in PNG file */ ret = fread (buf, 1, 8, png_file); if (ret != 8) return FALSE; ret = png_sig_cmp (buf, 0, 8); if (ret != 0) return FALSE; /* create png and info structures */ png_ptr = png_create_read_struct (png_get_libpng_ver(NULL), NULL, NULL, NULL); if (!png_ptr) return FALSE; /* out of memory */ info_ptr = png_create_info_struct (png_ptr); if (!info_ptr) { png_destroy_read_struct (&png_ptr, NULL, NULL); return FALSE; /* out of memory */ } if (setjmp (png_jmpbuf (png_ptr))) { png_destroy_read_struct (&png_ptr, &info_ptr, NULL); return FALSE; } /* set up the input control for C streams */ png_init_io (png_ptr, png_file); png_set_sig_bytes (png_ptr, 8); /* we already read the 8 signature bytes */ /* read the file information */ png_read_info (png_ptr, info_ptr); /* get size and bit-depth of the PNG-image */ png_get_IHDR (png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, NULL, NULL, NULL); /* set-up the transformations */ /* transform paletted images into full-color rgb */ if (color_type == PNG_COLOR_TYPE_PALETTE) png_set_expand (png_ptr); /* expand images to bit-depth 8 (only applicable for grayscale images) */ if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) png_set_expand (png_ptr); /* transform transparency maps into full alpha-channel */ if (png_get_valid (png_ptr, info_ptr, PNG_INFO_tRNS)) png_set_expand (png_ptr); #ifdef NJET /* downgrade 16-bit images to 8-bit */ if (bit_depth == 16) png_set_strip_16 (png_ptr); /* transform grayscale images into full-color */ if (color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA) png_set_gray_to_rgb (png_ptr); /* only if file has a file gamma, we do a correction */ if (png_get_gAMA (png_ptr, info_ptr, &file_gamma)) png_set_gamma (png_ptr, (double) 2.2, file_gamma); #endif /* all transformations have been registered; now update info_ptr data, * get rowbytes and channels, and allocate image memory */ png_read_update_info (png_ptr, info_ptr); /* get the new color-type and bit-depth (after expansion/stripping) */ png_get_IHDR (png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, NULL, NULL, NULL); /* check for 16-bit files */ if (bit_depth == 16) { raw = FALSE; #if defined(O_BINARY) && (O_BINARY != 0) setmode (fileno (pnm_file), O_BINARY); #endif } /* calculate new number of channels and store alpha-presence */ if (color_type == PNG_COLOR_TYPE_GRAY) channels = 1; else if (color_type == PNG_COLOR_TYPE_GRAY_ALPHA) channels = 2; else if (color_type == PNG_COLOR_TYPE_RGB) channels = 3; else if (color_type == PNG_COLOR_TYPE_RGB_ALPHA) channels = 4; else channels = 0; /* should never happen */ alpha_present = (channels - 1) % 2; /* check if alpha is expected to be present in file */ if (alpha && !alpha_present) { fprintf (stderr, "PNG2PNM\n"); fprintf (stderr, "Error: PNG-file doesn't contain alpha channel\n"); exit (1); } /* row_bytes is the width x number of channels x (bit-depth / 8) */ row_bytes = png_get_rowbytes (png_ptr, info_ptr); if ((row_bytes == 0) || ((size_t) height > (size_t) (-1) / (size_t) row_bytes)) { /* too big */ png_destroy_read_struct (&png_ptr, &info_ptr, NULL); return FALSE; } if ((png_pixels = (png_byte *) malloc ((size_t) row_bytes * (size_t) height)) == NULL) { png_destroy_read_struct (&png_ptr, &info_ptr, NULL); return FALSE; } if ((row_pointers = (png_byte **) malloc ((size_t) height * sizeof (png_byte *))) == NULL) { png_destroy_read_struct (&png_ptr, &info_ptr, NULL); free (png_pixels); return FALSE; } /* set the individual row_pointers to point at the correct offsets */ for (i = 0; i < ((int) height); i++) row_pointers[i] = png_pixels + i * row_bytes; /* now we can go ahead and just read the whole image */ png_read_image (png_ptr, row_pointers); /* read rest of file, and get additional chunks in info_ptr - REQUIRED */ png_read_end (png_ptr, info_ptr); /* clean up after the read, and free any memory allocated - REQUIRED */ png_destroy_read_struct (&png_ptr, &info_ptr, NULL); /* write header of PNM file */ if ((color_type == PNG_COLOR_TYPE_GRAY) || (color_type == PNG_COLOR_TYPE_GRAY_ALPHA)) { fprintf (pnm_file, "%s\n", (raw) ? "P5" : "P2"); fprintf (pnm_file, "%d %d\n", (int) width, (int) height); fprintf (pnm_file, "%ld\n", ((1L << (int) bit_depth) - 1L)); } else if ((color_type == PNG_COLOR_TYPE_RGB) || (color_type == PNG_COLOR_TYPE_RGB_ALPHA)) { fprintf (pnm_file, "%s\n", (raw) ? "P6" : "P3"); fprintf (pnm_file, "%d %d\n", (int) width, (int) height); fprintf (pnm_file, "%ld\n", ((1L << (int) bit_depth) - 1L)); } /* write header of PGM file with alpha channel */ if ((alpha) && ((color_type == PNG_COLOR_TYPE_GRAY_ALPHA) || (color_type == PNG_COLOR_TYPE_RGB_ALPHA))) { fprintf (alpha_file, "%s\n", (raw) ? "P5" : "P2"); fprintf (alpha_file, "%d %d\n", (int) width, (int) height); fprintf (alpha_file, "%ld\n", ((1L << (int) bit_depth) - 1L)); } /* write data to PNM file */ pix_ptr = png_pixels; for (row = 0; row < (int) height; row++) { for (col = 0; col < (int) width; col++) { for (i = 0; i < (channels - alpha_present); i++) { if (raw) { fputc ((int) *pix_ptr++, pnm_file); } else { if (bit_depth == 16) { dep_16 = (long) *pix_ptr++; fprintf (pnm_file, "%ld ", (dep_16 << 8) + ((long) *pix_ptr++)); } else { fprintf (pnm_file, "%ld ", (long) *pix_ptr++); } } } if (alpha_present) { if (!alpha) { pix_ptr++; /* alpha */ if (bit_depth == 16) pix_ptr++; } else /* output alpha-channel as pgm file */ { if (raw) { fputc ((int) *pix_ptr++, alpha_file); } else { if (bit_depth == 16) { dep_16 = (long) *pix_ptr++; fprintf (alpha_file, "%ld ", (dep_16 << 8) + (long) *pix_ptr++); } else { fprintf (alpha_file, "%ld ", (long) *pix_ptr++); } } } } /* end if alpha_present */ if (!raw) if (col % 4 == 3) fprintf (pnm_file, "\n"); } /* end for col */ if (!raw) if (col % 4 != 0) fprintf (pnm_file, "\n"); } /* end for row */ if (row_pointers != NULL) free (row_pointers); if (png_pixels != NULL) free (png_pixels); return TRUE; } /* end of source */
8eb333a9baa43b04c3920ddd480549b071858e75
e73547787354afd9b717ea57fe8dd0695d161821
/include/mapfs/kpa_10_shape.h
23eae756004df965c5ee36e8cc18a4a97e761058
[]
no_license
pmret/papermario
8b514b19653cef8d6145e47499b3636b8c474a37
9774b26d93f1045dd2a67e502b6efc9599fb6c31
refs/heads/main
2023-08-31T07:09:48.951514
2023-08-21T18:07:08
2023-08-21T18:07:08
287,151,133
904
139
null
2023-09-14T02:44:23
2020-08-13T01:22:57
C
UTF-8
C
false
false
7,662
h
kpa_10_shape.h
#define MODEL_Root 0xC9 #define MODEL_o2116 0xC8 #define MODEL_o2115 0xC7 #define MODEL_o2114 0xC6 #define MODEL_o2113 0xC5 #define MODEL_o2112 0xC4 #define MODEL_o2111 0xC3 #define MODEL_o2110 0xC2 #define MODEL_o2109 0xC1 #define MODEL_o2108 0xC0 #define MODEL_g318 0xBF #define MODEL_g346 0xBE #define MODEL_o2107 0xBD #define MODEL_o2106 0xBC #define MODEL_o2105 0xBB #define MODEL_o2104 0xBA #define MODEL_g345 0xB9 #define MODEL_o2098 0xB8 #define MODEL_g344 0xB7 #define MODEL_o2092 0xB6 #define MODEL_g343 0xB5 #define MODEL_o2091 0xB4 #define MODEL_o2090 0xB3 #define MODEL_o2089 0xB2 #define MODEL_o2088 0xB1 #define MODEL_g340 0xB0 #define MODEL_g342 0xAF #define MODEL_o2087 0xAE #define MODEL_g341 0xAD #define MODEL_o2086 0xAC #define MODEL_o2085 0xAB #define MODEL_o2084 0xAA #define MODEL_o2083 0xA9 #define MODEL_o2082 0xA8 #define MODEL_o2081 0xA7 #define MODEL_g339 0xA6 #define MODEL_o2075 0xA5 #define MODEL_g338 0xA4 #define MODEL_o2069 0xA3 #define MODEL_g337 0xA2 #define MODEL_o2068 0xA1 #define MODEL_o2067 0xA0 #define MODEL_o2066 0x9F #define MODEL_o2065 0x9E #define MODEL_g336 0x9D #define MODEL_o2059 0x9C #define MODEL_g335 0x9B #define MODEL_o2053 0x9A #define MODEL_g334 0x99 #define MODEL_o2047 0x98 #define MODEL_g333 0x97 #define MODEL_o2046 0x96 #define MODEL_o2045 0x95 #define MODEL_o2044 0x94 #define MODEL_o2043 0x93 #define MODEL_g332 0x92 #define MODEL_o2042 0x91 #define MODEL_o2041 0x90 #define MODEL_o2040 0x8F #define MODEL_o2039 0x8E #define MODEL_g331 0x8D #define MODEL_o2038 0x8C #define MODEL_o2037 0x8B #define MODEL_o2036 0x8A #define MODEL_o2035 0x89 #define MODEL_g330 0x88 #define MODEL_o2034 0x87 #define MODEL_o2033 0x86 #define MODEL_o2032 0x85 #define MODEL_o2031 0x84 #define MODEL_g329 0x83 #define MODEL_o2030 0x82 #define MODEL_o2029 0x81 #define MODEL_o2028 0x80 #define MODEL_o2027 0x7F #define MODEL_g328 0x7E #define MODEL_o2026 0x7D #define MODEL_o2025 0x7C #define MODEL_o2024 0x7B #define MODEL_o2023 0x7A #define MODEL_g327 0x79 #define MODEL_o2022 0x78 #define MODEL_o2021 0x77 #define MODEL_o2020 0x76 #define MODEL_o2019 0x75 #define MODEL_g326 0x74 #define MODEL_o2018 0x73 #define MODEL_o2017 0x72 #define MODEL_o2016 0x71 #define MODEL_o2015 0x70 #define MODEL_g325 0x6F #define MODEL_o2009 0x6E #define MODEL_g324 0x6D #define MODEL_o2003 0x6C #define MODEL_g323 0x6B #define MODEL_o1997 0x6A #define MODEL_g322 0x69 #define MODEL_o1996 0x68 #define MODEL_o1995 0x67 #define MODEL_o1994 0x66 #define MODEL_o1993 0x65 #define MODEL_o1992 0x64 #define MODEL_o1991 0x63 #define MODEL_g321 0x62 #define MODEL_o1990 0x61 #define MODEL_o1989 0x60 #define MODEL_o1988 0x5F #define MODEL_o1987 0x5E #define MODEL_o1986 0x5D #define MODEL_o1985 0x5C #define MODEL_g320 0x5B #define MODEL_o1984 0x5A #define MODEL_o1983 0x59 #define MODEL_o1982 0x58 #define MODEL_o1981 0x57 #define MODEL_o1980 0x56 #define MODEL_o1979 0x55 #define MODEL_g319 0x54 #define MODEL_o1978 0x53 #define MODEL_o1977 0x52 #define MODEL_o1976 0x51 #define MODEL_o1975 0x50 #define MODEL_o1974 0x4F #define MODEL_o1973 0x4E #define MODEL_g312 0x4D #define MODEL_g317 0x4C #define MODEL_o1972 0x4B #define MODEL_o1971 0x4A #define MODEL_o1970 0x49 #define MODEL_o1969 0x48 #define MODEL_o1968 0x47 #define MODEL_o1967 0x46 #define MODEL_o1966 0x45 #define MODEL_o1965 0x44 #define MODEL_o1964 0x43 #define MODEL_o1963 0x42 #define MODEL_o1962 0x41 #define MODEL_o1961 0x40 #define MODEL_o1960 0x3F #define MODEL_o1959 0x3E #define MODEL_o1958 0x3D #define MODEL_o1957 0x3C #define MODEL_g316 0x3B #define MODEL_o1956 0x3A #define MODEL_o1955 0x39 #define MODEL_o1954 0x38 #define MODEL_o1953 0x37 #define MODEL_o1952 0x36 #define MODEL_o1951 0x35 #define MODEL_g315 0x34 #define MODEL_o1950 0x33 #define MODEL_o1949 0x32 #define MODEL_o1948 0x31 #define MODEL_o1947 0x30 #define MODEL_o1946 0x2F #define MODEL_g314 0x2E #define MODEL_o1945 0x2D #define MODEL_o1944 0x2C #define MODEL_o1943 0x2B #define MODEL_o1942 0x2A #define MODEL_o1941 0x29 #define MODEL_o1940 0x28 #define MODEL_o1939 0x27 #define MODEL_o1938 0x26 #define MODEL_o1937 0x25 #define MODEL_o1936 0x24 #define MODEL_o1935 0x23 #define MODEL_o1934 0x22 #define MODEL_o1933 0x21 #define MODEL_o1932 0x20 #define MODEL_o1931 0x1F #define MODEL_o1930 0x1E #define MODEL_o1929 0x1D #define MODEL_o1928 0x1C #define MODEL_o1927 0x1B #define MODEL_o1926 0x1A #define MODEL_o1925 0x19 #define MODEL_o1924 0x18 #define MODEL_o1923 0x17 #define MODEL_g313 0x16 #define MODEL_o1922 0x15 #define MODEL_o1921 0x14 #define MODEL_o1920 0x13 #define MODEL_o1919 0x12 #define MODEL_o1918 0x11 #define MODEL_o1917 0x10 #define MODEL_g309 0xF #define MODEL_g311 0xE #define MODEL_o1915 0xD #define MODEL_o1914 0xC #define MODEL_o1913 0xB #define MODEL_o1912 0xA #define MODEL_o1911 0x9 #define MODEL_o1910 0x8 #define MODEL_g310 0x7 #define MODEL_o1909 0x6 #define MODEL_o1908 0x5 #define MODEL_o1907 0x4 #define MODEL_o1906 0x3 #define MODEL_o1905 0x2 #define MODEL_o1904 0x1 #define MODEL_o1903 0x0
0d5d614326e2e483158725215b8de38d3b10abbf
bb38c44037a99d0a12a12d92059678f2faebbc80
/src/bin/psql/tab-complete.h
340606f02e96e3b6d32726276949c5ae4b8b3308
[ "LicenseRef-scancode-mulanpsl-2.0-en", "LicenseRef-scancode-unknown-license-reference", "PostgreSQL", "BSD-3-Clause", "LGPL-2.0-or-later", "LicenseRef-scancode-unicode", "LicenseRef-scancode-warranty-disclaimer", "curl", "GPL-1.0-or-later", "LGPL-2.1-or-later", "LGPL-2.1-only", "CC-BY-4.0", "LicenseRef-scancode-protobuf", "OpenSSL", "LicenseRef-scancode-generic-export-compliance", "X11-distribute-modifications-variant", "LicenseRef-scancode-other-permissive", "MIT", "NCSA", "Python-2.0", "LicenseRef-scancode-openssl", "LicenseRef-scancode-ssleay-windows", "CC-BY-3.0", "LicenseRef-scancode-other-copyleft", "GPL-2.0-only", "BSL-1.0", "Apache-2.0", "LGPL-2.0-only", "LicenseRef-scancode-public-domain", "BSD-2-Clause", "Zlib" ]
permissive
opengauss-mirror/openGauss-server
a9c5a62908643492347830826c56da49f0942796
310e84631c68c8bf37b004148b66f94064f701e4
refs/heads/master
2023-07-26T19:29:12.495484
2023-07-17T12:23:32
2023-07-17T12:23:32
276,117,477
591
208
MulanPSL-2.0
2023-04-28T12:30:18
2020-06-30T14:08:59
C++
UTF-8
C
false
false
13,585
h
tab-complete.h
/* * psql - the openGauss interactive terminal * * Copyright (c) 2000-2012, PostgreSQL Global Development Group * * src/bin/psql/tab-complete.h */ #ifndef TAB_COMPLETE_H #define TAB_COMPLETE_H #include "postgres_fe.h" /* word break characters */ #define WORD_BREAKS "\t\n@$><=;|&{() " #ifdef HAVE_READLINE_READLINE_H #define filename_completion_function rl_filename_completion_function #define completion_matches rl_completion_matches /* * This struct is used to define "schema queries", which are custom-built * to obtain possibly-schema-qualified names of database objects. There is * enough similarity in the structure that we don't want to repeat it each * time. So we put the components of each query into this struct and * assemble them with the common boilerplate in _CompleteFromQuery(). */ typedef struct SchemaQuery { /* * Name of catalog or catalogs to be queried, with alias, eg. * "pg_catalog.pg_class c". Note that "pg_namespace n" will be added. */ const char *catname; /* * Selection condition --- only rows meeting this condition are candidates * to display. If catname mentions multiple tables, include the necessary * join condition here. For example, "c.relkind = 'r'". Write NULL (not * an empty string) if not needed. */ const char *selcondition; /* * Visibility condition --- which rows are visible without schema * qualification? For example, "pg_catalog.pg_table_is_visible(c.oid)". */ const char *viscondition; /* * Namespace --- name of field to join to pg_namespace.oid. For example, * "c.relnamespace". */ const char *nameSpace; /* * Result --- the appropriately-quoted name to return, in the case of an * unqualified name. For example, "pg_catalog.quote_ident(c.relname)". */ const char *result; /* * In some cases a different result must be used for qualified names. * Enter that here, or write NULL if result can be used. */ const char *qualresult; } SchemaQuery; /* * Queries to get lists of names of various kinds of things, possibly * restricted to names matching a partially entered name. In these queries, * the first %s will be replaced by the text entered so far (suitably escaped * to become a SQL literal string). %d will be replaced by the length of the * string (in unescaped form). A second and third %s, if present, will be * replaced by a suitably-escaped version of the string provided in * completion_info_charp. A fourth and fifth %s are similarly replaced by * completion_info_charp2. * * Beware that the allowed sequences of %s and %d are determined by * _CompleteFromQuery(). */ #define Query_for_list_of_attributes "SELECT pg_catalog.quote_ident(attname) " \ " FROM pg_catalog.pg_attribute a, pg_catalog.pg_class c " \ " WHERE c.oid = a.attrelid " \ " AND a.attnum > 0 " \ " AND NOT a.attisdropped " \ " AND substring(pg_catalog.quote_ident(attname),1,%d)='%s' " \ " AND (pg_catalog.quote_ident(relname)='%s' " \ " OR '\"' || relname || '\"'='%s') " \ " AND pg_catalog.pg_table_is_visible(c.oid)" #define Query_for_list_of_attributes_with_schema \ "SELECT pg_catalog.quote_ident(attname) " \ " FROM pg_catalog.pg_attribute a, pg_catalog.pg_class c, pg_catalog.pg_namespace n " \ " WHERE c.oid = a.attrelid " \ " AND n.oid = c.relnamespace " \ " AND a.attnum > 0 " \ " AND NOT a.attisdropped " \ " AND substring(pg_catalog.quote_ident(attname),1,%d)='%s' " \ " AND (pg_catalog.quote_ident(relname)='%s' " \ " OR '\"' || relname || '\"' ='%s') " \ " AND (pg_catalog.quote_ident(nspname)='%s' " \ " OR '\"' || nspname || '\"' ='%s') " #define Query_for_list_of_template_databases "SELECT pg_catalog.quote_ident(datname) FROM pg_catalog.pg_database " \ " WHERE substring(pg_catalog.quote_ident(datname),1,%d)='%s' AND datistemplate" #define Query_for_list_of_databases "SELECT pg_catalog.quote_ident(datname) FROM pg_catalog.pg_database " \ " WHERE substring(pg_catalog.quote_ident(datname),1,%d)='%s'" #define Query_for_list_of_tablespaces "SELECT pg_catalog.quote_ident(spcname) FROM pg_catalog.pg_tablespace " \ " WHERE substring(pg_catalog.quote_ident(spcname),1,%d)='%s'" #define Query_for_list_of_encodings " SELECT DISTINCT pg_catalog.pg_encoding_to_char(conforencoding) " \ " FROM pg_catalog.pg_conversion " \ " WHERE substring(pg_catalog.pg_encoding_to_char(conforencoding),1,%d)=UPPER('%s')" #define Query_for_list_of_languages "SELECT pg_catalog.quote_ident(lanname) " \ " FROM pg_catalog.pg_language " \ " WHERE lanname != 'internal' " \ " AND substring(pg_catalog.quote_ident(lanname),1,%d)='%s'" #define Query_for_list_of_schemas "SELECT pg_catalog.quote_ident(nspname) FROM pg_catalog.pg_namespace " \ " WHERE substring(pg_catalog.quote_ident(nspname),1,%d)='%s'" #define Query_for_list_of_alter_system_set_vars "SELECT name FROM " \ " (SELECT pg_catalog.lower(name) AS name FROM pg_catalog.pg_settings "\ " WHERE context != 'internal' "\ " UNION ALL SELECT 'all') ss "\ " WHERE substring(name,1,%d)='%s'" #define Query_for_list_of_set_vars "SELECT name FROM " \ " (SELECT pg_catalog.lower(name) AS name FROM pg_catalog.pg_settings " \ " WHERE context IN ('user', 'superuser') " \ " UNION ALL SELECT 'constraints' " \ " UNION ALL SELECT 'transaction' " \ " UNION ALL SELECT 'session' " \ " UNION ALL SELECT 'local' " \ " UNION ALL SELECT 'role' " \ " UNION ALL SELECT 'tablespace' " \ " UNION ALL SELECT 'all') ss " \ " WHERE substring(name,1,%d)='%s'" #define Query_for_list_of_show_vars "SELECT name FROM " \ " (SELECT pg_catalog.lower(name) AS name FROM pg_catalog.pg_settings " \ " UNION ALL SELECT 'session authorization' " \ " UNION ALL SELECT 'all') ss " \ " WHERE substring(name,1,%d)='%s'" #define Query_for_list_of_roles " SELECT pg_catalog.quote_ident(rolname) " \ " FROM pg_catalog.pg_roles " \ " WHERE substring(pg_catalog.quote_ident(rolname),1,%d)='%s'" #define Query_for_list_of_grant_roles " SELECT pg_catalog.quote_ident(rolname) " \ " FROM pg_catalog.pg_roles " \ " WHERE substring(pg_catalog.quote_ident(rolname),1,%d)='%s'" \ " UNION ALL SELECT 'PUBLIC'" /* the silly-looking length condition is just to eat up the current word */ #define Query_for_table_owning_index \ "SELECT pg_catalog.quote_ident(c1.relname) " \ " FROM pg_catalog.pg_class c1, pg_catalog.pg_class c2, pg_catalog.pg_index i" \ " WHERE c1.oid=i.indrelid and i.indexrelid=c2.oid" \ " and (%d = pg_catalog.length('%s'))" \ " and pg_catalog.quote_ident(c2.relname)='%s'" \ " and pg_catalog.pg_table_is_visible(c2.oid)" /* the silly-looking length condition is just to eat up the current word */ #define Query_for_index_of_table "SELECT pg_catalog.quote_ident(c2.relname) " \ " FROM pg_catalog.pg_class c1, pg_catalog.pg_class c2, pg_catalog.pg_index i" \ " WHERE c1.oid=i.indrelid and i.indexrelid=c2.oid" \ " and (%d = pg_catalog.length('%s'))" \ " and pg_catalog.quote_ident(c1.relname)='%s'" \ " and pg_catalog.pg_table_is_visible(c2.oid)" /* the silly-looking length condition is just to eat up the current word */ #define Query_for_list_of_tables_for_trigger "SELECT pg_catalog.quote_ident(relname) " \ " FROM pg_catalog.pg_class" \ " WHERE (%d = pg_catalog.length('%s'))" \ " AND oid IN " \ " (SELECT tgrelid FROM pg_catalog.pg_trigger " \ " WHERE pg_catalog.quote_ident(tgname)='%s')" #define Query_for_list_of_ts_configurations "SELECT pg_catalog.quote_ident(cfgname) FROM pg_catalog.pg_ts_config " \ " WHERE substring(pg_catalog.quote_ident(cfgname),1,%d)='%s'" #define Query_for_list_of_ts_dictionaries "SELECT pg_catalog.quote_ident(dictname) FROM pg_catalog.pg_ts_dict " \ " WHERE substring(pg_catalog.quote_ident(dictname),1,%d)='%s'" #define Query_for_list_of_ts_parsers "SELECT pg_catalog.quote_ident(prsname) FROM pg_catalog.pg_ts_parser " \ " WHERE substring(pg_catalog.quote_ident(prsname),1,%d)='%s'" #define Query_for_list_of_ts_templates "SELECT pg_catalog.quote_ident(tmplname) FROM pg_catalog.pg_ts_template " \ " WHERE substring(pg_catalog.quote_ident(tmplname),1,%d)='%s'" #define Query_for_list_of_fdws " SELECT pg_catalog.quote_ident(fdwname) " \ " FROM pg_catalog.pg_foreign_data_wrapper " \ " WHERE substring(pg_catalog.quote_ident(fdwname),1,%d)='%s'" #define Query_for_list_of_servers " SELECT pg_catalog.quote_ident(srvname) " \ " FROM pg_catalog.pg_foreign_server " \ " WHERE substring(pg_catalog.quote_ident(srvname),1,%d)='%s'" #define Query_for_list_of_user_mappings " SELECT pg_catalog.quote_ident(usename) " \ " FROM pg_catalog.pg_user_mappings " \ " WHERE substring(pg_catalog.quote_ident(usename),1,%d)='%s'" #define Query_for_list_of_access_methods " SELECT pg_catalog.quote_ident(amname) " \ " FROM pg_catalog.pg_am " \ " WHERE substring(pg_catalog.quote_ident(amname),1,%d)='%s'" #define Query_for_list_of_arguments " SELECT pg_catalog.oidvectortypes(proargtypes)||')' " \ " FROM pg_catalog.pg_proc " \ " WHERE proname='%s'" #define Query_for_list_of_extensions " SELECT pg_catalog.quote_ident(extname) " \ " FROM pg_catalog.pg_extension " \ " WHERE substring(pg_catalog.quote_ident(extname),1,%d)='%s'" #define Query_for_list_of_available_extensions " SELECT pg_catalog.quote_ident(name) " \ " FROM pg_catalog.pg_available_extensions " \ " WHERE substring(pg_catalog.quote_ident(name),1,%d)='%s' AND installed_version IS NULL" #define Query_for_list_of_available_extension_versions \ " SELECT pg_catalog.quote_ident(version) "\ " FROM pg_catalog.pg_available_extension_versions "\ " WHERE (%d = pg_catalog.length('%s'))"\ " AND pg_catalog.quote_ident(name)='%s'" #define Query_for_list_of_prepared_statements " SELECT pg_catalog.quote_ident(name) " \ " FROM pg_catalog.pg_prepared_statements " \ " WHERE substring(pg_catalog.quote_ident(name),1,%d)='%s'" #ifdef PGXC #define Query_for_list_of_available_nodenames " SELECT NODE_NAME " \ " FROM PGXC_NODE" #define Query_for_list_of_available_coordinators " SELECT NODE_NAME " \ " FROM PGXC_NODE" \ " WHERE NODE_TYPE = 'C'" #define Query_for_list_of_available_datanodes " SELECT NODE_NAME " \ " FROM PGXC_NODE" \ " WHERE NODE_TYPE = 'D'" #define Query_for_list_of_available_nodegroup_names " SELECT GROUP_NAME " \ " FROM PGXC_GROUP" #endif /* * This is a list of all "things" in Pgsql, which can show up after CREATE or * DROP; and there is also a query to get a list of them. */ typedef struct { const char *name; const char *query; /* simple query, or NULL */ const SchemaQuery *squery; /* schema query, or NULL */ const bits32 flags; /* visibility flags, see below */ } pgsql_thing_t; #define THING_NO_CREATE (1 << 0) /* should not show up after CREATE */ #define THING_NO_DROP (1 << 1) /* should not show up after DROP */ #define THING_NO_SHOW (THING_NO_CREATE | THING_NO_DROP) #endif /* HAVE_READLINE_READLINE_H */ void initialize_readline(void); #endif
349524f55dd11bf5fe1cfb0bba074f30cb254136
28d0f8c01599f8f6c711bdde0b59f9c2cd221203
/lib/libc/compat/arch/powerpc64/sys/compat_missing.c
d56005b720d41335f779283612a9baf1cb8f823f
[]
no_license
NetBSD/src
1a9cbc22ed778be638b37869ed4fb5c8dd616166
23ee83f7c0aea0777bd89d8ebd7f0cde9880d13c
refs/heads/trunk
2023-08-31T13:24:58.105962
2023-08-27T15:50:47
2023-08-27T15:50:47
88,439,547
656
348
null
2023-07-20T20:07:24
2017-04-16T20:03:43
null
UTF-8
C
false
false
3,275
c
compat_missing.c
/* $NetBSD: compat_missing.c,v 1.2 2021/11/02 06:54:10 thorpej Exp $ */ /*- * Copyright (c) 2020 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Christos Zoulas. * * 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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include <sys/cdefs.h> __RCSID("$NetBSD: compat_missing.c,v 1.2 2021/11/02 06:54:10 thorpej Exp $"); /* * define symbols that autoconf is supposed to find * without including the standard headers */ #define __LIBC12_SOURCE__ #include <signal.h> __warn_references(sigaction, "warning: reference to compatibility sigaction(); include <signal.h> to generate correct reference") __warn_references(sigpending, "warning: reference to compatibility sigpending(); include <signal.h> to generate correct reference") __warn_references(sigprocmask, "warning: reference to compatibility sigprocmask(); include <signal.h> to generate correct reference") __warn_references(sigsuspend, "warning: reference to compatibility sigsuspend(); include <signal.h> to generate correct reference") int sigaction(int, const struct sigaction * restrict, struct sigaction * restrict); int __sigaction_siginfo(int, const struct sigaction * restrict, struct sigaction * restrict); int sigaction(int sig, const struct sigaction * restrict act, struct sigaction * restrict oact) { return __sigaction_siginfo(sig, act, oact); } int sigpending(sigset_t *); int __sigpending14(sigset_t *); int sigpending(sigset_t *mask) { return __sigpending14(mask); } int sigprocmask(int how, const sigset_t * restrict set, sigset_t * restrict oset); int __sigprocmask14(int how, const sigset_t * restrict set, sigset_t * restrict oset); int sigprocmask(int how, const sigset_t * restrict set, sigset_t * restrict oset) { return __sigprocmask14(how, set, oset); } int sigsuspend(const sigset_t *); int __sigsuspend14(const sigset_t *); int sigsuspend(const sigset_t *mask) { return __sigsuspend14(mask); }
5a43a7a54109d3c47eb2840d3d7b666f83cce957
fdbb74a95924e2677466614f6ab6e2bb13b2a95a
/libc/intrin/describesockoptname.c
1a4c4810f8c3d0e8b58074d6b7ef70288e603fd5
[ "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
2,755
c
describesockoptname.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 2022 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/fmt/itoa.h" #include "libc/fmt/magnumstrs.internal.h" #include "libc/intrin/describeflags.internal.h" #include "libc/str/str.h" #include "libc/sysv/consts/sol.h" /** * Describes setsockopt() optname arguments. */ const char *(DescribeSockOptname)(char buf[32], int l, int x) { char *p; const char *s; const struct MagnumStr *ms; p = buf; if (x) { if (l == SOL_SOCKET) { *p++ = 'S'; *p++ = 'O'; *p++ = '_'; *p = 0; ms = kSockOptnames; } else if (l == SOL_TCP) { *p++ = 'T'; *p++ = 'C'; *p++ = 'P'; *p++ = '_'; ms = kTcpOptnames; } else if (l == SOL_IP) { *p++ = 'I'; *p++ = 'P'; *p++ = '_'; *p = 0; ms = kIpOptnames; } else { ms = 0; } } else { ms = 0; } if (ms && (s = GetMagnumStr(ms, x))) { stpcpy(p, s); } else { FormatInt32(p, x); } return buf; }
bf3b051a35d6f9efee5f1eabf4dfa5bb71f99d8c
61be4a7bfc24468a1227ea797150520c83257844
/event/RitoRabitMountain.c
bfa1c7240d6d7b3a26e0209b36b7ac286d51e5ff
[]
no_license
MrCheeze/botw-tools
491e6a2d06191efa7fc7048aefb48b3b38a59a52
9a9e845beed87f5ec417c01e515d0fa01366366c
refs/heads/master
2022-06-26T01:34:38.353269
2022-06-20T14:52:01
2022-06-20T14:53:26
85,882,713
238
92
null
2017-05-01T22:15:30
2017-03-22T22:34:34
Python
UTF-8
C
false
false
400
c
RitoRabitMountain.c
-------- EventFlow: RitoRabitMountain -------- void Finish_Npc_HighMountain003_Talk() { call Npc_HighMountain003.NPC003_MtUsagi_Finish() } void Finish_Npc_HighMountain003_Near() { Event125: call Npc_HighMountain003.Near() } void Ready_Npc_HighMountain003_Talk() { call Npc_HighMountain003.NPC003_MtUsagi_Ready() } void Ready_Npc_HighMountain003_Near() { goto Event125 }
4bbfcf3c8f7f5672a3ab1305939e42fa51c1d3f6
a11e4bdd6157b22067288d860507fa20abea033d
/src/modules/xkbswitch/e_mod_main.h
bfeefd1a35803fde4c07339fd971b998e5ef6fcf
[ "BSD-2-Clause" ]
permissive
JeffHoogland/moksha
85a0f39dc97daa61d35e64a511013d21552db288
c56013644d8cd8e32101bb38a8d1e4ebd9d47f37
refs/heads/master
2023-08-24T05:39:13.415948
2023-08-22T19:49:32
2023-08-22T19:49:32
34,704,822
179
51
NOASSERTION
2023-09-06T14:41:31
2015-04-28T02:59:19
C
UTF-8
C
false
false
441
h
e_mod_main.h
/* * Main module header. * Contains some i18n stuff, module versioning, * config and public prototypes from main. */ #ifndef E_MOD_MAIN_H #define E_MOD_MAIN_H typedef struct _Xkb { E_Module *module; E_Config_Dialog *cfd; Ecore_Event_Handler *evh; } Xkb; /* Prototypes */ void _xkb_update_icon(int); E_Config_Dialog *_xkb_cfg_dialog(E_Container *con, const char *params); extern Xkb _xkb; #endif
89f0782b8a40217f720363cd20512da771a3efb6
28d0f8c01599f8f6c711bdde0b59f9c2cd221203
/sys/dev/acpi/valz_acpi.c
4df842373ba0261fbd68751c2cfbc19d0ffd9f2e
[]
no_license
NetBSD/src
1a9cbc22ed778be638b37869ed4fb5c8dd616166
23ee83f7c0aea0777bd89d8ebd7f0cde9880d13c
refs/heads/trunk
2023-08-31T13:24:58.105962
2023-08-27T15:50:47
2023-08-27T15:50:47
88,439,547
656
348
null
2023-07-20T20:07:24
2017-04-16T20:03:43
null
UTF-8
C
false
false
16,976
c
valz_acpi.c
/* $NetBSD: valz_acpi.c,v 1.9 2021/01/29 15:49:55 thorpej Exp $ */ /*- * Copyright (c) 2002 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Masanori Kanaoka. * * 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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ /* * Copyright 2001 Bill Sommerfeld. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed for the NetBSD Project by * Wasabi Systems, Inc. * 4. The name of Wasabi Systems, Inc. may not be used to endorse * or promote products derived from this software without specific prior * written permission. * * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``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 WASABI SYSTEMS, INC * 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. */ /* * ACPI VALZ Driver for Toshiba dynabook R63/PS * This driver is based on vald_acpi.c */ /* * Obtain information of Toshiba "GHCI" Method from next URL. * http://www.buzzard.me.uk/toshiba/docs.html * http://memebeam.org/toys/ToshibaAcpiDriver */ #include <sys/cdefs.h> __KERNEL_RCSID(0, "$NetBSD: valz_acpi.c,v 1.9 2021/01/29 15:49:55 thorpej Exp $"); #include <sys/param.h> #include <sys/systm.h> #include <sys/device.h> #include <dev/acpi/acpica.h> #include <dev/acpi/acpireg.h> #include <dev/acpi/acpivar.h> #define _COMPONENT ACPI_RESOURCE_COMPONENT ACPI_MODULE_NAME ("valz_acpi") #define METHOD_HCI "GHCI" #define METHOD_HCI_ENABLE "ENAB" /* Operations */ /* Get */ #define HCI_GET 0xfe00 #define SCI_CHECK 0xf000 #define SCI_GET 0xf300 /* Set */ #define HCI_SET 0xff00 #define SCI_OPEN 0xf100 #define SCI_CLOSE 0xf200 #define SCI_SET 0xf400 /* Return codes */ #define HCI_SUCCESS 0x0000 #define HCI_FAILURE 0x1000 #define HCI_NOT_SUPPORTED 0x8000 #define HCI_INPUT_ERROR 0x8300 #define HCI_FIFO_EMPTY 0x8c00 #define SCI_OPENCLOSE_OK 0x0044 #define SCI_NOT_SUPPORTED 0x8000 #define SCI_ALREADY_OPEN 0x8100 #define SCI_NOT_OPEN 0x8200 #define SCI_NOT_PRESENT 0x8600 /* Functions */ #define HCI_LCD_BACKLIGHT 0x0002 #define HCI_ACADAPTOR 0x0003 #define HCI_SYSTEM_EVENT_FIFO 0x0016 #define HCI_KBD_BACKLIGHT 0x0017 #define HCI_DISPLAY_DEV 0x001c #define HCI_HOTKEY_EVENT 0x001e #define HCI_LCD_BRIGHTNESS 0x002a #define HCI_CPU_SPEED 0x0032 #define SCI_USB_OFF_CHARGE 0x0150 #define SCI_TOUCHPAD 0x050e #define SCI_KBD_BACKLIGHT_STS 0x015c #define SCI_KBD_BACKLIGHT 0x0095 #define SCI_KBD_BL_TIME_SHIFT 0x10 /* Field definitions */ #define HCI_LCD_BRIGHTNESS_BITS 3 #define HCI_LCD_BRIGHTNESS_SFT (16 - HCI_LCD_BRIGHTNESS_BITS) #define HCI_LCD_BRIGHTNESS_MIN 0 #define HCI_LCD_BRIGHTNESS_MAX 7 #define HCI_VIDEO_DEVICE_FLG 0x0100 #define HCI_CPU_SPEED_BITS 3 #define HCI_CPU_SPEED_SFT (16 - HCI_CPU_SPEED_BITS) #define HCI_CPU_SPEED_MAX ((1 << HCI_CPU_SPEED_BITS) - 1) /* Key press/release events */ /* Key press/release events */ #define FN_RELEASE_OFFSET 0x80 # if 0 /* Not used */ #define FN_PRESS 0x01ff #define FN_RELEASE 0x0100 # endif #define FN_ESC_PRESS 0x0101 #define FN_ESC_RELEASE (FN_ESC_PRESS + FN_RELEASE_OFFSET) #define FN_F1_PRESS 0x013b #define FN_F1_RELEASE (FN_F1_PRESS + FN_RELEASE_OFFSET) #define FN_F2_PRESS 0x013c #define FN_F2_RELEASE (FN_F2_PRESS + FN_RELEASE_OFFSET) #define FN_F3_PRESS 0x013d #define FN_F3_RELEASE (FN_F3_PRESS + FN_RELEASE_OFFSET) #define FN_F4_PRESS 0x013e #define FN_F4_RELEASE (FN_F4_PRESS + FN_RELEASE_OFFSET) #define FN_F5_PRESS 0x013f #define FN_F5_RELEASE (FN_F5_PRESS + FN_RELEASE_OFFSET) #define FN_F6_PRESS 0x0140 #define FN_F6_RELEASE (FN_F6_PRESS + FN_RELEASE_OFFSET) #define FN_F7_PRESS 0x0141 #define FN_F7_RELEASE (FN_F7_PRESS + FN_RELEASE_OFFSET) #define FN_F8_PRESS 0x0142 #define FN_F8_RELEASE (FN_F8_PRESS + FN_RELEASE_OFFSET) #define FN_F9_PRESS 0x0143 #define FN_F9_RELEASE (FN_F9_PRESS + FN_RELEASE_OFFSET) /* Toggle, they are controlled by hardware */ #define FN_F10_ON 0x1bb0 #define FN_F10_OFF 0x1bb1 #define FN_F11_ON 0x1bb2 #define FN_F11_OFF 0x1bb3 /* Fn+F12 does not emit keycode */ /* dynabook R63/PS does not have KANJI keytop print */ #define FN_KNJ_PRESS 0x0129 #define FN_KNJ_RELEASE (FN_KNJ_PRESS + FN_RELEASE_OFFSET) #define FN_1_PRESS 0x0102 #define FN_1_RELEASE (FN_1_PRESS + FN_RELEASE_OFFSET) #define FN_2_PRESS 0x0103 #define FN_2_RELEASE (FN_2_PRESS + FN_RELEASE_OFFSET) /* Fn+3 and Fn+4 do not emit keybode */ #define FN_Z_PRESS 0x012c #define FN_Z_RELEASE (FN_1_PRESS + FN_RELEASE_OFFSET) #define FN_SPACE_PRESS 0x0139 #define FN_SPACE_RELEASE (FN_1_PRESS + FN_RELEASE_OFFSET) #define FN_TAB_PRESS 0x010f #define FN_TAB_RELEASE (FN_TAB_PRESS + FN_RELEASE_OFFSET) #define FN_CAPS_PRESS 0x013a #define FN_CAPS_RELEASE (FN_CAPS_PRESS + FN_RELEASE_OFFSET) #define FN_BACKSPACE_PRESS 0x010e #define FN_BACKSPACE_RELEASE (FN_BACKSPACE_PRESS + FN_RELEASE_OFFSET) #define FN_INS_PRESS 0x0152 #define FN_INS_RELEASE (FN_INS_PRESS + FN_RELEASE_OFFSET) #define FN_DEL_PRESS 0x0153 #define FN_DEL_RELEASE (FN_DEL_PRESS + FN_RELEASE_OFFSET) #define FN_PRTSC_PRESS 0x0137 #define FN_PRTSC_RELEASE (FN_PRTSC_PRESS + FN_RELEASE_OFFSET) /* HCI register definitions */ #define HCI_WORDS 6 /* number of registers */ #define HCI_REG_AX 0 /* Operation -> return value */ #define HCI_REG_BX 1 /* Function */ #define HCI_REG_CX 2 /* Argument (in or out) */ #define HCI_REG_DX 3 /* unused */ #define HCI_REG_SI 4 /* unused */ #define HCI_REG_DI 5 /* unused */ #define HCI_ON 0x0001 #define HCI_OFF 0x0000 #define HCI_ENABLE 0x0001 #define HCI_DISABLE 0x0000 #define HCI_LCD 0x1 #define HCI_CRT 0x2 #define HCI_TV 0x4 #define SCI_KBD_BL_MODE_MASK 0x1f #define SCI_KBD_BL_TIMO_SFT 0x10 #define SCI_KBD_BL_MODE_AUTO 0x2 #define SCI_KBD_BL_MODE_ON 0x8 #define SCI_KBD_BL_MODE_OFF 0x10 struct valz_acpi_softc { device_t sc_dev; /* base device glue */ struct acpi_devnode *sc_node; /* our ACPI devnode */ }; static const struct device_compatible_entry compat_data[] = { { .compat = "TOS6208" }, DEVICE_COMPAT_EOL }; static int valz_acpi_match(device_t, cfdata_t, void *); static void valz_acpi_attach(device_t, device_t, void *); static void valz_acpi_event(void *); static void valz_acpi_notify_handler(ACPI_HANDLE, uint32_t, void *); #define ACPI_NOTIFY_ValzHotkeyPressed 0x80 #define ACPI_NOTIFY_ValzLidClosed 0x8f #define ACPI_NOTIFY_ValzKbdBLChanges 0x92 /* HCI manipulation */ static ACPI_STATUS hci_op(struct valz_acpi_softc *, uint32_t *, uint32_t *); static ACPI_STATUS valz_acpi_hci_get(struct valz_acpi_softc *, uint32_t, uint32_t, uint32_t *, uint32_t *); static ACPI_STATUS valz_acpi_hci_set(struct valz_acpi_softc *, uint32_t, uint32_t, uint32_t, uint32_t *); static ACPI_STATUS sci_open(struct valz_acpi_softc *); static ACPI_STATUS sci_close(struct valz_acpi_softc *); static ACPI_STATUS valz_acpi_touchpad_toggle(struct valz_acpi_softc *); static ACPI_STATUS valz_acpi_lcd_backlight_toggle( struct valz_acpi_softc *sc); CFATTACH_DECL_NEW(valz_acpi, sizeof(struct valz_acpi_softc), valz_acpi_match, valz_acpi_attach, NULL, NULL); /* * valz_acpi_match: * * Autoconfiguration `match' routine. */ static int valz_acpi_match(device_t parent, cfdata_t match, void *aux) { struct acpi_attach_args *aa = aux; return acpi_compatible_match(aa, compat_data); } /* * valz_acpi_attach: * * Autoconfiguration `attach' routine. */ static void valz_acpi_attach(device_t parent, device_t self, void *aux) { struct valz_acpi_softc *sc = device_private(self); struct acpi_attach_args *aa = aux; ACPI_STATUS rv; aprint_naive(": Toshiba VALZ\n"); aprint_normal(": Toshiba VALZ\n"); sc->sc_node = aa->aa_node; sc->sc_dev = self; /* enable valz notify */ rv = AcpiEvaluateObject(sc->sc_node->ad_handle, METHOD_HCI_ENABLE, NULL, NULL); if (ACPI_FAILURE(rv)) { aprint_error("Cannot enable VALZ.\n"); } else { (void)acpi_register_notify(sc->sc_node, valz_acpi_notify_handler); } } /* * valz_acpi_notify_handler: * * Notify handler. */ static void valz_acpi_notify_handler(ACPI_HANDLE handle, uint32_t notify, void *context) { struct valz_acpi_softc *sc; device_t self = context; sc = device_private(self); switch (notify) { case ACPI_NOTIFY_ValzHotkeyPressed: (void)AcpiOsExecute(OSL_NOTIFY_HANDLER, valz_acpi_event, sc); break; case ACPI_NOTIFY_ValzLidClosed: /* Lid closed */ break; case ACPI_NOTIFY_ValzKbdBLChanges: /* Keyboard backlight mode changed */ break; default: aprint_debug_dev(sc->sc_dev, "unknown notify 0x%02X\n", notify); break; } } /* * valz_acpi_event: * * Check hotkey event and do it, if event occur. */ static void valz_acpi_event(void *arg) { struct valz_acpi_softc *sc = arg; ACPI_STATUS rv; uint32_t value, result; for (;;) { rv = valz_acpi_hci_get(sc, HCI_GET, HCI_SYSTEM_EVENT_FIFO, &value, &result); if (ACPI_SUCCESS(rv) && result == 0) { switch (value) { case FN_F9_PRESS: valz_acpi_touchpad_toggle(sc); break; case FN_TAB_PRESS: valz_acpi_lcd_backlight_toggle(sc); break; default: /* Many unused buttons */ aprint_debug("Pressed: 0x%x\n", value); break; } } if (ACPI_FAILURE(rv) || result == HCI_NOT_SUPPORTED || result == HCI_FIFO_EMPTY) break; } } /* * HCI/SCI operation */ static ACPI_STATUS hci_op(struct valz_acpi_softc *sc, uint32_t *input, uint32_t *output) { ACPI_STATUS rv; ACPI_OBJECT Arg[HCI_WORDS]; ACPI_OBJECT_LIST ArgList; ACPI_OBJECT *param, *PrtElement; ACPI_BUFFER buf; int i; for (i = 0; i < HCI_WORDS; i++) { Arg[i].Type = ACPI_TYPE_INTEGER; Arg[i].Integer.Value = 0; } for (i = 0; i < HCI_WORDS; i++) { Arg[i].Integer.Value = input[i]; } ArgList.Count = HCI_WORDS; ArgList.Pointer = Arg; buf.Pointer = NULL; buf.Length = ACPI_ALLOCATE_BUFFER; rv = AcpiEvaluateObjectTyped(sc->sc_node->ad_handle, METHOD_HCI, &ArgList, &buf, ACPI_TYPE_PACKAGE); if (ACPI_FAILURE(rv)) { aprint_error_dev(sc->sc_dev, "failed to evaluate GHCI: %s\n", AcpiFormatException(rv)); return rv; } param = (ACPI_OBJECT *)buf.Pointer; PrtElement = param->Package.Elements; for (i = 0; i < HCI_WORDS; i++) { output[i] = PrtElement[i].Type == ACPI_TYPE_INTEGER ? PrtElement[i].Integer.Value : 0; } ACPI_FREE(buf.Pointer); return rv; } /* * valz_acpi_hci_get: * * Get value via "GHCI" Method. */ static ACPI_STATUS valz_acpi_hci_get(struct valz_acpi_softc *sc, uint32_t function, uint32_t reg, uint32_t *value, uint32_t *result) { ACPI_STATUS rv; uint32_t input[HCI_WORDS]; uint32_t output[HCI_WORDS]; input[HCI_REG_AX] = function; input[HCI_REG_BX] = reg; input[HCI_REG_CX] = 0; input[HCI_REG_DX] = 0; input[HCI_REG_SI] = 0; input[HCI_REG_DI] = 0; rv = hci_op(sc, input, output); *result = output[HCI_REG_AX]; *value = output[HCI_REG_CX]; return rv; } /* * valz_acpi_hci_set: * * Set value via "GHCI" Method. */ static ACPI_STATUS valz_acpi_hci_set(struct valz_acpi_softc *sc, uint32_t function, uint32_t reg, uint32_t value, uint32_t *result) { ACPI_STATUS rv; uint32_t input[HCI_WORDS]; uint32_t output[HCI_WORDS]; input[HCI_REG_AX] = function; input[HCI_REG_BX] = reg; input[HCI_REG_CX] = value; input[HCI_REG_DX] = 0; input[HCI_REG_SI] = 0; input[HCI_REG_DI] = 0; rv = hci_op(sc, input, output); *result = output[HCI_REG_AX]; return rv; } /* * Open SCI */ static ACPI_STATUS sci_open(struct valz_acpi_softc *sc) { ACPI_STATUS rv; uint32_t result; rv = valz_acpi_hci_set(sc, SCI_OPEN, 0, 0, &result); if (ACPI_FAILURE(rv)) { aprint_error("SCI: ACPI set error\n"); } else { switch (result) { case SCI_OPENCLOSE_OK: aprint_debug("Opening SCI\n"); break; case SCI_ALREADY_OPEN: aprint_error("SCI already open\n"); break; case SCI_NOT_SUPPORTED: aprint_error("SCI is not supported\n"); break; case SCI_NOT_PRESENT: aprint_error("SCI is not present\n"); break; default: aprint_error("SCI: undefined behavior\n"); break; } } return rv; } /* * Close SCI */ static ACPI_STATUS sci_close(struct valz_acpi_softc *sc) { ACPI_STATUS rv; uint32_t result; rv = valz_acpi_hci_set(sc, SCI_CLOSE, 0, 0, &result); if (ACPI_FAILURE(rv)) { aprint_error("SCI: ACPI set error\n"); } else { switch (result) { case SCI_OPENCLOSE_OK: aprint_debug("Closing SCI\n"); break; case SCI_NOT_OPEN: aprint_error("SCI is not opened\n"); break; case SCI_NOT_SUPPORTED: aprint_error("SCI is not supported\n"); break; case SCI_NOT_PRESENT: aprint_error("SCI is not present\n"); break; default: aprint_error("SCI: undefined behavior\n"); break; } } return rv; } /* * Enable/disable touchpad and trackpoint with HCI_ENABLE/HCI_DISABLE */ static ACPI_STATUS valz_acpi_touchpad_toggle(struct valz_acpi_softc *sc) { ACPI_STATUS rv; uint32_t result, status, value; rv = sci_open(sc); if (ACPI_FAILURE(rv)) aprint_error_dev(sc->sc_dev, "Cannot open SCI: %s\n", AcpiFormatException(rv)); rv = valz_acpi_hci_get(sc, SCI_GET, SCI_TOUCHPAD, &value, &result); if (ACPI_FAILURE(rv)) aprint_error_dev(sc->sc_dev, "Cannot get SCI touchpad status: %s\n", AcpiFormatException(rv)); switch (value) { case HCI_ENABLE: status = HCI_DISABLE; break; case HCI_DISABLE: status = HCI_ENABLE; break; default: status = HCI_ENABLE; break; } rv = valz_acpi_hci_set(sc, SCI_SET, SCI_TOUCHPAD, status, &result); if (ACPI_FAILURE(rv)) aprint_error_dev(sc->sc_dev, "Cannot set SCI touchpad status: %s\n", AcpiFormatException(rv)); rv = sci_close(sc); if (ACPI_FAILURE(rv)) aprint_error_dev(sc->sc_dev, "Cannot close SCI: %s\n", AcpiFormatException(rv)); return rv; } /* * Enable/disable LCD backlight with HCI_ENABLE/HCI_DISABLE */ static ACPI_STATUS valz_acpi_lcd_backlight_toggle(struct valz_acpi_softc *sc) { ACPI_STATUS rv; uint32_t result, status, value; rv = valz_acpi_hci_get(sc, HCI_GET, HCI_LCD_BACKLIGHT, &value, &result); if (ACPI_FAILURE(rv)) aprint_error_dev(sc->sc_dev, "Cannot get HCI LCD backlight status: %s\n", AcpiFormatException(rv)); switch (value) { case HCI_ON: status = HCI_OFF; break; case HCI_OFF: status = HCI_ON; break; default: status = HCI_ON; break; } rv = valz_acpi_hci_set(sc, HCI_SET, HCI_LCD_BACKLIGHT, status, &result); if (ACPI_FAILURE(rv)) aprint_error_dev(sc->sc_dev, "Cannot set HCI LCD backlight status: %s\n", AcpiFormatException(rv)); return rv; }
c6dea9561d91c6f70c24ef6de51e5220c8053a28
fbe68d84e97262d6d26dd65c704a7b50af2b3943
/third_party/virtualbox/src/VBox/Additions/solaris/Mouse/testcase/solaris.h
2b59bf98b45168b278ed9e550399bdf300222f0b
[ "MIT", "GPL-2.0-only", "LicenseRef-scancode-unknown-license-reference", "CDDL-1.0", "LicenseRef-scancode-warranty-disclaimer", "GPL-1.0-or-later", "LGPL-2.1-or-later", "GPL-2.0-or-later", "MPL-1.0", "LicenseRef-scancode-generic-exception", "Apache-2.0", "OpenSSL" ]
permissive
thalium/icebox
c4e6573f2b4f0973b6c7bb0bf068fe9e795fdcfb
6f78952d58da52ea4f0e55b2ab297f28e80c1160
refs/heads/master
2022-08-14T00:19:36.984579
2022-02-22T13:10:31
2022-02-22T13:10:31
190,019,914
585
109
MIT
2022-01-13T20:58:15
2019-06-03T14:18:12
C++
UTF-8
C
false
false
12,118
h
solaris.h
/* $Id: solaris.h $ */ /** @file * VBoxGuest - Guest Additions Driver for Solaris - testcase stubs. */ /* * Copyright (C) 2012-2017 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; * you can redistribute it and/or modify it under the terms of the GNU * General Public License (GPL) as published by the Free Software * Foundation, in version 2 as it comes in the "COPYING" file of the * VirtualBox OSE distribution. VirtualBox OSE is distributed in the * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. * * The contents of this file may alternatively be used under the terms * of the Common Development and Distribution License Version 1.0 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the * VirtualBox OSE distribution, in which case the provisions of the * CDDL are applicable instead of those of the GPL. * * You may elect to license modified versions of this file under the * terms and conditions of either the GPL or the CDDL or both. */ #ifndef ___VBoxGuestTestCaseSolaris_h #define ___VBoxGuestTestCaseSolaris_h #include <iprt/assert.h> #include <iprt/string.h> /* RT_ZERO */ #ifdef RT_OS_WINDOWS # include <iprt/win/winsock2.h> /* struct timeval */ #endif #include <errno.h> #include <time.h> /* struct timeval */ /* Overrides */ #define dev_t unsigned /* Constants */ #define DDI_FAILURE (-1) #define DDI_SUCCESS (0) #define MODMAXNAMELEN 32 #define MODMAXLINKINFOLEN 32 #define MODMAXLINK 10 #define MOD_NOAUTOUNLOAD 0x1 #define M_DATA 0x00 #define M_BREAK 0x08 #define M_PASSFP 0x09 #define M_EVENT 0x0a #define M_SIG 0x0b #define M_DELAY 0x0c #define M_CTL 0x0d #define M_IOCTL 0x0e #define M_SETOPTS 0x10 #define M_RSE 0x11 #define M_IOCACK 0x81 #define M_IOCNAK 0x82 #define M_PCPROTO 0x83 #define M_PCSIG 0x84 #define M_READ 0x85 #define M_FLUSH 0x86 #define M_STOP 0x87 #define M_START 0x88 #define M_HANGUP 0x89 #define M_ERROR 0x8a #define M_COPYIN 0x8b #define M_COPYOUT 0x8c #define M_IOCDATA 0x8d #define M_PCRSE 0x8e #define M_STOPI 0x8f #define M_STARTI 0x90 #define M_PCEVENT 0x91 #define M_UNHANGUP 0x92 #define M_CMD 0x93 #define BPRI_LO 1 #define BPRI_MED 2 #define BPRI_HI 3 #define FLUSHALL 1 #define FLUSHDATA 0 #define TRANSPARENT (unsigned int)(-1) #define FLUSHR 0x01 #define FLUSHW 0x02 #define MSIOC ('m'<<8) #define MSIOGETPARMS (MSIOC|1) #define MSIOSETPARMS (MSIOC|2) #define MSIOBUTTONS (MSIOC|3) #define MSIOSRESOLUTION (MSIOC|4) #define VUIOC ('v'<<8) #define VUIDSFORMAT (VUIOC|1) #define VUIDGFORMAT (VUIOC|2) #define VUID_NATIVE 0 #define VUID_FIRM_EVENT 1 #define VUIDSADDR (VUIOC|3) #define VUIDGADDR (VUIOC|4) #define VUID_WHEEL_MAX_COUNT 256 #define VUIDGWHEELCOUNT (VUIOC|15) #define VUIDGWHEELINFO (VUIOC|16) #define VUIDGWHEELSTATE (VUIOC|17) #define VUIDSWHEELSTATE (VUIOC|18) #define DDI_DEVICE_ATTR_V0 0x0001 #define DDI_DEVICE_ATTR_V1 0x0002 #define DDI_NEVERSWAP_ACC 0x00 #define DDI_STRUCTURE_LE_ACC 0x01 #define DDI_STRUCTURE_BE_ACC 0x02 #define DDI_STRICTORDER_ACC 0x00 #define DDI_UNORDERED_OK_ACC 0x01 #define DDI_MERGING_OK_ACC 0x02 #define DDI_LOADCACHING_OK_ACC 0x03 #define DDI_STORECACHING_OK_ACC 0x04 /** @todo fix this */ #define DDI_DEFAULT_ACC DDI_STRICTORDER_ACC #define DDI_INTR_CLAIMED 1 #define DDI_INTR_UNCLAIMED 0 #define DDI_INTR_TYPE_FIXED 0x1 #define DDI_INTR_TYPE_MSI 0x2 #define DDI_INTR_TYPE_MSIX 0x4 #define LOC_FIRST_DELTA 32640 #define LOC_X_DELTA 32640 #define LOC_Y_DELTA 32641 #define LOC_LAST_DELTA 32641 #define LOC_FIRST_ABSOLUTE 32642 #define LOC_X_ABSOLUTE 32642 #define LOC_Y_ABSOLUTE 32643 #define LOC_LAST_ABSOLUTE 32643 #define FE_PAIR_NONE 0 #define FE_PAIR_SET 1 #define FE_PAIR_DELTA 2 #define FE_PAIR_ABSOLUTE 3 typedef struct __ldi_handle *ldi_handle_t; typedef enum { DDI_INFO_DEVT2DEVINFO = 0, DDI_INFO_DEVT2INSTANCE = 1 } ddi_info_cmd_t; typedef enum { DDI_ATTACH = 0, DDI_RESUME = 1, DDI_PM_RESUME = 2 } ddi_attach_cmd_t; typedef enum { DDI_DETACH = 0, DDI_SUSPEND = 1, DDI_PM_SUSPEND = 2, DDI_HOTPLUG_DETACH = 3 } ddi_detach_cmd_t; /* Simple types */ typedef struct cred *cred_t; typedef struct dev_info *dev_info_t; typedef struct __ddi_acc_handle * ddi_acc_handle_t; typedef struct __ddi_intr_handle *ddi_intr_handle_t; typedef struct mutex *kmutex_t; typedef unsigned int uint_t; typedef unsigned short ushort_t; typedef unsigned char uchar_t; /* Structures */ struct modspecific_info { char msi_linkinfo[MODMAXLINKINFOLEN]; int msi_p0; }; struct modinfo { int mi_info; int mi_state; int mi_id; int mi_nextid; char *mi_base; /* Was caddr_t. */ size_t mi_size; int mi_rev; int mi_loadcnt; char mi_name[MODMAXNAMELEN]; struct modspecific_info mi_msinfo[MODMAXLINK]; }; typedef struct queue { struct qinit *q_qinfo; struct msgb *q_first; struct msgb *q_last; struct queue *q_next; void *q_ptr; size_t q_count; uint_t q_flag; ssize_t q_minpsz; ssize_t q_maxpsz; size_t q_hiwat; size_t q_lowat; } queue_t; typedef struct msgb { struct msgb *b_next; struct msgb *b_prev; struct msgb *b_cont; unsigned char *b_rptr; unsigned char *b_wptr; struct datab *b_datap; unsigned char b_band; unsigned short b_flag; } mblk_t; typedef struct datab { unsigned char *db_base; unsigned char *db_lim; unsigned char db_ref; unsigned char db_type; } dblk_t; struct iocblk { int ioc_cmd; cred_t *ioc_cr; uint_t ioc_id; uint_t ioc_flag; size_t ioc_count; int ioc_rval; int ioc_error; #if defined(RT_ARCH_AMD64) /* Actually this should be LP64. */ int dummy; /* For simplicity, to ensure the structure size matches struct copyreq. */ #endif }; struct copyreq { int cq_cmd; cred_t *cq_cr; uint_t cq_id; uint_t cq_flag; mblk_t *cq_private; char *cq_addr; /* Was caddr_t. */ size_t cq_size; }; struct copyresp { int cp_cmd; cred_t *cp_cr; uint_t cp_id; uint_t cp_flag; mblk_t *cp_private; char *cp_rval; /* Was caddr_t. */ }; typedef struct modctl { /* ... */ char mod_loadflags; /* ... */ } modctl_t; typedef struct { int jitter_thresh; int speed_law; int speed_limit; } Ms_parms; typedef struct { int height; int width; } Ms_screen_resolution; typedef struct vuid_addr_probe { short base; union { short next; short current; } data; } Vuid_addr_probe; typedef struct ddi_device_acc_attr { ushort_t devacc_attr_version; uchar_t devacc_attr_endian_flags; uchar_t devacc_attr_dataorder; uchar_t devacc_attr_access; } ddi_device_acc_attr_t; typedef struct firm_event { ushort_t id; uchar_t pair_type; uchar_t pair; int value; struct timeval time; } Firm_event; /* Prototypes */ #define _init vboxguestSolarisInit extern int vboxguestSolarisInit(void); #define _fini vboxguestSolarisFini extern int vboxguestSolarisFini(void); #define _info vboxguestSolarisInfo extern int vboxguestSolarisInfo(struct modinfo *pModInfo); /* Simple API stubs */ #define cmn_err(...) do {} while(0) #define mod_remove(...) 0 #define mod_info(...) 0 #define RTR0Init(...) VINF_SUCCESS #define RTR0Term(...) do {} while(0) #define RTR0AssertPanicSystem(...) do {} while(0) #define RTLogCreate(...) VINF_SUCCESS #define RTLogRelSetDefaultInstance(...) do {} while(0) #define RTLogDestroy(...) do {} while(0) #if 0 #define VBoxGuestCreateKernelSession(...) VINF_SUCCESS #define VBoxGuestCreateUserSession(...) VINF_SUCCESS #define VBoxGuestCloseSession(...) do {} while(0) #define VBoxGuestInitDevExt(...) VINF_SUCCESS #define VBoxGuestDeleteDevExt(...) do {} while(0) #define VBoxGuestCommonIOCtl(...) VINF_SUCCESS #define VBoxGuestCommonISR(...) true #define VbglR0GRAlloc(...) VINF_SUCCESS #define VbglR0GRPerform(...) VINF_SUCCESS #define VbglR0GRFree(...) do {} while(0) #endif #define VbglR0InitClient(...) VINF_SUCCESS #define vbglDriverOpen(...) VINF_SUCCESS #define vbglDriverClose(...) do {} while(0) #define vbglDriverIOCtl(...) VINF_SUCCESS #define qprocson(...) do {} while(0) #define qprocsoff(...) do {} while(0) #define flushq(...) do {} while(0) #define putnext(...) do {} while(0) #define ddi_get_instance(...) 0 #define pci_config_setup(...) DDI_SUCCESS #define pci_config_teardown(...) do {} while(0) #define ddi_regs_map_setup(...) DDI_SUCCESS #define ddi_regs_map_free(...) do {} while(0) #define ddi_dev_regsize(...) DDI_SUCCESS #define ddi_create_minor_node(...) DDI_SUCCESS #define ddi_remove_minor_node(...) do {} while(0) #define ddi_intr_get_supported_types(...) DDI_SUCCESS #define ddi_intr_get_nintrs(...) DDI_SUCCESS #define ddi_intr_get_navail(...) DDI_SUCCESS #define ddi_intr_alloc(...) DDI_SUCCESS #define ddi_intr_free(...) do {} while(0) #define ddi_intr_get_pri(...) DDI_SUCCESS #define ddi_intr_enable(...) DDI_SUCCESS #define ddi_intr_disable(...) DDI_SUCCESS #define ddi_intr_add_handler(...) DDI_SUCCESS #define ddi_intr_remove_handler(...) DDI_SUCCESS #define mutex_init(...) do {} while(0) #define mutex_destroy(...) do {} while(0) #define mutex_enter(...) do {} while(0) #define mutex_exit(...) do {} while(0) #define uniqtime32(...) do {} while(0) #define canput(...) true #define putbq(...) do {} while(0) /* Externally defined helpers. */ /** Flags set in the struct mblk b_flag member for verification purposes. * @{ */ /** miocpullup was called for this message. */ #define F_TEST_PULLUP 1 /** @} */ extern void miocack(queue_t *pWriteQueue, mblk_t *pMBlk, int cbData, int rc); extern void miocnak(queue_t *pWriteQueue, mblk_t *pMBlk, int cbData, int iErr); extern int miocpullup(mblk_t *pMBlk, size_t cbMsg); extern void mcopyin(mblk_t *pMBlk, void *pvState, size_t cbData, void *pvUser); extern void mcopyout(mblk_t *pMBlk, void *pvState, size_t cbData, void *pvUser, mblk_t *pMBlkData); extern void qreply(queue_t *pQueue, mblk_t *pMBlk); extern mblk_t *allocb(size_t cb, uint_t cPrio); extern void freemsg(mblk_t *pMsg); /* API stubs with simple logic */ static modctl_t s_ModCtl; static void **s_pvLinkage; static inline modctl_t *mod_getctl(void **linkage) { s_pvLinkage = linkage; return s_pvLinkage ? &s_ModCtl : NULL; } #define mod_install(linkage) (s_pvLinkage && ((linkage) == s_pvLinkage) ? 0 : EINVAL) #define QREADR 0x00000010 #define OTHERQ(q) ((q)->q_flag & QREADR ? (q) + 1 : (q) - 1) #define WR(q) ((q)->q_flag & QREADR ? (q) + 1 : (q)) #define RD(q) ((q)->q_flag & QREADR ? (q) : (q) - 1) /* Basic initialisation of a queue structure pair for testing. */ static inline void doInitQueues(queue_t aQueues[2]) { aQueues[0].q_flag = QREADR; } static inline dev_t makedevice(unsigned cMajor, unsigned cMinor) { return cMajor * 4096 + cMinor; } static inline unsigned getmajor(dev_t device) { return device / 4096; } /* API stubs with controllable logic */ #endif /* ___VBoxGuestTestCaseSolaris_h */
48bfe47c7b78cc1085c3017e3942e4ad6a529fb4
79d343002bb63a44f8ab0dbac0c9f4ec54078c3a
/lib/libc/include/any-linux-any/linux/module.h
e3e7b3c91fe54a1026f4d960abbff7b4cfb9ddbe
[ "MIT" ]
permissive
ziglang/zig
4aa75d8d3bcc9e39bf61d265fd84b7f005623fc5
f4c9e19bc3213c2bc7e03d7b06d7129882f39f6c
refs/heads/master
2023-08-31T13:16:45.980913
2023-08-31T05:50:29
2023-08-31T05:50:29
40,276,274
25,560
2,399
MIT
2023-09-14T21:09:50
2015-08-06T00:51:28
Zig
UTF-8
C
false
false
292
h
module.h
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ #ifndef _LINUX_MODULE_H #define _LINUX_MODULE_H /* Flags for sys_finit_module: */ #define MODULE_INIT_IGNORE_MODVERSIONS 1 #define MODULE_INIT_IGNORE_VERMAGIC 2 #define MODULE_INIT_COMPRESSED_FILE 4 #endif /* _LINUX_MODULE_H */
9e5d81421bf482539135cd4581183d16567c488d
ac2f43c8e0d9649a7f063c59b3dffdfed9fd7ed7
/common/recipes-utils/tpm-factory-upd/files/Source/Common/FirmwareImage.h
874f2c6c84bcaed989cdba12626f441f035d089e
[ "BSD-2-Clause" ]
permissive
facebook/openbmc
bef10604ced226288600f55248b7f1be9945aea4
32777c66a8410d767eae15baabf71c61a0bef13c
refs/heads/helium
2023-08-17T03:13:54.729494
2023-08-16T23:24:18
2023-08-16T23:24:18
31,917,712
684
331
null
2023-07-25T21:19:08
2015-03-09T19:18:35
C
UTF-8
C
false
false
7,917
h
FirmwareImage.h
/** * @brief Declares methods to access a firmware image * @details This module provides helper functions to access a firmware image. * @file FirmwareImage.h * @copyright Copyright 2014 - 2018 Infineon Technologies AG ( www.infineon.com ) * * @copyright All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #pragma once #include <StdInclude.h> #ifdef __cplusplus extern "C" { #endif /// Unique identifier for the IfxFirmwareImage structure static const GUID EFI_IFXTPM_FIRMWARE_IMAGE_GUID = { 0x1a53667a, 0xfb12, 0x479e, { 0xac, 0x58, 0xec, 0x99, 0x58, 0x86, 0x10, 0x93 } }; /// Unique identifier for newer version of the IfxFirmwareImage structure not compatible with this tool. static const GUID EFI_IFXTPM_FIRMWARE_IMAGE_2_GUID = { 0x1a53667a, 0xfb12, 0x479e, { 0xac, 0x58, 0xec, 0x99, 0x58, 0x86, 0x10, 0x94 } }; /// The ID of the signing key used to create the firmware image signature #define SIG_KEY_ID_1 0x0001 /// Indicates TPM1.2 firmware update. #define DEVICE_TYPE_TPM_12 0x01 /// Indicates TPM2.0 firmware update. #define DEVICE_TYPE_TPM_20 0x02 /// The maximum supported number of source TPM firmware versions in an image file #define MAX_SOURCE_VERSIONS_COUNT 8 /** * @brief TPM Target State bit field * @details This structure contains bit flags indicating the target state of the TPM after the firmware update. */ typedef struct tdBITFIELD_TPM_TARGET_STATE { /// This bit indicates if firmware update with this image will cause the TPM to be reset to factory defaults. unsigned int factoryDefaults : 1; /// This bit indicates if TPM Firmware Update will update the TPM to Common Criteria certified firmware. unsigned int commonCriteria : 1; /// This bit indicates if TPM Firmware Update will update the TPM to FIPS certified firmware. unsigned int fips : 1; /// Bits reserved for future use. unsigned int reserved3 : 29; } BITFIELD_TPM_TARGET_STATE; /** * @brief TPM firmware image capabilities bit field * @details This structure contains bit flags indicating capabilities of the TPM firmware image. */ typedef struct tdBITFIELD_FIRMWARE_IMAGE_CAPABILITIES { /// This bit indicates if the firmware image supports matching a unique ID in invalid firmware mode. unsigned int invalidFirmwareMode_matchUniqueID : 1; /// Bits reserved for future use. unsigned int reserved1 : 31; } BITFIELD_FIRMWARE_IMAGE_CAPABILITIES; /** * @brief Firmware image structure * @details This structure describes the firmware image that is passed to the driver in EFI_FIRMWARE_MANAGEMENT_PROTOCOL.SetImage and * EFI_FIRMWARE_MANAGEMENT_PROTOCOL.CheckImage. The structure parses all fields of the firmware image and copies them into the * structure, except for the parameter block and the firmware. Parameter block and the firmware are referenced by pointer and * length only. */ typedef struct tdIfxFirmwareImage { /// Unique identifier: Must be EFI_IFXTPM_FIRMWARE_IMAGE_GUID, a different version indicates a breaking change in firmware image file structure. /// If the unique identifier is EFI_IFXTPM_FIRMWARE_IMAGE_2_GUID then the firmware image is not supported by this version of the tool /// and a newer version of the tool is required to process the firmware image. GUID unique; /// Allowed TPM family where the firmware image can be installed on. Either DEVICE_TYPE_TPM_12 or DEVICE_TYPE_TPM_20. unsigned char bSourceTpmFamily; /// Count of the allowed source versions unsigned short usSourceVersionsCount; /// Allowed version names (e.g. "5.12.3456.0") where the firmware update can be applied to. wchar_t rgwszSourceVersions[MAX_SOURCE_VERSIONS_COUNT][64]; /// Target TPM family. Either DEVICE_TYPE_TPM_12 or DEVICE_TYPE_TPM_20. unsigned char bTargetTpmFamily; /// Size in bytes of wszTargetVersion. Uses big-endian format. unsigned short usTargetVersionSize; /// Target version name (e.g. "5.12.3456.0") wszTargetVersion includes a terminating NULL character. /// Size of wszTargetVersion is usTargetVersionSize. wchar_t wszTargetVersion[64]; /// Size in bytes of the policy parameter block in rgbPolicyParameterBlock. Uses big-endian format. unsigned short usPolicyParameterBlockSize; /// Policy parameter block. Size is usPolicyParameterBlockSize. unsigned char* rgbPolicyParameterBlock; /// Size in bytes of the firmware block in rgbFirmware. Uses big-endian format. unsigned int unFirmwareSize; /// Firmware block. Size is unFirmwareSize. unsigned char* rgbFirmware; /// Version number indicating the structure version of the firmware image. Will be increased with every non-breaking firmware image file structure change. unsigned short usImageStructureVersion; /// Target state BITFIELD_TPM_TARGET_STATE bfTargetState; /// Firmware image capabilities BITFIELD_FIRMWARE_IMAGE_CAPABILITIES bfCapabilities; /// Count of the allowed source versions (unsigned integer representation) unsigned short usIntSourceVersionCount; /// Allowed source versions (unsigned integer representation) unsigned int rgunIntSourceVersions[MAX_SOURCE_VERSIONS_COUNT]; /// Checksum over the IfxFirmwareImage structure excluding the unChecksum field. Uses big-endian format. unsigned int unChecksum; /// Key identifier for signature unsigned short usSignatureKeyId; /// Byte array for signature BYTE rgbSignature[256]; } IfxFirmwareImage; /** * @brief Function to unmarshal a IfxFirmwareImage from a byte stream * @details This function unmarshals the structures parameters. For all fields with variable * size the output structure contains a pointer to the buffers address where the data can be found. * * @param PpTarget Pointer to the target structure; must be allocated by the caller * @param PprgbBuffer Pointer to a byte stream containing the firmware image data; will be increased during execution by the amount of unmarshalled bytes * @param PpnBufferSize Size of elements readable from the byte stream; will be decreased during execution by the amount of unmarshalled bytes * @retval RC_SUCCESS In case the firmware is updatable with the given firmware * @retval RC_E_BAD_PARAMETER An invalid parameter was passed to the function or an error occurred at unmarshal. * @retval RC_E_BUFFER_TOO_SMALL In case an output buffer is too small for an input byte array * */ _Check_return_ unsigned int FirmwareImage_Unmarshal( _Out_ IfxFirmwareImage* PpTarget, _Inout_ unsigned char** PprgbBuffer, _Inout_ int* PpnBufferSize); #ifdef __cplusplus } #endif
c1d9f2dec567cb618d29a5eddcef3fd8df55c534
d61b532db0d3e08818338cfaac530a1ced1ffe3b
/lang/cem/libcc/gen/ttyslot.c
ffaf4ce8857addcf6ed3db6a7a817c947a8e4e18
[ "LicenseRef-scancode-other-permissive" ]
permissive
davidgiven/ack
61049c7a8e95ff61a77b1edd3c22bb290720e276
db5a32c68c4a60ca26a3927a799ea662b5b2b0e5
refs/heads/default
2023-08-29T07:33:12.771205
2023-07-08T20:17:27
2023-07-08T20:17:27
37,686,316
376
74
NOASSERTION
2023-07-08T20:17:28
2015-06-18T21:33:42
C
UTF-8
C
false
false
1,503
c
ttyslot.c
/* $Id$ */ #ifdef __USG /* system V, so no /etc/ttys file. In this case, scan the /etc/utmp file */ struct utmp { char ut_name[8]; char ut_id[4]; char ut_line[12]; short ut_pid; short ut_type; struct exit_status { short e_termination; short e_exit; } ut_exit; long ut_time; }; #define FILENAME "/etc/utmp" #else #define FILENAME "/etc/ttys" #endif char *ttyname(); char *rindex(); ttyslot() { register char *tp, *p; int fd; int retval = 1; #ifdef __USG struct utmp buf; #else char buf[32]; #endif if (! (tp=ttyname(0)) && ! (tp=ttyname(1)) && !(tp=ttyname(2))) return 0; if (! (p = rindex(tp, '/'))) p = tp; else p++; if ((fd = open(FILENAME, 0)) < 0) return 0; #ifdef __USG while (read(fd, (char *) &buf, sizeof(buf)) == sizeof(buf)) { /* processes associated with a terminal ... unfortunately we cannot use the include file because some systems have a different one ... INIT_PROCESS, DEAD_PROCESS, USER_PROCESS, LOGIN_PROCESS */ if ((buf.ut_type >= 5 && buf.ut_type <= 8) && ! strncmp(buf.ut_line, p, sizeof(buf.ut_line))) { close(fd); return retval; } retval++; } close(fd); return 0; #else for (;;) { tp = buf; for (;;tp++) { if (read(fd, tp, 1) != 1) { close(fd); return 0; } if (*tp == '\n' || tp >= &buf[31]) { *tp = 0; if (tp < buf+2) buf[2] = '\0'; tp = buf+2; break; } } if (! strcmp(p, tp)) { close(fd); return retval; } retval++; } /*NOTREACHED*/ #endif }
4a9fdef5c9e1deb10ab9468b82d899868fc7badb
88ae8695987ada722184307301e221e1ba3cc2fa
/third_party/wayland-protocols/gtk/gdk/win32/gdkdevicemanager-win32.c
d12666eed9dc70f71705edad01afefddfa571b9c
[ "Apache-2.0", "LGPL-2.0-or-later", "MIT", "GPL-1.0-or-later", "BSD-3-Clause", "LGPL-2.0-only", "LGPL-2.1-only" ]
permissive
iridium-browser/iridium-browser
71d9c5ff76e014e6900b825f67389ab0ccd01329
5ee297f53dc7f8e70183031cff62f37b0f19d25f
refs/heads/master
2023-08-03T16:44:16.844552
2023-07-20T15:17:00
2023-07-23T16:09:30
220,016,632
341
40
BSD-3-Clause
2021-08-13T13:54:45
2019-11-06T14:32:31
null
UTF-8
C
false
false
40,525
c
gdkdevicemanager-win32.c
/* GDK - The GIMP Drawing Kit * Copyright (C) 2009 Carlos Garnacho <carlosg@gnome.org> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see <http://www.gnu.org/licenses/>. */ #include "config.h" #include <stdlib.h> #include <stdio.h> #include <math.h> #include <gdk/gdk.h> #include "gdkwin32.h" #include "gdkprivate-win32.h" #include "gdkdevicemanager-win32.h" #include "gdkdeviceprivate.h" #include "gdkdevice-win32.h" #include "gdkdevice-virtual.h" #include "gdkdevice-wintab.h" #include "gdkdisplayprivate.h" #include "gdkseatdefaultprivate.h" #define WINTAB32_DLL "Wintab32.dll" #define PACKETDATA (PK_CONTEXT | PK_CURSOR | PK_BUTTONS | PK_X | PK_Y | PK_NORMAL_PRESSURE | PK_ORIENTATION) /* We want everything in absolute mode */ #define PACKETMODE (0) #include <pktdef.h> #define DEBUG_WINTAB 1 /* Verbose debug messages enabled */ #define TWOPI (2 * G_PI) static GList *wintab_contexts = NULL; static GdkSurface *wintab_window = NULL; extern int _gdk_input_ignore_core; typedef UINT (WINAPI *t_WTInfoA) (UINT a, UINT b, LPVOID c); typedef UINT (WINAPI *t_WTInfoW) (UINT a, UINT b, LPVOID c); typedef BOOL (WINAPI *t_WTEnable) (HCTX a, BOOL b); typedef HCTX (WINAPI *t_WTOpenA) (HWND a, LPLOGCONTEXTA b, BOOL c); typedef BOOL (WINAPI *t_WTGetA) (HCTX a, LPLOGCONTEXTA b); typedef BOOL (WINAPI *t_WTSetA) (HCTX a, LPLOGCONTEXTA b); typedef BOOL (WINAPI *t_WTOverlap) (HCTX a, BOOL b); typedef BOOL (WINAPI *t_WTPacket) (HCTX a, UINT b, LPVOID c); typedef int (WINAPI *t_WTQueueSizeSet) (HCTX a, int b); static t_WTInfoA p_WTInfoA; static t_WTInfoW p_WTInfoW; static t_WTEnable p_WTEnable; static t_WTOpenA p_WTOpenA; static t_WTGetA p_WTGetA; static t_WTSetA p_WTSetA; static t_WTOverlap p_WTOverlap; static t_WTPacket p_WTPacket; static t_WTQueueSizeSet p_WTQueueSizeSet; static gboolean default_display_opened = FALSE; G_DEFINE_TYPE (GdkDeviceManagerWin32, gdk_device_manager_win32, G_TYPE_OBJECT) static GdkDevice * create_pointer (GdkDeviceManagerWin32 *device_manager, GType g_type, const char *name, gboolean has_cursor) { return g_object_new (g_type, "name", name, "source", GDK_SOURCE_MOUSE, "has-cursor", has_cursor, "display", _gdk_display, NULL); } static GdkDevice * create_keyboard (GdkDeviceManagerWin32 *device_manager, GType g_type, const char *name) { return g_object_new (g_type, "name", name, "source", GDK_SOURCE_KEYBOARD, "has-cursor", FALSE, "display", _gdk_display, NULL); } static void gdk_device_manager_win32_init (GdkDeviceManagerWin32 *device_manager_win32) { } static void gdk_device_manager_win32_finalize (GObject *object) { GdkDeviceManagerWin32 *device_manager_win32; device_manager_win32 = GDK_DEVICE_MANAGER_WIN32 (object); g_object_unref (device_manager_win32->core_pointer); g_object_unref (device_manager_win32->core_keyboard); G_OBJECT_CLASS (gdk_device_manager_win32_parent_class)->finalize (object); } #if DEBUG_WINTAB static void print_lc(LOGCONTEXT *lc) { g_print ("lcName = %s\n", lc->lcName); g_print ("lcOptions ="); if (lc->lcOptions & CXO_SYSTEM) g_print (" CXO_SYSTEM"); if (lc->lcOptions & CXO_PEN) g_print (" CXO_PEN"); if (lc->lcOptions & CXO_MESSAGES) g_print (" CXO_MESSAGES"); if (lc->lcOptions & CXO_MARGIN) g_print (" CXO_MARGIN"); if (lc->lcOptions & CXO_MGNINSIDE) g_print (" CXO_MGNINSIDE"); if (lc->lcOptions & CXO_CSRMESSAGES) g_print (" CXO_CSRMESSAGES"); g_print ("\n"); g_print ("lcStatus ="); if (lc->lcStatus & CXS_DISABLED) g_print (" CXS_DISABLED"); if (lc->lcStatus & CXS_OBSCURED) g_print (" CXS_OBSCURED"); if (lc->lcStatus & CXS_ONTOP) g_print (" CXS_ONTOP"); g_print ("\n"); g_print ("lcLocks ="); if (lc->lcLocks & CXL_INSIZE) g_print (" CXL_INSIZE"); if (lc->lcLocks & CXL_INASPECT) g_print (" CXL_INASPECT"); if (lc->lcLocks & CXL_SENSITIVITY) g_print (" CXL_SENSITIVITY"); if (lc->lcLocks & CXL_MARGIN) g_print (" CXL_MARGIN"); g_print ("\n"); g_print ("lcMsgBase = %#x, lcDevice = %#x, lcPktRate = %d\n", lc->lcMsgBase, lc->lcDevice, lc->lcPktRate); g_print ("lcPktData ="); if (lc->lcPktData & PK_CONTEXT) g_print (" PK_CONTEXT"); if (lc->lcPktData & PK_STATUS) g_print (" PK_STATUS"); if (lc->lcPktData & PK_TIME) g_print (" PK_TIME"); if (lc->lcPktData & PK_CHANGED) g_print (" PK_CHANGED"); if (lc->lcPktData & PK_SERIAL_NUMBER) g_print (" PK_SERIAL_NUMBER"); if (lc->lcPktData & PK_CURSOR) g_print (" PK_CURSOR"); if (lc->lcPktData & PK_BUTTONS) g_print (" PK_BUTTONS"); if (lc->lcPktData & PK_X) g_print (" PK_X"); if (lc->lcPktData & PK_Y) g_print (" PK_Y"); if (lc->lcPktData & PK_Z) g_print (" PK_Z"); if (lc->lcPktData & PK_NORMAL_PRESSURE) g_print (" PK_NORMAL_PRESSURE"); if (lc->lcPktData & PK_TANGENT_PRESSURE) g_print (" PK_TANGENT_PRESSURE"); if (lc->lcPktData & PK_ORIENTATION) g_print (" PK_ORIENTATION"); if (lc->lcPktData & PK_ROTATION) g_print (" PK_ROTATION"); g_print ("\n"); g_print ("lcPktMode ="); if (lc->lcPktMode & PK_CONTEXT) g_print (" PK_CONTEXT"); if (lc->lcPktMode & PK_STATUS) g_print (" PK_STATUS"); if (lc->lcPktMode & PK_TIME) g_print (" PK_TIME"); if (lc->lcPktMode & PK_CHANGED) g_print (" PK_CHANGED"); if (lc->lcPktMode & PK_SERIAL_NUMBER) g_print (" PK_SERIAL_NUMBER"); if (lc->lcPktMode & PK_CURSOR) g_print (" PK_CURSOR"); if (lc->lcPktMode & PK_BUTTONS) g_print (" PK_BUTTONS"); if (lc->lcPktMode & PK_X) g_print (" PK_X"); if (lc->lcPktMode & PK_Y) g_print (" PK_Y"); if (lc->lcPktMode & PK_Z) g_print (" PK_Z"); if (lc->lcPktMode & PK_NORMAL_PRESSURE) g_print (" PK_NORMAL_PRESSURE"); if (lc->lcPktMode & PK_TANGENT_PRESSURE) g_print (" PK_TANGENT_PRESSURE"); if (lc->lcPktMode & PK_ORIENTATION) g_print (" PK_ORIENTATION"); if (lc->lcPktMode & PK_ROTATION) g_print (" PK_ROTATION"); g_print ("\n"); g_print ("lcMoveMask ="); if (lc->lcMoveMask & PK_CONTEXT) g_print (" PK_CONTEXT"); if (lc->lcMoveMask & PK_STATUS) g_print (" PK_STATUS"); if (lc->lcMoveMask & PK_TIME) g_print (" PK_TIME"); if (lc->lcMoveMask & PK_CHANGED) g_print (" PK_CHANGED"); if (lc->lcMoveMask & PK_SERIAL_NUMBER) g_print (" PK_SERIAL_NUMBER"); if (lc->lcMoveMask & PK_CURSOR) g_print (" PK_CURSOR"); if (lc->lcMoveMask & PK_BUTTONS) g_print (" PK_BUTTONS"); if (lc->lcMoveMask & PK_X) g_print (" PK_X"); if (lc->lcMoveMask & PK_Y) g_print (" PK_Y"); if (lc->lcMoveMask & PK_Z) g_print (" PK_Z"); if (lc->lcMoveMask & PK_NORMAL_PRESSURE) g_print (" PK_NORMAL_PRESSURE"); if (lc->lcMoveMask & PK_TANGENT_PRESSURE) g_print (" PK_TANGENT_PRESSURE"); if (lc->lcMoveMask & PK_ORIENTATION) g_print (" PK_ORIENTATION"); if (lc->lcMoveMask & PK_ROTATION) g_print (" PK_ROTATION"); g_print ("\n"); g_print ("lcBtnDnMask = %#x, lcBtnUpMask = %#x\n", (guint) lc->lcBtnDnMask, (guint) lc->lcBtnUpMask); g_print ("lcInOrgX = %ld, lcInOrgY = %ld, lcInOrgZ = %ld\n", lc->lcInOrgX, lc->lcInOrgY, lc->lcInOrgZ); g_print ("lcInExtX = %ld, lcInExtY = %ld, lcInExtZ = %ld\n", lc->lcInExtX, lc->lcInExtY, lc->lcInExtZ); g_print ("lcOutOrgX = %ld, lcOutOrgY = %ld, lcOutOrgZ = %ld\n", lc->lcOutOrgX, lc->lcOutOrgY, lc->lcOutOrgZ); g_print ("lcOutExtX = %ld, lcOutExtY = %ld, lcOutExtZ = %ld\n", lc->lcOutExtX, lc->lcOutExtY, lc->lcOutExtZ); g_print ("lcSensX = %g, lcSensY = %g, lcSensZ = %g\n", lc->lcSensX / 65536., lc->lcSensY / 65536., lc->lcSensZ / 65536.); g_print ("lcSysMode = %d\n", lc->lcSysMode); g_print ("lcSysOrgX = %d, lcSysOrgY = %d\n", lc->lcSysOrgX, lc->lcSysOrgY); g_print ("lcSysExtX = %d, lcSysExtY = %d\n", lc->lcSysExtX, lc->lcSysExtY); g_print ("lcSysSensX = %g, lcSysSensY = %g\n", lc->lcSysSensX / 65536., lc->lcSysSensY / 65536.); } static void print_cursor (int index) { int size; int i; char *name; BOOL active; WTPKT wtpkt; BYTE buttons; BYTE buttonbits; char *btnnames; char *p; BYTE buttonmap[32]; BYTE sysbtnmap[32]; BYTE npbutton; UINT npbtnmarks[2]; UINT *npresponse; BYTE tpbutton; UINT tpbtnmarks[2]; UINT *tpresponse; DWORD physid; UINT mode; UINT minpktdata; UINT minbuttons; UINT capabilities; size = (*p_WTInfoA) (WTI_CURSORS + index, CSR_NAME, NULL); name = g_malloc (size + 1); (*p_WTInfoA) (WTI_CURSORS + index, CSR_NAME, name); g_print ("NAME: %s\n", name); (*p_WTInfoA) (WTI_CURSORS + index, CSR_ACTIVE, &active); g_print ("ACTIVE: %s\n", active ? "YES" : "NO"); (*p_WTInfoA) (WTI_CURSORS + index, CSR_PKTDATA, &wtpkt); g_print ("PKTDATA: %#x:", (guint) wtpkt); #define BIT(x) if (wtpkt & PK_##x) g_print (" " #x) BIT (CONTEXT); BIT (STATUS); BIT (TIME); BIT (CHANGED); BIT (SERIAL_NUMBER); BIT (BUTTONS); BIT (X); BIT (Y); BIT (Z); BIT (NORMAL_PRESSURE); BIT (TANGENT_PRESSURE); BIT (ORIENTATION); BIT (ROTATION); #undef BIT g_print ("\n"); (*p_WTInfoA) (WTI_CURSORS + index, CSR_BUTTONS, &buttons); g_print ("BUTTONS: %d\n", buttons); (*p_WTInfoA) (WTI_CURSORS + index, CSR_BUTTONBITS, &buttonbits); g_print ("BUTTONBITS: %d\n", buttonbits); size = (*p_WTInfoA) (WTI_CURSORS + index, CSR_BTNNAMES, NULL); g_print ("BTNNAMES:"); if (size > 0) { btnnames = g_malloc (size + 1); (*p_WTInfoA) (WTI_CURSORS + index, CSR_BTNNAMES, btnnames); p = btnnames; while (*p) { g_print (" %s", p); p += strlen (p) + 1; } } g_print ("\n"); (*p_WTInfoA) (WTI_CURSORS + index, CSR_BUTTONMAP, buttonmap); g_print ("BUTTONMAP:"); for (i = 0; i < buttons; i++) g_print (" %d", buttonmap[i]); g_print ("\n"); (*p_WTInfoA) (WTI_CURSORS + index, CSR_SYSBTNMAP, sysbtnmap); g_print ("SYSBTNMAP:"); for (i = 0; i < buttons; i++) g_print (" %d", sysbtnmap[i]); g_print ("\n"); (*p_WTInfoA) (WTI_CURSORS + index, CSR_NPBUTTON, &npbutton); g_print ("NPBUTTON: %d\n", npbutton); (*p_WTInfoA) (WTI_CURSORS + index, CSR_NPBTNMARKS, npbtnmarks); g_print ("NPBTNMARKS: %d %d\n", npbtnmarks[0], npbtnmarks[1]); size = (*p_WTInfoA) (WTI_CURSORS + index, CSR_NPRESPONSE, NULL); g_print ("NPRESPONSE:"); if (size > 0) { npresponse = g_malloc (size); (*p_WTInfoA) (WTI_CURSORS + index, CSR_NPRESPONSE, npresponse); for (i = 0; i < size / sizeof (UINT); i++) g_print (" %d", npresponse[i]); } g_print ("\n"); (*p_WTInfoA) (WTI_CURSORS + index, CSR_TPBUTTON, &tpbutton); g_print ("TPBUTTON: %d\n", tpbutton); (*p_WTInfoA) (WTI_CURSORS + index, CSR_TPBTNMARKS, tpbtnmarks); g_print ("TPBTNMARKS: %d %d\n", tpbtnmarks[0], tpbtnmarks[1]); size = (*p_WTInfoA) (WTI_CURSORS + index, CSR_TPRESPONSE, NULL); g_print ("TPRESPONSE:"); if (size > 0) { tpresponse = g_malloc (size); (*p_WTInfoA) (WTI_CURSORS + index, CSR_TPRESPONSE, tpresponse); for (i = 0; i < size / sizeof (UINT); i++) g_print (" %d", tpresponse[i]); } g_print ("\n"); (*p_WTInfoA) (WTI_CURSORS + index, CSR_PHYSID, &physid); g_print ("PHYSID: %#x\n", (guint) physid); (*p_WTInfoA) (WTI_CURSORS + index, CSR_CAPABILITIES, &capabilities); g_print ("CAPABILITIES: %#x:", capabilities); #define BIT(x) if (capabilities & CRC_##x) g_print (" " #x) BIT (MULTIMODE); BIT (AGGREGATE); BIT (INVERT); #undef BIT g_print ("\n"); if (capabilities & CRC_MULTIMODE) { (*p_WTInfoA) (WTI_CURSORS + index, CSR_MODE, &mode); g_print ("MODE: %d\n", mode); } if (capabilities & CRC_AGGREGATE) { (*p_WTInfoA) (WTI_CURSORS + index, CSR_MINPKTDATA, &minpktdata); g_print ("MINPKTDATA: %d\n", minpktdata); (*p_WTInfoA) (WTI_CURSORS + index, CSR_MINBUTTONS, &minbuttons); g_print ("MINBUTTONS: %d\n", minbuttons); } } #endif static void wintab_init_check (GdkDeviceManagerWin32 *device_manager) { GdkDisplay *display = device_manager->display; static gboolean wintab_initialized = FALSE; GdkDeviceWintab *device; WORD specversion; HCTX *hctx; UINT ndevices, ncursors, ncsrtypes, firstcsr, hardware; BOOL active; DWORD physid; AXIS axis_x, axis_y, axis_npressure, axis_or[3]; UINT devix, cursorix; int i, num_axes = 0; wchar_t devname[100], csrname[100]; char *devname_utf8, *csrname_utf8, *device_name; BOOL defcontext_done; HMODULE wintab32; char *wintab32_dll_path; char dummy; int n, k; if (wintab_initialized) return; wintab_initialized = TRUE; wintab_contexts = NULL; if (_gdk_input_ignore_wintab) return; n = GetSystemDirectory (&dummy, 0); if (n <= 0) return; wintab32_dll_path = g_malloc (n + 1 + strlen (WINTAB32_DLL)); k = GetSystemDirectory (wintab32_dll_path, n); if (k == 0 || k > n) { g_free (wintab32_dll_path); return; } if (!G_IS_DIR_SEPARATOR (wintab32_dll_path[strlen (wintab32_dll_path) -1])) strcat (wintab32_dll_path, G_DIR_SEPARATOR_S); strcat (wintab32_dll_path, WINTAB32_DLL); if ((wintab32 = LoadLibrary (wintab32_dll_path)) == NULL) return; if ((p_WTInfoA = (t_WTInfoA) GetProcAddress (wintab32, "WTInfoA")) == NULL) return; if ((p_WTInfoW = (t_WTInfoW) GetProcAddress (wintab32, "WTInfoW")) == NULL) return; if ((p_WTEnable = (t_WTEnable) GetProcAddress (wintab32, "WTEnable")) == NULL) return; if ((p_WTOpenA = (t_WTOpenA) GetProcAddress (wintab32, "WTOpenA")) == NULL) return; if ((p_WTGetA = (t_WTGetA) GetProcAddress (wintab32, "WTGetA")) == NULL) return; if ((p_WTSetA = (t_WTSetA) GetProcAddress (wintab32, "WTSetA")) == NULL) return; if ((p_WTOverlap = (t_WTOverlap) GetProcAddress (wintab32, "WTOverlap")) == NULL) return; if ((p_WTPacket = (t_WTPacket) GetProcAddress (wintab32, "WTPacket")) == NULL) return; if ((p_WTQueueSizeSet = (t_WTQueueSizeSet) GetProcAddress (wintab32, "WTQueueSizeSet")) == NULL) return; if (!(*p_WTInfoA) (0, 0, NULL)) return; (*p_WTInfoA) (WTI_INTERFACE, IFC_SPECVERSION, &specversion); GDK_NOTE (INPUT, g_print ("Wintab interface version %d.%d\n", HIBYTE (specversion), LOBYTE (specversion))); (*p_WTInfoA) (WTI_INTERFACE, IFC_NDEVICES, &ndevices); (*p_WTInfoA) (WTI_INTERFACE, IFC_NCURSORS, &ncursors); #if DEBUG_WINTAB GDK_NOTE (INPUT, g_print ("NDEVICES: %d, NCURSORS: %d\n", ndevices, ncursors)); #endif /* Create a dummy window to receive wintab events */ wintab_window = _gdk_win32_display_create_surface (display, GDK_SURFACE_TEMP, NULL, -100, -100, 2, 2); g_object_ref (wintab_window); for (devix = 0; devix < ndevices; devix++) { LOGCONTEXT lc; /* We open the Wintab device (hmm, what if there are several, or * can there even be several, probably not?) as a system * pointing device, i.e. it controls the normal Windows * cursor. This seems much more natural. */ (*p_WTInfoW) (WTI_DEVICES + devix, DVC_NAME, devname); devname_utf8 = g_utf16_to_utf8 (devname, -1, NULL, NULL, NULL); #ifdef DEBUG_WINTAB GDK_NOTE (INPUT, (g_print("Device %u: %s\n", devix, devname_utf8))); #endif (*p_WTInfoA) (WTI_DEVICES + devix, DVC_NCSRTYPES, &ncsrtypes); (*p_WTInfoA) (WTI_DEVICES + devix, DVC_FIRSTCSR, &firstcsr); (*p_WTInfoA) (WTI_DEVICES + devix, DVC_HARDWARE, &hardware); (*p_WTInfoA) (WTI_DEVICES + devix, DVC_X, &axis_x); (*p_WTInfoA) (WTI_DEVICES + devix, DVC_Y, &axis_y); (*p_WTInfoA) (WTI_DEVICES + devix, DVC_NPRESSURE, &axis_npressure); (*p_WTInfoA) (WTI_DEVICES + devix, DVC_ORIENTATION, axis_or); defcontext_done = FALSE; if (HIBYTE (specversion) > 1 || LOBYTE (specversion) >= 1) { /* Try to get device-specific default context */ /* Some drivers, e.g. Aiptek, don't provide this info */ if ((*p_WTInfoA) (WTI_DSCTXS + devix, 0, &lc) > 0) defcontext_done = TRUE; #if DEBUG_WINTAB if (defcontext_done) GDK_NOTE (INPUT, (g_print("Using device-specific default context\n"))); else GDK_NOTE (INPUT, (g_print("Note: Driver did not provide device specific default context info despite claiming to support version 1.1\n"))); #endif } if (!defcontext_done) (*p_WTInfoA) (WTI_DEFSYSCTX, 0, &lc); #if DEBUG_WINTAB GDK_NOTE (INPUT, (g_print("Default context:\n"), print_lc(&lc))); #endif lc.lcOptions |= CXO_MESSAGES | CXO_CSRMESSAGES; lc.lcStatus = 0; lc.lcMsgBase = WT_DEFBASE; lc.lcPktRate = 0; lc.lcPktData = PACKETDATA; lc.lcPktMode = PACKETMODE; lc.lcMoveMask = PACKETDATA; lc.lcBtnUpMask = lc.lcBtnDnMask = ~0; lc.lcOutOrgX = axis_x.axMin; lc.lcOutOrgY = axis_y.axMin; lc.lcOutExtX = axis_x.axMax - axis_x.axMin + 1; lc.lcOutExtY = axis_y.axMax - axis_y.axMin + 1; lc.lcOutExtY = -lc.lcOutExtY; /* We want Y growing downward */ #if DEBUG_WINTAB GDK_NOTE (INPUT, (g_print("context for device %u:\n", devix), print_lc(&lc))); #endif hctx = g_new (HCTX, 1); if ((*hctx = (*p_WTOpenA) (GDK_SURFACE_HWND (wintab_window), &lc, TRUE)) == NULL) { g_warning ("gdk_input_wintab_init: WTOpen failed"); return; } GDK_NOTE (INPUT, g_print ("opened Wintab device %u %p\n", devix, *hctx)); wintab_contexts = g_list_append (wintab_contexts, hctx); #if 0 (*p_WTEnable) (*hctx, TRUE); #endif (*p_WTOverlap) (*hctx, TRUE); #if DEBUG_WINTAB GDK_NOTE (INPUT, (g_print("context for device %u after WTOpen:\n", devix), print_lc(&lc))); #endif /* Increase packet queue size to reduce the risk of lost packets. * According to the specs, if the function fails we must try again * with a smaller queue size. */ GDK_NOTE (INPUT, g_print("Attempting to increase queue size\n")); for (i = 128; i >= 1; i >>= 1) { if ((*p_WTQueueSizeSet) (*hctx, i)) { GDK_NOTE (INPUT, g_print("Queue size set to %d\n", i)); break; } } if (!i) GDK_NOTE (INPUT, g_print("Whoops, no queue size could be set\n")); for (cursorix = firstcsr; cursorix < firstcsr + ncsrtypes; cursorix++) { #ifdef DEBUG_WINTAB GDK_NOTE (INPUT, (g_print("Cursor %u:\n", cursorix), print_cursor (cursorix))); #endif active = FALSE; (*p_WTInfoA) (WTI_CURSORS + cursorix, CSR_ACTIVE, &active); if (!active) continue; /* Wacom tablets seem to report cursors corresponding to * nonexistent pens or pucks. At least my ArtPad II reports * six cursors: a puck, pressure stylus and eraser stylus, * and then the same three again. I only have a * pressure-sensitive pen. The puck instances, and the * second instances of the styluses report physid zero. So * at least for Wacom, skip cursors with physid zero. */ (*p_WTInfoA) (WTI_CURSORS + cursorix, CSR_PHYSID, &physid); if (wcscmp (devname, L"WACOM Tablet") == 0 && physid == 0) continue; (*p_WTInfoW) (WTI_CURSORS + cursorix, CSR_NAME, csrname); csrname_utf8 = g_utf16_to_utf8 (csrname, -1, NULL, NULL, NULL); device_name = g_strconcat (devname_utf8, " ", csrname_utf8, NULL); device = g_object_new (GDK_TYPE_DEVICE_WINTAB, "name", device_name, "source", GDK_SOURCE_PEN, "has-cursor", lc.lcOptions & CXO_SYSTEM, "display", display, NULL); device->sends_core = lc.lcOptions & CXO_SYSTEM; if (device->sends_core) { _gdk_device_set_associated_device (device_manager->system_pointer, GDK_DEVICE (device)); _gdk_device_add_physical_device (device_manager->core_pointer, GDK_DEVICE (device)); } g_free (csrname_utf8); device->hctx = *hctx; device->cursor = cursorix; (*p_WTInfoA) (WTI_CURSORS + cursorix, CSR_PKTDATA, &device->pktdata); if (device->pktdata & PK_X) { _gdk_device_add_axis (GDK_DEVICE (device), GDK_AXIS_X, axis_x.axMin, axis_x.axMax, axis_x.axResolution / 65535); num_axes++; } if (device->pktdata & PK_Y) { _gdk_device_add_axis (GDK_DEVICE (device), GDK_AXIS_Y, axis_y.axMin, axis_y.axMax, axis_y.axResolution / 65535); num_axes++; } if (device->pktdata & PK_NORMAL_PRESSURE) { _gdk_device_add_axis (GDK_DEVICE (device), GDK_AXIS_PRESSURE, axis_npressure.axMin, axis_npressure.axMax, axis_npressure.axResolution / 65535); num_axes++; } if (device->pktdata & PK_ORIENTATION) { device->orientation_axes[0] = axis_or[0]; device->orientation_axes[1] = axis_or[1]; /* Wintab gives us azimuth and altitude, which * we convert to x and y tilt in the -1000..1000 range */ _gdk_device_add_axis (GDK_DEVICE (device), GDK_AXIS_XTILT, -1000, 1000, 1000); _gdk_device_add_axis (GDK_DEVICE (device), GDK_AXIS_YTILT, -1000, 1000, 1000); num_axes += 2; } device->last_axis_data = g_new (int, num_axes); GDK_NOTE (INPUT, g_print ("device: (%u) %s axes: %d\n", cursorix, device_name, num_axes)); #if 0 for (i = 0; i < gdkdev->info.num_axes; i++) GDK_NOTE (INPUT, g_print ("... axis %d: %d--%d@%d\n", i, gdkdev->axes[i].min_value, gdkdev->axes[i].max_value, gdkdev->axes[i].resolution)); #endif device_manager->wintab_devices = g_list_append (device_manager->wintab_devices, device); g_free (device_name); } g_free (devname_utf8); } } /* Only initialize Wintab after the default display is set for * the first time. WTOpenA() executes code beyond our control, * and it can cause messages to be sent to the application even * before a window is opened. GDK has to be in a fit state to * handle them when they come. * * https://bugzilla.gnome.org/show_bug.cgi?id=774379 */ static void wintab_default_display_notify_cb (GdkDisplayManager *display_manager) { GdkDeviceManagerWin32 *device_manager = NULL; GdkDisplay *display = gdk_display_get_default(); if (default_display_opened) return; g_assert (display != NULL); device_manager = GDK_DEVICE_MANAGER_WIN32 (_gdk_device_manager); g_assert (display_manager != NULL); default_display_opened = TRUE; GDK_NOTE (INPUT, g_print ("wintab init: doing delayed initialization\n")); wintab_init_check (device_manager); } static void gdk_device_manager_win32_constructed (GObject *object) { GdkDeviceManagerWin32 *device_manager; GdkSeat *seat; GdkDisplayManager *display_manager = NULL; GdkDisplay *default_display = NULL; device_manager = GDK_DEVICE_MANAGER_WIN32 (object); device_manager->core_pointer = create_pointer (device_manager, GDK_TYPE_DEVICE_VIRTUAL, "Virtual Core Pointer", TRUE); device_manager->system_pointer = create_pointer (device_manager, GDK_TYPE_DEVICE_WIN32, "System Aggregated Pointer", FALSE); _gdk_device_virtual_set_active (device_manager->core_pointer, device_manager->system_pointer); _gdk_device_set_associated_device (device_manager->system_pointer, device_manager->core_pointer); _gdk_device_add_physical_device (device_manager->core_pointer, device_manager->system_pointer); device_manager->core_keyboard = create_keyboard (device_manager, GDK_TYPE_DEVICE_VIRTUAL, "Virtual Core Keyboard"); device_manager->system_keyboard = create_keyboard (device_manager, GDK_TYPE_DEVICE_WIN32, "System Aggregated Keyboard"); _gdk_device_virtual_set_active (device_manager->core_keyboard, device_manager->system_keyboard); _gdk_device_set_associated_device (device_manager->system_keyboard, device_manager->core_keyboard); _gdk_device_add_physical_device (device_manager->core_keyboard, device_manager->system_keyboard); _gdk_device_set_associated_device (device_manager->core_pointer, device_manager->core_keyboard); _gdk_device_set_associated_device (device_manager->core_keyboard, device_manager->core_pointer); seat = gdk_seat_default_new_for_logical_pair (device_manager->core_pointer, device_manager->core_keyboard); gdk_display_add_seat (_gdk_display, seat); gdk_seat_default_add_physical_device (GDK_SEAT_DEFAULT (seat), device_manager->system_pointer); gdk_seat_default_add_physical_device (GDK_SEAT_DEFAULT (seat), device_manager->system_keyboard); g_object_unref (seat); /* Only call Wintab init stuff after the default display * is globally known and accessible through the display manager * singleton. Approach lifted from gtkmodules.c. */ display_manager = gdk_display_manager_get (); g_assert (display_manager != NULL); default_display = gdk_display_manager_get_default_display (display_manager); g_assert (default_display == NULL); g_signal_connect (display_manager, "notify::default-display", G_CALLBACK (wintab_default_display_notify_cb), NULL); } static void gdk_device_manager_win32_class_init (GdkDeviceManagerWin32Class *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); object_class->finalize = gdk_device_manager_win32_finalize; object_class->constructed = gdk_device_manager_win32_constructed; } void _gdk_input_set_tablet_active (void) { GList *tmp_list; HCTX *hctx; /* Bring the contexts to the top of the overlap order when one of the * application's windows is activated */ if (!wintab_contexts) return; /* No tablet devices found, or Wintab not initialized yet */ GDK_NOTE (INPUT, g_print ("_gdk_input_set_tablet_active: " "Bringing Wintab contexts to the top of the overlap order\n")); tmp_list = wintab_contexts; while (tmp_list) { hctx = (HCTX *) (tmp_list->data); (*p_WTOverlap) (*hctx, TRUE); tmp_list = tmp_list->next; } } static void decode_tilt (int *axis_data, AXIS *axes, PACKET *packet) { double az, el; g_return_if_fail (axis_data != NULL); /* The wintab driver for the Wacom ArtPad II reports * PK_ORIENTATION in CSR_PKTDATA, but the tablet doesn't * actually sense tilt. Catch this by noticing that the * orientation axis's azimuth resolution is zero. * * The same is true of the Huion H610PRO, but in this case * it's the altitude resolution that's zero. GdkEvents with * sensible tilts will need both, so only add the GDK tilt axes * if both wintab axes are going to be well-behaved in use. */ if ((axes == NULL) || (axes[0].axResolution == 0) || (axes[1].axResolution == 0)) { axis_data[0] = 0; axis_data[1] = 0; return; } /* * Tested with a Wacom Intuos 5 touch M (PTH-650) + Wacom drivers 6.3.18-5. * Wintab's reference angle leads gdk's by 90 degrees. */ az = TWOPI * packet->pkOrientation.orAzimuth / (axes[0].axResolution / 65536.); az -= G_PI / 2; el = TWOPI * packet->pkOrientation.orAltitude / (axes[1].axResolution / 65536.); /* X tilt */ axis_data[0] = cos (az) * cos (el) * 1000; /* Y tilt */ axis_data[1] = sin (az) * cos (el) * 1000; } /* * Get the currently active keyboard modifiers (ignoring the mouse buttons) * We could use gdk_surface_get_pointer but that function does a lot of other * expensive things besides getting the modifiers. This code is somewhat based * on build_pointer_event_state from gdkevents-win32.c */ static guint get_modifier_key_state (void) { guint state; state = 0; /* High-order bit is up/down, low order bit is toggled/untoggled */ if (GetKeyState (VK_CONTROL) < 0) state |= GDK_CONTROL_MASK; if (GetKeyState (VK_SHIFT) < 0) state |= GDK_SHIFT_MASK; if (GetKeyState (VK_MENU) < 0) state |= GDK_ALT_MASK; if (GetKeyState (VK_CAPITAL) & 0x1) state |= GDK_LOCK_MASK; return state; } static GdkDeviceWintab * gdk_device_manager_find_wintab_device (GdkDeviceManagerWin32 *device_manager, HCTX hctx, UINT cursor) { GdkDeviceWintab *device; GList *tmp_list; for (tmp_list = device_manager->wintab_devices; tmp_list != NULL; tmp_list = tmp_list->next) { device = tmp_list->data; if (device->hctx == hctx && device->cursor == cursor) return device; } return NULL; } GdkEvent * gdk_input_other_event (GdkDisplay *display, MSG *msg, GdkSurface *window) { GdkDeviceManagerWin32 *device_manager; GdkDeviceWintab *source_device = NULL; GdkDeviceGrabInfo *last_grab; guint key_state; GdkEvent *event; PACKET packet; int num_axes; double x, y; guint translated_buttons, button_diff, button_mask; GdkEventType event_type; int event_button = 0; GdkModifierType event_state; double event_x, event_y; double *axes; /* Translation from tablet button state to GDK button state for * buttons 1-3 - swap button 2 and 3. */ static guint button_map[8] = {0, 1, 4, 5, 2, 3, 6, 7}; if (window != wintab_window) { g_warning ("gdk_input_other_event: not wintab_window?"); return NULL; } device_manager = GDK_DEVICE_MANAGER_WIN32 (_gdk_device_manager); window = gdk_device_get_surface_at_position (device_manager->core_pointer, &x, &y); if (window) g_object_ref (window); GDK_NOTE (EVENTS_OR_INPUT, g_print ("gdk_input_other_event: window=%p %+g%+g\n", window ? GDK_SURFACE_HWND (window) : NULL, x, y)); if (msg->message == WT_PACKET || msg->message == WT_CSRCHANGE) { if (!(*p_WTPacket) ((HCTX) msg->lParam, msg->wParam, &packet)) return NULL; } switch (msg->message) { case WT_PACKET: source_device = gdk_device_manager_find_wintab_device (device_manager, (HCTX) msg->lParam, packet.pkCursor); /* Check this first, as we get WT_PROXIMITY for disabled devices too */ if (device_manager->dev_entered_proximity > 0) { /* This is the same code as in WT_CSRCHANGE. Some drivers send * WT_CSRCHANGE after each WT_PROXIMITY with LOWORD(lParam) != 0, * this code is for those that don't. */ device_manager->dev_entered_proximity -= 1; if (source_device != NULL && source_device->sends_core) { _gdk_device_virtual_set_active (device_manager->core_pointer, GDK_DEVICE (source_device)); _gdk_input_ignore_core += 1; } } else if (source_device != NULL && source_device->sends_core && _gdk_input_ignore_core == 0) { /* A fallback for cases when two devices (disabled and enabled) * were in proximity simultaneously. * In this case the removal of a disabled device would also * make the system pointer active, as we don't know which * device was removed and assume it was the enabled one. * If we are still getting packets for the enabled device, * it means that the device that was removed was the disabled * device, so we must make the enabled device active again and * start ignoring the core pointer events. In practice this means that * removing a disabled device while an enabled device is still * in proximity might briefly make the core pointer active/visible. */ _gdk_device_virtual_set_active (device_manager->core_pointer, GDK_DEVICE (source_device)); _gdk_input_ignore_core += 1; } if (source_device == NULL) return NULL; /* Don't produce any button or motion events while a window is being * moved or resized, see bug #151090. */ if (_modal_operation_in_progress & GDK_WIN32_MODAL_OP_SIZEMOVE_MASK) { GDK_NOTE (EVENTS_OR_INPUT, g_print ("... ignored when moving/sizing\n")); return NULL; } last_grab = _gdk_display_get_last_device_grab (display, GDK_DEVICE (source_device)); if (last_grab && last_grab->surface) { g_object_unref (window); window = g_object_ref (last_grab->surface); } if (window == NULL) { GDK_NOTE (EVENTS_OR_INPUT, g_print ("... is root\n")); return NULL; } num_axes = 0; if (source_device->pktdata & PK_X) source_device->last_axis_data[num_axes++] = packet.pkX; if (source_device->pktdata & PK_Y) source_device->last_axis_data[num_axes++] = packet.pkY; if (source_device->pktdata & PK_NORMAL_PRESSURE) source_device->last_axis_data[num_axes++] = packet.pkNormalPressure; if (source_device->pktdata & PK_ORIENTATION) { decode_tilt (source_device->last_axis_data + num_axes, source_device->orientation_axes, &packet); num_axes += 2; } translated_buttons = button_map[packet.pkButtons & 0x07] | (packet.pkButtons & ~0x07); if (translated_buttons != source_device->button_state) { /* At least one button has changed state so produce a button event * If more than one button has changed state (unlikely), * just care about the first and act on the next the next time * we get a packet */ button_diff = translated_buttons ^ source_device->button_state; /* Gdk buttons are numbered 1.. */ event_button = 1; for (button_mask = 1; button_mask != 0x80000000; button_mask <<= 1, event_button++) { if (button_diff & button_mask) { /* Found a button that has changed state */ break; } } if (!(translated_buttons & button_mask)) { event_type = GDK_BUTTON_RELEASE; } else { event_type = GDK_BUTTON_PRESS; } source_device->button_state ^= button_mask; } else { event_type = GDK_MOTION_NOTIFY; } key_state = get_modifier_key_state (); if (event_type == GDK_BUTTON_PRESS || event_type == GDK_BUTTON_RELEASE) { axes = g_new (double, GDK_AXIS_LAST); _gdk_device_wintab_translate_axes (source_device, window, axes, &event_x, &event_y); event_state = key_state | ((source_device->button_state << 8) & (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | GDK_BUTTON3_MASK | GDK_BUTTON4_MASK | GDK_BUTTON5_MASK)); event = gdk_button_event_new (event_type, window, device_manager->core_pointer, NULL, _gdk_win32_get_next_tick (msg->time), event_state, event_button, event_x, event_y, axes); GDK_NOTE (EVENTS_OR_INPUT, g_print ("WINTAB button %s:%d %g,%g\n", (event->event_type == GDK_BUTTON_PRESS ? "press" : "release"), ((GdkButtonEvent *) event)->button, ((GdkButtonEvent *) event)->x, ((GdkButtonEvent *) event)->y)); } else { axes = g_new (double, GDK_AXIS_LAST); _gdk_device_wintab_translate_axes (source_device, window, axes, &event_x, &event_y); event_state = key_state | ((source_device->button_state << 8) & (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | GDK_BUTTON3_MASK | GDK_BUTTON4_MASK | GDK_BUTTON5_MASK)); event = gdk_motion_event_new (window, device_manager->core_pointer, NULL, _gdk_win32_get_next_tick (msg->time), event_state, event_x, event_y, axes); GDK_NOTE (EVENTS_OR_INPUT, g_print ("WINTAB motion: %g,%g\n", ((GdkMotionEvent *) event)->x, ((GdkMotionEvent *) event)->y)); } return event; case WT_CSRCHANGE: if (device_manager->dev_entered_proximity > 0) device_manager->dev_entered_proximity -= 1; if ((source_device = gdk_device_manager_find_wintab_device (device_manager, (HCTX) msg->lParam, packet.pkCursor)) == NULL) return NULL; if (source_device->sends_core) { _gdk_device_virtual_set_active (device_manager->core_pointer, GDK_DEVICE (source_device)); _gdk_input_ignore_core += 1; } return NULL; case WT_PROXIMITY: if (LOWORD (msg->lParam) == 0) { if (_gdk_input_ignore_core > 0) { _gdk_input_ignore_core -= 1; if (_gdk_input_ignore_core == 0) _gdk_device_virtual_set_active (device_manager->core_pointer, device_manager->system_pointer); } } else { device_manager->dev_entered_proximity += 1; } return NULL; } return NULL; }
b64dfdec513474836272ea651cd0d525d4cda080
06f2e78f4d736c8ac9cb7e98a5abcc28ed4f25b2
/ref/gl/vgl_shim/vgl_shim.c
456b3b2517b38aa6389097850c0186081bc92020
[]
no_license
FWGS/xash3d-fwgs
07a1002396f43754b49521681cc771c0d89051ed
435b95fc5ab3fc5b1a79212ffdc901a47769d056
refs/heads/master
2023-09-01T05:20:48.112400
2023-08-31T05:40:24
2023-08-31T05:40:24
127,814,982
1,078
275
null
2023-09-12T17:49:04
2018-04-02T21:33:02
C
UTF-8
C
false
false
12,585
c
vgl_shim.c
/* vgl_shim.c - vitaGL custom immediate mode shim Copyright (C) 2023 fgsfds This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. */ /* this is a "replacement" for vitaGL's immediate mode tailored specifically for xash this will only provide performance gains if vitaGL is built with DRAW_SPEEDHACK=1 since that makes it assume that all vertex data pointers are GPU-mapped */ #include <stdlib.h> #include <stdio.h> #include <string.h> #include <malloc.h> #include <vitaGL.h> #include "port.h" #include "xash3d_types.h" #include "cvardef.h" #include "const.h" #include "com_model.h" #include "cl_entity.h" #include "render_api.h" #include "protocol.h" #include "dlight.h" #include "ref_api.h" #include "com_strings.h" #include "crtlib.h" #include "vgl_shim.h" #define MAX_SHADERLEN 4096 // increase this when adding more attributes #define MAX_PROGS 32 extern ref_api_t gEngfuncs; enum vgl_attrib_e { VGL_ATTR_POS = 0, // 1 VGL_ATTR_COLOR = 1, // 2 VGL_ATTR_TEXCOORD0 = 2, // 4 VGL_ATTR_TEXCOORD1 = 3, // 8 VGL_ATTR_MAX }; // continuation of previous enum enum vgl_flag_e { VGL_FLAG_ALPHA_TEST = VGL_ATTR_MAX, // 16 VGL_FLAG_FOG, // 32 VGL_FLAG_MAX }; typedef struct { GLuint flags; GLint attridx[VGL_ATTR_MAX]; GLuint glprog; GLint ucolor; GLint ualpha; GLint utex0; GLint utex1; GLint ufog; } vgl_prog_t; static const char *vgl_vert_src = #include "vgl_shaders/vertex.cg.inc" ; static const char *vgl_frag_src = #include "vgl_shaders/fragment.cg.inc" ; static int vgl_init = 0; static struct { GLfloat *attrbuf[VGL_ATTR_MAX]; GLuint cur_flags; GLint begin; GLint end; GLenum prim; GLfloat color[4]; GLfloat fog[4]; // color + density GLfloat alpharef; vgl_prog_t progs[MAX_PROGS]; vgl_prog_t *cur_prog; GLboolean uchanged; } vgl; static const int vgl_attr_size[VGL_ATTR_MAX] = { 3, 4, 2, 2 }; static const char *vgl_flag_name[VGL_FLAG_MAX] = { "ATTR_POSITION", "ATTR_COLOR", "ATTR_TEXCOORD0", "ATTR_TEXCOORD1", "FEAT_ALPHA_TEST", "FEAT_FOG", }; static const char *vgl_attr_name[VGL_ATTR_MAX] = { "inPosition", "inColor", "inTexCoord0", "inTexCoord1", }; // HACK: borrow alpha test and fog flags from internal vitaGL state extern GLboolean alpha_test_state; extern GLboolean fogging; static GLuint VGL_GenerateShader( const vgl_prog_t *prog, GLenum type ) { char *shader, shader_buf[MAX_SHADERLEN + 1]; char tmp[256]; int i; GLint status, len; GLuint id; shader = shader_buf; shader[0] = '\n'; shader[1] = 0; for ( i = 0; i < VGL_FLAG_MAX; ++i ) { Q_snprintf( tmp, sizeof( tmp ), "#define %s %d\n", vgl_flag_name[i], prog->flags & ( 1 << i ) ); Q_strncat( shader, tmp, MAX_SHADERLEN ); } if ( type == GL_FRAGMENT_SHADER ) Q_strncat( shader, vgl_frag_src, MAX_SHADERLEN ); else Q_strncat( shader, vgl_vert_src, MAX_SHADERLEN ); id = glCreateShader( type ); len = Q_strlen( shader ); glShaderSource( id, 1, (const void *)&shader, &len ); glCompileShader( id ); glGetShaderiv( id, GL_COMPILE_STATUS, &status ); if ( status == GL_FALSE ) { gEngfuncs.Con_Reportf( S_ERROR "VGL_GenerateShader( 0x%04x, 0x%x ): compile failed:\n", prog->flags, type ); gEngfuncs.Con_DPrintf( "Shader text:\n%s\n\n", shader ); glDeleteShader( id ); return 0; } return id; } static vgl_prog_t *VGL_GetProg( const GLuint flags ) { int i, loc, status; GLuint vp, fp, glprog; vgl_prog_t *prog; // try to find existing prog matching this feature set if ( vgl.cur_prog && vgl.cur_prog->flags == flags ) return vgl.cur_prog; for ( i = 0; i < MAX_PROGS; ++i ) { if ( vgl.progs[i].flags == flags ) return &vgl.progs[i]; else if ( vgl.progs[i].flags == 0 ) break; } if ( i == MAX_PROGS ) { gEngfuncs.Host_Error( "VGL_GetProg(): Ran out of program slots for 0x%04x\n", flags ); return NULL; } // new prog; generate shaders gEngfuncs.Con_DPrintf( S_NOTE "VGL_GetProg(): Generating progs for 0x%04x\n", flags ); prog = &vgl.progs[i]; prog->flags = flags; vp = VGL_GenerateShader( prog, GL_VERTEX_SHADER ); fp = VGL_GenerateShader( prog, GL_FRAGMENT_SHADER ); if ( !vp || !fp ) { prog->flags = 0; return NULL; } glprog = glCreateProgram(); glAttachShader( glprog, vp ); glAttachShader( glprog, fp ); loc = 0; for ( i = 0; i < VGL_ATTR_MAX; ++i ) { if ( flags & ( 1 << i ) ) { prog->attridx[i] = loc; glBindAttribLocation( glprog, loc++, vgl_attr_name[i] ); } else { prog->attridx[i] = -1; } } glLinkProgram( glprog ); glDeleteShader( vp ); glDeleteShader( fp ); glGetProgramiv( glprog, GL_LINK_STATUS, &status ); if ( status == GL_FALSE ) { gEngfuncs.Con_Reportf( S_ERROR "VGL_GetProg(): Failed linking progs for 0x%04x!\n", prog->flags ); prog->flags = 0; glDeleteProgram( glprog ); return NULL; } prog->ucolor = glGetUniformLocation( glprog, "uColor" ); prog->ualpha = glGetUniformLocation( glprog, "uAlphaTest" ); prog->utex0 = glGetUniformLocation( glprog, "uTex0" ); prog->utex1 = glGetUniformLocation( glprog, "uTex1" ); prog->ufog = glGetUniformLocation( glprog, "uFog" ); // these never change if ( prog->utex0 >= 0 ) glUniform1i( prog->utex0, 0 ); if ( prog->utex1 >= 0 ) glUniform1i( prog->utex1, 1 ); prog->glprog = glprog; gEngfuncs.Con_DPrintf( S_NOTE "VGL_GetProg(): Generated progs for 0x%04x\n", flags ); return prog; } static vgl_prog_t *VGL_SetProg( const GLuint flags ) { vgl_prog_t *prog = NULL; if ( flags && ( prog = VGL_GetProg( flags ) ) ) { if ( prog != vgl.cur_prog ) { glUseProgram( prog->glprog ); vgl.uchanged = GL_TRUE; } if ( vgl.uchanged ) { if ( prog->ualpha >= 0 ) glUniform1f( prog->ualpha, vgl.alpharef ); if ( prog->ucolor >= 0 ) glUniform4fv( prog->ucolor, 1, vgl.color ); if ( prog->ufog >= 0 ) glUniform4fv( prog->ufog, 1, vgl.fog ); vgl.uchanged = GL_FALSE; } } else { glUseProgram( 0 ); } vgl.cur_prog = prog; return prog; } int VGL_ShimInit( void ) { int i; GLuint total, size; static const GLuint precache_progs[] = { 0x0001, // out = ucolor 0x0005, // out = tex0 * ucolor 0x0007, // out = tex0 * vcolor 0x0015, // out = tex0 * ucolor + FEAT_ALPHA_TEST 0x0021, // out = ucolor + FEAT_FOG 0x0025, // out = tex0 * ucolor + FEAT_FOG 0x0027, // out = tex0 * vcolor + FEAT_FOG 0x0035, // out = tex0 * ucolor + FEAT_ALPHA_TEST + FEAT_FOG }; if ( vgl_init ) return 0; memset( &vgl, 0, sizeof( vgl ) ); vgl.color[0] = 1.f; vgl.color[1] = 1.f; vgl.color[2] = 1.f; vgl.color[3] = 1.f; vgl.uchanged = GL_TRUE; total = 0; for ( i = 0; i < VGL_ATTR_MAX; ++i ) { size = VGL_MAX_VERTS * vgl_attr_size[i] * sizeof( GLfloat ); vgl.attrbuf[i] = memalign( 0x100, size ); total += size; } VGL_ShimInstall(); gEngfuncs.Con_DPrintf( S_NOTE "VGL_ShimInit(): %u bytes allocated for vertex buffer\n", total ); gEngfuncs.Con_DPrintf( S_NOTE "VGL_ShimInit(): Pre-generating %u progs...\n", sizeof( precache_progs ) / sizeof( *precache_progs ) ); for ( i = 0; i < (int)( sizeof( precache_progs ) / sizeof( *precache_progs ) ); ++i ) VGL_GetProg( precache_progs[i] ); vgl_init = 1; return 0; } void VGL_ShimShutdown( void ) { int i; if ( !vgl_init ) return; glFinish(); glUseProgram( 0 ); /* // FIXME: this sometimes causes the game to block on glDeleteProgram for up to a minute // but since this is only called on shutdown or game change, it should be fine to skip for ( i = 0; i < MAX_PROGS; ++i ) { if ( vgl.progs[i].flags ) glDeleteProgram( vgl.progs[i].glprog ); } */ for ( i = 0; i < VGL_ATTR_MAX; ++i ) free( vgl.attrbuf[i] ); memset( &vgl, 0, sizeof( vgl ) ); vgl_init = 0; } void VGL_ShimEndFrame( void ) { vgl.end = vgl.begin = 0; } void VGL_Begin( GLenum prim ) { int i; vgl.prim = prim; vgl.begin = vgl.end; // pos always enabled vgl.cur_flags = 1 << VGL_ATTR_POS; // disable all vertex attrib pointers for ( i = 0; i < VGL_ATTR_MAX; ++i ) glDisableVertexAttribArray( i ); } void VGL_End( void ) { int i; vgl_prog_t *prog; GLuint flags = vgl.cur_flags; GLint count = vgl.end - vgl.begin; if ( !vgl.prim || !count ) goto _leave; // end without begin // enable alpha test and fog if needed if ( alpha_test_state ) flags |= 1 << VGL_FLAG_ALPHA_TEST; if ( fogging ) flags |= 1 << VGL_FLAG_FOG; prog = VGL_SetProg( flags ); if ( !prog ) { gEngfuncs.Host_Error( "VGL_End(): Could not find program for flags 0x%04x!\n", flags ); goto _leave; } for ( i = 0; i < VGL_ATTR_MAX; ++i ) { if ( prog->attridx[i] >= 0 ) { glEnableVertexAttribArray( prog->attridx[i] ); glVertexAttribPointer( prog->attridx[i], vgl_attr_size[i], GL_FLOAT, GL_FALSE, 0, vgl.attrbuf[i] + vgl_attr_size[i] * vgl.begin ); } } glDrawArrays( vgl.prim, 0, count ); _leave: vgl.prim = GL_NONE; vgl.begin = vgl.end; vgl.cur_flags = 0; } void VGL_Vertex3f( GLfloat x, GLfloat y, GLfloat z ) { GLfloat *p = vgl.attrbuf[VGL_ATTR_POS] + vgl.end * 3; *p++ = x; *p++ = y; *p++ = z; ++vgl.end; if ( vgl.end >= VGL_MAX_VERTS ) { gEngfuncs.Con_DPrintf( S_ERROR "VGL_Vertex3f(): Vertex buffer overflow!\n" ); vgl.end = vgl.begin = 0; } } void VGL_Vertex2f( GLfloat x, GLfloat y ) { VGL_Vertex3f( x, y, 0.f ); } void VGL_Vertex3fv( const GLfloat *v ) { VGL_Vertex3f( v[0], v[1], v[2] ); } void VGL_Color4f( GLfloat r, GLfloat g, GLfloat b, GLfloat a ) { vgl.color[0] = r; vgl.color[1] = g; vgl.color[2] = b; vgl.color[3] = a; vgl.uchanged = GL_TRUE; if ( vgl.prim ) { // HACK: enable color attribute if we're using color inside a Begin-End pair GLfloat *p = vgl.attrbuf[VGL_ATTR_COLOR] + vgl.end * 4; vgl.cur_flags |= 1 << VGL_ATTR_COLOR; *p++ = r; *p++ = g; *p++ = b; *p++ = a; } } void VGL_Color3f( GLfloat r, GLfloat g, GLfloat b ) { VGL_Color4f( r, g, b, 1.f ); } void VGL_Color4ub( GLubyte r, GLubyte g, GLubyte b, GLubyte a ) { VGL_Color4f( (GLfloat)r / 255.f, (GLfloat)g / 255.f, (GLfloat)b / 255.f, (GLfloat)a / 255.f ); } void VGL_Color4ubv( const GLubyte *v ) { VGL_Color4ub( v[0], v[1], v[2], v[3] ); } void VGL_TexCoord2f( GLfloat u, GLfloat v ) { // by spec glTexCoord always updates texunit 0 GLfloat *p = vgl.attrbuf[VGL_ATTR_TEXCOORD0] + vgl.end * 2; vgl.cur_flags |= 1 << VGL_ATTR_TEXCOORD0; *p++ = u; *p++ = v; } void VGL_MultiTexCoord2f( GLenum tex, GLfloat u, GLfloat v ) { GLfloat *p; // assume there can only be two if ( tex == GL_TEXTURE0 ) { p = vgl.attrbuf[VGL_ATTR_TEXCOORD0] + vgl.end * 2; vgl.cur_flags |= 1 << VGL_ATTR_TEXCOORD0; } else { p = vgl.attrbuf[VGL_ATTR_TEXCOORD1] + vgl.end * 2; vgl.cur_flags |= 1 << VGL_ATTR_TEXCOORD1; } *p++ = u; *p++ = v; } void VGL_Normal3fv( const GLfloat *v ) { /* this does not seem to be necessary */ } void VGL_ShadeModel( GLenum unused ) { /* this doesn't do anything in vitaGL except spit errors in debug mode, so stub it out */ } void VGL_AlphaFunc( GLenum mode, GLfloat ref ) { vgl.alpharef = ref; vgl.uchanged = GL_TRUE; // mode is always GL_GREATER } void VGL_Fogf( GLenum param, GLfloat val ) { if ( param == GL_FOG_DENSITY ) { vgl.fog[3] = val; vgl.uchanged = GL_TRUE; } } void VGL_Fogfv( GLenum param, const GLfloat *val ) { if ( param == GL_FOG_COLOR ) { vgl.fog[0] = val[0]; vgl.fog[1] = val[1]; vgl.fog[2] = val[2]; vgl.uchanged = GL_TRUE; } } void VGL_DrawBuffer( GLenum mode ) { /* unsupported */ } void VGL_Hint( GLenum hint, GLenum val ) { /* none of the used hints are supported; stub to prevent errors */ } #define VGL_OVERRIDE_PTR( name ) \ { \ extern void *pgl ## name; \ pgl ## name = VGL_ ## name; \ } void VGL_ShimInstall( void ) { VGL_OVERRIDE_PTR( Vertex2f ) VGL_OVERRIDE_PTR( Vertex3f ) VGL_OVERRIDE_PTR( Vertex3fv ) VGL_OVERRIDE_PTR( Color3f ) VGL_OVERRIDE_PTR( Color4f ) VGL_OVERRIDE_PTR( Color4ub ) VGL_OVERRIDE_PTR( Color4ubv ) VGL_OVERRIDE_PTR( Normal3fv ) VGL_OVERRIDE_PTR( TexCoord2f ) VGL_OVERRIDE_PTR( MultiTexCoord2f ) VGL_OVERRIDE_PTR( ShadeModel ) VGL_OVERRIDE_PTR( DrawBuffer ) VGL_OVERRIDE_PTR( AlphaFunc ) VGL_OVERRIDE_PTR( Fogf ) VGL_OVERRIDE_PTR( Fogfv ) VGL_OVERRIDE_PTR( Hint ) VGL_OVERRIDE_PTR( Begin ) VGL_OVERRIDE_PTR( End ) }
6a1cf339f9c7ed7cb870e8785b97b5f6a075f2eb
ab63dc8fc5f050b43e3045e5d5848f1fe367c4d4
/examples/stm32/f1/obldc/pwmleds/pwmleds.c
3260f79e47ac30656a1ed995f09caae0fde0e758
[]
no_license
libopencm3/libopencm3-examples
1bfa56b6f7d193e8484b113b2bfa48ab5d2f17e9
15637e291b8ca228e35d5f657ed15f3b8958fa0c
refs/heads/master
2023-08-31T04:16:18.416874
2023-01-16T20:39:31
2023-01-16T20:39:31
9,558,129
467
353
null
2023-07-22T19:45:49
2013-04-20T02:27:12
Makefile
UTF-8
C
false
false
14,258
c
pwmleds.c
/* * This file is part of the libopencm3 project. * * Copyright (C) 2010 Piotr Esden-Tempski <piotr@esden.net> * * This library is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this library. If not, see <http://www.gnu.org/licenses/>. */ #include <libopencm3/stm32/rcc.h> #include <libopencm3/stm32/gpio.h> #include <libopencm3/stm32/timer.h> // #define COMPARE // #define MOVING_FADE #define KITT #ifdef COMPARE #define GAMMA_LINEAR #define GAMMA_1_3 #define GAMMA_2_5 #define GAMMA_3_0 #endif #ifdef MOVING_FADE #define GAMMA_2_2 #define GAMMA_TABLE gamma_table_2_2 #endif #ifdef KITT #define GAMMA_2_5 #define GAMMA_TABLE gamma_table_2_5 #endif /* * Gamma correction table * * The nonlinear tables are calculating with the function: * Iout = Iin ** gamma */ #ifdef GAMMA_LINEAR static const uint16_t gamma_table_linear[] = { 1, 4, 9, 17, 26, 37, 51, 67, 84, 104, 126, 149, 175, 203, 233, 265, 299, 334, 372, 412, 454, 499, 545, 593, 643, 695, 749, 805, 864, 924, 986, 1050, 1116, 1185, 1255, 1327, 1402, 1478, 1556, 1637, 1719, 1803, 1890, 1978, 2068, 2161, 2255, 2352, 2450, 2550, 2653, 2757, 2864, 2972, 3082, 3195, 3309, 3426, 3544, 3664, 3787, 3911, 4038, 4166, 4296, 4429, 4563, 4700, 4838, 4978, 5121, 5265, 5411, 5560, 5710, 5862, 6017, 6173, 6331, 6492, 6654, 6818, 6985, 7153, 7323, 7495, 7670, 7846, 8024, 8204, 8387, 8571, 8757, 8945, 9135, 9327, 9521, 9718, 9916, 10116, 10318, 10522, 10728, 10936, 11146, 11358, 11572, 11788, 12006, 12226, 12448, 12672, 12897, 13125, 13355, 13587, 13821, 14057, 14294, 14534, 14776, 15020, 15265, 15513, 15763, 16014, 16268, 16524, 16781, 17041, 17302, 17566, 17831, 18099, 18368, 18640, 18913, 19189, 19466, 19745, 20027, 20310, 20595, 20883, 21172, 21463, 21756, 22051, 22349, 22648, 22949, 23252, 23557, 23864, 24173, 24484, 24797, 25112, 25429, 25748, 26069, 26391, 26716, 27043, 27372, 27702, 28035, 28370, 28707, 29045, 29386, 29728, 30073, 30419, 30768, 31118, 31471, 31825, 32182, 32540, 32900, 33263, 33627, 33993, 34361, 34731, 35104, 35478, 35854, 36232, 36612, 36994, 37378, 37764, 38152, 38542, 38933, 39327, 39723, 40121, 40521, 40922, 41326, 41732, 42139, 42549, 42960, 43374, 43789, 44207, 44626, 45048, 45471, 45896, 46324, 46753, 47184, 47617, 48052, 48490, 48929, 49370, 49813, 50258, 50705, 51154, 51604, 52057, 52512, 52969, 53428, 53888, 54351, 54816, 55282, 55751, 56222, 56694, 57169, 57645, 58123, 58604, 59086, 59570, 60057, 60545, 61035, 61527, 62021, 62517, 63016, 63516, 64018, 64521, 65027, 65535, }; #endif #ifdef GAMMA_1_3 static const uint16_t gamma_table_1_3[] = { /* Gamma 1.3 */ 0, 49, 120, 203, 296, 395, 501, 612, 728, 848, 973, 1101, 1233, 1368, 1506, 1648, 1792, 1939, 2088, 2241, 2395, 2552, 2711, 2872, 3036, 3201, 3369, 3538, 3709, 3882, 4057, 4234, 4412, 4592, 4774, 4957, 5142, 5329, 5517, 5706, 5897, 6090, 6283, 6479, 6675, 6873, 7072, 7273, 7475, 7678, 7882, 8088, 8294, 8502, 8711, 8922, 9133, 9346, 9559, 9774, 9990, 10207, 10425, 10644, 10864, 11086, 11308, 11531, 11755, 11981, 12207, 12434, 12662, 12891, 13121, 13352, 13584, 13817, 14051, 14285, 14521, 14757, 14994, 15233, 15472, 15712, 15952, 16194, 16436, 16679, 16923, 17168, 17414, 17660, 17908, 18156, 18405, 18654, 18905, 19156, 19408, 19660, 19914, 20168, 20423, 20679, 20935, 21192, 21450, 21708, 21968, 22228, 22488, 22750, 23012, 23275, 23538, 23802, 24067, 24332, 24599, 24865, 25133, 25401, 25670, 25939, 26209, 26480, 26751, 27023, 27296, 27569, 27843, 28118, 28393, 28669, 28945, 29222, 29500, 29778, 30057, 30336, 30616, 30897, 31178, 31460, 31742, 32025, 32308, 32592, 32877, 33162, 33448, 33734, 34021, 34309, 34597, 34885, 35175, 35464, 35754, 36045, 36337, 36628, 36921, 37214, 37507, 37801, 38096, 38391, 38686, 38982, 39279, 39576, 39874, 40172, 40471, 40770, 41070, 41370, 41670, 41972, 42273, 42576, 42878, 43181, 43485, 43789, 44094, 44399, 44705, 45011, 45317, 45625, 45932, 46240, 46549, 46858, 47167, 47477, 47787, 48098, 48409, 48721, 49034, 49346, 49659, 49973, 50287, 50602, 50917, 51232, 51548, 51864, 52181, 52498, 52816, 53134, 53452, 53771, 54091, 54411, 54731, 55052, 55373, 55694, 56016, 56339, 56662, 56985, 57309, 57633, 57957, 58282, 58608, 58933, 59260, 59586, 59913, 60241, 60569, 60897, 61226, 61555, 61884, 62214, 62545, 62875, 63206, 63538, 63870, 64202, 64535, 64868, 65201, 65535, }; #endif #ifdef GAMMA_2_2 static const uint16_t gamma_table_2_2[] = { 0, 0, 2, 4, 7, 11, 17, 24, 32, 42, 53, 65, 79, 94, 111, 129, 148, 169, 192, 216, 242, 270, 299, 330, 362, 396, 432, 469, 508, 549, 591, 635, 681, 729, 779, 830, 883, 938, 995, 1053, 1113, 1175, 1239, 1305, 1373, 1443, 1514, 1587, 1663, 1740, 1819, 1900, 1983, 2068, 2155, 2243, 2334, 2427, 2521, 2618, 2717, 2817, 2920, 3024, 3131, 3240, 3350, 3463, 3578, 3694, 3813, 3934, 4057, 4182, 4309, 4438, 4570, 4703, 4838, 4976, 5115, 5257, 5401, 5547, 5695, 5845, 5998, 6152, 6309, 6468, 6629, 6792, 6957, 7124, 7294, 7466, 7640, 7816, 7994, 8175, 8358, 8543, 8730, 8919, 9111, 9305, 9501, 9699, 9900, 10102, 10307, 10515, 10724, 10936, 11150, 11366, 11585, 11806, 12029, 12254, 12482, 12712, 12944, 13179, 13416, 13655, 13896, 14140, 14386, 14635, 14885, 15138, 15394, 15652, 15912, 16174, 16439, 16706, 16975, 17247, 17521, 17798, 18077, 18358, 18642, 18928, 19216, 19507, 19800, 20095, 20393, 20694, 20996, 21301, 21609, 21919, 22231, 22546, 22863, 23182, 23504, 23829, 24156, 24485, 24817, 25151, 25487, 25826, 26168, 26512, 26858, 27207, 27558, 27912, 28268, 28627, 28988, 29351, 29717, 30086, 30457, 30830, 31206, 31585, 31966, 32349, 32735, 33124, 33514, 33908, 34304, 34702, 35103, 35507, 35913, 36321, 36732, 37146, 37562, 37981, 38402, 38825, 39252, 39680, 40112, 40546, 40982, 41421, 41862, 42306, 42753, 43202, 43654, 44108, 44565, 45025, 45487, 45951, 46418, 46888, 47360, 47835, 48313, 48793, 49275, 49761, 50249, 50739, 51232, 51728, 52226, 52727, 53230, 53736, 54245, 54756, 55270, 55787, 56306, 56828, 57352, 57879, 58409, 58941, 59476, 60014, 60554, 61097, 61642, 62190, 62741, 63295, 63851, 64410, 64971, 65535, }; #endif #ifdef GAMMA_2_5 static const uint16_t gamma_table_2_5[] = { /* gamma = 2.5 */ 0, 0, 0, 1, 2, 4, 6, 8, 11, 15, 20, 25, 31, 38, 46, 55, 65, 75, 87, 99, 113, 128, 143, 160, 178, 197, 218, 239, 262, 286, 311, 338, 366, 395, 425, 457, 491, 526, 562, 599, 639, 679, 722, 765, 811, 857, 906, 956, 1007, 1061, 1116, 1172, 1231, 1291, 1352, 1416, 1481, 1548, 1617, 1688, 1760, 1834, 1910, 1988, 2068, 2150, 2233, 2319, 2407, 2496, 2587, 2681, 2776, 2874, 2973, 3075, 3178, 3284, 3391, 3501, 3613, 3727, 3843, 3961, 4082, 4204, 4329, 4456, 4585, 4716, 4850, 4986, 5124, 5264, 5407, 5552, 5699, 5849, 6001, 6155, 6311, 6470, 6632, 6795, 6962, 7130, 7301, 7475, 7650, 7829, 8009, 8193, 8379, 8567, 8758, 8951, 9147, 9345, 9546, 9750, 9956, 10165, 10376, 10590, 10806, 11025, 11247, 11472, 11699, 11929, 12161, 12397, 12634, 12875, 13119, 13365, 13614, 13865, 14120, 14377, 14637, 14899, 15165, 15433, 15705, 15979, 16256, 16535, 16818, 17104, 17392, 17683, 17978, 18275, 18575, 18878, 19184, 19493, 19805, 20119, 20437, 20758, 21082, 21409, 21739, 22072, 22407, 22746, 23089, 23434, 23782, 24133, 24487, 24845, 25206, 25569, 25936, 26306, 26679, 27055, 27435, 27818, 28203, 28592, 28985, 29380, 29779, 30181, 30586, 30994, 31406, 31820, 32239, 32660, 33085, 33513, 33944, 34379, 34817, 35258, 35702, 36150, 36602, 37056, 37514, 37976, 38441, 38909, 39380, 39856, 40334, 40816, 41301, 41790, 42282, 42778, 43277, 43780, 44286, 44795, 45308, 45825, 46345, 46869, 47396, 47927, 48461, 48999, 49540, 50085, 50634, 51186, 51742, 52301, 52864, 53431, 54001, 54575, 55153, 55734, 56318, 56907, 57499, 58095, 58695, 59298, 59905, 60515, 61130, 61748, 62370, 62995, 63624, 64258, 64894, 65535, }; #endif #ifdef GAMMA_3_0 static const uint16_t gamma_table_3_0[] = { /* gamma = 3.0 */ 0, 0, 0, 0, 0, 0, 1, 1, 2, 3, 4, 5, 7, 9, 11, 13, 16, 19, 23, 27, 32, 37, 42, 48, 55, 62, 69, 78, 87, 96, 107, 118, 130, 142, 155, 169, 184, 200, 217, 234, 253, 272, 293, 314, 337, 360, 385, 410, 437, 465, 494, 524, 556, 588, 622, 658, 694, 732, 771, 812, 854, 897, 942, 988, 1036, 1085, 1136, 1189, 1243, 1298, 1356, 1415, 1475, 1538, 1602, 1667, 1735, 1804, 1876, 1949, 2024, 2100, 2179, 2260, 2343, 2427, 2514, 2603, 2693, 2786, 2881, 2978, 3078, 3179, 3283, 3389, 3497, 3607, 3720, 3835, 3952, 4072, 4194, 4319, 4446, 4575, 4707, 4842, 4979, 5118, 5261, 5405, 5553, 5703, 5856, 6011, 6169, 6330, 6494, 6660, 6830, 7002, 7177, 7355, 7536, 7719, 7906, 8096, 8289, 8484, 8683, 8885, 9090, 9298, 9510, 9724, 9942, 10163, 10387, 10614, 10845, 11079, 11317, 11557, 11802, 12049, 12300, 12555, 12813, 13074, 13339, 13608, 13880, 14156, 14435, 14718, 15005, 15295, 15589, 15887, 16189, 16494, 16803, 17117, 17433, 17754, 18079, 18408, 18740, 19077, 19418, 19762, 20111, 20464, 20821, 21182, 21547, 21917, 22290, 22668, 23050, 23436, 23827, 24222, 24621, 25025, 25433, 25845, 26262, 26683, 27109, 27539, 27974, 28413, 28857, 29306, 29759, 30217, 30680, 31147, 31619, 32095, 32577, 33063, 33554, 34050, 34551, 35056, 35567, 36082, 36602, 37128, 37658, 38194, 38734, 39280, 39830, 40386, 40947, 41513, 42084, 42661, 43243, 43830, 44422, 45019, 45622, 46231, 46844, 47463, 48088, 48718, 49353, 49994, 50641, 51293, 51950, 52614, 53282, 53957, 54637, 55323, 56014, 56712, 57415, 58123, 58838, 59558, 60285, 61017, 61755, 62499, 63249, 64005, 64767, 65535, }; #endif static void clock_setup(void) { rcc_clock_setup_pll(&rcc_hse_configs[RCC_CLOCK_HSE8_72MHZ]); /* Enable TIM3 clock. */ rcc_periph_clock_enable(RCC_TIM3); /* Enable GPIOC, Alternate Function clocks. */ rcc_periph_clock_enable(RCC_GPIOA); rcc_periph_clock_enable(RCC_GPIOB); rcc_periph_clock_enable(RCC_AFIO); } static void gpio_setup(void) { /* * Set GPIO6 and 7 (in GPIO port A) to * 'output alternate function push-pull'. */ gpio_set_mode(GPIOA, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_TIM3_CH1 | GPIO_TIM3_CH2); /* * Set GPIO0 and 1 (in GPIO port B) to * 'output alternate function push-pull'. */ gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO_TIM3_CH3 | GPIO_TIM3_CH4); } static void tim_setup(void) { /* Clock division and mode */ TIM3_CR1 = TIM_CR1_CKD_CK_INT | TIM_CR1_CMS_EDGE; /* Period */ TIM3_ARR = 65535; /* Prescaler */ TIM3_PSC = 0; TIM3_EGR = TIM_EGR_UG; /* ---- */ /* Output compare 1 mode and preload */ TIM3_CCMR1 |= TIM_CCMR1_OC1M_PWM1 | TIM_CCMR1_OC1PE; /* Polarity and state */ TIM3_CCER |= TIM_CCER_CC1P | TIM_CCER_CC1E; //TIM3_CCER |= TIM_CCER_CC1E; /* Capture compare value */ TIM3_CCR1 = 0; /* ---- */ /* Output compare 2 mode and preload */ TIM3_CCMR1 |= TIM_CCMR1_OC2M_PWM1 | TIM_CCMR1_OC2PE; /* Polarity and state */ TIM3_CCER |= TIM_CCER_CC2P | TIM_CCER_CC2E; //TIM3_CCER |= TIM_CCER_CC2E; /* Capture compare value */ TIM3_CCR2 = 0; /* ---- */ /* Output compare 3 mode and preload */ TIM3_CCMR2 |= TIM_CCMR2_OC3M_PWM1 | TIM_CCMR2_OC3PE; /* Polarity and state */ TIM3_CCER |= TIM_CCER_CC3P | TIM_CCER_CC3E; //TIM3_CCER |= TIM_CCER_CC3E; /* Capture compare value */ TIM3_CCR3 = 0; /* ---- */ /* Output compare 4 mode and preload */ TIM3_CCMR2 |= TIM_CCMR2_OC4M_PWM1 | TIM_CCMR2_OC4PE; /* Polarity and state */ TIM3_CCER |= TIM_CCER_CC4P | TIM_CCER_CC4E; //TIM3_CCER |= TIM_CCER_CC4E; /* Capture compare value */ TIM3_CCR4 = 0; /* ---- */ /* ARR reload enable */ TIM3_CR1 |= TIM_CR1_ARPE; /* Counter enable */ TIM3_CR1 |= TIM_CR1_CEN; } int main(void) { int i, j0, j1, j2, j3, d0, d1, d2, d3, j, k, kd; clock_setup(); gpio_setup(); tim_setup(); #ifdef COMPARE j0 = 0; d0 = 1; j1 = 0; d1 = 1; j2 = 0; d2 = 1; j3 = 0; d3 = 1; while (1) { TIM3_CCR1 = gamma_table_linear[j0]; j0 += d0; if (j0 == 255) d0 = -1; if (j0 == 0) d0 = 1; TIM3_CCR2 = gamma_table_1_3[j1]; j1 += d1; if (j1 == 255) d1 = -1; if (j1 == 0) d1 = 1; TIM3_CCR3 = gamma_table_2_5[j2]; j2 += d2; if (j2 == 255) d2 = -1; if (j2 == 0) d2 = 1; TIM3_CCR4 = gamma_table_3_0[j3]; j3 += d3; if (j3 == 255) d3 = -1; if (j3 == 0) d3 = 1; for (i = 0; i < 50000; i++); } #endif #ifdef MOVING_FADE j0 = 0; d0 = 1; j1 = 128; d1 = 1; j2 = 255; d2 = -1; j3 = 128; d3 = -1; while (1) { TIM3_CCR1 = GAMMA_TABLE[j0]; j0 += d0; if (j0 == 255) d0 = -1; if (j0 == 0) d0 = 1; TIM3_CCR2 = GAMMA_TABLE[j1]; j1 += d1; if (j1 == 255) d1 = -1; if (j1 == 0) d1 = 1; TIM3_CCR3 = GAMMA_TABLE[j2]; j2 += d2; if (j2 == 255) d2 = -1; if (j2 == 0) d2 = 1; TIM3_CCR4 = GAMMA_TABLE[j3]; j3 += d3; if (j3 == 255) d3 = -1; if (j3 == 0) d3 = 1; for (i = 0; i < 10000; i++); } #endif #ifdef KITT j0 = 255; d0 = -1; j1 = 20; d1 = -1; j2 = 20; d2 = -1; j3 = 20; d3 = -1; j = 0; k = 0; kd = 1; while (1) { TIM3_CCR1 = GAMMA_TABLE[j0]; j0 += d0; if (j0 == 255) d0 = -1; if (j0 == 19) j0 = 20; TIM3_CCR2 = GAMMA_TABLE[j1]; j1 += d1; if (j1 == 255) d1 = -1; if (j1 == 19) j1 = 20; TIM3_CCR3 = GAMMA_TABLE[j2]; j2 += d2; if (j2 == 255) d2 = -1; if (j2 == 19) j2 = 20; TIM3_CCR4 = GAMMA_TABLE[j3]; j3 += d3; if (j3 == 255) d3 = -1; if (j3 == 19) j3 = 20; for (i = 0; i < 15000; i++) __asm__("nop"); j++; if (j == 100) { j = 0; switch (k += kd) { case 0: j0 = 255; break; case 1: j1 = 255; break; case 2: j2 = 255; break; case 3: j3 = 255; break; } if (k == 3) kd = -1; if (k == 0) kd = 1; } } #endif return 0; }
5aa7dde7979532258a591d93ae5375368fb170fc
25b7cd3e4b750803565c374e59f8179c8aab276d
/h3m/h3mconvert/messages.h
a8fc2ee693e5066a08ebd2fc64e72310eaa492da
[ "MIT" ]
permissive
potmdehex/homm3tools
320ce70e0d22dc597df440ec7c63fde9844f7dbe
6b36d1f92ea67f5ad6d4847aeaf2dfb1766d3cc5
refs/heads/master
2023-08-06T02:56:53.534443
2022-09-19T12:42:50
2022-09-19T12:42:50
40,399,205
141
29
MIT
2019-12-06T12:11:43
2015-08-08T10:15:08
C
UTF-8
C
false
false
207
h
messages.h
#ifndef __MESSAGES_H_DEF__ #define __MESSAGES_H_DEF__ #define WM_CONVERTED_MAP WM_USER + 1 #define WM_FAILED_MAP WM_USER + 2 #define WM_SKIPPED_MAP WM_USER + 3 #define WM_CONVERTED_ALL WM_USER + 4 #endif
8ebfc54b4dd182d1d0184792d87d7741b5585b3c
f367e4b66a1ee42e85830b31df88f63723c36a47
/lib/fluent-otel-proto/proto_c/opentelemetry/proto/common/v1/common.pb-c.h
d13169c2645d3d9c13201608245f7183083bba8e
[ "Apache-2.0" ]
permissive
fluent/fluent-bit
06873e441162b92941024e9a7e9e8fc934150bf7
1a41f49dc2f3ae31a780caa9ffd6137b1d703065
refs/heads/master
2023-09-05T13:44:55.347372
2023-09-05T10:14:33
2023-09-05T10:14:33
29,933,948
4,907
1,565
Apache-2.0
2023-09-14T10:17:02
2015-01-27T20:41:52
C
UTF-8
C
false
true
13,515
h
common.pb-c.h
/* Generated by the protocol buffer compiler. DO NOT EDIT! */ /* Generated from: opentelemetry/proto/common/v1/common.proto */ #ifndef PROTOBUF_C_opentelemetry_2fproto_2fcommon_2fv1_2fcommon_2eproto__INCLUDED #define PROTOBUF_C_opentelemetry_2fproto_2fcommon_2fv1_2fcommon_2eproto__INCLUDED #include <protobuf-c/protobuf-c.h> PROTOBUF_C__BEGIN_DECLS #if PROTOBUF_C_VERSION_NUMBER < 1003000 # error This file was generated by a newer version of protoc-c which is incompatible with your libprotobuf-c headers. Please update your headers. #elif 1004001 < PROTOBUF_C_MIN_COMPILER_VERSION # error This file was generated by an older version of protoc-c which is incompatible with your libprotobuf-c headers. Please regenerate this file with a newer version of protoc-c. #endif typedef struct Opentelemetry__Proto__Common__V1__AnyValue Opentelemetry__Proto__Common__V1__AnyValue; typedef struct Opentelemetry__Proto__Common__V1__ArrayValue Opentelemetry__Proto__Common__V1__ArrayValue; typedef struct Opentelemetry__Proto__Common__V1__KeyValueList Opentelemetry__Proto__Common__V1__KeyValueList; typedef struct Opentelemetry__Proto__Common__V1__KeyValue Opentelemetry__Proto__Common__V1__KeyValue; typedef struct Opentelemetry__Proto__Common__V1__InstrumentationScope Opentelemetry__Proto__Common__V1__InstrumentationScope; /* --- enums --- */ /* --- messages --- */ typedef enum { OPENTELEMETRY__PROTO__COMMON__V1__ANY_VALUE__VALUE__NOT_SET = 0, OPENTELEMETRY__PROTO__COMMON__V1__ANY_VALUE__VALUE_STRING_VALUE = 1, OPENTELEMETRY__PROTO__COMMON__V1__ANY_VALUE__VALUE_BOOL_VALUE = 2, OPENTELEMETRY__PROTO__COMMON__V1__ANY_VALUE__VALUE_INT_VALUE = 3, OPENTELEMETRY__PROTO__COMMON__V1__ANY_VALUE__VALUE_DOUBLE_VALUE = 4, OPENTELEMETRY__PROTO__COMMON__V1__ANY_VALUE__VALUE_ARRAY_VALUE = 5, OPENTELEMETRY__PROTO__COMMON__V1__ANY_VALUE__VALUE_KVLIST_VALUE = 6, OPENTELEMETRY__PROTO__COMMON__V1__ANY_VALUE__VALUE_BYTES_VALUE = 7 PROTOBUF_C__FORCE_ENUM_TO_BE_INT_SIZE(OPENTELEMETRY__PROTO__COMMON__V1__ANY_VALUE__VALUE__CASE) } Opentelemetry__Proto__Common__V1__AnyValue__ValueCase; /* * AnyValue is used to represent any type of attribute value. AnyValue may contain a * primitive value such as a string or integer or it may contain an arbitrary nested * object containing arrays, key-value lists and primitives. */ struct Opentelemetry__Proto__Common__V1__AnyValue { ProtobufCMessage base; Opentelemetry__Proto__Common__V1__AnyValue__ValueCase value_case; union { char *string_value; protobuf_c_boolean bool_value; int64_t int_value; double double_value; Opentelemetry__Proto__Common__V1__ArrayValue *array_value; Opentelemetry__Proto__Common__V1__KeyValueList *kvlist_value; ProtobufCBinaryData bytes_value; }; }; #define OPENTELEMETRY__PROTO__COMMON__V1__ANY_VALUE__INIT \ { PROTOBUF_C_MESSAGE_INIT (&opentelemetry__proto__common__v1__any_value__descriptor) \ , OPENTELEMETRY__PROTO__COMMON__V1__ANY_VALUE__VALUE__NOT_SET, {0} } /* * ArrayValue is a list of AnyValue messages. We need ArrayValue as a message * since oneof in AnyValue does not allow repeated fields. */ struct Opentelemetry__Proto__Common__V1__ArrayValue { ProtobufCMessage base; /* * Array of values. The array may be empty (contain 0 elements). */ size_t n_values; Opentelemetry__Proto__Common__V1__AnyValue **values; }; #define OPENTELEMETRY__PROTO__COMMON__V1__ARRAY_VALUE__INIT \ { PROTOBUF_C_MESSAGE_INIT (&opentelemetry__proto__common__v1__array_value__descriptor) \ , 0,NULL } /* * KeyValueList is a list of KeyValue messages. We need KeyValueList as a message * since `oneof` in AnyValue does not allow repeated fields. Everywhere else where we need * a list of KeyValue messages (e.g. in Span) we use `repeated KeyValue` directly to * avoid unnecessary extra wrapping (which slows down the protocol). The 2 approaches * are semantically equivalent. */ struct Opentelemetry__Proto__Common__V1__KeyValueList { ProtobufCMessage base; /* * A collection of key/value pairs of key-value pairs. The list may be empty (may * contain 0 elements). * The keys MUST be unique (it is not allowed to have more than one * value with the same key). */ size_t n_values; Opentelemetry__Proto__Common__V1__KeyValue **values; }; #define OPENTELEMETRY__PROTO__COMMON__V1__KEY_VALUE_LIST__INIT \ { PROTOBUF_C_MESSAGE_INIT (&opentelemetry__proto__common__v1__key_value_list__descriptor) \ , 0,NULL } /* * KeyValue is a key-value pair that is used to store Span attributes, Link * attributes, etc. */ struct Opentelemetry__Proto__Common__V1__KeyValue { ProtobufCMessage base; char *key; Opentelemetry__Proto__Common__V1__AnyValue *value; }; #define OPENTELEMETRY__PROTO__COMMON__V1__KEY_VALUE__INIT \ { PROTOBUF_C_MESSAGE_INIT (&opentelemetry__proto__common__v1__key_value__descriptor) \ , (char *)protobuf_c_empty_string, NULL } /* * InstrumentationScope is a message representing the instrumentation scope information * such as the fully qualified name and version. */ struct Opentelemetry__Proto__Common__V1__InstrumentationScope { ProtobufCMessage base; /* * An empty instrumentation scope name means the name is unknown. */ char *name; char *version; size_t n_attributes; Opentelemetry__Proto__Common__V1__KeyValue **attributes; uint32_t dropped_attributes_count; }; #define OPENTELEMETRY__PROTO__COMMON__V1__INSTRUMENTATION_SCOPE__INIT \ { PROTOBUF_C_MESSAGE_INIT (&opentelemetry__proto__common__v1__instrumentation_scope__descriptor) \ , (char *)protobuf_c_empty_string, (char *)protobuf_c_empty_string, 0,NULL, 0 } /* Opentelemetry__Proto__Common__V1__AnyValue methods */ void opentelemetry__proto__common__v1__any_value__init (Opentelemetry__Proto__Common__V1__AnyValue *message); size_t opentelemetry__proto__common__v1__any_value__get_packed_size (const Opentelemetry__Proto__Common__V1__AnyValue *message); size_t opentelemetry__proto__common__v1__any_value__pack (const Opentelemetry__Proto__Common__V1__AnyValue *message, uint8_t *out); size_t opentelemetry__proto__common__v1__any_value__pack_to_buffer (const Opentelemetry__Proto__Common__V1__AnyValue *message, ProtobufCBuffer *buffer); Opentelemetry__Proto__Common__V1__AnyValue * opentelemetry__proto__common__v1__any_value__unpack (ProtobufCAllocator *allocator, size_t len, const uint8_t *data); void opentelemetry__proto__common__v1__any_value__free_unpacked (Opentelemetry__Proto__Common__V1__AnyValue *message, ProtobufCAllocator *allocator); /* Opentelemetry__Proto__Common__V1__ArrayValue methods */ void opentelemetry__proto__common__v1__array_value__init (Opentelemetry__Proto__Common__V1__ArrayValue *message); size_t opentelemetry__proto__common__v1__array_value__get_packed_size (const Opentelemetry__Proto__Common__V1__ArrayValue *message); size_t opentelemetry__proto__common__v1__array_value__pack (const Opentelemetry__Proto__Common__V1__ArrayValue *message, uint8_t *out); size_t opentelemetry__proto__common__v1__array_value__pack_to_buffer (const Opentelemetry__Proto__Common__V1__ArrayValue *message, ProtobufCBuffer *buffer); Opentelemetry__Proto__Common__V1__ArrayValue * opentelemetry__proto__common__v1__array_value__unpack (ProtobufCAllocator *allocator, size_t len, const uint8_t *data); void opentelemetry__proto__common__v1__array_value__free_unpacked (Opentelemetry__Proto__Common__V1__ArrayValue *message, ProtobufCAllocator *allocator); /* Opentelemetry__Proto__Common__V1__KeyValueList methods */ void opentelemetry__proto__common__v1__key_value_list__init (Opentelemetry__Proto__Common__V1__KeyValueList *message); size_t opentelemetry__proto__common__v1__key_value_list__get_packed_size (const Opentelemetry__Proto__Common__V1__KeyValueList *message); size_t opentelemetry__proto__common__v1__key_value_list__pack (const Opentelemetry__Proto__Common__V1__KeyValueList *message, uint8_t *out); size_t opentelemetry__proto__common__v1__key_value_list__pack_to_buffer (const Opentelemetry__Proto__Common__V1__KeyValueList *message, ProtobufCBuffer *buffer); Opentelemetry__Proto__Common__V1__KeyValueList * opentelemetry__proto__common__v1__key_value_list__unpack (ProtobufCAllocator *allocator, size_t len, const uint8_t *data); void opentelemetry__proto__common__v1__key_value_list__free_unpacked (Opentelemetry__Proto__Common__V1__KeyValueList *message, ProtobufCAllocator *allocator); /* Opentelemetry__Proto__Common__V1__KeyValue methods */ void opentelemetry__proto__common__v1__key_value__init (Opentelemetry__Proto__Common__V1__KeyValue *message); size_t opentelemetry__proto__common__v1__key_value__get_packed_size (const Opentelemetry__Proto__Common__V1__KeyValue *message); size_t opentelemetry__proto__common__v1__key_value__pack (const Opentelemetry__Proto__Common__V1__KeyValue *message, uint8_t *out); size_t opentelemetry__proto__common__v1__key_value__pack_to_buffer (const Opentelemetry__Proto__Common__V1__KeyValue *message, ProtobufCBuffer *buffer); Opentelemetry__Proto__Common__V1__KeyValue * opentelemetry__proto__common__v1__key_value__unpack (ProtobufCAllocator *allocator, size_t len, const uint8_t *data); void opentelemetry__proto__common__v1__key_value__free_unpacked (Opentelemetry__Proto__Common__V1__KeyValue *message, ProtobufCAllocator *allocator); /* Opentelemetry__Proto__Common__V1__InstrumentationScope methods */ void opentelemetry__proto__common__v1__instrumentation_scope__init (Opentelemetry__Proto__Common__V1__InstrumentationScope *message); size_t opentelemetry__proto__common__v1__instrumentation_scope__get_packed_size (const Opentelemetry__Proto__Common__V1__InstrumentationScope *message); size_t opentelemetry__proto__common__v1__instrumentation_scope__pack (const Opentelemetry__Proto__Common__V1__InstrumentationScope *message, uint8_t *out); size_t opentelemetry__proto__common__v1__instrumentation_scope__pack_to_buffer (const Opentelemetry__Proto__Common__V1__InstrumentationScope *message, ProtobufCBuffer *buffer); Opentelemetry__Proto__Common__V1__InstrumentationScope * opentelemetry__proto__common__v1__instrumentation_scope__unpack (ProtobufCAllocator *allocator, size_t len, const uint8_t *data); void opentelemetry__proto__common__v1__instrumentation_scope__free_unpacked (Opentelemetry__Proto__Common__V1__InstrumentationScope *message, ProtobufCAllocator *allocator); /* --- per-message closures --- */ typedef void (*Opentelemetry__Proto__Common__V1__AnyValue_Closure) (const Opentelemetry__Proto__Common__V1__AnyValue *message, void *closure_data); typedef void (*Opentelemetry__Proto__Common__V1__ArrayValue_Closure) (const Opentelemetry__Proto__Common__V1__ArrayValue *message, void *closure_data); typedef void (*Opentelemetry__Proto__Common__V1__KeyValueList_Closure) (const Opentelemetry__Proto__Common__V1__KeyValueList *message, void *closure_data); typedef void (*Opentelemetry__Proto__Common__V1__KeyValue_Closure) (const Opentelemetry__Proto__Common__V1__KeyValue *message, void *closure_data); typedef void (*Opentelemetry__Proto__Common__V1__InstrumentationScope_Closure) (const Opentelemetry__Proto__Common__V1__InstrumentationScope *message, void *closure_data); /* --- services --- */ /* --- descriptors --- */ extern const ProtobufCMessageDescriptor opentelemetry__proto__common__v1__any_value__descriptor; extern const ProtobufCMessageDescriptor opentelemetry__proto__common__v1__array_value__descriptor; extern const ProtobufCMessageDescriptor opentelemetry__proto__common__v1__key_value_list__descriptor; extern const ProtobufCMessageDescriptor opentelemetry__proto__common__v1__key_value__descriptor; extern const ProtobufCMessageDescriptor opentelemetry__proto__common__v1__instrumentation_scope__descriptor; PROTOBUF_C__END_DECLS #endif /* PROTOBUF_C_opentelemetry_2fproto_2fcommon_2fv1_2fcommon_2eproto__INCLUDED */
4bf7db813ad5070343701a90b815c883997aa679
106589e0030bde6ca790a3e825667e1e8ef168f9
/lib/eckey.c
198796543f1ad9996cf9e9dc276aec1c383cc4a5
[ "GPL-1.0-or-later", "BSD-3-Clause", "GPL-2.0-only", "BSD-2-Clause", "MIT" ]
permissive
microsoft/SymCrypt
bc97272fd79b5ed5fbd1b67bbf75dbddea8d6f72
4d3fd5136855648d2a5e987f3b95473b056876b1
refs/heads/main
2023-08-20T23:31:36.248359
2023-01-18T01:59:02
2023-01-18T01:59:02
175,901,565
258
49
MIT
2023-07-21T16:52:30
2019-03-15T22:57:01
C
UTF-8
C
false
false
33,401
c
eckey.c
// // eckey.c Functions for the ECKEY object // // Copyright (c) Microsoft Corporation. Licensed under the MIT license. // // #include "precomp.h" PSYMCRYPT_ECKEY SYMCRYPT_CALL SymCryptEckeyAllocate( _In_ PCSYMCRYPT_ECURVE pCurve ) { PVOID p; SIZE_T cb; PSYMCRYPT_ECKEY res = NULL; cb = SymCryptSizeofEckeyFromCurve( pCurve ); p = SymCryptCallbackAlloc( cb ); if ( p==NULL ) { goto cleanup; } res = SymCryptEckeyCreate( p, cb, pCurve ); cleanup: return res; } VOID SYMCRYPT_CALL SymCryptEckeyFree( _Out_ PSYMCRYPT_ECKEY pkObj ) { SYMCRYPT_CHECK_MAGIC( pkObj ); SymCryptEckeyWipe( pkObj ); SymCryptCallbackFree( pkObj ); } UINT32 SYMCRYPT_CALL SymCryptSizeofEckeyFromCurve( _In_ PCSYMCRYPT_ECURVE pCurve ) { // // From symcrypt_internal.h we have: // - sizeof results are upper bounded by 2^19 // - SYMCRYPT_SCRATCH_BYTES results are upper bounded by 2^27 (including RSA and ECURVE) // - SymCryptSizeofEcpointFromCurve outputs the size of up to 4 modelements + some overhead // Thus the following calculation does not overflow the result. // return sizeof(SYMCRYPT_ECKEY) + SymCryptSizeofEcpointFromCurve( pCurve ) + SymCryptSizeofIntFromDigits(SymCryptEcurveDigitsofScalarMultiplier(pCurve)); } PSYMCRYPT_ECKEY SYMCRYPT_CALL SymCryptEckeyCreate( _Out_writes_bytes_( cbBuffer ) PBYTE pbBuffer, SIZE_T cbBuffer, PCSYMCRYPT_ECURVE pCurve ) { PSYMCRYPT_ECKEY pkObj = NULL; UINT32 privateKeyDigits = SymCryptEcurveDigitsofScalarMultiplier(pCurve); SIZE_T cbPublicKey = SymCryptSizeofEcpointFromCurve( pCurve ); SIZE_T cbPrivateKey = SymCryptSizeofIntFromDigits( privateKeyDigits ); UNREFERENCED_PARAMETER( cbBuffer ); // only referenced in ASSERTs... SYMCRYPT_ASSERT( pCurve != NULL ); SYMCRYPT_ASSERT( cbBuffer >= SymCryptSizeofEckeyFromCurve( pCurve ) ); SYMCRYPT_ASSERT( cbBuffer >= sizeof(SYMCRYPT_ECKEY) + cbPublicKey + cbPrivateKey ); SYMCRYPT_ASSERT_ASYM_ALIGNED( pbBuffer ); pkObj = (PSYMCRYPT_ECKEY) pbBuffer; pkObj->fAlgorithmInfo = 0; pkObj->hasPrivateKey = FALSE; pkObj->pCurve = pCurve; pkObj->poPublicKey = SymCryptEcpointCreate( pbBuffer + sizeof(SYMCRYPT_ECKEY), cbPublicKey, pCurve ); SYMCRYPT_ASSERT( pkObj->poPublicKey != NULL ); pkObj->piPrivateKey = SymCryptIntCreate( pbBuffer + sizeof(SYMCRYPT_ECKEY) + cbPublicKey, cbPrivateKey, privateKeyDigits ); SYMCRYPT_ASSERT( pkObj->piPrivateKey ); // Setting the magic SYMCRYPT_SET_MAGIC( pkObj ); return pkObj; } VOID SYMCRYPT_CALL SymCryptEckeyWipe( _Out_ PSYMCRYPT_ECKEY pkDst ) { // Wipe the whole structure in one go. SymCryptWipe( pkDst, SymCryptSizeofEckeyFromCurve( pkDst->pCurve ) ); } VOID SymCryptEckeyCopy( _In_ PCSYMCRYPT_ECKEY pkSrc, _Out_ PSYMCRYPT_ECKEY pkDst ) { // // in-place copy is somewhat common... // if( pkSrc != pkDst ) { // Copy the fAlgorithmInfo flags pkDst->fAlgorithmInfo = pkSrc->fAlgorithmInfo; // Copy the hasPrivateKey flag pkDst->hasPrivateKey = pkSrc->hasPrivateKey; // Copy the public key SymCryptEcpointCopy( pkSrc->pCurve, pkSrc->poPublicKey, pkDst->poPublicKey ); // Copy the private key SymCryptIntCopy( pkSrc->piPrivateKey, pkDst->piPrivateKey ); } } UINT32 SYMCRYPT_CALL SymCryptEckeySizeofPublicKey( _In_ PCSYMCRYPT_ECKEY pkEckey, _In_ SYMCRYPT_ECPOINT_FORMAT ecPointFormat ) { // // From symcrypt_internal.h we have: // - sizeof results are upper bounded by 2^19 // - SYMCRYPT_SCRATCH_BYTES results are upper bounded by 2^27 (including RSA and ECURVE) // - SymCryptEcpointFormatNumberofElements returns up to 4 elements. // // Thus the following calculation does not overflow cbScratch. // return SymCryptEcpointFormatNumberofElements[ecPointFormat] * SymCryptEcurveSizeofFieldElement( pkEckey->pCurve ); } UINT32 SYMCRYPT_CALL SymCryptEckeySizeofPrivateKey( _In_ PCSYMCRYPT_ECKEY pkEckey ) { return SymCryptEcurveSizeofScalarMultiplier( pkEckey->pCurve ); } BOOLEAN SYMCRYPT_CALL SymCryptEckeyHasPrivateKey( _In_ PCSYMCRYPT_ECKEY pkEckey ) { return pkEckey->hasPrivateKey; } #define SYMCRYPT_FLAG_ECKEY_PUBLIC_KEY_ORDER_VALIDATION (0x1) SYMCRYPT_ERROR SYMCRYPT_CALL SymCryptEckeyPerformPublicKeyValidation( _In_ PCSYMCRYPT_ECKEY pEckey, _In_ UINT32 flags, _Out_writes_bytes_( cbScratch ) PBYTE pbScratch, SIZE_T cbScratch ) { SYMCRYPT_ERROR scError = SYMCRYPT_NO_ERROR; PCSYMCRYPT_ECURVE pCurve = pEckey->pCurve; PSYMCRYPT_ECPOINT poNPub = NULL; UINT32 cbNPub = SymCryptSizeofEcpointFromCurve( pCurve ); // This is an excessive amount of space to require, but all callers can currently provide it, and it's easy to phrase SYMCRYPT_ASSERT( cbScratch >= SYMCRYPT_INTERNAL_SCRATCH_BYTES_FOR_ECKEY_ECURVE_OPERATIONS( pCurve ) ); SYMCRYPT_ASSERT( cbScratch >= cbNPub ); // Check if Public key is O if ( SymCryptEcpointIsZero( pCurve, pEckey->poPublicKey, pbScratch, cbScratch ) ) { return SYMCRYPT_INVALID_ARGUMENT; } // Public key is represented by Modelements of the underlying finite field for the curve // If we have reached this point we have either: // Constructed the Public key to have coordinates in the field (Generate case), or // Verified the Public key has coordinates in the field (SetValue case) // Check that Public key is on the curve // Skip check for Montgomery curves as we do not have an EcpointOnCurve function for them if ( pCurve->type != SYMCRYPT_ECURVE_TYPE_MONTGOMERY && !SymCryptEcpointOnCurve( pCurve, pEckey->poPublicKey, pbScratch, cbScratch ) ) { return SYMCRYPT_INVALID_ARGUMENT; } // Perform validation that Public key is in a subgroup of order GOrd. if ( (flags & SYMCRYPT_FLAG_ECKEY_PUBLIC_KEY_ORDER_VALIDATION) != 0 ) { if ( SymCryptIntIsEqualUint32( pCurve->H, 1 ) ) { // If cofactor is 1 then to validate that Public key has order GOrd // it is sufficient to validate Public key is on the curve // We just performed this check - so we are done. } else { // Ensure GOrd*(Public key) == O poNPub = SymCryptEcpointCreate( pbScratch, cbNPub, pCurve ); pbScratch += cbNPub; cbScratch -= cbNPub; SYMCRYPT_ASSERT( poNPub != NULL ); // Do the multiplication scError = SymCryptEcpointScalarMul( pCurve, SymCryptIntFromModulus( pCurve->GOrd ), pEckey->poPublicKey, 0, // Do not multiply by cofactor! poNPub, pbScratch, cbScratch ); if ( scError != SYMCRYPT_NO_ERROR ) { return scError; } if ( !SymCryptEcpointIsZero( pCurve, poNPub, pbScratch, cbScratch ) ) { return SYMCRYPT_INVALID_ARGUMENT; } } } return SYMCRYPT_NO_ERROR; } SYMCRYPT_ERROR SYMCRYPT_CALL SymCryptEckeySetValue( _In_reads_bytes_( cbPrivateKey ) PCBYTE pbPrivateKey, SIZE_T cbPrivateKey, _In_reads_bytes_( cbPublicKey ) PCBYTE pbPublicKey, SIZE_T cbPublicKey, SYMCRYPT_NUMBER_FORMAT numFormat, SYMCRYPT_ECPOINT_FORMAT ecPointFormat, UINT32 flags, _Inout_ PSYMCRYPT_ECKEY pEckey ) { SYMCRYPT_ERROR scError = SYMCRYPT_NO_ERROR; PBYTE pbScratch = NULL; UINT32 cbScratch = 0; PBYTE pbScratchInternal = NULL; UINT32 cbScratchInternal = 0; PCSYMCRYPT_ECURVE pCurve = pEckey->pCurve; PSYMCRYPT_ECPOINT poTmp = NULL; UINT32 cbTmp = 0; PSYMCRYPT_INT piTmpInteger = NULL; UINT32 cbTmpInteger = 0; PSYMCRYPT_MODELEMENT peTmpModElement = NULL; UINT32 cbTmpModElement = pCurve->cbModElement; UINT32 privateKeyDigits = SymCryptEcurveDigitsofScalarMultiplier(pCurve); UINT32 fValidatePublicKeyOrder = SYMCRYPT_FLAG_ECKEY_PUBLIC_KEY_ORDER_VALIDATION; SYMCRYPT_ASSERT( (cbPrivateKey==0) || (cbPrivateKey == SymCryptEcurveSizeofScalarMultiplier( pEckey->pCurve )) ); SYMCRYPT_ASSERT( (cbPublicKey==0) || (cbPublicKey == SymCryptEckeySizeofPublicKey( pEckey, ecPointFormat)) ); // Ensure caller has specified what algorithm(s) the key will be used with UINT32 algorithmFlags = SYMCRYPT_FLAG_ECKEY_ECDSA | SYMCRYPT_FLAG_ECKEY_ECDH; // Make sure only allowed flags are specified UINT32 allowedFlags = SYMCRYPT_FLAG_KEY_NO_FIPS | SYMCRYPT_FLAG_KEY_MINIMAL_VALIDATION | algorithmFlags; if ( ( ( flags & ~allowedFlags ) != 0 ) || ( ( flags & algorithmFlags ) == 0 ) ) { scError = SYMCRYPT_INVALID_ARGUMENT; goto cleanup; } // Check that minimal validation flag only specified with no fips if ( ( ( flags & SYMCRYPT_FLAG_KEY_NO_FIPS ) == 0 ) && ( ( flags & SYMCRYPT_FLAG_KEY_MINIMAL_VALIDATION ) != 0 ) ) { scError = SYMCRYPT_INVALID_ARGUMENT; goto cleanup; } if ( ( flags & SYMCRYPT_FLAG_KEY_NO_FIPS ) != 0 ) { fValidatePublicKeyOrder = 0; } if ( ( ( cbPrivateKey == 0 ) && ( cbPublicKey == 0 ) ) || ( ( cbPrivateKey != 0 ) && ( cbPrivateKey != SymCryptEcurveSizeofScalarMultiplier( pEckey->pCurve ) ) ) || ( ( cbPublicKey != 0 ) && ( cbPublicKey != SymCryptEckeySizeofPublicKey( pEckey, ecPointFormat ) ) ) ) { scError = SYMCRYPT_INVALID_ARGUMENT; goto cleanup; } // Allocate scratch space cbScratch = SYMCRYPT_INTERNAL_SCRATCH_BYTES_FOR_ECKEY_ECURVE_OPERATIONS( pCurve ); pbScratch = SymCryptCallbackAlloc( cbScratch ); if ( pbScratch == NULL ) { scError = SYMCRYPT_MEMORY_ALLOCATION_FAILURE; goto cleanup; } if ( pbPrivateKey != NULL ) { // // Private key calculations // pbScratchInternal = pbScratch; cbScratchInternal = cbScratch; // Allocate the integer cbTmpInteger = SymCryptSizeofIntFromDigits( privateKeyDigits ); piTmpInteger = SymCryptIntCreate( pbScratchInternal, cbTmpInteger, privateKeyDigits ); SYMCRYPT_ASSERT( piTmpInteger != NULL ); pbScratchInternal += cbTmpInteger; cbScratchInternal -= cbTmpInteger; // Allocate the modelement peTmpModElement = SymCryptModElementCreate( pbScratchInternal, cbTmpModElement, pCurve->GOrd ); SYMCRYPT_ASSERT( peTmpModElement != NULL ); pbScratchInternal += cbTmpModElement; cbScratchInternal -= cbTmpModElement; // Get the "raw" private key scError = SymCryptIntSetValue( pbPrivateKey, cbPrivateKey, numFormat, piTmpInteger ); if (scError != SYMCRYPT_NO_ERROR) { goto cleanup; } // Validation steps if ( ( flags & SYMCRYPT_FLAG_KEY_MINIMAL_VALIDATION ) == 0 ) { // Perform range validation on imported Private key if it is in canonical format if ( pCurve->PrivateKeyDefaultFormat == SYMCRYPT_ECKEY_PRIVATE_FORMAT_CANONICAL ) { // Check if Private key is greater than or equal to GOrd if ( !SymCryptIntIsLessThan( piTmpInteger, SymCryptIntFromModulus( pCurve->GOrd ) ) ) { scError = SYMCRYPT_INVALID_ARGUMENT; goto cleanup; } } // "TimesH" formats // IntGetBits requirements: // We know that coFactorPower is up to SYMCRYPT_ECURVE_MAX_COFACTOR_POWER. Thus // less than 32 and less than the digits size in bits. if ( (pCurve->coFactorPower>0) && (pCurve->PrivateKeyDefaultFormat == SYMCRYPT_ECKEY_PRIVATE_FORMAT_DIVH_TIMESH) && (SymCryptIntGetBits( piTmpInteger, 0, pCurve->coFactorPower) != 0) ) { scError = SYMCRYPT_INVALID_ARGUMENT; goto cleanup; } // High bit restrictions // IntGetBits requirements: // Satisfied by asserting that // HighBitRestrictionPosition + HighBitRestrictionNumOfBits <= GOrdBitsize + coFactorPower // during EcurveAllocate. if ( (pCurve->HighBitRestrictionNumOfBits>0) && (SymCryptIntGetBits( piTmpInteger, pCurve->HighBitRestrictionPosition, pCurve->HighBitRestrictionNumOfBits) != pCurve->HighBitRestrictionValue) ) { scError = SYMCRYPT_INVALID_ARGUMENT; goto cleanup; } } // Convert the private key to "DivH" format if (pCurve->coFactorPower>0) { // "TimesH" format: Divide the input private key with the cofactor // by shifting right the appropriate number of bits if (pCurve->PrivateKeyDefaultFormat == SYMCRYPT_ECKEY_PRIVATE_FORMAT_DIVH_TIMESH) { SymCryptIntDivPow2( piTmpInteger, pCurve->coFactorPower, piTmpInteger ); } // "Canonical" format: Divide by h modulo GOrd if (pCurve->PrivateKeyDefaultFormat == SYMCRYPT_ECKEY_PRIVATE_FORMAT_CANONICAL) { SymCryptIntToModElement( piTmpInteger, pCurve->GOrd, peTmpModElement, pbScratchInternal, cbScratchInternal ); SymCryptModDivPow2( pCurve->GOrd, peTmpModElement, pCurve->coFactorPower, peTmpModElement, pbScratchInternal, cbScratchInternal ); SymCryptModElementToInt( pCurve->GOrd, peTmpModElement, piTmpInteger, pbScratchInternal, cbScratchInternal ); } } // Divide the input private key since it could be larger than subgroup order SymCryptIntDivMod( piTmpInteger, SymCryptDivisorFromModulus(pCurve->GOrd), NULL, piTmpInteger, pbScratchInternal, cbScratchInternal ); if ( ( flags & SYMCRYPT_FLAG_KEY_MINIMAL_VALIDATION ) == 0 ) { // Check if Private key is 0 after dividing it by the subgroup order // Other part of range validation if (SymCryptIntIsEqualUint32( piTmpInteger, 0 )) { scError = SYMCRYPT_INVALID_ARGUMENT; goto cleanup; } } // Copy into the ECKEY SymCryptIntCopy( piTmpInteger, pEckey->piPrivateKey ); pEckey->hasPrivateKey = TRUE; } if ( pbPublicKey != NULL ) { scError = SymCryptEcpointSetValue( pCurve, pbPublicKey, cbPublicKey, numFormat, ecPointFormat, pEckey->poPublicKey, SYMCRYPT_FLAG_DATA_PUBLIC, pbScratch, cbScratch ); if ( scError != SYMCRYPT_NO_ERROR ) { goto cleanup; } // Perform Public key validation on imported Public key. if ( ( flags & SYMCRYPT_FLAG_KEY_MINIMAL_VALIDATION ) == 0 ) { scError = SymCryptEckeyPerformPublicKeyValidation( pEckey, fValidatePublicKeyOrder, pbScratch, cbScratch ); if ( scError != SYMCRYPT_NO_ERROR ) { goto cleanup; } } } // Calculating the public key if no key was provided // or if needed for keypair regeneration validation if ( (pbPublicKey==NULL) || ( ( ( flags & SYMCRYPT_FLAG_KEY_NO_FIPS ) == 0 ) && (pbPrivateKey!=NULL) && (pbPublicKey!=NULL) ) ) { // Calculate the public key from the private key pbScratchInternal = pbScratch; cbScratchInternal = cbScratch; // By default calculate the Public key directly where it will be persisted poTmp = pEckey->poPublicKey; if ( pbPublicKey != NULL ) { // If doing regeneration validation calculate the Public key in scratch cbTmp = SymCryptSizeofEcpointFromCurve( pCurve ); poTmp = SymCryptEcpointCreate( pbScratchInternal, cbTmp, pCurve ); pbScratchInternal += cbTmp; cbScratchInternal -= cbTmp; } SYMCRYPT_ASSERT( poTmp != NULL ); // Always multiply by the cofactor since the internal format is "DIVH" scError = SymCryptEcpointScalarMul( pCurve, pEckey->piPrivateKey, NULL, SYMCRYPT_FLAG_ECC_LL_COFACTOR_MUL, poTmp, pbScratchInternal, cbScratchInternal ); if ( scError != SYMCRYPT_NO_ERROR ) { goto cleanup; } if ( pbPublicKey != NULL ) { if ( !SymCryptEcpointIsEqual( pCurve, poTmp, pEckey->poPublicKey, 0, pbScratchInternal, cbScratchInternal ) ) { scError = SYMCRYPT_INVALID_ARGUMENT; goto cleanup; } } else if ( ( flags & SYMCRYPT_FLAG_KEY_MINIMAL_VALIDATION ) == 0 ) { // Perform Public key validation on generated Public key. scError = SymCryptEckeyPerformPublicKeyValidation( pEckey, fValidatePublicKeyOrder, pbScratch, cbScratch ); if ( scError != SYMCRYPT_NO_ERROR ) { goto cleanup; } } } pEckey->fAlgorithmInfo = flags; // We want to track all of the flags in the Eckey if ( ( flags & SYMCRYPT_FLAG_KEY_NO_FIPS ) == 0 ) { if ( ( flags & SYMCRYPT_FLAG_ECKEY_ECDSA ) != 0 ) { // Ensure ECDSA algorithm selftest is run before first use of ECDSA algorithm SYMCRYPT_RUN_SELFTEST_ONCE( SymCryptEcDsaSelftest, SYMCRYPT_SELFTEST_ALGORITHM_ECDSA ); if( pEckey->hasPrivateKey ) { // We do not need to run an ECDSA PCT on import, indicate that the test has been run pEckey->fAlgorithmInfo |= SYMCRYPT_SELFTEST_KEY_ECDSA; } } if ( ( flags & SYMCRYPT_FLAG_ECKEY_ECDH ) != 0 ) { SYMCRYPT_RUN_SELFTEST_ONCE( SymCryptEcDhSecretAgreementSelftest, SYMCRYPT_SELFTEST_ALGORITHM_ECDH ); } } cleanup: if ( pbScratch != NULL ) { SymCryptWipe( pbScratch, cbScratch ); SymCryptCallbackFree( pbScratch ); } return scError; } SYMCRYPT_ERROR SYMCRYPT_CALL SymCryptEckeyGetValue( _In_ PCSYMCRYPT_ECKEY pEckey, _Out_writes_bytes_( cbPrivateKey ) PBYTE pbPrivateKey, SIZE_T cbPrivateKey, _Out_writes_bytes_( cbPublicKey ) PBYTE pbPublicKey, SIZE_T cbPublicKey, SYMCRYPT_NUMBER_FORMAT numFormat, SYMCRYPT_ECPOINT_FORMAT ecPointFormat, UINT32 flags ) { SYMCRYPT_ERROR scError = SYMCRYPT_NO_ERROR; PBYTE pbScratch = NULL; UINT32 cbScratch = 0; PBYTE pbScratchInternal = NULL; UINT32 cbScratchInternal = 0; PCSYMCRYPT_ECURVE pCurve = pEckey->pCurve; PSYMCRYPT_INT piTmpInteger = NULL; UINT32 cbTmpInteger = 0; PSYMCRYPT_MODELEMENT peTmpModElement = NULL; UINT32 cbTmpModElement = pCurve->cbModElement; UINT32 privateKeyDigits = SymCryptEcurveDigitsofScalarMultiplier(pCurve); SYMCRYPT_ASSERT( (cbPrivateKey==0) || (cbPrivateKey == SymCryptEcurveSizeofScalarMultiplier( pEckey->pCurve )) ); SYMCRYPT_ASSERT( (cbPublicKey==0) || (cbPublicKey == SymCryptEckeySizeofPublicKey( pEckey, ecPointFormat)) ); // Make sure we only specify the correct flags if (flags != 0) { scError = SYMCRYPT_INVALID_ARGUMENT; goto cleanup; } // Allocate scratch space cbScratch = SYMCRYPT_INTERNAL_SCRATCH_BYTES_FOR_ECKEY_ECURVE_OPERATIONS( pCurve ); pbScratch = SymCryptCallbackAlloc( cbScratch ); if ( pbScratch == NULL ) { scError = SYMCRYPT_MEMORY_ALLOCATION_FAILURE; goto cleanup; } pbScratchInternal = pbScratch; cbScratchInternal = cbScratch; // Allocate the integer cbTmpInteger = SymCryptSizeofIntFromDigits( privateKeyDigits ); piTmpInteger = SymCryptIntCreate( pbScratchInternal, cbTmpInteger, privateKeyDigits ); SYMCRYPT_ASSERT( piTmpInteger != NULL ); pbScratchInternal += cbTmpInteger; cbScratchInternal -= cbTmpInteger; // Allocate the modelement peTmpModElement = SymCryptModElementCreate( pbScratchInternal, cbTmpModElement, pCurve->GOrd ); SYMCRYPT_ASSERT( peTmpModElement != NULL ); pbScratchInternal += cbTmpModElement; cbScratchInternal -= cbTmpModElement; if ((cbPrivateKey == 0) && (cbPublicKey == 0)) { scError = SYMCRYPT_INVALID_ARGUMENT; goto cleanup; } if (cbPrivateKey != 0) { if (!pEckey->hasPrivateKey) { scError = SYMCRYPT_INVALID_BLOB; goto cleanup; } // If this keypair may be used in ECDSA, and does not have the no FIPS flag, run the PCT if // it has not already been run if ( ((pEckey->fAlgorithmInfo & SYMCRYPT_FLAG_ECKEY_ECDSA) != 0) && ((pEckey->fAlgorithmInfo & SYMCRYPT_FLAG_KEY_NO_FIPS) == 0) ) { SYMCRYPT_RUN_KEYGEN_PCT( SymCryptEcDsaSignVerifyTest, pEckey, SYMCRYPT_SELFTEST_ALGORITHM_ECDSA, SYMCRYPT_SELFTEST_KEY_ECDSA ); } // Copy the key into the temporary integer SymCryptIntCopy( pEckey->piPrivateKey, piTmpInteger ); // Convert the "DivH" format into the external format if (pCurve->coFactorPower>0) { // For the "Canonical" format: Multiply the integer by h // and then take the result modulo GOrd if (pCurve->PrivateKeyDefaultFormat == SYMCRYPT_ECKEY_PRIVATE_FORMAT_CANONICAL) { SymCryptIntMulPow2( piTmpInteger, pCurve->coFactorPower, piTmpInteger ); SymCryptIntDivMod( piTmpInteger, SymCryptDivisorFromModulus(pCurve->GOrd), NULL, piTmpInteger, pbScratch, cbScratchInternal ); } // For the "TimesH" format: Multiply the integer by h again by shifting if (pCurve->PrivateKeyDefaultFormat == SYMCRYPT_ECKEY_PRIVATE_FORMAT_DIVH_TIMESH) { SymCryptIntMulPow2( piTmpInteger, pCurve->coFactorPower, piTmpInteger ); } } scError = SymCryptIntGetValue( piTmpInteger, pbPrivateKey, cbPrivateKey, numFormat ); if (scError != SYMCRYPT_NO_ERROR) { goto cleanup; } } if (cbPublicKey != 0) { scError = SymCryptEcpointGetValue( pCurve, pEckey->poPublicKey, numFormat, ecPointFormat, pbPublicKey, cbPublicKey, SYMCRYPT_FLAG_DATA_PUBLIC, pbScratch, cbScratch ); } cleanup: if ( pbScratch != NULL ) { SymCryptWipe( pbScratch, cbScratch ); SymCryptCallbackFree( pbScratch ); } return scError; } #define SYMCRYPT_ECPOINT_SET_RANDOM_MAX_TRIES (1000) SYMCRYPT_ERROR SYMCRYPT_CALL SymCryptEckeySetRandom( _In_ UINT32 flags, _Inout_ PSYMCRYPT_ECKEY pEckey ) { SYMCRYPT_ERROR scError = SYMCRYPT_NO_ERROR; PBYTE pbScratch = NULL; UINT32 cbScratch = 0; PBYTE pbScratchInternal = NULL; UINT32 cbScratchInternal = 0; PCSYMCRYPT_ECURVE pCurve = pEckey->pCurve; INT32 cntr = SYMCRYPT_ECPOINT_SET_RANDOM_MAX_TRIES; PSYMCRYPT_MODELEMENT peScalar = NULL; PSYMCRYPT_INT piScalar = NULL; UINT32 cbScalar = 0; UINT32 highBitRestrictionPosition = pCurve->HighBitRestrictionPosition; // Ensure caller has specified what algorithm(s) the key will be used with UINT32 algorithmFlags = SYMCRYPT_FLAG_ECKEY_ECDSA | SYMCRYPT_FLAG_ECKEY_ECDH; // Make sure only allowed flags are specified UINT32 allowedFlags = SYMCRYPT_FLAG_KEY_NO_FIPS | algorithmFlags; if ( ( ( flags & ~allowedFlags ) != 0 ) || ( ( flags & algorithmFlags ) == 0 ) ) { scError = SYMCRYPT_INVALID_ARGUMENT; goto cleanup; } // // From symcrypt_internal.h we have: // - sizeof results are upper bounded by 2^19 // - SYMCRYPT_SCRATCH_BYTES results are upper bounded by 2^27 (including RSA and ECURVE) // Thus the following calculation does not overflow cbScratch. // cbScratch = SYMCRYPT_INTERNAL_SCRATCH_BYTES_FOR_ECKEY_ECURVE_OPERATIONS( pCurve ); pbScratch = SymCryptCallbackAlloc( cbScratch ); if ( pbScratch == NULL ) { scError = SYMCRYPT_MEMORY_ALLOCATION_FAILURE; goto cleanup; } // Allocating temporaries pbScratchInternal = pbScratch; cbScratchInternal = cbScratch; peScalar = SymCryptModElementCreate( pbScratchInternal, pCurve->cbModElement, pCurve->GOrd ); SYMCRYPT_ASSERT( peScalar != NULL ); pbScratchInternal += pCurve->cbModElement; cbScratchInternal -= pCurve->cbModElement; cbScalar = SymCryptSizeofIntFromDigits( SymCryptEcurveDigitsofScalarMultiplier(pCurve) ); piScalar = SymCryptIntCreate( pbScratchInternal, cbScalar, SymCryptEcurveDigitsofScalarMultiplier(pCurve) ); pbScratchInternal += cbScalar; cbScratchInternal -= cbScalar; // Shift the high bit position if the format is "TIMESH" // Note: Do not actually multiply the integer as we will check if it is // less than the group order if (pCurve->PrivateKeyDefaultFormat == SYMCRYPT_ECKEY_PRIVATE_FORMAT_DIVH_TIMESH) { highBitRestrictionPosition -= pCurve->coFactorPower; } // Main loop do { // We perform Private key range validation by construction // Setting a random mod element in the [1, SubgroupOrder-1] set // This will be the "DivH" format of the private key. This means // that PublicKey = h * PrivateKey * G SymCryptModSetRandom( pCurve->GOrd, peScalar, (SYMCRYPT_FLAG_MODRANDOM_ALLOW_ONE|SYMCRYPT_FLAG_MODRANDOM_ALLOW_MINUSONE), pbScratchInternal, cbScratchInternal ); // Converting to "canonical" format if (pCurve->PrivateKeyDefaultFormat == SYMCRYPT_ECKEY_PRIVATE_FORMAT_CANONICAL) { for (UINT32 i=0; i<pCurve->coFactorPower; i++) { SymCryptModAdd( pCurve->GOrd, peScalar, peScalar, peScalar, pbScratchInternal, cbScratchInternal ); } } // Set the temporary scalar to verify the format SymCryptModElementToInt( pCurve->GOrd, peScalar, piScalar, pbScratchInternal, cbScratchInternal ); if (pCurve->HighBitRestrictionNumOfBits > 0) { // Set the desired bits SymCryptIntSetBits( piScalar, pCurve->HighBitRestrictionValue, highBitRestrictionPosition, pCurve->HighBitRestrictionNumOfBits ); // Make sure we didn't exceed the group order if ( SymCryptIntIsLessThan( piScalar, SymCryptIntFromModulus( pCurve->GOrd )) ) { break; } } else { // No high bit restriction was specified break; } cntr--; } while (cntr>0); if (cntr <= 0) { scError = SYMCRYPT_INVALID_ARGUMENT; goto cleanup; } // Here piScalar has a private key that satisfies the restriction(s) // Move it to the modelement SymCryptIntToModElement( piScalar, pCurve->GOrd, peScalar, pbScratchInternal, cbScratchInternal ); // Convert the private key back to "DIVH" format if (pCurve->PrivateKeyDefaultFormat == SYMCRYPT_ECKEY_PRIVATE_FORMAT_CANONICAL) { SymCryptModDivPow2( pCurve->GOrd, peScalar, pCurve->coFactorPower, peScalar, pbScratchInternal, cbScratchInternal ); } // Set the private key SymCryptModElementToInt( pCurve->GOrd, peScalar, pEckey->piPrivateKey, pbScratchInternal, cbScratchInternal ); // Do the multiplication (pass over the entire scratch space as it is not needed anymore) scError = SymCryptEcpointScalarMul( pCurve, pEckey->piPrivateKey, NULL, SYMCRYPT_FLAG_ECC_LL_COFACTOR_MUL, pEckey->poPublicKey, pbScratch, cbScratch ); if ( scError != SYMCRYPT_NO_ERROR ) { goto cleanup; } // Perform range and public key order validation on generated Public key. if ( (flags & SYMCRYPT_FLAG_KEY_NO_FIPS) == 0 ) { // Perform Public key validation. // Always perform range validation and validation that Public key is in subgroup of order GOrd scError = SymCryptEckeyPerformPublicKeyValidation( pEckey, SYMCRYPT_FLAG_ECKEY_PUBLIC_KEY_ORDER_VALIDATION, pbScratch, cbScratch ); if ( scError != SYMCRYPT_NO_ERROR ) { goto cleanup; } } pEckey->hasPrivateKey = TRUE; pEckey->fAlgorithmInfo = flags; // We want to track all of the flags in the Eckey if ( (flags & SYMCRYPT_FLAG_KEY_NO_FIPS) == 0 ) { // We defer the ECDSA PCT to before first use of the Eckey in EcDsaSign, or first time // private key is exported - whichever comes first. if( ( flags & SYMCRYPT_FLAG_ECKEY_ECDH ) != 0 ) { // No additional per-key tests to perform before first use. // Just ensure we have run the algorithm selftest at least once. SYMCRYPT_RUN_SELFTEST_ONCE( SymCryptEcDhSecretAgreementSelftest, SYMCRYPT_SELFTEST_ALGORITHM_ECDH ); } } cleanup: if ( pbScratch != NULL ) { SymCryptWipe( pbScratch, cbScratch ); SymCryptCallbackFree( pbScratch ); } return scError; } SYMCRYPT_ERROR SYMCRYPT_CALL SymCryptEckeyExtendKeyUsage( _Inout_ PSYMCRYPT_ECKEY pEckey, UINT32 flags ) { SYMCRYPT_ERROR scError = SYMCRYPT_NO_ERROR; // Ensure caller has specified what algorithm(s) the key will be used with UINT32 algorithmFlags = SYMCRYPT_FLAG_ECKEY_ECDSA | SYMCRYPT_FLAG_ECKEY_ECDH; if ( ( ( flags & ~algorithmFlags ) != 0 ) || ( ( flags & algorithmFlags ) == 0) ) { scError = SYMCRYPT_INVALID_ARGUMENT; goto cleanup; } pEckey->fAlgorithmInfo |= flags; cleanup: return scError; }
6c0849556517c4a1905e93be87620e26b774ed9a
28d0f8c01599f8f6c711bdde0b59f9c2cd221203
/sys/arch/hppa/dev/lcd.c
fb9db9303e126ecc887ab7e9a1f5d9f060acabfe
[]
no_license
NetBSD/src
1a9cbc22ed778be638b37869ed4fb5c8dd616166
23ee83f7c0aea0777bd89d8ebd7f0cde9880d13c
refs/heads/trunk
2023-08-31T13:24:58.105962
2023-08-27T15:50:47
2023-08-27T15:50:47
88,439,547
656
348
null
2023-07-20T20:07:24
2017-04-16T20:03:43
null
UTF-8
C
false
false
3,603
c
lcd.c
/* $NetBSD: lcd.c,v 1.2 2018/09/03 16:29:24 riastradh Exp $ */ /* OpenBSD: lcd.c,v 1.2 2007/07/20 22:13:45 kettenis Exp */ /* * Copyright (c) 2007 Mark Kettenis * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include <sys/param.h> #include <sys/device.h> #include <sys/kernel.h> #include <sys/systm.h> #include <sys/callout.h> #include <machine/autoconf.h> #include <sys/bus.h> #include <machine/cpu.h> #include <machine/pdc.h> #define LCD_CLS 0x01 #define LCD_HOME 0x02 #define LCD_LOCATE(X, Y) (((Y) & 1 ? 0xc0 : 0x80) | ((X) & 0x0f)) struct lcd_softc { device_t sc_dv; bus_space_tag_t sc_iot; bus_space_handle_t sc_cmdh, sc_datah; u_int sc_delay; uint8_t sc_heartbeat[3]; struct callout sc_to; int sc_on; struct blink_lcd sc_blink; }; int lcd_match(device_t, cfdata_t, void *); void lcd_attach(device_t, device_t, void *); CFATTACH_DECL_NEW(lcd, sizeof(struct lcd_softc), lcd_match, lcd_attach, NULL, NULL); void lcd_write(struct lcd_softc *, const char *); void lcd_blink(void *, int); void lcd_blink_finish(void *); int lcd_match(device_t parent, cfdata_t match, void *aux) { struct confargs *ca = aux; if (strcmp(ca->ca_name, "lcd") == 0) return 1; return 0; } void lcd_attach(device_t parent, device_t self, void *aux) { struct lcd_softc *sc = device_private(self); struct confargs *ca = aux; struct pdc_chassis_lcd *pdc_lcd = &ca->ca_pcl; int i; sc->sc_dv = self; sc->sc_iot = ca->ca_iot; if (bus_space_map(sc->sc_iot, pdc_lcd->cmd_addr, 1, 0, &sc->sc_cmdh)) { aprint_error(": can't map cmd register\n"); return; } if (bus_space_map(sc->sc_iot, pdc_lcd->data_addr, 1, 0, &sc->sc_datah)) { aprint_error(": can't map data register\n"); bus_space_unmap(sc->sc_iot, sc->sc_cmdh, 1); return; } aprint_normal(": model %d\n", pdc_lcd->model); sc->sc_delay = pdc_lcd->delay; for (i = 0; i < 3; i++) sc->sc_heartbeat[i] = pdc_lcd->heartbeat[i]; bus_space_write_1(sc->sc_iot, sc->sc_cmdh, 0, LCD_CLS); delay(100 * sc->sc_delay); bus_space_write_1(sc->sc_iot, sc->sc_cmdh, 0, LCD_LOCATE(0, 0)); delay(sc->sc_delay); lcd_write(sc, "NetBSD/" MACHINE); callout_init(&sc->sc_to, 0); callout_setfunc(&sc->sc_to, lcd_blink_finish, sc); sc->sc_blink.bl_func = lcd_blink; sc->sc_blink.bl_arg = sc; blink_lcd_register(&sc->sc_blink); } void lcd_write(struct lcd_softc *sc, const char *str) { while (*str) { bus_space_write_1(sc->sc_iot, sc->sc_datah, 0, *str++); delay(sc->sc_delay); } } void lcd_blink(void *v, int on) { struct lcd_softc *sc = v; sc->sc_on = on; bus_space_write_1(sc->sc_iot, sc->sc_cmdh, 0, sc->sc_heartbeat[0]); callout_schedule(&sc->sc_to, uimax(1, (sc->sc_delay * hz) / 1000000)); } void lcd_blink_finish(void *v) { struct lcd_softc *sc = v; uint8_t data; if (sc->sc_on) data = sc->sc_heartbeat[1]; else data = sc->sc_heartbeat[2]; bus_space_write_1(sc->sc_iot, sc->sc_datah, 0, data); }
5862349c52bd84bfdda32274e9236e13663531fb
9b68b3d73b63ebcbfe18cc9a4aa8e91c84833a84
/tests/libs/gsl/tests/ieee-utils/test.c
dd8675b677831acf4b1a216ae48fb95f644907d6
[ "LicenseRef-scancode-unknown-license-reference", "Apache-2.0", "GPL-3.0-only" ]
permissive
openhpc/ohpc
17515db5082429eb9f250f12bf242b994beb715f
725a1f230434d0f08153ba1a5d0a7418574f8ae9
refs/heads/3.x
2023-08-19T02:15:14.682630
2023-08-18T19:33:51
2023-08-18T19:34:18
43,318,561
827
247
Apache-2.0
2023-09-14T01:22:18
2015-09-28T18:20:29
C
UTF-8
C
false
false
14,917
c
test.c
/* ieee-utils/test.c * * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Brian Gough * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include <config.h> #include <stdlib.h> #include <math.h> #include <float.h> #include <string.h> #include <gsl/gsl_ieee_utils.h> #include <gsl/gsl_test.h> #if HAVE_IRIX_IEEE_INTERFACE /* don't test denormals on IRIX */ #else #if HAVE_IEEE_DENORMALS #define TEST_DENORMAL 1 #endif #endif #ifndef FLT_MIN #define FLT_MIN 1.17549435e-38f #endif #ifndef FLT_MAX #define FLT_MAX 3.40282347e+38f #endif #ifndef DBL_MIN #define DBL_MIN 2.2250738585072014e-308 #endif #ifndef DBL_MAX #define DBL_MAX 1.7976931348623157e+308 #endif int main (void) { float zerof = 0.0f, minus_onef = -1.0f ; double zero = 0.0, minus_one = -1.0 ; /* Check for +ZERO (float) */ { float f = 0.0f; const char mantissa[] = "00000000000000000000000"; gsl_ieee_float_rep r; gsl_ieee_float_to_rep (&f, &r); gsl_test_int (r.sign, 0, "float x = 0, sign is +"); gsl_test_int (r.exponent, -127, "float x = 0, exponent is -127"); gsl_test_str (r.mantissa, mantissa, "float x = 0, mantissa"); gsl_test_int (r.type, GSL_IEEE_TYPE_ZERO, "float x = 0, type is ZERO"); } /* Check for -ZERO (float) */ { float f = minus_onef; const char mantissa[] = "00000000000000000000000"; gsl_ieee_float_rep r; while (f < 0) { f *= 0.1f; } gsl_ieee_float_to_rep (&f, &r); gsl_test_int (r.sign, 1, "float x = -1*0, sign is -"); gsl_test_int (r.exponent, -127, "float x = -1*0, exponent is -127"); gsl_test_str (r.mantissa, mantissa, "float x = -1*0, mantissa"); gsl_test_int (r.type, GSL_IEEE_TYPE_ZERO, "float x = -1*0, type is ZERO"); } /* Check for a positive NORMAL number (e.g. 2.1) (float) */ { float f = 2.1f; const char mantissa[] = "00001100110011001100110"; gsl_ieee_float_rep r; gsl_ieee_float_to_rep (&f, &r); gsl_test_int (r.sign, 0, "float x = 2.1, sign is +"); gsl_test_int (r.exponent, 1, "float x = 2.1, exponent is 1"); gsl_test_str (r.mantissa, mantissa, "float x = 2.1, mantissa"); gsl_test_int (r.type, GSL_IEEE_TYPE_NORMAL, "float x = 2.1, type is NORMAL"); } /* Check for a negative NORMAL number (e.g. -1.3304...) (float) */ { float f = -1.3303577090924210f ; const char mantissa[] = "01010100100100100101001"; gsl_ieee_float_rep r; gsl_ieee_float_to_rep (&f, &r); gsl_test_int (r.sign, 1, "float x = -1.3304..., sign is -"); gsl_test_int (r.exponent, 0, "float x = -1.3304..., exponent is 0"); gsl_test_str (r.mantissa, mantissa, "float x = -1.3304..., mantissa"); gsl_test_int (r.type, GSL_IEEE_TYPE_NORMAL, "float x = -1.3304..., type is NORMAL"); } /* Check for a large positive NORMAL number (e.g. 3.37e31) (float) */ { float f = 3.37e31f; const char mantissa[] = "10101001010110101001001"; gsl_ieee_float_rep r; gsl_ieee_float_to_rep (&f, &r); gsl_test_int (r.sign, 0, "float x = 3.37e31, sign is +"); gsl_test_int (r.exponent, 104, "float x = 3.37e31, exponent is 104"); gsl_test_str (r.mantissa, mantissa, "float x = 3.37e31, mantissa"); gsl_test_int (r.type, GSL_IEEE_TYPE_NORMAL, "float x = 3.37e31, type is NORMAL"); } /* Check for a small positive NORMAL number (e.g. 3.37e-31) (float) */ { float f = 3.37e-31f; const char mantissa[] = "10110101011100110111011"; gsl_ieee_float_rep r; gsl_ieee_float_to_rep (&f, &r); gsl_test_int (r.sign, 0, "float x = 3.37e-31, sign is +"); gsl_test_int (r.exponent, -102, "float x = 3.37e-31, exponent is -102"); gsl_test_str (r.mantissa, mantissa, "float x = 3.37e-31, mantissa"); gsl_test_int (r.type, GSL_IEEE_TYPE_NORMAL, "float x = 3.37e-31, type is NORMAL"); } /* Check for FLT_MIN (smallest possible number that is not denormal) */ { float f = FLT_MIN; const char mantissa[] = "00000000000000000000000"; gsl_ieee_float_rep r; gsl_ieee_float_to_rep (&f, &r); gsl_test_int (r.sign, 0, "float x = FLT_MIN, sign is +"); gsl_test_int (r.exponent, -126, "float x = FLT_MIN, exponent is -126"); gsl_test_str (r.mantissa, mantissa, "float x = FLT_MIN, mantissa"); gsl_test_int (r.type, GSL_IEEE_TYPE_NORMAL, "float x = FLT_MIN, type is NORMAL"); } /* Check for FLT_MAX (largest possible number that is not Inf) */ { float f = FLT_MAX; const char mantissa[] = "11111111111111111111111"; gsl_ieee_float_rep r; gsl_ieee_float_to_rep (&f, &r); gsl_test_int (r.sign, 0, "float x = FLT_MAX, sign is +"); gsl_test_int (r.exponent, 127, "float x = FLT_MAX, exponent is 127"); gsl_test_str (r.mantissa, mantissa, "float x = FLT_MAX, mantissa"); gsl_test_int (r.type, GSL_IEEE_TYPE_NORMAL, "float x = FLT_MAX, type is NORMAL"); } /* Check for DENORMAL numbers (e.g. FLT_MIN/2^n) */ #ifdef TEST_DENORMAL { float f = FLT_MIN; char mantissa[] = "10000000000000000000000"; int i; gsl_ieee_float_rep r; for (i = 0; i < 23; i++) { float x = f / (float)pow (2.0, 1 + (float) i); mantissa[i] = '1'; gsl_ieee_float_to_rep (&x, &r); gsl_test_int (r.sign, 0, "float x = FLT_MIN/2^%d, sign is +", i + 1); gsl_test_int (r.exponent, -127, "float x = FLT_MIN/2^%d, exponent is -127", i + 1); gsl_test_str (r.mantissa, mantissa, "float x = FLT_MIN/2^%d, mantissa", i + 1); gsl_test_int (r.type, GSL_IEEE_TYPE_DENORMAL, "float x = FLT_MIN/2^%d, type is DENORMAL", i + 1); mantissa[i] = '0'; } } #endif /* Check for positive INFINITY (e.g. 2*FLT_MAX) */ { float f = FLT_MAX; const char mantissa[] = "00000000000000000000000"; gsl_ieee_float_rep r; float x; x = 2 * f; gsl_ieee_float_to_rep (&x, &r); gsl_test_int (r.sign, 0, "float x = 2*FLT_MAX, sign is +"); gsl_test_int (r.exponent, 128, "float x = 2*FLT_MAX, exponent is 128"); gsl_test_str (r.mantissa, mantissa, "float x = 2*FLT_MAX, mantissa"); gsl_test_int (r.type, GSL_IEEE_TYPE_INF, "float x = -2*FLT_MAX, type is INF"); } /* Check for negative INFINITY (e.g. -2*FLT_MAX) */ { float f = FLT_MAX; const char mantissa[] = "00000000000000000000000"; gsl_ieee_float_rep r; float x; x = -2 * f; gsl_ieee_float_to_rep (&x, &r); gsl_test_int (r.sign, 1, "float x = -2*FLT_MAX, sign is -"); gsl_test_int (r.exponent, 128, "float x = -2*FLT_MAX, exponent is 128"); gsl_test_str (r.mantissa, mantissa, "float x = -2*FLT_MAX, mantissa"); gsl_test_int (r.type, GSL_IEEE_TYPE_INF, "float x = -2*FLT_MAX, type is INF"); } /* Check for NAN (e.g. Inf - Inf) (float) */ { gsl_ieee_float_rep r; float x = 1.0f, y = 2.0f, z = zerof; x = x / z; y = y / z; z = y - x; gsl_ieee_float_to_rep (&z, &r); /* We don't check the sign and we don't check the mantissa because they could be anything for a NaN */ gsl_test_int (r.exponent, 128, "float x = NaN, exponent is 128"); gsl_test_int (r.type, GSL_IEEE_TYPE_NAN, "float x = NaN, type is NAN"); } /* Check for +ZERO */ { double d = 0.0; const char mantissa[] = "0000000000000000000000000000000000000000000000000000"; gsl_ieee_double_rep r; gsl_ieee_double_to_rep (&d, &r); gsl_test_int (r.sign, 0, "double x = 0, sign is +"); gsl_test_int (r.exponent, -1023, "double x = 0, exponent is -1023"); gsl_test_str (r.mantissa, mantissa, "double x = 0, mantissa"); gsl_test_int (r.type, GSL_IEEE_TYPE_ZERO, "double x = 0, type is ZERO"); } /* Check for -ZERO */ { double d = minus_one; const char mantissa[] = "0000000000000000000000000000000000000000000000000000"; gsl_ieee_double_rep r; while (d < 0) { d *= 0.1; } gsl_ieee_double_to_rep (&d, &r); gsl_test_int (r.sign, 1, "double x = -1*0, sign is -"); gsl_test_int (r.exponent, -1023, "double x = -1*0, exponent is -1023"); gsl_test_str (r.mantissa, mantissa, "double x = -1*0, mantissa"); gsl_test_int (r.type, GSL_IEEE_TYPE_ZERO, "double x = -1*0, type is ZERO"); } /* Check for a positive NORMAL number (e.g. 2.1) */ { double d = 2.1; const char mantissa[] = "0000110011001100110011001100110011001100110011001101"; gsl_ieee_double_rep r; gsl_ieee_double_to_rep (&d, &r); gsl_test_int (r.sign, 0, "double x = 2.1, sign is +"); gsl_test_int (r.exponent, 1, "double x = 2.1, exponent is 1"); gsl_test_str (r.mantissa, mantissa, "double x = 2.1, mantissa"); gsl_test_int (r.type, GSL_IEEE_TYPE_NORMAL, "double x = 2.1, type is NORMAL"); } /* Check for a negative NORMAL number (e.g. -1.3304...) */ { double d = -1.3303577090924210146738460025517269968986511230468750; const char mantissa[] = "0101010010010010010100101010010010001000100011101110"; gsl_ieee_double_rep r; gsl_ieee_double_to_rep (&d, &r); gsl_test_int (r.sign, 1, "double x = -1.3304..., sign is -"); gsl_test_int (r.exponent, 0, "double x = -1.3304..., exponent is 0"); gsl_test_str (r.mantissa, mantissa, "double x = -1.3304..., mantissa"); gsl_test_int (r.type, GSL_IEEE_TYPE_NORMAL, "double x = -1.3304..., type is NORMAL"); } /* Check for a large positive NORMAL number (e.g. 3.37e297) */ { double d = 3.37e297; const char mantissa[] = "0100100111001001100101111001100000100110011101000100"; gsl_ieee_double_rep r; gsl_ieee_double_to_rep (&d, &r); gsl_test_int (r.sign, 0, "double x = 3.37e297, sign is +"); gsl_test_int (r.exponent, 988, "double x = 3.37e297, exponent is 998"); gsl_test_str (r.mantissa, mantissa, "double x = 3.37e297, mantissa"); gsl_test_int (r.type, GSL_IEEE_TYPE_NORMAL, "double x = 3.37e297, type is NORMAL"); } /* Check for a small positive NORMAL number (e.g. 3.37e-297) */ { double d = 3.37e-297; const char mantissa[] = "0001101000011011101011100001110010100001001100110111"; gsl_ieee_double_rep r; gsl_ieee_double_to_rep (&d, &r); gsl_test_int (r.sign, 0, "double x = 3.37e-297, sign is +"); gsl_test_int (r.exponent, -985, "double x = 3.37e-297, exponent is -985"); gsl_test_str (r.mantissa, mantissa, "double x = 3.37e-297, mantissa"); gsl_test_int (r.type, GSL_IEEE_TYPE_NORMAL, "double x = 3.37e-297, type is NORMAL"); } /* Check for DBL_MIN (smallest possible number that is not denormal) */ { double d = DBL_MIN; const char mantissa[] = "0000000000000000000000000000000000000000000000000000"; gsl_ieee_double_rep r; gsl_ieee_double_to_rep (&d, &r); gsl_test_int (r.sign, 0, "double x = DBL_MIN, sign is +"); gsl_test_int (r.exponent, -1022, "double x = DBL_MIN, exponent is -1022"); gsl_test_str (r.mantissa, mantissa, "double x = DBL_MIN, mantissa"); gsl_test_int (r.type, GSL_IEEE_TYPE_NORMAL, "double x = DBL_MIN, type is NORMAL"); } /* Check for DBL_MAX (largest possible number that is not Inf) */ { double d = DBL_MAX; const char mantissa[] = "1111111111111111111111111111111111111111111111111111"; gsl_ieee_double_rep r; gsl_ieee_double_to_rep (&d, &r); gsl_test_int (r.sign, 0, "double x = DBL_MAX, sign is +"); gsl_test_int (r.exponent, 1023, "double x = DBL_MAX, exponent is 1023"); gsl_test_str (r.mantissa, mantissa, "double x = DBL_MAX, mantissa"); gsl_test_int (r.type, GSL_IEEE_TYPE_NORMAL, "double x = DBL_MAX, type is NORMAL"); } /* Check for DENORMAL numbers (e.g. DBL_MIN/2^n) */ #ifdef TEST_DENORMAL { double d = DBL_MIN; char mantissa[] = "1000000000000000000000000000000000000000000000000000"; int i; gsl_ieee_double_rep r; for (i = 0; i < 52; i++) { double x = d / pow (2.0, 1 + (double) i); mantissa[i] = '1'; gsl_ieee_double_to_rep (&x, &r); gsl_test_int (r.sign, 0, "double x = DBL_MIN/2^%d, sign is +", i + 1); gsl_test_int (r.exponent, -1023, "double x = DBL_MIN/2^%d, exponent", i + 1); gsl_test_str (r.mantissa, mantissa, "double x = DBL_MIN/2^%d, mantissa", i + 1); gsl_test_int (r.type, GSL_IEEE_TYPE_DENORMAL, "double x = DBL_MIN/2^%d, type is DENORMAL", i + 1); mantissa[i] = '0'; } } #endif /* Check for positive INFINITY (e.g. 2*DBL_MAX) */ { double d = DBL_MAX; const char mantissa[] = "0000000000000000000000000000000000000000000000000000"; gsl_ieee_double_rep r; double x; x = 2.0 * d; gsl_ieee_double_to_rep (&x, &r); gsl_test_int (r.sign, 0, "double x = 2*DBL_MAX, sign is +"); gsl_test_int (r.exponent, 1024, "double x = 2*DBL_MAX, exponent is 1024"); gsl_test_str (r.mantissa, mantissa, "double x = 2*DBL_MAX, mantissa"); gsl_test_int (r.type, GSL_IEEE_TYPE_INF, "double x = 2*DBL_MAX, type is INF"); } /* Check for negative INFINITY (e.g. -2*DBL_MAX) */ { double d = DBL_MAX; const char mantissa[] = "0000000000000000000000000000000000000000000000000000"; gsl_ieee_double_rep r; double x; x = -2.0 * d; gsl_ieee_double_to_rep (&x, &r); gsl_test_int (r.sign, 1, "double x = -2*DBL_MAX, sign is -"); gsl_test_int (r.exponent, 1024, "double x = -2*DBL_MAX, exponent is 1024"); gsl_test_str (r.mantissa, mantissa, "double x = -2*DBL_MAX, mantissa"); gsl_test_int (r.type, GSL_IEEE_TYPE_INF,"double x = -2*DBL_MAX, type is INF"); } /* Check for NAN (e.g. Inf - Inf) */ { gsl_ieee_double_rep r; double x = 1.0, y = 2.0, z = zero; x = x / z; y = y / z; z = y - x; gsl_ieee_double_to_rep (&z, &r); /* We don't check the sign and we don't check the mantissa because they could be anything for a NaN */ gsl_test_int (r.exponent, 1024, "double x = NaN, exponent is 1024"); gsl_test_int (r.type, GSL_IEEE_TYPE_NAN, "double x = NaN, type is NAN"); } exit (gsl_test_summary ()); }
9d8690be0543fb656d34302d7c673b4202241b45
41db6c672362ccafdd28af40ecf7df51ffa90a15
/src/heapy/heapyc.c
50bbd47843dce42f23412a164095bd27acfc81d9
[ "LicenseRef-scancode-warranty-disclaimer", "MIT" ]
permissive
zhuyifei1999/guppy3
e5649a066199a92dc3bf8e77bdd6ffb44e790449
1b2db87af36388e43afd6ce5774b869bcc4a9452
refs/heads/master
2023-06-24T23:03:52.612921
2023-06-17T01:18:06
2023-06-17T01:54:06
202,611,372
371
24
MIT
2023-06-17T01:54:09
2019-08-15T21:05:15
Python
UTF-8
C
false
false
7,214
c
heapyc.c
/* module heapyc */ char heapyc_doc[] = "This module contains low level functionality for the heapy system.\n" "It is intended to be wrapped in higher level library classes.\n" "\n" "Summary of module content.\n" "\n" "Classes\n" " HeapView Gives a parameterized view of the heap.\n" " Horizon Limits the view back to some moment in time.\n" " NodeGraph Graph of nodes (address-treated objects).\n" " ObjectClassifier Classifies objects on various criteria.\n" " RootStateType Root of heap traversal using Python internals.\n" "\n" "Functions\n" " interpreter Start a new interpreter.\n" " set_async_exc Raise an exception in another thread.\n" " xmemstats Print system-dependent memory statistics.\n" "\n" "Object\n" " RootState The single instance of RootStateType.\n" ; #define PY_SSIZE_T_CLEAN #include <Python.h> #include "structmember.h" #include "compile.h" #include "frameobject.h" #include "../include/guppy.h" #include "../include/pythoncapi_compat.h" #include "../sets/nodeset.h" #include "hpinit.h" #include "heapdef.h" #include "heapy.h" #include "classifier.h" #include "nodegraph.h" #include "relation.h" #define INITFUNC PyInit_heapyc #define MODNAME "heapyc" /* Extern decls - maybe put in .h file but not in heapy.h */ extern NyHeapDef NyStdTypes_HeapDef[]; extern NyHeapDef NyStdTypes_HeapDef[]; extern NyHeapDef NyObjectWithHeapType_HeapDef; extern void NyStdTypes_init(void); extern int dict_relate_kv(NyHeapRelate *r, PyObject *dict, int k, int v); /* Forward decls */ PyTypeObject NyObjectClassifier_Type; PyTypeObject NyNodeSet_Type; PyTypeObject NyHeapView_Type; PyTypeObject NyHorizon_Type; PyTypeObject NyNodeGraph_Type; PyTypeObject NyRootState_Type; PyTypeObject NyRelation_Type; PyTypeObject NyNodeTuple_Type; NyHeapDef NyHvTypes_HeapDef[]; PyObject * NyObjectClassifier_New(PyObject *self, NyObjectClassifierDef *def); int NyHeapView_iterate(NyHeapViewObject *hv, int (*visit)(PyObject *, void *), void *arg); static Py_ssize_t roundupsize(Py_ssize_t n); /* Global constants */ static PyObject *this_module; PyObject *_hiding_tag__name; /* general utilities */ #include "impsets.c" static int iterable_iterate(PyObject *v, int (*visit)(PyObject *, void *), void *arg) { if (NyNodeSet_Check(v)) { return NyNodeSet_iterate((NyNodeSetObject *)v, visit, arg); } else if (NyHeapView_Check(v)) { return NyHeapView_iterate((NyHeapViewObject *)v, visit, arg); } else if (PyList_Check(v)) { /* A bit faster than general iterator?? */ Py_ssize_t i; int r; PyObject *item; for (i = 0; i < PyList_GET_SIZE(v); i++) { item = PyList_GET_ITEM(v, i); Py_INCREF(item); r = visit(item, arg); Py_DECREF(item); if (r == -1) return -1; if (r == 1) break; } return 0; } else { /* Do the general case. */ PyObject *it = PyObject_GetIter(v); int r; if (it == NULL) goto Err; /* Run iterator to exhaustion. */ for (;;) { PyObject *item = PyIter_Next(it); if (item == NULL) { if (PyErr_Occurred()) goto Err; break; } r = visit(item, arg); Py_DECREF(item); if (r == -1) goto Err; if (r == 1) break; } Py_DECREF(it); return 0; Err: Py_XDECREF(it); return -1; } } PyObject * gc_get_objects(void) { PyObject *gc=0, *objects=0; gc = PyImport_ImportModule("gc"); if (!gc) goto err; objects = PyObject_CallMethod(gc, "get_objects", ""); err: Py_XDECREF(gc); return objects; } #include "roundupsize.c" /* objects */ #include "hv.c" #include "classifier.c" #include "horizon.c" #include "nodegraph.c" #include "rootstate.c" /* Other functions */ #if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION < 9 #include "interpreter.c" #endif #include "xmemstats.c" static PyMethodDef module_methods[] = { #if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION < 9 {"interpreter", (PyCFunction)hp_interpreter, METH_VARARGS, hp_interpreter_doc}, {"set_async_exc", (PyCFunction)hp_set_async_exc, METH_VARARGS, hp_set_async_exc_doc}, #endif {"xmemstats", (PyCFunction)hp_xmemstats, METH_NOARGS, hp_xmemstats_doc}, {0} }; NyHeapDef NyHvTypes_HeapDef[] = { { 0, /* flags */ &NyNodeGraph_Type, /* type */ nodegraph_size, /* size */ nodegraph_traverse, /* traverse */ nodegraph_relate /* relate */ }, { 0, /* flags */ &NyRootState_Type, /* type */ 0, /* size */ rootstate_traverse, /* traverse */ rootstate_relate /* relate */ }, { 0, /* flags */ &NyHorizon_Type, /* type */ 0, /* size */ 0, /* traverse */ 0 /* relate */ }, /* End mark */ {0} }; static struct PyModuleDef moduledef = { PyModuleDef_HEAD_INIT, MODNAME, PyDoc_STR(heapyc_doc), -1, module_methods }; static int nyfills(void) { NYFILL(NyNodeTuple_Type); NYFILL(NyRelation_Type); NYFILL(NyHeapView_Type); NYFILL(NyObjectClassifier_Type); NYFILL(NyHorizon_Type); NYFILL(NyNodeGraph_Type); NYFILL(NyNodeGraphIter_Type); NYFILL(NyRootState_Type); return 0; } PyMODINIT_FUNC INITFUNC (void) { PyObject *m = NULL; PyObject *d; Py_SET_TYPE(&_Ny_RootStateStruct, &NyRootState_Type); // This has to be here because of 'initializer is not a constant' // build error on Windows. NyNodeTuple_Type.tp_base = &PyTuple_Type; if (nyfills() == -1) { goto error; } m = PyModule_Create(&moduledef); if (!m) goto error; if (import_sets() == -1) goto error; this_module = m; d = PyModule_GetDict(m); PyDict_SetItemString(d, "HeapView", (PyObject *)&NyHeapView_Type); PyDict_SetItemString(d, "Horizon", (PyObject *)&NyHorizon_Type); PyDict_SetItemString(d, "ObjectClassifier", (PyObject *)&NyObjectClassifier_Type); PyDict_SetItemString(d, "NodeGraph", (PyObject *)&NyNodeGraph_Type); PyDict_SetItemString(d, "Relation", (PyObject *)&NyRelation_Type); PyDict_SetItemString(d, "RootState", Ny_RootState); PyDict_SetItemString(d, "RootStateType", (PyObject *)&NyRootState_Type); _hiding_tag__name = PyUnicode_FromString("_hiding_tag_"); NyStdTypes_init(); if (NyNodeGraph_init() == -1) goto error; xmemstats_init(); return m; error: fprintf(stderr, "Error at initialization of module heapyc"); if (PyErr_Occurred() == NULL) PyErr_SetString(PyExc_ImportError, "module initialization failed"); Py_XDECREF(m); return NULL; }
72e15a88216d21567a41bdcc875292ceead143a7
89ea6e98727262e8767c59a925103e42eb034f0b
/BadCode-ReflectiveDLL/MemoryModule.h
1efefa33e808cb68fbae19179f77828147af0d52
[]
no_license
Rvn0xsy/BadCode
d5c0c25ecb7ba1b706e2c14e651d403448812b2a
801105e34885cca46074a2a016c55867cb2cccda
refs/heads/master
2022-04-29T01:07:52.968905
2022-03-07T06:18:29
2022-03-07T06:18:29
231,253,436
703
128
null
null
null
null
UTF-8
C
false
false
381
h
MemoryModule.h
#pragma once #ifndef __MEMORY_MODULE_HEADER #define __MEMORY_MODULE_HEADER #include <Windows.h> typedef void* HMEMORYMODULE; #ifdef __cplusplus extern "C" { #endif HMEMORYMODULE MemoryLoadLibrary(const void*); FARPROC MemoryGetProcAddress(HMEMORYMODULE, const char*); void MemoryFreeLibrary(HMEMORYMODULE); #ifdef __cplusplus } #endif #endif // __MEMORY_MODULE_HEADER
cfa511248cafc60d8017db85efd203467f04f226
450916eee7580beb928ed8f387db4f0a8c1aa508
/src/amuse/community/hacs64/src/Timer.h
7b1431e5c52ccddb7bfd204a13b2a7d019f00c5f
[ "Apache-2.0", "LicenseRef-scancode-warranty-disclaimer" ]
permissive
amusecode/amuse
42095545893f5a86ea79c2a52ce54d3ce8eb204f
b57c1e2fda1457d5025307be105c2aa59b19b574
refs/heads/main
2023-08-31T04:50:48.880044
2023-08-30T12:00:20
2023-08-30T12:00:20
18,516,331
158
118
Apache-2.0
2023-08-30T12:00:22
2014-04-07T12:35:07
AMPL
UTF-8
C
false
false
664
h
Timer.h
#ifndef __TIMER_H__ #define __TIMER_H__ #include <cstdio> #include <sys/time.h> inline double get_wtime() { struct timeval Tvalue; struct timezone dummy; gettimeofday(&Tvalue,&dummy); return ((double) Tvalue.tv_sec +1.e-6*((double) Tvalue.tv_usec)); } struct Timer{ const char *name; FILE *fp; const char *format; double tstart; Timer( const char *_name, FILE *_fp = stdout, const char *_format = " %-10s : %f sec\n") : name(_name), fp(_fp), format(_format) { tstart = get_wtime(); } ~Timer(){ double tend = get_wtime(); fprintf(fp, format, name, tend - tstart); fflush(fp); } }; #endif // __TIMER_H__
0c493406c084db7aec70ae8e1eba0b4b383e0737
7eaf54a78c9e2117247cb2ab6d3a0c20719ba700
/SOFTWARE/A64-TERES/linux-a64/include/linux/altera_uart.h
c022c82db7cac72baae890d7e0be4ca88bb3f127
[ "Linux-syscall-note", "GPL-2.0-only", "GPL-1.0-or-later", "LicenseRef-scancode-free-unknown", "Apache-2.0" ]
permissive
OLIMEX/DIY-LAPTOP
ae82f4ee79c641d9aee444db9a75f3f6709afa92
a3fafd1309135650bab27f5eafc0c32bc3ca74ee
refs/heads/rel3
2023-08-04T01:54:19.483792
2023-04-03T07:18:12
2023-04-03T07:18:12
80,094,055
507
92
Apache-2.0
2023-04-03T07:05:59
2017-01-26T07:25:50
C
UTF-8
C
false
false
358
h
altera_uart.h
/* * altera_uart.h -- Altera UART driver defines. */ #ifndef __ALTUART_H #define __ALTUART_H struct altera_uart_platform_uart { unsigned long mapbase; /* Physical address base */ unsigned int irq; /* Interrupt vector */ unsigned int uartclk; /* UART clock rate */ unsigned int bus_shift; /* Bus shift (address stride) */ }; #endif /* __ALTUART_H */
1bc36c17ff10a25cf2c32f93c35a9bf4937b0fe9
8149d6751e142ecbc200b43c2da2d5a94c0735df
/modules/aufile/aufile_src.c
0c5f26e3f88e7edb08e6ba2fb1e81881b33b1963
[ "BSD-3-Clause" ]
permissive
baresip/baresip
3c8ebef031f6a01a1462a9f36264197f90ce6ffe
5ace2f75b317bba60d46030ca3fd5e8fa045fecf
refs/heads/main
2023-08-25T12:55:24.860248
2023-08-17T06:56:31
2023-08-17T06:56:31
16,664,594
834
205
BSD-3-Clause
2023-09-14T12:47:57
2014-02-09T10:44:09
C
UTF-8
C
false
false
5,299
c
aufile_src.c
/** * @file aufile_src.c WAV Audio Source * * Copyright (C) 2022 commend.com - Christian Spielberger */ #define _DEFAULT_SOURCE 1 #define _BSD_SOURCE 1 #include <re_atomic.h> #include <re.h> #include <rem.h> #include <baresip.h> #include "aufile.h" /** * @defgroup aufile aufile * * Audio module for using a WAV-file as audio input * * Sample config: * \verbatim audio_source aufile,/tmp/test.wav \endverbatim */ struct ausrc_st { struct tmr tmr; struct aufile *aufile; struct aubuf *aubuf; enum aufmt fmt; /**< Wav file sample format */ struct ausrc_prm prm; /**< Audio src parameter */ uint32_t ptime; size_t sampc; RE_ATOMIC bool run; RE_ATOMIC bool started; thrd_t thread; ausrc_read_h *rh; ausrc_error_h *errh; void *arg; }; static void destructor(void *arg) { struct ausrc_st *st = arg; if (re_atomic_rlx(&st->started)) { re_atomic_rlx_set(&st->run, false); thrd_join(st->thread, NULL); } tmr_cancel(&st->tmr); mem_deref(st->aufile); mem_deref(st->aubuf); } static int src_thread(void *arg) { uint64_t now, ts = tmr_jiffies(); struct ausrc_st *st = arg; int16_t *sampv; uint32_t ms = 4; re_atomic_rlx_set(&st->started, true); if (!st->ptime) ms = 0; sampv = mem_alloc(st->sampc * sizeof(int16_t), NULL); if (!sampv) return ENOMEM; while (re_atomic_rlx(&st->run)) { struct auframe af; sys_msleep(ms); now = tmr_jiffies(); if (ts > now) continue; auframe_init(&af, AUFMT_S16LE, sampv, st->sampc, st->prm.srate, st->prm.ch); aubuf_read_auframe(st->aubuf, &af); st->rh(&af, st->arg); ts += st->ptime; if (aubuf_cur_size(st->aubuf) == 0) break; } mem_deref(sampv); re_atomic_rlx_set(&st->run, false); return 0; } static void timeout(void *arg) { struct ausrc_st *st = arg; tmr_start(&st->tmr, st->ptime ? st->ptime : 40, timeout, st); /* check if audio buffer is empty */ if (!re_atomic_rlx(&st->run)) { tmr_cancel(&st->tmr); info("aufile: end of file\n"); /* error handler must be called from re_main thread */ if (st->errh) st->errh(0, "end of file", st->arg); } } static int read_file(struct ausrc_st *st) { struct mbuf *mb = NULL; int err; size_t n; struct mbuf *mb2 = NULL; struct auframe af; auframe_init(&af, st->fmt, NULL, 0, st->prm.srate, st->prm.ch); for (;;) { uint16_t *sampv; uint8_t *p; size_t i; mem_deref(mb); mb = mbuf_alloc(4096); if (!mb) return ENOMEM; mb->end = mb->size; err = aufile_read(st->aufile, mb->buf, &mb->end); if (err) break; if (mb->end == 0) { info("aufile: read end of file\n"); break; } /* convert from Little-Endian to Native-Endian */ n = mb->end; sampv = (void *)mb->buf; p = (void *)mb->buf; switch (st->fmt) { case AUFMT_S16LE: /* convert from Little-Endian to Native-Endian */ for (i = 0; i < n/2; i++) sampv[i] = sys_ltohs(sampv[i]); aubuf_append_auframe(st->aubuf, mb, &af); break; case AUFMT_PCMA: case AUFMT_PCMU: mb2 = mbuf_alloc(2 * n); for (i = 0; i < n; i++) { err |= mbuf_write_u16(mb2, st->fmt == AUFMT_PCMA ? (uint16_t) g711_alaw2pcm(p[i]) : (uint16_t) g711_ulaw2pcm(p[i]) ); } mbuf_set_pos(mb2, 0); aubuf_append_auframe(st->aubuf, mb2, &af); mem_deref(mb2); break; default: err = ENOSYS; break; } if (err) break; } info("aufile: loaded %zu bytes\n", aubuf_cur_size(st->aubuf)); mem_deref(mb); return err; } int aufile_src_alloc(struct ausrc_st **stp, const struct ausrc *as, struct ausrc_prm *prm, const char *dev, ausrc_read_h *rh, ausrc_error_h *errh, void *arg) { struct ausrc_st *st; struct aufile_prm fprm; uint32_t ptime; bool join = false; int err; if (!stp || !as || !prm || !rh) return EINVAL; if (prm->fmt != AUFMT_S16LE) { warning("aufile: unsupported sample format (%s)\n", aufmt_name(prm->fmt)); return ENOTSUP; } info("aufile: loading input file '%s'\n", dev); st = mem_zalloc(sizeof(*st), destructor); if (!st) return ENOMEM; st->rh = rh; st->errh = errh; st->arg = arg; st->ptime = prm->ptime; /* ptime == 0 means blocking mode */ join = st->ptime == 0; ptime = st->ptime; if (!ptime) ptime = 40; err = aufile_open(&st->aufile, &fprm, dev, AUFILE_READ); if (err) { warning("aufile: failed to open file '%s' (%m)\n", dev, err); goto out; } info("aufile: %s: %u Hz, %d channels, %s\n", dev, fprm.srate, fprm.channels, aufmt_name(fprm.fmt)); /* return wav format to caller */ prm->srate = fprm.srate; prm->ch = fprm.channels; st->prm = *prm; st->fmt = fprm.fmt; st->sampc = prm->srate * prm->ch * ptime / 1000; info("aufile: audio ptime=%u sampc=%zu\n", st->ptime, st->sampc); /* 1 - inf seconds of audio */ err = aubuf_alloc(&st->aubuf, 0, 0); if (err) goto out; err = read_file(st); if (err) goto out; tmr_start(&st->tmr, ptime, timeout, st); re_atomic_rlx_set(&st->run, true); err = thread_create_name(&st->thread, "aufile_src", src_thread, st); if (err) { re_atomic_rlx_set(&st->run, false); goto out; } if (join) { thrd_join(st->thread, NULL); st->errh(0, NULL, st->arg); } out: if (err) mem_deref(st); else *stp = st; return err; }
75d685fa19dadfaa3f9a35375369863e9f693d7f
4692f28f86ee84a76abfac8cc8a0dd41fcd402e4
/pkg/security/ebpf/c/include/helpers/span.h
75d307b25f151f25c82680f3123381534d44141b
[ "CC0-1.0", "BSD-3-Clause", "Apache-2.0", "GPL-1.0-or-later", "MIT", "0BSD", "Unlicense", "LicenseRef-scancode-public-domain", "BSD-2-Clause", "BSD-2-Clause-Views", "MPL-2.0", "GPL-2.0-only" ]
permissive
DataDog/datadog-agent
cc4b89839d6031903bf23aa12eccc2a3f3c7f213
d960cdb7de8fa5d1c7138cfe58e754af80cb796a
refs/heads/main
2023-09-04T10:45:08.138748
2023-09-04T09:13:43
2023-09-04T09:13:43
49,970,739
2,388
1,288
Apache-2.0
2023-09-14T20:06:34
2016-01-19T17:40:41
Go
UTF-8
C
false
false
1,512
h
span.h
#ifndef _HELPERS_SPAN_H_ #define _HELPERS_SPAN_H_ #include "maps.h" #include "process.h" int __attribute__((always_inline)) handle_register_span_memory(void *data) { struct span_tls_t tls = {}; bpf_probe_read(&tls, sizeof(tls), data); u64 pid_tgid = bpf_get_current_pid_tgid(); u32 tgid = pid_tgid >> 32; bpf_map_update_elem(&span_tls, &tgid, &tls, BPF_NOEXIST); return 0; } int __attribute__((always_inline)) unregister_span_memory() { u64 pid_tgid = bpf_get_current_pid_tgid(); u32 tgid = pid_tgid >> 32; bpf_map_delete_elem(&span_tls, &tgid); return 0; } void __attribute__((always_inline)) fill_span_context(struct span_context_t *span) { u64 pid_tgid = bpf_get_current_pid_tgid(); u32 tgid = pid_tgid >> 32; struct span_tls_t *tls = bpf_map_lookup_elem(&span_tls, &tgid); if (tls) { u32 tid = pid_tgid; struct task_struct *current_ptr = (struct task_struct *)bpf_get_current_task(); u32 pid = get_namespace_nr_from_task_struct(current_ptr); if (pid) { tid = pid; } int offset = (tid % tls->max_threads) * sizeof(struct span_context_t); int ret = bpf_probe_read(span, sizeof(struct span_context_t), tls->base + offset); if (ret < 0) { span->span_id = 0; span->trace_id = 0; } } } void __attribute__((always_inline)) copy_span_context(struct span_context_t *src, struct span_context_t *dst) { dst->span_id = src->span_id; dst->trace_id = src->trace_id; } #endif
fbdf225c1b7dd819104fd06e8f5c80e83e66fe84
76f7459a09acb9be2d52407132f5ff8955627da2
/frame/include/level0/bli_copys_mxn.h
cb2513466e655d3c74b8ea26db335342be24487d
[ "BSD-3-Clause" ]
permissive
flame/blis
448bc0ad139b726188129c5627c304274b41c3c1
6dcf7666eff14348e82fbc2750be4b199321e1b9
refs/heads/master
2023-09-01T14:56:11.920485
2023-08-27T19:18:57
2023-08-27T19:18:57
16,143,904
1,696
361
NOASSERTION
2023-08-27T19:18:58
2014-01-22T15:58:24
C
UTF-8
C
false
false
17,745
h
bli_copys_mxn.h
/* BLIS An object-based framework for developing high-performance BLAS-like libraries. Copyright (C) 2014, The University of Texas at Austin Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name(s) of the copyright holder(s) nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef BLIS_COPYS_MXN_H #define BLIS_COPYS_MXN_H // copys_mxn // Notes: // - The first char encodes the type of x. // - The second char encodes the type of y. #undef BLIS_ENABLE_CR_CASES #define BLIS_ENABLE_CR_CASES 0 // -- bli_??copys_mxn -- #undef GENTFUNC2 #define GENTFUNC2( ctypex, ctypey, chx, chy, opname, kername ) \ \ BLIS_INLINE void PASTEMAC2(chx,chy,opname) \ ( \ const dim_t m, \ const dim_t n, \ const ctypex* x, inc_t rs_x, inc_t cs_x, \ ctypey* y, inc_t rs_y, inc_t cs_y \ ) \ { \ if ( BLIS_ENABLE_CR_CASES && rs_x == 1 && rs_y == 1 ) \ { \ for ( dim_t jj = 0; jj < n; ++jj ) \ for ( dim_t ii = 0; ii < m; ++ii ) \ PASTEMAC2(chx,chy,kername)( *(x + ii + jj*cs_x), \ *(y + ii + jj*cs_y) ); \ } \ else if ( BLIS_ENABLE_CR_CASES && cs_x == 1 && cs_y == 1 ) \ { \ for ( dim_t ii = 0; ii < m; ++ii ) \ for ( dim_t jj = 0; jj < n; ++jj ) \ PASTEMAC2(chx,chy,kername)( *(x + ii*rs_x + jj), \ *(y + ii*rs_y + jj) ); \ } \ else \ { \ for ( dim_t jj = 0; jj < n; ++jj ) \ for ( dim_t ii = 0; ii < m; ++ii ) \ PASTEMAC2(chx,chy,kername)( *(x + ii*rs_x + jj*cs_x), \ *(y + ii*rs_y + jj*cs_y) ); \ } \ } INSERT_GENTFUNC2_BASIC ( copys_mxn, copys ) INSERT_GENTFUNC2_MIX_DP( copys_mxn, copys ) // -- bli_?copys_mxn -- #undef GENTFUNC #define GENTFUNC( ctype, ch, opname ) \ \ BLIS_INLINE void PASTEMAC(ch,opname) \ ( \ const dim_t m, \ const dim_t n, \ const ctype* x, inc_t rs_x, inc_t cs_x, \ ctype* y, inc_t rs_y, inc_t cs_y \ ) \ { \ PASTEMAC2(ch,ch,opname)( m, n, x, rs_x, cs_x, y, rs_y, cs_y ); \ } INSERT_GENTFUNC_BASIC( copys_mxn ) #if 0 // xy = ?s BLIS_INLINE void bli_sscopys_mxn ( const dim_t m, const dim_t n, const float* restrict x, const inc_t rs_x, const inc_t cs_x, float* restrict y, const inc_t rs_y, const inc_t cs_y ) { #ifdef BLIS_ENABLE_CR_CASES if ( rs_x == 1 && rs_y == 1 ) { for ( dim_t jj = 0; jj < n; ++jj ) for ( dim_t ii = 0; ii < m; ++ii ) bli_sscopys( *(x + ii + jj*cs_x), *(y + ii + jj*cs_y) ); } else if ( cs_x == 1 && cs_y == 1 ) { for ( dim_t ii = 0; ii < m; ++ii ) for ( dim_t jj = 0; jj < n; ++jj ) bli_sscopys( *(x + ii*rs_x + jj), *(y + ii*rs_y + jj) ); } else #endif { for ( dim_t jj = 0; jj < n; ++jj ) for ( dim_t ii = 0; ii < m; ++ii ) bli_sscopys( *(x + ii*rs_x + jj*cs_x), *(y + ii*rs_y + jj*cs_y) ); } } BLIS_INLINE void bli_dscopys_mxn ( const dim_t m, const dim_t n, const double* restrict x, const inc_t rs_x, const inc_t cs_x, float* restrict y, const inc_t rs_y, const inc_t cs_y ) { #ifdef BLIS_ENABLE_CR_CASES if ( rs_x == 1 && rs_y == 1 ) { for ( dim_t jj = 0; jj < n; ++jj ) for ( dim_t ii = 0; ii < m; ++ii ) bli_dscopys( *(x + ii + jj*cs_x), *(y + ii + jj*cs_y) ); } else if ( cs_x == 1 && cs_y == 1 ) { for ( dim_t ii = 0; ii < m; ++ii ) for ( dim_t jj = 0; jj < n; ++jj ) bli_dscopys( *(x + ii*rs_x + jj), *(y + ii*rs_y + jj) ); } else #endif { for ( dim_t jj = 0; jj < n; ++jj ) for ( dim_t ii = 0; ii < m; ++ii ) bli_dscopys( *(x + ii*rs_x + jj*cs_x), *(y + ii*rs_y + jj*cs_y) ); } } BLIS_INLINE void bli_cscopys_mxn ( const dim_t m, const dim_t n, const scomplex* restrict x, const inc_t rs_x, const inc_t cs_x, float* restrict y, const inc_t rs_y, const inc_t cs_y ) { #ifdef BLIS_ENABLE_CR_CASES if ( rs_x == 1 && rs_y == 1 ) { for ( dim_t jj = 0; jj < n; ++jj ) for ( dim_t ii = 0; ii < m; ++ii ) bli_cscopys( *(x + ii + jj*cs_x), *(y + ii + jj*cs_y) ); } else if ( cs_x == 1 && cs_y == 1 ) { for ( dim_t ii = 0; ii < m; ++ii ) for ( dim_t jj = 0; jj < n; ++jj ) bli_cscopys( *(x + ii*rs_x + jj), *(y + ii*rs_y + jj) ); } else #endif { for ( dim_t jj = 0; jj < n; ++jj ) for ( dim_t ii = 0; ii < m; ++ii ) bli_cscopys( *(x + ii*rs_x + jj*cs_x), *(y + ii*rs_y + jj*cs_y) ); } } BLIS_INLINE void bli_zscopys_mxn ( const dim_t m, const dim_t n, const dcomplex* restrict x, const inc_t rs_x, const inc_t cs_x, float* restrict y, const inc_t rs_y, const inc_t cs_y ) { #ifdef BLIS_ENABLE_CR_CASES if ( rs_x == 1 && rs_y == 1 ) { for ( dim_t jj = 0; jj < n; ++jj ) for ( dim_t ii = 0; ii < m; ++ii ) bli_zscopys( *(x + ii + jj*cs_x), *(y + ii + jj*cs_y) ); } else if ( cs_x == 1 && cs_y == 1 ) { for ( dim_t ii = 0; ii < m; ++ii ) for ( dim_t jj = 0; jj < n; ++jj ) bli_zscopys( *(x + ii*rs_x + jj), *(y + ii*rs_y + jj) ); } else #endif { for ( dim_t jj = 0; jj < n; ++jj ) for ( dim_t ii = 0; ii < m; ++ii ) bli_zscopys( *(x + ii*rs_x + jj*cs_x), *(y + ii*rs_y + jj*cs_y) ); } } // xy = ?d BLIS_INLINE void bli_sdcopys_mxn ( const dim_t m, const dim_t n, const float* restrict x, const inc_t rs_x, const inc_t cs_x, double* restrict y, const inc_t rs_y, const inc_t cs_y ) { #ifdef BLIS_ENABLE_CR_CASES if ( rs_x == 1 && rs_y == 1 ) { for ( dim_t jj = 0; jj < n; ++jj ) for ( dim_t ii = 0; ii < m; ++ii ) bli_sdcopys( *(x + ii + jj*cs_x), *(y + ii + jj*cs_y) ); } else if ( cs_x == 1 && cs_y == 1 ) { for ( dim_t ii = 0; ii < m; ++ii ) for ( dim_t jj = 0; jj < n; ++jj ) bli_sdcopys( *(x + ii*rs_x + jj), *(y + ii*rs_y + jj) ); } else #endif { for ( dim_t jj = 0; jj < n; ++jj ) for ( dim_t ii = 0; ii < m; ++ii ) bli_sdcopys( *(x + ii*rs_x + jj*cs_x), *(y + ii*rs_y + jj*cs_y) ); } } BLIS_INLINE void bli_ddcopys_mxn ( const dim_t m, const dim_t n, const double* restrict x, const inc_t rs_x, const inc_t cs_x, double* restrict y, const inc_t rs_y, const inc_t cs_y ) { #ifdef BLIS_ENABLE_CR_CASES if ( rs_x == 1 && rs_y == 1 ) { for ( dim_t jj = 0; jj < n; ++jj ) for ( dim_t ii = 0; ii < m; ++ii ) bli_ddcopys( *(x + ii + jj*cs_x), *(y + ii + jj*cs_y) ); } else if ( cs_x == 1 && cs_y == 1 ) { for ( dim_t ii = 0; ii < m; ++ii ) for ( dim_t jj = 0; jj < n; ++jj ) bli_ddcopys( *(x + ii*rs_x + jj), *(y + ii*rs_y + jj) ); } else #endif { for ( dim_t jj = 0; jj < n; ++jj ) for ( dim_t ii = 0; ii < m; ++ii ) bli_ddcopys( *(x + ii*rs_x + jj*cs_x), *(y + ii*rs_y + jj*cs_y) ); } } BLIS_INLINE void bli_cdcopys_mxn ( const dim_t m, const dim_t n, const scomplex* restrict x, const inc_t rs_x, const inc_t cs_x, double* restrict y, const inc_t rs_y, const inc_t cs_y ) { #ifdef BLIS_ENABLE_CR_CASES if ( rs_x == 1 && rs_y == 1 ) { for ( dim_t jj = 0; jj < n; ++jj ) for ( dim_t ii = 0; ii < m; ++ii ) bli_cdcopys( *(x + ii + jj*cs_x), *(y + ii + jj*cs_y) ); } else if ( cs_x == 1 && cs_y == 1 ) { for ( dim_t ii = 0; ii < m; ++ii ) for ( dim_t jj = 0; jj < n; ++jj ) bli_cdcopys( *(x + ii*rs_x + jj), *(y + ii*rs_y + jj) ); } else #endif { for ( dim_t jj = 0; jj < n; ++jj ) for ( dim_t ii = 0; ii < m; ++ii ) bli_cdcopys( *(x + ii*rs_x + jj*cs_x), *(y + ii*rs_y + jj*cs_y) ); } } BLIS_INLINE void bli_zdcopys_mxn ( const dim_t m, const dim_t n, const dcomplex* restrict x, const inc_t rs_x, const inc_t cs_x, double* restrict y, const inc_t rs_y, const inc_t cs_y ) { #ifdef BLIS_ENABLE_CR_CASES if ( rs_x == 1 && rs_y == 1 ) { for ( dim_t jj = 0; jj < n; ++jj ) for ( dim_t ii = 0; ii < m; ++ii ) bli_zdcopys( *(x + ii + jj*cs_x), *(y + ii + jj*cs_y) ); } else if ( cs_x == 1 && cs_y == 1 ) { for ( dim_t ii = 0; ii < m; ++ii ) for ( dim_t jj = 0; jj < n; ++jj ) bli_zdcopys( *(x + ii*rs_x + jj), *(y + ii*rs_y + jj) ); } else #endif { for ( dim_t jj = 0; jj < n; ++jj ) for ( dim_t ii = 0; ii < m; ++ii ) bli_zdcopys( *(x + ii*rs_x + jj*cs_x), *(y + ii*rs_y + jj*cs_y) ); } } // xy = ?c BLIS_INLINE void bli_sccopys_mxn ( const dim_t m, const dim_t n, const float* restrict x, const inc_t rs_x, const inc_t cs_x, scomplex* restrict y, const inc_t rs_y, const inc_t cs_y ) { #ifdef BLIS_ENABLE_CR_CASES if ( rs_x == 1 && rs_y == 1 ) { for ( dim_t jj = 0; jj < n; ++jj ) for ( dim_t ii = 0; ii < m; ++ii ) bli_sccopys( *(x + ii + jj*cs_x), *(y + ii + jj*cs_y) ); } else if ( cs_x == 1 && cs_y == 1 ) { for ( dim_t ii = 0; ii < m; ++ii ) for ( dim_t jj = 0; jj < n; ++jj ) bli_sccopys( *(x + ii*rs_x + jj), *(y + ii*rs_y + jj) ); } else #endif { for ( dim_t jj = 0; jj < n; ++jj ) for ( dim_t ii = 0; ii < m; ++ii ) bli_sccopys( *(x + ii*rs_x + jj*cs_x), *(y + ii*rs_y + jj*cs_y) ); } } BLIS_INLINE void bli_dccopys_mxn ( const dim_t m, const dim_t n, const double* restrict x, const inc_t rs_x, const inc_t cs_x, scomplex* restrict y, const inc_t rs_y, const inc_t cs_y ) { #ifdef BLIS_ENABLE_CR_CASES if ( rs_x == 1 && rs_y == 1 ) { for ( dim_t jj = 0; jj < n; ++jj ) for ( dim_t ii = 0; ii < m; ++ii ) bli_dccopys( *(x + ii + jj*cs_x), *(y + ii + jj*cs_y) ); } else if ( cs_x == 1 && cs_y == 1 ) { for ( dim_t ii = 0; ii < m; ++ii ) for ( dim_t jj = 0; jj < n; ++jj ) bli_dccopys( *(x + ii*rs_x + jj), *(y + ii*rs_y + jj) ); } else #endif { for ( dim_t jj = 0; jj < n; ++jj ) for ( dim_t ii = 0; ii < m; ++ii ) bli_dccopys( *(x + ii*rs_x + jj*cs_x), *(y + ii*rs_y + jj*cs_y) ); } } BLIS_INLINE void bli_cccopys_mxn ( const dim_t m, const dim_t n, const scomplex* restrict x, const inc_t rs_x, const inc_t cs_x, scomplex* restrict y, const inc_t rs_y, const inc_t cs_y ) { #ifdef BLIS_ENABLE_CR_CASES if ( rs_x == 1 && rs_y == 1 ) { for ( dim_t jj = 0; jj < n; ++jj ) for ( dim_t ii = 0; ii < m; ++ii ) bli_cccopys( *(x + ii + jj*cs_x), *(y + ii + jj*cs_y) ); } else if ( cs_x == 1 && cs_y == 1 ) { for ( dim_t ii = 0; ii < m; ++ii ) for ( dim_t jj = 0; jj < n; ++jj ) bli_cccopys( *(x + ii*rs_x + jj), *(y + ii*rs_y + jj) ); } else #endif { for ( dim_t jj = 0; jj < n; ++jj ) for ( dim_t ii = 0; ii < m; ++ii ) bli_cccopys( *(x + ii*rs_x + jj*cs_x), *(y + ii*rs_y + jj*cs_y) ); } } BLIS_INLINE void bli_zccopys_mxn ( const dim_t m, const dim_t n, const dcomplex* restrict x, const inc_t rs_x, const inc_t cs_x, scomplex* restrict y, const inc_t rs_y, const inc_t cs_y ) { #ifdef BLIS_ENABLE_CR_CASES if ( rs_x == 1 && rs_y == 1 ) { for ( dim_t jj = 0; jj < n; ++jj ) for ( dim_t ii = 0; ii < m; ++ii ) bli_zccopys( *(x + ii + jj*cs_x), *(y + ii + jj*cs_y) ); } else if ( cs_x == 1 && cs_y == 1 ) { for ( dim_t ii = 0; ii < m; ++ii ) for ( dim_t jj = 0; jj < n; ++jj ) bli_zccopys( *(x + ii*rs_x + jj), *(y + ii*rs_y + jj) ); } else #endif { for ( dim_t jj = 0; jj < n; ++jj ) for ( dim_t ii = 0; ii < m; ++ii ) bli_zccopys( *(x + ii*rs_x + jj*cs_x), *(y + ii*rs_y + jj*cs_y) ); } } // xy = ?c BLIS_INLINE void bli_szcopys_mxn ( const dim_t m, const dim_t n, const float* restrict x, const inc_t rs_x, const inc_t cs_x, dcomplex* restrict y, const inc_t rs_y, const inc_t cs_y ) { #ifdef BLIS_ENABLE_CR_CASES if ( rs_x == 1 && rs_y == 1 ) { for ( dim_t jj = 0; jj < n; ++jj ) for ( dim_t ii = 0; ii < m; ++ii ) bli_szcopys( *(x + ii + jj*cs_x), *(y + ii + jj*cs_y) ); } else if ( cs_x == 1 && cs_y == 1 ) { for ( dim_t ii = 0; ii < m; ++ii ) for ( dim_t jj = 0; jj < n; ++jj ) bli_szcopys( *(x + ii*rs_x + jj), *(y + ii*rs_y + jj) ); } else #endif { for ( dim_t jj = 0; jj < n; ++jj ) for ( dim_t ii = 0; ii < m; ++ii ) bli_szcopys( *(x + ii*rs_x + jj*cs_x), *(y + ii*rs_y + jj*cs_y) ); } } BLIS_INLINE void bli_dzcopys_mxn ( const dim_t m, const dim_t n, const double* restrict x, const inc_t rs_x, const inc_t cs_x, dcomplex* restrict y, const inc_t rs_y, const inc_t cs_y ) { #ifdef BLIS_ENABLE_CR_CASES if ( rs_x == 1 && rs_y == 1 ) { for ( dim_t jj = 0; jj < n; ++jj ) for ( dim_t ii = 0; ii < m; ++ii ) bli_dzcopys( *(x + ii + jj*cs_x), *(y + ii + jj*cs_y) ); } else if ( cs_x == 1 && cs_y == 1 ) { for ( dim_t ii = 0; ii < m; ++ii ) for ( dim_t jj = 0; jj < n; ++jj ) bli_dzcopys( *(x + ii*rs_x + jj), *(y + ii*rs_y + jj) ); } else #endif { for ( dim_t jj = 0; jj < n; ++jj ) for ( dim_t ii = 0; ii < m; ++ii ) bli_dzcopys( *(x + ii*rs_x + jj*cs_x), *(y + ii*rs_y + jj*cs_y) ); } } BLIS_INLINE void bli_czcopys_mxn ( const dim_t m, const dim_t n, const scomplex* restrict x, const inc_t rs_x, const inc_t cs_x, dcomplex* restrict y, const inc_t rs_y, const inc_t cs_y ) { #ifdef BLIS_ENABLE_CR_CASES if ( rs_x == 1 && rs_y == 1 ) { for ( dim_t jj = 0; jj < n; ++jj ) for ( dim_t ii = 0; ii < m; ++ii ) bli_czcopys( *(x + ii + jj*cs_x), *(y + ii + jj*cs_y) ); } else if ( cs_x == 1 && cs_y == 1 ) { for ( dim_t ii = 0; ii < m; ++ii ) for ( dim_t jj = 0; jj < n; ++jj ) bli_czcopys( *(x + ii*rs_x + jj), *(y + ii*rs_y + jj) ); } else #endif { for ( dim_t jj = 0; jj < n; ++jj ) for ( dim_t ii = 0; ii < m; ++ii ) bli_czcopys( *(x + ii*rs_x + jj*cs_x), *(y + ii*rs_y + jj*cs_y) ); } } BLIS_INLINE void bli_zzcopys_mxn ( const dim_t m, const dim_t n, const dcomplex* restrict x, const inc_t rs_x, const inc_t cs_x, dcomplex* restrict y, const inc_t rs_y, const inc_t cs_y ) { #ifdef BLIS_ENABLE_CR_CASES if ( rs_x == 1 && rs_y == 1 ) { for ( dim_t jj = 0; jj < n; ++jj ) for ( dim_t ii = 0; ii < m; ++ii ) bli_zzcopys( *(x + ii + jj*cs_x), *(y + ii + jj*cs_y) ); } else if ( cs_x == 1 && cs_y == 1 ) { for ( dim_t ii = 0; ii < m; ++ii ) for ( dim_t jj = 0; jj < n; ++jj ) bli_zzcopys( *(x + ii*rs_x + jj), *(y + ii*rs_y + jj) ); } else #endif { for ( dim_t jj = 0; jj < n; ++jj ) for ( dim_t ii = 0; ii < m; ++ii ) bli_zzcopys( *(x + ii*rs_x + jj*cs_x), *(y + ii*rs_y + jj*cs_y) ); } } BLIS_INLINE void bli_scopys_mxn ( const dim_t m, const dim_t n, const float* restrict x, const inc_t rs_x, const inc_t cs_x, float* restrict y, const inc_t rs_y, const inc_t cs_y ) { bli_sscopys_mxn( m, n, x, rs_x, cs_x, y, rs_y, cs_y ); } BLIS_INLINE void bli_dcopys_mxn ( const dim_t m, const dim_t n, const double* restrict x, const inc_t rs_x, const inc_t cs_x, double* restrict y, const inc_t rs_y, const inc_t cs_y ) { bli_ddcopys_mxn( m, n, x, rs_x, cs_x, y, rs_y, cs_y ); } BLIS_INLINE void bli_ccopys_mxn ( const dim_t m, const dim_t n, const scomplex* restrict x, const inc_t rs_x, const inc_t cs_x, scomplex* restrict y, const inc_t rs_y, const inc_t cs_y ) { bli_cccopys_mxn( m, n, x, rs_x, cs_x, y, rs_y, cs_y ); } BLIS_INLINE void bli_zcopys_mxn ( const dim_t m, const dim_t n, const dcomplex* restrict x, const inc_t rs_x, const inc_t cs_x, dcomplex* restrict y, const inc_t rs_y, const inc_t cs_y ) { bli_zzcopys_mxn( m, n, x, rs_x, cs_x, y, rs_y, cs_y ); } #endif #endif
1b077146e7ab278e0dd118945a89a7e22d683825
99bdb3251fecee538e0630f15f6574054dfc1468
/bsp/ti/c28x/libraries/tms320f28379d/headers/include/F2837xD_ecap.h
1fdeb15ec32cfd20ce5be777a1098690e48e1ca3
[ "Zlib", "LicenseRef-scancode-proprietary-license", "MIT", "BSD-3-Clause", "X11", "BSD-4-Clause-UC", "LicenseRef-scancode-unknown-license-reference", "Apache-2.0" ]
permissive
RT-Thread/rt-thread
03a7c52c2aeb1b06a544143b0e803d72f47d1ece
3602f891211904a27dcbd51e5ba72fefce7326b2
refs/heads/master
2023-09-01T04:10:20.295801
2023-08-31T16:20:55
2023-08-31T16:20:55
7,408,108
9,599
5,805
Apache-2.0
2023-09-14T13:37:26
2013-01-02T14:49:21
C
UTF-8
C
false
false
9,613
h
F2837xD_ecap.h
//########################################################################### // // FILE: F2837xD_ecap.h // // TITLE: ECAP Register Definitions. // //########################################################################### // $TI Release: F2837xD Support Library v3.05.00.00 $ // $Release Date: Tue Jun 26 03:15:23 CDT 2018 $ // $Copyright: // Copyright (C) 2013-2018 Texas Instruments Incorporated - http://www.ti.com/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions // are met: // // Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the // distribution. // // Neither the name of Texas Instruments Incorporated nor the names of // its contributors may be used to endorse or promote products derived // from this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // $ //########################################################################### #ifndef __F2837xD_ECAP_H__ #define __F2837xD_ECAP_H__ #ifdef __cplusplus extern "C" { #endif //--------------------------------------------------------------------------- // ECAP Individual Register Bit Definitions: struct ECCTL1_BITS { // bits description Uint16 CAP1POL:1; // 0 Capture Event 1 Polarity select Uint16 CTRRST1:1; // 1 Counter Reset on Capture Event 1 Uint16 CAP2POL:1; // 2 Capture Event 2 Polarity select Uint16 CTRRST2:1; // 3 Counter Reset on Capture Event 2 Uint16 CAP3POL:1; // 4 Capture Event 3 Polarity select Uint16 CTRRST3:1; // 5 Counter Reset on Capture Event 3 Uint16 CAP4POL:1; // 6 Capture Event 4 Polarity select Uint16 CTRRST4:1; // 7 Counter Reset on Capture Event 4 Uint16 CAPLDEN:1; // 8 Enable Loading CAP1-4 regs on a Cap Event Uint16 PRESCALE:5; // 13:9 Event Filter prescale select Uint16 FREE_SOFT:2; // 15:14 Emulation mode }; union ECCTL1_REG { Uint16 all; struct ECCTL1_BITS bit; }; struct ECCTL2_BITS { // bits description Uint16 CONT_ONESHT:1; // 0 Continuous or one-shot Uint16 STOP_WRAP:2; // 2:1 Stop value for one-shot, Wrap for continuous Uint16 REARM:1; // 3 One-shot re-arm Uint16 TSCTRSTOP:1; // 4 TSCNT counter stop Uint16 SYNCI_EN:1; // 5 Counter sync-in select Uint16 SYNCO_SEL:2; // 7:6 Sync-out mode Uint16 SWSYNC:1; // 8 SW forced counter sync Uint16 CAP_APWM:1; // 9 CAP/APWM operating mode select Uint16 APWMPOL:1; // 10 APWM output polarity select Uint16 rsvd1:5; // 15:11 Reserved }; union ECCTL2_REG { Uint16 all; struct ECCTL2_BITS bit; }; struct ECEINT_BITS { // bits description Uint16 rsvd1:1; // 0 Reserved Uint16 CEVT1:1; // 1 Capture Event 1 Interrupt Enable Uint16 CEVT2:1; // 2 Capture Event 2 Interrupt Enable Uint16 CEVT3:1; // 3 Capture Event 3 Interrupt Enable Uint16 CEVT4:1; // 4 Capture Event 4 Interrupt Enable Uint16 CTROVF:1; // 5 Counter Overflow Interrupt Enable Uint16 CTR_EQ_PRD:1; // 6 Period Equal Interrupt Enable Uint16 CTR_EQ_CMP:1; // 7 Compare Equal Interrupt Enable Uint16 rsvd2:8; // 15:8 Reserved }; union ECEINT_REG { Uint16 all; struct ECEINT_BITS bit; }; struct ECFLG_BITS { // bits description Uint16 INT:1; // 0 Global Flag Uint16 CEVT1:1; // 1 Capture Event 1 Interrupt Flag Uint16 CEVT2:1; // 2 Capture Event 2 Interrupt Flag Uint16 CEVT3:1; // 3 Capture Event 3 Interrupt Flag Uint16 CEVT4:1; // 4 Capture Event 4 Interrupt Flag Uint16 CTROVF:1; // 5 Counter Overflow Interrupt Flag Uint16 CTR_PRD:1; // 6 Period Equal Interrupt Flag Uint16 CTR_CMP:1; // 7 Compare Equal Interrupt Flag Uint16 rsvd1:8; // 15:8 Reserved }; union ECFLG_REG { Uint16 all; struct ECFLG_BITS bit; }; struct ECCLR_BITS { // bits description Uint16 INT:1; // 0 ECAP Global Interrupt Status Clear Uint16 CEVT1:1; // 1 Capture Event 1 Status Clear Uint16 CEVT2:1; // 2 Capture Event 2 Status Clear Uint16 CEVT3:1; // 3 Capture Event 3 Status Clear Uint16 CEVT4:1; // 4 Capture Event 4 Status Clear Uint16 CTROVF:1; // 5 Counter Overflow Status Clear Uint16 CTR_PRD:1; // 6 Period Equal Status Clear Uint16 CTR_CMP:1; // 7 Compare Equal Status Clear Uint16 rsvd1:8; // 15:8 Reserved }; union ECCLR_REG { Uint16 all; struct ECCLR_BITS bit; }; struct ECFRC_BITS { // bits description Uint16 rsvd1:1; // 0 Reserved Uint16 CEVT1:1; // 1 Capture Event 1 Force Interrupt Uint16 CEVT2:1; // 2 Capture Event 2 Force Interrupt Uint16 CEVT3:1; // 3 Capture Event 3 Force Interrupt Uint16 CEVT4:1; // 4 Capture Event 4 Force Interrupt Uint16 CTROVF:1; // 5 Counter Overflow Force Interrupt Uint16 CTR_PRD:1; // 6 Period Equal Force Interrupt Uint16 CTR_CMP:1; // 7 Compare Equal Force Interrupt Uint16 rsvd2:8; // 15:8 Reserved }; union ECFRC_REG { Uint16 all; struct ECFRC_BITS bit; }; struct ECAP_REGS { Uint32 TSCTR; // Time-Stamp Counter Uint32 CTRPHS; // Counter Phase Offset Value Register Uint32 CAP1; // Capture 1 Register Uint32 CAP2; // Capture 2 Register Uint32 CAP3; // Capture 3 Register Uint32 CAP4; // Capture 4 Register Uint16 rsvd1[8]; // Reserved union ECCTL1_REG ECCTL1; // Capture Control Register 1 union ECCTL2_REG ECCTL2; // Capture Control Register 2 union ECEINT_REG ECEINT; // Capture Interrupt Enable Register union ECFLG_REG ECFLG; // Capture Interrupt Flag Register union ECCLR_REG ECCLR; // Capture Interrupt Clear Register union ECFRC_REG ECFRC; // Capture Interrupt Force Register Uint16 rsvd2[6]; // Reserved }; //--------------------------------------------------------------------------- // ECAP External References & Function Declarations: // #ifdef CPU1 extern volatile struct ECAP_REGS ECap1Regs; extern volatile struct ECAP_REGS ECap2Regs; extern volatile struct ECAP_REGS ECap3Regs; extern volatile struct ECAP_REGS ECap4Regs; extern volatile struct ECAP_REGS ECap5Regs; extern volatile struct ECAP_REGS ECap6Regs; #endif #ifdef CPU2 extern volatile struct ECAP_REGS ECap1Regs; extern volatile struct ECAP_REGS ECap2Regs; extern volatile struct ECAP_REGS ECap3Regs; extern volatile struct ECAP_REGS ECap4Regs; extern volatile struct ECAP_REGS ECap5Regs; extern volatile struct ECAP_REGS ECap6Regs; #endif #ifdef __cplusplus } #endif /* extern "C" */ #endif //=========================================================================== // End of file. //===========================================================================
1c02bdf9c7e66aa72dad5959837dffddc76f6493
24acbcc7b5ad20d2cea61b2b2b8190befe7f5bce
/Blogs/src/algs/blog/welcome/sample.c
9a6f5af41d84b12e49b2c7e9316bf8401e33850b
[ "MIT" ]
permissive
heineman/algorithms-nutshell-2ed
a08e2136fb3f9199e119a8aebca1be09a02b86f4
6bdaf7ee2878f69a2df00ae7a3274f5d43d24605
refs/heads/master
2022-09-04T20:53:52.422824
2021-12-29T02:34:44
2021-12-29T02:34:44
43,086,309
577
226
null
null
null
null
UTF-8
C
false
false
1,519
c
sample.c
#include <stdio.h> #include <string.h> #include <stdlib.h> /** Max line size. */ #define MAX 1024 #ifdef COUNT /** Must define here since we don't use default reporting. */ long __swapTotal = 0; #endif /* COUNT */ /** Enable strcmp to be the comparison function. */ extern void sortPointers (void **, int, int(*cmp)(const char *,const char *)); /** * Sample program to load the contents of a file (supplied * by the user) and sort it. The result is then written to * standard output. * * Each input line is terminated by a '\n' character. No * single line of input exceeds a fixed MAX amount. If it * does, the line is split into multiple input lines. */ int main (int argc, char **argv) { char buf[MAX]; FILE *in; void **ptrs; int size = 1000; int count = 0; int i; if (argc < 2) { printf ("Usage: %s InFile\n", argv[0]); exit (1); } in = fopen (argv[1], "r"); if (in == NULL) { printf ("Unable to open input file %s\n", argv[1]); exit (1); } /** Allocate an initial batch. */ ptrs = malloc (size*sizeof(char *)); while (fgets(buf, MAX, in) != NULL) { ptrs[count++] = strdup (buf); /** When capacity fills, double and keep going on... */ if (count == size) { ptrs = realloc (ptrs, (size*2)*sizeof(char *)); size = size*2; } } fclose(in); /* Use sortPtrs interface using strcmp. */ sortPointers (ptrs, count, strcmp); for (i = 0; i < count; i++) { fputs(ptrs[i], stdout); } return 0; }
088b5d41114dd7e6234c92ecd287192f20f6f834
3a30cfb29aac91e5c75d4dbcefddfd1f34d5f18c
/c-tests/gcc/921218-1.c
e44ef44e7522a6655fb53fc18b4540aefbc2d80c
[ "MIT", "MPL-1.0", "LicenseRef-scancode-warranty-disclaimer", "Apache-2.0", "LGPL-2.0-only", "GPL-3.0-only", "GPL-2.0-only" ]
permissive
vnmakarov/mir
a1725bc9c828e8580df6b7ae94e04175db8abe93
928e28fb3acaa50d051a906e76a55cc48a556574
refs/heads/master
2023-09-02T11:10:37.434581
2023-08-25T19:25:40
2023-08-25T19:25:40
178,932,492
2,005
156
MIT
2023-08-01T20:29:59
2019-04-01T19:24:56
C
UTF-8
C
false
false
142
c
921218-1.c
extern void exit (int); f() { return (unsigned char)("\377"[0]); } main() { if (f() != (unsigned char)(0377)) abort(); exit (0); }
650b29812704b6a40145222b9658df6130cca68c
e73547787354afd9b717ea57fe8dd0695d161821
/src/world/area_mac/mac_04/mac_04_0_header.c
cee4a8357c26ed54f76121e7b43dfec4f1764110
[]
no_license
pmret/papermario
8b514b19653cef8d6145e47499b3636b8c474a37
9774b26d93f1045dd2a67e502b6efc9599fb6c31
refs/heads/main
2023-08-31T07:09:48.951514
2023-08-21T18:07:08
2023-08-21T18:07:08
287,151,133
904
139
null
2023-09-14T02:44:23
2020-08-13T01:22:57
C
UTF-8
C
false
false
766
c
mac_04_0_header.c
#include "mac_04.h" EntryList N(Entrances) = { [mac_04_ENTRY_0] { 610.0, 0.0, 0.0, 280.0 }, [mac_04_ENTRY_1] { -420.0, 0.0, 430.0, 35.0 }, [mac_04_ENTRY_2] { -490.0, 20.0, -150.0, 180.0 }, [mac_04_ENTRY_3] { -420.0, 20.0, -95.0, 0.0 }, [mac_04_ENTRY_4] { 0.0, -100.0, 0.0, 0.0 }, [mac_04_ENTRY_5] { -420.0, 20.0, 235.0, 270.0 }, }; MapSettings N(settings) = { .main = &N(EVS_Main), .entryList = &N(Entrances), .entryCount = ENTRY_COUNT(N(Entrances)), .background = &gBackgroundImage, .tattle = { MSG_MapTattle_mac_04 }, }; s32 N(map_init)(void) { if (gGameStatusPtr->entryID == mac_04_ENTRY_4) { sprintf(wMapBgName, "hos_bg"); } return FALSE; }
3a1ed1262fad895c8582893f5d28d55d3c451274
e8b04bef9aa1ac8e2c109dd315f133c8f4d28ae6
/include/ode/ode/common.h
0308ff7af61e9a042b8540a0e59f7ef453d40deb
[ "Apache-2.0" ]
permissive
cyberbotics/webots
f075dacf4067e8dcebbfd89e8690df8525f6d745
8aba6eaae76989facf3442305c8089d3cc366bcf
refs/heads/master
2023-08-31T09:41:13.205940
2023-08-18T10:48:30
2023-08-18T10:48:30
156,228,018
2,495
1,525
Apache-2.0
2023-08-28T16:30:33
2018-11-05T14:09:10
C++
UTF-8
C
false
false
11,086
h
common.h
/************************************************************************* * * * Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. * * All rights reserved. Email: russ@q12.org Web: www.q12.org * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of EITHER: * * (1) The GNU Lesser General Public License as published by the Free * * Software Foundation; either version 2.1 of the License, or (at * * your option) any later version. The text of the GNU Lesser * * General Public License is included with this library in the * * file LICENSE.TXT. * * (2) The BSD-style license that is included with this library in * * the file LICENSE-BSD.TXT. * * * * This library is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files * * LICENSE.TXT and LICENSE-BSD.TXT for more details. * * * *************************************************************************/ #ifndef _ODE_COMMON_H_ #define _ODE_COMMON_H_ #include <ode/odeconfig.h> #include <ode/error.h> #ifdef __cplusplus extern "C" { #endif /* configuration stuff */ /* constants */ /* pi and 1/sqrt(2) are defined here if necessary because they don't get * defined in <math.h> on some platforms (like MS-Windows) */ #ifndef M_PI #define M_PI REAL(3.1415926535897932384626433832795029) #endif #ifndef M_PI_2 #define M_PI_2 REAL(1.5707963267948966192313216916398) #endif #ifndef M_SQRT1_2 #define M_SQRT1_2 REAL(0.7071067811865475244008443621048490) #endif /* floating point data type, vector, matrix and quaternion types */ #if defined(dSINGLE) typedef float dReal; #ifdef dDOUBLE #error You can only #define dSINGLE or dDOUBLE, not both. #endif /* dDOUBLE */ #elif defined(dDOUBLE) typedef double dReal; #else #error You must #define dSINGLE or dDOUBLE #endif /* Detect if we've got both trimesh engines enabled. */ #if dTRIMESH_ENABLED #if dTRIMESH_OPCODE && dTRIMESH_GIMPACT #error You can only #define dTRIMESH_OPCODE or dTRIMESH_GIMPACT, not both. #endif #endif /* dTRIMESH_ENABLED */ /* * Define a type for indices, either 16 or 32 bit, based on build option * TODO: Currently GIMPACT only supports 32 bit indices. */ #if dTRIMESH_16BIT_INDICES #if dTRIMESH_GIMPACT typedef duint32 dTriIndex; #else /* dTRIMESH_GIMPACT */ typedef duint16 dTriIndex; #endif /* dTRIMESH_GIMPACT */ #else /* dTRIMESH_16BIT_INDICES */ typedef duint32 dTriIndex; #endif /* dTRIMESH_16BIT_INDICES */ /* round an integer up to a multiple of 4, except that 0 and 1 are unmodified * (used to compute matrix leading dimensions) */ #define dPAD(a) (((a) > 1) ? ((((a)-1)|3)+1) : (a)) /* these types are mainly just used in headers */ typedef dReal dVector3[4]; typedef dReal dVector4[4]; typedef dReal dMatrix3[4*3]; typedef dReal dMatrix4[4*4]; typedef dReal dMatrix6[8*6]; typedef dReal dQuaternion[4]; /* precision dependent scalar math functions */ #if defined(dSINGLE) #define REAL(x) (x##f) /* form a constant */ #define dRecip(x) ((1.0f/(x))) /* reciprocal */ #define dSqrt(x) (sqrtf(x)) /* square root */ #define dRecipSqrt(x) ((1.0f/sqrtf(x))) /* reciprocal square root */ #define dSin(x) (sinf(x)) /* sine */ #define dCos(x) (cosf(x)) /* cosine */ #define dFabs(x) (fabsf(x)) /* absolute value */ #define dAtan2(y,x) (atan2f(y,x)) /* arc tangent with 2 args */ #define dAcos(x) (acosf(x)) #define dFMod(a,b) (fmodf(a,b)) /* modulo */ #define dFloor(x) floorf(x) /* floor */ #define dCeil(x) ceilf(x) /* ceil */ #define dCopySign(a,b) _ode_copysignf(a, b) /* copy value sign */ #define dNextAfter(x, y) _ode_nextafterf(x, y) /* next value after */ #ifdef HAVE___ISNANF #define dIsNan(x) (__isnanf(x)) #elif defined(HAVE__ISNANF) #define dIsNan(x) (_isnanf(x)) #elif defined(HAVE_ISNANF) #define dIsNan(x) (isnanf(x)) #else /* fall back to _isnan which is the VC way, this may seem redundant since we already checked for _isnan before, but if isnan is detected by configure but is not found during compilation we should always make sure we check for __isnanf, _isnanf and isnanf in that order before falling back to a default */ #define dIsNan(x) (_isnan(x)) #endif #elif defined(dDOUBLE) #define REAL(x) (x) #define dRecip(x) (1.0/(x)) #define dSqrt(x) sqrt(x) #define dRecipSqrt(x) (1.0/sqrt(x)) #define dSin(x) sin(x) #define dCos(x) cos(x) #define dFabs(x) fabs(x) #define dAtan2(y,x) atan2((y),(x)) #define dAcos(x) acos(x) #define dFMod(a,b) (fmod((a),(b))) #define dFloor(x) floor(x) #define dCeil(x) ceil(x) #define dCopySign(a,b) _ode_copysign(a, b) #define dNextAfter(x, y) _ode_nextafter(x, y) #define dMax(a, b) ((a) > (b) ? (a) : (b)) #define dMin(a, b) ((a) > (b) ? (b) : (a)) #ifdef HAVE___ISNAN #define dIsNan(x) (__isnan(x)) #elif defined(HAVE__ISNAN) #define dIsNan(x) (_isnan(x)) #elif defined(HAVE_ISNAN) #define dIsNan(x) (isnan(x)) #else #define dIsNan(x) (_isnan(x)) #endif #else #error You must #define dSINGLE or dDOUBLE #endif /* internal object types (all prefixed with `dx') */ struct dxWorld; /* dynamics world */ struct dxSpace; /* collision space */ struct dxBody; /* rigid body (dynamics object) */ struct dxGeom; /* geometry (collision object) */ struct dxJoint; struct dxJointNode; struct dxJointGroup; struct dxWorldProcessThreadingManager; typedef struct dxWorld *dWorldID; typedef struct dxSpace *dSpaceID; typedef struct dxBody *dBodyID; typedef struct dxGeom *dGeomID; typedef struct dxJoint *dJointID; typedef struct dxJointGroup *dJointGroupID; typedef struct dxWorldProcessThreadingManager *dWorldStepThreadingManagerID; /* error numbers */ enum { d_ERR_UNKNOWN = 0, /* unknown error */ d_ERR_IASSERT, /* internal assertion failed */ d_ERR_UASSERT, /* user assertion failed */ d_ERR_LCP /* user assertion failed */ }; /* joint type numbers */ typedef enum { dJointTypeNone = 0, /* or "unknown" */ dJointTypeBall, dJointTypeHinge, dJointTypeSlider, dJointTypeContact, dJointTypeUniversal, dJointTypeHinge2, dJointTypeFixed, dJointTypeNull, dJointTypeAMotor, dJointTypeLMotor, dJointTypePlane2D, dJointTypePR, dJointTypePU, dJointTypePiston, dJointTypeDBall, dJointTypeDHinge, dJointTypeTransmission, } dJointType; /* an alternative way of setting joint parameters, using joint parameter * structures and member constants. we don't actually do this yet. */ /* typedef struct dLimot { int mode; dReal lostop, histop; dReal vel, fmax; dReal fudge_factor; dReal bounce, soft; dReal suspension_erp, suspension_cfm; } dLimot; enum { dLimotLoStop = 0x0001, dLimotHiStop = 0x0002, dLimotVel = 0x0004, dLimotFMax = 0x0008, dLimotFudgeFactor = 0x0010, dLimotBounce = 0x0020, dLimotSoft = 0x0040 }; */ /* standard joint parameter names. why are these here? - because we don't want * to include all the joint function definitions in joint.cpp. hmmmm. * MSVC complains if we call D_ALL_PARAM_NAMES_X with a blank second argument, * which is why we have the D_ALL_PARAM_NAMES macro as well. please copy and * paste between these two. */ #define D_ALL_PARAM_NAMES(start) \ /* parameters for limits and motors */ \ dParamLoStop = start, \ dParamHiStop, \ dParamVel, \ dParamLoVel, \ dParamHiVel, \ dParamFMax, \ dParamFudgeFactor, \ dParamBounce, \ dParamCFM, \ dParamStopERP, \ dParamStopCFM, \ /* parameters for suspension */ \ dParamSuspensionERP, \ dParamSuspensionCFM, \ dParamERP, \ /* * \enum D_ALL_PARAM_NAMES_X * * \var dParamGroup This is the starting value of the different group * (i.e. dParamGroup1, dParamGroup2, dParamGroup3) * It also helps in the use of parameter * (dParamGroup2 | dParamFMax) == dParamFMax2 */ #define D_ALL_PARAM_NAMES_X(start,x) \ dParamGroup ## x = start, \ /* parameters for limits and motors */ \ dParamLoStop ## x = start, \ dParamHiStop ## x, \ dParamVel ## x, \ dParamLoVel ## x, \ dParamHiVel ## x, \ dParamFMax ## x, \ dParamFudgeFactor ## x, \ dParamBounce ## x, \ dParamCFM ## x, \ dParamStopERP ## x, \ dParamStopCFM ## x, \ /* parameters for suspension */ \ dParamSuspensionERP ## x, \ dParamSuspensionCFM ## x, \ dParamERP ## x, enum { D_ALL_PARAM_NAMES(0) dParamsInGroup, /* < Number of parameter in a group */ D_ALL_PARAM_NAMES_X(0x000,1) D_ALL_PARAM_NAMES_X(0x100,2) D_ALL_PARAM_NAMES_X(0x200,3) /* add a multiple of this constant to the basic parameter numbers to get * the parameters for the second, third etc axes. */ dParamGroup=0x100 }; /* angular motor mode numbers */ enum { dAMotorUser = 0, dAMotorEuler = 1 }; /* transmission joint mode numbers */ enum { dTransmissionParallelAxes = 0, dTransmissionIntersectingAxes = 1, dTransmissionChainDrive = 2 }; /* joint force feedback information */ typedef struct dJointFeedback { dVector3 f1; /* force applied to body 1 */ dVector3 t1; /* torque applied to body 1 */ dVector3 f2; /* force applied to body 2 */ dVector3 t2; /* torque applied to body 2 */ } dJointFeedback; /* private functions that must be implemented by the collision library: * (1) indicate that a geom has moved, (2) get the next geom in a body list. * these functions are called whenever the position of geoms connected to a * body have changed, e.g. with dBodySetPosition(), dBodySetRotation(), or * when the ODE step function updates the body state. */ void dGeomMoved (dGeomID); dGeomID dGeomGetBodyNext (dGeomID); /** * dGetConfiguration returns the specific ODE build configuration as * a string of tokens. The string can be parsed in a similar way to * the OpenGL extension mechanism, the naming convention should be * familiar too. The following extensions are reported: * * ODE * ODE_single_precision * ODE_double_precision * ODE_EXT_no_debug * ODE_EXT_trimesh * ODE_EXT_opcode * ODE_EXT_gimpact * ODE_OPC_16bit_indices * ODE_OPC_new_collider * ODE_EXT_mt_collisions * ODE_EXT_threading * ODE_THR_builtin_impl */ ODE_API const char* dGetConfiguration (void); /** * Helper to check for a token in the ODE configuration string. * Caution, this function is case sensitive. * * @param token A configuration token, see dGetConfiguration for details * * @return 1 if exact token is present, 0 if not present */ ODE_API int dCheckConfiguration( const char* token ); #ifdef __cplusplus } #endif #endif
604266f7eb0ee25ce3d03e7da94afa8bb02ccb52
c474663ca0eb361b191e5462f484cd936f0930b2
/d3drend/surftype.h
2ed9aa03f3f32aba33a76fa02cf516a5a84f5e9a
[ "MIT" ]
permissive
foone/BRender-1997
bc0ea2b170305d18e8b8f573724e27913b39c5a5
4e319d61ee474cc5536ef52fe254c2d327d5ea98
refs/heads/main
2023-08-13T01:59:56.422996
2022-05-03T21:29:09
2022-05-03T21:31:40
488,368,857
134
12
null
null
null
null
UTF-8
C
false
false
360
h
surftype.h
/* * Copyright (c) 1993-1995 Argonaut Technologies Limited. All rights reserved. * * $Id: surftype.h 1.1 1997/07/29 14:52:49 jon Exp JON $ * $Locker: JON $ * * Useful routines for dealing with BRender and DirectDraw pixel formats */ #ifndef _SURFTYPE_H_ #define _SURFTYPE_H_ #ifdef __cplusplus extern "C" { #endif #ifdef __cplusplus } #endif #endif
fcc1aa95dd5cc4ede20a1a3f76dbec6d2beaa8fb
0744dcc5394cebf57ebcba343747af6871b67017
/os/arch/arm/src/imxrt/usb/host/usb_host_ehci.h
d51621d4ea77e3a16e43ff3046db395175f283e5
[ "GPL-1.0-or-later", "BSD-3-Clause", "ISC", "MIT", "LicenseRef-scancode-warranty-disclaimer", "LicenseRef-scancode-other-permissive", "Apache-2.0" ]
permissive
Samsung/TizenRT
96abf62f1853f61fcf91ff14671a5e0c6ca48fdb
1a5c2e00a4b1bbf4c505bbf5cc6a8259e926f686
refs/heads/master
2023-08-31T08:59:33.327998
2023-08-08T06:09:20
2023-08-31T04:38:20
82,517,252
590
719
Apache-2.0
2023-09-14T06:54:49
2017-02-20T04:38:30
C
UTF-8
C
false
false
237,667
h
usb_host_ehci.h
/* * Copyright (c) 2015, Freescale Semiconductor, Inc. * Copyright 2016,2019 NXP * All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ #ifndef _USB_HOST_CONTROLLER_EHCI_H_ #define _USB_HOST_CONTROLLER_EHCI_H_ #include "usb_host_config.h" #include <stdint.h> #include "usb_host.h" /*! * @addtogroup USB_Peripheral_Access_Layer USB Peripheral Access Layer * @{ */ /** USB - Register Layout Typedef */ typedef struct { volatile const uint32_t ID; /**< Identification register, offset: 0x0 */ volatile const uint32_t HWGENERAL; /**< Hardware General, offset: 0x4 */ volatile const uint32_t HWHOST; /**< Host Hardware Parameters, offset: 0x8 */ volatile const uint32_t HWDEVICE; /**< Device Hardware Parameters, offset: 0xC */ volatile const uint32_t HWTXBUF; /**< TX Buffer Hardware Parameters, offset: 0x10 */ volatile const uint32_t HWRXBUF; /**< RX Buffer Hardware Parameters, offset: 0x14 */ uint8_t RESERVED_0[104]; volatile uint32_t GPTIMER0LD; /**< General Purpose Timer #0 Load, offset: 0x80 */ volatile uint32_t GPTIMER0CTRL; /**< General Purpose Timer #0 Controller, offset: 0x84 */ volatile uint32_t GPTIMER1LD; /**< General Purpose Timer #1 Load, offset: 0x88 */ volatile uint32_t GPTIMER1CTRL; /**< General Purpose Timer #1 Controller, offset: 0x8C */ volatile uint32_t SBUSCFG; /**< System Bus Config, offset: 0x90 */ uint8_t RESERVED_1[108]; volatile const uint8_t CAPLENGTH; /**< Capability Registers Length, offset: 0x100 */ uint8_t RESERVED_2[1]; volatile const uint16_t HCIVERSION; /**< Host Controller Interface Version, offset: 0x102 */ volatile const uint32_t HCSPARAMS; /**< Host Controller Structural Parameters, offset: 0x104 */ volatile const uint32_t HCCPARAMS; /**< Host Controller Capability Parameters, offset: 0x108 */ uint8_t RESERVED_3[20]; volatile const uint16_t DCIVERSION; /**< Device Controller Interface Version, offset: 0x120 */ uint8_t RESERVED_4[2]; volatile const uint32_t DCCPARAMS; /**< Device Controller Capability Parameters, offset: 0x124 */ uint8_t RESERVED_5[24]; volatile uint32_t USBCMD; /**< USB Command Register, offset: 0x140 */ volatile uint32_t USBSTS; /**< USB Status Register, offset: 0x144 */ volatile uint32_t USBINTR; /**< Interrupt Enable Register, offset: 0x148 */ volatile uint32_t FRINDEX; /**< USB Frame Index, offset: 0x14C */ uint8_t RESERVED_6[4]; union { /* offset: 0x154 */ volatile uint32_t DEVICEADDR; /**< Device Address, offset: 0x154 */ volatile uint32_t PERIODICLISTBASE; /**< Frame List Base Address, offset: 0x154 */ }; union { /* offset: 0x158 */ volatile uint32_t ASYNCLISTADDR; /**< Next Asynch. Address, offset: 0x158 */ volatile uint32_t ENDPTLISTADDR; /**< Endpoint List Address, offset: 0x158 */ }; uint8_t RESERVED_7[4]; volatile uint32_t BURSTSIZE; /**< Programmable Burst Size, offset: 0x160 */ volatile uint32_t TXFILLTUNING; /**< TX FIFO Fill Tuning, offset: 0x164 */ uint8_t RESERVED_8[16]; volatile uint32_t ENDPTNAK; /**< Endpoint NAK, offset: 0x178 */ volatile uint32_t ENDPTNAKEN; /**< Endpoint NAK Enable, offset: 0x17C */ volatile const uint32_t CONFIGFLAG; /**< Configure Flag Register, offset: 0x180 */ volatile uint32_t PORTSC1; /**< Port Status & Control, offset: 0x184 */ uint8_t RESERVED_9[28]; volatile uint32_t OTGSC; /**< On-The-Go Status & control, offset: 0x1A4 */ volatile uint32_t USBMODE; /**< USB Device Mode, offset: 0x1A8 */ volatile uint32_t ENDPTSETUPSTAT; /**< Endpoint Setup Status, offset: 0x1AC */ volatile uint32_t ENDPTPRIME; /**< Endpoint Prime, offset: 0x1B0 */ volatile uint32_t ENDPTFLUSH; /**< Endpoint Flush, offset: 0x1B4 */ volatile const uint32_t ENDPTSTAT; /**< Endpoint Status, offset: 0x1B8 */ volatile uint32_t ENDPTCOMPLETE; /**< Endpoint Complete, offset: 0x1BC */ volatile uint32_t ENDPTCTRL0; /**< Endpoint Control0, offset: 0x1C0 */ volatile uint32_t ENDPTCTRL[7]; /**< Endpoint Control 1..Endpoint Control 7, array offset: 0x1C4, array step: 0x4 */ } imxrt1020_usb; /** Peripheral USB base address */ #define IMXRT1020_USB_BASE (0x402E0000u) #define IMXRT1020_USB ((imxrt1020_usb *)IMXRT1020_USB_BASE) /** Peripheral USB base pointer */ /* ---------------------------------------------------------------------------- -- USB Register Masks ---------------------------------------------------------------------------- */ /*! * @addtogroup USB_Register_Masks USB Register Masks * @{ */ /*! @name ID - Identification register */ /*! @{ */ #define USB_ID_ID_MASK (0x3FU) #define USB_ID_ID_SHIFT (0U) #define USB_ID_ID(x) (((uint32_t)(((uint32_t)(x)) << USB_ID_ID_SHIFT)) & USB_ID_ID_MASK) #define USB_ID_NID_MASK (0x3F00U) #define USB_ID_NID_SHIFT (8U) #define USB_ID_NID(x) (((uint32_t)(((uint32_t)(x)) << USB_ID_NID_SHIFT)) & USB_ID_NID_MASK) #define USB_ID_REVISION_MASK (0xFF0000U) #define USB_ID_REVISION_SHIFT (16U) #define USB_ID_REVISION(x) (((uint32_t)(((uint32_t)(x)) << USB_ID_REVISION_SHIFT)) & USB_ID_REVISION_MASK) /*! @} */ /*! @name HWGENERAL - Hardware General */ /*! @{ */ #define USB_HWGENERAL_PHYW_MASK (0x30U) #define USB_HWGENERAL_PHYW_SHIFT (4U) /*! PHYW * 0b00..8 bit wide data bus Software non-programmable * 0b01..16 bit wide data bus Software non-programmable * 0b10..Reset to 8 bit wide data bus Software programmable * 0b11..Reset to 16 bit wide data bus Software programmable */ #define USB_HWGENERAL_PHYW(x) (((uint32_t)(((uint32_t)(x)) << USB_HWGENERAL_PHYW_SHIFT)) & USB_HWGENERAL_PHYW_MASK) #define USB_HWGENERAL_PHYM_MASK (0x1C0U) #define USB_HWGENERAL_PHYM_SHIFT (6U) /*! PHYM * 0b000..UTMI/UMTI+ * 0b001..ULPI DDR * 0b010..ULPI * 0b011..Serial Only * 0b100..Software programmable - reset to UTMI/UTMI+ * 0b101..Software programmable - reset to ULPI DDR * 0b110..Software programmable - reset to ULPI * 0b111..Software programmable - reset to Serial */ #define USB_HWGENERAL_PHYM(x) (((uint32_t)(((uint32_t)(x)) << USB_HWGENERAL_PHYM_SHIFT)) & USB_HWGENERAL_PHYM_MASK) #define USB_HWGENERAL_SM_MASK (0x600U) #define USB_HWGENERAL_SM_SHIFT (9U) /*! SM * 0b00..No Serial Engine, always use parallel signalling. * 0b01..Serial Engine present, always use serial signalling for FS/LS. * 0b10..Software programmable - Reset to use parallel signalling for FS/LS * 0b11..Software programmable - Reset to use serial signalling for FS/LS */ #define USB_HWGENERAL_SM(x) (((uint32_t)(((uint32_t)(x)) << USB_HWGENERAL_SM_SHIFT)) & USB_HWGENERAL_SM_MASK) /*! @} */ /*! @name HWHOST - Host Hardware Parameters */ /*! @{ */ #define USB_HWHOST_HC_MASK (0x1U) #define USB_HWHOST_HC_SHIFT (0U) /*! HC * 0b1..Supported * 0b0..Not supported */ #define USB_HWHOST_HC(x) (((uint32_t)(((uint32_t)(x)) << USB_HWHOST_HC_SHIFT)) & USB_HWHOST_HC_MASK) #define USB_HWHOST_NPORT_MASK (0xEU) #define USB_HWHOST_NPORT_SHIFT (1U) #define USB_HWHOST_NPORT(x) (((uint32_t)(((uint32_t)(x)) << USB_HWHOST_NPORT_SHIFT)) & USB_HWHOST_NPORT_MASK) /*! @} */ /*! @name HWDEVICE - Device Hardware Parameters */ /*! @{ */ #define USB_HWDEVICE_DC_MASK (0x1U) #define USB_HWDEVICE_DC_SHIFT (0U) /*! DC * 0b1..Supported * 0b0..Not supported */ #define USB_HWDEVICE_DC(x) (((uint32_t)(((uint32_t)(x)) << USB_HWDEVICE_DC_SHIFT)) & USB_HWDEVICE_DC_MASK) #define USB_HWDEVICE_DEVEP_MASK (0x3EU) #define USB_HWDEVICE_DEVEP_SHIFT (1U) #define USB_HWDEVICE_DEVEP(x) (((uint32_t)(((uint32_t)(x)) << USB_HWDEVICE_DEVEP_SHIFT)) & USB_HWDEVICE_DEVEP_MASK) /*! @} */ /*! @name HWTXBUF - TX Buffer Hardware Parameters */ /*! @{ */ #define USB_HWTXBUF_TXBURST_MASK (0xFFU) #define USB_HWTXBUF_TXBURST_SHIFT (0U) #define USB_HWTXBUF_TXBURST(x) (((uint32_t)(((uint32_t)(x)) << USB_HWTXBUF_TXBURST_SHIFT)) & USB_HWTXBUF_TXBURST_MASK) #define USB_HWTXBUF_TXCHANADD_MASK (0xFF0000U) #define USB_HWTXBUF_TXCHANADD_SHIFT (16U) #define USB_HWTXBUF_TXCHANADD(x) (((uint32_t)(((uint32_t)(x)) << USB_HWTXBUF_TXCHANADD_SHIFT)) & USB_HWTXBUF_TXCHANADD_MASK) /*! @} */ /*! @name HWRXBUF - RX Buffer Hardware Parameters */ /*! @{ */ #define USB_HWRXBUF_RXBURST_MASK (0xFFU) #define USB_HWRXBUF_RXBURST_SHIFT (0U) #define USB_HWRXBUF_RXBURST(x) (((uint32_t)(((uint32_t)(x)) << USB_HWRXBUF_RXBURST_SHIFT)) & USB_HWRXBUF_RXBURST_MASK) #define USB_HWRXBUF_RXADD_MASK (0xFF00U) #define USB_HWRXBUF_RXADD_SHIFT (8U) #define USB_HWRXBUF_RXADD(x) (((uint32_t)(((uint32_t)(x)) << USB_HWRXBUF_RXADD_SHIFT)) & USB_HWRXBUF_RXADD_MASK) /*! @} */ /*! @name GPTIMER0LD - General Purpose Timer #0 Load */ /*! @{ */ #define USB_GPTIMER0LD_GPTLD_MASK (0xFFFFFFU) #define USB_GPTIMER0LD_GPTLD_SHIFT (0U) #define USB_GPTIMER0LD_GPTLD(x) (((uint32_t)(((uint32_t)(x)) << USB_GPTIMER0LD_GPTLD_SHIFT)) & USB_GPTIMER0LD_GPTLD_MASK) /*! @} */ /*! @name GPTIMER0CTRL - General Purpose Timer #0 Controller */ /*! @{ */ #define USB_GPTIMER0CTRL_GPTCNT_MASK (0xFFFFFFU) #define USB_GPTIMER0CTRL_GPTCNT_SHIFT (0U) #define USB_GPTIMER0CTRL_GPTCNT(x) (((uint32_t)(((uint32_t)(x)) << USB_GPTIMER0CTRL_GPTCNT_SHIFT)) & USB_GPTIMER0CTRL_GPTCNT_MASK) #define USB_GPTIMER0CTRL_GPTMODE_MASK (0x1000000U) #define USB_GPTIMER0CTRL_GPTMODE_SHIFT (24U) /*! GPTMODE * 0b0..One Shot Mode * 0b1..Repeat Mode */ #define USB_GPTIMER0CTRL_GPTMODE(x) (((uint32_t)(((uint32_t)(x)) << USB_GPTIMER0CTRL_GPTMODE_SHIFT)) & USB_GPTIMER0CTRL_GPTMODE_MASK) #define USB_GPTIMER0CTRL_GPTRST_MASK (0x40000000U) #define USB_GPTIMER0CTRL_GPTRST_SHIFT (30U) /*! GPTRST * 0b0..No action * 0b1..Load counter value from GPTLD bits in n_GPTIMER0LD */ #define USB_GPTIMER0CTRL_GPTRST(x) (((uint32_t)(((uint32_t)(x)) << USB_GPTIMER0CTRL_GPTRST_SHIFT)) & USB_GPTIMER0CTRL_GPTRST_MASK) #define USB_GPTIMER0CTRL_GPTRUN_MASK (0x80000000U) #define USB_GPTIMER0CTRL_GPTRUN_SHIFT (31U) /*! GPTRUN * 0b0..Stop counting * 0b1..Run */ #define USB_GPTIMER0CTRL_GPTRUN(x) (((uint32_t)(((uint32_t)(x)) << USB_GPTIMER0CTRL_GPTRUN_SHIFT)) & USB_GPTIMER0CTRL_GPTRUN_MASK) /*! @} */ /*! @name GPTIMER1LD - General Purpose Timer #1 Load */ /*! @{ */ #define USB_GPTIMER1LD_GPTLD_MASK (0xFFFFFFU) #define USB_GPTIMER1LD_GPTLD_SHIFT (0U) #define USB_GPTIMER1LD_GPTLD(x) (((uint32_t)(((uint32_t)(x)) << USB_GPTIMER1LD_GPTLD_SHIFT)) & USB_GPTIMER1LD_GPTLD_MASK) /*! @} */ /*! @name GPTIMER1CTRL - General Purpose Timer #1 Controller */ /*! @{ */ #define USB_GPTIMER1CTRL_GPTCNT_MASK (0xFFFFFFU) #define USB_GPTIMER1CTRL_GPTCNT_SHIFT (0U) #define USB_GPTIMER1CTRL_GPTCNT(x) (((uint32_t)(((uint32_t)(x)) << USB_GPTIMER1CTRL_GPTCNT_SHIFT)) & USB_GPTIMER1CTRL_GPTCNT_MASK) #define USB_GPTIMER1CTRL_GPTMODE_MASK (0x1000000U) #define USB_GPTIMER1CTRL_GPTMODE_SHIFT (24U) /*! GPTMODE * 0b0..One Shot Mode * 0b1..Repeat Mode */ #define USB_GPTIMER1CTRL_GPTMODE(x) (((uint32_t)(((uint32_t)(x)) << USB_GPTIMER1CTRL_GPTMODE_SHIFT)) & USB_GPTIMER1CTRL_GPTMODE_MASK) #define USB_GPTIMER1CTRL_GPTRST_MASK (0x40000000U) #define USB_GPTIMER1CTRL_GPTRST_SHIFT (30U) /*! GPTRST * 0b0..No action * 0b1..Load counter value from GPTLD bits in USB_n_GPTIMER0LD */ #define USB_GPTIMER1CTRL_GPTRST(x) (((uint32_t)(((uint32_t)(x)) << USB_GPTIMER1CTRL_GPTRST_SHIFT)) & USB_GPTIMER1CTRL_GPTRST_MASK) #define USB_GPTIMER1CTRL_GPTRUN_MASK (0x80000000U) #define USB_GPTIMER1CTRL_GPTRUN_SHIFT (31U) /*! GPTRUN * 0b0..Stop counting * 0b1..Run */ #define USB_GPTIMER1CTRL_GPTRUN(x) (((uint32_t)(((uint32_t)(x)) << USB_GPTIMER1CTRL_GPTRUN_SHIFT)) & USB_GPTIMER1CTRL_GPTRUN_MASK) /*! @} */ /*! @name SBUSCFG - System Bus Config */ /*! @{ */ #define USB_SBUSCFG_AHBBRST_MASK (0x7U) #define USB_SBUSCFG_AHBBRST_SHIFT (0U) /*! AHBBRST * 0b000..Incremental burst of unspecified length only * 0b001..INCR4 burst, then single transfer * 0b010..INCR8 burst, INCR4 burst, then single transfer * 0b011..INCR16 burst, INCR8 burst, INCR4 burst, then single transfer * 0b100..Reserved, don't use * 0b101..INCR4 burst, then incremental burst of unspecified length * 0b110..INCR8 burst, INCR4 burst, then incremental burst of unspecified length * 0b111..INCR16 burst, INCR8 burst, INCR4 burst, then incremental burst of unspecified length */ #define USB_SBUSCFG_AHBBRST(x) (((uint32_t)(((uint32_t)(x)) << USB_SBUSCFG_AHBBRST_SHIFT)) & USB_SBUSCFG_AHBBRST_MASK) /*! @} */ /*! @name CAPLENGTH - Capability Registers Length */ /*! @{ */ #define USB_CAPLENGTH_CAPLENGTH_MASK (0xFFU) #define USB_CAPLENGTH_CAPLENGTH_SHIFT (0U) #define USB_CAPLENGTH_CAPLENGTH(x) (((uint8_t)(((uint8_t)(x)) << USB_CAPLENGTH_CAPLENGTH_SHIFT)) & USB_CAPLENGTH_CAPLENGTH_MASK) /*! @} */ /*! @name HCIVERSION - Host Controller Interface Version */ /*! @{ */ #define USB_HCIVERSION_HCIVERSION_MASK (0xFFFFU) #define USB_HCIVERSION_HCIVERSION_SHIFT (0U) #define USB_HCIVERSION_HCIVERSION(x) (((uint16_t)(((uint16_t)(x)) << USB_HCIVERSION_HCIVERSION_SHIFT)) & USB_HCIVERSION_HCIVERSION_MASK) /*! @} */ /*! @name HCSPARAMS - Host Controller Structural Parameters */ /*! @{ */ #define USB_HCSPARAMS_N_PORTS_MASK (0xFU) #define USB_HCSPARAMS_N_PORTS_SHIFT (0U) #define USB_HCSPARAMS_N_PORTS(x) (((uint32_t)(((uint32_t)(x)) << USB_HCSPARAMS_N_PORTS_SHIFT)) & USB_HCSPARAMS_N_PORTS_MASK) #define USB_HCSPARAMS_PPC_MASK (0x10U) #define USB_HCSPARAMS_PPC_SHIFT (4U) #define USB_HCSPARAMS_PPC(x) (((uint32_t)(((uint32_t)(x)) << USB_HCSPARAMS_PPC_SHIFT)) & USB_HCSPARAMS_PPC_MASK) #define USB_HCSPARAMS_N_PCC_MASK (0xF00U) #define USB_HCSPARAMS_N_PCC_SHIFT (8U) #define USB_HCSPARAMS_N_PCC(x) (((uint32_t)(((uint32_t)(x)) << USB_HCSPARAMS_N_PCC_SHIFT)) & USB_HCSPARAMS_N_PCC_MASK) #define USB_HCSPARAMS_N_CC_MASK (0xF000U) #define USB_HCSPARAMS_N_CC_SHIFT (12U) /*! N_CC * 0b0000..There is no internal Companion Controller and port-ownership hand-off is not supported. * 0b0001..There are internal companion controller(s) and port-ownership hand-offs is supported. */ #define USB_HCSPARAMS_N_CC(x) (((uint32_t)(((uint32_t)(x)) << USB_HCSPARAMS_N_CC_SHIFT)) & USB_HCSPARAMS_N_CC_MASK) #define USB_HCSPARAMS_PI_MASK (0x10000U) #define USB_HCSPARAMS_PI_SHIFT (16U) #define USB_HCSPARAMS_PI(x) (((uint32_t)(((uint32_t)(x)) << USB_HCSPARAMS_PI_SHIFT)) & USB_HCSPARAMS_PI_MASK) #define USB_HCSPARAMS_N_PTT_MASK (0xF00000U) #define USB_HCSPARAMS_N_PTT_SHIFT (20U) #define USB_HCSPARAMS_N_PTT(x) (((uint32_t)(((uint32_t)(x)) << USB_HCSPARAMS_N_PTT_SHIFT)) & USB_HCSPARAMS_N_PTT_MASK) #define USB_HCSPARAMS_N_TT_MASK (0xF000000U) #define USB_HCSPARAMS_N_TT_SHIFT (24U) #define USB_HCSPARAMS_N_TT(x) (((uint32_t)(((uint32_t)(x)) << USB_HCSPARAMS_N_TT_SHIFT)) & USB_HCSPARAMS_N_TT_MASK) /*! @} */ /*! @name HCCPARAMS - Host Controller Capability Parameters */ /*! @{ */ #define USB_HCCPARAMS_ADC_MASK (0x1U) #define USB_HCCPARAMS_ADC_SHIFT (0U) #define USB_HCCPARAMS_ADC(x) (((uint32_t)(((uint32_t)(x)) << USB_HCCPARAMS_ADC_SHIFT)) & USB_HCCPARAMS_ADC_MASK) #define USB_HCCPARAMS_PFL_MASK (0x2U) #define USB_HCCPARAMS_PFL_SHIFT (1U) #define USB_HCCPARAMS_PFL(x) (((uint32_t)(((uint32_t)(x)) << USB_HCCPARAMS_PFL_SHIFT)) & USB_HCCPARAMS_PFL_MASK) #define USB_HCCPARAMS_ASP_MASK (0x4U) #define USB_HCCPARAMS_ASP_SHIFT (2U) #define USB_HCCPARAMS_ASP(x) (((uint32_t)(((uint32_t)(x)) << USB_HCCPARAMS_ASP_SHIFT)) & USB_HCCPARAMS_ASP_MASK) #define USB_HCCPARAMS_IST_MASK (0xF0U) #define USB_HCCPARAMS_IST_SHIFT (4U) #define USB_HCCPARAMS_IST(x) (((uint32_t)(((uint32_t)(x)) << USB_HCCPARAMS_IST_SHIFT)) & USB_HCCPARAMS_IST_MASK) #define USB_HCCPARAMS_EECP_MASK (0xFF00U) #define USB_HCCPARAMS_EECP_SHIFT (8U) #define USB_HCCPARAMS_EECP(x) (((uint32_t)(((uint32_t)(x)) << USB_HCCPARAMS_EECP_SHIFT)) & USB_HCCPARAMS_EECP_MASK) /*! @} */ /*! @name DCIVERSION - Device Controller Interface Version */ /*! @{ */ #define USB_DCIVERSION_DCIVERSION_MASK (0xFFFFU) #define USB_DCIVERSION_DCIVERSION_SHIFT (0U) #define USB_DCIVERSION_DCIVERSION(x) (((uint16_t)(((uint16_t)(x)) << USB_DCIVERSION_DCIVERSION_SHIFT)) & USB_DCIVERSION_DCIVERSION_MASK) /*! @} */ /*! @name DCCPARAMS - Device Controller Capability Parameters */ /*! @{ */ #define USB_DCCPARAMS_DEN_MASK (0x1FU) #define USB_DCCPARAMS_DEN_SHIFT (0U) #define USB_DCCPARAMS_DEN(x) (((uint32_t)(((uint32_t)(x)) << USB_DCCPARAMS_DEN_SHIFT)) & USB_DCCPARAMS_DEN_MASK) #define USB_DCCPARAMS_DC_MASK (0x80U) #define USB_DCCPARAMS_DC_SHIFT (7U) #define USB_DCCPARAMS_DC(x) (((uint32_t)(((uint32_t)(x)) << USB_DCCPARAMS_DC_SHIFT)) & USB_DCCPARAMS_DC_MASK) #define USB_DCCPARAMS_HC_MASK (0x100U) #define USB_DCCPARAMS_HC_SHIFT (8U) #define USB_DCCPARAMS_HC(x) (((uint32_t)(((uint32_t)(x)) << USB_DCCPARAMS_HC_SHIFT)) & USB_DCCPARAMS_HC_MASK) /*! @} */ /*! @name USBCMD - USB Command Register */ /*! @{ */ #define USB_USBCMD_RS_MASK (0x1U) #define USB_USBCMD_RS_SHIFT (0U) #define USB_USBCMD_RS(x) (((uint32_t)(((uint32_t)(x)) << USB_USBCMD_RS_SHIFT)) & USB_USBCMD_RS_MASK) #define USB_USBCMD_RST_MASK (0x2U) #define USB_USBCMD_RST_SHIFT (1U) #define USB_USBCMD_RST(x) (((uint32_t)(((uint32_t)(x)) << USB_USBCMD_RST_SHIFT)) & USB_USBCMD_RST_MASK) #define USB_USBCMD_FS_1_MASK (0xCU) #define USB_USBCMD_FS_1_SHIFT (2U) #define USB_USBCMD_FS_1(x) (((uint32_t)(((uint32_t)(x)) << USB_USBCMD_FS_1_SHIFT)) & USB_USBCMD_FS_1_MASK) #define USB_USBCMD_PSE_MASK (0x10U) #define USB_USBCMD_PSE_SHIFT (4U) /*! PSE * 0b0..Do not process the Periodic Schedule * 0b1..Use the PERIODICLISTBASE register to access the Periodic Schedule. */ #define USB_USBCMD_PSE(x) (((uint32_t)(((uint32_t)(x)) << USB_USBCMD_PSE_SHIFT)) & USB_USBCMD_PSE_MASK) #define USB_USBCMD_ASE_MASK (0x20U) #define USB_USBCMD_ASE_SHIFT (5U) /*! ASE * 0b0..Do not process the Asynchronous Schedule. * 0b1..Use the ASYNCLISTADDR register to access the Asynchronous Schedule. */ #define USB_USBCMD_ASE(x) (((uint32_t)(((uint32_t)(x)) << USB_USBCMD_ASE_SHIFT)) & USB_USBCMD_ASE_MASK) #define USB_USBCMD_IAA_MASK (0x40U) #define USB_USBCMD_IAA_SHIFT (6U) #define USB_USBCMD_IAA(x) (((uint32_t)(((uint32_t)(x)) << USB_USBCMD_IAA_SHIFT)) & USB_USBCMD_IAA_MASK) #define USB_USBCMD_ASP_MASK (0x300U) #define USB_USBCMD_ASP_SHIFT (8U) #define USB_USBCMD_ASP(x) (((uint32_t)(((uint32_t)(x)) << USB_USBCMD_ASP_SHIFT)) & USB_USBCMD_ASP_MASK) #define USB_USBCMD_ASPE_MASK (0x800U) #define USB_USBCMD_ASPE_SHIFT (11U) #define USB_USBCMD_ASPE(x) (((uint32_t)(((uint32_t)(x)) << USB_USBCMD_ASPE_SHIFT)) & USB_USBCMD_ASPE_MASK) #define USB_USBCMD_ATDTW_MASK (0x1000U) #define USB_USBCMD_ATDTW_SHIFT (12U) #define USB_USBCMD_ATDTW(x) (((uint32_t)(((uint32_t)(x)) << USB_USBCMD_ATDTW_SHIFT)) & USB_USBCMD_ATDTW_MASK) #define USB_USBCMD_SUTW_MASK (0x2000U) #define USB_USBCMD_SUTW_SHIFT (13U) #define USB_USBCMD_SUTW(x) (((uint32_t)(((uint32_t)(x)) << USB_USBCMD_SUTW_SHIFT)) & USB_USBCMD_SUTW_MASK) #define USB_USBCMD_FS_2_MASK (0x8000U) #define USB_USBCMD_FS_2_SHIFT (15U) /*! FS_2 * 0b0..1024 elements (4096 bytes) Default value * 0b1..512 elements (2048 bytes) */ #define USB_USBCMD_FS_2(x) (((uint32_t)(((uint32_t)(x)) << USB_USBCMD_FS_2_SHIFT)) & USB_USBCMD_FS_2_MASK) #define USB_USBCMD_ITC_MASK (0xFF0000U) #define USB_USBCMD_ITC_SHIFT (16U) /*! ITC * 0b00000000..Immediate (no threshold) * 0b00000001..1 micro-frame * 0b00000010..2 micro-frames * 0b00000100..4 micro-frames * 0b00001000..8 micro-frames * 0b00010000..16 micro-frames * 0b00100000..32 micro-frames * 0b01000000..64 micro-frames */ #define USB_USBCMD_ITC(x) (((uint32_t)(((uint32_t)(x)) << USB_USBCMD_ITC_SHIFT)) & USB_USBCMD_ITC_MASK) /*! @} */ /*! @name USBSTS - USB Status Register */ /*! @{ */ #define USB_USBSTS_UI_MASK (0x1U) #define USB_USBSTS_UI_SHIFT (0U) #define USB_USBSTS_UI(x) (((uint32_t)(((uint32_t)(x)) << USB_USBSTS_UI_SHIFT)) & USB_USBSTS_UI_MASK) #define USB_USBSTS_UEI_MASK (0x2U) #define USB_USBSTS_UEI_SHIFT (1U) #define USB_USBSTS_UEI(x) (((uint32_t)(((uint32_t)(x)) << USB_USBSTS_UEI_SHIFT)) & USB_USBSTS_UEI_MASK) #define USB_USBSTS_PCI_MASK (0x4U) #define USB_USBSTS_PCI_SHIFT (2U) #define USB_USBSTS_PCI(x) (((uint32_t)(((uint32_t)(x)) << USB_USBSTS_PCI_SHIFT)) & USB_USBSTS_PCI_MASK) #define USB_USBSTS_FRI_MASK (0x8U) #define USB_USBSTS_FRI_SHIFT (3U) #define USB_USBSTS_FRI(x) (((uint32_t)(((uint32_t)(x)) << USB_USBSTS_FRI_SHIFT)) & USB_USBSTS_FRI_MASK) #define USB_USBSTS_SEI_MASK (0x10U) #define USB_USBSTS_SEI_SHIFT (4U) #define USB_USBSTS_SEI(x) (((uint32_t)(((uint32_t)(x)) << USB_USBSTS_SEI_SHIFT)) & USB_USBSTS_SEI_MASK) #define USB_USBSTS_AAI_MASK (0x20U) #define USB_USBSTS_AAI_SHIFT (5U) #define USB_USBSTS_AAI(x) (((uint32_t)(((uint32_t)(x)) << USB_USBSTS_AAI_SHIFT)) & USB_USBSTS_AAI_MASK) #define USB_USBSTS_URI_MASK (0x40U) #define USB_USBSTS_URI_SHIFT (6U) #define USB_USBSTS_URI(x) (((uint32_t)(((uint32_t)(x)) << USB_USBSTS_URI_SHIFT)) & USB_USBSTS_URI_MASK) #define USB_USBSTS_SRI_MASK (0x80U) #define USB_USBSTS_SRI_SHIFT (7U) #define USB_USBSTS_SRI(x) (((uint32_t)(((uint32_t)(x)) << USB_USBSTS_SRI_SHIFT)) & USB_USBSTS_SRI_MASK) #define USB_USBSTS_SLI_MASK (0x100U) #define USB_USBSTS_SLI_SHIFT (8U) #define USB_USBSTS_SLI(x) (((uint32_t)(((uint32_t)(x)) << USB_USBSTS_SLI_SHIFT)) & USB_USBSTS_SLI_MASK) #define USB_USBSTS_ULPII_MASK (0x400U) #define USB_USBSTS_ULPII_SHIFT (10U) #define USB_USBSTS_ULPII(x) (((uint32_t)(((uint32_t)(x)) << USB_USBSTS_ULPII_SHIFT)) & USB_USBSTS_ULPII_MASK) #define USB_USBSTS_HCH_MASK (0x1000U) #define USB_USBSTS_HCH_SHIFT (12U) #define USB_USBSTS_HCH(x) (((uint32_t)(((uint32_t)(x)) << USB_USBSTS_HCH_SHIFT)) & USB_USBSTS_HCH_MASK) #define USB_USBSTS_RCL_MASK (0x2000U) #define USB_USBSTS_RCL_SHIFT (13U) #define USB_USBSTS_RCL(x) (((uint32_t)(((uint32_t)(x)) << USB_USBSTS_RCL_SHIFT)) & USB_USBSTS_RCL_MASK) #define USB_USBSTS_PS_MASK (0x4000U) #define USB_USBSTS_PS_SHIFT (14U) #define USB_USBSTS_PS(x) (((uint32_t)(((uint32_t)(x)) << USB_USBSTS_PS_SHIFT)) & USB_USBSTS_PS_MASK) #define USB_USBSTS_AS_MASK (0x8000U) #define USB_USBSTS_AS_SHIFT (15U) #define USB_USBSTS_AS(x) (((uint32_t)(((uint32_t)(x)) << USB_USBSTS_AS_SHIFT)) & USB_USBSTS_AS_MASK) #define USB_USBSTS_NAKI_MASK (0x10000U) #define USB_USBSTS_NAKI_SHIFT (16U) #define USB_USBSTS_NAKI(x) (((uint32_t)(((uint32_t)(x)) << USB_USBSTS_NAKI_SHIFT)) & USB_USBSTS_NAKI_MASK) #define USB_USBSTS_TI0_MASK (0x1000000U) #define USB_USBSTS_TI0_SHIFT (24U) #define USB_USBSTS_TI0(x) (((uint32_t)(((uint32_t)(x)) << USB_USBSTS_TI0_SHIFT)) & USB_USBSTS_TI0_MASK) #define USB_USBSTS_TI1_MASK (0x2000000U) #define USB_USBSTS_TI1_SHIFT (25U) #define USB_USBSTS_TI1(x) (((uint32_t)(((uint32_t)(x)) << USB_USBSTS_TI1_SHIFT)) & USB_USBSTS_TI1_MASK) /*! @} */ /*! @name USBINTR - Interrupt Enable Register */ /*! @{ */ #define USB_USBINTR_UE_MASK (0x1U) #define USB_USBINTR_UE_SHIFT (0U) #define USB_USBINTR_UE(x) (((uint32_t)(((uint32_t)(x)) << USB_USBINTR_UE_SHIFT)) & USB_USBINTR_UE_MASK) #define USB_USBINTR_UEE_MASK (0x2U) #define USB_USBINTR_UEE_SHIFT (1U) #define USB_USBINTR_UEE(x) (((uint32_t)(((uint32_t)(x)) << USB_USBINTR_UEE_SHIFT)) & USB_USBINTR_UEE_MASK) #define USB_USBINTR_PCE_MASK (0x4U) #define USB_USBINTR_PCE_SHIFT (2U) #define USB_USBINTR_PCE(x) (((uint32_t)(((uint32_t)(x)) << USB_USBINTR_PCE_SHIFT)) & USB_USBINTR_PCE_MASK) #define USB_USBINTR_FRE_MASK (0x8U) #define USB_USBINTR_FRE_SHIFT (3U) #define USB_USBINTR_FRE(x) (((uint32_t)(((uint32_t)(x)) << USB_USBINTR_FRE_SHIFT)) & USB_USBINTR_FRE_MASK) #define USB_USBINTR_SEE_MASK (0x10U) #define USB_USBINTR_SEE_SHIFT (4U) #define USB_USBINTR_SEE(x) (((uint32_t)(((uint32_t)(x)) << USB_USBINTR_SEE_SHIFT)) & USB_USBINTR_SEE_MASK) #define USB_USBINTR_AAE_MASK (0x20U) #define USB_USBINTR_AAE_SHIFT (5U) #define USB_USBINTR_AAE(x) (((uint32_t)(((uint32_t)(x)) << USB_USBINTR_AAE_SHIFT)) & USB_USBINTR_AAE_MASK) #define USB_USBINTR_URE_MASK (0x40U) #define USB_USBINTR_URE_SHIFT (6U) #define USB_USBINTR_URE(x) (((uint32_t)(((uint32_t)(x)) << USB_USBINTR_URE_SHIFT)) & USB_USBINTR_URE_MASK) #define USB_USBINTR_SRE_MASK (0x80U) #define USB_USBINTR_SRE_SHIFT (7U) #define USB_USBINTR_SRE(x) (((uint32_t)(((uint32_t)(x)) << USB_USBINTR_SRE_SHIFT)) & USB_USBINTR_SRE_MASK) #define USB_USBINTR_SLE_MASK (0x100U) #define USB_USBINTR_SLE_SHIFT (8U) #define USB_USBINTR_SLE(x) (((uint32_t)(((uint32_t)(x)) << USB_USBINTR_SLE_SHIFT)) & USB_USBINTR_SLE_MASK) #define USB_USBINTR_ULPIE_MASK (0x400U) #define USB_USBINTR_ULPIE_SHIFT (10U) #define USB_USBINTR_ULPIE(x) (((uint32_t)(((uint32_t)(x)) << USB_USBINTR_ULPIE_SHIFT)) & USB_USBINTR_ULPIE_MASK) #define USB_USBINTR_NAKE_MASK (0x10000U) #define USB_USBINTR_NAKE_SHIFT (16U) #define USB_USBINTR_NAKE(x) (((uint32_t)(((uint32_t)(x)) << USB_USBINTR_NAKE_SHIFT)) & USB_USBINTR_NAKE_MASK) #define USB_USBINTR_UAIE_MASK (0x40000U) #define USB_USBINTR_UAIE_SHIFT (18U) #define USB_USBINTR_UAIE(x) (((uint32_t)(((uint32_t)(x)) << USB_USBINTR_UAIE_SHIFT)) & USB_USBINTR_UAIE_MASK) #define USB_USBINTR_UPIE_MASK (0x80000U) #define USB_USBINTR_UPIE_SHIFT (19U) #define USB_USBINTR_UPIE(x) (((uint32_t)(((uint32_t)(x)) << USB_USBINTR_UPIE_SHIFT)) & USB_USBINTR_UPIE_MASK) #define USB_USBINTR_TIE0_MASK (0x1000000U) #define USB_USBINTR_TIE0_SHIFT (24U) #define USB_USBINTR_TIE0(x) (((uint32_t)(((uint32_t)(x)) << USB_USBINTR_TIE0_SHIFT)) & USB_USBINTR_TIE0_MASK) #define USB_USBINTR_TIE1_MASK (0x2000000U) #define USB_USBINTR_TIE1_SHIFT (25U) #define USB_USBINTR_TIE1(x) (((uint32_t)(((uint32_t)(x)) << USB_USBINTR_TIE1_SHIFT)) & USB_USBINTR_TIE1_MASK) /*! @} */ /*! @name FRINDEX - USB Frame Index */ /*! @{ */ #define USB_FRINDEX_FRINDEX_MASK (0x3FFFU) #define USB_FRINDEX_FRINDEX_SHIFT (0U) /*! FRINDEX * 0b00000000000000..(1024) 12 * 0b00000000000001..(512) 11 * 0b00000000000010..(256) 10 * 0b00000000000011..(128) 9 * 0b00000000000100..(64) 8 * 0b00000000000101..(32) 7 * 0b00000000000110..(16) 6 * 0b00000000000111..(8) 5 */ #define USB_FRINDEX_FRINDEX(x) (((uint32_t)(((uint32_t)(x)) << USB_FRINDEX_FRINDEX_SHIFT)) & USB_FRINDEX_FRINDEX_MASK) /*! @} */ /*! @name DEVICEADDR - Device Address */ /*! @{ */ #define USB_DEVICEADDR_USBADRA_MASK (0x1000000U) #define USB_DEVICEADDR_USBADRA_SHIFT (24U) #define USB_DEVICEADDR_USBADRA(x) (((uint32_t)(((uint32_t)(x)) << USB_DEVICEADDR_USBADRA_SHIFT)) & USB_DEVICEADDR_USBADRA_MASK) #define USB_DEVICEADDR_USBADR_MASK (0xFE000000U) #define USB_DEVICEADDR_USBADR_SHIFT (25U) #define USB_DEVICEADDR_USBADR(x) (((uint32_t)(((uint32_t)(x)) << USB_DEVICEADDR_USBADR_SHIFT)) & USB_DEVICEADDR_USBADR_MASK) /*! @} */ /*! @name PERIODICLISTBASE - Frame List Base Address */ /*! @{ */ #define USB_PERIODICLISTBASE_BASEADR_MASK (0xFFFFF000U) #define USB_PERIODICLISTBASE_BASEADR_SHIFT (12U) #define USB_PERIODICLISTBASE_BASEADR(x) (((uint32_t)(((uint32_t)(x)) << USB_PERIODICLISTBASE_BASEADR_SHIFT)) & USB_PERIODICLISTBASE_BASEADR_MASK) /*! @} */ /*! @name ASYNCLISTADDR - Next Asynch. Address */ /*! @{ */ #define USB_ASYNCLISTADDR_ASYBASE_MASK (0xFFFFFFE0U) #define USB_ASYNCLISTADDR_ASYBASE_SHIFT (5U) #define USB_ASYNCLISTADDR_ASYBASE(x) (((uint32_t)(((uint32_t)(x)) << USB_ASYNCLISTADDR_ASYBASE_SHIFT)) & USB_ASYNCLISTADDR_ASYBASE_MASK) /*! @} */ /*! @name ENDPTLISTADDR - Endpoint List Address */ /*! @{ */ #define USB_ENDPTLISTADDR_EPBASE_MASK (0xFFFFF800U) #define USB_ENDPTLISTADDR_EPBASE_SHIFT (11U) #define USB_ENDPTLISTADDR_EPBASE(x) (((uint32_t)(((uint32_t)(x)) << USB_ENDPTLISTADDR_EPBASE_SHIFT)) & USB_ENDPTLISTADDR_EPBASE_MASK) /*! @} */ /*! @name BURSTSIZE - Programmable Burst Size */ /*! @{ */ #define USB_BURSTSIZE_RXPBURST_MASK (0xFFU) #define USB_BURSTSIZE_RXPBURST_SHIFT (0U) #define USB_BURSTSIZE_RXPBURST(x) (((uint32_t)(((uint32_t)(x)) << USB_BURSTSIZE_RXPBURST_SHIFT)) & USB_BURSTSIZE_RXPBURST_MASK) #define USB_BURSTSIZE_TXPBURST_MASK (0x1FF00U) #define USB_BURSTSIZE_TXPBURST_SHIFT (8U) #define USB_BURSTSIZE_TXPBURST(x) (((uint32_t)(((uint32_t)(x)) << USB_BURSTSIZE_TXPBURST_SHIFT)) & USB_BURSTSIZE_TXPBURST_MASK) /*! @} */ /*! @name TXFILLTUNING - TX FIFO Fill Tuning */ /*! @{ */ #define USB_TXFILLTUNING_TXSCHOH_MASK (0xFFU) #define USB_TXFILLTUNING_TXSCHOH_SHIFT (0U) #define USB_TXFILLTUNING_TXSCHOH(x) (((uint32_t)(((uint32_t)(x)) << USB_TXFILLTUNING_TXSCHOH_SHIFT)) & USB_TXFILLTUNING_TXSCHOH_MASK) #define USB_TXFILLTUNING_TXSCHHEALTH_MASK (0x1F00U) #define USB_TXFILLTUNING_TXSCHHEALTH_SHIFT (8U) #define USB_TXFILLTUNING_TXSCHHEALTH(x) (((uint32_t)(((uint32_t)(x)) << USB_TXFILLTUNING_TXSCHHEALTH_SHIFT)) & USB_TXFILLTUNING_TXSCHHEALTH_MASK) #define USB_TXFILLTUNING_TXFIFOTHRES_MASK (0x3F0000U) #define USB_TXFILLTUNING_TXFIFOTHRES_SHIFT (16U) #define USB_TXFILLTUNING_TXFIFOTHRES(x) (((uint32_t)(((uint32_t)(x)) << USB_TXFILLTUNING_TXFIFOTHRES_SHIFT)) & USB_TXFILLTUNING_TXFIFOTHRES_MASK) /*! @} */ /*! @name ENDPTNAK - Endpoint NAK */ /*! @{ */ #define USB_ENDPTNAK_EPRN_MASK (0xFFU) #define USB_ENDPTNAK_EPRN_SHIFT (0U) #define USB_ENDPTNAK_EPRN(x) (((uint32_t)(((uint32_t)(x)) << USB_ENDPTNAK_EPRN_SHIFT)) & USB_ENDPTNAK_EPRN_MASK) #define USB_ENDPTNAK_EPTN_MASK (0xFF0000U) #define USB_ENDPTNAK_EPTN_SHIFT (16U) #define USB_ENDPTNAK_EPTN(x) (((uint32_t)(((uint32_t)(x)) << USB_ENDPTNAK_EPTN_SHIFT)) & USB_ENDPTNAK_EPTN_MASK) /*! @} */ /*! @name ENDPTNAKEN - Endpoint NAK Enable */ /*! @{ */ #define USB_ENDPTNAKEN_EPRNE_MASK (0xFFU) #define USB_ENDPTNAKEN_EPRNE_SHIFT (0U) #define USB_ENDPTNAKEN_EPRNE(x) (((uint32_t)(((uint32_t)(x)) << USB_ENDPTNAKEN_EPRNE_SHIFT)) & USB_ENDPTNAKEN_EPRNE_MASK) #define USB_ENDPTNAKEN_EPTNE_MASK (0xFF0000U) #define USB_ENDPTNAKEN_EPTNE_SHIFT (16U) #define USB_ENDPTNAKEN_EPTNE(x) (((uint32_t)(((uint32_t)(x)) << USB_ENDPTNAKEN_EPTNE_SHIFT)) & USB_ENDPTNAKEN_EPTNE_MASK) /*! @} */ /*! @name CONFIGFLAG - Configure Flag Register */ /*! @{ */ #define USB_CONFIGFLAG_CF_MASK (0x1U) #define USB_CONFIGFLAG_CF_SHIFT (0U) /*! CF * 0b0..Port routing control logic default-routes each port to an implementation dependent classic host controller. * 0b1..Port routing control logic default-routes all ports to this host controller. */ #define USB_CONFIGFLAG_CF(x) (((uint32_t)(((uint32_t)(x)) << USB_CONFIGFLAG_CF_SHIFT)) & USB_CONFIGFLAG_CF_MASK) /*! @} */ /*! @name PORTSC1 - Port Status & Control */ /*! @{ */ #define USB_PORTSC1_CCS_MASK (0x1U) #define USB_PORTSC1_CCS_SHIFT (0U) #define USB_PORTSC1_CCS(x) (((uint32_t)(((uint32_t)(x)) << USB_PORTSC1_CCS_SHIFT)) & USB_PORTSC1_CCS_MASK) #define USB_PORTSC1_CSC_MASK (0x2U) #define USB_PORTSC1_CSC_SHIFT (1U) #define USB_PORTSC1_CSC(x) (((uint32_t)(((uint32_t)(x)) << USB_PORTSC1_CSC_SHIFT)) & USB_PORTSC1_CSC_MASK) #define USB_PORTSC1_PE_MASK (0x4U) #define USB_PORTSC1_PE_SHIFT (2U) #define USB_PORTSC1_PE(x) (((uint32_t)(((uint32_t)(x)) << USB_PORTSC1_PE_SHIFT)) & USB_PORTSC1_PE_MASK) #define USB_PORTSC1_PEC_MASK (0x8U) #define USB_PORTSC1_PEC_SHIFT (3U) #define USB_PORTSC1_PEC(x) (((uint32_t)(((uint32_t)(x)) << USB_PORTSC1_PEC_SHIFT)) & USB_PORTSC1_PEC_MASK) #define USB_PORTSC1_OCA_MASK (0x10U) #define USB_PORTSC1_OCA_SHIFT (4U) /*! OCA * 0b1..This port currently has an over-current condition * 0b0..This port does not have an over-current condition. */ #define USB_PORTSC1_OCA(x) (((uint32_t)(((uint32_t)(x)) << USB_PORTSC1_OCA_SHIFT)) & USB_PORTSC1_OCA_MASK) #define USB_PORTSC1_OCC_MASK (0x20U) #define USB_PORTSC1_OCC_SHIFT (5U) #define USB_PORTSC1_OCC(x) (((uint32_t)(((uint32_t)(x)) << USB_PORTSC1_OCC_SHIFT)) & USB_PORTSC1_OCC_MASK) #define USB_PORTSC1_FPR_MASK (0x40U) #define USB_PORTSC1_FPR_SHIFT (6U) #define USB_PORTSC1_FPR(x) (((uint32_t)(((uint32_t)(x)) << USB_PORTSC1_FPR_SHIFT)) & USB_PORTSC1_FPR_MASK) #define USB_PORTSC1_SUSP_MASK (0x80U) #define USB_PORTSC1_SUSP_SHIFT (7U) #define USB_PORTSC1_SUSP(x) (((uint32_t)(((uint32_t)(x)) << USB_PORTSC1_SUSP_SHIFT)) & USB_PORTSC1_SUSP_MASK) #define USB_PORTSC1_PR_MASK (0x100U) #define USB_PORTSC1_PR_SHIFT (8U) #define USB_PORTSC1_PR(x) (((uint32_t)(((uint32_t)(x)) << USB_PORTSC1_PR_SHIFT)) & USB_PORTSC1_PR_MASK) #define USB_PORTSC1_HSP_MASK (0x200U) #define USB_PORTSC1_HSP_SHIFT (9U) #define USB_PORTSC1_HSP(x) (((uint32_t)(((uint32_t)(x)) << USB_PORTSC1_HSP_SHIFT)) & USB_PORTSC1_HSP_MASK) #define USB_PORTSC1_LS_MASK (0xC00U) #define USB_PORTSC1_LS_SHIFT (10U) /*! LS * 0b00..SE0 * 0b10..J-state * 0b01..K-state * 0b11..Undefined */ #define USB_PORTSC1_LS(x) (((uint32_t)(((uint32_t)(x)) << USB_PORTSC1_LS_SHIFT)) & USB_PORTSC1_LS_MASK) #define USB_PORTSC1_PP_MASK (0x1000U) #define USB_PORTSC1_PP_SHIFT (12U) #define USB_PORTSC1_PP(x) (((uint32_t)(((uint32_t)(x)) << USB_PORTSC1_PP_SHIFT)) & USB_PORTSC1_PP_MASK) #define USB_PORTSC1_PO_MASK (0x2000U) #define USB_PORTSC1_PO_SHIFT (13U) #define USB_PORTSC1_PO(x) (((uint32_t)(((uint32_t)(x)) << USB_PORTSC1_PO_SHIFT)) & USB_PORTSC1_PO_MASK) #define USB_PORTSC1_PIC_MASK (0xC000U) #define USB_PORTSC1_PIC_SHIFT (14U) /*! PIC * 0b00..Port indicators are off * 0b01..Amber * 0b10..Green * 0b11..Undefined */ #define USB_PORTSC1_PIC(x) (((uint32_t)(((uint32_t)(x)) << USB_PORTSC1_PIC_SHIFT)) & USB_PORTSC1_PIC_MASK) #define USB_PORTSC1_PTC_MASK (0xF0000U) #define USB_PORTSC1_PTC_SHIFT (16U) /*! PTC * 0b0000..TEST_MODE_DISABLE * 0b0001..J_STATE * 0b0010..K_STATE * 0b0011..SE0 (host) / NAK (device) * 0b0100..Packet * 0b0101..FORCE_ENABLE_HS * 0b0110..FORCE_ENABLE_FS * 0b0111..FORCE_ENABLE_LS */ #define USB_PORTSC1_PTC(x) (((uint32_t)(((uint32_t)(x)) << USB_PORTSC1_PTC_SHIFT)) & USB_PORTSC1_PTC_MASK) #define USB_PORTSC1_WKCN_MASK (0x100000U) #define USB_PORTSC1_WKCN_SHIFT (20U) #define USB_PORTSC1_WKCN(x) (((uint32_t)(((uint32_t)(x)) << USB_PORTSC1_WKCN_SHIFT)) & USB_PORTSC1_WKCN_MASK) #define USB_PORTSC1_WKDC_MASK (0x200000U) #define USB_PORTSC1_WKDC_SHIFT (21U) #define USB_PORTSC1_WKDC(x) (((uint32_t)(((uint32_t)(x)) << USB_PORTSC1_WKDC_SHIFT)) & USB_PORTSC1_WKDC_MASK) #define USB_PORTSC1_WKOC_MASK (0x400000U) #define USB_PORTSC1_WKOC_SHIFT (22U) #define USB_PORTSC1_WKOC(x) (((uint32_t)(((uint32_t)(x)) << USB_PORTSC1_WKOC_SHIFT)) & USB_PORTSC1_WKOC_MASK) #define USB_PORTSC1_PHCD_MASK (0x800000U) #define USB_PORTSC1_PHCD_SHIFT (23U) /*! PHCD * 0b1..Disable PHY clock * 0b0..Enable PHY clock */ #define USB_PORTSC1_PHCD(x) (((uint32_t)(((uint32_t)(x)) << USB_PORTSC1_PHCD_SHIFT)) & USB_PORTSC1_PHCD_MASK) #define USB_PORTSC1_PFSC_MASK (0x1000000U) #define USB_PORTSC1_PFSC_SHIFT (24U) /*! PFSC * 0b1..Forced to full speed * 0b0..Normal operation */ #define USB_PORTSC1_PFSC(x) (((uint32_t)(((uint32_t)(x)) << USB_PORTSC1_PFSC_SHIFT)) & USB_PORTSC1_PFSC_MASK) #define USB_PORTSC1_PTS_2_MASK (0x2000000U) #define USB_PORTSC1_PTS_2_SHIFT (25U) #define USB_PORTSC1_PTS_2(x) (((uint32_t)(((uint32_t)(x)) << USB_PORTSC1_PTS_2_SHIFT)) & USB_PORTSC1_PTS_2_MASK) #define USB_PORTSC1_PSPD_MASK (0xC000000U) #define USB_PORTSC1_PSPD_SHIFT (26U) /*! PSPD * 0b00..Full Speed * 0b01..Low Speed * 0b10..High Speed * 0b11..Undefined */ #define USB_PORTSC1_PSPD(x) (((uint32_t)(((uint32_t)(x)) << USB_PORTSC1_PSPD_SHIFT)) & USB_PORTSC1_PSPD_MASK) #define USB_PORTSC1_PTW_MASK (0x10000000U) #define USB_PORTSC1_PTW_SHIFT (28U) /*! PTW * 0b0..Select the 8-bit UTMI interface [60MHz] * 0b1..Select the 16-bit UTMI interface [30MHz] */ #define USB_PORTSC1_PTW(x) (((uint32_t)(((uint32_t)(x)) << USB_PORTSC1_PTW_SHIFT)) & USB_PORTSC1_PTW_MASK) #define USB_PORTSC1_STS_MASK (0x20000000U) #define USB_PORTSC1_STS_SHIFT (29U) #define USB_PORTSC1_STS(x) (((uint32_t)(((uint32_t)(x)) << USB_PORTSC1_STS_SHIFT)) & USB_PORTSC1_STS_MASK) #define USB_PORTSC1_PTS_1_MASK (0xC0000000U) #define USB_PORTSC1_PTS_1_SHIFT (30U) #define USB_PORTSC1_PTS_1(x) (((uint32_t)(((uint32_t)(x)) << USB_PORTSC1_PTS_1_SHIFT)) & USB_PORTSC1_PTS_1_MASK) /*! @} */ /*! @name OTGSC - On-The-Go Status & control */ /*! @{ */ #define USB_OTGSC_VD_MASK (0x1U) #define USB_OTGSC_VD_SHIFT (0U) #define USB_OTGSC_VD(x) (((uint32_t)(((uint32_t)(x)) << USB_OTGSC_VD_SHIFT)) & USB_OTGSC_VD_MASK) #define USB_OTGSC_VC_MASK (0x2U) #define USB_OTGSC_VC_SHIFT (1U) #define USB_OTGSC_VC(x) (((uint32_t)(((uint32_t)(x)) << USB_OTGSC_VC_SHIFT)) & USB_OTGSC_VC_MASK) #define USB_OTGSC_OT_MASK (0x8U) #define USB_OTGSC_OT_SHIFT (3U) #define USB_OTGSC_OT(x) (((uint32_t)(((uint32_t)(x)) << USB_OTGSC_OT_SHIFT)) & USB_OTGSC_OT_MASK) #define USB_OTGSC_DP_MASK (0x10U) #define USB_OTGSC_DP_SHIFT (4U) #define USB_OTGSC_DP(x) (((uint32_t)(((uint32_t)(x)) << USB_OTGSC_DP_SHIFT)) & USB_OTGSC_DP_MASK) #define USB_OTGSC_IDPU_MASK (0x20U) #define USB_OTGSC_IDPU_SHIFT (5U) #define USB_OTGSC_IDPU(x) (((uint32_t)(((uint32_t)(x)) << USB_OTGSC_IDPU_SHIFT)) & USB_OTGSC_IDPU_MASK) #define USB_OTGSC_ID_MASK (0x100U) #define USB_OTGSC_ID_SHIFT (8U) #define USB_OTGSC_ID(x) (((uint32_t)(((uint32_t)(x)) << USB_OTGSC_ID_SHIFT)) & USB_OTGSC_ID_MASK) #define USB_OTGSC_AVV_MASK (0x200U) #define USB_OTGSC_AVV_SHIFT (9U) #define USB_OTGSC_AVV(x) (((uint32_t)(((uint32_t)(x)) << USB_OTGSC_AVV_SHIFT)) & USB_OTGSC_AVV_MASK) #define USB_OTGSC_ASV_MASK (0x400U) #define USB_OTGSC_ASV_SHIFT (10U) #define USB_OTGSC_ASV(x) (((uint32_t)(((uint32_t)(x)) << USB_OTGSC_ASV_SHIFT)) & USB_OTGSC_ASV_MASK) #define USB_OTGSC_BSV_MASK (0x800U) #define USB_OTGSC_BSV_SHIFT (11U) #define USB_OTGSC_BSV(x) (((uint32_t)(((uint32_t)(x)) << USB_OTGSC_BSV_SHIFT)) & USB_OTGSC_BSV_MASK) #define USB_OTGSC_BSE_MASK (0x1000U) #define USB_OTGSC_BSE_SHIFT (12U) #define USB_OTGSC_BSE(x) (((uint32_t)(((uint32_t)(x)) << USB_OTGSC_BSE_SHIFT)) & USB_OTGSC_BSE_MASK) #define USB_OTGSC_TOG_1MS_MASK (0x2000U) #define USB_OTGSC_TOG_1MS_SHIFT (13U) #define USB_OTGSC_TOG_1MS(x) (((uint32_t)(((uint32_t)(x)) << USB_OTGSC_TOG_1MS_SHIFT)) & USB_OTGSC_TOG_1MS_MASK) #define USB_OTGSC_DPS_MASK (0x4000U) #define USB_OTGSC_DPS_SHIFT (14U) #define USB_OTGSC_DPS(x) (((uint32_t)(((uint32_t)(x)) << USB_OTGSC_DPS_SHIFT)) & USB_OTGSC_DPS_MASK) #define USB_OTGSC_IDIS_MASK (0x10000U) #define USB_OTGSC_IDIS_SHIFT (16U) #define USB_OTGSC_IDIS(x) (((uint32_t)(((uint32_t)(x)) << USB_OTGSC_IDIS_SHIFT)) & USB_OTGSC_IDIS_MASK) #define USB_OTGSC_AVVIS_MASK (0x20000U) #define USB_OTGSC_AVVIS_SHIFT (17U) #define USB_OTGSC_AVVIS(x) (((uint32_t)(((uint32_t)(x)) << USB_OTGSC_AVVIS_SHIFT)) & USB_OTGSC_AVVIS_MASK) #define USB_OTGSC_ASVIS_MASK (0x40000U) #define USB_OTGSC_ASVIS_SHIFT (18U) #define USB_OTGSC_ASVIS(x) (((uint32_t)(((uint32_t)(x)) << USB_OTGSC_ASVIS_SHIFT)) & USB_OTGSC_ASVIS_MASK) #define USB_OTGSC_BSVIS_MASK (0x80000U) #define USB_OTGSC_BSVIS_SHIFT (19U) #define USB_OTGSC_BSVIS(x) (((uint32_t)(((uint32_t)(x)) << USB_OTGSC_BSVIS_SHIFT)) & USB_OTGSC_BSVIS_MASK) #define USB_OTGSC_BSEIS_MASK (0x100000U) #define USB_OTGSC_BSEIS_SHIFT (20U) #define USB_OTGSC_BSEIS(x) (((uint32_t)(((uint32_t)(x)) << USB_OTGSC_BSEIS_SHIFT)) & USB_OTGSC_BSEIS_MASK) #define USB_OTGSC_STATUS_1MS_MASK (0x200000U) #define USB_OTGSC_STATUS_1MS_SHIFT (21U) #define USB_OTGSC_STATUS_1MS(x) (((uint32_t)(((uint32_t)(x)) << USB_OTGSC_STATUS_1MS_SHIFT)) & USB_OTGSC_STATUS_1MS_MASK) #define USB_OTGSC_DPIS_MASK (0x400000U) #define USB_OTGSC_DPIS_SHIFT (22U) #define USB_OTGSC_DPIS(x) (((uint32_t)(((uint32_t)(x)) << USB_OTGSC_DPIS_SHIFT)) & USB_OTGSC_DPIS_MASK) #define USB_OTGSC_IDIE_MASK (0x1000000U) #define USB_OTGSC_IDIE_SHIFT (24U) #define USB_OTGSC_IDIE(x) (((uint32_t)(((uint32_t)(x)) << USB_OTGSC_IDIE_SHIFT)) & USB_OTGSC_IDIE_MASK) #define USB_OTGSC_AVVIE_MASK (0x2000000U) #define USB_OTGSC_AVVIE_SHIFT (25U) #define USB_OTGSC_AVVIE(x) (((uint32_t)(((uint32_t)(x)) << USB_OTGSC_AVVIE_SHIFT)) & USB_OTGSC_AVVIE_MASK) #define USB_OTGSC_ASVIE_MASK (0x4000000U) #define USB_OTGSC_ASVIE_SHIFT (26U) #define USB_OTGSC_ASVIE(x) (((uint32_t)(((uint32_t)(x)) << USB_OTGSC_ASVIE_SHIFT)) & USB_OTGSC_ASVIE_MASK) #define USB_OTGSC_BSVIE_MASK (0x8000000U) #define USB_OTGSC_BSVIE_SHIFT (27U) #define USB_OTGSC_BSVIE(x) (((uint32_t)(((uint32_t)(x)) << USB_OTGSC_BSVIE_SHIFT)) & USB_OTGSC_BSVIE_MASK) #define USB_OTGSC_BSEIE_MASK (0x10000000U) #define USB_OTGSC_BSEIE_SHIFT (28U) #define USB_OTGSC_BSEIE(x) (((uint32_t)(((uint32_t)(x)) << USB_OTGSC_BSEIE_SHIFT)) & USB_OTGSC_BSEIE_MASK) #define USB_OTGSC_EN_1MS_MASK (0x20000000U) #define USB_OTGSC_EN_1MS_SHIFT (29U) #define USB_OTGSC_EN_1MS(x) (((uint32_t)(((uint32_t)(x)) << USB_OTGSC_EN_1MS_SHIFT)) & USB_OTGSC_EN_1MS_MASK) #define USB_OTGSC_DPIE_MASK (0x40000000U) #define USB_OTGSC_DPIE_SHIFT (30U) #define USB_OTGSC_DPIE(x) (((uint32_t)(((uint32_t)(x)) << USB_OTGSC_DPIE_SHIFT)) & USB_OTGSC_DPIE_MASK) /*! @} */ /*! @name USBMODE - USB Device Mode */ /*! @{ */ #define USB_USBMODE_CM_MASK (0x3U) #define USB_USBMODE_CM_SHIFT (0U) /*! CM * 0b00..Idle [Default for combination host/device] * 0b01..Reserved * 0b10..Device Controller [Default for device only controller] * 0b11..Host Controller [Default for host only controller] */ #define USB_USBMODE_CM(x) (((uint32_t)(((uint32_t)(x)) << USB_USBMODE_CM_SHIFT)) & USB_USBMODE_CM_MASK) #define USB_USBMODE_ES_MASK (0x4U) #define USB_USBMODE_ES_SHIFT (2U) /*! ES * 0b0..Little Endian [Default] * 0b1..Big Endian */ #define USB_USBMODE_ES(x) (((uint32_t)(((uint32_t)(x)) << USB_USBMODE_ES_SHIFT)) & USB_USBMODE_ES_MASK) #define USB_USBMODE_SLOM_MASK (0x8U) #define USB_USBMODE_SLOM_SHIFT (3U) /*! SLOM * 0b0..Setup Lockouts On (default); * 0b1..Setup Lockouts Off (DCD requires use of Setup Data Buffer Tripwire in USBCMDUSB Command Register . */ #define USB_USBMODE_SLOM(x) (((uint32_t)(((uint32_t)(x)) << USB_USBMODE_SLOM_SHIFT)) & USB_USBMODE_SLOM_MASK) #define USB_USBMODE_SDIS_MASK (0x10U) #define USB_USBMODE_SDIS_SHIFT (4U) #define USB_USBMODE_SDIS(x) (((uint32_t)(((uint32_t)(x)) << USB_USBMODE_SDIS_SHIFT)) & USB_USBMODE_SDIS_MASK) /*! @} */ /*! @name ENDPTSETUPSTAT - Endpoint Setup Status */ /*! @{ */ #define USB_ENDPTSETUPSTAT_ENDPTSETUPSTAT_MASK (0xFFFFU) #define USB_ENDPTSETUPSTAT_ENDPTSETUPSTAT_SHIFT (0U) #define USB_ENDPTSETUPSTAT_ENDPTSETUPSTAT(x) (((uint32_t)(((uint32_t)(x)) << USB_ENDPTSETUPSTAT_ENDPTSETUPSTAT_SHIFT)) & USB_ENDPTSETUPSTAT_ENDPTSETUPSTAT_MASK) /*! @} */ /*! @name ENDPTPRIME - Endpoint Prime */ /*! @{ */ #define USB_ENDPTPRIME_PERB_MASK (0xFFU) #define USB_ENDPTPRIME_PERB_SHIFT (0U) #define USB_ENDPTPRIME_PERB(x) (((uint32_t)(((uint32_t)(x)) << USB_ENDPTPRIME_PERB_SHIFT)) & USB_ENDPTPRIME_PERB_MASK) #define USB_ENDPTPRIME_PETB_MASK (0xFF0000U) #define USB_ENDPTPRIME_PETB_SHIFT (16U) #define USB_ENDPTPRIME_PETB(x) (((uint32_t)(((uint32_t)(x)) << USB_ENDPTPRIME_PETB_SHIFT)) & USB_ENDPTPRIME_PETB_MASK) /*! @} */ /*! @name ENDPTFLUSH - Endpoint Flush */ /*! @{ */ #define USB_ENDPTFLUSH_FERB_MASK (0xFFU) #define USB_ENDPTFLUSH_FERB_SHIFT (0U) #define USB_ENDPTFLUSH_FERB(x) (((uint32_t)(((uint32_t)(x)) << USB_ENDPTFLUSH_FERB_SHIFT)) & USB_ENDPTFLUSH_FERB_MASK) #define USB_ENDPTFLUSH_FETB_MASK (0xFF0000U) #define USB_ENDPTFLUSH_FETB_SHIFT (16U) #define USB_ENDPTFLUSH_FETB(x) (((uint32_t)(((uint32_t)(x)) << USB_ENDPTFLUSH_FETB_SHIFT)) & USB_ENDPTFLUSH_FETB_MASK) /*! @} */ /*! @name ENDPTSTAT - Endpoint Status */ /*! @{ */ #define USB_ENDPTSTAT_ERBR_MASK (0xFFU) #define USB_ENDPTSTAT_ERBR_SHIFT (0U) #define USB_ENDPTSTAT_ERBR(x) (((uint32_t)(((uint32_t)(x)) << USB_ENDPTSTAT_ERBR_SHIFT)) & USB_ENDPTSTAT_ERBR_MASK) #define USB_ENDPTSTAT_ETBR_MASK (0xFF0000U) #define USB_ENDPTSTAT_ETBR_SHIFT (16U) #define USB_ENDPTSTAT_ETBR(x) (((uint32_t)(((uint32_t)(x)) << USB_ENDPTSTAT_ETBR_SHIFT)) & USB_ENDPTSTAT_ETBR_MASK) /*! @} */ /*! @name ENDPTCOMPLETE - Endpoint Complete */ /*! @{ */ #define USB_ENDPTCOMPLETE_ERCE_MASK (0xFFU) #define USB_ENDPTCOMPLETE_ERCE_SHIFT (0U) #define USB_ENDPTCOMPLETE_ERCE(x) (((uint32_t)(((uint32_t)(x)) << USB_ENDPTCOMPLETE_ERCE_SHIFT)) & USB_ENDPTCOMPLETE_ERCE_MASK) #define USB_ENDPTCOMPLETE_ETCE_MASK (0xFF0000U) #define USB_ENDPTCOMPLETE_ETCE_SHIFT (16U) #define USB_ENDPTCOMPLETE_ETCE(x) (((uint32_t)(((uint32_t)(x)) << USB_ENDPTCOMPLETE_ETCE_SHIFT)) & USB_ENDPTCOMPLETE_ETCE_MASK) /*! @} */ /*! @name ENDPTCTRL0 - Endpoint Control0 */ /*! @{ */ #define USB_ENDPTCTRL0_RXS_MASK (0x1U) #define USB_ENDPTCTRL0_RXS_SHIFT (0U) #define USB_ENDPTCTRL0_RXS(x) (((uint32_t)(((uint32_t)(x)) << USB_ENDPTCTRL0_RXS_SHIFT)) & USB_ENDPTCTRL0_RXS_MASK) #define USB_ENDPTCTRL0_RXT_MASK (0xCU) #define USB_ENDPTCTRL0_RXT_SHIFT (2U) #define USB_ENDPTCTRL0_RXT(x) (((uint32_t)(((uint32_t)(x)) << USB_ENDPTCTRL0_RXT_SHIFT)) & USB_ENDPTCTRL0_RXT_MASK) #define USB_ENDPTCTRL0_RXE_MASK (0x80U) #define USB_ENDPTCTRL0_RXE_SHIFT (7U) #define USB_ENDPTCTRL0_RXE(x) (((uint32_t)(((uint32_t)(x)) << USB_ENDPTCTRL0_RXE_SHIFT)) & USB_ENDPTCTRL0_RXE_MASK) #define USB_ENDPTCTRL0_TXS_MASK (0x10000U) #define USB_ENDPTCTRL0_TXS_SHIFT (16U) #define USB_ENDPTCTRL0_TXS(x) (((uint32_t)(((uint32_t)(x)) << USB_ENDPTCTRL0_TXS_SHIFT)) & USB_ENDPTCTRL0_TXS_MASK) #define USB_ENDPTCTRL0_TXT_MASK (0xC0000U) #define USB_ENDPTCTRL0_TXT_SHIFT (18U) #define USB_ENDPTCTRL0_TXT(x) (((uint32_t)(((uint32_t)(x)) << USB_ENDPTCTRL0_TXT_SHIFT)) & USB_ENDPTCTRL0_TXT_MASK) #define USB_ENDPTCTRL0_TXE_MASK (0x800000U) #define USB_ENDPTCTRL0_TXE_SHIFT (23U) #define USB_ENDPTCTRL0_TXE(x) (((uint32_t)(((uint32_t)(x)) << USB_ENDPTCTRL0_TXE_SHIFT)) & USB_ENDPTCTRL0_TXE_MASK) /*! @} */ /*! @name ENDPTCTRL - Endpoint Control 1..Endpoint Control 7 */ /*! @{ */ #define USB_ENDPTCTRL_RXS_MASK (0x1U) #define USB_ENDPTCTRL_RXS_SHIFT (0U) #define USB_ENDPTCTRL_RXS(x) (((uint32_t)(((uint32_t)(x)) << USB_ENDPTCTRL_RXS_SHIFT)) & USB_ENDPTCTRL_RXS_MASK) #define USB_ENDPTCTRL_RXD_MASK (0x2U) #define USB_ENDPTCTRL_RXD_SHIFT (1U) #define USB_ENDPTCTRL_RXD(x) (((uint32_t)(((uint32_t)(x)) << USB_ENDPTCTRL_RXD_SHIFT)) & USB_ENDPTCTRL_RXD_MASK) #define USB_ENDPTCTRL_RXT_MASK (0xCU) #define USB_ENDPTCTRL_RXT_SHIFT (2U) #define USB_ENDPTCTRL_RXT(x) (((uint32_t)(((uint32_t)(x)) << USB_ENDPTCTRL_RXT_SHIFT)) & USB_ENDPTCTRL_RXT_MASK) #define USB_ENDPTCTRL_RXI_MASK (0x20U) #define USB_ENDPTCTRL_RXI_SHIFT (5U) #define USB_ENDPTCTRL_RXI(x) (((uint32_t)(((uint32_t)(x)) << USB_ENDPTCTRL_RXI_SHIFT)) & USB_ENDPTCTRL_RXI_MASK) #define USB_ENDPTCTRL_RXR_MASK (0x40U) #define USB_ENDPTCTRL_RXR_SHIFT (6U) #define USB_ENDPTCTRL_RXR(x) (((uint32_t)(((uint32_t)(x)) << USB_ENDPTCTRL_RXR_SHIFT)) & USB_ENDPTCTRL_RXR_MASK) #define USB_ENDPTCTRL_RXE_MASK (0x80U) #define USB_ENDPTCTRL_RXE_SHIFT (7U) #define USB_ENDPTCTRL_RXE(x) (((uint32_t)(((uint32_t)(x)) << USB_ENDPTCTRL_RXE_SHIFT)) & USB_ENDPTCTRL_RXE_MASK) #define USB_ENDPTCTRL_TXS_MASK (0x10000U) #define USB_ENDPTCTRL_TXS_SHIFT (16U) #define USB_ENDPTCTRL_TXS(x) (((uint32_t)(((uint32_t)(x)) << USB_ENDPTCTRL_TXS_SHIFT)) & USB_ENDPTCTRL_TXS_MASK) #define USB_ENDPTCTRL_TXD_MASK (0x20000U) #define USB_ENDPTCTRL_TXD_SHIFT (17U) #define USB_ENDPTCTRL_TXD(x) (((uint32_t)(((uint32_t)(x)) << USB_ENDPTCTRL_TXD_SHIFT)) & USB_ENDPTCTRL_TXD_MASK) #define USB_ENDPTCTRL_TXT_MASK (0xC0000U) #define USB_ENDPTCTRL_TXT_SHIFT (18U) #define USB_ENDPTCTRL_TXT(x) (((uint32_t)(((uint32_t)(x)) << USB_ENDPTCTRL_TXT_SHIFT)) & USB_ENDPTCTRL_TXT_MASK) #define USB_ENDPTCTRL_TXI_MASK (0x200000U) #define USB_ENDPTCTRL_TXI_SHIFT (21U) #define USB_ENDPTCTRL_TXI(x) (((uint32_t)(((uint32_t)(x)) << USB_ENDPTCTRL_TXI_SHIFT)) & USB_ENDPTCTRL_TXI_MASK) #define USB_ENDPTCTRL_TXR_MASK (0x400000U) #define USB_ENDPTCTRL_TXR_SHIFT (22U) #define USB_ENDPTCTRL_TXR(x) (((uint32_t)(((uint32_t)(x)) << USB_ENDPTCTRL_TXR_SHIFT)) & USB_ENDPTCTRL_TXR_MASK) #define USB_ENDPTCTRL_TXE_MASK (0x800000U) #define USB_ENDPTCTRL_TXE_SHIFT (23U) #define USB_ENDPTCTRL_TXE(x) (((uint32_t)(((uint32_t)(x)) << USB_ENDPTCTRL_TXE_SHIFT)) & USB_ENDPTCTRL_TXE_MASK) /*! @} */ /* Backward compatibility */ #define GPTIMER0CTL GPTIMER0CTRL #define GPTIMER1CTL GPTIMER1CTRL #define USB_SBUSCFG SBUSCFG #define EPLISTADDR ENDPTLISTADDR #define EPSETUPSR ENDPTSETUPSTAT #define EPPRIME ENDPTPRIME #define EPFLUSH ENDPTFLUSH #define EPSR ENDPTSTAT #define EPCOMPLETE ENDPTCOMPLETE #define EPCR ENDPTCTRL #define EPCR0 ENDPTCTRL0 #define USBHS_ID_ID_MASK USB_ID_ID_MASK #define USBHS_ID_ID_SHIFT USB_ID_ID_SHIFT #define USBHS_ID_ID(x) USB_ID_ID(x) #define USBHS_ID_NID_MASK USB_ID_NID_MASK #define USBHS_ID_NID_SHIFT USB_ID_NID_SHIFT #define USBHS_ID_NID(x) USB_ID_NID(x) #define USBHS_ID_REVISION_MASK USB_ID_REVISION_MASK #define USBHS_ID_REVISION_SHIFT USB_ID_REVISION_SHIFT #define USBHS_ID_REVISION(x) USB_ID_REVISION(x) #define USBHS_HWGENERAL_PHYW_MASK USB_HWGENERAL_PHYW_MASK #define USBHS_HWGENERAL_PHYW_SHIFT USB_HWGENERAL_PHYW_SHIFT #define USBHS_HWGENERAL_PHYW(x) USB_HWGENERAL_PHYW(x) #define USBHS_HWGENERAL_PHYM_MASK USB_HWGENERAL_PHYM_MASK #define USBHS_HWGENERAL_PHYM_SHIFT USB_HWGENERAL_PHYM_SHIFT #define USBHS_HWGENERAL_PHYM(x) USB_HWGENERAL_PHYM(x) #define USBHS_HWGENERAL_SM_MASK USB_HWGENERAL_SM_MASK #define USBHS_HWGENERAL_SM_SHIFT USB_HWGENERAL_SM_SHIFT #define USBHS_HWGENERAL_SM(x) USB_HWGENERAL_SM(x) #define USBHS_HWHOST_HC_MASK USB_HWHOST_HC_MASK #define USBHS_HWHOST_HC_SHIFT USB_HWHOST_HC_SHIFT #define USBHS_HWHOST_HC(x) USB_HWHOST_HC(x) #define USBHS_HWHOST_NPORT_MASK USB_HWHOST_NPORT_MASK #define USBHS_HWHOST_NPORT_SHIFT USB_HWHOST_NPORT_SHIFT #define USBHS_HWHOST_NPORT(x) USB_HWHOST_NPORT(x) #define USBHS_HWDEVICE_DC_MASK USB_HWDEVICE_DC_MASK #define USBHS_HWDEVICE_DC_SHIFT USB_HWDEVICE_DC_SHIFT #define USBHS_HWDEVICE_DC(x) USB_HWDEVICE_DC(x) #define USBHS_HWDEVICE_DEVEP_MASK USB_HWDEVICE_DEVEP_MASK #define USBHS_HWDEVICE_DEVEP_SHIFT USB_HWDEVICE_DEVEP_SHIFT #define USBHS_HWDEVICE_DEVEP(x) USB_HWDEVICE_DEVEP(x) #define USBHS_HWTXBUF_TXBURST_MASK USB_HWTXBUF_TXBURST_MASK #define USBHS_HWTXBUF_TXBURST_SHIFT USB_HWTXBUF_TXBURST_SHIFT #define USBHS_HWTXBUF_TXBURST(x) USB_HWTXBUF_TXBURST(x) #define USBHS_HWTXBUF_TXCHANADD_MASK USB_HWTXBUF_TXCHANADD_MASK #define USBHS_HWTXBUF_TXCHANADD_SHIFT USB_HWTXBUF_TXCHANADD_SHIFT #define USBHS_HWTXBUF_TXCHANADD(x) USB_HWTXBUF_TXCHANADD(x) #define USBHS_HWRXBUF_RXBURST_MASK USB_HWRXBUF_RXBURST_MASK #define USBHS_HWRXBUF_RXBURST_SHIFT USB_HWRXBUF_RXBURST_SHIFT #define USBHS_HWRXBUF_RXBURST(x) USB_HWRXBUF_RXBURST(x) #define USBHS_HWRXBUF_RXADD_MASK USB_HWRXBUF_RXADD_MASK #define USBHS_HWRXBUF_RXADD_SHIFT USB_HWRXBUF_RXADD_SHIFT #define USBHS_HWRXBUF_RXADD(x) USB_HWRXBUF_RXADD(x) #define USBHS_GPTIMER0LD_GPTLD_MASK USB_GPTIMER0LD_GPTLD_MASK #define USBHS_GPTIMER0LD_GPTLD_SHIFT USB_GPTIMER0LD_GPTLD_SHIFT #define USBHS_GPTIMER0LD_GPTLD(x) USB_GPTIMER0LD_GPTLD(x) #define USBHS_GPTIMER0CTL_GPTCNT_MASK USB_GPTIMER0CTRL_GPTCNT_MASK #define USBHS_GPTIMER0CTL_GPTCNT_SHIFT USB_GPTIMER0CTRL_GPTCNT_SHIFT #define USBHS_GPTIMER0CTL_GPTCNT(x) USB_GPTIMER0CTRL_GPTCNT(x) #define USBHS_GPTIMER0CTL_MODE_MASK USB_GPTIMER0CTRL_GPTMODE_MASK #define USBHS_GPTIMER0CTL_MODE_SHIFT USB_GPTIMER0CTRL_GPTMODE_SHIFT #define USBHS_GPTIMER0CTL_MODE(x) USB_GPTIMER0CTRL_GPTMODE(x) #define USBHS_GPTIMER0CTL_RST_MASK USB_GPTIMER0CTRL_GPTRST_MASK #define USBHS_GPTIMER0CTL_RST_SHIFT USB_GPTIMER0CTRL_GPTRST_SHIFT #define USBHS_GPTIMER0CTL_RST(x) USB_GPTIMER0CTRL_GPTRST(x) #define USBHS_GPTIMER0CTL_RUN_MASK USB_GPTIMER0CTRL_GPTRUN_MASK #define USBHS_GPTIMER0CTL_RUN_SHIFT USB_GPTIMER0CTRL_GPTRUN_SHIFT #define USBHS_GPTIMER0CTL_RUN(x) USB_GPTIMER0CTRL_GPTRUN(x) #define USBHS_GPTIMER1LD_GPTLD_MASK USB_GPTIMER1LD_GPTLD_MASK #define USBHS_GPTIMER1LD_GPTLD_SHIFT USB_GPTIMER1LD_GPTLD_SHIFT #define USBHS_GPTIMER1LD_GPTLD(x) USB_GPTIMER1LD_GPTLD(x) #define USBHS_GPTIMER1CTL_GPTCNT_MASK USB_GPTIMER1CTRL_GPTCNT_MASK #define USBHS_GPTIMER1CTL_GPTCNT_SHIFT USB_GPTIMER1CTRL_GPTCNT_SHIFT #define USBHS_GPTIMER1CTL_GPTCNT(x) USB_GPTIMER1CTRL_GPTCNT(x) #define USBHS_GPTIMER1CTL_MODE_MASK USB_GPTIMER1CTRL_GPTMODE_MASK #define USBHS_GPTIMER1CTL_MODE_SHIFT USB_GPTIMER1CTRL_GPTMODE_SHIFT #define USBHS_GPTIMER1CTL_MODE(x) USB_GPTIMER1CTRL_GPTMODE(x) #define USBHS_GPTIMER1CTL_RST_MASK USB_GPTIMER1CTRL_GPTRST_MASK #define USBHS_GPTIMER1CTL_RST_SHIFT USB_GPTIMER1CTRL_GPTRST_SHIFT #define USBHS_GPTIMER1CTL_RST(x) USB_GPTIMER1CTRL_GPTRST(x) #define USBHS_GPTIMER1CTL_RUN_MASK USB_GPTIMER1CTRL_GPTRUN_MASK #define USBHS_GPTIMER1CTL_RUN_SHIFT USB_GPTIMER1CTRL_GPTRUN_SHIFT #define USBHS_GPTIMER1CTL_RUN(x) USB_GPTIMER1CTRL_GPTRUN(x) #define USBHS_USB_SBUSCFG_BURSTMODE_MASK USB_SBUSCFG_AHBBRST_MASK #define USBHS_USB_SBUSCFG_BURSTMODE_SHIFT USB_SBUSCFG_AHBBRST_SHIFT #define USBHS_USB_SBUSCFG_BURSTMODE(x) USB_SBUSCFG_AHBBRST(x) #define USBHS_HCIVERSION_CAPLENGTH(x) USB_HCIVERSION_CAPLENGTH(x) #define USBHS_HCIVERSION_HCIVERSION_MASK USB_HCIVERSION_HCIVERSION_MASK #define USBHS_HCIVERSION_HCIVERSION_SHIFT USB_HCIVERSION_HCIVERSION_SHIFT #define USBHS_HCIVERSION_HCIVERSION(x) USB_HCIVERSION_HCIVERSION(x) #define USBHS_HCSPARAMS_N_PORTS_MASK USB_HCSPARAMS_N_PORTS_MASK #define USBHS_HCSPARAMS_N_PORTS_SHIFT USB_HCSPARAMS_N_PORTS_SHIFT #define USBHS_HCSPARAMS_N_PORTS(x) USB_HCSPARAMS_N_PORTS(x) #define USBHS_HCSPARAMS_PPC_MASK USB_HCSPARAMS_PPC_MASK #define USBHS_HCSPARAMS_PPC_SHIFT USB_HCSPARAMS_PPC_SHIFT #define USBHS_HCSPARAMS_PPC(x) USB_HCSPARAMS_PPC(x) #define USBHS_HCSPARAMS_N_PCC_MASK USB_HCSPARAMS_N_PCC_MASK #define USBHS_HCSPARAMS_N_PCC_SHIFT USB_HCSPARAMS_N_PCC_SHIFT #define USBHS_HCSPARAMS_N_PCC(x) USB_HCSPARAMS_N_PCC(x) #define USBHS_HCSPARAMS_N_CC_MASK USB_HCSPARAMS_N_CC_MASK #define USBHS_HCSPARAMS_N_CC_SHIFT USB_HCSPARAMS_N_CC_SHIFT #define USBHS_HCSPARAMS_N_CC(x) USB_HCSPARAMS_N_CC(x) #define USBHS_HCSPARAMS_PI_MASK USB_HCSPARAMS_PI_MASK #define USBHS_HCSPARAMS_PI_SHIFT USB_HCSPARAMS_PI_SHIFT #define USBHS_HCSPARAMS_PI(x) USB_HCSPARAMS_PI(x) #define USBHS_HCSPARAMS_N_PTT_MASK USB_HCSPARAMS_N_PTT_MASK #define USBHS_HCSPARAMS_N_PTT_SHIFT USB_HCSPARAMS_N_PTT_SHIFT #define USBHS_HCSPARAMS_N_PTT(x) USB_HCSPARAMS_N_PTT(x) #define USBHS_HCSPARAMS_N_TT_MASK USB_HCSPARAMS_N_TT_MASK #define USBHS_HCSPARAMS_N_TT_SHIFT USB_HCSPARAMS_N_TT_SHIFT #define USBHS_HCSPARAMS_N_TT(x) USB_HCSPARAMS_N_TT(x) #define USBHS_HCCPARAMS_ADC_MASK USB_HCCPARAMS_ADC_MASK #define USBHS_HCCPARAMS_ADC_SHIFT USB_HCCPARAMS_ADC_SHIFT #define USBHS_HCCPARAMS_ADC(x) USB_HCCPARAMS_ADC(x) #define USBHS_HCCPARAMS_PFL_MASK USB_HCCPARAMS_PFL_MASK #define USBHS_HCCPARAMS_PFL_SHIFT USB_HCCPARAMS_PFL_SHIFT #define USBHS_HCCPARAMS_PFL(x) USB_HCCPARAMS_PFL(x) #define USBHS_HCCPARAMS_ASP_MASK USB_HCCPARAMS_ASP_MASK #define USBHS_HCCPARAMS_ASP_SHIFT USB_HCCPARAMS_ASP_SHIFT #define USBHS_HCCPARAMS_ASP(x) USB_HCCPARAMS_ASP(x) #define USBHS_HCCPARAMS_IST_MASK USB_HCCPARAMS_IST_MASK #define USBHS_HCCPARAMS_IST_SHIFT USB_HCCPARAMS_IST_SHIFT #define USBHS_HCCPARAMS_IST(x) USB_HCCPARAMS_IST(x) #define USBHS_HCCPARAMS_EECP_MASK USB_HCCPARAMS_EECP_MASK #define USBHS_HCCPARAMS_EECP_SHIFT USB_HCCPARAMS_EECP_SHIFT #define USBHS_HCCPARAMS_EECP(x) USB_HCCPARAMS_EECP(x) #define USBHS_DCIVERSION_DCIVERSION_MASK USB_DCIVERSION_DCIVERSION_MASK #define USBHS_DCIVERSION_DCIVERSION_SHIFT USB_DCIVERSION_DCIVERSION_SHIFT #define USBHS_DCIVERSION_DCIVERSION(x) USB_DCIVERSION_DCIVERSION(x) #define USBHS_DCCPARAMS_DEN_MASK USB_DCCPARAMS_DEN_MASK #define USBHS_DCCPARAMS_DEN_SHIFT USB_DCCPARAMS_DEN_SHIFT #define USBHS_DCCPARAMS_DEN(x) USB_DCCPARAMS_DEN(x) #define USBHS_DCCPARAMS_DC_MASK USB_DCCPARAMS_DC_MASK #define USBHS_DCCPARAMS_DC_SHIFT USB_DCCPARAMS_DC_SHIFT #define USBHS_DCCPARAMS_DC(x) USB_DCCPARAMS_DC(x) #define USBHS_DCCPARAMS_HC_MASK USB_DCCPARAMS_HC_MASK #define USBHS_DCCPARAMS_HC_SHIFT USB_DCCPARAMS_HC_SHIFT #define USBHS_DCCPARAMS_HC(x) USB_DCCPARAMS_HC(x) #define USBHS_USBCMD_RS_MASK USB_USBCMD_RS_MASK #define USBHS_USBCMD_RS_SHIFT USB_USBCMD_RS_SHIFT #define USBHS_USBCMD_RS(x) USB_USBCMD_RS(x) #define USBHS_USBCMD_RST_MASK USB_USBCMD_RST_MASK #define USBHS_USBCMD_RST_SHIFT USB_USBCMD_RST_SHIFT #define USBHS_USBCMD_RST(x) USB_USBCMD_RST(x) #define USBHS_USBCMD_FS_MASK USB_USBCMD_FS_1_MASK #define USBHS_USBCMD_FS_SHIFT USB_USBCMD_FS_1_SHIFT #define USBHS_USBCMD_FS(x) USB_USBCMD_FS_1(x) #define USBHS_USBCMD_PSE_MASK USB_USBCMD_PSE_MASK #define USBHS_USBCMD_PSE_SHIFT USB_USBCMD_PSE_SHIFT #define USBHS_USBCMD_PSE(x) USB_USBCMD_PSE(x) #define USBHS_USBCMD_ASE_MASK USB_USBCMD_ASE_MASK #define USBHS_USBCMD_ASE_SHIFT USB_USBCMD_ASE_SHIFT #define USBHS_USBCMD_ASE(x) USB_USBCMD_ASE(x) #define USBHS_USBCMD_IAA_MASK USB_USBCMD_IAA_MASK #define USBHS_USBCMD_IAA_SHIFT USB_USBCMD_IAA_SHIFT #define USBHS_USBCMD_IAA(x) USB_USBCMD_IAA(x) #define USBHS_USBCMD_ASP_MASK USB_USBCMD_ASP_MASK #define USBHS_USBCMD_ASP_SHIFT USB_USBCMD_ASP_SHIFT #define USBHS_USBCMD_ASP(x) USB_USBCMD_ASP(x) #define USBHS_USBCMD_ASPE_MASK USB_USBCMD_ASPE_MASK #define USBHS_USBCMD_ASPE_SHIFT USB_USBCMD_ASPE_SHIFT #define USBHS_USBCMD_ASPE(x) USB_USBCMD_ASPE(x) #define USBHS_USBCMD_ATDTW_MASK USB_USBCMD_ATDTW_MASK #define USBHS_USBCMD_ATDTW_SHIFT USB_USBCMD_ATDTW_SHIFT #define USBHS_USBCMD_ATDTW(x) USB_USBCMD_ATDTW(x) #define USBHS_USBCMD_SUTW_MASK USB_USBCMD_SUTW_MASK #define USBHS_USBCMD_SUTW_SHIFT USB_USBCMD_SUTW_SHIFT #define USBHS_USBCMD_SUTW(x) USB_USBCMD_SUTW(x) #define USBHS_USBCMD_FS2_MASK USB_USBCMD_FS_2_MASK #define USBHS_USBCMD_FS2_SHIFT USB_USBCMD_FS_2_SHIFT #define USBHS_USBCMD_FS2(x) USB_USBCMD_FS_2(x) #define USBHS_USBCMD_ITC_MASK USB_USBCMD_ITC_MASK #define USBHS_USBCMD_ITC_SHIFT USB_USBCMD_ITC_SHIFT #define USBHS_USBCMD_ITC(x) USB_USBCMD_ITC(x) #define USBHS_USBSTS_UI_MASK USB_USBSTS_UI_MASK #define USBHS_USBSTS_UI_SHIFT USB_USBSTS_UI_SHIFT #define USBHS_USBSTS_UI(x) USB_USBSTS_UI(x) #define USBHS_USBSTS_UEI_MASK USB_USBSTS_UEI_MASK #define USBHS_USBSTS_UEI_SHIFT USB_USBSTS_UEI_SHIFT #define USBHS_USBSTS_UEI(x) USB_USBSTS_UEI(x) #define USBHS_USBSTS_PCI_MASK USB_USBSTS_PCI_MASK #define USBHS_USBSTS_PCI_SHIFT USB_USBSTS_PCI_SHIFT #define USBHS_USBSTS_PCI(x) USB_USBSTS_PCI(x) #define USBHS_USBSTS_FRI_MASK USB_USBSTS_FRI_MASK #define USBHS_USBSTS_FRI_SHIFT USB_USBSTS_FRI_SHIFT #define USBHS_USBSTS_FRI(x) USB_USBSTS_FRI(x) #define USBHS_USBSTS_SEI_MASK USB_USBSTS_SEI_MASK #define USBHS_USBSTS_SEI_SHIFT USB_USBSTS_SEI_SHIFT #define USBHS_USBSTS_SEI(x) USB_USBSTS_SEI(x) #define USBHS_USBSTS_AAI_MASK USB_USBSTS_AAI_MASK #define USBHS_USBSTS_AAI_SHIFT USB_USBSTS_AAI_SHIFT #define USBHS_USBSTS_AAI(x) USB_USBSTS_AAI(x) #define USBHS_USBSTS_URI_MASK USB_USBSTS_URI_MASK #define USBHS_USBSTS_URI_SHIFT USB_USBSTS_URI_SHIFT #define USBHS_USBSTS_URI(x) USB_USBSTS_URI(x) #define USBHS_USBSTS_SRI_MASK USB_USBSTS_SRI_MASK #define USBHS_USBSTS_SRI_SHIFT USB_USBSTS_SRI_SHIFT #define USBHS_USBSTS_SRI(x) USB_USBSTS_SRI(x) #define USBHS_USBSTS_SLI_MASK USB_USBSTS_SLI_MASK #define USBHS_USBSTS_SLI_SHIFT USB_USBSTS_SLI_SHIFT #define USBHS_USBSTS_SLI(x) USB_USBSTS_SLI(x) #define USBHS_USBSTS_ULPII_MASK USB_USBSTS_ULPII_MASK #define USBHS_USBSTS_ULPII_SHIFT USB_USBSTS_ULPII_SHIFT #define USBHS_USBSTS_ULPII(x) USB_USBSTS_ULPII(x) #define USBHS_USBSTS_HCH_MASK USB_USBSTS_HCH_MASK #define USBHS_USBSTS_HCH_SHIFT USB_USBSTS_HCH_SHIFT #define USBHS_USBSTS_HCH(x) USB_USBSTS_HCH(x) #define USBHS_USBSTS_RCL_MASK USB_USBSTS_RCL_MASK #define USBHS_USBSTS_RCL_SHIFT USB_USBSTS_RCL_SHIFT #define USBHS_USBSTS_RCL(x) USB_USBSTS_RCL(x) #define USBHS_USBSTS_PS_MASK USB_USBSTS_PS_MASK #define USBHS_USBSTS_PS_SHIFT USB_USBSTS_PS_SHIFT #define USBHS_USBSTS_PS(x) USB_USBSTS_PS(x) #define USBHS_USBSTS_AS_MASK USB_USBSTS_AS_MASK #define USBHS_USBSTS_AS_SHIFT USB_USBSTS_AS_SHIFT #define USBHS_USBSTS_AS(x) USB_USBSTS_AS(x) #define USBHS_USBSTS_NAKI_MASK USB_USBSTS_NAKI_MASK #define USBHS_USBSTS_NAKI_SHIFT USB_USBSTS_NAKI_SHIFT #define USBHS_USBSTS_NAKI(x) USB_USBSTS_NAKI(x) #define USBHS_USBSTS_TI0_MASK USB_USBSTS_TI0_MASK #define USBHS_USBSTS_TI0_SHIFT USB_USBSTS_TI0_SHIFT #define USBHS_USBSTS_TI0(x) USB_USBSTS_TI0(x) #define USBHS_USBSTS_TI1_MASK USB_USBSTS_TI1_MASK #define USBHS_USBSTS_TI1_SHIFT USB_USBSTS_TI1_SHIFT #define USBHS_USBSTS_TI1(x) USB_USBSTS_TI1(x) #define USBHS_USBINTR_UE_MASK USB_USBINTR_UE_MASK #define USBHS_USBINTR_UE_SHIFT USB_USBINTR_UE_SHIFT #define USBHS_USBINTR_UE(x) USB_USBINTR_UE(x) #define USBHS_USBINTR_UEE_MASK USB_USBINTR_UEE_MASK #define USBHS_USBINTR_UEE_SHIFT USB_USBINTR_UEE_SHIFT #define USBHS_USBINTR_UEE(x) USB_USBINTR_UEE(x) #define USBHS_USBINTR_PCE_MASK USB_USBINTR_PCE_MASK #define USBHS_USBINTR_PCE_SHIFT USB_USBINTR_PCE_SHIFT #define USBHS_USBINTR_PCE(x) USB_USBINTR_PCE(x) #define USBHS_USBINTR_FRE_MASK USB_USBINTR_FRE_MASK #define USBHS_USBINTR_FRE_SHIFT USB_USBINTR_FRE_SHIFT #define USBHS_USBINTR_FRE(x) USB_USBINTR_FRE(x) #define USBHS_USBINTR_SEE_MASK USB_USBINTR_SEE_MASK #define USBHS_USBINTR_SEE_SHIFT USB_USBINTR_SEE_SHIFT #define USBHS_USBINTR_SEE(x) USB_USBINTR_SEE(x) #define USBHS_USBINTR_AAE_MASK USB_USBINTR_AAE_MASK #define USBHS_USBINTR_AAE_SHIFT USB_USBINTR_AAE_SHIFT #define USBHS_USBINTR_AAE(x) USB_USBINTR_AAE(x) #define USBHS_USBINTR_URE_MASK USB_USBINTR_URE_MASK #define USBHS_USBINTR_URE_SHIFT USB_USBINTR_URE_SHIFT #define USBHS_USBINTR_URE(x) USB_USBINTR_URE(x) #define USBHS_USBINTR_SRE_MASK USB_USBINTR_SRE_MASK #define USBHS_USBINTR_SRE_SHIFT USB_USBINTR_SRE_SHIFT #define USBHS_USBINTR_SRE(x) USB_USBINTR_SRE(x) #define USBHS_USBINTR_SLE_MASK USB_USBINTR_SLE_MASK #define USBHS_USBINTR_SLE_SHIFT USB_USBINTR_SLE_SHIFT #define USBHS_USBINTR_SLE(x) USB_USBINTR_SLE(x) #define USBHS_USBINTR_ULPIE_MASK USB_USBINTR_ULPIE_MASK #define USBHS_USBINTR_ULPIE_SHIFT USB_USBINTR_ULPIE_SHIFT #define USBHS_USBINTR_ULPIE(x) USB_USBINTR_ULPIE(x) #define USBHS_USBINTR_NAKE_MASK USB_USBINTR_NAKE_MASK #define USBHS_USBINTR_NAKE_SHIFT USB_USBINTR_NAKE_SHIFT #define USBHS_USBINTR_NAKE(x) USB_USBINTR_NAKE(x) #define USBHS_USBINTR_UAIE_MASK USB_USBINTR_UAIE_MASK #define USBHS_USBINTR_UAIE_SHIFT USB_USBINTR_UAIE_SHIFT #define USBHS_USBINTR_UAIE(x) USB_USBINTR_UAIE(x) #define USBHS_USBINTR_UPIE_MASK USB_USBINTR_UPIE_MASK #define USBHS_USBINTR_UPIE_SHIFT USB_USBINTR_UPIE_SHIFT #define USBHS_USBINTR_UPIE(x) USB_USBINTR_UPIE(x) #define USBHS_USBINTR_TIE0_MASK USB_USBINTR_TIE0_MASK #define USBHS_USBINTR_TIE0_SHIFT USB_USBINTR_TIE0_SHIFT #define USBHS_USBINTR_TIE0(x) USB_USBINTR_TIE0(x) #define USBHS_USBINTR_TIE1_MASK USB_USBINTR_TIE1_MASK #define USBHS_USBINTR_TIE1_SHIFT USB_USBINTR_TIE1_SHIFT #define USBHS_USBINTR_TIE1(x) USB_USBINTR_TIE1(x) #define USBHS_FRINDEX_FRINDEX_MASK USB_FRINDEX_FRINDEX_MASK #define USBHS_FRINDEX_FRINDEX_SHIFT USB_FRINDEX_FRINDEX_SHIFT #define USBHS_FRINDEX_FRINDEX(x) USB_FRINDEX_FRINDEX(x) #define USBHS_DEVICEADDR_USBADRA_MASK USB_DEVICEADDR_USBADRA_MASK #define USBHS_DEVICEADDR_USBADRA_SHIFT USB_DEVICEADDR_USBADRA_SHIFT #define USBHS_DEVICEADDR_USBADRA(x) USB_DEVICEADDR_USBADRA(x) #define USBHS_DEVICEADDR_USBADR_MASK USB_DEVICEADDR_USBADR_MASK #define USBHS_DEVICEADDR_USBADR_SHIFT USB_DEVICEADDR_USBADR_SHIFT #define USBHS_DEVICEADDR_USBADR(x) USB_DEVICEADDR_USBADR(x) #define USBHS_PERIODICLISTBASE_PERBASE_MASK USB_PERIODICLISTBASE_BASEADR_MASK #define USBHS_PERIODICLISTBASE_PERBASE_SHIFT USB_PERIODICLISTBASE_BASEADR_SHIFT #define USBHS_PERIODICLISTBASE_PERBASE(x) USB_PERIODICLISTBASE_BASEADR(x) #define USBHS_ASYNCLISTADDR_ASYBASE_MASK USB_ASYNCLISTADDR_ASYBASE_MASK #define USBHS_ASYNCLISTADDR_ASYBASE_SHIFT USB_ASYNCLISTADDR_ASYBASE_SHIFT #define USBHS_ASYNCLISTADDR_ASYBASE(x) USB_ASYNCLISTADDR_ASYBASE(x) #define USBHS_EPLISTADDR_EPBASE_MASK USB_ENDPTLISTADDR_EPBASE_MASK #define USBHS_EPLISTADDR_EPBASE_SHIFT USB_ENDPTLISTADDR_EPBASE_SHIFT #define USBHS_EPLISTADDR_EPBASE(x) USB_ENDPTLISTADDR_EPBASE(x) #define USBHS_BURSTSIZE_RXPBURST_MASK USB_BURSTSIZE_RXPBURST_MASK #define USBHS_BURSTSIZE_RXPBURST_SHIFT USB_BURSTSIZE_RXPBURST_SHIFT #define USBHS_BURSTSIZE_RXPBURST(x) USB_BURSTSIZE_RXPBURST(x) #define USBHS_BURSTSIZE_TXPBURST_MASK USB_BURSTSIZE_TXPBURST_MASK #define USBHS_BURSTSIZE_TXPBURST_SHIFT USB_BURSTSIZE_TXPBURST_SHIFT #define USBHS_BURSTSIZE_TXPBURST(x) USB_BURSTSIZE_TXPBURST(x) #define USBHS_TXFILLTUNING_TXSCHOH_MASK USB_TXFILLTUNING_TXSCHOH_MASK #define USBHS_TXFILLTUNING_TXSCHOH_SHIFT USB_TXFILLTUNING_TXSCHOH_SHIFT #define USBHS_TXFILLTUNING_TXSCHOH(x) USB_TXFILLTUNING_TXSCHOH(x) #define USBHS_TXFILLTUNING_TXSCHHEALTH_MASK USB_TXFILLTUNING_TXSCHHEALTH_MASK #define USBHS_TXFILLTUNING_TXSCHHEALTH_SHIFT USB_TXFILLTUNING_TXSCHHEALTH_SHIFT #define USBHS_TXFILLTUNING_TXSCHHEALTH(x) USB_TXFILLTUNING_TXSCHHEALTH(x) #define USBHS_TXFILLTUNING_TXFIFOTHRES_MASK USB_TXFILLTUNING_TXFIFOTHRES_MASK #define USBHS_TXFILLTUNING_TXFIFOTHRES_SHIFT USB_TXFILLTUNING_TXFIFOTHRES_SHIFT #define USBHS_TXFILLTUNING_TXFIFOTHRES(x) USB_TXFILLTUNING_TXFIFOTHRES(x) #define USBHS_ENDPTNAK_EPRN_MASK USB_ENDPTNAK_EPRN_MASK #define USBHS_ENDPTNAK_EPRN_SHIFT USB_ENDPTNAK_EPRN_SHIFT #define USBHS_ENDPTNAK_EPRN(x) USB_ENDPTNAK_EPRN(x) #define USBHS_ENDPTNAK_EPTN_MASK USB_ENDPTNAK_EPTN_MASK #define USBHS_ENDPTNAK_EPTN_SHIFT USB_ENDPTNAK_EPTN_SHIFT #define USBHS_ENDPTNAK_EPTN(x) USB_ENDPTNAK_EPTN(x) #define USBHS_ENDPTNAKEN_EPRNE_MASK USB_ENDPTNAKEN_EPRNE_MASK #define USBHS_ENDPTNAKEN_EPRNE_SHIFT USB_ENDPTNAKEN_EPRNE_SHIFT #define USBHS_ENDPTNAKEN_EPRNE(x) USB_ENDPTNAKEN_EPRNE(x) #define USBHS_ENDPTNAKEN_EPTNE_MASK USB_ENDPTNAKEN_EPTNE_MASK #define USBHS_ENDPTNAKEN_EPTNE_SHIFT USB_ENDPTNAKEN_EPTNE_SHIFT #define USBHS_ENDPTNAKEN_EPTNE(x) USB_ENDPTNAKEN_EPTNE(x) #define USBHS_CONFIGFLAG_CF_MASK USB_CONFIGFLAG_CF_MASK #define USBHS_CONFIGFLAG_CF_SHIFT USB_CONFIGFLAG_CF_SHIFT #define USBHS_CONFIGFLAG_CF(x) USB_CONFIGFLAG_CF(x) #define USBHS_PORTSC1_CCS_MASK USB_PORTSC1_CCS_MASK #define USBHS_PORTSC1_CCS_SHIFT USB_PORTSC1_CCS_SHIFT #define USBHS_PORTSC1_CCS(x) USB_PORTSC1_CCS(x) #define USBHS_PORTSC1_CSC_MASK USB_PORTSC1_CSC_MASK #define USBHS_PORTSC1_CSC_SHIFT USB_PORTSC1_CSC_SHIFT #define USBHS_PORTSC1_CSC(x) USB_PORTSC1_CSC(x) #define USBHS_PORTSC1_PE_MASK USB_PORTSC1_PE_MASK #define USBHS_PORTSC1_PE_SHIFT USB_PORTSC1_PE_SHIFT #define USBHS_PORTSC1_PE(x) USB_PORTSC1_PE(x) #define USBHS_PORTSC1_PEC_MASK USB_PORTSC1_PEC_MASK #define USBHS_PORTSC1_PEC_SHIFT USB_PORTSC1_PEC_SHIFT #define USBHS_PORTSC1_PEC(x) USB_PORTSC1_PEC(x) #define USBHS_PORTSC1_OCA_MASK USB_PORTSC1_OCA_MASK #define USBHS_PORTSC1_OCA_SHIFT USB_PORTSC1_OCA_SHIFT #define USBHS_PORTSC1_OCA(x) USB_PORTSC1_OCA(x) #define USBHS_PORTSC1_OCC_MASK USB_PORTSC1_OCC_MASK #define USBHS_PORTSC1_OCC_SHIFT USB_PORTSC1_OCC_SHIFT #define USBHS_PORTSC1_OCC(x) USB_PORTSC1_OCC(x) #define USBHS_PORTSC1_FPR_MASK USB_PORTSC1_FPR_MASK #define USBHS_PORTSC1_FPR_SHIFT USB_PORTSC1_FPR_SHIFT #define USBHS_PORTSC1_FPR(x) USB_PORTSC1_FPR(x) #define USBHS_PORTSC1_SUSP_MASK USB_PORTSC1_SUSP_MASK #define USBHS_PORTSC1_SUSP_SHIFT USB_PORTSC1_SUSP_SHIFT #define USBHS_PORTSC1_SUSP(x) USB_PORTSC1_SUSP(x) #define USBHS_PORTSC1_PR_MASK USB_PORTSC1_PR_MASK #define USBHS_PORTSC1_PR_SHIFT USB_PORTSC1_PR_SHIFT #define USBHS_PORTSC1_PR(x) USB_PORTSC1_PR(x) #define USBHS_PORTSC1_HSP_MASK USB_PORTSC1_HSP_MASK #define USBHS_PORTSC1_HSP_SHIFT USB_PORTSC1_HSP_SHIFT #define USBHS_PORTSC1_HSP(x) USB_PORTSC1_HSP(x) #define USBHS_PORTSC1_LS_MASK USB_PORTSC1_LS_MASK #define USBHS_PORTSC1_LS_SHIFT USB_PORTSC1_LS_SHIFT #define USBHS_PORTSC1_LS(x) USB_PORTSC1_LS(x) #define USBHS_PORTSC1_PP_MASK USB_PORTSC1_PP_MASK #define USBHS_PORTSC1_PP_SHIFT USB_PORTSC1_PP_SHIFT #define USBHS_PORTSC1_PP(x) USB_PORTSC1_PP(x) #define USBHS_PORTSC1_PO_MASK USB_PORTSC1_PO_MASK #define USBHS_PORTSC1_PO_SHIFT USB_PORTSC1_PO_SHIFT #define USBHS_PORTSC1_PO(x) USB_PORTSC1_PO(x) #define USBHS_PORTSC1_PIC_MASK USB_PORTSC1_PIC_MASK #define USBHS_PORTSC1_PIC_SHIFT USB_PORTSC1_PIC_SHIFT #define USBHS_PORTSC1_PIC(x) USB_PORTSC1_PIC(x) #define USBHS_PORTSC1_PTC_MASK USB_PORTSC1_PTC_MASK #define USBHS_PORTSC1_PTC_SHIFT USB_PORTSC1_PTC_SHIFT #define USBHS_PORTSC1_PTC(x) USB_PORTSC1_PTC(x) #define USBHS_PORTSC1_WKCN_MASK USB_PORTSC1_WKCN_MASK #define USBHS_PORTSC1_WKCN_SHIFT USB_PORTSC1_WKCN_SHIFT #define USBHS_PORTSC1_WKCN(x) USB_PORTSC1_WKCN(x) #define USBHS_PORTSC1_WKDS_MASK USB_PORTSC1_WKDC_MASK #define USBHS_PORTSC1_WKDS_SHIFT USB_PORTSC1_WKDC_SHIFT #define USBHS_PORTSC1_WKDS(x) USB_PORTSC1_WKDC(x) #define USBHS_PORTSC1_WKOC_MASK USB_PORTSC1_WKOC_MASK #define USBHS_PORTSC1_WKOC_SHIFT USB_PORTSC1_WKOC_SHIFT #define USBHS_PORTSC1_WKOC(x) USB_PORTSC1_WKOC(x) #define USBHS_PORTSC1_PHCD_MASK USB_PORTSC1_PHCD_MASK #define USBHS_PORTSC1_PHCD_SHIFT USB_PORTSC1_PHCD_SHIFT #define USBHS_PORTSC1_PHCD(x) USB_PORTSC1_PHCD(x) #define USBHS_PORTSC1_PFSC_MASK USB_PORTSC1_PFSC_MASK #define USBHS_PORTSC1_PFSC_SHIFT USB_PORTSC1_PFSC_SHIFT #define USBHS_PORTSC1_PFSC(x) USB_PORTSC1_PFSC(x) #define USBHS_PORTSC1_PTS2_MASK USB_PORTSC1_PTS_2_MASK #define USBHS_PORTSC1_PTS2_SHIFT USB_PORTSC1_PTS_2_SHIFT #define USBHS_PORTSC1_PTS2(x) USB_PORTSC1_PTS_2(x) #define USBHS_PORTSC1_PSPD_MASK USB_PORTSC1_PSPD_MASK #define USBHS_PORTSC1_PSPD_SHIFT USB_PORTSC1_PSPD_SHIFT #define USBHS_PORTSC1_PSPD(x) USB_PORTSC1_PSPD(x) #define USBHS_PORTSC1_PTW_MASK USB_PORTSC1_PTW_MASK #define USBHS_PORTSC1_PTW_SHIFT USB_PORTSC1_PTW_SHIFT #define USBHS_PORTSC1_PTW(x) USB_PORTSC1_PTW(x) #define USBHS_PORTSC1_STS_MASK USB_PORTSC1_STS_MASK #define USBHS_PORTSC1_STS_SHIFT USB_PORTSC1_STS_SHIFT #define USBHS_PORTSC1_STS(x) USB_PORTSC1_STS(x) #define USBHS_PORTSC1_PTS_MASK USB_PORTSC1_PTS_1_MASK #define USBHS_PORTSC1_PTS_SHIFT USB_PORTSC1_PTS_1_SHIFT #define USBHS_PORTSC1_PTS(x) USB_PORTSC1_PTS_1(x) #define USBHS_OTGSC_VD_MASK USB_OTGSC_VD_MASK #define USBHS_OTGSC_VD_SHIFT USB_OTGSC_VD_SHIFT #define USBHS_OTGSC_VD(x) USB_OTGSC_VD(x) #define USBHS_OTGSC_VC_MASK USB_OTGSC_VC_MASK #define USBHS_OTGSC_VC_SHIFT USB_OTGSC_VC_SHIFT #define USBHS_OTGSC_VC(x) USB_OTGSC_VC(x) #define USBHS_OTGSC_OT_MASK USB_OTGSC_OT_MASK #define USBHS_OTGSC_OT_SHIFT USB_OTGSC_OT_SHIFT #define USBHS_OTGSC_OT(x) USB_OTGSC_OT(x) #define USBHS_OTGSC_DP_MASK USB_OTGSC_DP_MASK #define USBHS_OTGSC_DP_SHIFT USB_OTGSC_DP_SHIFT #define USBHS_OTGSC_DP(x) USB_OTGSC_DP(x) #define USBHS_OTGSC_IDPU_MASK USB_OTGSC_IDPU_MASK #define USBHS_OTGSC_IDPU_SHIFT USB_OTGSC_IDPU_SHIFT #define USBHS_OTGSC_IDPU(x) USB_OTGSC_IDPU(x) #define USBHS_OTGSC_ID_MASK USB_OTGSC_ID_MASK #define USBHS_OTGSC_ID_SHIFT USB_OTGSC_ID_SHIFT #define USBHS_OTGSC_ID(x) USB_OTGSC_ID(x) #define USBHS_OTGSC_AVV_MASK USB_OTGSC_AVV_MASK #define USBHS_OTGSC_AVV_SHIFT USB_OTGSC_AVV_SHIFT #define USBHS_OTGSC_AVV(x) USB_OTGSC_AVV(x) #define USBHS_OTGSC_ASV_MASK USB_OTGSC_ASV_MASK #define USBHS_OTGSC_ASV_SHIFT USB_OTGSC_ASV_SHIFT #define USBHS_OTGSC_ASV(x) USB_OTGSC_ASV(x) #define USBHS_OTGSC_BSV_MASK USB_OTGSC_BSV_MASK #define USBHS_OTGSC_BSV_SHIFT USB_OTGSC_BSV_SHIFT #define USBHS_OTGSC_BSV(x) USB_OTGSC_BSV(x) #define USBHS_OTGSC_BSE_MASK USB_OTGSC_BSE_MASK #define USBHS_OTGSC_BSE_SHIFT USB_OTGSC_BSE_SHIFT #define USBHS_OTGSC_BSE(x) USB_OTGSC_BSE(x) #define USBHS_OTGSC_MST_MASK USB_OTGSC_TOG_1MS_MASK #define USBHS_OTGSC_MST_SHIFT USB_OTGSC_TOG_1MS_SHIFT #define USBHS_OTGSC_MST(x) USB_OTGSC_TOG_1MS(x) #define USBHS_OTGSC_DPS_MASK USB_OTGSC_DPS_MASK #define USBHS_OTGSC_DPS_SHIFT USB_OTGSC_DPS_SHIFT #define USBHS_OTGSC_DPS(x) USB_OTGSC_DPS(x) #define USBHS_OTGSC_IDIS_MASK USB_OTGSC_IDIS_MASK #define USBHS_OTGSC_IDIS_SHIFT USB_OTGSC_IDIS_SHIFT #define USBHS_OTGSC_IDIS(x) USB_OTGSC_IDIS(x) #define USBHS_OTGSC_AVVIS_MASK USB_OTGSC_AVVIS_MASK #define USBHS_OTGSC_AVVIS_SHIFT USB_OTGSC_AVVIS_SHIFT #define USBHS_OTGSC_AVVIS(x) USB_OTGSC_AVVIS(x) #define USBHS_OTGSC_ASVIS_MASK USB_OTGSC_ASVIS_MASK #define USBHS_OTGSC_ASVIS_SHIFT USB_OTGSC_ASVIS_SHIFT #define USBHS_OTGSC_ASVIS(x) USB_OTGSC_ASVIS(x) #define USBHS_OTGSC_BSVIS_MASK USB_OTGSC_BSVIS_MASK #define USBHS_OTGSC_BSVIS_SHIFT USB_OTGSC_BSVIS_SHIFT #define USBHS_OTGSC_BSVIS(x) USB_OTGSC_BSVIS(x) #define USBHS_OTGSC_BSEIS_MASK USB_OTGSC_BSEIS_MASK #define USBHS_OTGSC_BSEIS_SHIFT USB_OTGSC_BSEIS_SHIFT #define USBHS_OTGSC_BSEIS(x) USB_OTGSC_BSEIS(x) #define USBHS_OTGSC_MSS_MASK USB_OTGSC_STATUS_1MS_MASK #define USBHS_OTGSC_MSS_SHIFT USB_OTGSC_STATUS_1MS_SHIFT #define USBHS_OTGSC_MSS(x) USB_OTGSC_STATUS_1MS(x) #define USBHS_OTGSC_DPIS_MASK USB_OTGSC_DPIS_MASK #define USBHS_OTGSC_DPIS_SHIFT USB_OTGSC_DPIS_SHIFT #define USBHS_OTGSC_DPIS(x) USB_OTGSC_DPIS(x) #define USBHS_OTGSC_IDIE_MASK USB_OTGSC_IDIE_MASK #define USBHS_OTGSC_IDIE_SHIFT USB_OTGSC_IDIE_SHIFT #define USBHS_OTGSC_IDIE(x) USB_OTGSC_IDIE(x) #define USBHS_OTGSC_AVVIE_MASK USB_OTGSC_AVVIE_MASK #define USBHS_OTGSC_AVVIE_SHIFT USB_OTGSC_AVVIE_SHIFT #define USBHS_OTGSC_AVVIE(x) USB_OTGSC_AVVIE(x) #define USBHS_OTGSC_ASVIE_MASK USB_OTGSC_ASVIE_MASK #define USBHS_OTGSC_ASVIE_SHIFT USB_OTGSC_ASVIE_SHIFT #define USBHS_OTGSC_ASVIE(x) USB_OTGSC_ASVIE(x) #define USBHS_OTGSC_BSVIE_MASK USB_OTGSC_BSVIE_MASK #define USBHS_OTGSC_BSVIE_SHIFT USB_OTGSC_BSVIE_SHIFT #define USBHS_OTGSC_BSVIE(x) USB_OTGSC_BSVIE(x) #define USBHS_OTGSC_BSEIE_MASK USB_OTGSC_BSEIE_MASK #define USBHS_OTGSC_BSEIE_SHIFT USB_OTGSC_BSEIE_SHIFT #define USBHS_OTGSC_BSEIE(x) USB_OTGSC_BSEIE(x) #define USBHS_OTGSC_MSE_MASK USB_OTGSC_EN_1MS_MASK #define USBHS_OTGSC_MSE_SHIFT USB_OTGSC_EN_1MS_SHIFT #define USBHS_OTGSC_MSE(x) USB_OTGSC_EN_1MS(x) #define USBHS_OTGSC_DPIE_MASK USB_OTGSC_DPIE_MASK #define USBHS_OTGSC_DPIE_SHIFT USB_OTGSC_DPIE_SHIFT #define USBHS_OTGSC_DPIE(x) USB_OTGSC_DPIE(x) #define USBHS_USBMODE_CM_MASK USB_USBMODE_CM_MASK #define USBHS_USBMODE_CM_SHIFT USB_USBMODE_CM_SHIFT #define USBHS_USBMODE_CM(x) USB_USBMODE_CM(x) #define USBHS_USBMODE_ES_MASK USB_USBMODE_ES_MASK #define USBHS_USBMODE_ES_SHIFT USB_USBMODE_ES_SHIFT #define USBHS_USBMODE_ES(x) USB_USBMODE_ES(x) #define USBHS_USBMODE_SLOM_MASK USB_USBMODE_SLOM_MASK #define USBHS_USBMODE_SLOM_SHIFT USB_USBMODE_SLOM_SHIFT #define USBHS_USBMODE_SLOM(x) USB_USBMODE_SLOM(x) #define USBHS_USBMODE_SDIS_MASK USB_USBMODE_SDIS_MASK #define USBHS_USBMODE_SDIS_SHIFT USB_USBMODE_SDIS_SHIFT #define USBHS_USBMODE_SDIS(x) USB_USBMODE_SDIS(x) #define USBHS_EPSETUPSR_EPSETUPSTAT_MASK USB_ENDPTSETUPSTAT_ENDPTSETUPSTAT_MASK #define USBHS_EPSETUPSR_EPSETUPSTAT_SHIFT USB_ENDPTSETUPSTAT_ENDPTSETUPSTAT_SHIFT #define USBHS_EPSETUPSR_EPSETUPSTAT(x) USB_ENDPTSETUPSTAT_ENDPTSETUPSTAT(x) #define USBHS_EPPRIME_PERB_MASK USB_ENDPTPRIME_PERB_MASK #define USBHS_EPPRIME_PERB_SHIFT USB_ENDPTPRIME_PERB_SHIFT #define USBHS_EPPRIME_PERB(x) USB_ENDPTPRIME_PERB(x) #define USBHS_EPPRIME_PETB_MASK USB_ENDPTPRIME_PETB_MASK #define USBHS_EPPRIME_PETB_SHIFT USB_ENDPTPRIME_PETB_SHIFT #define USBHS_EPPRIME_PETB(x) USB_ENDPTPRIME_PETB(x) #define USBHS_EPFLUSH_FERB_MASK USB_ENDPTFLUSH_FERB_MASK #define USBHS_EPFLUSH_FERB_SHIFT USB_ENDPTFLUSH_FERB_SHIFT #define USBHS_EPFLUSH_FERB(x) USB_ENDPTFLUSH_FERB(x) #define USBHS_EPFLUSH_FETB_MASK USB_ENDPTFLUSH_FETB_MASK #define USBHS_EPFLUSH_FETB_SHIFT USB_ENDPTFLUSH_FETB_SHIFT #define USBHS_EPFLUSH_FETB(x) USB_ENDPTFLUSH_FETB(x) #define USBHS_EPSR_ERBR_MASK USB_ENDPTSTAT_ERBR_MASK #define USBHS_EPSR_ERBR_SHIFT USB_ENDPTSTAT_ERBR_SHIFT #define USBHS_EPSR_ERBR(x) USB_ENDPTSTAT_ERBR(x) #define USBHS_EPSR_ETBR_MASK USB_ENDPTSTAT_ETBR_MASK #define USBHS_EPSR_ETBR_SHIFT USB_ENDPTSTAT_ETBR_SHIFT #define USBHS_EPSR_ETBR(x) USB_ENDPTSTAT_ETBR(x) #define USBHS_EPCOMPLETE_ERCE_MASK USB_ENDPTCOMPLETE_ERCE_MASK #define USBHS_EPCOMPLETE_ERCE_SHIFT USB_ENDPTCOMPLETE_ERCE_SHIFT #define USBHS_EPCOMPLETE_ERCE(x) USB_ENDPTCOMPLETE_ERCE(x) #define USBHS_EPCOMPLETE_ETCE_MASK USB_ENDPTCOMPLETE_ETCE_MASK #define USBHS_EPCOMPLETE_ETCE_SHIFT USB_ENDPTCOMPLETE_ETCE_SHIFT #define USBHS_EPCOMPLETE_ETCE(x) USB_ENDPTCOMPLETE_ETCE(x) #define USBHS_EPCR0_RXS_MASK USB_ENDPTCTRL0_RXS_MASK #define USBHS_EPCR0_RXS_SHIFT USB_ENDPTCTRL0_RXS_SHIFT #define USBHS_EPCR0_RXS(x) USB_ENDPTCTRL0_RXS(x) #define USBHS_EPCR0_RXT_MASK USB_ENDPTCTRL0_RXT_MASK #define USBHS_EPCR0_RXT_SHIFT USB_ENDPTCTRL0_RXT_SHIFT #define USBHS_EPCR0_RXT(x) USB_ENDPTCTRL0_RXT(x) #define USBHS_EPCR0_RXE_MASK USB_ENDPTCTRL0_RXE_MASK #define USBHS_EPCR0_RXE_SHIFT USB_ENDPTCTRL0_RXE_SHIFT #define USBHS_EPCR0_RXE(x) USB_ENDPTCTRL0_RXE(x) #define USBHS_EPCR0_TXS_MASK USB_ENDPTCTRL0_TXS_MASK #define USBHS_EPCR0_TXS_SHIFT USB_ENDPTCTRL0_TXS_SHIFT #define USBHS_EPCR0_TXS(x) USB_ENDPTCTRL0_TXS(x) #define USBHS_EPCR0_TXT_MASK USB_ENDPTCTRL0_TXT_MASK #define USBHS_EPCR0_TXT_SHIFT USB_ENDPTCTRL0_TXT_SHIFT #define USBHS_EPCR0_TXT(x) USB_ENDPTCTRL0_TXT(x) #define USBHS_EPCR0_TXE_MASK USB_ENDPTCTRL0_TXE_MASK #define USBHS_EPCR0_TXE_SHIFT USB_ENDPTCTRL0_TXE_SHIFT #define USBHS_EPCR0_TXE(x) USB_ENDPTCTRL0_TXE(x) #define USBHS_EPCR_RXS_MASK USB_ENDPTCTRL_RXS_MASK #define USBHS_EPCR_RXS_SHIFT USB_ENDPTCTRL_RXS_SHIFT #define USBHS_EPCR_RXS(x) USB_ENDPTCTRL_RXS(x) #define USBHS_EPCR_RXD_MASK USB_ENDPTCTRL_RXD_MASK #define USBHS_EPCR_RXD_SHIFT USB_ENDPTCTRL_RXD_SHIFT #define USBHS_EPCR_RXD(x) USB_ENDPTCTRL_RXD(x) #define USBHS_EPCR_RXT_MASK USB_ENDPTCTRL_RXT_MASK #define USBHS_EPCR_RXT_SHIFT USB_ENDPTCTRL_RXT_SHIFT #define USBHS_EPCR_RXT(x) USB_ENDPTCTRL_RXT(x) #define USBHS_EPCR_RXI_MASK USB_ENDPTCTRL_RXI_MASK #define USBHS_EPCR_RXI_SHIFT USB_ENDPTCTRL_RXI_SHIFT #define USBHS_EPCR_RXI(x) USB_ENDPTCTRL_RXI(x) #define USBHS_EPCR_RXR_MASK USB_ENDPTCTRL_RXR_MASK #define USBHS_EPCR_RXR_SHIFT USB_ENDPTCTRL_RXR_SHIFT #define USBHS_EPCR_RXR(x) USB_ENDPTCTRL_RXR(x) #define USBHS_EPCR_RXE_MASK USB_ENDPTCTRL_RXE_MASK #define USBHS_EPCR_RXE_SHIFT USB_ENDPTCTRL_RXE_SHIFT #define USBHS_EPCR_RXE(x) USB_ENDPTCTRL_RXE(x) #define USBHS_EPCR_TXS_MASK USB_ENDPTCTRL_TXS_MASK #define USBHS_EPCR_TXS_SHIFT USB_ENDPTCTRL_TXS_SHIFT #define USBHS_EPCR_TXS(x) USB_ENDPTCTRL_TXS(x) #define USBHS_EPCR_TXD_MASK USB_ENDPTCTRL_TXD_MASK #define USBHS_EPCR_TXD_SHIFT USB_ENDPTCTRL_TXD_SHIFT #define USBHS_EPCR_TXD(x) USB_ENDPTCTRL_TXD(x) #define USBHS_EPCR_TXT_MASK USB_ENDPTCTRL_TXT_MASK #define USBHS_EPCR_TXT_SHIFT USB_ENDPTCTRL_TXT_SHIFT #define USBHS_EPCR_TXT(x) USB_ENDPTCTRL_TXT(x) #define USBHS_EPCR_TXI_MASK USB_ENDPTCTRL_TXI_MASK #define USBHS_EPCR_TXI_SHIFT USB_ENDPTCTRL_TXI_SHIFT #define USBHS_EPCR_TXI(x) USB_ENDPTCTRL_TXI(x) #define USBHS_EPCR_TXR_MASK USB_ENDPTCTRL_TXR_MASK #define USBHS_EPCR_TXR_SHIFT USB_ENDPTCTRL_TXR_SHIFT #define USBHS_EPCR_TXR(x) USB_ENDPTCTRL_TXR(x) #define USBHS_EPCR_TXE_MASK USB_ENDPTCTRL_TXE_MASK #define USBHS_EPCR_TXE_SHIFT USB_ENDPTCTRL_TXE_SHIFT #define USBHS_EPCR_TXE(x) USB_ENDPTCTRL_TXE(x) #define USBHS_BASE_ADDRS { IMXRT1020_USB_BASE } #define USBHS_IRQS { USB_OTG1_IRQn } #define USBHS_IRQHandler USB_OTG1_IRQHandler /* ---------------------------------------------------------------------------- -- USBNC Peripheral Access Layer ---------------------------------------------------------------------------- */ /*! * @addtogroup USBNC_Peripheral_Access_Layer USBNC Peripheral Access Layer * @{ */ /** USBNC - Register Layout Typedef */ typedef struct { uint8_t RESERVED_0[2048]; volatile uint32_t USB_OTGn_CTRL; /**< USB OTG1 Control Register, offset: 0x800 */ uint8_t RESERVED_1[20]; volatile uint32_t USB_OTGn_PHY_CTRL_0; /**< OTG1 UTMI PHY Control 0 Register, offset: 0x818 */ } imxrt1020_usb_nc; /* USBNC - Peripheral instance base addresses */ /** Peripheral USBNC base address */ #define IMXRT1020_USB_NC_BASE (0x402E0000u) /** Peripheral USBNC base pointer */ #define IMXRT1020_USB_NC ((imxrt1020_usb_nc *)IMXRT1020_USB_NC_BASE) /** Array initializer of USBNC peripheral base addresses */ #define IIMXRT1020_USBNC_BASE_ADDRS { 0u, IMXRT1020_USB_NC_BASE } /* ---------------------------------------------------------------------------- -- USBNC Register Masks ---------------------------------------------------------------------------- */ /*! * @addtogroup USBNC_Register_Masks USBNC Register Masks * @{ */ /*! @name USB_OTGn_CTRL - USB OTG1 Control Register */ /*! @{ */ #define USBNC_USB_OTGn_CTRL_OVER_CUR_DIS_MASK (0x80U) #define USBNC_USB_OTGn_CTRL_OVER_CUR_DIS_SHIFT (7U) /*! OVER_CUR_DIS * 0b1..Disables overcurrent detection * 0b0..Enables overcurrent detection */ #define USBNC_USB_OTGn_CTRL_OVER_CUR_DIS(x) (((uint32_t)(((uint32_t)(x)) << USBNC_USB_OTGn_CTRL_OVER_CUR_DIS_SHIFT)) & USBNC_USB_OTGn_CTRL_OVER_CUR_DIS_MASK) #define USBNC_USB_OTGn_CTRL_OVER_CUR_POL_MASK (0x100U) #define USBNC_USB_OTGn_CTRL_OVER_CUR_POL_SHIFT (8U) /*! OVER_CUR_POL * 0b1..Low active (low on this signal represents an overcurrent condition) * 0b0..High active (high on this signal represents an overcurrent condition) */ #define USBNC_USB_OTGn_CTRL_OVER_CUR_POL(x) (((uint32_t)(((uint32_t)(x)) << USBNC_USB_OTGn_CTRL_OVER_CUR_POL_SHIFT)) & USBNC_USB_OTGn_CTRL_OVER_CUR_POL_MASK) #define USBNC_USB_OTGn_CTRL_PWR_POL_MASK (0x200U) #define USBNC_USB_OTGn_CTRL_PWR_POL_SHIFT (9U) /*! PWR_POL * 0b1..PMIC Power Pin is High active. * 0b0..PMIC Power Pin is Low active. */ #define USBNC_USB_OTGn_CTRL_PWR_POL(x) (((uint32_t)(((uint32_t)(x)) << USBNC_USB_OTGn_CTRL_PWR_POL_SHIFT)) & USBNC_USB_OTGn_CTRL_PWR_POL_MASK) #define USBNC_USB_OTGn_CTRL_WIE_MASK (0x400U) #define USBNC_USB_OTGn_CTRL_WIE_SHIFT (10U) /*! WIE * 0b1..Interrupt Enabled * 0b0..Interrupt Disabled */ #define USBNC_USB_OTGn_CTRL_WIE(x) (((uint32_t)(((uint32_t)(x)) << USBNC_USB_OTGn_CTRL_WIE_SHIFT)) & USBNC_USB_OTGn_CTRL_WIE_MASK) #define USBNC_USB_OTGn_CTRL_WKUP_SW_EN_MASK (0x4000U) #define USBNC_USB_OTGn_CTRL_WKUP_SW_EN_SHIFT (14U) /*! WKUP_SW_EN * 0b1..Enable * 0b0..Disable */ #define USBNC_USB_OTGn_CTRL_WKUP_SW_EN(x) (((uint32_t)(((uint32_t)(x)) << USBNC_USB_OTGn_CTRL_WKUP_SW_EN_SHIFT)) & USBNC_USB_OTGn_CTRL_WKUP_SW_EN_MASK) #define USBNC_USB_OTGn_CTRL_WKUP_SW_MASK (0x8000U) #define USBNC_USB_OTGn_CTRL_WKUP_SW_SHIFT (15U) /*! WKUP_SW * 0b1..Force wake-up * 0b0..Inactive */ #define USBNC_USB_OTGn_CTRL_WKUP_SW(x) (((uint32_t)(((uint32_t)(x)) << USBNC_USB_OTGn_CTRL_WKUP_SW_SHIFT)) & USBNC_USB_OTGn_CTRL_WKUP_SW_MASK) #define USBNC_USB_OTGn_CTRL_WKUP_ID_EN_MASK (0x10000U) #define USBNC_USB_OTGn_CTRL_WKUP_ID_EN_SHIFT (16U) /*! WKUP_ID_EN * 0b1..Enable * 0b0..Disable */ #define USBNC_USB_OTGn_CTRL_WKUP_ID_EN(x) (((uint32_t)(((uint32_t)(x)) << USBNC_USB_OTGn_CTRL_WKUP_ID_EN_SHIFT)) & USBNC_USB_OTGn_CTRL_WKUP_ID_EN_MASK) #define USBNC_USB_OTGn_CTRL_WKUP_VBUS_EN_MASK (0x20000U) #define USBNC_USB_OTGn_CTRL_WKUP_VBUS_EN_SHIFT (17U) /*! WKUP_VBUS_EN * 0b1..Enable * 0b0..Disable */ #define USBNC_USB_OTGn_CTRL_WKUP_VBUS_EN(x) (((uint32_t)(((uint32_t)(x)) << USBNC_USB_OTGn_CTRL_WKUP_VBUS_EN_SHIFT)) & USBNC_USB_OTGn_CTRL_WKUP_VBUS_EN_MASK) #define USBNC_USB_OTGn_CTRL_WKUP_DPDM_EN_MASK (0x20000000U) #define USBNC_USB_OTGn_CTRL_WKUP_DPDM_EN_SHIFT (29U) /*! WKUP_DPDM_EN * 0b1..(Default) DPDM changes wake-up to be enabled, it is for device only. * 0b0..DPDM changes wake-up to be disabled only when VBUS is 0. */ #define USBNC_USB_OTGn_CTRL_WKUP_DPDM_EN(x) (((uint32_t)(((uint32_t)(x)) << USBNC_USB_OTGn_CTRL_WKUP_DPDM_EN_SHIFT)) & USBNC_USB_OTGn_CTRL_WKUP_DPDM_EN_MASK) #define USBNC_USB_OTGn_CTRL_WIR_MASK (0x80000000U) #define USBNC_USB_OTGn_CTRL_WIR_SHIFT (31U) /*! WIR * 0b1..Wake-up Interrupt Request received * 0b0..No wake-up interrupt request received */ #define USBNC_USB_OTGn_CTRL_WIR(x) (((uint32_t)(((uint32_t)(x)) << USBNC_USB_OTGn_CTRL_WIR_SHIFT)) & USBNC_USB_OTGn_CTRL_WIR_MASK) /*! @} */ /*! @name USB_OTGn_PHY_CTRL_0 - OTG1 UTMI PHY Control 0 Register */ /*! @{ */ #define USBNC_USB_OTGn_PHY_CTRL_0_UTMI_CLK_VLD_MASK (0x80000000U) #define USBNC_USB_OTGn_PHY_CTRL_0_UTMI_CLK_VLD_SHIFT (31U) /*! UTMI_CLK_VLD * 0b1..Valid * 0b0..Invalid */ #define USBNC_USB_OTGn_PHY_CTRL_0_UTMI_CLK_VLD(x) (((uint32_t)(((uint32_t)(x)) << USBNC_USB_OTGn_PHY_CTRL_0_UTMI_CLK_VLD_SHIFT)) & USBNC_USB_OTGn_PHY_CTRL_0_UTMI_CLK_VLD_MASK) /*! @} */ /*! * @} *//* end of group USBNC_Register_Masks */ /*! * @} *//* end of group USB_Register_Masks */ /* ---------------------------------------------------------------------------- -- USBPHY Peripheral Access Layer ---------------------------------------------------------------------------- */ /*! * @addtogroup USBPHY_Peripheral_Access_Layer USBPHY Peripheral Access Layer * @{ */ /** USBPHY - Register Layout Typedef */ typedef struct { volatile uint32_t PWD; /**< USB PHY Power-Down Register, offset: 0x0 */ volatile uint32_t PWD_SET; /**< USB PHY Power-Down Register, offset: 0x4 */ volatile uint32_t PWD_CLR; /**< USB PHY Power-Down Register, offset: 0x8 */ volatile uint32_t PWD_TOG; /**< USB PHY Power-Down Register, offset: 0xC */ volatile uint32_t TX; /**< USB PHY Transmitter Control Register, offset: 0x10 */ volatile uint32_t TX_SET; /**< USB PHY Transmitter Control Register, offset: 0x14 */ volatile uint32_t TX_CLR; /**< USB PHY Transmitter Control Register, offset: 0x18 */ volatile uint32_t TX_TOG; /**< USB PHY Transmitter Control Register, offset: 0x1C */ volatile uint32_t RX; /**< USB PHY Receiver Control Register, offset: 0x20 */ volatile uint32_t RX_SET; /**< USB PHY Receiver Control Register, offset: 0x24 */ volatile uint32_t RX_CLR; /**< USB PHY Receiver Control Register, offset: 0x28 */ volatile uint32_t RX_TOG; /**< USB PHY Receiver Control Register, offset: 0x2C */ volatile uint32_t CTRL; /**< USB PHY General Control Register, offset: 0x30 */ volatile uint32_t CTRL_SET; /**< USB PHY General Control Register, offset: 0x34 */ volatile uint32_t CTRL_CLR; /**< USB PHY General Control Register, offset: 0x38 */ volatile uint32_t CTRL_TOG; /**< USB PHY General Control Register, offset: 0x3C */ volatile uint32_t STATUS; /**< USB PHY Status Register, offset: 0x40 */ uint8_t RESERVED_0[12]; volatile uint32_t DEBUGr; /**< USB PHY Debug Register, offset: 0x50 */ volatile uint32_t DEBUG_SET; /**< USB PHY Debug Register, offset: 0x54 */ volatile uint32_t DEBUG_CLR; /**< USB PHY Debug Register, offset: 0x58 */ volatile uint32_t DEBUG_TOG; /**< USB PHY Debug Register, offset: 0x5C */ volatile const uint32_t DEBUG0_STATUS; /**< UTMI Debug Status Register 0, offset: 0x60 */ uint8_t RESERVED_1[12]; volatile uint32_t DEBUG1; /**< UTMI Debug Status Register 1, offset: 0x70 */ volatile uint32_t DEBUG1_SET; /**< UTMI Debug Status Register 1, offset: 0x74 */ volatile uint32_t DEBUG1_CLR; /**< UTMI Debug Status Register 1, offset: 0x78 */ volatile uint32_t DEBUG1_TOG; /**< UTMI Debug Status Register 1, offset: 0x7C */ volatile const uint32_t VERSION; /**< UTMI RTL Version, offset: 0x80 */ } imxrt1020_usb_phy; /* USBPHY - Peripheral instance base addresses */ /** Peripheral USBPHY base address */ #define IMXRT1020_USB_PHY_IRQn (65) /**< USBPHY (OTG1 UTMI), Interrupt */ #define IMXRT1020_USB_PHY_BASE (0x400D9000u) /** Peripheral USBPHY base pointer */ #define IMXRT1020_USB_PHY ((imxrt1020_usb_phy *)IMXRT1020_USB_PHY_BASE) /** Array initializer of USBPHY peripheral base addresses */ #define IMXRT1020_USB_PHY_BASE_ADDRS { 0u, IMXRT1020_USB_PHY_BASE } /** Array initializer of USBPHY peripheral base pointers */ #define IMXRT1020_USBPHY_BASE_PTRS { (imxrt1020_usb_phy *)0u, IMXRT1020_USB_PHY } /** Interrupt vectors for the USBPHY peripheral type */ #define IMXRT1020_USBPHY_IRQS { NotAvail_IRQn, IMXRT1020_USB_PHY_IRQn } /* ---------------------------------------------------------------------------- -- USBPHY Register Masks ---------------------------------------------------------------------------- */ /*! * @addtogroup USBPHY_Register_Masks USBPHY Register Masks * @{ */ /*! @name PWD - USB PHY Power-Down Register */ /*! @{ */ #define USBPHY_PWD_RSVD0_MASK (0x3FFU) #define USBPHY_PWD_RSVD0_SHIFT (0U) #define USBPHY_PWD_RSVD0(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_PWD_RSVD0_SHIFT)) & USBPHY_PWD_RSVD0_MASK) #define USBPHY_PWD_TXPWDFS_MASK (0x400U) #define USBPHY_PWD_TXPWDFS_SHIFT (10U) #define USBPHY_PWD_TXPWDFS(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_PWD_TXPWDFS_SHIFT)) & USBPHY_PWD_TXPWDFS_MASK) #define USBPHY_PWD_TXPWDIBIAS_MASK (0x800U) #define USBPHY_PWD_TXPWDIBIAS_SHIFT (11U) #define USBPHY_PWD_TXPWDIBIAS(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_PWD_TXPWDIBIAS_SHIFT)) & USBPHY_PWD_TXPWDIBIAS_MASK) #define USBPHY_PWD_TXPWDV2I_MASK (0x1000U) #define USBPHY_PWD_TXPWDV2I_SHIFT (12U) #define USBPHY_PWD_TXPWDV2I(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_PWD_TXPWDV2I_SHIFT)) & USBPHY_PWD_TXPWDV2I_MASK) #define USBPHY_PWD_RSVD1_MASK (0x1E000U) #define USBPHY_PWD_RSVD1_SHIFT (13U) #define USBPHY_PWD_RSVD1(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_PWD_RSVD1_SHIFT)) & USBPHY_PWD_RSVD1_MASK) #define USBPHY_PWD_RXPWDENV_MASK (0x20000U) #define USBPHY_PWD_RXPWDENV_SHIFT (17U) #define USBPHY_PWD_RXPWDENV(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_PWD_RXPWDENV_SHIFT)) & USBPHY_PWD_RXPWDENV_MASK) #define USBPHY_PWD_RXPWD1PT1_MASK (0x40000U) #define USBPHY_PWD_RXPWD1PT1_SHIFT (18U) #define USBPHY_PWD_RXPWD1PT1(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_PWD_RXPWD1PT1_SHIFT)) & USBPHY_PWD_RXPWD1PT1_MASK) #define USBPHY_PWD_RXPWDDIFF_MASK (0x80000U) #define USBPHY_PWD_RXPWDDIFF_SHIFT (19U) #define USBPHY_PWD_RXPWDDIFF(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_PWD_RXPWDDIFF_SHIFT)) & USBPHY_PWD_RXPWDDIFF_MASK) #define USBPHY_PWD_RXPWDRX_MASK (0x100000U) #define USBPHY_PWD_RXPWDRX_SHIFT (20U) #define USBPHY_PWD_RXPWDRX(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_PWD_RXPWDRX_SHIFT)) & USBPHY_PWD_RXPWDRX_MASK) #define USBPHY_PWD_RSVD2_MASK (0xFFE00000U) #define USBPHY_PWD_RSVD2_SHIFT (21U) #define USBPHY_PWD_RSVD2(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_PWD_RSVD2_SHIFT)) & USBPHY_PWD_RSVD2_MASK) /*! @} */ /*! @name PWD_SET - USB PHY Power-Down Register */ /*! @{ */ #define USBPHY_PWD_SET_RSVD0_MASK (0x3FFU) #define USBPHY_PWD_SET_RSVD0_SHIFT (0U) #define USBPHY_PWD_SET_RSVD0(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_PWD_SET_RSVD0_SHIFT)) & USBPHY_PWD_SET_RSVD0_MASK) #define USBPHY_PWD_SET_TXPWDFS_MASK (0x400U) #define USBPHY_PWD_SET_TXPWDFS_SHIFT (10U) #define USBPHY_PWD_SET_TXPWDFS(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_PWD_SET_TXPWDFS_SHIFT)) & USBPHY_PWD_SET_TXPWDFS_MASK) #define USBPHY_PWD_SET_TXPWDIBIAS_MASK (0x800U) #define USBPHY_PWD_SET_TXPWDIBIAS_SHIFT (11U) #define USBPHY_PWD_SET_TXPWDIBIAS(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_PWD_SET_TXPWDIBIAS_SHIFT)) & USBPHY_PWD_SET_TXPWDIBIAS_MASK) #define USBPHY_PWD_SET_TXPWDV2I_MASK (0x1000U) #define USBPHY_PWD_SET_TXPWDV2I_SHIFT (12U) #define USBPHY_PWD_SET_TXPWDV2I(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_PWD_SET_TXPWDV2I_SHIFT)) & USBPHY_PWD_SET_TXPWDV2I_MASK) #define USBPHY_PWD_SET_RSVD1_MASK (0x1E000U) #define USBPHY_PWD_SET_RSVD1_SHIFT (13U) #define USBPHY_PWD_SET_RSVD1(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_PWD_SET_RSVD1_SHIFT)) & USBPHY_PWD_SET_RSVD1_MASK) #define USBPHY_PWD_SET_RXPWDENV_MASK (0x20000U) #define USBPHY_PWD_SET_RXPWDENV_SHIFT (17U) #define USBPHY_PWD_SET_RXPWDENV(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_PWD_SET_RXPWDENV_SHIFT)) & USBPHY_PWD_SET_RXPWDENV_MASK) #define USBPHY_PWD_SET_RXPWD1PT1_MASK (0x40000U) #define USBPHY_PWD_SET_RXPWD1PT1_SHIFT (18U) #define USBPHY_PWD_SET_RXPWD1PT1(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_PWD_SET_RXPWD1PT1_SHIFT)) & USBPHY_PWD_SET_RXPWD1PT1_MASK) #define USBPHY_PWD_SET_RXPWDDIFF_MASK (0x80000U) #define USBPHY_PWD_SET_RXPWDDIFF_SHIFT (19U) #define USBPHY_PWD_SET_RXPWDDIFF(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_PWD_SET_RXPWDDIFF_SHIFT)) & USBPHY_PWD_SET_RXPWDDIFF_MASK) #define USBPHY_PWD_SET_RXPWDRX_MASK (0x100000U) #define USBPHY_PWD_SET_RXPWDRX_SHIFT (20U) #define USBPHY_PWD_SET_RXPWDRX(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_PWD_SET_RXPWDRX_SHIFT)) & USBPHY_PWD_SET_RXPWDRX_MASK) #define USBPHY_PWD_SET_RSVD2_MASK (0xFFE00000U) #define USBPHY_PWD_SET_RSVD2_SHIFT (21U) #define USBPHY_PWD_SET_RSVD2(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_PWD_SET_RSVD2_SHIFT)) & USBPHY_PWD_SET_RSVD2_MASK) /*! @} */ /*! @name PWD_CLR - USB PHY Power-Down Register */ /*! @{ */ #define USBPHY_PWD_CLR_RSVD0_MASK (0x3FFU) #define USBPHY_PWD_CLR_RSVD0_SHIFT (0U) #define USBPHY_PWD_CLR_RSVD0(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_PWD_CLR_RSVD0_SHIFT)) & USBPHY_PWD_CLR_RSVD0_MASK) #define USBPHY_PWD_CLR_TXPWDFS_MASK (0x400U) #define USBPHY_PWD_CLR_TXPWDFS_SHIFT (10U) #define USBPHY_PWD_CLR_TXPWDFS(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_PWD_CLR_TXPWDFS_SHIFT)) & USBPHY_PWD_CLR_TXPWDFS_MASK) #define USBPHY_PWD_CLR_TXPWDIBIAS_MASK (0x800U) #define USBPHY_PWD_CLR_TXPWDIBIAS_SHIFT (11U) #define USBPHY_PWD_CLR_TXPWDIBIAS(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_PWD_CLR_TXPWDIBIAS_SHIFT)) & USBPHY_PWD_CLR_TXPWDIBIAS_MASK) #define USBPHY_PWD_CLR_TXPWDV2I_MASK (0x1000U) #define USBPHY_PWD_CLR_TXPWDV2I_SHIFT (12U) #define USBPHY_PWD_CLR_TXPWDV2I(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_PWD_CLR_TXPWDV2I_SHIFT)) & USBPHY_PWD_CLR_TXPWDV2I_MASK) #define USBPHY_PWD_CLR_RSVD1_MASK (0x1E000U) #define USBPHY_PWD_CLR_RSVD1_SHIFT (13U) #define USBPHY_PWD_CLR_RSVD1(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_PWD_CLR_RSVD1_SHIFT)) & USBPHY_PWD_CLR_RSVD1_MASK) #define USBPHY_PWD_CLR_RXPWDENV_MASK (0x20000U) #define USBPHY_PWD_CLR_RXPWDENV_SHIFT (17U) #define USBPHY_PWD_CLR_RXPWDENV(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_PWD_CLR_RXPWDENV_SHIFT)) & USBPHY_PWD_CLR_RXPWDENV_MASK) #define USBPHY_PWD_CLR_RXPWD1PT1_MASK (0x40000U) #define USBPHY_PWD_CLR_RXPWD1PT1_SHIFT (18U) #define USBPHY_PWD_CLR_RXPWD1PT1(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_PWD_CLR_RXPWD1PT1_SHIFT)) & USBPHY_PWD_CLR_RXPWD1PT1_MASK) #define USBPHY_PWD_CLR_RXPWDDIFF_MASK (0x80000U) #define USBPHY_PWD_CLR_RXPWDDIFF_SHIFT (19U) #define USBPHY_PWD_CLR_RXPWDDIFF(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_PWD_CLR_RXPWDDIFF_SHIFT)) & USBPHY_PWD_CLR_RXPWDDIFF_MASK) #define USBPHY_PWD_CLR_RXPWDRX_MASK (0x100000U) #define USBPHY_PWD_CLR_RXPWDRX_SHIFT (20U) #define USBPHY_PWD_CLR_RXPWDRX(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_PWD_CLR_RXPWDRX_SHIFT)) & USBPHY_PWD_CLR_RXPWDRX_MASK) #define USBPHY_PWD_CLR_RSVD2_MASK (0xFFE00000U) #define USBPHY_PWD_CLR_RSVD2_SHIFT (21U) #define USBPHY_PWD_CLR_RSVD2(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_PWD_CLR_RSVD2_SHIFT)) & USBPHY_PWD_CLR_RSVD2_MASK) /*! @} */ /*! @name PWD_TOG - USB PHY Power-Down Register */ /*! @{ */ #define USBPHY_PWD_TOG_RSVD0_MASK (0x3FFU) #define USBPHY_PWD_TOG_RSVD0_SHIFT (0U) #define USBPHY_PWD_TOG_RSVD0(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_PWD_TOG_RSVD0_SHIFT)) & USBPHY_PWD_TOG_RSVD0_MASK) #define USBPHY_PWD_TOG_TXPWDFS_MASK (0x400U) #define USBPHY_PWD_TOG_TXPWDFS_SHIFT (10U) #define USBPHY_PWD_TOG_TXPWDFS(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_PWD_TOG_TXPWDFS_SHIFT)) & USBPHY_PWD_TOG_TXPWDFS_MASK) #define USBPHY_PWD_TOG_TXPWDIBIAS_MASK (0x800U) #define USBPHY_PWD_TOG_TXPWDIBIAS_SHIFT (11U) #define USBPHY_PWD_TOG_TXPWDIBIAS(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_PWD_TOG_TXPWDIBIAS_SHIFT)) & USBPHY_PWD_TOG_TXPWDIBIAS_MASK) #define USBPHY_PWD_TOG_TXPWDV2I_MASK (0x1000U) #define USBPHY_PWD_TOG_TXPWDV2I_SHIFT (12U) #define USBPHY_PWD_TOG_TXPWDV2I(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_PWD_TOG_TXPWDV2I_SHIFT)) & USBPHY_PWD_TOG_TXPWDV2I_MASK) #define USBPHY_PWD_TOG_RSVD1_MASK (0x1E000U) #define USBPHY_PWD_TOG_RSVD1_SHIFT (13U) #define USBPHY_PWD_TOG_RSVD1(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_PWD_TOG_RSVD1_SHIFT)) & USBPHY_PWD_TOG_RSVD1_MASK) #define USBPHY_PWD_TOG_RXPWDENV_MASK (0x20000U) #define USBPHY_PWD_TOG_RXPWDENV_SHIFT (17U) #define USBPHY_PWD_TOG_RXPWDENV(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_PWD_TOG_RXPWDENV_SHIFT)) & USBPHY_PWD_TOG_RXPWDENV_MASK) #define USBPHY_PWD_TOG_RXPWD1PT1_MASK (0x40000U) #define USBPHY_PWD_TOG_RXPWD1PT1_SHIFT (18U) #define USBPHY_PWD_TOG_RXPWD1PT1(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_PWD_TOG_RXPWD1PT1_SHIFT)) & USBPHY_PWD_TOG_RXPWD1PT1_MASK) #define USBPHY_PWD_TOG_RXPWDDIFF_MASK (0x80000U) #define USBPHY_PWD_TOG_RXPWDDIFF_SHIFT (19U) #define USBPHY_PWD_TOG_RXPWDDIFF(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_PWD_TOG_RXPWDDIFF_SHIFT)) & USBPHY_PWD_TOG_RXPWDDIFF_MASK) #define USBPHY_PWD_TOG_RXPWDRX_MASK (0x100000U) #define USBPHY_PWD_TOG_RXPWDRX_SHIFT (20U) #define USBPHY_PWD_TOG_RXPWDRX(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_PWD_TOG_RXPWDRX_SHIFT)) & USBPHY_PWD_TOG_RXPWDRX_MASK) #define USBPHY_PWD_TOG_RSVD2_MASK (0xFFE00000U) #define USBPHY_PWD_TOG_RSVD2_SHIFT (21U) #define USBPHY_PWD_TOG_RSVD2(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_PWD_TOG_RSVD2_SHIFT)) & USBPHY_PWD_TOG_RSVD2_MASK) /*! @} */ /*! @name TX - USB PHY Transmitter Control Register */ /*! @{ */ #define USBPHY_TX_D_CAL_MASK (0xFU) #define USBPHY_TX_D_CAL_SHIFT (0U) #define USBPHY_TX_D_CAL(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_TX_D_CAL_SHIFT)) & USBPHY_TX_D_CAL_MASK) #define USBPHY_TX_RSVD0_MASK (0xF0U) #define USBPHY_TX_RSVD0_SHIFT (4U) #define USBPHY_TX_RSVD0(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_TX_RSVD0_SHIFT)) & USBPHY_TX_RSVD0_MASK) #define USBPHY_TX_TXCAL45DN_MASK (0xF00U) #define USBPHY_TX_TXCAL45DN_SHIFT (8U) #define USBPHY_TX_TXCAL45DN(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_TX_TXCAL45DN_SHIFT)) & USBPHY_TX_TXCAL45DN_MASK) #define USBPHY_TX_RSVD1_MASK (0xF000U) #define USBPHY_TX_RSVD1_SHIFT (12U) #define USBPHY_TX_RSVD1(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_TX_RSVD1_SHIFT)) & USBPHY_TX_RSVD1_MASK) #define USBPHY_TX_TXCAL45DP_MASK (0xF0000U) #define USBPHY_TX_TXCAL45DP_SHIFT (16U) #define USBPHY_TX_TXCAL45DP(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_TX_TXCAL45DP_SHIFT)) & USBPHY_TX_TXCAL45DP_MASK) #define USBPHY_TX_RSVD2_MASK (0x3F00000U) #define USBPHY_TX_RSVD2_SHIFT (20U) #define USBPHY_TX_RSVD2(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_TX_RSVD2_SHIFT)) & USBPHY_TX_RSVD2_MASK) #define USBPHY_TX_USBPHY_TX_EDGECTRL_MASK (0x1C000000U) #define USBPHY_TX_USBPHY_TX_EDGECTRL_SHIFT (26U) #define USBPHY_TX_USBPHY_TX_EDGECTRL(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_TX_USBPHY_TX_EDGECTRL_SHIFT)) & USBPHY_TX_USBPHY_TX_EDGECTRL_MASK) #define USBPHY_TX_RSVD5_MASK (0xE0000000U) #define USBPHY_TX_RSVD5_SHIFT (29U) #define USBPHY_TX_RSVD5(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_TX_RSVD5_SHIFT)) & USBPHY_TX_RSVD5_MASK) /*! @} */ /*! @name TX_SET - USB PHY Transmitter Control Register */ /*! @{ */ #define USBPHY_TX_SET_D_CAL_MASK (0xFU) #define USBPHY_TX_SET_D_CAL_SHIFT (0U) #define USBPHY_TX_SET_D_CAL(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_TX_SET_D_CAL_SHIFT)) & USBPHY_TX_SET_D_CAL_MASK) #define USBPHY_TX_SET_RSVD0_MASK (0xF0U) #define USBPHY_TX_SET_RSVD0_SHIFT (4U) #define USBPHY_TX_SET_RSVD0(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_TX_SET_RSVD0_SHIFT)) & USBPHY_TX_SET_RSVD0_MASK) #define USBPHY_TX_SET_TXCAL45DN_MASK (0xF00U) #define USBPHY_TX_SET_TXCAL45DN_SHIFT (8U) #define USBPHY_TX_SET_TXCAL45DN(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_TX_SET_TXCAL45DN_SHIFT)) & USBPHY_TX_SET_TXCAL45DN_MASK) #define USBPHY_TX_SET_RSVD1_MASK (0xF000U) #define USBPHY_TX_SET_RSVD1_SHIFT (12U) #define USBPHY_TX_SET_RSVD1(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_TX_SET_RSVD1_SHIFT)) & USBPHY_TX_SET_RSVD1_MASK) #define USBPHY_TX_SET_TXCAL45DP_MASK (0xF0000U) #define USBPHY_TX_SET_TXCAL45DP_SHIFT (16U) #define USBPHY_TX_SET_TXCAL45DP(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_TX_SET_TXCAL45DP_SHIFT)) & USBPHY_TX_SET_TXCAL45DP_MASK) #define USBPHY_TX_SET_RSVD2_MASK (0x3F00000U) #define USBPHY_TX_SET_RSVD2_SHIFT (20U) #define USBPHY_TX_SET_RSVD2(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_TX_SET_RSVD2_SHIFT)) & USBPHY_TX_SET_RSVD2_MASK) #define USBPHY_TX_SET_USBPHY_TX_EDGECTRL_MASK (0x1C000000U) #define USBPHY_TX_SET_USBPHY_TX_EDGECTRL_SHIFT (26U) #define USBPHY_TX_SET_USBPHY_TX_EDGECTRL(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_TX_SET_USBPHY_TX_EDGECTRL_SHIFT)) & USBPHY_TX_SET_USBPHY_TX_EDGECTRL_MASK) #define USBPHY_TX_SET_RSVD5_MASK (0xE0000000U) #define USBPHY_TX_SET_RSVD5_SHIFT (29U) #define USBPHY_TX_SET_RSVD5(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_TX_SET_RSVD5_SHIFT)) & USBPHY_TX_SET_RSVD5_MASK) /*! @} */ /*! @name TX_CLR - USB PHY Transmitter Control Register */ /*! @{ */ #define USBPHY_TX_CLR_D_CAL_MASK (0xFU) #define USBPHY_TX_CLR_D_CAL_SHIFT (0U) #define USBPHY_TX_CLR_D_CAL(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_TX_CLR_D_CAL_SHIFT)) & USBPHY_TX_CLR_D_CAL_MASK) #define USBPHY_TX_CLR_RSVD0_MASK (0xF0U) #define USBPHY_TX_CLR_RSVD0_SHIFT (4U) #define USBPHY_TX_CLR_RSVD0(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_TX_CLR_RSVD0_SHIFT)) & USBPHY_TX_CLR_RSVD0_MASK) #define USBPHY_TX_CLR_TXCAL45DN_MASK (0xF00U) #define USBPHY_TX_CLR_TXCAL45DN_SHIFT (8U) #define USBPHY_TX_CLR_TXCAL45DN(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_TX_CLR_TXCAL45DN_SHIFT)) & USBPHY_TX_CLR_TXCAL45DN_MASK) #define USBPHY_TX_CLR_RSVD1_MASK (0xF000U) #define USBPHY_TX_CLR_RSVD1_SHIFT (12U) #define USBPHY_TX_CLR_RSVD1(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_TX_CLR_RSVD1_SHIFT)) & USBPHY_TX_CLR_RSVD1_MASK) #define USBPHY_TX_CLR_TXCAL45DP_MASK (0xF0000U) #define USBPHY_TX_CLR_TXCAL45DP_SHIFT (16U) #define USBPHY_TX_CLR_TXCAL45DP(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_TX_CLR_TXCAL45DP_SHIFT)) & USBPHY_TX_CLR_TXCAL45DP_MASK) #define USBPHY_TX_CLR_RSVD2_MASK (0x3F00000U) #define USBPHY_TX_CLR_RSVD2_SHIFT (20U) #define USBPHY_TX_CLR_RSVD2(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_TX_CLR_RSVD2_SHIFT)) & USBPHY_TX_CLR_RSVD2_MASK) #define USBPHY_TX_CLR_USBPHY_TX_EDGECTRL_MASK (0x1C000000U) #define USBPHY_TX_CLR_USBPHY_TX_EDGECTRL_SHIFT (26U) #define USBPHY_TX_CLR_USBPHY_TX_EDGECTRL(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_TX_CLR_USBPHY_TX_EDGECTRL_SHIFT)) & USBPHY_TX_CLR_USBPHY_TX_EDGECTRL_MASK) #define USBPHY_TX_CLR_RSVD5_MASK (0xE0000000U) #define USBPHY_TX_CLR_RSVD5_SHIFT (29U) #define USBPHY_TX_CLR_RSVD5(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_TX_CLR_RSVD5_SHIFT)) & USBPHY_TX_CLR_RSVD5_MASK) /*! @} */ /*! @name TX_TOG - USB PHY Transmitter Control Register */ /*! @{ */ #define USBPHY_TX_TOG_D_CAL_MASK (0xFU) #define USBPHY_TX_TOG_D_CAL_SHIFT (0U) #define USBPHY_TX_TOG_D_CAL(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_TX_TOG_D_CAL_SHIFT)) & USBPHY_TX_TOG_D_CAL_MASK) #define USBPHY_TX_TOG_RSVD0_MASK (0xF0U) #define USBPHY_TX_TOG_RSVD0_SHIFT (4U) #define USBPHY_TX_TOG_RSVD0(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_TX_TOG_RSVD0_SHIFT)) & USBPHY_TX_TOG_RSVD0_MASK) #define USBPHY_TX_TOG_TXCAL45DN_MASK (0xF00U) #define USBPHY_TX_TOG_TXCAL45DN_SHIFT (8U) #define USBPHY_TX_TOG_TXCAL45DN(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_TX_TOG_TXCAL45DN_SHIFT)) & USBPHY_TX_TOG_TXCAL45DN_MASK) #define USBPHY_TX_TOG_RSVD1_MASK (0xF000U) #define USBPHY_TX_TOG_RSVD1_SHIFT (12U) #define USBPHY_TX_TOG_RSVD1(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_TX_TOG_RSVD1_SHIFT)) & USBPHY_TX_TOG_RSVD1_MASK) #define USBPHY_TX_TOG_TXCAL45DP_MASK (0xF0000U) #define USBPHY_TX_TOG_TXCAL45DP_SHIFT (16U) #define USBPHY_TX_TOG_TXCAL45DP(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_TX_TOG_TXCAL45DP_SHIFT)) & USBPHY_TX_TOG_TXCAL45DP_MASK) #define USBPHY_TX_TOG_RSVD2_MASK (0x3F00000U) #define USBPHY_TX_TOG_RSVD2_SHIFT (20U) #define USBPHY_TX_TOG_RSVD2(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_TX_TOG_RSVD2_SHIFT)) & USBPHY_TX_TOG_RSVD2_MASK) #define USBPHY_TX_TOG_USBPHY_TX_EDGECTRL_MASK (0x1C000000U) #define USBPHY_TX_TOG_USBPHY_TX_EDGECTRL_SHIFT (26U) #define USBPHY_TX_TOG_USBPHY_TX_EDGECTRL(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_TX_TOG_USBPHY_TX_EDGECTRL_SHIFT)) & USBPHY_TX_TOG_USBPHY_TX_EDGECTRL_MASK) #define USBPHY_TX_TOG_RSVD5_MASK (0xE0000000U) #define USBPHY_TX_TOG_RSVD5_SHIFT (29U) #define USBPHY_TX_TOG_RSVD5(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_TX_TOG_RSVD5_SHIFT)) & USBPHY_TX_TOG_RSVD5_MASK) /*! @} */ /*! @name RX - USB PHY Receiver Control Register */ /*! @{ */ #define USBPHY_RX_ENVADJ_MASK (0x7U) #define USBPHY_RX_ENVADJ_SHIFT (0U) #define USBPHY_RX_ENVADJ(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_RX_ENVADJ_SHIFT)) & USBPHY_RX_ENVADJ_MASK) #define USBPHY_RX_RSVD0_MASK (0x8U) #define USBPHY_RX_RSVD0_SHIFT (3U) #define USBPHY_RX_RSVD0(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_RX_RSVD0_SHIFT)) & USBPHY_RX_RSVD0_MASK) #define USBPHY_RX_DISCONADJ_MASK (0x70U) #define USBPHY_RX_DISCONADJ_SHIFT (4U) #define USBPHY_RX_DISCONADJ(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_RX_DISCONADJ_SHIFT)) & USBPHY_RX_DISCONADJ_MASK) #define USBPHY_RX_RSVD1_MASK (0x3FFF80U) #define USBPHY_RX_RSVD1_SHIFT (7U) #define USBPHY_RX_RSVD1(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_RX_RSVD1_SHIFT)) & USBPHY_RX_RSVD1_MASK) #define USBPHY_RX_RXDBYPASS_MASK (0x400000U) #define USBPHY_RX_RXDBYPASS_SHIFT (22U) #define USBPHY_RX_RXDBYPASS(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_RX_RXDBYPASS_SHIFT)) & USBPHY_RX_RXDBYPASS_MASK) #define USBPHY_RX_RSVD2_MASK (0xFF800000U) #define USBPHY_RX_RSVD2_SHIFT (23U) #define USBPHY_RX_RSVD2(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_RX_RSVD2_SHIFT)) & USBPHY_RX_RSVD2_MASK) /*! @} */ /*! @name RX_SET - USB PHY Receiver Control Register */ /*! @{ */ #define USBPHY_RX_SET_ENVADJ_MASK (0x7U) #define USBPHY_RX_SET_ENVADJ_SHIFT (0U) #define USBPHY_RX_SET_ENVADJ(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_RX_SET_ENVADJ_SHIFT)) & USBPHY_RX_SET_ENVADJ_MASK) #define USBPHY_RX_SET_RSVD0_MASK (0x8U) #define USBPHY_RX_SET_RSVD0_SHIFT (3U) #define USBPHY_RX_SET_RSVD0(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_RX_SET_RSVD0_SHIFT)) & USBPHY_RX_SET_RSVD0_MASK) #define USBPHY_RX_SET_DISCONADJ_MASK (0x70U) #define USBPHY_RX_SET_DISCONADJ_SHIFT (4U) #define USBPHY_RX_SET_DISCONADJ(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_RX_SET_DISCONADJ_SHIFT)) & USBPHY_RX_SET_DISCONADJ_MASK) #define USBPHY_RX_SET_RSVD1_MASK (0x3FFF80U) #define USBPHY_RX_SET_RSVD1_SHIFT (7U) #define USBPHY_RX_SET_RSVD1(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_RX_SET_RSVD1_SHIFT)) & USBPHY_RX_SET_RSVD1_MASK) #define USBPHY_RX_SET_RXDBYPASS_MASK (0x400000U) #define USBPHY_RX_SET_RXDBYPASS_SHIFT (22U) #define USBPHY_RX_SET_RXDBYPASS(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_RX_SET_RXDBYPASS_SHIFT)) & USBPHY_RX_SET_RXDBYPASS_MASK) #define USBPHY_RX_SET_RSVD2_MASK (0xFF800000U) #define USBPHY_RX_SET_RSVD2_SHIFT (23U) #define USBPHY_RX_SET_RSVD2(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_RX_SET_RSVD2_SHIFT)) & USBPHY_RX_SET_RSVD2_MASK) /*! @} */ /*! @name RX_CLR - USB PHY Receiver Control Register */ /*! @{ */ #define USBPHY_RX_CLR_ENVADJ_MASK (0x7U) #define USBPHY_RX_CLR_ENVADJ_SHIFT (0U) #define USBPHY_RX_CLR_ENVADJ(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_RX_CLR_ENVADJ_SHIFT)) & USBPHY_RX_CLR_ENVADJ_MASK) #define USBPHY_RX_CLR_RSVD0_MASK (0x8U) #define USBPHY_RX_CLR_RSVD0_SHIFT (3U) #define USBPHY_RX_CLR_RSVD0(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_RX_CLR_RSVD0_SHIFT)) & USBPHY_RX_CLR_RSVD0_MASK) #define USBPHY_RX_CLR_DISCONADJ_MASK (0x70U) #define USBPHY_RX_CLR_DISCONADJ_SHIFT (4U) #define USBPHY_RX_CLR_DISCONADJ(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_RX_CLR_DISCONADJ_SHIFT)) & USBPHY_RX_CLR_DISCONADJ_MASK) #define USBPHY_RX_CLR_RSVD1_MASK (0x3FFF80U) #define USBPHY_RX_CLR_RSVD1_SHIFT (7U) #define USBPHY_RX_CLR_RSVD1(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_RX_CLR_RSVD1_SHIFT)) & USBPHY_RX_CLR_RSVD1_MASK) #define USBPHY_RX_CLR_RXDBYPASS_MASK (0x400000U) #define USBPHY_RX_CLR_RXDBYPASS_SHIFT (22U) #define USBPHY_RX_CLR_RXDBYPASS(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_RX_CLR_RXDBYPASS_SHIFT)) & USBPHY_RX_CLR_RXDBYPASS_MASK) #define USBPHY_RX_CLR_RSVD2_MASK (0xFF800000U) #define USBPHY_RX_CLR_RSVD2_SHIFT (23U) #define USBPHY_RX_CLR_RSVD2(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_RX_CLR_RSVD2_SHIFT)) & USBPHY_RX_CLR_RSVD2_MASK) /*! @} */ /*! @name RX_TOG - USB PHY Receiver Control Register */ /*! @{ */ #define USBPHY_RX_TOG_ENVADJ_MASK (0x7U) #define USBPHY_RX_TOG_ENVADJ_SHIFT (0U) #define USBPHY_RX_TOG_ENVADJ(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_RX_TOG_ENVADJ_SHIFT)) & USBPHY_RX_TOG_ENVADJ_MASK) #define USBPHY_RX_TOG_RSVD0_MASK (0x8U) #define USBPHY_RX_TOG_RSVD0_SHIFT (3U) #define USBPHY_RX_TOG_RSVD0(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_RX_TOG_RSVD0_SHIFT)) & USBPHY_RX_TOG_RSVD0_MASK) #define USBPHY_RX_TOG_DISCONADJ_MASK (0x70U) #define USBPHY_RX_TOG_DISCONADJ_SHIFT (4U) #define USBPHY_RX_TOG_DISCONADJ(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_RX_TOG_DISCONADJ_SHIFT)) & USBPHY_RX_TOG_DISCONADJ_MASK) #define USBPHY_RX_TOG_RSVD1_MASK (0x3FFF80U) #define USBPHY_RX_TOG_RSVD1_SHIFT (7U) #define USBPHY_RX_TOG_RSVD1(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_RX_TOG_RSVD1_SHIFT)) & USBPHY_RX_TOG_RSVD1_MASK) #define USBPHY_RX_TOG_RXDBYPASS_MASK (0x400000U) #define USBPHY_RX_TOG_RXDBYPASS_SHIFT (22U) #define USBPHY_RX_TOG_RXDBYPASS(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_RX_TOG_RXDBYPASS_SHIFT)) & USBPHY_RX_TOG_RXDBYPASS_MASK) #define USBPHY_RX_TOG_RSVD2_MASK (0xFF800000U) #define USBPHY_RX_TOG_RSVD2_SHIFT (23U) #define USBPHY_RX_TOG_RSVD2(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_RX_TOG_RSVD2_SHIFT)) & USBPHY_RX_TOG_RSVD2_MASK) /*! @} */ /*! @name CTRL - USB PHY General Control Register */ /*! @{ */ #define USBPHY_CTRL_ENOTG_ID_CHG_IRQ_MASK (0x1U) #define USBPHY_CTRL_ENOTG_ID_CHG_IRQ_SHIFT (0U) #define USBPHY_CTRL_ENOTG_ID_CHG_IRQ(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_ENOTG_ID_CHG_IRQ_SHIFT)) & USBPHY_CTRL_ENOTG_ID_CHG_IRQ_MASK) #define USBPHY_CTRL_ENHOSTDISCONDETECT_MASK (0x2U) #define USBPHY_CTRL_ENHOSTDISCONDETECT_SHIFT (1U) #define USBPHY_CTRL_ENHOSTDISCONDETECT(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_ENHOSTDISCONDETECT_SHIFT)) & USBPHY_CTRL_ENHOSTDISCONDETECT_MASK) #define USBPHY_CTRL_ENIRQHOSTDISCON_MASK (0x4U) #define USBPHY_CTRL_ENIRQHOSTDISCON_SHIFT (2U) #define USBPHY_CTRL_ENIRQHOSTDISCON(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_ENIRQHOSTDISCON_SHIFT)) & USBPHY_CTRL_ENIRQHOSTDISCON_MASK) #define USBPHY_CTRL_HOSTDISCONDETECT_IRQ_MASK (0x8U) #define USBPHY_CTRL_HOSTDISCONDETECT_IRQ_SHIFT (3U) #define USBPHY_CTRL_HOSTDISCONDETECT_IRQ(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_HOSTDISCONDETECT_IRQ_SHIFT)) & USBPHY_CTRL_HOSTDISCONDETECT_IRQ_MASK) #define USBPHY_CTRL_ENDEVPLUGINDETECT_MASK (0x10U) #define USBPHY_CTRL_ENDEVPLUGINDETECT_SHIFT (4U) #define USBPHY_CTRL_ENDEVPLUGINDETECT(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_ENDEVPLUGINDETECT_SHIFT)) & USBPHY_CTRL_ENDEVPLUGINDETECT_MASK) #define USBPHY_CTRL_DEVPLUGIN_POLARITY_MASK (0x20U) #define USBPHY_CTRL_DEVPLUGIN_POLARITY_SHIFT (5U) #define USBPHY_CTRL_DEVPLUGIN_POLARITY(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_DEVPLUGIN_POLARITY_SHIFT)) & USBPHY_CTRL_DEVPLUGIN_POLARITY_MASK) #define USBPHY_CTRL_OTG_ID_CHG_IRQ_MASK (0x40U) #define USBPHY_CTRL_OTG_ID_CHG_IRQ_SHIFT (6U) #define USBPHY_CTRL_OTG_ID_CHG_IRQ(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_OTG_ID_CHG_IRQ_SHIFT)) & USBPHY_CTRL_OTG_ID_CHG_IRQ_MASK) #define USBPHY_CTRL_ENOTGIDDETECT_MASK (0x80U) #define USBPHY_CTRL_ENOTGIDDETECT_SHIFT (7U) #define USBPHY_CTRL_ENOTGIDDETECT(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_ENOTGIDDETECT_SHIFT)) & USBPHY_CTRL_ENOTGIDDETECT_MASK) #define USBPHY_CTRL_RESUMEIRQSTICKY_MASK (0x100U) #define USBPHY_CTRL_RESUMEIRQSTICKY_SHIFT (8U) #define USBPHY_CTRL_RESUMEIRQSTICKY(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_RESUMEIRQSTICKY_SHIFT)) & USBPHY_CTRL_RESUMEIRQSTICKY_MASK) #define USBPHY_CTRL_ENIRQRESUMEDETECT_MASK (0x200U) #define USBPHY_CTRL_ENIRQRESUMEDETECT_SHIFT (9U) #define USBPHY_CTRL_ENIRQRESUMEDETECT(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_ENIRQRESUMEDETECT_SHIFT)) & USBPHY_CTRL_ENIRQRESUMEDETECT_MASK) #define USBPHY_CTRL_RESUME_IRQ_MASK (0x400U) #define USBPHY_CTRL_RESUME_IRQ_SHIFT (10U) #define USBPHY_CTRL_RESUME_IRQ(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_RESUME_IRQ_SHIFT)) & USBPHY_CTRL_RESUME_IRQ_MASK) #define USBPHY_CTRL_ENIRQDEVPLUGIN_MASK (0x800U) #define USBPHY_CTRL_ENIRQDEVPLUGIN_SHIFT (11U) #define USBPHY_CTRL_ENIRQDEVPLUGIN(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_ENIRQDEVPLUGIN_SHIFT)) & USBPHY_CTRL_ENIRQDEVPLUGIN_MASK) #define USBPHY_CTRL_DEVPLUGIN_IRQ_MASK (0x1000U) #define USBPHY_CTRL_DEVPLUGIN_IRQ_SHIFT (12U) #define USBPHY_CTRL_DEVPLUGIN_IRQ(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_DEVPLUGIN_IRQ_SHIFT)) & USBPHY_CTRL_DEVPLUGIN_IRQ_MASK) #define USBPHY_CTRL_DATA_ON_LRADC_MASK (0x2000U) #define USBPHY_CTRL_DATA_ON_LRADC_SHIFT (13U) #define USBPHY_CTRL_DATA_ON_LRADC(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_DATA_ON_LRADC_SHIFT)) & USBPHY_CTRL_DATA_ON_LRADC_MASK) #define USBPHY_CTRL_ENUTMILEVEL2_MASK (0x4000U) #define USBPHY_CTRL_ENUTMILEVEL2_SHIFT (14U) #define USBPHY_CTRL_ENUTMILEVEL2(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_ENUTMILEVEL2_SHIFT)) & USBPHY_CTRL_ENUTMILEVEL2_MASK) #define USBPHY_CTRL_ENUTMILEVEL3_MASK (0x8000U) #define USBPHY_CTRL_ENUTMILEVEL3_SHIFT (15U) #define USBPHY_CTRL_ENUTMILEVEL3(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_ENUTMILEVEL3_SHIFT)) & USBPHY_CTRL_ENUTMILEVEL3_MASK) #define USBPHY_CTRL_ENIRQWAKEUP_MASK (0x10000U) #define USBPHY_CTRL_ENIRQWAKEUP_SHIFT (16U) #define USBPHY_CTRL_ENIRQWAKEUP(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_ENIRQWAKEUP_SHIFT)) & USBPHY_CTRL_ENIRQWAKEUP_MASK) #define USBPHY_CTRL_WAKEUP_IRQ_MASK (0x20000U) #define USBPHY_CTRL_WAKEUP_IRQ_SHIFT (17U) #define USBPHY_CTRL_WAKEUP_IRQ(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_WAKEUP_IRQ_SHIFT)) & USBPHY_CTRL_WAKEUP_IRQ_MASK) #define USBPHY_CTRL_ENAUTO_PWRON_PLL_MASK (0x40000U) #define USBPHY_CTRL_ENAUTO_PWRON_PLL_SHIFT (18U) #define USBPHY_CTRL_ENAUTO_PWRON_PLL(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_ENAUTO_PWRON_PLL_SHIFT)) & USBPHY_CTRL_ENAUTO_PWRON_PLL_MASK) #define USBPHY_CTRL_ENAUTOCLR_CLKGATE_MASK (0x80000U) #define USBPHY_CTRL_ENAUTOCLR_CLKGATE_SHIFT (19U) #define USBPHY_CTRL_ENAUTOCLR_CLKGATE(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_ENAUTOCLR_CLKGATE_SHIFT)) & USBPHY_CTRL_ENAUTOCLR_CLKGATE_MASK) #define USBPHY_CTRL_ENAUTOCLR_PHY_PWD_MASK (0x100000U) #define USBPHY_CTRL_ENAUTOCLR_PHY_PWD_SHIFT (20U) #define USBPHY_CTRL_ENAUTOCLR_PHY_PWD(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_ENAUTOCLR_PHY_PWD_SHIFT)) & USBPHY_CTRL_ENAUTOCLR_PHY_PWD_MASK) #define USBPHY_CTRL_ENDPDMCHG_WKUP_MASK (0x200000U) #define USBPHY_CTRL_ENDPDMCHG_WKUP_SHIFT (21U) #define USBPHY_CTRL_ENDPDMCHG_WKUP(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_ENDPDMCHG_WKUP_SHIFT)) & USBPHY_CTRL_ENDPDMCHG_WKUP_MASK) #define USBPHY_CTRL_ENIDCHG_WKUP_MASK (0x400000U) #define USBPHY_CTRL_ENIDCHG_WKUP_SHIFT (22U) #define USBPHY_CTRL_ENIDCHG_WKUP(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_ENIDCHG_WKUP_SHIFT)) & USBPHY_CTRL_ENIDCHG_WKUP_MASK) #define USBPHY_CTRL_ENVBUSCHG_WKUP_MASK (0x800000U) #define USBPHY_CTRL_ENVBUSCHG_WKUP_SHIFT (23U) #define USBPHY_CTRL_ENVBUSCHG_WKUP(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_ENVBUSCHG_WKUP_SHIFT)) & USBPHY_CTRL_ENVBUSCHG_WKUP_MASK) #define USBPHY_CTRL_FSDLL_RST_EN_MASK (0x1000000U) #define USBPHY_CTRL_FSDLL_RST_EN_SHIFT (24U) #define USBPHY_CTRL_FSDLL_RST_EN(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_FSDLL_RST_EN_SHIFT)) & USBPHY_CTRL_FSDLL_RST_EN_MASK) #define USBPHY_CTRL_RSVD1_MASK (0x6000000U) #define USBPHY_CTRL_RSVD1_SHIFT (25U) #define USBPHY_CTRL_RSVD1(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_RSVD1_SHIFT)) & USBPHY_CTRL_RSVD1_MASK) #define USBPHY_CTRL_OTG_ID_VALUE_MASK (0x8000000U) #define USBPHY_CTRL_OTG_ID_VALUE_SHIFT (27U) #define USBPHY_CTRL_OTG_ID_VALUE(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_OTG_ID_VALUE_SHIFT)) & USBPHY_CTRL_OTG_ID_VALUE_MASK) #define USBPHY_CTRL_HOST_FORCE_LS_SE0_MASK (0x10000000U) #define USBPHY_CTRL_HOST_FORCE_LS_SE0_SHIFT (28U) #define USBPHY_CTRL_HOST_FORCE_LS_SE0(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_HOST_FORCE_LS_SE0_SHIFT)) & USBPHY_CTRL_HOST_FORCE_LS_SE0_MASK) #define USBPHY_CTRL_UTMI_SUSPENDM_MASK (0x20000000U) #define USBPHY_CTRL_UTMI_SUSPENDM_SHIFT (29U) #define USBPHY_CTRL_UTMI_SUSPENDM(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_UTMI_SUSPENDM_SHIFT)) & USBPHY_CTRL_UTMI_SUSPENDM_MASK) #define USBPHY_CTRL_CLKGATE_MASK (0x40000000U) #define USBPHY_CTRL_CLKGATE_SHIFT (30U) #define USBPHY_CTRL_CLKGATE(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_CLKGATE_SHIFT)) & USBPHY_CTRL_CLKGATE_MASK) #define USBPHY_CTRL_SFTRST_MASK (0x80000000U) #define USBPHY_CTRL_SFTRST_SHIFT (31U) #define USBPHY_CTRL_SFTRST(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_SFTRST_SHIFT)) & USBPHY_CTRL_SFTRST_MASK) /*! @} */ /*! @name CTRL_SET - USB PHY General Control Register */ /*! @{ */ #define USBPHY_CTRL_SET_ENOTG_ID_CHG_IRQ_MASK (0x1U) #define USBPHY_CTRL_SET_ENOTG_ID_CHG_IRQ_SHIFT (0U) #define USBPHY_CTRL_SET_ENOTG_ID_CHG_IRQ(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_SET_ENOTG_ID_CHG_IRQ_SHIFT)) & USBPHY_CTRL_SET_ENOTG_ID_CHG_IRQ_MASK) #define USBPHY_CTRL_SET_ENHOSTDISCONDETECT_MASK (0x2U) #define USBPHY_CTRL_SET_ENHOSTDISCONDETECT_SHIFT (1U) #define USBPHY_CTRL_SET_ENHOSTDISCONDETECT(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_SET_ENHOSTDISCONDETECT_SHIFT)) & USBPHY_CTRL_SET_ENHOSTDISCONDETECT_MASK) #define USBPHY_CTRL_SET_ENIRQHOSTDISCON_MASK (0x4U) #define USBPHY_CTRL_SET_ENIRQHOSTDISCON_SHIFT (2U) #define USBPHY_CTRL_SET_ENIRQHOSTDISCON(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_SET_ENIRQHOSTDISCON_SHIFT)) & USBPHY_CTRL_SET_ENIRQHOSTDISCON_MASK) #define USBPHY_CTRL_SET_HOSTDISCONDETECT_IRQ_MASK (0x8U) #define USBPHY_CTRL_SET_HOSTDISCONDETECT_IRQ_SHIFT (3U) #define USBPHY_CTRL_SET_HOSTDISCONDETECT_IRQ(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_SET_HOSTDISCONDETECT_IRQ_SHIFT)) & USBPHY_CTRL_SET_HOSTDISCONDETECT_IRQ_MASK) #define USBPHY_CTRL_SET_ENDEVPLUGINDETECT_MASK (0x10U) #define USBPHY_CTRL_SET_ENDEVPLUGINDETECT_SHIFT (4U) #define USBPHY_CTRL_SET_ENDEVPLUGINDETECT(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_SET_ENDEVPLUGINDETECT_SHIFT)) & USBPHY_CTRL_SET_ENDEVPLUGINDETECT_MASK) #define USBPHY_CTRL_SET_DEVPLUGIN_POLARITY_MASK (0x20U) #define USBPHY_CTRL_SET_DEVPLUGIN_POLARITY_SHIFT (5U) #define USBPHY_CTRL_SET_DEVPLUGIN_POLARITY(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_SET_DEVPLUGIN_POLARITY_SHIFT)) & USBPHY_CTRL_SET_DEVPLUGIN_POLARITY_MASK) #define USBPHY_CTRL_SET_OTG_ID_CHG_IRQ_MASK (0x40U) #define USBPHY_CTRL_SET_OTG_ID_CHG_IRQ_SHIFT (6U) #define USBPHY_CTRL_SET_OTG_ID_CHG_IRQ(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_SET_OTG_ID_CHG_IRQ_SHIFT)) & USBPHY_CTRL_SET_OTG_ID_CHG_IRQ_MASK) #define USBPHY_CTRL_SET_ENOTGIDDETECT_MASK (0x80U) #define USBPHY_CTRL_SET_ENOTGIDDETECT_SHIFT (7U) #define USBPHY_CTRL_SET_ENOTGIDDETECT(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_SET_ENOTGIDDETECT_SHIFT)) & USBPHY_CTRL_SET_ENOTGIDDETECT_MASK) #define USBPHY_CTRL_SET_RESUMEIRQSTICKY_MASK (0x100U) #define USBPHY_CTRL_SET_RESUMEIRQSTICKY_SHIFT (8U) #define USBPHY_CTRL_SET_RESUMEIRQSTICKY(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_SET_RESUMEIRQSTICKY_SHIFT)) & USBPHY_CTRL_SET_RESUMEIRQSTICKY_MASK) #define USBPHY_CTRL_SET_ENIRQRESUMEDETECT_MASK (0x200U) #define USBPHY_CTRL_SET_ENIRQRESUMEDETECT_SHIFT (9U) #define USBPHY_CTRL_SET_ENIRQRESUMEDETECT(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_SET_ENIRQRESUMEDETECT_SHIFT)) & USBPHY_CTRL_SET_ENIRQRESUMEDETECT_MASK) #define USBPHY_CTRL_SET_RESUME_IRQ_MASK (0x400U) #define USBPHY_CTRL_SET_RESUME_IRQ_SHIFT (10U) #define USBPHY_CTRL_SET_RESUME_IRQ(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_SET_RESUME_IRQ_SHIFT)) & USBPHY_CTRL_SET_RESUME_IRQ_MASK) #define USBPHY_CTRL_SET_ENIRQDEVPLUGIN_MASK (0x800U) #define USBPHY_CTRL_SET_ENIRQDEVPLUGIN_SHIFT (11U) #define USBPHY_CTRL_SET_ENIRQDEVPLUGIN(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_SET_ENIRQDEVPLUGIN_SHIFT)) & USBPHY_CTRL_SET_ENIRQDEVPLUGIN_MASK) #define USBPHY_CTRL_SET_DEVPLUGIN_IRQ_MASK (0x1000U) #define USBPHY_CTRL_SET_DEVPLUGIN_IRQ_SHIFT (12U) #define USBPHY_CTRL_SET_DEVPLUGIN_IRQ(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_SET_DEVPLUGIN_IRQ_SHIFT)) & USBPHY_CTRL_SET_DEVPLUGIN_IRQ_MASK) #define USBPHY_CTRL_SET_DATA_ON_LRADC_MASK (0x2000U) #define USBPHY_CTRL_SET_DATA_ON_LRADC_SHIFT (13U) #define USBPHY_CTRL_SET_DATA_ON_LRADC(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_SET_DATA_ON_LRADC_SHIFT)) & USBPHY_CTRL_SET_DATA_ON_LRADC_MASK) #define USBPHY_CTRL_SET_ENUTMILEVEL2_MASK (0x4000U) #define USBPHY_CTRL_SET_ENUTMILEVEL2_SHIFT (14U) #define USBPHY_CTRL_SET_ENUTMILEVEL2(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_SET_ENUTMILEVEL2_SHIFT)) & USBPHY_CTRL_SET_ENUTMILEVEL2_MASK) #define USBPHY_CTRL_SET_ENUTMILEVEL3_MASK (0x8000U) #define USBPHY_CTRL_SET_ENUTMILEVEL3_SHIFT (15U) #define USBPHY_CTRL_SET_ENUTMILEVEL3(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_SET_ENUTMILEVEL3_SHIFT)) & USBPHY_CTRL_SET_ENUTMILEVEL3_MASK) #define USBPHY_CTRL_SET_ENIRQWAKEUP_MASK (0x10000U) #define USBPHY_CTRL_SET_ENIRQWAKEUP_SHIFT (16U) #define USBPHY_CTRL_SET_ENIRQWAKEUP(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_SET_ENIRQWAKEUP_SHIFT)) & USBPHY_CTRL_SET_ENIRQWAKEUP_MASK) #define USBPHY_CTRL_SET_WAKEUP_IRQ_MASK (0x20000U) #define USBPHY_CTRL_SET_WAKEUP_IRQ_SHIFT (17U) #define USBPHY_CTRL_SET_WAKEUP_IRQ(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_SET_WAKEUP_IRQ_SHIFT)) & USBPHY_CTRL_SET_WAKEUP_IRQ_MASK) #define USBPHY_CTRL_SET_ENAUTO_PWRON_PLL_MASK (0x40000U) #define USBPHY_CTRL_SET_ENAUTO_PWRON_PLL_SHIFT (18U) #define USBPHY_CTRL_SET_ENAUTO_PWRON_PLL(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_SET_ENAUTO_PWRON_PLL_SHIFT)) & USBPHY_CTRL_SET_ENAUTO_PWRON_PLL_MASK) #define USBPHY_CTRL_SET_ENAUTOCLR_CLKGATE_MASK (0x80000U) #define USBPHY_CTRL_SET_ENAUTOCLR_CLKGATE_SHIFT (19U) #define USBPHY_CTRL_SET_ENAUTOCLR_CLKGATE(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_SET_ENAUTOCLR_CLKGATE_SHIFT)) & USBPHY_CTRL_SET_ENAUTOCLR_CLKGATE_MASK) #define USBPHY_CTRL_SET_ENAUTOCLR_PHY_PWD_MASK (0x100000U) #define USBPHY_CTRL_SET_ENAUTOCLR_PHY_PWD_SHIFT (20U) #define USBPHY_CTRL_SET_ENAUTOCLR_PHY_PWD(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_SET_ENAUTOCLR_PHY_PWD_SHIFT)) & USBPHY_CTRL_SET_ENAUTOCLR_PHY_PWD_MASK) #define USBPHY_CTRL_SET_ENDPDMCHG_WKUP_MASK (0x200000U) #define USBPHY_CTRL_SET_ENDPDMCHG_WKUP_SHIFT (21U) #define USBPHY_CTRL_SET_ENDPDMCHG_WKUP(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_SET_ENDPDMCHG_WKUP_SHIFT)) & USBPHY_CTRL_SET_ENDPDMCHG_WKUP_MASK) #define USBPHY_CTRL_SET_ENIDCHG_WKUP_MASK (0x400000U) #define USBPHY_CTRL_SET_ENIDCHG_WKUP_SHIFT (22U) #define USBPHY_CTRL_SET_ENIDCHG_WKUP(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_SET_ENIDCHG_WKUP_SHIFT)) & USBPHY_CTRL_SET_ENIDCHG_WKUP_MASK) #define USBPHY_CTRL_SET_ENVBUSCHG_WKUP_MASK (0x800000U) #define USBPHY_CTRL_SET_ENVBUSCHG_WKUP_SHIFT (23U) #define USBPHY_CTRL_SET_ENVBUSCHG_WKUP(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_SET_ENVBUSCHG_WKUP_SHIFT)) & USBPHY_CTRL_SET_ENVBUSCHG_WKUP_MASK) #define USBPHY_CTRL_SET_FSDLL_RST_EN_MASK (0x1000000U) #define USBPHY_CTRL_SET_FSDLL_RST_EN_SHIFT (24U) #define USBPHY_CTRL_SET_FSDLL_RST_EN(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_SET_FSDLL_RST_EN_SHIFT)) & USBPHY_CTRL_SET_FSDLL_RST_EN_MASK) #define USBPHY_CTRL_SET_RSVD1_MASK (0x6000000U) #define USBPHY_CTRL_SET_RSVD1_SHIFT (25U) #define USBPHY_CTRL_SET_RSVD1(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_SET_RSVD1_SHIFT)) & USBPHY_CTRL_SET_RSVD1_MASK) #define USBPHY_CTRL_SET_OTG_ID_VALUE_MASK (0x8000000U) #define USBPHY_CTRL_SET_OTG_ID_VALUE_SHIFT (27U) #define USBPHY_CTRL_SET_OTG_ID_VALUE(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_SET_OTG_ID_VALUE_SHIFT)) & USBPHY_CTRL_SET_OTG_ID_VALUE_MASK) #define USBPHY_CTRL_SET_HOST_FORCE_LS_SE0_MASK (0x10000000U) #define USBPHY_CTRL_SET_HOST_FORCE_LS_SE0_SHIFT (28U) #define USBPHY_CTRL_SET_HOST_FORCE_LS_SE0(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_SET_HOST_FORCE_LS_SE0_SHIFT)) & USBPHY_CTRL_SET_HOST_FORCE_LS_SE0_MASK) #define USBPHY_CTRL_SET_UTMI_SUSPENDM_MASK (0x20000000U) #define USBPHY_CTRL_SET_UTMI_SUSPENDM_SHIFT (29U) #define USBPHY_CTRL_SET_UTMI_SUSPENDM(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_SET_UTMI_SUSPENDM_SHIFT)) & USBPHY_CTRL_SET_UTMI_SUSPENDM_MASK) #define USBPHY_CTRL_SET_CLKGATE_MASK (0x40000000U) #define USBPHY_CTRL_SET_CLKGATE_SHIFT (30U) #define USBPHY_CTRL_SET_CLKGATE(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_SET_CLKGATE_SHIFT)) & USBPHY_CTRL_SET_CLKGATE_MASK) #define USBPHY_CTRL_SET_SFTRST_MASK (0x80000000U) #define USBPHY_CTRL_SET_SFTRST_SHIFT (31U) #define USBPHY_CTRL_SET_SFTRST(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_SET_SFTRST_SHIFT)) & USBPHY_CTRL_SET_SFTRST_MASK) /*! @} */ /*! @name CTRL_CLR - USB PHY General Control Register */ /*! @{ */ #define USBPHY_CTRL_CLR_ENOTG_ID_CHG_IRQ_MASK (0x1U) #define USBPHY_CTRL_CLR_ENOTG_ID_CHG_IRQ_SHIFT (0U) #define USBPHY_CTRL_CLR_ENOTG_ID_CHG_IRQ(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_CLR_ENOTG_ID_CHG_IRQ_SHIFT)) & USBPHY_CTRL_CLR_ENOTG_ID_CHG_IRQ_MASK) #define USBPHY_CTRL_CLR_ENHOSTDISCONDETECT_MASK (0x2U) #define USBPHY_CTRL_CLR_ENHOSTDISCONDETECT_SHIFT (1U) #define USBPHY_CTRL_CLR_ENHOSTDISCONDETECT(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_CLR_ENHOSTDISCONDETECT_SHIFT)) & USBPHY_CTRL_CLR_ENHOSTDISCONDETECT_MASK) #define USBPHY_CTRL_CLR_ENIRQHOSTDISCON_MASK (0x4U) #define USBPHY_CTRL_CLR_ENIRQHOSTDISCON_SHIFT (2U) #define USBPHY_CTRL_CLR_ENIRQHOSTDISCON(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_CLR_ENIRQHOSTDISCON_SHIFT)) & USBPHY_CTRL_CLR_ENIRQHOSTDISCON_MASK) #define USBPHY_CTRL_CLR_HOSTDISCONDETECT_IRQ_MASK (0x8U) #define USBPHY_CTRL_CLR_HOSTDISCONDETECT_IRQ_SHIFT (3U) #define USBPHY_CTRL_CLR_HOSTDISCONDETECT_IRQ(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_CLR_HOSTDISCONDETECT_IRQ_SHIFT)) & USBPHY_CTRL_CLR_HOSTDISCONDETECT_IRQ_MASK) #define USBPHY_CTRL_CLR_ENDEVPLUGINDETECT_MASK (0x10U) #define USBPHY_CTRL_CLR_ENDEVPLUGINDETECT_SHIFT (4U) #define USBPHY_CTRL_CLR_ENDEVPLUGINDETECT(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_CLR_ENDEVPLUGINDETECT_SHIFT)) & USBPHY_CTRL_CLR_ENDEVPLUGINDETECT_MASK) #define USBPHY_CTRL_CLR_DEVPLUGIN_POLARITY_MASK (0x20U) #define USBPHY_CTRL_CLR_DEVPLUGIN_POLARITY_SHIFT (5U) #define USBPHY_CTRL_CLR_DEVPLUGIN_POLARITY(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_CLR_DEVPLUGIN_POLARITY_SHIFT)) & USBPHY_CTRL_CLR_DEVPLUGIN_POLARITY_MASK) #define USBPHY_CTRL_CLR_OTG_ID_CHG_IRQ_MASK (0x40U) #define USBPHY_CTRL_CLR_OTG_ID_CHG_IRQ_SHIFT (6U) #define USBPHY_CTRL_CLR_OTG_ID_CHG_IRQ(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_CLR_OTG_ID_CHG_IRQ_SHIFT)) & USBPHY_CTRL_CLR_OTG_ID_CHG_IRQ_MASK) #define USBPHY_CTRL_CLR_ENOTGIDDETECT_MASK (0x80U) #define USBPHY_CTRL_CLR_ENOTGIDDETECT_SHIFT (7U) #define USBPHY_CTRL_CLR_ENOTGIDDETECT(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_CLR_ENOTGIDDETECT_SHIFT)) & USBPHY_CTRL_CLR_ENOTGIDDETECT_MASK) #define USBPHY_CTRL_CLR_RESUMEIRQSTICKY_MASK (0x100U) #define USBPHY_CTRL_CLR_RESUMEIRQSTICKY_SHIFT (8U) #define USBPHY_CTRL_CLR_RESUMEIRQSTICKY(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_CLR_RESUMEIRQSTICKY_SHIFT)) & USBPHY_CTRL_CLR_RESUMEIRQSTICKY_MASK) #define USBPHY_CTRL_CLR_ENIRQRESUMEDETECT_MASK (0x200U) #define USBPHY_CTRL_CLR_ENIRQRESUMEDETECT_SHIFT (9U) #define USBPHY_CTRL_CLR_ENIRQRESUMEDETECT(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_CLR_ENIRQRESUMEDETECT_SHIFT)) & USBPHY_CTRL_CLR_ENIRQRESUMEDETECT_MASK) #define USBPHY_CTRL_CLR_RESUME_IRQ_MASK (0x400U) #define USBPHY_CTRL_CLR_RESUME_IRQ_SHIFT (10U) #define USBPHY_CTRL_CLR_RESUME_IRQ(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_CLR_RESUME_IRQ_SHIFT)) & USBPHY_CTRL_CLR_RESUME_IRQ_MASK) #define USBPHY_CTRL_CLR_ENIRQDEVPLUGIN_MASK (0x800U) #define USBPHY_CTRL_CLR_ENIRQDEVPLUGIN_SHIFT (11U) #define USBPHY_CTRL_CLR_ENIRQDEVPLUGIN(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_CLR_ENIRQDEVPLUGIN_SHIFT)) & USBPHY_CTRL_CLR_ENIRQDEVPLUGIN_MASK) #define USBPHY_CTRL_CLR_DEVPLUGIN_IRQ_MASK (0x1000U) #define USBPHY_CTRL_CLR_DEVPLUGIN_IRQ_SHIFT (12U) #define USBPHY_CTRL_CLR_DEVPLUGIN_IRQ(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_CLR_DEVPLUGIN_IRQ_SHIFT)) & USBPHY_CTRL_CLR_DEVPLUGIN_IRQ_MASK) #define USBPHY_CTRL_CLR_DATA_ON_LRADC_MASK (0x2000U) #define USBPHY_CTRL_CLR_DATA_ON_LRADC_SHIFT (13U) #define USBPHY_CTRL_CLR_DATA_ON_LRADC(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_CLR_DATA_ON_LRADC_SHIFT)) & USBPHY_CTRL_CLR_DATA_ON_LRADC_MASK) #define USBPHY_CTRL_CLR_ENUTMILEVEL2_MASK (0x4000U) #define USBPHY_CTRL_CLR_ENUTMILEVEL2_SHIFT (14U) #define USBPHY_CTRL_CLR_ENUTMILEVEL2(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_CLR_ENUTMILEVEL2_SHIFT)) & USBPHY_CTRL_CLR_ENUTMILEVEL2_MASK) #define USBPHY_CTRL_CLR_ENUTMILEVEL3_MASK (0x8000U) #define USBPHY_CTRL_CLR_ENUTMILEVEL3_SHIFT (15U) #define USBPHY_CTRL_CLR_ENUTMILEVEL3(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_CLR_ENUTMILEVEL3_SHIFT)) & USBPHY_CTRL_CLR_ENUTMILEVEL3_MASK) #define USBPHY_CTRL_CLR_ENIRQWAKEUP_MASK (0x10000U) #define USBPHY_CTRL_CLR_ENIRQWAKEUP_SHIFT (16U) #define USBPHY_CTRL_CLR_ENIRQWAKEUP(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_CLR_ENIRQWAKEUP_SHIFT)) & USBPHY_CTRL_CLR_ENIRQWAKEUP_MASK) #define USBPHY_CTRL_CLR_WAKEUP_IRQ_MASK (0x20000U) #define USBPHY_CTRL_CLR_WAKEUP_IRQ_SHIFT (17U) #define USBPHY_CTRL_CLR_WAKEUP_IRQ(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_CLR_WAKEUP_IRQ_SHIFT)) & USBPHY_CTRL_CLR_WAKEUP_IRQ_MASK) #define USBPHY_CTRL_CLR_ENAUTO_PWRON_PLL_MASK (0x40000U) #define USBPHY_CTRL_CLR_ENAUTO_PWRON_PLL_SHIFT (18U) #define USBPHY_CTRL_CLR_ENAUTO_PWRON_PLL(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_CLR_ENAUTO_PWRON_PLL_SHIFT)) & USBPHY_CTRL_CLR_ENAUTO_PWRON_PLL_MASK) #define USBPHY_CTRL_CLR_ENAUTOCLR_CLKGATE_MASK (0x80000U) #define USBPHY_CTRL_CLR_ENAUTOCLR_CLKGATE_SHIFT (19U) #define USBPHY_CTRL_CLR_ENAUTOCLR_CLKGATE(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_CLR_ENAUTOCLR_CLKGATE_SHIFT)) & USBPHY_CTRL_CLR_ENAUTOCLR_CLKGATE_MASK) #define USBPHY_CTRL_CLR_ENAUTOCLR_PHY_PWD_MASK (0x100000U) #define USBPHY_CTRL_CLR_ENAUTOCLR_PHY_PWD_SHIFT (20U) #define USBPHY_CTRL_CLR_ENAUTOCLR_PHY_PWD(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_CLR_ENAUTOCLR_PHY_PWD_SHIFT)) & USBPHY_CTRL_CLR_ENAUTOCLR_PHY_PWD_MASK) #define USBPHY_CTRL_CLR_ENDPDMCHG_WKUP_MASK (0x200000U) #define USBPHY_CTRL_CLR_ENDPDMCHG_WKUP_SHIFT (21U) #define USBPHY_CTRL_CLR_ENDPDMCHG_WKUP(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_CLR_ENDPDMCHG_WKUP_SHIFT)) & USBPHY_CTRL_CLR_ENDPDMCHG_WKUP_MASK) #define USBPHY_CTRL_CLR_ENIDCHG_WKUP_MASK (0x400000U) #define USBPHY_CTRL_CLR_ENIDCHG_WKUP_SHIFT (22U) #define USBPHY_CTRL_CLR_ENIDCHG_WKUP(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_CLR_ENIDCHG_WKUP_SHIFT)) & USBPHY_CTRL_CLR_ENIDCHG_WKUP_MASK) #define USBPHY_CTRL_CLR_ENVBUSCHG_WKUP_MASK (0x800000U) #define USBPHY_CTRL_CLR_ENVBUSCHG_WKUP_SHIFT (23U) #define USBPHY_CTRL_CLR_ENVBUSCHG_WKUP(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_CLR_ENVBUSCHG_WKUP_SHIFT)) & USBPHY_CTRL_CLR_ENVBUSCHG_WKUP_MASK) #define USBPHY_CTRL_CLR_FSDLL_RST_EN_MASK (0x1000000U) #define USBPHY_CTRL_CLR_FSDLL_RST_EN_SHIFT (24U) #define USBPHY_CTRL_CLR_FSDLL_RST_EN(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_CLR_FSDLL_RST_EN_SHIFT)) & USBPHY_CTRL_CLR_FSDLL_RST_EN_MASK) #define USBPHY_CTRL_CLR_RSVD1_MASK (0x6000000U) #define USBPHY_CTRL_CLR_RSVD1_SHIFT (25U) #define USBPHY_CTRL_CLR_RSVD1(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_CLR_RSVD1_SHIFT)) & USBPHY_CTRL_CLR_RSVD1_MASK) #define USBPHY_CTRL_CLR_OTG_ID_VALUE_MASK (0x8000000U) #define USBPHY_CTRL_CLR_OTG_ID_VALUE_SHIFT (27U) #define USBPHY_CTRL_CLR_OTG_ID_VALUE(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_CLR_OTG_ID_VALUE_SHIFT)) & USBPHY_CTRL_CLR_OTG_ID_VALUE_MASK) #define USBPHY_CTRL_CLR_HOST_FORCE_LS_SE0_MASK (0x10000000U) #define USBPHY_CTRL_CLR_HOST_FORCE_LS_SE0_SHIFT (28U) #define USBPHY_CTRL_CLR_HOST_FORCE_LS_SE0(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_CLR_HOST_FORCE_LS_SE0_SHIFT)) & USBPHY_CTRL_CLR_HOST_FORCE_LS_SE0_MASK) #define USBPHY_CTRL_CLR_UTMI_SUSPENDM_MASK (0x20000000U) #define USBPHY_CTRL_CLR_UTMI_SUSPENDM_SHIFT (29U) #define USBPHY_CTRL_CLR_UTMI_SUSPENDM(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_CLR_UTMI_SUSPENDM_SHIFT)) & USBPHY_CTRL_CLR_UTMI_SUSPENDM_MASK) #define USBPHY_CTRL_CLR_CLKGATE_MASK (0x40000000U) #define USBPHY_CTRL_CLR_CLKGATE_SHIFT (30U) #define USBPHY_CTRL_CLR_CLKGATE(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_CLR_CLKGATE_SHIFT)) & USBPHY_CTRL_CLR_CLKGATE_MASK) #define USBPHY_CTRL_CLR_SFTRST_MASK (0x80000000U) #define USBPHY_CTRL_CLR_SFTRST_SHIFT (31U) #define USBPHY_CTRL_CLR_SFTRST(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_CLR_SFTRST_SHIFT)) & USBPHY_CTRL_CLR_SFTRST_MASK) /*! @} */ /*! @name CTRL_TOG - USB PHY General Control Register */ /*! @{ */ #define USBPHY_CTRL_TOG_ENOTG_ID_CHG_IRQ_MASK (0x1U) #define USBPHY_CTRL_TOG_ENOTG_ID_CHG_IRQ_SHIFT (0U) #define USBPHY_CTRL_TOG_ENOTG_ID_CHG_IRQ(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_TOG_ENOTG_ID_CHG_IRQ_SHIFT)) & USBPHY_CTRL_TOG_ENOTG_ID_CHG_IRQ_MASK) #define USBPHY_CTRL_TOG_ENHOSTDISCONDETECT_MASK (0x2U) #define USBPHY_CTRL_TOG_ENHOSTDISCONDETECT_SHIFT (1U) #define USBPHY_CTRL_TOG_ENHOSTDISCONDETECT(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_TOG_ENHOSTDISCONDETECT_SHIFT)) & USBPHY_CTRL_TOG_ENHOSTDISCONDETECT_MASK) #define USBPHY_CTRL_TOG_ENIRQHOSTDISCON_MASK (0x4U) #define USBPHY_CTRL_TOG_ENIRQHOSTDISCON_SHIFT (2U) #define USBPHY_CTRL_TOG_ENIRQHOSTDISCON(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_TOG_ENIRQHOSTDISCON_SHIFT)) & USBPHY_CTRL_TOG_ENIRQHOSTDISCON_MASK) #define USBPHY_CTRL_TOG_HOSTDISCONDETECT_IRQ_MASK (0x8U) #define USBPHY_CTRL_TOG_HOSTDISCONDETECT_IRQ_SHIFT (3U) #define USBPHY_CTRL_TOG_HOSTDISCONDETECT_IRQ(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_TOG_HOSTDISCONDETECT_IRQ_SHIFT)) & USBPHY_CTRL_TOG_HOSTDISCONDETECT_IRQ_MASK) #define USBPHY_CTRL_TOG_ENDEVPLUGINDETECT_MASK (0x10U) #define USBPHY_CTRL_TOG_ENDEVPLUGINDETECT_SHIFT (4U) #define USBPHY_CTRL_TOG_ENDEVPLUGINDETECT(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_TOG_ENDEVPLUGINDETECT_SHIFT)) & USBPHY_CTRL_TOG_ENDEVPLUGINDETECT_MASK) #define USBPHY_CTRL_TOG_DEVPLUGIN_POLARITY_MASK (0x20U) #define USBPHY_CTRL_TOG_DEVPLUGIN_POLARITY_SHIFT (5U) #define USBPHY_CTRL_TOG_DEVPLUGIN_POLARITY(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_TOG_DEVPLUGIN_POLARITY_SHIFT)) & USBPHY_CTRL_TOG_DEVPLUGIN_POLARITY_MASK) #define USBPHY_CTRL_TOG_OTG_ID_CHG_IRQ_MASK (0x40U) #define USBPHY_CTRL_TOG_OTG_ID_CHG_IRQ_SHIFT (6U) #define USBPHY_CTRL_TOG_OTG_ID_CHG_IRQ(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_TOG_OTG_ID_CHG_IRQ_SHIFT)) & USBPHY_CTRL_TOG_OTG_ID_CHG_IRQ_MASK) #define USBPHY_CTRL_TOG_ENOTGIDDETECT_MASK (0x80U) #define USBPHY_CTRL_TOG_ENOTGIDDETECT_SHIFT (7U) #define USBPHY_CTRL_TOG_ENOTGIDDETECT(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_TOG_ENOTGIDDETECT_SHIFT)) & USBPHY_CTRL_TOG_ENOTGIDDETECT_MASK) #define USBPHY_CTRL_TOG_RESUMEIRQSTICKY_MASK (0x100U) #define USBPHY_CTRL_TOG_RESUMEIRQSTICKY_SHIFT (8U) #define USBPHY_CTRL_TOG_RESUMEIRQSTICKY(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_TOG_RESUMEIRQSTICKY_SHIFT)) & USBPHY_CTRL_TOG_RESUMEIRQSTICKY_MASK) #define USBPHY_CTRL_TOG_ENIRQRESUMEDETECT_MASK (0x200U) #define USBPHY_CTRL_TOG_ENIRQRESUMEDETECT_SHIFT (9U) #define USBPHY_CTRL_TOG_ENIRQRESUMEDETECT(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_TOG_ENIRQRESUMEDETECT_SHIFT)) & USBPHY_CTRL_TOG_ENIRQRESUMEDETECT_MASK) #define USBPHY_CTRL_TOG_RESUME_IRQ_MASK (0x400U) #define USBPHY_CTRL_TOG_RESUME_IRQ_SHIFT (10U) #define USBPHY_CTRL_TOG_RESUME_IRQ(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_TOG_RESUME_IRQ_SHIFT)) & USBPHY_CTRL_TOG_RESUME_IRQ_MASK) #define USBPHY_CTRL_TOG_ENIRQDEVPLUGIN_MASK (0x800U) #define USBPHY_CTRL_TOG_ENIRQDEVPLUGIN_SHIFT (11U) #define USBPHY_CTRL_TOG_ENIRQDEVPLUGIN(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_TOG_ENIRQDEVPLUGIN_SHIFT)) & USBPHY_CTRL_TOG_ENIRQDEVPLUGIN_MASK) #define USBPHY_CTRL_TOG_DEVPLUGIN_IRQ_MASK (0x1000U) #define USBPHY_CTRL_TOG_DEVPLUGIN_IRQ_SHIFT (12U) #define USBPHY_CTRL_TOG_DEVPLUGIN_IRQ(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_TOG_DEVPLUGIN_IRQ_SHIFT)) & USBPHY_CTRL_TOG_DEVPLUGIN_IRQ_MASK) #define USBPHY_CTRL_TOG_DATA_ON_LRADC_MASK (0x2000U) #define USBPHY_CTRL_TOG_DATA_ON_LRADC_SHIFT (13U) #define USBPHY_CTRL_TOG_DATA_ON_LRADC(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_TOG_DATA_ON_LRADC_SHIFT)) & USBPHY_CTRL_TOG_DATA_ON_LRADC_MASK) #define USBPHY_CTRL_TOG_ENUTMILEVEL2_MASK (0x4000U) #define USBPHY_CTRL_TOG_ENUTMILEVEL2_SHIFT (14U) #define USBPHY_CTRL_TOG_ENUTMILEVEL2(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_TOG_ENUTMILEVEL2_SHIFT)) & USBPHY_CTRL_TOG_ENUTMILEVEL2_MASK) #define USBPHY_CTRL_TOG_ENUTMILEVEL3_MASK (0x8000U) #define USBPHY_CTRL_TOG_ENUTMILEVEL3_SHIFT (15U) #define USBPHY_CTRL_TOG_ENUTMILEVEL3(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_TOG_ENUTMILEVEL3_SHIFT)) & USBPHY_CTRL_TOG_ENUTMILEVEL3_MASK) #define USBPHY_CTRL_TOG_ENIRQWAKEUP_MASK (0x10000U) #define USBPHY_CTRL_TOG_ENIRQWAKEUP_SHIFT (16U) #define USBPHY_CTRL_TOG_ENIRQWAKEUP(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_TOG_ENIRQWAKEUP_SHIFT)) & USBPHY_CTRL_TOG_ENIRQWAKEUP_MASK) #define USBPHY_CTRL_TOG_WAKEUP_IRQ_MASK (0x20000U) #define USBPHY_CTRL_TOG_WAKEUP_IRQ_SHIFT (17U) #define USBPHY_CTRL_TOG_WAKEUP_IRQ(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_TOG_WAKEUP_IRQ_SHIFT)) & USBPHY_CTRL_TOG_WAKEUP_IRQ_MASK) #define USBPHY_CTRL_TOG_ENAUTO_PWRON_PLL_MASK (0x40000U) #define USBPHY_CTRL_TOG_ENAUTO_PWRON_PLL_SHIFT (18U) #define USBPHY_CTRL_TOG_ENAUTO_PWRON_PLL(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_TOG_ENAUTO_PWRON_PLL_SHIFT)) & USBPHY_CTRL_TOG_ENAUTO_PWRON_PLL_MASK) #define USBPHY_CTRL_TOG_ENAUTOCLR_CLKGATE_MASK (0x80000U) #define USBPHY_CTRL_TOG_ENAUTOCLR_CLKGATE_SHIFT (19U) #define USBPHY_CTRL_TOG_ENAUTOCLR_CLKGATE(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_TOG_ENAUTOCLR_CLKGATE_SHIFT)) & USBPHY_CTRL_TOG_ENAUTOCLR_CLKGATE_MASK) #define USBPHY_CTRL_TOG_ENAUTOCLR_PHY_PWD_MASK (0x100000U) #define USBPHY_CTRL_TOG_ENAUTOCLR_PHY_PWD_SHIFT (20U) #define USBPHY_CTRL_TOG_ENAUTOCLR_PHY_PWD(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_TOG_ENAUTOCLR_PHY_PWD_SHIFT)) & USBPHY_CTRL_TOG_ENAUTOCLR_PHY_PWD_MASK) #define USBPHY_CTRL_TOG_ENDPDMCHG_WKUP_MASK (0x200000U) #define USBPHY_CTRL_TOG_ENDPDMCHG_WKUP_SHIFT (21U) #define USBPHY_CTRL_TOG_ENDPDMCHG_WKUP(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_TOG_ENDPDMCHG_WKUP_SHIFT)) & USBPHY_CTRL_TOG_ENDPDMCHG_WKUP_MASK) #define USBPHY_CTRL_TOG_ENIDCHG_WKUP_MASK (0x400000U) #define USBPHY_CTRL_TOG_ENIDCHG_WKUP_SHIFT (22U) #define USBPHY_CTRL_TOG_ENIDCHG_WKUP(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_TOG_ENIDCHG_WKUP_SHIFT)) & USBPHY_CTRL_TOG_ENIDCHG_WKUP_MASK) #define USBPHY_CTRL_TOG_ENVBUSCHG_WKUP_MASK (0x800000U) #define USBPHY_CTRL_TOG_ENVBUSCHG_WKUP_SHIFT (23U) #define USBPHY_CTRL_TOG_ENVBUSCHG_WKUP(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_TOG_ENVBUSCHG_WKUP_SHIFT)) & USBPHY_CTRL_TOG_ENVBUSCHG_WKUP_MASK) #define USBPHY_CTRL_TOG_FSDLL_RST_EN_MASK (0x1000000U) #define USBPHY_CTRL_TOG_FSDLL_RST_EN_SHIFT (24U) #define USBPHY_CTRL_TOG_FSDLL_RST_EN(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_TOG_FSDLL_RST_EN_SHIFT)) & USBPHY_CTRL_TOG_FSDLL_RST_EN_MASK) #define USBPHY_CTRL_TOG_RSVD1_MASK (0x6000000U) #define USBPHY_CTRL_TOG_RSVD1_SHIFT (25U) #define USBPHY_CTRL_TOG_RSVD1(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_TOG_RSVD1_SHIFT)) & USBPHY_CTRL_TOG_RSVD1_MASK) #define USBPHY_CTRL_TOG_OTG_ID_VALUE_MASK (0x8000000U) #define USBPHY_CTRL_TOG_OTG_ID_VALUE_SHIFT (27U) #define USBPHY_CTRL_TOG_OTG_ID_VALUE(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_TOG_OTG_ID_VALUE_SHIFT)) & USBPHY_CTRL_TOG_OTG_ID_VALUE_MASK) #define USBPHY_CTRL_TOG_HOST_FORCE_LS_SE0_MASK (0x10000000U) #define USBPHY_CTRL_TOG_HOST_FORCE_LS_SE0_SHIFT (28U) #define USBPHY_CTRL_TOG_HOST_FORCE_LS_SE0(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_TOG_HOST_FORCE_LS_SE0_SHIFT)) & USBPHY_CTRL_TOG_HOST_FORCE_LS_SE0_MASK) #define USBPHY_CTRL_TOG_UTMI_SUSPENDM_MASK (0x20000000U) #define USBPHY_CTRL_TOG_UTMI_SUSPENDM_SHIFT (29U) #define USBPHY_CTRL_TOG_UTMI_SUSPENDM(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_TOG_UTMI_SUSPENDM_SHIFT)) & USBPHY_CTRL_TOG_UTMI_SUSPENDM_MASK) #define USBPHY_CTRL_TOG_CLKGATE_MASK (0x40000000U) #define USBPHY_CTRL_TOG_CLKGATE_SHIFT (30U) #define USBPHY_CTRL_TOG_CLKGATE(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_TOG_CLKGATE_SHIFT)) & USBPHY_CTRL_TOG_CLKGATE_MASK) #define USBPHY_CTRL_TOG_SFTRST_MASK (0x80000000U) #define USBPHY_CTRL_TOG_SFTRST_SHIFT (31U) #define USBPHY_CTRL_TOG_SFTRST(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_CTRL_TOG_SFTRST_SHIFT)) & USBPHY_CTRL_TOG_SFTRST_MASK) /*! @} */ /*! @name STATUS - USB PHY Status Register */ /*! @{ */ #define USBPHY_STATUS_RSVD0_MASK (0x7U) #define USBPHY_STATUS_RSVD0_SHIFT (0U) #define USBPHY_STATUS_RSVD0(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_STATUS_RSVD0_SHIFT)) & USBPHY_STATUS_RSVD0_MASK) #define USBPHY_STATUS_HOSTDISCONDETECT_STATUS_MASK (0x8U) #define USBPHY_STATUS_HOSTDISCONDETECT_STATUS_SHIFT (3U) #define USBPHY_STATUS_HOSTDISCONDETECT_STATUS(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_STATUS_HOSTDISCONDETECT_STATUS_SHIFT)) & USBPHY_STATUS_HOSTDISCONDETECT_STATUS_MASK) #define USBPHY_STATUS_RSVD1_MASK (0x30U) #define USBPHY_STATUS_RSVD1_SHIFT (4U) #define USBPHY_STATUS_RSVD1(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_STATUS_RSVD1_SHIFT)) & USBPHY_STATUS_RSVD1_MASK) #define USBPHY_STATUS_DEVPLUGIN_STATUS_MASK (0x40U) #define USBPHY_STATUS_DEVPLUGIN_STATUS_SHIFT (6U) #define USBPHY_STATUS_DEVPLUGIN_STATUS(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_STATUS_DEVPLUGIN_STATUS_SHIFT)) & USBPHY_STATUS_DEVPLUGIN_STATUS_MASK) #define USBPHY_STATUS_RSVD2_MASK (0x80U) #define USBPHY_STATUS_RSVD2_SHIFT (7U) #define USBPHY_STATUS_RSVD2(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_STATUS_RSVD2_SHIFT)) & USBPHY_STATUS_RSVD2_MASK) #define USBPHY_STATUS_OTGID_STATUS_MASK (0x100U) #define USBPHY_STATUS_OTGID_STATUS_SHIFT (8U) #define USBPHY_STATUS_OTGID_STATUS(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_STATUS_OTGID_STATUS_SHIFT)) & USBPHY_STATUS_OTGID_STATUS_MASK) #define USBPHY_STATUS_RSVD3_MASK (0x200U) #define USBPHY_STATUS_RSVD3_SHIFT (9U) #define USBPHY_STATUS_RSVD3(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_STATUS_RSVD3_SHIFT)) & USBPHY_STATUS_RSVD3_MASK) #define USBPHY_STATUS_RESUME_STATUS_MASK (0x400U) #define USBPHY_STATUS_RESUME_STATUS_SHIFT (10U) #define USBPHY_STATUS_RESUME_STATUS(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_STATUS_RESUME_STATUS_SHIFT)) & USBPHY_STATUS_RESUME_STATUS_MASK) #define USBPHY_STATUS_RSVD4_MASK (0xFFFFF800U) #define USBPHY_STATUS_RSVD4_SHIFT (11U) #define USBPHY_STATUS_RSVD4(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_STATUS_RSVD4_SHIFT)) & USBPHY_STATUS_RSVD4_MASK) /*! @} */ /*! @name DEBUG - USB PHY Debug Register */ /*! @{ */ #define USBPHY_DEBUG_OTGIDPIOLOCK_MASK (0x1U) #define USBPHY_DEBUG_OTGIDPIOLOCK_SHIFT (0U) #define USBPHY_DEBUG_OTGIDPIOLOCK(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_OTGIDPIOLOCK_SHIFT)) & USBPHY_DEBUG_OTGIDPIOLOCK_MASK) #define USBPHY_DEBUG_DEBUG_INTERFACE_HOLD_MASK (0x2U) #define USBPHY_DEBUG_DEBUG_INTERFACE_HOLD_SHIFT (1U) #define USBPHY_DEBUG_DEBUG_INTERFACE_HOLD(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_DEBUG_INTERFACE_HOLD_SHIFT)) & USBPHY_DEBUG_DEBUG_INTERFACE_HOLD_MASK) #define USBPHY_DEBUG_HSTPULLDOWN_MASK (0xCU) #define USBPHY_DEBUG_HSTPULLDOWN_SHIFT (2U) #define USBPHY_DEBUG_HSTPULLDOWN(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_HSTPULLDOWN_SHIFT)) & USBPHY_DEBUG_HSTPULLDOWN_MASK) #define USBPHY_DEBUG_ENHSTPULLDOWN_MASK (0x30U) #define USBPHY_DEBUG_ENHSTPULLDOWN_SHIFT (4U) #define USBPHY_DEBUG_ENHSTPULLDOWN(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_ENHSTPULLDOWN_SHIFT)) & USBPHY_DEBUG_ENHSTPULLDOWN_MASK) #define USBPHY_DEBUG_RSVD0_MASK (0xC0U) #define USBPHY_DEBUG_RSVD0_SHIFT (6U) #define USBPHY_DEBUG_RSVD0(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_RSVD0_SHIFT)) & USBPHY_DEBUG_RSVD0_MASK) #define USBPHY_DEBUG_TX2RXCOUNT_MASK (0xF00U) #define USBPHY_DEBUG_TX2RXCOUNT_SHIFT (8U) #define USBPHY_DEBUG_TX2RXCOUNT(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_TX2RXCOUNT_SHIFT)) & USBPHY_DEBUG_TX2RXCOUNT_MASK) #define USBPHY_DEBUG_ENTX2RXCOUNT_MASK (0x1000U) #define USBPHY_DEBUG_ENTX2RXCOUNT_SHIFT (12U) #define USBPHY_DEBUG_ENTX2RXCOUNT(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_ENTX2RXCOUNT_SHIFT)) & USBPHY_DEBUG_ENTX2RXCOUNT_MASK) #define USBPHY_DEBUG_RSVD1_MASK (0xE000U) #define USBPHY_DEBUG_RSVD1_SHIFT (13U) #define USBPHY_DEBUG_RSVD1(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_RSVD1_SHIFT)) & USBPHY_DEBUG_RSVD1_MASK) #define USBPHY_DEBUG_SQUELCHRESETCOUNT_MASK (0x1F0000U) #define USBPHY_DEBUG_SQUELCHRESETCOUNT_SHIFT (16U) #define USBPHY_DEBUG_SQUELCHRESETCOUNT(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_SQUELCHRESETCOUNT_SHIFT)) & USBPHY_DEBUG_SQUELCHRESETCOUNT_MASK) #define USBPHY_DEBUG_RSVD2_MASK (0xE00000U) #define USBPHY_DEBUG_RSVD2_SHIFT (21U) #define USBPHY_DEBUG_RSVD2(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_RSVD2_SHIFT)) & USBPHY_DEBUG_RSVD2_MASK) #define USBPHY_DEBUG_ENSQUELCHRESET_MASK (0x1000000U) #define USBPHY_DEBUG_ENSQUELCHRESET_SHIFT (24U) #define USBPHY_DEBUG_ENSQUELCHRESET(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_ENSQUELCHRESET_SHIFT)) & USBPHY_DEBUG_ENSQUELCHRESET_MASK) #define USBPHY_DEBUG_SQUELCHRESETLENGTH_MASK (0x1E000000U) #define USBPHY_DEBUG_SQUELCHRESETLENGTH_SHIFT (25U) #define USBPHY_DEBUG_SQUELCHRESETLENGTH(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_SQUELCHRESETLENGTH_SHIFT)) & USBPHY_DEBUG_SQUELCHRESETLENGTH_MASK) #define USBPHY_DEBUG_HOST_RESUME_DEBUG_MASK (0x20000000U) #define USBPHY_DEBUG_HOST_RESUME_DEBUG_SHIFT (29U) #define USBPHY_DEBUG_HOST_RESUME_DEBUG(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_HOST_RESUME_DEBUG_SHIFT)) & USBPHY_DEBUG_HOST_RESUME_DEBUG_MASK) #define USBPHY_DEBUG_CLKGATE_MASK (0x40000000U) #define USBPHY_DEBUG_CLKGATE_SHIFT (30U) #define USBPHY_DEBUG_CLKGATE(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_CLKGATE_SHIFT)) & USBPHY_DEBUG_CLKGATE_MASK) #define USBPHY_DEBUG_RSVD3_MASK (0x80000000U) #define USBPHY_DEBUG_RSVD3_SHIFT (31U) #define USBPHY_DEBUG_RSVD3(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_RSVD3_SHIFT)) & USBPHY_DEBUG_RSVD3_MASK) /*! @} */ /*! @name DEBUG_SET - USB PHY Debug Register */ /*! @{ */ #define USBPHY_DEBUG_SET_OTGIDPIOLOCK_MASK (0x1U) #define USBPHY_DEBUG_SET_OTGIDPIOLOCK_SHIFT (0U) #define USBPHY_DEBUG_SET_OTGIDPIOLOCK(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_SET_OTGIDPIOLOCK_SHIFT)) & USBPHY_DEBUG_SET_OTGIDPIOLOCK_MASK) #define USBPHY_DEBUG_SET_DEBUG_INTERFACE_HOLD_MASK (0x2U) #define USBPHY_DEBUG_SET_DEBUG_INTERFACE_HOLD_SHIFT (1U) #define USBPHY_DEBUG_SET_DEBUG_INTERFACE_HOLD(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_SET_DEBUG_INTERFACE_HOLD_SHIFT)) & USBPHY_DEBUG_SET_DEBUG_INTERFACE_HOLD_MASK) #define USBPHY_DEBUG_SET_HSTPULLDOWN_MASK (0xCU) #define USBPHY_DEBUG_SET_HSTPULLDOWN_SHIFT (2U) #define USBPHY_DEBUG_SET_HSTPULLDOWN(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_SET_HSTPULLDOWN_SHIFT)) & USBPHY_DEBUG_SET_HSTPULLDOWN_MASK) #define USBPHY_DEBUG_SET_ENHSTPULLDOWN_MASK (0x30U) #define USBPHY_DEBUG_SET_ENHSTPULLDOWN_SHIFT (4U) #define USBPHY_DEBUG_SET_ENHSTPULLDOWN(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_SET_ENHSTPULLDOWN_SHIFT)) & USBPHY_DEBUG_SET_ENHSTPULLDOWN_MASK) #define USBPHY_DEBUG_SET_RSVD0_MASK (0xC0U) #define USBPHY_DEBUG_SET_RSVD0_SHIFT (6U) #define USBPHY_DEBUG_SET_RSVD0(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_SET_RSVD0_SHIFT)) & USBPHY_DEBUG_SET_RSVD0_MASK) #define USBPHY_DEBUG_SET_TX2RXCOUNT_MASK (0xF00U) #define USBPHY_DEBUG_SET_TX2RXCOUNT_SHIFT (8U) #define USBPHY_DEBUG_SET_TX2RXCOUNT(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_SET_TX2RXCOUNT_SHIFT)) & USBPHY_DEBUG_SET_TX2RXCOUNT_MASK) #define USBPHY_DEBUG_SET_ENTX2RXCOUNT_MASK (0x1000U) #define USBPHY_DEBUG_SET_ENTX2RXCOUNT_SHIFT (12U) #define USBPHY_DEBUG_SET_ENTX2RXCOUNT(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_SET_ENTX2RXCOUNT_SHIFT)) & USBPHY_DEBUG_SET_ENTX2RXCOUNT_MASK) #define USBPHY_DEBUG_SET_RSVD1_MASK (0xE000U) #define USBPHY_DEBUG_SET_RSVD1_SHIFT (13U) #define USBPHY_DEBUG_SET_RSVD1(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_SET_RSVD1_SHIFT)) & USBPHY_DEBUG_SET_RSVD1_MASK) #define USBPHY_DEBUG_SET_SQUELCHRESETCOUNT_MASK (0x1F0000U) #define USBPHY_DEBUG_SET_SQUELCHRESETCOUNT_SHIFT (16U) #define USBPHY_DEBUG_SET_SQUELCHRESETCOUNT(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_SET_SQUELCHRESETCOUNT_SHIFT)) & USBPHY_DEBUG_SET_SQUELCHRESETCOUNT_MASK) #define USBPHY_DEBUG_SET_RSVD2_MASK (0xE00000U) #define USBPHY_DEBUG_SET_RSVD2_SHIFT (21U) #define USBPHY_DEBUG_SET_RSVD2(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_SET_RSVD2_SHIFT)) & USBPHY_DEBUG_SET_RSVD2_MASK) #define USBPHY_DEBUG_SET_ENSQUELCHRESET_MASK (0x1000000U) #define USBPHY_DEBUG_SET_ENSQUELCHRESET_SHIFT (24U) #define USBPHY_DEBUG_SET_ENSQUELCHRESET(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_SET_ENSQUELCHRESET_SHIFT)) & USBPHY_DEBUG_SET_ENSQUELCHRESET_MASK) #define USBPHY_DEBUG_SET_SQUELCHRESETLENGTH_MASK (0x1E000000U) #define USBPHY_DEBUG_SET_SQUELCHRESETLENGTH_SHIFT (25U) #define USBPHY_DEBUG_SET_SQUELCHRESETLENGTH(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_SET_SQUELCHRESETLENGTH_SHIFT)) & USBPHY_DEBUG_SET_SQUELCHRESETLENGTH_MASK) #define USBPHY_DEBUG_SET_HOST_RESUME_DEBUG_MASK (0x20000000U) #define USBPHY_DEBUG_SET_HOST_RESUME_DEBUG_SHIFT (29U) #define USBPHY_DEBUG_SET_HOST_RESUME_DEBUG(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_SET_HOST_RESUME_DEBUG_SHIFT)) & USBPHY_DEBUG_SET_HOST_RESUME_DEBUG_MASK) #define USBPHY_DEBUG_SET_CLKGATE_MASK (0x40000000U) #define USBPHY_DEBUG_SET_CLKGATE_SHIFT (30U) #define USBPHY_DEBUG_SET_CLKGATE(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_SET_CLKGATE_SHIFT)) & USBPHY_DEBUG_SET_CLKGATE_MASK) #define USBPHY_DEBUG_SET_RSVD3_MASK (0x80000000U) #define USBPHY_DEBUG_SET_RSVD3_SHIFT (31U) #define USBPHY_DEBUG_SET_RSVD3(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_SET_RSVD3_SHIFT)) & USBPHY_DEBUG_SET_RSVD3_MASK) /*! @} */ /*! @name DEBUG_CLR - USB PHY Debug Register */ /*! @{ */ #define USBPHY_DEBUG_CLR_OTGIDPIOLOCK_MASK (0x1U) #define USBPHY_DEBUG_CLR_OTGIDPIOLOCK_SHIFT (0U) #define USBPHY_DEBUG_CLR_OTGIDPIOLOCK(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_CLR_OTGIDPIOLOCK_SHIFT)) & USBPHY_DEBUG_CLR_OTGIDPIOLOCK_MASK) #define USBPHY_DEBUG_CLR_DEBUG_INTERFACE_HOLD_MASK (0x2U) #define USBPHY_DEBUG_CLR_DEBUG_INTERFACE_HOLD_SHIFT (1U) #define USBPHY_DEBUG_CLR_DEBUG_INTERFACE_HOLD(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_CLR_DEBUG_INTERFACE_HOLD_SHIFT)) & USBPHY_DEBUG_CLR_DEBUG_INTERFACE_HOLD_MASK) #define USBPHY_DEBUG_CLR_HSTPULLDOWN_MASK (0xCU) #define USBPHY_DEBUG_CLR_HSTPULLDOWN_SHIFT (2U) #define USBPHY_DEBUG_CLR_HSTPULLDOWN(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_CLR_HSTPULLDOWN_SHIFT)) & USBPHY_DEBUG_CLR_HSTPULLDOWN_MASK) #define USBPHY_DEBUG_CLR_ENHSTPULLDOWN_MASK (0x30U) #define USBPHY_DEBUG_CLR_ENHSTPULLDOWN_SHIFT (4U) #define USBPHY_DEBUG_CLR_ENHSTPULLDOWN(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_CLR_ENHSTPULLDOWN_SHIFT)) & USBPHY_DEBUG_CLR_ENHSTPULLDOWN_MASK) #define USBPHY_DEBUG_CLR_RSVD0_MASK (0xC0U) #define USBPHY_DEBUG_CLR_RSVD0_SHIFT (6U) #define USBPHY_DEBUG_CLR_RSVD0(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_CLR_RSVD0_SHIFT)) & USBPHY_DEBUG_CLR_RSVD0_MASK) #define USBPHY_DEBUG_CLR_TX2RXCOUNT_MASK (0xF00U) #define USBPHY_DEBUG_CLR_TX2RXCOUNT_SHIFT (8U) #define USBPHY_DEBUG_CLR_TX2RXCOUNT(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_CLR_TX2RXCOUNT_SHIFT)) & USBPHY_DEBUG_CLR_TX2RXCOUNT_MASK) #define USBPHY_DEBUG_CLR_ENTX2RXCOUNT_MASK (0x1000U) #define USBPHY_DEBUG_CLR_ENTX2RXCOUNT_SHIFT (12U) #define USBPHY_DEBUG_CLR_ENTX2RXCOUNT(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_CLR_ENTX2RXCOUNT_SHIFT)) & USBPHY_DEBUG_CLR_ENTX2RXCOUNT_MASK) #define USBPHY_DEBUG_CLR_RSVD1_MASK (0xE000U) #define USBPHY_DEBUG_CLR_RSVD1_SHIFT (13U) #define USBPHY_DEBUG_CLR_RSVD1(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_CLR_RSVD1_SHIFT)) & USBPHY_DEBUG_CLR_RSVD1_MASK) #define USBPHY_DEBUG_CLR_SQUELCHRESETCOUNT_MASK (0x1F0000U) #define USBPHY_DEBUG_CLR_SQUELCHRESETCOUNT_SHIFT (16U) #define USBPHY_DEBUG_CLR_SQUELCHRESETCOUNT(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_CLR_SQUELCHRESETCOUNT_SHIFT)) & USBPHY_DEBUG_CLR_SQUELCHRESETCOUNT_MASK) #define USBPHY_DEBUG_CLR_RSVD2_MASK (0xE00000U) #define USBPHY_DEBUG_CLR_RSVD2_SHIFT (21U) #define USBPHY_DEBUG_CLR_RSVD2(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_CLR_RSVD2_SHIFT)) & USBPHY_DEBUG_CLR_RSVD2_MASK) #define USBPHY_DEBUG_CLR_ENSQUELCHRESET_MASK (0x1000000U) #define USBPHY_DEBUG_CLR_ENSQUELCHRESET_SHIFT (24U) #define USBPHY_DEBUG_CLR_ENSQUELCHRESET(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_CLR_ENSQUELCHRESET_SHIFT)) & USBPHY_DEBUG_CLR_ENSQUELCHRESET_MASK) #define USBPHY_DEBUG_CLR_SQUELCHRESETLENGTH_MASK (0x1E000000U) #define USBPHY_DEBUG_CLR_SQUELCHRESETLENGTH_SHIFT (25U) #define USBPHY_DEBUG_CLR_SQUELCHRESETLENGTH(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_CLR_SQUELCHRESETLENGTH_SHIFT)) & USBPHY_DEBUG_CLR_SQUELCHRESETLENGTH_MASK) #define USBPHY_DEBUG_CLR_HOST_RESUME_DEBUG_MASK (0x20000000U) #define USBPHY_DEBUG_CLR_HOST_RESUME_DEBUG_SHIFT (29U) #define USBPHY_DEBUG_CLR_HOST_RESUME_DEBUG(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_CLR_HOST_RESUME_DEBUG_SHIFT)) & USBPHY_DEBUG_CLR_HOST_RESUME_DEBUG_MASK) #define USBPHY_DEBUG_CLR_CLKGATE_MASK (0x40000000U) #define USBPHY_DEBUG_CLR_CLKGATE_SHIFT (30U) #define USBPHY_DEBUG_CLR_CLKGATE(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_CLR_CLKGATE_SHIFT)) & USBPHY_DEBUG_CLR_CLKGATE_MASK) #define USBPHY_DEBUG_CLR_RSVD3_MASK (0x80000000U) #define USBPHY_DEBUG_CLR_RSVD3_SHIFT (31U) #define USBPHY_DEBUG_CLR_RSVD3(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_CLR_RSVD3_SHIFT)) & USBPHY_DEBUG_CLR_RSVD3_MASK) /*! @} */ /*! @name DEBUG_TOG - USB PHY Debug Register */ /*! @{ */ #define USBPHY_DEBUG_TOG_OTGIDPIOLOCK_MASK (0x1U) #define USBPHY_DEBUG_TOG_OTGIDPIOLOCK_SHIFT (0U) #define USBPHY_DEBUG_TOG_OTGIDPIOLOCK(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_TOG_OTGIDPIOLOCK_SHIFT)) & USBPHY_DEBUG_TOG_OTGIDPIOLOCK_MASK) #define USBPHY_DEBUG_TOG_DEBUG_INTERFACE_HOLD_MASK (0x2U) #define USBPHY_DEBUG_TOG_DEBUG_INTERFACE_HOLD_SHIFT (1U) #define USBPHY_DEBUG_TOG_DEBUG_INTERFACE_HOLD(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_TOG_DEBUG_INTERFACE_HOLD_SHIFT)) & USBPHY_DEBUG_TOG_DEBUG_INTERFACE_HOLD_MASK) #define USBPHY_DEBUG_TOG_HSTPULLDOWN_MASK (0xCU) #define USBPHY_DEBUG_TOG_HSTPULLDOWN_SHIFT (2U) #define USBPHY_DEBUG_TOG_HSTPULLDOWN(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_TOG_HSTPULLDOWN_SHIFT)) & USBPHY_DEBUG_TOG_HSTPULLDOWN_MASK) #define USBPHY_DEBUG_TOG_ENHSTPULLDOWN_MASK (0x30U) #define USBPHY_DEBUG_TOG_ENHSTPULLDOWN_SHIFT (4U) #define USBPHY_DEBUG_TOG_ENHSTPULLDOWN(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_TOG_ENHSTPULLDOWN_SHIFT)) & USBPHY_DEBUG_TOG_ENHSTPULLDOWN_MASK) #define USBPHY_DEBUG_TOG_RSVD0_MASK (0xC0U) #define USBPHY_DEBUG_TOG_RSVD0_SHIFT (6U) #define USBPHY_DEBUG_TOG_RSVD0(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_TOG_RSVD0_SHIFT)) & USBPHY_DEBUG_TOG_RSVD0_MASK) #define USBPHY_DEBUG_TOG_TX2RXCOUNT_MASK (0xF00U) #define USBPHY_DEBUG_TOG_TX2RXCOUNT_SHIFT (8U) #define USBPHY_DEBUG_TOG_TX2RXCOUNT(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_TOG_TX2RXCOUNT_SHIFT)) & USBPHY_DEBUG_TOG_TX2RXCOUNT_MASK) #define USBPHY_DEBUG_TOG_ENTX2RXCOUNT_MASK (0x1000U) #define USBPHY_DEBUG_TOG_ENTX2RXCOUNT_SHIFT (12U) #define USBPHY_DEBUG_TOG_ENTX2RXCOUNT(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_TOG_ENTX2RXCOUNT_SHIFT)) & USBPHY_DEBUG_TOG_ENTX2RXCOUNT_MASK) #define USBPHY_DEBUG_TOG_RSVD1_MASK (0xE000U) #define USBPHY_DEBUG_TOG_RSVD1_SHIFT (13U) #define USBPHY_DEBUG_TOG_RSVD1(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_TOG_RSVD1_SHIFT)) & USBPHY_DEBUG_TOG_RSVD1_MASK) #define USBPHY_DEBUG_TOG_SQUELCHRESETCOUNT_MASK (0x1F0000U) #define USBPHY_DEBUG_TOG_SQUELCHRESETCOUNT_SHIFT (16U) #define USBPHY_DEBUG_TOG_SQUELCHRESETCOUNT(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_TOG_SQUELCHRESETCOUNT_SHIFT)) & USBPHY_DEBUG_TOG_SQUELCHRESETCOUNT_MASK) #define USBPHY_DEBUG_TOG_RSVD2_MASK (0xE00000U) #define USBPHY_DEBUG_TOG_RSVD2_SHIFT (21U) #define USBPHY_DEBUG_TOG_RSVD2(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_TOG_RSVD2_SHIFT)) & USBPHY_DEBUG_TOG_RSVD2_MASK) #define USBPHY_DEBUG_TOG_ENSQUELCHRESET_MASK (0x1000000U) #define USBPHY_DEBUG_TOG_ENSQUELCHRESET_SHIFT (24U) #define USBPHY_DEBUG_TOG_ENSQUELCHRESET(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_TOG_ENSQUELCHRESET_SHIFT)) & USBPHY_DEBUG_TOG_ENSQUELCHRESET_MASK) #define USBPHY_DEBUG_TOG_SQUELCHRESETLENGTH_MASK (0x1E000000U) #define USBPHY_DEBUG_TOG_SQUELCHRESETLENGTH_SHIFT (25U) #define USBPHY_DEBUG_TOG_SQUELCHRESETLENGTH(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_TOG_SQUELCHRESETLENGTH_SHIFT)) & USBPHY_DEBUG_TOG_SQUELCHRESETLENGTH_MASK) #define USBPHY_DEBUG_TOG_HOST_RESUME_DEBUG_MASK (0x20000000U) #define USBPHY_DEBUG_TOG_HOST_RESUME_DEBUG_SHIFT (29U) #define USBPHY_DEBUG_TOG_HOST_RESUME_DEBUG(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_TOG_HOST_RESUME_DEBUG_SHIFT)) & USBPHY_DEBUG_TOG_HOST_RESUME_DEBUG_MASK) #define USBPHY_DEBUG_TOG_CLKGATE_MASK (0x40000000U) #define USBPHY_DEBUG_TOG_CLKGATE_SHIFT (30U) #define USBPHY_DEBUG_TOG_CLKGATE(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_TOG_CLKGATE_SHIFT)) & USBPHY_DEBUG_TOG_CLKGATE_MASK) #define USBPHY_DEBUG_TOG_RSVD3_MASK (0x80000000U) #define USBPHY_DEBUG_TOG_RSVD3_SHIFT (31U) #define USBPHY_DEBUG_TOG_RSVD3(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG_TOG_RSVD3_SHIFT)) & USBPHY_DEBUG_TOG_RSVD3_MASK) /*! @} */ /*! @name DEBUG0_STATUS - UTMI Debug Status Register 0 */ /*! @{ */ #define USBPHY_DEBUG0_STATUS_LOOP_BACK_FAIL_COUNT_MASK (0xFFFFU) #define USBPHY_DEBUG0_STATUS_LOOP_BACK_FAIL_COUNT_SHIFT (0U) #define USBPHY_DEBUG0_STATUS_LOOP_BACK_FAIL_COUNT(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG0_STATUS_LOOP_BACK_FAIL_COUNT_SHIFT)) & USBPHY_DEBUG0_STATUS_LOOP_BACK_FAIL_COUNT_MASK) #define USBPHY_DEBUG0_STATUS_UTMI_RXERROR_FAIL_COUNT_MASK (0x3FF0000U) #define USBPHY_DEBUG0_STATUS_UTMI_RXERROR_FAIL_COUNT_SHIFT (16U) #define USBPHY_DEBUG0_STATUS_UTMI_RXERROR_FAIL_COUNT(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG0_STATUS_UTMI_RXERROR_FAIL_COUNT_SHIFT)) & USBPHY_DEBUG0_STATUS_UTMI_RXERROR_FAIL_COUNT_MASK) #define USBPHY_DEBUG0_STATUS_SQUELCH_COUNT_MASK (0xFC000000U) #define USBPHY_DEBUG0_STATUS_SQUELCH_COUNT_SHIFT (26U) #define USBPHY_DEBUG0_STATUS_SQUELCH_COUNT(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG0_STATUS_SQUELCH_COUNT_SHIFT)) & USBPHY_DEBUG0_STATUS_SQUELCH_COUNT_MASK) /*! @} */ /*! @name DEBUG1 - UTMI Debug Status Register 1 */ /*! @{ */ #define USBPHY_DEBUG1_RSVD0_MASK (0x1FFFU) #define USBPHY_DEBUG1_RSVD0_SHIFT (0U) #define USBPHY_DEBUG1_RSVD0(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG1_RSVD0_SHIFT)) & USBPHY_DEBUG1_RSVD0_MASK) #define USBPHY_DEBUG1_ENTAILADJVD_MASK (0x6000U) #define USBPHY_DEBUG1_ENTAILADJVD_SHIFT (13U) #define USBPHY_DEBUG1_ENTAILADJVD(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG1_ENTAILADJVD_SHIFT)) & USBPHY_DEBUG1_ENTAILADJVD_MASK) #define USBPHY_DEBUG1_RSVD1_MASK (0xFFFF8000U) #define USBPHY_DEBUG1_RSVD1_SHIFT (15U) #define USBPHY_DEBUG1_RSVD1(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG1_RSVD1_SHIFT)) & USBPHY_DEBUG1_RSVD1_MASK) /*! @} */ /*! @name DEBUG1_SET - UTMI Debug Status Register 1 */ /*! @{ */ #define USBPHY_DEBUG1_SET_RSVD0_MASK (0x1FFFU) #define USBPHY_DEBUG1_SET_RSVD0_SHIFT (0U) #define USBPHY_DEBUG1_SET_RSVD0(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG1_SET_RSVD0_SHIFT)) & USBPHY_DEBUG1_SET_RSVD0_MASK) #define USBPHY_DEBUG1_SET_ENTAILADJVD_MASK (0x6000U) #define USBPHY_DEBUG1_SET_ENTAILADJVD_SHIFT (13U) #define USBPHY_DEBUG1_SET_ENTAILADJVD(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG1_SET_ENTAILADJVD_SHIFT)) & USBPHY_DEBUG1_SET_ENTAILADJVD_MASK) #define USBPHY_DEBUG1_SET_RSVD1_MASK (0xFFFF8000U) #define USBPHY_DEBUG1_SET_RSVD1_SHIFT (15U) #define USBPHY_DEBUG1_SET_RSVD1(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG1_SET_RSVD1_SHIFT)) & USBPHY_DEBUG1_SET_RSVD1_MASK) /*! @} */ /*! @name DEBUG1_CLR - UTMI Debug Status Register 1 */ /*! @{ */ #define USBPHY_DEBUG1_CLR_RSVD0_MASK (0x1FFFU) #define USBPHY_DEBUG1_CLR_RSVD0_SHIFT (0U) #define USBPHY_DEBUG1_CLR_RSVD0(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG1_CLR_RSVD0_SHIFT)) & USBPHY_DEBUG1_CLR_RSVD0_MASK) #define USBPHY_DEBUG1_CLR_ENTAILADJVD_MASK (0x6000U) #define USBPHY_DEBUG1_CLR_ENTAILADJVD_SHIFT (13U) #define USBPHY_DEBUG1_CLR_ENTAILADJVD(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG1_CLR_ENTAILADJVD_SHIFT)) & USBPHY_DEBUG1_CLR_ENTAILADJVD_MASK) #define USBPHY_DEBUG1_CLR_RSVD1_MASK (0xFFFF8000U) #define USBPHY_DEBUG1_CLR_RSVD1_SHIFT (15U) #define USBPHY_DEBUG1_CLR_RSVD1(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG1_CLR_RSVD1_SHIFT)) & USBPHY_DEBUG1_CLR_RSVD1_MASK) /*! @} */ /*! @name DEBUG1_TOG - UTMI Debug Status Register 1 */ /*! @{ */ #define USBPHY_DEBUG1_TOG_RSVD0_MASK (0x1FFFU) #define USBPHY_DEBUG1_TOG_RSVD0_SHIFT (0U) #define USBPHY_DEBUG1_TOG_RSVD0(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG1_TOG_RSVD0_SHIFT)) & USBPHY_DEBUG1_TOG_RSVD0_MASK) #define USBPHY_DEBUG1_TOG_ENTAILADJVD_MASK (0x6000U) #define USBPHY_DEBUG1_TOG_ENTAILADJVD_SHIFT (13U) #define USBPHY_DEBUG1_TOG_ENTAILADJVD(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG1_TOG_ENTAILADJVD_SHIFT)) & USBPHY_DEBUG1_TOG_ENTAILADJVD_MASK) #define USBPHY_DEBUG1_TOG_RSVD1_MASK (0xFFFF8000U) #define USBPHY_DEBUG1_TOG_RSVD1_SHIFT (15U) #define USBPHY_DEBUG1_TOG_RSVD1(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_DEBUG1_TOG_RSVD1_SHIFT)) & USBPHY_DEBUG1_TOG_RSVD1_MASK) /*! @} */ /*! @name VERSION - UTMI RTL Version */ /*! @{ */ #define USBPHY_VERSION_STEP_MASK (0xFFFFU) #define USBPHY_VERSION_STEP_SHIFT (0U) #define USBPHY_VERSION_STEP(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_VERSION_STEP_SHIFT)) & USBPHY_VERSION_STEP_MASK) #define USBPHY_VERSION_MINOR_MASK (0xFF0000U) #define USBPHY_VERSION_MINOR_SHIFT (16U) #define USBPHY_VERSION_MINOR(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_VERSION_MINOR_SHIFT)) & USBPHY_VERSION_MINOR_MASK) #define USBPHY_VERSION_MAJOR_MASK (0xFF000000U) #define USBPHY_VERSION_MAJOR_SHIFT (24U) #define USBPHY_VERSION_MAJOR(x) (((uint32_t)(((uint32_t)(x)) << USBPHY_VERSION_MAJOR_SHIFT)) & USBPHY_VERSION_MAJOR_MASK) /* Backward compatibility */ #define USBPHY_CTRL_ENDEVPLUGINDET_MASK USBPHY_CTRL_ENDEVPLUGINDETECT_MASK #define USBPHY_CTRL_ENDEVPLUGINDET_SHIFT USBPHY_CTRL_ENDEVPLUGINDETECT_SHIFT #define USBPHY_CTRL_ENDEVPLUGINDET(x) USBPHY_CTRL_ENDEVPLUGINDETECT(x) #define USBPHY_TX_TXCAL45DM_MASK USBPHY_TX_TXCAL45DN_MASK #define USBPHY_TX_TXCAL45DM(x) USBPHY_TX_TXCAL45DN(x) /*! @} */ /* ---------------------------------------------------------------------------- -- USB_ANALOG Peripheral Access Layer ---------------------------------------------------------------------------- */ /*! * @addtogroup USB_ANALOG_Peripheral_Access_Layer USB_ANALOG Peripheral Access Layer * @{ */ /** USB_ANALOG - Register Layout Typedef */ typedef struct { uint8_t RESERVED_0[416]; struct { /* offset: 0x1A0, array step: 0x60 */ volatile uint32_t VBUS_DETECT; /**< USB VBUS Detect Register, array offset: 0x1A0, array step: 0x60 */ volatile uint32_t VBUS_DETECT_SET; /**< USB VBUS Detect Register, array offset: 0x1A4, array step: 0x60 */ volatile uint32_t VBUS_DETECT_CLR; /**< USB VBUS Detect Register, array offset: 0x1A8, array step: 0x60 */ volatile uint32_t VBUS_DETECT_TOG; /**< USB VBUS Detect Register, array offset: 0x1AC, array step: 0x60 */ volatile uint32_t CHRG_DETECT; /**< USB Charger Detect Register, array offset: 0x1B0, array step: 0x60 */ volatile uint32_t CHRG_DETECT_SET; /**< USB Charger Detect Register, array offset: 0x1B4, array step: 0x60 */ volatile uint32_t CHRG_DETECT_CLR; /**< USB Charger Detect Register, array offset: 0x1B8, array step: 0x60 */ volatile uint32_t CHRG_DETECT_TOG; /**< USB Charger Detect Register, array offset: 0x1BC, array step: 0x60 */ volatile const uint32_t VBUS_DETECT_STAT; /**< USB VBUS Detect Status Register, array offset: 0x1C0, array step: 0x60 */ uint8_t RESERVED_0[12]; volatile const uint32_t CHRG_DETECT_STAT; /**< USB Charger Detect Status Register, array offset: 0x1D0, array step: 0x60 */ uint8_t RESERVED_1[12]; volatile uint32_t LOOPBACK; /**< USB Loopback Test Register, array offset: 0x1E0, array step: 0x60 */ volatile uint32_t LOOPBACK_SET; /**< USB Loopback Test Register, array offset: 0x1E4, array step: 0x60 */ volatile uint32_t LOOPBACK_CLR; /**< USB Loopback Test Register, array offset: 0x1E8, array step: 0x60 */ volatile uint32_t LOOPBACK_TOG; /**< USB Loopback Test Register, array offset: 0x1EC, array step: 0x60 */ volatile uint32_t MISC; /**< USB Misc Register, array offset: 0x1F0, array step: 0x60 */ volatile uint32_t MISC_SET; /**< USB Misc Register, array offset: 0x1F4, array step: 0x60 */ volatile uint32_t MISC_CLR; /**< USB Misc Register, array offset: 0x1F8, array step: 0x60 */ volatile uint32_t MISC_TOG; /**< USB Misc Register, array offset: 0x1FC, array step: 0x60 */ } INSTANCE[1]; uint8_t RESERVED_1[96]; volatile const uint32_t DIGPROG; /**< Chip Silicon Version, offset: 0x260 */ } imxrt1020_usb_analog; /* USB_ANALOG - Peripheral instance base addresses */ /** Peripheral USB_ANALOG base address */ #define IMXRT1020_USB_ANALOG_BASE (0x400D8000u) /** Peripheral IMXRT1020_USB_ANALOG base pointer */ #define IMXRT1020_USB_ANALOG ((imxrt1020_usb_analog *)IMXRT1020_USB_ANALOG_BASE) /** Array initializer of IMXRT1020_USB_ANALOG peripheral base addresses */ #define IMXRT1020_USB_ANALOG_BASE_ADDRS { IMXRT1020_USB_ANALOG_BASE } /** Array initializer of IMXRT1020_USB_ANALOG peripheral base pointers */ #define IMXRT1020_USB_ANALOG_BASE_PTRS { IMXRT1020_USB_ANALOG } /* ---------------------------------------------------------------------------- -- USB_ANALOG Register Masks ---------------------------------------------------------------------------- */ /*! * @addtogroup USB_ANALOG_Register_Masks USB_ANALOG Register Masks * @{ */ /*! @name VBUS_DETECT - USB VBUS Detect Register */ /*! @{ */ #define USB_ANALOG_VBUS_DETECT_VBUSVALID_THRESH_MASK (0x7U) #define USB_ANALOG_VBUS_DETECT_VBUSVALID_THRESH_SHIFT (0U) /*! VBUSVALID_THRESH * 0b000..4.0V * 0b001..4.1V * 0b010..4.2V * 0b011..4.3V * 0b100..4.4V (default) * 0b101..4.5V * 0b110..4.6V * 0b111..4.7V */ #define USB_ANALOG_VBUS_DETECT_VBUSVALID_THRESH(x) (((uint32_t)(((uint32_t)(x)) << USB_ANALOG_VBUS_DETECT_VBUSVALID_THRESH_SHIFT)) & USB_ANALOG_VBUS_DETECT_VBUSVALID_THRESH_MASK) #define USB_ANALOG_VBUS_DETECT_VBUSVALID_PWRUP_CMPS_MASK (0x100000U) #define USB_ANALOG_VBUS_DETECT_VBUSVALID_PWRUP_CMPS_SHIFT (20U) #define USB_ANALOG_VBUS_DETECT_VBUSVALID_PWRUP_CMPS(x) (((uint32_t)(((uint32_t)(x)) << USB_ANALOG_VBUS_DETECT_VBUSVALID_PWRUP_CMPS_SHIFT)) & USB_ANALOG_VBUS_DETECT_VBUSVALID_PWRUP_CMPS_MASK) #define USB_ANALOG_VBUS_DETECT_DISCHARGE_VBUS_MASK (0x4000000U) #define USB_ANALOG_VBUS_DETECT_DISCHARGE_VBUS_SHIFT (26U) #define USB_ANALOG_VBUS_DETECT_DISCHARGE_VBUS(x) (((uint32_t)(((uint32_t)(x)) << USB_ANALOG_VBUS_DETECT_DISCHARGE_VBUS_SHIFT)) & USB_ANALOG_VBUS_DETECT_DISCHARGE_VBUS_MASK) #define USB_ANALOG_VBUS_DETECT_CHARGE_VBUS_MASK (0x8000000U) #define USB_ANALOG_VBUS_DETECT_CHARGE_VBUS_SHIFT (27U) #define USB_ANALOG_VBUS_DETECT_CHARGE_VBUS(x) (((uint32_t)(((uint32_t)(x)) << USB_ANALOG_VBUS_DETECT_CHARGE_VBUS_SHIFT)) & USB_ANALOG_VBUS_DETECT_CHARGE_VBUS_MASK) /*! @} */ /* The count of USB_ANALOG_VBUS_DETECT */ #define USB_ANALOG_VBUS_DETECT_COUNT (1U) /*! @name VBUS_DETECT_SET - USB VBUS Detect Register */ /*! @{ */ #define USB_ANALOG_VBUS_DETECT_SET_VBUSVALID_THRESH_MASK (0x7U) #define USB_ANALOG_VBUS_DETECT_SET_VBUSVALID_THRESH_SHIFT (0U) /*! VBUSVALID_THRESH * 0b000..4.0V * 0b001..4.1V * 0b010..4.2V * 0b011..4.3V * 0b100..4.4V (default) * 0b101..4.5V * 0b110..4.6V * 0b111..4.7V */ #define USB_ANALOG_VBUS_DETECT_SET_VBUSVALID_THRESH(x) (((uint32_t)(((uint32_t)(x)) << USB_ANALOG_VBUS_DETECT_SET_VBUSVALID_THRESH_SHIFT)) & USB_ANALOG_VBUS_DETECT_SET_VBUSVALID_THRESH_MASK) #define USB_ANALOG_VBUS_DETECT_SET_VBUSVALID_PWRUP_CMPS_MASK (0x100000U) #define USB_ANALOG_VBUS_DETECT_SET_VBUSVALID_PWRUP_CMPS_SHIFT (20U) #define USB_ANALOG_VBUS_DETECT_SET_VBUSVALID_PWRUP_CMPS(x) (((uint32_t)(((uint32_t)(x)) << USB_ANALOG_VBUS_DETECT_SET_VBUSVALID_PWRUP_CMPS_SHIFT)) & USB_ANALOG_VBUS_DETECT_SET_VBUSVALID_PWRUP_CMPS_MASK) #define USB_ANALOG_VBUS_DETECT_SET_DISCHARGE_VBUS_MASK (0x4000000U) #define USB_ANALOG_VBUS_DETECT_SET_DISCHARGE_VBUS_SHIFT (26U) #define USB_ANALOG_VBUS_DETECT_SET_DISCHARGE_VBUS(x) (((uint32_t)(((uint32_t)(x)) << USB_ANALOG_VBUS_DETECT_SET_DISCHARGE_VBUS_SHIFT)) & USB_ANALOG_VBUS_DETECT_SET_DISCHARGE_VBUS_MASK) #define USB_ANALOG_VBUS_DETECT_SET_CHARGE_VBUS_MASK (0x8000000U) #define USB_ANALOG_VBUS_DETECT_SET_CHARGE_VBUS_SHIFT (27U) #define USB_ANALOG_VBUS_DETECT_SET_CHARGE_VBUS(x) (((uint32_t)(((uint32_t)(x)) << USB_ANALOG_VBUS_DETECT_SET_CHARGE_VBUS_SHIFT)) & USB_ANALOG_VBUS_DETECT_SET_CHARGE_VBUS_MASK) /*! @} */ /* The count of USB_ANALOG_VBUS_DETECT_SET */ #define USB_ANALOG_VBUS_DETECT_SET_COUNT (1U) /*! @name VBUS_DETECT_CLR - USB VBUS Detect Register */ /*! @{ */ #define USB_ANALOG_VBUS_DETECT_CLR_VBUSVALID_THRESH_MASK (0x7U) #define USB_ANALOG_VBUS_DETECT_CLR_VBUSVALID_THRESH_SHIFT (0U) /*! VBUSVALID_THRESH * 0b000..4.0V * 0b001..4.1V * 0b010..4.2V * 0b011..4.3V * 0b100..4.4V (default) * 0b101..4.5V * 0b110..4.6V * 0b111..4.7V */ #define USB_ANALOG_VBUS_DETECT_CLR_VBUSVALID_THRESH(x) (((uint32_t)(((uint32_t)(x)) << USB_ANALOG_VBUS_DETECT_CLR_VBUSVALID_THRESH_SHIFT)) & USB_ANALOG_VBUS_DETECT_CLR_VBUSVALID_THRESH_MASK) #define USB_ANALOG_VBUS_DETECT_CLR_VBUSVALID_PWRUP_CMPS_MASK (0x100000U) #define USB_ANALOG_VBUS_DETECT_CLR_VBUSVALID_PWRUP_CMPS_SHIFT (20U) #define USB_ANALOG_VBUS_DETECT_CLR_VBUSVALID_PWRUP_CMPS(x) (((uint32_t)(((uint32_t)(x)) << USB_ANALOG_VBUS_DETECT_CLR_VBUSVALID_PWRUP_CMPS_SHIFT)) & USB_ANALOG_VBUS_DETECT_CLR_VBUSVALID_PWRUP_CMPS_MASK) #define USB_ANALOG_VBUS_DETECT_CLR_DISCHARGE_VBUS_MASK (0x4000000U) #define USB_ANALOG_VBUS_DETECT_CLR_DISCHARGE_VBUS_SHIFT (26U) #define USB_ANALOG_VBUS_DETECT_CLR_DISCHARGE_VBUS(x) (((uint32_t)(((uint32_t)(x)) << USB_ANALOG_VBUS_DETECT_CLR_DISCHARGE_VBUS_SHIFT)) & USB_ANALOG_VBUS_DETECT_CLR_DISCHARGE_VBUS_MASK) #define USB_ANALOG_VBUS_DETECT_CLR_CHARGE_VBUS_MASK (0x8000000U) #define USB_ANALOG_VBUS_DETECT_CLR_CHARGE_VBUS_SHIFT (27U) #define USB_ANALOG_VBUS_DETECT_CLR_CHARGE_VBUS(x) (((uint32_t)(((uint32_t)(x)) << USB_ANALOG_VBUS_DETECT_CLR_CHARGE_VBUS_SHIFT)) & USB_ANALOG_VBUS_DETECT_CLR_CHARGE_VBUS_MASK) /*! @} */ /* The count of USB_ANALOG_VBUS_DETECT_CLR */ #define USB_ANALOG_VBUS_DETECT_CLR_COUNT (1U) /*! @name VBUS_DETECT_TOG - USB VBUS Detect Register */ /*! @{ */ #define USB_ANALOG_VBUS_DETECT_TOG_VBUSVALID_THRESH_MASK (0x7U) #define USB_ANALOG_VBUS_DETECT_TOG_VBUSVALID_THRESH_SHIFT (0U) /*! VBUSVALID_THRESH * 0b000..4.0V * 0b001..4.1V * 0b010..4.2V * 0b011..4.3V * 0b100..4.4V (default) * 0b101..4.5V * 0b110..4.6V * 0b111..4.7V */ #define USB_ANALOG_VBUS_DETECT_TOG_VBUSVALID_THRESH(x) (((uint32_t)(((uint32_t)(x)) << USB_ANALOG_VBUS_DETECT_TOG_VBUSVALID_THRESH_SHIFT)) & USB_ANALOG_VBUS_DETECT_TOG_VBUSVALID_THRESH_MASK) #define USB_ANALOG_VBUS_DETECT_TOG_VBUSVALID_PWRUP_CMPS_MASK (0x100000U) #define USB_ANALOG_VBUS_DETECT_TOG_VBUSVALID_PWRUP_CMPS_SHIFT (20U) #define USB_ANALOG_VBUS_DETECT_TOG_VBUSVALID_PWRUP_CMPS(x) (((uint32_t)(((uint32_t)(x)) << USB_ANALOG_VBUS_DETECT_TOG_VBUSVALID_PWRUP_CMPS_SHIFT)) & USB_ANALOG_VBUS_DETECT_TOG_VBUSVALID_PWRUP_CMPS_MASK) #define USB_ANALOG_VBUS_DETECT_TOG_DISCHARGE_VBUS_MASK (0x4000000U) #define USB_ANALOG_VBUS_DETECT_TOG_DISCHARGE_VBUS_SHIFT (26U) #define USB_ANALOG_VBUS_DETECT_TOG_DISCHARGE_VBUS(x) (((uint32_t)(((uint32_t)(x)) << USB_ANALOG_VBUS_DETECT_TOG_DISCHARGE_VBUS_SHIFT)) & USB_ANALOG_VBUS_DETECT_TOG_DISCHARGE_VBUS_MASK) #define USB_ANALOG_VBUS_DETECT_TOG_CHARGE_VBUS_MASK (0x8000000U) #define USB_ANALOG_VBUS_DETECT_TOG_CHARGE_VBUS_SHIFT (27U) #define USB_ANALOG_VBUS_DETECT_TOG_CHARGE_VBUS(x) (((uint32_t)(((uint32_t)(x)) << USB_ANALOG_VBUS_DETECT_TOG_CHARGE_VBUS_SHIFT)) & USB_ANALOG_VBUS_DETECT_TOG_CHARGE_VBUS_MASK) /*! @} */ /* The count of USB_ANALOG_VBUS_DETECT_TOG */ #define USB_ANALOG_VBUS_DETECT_TOG_COUNT (1U) /*! @name CHRG_DETECT - USB Charger Detect Register */ /*! @{ */ #define USB_ANALOG_CHRG_DETECT_CHK_CONTACT_MASK (0x40000U) #define USB_ANALOG_CHRG_DETECT_CHK_CONTACT_SHIFT (18U) /*! CHK_CONTACT - Check the contact of USB plug * 0b0..Do not check the contact of USB plug. * 0b1..Check whether the USB plug has been in contact with each other */ #define USB_ANALOG_CHRG_DETECT_CHK_CONTACT(x) (((uint32_t)(((uint32_t)(x)) << USB_ANALOG_CHRG_DETECT_CHK_CONTACT_SHIFT)) & USB_ANALOG_CHRG_DETECT_CHK_CONTACT_MASK) #define USB_ANALOG_CHRG_DETECT_CHK_CHRG_B_MASK (0x80000U) #define USB_ANALOG_CHRG_DETECT_CHK_CHRG_B_SHIFT (19U) /*! CHK_CHRG_B - Check the charger connection * 0b0..Check whether a charger (either a dedicated charger or a host charger) is connected to USB port. * 0b1..Do not check whether a charger is connected to the USB port. */ #define USB_ANALOG_CHRG_DETECT_CHK_CHRG_B(x) (((uint32_t)(((uint32_t)(x)) << USB_ANALOG_CHRG_DETECT_CHK_CHRG_B_SHIFT)) & USB_ANALOG_CHRG_DETECT_CHK_CHRG_B_MASK) #define USB_ANALOG_CHRG_DETECT_EN_B_MASK (0x100000U) #define USB_ANALOG_CHRG_DETECT_EN_B_SHIFT (20U) /*! EN_B * 0b0..Enable the charger detector. * 0b1..Disable the charger detector. */ #define USB_ANALOG_CHRG_DETECT_EN_B(x) (((uint32_t)(((uint32_t)(x)) << USB_ANALOG_CHRG_DETECT_EN_B_SHIFT)) & USB_ANALOG_CHRG_DETECT_EN_B_MASK) /*! @} */ /* The count of USB_ANALOG_CHRG_DETECT */ #define USB_ANALOG_CHRG_DETECT_COUNT (1U) /*! @name CHRG_DETECT_SET - USB Charger Detect Register */ /*! @{ */ #define USB_ANALOG_CHRG_DETECT_SET_CHK_CONTACT_MASK (0x40000U) #define USB_ANALOG_CHRG_DETECT_SET_CHK_CONTACT_SHIFT (18U) /*! CHK_CONTACT - Check the contact of USB plug * 0b0..Do not check the contact of USB plug. * 0b1..Check whether the USB plug has been in contact with each other */ #define USB_ANALOG_CHRG_DETECT_SET_CHK_CONTACT(x) (((uint32_t)(((uint32_t)(x)) << USB_ANALOG_CHRG_DETECT_SET_CHK_CONTACT_SHIFT)) & USB_ANALOG_CHRG_DETECT_SET_CHK_CONTACT_MASK) #define USB_ANALOG_CHRG_DETECT_SET_CHK_CHRG_B_MASK (0x80000U) #define USB_ANALOG_CHRG_DETECT_SET_CHK_CHRG_B_SHIFT (19U) /*! CHK_CHRG_B - Check the charger connection * 0b0..Check whether a charger (either a dedicated charger or a host charger) is connected to USB port. * 0b1..Do not check whether a charger is connected to the USB port. */ #define USB_ANALOG_CHRG_DETECT_SET_CHK_CHRG_B(x) (((uint32_t)(((uint32_t)(x)) << USB_ANALOG_CHRG_DETECT_SET_CHK_CHRG_B_SHIFT)) & USB_ANALOG_CHRG_DETECT_SET_CHK_CHRG_B_MASK) #define USB_ANALOG_CHRG_DETECT_SET_EN_B_MASK (0x100000U) #define USB_ANALOG_CHRG_DETECT_SET_EN_B_SHIFT (20U) /*! EN_B * 0b0..Enable the charger detector. * 0b1..Disable the charger detector. */ #define USB_ANALOG_CHRG_DETECT_SET_EN_B(x) (((uint32_t)(((uint32_t)(x)) << USB_ANALOG_CHRG_DETECT_SET_EN_B_SHIFT)) & USB_ANALOG_CHRG_DETECT_SET_EN_B_MASK) /*! @} */ /* The count of USB_ANALOG_CHRG_DETECT_SET */ #define USB_ANALOG_CHRG_DETECT_SET_COUNT (1U) /*! @name CHRG_DETECT_CLR - USB Charger Detect Register */ /*! @{ */ #define USB_ANALOG_CHRG_DETECT_CLR_CHK_CONTACT_MASK (0x40000U) #define USB_ANALOG_CHRG_DETECT_CLR_CHK_CONTACT_SHIFT (18U) /*! CHK_CONTACT - Check the contact of USB plug * 0b0..Do not check the contact of USB plug. * 0b1..Check whether the USB plug has been in contact with each other */ #define USB_ANALOG_CHRG_DETECT_CLR_CHK_CONTACT(x) (((uint32_t)(((uint32_t)(x)) << USB_ANALOG_CHRG_DETECT_CLR_CHK_CONTACT_SHIFT)) & USB_ANALOG_CHRG_DETECT_CLR_CHK_CONTACT_MASK) #define USB_ANALOG_CHRG_DETECT_CLR_CHK_CHRG_B_MASK (0x80000U) #define USB_ANALOG_CHRG_DETECT_CLR_CHK_CHRG_B_SHIFT (19U) /*! CHK_CHRG_B - Check the charger connection * 0b0..Check whether a charger (either a dedicated charger or a host charger) is connected to USB port. * 0b1..Do not check whether a charger is connected to the USB port. */ #define USB_ANALOG_CHRG_DETECT_CLR_CHK_CHRG_B(x) (((uint32_t)(((uint32_t)(x)) << USB_ANALOG_CHRG_DETECT_CLR_CHK_CHRG_B_SHIFT)) & USB_ANALOG_CHRG_DETECT_CLR_CHK_CHRG_B_MASK) #define USB_ANALOG_CHRG_DETECT_CLR_EN_B_MASK (0x100000U) #define USB_ANALOG_CHRG_DETECT_CLR_EN_B_SHIFT (20U) /*! EN_B * 0b0..Enable the charger detector. * 0b1..Disable the charger detector. */ #define USB_ANALOG_CHRG_DETECT_CLR_EN_B(x) (((uint32_t)(((uint32_t)(x)) << USB_ANALOG_CHRG_DETECT_CLR_EN_B_SHIFT)) & USB_ANALOG_CHRG_DETECT_CLR_EN_B_MASK) /*! @} */ /* The count of USB_ANALOG_CHRG_DETECT_CLR */ #define USB_ANALOG_CHRG_DETECT_CLR_COUNT (1U) /*! @name CHRG_DETECT_TOG - USB Charger Detect Register */ /*! @{ */ #define USB_ANALOG_CHRG_DETECT_TOG_CHK_CONTACT_MASK (0x40000U) #define USB_ANALOG_CHRG_DETECT_TOG_CHK_CONTACT_SHIFT (18U) /*! CHK_CONTACT - Check the contact of USB plug * 0b0..Do not check the contact of USB plug. * 0b1..Check whether the USB plug has been in contact with each other */ #define USB_ANALOG_CHRG_DETECT_TOG_CHK_CONTACT(x) (((uint32_t)(((uint32_t)(x)) << USB_ANALOG_CHRG_DETECT_TOG_CHK_CONTACT_SHIFT)) & USB_ANALOG_CHRG_DETECT_TOG_CHK_CONTACT_MASK) #define USB_ANALOG_CHRG_DETECT_TOG_CHK_CHRG_B_MASK (0x80000U) #define USB_ANALOG_CHRG_DETECT_TOG_CHK_CHRG_B_SHIFT (19U) /*! CHK_CHRG_B - Check the charger connection * 0b0..Check whether a charger (either a dedicated charger or a host charger) is connected to USB port. * 0b1..Do not check whether a charger is connected to the USB port. */ #define USB_ANALOG_CHRG_DETECT_TOG_CHK_CHRG_B(x) (((uint32_t)(((uint32_t)(x)) << USB_ANALOG_CHRG_DETECT_TOG_CHK_CHRG_B_SHIFT)) & USB_ANALOG_CHRG_DETECT_TOG_CHK_CHRG_B_MASK) #define USB_ANALOG_CHRG_DETECT_TOG_EN_B_MASK (0x100000U) #define USB_ANALOG_CHRG_DETECT_TOG_EN_B_SHIFT (20U) /*! EN_B * 0b0..Enable the charger detector. * 0b1..Disable the charger detector. */ #define USB_ANALOG_CHRG_DETECT_TOG_EN_B(x) (((uint32_t)(((uint32_t)(x)) << USB_ANALOG_CHRG_DETECT_TOG_EN_B_SHIFT)) & USB_ANALOG_CHRG_DETECT_TOG_EN_B_MASK) /*! @} */ /* The count of USB_ANALOG_CHRG_DETECT_TOG */ #define USB_ANALOG_CHRG_DETECT_TOG_COUNT (1U) /*! @name VBUS_DETECT_STAT - USB VBUS Detect Status Register */ /*! @{ */ #define USB_ANALOG_VBUS_DETECT_STAT_SESSEND_MASK (0x1U) #define USB_ANALOG_VBUS_DETECT_STAT_SESSEND_SHIFT (0U) #define USB_ANALOG_VBUS_DETECT_STAT_SESSEND(x) (((uint32_t)(((uint32_t)(x)) << USB_ANALOG_VBUS_DETECT_STAT_SESSEND_SHIFT)) & USB_ANALOG_VBUS_DETECT_STAT_SESSEND_MASK) #define USB_ANALOG_VBUS_DETECT_STAT_BVALID_MASK (0x2U) #define USB_ANALOG_VBUS_DETECT_STAT_BVALID_SHIFT (1U) #define USB_ANALOG_VBUS_DETECT_STAT_BVALID(x) (((uint32_t)(((uint32_t)(x)) << USB_ANALOG_VBUS_DETECT_STAT_BVALID_SHIFT)) & USB_ANALOG_VBUS_DETECT_STAT_BVALID_MASK) #define USB_ANALOG_VBUS_DETECT_STAT_AVALID_MASK (0x4U) #define USB_ANALOG_VBUS_DETECT_STAT_AVALID_SHIFT (2U) #define USB_ANALOG_VBUS_DETECT_STAT_AVALID(x) (((uint32_t)(((uint32_t)(x)) << USB_ANALOG_VBUS_DETECT_STAT_AVALID_SHIFT)) & USB_ANALOG_VBUS_DETECT_STAT_AVALID_MASK) #define USB_ANALOG_VBUS_DETECT_STAT_VBUS_VALID_MASK (0x8U) #define USB_ANALOG_VBUS_DETECT_STAT_VBUS_VALID_SHIFT (3U) #define USB_ANALOG_VBUS_DETECT_STAT_VBUS_VALID(x) (((uint32_t)(((uint32_t)(x)) << USB_ANALOG_VBUS_DETECT_STAT_VBUS_VALID_SHIFT)) & USB_ANALOG_VBUS_DETECT_STAT_VBUS_VALID_MASK) /*! @} */ /* The count of USB_ANALOG_VBUS_DETECT_STAT */ #define USB_ANALOG_VBUS_DETECT_STAT_COUNT (1U) /*! @name CHRG_DETECT_STAT - USB Charger Detect Status Register */ /*! @{ */ #define USB_ANALOG_CHRG_DETECT_STAT_PLUG_CONTACT_MASK (0x1U) #define USB_ANALOG_CHRG_DETECT_STAT_PLUG_CONTACT_SHIFT (0U) /*! PLUG_CONTACT * 0b0..The USB plug has not made contact. * 0b1..The USB plug has made good contact. */ #define USB_ANALOG_CHRG_DETECT_STAT_PLUG_CONTACT(x) (((uint32_t)(((uint32_t)(x)) << USB_ANALOG_CHRG_DETECT_STAT_PLUG_CONTACT_SHIFT)) & USB_ANALOG_CHRG_DETECT_STAT_PLUG_CONTACT_MASK) #define USB_ANALOG_CHRG_DETECT_STAT_CHRG_DETECTED_MASK (0x2U) #define USB_ANALOG_CHRG_DETECT_STAT_CHRG_DETECTED_SHIFT (1U) /*! CHRG_DETECTED * 0b0..The USB port is not connected to a charger. * 0b1..A charger (either a dedicated charger or a host charger) is connected to the USB port. */ #define USB_ANALOG_CHRG_DETECT_STAT_CHRG_DETECTED(x) (((uint32_t)(((uint32_t)(x)) << USB_ANALOG_CHRG_DETECT_STAT_CHRG_DETECTED_SHIFT)) & USB_ANALOG_CHRG_DETECT_STAT_CHRG_DETECTED_MASK) #define USB_ANALOG_CHRG_DETECT_STAT_DM_STATE_MASK (0x4U) #define USB_ANALOG_CHRG_DETECT_STAT_DM_STATE_SHIFT (2U) #define USB_ANALOG_CHRG_DETECT_STAT_DM_STATE(x) (((uint32_t)(((uint32_t)(x)) << USB_ANALOG_CHRG_DETECT_STAT_DM_STATE_SHIFT)) & USB_ANALOG_CHRG_DETECT_STAT_DM_STATE_MASK) #define USB_ANALOG_CHRG_DETECT_STAT_DP_STATE_MASK (0x8U) #define USB_ANALOG_CHRG_DETECT_STAT_DP_STATE_SHIFT (3U) #define USB_ANALOG_CHRG_DETECT_STAT_DP_STATE(x) (((uint32_t)(((uint32_t)(x)) << USB_ANALOG_CHRG_DETECT_STAT_DP_STATE_SHIFT)) & USB_ANALOG_CHRG_DETECT_STAT_DP_STATE_MASK) /*! @} */ /* The count of USB_ANALOG_CHRG_DETECT_STAT */ #define USB_ANALOG_CHRG_DETECT_STAT_COUNT (1U) /*! @name LOOPBACK - USB Loopback Test Register */ /*! @{ */ #define USB_ANALOG_LOOPBACK_UTMI_TESTSTART_MASK (0x1U) #define USB_ANALOG_LOOPBACK_UTMI_TESTSTART_SHIFT (0U) #define USB_ANALOG_LOOPBACK_UTMI_TESTSTART(x) (((uint32_t)(((uint32_t)(x)) << USB_ANALOG_LOOPBACK_UTMI_TESTSTART_SHIFT)) & USB_ANALOG_LOOPBACK_UTMI_TESTSTART_MASK) /*! @} */ /* The count of USB_ANALOG_LOOPBACK */ #define USB_ANALOG_LOOPBACK_COUNT (1U) /*! @name LOOPBACK_SET - USB Loopback Test Register */ /*! @{ */ #define USB_ANALOG_LOOPBACK_SET_UTMI_TESTSTART_MASK (0x1U) #define USB_ANALOG_LOOPBACK_SET_UTMI_TESTSTART_SHIFT (0U) #define USB_ANALOG_LOOPBACK_SET_UTMI_TESTSTART(x) (((uint32_t)(((uint32_t)(x)) << USB_ANALOG_LOOPBACK_SET_UTMI_TESTSTART_SHIFT)) & USB_ANALOG_LOOPBACK_SET_UTMI_TESTSTART_MASK) /*! @} */ /* The count of USB_ANALOG_LOOPBACK_SET */ #define USB_ANALOG_LOOPBACK_SET_COUNT (1U) /*! @name LOOPBACK_CLR - USB Loopback Test Register */ /*! @{ */ #define USB_ANALOG_LOOPBACK_CLR_UTMI_TESTSTART_MASK (0x1U) #define USB_ANALOG_LOOPBACK_CLR_UTMI_TESTSTART_SHIFT (0U) #define USB_ANALOG_LOOPBACK_CLR_UTMI_TESTSTART(x) (((uint32_t)(((uint32_t)(x)) << USB_ANALOG_LOOPBACK_CLR_UTMI_TESTSTART_SHIFT)) & USB_ANALOG_LOOPBACK_CLR_UTMI_TESTSTART_MASK) /*! @} */ /* The count of USB_ANALOG_LOOPBACK_CLR */ #define USB_ANALOG_LOOPBACK_CLR_COUNT (1U) /*! @name LOOPBACK_TOG - USB Loopback Test Register */ /*! @{ */ #define USB_ANALOG_LOOPBACK_TOG_UTMI_TESTSTART_MASK (0x1U) #define USB_ANALOG_LOOPBACK_TOG_UTMI_TESTSTART_SHIFT (0U) #define USB_ANALOG_LOOPBACK_TOG_UTMI_TESTSTART(x) (((uint32_t)(((uint32_t)(x)) << USB_ANALOG_LOOPBACK_TOG_UTMI_TESTSTART_SHIFT)) & USB_ANALOG_LOOPBACK_TOG_UTMI_TESTSTART_MASK) /*! @} */ /* The count of USB_ANALOG_LOOPBACK_TOG */ #define USB_ANALOG_LOOPBACK_TOG_COUNT (1U) /*! @name MISC - USB Misc Register */ /*! @{ */ #define USB_ANALOG_MISC_HS_USE_EXTERNAL_R_MASK (0x1U) #define USB_ANALOG_MISC_HS_USE_EXTERNAL_R_SHIFT (0U) #define USB_ANALOG_MISC_HS_USE_EXTERNAL_R(x) (((uint32_t)(((uint32_t)(x)) << USB_ANALOG_MISC_HS_USE_EXTERNAL_R_SHIFT)) & USB_ANALOG_MISC_HS_USE_EXTERNAL_R_MASK) #define USB_ANALOG_MISC_EN_DEGLITCH_MASK (0x2U) #define USB_ANALOG_MISC_EN_DEGLITCH_SHIFT (1U) #define USB_ANALOG_MISC_EN_DEGLITCH(x) (((uint32_t)(((uint32_t)(x)) << USB_ANALOG_MISC_EN_DEGLITCH_SHIFT)) & USB_ANALOG_MISC_EN_DEGLITCH_MASK) #define USB_ANALOG_MISC_EN_CLK_UTMI_MASK (0x40000000U) #define USB_ANALOG_MISC_EN_CLK_UTMI_SHIFT (30U) #define USB_ANALOG_MISC_EN_CLK_UTMI(x) (((uint32_t)(((uint32_t)(x)) << USB_ANALOG_MISC_EN_CLK_UTMI_SHIFT)) & USB_ANALOG_MISC_EN_CLK_UTMI_MASK) /*! @} */ /* The count of USB_ANALOG_MISC */ #define USB_ANALOG_MISC_COUNT (1U) /*! @name MISC_SET - USB Misc Register */ /*! @{ */ #define USB_ANALOG_MISC_SET_HS_USE_EXTERNAL_R_MASK (0x1U) #define USB_ANALOG_MISC_SET_HS_USE_EXTERNAL_R_SHIFT (0U) #define USB_ANALOG_MISC_SET_HS_USE_EXTERNAL_R(x) (((uint32_t)(((uint32_t)(x)) << USB_ANALOG_MISC_SET_HS_USE_EXTERNAL_R_SHIFT)) & USB_ANALOG_MISC_SET_HS_USE_EXTERNAL_R_MASK) #define USB_ANALOG_MISC_SET_EN_DEGLITCH_MASK (0x2U) #define USB_ANALOG_MISC_SET_EN_DEGLITCH_SHIFT (1U) #define USB_ANALOG_MISC_SET_EN_DEGLITCH(x) (((uint32_t)(((uint32_t)(x)) << USB_ANALOG_MISC_SET_EN_DEGLITCH_SHIFT)) & USB_ANALOG_MISC_SET_EN_DEGLITCH_MASK) #define USB_ANALOG_MISC_SET_EN_CLK_UTMI_MASK (0x40000000U) #define USB_ANALOG_MISC_SET_EN_CLK_UTMI_SHIFT (30U) #define USB_ANALOG_MISC_SET_EN_CLK_UTMI(x) (((uint32_t)(((uint32_t)(x)) << USB_ANALOG_MISC_SET_EN_CLK_UTMI_SHIFT)) & USB_ANALOG_MISC_SET_EN_CLK_UTMI_MASK) /*! @} */ /* The count of USB_ANALOG_MISC_SET */ #define USB_ANALOG_MISC_SET_COUNT (1U) /*! @name MISC_CLR - USB Misc Register */ /*! @{ */ #define USB_ANALOG_MISC_CLR_HS_USE_EXTERNAL_R_MASK (0x1U) #define USB_ANALOG_MISC_CLR_HS_USE_EXTERNAL_R_SHIFT (0U) #define USB_ANALOG_MISC_CLR_HS_USE_EXTERNAL_R(x) (((uint32_t)(((uint32_t)(x)) << USB_ANALOG_MISC_CLR_HS_USE_EXTERNAL_R_SHIFT)) & USB_ANALOG_MISC_CLR_HS_USE_EXTERNAL_R_MASK) #define USB_ANALOG_MISC_CLR_EN_DEGLITCH_MASK (0x2U) #define USB_ANALOG_MISC_CLR_EN_DEGLITCH_SHIFT (1U) #define USB_ANALOG_MISC_CLR_EN_DEGLITCH(x) (((uint32_t)(((uint32_t)(x)) << USB_ANALOG_MISC_CLR_EN_DEGLITCH_SHIFT)) & USB_ANALOG_MISC_CLR_EN_DEGLITCH_MASK) #define USB_ANALOG_MISC_CLR_EN_CLK_UTMI_MASK (0x40000000U) #define USB_ANALOG_MISC_CLR_EN_CLK_UTMI_SHIFT (30U) #define USB_ANALOG_MISC_CLR_EN_CLK_UTMI(x) (((uint32_t)(((uint32_t)(x)) << USB_ANALOG_MISC_CLR_EN_CLK_UTMI_SHIFT)) & USB_ANALOG_MISC_CLR_EN_CLK_UTMI_MASK) /*! @} */ /* The count of USB_ANALOG_MISC_CLR */ #define USB_ANALOG_MISC_CLR_COUNT (1U) /*! @name MISC_TOG - USB Misc Register */ /*! @{ */ #define USB_ANALOG_MISC_TOG_HS_USE_EXTERNAL_R_MASK (0x1U) #define USB_ANALOG_MISC_TOG_HS_USE_EXTERNAL_R_SHIFT (0U) #define USB_ANALOG_MISC_TOG_HS_USE_EXTERNAL_R(x) (((uint32_t)(((uint32_t)(x)) << USB_ANALOG_MISC_TOG_HS_USE_EXTERNAL_R_SHIFT)) & USB_ANALOG_MISC_TOG_HS_USE_EXTERNAL_R_MASK) #define USB_ANALOG_MISC_TOG_EN_DEGLITCH_MASK (0x2U) #define USB_ANALOG_MISC_TOG_EN_DEGLITCH_SHIFT (1U) #define USB_ANALOG_MISC_TOG_EN_DEGLITCH(x) (((uint32_t)(((uint32_t)(x)) << USB_ANALOG_MISC_TOG_EN_DEGLITCH_SHIFT)) & USB_ANALOG_MISC_TOG_EN_DEGLITCH_MASK) #define USB_ANALOG_MISC_TOG_EN_CLK_UTMI_MASK (0x40000000U) #define USB_ANALOG_MISC_TOG_EN_CLK_UTMI_SHIFT (30U) #define USB_ANALOG_MISC_TOG_EN_CLK_UTMI(x) (((uint32_t)(((uint32_t)(x)) << USB_ANALOG_MISC_TOG_EN_CLK_UTMI_SHIFT)) & USB_ANALOG_MISC_TOG_EN_CLK_UTMI_MASK) /*! @} */ /* The count of USB_ANALOG_MISC_TOG */ #define USB_ANALOG_MISC_TOG_COUNT (1U) /*! @name DIGPROG - Chip Silicon Version */ /*! @{ */ #define USB_ANALOG_DIGPROG_SILICON_REVISION_MASK (0xFFFFFFFFU) #define USB_ANALOG_DIGPROG_SILICON_REVISION_SHIFT (0U) /*! SILICON_REVISION * 0b00000000011010110000000000000000..Silicon revision 1.0 */ #define USB_ANALOG_DIGPROG_SILICON_REVISION(x) (((uint32_t)(((uint32_t)(x)) << USB_ANALOG_DIGPROG_SILICON_REVISION_SHIFT)) & USB_ANALOG_DIGPROG_SILICON_REVISION_MASK) /*! @} */ ////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////// /******************************************************************************* * Definitions ******************************************************************************/ /* EHCI host macros */ #define EHCI_HOST_T_INVALID_VALUE (1U) #define EHCI_HOST_POINTER_TYPE_ITD (0x00U) #define EHCI_HOST_POINTER_TYPE_QH (0x00000002U) #define EHCI_HOST_POINTER_TYPE_SITD (0x00000004U) #define EHCI_HOST_POINTER_TYPE_FSTN (0x00000006U) #define EHCI_HOST_POINTER_TYPE_MASK (0x00000006U) #define EHCI_HOST_POINTER_ADDRESS_MASK (0xFFFFFFE0U) #define EHCI_HOST_PID_OUT (0U) #define EHCI_HOST_PID_IN (1U) #define EHCI_HOST_PID_SETUP (2U) #define EHCI_HOST_QH_RL_SHIFT (28U) #define EHCI_HOST_QH_RL_MASK (0xF0000000U) #define EHCI_HOST_QH_C_SHIFT (27U) #define EHCI_HOST_QH_MAX_PACKET_LENGTH_SHIFT (16U) #define EHCI_HOST_QH_MAX_PACKET_LENGTH_MASK (0x07FF0000U) #define EHCI_HOST_QH_H_SHIFT (15U) #define EHCI_HOST_QH_DTC_SHIFT (14U) #define EHCI_HOST_QH_EPS_SHIFT (12U) #define EHCI_HOST_QH_ENDPT_SHIFT (8U) #define EHCI_HOST_QH_I_SHIFT (7U) #define EHCI_HOST_QH_DEVICE_ADDRESS_SHIFT (0U) #define EHCI_HOST_QH_DEVICE_ADDRESS_MASK (0x0000007FU) #define EHCI_HOST_QH_MULT_SHIFT (30U) #define EHCI_HOST_QH_PORT_NUMBER_SHIFT (23U) #define EHCI_HOST_QH_HUB_ADDR_SHIFT (16U) #define EHCI_HOST_QH_UFRAME_CMASK_SHIFT (8U) #define EHCI_HOST_QH_UFRAME_SMASK_SHIFT (0U) #define EHCI_HOST_QH_STATUS_ERROR_MASK (0x0000007EU) #define EHCI_HOST_QH_STATUS_NOSTALL_ERROR_MASK (0x0000003EU) #define EHCI_HOST_QTD_DT_SHIFT (31U) #define EHCI_HOST_QTD_DT_MASK (0x80000000U) #define EHCI_HOST_QTD_TOTAL_BYTES_SHIFT (16U) #define EHCI_HOST_QTD_TOTAL_BYTES_MASK (0x7FFF0000U) #define EHCI_HOST_QTD_IOC_MASK (0x00008000U) #define EHCI_HOST_QTD_C_PAGE_SHIFT (12U) #define EHCI_HOST_QTD_CERR_SHIFT (10U) #define EHCI_HOST_QTD_CERR_MAX_VALUE (0x00000003U) #define EHCI_HOST_QTD_PID_CODE_SHIFT (8U) #define EHCI_HOST_QTD_STATUS_SHIFT (0U) #define EHCI_HOST_QTD_CURRENT_OFFSET_MASK (0x00000FFFU) #define EHCI_HOST_QTD_BUFFER_POINTER_SHIFT (12U) #define EHCI_HOST_QTD_STATUS_ACTIVE_MASK (0x00000080U) #define EHCI_HOST_QTD_STATUS_MASK (0x000000ffU) #define EHCI_HOST_QTD_STATUS_ERROR_MASK (0x0000007EU) #define EHCI_HOST_QTD_STATUS_STALL_ERROR_MASK (0x00000040U) #define EHCI_HOST_ITD_STATUS_ACTIVE_MASK (0x80000000U) #define EHCI_HOST_ITD_TRANSACTION_LEN_SHIFT (16U) #define EHCI_HOST_ITD_TRANSACTION_LEN_MASK (0x0FFF0000U) #define EHCI_HOST_ITD_IOC_SHIFT (15U) #define EHCI_HOST_ITD_PG_SHIFT (12U) #define EHCI_HOST_ITD_TRANSACTION_OFFSET_SHIFT (0U) #define EHCI_HOST_ITD_TRANSACTION_OFFSET_MASK (0x00000FFFU) #define EHCI_HOST_ITD_BUFFER_POINTER_SHIFT (12U) #define EHCI_HOST_ITD_ENDPT_SHIFT (8U) #define EHCI_HOST_ITD_DEVICE_ADDRESS_SHIFT (0U) #define EHCI_HOST_ITD_MAX_PACKET_SIZE_SHIFT (0U) #define EHCI_HOST_ITD_MULT_SHIFT (0U) #define EHCI_HOST_ITD_DIRECTION_SHIFT (11U) #define EHCI_HOST_SITD_STATUS_ACTIVE_MASK (0x00000080U) #define EHCI_HOST_SITD_DIRECTION_SHIFT (31U) #define EHCI_HOST_SITD_PORT_NUMBER_SHIFT (24U) #define EHCI_HOST_SITD_HUB_ADDR_SHIFT (16U) #define EHCI_HOST_SITD_ENDPT_SHIFT (8U) #define EHCI_HOST_SITD_DEVICE_ADDRESS_SHIFT (0U) #define EHCI_HOST_SITD_CMASK_SHIFT (8U) #define EHCI_HOST_SITD_SMASK_SHIFT (0U) #define EHCI_HOST_SITD_TOTAL_BYTES_SHIFT (16U) #define EHCI_HOST_SITD_TOTAL_BYTES_MASK (0x03FF0000U) #define EHCI_HOST_SITD_TP_SHIFT (3U) #define EHCI_HOST_SITD_TCOUNT_SHIFT (0U) #define EHCI_HOST_SITD_IOC_SHIFT (31U) /* register related MACROs */ #define EHCI_PORTSC1_W1_BITS (0x0000002AU) #define EHCI_MAX_UFRAME_VALUE (0x00003FFFU) /* task event */ #define EHCI_TASK_EVENT_DEVICE_ATTACH (0x01U) #define EHCI_TASK_EVENT_TRANSACTION_DONE (0x02U) #define EHCI_TASK_EVENT_DEVICE_DETACH (0x04U) #define EHCI_TASK_EVENT_PORT_CHANGE (0x08U) #define EHCI_TASK_EVENT_TIMER0 (0x10U) #define EHCI_TASK_EVENT_TIMER1 (0x20U) #define USB_HostEhciLock() USB_ENTER_CRITICAL() #define USB_HostEhciUnlock() USB_EXIT_CRITICAL() /******************************************************************************* * KHCI driver public structures, enumerations, macros, functions ******************************************************************************/ /*! * @addtogroup usb_host_controller_ehci * @{ */ /*! @brief The maximum supported ISO pipe number */ #define USB_HOST_EHCI_ISO_NUMBER USB_HOST_CONFIG_EHCI_MAX_ITD /*! @brief Check the port connect state delay if the state is unstable */ #define USB_HOST_EHCI_PORT_CONNECT_DEBOUNCE_DELAY (101U) /*! @brief Delay for port reset */ #define USB_HOST_EHCI_PORT_RESET_DELAY (11U) /*! @brief The SITD inserts a frame interval for putting more SITD continuously. * There is an interval when an application sends two FS/LS ISO transfers. * When the interval is less than the macro, the two transfers are continuous in the frame list. Otherwise, the two * transfers * are not continuous. * For example: * - Use case 1: when inserting the SITD first, the inserted frame = the current frame value + this MACRO value. * - Use case 2: when inserting SITD is not first, choose between the last inserted frame value and the * current frame value according to the following criteria: * If the interval is less than the MACRO value, the new SITD is continuous with the last SITD. * If not, the new SITD inserting frame = the current frame value + this MACRO value. */ #define USB_HOST_EHCI_ISO_BOUNCE_FRAME_NUMBER (2U) /*! @brief The ITD inserts a micro-frame interval for putting more ITD continuously. * There is an interval when an application sends two HS ISO transfers. * When the interval is less than the macro, the two transfers are continuous in the frame list. Otherwise, the two * transfers * are not continuous. * For example: * - Use case 1: when inserting ITD first, the inserted micro-frame = the current micro-frame value + this MACRO value. * - Use case 2: when inserting ITD is not first, choose between the last inserted micro-frame value and the * current micro-frame value according to the following criteria: * If the interval is less than this MACRO value, the new ITD is continuous with the last ITD. * If not, the new ITD inserting micro-frame = the current micro-frame value + this MACRO value. */ #define USB_HOST_EHCI_ISO_BOUNCE_UFRAME_NUMBER (16U) /*! @brief Control or bulk transaction timeout value (unit: 100 ms) */ #define USB_HOST_EHCI_CONTROL_BULK_TIME_OUT_VALUE (50U) #if ((defined(USB_HOST_CONFIG_LOW_POWER_MODE)) && (USB_HOST_CONFIG_LOW_POWER_MODE > 0U)) typedef enum _bus_ehci_suspend_request_state { kBus_EhciIdle = 0U, kBus_EhciStartSuspend, kBus_EhciSuspended, kBus_EhciStartResume, } bus_ehci_suspend_request_state_t; #endif /* */ /*! @brief EHCI state for device attachment/detachment. */ typedef enum _host_ehci_device_state_ { kEHCIDevicePhyAttached = 1, /*!< Device is physically attached */ kEHCIDeviceAttached, /*!< Device is attached and initialized */ kEHCIDeviceDetached, /*!< Device is detached and de-initialized */ } host_ehci_device_state_t; /*! @brief EHCI pipe structure */ typedef struct _usb_host_ehci_pipe { usb_host_pipe_t pipeCommon; /*!< Common pipe information */ void *ehciQh; /*!< Control/bulk/interrupt: QH; ISO: usb_host_ehci_iso_t */ /* bandwidth */ uint16_t uframeInterval; /*!< Micro-frame interval value */ uint16_t startFrame; /*!< Bandwidth start frame: its value is from 0 to frame_list. */ uint16_t dataTime; /*!< Bandwidth time value: - When the host works as HS: it's the data bandwidth value. - When the host works as FS/LS: - For FS/LS device, it's the data bandwidth value when transferring the data by FS/LS. - For HS device, it's the data bandwidth value when transferring the data by HS. */ uint16_t startSplitTime; /*!< Start splitting the bandwidth time value: - When the host works as HS, it is the start split bandwidth value. */ uint16_t completeSplitTime; /*!< Complete splitting the bandwidth time value: - When host works as HS, it is the complete split bandwidth value. */ uint8_t startUframe; /*!< Bandwidth start micro-frame: its value is from 0 to 7. */ uint8_t uframeSmask; /*!< Start micro-frame. - When host works as an HS: - For FS/LS device, it's the interrupt or ISO transfer start-split mask. - For HS device, it's the interrupt transfer start micro-frame mask. - When host works as FS/LS, it's the interrupt and ISO start micro-frame mask */ uint8_t uframeCmask; /*!< Complete micro-frame - When host works as HS: - For FS/LS device, it's the interrupt or ISO transfer complete-split mask. */ } usb_host_ehci_pipe_t; /*! @brief EHCI QH structure. See the USB EHCI specification */ typedef struct _usb_host_ehci_qh { uint32_t horizontalLinkPointer; /*!< QH specification filed, queue head a horizontal link pointer */ uint32_t staticEndpointStates[2]; /*!< QH specification filed, static endpoint state and configuration information */ uint32_t currentQtdPointer; /*!< QH specification filed, current qTD pointer */ uint32_t nextQtdPointer; /*!< QH specification filed, next qTD pointer */ uint32_t alternateNextQtdPointer; /*!< QH specification filed, alternate next qTD pointer */ uint32_t transferOverlayResults[6]; /*!< QH specification filed, transfer overlay configuration and transfer results */ /* reserved space */ usb_host_ehci_pipe_t *ehciPipePointer; /*!< EHCI pipe pointer */ usb_host_transfer_t *ehciTransferHead; /*!< Transfer list head on this QH */ usb_host_transfer_t *ehciTransferTail; /*!< Transfer list tail on this QH */ uint16_t timeOutValue; /*!< Its maximum value is USB_HOST_EHCI_CONTROL_BULK_TIME_OUT_VALUE. When the value is zero, the transfer times out. */ uint16_t timeOutLabel; /*!< It's used to judge the transfer timeout. The EHCI driver maintain the value */ } usb_host_ehci_qh_t; /*! @brief EHCI QTD structure. See the USB EHCI specification. */ typedef struct _usb_host_ehci_qtd { uint32_t nextQtdPointer; /*!< QTD specification filed, the next QTD pointer */ uint32_t alternateNextQtdPointer; /*!< QTD specification filed, alternate next QTD pointer */ uint32_t transferResults[2]; /*!< QTD specification filed, transfer results fields */ uint32_t bufferPointers[4]; /*!< QTD specification filed, transfer buffer fields */ } usb_host_ehci_qtd_t; /*! @brief EHCI ITD structure. See the USB EHCI specification. */ typedef struct _usb_host_ehci_itd { uint32_t nextLinkPointer; /*!< ITD specification filed, the next linker pointer */ uint32_t transactions[8]; /*!< ITD specification filed, transactions information */ uint32_t bufferPointers[7]; /*!< ITD specification filed, transfer buffer fields */ /* add space */ struct _usb_host_ehci_itd *nextItdPointer; /*!< Next ITD pointer */ uint32_t frameEntryIndex; /*!< The ITD inserted frame value */ uint32_t reserved[6]; /*!< Reserved fields for 32 bytes align */ } usb_host_ehci_itd_t; /*! @brief EHCI SITD structure. See the USB EHCI specification. */ typedef struct _usb_host_ehci_sitd { uint32_t nextLinkPointer; /*!< SITD specification filed, the next linker pointer */ uint32_t endpointStates[2]; /*!< SITD specification filed, endpoint configuration information */ uint32_t transferResults[3]; /*!< SITD specification filed, transfer result fields */ uint32_t backPointer; /*!< SITD specification filed, back pointer */ /* reserved space */ uint16_t frameEntryIndex; /*!< The SITD inserted frame value */ uint8_t nextSitdIndex; /*!< The next SITD index; Get the next SITD pointer through adding base address with the index. 0xFF means invalid. */ uint8_t reserved; /*!< Reserved fields for 32 bytes align */ } usb_host_ehci_sitd_t; /*! @brief EHCI ISO structure; An ISO pipe has an instance of this structure to keep the ISO pipe-specific information. */ typedef struct _usb_host_ehci_iso { struct _usb_host_ehci_iso *next; /*!< Next instance pointer */ usb_host_pipe_t *ehciPipePointer; /*!< This ISO's EHCI pipe pointer */ usb_host_transfer_t *ehciTransferHead; /*!< Transfer list head on this ISO pipe */ usb_host_transfer_t *ehciTransferTail; /*!< Transfer list head on this ISO pipe */ uint16_t lastLinkFrame; /*!< It means that the inserted frame for ISO ITD/SITD. 0xFFFF is invalid. For ITD, it is a micro-frame value. For SITD, it is a frame value */ } usb_host_ehci_iso_t; /*! @brief EHCI data structure */ typedef struct _usb_host_ehci_data { #if ((defined(USB_HOST_CONFIG_EHCI_MAX_QH)) && (USB_HOST_CONFIG_EHCI_MAX_QH > 0U)) usb_host_ehci_qh_t ehciQh[USB_HOST_CONFIG_EHCI_MAX_QH]; /*!< Idle QH list array */ #endif /* */ #if ((defined(USB_HOST_CONFIG_EHCI_MAX_QTD)) && (USB_HOST_CONFIG_EHCI_MAX_QTD > 0U)) usb_host_ehci_qtd_t ehciQtd[USB_HOST_CONFIG_EHCI_MAX_QTD]; /*!< Idle QTD list array */ #endif /* */ #if ((defined(USB_HOST_CONFIG_EHCI_MAX_ITD)) && (USB_HOST_CONFIG_EHCI_MAX_ITD > 0U)) usb_host_ehci_itd_t ehciItd[USB_HOST_CONFIG_EHCI_MAX_ITD]; /*!< Idle ITD list array */ #endif /* */ #if ((defined(USB_HOST_CONFIG_EHCI_MAX_SITD)) && (USB_HOST_CONFIG_EHCI_MAX_SITD > 0U)) usb_host_ehci_sitd_t ehciSitd[USB_HOST_CONFIG_EHCI_MAX_SITD]; /*!< Idle SITD list array */ #endif /* */ #if ((defined(USB_HOST_EHCI_ISO_NUMBER)) && (USB_HOST_EHCI_ISO_NUMBER > 0U)) usb_host_ehci_iso_t ehciIso[USB_HOST_EHCI_ISO_NUMBER]; /*!< Idle ISO list array */ #endif /* */ #if ((defined(USB_HOST_CONFIG_MAX_PIPES)) && (USB_HOST_CONFIG_MAX_PIPES > 0U)) usb_host_ehci_pipe_t ehciPipe[USB_HOST_CONFIG_MAX_PIPES]; /*!< Idle pipe list array */ #endif /* */ } usb_host_ehci_data_t; /*! @brief EHCI instance structure */ typedef struct _IMXRT1020_USB_HOST_ { uint32_t usb_analog_index; uint32_t irqNumber; uint32_t irqPriority; uint8_t *ehciFrameList; /*!< The frame list of the current ehci instance */ usb_host_ehci_qh_t *ehciQhList; /*!< Idle QH list pointer */ usb_host_ehci_qtd_t *ehciQtdHead; /*!< Idle QTD list pointer head */ usb_host_ehci_qtd_t *ehciQtdTail; /*!< Idle QTD list pointer tail (recently used qTD will be used) */ usb_host_ehci_itd_t *ehciItdList; /*!< Idle ITD list pointer */ usb_host_ehci_sitd_t *ehciSitdIndexBase; /*!< SITD buffer's start pointer */ usb_host_ehci_sitd_t *ehciSitdList; /*!< Idle SITD list pointer */ usb_host_ehci_iso_t *ehciIsoList; /*!< Idle ISO list pointer */ imxrt1020_usb *usb; /*!< EHCI IP base address */ imxrt1020_usb_nc *usb_nc; /*!< EHCI IP non-core base address */ imxrt1020_usb_phy *usb_phy; imxrt1020_usb_analog *usb_analog; usb_host_ehci_qh_t *shedFirstQh; /*!< First async QH */ usb_host_ehci_pipe_t *ehciPipeIndexBase; /*!< Pipe buffer's start pointer */ usb_host_ehci_pipe_t *ehciPipeList; /*!< Idle pipe list pointer */ usb_host_ehci_pipe_t *ehciRunningPipeList; /*!< Running pipe list pointer */ #ifdef USB_TIZEN_RT struct work_s ehciEventTrigger; /* Supports interrupt bottom half */ #else /* */ usb_osa_event_handle ehciEventTrigger; /*!< EHCI task trigger */ #ifdef FSL_RTOS_FREE_RTOS osa_event_struct_t ehciEvent; #else /* */ event_t ehciEvent; #endif /* */ usb_osa_task_handle ehciEventTask; #endif /* */ USB_EVENT ehciEventFifo; //////////////////////////////////////////////////////////////////////////// usb_osa_event_handle ehciStatusChangeTrigger; #ifndef USB_TIZEN_RT #ifdef FSL_RTOS_FREE_RTOS osa_event_struct_t ehciStatusChangeEvent; #else /* */ event_t ehciStatusChangeEvent; #endif /* */ #endif /* */ USB_EVENT ehciStatusChangeFifo; usb_osa_task_handle ehciStatusMonitorTask; uint8_t deviceAttached; /*!< Device attach/detach state, see #host_ehci_device_state_t */ uint8_t firstDeviceSpeed; /*!< The first device's speed, the controller's work speed */ uint8_t ehciItdNumber; /*!< Idle ITD number */ uint8_t ehciSitdNumber; /*!< Idle SITD number */ uint8_t ehciQtdNumber; /*!< Idle QTD number */ // from usb_host_instance_t host_callback_t deviceCallback; /*!< Device attach/detach callback */ usb_host_transfer_t transferList[USB_HOST_CONFIG_MAX_TRANSFERS]; /*!< Transfer resource */ usb_host_transfer_t *transferHead; /*!< Idle transfer head */ void *deviceList; /*!< Device list */ uint8_t addressBitMap[16]; /*!< Used for address allocation. The first bit is the address 1, second bit is the address 2 */ uint8_t occupied; /*!< 0 - the instance is not occupied; 1 - the instance is occupied */ #if ((defined(USB_HOST_CONFIG_LOW_POWER_MODE)) && (USB_HOST_CONFIG_LOW_POWER_MODE > 0U)) uint64_t matchTick; bus_ehci_suspend_request_state_t busSuspendStatus; /*!< Bus Suspend Status */ void *suspendedDevice; /*!< Suspended device handle */ volatile uint64_t hwTick; /*!< Current hw tick(ms) */ usb_host_pipe_handle controlPipe; /*!< Device's control pipe */ #endif /* */ } IMXRT1020_USB_HOST; extern IMXRT1020_USB_HOST gIMXRT1020_USB_HOST; typedef struct _usb_host_ehci_sync_result { usb_status_t result; uint32_t dataLength; usb_osa_event_handle finished; /*!< waiting for transaction end */ #ifndef USB_TIZEN_RT #ifdef FSL_RTOS_FREE_RTOS osa_event_struct_t finishedEvent; #else /* */ event_t finishedEvent; #endif /* */ #endif /* */ } usb_host_ehci_sync_result_t; /*! * @name USB host EHCI APIs * @{ */ /*! * @brief Creates the USB host EHCI instance. * * This function initializes the USB host EHCI controller driver. * * * @retval kStatus_USB_Success The host is initialized successfully. * @retval kStatus_USB_AllocFail Allocating memory failed. * @retval kStatus_USB_Error Host mutex create fail, KHCI/EHCI mutex or KHCI/EHCI event create fail. * Or, KHCI/EHCI IP initialize fail. */ extern usb_status_t USB_HostEhciCreate(); /*! * @brief Destroys the USB host EHCI instance. * * This function de-initializes The USB host EHCI controller driver. * * * @retval kStatus_USB_Success The host is initialized successfully. */ extern usb_status_t USB_HostEhciDestroy(); /*! * @brief Opens the USB host pipe. * * This function opens a pipe according to the pipe_init_ptr parameter. * * @param[in] controllerHandle The controller handle. * @param[out] pipeHandle The pipe handle pointer, it is used to return the pipe handle. * @param[in] pipeInit It is used to initialize the pipe. * * @retval kStatus_USB_Success The host is initialized successfully. * @retval kStatus_USB_Error There is no idle pipe. * Or, there is no idle QH for EHCI. * Or, bandwidth allocate fail for EHCI. */ extern usb_status_t USB_HostEhciOpenPipe(usb_host_pipe_handle *pipeHandle, usb_host_pipe_init_t *pipeInit); /*! * @brief Closes the USB host pipe. * * This function closes a pipe and releases related resources. * * @param[in] controllerHandle The controller handle. * @param[in] pipeHandle The closing pipe handle. * * @retval kStatus_USB_Success The host is initialized successfully. */ extern usb_status_t USB_HostEhciClosePipe(usb_host_pipe_handle pipeHandle); /*! * @brief Sends data to the pipe. * * This function requests to send the transfer to the specified pipe. * * @param[in] controllerHandle The controller handle. * @param[in] pipeHandle The sending pipe handle. * @param[in] transfer The transfer information. * * @retval kStatus_USB_Success Sent successfully. * @retval kStatus_USB_LackSwapBuffer There is no swap buffer for KHCI. * @retval kStatus_USB_Error There is no idle QTD/ITD/SITD for EHCI. */ extern usb_status_t USB_HostEhciWritePipe(usb_host_pipe_handle pipeHandle, usb_host_transfer_t *transfer); /*! * @brief Receives data from the pipe. * * This function requests to receive the transfer from the specified pipe. * * @param[in] controllerHandle The controller handle. * @param[in] pipeHandle The receiving pipe handle. * @param[in] transfer The transfer information. * @retval kStatus_USB_Success Send successfully. * @retval kStatus_USB_LackSwapBuffer There is no swap buffer for KHCI. * @retval kStatus_USB_Error There is no idle QTD/ITD/SITD for EHCI. */ extern usb_status_t USB_HostEhciReadpipe(usb_host_pipe_handle pipeHandle, usb_host_transfer_t *transfer); /*! * @brief Controls the EHCI. * * This function controls the EHCI. * * @param[in] controllerHandle The controller handle. * @param[in] ioctlEvent See enumeration host_bus_control_t. * @param[in] ioctlParam The control parameter. * * @retval kStatus_USB_Success Cancel successfully. * @retval kStatus_USB_InvalidHandle The controllerHandle is a NULL pointer. */ extern usb_status_t USB_HostEhciIoctl(uint32_t ioctlEvent, void *ioctlParam); #endif /* _USB_HOST_CONTROLLER_EHCI_H_ */
4b042ddb23a314d0b5a8654e9e3764cd940ff915
f4ea6db9183b38e0cb1af1d317b0a02db24455d1
/src/bytecode.h
900a79637a7b524fee64ed464cae8135e6710809
[ "BSD-3-Clause", "LicenseRef-scancode-public-domain", "BSD-2-Clause" ]
permissive
ldmud/ldmud
1446ff7101f5a47ee1dfa4cfb97d5a326f2edcce
f1cfc9a8d911412d854055058889bb32432da2db
refs/heads/master
2023-05-25T00:36:28.318383
2023-02-14T21:07:35
2023-02-18T10:20:44
1,085,012
124
71
NOASSERTION
2023-09-01T16:54:48
2010-11-16T12:13:17
C
UTF-8
C
false
false
7,147
h
bytecode.h
#ifndef BYTECODE_H__ #define BYTECODE_H__ 1 /*--------------------------------------------------------------------------- * Types and Macros used to describe bytecode * *--------------------------------------------------------------------------- * While topically part of exec.h, the actual bytecode types and macros * have been exported into this file to reduce the coupling on exec.h. * Most files only need to know about bytecode_t and bytecode_p, and not * about all the other stuff in exec.h . * * Bytecode * -------- * * As the name conveys, the LPC programs are compiled into a bytecode, * assuming 8-Bit-Bytes. Since we have more than 256 opcodes, the less * often used instructions are encoded in two-byte opcodes: a prefix * byte and an sub-opcode. The translation opcode -> prefix:sub-opcode * is defined in the instrs[] table using the .prefix and .opcode * fields. * * To achieve platform independance, the driver does not operate directly * with 'char's and 'char *'s, but instead with 'bytecode_t' and * 'bytecode_p's. Combined with some macros this allows the implementation * even on platforms with CHAR_BITs != 8. * TODO: This support is far from complete/comprehensive, and some values * TODO:: in the bytecode are stored in host-sizes and -layouts. * * The bytecode itself is divided into functions: the code for every * function is (except for absolute jumps) selfcontained and prepended * by a header holding the index into the function table (which then * contains the name of the function name and number of arguments). * If the function has optional arguments (arguments with default values) * then it is followed by a jump table containing the relative offsets * (unsigned shorts) to the end of the initialization of optional arguments * (so the first entry skips the initialization of the first optional * variable, the second entry skips the second optional variable), * there are .num_opt_arg entries. * * The maximum size of a program is limited by the biggest offset * that can be stored in the 'functions' array, currently 1 MByte. * A lot of internal offset counters are shorts even, though so far * this never caused a problem. *--------------------------------------------------------------------------- */ #include "driver.h" #include "typedefs.h" /* --- Byte code --- * * The program code is stored as byte code. The following definitions * and macros allow its implementation even on platforms with more than * 8 bits per character. * TODO: This portability is far from complete, and not used everywhere, * TODO:: not even in the compiler. * * bytecode_t: an integral type holding the numbers 0..255. * bytecode_p: an integral type addressing a bytecode. This need not * be a pointer. * * bytecode_t GET_CODE(bytecode_p p) * bytecode_t LOAD_CODE(bytecode_p p) * Return the bytecode from *p, the LOAD_ variant then increments p. * * void PUT_CODE(bytecode_p p, bytecode_t c) * void STORE_CODE(bytecode_p p, bytecode_t c) * void RSTORE_CODE(bytecode_p p, bytecode_t c) * Store the bytecode c in *p, the STORE_ variant then increments p. * The RSTORE_ variant pre-decrements p. * * char GET_INT8(p) , LOAD_INT8(p) * uchar GET_UINT8(p), LOAD_UINT8(p) * Return the 8-Bit (unsigned) int stored at <p>, the LOAD_ variants * then increment <p>. * * void PUT_INT8(p, char c), STORE_INT8(p, char c) * void PUT_UINT8(p, uchar c), STORE_UINT8(p, uchar c) * Store the 8-Bit (unsigned) int <c> into <p>, the STORE_ variants * then increment <p>. * * void GET_SHORT ([unsigned] short d, bytecode_p p) * void LOAD_SHORT([unsigned] short d, bytecode_p p) * Load the (unsigned) short 'd' stored at <p>, the LOAD_ variant * then increments <p>. * TODO: Currently, all SHORTs must be 2 bytes. * * void PUT_SHORT (bytecode_p p, [unsigned] short d) * void STORE_SHORT(bytecode_p p, [unsigned] short d) * void RSTORE_SHORT(bytecode_p p, [unsigned] short d) * Store the (unsigned) short <d> into <p>, the STORE_ variant * then increments <p>. The RSTORE_ variant pre-decrements <p>. * TODO: Currently, all SHORTs must be 2 bytes. * * void GET_INT16 ([unsigned] int16 d, bytecode_p p) * void LOAD_INT16([unsigned] int16 d, bytecode_p p) * Load the (unsigned) int16 'd' stored at <p>, the LOAD_ variant * then increments <p>. * * void GET_LONG ([unsigned] long d, bytecode_p p) * void LOAD_LONG([unsigned] long d, bytecode_p p) * Load the (unsigned) long 'd' stored at <p>, the LOAD_ variant * then increments <p>. * TODO: Currently, all LONGs must be 4 bytes. * * void PUT_LONG (bytecode_p p, [unsigned] long d) * void STORE_LONG(bytecode_p p, [unsigned] long d) * void RSTORE_LONG(bytecode_p p, [unsigned] long d) * Store the (unsigned) long <d> into <p>, the STORE_ variant * then increments <p>. The RSTORE_ variant pre-decrements <p>. * TODO: Currently, all LONGs must be 4 bytes. * * void LOAD_INT32([unsigned] int32 d, bytecode_p p) * void GET_INT32([unsigned] int32 d, bytecode_p p) * Load the (unsigned) in32 'd' stored at <p>, the LOAD_ variant * then increments <p>. * * void STORE_INT32([unsigned] int32 d, bytecode_p p) * void PUT_INT32([unsigned] int32 d, bytecode_p p) * Store the (unsigned) int32 'd' at <p>, the STORE_ variant * then increments <p>. * * TODO: Instead of using *_LONG and *_SHORT we should introduce specific * TODO::types for specific tasks (like a type for offsets in the bytecode TODO::which can be different on different hosts and needs). In that way TODO::we should get rid of the *_SHORT and *_LONG variants. */ #if CHAR_BIT == 8 /* Types with specific semantics */ /* The basic code type encoding one instruction (bytecode_t) is in typedefs.h. // Type for storing offsets in the bytecode */ typedef int32_t bc_offset_t; typedef int16_t bc_shortoffset_t; #define PRIdBcOffset PRId32 #define PRIdBcShortOffset PRId16 // get_foo(), put_foo(), load_foo(), store_foo() and rstore_foo() functions #include "bytecode_gen.h" #if SIZEOF_SHORT != 2 # error "Unsupported size of short." #endif /* SIZEOF_SHORT */ /* some macros for compatibility */ #define GET_CODE(p) get_code(p) #define PUT_CODE(p,c) put_code((p),(c)) #define LOAD_CODE(p) load_code(&(p)) #define STORE_CODE(p,c) store_code(&(p),(c)) #define RSTORE_CODE(p,c) rstore_code(&(p),(c)) #define GET_UINT8(p) get_uint8(p) #define PUT_UINT8(p,c) put_uint8((p),(c)) #define LOAD_UINT8(p) load_uint8(&(p)) #define STORE_UINT8(p,c) store_uint8(&(p),(c)) #define GET_SHORT(d,p) (d = get_short((p))) #define LOAD_SHORT(d,p) (d = load_short(&(p))) #define PUT_SHORT(p,d) put_short((p),(d)) #define STORE_SHORT(p,d) store_short(&(p),(d)) #define RSTORE_SHORT(p,d) rstore_short(&(p),(d)) #endif /* CHAR_BIT */ /* #ifndef GET_CODE # error "No bytecode type defined." #endif */ #endif /* BYTECODE_H__ */ /* Tester: Coogan@tubmud, Arkas@Unitopia, largo@wunderland */
c8f028cdff84b3602f6ebce4ba786271c361497c
317410b28757af216145d23259d63fc96d07f613
/include_lib/driver/cpu/br25/asm/clock_define.h
c3f224e329cab60f7529cddf89b8121f6765b734
[ "Apache-2.0" ]
permissive
Jieli-Tech/fw-AC63_BT_SDK
48c757dca7e8000ec763bf5466583a4cd8c4a11c
393d63758081d56f0bf0a39ac596bee32c33d493
refs/heads/master
2023-07-18T02:14:56.187266
2023-06-21T03:14:20
2023-06-21T03:14:20
272,586,610
113
76
Apache-2.0
2022-10-20T23:07:31
2020-06-16T02:02:15
C
UTF-8
C
false
false
593
h
clock_define.h
#ifndef _CPU_CLOCK_DEFINE__ #define _CPU_CLOCK_DEFINE__ #define SYS_CLOCK_INPUT_RC 0 #define SYS_CLOCK_INPUT_BT_OSC 1 //BTOSC 双脚(12-26M) #define SYS_CLOCK_INPUT_RTOSCH 2 #define SYS_CLOCK_INPUT_RTOSCL 3 #define SYS_CLOCK_INPUT_PAT 4 #define SYS_CLOCK_INPUT_BT_OSCX2 5 //BTOSC 双脚(12-26M) ///衍生时钟源作系统时钟源 #define SYS_CLOCK_INPUT_PLL_RCL 6 #define SYS_CLOCK_INPUT_PLL_RCH 7 #define SYS_CLOCK_INPUT_PLL_BT_OSC 8 #define SYS_CLOCK_INPUT_PLL_RTOSCH 9 #define SYS_CLOCK_INPUT_PLL_PAT 10 #endif
28131a84152f7ffdc8960967ca936e9e6ccc9b73
5a5e1d7caeca65fa5121170c6aca351d2d495a35
/Samples/Asteroids/assets/shaders/shader_common.h
f83f12b47ebabc5d8fe18a4482319b9284716bfb
[ "LicenseRef-scancode-proprietary-license", "Intel", "LicenseRef-scancode-unknown-license-reference", "Zlib", "Apache-2.0", "LicenseRef-scancode-public-domain" ]
permissive
DiligentGraphics/DiligentSamples
06cf826ad79f6831c01578789d506d01af1d7cd0
7c5561876300b97d1debf5fb79b76b21f8caa782
refs/heads/master
2023-09-06T07:23:21.847248
2023-09-05T16:42:18
2023-09-05T16:42:18
44,292,736
326
102
Apache-2.0
2023-08-01T04:09:35
2015-10-15T03:57:07
C++
UTF-8
C
false
false
217
h
shader_common.h
#ifndef SHADER_COMMON_H #define SHADER_COMMON_H struct VSOut { float3 positionModel : POSITIONMODEL; float3 normalWorld : NORMAL; float3 albedo : ALBEDO; uint textureId : TEXTURE_ID; }; #endif
a09656eab99c4a2492867a0e8dff1e2c37b1c5a1
61da6274995cf914291af51bd02e60f408fdfedd
/src/noncart/nufft_chain.h
6704c3a71fd4910862ebd9af7a187cd75b8b74a2
[ "LicenseRef-scancode-unknown-license-reference", "BSD-3-Clause" ]
permissive
mrirecon/bart
360d518b4c79836d506803aa4a77e8e252ab820b
a3c9dc313f79c4c52f1ba3e617d5831ef088ddf7
refs/heads/master
2023-08-31T11:01:08.932824
2023-08-30T12:15:35
2023-08-30T13:51:18
23,212,230
264
185
BSD-3-Clause
2023-08-03T18:43:36
2014-08-22T03:57:09
C
UTF-8
C
false
false
803
h
nufft_chain.h
#include "misc/cppwrap.h" struct linop_s; struct grid_conf_s; extern struct linop_s* linop_kb_rolloff_create(int N, const long dims[__VLA(N)], unsigned long flags, struct grid_conf_s* conf); extern struct linop_s* linop_interpolate_create(int N, unsigned long flags, const long ksp_dims[__VLA(N)], const long grd_dims[__VLA(N)], const long trj_dims[__VLA(N)], const _Complex float* traj, struct grid_conf_s* conf); extern struct linop_s* nufft_create_chain(int N, const long ksp_dims[N], const long cim_dims[N], const long traj_dims[N], const _Complex float* traj, const long wgh_dims[N], const _Complex float* weights, const long bas_dims[N], const _Complex float* basis, struct grid_conf_s* conf); #include "misc/cppwrap.h"
b8e557e12212929d2b6a68971a16489b7925a028
94096248c1de2dcf46e69ca913cedfa290e44224
/tests/api/test-safe-to-string.c
334d9b351937005c42224d9614f97d45bb1c36ed
[ "LicenseRef-scancode-unknown-license-reference", "MIT" ]
permissive
svaarala/duktape
612110d1a6db46226c171cfd222974b1b3651ad5
5e169deafbbd12823665f5d30fb4c4c04e3dfa26
refs/heads/master
2023-08-06T16:43:33.014729
2022-11-17T21:02:08
2022-11-17T21:02:08
15,852,088
4,796
610
MIT
2023-09-11T17:13:01
2014-01-12T22:16:14
JavaScript
UTF-8
C
false
false
3,004
c
test-safe-to-string.c
/*=== *** test_1 (duk_safe_call) top=4 duk_safe_to_string[0] = '123' top=4 duk_safe_to_string[1] = 'toString result' top=4 duk_safe_to_string[2] = 'Error: toString error' top=4 duk_safe_to_string[3] = 'Error' top=4 duk_safe_to_lstring_null[0] = '123' top=4 duk_safe_to_lstring_null[1] = 'toString result' top=4 duk_safe_to_lstring_null[2] = 'Error: toString error' top=4 duk_safe_to_lstring_null[3] = 'Error' top=4 duk_safe_to_lstring[0] = '123', len 3 top=4 duk_safe_to_lstring[1] = 'toString result', len 15 top=4 duk_safe_to_lstring[2] = 'Error: toString error', len 21 top=4 duk_safe_to_lstring[3] = 'Error', len 5 top=4 duk_safe_to_lstring[0] = '123', len 3 top=4 duk_safe_to_lstring[1] = 'toString result', len 15 top=4 duk_safe_to_lstring[2] = 'Error: toString error', len 21 top=4 duk_safe_to_lstring[3] = 'Error', len 5 ==> rc=0, result='undefined' ===*/ static void init_test_values(duk_context *ctx) { duk_set_top(ctx, 0); /* Simple */ duk_push_int(ctx, 123); /* Object with toString() */ duk_eval_string(ctx, "({ toString: function () { return 'toString result'; } })"); /* toString() throws an error */ duk_eval_string(ctx, "({ toString: function () { throw new Error('toString error'); } })"); /* toString() throws an error which cannot be string coerced */ duk_eval_string(ctx, "({ toString: function () { var e = new Error('cannot string coerce me');" " e.toString = function () { throw new Error('coercion error'); };" " throw e; } })"); /* XXX: add an infinite loop and timeout case */ } static duk_ret_t test_1(duk_context *ctx, void *udata) { duk_idx_t i, n; (void) udata; /* duk_safe_to_string() */ init_test_values(ctx); n = duk_get_top(ctx); for (i = 0; i < n; i++) { printf("top=%ld\n", (long) duk_get_top(ctx)); printf("duk_safe_to_string[%ld] = '%s'\n", (long) i, duk_safe_to_string(ctx, i)); } /* duk_safe_to_lstring() with NULL arg */ init_test_values(ctx); n = duk_get_top(ctx); for (i = 0; i < n; i++) { const char *str; printf("top=%ld\n", (long) duk_get_top(ctx)); str = duk_safe_to_lstring(ctx, i, NULL); printf("duk_safe_to_lstring_null[%ld] = '%s'\n", (long) i, str); } /* duk_safe_to_lstring() */ init_test_values(ctx); n = duk_get_top(ctx); for (i = 0; i < n; i++) { const char *str; duk_size_t len; printf("top=%ld\n", (long) duk_get_top(ctx)); str = duk_safe_to_lstring(ctx, i, &len); printf("duk_safe_to_lstring[%ld] = '%s', len %lu\n", (long) i, str, (unsigned long) len); } /* duk_safe_to_lstring() with negative stack indices */ init_test_values(ctx); n = duk_get_top(ctx); for (i = 0; i < n; i++) { const char *str; duk_size_t len; printf("top=%ld\n", (long) duk_get_top(ctx)); str = duk_safe_to_lstring(ctx, -4 + i, &len); printf("duk_safe_to_lstring[%ld] = '%s', len %lu\n", (long) i, str, (unsigned long) len); } return 0; } void test(duk_context *ctx) { TEST_SAFE_CALL(test_1); }
487af2b44d904a931726c0f09bbeac8d3fa2571b
c26d7b0ed875357278e61627da2da0650da77986
/src/games/trek/srscan.c
24b4940f155744b165b4ba93fd96027e5b6fb1da
[ "BSD-3-Clause" ]
permissive
RetroBSD/retrobsd
5343d9e3c424637fc3ad5b03fe720b2744490025
486f81f6abff01c7dcc207235cd2979b226a95ff
refs/heads/master
2023-09-02T23:12:05.110883
2023-07-07T18:41:40
2023-07-07T18:41:40
18,598,087
282
59
BSD-3-Clause
2023-07-18T07:35:36
2014-04-09T13:25:46
C
UTF-8
C
false
false
3,560
c
srscan.c
/* * Copyright (c) 1980 Regents of the University of California. * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. */ # include "trek.h" # include "getpar.h" /* ** SHORT RANGE SENSOR SCAN ** ** A short range scan is taken of the current quadrant. If the ** flag 'f' is one, it is an "auto srscan", which is not done ** unless in 'fast' mode. It does a status report and a srscan. ** If 'f' is -1, you get a status report only. If it is zero, ** you get a srscan and an optional status report. The status ** report is taken if you enter "srscan yes"; for all srscans ** thereafter you get a status report with your srscan until ** you type "srscan no". It defaults to on. ** ** The current quadrant is filled in on the computer chart. */ char *Color[4] = { "GREEN", "DOCKED", "YELLOW", "RED" }; void srscan(f) int f; { register int i, j; register int statinfo; char *s; int percent; struct quad *q = 0; extern struct cvntab Skitab[]; extern struct cvntab Lentab[]; struct cvntab *p; if (f >= 0 && check_out(SRSCAN)) { return; } if (f) statinfo = 1; else { if (!testnl()) Etc.statreport = getynpar("status report"); statinfo = Etc.statreport; } if (f > 0) { Etc.statreport = 1; if (!Etc.fast) return; } if (f >= 0) { printf("\nShort range sensor scan\n"); q = &Quad[Ship.quadx][Ship.quady]; q->scanned = q->klings * 100 + q->bases * 10 + q->stars; printf(" "); for (i = 0; i < NSECTS; i++) { printf("%d ", i); } printf("\n"); } for (i = 0; i < NSECTS; i++) { if (f >= 0) { printf("%d ", i); for (j = 0; j < NSECTS; j++) printf("%c ", Sect[i][j]); printf("%d", i); if (statinfo) printf(" "); } if (statinfo) switch (i) { case 0: printf("stardate %.2f", Now.date); break; case 1: printf("condition %s", Color[(int)Ship.cond]); if (Ship.cloaked) printf(", CLOAKED"); break; case 2: printf("position %d,%d/%d,%d",Ship.quadx, Ship.quady, Ship.sectx, Ship.secty); break; case 3: printf("warp factor %.1f", Ship.warp); break; case 4: printf("total energy %d", Ship.energy); break; case 5: printf("torpedoes %d", Ship.torped); break; case 6: s = "down"; if (Ship.shldup) s = "up"; if (damaged(SHIELD)) s = "damaged"; percent = 100.0 * Ship.shield / Param.shield; printf("shields %s, %d%%", s, percent); break; case 7: printf("Klingons left %d", Now.klings); break; case 8: printf("time left %.2f", Now.time); break; case 9: printf("life support "); if (damaged(LIFESUP)) { printf("damaged, reserves = %.2f", Ship.reserves); break; } printf("active"); break; } printf("\n"); } if (f < 0) { printf("current crew %d\n", Ship.crew); printf("brig space %d\n", Ship.brigfree); printf("Klingon power %d\n", Param.klingpwr); p = &Lentab[Game.length - 1]; if (Game.length > 2) p--; printf("Length, Skill %s%s, ", p->abrev, p->full); p = &Skitab[Game.skill - 1]; printf("%s%s\n", p->abrev, p->full); return; } printf(" "); for (i = 0; i < NSECTS; i++) printf("%d ", i); printf("\n"); if (q) { if (q->qsystemname & Q_DISTRESSED) printf("Distressed "); if (q->qsystemname) printf("Starsystem %s\n", systemname(q)); } }
6b7e1b87f0f2af7f094f6450a6755f2909a2c6b4
9ddb8156ad2955f303055ae6d69509ddbdaecc41
/libs/OpenSSL/include/internal/quic_stream_map.h
fe430a8f4a1c76934b6080cf4ae22b42084129c8
[ "MIT" ]
permissive
Serial-Studio/Serial-Studio
3097a03a785a1e5d293357dd14bbb248609152b4
0a16c90acdde2e99a5e78dc158eae38cf0926c19
refs/heads/master
2023-08-27T08:42:15.383058
2023-02-06T03:32:38
2023-02-06T03:32:38
305,089,628
3,794
568
NOASSERTION
2022-09-27T17:41:22
2020-10-18T11:49:02
C++
UTF-8
C
false
false
7,509
h
quic_stream_map.h
/* * Copyright 2022 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ #ifndef OSSL_INTERNAL_QUIC_STREAM_MAP_H #define OSSL_INTERNAL_QUIC_STREAM_MAP_H #pragma once #include "internal/e_os.h" #include "internal/time.h" #include "internal/quic_types.h" #include "internal/quic_stream.h" #include "internal/quic_fc.h" #include <openssl/lhash.h> /* * QUIC Stream * =========== * * Logical QUIC stream composing all relevant send and receive components. */ typedef struct quic_stream_st QUIC_STREAM; typedef struct quic_stream_list_node_st QUIC_STREAM_LIST_NODE; struct quic_stream_list_node_st { QUIC_STREAM_LIST_NODE *prev, *next; }; struct quic_stream_st { QUIC_STREAM_LIST_NODE active_node; /* for use by QUIC_STREAM_MAP */ /* Temporary link used by TXP. */ QUIC_STREAM *txp_next; /* * QUIC Stream ID. Do not assume that this encodes a type as this is a * version-specific property and may change between QUIC versions; instead, * use the type field. */ uint64_t id; /* * Application Error Code (AEC) used for STOP_SENDING frame. * This is only valid if stop_sending is 1. */ uint64_t stop_sending_aec; /* * Application Error Code (AEC) used for RESET_STREAM frame. * This is only valid if reset_stream is 1. */ uint64_t reset_stream_aec; /* Temporary value used by TXP. */ uint64_t txp_txfc_new_credit_consumed; QUIC_SSTREAM *sstream; /* NULL if RX-only */ void *rstream; /* NULL if TX only (placeholder) */ QUIC_TXFC txfc; /* NULL if RX-only */ QUIC_RXFC rxfc; /* NULL if TX-only */ unsigned int type : 8; /* QUIC_STREAM_INITIATOR_*, QUIC_STREAM_DIR_* */ unsigned int active : 1; /* * Has STOP_SENDING been requested? Note that this is not the same as * want_stop_sending below, as a STOP_SENDING frame may already have been * sent and fully acknowledged. */ unsigned int stop_sending : 1; /* * Has RESET_STREAM been requested? Works identically to STOP_SENDING for * transmission purposes. */ unsigned int reset_stream : 1; /* Temporary flags used by TXP. */ unsigned int txp_sent_fc : 1; unsigned int txp_sent_stop_sending : 1; unsigned int txp_sent_reset_stream : 1; unsigned int txp_drained : 1; unsigned int txp_blocked : 1; /* Frame regeneration flags. */ unsigned int want_max_stream_data : 1; /* used for regen only */ unsigned int want_stop_sending : 1; /* used for gen or regen */ unsigned int want_reset_stream : 1; /* used for gen or regen */ }; /* * Marks a stream for STOP_SENDING. aec is the application error code (AEC). * This can only fail if it has already been called. */ int ossl_quic_stream_stop_sending(QUIC_STREAM *s, uint64_t aec); /* * Marks a stream for reset. aec is the application error code (AEC). * This can only fail if it has already been called. */ int ossl_quic_stream_reset(QUIC_STREAM *s, uint64_t aec); /* * QUIC Stream Map * =============== * * The QUIC stream map: * * - maps stream IDs to QUIC_STREAM objects; * - tracks which streams are 'active' (currently have data for transmission); * - allows iteration over the active streams only. * */ typedef struct quic_stream_map_st { LHASH_OF(QUIC_STREAM) * map; QUIC_STREAM_LIST_NODE active_list; size_t rr_stepping, rr_counter; QUIC_STREAM *rr_cur; } QUIC_STREAM_MAP; int ossl_quic_stream_map_init(QUIC_STREAM_MAP *qsm); /* * Any streams still in the map will be released as though * ossl_quic_stream_map_release was called on them. */ void ossl_quic_stream_map_cleanup(QUIC_STREAM_MAP *qsm); #define QUIC_STREAM_INITIATOR_CLIENT 0 #define QUIC_STREAM_INITIATOR_SERVER 1 #define QUIC_STREAM_INITIATOR_MASK 1 #define QUIC_STREAM_DIR_BIDI 0 #define QUIC_STREAM_DIR_UNI 2 #define QUIC_STREAM_DIR_MASK 2 /* * Allocate a new stream. type is a combination of one QUIC_STREAM_INITIATOR_* * value and one QUIC_STREAM_DIR_* value. Note that clients can e.g. allocate * server-initiated streams as they will need to allocate a QUIC_STREAM * structure to track any stream created by the server, etc. * * stream_id must be a valid value. Returns NULL if a stream already exists * with the given ID. */ QUIC_STREAM *ossl_quic_stream_map_alloc(QUIC_STREAM_MAP *qsm, uint64_t stream_id, int type); /* * Releases a stream object. Note that this must only be done once the teardown * process is entirely complete and the object will never be referenced again. */ void ossl_quic_stream_map_release(QUIC_STREAM_MAP *qsm, QUIC_STREAM *stream); /* * Calls visit_cb() for each stream in the map. visit_cb_arg is an opaque * argument which is passed through. */ void ossl_quic_stream_map_visit(QUIC_STREAM_MAP *qsm, void (*visit_cb)(QUIC_STREAM *stream, void *arg), void *visit_cb_arg); /* * Retrieves a stream by stream ID. Returns NULL if it does not exist. */ QUIC_STREAM *ossl_quic_stream_map_get_by_id(QUIC_STREAM_MAP *qsm, uint64_t stream_id); /* * Marks the given stream as active or inactive based on its state. Idempotent. * * When a stream is marked active, it becomes available in the iteration list, * and when a stream is marked inactive, it no longer appears in the iteration * list. * * Calling this function invalidates any iterator currently pointing at the * given stream object, but iterators not currently pointing at the given stream * object are not invalidated. */ void ossl_quic_stream_map_update_state(QUIC_STREAM_MAP *qsm, QUIC_STREAM *s); /* * Sets the RR stepping value, n. The RR rotation will be advanced every n * packets. The default value is 1. */ void ossl_quic_stream_map_set_rr_stepping(QUIC_STREAM_MAP *qsm, size_t stepping); /* * QUIC Stream Iterator * ==================== * * Allows the current set of active streams to be walked using a RR-based * algorithm. Each time ossl_quic_stream_iter_init is called, the RR algorithm * is stepped. The RR algorithm rotates the iteration order such that the next * active stream is returned first after n calls to ossl_quic_stream_iter_init, * where n is the stepping value configured via * ossl_quic_stream_map_set_rr_stepping. * * Suppose there are three active streams and the configured stepping is n: * * Iteration 0n: [Stream 1] [Stream 2] [Stream 3] * Iteration 1n: [Stream 2] [Stream 3] [Stream 1] * Iteration 2n: [Stream 3] [Stream 1] [Stream 2] * */ typedef struct quic_stream_iter_st { QUIC_STREAM_MAP *qsm; QUIC_STREAM *first_stream, *stream; } QUIC_STREAM_ITER; /* * Initialise an iterator, advancing the RR algorithm as necessary (if * advance_rr is 1). After calling this, it->stream will be the first stream in * the iteration sequence, or NULL if there are no active streams. */ void ossl_quic_stream_iter_init(QUIC_STREAM_ITER *it, QUIC_STREAM_MAP *qsm, int advance_rr); /* * Advances to next stream in iteration sequence. You do not need to call this * immediately after calling ossl_quic_stream_iter_init(). If the end of the * list is reached, it->stream will be NULL after calling this. */ void ossl_quic_stream_iter_next(QUIC_STREAM_ITER *it); #endif
b378b26724c33ba5f431ae48f074ec136b2cd06a
88ae8695987ada722184307301e221e1ba3cc2fa
/third_party/xnnpack/src/src/f32-prelu/gen/f32-prelu-wasm-2x1.c
e7088a48728169f6ecf7fcd86ef834b80d7ae388
[ "BSD-3-Clause", "LicenseRef-scancode-generic-cla", "Apache-2.0", "LGPL-2.0-or-later", "MIT", "GPL-1.0-or-later" ]
permissive
iridium-browser/iridium-browser
71d9c5ff76e014e6900b825f67389ab0ccd01329
5ee297f53dc7f8e70183031cff62f37b0f19d25f
refs/heads/master
2023-08-03T16:44:16.844552
2023-07-20T15:17:00
2023-07-23T16:09:30
220,016,632
341
40
BSD-3-Clause
2021-08-13T13:54:45
2019-11-06T14:32:31
null
UTF-8
C
false
false
1,845
c
f32-prelu-wasm-2x1.c
// Auto-generated file. Do not edit! // Template: src/f32-prelu/wasm.c.in // Generator: tools/xngen // // Copyright 2020 Google LLC // // This source code is licensed under the BSD-style license found in the // LICENSE file in the root directory of this source tree. #include <assert.h> #include <xnnpack/math.h> #include <xnnpack/prelu.h> void xnn_f32_prelu_ukernel__wasm_2x1( size_t rows, size_t channels, const float*restrict input, size_t input_stride, const float*restrict weights, float*restrict output, size_t output_stride) { assert(rows != 0); assert(channels != 0); assert(channels % sizeof(float) == 0); const float* i0 = input; float* o0 = output; const float* i1 = (const float*) ((uintptr_t) i0 + input_stride); float* o1 = (float*) ((uintptr_t) o0 + output_stride); const size_t input_increment = input_stride * 2 - channels; const size_t output_increment = output_stride * 2 - channels; const float vzero = 0.0f; do { if XNN_UNPREDICTABLE(rows < 2) { i1 = i0; o1 = o0; } const float* w = weights; size_t c = channels; do { const float vw = *w++; float vi0 = *i0++; float vi1 = *i1++; float vacc0 = __builtin_wasm_max_f32(vi0, vzero); vi0 = __builtin_wasm_min_f32(vi0, vzero); float vacc1 = __builtin_wasm_max_f32(vi1, vzero); vi1 = __builtin_wasm_min_f32(vi1, vzero); vacc0 += vi0 * vw; vacc1 += vi1 * vw; *o0++ = vacc0; *o1++ = vacc1; c -= sizeof(float); } while (c != 0); i0 = (const float*) ((uintptr_t) i0 + input_increment); o0 = (float*) ((uintptr_t) o0 + output_increment); i1 = (const float*) ((uintptr_t) i1 + input_increment); o1 = (float*) ((uintptr_t) o1 + output_increment); rows = doz(rows, 2); } while (rows != 0); }
f956b8b45bb9830b9dcb86bb6e5635ed08000b79
4ad126c6c71735fc9c6707253c5d026b7818b5ec
/log.c
b5f16e892072b4fdfb65dc15b4946ad67d69148f
[ "MIT" ]
permissive
adrianlopezroche/fdupes
06854b9f006ddd96e6e0890df3275bed5ae93625
04bb0b6c8da1b8c6afa8a95a820100ee34eb258c
refs/heads/master
2022-11-08T19:59:31.999498
2022-11-06T01:32:32
2022-11-06T01:33:48
19,813,003
1,989
235
null
2023-09-04T08:34:51
2014-05-15T09:00:19
C
UTF-8
C
false
false
4,386
c
log.c
/* Copyright (c) 2018-2022 Adrian Lopez This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include <stdlib.h> #include <string.h> #include <time.h> #include "fmatch.h" #include "dir.h" #include "log.h" #define LOG_HEADER "[fdupes log]\n" /* Open log file in append mode. If file exists, make sure it is a valid fdupes log file. */ struct log_info *log_open(char *filename, int *error) { struct log_info *info; int is_match; size_t read; info = (struct log_info*) malloc(sizeof(struct log_info)); if (info == 0) { if (error != 0) *error = LOG_ERROR_OUT_OF_MEMORY; return 0; } info->file = fopen(filename, "a+"); if (info->file == 0) { if (error != 0) *error = LOG_ERROR_FOPEN_FAILED; free(info); return 0; } fmatch(info->file, LOG_HEADER, &is_match, &read); if (!is_match && read > 0) { if (error != 0) *error = LOG_ERROR_NOT_A_LOG_FILE; free(info); return 0; } info->append = read > 0; info->log_start = 1; info->deleted = 0; info->remaining = 0; if (error != 0) *error = LOG_ERROR_NONE; return info; } /* Free linked lists holding set of deleted and remaining files. */ void log_free_set(struct log_info *info) { struct log_file *f; struct log_file *next; f = info->deleted; while (f != 0) { next = f->next; free(f); f = next; } f = info->remaining; while (f != 0) { next = f->next; free(f); f = next; } info->deleted = 0; info->remaining = 0; } /* Signal beginning of duplicate set. */ void log_begin_set(struct log_info *info) { log_free_set(info); } /* Add deleted file to log. */ int log_file_deleted(struct log_info *info, char *name) { struct log_file *file; file = (struct log_file*) malloc(sizeof(struct log_file)); if (file == 0) return 0; file->next = info->deleted; file->filename = name; info->deleted = file; return 1; } /* Add remaining file to log. */ int log_file_remaining(struct log_info *info, char *name) { struct log_file *file; file = (struct log_file*) malloc(sizeof(struct log_file)); if (file == 0) return 0; file->next = info->remaining; file->filename = name; info->remaining = file; return 1; } /* Output log header. */ void log_header(FILE *file) { fprintf(file, "%s\n", LOG_HEADER); } /* Output log timestamp. */ void log_timestamp(FILE *file) { time_t t = time(NULL); struct tm tm = *localtime(&t); fprintf(file, "Log entry for %d-%02d-%02d %02d:%02d:%02d\n\n", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); } /* Output current working directory. */ void log_cwd(FILE *file) { char *cwd = getworkingdirectory(); fprintf(file, "working directory:\n %s\n\n", cwd); free(cwd); } /* Signal the end of a duplicate set. */ void log_end_set(struct log_info *info) { struct log_file *f; if (info->deleted == 0) return; if (info->log_start) { if (info->append) fprintf(info->file, "---\n\n"); else log_header(info->file); log_timestamp(info->file); log_cwd(info->file); info->log_start = 0; } f = info->deleted; do { fprintf(info->file, "deleted %s\n", f->filename); f = f->next; } while (f != 0); f = info->remaining; while (f != 0) { fprintf(info->file, " left %s\n", f->filename); f = f->next; } fprintf(info->file, "\n"); fflush(info->file); } /* Close log and free all memory. */ void log_close(struct log_info *info) { fclose(info->file); log_free_set(info); free(info); }
4fad73d3811e6149154b949ee6ec249674836abc
0ba2e5061577f6286ff9265ef1df9aca96769445
/bubble_sort/C/Sudhanshu_Shekhar_Pandey_bubble_sort.c
85738c5558851f6f81f04aff751a99cde3accce3
[ "CC0-1.0" ]
permissive
ZoranPandovski/al-go-rithms
68d5d02f80a61de9baf8e50a81a52e7d0b3983a0
4ae6ba54e90af14af236e03e435eb0402dcac787
refs/heads/master
2023-09-04T16:04:04.321676
2023-06-06T15:22:16
2023-06-06T15:22:16
93,438,176
1,421
2,445
CC0-1.0
2023-06-15T14:24:28
2017-06-05T19:20:20
Jupyter Notebook
UTF-8
C
false
false
514
c
Sudhanshu_Shekhar_Pandey_bubble_sort.c
#include<stdio.h> void main() { int n,i,p,s,temp: printf("Enter number of elements\n"); scanf("%d",&n); int a[n]; printf("Enter elements\n"); for(i=0;i<n;i++) {scanf("%d",&a[i]);} for(p=0;p<n-1;p++) { for(s=0;s<n-p-1;s++) { if(a[s]>a[s+1]) { temp=a[s]; a[s]=a[s+1]; a[s+1]=temp; } } } printf("Sorted array is\n"); for(i=0;i<n;i++) {printf("%d",a[i]);} }
82135d5ac1058d0ed0b650a62c2f10f3aa8e7fdd
25e99a0af5751865bce1702ee85cc5c080b0715c
/gunmake/src/駕馭Makefile/Makefile/complicated/foo.h
02d9812932f785674f560cdc40b75af4085a2e5b
[]
no_license
jasonblog/note
215837f6a08d07abe3e3d2be2e1f183e14aa4a30
4471f95736c60969a718d854cab929f06726280a
refs/heads/master
2023-05-31T13:02:27.451743
2022-04-04T11:28:06
2022-04-04T11:28:06
35,311,001
130
67
null
2023-02-10T21:26:36
2015-05-09T02:04:40
C
UTF-8
C
false
false
83
h
foo.h
#ifndef __FOO_H #define __FOO_H #include "define.h" void foo (); #endif
151f9ad7cc20087be8c329054afbcbff7900c1f1
4e32ea5b4a215f427af04630e01b1312ffd31a55
/test/programs/simple/simple_setuid_test.c
1534c974d6a8f1b7b075d1886eb7e40340c4da6a
[ "Apache-2.0", "GPL-1.0-or-later" ]
permissive
sosy-lab/cpachecker
1add74cb774316dd6e1aea3fb1f352c8141466b7
1822761867d106301bda0bc99ed3cc0a25c529aa
refs/heads/trunk
2023-08-31T14:47:22.284597
2023-08-31T14:20:58
2023-08-31T14:20:58
20,107,238
186
90
Apache-2.0
2021-07-27T14:24:30
2014-05-23T16:57:37
SWIG
UTF-8
C
false
false
703
c
simple_setuid_test.c
// This file is part of CPAchecker, // a tool for configurable software verification: // https://cpachecker.sosy-lab.org // // SPDX-FileCopyrightText: 2007-2020 Dirk Beyer <https://www.sosy-lab.org> // // SPDX-License-Identifier: Apache-2.0 // testcase for simple_setuid.txt extern int someUserFunction(); extern void setuid(int); extern int system(int); main() { // some user input so CPAchecker must check all if branches int i = someUserFunction(); if (i == 0) { // this should be ok // setting the userid setuid(2); // systemcall i = system(20); } else if (i == 1) { // this should trigger an error //systemcall without setting the userid system(40); } }
1bede7ddd34850bdf0cbd8ce1166a308078f434c
d4810a0952986737223ca91458aa9770e5f2fc38
/audio/windows/openal-soft-1.18.2/Alc/backends/jack.c
ceff0b3a3fa4ba220a4d04203ee758f5ed10e3a0
[ "LGPL-2.0-only", "BSD-2-Clause" ]
permissive
g3n/engine
8bad54ec41bcffd84995bb141c7c015f37c3f381
b5c63e94be77871a78a9062f816b90d3af58b6c1
refs/heads/master
2023-08-10T17:02:06.427340
2022-06-18T15:04:41
2022-06-18T15:06:54
84,232,188
2,590
315
BSD-2-Clause
2023-06-09T12:50:46
2017-03-07T18:25:09
Go
UTF-8
C
false
false
19,504
c
jack.c
/** * OpenAL cross platform audio library * Copyright (C) 1999-2007 by authors. * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * Or go to http://www.gnu.org/copyleft/lgpl.html */ #include "config.h" #include <stdlib.h> #include <stdio.h> #include <memory.h> #include "alMain.h" #include "alu.h" #include "threads.h" #include "compat.h" #include "backends/base.h" #include <jack/jack.h> #include <jack/ringbuffer.h> static const ALCchar jackDevice[] = "JACK Default"; #ifdef HAVE_DYNLOAD #define JACK_FUNCS(MAGIC) \ MAGIC(jack_client_open); \ MAGIC(jack_client_close); \ MAGIC(jack_client_name_size); \ MAGIC(jack_get_client_name); \ MAGIC(jack_connect); \ MAGIC(jack_activate); \ MAGIC(jack_deactivate); \ MAGIC(jack_port_register); \ MAGIC(jack_port_unregister); \ MAGIC(jack_port_get_buffer); \ MAGIC(jack_port_name); \ MAGIC(jack_get_ports); \ MAGIC(jack_free); \ MAGIC(jack_get_sample_rate); \ MAGIC(jack_set_error_function); \ MAGIC(jack_set_process_callback); \ MAGIC(jack_set_buffer_size_callback); \ MAGIC(jack_set_buffer_size); \ MAGIC(jack_get_buffer_size); static void *jack_handle; #define MAKE_FUNC(f) static __typeof(f) * p##f JACK_FUNCS(MAKE_FUNC); static __typeof(jack_error_callback) * pjack_error_callback; #undef MAKE_FUNC #define jack_client_open pjack_client_open #define jack_client_close pjack_client_close #define jack_client_name_size pjack_client_name_size #define jack_get_client_name pjack_get_client_name #define jack_connect pjack_connect #define jack_activate pjack_activate #define jack_deactivate pjack_deactivate #define jack_port_register pjack_port_register #define jack_port_unregister pjack_port_unregister #define jack_port_get_buffer pjack_port_get_buffer #define jack_port_name pjack_port_name #define jack_get_ports pjack_get_ports #define jack_free pjack_free #define jack_get_sample_rate pjack_get_sample_rate #define jack_set_error_function pjack_set_error_function #define jack_set_process_callback pjack_set_process_callback #define jack_set_buffer_size_callback pjack_set_buffer_size_callback #define jack_set_buffer_size pjack_set_buffer_size #define jack_get_buffer_size pjack_get_buffer_size #define jack_error_callback (*pjack_error_callback) #endif static jack_options_t ClientOptions = JackNullOption; static ALCboolean jack_load(void) { ALCboolean error = ALC_FALSE; #ifdef HAVE_DYNLOAD if(!jack_handle) { al_string missing_funcs = AL_STRING_INIT_STATIC(); #ifdef _WIN32 #define JACKLIB "libjack.dll" #else #define JACKLIB "libjack.so.0" #endif jack_handle = LoadLib(JACKLIB); if(!jack_handle) { WARN("Failed to load %s\n", JACKLIB); return ALC_FALSE; } error = ALC_FALSE; #define LOAD_FUNC(f) do { \ p##f = GetSymbol(jack_handle, #f); \ if(p##f == NULL) { \ error = ALC_TRUE; \ alstr_append_cstr(&missing_funcs, "\n" #f); \ } \ } while(0) JACK_FUNCS(LOAD_FUNC); #undef LOAD_FUNC /* Optional symbols. These don't exist in all versions of JACK. */ #define LOAD_SYM(f) p##f = GetSymbol(jack_handle, #f) LOAD_SYM(jack_error_callback); #undef LOAD_SYM if(error) { WARN("Missing expected functions:%s\n", alstr_get_cstr(missing_funcs)); CloseLib(jack_handle); jack_handle = NULL; } alstr_reset(&missing_funcs); } #endif return !error; } typedef struct ALCjackPlayback { DERIVE_FROM_TYPE(ALCbackend); jack_client_t *Client; jack_port_t *Port[MAX_OUTPUT_CHANNELS]; ll_ringbuffer_t *Ring; alcnd_t Cond; volatile int killNow; althrd_t thread; } ALCjackPlayback; static int ALCjackPlayback_bufferSizeNotify(jack_nframes_t numframes, void *arg); static int ALCjackPlayback_process(jack_nframes_t numframes, void *arg); static int ALCjackPlayback_mixerProc(void *arg); static void ALCjackPlayback_Construct(ALCjackPlayback *self, ALCdevice *device); static void ALCjackPlayback_Destruct(ALCjackPlayback *self); static ALCenum ALCjackPlayback_open(ALCjackPlayback *self, const ALCchar *name); static void ALCjackPlayback_close(ALCjackPlayback *self); static ALCboolean ALCjackPlayback_reset(ALCjackPlayback *self); static ALCboolean ALCjackPlayback_start(ALCjackPlayback *self); static void ALCjackPlayback_stop(ALCjackPlayback *self); static DECLARE_FORWARD2(ALCjackPlayback, ALCbackend, ALCenum, captureSamples, void*, ALCuint) static DECLARE_FORWARD(ALCjackPlayback, ALCbackend, ALCuint, availableSamples) static ClockLatency ALCjackPlayback_getClockLatency(ALCjackPlayback *self); static DECLARE_FORWARD(ALCjackPlayback, ALCbackend, void, lock) static DECLARE_FORWARD(ALCjackPlayback, ALCbackend, void, unlock) DECLARE_DEFAULT_ALLOCATORS(ALCjackPlayback) DEFINE_ALCBACKEND_VTABLE(ALCjackPlayback); static void ALCjackPlayback_Construct(ALCjackPlayback *self, ALCdevice *device) { ALuint i; ALCbackend_Construct(STATIC_CAST(ALCbackend, self), device); SET_VTABLE2(ALCjackPlayback, ALCbackend, self); alcnd_init(&self->Cond); self->Client = NULL; for(i = 0;i < MAX_OUTPUT_CHANNELS;i++) self->Port[i] = NULL; self->Ring = NULL; self->killNow = 1; } static void ALCjackPlayback_Destruct(ALCjackPlayback *self) { ALuint i; if(self->Client) { for(i = 0;i < MAX_OUTPUT_CHANNELS;i++) { if(self->Port[i]) jack_port_unregister(self->Client, self->Port[i]); self->Port[i] = NULL; } jack_client_close(self->Client); self->Client = NULL; } alcnd_destroy(&self->Cond); ALCbackend_Destruct(STATIC_CAST(ALCbackend, self)); } static int ALCjackPlayback_bufferSizeNotify(jack_nframes_t numframes, void *arg) { ALCjackPlayback *self = arg; ALCdevice *device = STATIC_CAST(ALCbackend,self)->mDevice; ALuint bufsize; ALCjackPlayback_lock(self); device->UpdateSize = numframes; device->NumUpdates = 2; bufsize = device->UpdateSize; if(ConfigValueUInt(alstr_get_cstr(device->DeviceName), "jack", "buffer-size", &bufsize)) bufsize = maxu(NextPowerOf2(bufsize), device->UpdateSize); bufsize += device->UpdateSize; device->NumUpdates = bufsize / device->UpdateSize; TRACE("%u update size x%u\n", device->UpdateSize, device->NumUpdates); ll_ringbuffer_free(self->Ring); self->Ring = ll_ringbuffer_create(bufsize, FrameSizeFromDevFmt(device->FmtChans, device->FmtType, device->AmbiOrder) ); if(!self->Ring) { ERR("Failed to reallocate ringbuffer\n"); aluHandleDisconnect(device); } ALCjackPlayback_unlock(self); return 0; } static int ALCjackPlayback_process(jack_nframes_t numframes, void *arg) { ALCjackPlayback *self = arg; jack_default_audio_sample_t *out[MAX_OUTPUT_CHANNELS]; ll_ringbuffer_data_t data[2]; jack_nframes_t total = 0; jack_nframes_t todo; ALsizei i, c, numchans; ll_ringbuffer_get_read_vector(self->Ring, data); for(c = 0;c < MAX_OUTPUT_CHANNELS && self->Port[c];c++) out[c] = jack_port_get_buffer(self->Port[c], numframes); numchans = c; todo = minu(numframes, data[0].len); for(c = 0;c < numchans;c++) { const ALfloat *restrict in = ((ALfloat*)data[0].buf) + c; for(i = 0;(jack_nframes_t)i < todo;i++) out[c][i] = in[i*numchans]; out[c] += todo; } total += todo; todo = minu(numframes-total, data[1].len); if(todo > 0) { for(c = 0;c < numchans;c++) { const ALfloat *restrict in = ((ALfloat*)data[1].buf) + c; for(i = 0;(jack_nframes_t)i < todo;i++) out[c][i] = in[i*numchans]; out[c] += todo; } total += todo; } ll_ringbuffer_read_advance(self->Ring, total); alcnd_signal(&self->Cond); if(numframes > total) { todo = numframes-total; for(c = 0;c < numchans;c++) { for(i = 0;(jack_nframes_t)i < todo;i++) out[c][i] = 0.0f; } } return 0; } static int ALCjackPlayback_mixerProc(void *arg) { ALCjackPlayback *self = arg; ALCdevice *device = STATIC_CAST(ALCbackend,self)->mDevice; ll_ringbuffer_data_t data[2]; SetRTPriority(); althrd_setname(althrd_current(), MIXER_THREAD_NAME); ALCjackPlayback_lock(self); while(!self->killNow && device->Connected) { ALuint todo, len1, len2; /* NOTE: Unfortunately, there is an unavoidable race condition here. * It's possible for the process() method to run, updating the read * pointer and signaling the condition variable, in between the mixer * loop checking the write size and waiting for the condition variable. * This will cause the mixer loop to wait until the *next* process() * invocation, most likely writing silence for it. * * However, this should only happen if the mixer is running behind * anyway (as ideally we'll be asleep in alcnd_wait by the time the * process() method is invoked), so this behavior is not unwarranted. * It's unfortunate since it'll be wasting time sleeping that could be * used to catch up, but there's no way around it without blocking in * the process() method. */ if(ll_ringbuffer_write_space(self->Ring) < device->UpdateSize) { alcnd_wait(&self->Cond, &STATIC_CAST(ALCbackend,self)->mMutex); continue; } ll_ringbuffer_get_write_vector(self->Ring, data); todo = data[0].len + data[1].len; todo -= todo%device->UpdateSize; len1 = minu(data[0].len, todo); len2 = minu(data[1].len, todo-len1); aluMixData(device, data[0].buf, len1); if(len2 > 0) aluMixData(device, data[1].buf, len2); ll_ringbuffer_write_advance(self->Ring, todo); } ALCjackPlayback_unlock(self); return 0; } static ALCenum ALCjackPlayback_open(ALCjackPlayback *self, const ALCchar *name) { ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice; const char *client_name = "alsoft"; jack_status_t status; if(!name) name = jackDevice; else if(strcmp(name, jackDevice) != 0) return ALC_INVALID_VALUE; self->Client = jack_client_open(client_name, ClientOptions, &status, NULL); if(self->Client == NULL) { ERR("jack_client_open() failed, status = 0x%02x\n", status); return ALC_INVALID_VALUE; } if((status&JackServerStarted)) TRACE("JACK server started\n"); if((status&JackNameNotUnique)) { client_name = jack_get_client_name(self->Client); TRACE("Client name not unique, got `%s' instead\n", client_name); } jack_set_process_callback(self->Client, ALCjackPlayback_process, self); jack_set_buffer_size_callback(self->Client, ALCjackPlayback_bufferSizeNotify, self); alstr_copy_cstr(&device->DeviceName, name); return ALC_NO_ERROR; } static void ALCjackPlayback_close(ALCjackPlayback *self) { ALuint i; for(i = 0;i < MAX_OUTPUT_CHANNELS;i++) { if(self->Port[i]) jack_port_unregister(self->Client, self->Port[i]); self->Port[i] = NULL; } jack_client_close(self->Client); self->Client = NULL; } static ALCboolean ALCjackPlayback_reset(ALCjackPlayback *self) { ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice; ALsizei numchans, i; ALuint bufsize; for(i = 0;i < MAX_OUTPUT_CHANNELS;i++) { if(self->Port[i]) jack_port_unregister(self->Client, self->Port[i]); self->Port[i] = NULL; } /* Ignore the requested buffer metrics and just keep one JACK-sized buffer * ready for when requested. Note that one period's worth of audio in the * ring buffer will always be left unfilled because one element of the ring * buffer will not be writeable, and we only write in period-sized chunks. */ device->Frequency = jack_get_sample_rate(self->Client); device->UpdateSize = jack_get_buffer_size(self->Client); device->NumUpdates = 2; bufsize = device->UpdateSize; if(ConfigValueUInt(alstr_get_cstr(device->DeviceName), "jack", "buffer-size", &bufsize)) bufsize = maxu(NextPowerOf2(bufsize), device->UpdateSize); bufsize += device->UpdateSize; device->NumUpdates = bufsize / device->UpdateSize; /* Force 32-bit float output. */ device->FmtType = DevFmtFloat; numchans = ChannelsFromDevFmt(device->FmtChans, device->AmbiOrder); for(i = 0;i < numchans;i++) { char name[64]; snprintf(name, sizeof(name), "channel_%d", i+1); self->Port[i] = jack_port_register(self->Client, name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); if(self->Port[i] == NULL) { ERR("Not enough JACK ports available for %s output\n", DevFmtChannelsString(device->FmtChans)); if(i == 0) return ALC_FALSE; break; } } if(i < numchans) { if(i == 1) device->FmtChans = DevFmtMono; else { for(--i;i >= 2;i--) { jack_port_unregister(self->Client, self->Port[i]); self->Port[i] = NULL; } device->FmtChans = DevFmtStereo; } } ll_ringbuffer_free(self->Ring); self->Ring = ll_ringbuffer_create(bufsize, FrameSizeFromDevFmt(device->FmtChans, device->FmtType, device->AmbiOrder) ); if(!self->Ring) { ERR("Failed to allocate ringbuffer\n"); return ALC_FALSE; } SetDefaultChannelOrder(device); return ALC_TRUE; } static ALCboolean ALCjackPlayback_start(ALCjackPlayback *self) { const char **ports; ALsizei i; if(jack_activate(self->Client)) { ERR("Failed to activate client\n"); return ALC_FALSE; } ports = jack_get_ports(self->Client, NULL, NULL, JackPortIsPhysical|JackPortIsInput); if(ports == NULL) { ERR("No physical playback ports found\n"); jack_deactivate(self->Client); return ALC_FALSE; } for(i = 0;i < MAX_OUTPUT_CHANNELS && self->Port[i];i++) { if(!ports[i]) { ERR("No physical playback port for \"%s\"\n", jack_port_name(self->Port[i])); break; } if(jack_connect(self->Client, jack_port_name(self->Port[i]), ports[i])) ERR("Failed to connect output port \"%s\" to \"%s\"\n", jack_port_name(self->Port[i]), ports[i]); } jack_free(ports); self->killNow = 0; if(althrd_create(&self->thread, ALCjackPlayback_mixerProc, self) != althrd_success) { jack_deactivate(self->Client); return ALC_FALSE; } return ALC_TRUE; } static void ALCjackPlayback_stop(ALCjackPlayback *self) { int res; if(self->killNow) return; self->killNow = 1; /* Lock the backend to ensure we don't flag the mixer to die and signal the * mixer to wake up in between it checking the flag and going to sleep and * wait for a wakeup (potentially leading to it never waking back up to see * the flag). */ ALCjackPlayback_lock(self); ALCjackPlayback_unlock(self); alcnd_signal(&self->Cond); althrd_join(self->thread, &res); jack_deactivate(self->Client); } static ClockLatency ALCjackPlayback_getClockLatency(ALCjackPlayback *self) { ALCdevice *device = STATIC_CAST(ALCbackend, self)->mDevice; ClockLatency ret; ALCjackPlayback_lock(self); ret.ClockTime = GetDeviceClockTime(device); ret.Latency = ll_ringbuffer_read_space(self->Ring) * DEVICE_CLOCK_RES / device->Frequency; ALCjackPlayback_unlock(self); return ret; } static void jack_msg_handler(const char *message) { WARN("%s\n", message); } typedef struct ALCjackBackendFactory { DERIVE_FROM_TYPE(ALCbackendFactory); } ALCjackBackendFactory; #define ALCJACKBACKENDFACTORY_INITIALIZER { { GET_VTABLE2(ALCjackBackendFactory, ALCbackendFactory) } } static ALCboolean ALCjackBackendFactory_init(ALCjackBackendFactory* UNUSED(self)) { void (*old_error_cb)(const char*); jack_client_t *client; jack_status_t status; if(!jack_load()) return ALC_FALSE; if(!GetConfigValueBool(NULL, "jack", "spawn-server", 0)) ClientOptions |= JackNoStartServer; old_error_cb = (&jack_error_callback ? jack_error_callback : NULL); jack_set_error_function(jack_msg_handler); client = jack_client_open("alsoft", ClientOptions, &status, NULL); jack_set_error_function(old_error_cb); if(client == NULL) { WARN("jack_client_open() failed, 0x%02x\n", status); if((status&JackServerFailed) && !(ClientOptions&JackNoStartServer)) ERR("Unable to connect to JACK server\n"); return ALC_FALSE; } jack_client_close(client); return ALC_TRUE; } static void ALCjackBackendFactory_deinit(ALCjackBackendFactory* UNUSED(self)) { #ifdef HAVE_DYNLOAD if(jack_handle) CloseLib(jack_handle); jack_handle = NULL; #endif } static ALCboolean ALCjackBackendFactory_querySupport(ALCjackBackendFactory* UNUSED(self), ALCbackend_Type type) { if(type == ALCbackend_Playback) return ALC_TRUE; return ALC_FALSE; } static void ALCjackBackendFactory_probe(ALCjackBackendFactory* UNUSED(self), enum DevProbe type) { switch(type) { case ALL_DEVICE_PROBE: AppendAllDevicesList(jackDevice); break; case CAPTURE_DEVICE_PROBE: break; } } static ALCbackend* ALCjackBackendFactory_createBackend(ALCjackBackendFactory* UNUSED(self), ALCdevice *device, ALCbackend_Type type) { if(type == ALCbackend_Playback) { ALCjackPlayback *backend; NEW_OBJ(backend, ALCjackPlayback)(device); if(!backend) return NULL; return STATIC_CAST(ALCbackend, backend); } return NULL; } DEFINE_ALCBACKENDFACTORY_VTABLE(ALCjackBackendFactory); ALCbackendFactory *ALCjackBackendFactory_getFactory(void) { static ALCjackBackendFactory factory = ALCJACKBACKENDFACTORY_INITIALIZER; return STATIC_CAST(ALCbackendFactory, &factory); }
697251eb7b6a8c763fbbae3d3c8abfeb2766cab5
6f75c727e7b359efac7b1d46d8962c405ab85b0b
/resources/tests/c-testsuite/00107.c
fb608eb7881ef4089d414cdc52ed36d67c330330
[ "MIT" ]
permissive
SwadicalRag/wasm2lua
67e9ccac579747e39940d56d822a74913a9d956c
00f26cce8880ec993d591951d2e9fb06f9c52f8a
refs/heads/master
2022-01-02T02:37:47.559463
2021-12-14T11:41:58
2021-12-14T11:41:58
183,629,989
169
11
MIT
2021-12-14T20:25:24
2019-04-26T13:05:18
WebAssembly
UTF-8
C
false
false
72
c
00107.c
typedef int myint; myint x = (myint)1; int main(void) { return x-1; }
b761a6c3db1d79ee8277a1a8ab644e5f425f97b3
331640994b1b6f66c1639278571ddbdc6c8c0751
/src/nxt_buf.h
f1e2879f2b0094d5f9c26fc3845ccc19d2c4740f
[ "Apache-2.0" ]
permissive
nginx/unit
eabcd067eaa60f4bdcf0cfaffe7d9932add2c66a
9b22b6957bc87b3df002d0bc691fdae6a20abdac
refs/heads/master
2023-09-04T02:02:13.581700
2023-08-30T16:07:24
2023-08-30T16:07:24
102,627,638
4,649
452
Apache-2.0
2023-09-12T01:28:22
2017-09-06T15:45:30
C
UTF-8
C
false
false
9,139
h
nxt_buf.h
/* * Copyright (C) Igor Sysoev * Copyright (C) NGINX, Inc. */ #ifndef _NXT_BUF_H_INCLUDED_ #define _NXT_BUF_H_INCLUDED_ /* * There are four types of buffers. They are different sizes, so they * should be allocated by appropriate nxt_buf_XXX_alloc() function. * * 1) Memory-only buffers, their size is less than nxt_buf_t size, it * is equal to offsetof(nxt_buf_t, file_pos), that is it is nxt_buf_t * without file and mmap part. The buffers are frequently used, so * the reduction allows to save 20-32 bytes depending on platform. * * 2) Memory/file buffers, on Unix their size is exactly nxt_buf_t size, * since nxt_mem_map_file_ctx_t() is empty macro. On Windows the size * equals offsetof(nxt_buf_t, mmap), that is it is nxt_buf_t without * memory map context part. The buffers can contain both memory and * file pointers at once, or only memory or file pointers. * * 3) Memory mapped buffers are similar to the memory/file buffers. Their * size is exactly nxt_buf_t size. The buffers can contain both memory * and file pointers at once, or only memory or file pointers. If a * buffer is not currently mapped in memory, its mapping size is stored * in the mem.end field and available via nxt_buf_mem_size() macro. * * 4) Sync buffers, their size is the same size as memory-only buffers * size. A sync buffer can be smaller but for memory pool cache * purpose it is better to allocate it as frequently used memory-only * buffer. The buffers are used to synchronize pipeline processing * completion, because data buffers in the pipeline can be completed * and freed before their final output will even be passed to a peer. * For this purpose a sync buffer is allocated with the stop flag which * stops buffer chain completion processing on the sync buffer in * nxt_sendbuf_update() and nxt_sendbuf_completion(). * Clearing the stop flag allows to continue completion processing. * * The last flag means the end of the output and must be set only * in a sync buffer. The last flag is not permitted in memory and * file buffers since it requires special handling while conversion * one buffer to another. * * The nxt_buf_used_size() macro treats a sync buffer as a memory-only * buffer which has NULL pointers, thus the buffer content size is zero. * If allocated size of sync buffer would be lesser than memory-only * buffer, then the special memory flag would be required because * currently presence of memory part is indicated by non-NULL pointer * to a content in memory. * * All types of buffers can have the flush flag that means the buffer * should be sent as much as possible. */ typedef struct { u_char *pos; u_char *free; u_char *start; u_char *end; } nxt_buf_mem_t; struct nxt_buf_s { void *data; nxt_work_handler_t completion_handler; void *parent; /* * The next link, flags, and nxt_buf_mem_t should * reside together to improve cache locality. */ nxt_buf_t *next; uint32_t retain; uint8_t cache_hint; uint8_t is_file:1; uint8_t is_mmap:1; uint8_t is_port_mmap:1; uint8_t is_sync:1; uint8_t is_nobuf:1; uint8_t is_flush:1; uint8_t is_last:1; uint8_t is_port_mmap_sent:1; uint8_t is_ts:1; nxt_buf_mem_t mem; /* The file and mmap parts are not allocated by nxt_buf_mem_alloc(). */ nxt_file_t *file; nxt_off_t file_pos; nxt_off_t file_end; /* The mmap part is not allocated by nxt_buf_file_alloc(). */ nxt_mem_map_file_ctx_t (mmap) }; #define NXT_BUF_SYNC_SIZE offsetof(nxt_buf_t, mem.free) #define NXT_BUF_MEM_SIZE offsetof(nxt_buf_t, file) #define NXT_BUF_FILE_SIZE sizeof(nxt_buf_t) #define NXT_BUF_MMAP_SIZE NXT_BUF_FILE_SIZE #define NXT_BUF_PORT_MMAP_SIZE NXT_BUF_MEM_SIZE #define NXT_BUF_SYNC_NOBUF 1 #define NXT_BUF_SYNC_FLUSH 2 #define NXT_BUF_SYNC_LAST 4 #define nxt_buf_is_mem(b) \ ((b)->mem.pos != NULL) #define nxt_buf_is_file(b) \ ((b)->is_file) #define nxt_buf_set_file(b) \ (b)->is_file = 1 #define nxt_buf_clear_file(b) \ (b)->is_file = 0 #define nxt_buf_is_mmap(b) \ ((b)->is_mmap) #define nxt_buf_set_mmap(b) \ (b)->is_mmap = 1 #define nxt_buf_clear_mmap(b) \ (b)->is_mmap = 0 #define nxt_buf_is_port_mmap(b) \ ((b)->is_port_mmap) #define nxt_buf_set_port_mmap(b) \ (b)->is_port_mmap = 1 #define nxt_buf_clear_port_mmap(b) \ (b)->is_port_mmap = 0 #define nxt_buf_is_sync(b) \ ((b)->is_sync) #define nxt_buf_set_sync(b) \ (b)->is_sync = 1 #define nxt_buf_clear_sync(b) \ (b)->is_sync = 0 #define nxt_buf_is_nobuf(b) \ ((b)->is_nobuf) #define nxt_buf_set_nobuf(b) \ (b)->is_nobuf = 1 #define nxt_buf_clear_nobuf(b) \ (b)->is_nobuf = 0 #define nxt_buf_is_flush(b) \ ((b)->is_flush) #define nxt_buf_set_flush(b) \ (b)->is_flush = 1 #define nxt_buf_clear_flush(b) \ (b)->is_flush = 0 #define nxt_buf_is_last(b) \ ((b)->is_last) #define nxt_buf_set_last(b) \ (b)->is_last = 1 #define nxt_buf_clear_last(b) \ (b)->is_last = 0 #define nxt_buf_mem_set_size(bm, size) \ do { \ (bm)->start = 0; \ (bm)->end = (void *) size; \ } while (0) #define nxt_buf_mem_size(bm) \ ((bm)->end - (bm)->start) #define nxt_buf_mem_used_size(bm) \ ((bm)->free - (bm)->pos) #define nxt_buf_mem_free_size(bm) \ ((bm)->end - (bm)->free) #define nxt_buf_used_size(b) \ (nxt_buf_is_file(b) ? (b)->file_end - (b)->file_pos: \ nxt_buf_mem_used_size(&(b)->mem)) NXT_EXPORT void nxt_buf_mem_init(nxt_buf_t *b, void *start, size_t size); NXT_EXPORT nxt_buf_t *nxt_buf_mem_alloc(nxt_mp_t *mp, size_t size, nxt_uint_t flags); NXT_EXPORT nxt_buf_t *nxt_buf_mem_ts_alloc(nxt_task_t *task, nxt_mp_t *mp, size_t size); NXT_EXPORT nxt_buf_t *nxt_buf_file_alloc(nxt_mp_t *mp, size_t size, nxt_uint_t flags); NXT_EXPORT nxt_buf_t *nxt_buf_mmap_alloc(nxt_mp_t *mp, size_t size); NXT_EXPORT nxt_buf_t *nxt_buf_sync_alloc(nxt_mp_t *mp, nxt_uint_t flags); NXT_EXPORT nxt_int_t nxt_buf_ts_handle(nxt_task_t *task, void *obj, void *data); NXT_EXPORT void nxt_buf_parent_completion(nxt_task_t *task, nxt_buf_t *parent); NXT_EXPORT nxt_buf_t *nxt_buf_make_plain(nxt_mp_t *mp, nxt_buf_t *src, size_t size); nxt_inline nxt_buf_t * nxt_buf_chk_make_plain(nxt_mp_t *mp, nxt_buf_t *src, size_t size) { if (nxt_slow_path(src != NULL && src->next != NULL)) { return nxt_buf_make_plain(mp, src, size); } return src; } #define nxt_buf_free(mp, b) \ nxt_mp_free((mp), (b)) NXT_EXPORT void nxt_buf_chain_add(nxt_buf_t **head, nxt_buf_t *in); NXT_EXPORT size_t nxt_buf_chain_length(nxt_buf_t *b); nxt_inline nxt_buf_t * nxt_buf_cpy(nxt_buf_t *b, const void *src, size_t length) { nxt_memcpy(b->mem.free, src, length); b->mem.free += length; return b; } nxt_inline nxt_buf_t * nxt_buf_cpystr(nxt_buf_t *b, const nxt_str_t *str) { return nxt_buf_cpy(b, str->start, str->length); } nxt_inline void nxt_buf_dummy_completion(nxt_task_t *task, void *obj, void *data) { } #endif /* _NXT_BUF_H_INCLIDED_ */
7820932ba7c9922a0aad3ebc30cb8278bfbfce60
e48198ffea7b0b80669253fb970fdcc1d2f4c518
/src/proto/vim9instr.pro
1ba5639a562bf53db8660b1a0381631a40d9dded
[ "GPL-1.0-or-later", "Vim", "GPL-2.0-only" ]
permissive
vim/vim
f9ea5913ff884c87bc11f7826b1fc277fba8a2b5
816fbcc262687b81fc46f82f7bbeb1453addfe0c
refs/heads/master
2023-09-01T16:01:56.964678
2023-08-31T21:52:30
2023-08-31T21:52:30
40,997,482
37,589
7,920
Vim
2023-09-14T20:57:43
2015-08-18T21:03:56
Vim Script
UTF-8
C
false
false
5,401
pro
vim9instr.pro
/* vim9instr.c */ isn_T *generate_instr(cctx_T *cctx, isntype_T isn_type); isn_T *generate_instr_drop(cctx_T *cctx, isntype_T isn_type, int drop); isn_T *generate_instr_type(cctx_T *cctx, isntype_T isn_type, type_T *type); isn_T *generate_instr_debug(cctx_T *cctx); int generate_CONSTRUCT(cctx_T *cctx, class_T *cl); int generate_GET_OBJ_MEMBER(cctx_T *cctx, int idx, type_T *type); int generate_GET_ITF_MEMBER(cctx_T *cctx, class_T *itf, int idx, type_T *type); int generate_STORE_THIS(cctx_T *cctx, int idx); int may_generate_2STRING(int offset, int tolerant, cctx_T *cctx); int generate_add_instr(cctx_T *cctx, vartype_T vartype, type_T *type1, type_T *type2, exprtype_T expr_type); vartype_T operator_type(type_T *type1, type_T *type2); int generate_two_op(cctx_T *cctx, char_u *op); int check_compare_types(exprtype_T type, typval_T *tv1, typval_T *tv2); int generate_COMPARE(cctx_T *cctx, exprtype_T exprtype, int ic); int generate_CONCAT(cctx_T *cctx, int count); int generate_2BOOL(cctx_T *cctx, int invert, int offset); int generate_COND2BOOL(cctx_T *cctx); int generate_TYPECHECK(cctx_T *cctx, type_T *expected, int number_ok, int offset, int is_var, int argidx); int generate_SETTYPE(cctx_T *cctx, type_T *expected); int generate_tv_PUSH(cctx_T *cctx, typval_T *tv); int generate_PUSHNR(cctx_T *cctx, varnumber_T number); int generate_PUSHBOOL(cctx_T *cctx, varnumber_T number); int generate_PUSHSPEC(cctx_T *cctx, varnumber_T number); int generate_PUSHF(cctx_T *cctx, float_T fnumber); int generate_PUSHS(cctx_T *cctx, char_u **str); int generate_PUSHCHANNEL(cctx_T *cctx); int generate_PUSHJOB(cctx_T *cctx); int generate_PUSHBLOB(cctx_T *cctx, blob_T *blob); int generate_PUSHFUNC(cctx_T *cctx, char_u *name, type_T *type, int may_prefix); int generate_PUSHOBJ(cctx_T *cctx); int generate_AUTOLOAD(cctx_T *cctx, char_u *name, type_T *type); int generate_GETITEM(cctx_T *cctx, int index, int with_op); int generate_SLICE(cctx_T *cctx, int count); int generate_CHECKLEN(cctx_T *cctx, int min_len, int more_OK); int generate_STORE(cctx_T *cctx, isntype_T isn_type, int idx, char_u *name); int generate_CLASSMEMBER(cctx_T *cctx, int load, class_T *cl, int idx); int generate_STORENR(cctx_T *cctx, int idx, varnumber_T value); int generate_LOAD(cctx_T *cctx, isntype_T isn_type, int idx, char_u *name, type_T *type); int generate_LOADOUTER(cctx_T *cctx, int idx, int nesting, int loop_depth, int loop_idx, type_T *type); int generate_LOADV(cctx_T *cctx, char_u *name); int generate_UNLET(cctx_T *cctx, isntype_T isn_type, char_u *name, int forceit); int generate_LOCKCONST(cctx_T *cctx); int generate_OLDSCRIPT(cctx_T *cctx, isntype_T isn_type, char_u *name, int sid, type_T *type); int generate_VIM9SCRIPT(cctx_T *cctx, isntype_T isn_type, int sid, int idx, type_T *type); int generate_NEWLIST(cctx_T *cctx, int count, int use_null); int generate_NEWDICT(cctx_T *cctx, int count, int use_null); int generate_FUNCREF(cctx_T *cctx, ufunc_T *ufunc, class_T *cl, int fi, isn_T **isnp); int generate_NEWFUNC(cctx_T *cctx, char_u *lambda_name, char_u *func_name); int generate_DEF(cctx_T *cctx, char_u *name, size_t len); int generate_JUMP(cctx_T *cctx, jumpwhen_T when, int where); int generate_WHILE(cctx_T *cctx, int funcref_idx); int generate_JUMP_IF_ARG(cctx_T *cctx, isntype_T isn_type, int arg_off); int generate_FOR(cctx_T *cctx, int loop_idx); int generate_ENDLOOP(cctx_T *cctx, loop_info_T *loop_info); int generate_TRYCONT(cctx_T *cctx, int levels, int where); int check_internal_func_args(cctx_T *cctx, int func_idx, int argcount, int method_call, type2_T **argtypes, type2_T *shuffled_argtypes); int generate_BCALL(cctx_T *cctx, int func_idx, int argcount, int method_call); int generate_LISTAPPEND(cctx_T *cctx); int generate_BLOBAPPEND(cctx_T *cctx); int generate_CALL(cctx_T *cctx, ufunc_T *ufunc, class_T *cl, int mi, type_T *mtype, int pushed_argcount); int generate_UCALL(cctx_T *cctx, char_u *name, int argcount); int check_func_args_from_type(cctx_T *cctx, type_T *type, int argcount, int at_top, char_u *name); int generate_PCALL(cctx_T *cctx, int argcount, char_u *name, type_T *type, int at_top); int generate_DEFER(cctx_T *cctx, int var_idx, int obj_method, int argcount); int generate_STRINGMEMBER(cctx_T *cctx, char_u *name, size_t len); int generate_ECHO(cctx_T *cctx, int with_white, int count); int generate_MULT_EXPR(cctx_T *cctx, isntype_T isn_type, int count); int generate_ECHOWINDOW(cctx_T *cctx, int count, long time); int generate_SOURCE(cctx_T *cctx, int sid); int generate_PUT(cctx_T *cctx, int regname, linenr_T lnum); int generate_EXEC_copy(cctx_T *cctx, isntype_T isntype, char_u *line); int generate_EXEC(cctx_T *cctx, isntype_T isntype, char_u *str); int generate_LEGACY_EVAL(cctx_T *cctx, char_u *line); int generate_EXECCONCAT(cctx_T *cctx, int count); int generate_RANGE(cctx_T *cctx, char_u *range); int generate_UNPACK(cctx_T *cctx, int var_count, int semicolon); int generate_cmdmods(cctx_T *cctx, cmdmod_T *cmod); int generate_undo_cmdmods(cctx_T *cctx); int generate_store_var(cctx_T *cctx, assign_dest_T dest, int opt_flags, int vimvaridx, type_T *type, char_u *name, lhs_T *lhs); int inside_loop_scope(cctx_T *cctx); int generate_store_lhs(cctx_T *cctx, lhs_T *lhs, int instr_count, int is_decl); void may_generate_prof_end(cctx_T *cctx, int prof_lnum); void delete_instr(isn_T *isn); void clear_instr_ga(garray_T *gap); /* vim: set ft=c : */
74a5916db5b8902ede7cd246f3d782476c2d6170
6923f79f1eaaba0ab28b25337ba6cb56be97d32d
/GPU-Gems-Book-Source-Code/GPU-Gems-3-CD-Content/content/33/source/gridlib/GbMatrix3.C
adacd5fdfd82953192295667aaff7ade37ad1df4
[]
no_license
burakbayramli/books
9fe7ba0cabf06e113eb125d62fe16d4946f4a4f0
5e9a0e03aa7ddf5e5ddf89943ccc68d94b539e95
refs/heads/master
2023-08-17T05:31:08.885134
2023-08-14T10:05:37
2023-08-14T10:05:37
72,460,321
223
174
null
2022-10-24T12:15:06
2016-10-31T17:24:00
Jupyter Notebook
UTF-8
C
false
false
1,528
c
GbMatrix3.C
#ifdef USE_RCSID static const char RCSid_GbMatrix3[] = "$Id: GbMatrix3.C,v 1.3 2003/03/06 17:01:52 prkipfer Exp $"; #endif #ifdef OUTLINE #include "GbMatrix3.hh" #include "GbMatrix3.in" #include "GbMatrix3.T" // instantiate templates template class GRIDLIB_API GbMatrix3<float>; template class GRIDLIB_API GbMatrix3<double>; // instantiate friends template GRIDLIB_API GbVec3<float> operator* (const GbVec3<float>& v, const GbMatrix3<float>& m); template GRIDLIB_API GbVec3<double> operator* (const GbVec3<double>& v, const GbMatrix3<double>& m); template GRIDLIB_API std::ostream& operator<<(std::ostream&, const GbMatrix3<float>&); template GRIDLIB_API std::ostream& operator<<(std::ostream&, const GbMatrix3<double>&); template GRIDLIB_API std::istream& operator>>(std::istream&, GbMatrix3<float>&) ; template GRIDLIB_API std::istream& operator>>(std::istream&, GbMatrix3<double>&); // initialize static consts #if 0 def WIN32 const float GbMatrix3<float>::EPSILON = std::numeric_limits<float>::epsilon(); const GbMatrix3<float> GbMatrix3<float>::ZERO = GbMatrix3<float>(0.f,0.f,0.f, 0.f,0.f,0.f, 0.f,0.f,0.f); const GbMatrix3<float> GbMatrix3<float>::IDENTITY = GbMatrix3<float>(1.f,0.f,0.f, 0.f,1.f,0.f, 0.f,0.f,1.f); const double GbMatrix3<double>::EPSILON = std::numeric_limits<double>::epsilon(); const GbMatrix3<double> GbMatrix3<double>::ZERO = GbMatrix3<double>(0.,0.,0., 0.,0.,0., 0.,0.,0.); const GbMatrix3<double> GbMatrix3<double>::IDENTITY= GbMatrix3<double>(1.,0.,0., 0.,1.,0., 0.,0.,1.); #endif #endif