Changeset 8f748215 in mainline


Ignore:
Timestamp:
2011-01-07T16:42:00Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
93fb170c
Parents:
15701921
Message:

port_status refactoring, use flags instead of structure

Location:
uspace/drv/uhci/root_hub
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/uhci/root_hub/port.c

    r15701921 r8f748215  
    3333
    3434                /* read register value */
    35                 port_status_t port_status;
    36                 port_status.raw_value = pio_read_16(port_instance->address);
     35                port_status_t port_status =
     36                        port_status_read(port_instance->address);
     37//              port_status.raw_value = pio_read_16(port_instance->address);
    3738
    3839                /* debug print */
    3940                uhci_print_info("Port(%d) status %#.4x:\n",
    40                   port_instance->number, port_status.raw_value);
    41                 print_port_status( &port_status );
    42 
    43                 if (port_status.status.connect_change) {
    44                         if (port_status.status.connected) {
     41                  port_instance->number, port_status);
     42                print_port_status( port_status );
     43
     44                if (port_status & STATUS_CONNECTED_CHANGED) {
     45                        if (port_status & STATUS_CONNECTED) {
    4546                                /* assign address and report new device */
    4647                                uhci_port_new_device(port_instance);
     
    103104
    104105        /* read register value */
    105         port_status_t port_status;
    106         port_status.raw_value = pio_read_16( port->address );
     106        port_status_t port_status
     107                = port_status_read(port->address);
    107108
    108109        /* enable port: register write */
     110        if (enabled) {
     111                port_status |= STATUS_ENABLED;
     112        } else {
     113                port_status &= ~STATUS_ENABLED;
     114        }
     115        port_status_write( port->address, port_status );
     116
     117/*
    109118        port_status.status.enabled = enabled;
    110119        pio_write_16( port->address, port_status.raw_value );
     120*/
    111121
    112122        uhci_print_info( "%s port %d.\n",
  • uspace/drv/uhci/root_hub/port.h

    r15701921 r8f748215  
    3939#include <stdint.h>
    4040
    41 typedef uint16_t uhci_port_reg_t;
     41#include "port_status.h"
    4242
    4343typedef struct uhci_port
    4444{
    45         uhci_port_reg_t *address;
     45        port_status_t *address;
    4646        device_t *hc;
    4747        unsigned number;
     
    5151
    5252static inline void uhci_port_init(
    53   uhci_port_t *port, uhci_port_reg_t *address, device_t *hc, unsigned number,
     53  uhci_port_t *port, port_status_t *address, device_t *hc, unsigned number,
    5454  unsigned usec)
    5555{
  • uspace/drv/uhci/root_hub/port_status.c

    r15701921 r8f748215  
    22#include <stdio.h>
    33
     4#include "debug.h"
    45#include "port_status.h"
    56
    6 void print_port_status( const port_status_t *status )
     7struct flag_name
    78{
    8         assert( status );
    9         printf( "\tsuspended: %s\n", status->status.suspended ? "YES" : "NO" );
    10         printf( "\tin reset: %s\n", status->status.reset ? "YES" : "NO" );
    11         printf( "\tlow speed: %s\n", status->status.low_speed ? "YES" : "NO" );
    12         printf( "\tresume detected: %s\n", status->status.resume ? "YES" : "NO" );
    13         printf( "\talways \"1\" reserved bit: %s\n",
    14           status->status.always_one ? "YES" : "NO" );
    15         /* line status skipped */
    16         printf( "\tenable/disable change: %s\n", status->status.enabled_change ? "YES" : "NO" );
    17         printf( "\tport enabled: %s\n", status->status.enabled ? "YES" : "NO" );
    18         printf( "\tconnect change: %s\n", status->status.connect_change ? "YES" : "NO" );
    19         printf( "\tconnected: %s\n", status->status.connected ? "YES" : "NO" );
     9        unsigned flag;
     10        const char *name;
     11};
     12
     13static const struct flag_name flags[] =
     14{
     15        { STATUS_SUSPEND, "suspended" },
     16        { STATUS_IN_RESET, "in reset" },
     17        { STATUS_LOW_SPEED, "low speed device" },
     18        { STATUS_ALWAYS_ONE, "always 1 bit" },
     19        { STATUS_RESUME, "resume" },
     20        { STATUS_LINE_D_MINUS, "line D- value" },
     21        { STATUS_LINE_D_PLUS, "line D+ value" },
     22        { STATUS_ENABLED_CHANGED, "enabled changed" },
     23        { STATUS_ENABLED, "enabled" },
     24        { STATUS_CONNECTED_CHANGED, "connected changed" },
     25        { STATUS_CONNECTED, "connected" }
     26};
     27
     28void print_port_status(port_status_t value)
     29{
     30        unsigned i = 0;
     31        for (;i < sizeof(flags)/sizeof(struct flag_name); ++i) {
     32                uhci_print_verbose("\t%s status: %s.\n", flags[i].name,
     33                  value & flags[i].flag ? "ON" : "OFF");
     34        }
    2035}
  • uspace/drv/uhci/root_hub/port_status.h

    r15701921 r8f748215  
    3535#define DRV_UHCI_TD_PORT_STATUS_H
    3636
     37#include <libarch/ddi.h>
    3738#include <stdint.h>
    3839
    39 struct port_register {
    40         uint8_t connected:1;
    41         uint8_t connect_change:1;
    42         uint8_t enabled:1;
    43         uint8_t enabled_change:1;
    44         uint8_t line:2;
    45         uint8_t resume:1;
    46         const uint8_t always_one:1; /* reserved */
     40typedef uint16_t port_status_t;
    4741
    48         uint8_t low_speed:1;
    49         uint8_t reset:1;
    50         uint8_t :2; /* reserved */
    51         uint8_t suspended:1;
    52         uint8_t :3; /* reserved */
    53         /* first byte */
    54 //      uint8_t :3; /* reserved */
    55 //      uint8_t suspended:1;
    56 //      uint8_t :2; /* reserved */
    57 //      uint8_t reset:1;
    58 //      uint8_t low_speed:1;
     42enum {
     43        STATUS_CONNECTED         = 1 << 0,
     44        STATUS_CONNECTED_CHANGED = 1 << 1,
     45        STATUS_ENABLED           = 1 << 2,
     46        STATUS_ENABLED_CHANGED   = 1 << 3,
     47        STATUS_LINE_D_PLUS       = 1 << 4,
     48        STATUS_LINE_D_MINUS      = 1 << 5,
     49        STATUS_RESUME            = 1 << 6,
     50        STATUS_ALWAYS_ONE        = 1 << 7,
    5951
    60         /* second byte */
    61 //      uint8_t :1; /* reserved */
    62 //      uint8_t resume:1;
    63 //      uint8_t line:2;
    64 //      uint8_t enabled_change:1;
    65 //      uint8_t enabled:1;
    66 //      uint8_t connect_change:1;
    67 //      uint8_t connected:1;
    68 } __attribute__((packed));
     52        STATUS_LOW_SPEED = 1 <<  8,
     53        STATUS_IN_RESET  = 1 <<  9,
     54        STATUS_SUSPEND   = 1 << 12,
     55};
    6956
    70 typedef union port_status {
    71         struct port_register status;
    72         uint16_t raw_value;
    73 } port_status_t;
     57static inline port_status_t port_status_read(port_status_t * address)
     58        { return pio_read_16(address); }
    7459
    75 void print_port_status( const port_status_t *status );
     60static inline void port_status_write(
     61  port_status_t * address, port_status_t value)
     62        { pio_write_16(address, value); }
     63
     64void print_port_status(const port_status_t status);
    7665#endif
    7766/**
  • uspace/drv/uhci/root_hub/root_hub.c

    r15701921 r8f748215  
    1515
    1616        /* allow access to root hub registers */
    17         uhci_port_reg_t *regs;
     17        port_status_t *regs;
    1818        const int ret = pio_enable(
    19           addr, sizeof(uhci_port_reg_t) * UHCI_ROOT_HUB_PORT_COUNT, (void**)&regs);
     19          addr, sizeof(port_status_t) * UHCI_ROOT_HUB_PORT_COUNT, (void**)&regs);
    2020
    2121        if (ret < 0) {
Note: See TracChangeset for help on using the changeset viewer.