I have a task that handles several operations by the id of signal flag.
Those flags don't reset at the end of the operation ( it's running in an infinite loop and waits for the next signal).
for(;;)
{
signalWaitEvent = osSignalWait(0, osWaitForever);
if( signalWaitEvent.value.v == 0x10 )
{
// Some magic
}
else if( signalWaitEvent.value.v == 0x15 )
{
// Some magic
}
}
As I not from the STM form, the osSignalClear function wasn't implemented.
Is there any way around it?
Thanks all!
Thanks 0___________
I replaced the CMSIS function osSignalWait with FreeRTOS ulTaskNotifyTake and it's working now.
Related
my queue set seems to be ignoring the full queue.
xQueueSelectFromSet() always times out, but the queue is full and it can be read.
Here is a simplified example of my situation.
Did I misunderstood something and have false expectations, or is such behavior expected?
ISR:
if(xQueueIsQueueFullFromISR(queue)){
xQueueReceiveFromISR(queue, &dummy, &pxHigherPriorityTaskWoken);
}
xQueueSendFromISR(queue, event, &pxHigherPriorityTaskWoken);
task2:
xQueueSet = xQueueCreateSet(QUEUE_LENGTH + 1);
xQueueAddToSet(queue, xQueueSet);
xQueueAddToSet(semaphore, xQueueSet);
while(true){
xActivatedMember = xQueueSelectFromSet(xQueueSet, 100);
if(xActivatedMember == semaphore){
xSemaphoreTake(semaphore, 0);
break; // from the infinite loop
}else if(xActivatedMember == queue){
// read from queue
}else if(xActivatedMember == NULL){
// timed out but queue is full
uxQueueMessagesWaiting(queue); // returns QUEUE_LENGTH
xQueueReceive(queue, &event, 0); // reads without problem
} // xActivatedMember
} // infinite loop
I'm currently working on a project using a PIC32 and the wifi module ATWINC1500. I won't be able to give all the code but I'm on a test function that I can share.
First, here is some settings and configuration I'm using:
Processor : PIC32MZ1024EFE064
IDE : MPLAB IDE 5.45
Harmony version : 2.06
Wifi Module : ATWINC1500
Real Time OS : FreeRTOS
What I'm trying to do is to connect the Wifi module to an existing Access Point using the Infrastructure mode. I'm able to get the number of access point around me but when I try to read information from those access points, information are empty, void or incorrect.
Here is my code:
bool WIFI_Test_Infrastructure(void)
{
//Example: https://www.microchip.com/forums/m906568.aspx
//Wait for WINC1500 to be initialized
if(isWdrvExtReady() == false)
return false;
//Start a scan or wait for result
IWPRIV_PARAM_SCAN scanner;
IWPRIV_GET_PARAM param_scan = {
.scan = scanner
};
iwpriv_get(SCANSTATUS_GET, ¶m_scan);
IWPRIV_SCAN_STATUS status = param_scan.scan.scanStatus;
IWPRIV_EXECUTE_PARAM dummy_param;
//Process StateMachine while scanning
if(status == IWPRIV_SCAN_IDLE)
{
vTaskDelay(1000 / portTICK_PERIOD_MS);
//Disconnect wifi from everything
WDRV_Disconnect();
vTaskDelay(1000 / portTICK_PERIOD_MS);
while(WDRV_ConnectionState_Get() != WDRV_CONNECTION_STATE_NOT_CONNECTED)
vTaskDelay(10 / portTICK_PERIOD_MS);
vTaskDelay(1000 / portTICK_PERIOD_MS);
WDRV_EXT_CmdScanStart();
return false;
}
else if(status == IWPRIV_SCAN_IN_PROGRESS)
{
return false;
}
else if(status == IWPRIV_SCAN_NO_AP_FOUND)
{
iwpriv_execute(SCAN_START, &dummy_param);
return false;
}
else if(status == IWPRIV_SCAN_SUCCESSFUL)
{
vTaskDelay(1000 / portTICK_PERIOD_MS);
//Read liste of wifi access point
uint16_t wifi_number_AP;
wifi_number_AP = m2m_wifi_get_num_ap_found();
WDRV_SCAN_RESULT scanResult;
tstrM2mWifiscanResult result;
int i;
for(i=0; i<wifi_number_AP; i++)
{
m2m_wifi_req_scan_result(i);
vTaskDelay(1000 / portTICK_PERIOD_MS);
winc1500_scan_result_read(&result); //ISSUE HAPPENED HERE
vTaskDelay(1000 / portTICK_PERIOD_MS);
memcpy((void *)scanResult.bssid, (void *)result.au8BSSID, sizeof(scanResult.bssid));
}
//SUCCESS
return true;
}
else
{
return false;
}
}
So what happened here:
First, you need to know that this function is called by a Thread Manager, that's why it returns false or true. I'm checking the state in which the scan is.
I'm able to reach the SCAN_SUCCESSFUL part and the number of access point detected is correct.
I labeled the line where the issue is happening. When I'm reading the result information of an access point, it is quite empty. Here is what I see in Debug Session (and it is the same result for all of access points):
I have been waiting for weeks before asking this. Hope someone can help or at least give me hints on things to check.
If I missed information, do not hesitate to ask me.
Thanks in advance!
Adrien
The solution was simply a story of stack. I have two other tasks: SYS and TCP/IP. I needed to increase the size of their stack because they were managing several functions about scanning. So there was an overriding somewhere.
This is my first post here, so I'd like to say hello to everyone.
I am facing some problems with writing a TCP, I want to have a separate thread that allows user to type quit instruction to terminate process. The problem is that it doesn't seem to be running. The programme pauses on accept and I am unable to pass anything to the thread function.
The thread function:
void *loop_stop()
{
while(progr_control != 'q')
progr_control = getchar();
return NULL;
}
And the main (I ommited some code I think is not causing problems):
pthread_t thread_id;
pthread_create(&thread_id, NULL, loop_stop, NULL);
do
{
listen(sock_fd, 5);
int addr_len = sizeof(client_addr);
if( (new_sock_fd = accept(sock_fd, (struct sockaddr *) &client_addr, &addr_len)) < 0)
{
perror("Problems with incoming connection");
return -1;
}
else
//here is the ommited part-as I've said this loop stops at accept
}while(progr_control != 'q');
If anyone could please find the bug, or suggest other way of handling with the task, I'd be grateful
As Brian mentioned:
'accept' will make the thread wait for incomming connection, so no "quit check" is possible. The alternative is to use ctrl+c to quit instead.
I am trying to tackle a SIGSEGV signal error in cocos2d-iphone 1.0.1. I must note that, despite several hours trying, I couldn't actually replicate the crash. I only know that it happens because of the testers.
I've collected as much info as I could. First of all, here is the TestFlight backtrace:
Great. So let's take a look at CCScheduler's tick method. It is fairly large, so I have here only the block of code where the error occurs (at the bottom of the question you can see the full method):
for( elt->timerIndex = 0; elt->timerIndex < elt->timers->num; elt->timerIndex++) {
elt->currentTimer = elt->timers->arr[elt->timerIndex];
elt->currentTimerSalvaged = NO;
impMethod( elt->currentTimer, updateSelector, dt);
if( elt->currentTimerSalvaged ) {
[elt->currentTimer release];
}
elt->currentTimer = nil;
}
And the exact error line is
impMethod( elt->currentTimer, updateSelector, dt);
Good. So we got the culprit line.
Let's see, impMethod is of type TICK_IMP, which is defined as
typedef void (*TICK_IMP)(id, SEL, ccTime);
Hm. I don't see any problem with impMethod( elt->currentTimer, updateSelector, dt) itself.
Looking closely, my best guess is that elt->currentTimer could be problematic.
At first, I thought that maybe if elt is a NULL pointer, calling elt->currentTimer could cause a segmentation fault. However, I've recently been told that even if elt was NULL, sending a message to it wouldn't cause a SIGSEGV error.
I have confirmed this because I eventually wrapped the method with if (elt != NULL) and it still happened, so the problem must be something else.
Running out of clues, it occurred to me that this code, as it is, cannot be causing the error. It must be something obscure somewhere else in my code.
Let's see. If I perform an NSLog before the culprit line like this:
NSLog(#"[%# %#]" , [elt->target class],NSStringFromSelector(updateSelector));
I can tell what was the last scheduled object to be updated, and even get the corresponding method!
After making my testers crash again, I finally got this result:
[Game update]
Sweet. Game is the main game scene, so it seems like the problem is related to such scene.
But wait. There is no such method update for my scene. I never implemented something like that.
Then I figured that since Game is a CCScene object, maybe CCScene does have such method. But I see its implementation and it doesn't. But wait, CCScene is a subclass of CCNode! So let's take a look at CCNode.
... There are no update methods in CCNode either.
I did find something curious about CCNode:
-(void) scheduleUpdate;
Which apparently is in charge of scheduling the update method to be called once per frame - and it does. Here's a particular line of such procedure:
[target methodForSelector:updateSelector];
Where target is supposed to be Game and updateSelector is #selector(update:).
However, this doesn't make any sense: where is this update method supposed to be implemented? I do not find it anywhere in CCNode. Therefore, how could it possibly schedule such method?
Normally, I would say that this is what causes the error - that we're scheduling a method that is not implemented, thus causing a SIGSEGV error. However, this is plain weird, because if that was true, then it should be crashing all the time - but it doesn't.
And this is as far as I got trying to debug this error. What am I missing?
I know that you can't tell me where the problem is, but I believe that I got an important lead and you can shed some light on it: where is update implemented in cocos2d?
This is the full code of the tick method in CCScheduler, just in case:
-(void) tick: (ccTime) dt {
updateHashLocked = YES;
if( timeScale_ != 1.0f )
dt *= timeScale_;
// Iterate all over the Updates selectors
tListEntry *entry, *tmp;
// updates with priority < 0
DL_FOREACH_SAFE( updatesNeg, entry, tmp ) {
if( ! entry->paused && !entry->markedForDeletion )
entry->impMethod( entry->target, updateSelector, dt );
}
// updates with priority == 0
DL_FOREACH_SAFE( updates0, entry, tmp ) {
if( ! entry->paused && !entry->markedForDeletion )
{
entry->impMethod( entry->target, updateSelector, dt );
}
}
// updates with priority > 0
DL_FOREACH_SAFE( updatesPos, entry, tmp ) {
if( ! entry->paused && !entry->markedForDeletion )
entry->impMethod( entry->target, updateSelector, dt );
}
// Iterate all over the custome selectors
for(tHashSelectorEntry *elt=hashForSelectors; elt != NULL; ) {
currentTarget = elt;
currentTargetSalvaged = NO;
if( ! currentTarget->paused ) {
// The 'timers' ccArray may change while inside this loop.
for( elt->timerIndex = 0; elt->timerIndex < elt->timers->num; elt->timerIndex++) {
elt->currentTimer = elt->timers->arr[elt->timerIndex];
elt->currentTimerSalvaged = NO;
impMethod( elt->currentTimer, updateSelector, dt);
if( elt->currentTimerSalvaged ) {
// The currentTimer told the remove itself. To prevent the timer from
// accidentally deallocating itself before finishing its step, we retained
// it. Now that step is done, it's safe to release it.
[elt->currentTimer release];
}
elt->currentTimer = nil;
}
}
if (elt != NULL) {
// elt, at this moment, is still valid
// so it is safe to ask this here (issue #490)
elt = elt->hh.next;
// only delete currentTarget if no actions were scheduled during the cycle (issue #481)
if( currentTargetSalvaged && currentTarget->timers->num == 0 )
[self removeHashElement:currentTarget];
}
}
// delete all updates that are morked for deletion
// updates with priority < 0
DL_FOREACH_SAFE( updatesNeg, entry, tmp ) {
if(entry->markedForDeletion )
{
[self removeUpdateFromHash:entry];
}
}
// updates with priority == 0
DL_FOREACH_SAFE( updates0, entry, tmp ) {
if(entry->markedForDeletion )
{
[self removeUpdateFromHash:entry];
}
}
// updates with priority > 0
DL_FOREACH_SAFE( updatesPos, entry, tmp ) {
if(entry->markedForDeletion )
{
[self removeUpdateFromHash:entry];
}
}
updateHashLocked = NO;
currentTarget = nil;
}
My pthread_detach calls fail with a "Bad file descriptor" error. The calls are in the destructor for my class and look like this -
if(pthread_detach(get_sensors) != 0)
printf("\ndetach on get_sensors failed with error %m", errno);
if(pthread_detach(get_real_velocity) != 0)
printf("\ndetach on get_real_velocity failed with error %m", errno);
I have only ever dealt with this error when using sockets. What could be causing this to happen in a pthread_detach call that I should look for? Or is it likely something in the thread callback that could be causing it? Just in case, the callbacks look like this -
void* Robot::get_real_velocity_thread(void* threadid) {
Robot* r = (Robot*)threadid;
r->get_real_velocity_thread_i();
}
inline void Robot::get_real_velocity_thread_i() {
while(1) {
usleep(14500);
sensor_packet temp = get_sensor_value(REQUESTED_VELOCITY);
real_velocity = temp.values[0];
if(temp.values[1] != -1)
real_velocity += temp.values[1];
} //end while
}
/*Callback for get sensors thread*/
void* Robot::get_sensors_thread(void* threadid) {
Robot* r = (Robot*)threadid;
r->get_sensors_thread_i();
} //END GETSENSORS_THREAD
inline void Robot::get_sensors_thread_i() {
while(1) {
usleep(14500);
if(sensorsstreaming) {
unsigned char receive;
int read = 0;
read = connection.PollComport(port, &receive, sizeof(unsigned char));
if((int)receive == 19) {
read = connection.PollComport(port, &receive, sizeof(unsigned char));
unsigned char rest[54];
read = connection.PollComport(port, rest, 54);
/* ***SET SENSOR VALUES*** */
//bump + wheel drop
sensor_values[0] = (int)rest[1];
sensor_values[1] = -1;
//wall
sensor_values[2] = (int)rest[2];
sensor_values[3] = -1;
...
...
lots more setting just like the two above
} //end if header == 19
} //end if sensors streaming
} //end while
} //END GET_SENSORS_THREAD_I
Thank you for any help.
The pthread_* functions return an error code; they do not set errno. (Well, they may of course, but not in any way that is documented.)
Your code should print the value returned by pthread_detach and print that.
Single Unix Spec documents two return values for this function: ESRCH (no thread by that ID was found) and EINVAL (the thread is not joinable).
Detaching threads in the destructor of an object seems silly. Firstly, if they are going to be detached eventually, why not just create them that way?
If there is any risk that the threads can use the object that is being destroyed, they need to be stopped, not detached. I.e. you somehow indicate to the threads that they should shut down, and then wait for them to reach some safe place after which they will not touch the object any more. pthread_join is useful for this.
Also, it is a little late to be doing that from the destructor. A destructor should only be run when the thread executing it is the only thread with a reference to that object. If threads are still using the object, then you're destroying it from under them.