// memory commands static void cmd_memory(void) { u08 cmd,res; u08 exit = 0; while((cmd = get_char()) != 0) { switch(cmd) { case 'i': res = memory_init(); set_result(res); break; case 'c': res = memory_check(parse_hex_byte(0)); set_result(res); break; case 'd': memory_dump(parse_hex_byte(0),parse_hex_byte(0)); set_result(STATUS_OK); break; default: set_result(ERROR_SYNTAX); case '.': exit = 1; break; } if(exit) break; } }
static void new_viewMemory_oneData(void **state){ heap_t * newHeap = heap_new(100,30); memory_t * newMemory = heap_interactionMemory(newHeap, 50); memory_check(newMemory, "Hello World!"); assert_int_equal(strcmp(memory_view(newMemory), "Hello World!"), 0); heap_delete(newHeap); }
static void new_viewMemory_invalidData(void **state){ heap_t * newHeap = heap_new(100,30); memory_t * newMemory = heap_interactionMemory(newHeap, 20); memory_check(newMemory, "Hello World!"); assert_int_equal(strcmp(memory_view(newMemory), "Zdrastvuyte"), -1); heap_delete(newHeap); }
static void new_checkMemory_empty(void **state){ heap_t * newHeap = heap_new(100,30); memory_t * newMemory = heap_interactionMemory(newHeap, 50); memory_check(newMemory, ""); assert_int_equal(memory_status(newMemory), M_EMPTY); heap_delete(newHeap); }
static void new_checkMemory_normal(void **state){ heap_t * newHeap = heap_new(100,30); memory_t * newMemory = heap_interactionMemory(newHeap, 50); memory_check(newMemory, "I am normal string!"); assert_int_equal(memory_status(newMemory), M_OK); heap_delete(newHeap); }
static void actual_free(void *uptr, const char *file, int line) { void *mptr; const char *mfile; int mline; int mid; if ( uptr == NULL ) return; mptr = user2malloc_(uptr); memory_check(uptr, (mid=MID(mptr)), (mfile=MFILE(mptr)), (mline=MLINE(mptr)), file, line); if (malloc_watch && remove_warrant(mptr)==0 ) memory_check(uptr, mid, mfile, mline, file, line); #ifdef FREED_CHAR if ( mptr!=NULL ) { size_t nbytes = -nsize1_(mptr); /* LINTED */ (void)memset(mptr, FREED_CHAR, rbytes_(nbytes)); } #endif free(mptr); }
void * debug_realloc(void *uptr, size_t nbytes, const char *file, int line) { void *mptr; void *oldmptr; void *newuptr; size_t oldnbytes; int mid = id_counter; oldmptr = user2malloc_(uptr); oldnbytes = 0; if ((int)nbytes <= 0) memory_error(oldmptr, "debug_realloc", mid, file, line, file, line); if (uptr != NULL) { memory_check(uptr, MID(oldmptr), MFILE(oldmptr), MLINE(oldmptr), file, line); oldnbytes = -user_nsize1_(uptr); if ( malloc_watch && remove_warrant(oldmptr)==0 ) memory_check(uptr, MID(oldmptr), MFILE(oldmptr), MLINE(oldmptr), file, line); } if (uptr == NULL) { /* LINTED */ mptr = malloc(rbytes_(nbytes)); } else { /* LINTED */ mptr = realloc(oldmptr, rbytes_(nbytes)); } if (mptr == NULL) memory_error(oldmptr, "debug_realloc", mid, file, line, file, line); setup_space_and_issue_warrant(mptr, nbytes, file, line); newuptr = malloc2user_(mptr); #ifdef ALLOC_CHAR if (uptr == NULL) (void)memset(newuptr, ALLOC_CHAR, (size_t)nbytes); else if ( nbytes > oldnbytes ) (void)memset(((char*)newuptr)+oldnbytes, ALLOC_CHAR, (size_t)nbytes-oldnbytes); #endif return newuptr; }
void pass2( void ) { memory_check(); process_section_list(); allocate(); update_linker_information(); output_object(); if( mflag ) memory_map(); }
void debug_malloc_verify(const char *file, int line) { void *mptr; #ifdef MAX_FREE_DELAY_COUNT delayed_free_all(file,line); #endif if (!malloc_watch) { return; } mptr = first_warrant_mptr; if (mptr != NULL) { /* Check all this memory first */ do { memory_check(malloc2user_(mptr), MID(mptr), MFILE(mptr), MLINE(mptr), file, line); mptr = warrant_link_(mptr); } while (mptr != NULL); } }
static void delayed_free(void *uptr, const char* file, int line) { void *mptr; void *olduptr = free_delay[free_delay_pos]; size_t nbytes; if ( uptr==NULL ) return; mptr = user2malloc_(uptr); memory_check(uptr, MID(mptr), MFILE(mptr), MLINE(mptr), file, line); if ( olduptr!=NULL ) { actual_free(olduptr, file, line); } free_delay[free_delay_pos] = uptr; free_delay_pos++; free_delay_pos = free_delay_pos % MAX_FREE_DELAY_COUNT; nbytes = -user_nsize1_(uptr); #ifdef FREED_CHAR (void)memset(uptr, FREED_CHAR, (size_t)nbytes); #endif }
void setup(){ //! Clear the interrupt flag, to void all interrupts //! coming in during the setup phase cli(); //! Loads the settings saved in NVRAM //! Also loads the commands to the cached mem. nvram.load(); configure_device(&nvram); #ifdef DEBUG DEBUG_SERIAL.println("STARTING DEBUG ENGINE"); #endif #ifdef DEBUG //! Start Debug Engine. debug_api.enable_debug(); #endif #ifdef DEBUG_LEDs //! Check LEDs debug_api.test_leds(); debug_api.set_leds(CLEAR_ERRORS); #endif #ifdef DEBUG DEBUG_SERIAL.println("STARTED DEBUG ENGINE"); #endif //! sets the sdecoder objdect. packet_parser.set_handler(&packet_decoder); //! Reset and reboot device. attachInterrupt(SELECT_BUTTON_2, reset_device, CHANGE); #ifdef DEBUG DEBUG_SERIAL.println("INTERRUPT ATTACHED TO BUTTON 2"); DEBUG_SERIAL.println("ENTERING SELECT LOOP"); #endif //! Wait 5sec to check the pin. delay(FIVE_SECONDS); //! Check choice (default = Emulation). //! 1 - Emulation //! 0 - Real USB device if(digitalRead(SELECT_BUTTON_1) == HIGH){ //! Defines the generic pointer (EMULATION). //! This is where we setup the object pointer. EMULATION_DEVICE emulation_device(&joystick_report); generic_pointer = &emulation_device; emulation_chosen = true; #ifdef DEBUG DEBUG_SERIAL.println("EMULATION CHOSEN"); #endif }else if(digitalRead(SELECT_BUTTON_1) == LOW){ //! Define the generic pointer (USB HOST DEVICE). //! This is where we setup the object pointer. USB_DEVICE usb_host_device(&command_interpreter, &packet_parser, &joystick_report); generic_pointer = &usb_host_device; usb_device_chosen = true; #ifdef DEBUG DEBUG_SERIAL.println("USB DEVICE CHOSEN"); #endif }else{ //! If none of the above, reset the device. #ifdef DEBUG_LEDs debug_api.set_leds(REBOOT_ERROR); #endif error((void*)__LINE__, (void*)__func__); } //! Timer is initialized to keep track of the CPU idle time. TCCR1B = _BV(CS12) | _BV(CS11); #ifdef DEBUG DEBUG_SERIAL.println("USB INIT STATE"); #endif #ifdef DEBUG DEBUG_SERIAL.println("MEM CHECK"); #endif //! Check memory integrity if(memory_check() <= EMPTY) #ifdef DEBUG_LEDs debug_api.set_leds(MEMORY_ERROR); #endif error((void*)__LINE__, (void*)__func__); #ifdef DEBUG DEBUG_SERIAL.println("RESUME INTERRUPTS"); #endif //! Resume interrupt handling sei(); }
//! Setup rf link void USB_DEVICE::_init_rf_network(){ /** * Start the state machine and push the state to start. * * FROM: LOCAL_DEVICE_SETUP * TO: NETWORK_SETUP */ usb_state_machine.move_state_forward(); /** * Powers on the router. */ command_interpreter.send_cmd(USB_DEVICE_CMD, (void*)POWERON_ROUTER); /** * Move the state machine to the ID wakeup router section of the * state machine. * * FROM: NETWORK_SETUP * TO: NETWORK_ID_REQUEST */ usb_state_machine.move_state_forward(); /** This function sends_a wakeup call to the router and makes the * router go into command polling mode. This allows the router to * only react to the commands sent by the ground station and not the * sensors. * * -> This function needs an ack before a watchdog timer expires * to continue with the setup process. * * -> power_on_router(); * 1. send_wakeup_router(); * -> receive_router_ack(); */ command_interpreter.send_cmd(USB_DEVICE_CMD, (void*)WAKEUP_ROUTER); /** * Makes sure that the device is ok and running */ command_interpreter.send_cmd(USB_DEVICE_CMD, (void*)PING_ROUTER); /** * Move the state machine to the network status request state. * * FROM: NETWORK_ID_REQUEST * TO: NETWORK_STATUS_REQUEST */ usb_state_machine.move_state_forward(); /** * This function requests a router status structure. It sends a * request command and polls until a structure is returned or when a * watchdog timer exhaust is caught. * * -> This function needs an ack before a watchdog timer expires * to continue with the setup process. * * 2. request_router_status(); * -> receive_router_status(); */ command_interpreter.send_cmd(USB_DEVICE_CMD, (void*)REQUEST_ROUTER_STATUS); /** * Gets the router configs. [Radio Bytes Config] * Gets the radio configuration registers in the transceiver. */ command_interpreter.send_cmd(USB_DEVICE_CMD, (void*)REQUEST_ROUTER_CONFIG); /** * Save them to eeprom address 200dec. */ nvram._savex((byte)200, 8, (void*)packet_parser._radio_configs); /** * Move the state machine to the network map request. * * FROM: NETWORK_STATUS_REQUEST * TO: NETWORK_MAP_REQUEST */ usb_state_machine.move_state_forward(); /** * This function is very crucial to the network implementation, as * it maps out the receiver and sender nodes. This function sends a * generic "nmap" command, which activates a network_read() command on * the router. Then in turn, the router returns a network structure, * which contains enddevice information and other crucial network info. * * -> This function needs a message before a watchdog timer expires * to continue with the setup process. * * 3. request_net_map(); * -> receive_nmap(); */ command_interpreter.send_cmd(USB_DEVICE_CMD, (void*)REQUEST_NMAP); /** * Move the state machine to the network sensor configs. * * FROM: NETWORK_MAP_REQUEST * TO: NETWORK_SENSOR_CONFIGS */ usb_state_machine.move_state_forward(); //TODO // DO I REALLY NEED THIS????? // DYNAMIC OR STATIC BY USER BASE // /** // * Now that the network topology is mapped out, the follwoing command // * is issued to all endpoint devices (sensors) to acquire their // * respective specifics, such as channel IDs, speed and data types. // * // * -> This function needs a message before a watchdog timer expires // * to continue with the setup process. // * // * 4. request_sensor_channel_info(); // * -> receive_channel_info(); // */ // command_interpreter.send_cmd(USB_DEVICE_CMD, (void*)REQUEST_SENSOR_CONFIG); /** * This function polls for an enabled sensor report generated by the * user on the router, by selecting which sensor is enabled. * * 5. get_user_enable_sensors(); * -> set_flags(byte sensor flags); */ command_interpreter.send_cmd(USB_DEVICE_CMD, (void*)REQUEST_SENSOR_ENABLE); #ifdef DEBUG DEBUG_SERIAL.printf("[NOTICE]: The following sensors are active:\n"); for(register byte i = 0; i < sizeof(byte); i ++){ byte bitmask = 0b11111110; bitmask = ~bitmask; byte sensor = packet_parser._en_sensors & bitmask; if(sensor > 0) DEBUG_SERIAL.printf("\t - Sensor [%d] : ACTIVE\n", (i+1)); } #endif /** * Move the state machine to the network sensor configs. * * FROM: NETWORK_SENSOR_CONFIGS * TO: LOCAL_CONFIGURATION */ usb_state_machine.move_state_forward(); /** * Then to finalize the ground station network initialization, * we need to allocate buffers for each sensor and then create a * call priority table, which in other words is a call scheduler. * This finalizes the network setup on the ground station side. * * -> This function needs a message before a watchdog timer expires * to continue with the setup process. * 6. configure_ground_station(); * -> allocate_buffers(nampe_t* nmap, channel_info_t* channel_info); * -> create_call_priority_table(); * * *** NOTE: This is handled internally... No control signals are needed. * Only checking memory space is valid. */ if(memory_check() <= MAX_MEMORY){ #ifdef DEBUG_LEDs debug_api.set_leds(MEMORY_ERROR); #endif error((void*) __LINE__, (void*) __func__); } /** * Move the state machine to the network sensor configs. * * FROM: LOCAL_CONFIGURATION * TO: NETWORK_REQUEST_ROUTER_STATE_RUN */ usb_state_machine.move_state_forward(); /** * After this step is complete, we go into the loop that does all the * usb work and processing. */ }