I have problem with interrupt driven UART implementation. For some reason when I replace ttya to ittya all examples stops working. I added delay in Hello World example to keep task running (as suggested in comments), still no lack.
Documentation doesn't say whole a lot about interrupt driver UARTs. I have a feeling that UART interrupts must be enabled somehow to make it working, but can't find any examples for it.
By the way, can any one give me list of acceptable modes for serial I/O initialization?
For example: FILE_PTR serial_fd = fopen("ttya:",0); - have mode argument as 0. Is it only acceptable argument?
Solved! Go to Solution.
Hi Jetoleg,
I've gotten the interrupt version working successfully. Make sure the #define changes are truly in the BSP project and not a file in the /lib/ path as that is only a holding area for the libraries and header files that support MQX and its components.
So best to open the C:\Program Files\Freescale\Freescale MQX 3.1\config\m52259evb\build_libs.mcp to open the BSP mcp and then modify the user_config.h and recompile all components (just to be safe).
I'll attach the modified main.c I have and you can place it in the following directory:
C:\Program Files\Freescale\Freescale MQX 3.1\mqx\examples\io
I'm using the M52259EVB which has 3 UARTs (0/1/2). My example allows enabling the iTTYB or iTTYC.
Hope this helps.
Regards,
David
Hi
I'm sorry for rescue this thread, but I'm still a very confused about creates an uart using the functions FILE_PTR.
I'm trying to know what's the numbers of characters in my RX buffer to read it one by one. I've tried with this:
//if (fstatus(serial_fd))
//while(fstatus(serial_fd))
while(!feof(serial_fd))
{
read(serial_fd,(pointer)&buffer,1);
write(serial_fd,(pointer)&buffer,1);
}
But none of my 3 options works. Curiously, I always obtain not the last, but the penultimate character. I think that my problem is my uart contains the first time I read it a blank character, and if I could know the numbers of characters in my rx buffer, I could solve this problem.
Actually, I'm not pretty sure, but is at least a good point to start.
Thanks you in advance.
Regards
I'm having more doubts about my problem: Just I don't understand why the first character I write via Uart is ignored until receive the second character. By this way, I always obtain the penultime character introduced, and not the last how I should obtain!!!! :smileysad:
This is my code. Please, could you say me where I'm wrong?
/*ISR*-----------------------------------------------------------
*
* ISR Name : new_tick_isr
* Comments :
* This ISR replaces the existing timer ISR, then calls the
* old timer ISR.
*END*-----------------------------------------------------------*/
void uart_isr(pointer user_isr_ptr)
{
MY_ISR_STRUCT_PTR isr_ptr;
volatile char buffer;
isr_ptr = (MY_ISR_STRUCT_PTR)user_isr_ptr;
//if (fstatus(serial_fd))
while(fstatus(serial_fd))
{
read(serial_fd,(pointer)&buffer,1);
write(serial_fd,(pointer)&buffer,1);
}
/* Chain to the previous notifier */
(*isr_ptr->OLD_ISR)(isr_ptr->OLD_ISR_DATA);
}
/*TASK*----------------------------------------------------------
*
* Task Name : main_task
* Comments :
* UART ISR function. Executed when receiving a new character via uart
*END*-----------------------------------------------------------*/
void main_task(uint_32 initial_data)
{
MY_ISR_STRUCT_PTR uart_isr_ptr;
uint_32 baud=9600;
uint_32 flag=IO_SERIAL_RAW_IO;
serial_fd = fopen("ittya:",BSP_DEFAULT_IO_OPEN_MODE);
// configuro la UART0 a 9600 bps
ioctl(serial_fd,IO_IOCTL_SERIAL_SET_FLAGS, &flag);
ioctl(serial_fd,IO_IOCTL_SERIAL_SET_BAUD, &baud);
write(serial_fd,(pointer)"hola",4);
uart_isr_ptr = _mem_alloc_zero((_mem_size)sizeof(MY_ISR_STRUCT));
uart_isr_ptr->OLD_ISR_DATA =
_int_get_isr_data(BSP_UART0_INT_VECTOR);
uart_isr_ptr->OLD_ISR =
_int_get_isr(BSP_UART0_INT_VECTOR);
_int_install_isr(BSP_UART0_INT_VECTOR, uart_isr,
uart_isr_ptr);
fflush(serial_fd);
for(;;
_mqx_exit(0);
}
Thanks you in advance
Regards
Hello,
you should not be working with interrupts anyhow, this is hidden by the interrupt serial driver.
So you have to just open the driver, use some ioctl commands and then do the while with fstatus check. Just remember, that the loop ends when there's nothing to read, i.e. it can happen right after you run the program (consider another loop to wait for a character first).
Regards,
PetrM
OK, find my problem.
Looks like ITTA is not enabled on BSP level in user_config.h. BSPCFG_ENABLE_ITTYA needs to be non-zero value.
I really like this OS, but documentation needs a little overhaul. Looks like if you need to now how things work you need to go source every time
Still not out the woods.
I added following definitionts:
#define BSPCFG_ENABLE_ITTYA 1
#define BSPCFG_ENABLE_TTYA 0
UART somehow managed to work ones, but quickly crashed and I can't make it work again.
Currently definitions added to my project, but I aslo tried to add them into BSP user_config.h and rebuilding all the libs for BSP. Still no worky.
Any suggestions?
Hi Jetoleg,
I've gotten the interrupt version working successfully. Make sure the #define changes are truly in the BSP project and not a file in the /lib/ path as that is only a holding area for the libraries and header files that support MQX and its components.
So best to open the C:\Program Files\Freescale\Freescale MQX 3.1\config\m52259evb\build_libs.mcp to open the BSP mcp and then modify the user_config.h and recompile all components (just to be safe).
I'll attach the modified main.c I have and you can place it in the following directory:
C:\Program Files\Freescale\Freescale MQX 3.1\mqx\examples\io
I'm using the M52259EVB which has 3 UARTs (0/1/2). My example allows enabling the iTTYB or iTTYC.
Hope this helps.
Regards,
David
Thanks a lot!
Works fine now.