Reply by "mir...@neacsu.net [rabbit-semi]" October 3, 20172017-10-03
In C: unsigned char saved_bits; //this is where I saved the bits
unsigned char new_val; //this is whre thesy should end up;

new_val = (new_val &0x0f) | (saved_bits & 0xf0);

In assembler:
ld a, (saved_bits)
and 0xf0
ld b,a
ld a, (new_val)
and 0x0f
or b
ld (new_val), a

Cheers,
Mircea

---In r..., wrote :

Hello,

I am using the bits of integer value to represent digital input status. I know I can use set or res to update one by one bit, is it possible to update multi bits at one time? For example, I save bit 4-7 in one integer value, then I would like to copy this to the same bits in another integer.

Regards,

Yang

From: r... [mailto:r...]
Sent: September 11, 2017 2:10 PM
To: r...
Subject: Re: [rabbit-semi] Question for xalloc
When you call xalloc(), it reserves a portion of xmem for your use. If you go beyond the length of your allocation, you’ll overwrite something else in memory which will likely result in a crash at some point. Maybe you’re OK right now because nothing else is making use of that space, but you should fix your code to request the correct amount of space to save yourself headaches with future debugging!

The Rabbit doesn’t have a memory manager in place to throw a segmentation fault when you go outside of the requested memory range.

The “sz” parameter to xalloc() is the amount of space to reserve. In the _xalloc() call, you pass a pointer to a long with your desired allocation, and it will update that value with the actual amount of space reserved (which may be slightly larger than what you asked for).

Bottom line: If you ask for 512 bytes, don’t try to write past that 512-byte boundary.

-Tom

On Sep 8, 2017, at 1:59 PM, 'Yang Hong' yang@... mailto:yang@... [rabbit-semi] wrote:

Hello,

I am using xalloc to get a block of memory for my data, my data is structure with many variables, roughly about 512 word, so after I read manual of xalloc, I should set 512x2 bytes memory for those data, but when I try to set 512 as memory size, I still can save those data without any problem, I would like to know why? And also I don’t understand sz explanation in the help below.

SYNTAX: long xalloc(long sz);

DESCRIPTION: Allocates memory in extended memory. If xalloc() fails,
a run-time error will occur. This is a wrapper function for _xalloc(),
for backwards compatibility. It is the same as
_xalloc(&sz, 1, XALLOC_MAYBBB)
except that the actual allocated amount is not returned since the parameter
is not a pointer. The returned address is always even (word) aligned.

NOTE: xalloc is not thread safe, since it accesses a global static structure
with no locking.

PARAMETER1: sz: The number of bytes to allocate. This is rounded up
to the next higher even number. ( what does it mean?)

RETURN VALUE: The 20-bit physical address of the allocated data.

KEYWORDS: xalloc, premain

YANG HONG
Application Engineer/Technical Support
Omniverter Inc.
3075 14th Avenue
Unit #13
Markham, Ontario
L3R 0G9 Canada
Tel: 416 849 2299
Direct: 647 874 1505
USA: 440 290 4499
Fax: 416 849 2298
Web: www.omniverter.com http://www.omniverter.com/
Reply by "'Ya...@omniverter.com [rabbit-semi]" October 3, 20172017-10-03
Hello,

I am using the bits of integer value to represent digital input status. I know I can use set or res to update one by one bit, is it possible to update multi bits at one time? For example, I save bit 4-7 in one integer value, then I would like to copy this to the same bits in another integer.

Regards,

Yang

From: r... [mailto:r...]
Sent: September 11, 2017 2:10 PM
To: r...
Subject: Re: [rabbit-semi] Question for xalloc

When you call xalloc(), it reserves a portion of xmem for your use. If you go beyond the length of your allocation, you’ll overwrite something else in memory which will likely result in a crash at some point. Maybe you’re OK right now because nothing else is making use of that space, but you should fix your code to request the correct amount of space to save yourself headaches with future debugging!

The Rabbit doesn’t have a memory manager in place to throw a segmentation fault when you go outside of the requested memory range.

The “sz” parameter to xalloc() is the amount of space to reserve. In the _xalloc() call, you pass a pointer to a long with your desired allocation, and it will update that value with the actual amount of space reserved (which may be slightly larger than what you asked for).

Bottom line: If you ask for 512 bytes, don’t try to write past that 512-byte boundary.

-Tom
On Sep 8, 2017, at 1:59 PM, 'Yang Hong' y...@omniverter.com [rabbit-semi] > wrote:

Hello,

I am using xalloc to get a block of memory for my data, my data is structure with many variables, roughly about 512 word, so after I read manual of xalloc, I should set 512x2 bytes memory for those data, but when I try to set 512 as memory size, I still can save those data without any problem, I would like to know why? And also I don’t understand sz explanation in the help below.

SYNTAX: long xalloc(long sz);

DESCRIPTION: Allocates memory in extended memory. If xalloc() fails,

a run-time error will occur. This is a wrapper function for _xalloc(),

for backwards compatibility. It is the same as

_xalloc(&sz, 1, XALLOC_MAYBBB)

except that the actual allocated amount is not returned since the parameter

is not a pointer. The returned address is always even (word) aligned.

NOTE: xalloc is not thread safe, since it accesses a global static structure

with no locking.

PARAMETER1: sz: The number of bytes to allocate. This is rounded up

to the next higher even number. ( what does it mean?)

RETURN VALUE: The 20-bit physical address of the allocated data.

KEYWORDS: xalloc, premain

YANG HONG

Application Engineer/Technical Support

Omniverter Inc.

3075 14th Avenue

Unit #13
Markham, Ontario
L3R 0G9 Canada

Tel: 416 849 2299

Direct: 647 874 1505
USA: 440 290 4499
Fax: 416 849 2298

Web: www.omniverter.com