Infinite looping Meant to be a NO-NO?


Hello I’m a complete beginner with Open AT and C++.
I thought the concept is that application software is all event driven and therefore infinite looping not necessary. I’m just playing with UART2 and have the sample code working but it looks to me that the sample UART RX routine is very much just and infinite loop in a separate task?“while( 1 )” This seems to be a very differcult way of doing something which I achieve with BASCOM and an AVR in about 3 lines.
Any comments on how this could be simipified

While Ischarwaiting() = 1
Tempb = Inkey()

void stInit ( void )
   u32 idx_buff = 0;
   u32 nb_read;
   u32 nb_tb_read;
   u8* p_buff;
//char out[10];

   TRACE((1, "OK - stInit"));

   /* create Uart Event */
   EventHandle =  adl_eventCreate( INIT_TX_RX_MASK );

   /* Echoing mode: data received are just sent back ... */
   while( 1 )
      TRACE((1, "Wait for a Received Data......"));

      /* wait for Rx Available event */
      adl_eventWait( EventHandle,
     /* clear Rx Available event */
      adl_eventClear( EventHandle, RX_EVENT_WAIT_MASK, NULL );
      /*  Flip-flop buffer management */
      p_buff = (u8*)buffer_pool[ idx_buff ];
      idx_buff ^= 1;

      /* Reception loop */
      for( nb_tb_read = DATA_MAX;
           (nb_read = uart_handle, p_buff, nb_tb_read )); )
         /* Point at first free byte position in the receive buffer */
         p_buff += nb_read;

         /* Compute maximum allowed amount of bytes to be read */
         nb_tb_read -= nb_read;

         if( !nb_tb_read )
         /* No more available space */
            TRACE((1, "Read buffer is FULL"));
            adl_eventSet( EventHandle, RX_EVENT_WAIT_MASK );

      /* Alpha Rx chars in lower case are put in upper case and in upper case
       * are put in lower case
      for( nb_read = DATA_MAX - nb_tb_read; nb_read-- ; )
         if( isalpha( *--p_buff ) )
            /* Char in lowercase goes in upper case and vice & versa */
            *p_buff ^= ' ';

      /* Processed data are echoed */
      if( DATA_MAX != nb_tb_read )
          TRACE((1, "Wait for last Tx complete......"));

          /* wait for Tx Complete event */

          /* clear TxComplete event */
          adl_eventClear (EventHandle, TX_EVENT_WAIT_MASK, NULL);

          TRACE((1, "ADL Write Process"));

          /* write all former read data */
          if ( -1 == uart_itf.write(uart_handle, p_buff, DATA_MAX - nb_tb_read) )
              TRACE((1, "ERROR write !!!!!   pWriteData %x DataNbToWrite %d",DATA_MAX - nb_tb_read));

   } /* end while(1)*/



It’s not that it’s unnecessary. With Open-AT, your application is sharing the the same CPU that is also running the GSM stack - so, if your application “hogs” the CPU in a long (not necessarily even infinite) loop, the GSM stack will fail.

Your Open-AT application is scheduled in a “cooperative” way - rather like Windows 3.1 - it is not preempted by the GSM stack.

I think you’ve chosen the wrong sample for that!

It looks like you’ve taken the sample that illustrates the use of the Open-AT Event mechanism - which is an overcomplicated way just to use a UART! :open_mouth:

If you just want to “play with” UART2, I suggest you start with FCM (the Open-AT Flow Control Manager)…


Yes Thanks for that.
I’m starting to underside that code better now. I guess it waits at the adl_eventwait rather than continuely looping (while(1))?


Yes, that’s the idea…