How to implement interrupt handling for Nios 2?
I've succeeded writing polling for Nios 2 and the Altera DE2 and now I'm
instructed to do something similar but using interrupts instead for the
interaction:
Use interrupts from the keys instead of polling. This means that you must
write an interrupt service routine for the button interrupt (name the
function key InterruptHandler), and that you must initialize the system so
that interrupts from the button PIO will cause the key InterruptHandler
function to be executed. You must also enable interrupts from the button
PIO by writing appropriate value(s) to the appropriate register(s) in the
button PIO using the appropriate macro(s). The behavior caused by the
buttons shall be changed compared to the previous exercise: KEY0 The
button KEY0 shall toggle between start and stop counting the time. KEY1
Each time you push the button KEY1 the time value shall be incremented by
one. KEY2 Each time you push the button KEY2 the the time value shall be
set to 00:00. KEY3 Each time you push the button KEY3 the the time value
shall be set to 2.8 completed 59:57.
Now I don't really know which part to write in assembly and which part to
write in C, I have a few functions in assembly and C that I've written but
I'm not sure how to put the pieces together or if I'm missing something.
you must write an interrupt service routine for the button interrupt (name
the function key InterruptHandler), and that you must initialize the
system so that interrupts from the button PIO will cause the key
InterruptHandler function to be executed.
#include "alt_irq.h"
/* Define the null pointer */
#define NULL_POINTER ( (void *) 0)
void tick ( volatile int * ); /* in file tick.c */
/* Define addresses etc for de2_pio_keys4 */
volatile int * const de2_pio_keys4_base = (volatile int *) 0x840;
volatile int * const de2_pio_keys4_intmask = (volatile int *) 0x848;
volatile int * const de2_pio_keys4_edgecap = (volatile int *) 0x84c;
const int de2_pio_keys4_intindex = 2;
const int de2_pio_keys4_irqbit = 1 << 2;
/*
* Interrupt handler for de2_pio_keys4.
* The parameters are ignored here, but are
* required for correct compilation.
* The type alt_u32 is an Altera-defined
* unsigned integer type.
*
* To help debugging interruptible interrupt-handlers,
* this handler delays a long while when a key is pressed.
* However, there is no delay when the key is released.
*
* We keep a software copy of the LED value, since
* the parallel output ports are not program-readable.
*
* Example: we send out the value 1 on de2_pio_keys4,
* by executing *DE2_PIO_KEYS4_BASE = 1;
* Then we try to read the port by executing
* int test_val = *DE2_PIO_KEYS4_BASE; // WRONG
* The value of test_val is now undefined.
* The port returns some bits which are not related
* to the value we have written.
*
* The software copy of the LED value
* for this interrupt handler
* is the global variable myleds, defined above.
*/
void irq_handler_keys( void * context, alt_u32 irqnum )
{
alt_u32 save_value;
save_value = alt_irq_interruptible( de2_pio_keys4_intindex );
/* Read edge capture register of the de2_pio_keys4 device. */
int edges = *de2_pio_keys4_edgecap;
/* Clear edge capture register - writing
* any value clears all bits. */
*de2_pio_keys4_edgecap = 0;
/* If action on KEY0 */
if( edges & 1 )
{
/* If KEY0 is pressed now */
if( (*de2_pio_keys4_base & 1) == 0 )
{
/* Turn on green LED LEDG0
* in software copy of LED bits. */
myleds = myleds | 1;
/* Copy software LED bits to actual LEDs. */
*de2_pio_greenled9 = myleds;
/* Print an upper-case 'D' using out_char_uart_0. */
out_char_uart_0( 'D' );
/* Wait a long while */
bigdelay();
/* Print a lower-case 'd' using out_char_uart_0. */
out_char_uart_0( 'd' );
}
/* If KEY0 is released now */
else if( (*de2_pio_keys4_base & 1) != 0 )
{
/* Turn off green LED LEDG0
* in software copy of LED bits. */
myleds = myleds & 0xffffe;
/* Print an 'U' using out_char_uart_0. */
out_char_uart_0( 'U' );
/* Copy software LED bits to actual LEDs. */
*de2_pio_greenled9 = myleds;
}
alt_irq_non_interruptible( save_value );
}
}
int main()
{
/* Remove unwanted interrupts.
* initfix_int is supplied by KTH.
* A nonzero return value indicates failure. */
if( initfix_int() != 0 ) n2_fatal_error();
/* Initialize de2_pio_keys4 for
* interrupts. */
keysinit_int();
/* Initialize timer_1 for
* continuous timeout interrupts. */
timerinit_int();
/* Loop forever. */
while( 1 )
{
/* do some work */
/* Programmed delay between underscores.
* Defined earlier in this file. */
somedelay();
}
}
I didn't compile the above but it is my attempt at getting started to
solve the exercise.
The file tick.c is
/*
* tick.c - increment time in BCD format
*
* Copyright abandoned. This file is in the public domain.
*/
/*
* tick expects a pointer to a memory location containing
* BCD-coded time, and returns nothing.
*
* Time is stored as: days - hours - minutes - seconds,
* with two BCD digits for each number.
*/
void tick( unsigned int * timep )
{
/* Get current value, store locally */
register unsigned int t = * timep;
t += 1; /* Increment local copy */
/* If result was not a valid BCD-coded time, adjust now */
if( (t & 0x0000000f) == 0x0000000a ) t += 0x00000006;
if( (t & 0x000000f0) == 0x00000060 ) t += 0x000000a0;
/* Seconds are now OK */
if( (t & 0x00000f00) == 0x00000a00 ) t += 0x00000600;
if( (t & 0x0000f000) == 0x00006000 ) t += 0x0000a000;
/* Minutes are now OK */
if( (t & 0x000f0000) == 0x000a0000 ) t += 0x00060000;
if( (t & 0x00ff0000) == 0x00240000 ) t += 0x00dc0000;
/* Hours are now OK */
if( (t & 0x0f000000) == 0x0a000000 ) t += 0x06000000;
if( (t & 0xf0000000) == 0xa0000000 ) t = 0;
/* Days are now OK */
* timep = t; /* Store new value */
}
But do I not need any assembly to complete the task? Can I do it entirely
with C? I thought that when writing an ISR it must be done in assembly?
What more can you tell me to help me complete the task? I build it using
Quartus II and the Nios 2 SBT.
Tuesday, 10 September 2013
Monday, 9 September 2013
How can I convert a List to an xml document?
How can I convert a List to an xml document?
I have this current code:
List<string> BugWSResponseList1 = new List<string>();
Logger.Write("\n\n" + DateTime.Now + " : " +
" : START : Creation of a set of Bugs via bug.Add API");
BugWSResponseList1 =
CreateBugs(FilePath_EXPRESS_API_BugAdd_CreateBugs_DataFile);
I would like to convert the List<string> BugWSResponseList1 to an xml
document.
Can you please suggest a way to do it?
I have this current code:
List<string> BugWSResponseList1 = new List<string>();
Logger.Write("\n\n" + DateTime.Now + " : " +
" : START : Creation of a set of Bugs via bug.Add API");
BugWSResponseList1 =
CreateBugs(FilePath_EXPRESS_API_BugAdd_CreateBugs_DataFile);
I would like to convert the List<string> BugWSResponseList1 to an xml
document.
Can you please suggest a way to do it?
Select with oledb
Select with oledb
I Can't do select... I can not do a select inside a go with dates recebe
uma variavel que determina quantidade de meses a ser calculada
MesesDemanda Calculated a date before and one after
for (int i = 1; i <= MesesDemanda; i++)
{
int cont = 0;
DateTime dataposterior = DateTime.Now, dataanterior =
DateTime.Now;
dataanterior = dataanterior.AddMonths(i);
dataposterior = dataposterior.AddMonths(-(i - 1));
con.Open();
cmd = new OleDbCommand("SELECT HistSaida.dataHistSaida,
HistSaida.idProdutoHistSaida, HistSaida.qtdHistSaida FROM
HistSaida WHERE (((HistSaida.dataHistSaida) BETWEEN #" +
dataanterior + "# AND #" + dataposterior + "#) AND
idProdutoHistSaida = " + idProduto + ")", con);
dr = cmd.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
Demanda = Demanda +
Convert.ToInt32(dr["qtdHistSaida"]);
cont = 1;
}
}
dr.Close();
con.Close();
Valordivisao = Valordivisao + cont;
}
I Can't do select... I can not do a select inside a go with dates recebe
uma variavel que determina quantidade de meses a ser calculada
MesesDemanda Calculated a date before and one after
for (int i = 1; i <= MesesDemanda; i++)
{
int cont = 0;
DateTime dataposterior = DateTime.Now, dataanterior =
DateTime.Now;
dataanterior = dataanterior.AddMonths(i);
dataposterior = dataposterior.AddMonths(-(i - 1));
con.Open();
cmd = new OleDbCommand("SELECT HistSaida.dataHistSaida,
HistSaida.idProdutoHistSaida, HistSaida.qtdHistSaida FROM
HistSaida WHERE (((HistSaida.dataHistSaida) BETWEEN #" +
dataanterior + "# AND #" + dataposterior + "#) AND
idProdutoHistSaida = " + idProduto + ")", con);
dr = cmd.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
Demanda = Demanda +
Convert.ToInt32(dr["qtdHistSaida"]);
cont = 1;
}
}
dr.Close();
con.Close();
Valordivisao = Valordivisao + cont;
}
simple pythagorean theorem calculator in ruby
simple pythagorean theorem calculator in ruby
I made a pythagorean theorem calculator in ruby and it has a bug/does not
run. The error is: undefined local variable or method `a2'. I Was
wandering if anyone could help. Thanks.
puts "Welcome to my pythagorean theorem calculator. This calculator can
find the hypotenuse of any right triangle. Please enter side A of your
triangle."
a = gets.to_f
puts "please enter side B of your triangle."
b = gets.to_f
a**2 == a2
b**2 == b2
a2 + b2 = a2_b2
puts "The hypotenuse of your triangle is: #{ Math.sqrt(a2_b2)}"
I made a pythagorean theorem calculator in ruby and it has a bug/does not
run. The error is: undefined local variable or method `a2'. I Was
wandering if anyone could help. Thanks.
puts "Welcome to my pythagorean theorem calculator. This calculator can
find the hypotenuse of any right triangle. Please enter side A of your
triangle."
a = gets.to_f
puts "please enter side B of your triangle."
b = gets.to_f
a**2 == a2
b**2 == b2
a2 + b2 = a2_b2
puts "The hypotenuse of your triangle is: #{ Math.sqrt(a2_b2)}"
problems making async calls in streams using node.js
problems making async calls in streams using node.js
I am having a problem with making async calls in my streams. It looks like
for some reason if I have three streams and the middle stream makes an
async call, the final stream never receives the 'end' event. I can
simulate the behavior with some simple through streams and a timeout.
var options = {}
var streamOne = function(){
return through(function write(row){
this.emit('data', row)
})
}
var streamTwo = function(){
return through(function write(row){
this.pause()
var that = this;
setTimeout(function(){
that.emit('data', row)
that.resume()
}, 1000)
})
}
options.streams = [new streamOne(), new streamTwo()]
I then pass this through to event-stream.
var streams = []
//Pass stream one and stream two to es.pipe
streams.push(es.pipe.apply(this, options.streams))
//Then add the final stream
var endStream = es.pipe(
new streamThree()
)
streams.push(endStream)
//And send it through the pipeline
es.pipeline.apply(this, streams)
So, this does not work in the current case.
A couple of confusing points: if I remove streamOne, it works! If
streamTwo does not make an async call, it works. This makes me think the
problem lies in the way the two streams interact. However, if I
console.log throughout, it looks like everything works fine, streamThree
will write the data but never registers the 'end' event. *Note:
streamThree is not using through, and is instead using the native Streams
module.
Thoughts on why this is happening?
I am having a problem with making async calls in my streams. It looks like
for some reason if I have three streams and the middle stream makes an
async call, the final stream never receives the 'end' event. I can
simulate the behavior with some simple through streams and a timeout.
var options = {}
var streamOne = function(){
return through(function write(row){
this.emit('data', row)
})
}
var streamTwo = function(){
return through(function write(row){
this.pause()
var that = this;
setTimeout(function(){
that.emit('data', row)
that.resume()
}, 1000)
})
}
options.streams = [new streamOne(), new streamTwo()]
I then pass this through to event-stream.
var streams = []
//Pass stream one and stream two to es.pipe
streams.push(es.pipe.apply(this, options.streams))
//Then add the final stream
var endStream = es.pipe(
new streamThree()
)
streams.push(endStream)
//And send it through the pipeline
es.pipeline.apply(this, streams)
So, this does not work in the current case.
A couple of confusing points: if I remove streamOne, it works! If
streamTwo does not make an async call, it works. This makes me think the
problem lies in the way the two streams interact. However, if I
console.log throughout, it looks like everything works fine, streamThree
will write the data but never registers the 'end' event. *Note:
streamThree is not using through, and is instead using the native Streams
module.
Thoughts on why this is happening?
Drupal Help... How to Edit Specific Page?
Drupal Help... How to Edit Specific Page?
Going crazy trying to find where in the drupal system I can edit this page:
http://www.luxewinecellars.com/products/wine-cooling-units-0
I've have full admin access to drupal but can't edit this page form the
web interface and can't find anywhere in the backend/drop down admin
system to be able to access to edit this page.
Adding to the confusion is when I use the admin top bar I get to a
completely different version of this page I want to edit, I get to it
from:
Store Administration --> Products --> Product Categories (then I click the
"Wine Cooling Units" link and I get the following page)
http://www.luxewinecellars.com/products/wine-cooling-units
Can someone help me find/understand how to edit this page:
http://www.luxewinecellars.com/products/wine-cooling-units-0
Thanks!!!
Going crazy trying to find where in the drupal system I can edit this page:
http://www.luxewinecellars.com/products/wine-cooling-units-0
I've have full admin access to drupal but can't edit this page form the
web interface and can't find anywhere in the backend/drop down admin
system to be able to access to edit this page.
Adding to the confusion is when I use the admin top bar I get to a
completely different version of this page I want to edit, I get to it
from:
Store Administration --> Products --> Product Categories (then I click the
"Wine Cooling Units" link and I get the following page)
http://www.luxewinecellars.com/products/wine-cooling-units
Can someone help me find/understand how to edit this page:
http://www.luxewinecellars.com/products/wine-cooling-units-0
Thanks!!!
WPF ComboBox: Bind ItemsSource to List and Two-way Bind selected value to ViewModel Property?
WPF ComboBox: Bind ItemsSource to List and Two-way Bind selected value to
ViewModel Property?
This is my first go 'round with WPF bindings of this nature so I'm sure
I'm doing something silly.
Background / Setup
I have the following:
A ViewModel (MainWindowViewModel)
A bound Datacontext
in the Window definition, DataContext="{StaticResource MainWindowViewModel}"
In the viewmodel, a list:
readonly List<string> _sqlServerChoices = new List<string>{"DEV", "SPDEV",
"SPSQL", "SQL2008"};
A viewmodel property exposing the list:
public List<string> SqlServerChoices{get { return _sqlServerChoices; }}
A ComboBox for selecting the SQL Server
A property called "Settings" which is a custom type, UploaderSettings,
which has collections of database settings, sharepoint settings, etc.
A property called SqlServerHasBeenEntered, which is a boolean that returns
whether the
A text box that should be enabled or disabled based on whether a SQL
The Goal
I would like to have the choices for the items in the combobox (the
ItemsSource) to be set to the list of SQL Servers. This appears to work
fine.
I would like the selected element of the list to be a two-way binding to
the Settings.DatabaseSettings.SqlServer property on the ViewModel.
When this property is updated, I would like to fire OnPropertyChanged for
the SqlServerHasBeenEntered property.
I would like to have the text box enabled or disabled based on whether the
SqlServerHasBeenEntered property is true or false.
The Problem
The binding appears to be failing silently. I see the combo box items, but
when I select them, nothing is changing and it appears the
onpropertychanged event handler isn't being called.
The Code So Far
The ComboBox XAML definition:
<ComboBox Grid.Row="0" Grid.Column="1" VerticalAlignment="Center"
ItemsSource="{Binding SqlServerChoices}"
SelectedValue="{Binding
Settings.DatabaseSettings.SqlServer,
Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged }">
The Boolean value for whether or not the SQL Server field has text:
public bool SqlServerHasBeenEntered
{
get
{
return !String.IsNullOrEmpty(Settings.DatabaseSettings.SqlServer);
}
}
The Property changing handler:
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged([CallerMemberName] string
propertyName = null)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
ViewModel Property?
This is my first go 'round with WPF bindings of this nature so I'm sure
I'm doing something silly.
Background / Setup
I have the following:
A ViewModel (MainWindowViewModel)
A bound Datacontext
in the Window definition, DataContext="{StaticResource MainWindowViewModel}"
In the viewmodel, a list:
readonly List<string> _sqlServerChoices = new List<string>{"DEV", "SPDEV",
"SPSQL", "SQL2008"};
A viewmodel property exposing the list:
public List<string> SqlServerChoices{get { return _sqlServerChoices; }}
A ComboBox for selecting the SQL Server
A property called "Settings" which is a custom type, UploaderSettings,
which has collections of database settings, sharepoint settings, etc.
A property called SqlServerHasBeenEntered, which is a boolean that returns
whether the
A text box that should be enabled or disabled based on whether a SQL
The Goal
I would like to have the choices for the items in the combobox (the
ItemsSource) to be set to the list of SQL Servers. This appears to work
fine.
I would like the selected element of the list to be a two-way binding to
the Settings.DatabaseSettings.SqlServer property on the ViewModel.
When this property is updated, I would like to fire OnPropertyChanged for
the SqlServerHasBeenEntered property.
I would like to have the text box enabled or disabled based on whether the
SqlServerHasBeenEntered property is true or false.
The Problem
The binding appears to be failing silently. I see the combo box items, but
when I select them, nothing is changing and it appears the
onpropertychanged event handler isn't being called.
The Code So Far
The ComboBox XAML definition:
<ComboBox Grid.Row="0" Grid.Column="1" VerticalAlignment="Center"
ItemsSource="{Binding SqlServerChoices}"
SelectedValue="{Binding
Settings.DatabaseSettings.SqlServer,
Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged }">
The Boolean value for whether or not the SQL Server field has text:
public bool SqlServerHasBeenEntered
{
get
{
return !String.IsNullOrEmpty(Settings.DatabaseSettings.SqlServer);
}
}
The Property changing handler:
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged([CallerMemberName] string
propertyName = null)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
Subscribe to:
Posts (Atom)