Changeset 414 for branches

Show
Ignore:
Timestamp:
02/22/07 10:55:06 (16 years ago)
Author:
pieterpalmers
Message:

extended ARM handler functionality

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/streaming-rework/configure.ac

    r407 r414  
    2525m4_define(freebob_major_version, 1) 
    2626m4_define(freebob_minor_version, 999) 
    27 m4_define(freebob_micro_version, 2
     27m4_define(freebob_micro_version, 3
    2828 
    2929m4_define(freebob_version, freebob_major_version.freebob_minor_version.freebob_micro_version) 
  • branches/streaming-rework/src/libieee1394/ieee1394service.cpp

    r413 r414  
    2020 */ 
    2121#include "ieee1394service.h" 
     22#include "ARMHandler.h" 
    2223 
    2324#include <libavc1394/avc1394.h> 
     
    5758    stopRHThread(); 
    5859 
    59     for ( arm_mapping_vec_t::iterator it = m_arm_mappings.begin(); 
    60           it != m_arm_mappings.end(); 
     60    for ( arm_handler_vec_t::iterator it = m_armHandlers.begin(); 
     61          it != m_armHandlers.end(); 
    6162          ++it ) 
    6263    { 
    63         debugOutput(DEBUG_LEVEL_VERBOSE, "Unregistering ARM handler for 0x%016llX\n", (*it)->start); 
    64         int err=raw1394_arm_unregister(m_resetHandle, (*it)->start); 
     64        debugOutput(DEBUG_LEVEL_VERBOSE, "Unregistering ARM handler for 0x%016llX\n", (*it)->getStart()); 
     65        int err=raw1394_arm_unregister(m_resetHandle, (*it)->getStart()); 
    6566        if (err) { 
    66             debugError(" Failed to unregister ARM handler for 0x%016llX\n", (*it)->start); 
     67            debugError(" Failed to unregister ARM handler for 0x%016llX\n", (*it)->getStart()); 
    6768            debugError(" Error: %s\n", strerror(errno)); 
    68         } else { 
    69             delete *it; 
    7069        } 
    7170    } 
     
    146145            "read: node 0x%X, addr = 0x%016llX, length = %u\n", 
    147146            nodeId, addr, length); 
    148         printBuffer( length, buffer ); 
     147        printBuffer( DEBUG_LEVEL_VERY_VERBOSE, length, buffer ); 
    149148        #endif 
    150149 
     
    190189    debugOutput(DEBUG_LEVEL_VERY_VERBOSE,"write: node 0x%X, addr = 0x%016X, length = %d\n", 
    191190                nodeId, addr, length); 
    192     printBuffer( length, data ); 
     191    printBuffer( DEBUG_LEVEL_VERY_VERBOSE, length, data ); 
    193192    #endif 
    194193 
     
    226225    #ifdef DEBUG 
    227226    debugOutputShort(DEBUG_LEVEL_VERY_VERBOSE, "  pre avc1394_transaction_block2\n" ); 
    228     printBuffer( len, buf ); 
     227    printBuffer( DEBUG_LEVEL_VERY_VERBOSE, len, buf ); 
    229228    #endif 
    230229 
     
    239238    #ifdef DEBUG 
    240239    debugOutputShort(DEBUG_LEVEL_VERY_VERBOSE, "  post avc1394_transaction_block2\n" ); 
    241     printBuffer( *resp_len, result ); 
     240    printBuffer( DEBUG_LEVEL_VERY_VERBOSE, *resp_len, result ); 
    242241    #endif 
    243242 
     
    271270 
    272271void 
    273 Ieee1394Service::printBuffer( size_t length, fb_quadlet_t* buffer ) const 
     272Ieee1394Service::printBuffer( unsigned int level, size_t length, fb_quadlet_t* buffer ) const 
    274273{ 
    275274 
     
    277276        if ( ( i % 4 ) == 0 ) { 
    278277            if ( i > 0 ) { 
    279                 debugOutputShort(DEBUG_LEVEL_VERY_VERBOSE,"\n"); 
     278                debugOutputShort(level,"\n"); 
    280279            } 
    281             debugOutputShort(DEBUG_LEVEL_VERY_VERBOSE," %4d: ",i*4); 
    282         } 
    283         debugOutputShort(DEBUG_LEVEL_VERY_VERBOSE,"%08X ",buffer[i]); 
    284     } 
    285     debugOutputShort(DEBUG_LEVEL_VERY_VERBOSE,"\n"); 
     280            debugOutputShort(level," %4d: ",i*4); 
     281        } 
     282        debugOutputShort(level,"%08X ",buffer[i]); 
     283    } 
     284    debugOutputShort(level,"\n"); 
     285
     286void 
     287Ieee1394Service::printBufferBytes( unsigned int level, size_t length, byte_t* buffer ) const 
     288
     289 
     290    for ( unsigned int i=0; i < length; ++i ) { 
     291        if ( ( i % 16 ) == 0 ) { 
     292            if ( i > 0 ) { 
     293                debugOutputShort(level,"\n"); 
     294            } 
     295            debugOutputShort(level," %4d: ",i*16); 
     296        } 
     297        debugOutputShort(level,"%02X ",buffer[i]); 
     298    } 
     299    debugOutputShort(level,"\n"); 
    286300} 
    287301 
     
    314328} 
    315329 
    316 bool Ieee1394Service::registerARMrange(nodeaddr_t start, 
    317                      size_t length, byte_t *initial_value, 
    318                      arm_options_t access_rights, 
    319                      arm_options_t notification_options, 
    320                      arm_options_t client_transactions, 
    321                      Functor* functor) { 
    322     debugOutput(DEBUG_LEVEL_VERBOSE, "Registering ARM handler for 0x%016llX, length %u\n", start,length); 
    323                       
    324     arm_mapping_t *new_mapping=NULL; 
    325     new_mapping = new arm_mapping_t; 
    326      
    327     new_mapping->start=start; 
    328     new_mapping->length=length; 
    329     new_mapping->access_rights=access_rights; 
    330     new_mapping->notification_options=notification_options; 
    331     new_mapping->client_transactions=client_transactions; 
    332     new_mapping->functor=functor; 
    333      
    334     int err=raw1394_arm_register(m_resetHandle, start,  
    335                          length, initial_value, (octlet_t)new_mapping, 
    336                          access_rights, 
    337                          notification_options, 
    338                          client_transactions); 
     330bool Ieee1394Service::registerARMhandler(ARMHandler *h) { 
     331    debugOutput(DEBUG_LEVEL_VERBOSE, "Registering ARM handler (%p) for 0x%016llX, length %u\n", 
     332        h, h->getStart(), h->getLength()); 
     333 
     334    int err=raw1394_arm_register(m_resetHandle, h->getStart(),  
     335                         h->getLength(), h->getBuffer(), (octlet_t)h, 
     336                         h->getAccessRights(), 
     337                         h->getNotificationOptions(), 
     338                         h->getClientTransactions()); 
    339339    if (err) { 
    340         debugError("Failed to register ARM handler for 0x%016llX\n", start); 
     340        debugError("Failed to register ARM handler for 0x%016llX\n", h->getStart()); 
    341341        debugError(" Error: %s\n", strerror(errno)); 
    342         delete new_mapping; 
    343342        return false; 
    344343    } 
    345344     
    346     m_arm_mappings.push_back( new_mapping ); 
    347  
    348     return true; 
    349 
    350  
    351 bool Ieee1394Service::unregisterARMrange( nodeaddr_t start ) { 
    352     debugOutput(DEBUG_LEVEL_VERBOSE, "Unregistering ARM handler for 0x%016llX\n", start); 
    353      
    354     for ( arm_mapping_vec_t::iterator it = m_arm_mappings.begin(); 
    355           it != m_arm_mappings.end(); 
     345    m_armHandlers.push_back( h ); 
     346 
     347    return true; 
     348
     349 
     350bool Ieee1394Service::unregisterARMhandler( ARMHandler *h ) { 
     351    debugOutput(DEBUG_LEVEL_VERBOSE, "Unregistering ARM handler (%p) for 0x%016llX\n",  
     352        h, h->getStart()); 
     353     
     354    for ( arm_handler_vec_t::iterator it = m_armHandlers.begin(); 
     355          it != m_armHandlers.end(); 
    356356          ++it ) 
    357357    { 
    358         if((*it)->start == start) { 
    359             int err=raw1394_arm_unregister(m_resetHandle, start); 
     358        if((*it) == h) { 
     359            int err=raw1394_arm_unregister(m_resetHandle, h->getStart()); 
    360360            if (err) { 
    361                 debugError("Failed to unregister ARM handler for 0x%016llX\n", start); 
     361                debugError("Failed to unregister ARM handler (%p)\n", h); 
    362362                debugError(" Error: %s\n", strerror(errno)); 
    363363            } else { 
    364                 m_arm_mappings.erase(it); 
    365                 delete *it; 
     364                m_armHandlers.erase(it); 
    366365                return true; 
    367366            } 
    368367        } 
    369368    } 
    370     debugOutput(DEBUG_LEVEL_VERBOSE, " no handler found!\n"); 
    371      
     369    debugOutput(DEBUG_LEVEL_VERBOSE, " handler not found!\n"); 
     370 
    372371    return false; 
    373372} 
    374      
     373/** 
     374 * @brief Tries to find a free ARM address range 
     375 * 
     376 * @param start  address to start with 
     377 * @param length length of the block needed (bytes) 
     378 * @param step   step to use when searching (bytes) 
     379 * @return The base address that is free, and 0xFFFFFFFFFFFFFFFF when failed 
     380 */ 
     381nodeaddr_t Ieee1394Service::findFreeARMBlock( nodeaddr_t start, size_t length, size_t step ) { 
     382    debugOutput(DEBUG_LEVEL_VERBOSE, "Finding free ARM block of %d bytes, from 0x%016llX in steps of %d bytes\n", 
     383        length, start, step); 
     384         
     385    int cnt=0; 
     386    const int maxcnt=10; 
     387    int err=1; 
     388    while(err && cnt++ < maxcnt) { 
     389        // try to register 
     390        err=raw1394_arm_register(m_resetHandle, start, length, 0, 0, 0, 0, 0); 
     391         
     392        if (err) { 
     393            debugOutput(DEBUG_LEVEL_VERBOSE, " -> cannot use 0x%016llX\n", start); 
     394            debugError("    Error: %s\n", strerror(errno)); 
     395            start += step; 
     396        } else { 
     397            debugOutput(DEBUG_LEVEL_VERBOSE, " -> use 0x%016llX\n", start); 
     398            err=raw1394_arm_unregister(m_resetHandle, start); 
     399            if (err) { 
     400                debugOutput(DEBUG_LEVEL_VERBOSE, " error unregistering test handler\n"); 
     401                debugError("    Error: %s\n", strerror(errno)); 
     402                return 0xFFFFFFFFFFFFFFFFLLU; 
     403            } 
     404            return start; 
     405        } 
     406    } 
     407    debugOutput(DEBUG_LEVEL_VERBOSE, " Could not find free block in %d tries\n",cnt); 
     408    return 0xFFFFFFFFFFFFFFFFLLU; 
     409     
     410
     411 
    375412int  
    376413Ieee1394Service::armHandlerLowLevel(raw1394handle_t handle,  
     
    391428                     void *data) 
    392429{ 
    393     for ( arm_mapping_vec_t::iterator it = m_arm_mappings.begin(); 
    394           it != m_arm_mappings.end(); 
     430    for ( arm_handler_vec_t::iterator it = m_armHandlers.begin(); 
     431          it != m_armHandlers.end(); 
    395432          ++it ) 
    396433    { 
    397         if((*it) == (arm_mapping_t *)arm_tag) { 
    398             debugOutput(DEBUG_LEVEL_VERBOSE,"ARM handler for address 0x%016llX called\n", (*it)->start); 
    399             Functor* func = (*it)->functor; 
    400             ( *func )(); 
     434        if((*it) == (ARMHandler *)arm_tag) { 
     435            struct raw1394_arm_request_response *arm_req_resp; 
     436            arm_req_resp  = (struct raw1394_arm_request_response *) data; 
     437            raw1394_arm_request_t arm_req=arm_req_resp->request; 
     438            raw1394_arm_response_t arm_resp=arm_req_resp->response; 
     439             
     440            debugOutput(DEBUG_LEVEL_VERBOSE,"ARM handler for address 0x%016llX called\n", 
     441                (*it)->getStart()); 
     442            debugOutput(DEBUG_LEVEL_VERBOSE," request type   : 0x%02X\n",request_type); 
     443            debugOutput(DEBUG_LEVEL_VERBOSE," request length : %04d\n",requested_length); 
     444             
     445            switch(request_type) { 
     446                case RAW1394_ARM_READ: 
     447                    (*it)->handleRead(arm_req); 
     448                    *arm_resp=*((*it)->getResponse()); 
     449                    break; 
     450                case RAW1394_ARM_WRITE: 
     451                    (*it)->handleWrite(arm_req); 
     452                    *arm_resp=*((*it)->getResponse()); 
     453                    break; 
     454                case RAW1394_ARM_LOCK: 
     455                    (*it)->handleLock(arm_req); 
     456                    *arm_resp=*((*it)->getResponse()); 
     457                    break; 
     458                default: 
     459                    debugWarning("Unknown request type received, ignoring...\n"); 
     460            } 
     461 
    401462            return true; 
    402463        } 
  • branches/streaming-rework/src/libieee1394/ieee1394service.h

    r413 r414  
    11/* Ieee1394Service.cpp 
    22 * Copyright (C) 2005,06 by Daniel Wagner 
     3 * Copyright (C) 2007 by Pieter Palmers 
    34 * 
    45 * This file is part of FreeBoB. 
     
    3233#include <vector> 
    3334 
     35class ARMHandler; 
     36 
    3437class Ieee1394Service{ 
    3538public: 
     
    127130     
    128131    /** 
    129      * @brief register an AddressRangeMapping 
    130      * 
    131      * @param start          identifies addressrange 
    132      * @param length         identifies addressrange length 
    133      * @param initial_value  pointer to buffer containing (if necessary) initial value 
    134      *                    NULL means undefined 
    135      * @param access_rights access-rights for registered addressrange handled  
    136      *                    by kernel-part. Value is one or more binary or of the  
    137      *                    following flags - ARM_READ, ARM_WRITE, ARM_LOCK 
    138      * @param notification_options identifies for which type of request you want 
    139      *                    to be notified. Value is one or more binary or of the  
    140      *                    following flags - ARM_READ, ARM_WRITE, ARM_LOCK 
    141      * @param client_transactions identifies for which type of request you want 
    142      *                    to handle the request by the client application. 
    143      *                    for those requests no response will be generated, but 
    144      *                    has to be generated by the application. 
    145      *                    Value is one or more binary or of the  
    146      *                    following flags - ARM_READ, ARM_WRITE, ARM_LOCK 
    147      *                    For each bit set here, notification_options and 
    148      *                    access_rights will be ignored. 
    149      * @param functor the function to call when this range is written to 
     132     * @brief register an AddressRangeMapping Handler 
     133     * @param h pointer to the handler to register 
    150134     * 
    151135     * @return true on success or false on failure 
    152136     **/ 
    153137 
    154     bool registerARMrange(nodeaddr_t start, 
    155                          size_t length, byte_t *initial_value, 
    156                          arm_options_t access_rights, 
    157                          arm_options_t notification_options, 
    158                          arm_options_t client_transactions, 
    159                          Functor* functor); 
     138    bool registerARMhandler( ARMHandler *h ); 
    160139 
    161140    /** 
    162141     * @brief unregister ARM range 
    163      * @param start identifies addressrange 
     142     * @param h pointer to the handler to unregister 
    164143     * @return true if successful, false otherwise 
    165144     */ 
    166     bool unregisterARMrange( nodeaddr_t start ); 
     145    bool unregisterARMhandler( ARMHandler *h ); 
     146     
     147    nodeaddr_t findFreeARMBlock( nodeaddr_t start, size_t length, size_t step ); 
    167148 
    168149// ISO channel stuff 
     
    203184    static void* rHThread( void* arg ); 
    204185 
    205     void printBuffer( size_t length, fb_quadlet_t* buffer ) const; 
    206  
     186    void printBuffer( unsigned int level, size_t length, fb_quadlet_t* buffer ) const; 
     187    void printBufferBytes( unsigned int level, size_t length, byte_t* buffer ) const; 
     188     
    207189    static int resetHandlerLowLevel( raw1394handle_t handle, 
    208190                    unsigned int generation ); 
     
    231213    arm_tag_handler_t m_default_arm_handler; 
    232214     
    233     typedef struct arm_mapping { 
    234         nodeaddr_t start; 
    235         size_t length; 
    236         arm_options_t access_rights; 
    237         arm_options_t notification_options; 
    238         arm_options_t client_transactions; 
    239         Functor* functor; 
    240     } arm_mapping_t; 
    241      
    242     typedef std::vector< arm_mapping_t* > arm_mapping_vec_t; 
    243     arm_mapping_vec_t m_arm_mappings; 
     215    typedef std::vector< ARMHandler * > arm_handler_vec_t; 
     216    arm_handler_vec_t m_armHandlers; 
    244217     
    245218    DECLARE_DEBUG_MODULE; 
  • branches/streaming-rework/src/Makefile.am

    r413 r414  
    3232libfreebob_la_LIBADD = -lrt 
    3333 
    34 noinst_HEADERS = libieee1394/configrom.h libieee1394/csr1212.h \ 
    35     libieee1394/ieee1394service.h debugmodule/debugmodule.h \ 
     34noinst_HEADERS = \ 
     35    libieee1394/configrom.h libieee1394/csr1212.h \ 
     36    libieee1394/ieee1394service.h libieee1394/ARMHandler.h \ 
     37    debugmodule/debugmodule.h \ 
    3638        devicemanager.h fbtypes.h iavdevice.h threads.h bebob/bebob_avdevice.h \ 
    3739        bebob/bebob_avdevice_subunit.h bebob/bebob_avplug.h bebob/bebob_dl_bcd.h bebob/bebob_dl_codes.h \ 
     
    7678        libfreebobavc/avc_subunit_info.cpp \ 
    7779        libfreebobavc/avc_unit_info.cpp \ 
     80        libieee1394/ARMHandler.cpp \ 
    7881        libieee1394/configrom.cpp \ 
    7982        libieee1394/csr1212.c \ 
  • branches/streaming-rework/tests/test-ieee1394service.cpp

    r413 r414  
    3636#include "src/libieee1394/configrom.h" 
    3737#include "src/libieee1394/ieee1394service.h" 
     38#include "src/libieee1394/ARMHandler.h" 
    3839 
    3940#include <libraw1394/raw1394.h> 
     
    6465 
    6566    printf("Freebob Ieee1394Service test application\n"); 
    66  
    67     MyFunctor *test_busreset=new MyFunctor(); 
    68     MyFunctor *test_arm=new MyFunctor(); 
    69  
     67     
    7068    Ieee1394Service *m_service=NULL; 
    7169 
     
    7371    m_service->initialize(2); 
    7472     
     73    MyFunctor *test_busreset=new MyFunctor(); 
     74     
    7575    printf(" adding (%p) as busreset handler\n", test_busreset); 
    7676     
    77     m_service->addBusResetHandler(test_busreset); 
     77    m_service->addBusResetHandler(test_busreset);     
     78     
     79    nodeaddr_t addr =  m_service->findFreeARMBlock(0x0000FFFFE0000000ULL, 4, 4 ); 
     80     
     81    ARMHandler *test_arm=new ARMHandler(addr, 
     82                         4, 
     83                         RAW1394_ARM_READ | RAW1394_ARM_WRITE | RAW1394_ARM_LOCK, 
     84                         RAW1394_ARM_READ | RAW1394_ARM_WRITE | RAW1394_ARM_LOCK, 
     85                         0); 
    7886     
    7987    printf(" adding (%p) as arm handler\n", test_arm); 
    8088     
    81     m_service->registerARMrange(0x0000FFFFE0000000ULL, 
    82                          8, NULL, 
     89    if (!m_service->registerARMhandler(test_arm)) { 
     90        printf("  failed\n"); 
     91    } 
     92     
     93    addr =  m_service->findFreeARMBlock(0x0000FFFFE0000000ULL, 4, 4 ); 
     94                          
     95    ARMHandler *test_arm2=new ARMHandler(addr, 
     96                         4, 
    8397                         RAW1394_ARM_READ | RAW1394_ARM_WRITE | RAW1394_ARM_LOCK, 
    8498                         RAW1394_ARM_READ | RAW1394_ARM_WRITE | RAW1394_ARM_LOCK, 
    85                          0, 
    86                          test_arm); 
     99                         0); 
     100 
     101    printf(" adding (%p) as arm handler\n", test_arm2); 
     102     
     103    if (!m_service->registerARMhandler(test_arm2)) { 
     104        printf("  failed\n"); 
     105    } 
    87106     
    88107    while(run) { 
     
    91110        sleep(1); 
    92111    } 
    93      
     112 
    94113    delete m_service; 
    95114    delete test_busreset; 
    96115    delete test_arm; 
     116    delete test_arm2; 
    97117     
    98118    printf("Bye...\n");