int CharToHex(const char ch)
{
const char Hex[] = "0123456789ABCDEF";
for (int n = 0; Hex[n]; ++n)
{
if (ch == Hex[n])
{
return n;
}
}
return 0;
}
UINT64 StringToHex(const char* c)
{
UINT64 l = 0;
for (int n = 0; c[n]; ++c)
{
l = l * 16 + CharToHex(c[n]);
}
return l;
}
2012年2月21日 星期二
2012年2月1日 星期三
轉貼 VxWorks thread同步(使用Semaphore)
/* includes */
#include "vxWorks.h"
#include "taskLib.h"
#include "semLib.h"
#include "stdio.h"
/* function prototypes */
void taskOne(void);
void taskTwo(void);
/* globals */
#define ITER 10
SEM_ID semBinary;
int global = 0;
void binary(void)
{
int taskIdOne, taskIdTwo;
/* create semaphore with semaphore available and queue tasks on FIFO basis */
semBinary = semBCreate(SEM_Q_FIFO, SEM_FULL);
/* Note 1: lock the semaphore for scheduling purposes */
semTake(semBinary,WAIT_FOREVER);
/* spawn the two tasks */
taskIdOne = taskSpawn("t1",90,0x100,2000,(FUNCPTR)taskOne,0,0,0,0,0,0,0,0,0,0);
taskIdTwo = taskSpawn("t2",90,0x100,2000,(FUNCPTR)taskTwo,0,0,0,0,0,0,0,0,0,0);
}
void taskOne(void)
{
int i;
for (i=0; i < ITER; i++)
{
semTake(semBinary,WAIT_FOREVER); /* wait indefinitely for semaphore */
printf("I am taskOne and global = %d......................\n", ++global);
semGive(semBinary); /* give up semaphore */
}
}
void taskTwo(void)
{
int i;
semGive(semBinary); /* Note 2: give up semaphore(a scheduling fix) */
for (i=0; i < ITER; i++)
{
semTake(semBinary,WAIT_FOREVER); /* wait indefinitely for semaphore */
printf("I am taskTwo and global = %d----------------------\n", --global);
semGive(semBinary); /* give up semaphore */
}
}
訂閱:
意見 (Atom)
winsock2.h redefined問題
解法: #define _WINSOCKAPI_ // stops windows.h including winsock.h #include #include
-
對了,要跟大家推薦一下新竹的家具行, 當初要添購家具的時候,跟小丸子很努力的找遍新竹的家具行, 新竹市的家具行其實很多,大部分集中在新竹市的經國路, 還有中華路五段這兩個部分,竹北也有不少家具行, 不過我們主要還是找新竹市的, 找來找去,發現其實家具很多都是一模一樣的,應該都...
-
昨天要回新竹的路上,差點A到一臺摩托車, 可以清楚看到路口是綠燈,可是這位老兄,竟然從左方過來要待轉, 旁邊的女騎士也差點A到他,尖叫了一聲... 緊急煞車的同時,第一次感受到ABS做動,還好平安無事... 奉勸大家車子一定要裝行車記錄器阿~
-
前言: 從小就有鼻子過敏的毛病,每到季節轉換或是塵蟎較多的環境, 鼻子就像是水龍頭一樣,噴嚏打的不停,看過了不少醫生, 也做了兩次雷射治療,但效果有限,加上長期的鼻塞, 睡覺時只能靠嘴巴呼吸,也難怪黑眼圈很重...大家都以為我每天熬夜...@@ 這次終於痛定思...