Passing an array into C

If I have:

// Writes array of data to hardware using length
fun spi_send_c (cPtr0(uint8), uint8): uint32 = “mac#spi_send_c”

// Preallocated array for processing
uint8_t packetIn[258];
const uint8_t *packetInCount = packetIn;
const uint8_t *packetInHeader = packetIn + 1;
const uint8_t *packetInContents = packetIn + 2;

// A way to access the data as packetInContents[n] from ATS code
macdef packetInContents =
$extval(arrayref(uint8, 256),“packetInContents”)

How do I get a pointer of packetInContents to pass to spi_send_c?

Note, I’d be ok making a different kind of variable for packetInContents (C
version) just for passing it, rather than somehow converting
packetInContents (ATS version).

For example, I tried this:

macdef packetInContentsP =
$extval(cPtr0(uint8)), “packetInContents”)

But it does not compile.

Results in:

error(3): the tuple/record pattern is ill-typed.
patsopt(TRANS3): there are [1] errors in total.
exit(ATS): uncaught exception:
_2home_2hwxi_2Research_2ATS_2dPostiats_2src_2pats_error_2esats__FatalErrorExn(1025)On Tuesday, December 15, 2015 at 9:31:55 PM UTC-7, gmhwxi wrote:

Try cast:

val _ = spi_send_c($UN.cast(packetInContents), $UN.cast{uint8}(0))

On Tue, Dec 15, 2015 at 11:07 PM, Mike Jones <pro...@gmail.com <javascript:>> wrote:

If I have:

// Writes array of data to hardware using length
fun spi_send_c (cPtr0(uint8), uint8): uint32 = “mac#spi_send_c”

// Preallocated array for processing
uint8_t packetIn[258];
const uint8_t *packetInCount = packetIn;
const uint8_t *packetInHeader = packetIn + 1;
const uint8_t *packetInContents = packetIn + 2;

// A way to access the data as packetInContents[n] from ATS code
macdef packetInContents =
$extval(arrayref(uint8, 256),“packetInContents”)

How do I get a pointer of packetInContents to pass to spi_send_c?

Note, I’d be ok making a different kind of variable for packetInContents
(C version) just for passing it, rather than somehow converting
packetInContents (ATS version).

For example, I tried this:

macdef packetInContentsP =
$extval(cPtr0(uint8)), “packetInContents”)

But it does not compile.


You received this message because you are subscribed to the Google Groups
“ats-lang-users” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to ats-lang...@googlegroups.com <javascript:>.
To post to this group, send email to ats-l...@googlegroups.com
<javascript:>.
Visit this group at https://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/ab2084bd-198b-4653-8255-b2d701bfcd0c%40googlegroups.com
https://groups.google.com/d/msgid/ats-lang-users/ab2084bd-198b-4653-8255-b2d701bfcd0c%40googlegroups.com?utm_medium=email&utm_source=footer
.

In this case, it is void* to void* in C. The cast is just
for circumventing typechecking in ATS.On Tuesday, December 15, 2015 at 11:41:36 PM UTC-5, Mike Jones wrote:

Never mind. It was due to a mismatch in the return value. It compiled.

wrt cast(), does it cast anything to anything, or is it a pointer caster?

On Tuesday, December 15, 2015 at 9:39:53 PM UTC-7, Mike Jones wrote:

Results in:

error(3): the tuple/record pattern is ill-typed.
patsopt(TRANS3): there are [1] errors in total.
exit(ATS): uncaught exception:
_2home_2hwxi_2Research_2ATS_2dPostiats_2src_2pats_error_2esats__FatalErrorExn(1025)

On Tuesday, December 15, 2015 at 9:31:55 PM UTC-7, gmhwxi wrote:

Try cast:

val _ = spi_send_c($UN.cast(packetInContents), $UN.cast{uint8}(0))

On Tue, Dec 15, 2015 at 11:07 PM, Mike Jones pro...@gmail.com wrote:

If I have:

// Writes array of data to hardware using length
fun spi_send_c (cPtr0(uint8), uint8): uint32 = “mac#spi_send_c”

// Preallocated array for processing
uint8_t packetIn[258];
const uint8_t *packetInCount = packetIn;
const uint8_t *packetInHeader = packetIn + 1;
const uint8_t *packetInContents = packetIn + 2;

// A way to access the data as packetInContents[n] from ATS code
macdef packetInContents =
$extval(arrayref(uint8, 256),“packetInContents”)

How do I get a pointer of packetInContents to pass to spi_send_c?

Note, I’d be ok making a different kind of variable for
packetInContents (C version) just for passing it, rather than somehow
converting packetInContents (ATS version).

For example, I tried this:

macdef packetInContentsP =
$extval(cPtr0(uint8)), “packetInContents”)

But it does not compile.


You received this message because you are subscribed to the Google
Groups “ats-lang-users” group.
To unsubscribe from this group and stop receiving emails from it, send
an email to ats-lang...@googlegroups.com.
To post to this group, send email to ats-l...@googlegroups.com.
Visit this group at https://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/ab2084bd-198b-4653-8255-b2d701bfcd0c%40googlegroups.com
https://groups.google.com/d/msgid/ats-lang-users/ab2084bd-198b-4653-8255-b2d701bfcd0c%40googlegroups.com?utm_medium=email&utm_source=footer
.

Try cast:

val _ = spi_send_c($UN.cast(packetInContents), $UN.cast{uint8}(0))On Tue, Dec 15, 2015 at 11:07 PM, Mike Jones proc...@gmail.com wrote:

If I have:

// Writes array of data to hardware using length
fun spi_send_c (cPtr0(uint8), uint8): uint32 = “mac#spi_send_c”

// Preallocated array for processing
uint8_t packetIn[258];
const uint8_t *packetInCount = packetIn;
const uint8_t *packetInHeader = packetIn + 1;
const uint8_t *packetInContents = packetIn + 2;

// A way to access the data as packetInContents[n] from ATS code
macdef packetInContents =
$extval(arrayref(uint8, 256),“packetInContents”)

How do I get a pointer of packetInContents to pass to spi_send_c?

Note, I’d be ok making a different kind of variable for packetInContents
(C version) just for passing it, rather than somehow converting
packetInContents (ATS version).

For example, I tried this:

macdef packetInContentsP =
$extval(cPtr0(uint8)), “packetInContents”)

But it does not compile.


You received this message because you are subscribed to the Google Groups
“ats-lang-users” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to ats-lang-user...@googlegroups.com.
To post to this group, send email to ats-lan...@googlegroups.com.
Visit this group at https://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/ab2084bd-198b-4653-8255-b2d701bfcd0c%40googlegroups.com
https://groups.google.com/d/msgid/ats-lang-users/ab2084bd-198b-4653-8255-b2d701bfcd0c%40googlegroups.com?utm_medium=email&utm_source=footer
.

Never mind. It was due to a mismatch in the return value. It compiled.

wrt cast(), does it cast anything to anything, or is it a pointer caster?On Tuesday, December 15, 2015 at 9:39:53 PM UTC-7, Mike Jones wrote:

Results in:

error(3): the tuple/record pattern is ill-typed.
patsopt(TRANS3): there are [1] errors in total.
exit(ATS): uncaught exception:
_2home_2hwxi_2Research_2ATS_2dPostiats_2src_2pats_error_2esats__FatalErrorExn(1025)

On Tuesday, December 15, 2015 at 9:31:55 PM UTC-7, gmhwxi wrote:

Try cast:

val _ = spi_send_c($UN.cast(packetInContents), $UN.cast{uint8}(0))

On Tue, Dec 15, 2015 at 11:07 PM, Mike Jones pro...@gmail.com wrote:

If I have:

// Writes array of data to hardware using length
fun spi_send_c (cPtr0(uint8), uint8): uint32 = “mac#spi_send_c”

// Preallocated array for processing
uint8_t packetIn[258];
const uint8_t *packetInCount = packetIn;
const uint8_t *packetInHeader = packetIn + 1;
const uint8_t *packetInContents = packetIn + 2;

// A way to access the data as packetInContents[n] from ATS code
macdef packetInContents =
$extval(arrayref(uint8, 256),“packetInContents”)

How do I get a pointer of packetInContents to pass to spi_send_c?

Note, I’d be ok making a different kind of variable for packetInContents
(C version) just for passing it, rather than somehow converting
packetInContents (ATS version).

For example, I tried this:

macdef packetInContentsP =
$extval(cPtr0(uint8)), “packetInContents”)

But it does not compile.


You received this message because you are subscribed to the Google
Groups “ats-lang-users” group.
To unsubscribe from this group and stop receiving emails from it, send
an email to ats-lang...@googlegroups.com.
To post to this group, send email to ats-l...@googlegroups.com.
Visit this group at https://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/ab2084bd-198b-4653-8255-b2d701bfcd0c%40googlegroups.com
https://groups.google.com/d/msgid/ats-lang-users/ab2084bd-198b-4653-8255-b2d701bfcd0c%40googlegroups.com?utm_medium=email&utm_source=footer
.

Ah, the ultimate removal of seat belts!

I’ll make some safe ATS function call and put this dangerous cast inside so
the maintainer does not accidentally pass something too small, etc.On Tuesday, December 15, 2015 at 9:44:19 PM UTC-7, gmhwxi wrote:

In this case, it is void* to void* in C. The cast is just
for circumventing typechecking in ATS.

On Tuesday, December 15, 2015 at 11:41:36 PM UTC-5, Mike Jones wrote:

Never mind. It was due to a mismatch in the return value. It compiled.

wrt cast(), does it cast anything to anything, or is it a pointer caster?

On Tuesday, December 15, 2015 at 9:39:53 PM UTC-7, Mike Jones wrote:

Results in:

error(3): the tuple/record pattern is ill-typed.
patsopt(TRANS3): there are [1] errors in total.
exit(ATS): uncaught exception:
_2home_2hwxi_2Research_2ATS_2dPostiats_2src_2pats_error_2esats__FatalErrorExn(1025)

On Tuesday, December 15, 2015 at 9:31:55 PM UTC-7, gmhwxi wrote:

Try cast:

val _ = spi_send_c($UN.cast(packetInContents), $UN.cast{uint8}(0))

On Tue, Dec 15, 2015 at 11:07 PM, Mike Jones pro...@gmail.com wrote:

If I have:

// Writes array of data to hardware using length
fun spi_send_c (cPtr0(uint8), uint8): uint32 = “mac#spi_send_c”

// Preallocated array for processing
uint8_t packetIn[258];
const uint8_t *packetInCount = packetIn;
const uint8_t *packetInHeader = packetIn + 1;
const uint8_t *packetInContents = packetIn + 2;

// A way to access the data as packetInContents[n] from ATS code
macdef packetInContents =
$extval(arrayref(uint8, 256),“packetInContents”)

How do I get a pointer of packetInContents to pass to spi_send_c?

Note, I’d be ok making a different kind of variable for
packetInContents (C version) just for passing it, rather than somehow
converting packetInContents (ATS version).

For example, I tried this:

macdef packetInContentsP =
$extval(cPtr0(uint8)), “packetInContents”)

But it does not compile.


You received this message because you are subscribed to the Google
Groups “ats-lang-users” group.
To unsubscribe from this group and stop receiving emails from it, send
an email to ats-lang...@googlegroups.com.
To post to this group, send email to ats-l...@googlegroups.com.
Visit this group at https://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/ab2084bd-198b-4653-8255-b2d701bfcd0c%40googlegroups.com
https://groups.google.com/d/msgid/ats-lang-users/ab2084bd-198b-4653-8255-b2d701bfcd0c%40googlegroups.com?utm_medium=email&utm_source=footer
.