I wrote with my little Xenomai experience a rtdm kernel module witch
generates an external signal to measure it on an Oscilloscope. The
Result is satisfying. With no other load there is nearly no jitter.
With "dd if=/dev/zero of=/dev/null" and "ping -f" from an external
machine the jitter is +-15µsec.
My Question now is if my approach is OK or is there a better way to
generate the signal with Xenomai which would result in better results.
Maybe by using hardware timer interrupt or something?

I would appreciate any comment on the following code.

/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*/

#include <rtdm/rtdm_driver.h>

MODULE_LICENSE("GPL");

#define MPC52xx_MBAR            0xf0000000      /* Phys address */

/* WakeUp GPIO Registers - MBAR + 0x0C00 */
#define GPIO_WKUP_ENA          MPC52xx_MBAR + 0x0C00
#define GPIO_WKUP_DIR          MPC52xx_MBAR + 0x0C08
#define GPIO_WKUP_OUT          MPC52xx_MBAR + 0x0C0C
#define GPIO_WKUP_IN           MPC52xx_MBAR + 0x0C20

/* Set / Get value for Register reg */
#define MPC52xx_REG(reg)               *((unsigned long *)reg / 4)

/* Set Register Bit */
#define SET_REG_BIT(reg,bit)   MPC52xx_REG(reg) |= (1<<(31-bit))

/* Reset Register Bit */
#define RES_REG_BIT(reg,bit)   MPC52xx_REG(reg) &= ~(1<<(31-bit))

/* Get Register Bit */
#define GET_REG_BIT(reg,bit)   MPC52xx_REG(reg) & (1<<(31-bit)) ? 1:0

rtdm_task_t signal_task;
int         end = 0;

#define SIGNAL_PERIOD    1000000   /* 1 ms */

void set_pin(int mask)
{
        if (mask == 1)
        {
                SET_REG_BIT(GPIO_SINT_OUT,7);
                SET_REG_BIT(GPIO_SINT_ENA,7);
                SET_REG_BIT(GPIO_SINT_DIR,7);
        }
        else
        {
                RES_REG_BIT(GPIO_SINT_OUT,7);
                SET_REG_BIT(GPIO_SINT_ENA,7);
                SET_REG_BIT(GPIO_SINT_DIR,7);
        }
}

void signal(void *cookie)
{
   int state = 0;

   while (!end) {
       rtdm_task_wait_period();
       if (state >= 1)
       {
        set_pin(1);
           state = 0;
       }
       else
       {
        set_pin(0);
        state++;
       }
   }
}

int init_module(void)
{
        printk(KERN_INFO "pin_signal start\n");
   return rtdm_task_init(&signal_task, "signal", signal, NULL, 99,
SIGNAL_PERIOD);
}

void cleanup_module(void)
{
   end = 1;
   rtdm_task_join_nrt(&signal_task, 100);
   set_pin(0);
   printk(KERN_INFO "pin_signal stop\n");
}
_______________________________________________
Xenomai-help mailing list
[email protected]
https://mail.gna.org/listinfo/xenomai-help

Reply via email to