Can you setup uvm_backdoor access for a single register in UVM? - uvm

I am trying to use the add_hdl_path and add_hdl_path_slice methods to configure backdoor accesss for a specific register in our register package.
Can you setup uvm_backdoor for single register or do you need to setup the entire register map?
I get errors like:
Block does not have hdl path defined for abstraction 'RTL'.
Which seems like it is looking for the "RTL" queue of hdl paths for its parent uvm_reg_block.

You can set the hdl path for the top most wrapper of the reg model. After that you can set the relative path to individual registers and you should be able to access the registers individually.
top_reg_block.set_hdl_path_root("top_tb");
individual register
top_reg_block.block_level.reg.add_hdl_path_slice("dut.block.reg", 0, 1);
OR
top_reg_block.block_level.reg.add_hdl_path('{ '{"dut.block.reg", 0, 1} } );

Related

What device state can the store parameter (1010) in the canopen object dictionary be wrriten to

I am trying to figure out, what state I can store the current configuration by writing to the store index 1010.01 in the CANopen object dictionary.
I tried doing it in the preoperational state but got this error
Time: 2914.034 SDO slave:1 index:1010.01 error:08000022 Data cannot be transferred or stored to the application because of the present device state
uint32_t store_password = 0x65766173;
ret = ec_SDOwrite(slave, 0x1010, 0x01, FALSE, sizeof(store_password), &store_password, EC_TIMEOUTTXM);
It is worth noting that I am using CANopen over EtherCAT with the SOEM library.
This sounds like non-compliant behavior. As far as I know, CANopen does not specify which state you must be in when writing to 1010h.
I would recommend to always do this in the pre-operational state, since writing to flash etc might be time consuming and interrupt real-time behavior, if executed from the operational state (and SDO timeouts might occur).
Non-related to the question, it would be more readable to use this:
const char store_password [4] = "save"; // null termination purposely ignored
... sizeof(store_password), store_password, ...
This also removes the endianess dependency in your current code.

Access Shared Preferences externally / Store a value into a new file and access it externally

I have the two following methods and I am using them to store a special value locally and be able to access it on application restart:
(Store value locally:)
private void SaveSet(string key, string value)
{
ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(this);
ISharedPreferencesEditor prefEditor = prefs.Edit();
prefEditor.PutString(key, value);
// editor.Commit(); // applies changes synchronously on older APIs
prefEditor.Apply(); // applies changes asynchronously on newer APIs
}
(Read it again:)
private string RetrieveSet(string key)
{
ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(this);
return prefs.GetString(key, null);
}
This works perfectly. Now is it possible to access and edit this Shared Preferences externally? Unfortunately, I cannot find any file when searching in folder
Phone\Android\data\com.<company_name>.<application_name>\files
nor anywhere else. I want / try to edit this value from my computer, after connecting the phone to it. Is this possible?
Alternatively: Can anyone maybe show me how to create a new file in the given path above, write/read it programmatically and how it stays there, even if application is closed / started again? So I can then edit this file with my computer anyhow?
I tried it with the following code, but unfortunately it doesn't work / no file is created or at least i cannot see it in the given path above:
//"This code snippet is one example of writing an integer to a UTF-8 text file to the internal storage directory of an application:"
public void SaveValueIntoNewFile(int value)
{
var backingFile = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "newFile.txt");
using (var writer = System.IO.File.CreateText(backingFile))
{
writer.WriteLine(value.ToString());
}
}
Would be very happy about every answer, thanks in advance and best regards
What you're looking for is where Android stores the Shared Preference file for applications that make use of it's default PreferenceManager.
I'd refer to this SO post which answers your question pretty well
SharedPreferences are stored in an xml file in the app data folder,
i.e.
/data/data/YOUR_PACKAGE_NAME/shared_prefs/YOUR_PREFS_NAME.xml
or the default preferences at:
/data/data/YOUR_PACKAGE_NAME/shared_prefs/YOUR_PACKAGE_NAME_preferences.xml
SharedPreferences added during runtime are not stored in the Eclipse
project.
Note: Accessing /data/data/ requires superuser
privileges
A simple method is to use Android Device Monotor,you can open it by clicking Tools--> android-->Android Device Monotor...
For example:
The path in my device is as follows:
/data/data/YOUR_PACKAGE_NAME/shared_prefs/YOUR_PACKAGE_NAME_preferences.xml
And we notice three buttons in the upper right corner of the picture.
The first one is used toPull a file from the device,the second one is used to Push a file onto the device,and the last one is used to delete the preferences.xml file.
So we can pull the preferences.xml file from current device to our computer and edit it as we want, and then push the updated preferences.xml to the folder again.Then we will get the value of preferences.xml file .

send_v3trap context value

I am developing shared library and subagent for net-snmp. I need to send v3 traps for specific hardware events. I would like to know what value need to be filled in the context value of send_v3trap API.
void send_v3trap(netsnmp_variable_list * vars,const char * context )
Is this context value, same as user defined engine id ? i.e., the one which needs to be configured in snmptrapd.conf as below ?
createUser -e ENGINEID myuser SHA "my authentication pass" AES "my encryption pass"
More on configuring in this link
There is an example source code available for sending
v2traps
By looking at the net-snmp source code, send_v3trap calls internally send_v2trap and eventually,
/* A context name was provided, so copy it and its length to the v2 pdu
* template. */
if (context != NULL)
{
template_v2pdu->contextName = strdup(context);
template_v2pdu->contextNameLen = strlen(context);
}
Answering my own question.
"context" value can be filled with
value returned by "snmpv3_get_engineID"
NULL
As long as, configurations are proper in terms of v3 i.e., trapsess -v3 specified in the host and on the target, engineid of net-snmp is specified, then everything works fine.
Only unclear part still is, if someone is able to send v3 traps without specifying "context", in which scenario would it be useful really !

Dependency reset design pattern (embedded C)

Folks, I am working on an embedded system in C that uses an I2C module. Other modules that use the I2C have the I2C module as a dependency, or "child system". They pass it message context structs and when the I2C module is ready it asynchronously sends or reads messages as the context instructs, running a callback from the context to let the overlying module know the work has completed, successfully or with error.
I would like the I2C module to be able to recover itself from errors i.e. reset external connected hardware, itself and then reinitialise the external devices. the former two of these three actions can be handled internal to the I2C module with no problem, however the I2C module doesn't know what overlying modules may want to use it and need to send data to external devices to configure them again after their earlier hardware reset.
The message contexts could have callbacks to reinitialisation functions, but the I2C module only holds a reference to one of these at a time, the one it is currently working on how would it know to call the reinitialise handle for the next time a different module (with reset hardware) wants to talk to it's external hardware? the overlying module doesn't know the I2C has been reset, and the I2C module doesn't know if the overlying module has performed its reinitialisation sequence or not, or even if it needs to.
Is there a common design pattern to ameliorate such a problem?
To illustrate differently:
Normal initialisation of I2C and external hardware sequence:
initExtIOExpander() {
context_t initialisationMsg = {/*...*/};
i2cSend(&initialisationMsg )
}
initExtADC() {
context_t initialisationMsg = {/*...*/};
i2cSend(&initialisationMsg )
}
i2cSend() {
// Start sending data using passed context,
}
interrupt i2c_isr() {
//If the message completed run the callback handle in the current context
// else do the next part of the message, etc.
}
main () {
//...
initI2c();
initExtIOExpander();
initExtADC();
//...
// Use external devices here.
//
}
Reset and reinitialisation sequence:
If the normal sequence from above has already happened but now the I2C ISR is altered to detects errors:
interrupt i2c_isr () {
//If there was an error reset external H/W, and own H/W
// but how to know to call initExtIOExpander() and initExtADC()??
// this module might know about the ADC if it is processing and ADC
// message but it has "forgotten" about the IO expander or any other
// device
// else if the message completed run the callback handle in the current
// context
// else do the next part of the message, etc.
}
Thanks!
What about to put all your devies initialisation to 'aggregate' function and call it when need?
void init_all_i2c_devices(void) {
initExtIOExpander();
initExtADC();
...
}
interrupt i2c() {
....
init_all_i2c_devices();// or i2c_init_callback()
}
main() {
init_i2c();
init_all_i2c_devices();
// set_i2c_init_callback(init_all_i2c_devices) if need
}
For design patterns in the embedded context take a look here and here.
Especially the watchdog timer fits your case.
I think it is not the I2C module which should reset the HW.

Sharing a DNSServiceRef using kDNSServiceFlagsShareConnection stalls my program

I'm building a client using dns-sd api from Bonjour. I notice that there is a flag called kDNSServiceFlagsShareConnection that it is used to share the connection of one DNSServiceRef.
Apple site says
For efficiency, clients that perform many concurrent operations may want to use a single Unix Domain Socket connection with the background daemon, instead of having a separate connection for each independent operation. To use this mode, clients first call DNSServiceCreateConnection(&MainRef) to initialize the main DNSServiceRef. For each subsequent operation that is to share that same connection, the client copies the MainRef, and then passes the address of that copy, setting the ShareConnection flag to tell the library that this DNSServiceRef is not a typical uninitialized DNSServiceRef; it's a copy of an existing DNSServiceRef whose connection information should be reused.
There is even an example that shows how to use the flag. The problem i'm having is when I run the program it stays like waiting for something whenever I call a function with the flag. Here is the code:
DNSServiceErrorType error;
DNSServiceRef MainRef, BrowseRef;
error = DNSServiceCreateConnection(&MainRef);
BrowseRef = MainRef;
//I'm omitting when I check for errors
error = DNSServiceBrowse(&MainRef, kDNSServiceFlagsShareConnection, 0, "_http._tcp", "local", browse_reply, NULL);
// After this call the program stays waiting for I don't know what
//I'm omitting when I check for errors
error = DNSServiceBrowse(&BrowseRef, kDNSServiceFlagsShareConnection, 0, "_http._tcp", "local", browse_reply, NULL);
//I'm omitting when i check for errors
DNSServiceRefDeallocate(BrowseRef); // Terminate the browse operation
DNSServiceRefDeallocate(MainRef); // Terminate the shared connection
Any ideas? thoughts? suggestion?
Since there are conflicting answers, I dug up the source - annotations by me.
// If sharing...
if (flags & kDNSServiceFlagsShareConnection)
{
// There must be something to share (can't use this on the first call)
if (!*ref)
{
return kDNSServiceErr_BadParam;
}
// Ref must look valid (specifically, ref->fd)
if (!DNSServiceRefValid(*ref) ||
// Most operations cannot be shared.
((*ref)->op != connection_request &&
(*ref)->op != connection_delegate_request) ||
// When sharing, pass the ref from the original call.
(*ref)->primary)
{
return kDNSServiceErr_BadReference;
}
The primary fiels is explained elsewhere:
// When using kDNSServiceFlagsShareConnection, there is one primary _DNSServiceOp_t, and zero or more subordinates
// For the primary, the 'next' field points to the first subordinate, and its 'next' field points to the next, and so on.
// For the primary, the 'primary' field is NULL; for subordinates the 'primary' field points back to the associated primary
The problem with the question is that DNSServiceBrowse maps to ref->op==browse_request which causes a kDNSServiceErr_BadReference.
It looks like kDNSServiceFlagsShareConnection is half-implemented, because I've also seen cases in which it works - this source was found by tracing back when it didn't work.
Service referenses for browsing and resolving may unfortunately not be shared. See the comments in the Bonjour documentation for the kDNSServiceFlagsShareConnection-flag. Since you only browse twice I would just let them have separate service-refs instead.
So both DNSServiceBrowse() and DNSServiceResolve() require an unallocated service-ref as first parameter.
I can't explain why your program chokes though. The first DNSServiceBrowse() call in your example should return immediately with an error code.
Although an old question, but it should help people looking around for answers now.
The answer by vidtige is incorrect, the may be shared for any operation, provided you pass the 'kDNSServiceFlagsShareConnection' flag along with the arguments. Sample below -
m_dnsrefsearch = m_dnsservice;
DNSServiceErrorType mdnserr = DNSServiceBrowse(&m_dnsrefsearch,kDNSServiceFlagsShareConnection,0,
"_workstation._tcp",NULL,
DNSServiceBrowseReplyCallback,NULL);
Reference - http://osxr.org/android/source/external/mdnsresponder/mDNSShared/dns_sd.h#0267

Resources