I'm using the PICC CCS C compiler and am having issues with starting an enque/deque for my program. What I need it to do is to hold about 9 data packets, each packet is an array of 4 HEX integers. Each array is a different command for the program.
example of array commands:
Expand|Select|Wrap|Line Numbers
- int ph[4] = {0x18, 0x2B, 0x00, 0x00};
- int zt[4] = {0x28, 0x35, 0x00, 0x00};
- int zw[4] = {0x28, 0x37, 0x00, 0x00};
- int af[4] = {0x28, 0x41, 0x00, 0x00};
- int off[4] = {0x18, 0x5E, 0x00, 0x00};
From what I understand, I need an enque() function that will store up to 9 packets (or more depending on how large the program gets) and then a deque() function that will spill them out in a FIFO style. Is that correct? Below is what I've started, but I'm not sure if I'm headed in the right direction:
Expand|Select|Wrap|Line Numbers
- typedef struct
- {
- int front; //location of front of queue
- int rear; //location of rear of queue
- int max_size; //queue can hold 9 packets
- int packet[9][10]; //make sure queue is large enough
- } queue;
- typedef struct
- {
- int packet[9][10]; //make sure queue is large enough
- } packet;
- //add to front of queue, stack on top
- int1 enqueue (queue *working_queue ,packet *packets[]) //bring in que & packet to load
- {
- working_queue.front++; //increas front by one
- if (working_queue.front > working_queue.max_size) //if at end, loop around and write over old packets
- {
- working_queue.front = 0;
- }
- memcpy(working_queue.packet[working_queue.front], packets.packet[0], sizeof(working_queue.packet)); //copies packet to struct
- return 0;
- }
K