Ejemplo n.º 1
0
static void prvOLEDTask( void * pvParameters)
{
static struct oled_data xOLEDData;
static unsigned char ucOffset1 = 0, ucOffset2 = 5;
static TickType_t xLastScrollTime = 0UL;

	/* Initialise the display. */
	OLED_init();

	/* Initialise the parts of the oled_data structure that do not change. */
	xOLEDData.line1          = FIRST_LINE;
	xOLEDData.string1        = " www.FreeRTOS.org";
	xOLEDData.line2          = SECOND_LINE;
	xOLEDData.string2        = " www.FreeRTOS.org";
	xOLEDData.contrast_val                 = OLED_CONTRAST_VAL;
	xOLEDData.on_off                       = OLED_HORIZ_SCROLL_OFF;
	xOLEDData.column_scrool_per_step       = OLED_HORIZ_SCROLL_STEP;
	xOLEDData.start_page                   = OLED_START_PAGE;
	xOLEDData.time_intrval_btw_scroll_step = OLED_HORIZ_SCROLL_TINVL;
	xOLEDData.end_page                     = OLED_END_PAGE;


	/* Initialise the last scroll time.  This only needs to be done once,
	because from this point on it will get automatically updated in the
	xTaskDelayUntil() API function. */
	xLastScrollTime = xTaskGetTickCount();

	for( ;; )
	{
		/* Wait until it is time to update the OLED again. */
		vTaskDelayUntil( &xLastScrollTime, mainOLED_PERIOD_MS );
		
		xOLEDData.char_offset1   = ucOffset1++;
		xOLEDData.char_offset2   = ucOffset2++;
	
		OLED_write_data( &xOLEDData, BOTH_LINES );
	}
}
Ejemplo n.º 2
0
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;
}
Ejemplo n.º 3
0
void    event_handler( event_type_t event_type, unidata_t   unidata ) 
{
   char str[32];
   unsigned char ch;
   static int err;
   
   switch(event_type)
   {
   case KBRD_EVT:
//      ltoa((int32_t)unidata, str, 10);
//      OLED_puts(0, 41, 0xff, font6x9, str);
     
      if(kbrd_pressed)
      {
         kbrd_pressed = 0;
         //display_node(kbrd_getch());
         ch = kbrd_getch();
         /*
      itoa((int16_t)ch, str, 16);
      OLED_clr(0, 41, 3 * 6, 9);
      OLED_puts(0, 41, 0xff, font6x9, str);
         */
         if(!(ch & 0x80))
         {
            ch = active.menu->action(ch);
            active.menu->display(ch);
            update_statusbar();
         }
         /*
         switch((ch = kbrd_getch()))
         {
         case 1:
         case 129:
            display(0, 0);
            break;
         case 16:
         case 144:
            display(1, 0);
            break;
         case 14:
            if((scroll_pos < (MSG_TABLE_SIZE - MSG_VIEW_SIZE)) && (scroll_pos < msg_count - 1))
            {
               scroll_pos ++;
               event_emit(LOW_PRIORITY, DISPLAY_EVT, 2);
            }
         case 142:
            break;
         case 13:
            if(scroll_pos)
            {
               scroll_pos--;
               event_emit(LOW_PRIORITY, DISPLAY_EVT, 2);
            }
         case 141:
            break;
         case 11:
            OLED_cls();
            err = initConfig();
            //sprintf(str, "initConfig res: %d", err);
            //OLED_puts(0, 0, 0xff, font6x9, str);
            OLED_puts(0, 0, 0xff, font6x9, (err ? "initConfig failed" : "initConfig success"));
            break;
         case 134:
            {
               struct LogEntry entry;
               
               err = STRG_SUCCESS;
               entry.timestamp  = 0;
               err += logAddEntry(&entry, "Msg 0");
               entry.timestamp  = 1000;
               err += logAddEntry(&entry, "Msg 1");
               entry.timestamp  = 2000;
               err += logAddEntry(&entry, "Msg 2");
               sprintf(str, "Error code: %d", err);
               OLED_puts(0, 2*9, 0xff, font6x9, str);
            }
            break;
         default:
            display(2, ch);
            break; // display(0, 0);
         }
         */
         
         /*
         OLED_puts(64 + 12, 41, 0xff, font6x9, "Key pressed ");
         itoa(kbrd_getch(), str, 10);
         OLED_puts(64 + 12 + sizeof("Key pressed ") * 6, 41, 0xff, font6x9, str);
         OLED_puts(64 + 12 + sizeof("Key pressed ") * 6 + strlen(str) * 6, 41, 0xff, font6x9, "   ");
         */
      }
      /*
      else
         OLED_puts(0, 41, 0xff, font6x9, "Key not pressed");
         */
      break;

   case INIT_EVT:
      //OLED_init();
      //init_kbrd();
      SPI_init();
      event_emit(LOW_PRIORITY, INIT_MMC_EVT, 0);
      break;

   case INIT_MMC_EVT:
      initMMC();
      err = initStorage();
      event_emit(LOW_PRIORITY, INIT_OLED_EVT, 0);
      break;

   case INIT_OLED_EVT:
      OLED_init();
      OLED_puts(0, 0 , 0xff, font6x9, "System initialization...");
      OLED_puts(0, 1 * 9 , 0xff, font6x9, "SPI     init'ed.");
      OLED_puts(0, 2 * 9 , 0xff, font6x9, "MMC     init'ed.");
      OLED_puts(0, 3 * 9 , 0xff, font6x9, "OLED    init'ed.");
      event_emit(LOW_PRIORITY, INIT_STORAGE_EVT, 0);
      break;

   case INIT_STORAGE_EVT:
      //err = initStorage();
      //OLED_puts(0, 4 * 9 , 0xff, font6x9, err ? "Storage init failed!" : "Storage init'ed.");
      format_str(str, 32, "Storage err: %d", err);
      OLED_puts(0, 4 * 9 , 0xff, font6x9, err ? str : "Storage init'ed.");
      /*
      format_str(str, 32, "ZoneCfg pos: %u", syscfg.zone_cfg_addr);
      OLED_puts(0, 5 * 9 , 0xff, font6x9, str);
      err = 1;
      */
      event_emit(LOW_PRIORITY, INIT_USER_IO_EVT, 0);
      break;

   case INIT_USER_IO_EVT:
      init_kbrd();
      menu_init(err ? MNU_INIT | MNU_DO_NOT_SHOW : MNU_INIT);
      //set_sys_time((uint64_t)20000);
      stimer_set(1, 1000);
      break;
   }
       /*
   else if(event_type == INIT_SEND_MSGS_EVT)
   {
       msg_t msg;
       struct msginfo minfo;

       uint16_t addr_attr = 0x0000;
       uint8_t  port_attr = PORT;

       //attr_write(0x02, &addr_attr);
       //attr_write(0x07, &port_attr);

       // This must be the code for us to say ZigZag (Node Dispatcher)
       // that we are interested in listening for messages and events
       msg = msg_new(0x00, 0x00, 0x01, 3, MFLAG_DEFAULT);
       if(msg < 0)
          OLED_puts(0, 0, 0xff, font6x9, "Error: msg_new");
       if(msg_info(msg, &minfo) != ENOERR)
          OLED_puts(0, 9, 0xff, font6x9, "Error: msg_info");
       ((unsigned char *)minfo.body_ptr)[0] = 0x02;
       ((unsigned char *)minfo.body_ptr)[1] = 0x00;
       ((unsigned char *)minfo.body_ptr)[2] = 0x00;
       if(msg_send(msg) != ENOERR)
          OLED_puts(0, 18, 0xff, font6x9, "Error: msg_send (1)");
       msg = msg_new(0x00, 0x00, 0x01, 2, MFLAG_DEFAULT);
       if(msg < 0)
          OLED_puts(0, 0, 0xff, font6x9, "Error: msg_new");
       if(msg_info(msg, &minfo) != ENOERR)
          OLED_puts(0, 9, 0xff, font6x9, "Error: msg_info");
       ((unsigned char *)minfo.body_ptr)[0] = 0x07;
       ((unsigned char *)minfo.body_ptr)[1] = (uint8_t)PORT;
//       ((unsigned char *)minfo.body_ptr)[2] = (uint8_t)(PORT >> 8);
       if(msg_send(msg) != ENOERR)
          OLED_puts(0, 18, 0xff, font6x9, "Error: msg_send (2)");
   }
          */
   /*
   else
   {
      //sprintf(str, "Evt: %u", (uint16_t)event_type);
      //OLED_puts(0, 0, 0xff, font6x9, str);
   }
   */
}