Skip to content
This repository has been archived by the owner on Dec 29, 2019. It is now read-only.

Commit

Permalink
signal communication thread after 5 seconds of running
Browse files Browse the repository at this point in the history
  • Loading branch information
mburumaxwell committed Dec 22, 2015
1 parent 8892fe3 commit 02f2030
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
16 changes: 9 additions & 7 deletions CommunicationThread.c
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
#include "cmsis_os.h" // CMSIS RTOS header file
#include "rl_net.h" // Keil.MDK-Pro::Network:CORE
#include <stdio.h>
#include <stdlib.h>

/*----------------------------------------------------------------------------
* Thread 1 'CommunicationThread': Thread that handles communications
*---------------------------------------------------------------------------*/

static void CommunicationThread (void const *argument); // thread function
osThreadId tid_Thread; // thread id
osThreadDef (CommunicationThread, osPriorityNormal, 1, 0); // thread object
static void CommunicationThread (void const *argument); // thread function
osThreadId tid_CommunicationThread; // thread id
osThreadDef (CommunicationThread, osPriorityNormal, 1, 768); // thread object

int Init_CommunicationThread (void) {
tid_Thread = osThreadCreate (osThread(CommunicationThread), NULL);
if (!tid_Thread) return(-1);
tid_CommunicationThread = osThreadCreate (osThread(CommunicationThread), NULL);
if (!tid_CommunicationThread) return(-1);

return(0);
}
Expand All @@ -35,7 +36,7 @@ static void CommunicationThread (void const *argument) {
if (evt.status != osEventSignal)
continue;

stat = netPPP_Connect("*99#", NULL, NULL);
stat = netPPP_Connect("*99#", "", "");
if (stat != netOK) {
printf("PPP connection failed. ret=%d\r\n", stat);
continue;
Expand All @@ -56,6 +57,7 @@ static void CommunicationThread (void const *argument) {
}

// At this point we have a connection now we can do somthing
// Let us resolve the IP address of the blog
hostentry = gethostbyname(SERVER_NAME, &err);
if (hostentry == NULL) {
if (err == BSD_ERROR_NONAME)
Expand All @@ -68,6 +70,7 @@ static void CommunicationThread (void const *argument) {
addr = (IN_ADDR *)hostentry->h_addr_list[j];
printf("IPv4: %d.%d.%d.%d\r\n", addr->s_b1, addr->s_b2, addr->s_b3, addr->s_b4);
}
free(hostentry);
}


Expand All @@ -89,6 +92,5 @@ static void CommunicationThread (void const *argument) {
printf("Could not close the PPP connection after %dms\r\n", CONNECTION_WAITS*400);
else
printf("PPP link was closed\r\n");

}
}
9 changes: 8 additions & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "rl_net.h" // Keil.MDK-Pro::Network:CORE

extern int Init_CommunicationThread(void);
extern osThreadId tid_CommunicationThread;

int main(void) {
osKernelInitialize(); // Initialize CMSIS-RTOS
Expand All @@ -13,5 +14,11 @@ int main(void) {

Init_CommunicationThread();

osKernelStart(); // Start thread execution
osKernelStart(); // Start thread execution

// Signal the communication thread after 5 seconds of running
// This functionality can be replaced by an kind of interrupt
// example: RTC wakeup alarm, button press, physical timer timeout etc.
osDelay(5000);
osSignalSet(tid_CommunicationThread, 0x01);
}

0 comments on commit 02f2030

Please sign in to comment.