Thursday, 9 February 2017

RTOS CONCEPT's ARM LPC2148 EMBEDDED 'C' CODES-II

PROGRAM 1:

PROGRAM TO IMPLEMENT SIMPLE SEMAPHORE

#include <RTL.h>                     
#include <LPC21xx.h>               
#include <stdio.h>

void init_serial (void);      
unsigned char msg1[]="task1\r\n", msg2[]="task2\r\n";
unsigned int i=0;
OS_TID tsk1, tsk2;
OS_SEM semaphore1;

__task void task1 (void) {
  OS_RESULT ret;

  while (1) {
    os_dly_wait(3);
    ret = os_sem_wait (semaphore1, 1);
    if (ret != OS_R_TMO) {
       while (msg1[i] != '\0')
            {
                    while (!(U0LSR & 0x20));
                    U0THR = msg1[i];
                   i++;
            }
            i=0;
          os_sem_send (semaphore1);
    }
  }
}

__task void task2 (void) {
  while (1)
  {
  
    os_sem_wait (semaphore1, 0xFFFF);
     while (msg2[i] != '\0')
            {
                    while (!(U0LSR & 0x20));
                    U0THR = msg2[i];
                   i++;
            }
            i=0;
    os_sem_send (semaphore1);
  }
}

__task void init (void) {
   init_serial ();
   os_sem_init (semaphore1, 1);
  tsk1 = os_tsk_create (task1, 10);
  tsk2 = os_tsk_create (task2, 0);
   os_tsk_delete_self ();
}

void init_serial (void) {
  PINSEL0 = 0X0000005;                 // Enable RxD0 and TxD1             
  U0LCR = 0x83;                         // 8 bits, no Parity, 1 Stop bit    
  U0DLL = 0x61;                           // 9600 Baud Rate @ 15MHz VPB Clock 
  U0LCR = 0x03;                         // DLAB = 0                         
}
int main (void) {
  init_serial();
  os_sys_init (init);
}

PROGRAM 2:

PROGRAM TO IMPLEMENT HARDWARE INTERRUPT

#include<lpc21xx.h>
#include<rtl.h>
OS_TID tsk1;
__task void job1(void);

int p=0;
void delay(unsigned int j)
{        unsigned int i;
          for(i=0;i<j;i++);
}

void extint0_isr(void)__irq
{       
unsigned int c[16]={0xF03f0200,0xF0060200,0xF05b0200,0x004f0200,0x00660200,0x006d0200,0x007d0200,0x00070200,0x007f0200,0x006f0200,0x00770200,0x007f0200,0x00390200,0x003f0200,0x00790200,0x00710200};
          unsigned int i;
          PINSEL0=0x00000000;
          IODIR0=0xF0FF0200;
          IOCLR0=0x00ff0000;
          IOSET0=c[p];
          for(i=0;i<200;i++)
          delay(10000);
          IOCLR0=0x00000200;
          p++;
          if(p>15)
          p=0;
          EXTINT|=0x00000001;
          VICVectAddr=0;
          os_evt_set(0x0001,tsk1);
          }
__task void job1(void)
{        tsk1=os_tsk_self();
     while(1)
           {   
          PINSEL1=0x00000001;
          EXTMODE=0x00000001;
          EXTPOLAR=0x00000000;
VICVectAddr0=(unsigned long)extint0_isr;
          VICVectCntl0=0x20|14;
          VICIntEnable|=0x00004000;
          delay(1000);
            }
 }
int main(void)
{          IODIR0=0xF0FF0200;
          os_sys_init(job1);
          for(;;);
}

PROGRAM 3:

PROGRAM TO INTERFACE SOFTWARE INTERRUPT

#include<RTL.H>
 #include<stdio.h>
 #include<lpc21xx.h>
 OS_TID tsk1,tsk2;
 U32 i;
 __task void job1(void);
 __task void job2(void);
 void __swi(9) ONLED (void);
 void __swi(8) OFFLED (void);

 void __SWI_8 (void)
 {
          IODIR0=0x00FF0200;
          IOSET0=0x00FF0200;
          for(i=0;i<100000;i++);
 }

 void __SWI_9 (void)
 {
          for(i=0;i<100000;i++);
          IOCLR0=0x00FF0200;
          for(i=0;i<100000;i++);
          for(i=0;i<100000;i++);
 }

 __task void job1(void)
 {
          tsk1=os_tsk_self();
          tsk2=os_tsk_create(job2,2);
          while(1)
          {
                   ONLED();
          }
 }

 __task void job2(void)
 {
          while(1)
          {
                   OFFLED();
                   os_dly_wait(1);
          }
 }

 int main(void)
 {
          os_sys_init(job1);

 }



No comments:

Post a Comment

we are hear to discuss your queries ,so please feel free to ask any of your queries.

Wikipedia

Search results