5 years, 8 months ago.

how to create an software interrupt for the task ??

I have created three timer (timer1 calls the task1 for every2ms and timer2 calls the task2 for every10ms and timer3 calls the task3 for every10ms) and three tasks (which sends data to the server). I created a ethernet driver (TCP/IP) for sending and receiving the data. I am using an API provided in my requirement for receiving and sending the data through the ip address and the port number. My problem : I created a while loop in my void main () and calling the timer1 , timer2 and timer3 within the while loop. I am not able to come out of the while loop and not able to execute the API after the main program. Could anyone please help me to fix this problem ??


  1. include "MAIN.h"
  2. include "TIMER1.h"
  3. include "TIMER2.h"
  4. include "TIMER3.h"
  5. include "xcp.h"
  6. include "xcpip_inf.h"
  7. pragma comment (lib, "Ws2_32.lib")

typedef unsigned char uint8; uint8 measurements[20];

void main() { uint8 a; a= 5;

  1. ifdef XCP_ENABLE /*initialise the XCP Ecu Softwares */


  1. endif initialize before start of the operating system

while(1) { if(a) { Timer1(); Timer2(); Timer3(); } }

} I am not able to execute this function. Could anyone help me ?? void XcpApp_IpTransmit(uint16 port, Xcp_StatePtr8 pBytes, uint16 numBytes) this function must transmit the specified byte on IP connection identified by port { WSADATA wsa; SOCKET s, new_socket; uint8 bytes_recieved; uint8 recv_data[100]; uint16 sin_size; struct sockaddr_in server, client; creating a socket address structure: structure contains ip address and port number uint16 numTxBytes; uint8* pChunkData; uint16 chunkLen; numTxBytes = 1; port = 18000; pBytes = &measurements ; numBytes = strlen(pBytes);

printf("Initializing Winsock\n"); if(WSAStartup(MAKEWORD(2,2), &wsa)!=0) { printf("Failed Error Code", WSAGetLastError()); return 1; } printf("Initialised\n");


if ((s = socket(AF_INET, SOCK_STREAM, 0)) == -1) { printf("Could not Create Socket\n"); return 0; } printf("Socket Created\n");

server.sin_addr.s_addr = inet_addr(""); server.sin_family = AF_INET; server.sin_port = htons(port);

Binding between the socket and ip address

if(bind (s, (struct sockaddr *) &server, sizeof(server)) == SOCKET_ERROR) { printf("Bind failed with error code: %d", WSAGetLastError()); } puts("Bind Done");

Listen to incoming connections from the client listen(s, 1);

Accepting the incoming connection from the client while(1) {

sin_size = sizeof(struct sockaddr_in); new socket to send data : new socket is the client socket. new_socket = accept(s, (struct sockaddr *)&client, &sin_size);

printf("\n I got a connection from (%s , %d)", inet_ntoa(client.sin_addr),ntohs(client.sin_port));

after accepting the connection the server will send data to the client. it will send data through the new socket to the client. while (1) { bytes_recieved = recv(new_socket, recv_data, 1024 ,0 ); recv_data[bytes_recieved] = '\0';

pChunkData = &recv_data; chunkLen = sizeof(pChunkData); XcpIp_RxCallback (chunkLen, pChunkData, port);

if (strcmp(pChunkData, "q") == 0 || strcmp(pChunkData, "Q") == 0) { close(new_socket); break; }

else printf("received data from client %s\n", pChunkData); if (strcmp(pBytes , "q") != 0 && strcmp(pBytes , "Q") != 0) { send(new_socket, pBytes ,numBytes, 0); } else { send(new_socket, pBytes, numBytes , 0); XcpIp_TxCallback (port, numTxBytes); close(new_socket); break; } } closesocket(s); XcpIp_OnTcpCxnClosed(port); WSACleanup(); return 0; }


At least use <<code>> and <</code>>

But am I correct this has nothing whatsoever to do with mbed?

posted by Erik Olieman 14 Dec 2013
Comment on this question
Be the first to answer this question.

You need to log in to post a question