-
Notifications
You must be signed in to change notification settings - Fork 0
/
r3_queuies.c
105 lines (86 loc) · 3.26 KB
/
r3_queuies.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/**
* @file r3_queuies.c
* Copyright 2022 R3 Solutions GmbH
* Version 1.0
*/
/* ************************** INCLUDES ************************** */
#include "r3_frameTypes.h"
#include "r3_interrupt_control.h"
#include "memory_mgmt.h"
/* ************************** DEFINES *************************** */
/* ************************** ENUMS ***************************** */
typedef enum r3_rxh_framePoolType_e
{
R3_RXH_FRAMEPOOLTYPE_RECEIVED_FREE = 1,
R3_RXH_FRAMEPOOLTYPE_RECEIVED_IN_DECRYPTION,
R3_RXH_FRAMEPOOLTYPE_NUM
} r3_rxh_framePoolType_e;
typedef struct r3_rx_frame_t {
struct r3_rx_frame_t *next;
struct r3_rx_frame_t *prev;
r3_u32 id;
void* data;
} r3_rx_frame_t;
typedef struct r3_rxh_frameLinkedList_t
{
r3_rx_frame_t *head; // points to first element, null if none in list
r3_rx_frame_t *tail; // points to the last element, null if none in list
r3_u16 numFrames;
} r3_rxh_frameLinkedList_t;
/* ************************** STRUCTS *************************** */
/* ************************** VARIABLES ************************* */
r3_rxh_frameLinkedList_t rxFramePool[R3_RXH_FRAMEPOOLTYPE_NUM];
/* ************************** FUNCTIONS ************************* */
void r3_rxh_initFramePools(r3_u8 amountOfRxFrames, unsigned int amountOfDiagnosticBuffer)
{
rxFirstFrame = (r3_rx_frame_t *) malloc(amountOfRxFrames * sizeof(r3_rx_frame_t));
r3_u8 iterator = 0;
for (iterator = 0; iterator < amountOfRxFrames; iterator++)
{
rxFirstFrame[iterator].id = iterator;
rxFirstFrame[iterator].next = rxFirstFrame[iterator + 1];
rxFirstFrame[iterator].prev = rxFirstFrame[iterator - 1];
}
rxFramePool[R3_RXH_FRAMEPOOLTYPE_RECEIVED_FREE].head = rxFirstFrame;
rxFramePool[R3_RXH_FRAMEPOOLTYPE_RECEIVED_FREE].tail = rxFirstFrame + amountOfRxFrames;
rxFramePool[R3_RXH_FRAMEPOOLTYPE_RECEIVED_FREE].tail->next = NULL;
rxFramePool[R3_RXH_FRAMEPOOLTYPE_RECEIVED_FREE].numFrames = amountOfRxFrames;
rxFramePool[R3_RXH_FRAMEPOOLTYPE_RECEIVED_IN_DECRYPTION].head = NULL;
rxFramePool[R3_RXH_FRAMEPOOLTYPE_RECEIVED_IN_DECRYPTION].tail = NULL;
rxFramePool[R3_RXH_FRAMEPOOLTYPE_RECEIVED_IN_DECRYPTION].numFrames = 0;
}
void r3_rxh_addFrameToPool(r3_rxh_framePoolType_e poolType, r3_rx_frame_t *frame)
r3_u32 int_mask;
DISABLE_ALL(int_mask);
if(rxFramePool[poolType].tail == NULL)
{
rxFramePool[poolType].head = frame;
}
else
{
rxFramePool[poolType].tail->next = frame;
frame->prev = rxFramePool[poolType].tail;
}
rxFramePool[poolType].tail = frame;
rxFramePool[poolType].tail->next = NULL;
rxFramePool[poolType].numFrames++;
}
int r3_rxh_moveFrame(r3_rxh_framePoolType_e poolFrom, r3_rxh_framePoolType_e poolTo)
{
r3_rx_frame_t *frame = rxFramePool[poolFrom].tail;
rxFramePool[poolFrom].tail = rxFramePool[poolFrom].tail->prev;
rxFramePool[poolFrom].tail->next = NULL;
// now adding to poolTo (copied from r3_rxh_addFrameToPool)
if (rxFramePool[poolType].tail == NULL)
{
rxFramePool[poolType].head = frame;
}
else
{
rxFramePool[poolType].tail->next = frame;
frame->prev = rxFramePool[poolType].tail;
}
rxFramePool[poolType].tail = frame;
rxFramePool[poolType].tail->next = NULL;
rxFramePool[poolType].numFrames++;
}