// Get the car acceleration and break and calculate speed // speed semaphores are used so these values are not altered // any anything process while getting the values. // repetition rate 20Hz = 0.05 seconds void carSimulation(void const *args){ while (true) { // calculate current speed from these values Speed_SEM.wait(); // both acceleration and break value range between 0 and 1 // engine state is either 0 or 1 float totalAcc = (accelerationValue - brakeValue) * 100; float time = 0.05; currentSpeed = (currentSpeed + float(totalAcc * time)) * engineState; if(currentSpeed < 0) { currentSpeed = 0; } if(currentSpeed > maxSpeed) { currentSpeed = maxSpeed; } Speed_SEM.release(); // saves the last 3 speeds speeds[counter] = currentSpeed; counter++; if(counter > 2) { counter = 0; } Thread::wait(50); } }
// Show the average speed value with a RC servo motor // average speed semaphore is used to hold this value constant // Repetition rate 1 Hz = 1 second void showAverageSpeed(){ AVR_SPEED_SEM.wait(); // scales the average speed to the max allowed speed // servo value is between 0 and 1 servo = 1.0 - (averageSpeed / maxSpeed) ; AVR_SPEED_SEM.release(); }
// Dump contents of feature (6) MAIL queue to the serial connection to the PC. // (Data will be passed through the MBED USB connection) // content is also dumped into a csv file // car mail semaphore used to protect messages // Repetition rate 0.05 Hz = 20 seconds void dumpContents(void const *args){ while(true){ CAR_MAIL_SEM.wait(); while(write > read){ osEvent evt = mail_box.get(); if (evt.status == osEventMail) { mail_t *mail = (mail_t*)evt.value.p; // values sent to csv file FILE *fp = fopen("/local/Car_Values.csv", "a"); fprintf(fp,"%f ,", mail->speedVal); fprintf(fp,"%f ,", mail->accelerometerVal); fprintf(fp,"%f ", mail->breakVal); fprintf(fp,"\r\n"); fclose(fp); // values sent to serial port serial.printf("average speed: %f ,", mail->speedVal); serial.printf("break value: %f ,", mail->breakVal); serial.printf("acceleration: %f ,", mail->accelerometerVal); serial.printf("\r\n"); mail_box.free(mail); read++; } } CAR_MAIL_SEM.release(); Thread::wait(20000); } }
virtual void handler() { core_util_critical_section_enter(); _increment_tick(); core_util_critical_section_exit(); _sem.release(); }
static void netif_status_callback(struct netif *netif) { if (netif_is_up(netif)) { strcpy(ip_addr, inet_ntoa(netif->ip_addr)); strcpy(gateway, inet_ntoa(netif->gw)); strcpy(networkmask, inet_ntoa(netif->netmask)); netif_up.release(); } }
/**************************************************************************//** * @brief Callback function from JCU async mode * @param[in] mbed_jcu_err_t err_code : JCU result * @retval None ******************************************************************************/ void JPEG_CallbackFunction(mbed_jcu_err_t err_code) { if (pJPEG_ConverterCallback != NULL) { pJPEG_ConverterCallback((JPEG_Converter::jpeg_conv_error_t)err_code); } if (err_code != MBED_JCU_E_OK) { jcu_error_flag = true; } jpeg_converter_semaphore.release(); // RELEASE } /* End of callback function method () */
// Read the two turn indicator switches. // input semaphore used to protect values // Repetition rate 0.5 Hz = 2 seconds void getIndicators(void const *args){ while(true){ INPUT_SEM.wait(); leftLightState = leftIndicatorSwitch; rightLightState = rightIndicatorSwitch; INPUT_SEM.release(); Thread::wait(2000); } }
// Read brake and accelerator values from variable resistors // input semaphore is so these values are not changed while reading them // Repetition rate 10Hz = 0.1 seconds void readBreakAndAccel(void const *args){ while (true) { INPUT_SEM.wait(); accelerationValue = acceleratorPedal.read(); brakeValue = brakePedal.read(); INPUT_SEM.release(); Thread::wait(100); } }
// Filter speed with averaging filter // The last 3 speeds are used to caculate an average // Both the speed and the average speed semaphores are used // Repetition rate 5 Hz = 0.2 seconds void getAverageSpeed(void const *args) { while (true) { int sum = 0; Speed_SEM.wait(); AVR_SPEED_SEM.wait(); // get the sum of the last 3 speeds for(int i =0; i< sampleNumber ; i++) { sum += speeds[i]; } // get the average of the last 3 speeds averageSpeed = sum/sampleNumber; AVR_SPEED_SEM.release(); Speed_SEM.release(); Thread::wait(200); } }
// Read engine on/off switch and show current state on an LED. // input semaphore is so this values is not changed while reading it // Repetition rate 2 Hz = 0.5 seconds void readEngine(void const *args){ while (true) { INPUT_SEM.wait(); engineState = engineSwitch.read(); INPUT_SEM.release(); // switch engine light on or off respectively engineLight = engineState; Thread::wait(500); } }
// If both switches are switched on then flash both indicator LEDs at a rate of 2Hz (hazard mode). // input semaphore used so value doesnt change // Repetition rate 2 Hz = 0.5 seconds void flashHazard() { INPUT_SEM.wait(); if(leftLightState && rightLightState) { leftIndicator = !leftIndicator; rightIndicator = leftIndicator; } INPUT_SEM.release(); }
// Send speed, accelerometer and brake values to a 100 element MAIL queue // car mail semaphore used to protect messages // average speed and input semphore used to fix vales // Repetition rate 0.2 Hz = 5 seconds void sendToMail(void const *args){ while(true){ mail_t *mail = mail_box.alloc(); CAR_MAIL_SEM.wait(); AVR_SPEED_SEM.wait(); mail->speedVal = averageSpeed; AVR_SPEED_SEM.release(); INPUT_SEM.wait(); mail->accelerometerVal = accelerationValue; mail->breakVal = brakeValue; INPUT_SEM.release(); write++; mail_box.put(mail); CAR_MAIL_SEM.release(); Thread::wait(5000); } }
// Update the odometer value // Shows values of LCD display // - odometer values // - average speed // average speed semaphone used to fix this value // Repetition rate 2 Hz = 0.5 seconds void updateOdometer(){ AVR_SPEED_SEM.wait(); float time = 0.5; odometerValue += averageSpeed / time ; //show on MBED text display lcd->locate(0,0); lcd->printf("odo : %.0f", odometerValue); // show average speed lcd->locate(1,0); lcd->printf("speed : %.2f", averageSpeed); AVR_SPEED_SEM.release(); }
// Flash an LED if speed goes over 70 mph // average speed semaphore is used so this value is not changed // Repetition rate 0.5 Hz = 2 seconds void speedOver70(void const *args){ while(true){ AVR_SPEED_SEM.wait(); if(averageSpeed > 70) { // ! used to flip the values each time which // creates flashing. OverSpeedLED = !OverSpeedLED; }else { OverSpeedLED = 0; } AVR_SPEED_SEM.release(); Thread::wait(2000); } }
/** Testing thread states: wait semaphore Given the thread is running when thread waits for a semaphore then its state, as reported by @a get_state, is @a WaitingSemaphore */ void test_semaphore() { char *dummy = new (std::nothrow) char[THREAD_STACK_SIZE]; delete[] dummy; TEST_SKIP_UNLESS_MESSAGE(dummy, "Not enough memory to run test"); Thread t(osPriorityNormal, THREAD_STACK_SIZE); Semaphore sem; t.start(callback(test_semaphore_thread, &sem)); ThisThread::yield(); TEST_ASSERT_EQUAL(Thread::WaitingSemaphore, t.get_state()); sem.release(); }
// Flash appropriate indicator LEDs at a rate of 1Hz // input semaphore used so value doesnt change // Repetition rate 1 Hz = 1 seconds void flashIndicator() { INPUT_SEM.wait(); // only happens if a single light or no light is on if(!(leftLightState && rightLightState)) { if(leftLightState) { // ! used to flip value to create flashing leftIndicator = !leftIndicator; rightIndicator = 0; } if(rightLightState) { leftIndicator = 0; // ! used to flip value to create flashing rightIndicator = !rightIndicator; } } INPUT_SEM.release(); }
static void tcpip_init_done(void *arg) { tcpip_inited.release(); }
int main() { for (int i = 0; i < READER_COUNT; ++i) { createThread([&](){ g_mainWaiter.release(); g_threadsWaiter.wait(); double start = getTime(); for (int j = 0; j < READER_LOOP; ++j) { { #if USE_LOCK == LOCK_TYPE_RW ReaderGuard<ReaderWriterLock> guard(g_resRW); #elif USE_LOCK == LOCK_TYPE_RW2 ReaderGuard<ReaderWriterLock2> guard(g_resRW2); #elif USE_LOCK == LOCK_TYPE_POSIX_RW ReaderGuard<PosixReaderWriterLock> guard(g_posixResRW); #elif USE_LOCK == LOCK_TYPE_MUTEX MutexGuard<Mutex> guard(g_resMutex); #elif USE_LOCK == LOCK_TYPE_POSIX_MUTEX MutexGuard<PosixMutex> guard(g_posixResMutex); #else #endif doRead(); } } double readerTime = getTime() - start; MutexGuard<Mutex> guard(g_gMutex); g_readerTime += readerTime; g_mainWaiter.release(); }); } for (int i = 0; i < WRITER_COUNT; ++i) { createThread([&](){ g_mainWaiter.release(); g_threadsWaiter.wait(); double start = getTime(); for (int j = 0; j < WRITER_LOOP; ++j) { sleep_us(10); { #if USE_LOCK == LOCK_TYPE_RW WriterGuard<ReaderWriterLock> guard(g_resRW); #elif USE_LOCK == LOCK_TYPE_RW2 WriterGuard<ReaderWriterLock2> guard(g_resRW2); #elif USE_LOCK == LOCK_TYPE_POSIX_RW WriterGuard<PosixReaderWriterLock> guard(g_posixResRW); #elif USE_LOCK == LOCK_TYPE_MUTEX MutexGuard<Mutex> guard(g_resMutex); #elif USE_LOCK == LOCK_TYPE_POSIX_MUTEX MutexGuard<PosixMutex> guard(g_posixResMutex); #else #endif doWrite(); } } double writerTime = getTime() - start; MutexGuard<Mutex> guard(g_gMutex); g_writerTime += writerTime; g_mainWaiter.release(); }); } for (int i = 0; i < READER_COUNT + WRITER_COUNT; ++i) g_mainWaiter.acquire(); g_threadsWaiter.signal(); for (int i = 0; i < READER_COUNT + WRITER_COUNT; ++i) g_mainWaiter.acquire(); fprintf(stderr, "res=%d,res2=%d=\n", g_res, g_res2); printf("lockType=%s, R/W=%d, reader=%.3fs, writer=%.3fs\n", TYPE_NAME, READER_COUNT / WRITER_COUNT, g_readerTime / READER_COUNT, g_writerTime / WRITER_COUNT); }
/**************************************************************************//** * @brief Bitmap data encode to JPEG * @param[in] bitmap_buff_info_t* psInputBuff : Input bitmap data address * @param[out] void* pJpegBuff : Output JPEG data address * @param[out] size_t* pEncodeSize : Encode size address * @param[in] encode_options_t* pOptions : Encode option(Optional) * @retval error code ******************************************************************************/ JPEG_Converter::jpeg_conv_error_t JPEG_Converter::encode(bitmap_buff_info_t* psInputBuff, void* pJpegBuff, size_t* pEncodeSize, encode_options_t* pOptions ) { jpeg_conv_error_t e; jcu_errorcode_t jcu_error; jcu_buffer_param_t buffer; uint8_t* TableAddress; jcu_encode_param_t encode; jcu_count_mode_param_t count_para; int32_t encode_count; int32_t size_max_count = 1; size_t BufferSize = pOptions->encode_buff_size; const jcu_async_status_t* status; bool mutex_release = false; // Check JCU initialized if (driver_ac_count > 0) { // Check input address if ((pJpegBuff == NULL) || (psInputBuff == NULL) || (pEncodeSize == NULL)) { e = JPEG_CONV_PARAM_ERR; // Input address error goto fin; } // JCU Error reset if (jcu_error_flag == true) { (void)R_JCU_Terminate(); (void)R_JCU_Initialize(NULL); jcu_error_flag = false; } // Get mutex if ( pOptions->p_EncodeCallBackFunc == NULL ) { jpeg_converter_semaphore.wait(0xFFFFFFFFuL); // WAIT } else { if (!jpeg_converter_semaphore.wait(0)) { e = JPEG_CONV_BUSY; // Busy goto fin; } } // Select encode jcu_error = R_JCU_SelectCodec(JCU_ENCODE); if (jcu_error != JCU_ERROR_OK) { e = JPEG_CONV_JCU_ERR; mutex_release = true; goto fin; } /* Set tables */ if ( pOptions->quantization_table_Y != NULL ) { TableAddress = (uint8_t*)pOptions->quantization_table_Y; } else { TableAddress = (uint8_t*)csaDefaultQuantizationTable_Y; } jcu_error = R_JCU_SetQuantizationTable( JCU_TABLE_NO_0, (uint8_t*)TableAddress ); if ( jcu_error != JCU_ERROR_OK ) { e = JPEG_CONV_PARAM_RANGE_ERR; mutex_release = true; jcu_error_flag = true; goto fin; } if ( pOptions->quantization_table_C != NULL ) { TableAddress = (uint8_t*)pOptions->quantization_table_C; } else { TableAddress = (uint8_t*)csaDefaultQuantizationTable_C; } jcu_error = R_JCU_SetQuantizationTable( JCU_TABLE_NO_1, (uint8_t*)TableAddress ); if ( jcu_error != JCU_ERROR_OK ) { e = JPEG_CONV_PARAM_RANGE_ERR; mutex_release = true; jcu_error_flag = true; goto fin; } if ( pOptions->huffman_table_Y_DC != NULL ) { TableAddress = (uint8_t*)pOptions->huffman_table_Y_DC; } else { TableAddress = (uint8_t*)csaDefaultHuffmanTable_Y_DC; } jcu_error = R_JCU_SetHuffmanTable( JCU_TABLE_NO_0, JCU_HUFFMAN_DC, (uint8_t*)TableAddress ); if ( jcu_error != JCU_ERROR_OK ) { e = JPEG_CONV_PARAM_RANGE_ERR; mutex_release = true; jcu_error_flag = true; goto fin; } if ( pOptions->huffman_table_C_DC != NULL ) { TableAddress = (uint8_t*)pOptions->huffman_table_C_DC; } else { TableAddress = (uint8_t*)csaDefaultHuffmanTable_C_DC; } jcu_error = R_JCU_SetHuffmanTable( JCU_TABLE_NO_1, JCU_HUFFMAN_DC, (uint8_t*)TableAddress ); if ( jcu_error != JCU_ERROR_OK ) { e = JPEG_CONV_PARAM_RANGE_ERR; mutex_release = true; jcu_error_flag = true; goto fin; } if ( pOptions->huffman_table_Y_AC != NULL ) { TableAddress = (uint8_t*)pOptions->huffman_table_Y_AC; } else { TableAddress = (uint8_t*)csaDefaultHuffmanTable_Y_AC; } jcu_error = R_JCU_SetHuffmanTable( JCU_TABLE_NO_0, JCU_HUFFMAN_AC, (uint8_t*)TableAddress ); if ( jcu_error != JCU_ERROR_OK ) { e = JPEG_CONV_PARAM_RANGE_ERR; mutex_release = true; jcu_error_flag = true; goto fin; } if ( pOptions->huffman_table_C_AC != NULL ) { TableAddress = (uint8_t*)pOptions->huffman_table_C_AC; } else { TableAddress = (uint8_t*)csaDefaultHuffmanTable_C_AC; } jcu_error = R_JCU_SetHuffmanTable( JCU_TABLE_NO_1, JCU_HUFFMAN_AC, (uint8_t*)TableAddress ); if ( jcu_error != JCU_ERROR_OK ) { e = JPEG_CONV_PARAM_RANGE_ERR; mutex_release = true; jcu_error_flag = true; goto fin; } // JPEG encode buffer.source.swapSetting = (jcu_swap_t)pOptions->input_swapsetting; buffer.source.address = (uint32_t *)psInputBuff->buffer_address; buffer.destination.swapSetting = JCU_SWAP_LONG_WORD_AND_WORD_AND_BYTE; buffer.destination.address = (uint32_t *)pJpegBuff; buffer.lineOffset = psInputBuff->width; encode.encodeFormat = (jcu_jpeg_format_t)JCU_JPEG_YCbCr422; encode.QuantizationTable[ JCU_ELEMENT_Y ] = JCU_TABLE_NO_0; encode.QuantizationTable[ JCU_ELEMENT_Cb ] = JCU_TABLE_NO_1; encode.QuantizationTable[ JCU_ELEMENT_Cr ] = JCU_TABLE_NO_1; encode.HuffmanTable[ JCU_ELEMENT_Y ] = JCU_TABLE_NO_0; encode.HuffmanTable[ JCU_ELEMENT_Cb ] = JCU_TABLE_NO_1; encode.HuffmanTable[ JCU_ELEMENT_Cr ] = JCU_TABLE_NO_1; encode.DRI_value = pOptions->DRI_value; if ( pOptions->width != 0 ) { encode.width = pOptions->width; } else { encode.width = psInputBuff->width; } if ( pOptions->height != 0 ) { encode.height = pOptions->height; } else { encode.height = psInputBuff->height; } encode.inputCbCrOffset = (jcu_cbcr_offset_t)pOptions->input_cb_cr_offset; jcu_error = R_JCU_SetEncodeParam( &encode, &buffer ); if ( jcu_error != JCU_ERROR_OK ) { e = JPEG_CONV_PARAM_RANGE_ERR; mutex_release = true; jcu_error_flag = true; goto fin; } if (pOptions->encode_buff_size > 0) { while(BufferSize > ENC_SIZE_MAX) { size_max_count *= 2; BufferSize /= 2; } BufferSize = BufferSize & MASK_8BYTE; count_para.inputBuffer.isEnable = false; count_para.inputBuffer.isInitAddress = false; count_para.inputBuffer.restartAddress = NULL; count_para.inputBuffer.dataCount = 0; count_para.outputBuffer.isEnable = true; count_para.outputBuffer.isInitAddress = false; count_para.outputBuffer.restartAddress = NULL; count_para.outputBuffer.dataCount = BufferSize; R_JCU_SetCountMode(&count_para); } else { size_max_count = 0; } // Check async if ( pOptions->p_EncodeCallBackFunc == NULL ) { jcu_error = R_JCU_Start(); mutex_release = true; if ( jcu_error != JCU_ERROR_OK ) { e = JPEG_CONV_JCU_ERR; jcu_error_flag = true; goto fin; } if (pOptions->encode_buff_size > 0) { // Check Pause flag R_JCU_GetAsyncStatus( &status ); for ( encode_count = 1; (encode_count < size_max_count) && (status->IsPaused != false); encode_count++) { if ((status->SubStatusFlags & JCU_SUB_ENCODE_OUTPUT_PAUSE) == 0) { e = JPEG_CONV_JCU_ERR; jcu_error_flag = true; goto fin; } jcu_error = R_JCU_Continue( JCU_OUTPUT_BUFFER ); if (jcu_error != JCU_ERROR_OK) { e = JPEG_CONV_JCU_ERR; jcu_error_flag = true; goto fin; } R_JCU_GetAsyncStatus( &status ); } if (status->IsPaused != false) { e = JPEG_CONV_PARAM_RANGE_ERR; jcu_error_flag = true; goto fin; } } (void)R_JCU_GetEncodedSize(pEncodeSize); } else { pJPEG_ConverterCallback = pOptions->p_EncodeCallBackFunc; jcu_error = R_wrpper_set_encode_callback((mbed_CallbackFunc_t*)JPEG_CallbackFunction, pEncodeSize, size_max_count); if ( jcu_error != JCU_ERROR_OK ) { e = JPEG_CONV_JCU_ERR; goto fin; } } e = JPEG_CONV_OK; } else { e = JPEG_CONV_PARAM_RANGE_ERR; } fin: if (mutex_release == true) { jpeg_converter_semaphore.release(); // RELEASE } return e; } /* End of method encode() */
/**************************************************************************//** * @brief JPEG data decode to bitmap * @param[in] void* pJpegBuff : Input JPEG data address * @param[in/out] bitmap_buff_info_t* psOutputBuff : Output bitmap data address * @param[in] decode_options_t* pOptions : Decode option(Optional) * @retval error code ******************************************************************************/ JPEG_Converter::jpeg_conv_error_t JPEG_Converter::decode(void* pJpegBuff, bitmap_buff_info_t* psOutputBuff, decode_options_t* pOptions) { jpeg_conv_error_t e; jcu_errorcode_t jcu_error; jcu_decode_param_t decode; jcu_buffer_param_t buffer; uint8_t* pBuff = (uint8_t *)pJpegBuff; const jcu_async_status_t* status; jcu_image_info_t image_info; bool mutex_release = false; // Check JCU initialized if (driver_ac_count > 0) { size_t calc_height; size_t calc_width; calc_height = psOutputBuff->height * (2 ^ pOptions->vertical_sub_sampling); calc_width = psOutputBuff->width * (2 ^ pOptions->horizontal_sub_sampling); // Check input address if ((pJpegBuff == NULL) || (psOutputBuff == NULL) || (pOptions == NULL)) { e = JPEG_CONV_PARAM_ERR; // Input address error goto fin; } // Check JPEG header if (((uint32_t)(pBuff[0]) != JPEG_HEADER_LETTER_1) || ((uint32_t)(pBuff[1]) != JPEG_HEADER_LETTER_2)) { e = JPEG_CONV_FORMA_ERR; // JPEG data is not in ROM goto fin; } // JCU Error reset if (jcu_error_flag == true) { (void)R_JCU_Terminate(); (void)R_JCU_Initialize(NULL); jcu_error_flag = false; } // Get mutex if (pOptions->p_DecodeCallBackFunc == NULL) { jpeg_converter_semaphore.wait(0xFFFFFFFFuL); // WAIT } else { if (!jpeg_converter_semaphore.wait(0)) { e = JPEG_CONV_BUSY; // Busy goto fin; } } // Select decode jcu_error = R_JCU_SelectCodec( JCU_DECODE ); if (jcu_error != JCU_ERROR_OK) { e = JPEG_CONV_JCU_ERR; mutex_release = true; goto fin; } buffer.source.swapSetting = JCU_SWAP_LONG_WORD_AND_WORD_AND_BYTE; buffer.source.address = (uint32_t *)pBuff; buffer.lineOffset = (int16_t)psOutputBuff->width; buffer.destination.address = (uint32_t *)psOutputBuff->buffer_address; decode.decodeFormat = (jcu_decode_format_t)psOutputBuff->format; buffer.destination.swapSetting = (jcu_swap_t)pOptions->output_swapsetting; decode.outputCbCrOffset = (jcu_cbcr_offset_t)pOptions->output_cb_cr_offset; decode.alpha = pOptions->alpha; decode.horizontalSubSampling = (jcu_sub_sampling_t)pOptions->horizontal_sub_sampling; decode.verticalSubSampling = (jcu_sub_sampling_t)pOptions->vertical_sub_sampling; jcu_error = R_JCU_SetDecodeParam(&decode, &buffer); if (jcu_error != JCU_ERROR_OK) { e = JPEG_CONV_FORMA_ERR; mutex_release = true; jcu_error_flag = false; goto fin; } if (pOptions->check_jpeg_format != false) { jcu_error = R_JCU_SetPauseForImageInfo(true); if (jcu_error != JCU_ERROR_OK) { e = JPEG_CONV_JCU_ERR; mutex_release = true; jcu_error_flag = false; goto fin; } } if (pOptions->p_DecodeCallBackFunc == NULL) { jcu_error = R_JCU_Start(); mutex_release = true; if (jcu_error != JCU_ERROR_OK) { e = JPEG_CONV_JCU_ERR; jcu_error_flag = false; goto fin; } if (pOptions->check_jpeg_format != false) { R_JCU_GetAsyncStatus( &status ); if (status -> IsPaused == false) { e = JPEG_CONV_JCU_ERR; jcu_error_flag = false; goto fin; } if ((status->SubStatusFlags & JCU_SUB_INFOMATION_READY) == 0) { e = JPEG_CONV_JCU_ERR; jcu_error_flag = false; goto fin; } jcu_error = R_JCU_GetImageInfo( &image_info ); if (jcu_error != JCU_ERROR_OK) { e = JPEG_CONV_JCU_ERR; jcu_error_flag = false; goto fin; } if ((image_info.width == 0u) || (image_info.height == 0u) || (image_info.width > calc_width) || (image_info.height > calc_height)) { e = JPEG_CONV_FORMA_ERR; jcu_error_flag = false; goto fin; } if ((image_info.encodedFormat != JCU_JPEG_YCbCr444) && (image_info.encodedFormat != JCU_JPEG_YCbCr422) && (image_info.encodedFormat != JCU_JPEG_YCbCr420) && (image_info.encodedFormat != JCU_JPEG_YCbCr411)) { e = JPEG_CONV_FORMA_ERR; jcu_error_flag = false; goto fin; } jcu_error = R_JCU_Continue(JCU_IMAGE_INFO); if (jcu_error != JCU_ERROR_OK) { e = JPEG_CONV_JCU_ERR; jcu_error_flag = false; goto fin; } } } else { pJPEG_ConverterCallback = pOptions->p_DecodeCallBackFunc; jcu_error = R_wrpper_set_decode_callback((mbed_CallbackFunc_t*)JPEG_CallbackFunction, (size_t)calc_width, calc_height); if (jcu_error != JCU_ERROR_OK) { e = JPEG_CONV_JCU_ERR; mutex_release = true; goto fin; } } e = JPEG_CONV_OK; } else { e = JPEG_CONV_JCU_ERR; } fin: if (mutex_release == true) { jpeg_converter_semaphore.release(); // RELEASE } return e; } /* End of method decode() */
// Read a single side light switch and set side lights accordingly // input semaphore used to hold value // Repetition rate 1 Hz = 1 second void readSideLight(){ INPUT_SEM.wait(); int sideLightState = sideLightSwitch; INPUT_SEM.release(); sideLight = sideLightState; }
void button_clicked() { clicked = true; updates.release(); }
void unregister() { registered = false; updates.release(); }
static void netif_status_callback(struct netif *netif) { strcpy(ip_addr, inet_ntoa(netif->ip_addr)); connected = netif_is_up(netif) ? true : false; netif_inited.release(); }
virtual void handler() { sem.release(); }
static void netif_link_callback(struct netif *netif) { if (netif_is_link_up(netif)) { netif_linked.release(); } }
static void netif_status_callback(struct netif *netif) { if (netif_is_up(netif)) { strcpy(ip_addr, inet_ntoa(netif->ip_addr)); netif_up.release(); } }
void network_callback() { network_led = !network_led; network_sem.release(); }