LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-17-2013, 05:43 AM   #1
biyabani
Member
 
Registered: Mar 2013
Posts: 65

Rep: Reputation: Disabled
Cannot allocate memory Aborted problem while executing thread program in ARM9 board


Hi,
I am working on ARM9 based LPC3250 board with seven uarts. I have developed the user application code for transmitting the data into one UART and that data has to receive by the another UART(using UART7(TX2) for TX'ING and UART2(TX1) for RX'ING).

But when i execute that code into my board after completion of booting the kernel it is giving below error.

/nfs #./VTNMS_PRINT1
/dev/ttyTX2 opened
/dev/ttyTX1 opened
Semaphore initialization sucessful
thread_init
user_thread, Pthread creation Failed
: Cannot allocate memory
Aborted

What could be the problem? The code for thread is
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <signal.h>
#include <fcntl.h>
#include <ctype.h>
#include <termios.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <pthread.h>
#include <errno.h>
#include <sys/stat.h>


int fd_uart5,fd_uart2;

char is_exit = 0;
pthread_t tid1,tid2,tid3;
unsigned char code_version[]="1.0" ;
void *Data_transmit_thread(void* arg);
void *Data_receive_thread(void* arg);
//void *user_thread(void* arg);
//void error(const char *msg);


/****************************************************************************************
*Function :error
*Inputs :none
*Output :none
*Purpose :Function prints the system error
****************************************************************************************/

//void error(const char *msg)
//{
// perror(msg);
// exit(1);
//}


/****************************************************************************************
*Function :user_thread
*Inputs :none
*Output :none
*Purpose :Provide run time user interface
****************************************************************************************/
/*void *user_thread(void* arg)
{
char line[64];
char* banner = "VTNMS_CON";
while(is_exit == 0) {
printf("%s %s>",banner,code_version);
memset(line,0,sizeof(line));
fgets(line,sizeof(line),stdin);
if(strncmp("quit",line,4) == 0) {
is_exit = 1;
exit(0);
}
}
}
*/
int main(void)
{

pthread_attr_t attr;
pthread_attr_t attr_rx;

struct sched_param thread_param, main_param;

thread_param.sched_priority = 90;
main_param.sched_priority = 80;

pthread_attr_init(&attr);
pthread_attr_setschedpolicy(&attr, SCHED_FIFO);
pthread_attr_setschedparam(&attr, &thread_param);


if(sched_setscheduler(0, SCHED_FIFO, &main_param) == -1)
{
perror("sched_setscheduler failed");
exit(-1);
}


fd_uart5 = open("/dev/ttyTX2", O_RDWR | O_NOCTTY);
if(fd_uart5 == -1)
{
perror("open_port: Unable to open: \n");
printf("Error - Unable to open UART5. Ensure it is not in use by another application\n");
}
else
printf ("/dev/ttyTX2 opened \n");

fd_uart2 = open("/dev/ttyTX1", O_RDWR | O_NOCTTY);
if(fd_uart2 == -1)
{
perror("open_port: Unable to open: \n");
printf("Error - Unable to open UART5. Ensure it is not in use by another application\n");
}
else
printf ("/dev/ttyTX1 opened \n");

printf("Calling Data_receive_thread \n");
pthread_create(&tid2,NULL,Data_receive_thread,NULL);

printf("Calling Data_transmit_thread \n");
pthread_create(&tid1,NULL,Data_transmit_thread,NULL);
//pthread_join(tid1,NULL);
//pthread_join(tid2,NULL);
while(1);


//printf("Calling User_thread \n");

//pthread_create(&tid3,NULL,user_thread,NULL);

}



void *Data_transmit_thread(void* arg)
{
unsigned int stat,i;
unsigned char data_recieve_buff[50]="VTNMS";
unsigned char *read_ptr=&data_recieve_buff[0];
while(1)
{
printf("Entered Data_transmit_thread \n");
stat = write(fd_uart5,read_ptr,255);
printf("Data written %d characters to uart5 \n\r",stat);
printf(" data :%s \n\r",read_ptr);
getchar();

}
}


void *Data_receive_thread(void* arg)
{
unsigned int rx_length;
unsigned char rx_buffer[256];
unsigned char *p_tx_buffer=&rx_buffer[0];

while(1)
{
printf("Entered Data_receive_thread \n");


rx_length = read(fd_uart2, p_tx_buffer, 255);
if (rx_length <= 0)
{
printf("error \n");
printf("error \n");
printf("error \n");
}
else
{
printf("Bytes received \n");
rx_buffer[rx_length] = '\0';
printf("%i bytes read : %X \n", rx_length, rx_buffer);
}

//getchar();
}
}

Please help me and give reply.

Thanks & Regards,
MOHAMMAD BIYABANI.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Segmaentation fault while executing led program on lpc3250 board biyabani Linux - Newbie 4 05-06-2013 01:23 AM
malloc: cannot allocate memory (when running a small cli program). stf92 Linux - Software 1 11-09-2012 04:24 AM
MINI2440 board with Samsung S3C2440 ARM9 Board + 7"TFT Eddy van den Boom Linux - Newbie 5 05-24-2012 06:07 AM
Allocate memory to a program before execution codegenie Programming 9 01-27-2011 12:53 PM
Problem with Oprofile using Vmware on ARM9 board AshishJogeshwar Linux - Newbie 2 01-04-2010 05:05 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:34 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration