/*-----------------------------------------------------------------------------

 PRIVATE ROUTINE

  SER_Initialization

 DESCRIPTION

  This routine will initialize serial link management. Use ser_PortDescriptor
  look-up table to add or remove serial port.

 CALLED BY

  Application main

 CALLS

  [TBD]

 PARAMETER

  None

 RETURN

   E_ERR_Success      the routine executed successfully

 AUTHOR

  Bryan KW Chong


 HISTORY

    NAME            DATE                    REMARKS

   Bryan Chong    07-Sep-2009      Created initial revision

-----------------------------------------------------------------------------*/
E_ERR_T SER_Initialization()
{
  E_ERR_T rstatus = E_ERR_Success;
  UINT8 port_cnt = E_SER_COM_Port_1;

  SER_PD_T *ppd; // port descriptor array
  SER_CB_T *pcb; // port control block

  ppd = ser_PortDescriptor;
  pcb = ser_ControlBlk;

  // initialize global pointer to serial management control block
  pSER_CB = ser_ControlBlk;

  if(pHWP_CB->uctotalSerialCOMPort > E_SER_COM_EndOfList)
    return E_ERR_SER_SerialCOMPortOutOfRange;

  for(port_cnt = (UINT8)E_SER_COM_Port_1;
      port_cnt <= pHWP_CB->uctotalSerialCOMPort; port_cnt++)
  {
    ppd = &ser_PortDescriptor[port_cnt];
    pcb = &ser_ControlBlk[port_cnt];
    rstatus = ser_OpenPort(ppd->port, ppd->path_name, &pcb->fd,
                           ppd->accessmode);
    if(rstatus != E_ERR_Success)
    {
      #ifdef CFG_PRN_ERR
      printf("[SER] SER_Initialization, open port %d fail\n", port_cnt);
      #endif // CFG_PRN_ERR
    }

    rstatus = SER_SetAttribute(ppd->port, ppd->baudrate, ppd->parity,
                               ppd->databit, ppd->stopbit);
    SYS_ASSERT_RETURN(rstatus != E_ERR_Success, rstatus);


    delay(10);
    // flush input and output data
    tcflush(pcb->fd, TCIOFLUSH );

    pcb->pport_desc = ppd;

    #if ((defined CFG_DEBUG_MSG) && (defined CFG_DEBUG_SER))
    printf("[SER] SER_Initialization, port %d, port fd = %d\n",
           port_cnt, pcb->fd);
    #endif // ((defined CFG_DEBUG_MSG) && (defined CFG_DEBUG_SER))

  }

  memset(pcb->history, 0, sizeof(pcb->history));
  pcb->nextEmptyHistoryId = 0;
  #if ((defined CFG_DEBUG_MSG) && (defined CFG_DEBUG_SER_HOSTCMD))
  printf("[SER] SER_Initialization, history size %d bytes, start id %d\n",
         sizeof(pcb->history), pcb->nextEmptyHistoryId);
  #endif // ((defined CFG_DEBUG_MSG) && (defined CFG_DEBUG_SER))
  return E_ERR_Success;
} // SER_Initialization
Beispiel #2
0
/*----------------------------------------------------------------------------
  CDC Initialisation
  Initializes the data structures and serial port
  Parameters:   None 
  Return Value: None
 *---------------------------------------------------------------------------*/
void CDC_Init(void)
{

    ser_OpenPort();
    ser_InitPort(CDC_LineCoding.dwDTERate, CDC_LineCoding.bDataBits,
		 CDC_LineCoding.bParityType, CDC_LineCoding.bCharFormat);

    CDC_DepInEmpty = 1;
    CDC_SerialState = CDC_GetSerialState();

    CDC_BUF_RESET(CDC_OutBuf);
}
Beispiel #3
0
/*----------------------------------------------------------------------------
  CDC SetLineCoding Request Callback
  Called automatically on CDC SET_LINE_CODING Request
  Parameters:   none                    (global SetupPacket and EP0Buf)
  Return Value: TRUE - Success, FALSE - Error
 *---------------------------------------------------------------------------*/
uint32_t CDC_SetLineCoding(void)
{

    CDC_LineCoding.dwDTERate = (EP0Buf[0] << 0)
	| (EP0Buf[1] << 8)
	| (EP0Buf[2] << 16)
	| (EP0Buf[3] << 24);
    CDC_LineCoding.bCharFormat = EP0Buf[4];
    CDC_LineCoding.bParityType = EP0Buf[5];
    CDC_LineCoding.bDataBits = EP0Buf[6];

    ser_ClosePort();
    ser_OpenPort();
    ser_InitPort(CDC_LineCoding.dwDTERate, CDC_LineCoding.bDataBits,
		 CDC_LineCoding.bParityType, CDC_LineCoding.bCharFormat);
    return (TRUE);
}