Note, calling this from C is silly, but I want to test before I wrap a
whole state machine around it. Even so, eventually, even that has to be
called from C. So the need is general.
Yep. I have a ThreadX app thread in the Cypress FX3 USB3 device calling
ATS, which is then calling back into C to operate the I2C bus. Now I can
write a whole application in ATS. Given the level or reliability required
for a USB Device, this will be a big win.
I only used different names to make the example clear.
I’m having difficulty getting it to compile, so here is the exact code:
fun i2c_stop (arrayref(uint8, 256))
: uint8 = “mac#i2c_stop”
%{^
uint8_t i2c_data[256];
%}
macdef i2c_data =
$extval(arrayref(uint8, 256),“i2c_data”)
implement i2c_read_byte(address: uint8): (uint8, uint8) = let
var b: uint8 = u8(0)
var err: uint8 = err (0, u8)
val () = ifnerr(i2c_start(), err, 1, u8)
val () = ifnerr(i2c_write(wa address), err, 2, u8)
val () = ifnerr(i2c_read(), err, 3, u8)
val () = ifnerr(i2c_stop(i2c_data), err, 4, u8)
in (err, i2c_data[0]) end
I’m getting errors like:
/*
emit_instr: loc0 = /opt/ATS/ATS2-Postiats-0.2.4/prelude/DATS/array.dats:
1971(line=63, offs=45) – 1989(line=63, offs=63)
*/
ATSINSmove(tmpret33__1,
PMVtmpltcstmat[0](ptr0_get<S2Eapp(S2Ecst(g0uint_t0ype);
S2Eextkind(atstype_uint8))>)(tmp34__1)) ;
DATS/smbus_dats.c:1036:43: error: ‘ptr0_get’ undeclared (first use in this
function)
ATSINSmove(tmpret33__1,
PMVtmpltcstmat[0](ptr0_get<S2Eapp(S2Ecst(g0uint_t0ype);
S2Eextkind(atstype_uint8))>)(tmp34__1)) ;
DATS/smbus_dats.c:1036:66: error: ‘g0uint_t0ype’ undeclared (first use in
this function)
ATSINSmove(tmpret33__1,
PMVtmpltcstmat[0](ptr0_get<S2Eapp(S2Ecst(g0uint_t0ype);
S2Eextkind(atstype_uint8))>)(tmp34__1)) ;