Shop OBEX P1 Docs P2 Docs Learn Events
C - SimpleIDE, GCC, ETC - Just For The Sake Of Discussion — Parallax Forums

C - SimpleIDE, GCC, ETC - Just For The Sake Of Discussion

idbruceidbruce Posts: 6,197
edited 2015-02-07 14:12 in Propeller 1
A week or so ago, Dave Hein asked:
Bruce, I'm curious why you are converting the Teacup software to Spin, and not just leaving it in C. I noticed that you participated in this thread that attempted to port the C Teacup code to the Propeller. Why not continue from where that thread left off? It seems that converting to Spin code would be error-prone and unnecessary unless the program wouldn't fit in C. Why are you converting it to Spin?

While working on the Teacup port, going through the translation of C to SPIN, I have often pondered his questions. As I look at dda_queue, I now see that it has an array of DDA structures, with a current setting of 8 elements, and to convert these DDA elements to variables and then track them properly..... Let me just say that I am considering options.

Without doing any serious research, is there any Propeller supported C language that is object oriented and supports structures and unions? For example, is there anything out there that will support the following:
typedef struct
{
	TARGET endpoint;

	union {
		struct {
					uint8_t nullmove:1;
					uint8_t live:1;
					uint8_t done:1;					
					uint8_t waitfor_temp :1;
					uint8_t x_direction:1;
					uint8_t y_direction:1;
					uint8_t z_direction:1;
					uint8_t e_direction:1;
				};
				
				uint16_t allflags;
			};
	
	uint32_t x_delta;
	uint32_t y_delta;
	uint32_t z_delta;
	uint32_t e_delta;
	uint32_t total_steps;
	uint32_t fast_um;
	uint32_t fast_spm;
	uint32_t c;
	int32_t n;
	uint32_t rampup_steps;
	uint32_t rampdown_steps;
	uint32_t c_min;
	uint8_t endstop_check;
	uint8_t endstop_stop_cond;
  
} DDA;

Source: Teacup firmware - dda.h

Comments

  • Bill HenningBill Henning Posts: 6,445
    edited 2015-02-07 09:14
    Hi,

    Both propgcc and Catalina should compile that just fine.
  • idbruceidbruce Posts: 6,197
    edited 2015-02-07 09:25
    Hey Bill
    Both propgcc and Catalina should compile that just fine.

    Are you sure? :)
  • David BetzDavid Betz Posts: 14,516
    edited 2015-02-07 10:15
    idbruce wrote: »
    A week or so ago, Dave Hein asked:



    While working on the Teacup port, going through the translation of C to SPIN, I have often pondered his questions. As I look at dda_queue, I now see that it has an array of DDA structures, with a current setting of 8 elements, and to convert these DDA elements to variables and then track them properly..... Let me just say that I am considering options.

    Without doing any serious research, is there any Propeller supported C language that is object oriented and supports structures and unions? For example, is there anything out there that will support the following:
    typedef struct
    {
    	TARGET endpoint;
    
    	union {
    		struct {
    					uint8_t nullmove:1;
    					uint8_t live:1;
    					uint8_t done:1;					
    					uint8_t waitfor_temp :1;
    					uint8_t x_direction:1;
    					uint8_t y_direction:1;
    					uint8_t z_direction:1;
    					uint8_t e_direction:1;
    				};
    				
    				uint16_t allflags;
    			};
    	
    	uint32_t x_delta;
    	uint32_t y_delta;
    	uint32_t z_delta;
    	uint32_t e_delta;
    	uint32_t total_steps;
    	uint32_t fast_um;
    	uint32_t fast_spm;
    	uint32_t c;
    	int32_t n;
    	uint32_t rampup_steps;
    	uint32_t rampdown_steps;
    	uint32_t c_min;
    	uint8_t endstop_check;
    	uint8_t endstop_stop_cond;
      
    } DDA;
    

    Source: Teacup firmware - dda.h
    There is nothing unusual about that code. PropGCC will have no trouble with it.
  • idbruceidbruce Posts: 6,197
    edited 2015-02-07 10:29
    Thanks David and Bill

    I have already downloaded SimpleIDE and PropGCC, and I am currently reviewing the documentation.

    Nothing ventured, nothing gained :)
  • Heater.Heater. Posts: 21,230
    edited 2015-02-07 11:14
    Bruce,
    Without doing any serious research, is there any Propeller supported C language that is object oriented and supports structures and unions? For example, is there anything out there that will support the following:
    There is one one C language. (All be it in some slight variations as it's standard has evolved).

    C has always supported structs and unions.

    Object oriented programming can be done in any language. C++ and others of course provide languages features that make OOP much easier.

    That code you are translating was originally written for the Arduino. The Arduino uses the same GCC compiler as the Propeller. prop-gcc is GCC with a Propeller target output as opposed to avr-gcc as used by Arduino with AVR targets.
    Are we sure.
    Yes. In fact if it does not compile that is a bug that needs reporting somewhere.

    Except...On the Prop the same functionality as Spin will result in much bigger executable code when written and compiled as C.

    It may not fit the Prop.
  • idbruceidbruce Posts: 6,197
    edited 2015-02-07 11:47
    Heater

    Thank you very much for an informative answer.
    Except...On the Prop the same functionality as Spin will result in much bigger executable code when written and compiled as C.

    It may not fit the Prop.

    Approximately how much bigger, percentage wise? Although I am fairly sure this will depend on the memory model chosen.
  • David BetzDavid Betz Posts: 14,516
    edited 2015-02-07 12:08
    idbruce wrote: »
    Heater

    Thank you very much for an informative answer.



    Approximately how much bigger, percentage wise? Although I am fairly sure this will depend on the memory model chosen.
    Using the LMM memory model will be at least twice as big as Spin and probably more. Using CMM will be fairly similar in size to Spin although possibly a bit bigger. XMMC will let you run very large programs if you have external memory attached to your Propeller. SPI flash works best.
  • Heater.Heater. Posts: 21,230
    edited 2015-02-07 12:13
    Good question Bruce.

    I don't recall any code size comparisons now but there has been some posted here occasionally .

    prop-gcc can compile to LMM which is quite space hungry but fast. Or it can compile to CMM (Compressed Memory Model) which I believe compares in size and speed with Spin.

    Personally I have not looked into these things very much.

    I guess at the end of the day one has to compile the code with the various options of prop-gcc. Then, if the code fits in the Prop, run it and see what the speed is like.
  • idbruceidbruce Posts: 6,197
    edited 2015-02-07 12:50
    @David
    Using the LMM memory model will be at least twice as big as Spin and probably more. Using CMM will be fairly similar in size to Spin although possibly a bit bigger. XMMC will let you run very large programs if you have external memory attached to your Propeller. SPI flash works best.

    David thanks for that answer - I have a Propeller Memory Card attached to the controller, so it sounds like XMMC would be a nice option.

    @Heater
    I guess at the end of the day one has to compile the code with the various options of prop-gcc. Then, if the code fits in the Prop, run it and see what the speed is like.

    I suppose I will take a little time and poke a stick at it. Just between dda.c, dda_queue.c, dda_maths.c, gcode_parse.c, and gcode_process.c, a partial port might develop faster than the route that I am currently taking. Why write code if it is already written? But then again, who knows....
  • idbruceidbruce Posts: 6,197
    edited 2015-02-07 13:02
    Thanks for the responses and informative answers.
  • idbruceidbruce Posts: 6,197
    edited 2015-02-07 13:48
    Just for Giggles, I performed a simple test, which was as follows:

    **Please note that I removed all includes from linked files that I had no interest in retaining.

    Code submitted for compiling
    #include "dda.h"
    #include "dda_maths.h"
    #include "dda_queue.h"
    #include "gcode_parse.h"
    #include	"gcode_process.h"
    #include	"pinio.h"
    #include <math.h>
    #include	<stdint.h>
    #include <stdlib.h>
    #include	<string.h>
    
    int main(void)
    {
      return 0;
    }
    

    And the results
    Project Directory: C:/Documents and Settings/Bruce/Desktop/SimpleIDE/Teacup/TeacupPort/
    
    SimpleIDE Version 1.0.2
    C:/Documents and Settings/Bruce/Desktop/SimpleIDE/Learn/Simple Libraries/
    C:/Documents and Settings/Bruce/Desktop/SimpleIDE/ Updated on: 2015-02-07
    
    propeller-elf-gcc.exe -v GCC 4.6.1 (propellergcc_v1_0_0_2408)
    propeller-elf-gcc.exe -I . -L . -Os -mcmm -Wall -m32bit-doubles -fno-exceptions -std=c99 -c dda.c -o cmm/dda.o
    In file included from dda.c:5:0:
    dda_maths.h: In function 'um_to_steps_x':
    dda_maths.h:29:31: error: 'STEPS_PER_M_X' undeclared (first use in this function)
    dda_maths.h:29:31: note: each undeclared identifier is reported only once for each function it appears in
    dda_maths.h: In function 'um_to_steps_y':
    dda_maths.h:35:31: error: 'STEPS_PER_M_Y' undeclared (first use in this function)
    dda_maths.h: In function 'um_to_steps_z':
    dda_maths.h:41:31: error: 'STEPS_PER_M_Z' undeclared (first use in this function)
    dda_maths.h: In function 'um_to_steps_e':
    dda_maths.h:47:31: error: 'STEPS_PER_M_E' undeclared (first use in this function)
    In file included from dda.c:7:0:
    dda_queue.h: At top level:
    dda_queue.h:15:23: error: 'MOVEBUFFER_SIZE' undeclared here (not in a function)
    dda.c:13:12: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'startpoint'
    dda.c:14:12: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'startpoint_steps'
    dda.c:15:12: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'current_position'
    dda.c:16:16: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'move_state'
    dda.c: In function 'dda_init':
    dda.c:24:41: error: 'SEARCH_FEEDRATE_Z' undeclared (first use in this function)
    dda.c: In function 'dda_create':
    dda.c:85:2: warning: implicit declaration of function 'memcpy' [-Wimplicit-function-declaration]
    dda.c:85:2: warning: incompatible implicit declaration of built-in function 'memcpy' [enabled by default]
    dda.c:89:2: warning: implicit declaration of function 'labs' [-Wimplicit-function-declaration]
    dda.c:89:25: warning: incompatible implicit declaration of built-in function 'labs' [enabled by default]
    dda.c:126:18: error: 'STEPS_PER_M_X' undeclared (first use in this function)
    dda.c:132:19: error: 'STEPS_PER_M_Y' undeclared (first use in this function)
    dda.c:139:19: error: 'STEPS_PER_M_Z' undeclared (first use in this function)
    dda.c:146:19: error: 'STEPS_PER_M_E' undeclared (first use in this function)
    dda.c:156:3: warning: implicit declaration of function 'power_on' [-Wimplicit-function-declaration]
    dda.c:157:3: warning: implicit declaration of function 'stepper_enable' [-Wimplicit-function-declaration]
    dda.c:158:3: warning: implicit declaration of function 'x_enable' [-Wimplicit-function-declaration]
    dda.c:159:3: warning: implicit declaration of function 'y_enable' [-Wimplicit-function-declaration]
    dda.c:161:3: warning: implicit declaration of function 'e_enable' [-Wimplicit-function-declaration]
    dda.c:198:70: error: 'F_CPU' undeclared (first use in this function)
    dda.c:211:79: error: 'MAXIMUM_FEEDRATE_X' undeclared (first use in this function)
    dda.c:219:79: error: 'MAXIMUM_FEEDRATE_Y' undeclared (first use in this function)
    dda.c:227:79: error: 'MAXIMUM_FEEDRATE_Z' undeclared (first use in this function)
    dda.c:235:79: error: 'MAXIMUM_FEEDRATE_E' undeclared (first use in this function)
    dda.c:270:12: error: 'ACCELERATION' undeclared (first use in this function)
    dda.c: In function 'dda_start':
    dda.c:304:3: error: 'psu_timeout' undeclared (first use in this function)
    dda.c:308:4: warning: implicit declaration of function 'z_enable' [-Wimplicit-function-declaration]
    dda.c:313:4: warning: implicit declaration of function 'endstops_on' [-Wimplicit-function-declaration]
    dda.c:317:3: warning: implicit declaration of function 'x_direction' [-Wimplicit-function-declaration]
    dda.c:318:3: warning: implicit declaration of function 'y_direction' [-Wimplicit-function-declaration]
    dda.c:319:3: warning: implicit declaration of function 'z_direction' [-Wimplicit-function-declaration]
    dda.c:320:3: warning: implicit declaration of function 'e_direction' [-Wimplicit-function-declaration]
    dda.c:332:3: error: 'move_state' undeclared (first use in this function)
    dda.c:333:3: warning: incompatible implicit declaration of built-in function 'memcpy' [enabled by default]
    dda.c:342:3: warning: implicit declaration of function 'setTimer' [-Wimplicit-function-declaration]
    dda.c: In function 'dda_step':
    dda.c:360:8: error: 'DDA' has no member named 'axis_to_step'
    dda.c:362:3: warning: implicit declaration of function 'x_step' [-Wimplicit-function-declaration]
    dda.c:363:3: error: 'move_state' undeclared (first use in this function)
    dda.c:364:27: error: 'DDA' has no member named 'x_step_interval'
    dda.c:374:4: warning: implicit declaration of function 'y_step' [-Wimplicit-function-declaration]
    dda.c:386:4: warning: implicit declaration of function 'z_step' [-Wimplicit-function-declaration]
    dda.c:398:4: warning: implicit declaration of function 'e_step' [-Wimplicit-function-declaration]
    dda.c:421:3: warning: implicit declaration of function 'z_disable' [-Wimplicit-function-declaration]
    dda.c:425:3: error: 'psu_timeout' undeclared (first use in this function)
    dda.c:435:2: warning: implicit declaration of function 'unstep' [-Wimplicit-function-declaration]
    dda.c: In function 'dda_clock':
    dda.c:454:25: error: 'NULL' undeclared (first use in this function)
    dda.c:463:3: error: 'move_state' undeclared (first use in this function)
    dda.c:483:2: warning: implicit declaration of function 'sei' [-Wimplicit-function-declaration]
    dda.c:489:5: error: unknown type name 'ATOMIC_START'
    dda.c:491:2: error: conflicting types for 'move_step_no'
    dda.c:456:11: note: previous declaration of 'move_step_no' was here
    dda.c:496:2: error: unknown type name 'ATOMIC_END'
    dda.c:498:2: error: conflicting types for 'recalc_speed'
    dda.c:457:10: note: previous declaration of 'recalc_speed' was here
    dda.c:517:13: error: 'F_CPU' undeclared (first use in this function)
    dda.c:517:13: error: 'STEPS_PER_M_X' undeclared (first use in this function)
    dda.c:517:13: error: 'ACCELERATION' undeclared (first use in this function)
    dda.c:536:3: error: unknown type name 'ATOMIC_START'
    dda.c:538:6: error: expected '=', ',', ';', 'asm' or '__attribute__' before '->' token
    dda.c:540:3: error: 'ATOMIC_END' undeclared (first use in this function)
    dda.c:541:5: error: expected ';' before '}' token
    dda.c:543:2: warning: implicit declaration of function 'cli' [-Wimplicit-function-declaration]
    dda.c:455:10: warning: unused variable 'endstop_trigger' [-Wunused-variable]
    dda.c: In function 'update_current_position':
    dda.c:566:43: error: 'move_state' undeclared (first use in this function)
    dda.c:566:73: error: 'STEPS_PER_M_X' undeclared (first use in this function)
    dda.c:575:73: error: 'STEPS_PER_M_Y' undeclared (first use in this function)
    dda.c:584:73: error: 'STEPS_PER_M_Z' undeclared (first use in this function)
    dda.c:593:55: error: 'STEPS_PER_M_E' undeclared (first use in this function)
    dda.c: In function 'um_to_steps_x':
    dda_maths.h:31:1: warning: control reaches end of non-void function [-Wreturn-type]
    dda.c: In function 'um_to_steps_y':
    dda_maths.h:37:1: warning: control reaches end of non-void function [-Wreturn-type]
    dda.c: In function 'um_to_steps_z':
    dda_maths.h:43:1: warning: control reaches end of non-void function [-Wreturn-type]
    dda.c: In function 'um_to_steps_e':
    dda_maths.h:49:1: warning: control reaches end of non-void function [-Wreturn-type]
    Done. Build Failed!
    
    Click error or warning messages above to debug.
    

    Doesn't look too horrible
  • Dave HeinDave Hein Posts: 6,347
    edited 2015-02-07 14:11
    Bruce, I believe you need to define a few parameters that are specific to your application. They should be in a file called config_wrapper.h. There are several example config files included in the source code, such as config.default, config.teensy and config.rumba. Take a look at those for clues on how you should define things.

    EDIT: I see you found config.h while I was editing this post.
  • idbruceidbruce Posts: 6,197
    edited 2015-02-07 14:11
    And then adding a file named config.h, which defined many of the constants, cleaned up the results quite a bit.
    Project Directory: C:/Documents and Settings/Bruce/Desktop/SimpleIDE/Teacup/TeacupPort/
    
    SimpleIDE Version 1.0.2
    C:/Documents and Settings/Bruce/Desktop/SimpleIDE/Learn/Simple Libraries/
    C:/Documents and Settings/Bruce/Desktop/SimpleIDE/ Updated on: 2015-02-07
    
    propeller-elf-gcc.exe -v GCC 4.6.1 (propellergcc_v1_0_0_2408)
    propeller-elf-gcc.exe -I . -L . -Os -mcmm -Wall -m32bit-doubles -fno-exceptions -std=c99 -c dda.c -o cmm/dda.o
    dda.c:13:12: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'startpoint'
    dda.c:14:12: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'startpoint_steps'
    dda.c:15:12: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'current_position'
    dda.c:16:16: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'move_state'
    dda.c: In function 'dda_create':
    dda.c:85:2: warning: implicit declaration of function 'memcpy' [-Wimplicit-function-declaration]
    dda.c:85:2: warning: incompatible implicit declaration of built-in function 'memcpy' [enabled by default]
    dda.c:89:2: warning: implicit declaration of function 'labs' [-Wimplicit-function-declaration]
    dda.c:89:25: warning: incompatible implicit declaration of built-in function 'labs' [enabled by default]
    dda.c:156:3: warning: implicit declaration of function 'power_on' [-Wimplicit-function-declaration]
    dda.c:157:3: warning: implicit declaration of function 'stepper_enable' [-Wimplicit-function-declaration]
    dda.c:158:3: warning: implicit declaration of function 'x_enable' [-Wimplicit-function-declaration]
    dda.c:159:3: warning: implicit declaration of function 'y_enable' [-Wimplicit-function-declaration]
    dda.c:161:3: warning: implicit declaration of function 'e_enable' [-Wimplicit-function-declaration]
    dda.c: In function 'dda_start':
    dda.c:304:3: error: 'psu_timeout' undeclared (first use in this function)
    dda.c:304:3: note: each undeclared identifier is reported only once for each function it appears in
    dda.c:308:4: warning: implicit declaration of function 'z_enable' [-Wimplicit-function-declaration]
    dda.c:313:4: warning: implicit declaration of function 'endstops_on' [-Wimplicit-function-declaration]
    dda.c:317:3: warning: implicit declaration of function 'x_direction' [-Wimplicit-function-declaration]
    dda.c:318:3: warning: implicit declaration of function 'y_direction' [-Wimplicit-function-declaration]
    dda.c:319:3: warning: implicit declaration of function 'z_direction' [-Wimplicit-function-declaration]
    dda.c:320:3: warning: implicit declaration of function 'e_direction' [-Wimplicit-function-declaration]
    dda.c:332:3: error: 'move_state' undeclared (first use in this function)
    dda.c:333:3: warning: incompatible implicit declaration of built-in function 'memcpy' [enabled by default]
    dda.c:342:3: warning: implicit declaration of function 'setTimer' [-Wimplicit-function-declaration]
    dda.c: In function 'dda_step':
    dda.c:360:8: error: 'DDA' has no member named 'axis_to_step'
    dda.c:362:3: warning: implicit declaration of function 'x_step' [-Wimplicit-function-declaration]
    dda.c:363:3: error: 'move_state' undeclared (first use in this function)
    dda.c:364:27: error: 'DDA' has no member named 'x_step_interval'
    dda.c:374:4: warning: implicit declaration of function 'y_step' [-Wimplicit-function-declaration]
    dda.c:386:4: warning: implicit declaration of function 'z_step' [-Wimplicit-function-declaration]
    dda.c:398:4: warning: implicit declaration of function 'e_step' [-Wimplicit-function-declaration]
    dda.c:421:3: warning: implicit declaration of function 'z_disable' [-Wimplicit-function-declaration]
    dda.c:425:3: error: 'psu_timeout' undeclared (first use in this function)
    dda.c:435:2: warning: implicit declaration of function 'unstep' [-Wimplicit-function-declaration]
    dda.c: In function 'dda_clock':
    dda.c:454:25: error: 'NULL' undeclared (first use in this function)
    dda.c:463:3: error: 'move_state' undeclared (first use in this function)
    dda.c:483:2: warning: implicit declaration of function 'sei' [-Wimplicit-function-declaration]
    dda.c:489:5: error: unknown type name 'ATOMIC_START'
    dda.c:491:2: error: conflicting types for 'move_step_no'
    dda.c:456:11: note: previous declaration of 'move_step_no' was here
    dda.c:496:2: error: unknown type name 'ATOMIC_END'
    dda.c:498:2: error: conflicting types for 'recalc_speed'
    dda.c:457:10: note: previous declaration of 'recalc_speed' was here
    dda.c:536:3: error: unknown type name 'ATOMIC_START'
    dda.c:538:6: error: expected '=', ',', ';', 'asm' or '__attribute__' before '->' token
    dda.c:540:3: error: 'ATOMIC_END' undeclared (first use in this function)
    dda.c:541:5: error: expected ';' before '}' token
    dda.c:543:2: warning: implicit declaration of function 'cli' [-Wimplicit-function-declaration]
    dda.c:455:10: warning: unused variable 'endstop_trigger' [-Wunused-variable]
    dda.c: In function 'update_current_position':
    dda.c:566:43: error: 'move_state' undeclared (first use in this function)
    Done. Build Failed!
    
    Click error or warning messages above to debug.
    
    
  • idbruceidbruce Posts: 6,197
    edited 2015-02-07 14:12
    Dave

    I was doing that as you typed :)

    Same time stamp on our posts :)
Sign In or Register to comment.