Shop OBEX P1 Docs P2 Docs Learn Events
C4SX: C environment for running C programs on the SX 18/28/48! — Parallax Forums

C4SX: C environment for running C programs on the SX 18/28/48!

RW SenserRW Senser Posts: 61
edited 2007-07-26 02:57 in General Discussion
Hello all-

This posting announces C4SX.· This is an environment (editor, compiler, and loader
for the SK-KEY) that makes it possible to compile C programs under Windows and then
run these C programs on the SX.· This NO-COST environment has been used to produce
several large, production-quality C programs and includes SXIO.H.·

The SXIO.H C header file ("library") makes it possible to use C getchar(), putchar()
and puts() functions with the SX (assuming you have a USB2SER or other serial
capability connected to you SX).·

You can view documentation, including a "Quick Start", at:
http://www.rwsenser.com/c4sx/C4SX_Environment.htm
You can download the full C4SX Zip file from http://www.rwsenser.com by following
the "Click here to download the C4SX Zip File".· Note that you will also need to
download some other components from the web (Parallax SK-KEY, CC1B compiler and
possibly an editor).· Clear instructions for what to download are given in the
C4SX documentation.

If you are interested in C for the SX, please give C4SX a try.

Feedback, comments and/or questions about C4SX are welcome, please post them to
this forum.· Or, you can also email them to c4sx@rwsenser.com

If there is enough interest from the SX Community, C4SX with be expanded and
further refined.

printf("Thanks,\nrwsenser\n");

Comments

  • Brian CarpenterBrian Carpenter Posts: 728
    edited 2007-07-23 03:15
    RW Senser,
    is this in lue of the SXC?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    It's Only A Stupid Question If You Have Not Googled It First!!
  • RW SenserRW Senser Posts: 61
    edited 2007-07-23 03:23
    Hi Brian,

    Greets. No, this is in addition to SXC.

    I've heard that a next version of SXC (the "CSC" product) will be out soon.

    C4SX is different, we pulled together existing components and at no cost, have a C programming solution for the SX.

    Hope this answers your question.

    Thanks,
    RW Senser
  • Jared WoolstonJared Woolston Posts: 36
    edited 2007-07-23 04:04
    If its a C programming solution for the SX, i fail to see how it is not in liu of SXC. And Im not trying to be argumentative, im just trying to figure it out.

    -Jared

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    A wise man who is not known for sure to have existed once said, "Never test a river with both feet." I feel this is especially true in engineering...throughout history everytime something new was tried with little research or planning, the odds were stacked in favor of failure, and everyone knows the house always wins in the long run....
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2007-07-23 05:39
    RW Senser,
    I welcome this!
    As a SXC betatester, I looked at the CC1B compiler a long time ago (rev.G) and even
    proposed in the sxc beta forum to switch from CCS to CC1B for one major reason:
    the CC1B generated an almost sasm compatible assembly file. It looks you now
    finally resolved that by using an external conversion program. This means we can load
    the assembly file into the sxkey IDE to assemble and, more importantly, we can use SxSim to
    test generated code. The CCS generated assembly cannot be loaded into the sxkey
    and therefore SxSim cannot be used. As CC1B is purely a commandline compiler,
    I think it could even be integrated into the sxkey editor, just like SX/B.
    Complete the documentation, and have some more libraries and examples,·and it will be a winner, I am sure.

    regards peter

    Post Edited (Peter Verkaik) : 7/23/2007 5:49:13 AM GMT
  • RW SenserRW Senser Posts: 61
    edited 2007-07-23 12:53
    Hi Jarid,

    In further reply to your question about what C4SX is: Yes, you are correct: Both SXC and this C4SX can do roughly the same thing. They both provide a C solution for the SX. My point was that neither product/approach is in liu of the other.

    Hi peter,

    Thanks for the positive feedback. I too think this C4SX approach is a winner. The plan is to have more C4SX documentation and code examples out soon.

    Thanks to both of you guys for the feedback/interest,
    RW Senser
  • BeanBean Posts: 8,129
    edited 2007-07-23 14:25
    I·didn't have too much problem compiling the led flasher program. (After I read the directions blush.gif )
    I'm pretty impressed with the output too. I was able to program a chip with no errors or problems.
    I have the files attached for those who are interested.
    Nice job...

    Bean.




    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Teacher: What is the difference between ignorance and apathy ?
    Student: I don't know and I don't care
    Teacher: Correct !
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.hittconsulting.com


    Post Edited (Bean (Hitt Consulting)) : 7/23/2007 2:35:20 PM GMT
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2007-07-23 16:48
    RW Senser,

    I have been playing around with your suggested setup. Seems to work well.
    Some remarks:
    CC1B appears only to support #pragma chip CHIPTYPE
    that translates into device CHIPTYPE
    The other device directives are set by an (automatically) included header file.
    Is it possible to use #pragma to set other directives, for example
    #pragma sx_device·OSCHS2, TURBO, STACKX, OPTIONX, BOR42
    #pragma sx_freq 20_000_000
    #pragma sx_id 'sampleid'
    #pragma sx_irc_cal irc_fast
    #pragma sx_reset sxinit
    The idea is to let CC1B output the entire line with the leading sx_ omitted
    So the above 5 lines would translate into
    device·OSCHS2, TURBO, STACKX, OPTIONX, BOR42
    freq 20_000_000
    id 'sampleid'
    irc_cal irc_fast
    reset sxinit
    The 2nd request is for the use of #asm and #endasm
    #asm
    · mov w,#10
    #endasm
    gives a compiler error on mov w,#10
    Why not just let CC1B output anything between #asm and #endasm to the output file?
    If there are errors, these will be detected by sasm.

    I realize these requests concern CC1B and not your utilities.
    Do you have contact with B. Knudsen (author of the compiler)?
    These features would make it possible for a C file to have all necessary info in it,
    without the need for some template header file, and to include inline assembly using sasm
    assembly statements.

    regards peter
  • Kevin WoodKevin Wood Posts: 1,266
    edited 2007-07-24 00:28
    >>> Do you have contact with B. Knudsen (author of the compiler)?

    I know that this question wasn't directed to me, but just to let you know, they do answer email sent to the address on their site.
  • RW SenserRW Senser Posts: 61
    edited 2007-07-24 02:38
    Hi Kevin and Peter,

    As Kevin points out, B. Knudsen does respond to emails. I asked him about the future of CC1B (since I wanted to release C4SX). The impression I got is that he expects to keep CC1B around for the long-term but does not want to put any (more) extensions into it. I assume if there is a big demand for something (with $$$s behind it), anything is possible.

    On to Peter's points and questions:
    1) "The other device directives are set by an (automatically) included header file.
    Is it possible to use #pragma to set other directives, for example..."
    One of the upgrades, I have in mind, for C4SX is to make the included header files easily changeable. This means being able to supply the name on the c4sx invocation. This would allow all the SX-KEY Device settings to be easily set. However, it is not as clean as the #pragma approach that you suggest. Right now you can adjust the header file contents (CC1B2SX.HDR) and keep the adjusted header in a different directory, and compile there (if you put the C4SX directory in your Windows PATH -- I use this technique currently...).
    2) "The 2nd request is for the use of #asm and #endasm
    #asm
    mov w,#10
    #endasm
    "
    As you might have noticed, CC1B assembler support is very "PIC-ish". I'm sure CC1B is built from PIC-based technology. However, I have a existing thought on doing something like this: If you have ever used PHP or Microsoft's ASP, you have seen the interweaving of HTML and PHP/ASP code. I'm thinking of doing something similar for C4SX. The syntax would be a bit obtuse, something like:
    /* <?asm
    mov 2,#10
    ?> */

    You can probably see the 'trick' here, these look like comments to the CC1B C compiler but the C4SX reformatter can parse these out and insert the assembler code into the ouput .src file. As I said, this is not elegant but perhaps workable. <<Laughing permitted..... >>

    A question to people in general: Has anyone tried using the C4SX SXIO.H include file? If so, is the serial support working for you?

    Many thanks,
    RW Senser
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2007-07-24 03:41
    RW Senser,

    I think you can do it simpler.
    Let us use #pragma sx_????? where ????? stands for the directives, as I suggested.
    CC1B throws·warnings that can be ignored.
    When you convert the output
    check if a line starts with whitespace + ";#pragma sx_"
    and if it does, output the remaining of the line, else convert the line as you normally would.
    For #asm and #endasm
    Let us use asm statements by making them comments like
    #asm
    //;nop
    //mov w,#10
    #endasm
    check if a line starts with whitespace + ";#asm"
    If it does output following lines without the leading //
    until you encounter a line that starts with whitespace + ";#endasm"
    Note that we can simply comment out specific assembly statements by placing a ; in front of it.

    Edit: it can even simpler
    Start the main C file with
    #pragma chip SX28 // select device
    #pragma stackLevels 8· //make sure cc1b uses 8 stacklevels
    #asm
    //device OSCHS2, TURBO, STACKX, OPTIONX, BOR42
    //freq 20_000_000
    //id "sampleid"
    //irc_cal irc_fast
    //reset main
    #endasm
    This translates into
    ······· device SX28
    then some constants, followed by
    ······················· ;#pragma chip SX28 // select device
    ······················· ;#pragma stackLevels 8· //make sure cc1b uses 8 stacklevels
    ······················· ;#asm
    ······················· ;//device OSCHS2, TURBO, STACKX, OPTIONX, BOR42
    ······················· ;//freq 20_000_000
    ······················· ;//id "sampleid"
    ······················· ;//irc_cal irc_fast
    ······················· ;//reset main
    ······················· ;#endasm
    Simply scan for whitespace + ";#asm"
    Output following lines removing the whitespace+";//"
    until you encounter a line that starts with whitespace + ";#endasm"
    That works for all assembly statements, including directives and sasm macros!

    regards peter


    Post Edited (Peter Verkaik) : 7/24/2007 8:54:23 AM GMT
  • RW SenserRW Senser Posts: 61
    edited 2007-07-24 16:15
    Hi Peter,

    Yes, your suggestions look good. Let me run some of your examples through CC1B and put some additional thought into this approach.

    Thanks for the great ideas!

    RW Senser
  • BeanBean Posts: 8,129
    edited 2007-07-24 16:17
    RW Senser,
    Now that's the kind of support we like to see [noparse];)[/noparse]

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Teacher: What is the difference between ignorance and apathy ?
    Student: I don't know and I don't care
    Teacher: Correct !
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.hittconsulting.com
    ·
  • RW SenserRW Senser Posts: 61
    edited 2007-07-25 03:49
    Hi Bean and Peter,

    Bean: Thanks for the compliment!

    Peter: I've discussed some of the ideas posted with some other folks. One idea surfaced that seems really nice:

    In the C4SX C program any code lines that start with #prama sx <whatever> would have <whatever> put into the src file sent to the SX-KEY. So for example, all of the DEVICE, FREQ, RESET, etc pnemonics could be coded as

    #pragma sx DEVICE OSCHS3
    #pragma sx IRC_CAL IRC_FAST
    #pragma sx FREQ 50_000_000
    #pragma sx reset main

    This removes the need for the separate header file CC1B2SX.HDR.

    In addition, it would be possible to insert assembler statements with

    #pragma sx mov w,#10

    What do people think? Good, Bad, Or ??? The main thing I don't like is that each #pragma sx line will generate a warning from CC1B. I confirmed this with some test code. These are warnings, not errors.

    Also, I used some SX assembler code in the interrupt handler in SXIO.H. If you look in there, you can see the CC1B rr() and retiw() functions being used. If you are thinking of mixing assembler and C, I would suggest you review the SX.TXT and HEXCODES.H files that are included in the CC1B install. Also it is worth downloading cc5x-33.pdf from the CC1B web site and looking at sections 3 and 6.

    Thoughts?

    All the best,
    RW Senser
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2007-07-25 04:17
    RW Senser,
    The nice thing using the #asm / #endasm idea, is that it is a single method
    that solves all possible problems on how to add something to the
    assembly output. I intend to use sasm macros as well and I want to
    add assembly from the C source, so having #pragma sx before any statement
    is ugly and timeconsuming when typing. That's why the // is almost ideal:
    it takes hardly any time to type and it does not produce warnings.
    As far as cc1b is concerned, it is all comment.
    I did check Hexcode.h and that is even worse, using plain numbers,
    which is unsuitable for macro definitions that I plan to use.
    Doing it now in a way that is invisible to cc1b, prevents possible conflicts with
    any updated cc1b·later and when cc1b·does support·inline assembly using
    sasm mnenomics,·we can simply remove the leading //.
    Edit:
    Or use //? instead of #pragma sx, and anything following the //? is simply written
    to the output file. (/ and ? are on the same key on the keyboard). You then do not
    need to scan for #asm and #endasm, which may optionally be used for clarity
    in the C source file.
    #asm //optional
    //?mov w,#10· ;this will convert to "mov w,#10"
    #endasm //only if #asm used


    regards peter

    Post Edited (Peter Verkaik) : 7/25/2007 2:44:01 PM GMT
  • RW SenserRW Senser Posts: 61
    edited 2007-07-25 18:16
    Hi peter,

    Thanks for the additional feedback. We have something "in the works" that is very close to the "#asm, #endasm" and/or //? approach you mentioned. Basically we are thinking of using a different literal of #asm and #endasm but having the same multi-line functionality. I need to test it some more; if no major bugs show up then I'll post it later on today.

    Again, thanks for the feedback and please provide feedback on this new CC1B2SX version (to come later today). I would describe it in detail here -- but I think the time is better spent if I test then post.

    Thanks,
    RW Senser
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2007-07-25 18:24
    RW Senser,

    One thing that occured to me, is that since all C source is outputted by cc1b as comment,
    there is a restriction on using //? (or whatever approach), it can only be used
    outside conditional compilation. That is not a problem for the main directives like device
    and also not for sasm macros, but it is a problem for inline assembly code inside
    conditional compilation blocks. In that case the codes from Hexcodes.h must be
    used.

    regards peter
  • RW SenserRW Senser Posts: 61
    edited 2007-07-26 02:17
    Hi peter,

    Yes, I suspect you are right about the conditional compile (#ifdefs, etc.) and the use of comments for the mechanism to pass the assembler code to the SX-KEY. In addition, while testing I hit several issues. Some were bugs of mine, which are in the process of getting fixed. However, I hit one other issue that calls into question this approach of passing SX assembler through the CC1B compiler as comments. In a nutshell, if the #asm .. #endasm (or whatever syntax. /*<?sx and ?> */ used in code below) is put at the end of the C program then the CC1B listing (used to communicate CC1B2SX and then with the SX-KEY) does not contain the comments! I'll keep looking at this issue, but this will delay things a bit.

    Anyway, for those interested, a status update.

    Thanks for the feedback,
    RW Senser

    Here is a sample showing the issue:
    C snippet:

    bank0 unsigned char hold;
    bit holdB0 @ hold.0;
    // bank1 char c;

    TRISB = 0xfe; // %1111 1110
    RB = 0;
    while (1) {
    delay();
    holdB0 = pinB0;
    hold++;
    pinB0 = holdB0;
    }

    /*<?sx
    nop
    ?>*/

    becomes in the CC1B output listing:

    ; pinB0 = holdB0;
    SB 16.holdB0
    CLRB 6.pinB0
    SNB 16.holdB0
    SETB 6.pinB0
    ; }
    JMP m008

    ORG $07FF
    JMP main
    END


    ; *** KEY INFO ***

    Notice: the /*<? , etc. is gone!
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2007-07-26 02:57
    RW Senser,
    Remember that cc1b removes any code and variables that are never referenced,
    or in this case, never reached (all code behind while (1) without a break inside the while).
    Change the while (1) to if (1) or add a line if (pinB0) break; inside the while (1)
    and the comments are where they should be.

    regards peter
Sign In or Register to comment.