📄 hostif_low.c
字号:
/************************************************** * * hostif_low.c * * CVS ID: $Id: hostif_low.c,v 1.56 2007/11/15 13:21:29 belardi Exp $ * Author: Raffaele Belardi [RB] - STM * Date: $Date: 2007/11/15 13:21:29 $ * Revision: $Revision: 1.56 $ * * Description: * * Implement the Link Layer and Transport Layer of the * Communication protocol * project, which runs on the Accordo+. * Does not include the lower level I2C driver. * *************************************************** * * COPYRIGHT (C) ST Microelectronics 2005 * All Rights Reserved * *************************************************** * * STM CVS Log: * * $Log: hostif_low.c,v $ * Revision 1.56 2007/11/15 13:21:29 belardi * New request/message ReqCurrentPlaylistAbsContent * * Revision 1.55 2007/11/08 17:38:43 sedmik * based on setting IPOD_PASSTHROUGH and IPOD_AP different cmd channel is used * * Revision 1.54 2007/10/12 16:26:30 belardi * Changed absolute values to already existing #defines * * Revision 1.53 2007/10/12 13:15:35 marcucci * Add protection against interrupt modification of hostif_inevent variable. * This variable should be always modified in a Task by means of the set_hostif_inevent() * and the reset_hostif_inevent() procedures * * Revision 1.52 2007/10/02 09:02:28 belardi * Commented out unused function * * Revision 1.51 2007/08/02 13:36:25 sedmik * scheduling dir content multipacket message * * Revision 1.50 2007/06/28 20:53:52 longauer * 1.Usb restructuralization in order to supports more LUNs and interface preparation * for iAP; 2.PHY emulation moved; 3.compilation works with IPOD_PASSTHROUGH==0; 4. * usb patching init moved from main.c * * Revision 1.49 2007/06/04 16:58:45 longauer * USBtask rearrangement in order to support more logical units; new file usb_pri.h added with USBtask private declarations; USB compilation switches added; constants renaming; * * Revision 1.48 2007/05/02 12:42:50 belardi * Fix for race condition between hostif and i2c driver that cause loss of host command reception in presence of frequent CRQ timeout * * Revision 1.47 2007/04/18 10:27:51 belardi * Fix by JS and RB in scheduled_tx to solve overwrite of MsgTextInfo and ROMMediaContent messages. * * Revision 1.46 2007/03/08 08:51:58 belardi * Changed back set_hostif_inevent calls to send_hostif_inevent. They where changed by mistake and produced irregular time msg during search mode. * * Revision 1.45 2007/03/05 15:11:51 belardi * Addition to CIS: * - new parameter in MsgPlayerMode indicating current source * - new values for PAR11 of MsgTimeInfo to indicate the type of file (CDDA, MP3, WMA, AAC) * - new command/message ReqLongEntryName to transmit the filename in multi-packet format * * Revision 1.44 2007/02/15 16:08:39 sedmik * BinaryTransfer improved - added functionality for resume info processing * * Revision 1.43 2007/02/15 13:11:47 marcucci * Bootloader Optimization * * Revision 1.42 2007/02/13 11:03:54 sedmik * in hostif_process_scheduled_tx changed host update transmission * * Revision 1.41 2007/02/09 12:06:22 belardi * First integration of iPod pass-through: * - downstream passthrough ok, upstream not optimizing use of the hostif buffer * - broken host update protocol * * Revision 1.40 2006/12/18 13:16:04 belardi * Bug fix in hostif_calculate_checksum() (HAVE_UPDATE code) by Optomech * * Revision 1.39 2006/12/14 17:29:38 belardi * Changes in HAVE_HOST_UPDATE_NEW * * Revision 1.38 2006/12/14 13:41:48 marcucci * HAVE_POSITION: First execute SelectSDRAM(SELECT_BSPI) * and then bspi_init() * * Revision 1.37 2006/12/12 10:55:09 sedmik * changes in file update functionality ( internal command between hostif - player) * alignment related to power off (resume to NVRAM) * * Revision 1.36 2006/11/30 17:27:39 belardi * Added control on message length in the fifo_put_msg to avoid overflow * * Revision 1.35 2006/11/30 11:05:14 belardi * - fixed problem of app message overwritten by msgcmdeval. Now msgcmdeval is dealyed until the end of the current app transmission, if one is in progress * - moved HAVE_UPDATE code from transition_handler to its own function * - Removed unused CIS_0_05 definitions * * Revision 1.34 2006/11/28 09:04:18 belardi * Removed debug code that got in by error * * Revision 1.33 2006/11/27 19:50:29 belardi * Host Update protocol addition * - new functions * * Revision 1.32 2006/11/25 08:55:34 belardi * Coditional compilatio for HAVE_TEMP_SENSOR * * Revision 1.31 2006/11/24 11:37:20 zhong * Karbin for Temperature sensor detect * * Revision 1.30 2006/11/23 09:44:30 sedmik * added message MsgCommandEval(OK) * * Revision 1.29 2006/11/09 19:11:52 belardi * Removed unused code and variables, leftover of TransportLayer implementation, no more needed since long time * * Revision 1.28 2006/11/09 16:23:00 belardi * Removed unused function * * Revision 1.27 2006/11/01 15:44:50 trubac * ASSERT compilation problem fixed * * Revision 1.26 2006/10/27 15:11:19 sedmik * report_msg_entry_name added param for any file/dir addressing * * Revision 1.25 2006/10/20 15:48:17 belardi * Bug fix * * Revision 1.24 2006/10/20 15:41:10 belardi * Support for long multi-packet transmission (or scheduled tx) * * Revision 1.23 2006/10/18 12:38:44 belardi * Removed USE_STM_HOSTIF * * Revision 1.22 2006/10/11 16:16:36 belardi * Removed unused code in preparation of HostIF redesign to support long messages * * Revision 1.21 2006/09/27 19:51:50 belardi * Removed (global) unused variables * * Revision 1.20 2006/09/18 09:55:22 belardi * Corrected CVS keyword usage * * Revision 1.19 2006/09/18 09:24:13 belardi * Added Log CVS keyword into file header * * ***************************************************/#include <string.h>#include "configuration.h"#include "gendef.h"#include "osal.h"#include "hwreg.h"#if (0 != HAVE_POSITION)#include "blgendef.h"#include "bspi_util.h"#endif /* HAVE_POSITION */#include "accordoptimer.h"#include "i2c.h"#include "player.h"#include "hostif_high.h"#include "hostif_low.h"#include "hwinit.h"#if (1 == IPOD_PASSTHROUGH)#include "controller.h"#include "usb.h"#endif /* IPOD_PASSTHROUGH */hostifCommProtocolParamType hostifCommProtocolParam;/* Application layer message buffer for Send function */char hostif_app_buffer[HOSTIF_MAX_BLOCK_SIZE];uint16 hostif_app_buffer_length;char hostif_msg_cmd_eval_buf[5]; // for error returns#define HOSTIF_FLAGS_MSGEVAL_CHK_ERR 0x0002#define HOSTIF_FLAGS_MSGEVAL_LEN_ERR 0x0004uint32 hostif_ll_retry_count;uint32 hostif_pending_scheduled_tx;uint32 hostif_current_scheduled_tx;t_hostif_state hostif_state;t_hostif_msg_fifo hostif_msg_fifo;t_bool hostif_have_msgcmdeval;#if (STM_HOSTIF_USE_DEBUG_AND_TRACE==1)/* temporary storage to build the debug and trace message */char hostif_debug_string_buffer[HOSTIF_MAX_DEBUG_STRING_SIZE];#endif#if (0 != HAVE_POSITION)hostifStoredDataType hostifStoredData;uint32 hostifLoadData;uint32 hostif_store_address;extern volatile uint32 sf_type;#endif /* HAVE_POSITION *//******************************************************************************** Internal function prototypes*******************************************************************************/void hostif_update_transition_handler(void);/* Transport Layer functionalities */void hostifRecvBlock(char *, uint16 *);TLStatusType hostifSendBlock(hostif_block_tx_mode);/* Link Layer functionalities */LLStatusType hostifRecvPacket(char *, uint16 *);void hostifSendPacket(char *, uint16);/* message FIFO access */void fifo_reset(t_hostif_msg_fifo *);t_bool fifo_push_msg(t_hostif_msg_fifo *, char *, uint16);t_bool fifo_pop_msg(t_hostif_msg_fifo *, char *, uint16 *);t_bool fifo_has_msg(t_hostif_msg_fifo *);/******************************************************************************//* Function: send_hostif_inevent *//* *//*! \brief Insert the event into the HostIF task inevent and wake up the HostIF * \param msg event * \return void * \remark hostif_inevent is modified by the HostIF, timer IRQ, I2C irq * plus any task that needs to send to the I2C, potentially all at the same time * To avoid race conditions, it needs to be protected with interrupt locked out * (which also prevents rescheduling) *//******************************************************************************/void send_hostif_inevent(uint32 evt){ DISABLE_INTERRUPTS(); hostif_inevent |= evt; ENABLE_INTERRUPTS(); _event_OSAL_wake_thread(OSAL_THREAD_HostIfTask);}void reset_hostif_inevent(uint32 evt){ DISABLE_INTERRUPTS(); hostif_inevent &= ~evt; ENABLE_INTERRUPTS();}//#if (1 == HAVE_HOST_UPDATE)void set_hostif_inevent(uint32 evt){ DISABLE_INTERRUPTS(); hostif_inevent |= evt; ENABLE_INTERRUPTS();}//#endif/******************************************************************************//* Function: hostifAppSendMsg *//* *//*! \brief Transfer message buffer to the HostIF private buffer * \param msg Message to be sent * \param len Length of the message * \return void * \remark Does not actually send the message over the host interface, * only signals to the HostIF task that there is a new message * ready to be sent and copies it to the local buffer * The message is a CIS Application Layer message (i.e. * it contains the GR,Id bytes). *//******************************************************************************/void hostifAppSendMsg(char *msg, uint16 len){ ASSERT((len <= HOSTIF_MAX_BLOCK_SIZE), "Application layer message too big for HostIF"); if (len > HOSTIF_MAX_BLOCK_SIZE) { len = HOSTIF_MAX_BLOCK_SIZE; } if (fifo_push_msg(&hostif_msg_fifo, msg, len) == TRUE) { send_hostif_inevent(HOSTIF_CMD_SEND_HOST_MSG); } else { ASSERT(FALSE, "Too many messages for HostIF msg FIFO"); }}/******************************************************************************//* Function: debugSendPrintableString *//* *//*! \brief Formats and sends a debugging Application Layer msg * \param msg Message to be sent * \param len Length of the message * \return void * \remark Uses the (GR, ID) reserved for the debug messages *//******************************************************************************/#if 0 // [RB] commented out to reduce ROM spacevoid debugSendPrintableString(char *msg, uint16 len){#if (STM_HOSTIF_USE_DEBUG_AND_TRACE==1) uint16 local_len; char *debug_msg; ASSERT((len < HOSTIF_MAX_DEBUG_STRING_SIZE), "Debug and trace string message too big for HostIF"); if (len > HOSTIF_MAX_DEBUG_STRING_SIZE) { len = HOSTIF_MAX_DEBUG_STRING_SIZE; } debug_msg = &(hostif_debug_string_buffer[0]); *debug_msg++ = HOSTIF_GROUP_MSG_STM_DEBUG_AND_TRACE; *debug_msg++ = 0x01; /* PrintableString message ID */ *debug_msg++ = HOSTIF_DEBUG_PROTOCOL_VERSION; local_len = len; while (local_len-- > 0) { *debug_msg++ = *msg++; } hostifAppSendMsg(&(hostif_debug_string_buffer[0]), len+3);#endif}/******************************************************************************//* Function: debugSendMemoryDump *//* *//*! \brief Formats and sends a debugging Application Layer msg * \param addr 4-byte address of the memody dump * \param msg memory dump * \param len Length of the message * \return void * \remark Uses the (GR, ID) reserved for the debug messages *//******************************************************************************/void debugSendMemoryDump(void *addr, char *msg, uint16 len){#if (STM_HOSTIF_USE_DEBUG_AND_TRACE==1) uint16 local_len; char *debug_msg; ASSERT((len < HOSTIF_MAX_DEBUG_DUMP_SIZE), "Debug and trace dump message too big for HostIF"); if (len > HOSTIF_MAX_DEBUG_DUMP_SIZE) { len = HOSTIF_MAX_DEBUG_DUMP_SIZE; } debug_msg = &(hostif_debug_string_buffer[0]); *debug_msg++ = HOSTIF_GROUP_MSG_STM_DEBUG_AND_TRACE; *debug_msg++ = 0x02; /* MemoryDump message ID */ *debug_msg++ = HOSTIF_DEBUG_PROTOCOL_VERSION; *debug_msg++ = ((uint32)addr & 0xFF); *debug_msg++ = (((uint32)addr >> 8) & 0xFF); *debug_msg++ = (((uint32)addr >> 16) & 0xFF); *debug_msg++ = (((uint32)addr >> 24) & 0xFF); local_len = len; while (local_len-- > 0) { *debug_msg++ = *msg++; } hostifAppSendMsg(&(hostif_debug_string_buffer[0]), len+7);#endif}#endif // #if 0/******************************************************************************//* Function: debugSendErrorCode *//* *//*! \brief Formats and sends a single codeword debugging Application Layer msg * \param msg Message to be sent (10 bytes long)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -