📄 etpu_util.bak
字号:
******************************************************************************/
void fs_etpu_dma_disable(uint8_t channel)
{
eTPU->CHAN[channel].CR.B.DTRE = FALSE;
}
/******************************************************************************
FUNCTION : fs_timer_start
PURPOSE : This function start the timebases.
INPUTS NOTES : none
RETURNS NOTES: none
WARNING : This functions start the timebases of all timer modules on a device.
******************************************************************************/
void fs_timer_start(void)
{
eTPU->MCR.B.GTBE = 1; /* Global Time Base enabled - synchronous start of TCRs */
}
/******************************************************************************
FUNCTION : fs_etpu_malloc
PURPOSE : This function allocates data RAM (parameter RAM) for a channel.
INPUTS NOTES : This function has 1 parameter:
num_bytes: this is the number of bytes of data RAM that is
required by a channel. The number of bytes requested
must be a multiple of 8 bytes because the eTPU
alloactes memory in 8 byte blocks.
RETURNS NOTES: A pointer to allocated data RAM. If the requested amount of memory
is larger than the available amount of memory then 0 will be
returned.
WARNING : This function is non-reentrant and uses the fr_free_param global.
******************************************************************************/
uint32_t *fs_etpu_malloc(uint16_t num_bytes){
uint32_t *pba;
uint32_t x;
pba = fs_free_param;
fs_free_param += (((num_bytes+7)>>3)<<1);
x = (((num_bytes+7)>>3)<<1);
if (fs_free_param > (uint32_t *)fs_etpu_data_ram_end)
return(0);
else
return(pba);
}
/******************************************************************************
FUNCTION : fs_etpu_malloc2
PURPOSE : This function is similar to fs_etpu_malloc. The difference is
that this function first checks to see if the CPBA is not sero.
If it is not zero then it assumes the channel has already
been initialized and does not allocate more data RAM to the
channel.
INPUTS NOTES : This function has 2 parameters:
channel: The eTPU channel number.
num_bytes: this is the number of bytes of data RAM that is
required by a channel. The number of bytes requested
must be a multiple of 8 bytes because the eTPU
alloactes memory in 8 byte blocks.
RETURNS NOTES: A pointer to allocated data RAM. If the requested amount of memory
is larger than the available amount of memory then 0 will be
returned.
WARNING : This function is non-reentrant and uses the fr_free_param global.
******************************************************************************/
uint32_t *fs_etpu_malloc2(uint8_t channel, uint16_t num_bytes)
{
uint32_t *pba;
if (eTPU->CHAN[channel].CR.B.CPBA == 0 )
{
pba = fs_free_param;
fs_free_param += (((num_bytes+7)>>3)<<1);
if (fs_free_param > (uint32_t *)fs_etpu_data_ram_end)
return(0);
else
return(pba);
}
else
return(fs_etpu_data_ram(channel));
}
/* set local variables */
/******************************************************************************
FUNCTION : fs_etpu_set_chan_local_32
PURPOSE : This function sets a 32 bit parameter for an eTPU channel.
INPUTS NOTES : This function has 3 parameters:
channel: The eTPU channel number.
offset: The offset to the variable. This must be a 32bit
aligned value. This value is normally provided by
the eTPU compiler.
value: The value to write to the paramater.
RETURNS NOTES: none
WARNING :
******************************************************************************/
void fs_etpu_set_chan_local_32(uint8_t channel, uint32_t offset, uint32_t value)
{
*(uint32_t *)((uint32_t)fs_etpu_data_ram_start + (eTPU->CHAN[channel].CR.B.CPBA<<3) + offset) = value;
}
/******************************************************************************
FUNCTION : fs_etpu_set_chan_local_24
PURPOSE : This function sets a 24 bit parameter for an eTPU channel.
INPUTS NOTES : This function has 3 parameters:
channel: The eTPU channel number.
offset: The offset to the variable. This must be a 24bit
aligned value. This value is normally provided by
the eTPU compiler.
value: The value to write to the paramater.
RETURNS NOTES: none
WARNING : This function uses the sign extended location of the data memory
to write only 24 bits to the data memory. This 24 bit write is
an atomic operation and does not effect the upper 8 bits of the
32 bit value associated with the 24 bits.
******************************************************************************/
void fs_etpu_set_chan_local_24(uint8_t channel, uint32_t offset, uint24_t value)
{
*(uint32_t *)((uint32_t)fs_etpu_data_ram_ext + (eTPU->CHAN[channel].CR.B.CPBA<<3) + offset-1) = value;
}
/******************************************************************************
FUNCTION : fs_etpu_set_chan_local_16
PURPOSE : This function sets a 16 bit parameter for an eTPU channel.
INPUTS NOTES : This function has 3 parameters:
channel: The eTPU channel number.
offset: The offset to the variable. This must be a 16bit
aligned value. This value is normally provided by
the eTPU compiler.
value: The value to write to the paramater.
RETURNS NOTES: none
WARNING :
******************************************************************************/
void fs_etpu_set_chan_local_16(uint8_t channel, uint32_t offset, uint16_t value)
{
*(uint16_t *)((uint32_t)fs_etpu_data_ram_start + (eTPU->CHAN[channel].CR.B.CPBA<<3) + offset) = value;
}
/******************************************************************************
FUNCTION : fs_etpu_set_chan_local_8
PURPOSE : This function sets a 8 bit parameter for an eTPU channel.
INPUTS NOTES : This function has 3 parameters:
channel: The eTPU channel number.
offset: The offset to the variable. This must be a 8bit
aligned value. This value is normally provided by
the eTPU compiler.
value: The value to write to the paramater.
RETURNS NOTES: none
WARNING :
******************************************************************************/
void fs_etpu_set_chan_local_8(uint8_t channel, uint32_t offset, uint8_t value)
{
*(uint8_t *)((uint32_t)fs_etpu_data_ram_start + (eTPU->CHAN[channel].CR.B.CPBA<<3) + offset) = value;
}
/* get local variables */
/******************************************************************************
FUNCTION : fs_etpu_get_chan_local_32
PURPOSE : This function reads a 32 bit parameter for an eTPU channel.
INPUTS NOTES : This function has 2 parameters:
channel: The eTPU channel number.
offset: The offset to the variable. This must be a 32bit
aligned value. This value is normally provided by
the eTPU compiler.
RETURNS NOTES: The 32 bit value of the parameter.
WARNING :
******************************************************************************/
uint32_t fs_etpu_get_chan_local_32(uint8_t channel, uint32_t offset)
{
return(*(uint32_t *)((uint32_t)fs_etpu_data_ram_start + (eTPU->CHAN[channel].CR.B.CPBA<<3) + offset));
}
/******************************************************************************
FUNCTION : fs_etpu_get_chan_local_24s
PURPOSE : This function reads a signed 24 bit parameter for an eTPU channel.
INPUTS NOTES : This function has 2 parameters:
channel: The eTPU channel number.
offset: The offset to the variable. This must be a 24bit
aligned value. This value is normally provided by
the eTPU compiler.
RETURNS NOTES: The signed 24 bit value of the parameter.
WARNING : This function uses the signed area of the data memory.
******************************************************************************/
int24_t fs_etpu_get_chan_local_24s(uint8_t channel, uint32_t offset)
{
return(*(uint32_t *)((uint32_t)fs_etpu_data_ram_ext + (eTPU->CHAN[channel].CR.B.CPBA<<3) + offset-1));
}
/******************************************************************************
FUNCTION : fs_etpu_get_chan_local_24
PURPOSE : This function reads a unsigned 24 bit parameter for an eTPU channel.
INPUTS NOTES : This function has 2 parameters:
channel: The eTPU channel number.
offset: The offset to the variable. This must be a 24bit
aligned value. This value is normally provided by
the eTPU compiler.
RETURNS NOTES: The unsigned 24 bit value of the parameter.
WARNING :
******************************************************************************/
uint24_t fs_etpu_get_chan_local_24(uint8_t channel, uint32_t offset)
{
return( 0x00FFFFFF & (*(uint32_t *)((uint32_t)fs_etpu_data_ram_ext + (eTPU->CHAN[channel].CR.B.CPBA<<3) + offset-1)));
}
/******************************************************************************
FUNCTION : fs_etpu_get_chan_local_16
PURPOSE : This function reads a 16 bit parameter for an eTPU channel.
INPUTS NOTES : This function has 2 parameters:
channel: The eTPU channel number.
offset: The offset to the variable. This must be a 16bit
aligned value. This value is normally provided by
the eTPU compiler.
RETURNS NOTES: The 16 bit value of the parameter.
WARNING :
******************************************************************************/
uint16_t fs_etpu_get_chan_local_16(uint8_t channel, uint32_t offset)
{
return(*(uint16_t *)((uint32_t)fs_etpu_data_ram_start + (eTPU->CHAN[channel].CR.B.CPBA<<3) + offset));
}
/******************************************************************************
FUNCTION : fs_etpu_get_chan_local_8
PURPOSE : This function reads a 8 bit parameter for an eTPU channel.
INPUTS NOTES : This function has 2 parameters:
channel: The eTPU channel number.
offset: The offset to the variable. This must be a 8bit
aligned value. This value is normally provided by
the eTPU compiler.
RETURNS NOTES: The 8 bit value of the parameter.
WARNING :
******************************************************************************/
uint8_t fs_etpu_get_chan_local_8(uint8_t channel, uint32_t offset)
{
return(*(uint8_t *)((uint32_t)fs_etpu_data_ram_start + (eTPU->CHAN[channel].CR.B.CPBA<<3) + offset));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -