On 29 August 2011 16:48, Sebastian Kuzminsky <s...@highlab.com> wrote:

> I did not do the "set per-pin port and pin-within-port information at
> init-time" work, if it's not done by the end of this week by someone else
> I'll do it.

Is this what you had in mind?

--------

This commit adds a port number and port pin field to the hm2_pin_t struct,
populates it once, then uses those numbers in all the places where the
numbering was calculated using an assumed 24-pin port width which is no
longer true.


Signed-off-by: Andy Pugh <a...@bodgesoc.org>
---
 src/hal/drivers/mesa-hostmot2/hostmot2.h |    2 +
 src/hal/drivers/mesa-hostmot2/pins.c     |  108 ++++++++++++++++--------------
 2 files changed, 61 insertions(+), 49 deletions(-)

diff --git a/src/hal/drivers/mesa-hostmot2/hostmot2.h
b/src/hal/drivers/mesa-hostmot2/hostmot2.h
index cd86353..68c40ec 100644
--- a/src/hal/drivers/mesa-hostmot2/hostmot2.h
+++ b/src/hal/drivers/mesa-hostmot2/hostmot2.h
@@ -186,6 +186,8 @@ typedef struct {
     u8 sec_tag;
     u8 sec_unit;
     u8 primary_tag;
+    u8 port_num;
+    u8 port_pin;


     //
diff --git a/src/hal/drivers/mesa-hostmot2/pins.c
b/src/hal/drivers/mesa-hostmot2/pins.c
index 71f899b..7602bbe 100644
--- a/src/hal/drivers/mesa-hostmot2/pins.c
+++ b/src/hal/drivers/mesa-hostmot2/pins.c
@@ -202,6 +202,8 @@ int hm2_read_pin_descriptors(hostmot2_t *hm2) {
         hm2->pin[i].sec_tag     = (d >>  8) & 0x000000FF;
         hm2->pin[i].sec_unit    = (d >> 16) & 0x000000FF;
         hm2->pin[i].primary_tag = (d >> 24) & 0x000000FF;
+        hm2->pin[i].port_num    = -1;
+        hm2->pin[i].port_pin    = -1;

         if (hm2->pin[i].primary_tag == 0) {
             // oops, found the Zero sentinel before the promised number of pins
@@ -236,25 +238,59 @@ int hm2_read_pin_descriptors(hostmot2_t *hm2) {
 }


+// sets the port number and pin number within the port
+static void hm2_set_pin_numbers(hostmot2_t *hm2, int i){
+    int mio;
+    hm2->pin[i].port_num = i / hm2->llio->pins_per_connector;
+    switch (hm2->llio->pins_per_connector) {
+        case 24:   /* standard 50 pin 24 I/O cards, just the odd pins */
+            hm2->pin[i].port_pin = ((i % 24) * 2) + 1;
+            break;
+        case 17:    /* 25 pin 17 I/O parallel port type cards funny
DB25 order */
+            mio = i % 17;
+            if (mio > 7){
+                hm2->pin[i].port_pin = mio - 3;
+            }
+            else {
+                if (mio & 1){
+                    hm2->pin[i].port_pin = (mio / 2) + 14;
+                }
+                else {
+                    hm2->pin[i].port_pin = (mio / 2) + 1;
+                }
+            }
+            break;
+        case 32:      /* 5I21 punt on this for now */
+            hm2->pin[i].port_pin = i + 1;
+            break;
+        default:
+            HM2_ERR("hm2_pins_set_numbers: invalid port width %d\n",
+                    hm2->llio->pins_per_connector);
+    }
+}


 void hm2_set_pin_source(hostmot2_t *hm2, int pin_number, int source) {
-    int ioport_number;
-    int bit_number;
-
-    ioport_number = pin_number / 24;
-    bit_number = pin_number % 24;

-    if ((pin_number < 0) || (ioport_number >= hm2->ioport.num_instances)) {
+    if ((pin_number < 0)
+        || (pin_number >= hm2->llio->num_ioport_connectors *
hm2->llio->pins_per_connector)) {
         HM2_ERR("hm2_set_pin_source: invalid pin number %d\n", pin_number);
         return;
     }
+
+    if ((hm2->pin[pin_number].port_num < 0)
+        || (hm2->pin[pin_number].port_num >
hm2->llio->num_ioport_connectors)) {
+        HM2_ERR("hm2_set_pin_source: invalid port number %d\n",
+                hm2->pin[pin_number].port_num);
+    }

     if (source == HM2_PIN_SOURCE_IS_PRIMARY) {
-        hm2->ioport.alt_source_reg[ioport_number] &= ~(1 << bit_number);
+        hm2->ioport.alt_source_reg[hm2->pin[pin_number].port_num]
+        &= ~(1 << hm2->pin[pin_number].port_pin);
         hm2->pin[pin_number].gtag = hm2->pin[pin_number].primary_tag;
     } else if (source == HM2_PIN_SOURCE_IS_SECONDARY) {
-        hm2->ioport.alt_source_reg[ioport_number] |= (1 << bit_number);
+        hm2->ioport.alt_source_reg[hm2->pin[pin_number].port_num]
+        |= (1 << hm2->pin[pin_number].port_pin);
         hm2->pin[pin_number].gtag = hm2->pin[pin_number].sec_tag;
     } else {
         HM2_ERR("hm2_set_pin_source: invalid pin source 0x%08X\n", source);
@@ -266,16 +302,18 @@ void hm2_set_pin_source(hostmot2_t *hm2, int
pin_number, int source) {


 void hm2_set_pin_direction(hostmot2_t *hm2, int pin_number, int direction) {
-    int ioport_number;
-    int bit_number;
-
-    ioport_number = pin_number / 24;
-    bit_number = pin_number % 24;

-    if ((pin_number < 0) || (ioport_number >= hm2->ioport.num_instances)) {
+    if ((pin_number < 0)
+        || (pin_number >= hm2->llio->num_ioport_connectors *
hm2->llio->pins_per_connector)) {
         HM2_ERR("hm2_set_pin_direction: invalid pin number %d\n", pin_number);
         return;
     }
+
+    if ((hm2->pin[pin_number].port_num < 0)
+        || (hm2->pin[pin_number].port_num >
hm2->llio->num_ioport_connectors)) {
+        HM2_ERR("hm2_set_pin_direction: invalid port number %d\n",
+                hm2->pin[pin_number].port_num);
+    }

     if ((direction != HM2_PIN_DIR_IS_INPUT) && (direction !=
HM2_PIN_DIR_IS_OUTPUT)) {
         HM2_ERR("hm2_set_pin_direction: invalid pin direction
0x%08X\n", direction);
@@ -290,46 +328,17 @@ void hm2_set_pin_direction(hostmot2_t *hm2, int
pin_number, int direction) {

 void hm2_print_pin_usage(hostmot2_t *hm2) {
     int i;
-    int port, port_pin, mio;

     HM2_PRINT("%d I/O Pins used:\n", hm2->num_pins);

     for (i = 0; i < hm2->num_pins; i ++) {
-        port_pin = i + 1;
-        port = i / hm2->idrom.port_width;
-        switch (hm2->idrom.port_width) {
-            case 24:   /* standard 50 pin 24 I/O cards, just the odd pins */
-                port_pin = ((i % hm2->idrom.port_width) * 2) + 1;
-                break;
-            case 17:    /* 25 pin 17 I/O parallel port type cards
funny DB25 order */
-                mio = i % hm2->idrom.port_width;
-                if (mio > 7){
-                    port_pin = mio-3;
-                }
-                else {
-                    if (mio & 1){
-                        port_pin = (mio/2)+14;
-                    }
-                    else {
-                        port_pin = (mio/2)+1;
-                    }
-                }
-                break;
-            case 32:      /* 5I21 punt on this for now */
-                port_pin = i+1;
-                break;
-            default:
-                HM2_ERR("hm2_print_pin_usage: invalid port width
%d\n", hm2->idrom.port_width);
-        }
-
-
         if (hm2->pin[i].gtag == hm2->pin[i].sec_tag) {
             if(hm2->pin[i].sec_unit & 0x80)
                 HM2_PRINT(
                     "    IO Pin %03d (%s-%02d): %s (all), pin %s (%s)\n",
                     i,
-                    hm2->llio->ioport_connector_name[port],
-                    port_pin,
+                    hm2->llio->ioport_connector_name[hm2->pin[i].port_num],
+                    hm2->pin[i].port_pin,
                     hm2_get_general_function_name(hm2->pin[i].gtag),
                     hm2_get_pin_secondary_name(&hm2->pin[i]),
                     ((hm2->pin[i].sec_pin & 0x80) ? "Output" : "Input")
@@ -338,8 +347,8 @@ void hm2_print_pin_usage(hostmot2_t *hm2) {
                 HM2_PRINT(
                     "    IO Pin %03d (%s-%02d): %s #%d, pin %s (%s)\n",
                     i,
-                    hm2->llio->ioport_connector_name[port],
-                    port_pin,
+                    hm2->llio->ioport_connector_name[hm2->pin[i].port_num],
+                    hm2->pin[i].port_pin,
                     hm2_get_general_function_name(hm2->pin[i].gtag),
                     hm2->pin[i].sec_unit,
                     hm2_get_pin_secondary_name(&hm2->pin[i]),
@@ -349,8 +358,8 @@ void hm2_print_pin_usage(hostmot2_t *hm2) {
             HM2_PRINT(
                 "    IO Pin %03d (%s-%02d): %s\n",
                 i,
-                hm2->llio->ioport_connector_name[port],
-                port_pin,
+                hm2->llio->ioport_connector_name[hm2->pin[i].port_num],
+                hm2->pin[i].port_pin,
                 hm2_get_general_function_name(hm2->pin[i].gtag)
             );
         }
@@ -407,6 +416,7 @@ void hm2_configure_pins(hostmot2_t *hm2) {

     // everything defaults to GPIO input...
     for (i = 0; i < hm2->num_pins; i ++) {
+        hm2_set_pin_numbers(hm2, i);
         hm2_set_pin_source(hm2, i, HM2_PIN_SOURCE_IS_PRIMARY);
         hm2_set_pin_direction(hm2, i, HM2_PIN_DIR_IS_INPUT);
     }
-- 
1.7.0.4

-- 
atp
"Torque wrenches are for the obedience of fools and the guidance of wise men"

------------------------------------------------------------------------------
Special Offer -- Download ArcSight Logger for FREE!
Finally, a world-class log management solution at an even better 
price-free! And you'll get a free "Love Thy Logs" t-shirt when you
download Logger. Secure your free ArcSight Logger TODAY!
http://p.sf.net/sfu/arcsisghtdev2dev
_______________________________________________
Emc-developers mailing list
Emc-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emc-developers

Reply via email to