Beispiel #1
0
int Spi_Start( int channel )
{
  int status;

  if ( channel < 0 || channel > 3 )
    return CONTROLLER_ERROR_ILLEGAL_INDEX;

  // Make sure the channel isn't already being used
  int c = 1 << channel;
  if ( c & Spi.channels )
    return CONTROLLER_ERROR_CANT_LOCK;

  // lock the correct select line 
  int io = Spi_GetChannelIo( channel );
  // Try to lock the pin
  status = Io_Start( io, true );
  if ( status != CONTROLLER_OK )
    return status;

  // Disable the PIO for the IO Line
  Io_PioDisable( io );

  // Select the correct peripheral for the IO line
  int peripheralA = Spi_GetChannelPeripheralA( channel );
  if ( peripheralA )
    Io_SetPeripheralA( io );
  else
    Io_SetPeripheralB( io );

  if ( Spi.users == 0 )
  {
    status = Spi_Init();
    if ( status != CONTROLLER_OK )
    {
      // Couldn't init for some reason, need to undo the IO lock
      Io_Stop( io );
      // now return with the reason for the failure
      return status;
    }
    Spi.users++;
  }

  // Set the channel to locked
  Spi.channels |= c;

  return CONTROLLER_OK;
}
Beispiel #2
0
//-----更新RTC时钟---------------------------------------------------------------
//功能:将年月日时分秒写入到RTC时钟,更新RTC,由于RTC芯片存放的时间信息是基于BCD
//      编码格式,所以在写入时间前,需要将时间信息转化为相应的BCD格式
//参数:DateTime,rtc_tm结构类型的变量,里面存放着需更新RTC的时间信息
//返回:无
//-----------------------------------------------------------------------------
bool_t rtc_update_time(struct rtc_tm *DateTime)
{
    //判断是否需要初始化SPI,以防module_init_rtc未被调用
    if(!rtc_spi_Config)
    {
        rtc_spi_Config = &pg_spi_Config;
        rtc_spi_Config->freq=CFG_RTC_SPI_SPEED;
        Spi_Init(CFG_RTC_SPI_BUS,rtc_spi_Config);
    }

    __rtc_write (RTC_CMD_SECONDS,     HexToBcd (DateTime->tm_sec));
    __rtc_write (RTC_CMD_MINUTES,     HexToBcd (DateTime->tm_min));
    __rtc_write (RTC_CMD_HOURS,       HexToBcd (DateTime->tm_hour));
    __rtc_write (RTC_CMD_DAY_OF_WEEK, HexToBcd (DateTime->tm_wday + 1));//星期几
    __rtc_write (RTC_CMD_DATE_OF_MONTH, HexToBcd (DateTime->tm_mday));
    __rtc_write (RTC_CMD_MONTH,       HexToBcd (DateTime->tm_mon));
    __rtc_write (RTC_CMD_YEAR,        HexToBcd (DateTime->tm_year- 2000));

    return 1;
}
Beispiel #3
0
//-----更新RTC时钟---------------------------------------------------------------
//功能:将年月日时分秒写入到RTC时钟,更新RTC,由于RTC芯片存放的时间信息是基于BCD
//      编码格式,所以在写入时间前,需要将时间信息转化为相应的BCD格式
//参数:DateTime,rtc_tm结构类型的变量,里面存放着需更新RTC的时间信息
//返回:无
//-----------------------------------------------------------------------------
uint32_t rtc_time_get(struct rtc_tm *DateTime)
{
    uint32_t sec, min, hour, mday, wday, mon, year;

    //判断是否需要初始化SPI,以防module_init_rtc未被调用
    if(!rtc_spi_Config)
    {
        rtc_spi_Config = &pg_spi_Config;
        rtc_spi_Config->freq=CFG_RTC_SPI_SPEED;
        Spi_Init(CFG_RTC_SPI_BUS,rtc_spi_Config);
    }

    //从RTC读时间
    sec  = __rtc_read (RTC_CMD_SECONDS);
    min  = __rtc_read (RTC_CMD_MINUTES);
    hour = __rtc_read (RTC_CMD_HOURS);
    mday = __rtc_read (RTC_CMD_DATE_OF_MONTH);
    wday = __rtc_read (RTC_CMD_DAY_OF_WEEK);
    mon  = __rtc_read (RTC_CMD_MONTH);
    year = __rtc_read (RTC_CMD_YEAR);

    //将BCD格式转化为正常模式
    DateTime->tm_sec    = BcdToHex(sec & 0x7F);
    DateTime->tm_min    = BcdToHex(min & 0x7F);
    DateTime->tm_hour   = BcdToHex(hour);
    DateTime->tm_mday   = BcdToHex(mday & 0x3F);
    DateTime->tm_wday   = BcdToHex(wday & 0x07) - 1;
    DateTime->tm_mon    = BcdToHex(mon & 0x1F);
    DateTime->tm_year   = BcdToHex(year) + 2000;

/*---------------------test use only----------------------*/
    printf("Get RTC year: %04d mon: %02d mday: %02d wday: %02d "
           "hr: %02d min: %02d sec: %02d\r\n",
           DateTime->tm_year, DateTime->tm_mon, DateTime->tm_mday,
           DateTime->tm_wday, DateTime->tm_hour, DateTime->tm_min,
           DateTime->tm_sec);
/*---------------------test use only----------------------*/

    return 0;
}
Beispiel #4
0
//----初始化rtc实时时钟模块------------------------------------------------------
//功能:初始化RTC模块,主要进行外部中断1的初始化
//参数:模块初始化函数没有参数
//返回:true = 成功初始化,false = 初始化失败
//-----------------------------------------------------------------------------
u32 rtc_init(void)
{
    if(!rtc_spi_Config)
    {
        rtc_spi_Config = &pg_spi_Config;
        rtc_spi_Config->freq=CFG_RTC_SPI_SPEED;
        Spi_Init(CFG_RTC_SPI_BUS,rtc_spi_Config);
    }
/*---------------------test use only----------------------*/
    struct rtc_tm time,gtime;
    time.tm_sec    = 00;
    time.tm_min    = 12;
    time.tm_hour   = 16;
    time.tm_mday   = 15;
    time.tm_wday   = 2;
    time.tm_mon    = 4;
    time.tm_year   = 2014;
    //rtc_update_time(&time);
    rtc_time_get(&gtime);
/*---------------------test use only----------------------*/
    return 1;
}
Beispiel #5
0
void EcuM_Callout_DriverInitListOne(void)
{
  Det_Init();
  Dem_PreInit();
  Mcu_Init(&McuModuleConfiguration_0);
  Mcu_AdditionalInit();
  Mcl_Init(NULL_PTR);
  Port_Init(NULL_PTR);
  Adc_Init(NULL_PTR);
  Dio_Init(NULL_PTR);
  Gpt_Init(NULL_PTR);
  Pwm_Init(NULL_PTR);
  Icu_Init(NULL_PTR);
  Spi_Init(NULL_PTR);
  SpiCtrl_Init();
  SwGpt_Init();
  pIcomInstBle = ICOM_Create();
  ICOMChannelStatus_Init(pIcomInstBle);
  ICOMChannelDiag_Init(pIcomInstBle);
  ExtFlashSpiCtrlInit(SpiConf_SpiChannel_Spi_NVM_Command,\
                      SpiConf_SpiSequence_Spi_Seq_NVM,\
                      SpiConf_SpiJob_Spi_Job_NVM);
  CC254xCDD_Init(pIcomInstBle, 
                 DioConf_DioChannel_B6_SPI_SRDY_CU_LPCPU,\
                 SpiConf_SpiChannel_Spi_TICC2540_Command_8,\
                 SpiConf_SpiSequence_Spi_Seq_Ble_Exchange);
                 
  /* *******************************************************************
   * Wdg must be the latest in the initialization sequence
   * otherwise the function call Spi_SetAsyncMode(SPI_INTERRUPT_MODE)
   * returns a negative response when initializing the CC254xCDD_Init
   *********************************************************************/
  Wdg_Init(NULL_PTR);
  WdgM_Init(NULL_PTR);
  WdgM_SetMode(1U,0U);
  
}
void EcuM_AL_DriverInitTwo(const EcuM_ConfigType* ConfigPtr)
{
	(void)ConfigPtr;

#if defined(USE_SPI)
	// Setup SPI
	Spi_Init(ConfigPtr->SpiConfig);
#endif

#if defined(USE_EEP)
	// Setup EEP
	NO_DRIVER(Eep_Init(ConfigPtr->EepConfig));
#endif

#if defined(USE_FLS)
	// Setup Flash
	NO_DRIVER(Fls_Init(ConfigPtr->FlashConfig));
#endif

#if defined(USE_FEE)
	// Setup FEE
	NO_DRIVER(Fee_Init());
#endif

#if defined(USE_EA)
	// Setup EA
	NO_DRIVER(Ea_Init());
#endif

#if defined(USE_NVM)
	// Setup NVRAM Manager and start the read all job
	NO_DRIVER(NvM_Init());
	NO_DRIVER(NvM_ReadAll());
#endif


#if defined(USE_LIN)
    // Setup Lin driver
	Lin_Init(ConfigPtr->LinConfig);
#endif

#if defined(USE_LINIF)
    // Setup LinIf
	LinIf_Init(ConfigPtr->LinIfConfig);
#endif

#if defined(USE_LINSM)
    // Setup LinSM
	LinSM_Init(ConfigPtr->LinSMConfig);
#endif

	// Setup CAN tranceiver
	// NOTE: Add when adding supoprt for CanTranceiver

#if defined(USE_CAN)
	// Setup Can driver
	Can_Init(ConfigPtr->CanConfig);
#endif

#if defined(USE_CANIF)
	// Setup CanIf
	NO_DRIVER(CanIf_Init(ConfigPtr->PostBuildConfig->CanIf_ConfigPtr));
#endif

#if defined(USE_CANTP)
	// Setup CAN TP
	NO_DRIVER(CanTp_Init(ConfigPtr->PostBuildConfig->CanTp_ConfigPtr));
#endif

#if defined(USE_CANSM)
	NO_DRIVER(CanSM_Init(ConfigPtr->CanSMConfig));
#endif

#if defined(USE_J1939TP)
	// Setup J1939Tp
	NO_DRIVER(J1939Tp_Init(ConfigPtr->J1939TpConfig));
#endif

#if defined(USE_PDUR)
	// Setup PDU Router
	NO_DRIVER(PduR_Init(ConfigPtr->PostBuildConfig->PduR_ConfigPtr));
#endif

#if defined(USE_CANNM)
    // Setup Can Network Manager
	NO_DRIVER(CanNm_Init(ConfigPtr->PostBuildConfig->CanNm_ConfigPtr));
#endif

#if defined(USE_UDPNM)
        // Setup Udp Network Manager
	NO_DRIVER(UdpNm_Init(ConfigPtr->UdpNmConfig));
#endif

#if defined(USE_NM)
        // Setup Network Management Interface
	NO_DRIVER(Nm_Init());
#endif

#if defined(USE_COM)
	// Setup COM layer
	NO_DRIVER(Com_Init(ConfigPtr->PostBuildConfig->ComConfigurationPtr));
#endif

#if defined(USE_DCM)
	// Setup DCM
	NO_DRIVER(Dcm_Init(ConfigPtr->DcmConfig));
#endif

#if defined(USE_IOHWAB)
	// Setup IO hardware abstraction layer
	IoHwAb_Init();
#endif

#if defined(USE_XCP)
	// Setup XCP
	NO_DRIVER(Xcp_Init(ConfigPtr->XcpConfig));
#endif

}
int main(void)
#endif
{   
    BYTE i, j;
    BYTE TxSynCount = 0;
    BOOL bReceivedMessage = FALSE;
    _U16  m;

    
     #define BAUDRG 77
    /*******************************************************************/
    // Initialize the system
    /*******************************************************************/

    ANCON0 = 0XFF;     /*desactiva entradas analogicas*/
    ANCON1 = 0XFF;     /*desactiva entradas analogicas*/

    PPSUnLock();
    PPSOutput(PPS_RP10, PPS_TX2CK2);    // TX2 RP17/RC6
    PPSInput(PPS_RX2DT2, PPS_RP9);     // RX2 RP18/RC7

    PPSOutput(PPS_RP23, PPS_SDO2);    // SDO2 RP23/RD6
    PPSInput(PPS_SDI2, PPS_RP24);     // SDI2 RP24/RD7
    PPSOutput(PPS_RP22, PPS_SCK2);    // SCK2 RP22/RD5

    PPSLock();

     System_PeripheralPinSelect( ExternalInterrupt3, 19);  /*external interrupt 3 B3*/

     BoardInit();
     ConsoleInit();

     Open2USART(USART_TX_INT_OFF & USART_RX_INT_OFF & USART_EIGHT_BIT & USART_ASYNCH_MODE & USART_ADDEN_OFF, BAUDRG);
     baud2USART(BAUD_IDLE_TX_PIN_STATE_HIGH & BAUD_IDLE_RX_PIN_STATE_HIGH & BAUD_AUTO_OFF & BAUD_WAKEUP_OFF & BAUD_16_BIT_RATE & USART_RX_INT_OFF);

     Gpios_PinDirection(GPIOS_PORTD, 7, GPIOS_INPUT);  /*pin C0 como salida para SDI*/
     Gpios_PinDirection(GPIOS_PORTD, 6, GPIOS_OUTPUT); /*pin C1 como salida para SDO*/
     Gpios_PinDirection(GPIOS_PORTD, 5, GPIOS_OUTPUT); /*pin C2 como salida para SCK*/

     Spi_Init(SPI_PORT1, SPI_64DIV); /*Inicializamos SPI2*/
     Spi_Init(SPI_PORT2, SPI_64DIV); /*Inicializamos SPI2*/
     //Spi_SetMode(SPI_PORT1, 1);
     //Spi_SetMode(SPI_PORT1, 1);


    LED_1 = 1;
    LED_2 = 1;

    Read_MAC_Address();

    LED_1 = 0;
    LED_2 = 0;

                    ConsolePutROMString((ROM char *)"\r\n<MAC Addr:");
                 
                    PrintChar(myLongAddress[3]);
                    PrintChar(myLongAddress[2]);
                    PrintChar(myLongAddress[1]);
                    PrintChar(myLongAddress[0]);

                    ConsolePutROMString((ROM char *)"\r>");

        
    Printf("\r\nStarting Testing Interface for MiWi(TM) PRO Stack ...");
    #if defined(MRF24J40)
    Printf("\r\n     RF Transceiver: MRF24J40");
    #elif defined(MRF49XA)
    Printf("\r\n     RF Transceiver: MRF49XA");
    #elif defined(MRF89XA)
    Printf("\r\n     RF Transceiver: MRF89XA");
    #endif
    Printf("\r\n   Demo Instruction:");
    Printf("\r\n                     Press Enter to bring up the menu.");
    Printf("\r\n                     Type in hyper terminal to choose");
    Printf("\r\n                     menu item. ");
    Printf("\r\n\r\n");
   
    /*******************************************************************/
    // Following block display demo information on LCD of Explore 16 or 
    // PIC18 Explorer demo board.
    /*******************************************************************/
    #if defined(MRF49XA)
        LCDDisplay((char *)"MiWi PRO Test Interface MRF49XA", 0, TRUE); 
    #elif defined(MRF24J40)
        LCDDisplay((char *)"MiWi PRO Test Interface MRF24J40", 0, TRUE);
    #elif defined(MRF89XA)
        LCDDisplay((char *)"MiWi PRO Test Interface MRF89XA", 0, TRUE); 
    #endif
    
    //if( (PUSH_BUTTON_1 == 0) || ( MiApp_ProtocolInit(TRUE) == FALSE ) )
    if (PUSH_BUTTON_1 == 1)
    {  

        MiApp_ProtocolInit(FALSE);


        LED_1 = 0;
        LED_2 = 0;

        #ifdef ENABLE_ACTIVE_SCAN
        
            myChannel = 0xFF;
            ConsolePutROMString((ROM char *)"\r\nStarting Active Scan...");
            
            LCDDisplay((char *)"Active Scanning", 0, FALSE);
    
            /*******************************************************************/
            // Function MiApp_SearchConnection will return the number of 
            // existing connections in all channels. It will help to decide 
            // which channel to operate on and which connection to add.
            // The return value is the number of connections. The connection 
            //     data are stored in global variable ActiveScanResults. 
            //     Maximum active scan result is defined as 
            //     ACTIVE_SCAN_RESULT_SIZE
            // The first parameter is the scan duration, which has the same 
            //     definition in Energy Scan. 10 is roughly 1 second. 9 is a 
            //     half second and 11 is 2 seconds. Maximum scan duration is 14, 
            //     or roughly 16 seconds.
            // The second parameter is the channel map. Bit 0 of the 
            //     double word parameter represents channel 0. For the 2.4GHz 
            //     frequency band, all possible channels are channel 11 to 
            //     channel 26. As the result, the bit map is 0x07FFF800. Stack 
            //     will filter out all invalid channels, so the application 
            //     only needs to pay attention to the channels that are not 
            //     preferred.
            /*******************************************************************/
            i = MiApp_SearchConnection(10, 0x02000000);
            
            if( i > 0 )
            {
                // now print out the scan result.
                Printf("\r\nActive Scan Results: \r\n");
                for(j = 0; j < i; j++)
                {
                    Printf("Channel: ");
                    PrintDec(ActiveScanResults[j].Channel );
                    Printf("   RSSI: ");
                    PrintChar(ActiveScanResults[j].RSSIValue);
                    Printf("\r\n");
                    myChannel = ActiveScanResults[j].Channel;
                    Printf("PeerInfo: ");
                    PrintChar( ActiveScanResults[j].PeerInfo[0]);
                }
            }
        #endif

    

        /*******************************************************************/
        // Function MiApp_ConnectionMode sets the connection mode for the 
        // protocol stack. Possible connection modes are:
        //  - ENABLE_ALL_CONN       accept all connection request
        //  - ENABLE_PREV_CONN      accept only known device to connect
        //  - ENABL_ACTIVE_SCAN_RSP do not accept connection request, but 
        //                          allow response to active scan
        //  - DISABLE_ALL_CONN      disable all connection request, including
        //                          active scan request
        /*******************************************************************/
        MiApp_ConnectionMode(ENABLE_ALL_CONN);
    
    
        if( i > 0 )
        {
            /*******************************************************************/
            // Function MiApp_EstablishConnection try to establish a new 
            // connection with peer device. 
            // The first parameter is the index to the active scan result, which 
            //      is acquired by discovery process (active scan). If the value
            //      of the index is 0xFF, try to establish a connection with any 
            //      peer.
            // The second parameter is the mode to establish connection, either 
            //      direct or indirect. Direct mode means connection within the 
            //      radio range; Indirect mode means connection may or may not 
            //      in the radio range. 
            /*******************************************************************/
            if( MiApp_EstablishConnection(0, CONN_MODE_DIRECT) == 0xFF )
            {
                Printf("\r\nJoin Fail");
            }
        }    
        else
        {
            /*******************************************************************/
            // Function MiApp_StartConnection tries to start a new network 
            //
            // The first parameter is the mode of start connection. There are 
            // two valid connection modes:
            //   - START_CONN_DIRECT        start the connection on current 
            //                              channel
            //   - START_CONN_ENERGY_SCN    perform an energy scan first, 
            //                              before starting the connection on 
            //                              the channel with least noise
            //   - START_CONN_CS_SCN        perform a carrier sense scan 
            //                              first, before starting the 
            //                              connection on the channel with 
            //                              least carrier sense noise. Not 
            //                              supported on currrent radios
            //
            // The second parameter is the scan duration, which has the same 
            //     definition in Energy Scan. 10 is roughly 1 second. 9 is a 
            //     half second and 11 is 2 seconds. Maximum scan duration is 
            //     14, or roughly 16 seconds.
            //
            // The third parameter is the channel map. Bit 0 of the 
            //     double word parameter represents channel 0. For the 2.4GHz 
            //     frequency band, all possible channels are channel 11 to 
            //     channel 26. As the result, the bit map is 0x07FFF800. Stack 
            //     will filter out all invalid channels, so the application 
            //     only needs to pay attention to the channels that are not 
            //     preferred.
            /*******************************************************************/
            #ifdef ENABLE_ED_SCAN
                //LCDDisplay((char *)"Active Scanning Energy Scanning", 0, FALSE);
                ConsolePutROMString((ROM char *)"\r\nActive Scanning Energy Scanning");
                MiApp_StartConnection(START_CONN_ENERGY_SCN, 10, 0x02000000);
            #endif
        }
        
        // Turn on LED 1 to indicate ready to accept new connections
        LED_1 = 1;
    }
    else
    {
        //LCDDisplay((char *)" Network Freezer    ENABLED", 0, TRUE);
        Printf("\r\nNetwork Freezer Feature is enabled. There will be no hand-shake process.\r\n");
        LED_1 = 1;
        DumpConnection(0xFF);
    }
                   
    LCDDisplay((char *)"Start Connection on Channel %d", currentChannel, TRUE);
    LCDDisplay((char *)"Testing Menu on  Hyper Terminal", 0, FALSE);

    while(1)
    {
        /*******************************************************************/
        // Function MiApp_MessageAvailable will return a boolean to indicate 
        // if a message for application layer has been received by the 
        // transceiver. If a message has been received, all information will 
        // be stored in the rxMessage, structure of RECEIVED_MESSAGE.
        /*******************************************************************/
        if( MiApp_MessageAvailable() )
        {
            /*******************************************************************/
            // If a packet has been received, following code prints out some of
            // the information available in rxFrame.
            /*******************************************************************/
            if( rxMessage.flags.bits.secEn )
            {
                ConsolePutROMString((ROM char *)"Secured ");
            }

            if( rxMessage.flags.bits.broadcast )
            {
                ConsolePutROMString((ROM char *)"Broadcast Packet with RSSI ");
            }
            else
            {
                ConsolePutROMString((ROM char *)"Unicast Packet with RSSI ");
            }
            PrintChar(rxMessage.PacketRSSI);
            if( rxMessage.flags.bits.srcPrsnt )
            {
                ConsolePutROMString((ROM char *)" from ");
                if( rxMessage.flags.bits.altSrcAddr )
                {
                    PrintChar(rxMessage.SourceAddress[1]);
                    PrintChar(rxMessage.SourceAddress[0]);
                }
                else
                {    
                    for(i = 0; i < MY_ADDRESS_LENGTH; i++)
                    {
                        PrintChar(rxMessage.SourceAddress[MY_ADDRESS_LENGTH-1-i]);
                    }
                }    
            }

            ConsolePutROMString((ROM char *)": ");
            
            
            for(i = 0; i < rxMessage.PayloadSize; i++)
            {
                ConsolePut(rxMessage.Payload[i]);
            }
            
            // Toggle LED2 to indicate receiving a packet.
            LED_2 ^= 1;
            
            /*******************************************************************/
            // Function MiApp_DiscardMessage is used to release the current 
            // received message. After calling this function, the stack can 
            // start to process the next received message.
            /*******************************************************************/          
            MiApp_DiscardMessage();
            
            bReceivedMessage = TRUE;
            
            /*******************************************************************/
            // Following block update the total received and transmitted messages
            // on the LCD of the demo board. 
            /*******************************************************************/
            LCDTRXCount(TxNum, ++RxNum);
        }
        else
        {
         ++m;

         if(m > 8000)
         {
             m=0;
             //LED_1 ^= 1;
             
                MiApp_FlushTx();
    	        MiApp_WriteData('H');
    	        MiApp_WriteData('o');
    	        MiApp_WriteData('l');
    	        MiApp_WriteData('a');
                MiApp_WriteData('a');
                MiApp_WriteData('a');
    	        MiApp_WriteData(0x0D);
    	        MiApp_WriteData(0x0A);
               MiApp_BroadcastPacket(FALSE);

         }



            if ( ConsoleIsGetReady() )
            {
                //ProcessMenu();
            } 
        }
    }
}
Beispiel #8
0
/*****************************************************************************
*  EEPROM_Init
*
*  Initializes the EEPROM peripheral
*
*****************************************************************************/
ee_err_t EEPROM_Init(void)
{
    ee_err_t retval;
    spiBusConfig_t spiConfig = {
        .bitsPerSec = 2000000,
        .master = TRUE,
        .clkActiveHigh = TRUE,
        .clkPhaseFirstEdge = TRUE,
        .MsbFirst = TRUE
    };
    
    #if gEepromWriteEnable_d
    uint32_t i;

    // Mark Flash as Unerased
    for(i = 0; i < 64; i++)
        mEepromEraseBitmap[i] = 0;
#endif

    if(Spi_Init(gEepromSpiInstance_c, &mEepromSpiState, NULL, NULL) != spiSuccess)
    {
        return ee_error;
    }
    
    if(Spi_Configure(gEepromSpiInstance_c, &spiConfig) != spiSuccess)
    {
        return ee_error;
    }
    
    GPIO_DRV_OutputPinInit(&mEepromSpiCsCfg);
    PORT_HAL_SetMuxMode(g_portBase[GPIO_EXTRACT_PORT(gEepromSpiCsPin_d)],
                        GPIO_EXTRACT_PIN(gEepromSpiCsPin_d), 
                        kPortMuxAsGpio);   
    
    gEepromDeassertCS_d();
    
    return ee_ok;
}

/*****************************************************************************
*  EEPROM_ChipErase
*
*  Erase all memory to 0xFF
*
*****************************************************************************/
ee_err_t EEPROM_ChipErase(void)
{
    // make sure the write process is ready
    while(EEPROM_GetWriteReady() != ee_ok);
    
    return EEPROM_SendCmd(EEPROM_CMD_ERASE_BULK, EEPROM_CMD_END);
}

/*****************************************************************************
*  EEPROM_EraseBlock
*
*  Erase a block of memory to 0xFF
*
*****************************************************************************/
ee_err_t EEPROM_EraseBlock(uint32_t Addr, uint32_t size)
{
    ee_err_t status = ee_ok;
    
    if(size != EEPROM_SECTOR_SIZE)
    {
        return ee_error;
    }
    
    // make sure the write process is ready
    while(EEPROM_GetWriteReady() != ee_ok);
    
    // send the command
    status |= EEPROM_SendCmd( EEPROM_CMD_ERASE_SECTOR, EEPROM_CMD_CNT );
    
    // send the address
    status |= EEPROM_SendAddress(Addr);

    if (status == ee_ok)
    {
        gEepromDeassertCS_d();
        return ee_ok;
    }
    else
    {
        return ee_error;
    }
}
Beispiel #9
0
void EcuM_AL_DriverInitOne(const EcuM_ConfigType* configPtr) {

   /* provide a proper clock */
   Mcu_Init(configPtr->bsw_driver.init_one.mcu_cfg);
   Mcu_InitClock(0);
   Mcu_DistributePllClock();

   /* -----------------------------------------------------------------------
	      Interrupt System:
	      -----------------------------------------------------------------------
	      - four arbitration cycles (max. 255 interrupt sources)
	      - two clocks per arbitration cycle */

   __mtcr(0xFE2C,  0x00000000);     /* load CPU interrupt control register */
   __isync();

   /* -----------------------------------------------------------------------
	      Peripheral Control Processor (PCP):
	      -----------------------------------------------------------------------
	      - the PCP internal clock is always running

	      - use Full Context save area (R[0] - R[7])
	      - start progam counter as left by last invocation
	      - channel watchdog is disabled
	      - maximum channel number checking is disabled */

   /* - four arbitration cycles (max. 255 PCP channels) */
   /* - two clocks per arbitration cycle */
   PCP_ICR.U        =  0x00000000;  /* load PCP interrupt control register */

   /* - the PCP warning mechanism is disabled */
   PCP_ITR.U        =  0x00000000;  /* load PCP interrupt threshold register */

   /* - type of service of PCP node 4 is CPU interrupt */
   PCP_SRC4.U       =  0x00001000;  /* load service request control register 4 */

   /* - type of service of PCP node 5 is CPU interrupt */
   PCP_SRC5.U       =  0x00001000;  /* load service request control register 5 */

   /* - type of service of PCP node 6 is CPU interrupt */
   PCP_SRC6.U       =  0x00001000;  /* load service request control register 6 */

   /* - type of service of PCP node 7 is CPU interrupt */
   PCP_SRC7.U       =  0x00001000;  /* load service request control register 7 */

   /* - type of service of PCP node 8 is CPU interrupt */
   PCP_SRC8.U       =  0x00001000;  /* load service request control register 8 */


   ts_initGPTAInt();

   Port_Init(configPtr->bsw_driver.init_one.port_cfg);

   Adc_Init(configPtr->bsw_driver.init_one.adc_cfg);
   Fls_Init(configPtr->bsw_driver.init_one.fls_cfg);
   Gpt_Init(configPtr->bsw_driver.init_one.gpt_cfg);
   Pwm_Init(configPtr->bsw_driver.init_one.pwm_cfg);
   Spi_Init(configPtr->bsw_driver.init_one.spi_cfg);
   Wdg_Init(configPtr->bsw_driver.init_one.wdg_cfg);
#ifdef ECUM_WDGM_INCLUDED
   WdgM_Init(configPtr->bsw_driver.init_one.wdgm_cfg);
#endif

   /* setup end of init protected registers for OS */
   ts_endinit_clear();
   osInitProtected();
   ts_endinit_set();

   /* Overlay Ram:
    * Init registers and mem areas for switching from
    * working page (overlay ram) <-> reference page (flash)
    */
   RAM_OverlayRamReset();

   /* - the CPU interrupt system is globally disabled */
   __enable();


   Spi_SetAsyncMode(SPI_INTERRUPT_MODE);
   Adc_StartGroupConversion(0);
   Adc_StartGroupConversion(1);
   EcuM_SelectApplicationMode(OSDEFAULTAPPMODE);

}
Beispiel #10
0
void EcuM_AL_DriverInitTwo(const EcuM_ConfigType* ConfigPtr)
{
	(void)ConfigPtr;
  //lint --e{715}       PC-Lint (715) - ConfigPtr usage depends on configuration of modules
//	VALIDATE_STATE(ECUM_STATE_STARTUP_TWO);
#if defined(USE_ETH)
	buffer_init();
	Eth_Init();
#endif
//#undef USE_USB
#if defined(USE_USB)
//    usb_heap_init();
//    mailboxInit();
//    usb_sem_init();
    usbinit();
#endif
#if defined(USE_SPI)
	// Setup SPI
	Spi_Init(ConfigPtr->SpiConfig);
#endif

#if defined(USE_EEP)
	// Setup EEP
	NO_DRIVER(Eep_Init(ConfigPtr->EepConfig));
#endif

#if defined(USE_FLS)
	// Setup Flash
	NO_DRIVER(Fls_Init(ConfigPtr->FlashConfig));
#endif

#if defined(USE_FEE)
	// Setup FEE
	NO_DRIVER(Fee_Init());
#endif

#if defined(USE_EA)
	// Setup EA
	NO_DRIVER(Ea_Init());
#endif

#if defined(USE_NVM)
	// Setup NVRAM Manager and start the read all job
	NO_DRIVER(NvM_Init());
	NO_DRIVER(NvM_ReadAll());
#endif


#if defined(USE_LIN)
    // Setup Lin driver
	Lin_Init(ConfigPtr->LinConfig);
#endif

#if defined(USE_LINIF)
    // Setup LinIf
	LinIf_Init(ConfigPtr->LinIfConfig);
#endif

#if defined(USE_LINSM)
    // Setup LinSM
	LinSM_Init(ConfigPtr->LinSMConfig);
#endif

	// Setup CAN tranceiver
	// TODO

#if defined(USE_CAN)
	// Setup Can driver
	Can_Init(ConfigPtr->CanConfig);
#endif

#if defined(USE_CANIF)
	// Setup CanIf
	NO_DRIVER(CanIf_Init(ConfigPtr->PostBuildConfig->CanIf_ConfigPtr));
#endif

#if defined(USE_CANTP)
	// Setup CAN TP
	NO_DRIVER(CanTp_Init(ConfigPtr->PostBuildConfig->CanTp_ConfigPtr));
#endif

#if defined(USE_CANSM)
	NO_DRIVER(CanSM_Init(ConfigPtr->CanSMConfig));
#endif

#if defined(USE_J1939TP)
	// Setup J1939Tp
	NO_DRIVER(J1939Tp_Init(ConfigPtr->J1939TpConfig));
#endif

	// Setup LIN
	// TODO

#if defined(USE_PDUR)
	// Setup PDU Router
	NO_DRIVER(PduR_Init(ConfigPtr->PostBuildConfig->PduR_ConfigPtr));
#endif

#if defined(USE_CANNM)
    // Setup Can Network Manager
	NO_DRIVER(CanNm_Init(ConfigPtr->PostBuildConfig->CanNm_ConfigPtr));
#endif

#if defined(USE_UDPNM)
        // Setup Udp Network Manager
	NO_DRIVER(UdpNm_Init(ConfigPtr->UdpNmConfig));
#endif

#if defined(USE_NM)
        // Setup Network Management Interface
	NO_DRIVER(Nm_Init());
#endif

#if defined(USE_COM)
	// Setup COM layer
	NO_DRIVER(Com_Init(ConfigPtr->PostBuildConfig->ComConfigurationPtr));
#endif

#if defined(USE_DCM)
	// Setup DCM
	NO_DRIVER(Dcm_Init(ConfigPtr->DcmConfig));
#endif

#if defined(USE_IOHWAB)
	// Setup IO hardware abstraction layer
	IoHwAb_Init();
#endif

}
void WDRV_SPI_Init(void)
{     
    CS_Init();     
    CS_Deassert();
    Spi_Init(); 
}
Beispiel #12
0
void main(void)
{
     #define BAUDRG 77

    BYTE SecNum = 0;

   BOOL Tx_Success = FALSE;
   BYTE Tx_Trials = 0, scanresult = 0;
    /*******************************************************************/
    // Initialize the system
    /*******************************************************************/

    ANCON0 = 0XFF;     /*desactiva entradas analogicas*/
    ANCON1 = 0XFF;     /*desactiva entradas analogicas*/



    PPSUnLock();

    PPSOutput(PPS_RP10, PPS_TX2CK2);    // TX2 RP17/RC6     icsp
    PPSInput(PPS_RX2DT2, PPS_RP9);     // RX2 RP18/RC7

    PPSOutput(PPS_RP23, PPS_SDO2);    // SDO2 RP23/RD6
    PPSInput(PPS_SDI2, PPS_RP24);     // SDI2 RP24/RD7
    PPSOutput(PPS_RP22, PPS_SCK2);    // SCK2 RP22/RD5

    PPSLock();

     System_PeripheralPinSelect( ExternalInterrupt3, 19);  /*external interrupt 3 B3*/

     BoardInit();
     ConsoleInit();

     Gpios_PinDirection(GPIOS_PORTC, 7, GPIOS_INPUT);  /*pin C0 como salida para SDI*/
     Gpios_PinDirection(GPIOS_PORTC, 6, GPIOS_OUTPUT); /*pin C1 como salida para SDO*/
     
     //Gpios_PinDirection(GPIOS_PORTD, 4, GPIOS_OUTPUT);  /*pin D4 como salida */

     Open1USART(USART_TX_INT_OFF & USART_RX_INT_OFF & USART_EIGHT_BIT & USART_ASYNCH_MODE & USART_ADDEN_OFF, BAUDRG);
     baud1USART(BAUD_IDLE_TX_PIN_STATE_HIGH & BAUD_IDLE_RX_PIN_STATE_HIGH & BAUD_AUTO_OFF & BAUD_WAKEUP_OFF & BAUD_16_BIT_RATE & USART_RX_INT_OFF);


     Open2USART(USART_TX_INT_OFF & USART_RX_INT_OFF & USART_EIGHT_BIT & USART_ASYNCH_MODE & USART_ADDEN_OFF, BAUDRG);
     baud2USART(BAUD_IDLE_TX_PIN_STATE_HIGH & BAUD_IDLE_RX_PIN_STATE_HIGH & BAUD_AUTO_OFF & BAUD_WAKEUP_OFF & BAUD_16_BIT_RATE & USART_RX_INT_OFF);


     OpenTimer1( TIMER_INT_OFF &T1_16BIT_RW &T1_SOURCE_FOSC_4 & T1_PS_1_8 &T1_OSC1EN_OFF &T1_SYNC_EXT_OFF, TIMER_GATE_OFF  & TIMER_GATE_INT_OFF);



     Gpios_PinDirection(GPIOS_PORTD, 7, GPIOS_INPUT);  /*pin C0 como salida para SDI*/
     Gpios_PinDirection(GPIOS_PORTD, 6, GPIOS_OUTPUT); /*pin C1 como salida para SDO*/
     Gpios_PinDirection(GPIOS_PORTD, 5, GPIOS_OUTPUT); /*pin C2 como salida para SCK*/

     Spi_Init(SPI_PORT1, SPI_64DIV); /*Inicializamos SPI2*/
     Spi_Init(SPI_PORT2, SPI_64DIV); /*Inicializamos SPI2*/

     //Adc_Init(ADC_10BITS);

     LED_1 = 1;
     LED_2 = 0;
     //RLY_1 = 0;
     RLY_2 = 0;

     ON_RADIO = 1;
     ON_MAC = 1;
     ON_TEMP = 1;
     
     StartWirelessConnection();
     
     
     
     //myDevicesRequiredStatus[0] = 0x55;
     
     
     EEPROMRead(&myDevicesRequiredStatus, 0, 1);
     
     if(myDevicesRequiredStatus[0] == 0x55)
     {
         RLY_1 = 1;
         EEPROMCHG = 1;
         ConsolePutROMString((ROM char *)"RELAY ON ");
     }
     
     if(myDevicesRequiredStatus[0] == 0xAA)
     {
         RLY_1 = 0;
         EEPROMCHG = 0;
         ConsolePutROMString((ROM char *)"RELAY OFF ");
     }
     
     
     
     
     

     for(j=0;j<10;j++)
     {
         DelayMs(50);

         LED_1 ^= 1;
         LED_2 ^= 1;
     }
     
     

     LED_1 = 0;
     LED_2 = 0;
     //RLY_1 = 0;
     RLY_2 = 0;
     
    
     
     TickScaler = 4;
     EndDevStateMachine =0;



/*
                                

                                while(!Tx_Success)
                                {
                                    if(myChannel < 8)
                                        scanresult = MiApp_SearchConnection(10, (0x00000001 << myChannel));
                                    else if(myChannel < 16)
                    				    scanresult = MiApp_SearchConnection(10, (0x00000100 << (myChannel-8)));
                                    else if(myChannel < 24)
                    				    scanresult = MiApp_SearchConnection(10, (0x00010000 << (myChannel-16)));
                                    else
                    				    scanresult = MiApp_SearchConnection(10, (0x01000000 << (myChannel-24)));
                                    if(scanresult == 0)
                                    {
                                        Tx_Trials++;
                                        if(Tx_Trials > 2) break;

                                    }
                                    else Tx_Success = TRUE;

                                }
                                if(Tx_Success)
                                {
                                    ConsolePutROMString((ROM char *)"RADIO OK ");
                                }
                                else
                                {
                                    ConsolePutROMString((ROM char *)"RADIO FAIL ");
                                }

*/


     //.VBGOE = 0;
     //ANCON1bits.VBGEN = 1;		// Enable Band gap reference voltage
     //DelayMs(10);
     //VBGResult = Adc_u16Read(15);
     //ANCON1bits.VBGEN = 0;	    // Disable Bandgap

      //Adc_Init(ADC_10BITS);
     
     
     ANCON0 = 0xFF;
     ANCON1 = 0x9F;
     ANCON1bits.VBGEN = 1;		// Enable Band gap reference voltage
     
     
     ADCON0bits.VCFG = 0;    // vreff VDD-VSS
     ADCON0bits.CHS = 0x0F;  // VBG channel select
     
     ADCON1 = 0xBE;
     ADCON0bits.ADON = 1;
     
     //for(j=0;j<16;j++)
     //{
        //myDevicesOutputStatus[j] = j;
     //}
    
     
     //EEPROMWRITE(myDevicesOutputStatus,0,16);
     
     
     //for(j=0;j<16;j++)
     //{
        //myDevicesOutputStatus[j] = 0;
     //}
     
     //DelayMs(500);
     
     EEPROMRead(&myDevicesOutputStatus, 0, 16);
     ConsolePutROMString((ROM char *)"EEPROM READ: ");
     //PrintChar(TemperatureCalibrationValue);
     
     
     for(j=0;j<1;j++)
     {
         PrintChar(myDevicesOutputStatus[j]);
     }
	

     SwTimer3 = 0;
     SwTimer4 = 0;
     
     TRISB&=0xEF;   //JL: Configuro el pin B4 como salida si modificar el estado de los demas pines
     
     while(1)
     {
     /*
         WirelessTxRx();
         WirelesStatus();
         Bypass();
         */
         
         
         //No se utilizaron
         //Menu();
         //Timer1Tick();
         //WirelessTxRxPANCOORD();
         //TaskScheduler();
         
         //JLEstas funciones deben habilitarse para trabajar como repetidora
         
         Timer1Tick();
         Repeater();
        
     }

}