Hello , im having the follwing problem using my FRDM K64F platform, Im developing a Gateway that synchronizes its RTC with an SNTP server.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Hello , im having the follwing problem using my FRDM K64F platform, Im developing a Gateway that synchronizes its RTC with an SNTP server.

1,322 Views
javierverde
Contributor I

When using any of the IP binding functions (ipcfg_bind_staticip, auto or DHCP) i don´t get a result, the system gets halted there, waiting for the function to finish ( it can be with an error or with the binding done succesfully) . This does not happen every time, but very frecuently. The code im using is the following ( the ip config and binding its highlighted in the end ) ( sorry for the comments in spanish , im from argentina )  :

void main_task (uint32_t initial_data)

{

  IPCFG_IP_ADDRESS_DATA ip_data; //Estructura de datos de ip.

  _enet_address mac_address; //Definition for ENET six-byte Mac type. Vector de 6 uchar.

  uint32_t error; //Captura código de error

  uint8_t lastIp[4][4] = {0}; //Almaceno últimos valores. 0: Ip Servidor. 1: Ip Frdm. 2: MaskFrdm. 3: GtyFrdm.

  uint8_t verparamIp[4][4] = {0}; //Idem anterior pero utilizado para el comando verparam. Así si estoy cargando IPs y en el medio quiero ver parámetros no sobreescribe los valores ya cargados.

  uint8_t estampa[8] = {0}; //Buffer para escribir en pantalla luego de un itoa

  uint32_t lastIpaddr[4] = {0}; //Buffer donde se guardan los IPADDR luego de una leerIPdeFlash()

  uint32_t * checkIP = BASE_IPS_FLASH; //Dirección base 0xFB000. Se usa para revisar si la flash está vacía

  uint8_t i;

  uint16_t tiempo_poleo; //Almaceno el tiempo de poleo

  uint16_t verparam_tiempo_poleo; //Lo utilizo para leerlo en el menú verparam (idem verparamIp)

  uart_state_t uartState, consoleState;

  SERVER_MESSAGE_PTR msg_ptr;

  _queue_id maintask_qid;

  uint16_t __ram_func[LAUNCH_CMD_SIZE/2]; //array to copy __Launch_Command func to RAM

  /* Inicialización de pines de entrada/salida */

  GPIO_DRV_Init(gpio1_InConfig0,gpio1_OutConfig0);

  /* Inicialización de UART0 y UART3 */

  //Uart 3

  PORT_HAL_SetMuxMode((PORT_Type *)PORTC_BASE,16u,kPortMuxAlt3); // UART3_TX

  PORT_HAL_SetMuxMode((PORT_Type *)PORTC_BASE,17u,kPortMuxAlt3); // UART3_RX

  UART_DRV_Init(UART_INSTANCE, &uartState, &uartConfig);

  UART_DRV_InstallRxCallback(UART_INSTANCE, intPidenhora, NULL, NULL, true);

  //Uart 0

  UART_DRV_Deinit(CONSOLE_INSTANCE); //Elimino la UART abierta por MQX

  UART_DRV_Init(CONSOLE_INSTANCE, &consoleState, &consoleConfig); //Vuelvo a inicializarla

  /* Instalación de interrupciones en el vector */

  OSA_InstallIntHandler(PORTD_IRQn, (osa_int_handler_t)intTimestamp); //Int para PTD3. Evento externo.

  OSA_InstallIntHandler(UART3_RX_TX_IRQn, MQX_UART3_RX_TX_IRQHandler); //Int para UART3. Envío de time al CV.

  OSA_InstallIntHandler(UART0_RX_TX_IRQn, MQX_UART0_RX_TX_IRQHandler); //Int para UART0. Programa de consola.

/* Seteo de prioridades de las interrupciones: 0x70 (Prioridad 7 > 2*MQX_MAX_LEVEL_INTERRUPT = 2*2 */

  NVIC_SetPriority(UART3_RX_TX_IRQn, 112U);

  NVIC_SetPriority(UART0_RX_TX_IRQn, 112u);//112U

  /* Creación de RTCS */

  _RTCSTASK_priority = 6;//6

  _RTCSTASK_stacksize = RTCSCFG_STACK_SIZE;

  error = RTCS_create();

  if(error)

  { enviar_cadena("Error tarea RTC",3);

  //printf("\nFailed to create RTCS, error = %X", (unsigned int)error);

  //return;

  }

  /* Inicialización de cola de mensajes para recibir IPs desde la tarea de consola */

  maintask_qid = _msgq_open(/*(_queue_number)*/MAIN_TASK_QUEUE, 0);

  /* Inicialización de FLASH para guardar IPs (no volatil) */

  error = FlashInit(&flashSSDConfig);

  if (FTFx_OK != error)

  {

  enviar_cadena("Error al iniciar la Flash",3);

  }

  //This function provides a facility to relocate a function in RAM

  g_FlashLaunchCommand = (pFLASHCOMMANDSEQUENCE)RelocateFunction((uint32_t)__ram_func , LAUNCH_CMD_SIZE ,(uint32_t)FlashCommandSequence);

  /**** INICIO de inicialización valores por default en la flash si está limpia ****/

  enviar_cadena("Iniciando GTW-NL...",3);

  enviar_cadena("Restableciendo parámetros de red...",2);

  if((*(checkIP) == 0xFFFFFFFF) && (*(checkIP+1) == 0xFFFFFFFF) && (*(checkIP+2) == 0xFFFFFFFF) && (*(checkIP+3) == 0xFFFFFFFF))

  {

  lastIp[0][0] = 66; lastIp[0][1] = 60; lastIp[0][2] = 22; lastIp[0][3] = 202; //IpServ por default: 66.60.22.202

  lastIp[1][0] = 192; lastIp[1][1] = 168; lastIp[1][2] = 1; lastIp[1][3] = 141; //IpFrdm por default 192.168.1.141

  lastIp[2][0] = 255; lastIp[2][1] = 255; lastIp[2][2] = 255; lastIp[2][3] = 0; //Mask por default: 255.255.255.0

  lastIp[3][0] = 192; lastIp[3][1] = 168; lastIp[3][2] = 1; lastIp[3][3] = 1; //gateway por default: 192.168.1.1

  guardarIPenFlash((uint8_t *)lastIp);

  tiempo_poleo = SNTP_POLL_SEC;

  guardarPolltimeEnFlash((uint8_t *)&tiempo_poleo);

  }

  enviar_cadena("Paso IF",3);

  leerPolltimeDeFlash(&tiempo_poleo);

  leerIPdeFlash((uint8_t *)lastIp, (uint32_t *)lastIpaddr);

  ip_data.ip = lastIpaddr[1];

  ip_data.mask = lastIpaddr[2];

ip_data.gateway = lastIpaddr[3];

  ENET_get_mac_address(BSP_DEFAULT_ENET_DEVICE, ip_data.ip, mac_address); //Obtiene dirección MAC de un dispositivo no inicializado. La guarda en mac_address.

  enviar_cadena("Paso MAC",3);

  ipcfg_init_device(BSP_DEFAULT_ENET_DEVICE, mac_address); //Initializes given enet device and associated ip interface

  enviar_cadena("Paso init ip",3);

  _task_create(0, WATCHDOG_TASK, 0);

  ipcfg_unbind (BSP_DEFAULT_ENET_DEVICE);

  error = ipcfg_bind_dhcp_wait(BSP_DEFAULT_ENET_DEVICE,TRUE, &ip_data);

  //error = ipcfg_bind_staticip(BSP_DEFAULT_ENET_DEVICE, &ip_data);

  enviar_cadena("Paso ip bind",3);

  error =SNTP_init(HOSTNAME, SNTP_PRIORITY, SNTP_STACKSIZE, lastIpaddr[0], tiempo_poleo); //7 //crea un nuevo cliente sntp

  if(error){

  enviar_cadena("Error SNTP",3);

  itoa(error, (char *) estampa);

  enviar_cadena((char *)estampa, 2);

  }

  enviar_cadena("Inicialización exitosa.",2);

  /**** FIN de inicialización de valores por default ****/

Is anyone else having the same problem ? i dont get an error code , so could it be a problem of my router ?

Labels (1)
0 Kudos
4 Replies

655 Views
DavidS
NXP Employee
NXP Employee

Hi Javier,

I have not used that specific API call.

I have in the past called SNTP_oneshot() successfully.

Attached is my relevant code from long time ago when I was playing with MQX3.7 or MQX3.8.

Generically it assumes good network connection and a known good NTP server IP address to use.

If the SNTP_oneshot() fails, then a default time is set.

Hope it helps.

Regards,

David

0 Kudos

655 Views
javierverde
Contributor I

Hello David,

If i use this function , i do not have to use al the ip functions ? . This funcion also manages the configuration of the ip interface ?

Javier

0 Kudos

655 Views
soledad
NXP Employee
NXP Employee

Hola Javier,

Could you please let me know the MQX version you are using??

Regards

Soledad

0 Kudos

655 Views
javierverde
Contributor I

Hello , im using MQX 4.0 !

Regards

Javier

0 Kudos