Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
Jan Waclawek
10/27/11 04:15
Read: 734 times

#184389 - compatibility et al
Responding to: Marshall Brown's previous message

Marshall Brown said:
While I was happy to release the code to the public domain, I lack the motivation to make it cross compiler compatible. (and I don't have access to the other compilers)

I could download SDCC, but never really had the need, Raisonance works well.
I understand that.

I think, we still can discuss the code from the aspects of various compilers.

I've just downloaded and installed the Raisonance toolchain and obtained the "hobby" (code size limited) licence. Should be fun.
Marshall Brown said:

Obviously I want to make the code as tidy as possible so if there are bugs I'm keen to fix them.

I don't think we should call them bugs.

I started from the code you posted above, (ignoring the changes you've discussed with Per), and made the following changes:

- added a "compatibility" #ifdef chain, currently only for the code/__code keyword (not exactly necessary for SDCC, but the non-underscored version in SDCC now deprecated, plus I anticipate there will be more "compiler dependent" things we can put in there - that might become a header later)

- made the related changes in declarations from code to CODE; added code as pointer target type in first member of strct_running_recipe

- commented out the #includes for files I don't have; I had to add a few #defines because of that

- changed the assignment to NULL to simple zero (as I described previously)

Now it compiles both in RC51 and SDCC; in the latter it throws the famous and confusing "EVELYN" warning
c:Program FilesRaisonanceRideExamplesMyProjectssdcc>make

c:Program FilesRaisonanceRideExamplesMyProjectssdcc>sdcc -c ..smoker.c
..smoker.c:145: warning 110: conditional flow changed by optimizer: so said EVE
LYN the modified DOG

c:Program FilesRaisonanceRideExamplesMyProjectssdcc>
but that's simply the result of optimizer throwing out the unfinished empty conditional statements, and thus can be safely ignored for now.


#if defined __RC51__
  #define CODE code
#elif defined SDCC
  #define CODE __code
  #error "Unknown compiler"

#include <c8051F040.h>

// #include "ports.h"
// #include "smoker_iopoints.h"
// #include "nib.h"
// #include "LCD.h"
// #include "time.h"
// #include "recipes.h"

// #include <stdlib.h> // not needed while NULL is commented out

#define NUM_OF_RULES_PER_RECIPE     10

//this file handles the saving / restoring and control of the recipes for the smoker.
//in short we have only a few variables that we are able to control we can load these in a struct and save the whole struct to flash.

#define RULE_ACTION_ON          1
#define RULE_ACTION_OFF         2
#define RULE_ACTION_PULSE       4

#define RULE_START_COND_ANY_RULE       3

#define RULE_FEEDBACK_TIME_OFF          2
#define RULE_FEEDBACK_TIME_ON           3

#define RULE_NOT_STARTED                0
#define RULE_IN_PROGRESS                1
#define RULE_COMPLETED                  2

struct strct_rules{
    unsigned char out_point;
    unsigned char action;
    unsigned char start_condition;
    unsigned char start_time;
    unsigned char stop_time;
    unsigned char feedback_rule;
    unsigned char feedback_point;

struct recipe{
    char    title[16];                   // RECIPE TITLE
    unsigned int run_time;
    struct strct_rules rules[NUM_OF_RULES_PER_RECIPE];       //each recipe has 10 rules that it can have.


#define HEAT_OUTPUT 0
#define SMOKE_OUTPUT 1
#define PUMP_OUTPUT 2

CODE struct recipe salmon = {
    "SALMON",       //nice title
    20,             //run for 20mins
        {SMOKE_OUTPUT,  RULE_ACTION_ON,         RULE_START_COND_ABSOLUTE,   0, 5, RULE_FEEDBACK_TIME_OFF,   0},                           //turn on the smoke for 5mins
        {PUMP_OUTPUT,   RULE_ACTION_PULSE,      RULE_START_COND_PRIOR_RULE, 0, 1, RULE_FEEDBACK_TIME_OFF,   0},                           //start the pump pulsing for 1 min on / off after smoke has been on for 5mins
        {SMOKE_OUTPUT,  RULE_ACTION_PULSE,      RULE_START_COND_PRIOR_RULE, 0, 1, RULE_FEEDBACK_TIME_OFF,   0}                           //start the smoke pulsing for 1 min on / off after pump has been on for 1mins

struct strct_running_recipe {
    CODE struct recipe *recipe_in_flash;
    unsigned int recipe_elapsed_time;
    unsigned int rule_elapsed_time[NUM_OF_RULES_PER_RECIPE];    //hold variable for the elapsed time in a rule
    unsigned char rule_holding_var[NUM_OF_RULES_PER_RECIPE];
    unsigned char rule_active[NUM_OF_RULES_PER_RECIPE];

//load a few defaults for us
//cold smoke
//hot smoke

struct strct_running_recipe current_recipe;

void funInitRecipe(void){
    unsigned char i;
    static unsigned char j;
    current_recipe.recipe_in_flash = &salmon;
    current_recipe.recipe_elapsed_time = 0;

    for (i = 0; i< NUM_OF_RULES_PER_RECIPE; i++){
        current_recipe.rule_elapsed_time[i] = 0;
        current_recipe.rule_holding_var[i] = 0; // NULL;
        current_recipe.rule_active[i] = RULE_NOT_STARTED;

    i = current_recipe.recipe_in_flash->rules[1].stop_time;
    j = i;

void funExecuteRecipe(void){
//this function assumes that current_recipe is loaded with a recipe and is
//available, we could have had it accept a recipe pointer but that seems kind of redunant
//as we can only run one recipe at a time.
    static unsigned long start_time = 0;
    unsigned char rule_index = 0;

    if (start_time == 0){
//        start_time = sysTime;

    //whip through all the rules and look for the inactive rules.
    for (rule_index = 0 ; rule_index < NUM_OF_RULES_PER_RECIPE; rule_index++){

        if (current_recipe.rule_active[rule_index]== RULE_NOT_STARTED){ //rule is not active
            if (current_recipe.recipe_in_flash->rules[rule_index].start_condition == RULE_START_COND_ABSOLUTE){ //se if we are supposed to start on a time stamp.
                //obviously more to do in here.


List of 23 messages in thread
User entered recipes ???      Marshall Brown      10/24/11 13:35      
   Just create array of regular rules      Per Westermark      10/24/11 15:30      
      Thanks - that's great      Marshall Brown      10/24/11 17:35      
         programming language      Jan Waclawek      10/25/11 00:55      
            programming language - not really      Marshall Brown      10/25/11 01:21      
               consider enum        Per Westermark      10/25/11 01:48      
                  thanks - implemented.      Marshall Brown      10/25/11 02:23      
                     Intelligence      Per Westermark      10/25/11 02:34      
                        I must have a stupid compiler      Marshall Brown      10/25/11 03:05      
                           Not all compilers are as good at generate warnings      Per Westermark      10/25/11 03:28      
                              no warning/error on the compiler      Marshall Brown      10/25/11 03:55      
                                 response from Raisonance      Marshall Brown      10/27/11 09:51      
                  enumerations on 8051      Andy Peters      10/25/11 12:14      
                     enums are 8bit by default on Raisonance      Marshall Brown      10/25/11 12:42      
                        NULL      Jan Waclawek      10/26/11 04:08      
                           Could you show me the code      Marshall Brown      10/26/11 13:49      
                              compatibility et al      Jan Waclawek      10/27/11 04:15      
                                 why change pointer to CODE?      Marshall Brown      10/27/11 10:21      
                                    enum advantage      Michael Karas      10/27/11 11:18      
                                    user page does not work (at least for me)      Jan Waclawek      10/28/11 15:26      
                                       try it now      Marshall Brown      10/30/11 17:08      
                     re: enumerations on 8051      Andy Peters      11/01/11 15:22      
   Article on Hierarchical Menu Structure      Aubrey Kagan      11/02/11 09:42      

Back to Subject List