You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
3.6 KiB

#include "idibus_hw.h"
#include "config.h"
//=============================================================================
// RSLINK MCU SPECIFIC FUNCTIONS SECTION
// This example is typical Idibus_Ext with shift register
//=============================================================================
//-----------------------------------------------------------------------------
// Status LED functions
//-----------------------------------------------------------------------------
void RSLink_StatusLedInit(void) // Status led Init
{
RSLINK_LED_DDR|=1<<RSLINK_LED_BIT;
RSLINK_LED_PORT&=~(1<<RSLINK_LED_BIT);
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
void RSLink_StatusLedSetOn(void) // Status led On
{
RSLINK_LED_PORT|=1<<RSLINK_LED_BIT;
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
void RSLink_StatusLedSetOff(void) // Status led Off
{
RSLINK_LED_PORT&=~(1<<RSLINK_LED_BIT);
}
#ifdef _SLAVE_MODULE_
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// FOR 328pb
void RSLink_DipsInit(void) // Dip switch Adders, Speed, Bus Type Init
{
RSLINK_ADDR_DDR&=~(RSLINK_ADDR_MASK);
RSLINK_ADDR_PORT&=~(RSLINK_ADDR_MASK);
RSLINK_SPEED_DDR&=~(RSLINK_SPEED_MASK);
RSLINK_SPEED_PORT&=~(RSLINK_SPEED_MASK);
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
uint8_t RSLink_SpeedDecode(void)
{
return (RSLINK_SPEED_PIN)&RSLINK_SPEED_MASK;
}
uint8_t RSLink_AddrDecode(void)
{
return RSLINK_ADDR_PIN&RSLINK_ADDR_MASK;
}
#endif
#ifdef _SLAVE_EXT_
//-----------------------------------------------------------------------------
// DIP switch functions (FOR 328pb)
//-----------------------------------------------------------------------------
void RSLink_DipsInit(void) // Dip switch Adders, Speed, Bus Type Init
{
// Clock, output -> 1
RSLINK_DIPS_CP_DDR |= (1 << RSLINK_DIPS_CP_BIT);
RSLINK_DIPS_CP_PORT |= (1 << RSLINK_DIPS_CP_BIT);
// Latch, output -> 1
RSLINK_DIPS_nPL_DDR |= (1 << RSLINK_DIPS_nPL_BIT);
RSLINK_DIPS_nPL_PORT |= (1 << RSLINK_DIPS_nPL_BIT);
// Data, input
RSLINK_DIPS_Q7_DDR &= ~(1 << RSLINK_DIPS_Q7_BIT);
RSLINK_DIPS_Q7_PORT &= ~(1 << RSLINK_DIPS_Q7_BIT);
}
//-----------------------------------------------------------------------------
static uint16_t RSLink_DipsRead(void) // Dip switch Adders, Speed, Bus Type Read
{
// RESULT = [ADDR7...0][XXXX][TYPE][SS2...0]
RSLINK_DIPS_nPL_PORT &= ~(1 << RSLINK_DIPS_nPL_BIT);
uint16_t STATE = 0;
RSLINK_DIPS_nPL_PORT |= (1 << RSLINK_DIPS_nPL_BIT);
for (uint8_t I = 0; I < 16; I++)
{
STATE = STATE << 1;
RSLINK_DIPS_CP_PORT &= ~(1 << RSLINK_DIPS_CP_BIT);
if ((RSLINK_DIPS_Q7_PIN & (1 << RSLINK_DIPS_Q7_BIT)) != 0)
{
STATE |= 0x0001;
}
RSLINK_DIPS_CP_PORT |= (1 << RSLINK_DIPS_CP_BIT);
}
return STATE & 0xFF0F;
}
//-----------------------------------------------------------------------------
uint8_t RSLink_SpeedDecode()
{
return (uint8_t)(RSLink_DipsRead() & 0x07);
}
uint8_t RSLink_AddrDecode()
{
return (uint8_t)(RSLink_DipsRead() >> 8);
}
#endif
#ifdef _CUSTOM_TYPE_
//Define custom type here
#endif