void main(void) { // sample text char rc; // int ret; int loop=0; // DiagPrintf("sleep 10 sec. to wait for UART console\n"); //RtlMsleepOS(10000); DiagPrintf("CRYPTO API Demo...\r\n"); if ( rtl_cryptoEngine_init() != 0 ) { DiagPrintf("crypto engine init failed\r\n"); } test_md5(); test_aes_cbc(); for(;;); }
void ticker_irq_handler(const ticker_data_t *const data) { data->interface->clear_interrupt(); /* Go through all the pending TimerEvents */ while (1) { if (data->queue->head == NULL) { DiagPrintf("%s : ERROR head == NULL \r\n", __FUNCTION__); // There are no more TimerEvents left, so disable matches. data->interface->disable_interrupt(); return; } if (data->queue->head->timestamp <= data->interface->read()) { // This event was in the past: // point to the following one and execute its handler ticker_event_t *p = data->queue->head; data->queue->head = data->queue->head->next; if (data->queue->event_handler != NULL) { (*data->queue->event_handler)(p->id); // NOTE: the handler can set new events } else { DiagPrintf("event_handler == NULL \r\n"); } /* Note: We continue back to examining the head because calling the * event handler may have altered the chain of pending events. */ } else { // This event and the following ones in the list are in the future: // set it as next interrupt and return data->interface->set_interrupt(data->queue->head->timestamp); return; } } }
/** * @brief Main program. * @param None * @retval None */ void main(void) { if(rtl_cryptoEngine_init() != 0) { DiagPrintf("crypto engine init failed\r\n"); } /* Initialize log uart and at command service */ console_init(); // Setup init sequence for test setup_init_sequence(); /* wlan intialization */ #if defined(CONFIG_WIFI_NORMAL) && defined(CONFIG_NETWORK) wlan_network(); #endif /*Enable Schedule, Start Kernel*/ #if defined(CONFIG_KERNEL) && !TASK_SCHEDULER_DISABLED #ifdef PLATFORM_FREERTOS vTaskStartScheduler(); #endif #else RtlConsolTaskRom(NULL); #endif }
void ticker_set_handler(const ticker_data_t *const data, ticker_event_handler handler) { data->interface->init(); data->queue->event_handler = handler; DiagPrintf(" %s event_handler : 0x%x\r\n", __FUNCTION__, data->queue->event_handler); }
//--------------------------------------------------------------------------------------------------- //Function Name: // I2CISRHandle // // Description: // I2C Interrupt Service Routine. // According to the input pointer to SAL_I2C_HND, all the rest pointers will be // found and be used to the rest part of this servie routine. // The following types of interrupt will be taken care: // - General Call (providing General Call Callback). Slave receives a general call. // - STOP Bit (NOT providing General Call Callback) // - START Bit (NOTproviding General Call Callback) // - I2C Activity (NOTproviding General Call Callback) // - RX Done (providing Error Callback). The slave transmitter does NOT // receive a proper NACK for the end of whole transfer. // - TX Abort (providing Error Call Callback). The Master/Slave // transmitting is terminated. // - RD Req (providing TX and TXC Callback). Slave gets a Read Request // and starts a slave-transmitter operation. The slave transmit // data will be written into slave TX FIFO from user data buffer. // - TX Empty (providing TX and TXC Callback). Master TX FIFO is empty. // The user transmit data will be written into master TX FIFO // from user data buffer. // - TX Over (providing Error Callback). Master TX FIFO is Overflow. // - RX Full (providing RX and RXC Callback). Master/Slave RX FIFO contains // data. And the received data will be put into Master/Slave user // receive data buffer. // - RX Over (providing Error Callback). Master/Slave RX FIFO is Overflow. // - RX Under (providing Error Callback). Master/Slave RX FIFO is Underflow. // // Arguments: // [in] VOID *Data - // I2C SAL handle // // Return: // NA // // Note: // NA // // See Also: // NA // // Author: // By Jason Deng, 2014-04-02. // //---------------------------------------------------------------------------------------------------- VOID DACISRHandle( IN VOID *Data ){ #ifdef CONFIG_DEBUG_LOG_DAC_HAL PSAL_DAC_HND pSalDACHND = (PSAL_DAC_HND) Data; PSAL_DAC_HND_PRIV pSalDACHNDPriv = NULL; PSAL_DAC_MNGT_ADPT pSalDACMngtAdpt = NULL; PHAL_DAC_INIT_DAT pHalDACInitDat = NULL; PHAL_DAC_OP pHalDACOP = NULL; PSAL_DAC_USER_CB pSalDACUserCB = NULL; u8 DACIrqIdx; /* To get the SAL_I2C_MNGT_ADPT pointer, and parse the rest pointers */ pSalDACHNDPriv = CONTAINER_OF(pSalDACHND, SAL_DAC_HND_PRIV, SalDACHndPriv); pSalDACMngtAdpt = CONTAINER_OF(pSalDACHNDPriv->ppSalDACHnd, SAL_DAC_MNGT_ADPT, pSalHndPriv); pHalDACInitDat = pSalDACMngtAdpt->pHalInitDat; pHalDACOP = pSalDACMngtAdpt->pHalOp; DACIrqIdx = pHalDACInitDat->DACIdx; pSalDACUserCB = pSalDACHND->pUserCB; //DBG_8195A_DAC_LVL(HAL_DAC_LVL,"DAC INTR STS:%x\n",pHalDACOP->HalDACReadReg(pHalDACInitDat, REG_DAC_INTR_STS)); DiagPrintf("DAC INTR STS:%x\n",pHalDACOP->HalDACReadReg(pHalDACInitDat, REG_DAC_INTR_STS)); #else /* To reduce warning */ Data = Data; #endif }
int test_aes_cbc(void) { const u8 *key, *pIv; u32 keylen= 0; u32 ivlen = 0; u8 *message; u32 msglen; u8 *pResult; int ret; DiagPrintf("AES CBC test\r\n"); key = aes_test_key; keylen = 16; pIv = aes_test_iv_1; ivlen = 16; pResult = cipher_result; message = (unsigned char *)aes_test_buf; msglen = sizeof(aes_test_buf); ret = rtl_crypto_aes_cbc_init(key,keylen); if ( ret != 0 ) { DiagPrintf("AES CBC init failed\r\n"); return ret; } ret = rtl_crypto_aes_cbc_encrypt(message, msglen, pIv, ivlen, pResult); if ( ret != 0 ) { DiagPrintf("AES CBC encrypt failed\r\n"); return ret; } if ( rtl_memcmpb(aes_test_res_128, pResult, msglen) == 0 ) { DiagPrintf("AES CBC encrypt result success\r\n"); } else { DiagPrintf("AES CBC encrypt result failed\r\n"); } message = pResult; ret = rtl_crypto_aes_cbc_decrypt(message, msglen, pIv, ivlen, pResult); if ( ret != 0 ) { DiagPrintf("AES CBC decrypt failed, ret=%d\r\n", ret); return ret; } if ( rtl_memcmpb(aes_test_buf, pResult, msglen) == 0 ) { DiagPrintf("AES CBC decrypt result success\r\n"); } else { DiagPrintf("AES CBC decrypt result failed\r\n"); } return 0; }
/*----------------------------------------------------- Parameters: Returns value: Description ------------------------------------------------------*/ IMAGE * ImageRead(const char*fname) { IMAGE *I = NULL ; MATRIX *mat ; FILE *fp ; int type, frame ; char buf[STRLEN] ; strcpy(buf, fname) ; /* don't destroy callers string */ ImageUnpackFileName(buf, &frame, &type, buf) ; switch (type) { case TIFF_IMAGE: I = TiffReadImage(buf, frame) ; if (I == NULL) return(NULL) ; break ; case MATLAB_IMAGE: DiagPrintf(DIAG_WRITE, "ImageRead: buf=%s, frame=%d, type=%d (M=%d,H=%d)\n", buf, frame, type , MATLAB_IMAGE, HIPS_IMAGE); mat = MatlabRead(buf) ; if (!mat) ErrorReturn(NULL, (ERROR_NO_FILE, "ImageRead(%s) failed\n", buf)) ; I = ImageFromMatrix(mat, NULL) ; ImageInvert(I, I) ; MatrixFree(&mat) ; break ; case HIPS_IMAGE: fp = fopen(buf, "rb") ; if (!fp) ErrorReturn(NULL, (ERROR_NO_FILE, "ImageRead(%s, %d) failed\n", buf, frame)) ; I = ImageFRead(fp, buf, frame, 1) ; fclose(fp) ; break ; case JPEG_IMAGE: I = JPEGReadImage(buf); break ; case PGM_IMAGE: I = PGMReadImage(buf); break; case PPM_IMAGE: I = PPMReadImage(buf); break; case PBM_IMAGE: I = PBMReadImage(buf); break; case RGBI_IMAGE: I= RGBReadImage(buf); default: break ; } return(I) ; }
void test_md5(void) { int i; int ret; u8 md5sum[16]; DiagPrintf("MD5 test\r\n"); ret = rtl_crypto_md5(plaintext, strlen(plaintext), (unsigned char *)&digest); // the length of MD5's digest is 16 bytes. if ( rtl_memcmpb(digest, md5_digest, 16) == 0 ) { DiagPrintf("MD5 test result is correct, ret=%d\r\n", ret); } else { DiagPrintf("MD5 test result is WRONG!!, ret=%d\r\n", ret); } for( i = 0; i < 16; i++ ) { DiagPrintf( " MD5 test #%d: ", i + 1 ); ret = rtl_crypto_md5(md5_test_buf[i], md5_test_buflen[i], md5sum); // the length of MD5's digest is 16 bytes. DiagPrintf(" MD5 ret=%d\n", ret); if( rtl_memcmpb( md5sum, md5_test_sum[i], 16 ) != 0 ) { DiagPrintf( "failed\n" ); memset(md5sum,0,16); } else{ DiagPrintf( "passed\n" ); memset(md5sum,0,16);} } }
IMAGE2_TEXT_SECTION void delay( uint32_t ms ) { osStatus ret; //HalDelayUs(ms*1000); ret = osDelay(ms); if ( (ret != osEventTimeout) && (ret != osOK) ) { DiagPrintf("delay : ERROR : 0x%x \n", ret); } }
int Thread::start() { _tid = osThreadCreate(&_thread_def, _thread_arg); if ( _tid == NULL ) { DiagPrintf("Thread start failed \n"); return -1; } return 0; }
void main(void) { gpio_t gpio_led; int led_status; int i2clocalcnt; int error; uint16_t shtc1_id; float temperature = 1.123f; float humidity = 2.456f; DBG_8195A("sleep 10 sec. to wait for UART console\n"); Mdelay(10000); DBG_8195A("start i2c example - SHTC1\n"); error = SHTC1_Init(&shtc1_id); if ( error == NO_ERROR ) { DiagPrintf("SHTC1 init ok, id=0x%x\r\n", shtc1_id); } else { DiagPrintf("SHTC1 init FAILED! \r\n"); for(;;); } while(1){ error = SHTC1_GetTempAndHumi(&temperature, &humidity); rtl_printf("temp=%f, humidity=%f, error=%d\n", temperature, humidity, error); Mdelay(1000); } }
/*---------------------------------------------------------------------- Parameters: Description: ----------------------------------------------------------------------*/ void KernelUpdate(KIMAGE *ksrc, KIMAGE *kdst, int dst_row, int dst_col, int src_row, int src_col, float weight) { KERNEL *src_kernel, *dst_kernel ; register float *w ; int row, col, src_rows, src_cols, dst_rows, dst_cols, dst_row0, dst_col0, src_row0, src_col0, drow, dcol ; DiagPrintf(DIAG_KERNELS, "KernelUpdate(%d, %d, %d, %d, %f)\n", dst_row, dst_col, src_row, src_col, weight) ; src_kernel = KIMAGEpix(ksrc, src_row, src_col) ; dst_kernel = KIMAGEpix(kdst, dst_row, dst_col) ; src_rows = src_kernel->rows ; src_cols = src_kernel->cols ; src_row0 = src_kernel->row0 ; src_col0 = src_kernel->col0 ; dst_rows = dst_kernel->rows ; dst_cols = dst_kernel->cols ; dst_row0 = dst_kernel->row0 ; dst_col0 = dst_kernel->col0 ; /* go through each point in the source kernel. If it maps to a point that is within the domain of the destination kernel, then add its weight to the corresponding point in the destination kernel. */ drow = src_row0 - dst_row0 ; dcol = src_col0 - dst_col0 ; for (row = 0 ; row < src_rows ; row++) { w = src_kernel->weights[row] ; for (col = 0 ; col < src_cols ; col++, w++) { if (src_kernel->weights[row][col] > 0.0001) weight = weight * 1.0f ; dst_row = row + drow ; dst_col = col + dcol ; if ((dst_row < 0) || (dst_col < 0) || (dst_row >= dst_rows) || (dst_col >= dst_cols)) continue ; /* out of range */ dst_kernel->weights[dst_row][dst_col] += *w * weight ; } } }
int SHTC1_Init(uint16_t *pID) { int error = NO_ERROR; DiagPrintf("SHTC1_Init \r\n"); i2c_init((i2c_t*)&i2cmaster, MBED_I2C_MTR_SDA ,MBED_I2C_MTR_SCL); i2c_frequency((i2c_t*)&i2cmaster,MBED_I2C_BUS_CLK); if (pID == NULL ) return NULL_ERROR; error = SHTC1_GetID(pID); return error; }
/*---------------------------------------------------------------------- Parameters: Description: ----------------------------------------------------------------------*/ void KernelDiscount(KIMAGE *kimage, int row, int col, float weight) { KERNEL *kernel ; register float *w ; int cols ; DiagPrintf(DIAG_KERNELS, "KernelDiscount(%d, %d, %f)\n", row, col, weight) ; kernel = KIMAGEpix(kimage, row, col) ; cols = kernel->cols ; for (row = 0 ; row < kernel->rows ; row++) { w = kernel->weights[row] ; for (col = 0 ; col < cols ; col++) *w++ *= weight ; } }
/** * @brief Main program. * @param None * @retval None */ void main(void) { if ( rtl_cryptoEngine_init() != 0 ) { DiagPrintf("crypto engine init failed\r\n"); } /* Initialize log uart and at command service */ console_init(); /* pre-processor of application example */ pre_example_entry(); /* wlan intialization */ #if defined(CONFIG_WIFI_NORMAL) && defined(CONFIG_NETWORK) wlan_network(); #endif // setup uart with capability of wakeup system config_uart(); // setup log uart with capability of wakeup system config_loguart(); // By default tickless is disabled because WAKELOCK_OS is locked. // Release this wakelock to enable tickless release_wakelock(WAKELOCK_OS); // Register pre/post sleep callback. They are called when system automatically enter/leave sleep. register_pre_sleep_callback(pre_sleep_process_callback); register_post_sleep_callback(post_sleep_process_callback); /* Execute application example */ example_entry(); /*Enable Schedule, Start Kernel*/ #if defined(CONFIG_KERNEL) && !TASK_SCHEDULER_DISABLED #ifdef PLATFORM_FREERTOS vTaskStartScheduler(); #endif #else RtlConsolTaskRom(NULL); #endif }
//NeoJou // analogRead : ulPin : only for ADC using; uint32_t analogRead(uint32_t ulPin) { uint32_t ulValue = 0; uint32_t ulChannel; uint16_t ret = 0; float voltage; float adc_value; switch ( ulPin ) { case 0: case 1: ret = analogin_read_u16(&adc2); break; case 2: ret = analogin_read_u16(&adc3); break; default: DiagPrintf("%s : ulPin %d wrong\n", __FUNCTION__, ulPin); return 0; } ret >>= 4; if (ret < 674) { voltage = 0; } else if ( ret > 3410){ voltage = (float)(ret - 3410)*ADC_slope2 + 3.12; } else { voltage = (float)(ret-674)*ADC_slope1; } // Arduino analogRead() // input : 0~5V // 10 bit : 0 ~1023 ret = round(1023.0*voltage/5.0); if ( ret > 1023 ) ret = 1023; return ret; }
void mbed_die(void) { DiagPrintf("mbed_die\r\n"); for(;;); }
void os_error (uint32_t err_code) { /* This function is called when a runtime error is detected. Parameter */ /* 'err_code' holds the runtime error code (defined in RTX_Conf.h). */ DiagPrintf("os_error : 0x%x\n", err_code); mbed_die(); }
void sysThreadError(osStatus status) { if (status != osOK) { DiagPrintf("sysThreadError : 0x%x\n", status); mbed_die(); } }