Tuesday, July 11, 2017

Register Transfer Level Design with Verilog (1) [ebook]

設計程式之所以有趣不外乎是它的千變萬化,同樣的結果卻有不同的寫法。

但這些不同寫法當中也並沒有分誰對誰錯,也沒有制定標準來規範何事該用何解。

這也就是我們設計者的珍貴!!

Screen Shot 2013-01-20 at 9.58.41 PM





[1] Primitive Instantiations

在Verilog中最基本的邏輯閘便稱為Primitive,使用最基本的primitive為基礎來設計別稱Primitive Instantiations。

Screen Shot 2013-01-20 at 3.56.46 PM




[2] Assign Statements

透過Primitive gates在利用assign將結果牽線別有更多變的結果。

Screen Shot 2013-01-20 at 4.05.52 PM



[3] Conditional Expression

顧名思義,就是條件式的表示方法!這也是能將硬邦邦的硬體注入多變思想的刀刃。

Screen Shot 2013-01-20 at 4.04.09 PM



[4] Procedural Blocks

至於這套程序則是非常高接的處理程序,往往是很多Conditional Expression所組成。

Screen Shot 2013-01-20 at 4.04.28 PM




所有教課書不往往儘說這些道理,但這些確有哪些不同呢?其實在我的見解就如下

[1]就是利用最基本的邏輯閘組成所需的系統。

[2]的概念就與數學相似,利用運算元來表示系統。

[3]條件是就有如黑盒子概念,拿數位邏輯的概念來說,就是將系統使用Boolean Expressions來呈現,輸入與輸出的關係就有如條件班達成。

[4]則是透過程序流程來分析結果,當然所耗的資源都不盡相同。

Reference

<1>Verilog Digital System Design - RT Level Synthesis, Testbench and Verification

Monday, August 15, 2016

RF in IOT

      最近開始研究起RF通訊這方面的資訊,目前大家都鎖定在IOT這個區塊,各家大廠都推出屬於自己的協定來因應產品需求,好比Apple Homekit,Google Brillo。但由於各家都有各自條件優勢,所以對於這整塊市場還在群雄爭霸當中。
       基本上經過了解後發現這幾項技術還在開發階段,所以目前相關的文獻跟發展都還沒有到穩定成熟的狀況,也就是代表還有很多可以值得細玩的技術,此外切入門檻相對許多大系統這是比較容易許多,不過,卻可以增加不同產業的產品功能性,就好比醫療產業(透過藍芽或wifi做資料顯示傳送,省去許多空間)。
      技術層面來看硬體不外乎的就是在意耗電流以及RF的電路,至於訊號是屬於FSK, GSK, PSK, QPSK, DQPSK[5],就不列入細部考慮,畢竟這是一項時間,空間,能量的平衡槓桿,沒有對與錯沒有是與非,在應用的角度上會有各自的優勢,然而軟體就是需要瞭解藍芽的協定或是其他協定(Thread)[4],但以目前IOT所要結合網際網路的趨勢是在IPV6,主要是在於它相較TCP/IP,IPV4來說有更多的位址可以使用,但目前卻還有存在相對的風險[3]。
       其實在軟體方面有許多很好的切入點及應用是值得深入研究發展。

Reference
[1]http://www.nordicsemi.com/eng/About-us
[2]NordicSemi-eBook-IoT-Opportunity-Risks-Strategy
[3]http://blog.nordicsemi.com/getconnected/is-the-internet-ready-for-iot
[4]http://www.2cm.com.tw/markettrend_content.asp?sn=1512030005
[5]https://en.wikipedia.org/wiki/List_of_2.4_GHz_radio_use

Wednesday, February 11, 2015

Saturday, December 27, 2014

Getopt

#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int
main (int argc, char **argv)
{
int aflag = 0;
int bflag = 0;
char *cvalue = NULL;
int index;
int c;

opterr = 0;
  while ((c = getopt (argc, argv, "abc:")) != -1)
switch (c)
{
case 'a':
aflag = 1;
break;
case 'b':
bflag = 1;
break;
case 'c':
cvalue = optarg;
break;
case '?':
if (optopt == 'c')
fprintf (stderr, "Option -%c requires an argument.\n", optopt);
else if (isprint (optopt))
fprintf (stderr, "Unknown option `-%c'.\n", optopt);
else
fprintf (stderr,
"Unknown option character `\\x%x'.\n",
optopt);
return 1;
default:
abort ();
}
  printf ("aflag = %d, bflag = %d, cvalue = %s\n",
aflag, bflag, cvalue);

for (index = optind; index < argc; index++)
printf ("Non-option argument %s\n", argv[index]);
return 0;
}

Here are some examples showing what this program prints with different combinations of arguments:

% testopt
aflag = 0, bflag = 0, cvalue = (null)

% testopt -a -b
aflag = 1, bflag = 1, cvalue = (null)

% testopt -ab
aflag = 1, bflag = 1, cvalue = (null)

% testopt -c foo
aflag = 0, bflag = 0, cvalue = foo

% testopt -cfoo
aflag = 0, bflag = 0, cvalue = foo

% testopt arg1
aflag = 0, bflag = 0, cvalue = (null)
Non-option argument arg1

% testopt -a arg1
aflag = 1, bflag = 0, cvalue = (null)
Non-option argument arg1

% testopt -c foo arg1
aflag = 0, bflag = 0, cvalue = foo
Non-option argument arg1

% testopt -a -- -b
aflag = 1, bflag = 0, cvalue = (null)
Non-option argument -b

% testopt -a -
aflag = 1, bflag = 0, cvalue = (null)
Non-option argument -

An option character in this string can be followed by a colon (‘:’) to indicate that it takes a required argument. If an option character is followed by two colons (‘::’), its argument is optional.


This optarg is set by getopt to point at the value of the option argument, for those options that accept arguments.


 


Reference


[1] http://www.gnu.org/software/libc/manual/html_node/Using-Getopt.html


[2] http://www.gnu.org/software/libc/manual/html_node/Example-of-Getopt.html


[3] http://en.wikipedia.org/wiki/Getopt

Wednesday, December 24, 2014

MAKEFILE built-in function

How to implement built-in function as below

Text-processing function

https://www.gnu.org/software/make/manual/html_node/Text-Functions.html#Text-Functions

$(patsubst %.c,%.o,x.c.c bar.c)

Result: ‘x.c.o bar.o’

$(sort foo bar lose)

Result:‘bar foo lose’

$(word 2, foo bar baz)

Result:‘bar’

Filename manipulate function

https://www.gnu.org/software/make/manual/html_node/File-Name-Functions.html

$(dir src/foo.c hacks)

Result:‘src/ ./’

$(notdir src/foo.c hacks)

Result:‘foo.c hacks’

$(suffix src/foo.c src-1.0/bar.c hacks)

Result:‘.c .c’

$(addprefix src/,foo bar)

Result:‘src/foo src/bar’

Friday, December 19, 2014

linux command – grep

 

 

dmesg | grep -i usb

[option]

“-i” ignore the case.

cat /var/log/dmesg | less

 

 

Reference

http://manpages.ubuntu.com/manpages/utopic/man1/dmesg.1.html

Monday, December 1, 2014

Understanding lvalues and rvalues in C and C++

lvalues stands for left-values and rvalues is right-values[2]

lvalue is an expression referring to an object

Data storage for rvalues describes in ASM.[1]

mov #1, n

we could see 1 is a contant number, not a variable. the rvalue 1 never appears as an object in the data space.

 

Reference

[1] http://ieng9.ucsd.edu/~cs30x/Lvalues%20and%20Rvalues.htm

[2] http://www.c4learn.com/c-programming/c-r-value-expression/

[3] http://eli.thegreenplace.net/2011/12/15/understanding-lvalues-and-rvalues-in-c-and-c experitment

Sunday, November 30, 2014

Array initialization

Basic initialization
int myArray[10] = { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 };
other syntax 
int myArray[10] = { [4] = 5, [2] = 5 }; 
is equivalent to
int myArray[6] = { 0, 0, 5, 0, 5, 0 };
initialize a range of elements to the same value
int myArray[10] = {[0 ... 9] = 5};
 
Elements with missing values will be initialized to 0:
int myArray[10] = { 1, 2 }; // initialize to 1,2,0,0,0...

So this will initialize all elements to 0:
int myArray[10] = { 0 }; // all elements 0(only for Zero initial)

Remember that objects with static storage duration will initialize to 0 if no initializer is specified:
static int myArray[10]; // all elements 0

In C++, an empty initialization list will also initialize every element to 0. This is not allowed with C:
int myArray[10] = {}; // all elements 0 in C++


And that "0" doesn't necessarily mean "all-bits-zero", so using the above is better and more portable than memset(). (Floating point values will be initialized to +0, pointers to null value, etc.)
Reference
[1] http://stackoverflow.com/questions/201101/how-to-initialize-an-array-in-c
[2] https://gcc.gnu.org/onlinedocs/gcc/Designated-Inits.html
[3] http://www.lemoda.net/c/array-initialization/ (experiment)






Sunday, November 16, 2014

Inline Functions versus Macros

add my commend into the content

  1. Inline functions follow all the protocols of type safety enforced on normal functions.
    • more safe then the macro, especially, for the type defination.
    • for the type check, macro is checked by prepocessor, and inline functions is checked by compilar.
  2. Inline functions are specified using the same syntax as any other function except that they include the inline keyword in the function declaration.
    • only difference is keyword “inline”
  3. Expressions passed as arguments to inline functions are evaluated once. In some cases, expressions passed as arguments to macros can be evaluated more than once.
    • more variable for arguments
  4. There is no risk if called multiple times. But there is risk in macros which can be dangerous when the argument is an expression.
  5. functions can include multiple lines of code without trailing backlashes.
  6. functions have thier own scope for variables and they can return a value.
  7. debuging

Reference

[1] http://msdn.microsoft.com/en-us/library/bf6bf4cf.aspx

[2] http://www.thegeekstuff.com/2013/04/c-macros-inline-functions/

Friday, November 14, 2014

function and function-like macro

if we use the same name for those things. avoid the prepocessor will expand the function first, we usaully add parenthese to prevent.

simple example

#include <stdio.h>
#define test(x) __test(x)
#define __test(x) printf("\n%d\n", x + 1);

int test(int x);
#undef test

int main()
{
    test(1);
}
int (test)(int x)
{
    printf("\n%d\n", x);
}

Referemce

http://stackoverflow.com/questions/13600790/what-do-the-parentheses-around-a-function-name-mean

Friday, November 7, 2014

Thursday, November 6, 2014

CRP

CRP(Code read protection) is a way to avoid someone to get code from flash.

CRP

In C, Keyword “static”

 
#include <stdio.h>

int global_var; //statically allocated as a global variable
static int static_var; //statically allocated but only accessible within file

void my_function(void){
static int my_static = 0; //statically allocated, accessible within my_function
int my_stack = 0; //allocated on the stack

printf("my_static:%d, my_stack:%d\n", my_static, my_stack);
my_stack++;
my_static++;
}
Answer: 

my_static:0, my_stack:0
my_static:1, my_stack:0
my_static:2, my_stack:0
my_static:3, my_stack:0
my_static:4, my_stack:0
Reference
[1] http://coactionos.com/embedded%20design%20tips/2013/10/18/Tips-RAM-Flash-Usage-in-Embedded-C-Programs/

RAM/Flash Usage in Embedded C Programs

 

Read-only memory(Flash)

Data Section

int data_variable = 500;

Read-only date



constant

const int read_only_variable = 2000;

Text(code)



“literal pool” may in the function.


void my_function(void){
int x;
x = 200;
printf("X is %d\n", x);
}

Read-Write Data(RAM)


Data section


int data_var = 500; //require flash memory to stored.

BSS section


int bss_var0;
int bss_var1 = 0;
//doesn’t need require flash memory to stored.

Heap section


static int static_var;
buffer = malloc(512);

Stack section


int my_function(int a, int b, int c, int d)

Reference


[1] http://coactionos.com/embedded%20design%20tips/2013/10/18/Tips-RAM-Flash-Usage-in-Embedded-C-Programs/

Monday, November 3, 2014

Assembly command note

 

The syntax of MOV can also be more complex as the following examples show.[7]

MOV EAX, [EBX]	  ; Move the 4 bytes in memory at the address contained in EBX into EAX
MOV [ESI+EAX], CL ; Move the contents of CL into the byte at address ESI+EAX

 


Reference


[1] http://en.wikipedia.org/wiki/Assembly_language

Time Stamp

for keil compilar environment, they had a defination for time stamp, therefore we could use that to be a release note for product purpose.

how to use?

printf("%s %s",__DATE__,__TIME__);

or you could assign memory for them.

U8 KC_DATA Datestring[sizeof(__DATE__)];
U8 KC_DATA Timestring[sizeof(__TIME__)];


memcpy(Datestring, &__DATE__, sizeof(__DATE__));
memcpy(Timestring, &__TIME__, sizeof(__TIME__));

 

Reference

[1] http://www.keil.com/forum/2789/display-time-and-date/

Register Transfer Level Design with Verilog (1) [ebook]

設計程式之所以有趣不外乎是它的千變萬化,同樣的結果卻有不同的寫法。 但這些不同寫法當中也並沒有分誰對誰錯,也沒有制定標準來規範何事該用何解。 這也就是我們設計者的珍貴!! [1] Primitive Instantiations 在Verilog中最基本的邏輯...