why CMSIS does not offer a functo to read an IRQ enable/disable status? - cmsis

functions NVIC_EnableIRQ and NVIC_DisableIRQ are meant to enable and disable interrupts on a given IRQ number. Why there is no function to get the current enable/disable status of that IRQ?
The use case is the typical function that needs to disable a module's interrupt (IRQ) before proceeding. After the function is done then it will enable the IRQ again. But to be sure one needs to read first whether the IRQ was enabled at the moment the function was called.
Given that the function is not provided by CMSIS then I assume that my use case above is somehow flawed. But I do not see how.
Any hints?
Thanks
(using CMSIS 4.1)

I think your use case could make sense in some situations.
You'd have to create the function to read the enabled state of the IRQ by yourself.
You just need to make sure that no interrupt changes the enabled state between the reading of the enabled state and the actual disabling. In this case you would end up with setting the wrong enabled state after executing your function.
You can use __disable_irq(); to globally disable all irqs (Keil Syntax):
bool isEnabled;
__disable_irq();
isEnabled = ReadIrqEnabledState(irqNr);
__enable_irq();
yourFunction();
if(isEnabled)
NVIC_EnableIrq(irqNr);
else
NVIC_DisableIrq(irqNr);

You can use this function. It works fine...
inline bool IsIRQEnabled (IRQn_Type IRQn)
{
return (0 != (NVIC->ISER[(uint32_t)((int32_t)IRQn) >> 5] & (uint32_t)(1 << ((uint32_t)((int32_t)IRQn) & (uint32_t)0x1F))));
}

Related

Chisel randomly initialize register value when simulating with verilator

I'm using Chisel and blackbox to run my chisel logic against a verilog register file.
The registerfile does not have reset signal so I expect the register to be randomly initialized.
I passed the --x-initial unique to verilator,
Basically this is how I launch the test:
private val backendName = "verilator"
"NOCDMA" should s" do blkwrite and blkread correctly (with $backendName)" in {
Driver.execute(Array("--fint-write-vcd","--backend-name",s"$backendName",
"--more-vcs-flags","--trace-depth 1 --x-initial unique"),
()=>new DMANetworkWithMem(memAddrWidth,memDataWidth)(nocDataWidth)(nNodesX,nNodesY)){
c => new DMANetworkRWTest(c)
}
}
But The data I read from the register file is all zero before I wrote anything to it.
The read data is correct after I wrote to it.
So, is there anything inside chisel that I need to tune or I did not do everything properly ?
Any suggestions?
I'm not certain, but I found the following issue on Verilator with a similar issue: https://github.com/verilator/verilator/issues/1399.
From skimming the above issue, I think you also need to pass +verilator+seed+<value> and +verilator+rand+reset+<value> at runtime. I am not an expert in the iotesters, but I believe you can add these runtime values through the iotesters argument: --more-vcs-c-flags.
Side note, I would also set --x-assign unique in Verilator if there are cases in the Verilog where runtime would otherwise inject an X (eg. out-of-bounds index).
I hope this helps!

Can i Un-call a function in Common Lisp

I'm learning defclass and defmethod and defgeneric, so I made a defclass called savings-account with a member balance.
I created a defun (shown below) to begin to alter the value of balance, but it's not finished.
(defun balance (account)
(slot-value account 'balance))
Then I decided to go with a defgeneric (below) instead.
(defgeneric balance (account))
But when I ran the defgeneric I got this error:
BALANCE already names an ordinary function or a macro.
Is there a way to un-call or undeclare balance easily so I don't have to restart my Emacs session?
You can remove a function definition (created either with defun or defgeneric) with fmakunbound.
Any self-respecting Lisp will offer you an error restart to change the definition.
Here SLIME and Clozure CL:
The function BALANCE is defined as something other than a generic function.
[Condition of type CCL::SIMPLE-PROGRAM-ERROR]
Restarts:
0: [CONTINUE] Try to remove any global non-generic function or macro definition.
1: [RETRY] Retry SLIME REPL evaluation request.
2: [*ABORT] Return to SLIME's top level.
3: [ABORT-BREAK] Reset this thread
4: [ABORT] Kill this thread
Just select the CONTINUE restart by either typing 0 in that buffer or by selecting the respective line and pressing return.
Additionally to Xach's answer, using SLIME you can just move the text cursor on the function name and type c-c c-u, which calls SLIME-UNDEFINE-FUNCTION.

How to create & code a function which is used ONLY once - EVER! .... at first Start Up

I'm looking for some code where 'How to create & code a function which is used ONLY once - EVER! .... at first Start Up of AIR App.??? this I need to download the first set v1.0 of Xml base data files in an AIR Application and after that this particular function should never EVER be addressed again!
Any help would be appreciated regards aktell
a) write a function on init or CreationComplete event.
b) write an object extending objectproxy, introduce a flag, and allow it to use only if the flag is default, and then set the flag to other value.
c) write a static function with a static counter, and when you call it, check if counter != 0, to return, and counter++;
I think you have to use "SharedObject" in this case, so you can set a flag.
On each run the flag will be checked, if true or false you can trigger a function to execute.
Flex Mobile Development: storing data locally
you also can encrypt the stored data
Flex Mobile Development – Encrypting Data
Hope this will workout for you...
Sure you can, use the PersistenceManager to store a flag after first time run ,
for more info about PersistenceManager http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/spark/managers/PersistenceManager.html

Lwt and database access

I can't get my database access work with lwt. Should I include it in a thread? How? Or make a new thread which returns a 'a lwt value? If so, what to do with that value?
The same goes for Printf.eprintf, which also seems to be blocked by lwt. So I use Lwt_io instead. But why would lwt block regular io?
What I have is a simple db request like Db.update session. It is within an Lwt_main.run main function. All this is within a CGI script (should not matter, database access works fine until I start with the lwt commands).
I can give you more code if needed.
Regards
Olle
Edit
let main sock env =
(* code omitted *)
Gamesession.update_game_session env#db game_session_connected;
(* code omitted *)
Lwt_main.run (main sock_listen env)
Edit 2
This was the solution:
Lwt_preemptive.detach (fun () -> Db.call) ()
Printf.eprintf is not "blocked", it's just that the buffering parameters are changed and often messages do not display before the end of the program. You should try eprintf "something\n%!" (%! means "flush"), but yes it's better to use Lwt_io.
For the database, I don't know, you did not say which library you're using (at least the one called ocaml-mysql is not Lwt-friendly, so it may require using Lwt_preemptive).
Edit
Your:
Lwt_preemptive.detach (fun () -> Db.call) ()
This call creates a thread that, once executed, returns immediately the function Db.call. So, basically in that case Lwt_preemptive.detach does nothing :)
I don't know ocaml-mysql but if:
Db.call: connection_params -> connection_handle
you would have
let lwt_db_call connection_params =
Lwt_preemptive.detach Db.call connection_params

AllegroServe Exception Handling

How can I avoid getting an error when passing as argument to the function do-http-request an invalid host.
Is there any way that I can catch the error like the Java's exception-handling mechanism ?
Sure, CL has a very nice condition system. One easy option would be wrapping the call to do-http-request in ignore-errors, which returns nil (and the condition as a second value) if an error condition was signalled in the wrapped code. You could then check for nil afterwards.
If you want something more like exception handling in Java, just use handler-case and add an appropriate error clause (I don't have AllegroServe installed, but I suppose you get a socket-error for providing a wrong URL – just change that part if I misread):
(handler-case
(do-http-request …)
(socket-error ()
…))
If you need finally-like functionality, use unwind-protect:
(unwind-protect
(handler-case
(do-http-request …)
(socket-error (condition) ; bind the signalled condition
…) ; code to run when a socket-error was signalled
(:no-error (value) ; bind the returned value
…)) ; code to run when no condition was signalled
…) ; cleanup code (finally)
You can even get more fancy, and e.g. use handler-bind to handle the condition stack upwards by invoking a restart somewhere down the stack, without unwinding it. For example, if do-http-request provided a restart to try again with another URL, you could handle your error condition by invoking that restart with a new URL to retry. I just mention this for the sake of completeness – it would be overkill for your use case, but being able to resume (possibly expensive) computations easily can be a rather convenient feature.