43 #include "avrmalloc.h" 52 if (strncmp (str,
"bin", 3) == 0)
54 if (strncmp (str,
"ihex", 4) == 0)
56 if (strncmp (str,
"elf", 3) == 0)
68 extern inline uint16_t
set_bit_in_word (uint16_t src,
int bit,
int val);
81 if (gettimeofday (&tv, NULL) < 0)
82 avr_error (
"Failed to get program time.");
84 result = ((uint64_t) tv.tv_sec * 1000) + ((uint64_t) tv.tv_usec / 1000);
95 static DList *dlist_new_node (AvrClass *data);
96 static void dlist_construct_node (DList *node, AvrClass *data);
97 static void dlist_destroy_node (
void *node);
113 dlist_new_node (AvrClass *data)
118 dlist_construct_node (node, data);
125 dlist_construct_node (DList *node, AvrClass *data)
139 dlist_destroy_node (
void *node)
141 DList *_node = (DList *)node;
159 dlist_add (DList *head, AvrClass *data, DListFP_Cmp cmp)
165 return dlist_new_node (data);
171 if (cmp && ((*cmp) (node->data, data) == 0))
178 if (node->next == NULL)
181 node->next = dlist_new_node (data);
182 node->next->prev = node;
198 DList *node = dlist_new_node (data);;
220 avr_error (
"compare function not specified");
224 if ((*cmp) (node->data, data) == 0)
226 if ((node->prev == NULL) && (node->next == NULL))
231 else if (node->prev == NULL)
234 node->next->prev = NULL;
237 else if (node->next == NULL)
240 node->prev->next = NULL;
245 node->prev->next = node->next;
246 node->next->prev = node->prev;
296 avr_error (
"compare function not specified");
300 if ((*cmp) (node->data, data) == 0)
335 dlist_iterator_cmp (AvrClass *n1, AvrClass *n2)
341 return (
int)(n1 - n2);
363 avr_error (
"no iteration func supplied");
369 if ((*func) (node->data, user_data))
372 head =
dlist_delete (head, node->data, dlist_iterator_cmp);
DList * dlist_delete(DList *head, AvrClass *data, DListFP_Cmp cmp)
Conditionally delete a node from the list.
DList * dlist_iterator(DList *head, DListFP_Iter func, void *user_data)
Iterate over all elements of the list.
AvrClass * dlist_lookup(DList *head, AvrClass *data, DListFP_Cmp cmp)
Lookup an item in the list.
DList * dlist_add_head(DList *head, AvrClass *data)
Add a new node at the head of the list.
AvrClass * dlist_get_head_data(DList *head)
Extract the data from the head of the list.
uint64_t get_program_time(void)
Return the number of milliseconds of elapsed program time.
void dlist_delete_all(DList *head)
Blow away the entire list.
uint16_t set_bit_in_word(uint16_t src, int bit, int val)
Set a bit in src to 1 if val != 0, clears bit if val == 0.
DList * dlist_add(DList *head, AvrClass *data, DListFP_Cmp cmp)
Add a new node to the end of the list.
void class_destroy(void *klass)
Releases resources allocated by class's <klass>_new() function.
uint8_t set_bit_in_byte(uint8_t src, int bit, int val)
Set a bit in src to 1 if val != 0, clears bit if val == 0.
int str2ffmt(char *str)
Utility function to convert a string to a FileFormatType code.
void class_unref(AvrClass *klass)
Decrements the reference count for the klass object.
#define avr_error(fmt, args...)
Print an error message to stderr and terminate program.
#define avr_new(type, count)
Macro for allocating memory.
void class_overload_destroy(AvrClass *klass, AvrClassFP_Destroy destroy)
Overload the default destroy method.
void class_construct(AvrClass *klass)
Initializes the AvrClass data structure.