void vSerialPutString( xComPortHandle pxPort, const signed char * const pcString, unsigned short usStringLength ) { signed char *pxNext; /* A couple of parameters that this port does not use. */ ( void ) usStringLength; ( void ) pxPort; /* NOTE: This implementation does not handle the queue being full as no block time is used! */ /* The port handle is not required as this driver only supports UART0. */ ( void ) pxPort; /* Send each character in the string, one at a time. */ pxNext = ( signed char * ) pcString; while( *pxNext ) { xSerialPutChar( pxPort, *pxNext, serNO_BLOCK ); pxNext++; } }
static portTASK_FUNCTION( vComTxTask, pvParameters ) { signed char cByteToSend; portTickType xTimeToWait; /* Just to stop compiler warnings. */ ( void ) pvParameters; for( ;; ) { /* Simply transmit a sequence of characters from comFIRST_BYTE to comLAST_BYTE. */ for( cByteToSend = comFIRST_BYTE; cByteToSend <= comLAST_BYTE; cByteToSend++ ) { if( xSerialPutChar( xPort, cByteToSend, comNO_BLOCK ) == pdPASS ) { vParTestToggleLED( uxBaseLED + comTX_LED_OFFSET ); } } /* Turn the LED off while we are not doing anything. */ vParTestSetLED( uxBaseLED + comTX_LED_OFFSET, pdFALSE ); /* We have posted all the characters in the string - wait before re-sending. Wait a pseudo-random time as this will provide a better test. */ xTimeToWait = xTaskGetTickCount() + comOFFSET_TIME; /* Make sure we don't wait too long... */ xTimeToWait %= comTX_MAX_BLOCK_TIME; /* ...but we do want to wait. */ if( xTimeToWait < comTX_MIN_BLOCK_TIME ) { xTimeToWait = comTX_MIN_BLOCK_TIME; } vTaskDelay( xTimeToWait ); } } /*lint !e715 !e818 pvParameters is required for a task function even if it is not referenced. */
/* Described at the top of this file. */ static void prvUSARTEchoTask( void *pvParameters ) { signed char cChar; /* String declared static to ensure it does not end up on the stack, no matter what the optimisation level. */ static const char *pcLongishString = "ABBA was a Swedish pop music group formed in Stockholm in 1972, consisting of Anni-Frid Frida Lyngstad, " "Björn Ulvaeus, Benny Andersson and Agnetha Fältskog. Throughout the band's existence, Fältskog and Ulvaeus " "were a married couple, as were Lyngstad and Andersson - although both couples later divorced. They became one " "of the most commercially successful acts in the history of popular music, and they topped the charts worldwide " "from 1972 to 1983. ABBA gained international popularity employing catchy song hooks, simple lyrics, sound " "effects (reverb, phasing) and a Wall of Sound achieved by overdubbing the female singers' voices in multiple " "harmonies. As their popularity grew, they were sought after to tour Europe, Australia, and North America, drawing " "crowds of ardent fans, notably in Australia. Touring became a contentious issue, being particularly cumbersome for " "Fältskog, but they continued to release studio albums to widespread commercial success. At the height of their " "popularity, however, both relationships began suffering strain that led ultimately to the collapse of first the " "Ulvaeus-Fältskog marriage (in 1979) and then of the Andersson-Lyngstad marriage in 1981. In the late 1970s and early " "1980s these relationship changes began manifesting in the group's music, as they produced more thoughtful, " "introspective lyrics with different compositions."; /* Just to avoid compiler warnings. */ ( void ) pvParameters; /* Initialise COM0, which is USART1 according to the STM32 libraries. */ lCOMPortInit( mainCOM0, mainBAUD_RATE ); /* Try sending out a string all in one go, as a very basic test of the lSerialPutString() function. */ lSerialPutString( mainCOM0, pcLongishString, strlen( pcLongishString ) ); for( ;; ) { /* Block to wait for a character to be received on COM0. */ xSerialGetChar( mainCOM0, &cChar, portMAX_DELAY ); /* Write the received character back to COM0. */ xSerialPutChar( mainCOM0, cChar, 0 ); } }
void testUSART(void) { u8 temp,recvNum; while(1){ recvNum=uxQueueMessagesWaiting(xRxedChars); printf("Hello world!,rec=%d\r\n",recvNum); Delay_Ms(500); if(recvNum>0) { while(recvNum--){ xSerialGetChar((signed char*)&temp,0); xSerialPutChar(temp , 5/portTICK_RATE_MS); } //xSerialPutChar('\r' , 5/portTICK_RATE_MS); //xSerialPutChar('\n' , 5/portTICK_RATE_MS); } Delay_Ms(300); } }
/********************************************************************* * Function: void taskSerial(void* pvParameter) * * PreCondition: None * * Input: None * * Output: Does not return * * Side Effects: None * * Overview: * * Note: ********************************************************************/ void taskUART(void* pvParameter) { static GRAPHICS_MSG msg; unsigned char val; // vTaskSetApplicationTaskTag( NULL, ( void * ) 's' ); xSerialPortInitMinimal( 115200, 10 ); while (1) { vTaskDelay( 50 / portTICK_RATE_MS ); // Wait 50ms if( xSerialGetChar(NULL, &val, 0xffff ) ) xSerialPutChar( NULL, val, 0xffff ); // LATFbits.LATF3 ^= 0x04; // LATDbits.LATD0 ^= 0x01; // xSerialPutChar( NULL, 'A', 0xffff ); // xSerialPutChar( NULL, 'B', 0xffff ); } }
/* Creates the tasks, then starts the scheduler. */ void main( void ) { /* Initialise the required hardware. */ vParTestInitialise(); /* Send a character so we have some visible feedback of a reset. */ xSerialPortInitMinimal( mainBAUD_RATE, mainCOMMS_QUEUE_LENGTH ); xSerialPutChar( NULL, 'X', mainNO_BLOCK ); /* Start a few of the standard demo tasks found in the demo\common directory. */ vStartMathTasks( tskIDLE_PRIORITY ); vStartLEDFlashTasks( mainLED_FLASH_PRIORITY ); /* Start the check task defined in this file. */ xTaskCreate( vErrorChecks, ( const char * const ) "Check", portMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL ); /* Start the scheduler. Will never return here. */ vTaskStartScheduler(); while(1) /* This point should never be reached. */ { } }
static int ReceiveCmd(char* buf) { unsigned short idx = -1; /* accumulate characters until the enter is hit */ do { /* increment index pointer for each character increment */ idx++; if (xSerialGetChar(xComPort, (signed char *) &buf[idx], portMAX_DELAY) == pdFALSE) { continue; } /* echo the character back to the terminal */ xSerialPutChar(xComPort, buf[idx], 0); /* handle the hit of an backspace by shifting the idx back */ if(buf[idx] == '\b'){ idx -= 2; } /* add some verbosity for the demo */ if (verbose >= 2) { printf("buf[%d] = 0x%02x\n", idx, buf[idx]); } } while ((buf[idx] != '\n') && (buf[idx] != '\r')); /* return the command string without the new line, so we have only the command */ buf[idx] = '\0'; if (verbose >= 1){ mdump(buf, 512); } /* return the length of the string */ return idx + 1; }
static void prvUARTCommandConsoleTask( void *pvParameters ) { signed char cRxedChar; uint8_t ucInputIndex = 0; char *pcOutputString; static char cInputString[ cmdMAX_INPUT_SIZE ], cLastInputString[ cmdMAX_INPUT_SIZE ]; BaseType_t xReturned; xComPortHandle xPort; ( void ) pvParameters; /* Obtain the address of the output buffer. Note there is no mutual exclusion on this buffer as it is assumed only one command console interface will be used at any one time. */ pcOutputString = FreeRTOS_CLIGetOutputBuffer(); /* Initialise the UART. */ xPort = xSerialPortInitMinimal( configCLI_BAUD_RATE, cmdQUEUE_LENGTH ); /* Send the welcome message. */ vSerialPutString( xPort, ( signed char * ) pcWelcomeMessage, ( unsigned short ) strlen( pcWelcomeMessage ) ); for( ;; ) { /* Wait for the next character. The while loop is used in case INCLUDE_vTaskSuspend is not set to 1 - in which case portMAX_DELAY will be a genuine block time rather than an infinite block time. */ while( xSerialGetChar( xPort, &cRxedChar, portMAX_DELAY ) != pdPASS ); /* Ensure exclusive access to the UART Tx. */ if( xSemaphoreTake( xTxMutex, cmdMAX_MUTEX_WAIT ) == pdPASS ) { /* Echo the character back. */ xSerialPutChar( xPort, cRxedChar, portMAX_DELAY ); /* Was it the end of the line? */ if( cRxedChar == '\n' || cRxedChar == '\r' ) { /* Just to space the output from the input. */ vSerialPutString( xPort, ( signed char * ) pcNewLine, ( unsigned short ) strlen( pcNewLine ) ); /* See if the command is empty, indicating that the last command is to be executed again. */ if( ucInputIndex == 0 ) { /* Copy the last command back into the input string. */ strcpy( cInputString, cLastInputString ); } /* Pass the received command to the command interpreter. The command interpreter is called repeatedly until it returns pdFALSE (indicating there is no more output) as it might generate more than one string. */ do { /* Get the next output string from the command interpreter. */ xReturned = FreeRTOS_CLIProcessCommand( cInputString, pcOutputString, configCOMMAND_INT_MAX_OUTPUT_SIZE ); /* Write the generated string to the UART. */ vSerialPutString( xPort, ( signed char * ) pcOutputString, ( unsigned short ) strlen( pcOutputString ) ); } while( xReturned != pdFALSE ); /* All the strings generated by the input command have been sent. Clear the input string ready to receive the next command. Remember the command that was just processed first in case it is to be processed again. */ strcpy( cLastInputString, cInputString ); ucInputIndex = 0; memset( cInputString, 0x00, cmdMAX_INPUT_SIZE ); vSerialPutString( xPort, ( signed char * ) pcEndOfOutputMessage, ( unsigned short ) strlen( pcEndOfOutputMessage ) ); } else { if( cRxedChar == '\r' ) { /* Ignore the character. */ } else if( ( cRxedChar == '\b' ) || ( cRxedChar == cmdASCII_DEL ) ) { /* Backspace was pressed. Erase the last character in the string - if any. */ if( ucInputIndex > 0 ) { ucInputIndex--; cInputString[ ucInputIndex ] = '\0'; } } else { /* A character was entered. Add it to the string entered so far. When a \n is entered the complete string will be passed to the command interpreter. */ if( ( cRxedChar >= ' ' ) && ( cRxedChar <= '~' ) ) { if( ucInputIndex < cmdMAX_INPUT_SIZE ) { cInputString[ ucInputIndex ] = cRxedChar; ucInputIndex++; } } } } /* Must ensure to give the mutex back. */ xSemaphoreGive( xTxMutex ); } } }
static void prvUARTCommandConsoleTask( void *pvParameters ) { char cRxedChar, cInputIndex = 0, *pcOutputString; static char cInputString[ cmdMAX_INPUT_SIZE ], cLastInputString[ cmdMAX_INPUT_SIZE ]; portBASE_TYPE xReturned; ( void ) pvParameters; /* Obtain the address of the output buffer. Note there is no mutual exclusion on this buffer as it is assumed only one command console interface will be used at any one time. */ pcOutputString = FreeRTOS_CLIGetOutputBuffer(); /* Send the welcome message. */ vSerialPutString( NULL, ( const signed char * ) pcWelcomeMessage, strlen( ( char * ) pcWelcomeMessage ) ); for( ;; ) { /* Only interested in reading one character at a time. */ while( xSerialGetChar( NULL, ( signed char * ) &cRxedChar, portMAX_DELAY ) == pdFALSE ); /* Echo the character back. */ xSerialPutChar( NULL, cRxedChar, portMAX_DELAY ); /* Was it the end of the line? */ if( cRxedChar == '\n' || cRxedChar == '\r' ) { /* Just to space the output from the input. */ vSerialPutString( NULL, ( const signed char * ) pcNewLine, strlen( ( char * ) pcNewLine ) ); /* See if the command is empty, indicating that the last command is to be executed again. */ if( cInputIndex == 0 ) { /* Copy the last command back into the input string. */ strcpy( ( char * ) cInputString, ( char * ) cLastInputString ); } /* Pass the received command to the command interpreter. The command interpreter is called repeatedly until it returns pdFALSE (indicating there is no more output) as it might generate more than one string. */ do { /* Get the next output string from the command interpreter. */ xReturned = FreeRTOS_CLIProcessCommand( cInputString, pcOutputString, configCOMMAND_INT_MAX_OUTPUT_SIZE ); /* Write the generated string to the UART. */ vSerialPutString( NULL, ( const signed char * ) pcOutputString, strlen( ( char * ) pcOutputString ) ); } while( xReturned != pdFALSE ); /* All the strings generated by the input command have been sent. Clear the input string ready to receive the next command. Remember the command that was just processed first in case it is to be processed again. */ strcpy( ( char * ) cLastInputString, ( char * ) cInputString ); cInputIndex = 0; memset( cInputString, 0x00, cmdMAX_INPUT_SIZE ); vSerialPutString( NULL, ( const signed char * ) pcEndOfOutputMessage, strlen( ( char * ) pcEndOfOutputMessage ) ); } else { if( cRxedChar == '\r' ) { /* Ignore the character. */ } else if( cRxedChar == '\b' ) { /* Backspace was pressed. Erase the last character in the string - if any. */ if( cInputIndex > 0 ) { cInputIndex--; cInputString[ cInputIndex ] = '\0'; } } else { /* A character was entered. Add it to the string entered so far. When a \n is entered the complete string will be passed to the command interpreter. */ if( ( cRxedChar >= ' ' ) && ( cRxedChar <= '~' ) ) { if( cInputIndex < cmdMAX_INPUT_SIZE ) { cInputString[ cInputIndex ] = cRxedChar; cInputIndex++; } } } } } }
int fputc(int ch, FILE *f) { xSerialPutChar( (u8)ch, 0/portTICK_RATE_MS); return ch; }
portTASK_FUNCTION(ambilcepat, pvParameters ) { vTaskDelay(500); int loopambil=0; #ifdef PAKAI_SHELL printf(" Monita : Ambil cepat init !!\r\n"); #endif #if defined(PAKAI_I2C) && defined(PAKAI_TSC) unsigned char st_tsc=0; char a; int i; int c=0; if (setup_fma()) printf(" NO ack !\r\n"); else { printf("Init TSC OK ack !!!\r\n"); st_tsc = 1; } #endif #ifdef PAKAI_GPS int hasil_gpsnya; awal_gps(); #endif #ifdef PAKAI_ADC extern unsigned char status_adcnya; #endif #ifdef PAKAI_GPIO_DIMMER //init_remang(); #endif #ifdef PAKAI_PM int almtSumber=0; int sPM=0; #ifdef AMBIL_PM printf("Init ambil PM ..-ambilcepat-..!!!\r\n"); vTaskDelay(3000); #endif #endif int waktunya=0; char dataserial[50]; vTaskDelay(50); for(;;) { vTaskDelay(1); #ifdef DATA_RANDOM data_f[loopambil%10] = (float) ((rand() % 100)); //printf("%d: data: %.1f\r\n", loopambil%10, data_f[loopambil%10]); #endif loopambil++; #ifdef PAKAI_GPS if (serPollGPS()) { hasil_gpsnya = proses_gps(); #if 0 info_gps(hasilGPS); #endif } #endif #ifdef PAKAI_PM #ifdef AMBIL_PM // AMBIL_PM sedot_pm(); #endif #endif #ifdef PAKAI_ADC if (status_adcnya) { proses_data_adc(); //printf("proses adc ... %d !!\r\n", status_adcnya); #ifdef BOARD_KOMON_420_SAJA hitung_datanya(); #endif simpan_ke_data_f(); } #endif #ifdef BOARD_KOMON_KONTER if (loopambil%20==0) { // 5x20 = 100 hitung_rpm(); } data_frek_rpm(); #endif #ifdef BOARD_KOMON_KONTER_3_0 if (loopambil%20==0) { // 5x20 = 100 hitung_rpm(); data_frek_rpm(); } #endif #ifdef PAKAI_I2C #if 0 if (st_tsc) { if (loopambil%500==0) { // 2*250: 500ms = 0.5 detik printf("__detik: %3d\r\n", c++); //baca_register_tsc(); #if 1 if (int_berganti() == 0) { printf("disentuh\r\n"); } else printf("HIGH\r\n"); //vSerialPutString(0, "HIGH\r\n"); #endif } } #endif #if 0 if (st_tsc) { if (xSerialGetChar(1, &c, 0xFFFF ) == pdTRUE) { vSerialPutString(0, "Tombol ditekan = "); xSerialPutChar( 0, (char ) c); vSerialPutString(0, " \r\n"); if ( (char) c == 's') { printf(" Set\r\n"); /* if (i2c_set_register(0x68, 1, 8)) { out(" NO ACK !!\r\n"); } else out(" OK\r\n"); */ if (setup_fma()) { printf(" NO ack !\r\n"); } else printf(" OK ack !\r\n"); } else { printf("====\r\n"); for (i=0; i<16; i++) { if (i == 8) printf("****\r\n"); if (i2c_read_register(0x68, (0x50 + i), &a)) { printf(" Read failed !\r\n"); } else { printf(" Read OK ="); a = a + '0'; printf("%c", (char) a); printf(" \r\n"); } } printf("KEY \r\n"); if (i2c_read_register(0x68, 0x68, &a)) { printf(" Read failed !\r\n"); } else { printf(" Read OK ="); a = a + '0'; printf("%c", (char) a); printf(" \r\n"); } //a = read_key(); //a = a + '0'; //xSerialPutChar( 0, (char ) a); } } } #endif #endif #ifdef PAKAI_GPIO_DIMMER //remangkan(); /* loop_pwm++; #ifdef DEBUG_PWM_GPIO if (loop_pwm>500) { loop_pwm=0; blink_pwm=1-blink_pwm; if (blink_pwm) { FIO1SET = BIT(30); } else { FIO1CLR = BIT(30); } } #endif //*/ #endif } #ifdef PAKAI_GPS deinit_gps(); #endif }
/* Described at the top of this file. */ void BluetoothModemTask( void *pvParameters ) { char cChar; /* Just to avoid compiler warnings. */ ( void ) pvParameters; /* Initialise COM0, which is USART1 according to the STM32 libraries. */ lCOMPortInit( comBTM, mainBAUD_RATE ); /* Reset BTM */ #if 0 GPIO_ResetBits(BTM_Reset_Port, BTM_Reset_Pin); vTaskDelay( ( TickType_t ) 10 / portTICK_PERIOD_MS ); GPIO_SetBits(BTM_Reset_Port, BTM_Reset_Pin); #endif // do { } while (1); // const char *atEscape = "^^^"; const char *atEscapeChar = "^"; const char *atEOL = "\r"; const char *atTest = "AT\r"; // after-reset condition: give the BT module some time to init itself. vTaskDelay( ( TickType_t ) 1000 / portTICK_PERIOD_MS ); do { #if 1 // Before the escape sequence there must be silence for 1s vTaskDelay( ( TickType_t ) 1200 / portTICK_PERIOD_MS ); lSerialPutString( comBTM, atEscapeChar, strlen(atEscapeChar) ); vTaskDelay( ( TickType_t ) 120 / portTICK_PERIOD_MS ); lSerialPutString( comBTM, atEscapeChar, strlen(atEscapeChar) ); vTaskDelay( ( TickType_t ) 120 / portTICK_PERIOD_MS ); lSerialPutString( comBTM, atEscapeChar, strlen(atEscapeChar) ); // After the escape sequence there must be silence for 1s vTaskDelay( ( TickType_t ) 1200 / portTICK_PERIOD_MS ); #endif LEDs_Set(LED0, LED_INTENS_0, LED_INTENS_100, LED_INTENS_0); // Send end of line lSerialPutString( comBTM, atEOL, strlen(atEOL) ); // wait a little bit vTaskDelay( ( TickType_t ) 100 / portTICK_PERIOD_MS ); // empty input buffer usartDrainInput(comBTM); /* this drains possible 'ERROR 05' status */ // vTaskDelay( ( TickType_t ) 10 / portTICK_PERIOD_MS ); // Send plain AT lSerialPutString( comBTM, atTest, strlen(atTest) ); // vTaskDelay( ( TickType_t ) 20 / portTICK_PERIOD_MS ); // expect "OK\r\n" } while (btmExpectOK()); LEDs_Set(LED0, LED_INTENS_0, LED_INTENS_0, LED_INTENS_100); GPIO_InitTypeDef GPIO_InitStruct; GPIO_InitStruct.GPIO_Pin = GPIO_Pin_2 /*| GPIO_Pin_1*/; GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz; GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init( GPIOA, &GPIO_InitStruct ); do { } while (1); // disable local echo const char *atDisableEcho = "ATE0\r"; lSerialPutString( comBTM, atDisableEcho, strlen(atDisableEcho) ); if (btmExpectOK()) { // failed assert_failed(__FILE__, __LINE__); } const char *atSetDeviceName = "AT*agln=\"PIP-Watch\",0\r\n"; lSerialPutString( comBTM, atSetDeviceName, strlen(atSetDeviceName) ); if (btmExpectOK()) { // failed assert_failed(__FILE__, __LINE__); } const char *atSetPin = "AT*agfp=\"1234\",0\r"; lSerialPutString( comBTM, atSetPin, strlen(atSetPin) ); if (btmExpectOK()) { // failed assert_failed(__FILE__, __LINE__); } const char *atToDataMode = "AT*addm\r"; lSerialPutString( comBTM, atToDataMode, strlen(atToDataMode) ); if (btmExpectOK()) { // failed assert_failed(__FILE__, __LINE__); } /* Try sending out a string all in one go, as a very basic test of the lSerialPutString() function. */ // lSerialPutString( comBTM, pcLongishString, strlen( pcLongishString ) ); int k = 0; char *buf = NULL; for( ;; ) { /* Block to wait for a character to be received on COM0. */ xSerialGetChar( comBTM, &cChar, portMAX_DELAY ); /* Write the received character back to COM0. */ xSerialPutChar( comBTM, cChar, 0 ); if (!buf) { buf = pvPortMalloc(sizeof(char) * 32); #if 0 /* start ADC conversion by software */ // ADC_ClearFlag(ADC1, ADC_FLAG_EOC); ADC_ClearFlag(ADC1, ADC_FLAG_STRT); ADC_Cmd(ADC1, ENABLE); #if 0 ADC_SoftwareStartConvCmd(ADC1, ENABLE); /* wait till the conversion starts */ while (ADC_GetSoftwareStartConvStatus(ADC1) != RESET) { } #endif /* wait till the conversion ends */ while (ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) != SET) { } #endif k = 0; // k = itostr(buf, 32, RTC_GetCounter()); // k = itostr(buf, 32, ADC_GetConversionValue(ADC1)); // k = itostr(buf, 32, vbat_measured); // k = itostr(buf, 32, vbat_percent); // ADC_ClearFlag(ADC1, ADC_FLAG_EOC); } buf[k++] = cChar; if (cChar == '\r' || k >= 30) { buf[k] = '\0'; for (int i = 0; i < k-4; ++i) { if (buf[i] == '*') { /* set time: *<hours><minutes> */ int hours = (buf[i+1]-'0')*10 + (buf[i+2]-'0'); int minutes = (buf[i+3]-'0')*10 + (buf[i+4]-'0'); hours %= 24; minutes %= 60; current_rtime.sec = 0; current_rtime.hour = hours; current_rtime.min = minutes; break; } } if (xQueueSend(toDisplayStrQueue, &buf, 0) == pdTRUE) { // ok; will alloc new buffer buf = NULL; } else { // fail; ignore, keep buffer } // motor demo GPIO_SetBits(GPIOB, 1 << 13); vTaskDelay( ( TickType_t ) 300 / portTICK_PERIOD_MS ); GPIO_ResetBits(GPIOB, 1 << 13); k = 0; xSerialPutChar( comBTM, '\n', 0 ); } } }
static void TaskMonitor(void *pvParameters) // Monitor for Serial Interface { (void) pvParameters; uint8_t *ptr; int32_t p1; // create the buffer on the heap (so they can be moved later). if(LineBuffer == NULL) // if there is no Line buffer allocated (pointer is NULL), then allocate buffer. if( !(LineBuffer = (uint8_t *) pvPortMalloc( sizeof(uint8_t) * LINE_SIZE ))) xSerialPrint_P(PSTR("pvPortMalloc for *LineBuffer fail..!\r\n")); while(1) { xSerialPutChar(&xSerialPort, '>'); ptr = LineBuffer; get_line(ptr, (uint8_t)(sizeof(uint8_t)* LINE_SIZE)); //sizeof (Line); switch (*ptr++) { case 'h' : // help xSerialPrint_P( PSTR("rt - reset maximum & minimum temperatures\r\n") ); xSerialPrint_P( PSTR("t - show the time\r\n") ); xSerialPrint_P( PSTR("t - set the time\r\nt [<year yy> <month mm> <date dd> <day: Sun=0> <hour hh> <minute mm> <second ss>]\r\n") ); break; #ifdef portRTC_DEFINED case 't' : /* t [<year yy> <month mm> <date dd> <day: Sun=0> <hour hh> <minute mm> <second ss>] */ if (xatoi(&ptr, &p1)) { SetTimeDate.tm_year = (uint8_t)p1 + 100; // convert to (Gregorian - 1900) xatoi(&ptr, &p1); SetTimeDate.tm_mon = (uint8_t)p1; xatoi(&ptr, &p1); SetTimeDate.tm_mday = (uint8_t)p1; xatoi(&ptr, &p1); SetTimeDate.tm_wday = (uint8_t)p1; xatoi(&ptr, &p1); SetTimeDate.tm_hour = (uint8_t)p1; xatoi(&ptr, &p1); SetTimeDate.tm_min = (uint8_t)p1; if (!xatoi(&ptr, &p1)) break; SetTimeDate.tm_sec = (uint8_t)p1; xSerialPrintf_P(PSTR("Set: %u/%u/%u %2u:%02u:%02u\r\n"), SetTimeDate.tm_year, SetTimeDate.tm_mon, SetTimeDate.tm_mday, SetTimeDate.tm_hour, SetTimeDate.tm_min, SetTimeDate.tm_sec); if (setDateTimeDS1307( &SetTimeDate ) == pdTRUE) xSerialPrint_P( PSTR("Setting successful\r\n") ); } else { if (getDateTimeDS1307( &xCurrentTempTime.DateTime) == pdTRUE) xSerialPrintf_P(PSTR("Current: %u/%u/%u %2u:%02u:%02u\r\n"), xCurrentTempTime.DateTime.tm_year + 1900, xCurrentTempTime.DateTime.tm_mon, xCurrentTempTime.DateTime.tm_mday, xCurrentTempTime.DateTime.tm_hour, xCurrentTempTime.DateTime.tm_min, xCurrentTempTime.DateTime.tm_sec); } break; #endif case 'r' : // reset switch (*ptr++) { case 't' : // temperature xMaximumTempTime = xCurrentTempTime; xMinimumTempTime = xCurrentTempTime; // Now we commit the time and temperature to the EEPROM, forever... eeprom_update_block(&xMaximumTempTime, &xMaximumEverTempTime, sizeof(xRTCTempArray)); eeprom_update_block(&xMinimumTempTime, &xMinimumEverTempTime, sizeof(xRTCTempArray)); break; default : break; } break; default : break; } // xSerialPrintf_P(PSTR("\r\nSerial Monitor: Stack HighWater @ %u"), uxTaskGetStackHighWaterMark(NULL)); // xSerialPrintf_P(PSTR("\r\nFree Heap Size: %u\r\n"), xPortGetMinimumEverFreeHeapSize() ); // needs heap_1, heap_2 or heap_4 for this function to succeed. } }
/* Send character to second USART with default TIMEOUT */ void vPutCharToUSARTy( unsigned char data ) { xSerialPutChar(serCOM2, data, serNO_BLOCK); }
int fputc(int ch, FILE *f) { xSerialPutChar(0, ch, 0); return ch; }
/* * putchar */ void putchar2(const int fd, const int ch) { xSerialPutChar(0, ch, 1); }