/** * @brief main routine for EEPROM example * @return Always returns 0 */ int main(void) { uint8_t *ptr = (uint8_t *) buffer; uint8_t ret_code; /* Generic Initialization */ SystemCoreClockUpdate(); Board_Init(); /* Enable SysTick Timer */ SysTick_Config(SystemCoreClock / TICKRATE_HZ); /* Enable EEPROM clock and reset EEPROM controller */ Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_EEPROM); Chip_SYSCTL_PeriphReset(RESET_EEPROM); /* Data to be read from EEPROM */ ret_code = Chip_EEPROM_Read(EEPROM_ADDRESS, ptr, IAP_NUM_BYTES_TO_READ_WRITE); /* Error checking */ if (ret_code != IAP_CMD_SUCCESS) { DEBUGOUT("Command failed to execute, return code is: %x\r\n", ret_code); } /* Check and display string if it exists */ ShowString((char *) ptr); /* Get a string to save */ MakeString(ptr); /* Data to be written to EEPROM */ ret_code = Chip_EEPROM_Write(EEPROM_ADDRESS, ptr, IAP_NUM_BYTES_TO_READ_WRITE); /* Error checking */ if (ret_code == IAP_CMD_SUCCESS) { DEBUGSTR("EEPROM write passed\r\n"); } else { DEBUGOUT("EEPROM write failed, return code is: %x\r\n", ret_code); } return 0; }
// Read config from EEPROM void readConfigFromEEPROM(void){ Chip_EEPROM_Read(0x00000000, (uint8_t *)&daq, sizeof(daq)); }
/* Přeposílání jednotlivých zpráv na ethernet * * Funkce filtruje zprávy, které začínaji znakem #. * Každá přijatá zpráva ukončená znakem 0x0A se odesílá * jednotlivě se zpožděním kvůli synchronizaci přenosu. * Před každým odesláním packetu prečte data z paměti. * */ void ethernet_transmit(){ switch (state) { case WAIT_FOR_DATA: { while(!empty_buffer(&buf_uart)){ if(buf_uart.buffer[buf_uart.consumer] == FIRST_CHAR){ BUF_CONSUMER_PLUS1; state = WRONG_MESSAGE; break; } if(buf_uart.buffer[buf_uart.consumer] == LAST_CHAR){ BUF_CONSUMER_PLUS1; break; } state = RIGHT_MESSAGE; break; } break; } case WRONG_MESSAGE: { while(!empty_buffer(&buf_uart)){ if(buf_uart.buffer[buf_uart.consumer] != LAST_CHAR){ BUF_CONSUMER_PLUS1; } else{ BUF_CONSUMER_PLUS1; state = WAIT_FOR_DATA; break; } } break; } case RIGHT_MESSAGE: { while(!empty_buffer(&buf_uart)){ if(buf_uart.buffer[buf_uart.consumer] == FIRST_CHAR){ state = WRONG_MESSAGE; break; } if(buf_uart.buffer[buf_uart.consumer] != LAST_CHAR){ buffer[message_lenght] = buf_uart.buffer[buf_uart.consumer]; BUF_CONSUMER_PLUS1; message_lenght++; } else{ buffer[message_lenght] = buf_uart.buffer[buf_uart.consumer]; BUF_CONSUMER_PLUS1; message_lenght++; state = ETHERNET_TRANSMIT; break; } } break; } case ETHERNET_TRANSMIT: { /* Read all data from EEPROM page*/ Chip_EEPROM_Read(LPC_EEPROM, 0, PAGE_ADDR, eeprom_read, EEPROM_RWSIZE_8BITS, EEPROM_PAGE_SIZE); /* Destination address */ memcpy(destination_addr,(char*)eeprom_read + 2, sizeof(destination_addr)); /* Source address */ memcpy(source_addr,(char*)eeprom_read + 9, sizeof(source_addr)); /* Source ip */ memcpy(source_ip,(char*)eeprom_read + 16, sizeof(source_ip)); /* Destination ip */ memcpy(destination_ip,(char*)eeprom_read + 21, sizeof(destination_ip)); delayMs(3); UDP_packet_send((char*) buffer, message_lenght,destination_addr, source_addr,source_ip,destination_ip); memset(buffer,0,message_lenght); // Vynulování přeposlaných dat v bufferu message_lenght = 0; state = WAIT_FOR_DATA; break; } } }