コード例 #1
0
ファイル: i2c.c プロジェクト: aeickho/pix32_uart_demo
/*********************************************************************
* Function:        LDByteWriteI2C()
* Input:		Control Byte, 8 - bit address, data.
* Overview:		Write a byte to low density device at address LowAdd
********************************************************************/
unsigned int LDByteWriteI2C(unsigned char ControlByte, unsigned char LowAdd, unsigned char data)
{
	unsigned int ErrorCode1;
	unsigned int ErrorCode2;

	IdleI2C();						//Ensure Module is Idle	
	StartI2C();						//Generate Start COndition
	WriteI2C(ControlByte);			//Write Control byte
	IdleI2C();
	
	ErrorCode1 = ACKStatus();		//Return ACK Status
	
	WriteI2C(LowAdd);				//Write Low Address
	IdleI2C();

	ErrorCode2 = ACKStatus();		//Return ACK Status

	WriteI2C(data);					//Write Data
	IdleI2C();
	
	StopI2C();						//Initiate Stop Condition
	//EEAckPolling(ControlByte);		//Perform ACK polling
	if(ErrorCode1 == 0) { tfp_printf("ACK 1 not recieved\r\n"); }
	if(ErrorCode2 == 0) { tfp_printf("ACK 2 not recieved\r\n"); }
	//return(ErrorCode);
}
コード例 #2
0
ファイル: nrf52-timer0.c プロジェクト: EarthLord/nrf52DevBase
void printfcomma (uint32_t num) {
    if (num < 1000) {
        tfp_printf ("%d", (int)num);
        return;
    }
    printfcomma (num/1000);
    tfp_printf (",%03d",(int) num%1000);
}
コード例 #3
0
ファイル: td_gpio.c プロジェクト: jeromegros/TD1208
/***************************************************************************//**
 * @brief
 *   GPIO even interrupt handler
 *
 * @details
 *   This function is automatically called by the hardware upon incoming
 *   interrupt generated by an even-numbered GPIO pin.
 ******************************************************************************/
void GPIO_EVEN_IRQHandler(void)
{
	uint32_t flag;
	uint32_t system_mask = TD_GPIO_Hooks[TD_GPIO_SYSTEM_EVEN].mask;
	uint32_t user_mask = TD_GPIO_Hooks[TD_GPIO_USER_EVEN].mask;

	// Get interrupt bits
	flag = GPIO_IntGet() & TD_GPIO_EVEN_MASK & GPIO_IntGetEnabled();

	// Acknowledge IRQ.
	// We acknowledge all IRQ read, for this IRQ (EVEN) and enabled
	// even if theses IRQ are not used (otherwise, it will infinitely reenter in this IRQ)
	GPIO_IntClear(flag);
#ifdef WAKE_MAIN_LOOP_DEBUG
	tfp_printf("IO:0x%08X\r\n");
#endif
	// System hook set on odd IRQ
	if (TD_GPIO_Hooks[TD_GPIO_SYSTEM_EVEN].callback && (flag & system_mask)) {

		// Call the IRQ hook
		TD_GPIO_Hooks[TD_GPIO_SYSTEM_EVEN].callback(flag & system_mask);

		// Remember that this interrupt source has been processed
		flag &= ~system_mask;
		TD_WakeMainLoop();
	}

	// User hook on even IRQ
	if (TD_GPIO_Hooks[TD_GPIO_USER_EVEN].callback && (flag & user_mask)) {

		// Call the IRQ hook
		TD_GPIO_Hooks[TD_GPIO_USER_EVEN].callback(flag & user_mask);
		TD_WakeMainLoop();
	}
}
コード例 #4
0
ファイル: tfec3_tools.c プロジェクト: aeickho/pix32_uart_demo
static void
print_frame (const struct frame *pf)
{
  int j;
  const char *p;
  tfp_printf ("MID=%08X, [", pf->mid);
  p = (const char *) pf->fragmentdata;
  for (j = 0; j < BYTES_PER_FRAGMENT; ++j)
    {
      if (32 <= p[j] && p[j] < 127)
	tfp_printf ("%c", p[j]);
      else
	tfp_printf (".");
    }
  tfp_printf ("], METAD=%04X, CRC16=%04X\n\r", pf->metad, pf->crc16);
}
コード例 #5
0
ファイル: td_spi.c プロジェクト: jeromegros/TD1208
/***************************************************************************//**
 * @brief
 *   Dump current lock queue
 ******************************************************************************/
void TD_SPI_LockDump(void)
{
	uint8_t i,bus;

	for (bus = 0; bus < MAX_SPI_BUS; bus++) {
		tfp_printf("Locked byid:%d cnt:%d\r\n", SPI[bus].lock_id, SPI[bus].lock);
		tfp_printf("SPI Lock Dump, bus:%d bottom:%d top:%d\r\n", bus, SPI[bus].bottom, SPI[bus].top);
		for (i = 0; i < MAX_LOCKED_CALLBACK; i++) {

#ifdef SPI_DEBUG_STAMP
			tfp_printf("Bus CB %d:0x%08X Lock stamp:%d\r\n", i, SPI[bus].cb[i], SPI[bus].lock_stamp[i]);
#else
			tfp_printf("Bus CB %d:0x%08X \r\n", i, SPI[bus].cb[i]);
#endif

		}
	}
}
コード例 #6
0
ファイル: cmd.c プロジェクト: graugans/stm32f072-template
void cmd_display_banner()
{
    tfp_printf("\r\n");
    tfp_printf("%s","***************************************\r\n");
    tfp_printf("BUILD DATE        : %s\r\n",__DATE__);
    tfp_printf("BUILD TIME        : %s\r\n",__TIME__);
    tfp_printf("STM32 HAL version : 0x%08X\r\n",HAL_GetHalVersion());
    tfp_printf("STM32 Rev. ID     : 0x%08X\r\n",HAL_GetREVID());
    tfp_printf("STM32 Dev. ID     : 0x%08X\r\n",HAL_GetDEVID());
    tfp_printf("%s\r\n",cmd_banner);
}
コード例 #7
0
ファイル: at_parse.c プロジェクト: jeromegros/TD1208
/***************************************************************************//**
 * @brief
 *   Output an AT string according to a format.
 *
 * @note
 *   This function pre-pend the required line termination depending on the AT
 *   parser verbosity flag, and should be called for each new string output
 *   sequence.
 *   Each subsequent string output should then use tfp_printf().
 *
 * @param[in] fmt
 *   Pointer to format string in printf format.
 *
 * @param[in] ...
 *   Number and types of arguments according to the format string.
 ******************************************************************************/
void AT_printf(char *fmt, ...)
{
	va_list va;

	va_start(va, fmt);
	if (AT_verbose == true) {
		tfp_printf("\r\n");
	}
	tfp_vprintf(fmt, va);
	va_end(va);
}
コード例 #8
0
ファイル: cmd.c プロジェクト: graugans/stm32f072-template
void cmd_handler()
{
    unsigned char c = 0x00;
    if(HAL_OK ==  HAL_UART_Receive(&huart1, &c, 1, 100))
    {
        switch (c)
        {
        case '\r':
            // terminate the msg and reset the msg ptr. then send
            // it to the handler for processing.
            *msg_ptr = '\0';
            tfp_printf("\r\n");
            cmd_parse((char *)msg);
            msg_ptr = msg;
            break;

        case '\b':
            // backspace
            tfp_printf("%c",c);
            if (msg_ptr > msg)
            {
                msg_ptr--;
            }
            break;

        default:
            // normal character entered. add it to the buffer
            tfp_printf("%c",c);
            *msg_ptr++ = c;
            break;
        }
    }
    else
    {
        tfp_printf("%s","timeout occurred");
        cmd_display_prompt();
    }
}
コード例 #9
0
ファイル: hal.c プロジェクト: liuxizhen2009/zlggui
/*******************************
**函数名:ChipHalInit()
**功能:片内硬件初始化
*******************************/
void  ChipHalInit(void)
{
	//初始化时钟源
	RCC_Configuration();
	
	//初始化GPIO
	GPIO_Configuration();
	//初始化串口
	USART_Configuration();
	init_printf(printf_buf,uart1_putc);
	tfp_printf("tfp_printf Inital over\n");

	TIMER_Configuration();

	//初始化中断,在ucos启动后执行,其中包含两步,1,分配中断优先级,2,使能中断
	//NVIC_Configuration();

//	OLED_Configuration();
}
コード例 #10
0
ファイル: td_main.c プロジェクト: jeromegros/TD1208
/***************************************************************************//**
 * @brief
 *   Main function for the TDxxxx RF modules.
 *
 * @details
 *   This function performs all the required initialization for the TDxxxx
 *   RF modules before calling a user supplied function to perform the user
 *   initialization.
 *   This function then enter an infinite loop going into sleep mode waiting
 *   for an interrupt, and calls a user supplied function upon wake-up.
 *
 * @note
 *   If you use this main() function, you must provide 2 functions
 *   - TD_USER_Setup(), which will be called once at startup
 *   - TD_SSER_Loop(), which will be called after waking up by an event
 *   If you provide your own main() function, it will take precedence over this
 *   one, which is completely possible. However, using the library main()
 *   function as a template for your implementation is recommended.
 *
 * @note
 *   This function never returns.
 ******************************************************************************/
int main(void)
{
	// Workarounds for chip errata
	CHIP_Init();

#ifdef EARLY_SERIAL_DEBUG
	BITBAND_Peripheral(&(CMU ->HFPERCLKDIV), (cmuClock_HFPER >> CMU_EN_BIT_POS) & CMU_EN_BIT_MASK, 1);
	BITBAND_Peripheral(&(CMU ->HFPERCLKEN0), ((cmuClock_GPIO) >> CMU_EN_BIT_POS) & CMU_EN_BIT_MASK, 1);
	CMU_ClockSelectSet(cmuClock_LFB, cmuSelect_CORELEDIV2);
	CMU_ClockDivSet(cmuClock_LEUART0, cmuClkDiv_4);

	// Enable the LEUART0 clock
	CMU_ClockEnable(cmuClock_LEUART0, true);
	init_printf(TD_UART_Init(115200, true, false),
				TD_UART_Putc,
				TD_UART_Start,
				TD_UART_Stop);
	tfp_printf("--BOOT %s--\r\n", __TIME__);
#endif

	EARLY_DEBUG_PRINTF("TD_BOOT_Init(0x%08X)\r\n", TD_BOOT_Handler);
	if (TD_BOOT_Handler) {
		TD_BOOT_Handler(CONFIG_PRODUCT_LED_POLARITY, CONFIG_PRODUCT_TYPE);
	}

	// Initialize the clock Management Unit
	EARLY_DEBUG_PRINTF("TD_CMU_Init\r\n");
	TD_CMU_Init(true);

	// Initialize the RTC clock
	EARLY_DEBUG_PRINTF("TD_RTC_Init\r\n");
	TD_RTC_Init(0);

	// Initialize GPIOs
	EARLY_DEBUG_PRINTF("TD_GPIO_Init\r\n");
	TD_GPIO_Init();

	// Initialize SigFox (can be bypassed by : TD_SIGFOX_REMOVE_CODE)
	EARLY_DEBUG_PRINTF("TD_SIGFOX_Init\r\n");
	if (TD_SIGFOX_Init) {
		TD_SIGFOX_Init(true);
	}

	// Initialize Scheduler
	EARLY_DEBUG_PRINTF("TD_SCHEDULER_Init\r\n");
	TD_SCHEDULER_Init();

	// Call user setup function
	EARLY_DEBUG_PRINTF("TD_USER_Setup\r\n");
	TD_USER_Setup();

	EARLY_DEBUG_PRINTF("Entering Main Loop ...\r\n");

	// Main idle loop
	while (true) {

		// Prevent Exception and Interrupt from calling handler
		__set_PRIMASK(1);

		// Here:
		//  with "while" : while no background task should be called
		//                 all IRQs (or main loop) function that wanted main loop process MUST call TD_WakeMainLoop();
		//  with "if"    : if no background task should be called
		//                 all IRQs taken when in sleep mode, do a background loop
		//				   all function that wanted accurate main loop process MUST call TD_WakeMainLoop();

		if (!BackgroundRoundWanted) {

			// Go into EM2 sleep mode until an event occurs, exception/interrupt are masked
			TD_RTC_Sleep();

			// Allow exception/interrupts to call their handlers
			__set_PRIMASK(0);

			// Interrupt execution will take place at this stage

			// Now Prevent Exception and Interrupt from calling handler
			__set_PRIMASK(1);
		}

		// Clear flag. We will always do a round at this point, no sync needed
		BackgroundRoundWanted = false;

		// Allow exception/interrupts to call their handlers
		__set_PRIMASK(0);

		// Scheduler process
		TD_SCHEDULER_Process();

		// Call user loop function
		TD_USER_Loop();

		// RTC Process
		TD_RTC_Process();
	}
}
コード例 #11
0
ファイル: cmd.c プロジェクト: graugans/stm32f072-template
void cmd_display_unknown()
{
    tfp_printf("%s\r\n",cmd_unrecog);
}
コード例 #12
0
ファイル: cmd.c プロジェクト: graugans/stm32f072-template
void cmd_display_prompt()
{
    tfp_printf("%s",cmd_prompt);
}
コード例 #13
0
ファイル: at_parse.c プロジェクト: jeromegros/TD1208
/***************************************************************************//**
 * @brief
 *   AT command parser.
 *
 * @details
 *   This function is the main AT parser function to call when a new input
 *   character is received from the main idle loop.
 *
 *   It will perform lexical analysis, argument collection and call the piece of
 *   code in charge of handling the corresponding AT command.
 *
 * @param[in] c
 *   The new character to parse.
 ******************************************************************************/
void AT_Parse(char c)
{
	uint32_t x, y;
	int extension, i;
	char td_serial[13];

#if defined(__ICCARM__)
	extern unsigned char CSTACK$$Base;
	extern unsigned char CSTACK$$Limit;
	unsigned char *memptr;
#elif defined(__GNUC__)
	extern unsigned char __end;
	extern unsigned char __cs3_region_end_ram;
	unsigned char *memptr;
#endif

	uint8_t token = AT_PARSE;
	int8_t result = AT_OK, extension_result = AT_PARSE;
	uint8_t echo, verbosity, quiet_result, extended_result, banner;
	TD_DEVICE device = {0, 0, 0, 0, 0};
	TD_DEVICE_EXT device_ext = {
		1,
		{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
		{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
	};

	for (extension = 0; extension < AT_EXTENSION_NUMBER; extension++) {
		if (AT_extension[extension] == 0) {
			break;
		}
		if (AT_extension[extension]->tokenize != 0) {
			token = AT_extension[extension]->tokenize(c);
			if (token == AT_ESCAPE) {
				return;
			}
			if (token > AT_BASE_LAST) {
				break;
			}
		}
	}
	if (AT_echo) {
		switch (AT_state) {
		case AT_A:
			if (c == 'A' || c == 'a') {
				tfp_printf("%c", c);
			}
			break;

		case AT_AT:
			if (c == 'T' || c == 't' || c == '/') {
				tfp_printf("%c", c);
			} else {
				tfp_printf("\b \b");
			}
			break;

		default:
			if (c == '\b' || c == 0x7f) {
				if (AT_last > &AT_buffer[2]) {
					tfp_printf("\b \b");
				}
			} else if (c == '\r' || c == '\n') {
				tfp_printf("\r");
			} else {
				tfp_printf("%c", c);
			}
			break;
		}
	}
	if (token == AT_PARSE) {
		token = AT_Tokenize(c, &extension);
	}
	if (token > AT_BASE_LAST && extension < AT_EXTENSION_NUMBER && AT_extension[extension]->parse != 0) {
		extension_result = AT_extension[extension]->parse(token);
		if (extension_result != AT_NOTHING) {
			AT_PrintResult(extension_result);
		}
		return;
	}
	switch (token) {
	case AT_PARSE:
		result = AT_NOTHING;
		break;

	case AT_UNKNOWN:
		result = AT_ERROR;
		break;

	case AT:
		break;

	case AT_DISPLAY_CONFIG:
		for (extension = 0; extension < AT_EXTENSION_NUMBER; extension++) {
			if (AT_extension[extension] == 0) {
				break;
			}
			if (AT_extension[extension]->status != 0) {
				AT_extension[extension]->status(false);
			}
		}
		AT_printf("%s\r\n", CONFIG_MANUFACTURER);
		tfp_printf("Hardware Version: %s\r\n", CONFIG_HARDWARE_VERSION);
		tfp_printf("Software Version: %s\r\n", CONFIG_SOFTWARE_VERSION);
		TD_FLASH_DeviceRead(&device);
		tfp_printf("S/N: %08X\r\n", device.Serial);
		if (TD_FLASH_DeviceReadExtended(&device, &device_ext) == true) {
			for (i = 0; i < 12; i++) {
				td_serial[i] = device_ext.TDSerial[i];
			}
			td_serial[12] = '\0';
			if (td_serial[0] != '?') {
				tfp_printf("TDID: %12s\r\n", td_serial);
			}
		}
		tfp_printf("ACTIVE PROFILE\r\n");
		tfp_printf("E%d V%d Q%d",
				   AT_echo,
				   AT_verbose,
				   AT_quietResult);
		tfp_printf(" X%d S200:%d",
				   AT_extended,
				   AT_banner
				  );
		for (extension = 0; extension < AT_EXTENSION_NUMBER; extension++) {
			if (AT_extension[extension] == 0) {
				break;
			}
			if (AT_extension[extension]->status != 0) {
				AT_extension[extension]->status(true);
			}
		}
		tfp_printf("\r\n");
		break;

	case AT_FACTORY:
		AT_verbose = true;
		AT_extended = true;
		AT_echo = true;
		AT_quietResult = false;
		AT_banner = AT_FORCE_BANNER ? true : false;
		for (extension = 0; extension < AT_EXTENSION_NUMBER; extension++) {
			if (AT_extension[extension] == 0) {
				break;
			}
			if (AT_extension[extension]->init != 0) {
				AT_extension[extension]->init();
			}
		}
		break;

	case AT_GET_BANNER:
		if (AT_argc == 0) {
			AT_printf("%d\r\n", AT_banner);
		} else {
			result = AT_ERROR;
		}
		break;

	case AT_HARDWARE_REV:
		if (AT_argc == 0) {
			AT_printf("%s\r\n", CONFIG_HARDWARE_VERSION);
		} else {
			result = AT_ERROR;
		}
		break;

	case AT_HELP:
		if (AT_argc == 0) {
			AT_printf("%s", AT_help);
			for (extension = 0; extension < AT_EXTENSION_NUMBER; extension++) {
				if (AT_extension[extension] == 0) {
					break;
				}
				if (AT_extension[extension]->help != 0) {
					AT_extension[extension]->help();
				}
			}
		} else {
			result = AT_ERROR;
		}
		break;

	case AT_MANUFACTURER:
		if (AT_argc == 0) {
			AT_printf("%s\r\n", CONFIG_MANUFACTURER);
		} else {
			result = AT_ERROR;
		}
		break;

	case AT_PRODUCT_REV:
		if (AT_argc == 0) {
			if (TD_FLASH_DeviceRead(&device)) {
				AT_printf("%02X\r\n", device.ProdResult);
			} else {
				result = AT_ERROR;
			}
		} else {
			result = AT_ERROR;
		}
		break;

	case AT_QUERY_BANNER:
		if (AT_argc != 0) {
			result = AT_ERROR;
		} else {
			AT_printf("0..1\r\n");
		}
		break;

	case AT_RELEASE_DATE:
		if (AT_argc == 0) {
			AT_printf("%s\r\n", CONFIG_RELEASE_DATE);
		} else {
			result = AT_ERROR;
		}
		break;

	case AT_RESET:
		if (AT_argc == 0) {
			AT_PrintResult(result);
			TD_RTC_Delay(T100MS);
			NVIC_SystemReset();
		} else {
			result = AT_ERROR;
		}
		break;

	case AT_SERIAL_NUMBER:
		if (AT_argc == 0) {
			TD_FLASH_DeviceRead(&device);
			AT_printf("%04X\r\n", device.Serial);
			if (TD_FLASH_DeviceReadExtended(&device, &device_ext) == true) {
				for (i = 0; i < 12; i++) {
					td_serial[i] = device_ext.TDSerial[i];
				}
				td_serial[12] = '\0';
				tfp_printf("TDID: %12s\r\n", td_serial);
			}
		} else {
			result = AT_ERROR;
		}
		break;

	case AT_SET_BANNER:
		if (AT_argc == 1) {
			banner = AT_atoll(AT_argv[0]);
			if (banner > 1) {
				result = AT_ERROR;
			} else {
				AT_banner = banner;
			}
		} else {
			result = AT_ERROR;
		}
		break;

	case AT_SET_ECHO:
		if (AT_argc == 0) {
			AT_echo = false;
		} else if (AT_argc == 1) {
			echo = AT_atoll(AT_argv[0]);
			if (echo < 2) {
				AT_echo = echo ? true : false;
			} else {
				result = AT_ERROR;
			}
		} else {
			result = AT_ERROR;
		}
		break;

	case AT_SET_EXTENDED_RESULTS:
		if (AT_argc == 0) {
			AT_extended = true;
		} else if (AT_argc == 1) {
			extended_result = AT_atoll(AT_argv[0]);
			if (extended_result < 2) {
				AT_extended =  extended_result ? true : false;
			} else {
				result = AT_ERROR;
			}
		} else {
			result = AT_ERROR;
		}
		break;

	case AT_SET_QUIET:
		if (AT_argc == 0) {
			AT_quietResult = true;
		} else if (AT_argc == 1) {
			quiet_result = AT_atoll(AT_argv[0]);
			if (quiet_result < 2) {
				AT_quietResult = quiet_result ? true : false;
			} else {
				result = AT_ERROR;
			}
		} else {
			result = AT_ERROR;
		}
		break;

	case AT_SET_VERBOSITY:
		if (AT_argc == 0) {
			AT_verbose =  true;
		} else if (AT_argc == 1) {
			verbosity = AT_atoll(AT_argv[0]);
			if (verbosity < 2) {
				AT_verbose = verbosity ? true : false;
			} else {
				result = AT_ERROR;
			}
		} else {
			result = AT_ERROR;
		}
		break;

	case AT_SOFTWARE_REV:
		if (AT_argc == 0) {
			AT_printf("%s\r\n", CONFIG_SOFTWARE_VERSION);
		} else {
			result = AT_ERROR;
		}
		break;

#if defined(__ICCARM__)
	case AT_FREE_STACK:
		memptr = &CSTACK$$Base;
		while (memptr < &CSTACK$$Limit) {
			if (*memptr++ != 0xCD) {
				break;
			}
		}
		AT_printf("Free Stack: %d bytes", memptr - &CSTACK$$Base);
		break;
#elif defined(__GNUC__)
	case AT_FREE_STACK:
		memptr = &__end;
		while (memptr < &__cs3_region_end_ram) {
			if (*memptr++ != 0xCD) {
				break;
			}
		}
		AT_printf("Free Stack: %d bytes", memptr - &__end);
		break;
#endif

	case AT_UNIQUE_ID:
		if (AT_argc == 0) {
			x = DEVINFO->UNIQUEH;
			y = DEVINFO->UNIQUEL;
			AT_printf("%08X%08X\r\n", x, y);
		} else {
			result = AT_ERROR;
		}
		break;

	case AT_WRITE_CONFIG:
		if (AT_argc == 0) {
			AT_SavePersistBuffer();
			TD_FLASH_WriteVariables();
		} else {
			result = AT_ERROR;
		}
		break;

	default:
		result = AT_ERROR;
		break;
	}
	AT_PrintResult(result);
}
コード例 #14
0
ファイル: at_parse.c プロジェクト: jeromegros/TD1208
/***************************************************************************//**
 * @brief
 *   Tokenize a character for Hayes AT commands.
 *
 * @details
 *   This function implements the AT lexical analyzer by transforming the
 *   received characters into recognized tokens.
 *
 * @param[in] c
 *   The character to parse.
 *
 * @param[out] extension
 *   Pointer to the AT extension number that will be filled in with the
 *   extension that implement the recognized token.
 *
 * @return
 *   Returns:
 *   - the command token if found
 *   - AT_PARSE to continue parsing
 *   - AT_UNKNOWN if no corresponding command has been found
 ******************************************************************************/
uint8_t AT_Tokenize(char c, int *extension)
{
	char *s, *d;
	const AT_command_t *command;

	if (c == '/' && AT_last == &AT_buffer[1] && AT_buffer[0] == 'A') {

		// Replay last command
		for (s = AT_previousCommand, d = AT_buffer; *s;) {
			*d++ = *s++;
		}
		*d = '\0';
		c = '\r';
		AT_last = AT_buffer;
		AT_state = AT_A;
	} else {
		if (c >= 'a' && c <= 'z') {

			// Convert lower-case to upper-case
			c -= 'a' - 'A';
		}
		if (AT_last >= &AT_buffer[AT_BUFFER_SIZE]) {

			// AT command buffer overflow
			goto error;
		} else {
			switch (AT_state) {
			case AT_A:
				if (c != 'A') {
					return AT_PARSE;
				}
				AT_state = AT_AT;
				*AT_last++ = 'A';
				*AT_last = '\0';
				return AT_PARSE;

			case AT_AT:
				if (c != 'T') {
					AT_state = AT_A;
					AT_last = &AT_buffer[0];
					return AT_PARSE;
				}
				AT_state = AT_COMMAND;
				*AT_last++ = 'T';
				*AT_last = '\0';
				return AT_PARSE;
				break;

			case AT_COMMAND:
				if (c == '\r' || c == '\n') {

					// Command terminator, save command (if any) for replay
					for (s = AT_buffer, d = AT_previousCommand; s <= AT_last;) {
						*d++ = *s++;
					}
					*d = '\0';
					c = '\r';
					AT_last = AT_buffer;
					AT_state = AT_A;
					break;
				} else if (c == '\b' || c == 0x7f) {
					if (AT_last > &AT_buffer[2]) {

						// Backspace one character
						*(--AT_last) = '\0';
					}
					return AT_PARSE;
				} else if (c == '\0' || c == 0x18) {

					// Cancel command
					if (AT_echo) {
						for (; AT_last != AT_buffer; AT_last--) {
							tfp_printf("\b \b");
						}
					}
					AT_buffer[0] = '\0';
					c = '\0';
					AT_state = AT_A;
					return AT_PARSE;
				} else {
					*AT_last++ = c;
					*AT_last = '\0';
					return AT_PARSE;
				}
				break;

			default:
				AT_state = AT_A;
				return AT_PARSE;
			}
		}
	}

	// Command lookup
	for (*extension = 0; *extension <= AT_EXTENSION_NUMBER; (*extension)++) {
		if (*extension == AT_EXTENSION_NUMBER || AT_extension[*extension] == 0) {
			command = AT_commands;
		} else if (AT_extension[*extension]->commands != 0) {
			command = AT_extension[*extension]->commands;
		} else {
			continue;
		}
		for (; command->token; command++) {
			for (s = command->ascii, d = AT_buffer; *s; s++, d++) {
				if (*s != *d) {
					break;
				}
			}
			if (*s == '\0') {
				if (command->token == AT && AT_buffer[2] != '\0') {

					// Matched "AT", but have some extra characters behind => unknown command
					break;
				}

				// Found a matching command, parse the arguments (if any)
				AT_argc = 0;
				while (*d != '\0') {
					if (AT_argc < AT_MAX_ARGS) {
						AT_argv[AT_argc++] = d;
					} else {

						// Argument count overflow
						goto error;
					}
					while (*d != '\0' && *d != ',') {
						d++;
					}
					if (*d == ',') {
						*d++ = '\0';
					}
				}
				return command->token;
			}
		}
	}

	// No matching command found
error:
	AT_last = AT_buffer;
	return AT_UNKNOWN;
}
コード例 #15
0
ファイル: td_gpio.c プロジェクト: jeromegros/TD1208
/***************************************************************************//**
 * @brief
 *   Dump all GPIO configuration
 ******************************************************************************/
void TD_GPIO_Dump(void)
{
	uint8_t i, j, md;
	uint64_t mode;
	uint32_t d;
	char *txt;
	for (i = 0; i < 6; i++) {
		tfp_printf("--Port%c--\r\n", 'A' + i);
		mode = GPIO->P[i].MODEL;
		mode = mode | (((uint64_t)GPIO->P[i].MODEH) << 32);
		d = GPIO->P[i].DOUT;
		for (j = 0; j < 16; j++) {
			md = mode & 0xF;
			mode = mode >> 4;
			switch (md) {
			case 0:
				txt = "DIS";
				break;
			case 1:
				txt = "IN";
				break;
			case 2:
				txt = "INP";
				break;
			case 3:
				txt = "INPF";
				break;
			case 4:
				txt = "OUT";
				break;
			case 5:
				txt = "OUTD";
				break;
			case 6:
				txt = "WOR";
				break;
			case 7:
				txt = "WORP";
				break;
			case 8:
				txt = "WAN";
				break;
			case 9:
				txt = "WANF";
				break;
			case 10:
				txt = "WANP";
				break;
			case 11:
				txt = "WANPF";
				break;
			case 12:
				txt = "WAND";
				break;
			case 13:
				txt = "WANDF";
				break;
			case 14:
				txt = "WANDP";
				break;
			case 15:
				txt = "WANDPF";
				break;
			}
			tfp_printf("%01X)%6s:%d|  ", j, txt, d & 1);
			d >>= 1;
			if ((j & 3) == 3) {
				tfp_printf("\r\n");
			}
		}
	}
}
コード例 #16
0
ファイル: tfec3_tools.c プロジェクト: aeickho/pix32_uart_demo
int
sendblock (void)
{

  int n, r, i, ret;
  char msg[300];
  static int cnt = 0;

  tfp_sprintf (msg,
	       "Nachricht %d na da will ich mal sehen                   Hallo Du da!!!  nur ein kleiner Test ...............HASE \
	       Test........Bla-______---_--_-_-_-_-_-___-_\
	       hallo du da next warum ist das alles so einfach das finde ich lustig",
	       cnt++);




  tfp_printf ("Preparing a message for sending...\n\r");
  n = strlen (msg) + 1;		/* message size including null terminator */
  r = 40;			/* shoot for 20% redundancy */
  r = 80;
t[0] = ReadCoreTimer ();
 
  r = prepare_send_message (n, msg, r);
t[1] = ReadCoreTimer ();
printf("time for prepare_send_message %d ns",(t[1]-t[0])*50);  
  
   tfp_printf ("number of frames for message = %d\n\r", send_count);
  tfp_printf ("           actual redundancy = %d%%\n\r", r);

  for (i = 0; i < send_count; ++i)
    {
      print_frame (tx_frame + i);
    }

  tfp_printf ("send frames: \n\r");

  t[0] = ReadCoreTimer ();

////////////////////////////////////

// 

//tx_frame->fragmentdata [2]=33;
//(tx_frame+1) ->fragmentdata [2]=33;

// static struct frame tx_frame[FRAME_BUFF_SIZE];

// void nrf_send_frames (uint8_t  ** frame, int frames)

  printf ("-> %x \n\r", tx_frame);
  printf ("-> %x \n\r", tx_frame + 1);
  printf ("-> %c %c %c \n\r", tx_frame[0], tx_frame[1], tx_frame[2]);
  printf ("xxxxxxxxxxxxx\n\r");
  delay_ms (100);

  nrf_send_frames (tx_frame, send_count);

// nrf_send_frame (uint8_t * frame, int mode)

/*
  for (i = 0; i < send_count; ++i)
    {
      t[i + 1] = ReadCoreTimer ();
      nrf_send_frame ((uint8_t *) (tx_frame + i), 0);
      if (i % 4 == 0)
	{
	  delay_ms (5);
	}

    }
*/

///***************************

  for (i = 0; i < send_count; ++i)
    {
      print_frame (tx_frame + i);
    }


  return 0;
}