/***************************************************************************//** OLED_init() See "oled.h" for details of how to use this function. */ void OLED_init(void ) { uint8_t oled_init_sequence1[] = { OLED_COMMAND_CODE, CMD_DISPLAY_NON_INV, OLED_COMMAND_CODE, CMD_DISPLAY_ALL_OFF, OLED_COMMAND_CODE, CMD_MIRROR_HORI_ON, OLED_COMMAND_CODE, CMD_MIRROR_VERT_OFF, OLED_COMMAND_CODE, CMD_HORI_SCRL_OFF, OLED_COMMAND_CODE, CMD_CONTRAST, OLED_COMMAND_CODE, CONTRAST_DEFAULT, OLED_COMMAND_CODE, CMD_ARECOL_LPM, OLED_COMMAND_CODE, CMD_ARECOL_MONO^CMD_LPM_OFF }; uint8_t oled_init_sequence2[] = { OLED_COMMAND_CODE, CMD_START_LINE, OLED_COMMAND_CODE, CMD_PANEL_ON }; MSS_I2C_init( g_p_oled_i2c, OLED_SLAVE_ADDRESS, MSS_I2C_PCLK_DIV_60 ); MSS_I2C_write( g_p_oled_i2c, OLED_SLAVE_ADDRESS, oled_init_sequence1, sizeof(oled_init_sequence1), MSS_I2C_RELEASE_BUS ); MSS_I2C_wait_complete( g_p_oled_i2c ); OLED_clear_display(BOTH_LINES); MSS_I2C_write( g_p_oled_i2c, OLED_SLAVE_ADDRESS, oled_init_sequence2, sizeof(oled_init_sequence2), MSS_I2C_RELEASE_BUS ); MSS_I2C_wait_complete( g_p_oled_i2c ); OLED_set_cursor( FIRST_LINE, FIRST_CHARACTER ); }
/***************************************************************************//** OLED_write_data() See "oled.h" for details of how to use this function. */ void OLED_write_data(struct oled_data* data, oled_no_of_line LINES) { uint8_t line; uint8_t char_offset; char *string; switch(LINES) { case FIRST_LINE: { OLED_clear_display(FIRST_LINE); line = data->line1; char_offset = data->char_offset1; string = data->string1; } case SECOND_LINE: { OLED_clear_display(SECOND_LINE); line = data->line2; char_offset = data->char_offset2; string = data->string2; } case BOTH_LINES: { OLED_clear_display(BOTH_LINES); line = data->line1; char_offset = data->char_offset1; string = data->string1; OLED_set_cursor(line,char_offset); OLED_write_string(string); line = data->line2; char_offset = data->char_offset2; string = data->string2; } OLED_set_cursor(line,char_offset); OLED_write_string(string); OLED_contrast(data->contrast_val); } }
int_t main(void) { error_t error; NetInterface *interface; OsTask *task; MacAddr macAddr; #if (APP_USE_DHCP == DISABLED) Ipv4Addr ipv4Addr; #endif #if (APP_USE_SLAAC == DISABLED) Ipv6Addr ipv6Addr; #endif //Update system core clock SystemCoreClockUpdate(); //Initialize kernel osInitKernel(); //Configure debug UART debugInit(115200); //Start-up message TRACE_INFO("\r\n"); TRACE_INFO("**********************************\r\n"); TRACE_INFO("*** CycloneTCP FTP Client Demo ***\r\n"); TRACE_INFO("**********************************\r\n"); TRACE_INFO("Copyright: 2010-2014 Oryx Embedded\r\n"); TRACE_INFO("Compiled: %s %s\r\n", __DATE__, __TIME__); TRACE_INFO("Target: A2F200M3F\r\n"); TRACE_INFO("\r\n"); //LED configuration MSS_GPIO_init(); MSS_GPIO_config(MSS_GPIO_0, MSS_GPIO_OUTPUT_MODE); MSS_GPIO_config(MSS_GPIO_1, MSS_GPIO_OUTPUT_MODE); MSS_GPIO_config(MSS_GPIO_2, MSS_GPIO_OUTPUT_MODE); MSS_GPIO_config(MSS_GPIO_3, MSS_GPIO_OUTPUT_MODE); MSS_GPIO_config(MSS_GPIO_4, MSS_GPIO_OUTPUT_MODE); MSS_GPIO_config(MSS_GPIO_5, MSS_GPIO_OUTPUT_MODE); MSS_GPIO_config(MSS_GPIO_6, MSS_GPIO_OUTPUT_MODE); MSS_GPIO_config(MSS_GPIO_7, MSS_GPIO_OUTPUT_MODE); //Clear LEDs MSS_GPIO_set_output(MSS_GPIO_0, 1); MSS_GPIO_set_output(MSS_GPIO_1, 1); MSS_GPIO_set_output(MSS_GPIO_2, 1); MSS_GPIO_set_output(MSS_GPIO_3, 1); MSS_GPIO_set_output(MSS_GPIO_4, 1); MSS_GPIO_set_output(MSS_GPIO_5, 1); MSS_GPIO_set_output(MSS_GPIO_6, 1); MSS_GPIO_set_output(MSS_GPIO_7, 1); //Initialize SW1 and SW2 MSS_GPIO_config(MSS_GPIO_8, MSS_GPIO_INPUT_MODE); MSS_GPIO_config(MSS_GPIO_9, MSS_GPIO_INPUT_MODE); //Initialize LCD display OLED_init(); OLED_contrast(OLED_CONTRAST_VAL); OLED_clear_display(BOTH_LINES); //Welcome message lcdSetCursor(0, 0); printf("FTP Client Demo"); //TCP/IP stack initialization error = tcpIpStackInit(); //Any error to report? if(error) { //Debug message TRACE_ERROR("Failed to initialize TCP/IP stack!\r\n"); } //Configure the first Ethernet interface interface = &netInterface[0]; //Set interface name tcpIpStackSetInterfaceName(interface, "eth0"); //Set host name tcpIpStackSetHostname(interface, "FTPClientDemo"); //Select the relevant network adapter tcpIpStackSetDriver(interface, &a2fxxxm3EthDriver); tcpIpStackSetPhyDriver(interface, &dp83848PhyDriver); //Set host MAC address macStringToAddr(APP_MAC_ADDR, &macAddr); tcpIpStackSetMacAddr(interface, &macAddr); //Initialize network interface error = tcpIpStackConfigInterface(interface); //Any error to report? if(error) { //Debug message TRACE_ERROR("Failed to configure interface %s!\r\n", interface->name); } #if (IPV4_SUPPORT == ENABLED) #if (APP_USE_DHCP == ENABLED) //Get default settings dhcpClientGetDefaultSettings(&dhcpClientSettings); //Set the network interface to be configured by DHCP dhcpClientSettings.interface = interface; //Disable rapid commit option dhcpClientSettings.rapidCommit = FALSE; //DHCP client initialization error = dhcpClientInit(&dhcpClientContext, &dhcpClientSettings); //Failed to initialize DHCP client? if(error) { //Debug message TRACE_ERROR("Failed to initialize DHCP client!\r\n"); } //Start DHCP client error = dhcpClientStart(&dhcpClientContext); //Failed to start DHCP client? if(error) { //Debug message TRACE_ERROR("Failed to start DHCP client!\r\n"); } #else //Set IPv4 host address ipv4StringToAddr(APP_IPV4_HOST_ADDR, &ipv4Addr); ipv4SetHostAddr(interface, ipv4Addr); //Set subnet mask ipv4StringToAddr(APP_IPV4_SUBNET_MASK, &ipv4Addr); ipv4SetSubnetMask(interface, ipv4Addr); //Set default gateway ipv4StringToAddr(APP_IPV4_DEFAULT_GATEWAY, &ipv4Addr); ipv4SetDefaultGateway(interface, ipv4Addr); //Set primary and secondary DNS servers ipv4StringToAddr(APP_IPV4_PRIMARY_DNS, &ipv4Addr); ipv4SetDnsServer(interface, 0, ipv4Addr); ipv4StringToAddr(APP_IPV4_SECONDARY_DNS, &ipv4Addr); ipv4SetDnsServer(interface, 1, ipv4Addr); #endif #endif #if (IPV6_SUPPORT == ENABLED) #if (APP_USE_SLAAC == ENABLED) //Get default settings slaacGetDefaultSettings(&slaacSettings); //Set the network interface to be configured slaacSettings.interface = interface; //SLAAC initialization error = slaacInit(&slaacContext, &slaacSettings); //Failed to initialize SLAAC? if(error) { //Debug message TRACE_ERROR("Failed to initialize SLAAC!\r\n"); } //Start IPv6 address autoconfiguration process error = slaacStart(&slaacContext); //Failed to start SLAAC process? if(error) { //Debug message TRACE_ERROR("Failed to start SLAAC!\r\n"); } #else //Set link-local address ipv6StringToAddr(APP_IPV6_LINK_LOCAL_ADDR, &ipv6Addr); ipv6SetLinkLocalAddr(interface, &ipv6Addr, IPV6_ADDR_STATE_VALID); //Set IPv6 prefix ipv6StringToAddr(APP_IPV6_PREFIX, &ipv6Addr); ipv6SetPrefix(interface, &ipv6Addr, APP_IPV6_PREFIX_LENGTH); //Set global address ipv6StringToAddr(APP_IPV6_GLOBAL_ADDR, &ipv6Addr); ipv6SetGlobalAddr(interface, &ipv6Addr, IPV6_ADDR_STATE_VALID); //Set router ipv6StringToAddr(APP_IPV6_ROUTER, &ipv6Addr); ipv6SetRouter(interface, &ipv6Addr); //Set primary and secondary DNS servers ipv6StringToAddr(APP_IPV6_PRIMARY_DNS, &ipv6Addr); ipv6SetDnsServer(interface, 0, &ipv6Addr); ipv6StringToAddr(APP_IPV6_SECONDARY_DNS, &ipv6Addr); ipv6SetDnsServer(interface, 1, &ipv6Addr); #endif #endif //Create user task task = osCreateTask("User Task", userTask, NULL, 500, 1); //Failed to create the task? if(task == OS_INVALID_HANDLE) { //Debug message TRACE_ERROR("Failed to create task!\r\n"); } //Create a task to blink the LED task = osCreateTask("Blink", blinkTask, NULL, 500, 1); //Failed to create the task? if(task == OS_INVALID_HANDLE) { //Debug message TRACE_ERROR("Failed to create task!\r\n"); } //Start the execution of tasks osStartKernel(); //This function should never return return 0; }