Reputation: 148
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
Upvotes: 0
Views: 247
Reputation: 21
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:
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
[3] https://developer.microej.com/javadoc/microej_4.1/foundation/ej/hal/gpio/package-summary.html
Upvotes: 2