Skip to content

Commit

Permalink
implement Queuewq
Browse files Browse the repository at this point in the history
  • Loading branch information
shin21 committed Apr 14, 2014
1 parent cdf4be4 commit 68cdab2
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 10 deletions.
75 changes: 71 additions & 4 deletions CORTEX_M4F_STM32F407ZG-SK/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "queue.h"
/** @addtogroup Template
* @{
*/
Expand All @@ -43,6 +44,38 @@ EXTI_InitTypeDef EXTI_InitStructure;
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/

xQueueHandle MsgQueue;
uint32_t iii = 1;

void USART1_puts(char* s)
{
while(*s) {
while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
USART_SendData(USART1, *s);
s++;
}
}

void itoa(uint32_t n, uint32_t base) {
volatile portCHAR buf[33] = {0};
volatile portCHAR *p = &buf[32];

if (n == 0)
*--p = '0';
else {
portCHAR *q;
volatile uint32_t num = n;

*--p = '\r';
*--p = '\n';

for (; num; num/=base)
*--p = "0123456789ABCDEF" [num % base];
}

USART1_puts( p );
}

void Init()
{
/*STM_EVAL_PBInit( BUTTON_USER, BUTTON_MODE_GPIO );*/
Expand Down Expand Up @@ -137,25 +170,59 @@ void USART(void)

}






void Task1( void* pvParameters )
{
uint32_t iii = 0;

while( 1 ){
iii++;
while( STM_EVAL_PBGetState( BUTTON_USER ) ){
iii++;
itoa( iii, 10 );
}
itoa( 321, 10 );
}
}


void QTask1( void* pvParameters )
{
uint32_t snd = 100;

while( 1 ){
xQueueSend( MsgQueue, ( uint32_t* )&snd, 0 );
vTaskDelay(1000);
}
}

void QTask2( void* pvParameters )
{
uint32_t rcv = 0;
while( 1 ){
if( xQueueReceive( MsgQueue, &rcv, 100/portTICK_RATE_MS ) == pdPASS && rcv == 100)
{
STM_EVAL_LEDToggle( LED3 );
}
}
}


int
main( void )
{
Init();
EXTILine0_Config();
USART();

MsgQueue = xQueueCreate( 5 , sizeof( uint32_t ) );

xTaskCreate( Task1, (signed char*)"Task1", 128, NULL, tskIDLE_PRIORITY+1, NULL );
xTaskCreate( Task2, (signed char*)"Task1", 128, NULL, tskIDLE_PRIORITY+1, NULL );
// xTaskCreate( QTask1, (signed char*)"Task1", 128, NULL, tskIDLE_PRIORITY+1, NULL );
// xTaskCreate( QTask2, (signed char*)"Task2", 128, NULL, tskIDLE_PRIORITY+1, NULL );

vTaskStartScheduler();
}


2 changes: 1 addition & 1 deletion CORTEX_M4F_STM32F407ZG-SK/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include "FreeRTOS.h"
#include "task.h"

//uint32_t iii;

/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------*/
Expand Down
19 changes: 14 additions & 5 deletions CORTEX_M4F_STM32F407ZG-SK/stm32f4xx_it.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
/*}*/
/*extern uint32_t iii;*/

/*
void USART1_puts(char* s)
{
while(*s) {
Expand Down Expand Up @@ -173,18 +174,26 @@ void itoa(uint32_t n, uint32_t base) {
USART1_puts( p );
}
*/

extern uint32_t iii;

void EXTI0_IRQHandler(void)
{
if( EXTI_GetITStatus( EXTI_Line0 ) != RESET ){

while( 1 ){
if( EXTI_GetITStatus( EXTI_Line0 ) != RESET ){
while(1){
STM_EVAL_LEDToggle( LED4 );
vTaskDelay( 500 );
itoa( 123, 10 );

int j,k;
for(j=0;j<10000;j++){
for(k=0;k<1000;k++){}
}

itoa( iii, 10 );
}
}
EXTI_ClearITPendingBit( EXTI_Line0 );
EXTI_ClearITPendingBit( EXTI_Line0 );
}
/******************************************************************************/
/* STM32F4xx Peripherals Interrupt Handlers */
Expand Down

0 comments on commit 68cdab2

Please sign in to comment.