/* * Dummy function for checking memset's arguments. */ void *_dmalloc_memset(const char *file, const int line, void *buf, const int ch, const DMALLOC_SIZE len) { if (BIT_IS_SET(_dmalloc_flags, DEBUG_CHECK_FUNCS)) { if (! dmalloc_verify_pnt(file, line, "memset", buf, 0 /* not exact */, len)) { dmalloc_message("bad pointer argument found in memset"); } } return (void *)memset(buf, ch, len); }
/* * Dummy function for checking strrchr's arguments. */ char *_dmalloc_strrchr(const char *file, const int line, const char *str, const int ch) { if (BIT_IS_SET(_dmalloc_flags, DEBUG_CHECK_FUNCS)) { if (! dmalloc_verify_pnt(file, line, "strrchr", str, 0 /* not exact */, -1)) { dmalloc_message("bad pointer argument found in strrchr"); } } return (char *)strrchr(str, ch); }
/* * Dummy function for checking bzero's arguments. */ void _dmalloc_bzero(const char *file, const int line, void *buf, const DMALLOC_SIZE len) { if (BIT_IS_SET(_dmalloc_flags, DEBUG_CHECK_FUNCS)) { if (! dmalloc_verify_pnt(file, line, "bzero", buf, 0 /* not exact */, len)) { dmalloc_message("bad pointer argument found in bzero"); } } bzero(buf, len); }
int PIR_detectMotion(void) { if(BIT_IS_SET(INPUTPORT,INPUTPIN1)) { return 1; } else if(BIT_IS_SET(INPUTPORT,INPUTPIN2)) { return 2; } else if(BIT_IS_SET(INPUTPORT,INPUTPIN3)) { return 3; } else { return NOTHING; } }
/********************************************** * 关闭定时器,并取消触发事件 */ static void timing_cell_stop(unsigned int index) { if(index >= TIMING100MS_EVENT_BASE && index < (TIMING100MS_EVENT_BASE+TIMING100MS_EVENT_COUNT)) { TIM100MS_ARRAYS_T * ptiming = &tim100ms_arrys; index -= TIMING100MS_EVENT_BASE; if(BIT_IS_SET(ptiming->enable_bits,index)) { if(THIS_INFO)printf("stop timeimg 100ms :%d\r\n",index); SET_BIT(ptiming->enable_bits, index,0); } } else if(index >= TIMING1S_EVENT_BASE && index < (TIMING1S_EVENT_BASE+TIMING1S_EVENT_COUNT)) { TIM1S_ARRAYS_T * ptiming = &tim1s_arrys; index -= TIMING1S_EVENT_BASE; if(BIT_IS_SET(ptiming->enable_bits,index)) { if(THIS_INFO)printf("stop timeimg 1s :%d\r\n",index); SET_BIT(ptiming->enable_bits, index,0); } } else { if(THIS_ERROR)printf("timing stop error:%d\r\n",index); handle_plc_command_error(); } }
/* * ctree_find -- searches for a key in the tree */ uint64_t ctree_find(struct ctree *t, uint64_t key) { uint64_t *dst = t->root; struct node *a = NULL; while (NODE_IS_INTERNAL(dst)) { a = NODE_INTERNAL_GET(dst); dst = a->slots[BIT_IS_SET(key, a->diff)]; } return dst ? *dst : 0; }
/* * Dummy function for checking strlen's arguments. */ DMALLOC_SIZE _dmalloc_strlen(const char *file, const int line, const char *str) { if (BIT_IS_SET(_dmalloc_flags, DEBUG_CHECK_FUNCS)) { if (! dmalloc_verify_pnt(file, line, "strlen", str, 0 /* not exact */, -1)) { dmalloc_message("bad pointer argument found in strlen"); } } return loc_strlen(file, line, "strlen", str); }
static unsigned char get_last_bitval(unsigned int index) { unsigned char idata bitval = TIMING100MS_EVENT_BASE; if(index >= IO_INPUT_BASE && index < (IO_INPUT_BASE+IO_INPUT_COUNT)) { index -= IO_INPUT_BASE; bitval = BIT_IS_SET(inputs_last,index); } else if(index >= IO_OUTPUT_BASE && index < (IO_OUTPUT_BASE+IO_OUTPUT_COUNT)) { index -= IO_OUTPUT_BASE; bitval = BIT_IS_SET(output_last,index); } else if(index >= AUXI_RELAY_BASE && index < (AUXI_RELAY_BASE + AUXI_RELAY_COUNT)) { index -= AUXI_RELAY_BASE; bitval = BIT_IS_SET(auxi_relays_last,index); } else if(index >= TIMING100MS_EVENT_BASE && index < (TIMING100MS_EVENT_BASE+TIMING100MS_EVENT_COUNT)) { index -= TIMING100MS_EVENT_BASE; bitval = BIT_IS_SET(tim100ms_arrys.event_bits_last,index); } else if(index >= TIMING1S_EVENT_BASE && index < (TIMING1S_EVENT_BASE + TIMING1S_EVENT_COUNT)) { index -= TIMING1S_EVENT_BASE; bitval = BIT_IS_SET(tim1s_arrys.event_bits_last,index); } else if(index >= COUNTER_EVENT_BASE && index < (COUNTER_EVENT_BASE+COUNTER_EVENT_COUNT)) { index -= COUNTER_EVENT_BASE; bitval = BIT_IS_SET(counter_arrys.event_bits_last,index); } else { if(THIS_ERROR)printf("get bit index error:%d\r\n",index); handle_plc_command_error(); } return bitval; }
/* * static void *alloc_mem * * DESCRIPTION: * * Allocate space for bytes inside of an already open memory pool. * * RETURNS: * * Success - Pointer to the address to use. * * Failure - NULL * * ARGUMENTS: * * mp_p <-> Pointer to the memory pool. If NULL then it will do a * normal malloc. * * byte_size -> Number of bytes to allocate in the pool. Must be >0. * * error_p <- Pointer to integer which, if not NULL, will be set with * a mpool error code. */ static void *alloc_mem(mpool_t * mp_p, const unsigned long byte_size, int *error_p) { unsigned long size, fence; void *addr; /* make sure we have enough bytes */ if (byte_size < MIN_ALLOCATION) { size = MIN_ALLOCATION; } else { size = byte_size; } if (BIT_IS_SET(mp_p->mp_flags, MPOOL_FLAG_NO_FREE)) { fence = 0; } else { fence = FENCE_SIZE; } /* get our free space + the space for the fence post */ addr = get_space(mp_p, size + fence, error_p); if (addr == NULL) { /* error_p set in get_space */ return NULL; } if (!BIT_IS_SET(mp_p->mp_flags, MPOOL_FLAG_NO_FREE)) { write_magic((char *)addr + size); } /* maintain our stats */ mp_p->mp_alloc_c++; mp_p->mp_user_alloc += size; if (mp_p->mp_user_alloc > mp_p->mp_max_alloc) { mp_p->mp_max_alloc = mp_p->mp_user_alloc; } SET_POINTER(error_p, MPOOL_ERROR_NONE); return addr; }
/* * Dummy function for checking strspn's arguments. */ int _dmalloc_strspn(const char *file, const int line, const char *str, const char *list) { if (BIT_IS_SET(_dmalloc_flags, DEBUG_CHECK_FUNCS)) { if ((! dmalloc_verify_pnt(file, line, "strspn", str, 0 /* not exact */, -1)) || (! dmalloc_verify_pnt(file, line, "strspn", list, 0 /* not exact */, -1))) { dmalloc_message("bad pointer argument found in strspn"); } } return strspn(str, list); }
/* * Dummy function for checking strcmp's arguments. */ int _dmalloc_strcmp(const char *file, const int line, const char *s1, const char *s2) { if (BIT_IS_SET(_dmalloc_flags, DEBUG_CHECK_FUNCS)) { if ((! dmalloc_verify_pnt(file, line, "strcmp", s1, 0 /* not exact */, -1)) || (! dmalloc_verify_pnt(file, line, "strcmp", s2, 0 /* not exact */, -1))) { dmalloc_message("bad pointer argument found in strcmp"); } } return strcmp(s1, s2); }
/* * Dummy function for checking memmove's arguments. */ void *_dmalloc_memmove(const char *file, const int line, void *to, const void *from, const DMALLOC_SIZE len) { if (BIT_IS_SET(_dmalloc_flags, DEBUG_CHECK_FUNCS)) { if ((! dmalloc_verify_pnt(file, line, "memmove", to, 0 /* not exact */, len)) || (! dmalloc_verify_pnt(file, line, "memmove", from, 0 /* not exact */, len))) { dmalloc_message("bad pointer argument found in memmove"); } } return (void *)memmove(to, from, len); }
/* * Dummy function for checking memcmp's arguments. */ int _dmalloc_memcmp(const char *file, const int line, const void *b1, const void *b2, const DMALLOC_SIZE len) { if (BIT_IS_SET(_dmalloc_flags, DEBUG_CHECK_FUNCS)) { if ((! dmalloc_verify_pnt(file, line, "memcmp", b1, 0 /* not exact */, len)) || (! dmalloc_verify_pnt(file, line, "memcmp", b2, 0 /* not exact */, len))) { dmalloc_message("bad pointer argument found in memcmp"); } } return memcmp(b1, b2, len); }
/* * Dummy function for checking bcopy's arguments. */ void _dmalloc_bcopy(const char *file, const int line, const void *from, void *to, const DMALLOC_SIZE len) { if (BIT_IS_SET(_dmalloc_flags, DEBUG_CHECK_FUNCS)) { if ((! dmalloc_verify_pnt(file, line, "bcopy", from, 0 /* not exact */, len)) || (! dmalloc_verify_pnt(file, line, "bcopy", to, 0 /* not exact */, len))) { dmalloc_message("bad pointer argument found in bcopy"); } } bcopy(from, to, len); }
int32_t AJS_TargetIO_PinTrigId(uint32_t* level) { if (trigSet == 0) { return AJS_IO_PIN_NO_TRIGGER; } else { static uint32_t id = 0; while (!BIT_IS_SET(trigSet, id % MAX_TRIGGERS)) { ++id; } BIT_CLR(trigSet, id % MAX_TRIGGERS); return (id % MAX_TRIGGERS); } }
/* * static int free_mem * * DESCRIPTION: * * Free an address from a memory pool. * * RETURNS: * * Success - MPOOL_ERROR_NONE * * Failure - Mpool error code * * ARGUMENTS: * * mp_p <-> Pointer to the memory pool. If NULL then it will do a * normal free. * * addr <-> Address to free. * * size -> Size of the address being freed. */ static int free_mem(mpool_t *mp_p, void *addr, const unsigned long size) { unsigned long old_size, fence; int ret; mpool_block_t *block_p; /* * If the size is larger than a block then the allocation must be at * the front of the block. */ if (size > MAX_BLOCK_USER_MEMORY(mp_p)) { block_p = (mpool_block_t *)((char *)addr - sizeof(mpool_block_t)); if (block_p->mb_magic != BLOCK_MAGIC || block_p->mb_magic2 != BLOCK_MAGIC) { return MPOOL_ERROR_POOL_OVER; } } /* make sure we have enough bytes */ if (size < MIN_ALLOCATION) { old_size = MIN_ALLOCATION; } else { old_size = size; } /* if we are packing the pool smaller */ if (BIT_IS_SET(mp_p->mp_flags, MPOOL_FLAG_NO_FREE)) { fence = 0; } else { /* find the user's magic numbers if they were written */ ret = check_magic(addr, old_size); if (ret != MPOOL_ERROR_NONE) { return ret; } fence = FENCE_SIZE; } /* now we free the pointer */ ret = free_pointer(mp_p, addr, old_size + fence); if (ret != MPOOL_ERROR_NONE) { return ret; } mp_p->mp_user_alloc -= old_size; /* adjust our stats */ mp_p->mp_alloc_c--; return MPOOL_ERROR_NONE; }
/* * Dummy function for checking strcpy's arguments. */ char *_dmalloc_strcpy(const char *file, const int line, char *to, const char *from) { if (BIT_IS_SET(_dmalloc_flags, DEBUG_CHECK_FUNCS)) { if ((! dmalloc_verify_pnt(file, line, "strcpy", to, 0 /* not exact */, loc_strlen(file, line, "strcpy", from) + 1)) || (! dmalloc_verify_pnt(file, line, "strcpy", from, 0 /* not exact */, -1))) { dmalloc_message("bad pointer argument found in strcpy"); } } return (char *)strcpy(to, from); }
/* * Dummy function for checking strtok's arguments. */ char *_dmalloc_strtok(const char *file, const int line, char *str, const char *sep) { if (BIT_IS_SET(_dmalloc_flags, DEBUG_CHECK_FUNCS)) { if ((str != NULL && (! dmalloc_verify_pnt(file, line, "strtok", str, 0 /* not exact */, -1))) || (! dmalloc_verify_pnt(file, line, "strtok", sep, 0 /* not exact */, -1))) { dmalloc_message("bad pointer argument found in strtok"); } } return (char *)strtok(str, sep); }
static int8_t AllocTrigId(uint8_t pinNum) { int8_t id = 0; while (BIT_IS_SET(trigUse, id)) { ++id; } if (id == MAX_TRIGGERS) { return AJS_IO_PIN_NO_TRIGGER; } else { BIT_SET(trigUse, id); pinIdToSource[id] = pinNum; return id; } }
int main(void){ SET_BIT(DDRC,0); SET_BIT(DDRC,1); CLEAR_BIT(DDRA,0); CLEAR_BIT(DDRA,1); CLEAR_BIT(DDRA,2); while(1){ if (BIT_IS_SET(PINA,0)){ SET_BIT(PORTC,0); CLEAR_BIT(PORTC,1); } else if(BIT_IS_SET(PINA,1)) { SET_BIT(PORTC,1); CLEAR_BIT(PORTC,0); } else if (BIT_IS_SET(PINA,2)) { CLEAR_BIT(PORTC,0); CLEAR_BIT(PORTC,1); } } }
//* ************************************************************************************************ /// @fn menumode_handler(void) /// @brief Menu mode routine /// @return none //* ************************************************************************************************ static void menumode_handler(void) { // STAR button activates the selected item if (BIT_IS_SET(ports_pressed_btns, PORTS_BTN_STAR)) { // Exit mode menumode.enabled = 0; // Clear both lines but keep symbols ! display_clear(0, 1); display_clear(0, 2); // Turn off up/down symbols display_symbol(0, LCD_SYMB_ARROW_UP, SEG_OFF); display_symbol(0, LCD_SYMB_ARROW_DOWN, SEG_OFF); // Stop blinking name of current selected module display_chars(0, LCD_SEG_L2_4_0, NULL, BLINK_OFF); // Activate item if (menumode.item->activate_fn) menumode.item->activate_fn(); } // UP button selects/shows the next item else if (BIT_IS_SET(ports_pressed_btns, PORTS_BTN_UP)) { menumode.item = menumode.item->next; display_chars(0, LCD_SEG_L2_4_0, menumode.item->name, SEG_SET); } // UP button selects/shows the previous item else if (BIT_IS_SET(ports_pressed_btns, PORTS_BTN_DOWN)) { menumode.item = menumode.item->prev; display_chars(0, LCD_SEG_L2_4_0, menumode.item->name, SEG_SET); } }
/* * icp_adf_subsystemRegister * Register a new subsystem. */ CpaStatus icp_adf_subsystemRegister(subservice_registation_handle_t* subsystem_hdl) { CpaStatus status = CPA_STATUS_FAIL; icp_accel_dev_t *accel_dev=NULL; ICP_CHECK_FOR_NULL_PARAM(subsystem_hdl); ADF_DEBUG("Registering subsystem %s\n", subsystem_hdl->subsystem_name); status = adf_subsystemAdd(subsystem_hdl); if (CPA_STATUS_SUCCESS != status) { ADF_ERROR("Failed to add subsystem to the list.\n"); return CPA_STATUS_FAIL; } status = adf_devmgrGetAccelHead(&accel_dev); if(CPA_STATUS_SUCCESS != status) { ADF_ERROR("Failed to get accel head.\n"); adf_subsystemRemove(subsystem_hdl); return CPA_STATUS_SUCCESS; } /* Loop over each accel_dev in the system and clear the status * bits for each one. */ while(accel_dev) { /* Initialising the masks during the subsystem registration * and prior to init. */ CLEAR_STATUS_BIT(subsystem_hdl->subsystemStatus [accel_dev->accelId].subsystemInitBit, 0); CLEAR_STATUS_BIT(subsystem_hdl->subsystemStatus [accel_dev->accelId].subsystemStartBit, 0); /* Send init and start events to subsystem when ADF is started */ if( BIT_IS_SET(accel_dev->adfSubsystemStatus, ADF_STATUS_SYSTEM_STARTED)) { status = do_catchup(accel_dev, subsystem_hdl); if( CPA_STATUS_SUCCESS != status ) { ADF_ERROR("Failed to start subservice %s for device %d.\n", subsystem_hdl->subsystem_name, accel_dev->accelId ); } } accel_dev = accel_dev->pNext; } return status; }
/* * Insert leaf into the tree. */ void insert_leaf(const entry *e, int diff) { auto new_node = nvobj::make_persistent<node>(); new_node->diff = diff; int d = BIT_IS_SET(e->key, new_node->diff); new_node->entries[d] = nvobj::make_persistent<entry>(*e); auto dest_entry = root; while (dest_entry->inode != nullptr) { auto n = dest_entry->inode; if (n->diff < new_node->diff) break; dest_entry = n->entries[BIT_IS_SET(e->key, n->diff)]; } new_node->entries[!d] = nvobj::make_persistent<entry>(*dest_entry); dest_entry->key = 0; dest_entry->inode = new_node; dest_entry->value = nullptr; }
BYTE VerifyStartUserProgram( void ) { BYTE bStatus; e2prom_read( (BYTE*)&bStatus, BOOT_LDR_ST_ADDR, sizeof( BYTE )); if ( BIT_IS_SET( bStatus, BOOT_LOADER_CHANGE_FW ) ) { return TRUE; } else { return FALSE; } }
/* * check out a pointer to see if we were looking for it. * may not return. */ LOCAL void check_var(const char * file, const int line, char * pnt) { static int addc = 0; if (malloc_address == NULL || pnt != malloc_address) return; if (++addc < address_count) return; if (BIT_IS_SET(_malloc_debug, DEBUG_LOG_BAD_POINTER)) _malloc_message("found address '%#lx' after %d pass%s from '%s:%u'", pnt, addc, (addc == 1 ? "" : "es"), file, line); malloc_errno = MALLOC_POINTER_FOUND; _malloc_perror("check_var"); }
int32_t AJS_TargetIO_PinTrigId(uint32_t* level) { if (trigSet == 0) { return AJS_IO_PIN_NO_TRIGGER; } else { /* * This is static so triggers are returned round-robin to ensure fairness */ static uint32_t id = 0; while (!BIT_IS_SET(trigSet, id % MAX_TRIGGERS)) { ++id; } BIT_CLR(trigSet, id % MAX_TRIGGERS); return (id % MAX_TRIGGERS); } }
/* * int mpool_close * * DESCRIPTION: * * Close/free a memory allocation pool previously opened with * mpool_open. * * RETURNS: * * Success - MPOOL_ERROR_NONE * * Failure - Mpool error code * * ARGUMENTS: * * mp_p <-> Pointer to our memory pool. */ int mpool_close(mpool_t * mp_p) { mpool_block_t *block_p, *next_p; void *addr; unsigned long size; int ret, final = MPOOL_ERROR_NONE; /* special case, just return no-error */ if (mp_p == NULL) { return MPOOL_ERROR_ARG_NULL; } if (mp_p->mp_magic != MPOOL_MAGIC) { return MPOOL_ERROR_PNT; } if (mp_p->mp_magic2 != MPOOL_MAGIC) { return MPOOL_ERROR_POOL_OVER; } if (mp_p->mp_log_func != NULL) { mp_p->mp_log_func(mp_p, MPOOL_FUNC_CLOSE, 0, 0, NULL, NULL, 0); } /* * NOTE: if we are HEAVY_PACKING then the 1st block with the mpool * header is not on the linked list. */ /* free/invalidate the blocks */ for (block_p = mp_p->mp_first_p; block_p != NULL; block_p = next_p) { if (block_p->mb_magic != BLOCK_MAGIC || block_p->mb_magic2 != BLOCK_MAGIC) { final = MPOOL_ERROR_POOL_OVER; break; } block_p->mb_magic = 0; block_p->mb_magic2 = 0; /* record the next pointer because it might be invalidated below */ next_p = block_p->mb_next_p; ret = free_pages(block_p, (char *)block_p->mb_bounds_p - (char *)block_p, BIT_IS_SET(mp_p->mp_flags, MPOOL_FLAG_USE_SBRK)); if (ret != MPOOL_ERROR_NONE) { final = ret; }
/* * Dummy function for checking strlen's arguments. */ static int loc_strlen(const char *file, const int line, const char *func, const char *str) { int len = 0; const char *str_p; if (BIT_IS_SET(_dmalloc_flags, DEBUG_CHECK_FUNCS)) { if (! dmalloc_verify_pnt(file, line, func, str, 0 /* not exact */, -1)) { dmalloc_message("bad pointer argument found in %s", func); } } for (str_p = str; *str_p != '\0'; str_p++) { len++; } return len; }
int main(void) { DDRD &= ~(1 << PD2); // clear DDRD bit 2, sets PD2 (pin 4) for input PORTD |= (1 << PD2); // set PORTD bit 2, sets PD2 (pin 4) internal pull-up resistor DDRC |= (1 << PC5); // set DDRC bit 5, sets PC5 (pin 28) for output while (1) { // begin infinite loop if(BIT_IS_CLEAR(PIND, PD2)) { // check if PIND bit 2 is clear, which indicates switch is pressed (logic low) PORTC |= (1 << PC5); // set PORTC bit 5 to set PC5 (pin 28) high } else if(BIT_IS_SET(PIND, PD2)) { // check if PIND bit 2 is set, which indicates switch is not pressed (logic low) PORTC &= ~(1 << PC5); // clear PORTC, bit 5 to set PC5 (pin 28) low } else { // ideally should never get here, but may occasionally due to timing } } return(0); // should never get here, this is to prevent a compiler warning }
/* * Fetch leaf from the tree. */ nvobj::persistent_ptr<entry> get_leaf(key_type key, nvobj::persistent_ptr<entry> *parent) { auto n = root; nvobj::persistent_ptr<entry> p = nullptr; while (n->inode != nullptr) { p = n; n = n->inode->entries[BIT_IS_SET(key, n->inode->diff)]; } if (n->key == key) { if (parent) *parent = p; return n; } return nullptr; }