how to process multi-task access printf ?

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

how to process multi-task access printf ?

363 次查看
alice_th
Contributor III

does this osif_IsIsrContext API is get current status in isr or task with freertos?

can i used it in printf/scanf ? static inline bool osif_IsIsrContext(void) { bool is_isr = false; uint32_t ipsr_code = (uint32_t)( (S32_SCB->ICSR & S32_SCB_ICSR_VECTACTIVE_MASK) >> S32_SCB_ICSR_VECTACTIVE_SHIFT ); if (ipsr_code != 0u) { is_isr = true; } return is_isr; } int_t __read_console(__file_handle handle, uchar_t * buffer, size_t * count) { #ifdef rtos_version if(osif_IsIsrContext() == true) taskDISABLE_INTERRUPTS(); else { taskENTER_CRITICAL(); } #endif uint32_t bytesRemain; bool MsgDone=false; uchar_t new_lin[]={"\n"}; int i=0; while (MsgDone==false) { LPUART_DRV_ReceiveData(INST_LPUART1, &buffer[i], 1); while(LPUART_DRV_GetReceiveStatus(INST_LPUART1, &bytesRemain) != STATUS_SUCCESS); LPUART_DRV_SendData(INST_LPUART1, &buffer[i], 1); while(LPUART_DRV_GetTransmitStatus(INST_LPUART1, &bytesRemain) != STATUS_SUCCESS); if(buffer[i++] == '\r') { buffer[i-1]='\n'; MsgDone = true; } } LPUART_DRV_SendData(INST_LPUART1, new_lin, 1); while(LPUART_DRV_GetTransmitStatus(INST_LPUART1, &bytesRemain) != STATUS_SUCCESS); buffer[i]=0; *count = (size_t)i; #ifdef rtos_version if(osif_IsIsrContext() == true) taskENABLE_INTERRUPTS(); else { taskEXIT_CRITICAL(); } #endif return 0; }

0 项奖励
回复
1 回复

361 次查看
alice_th
Contributor III
static inline bool osif_IsIsrContext(void)
{
    bool is_isr = false;
    uint32_t ipsr_code = (uint32_t)( (S32_SCB->ICSR & S32_SCB_ICSR_VECTACTIVE_MASK) >> S32_SCB_ICSR_VECTACTIVE_SHIFT );
    if (ipsr_code != 0u)
    {
        is_isr = true;
    }
 
    return is_isr;
}
 
 
int_t __read_console(__file_handle handle, uchar_t * buffer, size_t * count)
{
#ifdef rtos_version
    if(osif_IsIsrContext() == true)
        taskDISABLE_INTERRUPTS();
    else
    {
        taskENTER_CRITICAL();
    }
#endif
    
    uint32_t bytesRemain;
bool MsgDone=false;
uchar_t new_lin[]={"\n"};
int i=0;
while (MsgDone==false)
{
    LPUART_DRV_ReceiveData(INST_LPUART1, &buffer[i], 1);
    while(LPUART_DRV_GetReceiveStatus(INST_LPUART1, &bytesRemain) != STATUS_SUCCESS);
    LPUART_DRV_SendData(INST_LPUART1, &buffer[i], 1);
    while(LPUART_DRV_GetTransmitStatus(INST_LPUART1, &bytesRemain) != STATUS_SUCCESS);
    if(buffer[i++] == '\r')
{
   buffer[i-1]='\n';
   MsgDone = true;
}
   }
   LPUART_DRV_SendData(INST_LPUART1, new_lin, 1);
   while(LPUART_DRV_GetTransmitStatus(INST_LPUART1, &bytesRemain) != STATUS_SUCCESS);
   buffer[i]=0;
   *count = (size_t)i;
#ifdef rtos_version
   if(osif_IsIsrContext() == true)
        taskENABLE_INTERRUPTS();
    else
    {
        taskEXIT_CRITICAL();
    }
#endif
   return 0;
}
 
 
int_t __write_console(__file_handle handle, uchar_t * buffer, size_t * count)
{
#ifdef rtos_version
 
  if(osif_IsIsrContext() == true)
        taskDISABLE_INTERRUPTS();
    else
    {
        taskENTER_CRITICAL();
    }
#endif
  uint32_t bytesRemain;
  size_t bytes=*count;
  uchar_t ret_car[]={"\r"};
  LPUART_DRV_SendData(INST_LPUART1, buffer, bytes);
  while(LPUART_DRV_GetTransmitStatus(INST_LPUART1, &bytesRemain) != STATUS_SUCCESS);
  LPUART_DRV_SendData(INST_LPUART1, ret_car, 1);
  while(LPUART_DRV_GetTransmitStatus(INST_LPUART1, &bytesRemain) != STATUS_SUCCESS);
#ifdef rtos_version
  if(osif_IsIsrContext() == true)
        taskENABLE_INTERRUPTS();
    else
    {
       taskEXIT_CRITICAL();
    }
#endif  
  return 0;
}

 

0 项奖励
回复