void at25_sel( void ){ CLRBIT( DF_SEL_OUT_REG, DF_SEL ); }
void at25_unsel( void ){ SETBIT( DF_SEL_OUT_REG, DF_SEL ); }
void si4421_sel( void ){ SI4421_SEL; }
void si4421_unsel( void ){ SI4421_UNSEL; }
static PGM Tspi_dev_list spi_devs[] =
{
{ no_dev, e_pr_low, NULL, NULL, NULL },
{ at25, e_pr_low, at25_sel, at25_unsel, at25_halt },
{ si4421, e_pr_high, si4421_sel, si4421_unsel, si4421_halt }
};
spi_init( spi_devs );
...
u16 cmd_exec( u16 in_cmd )
{
while( !spi_sel( si4421 ) );
u16 retval = spi_send_u16( in_cmd );
spi_unsel( si4421 );
return retval;
}
...
////////////////////////////////////////////////////////////////////////////////
bool spi_sel( Espi_dev_list is_dev )
{
if( busy_by_dev != no_dev )
{
if( is_dev < busy_by_dev )
{ // если уровень приоритета запрашиваемого ниже чем текущего то выход
return false;
}
else
{ // если выше то..
dev_list_p[ busy_by_dev ].func_halt(); // ..сообщить что будет прерван
dev_list_p[ busy_by_dev ].func_unsel(); // ..прервать младшего
}
}
dev_list_p[ is_dev ].func_sel();
busy_by_dev = is_dev;
return true;
}