Forum Discussion
Altera_Forum
Honored Contributor
15 years agoI do it like this:
# define L_CMD_BUFFER_SIZE 0x1000 // Only Hexnumbers like 0x10, 0x20 ......
# define L_MSG_QUEUE_MASK (L_CMD_BUFFER_SIZE - 1)
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
LCDMessage m_t_msg_buffer;
unsigned int m_ui_message_write_pointer;
OS_EVENT * m_message_queue;
......
void init_message_system
(
void
)
{
m_ui_message_write_pointer = 0;
if(!(m_message_queue = OSQCreate(&m_CommMsg,
L_CMD_BUFFER_SIZE)))
{
puts("OSQCreate() failed\r\n");
return;
}
}
void send_message
(
const LCDMessage * para_t_command
)
{
# if OS_CRITICAL_METHOD == 3
OS_CPU_SR cpu_sr;
# endif
OS_ENTER_CRITICAL();
memcpy(&m_t_cmd_buffer,
para_t_command,
sizeof(LCDMessage));
OS_EXIT_CRITICAL();
switch(OSQPost(m_message_queue,
(void *)&m_t_cmd_buffer))
{
case OS_NO_ERR:
{
break;
}
case OS_Q_FULL:
{
// error handling
....
break;
}
case OS_ERR_EVENT_TYPE:
{
// error handling
....
break;
}
case OS_ERR_PEVENT_NULL:
{
// error handling
....
break;
}
case OS_ERR_POST_NULL_PTR:
{
// error handling
....
break;
}
default:
{
// error handling
....
break;
}
}
OS_ENTER_CRITICAL();
m_ui_message_write_pointer = (m_ui_message_write_pointer + 1) & L_MSG_QUEUE_MASK;
OS_EXIT_CRITICAL();
}
bool get_message
(
LCDMessage * para_ptr_command_buffer,
INT16U para_ui_timeout
)
{
LCDMessage * proc_ptr_command;
INT8U proc_os_error;
# if OS_CRITICAL_METHOD == 3
OS_CPU_SR cpu_sr;
# endif
proc_ptr_command =
(t_command_typ *)OSQPend(m_message_queue,
para_ui_timeout,
&proc_os_error);
switch(proc_os_error)
{
case OS_NO_ERR:
{
OS_ENTER_CRITICAL();
memcpy(para_ptr_command_buffer,
proc_ptr_command,
sizeof(LCDMessage ));
OS_EXIT_CRITICAL();
return(true); // msg received
}
case OS_TIMEOUT:
{
return(false);
}
case OS_ERR_EVENT_TYPE:
{
// error handling
...
return(false);
}
case OS_ERR_PEVENT_NULL:
{
// error handling
...
return(false);
}
case OS_ERR_PEND_ISR:
{
// error handling
...
return(false);
}
default:
{
// error handling
...
return(false);
}
}
}
I used C++ therefore the bool type karsten