0

I need to know how to use UART interrupt in MicroEJ(when data receive ,do my job) . I dont want use a thread with while(true) (forever loop) to read input stream. we have these functions in C

LLCOMM_UART_callback and LLCOMM_BUFFERED_CONNECTION_dataReceived

//main uart interrupt

void USART6_IRQHandler(void)
{
    LLCOMM_UART_callback(&LLCOMM_UARTs[UART6_INDEX]);
}
/* Interrupt callback --------------------------------------------------------*/
void LLCOMM_UART_callback(LLCOMM_UART* llcomm)
{
    // retrieve LLCOM environment for given comIndex
    LLCOMM_BUFFERED_CONNECTION* env = &llcomm->header;
    UART_HandleTypeDef* handle = &llcomm->hal_uart_handle;

    uint8_t leave = interrupt_enter();

    // check RX
    if (__HAL_UART_GET_IT(handle, UART_IT_RXNE))
    {
        // read data, clear the interrupt and send data to MicroEJ framework
        LLCOMM_BUFFERED_CONNECTION_dataReceived(env, handle->Instance->RDR);
    }
}

but i cant find how to implement these interface to java ?

the 2nd part is how to use input pins interrupt and interface them to java? is there any API for this??

Thanks

Biftor
  • 148
  • 3
  • 13
  • There are several libraries for the use of serial ports in java. See: https://stackoverflow.com/questions/900950/how-to-send-data-to-com-port-using-java – B.Letz May 27 '19 at 11:12
  • Sry, I guess I misread your question. Hope you'll get helpful answers soon. – B.Letz May 28 '19 at 13:38
  • No pb , do you know to how to use interface(like what we have in java classes) in c to call a java interface? @B.Letz – Biftor May 28 '19 at 13:41

1 Answers1

2

Implementing the LLCOM_UART native interface will allow you to use ECOM COMM in Java.

The UART interrupt is handled by the underlying BSP (in C) caching the data received in a buffer until the Java thread is awake to get back the data of the read. So there is no choice between an interrupt handling or a "loop forever", it is:

  • interrupt handling in C, data read then cached into a buffer
  • Java thread periodically waking up and checking if there is data in the buffer

Pins configuration and interrupts handling for UART are not done in Java but in C at the BSP level, using the UART in Java only as a Java stream.

You can find an example of use of the Java comm connectors in our GitHub [1].

As for implementing the LL_UART C side you can take a look at how it was done for an existing platform [2]. Inside the archive you will find an implementation of BSP for STM32F7476G-DISCO, this BSP contains a LL_UART implementation (in platformSource\STM32F746GDISCO-846SI-platformSource.zip\STM32F746GDISCO-846SI-3.1.5-bsp\Projects\STM32746G-Discovery\Applications\MicroEJ\src-comm).

For GPIOs a HAL library exists [3].

Gaëtan

[1] https://github.com/MicroEJ/Example-Standalone-Foundation-Libraries/tree/master/com.microej.example.foundation.ecom.reader

[2] http://developer.microej.com/packages/referenceimplementations/846SI/3.1.5/STM32F746GDISCO-846SI-fullPackaging-eval-3.1.5.zip

[3] https://developer.microej.com/javadoc/microej_4.1/foundation/ej/hal/gpio/package-summary.html

  • Hey Gaëtan its good to see you here. i need a exact moment of when data is in serial port then trigger somethings. you never tell me how to get exact moment of there is data in serial buffer the read it . for this we need interrupt priority to start the reading data thread OR using a for ever loop to read serial buffer always. i am talking about detect there is data in serial buffer we need uart interrupt or for ever loop. i want interface uart interrupt in java part without forever loop i really hope you understand me or we can discuss on it in telegram if you have @Biftor pm me. – Biftor May 30 '19 at 20:28
  • contact me to find a solution . – Biftor May 30 '19 at 20:30