This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Thread Management in Keil MCB1700 for a Project

I am trying to work on a project where I am using the MCB1700's display. Here, I get the joystick input and enter one of the apps that I display in the main screen. So, I have a Photo Gallery and a retro Game. For the game part, just to be creative I want the user to be able to choose a level: Easy or Hard and then he/she can enter the Game. I am trying to use multi-threading here in this instance with RTX v1 and CMSIS-RTOS v1 API. I am having some difficulty here, I basically have three functions here: joyStick, selLev and displayLev. When I run this code in debg mode, I see that all threads run but when I run it on display, I see only joyStick and selLev running but even here, I cannot toggle the joystick. I am also pasting the copy of the code. Any help would be great.

Code:

#include <LPC17xx.H>                    /* NXP LPC17xx definitions            */
#include "string.h"
#include "GLCD.h"
#include "stdio.h"
//#include "LED.h"

#include "gameview.h"
#include "KBD.h"
#define osObjectsPublic 1
#include "osObjects.h"
#include "cmsis_os.h"

#define __FI        1                      /* Font index 16x24               */
#define __USE_LCD   0   

void viewGame(void);
void delay(int num);

void selLev(void const *argument);
void displayLev(void const *argument);
void joyStick(void const * argument);
//int level = 0;

osThreadId tid_Thread; // thread id
osThreadDef (selLev, osPriorityAboveNormal, 1, 0);                   // thread object

osThreadId tid2_Thread; // thread id
osThreadDef (displayLev, osPriorityAboveNormal, 1, 0);                   // thread object

osThreadId tid3_Thread; // thread id
osThreadDef (joyStick, osPriorityAboveNormal, 1, 0);                   // thread object
    int32_t res3 = 0; 

osSemaphoreDef(joyStickSemaphore); 
osSemaphoreId joyStickSemaphore;
int level = 0;
int level2 = 0;
int ex = 0;
/*----------------------------------------------------------------------------
  Main Program
 *----------------------------------------------------------------------------*/
void viewGame (void) {                       /* Main Program                       */

    GLCD_Clear(White);                       
  GLCD_SetBackColor(Blue);
  GLCD_SetTextColor(Yellow);
  GLCD_DisplayString(0, 0, __FI, "     Game    ");
    GLCD_SetTextColor(White);
  GLCD_DisplayString(1, 0, __FI, "  Choose Level:    ");
  
    GLCD_SetBackColor(White);
    GLCD_SetTextColor(Blue);
    GLCD_DisplayString(5, 0, __FI, "  Easy    ");
    GLCD_DisplayString(6, 0, __FI, "  Hard    "); 
    
    

          osKernelInitialize();

    tid3_Thread = osThreadCreate(osThread(joyStick), NULL);
  osThreadSetPriority(tid3_Thread,osPriorityHigh);
    tid_Thread = osThreadCreate (osThread(selLev), NULL);

    tid2_Thread = osThreadCreate (osThread(displayLev), NULL);
    osKernelStart();
for(;;);    //This for loop acts like a blocking for the program to return to main screen.
}

void joyStick(void const *argument){
    for(;;){
        int32_t res = 0;
    res = get_button();
        //int res = 0;

    if(res == KBD_DOWN){
     level = 1;
    }
    if(res == KBD_UP){
    level = 0;}
        osThreadSetPriority(tid3_Thread,osPriorityAboveNormal);
        osThreadSetPriority(tid_Thread,osPriorityHigh);
    
    
    osSignalSet(tid_Thread,0x01);
    
    
}
}

void selLev(void const *argument){
    for(;;){

osSignalWait(0x01, osWaitForever);  
    
        if(level == 0){
        GLCD_SetBackColor(Blue);
    GLCD_SetTextColor(Red);
    GLCD_DisplayString(5, 0, __FI, "  Easy    ");
    GLCD_SetBackColor(White);
    GLCD_SetTextColor(Blue);
    GLCD_DisplayString(6, 0, __FI, "  Hard    ");
            ex +=1;
            //osDelay(10);
        }
        if (level ==1 ){
            GLCD_SetBackColor(White);
    GLCD_SetTextColor(Blue);
    GLCD_DisplayString(5, 0, __FI, "  Easy    ");
    GLCD_SetBackColor(Blue);
    GLCD_SetTextColor(Red);
    GLCD_DisplayString(6, 0, __FI, "  Hard    ");
            ex+=2;
            //osDelay(10);
        }
        
  osThreadSetPriority(tid_Thread,osPriorityAboveNormal);

    osThreadSetPriority(tid2_Thread,osPriorityHigh);
    osSignalSet(tid2_Thread,0x02);
        

}
}

void displayLev(void const *argument){
    
    for(;;){
    
    osSignalWait(0x02,osWaitForever);
 
    int i = 0;

if (level == 0)
{
    
    for(i = 0;i<320;i++){
    delay(20);
    GLCD_Bitmap(i,50,20,20,(unsigned char*)BLACKCIRCLE_pixel_data);
        //if(i == 320) i =0;
}
    }
 if (level ==1){
     
for(i = 0;i<320;i++){
    delay(2);
    GLCD_Bitmap(i,50,20,20,(unsigned char*)BLACKCIRCLE_pixel_data);
        //if(i == 320) i =0;
}
     }
 osThreadSetPriority(tid2_Thread,osPriorityAboveNormal);

    }
}

void delay(int num){
    int i,j;

  for ( i = 0;i<50000;i++);
     for ( j = 0;j<num*50000;j++);
}