/*#*
*#* $Log$
+ *#* Revision 1.6 2004/10/03 20:43:22 bernie
+ *#* Import changes from sc/firmware.
+ *#*
*#* Revision 1.5 2004/08/25 14:12:08 rasky
*#* Aggiornato il comment block dei log RCS
*#*
*#*
*#* Revision 1.2 2004/05/23 18:21:53 bernie
*#* Trim CVS logs and cleanup header info.
- *#*
*#*/
#include "ser.h"
#include "ser_p.h"
-#include <drv/kdebug.h>
#include <drv/irq.h>
+#include <debug.h>
#include <hw.h>
-#include <DSP56F807.H>
+#include <DSP56F807.h>
// GPIO E is shared with SPI (in DSP56807). Pins 0&1 are TXD0 and RXD0. To use
// the serial, we need to disable the GPIO functions on them.
/*#*
*#* $Log$
+ *#* Revision 1.16 2004/10/03 20:39:28 bernie
+ *#* Import changes from sc/firmware.
+ *#*
*#* Revision 1.15 2004/09/20 03:29:39 bernie
*#* C++ fixes.
*#*
struct Process MainProcess;
-#if CONFIG_KERN_MONITOR
-List MonitorProcs;
-
-static void monitor_init(void)
-{
- INITLIST(&MonitorProcs);
-}
-
-static void monitor_add(Process* proc, const char* name, cpustack_t* stack_base, size_t stack_size)
-{
- proc->monitor.name = name;
- proc->monitor.stack_base = stack_base;
- proc->monitor.stack_size = stack_size;
-
- ADDTAIL(&MonitorProcs, &proc->monitor.link);
-}
-
-static void monitor_remove(Process* proc)
-{
- REMOVE(&proc->monitor.link);
-}
-
-#define MONITOR_NODE_TO_PROCESS(node) \
- (struct Process*)((char*)(node) - offsetof(struct Process, monitor.link))
-
-size_t monitor_check_stack(cpustack_t* stack_base, size_t stack_size)
-{
- cpustack_t* beg;
- cpustack_t* cur;
- cpustack_t* end;
- size_t sp_free;
-
- beg = stack_base;
- end = stack_base + stack_size / sizeof(cpustack_t) - 1;
-
- if (CPU_STACK_GROWS_UPWARD)
- {
- cur = beg;
- beg = end;
- end = cur;
- }
-
- cur = beg;
- while (cur != end)
- {
- if (*cur != CONFIG_KERN_STACKFILLCODE)
- break;
-
- if (CPU_STACK_GROWS_UPWARD)
- cur--;
- else
- cur++;
- }
-
- sp_free = ABS(cur - beg) * sizeof(cpustack_t);
- return sp_free;
-}
-
-#if CONFIG_KERN_MONITOR
-
-void monitor_debug_stacks(void)
-{
- struct Process* p;
- int i;
-
- if (ISLISTEMPTY(&MonitorProcs))
- {
- kputs("No stacks registered in the monitor\n");
- return;
- }
-
- kprintf("%-24s %-6s%-8s%-8s%-8s\n", "Process name", "TCB", "SPbase", "SPsize", "SPfree");
- for (i=0;i<56;i++)
- kputchar('-');
- kputchar('\n');
-
- for (p = MONITOR_NODE_TO_PROCESS(MonitorProcs.head);
- p->monitor.link.succ;
- p = MONITOR_NODE_TO_PROCESS(p->monitor.link.succ))
- {
- size_t free = monitor_check_stack(p->monitor.stack_base, p->monitor.stack_size);
- kprintf("%-24s %04x %04x %4x %4x\n", p->monitor.name, (uint16_t)p, (uint16_t)p->monitor.stack_base, (uint16_t)p->monitor.stack_size, (uint16_t)free);
- }
-}
-
-#endif /* CONFIG_KERN_MONITOR */
-
-#endif
-
-
static void proc_init_struct(Process* proc)
{
/* Avoid warning for unused argument */
#if 0 /* Simple testcase for the scheduler */
+#include <drv/timer.h>
+
/*!
* Proc scheduling test subthread 1
*/
/*#*
*#* $Log$
+ *#* Revision 1.8 2004/10/03 20:39:28 bernie
+ *#* Import changes from sc/firmware.
+ *#*
*#* Revision 1.7 2004/08/25 14:12:09 rasky
*#* Aggiornato il comment block dei log RCS
*#*
/*! Schedule to another process *without* adding the current to the ready list */
void proc_schedule(void);
+#if CONFIG_KERN_MONITOR
+ /*! Initialize the monitor */
+ void monitor_init(void);
+
+ /*! Register a process into the monitor */
+ void monitor_add(Process *proc, const char *name, cpustack_t *stack, size_t stacksize);
+
+ /*! Deregister a process from the monitor */
+ void monitor_remove(Process *proc);
+#endif /* CONFIG_KERN_MONITOR */
+
#endif /* KERN_PROC_P_H */
/*!
* \file
* <!--
- * Copyright (C) 2004 Giovanni Bajo
- * Copyright (C) 2004 Develer S.r.l. (http://www.develer.com/)
+ * Copyright 2004 Develer S.r.l. (http://www.develer.com/)
+ * Copyright 2004 Giovanni Bajo
* All Rights Reserved.
* -->
*
/*#*
*#* $Log$
- *#* Revision 1.2 2004/08/25 14:12:09 rasky
- *#* Aggiornato il comment block dei log RCS
- *#*
- *#* Revision 1.1 2004/07/14 14:08:16 rasky
- *#* Implementazione di una tabella hash
- *#*
- *#* Revision 1.13 2004/07/12 16:33:36 rasky
- *#* Aggiunta nuova ASSERT2, con stringa di descrizione del problema (disabilitabile tramite una macro di configurazione)
- *#* Modificato il codice del firmware per utilizzare ASSERT2
- *#* Modificato il progetto in modo da disabilitare le stringhe di errore nel target xROM-xRAM
+ *#* Revision 1.3 2004/10/03 20:43:22 bernie
+ *#* Import changes from sc/firmware.
*#*
*#* Revision 1.12 2004/06/14 15:15:24 rasky
*#* Cambiato key_data in un union invece di castare
*#* Sistemata la documentazione, rimossa keycmp in favore della memcmp
*#*
*#*/
+
#include "hashtable.h"
-#include <drv/kdebug.h>
+#include <debug.h>
#include <compiler.h>
+
#include <string.h>
*key = ht->key_data.hook(*node, key_length);
}
+
INLINE bool node_key_match(struct HashTable* ht, HashNodePtr node, const void* key, uint8_t key_length)
{
const void* key2;
return (key_length == key2_length && memcmp(key, key2, key_length) == 0);
}
+
static uint16_t calc_hash(const void* _key, uint8_t key_length)
{
const char* key = (const char*)_key;
return hash ^ (hash >> 6) ^ (hash >> 13);
}
+
static HashNodePtr perform_lookup(struct HashTable* ht,
const void* key, uint8_t key_length)
{
// Increment while going through the hash table in case of collision.
// This implements the double-hash technique: we use the higher part
// of the hash as a step increment instead of just going to the next
- // element, to minimize the collisions.
+ // element, to minimize the collisions.
// Notice that the number must be odd to be sure that the whole table
- // is traversed. Actually MCD(table_size, step) must be 1, but
+ // is traversed. Actually MCD(table_size, step) must be 1, but
// table_size is always a power of 2, so we just ensure that step is
// never a multiple of 2.
step = (ROTATE_RIGHT_16(hash, ht->max_elts_log2) & mask) | 1;
return NULL;
}
+
void ht_init(struct HashTable* ht)
{
memset(ht->mem, 0, sizeof(ht->mem[0]) * (1 << ht->max_elts_log2));
}
+
static bool insert(struct HashTable* ht, const void* key, uint8_t key_length, const void* data)
{
HashNodePtr node;
return true;
}
+
bool ht_insert_with_key(struct HashTable* ht, const void* key, uint8_t key_length, const void* data)
{
#ifdef _DEBUG
return insert(ht, key, key_length, data);
}
+
bool ht_insert(struct HashTable* ht, const void* data)
{
const void* key;
return insert(ht, key, key_length, data);
}
+
const void* ht_find(struct HashTable* ht, const void* key, uint8_t key_length)
{
HashNodePtr node;
-
+
if (HT_HAS_INTERNAL_KEY(ht))
key_length = MIN(key_length, INTERNAL_KEY_MAX_LENGTH);
{
int k;
int klen;
-
- do
+
+ do
{
klen = (rand() % 8) + 1;
for (k=0;k<klen;k++)
for (i=0;i<NUM_ELEMENTS;i++)
{
char *found1, *found2;
-
+
found1 = (char*)ht_find_str(&test1, data[i]);
if (strcmp(found1, data[i]) != 0)
{
/*!
* \file
* <!--
- * Copyright (C) 2004 Giovanni Bajo
- * Copyright (C) 2004 Develer S.r.l. (http://www.develer.com/)
+ * Copyright 2004 Develer S.r.l. (http://www.develer.com/)
+ * Copyright 2004 Giovanni Bajo
* All Rights Reserved.
* -->
*
/*#*
*#* $Log$
- *#* Revision 1.4 2004/08/25 14:12:09 rasky
- *#* Aggiornato il comment block dei log RCS
- *#*
- *#* Revision 1.3 2004/08/14 19:37:57 rasky
- *#* Merge da SC: macros.h, pool.h, BIT_CHANGE, nome dei processi, etc.
- *#*
- *#* Revision 1.2 2004/08/04 15:52:54 rasky
- *#* Merge da SC: fixato namespace dell'include guard
- *#*
- *#* Revision 1.1 2004/07/14 14:08:16 rasky
- *#* Implementazione di una tabella hash
- *#*
- *#* Revision 1.10 2004/06/14 15:17:15 rasky
- *#* Qualche fix alla documentazione Doxygen
+ *#* Revision 1.5 2004/10/03 20:43:22 bernie
+ *#* Import changes from sc/firmware.
*#*
*#* Revision 1.9 2004/06/14 15:15:24 rasky
*#* Cambiato key_data in un union invece di castare
*#*
*#* Revision 1.4 2004/05/24 15:28:20 rasky
*#* Sistemata la documentazione, rimossa keycmp in favore della memcmp
- *#*
*#*/
-
#ifndef MWARE_HASHTABLE_H
#define MWARE_HASHTABLE_H
#include <compiler.h>
#include <macros.h>
-#include <drv/kdebug.h>
+#include <debug.h>
-/*! Enable/disable support to declare special hash tables which maintain a copy of
- * the key internally instead of relying on the hook to extract it from the data.
+/*!
+ * Enable/disable support to declare special hash tables which maintain a copy of
+ * the key internally instead of relying on the hook to extract it from the data.
*/
#define CONFIG_HT_OPTIONAL_INTERNAL_KEY 1
//! Maximum length of the internal key (use (2^n)-1 for slight speedup)
#define INTERNAL_KEY_MAX_LENGTH 15
-/*! Hook to get the key from \a data, which is an element of the hash table. The
- * key must be returned together with \a key_length (in words).
+/*!
+ * Hook to get the key from \a data, which is an element of the hash table. The
+ * key must be returned together with \a key_length (in words).
*/
typedef const void* (*hook_get_key)(const void* data, uint8_t* key_length);
-/*! Hash table description
+
+/*!
+ * Hash table description
*
* \note This structures MUST NOT be accessed directly. Its definition is
* provided in the header file only for optimization purposes (see the rationale
* in hashtable.c).
*
- * \note If new elements must be added to this list, please double check
+ * \note If new elements must be added to this list, please double check
* \c DECLARE_HASHTABLE, which requires the existing elements to be at the top.
*/
struct HashTable
} key_data;
};
+
//! Iterator to walk the hash table
typedef struct
{
const void** end;
} HashIterator;
-/*! Declare a hash table in the current scope
+
+/*!
+ * Declare a hash table in the current scope
*
* \param name Variable name
* \param size Number of elements
static struct HashTable name = { name##_nodes, UINT32_LOG2(size), { true }, name##_keys }
#endif
-/*! Initialize (and clear) a hash table in a memory buffer.
+/*!
+ * Initialize (and clear) a hash table in a memory buffer.
*
* \param ht Hash table declared with \c DECLARE_HASHTABLE
*
*/
void ht_init(struct HashTable* ht);
-/*! Insert an element into the hash table
+/*!
+ * Insert an element into the hash table
*
* \param ht Handle of the hash table
* \param data Data to be inserted into the table
*/
bool ht_insert(struct HashTable* ht, const void* data);
-/*! Insert an element into the hash table
+/*!
+ * Insert an element into the hash table
*
* \param ht Handle of the hash table
* \param key Key of the element
*/
bool ht_insert_with_key(struct HashTable* ht, const void* key, uint8_t key_length, const void* data);
-/*! Find an element in the hash table
+/*!
+ * Find an element in the hash table
*
* \param ht Handle of the hash table
* \param key Key of the element
return h;
}
-/*! Get an iterator to the (exclusive) end of the hash table \a ht
+/*!
+ * Get an iterator to the (exclusive) end of the hash table \a ht
*
- * \note Like in STL, the end iterator is not a valid iterator (you
- * cannot call \c ht_iter_get() on it), and it must be used only to
- * detect if we reached the end of the iteration (through \c ht_iter_cmp()).
+ * \note Like in STL, the end iterator is not a valid iterator (you
+ * cannot call \c ht_iter_get() on it), and it must be used only to
+ * detect if we reached the end of the iteration (through \c ht_iter_cmp()).
*/
INLINE HashIterator ht_iter_end(struct HashTable* ht)
{
/*#*
*#* $Log$
- *#* Revision 1.4 2004/08/25 14:12:09 rasky
- *#* Aggiornato il comment block dei log RCS
- *#*
- *#* Revision 1.3 2004/08/14 19:37:57 rasky
- *#* Merge da SC: macros.h, pool.h, BIT_CHANGE, nome dei processi, etc.
- *#*
- *#* Revision 1.2 2004/08/04 15:54:18 rasky
- *#* Merge da SC: prima versione veramente funzionante
+ *#* Revision 1.5 2004/10/03 20:43:22 bernie
+ *#* Import changes from sc/firmware.
*#*
*#* Revision 1.1 2004/07/31 16:33:58 rasky
*#* Spostato lo heap da kern/ a mware/
#include "heap.h"
#include <string.h> // memset()
#include <macros.h> // IS_POW2()
-#include <drv/kdebug.h> // ASSERT()
+#include <debug.h> // ASSERT()
/* NOTE: struct size must be a 2's power! */
typedef struct _MemChunk