From ad2b10dd0be2509313f8faf81d9e364d0ee4e030 Mon Sep 17 00:00:00 2001 From: eqkter Date: Fri, 18 Aug 2023 23:25:49 +0200 Subject: auto updating site --- content/about.md | 18 +---- content/projects/first.md | 6 -- content/projects/second.md | 6 -- content/projects/test.md | 20 +++++ content/projects/uC_bare.md | 191 ++++++++++++++++++++++++++++++++++++++++++++ content/test.md | 20 +++++ 6 files changed, 234 insertions(+), 27 deletions(-) delete mode 100644 content/projects/first.md delete mode 100644 content/projects/second.md create mode 100644 content/projects/test.md create mode 100644 content/projects/uC_bare.md create mode 100644 content/test.md (limited to 'content') diff --git a/content/about.md b/content/about.md index a656bb5..09023c2 100644 --- a/content/about.md +++ b/content/about.md @@ -1,20 +1,8 @@ +++ -title = "Who am I?" +title = "About eqkter.org" page_template = "page.html" - -[extra] -latex = true +++ -### Under construction, test page for now -Hey, I am me, and you are you. -```bash -apt-get install blabla -``` - -$$ \mathrm{e}^{\mathbf{i}\pi} + 1 = 0 $$ - +For now, `eqkter.org` is mainly just a playground for me to test several hosted solution, learn to administrate a bare server, and share some of my experience as an embedded software developer on MCUs and ASICS. This takes form of some *projects* --- or should I say, **reminders and tip slips** --- available for everyone on this website. -An underscore in a latex string works fine in this example: \\(m_\alpha\\),
-It also works fine in this example: \\(m_\alpha\\) and \\(\xi_{\alpha}\\),
-But it breaks here: \\(\dot{\vec{x}}_\alpha\\). +See the bottom of the page for credits of inspiration and help, and for license. diff --git a/content/projects/first.md b/content/projects/first.md deleted file mode 100644 index a1d1130..0000000 --- a/content/projects/first.md +++ /dev/null @@ -1,6 +0,0 @@ -+++ -title = "My first post" -date = 2019-11-27 -+++ - -This is my first blog post. diff --git a/content/projects/second.md b/content/projects/second.md deleted file mode 100644 index 04db092..0000000 --- a/content/projects/second.md +++ /dev/null @@ -1,6 +0,0 @@ -+++ -title = "My second post" -date = 2019-11-28 -+++ - -This is my second blog post. diff --git a/content/projects/test.md b/content/projects/test.md new file mode 100644 index 0000000..b841ef6 --- /dev/null +++ b/content/projects/test.md @@ -0,0 +1,20 @@ ++++ +title = "Test page - empty" +date = 2019-11-28 + +[extra] +latex = true ++++ + +### Under construction, test page for now +Hey, I am me, and you are you. +```bash +apt-get install blabla +``` + +$$ \mathrm{e}^{\mathbf{i}\pi} + 1 = 0 $$ + + +An underscore in a latex string works fine in this example: \\(m_\alpha\\),
+It also works fine in this example: \\(m_\alpha\\) and \\(\xi_{\alpha}\\),
+But it breaks here: \\(\dot{\vec{x}}_\alpha\\). diff --git a/content/projects/uC_bare.md b/content/projects/uC_bare.md new file mode 100644 index 0000000..eeded17 --- /dev/null +++ b/content/projects/uC_bare.md @@ -0,0 +1,191 @@ ++++ +title = "µC firmware: interacting with bare-systems" +date = 2023-08-18 ++++ + +--- +## Address an hardware register +### Raw +```C +int main(void) +{ + unsigned char addr = 0xff; // reg addr + volatile unsigned char *reg = (volatile unisgned char *)addr; // reg ptr + unsigned char val; // reg value + // change the integer type if needed + +read: + val = *(volatile unsigned char *)reg; +write: + *(volatile unsigned char *)reg = val; + + return 0; +} +``` + +### Macro +```C +#define REG 0xff +#define READ_H(reg) (*(volatile unsigned char *)(reg)) +#define WRITE_H(reg, val) (*(volatile unsigned char *)(reg)) = (val) +``` + + +## Bit manipulation +### Raw +```C +int main(void) +{ + int val; // signed or unsigned + unsigned char position; // max at bit-length of val + unsigned char bit; // 0 or 1 + unsigned char x; // unknown value, 0 or 1 + +setBit: + val |= (1 << position); +unsetBit: + val &= ~(1 << position); +toggleBit: + val ^= (1 << position); +verifyBit: + bit = (val >> position) & 0x1; + +bit_to_x: // works with both x = 1 or 0 + val = (val & ~(1 << position)) | (x << position); + + return 0; +} +``` + +### Macro +```C +#define SET_BIT(val, bitIndex) (val) |= (1 << (bitIndex)) +#define CLEAR_BIT(val, bitIndex) (val) &= ~(1 << (bitIndex)) +#define TOGGLE_BIT(val, bitIndex) (val) ^= (1 << (bitIndex)) +#define BIT_VALUE(val, bitIndex) (((val) >> (bitIndex)) & 1) +#define BIT_TO_X(val, x, bitIndex) (val) = ((val) & ~(1 << (bitIndex)) | ((x) << (bitIndex)) +``` + + +## Declaration and use of hardware register +Following the last two sections: +```C +#define REGD (*(volatile unsigned char *)(0xff)) +#define D0 0 +#define D1 1 +#define D2 2 // etc + +int main(void) +{ + REGD = 0x00; // whole register + REGD |= (1 << D1); // set bit 1 of REGD + REGD &= ~(1 << D0); // unset bit 2 of REGD + return 0; +} +``` + +## Transpose a dataBus value on spread registers' bits +```C +void Xpos(unsigned char x, unsigned char xIndex, unsigned char *dest, unsigned char destIndex, unsigned char bitLength) +{ + unsigned char mask = 0x1; + unsigned char i = 1; + while (i++ < bitLength) + mask = (mask << 1) | 0x1; + *dest &= ~(mask << destIndex); // set the 0s + *dest |= (((x >> xIndex) & mask) << destIndex); // set the 1s +} + + +/*** Example ***/ +// Registers +unsigned char E = 0xa5; +unsigned char D = 0xa5; +unsigned char C = 0xa5; + +void drawBar(unsigned char x) // outputs x value on spread bits of E, D and C +{ + Xpos(x, 7, &E, 6, 1); // x7 is on E6 + Xpos(x, 6, &D, 7, 1); // x6 is on D7 + Xpos(x, 5, &C, 6, 1); // x5 is on C6 + Xpos(x, 4, &D, 4, 1); // x4 is on D4 + Xpos(x, 3, &D, 0, 1); // x3 is on D0 + Xpos(x, 2, &D, 1, 1); // x2 is on D1 + Xpos(x, 0, &D, 2, 2); // x1-0 is on D3-2 +} + +int main(void) +{ + unsigned char x = 0xff; + drawBar(x); + + return 0; +} +``` + +## Some macros +```C +#define MIN(A, B) ((A) <= (B) ? (A) : (B)) +#define MAX(A, B) ((A) >= (B) ? (A) : (B)) + +#ifndef ARRAY_SIZE +#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) +#endif + +#ifndef NULL +#define NULL ((void *)0) +#endif +``` + +## Bit-fields +**Careful:** the bit order is compiler-dependent, this implementation is *not* portable. +```C +#include + +union byte_t { + unsigned char val; + struct { + unsigned char A : 2; + unsigned char B : 1; + unsigned char C : 3; + }; + struct { + unsigned char A0 : 1; + unsigned char A1 : 1; + unsigned char : 1; + unsigned char C0 : 1; + unsigned char C1 : 1; + unsigned char C2 : 1; + }; +}; + +int main(void) +{ + union byte_t reg = {0x2a}; // 0b101010 + + printf("%hhu\t0x%x\t0x%x\n", reg.C1, reg.A, reg.val); + // gives: 1, 0x2, 0x2a + + return 0; +} +``` + +## Tricky definitions + +### Static +Static has three distinct uses in `C`: +1. A variable declared static within the body of a function maintains its value +between function invocations. +2. A variable declared static within a module, (but outside the body of +a function) is accessible by all functions within that module. It is not +accessible by functions within any other module. That is, it is a localized +global. +3. Functions declared static within a module may only be called by other +functions within that module. That is, the scope of the function is localized +to the module within which it is declared. + +### Volatile +Examples of volatile variables are: +1. Hardware registers in peripherals (e.g., status registers). +2. Non-stack variables referenced within an interrupt service routine. +3. Variables shared by multiple tasks in a multi-threaded application. diff --git a/content/test.md b/content/test.md new file mode 100644 index 0000000..a656bb5 --- /dev/null +++ b/content/test.md @@ -0,0 +1,20 @@ ++++ +title = "Who am I?" +page_template = "page.html" + +[extra] +latex = true ++++ + +### Under construction, test page for now +Hey, I am me, and you are you. +```bash +apt-get install blabla +``` + +$$ \mathrm{e}^{\mathbf{i}\pi} + 1 = 0 $$ + + +An underscore in a latex string works fine in this example: \\(m_\alpha\\),
+It also works fine in this example: \\(m_\alpha\\) and \\(\xi_{\alpha}\\),
+But it breaks here: \\(\dot{\vec{x}}_\alpha\\). -- cgit v1.2.3