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

led is not blinking whiel simulation

#define ledon IO1SET
#define ledoff IO1CLR

void EDF_scheduler(void);
int main(void)
{ IODIR1 = 0x00FF0000; scheduler();
}

void scheduler(void)
{ while(1){ int i,time=0; int curr_process=0; while(time<sim_time) { if(curr_process > -1) { if(array[curr_process].ceu < array[curr_process].wcet ) { array[curr_process].ceu++;
if((array[curr_process].task_id )==1 ) { here i want to blink led ledon = (1<<16); // Turn ON P1.16 – P1.23 delay(900000); ledoff= (1<<16); // Turn OFF P1.16 – P1.23

}

if((array[curr_process].task_id) ==2 ) { ledon = (1<<17); // Turn ON P1.16 – P1.23 delay(9000); ledoff= (1<<17); }

  • Did you find it hurtful to have to read through the posting instructions "Tips for Posting Messages"? Did your code come out well, after you skipped the instructions how to post formatted source code?

    ledon = (1<<16); // Turn ON P1.16 – P1.23
    


    So you are writing a single bit as high. How can you then claim in your comment that you are turning on P1.16, P1.17, P1.18, P1.19, P1.20, P1.21, P1.22 and P1.23? Don't you think you have to set _eight_ bits if you want to activate 8 outputs?

    You have this source line:

    void EDF_scheduler(void);
    

    But there doesn't seem to be any implementation of such a function. And no call to such a function. On the other hand, you call a function scheduler() - but before the compiler knows about the existence of such a function.

    If you want help with your code, wouldn't it then be good if you post code that is actually building correctly?

  • 
    #include<LPC214x.h>
    
    #define ledon IO1SET
    #define ledoff IO1CLR
    
    void delay(int x);
    
    typedef int (*compfn)(const void*, const void*);
    
    struct task {
            int task_id;
            int period;
            int wcet;
            int arrival_time;
            int deadline;
            int state;
            int ceu;
    
    };
    
    int sim_time=10;
    struct task array[3]  = { {  1,4,1,0,4,1,0  },
                                 {  2,6,2,0,6,1,0 },
                                 {  3,12,3,0,12,1,0 } };
    
    int  compare(struct task *, struct task *);
    void EDF_scheduler(void);
    
    int main(void)
    {
    
       IODIR1  = 0x00FF0000; 
       qsort((void *) &array,              // Beginning address of array
       3,                                 // Number of elements in array
       sizeof(struct task),              // Size of each element
       (compfn)compare );               // Pointer to compare function
    
       EDF_scheduler();
      
    }
    
    int compare(struct task *elem1, struct task *elem2)
    {
       if ( elem1->deadline < elem2->deadline)
          return -1;
    
       else if (elem1->deadline > elem2->deadline)
          return 1;
    
       else
          return 0;
    }
    
    void EDF_scheduler(void)
    {
    while(1)
            {
    
            int i,time=0;
    
            int curr_process;
    
            while(time<sim_time)
            {
                    printf("%d\n",time);
                    curr_process=0;
                    if(curr_process > -1)
                    {
                            if(array[curr_process].ceu  <  array[curr_process].wcet )
                            {
                                    array[curr_process].ceu++;
                                    if((array[curr_process].task_id )==1 )
                                             {
                                                ledon = (1<<16);  // Turn ON P1.16
                                                delay(900000);
                                                ledoff= (1<<16);  // Turn OFF P1.16
                                                
                                               }
    
                                    if((array[curr_process].task_id) ==2 )
                                            {
                                              ledon = (1<<17);  // Turn ON P1.17
                                              delay(9000);
                                              ledoff= (1<<17);
                                            }
    
                                    if((array[curr_process].task_id) ==3 )
                                            {
                                                    ledon = (1<<18);  // Turn ON P1.17
                                              delay(9000);
                                              ledoff= (1<<18);
                                            }
                            }
    
                            if(array[curr_process].ceu == array[curr_process].wcet )
                            {
                                    if(array[curr_process].task_id ==1 )
                                             {
                                                ledon |= (1<<19);  // Turn ON P1.18
                                                    delay(9000);
                                                    ledoff= (1<<19);    // Turn OFF P1.18
    
                                               }
    
    
                                    if(array[curr_process].task_id ==2 )
                                            {
                                                    ledon= (1<<20);  // Turn ON P1.16 – P1.23
                                                    delay(9000);
                                                    ledoff= (1<<20);
                                            }
    
                                    if(array[curr_process].task_id ==3 )
                                            {
                                                    ledon = (1<<21);  // Turn ON P1.16 – P1.23
                                                    delay(9000);
                                                    ledoff= (1<<21);
                                            }
                                    array[curr_process].arrival_time +=array[curr_process].period;
                                    array[curr_process].deadline = array[curr_process].arrival_time+array[curr_process].period;
                                    array[curr_process].state = READY;
                                    qsort((void *) &array,         // Beginning address of array
                                    3,                            // Number of elements in array
                                    sizeof(struct task),         // Size of each element
                                    (compfn)compare );
                                    array[curr_process].ceu=0;
    
                            }
                    }
                    for(i=0;i<3;i++)
                    {
                            if(array[i].deadline < time)
                            {
                                    printf("\tTASK %d",i+1);
                                    printf("missed deadline\n");
                                    array[i].arrival_time += array[i].period;
                                    array[i].deadline=array[i].arrival_time + array[i].period;
                                    qsort((void *) &array,           // Beginning address of array
                                    3,                              // Number of elements in array
                                    sizeof(struct task),          // Size of each element
                                    (compfn)compare );           // Pointer to compare function
                            }
    
                    }
                    time++;
                    qsort((void *) &array,              // Beginning address of array
                    3,                                 // Number of elements in array
                    sizeof(struct task),              // Size of each element
                    (compfn)compare );               // Pointer to compare function
    
    
            }
    
    
    }
    }
    void  delay(int x)
    {     unsigned  int  k,l;
          for(k = x;k > 0;k--)
          for(l = 0;l < x;l++);
    }
    
    
    
    
    

  • So you didn't take the time to fix the part of the code you were told about?

    ledon = (1<<17);  // Turn ON P1.17
    

    ledon = (1<<18);  // Turn ON P1.17
    


    Two different assigns but same comment. Should teach you to use magic numbers when you could instead make use of enum or #define to actually name your pins, thereby removing the need for a redundant (and in your case broken) comment.

    ledon = (1<<21);  // Turn ON P1.16 – P1.23
    


    You still think a single bit assign affects 8 processor pins?

    void  delay(int x)
    {     unsigned  int  k,l;
          for(k = x;k > 0;k--)
          for(l = 0;l < x;l++);
    }
    


    Try and google a bit about this type of busy-looping delays. You might find out that they aren't so very good to use. There are just on this site at least a couple of hundred threads debating the problems with compiler versions, optimization etc.

    delay(900000);
    
    delay(9000);
    


    A factor 100 difference in parameter between these two calls. Haven't you made specific tests to find out what actual delay you get when you call that delay() function?

    Next thing. Standard debugging is done by simplifying problems and figure out which half of the problem that isn't working. So ignore all your code simulating tasks. Do you manage to light a single LED if that is all you try? Do you manage to turn off a single LED? If that works, then you know the LED code is good and can settle for figuring out if your delay() code is working. And if your code that decides if you should blink the LED is working or not.

  • Sir plz dont consider all thing about the delay and comment that i'll rectify later

    .What i want is to blink LED say any of P1.16 to P1.23 based on particular conditon..

    e.g if(array[curr_process].task_id ==1 ) // blink any of P1.16-P1.23

    Sir my programm is running nicely but when i see peripherals GPIO windows ..its not blinking

    IO1DIR : 0x0000 0000
    IO1SET : 0x0000 0000
    IO1CLR : 0x0000 0000
    IO1PIN : 0xffff 0000
    Pins : 0xffff 0000

  • IO1PIN : 0xffff 0000

    So you have managed to set the pins? Have you tried to clear them too?