Thanks Robert,

Any chance you can make this work with both PXA and PXA27x?  Note that
the global variable "Mach" points to either an instance of class
MachinePXA or MachinePXA27x - see the files in the mach/
subdirectory.

-Kevin


On Thu, Jan 03, 2008 at 09:16:44PM +0100, robert jarzmik wrote:
> For your appreciation if worth integrating ...
> 
> This patch aims to provide better support for systems
> having 120 GPIOs (PXA for instance) instead of 84. The
> main goal is the haret function "dump gpio".
> This patch will still require a #define modification
> in gpios.cpp.
> 
> --
> Robert (aka diogene31)
> 
> 
> Index: src/gpio.cpp
> ===================================================================
> RCS file: /cvs/haret/src/gpio.cpp,v
> retrieving revision 1.11
> diff -u -r1.11 gpio.cpp
> --- src/gpio.cpp      21 Apr 2007 20:24:55 -0000      1.11
> +++ src/gpio.cpp      3 Jan 2008 20:05:39 -0000
> @@ -14,99 +14,139 @@
>  #include "script.h" // REG_VAR_BITSET
>  #include "arch-pxa.h" // testPXA
>  
> +#define MAX_GPIO 84 //(must be a multiple of 4)
> +#define NB_GPIO_REGS 4
> +
>  // Which GPIO changes to ignore during watch
>  uint32 gpioIgnore [3] = { 0, 0, 0 };
>  
> -REG_VAR_BITSET(testPXA, "IGPIO", gpioIgnore, 84
> +enum t_gpio {
> +     t_GPLR,
> +     t_GPDR,
> +     t_GPSR,
> +     t_GPCR,
> +     t_GRER,
> +     t_GFER,
> +     t_GEDR,
> +     t_GAFR
> +};
> +
> +int gpioOffset (int num, int reg_type)
> +{
> +     int ret = 0;
> +
> +     switch (reg_type) {
> +     case t_GAFR:
> +             ret += (num >> 4) << 2;
> +             break;
> +     default:
> +             if (num >= 96) {
> +                     ret = 0x100;
> +                     num -= 96;
> +             }
> +             ret += (num>>5) << 2;
> +             break;
> +     }
> +     return ret;
> +}
> +
> +//#define GPIO_bit(num) 1 << (num & 31)
> +
> +
> +REG_VAR_BITSET(testPXA, "IGPIO", gpioIgnore, MAX_GPIO
>                 , "The list of GPIOs to ignore during
> WGPIO")
>  
>  void gpioSetDir (int num, bool out)
>  {
> -  if (num > 84)
> +  if (num > MAX_GPIO)
>      return;
>  
> -  uint32 *gpdr = (uint32 *)memPhysMap (GPDR0);
> -  uint32 ofs = num >> 5;
> -  uint32 mask = 1 << (num & 31);
> +  uint32 *gpdr = (uint32 *)memPhysMap
> (GPDR0+gpioOffset(num, t_GPDR));
> +  uint32 mask = GPIO_bit(num);
>  
>    if (out)
> -    gpdr [ofs] |= mask;
> +    *gpdr |= mask;
>    else
> -    gpdr [ofs] &= ~mask;
> +    *gpdr &= ~mask;
>  }
>  
>  bool gpioGetDir (int num)
>  {
> -  if (num > 84)
> +  if (num > MAX_GPIO)
>      return false;
>  
> -  uint32 *gpdr = (uint32 *)memPhysMap (GPDR0);
> +  uint32 *gpdr = (uint32 *)memPhysMap
> (GPDR0+gpioOffset(num, t_GPDR));
>  
> -  return (gpdr [num >> 5] & (1 << (num & 31))) != 0;
> +  return (*gpdr & GPIO_bit(num)) != 0;
>  }
>  
>  void gpioSetAlt (int num, int altfn)
>  {
> -  if (num > 84)
> +  if (num > MAX_GPIO)
>      return;
>  
> -  uint32 *gafr = (uint32 *)memPhysMap (GAFR0_L);
> -  uint32 ofs = num >> 4;
> +  uint32 *gafr = (uint32 *)memPhysMap
> (GAFR0_L+gpioOffset(num, t_GAFR));
>    uint32 shft = (num & 15) << 1;
>  
> -  gafr [ofs] = (gafr [ofs] & ~(3 << shft)) | ((altfn
> & 3) << shft);
> +  *gafr = (*gafr & ~(3 << shft)) | ((altfn & 3) <<
> shft);
>  }
>  
>  uint32 gpioGetAlt (int num)
>  {
> -  if (num > 84)
> +  if (num > MAX_GPIO)
>      return -1;
>  
> -  uint32 *gafr = (uint32 *)memPhysMap (GAFR0_L);
> +  uint32 addr = GAFR0_L+gpioOffset(num, t_GAFR);
> +  uint32 *gafr = (uint32 *)memPhysMap (addr);
>  
> -  return (gafr [num >> 4] >> ((num & 15) << 1)) & 3;
> +  return (*gafr >> ((num & 15) << 1)) & 3;
>  }
>  
>  int gpioGetState (int num)
>  {
> -  if (num > 84)
> +  if (num > MAX_GPIO)
>      return -1;
>  
> -  uint32 *gplr = (uint32 *)memPhysMap (GPLR0);
> -  return (gplr [num >> 5] >> (num & 31)) & 1;
> +  uint32 *gplr = (uint32 *)memPhysMap
> (GPLR0+gpioOffset(num, t_GPLR));
> +  return ( (*gplr & GPIO_bit(num)) != 0 );
>  }
>  
>  void gpioSetState (int num, bool state)
>  {
> -  if (num > 84)
> +  if (num > MAX_GPIO)
>      return;
>  
> -  uint32 *gpscr = (uint32 *)memPhysMap (state ? GPSR0
> : GPCR0);
> -  gpscr [num >> 5] |= 1 << (num & 31);
> +  uint32 *gplr = (uint32 *)memPhysMap
> (GPLR0+gpioOffset(num, t_GPLR));
> +  uint32 *gpscr = (uint32 *)memPhysMap (state ?
> GPSR0+gpioOffset(num, t_GPSR) : GPCR0+gpioOffset(num,
> t_GPCR));
> +  Output("RJK: GPIO read level state : 0x%8x",
> *gplr);
> +  if (state)
> +       *gpscr |= GPIO_bit(num);
> +  else
> +       *gpscr &= ~ GPIO_bit(num);
> +  Output("RJK: GPIO read level state : 0x%8x",
> *gplr);
>  }
>  
>  int gpioGetSleepState (int num)
>  {
> -  if (num > 84)
> +  if (num > MAX_GPIO)
>      return -1;
>  
> -  uint32 *pgsr = (uint32 *)memPhysMap (PGSR0);
> -  return (pgsr [num >> 5] >> (num & 31)) & 1;
> +  uint32 *pgsr = (uint32 *)memPhysMap
> (PGSR0+gpioOffset(num, t_GPSR));
> +  return ((*pgsr & GPIO_bit(num)) != 0);
>  }
>  
>  void gpioSetSleepState (int num, bool state)
>  {
> -  if (num > 84)
> +  if (num > MAX_GPIO)
>      return;
>  
> -  uint32 *pgsr = (uint32 *)memPhysMap (PGSR0);
> -  uint32 ofs = num >> 5;
> -  uint32 mask = 1 << (num & 31);
> +  uint32 *pgsr = (uint32 *)memPhysMap
> (PGSR0+gpioOffset(num, t_GPSR));
> +  uint32 mask = GPIO_bit(num);
>  
>    if (state)
> -    pgsr [ofs] |= mask;
> +    *pgsr |= mask;
>    else
> -    pgsr [ofs] &= ~mask;
> +    *pgsr &= ~mask;
>  }
>  
>  // Watch for given number of seconds which GPIO pins
> change
> @@ -123,32 +163,32 @@
>    int i, j;
>  
>    uint32 *gplr = (uint32 *)memPhysMap (GPLR0);
> -  uint32 old_gplr [3];
> -  for (i = 0; i < 3; i++)
> +  uint32 old_gplr [NB_GPIO_REGS];
> +  for (i = 0; i < NB_GPIO_REGS; i++)
>      old_gplr [i] = gplr [i];
>  
>    uint32 *gpdr = (uint32 *)memPhysMap (GPDR0);
> -  uint32 old_gpdr [3];
> -  for (i = 0; i < 3; i++)
> +  uint32 old_gpdr [NB_GPIO_REGS];
> +  for (i = 0; i < NB_GPIO_REGS; i++)
>      old_gpdr [i] = gpdr [i];
>  
>    uint32 *gafr = (uint32 *)memPhysMap (GAFR0_L);
> -  uint32 old_gafr [6];
> -  for (i = 0; i < 6; i++)
> +  uint32 old_gafr [NB_GPIO_REGS*2];
> +  for (i = 0; i < NB_GPIO_REGS*2; i++)
>      old_gafr [i] = gafr [i];
>  
>    while (cur_time <= fin_time)
>    {
>      gplr = (uint32 *)memPhysMap (GPLR0);
> -    for (i = 0; i < 3; i++)
> +    for (i = 0; i < NB_GPIO_REGS; i++)
>      {
> -      uint32 val = gplr [i];
> +      uint32 val = i<3 ? gplr [i] : gplr[0x100/4+i];
>        if (old_gplr [i] != val)
>        {
>          uint32 changes = (old_gplr [i] ^ val) &
> ~gpioIgnore [i];
>          for (j = 0; j < 32; j++)
>            if ((changes & (1 << j))
> -        && ((i * 32 + j) <= 84))
> +        && ((i * 32 + j) <= MAX_GPIO))
>         {
>              Screen("GPLR[%d] changed to %d", i * 32 +
> j, (val >> j) & 1);
>            }
> @@ -157,15 +197,15 @@
>      }
>  
>      gpdr = (uint32 *)memPhysMap (GPDR0);
> -    for (i = 0; i < 3; i++)
> +    for (i = 0; i < NB_GPIO_REGS; i++)
>      {
> -      uint32 val = gpdr [i];
> +      uint32 val = i<3 ? gpdr [i] : gpdr[0x100/4+i];
>        if (old_gpdr [i] != val)
>        {
>          uint32 changes = (old_gpdr [i] ^ val) &
> ~gpioIgnore [i];
>          for (j = 0; j < 32; j++)
>            if ((changes & (1 << j))
> -        && ((i * 32 + j) <= 84))
> +        && ((i * 32 + j) <= MAX_GPIO))
>         {
>              Screen("GPDR[%d] changed to %d", i * 32 +
> j, (val >> j) & 1);
>         }
> @@ -174,7 +214,7 @@
>      }
>  
>      gafr = (uint32 *)memPhysMap (GAFR0_L);
> -    for (i = 0; i < 6; i++)
> +    for (i = 0; i < NB_GPIO_REGS*2; i++)
>      {
>        uint32 val = gafr [i];
>        if (old_gafr [i] != val)
> @@ -210,9 +250,9 @@
>  
>  static uint32 gpioScrGPLR (bool setval, uint32 *args,
> uint32 val)
>  {
> -  if (args [0] > 84)
> +  if (args [0] > MAX_GPIO)
>    {
> -    Output("Valid GPIO indexes are 0..84, not %d",
> args [0]);
> +    Output("Valid GPIO indexes are 0..%d, not %d",
> MAX_GPIO, args [0]);
>      return -1;
>    }
>  
> @@ -229,9 +269,9 @@
>  
>  static uint32 gpioScrGPDR (bool setval, uint32 *args,
> uint32 val)
>  {
> -  if (args [0] > 84)
> +  if (args [0] > MAX_GPIO)
>    {
> -    Output("Valid GPIO indexes are 0..84, not %d",
> args [0]);
> +    Output("Valid GPIO indexes are 0..%d, not %d",
> MAX_GPIO, args [0]);
>      return -1;
>    }
>  
> @@ -248,9 +288,9 @@
>  
>  static uint32 gpioScrGAFR (bool setval, uint32 *args,
> uint32 val)
>  {
> -  if (args [0] > 84)
> +  if (args [0] > MAX_GPIO)
>    {
> -    Output("Valid GPIO indexes are 0..84, not %d",
> args [0]);
> +    Output("Valid GPIO indexes are 0..%d, not %d",
> MAX_GPIO, args [0]);
>      return -1;
>    }
>  
> @@ -269,7 +309,7 @@
>  static void
>  gpioDump(const char *tok, const char *args)
>  {
> -  const uint rows = 84/4;
> +  const uint rows = MAX_GPIO/4;
>    uint32 *grer = (uint32 *)memPhysMap (GRER0);
>    uint32 *gfer = (uint32 *)memPhysMap (GFER0);
>  
> @@ -280,8 +320,8 @@
>      for (uint j = 0; j < 4; j++)
>      {
>        uint gpio = i + j * rows;
> -      bool re = (grer [gpio >> 5] & (1 << (gpio &
> 31))) != 0;
> -      bool fe = (gfer [gpio >> 5] & (1 << (gpio &
> 31))) != 0;
> +      bool re = (grer [gpioOffset(gpio, t_GRER)/4] &
> GPIO_bit(gpio)) != 0;
> +      bool fe = (gfer [gpioOffset(gpio, t_GFER)/4] &
> GPIO_bit(gpio)) != 0;
>  
>        Output("%3d   %c %d %d %s%s%s", gpio,
> gpioGetDir (gpio) ? 'O' : 'I',
>             gpioGetState (gpio), gpioGetAlt (gpio),
> @@ -300,19 +340,19 @@
>  {
>    int i;
>    Output("/* GPIO pin direction setup */");
> -  for (i = 0; i < 81; i++)
> +  for (i = 0; i < MAX_GPIO; i++)
>      Output("#define GPIO%02d_Dir\t%d",
>           i, gpioGetDir (i));
>    Output("\n/* GPIO Alternate Function (Select
> Function 0 ~ 3) */");
> -  for (i = 0; i < 81; i++)
> +  for (i = 0; i < MAX_GPIO; i++)
>      Output("#define GPIO%02d_AltFunc\t%d",
>           i, gpioGetAlt (i));
>    Output("\n/* GPIO Pin Init State */");
> -  for (i = 0; i < 81; i++)
> +  for (i = 0; i < MAX_GPIO; i++)
>      Output("#define GPIO%02d_Level\t%d",
>           i, gpioGetDir (i) ? gpioGetState (i) : 0);
>    Output("\n/* GPIO Pin Sleep Level */");
> -  for (i = 0; i < 81; i++)
> +  for (i = 0; i < MAX_GPIO; i++)
>      Output("#define GPIO%02d_Sleep_Level\t%d",
>           i, gpioGetSleepState (i));
>  }
> 
> 
> 
>       
> _____________________________________________________________________________ 
> Ne gardez plus qu'une seule adresse mail ! Copiez vos mails vers Yahoo! Mail 
> http://mail.yahoo.fr
> _______________________________________________
> Haret mailing list
> [email protected]
> https://handhelds.org/mailman/listinfo/haret
_______________________________________________
Haret mailing list
[email protected]
https://handhelds.org/mailman/listinfo/haret

Reply via email to