summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume2007-09-04 13:42:48 +0000
committerGuillaume2007-09-04 13:42:48 +0000
commitf9207b03c80a5bbbcc9168b6eb9cd3bbf6f570ab (patch)
tree7cd2db42f692f80e247fda4608c2708da9081df4
parent30de099ea53c986c726694d97d8e473352252e67 (diff)
module interf : work in progress
git-svn-id: svn+ssh://pessac/svn/cesar/trunk@654 017c9cb6-072f-447c-8318-d5b54f68fe89
-rw-r--r--cp/interf/Makefile2
-rw-r--r--cp/interf/inc/interf_private.h19
-rw-r--r--cp/interf/inc/interf_types.h2
-rw-r--r--cp/interf/interf.h36
-rw-r--r--cp/interf/src/interf.c121
5 files changed, 110 insertions, 70 deletions
diff --git a/cp/interf/Makefile b/cp/interf/Makefile
index f8f6e66e66..bfc6554261 100644
--- a/cp/interf/Makefile
+++ b/cp/interf/Makefile
@@ -4,6 +4,6 @@ ECOS = y
TARGET_PROGRAMS = interf
interf_SOURCES = interf.c interf_sar_layer.c
-interf_MODULES = lib mac/sar
+interf_MODULES = lib mac/sar cp/station
include $(BASE)/common/make/top.mk
diff --git a/cp/interf/inc/interf_private.h b/cp/interf/inc/interf_private.h
index 352029a506..d18bac05ac 100644
--- a/cp/interf/inc/interf_private.h
+++ b/cp/interf/inc/interf_private.h
@@ -14,16 +14,6 @@
#define INTERF_PRIVATE_H_
/**
- * \brief Receive new MME message
- * function is called in STA context
- *
- * \param
- * \return
- */
-void
-interf_received(void);
-
-/**
* \brief Receive fragment of message
*
* \param (void *) pointer to message fragment
@@ -44,15 +34,6 @@ interf_msg_add(msg_mme_dest_t mme_dest, msg_mme_t *msg);
/**
- * \brief release buffer for any interface
- *
- * \param
- * \return
- */
-void
-interf_released_buf(void);
-
-/**
* \brief release a buffer for CCO or STA
*
* \param
diff --git a/cp/interf/inc/interf_types.h b/cp/interf/inc/interf_types.h
index 9e65200d6d..a1bf80b758 100644
--- a/cp/interf/inc/interf_types.h
+++ b/cp/interf/inc/interf_types.h
@@ -23,7 +23,7 @@
/*
* Homeplug AV constantes
*/
-#define FragMMI_ReassemblyTimeOut_sec 1
+#define FragMMI_ReassemblyTimeOut_sec 2
/*
* INTERF constantes
diff --git a/cp/interf/interf.h b/cp/interf/interf.h
index 801471f4ff..1d9ed7d77c 100644
--- a/cp/interf/interf.h
+++ b/cp/interf/interf.h
@@ -21,7 +21,8 @@
#include <cyg/kernel/kapi.h>
#include "lib/types.h"
-#include "mac/sar/inc/sar_mf.h"
+//#include "cp/station/inc/station_types.h"
+#include "cp/station/station.h"
#include "cp/interf/inc/interf_sar_layer.h"
#include "cp/interf/inc/interf_types.h"
#include "cp/msg/msg.h"
@@ -47,6 +48,17 @@ void
interf_receive(msg_mme_t *msg);
/**
+ * \brief Receive new MME message
+ * function is called in STA context
+ *
+ * \param
+ * \return
+ */
+void
+interf_received(void);
+
+
+/**
* \brief Send new MME message
* can be called from any context
* \param Msg : the message to send
@@ -126,6 +138,17 @@ void
interf_release_buf(msg_mme_t *msg);
/**
+ * \brief release buffer for any interface
+ *
+ * \param
+ * \return
+ */
+void
+interf_buf_to_release(void);
+
+
+
+/**
* \brief give a buffer to the STA or CCO process
* (can be called only from CCO or STA)
* \param
@@ -142,5 +165,16 @@ interf_give_buf(void);
void
interf_msg_purge(void);
+
+/**
+ * \brief convert a time in ms to a number of system tick
+ * this function can be moved in another module
+ * \param the value to convert
+ * \return the converted value
+ */
+cyg_tick_count_t
+interf_ms_to_cyg_tick(uint ms);
+
+
#endif
diff --git a/cp/interf/src/interf.c b/cp/interf/src/interf.c
index 0de212a19d..7519f0c48e 100644
--- a/cp/interf/src/interf.c
+++ b/cp/interf/src/interf.c
@@ -30,12 +30,12 @@ const interf_desc_t interf_desc[]=
{ 3, NULL, NULL, NULL, NULL} // HLE
};
// FIFOs (STA and CCO)
-interf_msg_file_t fifo[2];
+static interf_msg_file_t fifo[2];
static cyg_mutex_t cco_fifo_lock;
// local buf ressources (for STA and CCO)
-uint nb_local_buf_available;
-cyg_mutex_t local_ressource_lock;
-cyg_cond_t local_ressource_wait;
+static uint nb_local_buf_available;
+static cyg_mutex_t local_ressource_lock;
+static cyg_cond_t local_ressource_wait;
// mbox for incomming msg
static cyg_handle_t incoming_mbox_handle;
static cyg_mbox incoming_mbox;
@@ -43,7 +43,11 @@ static cyg_mbox incoming_mbox;
static cyg_handle_t buf_rel_mbox_handle;
static cyg_mbox buf_rel_mbox;
// delay in ticks for the frag MMI timeout
-cyg_tick_count_t frag_MMI_time_out_delay;
+static cyg_tick_count_t frag_MMI_time_out_delay;
+
+
+
+extern cyg_flag_t station_flag;
/***************************************************************/
@@ -63,7 +67,11 @@ interf_received_frag(msg_mme_t *msg)
dbg_assert( ! msg_check_wrong_mme_const_values(msg));
- // check if previous fragment has been reveived
+ // check if some old messages must be removed
+ // this can be done anywhere, but i think here is a good place.
+ interf_msg_purge();
+ // now, process the received fragment
+ // check if previous fragment has been received
for(i=0 ; i < INTERF_MAX_FRAG_MSG_SIM ; i++)
{
if( (frag_msg[i].fmsn == msg->fmi.fmsn) && (memcmp(frag_msg[i].osa, msg->osa, sizeof(msg->osa))==0) )
@@ -189,38 +197,6 @@ interf_msg_remove(msg_mme_dest_t dest, msg_mme_t *msg)
return return_value;
}
-void
-interf_received(void)
-{
- msg_mme_t * msg;
- bool message_complete, msg_RSP_or_CNF;
- int msg_nb;
-
- // as we have msg in the mailbox
- while( (msg = cyg_mbox_tryget(incoming_mbox_handle)) != NULL )
- {
- dbg_assert( ! msg_check_wrong_mme_const_values(msg));
- // TODO : vérifier que l'ODA est bien celle de la station
- // check if message is complete
- if(msg->fmi.nf_mi == 0) message_complete = true;
- else
- {
- msg = interf_received_frag(msg);
- if(msg != NULL) message_complete = true;
- else message_complete = false;
- }
- // if MME is not complete, then look for next message
- if( ! message_complete) continue;
- // check if it is a .CNF or .RSP type message
- msg_RSP_or_CNF = msg->mm_type & 0x1;
- // check if message is for CCO or STA and add it in corresponding fifo
- msg_nb = msg_get_number(msg);
- interf_msg_add(msg_list[msg_nb].msg_dest, msg);
- // TODO : set corresponding flags
- }
-}
-
-
void
interf_local_buf_release(msg_mme_t *msg)
@@ -238,8 +214,10 @@ interf_local_buf_release(msg_mme_t *msg)
cyg_mutex_unlock( & local_ressource_lock);
}
+//void
+//interf_released_buf(void)
void
-interf_released_buf(void)
+interf_buf_to_release(void)
{
interf_buffer_t *buf;
msg_mme_t *msg, *next_msg;
@@ -284,7 +262,7 @@ interf_released_buf(void)
E_ErrCode
interf_init(void)
{
- cyg_resolution_t resolution;
+// cyg_resolution_t resolution;
unsigned int i, j, k;
#if DEBUG
unsigned int nb_buf=0;
@@ -312,13 +290,14 @@ interf_init(void)
// calculate the frag MMI timeout delay
frag_MMI_time_out_delay = FragMMI_ReassemblyTimeOut_sec;
- // convert it from s to ns
- frag_MMI_time_out_delay *= 1000000000;
+ // convert it from s to ms
+ frag_MMI_time_out_delay *= 1000;
// and then convert it to system ticks
- resolution = cyg_clock_get_resolution(cyg_real_time_clock());
+ frag_MMI_time_out_delay = interf_ms_to_cyg_tick(frag_MMI_time_out_delay);
+/* resolution = cyg_clock_get_resolution(cyg_real_time_clock());
frag_MMI_time_out_delay *= resolution.divisor;
frag_MMI_time_out_delay /= resolution.dividend;
-
+*/
// attribute buffer to their owner and use the loop to init msg const values
bzero(pool, sizeof(pool));
for(i=0, j=0, k=0 ; i<COUNT(interf_desc) ; i++)
@@ -372,10 +351,40 @@ void interf_receive(msg_mme_t *msg)
#else
cyg_mbox_put(incoming_mbox_handle, msg);
#endif
-
- // TODO ici, générer un évenement STA_message reçu
+ // set the flag for the station
+ cyg_flag_setbits(&station_flag, STATION_FLAG_MSG_RCV);
}
+void
+interf_received(void)
+{
+ msg_mme_t * msg;
+ bool message_complete, msg_RSP_or_CNF;
+ int msg_nb;
+
+ // as we have msg in the mailbox
+ while( (msg = cyg_mbox_tryget(incoming_mbox_handle)) != NULL )
+ {
+ dbg_assert( ! msg_check_wrong_mme_const_values(msg));
+ // TODO : vérifier que l'ODA est bien celle de la station
+ // check if message is complete
+ if(msg->fmi.nf_mi == 0) message_complete = true;
+ else
+ {
+ msg = interf_received_frag(msg);
+ if(msg != NULL) message_complete = true;
+ else message_complete = false;
+ }
+ // if MME is not complete, then look for next message
+ if( ! message_complete) continue;
+ // check if it is a .CNF or .RSP type message
+ msg_RSP_or_CNF = msg->mm_type & 0x1;
+ // check if message is for CCO or STA and add it in corresponding fifo
+ msg_nb = msg_get_number(msg);
+ interf_msg_add(msg_list[msg_nb].msg_dest, msg);
+ // TODO : set corresponding flags
+ }
+}
void
interf_send(msg_mme_t *msg, uint msg_size, interf_id_t interf_id)
@@ -476,7 +485,8 @@ interf_release_buf(msg_mme_t *msg)
#else
cyg_mbox_put(buf_rel_mbox_handle, msg);
#endif
- // TODO générer un évenement FLAG_BUF_REL
+ // set the flag
+ cyg_flag_setbits(&station_flag, STATION_FLAG_BUF_REL);
}
@@ -514,7 +524,7 @@ interf_msg_purge(void)
{
int i, j;
cyg_tick_count_t time_out_date;
- dbg_assert(frag_MMI_time_out_delay > 1);
+ dbg_assert(frag_MMI_time_out_delay >= 1);
// calculate the date before which messages has expired
time_out_date = cyg_current_time();
time_out_date -= frag_MMI_time_out_delay;
@@ -536,3 +546,18 @@ interf_msg_purge(void)
}
+cyg_tick_count_t
+interf_ms_to_cyg_tick(uint ms)
+{
+ cyg_resolution_t resolution;
+ cyg_tick_count_t return_value;
+
+ return_value = ms;
+ // convert it from ms to ns
+ return_value *= 1000000;
+ // and then convert it to system ticks
+ resolution = cyg_clock_get_resolution(cyg_real_time_clock());
+ return_value *= resolution.divisor;
+ return_value /= resolution.dividend;
+ return return_value;
+}