Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
112 user(s) are online (75 user(s) are browsing Forums)

Members: 0
Guests: 112

more...

Headlines

 
  Register To Post  

how to work properly with device when you need query every 5 seconds
Home away from home
Home away from home


See User information
The question comes up after finding that when you need one time in a 5-second query something from a serial device, then if you open-close device for every query, then you have 100% CPU load hit on that time. I.e there is init code:

BOOL initX5000serial(struct DockyData *dd)
{
    
BOOL res FALSE;
    
int8 err 0;

    
dd->port IExec->AllocSysObject(ASOT_PORTNULL);
    if(
dd->port)
    {
        
dd->req IExec->AllocSysObjectTags(ASOT_IOREQUESTASOIOR_Size,sizeof(struct IOExtSer),
                                            
ASOIOR_ReplyPort,dd->portTAG_DONE);
        if(
dd->req)
        {
            
            if(
IExec->OpenDevice("serial.device"1, (struct IORequest*)dd->req0) != -1)
            {
                
// Set parameters to address MCU 
                
dd->req->IOSer.io_Command SDCMD_SETPARAMS;
                
dd->req->io_Baud      38400// 38400 Baud
                
dd->req->io_ReadLen   8;     // 8 bit data
                
dd->req->io_WriteLen  8;     // 8 bit data
                
dd->req->io_StopBits  1;     // 1 Stop bit
                
dd->req->io_SerFlags &= ~SERF_PARTY_ON// No Parity
                
dd->req->io_SerFlags |= SERF_XDISABLED// No Flow Control
                
err IExec->DoIO( (struct IORequest*)dd->req );
                if(
err == IOERR_SUCCESS)
                {
                    
res TRUE;
                }
            }
        }
    }
    return(
res);
}



There is de-init code:

void closeX5000serial(struct DockyData *dd)
{
    if(
dd->dev_open) { IExec->CloseDevice( (struct IORequest*)dd->req ); dd->dev_open FALSE; }
    if(
dd->req) { IExec->FreeSysObject(ASOT_IOREQUESTdd->req); dd->req NULL; }
    if(
dd->port) { IExec->FreeSysObject(ASOT_PORTdd->port); dd->port NULL; }
}



Now if we do something like:

dd->dev_open initX5000serial(dd);
  if(
dd->dev_open)
  {
   
QueryTemp(dd);
   
QueryVoltFan(dd);
  }


We then hit 100% CPU loading every time we query our stuff.

If I remember right, it is correct to open/close the device for every query, right? And it should be not opened all the time?

Any advice is welcome, thanks!

Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: how to work properly with device when you need query every 5 seconds
Just popping in
Just popping in


See User information
@kas1e

Whether you should leave a device open or not depends on the use case. Could other programs need to access it in between your accesses? Will your having the device open block other accesses? (I'm too lazy to read the serial.device AutoDoc right now )

Again, I'm not sure of the use case. My guess is you have custom monitoring hardware attached to one of the X5000's serial headers. Or is it standard? Ideally, there would be a hardware monitor API that would share out this information to multiple listeners. Then it wouldn't matter much if the "API" blocked other direct access to the serial device.

Go to top

  Register To Post

 




Currently Active Users Viewing This Thread: 1 ( 0 members and 1 Anonymous Users )




Powered by XOOPS 2.0 © 2001-2023 The XOOPS Project