A loop cycle that is not running on the C operating system

I am having problems executing a for loop, I created a static table that contains specific values, and then pass my table as an argument to a function to process. basically my code is as follows:

#define ID_01 0x0000
#define ID_02 0x0001
#define ID_03 0x0002
#define ID_04 0x0003
#define ID_05 0x0004
#define ID_06 0x0005
#define ID_07 0x0006
#define ID_08 0x0007
#define ID_09 0x0008
/*...
*/
#define ID_LAST 0xFFFF
static char table[]={
ID_01, ID_02 ,ID_03, ID_04, .... , ID_LAST}

void process( char *table){

    int LastId=0; 
    char *Command; 

    for ( Command=table; LastId==0 ; Command++){
        switch(Command) 
        {
            case ID_01: 
                do_stuff01();
                break;
            case ID_02: 
                do_stuff02();
                break; 
            ...

            case ID_LAST: 
                LastId=1;
                break;
            default: 
                 break;
          } 
    }
}

I tried to print some messages for debugging, but the program does not perform any of the prints, even those that were before and after the cycle.

But when I changed the for loop to:

for(i=0;i<10;i++)

all messages were printed. but I have to process the same as me in the first place.

PS: this part of the code is executed in the task of the operating system running in the microcontroller, and I'm just a beginner.

+4
2

switch (Command), Command od table.

switch

switch (*Command) { //Use value at pointed Command.

}

, *Command char, 1 . 2 , .

:

static char table[] = {ID_01, ID_02 ,ID_03, ID_04, .... , ID_LAST}

16-

static unsigned short table[]={ID_01, ID_02 ,ID_03, ID_04, .... , ID_LAST}

process, unsigned short

void process( const unsigned short *table) { //Unsigned short
    int LastId = 0; 
    unsigned short *Command;  //Unsigned short

    for ( Command=table; LastId==0 ; Command++){
        switch(*Command) { //Added star
            //...
        }
    }
    //...

process:

void process(const unsigned short *table, size_t tableLen) {
    while (tableLen--) {
        switch (*table) {
            case ID_1: /* Do stuff */ break;
        }
        table++; //Increase pointer to next ID element
    }
}

//Usage then like this:
static unsigned short table[] = {ID_1, ID_2, ID_3, ..., ID_n};
//Put pointer and length of table
process(table, sizeof(table)/sizeof(table[0]));
+5

, ID/FUNC, .

#include <stdio.h>

#define ID_01 0x0000
#define ID_02 0x0001
/* ... */
#define ID_LAST 0xFFFF

typedef void (*func)();

typedef struct {
  char n;
  func f;
} fmap;

void do_something01() { }
void do_something02() { }
/* ... */

static fmap fmaps[] = {
  {ID_01, do_something01},
  {ID_02, do_something02},
  /* ... */
  {ID_LAST, NULL},
};
+1

Source: https://habr.com/ru/post/1680476/


All Articles