I have an array of structs like so:
Expand|Select|Wrap|Line Numbers
- //populates Message control object(st_cmd_t)and acts
- //as a container for the sourrounding data
- CanMsgObj* Populate_CanMsgObj()
- {
- //make a pointer to required structure
- CanMsgObj *MsgObj;
- //assign memory to structure
- MsgObj = malloc(sizeof(CanMsgObj));
- //assign memory to the st_cmd_t
- MsgObj->interface=Prepare_st_cmd_t();
- //Set Default Action
- MsgObj->mode=MODE_SEND;
- //zero the timer
- MsgObj->timer=1;
- MsgObj->local_time_overrun=0;
- //is the timer translated to local time? 0-no, 1-yes
- MsgObj->local_time=0;
- //set the mask to accept only this address
- long unsigned u32_temp;
- u32_temp=~0;
- MsgObj->mask=u32_temp;
- //zwroc obiekt
- return MsgObj;
- }
- //prepares the st_cmd_t structure by allocating memory
- st_cmd_t* Prepare_st_cmd_t()
- {
- //create a message object pointer
- st_cmd_t *msg;
- //allocate memory
- msg = malloc(sizeof(st_cmd_t));
- //create a pointer to data table
- U8 *buffer;
- //create space for data
- buffer = malloc(sizeof(U8)*8);
- //set the allcocated space to 0's
- for(int i=0; i<8; i++)
- {
- buffer[i]=7-(unsigned char)i;
- }
- //assign table to message
- msg->pt_data = &buffer[0];
- //mark data lenght 0
- msg->dlc = 8;
- //set default command mode (receive)
- msg->cmd = CMD_TX;
- //default CAN message number (x1234)
- int id=123;
- msg->id.std = id;
- //default to 11bit numbering
- msg->ctrl.ide = 0;
- //not a request frame
- msg->ctrl.rtr = 0;
- //return created and allocated st_cmd_t structure
- return msg;
- }
- //create a CanMsgObjArray
- volatile CanMsgObj *CanObjArray[15];
- //populate CanMsgObjArray
- for (int i=0; i<16; i++)
- {
- CanObjArray[i]=Populate_CanMsgObj();
- }
- //create a UART_MessageTracker pointer
- UART_MessageTracker *UART_Tracker;
- //prepare the tracker
- UART_MessageTracker* CreateUART_MessageTracker()
- {
- UART_MessageTracker *Tracker;
- Tracker = malloc(sizeof(UART_MessageTracker));
- Tracker->PropGroup=0;
- Tracker->MObj_no=0;
- Tracker->cnt=0;
- return Tracker;
- }
- //USART1 byte recevied interrupt handling
- ISR(USART1_RX_vect)
- {
- UART_hit(UART_Tracker, CanObjArray[UART_Tracker->MObj_no]);
- }
- main()
- {
- while(1);
- }
The question is : how to pass the CanObjArray to UART_hit so I can have access to all of the 15 structs inside?
I'm really stuck here :(
Thanks in advance for your suggestions!
(gucio)