how to process multi-task access printf ?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

how to process multi-task access printf ?

218 Views
alice_thanks
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 Kudos
1 Reply

216 Views
alice_thanks
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 Kudos